gem5 v24.1.0.1
Loading...
Searching...
No Matches
irregular_stream_buffer.cc
Go to the documentation of this file.
1
30
31#include "debug/HWPrefetch.hh"
32#include "params/IrregularStreamBufferPrefetcher.hh"
33
34namespace gem5
35{
36
37namespace prefetch
38{
39
41 const IrregularStreamBufferPrefetcherParams &p)
42 : Queued(p),
43 chunkSize(p.chunk_size),
44 prefetchCandidatesPerEntry(p.prefetch_candidates_per_entry),
45 degree(p.degree),
46 trainingUnit((name() + ".TrainingUnit").c_str(),
47 p.training_unit_entries,
48 p.training_unit_assoc,
49 p.training_unit_replacement_policy,
50 p.training_unit_indexing_policy,
51 TrainingUnitEntry(genTagExtractor(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 genTagExtractor(p.ps_address_map_cache_indexing_policy))),
60 spAddressMappingCache((name() + ".SPAddressMappingCache").c_str(),
61 p.address_map_cache_entries,
62 p.address_map_cache_assoc,
63 p.sp_address_map_cache_replacement_policy,
64 p.sp_address_map_cache_indexing_policy,
65 AddressMappingEntry(prefetchCandidatesPerEntry,
66 p.num_counter_bits,
67 genTagExtractor(p.sp_address_map_cache_indexing_policy))),
68 structuralAddressCounter(0)
69{
71}
72
73void
76 const CacheAccessor &cache)
77{
78 // This prefetcher requires a PC
79 if (!pfi.hasPC()) {
80 return;
81 }
82 bool is_secure = pfi.isSecure();
83 Addr pc = pfi.getPC();
84 Addr addr = blockIndex(pfi.getAddr());
85
86 // Training, if the entry exists, then we found a correlation between
87 // the entry lastAddress (named as correlated_addr_A) and the address of
88 // the current access (named as correlated_addr_B)
89 const TrainingUnitEntry::KeyType key{pc, is_secure};
90 TrainingUnitEntry *entry = trainingUnit.findEntry(key);
91 bool correlated_addr_found = false;
92 Addr correlated_addr_A = 0;
93 Addr correlated_addr_B = 0;
94 if (entry != nullptr && entry->lastAddressSecure == is_secure) {
95 trainingUnit.accessEntry(entry);
96 correlated_addr_found = true;
97 correlated_addr_A = entry->lastAddress;
98 correlated_addr_B = addr;
99 } else {
100 entry = trainingUnit.findVictim(key);
101 assert(entry != nullptr);
102
103 trainingUnit.insertEntry(key, entry);
104 }
105 // Update the entry
106 entry->lastAddress = addr;
107 entry->lastAddressSecure = is_secure;
108
109 if (correlated_addr_found) {
110 // If a correlation was found, update the Physical-to-Structural
111 // table accordingly
112 AddressMapping &mapping_A = getPSMapping(correlated_addr_A, is_secure);
113 AddressMapping &mapping_B = getPSMapping(correlated_addr_B, is_secure);
114 if (mapping_A.counter > 0 && mapping_B.counter > 0) {
115 // Entry for A and B
116 if (mapping_B.address == (mapping_A.address + 1)) {
117 mapping_B.counter++;
118 } else {
119 if (mapping_B.counter == 1) {
120 // Counter would hit 0, reassign address while keeping
121 // counter at 1
122 mapping_B.address = mapping_A.address + 1;
123 addStructuralToPhysicalEntry(mapping_B.address, is_secure,
124 correlated_addr_B);
125 } else {
126 mapping_B.counter--;
127 }
128 }
129 } else {
130 if (mapping_A.counter == 0) {
131 // if A is not valid, generate a new structural address
132 mapping_A.counter++;
136 is_secure, correlated_addr_A);
137 }
138 mapping_B.counter.reset();
139 mapping_B.counter++;
140 mapping_B.address = mapping_A.address + 1;
141 // update SP-AMC
142 addStructuralToPhysicalEntry(mapping_B.address, is_secure,
143 correlated_addr_B);
144 }
145 }
146
147 // Use the PS mapping to predict future accesses using the current address
148 // - Look for the structured address
149 // - if it exists, use it to generate prefetches for the subsequent
150 // addresses in ascending order, as many as indicated by the degree
151 // (given the structured address S, prefetch S+1, S+2, .. up to S+degree)
152 Addr amc_address = addr / prefetchCandidatesPerEntry;
155 {amc_address, is_secure});
156 if (ps_am != nullptr) {
157 AddressMapping &mapping = ps_am->mappings[map_index];
158 if (mapping.counter > 0) {
159 Addr sp_address = mapping.address / prefetchCandidatesPerEntry;
160 Addr sp_index = mapping.address % prefetchCandidatesPerEntry;
161 AddressMappingEntry *sp_am =
162 spAddressMappingCache.findEntry({sp_address, is_secure});
163 if (sp_am == nullptr) {
164 // The entry has been evicted, can not generate prefetches
165 return;
166 }
167 for (unsigned d = 1;
168 d <= degree && (sp_index + d) < prefetchCandidatesPerEntry;
169 d += 1)
170 {
171 AddressMapping &spm = sp_am->mappings[sp_index + d];
172 //generate prefetch
173 if (spm.counter > 0) {
174 Addr pf_addr = spm.address << lBlkSize;
175 addresses.push_back(AddrPriority(pf_addr, 0));
176 }
177 }
178 }
179 }
180}
181
184{
185 Addr amc_address = paddr / prefetchCandidatesPerEntry;
186 Addr map_index = paddr % prefetchCandidatesPerEntry;
187 AddressMappingEntry *ps_entry =
188 psAddressMappingCache.findEntry({amc_address, is_secure});
189 if (ps_entry != nullptr) {
190 // A PS-AMC line already exists
191 psAddressMappingCache.accessEntry(ps_entry);
192 } else {
193 ps_entry = psAddressMappingCache.findVictim({amc_address, is_secure});
194 assert(ps_entry != nullptr);
195
196 psAddressMappingCache.insertEntry({amc_address, is_secure}, ps_entry);
197 }
198 return ps_entry->mappings[map_index];
199}
200
201void
203 Addr structural_address, bool is_secure, Addr physical_address)
204{
205 Addr amc_address = structural_address / prefetchCandidatesPerEntry;
206 Addr map_index = structural_address % prefetchCandidatesPerEntry;
207 AddressMappingEntry *sp_entry =
208 spAddressMappingCache.findEntry({amc_address, is_secure});
209 if (sp_entry != nullptr) {
210 spAddressMappingCache.accessEntry(sp_entry);
211 } else {
212 sp_entry = spAddressMappingCache.findVictim({amc_address, is_secure});
213 assert(sp_entry != nullptr);
214
215 spAddressMappingCache.insertEntry({amc_address, is_secure}, sp_entry);
216 }
217 AddressMapping &mapping = sp_entry->mappings[map_index];
218 mapping.address = physical_address;
219 mapping.counter.reset();
220 mapping.counter++;
221}
222
223} // namespace prefetch
224} // 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.
AssociativeCache< TrainingUnitEntry > trainingUnit
Map of PCs to Training unit entries.
const size_t chunkSize
Size in bytes of a temporal stream.
AssociativeCache< AddressMappingEntry > psAddressMappingCache
Physical-to-Structured mappings table.
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
AssociativeCache< AddressMappingEntry > spAddressMappingCache
Structured-to-Physical mappings table.
IrregularStreamBuffer(const IrregularStreamBufferPrefetcherParams &p)
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.
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 Arm Limited 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
static constexpr auto genTagExtractor(BTBIndexingPolicy *ip)
This helper generates a tag extractor function object which will be typically used by Replaceable ent...
Definition btb_entry.hh:281
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 Mon Jan 13 2025 04:28:38 for gem5 by doxygen 1.9.8