gem5 v23.0.0.1
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(p.training_unit_assoc, p.training_unit_entries,
48 p.training_unit_indexing_policy,
49 p.training_unit_replacement_policy),
50 psAddressMappingCache(p.address_map_cache_assoc,
51 p.address_map_cache_entries,
52 p.ps_address_map_cache_indexing_policy,
53 p.ps_address_map_cache_replacement_policy,
54 AddressMappingEntry(prefetchCandidatesPerEntry,
55 p.num_counter_bits)),
56 spAddressMappingCache(p.address_map_cache_assoc,
57 p.address_map_cache_entries,
58 p.sp_address_map_cache_indexing_policy,
59 p.sp_address_map_cache_replacement_policy,
60 AddressMappingEntry(prefetchCandidatesPerEntry,
61 p.num_counter_bits)),
62 structuralAddressCounter(0)
63{
65}
66
67void
70{
71 // This prefetcher requires a PC
72 if (!pfi.hasPC()) {
73 return;
74 }
75 bool is_secure = pfi.isSecure();
76 Addr pc = pfi.getPC();
77 Addr addr = blockIndex(pfi.getAddr());
78
79 // Training, if the entry exists, then we found a correlation between
80 // the entry lastAddress (named as correlated_addr_A) and the address of
81 // the current access (named as correlated_addr_B)
82 TrainingUnitEntry *entry = trainingUnit.findEntry(pc, is_secure);
83 bool correlated_addr_found = false;
84 Addr correlated_addr_A = 0;
85 Addr correlated_addr_B = 0;
86 if (entry != nullptr && entry->lastAddressSecure == is_secure) {
87 trainingUnit.accessEntry(entry);
88 correlated_addr_found = true;
89 correlated_addr_A = entry->lastAddress;
90 correlated_addr_B = addr;
91 } else {
92 entry = trainingUnit.findVictim(pc);
93 assert(entry != nullptr);
94
95 trainingUnit.insertEntry(pc, is_secure, entry);
96 }
97 // Update the entry
98 entry->lastAddress = addr;
99 entry->lastAddressSecure = is_secure;
100
101 if (correlated_addr_found) {
102 // If a correlation was found, update the Physical-to-Structural
103 // table accordingly
104 AddressMapping &mapping_A = getPSMapping(correlated_addr_A, is_secure);
105 AddressMapping &mapping_B = getPSMapping(correlated_addr_B, is_secure);
106 if (mapping_A.counter > 0 && mapping_B.counter > 0) {
107 // Entry for A and B
108 if (mapping_B.address == (mapping_A.address + 1)) {
109 mapping_B.counter++;
110 } else {
111 if (mapping_B.counter == 1) {
112 // Counter would hit 0, reassign address while keeping
113 // counter at 1
114 mapping_B.address = mapping_A.address + 1;
115 addStructuralToPhysicalEntry(mapping_B.address, is_secure,
116 correlated_addr_B);
117 } else {
118 mapping_B.counter--;
119 }
120 }
121 } else {
122 if (mapping_A.counter == 0) {
123 // if A is not valid, generate a new structural address
124 mapping_A.counter++;
128 is_secure, correlated_addr_A);
129 }
130 mapping_B.counter.reset();
131 mapping_B.counter++;
132 mapping_B.address = mapping_A.address + 1;
133 // update SP-AMC
134 addStructuralToPhysicalEntry(mapping_B.address, is_secure,
135 correlated_addr_B);
136 }
137 }
138
139 // Use the PS mapping to predict future accesses using the current address
140 // - Look for the structured address
141 // - if it exists, use it to generate prefetches for the subsequent
142 // addresses in ascending order, as many as indicated by the degree
143 // (given the structured address S, prefetch S+1, S+2, .. up to S+degree)
144 Addr amc_address = addr / prefetchCandidatesPerEntry;
146 AddressMappingEntry *ps_am = psAddressMappingCache.findEntry(amc_address,
147 is_secure);
148 if (ps_am != nullptr) {
149 AddressMapping &mapping = ps_am->mappings[map_index];
150 if (mapping.counter > 0) {
151 Addr sp_address = mapping.address / prefetchCandidatesPerEntry;
152 Addr sp_index = mapping.address % prefetchCandidatesPerEntry;
153 AddressMappingEntry *sp_am =
154 spAddressMappingCache.findEntry(sp_address, is_secure);
155 if (sp_am == nullptr) {
156 // The entry has been evicted, can not generate prefetches
157 return;
158 }
159 for (unsigned d = 1;
160 d <= degree && (sp_index + d) < prefetchCandidatesPerEntry;
161 d += 1)
162 {
163 AddressMapping &spm = sp_am->mappings[sp_index + d];
164 //generate prefetch
165 if (spm.counter > 0) {
166 Addr pf_addr = spm.address << lBlkSize;
167 addresses.push_back(AddrPriority(pf_addr, 0));
168 }
169 }
170 }
171 }
172}
173
176{
177 Addr amc_address = paddr / prefetchCandidatesPerEntry;
178 Addr map_index = paddr % prefetchCandidatesPerEntry;
179 AddressMappingEntry *ps_entry =
180 psAddressMappingCache.findEntry(amc_address, is_secure);
181 if (ps_entry != nullptr) {
182 // A PS-AMC line already exists
183 psAddressMappingCache.accessEntry(ps_entry);
184 } else {
185 ps_entry = psAddressMappingCache.findVictim(amc_address);
186 assert(ps_entry != nullptr);
187
188 psAddressMappingCache.insertEntry(amc_address, is_secure, ps_entry);
189 }
190 return ps_entry->mappings[map_index];
191}
192
193void
195 Addr structural_address, bool is_secure, Addr physical_address)
196{
197 Addr amc_address = structural_address / prefetchCandidatesPerEntry;
198 Addr map_index = structural_address % prefetchCandidatesPerEntry;
199 AddressMappingEntry *sp_entry =
200 spAddressMappingCache.findEntry(amc_address, is_secure);
201 if (sp_entry != nullptr) {
202 spAddressMappingCache.accessEntry(sp_entry);
203 } else {
204 sp_entry = spAddressMappingCache.findVictim(amc_address);
205 assert(sp_entry != nullptr);
206
207 spAddressMappingCache.insertEntry(amc_address, is_secure, sp_entry);
208 }
209 AddressMapping &mapping = sp_entry->mappings[map_index];
210 mapping.address = physical_address;
211 mapping.counter.reset();
212 mapping.counter++;
213}
214
215} // namespace prefetch
216} // namespace gem5
Class containing the information needed by the prefetch to train and generate new prefetch requests.
Definition base.hh:97
Addr getPC() const
Returns the program counter that generated this request.
Definition base.hh:142
bool isSecure() const
Returns true if the address targets the secure memory space.
Definition base.hh:133
Addr getAddr() const
Obtains the address value of this Prefetcher address.
Definition base.hh:124
bool hasPC() const
Returns true if the associated program counter is valid.
Definition base.hh:152
unsigned lBlkSize
log_2(block size of the parent cache).
Definition base.hh:272
Addr blockIndex(Addr a) const
Determine the address of a at block granularity.
Definition base.cc:218
const unsigned prefetchCandidatesPerEntry
Number of prefetch candidates per Physical-to-Structural entry.
const size_t chunkSize
Size in bytes of a temporal stream.
void calculatePrefetch(const PrefetchInfo &pfi, std::vector< AddrPriority > &addresses) override
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.
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:190
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
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition types.hh:147
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.

Generated on Mon Jul 10 2023 15:32:04 for gem5 by doxygen 1.9.7