mem-cache: Encapsulate CacheBlk's refCount

Encapsulate this variable to facilitate polymorphism.

- refCount was renamed to _refCount and was privatized.
- The reference count should only be reset at invalidation;
  thus, its setter is not public.
- An additional function was created to increment the number
  of references by 1.

Change-Id: Ibc8799a8dcb7c53c651de3eb1c9b86118a297b9d
Signed-off-by: Daniel R. Carvalho <odanrc@yahoo.com.br>
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/34957
Reviewed-by: Jason Lowe-Power <power.jg@gmail.com>
Reviewed-by: Nikos Nikoleris <nikos.nikoleris@arm.com>
Maintainer: Nikos Nikoleris <nikos.nikoleris@arm.com>
Tested-by: kokoro <noreply+kokoro@google.com>
This commit is contained in:
Daniel R. Carvalho
2020-09-21 17:32:01 +02:00
committed by Daniel Carvalho
parent e2a1dd1f2a
commit 2c21052fa6
6 changed files with 18 additions and 9 deletions

View File

@@ -69,7 +69,7 @@ CacheBlk::insert(const Addr tag, const bool is_secure,
tickInserted = curTick();
// Insertion counts as a reference to the block
refCount = 1;
increaseRefCount();
// Set secure state
if (is_secure) {

View File

@@ -106,9 +106,6 @@ class CacheBlk : public ReplaceableEntry
*/
Tick whenReady;
/** Number of references to this block since it was brought in. */
unsigned refCount;
/** holds the source requestor ID for this block. */
int srcRequestorId;
@@ -210,7 +207,7 @@ class CacheBlk : public ReplaceableEntry
setTaskId(ContextSwitchTaskId::Unknown);
status = 0;
whenReady = MaxTick;
refCount = 0;
setRefCount(0);
srcRequestorId = Request::invldRequestorId;
lockList.clear();
}
@@ -301,6 +298,12 @@ class CacheBlk : public ReplaceableEntry
/** Get the task id associated to this block. */
uint32_t getTaskId() const { return _taskId; }
/** Get the number of references to this block since insertion. */
unsigned getRefCount() const { return _refCount; }
/** Get the number of references to this block since insertion. */
void increaseRefCount() { _refCount++; }
/**
* Checks if the given information corresponds to this block's.
*
@@ -456,12 +459,18 @@ class CacheBlk : public ReplaceableEntry
/** Set the task id value. */
void setTaskId(const uint32_t task_id) { _taskId = task_id; }
/** Set the number of references to this block since insertion. */
void setRefCount(const unsigned count) { _refCount = count; }
private:
/** Data block tag value. */
Addr _tag;
/** Task Id associated with this block */
uint32_t _taskId;
/** Number of references to this block since it was brought in. */
unsigned _refCount;
};
/**

View File

@@ -133,7 +133,7 @@ void
BaseTags::cleanupRefsVisitor(CacheBlk &blk)
{
if (blk.isValid()) {
stats.totalRefs += blk.refCount;
stats.totalRefs += blk.getRefCount();
++stats.sampledRefs;
}
}

View File

@@ -254,7 +254,7 @@ class BaseTags : public ClockedObject
assert(blk->isValid());
stats.occupancies[blk->srcRequestorId]--;
stats.totalRefs += blk->refCount;
stats.totalRefs += blk->getRefCount();
stats.sampledRefs++;
blk->invalidate();

View File

@@ -141,7 +141,7 @@ class BaseSetAssoc : public BaseTags
// If a cache hit
if (blk != nullptr) {
// Update number of references to accessed block
blk->refCount++;
blk->increaseRefCount();
// Update replacement data of accessed block
replacementPolicy->touch(blk->replacementData);

View File

@@ -151,7 +151,7 @@ SectorTags::accessBlock(Addr addr, bool is_secure, Cycles &lat)
// If a cache hit
if (blk != nullptr) {
// Update number of references to accessed block
blk->refCount++;
blk->increaseRefCount();
// Get block's sector
SectorSubBlk* sub_blk = static_cast<SectorSubBlk*>(blk);