mem-cache: Add more compression stats
authorDaniel R. Carvalho <odanrc@yahoo.com.br>
Fri, 15 Feb 2019 13:48:19 +0000 (14:48 +0100)
committerDaniel Carvalho <odanrc@yahoo.com.br>
Fri, 17 Jan 2020 16:31:03 +0000 (16:31 +0000)
Add stats to calculate the total number of compressions, decompressions
and the average compression size, in number of bits.

Change-Id: I5eb563856c1ff54216e1edcd2886332b7481cbfe
Signed-off-by: Daniel R. Carvalho <odanrc@yahoo.com.br>
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/22609
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Nikos Nikoleris <nikos.nikoleris@arm.com>
Maintainer: Nikos Nikoleris <nikos.nikoleris@arm.com>

src/mem/cache/compressors/base.cc
src/mem/cache/compressors/base.hh

index 0016e47020f600a5c53281326ee140bb8e541010..297c6a927ce14f4133dea52f5ca7dff0e72b5f5c 100644 (file)
@@ -35,6 +35,7 @@
 #include "mem/cache/compressors/base.hh"
 
 #include <algorithm>
+#include <cmath>
 #include <cstdint>
 #include <string>
 
@@ -73,7 +74,8 @@ BaseCacheCompressor::CompressionData::getSize() const
 }
 
 BaseCacheCompressor::BaseCacheCompressor(const Params *p)
-    : SimObject(p), blkSize(p->block_size), sizeThreshold(p->size_threshold)
+  : SimObject(p), blkSize(p->block_size), sizeThreshold(p->size_threshold),
+    stats(*this)
 {
     fatal_if(blkSize < sizeThreshold, "Compressed data must fit in a block");
 }
@@ -107,7 +109,9 @@ BaseCacheCompressor::compress(const uint64_t* data, Cycles& comp_lat,
     }
 
     // Update stats
-    compressionSize[std::ceil(std::log2(comp_size_bits))]++;
+    stats.compressions++;
+    stats.compressionSizeBits += comp_size_bits;
+    stats.compressionSize[std::ceil(std::log2(comp_size_bits))]++;
 
     // Print debug information
     DPRINTF(CacheComp, "Compressed cache line from %d to %d bits. " \
@@ -116,7 +120,7 @@ BaseCacheCompressor::compress(const uint64_t* data, Cycles& comp_lat,
 }
 
 Cycles
-BaseCacheCompressor::getDecompressionLatency(const CacheBlk* blk) const
+BaseCacheCompressor::getDecompressionLatency(const CacheBlk* blk)
 {
     const CompressionBlk* comp_blk = static_cast<const CompressionBlk*>(blk);
 
@@ -125,6 +129,7 @@ BaseCacheCompressor::getDecompressionLatency(const CacheBlk* blk) const
         const Cycles decomp_lat = comp_blk->getDecompressionLatency();
         DPRINTF(CacheComp, "Decompressing block: %s (%d cycles)\n",
                 comp_blk->print(), decomp_lat);
+        stats.decompressions += 1;
         return decomp_lat;
     }
 
@@ -152,22 +157,36 @@ BaseCacheCompressor::setSizeBits(CacheBlk* blk, const std::size_t size_bits)
     static_cast<CompressionBlk*>(blk)->setSizeBits(size_bits);
 }
 
+BaseCacheCompressor::BaseCacheCompressorStats::BaseCacheCompressorStats(
+    BaseCacheCompressor& _compressor)
+  : Stats::Group(&_compressor), compressor(_compressor),
+    compressions(this, "compressions",
+        "Total number of compressions"),
+    compressionSize(this, "compression_size",
+        "Number of blocks that were compressed to this power of two size"),
+    compressionSizeBits(this, "compression_size_bits",
+        "Total compressed data size, in bits"),
+    avgCompressionSizeBits(this, "avg_compression_size_bits",
+        "Average compression size, in bits"),
+    decompressions(this, "total_decompressions",
+        "Total number of decompressions")
+{
+}
+
 void
-BaseCacheCompressor::regStats()
+BaseCacheCompressor::BaseCacheCompressorStats::regStats()
 {
-    SimObject::regStats();
-
-    compressionSize
-        .init(std::log2(blkSize*8) + 1)
-        .name(name() + ".compression_size")
-        .desc("Number of blocks that were compressed to this power of" \
-              "two size.")
-        ;
-
-    for (unsigned i = 0; i <= std::log2(blkSize*8); ++i) {
-        compressionSize.subname(i, std::to_string(1 << i));
-        compressionSize.subdesc(i, "Number of blocks that compressed to fit " \
-                                   "in " + std::to_string(1 << i) + " bits");
+    Stats::Group::regStats();
+
+    compressionSize.init(std::log2(compressor.blkSize*8) + 1);
+    for (unsigned i = 0; i <= std::log2(compressor.blkSize*8); ++i) {
+        std::string str_i = std::to_string(1 << i);
+        compressionSize.subname(i, str_i);
+        compressionSize.subdesc(i,
+            "Number of blocks that compressed to fit in " + str_i + " bits");
     }
+
+    avgCompressionSizeBits.flags(Stats::total | Stats::nozero | Stats::nonan);
+    avgCompressionSizeBits = compressionSizeBits / compressions;
 }
 
index ea40b8dab7f26189167d27c151b1894c2f4c7073..027b26c16c414207e6b56e5afc3344d4759ecee1 100644 (file)
@@ -51,7 +51,8 @@ struct BaseCacheCompressorParams;
  * Base cache compressor interface. Every cache compressor must implement a
  * compression and a decompression method.
  */
-class BaseCacheCompressor : public SimObject {
+class BaseCacheCompressor : public SimObject
+{
   protected:
     /**
      * This compressor must be able to access the protected functions of
@@ -76,17 +77,29 @@ class BaseCacheCompressor : public SimObject {
      */
     const std::size_t sizeThreshold;
 
-    /**
-     * @defgroup CompressionStats Compression specific statistics.
-     * @{
-     */
+    struct BaseCacheCompressorStats : public Stats::Group
+    {
+        const BaseCacheCompressor& compressor;
 
-    /** Number of blocks that were compressed to this power of two size. */
-    Stats::Vector compressionSize;
+        BaseCacheCompressorStats(BaseCacheCompressor& compressor);
 
-    /**
-     * @}
-     */
+        void regStats() override;
+
+        /** Number of compressions performed. */
+        Stats::Scalar compressions;
+
+        /** Number of blocks that were compressed to this power of two size. */
+        Stats::Vector compressionSize;
+
+        /** Total compressed data size, in number of bits. */
+        Stats::Scalar compressionSizeBits;
+
+        /** Average data size after compression, in number of bits. */
+        Stats::Formula avgCompressionSizeBits;
+
+        /** Number of decompressions performed. */
+        Stats::Scalar decompressions;
+    } stats;
 
     /**
      * Apply the compression process to the cache line.
@@ -144,7 +157,7 @@ class BaseCacheCompressor : public SimObject {
      *
      * @param blk The compressed block.
      */
-    Cycles getDecompressionLatency(const CacheBlk* blk) const;
+    Cycles getDecompressionLatency(const CacheBlk* blk);
 
     /**
      * Set the decompression latency of compressed block.
@@ -161,11 +174,6 @@ class BaseCacheCompressor : public SimObject {
      * @param size_bits The block size.
      */
     static void setSizeBits(CacheBlk* blk, const std::size_t size_bits);
-
-    /**
-     * Register local statistics.
-     */
-    void regStats() override;
 };
 
 class BaseCacheCompressor::CompressionData {