From 1ed159489d11ea4cb48e02a685876e7f8cab113e Mon Sep 17 00:00:00 2001 From: Matheus Date: Mon, 5 Oct 2026 23:57:01 -0300 Subject: [PATCH] scheduler: only run load balance when appropriate Prevent the load balancer from balancing when running uniprocessor machines and when not all CPUs are online yet. This prevents a race between ap initialization and load balancing. --- kernel-src/sys/scheduler/queue.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/kernel-src/sys/scheduler/queue.c b/kernel-src/sys/scheduler/queue.c index 5fd352bd..3641f331 100644 --- a/kernel-src/sys/scheduler/queue.c +++ b/kernel-src/sys/scheduler/queue.c @@ -353,7 +353,9 @@ void sched_calendar_tick(context_t *, dpcarg_t) { // note that there has to be a migrateable thread for this to be possible. // (so if a thread targets the cpu it is ignored in the count) void sched_load_balancer(context_t *, dpcarg_t) { - if (!smp_cpus) + size_t cpu_count = arch_smp_get_cpu_count(); + if (cpu_count < 2 || + __atomic_load_n(&arch_smp_cpusawake, __ATOMIC_ACQUIRE) != cpu_count) return; interrupt_set(false);