gem5  [DEVELOP-FOR-23.0]
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
pif.cc
Go to the documentation of this file.
1 
30 
31 #include <utility>
32 
33 #include "debug/HWPrefetch.hh"
35 #include "params/PIFPrefetcher.hh"
36 
37 namespace gem5
38 {
39 
40 namespace prefetch
41 {
42 
43 PIF::PIF(const PIFPrefetcherParams &p)
44  : Queued(p),
45  precSize(p.prec_spatial_region_bits),
46  succSize(p.succ_spatial_region_bits),
47  maxCompactorEntries(p.compactor_entries),
48  historyBuffer(p.history_buffer_size),
49  index(p.index_assoc, p.index_entries, p.index_indexing_policy,
50  p.index_replacement_policy),
51  streamAddressBuffer(p.stream_address_buffer_entries),
52  listenersPC()
53 {
54 }
55 
57  unsigned int prec_size, unsigned int succ_size)
58 {
59  trigger = addr;
60  prec.resize(prec_size, false);
61  succ.resize(succ_size, false);
62 }
63 
64 Addr
66  unsigned int log_blk_size) const
67 {
68  const Addr target_blk = target >> log_blk_size;
69  const Addr trigger_blk = trigger >> log_blk_size;
70 
71  return target_blk > trigger_blk ?
72  target_blk - trigger_blk : trigger_blk - target_blk;
73 }
74 
75 bool
77  unsigned int log_blk_size, bool update)
78 {
79  Addr blk_distance = distanceFromTrigger(pc, log_blk_size);
80 
81  bool hit = (pc > trigger) ?
82  (succ.size() > blk_distance) : (prec.size() > blk_distance);
83  if (hit && update) {
84  if (pc > trigger) {
85  succ[blk_distance] = true;
86  } else if (pc < trigger) {
87  prec[blk_distance] = true;
88  }
89  }
90  return hit;
91 }
92 
93 bool
95  unsigned int log_blk_size) const
96 {
97  Addr blk_distance = distanceFromTrigger(target, log_blk_size);
98  bool hit = false;
99  if (target > trigger) {
100  hit = blk_distance < succ.size() && succ[blk_distance];
101  } else if (target < trigger) {
102  hit = blk_distance < prec.size() && prec[blk_distance];
103  } else {
104  hit = true;
105  }
106  return hit;
107 }
108 
109 void
111  std::vector<AddrPriority> &addresses) const
112 {
113  // Calculate the addresses of the instruction blocks that are encoded
114  // by the bit vector and issue prefetch requests for these addresses.
115  // Predictions are made by traversing the bit vector from left to right
116  // as this typically predicts the accesses in the order they will be
117  // issued in the core.
118  const Addr trigger_blk = trigger >> log_blk_size;
119  for (int i = prec.size()-1; i >= 0; i--) {
120  // Address from the preceding blocks to issue a prefetch
121  if (prec[i]) {
122  const Addr prec_addr = (trigger_blk - (i+1)) << log_blk_size;
123  addresses.push_back(AddrPriority(prec_addr, 0));
124  }
125  }
126  for (int i = 0; i < succ.size(); i++) {
127  // Address from the succeding blocks to issue a prefetch
128  if (succ[i]) {
129  const Addr succ_addr = (trigger_blk + (i+1)) << log_blk_size;
130  addresses.push_back(AddrPriority(succ_addr, 0));
131  }
132  }
133 }
134 
135 void
137 {
138  // First access to the prefetcher
139  if (temporalCompactor.size() == 0) {
142  } else {
143  // If the PC of the instruction retired is in the same spatial region
144  // than the last trigger address, update the bit vectors based on the
145  // distance between them
147  // If the PC of the instruction retired is outside the latest spatial
148  // region, check if it matches in any of the regions in the temporal
149  // compactor and update it to the MRU position
150  } else {
151  bool is_in_temporal_compactor = false;
152 
153  // Check if the PC is in the temporal compactor
154  for (auto it = temporalCompactor.begin();
155  it != temporalCompactor.end(); it++)
156  {
157  if (it->inSameSpatialRegion(pc, lBlkSize, false)) {
158  spatialCompactor = (*it);
159  temporalCompactor.erase(it);
160  is_in_temporal_compactor = true;
161  break;
162  }
163  }
164 
165  if (temporalCompactor.size() == maxCompactorEntries) {
166  temporalCompactor.pop_front(); // Discard the LRU entry
167  }
168 
170 
171  // If the compactor entry is neither the spatial or can't be
172  // found in the temporal compactor, reset the spatial compactor
173  // updating the trigger address and resetting the vector bits
174  if (!is_in_temporal_compactor) {
175  // Insert the spatial entry into the history buffer and update
176  // the 'iterator' table to point to the new entry
178 
179  IndexEntry *idx_entry =
180  index.findEntry(spatialCompactor.trigger, false);
181  if (idx_entry != nullptr) {
182  index.accessEntry(idx_entry);
183  } else {
184  idx_entry = index.findVictim(spatialCompactor.trigger);
185  assert(idx_entry != nullptr);
186  index.insertEntry(spatialCompactor.trigger, false,
187  idx_entry);
188  }
189  idx_entry->historyIt =
191 
192  // Reset the spatial compactor fields with the new address
194  }
195  }
196  }
197 }
198 
199 void
201  std::vector<AddrPriority> &addresses)
202 {
203  if (!pfi.hasPC()) {
204  return;
205  }
206 
207  const Addr pc = pfi.getPC();
208 
209  // First check if the access has been prefetched, this is done by
210  // comparing the access against the active Stream Address Buffers
211  for (auto &sabEntry : streamAddressBuffer) {
212  if (sabEntry->hasAddress(pc, lBlkSize)) {
213  sabEntry++;
214  sabEntry->getPredictedAddresses(lBlkSize, addresses);
215  // We are done
216  return;
217  }
218  }
219 
220  // Check if a valid entry in the 'index' table is found and allocate a new
221  // active prediction stream
222  IndexEntry *idx_entry = index.findEntry(pc, /* unused */ false);
223 
224  if (idx_entry != nullptr) {
225  index.accessEntry(idx_entry);
226  // Trigger address from the 'index' table and index to the history
227  // buffer
228  auto entry = idx_entry->historyIt;
229 
230  // Track the block in the Stream Address Buffer
231  streamAddressBuffer.push_back(entry);
232 
233  entry->getPredictedAddresses(lBlkSize, addresses);
234  }
235 }
236 
237 void
239 {
240  parent.notifyRetiredInst(pc);
241 }
242 
243 void
245 {
246  ProbeManager *pm(obj->getProbeManager());
247  listenersPC.push_back(new PrefetchListenerPC(*this, pm, name));
248 }
249 
250 } // namespace prefetch
251 } // namespace gem5
associative_set_impl.hh
gem5::prefetch::PIF::CompactorEntry::trigger
Addr trigger
Definition: pif.hh:80
gem5::prefetch::Queued::AddrPriority
std::pair< Addr, int32_t > AddrPriority
Definition: queued.hh:190
gem5::MipsISA::index
Bitfield< 30, 0 > index
Definition: pra_constants.hh:47
gem5::prefetch::PIF::PrefetchListenerPC
Probe Listener to handle probe events from the CPU.
Definition: pif.hh:164
gem5::prefetch::PIF::PrefetchListenerPC::notify
void notify(const Addr &pc) override
Definition: pif.cc:238
gem5::prefetch::PIF::IndexEntry::historyIt
HistoryBuffer::iterator historyIt
Definition: pif.hh:139
std::vector
STL vector class.
Definition: stl.hh:37
gem5::CircularQueue::push_back
void push_back(typename std::vector< T >::value_type val)
Pushes an element at the end of the queue.
Definition: circular_queue.hh:502
gem5::prefetch::PIF::maxCompactorEntries
const unsigned int maxCompactorEntries
Number of entries used for the temporal compactor.
Definition: pif.hh:62
gem5::ArmISA::i
Bitfield< 7 > i
Definition: misc_types.hh:67
gem5::prefetch::PIF::spatialCompactor
CompactorEntry spatialCompactor
Definition: pif.hh:127
gem5::Clocked::update
void update() const
Align cycle and tick to the next clock edge if not already done.
Definition: clocked_object.hh:79
gem5::prefetch::PIF::notifyRetiredInst
void notifyRetiredInst(const Addr pc)
Updates the prefetcher structures upon an instruction retired.
Definition: pif.cc:136
gem5::prefetch::PIF::CompactorEntry::hasAddress
bool hasAddress(Addr target, unsigned int log_blk_size) const
Checks if the provided address is contained in this spatial region and if its corresponding bit vecto...
Definition: pif.cc:94
gem5::prefetch::PIF::CompactorEntry::succ
std::vector< bool > succ
Definition: pif.hh:82
gem5::prefetch::Base::PrefetchInfo::getPC
Addr getPC() const
Returns the program counter that generated this request.
Definition: base.hh:142
gem5::CircularQueue::tail
size_t tail() const
Definition: circular_queue.hh:456
gem5::Named::name
virtual std::string name() const
Definition: named.hh:47
gem5::VegaISA::p
Bitfield< 54 > p
Definition: pagetable.hh:70
gem5::prefetch::PIF::CompactorEntry::distanceFromTrigger
Addr distanceFromTrigger(Addr addr, unsigned int log_blk_size) const
Computes the distance, in cache blocks, from an address to the trigger of the entry.
Definition: pif.cc:65
gem5::prefetch::PIF::succSize
const unsigned int succSize
Definition: pif.hh:60
gem5::prefetch::PIF::CompactorEntry::CompactorEntry
CompactorEntry()
Definition: pif.hh:83
gem5::SimObject
Abstract superclass for simulation objects.
Definition: sim_object.hh:146
gem5::Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
gem5::RiscvISA::succ
Bitfield< 23, 20 > succ
Definition: types.hh:90
gem5::ProbeManager
ProbeManager is a conduit class that lives on each SimObject, and is used to match up probe listeners...
Definition: probe.hh:162
pif.hh
gem5::prefetch::Queued
Definition: queued.hh:59
gem5::prefetch::PIF::historyBuffer
HistoryBuffer historyBuffer
Definition: pif.hh:135
gem5::prefetch::PIF::precSize
const unsigned int precSize
Number of preceding and subsequent spatial addresses to compact.
Definition: pif.hh:59
gem5::SimObject::getProbeManager
ProbeManager * getProbeManager()
Get the probe manager for this object.
Definition: sim_object.cc:117
gem5::prefetch::Base::lBlkSize
unsigned lBlkSize
log_2(block size of the parent cache).
Definition: base.hh:272
gem5::prefetch::PIF::calculatePrefetch
void calculatePrefetch(const PrefetchInfo &pfi, std::vector< AddrPriority > &addresses)
Definition: pif.cc:200
gem5::prefetch::PIF::addEventProbeRetiredInsts
void addEventProbeRetiredInsts(SimObject *obj, const char *name)
Add a SimObject and a probe name to monitor the retired instructions.
Definition: pif.cc:244
gem5::MipsISA::pc
Bitfield< 4 > pc
Definition: pra_constants.hh:243
gem5::prefetch::PIF::CompactorEntry::getPredictedAddresses
void getPredictedAddresses(unsigned int log_blk_size, std::vector< AddrPriority > &addresses) const
Fills the provided vector with the predicted addresses using the recorded bit vectors of the entry.
Definition: pif.cc:110
gem5::prefetch::PIF::CompactorEntry::prec
std::vector< bool > prec
Definition: pif.hh:81
gem5::prefetch::PIF::temporalCompactor
std::deque< CompactorEntry > temporalCompactor
Definition: pif.hh:128
gem5::prefetch::PIF::CompactorEntry
The compactor tracks retired instructions addresses, leveraging the spatial and temporal locality amo...
Definition: pif.hh:78
gem5::prefetch::PIF::streamAddressBuffer
CircularQueue< HistoryBuffer::iterator > streamAddressBuffer
A Stream Address Buffer (SAB) tracks a window of consecutive spatial regions.
Definition: pif.hh:153
gem5::prefetch::PIF::PIF
PIF(const PIFPrefetcherParams &p)
Definition: pif.cc:43
gem5::CircularQueue::getIterator
iterator getIterator(size_t idx)
Return an iterator to an index in the queue.
Definition: circular_queue.hh:592
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: gpu_translation_state.hh:37
gem5::prefetch::PIF::index
AssociativeSet< IndexEntry > index
The index table is a small cache-like structure that facilitates fast search of the history buffer.
Definition: pif.hh:145
gem5::prefetch::PIF::CompactorEntry::inSameSpatialRegion
bool inSameSpatialRegion(Addr addr, unsigned int log_blk_size, bool update)
Checks if a given address is in the same defined spatial region as the compactor entry.
Definition: pif.cc:76
gem5::prefetch::Base::PrefetchInfo
Class containing the information needed by the prefetch to train and generate new prefetch requests.
Definition: base.hh:96
gem5::prefetch::PIF::listenersPC
std::vector< PrefetchListenerPC * > listenersPC
Array of probe listeners.
Definition: pif.hh:177
gem5::X86ISA::trigger
Bitfield< 21 > trigger
Definition: intmessage.hh:52
gem5::prefetch::PIF::IndexEntry
Definition: pif.hh:137
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