gem5 v24.0.0.0
Loading...
Searching...
No Matches
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
37namespace gem5
38{
39
40namespace replacement_policy
41{
42
44 : Base(p)
45{
46}
47
48void
49Random::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
56void
57Random::touch(const std::shared_ptr<ReplacementData>& replacement_data) const
58{
59}
60
61void
62Random::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
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
92std::shared_ptr<ReplacementData>
94{
95 return std::shared_ptr<ReplacementData>(new RandomReplData());
96}
97
98} // namespace replacement_policy
99} // 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:55
std::shared_ptr< ReplacementData > instantiateEntry() override
Instantiate a replacement data entry.
Definition random_rp.cc:93
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
void touch(const std::shared_ptr< ReplacementData > &replacement_data) const override
Touch an entry to update its replacement data.
Definition random_rp.cc:57
void reset(const std::shared_ptr< ReplacementData > &replacement_data) const override
Reset replacement data.
Definition random_rp.cc:62
ReplaceableEntry * getVictim(const ReplacementCandidates &candidates) const override
Find replacement victim at random.
Definition random_rp.cc:70
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< 0 > p
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
Copyright (c) 2018-2020 Inria All rights reserved.
Random-specific implementation of replacement data.
Definition random_rp.hh:53

Generated on Tue Jun 18 2024 16:24:05 for gem5 by doxygen 1.11.0