From 504f6e1f42185c794d05dc2f2750173705a0bfd4 Mon Sep 17 00:00:00 2001 From: bjs Date: Sun, 19 May 2024 16:10:11 +0000 Subject: [PATCH] (lib/setup) replace some hardcoded 4 with (MAX|NO)_CPUS --- inc/thread_info.h | 2 +- lib/arch/cpu_boot.c | 2 +- lib/litmus_test/litmus_test.c | 2 +- lib/setup.c | 11 ++++++----- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/inc/thread_info.h b/inc/thread_info.h index b0460fc..1c88c1d 100644 --- a/inc/thread_info.h +++ b/inc/thread_info.h @@ -21,7 +21,7 @@ typedef struct struct arm_implementation impl; } thread_info_t; -extern thread_info_t thread_infos[4]; +extern thread_info_t thread_infos[MAX_CPUS]; u64 get_cpu(void); u64 get_vcpu(void); diff --git a/lib/arch/cpu_boot.c b/lib/arch/cpu_boot.c index 15e7356..423cec6 100644 --- a/lib/arch/cpu_boot.c +++ b/lib/arch/cpu_boot.c @@ -9,7 +9,7 @@ thread_info_t* current_thread_info() { } void cpu_data_init(void) { - for (int i = 0; i < 4; i++) { + for (int i = 0; i < MAX_CPUS; i++) { cpu_data[i].started = 0; cpu_data[i].to_execute = 0; } diff --git a/lib/litmus_test/litmus_test.c b/lib/litmus_test/litmus_test.c index e657a65..8718c7e 100644 --- a/lib/litmus_test/litmus_test.c +++ b/lib/litmus_test/litmus_test.c @@ -39,7 +39,7 @@ void run_test(const litmus_test_t* cfg) { /* run it */ if (TRACE) { printf("#"); - for (int i = 0; i < 4; i++) { + for (int i = 0; i < NO_CPUS; i++) { printf("P%d\t\t\t", i); } printf("\n"); diff --git a/lib/setup.c b/lib/setup.c index a35209f..0e949e8 100644 --- a/lib/setup.c +++ b/lib/setup.c @@ -1,12 +1,13 @@ #include +#include "device.h" #include "vmm.h" extern u64 __argc; extern char* __argv[100]; /* per-thread boot data */ -cpu_data_t cpu_data[4]; +cpu_data_t cpu_data[MAX_CPUS]; /** setup is called very early * before the UART is enabled @@ -209,12 +210,12 @@ void ensure_cpus_on(void) { per_cpu_setup(0); debug("booting all CPUs ...\n"); - cpu_boot(1); - cpu_boot(2); - cpu_boot(3); + for (int i = 1; i < NO_CPUS; i++) { + cpu_boot(i); + } debug("started boot.\n"); - for (int i = 0; i < 4; i++) { + for (int i = 0; i < NO_CPUS; i++) { while (!cpu_data[i].started) wfe(); }