gem5  [DEVELOP-FOR-23.0]
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
base.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013-2014 ARM Limited
3  * All rights reserved.
4  *
5  * The license below extends only to copyright in the software and shall
6  * not be construed as granting a license to any other intellectual
7  * property including but not limited to intellectual property relating
8  * to a hardware implementation of the functionality of the software
9  * licensed hereunder. You may use the software subject to the license
10  * terms below provided that you ensure that this notice is replicated
11  * unmodified and in its entirety in all distributions of the software,
12  * modified or unmodified, in source code or in binary form.
13  *
14  * Copyright (c) 2005 The Regents of The University of Michigan
15  * All rights reserved.
16  *
17  * Redistribution and use in source and binary forms, with or without
18  * modification, are permitted provided that the following conditions are
19  * met: redistributions of source code must retain the above copyright
20  * notice, this list of conditions and the following disclaimer;
21  * redistributions in binary form must reproduce the above copyright
22  * notice, this list of conditions and the following disclaimer in the
23  * documentation and/or other materials provided with the distribution;
24  * neither the name of the copyright holders nor the names of its
25  * contributors may be used to endorse or promote products derived from
26  * this software without specific prior written permission.
27  *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39  */
40 
47 
48 #include <cassert>
49 
50 #include "base/intmath.hh"
51 #include "mem/cache/base.hh"
52 #include "params/BasePrefetcher.hh"
53 #include "sim/system.hh"
54 
55 namespace gem5
56 {
57 
58 namespace prefetch
59 {
60 
62  : address(addr), pc(pkt->req->hasPC() ? pkt->req->getPC() : 0),
63  requestorId(pkt->req->requestorId()), validPC(pkt->req->hasPC()),
64  secure(pkt->isSecure()), size(pkt->req->getSize()), write(pkt->isWrite()),
65  paddress(pkt->req->getPaddr()), cacheMiss(miss)
66 {
67  unsigned int req_size = pkt->req->getSize();
68  if (!write && miss) {
69  data = nullptr;
70  } else {
71  data = new uint8_t[req_size];
72  Addr offset = pkt->req->getPaddr() - pkt->getAddr();
73  std::memcpy(data, &(pkt->getConstPtr<uint8_t>()[offset]), req_size);
74  }
75 }
76 
78  : address(addr), pc(pfi.pc), requestorId(pfi.requestorId),
79  validPC(pfi.validPC), secure(pfi.secure), size(pfi.size),
80  write(pfi.write), paddress(pfi.paddress), cacheMiss(pfi.cacheMiss),
81  data(nullptr)
82 {
83 }
84 
85 void
87 {
88  if (isFill) {
89  parent.notifyFill(pkt);
90  } else {
91  parent.probeNotify(pkt, miss);
92  }
93 }
94 
95 Base::Base(const BasePrefetcherParams &p)
96  : ClockedObject(p), listeners(), cache(nullptr), blkSize(p.block_size),
97  lBlkSize(floorLog2(blkSize)), onMiss(p.on_miss), onRead(p.on_read),
98  onWrite(p.on_write), onData(p.on_data), onInst(p.on_inst),
99  requestorId(p.sys->getRequestorId(this)),
100  pageBytes(p.page_bytes),
101  prefetchOnAccess(p.prefetch_on_access),
102  prefetchOnPfHit(p.prefetch_on_pf_hit),
103  useVirtualAddresses(p.use_virtual_addresses),
105  usefulPrefetches(0), mmu(nullptr)
106 {
107 }
108 
109 void
111 {
112  assert(!cache);
113  cache = _cache;
114 
115  // If the cache has a different block size from the system's, save it
118 }
119 
121  : statistics::Group(parent),
122  ADD_STAT(demandMshrMisses, statistics::units::Count::get(),
123  "demands not covered by prefetchs"),
124  ADD_STAT(pfIssued, statistics::units::Count::get(),
125  "number of hwpf issued"),
126  ADD_STAT(pfUnused, statistics::units::Count::get(),
127  "number of HardPF blocks evicted w/o reference"),
128  ADD_STAT(pfUseful, statistics::units::Count::get(),
129  "number of useful prefetch"),
130  ADD_STAT(pfUsefulButMiss, statistics::units::Count::get(),
131  "number of hit on prefetch but cache block is not in an usable "
132  "state"),
133  ADD_STAT(accuracy, statistics::units::Count::get(),
134  "accuracy of the prefetcher"),
135  ADD_STAT(coverage, statistics::units::Count::get(),
136  "coverage brought by this prefetcher"),
137  ADD_STAT(pfHitInCache, statistics::units::Count::get(),
138  "number of prefetches hitting in cache"),
139  ADD_STAT(pfHitInMSHR, statistics::units::Count::get(),
140  "number of prefetches hitting in a MSHR"),
141  ADD_STAT(pfHitInWB, statistics::units::Count::get(),
142  "number of prefetches hit in the Write Buffer"),
143  ADD_STAT(pfLate, statistics::units::Count::get(),
144  "number of late prefetches (hitting in cache, MSHR or WB)")
145 {
146  using namespace statistics;
147 
149 
152 
155 
157 }
158 
159 bool
160 Base::observeAccess(const PacketPtr &pkt, bool miss) const
161 {
162  bool fetch = pkt->req->isInstFetch();
163  bool read = pkt->isRead();
164  bool inv = pkt->isInvalidate();
165 
166  if (!miss) {
167  if (prefetchOnPfHit)
168  return hasBeenPrefetched(pkt->getAddr(), pkt->isSecure());
169  if (!prefetchOnAccess)
170  return false;
171  }
172  if (pkt->req->isUncacheable()) return false;
173  if (fetch && !onInst) return false;
174  if (!fetch && !onData) return false;
175  if (!fetch && read && !onRead) return false;
176  if (!fetch && !read && !onWrite) return false;
177  if (!fetch && !read && inv) return false;
178  if (pkt->cmd == MemCmd::CleanEvict) return false;
179 
180  if (onMiss) {
181  return miss;
182  }
183 
184  return true;
185 }
186 
187 bool
188 Base::inCache(Addr addr, bool is_secure) const
189 {
190  return cache->inCache(addr, is_secure);
191 }
192 
193 bool
194 Base::inMissQueue(Addr addr, bool is_secure) const
195 {
196  return cache->inMissQueue(addr, is_secure);
197 }
198 
199 bool
200 Base::hasBeenPrefetched(Addr addr, bool is_secure) const
201 {
202  return cache->hasBeenPrefetched(addr, is_secure);
203 }
204 
205 bool
207 {
208  return roundDown(a, pageBytes) == roundDown(b, pageBytes);
209 }
210 
211 Addr
213 {
214  return a & ~((Addr)blkSize-1);
215 }
216 
217 Addr
219 {
220  return a >> lBlkSize;
221 }
222 
223 Addr
225 {
226  return roundDown(a, pageBytes);
227 }
228 
229 Addr
231 {
232  return a & (pageBytes - 1);
233 }
234 
235 Addr
237 {
238  return page + (blockIndex << lBlkSize);
239 }
240 
241 void
242 Base::probeNotify(const PacketPtr &pkt, bool miss)
243 {
244  // Don't notify prefetcher on SWPrefetch, cache maintenance
245  // operations or for writes that we are coaslescing.
246  if (pkt->cmd.isSWPrefetch()) return;
247  if (pkt->req->isCacheMaintenance()) return;
248  if (pkt->isWrite() && cache != nullptr && cache->coalesce()) return;
249  if (!pkt->req->hasPaddr()) {
250  panic("Request must have a physical address");
251  }
252 
253  if (hasBeenPrefetched(pkt->getAddr(), pkt->isSecure())) {
254  usefulPrefetches += 1;
256  if (miss)
257  // This case happens when a demand hits on a prefetched line
258  // that's not in the requested coherency state.
260  }
261 
262  // Verify this access type is observed by prefetcher
263  if (observeAccess(pkt, miss)) {
264  if (useVirtualAddresses && pkt->req->hasVaddr()) {
265  PrefetchInfo pfi(pkt, pkt->req->getVaddr(), miss);
266  notify(pkt, pfi);
267  } else if (!useVirtualAddresses) {
268  PrefetchInfo pfi(pkt, pkt->req->getPaddr(), miss);
269  notify(pkt, pfi);
270  }
271  }
272 }
273 
274 void
276 {
282  if (listeners.empty() && cache != nullptr) {
284  listeners.push_back(new PrefetchListener(*this, pm, "Miss", false,
285  true));
286  listeners.push_back(new PrefetchListener(*this, pm, "Fill", true,
287  false));
288  listeners.push_back(new PrefetchListener(*this, pm, "Hit", false,
289  false));
290  }
291 }
292 
293 void
295 {
296  ProbeManager *pm(obj->getProbeManager());
297  listeners.push_back(new PrefetchListener(*this, pm, name));
298 }
299 
300 void
302 {
303  fatal_if(mmu != nullptr, "Only one MMU can be registered");
304  mmu = m;
305 }
306 
307 } // namespace prefetch
308 } // namespace gem5
gem5::prefetch::Base::StatGroup::demandMshrMisses
statistics::Scalar demandMshrMisses
Definition: base.hh:333
gem5::prefetch::Base::prefetchOnAccess
const bool prefetchOnAccess
Prefetch on every access, not just misses.
Definition: base.hh:295
gem5::prefetch::Base::StatGroup::pfUsefulButMiss
statistics::Scalar pfUsefulButMiss
The number of times there is a hit on prefetch but cache block is not in an usable state.
Definition: base.hh:342
gem5::prefetch::Base::blockIndex
Addr blockIndex(Addr a) const
Determine the address of a at block granularity.
Definition: base.cc:218
gem5::prefetch::Base::useVirtualAddresses
const bool useVirtualAddresses
Use Virtual Addresses for prefetching.
Definition: base.hh:301
gem5::prefetch::Base::pageOffset
Addr pageOffset(Addr a) const
Determine the page-offset of a
Definition: base.cc:230
gem5::prefetch::Base::addMMU
void addMMU(BaseMMU *mmu)
Add a BaseMMU object to be used whenever a translation is needed.
Definition: base.cc:301
gem5::prefetch::Base::hasBeenPrefetched
bool hasBeenPrefetched(Addr addr, bool is_secure) const
Definition: base.cc:200
base.hh
gem5::prefetch::Base::PrefetchInfo::write
bool write
Whether this event comes from a write request.
Definition: base.hh:111
system.hh
gem5::VegaISA::m
m
Definition: pagetable.hh:52
gem5::MemCmd::CleanEvict
@ CleanEvict
Definition: packet.hh:96
gem5::MipsISA::misc_reg::Count
@ Count
Definition: misc.hh:94
data
const char data[]
Definition: circlebuf.test.cc:48
gem5::prefetch::Base::StatGroup::StatGroup
StatGroup(statistics::Group *parent)
Definition: base.cc:120
gem5::prefetch::Base::setCache
virtual void setCache(BaseCache *_cache)
Definition: base.cc:110
gem5::prefetch::Base::StatGroup::pfIssued
statistics::Scalar pfIssued
Definition: base.hh:334
gem5::Packet::req
RequestPtr req
A pointer to the original request.
Definition: packet.hh:377
gem5::BaseCache::coalesce
bool coalesce() const
Checks if the cache is coalescing writes.
Definition: base.cc:1808
gem5::prefetch::Base::PrefetchInfo::data
uint8_t * data
Pointer to the associated request data.
Definition: base.hh:117
gem5::statistics::nozero
const FlagsType nozero
Don't print if this is zero.
Definition: info.hh:67
gem5::prefetch::Base::addEventProbe
void addEventProbe(SimObject *obj, const char *name)
Add a SimObject and a probe name to listen events from.
Definition: base.cc:294
gem5::prefetch::Base::listeners
std::vector< PrefetchListener * > listeners
Definition: base.hh:88
gem5::floorLog2
static constexpr std::enable_if_t< std::is_integral_v< T >, int > floorLog2(T x)
Definition: intmath.hh:59
gem5::ArmISA::a
Bitfield< 8 > a
Definition: misc_types.hh:66
gem5::Packet::isWrite
bool isWrite() const
Definition: packet.hh:594
gem5::prefetch::Base::pageAddress
Addr pageAddress(Addr a) const
Determine the address of the page in which a lays.
Definition: base.cc:224
gem5::Packet::isSecure
bool isSecure() const
Definition: packet.hh:836
gem5::prefetch::Base::inMissQueue
bool inMissQueue(Addr addr, bool is_secure) const
Determine if address is in cache miss queue.
Definition: base.cc:194
gem5::prefetch::Base::Base
Base(const BasePrefetcherParams &p)
Definition: base.cc:95
gem5::prefetch::Base::blockAddress
Addr blockAddress(Addr a) const
Determine the address of the block in which a lays.
Definition: base.cc:212
gem5::prefetch::Base::requestorId
const RequestorID requestorId
Request id for prefetches.
Definition: base.hh:290
gem5::prefetch::Base::onRead
const bool onRead
Consult prefetcher on reads?
Definition: base.hh:278
gem5::prefetch::Base::mmu
BaseMMU * mmu
Registered mmu for address translations.
Definition: base.hh:367
gem5::BaseMMU
Definition: mmu.hh:53
gem5::prefetch::Base::StatGroup::pfHitInWB
statistics::Scalar pfHitInWB
The number of times a HW-prefetch hits in the Write Buffer (WB).
Definition: base.hh:354
gem5::prefetch::Base::observeAccess
bool observeAccess(const PacketPtr &pkt, bool miss) const
Determine if this access should be observed.
Definition: base.cc:160
gem5::prefetch::Base::onInst
const bool onInst
Consult prefetcher on instruction accesses?
Definition: base.hh:287
gem5::prefetch::Base::StatGroup::pfUnused
statistics::Scalar pfUnused
The number of times a HW-prefetched block is evicted w/o reference.
Definition: base.hh:337
gem5::prefetch::Base::samePage
bool samePage(Addr a, Addr b) const
Determine if addresses are on the same page.
Definition: base.cc:206
gem5::Packet::isRead
bool isRead() const
Definition: packet.hh:593
gem5::prefetch::Base::onMiss
const bool onMiss
Only consult prefetcher on cache misses?
Definition: base.hh:275
base.hh
gem5::ArmISA::b
Bitfield< 7 > b
Definition: misc_types.hh:438
gem5::prefetch::Base::pageBytes
const Addr pageBytes
Definition: base.hh:292
gem5::Named::name
virtual std::string name() const
Definition: named.hh:47
gem5::VegaISA::p
Bitfield< 54 > p
Definition: pagetable.hh:70
gem5::BaseCache
A basic cache interface.
Definition: base.hh:94
ADD_STAT
#define ADD_STAT(n,...)
Convenience macro to add a stat to a statistics group.
Definition: group.hh:75
gem5::Packet
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:294
gem5::prefetch::Base::usefulPrefetches
uint64_t usefulPrefetches
Total prefetches that has been useful.
Definition: base.hh:364
gem5::BaseCache::hasBeenPrefetched
bool hasBeenPrefetched(Addr addr, bool is_secure) const
Definition: base.hh:1279
gem5::prefetch::Base::PrefetchInfo::PrefetchInfo
PrefetchInfo(PacketPtr pkt, Addr addr, bool miss)
Constructs a PrefetchInfo using a PacketPtr.
Definition: base.cc:61
gem5::prefetch::Base::StatGroup::pfLate
statistics::Formula pfLate
The number of times a HW-prefetch is late (hit in cache, MSHR, WB).
Definition: base.hh:358
gem5::Packet::getConstPtr
const T * getConstPtr() const
Definition: packet.hh:1234
gem5::ArmISA::offset
Bitfield< 23, 0 > offset
Definition: types.hh:144
gem5::prefetch::Base::probeNotify
void probeNotify(const PacketPtr &pkt, bool miss)
Process a notification event from the ProbeListener.
Definition: base.cc:242
gem5::prefetch::Base::onData
const bool onData
Consult prefetcher on data accesses?
Definition: base.hh:284
gem5::prefetch::Base::StatGroup::coverage
statistics::Formula coverage
Definition: base.hh:344
gem5::roundDown
static constexpr T roundDown(const T &val, const U &align)
This function is used to align addresses in memory.
Definition: intmath.hh:279
gem5::SimObject
Abstract superclass for simulation objects.
Definition: sim_object.hh:146
gem5::Packet::cmd
MemCmd cmd
The command field of the packet.
Definition: packet.hh:372
gem5::Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
gem5::BaseCache::getBlockSize
unsigned getBlockSize() const
Query block size of a cache.
Definition: base.hh:1162
gem5::BaseCache::inMissQueue
bool inMissQueue(Addr addr, bool is_secure) const
Definition: base.hh:1288
gem5::ArmISA::isSecure
bool isSecure(ThreadContext *tc)
Definition: utility.cc:74
gem5::ClockedObject
The ClockedObject class extends the SimObject with a clock and accessor functions to relate ticks to ...
Definition: clocked_object.hh:234
gem5::ProbeManager
ProbeManager is a conduit class that lives on each SimObject, and is used to match up probe listeners...
Definition: probe.hh:162
gem5::SimObject::getProbeManager
ProbeManager * getProbeManager()
Get the probe manager for this object.
Definition: sim_object.cc:117
gem5::prefetch::Base::prefetchStats
gem5::prefetch::Base::StatGroup prefetchStats
gem5::prefetch::Base::PrefetchListener::notify
void notify(const PacketPtr &pkt) override
Definition: base.cc:86
gem5::prefetch::Base::issuedPrefetches
uint64_t issuedPrefetches
Total prefetches issued.
Definition: base.hh:362
gem5::prefetch::Base::lBlkSize
unsigned lBlkSize
log_2(block size of the parent cache).
Definition: base.hh:272
gem5::prefetch::Base::regProbeListeners
void regProbeListeners() override
Register probe points for this object.
Definition: base.cc:275
gem5::MemCmd::isSWPrefetch
bool isSWPrefetch() const
Definition: packet.hh:253
gem5::prefetch::Base::StatGroup::pfUseful
statistics::Scalar pfUseful
The number of times a HW-prefetch is useful.
Definition: base.hh:339
gem5::X86ISA::inv
Bitfield< 23 > inv
Definition: misc.hh:815
gem5::MipsISA::pc
Bitfield< 4 > pc
Definition: pra_constants.hh:243
gem5::prefetch::Base::StatGroup::accuracy
statistics::Formula accuracy
Definition: base.hh:343
gem5::statistics::Group
Statistics container.
Definition: group.hh:92
gem5::prefetch::Base::cache
BaseCache * cache
Pointr to the parent cache.
Definition: base.hh:266
gem5::prefetch::Base::prefetchOnPfHit
const bool prefetchOnPfHit
Prefetch on hit on prefetched lines.
Definition: base.hh:298
gem5::BaseCache::inCache
bool inCache(Addr addr, bool is_secure) const
Definition: base.hh:1275
gem5::prefetch::Base::blkSize
unsigned blkSize
The block size of the parent cache.
Definition: base.hh:269
gem5::statistics::DataWrap::flags
Derived & flags(Flags _flags)
Set the flags and marks this stat to print at the end of simulation.
Definition: statistics.hh:357
gem5::prefetch::Base::inCache
bool inCache(Addr addr, bool is_secure) const
Determine if address is in cache.
Definition: base.cc:188
gem5::Packet::getAddr
Addr getAddr() const
Definition: packet.hh:807
intmath.hh
gem5::prefetch::Base::pageIthBlockAddress
Addr pageIthBlockAddress(Addr page, uint32_t i) const
Build the address of the i-th block inside the page.
Definition: base.cc:236
fatal_if
#define fatal_if(cond,...)
Conditional fatal macro that checks the supplied condition and only causes a fatal error if the condi...
Definition: logging.hh:236
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: gpu_translation_state.hh:37
gem5::statistics::total
const FlagsType total
Print the total.
Definition: info.hh:59
gem5::prefetch::Base::StatGroup::pfHitInMSHR
statistics::Scalar pfHitInMSHR
The number of times a HW-prefetch hits in a MSHR.
Definition: base.hh:350
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::Base::onWrite
const bool onWrite
Consult prefetcher on reads?
Definition: base.hh:281
gem5::prefetch::Base::StatGroup::pfHitInCache
statistics::Scalar pfHitInCache
The number of times a HW-prefetch hits in cache.
Definition: base.hh:347
gem5::Packet::isInvalidate
bool isInvalidate() const
Definition: packet.hh:609
panic
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:188
gem5::X86ISA::addr
Bitfield< 3 > addr
Definition: types.hh:84
gem5::prefetch::Base::PrefetchListener
Definition: base.hh:73
gem5::prefetch::Base::notify
virtual void notify(const PacketPtr &pkt, const PrefetchInfo &pfi)=0
Notify prefetcher of cache access (may be any access or just misses, depending on cache parameters....

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