gem5  v21.0.1.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 "mem/cache/base.hh"
52 #include "params/BasePrefetcher.hh"
53 #include "sim/system.hh"
54 
55 namespace Prefetcher {
56 
58  : address(addr), pc(pkt->req->hasPC() ? pkt->req->getPC() : 0),
59  requestorId(pkt->req->requestorId()), validPC(pkt->req->hasPC()),
60  secure(pkt->isSecure()), size(pkt->req->getSize()), write(pkt->isWrite()),
61  paddress(pkt->req->getPaddr()), cacheMiss(miss)
62 {
63  unsigned int req_size = pkt->req->getSize();
64  if (!write && miss) {
65  data = nullptr;
66  } else {
67  data = new uint8_t[req_size];
68  Addr offset = pkt->req->getPaddr() - pkt->getAddr();
69  std::memcpy(data, &(pkt->getConstPtr<uint8_t>()[offset]), req_size);
70  }
71 }
72 
74  : address(addr), pc(pfi.pc), requestorId(pfi.requestorId),
75  validPC(pfi.validPC), secure(pfi.secure), size(pfi.size),
76  write(pfi.write), paddress(pfi.paddress), cacheMiss(pfi.cacheMiss),
77  data(nullptr)
78 {
79 }
80 
81 void
83 {
84  if (isFill) {
85  parent.notifyFill(pkt);
86  } else {
87  parent.probeNotify(pkt, miss);
88  }
89 }
90 
91 Base::Base(const BasePrefetcherParams &p)
92  : ClockedObject(p), listeners(), cache(nullptr), blkSize(p.block_size),
93  lBlkSize(floorLog2(blkSize)), onMiss(p.on_miss), onRead(p.on_read),
94  onWrite(p.on_write), onData(p.on_data), onInst(p.on_inst),
95  requestorId(p.sys->getRequestorId(this)),
96  pageBytes(p.sys->getPageBytes()),
97  prefetchOnAccess(p.prefetch_on_access),
98  useVirtualAddresses(p.use_virtual_addresses),
100  usefulPrefetches(0), tlb(nullptr)
101 {
102 }
103 
104 void
106 {
107  assert(!cache);
108  cache = _cache;
109 
110  // If the cache has a different block size from the system's, save it
113 }
115  : Stats::Group(parent),
116  ADD_STAT(pfIssued, UNIT_COUNT, "number of hwpf issued")
117 {
118 }
119 
120 
121 bool
122 Base::observeAccess(const PacketPtr &pkt, bool miss) const
123 {
124  bool fetch = pkt->req->isInstFetch();
125  bool read = pkt->isRead();
126  bool inv = pkt->isInvalidate();
127 
128  if (!miss && !prefetchOnAccess) return false;
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  listeners.push_back(new PrefetchListener(*this, pm, "Hit", false,
241  false));
242  }
243 }
244 
245 void
247 {
248  ProbeManager *pm(obj->getProbeManager());
249  listeners.push_back(new PrefetchListener(*this, pm, name));
250 }
251 
252 void
254 {
255  fatal_if(tlb != nullptr, "Only one TLB can be registered");
256  tlb = t;
257 }
258 
259 } // 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:57
MemCmd::isSWPrefetch
bool isSWPrefetch() const
Definition: packet.hh:225
base.hh
system.hh
data
const char data[]
Definition: circlebuf.test.cc:47
Prefetcher::Base::useVirtualAddresses
const bool useVirtualAddresses
Use Virtual Addresses for prefetching.
Definition: base.hh:291
Packet::getAddr
Addr getAddr() const
Definition: packet.hh:755
Prefetcher::Base::StatGroup::StatGroup
StatGroup(Stats::Group *parent)
Definition: base.cc:114
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:557
MemCmd::CleanEvict
@ CleanEvict
Definition: packet.hh:92
BaseCache::hasBeenPrefetched
bool hasBeenPrefetched(Addr addr, bool is_secure) const
Definition: base.hh:1270
Packet::isInvalidate
bool isInvalidate() const
Definition: packet.hh:572
Packet::req
RequestPtr req
A pointer to the original request.
Definition: packet.hh:341
Prefetcher::Base::inCache
bool inCache(Addr addr, bool is_secure) const
Determine if address is in cache.
Definition: base.cc:145
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:1712
Packet::isSecure
bool isSecure() const
Definition: packet.hh:784
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:122
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:91
ADD_STAT
#define ADD_STAT(n,...)
Convenience macro to add a stat to a statistics group.
Definition: group.hh:71
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:105
BaseCache::inMissQueue
bool inMissQueue(Addr addr, bool is_secure) const
Definition: base.hh:1279
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:1153
Prefetcher::Base::PrefetchListener::notify
void notify(const PacketPtr &pkt) override
Definition: base.cc:82
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
UNIT_COUNT
#define UNIT_COUNT
Definition: units.hh:49
Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:148
Prefetcher::Base::addTLB
void addTLB(BaseTLB *tlb)
Add a BaseTLB object to be used whenever a translation is needed.
Definition: base.cc:253
SimObject::getProbeManager
ProbeManager * getProbeManager()
Get the probe manager for this object.
Definition: sim_object.cc:114
X86ISA::addr
Bitfield< 3 > addr
Definition: types.hh:80
SimObject::name
virtual const std::string name() const
Definition: sim_object.hh:182
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:336
floorLog2
std::enable_if_t< std::is_integral< T >::value, int > floorLog2(T x)
Definition: intmath.hh:63
ProbeManager
ProbeManager is a conduit class that lives on each SimObject, and is used to match up probe listeners...
Definition: probe.hh:154
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
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:246
Packet
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:258
Stats::Group
Statistics container.
Definition: group.hh:87
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:558
Prefetcher::Base::PrefetchInfo::write
bool write
Whether this event comes from a write request.
Definition: base.hh:104
Stats
Definition: statistics.cc:53
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:1266
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:1167
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:112
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:141

Generated on Tue Jun 22 2021 15:28:25 for gem5 by doxygen 1.8.17