Skip to content

timekeeping: Provide support for auxiliary timekeepers

Thomas Gleixner lkml netdev 2 versions – Applied

Status from this message: The following commit has been merged into the timers/ptp branch of tip:

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest26 patches 15 repliesApplied
  2. v126 patches 5 repliesSuperseded

Changes in v2 from the cover letter

- Rename to auxiliary clocks/timekeepers - Miroslav

- Fix the sysfs documentation - Antoine

Patches in v2 Applied

#Subject and filesSizeRepliesApplied
1/26timekeeping: Remove hardcoded access to tk_corekernel/time/timekeeping.c+1 -11 reply
2/26timekeeping: Cleanup kernel doc of __ktime_get_real_seconds()kernel/time/timekeeping.c+8 -31 reply
3/26timekeeping: Avoid double notification in do_adjtimex()kernel/time/timekeeping.c+56 -420 replies
4/26timekeeping: Introduce timekeeper IDinclude/linux/timekeeper_internal.h kernel/time/timekeeping.c+16 -31 reply
5/26time: Introduce auxiliary POSIX clocksinclude/linux/timekeeper_internal.h include/uapi/linux/time.h kernel/time/Kconfig+30 -21 reply
6/26ntp: Add support for auxiliary timekeeperskernel/time/ntp.c+22 -192 replies
7/26ntp: Add timekeeper ID arguments to public functionskernel/time/ntp.c kernel/time/ntp_internal.h kernel/time/timekeeping.c+30 -261 reply
8/26ntp: Rename __do_adjtimex() to ntp_adjtimex()kernel/time/ntp.c kernel/time/ntp_internal.h kernel/time/timekeeping.c+5 -51 reply
9/26timekeeping: Make __timekeeping_advance() reusablekernel/time/timekeeping.c+6 -61 reply
10/26timekeeping: Prepare timekeeping_update_from_shadow()kernel/time/timekeeping.c+7 -50 replies
11/26timekeeping: Add clock_valid flag to timekeeperinclude/linux/timekeeper_internal.h kernel/time/timekeeping.c+5 -21 reply
12/26timekeeping: Introduce auxiliary timekeeperskernel/time/timekeeping.c+20 -21 reply
13/26timekeeping: Provide ktime_get_ntp_seconds()kernel/time/timekeeping.c kernel/time/timekeeping_internal.h+12 -00 replies
14/26ntp: Use ktime_get_ntp_seconds()kernel/time/ntp.c+2 -20 replies
15/26timekeeping: Add AUX offset to struct timekeeperinclude/linux/timekeeper_internal.h+5 -11 reply
16/26timekeeping: Update auxiliary timekeepers on clocksource changekernel/time/timekeeping.c+28 -00 replies
17/26timekeeping: Provide time getters for auxiliary clocksinclude/linux/timekeeping.h kernel/time/timekeeping.c+73 -02 replies
18/26timekeeping: Add minimal posix-timers support for auxiliary clockskernel/time/posix-timers.c kernel/time/posix-timers.h kernel/time/timekeeping.c+25 -00 replies
19/26timekeeping: Provide time setter for auxiliary clockskernel/time/timekeeping.c+39 -00 replies
20/26timekeeping: Make timekeeping_inject_offset() reusablekernel/time/timekeeping.c+15 -110 replies
21/26timekeeping: Add auxiliary clock support to __timekeeping_inject_offset()kernel/time/timekeeping.c+26 -80 replies
22/26timekeeping: Make do_adjtimex() reusablekernel/time/timekeeping.c+60 -500 replies
23/26timekeeping: Prepare do_adtimex() for auxiliary clockskernel/time/timekeeping.c+36 -30 replies
24/26timekeeping: Provide adjtimex() for auxiliary clockskernel/time/timekeeping.c+16 -00 replies
25/26timekeeping: Provide update for auxiliary timekeeperskernel/time/timekeeping.c+18 -00 replies
26/26timekeeping: Provide interface to control auxiliary clocksDocumentation/ABI/stable/sysfs-kernel-time-aux-clocks kernel/time/timekeeping.c+130 -01 reply

Reviews trailers per patch

11 of 26 patches have a Reviewed-by or Acked-by.

PatchJohn Stultz
1/26A-b
2/26A-b
3/26
4/26A-b
5/26A-b
6/26A-b
7/26A-b
8/26A-b
9/26A-b
10/26
11/26A-b
12/26A-b
13/26
14/26
15/26A-b
16/26
17/26
18/26
19/26
20/26
21/26
22/26
23/26
24/26
25/26
26/26

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v2 thread

Cover letter [patch V2 00/26] timekeeping: Provide support for auxiliary timekeepers

This is an update to the initial series, which can be found here:

     https://lore.kernel.org/all/[email protected]

The kernel supports PTP clocks pretty well at the hardware level and the ability to steer the core time keeper, but there is a major gap for other PTP use cases especially in the context of TSN.

TSN use cases in automation, automotive, audio and other areas utilize PTP for synchronizing nodes in a network accurately, but the underlying master clock is not necessarily related to clock TAI. They are completely independent and just represent a common notion of time in a network for an application specific purpose. This comes with problems obvioulsy:

1) Applications have no fast access to the time of such independent PTP clocks. The only way is to utilize the file descriptor of the PTP device with clock_gettime(). That's slow as it has to go all the way out to the hardware.

2) The network stack cannot access PTP time at all because accessing the PTP hardware requires preemptible task context in quite some cases.

There has been attempts to solve this by creating a new PTP specific infrastructure independent of the core timekeeping code, but that's a patently bad idea as it would just create duplicated code with new bugs and also be in the way of supporting these clocks in the VDSO and hrtimers based on such clocks down the road.

This series addresses the timekeeping part by utilizing the existing timekeeping and NTP infrastructure, which has been prepared for multi-instance in recent kernels.

The approach is the same as for core timekeeping:

The clock readout uses the system clocksource, e.g. TSC, ARM architected timer..., and converts it to a "nanoseconds" timestamp with the underlying conversion factors.

The conversion factors are steered via clock_adjtimex(2) to provide the required accuracy. That means tools like chrony can be reused with a small amount of modifications.

The infrastructure supports up to eight auxiliary clocks and timekeepers, which can be accessed by the new CLOCK_AUX0 .. CLOCK_AUX7 POSIX clock IDs.

The timekeepers are off by default and can be individually enabled/disabled via a new sysfs interface. In the disabled case the overhead introduced by these timekeepers is practically zero. Only if enabled, the periodic update in the timekeeper tick adds extra work.

The infrastructure provides:

1) In-kernel time getter interfaces similar to the existing ktime_get*() interfaces. The main difference is that they have a boolean return value, which indicates whether the clock is enabled and valid. These interfaces are lockless and sequence count protected as the other ktime_get*() variants, so the same restrictions apply (not usable from the timekeeper context or from NMI).

2) clock_gettime() support

Same as the existing clock_gettime() for CLOCK_..., but returns -ENODEV if the clock is disabled.

3) clock_settime() support

Same as clock_settime(CLOCK_REALTIME), but does not affect the system timekeeping

4) clock_adjtime() support

Same as clock_settime(CLOCK_REALTIME), but does not affect the system timekeeping. It has some restrictions: no support for PPS, leap seconds and other tiny details which are only relevant for CLOCK_REALTIME steering.

The timekeeper updates for these auxiliary clocks are not yet propagated to VDSO and paravirt interfaces as this has to be addressed separately once the core infrastructure is in place. Thomas W. has a prototype implementation for the VDSO support ready, which will be posted once the dust has settled here.

Once the timekeeping infrastructure is in place, the road is paved for supporting hrtimers on these clocks, which is another problem in the context of applications and the network stack. The idea is to convert the independent expiry time to clock MONOTONIC internally under the assumption that both involved clocks will have halfways stable conversion factors within the expiry time of the timer. If one of the clocks starts to jump around via their respective clock_adjtime(2) steering, then there are bigger problems to solve than a timer expiring late. But that's just an concept in my head and on some scribbled notes. It will take some time to materialize. But let's get the timekeeping part sorted first. :)

Changes from V1:

- Rename to auxiliary clocks/timekeepers - Miroslav

- Fix the sysfs documentation - Antoine

The series applies on top of 6.15-rc7 + tip timers/core and is available from git:

git://git.kernel.org/pub/scm/linux/kernel/git/tglx/devel.git timers/ptp/clocks

Thanks,

tglx

---
 Documentation/ABI/stable/sysfs-kernel-time-aux-clocks |    5 
 include/linux/timekeeper_internal.h                   |   28 
 include/linux/timekeeping.h                           |   11 
 include/uapi/linux/time.h                             |   11 
 kernel/time/Kconfig                                   |   15 
 kernel/time/ntp.c                                     |   72 +-
 kernel/time/ntp_internal.h                            |   13 
 kernel/time/posix-timers.c                            |    3 
 kernel/time/posix-timers.h                            |    1 
 kernel/time/timekeeping.c                             |  576 +++++++++++++++---
 kernel/time/timekeeping_internal.h                    |    3 
 11 files changed, 619 insertions(+), 119 deletions(-)