Merge from head.
[gem5.git] / src / mem / cache / tags / lru.cc
index 556025a3ab0f25fbb2442d1565fa38935f41b217..0a8587c2061647388d846c93e4150385683a78b2 100644 (file)
 #include "mem/cache/base_cache.hh"
 #include "base/intmath.hh"
 #include "mem/cache/tags/lru.hh"
-#include "sim/root.hh"
+#include "sim/core.hh"
 
 using namespace std;
 
 LRUBlk*
-CacheSet::findBlk(int asid, Addr tag) const
+CacheSet::findBlk(Addr tag) const
 {
     for (int i = 0; i < assoc; ++i) {
         if (blks[i]->tag == tag && blks[i]->isValid()) {
@@ -135,7 +135,6 @@ LRU::LRU(int _numSets, int _blkSize, int _assoc, int _hit_latency) :
             // table; won't matter because the block is invalid
             blk->tag = j;
             blk->whenReady = 0;
-            blk->asid = -1;
             blk->isTouched = false;
             blk->size = blkSize;
             sets[i].blks[j]=blk;
@@ -153,27 +152,29 @@ LRU::~LRU()
 
 // probe cache for presence of given block.
 bool
-LRU::probe(int asid, Addr addr) const
+LRU::probe(Addr addr) const
 {
     //  return(findBlock(Read, addr, asid) != 0);
     Addr tag = extractTag(addr);
     unsigned myset = extractSet(addr);
 
-    LRUBlk *blk = sets[myset].findBlk(asid, tag);
+    LRUBlk *blk = sets[myset].findBlk(tag);
 
     return (blk != NULL);      // true if in cache
 }
 
 LRUBlk*
-LRU::findBlock(Addr addr, int asid, int &lat)
+LRU::findBlock(Addr addr, int &lat)
 {
     Addr tag = extractTag(addr);
     unsigned set = extractSet(addr);
-    LRUBlk *blk = sets[set].findBlk(asid, tag);
+    LRUBlk *blk = sets[set].findBlk(tag);
     lat = hitLatency;
     if (blk != NULL) {
         // move this block to head of the MRU list
         sets[set].moveToHead(blk);
+        DPRINTF(CacheRepl, "set %x: moving blk %x to MRU\n",
+                set, regenerateBlkAddr(tag, set));
         if (blk->whenReady > curTick
             && blk->whenReady - curTick > hitLatency) {
             lat = blk->whenReady - curTick;
@@ -184,43 +185,20 @@ LRU::findBlock(Addr addr, int asid, int &lat)
     return blk;
 }
 
-LRUBlk*
-LRU::findBlock(Packet * &pkt, int &lat)
-{
-    Addr addr = pkt->getAddr();
-    int asid = 0;//pkt->req->getAsid();
-
-    Addr tag = extractTag(addr);
-    unsigned set = extractSet(addr);
-    LRUBlk *blk = sets[set].findBlk(asid, tag);
-    lat = hitLatency;
-    if (blk != NULL) {
-        // move this block to head of the MRU list
-        sets[set].moveToHead(blk);
-        if (blk->whenReady > curTick
-            && blk->whenReady - curTick > hitLatency) {
-            lat = blk->whenReady - curTick;
-        }
-        blk->refCount += 1;
-    }
-
-    return blk;
-}
 
 LRUBlk*
-LRU::findBlock(Addr addr, int asid) const
+LRU::findBlock(Addr addr) const
 {
     Addr tag = extractTag(addr);
     unsigned set = extractSet(addr);
-    LRUBlk *blk = sets[set].findBlk(asid, tag);
+    LRUBlk *blk = sets[set].findBlk(tag);
     return blk;
 }
 
 LRUBlk*
-LRU::findReplacement(Packet * &pkt, PacketList &writebacks,
-                     BlkList &compress_blocks)
+LRU::findReplacement(Addr addr, PacketList &writebacks)
 {
-    unsigned set = extractSet(pkt->getAddr());
+    unsigned set = extractSet(addr);
     // grab a replacement candidate
     LRUBlk *blk = sets[set].blks[assoc-1];
     sets[set].moveToHead(blk);
@@ -229,6 +207,9 @@ LRU::findReplacement(Packet * &pkt, PacketList &writebacks,
         totalRefs += blk->refCount;
         ++sampledRefs;
         blk->refCount = 0;
+
+        DPRINTF(CacheRepl, "set %x: selecting blk %x for replacement\n",
+                set, regenerateBlkAddr(blk->tag, set));
     } else if (!blk->isTouched) {
         tagsInUse++;
         blk->isTouched = true;
@@ -242,62 +223,16 @@ LRU::findReplacement(Packet * &pkt, PacketList &writebacks,
 }
 
 void
-LRU::invalidateBlk(int asid, Addr addr)
+LRU::invalidateBlk(LRU::BlkType *blk)
 {
-    LRUBlk *blk = findBlock(addr, asid);
     if (blk) {
         blk->status = 0;
         blk->isTouched = false;
+        blk->clearLoadLocks();
         tagsInUse--;
     }
 }
 
-void
-LRU::doCopy(Addr source, Addr dest, int asid, PacketList &writebacks)
-{
-    assert(source == blkAlign(source));
-    assert(dest == blkAlign(dest));
-    LRUBlk *source_blk = findBlock(source, asid);
-    assert(source_blk);
-    LRUBlk *dest_blk = findBlock(dest, asid);
-    if (dest_blk == NULL) {
-        // Need to do a replacement
-        Request *search = new Request(dest,1,0);
-        Packet * pkt = new Packet(search, Packet::ReadReq, -1);
-        BlkList dummy_list;
-        dest_blk = findReplacement(pkt, writebacks, dummy_list);
-        if (dest_blk->isValid() && dest_blk->isModified()) {
-            // Need to writeback data.
-/*         pkt = buildWritebackReq(regenerateBlkAddr(dest_blk->tag,
-                                                      dest_blk->set),
-                                    dest_blk->req->asid,
-                                    dest_blk->xc,
-                                    blkSize,
-                                    dest_blk->data,
-                                    dest_blk->size);
-*/
-            Request *writebackReq = new Request(regenerateBlkAddr(dest_blk->tag,
-                                                                  dest_blk->set),
-                                                blkSize, 0);
-            Packet *writeback = new Packet(writebackReq, Packet::Writeback, -1);
-            writeback->allocate();
-            memcpy(writeback->getPtr<uint8_t>(),dest_blk->data, blkSize);
-            writebacks.push_back(writeback);
-        }
-        dest_blk->tag = extractTag(dest);
-        dest_blk->asid = asid;
-        delete search;
-        delete pkt;
-    }
-    /**
-     * @todo Can't assume the status once we have coherence on copies.
-     */
-
-    // Set this block as readable, writeable, and dirty.
-    dest_blk->status = 7;
-    memcpy(dest_blk->data, source_blk->data, blkSize);
-}
-
 void
 LRU::cleanupRefs()
 {