Cache: Split invalidateBlk up to seperate block vs. tags
authorLena Olson <lena@cs.wisc.edu>
Tue, 11 Sep 2012 18:14:49 +0000 (14:14 -0400)
committerLena Olson <lena@cs.wisc.edu>
Tue, 11 Sep 2012 18:14:49 +0000 (14:14 -0400)
This seperates the functionality to clear the state in a block into
blk.hh and the functionality to udpate the tag information into the
tags.  This gets rid of the case where calling invalidateBlk on an
already-invalid block does something different than calling it on a
valid block, which was confusing.

src/mem/cache/blk.hh
src/mem/cache/cache_impl.hh
src/mem/cache/tags/fa_lru.cc
src/mem/cache/tags/fa_lru.hh
src/mem/cache/tags/iic.cc
src/mem/cache/tags/iic.hh
src/mem/cache/tags/lru.cc
src/mem/cache/tags/lru.hh

index 91970e09bd4b8ca5bcacdf59d2a8f8b28c07341b..73f569e6acc5c363d346cef693d5e66209b7c1fb 100644 (file)
@@ -188,6 +188,16 @@ class CacheBlk
         return (status & BlkValid) != 0;
     }
 
+    /**
+     * Invalidate the block and clear all state.
+     */
+    void invalidate()
+    {
+        status = 0;
+        isTouched = false;
+        clearLoadLocks();
+    }
+
     /**
      * Check to see if a block has been written.
      * @return True if the block is dirty.
index 2fdbc5c1dbaf16de33bf2cecf676eaa63deb5275..563160ac18f3d0965e4576f3131777dd0fcc8057 100644 (file)
@@ -170,7 +170,9 @@ Cache<TagStore>::satisfyCpuSideRequest(PacketPtr pkt, BlkType *blk,
                     pkt->assertMemInhibit();
                 }
                 // on ReadExReq we give up our copy unconditionally
-                tags->invalidateBlk(blk);
+                assert(blk != tempBlock);
+                tags->invalidate(blk);
+                blk->invalidate();
             } else if (blk->isWritable() && !pending_downgrade
                       && !pkt->sharedAsserted() && !pkt->req->isInstFetch()) {
                 // we can give the requester an exclusive copy (by not
@@ -210,7 +212,9 @@ Cache<TagStore>::satisfyCpuSideRequest(PacketPtr pkt, BlkType *blk,
         // to just ack those as long as we have an exclusive
         // copy at this level.
         assert(pkt->isUpgrade());
-        tags->invalidateBlk(blk);
+        assert(blk != tempBlock);
+        tags->invalidate(blk);
+        blk->invalidate();
     }
 }
 
@@ -280,7 +284,8 @@ Cache<TagStore>::access(PacketPtr pkt, BlkType *&blk,
         } else if (pkt->isWrite()) {
            blk = tags->findBlock(pkt->getAddr());
            if (blk != NULL) {
-               tags->invalidateBlk(blk);
+               tags->invalidate(blk);
+               blk->invalidate();
            }
         }
 
@@ -444,7 +449,8 @@ Cache<TagStore>::timingAccess(PacketPtr pkt)
         } else if (pkt->isWrite()) {
             BlkType *blk = tags->findBlock(pkt->getAddr());
             if (blk != NULL) {
-                tags->invalidateBlk(blk);
+                tags->invalidate(blk);
+                blk->invalidate();
             }
         }
 
@@ -644,7 +650,8 @@ Cache<TagStore>::atomicAccess(PacketPtr pkt)
         if (pkt->isInvalidate()) {
             BlkType *blk = tags->findBlock(pkt->getAddr());
             if (blk && blk->isValid()) {
-                tags->invalidateBlk(blk);
+                tags->invalidate(blk);
+                blk->invalidate();
                 DPRINTF(Cache, "rcvd mem-inhibited %s on 0x%x: invalidating\n",
                         pkt->cmdString(), pkt->getAddr());
             }
@@ -953,9 +960,11 @@ Cache<TagStore>::handleResponse(PacketPtr pkt)
         mshr->popTarget();
     }
 
-    if (blk) {
+    if (blk && blk->isValid()) {
         if (pkt->isInvalidate() || mshr->hasPostInvalidate()) {
-            tags->invalidateBlk(blk);
+            assert(blk != tempBlock);
+            tags->invalidate(blk);
+            blk->invalidate();
         } else if (mshr->hasPostDowngrade()) {
             blk->status &= ~BlkWritable;
         }
@@ -988,8 +997,7 @@ Cache<TagStore>::handleResponse(PacketPtr pkt)
         if (blk->isDirty()) {
             allocateWriteBuffer(writebackBlk(blk), time, true);
         }
-        blk->status &= ~BlkValid;
-        tags->invalidateBlk(blk);
+        blk->invalidate();
     }
 
     delete pkt;
@@ -1087,8 +1095,8 @@ Cache<TagStore>::handleFill(PacketPtr pkt, BlkType *blk,
             tags->insertBlock(pkt->getAddr(), blk, id);
         }
 
-        // starting from scratch with a new block
-        blk->status = 0;
+        // we should never be overwriting a valid block
+        assert(!blk->isValid());
     } else {
         // existing block... probably an upgrade
         assert(blk->tag == tags->extractTag(addr));
@@ -1259,7 +1267,9 @@ Cache<TagStore>::handleSnoop(PacketPtr pkt, BlkType *blk,
     // Do this last in case it deallocates block data or something
     // like that
     if (invalidate) {
-        tags->invalidateBlk(blk);
+        assert(blk != tempBlock);
+        tags->invalidate(blk);
+        blk->invalidate();
     }
 }
 
index 3a1246ce71a91624c01b54b8aa80111dc8605d85..cc2f12eefd78bb34f04564670f26dc2f8bda5d10 100644 (file)
@@ -152,13 +152,10 @@ FALRU::hashLookup(Addr addr) const
 }
 
 void
-FALRU::invalidateBlk(FALRU::BlkType *blk)
+FALRU::invalidate(FALRU::BlkType *blk)
 {
-    if (blk) {
-        blk->status = 0;
-        blk->isTouched = false;
-        tagsInUse--;
-    }
+    assert(blk);
+    tagsInUse--;
 }
 
 FALRUBlk*
index fa1f49a42f45f05e8019caf2de04b5f984f9a8fd..66f70a89bbf6b59cab6ee694e75c15bf4400017a 100644 (file)
@@ -168,7 +168,7 @@ public:
      * Invalidate a cache block.
      * @param blk The block to invalidate.
      */
-    void invalidateBlk(BlkType *blk);
+    void invalidate(BlkType *blk);
 
     /**
      * Access block and update replacement data.  May not succeed, in which case
index 3fdc11e80522e0103b8779f202c91356e14c7c28..e8b0a1b296c3c7ae3a40927dbc0b53fa88bc60f4 100644 (file)
@@ -617,7 +617,7 @@ IIC::secondaryChain(Addr tag, unsigned long chain_ptr,
 }
 
 void
-IIC::invalidateBlk(IIC::BlkType *tag_ptr)
+IIC::invalidate(IIC::BlkType *tag_ptr)
 {
     if (tag_ptr) {
         for (int i = 0; i < tag_ptr->numData; ++i) {
index fd63daff716c423587662ba6424d2edcbe621cfe..97011d1c5141d55aa129d5b7a96443d6f3c506f7 100644 (file)
@@ -408,7 +408,7 @@ class IIC : public BaseTags
      * Invalidate a block.
      * @param blk The block to invalidate.
      */
-    void invalidateBlk(BlkType *blk);
+    void invalidate(BlkType *blk);
 
     /**
      * Access block and update replacement data.  May not succeed, in which case
index c73f557b9dcef054bda0ab213a21ffda81ebf3ab..8d32d4b351c6e5b933c4e54eaa488cdf19bf5e1a 100644 (file)
@@ -92,7 +92,7 @@ LRU::LRU(unsigned _numSets, unsigned _blkSize, unsigned _assoc,
             ++blkIndex;
 
             // invalidate new cache block
-            blk->status = 0;
+            blk->invalidate();
 
             //EGH Fix Me : do we need to initialize blk?
 
@@ -186,8 +186,11 @@ LRU::insertBlock(Addr addr, BlkType *blk, int master_id)
         // deal with evicted block
         assert(blk->srcMasterId < cache->system->maxMasters());
         occupancies[blk->srcMasterId]--;
+
+        blk->invalidate();
     }
 
+    blk->isTouched = true;
     // Set tag for new block.  Caller is responsible for setting status.
     blk->tag = extractTag(addr);
 
@@ -201,23 +204,18 @@ LRU::insertBlock(Addr addr, BlkType *blk, int master_id)
 }
 
 void
-LRU::invalidateBlk(BlkType *blk)
+LRU::invalidate(BlkType *blk)
 {
-    if (blk) {
-        if (blk->isValid()) {
-            tagsInUse--;
-            assert(blk->srcMasterId < cache->system->maxMasters());
-            occupancies[blk->srcMasterId]--;
-            blk->srcMasterId = Request::invldMasterId;
-        }
-        blk->status = 0;
-        blk->isTouched = false;
-        blk->clearLoadLocks();
-
-        // should be evicted before valid blocks
-        unsigned set = blk->set;
-        sets[set].moveToTail(blk);
-    }
+    assert(blk);
+    assert(blk->isValid());
+    tagsInUse--;
+    assert(blk->srcMasterId < cache->system->maxMasters());
+    occupancies[blk->srcMasterId]--;
+    blk->srcMasterId = Request::invldMasterId;
+
+    // should be evicted before valid blocks
+    unsigned set = blk->set;
+    sets[set].moveToTail(blk);
 }
 
 void
index 4eb66b708d043d8a0e32041ef9a65c7478eb9c0e..bb1420f7109d4fefb9d25b97a78df59d700b3591 100644 (file)
@@ -127,7 +127,7 @@ public:
      * Invalidate the given block.
      * @param blk The block to invalidate.
      */
-    void invalidateBlk(BlkType *blk);
+    void invalidate(BlkType *blk);
 
     /**
      * Access block and update replacement data.  May not succeed, in which case