2 * Copyright (c) 2002-2005 The Regents of The University of Michigan
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 * Authors: Erik Hallnor
33 * Declarations of generational replacement policy
41 #include "base/statistics.hh"
42 #include "mem/cache/tags/iic_repl/repl.hh"
43 #include "params/GenRepl.hh"
46 * Generational Replacement entry.
51 /** Valid flag, used to quickly invalidate bogus entries. */
53 /** The difference between this entry and the previous in the pool. */
55 /** Pointer to the corresponding tag in the IIC. */
56 unsigned long tag_ptr;
60 * Generational replacement pool
65 /** The time the last entry was added. */
67 /** The time the oldest entry was added. */
69 /** List of the replacement entries in this pool. */
70 std::list<GenReplEntry*> entries;
72 /** The number of entries in this pool. */
85 * Add an entry to this pool.
86 * @param re The entry to add.
87 * @param now The current time.
89 void push(GenReplEntry *re, Tick now) {
91 if (!entries.empty()) {
92 re->delta = now - newest;
96 newest = oldest = now;
98 entries.push_back(re);
102 * Remove an entry from the pool.
103 * @return The entry at the front of the list.
105 GenReplEntry* pop() {
106 GenReplEntry *tmp = NULL;
107 if (!entries.empty()) {
109 tmp = entries.front();
111 oldest += tmp->delta;
117 * Return the entry at the front of the list.
118 * @return the entry at the front of the list.
120 GenReplEntry* top() {
121 return entries.front();
128 while (!entries.empty()) {
129 GenReplEntry *tmp = entries.front();
137 * Generational replacement policy for use with the IIC.
138 * @todo update to use STL and for efficiency
140 class GenRepl : public Repl
143 /** The number of pools. */
145 /** The amount of time to stay in the fresh pool. */
147 /** The amount of time to stay in the normal pools. */
149 /** The maximum number of entries */
151 /** The number of entries currently in the pools. */
152 int num_pool_entries;
153 /** The number of misses. Used as the internal time. */
155 /** The array of pools. */
161 * @addtogroup CacheStatistics
164 /** The number of replacements from each pool. */
165 Stats::Distribution repl_pool;
166 /** The number of advances out of each pool. */
167 Stats::Distribution advance_pool;
168 /** The number of demotions from each pool. */
169 Stats::Distribution demote_pool;
174 typedef GenReplParams Params;
175 GenRepl(const Params *p);
183 * Returns the tag pointer of the cache block to replace.
184 * @return The tag to replace.
186 virtual unsigned long getRepl();
189 * Return an array of N tag pointers to replace.
190 * @param n The number of tag pointer to return.
191 * @return An array of tag pointers to replace.
193 virtual unsigned long *getNRepl(int n);
196 * Update replacement data
198 virtual void doAdvance(std::list<unsigned long> &demoted);
201 * Add a tag to the replacement policy and return a pointer to the
203 * @param tag_index The tag to add.
204 * @return The replacement entry.
206 virtual void* add(unsigned long tag_index);
209 * Register statistics.
210 * @param name The name to prepend to statistic descriptions.
212 virtual void regStatsWithSuffix(const std::string name);
215 * Update the tag pointer to when the tag moves.
216 * @param re The replacement entry of the tag.
217 * @param old_index The old tag pointer.
218 * @param new_index The new tag pointer.
219 * @return 1 if successful, 0 otherwise.
221 virtual int fixTag(void *re, unsigned long old_index,
222 unsigned long new_index);
225 * Remove this entry from the replacement policy.
226 * @param re The replacement entry to remove
228 virtual void removeEntry(void *re)
230 ((GenReplEntry*)re)->valid = false;
235 * Debug function to verify that there is only one repl entry per tag.
236 * @param index The tag index to check.
238 bool findTagPtr(unsigned long index);
241 #endif /* __GEN_HH__ */