From: Daniel R. Carvalho Date: Mon, 21 Sep 2020 15:32:01 +0000 (+0200) Subject: mem-cache: Encapsulate CacheBlk's refCount X-Git-Tag: develop-gem5-snapshot~685 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=2c21052fa6f410f0fbd62647a1922e42c228c8e1;p=gem5.git 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 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/34957 Reviewed-by: Jason Lowe-Power Reviewed-by: Nikos Nikoleris Maintainer: Nikos Nikoleris Tested-by: kokoro --- diff --git a/src/mem/cache/cache_blk.cc b/src/mem/cache/cache_blk.cc index 1b44371a2..c591aaa53 100644 --- a/src/mem/cache/cache_blk.cc +++ b/src/mem/cache/cache_blk.cc @@ -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) { diff --git a/src/mem/cache/cache_blk.hh b/src/mem/cache/cache_blk.hh index 77fd4b8f6..cfc05a1c9 100644 --- a/src/mem/cache/cache_blk.hh +++ b/src/mem/cache/cache_blk.hh @@ -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; }; /** diff --git a/src/mem/cache/tags/base.cc b/src/mem/cache/tags/base.cc index 19b620029..61be03e9f 100644 --- a/src/mem/cache/tags/base.cc +++ b/src/mem/cache/tags/base.cc @@ -133,7 +133,7 @@ void BaseTags::cleanupRefsVisitor(CacheBlk &blk) { if (blk.isValid()) { - stats.totalRefs += blk.refCount; + stats.totalRefs += blk.getRefCount(); ++stats.sampledRefs; } } diff --git a/src/mem/cache/tags/base.hh b/src/mem/cache/tags/base.hh index 5e0af20bd..700edcb92 100644 --- a/src/mem/cache/tags/base.hh +++ b/src/mem/cache/tags/base.hh @@ -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(); diff --git a/src/mem/cache/tags/base_set_assoc.hh b/src/mem/cache/tags/base_set_assoc.hh index d273f1e38..211bc1fdb 100644 --- a/src/mem/cache/tags/base_set_assoc.hh +++ b/src/mem/cache/tags/base_set_assoc.hh @@ -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); diff --git a/src/mem/cache/tags/sector_tags.cc b/src/mem/cache/tags/sector_tags.cc index e43237ea2..43020aa28 100644 --- a/src/mem/cache/tags/sector_tags.cc +++ b/src/mem/cache/tags/sector_tags.cc @@ -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(blk);