gem5 v24.0.0.0
Loading...
Searching...
No Matches
exec_context.hh
Go to the documentation of this file.
1/*
2 * Copyright (c) 2014-2018, 2020-2021 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) 2002-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
41#ifndef __CPU_SIMPLE_EXEC_CONTEXT_HH__
42#define __CPU_SIMPLE_EXEC_CONTEXT_HH__
43
44#include "base/types.hh"
45#include "cpu/base.hh"
46#include "cpu/exec_context.hh"
47#include "cpu/reg_class.hh"
48#include "cpu/simple/base.hh"
50#include "cpu/translation.hh"
51#include "mem/request.hh"
52
53namespace gem5
54{
55
56class BaseSimpleCPU;
57
59{
60 public:
63
64 // This is the offset from the current pc that fetch should be performed
66 // This flag says to stay at the current pc. This is useful for
67 // instructions which go beyond MachInst boundaries.
69
70 // Branch prediction
71 std::unique_ptr<PCStateBase> predPC;
72
76 // Number of simulated loads
78 // Number of cycles stalled for I-cache responses
80 // Number of cycles stalled for D-cache responses
82
84 {
86 : statistics::Group(cpu,
87 csprintf("exec_context.thread_%i",
88 thread->threadId()).c_str()),
89 ADD_STAT(numMatAluAccesses, statistics::units::Count::get(),
90 "Number of matrix alu accesses"),
91 ADD_STAT(numCallsReturns, statistics::units::Count::get(),
92 "Number of times a function call or return occured"),
93 ADD_STAT(numMatInsts, statistics::units::Count::get(),
94 "Number of matrix instructions"),
95 ADD_STAT(numIdleCycles, statistics::units::Cycle::get(),
96 "Number of idle cycles"),
97 ADD_STAT(numBusyCycles, statistics::units::Cycle::get(),
98 "Number of busy cycles"),
99 ADD_STAT(notIdleFraction, statistics::units::Ratio::get(),
100 "Percentage of non-idle cycles"),
101 ADD_STAT(idleFraction, statistics::units::Ratio::get(),
102 "Percentage of idle cycles"),
103 ADD_STAT(numPredictedBranches, statistics::units::Count::get(),
104 "Number of branches predicted as taken"),
105 ADD_STAT(numBranchMispred, statistics::units::Count::get(),
106 "Number of branch mispredictions"),
108 &(cpu->executeStats[thread->threadId()]->numIntRegReads),
109 &(cpu->executeStats[thread->threadId()]->numFpRegReads),
110 &(cpu->executeStats[thread->threadId()]->numVecRegReads),
111 &(cpu->executeStats[thread->threadId()]->numVecRegReads),
112 &(cpu->executeStats[thread->threadId()]->numVecPredRegReads),
113 &(cpu->executeStats[thread->threadId()]->numCCRegReads),
115 },
117 &(cpu->executeStats[thread->threadId()]->numIntRegWrites),
118 &(cpu->executeStats[thread->threadId()]->numFpRegWrites),
119 &(cpu->executeStats[thread->threadId()]->numVecRegWrites),
120 &(cpu->executeStats[thread->threadId()]->numVecRegWrites),
121 &(cpu->executeStats[thread->threadId()]
122 ->numVecPredRegWrites),
123 &(cpu->executeStats[thread->threadId()]->numCCRegWrites),
125 }
126 {
130
133
136 }
137
138 // Number of matrix alu accesses
140
141 // Number of function calls/returns
143
144 // Number of matrix instructions
146
147 // Number of matrix register file accesses
150
151 // Number of idle cycles
153
154 // Number of busy cycles
156
157 // Number of idle cycles
160
167
168 std::array<statistics::Scalar *, CCRegClass + 1> numRegReads;
169 std::array<statistics::Scalar *, CCRegClass + 1> numRegWrites;
170
172
173 public:
176 : cpu(_cpu), thread(_thread), fetchOffset(0), stayAtPC(false),
177 numInst(0), numOp(0), numLoad(0), lastIcacheStall(0),
179 { }
180
181 RegVal
182 getRegOperand(const StaticInst *si, int idx) override
183 {
184 const RegId &reg = si->srcRegIdx(idx);
185 if (reg.is(InvalidRegClass))
186 return 0;
187 (*execContextStats.numRegReads[reg.classValue()])++;
188 return thread->getReg(reg);
189 }
190
191 void
192 getRegOperand(const StaticInst *si, int idx, void *val) override
193 {
194 const RegId &reg = si->srcRegIdx(idx);
195 (*execContextStats.numRegReads[reg.classValue()])++;
196 thread->getReg(reg, val);
197 }
198
199 void *
200 getWritableRegOperand(const StaticInst *si, int idx) override
201 {
202 const RegId &reg = si->destRegIdx(idx);
203 (*execContextStats.numRegWrites[reg.classValue()])++;
204 return thread->getWritableReg(reg);
205 }
206
207 void
208 setRegOperand(const StaticInst *si, int idx, RegVal val) override
209 {
210 const RegId &reg = si->destRegIdx(idx);
211 if (reg.is(InvalidRegClass))
212 return;
213 (*execContextStats.numRegWrites[reg.classValue()])++;
214 thread->setReg(reg, val);
215 }
216
217 void
218 setRegOperand(const StaticInst *si, int idx, const void *val) override
219 {
220 const RegId &reg = si->destRegIdx(idx);
221 (*execContextStats.numRegWrites[reg.classValue()])++;
222 thread->setReg(reg, val);
223 }
224
225 RegVal
226 readMiscRegOperand(const StaticInst *si, int idx) override
227 {
228 cpu->executeStats[thread->threadId()]->numMiscRegReads++;
229 const RegId& reg = si->srcRegIdx(idx);
230 assert(reg.is(MiscRegClass));
231 return thread->readMiscReg(reg.index());
232 }
233
234 void
235 setMiscRegOperand(const StaticInst *si, int idx, RegVal val) override
236 {
237 cpu->executeStats[thread->threadId()]->numMiscRegWrites++;
238 const RegId& reg = si->destRegIdx(idx);
239 assert(reg.is(MiscRegClass));
240 thread->setMiscReg(reg.index(), val);
241 }
242
247 RegVal
248 readMiscReg(int misc_reg) override
249 {
250 cpu->executeStats[thread->threadId()]->numMiscRegReads++;
251 return thread->readMiscReg(misc_reg);
252 }
253
258 void
259 setMiscReg(int misc_reg, RegVal val) override
260 {
261 cpu->executeStats[thread->threadId()]->numMiscRegWrites++;
262 thread->setMiscReg(misc_reg, val);
263 }
264
265 const PCStateBase &
266 pcState() const override
267 {
268 return thread->pcState();
269 }
270
271 void
272 pcState(const PCStateBase &val) override
273 {
275 }
276
277 Fault
278 readMem(Addr addr, uint8_t *data, unsigned int size,
280 const std::vector<bool>& byte_enable)
281 override
282 {
283 assert(byte_enable.size() == size);
284 return cpu->readMem(addr, data, size, flags, byte_enable);
285 }
286
287 Fault
288 initiateMemRead(Addr addr, unsigned int size,
290 const std::vector<bool>& byte_enable)
291 override
292 {
293 assert(byte_enable.size() == size);
294 return cpu->initiateMemRead(addr, size, flags, byte_enable);
295 }
296
297 Fault
298 writeMem(uint8_t *data, unsigned int size, Addr addr,
299 Request::Flags flags, uint64_t *res,
300 const std::vector<bool>& byte_enable)
301 override
302 {
303 assert(byte_enable.size() == size);
304 return cpu->writeMem(data, size, addr, flags, res,
305 byte_enable);
306 }
307
308 Fault
309 amoMem(Addr addr, uint8_t *data, unsigned int size,
310 Request::Flags flags, AtomicOpFunctorPtr amo_op) override
311 {
312 return cpu->amoMem(addr, data, size, flags, std::move(amo_op));
313 }
314
315 Fault
316 initiateMemAMO(Addr addr, unsigned int size,
318 AtomicOpFunctorPtr amo_op) override
319 {
320 return cpu->initiateMemAMO(addr, size, flags, std::move(amo_op));
321 }
322
323 Fault
328
332 void
333 setStCondFailures(unsigned int sc_failures) override
334 {
335 thread->setStCondFailures(sc_failures);
336 }
337
341 unsigned int
342 readStCondFailures() const override
343 {
344 return thread->readStCondFailures();
345 }
346
348 ThreadContext *tcBase() const override { return thread->getTC(); }
349
350 bool
351 readPredicate() const override
352 {
353 return thread->readPredicate();
354 }
355
356 void
357 setPredicate(bool val) override
358 {
360
361 if (cpu->traceData) {
363 }
364 }
365
366 bool
367 readMemAccPredicate() const override
368 {
369 return thread->readMemAccPredicate();
370 }
371
372 void
373 setMemAccPredicate(bool val) override
374 {
376 }
377
378 uint64_t
379 getHtmTransactionUid() const override
380 {
381 return tcBase()->getHtmCheckpointPtr()->getHtmUid();
382 }
383
384 uint64_t
385 newHtmTransactionUid() const override
386 {
387 return tcBase()->getHtmCheckpointPtr()->newHtmUid();
388 }
389
390 bool
391 inHtmTransactionalState() const override
392 {
393 return (getHtmTransactionalDepth() > 0);
394 }
395
396 uint64_t
402
406 void
407 demapPage(Addr vaddr, uint64_t asn) override
408 {
409 thread->demapPage(vaddr, asn);
410 }
411
412 void
413 armMonitor(Addr address) override
414 {
415 cpu->armMonitor(thread->threadId(), address);
416 }
417
418 bool
419 mwait(PacketPtr pkt) override
420 {
421 return cpu->mwait(thread->threadId(), pkt);
422 }
423
424 void
426 {
428 }
429
431 getAddrMonitor() override
432 {
434 }
435};
436
437} // namespace gem5
438
439#endif // __CPU_EXEC_CONTEXT_HH__
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,...
const char data[]
void mwaitAtomic(ThreadID tid, ThreadContext *tc, BaseMMU *mmu)
Definition base.cc:277
AddressMonitor * getCpuAddrMonitor(ThreadID tid)
Definition base.hh:656
bool mwait(ThreadID tid, PacketPtr pkt)
Definition base.cc:254
gem5::BaseCPU::BaseCPUStats baseStats
std::vector< std::unique_ptr< ExecuteCPUStats > > executeStats
Definition base.hh:820
void armMonitor(ThreadID tid, Addr address)
Definition base.cc:242
virtual Fault initiateMemRead(Addr addr, unsigned size, Request::Flags flags, const std::vector< bool > &byte_enable=std::vector< bool >())
Definition base.hh:156
virtual Fault readMem(Addr addr, uint8_t *data, unsigned size, Request::Flags flags, const std::vector< bool > &byte_enable=std::vector< bool >())
Definition base.hh:149
virtual Fault initiateMemMgmtCmd(Request::Flags flags)=0
Memory management commands such as hardware transactional memory commands or TLB invalidation command...
virtual Fault writeMem(uint8_t *data, unsigned size, Addr addr, Request::Flags flags, uint64_t *res, const std::vector< bool > &byte_enable=std::vector< bool >())
Definition base.hh:163
virtual Fault amoMem(Addr addr, uint8_t *data, unsigned size, Request::Flags flags, AtomicOpFunctorPtr amo_op)
Definition base.hh:171
virtual Fault initiateMemAMO(Addr addr, unsigned size, Request::Flags flags, AtomicOpFunctorPtr amo_op)
Definition base.hh:178
trace::InstRecord * traceData
Definition base.hh:97
The ExecContext is an abstract base class the provides the interface used by the ISA to manipulate th...
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition packet.hh:295
Register ID: describe an architectural register with its class and index.
Definition reg_class.hh:94
Fault initiateMemRead(Addr addr, unsigned int size, Request::Flags flags, const std::vector< bool > &byte_enable) override
Initiate a timing memory read operation.
Fault readMem(Addr addr, uint8_t *data, unsigned int size, Request::Flags flags, const std::vector< bool > &byte_enable) override
Perform an atomic memory read operation.
void setStCondFailures(unsigned int sc_failures) override
Sets the number of consecutive store conditional failures.
unsigned int readStCondFailures() const override
Returns the number of consecutive store conditional failures.
bool readPredicate() const override
uint64_t getHtmTransactionalDepth() const override
void demapPage(Addr vaddr, uint64_t asn) override
Invalidate a page in the DTLB and ITLB.
void mwaitAtomic(ThreadContext *tc) override
Counter numInst
PER-THREAD STATS.
AddressMonitor * getAddrMonitor() override
void setMemAccPredicate(bool val) override
void getRegOperand(const StaticInst *si, int idx, void *val) override
void setMiscRegOperand(const StaticInst *si, int idx, RegVal val) override
RegVal getRegOperand(const StaticInst *si, int idx) override
RegVal readMiscReg(int misc_reg) override
Reads a miscellaneous register, handling any architectural side effects due to reading that register.
void setPredicate(bool val) override
SimpleExecContext(BaseSimpleCPU *_cpu, SimpleThread *_thread)
Constructor.
void setRegOperand(const StaticInst *si, int idx, RegVal val) override
std::unique_ptr< PCStateBase > predPC
Fault initiateMemAMO(Addr addr, unsigned int size, Request::Flags flags, AtomicOpFunctorPtr amo_op) override
For timing-mode contexts, initiate an atomic AMO (atomic read-modify-write memory operation)
bool readMemAccPredicate() const override
uint64_t newHtmTransactionUid() const override
void setRegOperand(const StaticInst *si, int idx, const void *val) override
bool inHtmTransactionalState() const override
Fault writeMem(uint8_t *data, unsigned int size, Addr addr, Request::Flags flags, uint64_t *res, const std::vector< bool > &byte_enable) override
For atomic-mode contexts, perform an atomic memory write operation.
bool mwait(PacketPtr pkt) override
void setMiscReg(int misc_reg, RegVal val) override
Sets a miscellaneous register, handling any architectural side effects due to writing that register.
Fault initiateMemMgmtCmd(Request::Flags flags) override
Initiate a memory management command with no valid address.
void pcState(const PCStateBase &val) override
gem5::SimpleExecContext::ExecContextStats execContextStats
Fault amoMem(Addr addr, uint8_t *data, unsigned int size, Request::Flags flags, AtomicOpFunctorPtr amo_op) override
For atomic-mode contexts, perform an atomic AMO (a.k.a., Atomic Read-Modify-Write Memory Operation)
RegVal readMiscRegOperand(const StaticInst *si, int idx) override
uint64_t getHtmTransactionUid() const override
const PCStateBase & pcState() const override
ThreadContext * tcBase() const override
Returns a pointer to the ThreadContext.
void armMonitor(Addr address) override
void * getWritableRegOperand(const StaticInst *si, int idx) override
The SimpleThread object provides a combination of the ThreadState object and the ThreadContext interf...
int threadId() const override
bool readPredicate() const
void setPredicate(bool val)
void setStCondFailures(unsigned sc_failures) override
const PCStateBase & pcState() const override
void setMiscReg(RegIndex misc_reg, RegVal val) override
void demapPage(Addr vaddr, uint64_t asn)
void * getWritableReg(const RegId &arch_reg) override
unsigned readStCondFailures() const override
void setReg(const RegId &arch_reg, RegVal val) override
ThreadContext * getTC()
Returns the pointer to this SimpleThread's ThreadContext.
RegVal readMiscReg(RegIndex misc_reg) override
void setMemAccPredicate(bool val)
RegVal getReg(const RegId &arch_reg) const override
Base, ISA-independent static instruction class.
ThreadContext is the external interface to all thread state for anything outside of the CPU.
virtual BaseHTMCheckpointPtr & getHtmCheckpointPtr()=0
A stat that calculates the per tick average of a value.
Derived & prereq(const Stat &prereq)
Set the prerequisite stat and marks this stat to print at the end of simulation.
A formula for statistics that is calculated when printed.
Statistics container.
Definition group.hh:93
This is a simple scalar statistic, like a counter.
void setPredicate(bool val)
STL vector class.
Definition stl.hh:37
#define ADD_STAT(n,...)
Convenience macro to add a stat to a statistics group.
Definition group.hh:75
std::unique_ptr< AtomicOpFunctor > AtomicOpFunctorPtr
Definition amo.hh:269
uint8_t flags
Definition helpers.cc:87
Bitfield< 6 > si
Bitfield< 5, 3 > reg
Definition types.hh:92
Bitfield< 63 > val
Definition misc.hh:804
Bitfield< 3 > addr
Definition types.hh:84
Temp constant(T val)
double Counter
All counters are of 64-bit values.
Definition types.hh:46
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
std::shared_ptr< FaultBase > Fault
Definition types.hh:249
uint64_t RegVal
Definition types.hh:173
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition types.hh:147
std::string csprintf(const char *format, const Args &...args)
Definition cprintf.hh:161
@ InvalidRegClass
Definition reg_class.hh:71
@ MiscRegClass
Control (misc) register.
Definition reg_class.hh:70
Declaration of a request, the overall memory request consisting of the parts of the request that are ...
statistics::Scalar numCycles
Definition base.hh:640
std::array< statistics::Scalar *, CCRegClass+1 > numRegReads
statistics::Scalar numBranchMispred
Number of misprediced branches.
std::array< statistics::Scalar *, CCRegClass+1 > numRegWrites
ExecContextStats(BaseSimpleCPU *cpu, SimpleThread *thread)

Generated on Tue Jun 18 2024 16:24:02 for gem5 by doxygen 1.11.0