All of lore.kernel.org
 help / color / mirror / Atom feed
From: "William A. Kennington III" <william@wkennington.com>
To: Daniel Lezcano <daniel.lezcano@kernel.org>,
	Thomas Gleixner <tglx@kernel.org>
Cc: "Andrew Jeffery" <andrew@codeconstruct.com.au>,
	"Avi Fishman" <avifishman70@gmail.com>,
	"Tomer Maimon" <tmaimon77@gmail.com>,
	"Tali Perry" <tali.perry1@gmail.com>,
	"Patrick Venture" <venture@google.com>,
	"Nancy Yuen" <yuenn@google.com>,
	"Benjamin Fair" <benjaminfair@google.com>,
	"Joel Stanley" <joel@jms.id.au>,
	"Jonathan Neuschäfer" <j.neuschaefer@gmx.net>,
	openbmc@lists.ozlabs.org, linux-kernel@vger.kernel.org,
	"William A. Kennington III" <william@wkennington.com>
Subject: [PATCH 2/2] clocksource/drivers/timer-npcm7xx: Register timer1 as sched_clock
Date: Sat, 28 Nov 2026 02:52:24 +0000	[thread overview]
Message-ID: <20261128025224.2680046-3-william@wkennington.com> (raw)
In-Reply-To: <20261128025224.2680046-1-william@wkennington.com>

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)

      parent reply	other threads:[~2026-11-28  2:52 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]

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=20261128025224.2680046-3-william@wkennington.com \
    --to=william@wkennington.com \
    --cc=andrew@codeconstruct.com.au \
    --cc=avifishman70@gmail.com \
    --cc=benjaminfair@google.com \
    --cc=daniel.lezcano@kernel.org \
    --cc=j.neuschaefer@gmx.net \
    --cc=joel@jms.id.au \
    --cc=linux-kernel@vger.kernel.org \
    --cc=openbmc@lists.ozlabs.org \
    --cc=tali.perry1@gmail.com \
    --cc=tglx@kernel.org \
    --cc=tmaimon77@gmail.com \
    --cc=venture@google.com \
    --cc=yuenn@google.com \
    /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.