AbstractReplacementPolicy.hh revision 7039
113071Sgabeblack@google.com/* 213071Sgabeblack@google.com * Copyright (c) 2007 Mark D. Hill and David A. Wood 313071Sgabeblack@google.com * All rights reserved. 413071Sgabeblack@google.com * 513071Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without 613071Sgabeblack@google.com * modification, are permitted provided that the following conditions are 713071Sgabeblack@google.com * met: redistributions of source code must retain the above copyright 813071Sgabeblack@google.com * notice, this list of conditions and the following disclaimer; 913071Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright 1013071Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the 1113071Sgabeblack@google.com * documentation and/or other materials provided with the distribution; 1213071Sgabeblack@google.com * neither the name of the copyright holders nor the names of its 1313071Sgabeblack@google.com * contributors may be used to endorse or promote products derived from 1413071Sgabeblack@google.com * this software without specific prior written permission. 1513071Sgabeblack@google.com * 1613071Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1713071Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1813071Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1913071Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2013071Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2113071Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2213071Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2313071Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2413071Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2513071Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2613071Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2713071Sgabeblack@google.com */ 2813071Sgabeblack@google.com 2913071Sgabeblack@google.com#ifndef __MEM_RUBY_SYSTEM_ABSTRACTREPLACEMENTPOLICY_HH__ 3013071Sgabeblack@google.com#define __MEM_RUBY_SYSTEM_ABSTRACTREPLACEMENTPOLICY_HH__ 3113071Sgabeblack@google.com 3213071Sgabeblack@google.com#include "mem/ruby/common/Global.hh" 3313071Sgabeblack@google.com 3413071Sgabeblack@google.comclass AbstractReplacementPolicy 3513071Sgabeblack@google.com{ 3613071Sgabeblack@google.com public: 3713071Sgabeblack@google.com AbstractReplacementPolicy(Index num_sets, Index assoc); 3813071Sgabeblack@google.com virtual ~AbstractReplacementPolicy(); 3913286Sgabeblack@google.com 4013071Sgabeblack@google.com /* touch a block. a.k.a. update timestamp */ 4113071Sgabeblack@google.com virtual void touch(Index set, Index way, Time time) = 0; 4213071Sgabeblack@google.com 4313071Sgabeblack@google.com /* returns the way to replace */ 4413286Sgabeblack@google.com virtual Index getVictim(Index set) const = 0; 4513071Sgabeblack@google.com 4613071Sgabeblack@google.com /* get the time of the last access */ 4713071Sgabeblack@google.com Time getLastAccess(Index set, Index way); 4813071Sgabeblack@google.com 4913071Sgabeblack@google.com protected: 5013071Sgabeblack@google.com unsigned m_num_sets; /** total number of sets */ 5113071Sgabeblack@google.com unsigned m_assoc; /** set associativity */ 5213071Sgabeblack@google.com Time **m_last_ref_ptr; /** timestamp of last reference */ 53}; 54 55inline 56AbstractReplacementPolicy::AbstractReplacementPolicy(Index num_sets, 57 Index assoc) 58{ 59 m_num_sets = num_sets; 60 m_assoc = assoc; 61 m_last_ref_ptr = new Time*[m_num_sets]; 62 for(unsigned i = 0; i < m_num_sets; i++){ 63 m_last_ref_ptr[i] = new Time[m_assoc]; 64 for(unsigned j = 0; j < m_assoc; j++){ 65 m_last_ref_ptr[i][j] = 0; 66 } 67 } 68} 69 70inline 71AbstractReplacementPolicy::~AbstractReplacementPolicy() 72{ 73 if (m_last_ref_ptr != NULL){ 74 for (unsigned i = 0; i < m_num_sets; i++){ 75 if (m_last_ref_ptr[i] != NULL){ 76 delete[] m_last_ref_ptr[i]; 77 } 78 } 79 delete[] m_last_ref_ptr; 80 } 81} 82 83inline Time 84AbstractReplacementPolicy::getLastAccess(Index set, Index way) 85{ 86 return m_last_ref_ptr[set][way]; 87} 88 89#endif // __MEM_RUBY_SYSTEM_ABSTRACTREPLACEMENTPOLICY_HH__ 90