1/* 2 * Copyright (c) 2012-2014,2017 ARM Limited 3 * All rights reserved. 4 * 5 * The license below extends only to copyright in the software and shall 6 * not be construed as granting a license to any other intellectual 7 * property including but not limited to intellectual property relating 8 * to a hardware implementation of the functionality of the software --- 45 unchanged lines hidden (view full) --- 54 55#include "base/logging.hh" 56#include "base/types.hh" 57#include "debug/CacheRepl.hh" 58#include "mem/cache/base.hh" 59#include "mem/cache/blk.hh" 60#include "mem/cache/replacement_policies/base.hh" 61#include "mem/cache/tags/base.hh" |
62#include "mem/cache/tags/indexing_policies/base.hh" |
63#include "params/BaseSetAssoc.hh" 64 65/** |
66 * A basic cache tag store. |
67 * @sa \ref gem5MemorySystem "gem5 Memory System" 68 * 69 * The BaseSetAssoc placement policy divides the cache into s sets of w |
70 * cache lines (ways). |
71 */ 72class BaseSetAssoc : public BaseTags 73{ 74 public: 75 /** Typedef the block type used in this tag store. */ 76 typedef CacheBlk BlkType; |
77 78 protected: |
79 /** The allocatable associativity of the cache (alloc mask). */ 80 unsigned allocAssoc; 81 82 /** The cache blocks. */ 83 std::vector<BlkType> blks; 84 |
85 /** Whether tags and data are accessed sequentially. */ 86 const bool sequentialAccess; 87 |
88 /** Replacement policy */ 89 BaseReplacementPolicy *replacementPolicy; 90 |
91 public: 92 /** Convenience typedef. */ 93 typedef BaseSetAssocParams Params; 94 95 /** 96 * Construct and initialize this tag store. 97 */ 98 BaseSetAssoc(const Params *p); --- 65 unchanged lines hidden (view full) --- 164 // If a cache miss 165 lat = lookupLatency; 166 } 167 168 return blk; 169 } 170 171 /** |
172 * Find replacement victim based on address. The list of evicted blocks 173 * only contains the victim. 174 * 175 * @param addr Address to find a victim for. 176 * @param is_secure True if the target memory space is secure. 177 * @param evict_blks Cache blocks to be evicted. 178 * @return Cache block to be replaced. 179 */ 180 CacheBlk* findVictim(Addr addr, const bool is_secure, 181 std::vector<CacheBlk*>& evict_blks) const override 182 { |
183 // Get possible entries to be victimized 184 const std::vector<ReplaceableEntry*> entries = 185 indexingPolicy->getPossibleEntries(addr); |
186 187 // Choose replacement victim from replacement candidates 188 CacheBlk* victim = static_cast<CacheBlk*>(replacementPolicy->getVictim( |
189 entries)); |
190 191 // There is only one eviction for this replacement 192 evict_blks.push_back(victim); 193 194 DPRINTF(CacheRepl, "set %x, way %x: selecting blk for replacement\n", 195 victim->getSet(), victim->getWay()); 196 197 return victim; --- 37 unchanged lines hidden (view full) --- 235 * @return The maximum number of ways available for replacement. 236 */ 237 virtual int getWayAllocationMax() const override 238 { 239 return allocAssoc; 240 } 241 242 /** |
243 * Regenerate the block address from the tag and indexing location. |
244 * 245 * @param block The block. 246 * @return the block address. 247 */ 248 Addr regenerateBlkAddr(const CacheBlk* blk) const override 249 { |
250 return indexingPolicy->regenerateAddr(blk->tag, blk); |
251 } 252 253 void forEachBlk(std::function<void(CacheBlk &)> visitor) override { 254 for (CacheBlk& blk : blks) { 255 visitor(blk); 256 } 257 } 258 259 bool anyBlk(std::function<bool(CacheBlk &)> visitor) override { 260 for (CacheBlk& blk : blks) { 261 if (visitor(blk)) { 262 return true; 263 } 264 } 265 return false; 266 } |
267}; 268 269#endif //__MEM_CACHE_TAGS_BASE_SET_ASSOC_HH__ |