60#include "debug/Mwait.hh"
61#include "debug/SyscallVerbose.hh"
62#include "debug/Thread.hh"
64#include "params/BaseCPU.hh"
104 if (
cpu->switchedOut()) {
111 DPRINTFN(
"%s progress event, total committed:%i, progress insts committed: "
116 cprintf(
"%lli: %s progress event, total committed:%i, progress insts "
117 "committed: %lli\n",
curTick(),
cpu->name(), temp,
126 return "CPU Progress";
149 _cpuId = cpuList.size();
153 cpuList.push_back(
this);
155 DPRINTF(SyscallVerbose,
"Constructing CPU with id %d, socket id %d\n",
161 functionTracingEnabled =
false;
162 if (
p.function_trace) {
163 const std::string fname =
csprintf(
"ftrace.%s",
name());
166 currentFunctionStart = currentFunctionEnd = 0;
167 functionEntryTick =
p.function_trace_start;
169 if (
p.function_trace_start == 0) {
170 functionTracingEnabled =
true;
173 [
this]{ enableFunctionTrace(); },
name(),
true);
174 schedule(
event,
p.function_trace_start);
178 tracer = params().tracer;
180 if (params().isa.size() != numThreads) {
181 fatal(
"Number of ISAs (%i) assigned to the CPU does not equal number "
182 "of threads (%i).\n", params().isa.size(), numThreads);
185 if (!
FullSystem && params().workload.size() != numThreads) {
186 fatal(
"Number of processes (cpu.workload) (%i) assigned to the CPU "
187 "does not equal number of threads (%i).\n",
188 params().workload.size(), numThreads);
191 modelResetPort.onChange([
this](
const bool &new_val) {
195 for (
int i = 0;
i < params().port_cpu_idle_pins_connection_count;
i++) {
201 fetchStats.reserve(numThreads);
202 executeStats.reserve(numThreads);
203 commitStats.reserve(numThreads);
204 for (
int i = 0;
i < numThreads;
i++) {
206 FetchCPUStats* fetchStatptr =
new FetchCPUStats(
this,
i);
207 fetchStatptr->fetchRate = fetchStatptr->numInsts / baseStats.numCycles;
208 fetchStatptr->branchRate = fetchStatptr->numBranches /
210 fetchStats.emplace_back(fetchStatptr);
213 ExecuteCPUStats* executeStatptr =
new ExecuteCPUStats(
this,
i);
214 executeStatptr->instRate = executeStatptr->numInsts /
216 executeStats.emplace_back(executeStatptr);
219 CommitCPUStats* commitStatptr =
new CommitCPUStats(
this,
i);
220 commitStatptr->ipc = commitStatptr->numInsts / baseStats.numCycles;
221 commitStatptr->cpi = baseStats.numCycles / commitStatptr->numInsts;
222 commitStats.emplace_back(commitStatptr);
257 monitor.
armed =
true;
258 monitor.
vAddr = address;
260 DPRINTF(Mwait,
"[tid:%d] Armed monitor (vAddr=0x%lx)\n", tid, address);
273 assert(pkt->
req->hasPaddr());
277 DPRINTF(Mwait,
"[tid:%d] mwait called (vAddr=0x%lx, "
278 "line's paddr=0x%lx)\n", tid, monitor.
vAddr, monitor.
pAddr);
297 int size = block_size;
302 if (secondAddr >
addr)
303 size = secondAddr -
addr;
315 DPRINTF(Mwait,
"[tid:%d] mwait called (vAddr=0x%lx, line's paddr=0x%lx)\n",
324 if (
params().max_insts_any_thread != 0) {
332 if (!
params().simpoint_start_insts.empty()) {
336 if (
params().max_insts_all_threads != 0) {
337 std::string cause =
"all threads reached the max instruction count";
342 int *counter =
new int;
351 if (!
params().switched_out) {
361 if (
params().progress_interval) {
369 if (
powerState->get() == enums::PwrState::UNDEFINED)
421 "Number of cpu cycles simulated"),
424 "CPI: cycles per instruction (core level)"),
427 "IPC: instructions per cycle (core level)"),
429 "Number of work items this cpu started"),
431 "Number of work items this cpu completed")
455 for (
int i = 0;
i < size; ++
i) {
456 std::stringstream namestr;
460 }
else if (size == 1)
470 if (if_name ==
"dcache_port")
472 else if (if_name ==
"icache_port")
474 else if (if_name ==
"model_reset")
476 else if (if_name ==
"cpu_idle_pins")
488 "CPU %s has %i interrupt controllers, but is expecting one "
495 system->registerThreadContext(tc);
521 if (
powerState->get() == enums::PwrState::CLK_GATED &&
534 for (
ThreadID tid = 0; tid < size; ++tid) {
545 DPRINTF(Thread,
"CPU in reset, not activating context %d\n",
550 DPRINTF(Thread,
"activate contextId %d\n",
569 DPRINTF(Thread,
"suspend contextId %d\n",
629 assert(oldCPU !=
this);
666 if (old_checker && new_checker) {
698 tc->getIsaPtr()->resetThread();
700 tc->getDecoderPtr()->reset();
702 tc->getMMUPtr()->reset();
788 assert(pkt->
req->hasPaddr());
791 DPRINTF(Mwait,
"pAddr=0x%lx invalidated: waking up core\n",
820 sym_str = it->name();
833 std::string cause =
"simpoint starting point found";
834 for (
size_t i = 0;
i < inst_starts.size(); ++
i) {
842 std::string cause =
"a thread reached the max instruction count";
851 "Number of instructions simulated"),
853 "Number of ops (including micro ops) simulated"),
856 "Simulator instruction rate (inst/s)"),
859 "Simulator op (including micro ops) rate (op/s)")
891 "Number of instructions fetched (thread level)"),
893 "Number of ops (including micro ops) fetched (thread level)"),
896 "Number of inst fetches per cycle"),
898 "Number of branches fetched"),
900 "Number of branch fetches per cycle"),
902 "ICache total stall cycles"),
904 "Number of times Execute suspended instruction fetching")
926 "Number of executed instructions"),
928 "Number of nop insts executed"),
930 "Number of branches executed"),
932 "Number of load instructions executed"),
934 "Number of stores executed"),
937 "Inst execution rate"),
939 "DCache total stall cycles"),
941 "Number of times the CC registers were read"),
943 "Number of times the CC registers were written"),
945 "Number of float alu accesses"),
947 "Number of times the floating registers were read"),
949 "Number of times the floating registers were written"),
951 "Number of integer alu accesses"),
953 "Number of times the integer registers were read"),
955 "Number of times the integer registers were written"),
957 "Number of memory refs"),
959 "Number of times the Misc registers were read"),
961 "Number of times the Misc registers were written"),
963 "Number of vector alu accesses"),
965 "Number of times the predicate registers were read"),
967 "Number of times the predicate registers were written"),
969 "Number of times the vector registers were read"),
971 "Number of times the vector registers were written"),
973 "Number of ops (including micro ops) which were discarded before "
1014 "Number of instructions committed (thread level)"),
1016 "Number of ops (including micro ops) committed (thread level)"),
1018 "Number of instructions committed excluding NOPs or prefetches"),
1020 "Number of Ops (including micro ops) Simulated"),
1023 "CPI: cycles per instruction (thread level)"),
1026 "IPC: instructions per cycle (thread level)"),
1028 "Number of memory references committed"),
1030 "Number of float instructions"),
1032 "Number of integer instructions"),
1034 "Number of load instructions"),
1036 "Number of store instructions"),
1038 "Number of vector instructions"),
1040 "Class of committed instruction."),
1042 "Class of control type instructions committed")
1051 .init(enums::Num_OpClass)
1059 .init(StaticInstFlags::Flags::Num_Flags)
1062 for (
unsigned i = 0;
i < StaticInstFlags::Flags::Num_Flags;
i++) {
1077 if (staticInst->
isCall()) {
1085 [gem5::StaticInstFlags::Flags::IsIndirectControl]++;
void regStats() override
Callback to set stat parameters.
int findContext(ThreadContext *tc)
Given a Thread Context pointer return the thread num.
RequestorID dataRequestorId() const
Reads this CPU's unique data requestor ID.
probing::PMUUPtr ppRetiredInsts
Instruction commit probe point.
const Cycles pwrGatingLatency
virtual void serializeThread(CheckpointOut &cp, ThreadID tid) const
Serialize a single thread.
Cycles syscallRetryLatency
void traceFunctionsInternal(Addr pc)
const bool powerGatingOnIdle
void registerThreadContexts()
virtual void haltContext(ThreadID thread_num)
Notify the CPU that the indicated context is now halted.
probing::PMUUPtr ppRetiredLoads
Retired load instructions.
Tick instCnt
Instruction count used for SPARC misc register.
SignalSinkPort< bool > modelResetPort
probing::PMUUPtr ppAllCycles
CPU cycle counter even if any thread Context is suspended.
probing::PMUUPtr ppRetiredInstsPC
void init() override
init() is called after all C++ SimObjects have been created and all ports are connected.
void mwaitAtomic(ThreadID tid, ThreadContext *tc, BaseMMU *mmu)
Addr cacheLineSize() const
Get the cache line size of the system.
void updateCycleCounters(CPUState state)
base method keeping track of cycle progression
probing::PMUUPtr pmuProbePoint(const char *name)
Helper method to instantiate probe points belonging to this object.
static const uint32_t invldPid
Invalid or unknown Pid.
void postInterrupt(ThreadID tid, int int_num, int index)
std::vector< std::unique_ptr< IntSourcePin< BaseCPU > > > cpuIdlePins
bool mwait(ThreadID tid, PacketPtr pkt)
const uint32_t _socketId
Each cpu will have a socket ID that corresponds to its physical location in the system.
void unserialize(CheckpointIn &cp) override
Reconstruct the state of this object from a checkpoint.
void scheduleInstStopAnyThread(Counter max_insts)
Schedule an exit event when any threads in the core reach the max_insts instructions using the schedu...
void serialize(CheckpointOut &cp) const override
Serialize this object to the given output stream.
probing::PMUUPtr ppRetiredStores
Retired store instructions.
bool _switchedOut
Is the CPU switched out or active?
Port & getPort(const std::string &if_name, PortID idx=InvalidPortID) override
Get a port on this CPU.
Addr currentFunctionStart
void schedulePowerGatingEvent()
static std::unique_ptr< GlobalStats > globalStats
Pointer to the global stat structure.
virtual Port & getDataPort()=0
Purely virtual method that returns a reference to the data port.
virtual void verifyMemoryMode() const
Verify that the system is in a memory mode supported by the CPU.
void regProbePoints() override
Register probe points for this object.
void scheduleSimpointsInstStop(std::vector< Counter > inst_starts)
Schedule simpoint events using the scheduleInstStop function.
uint32_t taskId() const
Get cpu task id.
virtual void suspendContext(ThreadID thread_num)
Notify the CPU that the indicated context is now suspended.
void enableFunctionTrace()
gem5::BaseCPU::BaseCPUStats baseStats
virtual Port & getInstPort()=0
Purely virtual method that returns a reference to the instruction port.
ThreadID numThreads
Number of threads we're actually simulating (<= SMT_MAX_THREADS).
probing::PMUUPtr ppRetiredBranches
Retired branches (any type)
void deschedulePowerGatingEvent()
virtual void wakeup(ThreadID tid)=0
probing::PMUUPtr ppActiveCycles
CPU cycle counter, only counts if any thread contexts is active.
bool functionTracingEnabled
int cpuId() const
Reads this CPU's ID.
uint32_t _taskId
An intrenal representation of a task identifier within gem5.
std::vector< BaseInterrupts * > interrupts
void startup() override
startup() is the final initialization call before simulation.
virtual void unserializeThread(CheckpointIn &cp, ThreadID tid)
Unserialize one thread.
virtual void switchOut()
Prepare for another CPU to take over execution.
virtual void setReset(bool state)
Set the reset of the CPU to be either asserted or deasserted.
void flushTLBs()
Flush all TLBs in the CPU.
void armMonitor(ThreadID tid, Addr address)
ProbePointArg< bool > * ppSleeping
ProbePoint that signals transitions of threadContexts sets.
std::ostream * functionTraceStream
virtual void takeOverFrom(BaseCPU *cpu)
Load the state of a CPU from the previous CPU object, invoked on all new CPUs that are about to be sw...
std::vector< AddressMonitor > addressMonitor
const Addr _cacheLineSize
Cache the cache line size that we get from the system.
std::vector< ThreadContext * > threadContexts
static std::vector< BaseCPU * > cpuList
Static global cpu list.
RequestorID _instRequestorId
instruction side request id that must be placed in all requests
EventFunctionWrapper enterPwrGatingEvent
void scheduleInstStop(ThreadID tid, Counter insts, std::string cause)
Schedule an event that exits the simulation loops after a predefined number of instructions.
BaseCPU(const Params ¶ms, bool is_checker=false)
uint32_t _pid
The current OS process ID that is executing on this processor.
virtual void probeInstCommit(const StaticInstPtr &inst, Addr pc)
Helper method to trigger PMU probes for a committed instruction.
uint64_t getCurrentInstCount(ThreadID tid)
Get the number of instructions executed by the specified thread on this CPU.
RequestorID _dataRequestorId
data side request id that must be placed in all requests
virtual void activateContext(ThreadID thread_num)
Notify the CPU that the indicated context is now active.
virtual void setThreadContext(ThreadContext *_tc)
virtual void takeOverFrom(BaseMMU *old_mmu)
virtual Fault translateAtomic(const RequestPtr &req, ThreadContext *tc, Mode mode)
CPUProgressEvent(BaseCPU *_cpu, Tick ival=0)
virtual const char * description() const
Return a C string describing the event.
ClockedObject(const ClockedObjectParams &p)
ClockedObjectParams Params
Parameters of ClockedObject.
Tick clockEdge(Cycles cycles=Cycles(0)) const
Determine the tick when a cycle begins, by default the current one, but the argument also enables the...
Event(Priority p=Default_Pri, Flags f=0)
virtual std::string name() const
OutputStream * findOrCreate(const std::string &name, bool binary=false)
std::ostream * stream() const
Get the output underlying output stream.
Addr instAddr() const
Returns the memory address of the instruction this PC points to.
RequestPtr req
A pointer to the original request.
Ports are used to interface objects to each other.
bool isConnected() const
Is this port currently connected to a peer?
void takeOverFrom(Port *old)
A utility function to make it easier to swap out ports.
enums::PwrState get() const
ProbePointArg generates a point for the class of Arg.
void assignThreadContext(ContextID context_id)
Static instruction class for unknown (illegal) instructions.
static Root * root()
Use this function to get a pointer to the single Root object in the simulation.
bool isDirectCtrl() const
bool isUncondCtrl() const
bool isIndirectCtrl() const
bool isLastMicroop() const
ThreadContext is the external interface to all thread state for anything outside of the CPU.
virtual BaseISA * getIsaPtr() const =0
virtual void takeOverFrom(ThreadContext *old_context)=0
virtual CheckerCPU * getCheckerCpuPtr()=0
@ Suspended
Temporarily inactive.
virtual const PCStateBase & pcState() const =0
virtual int threadId() const =0
virtual BaseMMU * getMMUPtr()=0
virtual Process * getProcessPtr()=0
virtual ContextID contextId() const =0
ClockedObject declaration and implementation.
#define ADD_STAT(n,...)
Convenience macro to add a stat to a statistics group.
static constexpr T roundDown(const T &val, const U &align)
This function is used to align addresses in memory.
void deschedule(Event &event)
void schedule(Event &event, Tick when)
static const Priority Progress_Event_Pri
Progress events come at the end.
#define fatal_if(cond,...)
Conditional fatal macro that checks the supplied condition and only causes a fatal error if the condi...
#define fatal(...)
This implements a cprintf based fatal() function.
const Params & params() const
ProbeManager * getProbeManager()
Get the probe manager for this object.
virtual Port & getPort(const std::string &if_name, PortID idx=InvalidPortID)
Get a port with a given name and index.
virtual void regStats()
Callback to set stat parameters.
Special TaskIds that are used for per-context-switch stats dumps and Cache Occupancy.
SymbolTable debugSymbolTable
Global unified debugging symbol table (for target).
std::unique_ptr< PMU > PMUUPtr
ProbePointArg< uint64_t > PMU
PMU probe point.
const FlagsType pdf
Print the percent of the total that this entry represents.
const FlagsType nozero
Don't print if this is zero.
const FlagsType total
Print the total.
double Counter
All counters are of 64-bit values.
const FlagsType dist
Print the distribution.
Copyright (c) 2024 Arm Limited All rights reserved.
std::shared_ptr< FaultBase > Fault
int16_t ThreadID
Thread index/ID type.
std::shared_ptr< Request > RequestPtr
IntSourcePinBase IntSourcePin
statistics::Value & hostSeconds
static const OpClass Num_OpClasses
void cprintf(const char *format, const Args &...args)
Tick curTick()
The universal simulation clock.
std::ostream CheckpointOut
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
bool FullSystem
The FullSystem variable can be used to determine the current mode of simulation.
uint64_t Tick
Tick count type.
int maxThreadsPerCPU
The maximum number of active threads across all cpus.
RefCountingPtr< StaticInst > StaticInstPtr
std::string csprintf(const char *format, const Args &...args)
constexpr decltype(nullptr) NoFault
void ccprintf(cp::Print &print)
Declarations of a non-full system Page Table.
#define UNSERIALIZE_SCALAR(scalar)
#define SERIALIZE_SCALAR(scalar)
bool doMonitor(PacketPtr pkt)
statistics::Scalar numWorkItemsStarted
BaseCPUStats(statistics::Group *parent)
statistics::Scalar numInsts
statistics::Scalar numCycles
statistics::Scalar numWorkItemsCompleted
statistics::Scalar numFpInsts
statistics::Vector committedInstType
statistics::Scalar numVecInsts
void updateComCtrlStats(const StaticInstPtr staticInst)
statistics::Vector committedControl
statistics::Scalar numInstsNotNOP
statistics::Scalar numStoreInsts
statistics::Scalar numInsts
CommitCPUStats(statistics::Group *parent, int thread_id)
statistics::Scalar numOpsNotNOP
statistics::Scalar numLoadInsts
statistics::Scalar numIntInsts
statistics::Scalar numMemRefs
statistics::Scalar numOps
statistics::Scalar numIntRegReads
statistics::Scalar numVecPredRegReads
statistics::Scalar dcacheStallCycles
statistics::Scalar numCCRegReads
statistics::Scalar numBranches
statistics::Scalar numInsts
statistics::Scalar numIntRegWrites
statistics::Formula numStoreInsts
statistics::Scalar numMemRefs
statistics::Formula instRate
statistics::Scalar numVecAluAccesses
statistics::Scalar numMiscRegReads
statistics::Scalar numCCRegWrites
statistics::Scalar numVecPredRegWrites
statistics::Scalar numFpAluAccesses
statistics::Scalar numFpRegWrites
statistics::Scalar numDiscardedOps
statistics::Scalar numNop
statistics::Scalar numIntAluAccesses
ExecuteCPUStats(statistics::Group *parent, int thread_id)
statistics::Scalar numVecRegWrites
statistics::Scalar numFpRegReads
statistics::Scalar numVecRegReads
statistics::Scalar numMiscRegWrites
statistics::Scalar numLoadInsts
statistics::Scalar numOps
statistics::Scalar numInsts
statistics::Formula fetchRate
statistics::Formula branchRate
statistics::Scalar numFetchSuspends
statistics::Scalar numBranches
FetchCPUStats(statistics::Group *parent, int thread_id)
statistics::Scalar icacheStallCycles
Global CPU statistics that are merged into the Root object.
statistics::Formula hostInstRate
statistics::Value simInsts
static Counter numSimulatedInsts()
GlobalStats(statistics::Group *parent)
static Counter numSimulatedOps()
statistics::Formula hostOpRate
const std::string & name()