Prefetcher: Fix some memory leaks with the prefetcher.
authorAli Saidi <Ali.Saidi@ARM.com>
Fri, 19 Aug 2011 20:08:05 +0000 (15:08 -0500)
committerAli Saidi <Ali.Saidi@ARM.com>
Fri, 19 Aug 2011 20:08:05 +0000 (15:08 -0500)
src/mem/cache/cache_impl.hh
src/mem/cache/prefetch/base.cc
src/mem/cache/prefetch/stride.cc

index e1aed8b0c17df73f1d3503ae98d0e29cb0584b62..e9a40a74196f0aa5828ef52913f7b3c789a0cd12 100644 (file)
@@ -1443,6 +1443,10 @@ Cache<TagStore>::getNextMSHR()
                 mshr_misses[pkt->cmdToIndex()][0/*pkt->req->threadId()*/]++;
                 // Don't request bus, since we already have it
                 return allocateMissBuffer(pkt, curTick(), false);
+            } else {
+                // free the request and packet
+                delete pkt->req;
+                delete pkt;
             }
         }
     }
index 12028ac525f7440b9d8b6cc5250b1b8279cf743b..52d1171401824f55d65fbf5bdd11536ffb334b1a 100644 (file)
@@ -139,25 +139,25 @@ BasePrefetcher::getPacket()
     }
 
     PacketPtr pkt;
-    bool keep_trying = false;
-    do {
+    while (!pf.empty()) {
         pkt = *pf.begin();
         pf.pop_front();
 
-        if (keep_trying) {
-            DPRINTF(HWPrefetch, "addr 0x%x in cache, skipping\n",
-                    pkt->getAddr());
-            delete pkt->req;
-            delete pkt;
-        }
+        Addr blk_addr = pkt->getAddr() & ~(Addr)(blkSize-1);
+
+        if (!inCache(blk_addr) && !inMissQueue(blk_addr))
+            // we found a prefetch, return it
+            break;
+
+        DPRINTF(HWPrefetch, "addr 0x%x in cache, skipping\n", pkt->getAddr());
+        delete pkt->req;
+        delete pkt;
 
         if (pf.empty()) {
             cache->deassertMemSideBusRequest(BaseCache::Request_PF);
-            if (keep_trying) {
-                return NULL; // None left, all were in cache
-            }
+            return NULL; // None left, all were in cache
         }
-    } while (keep_trying);
+    }
 
     pfIssued++;
     assert(pkt != NULL);
index f71fd977dc503fada60d9cdccec72fdbc567d073..a5cc805efe6a31ea2f9e67cb7e4949f67efecf05 100644 (file)
@@ -118,6 +118,9 @@ StridePrefetcher::calculatePrefetch(PacketPtr &pkt, std::list<Addr> &addresses,
                 }
             }
             DPRINTF(HWPrefetch, "  replacing PC %x\n", (*min_pos)->instAddr);
+
+            // free entry and delete it
+            delete *min_pos;
             tab.erase(min_pos);
         }