brrip_rp.hh revision 12626
18981Sandreas.hansson@arm.com/** 210744SGeoffrey.Blake@arm.com * Copyright (c) 2018 Inria 311804Srjthakur@google.com * All rights reserved. 411804Srjthakur@google.com * 58981Sandreas.hansson@arm.com * Redistribution and use in source and binary forms, with or without 68981Sandreas.hansson@arm.com * modification, are permitted provided that the following conditions are 78981Sandreas.hansson@arm.com * met: redistributions of source code must retain the above copyright 88981Sandreas.hansson@arm.com * notice, this list of conditions and the following disclaimer; 98981Sandreas.hansson@arm.com * redistributions in binary form must reproduce the above copyright 108981Sandreas.hansson@arm.com * notice, this list of conditions and the following disclaimer in the 118981Sandreas.hansson@arm.com * documentation and/or other materials provided with the distribution; 128981Sandreas.hansson@arm.com * neither the name of the copyright holders nor the names of its 138981Sandreas.hansson@arm.com * contributors may be used to endorse or promote products derived from 148981Sandreas.hansson@arm.com * this software without specific prior written permission. 158981Sandreas.hansson@arm.com * 168981Sandreas.hansson@arm.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 178981Sandreas.hansson@arm.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 188981Sandreas.hansson@arm.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 198981Sandreas.hansson@arm.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 208981Sandreas.hansson@arm.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 218981Sandreas.hansson@arm.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 228981Sandreas.hansson@arm.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 238981Sandreas.hansson@arm.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 248981Sandreas.hansson@arm.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 258981Sandreas.hansson@arm.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 268981Sandreas.hansson@arm.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 278981Sandreas.hansson@arm.com * 288981Sandreas.hansson@arm.com * Authors: Daniel Carvalho 298981Sandreas.hansson@arm.com */ 308981Sandreas.hansson@arm.com 318981Sandreas.hansson@arm.com/** 328981Sandreas.hansson@arm.com * @file 338981Sandreas.hansson@arm.com * Declaration of a Re-Reference Interval Prediction replacement policy. 348981Sandreas.hansson@arm.com * 358981Sandreas.hansson@arm.com * Not-Recently Used (NRU) is an approximation of LRU that uses a single bit 368981Sandreas.hansson@arm.com * to determine if a block is going to be re-referenced in the near or distant 378981Sandreas.hansson@arm.com * future. 388981Sandreas.hansson@arm.com * 398981Sandreas.hansson@arm.com * Re-Reference Interval Prediction (RRIP) is an extension of NRU that uses a 4011804Srjthakur@google.com * re-reference prediction value to determine if blocks are going to be re- 418981Sandreas.hansson@arm.com * used in the near future or not. 428981Sandreas.hansson@arm.com * 4311793Sbrandon.potter@amd.com * The higher the value of the RRPV, the more distant the block is from 4411793Sbrandon.potter@amd.com * its next access. 459356Snilay@cs.wisc.edu * 468981Sandreas.hansson@arm.com * Bimodal Re-Reference Interval Prediction (BRRIP) is an extension of RRIP 478981Sandreas.hansson@arm.com * that has a probability of not inserting blocks as the LRU. This probability 488981Sandreas.hansson@arm.com * is controlled by the bimodal throtle parameter (btp). 498981Sandreas.hansson@arm.com * 508981Sandreas.hansson@arm.com * From the original paper, this implementation of RRIP is also called 518981Sandreas.hansson@arm.com * Static RRIP (SRRIP), as it always inserts blocks with the same RRPV. 528981Sandreas.hansson@arm.com */ 538981Sandreas.hansson@arm.com 548981Sandreas.hansson@arm.com#ifndef __MEM_CACHE_REPLACEMENT_POLICIES_BRRIP_RP_HH__ 5510902Sandreas.sandberg@arm.com#define __MEM_CACHE_REPLACEMENT_POLICIES_BRRIP_RP_HH__ 5610902Sandreas.sandberg@arm.com 578981Sandreas.hansson@arm.com#include "mem/cache/replacement_policies/base.hh" 588981Sandreas.hansson@arm.com#include "params/BRRIPRP.hh" 5910064Sandreas.hansson@arm.com 6010902Sandreas.sandberg@arm.comclass BRRIPRP : public BaseReplacementPolicy 618981Sandreas.hansson@arm.com{ 628981Sandreas.hansson@arm.com protected: 638981Sandreas.hansson@arm.com /** 648981Sandreas.hansson@arm.com * Maximum Re-Reference Prediction Value possible. A block with this 658981Sandreas.hansson@arm.com * value as the rrpv has the longest possible re-reference interval, 668981Sandreas.hansson@arm.com * that is, it is likely not to be used in the near future, and is 678981Sandreas.hansson@arm.com * among the best eviction candidates. 688981Sandreas.hansson@arm.com * A maxRRPV of 1 implies in a NRU. 698981Sandreas.hansson@arm.com */ 708981Sandreas.hansson@arm.com const unsigned maxRRPV; 718981Sandreas.hansson@arm.com 728981Sandreas.hansson@arm.com /** 738981Sandreas.hansson@arm.com * The hit priority (HP) policy replaces blocks that do not receive cache 748981Sandreas.hansson@arm.com * hits over any cache block that receives a hit, while the frequency 758981Sandreas.hansson@arm.com * priority (FP) policy replaces infrequently re-referenced blocks. 768981Sandreas.hansson@arm.com */ 7710994Sandreas.sandberg@arm.com const bool hitPriority; 7810994Sandreas.sandberg@arm.com 7910994Sandreas.sandberg@arm.com /** 8010994Sandreas.sandberg@arm.com * Bimodal throtle parameter. Value in the range [0,100] used to decide 8110994Sandreas.sandberg@arm.com * if a new block is inserted with long or distant re-reference. 8210994Sandreas.sandberg@arm.com */ 8310994Sandreas.sandberg@arm.com const unsigned btp; 849294Sandreas.hansson@arm.com 859294Sandreas.hansson@arm.com public: 868981Sandreas.hansson@arm.com /** Convenience typedef. */ 878981Sandreas.hansson@arm.com typedef BRRIPRPParams Params; 888981Sandreas.hansson@arm.com 898981Sandreas.hansson@arm.com /** 908981Sandreas.hansson@arm.com * Construct and initiliaze this replacement policy. 918981Sandreas.hansson@arm.com */ 928981Sandreas.hansson@arm.com BRRIPRP(const Params *p); 938981Sandreas.hansson@arm.com 949294Sandreas.hansson@arm.com /** 959294Sandreas.hansson@arm.com * Destructor. 968981Sandreas.hansson@arm.com */ 978981Sandreas.hansson@arm.com ~BRRIPRP() {} 988981Sandreas.hansson@arm.com 998981Sandreas.hansson@arm.com /** 1008981Sandreas.hansson@arm.com * Touch a block to update its replacement data. 1018981Sandreas.hansson@arm.com * 1028981Sandreas.hansson@arm.com * @param blk Cache block to be touched. 1038981Sandreas.hansson@arm.com */ 1048981Sandreas.hansson@arm.com void touch(CacheBlk *blk) override; 1058981Sandreas.hansson@arm.com 1068981Sandreas.hansson@arm.com /** 1078981Sandreas.hansson@arm.com * Reset replacement data for a block. Used when a block is inserted. 1088981Sandreas.hansson@arm.com * Sets the insertion tick, and update correspondent replacement data. 1098981Sandreas.hansson@arm.com * Set RRPV according to the insertion policy used. 1108981Sandreas.hansson@arm.com * 1118981Sandreas.hansson@arm.com * @param blk Cache block to be reset. 1128981Sandreas.hansson@arm.com */ 1138981Sandreas.hansson@arm.com void reset(CacheBlk *blk) override; 1148981Sandreas.hansson@arm.com 1158981Sandreas.hansson@arm.com /** 11611804Srjthakur@google.com * Find replacement victim using rrpv. 11711804Srjthakur@google.com * 11811804Srjthakur@google.com * @param cands Replacement candidates, selected by indexing policy. 11911804Srjthakur@google.com * @return Cache block to be replaced. 12011804Srjthakur@google.com */ 12111804Srjthakur@google.com CacheBlk* getVictim(const ReplacementCandidates& candidates) override; 12211804Srjthakur@google.com}; 12311804Srjthakur@google.com 12411804Srjthakur@google.com#endif // __MEM_CACHE_REPLACEMENT_POLICIES_BRRIP_RP_HH__ 12511804Srjthakur@google.com