LRUPolicy.hh revision 10314
17008SN/A/* 27008SN/A * Copyright (c) 2007 Mark D. Hill and David A. Wood 37008SN/A * All rights reserved. 47008SN/A * 57008SN/A * Redistribution and use in source and binary forms, with or without 67008SN/A * modification, are permitted provided that the following conditions are 77008SN/A * met: redistributions of source code must retain the above copyright 87008SN/A * notice, this list of conditions and the following disclaimer; 97008SN/A * redistributions in binary form must reproduce the above copyright 107008SN/A * notice, this list of conditions and the following disclaimer in the 117008SN/A * documentation and/or other materials provided with the distribution; 127008SN/A * neither the name of the copyright holders nor the names of its 137008SN/A * contributors may be used to endorse or promote products derived from 147008SN/A * this software without specific prior written permission. 157008SN/A * 167008SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 177008SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 187008SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 197008SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 207008SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 217008SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 227008SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 237008SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 247008SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 257008SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 267008SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 277008SN/A */ 286145SN/A 297039SN/A#ifndef __MEM_RUBY_SYSTEM_LRUPOLICY_HH__ 307039SN/A#define __MEM_RUBY_SYSTEM_LRUPOLICY_HH__ 316145SN/A 3210301Snilay@cs.wisc.edu#include "mem/ruby/structures/AbstractReplacementPolicy.hh" 336145SN/A 346145SN/A/* Simple true LRU replacement policy */ 356145SN/A 367039SN/Aclass LRUPolicy : public AbstractReplacementPolicy 377039SN/A{ 387039SN/A public: 3910314Snilay@cs.wisc.edu LRUPolicy(int64 num_sets, int64 assoc); 407039SN/A ~LRUPolicy(); 416145SN/A 4210314Snilay@cs.wisc.edu void touch(int64 set, int64 way, Tick time); 4310314Snilay@cs.wisc.edu int64 getVictim(int64 set) const; 446145SN/A}; 456145SN/A 466145SN/Ainline 4710314Snilay@cs.wisc.eduLRUPolicy::LRUPolicy(int64 num_sets, int64 assoc) 487039SN/A : AbstractReplacementPolicy(num_sets, assoc) 496145SN/A{ 506145SN/A} 516145SN/A 526145SN/Ainline 536145SN/ALRUPolicy::~LRUPolicy() 546145SN/A{ 556145SN/A} 566145SN/A 577039SN/Ainline void 5810314Snilay@cs.wisc.eduLRUPolicy::touch(int64 set, int64 index, Tick time) 597039SN/A{ 607039SN/A assert(index >= 0 && index < m_assoc); 617039SN/A assert(set >= 0 && set < m_num_sets); 626145SN/A 637039SN/A m_last_ref_ptr[set][index] = time; 646145SN/A} 656145SN/A 6610314Snilay@cs.wisc.eduinline int64 6710314Snilay@cs.wisc.eduLRUPolicy::getVictim(int64 set) const 687039SN/A{ 697039SN/A // assert(m_assoc != 0); 709505SN/A Tick time, smallest_time; 7110314Snilay@cs.wisc.edu int64 smallest_index; 726145SN/A 737039SN/A smallest_index = 0; 747039SN/A smallest_time = m_last_ref_ptr[set][0]; 756145SN/A 767039SN/A for (unsigned i = 0; i < m_assoc; i++) { 777039SN/A time = m_last_ref_ptr[set][i]; 787039SN/A // assert(m_cache[cacheSet][i].m_Permission != 797039SN/A // AccessPermission_NotPresent); 806145SN/A 817039SN/A if (time < smallest_time) { 827039SN/A smallest_index = i; 837039SN/A smallest_time = time; 847039SN/A } 856145SN/A } 866145SN/A 877039SN/A // DEBUG_EXPR(CACHE_COMP, MedPrio, cacheSet); 887039SN/A // DEBUG_EXPR(CACHE_COMP, MedPrio, smallest_index); 897039SN/A // DEBUG_EXPR(CACHE_COMP, MedPrio, m_cache[cacheSet][smallest_index]); 907039SN/A // DEBUG_EXPR(CACHE_COMP, MedPrio, *this); 916145SN/A 927039SN/A return smallest_index; 936145SN/A} 946145SN/A 957039SN/A#endif // __MEM_RUBY_SYSTEM_LRUPOLICY_HH__ 96