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 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/52495 Maintainer: Gabe Black <gabe.black@gmail.com> Reviewed-by: Gabe Black <gabe.black@gmail.com> Reviewed-by: Andreas Sandberg <andreas.sandberg@arm.com> Tested-by: kokoro <noreply+kokoro@google.com> Maintainer: Andreas Sandberg <andreas.sandberg@arm.com>
This commit is contained in:
@@ -37,22 +37,20 @@
|
||||
|
||||
Import('*')
|
||||
|
||||
import platform
|
||||
host_isa = platform.machine()
|
||||
|
||||
if not (env['CONF']['USE_KVM'] and env['CONF']['KVM_ISA'] == 'arm'):
|
||||
Return()
|
||||
if env['CONF']['KVM_ISA'] == 'arm':
|
||||
import platform
|
||||
host_isa = platform.machine()
|
||||
env.TagImplies(f'{host_isa} kvm', 'arm kvm')
|
||||
|
||||
SimObject('KvmGic.py',
|
||||
sim_objects=['MuxingKvmGicV2', 'MuxingKvmGicV3'], tags='arm isa')
|
||||
Source('gic.cc', tags='arm isa')
|
||||
sim_objects=['MuxingKvmGicV2', 'MuxingKvmGicV3'], tags='arm kvm')
|
||||
Source('gic.cc', tags='arm kvm')
|
||||
|
||||
SimObject('BaseArmKvmCPU.py', sim_objects=['BaseArmKvmCPU'], tags='arm isa')
|
||||
Source('base_cpu.cc', tags='arm isa')
|
||||
SimObject('BaseArmKvmCPU.py', sim_objects=['BaseArmKvmCPU'], tags='arm kvm')
|
||||
Source('base_cpu.cc', tags='arm kvm')
|
||||
|
||||
if host_isa == "armv7l":
|
||||
SimObject('ArmKvmCPU.py', sim_objects=['ArmKvmCPU'], tags='arm isa')
|
||||
Source('arm_cpu.cc', tags='arm isa')
|
||||
elif host_isa == "aarch64":
|
||||
SimObject('ArmV8KvmCPU.py', sim_objects=['ArmV8KvmCPU'], tags='arm isa')
|
||||
Source('armv8_cpu.cc', tags='arm isa')
|
||||
SimObject('ArmKvmCPU.py', sim_objects=['ArmKvmCPU'], tags='armv71 kvm')
|
||||
Source('arm_cpu.cc', tags='armv71 kvm')
|
||||
|
||||
SimObject('ArmV8KvmCPU.py', sim_objects=['ArmV8KvmCPU'], tags='aarch64 kvm')
|
||||
Source('armv8_cpu.cc', tags='aarch64 kvm')
|
||||
|
||||
36
src/arch/arm/kvm/SConsopts
Normal file
36
src/arch/arm/kvm/SConsopts
Normal file
@@ -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['CONF']['KVM_ISA'] = 'arm'
|
||||
@@ -37,8 +37,5 @@
|
||||
|
||||
Import('*')
|
||||
|
||||
if not env['CONF']['USE_KVM'] or env['CONF']['KVM_ISA'] != 'x86':
|
||||
Return()
|
||||
|
||||
SimObject('X86KvmCPU.py', sim_objects=['X86KvmCPU'], tags='x86 isa')
|
||||
Source('x86_cpu.cc', tags='x86 isa')
|
||||
SimObject('X86KvmCPU.py', sim_objects=['X86KvmCPU'], tags='x86 kvm')
|
||||
Source('x86_cpu.cc', tags='x86 kvm')
|
||||
|
||||
45
src/arch/x86/kvm/SConsopts
Normal file
45
src/arch/x86/kvm/SConsopts
Normal file
@@ -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['CONF']['KVM_ISA'] = 'x86'
|
||||
else:
|
||||
warning("KVM on x86 requires xsave support in kernel headers.")
|
||||
@@ -37,29 +37,27 @@
|
||||
|
||||
Import('*')
|
||||
|
||||
if not env['CONF']['USE_KVM']:
|
||||
Return()
|
||||
if env['CONF']['USE_KVM']:
|
||||
env.TagImplies('kvm', 'gem5 lib')
|
||||
env.TagImplies(env.subst('${CONF["KVM_ISA"]} kvm'),
|
||||
env.subst('${CONF["KVM_ISA"]} isa'))
|
||||
|
||||
kvm_isa = env['CONF']['KVM_ISA']
|
||||
if not env['CONF'][f'USE_{kvm_isa.upper()}_ISA']:
|
||||
Return()
|
||||
SimObject('KvmVM.py', sim_objects=['KvmVM'], tags='kvm')
|
||||
SimObject('BaseKvmCPU.py', sim_objects=['BaseKvmCPU'], tags='kvm')
|
||||
|
||||
SimObject('KvmVM.py', sim_objects=['KvmVM'])
|
||||
SimObject('BaseKvmCPU.py', sim_objects=['BaseKvmCPU'])
|
||||
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')
|
||||
|
||||
Source('base.cc')
|
||||
Source('device.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')
|
||||
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')
|
||||
|
||||
@@ -28,39 +28,29 @@ Import('*')
|
||||
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='')
|
||||
|
||||
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.
|
||||
# The default value of KVM_ISA should serialize to a string in the
|
||||
# C++ header and test False in Scons/Python.
|
||||
conf.env['CONF']['KVM_ISA'] = ''
|
||||
# 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['CONF']['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['CONF']['KVM_ISA'] = 'x86'
|
||||
else:
|
||||
warning("KVM on x86 requires xsave support in kernel headers.")
|
||||
elif host_isa in ('armv7l', 'aarch64'):
|
||||
conf.env['CONF']['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['CONF']['HAVE_KVM'] = True
|
||||
|
||||
if conf.env['CONF']['KVM_ISA']:
|
||||
# Check if the exclude_host attribute is available. We want this to
|
||||
# get accurate instruction counts in KVM.
|
||||
conf.env['CONF']['HAVE_PERF_ATTR_EXCLUDE_HOST'] = conf.CheckMember(
|
||||
@@ -71,9 +61,13 @@ with gem5_scons.Configure(main) as conf:
|
||||
warning("perf_event headers lack support for the exclude_host "
|
||||
"attribute. KVM instruction counts will be inaccurate.")
|
||||
|
||||
if main['CONF']['KVM_ISA']:
|
||||
sticky_vars.Add(BoolVariable('USE_KVM',
|
||||
'Enable hardware virtualized (KVM) CPU models', True))
|
||||
else:
|
||||
main['CONF']['USE_KVM'] = False
|
||||
warning("Can not enable KVM, host seems to lack KVM support")
|
||||
|
||||
def create_use_kvm_var():
|
||||
if main['CONF']['HAVE_KVM'] and main['CONF']['KVM_ISA']:
|
||||
sticky_vars.Add(BoolVariable('USE_KVM',
|
||||
'Enable hardware virtualized (KVM) CPU models', True))
|
||||
else:
|
||||
main['CONF']['USE_KVM'] = False
|
||||
warning("Cannot enable KVM, host seems to lack KVM support")
|
||||
|
||||
AfterSConsopts(create_use_kvm_var)
|
||||
|
||||
Reference in New Issue
Block a user