bip_rp.hh revision 12684
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#include "params/BIPRP.hh"
49
50class BIPRP : public LRURP
51{
52  protected:
53    /**
54     * Bimodal throtle parameter. Value in the range [0,100] used to decide
55     * if a new entry is inserted at the MRU or LRU position.
56     */
57    const unsigned btp;
58
59  public:
60    /** Convenience typedef. */
61    typedef BIPRPParams Params;
62
63    /**
64     * Construct and initiliaze this replacement policy.
65     */
66    BIPRP(const Params *p);
67
68    /**
69     * Destructor.
70     */
71    ~BIPRP() {}
72
73    /**
74     * Reset replacement data for an entry. Used when an entry is inserted.
75     * Uses the bimodal throtle parameter to decide whether the new entry
76     * should be inserted as MRU, or LRU.
77     *
78     * @param replacement_data Replacement data to be reset.
79     */
80    void reset(const std::shared_ptr<ReplacementData>& replacement_data) const
81                                                                     override;
82};
83
84#endif // __MEM_CACHE_REPLACEMENT_POLICIES_BIP_RP_HH__
85