From: Nam Cao <namcao@linutronix.de>
To: Adriano Vero <litaliano00.contact@gmail.com>,
palmer@dabbelt.com, pjw@kernel.org, aou@eecs.berkeley.edu
Cc: alex@ghiti.fr, linux-riscv@lists.infradead.org,
linux-kernel@vger.kernel.org,
Adriano Vero <litaliano00.contact@gmail.com>
Subject: Re: [PATCH] riscv: Add WFI to secondary hart spinwait loop
Date: Tue, 07 Apr 2026 10:40:17 +0200 [thread overview]
Message-ID: <87pl4bw4cu.fsf@yellow.woof> (raw)
In-Reply-To: <20260407074534.59179-1-litaliano00.contact@gmail.com>
Adriano Vero <litaliano00.contact@gmail.com> writes:
> 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 <litaliano00.contact@gmail.com>
> ---
> 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 9c99c5ad6..ca208da7c 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
> --
> 2.53.0
>
>
> _______________________________________________
> linux-riscv mailing list
> linux-riscv@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-riscv
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
WARNING: multiple messages have this Message-ID (diff)
From: Nam Cao <namcao@linutronix.de>
To: Adriano Vero <litaliano00.contact@gmail.com>,
palmer@dabbelt.com, pjw@kernel.org, aou@eecs.berkeley.edu
Cc: alex@ghiti.fr, linux-riscv@lists.infradead.org,
linux-kernel@vger.kernel.org,
Adriano Vero <litaliano00.contact@gmail.com>
Subject: Re: [PATCH] riscv: Add WFI to secondary hart spinwait loop
Date: Tue, 07 Apr 2026 10:40:17 +0200 [thread overview]
Message-ID: <87pl4bw4cu.fsf@yellow.woof> (raw)
In-Reply-To: <20260407074534.59179-1-litaliano00.contact@gmail.com>
Adriano Vero <litaliano00.contact@gmail.com> writes:
> 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 <litaliano00.contact@gmail.com>
> ---
> 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 9c99c5ad6..ca208da7c 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
> --
> 2.53.0
>
>
> _______________________________________________
> linux-riscv mailing list
> linux-riscv@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-riscv
next prev parent reply other threads:[~2026-04-07 8:40 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-07 7:45 [PATCH] riscv: Add WFI to secondary hart spinwait loop Adriano Vero
2026-04-07 7:45 ` Adriano Vero
2026-04-07 8:40 ` Nam Cao [this message]
2026-04-07 8:40 ` Nam Cao
2026-04-07 8:45 ` Nam Cao
2026-04-07 8:45 ` Nam Cao
[not found] ` <CAK-CEVO6h+v-2iRdsR6THbOvoTrxM7xnmsDyXfnP5sAgUdmhYQ@mail.gmail.com>
2026-04-07 11:48 ` Nam Cao
2026-04-07 11:48 ` Nam Cao
[not found] ` <8c77810f-8198-46b5-9b6b-23095dbfee1a@lanxincomputing.com>
2026-04-07 12:27 ` litaliano00
2026-04-07 12:27 ` litaliano00
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87pl4bw4cu.fsf@yellow.woof \
--to=namcao@linutronix.de \
--cc=alex@ghiti.fr \
--cc=aou@eecs.berkeley.edu \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=litaliano00.contact@gmail.com \
--cc=palmer@dabbelt.com \
--cc=pjw@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.