Daniel Carvalho has uploaded this change for review. (
https://gem5-review.googlesource.com/9421
Change subject: mem-cache: ReplacementPolicy specific replacement data
......................................................................
mem-cache: ReplacementPolicy specific replacement data
Replacement data is specific for each replacement policy, and thus
should be instantiated differently by each policy.
Touch and reset do not need to be aware of CacheBlk, as they only
update its ReplacementData.
Change-Id: I998917d800fa48504ed95abffa2f1b7bfd68522b
---
M src/mem/cache/blk.hh
M src/mem/cache/replacement_policies/base.cc
M src/mem/cache/replacement_policies/base.hh
M src/mem/cache/replacement_policies/brrip_rp.cc
M src/mem/cache/replacement_policies/brrip_rp.hh
M src/mem/cache/replacement_policies/fifo_rp.cc
M src/mem/cache/replacement_policies/lru_rp.cc
M src/mem/cache/replacement_policies/lru_rp.hh
M src/mem/cache/replacement_policies/mru_rp.cc
M src/mem/cache/replacement_policies/mru_rp.hh
M src/mem/cache/replacement_policies/random_rp.cc
M src/mem/cache/tags/base_set_assoc.cc
M src/mem/cache/tags/base_set_assoc.hh
13 files changed, 294 insertions(+), 125 deletions(-)
diff --git a/src/mem/cache/blk.hh b/src/mem/cache/blk.hh
index 65f32ff..83807b7 100644
--- a/src/mem/cache/blk.hh
+++ b/src/mem/cache/blk.hh
@@ -51,6 +51,7 @@
#include <list>
#include "base/printable.hh"
+#include "mem/cache/replacement_policies/base.hh"
#include "mem/packet.hh"
#include "mem/request.hh"
@@ -108,31 +109,14 @@
*/
int set, way;
- /**
- * Whether this block has been touched since simulation started.
- * Used to calculate number of used tags.
- */
- bool isTouched;
-
- /** Number of references to this block since it was brought in. */
- unsigned refCount;
-
/** holds the source requestor ID for this block. */
int srcMasterId;
- /** Tick on which the block was inserted in the cache. */
- Tick tickInserted;
-
/**
- * Replacement policy data. As of now it is only an update timestamp.
- * Tick on which the block was last touched.
+ * Replacement data associated to this block.
+ * It is instantiated by the replacement policy.
*/
- Tick lastTouchTick;
-
- /**
- * Re-Reference Interval Prediction Value. Used with RRIP repl policy.
- */
- unsigned rrpv;
+ std::unique_ptr<ReplacementData> replacementData;
protected:
/**
@@ -227,10 +211,14 @@
task_id = ContextSwitchTaskId::Unknown;
status = 0;
whenReady = MaxTick;
- isTouched = false;
- refCount = 0;
srcMasterId = Request::invldMasterId;
- tickInserted = MaxTick;
+
+ // The first invalidate is called before replacementData is
+ // instantiated by the replacement policy
+ if (replacementData) {
+ replacementData->clear();
+ }
+
lockList.clear();
}
diff --git a/src/mem/cache/replacement_policies/base.cc
b/src/mem/cache/replacement_policies/base.cc
index c422a75..5957763 100644
--- a/src/mem/cache/replacement_policies/base.cc
+++ b/src/mem/cache/replacement_policies/base.cc
@@ -30,12 +30,13 @@
/**
* @file
- * Declaration of a common base class for cache replacement policy objects.
+ * Declaration of a common base class for replacement policy objects.
* In general replacement policies try to use invalid entries as victims,
- * and if no such blocks exist the replacement policy is applied.
+ * and if no such blocks exists the replacement policy is applied.
*/
#include "mem/cache/replacement_policies/base.hh"
+#include "mem/cache/blk.hh"
BaseReplacementPolicy::BaseReplacementPolicy(const Params *p)
: SimObject(p)
@@ -43,24 +44,30 @@
}
void
-BaseReplacementPolicy::touch(CacheBlk *blk)
+BaseReplacementPolicy::touch(ReplacementData* replacementData)
{
// Inform block has been touched
- blk->isTouched = true;
+ replacementData->isTouched = true;
// Update frequency counter
- blk->refCount++;
+ replacementData->refCount++;
}
void
-BaseReplacementPolicy::reset(CacheBlk *blk)
+BaseReplacementPolicy::reset(ReplacementData* replacementData)
{
// Inform block has been touched
- blk->isTouched = true;
+ replacementData->isTouched = true;
// Set insertion tick
- blk->tickInserted = curTick();
+ replacementData->tickInserted = curTick();
// Reset frequency counter
- blk->refCount = 0;
+ replacementData->refCount = 0;
+}
+
+std::unique_ptr<ReplacementData>
+BaseReplacementPolicy::instantiateEntry()
+{
+ return std::unique_ptr<ReplacementData>(new ReplacementData());
}
diff --git a/src/mem/cache/replacement_policies/base.hh
b/src/mem/cache/replacement_policies/base.hh
index 383f3f0..02ca743 100644
--- a/src/mem/cache/replacement_policies/base.hh
+++ b/src/mem/cache/replacement_policies/base.hh
@@ -32,27 +32,58 @@
#define __MEM_CACHE_REPLACEMENT_POLICIES_BASE_HH__
#include "mem/cache/base.hh"
-#include "mem/cache/blk.hh"
#include "params/BaseReplacementPolicy.hh"
#include "sim/sim_object.hh"
+/** Forward declaration of a block. */
+class CacheBlk;
+
/**
* Replacement candidates as chosen by the indexing policy.
*
* The base functions touch() and reset() must be called by all subclasses
* that override them.
- *
- * @todo
- * Currently the replacement candidates are simply the cache blocks
- * derived from the possible placement locations of an address, as
- * defined by the getPossibleLocations() from BaseTags. In a future
- * patch it should be an inheritable class to allow the replacement
- * policies to be used with any table-like structure that needs to
- * replace its entries.
*/
typedef std::vector<CacheBlk*> ReplacementCandidates;
/**
+ * The replacement data needed by the replacement policy.
+ */
+class ReplacementData
+{
+ public:
+ /** Whether this entry has been touched since simulation started. */
+ bool isTouched;
+
+ /** Number of references to this entry since it was brought in. */
+ unsigned refCount;
+
+ /** Tick on which the entry was inserted in the table. */
+ Tick tickInserted;
+
+ /**
+ * Default constructor.
+ */
+ ReplacementData(){
+ clear();
+ }
+
+ /**
+ * Default destructor.
+ */
+ ~ReplacementData(){}
+
+ /**
+ * Clear replacement data.
+ */
+ virtual void clear(){
+ isTouched = false;
+ refCount = 0;
+ tickInserted = MaxTick;
+ }
+};
+
+/**
* A common base class of cache replacement policy objects.
*/
class BaseReplacementPolicy : public SimObject
@@ -79,19 +110,19 @@
*
* This base function must be called by all subclasses that override
it.
*
- * @param blk Cache block to be touched.
+ * @param replacementData Replacement data to be touched.
*/
- virtual void touch(CacheBlk *blk);
+ virtual void touch(ReplacementData* replacementData);
/**
- * Reset replacement data for a block. Used when a block is inserted.
+ * Reset replacement data. Used when a block is inserted.
* Sets the insertion tick, and update number of references.
*
* This base function must be called by all subclasses that override
it.
*
- * @param blk Cache block to be reset.
+ * @param replacementData Replacement data to be reset.
*/
- virtual void reset(CacheBlk *blk);
+ virtual void reset(ReplacementData* replacementData);
/**
* Find replacement victim among candidates.
@@ -100,6 +131,15 @@
* @return Cache block to be replaced.
*/
virtual CacheBlk* getVictim(const ReplacementCandidates& candidates) =
0;
+
+ /**
+ * Instantiate a replacement data entry.
+ * If the replacement policy subclasses ReplacementData, this should be
+ * overridden.
+ *
+ * @return A unique pointer to the new replacement data.
+ */
+ virtual std::unique_ptr<ReplacementData> instantiateEntry();
};
#endif // __MEM_CACHE_REPLACEMENT_POLICIES_BASE_HH__
diff --git a/src/mem/cache/replacement_policies/brrip_rp.cc
b/src/mem/cache/replacement_policies/brrip_rp.cc
index 3c3080b..26d38cf 100644
--- a/src/mem/cache/replacement_policies/brrip_rp.cc
+++ b/src/mem/cache/replacement_policies/brrip_rp.cc
@@ -31,7 +31,7 @@
#include "mem/cache/replacement_policies/brrip_rp.hh"
#include "base/random.hh"
-#include "debug/CacheRepl.hh"
+#include "mem/cache/blk.hh"
BRRIPRP::BRRIPRP(const Params *p)
: BaseReplacementPolicy(p),
@@ -41,32 +41,32 @@
}
void
-BRRIPRP::touch(CacheBlk *blk)
+BRRIPRP::touch(ReplacementData* replacementData)
{
- BaseReplacementPolicy::touch(blk);
+ BaseReplacementPolicy::touch(replacementData);
// Update RRPV if not 0 yet
// Every hit in HP mode makes the block the last to be evicted, while
// in FP mode a hit makes the block less likely to be evicted
if (hitPriority) {
- blk->rrpv = 0;
- } else if (blk->rrpv > 0) {
- blk->rrpv--;
+ ((BRRIPReplData*)replacementData)->rrpv = 0;
+ } else if (((BRRIPReplData*)replacementData)->rrpv > 0) {
+ ((BRRIPReplData*)replacementData)->rrpv--;
}
}
void
-BRRIPRP::reset(CacheBlk *blk)
+BRRIPRP::reset(ReplacementData* replacementData)
{
- BaseReplacementPolicy::reset(blk);
+ BaseReplacementPolicy::reset(replacementData);
// Reset RRPV
// Blocks are inserted as "long re-reference" if lower than btp,
// "distant re-reference" otherwise
if (random_mt.random<unsigned>(1, 100) <= btp) {
- blk->rrpv = maxRRPV-1;
+ ((BRRIPReplData*)replacementData)->rrpv = maxRRPV-1;
} else {
- blk->rrpv = maxRRPV;
+ ((BRRIPReplData*)replacementData)->rrpv = maxRRPV;
}
}
@@ -84,32 +84,40 @@
blk = candidate;
break;
// Update victim block if necessary
- } else if (candidate->rrpv > blk->rrpv) {
+ } else if
(((BRRIPReplData*)candidate->replacementData.get())->rrpv >
+ ((BRRIPReplData*)blk->replacementData.get())->rrpv) {
blk = candidate;
}
}
// Get difference of block's RRPV to the highest possible RRPV in
// order to update the RRPV of all the other blocks accordingly
- uint32_t diff = maxRRPV - blk->rrpv;
+ uint32_t diff = maxRRPV -
+ ((BRRIPReplData*)blk->replacementData.get())->rrpv;
// Update RRPV of all candidates
for (const auto& candidate : candidates) {
+ BRRIPReplData* replData =
+ (BRRIPReplData*)candidate->replacementData.get();
+
// Update the block's RPPV with the new value
- candidate->rrpv += diff;
+ replData->rrpv += diff;
// Apply limit to avoid bugs
- if (candidate->rrpv > maxRRPV) {
- candidate->rrpv = maxRRPV;
+ if (replData->rrpv > maxRRPV) {
+ replData->rrpv = maxRRPV;
}
}
- DPRINTF(CacheRepl, "set %x, way %x: selecting blk for replacement\n",
- blk->set, blk->way);
-
return blk;
}
+std::unique_ptr<ReplacementData>
+BRRIPRP::instantiateEntry()
+{
+ return std::unique_ptr<ReplacementData>(new BRRIPReplData());
+}
+
BRRIPRP*
BRRIPRPParams::create()
{
diff --git a/src/mem/cache/replacement_policies/brrip_rp.hh
b/src/mem/cache/replacement_policies/brrip_rp.hh
index cce9be7..df426a5 100644
--- a/src/mem/cache/replacement_policies/brrip_rp.hh
+++ b/src/mem/cache/replacement_policies/brrip_rp.hh
@@ -60,6 +60,35 @@
class BRRIPRP : public BaseReplacementPolicy
{
protected:
+ /** BRRIP-specific implementation of replacement data. */
+ class BRRIPReplData : public ReplacementData
+ {
+ public:
+ /** Re-Reference Interval Prediction Value. */
+ unsigned rrpv;
+
+ /**
+ * Default constructor.
+ */
+ BRRIPReplData(){
+ clear();
+ }
+
+ /**
+ * Default destructor.
+ */
+ ~BRRIPReplData(){}
+
+ /**
+ * Clear replacement data.
+ */
+ void clear() override
+ {
+ ReplacementData::clear();
+ rrpv = 0;
+ }
+ };
+
/**
* Maximum Re-Reference Prediction Value possible. A block with this
* value as the rrpv has the longest possible re-reference interval,
@@ -99,18 +128,18 @@
/**
* Touch a block to update its replacement data.
*
- * @param blk Cache block to be touched.
+ * @param replacementData Replacement data to be touched.
*/
- void touch(CacheBlk *blk) override;
+ void touch(ReplacementData* replacementData) override;
/**
- * Reset replacement data for a block. Used when a block is inserted.
+ * Reset replacement data. Used when a block is inserted.
* Sets the insertion tick, and update correspondent replacement data.
* Set RRPV according to the insertion policy used.
*
- * @param blk Cache block to be reset.
+ * @param replacementData Replacement data to be reset.
*/
- void reset(CacheBlk *blk) override;
+ void reset(ReplacementData* replacementData) override;
/**
* Find replacement victim using rrpv.
@@ -119,6 +148,13 @@
* @return Cache block to be replaced.
*/
CacheBlk* getVictim(const ReplacementCandidates& candidates) override;
+
+ /**
+ * Instantiate a replacement data entry.
+ *
+ * @return A unique pointer to the new replacement data.
+ */
+ std::unique_ptr<ReplacementData> instantiateEntry() override;
};
#endif // __MEM_CACHE_REPLACEMENT_POLICIES_BRRIP_RP_HH__
diff --git a/src/mem/cache/replacement_policies/fifo_rp.cc
b/src/mem/cache/replacement_policies/fifo_rp.cc
index fd320be..3077b8e 100644
--- a/src/mem/cache/replacement_policies/fifo_rp.cc
+++ b/src/mem/cache/replacement_policies/fifo_rp.cc
@@ -29,8 +29,7 @@
*/
#include "mem/cache/replacement_policies/fifo_rp.hh"
-
-#include "debug/CacheRepl.hh"
+#include "mem/cache/blk.hh"
FIFORP::FIFORP(const Params *p)
: BaseReplacementPolicy(p)
@@ -51,14 +50,12 @@
blk = candidate;
break;
// Update victim block if necessary
- } else if (candidate->tickInserted < blk->tickInserted) {
+ } else if (candidate->replacementData->tickInserted <
+ blk->replacementData->tickInserted) {
blk = candidate;
}
}
- DPRINTF(CacheRepl, "set %x, way %x: selecting blk for replacement\n",
- blk->set, blk->way);
-
return blk;
}
diff --git a/src/mem/cache/replacement_policies/lru_rp.cc
b/src/mem/cache/replacement_policies/lru_rp.cc
index b2fa20b..89fa0fc 100644
--- a/src/mem/cache/replacement_policies/lru_rp.cc
+++ b/src/mem/cache/replacement_policies/lru_rp.cc
@@ -29,8 +29,7 @@
*/
#include "mem/cache/replacement_policies/lru_rp.hh"
-
-#include "debug/CacheRepl.hh"
+#include "mem/cache/blk.hh"
LRURP::LRURP(const Params *p)
: BaseReplacementPolicy(p)
@@ -38,21 +37,22 @@
}
void
-LRURP::touch(CacheBlk *blk)
+LRURP::touch(ReplacementData* replacementData)
{
- BaseReplacementPolicy::touch(blk);
+ BaseReplacementPolicy::touch(replacementData);
// Update last touch timestamp
- blk->lastTouchTick = curTick();
+ ((LRUReplData*)replacementData)->lastTouchTick = curTick();
}
void
-LRURP::reset(CacheBlk *blk)
+LRURP::reset(ReplacementData* replacementData)
{
- BaseReplacementPolicy::reset(blk);
+ BaseReplacementPolicy::reset(replacementData);
// Set last touch timestamp
- blk->lastTouchTick = blk->tickInserted;
+ ((LRUReplData*)replacementData)->lastTouchTick =
+ replacementData->tickInserted;
}
CacheBlk*
@@ -69,17 +69,23 @@
blk = candidate;
break;
// Update victim block if necessary
- } else if (candidate->lastTouchTick < blk->lastTouchTick) {
+ } else if (((LRUReplData*)
+ candidate->replacementData.get())->lastTouchTick <
+ ((LRUReplData*)
+ blk->replacementData.get())->lastTouchTick) {
blk = candidate;
}
}
- DPRINTF(CacheRepl, "set %x, way %x: selecting blk for replacement\n",
- blk->set, blk->way);
-
return blk;
}
+std::unique_ptr<ReplacementData>
+LRURP::instantiateEntry()
+{
+ return std::unique_ptr<ReplacementData>(new LRUReplData());
+}
+
LRURP*
LRURPParams::create()
{
diff --git a/src/mem/cache/replacement_policies/lru_rp.hh
b/src/mem/cache/replacement_policies/lru_rp.hh
index 2dd7e86..8beeb40 100644
--- a/src/mem/cache/replacement_policies/lru_rp.hh
+++ b/src/mem/cache/replacement_policies/lru_rp.hh
@@ -43,6 +43,36 @@
class LRURP : public BaseReplacementPolicy
{
+ protected:
+ /** LRU-specific implementation of replacement data. */
+ class LRUReplData : public ReplacementData
+ {
+ public:
+ /** Tick on which the block was last touched. */
+ Tick lastTouchTick;
+
+ /**
+ * Default constructor.
+ */
+ LRUReplData(){
+ clear();
+ }
+
+ /**
+ * Default destructor.
+ */
+ ~LRUReplData(){}
+
+ /**
+ * Clear replacement data.
+ */
+ void clear() override
+ {
+ ReplacementData::clear();
+ lastTouchTick = 0;
+ }
+ };
+
public:
/** Convenience typedef. */
typedef LRURPParams Params;
@@ -58,19 +88,19 @@
~LRURP() {}
/**
- * Touch a block to update its last touch tick.
+ * Touch a blocks replacement data to update its last touch tick.
*
- * @param blk Cache block to be touched.
+ * @param replacementData Replacement data to be touched.
*/
- void touch(CacheBlk *blk) override;
+ void touch(ReplacementData* replacementData) override;
/**
- * Reset replacement data for a block. Used when a block is inserted.
+ * Reset replacement data. Used when a block is inserted.
* Sets its last touch tick as the current tick.
*
- * @param blk Cache block to be reset.
+ * @param replacementData Replacement data to be reset.
*/
- void reset(CacheBlk *blk) override;
+ void reset(ReplacementData* replacementData) override;
/**
* Find replacement victim using LRU timestamps.
@@ -79,6 +109,13 @@
* @return Cache block to be replaced.
*/
CacheBlk* getVictim(const ReplacementCandidates& candidates) override;
+
+ /**
+ * Instantiate a replacement data entry.
+ *
+ * @return A unique pointer to the new replacement data.
+ */
+ std::unique_ptr<ReplacementData> instantiateEntry() override;
};
#endif // __MEM_CACHE_REPLACEMENT_POLICIES_LRU_RP_HH__
diff --git a/src/mem/cache/replacement_policies/mru_rp.cc
b/src/mem/cache/replacement_policies/mru_rp.cc
index f4cf014..17f38e8 100644
--- a/src/mem/cache/replacement_policies/mru_rp.cc
+++ b/src/mem/cache/replacement_policies/mru_rp.cc
@@ -29,8 +29,7 @@
*/
#include "mem/cache/replacement_policies/mru_rp.hh"
-
-#include "debug/CacheRepl.hh"
+#include "mem/cache/blk.hh"
MRURP::MRURP(const Params *p)
: BaseReplacementPolicy(p)
@@ -38,21 +37,22 @@
}
void
-MRURP::touch(CacheBlk *blk)
+MRURP::touch(ReplacementData* replacementData)
{
- BaseReplacementPolicy::touch(blk);
+ BaseReplacementPolicy::touch(replacementData);
// Update last touch timestamp
- blk->lastTouchTick = curTick();
+ ((MRUReplData*)replacementData)->lastTouchTick = curTick();
}
void
-MRURP::reset(CacheBlk *blk)
+MRURP::reset(ReplacementData* replacementData)
{
- BaseReplacementPolicy::reset(blk);
+ BaseReplacementPolicy::reset(replacementData);
// Set last touch timestamp
- blk->lastTouchTick = blk->tickInserted;
+ ((MRUReplData*)replacementData)->lastTouchTick =
+ replacementData->tickInserted;
}
CacheBlk*
@@ -69,17 +69,23 @@
blk = candidate;
break;
// Update victim block if necessary
- } else if (candidate->lastTouchTick > blk->lastTouchTick) {
+ } else if (((MRUReplData*)
+ candidate->replacementData.get())->lastTouchTick >
+ ((MRUReplData*)
+ blk->replacementData.get())->lastTouchTick) {
blk = candidate;
}
}
- DPRINTF(CacheRepl, "set %x, way %x: selecting blk for replacement\n",
- blk->set, blk->way);
-
return blk;
}
+std::unique_ptr<ReplacementData>
+MRURP::instantiateEntry()
+{
+ return std::unique_ptr<ReplacementData>(new MRUReplData());
+}
+
MRURP*
MRURPParams::create()
{
diff --git a/src/mem/cache/replacement_policies/mru_rp.hh
b/src/mem/cache/replacement_policies/mru_rp.hh
index fd9a29d..d8bb52c 100644
--- a/src/mem/cache/replacement_policies/mru_rp.hh
+++ b/src/mem/cache/replacement_policies/mru_rp.hh
@@ -43,6 +43,36 @@
class MRURP : public BaseReplacementPolicy
{
+ protected:
+ /** MRU-specific implementation of replacement data. */
+ class MRUReplData : public ReplacementData
+ {
+ public:
+ /** Tick on which the block was last touched. */
+ Tick lastTouchTick;
+
+ /**
+ * Default constructor.
+ */
+ MRUReplData(){
+ clear();
+ }
+
+ /**
+ * Default destructor.
+ */
+ ~MRUReplData(){}
+
+ /**
+ * Clear replacement data.
+ */
+ void clear() override
+ {
+ ReplacementData::clear();
+ lastTouchTick = 0;
+ }
+ };
+
public:
/** Convenience typedef. */
typedef MRURPParams Params;
@@ -58,26 +88,34 @@
~MRURP() {}
/**
- * Touch a block to update its last touch tick.
+ * Touch a block's replacement data to update its last touch tick.
*
- * @param blk Cache block to be touched.
+ * @param replacementData Replacement data to be touched.
*/
- void touch(CacheBlk *blk) override;
+ void touch(ReplacementData* replacementData) override;
/**
- * Reset replacement data for a block. Used when a block is inserted.
+ * Reset replacement data. Used when a block is inserted.
* Sets its last touch tick as the current tick.
*
- * @param blk Cache block to be reset.
+ * @param replacementData Replacement data to be reset.
*/
- void reset(CacheBlk *blk) override;
+ void reset(ReplacementData* replacementData) override;
/**
* Find replacement victim using access timestamps.
+ *
* @param cands Replacement candidates, selected by indexing policy.
* @return Cache block to be replaced.
*/
CacheBlk* getVictim(const ReplacementCandidates& candidates) override;
+
+ /**
+ * Instantiate a replacement data entry.
+ *
+ * @return A unique pointer to the new replacement data.
+ */
+ std::unique_ptr<ReplacementData> instantiateEntry() override;
};
#endif // __MEM_CACHE_REPLACEMENT_POLICIES_MRU_RP_HH__
diff --git a/src/mem/cache/replacement_policies/random_rp.cc
b/src/mem/cache/replacement_policies/random_rp.cc
index 1c54bda..da1d9e9 100644
--- a/src/mem/cache/replacement_policies/random_rp.cc
+++ b/src/mem/cache/replacement_policies/random_rp.cc
@@ -31,7 +31,7 @@
#include "mem/cache/replacement_policies/random_rp.hh"
#include "base/random.hh"
-#include "debug/CacheRepl.hh"
+#include "mem/cache/blk.hh"
RandomRP::RandomRP(const Params *p)
: BaseReplacementPolicy(p)
@@ -57,10 +57,6 @@
}
}
- // If no invalid blocks were found, choose one of the candidates
randomly
- DPRINTF(CacheRepl, "set %x, way %x: selecting blk for replacement\n",
- blk->set, blk->way);
-
return blk;
}
diff --git a/src/mem/cache/tags/base_set_assoc.cc
b/src/mem/cache/tags/base_set_assoc.cc
index 2475e6f..8f46aa7 100644
--- a/src/mem/cache/tags/base_set_assoc.cc
+++ b/src/mem/cache/tags/base_set_assoc.cc
@@ -47,6 +47,7 @@
#include "mem/cache/tags/base_set_assoc.hh"
+#include <memory>
#include <string>
#include "base/intmath.hh"
@@ -95,6 +96,9 @@
// 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;
@@ -146,7 +150,7 @@
{
for (unsigned i = 0; i < numSets*assoc; ++i) {
if (blks[i].isValid()) {
- totalRefs += blks[i].refCount;
+ totalRefs += blks[i].replacementData->refCount;
++sampledRefs;
}
}
@@ -166,8 +170,8 @@
if (blks[i].isValid()) {
assert(blks[i].task_id < ContextSwitchTaskId::NumTaskId);
occupanciesTaskId[blks[i].task_id]++;
- assert(blks[i].tickInserted <= curTick());
- Tick age = curTick() - blks[i].tickInserted;
+ assert(blks[i].replacementData->tickInserted <= curTick());
+ Tick age = curTick() - blks[i].replacementData->tickInserted;
int age_index;
if (age / SimClock::Int::us < 10) { // <10us
diff --git a/src/mem/cache/tags/base_set_assoc.hh
b/src/mem/cache/tags/base_set_assoc.hh
index f7b386a..05d5241 100644
--- a/src/mem/cache/tags/base_set_assoc.hh
+++ b/src/mem/cache/tags/base_set_assoc.hh
@@ -53,6 +53,7 @@
#include <memory>
#include <vector>
+#include "debug/CacheRepl.hh"
#include "mem/cache/base.hh"
#include "mem/cache/blk.hh"
#include "mem/cache/tags/base.hh"
@@ -76,7 +77,6 @@
/** Typedef the set type used in this tag store. */
typedef CacheSet<CacheBlk> SetType;
-
protected:
/** The associativity of the cache. */
const unsigned assoc;
@@ -169,7 +169,7 @@
}
// Update replacement data of accessed block
- replacementPolicy->touch(blk);
+ replacementPolicy->touch(blk->replacementData.get());
} else {
// If a cache miss
lat = lookupLatency;
@@ -197,7 +197,13 @@
CacheBlk* findVictim(Addr addr) override
{
// Choose replacement victim from replacement candidates
- return replacementPolicy->getVictim(getPossibleLocations(addr));
+ CacheBlk* victim = (CacheBlk*)replacementPolicy->getVictim(
+ getPossibleLocations(addr));
+
+ DPRINTF(CacheRepl, "set %x, way %x: selecting blk for
replacement\n",
+ victim->set, victim->way);
+
+ return victim;
}
/**
@@ -225,7 +231,7 @@
MasterID master_id = pkt->req->masterId();
uint32_t task_id = pkt->req->taskId();
- if (!blk->isTouched) {
+ if (!blk->replacementData->isTouched) {
if (!warmedUp && tagsInUse.value() >= warmupBound) {
warmedUp = true;
warmupCycle = curTick();
@@ -238,7 +244,7 @@
// coherence protocol says it can't be.
if (blk->isValid()) {
replacements[0]++;
- totalRefs += blk->refCount;
+ totalRefs += blk->replacementData->refCount;
++sampledRefs;
invalidate(blk);
@@ -262,7 +268,7 @@
tagAccesses += 1;
dataAccesses += 1;
- replacementPolicy->reset(blk);
+ replacementPolicy->reset(blk->replacementData.get());
}
/**
--
To view, visit https://gem5-review.googlesource.com/9421
To unsubscribe, or for help writing mail filters, visit
https://gem5-review.googlesource.com/settings
Gerrit-Project: public/gem5
Gerrit-Branch: master
Gerrit-Change-Id: I998917d800fa48504ed95abffa2f1b7bfd68522b
Gerrit-Change-Number: 9421
Gerrit-PatchSet: 1
Gerrit-Owner: Daniel Carvalho <[email protected]>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev