mem: cache: tags: Implement LIFO Cache Replacement Policy
This commit is contained in:
parent
bfcc9d4080
commit
627f5dabdb
5 changed files with 134 additions and 1 deletions
|
@ -95,7 +95,8 @@ class L1DCache(L1Cache):
|
||||||
SimpleOpts.add_option('--l1d_assoc',
|
SimpleOpts.add_option('--l1d_assoc',
|
||||||
help="L1 data cache associativity. Default: %s" % assoc)
|
help="L1 data cache associativity. Default: %s" % assoc)
|
||||||
SimpleOpts.add_option('--replacement_policy',
|
SimpleOpts.add_option('--replacement_policy',
|
||||||
help="L1 cache replacement policy. [NMRU,LFU,LRU,Random]")
|
help="L1 cache replacement policy. [NMRU,LFU,LIFO,LRU,"
|
||||||
|
"Random]")
|
||||||
|
|
||||||
def __init__(self, opts=None):
|
def __init__(self, opts=None):
|
||||||
super(L1DCache, self).__init__(opts)
|
super(L1DCache, self).__init__(opts)
|
||||||
|
@ -120,6 +121,9 @@ class L1DCache(L1Cache):
|
||||||
elif opts.replacement_policy == "LFU":
|
elif opts.replacement_policy == "LFU":
|
||||||
from m5.objects import LFU
|
from m5.objects import LFU
|
||||||
self.tags = LFU()
|
self.tags = LFU()
|
||||||
|
elif opts.replacement_policy == "LIFO":
|
||||||
|
from m5.objects import LIFO
|
||||||
|
self.tags = LIFO()
|
||||||
elif opts.replacement_policy:
|
elif opts.replacement_policy:
|
||||||
fatal("Unsupported replacement policy: %s" %
|
fatal("Unsupported replacement policy: %s" %
|
||||||
opts.replacement_policy)
|
opts.replacement_policy)
|
||||||
|
|
1
src/mem/cache/tags/SConscript
vendored
1
src/mem/cache/tags/SConscript
vendored
|
@ -39,3 +39,4 @@ Source('random_repl.cc')
|
||||||
Source('fa_lru.cc')
|
Source('fa_lru.cc')
|
||||||
Source('nmru.cc')
|
Source('nmru.cc')
|
||||||
Source('lfu.cc')
|
Source('lfu.cc')
|
||||||
|
Source('lifo.cc')
|
||||||
|
|
5
src/mem/cache/tags/Tags.py
vendored
5
src/mem/cache/tags/Tags.py
vendored
|
@ -90,3 +90,8 @@ class LFU(BaseSetAssoc):
|
||||||
type = 'LFU'
|
type = 'LFU'
|
||||||
cxx_class = 'LFU'
|
cxx_class = 'LFU'
|
||||||
cxx_header = "mem/cache/tags/lfu.hh"
|
cxx_header = "mem/cache/tags/lfu.hh"
|
||||||
|
|
||||||
|
class LIFO(BaseSetAssoc):
|
||||||
|
type = 'LIFO'
|
||||||
|
cxx_class = 'LIFO'
|
||||||
|
cxx_header = "mem/cache/tags/lifo.hh"
|
||||||
|
|
82
src/mem/cache/tags/lifo.cc
vendored
Normal file
82
src/mem/cache/tags/lifo.cc
vendored
Normal file
|
@ -0,0 +1,82 @@
|
||||||
|
/*
|
||||||
|
* Authors: Prashanth Ramaprasad
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* Definitions of a LIFO tag store.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "mem/cache/tags/lifo.hh"
|
||||||
|
|
||||||
|
#include "debug/CacheRepl.hh"
|
||||||
|
#include "mem/cache/base.hh"
|
||||||
|
|
||||||
|
LIFO::LIFO(const Params *p)
|
||||||
|
: BaseSetAssoc(p)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
CacheBlk*
|
||||||
|
LIFO::accessBlock(Addr addr, bool is_secure, Cycles &lat, int master_id)
|
||||||
|
{
|
||||||
|
CacheBlk *blk = BaseSetAssoc::accessBlock(addr, is_secure, lat, master_id);
|
||||||
|
|
||||||
|
if (blk != nullptr) {
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
CacheBlk*
|
||||||
|
LIFO::findVictim(Addr addr)
|
||||||
|
{
|
||||||
|
int set = extractSet(addr);
|
||||||
|
// grab a replacement candidate
|
||||||
|
BlkType *blk = nullptr;
|
||||||
|
for (int i = 0; i <= assoc - 1; i++) {
|
||||||
|
BlkType *b = sets[set].blks[i];
|
||||||
|
if (b->way < allocAssoc) {
|
||||||
|
blk = b;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assert(!blk || blk->way < allocAssoc);
|
||||||
|
|
||||||
|
if (blk && blk->isValid()) {
|
||||||
|
DPRINTF(CacheRepl, "set %x: selecting blk %x for replacement\n",
|
||||||
|
set, regenerateBlkAddr(blk->tag, set));
|
||||||
|
}
|
||||||
|
|
||||||
|
return blk;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
LIFO::insertBlock(PacketPtr pkt, BlkType *blk)
|
||||||
|
{
|
||||||
|
BaseSetAssoc::insertBlock(pkt, blk);
|
||||||
|
|
||||||
|
int set = extractSet(pkt->getAddr());
|
||||||
|
sets[set].moveToHead(blk);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
LIFO::invalidate(CacheBlk *blk)
|
||||||
|
{
|
||||||
|
BaseSetAssoc::invalidate(blk);
|
||||||
|
|
||||||
|
// should be evicted before valid blocks
|
||||||
|
int set = blk->set;
|
||||||
|
sets[set].moveToTail(blk);
|
||||||
|
}
|
||||||
|
|
||||||
|
LIFO*
|
||||||
|
LIFOParams::create()
|
||||||
|
{
|
||||||
|
return new LIFO(this);
|
||||||
|
}
|
41
src/mem/cache/tags/lifo.hh
vendored
Normal file
41
src/mem/cache/tags/lifo.hh
vendored
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
/*
|
||||||
|
* Authors: Prashanth Ramaprasad
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* Declaration of a LIFO tag store.
|
||||||
|
* The LIFO tags guarantee that the true least-recently-used way in
|
||||||
|
* a set will always be evicted.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __MEM_CACHE_TAGS_LIFO_HH__
|
||||||
|
#define __MEM_CACHE_TAGS_LIFO_HH__
|
||||||
|
|
||||||
|
#include "mem/cache/tags/base_set_assoc.hh"
|
||||||
|
#include "params/LIFO.hh"
|
||||||
|
|
||||||
|
class LIFO : public BaseSetAssoc
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
/** Convenience typedef. */
|
||||||
|
typedef LIFOParams Params;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct and initialize this tag store.
|
||||||
|
*/
|
||||||
|
LIFO(const Params *p);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Destructor
|
||||||
|
*/
|
||||||
|
~LIFO() {}
|
||||||
|
|
||||||
|
CacheBlk* accessBlock(Addr addr, bool is_secure, Cycles &lat,
|
||||||
|
int context_src);
|
||||||
|
CacheBlk* findVictim(Addr addr);
|
||||||
|
void insertBlock(PacketPtr pkt, BlkType *blk);
|
||||||
|
void invalidate(CacheBlk *blk);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // __MEM_CACHE_TAGS_LIFO_HH__
|
Loading…
Reference in a new issue