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

Generated on Tue Jun 22 2021 15:28:29 for gem5 by doxygen 1.8.17