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 set associative tag store. 34 */ 35 36#ifndef __MEM_CACHE_TAGS_SECTOR_TAGS_HH__ 37#define __MEM_CACHE_TAGS_SECTOR_TAGS_HH__ 38 39#include <string> 40#include <vector> 41 42#include "mem/cache/sector_blk.hh" 43#include "mem/cache/tags/base.hh" 44#include "params/SectorTags.hh" 45 46class BaseCache; 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 protected: 61 /** Typedef the set type used in this tag store. */ 62 typedef std::vector<SectorBlk*> SetType; 63 64 /** The associativity of the cache. */ 65 const unsigned assoc; 66 /** The allocatable associativity of the cache (alloc mask). */ 67 unsigned allocAssoc; 68 69 /** Whether tags and data are accessed sequentially. */ 70 const bool sequentialAccess; 71 72 /** Replacement policy */ 73 BaseReplacementPolicy *replacementPolicy; 74 75 /** Number of data blocks per sector. */ 76 const unsigned numBlocksPerSector; 77 78 /** The number of sectors in the cache. */ 79 const unsigned numSectors; 80 /** The number of sets in the cache. */ 81 const unsigned numSets; 82 83 /** The cache blocks. */ 84 std::vector<SectorSubBlk> blks; 85 /** The cache sector blocks. */ 86 std::vector<SectorBlk> secBlks; 87 /** The cache sets. */ 88 std::vector<SetType> sets; 89 90 // Organization of an address: Tag | Set # | Sector Offset # | Offset # 91 /** The amount to shift the address to get the sector tag. */ 92 const int sectorShift; 93 /** The amount to shift the address to get the set. */ 94 const int setShift; 95 /** The amount to shift the address to get the tag. */ 96 const int tagShift; 97 98 /** Mask out all bits that aren't part of the sector tag. */ 99 const unsigned sectorMask; 100 /** Mask out all bits that aren't part of the set index. */ 101 const unsigned setMask; 102
|
103 /** 104 * Find all possible block locations for insertion and replacement of 105 * an address. Should be called immediately before ReplacementPolicy's 106 * findVictim() not to break cache resizing. 107 * Returns sector blocks in all ways belonging to the set of the address. 108 * 109 * @param addr The addr to a find possible locations for. 110 * @return The possible locations. 111 */ 112 std::vector<ReplaceableEntry*> getPossibleLocations(const Addr addr) const 113 override; 114 |
115 public: 116 /** Convenience typedef. */ 117 typedef SectorTagsParams Params; 118 119 /** 120 * Construct and initialize this tag store. 121 */ 122 SectorTags(const Params *p); 123 124 /** 125 * Destructor. 126 */ 127 virtual ~SectorTags() {}; 128 129 /** 130 * Initialize blocks and set the parent cache back pointer. 131 * 132 * @param _cache Pointer to parent cache. 133 */ 134 void init(BaseCache *_cache) override; 135 136 /** 137 * This function updates the tags when a block is invalidated but does 138 * not invalidate the block itself. It also updates the replacement data. 139 * 140 * @param blk The block to invalidate. 141 */ 142 void invalidate(CacheBlk *blk) override; 143 144 /** 145 * Access block and update replacement data. May not succeed, in which 146 * case nullptr is returned. This has all the implications of a cache 147 * access and should only be used as such. Returns the access latency 148 * as a side effect. 149 * 150 * @param addr The address to find. 151 * @param is_secure True if the target memory space is secure. 152 * @param lat The access latency. 153 * @return Pointer to the cache block if found. 154 */ 155 CacheBlk* accessBlock(Addr addr, bool is_secure, Cycles &lat) override; 156 157 /**
|
146 * Find all possible block locations for insertion and replacement of
147 * an address. Should be called immediately before ReplacementPolicy's
148 * findVictim() not to break cache resizing.
149 * Returns sector blocks in all ways belonging to the set of the address.
150 *
151 * @param addr The addr to a find possible locations for.
152 * @return The possible locations.
153 */
154 virtual const std::vector<SectorBlk*> getPossibleLocations(Addr addr)
155 const;
156
157 /**
|
158 * Insert the new block into the cache and update replacement data. 159 * 160 * @param addr Address of the block. 161 * @param is_secure Whether the block is in secure space or not. 162 * @param src_master_ID The source requestor ID. 163 * @param task_ID The new task ID. 164 * @param blk The block to update. 165 */ 166 void insertBlock(const Addr addr, const bool is_secure, 167 const int src_master_ID, const uint32_t task_ID, 168 CacheBlk *blk) override; 169 170 /** 171 * Finds the given address in the cache, do not update replacement data. 172 * i.e. This is a no-side-effect find of a block. 173 * 174 * @param addr The address to find. 175 * @param is_secure True if the target memory space is secure. 176 * @return Pointer to the cache block if found. 177 */ 178 CacheBlk* findBlock(Addr addr, bool is_secure) const override; 179 180 /** 181 * Find a sector block given set and way. 182 * 183 * @param set The set of the block. 184 * @param way The way of the block. 185 * @return The block. 186 */ 187 ReplaceableEntry* findBlockBySetAndWay(int set, int way) const override; 188 189 /** 190 * Find replacement victim based on address. 191 * 192 * @param addr Address to find a victim for. 193 * @param is_secure True if the target memory space is secure. 194 * @param evict_blks Cache blocks to be evicted. 195 * @return Cache block to be replaced. 196 */ 197 CacheBlk* findVictim(Addr addr, const bool is_secure, 198 std::vector<CacheBlk*>& evict_blks) const override; 199 200 /** 201 * Generate the sector tag from the given address. 202 * 203 * @param addr The address to get the sector tag from. 204 * @return The sector tag of the address. 205 */ 206 Addr extractTag(Addr addr) const override; 207 208 /** 209 * Calculate the set index from the address. 210 * 211 * @param addr The address to get the set from. 212 * @return The set index of the address. 213 */ 214 int extractSet(Addr addr) const; 215 216 /** 217 * Calculate a block's offset in a sector from the address. 218 * 219 * @param addr The address to get the offset from. 220 * @return Offset of the corresponding block within its sector. 221 */ 222 int extractSectorOffset(Addr addr) const; 223 224 /** 225 * Regenerate the block address from the tag and set. 226 * 227 * @param block The block. 228 * @return the block address. 229 */ 230 Addr regenerateBlkAddr(const CacheBlk* blk) const override; 231 232 /** 233 * Visit each sub-block in the tags and apply a visitor. 234 * 235 * The visitor should be a std::function that takes a cache block. 236 * reference as its parameter. 237 * 238 * @param visitor Visitor to call on each block. 239 */ 240 void forEachBlk(std::function<void(CacheBlk &)> visitor) override; 241 242 /** 243 * Find if any of the sub-blocks satisfies a condition. 244 * 245 * The visitor should be a std::function that takes a cache block 246 * reference as its parameter. The visitor will terminate the 247 * traversal early if the condition is satisfied. 248 * 249 * @param visitor Visitor to call on each block. 250 */ 251 bool anyBlk(std::function<bool(CacheBlk &)> visitor) override; 252}; 253 254#endif //__MEM_CACHE_TAGS_SECTOR_TAGS_HH__
|