gem5  [DEVELOP-FOR-23.0]
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 
38 namespace 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 
67 void
69  std::vector<AddrPriority> &addresses)
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++;
125  mapping_A.address = structuralAddressCounter;
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;
145  Addr map_index = 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 
193 void
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
gem5::prefetch::Base::PrefetchInfo::getAddr
Addr getAddr() const
Obtains the address value of this Prefetcher address.
Definition: base.hh:124
associative_set_impl.hh
gem5::prefetch::Base::blockIndex
Addr blockIndex(Addr a) const
Determine the address of a at block granularity.
Definition: base.cc:218
gem5::prefetch::IrregularStreamBuffer::TrainingUnitEntry::lastAddress
Addr lastAddress
Definition: irregular_stream_buffer.hh:69
gem5::prefetch::IrregularStreamBuffer::getPSMapping
AddressMapping & getPSMapping(Addr paddr, bool is_secure)
Obtain the Physical-to-Structured mapping entry of the given physical address.
Definition: irregular_stream_buffer.cc:175
gem5::prefetch::IrregularStreamBuffer::AddressMappingEntry
Maps a set of contiguous addresses to another set of (not necessarily contiguos) addresses,...
Definition: irregular_stream_buffer.hh:88
gem5::prefetch::Queued::AddrPriority
std::pair< Addr, int32_t > AddrPriority
Definition: queued.hh:190
gem5::prefetch::IrregularStreamBuffer::calculatePrefetch
void calculatePrefetch(const PrefetchInfo &pfi, std::vector< AddrPriority > &addresses) override
Definition: irregular_stream_buffer.cc:68
gem5::prefetch::Base::PrefetchInfo::isSecure
bool isSecure() const
Returns true if the address targets the secure memory space.
Definition: base.hh:133
gem5::prefetch::IrregularStreamBuffer::AddressMapping::address
Addr address
Definition: irregular_stream_buffer.hh:78
std::vector
STL vector class.
Definition: stl.hh:37
gem5::prefetch::IrregularStreamBuffer::TrainingUnitEntry
Training Unit Entry datatype, it holds the last accessed address and its secure flag.
Definition: irregular_stream_buffer.hh:67
gem5::prefetch::IrregularStreamBuffer::AddressMapping::counter
SatCounter8 counter
Definition: irregular_stream_buffer.hh:79
gem5::isPowerOf2
static constexpr bool isPowerOf2(const T &n)
Definition: intmath.hh:98
irregular_stream_buffer.hh
gem5::prefetch::IrregularStreamBuffer::prefetchCandidatesPerEntry
const unsigned prefetchCandidatesPerEntry
Number of prefetch candidates per Physical-to-Structural entry.
Definition: irregular_stream_buffer.hh:59
gem5::prefetch::Base::PrefetchInfo::getPC
Addr getPC() const
Returns the program counter that generated this request.
Definition: base.hh:142
gem5::prefetch::IrregularStreamBuffer::trainingUnit
AssociativeSet< TrainingUnitEntry > trainingUnit
Map of PCs to Training unit entries.
Definition: irregular_stream_buffer.hh:73
gem5::VegaISA::p
Bitfield< 54 > p
Definition: pagetable.hh:70
gem5::prefetch::IrregularStreamBuffer::addStructuralToPhysicalEntry
void addStructuralToPhysicalEntry(Addr structuralAddress, bool is_secure, Addr physical_address)
Add a mapping to the Structured-to-Physica mapping table.
Definition: irregular_stream_buffer.cc:194
gem5::ArmISA::d
Bitfield< 9 > d
Definition: misc_types.hh:64
gem5::prefetch::IrregularStreamBuffer::IrregularStreamBuffer
IrregularStreamBuffer(const IrregularStreamBufferPrefetcherParams &p)
Definition: irregular_stream_buffer.cc:41
gem5::GenericSatCounter::reset
void reset()
Reset the counter to its initial value.
Definition: sat_counter.hh:292
gem5::prefetch::IrregularStreamBuffer::chunkSize
const size_t chunkSize
Size in bytes of a temporal stream.
Definition: irregular_stream_buffer.hh:57
gem5::prefetch::IrregularStreamBuffer::degree
const unsigned degree
Number of maximum prefetches requests created when predicting.
Definition: irregular_stream_buffer.hh:61
gem5::prefetch::IrregularStreamBuffer::spAddressMappingCache
AssociativeSet< AddressMappingEntry > spAddressMappingCache
Structured-to-Physical mappings table.
Definition: irregular_stream_buffer.hh:110
gem5::prefetch::IrregularStreamBuffer::TrainingUnitEntry::lastAddressSecure
bool lastAddressSecure
Definition: irregular_stream_buffer.hh:70
gem5::prefetch::IrregularStreamBuffer::structuralAddressCounter
uint64_t structuralAddressCounter
Counter of allocated structural addresses, increased by "chunkSize", each time a new structured addre...
Definition: irregular_stream_buffer.hh:115
gem5::Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
gem5::prefetch::IrregularStreamBuffer::psAddressMappingCache
AssociativeSet< AddressMappingEntry > psAddressMappingCache
Physical-to-Structured mappings table.
Definition: irregular_stream_buffer.hh:108
gem5::prefetch::Queued
Definition: queued.hh:59
gem5::prefetch::Base::lBlkSize
unsigned lBlkSize
log_2(block size of the parent cache).
Definition: base.hh:272
gem5::prefetch::IrregularStreamBuffer::AddressMappingEntry::mappings
std::vector< AddressMapping > mappings
Definition: irregular_stream_buffer.hh:90
gem5::MipsISA::pc
Bitfield< 4 > pc
Definition: pra_constants.hh:243
gem5::prefetch::IrregularStreamBuffer::AddressMapping
Address Mapping entry, holds an address and a confidence counter.
Definition: irregular_stream_buffer.hh:76
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: gpu_translation_state.hh:37
gem5::prefetch::Base::PrefetchInfo
Class containing the information needed by the prefetch to train and generate new prefetch requests.
Definition: base.hh:96
gem5::X86ISA::addr
Bitfield< 3 > addr
Definition: types.hh:84
gem5::prefetch::Base::PrefetchInfo::hasPC
bool hasPC() const
Returns true if the associated program counter is valid.
Definition: base.hh:152

Generated on Sun Jul 30 2023 01:56:57 for gem5 by doxygen 1.8.17