From ff78793540463f2836e39af9d1c6421bbcb85081 Mon Sep 17 00:00:00 2001 From: Adriano Vero Date: Tue, 7 Apr 2026 09:45:34 +0200 Subject: [PATCH] riscv: Add WFI to secondary hart spinwait loop The .Lwait_for_cpu_up loop in the RISCV_BOOT_SPINWAIT path busy-polls __cpu_spinwait_stack_pointer and __cpu_spinwait_task_pointer, burning power on all non-boot harts while they wait for the primary hart to complete early boot setup. Add a WFI instruction before each polling iteration to allow the hardware to enter a low-power state while waiting. Per the RISC-V privileged specification, WFI wakes on any pending interrupt even with global interrupts disabled (SIE=0), and implementations are permitted to treat it as a NOP, so this is safe in all contexts. The same pattern is already used in .Lsecondary_park in the same file. Signed-off-by: Adriano Vero Signed-off-by: Linux RISC-V bot --- arch/riscv/kernel/head.S | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/arch/riscv/kernel/head.S b/arch/riscv/kernel/head.S index 9c99c5ad6fe8a3..ca208da7c29941 100644 --- a/arch/riscv/kernel/head.S +++ b/arch/riscv/kernel/head.S @@ -385,7 +385,14 @@ SYM_CODE_START(_start_kernel) * get far enough along the boot process that it should continue. */ .Lwait_for_cpu_up: - /* FIXME: We should WFI to save some energy here. */ + /* + * Wait for the boot hart to populate the stack and task pointers. + * Use WFI to avoid burning power in a busy-wait loop. Per the + * RISC-V privileged spec, WFI wakes on a pending interrupt even + * with global interrupts disabled (e.g. SIE=0), and implementations + * are permitted to treat it as a NOP, so this is always safe. + */ + wfi REG_L sp, (a1) REG_L tp, (a2) beqz sp, .Lwait_for_cpu_up