gem5  v19.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
weighted_lru_rp.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013-2015 Advanced Micro Devices, Inc.
3  * All rights reserved.
4  *
5  * For use for simulation and test purposes only
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright notice,
11  * this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright notice,
14  * this list of conditions and the following disclaimer in the documentation
15  * and/or other materials provided with the distribution.
16  *
17  * 3. Neither the name of the copyright holder nor the names of its
18  * contributors may be used to endorse or promote products derived from this
19  * software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
25  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31  * POSSIBILITY OF SUCH DAMAGE.
32  *
33  * Authors: Derek Hower
34  */
35 
37 
38 #include <cassert>
39 
40 #include "params/WeightedLRURP.hh"
41 
44 {
45 }
46 
48 WeightedLRURPParams::create()
49 {
50  return new WeightedLRUPolicy(this);
51 }
52 
53 void
54 WeightedLRUPolicy::touch(const std::shared_ptr<ReplacementData>&
55  replacement_data) const
56 {
57  std::static_pointer_cast<WeightedLRUReplData>(replacement_data)->
58  last_touch_tick = curTick();
59 }
60 
61 void
62 WeightedLRUPolicy::touch(const std::shared_ptr<ReplacementData>&
63  replacement_data, int occupancy) const
64 {
65  std::static_pointer_cast<WeightedLRUReplData>(replacement_data)->
66  last_touch_tick = curTick();
67  std::static_pointer_cast<WeightedLRUReplData>(replacement_data)->
68  last_occ_ptr = occupancy;
69 }
70 
73 {
74  assert(candidates.size() > 0);
75 
76  ReplaceableEntry* victim = candidates[0];
77  // Use weight (last_occ_ptr) to find victim.
78  // Evict the block that has the smallest weight.
79  // If two blocks have the same weight, evict the oldest one.
80  for (const auto& candidate : candidates) {
81  // candidate's replacement_data
82  std::shared_ptr<WeightedLRUReplData> candidate_replacement_data =
83  std::static_pointer_cast<WeightedLRUReplData>(
84  candidate->replacementData);
85  // victim's replacement_data
86  std::shared_ptr<WeightedLRUReplData> victim_replacement_data =
87  std::static_pointer_cast<WeightedLRUReplData>(
88  victim->replacementData);
89 
90  if (candidate_replacement_data->last_occ_ptr <
91  victim_replacement_data->last_occ_ptr) {
92  victim = candidate;
93  } else if (candidate_replacement_data->last_occ_ptr ==
94  victim_replacement_data->last_occ_ptr) {
95  // Evict the block with a smaller tick.
96  Tick time = candidate_replacement_data->last_touch_tick;
97  if (time < victim_replacement_data->last_touch_tick) {
98  victim = candidate;
99  }
100  }
101  }
102  return victim;
103 }
104 
105 std::shared_ptr<ReplacementData>
107 {
108  return std::shared_ptr<ReplacementData>(new WeightedLRUReplData);
109 }
110 
111 void
112 WeightedLRUPolicy::reset(const std::shared_ptr<ReplacementData>&
113  replacement_data) const
114 {
115  // Set last touch timestamp
116  std::static_pointer_cast<WeightedLRUReplData>(
117  replacement_data)->last_touch_tick = curTick();
118 }
119 
120 void
121 WeightedLRUPolicy::invalidate(const std::shared_ptr<ReplacementData>&
122  replacement_data) const
123 {
124  // Reset last touch timestamp
125  std::static_pointer_cast<WeightedLRUReplData>(
126  replacement_data)->last_touch_tick = Tick(0);
127 }
BaseReplacementPolicyParams Params
Convenience typedef.
Definition: base.hh:54
void invalidate(const std::shared_ptr< ReplacementData > &replacement_data) const override
Invalidate replacement data to set it as the next probable victim.
void touch(const std::shared_ptr< ReplacementData > &replacement_data) const override
Touch an entry to update its replacement data.
A common base class of cache replacement policy objects.
Definition: base.hh:48
STL vector class.
Definition: stl.hh:40
void reset(const std::shared_ptr< ReplacementData > &replacement_data) const override
Reset replacement data.
Tick curTick()
The current simulated tick.
Definition: core.hh:47
ReplaceableEntry * getVictim(const ReplacementCandidates &candidates) const override
Find replacement victim using weight.
WeightedLRUPolicy(const Params *p)
uint64_t Tick
Tick count type.
Definition: types.hh:63
Tick last_touch_tick
Tick on which the entry was last touched.
Weighted LRU implementation of replacement data.
A replaceable entry is a basic entry in a 2d table-like structure that needs to have replacement func...
std::shared_ptr< ReplacementData > instantiateEntry() override
Instantiate a replacement data entry.
Bitfield< 0 > p

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