AbstractReplacementPolicy.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_ABSTRACTREPLACEMENTPOLICY_HH__
307039SN/A#define __MEM_RUBY_SYSTEM_ABSTRACTREPLACEMENTPOLICY_HH__
316145SN/A
329505SN/A#include "base/types.hh"
336145SN/A
347039SN/Aclass AbstractReplacementPolicy
357039SN/A{
367039SN/A  public:
3710314Snilay@cs.wisc.edu    AbstractReplacementPolicy(int64 num_sets, int64 assoc);
387039SN/A    virtual ~AbstractReplacementPolicy();
396145SN/A
407039SN/A    /* touch a block. a.k.a. update timestamp */
4110314Snilay@cs.wisc.edu    virtual void touch(int64 set, int64 way, Tick time) = 0;
426145SN/A
437039SN/A    /* returns the way to replace */
4410314Snilay@cs.wisc.edu    virtual int64 getVictim(int64 set) const = 0;
456145SN/A
467039SN/A    /* get the time of the last access */
4710314Snilay@cs.wisc.edu    Tick getLastAccess(int64 set, int64 way);
486145SN/A
497039SN/A  protected:
507039SN/A    unsigned m_num_sets;       /** total number of sets */
517039SN/A    unsigned m_assoc;          /** set associativity */
529505SN/A    Tick **m_last_ref_ptr;         /** timestamp of last reference */
536145SN/A};
546145SN/A
556145SN/Ainline
5610314Snilay@cs.wisc.eduAbstractReplacementPolicy::AbstractReplacementPolicy(int64 num_sets,
5710314Snilay@cs.wisc.edu                                                     int64 assoc)
586145SN/A{
597039SN/A    m_num_sets = num_sets;
607039SN/A    m_assoc = assoc;
619505SN/A    m_last_ref_ptr = new Tick*[m_num_sets];
627039SN/A    for(unsigned i = 0; i < m_num_sets; i++){
639505SN/A        m_last_ref_ptr[i] = new Tick[m_assoc];
647039SN/A        for(unsigned j = 0; j < m_assoc; j++){
657039SN/A            m_last_ref_ptr[i][j] = 0;
667039SN/A        }
676145SN/A    }
686145SN/A}
696145SN/A
706145SN/Ainline
716145SN/AAbstractReplacementPolicy::~AbstractReplacementPolicy()
726145SN/A{
737039SN/A    if (m_last_ref_ptr != NULL){
747039SN/A        for (unsigned i = 0; i < m_num_sets; i++){
757039SN/A            if (m_last_ref_ptr[i] != NULL){
767039SN/A                delete[] m_last_ref_ptr[i];
777039SN/A            }
787039SN/A        }
797039SN/A        delete[] m_last_ref_ptr;
806145SN/A    }
816145SN/A}
826145SN/A
839505SN/Ainline Tick
8410314Snilay@cs.wisc.eduAbstractReplacementPolicy::getLastAccess(int64 set, int64 way)
856145SN/A{
867039SN/A    return m_last_ref_ptr[set][way];
876145SN/A}
886145SN/A
897039SN/A#endif // __MEM_RUBY_SYSTEM_ABSTRACTREPLACEMENTPOLICY_HH__
90