gem5 v24.0.0.0
Loading...
Searching...
No Matches
base.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2013-2014, 2022-2024 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
55namespace gem5
56{
57
58namespace 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) || !pkt->hasData()) {
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
85void
87{
88 if (isFill) {
89 parent.notifyFill(arg);
90 } else {
91 parent.probeNotify(arg, miss);
92 }
93}
94
95void
97{
98 if (info.newData.empty())
99 parent.notifyEvict(info);
100}
101
102Base::Base(const BasePrefetcherParams &p)
103 : ClockedObject(p), listeners(), system(nullptr), probeManager(nullptr),
104 blkSize(p.block_size), lBlkSize(floorLog2(blkSize)),
105 onMiss(p.on_miss), onRead(p.on_read),
106 onWrite(p.on_write), onData(p.on_data), onInst(p.on_inst),
107 requestorId(p.sys->getRequestorId(this)),
108 pageBytes(p.page_bytes),
109 prefetchOnAccess(p.prefetch_on_access),
110 prefetchOnPfHit(p.prefetch_on_pf_hit),
111 useVirtualAddresses(p.use_virtual_addresses),
113 usefulPrefetches(0), mmu(nullptr)
114{
115}
116
117void
118Base::setParentInfo(System *sys, ProbeManager *pm, unsigned blk_size)
119{
120 assert(!system && !probeManager);
121 system = sys;
122 probeManager = pm;
123 // If the cache has a different block size from the system's, save it
124 blkSize = blk_size;
126}
127
129 : statistics::Group(parent),
130 ADD_STAT(demandMshrMisses, statistics::units::Count::get(),
131 "demands not covered by prefetchs"),
132 ADD_STAT(pfIssued, statistics::units::Count::get(),
133 "number of hwpf issued"),
134 ADD_STAT(pfUnused, statistics::units::Count::get(),
135 "number of HardPF blocks evicted w/o reference"),
136 ADD_STAT(pfUseful, statistics::units::Count::get(),
137 "number of useful prefetch"),
138 ADD_STAT(pfUsefulButMiss, statistics::units::Count::get(),
139 "number of hit on prefetch but cache block is not in an usable "
140 "state"),
141 ADD_STAT(accuracy, statistics::units::Count::get(),
142 "accuracy of the prefetcher"),
143 ADD_STAT(coverage, statistics::units::Count::get(),
144 "coverage brought by this prefetcher"),
145 ADD_STAT(pfHitInCache, statistics::units::Count::get(),
146 "number of prefetches hitting in cache"),
147 ADD_STAT(pfHitInMSHR, statistics::units::Count::get(),
148 "number of prefetches hitting in a MSHR"),
149 ADD_STAT(pfHitInWB, statistics::units::Count::get(),
150 "number of prefetches hit in the Write Buffer"),
151 ADD_STAT(pfLate, statistics::units::Count::get(),
152 "number of late prefetches (hitting in cache, MSHR or WB)")
153{
154 using namespace statistics;
155
157
160
163
165}
166
167bool
168Base::observeAccess(const PacketPtr &pkt, bool miss, bool prefetched) const
169{
170 bool fetch = pkt->req->isInstFetch();
171 bool read = pkt->isRead();
172 bool inv = pkt->isInvalidate();
173
174 if (!miss) {
175 if (prefetchOnPfHit)
176 return prefetched;
177 if (!prefetchOnAccess)
178 return false;
179 }
180 if (pkt->req->isUncacheable()) return false;
181 if (fetch && !onInst) return false;
182 if (!fetch && !onData) return false;
183 if (!fetch && read && !onRead) return false;
184 if (!fetch && !read && !onWrite) return false;
185 if (!fetch && !read && inv) return false;
186 if (pkt->cmd == MemCmd::CleanEvict) return false;
187
188 if (onMiss) {
189 return miss;
190 }
191
192 return true;
193}
194
195bool
197{
199}
200
201Addr
203{
204 return a & ~((Addr)blkSize-1);
205}
206
207Addr
209{
210 return a >> lBlkSize;
211}
212
213Addr
215{
216 return roundDown(a, pageBytes);
217}
218
219Addr
221{
222 return a & (pageBytes - 1);
223}
224
225Addr
227{
228 return page + (blockIndex << lBlkSize);
229}
230
231void
233{
234 const PacketPtr pkt = acc.pkt;
235 const CacheAccessor &cache = acc.cache;
236
237 // Don't notify prefetcher on SWPrefetch, cache maintenance
238 // operations or for writes that we are coaslescing.
239 if (pkt->cmd.isSWPrefetch()) return;
240 if (pkt->req->isCacheMaintenance()) return;
241 if (pkt->isCleanEviction()) return;
242 if (pkt->isWrite() && cache.coalesce()) return;
243 if (!pkt->req->hasPaddr()) {
244 panic("Request must have a physical address");
245 }
246
247 bool has_been_prefetched =
248 acc.cache.hasBeenPrefetched(pkt->getAddr(), pkt->isSecure(),
250 if (has_been_prefetched) {
251 usefulPrefetches += 1;
253 if (miss)
254 // This case happens when a demand hits on a prefetched line
255 // that's not in the requested coherency state.
257 }
258
259 // Verify this access type is observed by prefetcher
260 if (observeAccess(pkt, miss, has_been_prefetched)) {
261 if (useVirtualAddresses && pkt->req->hasVaddr()) {
262 PrefetchInfo pfi(pkt, pkt->req->getVaddr(), miss);
263 notify(acc, pfi);
264 } else if (!useVirtualAddresses) {
265 PrefetchInfo pfi(pkt, pkt->req->getPaddr(), miss);
266 notify(acc, pfi);
267 }
268 }
269}
270
271void
273{
279 if (listeners.empty() && probeManager != nullptr) {
280 listeners.push_back(new PrefetchListener(*this, probeManager,
281 "Miss", false, true));
282 listeners.push_back(new PrefetchListener(*this, probeManager,
283 "Fill", true, false));
284 listeners.push_back(new PrefetchListener(*this, probeManager,
285 "Hit", false, false));
286 listeners.push_back(new PrefetchEvictListener(*this, probeManager,
287 "Data Update"));
288 }
289}
290
291void
293{
294 ProbeManager *pm(obj->getProbeManager());
295 listeners.push_back(new PrefetchListener(*this, pm, name));
296}
297
298void
300{
301 fatal_if(mmu != nullptr, "Only one MMU can be registered");
302 mmu = m;
303}
304
305} // namespace prefetch
306} // namespace gem5
const char data[]
Information provided to probes on a cache event.
PacketPtr pkt
Packet that triggered the cache access.
CacheAccessor & cache
Accessor for the cache.
The ClockedObject class extends the SimObject with a clock and accessor functions to relate ticks to ...
bool isSWPrefetch() const
Definition packet.hh:253
virtual std::string name() const
Definition named.hh:47
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition packet.hh:295
bool isRead() const
Definition packet.hh:593
bool isSecure() const
Definition packet.hh:836
Addr getAddr() const
Definition packet.hh:807
bool isCleanEviction() const
Is this packet a clean eviction, including both actual clean evict packets, but also clean writebacks...
Definition packet.hh:1435
bool hasData() const
Definition packet.hh:614
bool isWrite() const
Definition packet.hh:594
RequestPtr req
A pointer to the original request.
Definition packet.hh:377
const T * getConstPtr() const
Definition packet.hh:1234
MemCmd cmd
The command field of the packet.
Definition packet.hh:372
bool isInvalidate() const
Definition packet.hh:609
ProbeManager is a conduit class that lives on each SimObject, and is used to match up probe listeners...
Definition probe.hh:164
Abstract superclass for simulation objects.
void notify(const EvictionInfo &info) override
Definition base.cc:96
Class containing the information needed by the prefetch to train and generate new prefetch requests.
Definition base.hh:111
PrefetchInfo(PacketPtr pkt, Addr addr, bool miss)
Constructs a PrefetchInfo using a PacketPtr.
Definition base.cc:61
bool write
Whether this event comes from a write request.
Definition base.hh:125
uint8_t * data
Pointer to the associated request data.
Definition base.hh:131
void notify(const CacheAccessProbeArg &arg) override
Definition base.cc:86
Base(const BasePrefetcherParams &p)
Definition base.cc:102
const bool useVirtualAddresses
Use Virtual Addresses for prefetching.
Definition base.hh:318
const bool prefetchOnAccess
Prefetch on every access, not just misses.
Definition base.hh:312
const bool onRead
Consult prefetcher on reads?
Definition base.hh:295
unsigned blkSize
The block size of the parent cache.
Definition base.hh:286
uint64_t issuedPrefetches
Total prefetches issued.
Definition base.hh:372
const RequestorID requestorId
Request id for prefetches.
Definition base.hh:307
void addMMU(BaseMMU *mmu)
Add a BaseMMU object to be used whenever a translation is needed.
Definition base.cc:299
void regProbeListeners() override
Register probe points for this object.
Definition base.cc:272
Addr pageAddress(Addr a) const
Determine the address of the page in which a lays.
Definition base.cc:214
ProbeManager * probeManager
Pointer to the parent cache's probe manager.
Definition base.hh:283
const bool onInst
Consult prefetcher on instruction accesses?
Definition base.hh:304
uint64_t usefulPrefetches
Total prefetches that has been useful.
Definition base.hh:374
gem5::prefetch::Base::StatGroup prefetchStats
virtual void setParentInfo(System *sys, ProbeManager *pm, unsigned blk_size)
Definition base.cc:118
virtual void notify(const CacheAccessProbeArg &acc, const PrefetchInfo &pfi)=0
Notify prefetcher of cache access (may be any access or just misses, depending on cache parameters....
Addr pageIthBlockAddress(Addr page, uint32_t i) const
Build the address of the i-th block inside the page.
Definition base.cc:226
Addr pageOffset(Addr a) const
Determine the page-offset of a
Definition base.cc:220
std::vector< ProbeListener * > listeners
Definition base.hh:102
BaseMMU * mmu
Registered mmu for address translations.
Definition base.hh:377
const bool onData
Consult prefetcher on data accesses?
Definition base.hh:301
const bool prefetchOnPfHit
Prefetch on hit on prefetched lines.
Definition base.hh:315
System * system
Pointer to the parent system.
Definition base.hh:280
const bool onWrite
Consult prefetcher on reads?
Definition base.hh:298
unsigned lBlkSize
log_2(block size of the parent cache).
Definition base.hh:289
bool observeAccess(const PacketPtr &pkt, bool miss, bool prefetched) const
Determine if this access should be observed.
Definition base.cc:168
const Addr pageBytes
Definition base.hh:309
Addr blockIndex(Addr a) const
Determine the address of a at block granularity.
Definition base.cc:208
Addr blockAddress(Addr a) const
Determine the address of the block in which a lays.
Definition base.cc:202
void probeNotify(const CacheAccessProbeArg &acc, bool miss)
Process a notification event from the ProbeListener.
Definition base.cc:232
const bool onMiss
Only consult prefetcher on cache misses?
Definition base.hh:292
bool samePage(Addr a, Addr b) const
Determine if addresses are on the same page.
Definition base.cc:196
void addEventProbe(SimObject *obj, const char *name)
Add a SimObject and a probe name to listen events from.
Definition base.cc:292
Derived & flags(Flags _flags)
Set the flags and marks this stat to print at the end of simulation.
Statistics container.
Definition group.hh:93
#define ADD_STAT(n,...)
Convenience macro to add a stat to a statistics group.
Definition group.hh:75
static constexpr std::enable_if_t< std::is_integral_v< T >, int > floorLog2(T x)
Definition intmath.hh:59
static constexpr T roundDown(const T &val, const U &align)
This function is used to align addresses in memory.
Definition intmath.hh:279
#define panic(...)
This implements a cprintf based panic() function.
Definition logging.hh:188
#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
ProbeManager * getProbeManager()
Get the probe manager for this object.
Declares a basic cache interface BaseCache.
Miss and writeback queue declarations.
bool isSecure(ThreadContext *tc)
Definition utility.cc:74
Bitfield< 7 > b
Bitfield< 23, 0 > offset
Definition types.hh:144
Bitfield< 8 > a
Definition misc_types.hh:66
Bitfield< 0 > m
Bitfield< 4 > pc
Bitfield< 0 > p
Bitfield< 23 > inv
Definition misc.hh:843
Bitfield< 3 > addr
Definition types.hh:84
const FlagsType nozero
Don't print if this is zero.
Definition info.hh:67
const FlagsType total
Print the total.
Definition info.hh:59
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition types.hh:147
Provides generic cache lookup functions.
virtual bool coalesce() const =0
Determine if cache is coalescing writes.
virtual bool hasBeenPrefetched(Addr addr, bool is_secure) const =0
Determine if address has been prefetched.
A data contents update is composed of the updated block's address, the old contents,...
std::vector< uint64_t > newData
The new data contents.
statistics::Formula accuracy
Definition base.hh:353
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:352
statistics::Scalar pfIssued
Definition base.hh:344
statistics::Scalar pfUseful
The number of times a HW-prefetch is useful.
Definition base.hh:349
statistics::Scalar pfHitInWB
The number of times a HW-prefetch hits in the Write Buffer (WB).
Definition base.hh:364
statistics::Scalar pfHitInMSHR
The number of times a HW-prefetch hits in a MSHR.
Definition base.hh:360
statistics::Formula pfLate
The number of times a HW-prefetch is late (hit in cache, MSHR, WB).
Definition base.hh:368
statistics::Scalar pfUnused
The number of times a HW-prefetched block is evicted w/o reference.
Definition base.hh:347
statistics::Scalar pfHitInCache
The number of times a HW-prefetch hits in cache.
Definition base.hh:357
statistics::Scalar demandMshrMisses
Definition base.hh:343
StatGroup(statistics::Group *parent)
Definition base.cc:128
statistics::Formula coverage
Definition base.hh:354

Generated on Tue Jun 18 2024 16:24:01 for gem5 by doxygen 1.11.0