mem,stats: Update stats style for FALRU
authorHoa Nguyen <hoanguyen@ucdavis.edu>
Thu, 22 Oct 2020 10:26:21 +0000 (03:26 -0700)
committerHoa Nguyen <hoanguyen@ucdavis.edu>
Thu, 19 Nov 2020 22:46:48 +0000 (22:46 +0000)
Change-Id: I67a202eb974a31851fbbce0f15b5377ba726bc1c
Signed-off-by: Hoa Nguyen <hoanguyen@ucdavis.edu>
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/36475
Reviewed-by: Daniel Carvalho <odanrc@yahoo.com.br>
Maintainer: Jason Lowe-Power <power.jg@gmail.com>
Tested-by: kokoro <noreply+kokoro@google.com>
src/mem/cache/tags/fa_lru.cc
src/mem/cache/tags/fa_lru.hh

index 79019fc7644b77fc8c2d37aab5fc46acd105000b..e61a280174d69e5b46a58603b930537da1848269 100644 (file)
@@ -63,7 +63,7 @@ FALRUBlk::print() const
 FALRU::FALRU(const Params &p)
     : BaseTags(p),
 
-      cacheTracking(p.min_tracked_cache_size, size, blkSize)
+      cacheTracking(p.min_tracked_cache_size, size, blkSize, this)
 {
     if (!isPowerOf2(blkSize))
         fatal("cache block size (in bytes) `%d' must be a power of two",
@@ -106,13 +106,6 @@ FALRU::tagsInit()
     cacheTracking.init(head, tail);
 }
 
-void
-FALRU::regStats()
-{
-    BaseTags::regStats();
-    cacheTracking.regStats(name());
-}
-
 void
 FALRU::invalidate(CacheBlk *blk)
 {
@@ -285,6 +278,51 @@ FALRU::moveToTail(FALRUBlk *blk)
     }
 }
 
+void
+printSize(std::ostream &stream, size_t size)
+{
+    static const char *SIZES[] = { "B", "kB", "MB", "GB", "TB", "ZB" };
+    int div = 0;
+    while (size >= 1024 && div < (sizeof SIZES / sizeof *SIZES)) {
+        div++;
+        size >>= 10;
+    }
+    stream << size << SIZES[div];
+}
+
+FALRU::CacheTracking::CacheTracking(unsigned min_size, unsigned max_size,
+                                    unsigned block_size, Stats::Group *parent)
+    : Stats::Group(parent),
+      blkSize(block_size),
+      minTrackedSize(min_size),
+      numTrackedCaches(max_size > min_size ?
+                       floorLog2(max_size) - floorLog2(min_size) : 0),
+      inAllCachesMask(mask(numTrackedCaches)),
+      boundaries(numTrackedCaches),
+      ADD_STAT(hits, "The number of hits in each cache size."),
+      ADD_STAT(misses, "The number of misses in each cache size."),
+      ADD_STAT(accesses, "The number of accesses to the FA LRU cache.")
+{
+    fatal_if(numTrackedCaches > sizeof(CachesMask) * 8,
+             "Not enough bits (%s) in type CachesMask type to keep "
+             "track of %d caches\n", sizeof(CachesMask),
+             numTrackedCaches);
+
+    hits
+        .init(numTrackedCaches + 1);
+    misses
+        .init(numTrackedCaches + 1);
+
+    for (unsigned i = 0; i < numTrackedCaches + 1; ++i) {
+      std::stringstream size_str;
+      printSize(size_str, minTrackedSize << i);
+      hits.subname(i, size_str.str());
+      hits.subdesc(i, "Hits in a " + size_str.str() + " cache");
+      misses.subname(i, size_str.str());
+      misses.subdesc(i, "Misses in a " + size_str.str() + " cache");
+    }
+}
+
 void
 FALRU::CacheTracking::check(const FALRUBlk *head, const FALRUBlk *tail) const
 {
@@ -412,42 +450,3 @@ FALRU::CacheTracking::recordAccess(FALRUBlk *blk)
     accesses++;
 }
 
-void
-printSize(std::ostream &stream, size_t size)
-{
-    static const char *SIZES[] = { "B", "kB", "MB", "GB", "TB", "ZB" };
-    int div = 0;
-    while (size >= 1024 && div < (sizeof SIZES / sizeof *SIZES)) {
-        div++;
-        size >>= 10;
-    }
-    stream << size << SIZES[div];
-}
-
-void
-FALRU::CacheTracking::regStats(std::string name)
-{
-    hits
-        .init(numTrackedCaches + 1)
-        .name(name + ".falru_hits")
-        .desc("The number of hits in each cache size.")
-        ;
-    misses
-        .init(numTrackedCaches + 1)
-        .name(name + ".falru_misses")
-        .desc("The number of misses in each cache size.")
-        ;
-    accesses
-        .name(name + ".falru_accesses")
-        .desc("The number of accesses to the FA LRU cache.")
-        ;
-
-    for (unsigned i = 0; i < numTrackedCaches + 1; ++i) {
-        std::stringstream size_str;
-        printSize(size_str, minTrackedSize << i);
-        hits.subname(i, size_str.str());
-        hits.subdesc(i, "Hits in a " + size_str.str() + " cache");
-        misses.subname(i, size_str.str());
-        misses.subdesc(i, "Misses in a " + size_str.str() + " cache");
-    }
-}
index f24ac0e8c2ad8c5f5fb74e249e7f71f2f2a2573d..1d7e45abf629bd2290cf40599185db6fb55ebfba 100644 (file)
@@ -161,11 +161,6 @@ class FALRU : public BaseTags
      */
     void tagsInit() override;
 
-    /**
-     * Register the stats for this object.
-     */
-    void regStats() override;
-
     /**
      * Invalidate a cache block.
      * @param blk The block to invalidate.
@@ -278,23 +273,11 @@ class FALRU : public BaseTags
      * caches from a set minimum size of interest up to the actual
      * cache size.
      */
-    class CacheTracking
+    class CacheTracking : public Stats::Group
     {
       public:
         CacheTracking(unsigned min_size, unsigned max_size,
-                      unsigned block_size)
-            : blkSize(block_size),
-              minTrackedSize(min_size),
-              numTrackedCaches(max_size > min_size ?
-                               floorLog2(max_size) - floorLog2(min_size) : 0),
-              inAllCachesMask(mask(numTrackedCaches)),
-              boundaries(numTrackedCaches)
-        {
-            fatal_if(numTrackedCaches > sizeof(CachesMask) * 8,
-                     "Not enough bits (%s) in type CachesMask type to keep "
-                     "track of %d caches\n", sizeof(CachesMask),
-                     numTrackedCaches);
-        }
+                      unsigned block_size, Stats::Group *parent);
 
         /**
          * Initialiaze cache blocks and the tracking mechanism
@@ -352,11 +335,6 @@ class FALRU : public BaseTags
          */
         void check(const FALRUBlk *head, const FALRUBlk *tail) const;
 
-        /**
-         * Register the stats for this object.
-         */
-        void regStats(std::string name);
-
       private:
         /** The size of the cache block */
         const unsigned blkSize;