summaryrefslogtreecommitdiff
path: root/src/mem/cache/replacement_policies/random_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/random_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/random_rp.cc')
-rw-r--r--src/mem/cache/replacement_policies/random_rp.cc49
1 files changed, 37 insertions, 12 deletions
diff --git a/src/mem/cache/replacement_policies/random_rp.cc b/src/mem/cache/replacement_policies/random_rp.cc
index 1c54bdac6..24e64fc90 100644
--- a/src/mem/cache/replacement_policies/random_rp.cc
+++ b/src/mem/cache/replacement_policies/random_rp.cc
@@ -31,37 +31,62 @@
#include "mem/cache/replacement_policies/random_rp.hh"
#include "base/random.hh"
-#include "debug/CacheRepl.hh"
+#include "mem/cache/blk.hh"
RandomRP::RandomRP(const Params *p)
: BaseReplacementPolicy(p)
{
}
-CacheBlk*
-RandomRP::getVictim(const ReplacementCandidates& candidates)
+void
+RandomRP::invalidate(const std::shared_ptr<ReplacementData>& replacement_data)
+const
+{
+ // Unprioritize replacement data victimization
+ std::static_pointer_cast<RandomReplData>(
+ replacement_data)->valid = false;
+}
+
+void
+RandomRP::touch(const std::shared_ptr<ReplacementData>& replacement_data) const
+{
+}
+
+void
+RandomRP::reset(const std::shared_ptr<ReplacementData>& replacement_data) const
+{
+ // Unprioritize replacement data victimization
+ std::static_pointer_cast<RandomReplData>(
+ replacement_data)->valid = true;
+}
+
+ReplaceableEntry*
+RandomRP::getVictim(const ReplacementCandidates& candidates) const
{
// There must be at least one replacement candidate
assert(candidates.size() > 0);
// Choose one candidate at random
- CacheBlk* blk = candidates[random_mt.random<unsigned>(0,
+ ReplaceableEntry* victim = candidates[random_mt.random<unsigned>(0,
candidates.size() - 1)];
- // Visit all candidates to find an invalid entry
+ // Visit all candidates to search for an invalid entry. If one is found,
+ // its eviction is prioritized
for (const auto& candidate : candidates) {
- // Give priority to victimise invalid entries
- if (!candidate->isValid()){
- blk = candidate;
+ if (!std::static_pointer_cast<RandomReplData>(
+ candidate->replacementData)->valid) {
+ victim = candidate;
break;
}
}
- // If no invalid blocks were found, choose one of the candidates randomly
- DPRINTF(CacheRepl, "set %x, way %x: selecting blk for replacement\n",
- blk->set, blk->way);
+ return victim;
+}
- return blk;
+std::shared_ptr<ReplacementData>
+RandomRP::instantiateEntry()
+{
+ return std::shared_ptr<ReplacementData>(new ReplacementData());
}
RandomRP*