sim, kvm: make KvmVM a System parameter
authorCurtis Dunham <Curtis.Dunham@arm.com>
Tue, 14 Feb 2017 21:09:18 +0000 (15:09 -0600)
committerCurtis Dunham <Curtis.Dunham@arm.com>
Tue, 14 Feb 2017 21:09:18 +0000 (15:09 -0600)
A KVM VM is typically a child of the System object already, but for
solving future issues with configuration graph resolution, the most
logical way to keep track of this object is for it to be an actual
parameter of the System object.

Change-Id: I965ded22203ff8667db9ca02de0042ff1c772220
Reviewed-by: Andreas Sandberg <andreas.sandberg@arm.com>
12 files changed:
configs/example/fs.py
configs/example/se.py
src/arch/arm/kvm/KvmGic.py
src/arch/arm/kvm/gic.cc
src/cpu/kvm/BaseKvmCPU.py
src/cpu/kvm/KvmVM.py
src/cpu/kvm/base.cc
src/cpu/kvm/vm.cc
src/cpu/kvm/vm.hh
src/sim/System.py
src/sim/system.cc
src/sim/system.hh

index 1ada590845c3152658a5aa23f48a2cd745bdef91..8102edc75b0162ee16c239f878ace77314ec3e45 100644 (file)
@@ -143,7 +143,7 @@ def build_test_system(np):
                     for i in xrange(np)]
 
     if is_kvm_cpu(TestCPUClass) or is_kvm_cpu(FutureClass):
-        test_sys.vm = KvmVM()
+        test_sys.kvm_vm = KvmVM()
 
     if options.ruby:
         # Check for timing mode because ruby does not support atomic accesses
@@ -280,7 +280,7 @@ def build_drive_system(np):
         drive_sys.kernel = binary(options.kernel)
 
     if is_kvm_cpu(DriveCPUClass):
-        drive_sys.vm = KvmVM()
+        drive_sys.kvm_vm = KvmVM()
 
     drive_sys.iobridge = Bridge(delay='50ns',
                                 ranges = drive_sys.mem_ranges)
index c48b99eb48d1e7a44d9abe49275913488e660f9e..4adfe7bb8da5955a96613bc13309c7716a950f10 100644 (file)
@@ -209,7 +209,7 @@ for cpu in system.cpu:
 
 if is_kvm_cpu(CPUClass) or is_kvm_cpu(FutureClass):
     if buildEnv['TARGET_ISA'] == 'x86':
-        system.vm = KvmVM()
+        system.kvm_vm = KvmVM()
         for process in multiprocesses:
             process.useArchPT = True
             process.kvmInSE = True
index 74bfe1e0bae8531e6b62d8e94aaccda8a6233824..9ae52db2293b0478e11425f53ea91ec56991debc 100644 (file)
@@ -52,4 +52,3 @@ class KvmGic(BaseGic):
 
     system = Param.System(Parent.any,
                           'System this interrupt controller belongs to')
-    kvmVM = Param.KvmVM(Parent.any, 'KVM VM (i.e., shared memory domain)')
index 684f026f0fbf6ec3008cfded70ce17faf95d2e1c..c5a30879c885093683a3cfacedeb390b55f5d346 100644 (file)
@@ -106,7 +106,8 @@ KvmKernelGicV2::setIntState(unsigned type, unsigned vcpu, unsigned irq,
 KvmGic::KvmGic(const KvmGicParams *p)
     : BaseGic(p),
       system(*p->system),
-      kernelGic(*p->kvmVM, p->cpu_addr, p->dist_addr, p->it_lines),
+      kernelGic(*system.getKvmVM(),
+                p->cpu_addr, p->dist_addr, p->it_lines),
       addrRanges{kernelGic.distRange, kernelGic.cpuRange}
 {
 }
index 4c64f24ed0d901db2e96f500e89192517599322d..cc0b28fe9dba6b5878ab1bec563c83b4a3912b1c 100644 (file)
@@ -64,7 +64,6 @@ class BaseKvmCPU(BaseCPU):
     def support_take_over(cls):
         return True
 
-    kvmVM = Param.KvmVM(Parent.any, 'KVM VM (i.e., shared memory domain)')
     useCoalescedMMIO = Param.Bool(False, "Use coalesced MMIO (EXPERIMENTAL)")
     usePerfOverflow = Param.Bool(False, "Use perf event overflow counters (EXPERIMENTAL)")
     alwaysSyncTC = Param.Bool(False,
index 478a91682a9f1b7b789cd0ea05f93a60e8ad38ff..cbc92ca0d4972cf2ada7f932e79ff1896725d0d4 100644 (file)
@@ -44,6 +44,5 @@ class KvmVM(SimObject):
     type = 'KvmVM'
     cxx_header = "cpu/kvm/vm.hh"
 
-    system = Param.System(Parent.any, "system object")
-
-    coalescedMMIO = VectorParam.AddrRange([], "memory ranges for coalesced MMIO")
+    coalescedMMIO = \
+      VectorParam.AddrRange([], "memory ranges for coalesced MMIO")
index 723feda448b71a4be4a1c9d3ae689b79f49b432b..6ae3c7dff9631a1e942ffa6595e4ec73d5d3237e 100644 (file)
@@ -64,7 +64,7 @@
 
 BaseKvmCPU::BaseKvmCPU(BaseKvmCPUParams *params)
     : BaseCPU(params),
-      vm(*params->kvmVM),
+      vm(*params->system->getKvmVM()),
       _status(Idle),
       dataPort(name() + ".dcache_port", this),
       instPort(name() + ".icache_port", this),
index d3ab8c45a6c08b19b1908ba3c831dedcb8ddc671..604d182ab2e5fe0057bbe9dfe42956f9aa04af42 100644 (file)
@@ -292,7 +292,7 @@ Kvm::createVM()
 
 KvmVM::KvmVM(KvmVMParams *params)
     : SimObject(params),
-      kvm(new Kvm()), system(params->system),
+      kvm(new Kvm()), system(nullptr),
       vmFD(kvm->createVM()),
       started(false),
       nextVCPUID(0)
@@ -342,6 +342,7 @@ KvmVM::cpuStartup()
 void
 KvmVM::delayedStartup()
 {
+    assert(system); // set by the system during its construction
     const std::vector<BackingStoreEntry> &memories(
         system->getPhysMem().getBackingStore());
 
@@ -526,6 +527,13 @@ KvmVM::createDevice(uint32_t type, uint32_t flags)
 #endif
 }
 
+void
+KvmVM::setSystem(System *s) {
+    panic_if(system != nullptr, "setSystem() can only be called once");
+    panic_if(s == nullptr, "setSystem() called with null System*");
+    system = s;
+}
+
 int
 KvmVM::createVCPU(long vcpuID)
 {
index 560efb606da997f94769c7ce823cd9288b442d93..dbd46aa3c3356e6cfa9bfe96081ac1a80c075ea7 100644 (file)
@@ -400,6 +400,11 @@ class KvmVM : public SimObject
     /** Global KVM interface */
     Kvm *kvm;
 
+    /**
+     * Initialize system pointer. Invoked by system object.
+     */
+    void setSystem(System *s);
+
 #if defined(__aarch64__)
   public: // ARM-specific
     /**
index 34b1fd12795646bd5a31b69189e8eb62045e5916..e3e42d862cc3c810b9321f6aaff2e79f38addc18 100644 (file)
@@ -29,6 +29,7 @@
 #          Rick Strong
 
 from m5.SimObject import SimObject
+from m5.defines import buildEnv
 from m5.params import *
 from m5.proxy import *
 
@@ -106,3 +107,6 @@ class System(MemObject):
     # Dynamic voltage and frequency handler for the system, disabled by default
     # Provide list of domains that need to be controlled by the handler
     dvfs_handler = DVFSHandler()
+
+    if buildEnv['USE_KVM']:
+        kvm_vm = Param.KvmVM(NULL, 'KVM VM (i.e., shared memory domain)')
index 09be232a73ab309dc6b35d4978d15b8878a296cb..9315882b7d776826f8b0e40d833b9026b560bcee 100644 (file)
 #include "base/loader/symtab.hh"
 #include "base/str.hh"
 #include "base/trace.hh"
+#include "config/use_kvm.hh"
+#if USE_KVM
+#include "cpu/kvm/vm.hh"
+#endif
 #include "cpu/thread_context.hh"
 #include "debug/Loader.hh"
 #include "debug/WorkItems.hh"
@@ -90,6 +94,11 @@ System::System(Params *p)
       kernel(nullptr),
       loadAddrMask(p->load_addr_mask),
       loadAddrOffset(p->load_offset),
+#if USE_KVM
+      kvmVM(p->kvm_vm),
+#else
+      kvmVM(nullptr),
+#endif
       physmem(name() + ".physmem", p->memories, p->mmap_using_noreserve),
       memoryMode(p->mem_mode),
       _cacheLineSize(p->cache_line_size),
@@ -104,6 +113,12 @@ System::System(Params *p)
     // add self to global system list
     systemList.push_back(this);
 
+#if USE_KVM
+    if (kvmVM) {
+        kvmVM->setSystem(this);
+    }
+#endif
+
     if (FullSystem) {
         kernelSymtab = new SymbolTable;
         if (!debugSymbolTable)
index 1bbd37d9d5912360ecd4099fb2af60c81dce7342..c3667fe099c58023fb427b54bf7074908e2a8066 100644 (file)
@@ -72,6 +72,7 @@
 
 class BaseRemoteGDB;
 class GDBListener;
+class KvmVM;
 class ObjectFile;
 class ThreadContext;
 
@@ -249,6 +250,14 @@ class System : public MemObject
     Addr loadAddrOffset;
 
   public:
+    /**
+     * Get a pointer to the Kernel Virtual Machine (KVM) SimObject,
+     * if present.
+     */
+    KvmVM* getKvmVM() {
+        return kvmVM;
+    }
+
     /** Get a pointer to access the physical memory of the system */
     PhysicalMemory& getPhysMem() { return physmem; }
 
@@ -289,6 +298,8 @@ class System : public MemObject
 
   protected:
 
+    KvmVM *const kvmVM;
+
     PhysicalMemory physmem;
 
     Enums::MemoryMode memoryMode;