mem-cache: Add helper function to perform evictions
authorNikos Nikoleris <nikos.nikoleris@arm.com>
Fri, 4 May 2018 15:54:48 +0000 (16:54 +0100)
committerNikos Nikoleris <nikos.nikoleris@arm.com>
Thu, 31 May 2018 15:11:23 +0000 (15:11 +0000)
Change-Id: I2df24eb1a8516220bec9b685c8c09bf55be18681
Reviewed-on: https://gem5-review.googlesource.com/10430
Maintainer: Nikos Nikoleris <nikos.nikoleris@arm.com>
Reviewed-by: Jason Lowe-Power <jason@lowepower.com>
src/mem/cache/cache.cc
src/mem/cache/cache.hh

index c755fb29ce366c2848e789c1425ca9abbe4e5c0d..79196e8be0e993cf77e4a11f2350f204dc650eed 100644 (file)
@@ -303,11 +303,7 @@ Cache::access(PacketPtr pkt, CacheBlk *&blk, Cycles &lat,
         // flush and invalidate any existing block
         CacheBlk *old_blk(tags->findBlock(pkt->getAddr(), pkt->isSecure()));
         if (old_blk && old_blk->isValid()) {
-            if (old_blk->isDirty() || writebackClean)
-                writebacks.push_back(writebackBlk(old_blk));
-            else
-                writebacks.push_back(cleanEvictBlk(old_blk));
-            invalidateBlock(old_blk);
+            evictBlock(old_blk, writebacks);
         }
 
         blk = nullptr;
@@ -1248,9 +1244,7 @@ Cache::recvAtomic(PacketPtr pkt)
             schedule(writebackTempBlockAtomicEvent, curTick());
         }
 
-        tempBlockWriteback = (blk->isDirty() || writebackClean) ?
-            writebackBlk(blk) : cleanEvictBlk(blk);
-        invalidateBlock(blk);
+        tempBlockWriteback = evictBlock(blk);
     }
 
     if (pkt->needsResponse()) {
@@ -1643,10 +1637,7 @@ Cache::recvTimingResp(PacketPtr pkt)
 
     // if we used temp block, check to see if its valid and then clear it out
     if (blk == tempBlock && tempBlock->isValid()) {
-        PacketPtr wb_pkt = tempBlock->isDirty() || writebackClean ?
-            writebackBlk(blk) : cleanEvictBlk(blk);
-        writebacks.push_back(wb_pkt);
-        invalidateBlock(tempBlock);
+        evictBlock(blk, writebacks);
     }
 
     const Tick forward_time = clockEdge(forwardLatency) + pkt->headerDelay;
@@ -1657,6 +1648,26 @@ Cache::recvTimingResp(PacketPtr pkt)
     delete pkt;
 }
 
+PacketPtr
+Cache::evictBlock(CacheBlk *blk)
+{
+    PacketPtr pkt = (blk->isDirty() || writebackClean) ?
+        writebackBlk(blk) : cleanEvictBlk(blk);
+
+    invalidateBlock(blk);
+
+    return pkt;
+}
+
+void
+Cache::evictBlock(CacheBlk *blk, PacketList &writebacks)
+{
+    PacketPtr pkt = evictBlock(blk);
+    if (pkt) {
+        writebacks.push_back(pkt);
+    }
+}
+
 PacketPtr
 Cache::writebackBlk(CacheBlk *blk)
 {
@@ -1850,15 +1861,7 @@ Cache::allocateBlock(Addr addr, bool is_secure, PacketList &writebacks)
             if (blk->wasPrefetched()) {
                 unusedPrefetches++;
             }
-            // Will send up Writeback/CleanEvict snoops via isCachedAbove
-            // when pushing this writeback list into the write buffer.
-            if (blk->isDirty() || writebackClean) {
-                // Save writeback packet for handling by caller
-                writebacks.push_back(writebackBlk(blk));
-            } else {
-                writebacks.push_back(cleanEvictBlk(blk));
-            }
-            invalidateBlock(blk);
+            evictBlock(blk, writebacks);
             replacements++;
         }
     }
index 4a56f14f123fb9e00caaccf3c0cc3c7f13a2f8bf..86ec2a2a5629bbcc38c7b96b8a62ee2799b08424 100644 (file)
@@ -495,6 +495,26 @@ class Cache : public BaseCache
     uint32_t handleSnoop(PacketPtr pkt, CacheBlk *blk,
                          bool is_timing, bool is_deferred, bool pending_inval);
 
+    /**
+     * Evict a cache block.
+     *
+     * Performs a writeback if necesssary and invalidates the block
+     *
+     * @param blk Block to invalidate
+     * @return A packet with the writeback, can be nullptr
+     */
+    M5_NODISCARD virtual PacketPtr evictBlock(CacheBlk *blk);
+
+    /**
+     * Evict a cache block.
+     *
+     * Performs a writeback if necesssary and invalidates the block
+     *
+     * @param blk Block to invalidate
+     * @param writebacks Return a list of packets with writebacks
+     */
+    virtual void evictBlock(CacheBlk *blk, PacketList &writebacks);
+
     /**
      * Create a writeback request for the given block.
      * @param blk The block to writeback.