[PATCH 00/24] timekeeping: Rework to prepare support of indenpendent PTP clocks

From: Anna-Maria Behnsen
Date: Wed Sep 11 2024 - 09:31:44 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. (See
https://lore.kernel.org/r/20240911-devel-anna-maria-b4-timers-ptp-ntp-v1-0-2d52f4e13476@xxxxxxxxxxxxx)

Even without the future 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 timekeeping:

- Patch 1-5: Basic cleanups
- Patch 6-10: Generalization of tk_data
- Patch 11-24: Use always shadow timekeeper for updates

The queue is available here:

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

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 (16):
timekeeping: Avoid duplicate leap state update
timekeeping: Move timekeeper_lock into tk_core
timekeeping: Define a struct type for tk_core to make it reusable
timekeeping: Add struct tk_data as argument to timekeeping_update()
timekeeping: Split out timekeeper update of timekeeping_advanced()
timekeeping: Introduce combined timekeeping action flag
timekeeping: Rework do_settimeofday64() to use shadow_timekeeper
timekeeping: Rework timekeeping_inject_offset() to use shadow_timekeeper
timekeeping: Rework change_clocksource() to use shadow_timekeeper
timekeeping: Rework timekeeping_init() to use shadow_timekeeper
timekeeping: Rework timekeeping_inject_sleeptime64() to use shadow_timekeeper
timekeeping: Rework timekeeping_resume() to use shadow_timekeeper
timekeeping: Rework timekeeping_suspend() to use shadow_timekeeper
timekeeping: Rework do_adjtimex() to use shadow_timekeeper
timekeeping: Remove TK_MIRROR timekeeping_update() action
timekeeping: Merge timekeeping_update_staged() and timekeeping_update()

Thomas Gleixner (8):
timekeeping: Read NTP tick length only once
timekeeping: Don't stop time readers across hard_pps() update
timekeeping: Abort clocksource change in case of failure
timekeeping: Simplify code in timekeeping_advance()
timekeeping: Reorder struct timekeeper
timekeeping: Move shadow_timekeeper into tk_core
timekeeping: Encapsulate locking/unlocking of timekeeper_lock
timekeeping: Provide timekeeping_restore_shadow()

include/linux/timekeeper_internal.h | 102 ++++++----
kernel/time/timekeeping.c | 369 +++++++++++++++++-------------------
kernel/time/timekeeping_internal.h | 3 +-
kernel/time/vsyscall.c | 5 +-
4 files changed, 238 insertions(+), 241 deletions(-)