summaryrefslogtreecommitdiff
path: root/src/mem/cache/replacement_policies/lfu_rp.cc
diff options
context:
space:
mode:
authorDaniel R. Carvalho <odanrc@yahoo.com.br>2018-03-27 11:53:33 +0200
committerDaniel Carvalho <odanrc@yahoo.com.br>2018-05-03 14:25:29 +0000
commitc149983d931054d8cf88d2977a1f03a0b8b3b543 (patch)
tree1651101f29d8b06098394ffb078bf2716348664a /src/mem/cache/replacement_policies/lfu_rp.cc
parentddb80527e37e505e74b04755da502934ce8f0645 (diff)
downloadgem5-c149983d931054d8cf88d2977a1f03a0b8b3b543.tar.xz
mem-cache: ReplacementPolicy specific replacement data
Replacement data is specific for each replacement policy, and thus should be instantiated differently by each policy. Touch() and reset() do not need to be aware of CacheBlk, as they only update its ReplacementData. Invalidate() makes replacement policies independent of cache blocks, by removing the awareness of the valid state. An inheritable base ReplaceableEntry class was created to allow usage of replacement policies with any table-like structure. Change-Id: I998917d800fa48504ed95abffa2f1b7bfd68522b Reviewed-on: https://gem5-review.googlesource.com/9421 Reviewed-by: Nikos Nikoleris <nikos.nikoleris@arm.com> Maintainer: Nikos Nikoleris <nikos.nikoleris@arm.com>
Diffstat (limited to 'src/mem/cache/replacement_policies/lfu_rp.cc')
-rw-r--r--src/mem/cache/replacement_policies/lfu_rp.cc52
1 files changed, 38 insertions, 14 deletions
diff --git a/src/mem/cache/replacement_policies/lfu_rp.cc b/src/mem/cache/replacement_policies/lfu_rp.cc
index 90a5ee227..ffa653e87 100644
--- a/src/mem/cache/replacement_policies/lfu_rp.cc
+++ b/src/mem/cache/replacement_policies/lfu_rp.cc
@@ -30,36 +30,60 @@
#include "mem/cache/replacement_policies/lfu_rp.hh"
-#include "debug/CacheRepl.hh"
+#include <memory>
LFURP::LFURP(const Params *p)
: BaseReplacementPolicy(p)
{
}
-CacheBlk*
-LFURP::getVictim(const ReplacementCandidates& candidates)
+void
+LFURP::invalidate(const std::shared_ptr<ReplacementData>& replacement_data)
+const
+{
+ // Reset reference count
+ std::static_pointer_cast<LFUReplData>(replacement_data)->refCount = 0;
+}
+
+void
+LFURP::touch(const std::shared_ptr<ReplacementData>& replacement_data) const
+{
+ // Update reference count
+ std::static_pointer_cast<LFUReplData>(replacement_data)->refCount++;
+}
+
+void
+LFURP::reset(const std::shared_ptr<ReplacementData>& replacement_data) const
+{
+ // Reset reference count
+ std::static_pointer_cast<LFUReplData>(replacement_data)->refCount = 1;
+}
+
+ReplaceableEntry*
+LFURP::getVictim(const ReplacementCandidates& candidates) const
{
// There must be at least one replacement candidate
assert(candidates.size() > 0);
// Visit all candidates to find victim
- CacheBlk* blk = candidates[0];
+ ReplaceableEntry* victim = candidates[0];
for (const auto& candidate : candidates) {
- // Stop iteration if found an invalid block
- if (!candidate->isValid()) {
- blk = candidate;
- break;
- // Update victim block if necessary
- } else if (candidate->refCount < blk->refCount) {
- blk = candidate;
+ // Update victim entry if necessary
+ if (std::static_pointer_cast<LFUReplData>(
+ candidate->replacementData)->refCount <
+ std::static_pointer_cast<LFUReplData>(
+ victim->replacementData)->refCount) {
+ victim = candidate;
}
}
- DPRINTF(CacheRepl, "set %x, way %x: selecting blk for replacement\n",
- blk->set, blk->way);
+ return victim;
+}
- return blk;
+std::shared_ptr<ReplacementData>
+LFURP::instantiateEntry()
+{
+ return std::shared_ptr<ReplacementData>(new LFUReplData());
}
LFURP*