[PATCH 00/21] ntp: Rework to prepare support of indenpendent PTP clocks

From: Anna-Maria Behnsen
Date: Wed Sep 11 2024 - 09:18:58 EST


The generic clock and timekeeping infrastructure supports only the already
defined clocks and as they are not independent there is no need of
generalization of data structures. But PTP clocks can be independent from
CLOCK_TAI.

PTP clocks already have clock_gettime() support via the file descriptor
based posix clocks. These interfaces access the PTP hardware and are
therefore slow and cannot be used from within the kernel, e.g. TSN
networking.

This problem can be solved by emulating clock_gettime() via the system
clock source e.g. TSC on x86. Such emulation requires:

1. timekeeping mechanism similar to the existing system timekeeping
2. clock steering equivalent to NTP/adjtimex()

In the already existing system timekeeping implementation the lock and
shadow timekeeper are separate from the timekeeper and sequence
counter. Move this information into a new struct type "tk_data" to be able
to recycle it for the above explained approach.

NTP/adjtimex() related information is all stored in static variables. Move
all of them into the new struct type ntp_data to make it reusable.

Even without the furture support for independent PTP clocks, the
generalization of timekeeping and NTP/adjtimex() improves the structure and
readability of the already existing code.

Once this is implemented clock_gettime() support for these clocks via vdso
can be implement as well but this is an orthogonal task.

This queue covers only the generalization of ntp:

- Patch 1-6: Basic cleanups
- Patch 7-21: Introduction of struct ntp_data and move all static variables
to the struct

The queue is available here:

git://git.kernel.org/pub/scm/linux/kernel/git/anna-maria/linux-devel.git timers/ptp/ntp

Cc: linux-kernel@xxxxxxxxxxxxxxx
Cc: netdev@xxxxxxxxxxxxxxx
Cc: Miroslav Lichvar <mlichvar@xxxxxxxxxx>
Cc: Richard Cochran <richardcochran@xxxxxxxxx>
Cc: Christopher S Hall <christopher.s.hall@xxxxxxxxx>
To: John Stultz <jstultz@xxxxxxxxxx>
To: Frederic Weisbecker <frederic@xxxxxxxxxx>
To: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
Signed-off-by: Anna-Maria Behnsen <anna-maria@xxxxxxxxxxxxx>

Thanks,

Anna-Maria

---
Anna-Maria Behnsen (1):
ntp: Cleanup formatting of code

Thomas Gleixner (20):
ntp: Remove unused tick_nsec
ntp: Make tick_usec static
ntp: Clean up comments
ntp: Convert functions with only two states to bool
ntp: Read reference time only once
ntp: Introduce struct ntp_data
ntp: Move tick_length* into ntp_data
ntp: Move tick_stat* into ntp_data
ntp: Move time_offset/constant into ntp_data
ntp: Move time_max/esterror into ntp_data
ntp: Move time_freq/reftime into ntp_data
ntp: Move time_adj/ntp_tick_adj into ntp_data
ntp: Move ntp_next_leap_sec into ntp_data
ntp: Move pps_valid into ntp_data
ntp: Move pps_ft into ntp_data
ntp: Move pps_jitter into ntp_data
ntp: Move pps_fbase into ntp_data
ntp: Move pps_shift/intcnt into ntp_data
ntp: Move pps_freq/stabil into ntp_data
ntp: Move pps monitors into ntp_data

arch/x86/include/asm/timer.h | 2 -
include/linux/timex.h | 8 -
kernel/time/ntp.c | 840 +++++++++++++++++++++----------------------
3 files changed, 419 insertions(+), 431 deletions(-)