cpu-kvm: Move the validKvmEnvironment method into KvmVM.

This makes the generic System class consistent whether you have KVM
enabled or not.

Change-Id: Ie6928961200943d1d4e3bd129a4e4269e9f12950
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/56263
Reviewed-by: Andreas Sandberg <andreas.sandberg@arm.com>
Maintainer: Gabe Black <gabe.black@gmail.com>
Tested-by: kokoro <noreply+kokoro@google.com>
This commit is contained in:
Gabe Black
2022-01-27 23:52:41 -08:00
parent 5e1fdf7586
commit ac5f79af28
8 changed files with 34 additions and 27 deletions

View File

@@ -188,7 +188,7 @@ void
MuxingKvmGic::startup()
{
GicV2::startup();
usingKvm = (kernelGic != nullptr) && system.validKvmEnvironment();
usingKvm = kernelGic && vm && vm->validEnvironment();
if (usingKvm)
fromGicV2ToKvm();
}
@@ -205,7 +205,7 @@ void
MuxingKvmGic::drainResume()
{
GicV2::drainResume();
bool use_kvm = (kernelGic != nullptr) && system.validKvmEnvironment();
bool use_kvm = kernelGic && vm && vm->validEnvironment();
if (use_kvm != usingKvm) {
// Should only occur due to CPU switches
if (use_kvm) // from simulation to KVM emulation

View File

@@ -79,3 +79,4 @@ else:
warning("Can not enable KVM, host seems to lack KVM support")
export_vars.append('USE_KVM')
export_vars.append('KVM_ISA')

View File

@@ -542,6 +542,17 @@ KvmVM::createDevice(uint32_t type, uint32_t flags)
#endif
}
bool
KvmVM::validEnvironment() const
{
for (auto *tc: system->threads) {
if (!dynamic_cast<BaseKvmCPU *>(tc->getCpuPtr()))
return false;
}
return true;
}
void
KvmVM::setSystem(System *s)
{

View File

@@ -416,6 +416,9 @@ class KvmVM : public SimObject
/** Global KVM interface */
Kvm *kvm;
/** Verify gem5 configuration will support KVM emulation */
bool validEnvironment() const;
/**
* Initialize system pointer. Invoked by system object.
*/

View File

@@ -38,13 +38,17 @@
#include "dev/arm/generic_timer.hh"
#include <cmath>
#include <string_view>
#include "arch/arm/page_size.hh"
#include "arch/arm/system.hh"
#include "arch/arm/utility.hh"
#include "base/logging.hh"
#include "base/trace.hh"
#include "config/kvm_isa.hh"
#include "config/use_kvm.hh"
#include "cpu/base.hh"
#include "cpu/kvm/vm.hh"
#include "debug/Timer.hh"
#include "dev/arm/base_gic.hh"
#include "mem/packet_access.hh"
@@ -403,6 +407,18 @@ ArchTimer::drainResume()
updateCounter();
}
bool
ArchTimerKvm::scheduleEvents()
{
if constexpr (USE_KVM &&
std::string_view(KVM_ISA) == std::string_view("arm")) {
auto *vm = system.getKvmVM();
return !vm || !vm->validEnvironment();
} else {
return true;
}
}
GenericTimer::GenericTimer(const GenericTimerParams &p)
: SimObject(p),
systemCounter(*p.counter),

View File

@@ -280,9 +280,7 @@ class ArchTimerKvm : public ArchTimer
// For ArchTimer's in a GenericTimerISA with Kvm execution about
// to begin, skip rescheduling the event.
// Otherwise, we should reschedule the event (if necessary).
bool scheduleEvents() override {
return !system.validKvmEnvironment();
}
bool scheduleEvents() override;
};
class GenericTimer : public SimObject

View File

@@ -52,7 +52,6 @@
#include "config/the_isa.hh"
#include "config/use_kvm.hh"
#if USE_KVM
#include "cpu/kvm/base.hh"
#include "cpu/kvm/vm.hh"
#endif
#if !IS_NULL_ISA
@@ -316,24 +315,6 @@ System::replaceThreadContext(ThreadContext *tc, ContextID context_id)
}
}
bool
System::validKvmEnvironment() const
{
#if USE_KVM
if (threads.empty())
return false;
for (auto *tc: threads) {
if (!dynamic_cast<BaseKvmCPU *>(tc->getCpuPtr()))
return false;
}
return true;
#else
return false;
#endif
}
Addr
System::memSize() const
{

View File

@@ -336,9 +336,6 @@ class System : public SimObject, public PCEventScope
*/
KvmVM *getKvmVM() { return kvmVM; }
/** Verify gem5 configuration will support KVM emulation */
bool validKvmEnvironment() const;
/** Get a pointer to access the physical memory of the system */
memory::PhysicalMemory& getPhysMem() { return physmem; }
const memory::PhysicalMemory& getPhysMem() const { return physmem; }