]> Pileus Git - ~andy/linux/commitdiff
timekeeping: Add CLOCK_TAI clockid
authorJohn Stultz <john.stultz@linaro.org>
Thu, 3 May 2012 19:43:40 +0000 (12:43 -0700)
committerJohn Stultz <john.stultz@linaro.org>
Fri, 22 Mar 2013 23:19:59 +0000 (16:19 -0700)
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>
include/linux/time.h
include/uapi/linux/time.h
kernel/posix-timers.c
kernel/time/timekeeping.c

index 47210a175e781228d640fae5b5d424407601161d..22d81b3c955b533bf73ec0b9353c6c7d4287c010 100644 (file)
@@ -183,6 +183,7 @@ extern u64 timekeeping_max_deferment(void);
 extern int timekeeping_inject_offset(struct timespec *ts);
 extern s32 timekeeping_get_tai_offset(void);
 extern void timekeeping_set_tai_offset(s32 tai_offset);
+extern void timekeeping_clocktai(struct timespec *ts);
 
 struct tms;
 extern void do_sys_times(struct tms *);
index 0d3c0edc3edaeaef405d7f208e424cc5f3fda2be..e75e1b6ff27f72162a83a7ad59866acf2a8c9c20 100644 (file)
@@ -54,11 +54,9 @@ struct itimerval {
 #define CLOCK_BOOTTIME                 7
 #define CLOCK_REALTIME_ALARM           8
 #define CLOCK_BOOTTIME_ALARM           9
+#define CLOCK_SGI_CYCLE                        10      /* Hardware specific */
+#define CLOCK_TAI                      11
 
-/*
- * The IDs of various hardware clocks:
- */
-#define CLOCK_SGI_CYCLE                        10
 #define MAX_CLOCKS                     16
 #define CLOCKS_MASK                    (CLOCK_REALTIME | CLOCK_MONOTONIC)
 #define CLOCKS_MONO                    CLOCK_MONOTONIC
index 6edbb2c55c22fd56a61eb6665e32087592a81fc3..fbfc5f1b7710528bd2138b14967cdcae12f48712 100644 (file)
@@ -221,6 +221,11 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
        return 0;
 }
 
+static int posix_get_tai(clockid_t which_clock, struct timespec *tp)
+{
+       timekeeping_clocktai(tp);
+       return 0;
+}
 
 /*
  * Initialize everything, well, just everything in Posix clocks/timers ;)
@@ -261,6 +266,10 @@ static __init int init_posix_timers(void)
                .clock_getres   = posix_get_coarse_res,
                .clock_get      = posix_get_monotonic_coarse,
        };
+       struct k_clock clock_tai = {
+               .clock_getres   = hrtimer_get_res,
+               .clock_get      = posix_get_tai,
+       };
        struct k_clock clock_boottime = {
                .clock_getres   = hrtimer_get_res,
                .clock_get      = posix_get_boottime,
@@ -278,6 +287,7 @@ static __init int init_posix_timers(void)
        posix_timers_register_clock(CLOCK_REALTIME_COARSE, &clock_realtime_coarse);
        posix_timers_register_clock(CLOCK_MONOTONIC_COARSE, &clock_monotonic_coarse);
        posix_timers_register_clock(CLOCK_BOOTTIME, &clock_boottime);
+       posix_timers_register_clock(CLOCK_TAI, &clock_tai);
 
        posix_timers_cache = kmem_cache_create("posix_timers_cache",
                                        sizeof (struct k_itimer), 0, SLAB_PANIC,
index 937098aab49877b670409f49eb869fec9e20cfd1..8a842756572d48545e1ea062d336cd0decce5e85 100644 (file)
@@ -379,6 +379,36 @@ void ktime_get_ts(struct timespec *ts)
 }
 EXPORT_SYMBOL_GPL(ktime_get_ts);
 
+
+/**
+ * timekeeping_clocktai - Returns the TAI time of day in a timespec
+ * @ts:                pointer to the timespec to be set
+ *
+ * Returns the time of day in a timespec.
+ */
+void timekeeping_clocktai(struct timespec *ts)
+{
+       struct timekeeper *tk = &timekeeper;
+       unsigned long seq;
+       u64 nsecs;
+
+       WARN_ON(timekeeping_suspended);
+
+       do {
+               seq = read_seqbegin(&tk->lock);
+
+               ts->tv_sec = tk->xtime_sec + tk->tai_offset;
+               nsecs = timekeeping_get_ns(tk);
+
+       } while (read_seqretry(&tk->lock, seq));
+
+       ts->tv_nsec = 0;
+       timespec_add_ns(ts, nsecs);
+
+}
+EXPORT_SYMBOL(timekeeping_clocktai);
+
+
 #ifdef CONFIG_NTP_PPS
 
 /**