All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] clocksource/drivers/timer-npcm7xx: Fix timer1 warning, add sched_clock
@ 2026-11-28  2:52 William A. Kennington III
  2026-11-28  2:52 ` [PATCH 1/2] clocksource/drivers/timer-npcm7xx: Fix spurious timer1 clock warning William A. Kennington III
  2026-11-28  2:52 ` [PATCH 2/2] clocksource/drivers/timer-npcm7xx: Register timer1 as sched_clock William A. Kennington III
  0 siblings, 2 replies; 3+ messages in thread
From: William A. Kennington III @ 2026-11-28  2:52 UTC (permalink / raw)
  To: Daniel Lezcano, Thomas Gleixner
  Cc: Andrew Jeffery, Avi Fishman, Tomer Maimon, Tali Perry,
	Patrick Venture, Nancy Yuen, Benjamin Fair, Joel Stanley,
	Jonathan Neuschäfer, openbmc, linux-kernel,
	William A. Kennington III

Two fixes for drivers/clocksource/timer-npcm7xx.c found while bringing
up Linux 7.3 on an NPCM730 BMC:

1. of_clk_get(np, 1) returns ERR_PTR(-ENOENT) when only one clock is
   present in DT, which is the case for every in-tree device tree, so
   boot always logs a spurious warning for the optional timer1 clock.
   Ignore -ENOENT, add the missing newline, and check
   clk_prepare_enable() errors.
2. Register the 24-bit free-running timer1 counter with
   sched_clock_register() instead of falling back to jiffies, which
   also enables CONFIG_IRQ_TIME_ACCOUNTING at runtime.

Tested on an NPCM730 BMC: the timer1 -ENOENT boot warning is gone,
sched_clock registers at 80 ns resolution with microsecond dmesg
timestamps, and /proc/stat reports live IRQ time under TCP load.
WPCM450, which shares the driver, was not tested.

William A. Kennington III (2):
  clocksource/drivers/timer-npcm7xx: Fix spurious timer1 clock warning
  clocksource/drivers/timer-npcm7xx: Register timer1 as sched_clock

 drivers/clocksource/timer-npcm7xx.c | 23 ++++++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/2] clocksource/drivers/timer-npcm7xx: Fix spurious timer1 clock warning
  2026-11-28  2:52 [PATCH 0/2] clocksource/drivers/timer-npcm7xx: Fix timer1 warning, add sched_clock William A. Kennington III
@ 2026-11-28  2:52 ` William A. Kennington III
  2026-11-28  2:52 ` [PATCH 2/2] clocksource/drivers/timer-npcm7xx: Register timer1 as sched_clock William A. Kennington III
  1 sibling, 0 replies; 3+ messages in thread
From: William A. Kennington III @ 2026-11-28  2:52 UTC (permalink / raw)
  To: Daniel Lezcano, Thomas Gleixner
  Cc: Andrew Jeffery, Avi Fishman, Tomer Maimon, Tali Perry,
	Patrick Venture, Nancy Yuen, Benjamin Fair, Joel Stanley,
	Jonathan Neuschäfer, openbmc, linux-kernel,
	William A. Kennington III

of_clk_get(np, 1) returns ERR_PTR(-ENOENT), not NULL, when only one
clock is listed in the device tree. No in-tree device tree lists a
second timer clock, so the existing if (clk) check always logs a
warning on boot:

  /ahb/apb/timer@8000: Failed to get clock for timer1: -ENOENT

Ignore -ENOENT since the second clock is optional, add the missing
trailing newline, and check clk_prepare_enable() for errors.

Fixes: db78539fc95c ("clocksource/drivers/timer-npcm7xx: Enable timer 1 clock before use")
Signed-off-by: William A. Kennington III <william@wkennington.com>
---
 drivers/clocksource/timer-npcm7xx.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/drivers/clocksource/timer-npcm7xx.c b/drivers/clocksource/timer-npcm7xx.c
index 9af30af5f989..c7377f30e95a 100644
--- a/drivers/clocksource/timer-npcm7xx.c
+++ b/drivers/clocksource/timer-npcm7xx.c
@@ -202,11 +202,15 @@ static int __init npcm7xx_timer_init(struct device_node *np)
 
 	/* Enable the clock for timer1, if it exists */
 	clk = of_clk_get(np, 1);
-	if (clk) {
-		if (!IS_ERR(clk))
-			clk_prepare_enable(clk);
-		else
-			pr_warn("%pOF: Failed to get clock for timer1: %pe", np, clk);
+	if (!IS_ERR(clk)) {
+		ret = clk_prepare_enable(clk);
+		if (ret) {
+			pr_warn("%pOF: Failed to enable clock for timer1: %d\n",
+				np, ret);
+			clk_put(clk);
+		}
+	} else if (PTR_ERR(clk) != -ENOENT) {
+		pr_warn("%pOF: Failed to get clock for timer1: %pe\n", np, clk);
 	}
 
 	npcm7xx_clocksource_init();

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] clocksource/drivers/timer-npcm7xx: Register timer1 as sched_clock
  2026-11-28  2:52 [PATCH 0/2] clocksource/drivers/timer-npcm7xx: Fix timer1 warning, add sched_clock William A. Kennington III
  2026-11-28  2:52 ` [PATCH 1/2] clocksource/drivers/timer-npcm7xx: Fix spurious timer1 clock warning William A. Kennington III
@ 2026-11-28  2:52 ` William A. Kennington III
  1 sibling, 0 replies; 3+ messages in thread
From: William A. Kennington III @ 2026-11-28  2:52 UTC (permalink / raw)
  To: Daniel Lezcano, Thomas Gleixner
  Cc: Andrew Jeffery, Avi Fishman, Tomer Maimon, Tali Perry,
	Patrick Venture, Nancy Yuen, Benjamin Fair, Joel Stanley,
	Jonathan Neuschäfer, openbmc, linux-kernel,
	William A. Kennington III

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@wkennington.com>
---
 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)

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-28  2:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-28  2:52 [PATCH 0/2] clocksource/drivers/timer-npcm7xx: Fix timer1 warning, add sched_clock William A. Kennington III
2026-11-28  2:52 ` [PATCH 1/2] clocksource/drivers/timer-npcm7xx: Fix spurious timer1 clock warning William A. Kennington III
2026-11-28  2:52 ` [PATCH 2/2] clocksource/drivers/timer-npcm7xx: Register timer1 as sched_clock William A. Kennington III

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.