changeset f551c8ad12a5 in /z/repo/gem5
details: http://repo.gem5.org/gem5?cmd=changeset;node=f551c8ad12a5
description:
        kvm: Basic support for hardware virtualized CPUs

        This changeset introduces the architecture independent parts required
        to support KVM-accelerated CPUs. It introduces two new simulation
        objects:

        KvmVM -- The KVM VM is a component shared between all CPUs in a shared
                 memory domain. It is typically instantiated as a child of the
                 system object in the simulation hierarchy. It provides access
                 to KVM VM specific interfaces.

        BaseKvmCPU -- Abstract base class for all KVM-based CPUs. Architecture
                      dependent CPU implementations inherit from this class
                      and implement the following methods:

                        * updateKvmState() -- Update the
                          architecture-dependent KVM state from the gem5
                          thread context associated with the CPU.

                        * updateThreadContext() -- Update the thread context
                          from the architecture-dependent KVM state.

                        * dump() -- Dump the KVM state using (optional).

                      In order to deliver interrupts to the guest, CPU
                      implementations typically override the tick() method and
                      check for, and deliver, interrupts prior to entering
                      KVM.

        Hardware-virutalized CPU currently have the following limitations:
         * SE mode is not supported.
         * PC events are not supported.
         * Timing statistics are currently very limited. The current approach
           simply scales the host cycles with a user-configurable factor.
         * The simulated system must not contain any caches.
         * Since cycle counts are approximate, there is no way to request an
           exact number of cycles (or instructions) to be executed by the CPU.
         * Hardware virtualized CPUs and gem5 CPUs must not execute at the
           same time in the same simulator instance.
         * Only single-CPU systems can be simulated.
         * Remote GDB connections to the guest system are not supported.

        Additionally, m5ops requires an architecture specific interface and
        might not be supported.

diffstat:

 SConstruct                |   30 +
 src/cpu/kvm/BaseKvmCPU.py |   72 ++++
 src/cpu/kvm/KvmVM.py      |   49 ++
 src/cpu/kvm/SConscript    |   60 +++
 src/cpu/kvm/base.cc       |  805 ++++++++++++++++++++++++++++++++++++++++++++++
 src/cpu/kvm/base.hh       |  489 +++++++++++++++++++++++++++
 src/cpu/kvm/perfevent.cc  |  246 ++++++++++++++
 src/cpu/kvm/perfevent.hh  |  347 +++++++++++++++++++
 src/cpu/kvm/timer.cc      |  112 ++++++
 src/cpu/kvm/timer.hh      |  206 +++++++++++
 src/cpu/kvm/vm.cc         |  370 +++++++++++++++++++++
 src/cpu/kvm/vm.hh         |  390 ++++++++++++++++++++++
 12 files changed, 3176 insertions(+), 0 deletions(-)

diffs (truncated from 3244 to 300 lines):

diff -r d79319eb68d5 -r f551c8ad12a5 SConstruct
--- a/SConstruct        Mon Apr 22 13:20:31 2013 -0400
+++ b/SConstruct        Mon Apr 22 13:20:32 2013 -0400
@@ -944,6 +944,26 @@
     print "Warning: Header file <fenv.h> not found."
     print "         This host has no IEEE FP rounding mode control."
 
+# Check if we should enable KVM-based hardware virtualization
+have_kvm = conf.CheckHeader('linux/kvm.h', '<>')
+if not have_kvm:
+    print "Info: Header file <linux/kvm.h> not found, " \
+        "disabling KVM support."
+
+# Check if the requested target ISA is compatible with the host
+def is_isa_kvm_compatible(isa):
+    isa_comp_table = {
+        }
+    try:
+        import platform
+        host_isa = platform.machine()
+    except:
+        print "Warning: Failed to determine host ISA."
+        return False
+
+    return host_isa in isa_comp_table.get(isa, [])
+
+
 ######################################################################
 #
 # Finish the configuration
@@ -1038,6 +1058,7 @@
     BoolVariable('USE_POSIX_CLOCK', 'Use POSIX Clocks', have_posix_clock),
     BoolVariable('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv),
     BoolVariable('CP_ANNOTATE', 'Enable critical path annotation capability', 
False),
+    BoolVariable('USE_KVM', 'Enable hardware virtualized (KVM) CPU models', 
have_kvm),
     EnumVariable('PROTOCOL', 'Coherence protocol for Ruby', 'None',
                   all_protocols),
     )
@@ -1205,6 +1226,15 @@
     if env['EFENCE']:
         env.Append(LIBS=['efence'])
 
+    if env['USE_KVM']:
+        if not have_kvm:
+            print "Warning: Can not enable KVM, host seems to lack KVM support"
+            env['USE_KVM'] = False
+        elif not is_isa_kvm_compatible(env['TARGET_ISA']):
+            print "Info: KVM support disabled due to unsupported host and " \
+                "target ISA combination"
+            env['USE_KVM'] = False
+
     # Save sticky variable settings back to current variables file
     sticky_vars.Save(current_vars_file, env)
 
diff -r d79319eb68d5 -r f551c8ad12a5 src/cpu/kvm/BaseKvmCPU.py
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/src/cpu/kvm/BaseKvmCPU.py Mon Apr 22 13:20:32 2013 -0400
@@ -0,0 +1,72 @@
+# Copyright (c) 2012 ARM Limited
+# All rights reserved.
+#
+# The license below extends only to copyright in the software and shall
+# not be construed as granting a license to any other intellectual
+# property including but not limited to intellectual property relating
+# to a hardware implementation of the functionality of the software
+# licensed hereunder.  You may use the software subject to the license
+# terms below provided that you ensure that this notice is replicated
+# unmodified and in its entirety in all distributions of the software,
+# modified or unmodified, in source code or in binary form.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met: redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer;
+# redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution;
+# neither the name of the copyright holders nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+# Authors: Andreas Sandberg
+
+from m5.params import *
+from m5.proxy import *
+
+from BaseCPU import BaseCPU
+from KvmVM import KvmVM
+
+class BaseKvmCPU(BaseCPU):
+    type = 'BaseKvmCPU'
+    cxx_header = "cpu/kvm/base.hh"
+    abstract = True
+
+    @classmethod
+    def export_method_cxx_predecls(cls, code):
+        code('#include "cpu/kvm/base.hh"')
+
+    @classmethod
+    def export_methods(cls, code):
+        code('''
+      void dump();
+''')
+
+    @classmethod
+    def memory_mode(cls):
+        return 'atomic_noncaching'
+
+    @classmethod
+    def require_caches(cls):
+        return False
+
+    @classmethod
+    def support_take_over(cls):
+        return True
+
+    kvmVM = Param.KvmVM(Parent.any, 'KVM VM (i.e., shared memory domain)')
+    hostFactor = Param.Float(1.0, "Cycle scale factor")
diff -r d79319eb68d5 -r f551c8ad12a5 src/cpu/kvm/KvmVM.py
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/src/cpu/kvm/KvmVM.py      Mon Apr 22 13:20:32 2013 -0400
@@ -0,0 +1,49 @@
+# Copyright (c) 2012 ARM Limited
+# All rights reserved.
+#
+# The license below extends only to copyright in the software and shall
+# not be construed as granting a license to any other intellectual
+# property including but not limited to intellectual property relating
+# to a hardware implementation of the functionality of the software
+# licensed hereunder.  You may use the software subject to the license
+# terms below provided that you ensure that this notice is replicated
+# unmodified and in its entirety in all distributions of the software,
+# modified or unmodified, in source code or in binary form.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met: redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer;
+# redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution;
+# neither the name of the copyright holders nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+# Authors: Andreas Sandberg
+
+from m5.params import *
+from m5.proxy import *
+
+from m5.SimObject import SimObject
+
+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")
diff -r d79319eb68d5 -r f551c8ad12a5 src/cpu/kvm/SConscript
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/src/cpu/kvm/SConscript    Mon Apr 22 13:20:32 2013 -0400
@@ -0,0 +1,60 @@
+# -*- mode:python -*-
+
+# Copyright (c) 2012 ARM Limited
+# All rights reserved.
+#
+# The license below extends only to copyright in the software and shall
+# not be construed as granting a license to any other intellectual
+# property including but not limited to intellectual property relating
+# to a hardware implementation of the functionality of the software
+# licensed hereunder.  You may use the software subject to the license
+# terms below provided that you ensure that this notice is replicated
+# unmodified and in its entirety in all distributions of the software,
+# modified or unmodified, in source code or in binary form.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met: redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer;
+# redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution;
+# neither the name of the copyright holders nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+# Authors: Andreas Sandberg
+
+Import('*')
+
+if env['USE_KVM']:
+    SimObject('KvmVM.py')
+    SimObject('BaseKvmCPU.py')
+
+    Source('base.cc')
+    Source('vm.cc')
+    Source('perfevent.cc')
+    Source('timer.cc')
+
+    DebugFlag('Kvm', 'Basic KVM Functionality')
+    DebugFlag('KvmContext', 'KVM/gem5 context synchronization')
+    DebugFlag('KvmIO', 'KVM MMIO diagnostics')
+    DebugFlag('KvmInt', 'KVM Interrupt handling')
+    DebugFlag('KvmRun', 'KvmRun entry/exit diagnostics')
+    DebugFlag('KvmTimer', 'KVM timing')
+
+    CompoundFlag('KvmAll', [ 'Kvm', 'KvmContext', 'KvmRun',
+                             'KvmIO', 'KvmInt', 'KvmTimer' ],
+                 'All KVM debug flags')
diff -r d79319eb68d5 -r f551c8ad12a5 src/cpu/kvm/base.cc
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/src/cpu/kvm/base.cc       Mon Apr 22 13:20:32 2013 -0400
@@ -0,0 +1,805 @@
+/*
+ * Copyright (c) 2012 ARM Limited
+ * All rights reserved
+ *
+ * The license below extends only to copyright in the software and shall
+ * not be construed as granting a license to any other intellectual
+ * property including but not limited to intellectual property relating
+ * to a hardware implementation of the functionality of the software
+ * licensed hereunder.  You may use the software subject to the license
+ * terms below provided that you ensure that this notice is replicated
+ * unmodified and in its entirety in all distributions of the software,
+ * modified or unmodified, in source code or in binary form.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met: redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer;
+ * redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution;
+ * neither the name of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Authors: Andreas Sandberg
+ */
+
+#include <linux/kvm.h>
+#include <sys/ioctl.h>
+#include <sys/mman.h>
+#include <unistd.h>
+
+#include <cerrno>
+#include <csignal>
+#include <ostream>
+
+#include "arch/utility.hh"
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to