brrip_rp.hh revision 12626:e161d7725d4b
172SN/A/**
21762SN/A * Copyright (c) 2018 Inria
372SN/A * All rights reserved.
472SN/A *
572SN/A * Redistribution and use in source and binary forms, with or without
672SN/A * modification, are permitted provided that the following conditions are
772SN/A * met: redistributions of source code must retain the above copyright
872SN/A * notice, this list of conditions and the following disclaimer;
972SN/A * redistributions in binary form must reproduce the above copyright
1072SN/A * notice, this list of conditions and the following disclaimer in the
1172SN/A * documentation and/or other materials provided with the distribution;
1272SN/A * neither the name of the copyright holders nor the names of its
1372SN/A * contributors may be used to endorse or promote products derived from
1472SN/A * this software without specific prior written permission.
1572SN/A *
1672SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1772SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1872SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1972SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2072SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2172SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2272SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2372SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2472SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2572SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2672SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272665Ssaidi@eecs.umich.edu *
282665Ssaidi@eecs.umich.edu * Authors: Daniel Carvalho
2972SN/A */
3072SN/A
312SN/A/**
322SN/A * @file
332SN/A * Declaration of a Re-Reference Interval Prediction replacement policy.
342SN/A *
352SN/A * Not-Recently Used (NRU) is an approximation of LRU that uses a single bit
362SN/A * to determine if a block is going to be re-referenced in the near or distant
372SN/A * future.
382SN/A *
392SN/A * Re-Reference Interval Prediction (RRIP) is an extension of NRU that uses a
402SN/A * re-reference prediction value to determine if blocks are going to be re-
412SN/A * used in the near future or not.
422SN/A *
432SN/A * The higher the value of the RRPV, the more distant the block is from
442SN/A * its next access.
452SN/A *
462SN/A * Bimodal Re-Reference Interval Prediction (BRRIP) is an extension of RRIP
472SN/A * that has a probability of not inserting blocks as the LRU. This probability
482SN/A * is controlled by the bimodal throtle parameter (btp).
492SN/A *
502SN/A * From the original paper, this implementation of RRIP is also called
512SN/A * Static RRIP (SRRIP), as it always inserts blocks with the same RRPV.
522SN/A */
532SN/A
542SN/A#ifndef __MEM_CACHE_REPLACEMENT_POLICIES_BRRIP_RP_HH__
552SN/A#define __MEM_CACHE_REPLACEMENT_POLICIES_BRRIP_RP_HH__
562SN/A
572SN/A#include "mem/cache/replacement_policies/base.hh"
582SN/A#include "params/BRRIPRP.hh"
592SN/A
602SN/Aclass BRRIPRP : public BaseReplacementPolicy
612SN/A{
622SN/A  protected:
632SN/A    /**
642SN/A     * Maximum Re-Reference Prediction Value possible. A block with this
652SN/A     * value as the rrpv has the longest possible re-reference interval,
662SN/A     * that is, it is likely not to be used in the near future, and is
672SN/A     * among the best eviction candidates.
682SN/A     * A maxRRPV of 1 implies in a NRU.
692SN/A     */
702SN/A    const unsigned maxRRPV;
712SN/A
722SN/A    /**
732SN/A     * The hit priority (HP) policy replaces blocks that do not receive cache
742SN/A     * hits over any cache block that receives a hit, while the frequency
752SN/A     * priority (FP) policy replaces infrequently re-referenced blocks.
762SN/A     */
772SN/A    const bool hitPriority;
782SN/A
792SN/A    /**
802SN/A     * Bimodal throtle parameter. Value in the range [0,100] used to decide
812SN/A     * if a new block is inserted with long or distant re-reference.
822SN/A     */
832SN/A    const unsigned btp;
842SN/A
852SN/A  public:
862SN/A    /** Convenience typedef. */
872SN/A    typedef BRRIPRPParams Params;
882SN/A
892SN/A    /**
902SN/A     * Construct and initiliaze this replacement policy.
912SN/A     */
922SN/A    BRRIPRP(const Params *p);
932SN/A
942SN/A    /**
952SN/A     * Destructor.
962SN/A     */
972SN/A    ~BRRIPRP() {}
982SN/A
992SN/A    /**
1002SN/A     * Touch a block to update its replacement data.
1012SN/A     *
1022SN/A     * @param blk Cache block to be touched.
1032SN/A     */
1042SN/A    void touch(CacheBlk *blk) override;
1052SN/A
1062SN/A    /**
1072SN/A     * Reset replacement data for a block. Used when a block is inserted.
1082SN/A     * Sets the insertion tick, and update correspondent replacement data.
1092SN/A     * Set RRPV according to the insertion policy used.
1102SN/A     *
1112SN/A     * @param blk Cache block to be reset.
1122SN/A     */
1132SN/A    void reset(CacheBlk *blk) override;
1142SN/A
1152SN/A    /**
1162SN/A     * Find replacement victim using rrpv.
1172SN/A     *
1182SN/A     * @param cands Replacement candidates, selected by indexing policy.
1192SN/A     * @return Cache block to be replaced.
1202SN/A     */
1211717SN/A    CacheBlk* getVictim(const ReplacementCandidates& candidates) override;
1222SN/A};
1232SN/A
1242521SN/A#endif // __MEM_CACHE_REPLACEMENT_POLICIES_BRRIP_RP_HH__
12556SN/A