gem5  v19.0.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  * Authors: Ron Dreslinski
41  * Mitch Hayenga
42  */
43 
49 #ifndef __MEM_CACHE_PREFETCH_BASE_HH__
50 #define __MEM_CACHE_PREFETCH_BASE_HH__
51 
52 #include <cstdint>
53 
54 #include "arch/isa_traits.hh"
55 #include "arch/generic/tlb.hh"
56 #include "base/statistics.hh"
57 #include "base/types.hh"
58 #include "mem/packet.hh"
59 #include "mem/request.hh"
60 #include "sim/byteswap.hh"
61 #include "sim/clocked_object.hh"
62 #include "sim/probe/probe.hh"
63 
64 class BaseCache;
65 struct BasePrefetcherParams;
66 
68 {
69  class PrefetchListener : public ProbeListenerArgBase<PacketPtr>
70  {
71  public:
73  const std::string &name, bool _isFill = false,
74  bool _miss = false)
75  : ProbeListenerArgBase(pm, name),
76  parent(_parent), isFill(_isFill), miss(_miss) {}
77  void notify(const PacketPtr &pkt) override;
78  protected:
80  const bool isFill;
81  const bool miss;
82  };
83 
85 
86  public:
87 
92  class PrefetchInfo {
100  bool validPC;
102  bool secure;
104  unsigned int size;
106  bool write;
110  bool cacheMiss;
112  uint8_t *data;
113 
114  public:
119  Addr getAddr() const
120  {
121  return address;
122  }
123 
128  bool isSecure() const
129  {
130  return secure;
131  }
132 
137  Addr getPC() const
138  {
139  assert(hasPC());
140  return pc;
141  }
142 
147  bool hasPC() const
148  {
149  return validPC;
150  }
151 
157  {
158  return masterId;
159  }
160 
165  unsigned int getSize() const
166  {
167  return size;
168  }
169 
175  bool isWrite() const
176  {
177  return write;
178  }
179 
184  Addr getPaddr() const
185  {
186  return paddress;
187  }
188 
193  bool isCacheMiss() const
194  {
195  return cacheMiss;
196  }
197 
203  template <typename T>
204  inline T
205  get(ByteOrder endian) const
206  {
207  if (data == nullptr) {
208  panic("PrefetchInfo::get called with a request with no data.");
209  }
210  switch (endian) {
211  case BigEndianByteOrder:
212  return betoh(*(T*)data);
213 
215  return letoh(*(T*)data);
216 
217  default:
218  panic("Illegal byte order in PrefetchInfo::get()\n");
219  };
220  }
221 
227  bool sameAddr(PrefetchInfo const &pfi) const
228  {
229  return this->getAddr() == pfi.getAddr() &&
230  this->isSecure() == pfi.isSecure();
231  }
232 
240  PrefetchInfo(PacketPtr pkt, Addr addr, bool miss);
241 
248  PrefetchInfo(PrefetchInfo const &pfi, Addr addr);
249 
251  {
252  delete[] data;
253  }
254  };
255 
256  protected:
257 
258  // PARAMETERS
259 
262 
264  unsigned blkSize;
265 
267  unsigned lBlkSize;
268 
270  const bool onMiss;
271 
273  const bool onRead;
274 
276  const bool onWrite;
277 
279  const bool onData;
280 
282  const bool onInst;
283 
286 
288 
290  const bool prefetchOnAccess;
291 
294 
300  bool observeAccess(const PacketPtr &pkt, bool miss) const;
301 
303  bool inCache(Addr addr, bool is_secure) const;
304 
306  bool inMissQueue(Addr addr, bool is_secure) const;
307 
308  bool hasBeenPrefetched(Addr addr, bool is_secure) const;
309 
311  bool samePage(Addr a, Addr b) const;
313  Addr blockAddress(Addr a) const;
315  Addr blockIndex(Addr a) const;
317  Addr pageAddress(Addr a) const;
319  Addr pageOffset(Addr a) const;
321  Addr pageIthBlockAddress(Addr page, uint32_t i) const;
322 
324 
329 
332 
333  public:
334 
335  BasePrefetcher(const BasePrefetcherParams *p);
336 
337  virtual ~BasePrefetcher() {}
338 
339  virtual void setCache(BaseCache *_cache);
340 
345  virtual void notify(const PacketPtr &pkt, const PrefetchInfo &pfi) = 0;
346 
348  virtual void notifyFill(const PacketPtr &pkt)
349  {}
350 
351  virtual PacketPtr getPacket() = 0;
352 
353  virtual Tick nextPrefetchReadyTime() const = 0;
354 
358  void regStats() override;
359 
363  void regProbeListeners() override;
364 
370  void probeNotify(const PacketPtr &pkt, bool miss);
371 
377  void addEventProbe(SimObject *obj, const char *name);
378 
385  void addTLB(BaseTLB *tlb);
386 };
387 #endif //__MEM_CACHE_PREFETCH_BASE_HH__
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:167
BasePrefetcher(const BasePrefetcherParams *p)
Definition: base.cc:92
const std::string name
Definition: probe.hh:127
const bool onWrite
Consult prefetcher on reads?
Definition: base.hh:276
Bitfield< 7 > i
bool sameAddr(PrefetchInfo const &pfi) const
Check for equality.
Definition: base.hh:227
const bool onInst
Consult prefetcher on instruction accesses?
Definition: base.hh:282
Addr pageIthBlockAddress(Addr page, uint32_t i) const
Build the address of the i-th block inside the page.
Definition: base.cc:197
Addr blockIndex(Addr a) const
Determine the address of a at block granularity.
Definition: base.cc:179
Declaration of a request, the overall memory request consisting of the parts of the request that are ...
bool inCache(Addr addr, bool is_secure) const
Determine if address is in cache.
Definition: base.cc:149
Bitfield< 8 > a
std::vector< PrefetchListener * > listeners
Definition: base.hh:84
ip6_addr_t addr
Definition: inet.hh:335
bool isCacheMiss() const
Check if this event comes from a cache miss.
Definition: base.hh:193
BaseCache * cache
Pointr to the parent cache.
Definition: base.hh:261
uint64_t usefulPrefetches
Total prefetches that has been useful.
Definition: base.hh:328
const bool onMiss
Only consult prefetcher on cache misses?
Definition: base.hh:270
bool isSecure() const
Returns true if the address targets the secure memory space.
Definition: base.hh:128
ProbeManager is a conduit class that lives on each SimObject, and is used to match up probe listeners...
Definition: probe.hh:152
unsigned int getSize() const
Gets the size of the request triggering this event.
Definition: base.hh:165
T letoh(T value)
Definition: byteswap.hh:145
const bool prefetchOnAccess
Prefetch on every access, not just misses.
Definition: base.hh:290
unsigned lBlkSize
log_2(block size of the parent cache).
Definition: base.hh:267
BaseTLB * tlb
Registered tlb for address translations.
Definition: base.hh:331
const MasterID masterId
Request id for prefetches.
Definition: base.hh:285
Declaration of Statistics objects.
This is a simple scalar statistic, like a counter.
Definition: statistics.hh:2508
STL vector class.
Definition: stl.hh:40
void addTLB(BaseTLB *tlb)
Add a BaseTLB object to be used whenever a translation is needed.
Definition: base.cc:259
uint64_t issuedPrefetches
Total prefetches issued.
Definition: base.hh:326
Bitfield< 7 > b
Addr getAddr() const
Obtains the address value of this Prefetcher address.
Definition: base.hh:119
Definition: tlb.hh:52
Bitfield< 4 > pc
bool isWrite() const
Checks if the request that caused this prefetch event was a write request.
Definition: base.hh:175
void addEventProbe(SimObject *obj, const char *name)
Add a SimObject and a probe name to listen events from.
Definition: base.cc:252
Class containing the information needed by the prefetch to train and generate new prefetch requests...
Definition: base.hh:92
ProbeListenerArgBase is used to define the base interface to a ProbeListenerArg (i.e the notify method on specific type).
Definition: probe.hh:200
const Addr pageBytes
Definition: base.hh:287
virtual ~BasePrefetcher()
Definition: base.hh:337
MasterID masterId
The requestor ID that generated this address.
Definition: base.hh:98
uint64_t Tick
Tick count type.
Definition: types.hh:63
Addr getPC() const
Returns the program counter that generated this request.
Definition: base.hh:137
The ClockedObject class extends the SimObject with a clock and accessor functions to relate ticks to ...
bool validPC
Validity bit for the PC of this address.
Definition: base.hh:100
bool cacheMiss
Whether this event comes from a cache miss.
Definition: base.hh:110
ByteOrder
Definition: types.hh:247
void regStats() override
Register local statistics.
Definition: base.cc:115
ClockedObject declaration and implementation.
const bool onRead
Consult prefetcher on reads?
Definition: base.hh:273
A basic cache interface.
Definition: base.hh:93
void notify(const PacketPtr &pkt) override
Definition: base.cc:83
bool secure
Whether this address targets the secure memory space.
Definition: base.hh:102
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,16,32,64}_t.
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
uint16_t MasterID
Definition: request.hh:86
bool write
Whether this event comes from a write request.
Definition: base.hh:106
A Packet is used to encapsulate a transfer between two objects in the memory system (e...
Definition: packet.hh:255
virtual void notifyFill(const PacketPtr &pkt)
Notify prefetcher of cache fill.
Definition: base.hh:348
Addr pageOffset(Addr a) const
Determine the page-offset of a.
Definition: base.cc:191
bool observeAccess(const PacketPtr &pkt, bool miss) const
Determine if this access should be observed.
Definition: base.cc:127
Declaration of the Packet class.
Addr pageAddress(Addr a) const
Determine the address of the page in which a lays.
Definition: base.cc:185
Addr pc
The program counter that generated this address.
Definition: base.hh:96
bool inMissQueue(Addr addr, bool is_secure) const
Determine if address is in cache miss queue.
Definition: base.cc:155
const bool useVirtualAddresses
Use Virtual Addresses for prefetching.
Definition: base.hh:293
unsigned int size
Size in bytes of the request triggering this event.
Definition: base.hh:104
Addr address
The address used to train and generate prefetches.
Definition: base.hh:94
virtual void setCache(BaseCache *_cache)
Definition: base.cc:104
bool samePage(Addr a, Addr b) const
Determine if addresses are on the same page.
Definition: base.cc:167
PrefetchListener(BasePrefetcher &_parent, ProbeManager *pm, const std::string &name, bool _isFill=false, bool _miss=false)
Definition: base.hh:72
T betoh(T value)
Definition: byteswap.hh:147
Addr blockAddress(Addr a) const
Determine the address of the block in which a lays.
Definition: base.cc:173
const bool onData
Consult prefetcher on data accesses?
Definition: base.hh:279
Addr getPaddr() const
Gets the physical address of the request.
Definition: base.hh:184
unsigned blkSize
The block size of the parent cache.
Definition: base.hh:264
virtual Tick nextPrefetchReadyTime() const =0
Addr paddress
Physical address, needed because address can be virtual.
Definition: base.hh:108
void regProbeListeners() override
Register probe points for this object.
Definition: base.cc:231
Bitfield< 0 > p
Stats::Scalar pfIssued
Definition: base.hh:323
const char data[]
uint8_t * data
Pointer to the associated request data.
Definition: base.hh:112
bool hasBeenPrefetched(Addr addr, bool is_secure) const
Definition: base.cc:161
virtual PacketPtr getPacket()=0
Abstract superclass for simulation objects.
Definition: sim_object.hh:96
void probeNotify(const PacketPtr &pkt, bool miss)
Process a notification event from the ProbeListener.
Definition: base.cc:203
MasterID getMasterId() const
Gets the requestor ID that generated this address.
Definition: base.hh:156
BasePrefetcher & parent
Definition: base.hh:79
bool hasPC() const
Returns true if the associated program counter is valid.
Definition: base.hh:147

Generated on Fri Feb 28 2020 16:26:58 for gem5 by doxygen 1.8.13