base.hh revision 12600
112600Sodanrc@yahoo.com.br/** 212600Sodanrc@yahoo.com.br * Copyright (c) 2018 Inria 312600Sodanrc@yahoo.com.br * All rights reserved. 412600Sodanrc@yahoo.com.br * 512600Sodanrc@yahoo.com.br * Redistribution and use in source and binary forms, with or without 612600Sodanrc@yahoo.com.br * modification, are permitted provided that the following conditions are 712600Sodanrc@yahoo.com.br * met: redistributions of source code must retain the above copyright 812600Sodanrc@yahoo.com.br * notice, this list of conditions and the following disclaimer; 912600Sodanrc@yahoo.com.br * redistributions in binary form must reproduce the above copyright 1012600Sodanrc@yahoo.com.br * notice, this list of conditions and the following disclaimer in the 1112600Sodanrc@yahoo.com.br * documentation and/or other materials provided with the distribution; 1212600Sodanrc@yahoo.com.br * neither the name of the copyright holders nor the names of its 1312600Sodanrc@yahoo.com.br * contributors may be used to endorse or promote products derived from 1412600Sodanrc@yahoo.com.br * this software without specific prior written permission. 1512600Sodanrc@yahoo.com.br * 1612600Sodanrc@yahoo.com.br * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1712600Sodanrc@yahoo.com.br * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1812600Sodanrc@yahoo.com.br * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1912600Sodanrc@yahoo.com.br * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2012600Sodanrc@yahoo.com.br * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2112600Sodanrc@yahoo.com.br * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2212600Sodanrc@yahoo.com.br * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2312600Sodanrc@yahoo.com.br * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2412600Sodanrc@yahoo.com.br * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2512600Sodanrc@yahoo.com.br * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2612600Sodanrc@yahoo.com.br * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2712600Sodanrc@yahoo.com.br * 2812600Sodanrc@yahoo.com.br * Authors: Daniel Carvalho 2912600Sodanrc@yahoo.com.br */ 3012600Sodanrc@yahoo.com.br 3112600Sodanrc@yahoo.com.br#ifndef __MEM_CACHE_REPLACEMENT_POLICIES_BASE_HH__ 3212600Sodanrc@yahoo.com.br#define __MEM_CACHE_REPLACEMENT_POLICIES_BASE_HH__ 3312600Sodanrc@yahoo.com.br 3412600Sodanrc@yahoo.com.br#include "mem/cache/base.hh" 3512600Sodanrc@yahoo.com.br#include "mem/cache/blk.hh" 3612600Sodanrc@yahoo.com.br#include "params/BaseReplacementPolicy.hh" 3712600Sodanrc@yahoo.com.br#include "sim/sim_object.hh" 3812600Sodanrc@yahoo.com.br 3912600Sodanrc@yahoo.com.br/** 4012600Sodanrc@yahoo.com.br * Replacement candidates as chosen by the indexing policy. 4112600Sodanrc@yahoo.com.br * 4212600Sodanrc@yahoo.com.br * The base functions touch() and reset() must be called by all subclasses 4312600Sodanrc@yahoo.com.br * that override them. 4412600Sodanrc@yahoo.com.br * 4512600Sodanrc@yahoo.com.br * @todo 4612600Sodanrc@yahoo.com.br * Currently the replacement candidates are simply the cache blocks 4712600Sodanrc@yahoo.com.br * derived from the possible placement locations of an address, as 4812600Sodanrc@yahoo.com.br * defined by the getPossibleLocations() from BaseTags. In a future 4912600Sodanrc@yahoo.com.br * patch it should be an inheritable class to allow the replacement 5012600Sodanrc@yahoo.com.br * policies to be used with any table-like structure that needs to 5112600Sodanrc@yahoo.com.br * replace its entries. 5212600Sodanrc@yahoo.com.br */ 5312600Sodanrc@yahoo.com.brtypedef std::vector<CacheBlk*> ReplacementCandidates; 5412600Sodanrc@yahoo.com.br 5512600Sodanrc@yahoo.com.br/** 5612600Sodanrc@yahoo.com.br * A common base class of cache replacement policy objects. 5712600Sodanrc@yahoo.com.br */ 5812600Sodanrc@yahoo.com.brclass BaseReplacementPolicy : public SimObject 5912600Sodanrc@yahoo.com.br{ 6012600Sodanrc@yahoo.com.br public: 6112600Sodanrc@yahoo.com.br /** 6212600Sodanrc@yahoo.com.br * Convenience typedef. 6312600Sodanrc@yahoo.com.br */ 6412600Sodanrc@yahoo.com.br typedef BaseReplacementPolicyParams Params; 6512600Sodanrc@yahoo.com.br 6612600Sodanrc@yahoo.com.br /** 6712600Sodanrc@yahoo.com.br * Construct and initiliaze this replacement policy. 6812600Sodanrc@yahoo.com.br */ 6912600Sodanrc@yahoo.com.br BaseReplacementPolicy(const Params *p); 7012600Sodanrc@yahoo.com.br 7112600Sodanrc@yahoo.com.br /** 7212600Sodanrc@yahoo.com.br * Destructor. 7312600Sodanrc@yahoo.com.br */ 7412600Sodanrc@yahoo.com.br virtual ~BaseReplacementPolicy() {} 7512600Sodanrc@yahoo.com.br 7612600Sodanrc@yahoo.com.br /** 7712600Sodanrc@yahoo.com.br * Touch a block to update its replacement data. 7812600Sodanrc@yahoo.com.br * Updates number of references. 7912600Sodanrc@yahoo.com.br * 8012600Sodanrc@yahoo.com.br * This base function must be called by all subclasses that override it. 8112600Sodanrc@yahoo.com.br * 8212600Sodanrc@yahoo.com.br * @param blk Cache block to be touched. 8312600Sodanrc@yahoo.com.br */ 8412600Sodanrc@yahoo.com.br virtual void touch(CacheBlk *blk); 8512600Sodanrc@yahoo.com.br 8612600Sodanrc@yahoo.com.br /** 8712600Sodanrc@yahoo.com.br * Reset replacement data for a block. Used when a block is inserted. 8812600Sodanrc@yahoo.com.br * Sets the insertion tick, and update number of references. 8912600Sodanrc@yahoo.com.br * 9012600Sodanrc@yahoo.com.br * This base function must be called by all subclasses that override it. 9112600Sodanrc@yahoo.com.br * 9212600Sodanrc@yahoo.com.br * @param blk Cache block to be reset. 9312600Sodanrc@yahoo.com.br */ 9412600Sodanrc@yahoo.com.br virtual void reset(CacheBlk *blk); 9512600Sodanrc@yahoo.com.br 9612600Sodanrc@yahoo.com.br /** 9712600Sodanrc@yahoo.com.br * Find replacement victim among candidates. 9812600Sodanrc@yahoo.com.br * 9912600Sodanrc@yahoo.com.br * @param candidates Replacement candidates, selected by indexing policy. 10012600Sodanrc@yahoo.com.br * @return Cache block to be replaced. 10112600Sodanrc@yahoo.com.br */ 10212600Sodanrc@yahoo.com.br virtual CacheBlk* getVictim(const ReplacementCandidates& candidates) = 0; 10312600Sodanrc@yahoo.com.br}; 10412600Sodanrc@yahoo.com.br 10512600Sodanrc@yahoo.com.br#endif // __MEM_CACHE_REPLACEMENT_POLICIES_BASE_HH__ 106