gem5  v21.1.0.2
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
gem5::prefetch::Base::PrefetchInfo::getAddr
Addr getAddr() const
Obtains the address value of this Prefetcher address.
Definition: base.hh:125
associative_set_impl.hh
gem5::prefetch::Base::blockIndex
Addr blockIndex(Addr a) const
Determine the address of a at block granularity.
Definition: base.cc:219
gem5::prefetch::IrregularStreamBuffer::TrainingUnitEntry::lastAddress
Addr lastAddress
Definition: irregular_stream_buffer.hh:70
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:176
gem5::prefetch::IrregularStreamBuffer::AddressMappingEntry
Maps a set of contiguous addresses to another set of (not necessarily contiguos) addresses,...
Definition: irregular_stream_buffer.hh:89
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:69
gem5::prefetch::Base::PrefetchInfo::isSecure
bool isSecure() const
Returns true if the address targets the secure memory space.
Definition: base.hh:134
gem5::prefetch::IrregularStreamBuffer::AddressMapping::address
Addr address
Definition: irregular_stream_buffer.hh:79
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:68
gem5::prefetch::IrregularStreamBuffer::AddressMapping::counter
SatCounter8 counter
Definition: irregular_stream_buffer.hh:80
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:60
gem5::prefetch::Base::PrefetchInfo::getPC
Addr getPC() const
Returns the program counter that generated this request.
Definition: base.hh:143
gem5::prefetch::IrregularStreamBuffer::trainingUnit
AssociativeSet< TrainingUnitEntry > trainingUnit
Map of PCs to Training unit entries.
Definition: irregular_stream_buffer.hh:74
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:195
gem5::ArmISA::d
Bitfield< 9 > d
Definition: misc_types.hh:63
gem5::MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:326
gem5::prefetch::IrregularStreamBuffer::IrregularStreamBuffer
IrregularStreamBuffer(const IrregularStreamBufferPrefetcherParams &p)
Definition: irregular_stream_buffer.cc:42
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:58
gem5::prefetch::IrregularStreamBuffer::degree
const unsigned degree
Number of maximum prefetches requests created when predicting.
Definition: irregular_stream_buffer.hh:62
gem5::prefetch::IrregularStreamBuffer::spAddressMappingCache
AssociativeSet< AddressMappingEntry > spAddressMappingCache
Structured-to-Physical mappings table.
Definition: irregular_stream_buffer.hh:111
gem5::prefetch::IrregularStreamBuffer::TrainingUnitEntry::lastAddressSecure
bool lastAddressSecure
Definition: irregular_stream_buffer.hh:71
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:116
gem5::Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
gem5::GEM5_DEPRECATED_NAMESPACE
GEM5_DEPRECATED_NAMESPACE(GuestABI, guest_abi)
gem5::prefetch::IrregularStreamBuffer::psAddressMappingCache
AssociativeSet< AddressMappingEntry > psAddressMappingCache
Physical-to-Structured mappings table.
Definition: irregular_stream_buffer.hh:109
gem5::prefetch::Queued
Definition: queued.hh:60
gem5::prefetch::Base::lBlkSize
unsigned lBlkSize
log_2(block size of the parent cache).
Definition: base.hh:273
gem5::prefetch::IrregularStreamBuffer::AddressMappingEntry::mappings
std::vector< AddressMapping > mappings
Definition: irregular_stream_buffer.hh:91
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:77
gem5::context_switch_task_id::Prefetcher
@ Prefetcher
Definition: request.hh:83
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: decoder.cc:40
gem5::prefetch::Base::PrefetchInfo
Class containing the information needed by the prefetch to train and generate new prefetch requests.
Definition: base.hh:97
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:153

Generated on Tue Sep 21 2021 12:25:29 for gem5 by doxygen 1.8.17