diff options
Diffstat (limited to 'src/mem/cache/tags')
-rw-r--r-- | src/mem/cache/tags/base.cc | 5 | ||||
-rw-r--r-- | src/mem/cache/tags/base_set_assoc.cc | 13 | ||||
-rw-r--r-- | src/mem/cache/tags/base_set_assoc.hh | 31 |
3 files changed, 43 insertions, 6 deletions
diff --git a/src/mem/cache/tags/base.cc b/src/mem/cache/tags/base.cc index d48acfbe1..2f8d428c7 100644 --- a/src/mem/cache/tags/base.cc +++ b/src/mem/cache/tags/base.cc @@ -100,6 +100,11 @@ BaseTags::insertBlock(PacketPtr pkt, CacheBlk *blk) blk->invalidate(); } + // Touch block + blk->isTouched = true; + blk->refCount = 1; + blk->tickInserted = curTick(); + // Previous block, if existed, has been removed, and now we have // to insert the new one tagsInUse++; diff --git a/src/mem/cache/tags/base_set_assoc.cc b/src/mem/cache/tags/base_set_assoc.cc index f0ee2a5d8..5888d1f00 100644 --- a/src/mem/cache/tags/base_set_assoc.cc +++ b/src/mem/cache/tags/base_set_assoc.cc @@ -50,7 +50,6 @@ #include <string> #include "base/intmath.hh" -#include "sim/core.hh" BaseSetAssoc::BaseSetAssoc(const Params *p) :BaseTags(p), assoc(p->assoc), allocAssoc(p->assoc), @@ -92,6 +91,9 @@ BaseSetAssoc::BaseSetAssoc(const Params *p) // Associate a data chunk to the block blk->data = &dataBlks[blkSize*blkIndex]; + // Associate a replacement data entry to the block + blk->replacementData = replacementPolicy->instantiateEntry(); + // Setting the tag to j is just to prevent long chains in the // hash table; won't matter because the block is invalid blk->tag = j; @@ -106,6 +108,15 @@ BaseSetAssoc::BaseSetAssoc(const Params *p) } } +void +BaseSetAssoc::invalidate(CacheBlk *blk) +{ + BaseTags::invalidate(blk); + + // Invalidate replacement data + replacementPolicy->invalidate(blk->replacementData); +} + CacheBlk* BaseSetAssoc::findBlock(Addr addr, bool is_secure) const { diff --git a/src/mem/cache/tags/base_set_assoc.hh b/src/mem/cache/tags/base_set_assoc.hh index 024fda157..5a3e832c1 100644 --- a/src/mem/cache/tags/base_set_assoc.hh +++ b/src/mem/cache/tags/base_set_assoc.hh @@ -50,11 +50,12 @@ #include <cassert> #include <cstring> -#include <memory> #include <vector> +#include "debug/CacheRepl.hh" #include "mem/cache/base.hh" #include "mem/cache/blk.hh" +#include "mem/cache/replacement_policies/base.hh" #include "mem/cache/tags/base.hh" #include "mem/cache/tags/cacheset.hh" #include "mem/packet.hh" @@ -105,7 +106,6 @@ class BaseSetAssoc : public BaseTags BaseReplacementPolicy *replacementPolicy; public: - /** Convenience typedef. */ typedef BaseSetAssocParams Params; @@ -120,6 +120,14 @@ class BaseSetAssoc : public BaseTags virtual ~BaseSetAssoc() {}; /** + * This function updates the tags when a block is invalidated but does + * not invalidate the block itself. It also updates the replacement data. + * + * @param blk The block to invalidate. + */ + void invalidate(CacheBlk *blk) override; + + /** * Find the cache block given set and way * @param set The set of the block. * @param way The way of the block. @@ -165,8 +173,11 @@ class BaseSetAssoc : public BaseTags accessLatency; } + // Update number of references to accessed block + blk->refCount++; + // Update replacement data of accessed block - replacementPolicy->touch(blk); + replacementPolicy->touch(blk->replacementData); } else { // If a cache miss lat = lookupLatency; @@ -193,8 +204,18 @@ class BaseSetAssoc : public BaseTags */ CacheBlk* findVictim(Addr addr) override { + // Get possible locations for the victim block + std::vector<CacheBlk*> locations = getPossibleLocations(addr); + // Choose replacement victim from replacement candidates - return replacementPolicy->getVictim(getPossibleLocations(addr)); + CacheBlk* victim = static_cast<CacheBlk*>(replacementPolicy->getVictim( + std::vector<ReplaceableEntry*>( + locations.begin(), locations.end()))); + + DPRINTF(CacheRepl, "set %x, way %x: selecting blk for replacement\n", + victim->set, victim->way); + + return victim; } /** @@ -223,7 +244,7 @@ class BaseSetAssoc : public BaseTags BaseTags::insertBlock(pkt, blk); // Update replacement policy - replacementPolicy->reset(blk); + replacementPolicy->reset(blk->replacementData); } /** |