gem5  v22.1.0.0
base.hh
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 
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"
55 #include "mem/cache/cache_blk.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 
62 namespace gem5
63 {
64 
65 class BaseCache;
66 struct BasePrefetcherParams;
67 
69 namespace prefetch
70 {
71 
72 class Base : public ClockedObject
73 {
74  class PrefetchListener : public ProbeListenerArgBase<PacketPtr>
75  {
76  public:
78  const std::string &name, bool _isFill = false,
79  bool _miss = false)
81  parent(_parent), isFill(_isFill), miss(_miss) {}
82  void notify(const PacketPtr &pkt) override;
83  protected:
85  const bool isFill;
86  const bool miss;
87  };
88 
90 
91  public:
92 
98  {
106  bool validPC;
108  bool secure;
110  unsigned int size;
112  bool write;
116  bool cacheMiss;
118  uint8_t *data;
119 
120  public:
125  Addr getAddr() const
126  {
127  return address;
128  }
129 
134  bool isSecure() const
135  {
136  return secure;
137  }
138 
143  Addr getPC() const
144  {
145  assert(hasPC());
146  return pc;
147  }
148 
153  bool hasPC() const
154  {
155  return validPC;
156  }
157 
163  {
164  return requestorId;
165  }
166 
171  unsigned int getSize() const
172  {
173  return size;
174  }
175 
181  bool isWrite() const
182  {
183  return write;
184  }
185 
190  Addr getPaddr() const
191  {
192  return paddress;
193  }
194 
199  bool isCacheMiss() const
200  {
201  return cacheMiss;
202  }
203 
209  template <typename T>
210  inline T
211  get(ByteOrder endian) const
212  {
213  if (data == nullptr) {
214  panic("PrefetchInfo::get called with a request with no data.");
215  }
216  switch (endian) {
217  case ByteOrder::big:
218  return betoh(*(T*)data);
219 
220  case ByteOrder::little:
221  return letoh(*(T*)data);
222 
223  default:
224  panic("Illegal byte order in PrefetchInfo::get()\n");
225  };
226  }
227 
233  bool sameAddr(PrefetchInfo const &pfi) const
234  {
235  return this->getAddr() == pfi.getAddr() &&
236  this->isSecure() == pfi.isSecure();
237  }
238 
246  PrefetchInfo(PacketPtr pkt, Addr addr, bool miss);
247 
254  PrefetchInfo(PrefetchInfo const &pfi, Addr addr);
255 
257  {
258  delete[] data;
259  }
260  };
261 
262  protected:
263 
264  // PARAMETERS
265 
268 
270  unsigned blkSize;
271 
273  unsigned lBlkSize;
274 
276  const bool onMiss;
277 
279  const bool onRead;
280 
282  const bool onWrite;
283 
285  const bool onData;
286 
288  const bool onInst;
289 
292 
294 
296  const bool prefetchOnAccess;
297 
299  const bool prefetchOnPfHit;
300 
303 
309  bool observeAccess(const PacketPtr &pkt, bool miss) const;
310 
312  bool inCache(Addr addr, bool is_secure) const;
313 
315  bool inMissQueue(Addr addr, bool is_secure) const;
316 
317  bool hasBeenPrefetched(Addr addr, bool is_secure) const;
318 
320  bool samePage(Addr a, Addr b) const;
322  Addr blockAddress(Addr a) const;
324  Addr blockIndex(Addr a) const;
326  Addr pageAddress(Addr a) const;
328  Addr pageOffset(Addr a) const;
330  Addr pageIthBlockAddress(Addr page, uint32_t i) const;
331  struct StatGroup : public statistics::Group
332  {
333  StatGroup(statistics::Group *parent);
346 
349 
352 
356 
361 
366 
369 
370  public:
371  Base(const BasePrefetcherParams &p);
372  virtual ~Base() = default;
373 
374  virtual void setCache(BaseCache *_cache);
375 
380  virtual void notify(const PacketPtr &pkt, const PrefetchInfo &pfi) = 0;
381 
383  virtual void notifyFill(const PacketPtr &pkt)
384  {}
385 
386  virtual PacketPtr getPacket() = 0;
387 
388  virtual Tick nextPrefetchReadyTime() const = 0;
389 
390  void
392  {
394  }
395 
396  void
398  {
400  }
401 
402  void
404  {
406  }
407 
408  void
410  {
412  }
413 
414  void
416  {
418  }
419 
423  void regProbeListeners() override;
424 
430  void probeNotify(const PacketPtr &pkt, bool miss);
431 
437  void addEventProbe(SimObject *obj, const char *name);
438 
445  void addTLB(BaseTLB *tlb);
446 };
447 
448 } // namespace prefetch
449 } // namespace gem5
450 
451 #endif //__MEM_CACHE_PREFETCH_BASE_HH__
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,...
Definitions of a simple cache block class.
A basic cache interface.
Definition: base.hh:96
The ClockedObject class extends the SimObject with a clock and accessor functions to relate ticks to ...
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:294
ProbeListenerArgBase is used to define the base interface to a ProbeListenerArg (i....
Definition: probe.hh:212
const std::string name
Definition: probe.hh:138
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.
Definition: sim_object.hh:148
Class containing the information needed by the prefetch to train and generate new prefetch requests.
Definition: base.hh:98
bool validPC
Validity bit for the PC of this address.
Definition: base.hh:106
PrefetchInfo(PacketPtr pkt, Addr addr, bool miss)
Constructs a PrefetchInfo using a PacketPtr.
Definition: base.cc:62
Addr getPC() const
Returns the program counter that generated this request.
Definition: base.hh:143
bool isSecure() const
Returns true if the address targets the secure memory space.
Definition: base.hh:134
unsigned int getSize() const
Gets the size of the request triggering this event.
Definition: base.hh:171
Addr getPaddr() const
Gets the physical address of the request.
Definition: base.hh:190
bool write
Whether this event comes from a write request.
Definition: base.hh:112
bool isWrite() const
Checks if the request that caused this prefetch event was a write request.
Definition: base.hh:181
bool isCacheMiss() const
Check if this event comes from a cache miss.
Definition: base.hh:199
RequestorID requestorId
The requestor ID that generated this address.
Definition: base.hh:104
Addr address
The address used to train and generate prefetches.
Definition: base.hh:100
Addr getAddr() const
Obtains the address value of this Prefetcher address.
Definition: base.hh:125
bool cacheMiss
Whether this event comes from a cache miss.
Definition: base.hh:116
Addr paddress
Physical address, needed because address can be virtual.
Definition: base.hh:114
T get(ByteOrder endian) const
Gets the associated data of the request triggering the event.
Definition: base.hh:211
bool hasPC() const
Returns true if the associated program counter is valid.
Definition: base.hh:153
Addr pc
The program counter that generated this address.
Definition: base.hh:102
unsigned int size
Size in bytes of the request triggering this event.
Definition: base.hh:110
uint8_t * data
Pointer to the associated request data.
Definition: base.hh:118
RequestorID getRequestorId() const
Gets the requestor ID that generated this address.
Definition: base.hh:162
bool secure
Whether this address targets the secure memory space.
Definition: base.hh:108
bool sameAddr(PrefetchInfo const &pfi) const
Check for equality.
Definition: base.hh:233
void notify(const PacketPtr &pkt) override
Definition: base.cc:87
PrefetchListener(Base &_parent, ProbeManager *pm, const std::string &name, bool _isFill=false, bool _miss=false)
Definition: base.hh:77
Base(const BasePrefetcherParams &p)
Definition: base.cc:96
const bool useVirtualAddresses
Use Virtual Addresses for prefetching.
Definition: base.hh:302
void addTLB(BaseTLB *tlb)
Add a BaseTLB object to be used whenever a translation is needed.
Definition: base.cc:302
const bool prefetchOnAccess
Prefetch on every access, not just misses.
Definition: base.hh:296
const bool onRead
Consult prefetcher on reads?
Definition: base.hh:279
unsigned blkSize
The block size of the parent cache.
Definition: base.hh:270
uint64_t issuedPrefetches
Total prefetches issued.
Definition: base.hh:363
bool observeAccess(const PacketPtr &pkt, bool miss) const
Determine if this access should be observed.
Definition: base.cc:161
bool inCache(Addr addr, bool is_secure) const
Determine if address is in cache.
Definition: base.cc:189
void incrDemandMhsrMisses()
Definition: base.hh:397
void addEventProbe(SimObject *obj, const char *name)
Add a SimObject and a probe name to listen events from.
Definition: base.cc:295
void pfHitInWB()
Definition: base.hh:415
const RequestorID requestorId
Request id for prefetches.
Definition: base.hh:291
void pfHitInCache()
Definition: base.hh:403
std::vector< PrefetchListener * > listeners
Definition: base.hh:89
BaseTLB * tlb
Registered tlb for address translations.
Definition: base.hh:368
void regProbeListeners() override
Register probe points for this object.
Definition: base.cc:276
Addr pageAddress(Addr a) const
Determine the address of the page in which a lays.
Definition: base.cc:225
bool inMissQueue(Addr addr, bool is_secure) const
Determine if address is in cache miss queue.
Definition: base.cc:195
bool hasBeenPrefetched(Addr addr, bool is_secure) const
Definition: base.cc:201
const bool onInst
Consult prefetcher on instruction accesses?
Definition: base.hh:288
uint64_t usefulPrefetches
Total prefetches that has been useful.
Definition: base.hh:365
gem5::prefetch::Base::StatGroup prefetchStats
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:237
BaseCache * cache
Pointr to the parent cache.
Definition: base.hh:267
Addr pageOffset(Addr a) const
Determine the page-offset of a
Definition: base.cc:231
void pfHitInMSHR()
Definition: base.hh:409
virtual PacketPtr getPacket()=0
virtual void setCache(BaseCache *_cache)
Definition: base.cc:111
const bool onData
Consult prefetcher on data accesses?
Definition: base.hh:285
const bool prefetchOnPfHit
Prefetch on hit on prefetched lines.
Definition: base.hh:299
void probeNotify(const PacketPtr &pkt, bool miss)
Process a notification event from the ProbeListener.
Definition: base.cc:243
virtual void notifyFill(const PacketPtr &pkt)
Notify prefetcher of cache fill.
Definition: base.hh:383
const bool onWrite
Consult prefetcher on reads?
Definition: base.hh:282
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:273
const Addr pageBytes
Definition: base.hh:293
Addr blockIndex(Addr a) const
Determine the address of a at block granularity.
Definition: base.cc:219
void prefetchUnused()
Definition: base.hh:391
Addr blockAddress(Addr a) const
Determine the address of the block in which a lays.
Definition: base.cc:213
const bool onMiss
Only consult prefetcher on cache misses?
Definition: base.hh:276
bool samePage(Addr a, Addr b) const
Determine if addresses are on the same page.
Definition: base.cc:207
virtual Tick nextPrefetchReadyTime() const =0
A formula for statistics that is calculated when printed.
Definition: statistics.hh:2540
Statistics container.
Definition: group.hh:94
This is a simple scalar statistic, like a counter.
Definition: statistics.hh:1931
STL vector class.
Definition: stl.hh:37
ClockedObject declaration and implementation.
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:178
Bitfield< 7 > b
Definition: misc_types.hh:388
Bitfield< 7 > i
Definition: misc_types.hh:67
Bitfield< 8 > a
Definition: misc_types.hh:66
Bitfield< 54 > p
Definition: pagetable.hh:70
Bitfield< 3 > addr
Definition: types.hh:84
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
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
GEM5_DEPRECATED_NAMESPACE(GuestABI, guest_abi)
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.
statistics::Formula accuracy
Definition: base.hh:344
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:343
statistics::Scalar pfIssued
Definition: base.hh:335
statistics::Scalar pfUseful
The number of times a HW-prefetch is useful.
Definition: base.hh:340
statistics::Scalar pfHitInWB
The number of times a HW-prefetch hits in the Write Buffer (WB).
Definition: base.hh:355
statistics::Scalar pfHitInMSHR
The number of times a HW-prefetch hits in a MSHR.
Definition: base.hh:351
statistics::Formula pfLate
The number of times a HW-prefetch is late (hit in cache, MSHR, WB).
Definition: base.hh:359
statistics::Scalar pfUnused
The number of times a HW-prefetched block is evicted w/o reference.
Definition: base.hh:338
statistics::Scalar pfHitInCache
The number of times a HW-prefetch hits in cache.
Definition: base.hh:348
statistics::Scalar demandMshrMisses
Definition: base.hh:334
StatGroup(statistics::Group *parent)
Definition: base.cc:121
statistics::Formula coverage
Definition: base.hh:345

Generated on Wed Dec 21 2022 10:22:28 for gem5 by doxygen 1.9.1