From: David Woodhouse <dwmw2@infradead.org>
To: Rodolfo Giometti <giometti@enneenne.com>,
Miroslav Lichvar <mlichvar@redhat.com>
Cc: Richard Cochran <richardcochran@gmail.com>,
Andrew Lunn <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>,
Paolo Abeni <pabeni@redhat.com>,
John Stultz <jstultz@google.com>,
Thomas Gleixner <tglx@kernel.org>,
Stephen Boyd <sboyd@kernel.org>,
linux-kernel@vger.kernel.org, netdev@vger.kernel.org,
Alexander Gordeev <agordeev@linux.ibm.com>
Subject: Re: [PATCH v4 3/4] pps: Always use ktime_get_snapshot_id() for pps_get_ts()
Date: Sat, 03 Oct 2026 12:29:29 +0100 [thread overview]
Message-ID: <c47a3d769d374b6fd2a52f4a7c4fabb88bf0392c.camel@infradead.org> (raw)
In-Reply-To: <dd7a873caecab6c912e2c0f910d1e46818ea455d.camel@infradead.org>
[-- Attachment #1: Type: text/plain, Size: 4463 bytes --]
On Fri, 2026-10-02 at 14:44 +0100, David Woodhouse wrote:
>
> Hah, I should stop predicting results before I have them. I'm clearly
> not very prescient. Spinning on the MMIO (the GPIO wait_for_edge()
> method idea) makes more of a difference than I thought (~30% off every
> column brings us down to only 3× the entry.S capture):
>
> ┌──────────────────────────────┬─────┬──────┬──────┬──────┬─────┐
> │ capture method │ p50 │ p95 │ p99 │ max │ σ │
> ├──────────────────────────────┼─────┼──────┼──────┼──────┼─────┤
> │ pps-gpio (IRQ) │ 84 │ 1206 │ 4013 │ 4889 │ 688 │
> │ polling, stamp after edge │ 206 │ 536 │ 665 │ 1106 │ 286 │
> │ polling, bracketed counter │ 206 │ 545 │ 647 │ 811 │ 286 │
> │ polling, bracketed, raw MMIO │ 135 │ 359 │ 434 │ 564 │ 188 │
> │ entry.S counter capture │ 46 │ 109 │ 135 │ 206 │ 58 │
> └──────────────────────────────┴─────┴──────┴──────┴──────┴─────┘
>
> (NB: We should be careful not to forget the common-mode hardware
> latency which could be different for the IRQ paths vs. the polling
> paths. On my list is a test where one CPU polls while the other takes
> the interrupt, so we can compare on the *same* pulse.)
I did this test, on a live system rather than a tweaked-for-idleness
initramfs environment which was going to flatter the IRQ path
massively.
It compares the cycle count from the GPIO spin on one CPU, with the
entry.S (and, eventually, pps_gpio_irq_hardirq()) on the other.
Full results at https://david.woodhou.se/ntptest-r64/capture-latency/
Running idle-ish, with schedutil disabled, the poll captures the edge
sooner (-200ns), but with higher jitter (σ 150 ns vs. 115 ns for
entry.S).
Running under load, we see a lot more jitter even on the entry.S
capture (σ 7.6µs). And some captures are seen *before* the polled
pulse, presumably because something else asserted the IRQ line first
and then the GPIO interrupt was present by the time it was checked.
Eliminating those, σ 5.8µs under load.
All of which brings me back to the case for better filtering. The CDF
suggests there are enough *good* pulses — even under load the median
entry.S capture is within ~300ns and 95% are within 1.5µs.
Ultimately, the common mode offset is unmeasurable and includes things
like the antenna length.
The *jitter* has a hard floor for the polling method, based on the time
it takes to actually read the GPIO (gpio_read @600ns → σ286ns, direct
MMIO @400ns → σ188ns as shown in the table cited above, which is
slightly different because it's phase offset against what hardpps was
tracking).
There's no such obvious hard floor for the entry.S capture, but it does
require filtering to throw away the outliers.
Intelligently and in *retrospect* building a best fit line for today's
data (no hardpps here; just counter captures), we get σ 150-180ns for
polling, and 50-280ns for entry.S capture, the latter correlated with
load.
Polling under load basically does its *own* filtering, because if it
misses a pulse when its hrtimer doesn't get to run, that datum just
doesn't exist in the first place. So its jitter *is* its hard floor.
(Modulo the bus taking a bit longer to do the GPIO read, perhaps).
While interrupt capture — however early you do it — is worse either way
when the load is high. (My friend made me add "when the load is high"
in reviewing for statistical accuracy and defensibility against the
results, but it's tautological — the variability is high, when you
don't exclude the outliers.)
If we need to cope with load (and I think we do), the interrupt capture
didn't survive the test. Which is just as well really, because nobody
actually wanted to implement it that way. But I think it was worth
finding out, while I had the test reg set up to do so.
Still looking forward to hardware which captures the counter for itself
when the edge occurs.
[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 6179 bytes --]
next prev parent reply other threads:[~2026-10-03 11:29 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-29 20:56 [PATCH v4 0/4] Add ntp_error to clock snapshot, enable NTP_PPS on tickless kernel David Woodhouse
2026-08-29 20:56 ` [PATCH v4 1/4] timekeeping: Apply extrapolated ntp_error to clock snapshots David Woodhouse
2026-08-29 20:57 ` [PATCH v4 2/4] pps: Drop the !NO_HZ_COMMON dependency from NTP_PPS David Woodhouse
2026-09-01 15:35 ` Rodolfo Giometti
2026-09-02 0:13 ` David Woodhouse
2026-09-28 13:37 ` David Woodhouse
2026-09-28 16:41 ` Rodolfo Giometti
2026-09-28 19:28 ` David Woodhouse
2026-09-29 6:33 ` Rodolfo Giometti
2026-09-29 9:32 ` David Woodhouse
2026-09-29 11:48 ` Rodolfo Giometti
2026-09-29 12:02 ` David Woodhouse
2026-09-30 1:28 ` David Woodhouse
2026-09-30 12:57 ` Rodolfo Giometti
2026-09-30 10:37 ` David Woodhouse
2026-09-30 12:57 ` Rodolfo Giometti
2026-09-30 14:05 ` David Woodhouse
2026-09-30 18:24 ` David Woodhouse
2026-10-01 8:20 ` Rodolfo Giometti
2026-10-01 9:08 ` David Woodhouse
2026-08-29 20:57 ` [PATCH v4 3/4] pps: Always use ktime_get_snapshot_id() for pps_get_ts() David Woodhouse
2026-09-01 15:35 ` Rodolfo Giometti
2026-09-01 23:56 ` David Woodhouse
2026-09-26 20:38 ` David Woodhouse
2026-09-28 7:58 ` Rodolfo Giometti
2026-09-28 12:59 ` David Woodhouse
2026-09-28 16:41 ` Rodolfo Giometti
2026-10-01 13:14 ` Miroslav Lichvar
2026-10-01 15:38 ` David Woodhouse
2026-10-02 7:04 ` Rodolfo Giometti
2026-10-02 9:07 ` David Woodhouse
2026-10-02 12:29 ` David Woodhouse
2026-10-02 13:44 ` David Woodhouse
2026-10-03 11:29 ` David Woodhouse [this message]
2026-10-05 9:16 ` Miroslav Lichvar
2026-08-29 20:57 ` [PATCH v4 4/4] [DO NOT MERGE] ptp: ptp_vmclock: Add simulated 1PPS support David Woodhouse
2026-09-01 15:35 ` [PATCH v4 0/4] Add ntp_error to clock snapshot, enable NTP_PPS on tickless kernel Rodolfo Giometti
2026-09-01 23:37 ` David Woodhouse
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=c47a3d769d374b6fd2a52f4a7c4fabb88bf0392c.camel@infradead.org \
--to=dwmw2@infradead.org \
--cc=agordeev@linux.ibm.com \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=giometti@enneenne.com \
--cc=jstultz@google.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mlichvar@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=richardcochran@gmail.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