gem5  v20.1.0.0
brrip_rp.cc
Go to the documentation of this file.
1 
30 
31 #include <cassert>
32 #include <memory>
33 
34 #include "base/logging.hh" // For fatal_if
35 #include "base/random.hh"
36 #include "params/BRRIPRP.hh"
37 
40  numRRPVBits(p->num_bits), hitPriority(p->hit_priority), btp(p->btp)
41 {
42  fatal_if(numRRPVBits <= 0, "There should be at least one bit per RRPV.\n");
43 }
44 
45 void
46 BRRIPRP::invalidate(const std::shared_ptr<ReplacementData>& replacement_data)
47 const
48 {
49  std::shared_ptr<BRRIPReplData> casted_replacement_data =
50  std::static_pointer_cast<BRRIPReplData>(replacement_data);
51 
52  // Invalidate entry
53  casted_replacement_data->valid = false;
54 }
55 
56 void
57 BRRIPRP::touch(const std::shared_ptr<ReplacementData>& replacement_data) const
58 {
59  std::shared_ptr<BRRIPReplData> casted_replacement_data =
60  std::static_pointer_cast<BRRIPReplData>(replacement_data);
61 
62  // Update RRPV if not 0 yet
63  // Every hit in HP mode makes the entry the last to be evicted, while
64  // in FP mode a hit makes the entry less likely to be evicted
65  if (hitPriority) {
66  casted_replacement_data->rrpv.reset();
67  } else {
68  casted_replacement_data->rrpv--;
69  }
70 }
71 
72 void
73 BRRIPRP::reset(const std::shared_ptr<ReplacementData>& replacement_data) const
74 {
75  std::shared_ptr<BRRIPReplData> casted_replacement_data =
76  std::static_pointer_cast<BRRIPReplData>(replacement_data);
77 
78  // Reset RRPV
79  // Replacement data is inserted as "long re-reference" if lower than btp,
80  // "distant re-reference" otherwise
81  casted_replacement_data->rrpv.saturate();
82  if (random_mt.random<unsigned>(1, 100) <= btp) {
83  casted_replacement_data->rrpv--;
84  }
85 
86  // Mark entry as ready to be used
87  casted_replacement_data->valid = true;
88 }
89 
91 BRRIPRP::getVictim(const ReplacementCandidates& candidates) const
92 {
93  // There must be at least one replacement candidate
94  assert(candidates.size() > 0);
95 
96  // Use first candidate as dummy victim
97  ReplaceableEntry* victim = candidates[0];
98 
99  // Store victim->rrpv in a variable to improve code readability
100  int victim_RRPV = std::static_pointer_cast<BRRIPReplData>(
101  victim->replacementData)->rrpv;
102 
103  // Visit all candidates to find victim
104  for (const auto& candidate : candidates) {
105  std::shared_ptr<BRRIPReplData> candidate_repl_data =
106  std::static_pointer_cast<BRRIPReplData>(
107  candidate->replacementData);
108 
109  // Stop searching for victims if an invalid entry is found
110  if (!candidate_repl_data->valid) {
111  return candidate;
112  }
113 
114  // Update victim entry if necessary
115  int candidate_RRPV = candidate_repl_data->rrpv;
116  if (candidate_RRPV > victim_RRPV) {
117  victim = candidate;
118  victim_RRPV = candidate_RRPV;
119  }
120  }
121 
122  // Get difference of victim's RRPV to the highest possible RRPV in
123  // order to update the RRPV of all the other entries accordingly
124  int diff = std::static_pointer_cast<BRRIPReplData>(
125  victim->replacementData)->rrpv.saturate();
126 
127  // No need to update RRPV if there is no difference
128  if (diff > 0){
129  // Update RRPV of all candidates
130  for (const auto& candidate : candidates) {
131  std::static_pointer_cast<BRRIPReplData>(
132  candidate->replacementData)->rrpv += diff;
133  }
134  }
135 
136  return victim;
137 }
138 
139 std::shared_ptr<ReplacementData>
141 {
142  return std::shared_ptr<ReplacementData>(new BRRIPReplData(numRRPVBits));
143 }
144 
145 BRRIPRP*
146 BRRIPRPParams::create()
147 {
148  return new BRRIPRP(this);
149 }
ReplaceableEntry
A replaceable entry is a basic entry in a 2d table-like structure that needs to have replacement func...
Definition: replaceable_entry.hh:53
BRRIPRP::touch
void touch(const std::shared_ptr< ReplacementData > &replacement_data) const override
Touch an entry to update its replacement data.
Definition: brrip_rp.cc:57
BaseReplacementPolicy::Params
BaseReplacementPolicyParams Params
Convenience typedef.
Definition: base.hh:52
BRRIPRP::btp
const unsigned btp
Bimodal throtle parameter.
Definition: brrip_rp.hh:106
random.hh
BRRIPRP
Definition: brrip_rp.hh:60
std::vector
STL vector class.
Definition: stl.hh:37
BRRIPRP::invalidate
void invalidate(const std::shared_ptr< ReplacementData > &replacement_data) const override
Invalidate replacement data to set it as the next probable victim.
Definition: brrip_rp.cc:46
random_mt
Random random_mt
Definition: random.cc:96
BaseReplacementPolicy
A common base class of cache replacement policy objects.
Definition: base.hh:46
BRRIPRP::instantiateEntry
std::shared_ptr< ReplacementData > instantiateEntry() override
Instantiate a replacement data entry.
Definition: brrip_rp.cc:140
brrip_rp.hh
Copyright (c) 2018 Inria All rights reserved.
BRRIPRP::numRRPVBits
const unsigned numRRPVBits
Number of RRPV bits.
Definition: brrip_rp.hh:93
BRRIPRP::BRRIPRP
BRRIPRP(const Params *p)
Construct and initiliaze this replacement policy.
Definition: brrip_rp.cc:38
logging.hh
ReplaceableEntry::replacementData
std::shared_ptr< ReplacementData > replacementData
Replacement data associated to this entry.
Definition: replaceable_entry.hh:74
Random::random
std::enable_if< std::is_integral< T >::value, T >::type random()
Use the SFINAE idiom to choose an implementation based on whether the type is integral or floating po...
Definition: random.hh:86
BRRIPRP::reset
void reset(const std::shared_ptr< ReplacementData > &replacement_data) const override
Reset replacement data.
Definition: brrip_rp.cc:73
BRRIPRP::hitPriority
const bool hitPriority
The hit priority (HP) policy replaces entries that do not receive cache hits over any cache entry tha...
Definition: brrip_rp.hh:100
MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:323
BRRIPRP::BRRIPReplData
BRRIP-specific implementation of replacement data.
Definition: brrip_rp.hh:64
fatal_if
#define fatal_if(cond,...)
Conditional fatal macro that checks the supplied condition and only causes a fatal error if the condi...
Definition: logging.hh:219
BRRIPRP::getVictim
ReplaceableEntry * getVictim(const ReplacementCandidates &candidates) const override
Find replacement victim using rrpv.
Definition: brrip_rp.cc:91

Generated on Wed Sep 30 2020 14:02:12 for gem5 by doxygen 1.8.17