gem5 v24.0.0.0
Loading...
Searching...
No Matches
gem5::BaseKvmCPU Class Referenceabstract

Base class for KVM based CPU models. More...

#include <base.hh>

Inheritance diagram for gem5::BaseKvmCPU:
gem5::BaseCPU gem5::ClockedObject gem5::SimObject gem5::Clocked gem5::EventManager gem5::Serializable gem5::Drainable gem5::statistics::Group gem5::Named gem5::ArmKvmCPU gem5::BaseArmKvmCPU gem5::X86KvmCPU gem5::ArmV8KvmCPU

Classes

class  KVMCpuPort
 KVM memory port. More...
 
struct  StatGroup
 

Public Member Functions

 BaseKvmCPU (const BaseKvmCPUParams &params)
 
virtual ~BaseKvmCPU ()
 
void init () override
 init() is called after all C++ SimObjects have been created and all ports are connected.
 
void startup () override
 startup() is the final initialization call before simulation.
 
void serializeThread (CheckpointOut &cp, ThreadID tid) const override
 Serialize a single thread.
 
void unserializeThread (CheckpointIn &cp, ThreadID tid) override
 Unserialize one thread.
 
DrainState drain () override
 Draining is the process of clearing out the states of SimObjects.These are the SimObjects that are partially executed or are partially in flight.
 
void drainResume () override
 Resume execution after a successful drain.
 
void notifyFork () override
 Notify a child process of a fork.
 
void switchOut () override
 Prepare for another CPU to take over execution.
 
void takeOverFrom (BaseCPU *cpu) override
 Load the state of a CPU from the previous CPU object, invoked on all new CPUs that are about to be switched in.
 
void verifyMemoryMode () const override
 Verify that the system is in a memory mode supported by the CPU.
 
PortgetDataPort () override
 Purely virtual method that returns a reference to the data port.
 
PortgetInstPort () override
 Purely virtual method that returns a reference to the instruction port.
 
void wakeup (ThreadID tid=0) override
 
void activateContext (ThreadID thread_num) override
 Notify the CPU that the indicated context is now active.
 
void suspendContext (ThreadID thread_num) override
 Notify the CPU that the indicated context is now suspended.
 
void deallocateContext (ThreadID thread_num)
 
void haltContext (ThreadID thread_num) override
 Notify the CPU that the indicated context is now halted.
 
long getVCpuID () const
 
ThreadContextgetContext (int tn) override
 Given a thread num get tho thread context for it.
 
Counter totalInsts () const override
 
Counter totalOps () const override
 
void finishMMIOPending ()
 Callback from KvmCPUPort to transition the CPU out of RunningMMIOPending when all timing requests have completed.
 
virtual void dump () const
 Dump the internal state to the terminal.
 
void kick () const
 Force an exit from KVM.
 
- Public Member Functions inherited from gem5::BaseCPU
int cpuId () const
 Reads this CPU's ID.
 
uint32_t socketId () const
 Reads this CPU's Socket ID.
 
RequestorID dataRequestorId () const
 Reads this CPU's unique data requestor ID.
 
RequestorID instRequestorId () const
 Reads this CPU's unique instruction requestor ID.
 
PortgetPort (const std::string &if_name, PortID idx=InvalidPortID) override
 Get a port on this CPU.
 
uint32_t taskId () const
 Get cpu task id.
 
void taskId (uint32_t id)
 Set cpu task id.
 
uint32_t getPid () const
 
void setPid (uint32_t pid)
 
void workItemBegin ()
 
void workItemEnd ()
 
Tick instCount ()
 
BaseInterruptsgetInterruptController (ThreadID tid)
 
void postInterrupt (ThreadID tid, int int_num, int index)
 
void clearInterrupt (ThreadID tid, int int_num, int index)
 
void clearInterrupts (ThreadID tid)
 
bool checkInterrupts (ThreadID tid) const
 
trace::InstTracergetTracer ()
 Provide access to the tracer pointer.
 
int findContext (ThreadContext *tc)
 Given a Thread Context pointer return the thread num.
 
unsigned numContexts ()
 Get the number of thread contexts available.
 
ThreadID contextToThread (ContextID cid)
 Convert ContextID to threadID.
 
 PARAMS (BaseCPU)
 
 BaseCPU (const Params &params, bool is_checker=false)
 
virtual ~BaseCPU ()
 
void regStats () override
 Callback to set stat parameters.
 
void regProbePoints () override
 Register probe points for this object.
 
void registerThreadContexts ()
 
void deschedulePowerGatingEvent ()
 
void schedulePowerGatingEvent ()
 
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.
 
bool switchedOut () const
 Determine if the CPU is switched out.
 
Addr cacheLineSize () const
 Get the cache line size of the system.
 
void serialize (CheckpointOut &cp) const override
 Serialize this object to the given output stream.
 
void unserialize (CheckpointIn &cp) override
 Reconstruct the state of this object from a checkpoint.
 
void scheduleInstStop (ThreadID tid, Counter insts, std::string cause)
 Schedule an event that exits the simulation loops after a predefined number of instructions.
 
void scheduleSimpointsInstStop (std::vector< Counter > inst_starts)
 Schedule simpoint events using the scheduleInstStop function.
 
void scheduleInstStopAnyThread (Counter max_insts)
 Schedule an exit event when any threads in the core reach the max_insts instructions using the scheduleInstStop function.
 
uint64_t getCurrentInstCount (ThreadID tid)
 Get the number of instructions executed by the specified thread on this CPU.
 
void traceFunctions (Addr pc)
 
void armMonitor (ThreadID tid, Addr address)
 
bool mwait (ThreadID tid, PacketPtr pkt)
 
void mwaitAtomic (ThreadID tid, ThreadContext *tc, BaseMMU *mmu)
 
AddressMonitorgetCpuAddrMonitor (ThreadID tid)
 
virtual void htmSendAbortSignal (ThreadID tid, uint64_t htm_uid, HtmFailureFaultCause cause)
 This function is used to instruct the memory subsystem that a transaction should be aborted and the speculative state should be thrown away.
 
virtual void probeInstCommit (const StaticInstPtr &inst, Addr pc)
 Helper method to trigger PMU probes for a committed instruction.
 
- Public Member Functions inherited from gem5::ClockedObject
 ClockedObject (const ClockedObjectParams &p)
 
void serialize (CheckpointOut &cp) const override
 Serialize an object.
 
void unserialize (CheckpointIn &cp) override
 Unserialize an object.
 
- Public Member Functions inherited from gem5::SimObject
const Paramsparams () const
 
 SimObject (const Params &p)
 
virtual ~SimObject ()
 
virtual void loadState (CheckpointIn &cp)
 loadState() is called on each SimObject when restoring from a checkpoint.
 
virtual void initState ()
 initState() is called on each SimObject when not restoring from a checkpoint.
 
virtual void regProbeListeners ()
 Register probe listeners for this object.
 
ProbeManagergetProbeManager ()
 Get the probe manager for this object.
 
DrainState drain () override
 Provide a default implementation of the drain interface for objects that don't need draining.
 
virtual void memWriteback ()
 Write back dirty buffers to memory using functional writes.
 
virtual void memInvalidate ()
 Invalidate the contents of memory buffers.
 
void serialize (CheckpointOut &cp) const override
 Serialize an object.
 
void unserialize (CheckpointIn &cp) override
 Unserialize an object.
 
- Public Member Functions inherited from gem5::EventManager
EventQueueeventQueue () const
 
void schedule (Event &event, Tick when)
 
void deschedule (Event &event)
 
void reschedule (Event &event, Tick when, bool always=false)
 
void schedule (Event *event, Tick when)
 
void deschedule (Event *event)
 
void reschedule (Event *event, Tick when, bool always=false)
 
void wakeupEventQueue (Tick when=(Tick) -1)
 This function is not needed by the usual gem5 event loop but may be necessary in derived EventQueues which host gem5 on other schedulers.
 
void setCurTick (Tick newVal)
 
 EventManager (EventManager &em)
 Event manger manages events in the event queue.
 
 EventManager (EventManager *em)
 
 EventManager (EventQueue *eq)
 
- Public Member Functions inherited from gem5::Serializable
 Serializable ()
 
virtual ~Serializable ()
 
void serializeSection (CheckpointOut &cp, const char *name) const
 Serialize an object into a new section.
 
void serializeSection (CheckpointOut &cp, const std::string &name) const
 
void unserializeSection (CheckpointIn &cp, const char *name)
 Unserialize an a child object.
 
void unserializeSection (CheckpointIn &cp, const std::string &name)
 
- Public Member Functions inherited from gem5::Drainable
DrainState drainState () const
 Return the current drain state of an object.
 
- Public Member Functions inherited from gem5::statistics::Group
 Group (Group *parent, const char *name=nullptr)
 Construct a new statistics group.
 
virtual ~Group ()
 
virtual void resetStats ()
 Callback to reset stats.
 
virtual void preDumpStats ()
 Callback before stats are dumped.
 
void addStat (statistics::Info *info)
 Register a stat with this group.
 
const std::map< std::string, Group * > & getStatGroups () const
 Get all child groups associated with this object.
 
const std::vector< Info * > & getStats () const
 Get all stats associated with this object.
 
void addStatGroup (const char *name, Group *block)
 Add a stat block as a child of this block.
 
const InforesolveStat (std::string name) const
 Resolve a stat by its name within this group.
 
void mergeStatGroup (Group *block)
 Merge the contents (stats & children) of a block to this block.
 
 Group ()=delete
 
 Group (const Group &)=delete
 
Groupoperator= (const Group &)=delete
 
- Public Member Functions inherited from gem5::Named
 Named (const std::string &name_)
 
virtual ~Named ()=default
 
virtual std::string name () const
 
- Public Member Functions inherited from gem5::Clocked
void updateClockPeriod ()
 Update the tick to the current tick.
 
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 caller to determine a future cycle.
 
Cycles curCycle () const
 Determine the current cycle, corresponding to a tick aligned to a clock edge.
 
Tick nextCycle () const
 Based on the clock of the object, determine the start tick of the first cycle that is at least one cycle in the future.
 
uint64_t frequency () const
 
Tick clockPeriod () const
 
double voltage () const
 
Cycles ticksToCycles (Tick t) const
 
Tick cyclesToTicks (Cycles c) const
 

Public Attributes

SimpleThreadthread
 A cached copy of a thread's state in the form of a SimpleThread object.
 
ThreadContexttc
 ThreadContext object, provides an interface for external objects to modify this thread's state.
 
KvmVMvm
 
gem5::BaseKvmCPU::StatGroup stats
 
Counter ctrInsts
 Number of instructions executed by the CPU.
 
- Public Attributes inherited from gem5::BaseCPU
ThreadID numThreads
 Number of threads we're actually simulating (<= SMT_MAX_THREADS).
 
Systemsystem
 
gem5::BaseCPU::BaseCPUStats baseStats
 
Cycles syscallRetryLatency
 
std::vector< std::unique_ptr< FetchCPUStats > > fetchStats
 
std::vector< std::unique_ptr< ExecuteCPUStats > > executeStats
 
std::vector< std::unique_ptr< CommitCPUStats > > commitStats
 
- Public Attributes inherited from gem5::ClockedObject
PowerStatepowerState
 

Protected Types

enum  Status {
  Idle , Running , RunningService , RunningMMIOPending ,
  RunningServiceCompletion
}
 
- Protected Types inherited from gem5::BaseCPU
enum  CPUState { CPU_STATE_ON , CPU_STATE_SLEEP , CPU_STATE_WAKEUP }
 

Protected Member Functions

void tick ()
 Execute the CPU until the next event in the main event queue or until the guest needs service from gem5.
 
virtual uint64_t getHostCycles () const
 Get the value of the hardware cycle counter in the guest.
 
virtual void stutterPC (PCStateBase &pc) const =0
 Modify a PCStatePtr's value so that its next PC is the current PC.
 
virtual Tick kvmRun (Tick ticks)
 Request KVM to run the guest for a given number of ticks.
 
virtual Tick kvmRunDrain ()
 Request the CPU to run until draining completes.
 
struct kvm_run * getKvmRunState ()
 Get a pointer to the kvm_run structure containing all the input and output parameters from kvmRun().
 
uint8_t * getGuestData (uint64_t offset) const
 Retrieve a pointer to guest data stored at the end of the kvm_run structure.
 
void kvmNonMaskableInterrupt ()
 Send a non-maskable interrupt to the guest.
 
void kvmInterrupt (const struct kvm_interrupt &interrupt)
 Send a normal interrupt to the guest.
 
std::string getAndFormatOneReg (uint64_t id) const
 Get and format one register for printout.
 
virtual bool archIsDrained () const
 Is the architecture specific code in a state that prevents draining?
 
Tick doMMIOAccess (Addr paddr, void *data, int size, bool write)
 Inject a memory mapped IO request into gem5.
 
int ioctl (int request, long p1) const
 vCPU ioctl interface.
 
int ioctl (int request, void *p1) const
 
int ioctl (int request) const
 
virtual void ioctlRun ()
 Execute the KVM_RUN ioctl.
 
void getRegisters (struct kvm_regs &regs) const
 Get/Set the register state of the guest vCPU.
 
void setRegisters (const struct kvm_regs &regs)
 
void getSpecialRegisters (struct kvm_sregs &regs) const
 
void setSpecialRegisters (const struct kvm_sregs &regs)
 
void getFPUState (struct kvm_fpu &state) const
 Get/Set the guest FPU/vector state.
 
void setFPUState (const struct kvm_fpu &state)
 
void setOneReg (uint64_t id, const void *addr)
 Get/Set single register using the KVM_(SET|GET)_ONE_REG API.
 
void setOneReg (uint64_t id, uint64_t value)
 
void setOneReg (uint64_t id, uint32_t value)
 
void getOneReg (uint64_t id, void *addr) const
 
uint64_t getOneRegU64 (uint64_t id) const
 
uint32_t getOneRegU32 (uint64_t id) const
 
virtual void updateKvmState ()=0
 Update the KVM state from the current thread context.
 
virtual void updateThreadContext ()=0
 Update the current thread context with the KVM state.
 
void syncThreadContext ()
 Update a thread context if the KVM state is dirty with respect to the cached thread context.
 
EventQueuedeviceEventQueue ()
 Get a pointer to the event queue owning devices.
 
void syncKvmState ()
 Update the KVM if the thread context is dirty.
 
virtual Tick handleKvmExit ()
 Main kvmRun exit handler, calls the relevant handleKvmExit* depending on exit type.
 
virtual Tick handleKvmExitIO ()
 The guest performed a legacy IO request (out/inp on x86)
 
virtual Tick handleKvmExitHypercall ()
 The guest requested a monitor service using a hypercall.
 
virtual Tick handleKvmExitIRQWindowOpen ()
 The guest exited because an interrupt window was requested.
 
virtual Tick handleKvmExitUnknown ()
 An unknown architecture dependent error occurred when starting the vCPU.
 
virtual Tick handleKvmExitException ()
 An unhandled virtualization exception occured.
 
virtual Tick handleKvmExitFailEntry ()
 KVM failed to start the virtualized CPU.
 
void setSignalMask (const sigset_t *mask)
 Set the signal mask used in kvmRun()
 
- Protected Member Functions inherited from gem5::BaseCPU
void updateCycleCounters (CPUState state)
 base method keeping track of cycle progression
 
void enterPwrGating ()
 
probing::PMUUPtr pmuProbePoint (const char *name)
 Helper method to instantiate probe points belonging to this object.
 
- Protected Member Functions inherited from gem5::Drainable
 Drainable ()
 
virtual ~Drainable ()
 
void signalDrainDone () const
 Signal that an object is drained.
 
- Protected Member Functions inherited from gem5::Clocked
 Clocked (ClockDomain &clk_domain)
 Create a clocked object and set the clock domain based on the parameters.
 
 Clocked (Clocked &)=delete
 
Clockedoperator= (Clocked &)=delete
 
virtual ~Clocked ()
 Virtual destructor due to inheritance.
 
void resetClock () const
 Reset the object's clock using the current global tick value.
 
virtual void clockPeriodUpdated ()
 A hook subclasses can implement so they can do any extra work that's needed when the clock rate is changed.
 

Protected Attributes

Status _status
 CPU run state.
 
KVMCpuPort dataPort
 Port for data requests.
 
KVMCpuPort instPort
 Unused dummy port for the instruction interface.
 
const bool alwaysSyncTC
 Be conservative and always synchronize the thread context on KVM entry/exit.
 
bool threadContextDirty
 Is the gem5 context dirty? Set to true to force an update of the KVM vCPU state upon the next call to kvmRun().
 
bool kvmStateDirty
 Is the KVM state dirty? Set to true to force an update of the KVM vCPU state upon the next call to kvmRun().
 
bool usePerf
 True if using perf; False otherwise.
 
long vcpuID
 KVM internal ID of the vCPU.
 
pthread_t vcpuThread
 ID of the vCPU thread.
 
- Protected Attributes inherited from gem5::BaseCPU
Tick instCnt
 Instruction count used for SPARC misc register.
 
int _cpuId
 
const uint32_t _socketId
 Each cpu will have a socket ID that corresponds to its physical location in the system.
 
RequestorID _instRequestorId
 instruction side request id that must be placed in all requests
 
RequestorID _dataRequestorId
 data side request id that must be placed in all requests
 
uint32_t _taskId
 An intrenal representation of a task identifier within gem5.
 
uint32_t _pid
 The current OS process ID that is executing on this processor.
 
bool _switchedOut
 Is the CPU switched out or active?
 
const Addr _cacheLineSize
 Cache the cache line size that we get from the system.
 
SignalSinkPort< bool > modelResetPort
 
std::vector< BaseInterrupts * > interrupts
 
std::vector< ThreadContext * > threadContexts
 
trace::InstTracertracer
 
Cycles previousCycle
 
CPUState previousState
 
const Cycles pwrGatingLatency
 
const bool powerGatingOnIdle
 
EventFunctionWrapper enterPwrGatingEvent
 
probing::PMUUPtr ppRetiredInsts
 Instruction commit probe point.
 
probing::PMUUPtr ppRetiredInstsPC
 
probing::PMUUPtr ppRetiredLoads
 Retired load instructions.
 
probing::PMUUPtr ppRetiredStores
 Retired store instructions.
 
probing::PMUUPtr ppRetiredBranches
 Retired branches (any type)
 
probing::PMUUPtr ppAllCycles
 CPU cycle counter even if any thread Context is suspended.
 
probing::PMUUPtr ppActiveCycles
 CPU cycle counter, only counts if any thread contexts is active.
 
ProbePointArg< bool > * ppSleeping
 ProbePoint that signals transitions of threadContexts sets.
 
- Protected Attributes inherited from gem5::SimObject
const SimObjectParams & _params
 Cached copy of the object parameters.
 
- Protected Attributes inherited from gem5::EventManager
EventQueueeventq
 A pointer to this object's event queue.
 

Private Member Functions

Tick flushCoalescedMMIO ()
 Service MMIO requests in the mmioRing.
 
void setupSignalHandler ()
 Setup a signal handler to catch the timer signal used to switch back to the monitor.
 
bool discardPendingSignal (int signum) const
 Discard a (potentially) pending signal.
 
void restartEqThread ()
 Thread-specific initialization.
 
bool tryDrain ()
 Try to drain the CPU if a drain is pending.
 
void setupInstStop ()
 Setup an instruction break if there is one pending.
 

Private Attributes

int vcpuFD
 KVM vCPU file descriptor.
 
int vcpuMMapSize
 Size of MMAPed kvm_run area.
 
struct kvm_run * _kvmRun
 Pointer to the kvm_run structure used to communicate parameters with KVM.
 
struct kvm_coalesced_mmio_ring * mmioRing
 Coalesced MMIO ring buffer.
 
const long pageSize
 Cached page size of the host.
 
EventFunctionWrapper tickEvent
 
std::unique_ptr< BaseKvmTimerrunTimer
 Timer used to force execution into the monitor after a specified number of simulation tick equivalents have executed in the guest.
 
float hostFactor
 Host factor as specified in the configuration.
 
uint64_t activeInstPeriod
 Currently active instruction count breakpoint.
 
std::unique_ptr< PerfKvmCounterhwCycles
 Guest cycle counter.
 
std::unique_ptr< PerfKvmCounterhwInstructions
 Guest instruction counter.
 
bool perfControlledByTimer
 Does the runTimer control the performance counters?
 
void setupCounters ()
 Setup hardware performance counters.
 
void setupInstCounter (uint64_t period=0)
 Setup the guest instruction counter.
 

Additional Inherited Members

- Public Types inherited from gem5::ClockedObject
using Params = ClockedObjectParams
 Parameters of ClockedObject.
 
- Public Types inherited from gem5::SimObject
typedef SimObjectParams Params
 
- Static Public Member Functions inherited from gem5::BaseCPU
static int numSimulatedCPUs ()
 
static Counter numSimulatedInsts ()
 
static Counter numSimulatedOps ()
 
- Static Public Member Functions inherited from gem5::SimObject
static void serializeAll (const std::string &cpt_dir)
 Create a checkpoint by serializing all SimObjects in the system.
 
static SimObjectfind (const char *name)
 Find the SimObject with the given name and return a pointer to it.
 
static void setSimObjectResolver (SimObjectResolver *resolver)
 There is a single object name resolver, and it is only set when simulation is restoring from checkpoints.
 
static SimObjectResolvergetSimObjectResolver ()
 There is a single object name resolver, and it is only set when simulation is restoring from checkpoints.
 
- Static Public Member Functions inherited from gem5::Serializable
static const std::string & currentSection ()
 Gets the fully-qualified name of the active section.
 
static void generateCheckpointOut (const std::string &cpt_dir, std::ofstream &outstream)
 Generate a checkpoint file so that the serialization can be routed to it.
 
- Static Public Attributes inherited from gem5::BaseCPU
static const uint32_t invldPid = std::numeric_limits<uint32_t>::max()
 Invalid or unknown Pid.
 
- Static Protected Attributes inherited from gem5::BaseCPU
static std::unique_ptr< GlobalStatsglobalStats
 Pointer to the global stat structure.
 

Detailed Description

Base class for KVM based CPU models.

All architecture specific KVM implementation should inherit from this class. The most basic CPU models only need to override the updateKvmState() and updateThreadContext() methods to implement state synchronization between gem5 and KVM.

The architecture specific implementation is also responsible for delivering interrupts into the VM. This is typically done by overriding tick() and checking the thread context before entering into the VM. In order to deliver an interrupt, the implementation then calls KvmVM::setIRQLine() or BaseKvmCPU::kvmInterrupt() depending on the specifics of the underlying hardware/drivers.

Definition at line 87 of file base.hh.

Member Enumeration Documentation

◆ Status

enum gem5::BaseKvmCPU::Status
protected
Enumerator
Idle 

Context not scheduled in KVM.

The CPU generally enters this state when the guest execute an instruction that halts the CPU (e.g., WFI on ARM or HLT on X86) if KVM traps this instruction. Ticks are not scheduled in this state.

See also
suspendContext()
Running 

Running normally.

This is the normal run state of the CPU. KVM will be entered next time tick() is called.

RunningService 

Requiring service at the beginning of the next cycle.

The virtual machine has exited and requires service, tick() will call handleKvmExit() on the next cycle. The next state after running service is determined in handleKvmExit() and depends on what kind of service the guest requested:

  • IO/MMIO (Atomic): RunningServiceCompletion
  • IO/MMIO (Timing): RunningMMIOPending
  • Halt: Idle
  • Others: Running
RunningMMIOPending 

Timing MMIO request in flight or stalled.

The VM has requested IO/MMIO and we are in timing mode. A timing request is either stalled (and will be retried with recvReqRetry()) or it is in flight. After the timing request is complete, the CPU will transition to the RunningServiceCompletion state.

RunningServiceCompletion 

Service completion in progress.

The VM has requested service that requires KVM to be entered once in order to get to a consistent state. This happens in handleKvmExit() or one of its friends after IO exits. After executing tick(), the CPU will transition into the Running or RunningService state.

Definition at line 188 of file base.hh.

Constructor & Destructor Documentation

◆ BaseKvmCPU()

gem5::BaseKvmCPU::BaseKvmCPU ( const BaseKvmCPUParams & params)

Definition at line 65 of file base.cc.

References tick().

◆ ~BaseKvmCPU()

gem5::BaseKvmCPU::~BaseKvmCPU ( )
virtual

Definition at line 120 of file base.cc.

References _kvmRun, vcpuFD, and vcpuMMapSize.

Member Function Documentation

◆ activateContext()

void gem5::BaseKvmCPU::activateContext ( ThreadID thread_num)
overridevirtual

◆ archIsDrained()

virtual bool gem5::BaseKvmCPU::archIsDrained ( ) const
inlineprotectedvirtual

Is the architecture specific code in a state that prevents draining?

This method should return false if there are any pending events in the guest vCPU that won't be carried over to the gem5 state and thus will prevent correct checkpointing or CPU handover. It might, for example, check for pending interrupts that have been passed to the vCPU but not acknowledged by the OS. Architecures implementing this method must override kvmRunDrain().

See also
BaseKvmCPU::kvmRunDrain()
Returns
true if the vCPU is drained, false otherwise.

Reimplemented in gem5::X86KvmCPU.

Definition at line 541 of file base.hh.

Referenced by drain(), and tryDrain().

◆ deallocateContext()

void gem5::BaseKvmCPU::deallocateContext ( ThreadID thread_num)

Definition at line 559 of file base.cc.

References suspendContext().

◆ deviceEventQueue()

EventQueue * gem5::BaseKvmCPU::deviceEventQueue ( )
inlineprotected

Get a pointer to the event queue owning devices.

Devices always live in a separate device event queue when running in multi-core mode. We need to temporarily migrate to this queue when accessing devices. By convention, devices and the VM use the same event queue.

Definition at line 447 of file base.hh.

References gem5::EventManager::eventQueue(), and vm.

Referenced by doMMIOAccess(), gem5::X86KvmCPU::handleKvmExitIO(), gem5::ArmV8KvmCPU::updateKvmState(), and gem5::ArmV8KvmCPU::updateThreadContext().

◆ discardPendingSignal()

bool gem5::BaseKvmCPU::discardPendingSignal ( int signum) const
private

Discard a (potentially) pending signal.

Parameters
signumSignal to discard
Returns
true if the signal was pending, false otherwise.

Definition at line 1268 of file base.cc.

References panic.

Referenced by kvmRun().

◆ doMMIOAccess()

Tick gem5::BaseKvmCPU::doMMIOAccess ( Addr paddr,
void * data,
int size,
bool write )
protected

◆ drain()

DrainState gem5::BaseKvmCPU::drain ( )
overridevirtual

Draining is the process of clearing out the states of SimObjects.These are the SimObjects that are partially executed or are partially in flight.

Draining is mostly used before forking and creating a check point.

This function notifies an object that it needs to drain its state.

If the object does not need further simulation to drain internal buffers, it returns DrainState::Drained and automatically switches to the Drained state. If the object needs more simulation, it returns DrainState::Draining and automatically enters the Draining state. Other return values are invalid.

Note
An object that has entered the Drained state can be disturbed by other objects in the system and consequently stop being drained. These perturbations are not visible in the drain state. The simulator therefore repeats the draining process until all objects return DrainState::Drained on the first call to drain().
Returns
DrainState::Drained if the object is drained at this point in time, DrainState::Draining if it needs further simulation.

Implements gem5::Drainable.

Definition at line 328 of file base.cc.

References _status, archIsDrained(), gem5::EventManager::deschedule(), DPRINTF, gem5::Drained, gem5::Draining, gem5::EventManager::eventQueue(), Idle, gem5::X86ISA::lock, panic, Running, RunningMMIOPending, RunningService, RunningServiceCompletion, gem5::Event::scheduled(), gem5::BaseCPU::switchedOut(), syncThreadContext(), and tickEvent.

◆ drainResume()

void gem5::BaseKvmCPU::drainResume ( )
overridevirtual

◆ dump()

void gem5::BaseKvmCPU::dump ( ) const
virtual

Dump the internal state to the terminal.

Reimplemented in gem5::ArmV8KvmCPU, and gem5::X86KvmCPU.

Definition at line 596 of file base.cc.

References inform.

Referenced by handleKvmExit(), handleKvmExitException(), handleKvmExitFailEntry(), handleKvmExitUnknown(), and serializeThread().

◆ finishMMIOPending()

void gem5::BaseKvmCPU::finishMMIOPending ( )

Callback from KvmCPUPort to transition the CPU out of RunningMMIOPending when all timing requests have completed.

Definition at line 242 of file base.cc.

References _status, gem5::Clocked::nextCycle(), RunningMMIOPending, RunningServiceCompletion, gem5::EventManager::schedule(), gem5::Event::scheduled(), and tickEvent.

◆ flushCoalescedMMIO()

Tick gem5::BaseKvmCPU::flushCoalescedMMIO ( )
private

Service MMIO requests in the mmioRing.

Returns
Number of ticks spent servicing the MMIO requests in the MMIO ring buffer

Definition at line 1197 of file base.cc.

References doMMIOAccess(), DPRINTF, mmioRing, gem5::BaseKvmCPU::StatGroup::numCoalescedMMIO, and stats.

Referenced by kvmRun().

◆ getAndFormatOneReg()

std::string gem5::BaseKvmCPU::getAndFormatOneReg ( uint64_t id) const
protected

Get and format one register for printout.

This function call getOneReg() to retrieve the contents of one register and automatically formats it for printing.

Note
The presence of this call depends on Kvm::capOneReg().

Definition at line 919 of file base.cc.

References panic, and gem5::ArmISA::ss.

Referenced by gem5::ArmV8KvmCPU::dump(), gem5::ArmKvmCPU::dumpKvmStateCoProc(), gem5::ArmKvmCPU::dumpKvmStateMisc(), gem5::ArmKvmCPU::dumpKvmStateVFP(), gem5::ArmV8KvmCPU::updateKvmState(), and gem5::ArmV8KvmCPU::updateThreadContext().

◆ getContext()

ThreadContext * gem5::BaseKvmCPU::getContext ( int tn)
overridevirtual

Given a thread num get tho thread context for it.

Reimplemented from gem5::BaseCPU.

Definition at line 574 of file base.cc.

References syncThreadContext(), and tc.

◆ getDataPort()

Port & gem5::BaseKvmCPU::getDataPort ( )
inlineoverridevirtual

Purely virtual method that returns a reference to the data port.

All subclasses must implement this method.

Returns
a reference to the data port

Implements gem5::BaseCPU.

Definition at line 108 of file base.hh.

References dataPort.

◆ getFPUState()

void gem5::BaseKvmCPU::getFPUState ( struct kvm_fpu & state) const
protected

Get/Set the guest FPU/vector state.

Definition at line 870 of file base.cc.

References ioctl(), panic, and state.

Referenced by gem5::X86KvmCPU::dumpFpuRegs(), and gem5::X86KvmCPU::updateThreadContext().

◆ getGuestData()

uint8_t * gem5::BaseKvmCPU::getGuestData ( uint64_t offset) const
inlineprotected

Retrieve a pointer to guest data stored at the end of the kvm_run structure.

This is mainly used for PIO operations (KVM_EXIT_IO).

Parameters
offsetOffset as specified by the kvm_run structure
Returns
Pointer to guest data

Definition at line 327 of file base.hh.

References _kvmRun, and gem5::ArmISA::offset.

Referenced by gem5::X86KvmCPU::handleIOMiscReg32(), and gem5::X86KvmCPU::handleKvmExitIO().

◆ getHostCycles()

uint64_t gem5::BaseKvmCPU::getHostCycles ( ) const
protectedvirtual

Get the value of the hardware cycle counter in the guest.

This method is supposed to return the total number of cycles executed in hardware mode relative to some arbitrary point in the past. It's mainly used when estimating the number of cycles actually executed by the CPU in kvmRun(). The default behavior of this method is to use the cycles performance counter, but some architectures may want to use internal registers instead.

Returns
Number of host cycles executed relative to an undefined point in the past.

Reimplemented in gem5::X86KvmCPU.

Definition at line 712 of file base.cc.

References hwCycles, and usePerf.

Referenced by kvmRun().

◆ getInstPort()

Port & gem5::BaseKvmCPU::getInstPort ( )
inlineoverridevirtual

Purely virtual method that returns a reference to the instruction port.

All subclasses must implement this method.

Returns
a reference to the instruction port

Implements gem5::BaseCPU.

Definition at line 109 of file base.hh.

References instPort.

◆ getKvmRunState()

struct kvm_run * gem5::BaseKvmCPU::getKvmRunState ( )
inlineprotected

Get a pointer to the kvm_run structure containing all the input and output parameters from kvmRun().

Definition at line 317 of file base.hh.

References _kvmRun.

Referenced by gem5::X86KvmCPU::handleIOMiscReg32(), gem5::X86KvmCPU::handleKvmExitIO(), gem5::X86KvmCPU::ioctlRun(), gem5::BaseArmKvmCPU::kvmRun(), gem5::X86KvmCPU::kvmRun(), gem5::X86KvmCPU::kvmRunDrain(), and gem5::X86KvmCPU::updateThreadContextSRegs().

◆ getOneReg()

void gem5::BaseKvmCPU::getOneReg ( uint64_t id,
void * addr ) const
protected

◆ getOneRegU32()

uint32_t gem5::BaseKvmCPU::getOneRegU32 ( uint64_t id) const
inlineprotected

◆ getOneRegU64()

uint64_t gem5::BaseKvmCPU::getOneRegU64 ( uint64_t id) const
inlineprotected

◆ getRegisters()

void gem5::BaseKvmCPU::getRegisters ( struct kvm_regs & regs) const
protected

Get/Set the register state of the guest vCPU.

KVM has two different interfaces for accessing the state of the guest CPU. One interface updates 'normal' registers and one updates 'special' registers. The distinction between special and normal registers isn't very clear and is architecture dependent.

Definition at line 842 of file base.cc.

References ioctl(), and panic.

Referenced by gem5::X86KvmCPU::dumpIntRegs(), and gem5::X86KvmCPU::updateThreadContext().

◆ getSpecialRegisters()

void gem5::BaseKvmCPU::getSpecialRegisters ( struct kvm_sregs & regs) const
protected

Definition at line 856 of file base.cc.

References ioctl(), and panic.

Referenced by gem5::X86KvmCPU::dumpSpecRegs(), and gem5::X86KvmCPU::updateThreadContext().

◆ getVCpuID()

long gem5::BaseKvmCPU::getVCpuID ( ) const
inline

Definition at line 117 of file base.hh.

References vcpuID.

◆ haltContext()

void gem5::BaseKvmCPU::haltContext ( ThreadID thread_num)
overridevirtual

Notify the CPU that the indicated context is now halted.

Reimplemented from gem5::BaseCPU.

Definition at line 566 of file base.cc.

References gem5::BaseCPU::CPU_STATE_SLEEP, suspendContext(), and gem5::BaseCPU::updateCycleCounters().

◆ handleKvmExit()

◆ handleKvmExitException()

Tick gem5::BaseKvmCPU::handleKvmExitException ( )
protectedvirtual

An unhandled virtualization exception occured.

Some KVM virtualization drivers return unhandled exceptions to the user-space monitor. This interface is currently only used by the Intel VMX KVM driver.

Returns
Number of ticks delay the next CPU tick

Definition at line 1097 of file base.cc.

References _kvmRun, dump(), and panic.

Referenced by handleKvmExit().

◆ handleKvmExitFailEntry()

Tick gem5::BaseKvmCPU::handleKvmExitFailEntry ( )
protectedvirtual

KVM failed to start the virtualized CPU.

The kvm_run data structure contains the hardware-specific error code.

Returns
Number of ticks delay the next CPU tick

Definition at line 1106 of file base.cc.

References _kvmRun, dump(), and panic.

Referenced by handleKvmExit().

◆ handleKvmExitHypercall()

Tick gem5::BaseKvmCPU::handleKvmExitHypercall ( )
protectedvirtual

The guest requested a monitor service using a hypercall.

Returns
Number of ticks spent servicing the hypercall

Definition at line 1075 of file base.cc.

References panic.

Referenced by handleKvmExit().

◆ handleKvmExitIO()

Tick gem5::BaseKvmCPU::handleKvmExitIO ( )
protectedvirtual

The guest performed a legacy IO request (out/inp on x86)

Returns
Number of ticks spent servicing the IO request

Reimplemented in gem5::X86KvmCPU.

Definition at line 1067 of file base.cc.

References _kvmRun, and panic.

Referenced by handleKvmExit().

◆ handleKvmExitIRQWindowOpen()

Tick gem5::BaseKvmCPU::handleKvmExitIRQWindowOpen ( )
protectedvirtual

The guest exited because an interrupt window was requested.

The guest exited because an interrupt window was requested (request_interrupt_window in the kvm_run structure was set to 1 before calling kvmRun) and it is now ready to receive

Returns
Number of ticks spent servicing the IRQ

Reimplemented in gem5::X86KvmCPU.

Definition at line 1081 of file base.cc.

References warn.

Referenced by handleKvmExit().

◆ handleKvmExitUnknown()

Tick gem5::BaseKvmCPU::handleKvmExitUnknown ( )
protectedvirtual

An unknown architecture dependent error occurred when starting the vCPU.

The kvm_run data structure contains the hardware error code. The defaults behavior of this method just prints the HW error code and panics. Architecture dependent implementations may want to override this method to provide better, hardware-aware, error messages.

Returns
Number of ticks delay the next CPU tick

Definition at line 1089 of file base.cc.

References _kvmRun, dump(), and panic.

Referenced by handleKvmExit().

◆ init()

void gem5::BaseKvmCPU::init ( )
overridevirtual

init() is called after all C++ SimObjects have been created and all ports are connected.

Initializations that are independent of unserialization but rely on a fully instantiated and connected SimObject graph should be done here.

Reimplemented from gem5::BaseCPU.

Reimplemented in gem5::X86KvmCPU.

Definition at line 128 of file base.cc.

References gem5::KvmVM::allocVCPUID(), fatal_if, gem5::System::getKvmVM(), gem5::BaseCPU::init(), gem5::BaseCPU::numThreads, gem5::BaseCPU::system, vcpuID, and vm.

Referenced by gem5::X86KvmCPU::init(), gem5::ArmKvmCPU::kvmArmVCpuInit(), gem5::ArmKvmCPU::kvmArmVCpuInit(), and gem5::BaseArmKvmCPU::kvmArmVCpuInit().

◆ ioctlRun()

void gem5::BaseKvmCPU::ioctlRun ( )
protectedvirtual

Execute the KVM_RUN ioctl.

Reimplemented in gem5::BaseArmKvmCPU, and gem5::X86KvmCPU.

Definition at line 1355 of file base.cc.

References ioctl(), and panic.

Referenced by gem5::BaseArmKvmCPU::ioctlRun(), gem5::X86KvmCPU::ioctlRun(), and kvmRun().

◆ kick()

void gem5::BaseKvmCPU::kick ( ) const
inline

Force an exit from KVM.

Send a signal to the thread owning this vCPU to get it to exit from KVM. Ignored if the vCPU is not executing.

Definition at line 138 of file base.hh.

References KVM_KICK_SIGNAL, and vcpuThread.

Referenced by kvmRun(), and wakeup().

◆ kvmRun()

Tick gem5::BaseKvmCPU::kvmRun ( Tick ticks)
protectedvirtual

Request KVM to run the guest for a given number of ticks.

The method returns the approximate number of ticks executed.

Note
The returned number of ticks can be both larger or smaller than the requested number of ticks. A smaller number can, for example, occur when the guest executes MMIO. A larger number is typically due to performance counter inaccuracies.
This method is virtual in order to allow implementations to check for architecture specific events (e.g., interrupts) before entering the VM.
It is the response of the caller (normally tick()) to make sure that the KVM state is synchronized and that the TC is invalidated after entering KVM.
This method does not normally cause any state transitions. However, if it may suspend the CPU by suspending the thread, which leads to a transition to the Idle state. In such a case, kvm must not be entered.
Parameters
ticksNumber of ticks to execute, set to 0 to exit immediately after finishing pending operations.
Returns
Number of ticks executed (see note)

Reimplemented in gem5::ArmKvmCPU, gem5::BaseArmKvmCPU, and gem5::X86KvmCPU.

Definition at line 720 of file base.cc.

References gem5::BaseCPU::baseStats, gem5::Clocked::clockPeriod(), gem5::BaseCPU::commitStats, ctrInsts, gem5::curEventQueue(), discardPendingSignal(), DPRINTF, fatal_if, flushCoalescedMMIO(), getHostCycles(), hostFactor, hwCycles, hwInstructions, ioctlRun(), kick(), KVM_KICK_SIGNAL, gem5::BaseCPU::BaseCPUStats::numCycles, gem5::BaseCPU::BaseCPUStats::numInsts, gem5::BaseKvmCPU::StatGroup::numVMExits, gem5::BaseKvmCPU::StatGroup::numVMHalfEntries, perfControlledByTimer, runTimer, stats, thread, gem5::SimpleThread::threadId(), usePerf, and vcpuFD.

Referenced by gem5::ArmKvmCPU::kvmRun(), gem5::BaseArmKvmCPU::kvmRun(), gem5::X86KvmCPU::kvmRun(), kvmRunDrain(), gem5::X86KvmCPU::kvmRunDrain(), and tick().

◆ kvmRunDrain()

Tick gem5::BaseKvmCPU::kvmRunDrain ( )
protectedvirtual

Request the CPU to run until draining completes.

This function normally calls kvmRun(0) to make KVM finish pending MMIO operations. Architecures implementing archIsDrained() must override this method.

See also
BaseKvmCPU::archIsDrained()
Returns
Number of ticks executed

Reimplemented in gem5::X86KvmCPU.

Definition at line 698 of file base.cc.

References _status, kvmRun(), RunningMMIOPending, and RunningServiceCompletion.

Referenced by tick().

◆ notifyFork()

void gem5::BaseKvmCPU::notifyFork ( )
overridevirtual

Notify a child process of a fork.

SimObjects are told that the process is going to be forked.

Forking is a process of splitting a process in to two processes, which is then used for multiprocessing.

When calling fork in gem5, we need to ensure that resources shared between the parent and the child are consistent. This method is intended to be overloaded to handle that. For example, an object could use this method to re-open input files to get a separate file description with a private file offset.

This method is only called in the child of the fork. The call takes place in a drained system.

Reimplemented from gem5::Drainable.

Definition at line 429 of file base.cc.

References _kvmRun, _status, hwCycles, hwInstructions, Idle, gem5::Event::scheduled(), tickEvent, usePerf, vcpuFD, vcpuMMapSize, and warn.

◆ restartEqThread()

void gem5::BaseKvmCPU::restartEqThread ( )
private

Thread-specific initialization.

Some KVM-related initialization requires us to know the TID of the thread that is going to execute our event queue. For example, when setting up timers, we need to know the TID of the thread executing in KVM in order to deliver the timer signal to that thread. This method is called as the first event in this SimObject's event queue and after drainResume to handle changes to event queue service threads.

See also
startup

Definition at line 252 of file base.cc.

References hwCycles, KVM_KICK_SIGNAL, gem5::MipsISA::p, gem5::SimObject::params(), runTimer, setupCounters(), setupSignalHandler(), and vcpuThread.

Referenced by drainResume(), and startup().

◆ serializeThread()

void gem5::BaseKvmCPU::serializeThread ( CheckpointOut & cp,
ThreadID tid ) const
overridevirtual

Serialize a single thread.

Parameters
cpThe stream to serialize to.
tidID of the current thread.

Reimplemented from gem5::BaseCPU.

Definition at line 304 of file base.cc.

References _status, DPRINTF, dump(), Idle, gem5::SimpleThread::serialize(), and thread.

◆ setFPUState()

void gem5::BaseKvmCPU::setFPUState ( const struct kvm_fpu & state)
protected

Definition at line 877 of file base.cc.

References ioctl(), panic, and state.

Referenced by gem5::X86KvmCPU::updateKvmStateFPULegacy().

◆ setOneReg() [1/3]

void gem5::BaseKvmCPU::setOneReg ( uint64_t id,
const void * addr )
protected

◆ setOneReg() [2/3]

void gem5::BaseKvmCPU::setOneReg ( uint64_t id,
uint32_t value )
inlineprotected

Definition at line 388 of file base.hh.

References setOneReg().

Referenced by setOneReg().

◆ setOneReg() [3/3]

void gem5::BaseKvmCPU::setOneReg ( uint64_t id,
uint64_t value )
inlineprotected

Definition at line 387 of file base.hh.

References setOneReg().

Referenced by setOneReg().

◆ setRegisters()

void gem5::BaseKvmCPU::setRegisters ( const struct kvm_regs & regs)
protected

Definition at line 849 of file base.cc.

References ioctl(), and panic.

Referenced by gem5::X86KvmCPU::updateKvmStateRegs().

◆ setSignalMask()

void gem5::BaseKvmCPU::setSignalMask ( const sigset_t * mask)
protected

Set the signal mask used in kvmRun()

This method allows the signal mask of the thread executing kvmRun() to be overridden inside the actual system call. This allows us to mask timer signals used to force KVM exits while in gem5.

The signal mask can be disabled by setting it to NULL.

Parameters
maskSignals to mask

Definition at line 1166 of file base.cc.

References ioctl(), gem5::ArmISA::mask, gem5::MipsISA::p, and panic.

Referenced by setupSignalHandler().

◆ setSpecialRegisters()

void gem5::BaseKvmCPU::setSpecialRegisters ( const struct kvm_sregs & regs)
protected

Definition at line 863 of file base.cc.

References ioctl(), and panic.

Referenced by gem5::X86KvmCPU::updateKvmStateSRegs().

◆ setupCounters()

◆ setupInstCounter()

void gem5::BaseKvmCPU::setupInstCounter ( uint64_t period = 0)
private

Setup the guest instruction counter.

Setup the guest instruction counter and optionally request a signal every N instructions executed by the guest. This method will re-attach the counter if the counter has already been attached and its sampling settings have changed.

Parameters
periodSignal period, set to 0 to disable signaling.

Definition at line 1377 of file base.cc.

References activeInstPeriod, gem5::PerfKvmCounterConfig::exclude_host(), gem5::PerfKvmCounterConfig::exclude_hv(), hwCycles, hwInstructions, KVM_KICK_SIGNAL, gem5::PerfKvmCounterConfig::samplePeriod(), usePerf, and gem5::PerfKvmCounterConfig::wakeupEvents().

Referenced by setupCounters(), and setupInstStop().

◆ setupInstStop()

void gem5::BaseKvmCPU::setupInstStop ( )
private

Setup an instruction break if there is one pending.

Check if there are pending instruction breaks in the CPU's instruction event queue and schedule an instruction break using PerfEvent.

Note
This method doesn't currently handle the main system instruction event queue.

Definition at line 1365 of file base.cc.

References gem5::SimpleThread::comInstEventQueue, ctrInsts, gem5::EventQueue::empty(), gem5::EventQueue::nextTick(), setupInstCounter(), and thread.

Referenced by tick().

◆ setupSignalHandler()

void gem5::BaseKvmCPU::setupSignalHandler ( )
private

Setup a signal handler to catch the timer signal used to switch back to the monitor.

Definition at line 1239 of file base.cc.

References KVM_KICK_SIGNAL, gem5::onKickSignal(), panic, gem5::ArmISA::sa, and setSignalMask().

Referenced by restartEqThread().

◆ startup()

void gem5::BaseKvmCPU::startup ( )
overridevirtual

startup() is the final initialization call before simulation.

All state is initialized (including unserialized state, if any, such as the curTick() value), so this is the appropriate place to schedule initial event(s) for objects that need them.

Reimplemented from gem5::BaseCPU.

Reimplemented in gem5::X86KvmCPU.

Definition at line 137 of file base.cc.

References _kvmRun, gem5::Kvm::capCoalescedMMIO(), gem5::KvmVM::cpuStartup(), gem5::KvmVM::createVCPU(), gem5::curTick(), gem5::Kvm::getVCPUMMapSize(), inform, gem5::KvmVM::kvm, mmioRing, gem5::Named::name(), gem5::MipsISA::p, pageSize, panic, gem5::SimObject::params(), restartEqThread(), gem5::EventManager::schedule(), gem5::BaseCPU::startup(), vcpuFD, vcpuID, vcpuMMapSize, and vm.

Referenced by gem5::ArmKvmCPU::startup(), gem5::BaseArmKvmCPU::startup(), and gem5::X86KvmCPU::startup().

◆ stutterPC()

virtual void gem5::BaseKvmCPU::stutterPC ( PCStateBase & pc) const
protectedpure virtual

Modify a PCStatePtr's value so that its next PC is the current PC.

This needs to be implemented in KVM base classes since modifying the next PC value is an ISA specific operation. This is only used in doMMIOAccess, for reasons explained in a comment there.

Implemented in gem5::ArmKvmCPU, gem5::BaseArmKvmCPU, and gem5::X86KvmCPU.

Referenced by doMMIOAccess().

◆ suspendContext()

void gem5::BaseKvmCPU::suspendContext ( ThreadID thread_num)
overridevirtual

Notify the CPU that the indicated context is now suspended.

Check if possible to enter a lower power state

Reimplemented from gem5::BaseCPU.

Definition at line 536 of file base.cc.

References _status, gem5::EventManager::deschedule(), DPRINTF, Idle, Running, RunningServiceCompletion, gem5::Event::scheduled(), thread, and tickEvent.

Referenced by deallocateContext(), and haltContext().

◆ switchOut()

void gem5::BaseKvmCPU::switchOut ( )
overridevirtual

Prepare for another CPU to take over execution.

When this method exits, all internal state should have been flushed. After the method returns, the simulator calls takeOverFrom() on the new CPU with this CPU as its parameter.

Reimplemented from gem5::BaseCPU.

Definition at line 454 of file base.cc.

References _status, DPRINTF, Idle, gem5::Event::scheduled(), gem5::BaseCPU::switchOut(), and tickEvent.

◆ syncKvmState()

void gem5::BaseKvmCPU::syncKvmState ( )
protected

Update the KVM if the thread context is dirty.

Definition at line 978 of file base.cc.

References kvmStateDirty, threadContextDirty, and updateKvmState().

Referenced by tick().

◆ syncThreadContext()

void gem5::BaseKvmCPU::syncThreadContext ( )
protected

Update a thread context if the KVM state is dirty with respect to the cached thread context.

Definition at line 966 of file base.cc.

References kvmStateDirty, threadContextDirty, and updateThreadContext().

Referenced by gem5::X86KvmCPU::deliverInterrupts(), doMMIOAccess(), drain(), getContext(), gem5::X86KvmCPU::kvmRun(), and tick().

◆ takeOverFrom()

void gem5::BaseKvmCPU::takeOverFrom ( BaseCPU * cpu)
overridevirtual

Load the state of a CPU from the previous CPU object, invoked on all new CPUs that are about to be switched in.

A CPU model implementing this method is expected to initialize its state from the old CPU and connect its memory (unless they are already connected) to the memories connected to the old CPU.

Parameters
cpuCPU to initialize read state from.

Reimplemented from gem5::BaseCPU.

Definition at line 468 of file base.cc.

References _status, DPRINTF, Idle, gem5::Event::scheduled(), gem5::BaseCPU::takeOverFrom(), threadContextDirty, gem5::BaseCPU::threadContexts, tickEvent, and updateKvmState().

◆ tick()

◆ totalInsts()

Counter gem5::BaseKvmCPU::totalInsts ( ) const
overridevirtual

Implements gem5::BaseCPU.

Definition at line 583 of file base.cc.

References ctrInsts.

◆ totalOps()

Counter gem5::BaseKvmCPU::totalOps ( ) const
overridevirtual

Implements gem5::BaseCPU.

Definition at line 589 of file base.cc.

References ctrInsts, and hack_once.

◆ tryDrain()

bool gem5::BaseKvmCPU::tryDrain ( )
private

Try to drain the CPU if a drain is pending.

Definition at line 1333 of file base.cc.

References _status, archIsDrained(), DPRINTF, gem5::Draining, gem5::Drainable::drainState(), Idle, Running, and gem5::Drainable::signalDrainDone().

Referenced by tick().

◆ unserializeThread()

void gem5::BaseKvmCPU::unserializeThread ( CheckpointIn & cp,
ThreadID tid )
overridevirtual

Unserialize one thread.

Parameters
cpThe checkpoint use.
tidID of the current thread.

Reimplemented from gem5::BaseCPU.

Definition at line 317 of file base.cc.

References _status, DPRINTF, Idle, thread, threadContextDirty, and gem5::SimpleThread::unserialize().

◆ updateKvmState()

virtual void gem5::BaseKvmCPU::updateKvmState ( )
protectedpure virtual

Update the KVM state from the current thread context.

The base CPU calls this method before starting the guest CPU when the contextDirty flag is set. The architecture dependent CPU implementation is expected to update all guest state (registers, special registers, and FPU state).

Implemented in gem5::ArmKvmCPU, gem5::ArmV8KvmCPU, and gem5::X86KvmCPU.

Referenced by syncKvmState(), and takeOverFrom().

◆ updateThreadContext()

virtual void gem5::BaseKvmCPU::updateThreadContext ( )
protectedpure virtual

Update the current thread context with the KVM state.

The base CPU after the guest updates any of the KVM state. In practice, this happens after kvmRun is called. The architecture dependent code is expected to read the state of the guest CPU and update gem5's thread state.

Implemented in gem5::ArmKvmCPU, gem5::ArmV8KvmCPU, and gem5::X86KvmCPU.

Referenced by syncThreadContext().

◆ verifyMemoryMode()

void gem5::BaseKvmCPU::verifyMemoryMode ( ) const
overridevirtual

Verify that the system is in a memory mode supported by the CPU.

Implementations are expected to query the system for the current memory mode and ensure that it is what the CPU model expects. If the check fails, the implementation should terminate the simulation using fatal().

Reimplemented from gem5::BaseCPU.

Definition at line 490 of file base.cc.

References gem5::System::bypassCaches(), fatal, and gem5::BaseCPU::system.

Referenced by drainResume().

◆ wakeup()

void gem5::BaseKvmCPU::wakeup ( ThreadID tid = 0)
overridevirtual

Member Data Documentation

◆ _kvmRun

struct kvm_run* gem5::BaseKvmCPU::_kvmRun
private

Pointer to the kvm_run structure used to communicate parameters with KVM.

Note
This is the base pointer of the MMAPed KVM region. The first page contains the kvm_run structure. Subsequent pages may contain other data such as the MMIO ring buffer.

Definition at line 719 of file base.hh.

Referenced by getGuestData(), getKvmRunState(), handleKvmExit(), handleKvmExitException(), handleKvmExitFailEntry(), handleKvmExitIO(), handleKvmExitUnknown(), notifyFork(), startup(), tick(), and ~BaseKvmCPU().

◆ _status

◆ activeInstPeriod

uint64_t gem5::BaseKvmCPU::activeInstPeriod
private

Currently active instruction count breakpoint.

Definition at line 759 of file base.hh.

Referenced by setupInstCounter().

◆ alwaysSyncTC

const bool gem5::BaseKvmCPU::alwaysSyncTC
protected

Be conservative and always synchronize the thread context on KVM entry/exit.

Definition at line 642 of file base.hh.

Referenced by tick().

◆ ctrInsts

Counter gem5::BaseKvmCPU::ctrInsts

Number of instructions executed by the CPU.

Definition at line 823 of file base.hh.

Referenced by kvmRun(), setupInstStop(), tick(), totalInsts(), and totalOps().

◆ dataPort

KVMCpuPort gem5::BaseKvmCPU::dataPort
protected

Port for data requests.

Definition at line 633 of file base.hh.

Referenced by doMMIOAccess(), getDataPort(), handleKvmExit(), and gem5::X86KvmCPU::handleKvmExitIO().

◆ hostFactor

float gem5::BaseKvmCPU::hostFactor
private

Host factor as specified in the configuration.

Definition at line 803 of file base.hh.

Referenced by kvmRun().

◆ hwCycles

std::unique_ptr<PerfKvmCounter> gem5::BaseKvmCPU::hwCycles
private

Guest cycle counter.

This is the group leader of all performance counters measuring the guest system. It can be used in conjunction with the PerfKvmTimer (see perfControlledByTimer) to trigger exits from KVM.

Definition at line 769 of file base.hh.

Referenced by getHostCycles(), kvmRun(), notifyFork(), restartEqThread(), setupCounters(), and setupInstCounter().

◆ hwInstructions

std::unique_ptr<PerfKvmCounter> gem5::BaseKvmCPU::hwInstructions
private

Guest instruction counter.

This counter is typically only used to measure the number of instructions executed by the guest. However, it can also be used to trigger exits from KVM if the configuration script requests an exit after a certain number of instructions.

See also
setupInstBreak
scheduleInstStop

Definition at line 782 of file base.hh.

Referenced by kvmRun(), notifyFork(), and setupInstCounter().

◆ instPort

KVMCpuPort gem5::BaseKvmCPU::instPort
protected

Unused dummy port for the instruction interface.

Definition at line 636 of file base.hh.

Referenced by getInstPort().

◆ kvmStateDirty

bool gem5::BaseKvmCPU::kvmStateDirty
protected

Is the KVM state dirty? Set to true to force an update of the KVM vCPU state upon the next call to kvmRun().

Definition at line 654 of file base.hh.

Referenced by syncKvmState(), syncThreadContext(), and tick().

◆ mmioRing

struct kvm_coalesced_mmio_ring* gem5::BaseKvmCPU::mmioRing
private

Coalesced MMIO ring buffer.

NULL if coalesced MMIO is not supported.

Definition at line 724 of file base.hh.

Referenced by flushCoalescedMMIO(), and startup().

◆ pageSize

const long gem5::BaseKvmCPU::pageSize
private

Cached page size of the host.

Definition at line 726 of file base.hh.

Referenced by startup().

◆ perfControlledByTimer

bool gem5::BaseKvmCPU::perfControlledByTimer
private

Does the runTimer control the performance counters?

The run timer will automatically enable and disable performance counters if a PerfEvent-based timer is used to control KVM exits.

Definition at line 791 of file base.hh.

Referenced by kvmRun(), and setupCounters().

◆ runTimer

std::unique_ptr<BaseKvmTimer> gem5::BaseKvmCPU::runTimer
private

Timer used to force execution into the monitor after a specified number of simulation tick equivalents have executed in the guest.

This counter generates the signal specified by KVM_TIMER_SIGNAL.

Definition at line 800 of file base.hh.

Referenced by kvmRun(), restartEqThread(), and tick().

◆ stats

◆ tc

◆ thread

SimpleThread* gem5::BaseKvmCPU::thread

A cached copy of a thread's state in the form of a SimpleThread object.

Normally the actual thread state is stored in the KVM vCPU. If KVM has been running this copy is will be out of date. If we recently handled some events within gem5 that required state to be updated this could be the most up-to-date copy. When getContext() or updateThreadContext() is called this copy gets updated. The method syncThreadContext can be used within a KVM CPU to update the thread context if the KVM state is dirty (i.e., the vCPU has been run since the last update).

Definition at line 153 of file base.hh.

Referenced by activateContext(), gem5::X86KvmCPU::deliverInterrupts(), doMMIOAccess(), handleKvmExit(), kvmRun(), serializeThread(), setupInstStop(), suspendContext(), tick(), unserializeThread(), and wakeup().

◆ threadContextDirty

bool gem5::BaseKvmCPU::threadContextDirty
protected

Is the gem5 context dirty? Set to true to force an update of the KVM vCPU state upon the next call to kvmRun().

Definition at line 648 of file base.hh.

Referenced by gem5::X86KvmCPU::deliverInterrupts(), doMMIOAccess(), syncKvmState(), syncThreadContext(), takeOverFrom(), tick(), and unserializeThread().

◆ tickEvent

EventFunctionWrapper gem5::BaseKvmCPU::tickEvent
private

◆ usePerf

bool gem5::BaseKvmCPU::usePerf
protected

True if using perf; False otherwise.

Definition at line 657 of file base.hh.

Referenced by getHostCycles(), kvmRun(), notifyFork(), setupCounters(), and setupInstCounter().

◆ vcpuFD

int gem5::BaseKvmCPU::vcpuFD
private

KVM vCPU file descriptor.

Definition at line 708 of file base.hh.

Referenced by ioctl(), kvmRun(), notifyFork(), startup(), and ~BaseKvmCPU().

◆ vcpuID

long gem5::BaseKvmCPU::vcpuID
protected

KVM internal ID of the vCPU.

Definition at line 660 of file base.hh.

Referenced by getVCpuID(), init(), gem5::ArmKvmCPU::kvmRun(), gem5::BaseArmKvmCPU::kvmRun(), and startup().

◆ vcpuMMapSize

int gem5::BaseKvmCPU::vcpuMMapSize
private

Size of MMAPed kvm_run area.

Definition at line 710 of file base.hh.

Referenced by notifyFork(), startup(), and ~BaseKvmCPU().

◆ vcpuThread

pthread_t gem5::BaseKvmCPU::vcpuThread
protected

ID of the vCPU thread.

Definition at line 663 of file base.hh.

Referenced by kick(), and restartEqThread().

◆ vm


The documentation for this class was generated from the following files:

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