Daniel Carvalho has uploaded this change for review. ( https://gem5-review.googlesource.com/c/public/gem5/+/36576 )

Change subject: mem-cache: Add function to move blocks in the tags
......................................................................

mem-cache: Add function to move blocks in the tags

Add a function to allow moving a block's metadata from a source
entry to an invalid destination entry.

Change-Id: I7c8adbcd1133c907f1eea7f69dca983215bc3960
Signed-off-by: Daniel R. Carvalho <[email protected]>
---
M src/mem/cache/tags/base.cc
M src/mem/cache/tags/base.hh
M src/mem/cache/tags/base_set_assoc.cc
M src/mem/cache/tags/base_set_assoc.hh
M src/mem/cache/tags/fa_lru.cc
M src/mem/cache/tags/fa_lru.hh
M src/mem/cache/tags/sector_tags.cc
M src/mem/cache/tags/sector_tags.hh
8 files changed, 90 insertions(+), 0 deletions(-)



diff --git a/src/mem/cache/tags/base.cc b/src/mem/cache/tags/base.cc
index b00ad49..edd85a4 100644
--- a/src/mem/cache/tags/base.cc
+++ b/src/mem/cache/tags/base.cc
@@ -123,6 +123,19 @@
     stats.dataAccesses += 1;
 }

+void
+BaseTags::moveBlock(CacheBlk *src_blk, CacheBlk *dest_blk)
+{
+    assert(!dest_blk->isValid());
+    assert(src_blk->isValid());
+
+    // Move src's contents to dest's
+    *dest_blk = std::move(*src_blk);
+
+    assert(dest_blk->isValid());
+    assert(!src_blk->isValid());
+}
+
 Addr
 BaseTags::extractTag(const Addr addr) const
 {
diff --git a/src/mem/cache/tags/base.hh b/src/mem/cache/tags/base.hh
index deda63e..5a407a6 100644
--- a/src/mem/cache/tags/base.hh
+++ b/src/mem/cache/tags/base.hh
@@ -309,6 +309,16 @@
     virtual void insertBlock(const PacketPtr pkt, CacheBlk *blk);

     /**
+ * Move a block's metadata to another location decided by the replacement
+     * policy. It behaves as a swap, however, since the destination block
+     * should be invalid, the result is a move.
+     *
+     * @param src_blk The source block.
+     * @param dest_blk The destination block. Must be invalid.
+     */
+    virtual void moveBlock(CacheBlk *src_blk, CacheBlk *dest_blk);
+
+    /**
      * Regenerate the block address.
      *
      * @param block The block.
diff --git a/src/mem/cache/tags/base_set_assoc.cc b/src/mem/cache/tags/base_set_assoc.cc
index cc2fac6..9f9a261 100644
--- a/src/mem/cache/tags/base_set_assoc.cc
+++ b/src/mem/cache/tags/base_set_assoc.cc
@@ -91,6 +91,18 @@
     replacementPolicy->invalidate(blk->replacementData);
 }

+void
+BaseSetAssoc::moveBlock(CacheBlk *src_blk, CacheBlk *dest_blk)
+{
+    BaseTags::moveBlock(src_blk, dest_blk);
+
+    // Since the blocks were using different replacement data pointers,
+    // we must touch the replacement data of the new entry, and invalidate
+    // the one that is being moved.
+    replacementPolicy->invalidate(src_blk->replacementData);
+    replacementPolicy->touch(dest_blk->replacementData);
+}
+
 BaseSetAssoc *
 BaseSetAssocParams::create() const
 {
diff --git a/src/mem/cache/tags/base_set_assoc.hh b/src/mem/cache/tags/base_set_assoc.hh
index 787cc6b..b13b007 100644
--- a/src/mem/cache/tags/base_set_assoc.hh
+++ b/src/mem/cache/tags/base_set_assoc.hh
@@ -199,6 +199,8 @@
         replacementPolicy->reset(blk->replacementData);
     }

+    void moveBlock(CacheBlk *src_blk, CacheBlk *dest_blk) override;
+
     /**
      * Limit the allocation for the cache ways.
      * @param ways The maximum number of ways available for replacement.
diff --git a/src/mem/cache/tags/fa_lru.cc b/src/mem/cache/tags/fa_lru.cc
index fc69bda..1ded22f 100644
--- a/src/mem/cache/tags/fa_lru.cc
+++ b/src/mem/cache/tags/fa_lru.cc
@@ -226,6 +226,12 @@
 }

 void
+FALRU::moveBlock(CacheBlk *src_blk, CacheBlk *dest_blk)
+{
+    panic("Moving blocks in FALRU has not been implemented");
+}
+
+void
 FALRU::moveToHead(FALRUBlk *blk)
 {
     // If block is not already head, do the moving
diff --git a/src/mem/cache/tags/fa_lru.hh b/src/mem/cache/tags/fa_lru.hh
index f03ecee..f24ac0e 100644
--- a/src/mem/cache/tags/fa_lru.hh
+++ b/src/mem/cache/tags/fa_lru.hh
@@ -232,6 +232,8 @@
      */
     void insertBlock(const PacketPtr pkt, CacheBlk *blk) override;

+    void moveBlock(CacheBlk *src_blk, CacheBlk *dest_blk) override;
+
     /**
* Generate the tag from the addres. For fully associative this is just the
      * block address.
diff --git a/src/mem/cache/tags/sector_tags.cc b/src/mem/cache/tags/sector_tags.cc
index aa6cb24..c249293 100644
--- a/src/mem/cache/tags/sector_tags.cc
+++ b/src/mem/cache/tags/sector_tags.cc
@@ -125,6 +125,7 @@
     if (!sector_blk->isValid()) {
         // Decrease the number of tags in use
         stats.tagsInUse--;
+        assert(stats.tagsInUse.value() >= 0);

         // Invalidate replacement data, as we're invalidating the sector
         replacementPolicy->invalidate(sector_blk->replacementData);
@@ -183,6 +184,7 @@
     } else {
         // Increment tag counter
         stats.tagsInUse++;
+        assert(stats.tagsInUse.value() <= numSectors);

         // A new entry resets the replacement data
         replacementPolicy->reset(sector_blk->replacementData);
@@ -192,6 +194,47 @@
     BaseTags::insertBlock(pkt, blk);
 }

+void
+SectorTags::moveBlock(CacheBlk *src_blk, CacheBlk *dest_blk)
+{
+    const bool dest_was_valid =
+        static_cast<SectorSubBlk*>(dest_blk)->getSectorBlock()->isValid();
+
+    BaseTags::moveBlock(src_blk, dest_blk);
+
+ // Get blocks' sectors. The blocks have effectively been swapped by now,
+    // so src points to an invalid block, and dest to the moved valid one.
+    SectorSubBlk* src_sub_blk = static_cast<SectorSubBlk*>(src_blk);
+    const SectorBlk* src_sector_blk = src_sub_blk->getSectorBlock();
+    SectorSubBlk* dest_sub_blk = static_cast<SectorSubBlk*>(dest_blk);
+    const SectorBlk* dest_sector_blk = dest_sub_blk->getSectorBlock();
+
+    // Since the blocks were using different replacement data pointers,
+    // we must touch the replacement data of the new entry, and invalidate
+    // the one that is being moved.
+    // When a block in a sector is invalidated, it does not make the tag
+    // invalid automatically, as there might be other blocks in the sector
+    // using it. The tag is invalidated only when there is a single block
+    // in the sector.
+    if (!src_sector_blk->isValid()) {
+        // Invalidate replacement data, as we're invalidating the sector
+        replacementPolicy->invalidate(src_sector_blk->replacementData);
+
+        if (dest_was_valid) {
+ // If destination sector was valid, and the source sector became
+            // invalid, there is one less tag being used
+            stats.tagsInUse--;
+            assert(stats.tagsInUse.value() >= 0);
+        }
+    } else if (!dest_was_valid) {
+ // If destination sector was invalid and became valid, and the source
+        // sector is still valid, there is one extra tag being used
+        stats.tagsInUse++;
+        assert(stats.tagsInUse.value() <= numSectors);
+    }
+    replacementPolicy->touch(dest_sector_blk->replacementData);
+}
+
 CacheBlk*
 SectorTags::findBlock(Addr addr, bool is_secure) const
 {
diff --git a/src/mem/cache/tags/sector_tags.hh b/src/mem/cache/tags/sector_tags.hh
index c56ef24..5c228ee 100644
--- a/src/mem/cache/tags/sector_tags.hh
+++ b/src/mem/cache/tags/sector_tags.hh
@@ -149,6 +149,8 @@
      */
     void insertBlock(const PacketPtr pkt, CacheBlk *blk) override;

+    void moveBlock(CacheBlk *src_blk, CacheBlk *dest_blk) override;
+
     /**
* Finds the given address in the cache, do not update replacement data.
      * i.e. This is a no-side-effect find of a block.

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/36576
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: I7c8adbcd1133c907f1eea7f69dca983215bc3960
Gerrit-Change-Number: 36576
Gerrit-PatchSet: 1
Gerrit-Owner: Daniel Carvalho <[email protected]>
Gerrit-MessageType: newchange
_______________________________________________
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