gem5  v21.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
lfu_rp.cc
Go to the documentation of this file.
1 
30 
31 #include <cassert>
32 #include <memory>
33 
34 #include "params/LFURP.hh"
35 
36 namespace ReplacementPolicy {
37 
38 LFU::LFU(const Params &p)
39  : Base(p)
40 {
41 }
42 
43 void
44 LFU::invalidate(const std::shared_ptr<ReplacementData>& replacement_data)
45 const
46 {
47  // Reset reference count
48  std::static_pointer_cast<LFUReplData>(replacement_data)->refCount = 0;
49 }
50 
51 void
52 LFU::touch(const std::shared_ptr<ReplacementData>& replacement_data) const
53 {
54  // Update reference count
55  std::static_pointer_cast<LFUReplData>(replacement_data)->refCount++;
56 }
57 
58 void
59 LFU::reset(const std::shared_ptr<ReplacementData>& replacement_data) const
60 {
61  // Reset reference count
62  std::static_pointer_cast<LFUReplData>(replacement_data)->refCount = 1;
63 }
64 
66 LFU::getVictim(const ReplacementCandidates& candidates) const
67 {
68  // There must be at least one replacement candidate
69  assert(candidates.size() > 0);
70 
71  // Visit all candidates to find victim
72  ReplaceableEntry* victim = candidates[0];
73  for (const auto& candidate : candidates) {
74  // Update victim entry if necessary
75  if (std::static_pointer_cast<LFUReplData>(
76  candidate->replacementData)->refCount <
77  std::static_pointer_cast<LFUReplData>(
78  victim->replacementData)->refCount) {
79  victim = candidate;
80  }
81  }
82 
83  return victim;
84 }
85 
86 std::shared_ptr<ReplacementData>
88 {
89  return std::shared_ptr<ReplacementData>(new LFUReplData());
90 }
91 
92 } // 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::LFU::reset
void reset(const std::shared_ptr< ReplacementData > &replacement_data) const override
Reset replacement data.
Definition: lfu_rp.cc:59
lfu_rp.hh
Copyright (c) 2018-2020 Inria All rights reserved.
std::vector
STL vector class.
Definition: stl.hh:37
ReplacementPolicy::LFU::LFU
LFU(const Params &p)
Definition: lfu_rp.cc:38
ReplacementPolicy
Copyright (c) 2018-2020 Inria All rights reserved.
Definition: stride.hh:64
ReplacementPolicy::Base::Params
BaseReplacementPolicyParams Params
Definition: base.hh:51
ReplacementPolicy::Base
A common base class of cache replacement policy objects.
Definition: base.hh:48
ReplacementPolicy::LFU::getVictim
ReplaceableEntry * getVictim(const ReplacementCandidates &candidates) const override
Find replacement victim using reference frequency.
Definition: lfu_rp.cc:66
ReplaceableEntry::replacementData
std::shared_ptr< ReplacementPolicy::ReplacementData > replacementData
Replacement data associated to this entry.
Definition: replaceable_entry.hh:78
ReplacementPolicy::LFU::LFUReplData
LFU-specific implementation of replacement data.
Definition: lfu_rp.hh:50
ReplacementPolicy::LFU::instantiateEntry
std::shared_ptr< ReplacementData > instantiateEntry() override
Instantiate a replacement data entry.
Definition: lfu_rp.cc:87
MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:323
ReplacementPolicy::LFU::invalidate
void invalidate(const std::shared_ptr< ReplacementData > &replacement_data) const override
Invalidate replacement data to set it as the next probable victim.
Definition: lfu_rp.cc:44
ReplacementPolicy::LFU::touch
void touch(const std::shared_ptr< ReplacementData > &replacement_data) const override
Touch an entry to update its replacement data.
Definition: lfu_rp.cc:52

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