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

Generated on Fri Feb 28 2020 16:27:02 for gem5 by doxygen 1.8.13