gem5  v21.2.1.1
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
gem5::replacement_policy::FIFO::getVictim
ReplaceableEntry * getVictim(const ReplacementCandidates &candidates) const override
Find replacement victim using insertion timestamps.
Definition: fifo_rp.cc:72
gem5::replacement_policy::SecondChance::touch
void touch(const std::shared_ptr< ReplacementData > &replacement_data) const override
Touch an entry to update its re-insertion tick and second chance bit.
Definition: second_chance_rp.cc:70
gem5::replacement_policy::Base::Params
BaseReplacementPolicyParams Params
Definition: base.hh:58
gem5::replacement_policy::FIFO::invalidate
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
std::vector
STL vector class.
Definition: stl.hh:37
gem5::replacement_policy::FIFO::reset
void reset(const std::shared_ptr< ReplacementData > &replacement_data) const override
Reset replacement data.
Definition: fifo_rp.cc:64
gem5::MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:326
gem5::Tick
uint64_t Tick
Tick count type.
Definition: types.hh:58
gem5::replacement_policy::SecondChance::SecondChance
SecondChance(const Params &p)
Definition: second_chance_rp.cc:42
gem5::replacement_policy::SecondChance::instantiateEntry
std::shared_ptr< ReplacementData > instantiateEntry() override
Instantiate a replacement data entry.
Definition: second_chance_rp.cc:136
gem5::replacement_policy::SecondChance::invalidate
void invalidate(const std::shared_ptr< ReplacementData > &replacement_data) override
Invalidate replacement data to set it as the next probable victim.
Definition: second_chance_rp.cc:59
gem5::replacement_policy::SecondChance::SecondChanceReplData
Second-Chance-specific implementation of replacement data.
Definition: second_chance_rp.hh:57
gem5::replacement_policy::FIFO::touch
void touch(const std::shared_ptr< ReplacementData > &replacement_data) const override
Touch an entry to update its replacement data.
Definition: fifo_rp.cc:58
gem5::GEM5_DEPRECATED_NAMESPACE
GEM5_DEPRECATED_NAMESPACE(GuestABI, guest_abi)
gem5::replacement_policy::SecondChance::getVictim
ReplaceableEntry * getVictim(const ReplacementCandidates &candidates) const override
Find replacement victim using insertion timestamps and second chance bit.
Definition: second_chance_rp.cc:92
gem5::replacement_policy::FIFO
Definition: fifo_rp.hh:51
gem5::replacement_policy::SecondChance::reset
void reset(const std::shared_ptr< ReplacementData > &replacement_data) const override
Reset replacement data.
Definition: second_chance_rp.cc:81
gem5::replacement_policy::SecondChance::useSecondChance
void useSecondChance(const std::shared_ptr< SecondChanceReplData > &replacement_data) const
Use replacement data's second chance.
Definition: second_chance_rp.cc:48
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
second_chance_rp.hh
Copyright (c) 2018-2020 Inria All rights reserved.
gem5::ReplaceableEntry::replacementData
std::shared_ptr< replacement_policy::ReplacementData > replacementData
Replacement data associated to this entry.
Definition: replaceable_entry.hh:84
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: tlb.cc:60

Generated on Wed May 4 2022 12:14:00 for gem5 by doxygen 1.8.17