mem-cache: Limit compression size
authorDaniel R. Carvalho <odanrc@yahoo.com.br>
Wed, 21 Aug 2019 12:44:00 +0000 (14:44 +0200)
committerDaniel Carvalho <odanrc@yahoo.com.br>
Tue, 29 Oct 2019 21:32:02 +0000 (21:32 +0000)
Add a threshold so that if the compressed size is greater than it,
the compression is abandoned, and the data is considered uncompressible.

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

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

index b266ccc95492ad245b4074623ead680b54ea2287..4f86ec2825f483a1ccf5e35b497b4bec62b1bc92 100644 (file)
@@ -36,6 +36,9 @@ class BaseCacheCompressor(SimObject):
     cxx_header = "mem/cache/compressors/base.hh"
 
     block_size = Param.Int(Parent.cache_line_size, "Block size in bytes")
+    size_threshold = Param.Unsigned(Parent.cache_line_size, "Minimum size, "
+        "in bytes, in which a block must be compressed to. Otherwise it is "
+        "stored in its uncompressed state")
 
 class BDI(BaseCacheCompressor):
     type = 'BDI'
index 40244e2492accf39678f358a929c6b47335cd95c..0016e47020f600a5c53281326ee140bb8e541010 100644 (file)
@@ -73,8 +73,9 @@ BaseCacheCompressor::CompressionData::getSize() const
 }
 
 BaseCacheCompressor::BaseCacheCompressor(const Params *p)
-    : SimObject(p), blkSize(p->block_size)
+    : SimObject(p), blkSize(p->block_size), sizeThreshold(p->size_threshold)
 {
+    fatal_if(blkSize < sizeThreshold, "Compressed data must fit in a block");
 }
 
 void
@@ -98,8 +99,12 @@ BaseCacheCompressor::compress(const uint64_t* data, Cycles& comp_lat,
              "Decompressed line does not match original line.");
     #endif
 
-    // Get compression size
+    // Get compression size. If compressed size is greater than the size
+    // threshold, the compression is seen as unsuccessful
     comp_size_bits = comp_data->getSizeBits();
+    if (comp_size_bits >= sizeThreshold * 8) {
+        comp_size_bits = blkSize * 8;
+    }
 
     // Update stats
     compressionSize[std::ceil(std::log2(comp_size_bits))]++;
@@ -152,15 +157,14 @@ BaseCacheCompressor::regStats()
 {
     SimObject::regStats();
 
-    // We also store when compression is bigger than original block size
     compressionSize
-        .init(std::log2(blkSize*8) + 2)
+        .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) + 1; ++i) {
+    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");
index f457ecdc4b2af59ccede7815dcf7d15f1a90bade..19dec0fd37b2b3902a7931d40477c7939955f79e 100644 (file)
@@ -64,6 +64,12 @@ class BaseCacheCompressor : public SimObject {
      */
     const std::size_t blkSize;
 
+    /**
+     * Size in bytes at which a compression is classified as bad and therefore
+     * the compressed block is restored to its uncompressed format.
+     */
+    const std::size_t sizeThreshold;
+
     /**
      * @defgroup CompressionStats Compression specific statistics.
      * @{