2 * Copyright (c) 2018 Inria
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.
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.
28 * Authors: Daniel Carvalho
31 #ifndef __MEM_CACHE_REPLACEMENT_POLICIES_BASE_HH__
32 #define __MEM_CACHE_REPLACEMENT_POLICIES_BASE_HH__
36 #include "params/BaseReplacementPolicy.hh"
37 #include "sim/sim_object.hh"
40 * The replacement data needed by the replacement policy.
41 * Each replacement policy should have its own replacement data.
43 struct ReplacementData {};
46 * A replaceable entry is used by any table-like structure that needs to
47 * implement replacement functionality. It provides the replacement data
48 * pointer instantiated and needed by the replacement policy used.
49 * @sa Replacement Policies
51 class ReplaceableEntry
55 * Replacement data associated to this entry.
56 * It is instantiated by the replacement policy.
58 std::shared_ptr<ReplacementData> replacementData;
62 * Replacement candidates as chosen by the indexing policy.
64 typedef std::vector<ReplaceableEntry*> ReplacementCandidates;
67 * A common base class of cache replacement policy objects.
69 class BaseReplacementPolicy : public SimObject
73 * Convenience typedef.
75 typedef BaseReplacementPolicyParams Params;
78 * Construct and initiliaze this replacement policy.
80 BaseReplacementPolicy(const Params *p) : SimObject(p) {}
85 virtual ~BaseReplacementPolicy() {}
88 * Invalidate replacement data to set it as the next probable victim.
90 * @param replacement_data Replacement data to be invalidated.
92 virtual void invalidate(const std::shared_ptr<ReplacementData>&
93 replacement_data) const = 0;
96 * Update replacement data.
98 * @param replacement_data Replacement data to be touched.
100 virtual void touch(const std::shared_ptr<ReplacementData>&
101 replacement_data) const = 0;
104 * Reset replacement data. Used when it's holder is inserted/validated.
106 * @param replacement_data Replacement data to be reset.
108 virtual void reset(const std::shared_ptr<ReplacementData>&
109 replacement_data) const = 0;
112 * Find replacement victim among candidates.
114 * @param candidates Replacement candidates, selected by indexing policy.
115 * @return Replacement entry to be replaced.
117 virtual ReplaceableEntry* getVictim(
118 const ReplacementCandidates& candidates) const = 0;
121 * Instantiate a replacement data entry.
123 * @return A shared pointer to the new replacement data.
125 virtual std::shared_ptr<ReplacementData> instantiateEntry() = 0;
128 #endif // __MEM_CACHE_REPLACEMENT_POLICIES_BASE_HH__