Skip to content

Commit 1ff3c96

Browse files
timekeeping: Add CLOCK_TAI clockid
This add a CLOCK_TAI clockid and the needed accessors. CC: Thomas Gleixner <tglx@linutronix.de> CC: Eric Dumazet <eric.dumazet@gmail.com> CC: Richard Cochran <richardcochran@gmail.com> Signed-off-by: John Stultz <john.stultz@linaro.org>
1 parent cc244dd commit 1ff3c96

4 files changed

Lines changed: 43 additions & 4 deletions

File tree

‎include/linux/time.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ extern u64 timekeeping_max_deferment(void);
183183
extern int timekeeping_inject_offset(struct timespec *ts);
184184
extern s32 timekeeping_get_tai_offset(void);
185185
extern void timekeeping_set_tai_offset(s32 tai_offset);
186+
extern void timekeeping_clocktai(struct timespec *ts);
186187

187188
struct tms;
188189
extern void do_sys_times(struct tms *);

‎include/uapi/linux/time.h‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,9 @@ struct itimerval {
5454
#define CLOCK_BOOTTIME 7
5555
#define CLOCK_REALTIME_ALARM 8
5656
#define CLOCK_BOOTTIME_ALARM 9
57+
#define CLOCK_SGI_CYCLE 10 /* Hardware specific */
58+
#define CLOCK_TAI 11
5759

58-
/*
59-
* The IDs of various hardware clocks:
60-
*/
61-
#define CLOCK_SGI_CYCLE 10
6260
#define MAX_CLOCKS 16
6361
#define CLOCKS_MASK (CLOCK_REALTIME | CLOCK_MONOTONIC)
6462
#define CLOCKS_MONO CLOCK_MONOTONIC

‎kernel/posix-timers.c‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,11 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
221221
return 0;
222222
}
223223

224+
static int posix_get_tai(clockid_t which_clock, struct timespec *tp)
225+
{
226+
timekeeping_clocktai(tp);
227+
return 0;
228+
}
224229

225230
/*
226231
* Initialize everything, well, just everything in Posix clocks/timers ;)
@@ -261,6 +266,10 @@ static __init int init_posix_timers(void)
261266
.clock_getres = posix_get_coarse_res,
262267
.clock_get = posix_get_monotonic_coarse,
263268
};
269+
struct k_clock clock_tai = {
270+
.clock_getres = hrtimer_get_res,
271+
.clock_get = posix_get_tai,
272+
};
264273
struct k_clock clock_boottime = {
265274
.clock_getres = hrtimer_get_res,
266275
.clock_get = posix_get_boottime,
@@ -278,6 +287,7 @@ static __init int init_posix_timers(void)
278287
posix_timers_register_clock(CLOCK_REALTIME_COARSE, &clock_realtime_coarse);
279288
posix_timers_register_clock(CLOCK_MONOTONIC_COARSE, &clock_monotonic_coarse);
280289
posix_timers_register_clock(CLOCK_BOOTTIME, &clock_boottime);
290+
posix_timers_register_clock(CLOCK_TAI, &clock_tai);
281291

282292
posix_timers_cache = kmem_cache_create("posix_timers_cache",
283293
sizeof (struct k_itimer), 0, SLAB_PANIC,

‎kernel/time/timekeeping.c‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,36 @@ void ktime_get_ts(struct timespec *ts)
379379
}
380380
EXPORT_SYMBOL_GPL(ktime_get_ts);
381381

382+
383+
/**
384+
* timekeeping_clocktai - Returns the TAI time of day in a timespec
385+
* @ts: pointer to the timespec to be set
386+
*
387+
* Returns the time of day in a timespec.
388+
*/
389+
void timekeeping_clocktai(struct timespec *ts)
390+
{
391+
struct timekeeper *tk = &timekeeper;
392+
unsigned long seq;
393+
u64 nsecs;
394+
395+
WARN_ON(timekeeping_suspended);
396+
397+
do {
398+
seq = read_seqbegin(&tk->lock);
399+
400+
ts->tv_sec = tk->xtime_sec + tk->tai_offset;
401+
nsecs = timekeeping_get_ns(tk);
402+
403+
} while (read_seqretry(&tk->lock, seq));
404+
405+
ts->tv_nsec = 0;
406+
timespec_add_ns(ts, nsecs);
407+
408+
}
409+
EXPORT_SYMBOL(timekeeping_clocktai);
410+
411+
382412
#ifdef CONFIG_NTP_PPS
383413

384414
/**

0 commit comments

Comments
 (0)