lfu_rp.hh revision 12684
112628Sodanrc@yahoo.com.br/** 212628Sodanrc@yahoo.com.br * Copyright (c) 2018 Inria 312628Sodanrc@yahoo.com.br * All rights reserved. 412628Sodanrc@yahoo.com.br * 512628Sodanrc@yahoo.com.br * Redistribution and use in source and binary forms, with or without 612628Sodanrc@yahoo.com.br * modification, are permitted provided that the following conditions are 712628Sodanrc@yahoo.com.br * met: redistributions of source code must retain the above copyright 812628Sodanrc@yahoo.com.br * notice, this list of conditions and the following disclaimer; 912628Sodanrc@yahoo.com.br * redistributions in binary form must reproduce the above copyright 1012628Sodanrc@yahoo.com.br * notice, this list of conditions and the following disclaimer in the 1112628Sodanrc@yahoo.com.br * documentation and/or other materials provided with the distribution; 1212628Sodanrc@yahoo.com.br * neither the name of the copyright holders nor the names of its 1312628Sodanrc@yahoo.com.br * contributors may be used to endorse or promote products derived from 1412628Sodanrc@yahoo.com.br * this software without specific prior written permission. 1512628Sodanrc@yahoo.com.br * 1612628Sodanrc@yahoo.com.br * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1712628Sodanrc@yahoo.com.br * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1812628Sodanrc@yahoo.com.br * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1912628Sodanrc@yahoo.com.br * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2012628Sodanrc@yahoo.com.br * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2112628Sodanrc@yahoo.com.br * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2212628Sodanrc@yahoo.com.br * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2312628Sodanrc@yahoo.com.br * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2412628Sodanrc@yahoo.com.br * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2512628Sodanrc@yahoo.com.br * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2612628Sodanrc@yahoo.com.br * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2712628Sodanrc@yahoo.com.br * 2812628Sodanrc@yahoo.com.br * Authors: Daniel Carvalho 2912628Sodanrc@yahoo.com.br */ 3012628Sodanrc@yahoo.com.br 3112628Sodanrc@yahoo.com.br/** 3212628Sodanrc@yahoo.com.br * @file 3312628Sodanrc@yahoo.com.br * Declaration of a Least Frequently Used replacement policy. 3412628Sodanrc@yahoo.com.br * The victim is chosen using the reference frequency. The least referenced 3512684Sodanrc@yahoo.com.br * entry is always chosen to be evicted, regardless of the amount of times 3612628Sodanrc@yahoo.com.br * it has been touched, or how long has passed since its last touch. 3712628Sodanrc@yahoo.com.br */ 3812628Sodanrc@yahoo.com.br 3912628Sodanrc@yahoo.com.br#ifndef __MEM_CACHE_REPLACEMENT_POLICIES_LFU_RP_HH__ 4012628Sodanrc@yahoo.com.br#define __MEM_CACHE_REPLACEMENT_POLICIES_LFU_RP_HH__ 4112628Sodanrc@yahoo.com.br 4212628Sodanrc@yahoo.com.br#include "mem/cache/replacement_policies/base.hh" 4312628Sodanrc@yahoo.com.br#include "params/LFURP.hh" 4412628Sodanrc@yahoo.com.br 4512628Sodanrc@yahoo.com.brclass LFURP : public BaseReplacementPolicy 4612628Sodanrc@yahoo.com.br{ 4712684Sodanrc@yahoo.com.br protected: 4812684Sodanrc@yahoo.com.br /** LFU-specific implementation of replacement data. */ 4912684Sodanrc@yahoo.com.br struct LFUReplData : ReplacementData 5012684Sodanrc@yahoo.com.br { 5112684Sodanrc@yahoo.com.br /** Number of references to this entry since it was reset. */ 5212684Sodanrc@yahoo.com.br unsigned refCount; 5312684Sodanrc@yahoo.com.br 5412684Sodanrc@yahoo.com.br /** 5512684Sodanrc@yahoo.com.br * Default constructor. Invalidate data. 5612684Sodanrc@yahoo.com.br */ 5712684Sodanrc@yahoo.com.br LFUReplData() : refCount(0) {} 5812684Sodanrc@yahoo.com.br }; 5912684Sodanrc@yahoo.com.br 6012628Sodanrc@yahoo.com.br public: 6112628Sodanrc@yahoo.com.br /** Convenience typedef. */ 6212628Sodanrc@yahoo.com.br typedef LFURPParams Params; 6312628Sodanrc@yahoo.com.br 6412628Sodanrc@yahoo.com.br /** 6512628Sodanrc@yahoo.com.br * Construct and initiliaze this replacement policy. 6612628Sodanrc@yahoo.com.br */ 6712628Sodanrc@yahoo.com.br LFURP(const Params *p); 6812628Sodanrc@yahoo.com.br 6912628Sodanrc@yahoo.com.br /** 7012628Sodanrc@yahoo.com.br * Destructor. 7112628Sodanrc@yahoo.com.br */ 7212628Sodanrc@yahoo.com.br ~LFURP() {} 7312628Sodanrc@yahoo.com.br 7412628Sodanrc@yahoo.com.br /** 7512684Sodanrc@yahoo.com.br * Invalidate replacement data to set it as the next probable victim. 7612684Sodanrc@yahoo.com.br * Clear the number of references. 7712684Sodanrc@yahoo.com.br * 7812684Sodanrc@yahoo.com.br * @param replacement_data Replacement data to be invalidated. 7912684Sodanrc@yahoo.com.br */ 8012684Sodanrc@yahoo.com.br void invalidate(const std::shared_ptr<ReplacementData>& replacement_data) 8112684Sodanrc@yahoo.com.br const override; 8212684Sodanrc@yahoo.com.br 8312684Sodanrc@yahoo.com.br /** 8412684Sodanrc@yahoo.com.br * Touch an entry to update its replacement data. 8512684Sodanrc@yahoo.com.br * Increase number of references. 8612684Sodanrc@yahoo.com.br * 8712684Sodanrc@yahoo.com.br * @param replacement_data Replacement data to be touched. 8812684Sodanrc@yahoo.com.br */ 8912684Sodanrc@yahoo.com.br void touch(const std::shared_ptr<ReplacementData>& replacement_data) const 9012684Sodanrc@yahoo.com.br override; 9112684Sodanrc@yahoo.com.br 9212684Sodanrc@yahoo.com.br /** 9312684Sodanrc@yahoo.com.br * Reset replacement data. Used when an entry is inserted. 9412684Sodanrc@yahoo.com.br * Reset number of references. 9512684Sodanrc@yahoo.com.br * 9612684Sodanrc@yahoo.com.br * @param replacement_data Replacement data to be reset. 9712684Sodanrc@yahoo.com.br */ 9812684Sodanrc@yahoo.com.br void reset(const std::shared_ptr<ReplacementData>& replacement_data) const 9912684Sodanrc@yahoo.com.br override; 10012684Sodanrc@yahoo.com.br 10112684Sodanrc@yahoo.com.br /** 10212628Sodanrc@yahoo.com.br * Find replacement victim using reference frequency. 10312628Sodanrc@yahoo.com.br * 10412628Sodanrc@yahoo.com.br * @param cands Replacement candidates, selected by indexing policy. 10512684Sodanrc@yahoo.com.br * @return Replacement entry to be replaced. 10612628Sodanrc@yahoo.com.br */ 10712684Sodanrc@yahoo.com.br ReplaceableEntry* getVictim(const ReplacementCandidates& candidates) const 10812684Sodanrc@yahoo.com.br override; 10912684Sodanrc@yahoo.com.br 11012684Sodanrc@yahoo.com.br /** 11112684Sodanrc@yahoo.com.br * Instantiate a replacement data entry. 11212684Sodanrc@yahoo.com.br * 11312684Sodanrc@yahoo.com.br * @return A shared pointer to the new replacement data. 11412684Sodanrc@yahoo.com.br */ 11512684Sodanrc@yahoo.com.br std::shared_ptr<ReplacementData> instantiateEntry() override; 11612628Sodanrc@yahoo.com.br}; 11712628Sodanrc@yahoo.com.br 11812628Sodanrc@yahoo.com.br#endif // __MEM_CACHE_REPLACEMENT_POLICIES_LFU_RP_HH__ 119