2 * Copyright (c) 2018 Inria
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.
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.
28 * Authors: Daniel Carvalho
33 * Declaration of a sector tag store.
36 #ifndef __MEM_CACHE_TAGS_SECTOR_TAGS_HH__
37 #define __MEM_CACHE_TAGS_SECTOR_TAGS_HH__
42 #include "mem/cache/sector_blk.hh"
43 #include "mem/cache/tags/base.hh"
44 #include "params/SectorTags.hh"
47 class BaseReplacementPolicy;
48 class ReplaceableEntry;
51 * A SectorTags cache tag store.
52 * @sa \ref gem5MemorySystem "gem5 Memory System"
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.
58 class SectorTags : public BaseTags
61 /** The allocatable associativity of the cache (alloc mask). */
64 /** Whether tags and data are accessed sequentially. */
65 const bool sequentialAccess;
67 /** Replacement policy */
68 BaseReplacementPolicy *replacementPolicy;
70 /** Number of data blocks per sector. */
71 const unsigned numBlocksPerSector;
73 /** The number of sectors in the cache. */
74 const unsigned numSectors;
76 /** The cache blocks. */
77 std::vector<SectorSubBlk> blks;
78 /** The cache sector blocks. */
79 std::vector<SectorBlk> secBlks;
81 // Organization of an address:
82 // Tag | Placement Location | Sector Offset # | Offset #
83 /** The amount to shift the address to get the sector tag. */
84 const int sectorShift;
86 /** Mask out all bits that aren't part of the sector tag. */
87 const unsigned sectorMask;
90 /** Convenience typedef. */
91 typedef SectorTagsParams Params;
94 * Construct and initialize this tag store.
96 SectorTags(const Params *p);
101 virtual ~SectorTags() {};
104 * Initialize blocks and set the parent cache back pointer.
106 * @param _cache Pointer to parent cache.
108 void init(BaseCache *_cache) override;
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.
114 * @param blk The block to invalidate.
116 void invalidate(CacheBlk *blk) override;
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 access latency
124 * @param addr The address to find.
125 * @param is_secure True if the target memory space is secure.
126 * @param lat The access latency.
127 * @return Pointer to the cache block if found.
129 CacheBlk* accessBlock(Addr addr, bool is_secure, Cycles &lat) override;
132 * Insert the new block into the cache and update replacement data.
134 * @param addr Address of the block.
135 * @param is_secure Whether the block is in secure space or not.
136 * @param src_master_ID The source requestor ID.
137 * @param task_ID The new task ID.
138 * @param blk The block to update.
140 void insertBlock(const Addr addr, const bool is_secure,
141 const int src_master_ID, const uint32_t task_ID,
142 CacheBlk *blk) override;
145 * Finds the given address in the cache, do not update replacement data.
146 * i.e. This is a no-side-effect find of a block.
148 * @param addr The address to find.
149 * @param is_secure True if the target memory space is secure.
150 * @return Pointer to the cache block if found.
152 CacheBlk* findBlock(Addr addr, bool is_secure) const override;
155 * Find replacement victim based on address.
157 * @param addr Address to find a victim for.
158 * @param is_secure True if the target memory space is secure.
159 * @param evict_blks Cache blocks to be evicted.
160 * @return Cache block to be replaced.
162 CacheBlk* findVictim(Addr addr, const bool is_secure,
163 std::vector<CacheBlk*>& evict_blks) const override;
166 * Calculate a block's offset in a sector from the address.
168 * @param addr The address to get the offset from.
169 * @return Offset of the corresponding block within its sector.
171 int extractSectorOffset(Addr addr) const;
174 * Regenerate the block address from the tag and location.
176 * @param block The block.
177 * @return the block address.
179 Addr regenerateBlkAddr(const CacheBlk* blk) const override;
182 * Visit each sub-block in the tags and apply a visitor.
184 * The visitor should be a std::function that takes a cache block.
185 * reference as its parameter.
187 * @param visitor Visitor to call on each block.
189 void forEachBlk(std::function<void(CacheBlk &)> visitor) override;
192 * Find if any of the sub-blocks satisfies a condition.
194 * The visitor should be a std::function that takes a cache block
195 * reference as its parameter. The visitor will terminate the
196 * traversal early if the condition is satisfied.
198 * @param visitor Visitor to call on each block.
200 bool anyBlk(std::function<bool(CacheBlk &)> visitor) override;
203 #endif //__MEM_CACHE_TAGS_SECTOR_TAGS_HH__