64 #include "debug/Mwait.hh" 65 #include "debug/SyscallVerbose.hh" 66 #include "debug/Thread.hh" 68 #include "params/BaseCPU.hh" 89 :
Event(
Event::Progress_Event_Pri), _interval(ival), lastNumInst(0),
90 cpu(_cpu), _repeatEvent(true)
111 DPRINTFN(
"%s progress event, total committed:%i, progress insts committed: " 116 cprintf(
"%lli: %s progress event, total committed:%i, progress insts " 126 return "CPU Progress";
130 :
ClockedObject(p), instCnt(0), _cpuId(p->cpu_id), _socketId(p->socket_id),
131 _instMasterId(p->
system->getMasterId(this,
"inst")),
132 _dataMasterId(p->
system->getMasterId(this,
"data")),
134 _switchedOut(p->switched_out), _cacheLineSize(p->
system->cacheLineSize()),
135 interrupts(p->interrupts), profileEvent(NULL),
137 previousCycle(0), previousState(CPU_STATE_SLEEP),
138 functionTraceStream(nullptr), currentFunctionStart(0),
139 currentFunctionEnd(0), functionEntryTick(0),
140 addressMonitor(p->numThreads),
141 syscallRetryLatency(p->syscallRetryLatency),
142 pwrGatingLatency(p->pwr_gating_latency),
143 powerGatingOnIdle(p->power_gating_on_idle),
154 DPRINTF(SyscallVerbose,
"Constructing CPU with id %d, socket id %d\n",
161 if (
p->function_trace) {
168 if (
p->function_trace_start == 0) {
179 if (!
params()->switched_out && !is_checker) {
181 "CPU %s has %i interrupt controllers, but is expecting one " 197 fatal(
"Number of ISAs (%i) assigned to the CPU does not equal number " 219 monitor.
armed =
true;
220 monitor.
vAddr = address;
222 DPRINTF(Mwait,
"[tid:%d] Armed monitor (vAddr=0x%lx)\n", tid, address);
233 uint64_t
mask = ~((uint64_t)(block_size - 1));
235 assert(pkt->
req->hasPaddr());
239 DPRINTF(Mwait,
"[tid:%d] mwait called (vAddr=0x%lx, " 240 "line's paddr=0x%lx)\n", tid, monitor.
vAddr, monitor.
pAddr);
258 uint64_t
mask = ~((uint64_t)(block_size - 1));
259 int size = block_size;
264 if (secondAddr > addr)
265 size = secondAddr -
addr;
276 DPRINTF(Mwait,
"[tid:%d] mwait called (vAddr=0x%lx, line's paddr=0x%lx)\n",
285 if (
params()->max_insts_any_thread != 0) {
286 const char *cause =
"a thread reached the max instruction count";
295 if (!
params()->simpoint_start_insts.empty()) {
296 const char *cause =
"simpoint starting point found";
297 for (
size_t i = 0;
i <
params()->simpoint_start_insts.size(); ++
i)
301 if (
params()->max_insts_all_threads != 0) {
302 const char *cause =
"all threads reached the max instruction count";
307 int *counter =
new int;
316 if (!
params()->switched_out) {
331 if (
params()->progress_interval) {
392 using namespace Stats;
396 .
desc(
"number of cpu cycles simulated")
400 .
name(
name() +
".numWorkItemsStarted")
401 .
desc(
"number of work items this cpu started")
405 .
name(
name() +
".numWorkItemsCompleted")
406 .
desc(
"number of work items this cpu completed")
411 for (
int i = 0;
i < size; ++
i) {
412 stringstream namestr;
416 }
else if (size == 1)
426 if (if_name ==
"dcache_port")
428 else if (if_name ==
"icache_port")
440 for (
ThreadID tid = 0; tid < size; ++tid) {
483 for (
ThreadID tid = 0; tid < size; ++tid) {
493 DPRINTF(Thread,
"activate contextId %d\n",
507 DPRINTF(Thread,
"suspend contextId %d\n",
564 assert(oldCPU !=
this);
612 if (oldChecker && newChecker) {
613 Port *old_checker_itb_port =
615 Port *old_checker_dtb_port =
617 Port *new_checker_itb_port =
619 Port *new_checker_dtb_port =
626 if (new_checker_itb_port)
627 new_checker_itb_port->
takeOverFrom(old_checker_itb_port);
628 if (new_checker_dtb_port)
629 new_checker_dtb_port->
takeOverFrom(old_checker_dtb_port);
665 checker->getITBPtr()->flushAll();
666 checker->getDTBPtr()->flushAll();
742 assert(pkt->
req->hasPaddr());
743 if (armed && waiting) {
745 DPRINTF(Mwait,
"pAddr=0x%lx invalidated: waking up core\n",
785 return params()->wait_for_remote_gdb;
uint32_t taskId() const
Get cpu task id.
void ccprintf(cp::Print &print)
virtual const char * description() const
Return a C string describing the event.
virtual void unserializeThread(CheckpointIn &cp, ThreadID tid)
Unserialize one thread.
virtual void flushAll()=0
Remove all entries from the TLB.
Ports are used to interface objects to each other.
virtual Port & getPort(const std::string &if_name, PortID idx=InvalidPortID)
Get a port with a given name and index.
virtual void probeInstCommit(const StaticInstPtr &inst, Addr pc)
Helper method to trigger PMU probes for a committed instruction.
static void replaceThreadContext(ThreadContext *oldTc, ThreadContext *newTc)
Update all events switching old tc to new tc.
decltype(nullptr) constexpr NoFault
int findContext(ThreadContext *tc)
Given a Thread Context pointer return the thread num.
#define fatal(...)
This implements a cprintf based fatal() function.
ProbePoints::PMUUPtr ppRetiredStores
Retired store instructions.
ContextID registerThreadContext(ThreadContext *tc, ContextID assigned=InvalidContextID)
ThreadID numThreads
Number of threads we're actually simulating (<= SMT_MAX_THREADS).
virtual BaseTLB * getDTBPtr()=0
void registerThreadContexts()
Tick instCnt
Instruction count used for SPARC misc register.
void scheduleInstStop(ThreadID tid, Counter insts, const char *cause)
Schedule an event that exits the simulation loops after a predefined number of instructions.
std::vector< BaseInterrupts * > interrupts
std::shared_ptr< Request > RequestPtr
Port & getPort(const std::string &if_name, PortID idx=InvalidPortID) override
Get a port on this CPU.
Stats::Scalar numWorkItemsCompleted
EventFunctionWrapper enterPwrGatingEvent
BaseCPU(Params *params, bool is_checker=false)
uint64_t getCurrentInstCount(ThreadID tid)
Get the number of instructions executed by the specified thread on this CPU.
virtual void activateContext(ThreadID thread_num)
Notify the CPU that the indicated context is now active.
bool FullSystem
The FullSystem variable can be used to determine the current mode of simulation.
virtual Process * getProcessPtr()=0
bool switchedOut() const
Determine if the CPU is switched out.
bool _switchedOut
Is the CPU switched out or active?
virtual void regStats()
Callback to set stat parameters.
SymbolTable * debugSymbolTable
Global unified debugging symbol table (for target).
void unserialize(CheckpointIn &cp) override
Reconstruct the state of this object from a checkpoint.
Overload hash function for BasicBlockRange type.
int cpuId() const
Reads this CPU's ID.
ThreadContext is the external interface to all thread state for anything outside of the CPU...
void deschedule(Event &event)
void armMonitor(ThreadID tid, Addr address)
std::ostream * stream() const
Get the output underlying output stream.
const uint32_t _socketId
Each cpu will have a socket ID that corresponds to its physical location in the system.
RequestPtr req
A pointer to the original request.
void regStats() override
Callback to set stat parameters.
virtual void serializeThread(CheckpointOut &cp, ThreadID tid) const
Serialize a single thread.
ProbePoints::PMUUPtr ppActiveCycles
CPU cycle counter, only counts if any thread contexts is active.
std::vector< ThreadContext * > threadContexts
#define UNSERIALIZE_SCALAR(scalar)
virtual void setContextId(ContextID id)=0
Tick curTick()
The current simulated tick.
virtual Port & getInstPort()=0
Purely virtual method that returns a reference to the instruction port.
std::string csprintf(const char *format, const Args &...args)
void schedulePowerGatingEvent()
bool scheduled() const
Determine if the current event is scheduled.
void assignThreadContext(ContextID context_id)
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::unique_ptr< PMU > PMUUPtr
MasterID dataMasterId() const
Reads this CPU's unique data requestor ID.
uint64_t Tick
Tick count type.
void updateCycleCounters(CPUState state)
base method keeping track of cycle progression
ProbePointArg< bool > * ppSleeping
ProbePoint that signals transitions of threadContexts sets.
The ClockedObject class extends the SimObject with a clock and accessor functions to relate ticks to ...
EventFunctionWrapper * profileEvent
void startup() override
startup() is the final initialization call before simulation.
ClockedObject declaration and implementation.
bool findNearestSymbol(Addr addr, std::string &symbol, Addr &symaddr, Addr &nextaddr) const
Find the nearest symbol equal to or less than the supplied address (e.g., the label for the enclosing...
bool doMonitor(PacketPtr pkt)
ProbePoints::PMUUPtr ppRetiredInstsPC
virtual BaseTLB * getITBPtr()=0
std::vector< AddressMonitor > addressMonitor
#define fatal_if(cond,...)
Conditional fatal macro that checks the supplied condition and only causes a fatal error if the condi...
void flushTLBs()
Flush all TLBs in the CPU.
bool functionTracingEnabled
void mwaitAtomic(ThreadID tid, ThreadContext *tc, BaseTLB *dtb)
T roundDown(const T &val, const U &align)
This function is used to align addresses in memory.
virtual void verifyMemoryMode() const
Verify that the system is in a memory mode supported by the CPU.
virtual Addr instAddr() const =0
virtual Counter totalOps() const =0
virtual void takeOverFrom(BaseTLB *otlb)=0
Take over from an old tlb context.
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
uint32_t _pid
The current OS process ID that is executing on this processor.
virtual const std::string name() const
int64_t Counter
Statistics counter type.
A Packet is used to encapsulate a transfer between two objects in the memory system (e...
int maxThreadsPerCPU
The maximum number of active threads across all cpus.
bool waitForRemoteGDB() const
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...
Special TaskIds that are used for per-context-switch stats dumps and Cache Occupancy.
void processProfileEvent()
virtual void switchOut()
Prepare for another CPU to take over execution.
ProbePoints::PMUUPtr ppAllCycles
CPU cycle counter even if any thread Context is suspended.
#define SERIALIZE_SCALAR(scalar)
const bool powerGatingOnIdle
ProbePoints::PMUUPtr pmuProbePoint(const char *name)
Helper method to instantiate probe points belonging to this object.
Derived & name(const std::string &name)
Set the name and marks this stat to print at the end of simulation.
Enums::PwrState pwrState() const
int16_t ThreadID
Thread index/ID type.
OutputStream * findOrCreate(const std::string &name, bool binary=false)
bool mwait(ThreadID tid, PacketPtr pkt)
unsigned int cacheLineSize() const
Get the cache line size of the system.
virtual Port * getTableWalkerPort()
Get the table walker port if present.
virtual CheckerCPU * getCheckerCpuPtr()=0
ProbePointArg generates a point for the class of Arg.
static std::vector< BaseCPU * > cpuList
Static global cpu list.
void regProbePoints() override
Register probe points for this object.
Declarations of a non-full system Page Table.
std::ostream CheckpointOut
virtual void takeOverFrom(ThreadContext *old_context)=0
void deschedulePowerGatingEvent()
void takeOverFrom(Port *old)
A utility function to make it easier to swap out ports.
ProbePoints::PMUUPtr ppRetiredBranches
Retired branches (any type)
virtual int threadId() const =0
void traceFunctionsInternal(Addr pc)
ProbeManager * getProbeManager()
Get the probe manager for this object.
ProbePoints::PMUUPtr ppRetiredLoads
Retired load instructions.
void init() override
init() is called after all C++ SimObjects have been created and all ports are connected.
virtual ContextID contextId() const =0
virtual Port & getDataPort()=0
Purely virtual method that returns a reference to the data port.
void replaceThreadContext(ThreadContext *tc, ContextID context_id)
void schedule(Event &event, Tick when)
uint32_t _taskId
An intrenal representation of a task identifier within gem5.
Trace::InstTracer * tracer
void serialize(CheckpointOut &cp) const override
Serialize this object to the given output stream.
Derived & desc(const std::string &_desc)
Set the description and marks this stat to print at the end of simulation.
const Cycles pwrGatingLatency
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
virtual void haltContext(ThreadID thread_num)
Notify the CPU that the indicated context is now halted.
Scoped checkpoint section helper class.
void enableFunctionTrace()
std::shared_ptr< FaultBase > Fault
const Params * params() const
ProbePoints::PMUUPtr ppRetiredInsts
Instruction commit probe point.
std::ostream * functionTraceStream
virtual Fault translateAtomic(const RequestPtr &req, ThreadContext *tc, Mode mode)=0
virtual void suspendContext(ThreadID thread_num)
Notify the CPU that the indicated context is now suspended.
bool isLastMicroop() const
void cprintf(const char *format, const Args &...args)
Stats::Scalar numWorkItemsStarted
CPUProgressEvent(BaseCPU *_cpu, Tick ival=0)
Addr currentFunctionStart