From b6209eb91163d8739e263751bd83e0e21d4097cf Mon Sep 17 00:00:00 2001 From: "Daniel R. Carvalho" Date: Mon, 21 Sep 2020 17:40:45 +0200 Subject: [PATCH] mem-cache: Encapsulate CacheBlk's tickInserted Encapsulate this variable to facilitate polymorphism. - tickInserted was renamed to _tickInserted and was privatized. - The insertion tick should always be set to the current tick, and only on insertion; thus, its setter is not public and does not take arguments. - An additional function was created to get the age since of the block relative to its insertion tick. - There is no current need for a getter. Change-Id: I81d4009abec5e9633e10f1e851e3a524553c98a4 Signed-off-by: Daniel R. Carvalho Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/34958 Reviewed-by: Jason Lowe-Power Reviewed-by: Nikos Nikoleris Maintainer: Nikos Nikoleris Tested-by: kokoro --- src/mem/cache/cache_blk.cc | 2 +- src/mem/cache/cache_blk.hh | 32 ++++++++++++++++++++++++-------- src/mem/cache/tags/base.cc | 3 +-- 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/mem/cache/cache_blk.cc b/src/mem/cache/cache_blk.cc index c591aaa53..26ad4afcc 100644 --- a/src/mem/cache/cache_blk.cc +++ b/src/mem/cache/cache_blk.cc @@ -66,7 +66,7 @@ CacheBlk::insert(const Addr tag, const bool is_secure, setTaskId(task_ID); // Set insertion tick as current tick - tickInserted = curTick(); + setTickInserted(); // Insertion counts as a reference to the block increaseRefCount(); diff --git a/src/mem/cache/cache_blk.hh b/src/mem/cache/cache_blk.hh index cfc05a1c9..448b89593 100644 --- a/src/mem/cache/cache_blk.hh +++ b/src/mem/cache/cache_blk.hh @@ -57,6 +57,7 @@ #include "mem/cache/replacement_policies/base.hh" #include "mem/packet.hh" #include "mem/request.hh" +#include "sim/core.hh" /** * Cache block status bit assignments @@ -109,12 +110,6 @@ class CacheBlk : public ReplaceableEntry /** holds the source requestor ID for this block. */ int srcRequestorId; - /** - * Tick on which the block was inserted in the cache. Its value is only - * meaningful if the block is valid. - */ - Tick tickInserted; - protected: /** * Represents that the indicated thread context has a "lock" on @@ -158,7 +153,7 @@ class CacheBlk : public ReplaceableEntry std::list lockList; public: - CacheBlk() : data(nullptr), tickInserted(0) + CacheBlk() : data(nullptr), _tickInserted(0) { invalidate(); } @@ -291,7 +286,7 @@ class CacheBlk : public ReplaceableEntry */ void setWhenReady(const Tick tick) { - assert(tick >= tickInserted); + assert(tick >= _tickInserted); whenReady = tick; } @@ -304,6 +299,18 @@ class CacheBlk : public ReplaceableEntry /** Get the number of references to this block since insertion. */ void increaseRefCount() { _refCount++; } + /** + * Get the block's age, that is, the number of ticks since its insertion. + * + * @return The block's age. + */ + Tick + getAge() const + { + assert(_tickInserted <= curTick()); + return curTick() - _tickInserted; + } + /** * Checks if the given information corresponds to this block's. * @@ -462,6 +469,9 @@ class CacheBlk : public ReplaceableEntry /** Set the number of references to this block since insertion. */ void setRefCount(const unsigned count) { _refCount = count; } + /** Set the current tick as this block's insertion tick. */ + void setTickInserted() { _tickInserted = curTick(); } + private: /** Data block tag value. */ Addr _tag; @@ -471,6 +481,12 @@ class CacheBlk : public ReplaceableEntry /** Number of references to this block since it was brought in. */ unsigned _refCount; + + /** + * Tick on which the block was inserted in the cache. Its value is only + * meaningful if the block is valid. + */ + Tick _tickInserted; }; /** diff --git a/src/mem/cache/tags/base.cc b/src/mem/cache/tags/base.cc index 61be03e9f..09de5fc5f 100644 --- a/src/mem/cache/tags/base.cc +++ b/src/mem/cache/tags/base.cc @@ -151,8 +151,7 @@ BaseTags::computeStatsVisitor(CacheBlk &blk) const uint32_t task_id = blk.getTaskId(); assert(task_id < ContextSwitchTaskId::NumTaskId); stats.occupanciesTaskId[task_id]++; - assert(blk.tickInserted <= curTick()); - Tick age = curTick() - blk.tickInserted; + Tick age = blk.getAge(); int age_index; if (age / SimClock::Int::us < 10) { // <10us -- 2.30.2