brrip_rp.hh revision 13849
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"
5812727Snikos.nikoleris@arm.com
5912727Snikos.nikoleris@arm.comstruct BRRIPRPParams;
6012626Sodanrc@yahoo.com.br
6112626Sodanrc@yahoo.com.brclass BRRIPRP : public BaseReplacementPolicy
6212626Sodanrc@yahoo.com.br{
6312626Sodanrc@yahoo.com.br  protected:
6412684Sodanrc@yahoo.com.br    /** BRRIP-specific implementation of replacement data. */
6512684Sodanrc@yahoo.com.br    struct BRRIPReplData : ReplacementData
6612684Sodanrc@yahoo.com.br    {
6712684Sodanrc@yahoo.com.br        /**
6812684Sodanrc@yahoo.com.br         * Re-Reference Interval Prediction Value.
6913849Sanis.peysieux@inria.fr         * Some values have specific names (according to the paper):
7013849Sanis.peysieux@inria.fr         * 0 -> near-immediate re-rereference interval
7113849Sanis.peysieux@inria.fr         * max_RRPV-1 -> long re-rereference interval
7213849Sanis.peysieux@inria.fr         * max_RRPV -> distant re-rereference interval
7312684Sodanrc@yahoo.com.br         * A value equal to max_RRPV + 1 indicates an invalid entry.
7412684Sodanrc@yahoo.com.br         */
7512684Sodanrc@yahoo.com.br        int rrpv;
7612684Sodanrc@yahoo.com.br
7712684Sodanrc@yahoo.com.br        /**
7812684Sodanrc@yahoo.com.br         * Default constructor. Invalidate data.
7912684Sodanrc@yahoo.com.br         */
8012684Sodanrc@yahoo.com.br        BRRIPReplData(const int max_RRPV) : rrpv(max_RRPV + 1) {}
8112684Sodanrc@yahoo.com.br    };
8212684Sodanrc@yahoo.com.br
8312626Sodanrc@yahoo.com.br    /**
8412684Sodanrc@yahoo.com.br     * Maximum Re-Reference Prediction Value possible. An entry with this
8512626Sodanrc@yahoo.com.br     * value as the rrpv has the longest possible re-reference interval,
8612626Sodanrc@yahoo.com.br     * that is, it is likely not to be used in the near future, and is
8712626Sodanrc@yahoo.com.br     * among the best eviction candidates.
8812626Sodanrc@yahoo.com.br     * A maxRRPV of 1 implies in a NRU.
8912626Sodanrc@yahoo.com.br     */
9012684Sodanrc@yahoo.com.br    const int maxRRPV;
9112626Sodanrc@yahoo.com.br
9212626Sodanrc@yahoo.com.br    /**
9312684Sodanrc@yahoo.com.br     * The hit priority (HP) policy replaces entries that do not receive cache
9412684Sodanrc@yahoo.com.br     * hits over any cache entry that receives a hit, while the frequency
9512684Sodanrc@yahoo.com.br     * priority (FP) policy replaces infrequently re-referenced entries.
9612626Sodanrc@yahoo.com.br     */
9712626Sodanrc@yahoo.com.br    const bool hitPriority;
9812626Sodanrc@yahoo.com.br
9912626Sodanrc@yahoo.com.br    /**
10012626Sodanrc@yahoo.com.br     * Bimodal throtle parameter. Value in the range [0,100] used to decide
10112684Sodanrc@yahoo.com.br     * if a new entry is inserted with long or distant re-reference.
10212626Sodanrc@yahoo.com.br     */
10312626Sodanrc@yahoo.com.br    const unsigned btp;
10412626Sodanrc@yahoo.com.br
10512626Sodanrc@yahoo.com.br  public:
10612626Sodanrc@yahoo.com.br    /** Convenience typedef. */
10712626Sodanrc@yahoo.com.br    typedef BRRIPRPParams Params;
10812626Sodanrc@yahoo.com.br
10912626Sodanrc@yahoo.com.br    /**
11012626Sodanrc@yahoo.com.br     * Construct and initiliaze this replacement policy.
11112626Sodanrc@yahoo.com.br     */
11212626Sodanrc@yahoo.com.br    BRRIPRP(const Params *p);
11312626Sodanrc@yahoo.com.br
11412626Sodanrc@yahoo.com.br    /**
11512626Sodanrc@yahoo.com.br     * Destructor.
11612626Sodanrc@yahoo.com.br     */
11712626Sodanrc@yahoo.com.br    ~BRRIPRP() {}
11812626Sodanrc@yahoo.com.br
11912626Sodanrc@yahoo.com.br    /**
12012684Sodanrc@yahoo.com.br     * Invalidate replacement data to set it as the next probable victim.
12112684Sodanrc@yahoo.com.br     * Set RRPV as the the most distant re-reference.
12212626Sodanrc@yahoo.com.br     *
12312684Sodanrc@yahoo.com.br     * @param replacement_data Replacement data to be invalidated.
12412626Sodanrc@yahoo.com.br     */
12512684Sodanrc@yahoo.com.br    void invalidate(const std::shared_ptr<ReplacementData>& replacement_data)
12612684Sodanrc@yahoo.com.br                                                              const override;
12712626Sodanrc@yahoo.com.br
12812626Sodanrc@yahoo.com.br    /**
12912684Sodanrc@yahoo.com.br     * Touch an entry to update its replacement data.
13012684Sodanrc@yahoo.com.br     *
13112684Sodanrc@yahoo.com.br     * @param replacement_data Replacement data to be touched.
13212684Sodanrc@yahoo.com.br     */
13312684Sodanrc@yahoo.com.br    void touch(const std::shared_ptr<ReplacementData>& replacement_data) const
13412684Sodanrc@yahoo.com.br                                                                     override;
13512684Sodanrc@yahoo.com.br
13612684Sodanrc@yahoo.com.br    /**
13712684Sodanrc@yahoo.com.br     * Reset replacement data. Used when an entry is inserted.
13812626Sodanrc@yahoo.com.br     * Set RRPV according to the insertion policy used.
13912626Sodanrc@yahoo.com.br     *
14012684Sodanrc@yahoo.com.br     * @param replacement_data Replacement data to be reset.
14112626Sodanrc@yahoo.com.br     */
14212684Sodanrc@yahoo.com.br    void reset(const std::shared_ptr<ReplacementData>& replacement_data) const
14312684Sodanrc@yahoo.com.br                                                                     override;
14412626Sodanrc@yahoo.com.br
14512626Sodanrc@yahoo.com.br    /**
14612626Sodanrc@yahoo.com.br     * Find replacement victim using rrpv.
14712626Sodanrc@yahoo.com.br     *
14812626Sodanrc@yahoo.com.br     * @param cands Replacement candidates, selected by indexing policy.
14912684Sodanrc@yahoo.com.br     * @return Replacement entry to be replaced.
15012626Sodanrc@yahoo.com.br     */
15112684Sodanrc@yahoo.com.br    ReplaceableEntry* getVictim(const ReplacementCandidates& candidates) const
15212684Sodanrc@yahoo.com.br                                                                     override;
15312684Sodanrc@yahoo.com.br
15412684Sodanrc@yahoo.com.br    /**
15512684Sodanrc@yahoo.com.br     * Instantiate a replacement data entry.
15612684Sodanrc@yahoo.com.br     *
15712684Sodanrc@yahoo.com.br     * @return A shared pointer to the new replacement data.
15812684Sodanrc@yahoo.com.br     */
15912684Sodanrc@yahoo.com.br    std::shared_ptr<ReplacementData> instantiateEntry() override;
16012626Sodanrc@yahoo.com.br};
16112626Sodanrc@yahoo.com.br
16212626Sodanrc@yahoo.com.br#endif // __MEM_CACHE_REPLACEMENT_POLICIES_BRRIP_RP_HH__
163