gem5  [DEVELOP-FOR-23.0]
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
random_rp.cc
Go to the documentation of this file.
1 
30 
31 #include <cassert>
32 #include <memory>
33 
34 #include "base/random.hh"
35 #include "params/RandomRP.hh"
36 
37 namespace gem5
38 {
39 
40 namespace replacement_policy
41 {
42 
44  : Base(p)
45 {
46 }
47 
48 void
49 Random::invalidate(const std::shared_ptr<ReplacementData>& replacement_data)
50 {
51  // Unprioritize replacement data victimization
52  std::static_pointer_cast<RandomReplData>(
53  replacement_data)->valid = false;
54 }
55 
56 void
57 Random::touch(const std::shared_ptr<ReplacementData>& replacement_data) const
58 {
59 }
60 
61 void
62 Random::reset(const std::shared_ptr<ReplacementData>& replacement_data) const
63 {
64  // Unprioritize replacement data victimization
65  std::static_pointer_cast<RandomReplData>(
66  replacement_data)->valid = true;
67 }
68 
70 Random::getVictim(const ReplacementCandidates& candidates) const
71 {
72  // There must be at least one replacement candidate
73  assert(candidates.size() > 0);
74 
75  // Choose one candidate at random
76  ReplaceableEntry* victim = candidates[random_mt.random<unsigned>(0,
77  candidates.size() - 1)];
78 
79  // Visit all candidates to search for an invalid entry. If one is found,
80  // its eviction is prioritized
81  for (const auto& candidate : candidates) {
82  if (!std::static_pointer_cast<RandomReplData>(
83  candidate->replacementData)->valid) {
84  victim = candidate;
85  break;
86  }
87  }
88 
89  return victim;
90 }
91 
92 std::shared_ptr<ReplacementData>
94 {
95  return std::shared_ptr<ReplacementData>(new RandomReplData());
96 }
97 
98 } // namespace replacement_policy
99 } // namespace gem5
gem5::replacement_policy::Base::Params
BaseReplacementPolicyParams Params
Definition: base.hh:57
random.hh
std::vector
STL vector class.
Definition: stl.hh:37
gem5::Random::random
std::enable_if_t< std::is_integral_v< T >, T > random()
Use the SFINAE idiom to choose an implementation based on whether the type is integral or floating po...
Definition: random.hh:90
gem5::VegaISA::p
Bitfield< 54 > p
Definition: pagetable.hh:70
gem5::replacement_policy::Random::reset
void reset(const std::shared_ptr< ReplacementData > &replacement_data) const override
Reset replacement data.
Definition: random_rp.cc:62
random_rp.hh
Copyright (c) 2018-2020 Inria All rights reserved.
gem5::replacement_policy::Random::instantiateEntry
std::shared_ptr< ReplacementData > instantiateEntry() override
Instantiate a replacement data entry.
Definition: random_rp.cc:93
gem5::replacement_policy::Random::Random
Random(const Params &p)
Definition: random_rp.cc:43
gem5::replacement_policy::Base
A common base class of cache replacement policy objects.
Definition: base.hh:54
gem5::replacement_policy::Random::touch
void touch(const std::shared_ptr< ReplacementData > &replacement_data) const override
Touch an entry to update its replacement data.
Definition: random_rp.cc:57
gem5::replacement_policy::Random::invalidate
void invalidate(const std::shared_ptr< ReplacementData > &replacement_data) override
Invalidate replacement data to set it as the next probable victim.
Definition: random_rp.cc:49
gem5::replacement_policy::Random::getVictim
ReplaceableEntry * getVictim(const ReplacementCandidates &candidates) const override
Find replacement victim at random.
Definition: random_rp.cc:70
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:62
gem5::replacement_policy::Random::RandomReplData
Random-specific implementation of replacement data.
Definition: random_rp.hh:52
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: gpu_translation_state.hh:37
gem5::random_mt
Random random_mt
Definition: random.cc:99

Generated on Sun Jul 30 2023 01:56:57 for gem5 by doxygen 1.8.17