signature_path.hh (13553:047def1fa787) signature_path.hh (13624:3d8220c2d41d)
1/**
2 * Copyright (c) 2018 Metempsy Technology Consulting
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;

--- 36 unchanged lines hidden (view full) ---

45#include "mem/cache/prefetch/associative_set.hh"
46#include "mem/cache/prefetch/queued.hh"
47#include "mem/packet.hh"
48
49struct SignaturePathPrefetcherParams;
50
51class SignaturePathPrefetcher : public QueuedPrefetcher
52{
1/**
2 * Copyright (c) 2018 Metempsy Technology Consulting
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;

--- 36 unchanged lines hidden (view full) ---

45#include "mem/cache/prefetch/associative_set.hh"
46#include "mem/cache/prefetch/queued.hh"
47#include "mem/packet.hh"
48
49struct SignaturePathPrefetcherParams;
50
51class SignaturePathPrefetcher : public QueuedPrefetcher
52{
53 protected:
53 /** Signature type */
54 typedef uint16_t signature_t;
55 /** Stride type */
56 typedef int16_t stride_t;
57
58 /** Number of strides stored in each pattern entry */
59 const unsigned stridesPerPatternEntry;
60 /** Number of bits to shift when generating a new signature */

--- 30 unchanged lines hidden (view full) ---

91 PatternStrideEntry() : stride(0), counter(0)
92 {}
93 };
94 /** Pattern entry data type, a set of stride and counter entries */
95 struct PatternEntry : public TaggedEntry
96 {
97 /** group of stides */
98 std::vector<PatternStrideEntry> strideEntries;
54 /** Signature type */
55 typedef uint16_t signature_t;
56 /** Stride type */
57 typedef int16_t stride_t;
58
59 /** Number of strides stored in each pattern entry */
60 const unsigned stridesPerPatternEntry;
61 /** Number of bits to shift when generating a new signature */

--- 30 unchanged lines hidden (view full) ---

92 PatternStrideEntry() : stride(0), counter(0)
93 {}
94 };
95 /** Pattern entry data type, a set of stride and counter entries */
96 struct PatternEntry : public TaggedEntry
97 {
98 /** group of stides */
99 std::vector<PatternStrideEntry> strideEntries;
99 PatternEntry(size_t num_strides) : strideEntries(num_strides)
100 /** use counter, used by SPPv2 */
101 uint8_t counter;
102 PatternEntry(size_t num_strides) : strideEntries(num_strides),
103 counter(0)
100 {}
101
102 /** Reset the entries to their initial values */
103 void reset() override
104 {
105 for (auto &entry : strideEntries) {
106 entry.counter = 0;
107 entry.stride = 0;
108 }
104 {}
105
106 /** Reset the entries to their initial values */
107 void reset() override
108 {
109 for (auto &entry : strideEntries) {
110 entry.counter = 0;
111 entry.stride = 0;
112 }
113 counter = 0;
109 }
110
111 /**
112 * Returns the entry with the desired stride
113 * @param stride the stride to find
114 * @result a pointer to the entry, if the stride was found, or nullptr,
115 * if the stride was not found
116 */

--- 35 unchanged lines hidden (view full) ---

152 sig ^= str;
153 sig &= mask(signatureBits);
154 return sig;
155 }
156
157 /**
158 * Generates an address to be prefetched.
159 * @param ppn page number to prefetch from
114 }
115
116 /**
117 * Returns the entry with the desired stride
118 * @param stride the stride to find
119 * @result a pointer to the entry, if the stride was found, or nullptr,
120 * if the stride was not found
121 */

--- 35 unchanged lines hidden (view full) ---

157 sig ^= str;
158 sig &= mask(signatureBits);
159 return sig;
160 }
161
162 /**
163 * Generates an address to be prefetched.
164 * @param ppn page number to prefetch from
160 * @param block block number within the page, this value can be negative,
161 * which means that the block refered is actualy in the previous
162 * page (ppn-1), if the value is greater than (pageBytes/blkSize-1)
163 * then the block refers to a block within the next page (ppn+1)
165 * @param last_block last accessed block within the page ppn
166 * @param delta difference, in number of blocks, from the last_block
167 * accessed to the block to prefetch. The block to prefetch is
168 * computed by this formula:
169 * ppn * pageBytes + (last_block + delta) * blkSize
170 * This value can be negative.
171 * @param path_confidence the confidence factor of this prefetch
172 * @param signature the current path signature
164 * @param is_secure whether this page is inside the secure memory area
173 * @param is_secure whether this page is inside the secure memory area
165 * @param addresses if allowed, the address will be added to this vector
174 * @param addresses addresses to prefetch will be added to this vector
166 */
175 */
167 void addPrefetch(Addr ppn, stride_t block, bool is_secure,
168 std::vector<AddrPriority> &addresses);
176 void addPrefetch(Addr ppn, stride_t last_block, stride_t delta,
177 double path_confidence, signature_t signature,
178 bool is_secure,
179 std::vector<AddrPriority> &addresses);
169
170 /**
171 * Obtains the SignatureEntry of the given page, if the page is not found,
172 * it allocates a new one, replacing an existing entry if needed
180
181 /**
182 * Obtains the SignatureEntry of the given page, if the page is not found,
183 * it allocates a new one, replacing an existing entry if needed
184 * It also provides the stride of the current block and the initial
185 * path confidence of the corresponding entry
173 * @param ppn physical page number of the page
174 * @param is_secure whether this page is inside the secure memory area
175 * @param block accessed block within the page
186 * @param ppn physical page number of the page
187 * @param is_secure whether this page is inside the secure memory area
188 * @param block accessed block within the page
176 * @param miss output, if the entry is not found, this will be set to true
189 * @param miss if the entry is not found, this will be set to true
190 * @param stride set to the computed stride
191 * @param initial_confidence set to the initial confidence value
177 * @result a reference to the SignatureEntry
178 */
192 * @result a reference to the SignatureEntry
193 */
179 SignatureEntry & getSignatureEntry(Addr ppn, bool is_secure,
180 stride_t block, bool &miss);
194 SignatureEntry &getSignatureEntry(Addr ppn, bool is_secure, stride_t block,
195 bool &miss, stride_t &stride, double &initial_confidence);
181 /**
182 * Obtains the PatternEntry of the given signature, if the signature is
183 * not found, it allocates a new one, replacing an existing entry if needed
184 * @param signature the signature of the desired entry
185 * @result a reference to the PatternEntry
186 */
196 /**
197 * Obtains the PatternEntry of the given signature, if the signature is
198 * not found, it allocates a new one, replacing an existing entry if needed
199 * @param signature the signature of the desired entry
200 * @result a reference to the PatternEntry
201 */
187 PatternEntry & getPatternEntry(Addr signature);
202 PatternEntry& getPatternEntry(Addr signature);
188
189 /**
190 * Updates the pattern table with the provided signature and stride
191 * @param signature the signature to use to index the pattern table
192 * @param stride the stride to use to index the set of strides of the
193 * pattern table entry
194 */
195 void updatePatternTable(Addr signature, stride_t stride);
196
203
204 /**
205 * Updates the pattern table with the provided signature and stride
206 * @param signature the signature to use to index the pattern table
207 * @param stride the stride to use to index the set of strides of the
208 * pattern table entry
209 */
210 void updatePatternTable(Addr signature, stride_t stride);
211
212 /**
213 * Computes the lookahead path confidence of the provided pattern entry
214 * @param sig the PatternEntry to use
215 * @param lookahead PatternStrideEntry within the provided PatternEntry
216 * @return the computed confidence factor
217 */
218 virtual double calculateLookaheadConfidence(PatternEntry const &sig,
219 PatternStrideEntry const &lookahead) const;
220
221 /**
222 * Computes the prefetch confidence of the provided pattern entry
223 * @param sig the PatternEntry to use
224 * @param entry PatternStrideEntry within the provided PatternEntry
225 * @return the computed confidence factor
226 */
227 virtual double calculatePrefetchConfidence(PatternEntry const &sig,
228 PatternStrideEntry const &entry) const;
229
230 /**
231 * Increases the counter of a given PatternEntry/PatternStrideEntry
232 * @param pattern_entry the corresponding PatternEntry
233 * @param pstride_entry the PatternStrideEntry within the PatternEntry
234 */
235 virtual void increasePatternEntryCounter(PatternEntry &pattern_entry,
236 PatternStrideEntry &pstride_entry);
237
238 /**
239 * Whenever a new SignatureEntry is allocated, it computes the new
240 * signature to be used with the new entry, the resulting stride and the
241 * initial path confidence of the new entry.
242 * @param current_block accessed block within the page of the associated
243 entry
244 * @param new_signature new signature of the allocated entry
245 * @param new_conf the initial path confidence of this entry
246 * @param new_stride the resulting current stride
247 */
248 virtual void handleSignatureTableMiss(stride_t current_block,
249 signature_t &new_signature, double &new_conf,
250 stride_t &new_stride);
251
252 /**
253 * Auxiliar prefetch mechanism used at the end of calculatePrefetch.
254 * This prefetcher uses this to activate the next line prefetcher if
255 * no prefetch candidates have been found.
256 * @param ppn physical page number of the current accessed page
257 * @param current_block last accessed block within the page ppn
258 * @param is_secure whether this page is inside the secure memory area
259 * @param addresses the addresses to be prefetched are added to this vector
260 * @param updated_filter_entries set of addresses containing these that
261 * their filter has been updated, if this call updates a new entry
262 */
263 virtual void auxiliaryPrefetcher(Addr ppn, stride_t current_block,
264 bool is_secure, std::vector<AddrPriority> &addresses);
265
266 /**
267 * Handles the situation when the lookahead process has crossed the
268 * boundaries of the current page. This is not fully described in the
269 * paper that was used to implement this code, however, the article
270 * describing the upgraded version of this prefetcher provides some
271 * details. For this prefetcher, there are no specific actions to be
272 * done.
273 * @param signature the lookahead signature that crossed the page
274 * @param delta the current stride that caused it
275 * @param last_offset the last accessed block within the page
276 * @param path_confidence the path confidence at the moment of crossing
277 */
278 virtual void handlePageCrossingLookahead(signature_t signature,
279 stride_t last_offset, stride_t delta, double path_confidence) {
280 }
281
197 public:
198 SignaturePathPrefetcher(const SignaturePathPrefetcherParams* p);
199 ~SignaturePathPrefetcher() {}
200 void calculatePrefetch(const PrefetchInfo &pfi,
201 std::vector<AddrPriority> &addresses) override;
202};
203
204#endif//__MEM_CACHE_PREFETCH_SIGNATURE_PATH_HH__
282 public:
283 SignaturePathPrefetcher(const SignaturePathPrefetcherParams* p);
284 ~SignaturePathPrefetcher() {}
285 void calculatePrefetch(const PrefetchInfo &pfi,
286 std::vector<AddrPriority> &addresses) override;
287};
288
289#endif//__MEM_CACHE_PREFETCH_SIGNATURE_PATH_HH__