gem5  v20.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 Prefetcher {
36 
38  const IrregularStreamBufferPrefetcherParams *p)
39  : Queued(p),
40  chunkSize(p->chunk_size),
41  prefetchCandidatesPerEntry(p->prefetch_candidates_per_entry),
42  degree(p->degree),
43  trainingUnit(p->training_unit_assoc, p->training_unit_entries,
44  p->training_unit_indexing_policy,
45  p->training_unit_replacement_policy),
46  psAddressMappingCache(p->address_map_cache_assoc,
47  p->address_map_cache_entries,
48  p->ps_address_map_cache_indexing_policy,
49  p->ps_address_map_cache_replacement_policy,
50  AddressMappingEntry(prefetchCandidatesPerEntry,
51  p->num_counter_bits)),
52  spAddressMappingCache(p->address_map_cache_assoc,
53  p->address_map_cache_entries,
54  p->sp_address_map_cache_indexing_policy,
55  p->sp_address_map_cache_replacement_policy,
56  AddressMappingEntry(prefetchCandidatesPerEntry,
57  p->num_counter_bits)),
58  structuralAddressCounter(0)
59 {
61 }
62 
63 void
65  std::vector<AddrPriority> &addresses)
66 {
67  // This prefetcher requires a PC
68  if (!pfi.hasPC()) {
69  return;
70  }
71  bool is_secure = pfi.isSecure();
72  Addr pc = pfi.getPC();
73  Addr addr = blockIndex(pfi.getAddr());
74 
75  // Training, if the entry exists, then we found a correlation between
76  // the entry lastAddress (named as correlated_addr_A) and the address of
77  // the current access (named as correlated_addr_B)
78  TrainingUnitEntry *entry = trainingUnit.findEntry(pc, is_secure);
79  bool correlated_addr_found = false;
80  Addr correlated_addr_A = 0;
81  Addr correlated_addr_B = 0;
82  if (entry != nullptr && entry->lastAddressSecure == is_secure) {
83  trainingUnit.accessEntry(entry);
84  correlated_addr_found = true;
85  correlated_addr_A = entry->lastAddress;
86  correlated_addr_B = addr;
87  } else {
88  entry = trainingUnit.findVictim(pc);
89  assert(entry != nullptr);
90 
91  trainingUnit.insertEntry(pc, is_secure, entry);
92  }
93  // Update the entry
94  entry->lastAddress = addr;
95  entry->lastAddressSecure = is_secure;
96 
97  if (correlated_addr_found) {
98  // If a correlation was found, update the Physical-to-Structural
99  // table accordingly
100  AddressMapping &mapping_A = getPSMapping(correlated_addr_A, is_secure);
101  AddressMapping &mapping_B = getPSMapping(correlated_addr_B, is_secure);
102  if (mapping_A.counter > 0 && mapping_B.counter > 0) {
103  // Entry for A and B
104  if (mapping_B.address == (mapping_A.address + 1)) {
105  mapping_B.counter++;
106  } else {
107  if (mapping_B.counter == 1) {
108  // Counter would hit 0, reassign address while keeping
109  // counter at 1
110  mapping_B.address = mapping_A.address + 1;
111  addStructuralToPhysicalEntry(mapping_B.address, is_secure,
112  correlated_addr_B);
113  } else {
114  mapping_B.counter--;
115  }
116  }
117  } else {
118  if (mapping_A.counter == 0) {
119  // if A is not valid, generate a new structural address
120  mapping_A.counter++;
121  mapping_A.address = structuralAddressCounter;
124  is_secure, correlated_addr_A);
125  }
126  mapping_B.counter.reset();
127  mapping_B.counter++;
128  mapping_B.address = mapping_A.address + 1;
129  // update SP-AMC
130  addStructuralToPhysicalEntry(mapping_B.address, is_secure,
131  correlated_addr_B);
132  }
133  }
134 
135  // Use the PS mapping to predict future accesses using the current address
136  // - Look for the structured address
137  // - if it exists, use it to generate prefetches for the subsequent
138  // addresses in ascending order, as many as indicated by the degree
139  // (given the structured address S, prefetch S+1, S+2, .. up to S+degree)
140  Addr amc_address = addr / prefetchCandidatesPerEntry;
141  Addr map_index = addr % prefetchCandidatesPerEntry;
142  AddressMappingEntry *ps_am = psAddressMappingCache.findEntry(amc_address,
143  is_secure);
144  if (ps_am != nullptr) {
145  AddressMapping &mapping = ps_am->mappings[map_index];
146  if (mapping.counter > 0) {
147  Addr sp_address = mapping.address / prefetchCandidatesPerEntry;
148  Addr sp_index = mapping.address % prefetchCandidatesPerEntry;
149  AddressMappingEntry *sp_am =
150  spAddressMappingCache.findEntry(sp_address, is_secure);
151  if (sp_am == nullptr) {
152  // The entry has been evicted, can not generate prefetches
153  return;
154  }
155  for (unsigned d = 1;
156  d <= degree && (sp_index + d) < prefetchCandidatesPerEntry;
157  d += 1)
158  {
159  AddressMapping &spm = sp_am->mappings[sp_index + d];
160  //generate prefetch
161  if (spm.counter > 0) {
162  Addr pf_addr = spm.address << lBlkSize;
163  addresses.push_back(AddrPriority(pf_addr, 0));
164  }
165  }
166  }
167  }
168 }
169 
172 {
173  Addr amc_address = paddr / prefetchCandidatesPerEntry;
174  Addr map_index = paddr % prefetchCandidatesPerEntry;
175  AddressMappingEntry *ps_entry =
176  psAddressMappingCache.findEntry(amc_address, is_secure);
177  if (ps_entry != nullptr) {
178  // A PS-AMC line already exists
179  psAddressMappingCache.accessEntry(ps_entry);
180  } else {
181  ps_entry = psAddressMappingCache.findVictim(amc_address);
182  assert(ps_entry != nullptr);
183 
184  psAddressMappingCache.insertEntry(amc_address, is_secure, ps_entry);
185  }
186  return ps_entry->mappings[map_index];
187 }
188 
189 void
191  Addr structural_address, bool is_secure, Addr physical_address)
192 {
193  Addr amc_address = structural_address / prefetchCandidatesPerEntry;
194  Addr map_index = structural_address % prefetchCandidatesPerEntry;
195  AddressMappingEntry *sp_entry =
196  spAddressMappingCache.findEntry(amc_address, is_secure);
197  if (sp_entry != nullptr) {
198  spAddressMappingCache.accessEntry(sp_entry);
199  } else {
200  sp_entry = spAddressMappingCache.findVictim(amc_address);
201  assert(sp_entry != nullptr);
202 
203  spAddressMappingCache.insertEntry(amc_address, is_secure, sp_entry);
204  }
205  AddressMapping &mapping = sp_entry->mappings[map_index];
206  mapping.address = physical_address;
207  mapping.counter.reset();
208  mapping.counter++;
209 }
210 
211 } // namespace Prefetcher
212 
214 IrregularStreamBufferPrefetcherParams::create()
215 {
216  return new Prefetcher::IrregularStreamBuffer(this);
217 }
associative_set_impl.hh
Prefetcher::Queued::AddrPriority
std::pair< Addr, int32_t > AddrPriority
Definition: queued.hh:182
Prefetcher::IrregularStreamBuffer::AddressMapping::address
Addr address
Definition: irregular_stream_buffer.hh:72
SatCounter::reset
void reset()
Reset the counter to its initial value.
Definition: sat_counter.hh:286
Prefetcher::IrregularStreamBuffer::degree
const unsigned degree
Number of maximum prefetches requests created when predicting.
Definition: irregular_stream_buffer.hh:57
Prefetcher::Base::PrefetchInfo::getPC
Addr getPC() const
Returns the program counter that generated this request.
Definition: base.hh:135
std::vector
STL vector class.
Definition: stl.hh:37
Prefetcher::IrregularStreamBuffer::TrainingUnitEntry::lastAddress
Addr lastAddress
Definition: irregular_stream_buffer.hh:64
Prefetcher::IrregularStreamBuffer
Definition: irregular_stream_buffer.hh:50
irregular_stream_buffer.hh
Prefetcher::IrregularStreamBuffer::spAddressMappingCache
AssociativeSet< AddressMappingEntry > spAddressMappingCache
Structured-to-Physical mappings table.
Definition: irregular_stream_buffer.hh:104
Prefetcher::IrregularStreamBuffer::IrregularStreamBuffer
IrregularStreamBuffer(const IrregularStreamBufferPrefetcherParams *p)
Definition: irregular_stream_buffer.cc:37
Prefetcher::IrregularStreamBuffer::calculatePrefetch
void calculatePrefetch(const PrefetchInfo &pfi, std::vector< AddrPriority > &addresses) override
Definition: irregular_stream_buffer.cc:64
Prefetcher::IrregularStreamBuffer::structuralAddressCounter
uint64_t structuralAddressCounter
Counter of allocated structural addresses, increased by "chunkSize", each time a new structured addre...
Definition: irregular_stream_buffer.hh:109
Prefetcher::IrregularStreamBuffer::trainingUnit
AssociativeSet< TrainingUnitEntry > trainingUnit
Map of PCs to Training unit entries.
Definition: irregular_stream_buffer.hh:68
ArmISA::d
Bitfield< 9 > d
Definition: miscregs_types.hh:60
Prefetcher::Base::lBlkSize
unsigned lBlkSize
log_2(block size of the parent cache).
Definition: base.hh:265
MipsISA::pc
Bitfield< 4 > pc
Definition: pra_constants.hh:240
Prefetcher::IrregularStreamBuffer::prefetchCandidatesPerEntry
const unsigned prefetchCandidatesPerEntry
Number of prefetch candidates per Physical-to-Structural entry.
Definition: irregular_stream_buffer.hh:55
Prefetcher::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:171
Prefetcher
Copyright (c) 2018 Metempsy Technology Consulting All rights reserved.
Definition: base.hh:78
Prefetcher::IrregularStreamBuffer::AddressMappingEntry
Maps a set of contiguous addresses to another set of (not necessarily contiguos) addresses,...
Definition: irregular_stream_buffer.hh:82
Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
Prefetcher::IrregularStreamBuffer::TrainingUnitEntry
Training Unit Entry datatype, it holds the last accessed address and its secure flag.
Definition: irregular_stream_buffer.hh:63
Prefetcher::Queued
Definition: queued.hh:54
Prefetcher::IrregularStreamBuffer::AddressMapping::counter
SatCounter counter
Definition: irregular_stream_buffer.hh:73
Prefetcher::Base::PrefetchInfo::isSecure
bool isSecure() const
Returns true if the address targets the secure memory space.
Definition: base.hh:126
Prefetcher::Base::blockIndex
Addr blockIndex(Addr a) const
Determine the address of a at block granularity.
Definition: base.cc:175
Prefetcher::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:190
addr
ip6_addr_t addr
Definition: inet.hh:423
Prefetcher::Base::PrefetchInfo
Class containing the information needed by the prefetch to train and generate new prefetch requests.
Definition: base.hh:90
Prefetcher::IrregularStreamBuffer::AddressMapping
Address Mapping entry, holds an address and a confidence counter.
Definition: irregular_stream_buffer.hh:71
Prefetcher::IrregularStreamBuffer::AddressMappingEntry::mappings
std::vector< AddressMapping > mappings
Definition: irregular_stream_buffer.hh:84
MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:323
Prefetcher::IrregularStreamBuffer::chunkSize
const size_t chunkSize
Size in bytes of a temporal stream.
Definition: irregular_stream_buffer.hh:53
Prefetcher::Base::PrefetchInfo::getAddr
Addr getAddr() const
Obtains the address value of this Prefetcher address.
Definition: base.hh:117
isPowerOf2
bool isPowerOf2(const T &n)
Definition: intmath.hh:102
Prefetcher::Base::PrefetchInfo::hasPC
bool hasPC() const
Returns true if the associated program counter is valid.
Definition: base.hh:145
Prefetcher::IrregularStreamBuffer::TrainingUnitEntry::lastAddressSecure
bool lastAddressSecure
Definition: irregular_stream_buffer.hh:65
Prefetcher::IrregularStreamBuffer::psAddressMappingCache
AssociativeSet< AddressMappingEntry > psAddressMappingCache
Physical-to-Structured mappings table.
Definition: irregular_stream_buffer.hh:102

Generated on Wed Sep 30 2020 14:02:12 for gem5 by doxygen 1.8.17