mem-cache: Use SatCounter for RRPV
Use SatCounter in RRIP's RRPV. As such, move validation functionality to a proper variable. Change-Id: I142db2b7f6cd518ac3a2b68c9ed48005402b3464 Signed-off-by: Daniel R. Carvalho <odanrc@yahoo.com.br> Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/20452 Reviewed-by: Jason Lowe-Power <jason@lowepower.com> Maintainer: Jason Lowe-Power <jason@lowepower.com> Tested-by: kokoro <noreply+kokoro@google.com>
This commit is contained in:
committed by
Daniel Carvalho
parent
fc528bb0c0
commit
54603b0f57
@@ -78,7 +78,7 @@ class BRRIPRP(BaseReplacementPolicy):
|
||||
type = 'BRRIPRP'
|
||||
cxx_class = 'BRRIPRP'
|
||||
cxx_header = "mem/cache/replacement_policies/brrip_rp.hh"
|
||||
max_RRPV = Param.Int(3, "Maximum RRPV possible")
|
||||
num_bits = Param.Int(2, "Number of bits per RRPV")
|
||||
hit_priority = Param.Bool(False,
|
||||
"Prioritize evicting blocks that havent had a hit recently")
|
||||
btp = Param.Percent(3,
|
||||
@@ -89,7 +89,7 @@ class RRIPRP(BRRIPRP):
|
||||
|
||||
class NRURP(BRRIPRP):
|
||||
btp = 100
|
||||
max_RRPV = 1
|
||||
num_bits = 1
|
||||
|
||||
class TreePLRURP(BaseReplacementPolicy):
|
||||
type = 'TreePLRURP'
|
||||
|
||||
38
src/mem/cache/replacement_policies/brrip_rp.cc
vendored
38
src/mem/cache/replacement_policies/brrip_rp.cc
vendored
@@ -39,9 +39,9 @@
|
||||
|
||||
BRRIPRP::BRRIPRP(const Params *p)
|
||||
: BaseReplacementPolicy(p),
|
||||
maxRRPV(p->max_RRPV), hitPriority(p->hit_priority), btp(p->btp)
|
||||
numRRPVBits(p->num_bits), hitPriority(p->hit_priority), btp(p->btp)
|
||||
{
|
||||
fatal_if(maxRRPV <= 0, "max_RRPV should be greater than zero.\n");
|
||||
fatal_if(numRRPVBits <= 0, "There should be at least one bit per RRPV.\n");
|
||||
}
|
||||
|
||||
void
|
||||
@@ -51,8 +51,8 @@ const
|
||||
std::shared_ptr<BRRIPReplData> casted_replacement_data =
|
||||
std::static_pointer_cast<BRRIPReplData>(replacement_data);
|
||||
|
||||
// Set RRPV to an invalid distance
|
||||
casted_replacement_data->rrpv = maxRRPV + 1;
|
||||
// Invalidate entry
|
||||
casted_replacement_data->valid = false;
|
||||
}
|
||||
|
||||
void
|
||||
@@ -65,8 +65,8 @@ BRRIPRP::touch(const std::shared_ptr<ReplacementData>& replacement_data) const
|
||||
// Every hit in HP mode makes the entry the last to be evicted, while
|
||||
// in FP mode a hit makes the entry less likely to be evicted
|
||||
if (hitPriority) {
|
||||
casted_replacement_data->rrpv = 0;
|
||||
} else if (casted_replacement_data->rrpv > 0) {
|
||||
casted_replacement_data->rrpv.reset();
|
||||
} else {
|
||||
casted_replacement_data->rrpv--;
|
||||
}
|
||||
}
|
||||
@@ -80,11 +80,13 @@ BRRIPRP::reset(const std::shared_ptr<ReplacementData>& replacement_data) const
|
||||
// Reset RRPV
|
||||
// Replacement data is inserted as "long re-reference" if lower than btp,
|
||||
// "distant re-reference" otherwise
|
||||
casted_replacement_data->rrpv.saturate();
|
||||
if (random_mt.random<unsigned>(1, 100) <= btp) {
|
||||
casted_replacement_data->rrpv = maxRRPV-1;
|
||||
} else {
|
||||
casted_replacement_data->rrpv = maxRRPV;
|
||||
casted_replacement_data->rrpv--;
|
||||
}
|
||||
|
||||
// Mark entry as ready to be used
|
||||
casted_replacement_data->valid = true;
|
||||
}
|
||||
|
||||
ReplaceableEntry*
|
||||
@@ -102,15 +104,18 @@ BRRIPRP::getVictim(const ReplacementCandidates& candidates) const
|
||||
|
||||
// Visit all candidates to find victim
|
||||
for (const auto& candidate : candidates) {
|
||||
// Get candidate's rrpv
|
||||
int candidate_RRPV = std::static_pointer_cast<BRRIPReplData>(
|
||||
candidate->replacementData)->rrpv;
|
||||
std::shared_ptr<BRRIPReplData> candidate_repl_data =
|
||||
std::static_pointer_cast<BRRIPReplData>(
|
||||
candidate->replacementData);
|
||||
|
||||
// Stop searching for victims if an invalid entry is found
|
||||
if (candidate_RRPV == maxRRPV + 1) {
|
||||
if (!candidate_repl_data->valid) {
|
||||
return candidate;
|
||||
}
|
||||
|
||||
// Update victim entry if necessary
|
||||
} else if (candidate_RRPV > victim_RRPV) {
|
||||
int candidate_RRPV = candidate_repl_data->rrpv;
|
||||
if (candidate_RRPV > victim_RRPV) {
|
||||
victim = candidate;
|
||||
victim_RRPV = candidate_RRPV;
|
||||
}
|
||||
@@ -118,7 +123,8 @@ BRRIPRP::getVictim(const ReplacementCandidates& candidates) const
|
||||
|
||||
// Get difference of victim's RRPV to the highest possible RRPV in
|
||||
// order to update the RRPV of all the other entries accordingly
|
||||
int diff = maxRRPV - victim_RRPV;
|
||||
int diff = std::static_pointer_cast<BRRIPReplData>(
|
||||
victim->replacementData)->rrpv.saturate();
|
||||
|
||||
// No need to update RRPV if there is no difference
|
||||
if (diff > 0){
|
||||
@@ -135,7 +141,7 @@ BRRIPRP::getVictim(const ReplacementCandidates& candidates) const
|
||||
std::shared_ptr<ReplacementData>
|
||||
BRRIPRP::instantiateEntry()
|
||||
{
|
||||
return std::shared_ptr<ReplacementData>(new BRRIPReplData(maxRRPV));
|
||||
return std::shared_ptr<ReplacementData>(new BRRIPReplData(numRRPVBits));
|
||||
}
|
||||
|
||||
BRRIPRP*
|
||||
|
||||
23
src/mem/cache/replacement_policies/brrip_rp.hh
vendored
23
src/mem/cache/replacement_policies/brrip_rp.hh
vendored
@@ -54,6 +54,7 @@
|
||||
#ifndef __MEM_CACHE_REPLACEMENT_POLICIES_BRRIP_RP_HH__
|
||||
#define __MEM_CACHE_REPLACEMENT_POLICIES_BRRIP_RP_HH__
|
||||
|
||||
#include "base/sat_counter.hh"
|
||||
#include "mem/cache/replacement_policies/base.hh"
|
||||
|
||||
struct BRRIPRPParams;
|
||||
@@ -70,24 +71,28 @@ class BRRIPRP : public BaseReplacementPolicy
|
||||
* 0 -> near-immediate re-rereference interval
|
||||
* max_RRPV-1 -> long re-rereference interval
|
||||
* max_RRPV -> distant re-rereference interval
|
||||
* A value equal to max_RRPV + 1 indicates an invalid entry.
|
||||
*/
|
||||
int rrpv;
|
||||
SatCounter rrpv;
|
||||
|
||||
/** Whether the entry is valid. */
|
||||
bool valid;
|
||||
|
||||
/**
|
||||
* Default constructor. Invalidate data.
|
||||
*/
|
||||
BRRIPReplData(const int max_RRPV) : rrpv(max_RRPV + 1) {}
|
||||
BRRIPReplData(const int num_bits)
|
||||
: rrpv(num_bits), valid(false)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Maximum Re-Reference Prediction Value possible. An entry with this
|
||||
* value as the rrpv has the longest possible re-reference interval,
|
||||
* that is, it is likely not to be used in the near future, and is
|
||||
* among the best eviction candidates.
|
||||
* A maxRRPV of 1 implies in a NRU.
|
||||
* Number of RRPV bits. An entry that saturates its RRPV has the longest
|
||||
* possible re-reference interval, that is, it is likely not to be used
|
||||
* in the near future, and is among the best eviction candidates.
|
||||
* A maximum RRPV of 1 implies in a NRU.
|
||||
*/
|
||||
const int maxRRPV;
|
||||
const unsigned numRRPVBits;
|
||||
|
||||
/**
|
||||
* The hit priority (HP) policy replaces entries that do not receive cache
|
||||
|
||||
Reference in New Issue
Block a user