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

Generated on Sun Jul 30 2023 01:56:57 for gem5 by doxygen 1.8.17