gem5  v21.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
mru_rp.cc
Go to the documentation of this file.
1 
30 
31 #include <cassert>
32 #include <memory>
33 
34 #include "params/MRURP.hh"
35 #include "sim/core.hh"
36 
37 namespace ReplacementPolicy {
38 
39 MRU::MRU(const Params &p)
40  : Base(p)
41 {
42 }
43 
44 void
45 MRU::invalidate(const std::shared_ptr<ReplacementData>& replacement_data)
46 const
47 {
48  // Reset last touch timestamp
49  std::static_pointer_cast<MRUReplData>(
50  replacement_data)->lastTouchTick = Tick(0);
51 }
52 
53 void
54 MRU::touch(const std::shared_ptr<ReplacementData>& replacement_data) const
55 {
56  // Update last touch timestamp
57  std::static_pointer_cast<MRUReplData>(
58  replacement_data)->lastTouchTick = curTick();
59 }
60 
61 void
62 MRU::reset(const std::shared_ptr<ReplacementData>& replacement_data) const
63 {
64  // Set last touch timestamp
65  std::static_pointer_cast<MRUReplData>(
66  replacement_data)->lastTouchTick = curTick();
67 }
68 
70 MRU::getVictim(const ReplacementCandidates& candidates) const
71 {
72  // There must be at least one replacement candidate
73  assert(candidates.size() > 0);
74 
75  // Visit all candidates to find victim
76  ReplaceableEntry* victim = candidates[0];
77  for (const auto& candidate : candidates) {
78  std::shared_ptr<MRUReplData> candidate_replacement_data =
79  std::static_pointer_cast<MRUReplData>(candidate->replacementData);
80 
81  // Stop searching entry if a cache line that doesn't warm up is found.
82  if (candidate_replacement_data->lastTouchTick == 0) {
83  victim = candidate;
84  break;
85  } else if (candidate_replacement_data->lastTouchTick >
86  std::static_pointer_cast<MRUReplData>(
87  victim->replacementData)->lastTouchTick) {
88  victim = candidate;
89  }
90  }
91 
92  return victim;
93 }
94 
95 std::shared_ptr<ReplacementData>
97 {
98  return std::shared_ptr<ReplacementData>(new MRUReplData());
99 }
100 
101 } // namespace ReplacementPolicy
ReplaceableEntry
A replaceable entry is a basic entry in a 2d table-like structure that needs to have replacement func...
Definition: replaceable_entry.hh:57
ReplacementPolicy::MRU::instantiateEntry
std::shared_ptr< ReplacementData > instantiateEntry() override
Instantiate a replacement data entry.
Definition: mru_rp.cc:96
ReplacementPolicy::MRU::MRUReplData
MRU-specific implementation of replacement data.
Definition: mru_rp.hh:50
ReplacementPolicy::MRU::touch
void touch(const std::shared_ptr< ReplacementData > &replacement_data) const override
Touch an entry to update its replacement data.
Definition: mru_rp.cc:54
Tick
uint64_t Tick
Tick count type.
Definition: types.hh:59
std::vector
STL vector class.
Definition: stl.hh:37
ReplacementPolicy
Copyright (c) 2018-2020 Inria All rights reserved.
Definition: stride.hh:64
ReplacementPolicy::MRU::MRU
MRU(const Params &p)
Definition: mru_rp.cc:39
ReplacementPolicy::Base::Params
BaseReplacementPolicyParams Params
Definition: base.hh:51
ReplacementPolicy::MRU::getVictim
ReplaceableEntry * getVictim(const ReplacementCandidates &candidates) const override
Find replacement victim using access timestamps.
Definition: mru_rp.cc:70
ReplacementPolicy::Base
A common base class of cache replacement policy objects.
Definition: base.hh:48
mru_rp.hh
Copyright (c) 2018-2020 Inria All rights reserved.
ReplaceableEntry::replacementData
std::shared_ptr< ReplacementPolicy::ReplacementData > replacementData
Replacement data associated to this entry.
Definition: replaceable_entry.hh:78
core.hh
ReplacementPolicy::MRU::invalidate
void invalidate(const std::shared_ptr< ReplacementData > &replacement_data) const override
Invalidate replacement data to set it as the next probable victim.
Definition: mru_rp.cc:45
curTick
Tick curTick()
The universal simulation clock.
Definition: cur_tick.hh:43
MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:323
ReplacementPolicy::MRU::reset
void reset(const std::shared_ptr< ReplacementData > &replacement_data) const override
Reset replacement data.
Definition: mru_rp.cc:62

Generated on Tue Mar 23 2021 19:41:27 for gem5 by doxygen 1.8.17