timekeeping: Provide timespec64 based interfaces

To convert callers of the core code to timespec64 we need to provide
the proper interfaces.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: John Stultz <john.stultz@linaro.org>
This commit is contained in:
Thomas Gleixner 2014-07-16 21:04:04 +00:00 committed by John Stultz
parent 8b094cd03b
commit d6d29896c6
3 changed files with 87 additions and 33 deletions

View File

@ -29,15 +29,71 @@ struct timespec get_monotonic_coarse(void);
extern void getrawmonotonic(struct timespec *ts); extern void getrawmonotonic(struct timespec *ts);
extern void monotonic_to_bootbased(struct timespec *ts); extern void monotonic_to_bootbased(struct timespec *ts);
extern void get_monotonic_boottime(struct timespec *ts); extern void get_monotonic_boottime(struct timespec *ts);
extern void ktime_get_ts(struct timespec *ts); extern void ktime_get_ts64(struct timespec64 *ts);
extern int __getnstimeofday64(struct timespec64 *tv);
extern void getnstimeofday64(struct timespec64 *tv);
#if BITS_PER_LONG == 64
static inline int __getnstimeofday(struct timespec *ts)
{
return __getnstimeofday64(ts);
}
static inline void getnstimeofday(struct timespec *ts)
{
getnstimeofday64(ts);
}
static inline void ktime_get_ts(struct timespec *ts)
{
ktime_get_ts64(ts);
}
static inline void ktime_get_real_ts(struct timespec *ts)
{
getnstimeofday64(ts);
}
#else
static inline int __getnstimeofday(struct timespec *ts)
{
struct timespec64 ts64;
int ret = __getnstimeofday64(&ts64);
*ts = timespec64_to_timespec(ts64);
return ret;
}
static inline void getnstimeofday(struct timespec *ts)
{
struct timespec64 ts64;
getnstimeofday64(&ts64);
*ts = timespec64_to_timespec(ts64);
}
static inline void ktime_get_ts(struct timespec *ts)
{
struct timespec64 ts64;
ktime_get_ts64(&ts64);
*ts = timespec64_to_timespec(ts64);
}
static inline void ktime_get_real_ts(struct timespec *ts)
{
struct timespec64 ts64;
getnstimeofday64(&ts64);
*ts = timespec64_to_timespec(ts64);
}
#endif
extern int __getnstimeofday(struct timespec *tv);
extern void getnstimeofday(struct timespec *tv);
extern void getboottime(struct timespec *ts); extern void getboottime(struct timespec *ts);
#define do_posix_clock_monotonic_gettime(ts) ktime_get_ts(ts) #define do_posix_clock_monotonic_gettime(ts) ktime_get_ts(ts)
#define ktime_get_real_ts(ts) getnstimeofday(ts) #define ktime_get_real_ts64(ts) getnstimeofday64(ts)
/* /*
* ktime_t based interfaces * ktime_t based interfaces

View File

@ -466,7 +466,8 @@ static DECLARE_DELAYED_WORK(sync_cmos_work, sync_cmos_clock);
static void sync_cmos_clock(struct work_struct *work) static void sync_cmos_clock(struct work_struct *work)
{ {
struct timespec now, next; struct timespec64 now;
struct timespec next;
int fail = 1; int fail = 1;
/* /*
@ -485,9 +486,9 @@ static void sync_cmos_clock(struct work_struct *work)
return; return;
} }
getnstimeofday(&now); getnstimeofday64(&now);
if (abs(now.tv_nsec - (NSEC_PER_SEC / 2)) <= tick_nsec * 5) { if (abs(now.tv_nsec - (NSEC_PER_SEC / 2)) <= tick_nsec * 5) {
struct timespec adjust = now; struct timespec adjust = timespec64_to_timespec(now);
fail = -ENODEV; fail = -ENODEV;
if (persistent_clock_is_local) if (persistent_clock_is_local)

View File

@ -285,13 +285,13 @@ static void timekeeping_forward_now(struct timekeeper *tk)
} }
/** /**
* __getnstimeofday - Returns the time of day in a timespec. * __getnstimeofday64 - Returns the time of day in a timespec64.
* @ts: pointer to the timespec to be set * @ts: pointer to the timespec to be set
* *
* Updates the time of day in the timespec. * Updates the time of day in the timespec.
* Returns 0 on success, or -ve when suspended (timespec will be undefined). * Returns 0 on success, or -ve when suspended (timespec will be undefined).
*/ */
int __getnstimeofday(struct timespec *ts) int __getnstimeofday64(struct timespec64 *ts)
{ {
struct timekeeper *tk = &timekeeper; struct timekeeper *tk = &timekeeper;
unsigned long seq; unsigned long seq;
@ -306,7 +306,7 @@ int __getnstimeofday(struct timespec *ts)
} while (read_seqcount_retry(&timekeeper_seq, seq)); } while (read_seqcount_retry(&timekeeper_seq, seq));
ts->tv_nsec = 0; ts->tv_nsec = 0;
timespec_add_ns(ts, nsecs); timespec64_add_ns(ts, nsecs);
/* /*
* Do not bail out early, in case there were callers still using * Do not bail out early, in case there were callers still using
@ -316,19 +316,19 @@ int __getnstimeofday(struct timespec *ts)
return -EAGAIN; return -EAGAIN;
return 0; return 0;
} }
EXPORT_SYMBOL(__getnstimeofday); EXPORT_SYMBOL(__getnstimeofday64);
/** /**
* getnstimeofday - Returns the time of day in a timespec. * getnstimeofday64 - Returns the time of day in a timespec64.
* @ts: pointer to the timespec to be set * @ts: pointer to the timespec to be set
* *
* Returns the time of day in a timespec (WARN if suspended). * Returns the time of day in a timespec (WARN if suspended).
*/ */
void getnstimeofday(struct timespec *ts) void getnstimeofday64(struct timespec64 *ts)
{ {
WARN_ON(__getnstimeofday(ts)); WARN_ON(__getnstimeofday64(ts));
} }
EXPORT_SYMBOL(getnstimeofday); EXPORT_SYMBOL(getnstimeofday64);
ktime_t ktime_get(void) ktime_t ktime_get(void)
{ {
@ -350,17 +350,17 @@ ktime_t ktime_get(void)
EXPORT_SYMBOL_GPL(ktime_get); EXPORT_SYMBOL_GPL(ktime_get);
/** /**
* ktime_get_ts - get the monotonic clock in timespec format * ktime_get_ts64 - get the monotonic clock in timespec64 format
* @ts: pointer to timespec variable * @ts: pointer to timespec variable
* *
* The function calculates the monotonic clock from the realtime * The function calculates the monotonic clock from the realtime
* clock and the wall_to_monotonic offset and stores the result * clock and the wall_to_monotonic offset and stores the result
* in normalized timespec format in the variable pointed to by @ts. * in normalized timespec format in the variable pointed to by @ts.
*/ */
void ktime_get_ts(struct timespec *ts) void ktime_get_ts64(struct timespec64 *ts)
{ {
struct timekeeper *tk = &timekeeper; struct timekeeper *tk = &timekeeper;
struct timespec64 ts64, tomono; struct timespec64 tomono;
s64 nsec; s64 nsec;
unsigned int seq; unsigned int seq;
@ -368,18 +368,17 @@ void ktime_get_ts(struct timespec *ts)
do { do {
seq = read_seqcount_begin(&timekeeper_seq); seq = read_seqcount_begin(&timekeeper_seq);
ts64.tv_sec = tk->xtime_sec; ts->tv_sec = tk->xtime_sec;
nsec = timekeeping_get_ns(tk); nsec = timekeeping_get_ns(tk);
tomono = tk->wall_to_monotonic; tomono = tk->wall_to_monotonic;
} while (read_seqcount_retry(&timekeeper_seq, seq)); } while (read_seqcount_retry(&timekeeper_seq, seq));
ts64.tv_sec += tomono.tv_sec; ts->tv_sec += tomono.tv_sec;
ts64.tv_nsec = 0; ts->tv_nsec = 0;
timespec64_add_ns(&ts64, nsec + tomono.tv_nsec); timespec64_add_ns(ts, nsec + tomono.tv_nsec);
*ts = timespec64_to_timespec(ts64);
} }
EXPORT_SYMBOL_GPL(ktime_get_ts); EXPORT_SYMBOL_GPL(ktime_get_ts64);
/** /**
@ -473,9 +472,9 @@ EXPORT_SYMBOL(getnstime_raw_and_real);
*/ */
void do_gettimeofday(struct timeval *tv) void do_gettimeofday(struct timeval *tv)
{ {
struct timespec now; struct timespec64 now;
getnstimeofday(&now); getnstimeofday64(&now);
tv->tv_sec = now.tv_sec; tv->tv_sec = now.tv_sec;
tv->tv_usec = now.tv_nsec/1000; tv->tv_usec = now.tv_nsec/1000;
} }
@ -680,11 +679,11 @@ int timekeeping_notify(struct clocksource *clock)
*/ */
ktime_t ktime_get_real(void) ktime_t ktime_get_real(void)
{ {
struct timespec now; struct timespec64 now;
getnstimeofday(&now); getnstimeofday64(&now);
return timespec_to_ktime(now); return timespec64_to_ktime(now);
} }
EXPORT_SYMBOL_GPL(ktime_get_real); EXPORT_SYMBOL_GPL(ktime_get_real);
@ -1689,7 +1688,6 @@ int do_adjtimex(struct timex *txc)
struct timekeeper *tk = &timekeeper; struct timekeeper *tk = &timekeeper;
unsigned long flags; unsigned long flags;
struct timespec64 ts; struct timespec64 ts;
struct timespec tmp;
s32 orig_tai, tai; s32 orig_tai, tai;
int ret; int ret;
@ -1709,8 +1707,7 @@ int do_adjtimex(struct timex *txc)
return ret; return ret;
} }
getnstimeofday(&tmp); getnstimeofday64(&ts);
ts = timespec_to_timespec64(tmp);
raw_spin_lock_irqsave(&timekeeper_lock, flags); raw_spin_lock_irqsave(&timekeeper_lock, flags);
write_seqcount_begin(&timekeeper_seq); write_seqcount_begin(&timekeeper_seq);