gem5  v20.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 
36  : FIFORP(p)
37 {
38 }
39 
40 void
42  const std::shared_ptr<SecondChanceReplData>& replacement_data) const
43 {
44  // Reset FIFO data
45  FIFORP::reset(replacement_data);
46 
47  // Use second chance
48  replacement_data->hasSecondChance = false;
49 }
50 
51 void
53  const std::shared_ptr<ReplacementData>& replacement_data) const
54 {
55  FIFORP::invalidate(replacement_data);
56 
57  // Do not give a second chance to invalid entries
58  std::static_pointer_cast<SecondChanceReplData>(
59  replacement_data)->hasSecondChance = false;
60 }
61 
62 void
63 SecondChanceRP::touch(const std::shared_ptr<ReplacementData>&
64  replacement_data) const
65 {
66  FIFORP::touch(replacement_data);
67 
68  // Whenever an entry is touched, it is given a second chance
69  std::static_pointer_cast<SecondChanceReplData>(
70  replacement_data)->hasSecondChance = true;
71 }
72 
73 void
74 SecondChanceRP::reset(const std::shared_ptr<ReplacementData>&
75  replacement_data) const
76 {
77  FIFORP::reset(replacement_data);
78 
79  // Entries are inserted with a second chance
80  std::static_pointer_cast<SecondChanceReplData>(
81  replacement_data)->hasSecondChance = false;
82 }
83 
86 {
87  // There must be at least one replacement candidate
88  assert(candidates.size() > 0);
89 
90  // Search for invalid entries, as they have the eviction priority
91  for (const auto& candidate : candidates) {
92  // Cast candidate's replacement data
93  std::shared_ptr<SecondChanceReplData> candidate_replacement_data =
94  std::static_pointer_cast<SecondChanceReplData>(
95  candidate->replacementData);
96 
97  // Stop iteration if found an invalid entry
98  if ((candidate_replacement_data->tickInserted == Tick(0)) &&
99  !candidate_replacement_data->hasSecondChance) {
100  return candidate;
101  }
102  }
103 
104  // Visit all candidates to find victim
105  ReplaceableEntry* victim = candidates[0];
106  bool search_victim = true;
107  while (search_victim) {
108  // Do a FIFO victim search
109  victim = FIFORP::getVictim(candidates);
110 
111  // Cast victim's replacement data for code readability
112  std::shared_ptr<SecondChanceReplData> victim_replacement_data =
113  std::static_pointer_cast<SecondChanceReplData>(
114  victim->replacementData);
115 
116  // If victim has a second chance, use it and repeat search
117  if (victim_replacement_data->hasSecondChance) {
118  useSecondChance(victim_replacement_data);
119  } else {
120  // Found victim
121  search_victim = false;
122  }
123  }
124 
125  return victim;
126 }
127 
128 std::shared_ptr<ReplacementData>
130 {
131  return std::shared_ptr<ReplacementData>(new SecondChanceReplData());
132 }
133 
135 SecondChanceRPParams::create()
136 {
137  return new SecondChanceRP(this);
138 }
ReplaceableEntry
A replaceable entry is a basic entry in a 2d table-like structure that needs to have replacement func...
Definition: replaceable_entry.hh:53
BaseReplacementPolicy::Params
BaseReplacementPolicyParams Params
Convenience typedef.
Definition: base.hh:52
FIFORP::getVictim
ReplaceableEntry * getVictim(const ReplacementCandidates &candidates) const override
Find replacement victim using insertion timestamps.
Definition: fifo_rp.cc:66
SecondChanceRP::instantiateEntry
std::shared_ptr< ReplacementData > instantiateEntry() override
Instantiate a replacement data entry.
Definition: second_chance_rp.cc:129
FIFORP::touch
void touch(const std::shared_ptr< ReplacementData > &replacement_data) const override
Touch an entry to update its replacement data.
Definition: fifo_rp.cc:52
Tick
uint64_t Tick
Tick count type.
Definition: types.hh:63
SecondChanceRP::getVictim
ReplaceableEntry * getVictim(const ReplacementCandidates &candidates) const override
Find replacement victim using insertion timestamps and second chance bit.
Definition: second_chance_rp.cc:85
std::vector
STL vector class.
Definition: stl.hh:37
SecondChanceRP::SecondChanceReplData
Second-Chance-specific implementation of replacement data.
Definition: second_chance_rp.hh:50
SecondChanceRP::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:63
SecondChanceRP::useSecondChance
void useSecondChance(const std::shared_ptr< SecondChanceReplData > &replacement_data) const
Use replacement data's second chance.
Definition: second_chance_rp.cc:41
FIFORP::reset
void reset(const std::shared_ptr< ReplacementData > &replacement_data) const override
Reset replacement data.
Definition: fifo_rp.cc:58
FIFORP::invalidate
void invalidate(const std::shared_ptr< ReplacementData > &replacement_data) const override
Invalidate replacement data to set it as the next probable victim.
Definition: fifo_rp.cc:43
ReplaceableEntry::replacementData
std::shared_ptr< ReplacementData > replacementData
Replacement data associated to this entry.
Definition: replaceable_entry.hh:74
SecondChanceRP::invalidate
void invalidate(const std::shared_ptr< ReplacementData > &replacement_data) const override
Invalidate replacement data to set it as the next probable victim.
Definition: second_chance_rp.cc:52
FIFORP
Definition: fifo_rp.hh:44
second_chance_rp.hh
Copyright (c) 2018 Inria All rights reserved.
SecondChanceRP::SecondChanceRP
SecondChanceRP(const Params *p)
Construct and initiliaze this replacement policy.
Definition: second_chance_rp.cc:35
MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:323
SecondChanceRP::reset
void reset(const std::shared_ptr< ReplacementData > &replacement_data) const override
Reset replacement data.
Definition: second_chance_rp.cc:74
SecondChanceRP
Definition: second_chance_rp.hh:46

Generated on Wed Sep 30 2020 14:02:12 for gem5 by doxygen 1.8.17