gem5  v21.1.0.2
dueling_rp.cc
Go to the documentation of this file.
1 
30 
31 #include "base/logging.hh"
32 #include "params/DuelingRP.hh"
33 
34 namespace gem5
35 {
36 
37 namespace replacement_policy
38 {
39 
41  : Base(p), replPolicyA(p.replacement_policy_a),
42  replPolicyB(p.replacement_policy_b),
43  duelingMonitor(p.constituency_size, p.team_size),
44  duelingStats(this)
45 {
46  fatal_if((replPolicyA == nullptr) || (replPolicyB == nullptr),
47  "All replacement policies must be instantiated");
48 }
49 
50 void
51 Dueling::invalidate(const std::shared_ptr<ReplacementData>& replacement_data)
52 {
53  std::shared_ptr<DuelerReplData> casted_replacement_data =
54  std::static_pointer_cast<DuelerReplData>(replacement_data);
55  replPolicyA->invalidate(casted_replacement_data->replDataA);
56  replPolicyB->invalidate(casted_replacement_data->replDataB);
57 }
58 
59 void
60 Dueling::touch(const std::shared_ptr<ReplacementData>& replacement_data,
61  const PacketPtr pkt)
62 {
63  std::shared_ptr<DuelerReplData> casted_replacement_data =
64  std::static_pointer_cast<DuelerReplData>(replacement_data);
65  replPolicyA->touch(casted_replacement_data->replDataA, pkt);
66  replPolicyB->touch(casted_replacement_data->replDataB, pkt);
67 }
68 
69 void
70 Dueling::touch(const std::shared_ptr<ReplacementData>& replacement_data) const
71 {
72  std::shared_ptr<DuelerReplData> casted_replacement_data =
73  std::static_pointer_cast<DuelerReplData>(replacement_data);
74  replPolicyA->touch(casted_replacement_data->replDataA);
75  replPolicyB->touch(casted_replacement_data->replDataB);
76 }
77 
78 void
79 Dueling::reset(const std::shared_ptr<ReplacementData>& replacement_data,
80  const PacketPtr pkt)
81 {
82  std::shared_ptr<DuelerReplData> casted_replacement_data =
83  std::static_pointer_cast<DuelerReplData>(replacement_data);
84  replPolicyA->reset(casted_replacement_data->replDataA, pkt);
85  replPolicyB->reset(casted_replacement_data->replDataB, pkt);
86 
87  // A miss in a set is a sample to the duel. A call to this function
88  // implies in the replacement of an entry, which was either caused by
89  // a miss, an external invalidation, or the initialization of the table
90  // entry (when warming up)
91  duelingMonitor.sample(static_cast<Dueler*>(casted_replacement_data.get()));
92 }
93 
94 void
95 Dueling::reset(const std::shared_ptr<ReplacementData>& replacement_data) const
96 {
97  std::shared_ptr<DuelerReplData> casted_replacement_data =
98  std::static_pointer_cast<DuelerReplData>(replacement_data);
99  replPolicyA->reset(casted_replacement_data->replDataA);
100  replPolicyB->reset(casted_replacement_data->replDataB);
101 
102  // A miss in a set is a sample to the duel. A call to this function
103  // implies in the replacement of an entry, which was either caused by
104  // a miss, an external invalidation, or the initialization of the table
105  // entry (when warming up)
106  duelingMonitor.sample(static_cast<Dueler*>(casted_replacement_data.get()));
107 }
108 
111 {
112  // This function assumes that all candidates are either part of the same
113  // sampled set, or are not samples.
114  // @todo This should be improved at some point.
115  panic_if(candidates.size() != params().team_size, "We currently only "
116  "support team sizes that match the number of replacement candidates");
117 
118  // The team with the most misses loses
119  bool winner = !duelingMonitor.getWinner();
120 
121  // If the entry is a sample, it can only be used with a certain policy.
122  bool team;
123  bool is_sample = duelingMonitor.isSample(static_cast<Dueler*>(
124  std::static_pointer_cast<DuelerReplData>(
125  candidates[0]->replacementData).get()), team);
126 
127  // All replacement candidates must be set appropriately, so that the
128  // proper replacement data is used. A replacement policy X must be used
129  // if the candidates are its samples - in which case they must always
130  // use X - or if it is not a sample, and X is currently the best RP.
131  // This assumes that A's team is "false", and B's team is "true".
132  bool team_a;
133  if ((is_sample && !team) || (!is_sample && !winner)) {
135  team_a = true;
136  } else {
138  team_a = false;
139  }
140 
141  // Create a temporary list of replacement candidates which re-routes the
142  // replacement data of the selected team
143  std::vector<std::shared_ptr<ReplacementData>> dueling_replacement_data;
144  for (auto& candidate : candidates) {
145  std::shared_ptr<DuelerReplData> dueler_repl_data =
146  std::static_pointer_cast<DuelerReplData>(
147  candidate->replacementData);
148 
149  // As of now we assume that all candidates are either part of
150  // the same sampled team, or are not samples.
151  bool candidate_team;
152  panic_if(
153  duelingMonitor.isSample(dueler_repl_data.get(), candidate_team) &&
154  (team != candidate_team),
155  "Not all sampled candidates belong to the same team");
156 
157  // Copy the original entry's data, re-routing its replacement data
158  // to the selected one
159  dueling_replacement_data.push_back(dueler_repl_data);
160  candidate->replacementData = team_a ? dueler_repl_data->replDataA :
161  dueler_repl_data->replDataB;
162  }
163 
164  // Use the selected replacement policy to find the victim
165  ReplaceableEntry* victim = team_a ? replPolicyA->getVictim(candidates) :
166  replPolicyB->getVictim(candidates);
167 
168  // Search for entry within the original candidates and clean-up duplicates
169  for (int i = 0; i < candidates.size(); i++) {
170  candidates[i]->replacementData = dueling_replacement_data[i];
171  }
172 
173  return victim;
174 }
175 
176 std::shared_ptr<ReplacementData>
178 {
179  DuelerReplData* replacement_data = new DuelerReplData(
181  duelingMonitor.initEntry(static_cast<Dueler*>(replacement_data));
182  return std::shared_ptr<DuelerReplData>(replacement_data);
183 }
184 
186  : statistics::Group(parent),
187  ADD_STAT(selectedA, "Number of times A was selected to victimize"),
188  ADD_STAT(selectedB, "Number of times B was selected to victimize")
189 {
190 }
191 
192 } // namespace replacement_policy
193 } // namespace gem5
gem5::replacement_policy::Dueling::touch
void touch(const std::shared_ptr< ReplacementData > &replacement_data, const PacketPtr pkt) override
Update replacement data.
Definition: dueling_rp.cc:60
gem5::replacement_policy::Dueling::getVictim
ReplaceableEntry * getVictim(const ReplacementCandidates &candidates) const override
Find replacement victim among candidates.
Definition: dueling_rp.cc:110
gem5::DuelingMonitor::initEntry
void initEntry(Dueler *dueler)
Initialize a dueler entry, deciding wether it is a sample or not.
Definition: dueling.cc:124
gem5::replacement_policy::Base::Params
BaseReplacementPolicyParams Params
Definition: base.hh:58
gem5::replacement_policy::Dueling::reset
void reset(const std::shared_ptr< ReplacementData > &replacement_data, const PacketPtr pkt) override
Reset replacement data.
Definition: dueling_rp.cc:79
gem5::replacement_policy::Base::reset
virtual void reset(const std::shared_ptr< ReplacementData > &replacement_data, const PacketPtr pkt)
Reset replacement data.
Definition: base.hh:90
gem5::replacement_policy::Dueling::DuelerReplData
Dueler-specific implementation of replacement data.
Definition: dueling_rp.hh:60
std::vector
STL vector class.
Definition: stl.hh:37
gem5::replacement_policy::Dueling::DuelingStats::selectedA
statistics::Scalar selectedA
Number of times A was selected on victimization.
Definition: dueling_rp.hh:90
gem5::replacement_policy::Dueling::invalidate
void invalidate(const std::shared_ptr< ReplacementData > &replacement_data) override
Invalidate replacement data to set it as the next probable victim.
Definition: dueling_rp.cc:51
gem5::ArmISA::i
Bitfield< 7 > i
Definition: misc_types.hh:66
gem5::replacement_policy::Base::instantiateEntry
virtual std::shared_ptr< ReplacementData > instantiateEntry()=0
Instantiate a replacement data entry.
dueling_rp.hh
gem5::DuelingMonitor::getWinner
bool getWinner() const
Get the team that is currently winning the duel.
Definition: dueling.cc:118
gem5::SimObject::params
const Params & params() const
Definition: sim_object.hh:176
gem5::replacement_policy::Dueling::replPolicyB
Base *const replPolicyB
Sub-replacement policy used in this multiple container.
Definition: dueling_rp.hh:77
ADD_STAT
#define ADD_STAT(n,...)
Convenience macro to add a stat to a statistics group.
Definition: group.hh:75
gem5::Packet
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:283
gem5::MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:326
gem5::replacement_policy::Base::getVictim
virtual ReplaceableEntry * getVictim(const ReplacementCandidates &candidates) const =0
Find replacement victim among candidates.
gem5::replacement_policy::Dueling::duelingStats
gem5::replacement_policy::Dueling::DuelingStats duelingStats
gem5::replacement_policy::Base
A common base class of cache replacement policy objects.
Definition: base.hh:55
gem5::replacement_policy::Dueling::DuelingStats::DuelingStats
DuelingStats(statistics::Group *parent)
Definition: dueling_rp.cc:185
gem5::replacement_policy::Dueling::Dueling
Dueling(const Params &p)
Definition: dueling_rp.cc:40
gem5::replacement_policy::Dueling::DuelingStats::selectedB
statistics::Scalar selectedB
Number of times B was selected on victimization.
Definition: dueling_rp.hh:93
panic_if
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
Definition: logging.hh:203
gem5::replacement_policy::Base::touch
virtual void touch(const std::shared_ptr< ReplacementData > &replacement_data, const PacketPtr pkt)
Update replacement data.
Definition: base.hh:76
gem5::replacement_policy::Dueling::replPolicyA
Base *const replPolicyA
Sub-replacement policy used in this multiple container.
Definition: dueling_rp.hh:75
gem5::replacement_policy::Dueling::instantiateEntry
std::shared_ptr< ReplacementData > instantiateEntry() override
Instantiate a replacement data entry.
Definition: dueling_rp.cc:177
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
logging.hh
gem5::statistics::Group
Statistics container.
Definition: group.hh:93
gem5::DuelingMonitor::isSample
bool isSample(const Dueler *dueler, bool &team) const
Check if the given dueler is a sample for this instance.
Definition: dueling.cc:112
gem5::Dueler
A dueler is an entry that may or may not be accounted for sampling.
Definition: dueling.hh:52
gem5::ReplaceableEntry::replacementData
std::shared_ptr< replacement_policy::ReplacementData > replacementData
Replacement data associated to this entry.
Definition: replaceable_entry.hh:84
gem5::DuelingMonitor::sample
void sample(const Dueler *dueler)
If given dueler is a sampling entry, sample it and check if the winning team must be updated.
Definition: dueling.cc:91
fatal_if
#define fatal_if(cond,...)
Conditional fatal macro that checks the supplied condition and only causes a fatal error if the condi...
Definition: logging.hh:225
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: decoder.cc:40
gem5::replacement_policy::Dueling::duelingMonitor
DuelingMonitor duelingMonitor
A dueling monitor that decides which is the best sub-policy based on their number of misses.
Definition: dueling_rp.hh:83
gem5::replacement_policy::Base::invalidate
virtual void invalidate(const std::shared_ptr< ReplacementData > &replacement_data)=0
Invalidate replacement data to set it as the next probable victim.

Generated on Tue Sep 21 2021 12:25:30 for gem5 by doxygen 1.8.17