base.hh (12600:e670dd17c8cf) | base.hh (12684:44ebd2bc020f) |
---|---|
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 | 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 "mem/cache/base.hh" 35#include "mem/cache/blk.hh" | 34#include <memory> 35 |
36#include "params/BaseReplacementPolicy.hh" 37#include "sim/sim_object.hh" 38 39/** | 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/** |
|
40 * Replacement candidates as chosen by the indexing policy. | 62 * Replacement candidates as chosen by the indexing policy. |
41 * 42 * The base functions touch() and reset() must be called by all subclasses 43 * that override them. 44 * 45 * @todo 46 * Currently the replacement candidates are simply the cache blocks 47 * derived from the possible placement locations of an address, as 48 * defined by the getPossibleLocations() from BaseTags. In a future 49 * patch it should be an inheritable class to allow the replacement 50 * policies to be used with any table-like structure that needs to 51 * replace its entries. | |
52 */ | 63 */ |
53typedef std::vector<CacheBlk*> ReplacementCandidates; | 64typedef std::vector<ReplaceableEntry*> ReplacementCandidates; |
54 55/** 56 * A common base class of cache replacement policy objects. 57 */ 58class BaseReplacementPolicy : public SimObject 59{ 60 public: 61 /** 62 * Convenience typedef. 63 */ 64 typedef BaseReplacementPolicyParams Params; 65 66 /** 67 * Construct and initiliaze this replacement policy. 68 */ | 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 */ |
69 BaseReplacementPolicy(const Params *p); | 80 BaseReplacementPolicy(const Params *p) : SimObject(p) {} |
70 71 /** 72 * Destructor. 73 */ 74 virtual ~BaseReplacementPolicy() {} 75 76 /** | 81 82 /** 83 * Destructor. 84 */ 85 virtual ~BaseReplacementPolicy() {} 86 87 /** |
77 * Touch a block to update its replacement data. 78 * Updates number of references. | 88 * Invalidate replacement data to set it as the next probable victim. |
79 * | 89 * |
80 * This base function must be called by all subclasses that override it. | 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. |
81 * | 97 * |
82 * @param blk Cache block to be touched. | 98 * @param replacement_data Replacement data to be touched. |
83 */ | 99 */ |
84 virtual void touch(CacheBlk *blk); | 100 virtual void touch(const std::shared_ptr<ReplacementData>& 101 replacement_data) const = 0; |
85 86 /** | 102 103 /** |
87 * Reset replacement data for a block. Used when a block is inserted. 88 * Sets the insertion tick, and update number of references. | 104 * Reset replacement data. Used when it's holder is inserted/validated. |
89 * | 105 * |
90 * This base function must be called by all subclasses that override it. 91 * 92 * @param blk Cache block to be reset. | 106 * @param replacement_data Replacement data to be reset. |
93 */ | 107 */ |
94 virtual void reset(CacheBlk *blk); | 108 virtual void reset(const std::shared_ptr<ReplacementData>& 109 replacement_data) const = 0; |
95 96 /** 97 * Find replacement victim among candidates. 98 * 99 * @param candidates Replacement candidates, selected by indexing policy. | 110 111 /** 112 * Find replacement victim among candidates. 113 * 114 * @param candidates Replacement candidates, selected by indexing policy. |
100 * @return Cache block to be replaced. | 115 * @return Replacement entry to be replaced. |
101 */ | 116 */ |
102 virtual CacheBlk* getVictim(const ReplacementCandidates& candidates) = 0; | 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; |
103}; 104 105#endif // __MEM_CACHE_REPLACEMENT_POLICIES_BASE_HH__ | 126}; 127 128#endif // __MEM_CACHE_REPLACEMENT_POLICIES_BASE_HH__ |