Gabe Black has uploaded this change for review. (
https://gem5-review.googlesource.com/c/public/gem5/+/52495 )
Change subject: arch,cpu: Distribute KVM checks and get rid of ISA switch
statement.
......................................................................
arch,cpu: Distribute KVM checks and get rid of ISA switch statement.
Because tags don't work properly on SimObject()s right now (which will
be fixed by my SCons series), there are extra checks which manually
exclude files that should be excluded by their tags automatically.
Change-Id: Idb110269d6400ae6892eac994e673121e49b937c
---
A src/arch/x86/kvm/SConsopts
M src/cpu/kvm/SConsopts
M src/arch/x86/kvm/SConscript
A src/arch/arm/kvm/SConsopts
M src/arch/arm/kvm/SConscript
M src/cpu/kvm/SConscript
6 files changed, 159 insertions(+), 80 deletions(-)
diff --git a/src/arch/arm/kvm/SConscript b/src/arch/arm/kvm/SConscript
index 3adb45c..6a89be2 100644
--- a/src/arch/arm/kvm/SConscript
+++ b/src/arch/arm/kvm/SConscript
@@ -37,21 +37,26 @@
Import('*')
-import platform
-host_isa = platform.machine()
+if env['KVM_ISA'] == 'arm':
+ import platform
+ host_isa = platform.machine()
+ env.TagImplies(f'{host_isa} kvm', 'arm kvm')
-if not (env['USE_KVM'] and env['KVM_ISA'] == 'arm'):
- Return()
+if env['USE_KVM'] and env['KVM_ISA'] == 'arm':
+ SimObject('KvmGic.py', tags='arm kvm')
+Source('gic.cc', tags='arm kvm')
-SimObject('KvmGic.py', tags='arm isa')
-Source('gic.cc', tags='arm isa')
+if env['USE_KVM'] and env['KVM_ISA'] == 'arm':
+ SimObject('BaseArmKvmCPU.py', tags='arm kvm')
+Source('base_cpu.cc', tags='arm kvm')
-SimObject('BaseArmKvmCPU.py', tags='arm isa')
-Source('base_cpu.cc', tags='arm isa')
-if host_isa == "armv7l":
- SimObject('ArmKvmCPU.py', tags='arm isa')
- Source('arm_cpu.cc', tags='arm isa')
-elif host_isa == "aarch64":
- SimObject('ArmV8KvmCPU.py', tags='arm isa')
- Source('armv8_cpu.cc', tags='arm isa')
+if env['USE_KVM'] and env['KVM_ISA'] == 'arm' and \
+ platform.machine() == 'armv71':
+ SimObject('ArmKvmCPU.py', tags='armv71 kvm')
+Source('arm_cpu.cc', tags='armv71 kvm')
+
+if env['USE_KVM'] and env['KVM_ISA'] == 'arm' and \
+ platform.machine() == 'aarch64':
+ SimObject('ArmV8KvmCPU.py', tags='aarch64 kvm')
+Source('armv8_cpu.cc', tags='aarch64 kvm')
diff --git a/src/arch/arm/kvm/SConsopts b/src/arch/arm/kvm/SConsopts
new file mode 100644
index 0000000..3859ad1
--- /dev/null
+++ b/src/arch/arm/kvm/SConsopts
@@ -0,0 +1,36 @@
+# Copyright 2021 Google, Inc.
+#
+# 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.
+
+Import('*')
+
+host_isa = None
+try:
+ import platform
+ host_isa = platform.machine()
+except:
+ pass
+
+if host_isa in ('armv7l', 'aarch64'):
+ main['KVM_ISA'] = 'arm'
diff --git a/src/arch/x86/kvm/SConscript b/src/arch/x86/kvm/SConscript
index 56f85ad..de59a9c 100644
--- a/src/arch/x86/kvm/SConscript
+++ b/src/arch/x86/kvm/SConscript
@@ -37,8 +37,5 @@
Import('*')
-if not env['USE_KVM'] or env['KVM_ISA'] != 'x86':
- Return()
-
-SimObject('X86KvmCPU.py', tags='x86 isa')
-Source('x86_cpu.cc', tags='x86 isa')
+SimObject('X86KvmCPU.py', tags='x86 kvm')
+Source('x86_cpu.cc', tags='x86 kvm')
diff --git a/src/arch/x86/kvm/SConsopts b/src/arch/x86/kvm/SConsopts
new file mode 100644
index 0000000..563569f
--- /dev/null
+++ b/src/arch/x86/kvm/SConsopts
@@ -0,0 +1,45 @@
+# Copyright 2021 Google, Inc.
+#
+# 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.
+
+Import('*')
+
+from gem5_scons import warning
+
+import gem5_scons
+
+host_isa = None
+try:
+ import platform
+ host_isa = platform.machine()
+except:
+ pass
+
+if host_isa == 'x86_64':
+ with gem5_scons.Configure(main) as conf:
+ if conf.CheckTypeSize('struct kvm_xsave',
+ '#include <linux/kvm.h>') != 0:
+ conf.env['KVM_ISA'] = 'x86'
+ else:
+ warning("KVM on x86 requires xsave support in kernel headers.")
diff --git a/src/cpu/kvm/SConscript b/src/cpu/kvm/SConscript
index 54ff52f..29c78a2 100644
--- a/src/cpu/kvm/SConscript
+++ b/src/cpu/kvm/SConscript
@@ -37,39 +37,27 @@
Import('*')
-if env['USE_ARM']:
- isa = 'arm'
-elif env['USE_MIPS']:
- isa = 'mips'
-elif env['USE_POWER']:
- isa = 'power'
-elif env['USE_RISCV']:
- isa = 'riscv'
-elif env['USE_SPARC']:
- isa = 'sparc'
-elif env['USE_X86']:
- isa = 'x86'
-elif env['USE_NULL']:
- isa = 'null'
-if not env['USE_KVM'] or isa != env['KVM_ISA']:
- Return()
+if env['USE_KVM']:
+ env.TagImplies('kvm', 'gem5 lib')
+ env.TagImplies(env.subst('${KVM_ISA} kvm'), 'kvm')
-SimObject('KvmVM.py')
-SimObject('BaseKvmCPU.py')
+if env['USE_KVM']:
+ SimObject('KvmVM.py', tags='kvm')
+ SimObject('BaseKvmCPU.py', tags='kvm')
-Source('base.cc')
-Source('device.cc')
-Source('vm.cc')
-Source('perfevent.cc')
-Source('timer.cc')
+Source('base.cc', tags='kvm')
+Source('device.cc', tags='kvm')
+Source('vm.cc', tags='kvm')
+Source('perfevent.cc', tags='kvm')
+Source('timer.cc', tags='kvm')
-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')
+DebugFlag('Kvm', 'Basic KVM Functionality', tags='kvm')
+DebugFlag('KvmContext', 'KVM/gem5 context synchronization', tags='kvm')
+DebugFlag('KvmIO', 'KVM MMIO diagnostics', tags='kvm')
+DebugFlag('KvmInt', 'KVM Interrupt handling', tags='kvm')
+DebugFlag('KvmRun', 'KvmRun entry/exit diagnostics', tags='kvm')
+DebugFlag('KvmTimer', 'KVM timing', tags='kvm')
CompoundFlag('KvmAll', [ 'Kvm', 'KvmContext', 'KvmRun',
'KvmIO', 'KvmInt', 'KvmTimer' ],
- 'All KVM debug flags')
+ 'All KVM debug flags', tags='kvm')
diff --git a/src/cpu/kvm/SConsopts b/src/cpu/kvm/SConsopts
index 4117736..f975bd6 100644
--- a/src/cpu/kvm/SConsopts
+++ b/src/cpu/kvm/SConsopts
@@ -28,37 +28,29 @@
from gem5_scons import warning
import gem5_scons
-host_isa = None
-try:
- import platform
- host_isa = platform.machine()
-except:
- pass
+
+# ISA code can set this to indicate what ISA KVM can target.
+main.SetDefault(KVM_ISA=None)
with gem5_scons.Configure(main) as conf:
- # Check if we should enable KVM-based hardware virtualization. The API
- # we rely on exists since version 2.6.36 of the kernel, but somehow
- # the KVM_API_VERSION does not reflect the change. We test for one of
- # the types as a fall back.
- conf.env['KVM_ISA'] = None
+ # Check if we should enable KVM-based hardware virtualization. The
+ # API we rely on exists since version 2.6.36 of the kernel, but
+ # somehow the KVM_API_VERSION does not reflect the change. We test
+ # for one of the types as a fall back.
+
+ main['HAVE_KVM'] = False
+
if not conf.CheckHeader('linux/kvm.h', '<>'):
- print("Info: Compatible header file <linux/kvm.h> not found, "
- "disabling KVM support.")
+ warning("Info: Compatible header file <linux/kvm.h> not found, "
+ "disabling KVM support.")
elif not conf.CheckLibWithHeader([None, 'rt'], [ 'time.h', 'signal.h'
],
'C', 'timer_create(CLOCK_MONOTONIC, NULL, NULL);'):
warning("Cannot enable KVM, host doesn't support POSIX timers")
- elif host_isa == 'x86_64':
- if conf.CheckTypeSize('struct kvm_xsave',
- '#include <linux/kvm.h>') != 0:
- conf.env['KVM_ISA'] = 'x86'
- else:
- warning("KVM on x86 requires xsave support in kernel headers.")
- elif host_isa in ('armv7l', 'aarch64'):
- conf.env['KVM_ISA'] = 'arm'
else:
- warning("Failed to determine host ISA.")
+ # Generic support is available. We'll let the ISAs figure out if
+ # it's really supported.
+ conf.env['HAVE_KVM'] = True
- if conf.env['KVM_ISA']:
# Check if the exclude_host attribute is available. We want this to
# get accurate instruction counts in KVM.
conf.env['HAVE_PERF_ATTR_EXCLUDE_HOST'] = conf.CheckMember(
@@ -69,13 +61,16 @@
warning("perf_event headers lack support for the exclude_host "
"attribute. KVM instruction counts will be
inaccurate.")
- export_vars.append('HAVE_PERF_ATTR_EXCLUDE_HOST')
+ export_vars.append('HAVE_PERF_ATTR_EXCLUDE_HOST')
-if main['KVM_ISA']:
- sticky_vars.Add(BoolVariable('USE_KVM',
- 'Enable hardware virtualized (KVM) CPU models', True))
-else:
- main['USE_KVM'] = False
- warning("Can not enable KVM, host seems to lack KVM support")
+def create_use_kvm_var():
+ if main['HAVE_KVM'] and main['KVM_ISA'] is not None:
+ sticky_vars.Add(BoolVariable('USE_KVM',
+ 'Enable hardware virtualized (KVM) CPU models', True))
+ else:
+ main['USE_KVM'] = False
+ warning("Cannot enable KVM, host seems to lack KVM support")
-export_vars.append('USE_KVM')
+ export_vars.append('USE_KVM')
+
+AfterSConsopts(create_use_kvm_var)
--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/52495
To unsubscribe, or for help writing mail filters, visit
https://gem5-review.googlesource.com/settings
Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: Idb110269d6400ae6892eac994e673121e49b937c
Gerrit-Change-Number: 52495
Gerrit-PatchSet: 1
Gerrit-Owner: Gabe Black <[email protected]>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s