* [PATCH] clocksource/drivers/nxp-stm: Register sched_clock once
@ 2026-09-13 13:36 Juhee Kang
2026-10-13 11:01 ` Ghennadi Procopciuc
0 siblings, 1 reply; 2+ messages in thread
From: Juhee Kang @ 2026-09-13 13:36 UTC (permalink / raw)
To: Daniel Lezcano, Thomas Gleixner
Cc: linux-kernel, linux-arm-kernel, Ghennadi Procopciuc,
NXP S32 Linux Team, Dustin Black, stable, Juhee Kang
Each probe updates stm_sched_clock before calling sched_clock_register()
again. The call then subtracts the counter value saved during the
previous registration from the new STM's counter. If the new counter is
smaller, the subtraction wraps and the timestamp jumps forward.
(e.g. from 0.4 to 32.9 seconds below)
[ 0.403653] sched_clock: 32 bits at 132MHz, resolution 7ns, wraps every 16243448316ns
[ 0.404056] clocksource: timer@40120000: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 14456668980 ns
[ 32.890509] sched_clock: 32 bits at 132MHz, resolution 7ns, wraps every 16243448316ns
[ 32.890882] clocksource: timer@40124000: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 14456668980 ns
To fix this, register sched_clock once at the end of the first
successful probe. Clocksource and per-CPU clockevent registration
remain unchanged.
Fixes: cec32ac75827 ("clocksource/drivers/nxp-timer: Add the System Timer Module for the s32gx platforms")
Reported-by: Dustin Black <dblack@redhat.com>
Signed-off-by: Juhee Kang <juhee.kang@redhat.com>
---
drivers/clocksource/timer-nxp-stm.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/drivers/clocksource/timer-nxp-stm.c b/drivers/clocksource/timer-nxp-stm.c
index 6fe098a4a33f..7572cd20732f 100644
--- a/drivers/clocksource/timer-nxp-stm.c
+++ b/drivers/clocksource/timer-nxp-stm.c
@@ -211,10 +211,6 @@ static int nxp_stm_clocksource_init(struct device *dev, struct stm_timer *stm_ti
if (ret)
return ret;
- stm_sched_clock = stm_timer;
-
- sched_clock_register(nxp_stm_read_sched_clock, 32, stm_timer->rate);
-
dev_dbg(dev, "Registered clocksource %s\n", name);
return 0;
@@ -473,6 +469,11 @@ static int nxp_stm_timer_probe(struct platform_device *pdev)
return ret;
}
+ if (!stm_sched_clock) {
+ stm_sched_clock = stm_timer;
+ sched_clock_register(nxp_stm_read_sched_clock, 32, stm_timer->rate);
+ }
+
return 0;
}
--
2.55.0
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] clocksource/drivers/nxp-stm: Register sched_clock once
2026-09-13 13:36 [PATCH] clocksource/drivers/nxp-stm: Register sched_clock once Juhee Kang
@ 2026-10-13 11:01 ` Ghennadi Procopciuc
0 siblings, 0 replies; 2+ messages in thread
From: Ghennadi Procopciuc @ 2026-10-13 11:01 UTC (permalink / raw)
To: Juhee Kang, Daniel Lezcano, Thomas Gleixner
Cc: linux-kernel, linux-arm-kernel, NXP S32 Linux Team, Dustin Black, stable
On 9/13/2026 4:36 PM, Juhee Kang wrote:
>
> Each probe updates stm_sched_clock before calling sched_clock_register()
> again. The call then subtracts the counter value saved during the
> previous registration from the new STM's counter. If the new counter is
> smaller, the subtraction wraps and the timestamp jumps forward.
> (e.g. from 0.4 to 32.9 seconds below)
>
> [ 0.403653] sched_clock: 32 bits at 132MHz, resolution 7ns, wraps every 16243448316ns
> [ 0.404056] clocksource: timer@40120000: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 14456668980 ns
> [ 32.890509] sched_clock: 32 bits at 132MHz, resolution 7ns, wraps every 16243448316ns
> [ 32.890882] clocksource: timer@40124000: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 14456668980 ns
>
> To fix this, register sched_clock once at the end of the first
> successful probe. Clocksource and per-CPU clockevent registration
> remain unchanged.
>
> Fixes: cec32ac75827 ("clocksource/drivers/nxp-timer: Add the System Timer Module for the s32gx platforms")
> Reported-by: Dustin Black <dblack@redhat.com>
> Signed-off-by: Juhee Kang <juhee.kang@redhat.com>
> ---
> drivers/clocksource/timer-nxp-stm.c | 9 +++++----
> 1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/clocksource/timer-nxp-stm.c b/drivers/clocksource/timer-nxp-stm.c
> index 6fe098a4a33f..7572cd20732f 100644
> --- a/drivers/clocksource/timer-nxp-stm.c
> +++ b/drivers/clocksource/timer-nxp-stm.c
> @@ -211,10 +211,6 @@ static int nxp_stm_clocksource_init(struct device *dev, struct stm_timer *stm_ti
> if (ret)
> return ret;
>
> - stm_sched_clock = stm_timer;
> -
> - sched_clock_register(nxp_stm_read_sched_clock, 32, stm_timer->rate);
> -
> dev_dbg(dev, "Registered clocksource %s\n", name);
>
> return 0;
> @@ -473,6 +469,11 @@ static int nxp_stm_timer_probe(struct platform_device *pdev)
> return ret;
> }
>
> + if (!stm_sched_clock) {
> + stm_sched_clock = stm_timer;
> + sched_clock_register(nxp_stm_read_sched_clock, 32, stm_timer->rate);
> + }
> +
> return 0;
> }
>
One optional nit: a short comment above the block would help future
readers understand why it runs only once, e.g.:
/*
* The STM instances are independent counters running at the same
* rate. Only one of them can back sched_clock, use the first one
* probed.
*/
With or without it:
Reviewed-by: Ghennadi Procopciuc <ghennadi.procopciuc@oss.nxp.com>
--
Regards,
Ghennadi
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-10-13 11:01 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-13 13:36 [PATCH] clocksource/drivers/nxp-stm: Register sched_clock once Juhee Kang
2026-10-13 11:01 ` Ghennadi Procopciuc
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®