From c149983d931054d8cf88d2977a1f03a0b8b3b543 Mon Sep 17 00:00:00 2001 From: "Daniel R. Carvalho" Date: Tue, 27 Mar 2018 11:53:33 +0200 Subject: 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 Maintainer: Nikos Nikoleris --- src/mem/cache/replacement_policies/random_rp.cc | 49 +++++++++++++++++++------ 1 file changed, 37 insertions(+), 12 deletions(-) (limited to 'src/mem/cache/replacement_policies/random_rp.cc') 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& replacement_data) +const +{ + // Unprioritize replacement data victimization + std::static_pointer_cast( + replacement_data)->valid = false; +} + +void +RandomRP::touch(const std::shared_ptr& replacement_data) const +{ +} + +void +RandomRP::reset(const std::shared_ptr& replacement_data) const +{ + // Unprioritize replacement data victimization + std::static_pointer_cast( + 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(0, + ReplaceableEntry* victim = candidates[random_mt.random(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( + 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 +RandomRP::instantiateEntry() +{ + return std::shared_ptr(new ReplacementData()); } RandomRP* -- cgit v1.2.3