gem5 v24.0.0.0
Loading...
Searching...
No Matches
second_chance_rp.cc
Go to the documentation of this file.
1
30
31#include <cassert>
32
33#include "params/SecondChanceRP.hh"
34
35namespace gem5
36{
37
38namespace replacement_policy
39{
40
45
46void
48 const std::shared_ptr<SecondChanceReplData>& replacement_data) const
49{
50 // Reset FIFO data
51 FIFO::reset(replacement_data);
52
53 // Use second chance
54 replacement_data->hasSecondChance = false;
55}
56
57void
59 const std::shared_ptr<ReplacementData>& replacement_data)
60{
61 FIFO::invalidate(replacement_data);
62
63 // Do not give a second chance to invalid entries
64 std::static_pointer_cast<SecondChanceReplData>(
65 replacement_data)->hasSecondChance = false;
66}
67
68void
70 const std::shared_ptr<ReplacementData>& replacement_data) const
71{
72 FIFO::touch(replacement_data);
73
74 // Whenever an entry is touched, it is given a second chance
75 std::static_pointer_cast<SecondChanceReplData>(
76 replacement_data)->hasSecondChance = true;
77}
78
79void
81 const std::shared_ptr<ReplacementData>& replacement_data) const
82{
83 FIFO::reset(replacement_data);
84
85 // Entries are inserted with a second chance
86 std::static_pointer_cast<SecondChanceReplData>(
87 replacement_data)->hasSecondChance = false;
88}
89
92{
93 // There must be at least one replacement candidate
94 assert(candidates.size() > 0);
95
96 // Search for invalid entries, as they have the eviction priority
97 for (const auto& candidate : candidates) {
98 // Cast candidate's replacement data
99 std::shared_ptr<SecondChanceReplData> candidate_replacement_data =
100 std::static_pointer_cast<SecondChanceReplData>(
101 candidate->replacementData);
102
103 // Stop iteration if found an invalid entry
104 if ((candidate_replacement_data->tickInserted == Tick(0)) &&
105 !candidate_replacement_data->hasSecondChance) {
106 return candidate;
107 }
108 }
109
110 // Visit all candidates to find victim
111 ReplaceableEntry* victim = candidates[0];
112 bool search_victim = true;
113 while (search_victim) {
114 // Do a FIFO victim search
115 victim = FIFO::getVictim(candidates);
116
117 // Cast victim's replacement data for code readability
118 std::shared_ptr<SecondChanceReplData> victim_replacement_data =
119 std::static_pointer_cast<SecondChanceReplData>(
120 victim->replacementData);
121
122 // If victim has a second chance, use it and repeat search
123 if (victim_replacement_data->hasSecondChance) {
124 useSecondChance(victim_replacement_data);
125 } else {
126 // Found victim
127 search_victim = false;
128 }
129 }
130
131 return victim;
132}
133
134std::shared_ptr<ReplacementData>
136{
137 return std::shared_ptr<ReplacementData>(new SecondChanceReplData());
138}
139
140} // namespace replacement_policy
141} // namespace gem5
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.
void reset(const std::shared_ptr< ReplacementData > &replacement_data) const override
Reset replacement data.
Definition fifo_rp.cc:63
ReplaceableEntry * getVictim(const ReplacementCandidates &candidates) const override
Find replacement victim using insertion timestamps.
Definition fifo_rp.cc:71
void invalidate(const std::shared_ptr< ReplacementData > &replacement_data) override
Invalidate replacement data to set it as the next probable victim.
Definition fifo_rp.cc:49
void touch(const std::shared_ptr< ReplacementData > &replacement_data) const override
Touch an entry to update its replacement data.
Definition fifo_rp.cc:57
std::shared_ptr< ReplacementData > instantiateEntry() override
Instantiate a replacement data entry.
ReplaceableEntry * getVictim(const ReplacementCandidates &candidates) const override
Find replacement victim using insertion timestamps and second chance bit.
void reset(const std::shared_ptr< ReplacementData > &replacement_data) const override
Reset replacement data.
void useSecondChance(const std::shared_ptr< SecondChanceReplData > &replacement_data) const
Use replacement data's second chance.
void touch(const std::shared_ptr< ReplacementData > &replacement_data) const override
Touch an entry to update its re-insertion tick and second chance bit.
void invalidate(const std::shared_ptr< ReplacementData > &replacement_data) override
Invalidate replacement data to set it as the next probable victim.
STL vector class.
Definition stl.hh:37
Bitfield< 0 > p
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
uint64_t Tick
Tick count type.
Definition types.hh:58
Copyright (c) 2018-2020 Inria All rights reserved.
Second-Chance-specific implementation of replacement data.

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