brrip_rp.hh revision 12684
112626Sodanrc@yahoo.com.br/** 212626Sodanrc@yahoo.com.br * Copyright (c) 2018 Inria 312626Sodanrc@yahoo.com.br * All rights reserved. 412626Sodanrc@yahoo.com.br * 512626Sodanrc@yahoo.com.br * Redistribution and use in source and binary forms, with or without 612626Sodanrc@yahoo.com.br * modification, are permitted provided that the following conditions are 712626Sodanrc@yahoo.com.br * met: redistributions of source code must retain the above copyright 812626Sodanrc@yahoo.com.br * notice, this list of conditions and the following disclaimer; 912626Sodanrc@yahoo.com.br * redistributions in binary form must reproduce the above copyright 1012626Sodanrc@yahoo.com.br * notice, this list of conditions and the following disclaimer in the 1112626Sodanrc@yahoo.com.br * documentation and/or other materials provided with the distribution; 1212626Sodanrc@yahoo.com.br * neither the name of the copyright holders nor the names of its 1312626Sodanrc@yahoo.com.br * contributors may be used to endorse or promote products derived from 1412626Sodanrc@yahoo.com.br * this software without specific prior written permission. 1512626Sodanrc@yahoo.com.br * 1612626Sodanrc@yahoo.com.br * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1712626Sodanrc@yahoo.com.br * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1812626Sodanrc@yahoo.com.br * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1912626Sodanrc@yahoo.com.br * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2012626Sodanrc@yahoo.com.br * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2112626Sodanrc@yahoo.com.br * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2212626Sodanrc@yahoo.com.br * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2312626Sodanrc@yahoo.com.br * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2412626Sodanrc@yahoo.com.br * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2512626Sodanrc@yahoo.com.br * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2612626Sodanrc@yahoo.com.br * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2712626Sodanrc@yahoo.com.br * 2812626Sodanrc@yahoo.com.br * Authors: Daniel Carvalho 2912626Sodanrc@yahoo.com.br */ 3012626Sodanrc@yahoo.com.br 3112626Sodanrc@yahoo.com.br/** 3212626Sodanrc@yahoo.com.br * @file 3312626Sodanrc@yahoo.com.br * Declaration of a Re-Reference Interval Prediction replacement policy. 3412626Sodanrc@yahoo.com.br * 3512626Sodanrc@yahoo.com.br * Not-Recently Used (NRU) is an approximation of LRU that uses a single bit 3612684Sodanrc@yahoo.com.br * to determine if an entry is going to be re-referenced in the near or distant 3712626Sodanrc@yahoo.com.br * future. 3812626Sodanrc@yahoo.com.br * 3912626Sodanrc@yahoo.com.br * Re-Reference Interval Prediction (RRIP) is an extension of NRU that uses a 4012684Sodanrc@yahoo.com.br * re-reference prediction value to determine if entries are going to be re- 4112626Sodanrc@yahoo.com.br * used in the near future or not. 4212626Sodanrc@yahoo.com.br * 4312684Sodanrc@yahoo.com.br * The higher the value of the RRPV, the more distant the entry is from its 4412684Sodanrc@yahoo.com.br * next access. 4512626Sodanrc@yahoo.com.br * 4612626Sodanrc@yahoo.com.br * Bimodal Re-Reference Interval Prediction (BRRIP) is an extension of RRIP 4712684Sodanrc@yahoo.com.br * that has a probability of not inserting entries as the LRU. This probability 4812626Sodanrc@yahoo.com.br * is controlled by the bimodal throtle parameter (btp). 4912626Sodanrc@yahoo.com.br * 5012626Sodanrc@yahoo.com.br * From the original paper, this implementation of RRIP is also called 5112684Sodanrc@yahoo.com.br * Static RRIP (SRRIP), as it always inserts entries with the same RRPV. 5212626Sodanrc@yahoo.com.br */ 5312626Sodanrc@yahoo.com.br 5412626Sodanrc@yahoo.com.br#ifndef __MEM_CACHE_REPLACEMENT_POLICIES_BRRIP_RP_HH__ 5512626Sodanrc@yahoo.com.br#define __MEM_CACHE_REPLACEMENT_POLICIES_BRRIP_RP_HH__ 5612626Sodanrc@yahoo.com.br 5712626Sodanrc@yahoo.com.br#include "mem/cache/replacement_policies/base.hh" 5812626Sodanrc@yahoo.com.br#include "params/BRRIPRP.hh" 5912626Sodanrc@yahoo.com.br 6012626Sodanrc@yahoo.com.brclass BRRIPRP : public BaseReplacementPolicy 6112626Sodanrc@yahoo.com.br{ 6212626Sodanrc@yahoo.com.br protected: 6312684Sodanrc@yahoo.com.br /** BRRIP-specific implementation of replacement data. */ 6412684Sodanrc@yahoo.com.br struct BRRIPReplData : ReplacementData 6512684Sodanrc@yahoo.com.br { 6612684Sodanrc@yahoo.com.br /** 6712684Sodanrc@yahoo.com.br * Re-Reference Interval Prediction Value. 6812684Sodanrc@yahoo.com.br * A value equal to max_RRPV + 1 indicates an invalid entry. 6912684Sodanrc@yahoo.com.br */ 7012684Sodanrc@yahoo.com.br int rrpv; 7112684Sodanrc@yahoo.com.br 7212684Sodanrc@yahoo.com.br /** 7312684Sodanrc@yahoo.com.br * Default constructor. Invalidate data. 7412684Sodanrc@yahoo.com.br */ 7512684Sodanrc@yahoo.com.br BRRIPReplData(const int max_RRPV) : rrpv(max_RRPV + 1) {} 7612684Sodanrc@yahoo.com.br }; 7712684Sodanrc@yahoo.com.br 7812626Sodanrc@yahoo.com.br /** 7912684Sodanrc@yahoo.com.br * Maximum Re-Reference Prediction Value possible. An entry with this 8012626Sodanrc@yahoo.com.br * value as the rrpv has the longest possible re-reference interval, 8112626Sodanrc@yahoo.com.br * that is, it is likely not to be used in the near future, and is 8212626Sodanrc@yahoo.com.br * among the best eviction candidates. 8312626Sodanrc@yahoo.com.br * A maxRRPV of 1 implies in a NRU. 8412626Sodanrc@yahoo.com.br */ 8512684Sodanrc@yahoo.com.br const int maxRRPV; 8612626Sodanrc@yahoo.com.br 8712626Sodanrc@yahoo.com.br /** 8812684Sodanrc@yahoo.com.br * The hit priority (HP) policy replaces entries that do not receive cache 8912684Sodanrc@yahoo.com.br * hits over any cache entry that receives a hit, while the frequency 9012684Sodanrc@yahoo.com.br * priority (FP) policy replaces infrequently re-referenced entries. 9112626Sodanrc@yahoo.com.br */ 9212626Sodanrc@yahoo.com.br const bool hitPriority; 9312626Sodanrc@yahoo.com.br 9412626Sodanrc@yahoo.com.br /** 9512626Sodanrc@yahoo.com.br * Bimodal throtle parameter. Value in the range [0,100] used to decide 9612684Sodanrc@yahoo.com.br * if a new entry is inserted with long or distant re-reference. 9712626Sodanrc@yahoo.com.br */ 9812626Sodanrc@yahoo.com.br const unsigned btp; 9912626Sodanrc@yahoo.com.br 10012626Sodanrc@yahoo.com.br public: 10112626Sodanrc@yahoo.com.br /** Convenience typedef. */ 10212626Sodanrc@yahoo.com.br typedef BRRIPRPParams Params; 10312626Sodanrc@yahoo.com.br 10412626Sodanrc@yahoo.com.br /** 10512626Sodanrc@yahoo.com.br * Construct and initiliaze this replacement policy. 10612626Sodanrc@yahoo.com.br */ 10712626Sodanrc@yahoo.com.br BRRIPRP(const Params *p); 10812626Sodanrc@yahoo.com.br 10912626Sodanrc@yahoo.com.br /** 11012626Sodanrc@yahoo.com.br * Destructor. 11112626Sodanrc@yahoo.com.br */ 11212626Sodanrc@yahoo.com.br ~BRRIPRP() {} 11312626Sodanrc@yahoo.com.br 11412626Sodanrc@yahoo.com.br /** 11512684Sodanrc@yahoo.com.br * Invalidate replacement data to set it as the next probable victim. 11612684Sodanrc@yahoo.com.br * Set RRPV as the the most distant re-reference. 11712626Sodanrc@yahoo.com.br * 11812684Sodanrc@yahoo.com.br * @param replacement_data Replacement data to be invalidated. 11912626Sodanrc@yahoo.com.br */ 12012684Sodanrc@yahoo.com.br void invalidate(const std::shared_ptr<ReplacementData>& replacement_data) 12112684Sodanrc@yahoo.com.br const override; 12212626Sodanrc@yahoo.com.br 12312626Sodanrc@yahoo.com.br /** 12412684Sodanrc@yahoo.com.br * Touch an entry to update its replacement data. 12512684Sodanrc@yahoo.com.br * 12612684Sodanrc@yahoo.com.br * @param replacement_data Replacement data to be touched. 12712684Sodanrc@yahoo.com.br */ 12812684Sodanrc@yahoo.com.br void touch(const std::shared_ptr<ReplacementData>& replacement_data) const 12912684Sodanrc@yahoo.com.br override; 13012684Sodanrc@yahoo.com.br 13112684Sodanrc@yahoo.com.br /** 13212684Sodanrc@yahoo.com.br * Reset replacement data. Used when an entry is inserted. 13312626Sodanrc@yahoo.com.br * Set RRPV according to the insertion policy used. 13412626Sodanrc@yahoo.com.br * 13512684Sodanrc@yahoo.com.br * @param replacement_data Replacement data to be reset. 13612626Sodanrc@yahoo.com.br */ 13712684Sodanrc@yahoo.com.br void reset(const std::shared_ptr<ReplacementData>& replacement_data) const 13812684Sodanrc@yahoo.com.br override; 13912626Sodanrc@yahoo.com.br 14012626Sodanrc@yahoo.com.br /** 14112626Sodanrc@yahoo.com.br * Find replacement victim using rrpv. 14212626Sodanrc@yahoo.com.br * 14312626Sodanrc@yahoo.com.br * @param cands Replacement candidates, selected by indexing policy. 14412684Sodanrc@yahoo.com.br * @return Replacement entry to be replaced. 14512626Sodanrc@yahoo.com.br */ 14612684Sodanrc@yahoo.com.br ReplaceableEntry* getVictim(const ReplacementCandidates& candidates) const 14712684Sodanrc@yahoo.com.br override; 14812684Sodanrc@yahoo.com.br 14912684Sodanrc@yahoo.com.br /** 15012684Sodanrc@yahoo.com.br * Instantiate a replacement data entry. 15112684Sodanrc@yahoo.com.br * 15212684Sodanrc@yahoo.com.br * @return A shared pointer to the new replacement data. 15312684Sodanrc@yahoo.com.br */ 15412684Sodanrc@yahoo.com.br std::shared_ptr<ReplacementData> instantiateEntry() override; 15512626Sodanrc@yahoo.com.br}; 15612626Sodanrc@yahoo.com.br 15712626Sodanrc@yahoo.com.br#endif // __MEM_CACHE_REPLACEMENT_POLICIES_BRRIP_RP_HH__ 158