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; --- 17 unchanged lines hidden (view full) --- 26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * 28 * Authors: Daniel Carvalho 29 */ 30 31#ifndef __MEM_CACHE_REPLACEMENT_POLICIES_BASE_HH__ 32#define __MEM_CACHE_REPLACEMENT_POLICIES_BASE_HH__ 33 |
34#include <memory> 35 |
36#include "params/BaseReplacementPolicy.hh" 37#include "sim/sim_object.hh" 38 39/** |
40 * The replacement data needed by the replacement policy. 41 * Each replacement policy should have its own replacement data. 42 */ 43struct ReplacementData {}; 44 45/** 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 50 */ 51class ReplaceableEntry 52{ 53 public: 54 /** 55 * Replacement data associated to this entry. 56 * It is instantiated by the replacement policy. 57 */ 58 std::shared_ptr<ReplacementData> replacementData; 59}; 60 61/** |
62 * Replacement candidates as chosen by the indexing policy. |
63 */ |
64typedef std::vector<ReplaceableEntry*> ReplacementCandidates; |
65 66/** 67 * A common base class of cache replacement policy objects. 68 */ 69class BaseReplacementPolicy : public SimObject 70{ 71 public: 72 /** 73 * Convenience typedef. 74 */ 75 typedef BaseReplacementPolicyParams Params; 76 77 /** 78 * Construct and initiliaze this replacement policy. 79 */ |
80 BaseReplacementPolicy(const Params *p) : SimObject(p) {} |
81 82 /** 83 * Destructor. 84 */ 85 virtual ~BaseReplacementPolicy() {} 86 87 /** |
88 * Invalidate replacement data to set it as the next probable victim. |
89 * |
90 * @param replacement_data Replacement data to be invalidated. 91 */ 92 virtual void invalidate(const std::shared_ptr<ReplacementData>& 93 replacement_data) const = 0; 94 95 /** 96 * Update replacement data. |
97 * |
98 * @param replacement_data Replacement data to be touched. |
99 */ |
100 virtual void touch(const std::shared_ptr<ReplacementData>& 101 replacement_data) const = 0; |
102 103 /** |
104 * Reset replacement data. Used when it's holder is inserted/validated. |
105 * |
106 * @param replacement_data Replacement data to be reset. |
107 */ |
108 virtual void reset(const std::shared_ptr<ReplacementData>& 109 replacement_data) const = 0; |
110 111 /** 112 * Find replacement victim among candidates. 113 * 114 * @param candidates Replacement candidates, selected by indexing policy. |
115 * @return Replacement entry to be replaced. |
116 */ |
117 virtual ReplaceableEntry* getVictim( 118 const ReplacementCandidates& candidates) const = 0; 119 120 /** 121 * Instantiate a replacement data entry. 122 * 123 * @return A shared pointer to the new replacement data. 124 */ 125 virtual std::shared_ptr<ReplacementData> instantiateEntry() = 0; |
126}; 127 128#endif // __MEM_CACHE_REPLACEMENT_POLICIES_BASE_HH__ |