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

Generated on Wed Dec 21 2022 10:22:36 for gem5 by doxygen 1.9.1