diff options
author | Daniel R. Carvalho <odanrc@yahoo.com.br> | 2019-02-15 14:48:19 +0100 |
---|---|---|
committer | Daniel Carvalho <odanrc@yahoo.com.br> | 2020-01-17 16:31:03 +0000 |
commit | 7ff32d7b53b1a699f4383d3c9c5279b6ab894d55 (patch) | |
tree | 2b6bfe945c7bf11530da0b5fd26873dbfe7b4f57 | |
parent | 7dce9e3782523e1b1989c50be194385b93603aea (diff) | |
download | gem5-7ff32d7b53b1a699f4383d3c9c5279b6ab894d55.tar.xz |
mem-cache: Add more compression stats
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>
-rw-r--r-- | src/mem/cache/compressors/base.cc | 53 | ||||
-rw-r--r-- | src/mem/cache/compressors/base.hh | 40 |
2 files changed, 60 insertions, 33 deletions
diff --git a/src/mem/cache/compressors/base.cc b/src/mem/cache/compressors/base.cc index 0016e4702..297c6a927 100644 --- a/src/mem/cache/compressors/base.cc +++ b/src/mem/cache/compressors/base.cc @@ -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; } diff --git a/src/mem/cache/compressors/base.hh b/src/mem/cache/compressors/base.hh index ea40b8dab..027b26c16 100644 --- a/src/mem/cache/compressors/base.hh +++ b/src/mem/cache/compressors/base.hh @@ -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 { |