gem5  v22.1.0.0
irregular_stream_buffer.cc
Go to the documentation of this file.
1 
30 
31 #include "debug/HWPrefetch.hh"
33 #include "params/IrregularStreamBufferPrefetcher.hh"
34 
35 namespace gem5
36 {
37 
39 namespace prefetch
40 {
41 
43  const IrregularStreamBufferPrefetcherParams &p)
44  : Queued(p),
45  chunkSize(p.chunk_size),
46  prefetchCandidatesPerEntry(p.prefetch_candidates_per_entry),
47  degree(p.degree),
48  trainingUnit(p.training_unit_assoc, p.training_unit_entries,
49  p.training_unit_indexing_policy,
50  p.training_unit_replacement_policy),
51  psAddressMappingCache(p.address_map_cache_assoc,
52  p.address_map_cache_entries,
53  p.ps_address_map_cache_indexing_policy,
54  p.ps_address_map_cache_replacement_policy,
55  AddressMappingEntry(prefetchCandidatesPerEntry,
56  p.num_counter_bits)),
57  spAddressMappingCache(p.address_map_cache_assoc,
58  p.address_map_cache_entries,
59  p.sp_address_map_cache_indexing_policy,
60  p.sp_address_map_cache_replacement_policy,
61  AddressMappingEntry(prefetchCandidatesPerEntry,
62  p.num_counter_bits)),
63  structuralAddressCounter(0)
64 {
66 }
67 
68 void
70  std::vector<AddrPriority> &addresses)
71 {
72  // This prefetcher requires a PC
73  if (!pfi.hasPC()) {
74  return;
75  }
76  bool is_secure = pfi.isSecure();
77  Addr pc = pfi.getPC();
78  Addr addr = blockIndex(pfi.getAddr());
79 
80  // Training, if the entry exists, then we found a correlation between
81  // the entry lastAddress (named as correlated_addr_A) and the address of
82  // the current access (named as correlated_addr_B)
83  TrainingUnitEntry *entry = trainingUnit.findEntry(pc, is_secure);
84  bool correlated_addr_found = false;
85  Addr correlated_addr_A = 0;
86  Addr correlated_addr_B = 0;
87  if (entry != nullptr && entry->lastAddressSecure == is_secure) {
88  trainingUnit.accessEntry(entry);
89  correlated_addr_found = true;
90  correlated_addr_A = entry->lastAddress;
91  correlated_addr_B = addr;
92  } else {
93  entry = trainingUnit.findVictim(pc);
94  assert(entry != nullptr);
95 
96  trainingUnit.insertEntry(pc, is_secure, entry);
97  }
98  // Update the entry
99  entry->lastAddress = addr;
100  entry->lastAddressSecure = is_secure;
101 
102  if (correlated_addr_found) {
103  // If a correlation was found, update the Physical-to-Structural
104  // table accordingly
105  AddressMapping &mapping_A = getPSMapping(correlated_addr_A, is_secure);
106  AddressMapping &mapping_B = getPSMapping(correlated_addr_B, is_secure);
107  if (mapping_A.counter > 0 && mapping_B.counter > 0) {
108  // Entry for A and B
109  if (mapping_B.address == (mapping_A.address + 1)) {
110  mapping_B.counter++;
111  } else {
112  if (mapping_B.counter == 1) {
113  // Counter would hit 0, reassign address while keeping
114  // counter at 1
115  mapping_B.address = mapping_A.address + 1;
116  addStructuralToPhysicalEntry(mapping_B.address, is_secure,
117  correlated_addr_B);
118  } else {
119  mapping_B.counter--;
120  }
121  }
122  } else {
123  if (mapping_A.counter == 0) {
124  // if A is not valid, generate a new structural address
125  mapping_A.counter++;
126  mapping_A.address = structuralAddressCounter;
129  is_secure, correlated_addr_A);
130  }
131  mapping_B.counter.reset();
132  mapping_B.counter++;
133  mapping_B.address = mapping_A.address + 1;
134  // update SP-AMC
135  addStructuralToPhysicalEntry(mapping_B.address, is_secure,
136  correlated_addr_B);
137  }
138  }
139 
140  // Use the PS mapping to predict future accesses using the current address
141  // - Look for the structured address
142  // - if it exists, use it to generate prefetches for the subsequent
143  // addresses in ascending order, as many as indicated by the degree
144  // (given the structured address S, prefetch S+1, S+2, .. up to S+degree)
145  Addr amc_address = addr / prefetchCandidatesPerEntry;
146  Addr map_index = addr % prefetchCandidatesPerEntry;
147  AddressMappingEntry *ps_am = psAddressMappingCache.findEntry(amc_address,
148  is_secure);
149  if (ps_am != nullptr) {
150  AddressMapping &mapping = ps_am->mappings[map_index];
151  if (mapping.counter > 0) {
152  Addr sp_address = mapping.address / prefetchCandidatesPerEntry;
153  Addr sp_index = mapping.address % prefetchCandidatesPerEntry;
154  AddressMappingEntry *sp_am =
155  spAddressMappingCache.findEntry(sp_address, is_secure);
156  if (sp_am == nullptr) {
157  // The entry has been evicted, can not generate prefetches
158  return;
159  }
160  for (unsigned d = 1;
161  d <= degree && (sp_index + d) < prefetchCandidatesPerEntry;
162  d += 1)
163  {
164  AddressMapping &spm = sp_am->mappings[sp_index + d];
165  //generate prefetch
166  if (spm.counter > 0) {
167  Addr pf_addr = spm.address << lBlkSize;
168  addresses.push_back(AddrPriority(pf_addr, 0));
169  }
170  }
171  }
172  }
173 }
174 
177 {
178  Addr amc_address = paddr / prefetchCandidatesPerEntry;
179  Addr map_index = paddr % prefetchCandidatesPerEntry;
180  AddressMappingEntry *ps_entry =
181  psAddressMappingCache.findEntry(amc_address, is_secure);
182  if (ps_entry != nullptr) {
183  // A PS-AMC line already exists
184  psAddressMappingCache.accessEntry(ps_entry);
185  } else {
186  ps_entry = psAddressMappingCache.findVictim(amc_address);
187  assert(ps_entry != nullptr);
188 
189  psAddressMappingCache.insertEntry(amc_address, is_secure, ps_entry);
190  }
191  return ps_entry->mappings[map_index];
192 }
193 
194 void
196  Addr structural_address, bool is_secure, Addr physical_address)
197 {
198  Addr amc_address = structural_address / prefetchCandidatesPerEntry;
199  Addr map_index = structural_address % prefetchCandidatesPerEntry;
200  AddressMappingEntry *sp_entry =
201  spAddressMappingCache.findEntry(amc_address, is_secure);
202  if (sp_entry != nullptr) {
203  spAddressMappingCache.accessEntry(sp_entry);
204  } else {
205  sp_entry = spAddressMappingCache.findVictim(amc_address);
206  assert(sp_entry != nullptr);
207 
208  spAddressMappingCache.insertEntry(amc_address, is_secure, sp_entry);
209  }
210  AddressMapping &mapping = sp_entry->mappings[map_index];
211  mapping.address = physical_address;
212  mapping.counter.reset();
213  mapping.counter++;
214 }
215 
216 } // namespace prefetch
217 } // namespace gem5
Class containing the information needed by the prefetch to train and generate new prefetch requests.
Definition: base.hh:98
Addr getPC() const
Returns the program counter that generated this request.
Definition: base.hh:143
bool isSecure() const
Returns true if the address targets the secure memory space.
Definition: base.hh:134
Addr getAddr() const
Obtains the address value of this Prefetcher address.
Definition: base.hh:125
bool hasPC() const
Returns true if the associated program counter is valid.
Definition: base.hh:153
unsigned lBlkSize
log_2(block size of the parent cache).
Definition: base.hh:273
Addr blockIndex(Addr a) const
Determine the address of a at block granularity.
Definition: base.cc:219
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:191
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.
Definition: sat_counter.hh:292
Bitfield< 9 > d
Definition: misc_types.hh:64
Bitfield< 4 > pc
Bitfield< 54 > p
Definition: pagetable.hh:70
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
GEM5_DEPRECATED_NAMESPACE(GuestABI, guest_abi)
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 Wed Dec 21 2022 10:22:36 for gem5 by doxygen 1.9.1