* [PATCH RESEND] clocksource/timer-riscv: use riscv_has_extension_likely
@ 2026-11-07 13:49 Jisheng Zhang
2026-11-25 16:51 ` Daniel Lezcano
2026-11-27 17:29 ` Kuan-Wei Chiu
0 siblings, 2 replies; 3+ messages in thread
From: Jisheng Zhang @ 2026-11-07 13:49 UTC (permalink / raw)
To: Daniel Lezcano, Thomas Gleixner, Paul Walmsley, Palmer Dabbelt,
Albert Ou, Alexandre Ghiti
Cc: linux-kernel, linux-riscv
Instead of static branch, use riscv_has_extension_likely() to check
whether SSTC is supported or not. For one thing, this is straight
forward, no need to add and enable/disable a static branch during
probe; For another, riscv_has_extension_likely() is based on
alternative mechanism, it avoid some downsides of static branch, for
example static branch's metadata in the __jump_table section, which is
not discarded after ISA extensions are finalized, wastes some space.
Signed-off-by: Jisheng Zhang <jszhang@kernel.org>
---
drivers/clocksource/timer-riscv.c | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)
diff --git a/drivers/clocksource/timer-riscv.c b/drivers/clocksource/timer-riscv.c
index b310e6721fac..151f4f0cfd6c 100644
--- a/drivers/clocksource/timer-riscv.c
+++ b/drivers/clocksource/timer-riscv.c
@@ -29,12 +29,11 @@
#include <asm/sbi.h>
#include <asm/timex.h>
-static DEFINE_STATIC_KEY_FALSE(riscv_sstc_available);
static bool riscv_timer_cannot_wake_cpu;
static void riscv_clock_event_stop(void)
{
- if (static_branch_likely(&riscv_sstc_available)) {
+ if (riscv_has_extension_likely(RISCV_ISA_EXT_SSTC)) {
csr_write(CSR_STIMECMP, ULONG_MAX);
if (IS_ENABLED(CONFIG_32BIT))
csr_write(CSR_STIMECMPH, ULONG_MAX);
@@ -48,7 +47,7 @@ static int riscv_clock_next_event(unsigned long delta,
{
u64 next_tval = get_cycles64() + delta;
- if (static_branch_likely(&riscv_sstc_available)) {
+ if (riscv_has_extension_likely(RISCV_ISA_EXT_SSTC)) {
#if defined(CONFIG_32BIT)
csr_write(CSR_STIMECMP, ULONG_MAX);
csr_write(CSR_STIMECMPH, next_tval >> 32);
@@ -112,7 +111,7 @@ static int riscv_timer_starting_cpu(unsigned int cpu)
ce->irq = riscv_clock_event_irq;
if (riscv_timer_cannot_wake_cpu)
ce->features |= CLOCK_EVT_FEAT_C3STOP;
- if (static_branch_likely(&riscv_sstc_available))
+ if (riscv_has_extension_likely(RISCV_ISA_EXT_SSTC))
ce->rating = 450;
clockevents_config_and_register(ce, riscv_timebase, 100, ULONG_MAX);
@@ -186,10 +185,8 @@ static int __init riscv_timer_init_common(void)
return error;
}
- if (riscv_isa_extension_available(NULL, SSTC)) {
+ if (riscv_isa_extension_available(NULL, SSTC))
pr_info("Timer interrupt in S-mode is available via sstc extension\n");
- static_branch_enable(&riscv_sstc_available);
- }
error = cpuhp_setup_state(CPUHP_AP_RISCV_TIMER_STARTING,
"clockevents/riscv/timer:starting",
--
2.53.0
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH RESEND] clocksource/timer-riscv: use riscv_has_extension_likely
2026-11-07 13:49 [PATCH RESEND] clocksource/timer-riscv: use riscv_has_extension_likely Jisheng Zhang
@ 2026-11-25 16:51 ` Daniel Lezcano
2026-11-27 17:29 ` Kuan-Wei Chiu
1 sibling, 0 replies; 3+ messages in thread
From: Daniel Lezcano @ 2026-11-25 16:51 UTC (permalink / raw)
To: Jisheng Zhang, Daniel Lezcano, Thomas Gleixner, Paul Walmsley,
Palmer Dabbelt, Albert Ou, Alexandre Ghiti
Cc: linux-kernel, linux-riscv
On 11/7/26 14:49, Jisheng Zhang wrote:
> Instead of static branch, use riscv_has_extension_likely() to check
> whether SSTC is supported or not. For one thing, this is straight
> forward, no need to add and enable/disable a static branch during
> probe; For another, riscv_has_extension_likely() is based on
> alternative mechanism, it avoid some downsides of static branch, for
> example static branch's metadata in the __jump_table section, which is
> not discarded after ISA extensions are finalized, wastes some space.
>
> Signed-off-by: Jisheng Zhang <jszhang@kernel.org>
Still waiting for maintainers' blessing ...
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH RESEND] clocksource/timer-riscv: use riscv_has_extension_likely
2026-11-07 13:49 [PATCH RESEND] clocksource/timer-riscv: use riscv_has_extension_likely Jisheng Zhang
2026-11-25 16:51 ` Daniel Lezcano
@ 2026-11-27 17:29 ` Kuan-Wei Chiu
1 sibling, 0 replies; 3+ messages in thread
From: Kuan-Wei Chiu @ 2026-11-27 17:29 UTC (permalink / raw)
To: Jisheng Zhang
Cc: Daniel Lezcano, Thomas Gleixner, Paul Walmsley, Palmer Dabbelt,
Albert Ou, Alexandre Ghiti, linux-kernel, linux-riscv
Hi Jisheng,
On Sat, Nov 07, 2026 at 09:49:52PM +0800, Jisheng Zhang wrote:
> Instead of static branch, use riscv_has_extension_likely() to check
> whether SSTC is supported or not. For one thing, this is straight
> forward, no need to add and enable/disable a static branch during
> probe; For another, riscv_has_extension_likely() is based on
> alternative mechanism, it avoid some downsides of static branch, for
> example static branch's metadata in the __jump_table section, which is
> not discarded after ISA extensions are finalized, wastes some space.
After reading the __jump_table note above, I checked the generated
timer-riscv.o. One side effect I noticed in the disassembly is that gcc
stops inlining riscv_clock_event_stop() with the alternative asm, so
riscv_timer_interrupt() ends up doing an extra call/ret plus a stack
spill/reload on every timer irq.
Not sure if it's worth worrying about, or if marking
riscv_clock_event_stop() inline makes sense to keep the irq path flat.
Otherwise, I tested this on qemu virt smp for both rv64 and rv32 with
sstc enabled and disabled, including cpu hotplug, and everything worked
fine.
Tested-by: Kuan-Wei Chiu <visitorckw@gmail.com>
Regards,
Kuan-Wei
>
> Signed-off-by: Jisheng Zhang <jszhang@kernel.org>
> ---
> drivers/clocksource/timer-riscv.c | 11 ++++-------
> 1 file changed, 4 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/clocksource/timer-riscv.c b/drivers/clocksource/timer-riscv.c
> index b310e6721fac..151f4f0cfd6c 100644
> --- a/drivers/clocksource/timer-riscv.c
> +++ b/drivers/clocksource/timer-riscv.c
> @@ -29,12 +29,11 @@
> #include <asm/sbi.h>
> #include <asm/timex.h>
>
> -static DEFINE_STATIC_KEY_FALSE(riscv_sstc_available);
> static bool riscv_timer_cannot_wake_cpu;
>
> static void riscv_clock_event_stop(void)
> {
> - if (static_branch_likely(&riscv_sstc_available)) {
> + if (riscv_has_extension_likely(RISCV_ISA_EXT_SSTC)) {
> csr_write(CSR_STIMECMP, ULONG_MAX);
> if (IS_ENABLED(CONFIG_32BIT))
> csr_write(CSR_STIMECMPH, ULONG_MAX);
> @@ -48,7 +47,7 @@ static int riscv_clock_next_event(unsigned long delta,
> {
> u64 next_tval = get_cycles64() + delta;
>
> - if (static_branch_likely(&riscv_sstc_available)) {
> + if (riscv_has_extension_likely(RISCV_ISA_EXT_SSTC)) {
> #if defined(CONFIG_32BIT)
> csr_write(CSR_STIMECMP, ULONG_MAX);
> csr_write(CSR_STIMECMPH, next_tval >> 32);
> @@ -112,7 +111,7 @@ static int riscv_timer_starting_cpu(unsigned int cpu)
> ce->irq = riscv_clock_event_irq;
> if (riscv_timer_cannot_wake_cpu)
> ce->features |= CLOCK_EVT_FEAT_C3STOP;
> - if (static_branch_likely(&riscv_sstc_available))
> + if (riscv_has_extension_likely(RISCV_ISA_EXT_SSTC))
> ce->rating = 450;
> clockevents_config_and_register(ce, riscv_timebase, 100, ULONG_MAX);
>
> @@ -186,10 +185,8 @@ static int __init riscv_timer_init_common(void)
> return error;
> }
>
> - if (riscv_isa_extension_available(NULL, SSTC)) {
> + if (riscv_isa_extension_available(NULL, SSTC))
> pr_info("Timer interrupt in S-mode is available via sstc extension\n");
> - static_branch_enable(&riscv_sstc_available);
> - }
>
> error = cpuhp_setup_state(CPUHP_AP_RISCV_TIMER_STARTING,
> "clockevents/riscv/timer:starting",
> --
> 2.53.0
>
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-27 17:29 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-07 13:49 [PATCH RESEND] clocksource/timer-riscv: use riscv_has_extension_likely Jisheng Zhang
2026-11-25 16:51 ` Daniel Lezcano
2026-11-27 17:29 ` Kuan-Wei Chiu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®