riscv: Make NR_CPUS configurable
Subsystems (3)
PATCH 1/1 riscv: Make NR_CPUS configurable
Unit tests would like to go nuts with the number of harts in order to help shake out issues with hart number assumptions. Rather than set a huge number that will only be used when a platform supports a huge number or when QEMU is told to exceed the recommended number of vcpus, make the number configurable. However, we do bump the default from 16 to 2*xlen since we would like to always force kvm-unit-tests to use cpumasks with more than one word in order to ensure that code stays maintained.
--- configure | 8 ++++++++ lib/riscv/asm/setup.h | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-)
configure +8 -0
@@ -77,6 +77,8 @@ usage() { Specify the page size (translation granule). PAGE_SIZE can be 4k [default], 16k, 64k for arm64. 4k [default], 64k for ppc64. + --max-cpus=MAX_CPUS + Specify the maximum number of CPUs supported. (riscv64 only) --earlycon=EARLYCON Specify the UART name, type and address (optional, arm and arm64 only). The specified address will overwrite the UART
@@ -168,6 +170,9 @@ while [[ "$1" = -* ]]; do --page-size) page_size="$arg" ;; + --max-cpus) + max_cpus="$arg" + ;; --earlycon) earlycon="$arg" ;;
@@ -496,8 +501,11 @@ cat <<EOF >> lib/config.h EOF elif [ "$arch" = "riscv32" ] || [ "$arch" = "riscv64" ]; then + [ -z $max_cpus ] && max_cpus='(__riscv_xlen * 2)' + cat <<EOF >> lib/config.h +#define CONFIG_NR_CPUS $max_cpus #define CONFIG_UART_EARLY_BASE 0x10000000 EOF
lib/riscv/asm/setup.h +2 -1
@@ -2,9 +2,10 @@#ifndef _ASMRISCV_SETUP_H_#define _ASMRISCV_SETUP_H_#include <libcflat.h> +#include <config.h> #include <asm/processor.h> -#define NR_CPUS 16 +#define NR_CPUS CONFIG_NR_CPUSextern struct thread_info cpus[NR_CPUS ];extern int nr_cpus;extern uint64_t timebase_frequency;
Signature · 1 line
2.45.2
Quoted 69 lines · Andrew Jones
Unit tests would like to go nuts with the number of harts in order to help shake out issues with hart number assumptions. Rather than set a huge number that will only be used when a platform supports a huge number or when QEMU is told to exceed the recommended number of vcpus, make the number configurable. However, we do bump the default from 16 to 2*xlen since we would like to always force kvm-unit-tests to use cpumasks with more than one word in order to ensure that code stays maintained.
Signed-off-by Andrew Jones <[email protected]>--- configure | 8 ++++++++ lib/riscv/asm/setup.h | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-)configure +8
-0@@ -77,6 +77,8 @@ usage() { Specify the page size (translation granule). PAGE_SIZE can be 4k [default], 16k, 64k for arm64. 4k [default], 64k for ppc64. + --max-cpus=MAX_CPUS + Specify the maximum number of CPUs supported. (riscv64 only) --earlycon=EARLYCON Specify the UART name, type and address (optional, arm and arm64 only). The specified address will overwrite the UART@@ -168,6 +170,9 @@ while [[ "$1" = -* ]]; do --page-size) page_size="$arg" ;; + --max-cpus) + max_cpus="$arg" + ;; --earlycon) earlycon="$arg" ;;@@ -496,8 +501,11 @@ cat <<EOF >> lib/config.h EOF elif [ "$arch" = "riscv32" ] || [ "$arch" = "riscv64" ]; then + [ -z $max_cpus ] && max_cpus='(__riscv_xlen * 2)' + cat <<EOF >> lib/config.h +#define CONFIG_NR_CPUS $max_cpus #define CONFIG_UART_EARLY_BASE 0x10000000 EOFlib/riscv/asm/setup.h +2
-1@@ -2,9 +2,10 @@#ifndef _ASMRISCV_SETUP_H_#define _ASMRISCV_SETUP_H_#include <libcflat.h> +#include <config.h> #include <asm/processor.h> -#define NR_CPUS 16 +#define NR_CPUS CONFIG_NR_CPUSextern struct thread_info cpus[NR_CPUS ];extern int nr_cpus;extern uint64_t timebase_frequency;Signature · 1 line
2.45.2
I started having second thoughts about this approach since we'll have to keep adding configure command line options for every CONFIG option. I posted an alternative approach now [1] and CC'ed everyone since other architectures should chime in on the approach too.
[1] https://lore.kernel.org/all/20240903143946.834864-4-andrew.jones at linux.dev/
Thanks,
drew