[PATCH 2/2] clocksource/drivers/timer-npcm7xx: Register timer1 as sched_clock
From: William A. Kennington III
Date: Fri Nov 27 2026 - 21:52:36 EST
timer-npcm7xx starts timer1 as a 24-bit free-running down-counter and
registers it as a clocksource, but never calls sched_clock_register().
sched_clock() then falls back to jiffies, which leaves
CONFIG_IRQ_TIME_ACCOUNTING disabled at runtime and gives coarse
scheduler and printk timestamps.
Register timer1 with sched_clock_register() using an inverted
readl_relaxed() callback matching clocksource_mmio_readl_down(). The
counter is the one the clocksource already reads, so its 24-bit wrap
(about 1.3 s at 12.5 MHz) is not a new constraint.
Tested on an NPCM730 BMC, where sched_clock now has 80 ns resolution.
The driver also binds nuvoton,wpcm450-timer, which was not tested.
Signed-off-by: William A. Kennington III <william@xxxxxxxxxxxxxxx>
---
drivers/clocksource/timer-npcm7xx.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/drivers/clocksource/timer-npcm7xx.c b/drivers/clocksource/timer-npcm7xx.c
index c7377f30e95a..f4b828d7c183 100644
--- a/drivers/clocksource/timer-npcm7xx.c
+++ b/drivers/clocksource/timer-npcm7xx.c
@@ -14,6 +14,7 @@
#include <linux/clk.h>
#include <linux/io.h>
#include <linux/clockchips.h>
+#include <linux/sched_clock.h>
#include <linux/of_irq.h>
#include <linux/of_address.h>
#include "timer-of.h"
@@ -166,6 +167,11 @@ static void __init npcm7xx_clockevents_init(void)
0x1, NPCM7XX_Tx_MAX_CNT);
}
+static u64 notrace npcm7xx_read_sched_clock(void)
+{
+ return ~(u64)readl_relaxed(npcm7xx_to.of_base.base + NPCM7XX_REG_TDR1);
+}
+
static void __init npcm7xx_clocksource_init(void)
{
u32 val;
@@ -184,6 +190,9 @@ static void __init npcm7xx_clocksource_init(void)
"npcm7xx-timer1", timer_of_rate(&npcm7xx_to),
200, (unsigned int)NPCM7XX_Tx_TDR_MASK_BITS,
clocksource_mmio_readl_down);
+ sched_clock_register(npcm7xx_read_sched_clock,
+ NPCM7XX_Tx_TDR_MASK_BITS,
+ timer_of_rate(&npcm7xx_to));
}
static int __init npcm7xx_timer_init(struct device_node *np)