Thomas Gleixner
c85f5ab608
ntp: Use ktime_get_ntp_seconds()
...
Use ktime_get_ntp_seconds() to prepare for auxiliary clocks so that
the readout becomes per timekeeper.
Signed-off-by: Thomas Gleixner <tglx@linutronix.de >
Link: https://lore.kernel.org/all/20250519083026.472512636@linutronix.de
2025-06-19 14:28:24 +02:00
Thomas Gleixner
c7ebfbc440
ntp: Rename __do_adjtimex() to ntp_adjtimex()
...
Clean up the name space. No functional change.
Signed-off-by: Thomas Gleixner <tglx@linutronix.de >
Acked-by: John Stultz <jstultz@google.com >
Link: https://lore.kernel.org/all/20250519083026.095637820@linutronix.de
2025-06-19 14:28:23 +02:00
Thomas Gleixner
5ffa25f573
ntp: Add timekeeper ID arguments to public functions
...
In preparation for supporting auxiliary POSIX clocks, add a timekeeper ID
to the relevant functions.
Signed-off-by: Thomas Gleixner <tglx@linutronix.de >
Acked-by: John Stultz <jstultz@google.com >
Link: https://lore.kernel.org/all/20250519083026.032425931@linutronix.de
2025-06-19 14:28:23 +02:00
Thomas Gleixner
8515714b0f
ntp: Add support for auxiliary timekeepers
...
If auxiliary clocks are enabled, provide an array of NTP data so that the
auxiliary timekeepers can be steered independently of the core timekeeper.
Signed-off-by: Thomas Gleixner <tglx@linutronix.de >
Acked-by: John Stultz <jstultz@google.com >
Link: https://lore.kernel.org/all/20250519083025.969000914@linutronix.de
2025-06-19 14:28:22 +02:00
Nam Cao and Thomas Gleixner
f66b0acf39
time: Switch to hrtimer_setup()
...
hrtimer_setup() takes the callback function pointer as argument and
initializes the timer completely.
Replace hrtimer_init() and the open coded initialization of
hrtimer::function with the new setup mechanism.
Signed-off-by: Nam Cao <namcao@linutronix.de >
Signed-off-by: Thomas Gleixner <tglx@linutronix.de >
Link: https://lore.kernel.org/all/170bb691a0d59917c8268a98c80b607128fc9f7f.1738746821.git.namcao@linutronix.de
2025-02-18 10:32:33 +01:00
Marcelo Dalmas and Thomas Gleixner
f5807b0606
ntp: Remove invalid cast in time offset math
...
Due to an unsigned cast, adjtimex() returns the wrong offest when using
ADJ_MICRO and the offset is negative. In this case a small negative offset
returns approximately 4.29 seconds (~ 2^32/1000 milliseconds) due to the
unsigned cast of the negative offset.
This cast was added when the kernel internal struct timex was changed to
use type long long for the time offset value to address the problem of a
64bit/32bit division on 32bit systems.
The correct cast would have been (s32), which is correct as time_offset can
only be in the range of [INT_MIN..INT_MAX] because the shift constant used
for calculating it is 32. But that's non-obvious.
Remove the cast and use div_s64() to cure the issue.
[ tglx: Fix white space damage, use div_s64() and amend the change log ]
Fixes: ead25417f8 ("timex: use __kernel_timex internally")
Signed-off-by: Marcelo Dalmas <marcelo.dalmas@ge.com >
Signed-off-by: Thomas Gleixner <tglx@linutronix.de >
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/all/SJ0P101MB03687BF7D5A10FD3C49C51E5F42E2@SJ0P101MB0368.NAMP101.PROD.OUTLOOK.COM
2024-11-28 12:02:38 +01:00
Thomas Gleixner
6fadb4a61d
ntp: Move pps monitors into ntp_data
...
Finalize the conversion from static variables to struct based data.
No functional change.
Signed-off-by: Thomas Gleixner <tglx@linutronix.de >
Signed-off-by: Anna-Maria Behnsen <anna-maria@linutronix.de >
Signed-off-by: Thomas Gleixner <tglx@linutronix.de >
Acked-by: John Stultz <jstultz@google.com >
Link: https://lore.kernel.org/all/20240911-devel-anna-maria-b4-timers-ptp-ntp-v1-21-2d52f4e13476@linutronix.de
2024-10-02 16:53:41 +02:00
Thomas Gleixner
12850b4658
ntp: Move pps_freq/stabil into ntp_data
...
Continue the conversion from static variables to struct based data.
No functional change.
Signed-off-by: Thomas Gleixner <tglx@linutronix.de >
Signed-off-by: Anna-Maria Behnsen <anna-maria@linutronix.de >
Signed-off-by: Thomas Gleixner <tglx@linutronix.de >
Acked-by: John Stultz <jstultz@google.com >
Link: https://lore.kernel.org/all/20240911-devel-anna-maria-b4-timers-ptp-ntp-v1-20-2d52f4e13476@linutronix.de
2024-10-02 16:53:41 +02:00
Thomas Gleixner
b1c89a762f
ntp: Move pps_shift/intcnt into ntp_data
...
Continue the conversion from static variables to struct based data.
No functional change.
Signed-off-by: Thomas Gleixner <tglx@linutronix.de >
Signed-off-by: Anna-Maria Behnsen <anna-maria@linutronix.de >
Signed-off-by: Thomas Gleixner <tglx@linutronix.de >
Acked-by: John Stultz <jstultz@google.com >
Link: https://lore.kernel.org/all/20240911-devel-anna-maria-b4-timers-ptp-ntp-v1-19-2d52f4e13476@linutronix.de
2024-10-02 16:53:40 +02:00
Thomas Gleixner
db45e9bce8
ntp: Move pps_fbase into ntp_data
...
Continue the conversion from static variables to struct based data.
No functional change.
Signed-off-by: Thomas Gleixner <tglx@linutronix.de >
Signed-off-by: Anna-Maria Behnsen <anna-maria@linutronix.de >
Signed-off-by: Thomas Gleixner <tglx@linutronix.de >
Acked-by: John Stultz <jstultz@google.com >
Link: https://lore.kernel.org/all/20240911-devel-anna-maria-b4-timers-ptp-ntp-v1-18-2d52f4e13476@linutronix.de
2024-10-02 16:53:40 +02:00
Thomas Gleixner
9d7130dfc0
ntp: Move pps_jitter into ntp_data
...
Continue the conversion from static variables to struct based data.
No functional change.
Signed-off-by: Thomas Gleixner <tglx@linutronix.de >
Signed-off-by: Anna-Maria Behnsen <anna-maria@linutronix.de >
Signed-off-by: Thomas Gleixner <tglx@linutronix.de >
Acked-by: John Stultz <jstultz@google.com >
Link: https://lore.kernel.org/all/20240911-devel-anna-maria-b4-timers-ptp-ntp-v1-17-2d52f4e13476@linutronix.de
2024-10-02 16:53:40 +02:00
Thomas Gleixner
5cc953b8ae
ntp: Move pps_ft into ntp_data
...
Continue the conversion from static variables to struct based data.
No functional change.
Signed-off-by: Thomas Gleixner <tglx@linutronix.de >
Signed-off-by: Anna-Maria Behnsen <anna-maria@linutronix.de >
Signed-off-by: Thomas Gleixner <tglx@linutronix.de >
Acked-by: John Stultz <jstultz@google.com >
Link: https://lore.kernel.org/all/20240911-devel-anna-maria-b4-timers-ptp-ntp-v1-16-2d52f4e13476@linutronix.de
2024-10-02 16:53:40 +02:00
Thomas Gleixner
931a177f70
ntp: Move pps_valid into ntp_data
...
Continue the conversion from static variables to struct based data.
No functional change.
Signed-off-by: Thomas Gleixner <tglx@linutronix.de >
Signed-off-by: Anna-Maria Behnsen <anna-maria@linutronix.de >
Signed-off-by: Thomas Gleixner <tglx@linutronix.de >
Acked-by: John Stultz <jstultz@google.com >
Link: https://lore.kernel.org/all/20240911-devel-anna-maria-b4-timers-ptp-ntp-v1-15-2d52f4e13476@linutronix.de
2024-10-02 16:53:40 +02:00
Thomas Gleixner
75d956b947
ntp: Move ntp_next_leap_sec into ntp_data
...
Continue the conversion from static variables to struct based data.
No functional change.
Signed-off-by: Thomas Gleixner <tglx@linutronix.de >
Signed-off-by: Anna-Maria Behnsen <anna-maria@linutronix.de >
Signed-off-by: Thomas Gleixner <tglx@linutronix.de >
Acked-by: John Stultz <jstultz@google.com >
Link: https://lore.kernel.org/all/20240911-devel-anna-maria-b4-timers-ptp-ntp-v1-14-2d52f4e13476@linutronix.de
2024-10-02 16:53:40 +02:00
Thomas Gleixner
bb6400a298
ntp: Move time_adj/ntp_tick_adj into ntp_data
...
Continue the conversion from static variables to struct based data.
No functional change.
Signed-off-by: Thomas Gleixner <tglx@linutronix.de >
Signed-off-by: Anna-Maria Behnsen <anna-maria@linutronix.de >
Signed-off-by: Thomas Gleixner <tglx@linutronix.de >
Acked-by: John Stultz <jstultz@google.com >
Link: https://lore.kernel.org/all/20240911-devel-anna-maria-b4-timers-ptp-ntp-v1-13-2d52f4e13476@linutronix.de
2024-10-02 16:53:40 +02:00
Thomas Gleixner
161b8ec281
ntp: Move time_freq/reftime into ntp_data
...
Continue the conversion from static variables to struct based data.
No functional change.
Signed-off-by: Thomas Gleixner <tglx@linutronix.de >
Signed-off-by: Anna-Maria Behnsen <anna-maria@linutronix.de >
Signed-off-by: Thomas Gleixner <tglx@linutronix.de >
Acked-by: John Stultz <jstultz@google.com >
Link: https://lore.kernel.org/all/20240911-devel-anna-maria-b4-timers-ptp-ntp-v1-12-2d52f4e13476@linutronix.de
2024-10-02 16:53:40 +02:00
Thomas Gleixner
7891cf2961
ntp: Move time_max/esterror into ntp_data
...
Continue the conversion from static variables to struct based data.
No functional change.
Signed-off-by: Thomas Gleixner <tglx@linutronix.de >
Signed-off-by: Anna-Maria Behnsen <anna-maria@linutronix.de >
Signed-off-by: Thomas Gleixner <tglx@linutronix.de >
Acked-by: John Stultz <jstultz@google.com >
Link: https://lore.kernel.org/all/20240911-devel-anna-maria-b4-timers-ptp-ntp-v1-11-2d52f4e13476@linutronix.de
2024-10-02 16:53:39 +02:00
Thomas Gleixner
d51435548e
ntp: Move time_offset/constant into ntp_data
...
Continue the conversion from static variables to struct based data.
No functional change.
Signed-off-by: Thomas Gleixner <tglx@linutronix.de >
Signed-off-by: Anna-Maria Behnsen <anna-maria@linutronix.de >
Signed-off-by: Thomas Gleixner <tglx@linutronix.de >
Acked-by: John Stultz <jstultz@google.com >
Link: https://lore.kernel.org/all/20240911-devel-anna-maria-b4-timers-ptp-ntp-v1-10-2d52f4e13476@linutronix.de
2024-10-02 16:53:39 +02:00
Thomas Gleixner
bee18a2301
ntp: Move tick_stat* into ntp_data
...
Continue the conversion from static variables to struct based data.
No functional change.
Signed-off-by: Thomas Gleixner <tglx@linutronix.de >
Signed-off-by: Anna-Maria Behnsen <anna-maria@linutronix.de >
Signed-off-by: Thomas Gleixner <tglx@linutronix.de >
Acked-by: John Stultz <jstultz@google.com >
Link: https://lore.kernel.org/all/20240911-devel-anna-maria-b4-timers-ptp-ntp-v1-9-2d52f4e13476@linutronix.de
2024-10-02 16:53:39 +02:00
Thomas Gleixner
ec93ec22aa
ntp: Move tick_length* into ntp_data
...
Continue the conversion from static variables to struct based data.
No functional change.
Signed-off-by: Thomas Gleixner <tglx@linutronix.de >
Signed-off-by: Anna-Maria Behnsen <anna-maria@linutronix.de >
Signed-off-by: Thomas Gleixner <tglx@linutronix.de >
Acked-by: John Stultz <jstultz@google.com >
Link: https://lore.kernel.org/all/20240911-devel-anna-maria-b4-timers-ptp-ntp-v1-8-2d52f4e13476@linutronix.de
2024-10-02 16:53:39 +02:00
Thomas Gleixner
68f66f97c5
ntp: Introduce struct ntp_data
...
All NTP data is held in static variables. That prevents the NTP code from
being reuasble for non-system time timekeepers, e.g. per PTP clock
timekeeping.
Introduce struct ntp_data and move tick_usec into it for a start.
No functional change.
Signed-off-by: Thomas Gleixner <tglx@linutronix.de >
Signed-off-by: Anna-Maria Behnsen <anna-maria@linutronix.de >
Signed-off-by: Thomas Gleixner <tglx@linutronix.de >
Acked-by: John Stultz <jstultz@google.com >
Link: https://lore.kernel.org/all/20240911-devel-anna-maria-b4-timers-ptp-ntp-v1-7-2d52f4e13476@linutronix.de
2024-10-02 16:53:39 +02:00
Thomas Gleixner
136bccbc2e
ntp: Read reference time only once
...
The reference time is required twice in ntp_update_offset(). It will not
change in the meantime as the calling code holds the timekeeper lock. Read
it only once and store it into a local variable.
Signed-off-by: Thomas Gleixner <tglx@linutronix.de >
Signed-off-by: Anna-Maria Behnsen <anna-maria@linutronix.de >
Signed-off-by: Thomas Gleixner <tglx@linutronix.de >
Acked-by: John Stultz <jstultz@google.com >
Link: https://lore.kernel.org/all/20240911-devel-anna-maria-b4-timers-ptp-ntp-v1-6-2d52f4e13476@linutronix.de
2024-10-02 16:53:39 +02:00
Thomas Gleixner
48c3c65f64
ntp: Convert functions with only two states to bool
...
is_error_status() and ntp_synced() return whether a state is set or
not. Both functions use unsigned int for it even if it would be a perfect
job for a bool.
Use bool instead of unsigned int. And while at it, move ntp_synced()
function to the place where it is used.
No functional change.
Signed-off-by: Thomas Gleixner <tglx@linutronix.de >
Signed-off-by: Anna-Maria Behnsen <anna-maria@linutronix.de >
Signed-off-by: Thomas Gleixner <tglx@linutronix.de >
Acked-by: John Stultz <jstultz@google.com >
Link: https://lore.kernel.org/all/20240911-devel-anna-maria-b4-timers-ptp-ntp-v1-5-2d52f4e13476@linutronix.de
2024-10-02 16:53:39 +02:00
Anna-Maria Behnsen and Thomas Gleixner
38007dc032
ntp: Cleanup formatting of code
...
Code is partially formatted in a creative way which makes reading
harder. Examples are function calls over several lines where the
indentation does not start at the same height then the open bracket after
the function name.
Improve formatting but do not make a functional change.
Signed-off-by: Anna-Maria Behnsen <anna-maria@linutronix.de >
Signed-off-by: Thomas Gleixner <tglx@linutronix.de >
Acked-by: John Stultz <jstultz@google.com >
Link: https://lore.kernel.org/all/20240911-devel-anna-maria-b4-timers-ptp-ntp-v1-4-2d52f4e13476@linutronix.de
2024-10-02 16:53:38 +02:00
Thomas Gleixner
a0581cdb2e
ntp: Clean up comments
...
Usage of different comment formatting makes fast reading and parsing the
code harder. There are several multi-line comments which do not follow the
coding style by starting with a line only containing '/*'. There are also
comments which do not start with capitals.
Clean up all those comments to be consistent and remove comments which
document the obvious.
Signed-off-by: Thomas Gleixner <tglx@linutronix.de >
Signed-off-by: Anna-Maria Behnsen <anna-maria@linutronix.de >
Signed-off-by: Thomas Gleixner <tglx@linutronix.de >
Acked-by: John Stultz <jstultz@google.com >
Link: https://lore.kernel.org/all/20240911-devel-anna-maria-b4-timers-ptp-ntp-v1-3-2d52f4e13476@linutronix.de
2024-10-02 16:53:38 +02:00