gem5 [DEVELOP-FOR-25.0]
Loading...
Searching...
No Matches
base.hh
Go to the documentation of this file.
1/*
2 * Copyright (c) 2013-2014, 2023 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
45
46#ifndef __MEM_CACHE_PREFETCH_BASE_HH__
47#define __MEM_CACHE_PREFETCH_BASE_HH__
48
49#include <cstdint>
50
51#include "arch/generic/tlb.hh"
52#include "base/compiler.hh"
53#include "base/statistics.hh"
54#include "base/types.hh"
56#include "mem/packet.hh"
57#include "mem/request.hh"
58#include "sim/byteswap.hh"
59#include "sim/clocked_object.hh"
60#include "sim/probe/probe.hh"
61
62namespace gem5
63{
64
65struct BasePrefetcherParams;
66class ProbeManager;
67class System;
68
69namespace prefetch
70{
71
72class Base : public ClockedObject
73{
74 class PrefetchListener : public ProbeListenerArgBase<CacheAccessProbeArg>
75 {
76 public:
77 PrefetchListener(Base &_parent, std::string name, bool _isFill = false,
78 bool _miss = false)
80 parent(_parent),
81 isFill(_isFill),
82 miss(_miss)
83 {}
84 void notify(const CacheAccessProbeArg &arg) override;
85 protected:
87 const bool isFill;
88 const bool miss;
89 };
90
92
93 class PrefetchEvictListener : public ProbeListenerArgBase<EvictionInfo>
94 {
95 public:
96 PrefetchEvictListener(Base &_parent, std::string name)
97 : ProbeListenerArgBase(std::move(name)), parent(_parent)
98 {}
99 void notify(const EvictionInfo &info) override;
100 protected:
102 };
103
105
106 public:
107
113 {
123 bool secure;
125 unsigned int size;
127 bool write;
133 uint8_t *data;
134
135 public:
140 Addr getAddr() const
141 {
142 return address;
143 }
144
149 bool isSecure() const
150 {
151 return secure;
152 }
153
158 Addr getPC() const
159 {
160 assert(hasPC());
161 return pc;
162 }
163
168 bool hasPC() const
169 {
170 return validPC;
171 }
172
178 {
179 return requestorId;
180 }
181
186 unsigned int getSize() const
187 {
188 return size;
189 }
190
196 bool isWrite() const
197 {
198 return write;
199 }
200
206 {
207 return paddress;
208 }
209
214 bool isCacheMiss() const
215 {
216 return cacheMiss;
217 }
218
224 template <typename T>
225 inline T
226 get(ByteOrder endian) const
227 {
228 if (data == nullptr) {
229 panic("PrefetchInfo::get called with a request with no data.");
230 }
231 switch (endian) {
232 case ByteOrder::big:
233 return betoh(*(T*)data);
234
235 case ByteOrder::little:
236 return letoh(*(T*)data);
237
238 default:
239 panic("Illegal byte order in PrefetchInfo::get()\n");
240 };
241 }
242
248 bool sameAddr(PrefetchInfo const &pfi) const
249 {
250 return this->getAddr() == pfi.getAddr() &&
251 this->isSecure() == pfi.isSecure();
252 }
253
261 PrefetchInfo(PacketPtr pkt, Addr addr, bool miss);
262
269 PrefetchInfo(PrefetchInfo const &pfi, Addr addr);
270
272 {
273 delete[] data;
274 }
275 };
276
277 protected:
278
279 // PARAMETERS
280
283
286
288 unsigned blkSize;
289
291 unsigned lBlkSize;
292
294 const bool onMiss;
295
297 const bool onRead;
298
300 const bool onWrite;
301
303 const bool onData;
304
306 const bool onInst;
307
310
312
315
317 const bool prefetchOnPfHit;
318
321
328 bool observeAccess(const PacketPtr &pkt, bool miss, bool prefetched) const;
329
331 bool samePage(Addr a, Addr b) const;
333 Addr blockAddress(Addr a) const;
335 Addr blockIndex(Addr a) const;
337 Addr pageAddress(Addr a) const;
339 Addr pageOffset(Addr a) const;
341 Addr pageIthBlockAddress(Addr page, uint32_t i) const;
372
377
380
381 public:
382 Base(const BasePrefetcherParams &p);
383 virtual ~Base() = default;
384
385 virtual void
386 setParentInfo(System *sys, ProbeManager *pm, unsigned blk_size);
387
392 virtual void
393 notify(const CacheAccessProbeArg &acc, const PrefetchInfo &pfi) = 0;
394
396 virtual void notifyFill(const CacheAccessProbeArg &acc)
397 {}
398
400 virtual void notifyEvict(const EvictionInfo &info)
401 {}
402
403 virtual PacketPtr getPacket() = 0;
404
405 virtual Tick nextPrefetchReadyTime() const = 0;
406
407 void
409 {
410 prefetchStats.pfUnused++;
411 }
412
413 void
415 {
416 prefetchStats.demandMshrMisses++;
417 }
418
419 void
421 {
422 prefetchStats.pfHitInCache++;
423 }
424
425 void
427 {
428 prefetchStats.pfHitInMSHR++;
429 }
430
431 void
433 {
434 prefetchStats.pfHitInWB++;
435 }
436
440 void regProbeListeners() override;
441
447 void probeNotify(const CacheAccessProbeArg &acc, bool miss);
448
454 void addEventProbe(SimObject *obj, const char *name);
455
462 void addMMU(BaseMMU *mmu);
463};
464
465} // namespace prefetch
466} // namespace gem5
467
468#endif //__MEM_CACHE_PREFETCH_BASE_HH__
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,...
Information provided to probes on a cache event.
ClockedObject(const ClockedObjectParams &p)
const std::string name
Definition probe.hh:114
ProbeManager is a conduit class that lives on each SimObject, and is used to match up probe listeners...
Definition probe.hh:162
Abstract superclass for simulation objects.
PrefetchEvictListener(Base &_parent, std::string name)
Definition base.hh:96
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:113
bool validPC
Validity bit for the PC of this address.
Definition base.hh:121
PrefetchInfo(PacketPtr pkt, Addr addr, bool miss)
Constructs a PrefetchInfo using a PacketPtr.
Definition base.cc:61
Addr getPC() const
Returns the program counter that generated this request.
Definition base.hh:158
bool isSecure() const
Returns true if the address targets the secure memory space.
Definition base.hh:149
unsigned int getSize() const
Gets the size of the request triggering this event.
Definition base.hh:186
Addr getPaddr() const
Gets the physical address of the request.
Definition base.hh:205
bool write
Whether this event comes from a write request.
Definition base.hh:127
bool isWrite() const
Checks if the request that caused this prefetch event was a write request.
Definition base.hh:196
bool isCacheMiss() const
Check if this event comes from a cache miss.
Definition base.hh:214
RequestorID requestorId
The requestor ID that generated this address.
Definition base.hh:119
Addr address
The address used to train and generate prefetches.
Definition base.hh:115
Addr getAddr() const
Obtains the address value of this Prefetcher address.
Definition base.hh:140
bool cacheMiss
Whether this event comes from a cache miss.
Definition base.hh:131
Addr paddress
Physical address, needed because address can be virtual.
Definition base.hh:129
T get(ByteOrder endian) const
Gets the associated data of the request triggering the event.
Definition base.hh:226
bool hasPC() const
Returns true if the associated program counter is valid.
Definition base.hh:168
Addr pc
The program counter that generated this address.
Definition base.hh:117
unsigned int size
Size in bytes of the request triggering this event.
Definition base.hh:125
uint8_t * data
Pointer to the associated request data.
Definition base.hh:133
RequestorID getRequestorId() const
Gets the requestor ID that generated this address.
Definition base.hh:177
bool secure
Whether this address targets the secure memory space.
Definition base.hh:123
bool sameAddr(PrefetchInfo const &pfi) const
Check for equality.
Definition base.hh:248
void notify(const CacheAccessProbeArg &arg) override
Definition base.cc:86
PrefetchListener(Base &_parent, std::string name, bool _isFill=false, bool _miss=false)
Definition base.hh:77
Base(const BasePrefetcherParams &p)
Definition base.cc:102
const bool useVirtualAddresses
Use Virtual Addresses for prefetching.
Definition base.hh:320
const bool prefetchOnAccess
Prefetch on every access, not just misses.
Definition base.hh:314
const bool onRead
Consult prefetcher on reads?
Definition base.hh:297
virtual void notifyFill(const CacheAccessProbeArg &acc)
Notify prefetcher of cache fill.
Definition base.hh:396
unsigned blkSize
The block size of the parent cache.
Definition base.hh:288
uint64_t issuedPrefetches
Total prefetches issued.
Definition base.hh:374
void incrDemandMhsrMisses()
Definition base.hh:414
void addEventProbe(SimObject *obj, const char *name)
Add a SimObject and a probe name to listen events from.
Definition base.cc:292
std::vector< ProbeListenerPtr<> > listeners
Definition base.hh:104
const RequestorID requestorId
Request id for prefetches.
Definition base.hh:309
void pfHitInCache()
Definition base.hh:420
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:285
virtual void notifyEvict(const EvictionInfo &info)
Notify prefetcher of cache eviction.
Definition base.hh:400
const bool onInst
Consult prefetcher on instruction accesses?
Definition base.hh:306
uint64_t usefulPrefetches
Total prefetches that has been useful.
Definition base.hh:376
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....
CacheDataUpdateProbeArg EvictionInfo
Definition base.hh:91
virtual ~Base()=default
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
BaseMMU * mmu
Registered mmu for address translations.
Definition base.hh:379
virtual PacketPtr getPacket()=0
const bool onData
Consult prefetcher on data accesses?
Definition base.hh:303
const bool prefetchOnPfHit
Prefetch on hit on prefetched lines.
Definition base.hh:317
System * system
Pointer to the parent system.
Definition base.hh:282
const bool onWrite
Consult prefetcher on reads?
Definition base.hh:300
unsigned lBlkSize
log_2(block size of the parent cache).
Definition base.hh:291
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:311
Addr blockIndex(Addr a) const
Determine the address of a at block granularity.
Definition base.cc:208
void prefetchUnused()
Definition base.hh:408
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:294
bool samePage(Addr a, Addr b) const
Determine if addresses are on the same page.
Definition base.cc:196
virtual Tick nextPrefetchReadyTime() const =0
A formula for statistics that is calculated when printed.
Statistics container.
Definition group.hh:93
This is a simple scalar statistic, like a counter.
STL vector class.
Definition stl.hh:37
ClockedObject declaration and implementation.
#define panic(...)
This implements a cprintf based panic() function.
Definition logging.hh:220
Bitfield< 7 > b
Bitfield< 7 > i
Definition misc_types.hh:67
Bitfield< 8 > a
Definition misc_types.hh:66
Bitfield< 0 > p
Bitfield< 3 > addr
Definition types.hh:84
Copyright (c) 2024 Arm Limited All rights reserved.
Definition binary32.hh:36
T letoh(T value)
Definition byteswap.hh:173
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition types.hh:147
T betoh(T value)
Definition byteswap.hh:175
uint64_t Tick
Tick count type.
Definition types.hh:58
uint16_t RequestorID
Definition request.hh:95
Packet * PacketPtr
Overload hash function for BasicBlockRange type.
Definition binary32.hh:81
Declaration of the Packet class.
Declaration of a request, the overall memory request consisting of the parts of the request that are ...
Declaration of Statistics objects.
A data contents update is composed of the updated block's address, the old contents,...
statistics::Formula accuracy
Definition base.hh:355
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:354
statistics::Scalar pfIssued
Definition base.hh:346
statistics::Scalar pfUseful
The number of times a HW-prefetch is useful.
Definition base.hh:351
statistics::Scalar pfHitInWB
The number of times a HW-prefetch hits in the Write Buffer (WB).
Definition base.hh:366
statistics::Scalar pfHitInMSHR
The number of times a HW-prefetch hits in a MSHR.
Definition base.hh:362
statistics::Formula pfLate
The number of times a HW-prefetch is late (hit in cache, MSHR, WB).
Definition base.hh:370
statistics::Scalar pfUnused
The number of times a HW-prefetched block is evicted w/o reference.
Definition base.hh:349
statistics::Scalar pfHitInCache
The number of times a HW-prefetch hits in cache.
Definition base.hh:359
statistics::Scalar demandMshrMisses
Definition base.hh:345
StatGroup(statistics::Group *parent)
Definition base.cc:128
statistics::Formula coverage
Definition base.hh:356
const std::string & name()
Definition trace.cc:48

Generated on Mon May 26 2025 09:19:09 for gem5 by doxygen 1.13.2