gem5 v24.0.0.0
Loading...
Searching...
No Matches
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
38namespace gem5
39{
40
41namespace 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
51void
52BRRIP::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
61void
62BRRIP::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
77void
78BRRIP::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
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
144std::shared_ptr<ReplacementData>
146{
147 return std::shared_ptr<ReplacementData>(new BRRIPReplData(numRRPVBits));
148}
149
150} // namespace replacement_policy
151} // 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:96
const unsigned numRRPVBits
Number of RRPV bits.
Definition brrip_rp.hh:99
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
void touch(const std::shared_ptr< ReplacementData > &replacement_data) const override
Touch an entry to update its replacement data.
Definition brrip_rp.cc:62
void reset(const std::shared_ptr< ReplacementData > &replacement_data) const override
Reset replacement data.
Definition brrip_rp.cc:78
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
const unsigned btp
Bimodal throtle parameter.
Definition brrip_rp.hh:112
std::shared_ptr< ReplacementData > instantiateEntry() override
Instantiate a replacement data entry.
Definition brrip_rp.cc:145
A common base class of cache replacement policy objects.
Definition base.hh:55
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:236
Bitfield< 0 > p
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
BRRIP-specific implementation of replacement data.
Definition brrip_rp.hh:71

Generated on Tue Jun 18 2024 16:24:05 for gem5 by doxygen 1.11.0