mem-cache: Encapsulate CacheBlk's task_id
authorDaniel R. Carvalho <odanrc@yahoo.com.br>
Mon, 21 Sep 2020 15:15:40 +0000 (17:15 +0200)
committerDaniel Carvalho <odanrc@yahoo.com.br>
Tue, 6 Oct 2020 09:05:49 +0000 (09:05 +0000)
Encapsulate this variable to facilitate polymorphism.

- task_id was renamed to _taskId and was privatized.
- The task id should only be modified at 2 specific moments:
  insertion and invalidation of the block; thus, its setter
  is not public.

Change-Id: If9c49c22117ef5d7f25163ec94bf8b174f221e39
Signed-off-by: Daniel R. Carvalho <odanrc@yahoo.com.br>
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/34956
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>
src/mem/cache/base.cc
src/mem/cache/cache.cc
src/mem/cache/cache_blk.cc
src/mem/cache/cache_blk.hh
src/mem/cache/tags/base.cc

index c52d2c6c19b4fe254ca56093936526f952752833..4b7333c1efc0151c8c4282c209544317a9fdaca7 100644 (file)
@@ -1497,7 +1497,7 @@ BaseCache::writebackBlk(CacheBlk *blk)
     if (blk->isSecure())
         req->setFlags(Request::SECURE);
 
-    req->taskId(blk->task_id);
+    req->taskId(blk->getTaskId());
 
     PacketPtr pkt =
         new Packet(req, blk->isDirty() ?
@@ -1539,7 +1539,7 @@ BaseCache::writecleanBlk(CacheBlk *blk, Request::Flags dest, PacketId id)
     if (blk->isSecure()) {
         req->setFlags(Request::SECURE);
     }
-    req->taskId(blk->task_id);
+    req->taskId(blk->getTaskId());
 
     PacketPtr pkt = new Packet(req, MemCmd::WriteClean, blkSize, id);
 
@@ -1609,7 +1609,7 @@ BaseCache::writebackVisitor(CacheBlk &blk)
         RequestPtr request = std::make_shared<Request>(
             regenerateBlkAddr(&blk), blkSize, 0, Request::funcRequestorId);
 
-        request->taskId(blk.task_id);
+        request->taskId(blk.getTaskId());
         if (blk.isSecure()) {
             request->setFlags(Request::SECURE);
         }
index 4ecda83d7813ae09721de8e432c0b20bbe836f53..a46404b69e0a9ed0d2adb9d3121c7d952ae7b446 100644 (file)
@@ -917,7 +917,7 @@ Cache::cleanEvictBlk(CacheBlk *blk)
     if (blk->isSecure())
         req->setFlags(Request::SECURE);
 
-    req->taskId(blk->task_id);
+    req->taskId(blk->getTaskId());
 
     PacketPtr pkt = new Packet(req, MemCmd::CleanEvict);
     pkt->allocate();
index 4b3325ca60ae57da155aa6294dd2707aff3e6794..1b44371a25c507453e248700c74c15b73d1e5e3a 100644 (file)
@@ -63,7 +63,7 @@ CacheBlk::insert(const Addr tag, const bool is_secure,
     srcRequestorId = src_requestor_ID;
 
     // Set task ID
-    task_id = task_ID;
+    setTaskId(task_ID);
 
     // Set insertion tick as current tick
     tickInserted = curTick();
index 1de5a818a3184f2dd6f668989404cf1eaabf156f..77fd4b8f6ce5c26eaf0ca9c8ca094f1b21638d44 100644 (file)
@@ -85,9 +85,6 @@ enum CacheBlkStatusBits : unsigned {
 class CacheBlk : public ReplaceableEntry
 {
   public:
-    /** Task Id associated with this block */
-    uint32_t task_id;
-
     /**
      * Contains a copy of the data in this block for easy access. This is used
      * for efficient execution when the data could be actually stored in
@@ -210,7 +207,7 @@ class CacheBlk : public ReplaceableEntry
     virtual void invalidate()
     {
         setTag(MaxAddr);
-        task_id = ContextSwitchTaskId::Unknown;
+        setTaskId(ContextSwitchTaskId::Unknown);
         status = 0;
         whenReady = MaxTick;
         refCount = 0;
@@ -301,6 +298,9 @@ class CacheBlk : public ReplaceableEntry
         whenReady = tick;
     }
 
+    /** Get the task id associated to this block. */
+    uint32_t getTaskId() const { return _taskId; }
+
     /**
      * Checks if the given information corresponds to this block's.
      *
@@ -452,9 +452,16 @@ class CacheBlk : public ReplaceableEntry
         }
     }
 
+  protected:
+    /** Set the task id value. */
+    void setTaskId(const uint32_t task_id) { _taskId = task_id; }
+
   private:
     /** Data block tag value. */
     Addr _tag;
+
+    /** Task Id associated with this block */
+    uint32_t _taskId;
 };
 
 /**
index 985a1eb4ad0d98d3efdb578235e7d9bc1888b4a0..19b6200296d9595861eca9f190103699f729751e 100644 (file)
@@ -148,8 +148,9 @@ void
 BaseTags::computeStatsVisitor(CacheBlk &blk)
 {
     if (blk.isValid()) {
-        assert(blk.task_id < ContextSwitchTaskId::NumTaskId);
-        stats.occupanciesTaskId[blk.task_id]++;
+        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;
 
@@ -165,7 +166,7 @@ BaseTags::computeStatsVisitor(CacheBlk &blk)
         } else
             age_index = 4; // >10ms
 
-        stats.ageTaskId[blk.task_id][age_index]++;
+        stats.ageTaskId[task_id][age_index]++;
     }
 }