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

Change subject: mem-cache: Add move assign and delete move constr of blk
......................................................................

mem-cache: Add move assign and delete move constr of blk

Some cache techniques may need to move a block's metadata information
into another block. This must have some limitations to avoid mistakes:
- The destination entry must be invalid, otherwise the replacement
  policy steps would be skipped.
- The source entry must be valid, otherwise there would be no point
  in moving their metadata contents.
- The entries locations (set, way, offset...) must not be moved, since
  they are fixed. The same principle is applied to the location specific
  variables, such as the replacement pointer

Why it would be used:
For example, when using compression, and a block goes from uncompressed
to compressed state due to an overwrite, after the tag lookup
(sequential access) it can be decided whether to store the new data in
the old location, or, since we might have already found the block's co-
allocatable blocks, move it to co-allocate.

Other examples of techniques that could use this functionality are
Skewed Compressed Caches, and ZCaches.

Change-Id: I96e4f8cc8c992c4b01f315251d1a75d51c28692c
Signed-off-by: Daniel R. Carvalho <[email protected]>
---
M src/mem/cache/cache_blk.hh
M src/mem/cache/tags/sector_blk.hh
M src/mem/cache/tags/super_blk.cc
M src/mem/cache/tags/super_blk.hh
4 files changed, 81 insertions(+), 4 deletions(-)



diff --git a/src/mem/cache/cache_blk.hh b/src/mem/cache/cache_blk.hh
index c16e599..f3f9725 100644
--- a/src/mem/cache/cache_blk.hh
+++ b/src/mem/cache/cache_blk.hh
@@ -155,6 +155,39 @@

     CacheBlk(const CacheBlk&) = delete;
     CacheBlk& operator=(const CacheBlk&) = delete;
+    CacheBlk(const CacheBlk&&) = delete;
+    /**
+     * Move assignment operator.
+     * This should only be used to move an existing valid entry into an
+     * invalid one, not to create a new entry. In the end the valid entry
+     * will become invalid, and the invalid, valid. All location related
+     * variables will remain the same, that is, an entry cannot move its
+     * data, just its metadata contents.
+     */
+    virtual CacheBlk&
+    operator=(CacheBlk&& other)
+    {
+        // Copying an entry into a valid one would imply in skipping all
+        // replacement steps, so it cannot be allowed
+        assert(!isValid());
+        assert(other.isValid());
+
+        insert(other.getTag(), other.isSecure());
+
+        if (other.wasPrefetched()) {
+            setPrefetched();
+        }
+        setCoherenceBits(other.coherence);
+        setTaskId(other.getTaskId());
+        setWhenReady(curTick());
+        setRefCount(other.getRefCount());
+        setSrcRequestorId(other.getSrcRequestorId());
+        std::swap(lockList, other.lockList);
+
+        other.invalidate();
+
+        return *this;
+    }
     virtual ~CacheBlk() {};

     /**
@@ -168,7 +201,7 @@
         clearCoherenceBits(AllBits);

         setTaskId(ContextSwitchTaskId::Unknown);
-        whenReady = MaxTick;
+        setWhenReady(MaxTick);
         setRefCount(0);
         setSrcRequestorId(Request::invldRequestorId);
         lockList.clear();
@@ -240,7 +273,7 @@
      */
     void setWhenReady(const Tick tick)
     {
-        assert(tick >= _tickInserted);
+        assert((tick >= _tickInserted) || (tick == MaxTick));
         whenReady = tick;
     }

diff --git a/src/mem/cache/tags/sector_blk.hh b/src/mem/cache/tags/sector_blk.hh
index ea3c79a..2d649cd 100644
--- a/src/mem/cache/tags/sector_blk.hh
+++ b/src/mem/cache/tags/sector_blk.hh
@@ -62,7 +62,17 @@
     SectorSubBlk() : CacheBlk(), _sectorBlk(nullptr), _sectorOffset(0) {}
     SectorSubBlk(const SectorSubBlk&) = delete;
     SectorSubBlk& operator=(const SectorSubBlk&) = delete;
-    ~SectorSubBlk() {};
+    SectorSubBlk(SectorSubBlk&&) = delete;
+    /**
+     * Move assignment operator.
+     * This should only be used to move an existing valid entry into an
+     * invalid one, not to create a new entry. In the end the valid entry
+     * will become invalid, and the invalid, valid. All location related
+     * variables will remain the same, that is, an entry cannot change
+     * its sector block nor its offset.
+     */
+    SectorSubBlk& operator=(SectorSubBlk&& other) = default;
+    ~SectorSubBlk() = default;

     /**
      * Set sector block associated to this block.
diff --git a/src/mem/cache/tags/super_blk.cc b/src/mem/cache/tags/super_blk.cc
index 0f570f9..a6d8afb 100644
--- a/src/mem/cache/tags/super_blk.cc
+++ b/src/mem/cache/tags/super_blk.cc
@@ -41,6 +41,30 @@
 {
 }

+CacheBlk&
+CompressionBlk::operator=(CacheBlk&& other)
+{
+    operator=(std::move(static_cast<CompressionBlk&&>(other)));
+    return *this;
+}
+
+CompressionBlk&
+CompressionBlk::operator=(CompressionBlk&& other)
+{
+ // Copy internal variables; if moving, that means we had an expansion or
+    // contraction, and therefore the size is no longer valid, so it is not
+    // moved
+    setDecompressionLatency(other.getDecompressionLatency());
+    if (other.isCompressed()) {
+        setCompressed();
+    } else {
+        setUncompressed();
+    }
+
+    CacheBlk::operator=(std::move(other));
+    return *this;
+}
+
 bool
 CompressionBlk::isCompressed() const
 {
diff --git a/src/mem/cache/tags/super_blk.hh b/src/mem/cache/tags/super_blk.hh
index bca3266..d7abe18 100644
--- a/src/mem/cache/tags/super_blk.hh
+++ b/src/mem/cache/tags/super_blk.hh
@@ -66,7 +66,17 @@
     CompressionBlk();
     CompressionBlk(const CompressionBlk&) = delete;
     CompressionBlk& operator=(const CompressionBlk&) = delete;
-    ~CompressionBlk() {};
+    CompressionBlk(CompressionBlk&&) = delete;
+    /**
+     * Move assignment operator.
+     * This should only be used to move an existing valid entry into an
+     * invalid one, not to create a new entry. In the end the valid entry
+     * will become invalid, and the invalid, valid. All location related
+     * variables will remain the same.
+     */
+    CompressionBlk& operator=(CompressionBlk&& other);
+    CacheBlk& operator=(CacheBlk&& other);
+    ~CompressionBlk() = default;

     /**
      * Check if this block holds compressed data.

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/36575
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: I96e4f8cc8c992c4b01f315251d1a75d51c28692c
Gerrit-Change-Number: 36575
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