gem5  v22.1.0.0
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 GEM5_DEPRECATED_NAMESPACE(ReplacementPolicy, replacement_policy);
41 namespace replacement_policy
42 {
43 
45  : Base(p)
46 {
47 }
48 
49 void
50 Random::invalidate(const std::shared_ptr<ReplacementData>& replacement_data)
51 {
52  // Unprioritize replacement data victimization
53  std::static_pointer_cast<RandomReplData>(
54  replacement_data)->valid = false;
55 }
56 
57 void
58 Random::touch(const std::shared_ptr<ReplacementData>& replacement_data) const
59 {
60 }
61 
62 void
63 Random::reset(const std::shared_ptr<ReplacementData>& replacement_data) const
64 {
65  // Unprioritize replacement data victimization
66  std::static_pointer_cast<RandomReplData>(
67  replacement_data)->valid = true;
68 }
69 
71 Random::getVictim(const ReplacementCandidates& candidates) const
72 {
73  // There must be at least one replacement candidate
74  assert(candidates.size() > 0);
75 
76  // Choose one candidate at random
77  ReplaceableEntry* victim = candidates[random_mt.random<unsigned>(0,
78  candidates.size() - 1)];
79 
80  // Visit all candidates to search for an invalid entry. If one is found,
81  // its eviction is prioritized
82  for (const auto& candidate : candidates) {
83  if (!std::static_pointer_cast<RandomReplData>(
84  candidate->replacementData)->valid) {
85  victim = candidate;
86  break;
87  }
88  }
89 
90  return victim;
91 }
92 
93 std::shared_ptr<ReplacementData>
95 {
96  return std::shared_ptr<ReplacementData>(new RandomReplData());
97 }
98 
99 } // namespace replacement_policy
100 } // namespace gem5
A replaceable entry is a basic entry in a 2d table-like structure that needs to have replacement func...
A common base class of cache replacement policy objects.
Definition: base.hh:56
BaseReplacementPolicyParams Params
Definition: base.hh:58
std::shared_ptr< ReplacementData > instantiateEntry() override
Instantiate a replacement data entry.
Definition: random_rp.cc:94
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:50
void touch(const std::shared_ptr< ReplacementData > &replacement_data) const override
Touch an entry to update its replacement data.
Definition: random_rp.cc:58
void reset(const std::shared_ptr< ReplacementData > &replacement_data) const override
Reset replacement data.
Definition: random_rp.cc:63
ReplaceableEntry * getVictim(const ReplacementCandidates &candidates) const override
Find replacement victim at random.
Definition: random_rp.cc:71
STL vector class.
Definition: stl.hh:37
Random random_mt
Definition: random.cc:99
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
Bitfield< 54 > p
Definition: pagetable.hh:70
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
GEM5_DEPRECATED_NAMESPACE(GuestABI, guest_abi)
Copyright (c) 2018-2020 Inria All rights reserved.
Random-specific implementation of replacement data.
Definition: random_rp.hh:54

Generated on Wed Dec 21 2022 10:22:36 for gem5 by doxygen 1.9.1