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

Generated on Wed Dec 21 2022 10:22:36 for gem5 by doxygen 1.9.1