#include "mem/cache/compressors/base.hh"
#include <algorithm>
+#include <cmath>
#include <cstdint>
#include <string>
}
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");
}
}
// 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. " \
}
Cycles
-BaseCacheCompressor::getDecompressionLatency(const CacheBlk* blk) const
+BaseCacheCompressor::getDecompressionLatency(const CacheBlk* blk)
{
const CompressionBlk* comp_blk = static_cast<const CompressionBlk*>(blk);
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;
}
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;
}
* 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
*/
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.
*
* @param blk The compressed block.
*/
- Cycles getDecompressionLatency(const CacheBlk* blk) const;
+ Cycles getDecompressionLatency(const CacheBlk* blk);
/**
* Set the decompression latency of compressed block.
* @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 {