[kvm-unit-tests PATCH v4 4/5] configure: Add --target-cpu option
Jean-Philippe Brucker
jean-philippe at linaro.org
Tue Apr 8 06:20:53 PDT 2025
Add the --target-cpu option to let users set the CPU type to run on.
At the moment --processor allows to set both GCC -mcpu flag and QEMU
-cpu. On Arm we'd like to pass `-cpu max` to QEMU in order to enable all
the TCG features by default, and it could also be nice to let users
modify the CPU capabilities by setting extra -cpu options. Since GCC
-mcpu doesn't accept "max" or "host", separate the compiler and QEMU
arguments.
`--processor` is now exclusively for compiler options, as indicated by
its documentation ("processor to compile for"). So use $TARGET_CPU on
RISC-V as well.
Suggested-by: Andrew Jones <andrew.jones at linux.dev>
Signed-off-by: Jean-Philippe Brucker <jean-philippe at linaro.org>
---
scripts/mkstandalone.sh | 3 ++-
arm/run | 15 +++++++++------
riscv/run | 8 ++++----
configure | 27 +++++++++++++++++++++++++++
4 files changed, 42 insertions(+), 11 deletions(-)
diff --git a/scripts/mkstandalone.sh b/scripts/mkstandalone.sh
index 2318a85f..c4ba81f1 100755
--- a/scripts/mkstandalone.sh
+++ b/scripts/mkstandalone.sh
@@ -42,7 +42,8 @@ generate_test ()
config_export ARCH
config_export ARCH_NAME
- config_export PROCESSOR
+ config_export TARGET_CPU
+ config_export DEFAULT_QEMU_CPU
echo "echo BUILD_HEAD=$(cat build-head)"
diff --git a/arm/run b/arm/run
index efdd44ce..ef585582 100755
--- a/arm/run
+++ b/arm/run
@@ -8,7 +8,7 @@ if [ -z "$KUT_STANDALONE" ]; then
source config.mak
source scripts/arch-run.bash
fi
-processor="$PROCESSOR"
+qemu_cpu="$TARGET_CPU"
if [ "$QEMU" ] && [ -z "$ACCEL" ] &&
[ "$HOST" = "aarch64" ] && [ "$ARCH" = "arm" ] &&
@@ -37,12 +37,15 @@ if [ "$ACCEL" = "kvm" ]; then
fi
fi
-if [ "$ACCEL" = "kvm" ] || [ "$ACCEL" = "hvf" ]; then
- if [ "$HOST" = "aarch64" ] || [ "$HOST" = "arm" ]; then
- processor="host"
+if [ -z "$qemu_cpu" ]; then
+ if ( [ "$ACCEL" = "kvm" ] || [ "$ACCEL" = "hvf" ] ) &&
+ ( [ "$HOST" = "aarch64" ] || [ "$HOST" = "arm" ] ); then
+ qemu_cpu="host"
if [ "$ARCH" = "arm" ] && [ "$HOST" = "aarch64" ]; then
- processor+=",aarch64=off"
+ qemu_cpu+=",aarch64=off"
fi
+ else
+ qemu_cpu="$DEFAULT_QEMU_CPU"
fi
fi
@@ -71,7 +74,7 @@ if $qemu $M -device '?' | grep -q pci-testdev; then
fi
A="-accel $ACCEL$ACCEL_PROPS"
-command="$qemu -nodefaults $M $A -cpu $processor $chr_testdev $pci_testdev"
+command="$qemu -nodefaults $M $A -cpu $qemu_cpu $chr_testdev $pci_testdev"
command+=" -display none -serial stdio"
command="$(migration_cmd) $(timeout_cmd) $command"
diff --git a/riscv/run b/riscv/run
index e2f5a922..2bd42ad8 100755
--- a/riscv/run
+++ b/riscv/run
@@ -11,12 +11,12 @@ fi
# Allow user overrides of some config.mak variables
mach=$MACHINE_OVERRIDE
-processor=$PROCESSOR_OVERRIDE
+qemu_cpu=$QEMU_CPU_OVERRIDE
firmware=$FIRMWARE_OVERRIDE
-[ "$PROCESSOR" = "$ARCH" ] && PROCESSOR="max"
: "${mach:=virt}"
-: "${processor:=$PROCESSOR}"
+: "${qemu_cpu:=$TARGET_CPU}"
+: "${qemu_cpu:=$DEFAULT_QEMU_CPU}"
: "${firmware:=$FIRMWARE}"
[ "$firmware" ] && firmware="-bios $firmware"
@@ -32,7 +32,7 @@ fi
mach="-machine $mach"
command="$qemu -nodefaults -nographic -serial mon:stdio"
-command+=" $mach $acc $firmware -cpu $processor "
+command+=" $mach $acc $firmware -cpu $qemu_cpu "
command="$(migration_cmd) $(timeout_cmd) $command"
if [ "$UEFI_SHELL_RUN" = "y" ]; then
diff --git a/configure b/configure
index b4875ef3..63367bbc 100755
--- a/configure
+++ b/configure
@@ -23,6 +23,24 @@ function get_default_processor()
esac
}
+# Return the default CPU type to run on
+function get_default_qemu_cpu()
+{
+ local arch="$1"
+
+ case "$arch" in
+ "arm")
+ echo "cortex-a15"
+ ;;
+ "arm64")
+ echo "cortex-a57"
+ ;;
+ "riscv32" | "riscv64")
+ echo "max"
+ ;;
+ esac
+}
+
srcdir=$(cd "$(dirname "$0")"; pwd)
prefix=/usr/local
cc=gcc
@@ -52,6 +70,7 @@ earlycon=
console=
efi=
efi_direct=
+target_cpu=
# Enable -Werror by default for git repositories only (i.e. developer builds)
if [ -e "$srcdir"/.git ]; then
@@ -70,6 +89,9 @@ usage() {
--arch=ARCH architecture to compile for ($arch). ARCH can be one of:
arm, arm64, i386, ppc64, riscv32, riscv64, s390x, x86_64
--processor=PROCESSOR processor to compile for ($processor)
+ --target-cpu=CPU the CPU model to run on. If left unset, the run script
+ selects the best value based on the host system and the
+ test configuration.
--target=TARGET target platform that the tests will be running on (qemu or
kvmtool, default is qemu) (arm/arm64 only)
--cross-prefix=PREFIX cross compiler prefix
@@ -146,6 +168,9 @@ while [[ $optno -le $argc ]]; do
--processor)
processor="$arg"
;;
+ --target-cpu)
+ target_cpu="$arg"
+ ;;
--target)
target="$arg"
;;
@@ -471,6 +496,8 @@ ARCH=$arch
ARCH_NAME=$arch_name
ARCH_LIBDIR=$arch_libdir
PROCESSOR=$processor
+TARGET_CPU=$target_cpu
+DEFAULT_QEMU_CPU=$(get_default_qemu_cpu $arch)
CC=$cc
CFLAGS=$cflags
LD=$cross_prefix$ld
--
2.49.0
More information about the kvm-riscv
mailing list