sector_tags.hh (13938:14f80b6b37c1) sector_tags.hh (13941:2c19da00ef9c)
1/*
2 * Copyright (c) 2018 Inria
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 * Authors: Daniel Carvalho
29 */
30
31/**
32 * @file
33 * Declaration of a sector tag store.
34 */
35
36#ifndef __MEM_CACHE_TAGS_SECTOR_TAGS_HH__
37#define __MEM_CACHE_TAGS_SECTOR_TAGS_HH__
38
1/*
2 * Copyright (c) 2018 Inria
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 * Authors: Daniel Carvalho
29 */
30
31/**
32 * @file
33 * Declaration of a sector tag store.
34 */
35
36#ifndef __MEM_CACHE_TAGS_SECTOR_TAGS_HH__
37#define __MEM_CACHE_TAGS_SECTOR_TAGS_HH__
38
39#include <cstdint>
39#include <string>
40#include <vector>
41
42#include "mem/cache/tags/base.hh"
43#include "mem/cache/tags/sector_blk.hh"
44#include "mem/packet.hh"
45#include "params/SectorTags.hh"
46
47class BaseReplacementPolicy;
48class ReplaceableEntry;
49
50/**
51 * A SectorTags cache tag store.
52 * @sa \ref gem5MemorySystem "gem5 Memory System"
53 *
54 * The SectorTags placement policy divides the cache into s sectors of w
55 * consecutive sectors (ways). Each sector then consists of a number of
56 * sequential cache lines that may or may not be present.
57 */
58class SectorTags : public BaseTags
59{
60 private:
61 /** The cache blocks. */
62 std::vector<SectorSubBlk> blks;
63 /** The cache sector blocks. */
64 std::vector<SectorBlk> secBlks;
65
66 protected:
67 /** The allocatable associativity of the cache (alloc mask). */
68 unsigned allocAssoc;
69
70 /** Whether tags and data are accessed sequentially. */
71 const bool sequentialAccess;
72
73 /** Replacement policy */
74 BaseReplacementPolicy *replacementPolicy;
75
76 /** Number of data blocks per sector. */
77 const unsigned numBlocksPerSector;
78
79 /** The number of sectors in the cache. */
80 const unsigned numSectors;
81
82 // Organization of an address:
83 // Tag | Placement Location | Sector Offset # | Offset #
84 /** The amount to shift the address to get the sector tag. */
85 const int sectorShift;
86
87 /** Mask out all bits that aren't part of the sector tag. */
88 const unsigned sectorMask;
89
90 public:
91 /** Convenience typedef. */
92 typedef SectorTagsParams Params;
93
94 /**
95 * Construct and initialize this tag store.
96 */
97 SectorTags(const Params *p);
98
99 /**
100 * Destructor.
101 */
102 virtual ~SectorTags() {};
103
104 /**
105 * Initialize blocks as SectorBlk and SectorSubBlk instances.
106 */
107 void tagsInit() override;
108
109 /**
110 * This function updates the tags when a block is invalidated but does
111 * not invalidate the block itself. It also updates the replacement data.
112 *
113 * @param blk The block to invalidate.
114 */
115 void invalidate(CacheBlk *blk) override;
116
117 /**
118 * Access block and update replacement data. May not succeed, in which
119 * case nullptr is returned. This has all the implications of a cache
120 * access and should only be used as such. Returns the tag lookup latency
121 * as a side effect.
122 *
123 * @param addr The address to find.
124 * @param is_secure True if the target memory space is secure.
125 * @param lat The latency of the tag lookup.
126 * @return Pointer to the cache block if found.
127 */
128 CacheBlk* accessBlock(Addr addr, bool is_secure, Cycles &lat) override;
129
130 /**
131 * Insert the new block into the cache and update replacement data.
132 *
133 * @param pkt Packet holding the address to update
134 * @param blk The block to update.
135 */
136 void insertBlock(const PacketPtr pkt, CacheBlk *blk) override;
137
138 /**
139 * Finds the given address in the cache, do not update replacement data.
140 * i.e. This is a no-side-effect find of a block.
141 *
142 * @param addr The address to find.
143 * @param is_secure True if the target memory space is secure.
144 * @return Pointer to the cache block if found.
145 */
146 CacheBlk* findBlock(Addr addr, bool is_secure) const override;
147
148 /**
149 * Find replacement victim based on address.
150 *
151 * @param addr Address to find a victim for.
152 * @param is_secure True if the target memory space is secure.
40#include <string>
41#include <vector>
42
43#include "mem/cache/tags/base.hh"
44#include "mem/cache/tags/sector_blk.hh"
45#include "mem/packet.hh"
46#include "params/SectorTags.hh"
47
48class BaseReplacementPolicy;
49class ReplaceableEntry;
50
51/**
52 * A SectorTags cache tag store.
53 * @sa \ref gem5MemorySystem "gem5 Memory System"
54 *
55 * The SectorTags placement policy divides the cache into s sectors of w
56 * consecutive sectors (ways). Each sector then consists of a number of
57 * sequential cache lines that may or may not be present.
58 */
59class SectorTags : public BaseTags
60{
61 private:
62 /** The cache blocks. */
63 std::vector<SectorSubBlk> blks;
64 /** The cache sector blocks. */
65 std::vector<SectorBlk> secBlks;
66
67 protected:
68 /** The allocatable associativity of the cache (alloc mask). */
69 unsigned allocAssoc;
70
71 /** Whether tags and data are accessed sequentially. */
72 const bool sequentialAccess;
73
74 /** Replacement policy */
75 BaseReplacementPolicy *replacementPolicy;
76
77 /** Number of data blocks per sector. */
78 const unsigned numBlocksPerSector;
79
80 /** The number of sectors in the cache. */
81 const unsigned numSectors;
82
83 // Organization of an address:
84 // Tag | Placement Location | Sector Offset # | Offset #
85 /** The amount to shift the address to get the sector tag. */
86 const int sectorShift;
87
88 /** Mask out all bits that aren't part of the sector tag. */
89 const unsigned sectorMask;
90
91 public:
92 /** Convenience typedef. */
93 typedef SectorTagsParams Params;
94
95 /**
96 * Construct and initialize this tag store.
97 */
98 SectorTags(const Params *p);
99
100 /**
101 * Destructor.
102 */
103 virtual ~SectorTags() {};
104
105 /**
106 * Initialize blocks as SectorBlk and SectorSubBlk instances.
107 */
108 void tagsInit() override;
109
110 /**
111 * This function updates the tags when a block is invalidated but does
112 * not invalidate the block itself. It also updates the replacement data.
113 *
114 * @param blk The block to invalidate.
115 */
116 void invalidate(CacheBlk *blk) override;
117
118 /**
119 * Access block and update replacement data. May not succeed, in which
120 * case nullptr is returned. This has all the implications of a cache
121 * access and should only be used as such. Returns the tag lookup latency
122 * as a side effect.
123 *
124 * @param addr The address to find.
125 * @param is_secure True if the target memory space is secure.
126 * @param lat The latency of the tag lookup.
127 * @return Pointer to the cache block if found.
128 */
129 CacheBlk* accessBlock(Addr addr, bool is_secure, Cycles &lat) override;
130
131 /**
132 * Insert the new block into the cache and update replacement data.
133 *
134 * @param pkt Packet holding the address to update
135 * @param blk The block to update.
136 */
137 void insertBlock(const PacketPtr pkt, CacheBlk *blk) override;
138
139 /**
140 * Finds the given address in the cache, do not update replacement data.
141 * i.e. This is a no-side-effect find of a block.
142 *
143 * @param addr The address to find.
144 * @param is_secure True if the target memory space is secure.
145 * @return Pointer to the cache block if found.
146 */
147 CacheBlk* findBlock(Addr addr, bool is_secure) const override;
148
149 /**
150 * Find replacement victim based on address.
151 *
152 * @param addr Address to find a victim for.
153 * @param is_secure True if the target memory space is secure.
154 * @param size Size, in bits, of new block to allocate.
153 * @param evict_blks Cache blocks to be evicted.
154 * @return Cache block to be replaced.
155 */
156 CacheBlk* findVictim(Addr addr, const bool is_secure,
155 * @param evict_blks Cache blocks to be evicted.
156 * @return Cache block to be replaced.
157 */
158 CacheBlk* findVictim(Addr addr, const bool is_secure,
159 const std::size_t size,
157 std::vector<CacheBlk*>& evict_blks) const override;
158
159 /**
160 * Calculate a block's offset in a sector from the address.
161 *
162 * @param addr The address to get the offset from.
163 * @return Offset of the corresponding block within its sector.
164 */
165 int extractSectorOffset(Addr addr) const;
166
167 /**
168 * Regenerate the block address from the tag and location.
169 *
170 * @param block The block.
171 * @return the block address.
172 */
173 Addr regenerateBlkAddr(const CacheBlk* blk) const override;
174
175 /**
176 * Visit each sub-block in the tags and apply a visitor.
177 *
178 * The visitor should be a std::function that takes a cache block.
179 * reference as its parameter.
180 *
181 * @param visitor Visitor to call on each block.
182 */
183 void forEachBlk(std::function<void(CacheBlk &)> visitor) override;
184
185 /**
186 * Find if any of the sub-blocks satisfies a condition.
187 *
188 * The visitor should be a std::function that takes a cache block
189 * reference as its parameter. The visitor will terminate the
190 * traversal early if the condition is satisfied.
191 *
192 * @param visitor Visitor to call on each block.
193 */
194 bool anyBlk(std::function<bool(CacheBlk &)> visitor) override;
195};
196
197#endif //__MEM_CACHE_TAGS_SECTOR_TAGS_HH__
160 std::vector<CacheBlk*>& evict_blks) const override;
161
162 /**
163 * Calculate a block's offset in a sector from the address.
164 *
165 * @param addr The address to get the offset from.
166 * @return Offset of the corresponding block within its sector.
167 */
168 int extractSectorOffset(Addr addr) const;
169
170 /**
171 * Regenerate the block address from the tag and location.
172 *
173 * @param block The block.
174 * @return the block address.
175 */
176 Addr regenerateBlkAddr(const CacheBlk* blk) const override;
177
178 /**
179 * Visit each sub-block in the tags and apply a visitor.
180 *
181 * The visitor should be a std::function that takes a cache block.
182 * reference as its parameter.
183 *
184 * @param visitor Visitor to call on each block.
185 */
186 void forEachBlk(std::function<void(CacheBlk &)> visitor) override;
187
188 /**
189 * Find if any of the sub-blocks satisfies a condition.
190 *
191 * The visitor should be a std::function that takes a cache block
192 * reference as its parameter. The visitor will terminate the
193 * traversal early if the condition is satisfied.
194 *
195 * @param visitor Visitor to call on each block.
196 */
197 bool anyBlk(std::function<bool(CacheBlk &)> visitor) override;
198};
199
200#endif //__MEM_CACHE_TAGS_SECTOR_TAGS_HH__