Daniel Carvalho has submitted this change. ( https://gem5-review.googlesource.com/c/public/gem5/+/36580 )

Change subject: mem-cache: Set compression bit with its size
......................................................................

mem-cache: Set compression bit with its size

When setting the size of a compressed block, its compressibility
needs to be recalculated based on that, so move such functionality
to be done after the block has been inserted, within setSizeBits.

As a side effect, insertBlock does not need to be overridden
anymore.

Change-Id: I608f876cd2110ac5e394ffad5b29941ba458ba91
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/36580
Reviewed-by: Nikos Nikoleris <[email protected]>
Maintainer: Nikos Nikoleris <[email protected]>
Tested-by: kokoro <[email protected]>
---
M src/mem/cache/base.cc
M src/mem/cache/tags/compressed_tags.cc
M src/mem/cache/tags/compressed_tags.hh
M src/mem/cache/tags/super_blk.cc
4 files changed, 27 insertions(+), 53 deletions(-)

Approvals:
  Nikos Nikoleris: Looks good to me, approved; Looks good to me, approved
  kokoro: Regressions pass



diff --git a/src/mem/cache/base.cc b/src/mem/cache/base.cc
index 09c810a..98467ab 100644
--- a/src/mem/cache/base.cc
+++ b/src/mem/cache/base.cc
@@ -853,12 +853,6 @@
     CompressionBlk* compression_blk = static_cast<CompressionBlk*>(blk);
M5_VAR_USED const std::size_t prev_size = compression_blk->getSizeBits();

-    // Check if new data is co-allocatable
-    const SuperBlk* superblock =
-        static_cast<const SuperBlk*>(compression_blk->getSectorBlock());
- const bool is_co_allocatable = superblock->isCompressed(compression_blk) &&
-        superblock->canCoAllocate(compression_size);
-
// If compressed size didn't change enough to modify its co-allocatability
     // there is nothing to do. Otherwise we may be facing a data expansion
     // (block passing from more compressed to less compressed state), or a
@@ -909,7 +903,7 @@
         } else {
             // If we do not move the expanded block, we must make room for
             // the expansion to happen, so evict every co-allocated block
-            superblock = static_cast<const SuperBlk*>(
+            const SuperBlk* superblock = static_cast<const SuperBlk*>(
                 compression_blk->getSectorBlock());
             for (auto& sub_blk : superblock->blks) {
                 if (sub_blk->isValid() && (blk != sub_blk)) {
@@ -945,17 +939,6 @@
     compression_blk->setSizeBits(compression_size);
     compression_blk->setDecompressionLatency(decompression_lat);

-    if (is_data_expansion || is_data_contraction) {
-        // If contracting data, for sure data is compressed. If expanding,
- // both situations can arise. When no contraction or expansion happens
-        // block keeps its old state
-        if (is_co_allocatable) {
-            compression_blk->setCompressed();
-        } else {
-            compression_blk->setUncompressed();
-        }
-    }
-
     return true;
 }

@@ -1503,16 +1486,16 @@
         return nullptr;
     }

- // If using a compressor, set compression data. This must be done before
-    // block insertion, as compressed tags use this information.
+    // Insert new block at victimized entry
+    tags->insertBlock(pkt, victim);
+
+    // If using a compressor, set compression data. This must be done after
+    // insertion, as the compression bit may be set.
     if (compressor) {
         compressor->setSizeBits(victim, blk_size_bits);
         compressor->setDecompressionLatency(victim, decompression_lat);
     }

-    // Insert new block at victimized entry
-    tags->insertBlock(pkt, victim);
-
     return victim;
 }

diff --git a/src/mem/cache/tags/compressed_tags.cc b/src/mem/cache/tags/compressed_tags.cc
index 780c738..f71deda 100644
--- a/src/mem/cache/tags/compressed_tags.cc
+++ b/src/mem/cache/tags/compressed_tags.cc
@@ -165,28 +165,6 @@
 }

 void
-CompressedTags::insertBlock(const PacketPtr pkt, CacheBlk *blk)
-{
- // We check if block can co-allocate before inserting, because this check
-    // assumes the block is still invalid
-    CompressionBlk* compression_blk = static_cast<CompressionBlk*>(blk);
-    const SuperBlk* superblock = static_cast<const SuperBlk*>(
-        compression_blk->getSectorBlock());
-    const bool is_co_allocatable = superblock->isCompressed() &&
-        superblock->canCoAllocate(compression_blk->getSizeBits());
-
-    // Insert block
-    SectorTags::insertBlock(pkt, blk);
-
-    // We always store compressed blocks when possible
-    if (is_co_allocatable) {
-        compression_blk->setCompressed();
-    } else {
-        compression_blk->setUncompressed();
-    }
-}
-
-void
 CompressedTags::forEachBlk(std::function<void(CacheBlk &)> visitor)
 {
     for (CompressionBlk& blk : blks) {
diff --git a/src/mem/cache/tags/compressed_tags.hh b/src/mem/cache/tags/compressed_tags.hh
index 73231f2..306acd5 100644
--- a/src/mem/cache/tags/compressed_tags.hh
+++ b/src/mem/cache/tags/compressed_tags.hh
@@ -110,14 +110,6 @@
                          std::vector<CacheBlk*>& evict_blks) override;

     /**
-     * Insert the new block into the cache and update replacement data.
-     *
-     * @param pkt Packet holding the address to update
-     * @param blk The block to update.
-     */
-    void insertBlock(const PacketPtr pkt, CacheBlk *blk) override;
-
-    /**
      * Visit each sub-block in the tags and apply a visitor.
      *
      * The visitor should be a std::function that takes a cache block.
diff --git a/src/mem/cache/tags/super_blk.cc b/src/mem/cache/tags/super_blk.cc
index 9f7ce65..09bb207 100644
--- a/src/mem/cache/tags/super_blk.cc
+++ b/src/mem/cache/tags/super_blk.cc
@@ -93,6 +93,27 @@
 CompressionBlk::setSizeBits(const std::size_t size)
 {
     _size = size;
+
+    SuperBlk* superblock = static_cast<SuperBlk*>(getSectorBlock());
+
+    // Either this function is called after an insertion, or an update.
+    // If somebody else is present in the block, keep the superblock's
+    // compressibility. Otherwise, check if it can co-allocate
+    const uint8_t num_valid = superblock->getNumValid();
+    assert(num_valid >= 1);
+    if (num_valid == 1) {
+        if (superblock->canCoAllocate(size)) {
+            setCompressed();
+        } else {
+            setUncompressed();
+        }
+    } else {
+        if (superblock->isCompressed(this)) {
+            setCompressed();
+        } else {
+            setUncompressed();
+        }
+    }
 }

 Cycles

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/36580
To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: I608f876cd2110ac5e394ffad5b29941ba458ba91
Gerrit-Change-Number: 36580
Gerrit-PatchSet: 4
Gerrit-Owner: Daniel Carvalho <[email protected]>
Gerrit-Reviewer: Daniel Carvalho <[email protected]>
Gerrit-Reviewer: Nikos Nikoleris <[email protected]>
Gerrit-Reviewer: kokoro <[email protected]>
Gerrit-MessageType: merged
_______________________________________________
gem5-dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

Reply via email to