mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: David Woodhouse <dwmw2@infradead.org>
To: Mark Rutland <mark.rutland@arm.com>
Cc: Thomas Gleixner <tglx@kernel.org>,
	John Stultz <jstultz@google.com>,
	 Stephen Boyd <sboyd@kernel.org>,
	Miroslav Lichvar <mlichvar@redhat.com>,
	Catalin Marinas	 <catalin.marinas@arm.com>,
	Will Deacon <will@kernel.org>, Marc Zyngier	 <maz@kernel.org>,
	Daniel Lezcano <daniel.lezcano@kernel.org>,
	Rodolfo Giometti	 <giometti@enneenne.com>,
	linux-arm-kernel@lists.infradead.org,
		linux-kernel@vger.kernel.org
Subject: Re: [PATCH 0/2] Optimise ktime_get_snapshot_id() for capture latency
Date: Fri, 02 Oct 2026 18:11:59 +0100	[thread overview]
Message-ID: <75d47e6d1406f7bde3b0ceeeeee3ca10a8aea889.camel@infradead.org> (raw)
In-Reply-To: <ar_et83fB9sI16Zi@J2N7QTR9R3.cambridge.arm.com>

[-- Attachment #1: Type: text/plain, Size: 3218 bytes --]

On Fri, 2026-10-02 at 17:41 +0100, Mark Rutland wrote:
> On Fri, Oct 02, 2026 at 04:19:36PM +0100, David Woodhouse wrote:
> > Commit 2e27beeb66e4 ("timekeeping: Allow inlining clocksource::read()")
> > allows an architecture's primary implementation of clocksource::read()
> > to be inlined, apparently because the out-of-line function calls get
> > expensive on x86 with certain speculation mitigations. Use the inline
> > read in tk_clock_read_snapshot(), and wire it up for arm64 too.
> > 
> > Also bias the clock_id switch() in ktime_get_snapshot_id() for the
> > likely() case of CLOCK_REALTIME.
> > 
> > Measured on a Cortex-A53 at 1.35GHz (12.5MHz arch counter), with
> > inlined clocksource reads enabled: the interval from a raw counter
> > read in the caller to the counter read in ktime_get_snapshot_id()
> > drops from 49.9ns to 41.2ns with the inline read, and to 38.8ns with
> > the dispatch bias, mean of 1M iterations.
> > 
> > This is unashamedly a microbenchmark but it actually captures a real
> > world use case: The time it takes for ktime_get_snapshot_id() to read
> > the counter is critical to some users, especially 1PPS signal
> > capture. Every nanosecond helps, and for the inline clocksource read,
> > the actually *complex* part is already in place; this is just using
> > the infrastructure that's already there.
> 
> When I mentioned this on IRC, my complaint about complexity wasn't about
> the core code, My conern was with the subtle interactions *within* the
> timer driver, and between the timer driver and arch code.
> 
> I don't think it's fair to say that the core code is the singular
> complex part.

This patch doesn't touch the *complex* part of the arch_timer support
with a barge-pole. The inline path is only enabled for the trivial case
where !arch_timer_counter_has_wa() and thus the indirect function
pointer is guaranteed to do *precisely* the same thing.

> Does this show up on any top-level workload, or is the benefit purely
> limited to microbenchmarks and timer synchronization?

For PPS, my latest experiments show that even with a tight loop
*polling* the GPIO directly via MMIO on my test board, the MMIO read
takes ~400ns. So I don't think we can claim that the ~8ns I get from
the inlining is critical to the PPS use case, no.

Rodolfo was concerned about the time taken in ktime_get_snapshot_id();
I responded that I think it's in the noise but there's some low-hanging
fruit for making it faster... I think I've fairly much shown that it's
in the noise *however* hard we try to reduce the rest of the latency.
I think think it's low-hanging fruit though; I guess it comes down to
how we view the complexity.

As also discussed on IRC before you pointed out that it's a long way to
April 1st, the most effective answer for PPS by *far* is to sample the
counter as early as possible in the exception handler, and for the PPS
IRQ handler to pull it out of pt_regs.

https://lore.kernel.org/all/dd7a873caecab6c912e2c0f910d1e46818ea455d.camel@infradead.org/

I did say I'd post the inline timer patch for posterity and let you
shoot it down, and here it is. I'm still not posting the entry.S one :)

[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 6179 bytes --]

      reply	other threads:[~2026-10-02 17:12 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-02 15:19 David Woodhouse
2026-10-02 15:19 ` [PATCH 1/2] arm64: Support inlined clocksource reads for the arch counter David Woodhouse
2026-10-02 16:36   ` Mark Rutland
2026-10-02 15:19 ` [PATCH 2/2] timekeeping: Use inlined counter read in ktime_get_snapshot_id() David Woodhouse
2026-10-02 16:41 ` [PATCH 0/2] Optimise ktime_get_snapshot_id() for capture latency Mark Rutland
2026-10-02 17:11   ` David Woodhouse [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=75d47e6d1406f7bde3b0ceeeeee3ca10a8aea889.camel@infradead.org \
    --to=dwmw2@infradead.org \
    --cc=catalin.marinas@arm.com \
    --cc=daniel.lezcano@kernel.org \
    --cc=giometti@enneenne.com \
    --cc=jstultz@google.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=maz@kernel.org \
    --cc=mlichvar@redhat.com \
    --cc=sboyd@kernel.org \
    --cc=tglx@kernel.org \
    --cc=will@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®