Daniel Carvalho has uploaded this change for review. ( https://gem5-review.googlesource.com/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
---
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(-)



diff --git a/src/mem/cache/base.cc b/src/mem/cache/base.cc
index 1a40c83..67d5e70 100644
--- a/src/mem/cache/base.cc
+++ b/src/mem/cache/base.cc
@@ -116,7 +116,7 @@
     tempBlock = new TempCacheBlk();
     tempBlock->data = new uint8_t[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 cde0074..3fb98d6 100644
--- a/src/mem/cache/tags/base.hh
+++ b/src/mem/cache/tags/base.hh
@@ -155,6 +155,13 @@
      */

     /**
+     * Set the parent cache back pointer.
+     *
+     * @param _cache Pointer to parent cache.
+     */
+    void setCache(BaseCache *_cache);
+
+    /**
* Update insertion related stats. It does not, however, update tagsInUse,
      * as it depends on the blk type being used. Must be called within
      * insertBlock().
@@ -173,10 +180,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 81b91df..55626de 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 af23069..8fb5eca 100644
--- a/src/mem/cache/tags/fa_lru.cc
+++ b/src/mem/cache/tags/fa_lru.cc
@@ -67,6 +67,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;
@@ -95,11 +107,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 20650d6..ab37d72 100644
--- a/src/mem/cache/tags/fa_lru.hh
+++ b/src/mem/cache/tags/fa_lru.hh
@@ -67,6 +67,7 @@
 // TrackedCaches class
 //#define FALRU_DEBUG

+class BaseCache;
 class ReplaceableEntry;

 // A bitmask of the caches we are keeping track of. Currently the
@@ -148,6 +149,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 0ca55bc..6fca38a 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/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: 1
Gerrit-Owner: Daniel Carvalho <[email protected]>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to