Sanchayan Maity
2e1e1aedc7
Introduce NMRU Cache Replacement Policy Reference implementation is here http://pages.cs.wisc.edu/~david/courses/cs752/Fall2015/gem5-tutorial/part2/simobject.html Note that the reference implementation is outdated and does not build/work with the current gem5 branch. This commit modifies the above example to make it work with the current gem5 branch.
80 lines
1.8 KiB
C++
80 lines
1.8 KiB
C++
/**
|
|
* @file
|
|
* Definitions of a NMRU tag store.
|
|
*/
|
|
|
|
#include "mem/cache/tags/nmru.hh"
|
|
|
|
#include "base/random.hh"
|
|
#include "debug/CacheRepl.hh"
|
|
#include "mem/cache/base.hh"
|
|
|
|
NMRU::NMRU(const Params *p) : BaseSetAssoc(p)
|
|
{
|
|
|
|
}
|
|
|
|
BaseSetAssoc::BlkType*
|
|
NMRU::accessBlock(Addr addr, bool is_secure, Cycles &lat, int master_id)
|
|
{
|
|
// Accesses are based on parent class, no need to do anything special
|
|
BlkType *blk = BaseSetAssoc::accessBlock(addr, is_secure, lat, master_id);
|
|
|
|
if (blk != NULL) {
|
|
// move this block to head of the MRU list
|
|
sets[blk->set].moveToHead(blk);
|
|
DPRINTF(CacheRepl, "set %x: moving blk %x (%s) to MRU\n",
|
|
blk->set, regenerateBlkAddr(blk->tag, blk->set),
|
|
is_secure ? "s" : "ns");
|
|
}
|
|
|
|
return blk;
|
|
}
|
|
|
|
BaseSetAssoc::BlkType*
|
|
NMRU::findVictim(Addr addr)
|
|
{
|
|
BlkType *blk = BaseSetAssoc::findVictim(addr);
|
|
|
|
// if all blocks are valid, pick a replacement that is not MRU at random
|
|
if (blk->isValid()) {
|
|
// find a random index within the bounds of the set
|
|
int idx = random_mt.random<int>(1, assoc - 1);
|
|
assert(idx < assoc);
|
|
assert(idx >= 0);
|
|
blk = sets[extractSet(addr)].blks[idx];
|
|
|
|
DPRINTF(CacheRepl,
|
|
"set %x: selecting blk %x for replacement\n",
|
|
blk->set,
|
|
regenerateBlkAddr(blk->tag, blk->set));
|
|
}
|
|
|
|
return blk;
|
|
}
|
|
|
|
void
|
|
NMRU::insertBlock(PacketPtr pkt, BlkType *blk)
|
|
{
|
|
BaseSetAssoc::insertBlock(pkt, blk);
|
|
|
|
int set = extractSet(pkt->getAddr());
|
|
sets[set].moveToHead(blk);
|
|
}
|
|
|
|
void
|
|
NMRU::invalidate(BlkType *blk)
|
|
{
|
|
BaseSetAssoc::invalidate(blk);
|
|
|
|
// should be evicted before valid blocks
|
|
int set = blk->set;
|
|
sets[set].moveToTail(blk);
|
|
}
|
|
|
|
NMRU*
|
|
NMRUParams::create()
|
|
{
|
|
return new NMRU(this);
|
|
}
|