gem5 v23.0.0.1
Loading...
Searching...
No Matches
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
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) {
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(pkt);
90 } else {
91 parent.probeNotify(pkt, miss);
92 }
93}
94
95Base::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
109void
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
159bool
160Base::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
187bool
188Base::inCache(Addr addr, bool is_secure) const
189{
190 return cache->inCache(addr, is_secure);
191}
192
193bool
194Base::inMissQueue(Addr addr, bool is_secure) const
195{
196 return cache->inMissQueue(addr, is_secure);
197}
198
199bool
200Base::hasBeenPrefetched(Addr addr, bool is_secure) const
201{
202 return cache->hasBeenPrefetched(addr, is_secure);
203}
204
205bool
207{
209}
210
211Addr
213{
214 return a & ~((Addr)blkSize-1);
215}
216
217Addr
219{
220 return a >> lBlkSize;
221}
222
223Addr
225{
226 return roundDown(a, pageBytes);
227}
228
229Addr
231{
232 return a & (pageBytes - 1);
233}
234
235Addr
237{
238 return page + (blockIndex << lBlkSize);
239}
240
241void
242Base::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
274void
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
293void
295{
296 ProbeManager *pm(obj->getProbeManager());
297 listeners.push_back(new PrefetchListener(*this, pm, name));
298}
299
300void
302{
303 fatal_if(mmu != nullptr, "Only one MMU can be registered");
304 mmu = m;
305}
306
307} // namespace prefetch
308} // namespace gem5
const char data[]
A basic cache interface.
Definition base.hh:95
bool inMissQueue(Addr addr, bool is_secure) const
Definition base.hh:1288
bool hasBeenPrefetched(Addr addr, bool is_secure) const
Definition base.hh:1279
unsigned getBlockSize() const
Query block size of a cache.
Definition base.hh:1162
bool inCache(Addr addr, bool is_secure) const
Definition base.hh:1275
bool coalesce() const
Checks if the cache is coalescing writes.
Definition base.cc:1808
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 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:163
Abstract superclass for simulation objects.
Class containing the information needed by the prefetch to train and generate new prefetch requests.
Definition base.hh:97
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:111
uint8_t * data
Pointer to the associated request data.
Definition base.hh:117
void notify(const PacketPtr &pkt) override
Definition base.cc:86
Base(const BasePrefetcherParams &p)
Definition base.cc:95
const bool useVirtualAddresses
Use Virtual Addresses for prefetching.
Definition base.hh:301
const bool prefetchOnAccess
Prefetch on every access, not just misses.
Definition base.hh:295
const bool onRead
Consult prefetcher on reads?
Definition base.hh:278
unsigned blkSize
The block size of the parent cache.
Definition base.hh:269
uint64_t issuedPrefetches
Total prefetches issued.
Definition base.hh:362
bool observeAccess(const PacketPtr &pkt, bool miss) const
Determine if this access should be observed.
Definition base.cc:160
bool inCache(Addr addr, bool is_secure) const
Determine if address is in cache.
Definition base.cc:188
void addEventProbe(SimObject *obj, const char *name)
Add a SimObject and a probe name to listen events from.
Definition base.cc:294
const RequestorID requestorId
Request id for prefetches.
Definition base.hh:290
std::vector< PrefetchListener * > listeners
Definition base.hh:88
void addMMU(BaseMMU *mmu)
Add a BaseMMU object to be used whenever a translation is needed.
Definition base.cc:301
void regProbeListeners() override
Register probe points for this object.
Definition base.cc:275
Addr pageAddress(Addr a) const
Determine the address of the page in which a lays.
Definition base.cc:224
bool inMissQueue(Addr addr, bool is_secure) const
Determine if address is in cache miss queue.
Definition base.cc:194
bool hasBeenPrefetched(Addr addr, bool is_secure) const
Definition base.cc:200
const bool onInst
Consult prefetcher on instruction accesses?
Definition base.hh:287
uint64_t usefulPrefetches
Total prefetches that has been useful.
Definition base.hh:364
gem5::prefetch::Base::StatGroup prefetchStats
Addr pageIthBlockAddress(Addr page, uint32_t i) const
Build the address of the i-th block inside the page.
Definition base.cc:236
BaseCache * cache
Pointr to the parent cache.
Definition base.hh:266
Addr pageOffset(Addr a) const
Determine the page-offset of a
Definition base.cc:230
BaseMMU * mmu
Registered mmu for address translations.
Definition base.hh:367
virtual void setCache(BaseCache *_cache)
Definition base.cc:110
const bool onData
Consult prefetcher on data accesses?
Definition base.hh:284
const bool prefetchOnPfHit
Prefetch on hit on prefetched lines.
Definition base.hh:298
void probeNotify(const PacketPtr &pkt, bool miss)
Process a notification event from the ProbeListener.
Definition base.cc:242
const bool onWrite
Consult prefetcher on reads?
Definition base.hh:281
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....
unsigned lBlkSize
log_2(block size of the parent cache).
Definition base.hh:272
const Addr pageBytes
Definition base.hh:292
Addr blockIndex(Addr a) const
Determine the address of a at block granularity.
Definition base.cc:218
Addr blockAddress(Addr a) const
Determine the address of the block in which a lays.
Definition base.cc:212
const bool onMiss
Only consult prefetcher on cache misses?
Definition base.hh:275
bool samePage(Addr a, Addr b) const
Determine if addresses are on the same page.
Definition base.cc:206
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:815
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
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition types.hh:147
statistics::Formula accuracy
Definition base.hh:343
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
statistics::Scalar pfIssued
Definition base.hh:334
statistics::Scalar pfUseful
The number of times a HW-prefetch is useful.
Definition base.hh:339
statistics::Scalar pfHitInWB
The number of times a HW-prefetch hits in the Write Buffer (WB).
Definition base.hh:354
statistics::Scalar pfHitInMSHR
The number of times a HW-prefetch hits in a MSHR.
Definition base.hh:350
statistics::Formula pfLate
The number of times a HW-prefetch is late (hit in cache, MSHR, WB).
Definition base.hh:358
statistics::Scalar pfUnused
The number of times a HW-prefetched block is evicted w/o reference.
Definition base.hh:337
statistics::Scalar pfHitInCache
The number of times a HW-prefetch hits in cache.
Definition base.hh:347
statistics::Scalar demandMshrMisses
Definition base.hh:333
StatGroup(statistics::Group *parent)
Definition base.cc:120
statistics::Formula coverage
Definition base.hh:344

Generated on Mon Jul 10 2023 15:32:01 for gem5 by doxygen 1.9.7