gem5  v20.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 
39 {
40 }
41 
42 void
43 RandomRP::invalidate(const std::shared_ptr<ReplacementData>& replacement_data)
44 const
45 {
46  // Unprioritize replacement data victimization
47  std::static_pointer_cast<RandomReplData>(
48  replacement_data)->valid = false;
49 }
50 
51 void
52 RandomRP::touch(const std::shared_ptr<ReplacementData>& replacement_data) const
53 {
54 }
55 
56 void
57 RandomRP::reset(const std::shared_ptr<ReplacementData>& replacement_data) const
58 {
59  // Unprioritize replacement data victimization
60  std::static_pointer_cast<RandomReplData>(
61  replacement_data)->valid = true;
62 }
63 
66 {
67  // There must be at least one replacement candidate
68  assert(candidates.size() > 0);
69 
70  // Choose one candidate at random
71  ReplaceableEntry* victim = candidates[random_mt.random<unsigned>(0,
72  candidates.size() - 1)];
73 
74  // Visit all candidates to search for an invalid entry. If one is found,
75  // its eviction is prioritized
76  for (const auto& candidate : candidates) {
77  if (!std::static_pointer_cast<RandomReplData>(
78  candidate->replacementData)->valid) {
79  victim = candidate;
80  break;
81  }
82  }
83 
84  return victim;
85 }
86 
87 std::shared_ptr<ReplacementData>
89 {
90  return std::shared_ptr<ReplacementData>(new RandomReplData());
91 }
92 
93 RandomRP*
94 RandomRPParams::create()
95 {
96  return new RandomRP(this);
97 }
ReplaceableEntry
A replaceable entry is a basic entry in a 2d table-like structure that needs to have replacement func...
Definition: replaceable_entry.hh:53
BaseReplacementPolicy::Params
BaseReplacementPolicyParams Params
Convenience typedef.
Definition: base.hh:52
RandomRP::RandomReplData
MRU-specific implementation of replacement data.
Definition: random_rp.hh:46
random.hh
RandomRP::instantiateEntry
std::shared_ptr< ReplacementData > instantiateEntry() override
Instantiate a replacement data entry.
Definition: random_rp.cc:88
RandomRP
Definition: random_rp.hh:42
std::vector
STL vector class.
Definition: stl.hh:37
random_mt
Random random_mt
Definition: random.cc:96
RandomRP::reset
void reset(const std::shared_ptr< ReplacementData > &replacement_data) const override
Reset replacement data.
Definition: random_rp.cc:57
BaseReplacementPolicy
A common base class of cache replacement policy objects.
Definition: base.hh:46
random_rp.hh
Copyright (c) 2018 Inria All rights reserved.
RandomRP::getVictim
ReplaceableEntry * getVictim(const ReplacementCandidates &candidates) const override
Find replacement victim at random.
Definition: random_rp.cc:65
RandomRP::touch
void touch(const std::shared_ptr< ReplacementData > &replacement_data) const override
Touch an entry to update its replacement data.
Definition: random_rp.cc:52
RandomRP::RandomRP
RandomRP(const Params *p)
Construct and initiliaze this replacement policy.
Definition: random_rp.cc:37
Random::random
std::enable_if< std::is_integral< T >::value, T >::type random()
Use the SFINAE idiom to choose an implementation based on whether the type is integral or floating po...
Definition: random.hh:86
MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:323
RandomRP::invalidate
void invalidate(const std::shared_ptr< ReplacementData > &replacement_data) const override
Invalidate replacement data to set it as the next probable victim.
Definition: random_rp.cc:43

Generated on Wed Sep 30 2020 14:02:12 for gem5 by doxygen 1.8.17