gem5  v20.1.0.0
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 "cpu/base.hh"
52 #include "mem/cache/base.hh"
53 #include "params/BasePrefetcher.hh"
54 #include "sim/system.hh"
55 
56 namespace Prefetcher {
57 
59  : address(addr), pc(pkt->req->hasPC() ? pkt->req->getPC() : 0),
60  requestorId(pkt->req->requestorId()), validPC(pkt->req->hasPC()),
61  secure(pkt->isSecure()), size(pkt->req->getSize()), write(pkt->isWrite()),
62  paddress(pkt->req->getPaddr()), cacheMiss(miss)
63 {
64  unsigned int req_size = pkt->req->getSize();
65  if (!write && miss) {
66  data = nullptr;
67  } else {
68  data = new uint8_t[req_size];
69  Addr offset = pkt->req->getPaddr() - pkt->getAddr();
70  std::memcpy(data, &(pkt->getConstPtr<uint8_t>()[offset]), req_size);
71  }
72 }
73 
75  : address(addr), pc(pfi.pc), requestorId(pfi.requestorId),
76  validPC(pfi.validPC), secure(pfi.secure), size(pfi.size),
77  write(pfi.write), paddress(pfi.paddress), cacheMiss(pfi.cacheMiss),
78  data(nullptr)
79 {
80 }
81 
82 void
84 {
85  if (isFill) {
86  parent.notifyFill(pkt);
87  } else {
88  parent.probeNotify(pkt, miss);
89  }
90 }
91 
92 Base::Base(const BasePrefetcherParams *p)
93  : ClockedObject(p), listeners(), cache(nullptr), blkSize(p->block_size),
94  lBlkSize(floorLog2(blkSize)), onMiss(p->on_miss), onRead(p->on_read),
95  onWrite(p->on_write), onData(p->on_data), onInst(p->on_inst),
96  requestorId(p->sys->getRequestorId(this)),
97  pageBytes(p->sys->getPageBytes()),
98  prefetchOnAccess(p->prefetch_on_access),
99  useVirtualAddresses(p->use_virtual_addresses),
101  usefulPrefetches(0), tlb(nullptr)
102 {
103 }
104 
105 void
107 {
108  assert(!cache);
109  cache = _cache;
110 
111  // If the cache has a different block size from the system's, save it
114 }
116  : Stats::Group(parent),
117  ADD_STAT(pfIssued, "number of hwpf issued")
118 {
119 }
120 
121 
122 bool
123 Base::observeAccess(const PacketPtr &pkt, bool miss) const
124 {
125  bool fetch = pkt->req->isInstFetch();
126  bool read = pkt->isRead();
127  bool inv = pkt->isInvalidate();
128 
129  if (pkt->req->isUncacheable()) return false;
130  if (fetch && !onInst) return false;
131  if (!fetch && !onData) return false;
132  if (!fetch && read && !onRead) return false;
133  if (!fetch && !read && !onWrite) return false;
134  if (!fetch && !read && inv) return false;
135  if (pkt->cmd == MemCmd::CleanEvict) return false;
136 
137  if (onMiss) {
138  return miss;
139  }
140 
141  return true;
142 }
143 
144 bool
145 Base::inCache(Addr addr, bool is_secure) const
146 {
147  return cache->inCache(addr, is_secure);
148 }
149 
150 bool
151 Base::inMissQueue(Addr addr, bool is_secure) const
152 {
153  return cache->inMissQueue(addr, is_secure);
154 }
155 
156 bool
157 Base::hasBeenPrefetched(Addr addr, bool is_secure) const
158 {
159  return cache->hasBeenPrefetched(addr, is_secure);
160 }
161 
162 bool
164 {
165  return roundDown(a, pageBytes) == roundDown(b, pageBytes);
166 }
167 
168 Addr
170 {
171  return a & ~((Addr)blkSize-1);
172 }
173 
174 Addr
176 {
177  return a >> lBlkSize;
178 }
179 
180 Addr
182 {
183  return roundDown(a, pageBytes);
184 }
185 
186 Addr
188 {
189  return a & (pageBytes - 1);
190 }
191 
192 Addr
194 {
195  return page + (blockIndex << lBlkSize);
196 }
197 
198 void
199 Base::probeNotify(const PacketPtr &pkt, bool miss)
200 {
201  // Don't notify prefetcher on SWPrefetch, cache maintenance
202  // operations or for writes that we are coaslescing.
203  if (pkt->cmd.isSWPrefetch()) return;
204  if (pkt->req->isCacheMaintenance()) return;
205  if (pkt->isWrite() && cache != nullptr && cache->coalesce()) return;
206  if (!pkt->req->hasPaddr()) {
207  panic("Request must have a physical address");
208  }
209 
210  if (hasBeenPrefetched(pkt->getAddr(), pkt->isSecure())) {
211  usefulPrefetches += 1;
212  }
213 
214  // Verify this access type is observed by prefetcher
215  if (observeAccess(pkt, miss)) {
216  if (useVirtualAddresses && pkt->req->hasVaddr()) {
217  PrefetchInfo pfi(pkt, pkt->req->getVaddr(), miss);
218  notify(pkt, pfi);
219  } else if (!useVirtualAddresses) {
220  PrefetchInfo pfi(pkt, pkt->req->getPaddr(), miss);
221  notify(pkt, pfi);
222  }
223  }
224 }
225 
226 void
228 {
234  if (listeners.empty() && cache != nullptr) {
236  listeners.push_back(new PrefetchListener(*this, pm, "Miss", false,
237  true));
238  listeners.push_back(new PrefetchListener(*this, pm, "Fill", true,
239  false));
240  if (prefetchOnAccess) {
241  listeners.push_back(new PrefetchListener(*this, pm, "Hit", false,
242  false));
243  }
244  }
245 }
246 
247 void
249 {
250  ProbeManager *pm(obj->getProbeManager());
251  listeners.push_back(new PrefetchListener(*this, pm, name));
252 }
253 
254 void
256 {
257  fatal_if(tlb != nullptr, "Only one TLB can be registered");
258  tlb = t;
259 }
260 
261 } // namespace Prefetcher
Prefetcher::Base::onData
const bool onData
Consult prefetcher on data accesses?
Definition: base.hh:277
Prefetcher::Base::cache
BaseCache * cache
Pointr to the parent cache.
Definition: base.hh:259
roundDown
T roundDown(const T &val, const U &align)
This function is used to align addresses in memory.
Definition: intmath.hh:150
Prefetcher::Base::PrefetchInfo::PrefetchInfo
PrefetchInfo(PacketPtr pkt, Addr addr, bool miss)
Constructs a PrefetchInfo using a PacketPtr.
Definition: base.cc:58
MemCmd::isSWPrefetch
bool isSWPrefetch() const
Definition: packet.hh:224
base.hh
system.hh
data
const char data[]
Definition: circlebuf.test.cc:42
Prefetcher::Base::useVirtualAddresses
const bool useVirtualAddresses
Use Virtual Addresses for prefetching.
Definition: base.hh:291
Packet::getAddr
Addr getAddr() const
Definition: packet.hh:754
Prefetcher::Base::StatGroup::StatGroup
StatGroup(Stats::Group *parent)
Definition: base.cc:115
Prefetcher::Base::blkSize
unsigned blkSize
The block size of the parent cache.
Definition: base.hh:262
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
Packet::isRead
bool isRead() const
Definition: packet.hh:556
MemCmd::CleanEvict
@ CleanEvict
Definition: packet.hh:91
BaseCache::hasBeenPrefetched
bool hasBeenPrefetched(Addr addr, bool is_secure) const
Definition: base.hh:1207
Packet::isInvalidate
bool isInvalidate() const
Definition: packet.hh:571
Packet::req
RequestPtr req
A pointer to the original request.
Definition: packet.hh:340
Prefetcher::Base::inCache
bool inCache(Addr addr, bool is_secure) const
Determine if address is in cache.
Definition: base.cc:145
floorLog2
std::enable_if< std::is_integral< T >::value, int >::type floorLog2(T x)
Definition: intmath.hh:63
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
BaseTLB
Definition: tlb.hh:50
BaseCache::coalesce
bool coalesce() const
Checks if the cache is coalescing writes.
Definition: base.cc:1598
Packet::isSecure
bool isSecure() const
Definition: packet.hh:783
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::prefetchStats
Prefetcher::Base::StatGroup prefetchStats
X86ISA::inv
Bitfield< 23 > inv
Definition: misc.hh:808
base.hh
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::Base
Base(const BasePrefetcherParams *p)
Definition: base.cc:92
ADD_STAT
#define ADD_STAT(n,...)
Convenience macro to add a stat to a statistics group.
Definition: group.hh:67
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
MipsISA::pc
Bitfield< 4 > pc
Definition: pra_constants.hh:240
Prefetcher::Base::setCache
virtual void setCache(BaseCache *_cache)
Definition: base.cc:106
BaseCache::inMissQueue
bool inMissQueue(Addr addr, bool is_secure) const
Definition: base.hh:1216
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
BaseCache::getBlockSize
unsigned getBlockSize() const
Query block size of a cache.
Definition: base.hh:1090
Prefetcher::Base::PrefetchListener::notify
void notify(const PacketPtr &pkt) override
Definition: base.cc:83
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
Prefetcher::Base::addTLB
void addTLB(BaseTLB *tlb)
Add a BaseTLB object to be used whenever a translation is needed.
Definition: base.cc:255
SimObject::getProbeManager
ProbeManager * getProbeManager()
Get the probe manager for this object.
Definition: sim_object.cc:117
SimObject::name
virtual const std::string name() const
Definition: sim_object.hh:133
Prefetcher::Base::blockIndex
Addr blockIndex(Addr a) const
Determine the address of a at block granularity.
Definition: base.cc:175
Packet::cmd
MemCmd cmd
The command field of the packet.
Definition: packet.hh:335
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
base.hh
ArmISA::t
Bitfield< 5 > t
Definition: miscregs_types.hh:67
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
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
Packet::isWrite
bool isWrite() const
Definition: packet.hh:557
Prefetcher::Base::PrefetchInfo::write
bool write
Whether this event comes from a write request.
Definition: base.hh:104
Stats
Definition: statistics.cc:61
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
intmath.hh
Prefetcher::Base::inMissQueue
bool inMissQueue(Addr addr, bool is_secure) const
Determine if address is in cache miss queue.
Definition: base.cc:151
Prefetcher::Base::pageBytes
const Addr pageBytes
Definition: base.hh:285
fatal_if
#define fatal_if(cond,...)
Conditional fatal macro that checks the supplied condition and only causes a fatal error if the condi...
Definition: logging.hh:219
Prefetcher::Base::samePage
bool samePage(Addr a, Addr b) const
Determine if addresses are on the same page.
Definition: base.cc:163
BaseCache::inCache
bool inCache(Addr addr, bool is_secure) const
Definition: base.hh:1203
Prefetcher::Base::probeNotify
void probeNotify(const PacketPtr &pkt, bool miss)
Process a notification event from the ProbeListener.
Definition: base.cc:199
Packet::getConstPtr
const T * getConstPtr() const
Definition: packet.hh:1166
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
ArmISA::isSecure
bool isSecure(ThreadContext *tc)
Definition: utility.cc:174
panic
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:171
ArmISA::offset
Bitfield< 23, 0 > offset
Definition: types.hh:153
SimObject
Abstract superclass for simulation objects.
Definition: sim_object.hh:92

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