gem5  v21.2.1.1
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
gem5::replacement_policy::BRRIP::instantiateEntry
std::shared_ptr< ReplacementData > instantiateEntry() override
Instantiate a replacement data entry.
Definition: brrip_rp.cc:146
gem5::replacement_policy::BRRIP::btp
const unsigned btp
Bimodal throtle parameter.
Definition: brrip_rp.hh:113
gem5::replacement_policy::BRRIP::getVictim
ReplaceableEntry * getVictim(const ReplacementCandidates &candidates) const override
Find replacement victim using rrpv.
Definition: brrip_rp.cc:97
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:63
gem5::replacement_policy::Base::Params
BaseReplacementPolicyParams Params
Definition: base.hh:58
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:45
gem5::replacement_policy::BRRIP::BRRIPReplData
BRRIP-specific implementation of replacement data.
Definition: brrip_rp.hh:71
gem5::MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:326
gem5::replacement_policy::Base
A common base class of cache replacement policy objects.
Definition: base.hh:55
gem5::replacement_policy::BRRIP::numRRPVBits
const unsigned numRRPVBits
Number of RRPV bits.
Definition: brrip_rp.hh:100
gem5::GEM5_DEPRECATED_NAMESPACE
GEM5_DEPRECATED_NAMESPACE(GuestABI, guest_abi)
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:79
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:63
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:53
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:107
gem5::ReplaceableEntry::replacementData
std::shared_ptr< replacement_policy::ReplacementData > replacementData
Replacement data associated to this entry.
Definition: replaceable_entry.hh:84
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:226
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: tlb.cc:60
gem5::random_mt
Random random_mt
Definition: random.cc:99

Generated on Wed May 4 2022 12:13:59 for gem5 by doxygen 1.8.17