mem: cache: tags: Implement FIFO Cache Replacement Policy

Signed-off-by: Ranjeet Kumar <rkumar15@hawk.iit.edu>
This commit is contained in:
Ranjeet Kumar 2017-04-09 21:08:37 +05:30 committed by Sanchayan Maity
parent 627f5dabdb
commit 1470e87527
5 changed files with 124 additions and 1 deletions

View File

@ -96,7 +96,7 @@ class L1DCache(L1Cache):
help="L1 data cache associativity. Default: %s" % assoc)
SimpleOpts.add_option('--replacement_policy',
help="L1 cache replacement policy. [NMRU,LFU,LIFO,LRU,"
"Random]")
"Random,FIFO]")
def __init__(self, opts=None):
super(L1DCache, self).__init__(opts)
@ -124,6 +124,9 @@ class L1DCache(L1Cache):
elif opts.replacement_policy == "LIFO":
from m5.objects import LIFO
self.tags = LIFO()
elif opts.replacement_policy == "FIFO":
from m5.objects import FIFO
self.tags = FIFO()
elif opts.replacement_policy:
fatal("Unsupported replacement policy: %s" %
opts.replacement_policy)

View File

@ -40,3 +40,4 @@ Source('fa_lru.cc')
Source('nmru.cc')
Source('lfu.cc')
Source('lifo.cc')
Source('fifo.cc')

View File

@ -95,3 +95,7 @@ class LIFO(BaseSetAssoc):
type = 'LIFO'
cxx_class = 'LIFO'
cxx_header = "mem/cache/tags/lifo.hh"
class FIFO(BaseSetAssoc):
type = 'FIFO'
cxx_class = 'FIFO'
cxx_header = "mem/cache/tags/fifo.hh"

74
src/mem/cache/tags/fifo.cc vendored Normal file
View File

@ -0,0 +1,74 @@
/*
* Authors: Ranjeet Kumar
*/
/**
* @file
* Definitions of a FIFO tag store.
*/
#include "mem/cache/tags/fifo.hh"
#include "debug/CacheRepl.hh"
#include "mem/cache/base.hh"
FIFO::FIFO(const Params *p)
: BaseSetAssoc(p)
{
}
CacheBlk*
FIFO::accessBlock(Addr addr, bool is_secure, Cycles &lat, int master_id)
{
CacheBlk *blk = BaseSetAssoc::accessBlock(addr, is_secure, lat, master_id);
return blk;
}
CacheBlk*
FIFO::findVictim(Addr addr)
{
int set = extractSet(addr);
// grab a replacement candidate
BlkType *blk = nullptr;
for (int i = assoc-1; i >= 0; 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
FIFO::insertBlock(PacketPtr pkt, BlkType *blk)
{
BaseSetAssoc::insertBlock(pkt, blk);
int set = extractSet(pkt->getAddr());
sets[set].moveToHead(blk);
}
void
FIFO::invalidate(CacheBlk *blk)
{
BaseSetAssoc::invalidate(blk);
// should be evicted before valid blocks
int set = blk->set;
sets[set].moveToTail(blk);
}
FIFO*
FIFOParams::create()
{
return new FIFO(this);
}

41
src/mem/cache/tags/fifo.hh vendored Normal file
View File

@ -0,0 +1,41 @@
/*
* Authors: Ranjeet Kumar
*/
/**
* @file
* Declaration of a FIFO tag store.
* The FIFO tags guarantee that the true least-recently-used way in
* a set will always be evicted.
*/
#ifndef __MEM_CACHE_TAGS_FIFO_HH__
#define __MEM_CACHE_TAGS_FIFO_HH__
#include "mem/cache/tags/base_set_assoc.hh"
#include "params/FIFO.hh"
class FIFO : public BaseSetAssoc
{
public:
/** Convenience typedef. */
typedef FIFOParams Params;
/**
* Construct and initialize this tag store.
*/
FIFO(const Params *p);
/**
* Destructor
*/
~FIFO() {}
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_FIFO_HH__