From 584eba3ab66c8f95e2344cf7115ec2fb13604eb1 Mon Sep 17 00:00:00 2001 From: Lena Olson Date: Tue, 11 Sep 2012 14:14:49 -0400 Subject: [PATCH] Cache: Split invalidateBlk up to seperate block vs. tags 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 | 10 ++++++++++ src/mem/cache/cache_impl.hh | 34 ++++++++++++++++++++++------------ src/mem/cache/tags/fa_lru.cc | 9 +++------ src/mem/cache/tags/fa_lru.hh | 2 +- src/mem/cache/tags/iic.cc | 2 +- src/mem/cache/tags/iic.hh | 2 +- src/mem/cache/tags/lru.cc | 32 +++++++++++++++----------------- src/mem/cache/tags/lru.hh | 2 +- 8 files changed, 54 insertions(+), 39 deletions(-) diff --git a/src/mem/cache/blk.hh b/src/mem/cache/blk.hh index 91970e09b..73f569e6a 100644 --- a/src/mem/cache/blk.hh +++ b/src/mem/cache/blk.hh @@ -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. diff --git a/src/mem/cache/cache_impl.hh b/src/mem/cache/cache_impl.hh index 2fdbc5c1d..563160ac1 100644 --- a/src/mem/cache/cache_impl.hh +++ b/src/mem/cache/cache_impl.hh @@ -170,7 +170,9 @@ Cache::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::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::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::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::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::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::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::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::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(); } } diff --git a/src/mem/cache/tags/fa_lru.cc b/src/mem/cache/tags/fa_lru.cc index 3a1246ce7..cc2f12eef 100644 --- a/src/mem/cache/tags/fa_lru.cc +++ b/src/mem/cache/tags/fa_lru.cc @@ -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* diff --git a/src/mem/cache/tags/fa_lru.hh b/src/mem/cache/tags/fa_lru.hh index fa1f49a42..66f70a89b 100644 --- a/src/mem/cache/tags/fa_lru.hh +++ b/src/mem/cache/tags/fa_lru.hh @@ -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 diff --git a/src/mem/cache/tags/iic.cc b/src/mem/cache/tags/iic.cc index 3fdc11e80..e8b0a1b29 100644 --- a/src/mem/cache/tags/iic.cc +++ b/src/mem/cache/tags/iic.cc @@ -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) { diff --git a/src/mem/cache/tags/iic.hh b/src/mem/cache/tags/iic.hh index fd63daff7..97011d1c5 100644 --- a/src/mem/cache/tags/iic.hh +++ b/src/mem/cache/tags/iic.hh @@ -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 diff --git a/src/mem/cache/tags/lru.cc b/src/mem/cache/tags/lru.cc index c73f557b9..8d32d4b35 100644 --- a/src/mem/cache/tags/lru.cc +++ b/src/mem/cache/tags/lru.cc @@ -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 diff --git a/src/mem/cache/tags/lru.hh b/src/mem/cache/tags/lru.hh index 4eb66b708..bb1420f71 100644 --- a/src/mem/cache/tags/lru.hh +++ b/src/mem/cache/tags/lru.hh @@ -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 -- 2.30.2