Re: [PATCH v5 0/3] pps: improve PREEMPT_RT performance

From: Michael Byczkowski

Date: Sat May 23 2026 - 14:06:22 EST


Hi Calvin,

Thank you again for offering to relay the series. v6 is ready,
addressing all of Sebastian's review feedback on v5.

Branch: https://github.com/by/linux-PPS/tree/pps-rt-v6
Tip SHA: 013781f19756a4c6ac9c91e83b3a74a52882b707
Base: 0d9363a764d9d601a05591f9695cea8b429e9be3
("Input: xpad - add support for BETOP BTP-KP50B/C
controller's wireless mode")

To regenerate:

git fetch https://github.com/by/linux-PPS.git pps-rt-v6
git format-patch -3 \
--cover-letter \
--thread \
--subject-prefix="PATCH v6" \
--base=0d9363a764d9d601a05591f9695cea8b429e9be3 \
FETCH_HEAD

If easier, I have the four .patch files generated locally and can
attach them on request.

checkpatch.pl is clean on all three patches (0 errors, 0 warnings).

Suggested recipients (per scripts/get_maintainer.pl):

To: Rodolfo Giometti <giometti@xxxxxxxxxxxx>
Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>

Cc: Sebastian Andrzej Siewior <bigeasy@xxxxxxxxxxxxx>
Clark Williams <clrkwllms@xxxxxxxxxx>
Steven Rostedt <rostedt@xxxxxxxxxxx>
Thomas Gleixner <tglx@xxxxxxxxxxxxx>
linux-kernel@xxxxxxxxxxxxxxx
linux-rt-devel@xxxxxxxxxxxxxxx

Please add yourself with Signed-off-by as the relayer; the patches
preserve my authorship via the From: line inside each patch.

Cover letter content for the 0000 file:

----------------------------------------------------------------
Subject: [PATCH v6 0/3] pps: improve PREEMPT_RT performance

This is v6 of the PPS PREEMPT_RT patchset, addressing the review
feedback from Sebastian Andrzej Siewior on v5.

Changes since v5:
- 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:
- Patch 2/3: added Acked-by: Rodolfo Giometti <giometti@xxxxxxxxxxxx>

Changes since v3:
- Patch 2/3: fixed lost indentation on pps_kc_event() call
(reported by Rodolfo Giometti <giometti@xxxxxxxxxxxx>)

Changes since v2:
- 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@xxxxxxxxxxxx>)

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).

2. pps_kc_hardpps_lock: spinlock_t becomes a sleeping mutex on
PREEMPT_RT. Since pps_kc_event() calls hardpps() under this lock
and hardpps() takes the raw_spinlock_t tk_core.lock, the nesting
is invalid. Fix: convert to DEFINE_RAW_SPINLOCK.

3. pps_device.lock: same issue as (2), in the PPS event delivery
path. Fix: convert to raw_spinlock_t and move sleeping calls out
of the critical section.

All three patches are 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.
----------------------------------------------------------------

Thank you again. Let me know if you hit anything unexpected.

Best regards,
Michael



> On 22. May 2026, at 17:56, Michael Byczkowski <by@xxxxxxxxxxxx> wrote:
>
> Dear Calvin,
>
> Thanks for picking this up, and yes, I’m actually a bit overwhelmed, so your help is much appreciated! And my apologies for the delay, I was traveling.
>
> The clean v5 series is at:
> https://github.com/by/linux-PPS/tree/pps-rt-v5-clean
>
> Three commits on top of torvalds 0d9363a764d9 (around v7.0-rc6):
> pps: pps-gpio: split IRQ handler into hardirq timestamper + threaded handler pps: convert pps_device.lock to raw_spinlock_t pps: kc: convert pps_kc_hardpps_lock to raw_spinlock_t
>
> Your suspicion about Apple Mail was correct: I diffed the GitHub branch against the lore mbox and the sent version has quoted-printable damage which would explain why nobody could git am it cleanly. The GitHub branch is the ground truth.
>
> Let me know how you'd like to proceed.
> Lore thread for context: https://lore.kernel.org/lkml/719A31CE-CA58-45C3-A013-1BFE81F724C5@xxxxxxxxxxxx/
>
> Thanks and best regards,
> Michael
>
>
>> On 19. May 2026, at 18:19, Calvin Owens <calvin@xxxxxxxxxx> wrote:
>>
>> On Saturday 05/16 at 13:32 +0200, Michael Byczkowski wrote:
>>>> On 25. Apr 2026, at 19:18, Michael Byczkowski <by@xxxxxxxxxxxx> wrote:
>>>>
>>>> I found three issues in the PPS subsystem that cause unnecessary 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).
>>>>
>>>> 2. pps_device.lock: spinlock_t becomes a sleeping mutex on PREEMPT_RT,
>>>> allowing pps_event() to be preempted mid-update. Fix: convert to
>>>> raw_spinlock_t and move sleeping calls out of the critical section.
>>>>
>>>> 3. pps_kc_hardpps_lock: Same issue as (2), in the kernel consumer path
>>>> that calls hardpps(). Fix: convert to DEFINE_RAW_SPINLOCK.
>>>>
>>>> All three patches are tested on a Raspberry Pi 5 running a 7.0.0-rc6
>>>> PREEMPT_RT kernel. On non-RT kernels there is zero behavioral change.
>>>>
>>>> Signed-off-by: Michael Byczkowski <by@xxxxxxxxxxxx>
>>>> Acked-by: Rodolfo Giometti <giometti@xxxxxxxxxxxx>
>>>> Tested-by: Michael Byczkowski <by@xxxxxxxxxxxx>
>>>>
>>>> by (3):
>>>> pps: pps-gpio: split IRQ handler into hardirq and threaded parts
>>>> pps: convert pps_device lock to raw_spinlock for PREEMPT_RT
>>>> pps: convert pps_kc_hardpps_lock to raw_spinlock for PREEMPT_RT
>>>>
>>>> drivers/pps/clients/pps-gpio.c | 37 +++++++++++++++++++++++-----------
>>>> drivers/pps/kapi.c | 18 ++++++++++-------
>>>> drivers/pps/kc.c | 22 ++++++++++----------
>>>> drivers/pps/pps.c | 16 +++++++--------
>>>> include/linux/pps_kernel.h | 2 +-
>>>> 5 files changed, 56 insertions(+), 39 deletions(-)
>>>>
>>>> --
>>>> 2.47.3
>>>
>>> Gentle ping on this series. v4 patches 1/3 and 3/3 carried Rodolfo's
>>> Acked-by; v5 addressed the remaining feedback on 2/3. Happy to rework
>>> anything or split the series if that helps it move forward.
>>
>> Unfortunately apple mail is corrupting your patches :/
>>
>> Greg KH usually applies patches for drivers/pps/, but I didn't add him
>> here yet because the patches don't apply.
>>
>> If you can point me at a git branch for v5, I'd be happy to re-send the
>> patches myself with your authorship. This is all useful for me and I'd
>> like to help :)
>>
>> If you do it yourself, just make sure to add Greg to the Cc: list.
>>
>> Cheers,
>> Calvin
>>
>>> Adding linux-rt-users@ and Sebastian on Cc in case there's interest from the
>>> PREEMPT_RT side.
>