gem5
|
Base class for KVM based CPU models. More...
#include <base.hh>
Classes | |
class | KVMCpuPort |
KVM memory port. More... | |
struct | TickEvent |
Public Member Functions | |
BaseKvmCPU (BaseKvmCPUParams *params) | |
virtual | ~BaseKvmCPU () |
void | init () override |
void | startup () override |
void | regStats () override |
void | serializeThread (CheckpointOut &cp, ThreadID tid) const override |
void | unserializeThread (CheckpointIn &cp, ThreadID tid) override |
DrainState | drain () override |
void | drainResume () override |
void | notifyFork () override |
void | switchOut () override |
void | takeOverFrom (BaseCPU *cpu) override |
void | verifyMemoryMode () const override |
MasterPort & | getDataPort () override |
MasterPort & | getInstPort () override |
void | wakeup (ThreadID tid=0) override |
void | activateContext (ThreadID thread_num) override |
void | suspendContext (ThreadID thread_num) override |
void | deallocateContext (ThreadID thread_num) |
void | haltContext (ThreadID thread_num) override |
long | getVCpuID () const |
ThreadContext * | getContext (int tn) override |
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. More... | |
virtual void | dump () const |
Dump the internal state to the terminal. More... | |
void | kick () const |
Force an exit from KVM. More... | |
Public Attributes | |
SimpleThread * | thread |
A cached copy of a thread's state in the form of a SimpleThread object. More... | |
ThreadContext * | tc |
ThreadContext object, provides an interface for external objects to modify this thread's state. More... | |
KvmVM & | vm |
Counter | ctrInsts |
Number of instructions executed by the CPU. More... | |
Stats::Scalar | numInsts |
Stats::Scalar | numVMExits |
Stats::Scalar | numVMHalfEntries |
Stats::Scalar | numExitSignal |
Stats::Scalar | numMMIO |
Stats::Scalar | numCoalescedMMIO |
Stats::Scalar | numIO |
Stats::Scalar | numHalt |
Stats::Scalar | numInterrupts |
Stats::Scalar | numHypercalls |
Protected Types | |
enum | Status { Idle, Running, RunningService, RunningMMIOPending, RunningServiceCompletion } |
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. More... | |
virtual uint64_t | getHostCycles () const |
Get the value of the hardware cycle counter in the guest. More... | |
virtual Tick | kvmRun (Tick ticks) |
Request KVM to run the guest for a given number of ticks. More... | |
virtual Tick | kvmRunDrain () |
Request the CPU to run until draining completes. More... | |
struct kvm_run * | getKvmRunState () |
Get a pointer to the kvm_run structure containing all the input and output parameters from kvmRun(). More... | |
uint8_t * | getGuestData (uint64_t offset) const |
Retrieve a pointer to guest data stored at the end of the kvm_run structure. More... | |
void | kvmNonMaskableInterrupt () |
Send a non-maskable interrupt to the guest. More... | |
void | kvmInterrupt (const struct kvm_interrupt &interrupt) |
Send a normal interrupt to the guest. More... | |
std::string | getAndFormatOneReg (uint64_t id) const |
Get and format one register for printout. More... | |
virtual bool | archIsDrained () const |
Is the architecture specific code in a state that prevents draining? More... | |
Tick | doMMIOAccess (Addr paddr, void *data, int size, bool write) |
Inject a memory mapped IO request into gem5. More... | |
int | ioctl (int request, long p1) const |
vCPU ioctl interface. More... | |
int | ioctl (int request, void *p1) const |
int | ioctl (int request) const |
void | getRegisters (struct kvm_regs ®s) const |
Get/Set the register state of the guest vCPU. More... | |
void | setRegisters (const struct kvm_regs ®s) |
void | getSpecialRegisters (struct kvm_sregs ®s) const |
void | setSpecialRegisters (const struct kvm_sregs ®s) |
void | getFPUState (struct kvm_fpu &state) const |
Get/Set the guest FPU/vector state. More... | |
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. More... | |
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. More... | |
virtual void | updateThreadContext ()=0 |
Update the current thread context with the KVM state. More... | |
void | syncThreadContext () |
Update a thread context if the KVM state is dirty with respect to the cached thread context. More... | |
void | syncKvmState () |
Update the KVM if the thread context is dirty. More... | |
virtual Tick | handleKvmExit () |
Main kvmRun exit handler, calls the relevant handleKvmExit* depending on exit type. More... | |
virtual Tick | handleKvmExitIO () |
The guest performed a legacy IO request (out/inp on x86) More... | |
virtual Tick | handleKvmExitHypercall () |
The guest requested a monitor service using a hypercall. More... | |
virtual Tick | handleKvmExitIRQWindowOpen () |
The guest exited because an interrupt window was requested. More... | |
virtual Tick | handleKvmExitUnknown () |
An unknown architecture dependent error occurred when starting the vCPU. More... | |
virtual Tick | handleKvmExitException () |
An unhandled virtualization exception occured. More... | |
virtual Tick | handleKvmExitFailEntry () |
KVM failed to start the virtualized CPU. More... | |
void | setSignalMask (const sigset_t *mask) |
Set the signal mask used in kvmRun() More... | |
Protected Attributes | |
Status | _status |
CPU run state. More... | |
KVMCpuPort | dataPort |
Port for data requests. More... | |
KVMCpuPort | instPort |
Unused dummy port for the instruction interface. More... | |
const bool | alwaysSyncTC |
Be conservative and always synchronize the thread context on KVM entry/exit. More... | |
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(). More... | |
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(). More... | |
const long | vcpuID |
KVM internal ID of the vCPU. More... | |
pthread_t | vcpuThread |
ID of the vCPU thread. More... | |
Private Member Functions | |
Tick | flushCoalescedMMIO () |
Service MMIO requests in the mmioRing. More... | |
void | setupSignalHandler () |
Setup a signal handler to catch the timer signal used to switch back to the monitor. More... | |
bool | discardPendingSignal (int signum) const |
Discard a (potentially) pending signal. More... | |
void | startupThread () |
Thread-specific initialization. More... | |
bool | tryDrain () |
Try to drain the CPU if a drain is pending. More... | |
void | ioctlRun () |
Execute the KVM_RUN ioctl. More... | |
void | setupInstStop () |
Setup an instruction break if there is one pending. More... | |
Private Attributes | |
int | vcpuFD |
KVM vCPU file descriptor. More... | |
int | vcpuMMapSize |
Size of MMAPed kvm_run area. More... | |
struct kvm_run * | _kvmRun |
Pointer to the kvm_run structure used to communicate parameters with KVM. More... | |
struct kvm_coalesced_mmio_ring * | mmioRing |
Coalesced MMIO ring buffer. More... | |
const long | pageSize |
Cached page size of the host. More... | |
TickEvent | tickEvent |
std::unique_ptr< BaseKvmTimer > | runTimer |
Timer used to force execution into the monitor after a specified number of simulation tick equivalents have executed in the guest. More... | |
float | hostFactor |
Host factor as specified in the configuration. More... | |
uint64_t | activeInstPeriod |
Currently active instruction count breakpoint. More... | |
PerfKvmCounter | hwCycles |
Guest cycle counter. More... | |
PerfKvmCounter | hwInstructions |
Guest instruction counter. More... | |
bool | perfControlledByTimer |
Does the runTimer control the performance counters? More... | |
void | setupCounters () |
Setup hardware performance counters. More... | |
void | setupInstCounter (uint64_t period=0) |
Setup the guest instruction counter. More... | |
Additional Inherited Members | |
Static Public Member Functions inherited from BaseCPU | |
static int | numSimulatedInsts () |
static int | numSimulatedOps () |
static void | wakeup (ThreadID tid) |
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.
|
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.
|
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:
|
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. |
BaseKvmCPU::BaseKvmCPU | ( | BaseKvmCPUParams * | params | ) |
Definition at line 65 of file base.cc.
References FullSystem, SimpleThread::getTC(), ThreadContext::Halted, pageSize, panic, SimpleThread::setStatus(), tc, and thread.
|
virtual |
Definition at line 100 of file base.cc.
References _kvmRun, vcpuFD, and vcpuMMapSize.
|
override |
Definition at line 528 of file base.cc.
References _status, DPRINTF, Idle, ThreadState::lastActivate, ThreadState::lastSuspend, Running, Event::scheduled(), thread, and tickEvent.
|
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().
Reimplemented in X86KvmCPU.
Definition at line 513 of file base.hh.
Referenced by drain(), and tryDrain().
void BaseKvmCPU::deallocateContext | ( | ThreadID | thread_num | ) |
Definition at line 569 of file base.cc.
References suspendContext().
|
private |
Inject a memory mapped IO request into gem5.
paddr | Physical address |
data | Pointer to the source/destination buffer |
size | Memory access size |
write | True if write, False if read |
Definition at line 1109 of file base.cc.
References ThreadContext::contextId(), dataPort, Packet::dataStatic(), EventManager::eventQueue(), ThreadContext::getDTBPtr(), SimpleThread::getTC(), GenericISA::handleIprRead(), GenericISA::handleIprWrite(), Request::isMmappedIpr(), NoFault, BaseTLB::Read, MemCmd::ReadReq, Packet::req, Request::setContext(), BaseKvmCPU::KVMCpuPort::submitIO(), syncThreadContext(), tc, thread, threadContextDirty, Request::UNCACHEABLE, vm, warn, BaseTLB::Write, and MemCmd::WriteReq.
Referenced by flushCoalescedMMIO(), and handleKvmExit().
|
override |
FALLTHROUGH
Definition at line 355 of file base.cc.
References _status, archIsDrained(), DPRINTF, Drained, Draining, Idle, panic, Running, RunningMMIOPending, RunningService, RunningServiceCompletion, Event::scheduled(), syncThreadContext(), and tickEvent.
|
override |
Definition at line 419 of file base.cc.
References _status, ThreadContext::Active, DPRINTF, Idle, Running, Event::scheduled(), ThreadContext::status(), tc, tickEvent, and verifyMemoryMode().
|
virtual |
Dump the internal state to the terminal.
Reimplemented in ArmV8KvmCPU, and X86KvmCPU.
Definition at line 605 of file base.cc.
References inform.
Referenced by handleKvmExit(), handleKvmExitException(), handleKvmExitFailEntry(), handleKvmExitUnknown(), and serializeThread().
void BaseKvmCPU::finishMMIOPending | ( | ) |
Callback from KvmCPUPort to transition the CPU out of RunningMMIOPending when all timing requests have completed.
Definition at line 233 of file base.cc.
References _status, RunningMMIOPending, RunningServiceCompletion, Event::scheduled(), and tickEvent.
|
private |
Service MMIO requests in the mmioRing.
Definition at line 1183 of file base.cc.
References doMMIOAccess(), DPRINTF, mmioRing, and numCoalescedMMIO.
Referenced by kvmRun().
|
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.
Definition at line 914 of file base.cc.
References panic, and ArmISA::ss.
Referenced by ArmV8KvmCPU::dump(), ArmKvmCPU::dumpKvmStateCoProc(), ArmKvmCPU::dumpKvmStateMisc(), ArmKvmCPU::dumpKvmStateVFP(), ArmV8KvmCPU::updateKvmState(), and ArmV8KvmCPU::updateThreadContext().
|
override |
Definition at line 583 of file base.cc.
References syncThreadContext(), and tc.
Referenced by ArmKvmCPU::onKvmExitHypercall().
|
inlineoverride |
|
protected |
Get/Set the guest FPU/vector state.
Definition at line 865 of file base.cc.
References ioctl(), and panic.
Referenced by X86KvmCPU::dumpFpuRegs(), and X86KvmCPU::updateThreadContext().
|
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).
offset | Offset as specified by the kvm_run structure |
Definition at line 309 of file base.hh.
References _kvmRun, and ArmISA::offset.
Referenced by X86KvmCPU::handleIOMiscReg32(), and X86KvmCPU::handleKvmExitIO().
|
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.
Reimplemented in X86KvmCPU.
Definition at line 717 of file base.cc.
References hwCycles, and PerfKvmCounter::read().
Referenced by kvmRun().
|
inlineoverride |
|
inlineprotected |
Get a pointer to the kvm_run structure containing all the input and output parameters from kvmRun().
Definition at line 299 of file base.hh.
References _kvmRun.
Referenced by X86KvmCPU::handleIOMiscReg32(), X86KvmCPU::handleKvmExitIO(), X86KvmCPU::kvmRun(), X86KvmCPU::kvmRunDrain(), X86KvmCPU::kvmRunWrapper(), and X86KvmCPU::updateThreadContextSRegs().
|
protected |
Definition at line 897 of file base.cc.
References SparcISA::id, ioctl(), and panic.
Referenced by getOneRegU32(), getOneRegU64(), and ArmV8KvmCPU::updateThreadContext().
|
inlineprotected |
Definition at line 377 of file base.hh.
References getOneReg().
Referenced by ArmKvmCPU::dumpKvmStateCoProc(), ArmKvmCPU::dumpKvmStateCore(), ArmKvmCPU::updateTCStateCoProc(), and ArmKvmCPU::updateTCStateCore().
|
inlineprotected |
Definition at line 372 of file base.hh.
References getOneReg().
Referenced by ArmKvmCPU::updateTCStateCoProc(), ArmKvmCPU::updateTCStateVFP(), and ArmV8KvmCPU::updateThreadContext().
|
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 837 of file base.cc.
References ioctl(), and panic.
Referenced by X86KvmCPU::dumpIntRegs(), and X86KvmCPU::updateThreadContext().
|
protected |
Definition at line 851 of file base.cc.
References ioctl(), and panic.
Referenced by X86KvmCPU::dumpSpecRegs(), and X86KvmCPU::updateThreadContext().
|
inline |
|
override |
Definition at line 576 of file base.cc.
References suspendContext().
|
protectedvirtual |
Main kvmRun exit handler, calls the relevant handleKvmExit* depending on exit type.
Definition at line 985 of file base.cc.
References _kvmRun, _status, dataPort, doMMIOAccess(), DPRINTF, dump(), handleKvmExitException(), handleKvmExitFailEntry(), handleKvmExitHypercall(), handleKvmExitIO(), handleKvmExitIRQWindowOpen(), handleKvmExitUnknown(), Idle, BaseKvmCPU::KVMCpuPort::nextIOState(), numHalt, numHypercalls, numIO, numMMIO, panic, Running, RunningService, SimpleThread::suspend(), and thread.
Referenced by tick().
|
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.
Definition at line 1092 of file base.cc.
References _kvmRun, dump(), and panic.
Referenced by handleKvmExit().
|
protectedvirtual |
|
protectedvirtual |
The guest requested a monitor service using a hypercall.
Definition at line 1070 of file base.cc.
References panic.
Referenced by handleKvmExit().
|
protectedvirtual |
|
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
Reimplemented in X86KvmCPU.
Definition at line 1076 of file base.cc.
References warn.
Referenced by handleKvmExit().
|
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.
Definition at line 1084 of file base.cc.
References _kvmRun, dump(), and panic.
Referenced by handleKvmExit().
|
override |
Definition at line 108 of file base.cc.
References ThreadContext::contextId(), fatal, FullSystem, Stats::init, AlphaISA::initCPU(), ThreadContext::initMemProxies(), and tc.
|
private |
|
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 130 of file base.hh.
References KVM_KICK_SIGNAL, and vcpuThread.
Request KVM to run the guest for a given number of ticks.
The method returns the approximate number of ticks executed.
ticks | Number of ticks to execute, set to 0 to exit immediately after finishing pending operations. |
Reimplemented in ArmKvmCPU, X86KvmCPU, and BaseArmKvmCPU.
Definition at line 723 of file base.cc.
References ctrInsts, curEventQueue(), discardPendingSignal(), DPRINTF, fatal_if(), flushCoalescedMMIO(), getHostCycles(), hostFactor, hwCycles, hwInstructions, ioctlRun(), kick(), KVM_KICK_SIGNAL, numInsts, numVMExits, numVMHalfEntries, perfControlledByTimer, PerfKvmCounter::read(), runTimer, PerfKvmCounter::start(), PerfKvmCounter::stop(), ArmISA::system, and vcpuFD.
Referenced by BaseArmKvmCPU::kvmRun(), ArmKvmCPU::kvmRun(), kvmRunDrain(), X86KvmCPU::kvmRunWrapper(), and tick().
|
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.
Reimplemented in X86KvmCPU.
Definition at line 703 of file base.cc.
References _status, kvmRun(), RunningMMIOPending, and RunningServiceCompletion.
Referenced by tick().
|
override |
Definition at line 442 of file base.cc.
References _kvmRun, _status, PerfKvmCounter::detach(), hwCycles, hwInstructions, Idle, Event::scheduled(), tickEvent, vcpuFD, vcpuMMapSize, and warn.
|
override |
Definition at line 273 of file base.cc.
References Stats::DataWrap< Derived, InfoProxyType >::desc(), name(), Stats::DataWrap< Derived, InfoProxyType >::name(), numCoalescedMMIO, numExitSignal, numHalt, numHypercalls, numInsts, numInterrupts, numIO, numMMIO, numVMExits, and numVMHalfEntries.
|
override |
|
protected |
Definition at line 872 of file base.cc.
References ioctl(), and panic.
Referenced by X86KvmCPU::updateKvmStateFPULegacy().
|
protected |
Get/Set single register using the KVM_(SET|GET)_ONE_REG API.
Definition at line 880 of file base.cc.
References SparcISA::id, ioctl(), and panic.
Referenced by ArmKvmCPU::onKvmExitHypercall(), ArmV8KvmCPU::startup(), ArmV8KvmCPU::updateKvmState(), ArmKvmCPU::updateKvmStateCoProc(), ArmKvmCPU::updateKvmStateCore(), and ArmKvmCPU::updateKvmStateVFP().
|
inlineprotected |
|
inlineprotected |
|
protected |
Definition at line 844 of file base.cc.
References ioctl(), and panic.
Referenced by X86KvmCPU::updateKvmStateRegs().
|
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.
mask | Signals to mask |
Definition at line 1153 of file base.cc.
References ioctl(), and panic.
Referenced by setupSignalHandler().
|
protected |
Definition at line 858 of file base.cc.
References ioctl(), and panic.
Referenced by X86KvmCPU::updateKvmStateSRegs().
|
private |
Setup hardware performance counters.
Definition at line 1282 of file base.cc.
References PerfKvmCounter::attach(), PerfKvmCounterConfig::disabled(), DPRINTF, PerfKvmCounterConfig::exclude_host(), PerfKvmCounterConfig::exclude_hv(), hwCycles, perfControlledByTimer, PerfKvmCounterConfig::pinned(), PerfKvmCounterConfig::samplePeriod(), setupInstCounter(), and PerfKvmCounterConfig::wakeupEvents().
Referenced by startupThread().
|
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.
period | Signal period, set to 0 to disable signaling. |
Definition at line 1358 of file base.cc.
References activeInstPeriod, PerfKvmCounter::attach(), PerfKvmCounter::attached(), PerfKvmCounter::detach(), PerfKvmCounter::enableSignals(), PerfKvmCounterConfig::exclude_host(), PerfKvmCounterConfig::exclude_hv(), hwCycles, hwInstructions, KVM_KICK_SIGNAL, PerfKvmCounterConfig::samplePeriod(), and PerfKvmCounterConfig::wakeupEvents().
Referenced by setupCounters(), and 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.
Definition at line 1345 of file base.cc.
References ctrInsts, and setupInstCounter().
Referenced by tick().
|
private |
Setup a signal handler to catch the timer signal used to switch back to the monitor.
Definition at line 1225 of file base.cc.
References KVM_KICK_SIGNAL, onKickSignal(), panic, and setSignalMask().
Referenced by startupThread().
|
override |
Definition at line 123 of file base.cc.
References _kvmRun, Kvm::capCoalescedMMIO(), KvmVM::cpuStartup(), KvmVM::createVCPU(), curTick(), Kvm::getVCPUMMapSize(), inform, KvmVM::kvm, mmioRing, MipsISA::p, pageSize, panic, SimpleThread::startup(), startupThread(), thread, vcpuFD, vcpuID, vcpuMMapSize, and vm.
Referenced by X86KvmCPU::startup(), BaseArmKvmCPU::startup(), and ArmKvmCPU::startup().
|
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.
Definition at line 243 of file base.cc.
References hwCycles, KVM_KICK_SIGNAL, MipsISA::p, runTimer, setupCounters(), setupSignalHandler(), and vcpuThread.
Referenced by startup().
|
override |
Definition at line 546 of file base.cc.
References _status, DPRINTF, Idle, Running, RunningServiceCompletion, Event::scheduled(), thread, and tickEvent.
Referenced by deallocateContext(), and haltContext().
|
override |
|
protected |
Update the KVM if the thread context is dirty.
Definition at line 973 of file base.cc.
References kvmStateDirty, threadContextDirty, and updateKvmState().
Referenced by tick().
|
protected |
Update a thread context if the KVM state is dirty with respect to the cached thread context.
Definition at line 961 of file base.cc.
References kvmStateDirty, threadContextDirty, and updateThreadContext().
Referenced by X86KvmCPU::deliverInterrupts(), doMMIOAccess(), drain(), getContext(), X86KvmCPU::kvmRun(), and tick().
|
override |
Definition at line 479 of file base.cc.
References _status, DPRINTF, Idle, Event::scheduled(), takeOverFrom(), threadContextDirty, tickEvent, and updateKvmState().
|
protected |
Execute the CPU until the next event in the main event queue or until the guest needs service from gem5.
Definition at line 611 of file base.cc.
References _kvmRun, _status, alwaysSyncTC, ctrInsts, curEventQueue(), curTick(), DPRINTF, Draining, handleKvmExit(), Idle, kvmRun(), kvmRunDrain(), kvmStateDirty, numExitSignal, panic, Running, RunningMMIOPending, RunningService, RunningServiceCompletion, setupInstStop(), syncKvmState(), syncThreadContext(), ArmISA::system, threadContextDirty, tickEvent, and tryDrain().
|
override |
|
override |
|
private |
|
override |
Definition at line 344 of file base.cc.
References _status, DPRINTF, Idle, thread, threadContextDirty, and SimpleThread::unserialize().
|
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 X86KvmCPU, ArmKvmCPU, and ArmV8KvmCPU.
Referenced by syncKvmState(), and takeOverFrom().
|
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 X86KvmCPU, ArmKvmCPU, and ArmV8KvmCPU.
Referenced by syncThreadContext().
|
override |
Definition at line 501 of file base.cc.
References fatal, and ArmISA::system.
Referenced by drainResume().
|
override |
Definition at line 510 of file base.cc.
References SimpleThread::activate(), DPRINTF, kick(), SimpleThread::status(), ThreadContext::Suspended, and thread.
|
private |
Pointer to the kvm_run structure used to communicate parameters with KVM.
Definition at line 702 of file base.hh.
Referenced by getGuestData(), getKvmRunState(), handleKvmExit(), handleKvmExitException(), handleKvmExitFailEntry(), handleKvmExitIO(), handleKvmExitUnknown(), notifyFork(), startup(), tick(), and ~BaseKvmCPU().
|
protected |
CPU run state.
Definition at line 231 of file base.hh.
Referenced by activateContext(), drain(), drainResume(), finishMMIOPending(), handleKvmExit(), X86KvmCPU::kvmRun(), kvmRunDrain(), notifyFork(), serializeThread(), suspendContext(), switchOut(), takeOverFrom(), tick(), tryDrain(), and unserializeThread().
|
private |
Currently active instruction count breakpoint.
Definition at line 742 of file base.hh.
Referenced by setupInstCounter().
|
protected |
Counter BaseKvmCPU::ctrInsts |
Number of instructions executed by the CPU.
Definition at line 803 of file base.hh.
Referenced by kvmRun(), setupInstStop(), tick(), totalInsts(), and totalOps().
|
protected |
Port for data requests.
Definition at line 603 of file base.hh.
Referenced by doMMIOAccess(), getDataPort(), handleKvmExit(), and X86KvmCPU::handleKvmExitIO().
|
private |
|
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 752 of file base.hh.
Referenced by getHostCycles(), kvmRun(), notifyFork(), setupCounters(), setupInstCounter(), and startupThread().
|
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.
Definition at line 765 of file base.hh.
Referenced by kvmRun(), notifyFork(), and setupInstCounter().
|
protected |
Unused dummy port for the instruction interface.
Definition at line 606 of file base.hh.
Referenced by getInstPort().
|
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 624 of file base.hh.
Referenced by syncKvmState(), syncThreadContext(), and tick().
|
private |
Coalesced MMIO ring buffer.
NULL if coalesced MMIO is not supported.
Definition at line 707 of file base.hh.
Referenced by flushCoalescedMMIO(), and startup().
Stats::Scalar BaseKvmCPU::numCoalescedMMIO |
Definition at line 795 of file base.hh.
Referenced by flushCoalescedMMIO(), and regStats().
Stats::Scalar BaseKvmCPU::numExitSignal |
Definition at line 793 of file base.hh.
Referenced by regStats(), and tick().
Stats::Scalar BaseKvmCPU::numHalt |
Definition at line 797 of file base.hh.
Referenced by handleKvmExit(), and regStats().
Stats::Scalar BaseKvmCPU::numHypercalls |
Definition at line 799 of file base.hh.
Referenced by handleKvmExit(), and regStats().
Stats::Scalar BaseKvmCPU::numInsts |
Definition at line 790 of file base.hh.
Referenced by kvmRun(), and regStats().
Stats::Scalar BaseKvmCPU::numInterrupts |
Definition at line 798 of file base.hh.
Referenced by kvmInterrupt(), kvmNonMaskableInterrupt(), and regStats().
Stats::Scalar BaseKvmCPU::numIO |
Definition at line 796 of file base.hh.
Referenced by handleKvmExit(), and regStats().
Stats::Scalar BaseKvmCPU::numMMIO |
Definition at line 794 of file base.hh.
Referenced by handleKvmExit(), and regStats().
Stats::Scalar BaseKvmCPU::numVMExits |
Definition at line 791 of file base.hh.
Referenced by kvmRun(), and regStats().
Stats::Scalar BaseKvmCPU::numVMHalfEntries |
Definition at line 792 of file base.hh.
Referenced by kvmRun(), and regStats().
|
private |
Cached page size of the host.
Definition at line 709 of file base.hh.
Referenced by BaseKvmCPU(), and startup().
|
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 774 of file base.hh.
Referenced by kvmRun(), and setupCounters().
|
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 783 of file base.hh.
Referenced by kvmRun(), and startupThread().
ThreadContext* BaseKvmCPU::tc |
ThreadContext object, provides an interface for external objects to modify this thread's state.
Definition at line 150 of file base.hh.
Referenced by BaseKvmCPU(), X86KvmCPU::deliverInterrupts(), doMMIOAccess(), drainResume(), ArmKvmCPU::dumpKvmStateCoProc(), getContext(), X86KvmCPU::handleIOMiscReg32(), X86KvmCPU::handleKvmExitIO(), init(), X86KvmCPU::kvmRun(), X86KvmCPU::kvmRunWrapper(), ArmKvmCPU::onKvmExitHypercall(), ArmV8KvmCPU::startup(), X86KvmCPU::updateCPUID(), ArmV8KvmCPU::updateKvmState(), ArmKvmCPU::updateKvmStateCoProc(), ArmKvmCPU::updateKvmStateCore(), X86KvmCPU::updateKvmStateFPULegacy(), X86KvmCPU::updateKvmStateFPUXSave(), X86KvmCPU::updateKvmStateMSRs(), X86KvmCPU::updateKvmStateRegs(), X86KvmCPU::updateKvmStateSRegs(), ArmKvmCPU::updateKvmStateVFP(), ArmKvmCPU::updateTCStateCoProc(), ArmKvmCPU::updateTCStateCore(), ArmKvmCPU::updateTCStateVFP(), ArmV8KvmCPU::updateThreadContext(), X86KvmCPU::updateThreadContext(), X86KvmCPU::updateThreadContextFPU(), X86KvmCPU::updateThreadContextMSRs(), X86KvmCPU::updateThreadContextRegs(), and X86KvmCPU::updateThreadContextXSave().
SimpleThread* 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 145 of file base.hh.
Referenced by activateContext(), BaseKvmCPU(), X86KvmCPU::deliverInterrupts(), doMMIOAccess(), handleKvmExit(), serializeThread(), startup(), suspendContext(), unserializeThread(), and wakeup().
|
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 618 of file base.hh.
Referenced by X86KvmCPU::deliverInterrupts(), doMMIOAccess(), syncKvmState(), syncThreadContext(), takeOverFrom(), tick(), and unserializeThread().
|
private |
Definition at line 711 of file base.hh.
Referenced by activateContext(), drain(), drainResume(), finishMMIOPending(), notifyFork(), suspendContext(), switchOut(), takeOverFrom(), and tick().
|
private |
KVM vCPU file descriptor.
Definition at line 691 of file base.hh.
Referenced by ioctl(), kvmRun(), notifyFork(), startup(), and ~BaseKvmCPU().
|
protected |
KVM internal ID of the vCPU.
Definition at line 627 of file base.hh.
Referenced by getVCpuID(), BaseArmKvmCPU::kvmRun(), ArmKvmCPU::kvmRun(), and startup().
|
private |
Size of MMAPed kvm_run area.
Definition at line 693 of file base.hh.
Referenced by notifyFork(), startup(), and ~BaseKvmCPU().
|
protected |
ID of the vCPU thread.
Definition at line 630 of file base.hh.
Referenced by kick(), and startupThread().
KvmVM& BaseKvmCPU::vm |
Definition at line 152 of file base.hh.
Referenced by doMMIOAccess(), X86KvmCPU::dumpMSRs(), X86KvmCPU::getMsrIntersection(), X86KvmCPU::handleKvmExitIO(), BaseArmKvmCPU::kvmRun(), ArmKvmCPU::kvmRun(), BaseArmKvmCPU::startup(), startup(), and X86KvmCPU::X86KvmCPU().