mem-cache: Remove mumBlock redundant initialiation from FALRU
[gem5.git] / src / mem / cache / tags / random_repl.cc
index 77b3791353622ce9d7a7fe793b6eaf45d212c1c5..ab51f640770c0a9560f107e1fb2e24eab203e9c4 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Copyright (c) 2014 The Regents of The University of Michigan
+ * Copyright (c) 2016 ARM Limited
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * Definitions of a random replacement tag store.
  */
 
+#include "mem/cache/tags/random_repl.hh"
+
 #include "base/random.hh"
 #include "debug/CacheRepl.hh"
-#include "mem/cache/tags/random_repl.hh"
 #include "mem/cache/base.hh"
 
 RandomRepl::RandomRepl(const Params *p)
@@ -44,24 +46,32 @@ RandomRepl::RandomRepl(const Params *p)
 {
 }
 
-BaseSetAssoc::BlkType*
-RandomRepl::accessBlock(Addr addr, bool is_secure, Cycles &lat, int master_id)
+CacheBlk*
+RandomRepl::accessBlock(Addr addr, bool is_secure, Cycles &lat)
 {
-    return BaseSetAssoc::accessBlock(addr, is_secure, lat, master_id);
+    return BaseSetAssoc::accessBlock(addr, is_secure, lat);
 }
 
-BaseSetAssoc::BlkType*
-RandomRepl::findVictim(Addr addr) const
+CacheBlk*
+RandomRepl::findVictim(Addr addr)
 {
-    BlkType *blk = BaseSetAssoc::findVictim(addr);
+    CacheBlk *blk = BaseSetAssoc::findVictim(addr);
+    unsigned set = extractSet(addr);
 
     // if all blocks are valid, pick a replacement at random
-    if (blk->isValid()) {
+    if (blk && blk->isValid()) {
         // find a random index within the bounds of the set
         int idx = random_mt.random<int>(0, assoc - 1);
+        blk = sets[set].blks[idx];
+        // Enforce allocation limit
+        while (blk->way >= allocAssoc) {
+            idx = (idx + 1) % assoc;
+            blk = sets[set].blks[idx];
+        }
+
         assert(idx < assoc);
         assert(idx >= 0);
-        blk = sets[extractSet(addr)].blks[idx];
+        assert(blk->way < allocAssoc);
 
         DPRINTF(CacheRepl, "set %x: selecting blk %x for replacement\n",
                 blk->set, regenerateBlkAddr(blk->tag, blk->set));
@@ -77,7 +87,7 @@ RandomRepl::insertBlock(PacketPtr pkt, BlkType *blk)
 }
 
 void
-RandomRepl::invalidate(BlkType *blk)
+RandomRepl::invalidate(CacheBlk *blk)
 {
     BaseSetAssoc::invalidate(blk);
 }