mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] pps: improve PREEMPT_RT performance
@ 2026-04-06 12:11 Michael Byczkowski
  2026-04-06 15:28 ` Rodolfo Giometti
  2026-04-06 17:24 ` Calvin Owens
  0 siblings, 2 replies; 4+ messages in thread
From: Michael Byczkowski @ 2026-04-06 12:11 UTC (permalink / raw)
  To: giometti; +Cc: linux-kernel, akpm

Dear Rodolfo,

Andrew Morton pointed me your way as PPS maintainer. I'm running a
precision NTP time server on a Raspberry Pi 5 with a PREEMPT_RT kernel
and a u-blox ZED-F9P GPS receiver on a Rapsberry Pi HAT providing PPS via GPIO.

I found three areas 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).
  On non-RT kernels, request_threaded_irq with an explicit primary
  handler behaves identically to the current code.

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, which compiles to identical code on non-RT.

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 with a PPS-disciplined NTP server. They apply cleanly
against mainline. On non-RT kernels, raw_spinlock_t compiles identically
to spinlock_t, and request_threaded_irq with a primary handler works
the same as request_irq — so there is zero behavioral change for
non-RT users.

The patches are available as individual commits at:
 https://github.com/by/linux-PPS

[PATCH 1/3] pps: pps-gpio: split handler into hardirq timestamp and threaded processing
https://github.com/by/linux-PPS/commit/e811a4e6f63f39a782db2a2fe1588419de96275b

[PATCH 2/3] pps: convert pps_device lock to raw_spinlock for PREEMPT_RT
(covers include/linux/pps_kernel.h, drivers/pps/kapi.c, drivers/pps/pps.c)
https://github.com/by/linux-PPS/commit/918e6f9c87adc552bda3b9b5847eb535f943c68e
https://github.com/by/linux-PPS/commit/d1eb9d80768f6648ff4638b5f83028344f0860e9
https://github.com/by/linux-PPS/commit/1f149bf2c449a36730adb341fdf626ed07953f5f

[PATCH 3/3] pps: convert pps_kc_hardpps_lock to raw_spinlock for PREEMPT_RT
https://github.com/by/linux-PPS/commit/a37a12ed96c8d5d0d73ac9e8f43cf0118cc72c1c

Files changed:
 drivers/pps/clients/pps-gpio.c   (patch 1)
 include/linux/pps_kernel.h       (patch 2)
 drivers/pps/kapi.c               (patch 2)
 drivers/pps/pps.c                (patch 2)
 drivers/pps/kc.c                 (patch 3)

Signed-off-by: Michael Byczkowski <by@by-online.de>

And please forgive my complete lack of erperience in the kernel patch process, thanks.

Best regards,
	Michael


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] pps: improve PREEMPT_RT performance
  2026-04-06 12:11 [PATCH] pps: improve PREEMPT_RT performance Michael Byczkowski
@ 2026-04-06 15:28 ` Rodolfo Giometti
  2026-04-06 17:24 ` Calvin Owens
  1 sibling, 0 replies; 4+ messages in thread
From: Rodolfo Giometti @ 2026-04-06 15:28 UTC (permalink / raw)
  To: Michael Byczkowski; +Cc: linux-kernel, akpm

On 4/6/26 14:11, Michael Byczkowski wrote:
> Dear Rodolfo,
> 
> Andrew Morton pointed me your way as PPS maintainer. I'm running a
> precision NTP time server on a Raspberry Pi 5 with a PREEMPT_RT kernel
> and a u-blox ZED-F9P GPS receiver on a Rapsberry Pi HAT providing PPS via GPIO.
> 
> I found three areas 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).
>    On non-RT kernels, request_threaded_irq with an explicit primary
>    handler behaves identically to the current code.
> 
> 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, which compiles to identical code on non-RT.
> 
> 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 with a PPS-disciplined NTP server. They apply cleanly
> against mainline. On non-RT kernels, raw_spinlock_t compiles identically
> to spinlock_t, and request_threaded_irq with a primary handler works
> the same as request_irq — so there is zero behavioral change for
> non-RT users.
> 
> The patches are available as individual commits at:
>   https://github.com/by/linux-PPS
> 
> [PATCH 1/3] pps: pps-gpio: split handler into hardirq timestamp and threaded processing
> https://github.com/by/linux-PPS/commit/e811a4e6f63f39a782db2a2fe1588419de96275b

The patch looks good to me; please add your info 1 above within the patch 
description for better documentation and add my "Acked-by: Rodolfo Giometti 
<giometti@enneenne.com>" line in the new patch.

> [PATCH 2/3] pps: convert pps_device lock to raw_spinlock for PREEMPT_RT
> (covers include/linux/pps_kernel.h, drivers/pps/kapi.c, drivers/pps/pps.c)
> https://github.com/by/linux-PPS/commit/918e6f9c87adc552bda3b9b5847eb535f943c68e
> https://github.com/by/linux-PPS/commit/d1eb9d80768f6648ff4638b5f83028344f0860e9
> https://github.com/by/linux-PPS/commit/1f149bf2c449a36730adb341fdf626ed07953f5f

Please merge these patches and add my "Acked-by:" tag in the resulting patch.

> [PATCH 3/3] pps: convert pps_kc_hardpps_lock to raw_spinlock for PREEMPT_RT
> https://github.com/by/linux-PPS/commit/a37a12ed96c8d5d0d73ac9e8f43cf0118cc72c1c

Add my "Acked-by:" tag.

After that, resend the patchset as suggested by Andrew. Also, consider adding a 
"Tested-by" entry for the whole patchset.

Ciao,

Rodolfo

-- 
GNU/Linux Solutions                  e-mail: giometti@enneenne.com
Linux Device Driver                          giometti@linux.it
Embedded Systems                     phone:  +39 349 2432127
UNIX programming

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] pps: improve PREEMPT_RT performance
  2026-04-06 12:11 [PATCH] pps: improve PREEMPT_RT performance Michael Byczkowski
  2026-04-06 15:28 ` Rodolfo Giometti
@ 2026-04-06 17:24 ` Calvin Owens
  2026-04-06 20:46   ` Michael Byczkowski
  1 sibling, 1 reply; 4+ messages in thread
From: Calvin Owens @ 2026-04-06 17:24 UTC (permalink / raw)
  To: Michael Byczkowski; +Cc: giometti, linux-kernel, akpm

On Monday 04/06 at 14:11 +0200, Michael Byczkowski wrote:
> Dear Rodolfo,
> 
> Andrew Morton pointed me your way as PPS maintainer. I'm running a
> precision NTP time server on a Raspberry Pi 5 with a PREEMPT_RT kernel
> and a u-blox ZED-F9P GPS receiver on a Rapsberry Pi HAT providing PPS via GPIO.
> 
> I found three areas 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).
>   On non-RT kernels, request_threaded_irq with an explicit primary
>   handler behaves identically to the current code.
> 
> 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, which compiles to identical code on non-RT.
> 
> 3. pps_kc_hardpps_lock: Same issue as (2), in the kernel consumer path
>   that calls hardpps(). Fix: convert to DEFINE_RAW_SPINLOCK.

Hi Michael,

Thanks for working on this, and for the nice clean patches :)

Your series is happily running on my pps-gpio setup. When you resend
the patches, feel free to add:

Tested-by: Calvin Owens <calvin@wbinvd.org>

One quick thought below:

> All three patches are tested on a Raspberry Pi 5 running a 7.0.0-rc6
> PREEMPT_RT kernel with a PPS-disciplined NTP server. They apply cleanly
> against mainline. On non-RT kernels, raw_spinlock_t compiles identically
> to spinlock_t, and request_threaded_irq with a primary handler works
> the same as request_irq — so there is zero behavioral change for
> non-RT users.
> 
> The patches are available as individual commits at:
>  https://github.com/by/linux-PPS
> 
> [PATCH 1/3] pps: pps-gpio: split handler into hardirq timestamp and threaded processing
> https://github.com/by/linux-PPS/commit/e811a4e6f63f39a782db2a2fe1588419de96275b
> 
> [PATCH 2/3] pps: convert pps_device lock to raw_spinlock for PREEMPT_RT
> (covers include/linux/pps_kernel.h, drivers/pps/kapi.c, drivers/pps/pps.c)
> https://github.com/by/linux-PPS/commit/918e6f9c87adc552bda3b9b5847eb535f943c68e
> https://github.com/by/linux-PPS/commit/d1eb9d80768f6648ff4638b5f83028344f0860e9
> https://github.com/by/linux-PPS/commit/1f149bf2c449a36730adb341fdf626ed07953f5f

These should be combined into one commit to avoid bisection problems,
the intermediate states don't compile. But maybe you already intend to
do that, I see you've grouped them together here.

Cheers,
Calvin

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] pps: improve PREEMPT_RT performance
  2026-04-06 17:24 ` Calvin Owens
@ 2026-04-06 20:46   ` Michael Byczkowski
  0 siblings, 0 replies; 4+ messages in thread
From: Michael Byczkowski @ 2026-04-06 20:46 UTC (permalink / raw)
  To: Calvin Owens; +Cc: giometti, linux-kernel, akpm

Dear Calvin,

Thank you very much for your kind words, will do.

Best regards,
	Michael


> On 6. Apr 2026, at 19:24, Calvin Owens <calvin@wbinvd.org> wrote:
> 
> On Monday 04/06 at 14:11 +0200, Michael Byczkowski wrote:
>> Dear Rodolfo,
>> 
>> Andrew Morton pointed me your way as PPS maintainer. I'm running a
>> precision NTP time server on a Raspberry Pi 5 with a PREEMPT_RT kernel
>> and a u-blox ZED-F9P GPS receiver on a Rapsberry Pi HAT providing PPS via GPIO.
>> 
>> I found three areas 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).
>>  On non-RT kernels, request_threaded_irq with an explicit primary
>>  handler behaves identically to the current code.
>> 
>> 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, which compiles to identical code on non-RT.
>> 
>> 3. pps_kc_hardpps_lock: Same issue as (2), in the kernel consumer path
>>  that calls hardpps(). Fix: convert to DEFINE_RAW_SPINLOCK.
> 
> Hi Michael,
> 
> Thanks for working on this, and for the nice clean patches :)
> 
> Your series is happily running on my pps-gpio setup. When you resend
> the patches, feel free to add:
> 
> Tested-by: Calvin Owens <calvin@wbinvd.org>
> 
> One quick thought below:
> 
>> All three patches are tested on a Raspberry Pi 5 running a 7.0.0-rc6
>> PREEMPT_RT kernel with a PPS-disciplined NTP server. They apply cleanly
>> against mainline. On non-RT kernels, raw_spinlock_t compiles identically
>> to spinlock_t, and request_threaded_irq with a primary handler works
>> the same as request_irq — so there is zero behavioral change for
>> non-RT users.
>> 
>> The patches are available as individual commits at:
>> https://github.com/by/linux-PPS
>> 
>> [PATCH 1/3] pps: pps-gpio: split handler into hardirq timestamp and threaded processing
>> https://github.com/by/linux-PPS/commit/e811a4e6f63f39a782db2a2fe1588419de96275b
>> 
>> [PATCH 2/3] pps: convert pps_device lock to raw_spinlock for PREEMPT_RT
>> (covers include/linux/pps_kernel.h, drivers/pps/kapi.c, drivers/pps/pps.c)
>> https://github.com/by/linux-PPS/commit/918e6f9c87adc552bda3b9b5847eb535f943c68e
>> https://github.com/by/linux-PPS/commit/d1eb9d80768f6648ff4638b5f83028344f0860e9
>> https://github.com/by/linux-PPS/commit/1f149bf2c449a36730adb341fdf626ed07953f5f
> 
> These should be combined into one commit to avoid bisection problems,
> the intermediate states don't compile. But maybe you already intend to
> do that, I see you've grouped them together here.
> 
> Cheers,
> Calvin


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-04-06 20:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-04-06 12:11 [PATCH] pps: improve PREEMPT_RT performance Michael Byczkowski
2026-04-06 15:28 ` Rodolfo Giometti
2026-04-06 17:24 ` Calvin Owens
2026-04-06 20:46   ` Michael Byczkowski

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®