Mem: Use cycles to express cache-related latencies
[gem5.git] / src / mem / cache / tags / iic.cc
index acce3ffc8f608a1fb56f29a1b757fedf56c3df95..b9e582c290cb144572eb2cf872da4c7ec74f3b22 100644 (file)
@@ -160,6 +160,7 @@ IIC::~IIC()
     delete [] dataStore;
     delete [] tagStore;
     delete [] sets;
+    delete [] dataBlks;
 }
 
 /* register cache stats */
@@ -219,11 +220,11 @@ IIC::regStats(const string &name)
 
 
 IICTag*
-IIC::accessBlock(Addr addr, int &lat, int context_src)
+IIC::accessBlock(Addr addr, Cycles &lat, int context_src)
 {
     Addr tag = extractTag(addr);
     unsigned set = hash(addr);
-    int set_lat;
+    Cycles set_lat;
 
     unsigned long chain_ptr = tagNull;
 
@@ -231,11 +232,11 @@ IIC::accessBlock(Addr addr, int &lat, int context_src)
         setAccess.sample(set);
 
     IICTag *tag_ptr = sets[set].findTag(tag, chain_ptr);
-    set_lat = 1;
+    set_lat = Cycles(1);
     if (tag_ptr == NULL && chain_ptr != tagNull) {
         int secondary_depth;
         tag_ptr = secondaryChain(tag, chain_ptr, &secondary_depth);
-        set_lat += secondary_depth;
+        set_lat += Cycles(secondary_depth);
         // set depth for statistics fix this later!!! egh
         sets[set].depth = set_lat;
 
@@ -249,7 +250,7 @@ IIC::accessBlock(Addr addr, int &lat, int context_src)
         }
 
     }
-    set_lat = set_lat * hashDelay + hitLatency;
+    set_lat = Cycles(set_lat * hashDelay + hitLatency);
     if (tag_ptr != NULL) {
         // IIC replacement: if this is not the first element of
         //   list, reorder
@@ -260,8 +261,9 @@ IIC::accessBlock(Addr addr, int &lat, int context_src)
         hitDepthTotal += sets[set].depth;
         tag_ptr->status |= BlkReferenced;
         lat = set_lat;
-        if (tag_ptr->whenReady > curTick() && tag_ptr->whenReady - curTick() > set_lat) {
-            lat = tag_ptr->whenReady - curTick();
+        if (tag_ptr->whenReady > curTick() &&
+            cache->ticksToCycles(tag_ptr->whenReady - curTick()) > set_lat) {
+            lat = cache->ticksToCycles(tag_ptr->whenReady - curTick());
         }
 
         tag_ptr->refCount += 1;
@@ -349,34 +351,32 @@ IIC::freeReplacementBlock(PacketList & writebacks)
     unsigned long data_ptr;
     /* consult replacement policy */
     tag_ptr = &tagStore[repl->getRepl()];
+    assert(tag_ptr != NULL);
     assert(tag_ptr->isValid());
 
     DPRINTF(Cache, "Replacing %x in IIC: %s\n",
             regenerateBlkAddr(tag_ptr->tag,0),
             tag_ptr->isDirty() ? "writeback" : "clean");
     /* write back replaced block data */
-    if (tag_ptr && (tag_ptr->isValid())) {
-        replacements[0]++;
-        totalRefs += tag_ptr->refCount;
-        ++sampledRefs;
-        tag_ptr->refCount = 0;
+    replacements[0]++;
+    totalRefs += tag_ptr->refCount;
+    ++sampledRefs;
+    tag_ptr->refCount = 0;
 
-        if (tag_ptr->isDirty()) {
+    if (tag_ptr->isDirty()) {
 /*          PacketPtr writeback =
-                buildWritebackReq(regenerateBlkAddr(tag_ptr->tag, 0),
-                                  tag_ptr->req->asid, tag_ptr->xc, blkSize,
-                                  tag_ptr->data,
-                                  tag_ptr->size);
+            buildWritebackReq(regenerateBlkAddr(tag_ptr->tag, 0),
+            tag_ptr->req->asid, tag_ptr->xc, blkSize,
+            tag_ptr->data,
+            tag_ptr->size);
 */
-            Request *writebackReq = new Request(regenerateBlkAddr(tag_ptr->tag, 0),
-                                           blkSize, 0);
-            PacketPtr writeback = new Packet(writebackReq, MemCmd::Writeback,
-                                             -1);
-            writeback->allocate();
-            memcpy(writeback->getPtr<uint8_t>(), tag_ptr->data, blkSize);
-
-            writebacks.push_back(writeback);
-        }
+        Request *writebackReq = new Request(regenerateBlkAddr(tag_ptr->tag, 0),
+                                            blkSize, 0, Request::wbMasterId);
+        PacketPtr writeback = new Packet(writebackReq, MemCmd::Writeback);
+        writeback->allocate();
+        memcpy(writeback->getPtr<uint8_t>(), tag_ptr->data, blkSize);
+
+        writebacks.push_back(writeback);
     }
 
     // free the data blocks
@@ -615,7 +615,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) {