From: Feng Tang <feng.tang@linux.alibaba.com>
To: Thomas Gleixner <tglx@kernel.org>,
John Stultz <jstultz@google.com>, Stephen Boyd <sboyd@kernel.org>,
Miroslav Lichvar <mlichvar@redhat.com>,
Daniel Lezcano <daniel.lezcano@kernel.org>,
Peter Zijlstra <peterz@infradead.org>
Cc: Marc Zyngier <maz@kernel.org>, Petr Mladek <pmladek@suse.com>,
linux-kernel@vger.kernel.org,
Feng Tang <feng.tang@linux.alibaba.com>
Subject: [PATCH] sched_clock: Add option to use absolute time against hardware clock reset
Date: Wed, 2 Sep 2026 16:21:23 +0800 [thread overview]
Message-ID: <20260902082123.95770-1-feng.tang@linux.alibaba.com> (raw)
Currently sched_clock shows the relative time to the boot starting of
kernel, while there could be long firmware start time before it and
after the hardware reset.
On modern server platforms, there could be several software running in
parallel. Like for arm64, it could have SCP (System Control Processor)
firmware running on SCP processor, and ATF (Arm Trusted Firmware) and
Linux OS on the main processor.
Debugging some nasty issues on these platform may need to cross-check
the logs from these firmwares and Linux kernel for specific events,
where a unified reference timeline is critical. All these software can
read the hardware timer, which is also the base of sched_clock for
Linux kernel. Using the absolute counter since hardware timer reset
makes it possible for all kinds of software to have a same time base.
Add 'abs_sched_clock' parameter to provide an option for using absolute
counter, and users should make sure their sched_clock (hardware timer)
is capable of supporting absolute counter before enabling the option.
Locally, it did help on chasing some RAS issues which needed cooperation
between kernel, SCP firmware and ATF, by mapping the actions from each
players into one timeline based on the timestamps in their logs.
Signed-off-by: Feng Tang <feng.tang@linux.alibaba.com>
---
kernel/time/sched_clock.c | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/kernel/time/sched_clock.c b/kernel/time/sched_clock.c
index f3aaef695b8c..321c580d6799 100644
--- a/kernel/time/sched_clock.c
+++ b/kernel/time/sched_clock.c
@@ -49,6 +49,10 @@ static int irqtime = -1;
core_param(irqtime, irqtime, int, 0400);
+/* Whether to use the absolute counter since the clock hardware reset */
+static bool abs_sched_clock;
+core_param(abs_sched_clock, abs_sched_clock, bool, 0400);
+
static u64 notrace jiffy_sched_clock_read(void)
{
/*
@@ -200,10 +204,14 @@ void sched_clock_register(u64 (*read)(void), int bits, unsigned long rate)
rd = cd.read_data[0];
- /* Update epoch for new counter and update 'epoch_ns' from old counter*/
+ /* Update epoch for new counter and update 'epoch_ns' */
new_epoch = read();
- cyc = cd.actual_read_sched_clock();
- ns = rd.epoch_ns + cyc_to_ns((cyc - rd.epoch_cyc) & rd.sched_clock_mask, rd.mult, rd.shift);
+ if (abs_sched_clock) {
+ ns = cyc_to_ns(new_epoch & new_mask, new_mult, new_shift);
+ } else {
+ cyc = cd.actual_read_sched_clock();
+ ns = rd.epoch_ns + cyc_to_ns((cyc - rd.epoch_cyc) & rd.sched_clock_mask, rd.mult, rd.shift);
+ }
cd.actual_read_sched_clock = read;
rd.read_sched_clock = read;
--
2.39.5 (Apple Git-154)
next reply other threads:[~2026-09-02 8:21 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-02 8:21 Feng Tang [this message]
2026-09-02 15:32 ` Marc Zyngier
2026-09-03 6:51 ` Yao Yuan
2026-09-03 7:38 ` Marc Zyngier
2026-09-03 8:07 ` Feng Tang
2026-09-03 10:20 ` Yao Yuan
2026-09-03 7:45 ` Feng Tang
2026-09-05 20:39 ` Thomas Gleixner
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=20260902082123.95770-1-feng.tang@linux.alibaba.com \
--to=feng.tang@linux.alibaba.com \
--cc=daniel.lezcano@kernel.org \
--cc=jstultz@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=maz@kernel.org \
--cc=mlichvar@redhat.com \
--cc=peterz@infradead.org \
--cc=pmladek@suse.com \
--cc=sboyd@kernel.org \
--cc=tglx@kernel.org \
/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 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®