bip_rp.hh revision 12727
1/**
2 * Copyright (c) 2018 Inria
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 * Authors: Daniel Carvalho
29 */
30
31/**
32 * @file
33 * Declaration of a Bimodal Interval Prediction replacement policy.
34 * Has a probability of when placing new entries, placing them as MRU.
35 *
36 * Although both LRU and LIP can be seen as specific cases of BIP
37 * where the bimodal throtle parameter are 1 and 0, respectively, we
38 * decide not to inherit from it, and do the other way around (inherit
39 * from LRU) for efficiency reasons.
40 *
41 * In the original paper they use btp = 1/32 ~= 3%.
42 */
43
44#ifndef __MEM_CACHE_REPLACEMENT_POLICIES_BIP_RP_HH__
45#define __MEM_CACHE_REPLACEMENT_POLICIES_BIP_RP_HH__
46
47#include "mem/cache/replacement_policies/lru_rp.hh"
48
49struct BIPRPParams;
50
51class BIPRP : public LRURP
52{
53  protected:
54    /**
55     * Bimodal throtle parameter. Value in the range [0,100] used to decide
56     * if a new entry is inserted at the MRU or LRU position.
57     */
58    const unsigned btp;
59
60  public:
61    /** Convenience typedef. */
62    typedef BIPRPParams Params;
63
64    /**
65     * Construct and initiliaze this replacement policy.
66     */
67    BIPRP(const Params *p);
68
69    /**
70     * Destructor.
71     */
72    ~BIPRP() {}
73
74    /**
75     * Reset replacement data for an entry. Used when an entry is inserted.
76     * Uses the bimodal throtle parameter to decide whether the new entry
77     * should be inserted as MRU, or LRU.
78     *
79     * @param replacement_data Replacement data to be reset.
80     */
81    void reset(const std::shared_ptr<ReplacementData>& replacement_data) const
82                                                                     override;
83};
84
85#endif // __MEM_CACHE_REPLACEMENT_POLICIES_BIP_RP_HH__
86