diff --git a/configs/learning_gem5/part1/caches.py b/configs/learning_gem5/part1/caches.py index 79e33d0a7..489be4b4f 100644 --- a/configs/learning_gem5/part1/caches.py +++ b/configs/learning_gem5/part1/caches.py @@ -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) diff --git a/src/mem/cache/tags/SConscript b/src/mem/cache/tags/SConscript index 85a2059c8..0dee8cf85 100644 --- a/src/mem/cache/tags/SConscript +++ b/src/mem/cache/tags/SConscript @@ -40,3 +40,4 @@ Source('fa_lru.cc') Source('nmru.cc') Source('lfu.cc') Source('lifo.cc') +Source('fifo.cc') diff --git a/src/mem/cache/tags/Tags.py b/src/mem/cache/tags/Tags.py index 72509f2ff..8262cd200 100644 --- a/src/mem/cache/tags/Tags.py +++ b/src/mem/cache/tags/Tags.py @@ -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" diff --git a/src/mem/cache/tags/fifo.cc b/src/mem/cache/tags/fifo.cc new file mode 100644 index 000000000..b57c2a1ca --- /dev/null +++ b/src/mem/cache/tags/fifo.cc @@ -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); +} diff --git a/src/mem/cache/tags/fifo.hh b/src/mem/cache/tags/fifo.hh new file mode 100644 index 000000000..a49c0358f --- /dev/null +++ b/src/mem/cache/tags/fifo.hh @@ -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__