gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
WeightedLRUPolicy.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 contributors
18  * may be used to endorse or promote products derived from this software
19  * 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  * Author: Derek Hower
34  */
35 
37 
39  : AbstractReplacementPolicy(p), m_cache(p->cache)
40 {
41  m_last_occ_ptr = new int*[m_num_sets];
42  for (unsigned i = 0; i < m_num_sets; i++){
43  m_last_occ_ptr[i] = new int[m_assoc];
44  for (unsigned j = 0; j < m_assoc; j++){
45  m_last_occ_ptr[i][j] = 0;
46  }
47  }
48 }
49 
51 WeightedLRUReplacementPolicyParams::create()
52 {
53  return new WeightedLRUPolicy(this);
54 }
55 
57 {
58  if (m_last_occ_ptr != NULL){
59  for (unsigned i = 0; i < m_num_sets; i++){
60  if (m_last_occ_ptr[i] != NULL){
61  delete[] m_last_occ_ptr[i];
62  }
63  }
64  delete[] m_last_occ_ptr;
65  }
66 }
67 
68 void
69 WeightedLRUPolicy::touch(int64_t set, int64_t index, Tick time)
70 {
71  assert(index >= 0 && index < m_assoc);
72  assert(set >= 0 && set < m_num_sets);
73 
74  m_last_ref_ptr[set][index] = time;
75 }
76 
77 void
78 WeightedLRUPolicy::touch(int64_t set, int64_t index, Tick time, int occupancy)
79 {
80  assert(index >= 0 && index < m_assoc);
81  assert(set >= 0 && set < m_num_sets);
82 
83  m_last_ref_ptr[set][index] = time;
84  m_last_occ_ptr[set][index] = occupancy;
85 }
86 
87 int64_t
88 WeightedLRUPolicy::getVictim(int64_t set) const
89 {
90  Tick time, smallest_time;
91  int64_t smallest_index;
92 
93  smallest_index = 0;
94  smallest_time = m_last_ref_ptr[set][0];
95  int smallest_weight = m_last_ref_ptr[set][0];
96 
97  for (unsigned i = 1; i < m_assoc; i++) {
98 
99  int weight = m_last_occ_ptr[set][i];
100  if (weight < smallest_weight) {
101  smallest_weight = weight;
102  smallest_index = i;
103  smallest_time = m_last_ref_ptr[set][i];
104  } else if (weight == smallest_weight) {
105  time = m_last_ref_ptr[set][i];
106  if (time < smallest_time) {
107  smallest_index = i;
108  smallest_time = time;
109  }
110  }
111  }
112  return smallest_index;
113 }
unsigned m_assoc
total number of sets
Bitfield< 30, 0 > index
Bitfield< 7 > i
Definition: miscregs.hh:1378
Tick ** m_last_ref_ptr
set associativity
void touch(int64_t set, int64_t way, Tick time) override
int64_t getVictim(int64_t set) const override
WeightedLRUPolicy(const Params *p)
uint64_t Tick
Tick count type.
Definition: types.hh:63
Bitfield< 24 > j
Definition: miscregs.hh:1369
Bitfield< 0 > p

Generated on Fri Jun 9 2017 13:03:50 for gem5 by doxygen 1.8.6