Skip to content

Commit 5ffa25f

Browse files
committed
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
1 parent 8515714 commit 5ffa25f

3 files changed

Lines changed: 30 additions & 26 deletions

File tree

kernel/time/ntp.c

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -351,33 +351,38 @@ static void __ntp_clear(struct ntp_data *ntpdata)
351351

352352
/**
353353
* ntp_clear - Clears the NTP state variables
354+
* @tkid: Timekeeper ID to be able to select proper ntp data array member
354355
*/
355-
void ntp_clear(void)
356+
void ntp_clear(unsigned int tkid)
356357
{
357-
__ntp_clear(&tk_ntp_data[TIMEKEEPER_CORE]);
358+
__ntp_clear(&tk_ntp_data[tkid]);
358359
}
359360

360361

361-
u64 ntp_tick_length(void)
362+
u64 ntp_tick_length(unsigned int tkid)
362363
{
363-
return tk_ntp_data[TIMEKEEPER_CORE].tick_length;
364+
return tk_ntp_data[tkid].tick_length;
364365
}
365366

366367
/**
367368
* ntp_get_next_leap - Returns the next leapsecond in CLOCK_REALTIME ktime_t
369+
* @tkid: Timekeeper ID
368370
*
369-
* Provides the time of the next leapsecond against CLOCK_REALTIME in
370-
* a ktime_t format. Returns KTIME_MAX if no leapsecond is pending.
371+
* Returns: For @tkid == TIMEKEEPER_CORE this provides the time of the next
372+
* leap second against CLOCK_REALTIME in a ktime_t format if a
373+
* leap second is pending. KTIME_MAX otherwise.
371374
*/
372-
ktime_t ntp_get_next_leap(void)
375+
ktime_t ntp_get_next_leap(unsigned int tkid)
373376
{
374377
struct ntp_data *ntpdata = &tk_ntp_data[TIMEKEEPER_CORE];
375-
ktime_t ret;
378+
379+
if (tkid != TIMEKEEPER_CORE)
380+
return KTIME_MAX;
376381

377382
if ((ntpdata->time_state == TIME_INS) && (ntpdata->time_status & STA_INS))
378383
return ktime_set(ntpdata->ntp_next_leap_sec, 0);
379-
ret = KTIME_MAX;
380-
return ret;
384+
385+
return KTIME_MAX;
381386
}
382387

383388
/*
@@ -390,9 +395,9 @@ ktime_t ntp_get_next_leap(void)
390395
*
391396
* Also handles leap second processing, and returns leap offset
392397
*/
393-
int second_overflow(time64_t secs)
398+
int second_overflow(unsigned int tkid, time64_t secs)
394399
{
395-
struct ntp_data *ntpdata = &tk_ntp_data[TIMEKEEPER_CORE];
400+
struct ntp_data *ntpdata = &tk_ntp_data[tkid];
396401
s64 delta;
397402
int leap = 0;
398403
s32 rem;
@@ -762,10 +767,10 @@ static inline void process_adjtimex_modes(struct ntp_data *ntpdata, const struct
762767
* adjtimex() mainly allows reading (and writing, if superuser) of
763768
* kernel time-keeping variables. used by xntpd.
764769
*/
765-
int __do_adjtimex(struct __kernel_timex *txc, const struct timespec64 *ts,
770+
int __do_adjtimex(unsigned int tkid, struct __kernel_timex *txc, const struct timespec64 *ts,
766771
s32 *time_tai, struct audit_ntp_data *ad)
767772
{
768-
struct ntp_data *ntpdata = &tk_ntp_data[TIMEKEEPER_CORE];
773+
struct ntp_data *ntpdata = &tk_ntp_data[tkid];
769774
int result;
770775

771776
if (txc->modes & ADJ_ADJTIME) {

kernel/time/ntp_internal.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@
33
#define _LINUX_NTP_INTERNAL_H
44

55
extern void ntp_init(void);
6-
extern void ntp_clear(void);
6+
extern void ntp_clear(unsigned int tkid);
77
/* Returns how long ticks are at present, in ns / 2^NTP_SCALE_SHIFT. */
8-
extern u64 ntp_tick_length(void);
9-
extern ktime_t ntp_get_next_leap(void);
10-
extern int second_overflow(time64_t secs);
11-
extern int __do_adjtimex(struct __kernel_timex *txc,
12-
const struct timespec64 *ts,
8+
extern u64 ntp_tick_length(unsigned int tkid);
9+
extern ktime_t ntp_get_next_leap(unsigned int tkid);
10+
extern int second_overflow(unsigned int tkid, time64_t secs);
11+
extern int __do_adjtimex(unsigned int tkid, struct __kernel_timex *txc, const struct timespec64 *ts,
1312
s32 *time_tai, struct audit_ntp_data *ad);
1413
extern void __hardpps(const struct timespec64 *phase_ts, const struct timespec64 *raw_ts);
1514

kernel/time/timekeeping.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@ EXPORT_SYMBOL_GPL(pvclock_gtod_unregister_notifier);
601601
*/
602602
static inline void tk_update_leap_state(struct timekeeper *tk)
603603
{
604-
tk->next_leap_ktime = ntp_get_next_leap();
604+
tk->next_leap_ktime = ntp_get_next_leap(tk->id);
605605
if (tk->next_leap_ktime != KTIME_MAX)
606606
/* Convert to monotonic time */
607607
tk->next_leap_ktime = ktime_sub(tk->next_leap_ktime, tk->offs_real);
@@ -678,7 +678,7 @@ static void timekeeping_update_from_shadow(struct tk_data *tkd, unsigned int act
678678

679679
if (action & TK_CLEAR_NTP) {
680680
tk->ntp_error = 0;
681-
ntp_clear();
681+
ntp_clear(tk->id);
682682
}
683683

684684
tk_update_leap_state(tk);
@@ -2049,7 +2049,7 @@ static __always_inline void timekeeping_apply_adjustment(struct timekeeper *tk,
20492049
*/
20502050
static void timekeeping_adjust(struct timekeeper *tk, s64 offset)
20512051
{
2052-
u64 ntp_tl = ntp_tick_length();
2052+
u64 ntp_tl = ntp_tick_length(tk->id);
20532053
u32 mult;
20542054

20552055
/*
@@ -2130,7 +2130,7 @@ static inline unsigned int accumulate_nsecs_to_secs(struct timekeeper *tk)
21302130
}
21312131

21322132
/* Figure out if its a leap sec and apply if needed */
2133-
leap = second_overflow(tk->xtime_sec);
2133+
leap = second_overflow(tk->id, tk->xtime_sec);
21342134
if (unlikely(leap)) {
21352135
struct timespec64 ts;
21362136

@@ -2227,7 +2227,7 @@ static bool __timekeeping_advance(enum timekeeping_adv_mode mode)
22272227
shift = ilog2(offset) - ilog2(tk->cycle_interval);
22282228
shift = max(0, shift);
22292229
/* Bound shift to one less than what overflows tick_length */
2230-
maxshift = (64 - (ilog2(ntp_tick_length())+1)) - 1;
2230+
maxshift = (64 - (ilog2(ntp_tick_length(tk->id)) + 1)) - 1;
22312231
shift = min(shift, maxshift);
22322232
while (offset >= tk->cycle_interval) {
22332233
offset = logarithmic_accumulation(tk, offset, shift, &clock_set);
@@ -2586,7 +2586,7 @@ int do_adjtimex(struct __kernel_timex *txc)
25862586
}
25872587

25882588
orig_tai = tai = tks->tai_offset;
2589-
ret = __do_adjtimex(txc, &ts, &tai, &ad);
2589+
ret = __do_adjtimex(tks->id, txc, &ts, &tai, &ad);
25902590

25912591
if (tai != orig_tai) {
25922592
__timekeeping_set_tai_offset(tks, tai);

0 commit comments

Comments
 (0)