gem5 [DEVELOP-FOR-25.1]
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 {
87 cpu, csprintf("exec_context.thread_%i", thread->threadId())
88 .c_str()),
90 "Number of matrix alu accesses"),
91 ADD_STAT(numMatInsts, statistics::units::Count::get(),
92 "Number of matrix instructions"),
93 ADD_STAT(numIdleCycles, statistics::units::Cycle::get(),
94 "Number of idle cycles"),
95 ADD_STAT(numBusyCycles, statistics::units::Cycle::get(),
96 "Number of busy cycles"),
98 "Percentage of non-idle cycles"),
99 ADD_STAT(idleFraction, statistics::units::Ratio::get(),
100 "Percentage of idle cycles"),
102 "Number of branches predicted as taken"),
104 "Number of branch mispredictions"),
106 &(cpu->executeStats[thread->threadId()]->numIntRegReads),
107 &(cpu->executeStats[thread->threadId()]->numFpRegReads),
108 &(cpu->executeStats[thread->threadId()]->numVecRegReads),
109 &(cpu->executeStats[thread->threadId()]->numVecRegReads),
110 &(cpu->executeStats[thread->threadId()]->numVecPredRegReads),
112 &(cpu->executeStats[thread->threadId()]->numCCRegReads)},
114 &(cpu->executeStats[thread->threadId()]->numIntRegWrites),
115 &(cpu->executeStats[thread->threadId()]->numFpRegWrites),
116 &(cpu->executeStats[thread->threadId()]->numVecRegWrites),
117 &(cpu->executeStats[thread->threadId()]->numVecRegWrites),
118 &(cpu->executeStats[thread->threadId()]
119 ->numVecPredRegWrites),
121 &(cpu->executeStats[thread->threadId()]->numCCRegWrites)}
122 {
124 numIdleCycles = idleFraction * cpu->baseStats.numCycles;
125 numBusyCycles = notIdleFraction * cpu->baseStats.numCycles;
126
128 .prereq(numPredictedBranches);
129
131 .prereq(numBranchMispred);
132 }
133
134 // Number of matrix alu accesses
136
137 // Number of matrix instructions
139
140 // Number of matrix register file accesses
143
144 // Number of idle cycles
146
147 // Number of busy cycles
149
150 // Number of idle cycles
153
160
161 std::array<statistics::Scalar *, CCRegClass + 1> numRegReads;
162 std::array<statistics::Scalar *, CCRegClass + 1> numRegWrites;
163
165
167 {
169 : statistics::Group(cpu),
170 ADD_STAT(issuedInstType, statistics::units::Count::get(),
171 "Number of insts issued per FU, per thread")
172 {
173 issuedInstType.init(cpu->numThreads, enums::Num_OpClass)
175 issuedInstType.ysubnames(enums::OpClassStrings);
176 }
178
180
181 public:
184 : cpu(_cpu),
185 thread(_thread),
186 fetchOffset(0),
187 stayAtPC(false),
188 numInst(0),
189 numOp(0),
190 numLoad(0),
195 { }
196
197 RegVal
198 getRegOperand(const StaticInst *si, int idx) override
199 {
200 const RegId &reg = si->srcRegIdx(idx);
201 if (reg.is(InvalidRegClass))
202 return 0;
203 (*execContextStats.numRegReads[reg.classValue()])++;
204 return thread->getReg(reg);
205 }
206
207 void
208 getRegOperand(const StaticInst *si, int idx, void *val) override
209 {
210 const RegId &reg = si->srcRegIdx(idx);
211 (*execContextStats.numRegReads[reg.classValue()])++;
212 thread->getReg(reg, val);
213 }
214
215 void *
216 getWritableRegOperand(const StaticInst *si, int idx) override
217 {
218 const RegId &reg = si->destRegIdx(idx);
219 (*execContextStats.numRegWrites[reg.classValue()])++;
220 return thread->getWritableReg(reg);
221 }
222
223 void
224 setRegOperand(const StaticInst *si, int idx, RegVal val) override
225 {
226 const RegId &reg = si->destRegIdx(idx);
227 if (reg.is(InvalidRegClass))
228 return;
229 (*execContextStats.numRegWrites[reg.classValue()])++;
230 thread->setReg(reg, val);
231 }
232
233 void
234 setRegOperand(const StaticInst *si, int idx, const void *val) override
235 {
236 const RegId &reg = si->destRegIdx(idx);
237 (*execContextStats.numRegWrites[reg.classValue()])++;
238 thread->setReg(reg, val);
239 }
240
241 RegVal
242 readMiscRegOperand(const StaticInst *si, int idx) override
243 {
244 cpu->executeStats[thread->threadId()]->numMiscRegReads++;
245 const RegId& reg = si->srcRegIdx(idx);
246 assert(reg.is(MiscRegClass));
247 return thread->readMiscReg(reg.index());
248 }
249
250 void
251 setMiscRegOperand(const StaticInst *si, int idx, RegVal val) override
252 {
253 cpu->executeStats[thread->threadId()]->numMiscRegWrites++;
254 const RegId& reg = si->destRegIdx(idx);
255 assert(reg.is(MiscRegClass));
256 thread->setMiscReg(reg.index(), val);
257 }
258
263 RegVal
264 readMiscReg(int misc_reg) override
265 {
266 cpu->executeStats[thread->threadId()]->numMiscRegReads++;
267 return thread->readMiscReg(misc_reg);
268 }
269
274 void
276 {
277 cpu->executeStats[thread->threadId()]->numMiscRegWrites++;
278 thread->setMiscReg(misc_reg, val);
279 }
280
281 const PCStateBase &
282 pcState() const override
283 {
284 return thread->pcState();
285 }
286
287 void
288 pcState(const PCStateBase &val) override
289 {
290 thread->pcState(val);
291 }
292
293 Fault
294 readMem(Addr addr, uint8_t *data, unsigned int size,
295 Request::Flags flags,
296 const std::vector<bool>& byte_enable)
297 override
298 {
299 assert(byte_enable.size() == size);
300 return cpu->readMem(addr, data, size, flags, byte_enable);
301 }
302
303 Fault
304 initiateMemRead(Addr addr, unsigned int size,
305 Request::Flags flags,
306 const std::vector<bool>& byte_enable)
307 override
308 {
309 assert(byte_enable.size() == size);
310 return cpu->initiateMemRead(addr, size, flags, byte_enable);
311 }
312
313 Fault
314 writeMem(uint8_t *data, unsigned int size, Addr addr,
315 Request::Flags flags, uint64_t *res,
316 const std::vector<bool>& byte_enable)
317 override
318 {
319 assert(byte_enable.size() == size);
320 return cpu->writeMem(data, size, addr, flags, res,
321 byte_enable);
322 }
323
324 Fault
325 amoMem(Addr addr, uint8_t *data, unsigned int size,
326 Request::Flags flags, AtomicOpFunctorPtr amo_op) override
327 {
328 return cpu->amoMem(addr, data, size, flags, std::move(amo_op));
329 }
330
331 Fault
332 initiateMemAMO(Addr addr, unsigned int size,
333 Request::Flags flags,
334 AtomicOpFunctorPtr amo_op) override
335 {
336 return cpu->initiateMemAMO(addr, size, flags, std::move(amo_op));
337 }
338
339 Fault
341 {
342 return cpu->initiateMemMgmtCmd(flags);
343 }
344
348 void
349 setStCondFailures(unsigned int sc_failures) override
350 {
351 thread->setStCondFailures(sc_failures);
352 }
353
357 unsigned int
358 readStCondFailures() const override
359 {
360 return thread->readStCondFailures();
361 }
362
364 ThreadContext *tcBase() const override { return thread->getTC(); }
365
366 bool
367 readPredicate() const override
368 {
369 return thread->readPredicate();
370 }
371
372 void
373 setPredicate(bool val) override
374 {
375 thread->setPredicate(val);
376
377 if (cpu->traceData) {
378 cpu->traceData->setPredicate(val);
379 }
380 }
381
382 bool
383 readMemAccPredicate() const override
384 {
385 return thread->readMemAccPredicate();
386 }
387
388 void
389 setMemAccPredicate(bool val) override
390 {
391 thread->setMemAccPredicate(val);
392 }
393
394 uint64_t
395 getHtmTransactionUid() const override
396 {
397 return tcBase()->getHtmCheckpointPtr()->getHtmUid();
398 }
399
400 uint64_t
401 newHtmTransactionUid() const override
402 {
403 return tcBase()->getHtmCheckpointPtr()->newHtmUid();
404 }
405
406 bool
407 inHtmTransactionalState() const override
408 {
409 return (getHtmTransactionalDepth() > 0);
410 }
411
412 uint64_t
414 {
415 assert(thread->htmTransactionStarts >= thread->htmTransactionStops);
416 return (thread->htmTransactionStarts - thread->htmTransactionStops);
417 }
418
422 void
423 demapPage(Addr vaddr, uint64_t asn) override
424 {
425 thread->demapPage(vaddr, asn);
426 }
427
428 void
429 armMonitor(Addr address) override
430 {
431 cpu->armMonitor(thread->threadId(), address);
432 }
433
434 bool
435 mwait(PacketPtr pkt) override
436 {
437 return cpu->mwait(thread->threadId(), pkt);
438 }
439
440 void
442 {
443 cpu->mwaitAtomic(thread->threadId(), tc, thread->mmu);
444 }
445
447 getAddrMonitor() override
448 {
449 return cpu->getCpuAddrMonitor(thread->threadId());
450 }
451};
452
453} // namespace gem5
454
455#endif // __CPU_EXEC_CONTEXT_HH__
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,...
const char data[]
The ExecContext is an abstract base class the provides the interface used by the ISA to manipulate th...
Register ID: describe an architectural register with its class and index.
Definition reg_class.hh:94
gem5::Flags< FlagsType > Flags
Definition request.hh:102
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
gem5::SimpleExecContext::IssueStats issueStats
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...
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.
A formula for statistics that is calculated when printed.
Statistics container.
Definition group.hh:93
This is a simple scalar statistic, like a counter.
A 2-Dimensional vecto of scalar stats.
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
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
Units for Stats.
Definition units.hh:113
const FlagsType pdf
Print the percent of the total that this entry represents.
Definition info.hh:61
Temp constant(T val)
const FlagsType total
Print the total.
Definition info.hh:59
double Counter
All counters are of 64-bit values.
Definition types.hh:46
const FlagsType dist
Print the distribution.
Definition info.hh:65
Copyright (c) 2024 Arm Limited 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
Packet * PacketPtr
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 ...
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 Mon Oct 27 2025 04:13:01 for gem5 by doxygen 1.14.0