Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

+43 -4
+1
include/linux/time.h
··· 183 183 extern int timekeeping_inject_offset(struct timespec *ts); 184 184 extern s32 timekeeping_get_tai_offset(void); 185 185 extern void timekeeping_set_tai_offset(s32 tai_offset); 186 + extern void timekeeping_clocktai(struct timespec *ts); 186 187 187 188 struct tms; 188 189 extern void do_sys_times(struct tms *);
+2 -4
include/uapi/linux/time.h
··· 54 54 #define CLOCK_BOOTTIME 7 55 55 #define CLOCK_REALTIME_ALARM 8 56 56 #define CLOCK_BOOTTIME_ALARM 9 57 + #define CLOCK_SGI_CYCLE 10 /* Hardware specific */ 58 + #define CLOCK_TAI 11 57 59 58 - /* 59 - * The IDs of various hardware clocks: 60 - */ 61 - #define CLOCK_SGI_CYCLE 10 62 60 #define MAX_CLOCKS 16 63 61 #define CLOCKS_MASK (CLOCK_REALTIME | CLOCK_MONOTONIC) 64 62 #define CLOCKS_MONO CLOCK_MONOTONIC
+10
kernel/posix-timers.c
··· 221 221 return 0; 222 222 } 223 223 224 + static int posix_get_tai(clockid_t which_clock, struct timespec *tp) 225 + { 226 + timekeeping_clocktai(tp); 227 + return 0; 228 + } 224 229 225 230 /* 226 231 * Initialize everything, well, just everything in Posix clocks/timers ;) ··· 266 261 .clock_getres = posix_get_coarse_res, 267 262 .clock_get = posix_get_monotonic_coarse, 268 263 }; 264 + struct k_clock clock_tai = { 265 + .clock_getres = hrtimer_get_res, 266 + .clock_get = posix_get_tai, 267 + }; 269 268 struct k_clock clock_boottime = { 270 269 .clock_getres = hrtimer_get_res, 271 270 .clock_get = posix_get_boottime, ··· 287 278 posix_timers_register_clock(CLOCK_REALTIME_COARSE, &clock_realtime_coarse); 288 279 posix_timers_register_clock(CLOCK_MONOTONIC_COARSE, &clock_monotonic_coarse); 289 280 posix_timers_register_clock(CLOCK_BOOTTIME, &clock_boottime); 281 + posix_timers_register_clock(CLOCK_TAI, &clock_tai); 290 282 291 283 posix_timers_cache = kmem_cache_create("posix_timers_cache", 292 284 sizeof (struct k_itimer), 0, SLAB_PANIC,
+30
kernel/time/timekeeping.c
··· 379 379 } 380 380 EXPORT_SYMBOL_GPL(ktime_get_ts); 381 381 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 + 382 412 #ifdef CONFIG_NTP_PPS 383 413 384 414 /**