brrip_rp.hh revision 12684
17199Sgblack@eecs.umich.edu/** 27199Sgblack@eecs.umich.edu * Copyright (c) 2018 Inria 37199Sgblack@eecs.umich.edu * All rights reserved. 47199Sgblack@eecs.umich.edu * 57199Sgblack@eecs.umich.edu * Redistribution and use in source and binary forms, with or without 67199Sgblack@eecs.umich.edu * modification, are permitted provided that the following conditions are 77199Sgblack@eecs.umich.edu * met: redistributions of source code must retain the above copyright 87199Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer; 97199Sgblack@eecs.umich.edu * redistributions in binary form must reproduce the above copyright 107199Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer in the 117199Sgblack@eecs.umich.edu * documentation and/or other materials provided with the distribution; 127199Sgblack@eecs.umich.edu * neither the name of the copyright holders nor the names of its 137199Sgblack@eecs.umich.edu * contributors may be used to endorse or promote products derived from 147199Sgblack@eecs.umich.edu * this software without specific prior written permission. 157199Sgblack@eecs.umich.edu * 167199Sgblack@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 177199Sgblack@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 187199Sgblack@eecs.umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 197199Sgblack@eecs.umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 207199Sgblack@eecs.umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 217199Sgblack@eecs.umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 227199Sgblack@eecs.umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 237199Sgblack@eecs.umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 247199Sgblack@eecs.umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 257199Sgblack@eecs.umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 267199Sgblack@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 277199Sgblack@eecs.umich.edu * 287199Sgblack@eecs.umich.edu * Authors: Daniel Carvalho 297199Sgblack@eecs.umich.edu */ 307199Sgblack@eecs.umich.edu 317199Sgblack@eecs.umich.edu/** 327199Sgblack@eecs.umich.edu * @file 337199Sgblack@eecs.umich.edu * Declaration of a Re-Reference Interval Prediction replacement policy. 347199Sgblack@eecs.umich.edu * 357199Sgblack@eecs.umich.edu * Not-Recently Used (NRU) is an approximation of LRU that uses a single bit 367199Sgblack@eecs.umich.edu * to determine if an entry is going to be re-referenced in the near or distant 377199Sgblack@eecs.umich.edu * future. 387199Sgblack@eecs.umich.edu * 397199Sgblack@eecs.umich.edu * Re-Reference Interval Prediction (RRIP) is an extension of NRU that uses a 407199Sgblack@eecs.umich.edu * re-reference prediction value to determine if entries are going to be re- 417199Sgblack@eecs.umich.edu * used in the near future or not. 427199Sgblack@eecs.umich.edu * 437199Sgblack@eecs.umich.edu * The higher the value of the RRPV, the more distant the entry is from its 447199Sgblack@eecs.umich.edu * next access. 457199Sgblack@eecs.umich.edu * 467199Sgblack@eecs.umich.edu * Bimodal Re-Reference Interval Prediction (BRRIP) is an extension of RRIP 477199Sgblack@eecs.umich.edu * that has a probability of not inserting entries as the LRU. This probability 487199Sgblack@eecs.umich.edu * is controlled by the bimodal throtle parameter (btp). 497199Sgblack@eecs.umich.edu * 507199Sgblack@eecs.umich.edu * From the original paper, this implementation of RRIP is also called 517199Sgblack@eecs.umich.edu * Static RRIP (SRRIP), as it always inserts entries with the same RRPV. 527199Sgblack@eecs.umich.edu */ 537199Sgblack@eecs.umich.edu 547199Sgblack@eecs.umich.edu#ifndef __MEM_CACHE_REPLACEMENT_POLICIES_BRRIP_RP_HH__ 557199Sgblack@eecs.umich.edu#define __MEM_CACHE_REPLACEMENT_POLICIES_BRRIP_RP_HH__ 567199Sgblack@eecs.umich.edu 577199Sgblack@eecs.umich.edu#include "mem/cache/replacement_policies/base.hh" 587202Sgblack@eecs.umich.edu#include "params/BRRIPRP.hh" 597202Sgblack@eecs.umich.edu 607202Sgblack@eecs.umich.educlass BRRIPRP : public BaseReplacementPolicy 617202Sgblack@eecs.umich.edu{ 627202Sgblack@eecs.umich.edu protected: 637202Sgblack@eecs.umich.edu /** BRRIP-specific implementation of replacement data. */ 647202Sgblack@eecs.umich.edu struct BRRIPReplData : ReplacementData 657202Sgblack@eecs.umich.edu { 667599Sminkyu.jeong@arm.com /** 677783SGiacomo.Gabrielli@arm.com * Re-Reference Interval Prediction Value. 687202Sgblack@eecs.umich.edu * A value equal to max_RRPV + 1 indicates an invalid entry. 697202Sgblack@eecs.umich.edu */ 707202Sgblack@eecs.umich.edu int rrpv; 717202Sgblack@eecs.umich.edu 727202Sgblack@eecs.umich.edu /** 737202Sgblack@eecs.umich.edu * Default constructor. Invalidate data. 747202Sgblack@eecs.umich.edu */ 757599Sminkyu.jeong@arm.com BRRIPReplData(const int max_RRPV) : rrpv(max_RRPV + 1) {} 767783SGiacomo.Gabrielli@arm.com }; 777202Sgblack@eecs.umich.edu 787202Sgblack@eecs.umich.edu /** 797202Sgblack@eecs.umich.edu * Maximum Re-Reference Prediction Value possible. An entry with this 807202Sgblack@eecs.umich.edu * value as the rrpv has the longest possible re-reference interval, 817202Sgblack@eecs.umich.edu * that is, it is likely not to be used in the near future, and is 827400SAli.Saidi@ARM.com * among the best eviction candidates. 837202Sgblack@eecs.umich.edu * A maxRRPV of 1 implies in a NRU. 847400SAli.Saidi@ARM.com */ 857202Sgblack@eecs.umich.edu const int maxRRPV; 867202Sgblack@eecs.umich.edu 877202Sgblack@eecs.umich.edu /** 887202Sgblack@eecs.umich.edu * The hit priority (HP) policy replaces entries that do not receive cache 897202Sgblack@eecs.umich.edu * hits over any cache entry that receives a hit, while the frequency 907599Sminkyu.jeong@arm.com * priority (FP) policy replaces infrequently re-referenced entries. 917599Sminkyu.jeong@arm.com */ 927202Sgblack@eecs.umich.edu const bool hitPriority; 937202Sgblack@eecs.umich.edu 947202Sgblack@eecs.umich.edu /** 957202Sgblack@eecs.umich.edu * Bimodal throtle parameter. Value in the range [0,100] used to decide 967202Sgblack@eecs.umich.edu * if a new entry is inserted with long or distant re-reference. 977202Sgblack@eecs.umich.edu */ 987202Sgblack@eecs.umich.edu const unsigned btp; 997599Sminkyu.jeong@arm.com 1007599Sminkyu.jeong@arm.com public: 1017202Sgblack@eecs.umich.edu /** Convenience typedef. */ 1027202Sgblack@eecs.umich.edu typedef BRRIPRPParams Params; 1037202Sgblack@eecs.umich.edu 1047202Sgblack@eecs.umich.edu /** 1057202Sgblack@eecs.umich.edu * Construct and initiliaze this replacement policy. 1067400SAli.Saidi@ARM.com */ 1077202Sgblack@eecs.umich.edu BRRIPRP(const Params *p); 1087400SAli.Saidi@ARM.com 1097202Sgblack@eecs.umich.edu /** 1107202Sgblack@eecs.umich.edu * Destructor. 1117202Sgblack@eecs.umich.edu */ 1127202Sgblack@eecs.umich.edu ~BRRIPRP() {} 1137202Sgblack@eecs.umich.edu 1147599Sminkyu.jeong@arm.com /** 1157599Sminkyu.jeong@arm.com * Invalidate replacement data to set it as the next probable victim. 1167202Sgblack@eecs.umich.edu * Set RRPV as the the most distant re-reference. 1177202Sgblack@eecs.umich.edu * 1187202Sgblack@eecs.umich.edu * @param replacement_data Replacement data to be invalidated. 1197202Sgblack@eecs.umich.edu */ 1207202Sgblack@eecs.umich.edu void invalidate(const std::shared_ptr<ReplacementData>& replacement_data) 1217202Sgblack@eecs.umich.edu const override; 1227202Sgblack@eecs.umich.edu 1237599Sminkyu.jeong@arm.com /** 1247599Sminkyu.jeong@arm.com * Touch an entry to update its replacement data. 1257202Sgblack@eecs.umich.edu * 1267202Sgblack@eecs.umich.edu * @param replacement_data Replacement data to be touched. 1277202Sgblack@eecs.umich.edu */ 1287209Sgblack@eecs.umich.edu void touch(const std::shared_ptr<ReplacementData>& replacement_data) const 1297209Sgblack@eecs.umich.edu override; 1307209Sgblack@eecs.umich.edu 1317209Sgblack@eecs.umich.edu /** 1327209Sgblack@eecs.umich.edu * Reset replacement data. Used when an entry is inserted. 1337261Sgblack@eecs.umich.edu * Set RRPV according to the insertion policy used. 1347209Sgblack@eecs.umich.edu * 1357209Sgblack@eecs.umich.edu * @param replacement_data Replacement data to be reset. 1367261Sgblack@eecs.umich.edu */ 1377261Sgblack@eecs.umich.edu void reset(const std::shared_ptr<ReplacementData>& replacement_data) const 1387209Sgblack@eecs.umich.edu override; 1397209Sgblack@eecs.umich.edu 1407209Sgblack@eecs.umich.edu /** 1417209Sgblack@eecs.umich.edu * Find replacement victim using rrpv. 1427209Sgblack@eecs.umich.edu * 1437209Sgblack@eecs.umich.edu * @param cands Replacement candidates, selected by indexing policy. 1447209Sgblack@eecs.umich.edu * @return Replacement entry to be replaced. 1457209Sgblack@eecs.umich.edu */ 1467209Sgblack@eecs.umich.edu ReplaceableEntry* getVictim(const ReplacementCandidates& candidates) const 1477261Sgblack@eecs.umich.edu override; 1487209Sgblack@eecs.umich.edu 1497209Sgblack@eecs.umich.edu /** 1507261Sgblack@eecs.umich.edu * Instantiate a replacement data entry. 1517261Sgblack@eecs.umich.edu * 1527209Sgblack@eecs.umich.edu * @return A shared pointer to the new replacement data. 1537209Sgblack@eecs.umich.edu */ 1547209Sgblack@eecs.umich.edu std::shared_ptr<ReplacementData> instantiateEntry() override; 1557209Sgblack@eecs.umich.edu}; 1567209Sgblack@eecs.umich.edu 1577209Sgblack@eecs.umich.edu#endif // __MEM_CACHE_REPLACEMENT_POLICIES_BRRIP_RP_HH__ 1587261Sgblack@eecs.umich.edu