gem5 v24.0.0.0
|
KVM VM container. More...
#include <vm.hh>
Classes | |
class | MemorySlot |
Structures tracking memory slots. More... | |
struct | MemSlot |
Public Member Functions | |
KvmVM (const KvmVMParams ¶ms) | |
virtual | ~KvmVM () |
void | notifyFork () |
Notify a child process of a fork. | |
void | setTSSAddress (Addr tss_address) |
Setup a shared three-page memory region used by the internals of KVM. | |
void | createIRQChip () |
Create an in-kernel interrupt controller. | |
void | setIRQLine (uint32_t irq, bool high) |
Set the status of an IRQ line using KVM_IRQ_LINE. | |
bool | hasKernelIRQChip () const |
Is in-kernel IRQ chip emulation enabled? | |
void | enableKernelIRQChip () |
Tell the VM and VCPUs to use an in-kernel IRQ chip for interrupt delivery. | |
const MemSlot | allocMemSlot (uint64_t size) |
Allocate a memory slot within the VM. | |
void | setupMemSlot (const MemSlot slot, void *host_addr, Addr guest_addr, uint32_t flags) |
Setup a region of physical memory in the guest. | |
void | disableMemSlot (const MemSlot slot) |
Disable a memory slot. | |
void | freeMemSlot (const MemSlot slot) |
Free a previously allocated memory slot. | |
int | createDevice (uint32_t type, uint32_t flags=0) |
Create an in-kernel device model. | |
bool | validEnvironment () const |
Verify gem5 configuration will support KVM emulation. | |
long | contextIdToVCpuId (ContextID ctx) const |
Get the VCPUID for a given context. | |
void | coalesceMMIO (Addr start, int size) |
Request coalescing MMIO for a memory range. | |
void | coalesceMMIO (const AddrRange &range) |
Request coalescing MMIO for a memory range. | |
Public Member Functions inherited from gem5::SimObject | |
const Params & | params () const |
SimObject (const Params &p) | |
virtual | ~SimObject () |
virtual void | init () |
init() is called after all C++ SimObjects have been created and all ports are connected. | |
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 | regProbePoints () |
Register probe points for this object. | |
virtual void | regProbeListeners () |
Register probe listeners for this object. | |
ProbeManager * | getProbeManager () |
Get the probe manager for this object. | |
virtual Port & | getPort (const std::string &if_name, PortID idx=InvalidPortID) |
Get a port with a given name and index. | |
virtual void | startup () |
startup() is the final initialization call before simulation. | |
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 | |
EventQueue * | eventQueue () 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 | regStats () |
Callback to set stat parameters. | |
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 Info * | resolveStat (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 | |
Group & | operator= (const Group &)=delete |
Public Member Functions inherited from gem5::Named | |
Named (const std::string &name_) | |
virtual | ~Named ()=default |
virtual std::string | name () const |
Public Attributes | |
Kvm * | kvm |
Global KVM interface. | |
Protected Member Functions | |
void | cpuStartup () |
VM CPU initialization code. | |
void | delayedStartup () |
Delayed initialization, executed once before the first CPU starts. | |
int | createVCPU (long vcpuID) |
Create a new vCPU within a VM. | |
long | allocVCPUID () |
Allocate a new vCPU ID within the VM. | |
int | ioctl (int request, long p1) const |
KVM VM ioctl interface. | |
int | ioctl (int request, void *p1) const |
int | ioctl (int request) const |
void | setUserMemoryRegion (uint32_t slot, void *host_addr, Addr guest_addr, uint64_t len, uint32_t flags) |
Setup a region of physical memory in the guest. | |
Protected Member Functions inherited from gem5::Drainable | |
Drainable () | |
virtual | ~Drainable () |
virtual void | drainResume () |
Resume execution after a successful drain. | |
void | signalDrainDone () const |
Signal that an object is drained. | |
Private Member Functions | |
KvmVM (const KvmVM &vm) | |
KvmVM & | operator= (const KvmVM &vm) |
Private Attributes | |
System * | system |
int | vmFD |
KVM VM file descriptor. | |
bool | started |
Has delayedStartup() already been called? | |
bool | _hasKernelIRQChip |
Do we have in-kernel IRQ-chip emulation enabled? | |
long | nextVCPUID |
Next unallocated vCPU ID. | |
std::vector< MemorySlot > | memorySlots |
uint32_t | maxMemorySlot |
Friends | |
class | BaseKvmCPU |
Additional Inherited Members | |
Public Types inherited from gem5::SimObject | |
typedef SimObjectParams | Params |
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 SimObject * | find (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 SimObjectResolver * | getSimObjectResolver () |
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. | |
Protected Attributes inherited from gem5::SimObject | |
const SimObjectParams & | _params |
Cached copy of the object parameters. | |
Protected Attributes inherited from gem5::EventManager | |
EventQueue * | eventq |
A pointer to this object's event queue. | |
KVM VM container.
A KVM VM container normally contains all the CPUs in a shared memory machine. The VM container handles things like physical memory and to some extent interrupts. Normally, the VM API is only used for interrupts when the PIC is emulated by the kernel, which is a feature we do not use. However, some architectures (notably ARM) use the VM interface to deliver interrupts to specific CPUs as well.
VM initialization is a bit different from that of other SimObjects. When we initialize the VM, we discover all physical memory mappings in the system. Since AbstractMem::unserialize re-maps the guests memory, we need to make sure that this is done after the memory has been re-mapped, but before the vCPUs are initialized (KVM requires memory mappings to be setup before CPUs can be created). Normally, we would just initialize the VM in init() or startup(), however, we can not use init() since this is called before AbstractMem::unserialize() and we can not use startup() since it must be called before BaseKvmCPU::startup() and the simulator framework does not guarantee call order. We therefore call cpuStartup() from BaseKvmCPU::startup() instead and execute the initialization code once when the first CPU in the VM is starting.
gem5::KvmVM::KvmVM | ( | const KvmVMParams & | params | ) |
Definition at line 316 of file vm.cc.
References gem5::Kvm::capNumMemSlots(), coalesceMMIO(), gem5::ArmISA::i, kvm, maxMemorySlot, gem5::SimObject::params(), gem5::System::setKvmVM(), and system.
|
private |
const KvmVM::MemSlot gem5::KvmVM::allocMemSlot | ( | uint64_t | size | ) |
Allocate a memory slot within the VM.
Definition at line 402 of file vm.cc.
References gem5::KvmVM::MemorySlot::active, maxMemorySlot, memorySlots, panic, gem5::KvmVM::MemorySlot::size, and gem5::KvmVM::MemorySlot::slot.
Referenced by delayedStartup().
|
protected |
Allocate a new vCPU ID within the VM.
The returned vCPU ID is guaranteed to be unique within the VM. New IDs are allocated sequentially starting from 0.
Definition at line 585 of file vm.cc.
References nextVCPUID.
Referenced by gem5::BaseKvmCPU::init().
void gem5::KvmVM::coalesceMMIO | ( | Addr | start, |
int | size ) |
void gem5::KvmVM::coalesceMMIO | ( | const AddrRange & | range | ) |
Request coalescing MMIO for a memory range.
range | Coalesced MMIO range |
Definition at line 481 of file vm.cc.
References coalesceMMIO(), gem5::AddrRange::size(), and gem5::AddrRange::start().
long gem5::KvmVM::contextIdToVCpuId | ( | ContextID | ctx | ) | const |
Get the VCPUID for a given context.
Definition at line 566 of file vm.cc.
References system, and gem5::System::threads.
Referenced by gem5::KvmKernelGicV2::readCpu(), gem5::KvmKernelGicV2::readDistributor(), gem5::KvmKernelGicV2::writeCpu(), and gem5::KvmKernelGicV2::writeDistributor().
|
protected |
VM CPU initialization code.
This method is called from BaseKvmCPU::startup() when a CPU in the VM executes its BaseKvmCPU::startup() method. The first time method is executed on a VM, it calls the delayedStartup() method.
Definition at line 358 of file vm.cc.
References delayedStartup(), and started.
Referenced by gem5::BaseKvmCPU::startup().
int gem5::KvmVM::createDevice | ( | uint32_t | type, |
uint32_t | flags = 0 ) |
|
protected |
Create a new vCPU within a VM.
vcpuID | ID of the new CPU within the VM. |
Definition at line 573 of file vm.cc.
References gem5::ArmISA::fd, ioctl(), and panic.
Referenced by gem5::BaseKvmCPU::startup().
|
protected |
Delayed initialization, executed once before the first CPU starts.
This method provides a way to do VM initialization once before the first CPU in a VM starts. It is needed since some resources (e.g., memory mappings) can change in the normal SimObject::startup() path. Since the call order of SimObject::startup() is not guaranteed, we simply defer some initialization until a CPU is about to start.
Definition at line 368 of file vm.cc.
References allocMemSlot(), DPRINTF, gem5::memory::PhysicalMemory::getBackingStore(), gem5::System::getPhysMem(), hack, panic, setupMemSlot(), and system.
Referenced by cpuStartup().
void gem5::KvmVM::disableMemSlot | ( | const MemSlot | slot | ) |
Disable a memory slot.
Definition at line 439 of file vm.cc.
References gem5::KvmVM::MemorySlot::active, memorySlots, gem5::KvmVM::MemSlot::num, and setUserMemoryRegion().
Referenced by freeMemSlot().
void gem5::KvmVM::freeMemSlot | ( | const MemSlot | slot | ) |
Free a previously allocated memory slot.
Definition at line 448 of file vm.cc.
References disableMemSlot(), memorySlots, gem5::KvmVM::MemSlot::num, and gem5::KvmVM::MemorySlot::size.
|
virtual |
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.
void gem5::KvmVM::setTSSAddress | ( | Addr | tss_address | ) |
void gem5::KvmVM::setupMemSlot | ( | const MemSlot | slot, |
void * | host_addr, | ||
Addr | guest_addr, | ||
uint32_t | flags ) |
Setup a region of physical memory in the guest.
slot | KVM memory slot ID returned by allocMemSlot |
host_addr | Memory allocation backing the memory |
guest_addr | Address in the guest |
flags | Flags (see the KVM API documentation) |
Definition at line 430 of file vm.cc.
References gem5::KvmVM::MemorySlot::active, flags, memorySlots, gem5::KvmVM::MemSlot::num, setUserMemoryRegion(), and gem5::KvmVM::MemorySlot::size.
Referenced by delayedStartup().
|
protected |
Setup a region of physical memory in the guest.
slot | KVM memory slot ID (must be unique) |
host_addr | Memory allocation backing the memory |
guest_addr | Address in the guest |
len | Size of the allocation in bytes |
flags | Flags (see the KVM API documentation) |
Definition at line 456 of file vm.cc.
References flags, ioctl(), gem5::ArmISA::len, gem5::ArmISA::m, and panic.
Referenced by disableMemSlot(), and setupMemSlot().
bool gem5::KvmVM::validEnvironment | ( | ) | const |
Verify gem5 configuration will support KVM emulation.
Definition at line 555 of file vm.cc.
References system, and gem5::System::threads.
Referenced by gem5::MuxingKvmGic< Types >::drainResume(), and gem5::ArchTimerKvm::scheduleEvents().
|
friend |
|
private |
Do we have in-kernel IRQ-chip emulation enabled?
Definition at line 543 of file vm.hh.
Referenced by createIRQChip(), enableKernelIRQChip(), and hasKernelIRQChip().
Kvm* gem5::KvmVM::kvm |
Global KVM interface.
Definition at line 421 of file vm.hh.
Referenced by gem5::X86KvmCPU::dumpMSRs(), gem5::X86KvmCPU::getMsrIntersection(), gem5::X86KvmCPU::init(), KvmVM(), notifyFork(), gem5::KvmKernelGic::setIntState(), gem5::BaseKvmCPU::startup(), and ~KvmVM().
|
private |
Definition at line 559 of file vm.hh.
Referenced by allocMemSlot(), and KvmVM().
|
private |
Definition at line 558 of file vm.hh.
Referenced by allocMemSlot(), disableMemSlot(), freeMemSlot(), and setupMemSlot().
|
private |
|
private |
Has delayedStartup() already been called?
Definition at line 540 of file vm.hh.
Referenced by cpuStartup().
|
private |
Definition at line 534 of file vm.hh.
Referenced by contextIdToVCpuId(), delayedStartup(), KvmVM(), and validEnvironment().
|
private |
KVM VM file descriptor.
Definition at line 537 of file vm.hh.
Referenced by ioctl(), notifyFork(), and ~KvmVM().