cache: improve coherence handling of writebacks
authorSteve Reinhardt <steve.reinhardt@amd.com>
Wed, 22 Sep 2010 06:07:34 +0000 (23:07 -0700)
committerSteve Reinhardt <steve.reinhardt@amd.com>
Wed, 22 Sep 2010 06:07:34 +0000 (23:07 -0700)
If we write back an exclusive copy, we now mark it
as such, so the cache receiving the writeback can
mark its copy as exclusive.  This avoids some
unnecessary upgrade requests when a cache later
tries to re-acquire exclusive access to the block.

src/mem/cache/cache_impl.hh
src/mem/packet.hh

index 4f4d720b6ccb2b75f2888fa977b0645128c579d1..86bf79b7b77174ac1e8f53ffd5d4554281fe7b9d 100644 (file)
@@ -360,6 +360,9 @@ Cache<TagStore>::access(PacketPtr pkt, BlkType *&blk,
         }
         std::memcpy(blk->data, pkt->getPtr<uint8_t>(), blkSize);
         blk->status |= BlkDirty;
+        if (pkt->isSupplyExclusive()) {
+            blk->status |= BlkWritable;
+        }
         // nothing else to do; writeback doesn't expect response
         assert(!pkt->needsResponse());
         incHitCount(pkt, id);
@@ -1007,6 +1010,9 @@ Cache<TagStore>::writebackBlk(BlkType *blk)
     Request *writebackReq =
         new Request(tags->regenerateBlkAddr(blk->tag, blk->set), blkSize, 0);
     PacketPtr writeback = new Packet(writebackReq, MemCmd::Writeback, -1);
+    if (blk->isWritable()) {
+        writeback->setSupplyExclusive();
+    }
     writeback->allocate();
     std::memcpy(writeback->getPtr<uint8_t>(), blk->data, blkSize);
 
@@ -1307,6 +1313,8 @@ Cache<TagStore>::snoopTiming(PacketPtr pkt)
             pkt->assertMemInhibit();
             if (!pkt->needsExclusive()) {
                 pkt->assertShared();
+                // the writeback is no longer the exclusive copy in the system
+                wb_pkt->clearSupplyExclusive();
             } else {
                 // if we're not asserting the shared line, we need to
                 // invalidate our copy.  we'll do that below as long as
index cefb7c2edaa14596c47bf54b07d0076afa1189f6..48b80879e6b72ea495e0bde149f394af967bfbe7 100644 (file)
@@ -422,6 +422,7 @@ class Packet : public FastAlloc, public Printable
     void setExpressSnoop()      { flags.set(EXPRESS_SNOOP); }
     bool isExpressSnoop()       { return flags.isSet(EXPRESS_SNOOP); }
     void setSupplyExclusive()   { flags.set(SUPPLY_EXCLUSIVE); }
+    void clearSupplyExclusive() { flags.clear(SUPPLY_EXCLUSIVE); }
     bool isSupplyExclusive()    { return flags.isSet(SUPPLY_EXCLUSIVE); }
 
     // Network error conditions... encapsulate them as methods since