* [PATCH v7 0/1] pps: improve PREEMPT_RT performance
@ 2026-06-02 0:44 Calvin Owens
2026-06-02 0:44 ` [PATCH v7 1/1] pps: pps-gpio: split IRQ handler into hardirq timestamper + threaded handler Calvin Owens
0 siblings, 1 reply; 4+ messages in thread
From: Calvin Owens @ 2026-06-02 0:44 UTC (permalink / raw)
To: linux-kernel
Cc: linux-rt-devel, Rodolfo Giometti, Sebastian Andrzej Siewior,
Clark Williams, Steven Rostedt, Greg Kroah-Hartman, Eliav Farber,
Michael Byczkowski, Ingo Molnar, David Laight, Thomas Gleixner
Hello all,
I'm relaying v7 for Michael.
A quick note, this conflicts with the patch I have out to remove
capture_clear: it's trivial to resolve, but if it saves anybody time let
me know and I can respin one or the other.
Thanks,
Calvin
---
From: Michael Byczkowski <by@by-online.de>
Changes since v6: https://lore.kernel.org/lkml/cover.1779733602.git.calvin@wbinvd.org/
- patches 2 and 3 are dropped since neither lock is ever taken in
hardirq context.
Changes since v5: https://lore.kernel.org/lkml/719A31CE-CA58-45C3-A013-1BFE81F724C5@by-online.de/
- Reordered: the pps_kc_hardpps_lock conversion now precedes the
pps_device.lock conversion. The previous order would have briefly
produced a raw_spinlock holding a sleeping spinlock on PREEMPT_RT
(Sebastian).
- Patch 1/3: commit message reworded to describe the handler split
structurally first, then its PREEMPT_RT benefit (Sebastian).
- Patch 2/3: refactored pps_kc_bind() and pps_kc_remove() to use
guard(raw_spinlock_irq) for scope-based lock release. Eliminates
four duplicated unlock call sites in pps_kc_bind() and the
ambiguous bracket structure that resulted from them (Sebastian).
- Rodolfo's Acked-by on patch 2/3 is preserved from v5; the guard()
refactor is purely stylistic and was suggested by Sebastian, but
please re-ack or NAK if disagreement.
Changes since v4: https://lore.kernel.org/lkml/B24484C5-3117-4C56-9522-1EE9876E64BA@by-online.de/
- Patch 2/3: added Acked-by: Rodolfo Giometti <giometti@enneenne.com>
Changes since v3: https://lore.kernel.org/lkml/83318241-44C3-48BE-829D-5C5F82A78A74@by-online.de/
- Patch 2/3: fixed lost indentation on pps_kc_event() call
(reported by Rodolfo Giometti <giometti@enneenne.com>)
Changes since v2: https://lore.kernel.org/lkml/1BB87C0C-33C1-45C3-B50E-C5F349DA3FDC@by-online.de/
- Patch 2/3: moved wake_up_interruptible_all() and kill_fasync() out
of raw_spinlock section to avoid sleeping-in-atomic on PREEMPT_RT
(reported by Nikolaus Buchwitz <nb@buchwitz.com>)
This patchset addresses three sources of PPS jitter under PREEMPT_RT,
while being fully backward-compatible with non-RT kernels:
1. pps-gpio: The IRQ handler is force-threaded on PREEMPT_RT, so the
PPS timestamp is captured after scheduling delay rather than at
interrupt entry. Fix: split into a hardirq primary handler
(captures timestamp only) and a threaded handler (processes the
event).
Tested on a Raspberry Pi 5 running 7.0.1 and 7.1-rc PREEMPT_RT kernels.
On non-RT kernels there is zero behavioral change.
Michael Byczkowski (1):
pps: pps-gpio: split IRQ handler into hardirq timestamper + threaded
handler
drivers/pps/clients/pps-gpio.c | 37 +++++++++++++++++++++++-----------
1 file changed, 25 insertions(+), 12 deletions(-)
--
2.47.3
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v7 1/1] pps: pps-gpio: split IRQ handler into hardirq timestamper + threaded handler
2026-06-02 0:44 [PATCH v7 0/1] pps: improve PREEMPT_RT performance Calvin Owens
@ 2026-06-02 0:44 ` Calvin Owens
2026-06-02 6:36 ` Sebastian Andrzej Siewior
0 siblings, 1 reply; 4+ messages in thread
From: Calvin Owens @ 2026-06-02 0:44 UTC (permalink / raw)
To: linux-kernel
Cc: linux-rt-devel, Rodolfo Giometti, Sebastian Andrzej Siewior,
Clark Williams, Steven Rostedt, Greg Kroah-Hartman, Eliav Farber,
Michael Byczkowski, Ingo Molnar, David Laight, Thomas Gleixner
From: Michael Byczkowski <by@by-online.de>
Split the pps-gpio interrupt handler into a primary (hardirq) handler
that captures the PPS timestamp at interrupt entry, and a threaded
handler that processes the event. This produces the same two-part
handler structure on both PREEMPT_RT and non-RT kernels.
On non-RT kernels the threaded portion runs immediately after the
primary, with no behavioral change compared to the previous
single-handler implementation.
On PREEMPT_RT, where interrupt handlers are force-threaded by default,
the previous single-handler implementation captured the timestamp
inside the threaded portion, after IRQ-thread scheduling delay. With
the split, the timestamp is captured in true hardirq context as it is
on non-RT kernels, eliminating a significant source of PPS jitter on
RT systems.
Tested-by: Michael Byczkowski <by@by-online.de>
Tested-by: Calvin Owens <calvin@wbinvd.org>
Acked-by: Rodolfo Giometti <giometti@enneenne.com>
Signed-off-by: Michael Byczkowski <by@by-online.de>
Signed-off-by: Calvin Owens <calvin@wbinvd.org>
---
drivers/pps/clients/pps-gpio.c | 37 +++++++++++++++++++++++-----------
1 file changed, 25 insertions(+), 12 deletions(-)
diff --git a/drivers/pps/clients/pps-gpio.c b/drivers/pps/clients/pps-gpio.c
index 935da68610c7..ed111621ee5f 100644
--- a/drivers/pps/clients/pps-gpio.c
+++ b/drivers/pps/clients/pps-gpio.c
@@ -35,33 +35,44 @@ struct pps_gpio_device_data {
bool capture_clear;
unsigned int echo_active_ms; /* PPS echo active duration */
unsigned long echo_timeout; /* timer timeout value in jiffies */
+ struct pps_event_time ts; /* timestamp captured in hardirq */
};
/*
* Report the PPS event
*/
-static irqreturn_t pps_gpio_irq_handler(int irq, void *data)
+/*
+ * Primary hardirq handler -- runs in hardirq context even on PREEMPT_RT.
+ * Only captures the timestamp; all other work is deferred to the thread.
+ */
+static irqreturn_t pps_gpio_irq_hardirq(int irq, void *data)
{
- const struct pps_gpio_device_data *info;
- struct pps_event_time ts;
- int rising_edge;
+ struct pps_gpio_device_data *info = data;
+
+ pps_get_ts(&info->ts);
- /* Get the time stamp first */
- pps_get_ts(&ts);
+ return IRQ_WAKE_THREAD;
+}
- info = data;
+/*
+ * Threaded handler -- processes the PPS event using the timestamp
+ * captured in hardirq context above.
+ */
+static irqreturn_t pps_gpio_irq_thread(int irq, void *data)
+{
+ struct pps_gpio_device_data *info = data;
+ int rising_edge;
- /* Small trick to bypass the check on edge's direction when capture_clear is unset */
rising_edge = info->capture_clear ?
gpiod_get_value(info->gpio_pin) : !info->assert_falling_edge;
if ((rising_edge && !info->assert_falling_edge) ||
(!rising_edge && info->assert_falling_edge))
- pps_event(info->pps, &ts, PPS_CAPTUREASSERT, data);
+ pps_event(info->pps, &info->ts, PPS_CAPTUREASSERT, data);
else if (info->capture_clear &&
((rising_edge && info->assert_falling_edge) ||
(!rising_edge && !info->assert_falling_edge)))
- pps_event(info->pps, &ts, PPS_CAPTURECLEAR, data);
+ pps_event(info->pps, &info->ts, PPS_CAPTURECLEAR, data);
else
dev_warn_ratelimited(&info->pps->dev, "IRQ did not trigger any PPS event\n");
@@ -210,8 +221,10 @@ static int pps_gpio_probe(struct platform_device *pdev)
}
/* register IRQ interrupt handler */
- ret = request_irq(data->irq, pps_gpio_irq_handler,
- get_irqf_trigger_flags(data), data->info.name, data);
+ ret = request_threaded_irq(data->irq,
+ pps_gpio_irq_hardirq, pps_gpio_irq_thread,
+ get_irqf_trigger_flags(data) | IRQF_ONESHOT,
+ data->info.name, data);
if (ret) {
pps_unregister_source(data->pps);
dev_err(dev, "failed to acquire IRQ %d\n", data->irq);
--
2.47.3
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v7 1/1] pps: pps-gpio: split IRQ handler into hardirq timestamper + threaded handler
2026-06-02 0:44 ` [PATCH v7 1/1] pps: pps-gpio: split IRQ handler into hardirq timestamper + threaded handler Calvin Owens
@ 2026-06-02 6:36 ` Sebastian Andrzej Siewior
2026-06-03 17:29 ` Michael Byczkowski
0 siblings, 1 reply; 4+ messages in thread
From: Sebastian Andrzej Siewior @ 2026-06-02 6:36 UTC (permalink / raw)
To: Calvin Owens
Cc: linux-kernel, linux-rt-devel, Rodolfo Giometti, Clark Williams,
Steven Rostedt, Greg Kroah-Hartman, Eliav Farber,
Michael Byczkowski, Ingo Molnar, David Laight, Thomas Gleixner
On 2026-06-01 17:44:09 [-0700], Calvin Owens wrote:
> From: Michael Byczkowski <by@by-online.de>
>
> Split the pps-gpio interrupt handler into a primary (hardirq) handler
> that captures the PPS timestamp at interrupt entry, and a threaded
> handler that processes the event. This produces the same two-part
> handler structure on both PREEMPT_RT and non-RT kernels.
>
> On non-RT kernels the threaded portion runs immediately after the
> primary, with no behavioral change compared to the previous
> single-handler implementation.
>
> On PREEMPT_RT, where interrupt handlers are force-threaded by default,
> the previous single-handler implementation captured the timestamp
> inside the threaded portion, after IRQ-thread scheduling delay. With
> the split, the timestamp is captured in true hardirq context as it is
> on non-RT kernels, eliminating a significant source of PPS jitter on
> RT systems.
>
> Tested-by: Michael Byczkowski <by@by-online.de>
> Tested-by: Calvin Owens <calvin@wbinvd.org>
> Acked-by: Rodolfo Giometti <giometti@enneenne.com>
> Signed-off-by: Michael Byczkowski <by@by-online.de>
> Signed-off-by: Calvin Owens <calvin@wbinvd.org>
> ---
Reviewed-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Sebastian
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v7 1/1] pps: pps-gpio: split IRQ handler into hardirq timestamper + threaded handler
2026-06-02 6:36 ` Sebastian Andrzej Siewior
@ 2026-06-03 17:29 ` Michael Byczkowski
0 siblings, 0 replies; 4+ messages in thread
From: Michael Byczkowski @ 2026-06-03 17:29 UTC (permalink / raw)
To: Sebastian Andrzej Siewior
Cc: Calvin Owens, linux-kernel, linux-rt-devel, Rodolfo Giometti,
Clark Williams, Steven Rostedt, Greg Kroah-Hartman, Eliav Farber,
Ingo Molnar, David Laight, Thomas Gleixner
Thank you Sebastian, and thank you Calvin for relaying. I appreciate the
thorough review that got this to the right shape.
Best regards,
Michael
> On 2. Jun 2026, at 08:36, Sebastian Andrzej Siewior <bigeasy@linutronix.de> wrote:
>
> On 2026-06-01 17:44:09 [-0700], Calvin Owens wrote:
>> From: Michael Byczkowski <by@by-online.de>
>>
>> Split the pps-gpio interrupt handler into a primary (hardirq) handler
>> that captures the PPS timestamp at interrupt entry, and a threaded
>> handler that processes the event. This produces the same two-part
>> handler structure on both PREEMPT_RT and non-RT kernels.
>>
>> On non-RT kernels the threaded portion runs immediately after the
>> primary, with no behavioral change compared to the previous
>> single-handler implementation.
>>
>> On PREEMPT_RT, where interrupt handlers are force-threaded by default,
>> the previous single-handler implementation captured the timestamp
>> inside the threaded portion, after IRQ-thread scheduling delay. With
>> the split, the timestamp is captured in true hardirq context as it is
>> on non-RT kernels, eliminating a significant source of PPS jitter on
>> RT systems.
>>
>> Tested-by: Michael Byczkowski <by@by-online.de>
>> Tested-by: Calvin Owens <calvin@wbinvd.org>
>> Acked-by: Rodolfo Giometti <giometti@enneenne.com>
>> Signed-off-by: Michael Byczkowski <by@by-online.de>
>> Signed-off-by: Calvin Owens <calvin@wbinvd.org>
>> ---
>
> Reviewed-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
>
> Sebastian
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-06-03 17:30 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-02 0:44 [PATCH v7 0/1] pps: improve PREEMPT_RT performance Calvin Owens
2026-06-02 0:44 ` [PATCH v7 1/1] pps: pps-gpio: split IRQ handler into hardirq timestamper + threaded handler Calvin Owens
2026-06-02 6:36 ` Sebastian Andrzej Siewior
2026-06-03 17:29 ` Michael Byczkowski
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.