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
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
// 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--;
}
}
// 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*
// 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;
}
// 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){
std::shared_ptr<ReplacementData>
BRRIPRP::instantiateEntry()
{
- return std::shared_ptr<ReplacementData>(new BRRIPReplData(maxRRPV));
+ return std::shared_ptr<ReplacementData>(new BRRIPReplData(numRRPVBits));
}
BRRIPRP*
#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;
* 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