40 #ifndef __CPU_KVM_BASE_HH__
41 #define __CPU_KVM_BASE_HH__
57 #define KVM_KICK_SIGNAL SIGRTMIN
61 struct BaseKvmCPUParams;
122 virtual void dump()
const;
555 int ioctl(
int request,
long p1)
const;
556 int ioctl(
int request,
void *p1)
const {
557 return ioctl(request, (
long)p1);
560 return ioctl(request, 0
L);
643 return "BaseKvmCPU tick";
A MasterPort is a specialisation of a BaseMasterPort, which implements the default protocol for the t...
void tick()
Execute the CPU until the next event in the main event queue or until the guest needs service from ge...
void setupCounters()
Setup hardware performance counters.
void finishMMIOPending()
Callback from KvmCPUPort to transition the CPU out of RunningMMIOPending when all timing requests hav...
Counter ctrInsts
Number of instructions executed by the CPU.
uint64_t activeInstPeriod
Currently active instruction count breakpoint.
Timing MMIO request in flight or stalled.
virtual void updateThreadContext()=0
Update the current thread context with the KVM state.
BaseKvmCPU * cpu
KVM cpu pointer for finishMMIOPending() callback.
DrainState
Object drain/handover states.
virtual Tick handleKvmExitIO()
The guest performed a legacy IO request (out/inp on x86)
bool recvTimingResp(PacketPtr pkt) override
Receive a timing response from the slave port.
Tick submitIO(PacketPtr pkt)
Interface to send Atomic or Timing IO request.
bool threadContextDirty
Is the gem5 context dirty? Set to true to force an update of the KVM vCPU state upon the next call to...
bool perfControlledByTimer
Does the runTimer control the performance counters?
static const Priority CPU_Tick_Pri
CPU ticks must come after other associated CPU events (such as writebacks).
void notifyFork() override
virtual Tick kvmRun(Tick ticks)
Request KVM to run the guest for a given number of ticks.
std::unique_ptr< BaseKvmTimer > runTimer
Timer used to force execution into the monitor after a specified number of simulation tick equivalent...
ThreadContext * tc
ThreadContext object, provides an interface for external objects to modify this thread's state...
void kvmNonMaskableInterrupt()
Send a non-maskable interrupt to the guest.
virtual Tick handleKvmExitIRQWindowOpen()
The guest exited because an interrupt window was requested.
KVMCpuPort instPort
Unused dummy port for the instruction interface.
void verifyMemoryMode() const override
void wakeup(ThreadID tid=0) override
The SimpleThread object provides a combination of the ThreadState object and the ThreadContext interf...
float hostFactor
Host factor as specified in the configuration.
bool tryDrain()
Try to drain the CPU if a drain is pending.
void setOneReg(uint64_t id, uint32_t value)
Counter totalInsts() const override
Stats::Scalar numExitSignal
virtual Tick kvmRunDrain()
Request the CPU to run until draining completes.
Base class for KVM based CPU models.
Tick flushCoalescedMMIO()
Service MMIO requests in the mmioRing.
MasterPort & getInstPort() override
DrainState drain() override
ThreadContext is the external interface to all thread state for anything outside of the CPU...
Declaration of Statistics objects.
This is a simple scalar statistic, like a counter.
const long vcpuID
KVM internal ID of the vCPU.
void recvReqRetry() override
Called by the slave port if sendTimingReq was called on this master port (causing recvTimingReq to be...
virtual void updateKvmState()=0
Update the KVM state from the current thread context.
void activateContext(ThreadID thread_num) override
Stats::Scalar numInterrupts
#define KVM_KICK_SIGNAL
Signal to use to trigger exits from KVM.
bool discardPendingSignal(int signum) const
Discard a (potentially) pending signal.
void setSpecialRegisters(const struct kvm_sregs ®s)
void serializeThread(CheckpointOut &cp, ThreadID tid) const override
void setupSignalHandler()
Setup a signal handler to catch the timer signal used to switch back to the monitor.
int vcpuMMapSize
Size of MMAPed kvm_run area.
virtual Tick handleKvmExitFailEntry()
KVM failed to start the virtualized CPU.
void drainResume() override
struct kvm_run * _kvmRun
Pointer to the kvm_run structure used to communicate parameters with KVM.
void syncKvmState()
Update the KVM if the thread context is dirty.
ThreadContext * getContext(int tn) override
void setOneReg(uint64_t id, const void *addr)
Get/Set single register using the KVM_(SET|GET)_ONE_REG API.
uint64_t Tick
Tick count type.
uint64_t getOneRegU64(uint64_t id) const
const bool alwaysSyncTC
Be conservative and always synchronize the thread context on KVM entry/exit.
void deallocateContext(ThreadID thread_num)
void takeOverFrom(BaseCPU *cpu) override
struct kvm_coalesced_mmio_ring * mmioRing
Coalesced MMIO ring buffer.
const char * description() const
Return a C string describing the event.
pthread_t vcpuThread
ID of the vCPU thread.
bool kvmStateDirty
Is the KVM state dirty? Set to true to force an update of the KVM vCPU state upon the next call to kv...
void setOneReg(uint64_t id, uint64_t value)
PerfKvmCounter hwInstructions
Guest instruction counter.
uint32_t getOneRegU32(uint64_t id) const
PerfKvmCounter hwCycles
Guest cycle counter.
Service completion in progress.
uint8_t * getGuestData(uint64_t offset) const
Retrieve a pointer to guest data stored at the end of the kvm_run structure.
An instance of a performance counter.
Requiring service at the beginning of the next cycle.
virtual Tick handleKvmExitException()
An unhandled virtualization exception occured.
void setSignalMask(const sigset_t *mask)
Set the signal mask used in kvmRun()
Stats::Scalar numVMHalfEntries
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
virtual bool archIsDrained() const
Is the architecture specific code in a state that prevents draining?
int64_t Counter
Statistics counter type.
void setupInstStop()
Setup an instruction break if there is one pending.
A Packet is used to encapsulate a transfer between two objects in the memory system (e...
Status _status
CPU run state.
void kvmInterrupt(const struct kvm_interrupt &interrupt)
Send a normal interrupt to the guest.
Stats::Scalar numHypercalls
BaseKvmCPU(BaseKvmCPUParams *params)
void setFPUState(const struct kvm_fpu &state)
std::queue< PacketPtr > pendingMMIOPkts
Pending MMIO packets.
int16_t ThreadID
Thread index/ID type.
const long pageSize
Cached page size of the host.
KVMCpuPort dataPort
Port for data requests.
void ioctlRun()
Execute the KVM_RUN ioctl.
int ioctl(int request) const
std::ostream CheckpointOut
void kick() const
Force an exit from KVM.
int vcpuFD
KVM vCPU file descriptor.
MasterPort & getDataPort() override
void setRegisters(const struct kvm_regs ®s)
void getOneReg(uint64_t id, void *addr) const
std::string getAndFormatOneReg(uint64_t id) const
Get and format one register for printout.
void setupInstCounter(uint64_t period=0)
Setup the guest instruction counter.
virtual void dump() const
Dump the internal state to the terminal.
void suspendContext(ThreadID thread_num) override
virtual Tick handleKvmExitHypercall()
The guest requested a monitor service using a hypercall.
void unserializeThread(CheckpointIn &cp, ThreadID tid) override
virtual uint64_t getHostCycles() const
Get the value of the hardware cycle counter in the guest.
int ioctl(int request, void *p1) const
Status nextIOState() const
Returns next valid state after one or more IO accesses.
Context not scheduled in KVM.
Counter totalOps() const override
virtual Tick handleKvmExitUnknown()
An unknown architecture dependent error occurred when starting the vCPU.
SimpleThread * thread
A cached copy of a thread's state in the form of a SimpleThread object.
void getFPUState(struct kvm_fpu &state) const
Get/Set the guest FPU/vector state.
void switchOut() override
KVMCpuPort(const std::string &_name, BaseKvmCPU *_cpu)
void getRegisters(struct kvm_regs ®s) const
Get/Set the register state of the guest vCPU.
virtual Tick handleKvmExit()
Main kvmRun exit handler, calls the relevant handleKvmExit* depending on exit type.
unsigned int activeMMIOReqs
Number of MMIO requests in flight.
Tick doMMIOAccess(Addr paddr, void *data, int size, bool write)
Inject a memory mapped IO request into gem5.
Stats::Scalar numCoalescedMMIO
void startupThread()
Thread-specific initialization.
void syncThreadContext()
Update a thread context if the KVM state is dirty with respect to the cached thread context...
void haltContext(ThreadID thread_num) override
void getSpecialRegisters(struct kvm_sregs ®s) const
int ioctl(int request, long p1) const
vCPU ioctl interface.
struct kvm_run * getKvmRunState()
Get a pointer to the kvm_run structure containing all the input and output parameters from kvmRun()...