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

Generated on Mon Jan 13 2025 04:28:38 for gem5 by doxygen 1.9.8