38#ifndef __CPU_KVM_BASE_HH__
39#define __CPU_KVM_BASE_HH__
56#define KVM_KICK_SIGNAL SIGRTMIN
58struct kvm_coalesced_mmio_ring;
70struct BaseKvmCPUParams;
130 virtual void dump()
const;
352 void kvmInterrupt(
const struct kvm_interrupt &interrupt);
583 int ioctl(
int request,
long p1)
const;
584 int ioctl(
int request,
void *p1)
const {
585 return ioctl(request, (
long)p1);
588 return ioctl(request, 0
L);
KVMCpuPort(const std::string &_name, BaseKvmCPU *_cpu)
std::queue< PacketPtr > pendingMMIOPkts
Pending MMIO packets.
Status nextIOState() const
Returns next valid state after one or more IO accesses.
BaseKvmCPU * cpu
KVM cpu pointer for finishMMIOPending() callback.
Tick submitIO(PacketPtr pkt)
Interface to send Atomic or Timing IO request.
void recvReqRetry() override
Called by the peer if sendTimingReq was called on this peer (causing recvTimingReq to be called on th...
bool recvTimingResp(PacketPtr pkt) override
Receive a timing response from the peer.
unsigned int activeMMIOReqs
Number of MMIO requests in flight.
Base class for KVM based CPU models.
virtual void dump() const
Dump the internal state to the terminal.
int vcpuFD
KVM vCPU file descriptor.
void finishMMIOPending()
Callback from KvmCPUPort to transition the CPU out of RunningMMIOPending when all timing requests hav...
Status _status
CPU run state.
uint64_t activeInstPeriod
Currently active instruction count breakpoint.
virtual void updateKvmState()=0
Update the KVM state from the current thread context.
struct kvm_coalesced_mmio_ring * mmioRing
Coalesced MMIO ring buffer.
virtual Tick handleKvmExitHypercall()
The guest requested a monitor service using a hypercall.
long vcpuID
KVM internal ID of the vCPU.
void drainResume() override
Resume execution after a successful drain.
void getSpecialRegisters(struct kvm_sregs ®s) const
virtual void updateThreadContext()=0
Update the current thread context with the KVM state.
uint8_t * getGuestData(uint64_t offset) const
Retrieve a pointer to guest data stored at the end of the kvm_run structure.
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 sw...
virtual uint64_t getHostCycles() const
Get the value of the hardware cycle counter in the guest.
Counter totalInsts() const override
void getOneReg(uint64_t id, void *addr) const
void init() override
init() is called after all C++ SimObjects have been created and all ports are connected.
const bool alwaysSyncTC
Be conservative and always synchronize the thread context on KVM entry/exit.
void suspendContext(ThreadID thread_num) override
Notify the CPU that the indicated context is now suspended.
struct kvm_run * getKvmRunState()
Get a pointer to the kvm_run structure containing all the input and output parameters from kvmRun().
virtual Tick handleKvmExitIRQWindowOpen()
The guest exited because an interrupt window was requested.
uint64_t getOneRegU64(uint64_t id) const
void setSignalMask(const sigset_t *mask)
Set the signal mask used in kvmRun()
void notifyFork() override
Notify a child process of a fork.
int vcpuMMapSize
Size of MMAPed kvm_run area.
void syncKvmState()
Update the KVM if the thread context is dirty.
bool tryDrain()
Try to drain the CPU if a drain is pending.
void setRegisters(const struct kvm_regs ®s)
BaseKvmCPU(const BaseKvmCPUParams ¶ms)
virtual Tick handleKvmExitException()
An unhandled virtualization exception occured.
KVMCpuPort instPort
Unused dummy port for the instruction interface.
void kick() const
Force an exit from KVM.
@ Running
Running normally.
@ Idle
Context not scheduled in KVM.
@ RunningMMIOPending
Timing MMIO request in flight or stalled.
@ RunningService
Requiring service at the beginning of the next cycle.
@ RunningServiceCompletion
Service completion in progress.
void deallocateContext(ThreadID thread_num)
void getRegisters(struct kvm_regs ®s) const
Get/Set the register state of the guest vCPU.
void setupSignalHandler()
Setup a signal handler to catch the timer signal used to switch back to the monitor.
void setOneReg(uint64_t id, uint64_t value)
void setSpecialRegisters(const struct kvm_sregs ®s)
ThreadContext * getContext(int tn) override
Given a thread num get tho thread context for it.
bool usePerf
True if using perf; False otherwise.
virtual Tick handleKvmExitIO()
The guest performed a legacy IO request (out/inp on x86)
std::string getAndFormatOneReg(uint64_t id) const
Get and format one register for printout.
gem5::BaseKvmCPU::StatGroup stats
virtual Tick handleKvmExit()
Main kvmRun exit handler, calls the relevant handleKvmExit* depending on exit type.
void syncThreadContext()
Update a thread context if the KVM state is dirty with respect to the cached thread context.
void unserializeThread(CheckpointIn &cp, ThreadID tid) override
Unserialize one thread.
uint32_t getOneRegU32(uint64_t id) const
DrainState drain() override
Draining is the process of clearing out the states of SimObjects.These are the SimObjects that are pa...
Tick doMMIOAccess(Addr paddr, void *data, int size, bool write)
Inject a memory mapped IO request into gem5.
void wakeup(ThreadID tid=0) override
void startup() override
startup() is the final initialization call before simulation.
Counter totalOps() const override
Tick flushCoalescedMMIO()
Service MMIO requests in the mmioRing.
std::unique_ptr< PerfKvmCounter > hwInstructions
Guest instruction counter.
EventFunctionWrapper tickEvent
bool perfControlledByTimer
Does the runTimer control the performance counters?
virtual Tick kvmRun(Tick ticks)
Request KVM to run the guest for a given number of ticks.
void setupInstStop()
Setup an instruction break if there is one pending.
bool discardPendingSignal(int signum) const
Discard a (potentially) pending signal.
void setOneReg(uint64_t id, uint32_t value)
virtual Tick kvmRunDrain()
Request the CPU to run until draining completes.
virtual Tick handleKvmExitFailEntry()
KVM failed to start the virtualized CPU.
void switchOut() override
Prepare for another CPU to take over execution.
void restartEqThread()
Thread-specific initialization.
void setupCounters()
Setup hardware performance counters.
void serializeThread(CheckpointOut &cp, ThreadID tid) const override
Serialize a single thread.
void setupInstCounter(uint64_t period=0)
Setup the guest instruction counter.
void activateContext(ThreadID thread_num) override
Notify the CPU that the indicated context is now active.
void tick()
Execute the CPU until the next event in the main event queue or until the guest needs service from ge...
virtual bool archIsDrained() const
Is the architecture specific code in a state that prevents draining?
struct kvm_run * _kvmRun
Pointer to the kvm_run structure used to communicate parameters with KVM.
std::unique_ptr< PerfKvmCounter > hwCycles
Guest cycle counter.
void setOneReg(uint64_t id, const void *addr)
Get/Set single register using the KVM_(SET|GET)_ONE_REG API.
std::unique_ptr< BaseKvmTimer > runTimer
Timer used to force execution into the monitor after a specified number of simulation tick equivalent...
KVMCpuPort dataPort
Port for data requests.
SimpleThread * thread
A cached copy of a thread's state in the form of a SimpleThread object.
void setFPUState(const struct kvm_fpu &state)
virtual Tick handleKvmExitUnknown()
An unknown architecture dependent error occurred when starting the vCPU.
void getFPUState(struct kvm_fpu &state) const
Get/Set the guest FPU/vector state.
void haltContext(ThreadID thread_num) override
Notify the CPU that the indicated context is now halted.
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...
EventQueue * deviceEventQueue()
Get a pointer to the event queue owning devices.
void verifyMemoryMode() const override
Verify that the system is in a memory mode supported by the CPU.
bool threadContextDirty
Is the gem5 context dirty? Set to true to force an update of the KVM vCPU state upon the next call to...
const long pageSize
Cached page size of the host.
pthread_t vcpuThread
ID of the vCPU thread.
Counter ctrInsts
Number of instructions executed by the CPU.
float hostFactor
Host factor as specified in the configuration.
Port & getInstPort() override
Purely virtual method that returns a reference to the instruction port.
Port & getDataPort() override
Purely virtual method that returns a reference to the data port.
ThreadContext * tc
ThreadContext object, provides an interface for external objects to modify this thread's state.
virtual void ioctlRun()
Execute the KVM_RUN ioctl.
virtual void stutterPC(PCStateBase &pc) const =0
Modify a PCStatePtr's value so that its next PC is the current PC.
Queue of events sorted in time order.
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Ports are used to interface objects to each other.
A RequestPort is a specialisation of a Port, which implements the default protocol for the three diff...
The SimpleThread object provides a combination of the ThreadState object and the ThreadContext interf...
ThreadContext is the external interface to all thread state for anything outside of the CPU.
This is a simple scalar statistic, like a counter.
#define KVM_KICK_SIGNAL
Signal to use to trigger exits from KVM.
void kvmInterrupt(const struct kvm_interrupt &interrupt)
Send a normal interrupt to the guest.
void kvmNonMaskableInterrupt()
Send a non-maskable interrupt to the guest.
int ioctl(int request, long p1) const
vCPU ioctl interface.
int ioctl(int request, void *p1) const
int ioctl(int request) const
DrainState
Object drain/handover states.
EventQueue * eventQueue() const
const Params & params() const
double Counter
All counters are of 64-bit values.
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
int16_t ThreadID
Thread index/ID type.
std::ostream CheckpointOut
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
uint64_t Tick
Tick count type.
Declaration of Statistics objects.
statistics::Scalar numExitSignal
StatGroup(statistics::Group *parent)
statistics::Scalar numHypercalls
statistics::Scalar numHalt
statistics::Scalar numVMHalfEntries
statistics::Scalar numMMIO
statistics::Scalar numCoalescedMMIO
statistics::Scalar numInterrupts
statistics::Scalar numVMExits