From 066e331200f369c198e0152f0193d6e01185a5e7 Mon Sep 17 00:00:00 2001 From: Nathan Chancellor Date: Fri, 11 Mar 2022 15:17:21 -0700 Subject: [PATCH 1/3] boot-qemu.sh: Clamp '-smp' based on CONFIG_NR_CPUS when available As noted on the review for #17, when booting an i386_defconfig kernel, there is a lot of spam in the boot logs because CONFIG_NR_CPUS is set to 8: [ 0.020644] APIC: NR_CPUS/possible_cpus limit of 8 reached. Processor 8/0x8 ignored. [ 0.021302] APIC: NR_CPUS/possible_cpus limit of 8 reached. Processor 9/0x9 ignored. [ 0.021964] APIC: NR_CPUS/possible_cpus limit of 8 reached. Processor 10/0xa ignored. [ 0.022642] APIC: NR_CPUS/possible_cpus limit of 8 reached. Processor 11/0xb ignored. With large machines, this can be quite noisy, as there is one print out for every CPU above 8. Refactor the logic for finding a sensible value based on CONFIG_NR_CPUS if a config can be found. If no config is available, default to 8, which is the default value for i386_defconfig. Signed-off-by: Nathan Chancellor --- boot-qemu.sh | 46 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/boot-qemu.sh b/boot-qemu.sh index fd402e1..ec81ff0 100755 --- a/boot-qemu.sh +++ b/boot-qemu.sh @@ -111,6 +111,50 @@ function sanity_check() { checkbin zstd } +function get_default_smp_value() { + # KERNEL_LOCATION is either a path to the kernel source or a full kernel + # location. If it is a file, we need to strip off the basename so that we + # can easily navigate around with '..'. + if [[ -f ${KERNEL_LOCATION} ]]; then + KERNEL_DIRNAME=$(dirname "${KERNEL_LOCATION}") + else + KERNEL_DIRNAME=${KERNEL_LOCATION} + fi + + # If KERNEL_LOCATION is the kernel source, the configuration will be at + # ${KERNEL_DIRNAME}/.config + # + # If KERNEL_LOCATION is a full kernel location, it could either be: + # * ${KERNEL_DIRNAME}/.config (if the image is vmlinux) + # * ${KERNEL_DIRNAME}/../../../.config (if the image is in arch/*/boot/) + # * ${KERNEL_DIRNAME}/config (if the image is in a TuxMake folder) + for CONFIG_LOCATION in .config ../../../.config config; do + CONFIG_FILE=$(readlink -f "${KERNEL_DIRNAME}/${CONFIG_LOCATION}") + if [[ -f ${CONFIG_FILE} ]]; then + HAS_CONFIG=true + break + fi + done + + if ${HAS_CONFIG:=false}; then + CONFIG_NR_CPUS=$(grep "^CONFIG_NR_CPUS=" "${CONFIG_FILE}" | cut -d= -f2) + fi + + if [[ -z ${CONFIG_NR_CPUS} ]]; then + # Sensible default value based on treewide defaults for CONFIG_NR_CPUS. + CONFIG_NR_CPUS=8 + fi + + # Use the minimum of the number of processors in the system or + # CONFIG_NR_CPUS. + CPUS=$(nproc) + if [[ ${CPUS} -gt ${CONFIG_NR_CPUS} ]]; then + echo "${CONFIG_NR_CPUS}" + else + echo "${CPUS}" + fi +} + # Boot QEMU function setup_qemu_args() { # All arm32_* options share the same rootfs, under images/arm @@ -297,7 +341,7 @@ function setup_qemu_args() { -cpu host -d "unimp,guest_errors" -enable-kvm - -smp "${SMP:-$(nproc)}" + -smp "${SMP:-$(get_default_smp_value)}" ) else [[ ${ARCH} = "x86_64" ]] && QEMU_ARCH_ARGS=(-cpu Nehalem) From e623485fe68f0a8a15b4022fbaceaa672680d838 Mon Sep 17 00:00:00 2001 From: Nathan Chancellor Date: Fri, 11 Mar 2022 15:19:06 -0700 Subject: [PATCH 2/3] boot-qemu.sh: Use '-smp' for other instances of KVM For both ARCH=arm and ARCH=arm64 defconfig, the default of get_default_smp_value when there is no configuration available will work. Signed-off-by: Nathan Chancellor --- boot-qemu.sh | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/boot-qemu.sh b/boot-qemu.sh index ec81ff0..dfac1a6 100755 --- a/boot-qemu.sh +++ b/boot-qemu.sh @@ -222,6 +222,7 @@ function setup_qemu_args() { QEMU_ARCH_ARGS+=( -cpu "host,aarch64=off" -enable-kvm + -smp "${SMP:-$(get_default_smp_value)}" ) QEMU=(qemu-system-aarch64) else @@ -238,14 +239,19 @@ function setup_qemu_args() { -machine "virt,gic-version=max" ) if [[ "$(uname -m)" = "aarch64" && -e /dev/kvm ]] && ${KVM}; then - QEMU_ARCH_ARGS+=(-enable-kvm) + QEMU_ARCH_ARGS+=( + -enable-kvm + -smp "${SMP:-$(get_default_smp_value)}" + ) else QEMU_ARCH_ARGS+=(-machine "virtualization=true") fi if ${DEBIAN}; then # Booting is so slow without these QEMU_RAM=2G - QEMU_ARCH_ARGS+=(-smp "${SMP:-4}") + if ! echo "${QEMU_ARCH_ARGS[*]}" | grep -q smp; then + QEMU_ARCH_ARGS+=(-smp "${SMP:-4}") + fi fi QEMU=(qemu-system-aarch64) ;; From ff6f235f6667662456a20c008b295934168b81d1 Mon Sep 17 00:00:00 2001 From: Nathan Chancellor Date: Wed, 16 Mar 2022 14:33:37 -0700 Subject: [PATCH 3/3] boot-qemu.sh: Add a few comments in the arm64 Debian block Signed-off-by: Nathan Chancellor --- boot-qemu.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/boot-qemu.sh b/boot-qemu.sh index dfac1a6..074d038 100755 --- a/boot-qemu.sh +++ b/boot-qemu.sh @@ -246,9 +246,13 @@ function setup_qemu_args() { else QEMU_ARCH_ARGS+=(-machine "virtualization=true") fi + # Give the machine more cores and memory when booting Debian to + # improve performance if ${DEBIAN}; then - # Booting is so slow without these QEMU_RAM=2G + # Do not add '-smp' if it is present at this point, as that + # means that KVM is being used, which will already have a + # suitable number of cores if ! echo "${QEMU_ARCH_ARGS[*]}" | grep -q smp; then QEMU_ARCH_ARGS+=(-smp "${SMP:-4}") fi