Daniel Carvalho has submitted this change and it was merged. ( https://gem5-review.googlesource.com/c/public/gem5/+/11509 )

Change subject: mem-cache: Create tags initialization function
......................................................................

mem-cache: Create tags initialization function

Having the blocks initialized in the constructor makes it harder
to apply inheritance in the tags classes. This patch decouples
the block initialization functionality from the constructor by
using an init() function. It also sets the parent cache.

Change-Id: I0da7fdaae492b1177c7cc3bda8639f79921fbbeb
Reviewed-on: https://gem5-review.googlesource.com/c/11509
Reviewed-by: Jason Lowe-Power <[email protected]>
Reviewed-by: Nikos Nikoleris <[email protected]>
Maintainer: Jason Lowe-Power <[email protected]>
---
M src/mem/cache/base.cc
M src/mem/cache/tags/base.hh
M src/mem/cache/tags/base_set_assoc.cc
M src/mem/cache/tags/base_set_assoc.hh
M src/mem/cache/tags/fa_lru.cc
M src/mem/cache/tags/fa_lru.hh
M src/mem/cache/tags/sector_tags.cc
M src/mem/cache/tags/sector_tags.hh
8 files changed, 61 insertions(+), 8 deletions(-)

Approvals:
  Jason Lowe-Power: Looks good to me, approved; Looks good to me, approved
  Nikos Nikoleris: Looks good to me, but someone else must approve



diff --git a/src/mem/cache/base.cc b/src/mem/cache/base.cc
index 6c79fd6..736f167 100644
--- a/src/mem/cache/base.cc
+++ b/src/mem/cache/base.cc
@@ -115,7 +115,7 @@

     tempBlock = new TempCacheBlk(blkSize);

-    tags->setCache(this);
+    tags->init(this);
     if (prefetcher)
         prefetcher->setCache(this);
 }
diff --git a/src/mem/cache/tags/base.hh b/src/mem/cache/tags/base.hh
index 30a7af7..385d25c 100644
--- a/src/mem/cache/tags/base.hh
+++ b/src/mem/cache/tags/base.hh
@@ -154,6 +154,13 @@
      * @}
      */

+    /**
+     * Set the parent cache back pointer.
+     *
+     * @param _cache Pointer to parent cache.
+     */
+    void setCache(BaseCache *_cache);
+
   public:
     typedef BaseTagsParams Params;
     BaseTags(const Params *p);
@@ -164,10 +171,11 @@
     virtual ~BaseTags() {}

     /**
-     * Set the parent cache back pointer.
+     * Initialize blocks and set the parent cache back pointer.
+     *
      * @param _cache Pointer to parent cache.
      */
-    void setCache(BaseCache *_cache);
+    virtual void init(BaseCache *_cache) = 0;

     /**
      * Register local statistics.
diff --git a/src/mem/cache/tags/base_set_assoc.cc b/src/mem/cache/tags/base_set_assoc.cc
index 18da532..8bd65e0 100644
--- a/src/mem/cache/tags/base_set_assoc.cc
+++ b/src/mem/cache/tags/base_set_assoc.cc
@@ -73,7 +73,15 @@
     setShift = floorLog2(blkSize);
     setMask = numSets - 1;
     tagShift = setShift + floorLog2(numSets);
+}

+void
+BaseSetAssoc::init(BaseCache* cache)
+{
+    // Set parent cache
+    setCache(cache);
+
+    // Initialize blocks
     unsigned blkIndex = 0;       // index into blks array
     for (unsigned i = 0; i < numSets; ++i) {
         sets[i].assoc = assoc;
diff --git a/src/mem/cache/tags/base_set_assoc.hh b/src/mem/cache/tags/base_set_assoc.hh
index dc0e042..a382649 100644
--- a/src/mem/cache/tags/base_set_assoc.hh
+++ b/src/mem/cache/tags/base_set_assoc.hh
@@ -121,6 +121,13 @@
     virtual ~BaseSetAssoc() {};

     /**
+     * Initialize blocks and set the parent cache back pointer.
+     *
+     * @param _cache Pointer to parent cache.
+     */
+    void init(BaseCache *_cache) override;
+
+    /**
      * This function updates the tags when a block is invalidated. It also
      * updates the replacement data.
      *
diff --git a/src/mem/cache/tags/fa_lru.cc b/src/mem/cache/tags/fa_lru.cc
index 1b43e98..d35e37c 100644
--- a/src/mem/cache/tags/fa_lru.cc
+++ b/src/mem/cache/tags/fa_lru.cc
@@ -69,6 +69,18 @@
         fatal("Cache Size must be power of 2 for now");

     blks = new FALRUBlk[numBlocks];
+}
+
+FALRU::~FALRU()
+{
+    delete[] blks;
+}
+
+void
+FALRU::init(BaseCache* cache)
+{
+    // Set parent cache
+    setCache(cache);

     head = &(blks[0]);
     head->prev = nullptr;
@@ -97,11 +109,6 @@
     cacheTracking.init(head, tail);
 }

-FALRU::~FALRU()
-{
-    delete[] blks;
-}
-
 void
 FALRU::regStats()
 {
diff --git a/src/mem/cache/tags/fa_lru.hh b/src/mem/cache/tags/fa_lru.hh
index c8ccc66..0d9a8d4 100644
--- a/src/mem/cache/tags/fa_lru.hh
+++ b/src/mem/cache/tags/fa_lru.hh
@@ -68,6 +68,7 @@
 // TrackedCaches class
 //#define FALRU_DEBUG

+class BaseCache;
 class ReplaceableEntry;

 // A bitmask of the caches we are keeping track of. Currently the
@@ -151,6 +152,13 @@
     ~FALRU();

     /**
+     * Initialize blocks and set the parent cache back pointer.
+     *
+     * @param _cache Pointer to parent cache.
+     */
+    void init(BaseCache *_cache) override;
+
+    /**
      * Register the stats for this object.
      */
     void regStats() override;
diff --git a/src/mem/cache/tags/sector_tags.cc b/src/mem/cache/tags/sector_tags.cc
index 76034e1..988fda5 100644
--- a/src/mem/cache/tags/sector_tags.cc
+++ b/src/mem/cache/tags/sector_tags.cc
@@ -67,6 +67,13 @@
     fatal_if(!isPowerOf2(numBlocksPerSector),
              "# of blocks per sector must be non-zero and a power of 2");
     fatal_if(assoc <= 0, "associativity must be greater than zero");
+}
+
+void
+SectorTags::init(BaseCache* cache)
+{
+    // Set parent cache
+    setCache(cache);

     // Initialize all sets
     unsigned sec_blk_index = 0;   // index into sector blks array
diff --git a/src/mem/cache/tags/sector_tags.hh b/src/mem/cache/tags/sector_tags.hh
index 109b983..7a2cdda 100644
--- a/src/mem/cache/tags/sector_tags.hh
+++ b/src/mem/cache/tags/sector_tags.hh
@@ -43,6 +43,7 @@
 #include "mem/cache/tags/base.hh"
 #include "params/SectorTags.hh"

+class BaseCache;
 class BaseReplacementPolicy;
 class ReplaceableEntry;

@@ -114,6 +115,13 @@
     virtual ~SectorTags() {};

     /**
+     * Initialize blocks and set the parent cache back pointer.
+     *
+     * @param _cache Pointer to parent cache.
+     */
+    void init(BaseCache *_cache) override;
+
+    /**
      * This function updates the tags when a block is invalidated but does
* not invalidate the block itself. It also updates the replacement data.
      *

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/11509
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: I0da7fdaae492b1177c7cc3bda8639f79921fbbeb
Gerrit-Change-Number: 11509
Gerrit-PatchSet: 6
Gerrit-Owner: Daniel Carvalho <[email protected]>
Gerrit-Reviewer: Daniel Carvalho <[email protected]>
Gerrit-Reviewer: Jason Lowe-Power <[email protected]>
Gerrit-Reviewer: Nikos Nikoleris <[email protected]>
Gerrit-MessageType: merged
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to