gem5  v20.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/statistics.hh"
53 #include "base/types.hh"
54 #include "mem/packet.hh"
55 #include "mem/request.hh"
56 #include "sim/byteswap.hh"
57 #include "sim/clocked_object.hh"
58 #include "sim/probe/probe.hh"
59 
60 class BaseCache;
61 struct BasePrefetcherParams;
62 
63 namespace Prefetcher {
64 
65 class Base : public ClockedObject
66 {
67  class PrefetchListener : public ProbeListenerArgBase<PacketPtr>
68  {
69  public:
71  const std::string &name, bool _isFill = false,
72  bool _miss = false)
74  parent(_parent), isFill(_isFill), miss(_miss) {}
75  void notify(const PacketPtr &pkt) override;
76  protected:
78  const bool isFill;
79  const bool miss;
80  };
81 
83 
84  public:
85 
90  class PrefetchInfo {
98  bool validPC;
100  bool secure;
102  unsigned int size;
104  bool write;
108  bool cacheMiss;
110  uint8_t *data;
111 
112  public:
117  Addr getAddr() const
118  {
119  return address;
120  }
121 
126  bool isSecure() const
127  {
128  return secure;
129  }
130 
135  Addr getPC() const
136  {
137  assert(hasPC());
138  return pc;
139  }
140 
145  bool hasPC() const
146  {
147  return validPC;
148  }
149 
155  {
156  return requestorId;
157  }
158 
163  unsigned int getSize() const
164  {
165  return size;
166  }
167 
173  bool isWrite() const
174  {
175  return write;
176  }
177 
182  Addr getPaddr() const
183  {
184  return paddress;
185  }
186 
191  bool isCacheMiss() const
192  {
193  return cacheMiss;
194  }
195 
201  template <typename T>
202  inline T
203  get(ByteOrder endian) const
204  {
205  if (data == nullptr) {
206  panic("PrefetchInfo::get called with a request with no data.");
207  }
208  switch (endian) {
209  case ByteOrder::big:
210  return betoh(*(T*)data);
211 
212  case ByteOrder::little:
213  return letoh(*(T*)data);
214 
215  default:
216  panic("Illegal byte order in PrefetchInfo::get()\n");
217  };
218  }
219 
225  bool sameAddr(PrefetchInfo const &pfi) const
226  {
227  return this->getAddr() == pfi.getAddr() &&
228  this->isSecure() == pfi.isSecure();
229  }
230 
238  PrefetchInfo(PacketPtr pkt, Addr addr, bool miss);
239 
246  PrefetchInfo(PrefetchInfo const &pfi, Addr addr);
247 
249  {
250  delete[] data;
251  }
252  };
253 
254  protected:
255 
256  // PARAMETERS
257 
260 
262  unsigned blkSize;
263 
265  unsigned lBlkSize;
266 
268  const bool onMiss;
269 
271  const bool onRead;
272 
274  const bool onWrite;
275 
277  const bool onData;
278 
280  const bool onInst;
281 
284 
286 
288  const bool prefetchOnAccess;
289 
292 
298  bool observeAccess(const PacketPtr &pkt, bool miss) const;
299 
301  bool inCache(Addr addr, bool is_secure) const;
302 
304  bool inMissQueue(Addr addr, bool is_secure) const;
305 
306  bool hasBeenPrefetched(Addr addr, bool is_secure) const;
307 
309  bool samePage(Addr a, Addr b) const;
311  Addr blockAddress(Addr a) const;
313  Addr blockIndex(Addr a) const;
315  Addr pageAddress(Addr a) const;
317  Addr pageOffset(Addr a) const;
319  Addr pageIthBlockAddress(Addr page, uint32_t i) const;
320  struct StatGroup : public Stats::Group
321  {
322  StatGroup(Stats::Group *parent);
324  } prefetchStats;
325 
330 
333 
334  public:
335  Base(const BasePrefetcherParams *p);
336  virtual ~Base() = default;
337 
338  virtual void setCache(BaseCache *_cache);
339 
344  virtual void notify(const PacketPtr &pkt, const PrefetchInfo &pfi) = 0;
345 
347  virtual void notifyFill(const PacketPtr &pkt)
348  {}
349 
350  virtual PacketPtr getPacket() = 0;
351 
352  virtual Tick nextPrefetchReadyTime() const = 0;
353 
354 
358  void regProbeListeners() override;
359 
365  void probeNotify(const PacketPtr &pkt, bool miss);
366 
372  void addEventProbe(SimObject *obj, const char *name);
373 
380  void addTLB(BaseTLB *tlb);
381 };
382 
383 } // namespace Prefetcher
384 
385 #endif //__MEM_CACHE_PREFETCH_BASE_HH__
Prefetcher::Base::onData
const bool onData
Consult prefetcher on data accesses?
Definition: base.hh:277
Prefetcher::Base::PrefetchListener::PrefetchListener
PrefetchListener(Base &_parent, ProbeManager *pm, const std::string &name, bool _isFill=false, bool _miss=false)
Definition: base.hh:70
Prefetcher::Base::PrefetchListener::parent
Base & parent
Definition: base.hh:77
Prefetcher::Base::cache
BaseCache * cache
Pointr to the parent cache.
Definition: base.hh:259
Prefetcher::Base::PrefetchInfo::PrefetchInfo
PrefetchInfo(PacketPtr pkt, Addr addr, bool miss)
Constructs a PrefetchInfo using a PacketPtr.
Definition: base.cc:58
Prefetcher::Base::StatGroup::pfIssued
Stats::Scalar pfIssued
Definition: base.hh:323
Prefetcher::Base::PrefetchInfo::sameAddr
bool sameAddr(PrefetchInfo const &pfi) const
Check for equality.
Definition: base.hh:225
Prefetcher::Base::useVirtualAddresses
const bool useVirtualAddresses
Use Virtual Addresses for prefetching.
Definition: base.hh:291
Prefetcher::Base::StatGroup::StatGroup
StatGroup(Stats::Group *parent)
Definition: base.cc:115
ArmISA::i
Bitfield< 7 > i
Definition: miscregs_types.hh:63
Prefetcher::Base::blkSize
unsigned blkSize
The block size of the parent cache.
Definition: base.hh:262
Prefetcher::Base::PrefetchInfo::getPC
Addr getPC() const
Returns the program counter that generated this request.
Definition: base.hh:135
Prefetcher::Base::notifyFill
virtual void notifyFill(const PacketPtr &pkt)
Notify prefetcher of cache fill.
Definition: base.hh:347
Prefetcher::Base::pageAddress
Addr pageAddress(Addr a) const
Determine the address of the page in which a lays.
Definition: base.cc:181
Prefetcher::Base::onWrite
const bool onWrite
Consult prefetcher on reads?
Definition: base.hh:274
tlb.hh
Tick
uint64_t Tick
Tick count type.
Definition: types.hh:63
Prefetcher::Base::~Base
virtual ~Base()=default
Prefetcher::Base::inCache
bool inCache(Addr addr, bool is_secure) const
Determine if address is in cache.
Definition: base.cc:145
std::vector
STL vector class.
Definition: stl.hh:37
Prefetcher::Base::PrefetchInfo::cacheMiss
bool cacheMiss
Whether this event comes from a cache miss.
Definition: base.hh:108
Prefetcher::Base::PrefetchListener::miss
const bool miss
Definition: base.hh:79
Prefetcher::Base::usefulPrefetches
uint64_t usefulPrefetches
Total prefetches that has been useful.
Definition: base.hh:329
Prefetcher::Base::onInst
const bool onInst
Consult prefetcher on instruction accesses?
Definition: base.hh:280
Prefetcher::Base::onMiss
const bool onMiss
Only consult prefetcher on cache misses?
Definition: base.hh:268
Prefetcher::Base::PrefetchListener::isFill
const bool isFill
Definition: base.hh:78
request.hh
BaseTLB
Definition: tlb.hh:50
Prefetcher::Base::hasBeenPrefetched
bool hasBeenPrefetched(Addr addr, bool is_secure) const
Definition: base.cc:157
ClockedObject
The ClockedObject class extends the SimObject with a clock and accessor functions to relate ticks to ...
Definition: clocked_object.hh:231
Prefetcher::Base
Definition: base.hh:65
packet.hh
Prefetcher::Base::PrefetchInfo::getPaddr
Addr getPaddr() const
Gets the physical address of the request.
Definition: base.hh:182
Prefetcher::Base::prefetchStats
Prefetcher::Base::StatGroup prefetchStats
Stats::Scalar
This is a simple scalar statistic, like a counter.
Definition: statistics.hh:2533
Prefetcher::Base::PrefetchInfo::requestorId
RequestorID requestorId
The requestor ID that generated this address.
Definition: base.hh:96
RequestorID
uint16_t RequestorID
Definition: request.hh:85
letoh
T letoh(T value)
Definition: byteswap.hh:141
Prefetcher::Base::tlb
BaseTLB * tlb
Registered tlb for address translations.
Definition: base.hh:332
ArmISA::a
Bitfield< 8 > a
Definition: miscregs_types.hh:62
Prefetcher::Base::observeAccess
bool observeAccess(const PacketPtr &pkt, bool miss) const
Determine if this access should be observed.
Definition: base.cc:123
Prefetcher::Base::PrefetchInfo::data
uint8_t * data
Pointer to the associated request data.
Definition: base.hh:110
Prefetcher::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....
Prefetcher::Base::PrefetchInfo::isWrite
bool isWrite() const
Checks if the request that caused this prefetch event was a write request.
Definition: base.hh:173
Prefetcher::Base::PrefetchInfo::getRequestorId
RequestorID getRequestorId() const
Gets the requestor ID that generated this address.
Definition: base.hh:154
Prefetcher::Base::Base
Base(const BasePrefetcherParams *p)
Definition: base.cc:92
Prefetcher::Base::onRead
const bool onRead
Consult prefetcher on reads?
Definition: base.hh:271
Prefetcher::Base::lBlkSize
unsigned lBlkSize
log_2(block size of the parent cache).
Definition: base.hh:265
statistics.hh
Prefetcher::Base::setCache
virtual void setCache(BaseCache *_cache)
Definition: base.cc:106
ProbeListener::name
const std::string name
Definition: probe.hh:125
Prefetcher::Base::PrefetchInfo::isCacheMiss
bool isCacheMiss() const
Check if this event comes from a cache miss.
Definition: base.hh:191
Prefetcher::Base::PrefetchInfo::address
Addr address
The address used to train and generate prefetches.
Definition: base.hh:92
Prefetcher
Copyright (c) 2018 Metempsy Technology Consulting All rights reserved.
Definition: base.hh:78
Prefetcher::Base::PrefetchListener
Definition: base.hh:67
Prefetcher::Base::listeners
std::vector< PrefetchListener * > listeners
Definition: base.hh:82
Prefetcher::Base::PrefetchInfo::getSize
unsigned int getSize() const
Gets the size of the request triggering this event.
Definition: base.hh:163
Prefetcher::Base::PrefetchListener::notify
void notify(const PacketPtr &pkt) override
Definition: base.cc:83
Prefetcher::Base::PrefetchInfo::validPC
bool validPC
Validity bit for the PC of this address.
Definition: base.hh:98
Prefetcher::Base::pageOffset
Addr pageOffset(Addr a) const
Determine the page-offset of a
Definition: base.cc:187
BaseCache
A basic cache interface.
Definition: base.hh:89
Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
betoh
T betoh(T value)
Definition: byteswap.hh:143
Prefetcher::Base::addTLB
void addTLB(BaseTLB *tlb)
Add a BaseTLB object to be used whenever a translation is needed.
Definition: base.cc:255
Prefetcher::Base::nextPrefetchReadyTime
virtual Tick nextPrefetchReadyTime() const =0
SimObject::name
virtual const std::string name() const
Definition: sim_object.hh:133
Prefetcher::Base::PrefetchInfo::isSecure
bool isSecure() const
Returns true if the address targets the secure memory space.
Definition: base.hh:126
Prefetcher::Base::blockIndex
Addr blockIndex(Addr a) const
Determine the address of a at block granularity.
Definition: base.cc:175
Prefetcher::Base::StatGroup
Definition: base.hh:320
ProbeManager
ProbeManager is a conduit class that lives on each SimObject, and is used to match up probe listeners...
Definition: probe.hh:150
Prefetcher::Base::issuedPrefetches
uint64_t issuedPrefetches
Total prefetches issued.
Definition: base.hh:327
ArmISA::b
Bitfield< 7 > b
Definition: miscregs_types.hh:376
Prefetcher::Base::requestorId
const RequestorID requestorId
Request id for prefetches.
Definition: base.hh:283
Prefetcher::Base::prefetchOnAccess
const bool prefetchOnAccess
Prefetch on every access, not just misses.
Definition: base.hh:288
types.hh
Prefetcher::Base::regProbeListeners
void regProbeListeners() override
Register probe points for this object.
Definition: base.cc:227
Prefetcher::Base::addEventProbe
void addEventProbe(SimObject *obj, const char *name)
Add a SimObject and a probe name to listen events from.
Definition: base.cc:248
clocked_object.hh
Packet
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:257
Stats::Group
Statistics container.
Definition: group.hh:83
addr
ip6_addr_t addr
Definition: inet.hh:423
Prefetcher::Base::PrefetchInfo
Class containing the information needed by the prefetch to train and generate new prefetch requests.
Definition: base.hh:90
Prefetcher::Base::PrefetchInfo::secure
bool secure
Whether this address targets the secure memory space.
Definition: base.hh:100
Prefetcher::Base::getPacket
virtual PacketPtr getPacket()=0
Prefetcher::Base::PrefetchInfo::write
bool write
Whether this event comes from a write request.
Definition: base.hh:104
MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:323
Prefetcher::Base::blockAddress
Addr blockAddress(Addr a) const
Determine the address of the block in which a lays.
Definition: base.cc:169
Prefetcher::Base::PrefetchInfo::paddress
Addr paddress
Physical address, needed because address can be virtual.
Definition: base.hh:106
Prefetcher::Base::inMissQueue
bool inMissQueue(Addr addr, bool is_secure) const
Determine if address is in cache miss queue.
Definition: base.cc:151
probe.hh
Prefetcher::Base::pageBytes
const Addr pageBytes
Definition: base.hh:285
Prefetcher::Base::samePage
bool samePage(Addr a, Addr b) const
Determine if addresses are on the same page.
Definition: base.cc:163
Prefetcher::Base::PrefetchInfo::get
T get(ByteOrder endian) const
Gets the associated data of the request triggering the event.
Definition: base.hh:203
Prefetcher::Base::PrefetchInfo::size
unsigned int size
Size in bytes of the request triggering this event.
Definition: base.hh:102
Prefetcher::Base::probeNotify
void probeNotify(const PacketPtr &pkt, bool miss)
Process a notification event from the ProbeListener.
Definition: base.cc:199
Prefetcher::Base::PrefetchInfo::getAddr
Addr getAddr() const
Obtains the address value of this Prefetcher address.
Definition: base.hh:117
Prefetcher::Base::PrefetchInfo::~PrefetchInfo
~PrefetchInfo()
Definition: base.hh:248
Prefetcher::Base::pageIthBlockAddress
Addr pageIthBlockAddress(Addr page, uint32_t i) const
Build the address of the i-th block inside the page.
Definition: base.cc:193
Prefetcher::Base::PrefetchInfo::pc
Addr pc
The program counter that generated this address.
Definition: base.hh:94
Prefetcher::Base::PrefetchInfo::hasPC
bool hasPC() const
Returns true if the associated program counter is valid.
Definition: base.hh:145
byteswap.hh
panic
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:171
SimObject
Abstract superclass for simulation objects.
Definition: sim_object.hh:92
ProbeListenerArgBase
ProbeListenerArgBase is used to define the base interface to a ProbeListenerArg (i....
Definition: probe.hh:198

Generated on Wed Sep 30 2020 14:02:07 for gem5 by doxygen 1.8.17