SCons: Support building without an ISA
[gem5.git] / src / mem / cache / tags / lru.cc
index 81d44b0c06f7c454c2283b763d87a2fcbdead211..8a8b0d0d650c714a23eadb7d62cddb8578ec568b 100644 (file)
 
 #include <string>
 
-#include "mem/cache/base.hh"
 #include "base/intmath.hh"
+#include "mem/cache/base.hh"
+#include "mem/cache/tags/cacheset.hh"
 #include "mem/cache/tags/lru.hh"
 #include "sim/core.hh"
-#include "cacheset.hh"
 
 using namespace std;
 
@@ -74,7 +74,8 @@ LRU::LRU(unsigned _numSets, unsigned _blkSize, unsigned _assoc,
     sets = new CacheSet[numSets];
     blks = new BlkType[numSets * assoc];
     // allocate data storage in one big chunk
-    dataBlks = new uint8_t[numSets*assoc*blkSize];
+    numBlocks = numSets * assoc;
+    dataBlks = new uint8_t[numBlocks * blkSize];
 
     unsigned blkIndex = 0;       // index into blks array
     for (unsigned i = 0; i < numSets; ++i) {
@@ -157,6 +158,14 @@ LRU::findVictim(Addr addr, PacketList &writebacks)
         ++sampledRefs;
         blk->refCount = 0;
 
+        // deal with evicted block
+        if (blk->contextSrc != -1) {
+            occupancies[blk->contextSrc % cache->numCpus()]--;
+            blk->contextSrc = -1;
+        } else {
+            occupancies[cache->numCpus()]--;
+        }
+
         DPRINTF(CacheRepl, "set %x: selecting blk %x for replacement\n",
                 set, regenerateBlkAddr(blk->tag, set));
     }
@@ -178,6 +187,14 @@ LRU::insertBlock(Addr addr, BlkType *blk, int context_src)
     // Set tag for new block.  Caller is responsible for setting status.
     blk->tag = extractTag(addr);
 
+    // deal with what we are bringing in
+    if (context_src != -1) {
+        occupancies[context_src % cache->numCpus()]++;
+    } else {
+        occupancies[cache->numCpus()]++;
+    }
+    blk->contextSrc = context_src;
+
     unsigned set = extractSet(addr);
     sets[set].moveToHead(blk);
 }
@@ -190,6 +207,20 @@ LRU::invalidateBlk(BlkType *blk)
         blk->isTouched = false;
         blk->clearLoadLocks();
         tagsInUse--;
+        if (blk->contextSrc != -1) {
+            occupancies[blk->contextSrc % cache->numCpus()]--;
+            blk->contextSrc = -1;
+        } else {
+            occupancies[cache->numCpus()]--;
+        }
+    }
+}
+
+void
+LRU::clearLocks()
+{
+    for (int i = 0; i < numBlocks; i++){
+        blks[i].clearLoadLocks();
     }
 }