gem5  v22.1.0.0
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"
49 #include "cpu/static_inst_fwd.hh"
50 #include "cpu/translation.hh"
51 #include "mem/request.hh"
52 
53 namespace gem5
54 {
55 
56 class 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.
68  bool stayAtPC;
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(numInsts, statistics::units::Count::get(),
90  "Number of instructions committed"),
91  ADD_STAT(numOps, statistics::units::Count::get(),
92  "Number of ops (including micro ops) committed"),
93  ADD_STAT(numIntAluAccesses, statistics::units::Count::get(),
94  "Number of integer alu accesses"),
95  ADD_STAT(numFpAluAccesses, statistics::units::Count::get(),
96  "Number of float alu accesses"),
97  ADD_STAT(numVecAluAccesses, statistics::units::Count::get(),
98  "Number of vector alu accesses"),
99  ADD_STAT(numCallsReturns, statistics::units::Count::get(),
100  "Number of times a function call or return occured"),
101  ADD_STAT(numCondCtrlInsts, statistics::units::Count::get(),
102  "Number of instructions that are conditional controls"),
103  ADD_STAT(numIntInsts, statistics::units::Count::get(),
104  "Number of integer instructions"),
105  ADD_STAT(numFpInsts, statistics::units::Count::get(),
106  "Number of float instructions"),
107  ADD_STAT(numVecInsts, statistics::units::Count::get(),
108  "Number of vector instructions"),
109  ADD_STAT(numIntRegReads, statistics::units::Count::get(),
110  "Number of times the integer registers were read"),
111  ADD_STAT(numIntRegWrites, statistics::units::Count::get(),
112  "Number of times the integer registers were written"),
113  ADD_STAT(numFpRegReads, statistics::units::Count::get(),
114  "Number of times the floating registers were read"),
115  ADD_STAT(numFpRegWrites, statistics::units::Count::get(),
116  "Number of times the floating registers were written"),
117  ADD_STAT(numVecRegReads, statistics::units::Count::get(),
118  "Number of times the vector registers were read"),
119  ADD_STAT(numVecRegWrites, statistics::units::Count::get(),
120  "Number of times the vector registers were written"),
121  ADD_STAT(numVecPredRegReads, statistics::units::Count::get(),
122  "Number of times the predicate registers were read"),
123  ADD_STAT(numVecPredRegWrites, statistics::units::Count::get(),
124  "Number of times the predicate registers were written"),
125  ADD_STAT(numCCRegReads, statistics::units::Count::get(),
126  "Number of times the CC registers were read"),
127  ADD_STAT(numCCRegWrites, statistics::units::Count::get(),
128  "Number of times the CC registers were written"),
129  ADD_STAT(numMiscRegReads, statistics::units::Count::get(),
130  "Number of times the Misc registers were read"),
131  ADD_STAT(numMiscRegWrites, statistics::units::Count::get(),
132  "Number of times the Misc registers were written"),
133  ADD_STAT(numMemRefs, statistics::units::Count::get(),
134  "Number of memory refs"),
135  ADD_STAT(numLoadInsts, statistics::units::Count::get(),
136  "Number of load instructions"),
137  ADD_STAT(numStoreInsts, statistics::units::Count::get(),
138  "Number of store instructions"),
139  ADD_STAT(numIdleCycles, statistics::units::Cycle::get(),
140  "Number of idle cycles"),
141  ADD_STAT(numBusyCycles, statistics::units::Cycle::get(),
142  "Number of busy cycles"),
143  ADD_STAT(notIdleFraction, statistics::units::Ratio::get(),
144  "Percentage of non-idle cycles"),
145  ADD_STAT(idleFraction, statistics::units::Ratio::get(),
146  "Percentage of idle cycles"),
147  ADD_STAT(icacheStallCycles, statistics::units::Cycle::get(),
148  "ICache total stall cycles"),
149  ADD_STAT(dcacheStallCycles, statistics::units::Cycle::get(),
150  "DCache total stall cycles"),
151  ADD_STAT(numBranches, statistics::units::Count::get(),
152  "Number of branches fetched"),
153  ADD_STAT(numPredictedBranches, statistics::units::Count::get(),
154  "Number of branches predicted as taken"),
155  ADD_STAT(numBranchMispred, statistics::units::Count::get(),
156  "Number of branch mispredictions"),
157  ADD_STAT(statExecutedInstType, statistics::units::Count::get(),
158  "Class of executed instruction."),
159  numRegReads{
161  &numFpRegReads,
166  },
167  numRegWrites{
174  }
175  {
178 
181 
184 
187 
189  .init(enums::Num_OpClass)
191 
192  for (unsigned i = 0; i < Num_OpClasses; ++i) {
193  statExecutedInstType.subname(i, enums::OpClassStrings[i]);
194  }
195 
199 
202 
205 
208  }
209 
210  // Number of simulated instructions
213 
214  // Number of integer alu accesses
216 
217  // Number of float alu accesses
219 
220  // Number of vector alu accesses
222 
223  // Number of function calls/returns
225 
226  // Conditional control instructions;
228 
229  // Number of int instructions
231 
232  // Number of float instructions
234 
235  // Number of vector instructions
237 
238  // Number of integer register file accesses
241 
242  // Number of float register file accesses
245 
246  // Number of vector register file accesses
249 
250  // Number of predicate register file accesses
253 
254  // Number of condition code register file accesses
257 
258  // Number of misc register file accesses
261 
262  // Number of simulated memory references
266 
267  // Number of idle cycles
269 
270  // Number of busy cycles
272 
273  // Number of idle cycles
276 
277  // Number of cycles stalled for I-cache responses
279 
280  // Number of cycles stalled for D-cache responses
282 
291 
292  // Instruction mix histogram by OpClass
294 
295  std::array<statistics::Scalar *, CCRegClass + 1> numRegReads;
296  std::array<statistics::Scalar *, CCRegClass + 1> numRegWrites;
297 
299 
300  public:
303  : cpu(_cpu), thread(_thread), fetchOffset(0), stayAtPC(false),
304  numInst(0), numOp(0), numLoad(0), lastIcacheStall(0),
306  { }
307 
308  RegVal
309  getRegOperand(const StaticInst *si, int idx) override
310  {
311  const RegId &reg = si->srcRegIdx(idx);
312  if (reg.is(InvalidRegClass))
313  return 0;
314  (*execContextStats.numRegReads[reg.classValue()])++;
315  return thread->getReg(reg);
316  }
317 
318  void
319  getRegOperand(const StaticInst *si, int idx, void *val) override
320  {
321  const RegId &reg = si->srcRegIdx(idx);
322  (*execContextStats.numRegReads[reg.classValue()])++;
323  thread->getReg(reg, val);
324  }
325 
326  void *
327  getWritableRegOperand(const StaticInst *si, int idx) override
328  {
329  const RegId &reg = si->destRegIdx(idx);
330  (*execContextStats.numRegWrites[reg.classValue()])++;
331  return thread->getWritableReg(reg);
332  }
333 
334  void
335  setRegOperand(const StaticInst *si, int idx, RegVal val) override
336  {
337  const RegId &reg = si->destRegIdx(idx);
338  if (reg.is(InvalidRegClass))
339  return;
340  (*execContextStats.numRegWrites[reg.classValue()])++;
341  thread->setReg(reg, val);
342  }
343 
344  void
345  setRegOperand(const StaticInst *si, int idx, const void *val) override
346  {
347  const RegId &reg = si->destRegIdx(idx);
348  (*execContextStats.numRegWrites[reg.classValue()])++;
349  thread->setReg(reg, val);
350  }
351 
352  RegVal
353  readMiscRegOperand(const StaticInst *si, int idx) override
354  {
356  const RegId& reg = si->srcRegIdx(idx);
357  assert(reg.is(MiscRegClass));
358  return thread->readMiscReg(reg.index());
359  }
360 
361  void
362  setMiscRegOperand(const StaticInst *si, int idx, RegVal val) override
363  {
365  const RegId& reg = si->destRegIdx(idx);
366  assert(reg.is(MiscRegClass));
367  thread->setMiscReg(reg.index(), val);
368  }
369 
374  RegVal
375  readMiscReg(int misc_reg) override
376  {
378  return thread->readMiscReg(misc_reg);
379  }
380 
385  void
386  setMiscReg(int misc_reg, RegVal val) override
387  {
389  thread->setMiscReg(misc_reg, val);
390  }
391 
392  const PCStateBase &
393  pcState() const override
394  {
395  return thread->pcState();
396  }
397 
398  void
399  pcState(const PCStateBase &val) override
400  {
401  thread->pcState(val);
402  }
403 
404  Fault
405  readMem(Addr addr, uint8_t *data, unsigned int size,
407  const std::vector<bool>& byte_enable)
408  override
409  {
410  assert(byte_enable.size() == size);
411  return cpu->readMem(addr, data, size, flags, byte_enable);
412  }
413 
414  Fault
415  initiateMemRead(Addr addr, unsigned int size,
417  const std::vector<bool>& byte_enable)
418  override
419  {
420  assert(byte_enable.size() == size);
421  return cpu->initiateMemRead(addr, size, flags, byte_enable);
422  }
423 
424  Fault
425  writeMem(uint8_t *data, unsigned int size, Addr addr,
426  Request::Flags flags, uint64_t *res,
427  const std::vector<bool>& byte_enable)
428  override
429  {
430  assert(byte_enable.size() == size);
431  return cpu->writeMem(data, size, addr, flags, res,
432  byte_enable);
433  }
434 
435  Fault
436  amoMem(Addr addr, uint8_t *data, unsigned int size,
437  Request::Flags flags, AtomicOpFunctorPtr amo_op) override
438  {
439  return cpu->amoMem(addr, data, size, flags, std::move(amo_op));
440  }
441 
442  Fault
443  initiateMemAMO(Addr addr, unsigned int size,
445  AtomicOpFunctorPtr amo_op) override
446  {
447  return cpu->initiateMemAMO(addr, size, flags, std::move(amo_op));
448  }
449 
450  Fault
452  {
453  return cpu->initiateMemMgmtCmd(flags);
454  }
455 
459  void
460  setStCondFailures(unsigned int sc_failures) override
461  {
462  thread->setStCondFailures(sc_failures);
463  }
464 
468  unsigned int
469  readStCondFailures() const override
470  {
471  return thread->readStCondFailures();
472  }
473 
475  ThreadContext *tcBase() const override { return thread->getTC(); }
476 
477  bool
478  readPredicate() const override
479  {
480  return thread->readPredicate();
481  }
482 
483  void
484  setPredicate(bool val) override
485  {
487 
488  if (cpu->traceData) {
490  }
491  }
492 
493  bool
494  readMemAccPredicate() const override
495  {
496  return thread->readMemAccPredicate();
497  }
498 
499  void
500  setMemAccPredicate(bool val) override
501  {
503  }
504 
505  uint64_t
506  getHtmTransactionUid() const override
507  {
508  return tcBase()->getHtmCheckpointPtr()->getHtmUid();
509  }
510 
511  uint64_t
512  newHtmTransactionUid() const override
513  {
514  return tcBase()->getHtmCheckpointPtr()->newHtmUid();
515  }
516 
517  bool
518  inHtmTransactionalState() const override
519  {
520  return (getHtmTransactionalDepth() > 0);
521  }
522 
523  uint64_t
524  getHtmTransactionalDepth() const override
525  {
528  }
529 
533  void
534  demapPage(Addr vaddr, uint64_t asn) override
535  {
536  thread->demapPage(vaddr, asn);
537  }
538 
539  void
540  armMonitor(Addr address) override
541  {
542  cpu->armMonitor(thread->threadId(), address);
543  }
544 
545  bool
546  mwait(PacketPtr pkt) override
547  {
548  return cpu->mwait(thread->threadId(), pkt);
549  }
550 
551  void
553  {
555  }
556 
558  getAddrMonitor() override
559  {
560  return cpu->getCpuAddrMonitor(thread->threadId());
561  }
562 };
563 
564 } // namespace gem5
565 
566 #endif // __CPU_EXEC_CONTEXT_HH__
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,...
const char data[]
AddressMonitor * getCpuAddrMonitor(ThreadID tid)
Definition: base.hh:633
void mwaitAtomic(ThreadID tid, ThreadContext *tc, BaseMMU *mmu)
Definition: base.cc:240
bool mwait(ThreadID tid, PacketPtr pkt)
Definition: base.cc:217
gem5::BaseCPU::BaseCPUStats baseStats
void armMonitor(ThreadID tid, Addr address)
Definition: base.cc:205
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...
Definition: exec_context.hh:72
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:294
Register ID: describe an architectural register with its class and index.
Definition: reg_class.hh:91
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
ThreadContext * tcBase() const override
Returns a pointer to the ThreadContext.
void demapPage(Addr vaddr, uint64_t asn) override
Invalidate a page in the DTLB and ITLB.
void mwaitAtomic(ThreadContext *tc) override
void * getWritableRegOperand(const StaticInst *si, int idx) override
Counter numInst
PER-THREAD STATS.
Definition: exec_context.hh:74
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
Definition: exec_context.hh:71
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
const PCStateBase & pcState() 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
AddressMonitor * getAddrMonitor() 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
SimpleThread * thread
Definition: exec_context.hh:62
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
void armMonitor(Addr address) override
BaseSimpleCPU * cpu
Definition: exec_context.hh:61
The SimpleThread object provides a combination of the ThreadState object and the ThreadContext interf...
int threadId() const override
ThreadContext * getTC()
Returns the pointer to this SimpleThread's ThreadContext.
bool readPredicate() const
void setPredicate(bool val)
const PCStateBase & pcState() const override
void setStCondFailures(unsigned sc_failures) 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
int64_t htmTransactionStarts
RegVal readMiscReg(RegIndex misc_reg) override
void setMemAccPredicate(bool val)
RegVal getReg(const RegId &arch_reg) const override
Base, ISA-independent static instruction class.
Definition: static_inst.hh:89
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.
Definition: statistics.hh:1959
Derived & subname(off_type index, const std::string &name)
Set the subfield name for the given index, and marks this stat to print at the end of simulation.
Definition: statistics.hh:402
Derived & flags(Flags _flags)
Set the flags and marks this stat to print at the end of simulation.
Definition: statistics.hh:358
Derived & prereq(const Stat &prereq)
Set the prerequisite stat and marks this stat to print at the end of simulation.
Definition: statistics.hh:372
A formula for statistics that is calculated when printed.
Definition: statistics.hh:2540
Statistics container.
Definition: group.hh:94
This is a simple scalar statistic, like a counter.
Definition: statistics.hh:1931
Derived & init(size_type size)
Set this vector to have the given size.
Definition: statistics.hh:1040
A vector of scalar stats.
Definition: statistics.hh:2007
void setPredicate(bool val)
Definition: insttracer.hh:258
#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:242
uint8_t flags
Definition: helpers.cc:66
Bitfield< 7 > i
Definition: misc_types.hh:67
Bitfield< 6 > si
Definition: misc_types.hh:831
Bitfield< 5, 3 > reg
Definition: types.hh:92
Bitfield< 63 > val
Definition: misc.hh:776
Bitfield< 3 > addr
Definition: types.hh:84
const FlagsType pdf
Print the percent of the total that this entry represents.
Definition: info.hh:62
const FlagsType nozero
Don't print if this is zero.
Definition: info.hh:68
Temp constant(T val)
Definition: statistics.hh:2865
const FlagsType total
Print the total.
Definition: info.hh:60
double Counter
All counters are of 64-bit values.
Definition: types.hh:47
const FlagsType dist
Print the distribution.
Definition: info.hh:66
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
std::shared_ptr< FaultBase > Fault
Definition: types.hh:248
static const OpClass Num_OpClasses
Definition: op_class.hh:108
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
uint64_t RegVal
Definition: types.hh:173
std::string csprintf(const char *format, const Args &...args)
Definition: cprintf.hh:161
@ InvalidRegClass
Definition: reg_class.hh:69
@ MiscRegClass
Control (misc) register.
Definition: reg_class.hh:68
Declaration of a request, the overall memory request consisting of the parts of the request that are ...
statistics::Scalar numCycles
Definition: base.hh:620
std::array< statistics::Scalar *, CCRegClass+1 > numRegReads
statistics::Scalar numBranchMispred
Number of misprediced branches.
statistics::Scalar numPredictedBranches
Number of branches predicted as taken.
std::array< statistics::Scalar *, CCRegClass+1 > numRegWrites
ExecContextStats(BaseSimpleCPU *cpu, SimpleThread *thread)
Definition: exec_context.hh:85

Generated on Wed Dec 21 2022 10:22:30 for gem5 by doxygen 1.9.1