gem5 v24.0.0.0
Loading...
Searching...
No Matches
irregular_stream_buffer.cc
Go to the documentation of this file.
1
30
31#include "debug/HWPrefetch.hh"
33#include "params/IrregularStreamBufferPrefetcher.hh"
34
35namespace gem5
36{
37
38namespace prefetch
39{
40
42 const IrregularStreamBufferPrefetcherParams &p)
43 : Queued(p),
44 chunkSize(p.chunk_size),
45 prefetchCandidatesPerEntry(p.prefetch_candidates_per_entry),
46 degree(p.degree),
47 trainingUnit((name() + ".TrainingUnit").c_str(),
48 p.training_unit_entries,
49 p.training_unit_assoc,
50 p.training_unit_replacement_policy,
51 p.training_unit_indexing_policy),
52 psAddressMappingCache((name() + ".PSAddressMappingCache").c_str(),
53 p.address_map_cache_entries,
54 p.address_map_cache_assoc,
55 p.ps_address_map_cache_replacement_policy,
56 p.ps_address_map_cache_indexing_policy,
57 AddressMappingEntry(prefetchCandidatesPerEntry,
58 p.num_counter_bits)),
59 spAddressMappingCache((name() + ".SPAddressMappingCache").c_str(),
60 p.address_map_cache_entries,
61 p.address_map_cache_assoc,
62 p.sp_address_map_cache_replacement_policy,
63 p.sp_address_map_cache_indexing_policy,
64 AddressMappingEntry(prefetchCandidatesPerEntry,
65 p.num_counter_bits)),
66 structuralAddressCounter(0)
67{
69}
70
71void
74 const CacheAccessor &cache)
75{
76 // This prefetcher requires a PC
77 if (!pfi.hasPC()) {
78 return;
79 }
80 bool is_secure = pfi.isSecure();
81 Addr pc = pfi.getPC();
82 Addr addr = blockIndex(pfi.getAddr());
83
84 // Training, if the entry exists, then we found a correlation between
85 // the entry lastAddress (named as correlated_addr_A) and the address of
86 // the current access (named as correlated_addr_B)
87 TrainingUnitEntry *entry = trainingUnit.findEntry(pc, is_secure);
88 bool correlated_addr_found = false;
89 Addr correlated_addr_A = 0;
90 Addr correlated_addr_B = 0;
91 if (entry != nullptr && entry->lastAddressSecure == is_secure) {
92 trainingUnit.accessEntry(entry);
93 correlated_addr_found = true;
94 correlated_addr_A = entry->lastAddress;
95 correlated_addr_B = addr;
96 } else {
97 entry = trainingUnit.findVictim(pc);
98 assert(entry != nullptr);
99
100 trainingUnit.insertEntry(pc, is_secure, entry);
101 }
102 // Update the entry
103 entry->lastAddress = addr;
104 entry->lastAddressSecure = is_secure;
105
106 if (correlated_addr_found) {
107 // If a correlation was found, update the Physical-to-Structural
108 // table accordingly
109 AddressMapping &mapping_A = getPSMapping(correlated_addr_A, is_secure);
110 AddressMapping &mapping_B = getPSMapping(correlated_addr_B, is_secure);
111 if (mapping_A.counter > 0 && mapping_B.counter > 0) {
112 // Entry for A and B
113 if (mapping_B.address == (mapping_A.address + 1)) {
114 mapping_B.counter++;
115 } else {
116 if (mapping_B.counter == 1) {
117 // Counter would hit 0, reassign address while keeping
118 // counter at 1
119 mapping_B.address = mapping_A.address + 1;
120 addStructuralToPhysicalEntry(mapping_B.address, is_secure,
121 correlated_addr_B);
122 } else {
123 mapping_B.counter--;
124 }
125 }
126 } else {
127 if (mapping_A.counter == 0) {
128 // if A is not valid, generate a new structural address
129 mapping_A.counter++;
133 is_secure, correlated_addr_A);
134 }
135 mapping_B.counter.reset();
136 mapping_B.counter++;
137 mapping_B.address = mapping_A.address + 1;
138 // update SP-AMC
139 addStructuralToPhysicalEntry(mapping_B.address, is_secure,
140 correlated_addr_B);
141 }
142 }
143
144 // Use the PS mapping to predict future accesses using the current address
145 // - Look for the structured address
146 // - if it exists, use it to generate prefetches for the subsequent
147 // addresses in ascending order, as many as indicated by the degree
148 // (given the structured address S, prefetch S+1, S+2, .. up to S+degree)
149 Addr amc_address = addr / prefetchCandidatesPerEntry;
151 AddressMappingEntry *ps_am = psAddressMappingCache.findEntry(amc_address,
152 is_secure);
153 if (ps_am != nullptr) {
154 AddressMapping &mapping = ps_am->mappings[map_index];
155 if (mapping.counter > 0) {
156 Addr sp_address = mapping.address / prefetchCandidatesPerEntry;
157 Addr sp_index = mapping.address % prefetchCandidatesPerEntry;
158 AddressMappingEntry *sp_am =
159 spAddressMappingCache.findEntry(sp_address, is_secure);
160 if (sp_am == nullptr) {
161 // The entry has been evicted, can not generate prefetches
162 return;
163 }
164 for (unsigned d = 1;
165 d <= degree && (sp_index + d) < prefetchCandidatesPerEntry;
166 d += 1)
167 {
168 AddressMapping &spm = sp_am->mappings[sp_index + d];
169 //generate prefetch
170 if (spm.counter > 0) {
171 Addr pf_addr = spm.address << lBlkSize;
172 addresses.push_back(AddrPriority(pf_addr, 0));
173 }
174 }
175 }
176 }
177}
178
181{
182 Addr amc_address = paddr / prefetchCandidatesPerEntry;
183 Addr map_index = paddr % prefetchCandidatesPerEntry;
184 AddressMappingEntry *ps_entry =
185 psAddressMappingCache.findEntry(amc_address, is_secure);
186 if (ps_entry != nullptr) {
187 // A PS-AMC line already exists
188 psAddressMappingCache.accessEntry(ps_entry);
189 } else {
190 ps_entry = psAddressMappingCache.findVictim(amc_address);
191 assert(ps_entry != nullptr);
192
193 psAddressMappingCache.insertEntry(amc_address, is_secure, ps_entry);
194 }
195 return ps_entry->mappings[map_index];
196}
197
198void
200 Addr structural_address, bool is_secure, Addr physical_address)
201{
202 Addr amc_address = structural_address / prefetchCandidatesPerEntry;
203 Addr map_index = structural_address % prefetchCandidatesPerEntry;
204 AddressMappingEntry *sp_entry =
205 spAddressMappingCache.findEntry(amc_address, is_secure);
206 if (sp_entry != nullptr) {
207 spAddressMappingCache.accessEntry(sp_entry);
208 } else {
209 sp_entry = spAddressMappingCache.findVictim(amc_address);
210 assert(sp_entry != nullptr);
211
212 spAddressMappingCache.insertEntry(amc_address, is_secure, sp_entry);
213 }
214 AddressMapping &mapping = sp_entry->mappings[map_index];
215 mapping.address = physical_address;
216 mapping.counter.reset();
217 mapping.counter++;
218}
219
220} // namespace prefetch
221} // namespace gem5
Class containing the information needed by the prefetch to train and generate new prefetch requests.
Definition base.hh:111
Addr getPC() const
Returns the program counter that generated this request.
Definition base.hh:156
bool isSecure() const
Returns true if the address targets the secure memory space.
Definition base.hh:147
Addr getAddr() const
Obtains the address value of this Prefetcher address.
Definition base.hh:138
bool hasPC() const
Returns true if the associated program counter is valid.
Definition base.hh:166
unsigned lBlkSize
log_2(block size of the parent cache).
Definition base.hh:289
Addr blockIndex(Addr a) const
Determine the address of a at block granularity.
Definition base.cc:208
const unsigned prefetchCandidatesPerEntry
Number of prefetch candidates per Physical-to-Structural entry.
const size_t chunkSize
Size in bytes of a temporal stream.
uint64_t structuralAddressCounter
Counter of allocated structural addresses, increased by "chunkSize", each time a new structured addre...
AddressMapping & getPSMapping(Addr paddr, bool is_secure)
Obtain the Physical-to-Structured mapping entry of the given physical address.
void calculatePrefetch(const PrefetchInfo &pfi, std::vector< AddrPriority > &addresses, const CacheAccessor &cache) override
IrregularStreamBuffer(const IrregularStreamBufferPrefetcherParams &p)
AssociativeSet< AddressMappingEntry > spAddressMappingCache
Structured-to-Physical mappings table.
void addStructuralToPhysicalEntry(Addr structuralAddress, bool is_secure, Addr physical_address)
Add a mapping to the Structured-to-Physica mapping table.
const unsigned degree
Number of maximum prefetches requests created when predicting.
AssociativeSet< TrainingUnitEntry > trainingUnit
Map of PCs to Training unit entries.
AssociativeSet< AddressMappingEntry > psAddressMappingCache
Physical-to-Structured mappings table.
std::pair< Addr, int32_t > AddrPriority
Definition queued.hh:192
STL vector class.
Definition stl.hh:37
static constexpr bool isPowerOf2(const T &n)
Definition intmath.hh:98
void reset()
Reset the counter to its initial value.
Bitfield< 9 > d
Definition misc_types.hh:64
Bitfield< 4 > pc
Bitfield< 0 > p
Bitfield< 3 > addr
Definition types.hh:84
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition types.hh:147
Provides generic cache lookup functions.
Maps a set of contiguous addresses to another set of (not necessarily contiguos) addresses,...
Address Mapping entry, holds an address and a confidence counter.
Training Unit Entry datatype, it holds the last accessed address and its secure flag.
const std::string & name()
Definition trace.cc:48

Generated on Tue Jun 18 2024 16:24:05 for gem5 by doxygen 1.11.0