diff options
author | Thomas Gleixner <tglx@linutronix.de> | 2014-07-16 17:04:04 -0400 |
---|---|---|
committer | John Stultz <john.stultz@linaro.org> | 2014-07-23 13:17:55 -0400 |
commit | d6d29896c665dfd50e6e0be7a9039901640433a3 (patch) | |
tree | f6f80e9658798bb94f1aef2b06ddb63d5f32e26d | |
parent | 8b094cd03b4a3793220d8d8d86a173bfea8c285b (diff) |
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>
-rw-r--r-- | include/linux/timekeeping.h | 66 | ||||
-rw-r--r-- | kernel/time/ntp.c | 7 | ||||
-rw-r--r-- | kernel/time/timekeeping.c | 47 |
3 files changed, 87 insertions, 33 deletions
diff --git a/include/linux/timekeeping.h b/include/linux/timekeeping.h index e81c35b71da7..3eb19e34cc20 100644 --- a/include/linux/timekeeping.h +++ b/include/linux/timekeeping.h | |||
@@ -29,15 +29,71 @@ struct timespec get_monotonic_coarse(void); | |||
29 | extern void getrawmonotonic(struct timespec *ts); | 29 | extern void getrawmonotonic(struct timespec *ts); |
30 | extern void monotonic_to_bootbased(struct timespec *ts); | 30 | extern void monotonic_to_bootbased(struct timespec *ts); |
31 | extern void get_monotonic_boottime(struct timespec *ts); | 31 | extern void get_monotonic_boottime(struct timespec *ts); |
32 | extern void ktime_get_ts(struct timespec *ts); | 32 | extern void ktime_get_ts64(struct timespec64 *ts); |
33 | |||
34 | extern int __getnstimeofday64(struct timespec64 *tv); | ||
35 | extern void getnstimeofday64(struct timespec64 *tv); | ||
36 | |||
37 | #if BITS_PER_LONG == 64 | ||
38 | static inline int __getnstimeofday(struct timespec *ts) | ||
39 | { | ||
40 | return __getnstimeofday64(ts); | ||
41 | } | ||
42 | |||
43 | static inline void getnstimeofday(struct timespec *ts) | ||
44 | { | ||
45 | getnstimeofday64(ts); | ||
46 | } | ||
47 | |||
48 | static inline void ktime_get_ts(struct timespec *ts) | ||
49 | { | ||
50 | ktime_get_ts64(ts); | ||
51 | } | ||
52 | |||
53 | static inline void ktime_get_real_ts(struct timespec *ts) | ||
54 | { | ||
55 | getnstimeofday64(ts); | ||
56 | } | ||
57 | |||
58 | #else | ||
59 | static inline int __getnstimeofday(struct timespec *ts) | ||
60 | { | ||
61 | struct timespec64 ts64; | ||
62 | int ret = __getnstimeofday64(&ts64); | ||
63 | |||
64 | *ts = timespec64_to_timespec(ts64); | ||
65 | return ret; | ||
66 | } | ||
67 | |||
68 | static inline void getnstimeofday(struct timespec *ts) | ||
69 | { | ||
70 | struct timespec64 ts64; | ||
71 | |||
72 | getnstimeofday64(&ts64); | ||
73 | *ts = timespec64_to_timespec(ts64); | ||
74 | } | ||
75 | |||
76 | static inline void ktime_get_ts(struct timespec *ts) | ||
77 | { | ||
78 | struct timespec64 ts64; | ||
79 | |||
80 | ktime_get_ts64(&ts64); | ||
81 | *ts = timespec64_to_timespec(ts64); | ||
82 | } | ||
83 | |||
84 | static inline void ktime_get_real_ts(struct timespec *ts) | ||
85 | { | ||
86 | struct timespec64 ts64; | ||
87 | |||
88 | getnstimeofday64(&ts64); | ||
89 | *ts = timespec64_to_timespec(ts64); | ||
90 | } | ||
91 | #endif | ||
33 | 92 | ||
34 | extern int __getnstimeofday(struct timespec *tv); | ||
35 | extern void getnstimeofday(struct timespec *tv); | ||
36 | extern void getboottime(struct timespec *ts); | 93 | extern void getboottime(struct timespec *ts); |
37 | 94 | ||
38 | #define do_posix_clock_monotonic_gettime(ts) ktime_get_ts(ts) | 95 | #define do_posix_clock_monotonic_gettime(ts) ktime_get_ts(ts) |
39 | #define ktime_get_real_ts(ts) getnstimeofday(ts) | 96 | #define ktime_get_real_ts64(ts) getnstimeofday64(ts) |
40 | |||
41 | 97 | ||
42 | /* | 98 | /* |
43 | * ktime_t based interfaces | 99 | * ktime_t based interfaces |
diff --git a/kernel/time/ntp.c b/kernel/time/ntp.c index 6e87df94122f..87a346fd6d61 100644 --- a/kernel/time/ntp.c +++ b/kernel/time/ntp.c | |||
@@ -466,7 +466,8 @@ static DECLARE_DELAYED_WORK(sync_cmos_work, sync_cmos_clock); | |||
466 | 466 | ||
467 | static void sync_cmos_clock(struct work_struct *work) | 467 | static void sync_cmos_clock(struct work_struct *work) |
468 | { | 468 | { |
469 | struct timespec now, next; | 469 | struct timespec64 now; |
470 | struct timespec next; | ||
470 | int fail = 1; | 471 | int fail = 1; |
471 | 472 | ||
472 | /* | 473 | /* |
@@ -485,9 +486,9 @@ static void sync_cmos_clock(struct work_struct *work) | |||
485 | return; | 486 | return; |
486 | } | 487 | } |
487 | 488 | ||
488 | getnstimeofday(&now); | 489 | getnstimeofday64(&now); |
489 | if (abs(now.tv_nsec - (NSEC_PER_SEC / 2)) <= tick_nsec * 5) { | 490 | if (abs(now.tv_nsec - (NSEC_PER_SEC / 2)) <= tick_nsec * 5) { |
490 | struct timespec adjust = now; | 491 | struct timespec adjust = timespec64_to_timespec(now); |
491 | 492 | ||
492 | fail = -ENODEV; | 493 | fail = -ENODEV; |
493 | if (persistent_clock_is_local) | 494 | if (persistent_clock_is_local) |
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index 84a2075c3eb4..3210c9e690c5 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c | |||
@@ -285,13 +285,13 @@ static void timekeeping_forward_now(struct timekeeper *tk) | |||
285 | } | 285 | } |
286 | 286 | ||
287 | /** | 287 | /** |
288 | * __getnstimeofday - Returns the time of day in a timespec. | 288 | * __getnstimeofday64 - Returns the time of day in a timespec64. |
289 | * @ts: pointer to the timespec to be set | 289 | * @ts: pointer to the timespec to be set |
290 | * | 290 | * |
291 | * Updates the time of day in the timespec. | 291 | * Updates the time of day in the timespec. |
292 | * Returns 0 on success, or -ve when suspended (timespec will be undefined). | 292 | * Returns 0 on success, or -ve when suspended (timespec will be undefined). |
293 | */ | 293 | */ |
294 | int __getnstimeofday(struct timespec *ts) | 294 | int __getnstimeofday64(struct timespec64 *ts) |
295 | { | 295 | { |
296 | struct timekeeper *tk = &timekeeper; | 296 | struct timekeeper *tk = &timekeeper; |
297 | unsigned long seq; | 297 | unsigned long seq; |
@@ -306,7 +306,7 @@ int __getnstimeofday(struct timespec *ts) | |||
306 | } while (read_seqcount_retry(&timekeeper_seq, seq)); | 306 | } while (read_seqcount_retry(&timekeeper_seq, seq)); |
307 | 307 | ||
308 | ts->tv_nsec = 0; | 308 | ts->tv_nsec = 0; |
309 | timespec_add_ns(ts, nsecs); | 309 | timespec64_add_ns(ts, nsecs); |
310 | 310 | ||
311 | /* | 311 | /* |
312 | * Do not bail out early, in case there were callers still using | 312 | * Do not bail out early, in case there were callers still using |
@@ -316,19 +316,19 @@ int __getnstimeofday(struct timespec *ts) | |||
316 | return -EAGAIN; | 316 | return -EAGAIN; |
317 | return 0; | 317 | return 0; |
318 | } | 318 | } |
319 | EXPORT_SYMBOL(__getnstimeofday); | 319 | EXPORT_SYMBOL(__getnstimeofday64); |
320 | 320 | ||
321 | /** | 321 | /** |
322 | * getnstimeofday - Returns the time of day in a timespec. | 322 | * getnstimeofday64 - Returns the time of day in a timespec64. |
323 | * @ts: pointer to the timespec to be set | 323 | * @ts: pointer to the timespec to be set |
324 | * | 324 | * |
325 | * Returns the time of day in a timespec (WARN if suspended). | 325 | * Returns the time of day in a timespec (WARN if suspended). |
326 | */ | 326 | */ |
327 | void getnstimeofday(struct timespec *ts) | 327 | void getnstimeofday64(struct timespec64 *ts) |
328 | { | 328 | { |
329 | WARN_ON(__getnstimeofday(ts)); | 329 | WARN_ON(__getnstimeofday64(ts)); |
330 | } | 330 | } |
331 | EXPORT_SYMBOL(getnstimeofday); | 331 | EXPORT_SYMBOL(getnstimeofday64); |
332 | 332 | ||
333 | ktime_t ktime_get(void) | 333 | ktime_t ktime_get(void) |
334 | { | 334 | { |
@@ -350,17 +350,17 @@ ktime_t ktime_get(void) | |||
350 | EXPORT_SYMBOL_GPL(ktime_get); | 350 | EXPORT_SYMBOL_GPL(ktime_get); |
351 | 351 | ||
352 | /** | 352 | /** |
353 | * ktime_get_ts - get the monotonic clock in timespec format | 353 | * ktime_get_ts64 - get the monotonic clock in timespec64 format |
354 | * @ts: pointer to timespec variable | 354 | * @ts: pointer to timespec variable |
355 | * | 355 | * |
356 | * The function calculates the monotonic clock from the realtime | 356 | * The function calculates the monotonic clock from the realtime |
357 | * clock and the wall_to_monotonic offset and stores the result | 357 | * clock and the wall_to_monotonic offset and stores the result |
358 | * in normalized timespec format in the variable pointed to by @ts. | 358 | * in normalized timespec format in the variable pointed to by @ts. |
359 | */ | 359 | */ |
360 | void ktime_get_ts(struct timespec *ts) | 360 | void ktime_get_ts64(struct timespec64 *ts) |
361 | { | 361 | { |
362 | struct timekeeper *tk = &timekeeper; | 362 | struct timekeeper *tk = &timekeeper; |
363 | struct timespec64 ts64, tomono; | 363 | struct timespec64 tomono; |
364 | s64 nsec; | 364 | s64 nsec; |
365 | unsigned int seq; | 365 | unsigned int seq; |
366 | 366 | ||
@@ -368,18 +368,17 @@ void ktime_get_ts(struct timespec *ts) | |||
368 | 368 | ||
369 | do { | 369 | do { |
370 | seq = read_seqcount_begin(&timekeeper_seq); | 370 | seq = read_seqcount_begin(&timekeeper_seq); |
371 | ts64.tv_sec = tk->xtime_sec; | 371 | ts->tv_sec = tk->xtime_sec; |
372 | nsec = timekeeping_get_ns(tk); | 372 | nsec = timekeeping_get_ns(tk); |
373 | tomono = tk->wall_to_monotonic; | 373 | tomono = tk->wall_to_monotonic; |
374 | 374 | ||
375 | } while (read_seqcount_retry(&timekeeper_seq, seq)); | 375 | } while (read_seqcount_retry(&timekeeper_seq, seq)); |
376 | 376 | ||
377 | ts64.tv_sec += tomono.tv_sec; | 377 | ts->tv_sec += tomono.tv_sec; |
378 | ts64.tv_nsec = 0; | 378 | ts->tv_nsec = 0; |
379 | timespec64_add_ns(&ts64, nsec + tomono.tv_nsec); | 379 | timespec64_add_ns(ts, nsec + tomono.tv_nsec); |
380 | *ts = timespec64_to_timespec(ts64); | ||
381 | } | 380 | } |
382 | EXPORT_SYMBOL_GPL(ktime_get_ts); | 381 | EXPORT_SYMBOL_GPL(ktime_get_ts64); |
383 | 382 | ||
384 | 383 | ||
385 | /** | 384 | /** |
@@ -473,9 +472,9 @@ EXPORT_SYMBOL(getnstime_raw_and_real); | |||
473 | */ | 472 | */ |
474 | void do_gettimeofday(struct timeval *tv) | 473 | void do_gettimeofday(struct timeval *tv) |
475 | { | 474 | { |
476 | struct timespec now; | 475 | struct timespec64 now; |
477 | 476 | ||
478 | getnstimeofday(&now); | 477 | getnstimeofday64(&now); |
479 | tv->tv_sec = now.tv_sec; | 478 | tv->tv_sec = now.tv_sec; |
480 | tv->tv_usec = now.tv_nsec/1000; | 479 | tv->tv_usec = now.tv_nsec/1000; |
481 | } | 480 | } |
@@ -680,11 +679,11 @@ int timekeeping_notify(struct clocksource *clock) | |||
680 | */ | 679 | */ |
681 | ktime_t ktime_get_real(void) | 680 | ktime_t ktime_get_real(void) |
682 | { | 681 | { |
683 | struct timespec now; | 682 | struct timespec64 now; |
684 | 683 | ||
685 | getnstimeofday(&now); | 684 | getnstimeofday64(&now); |
686 | 685 | ||
687 | return timespec_to_ktime(now); | 686 | return timespec64_to_ktime(now); |
688 | } | 687 | } |
689 | EXPORT_SYMBOL_GPL(ktime_get_real); | 688 | EXPORT_SYMBOL_GPL(ktime_get_real); |
690 | 689 | ||
@@ -1689,7 +1688,6 @@ int do_adjtimex(struct timex *txc) | |||
1689 | struct timekeeper *tk = &timekeeper; | 1688 | struct timekeeper *tk = &timekeeper; |
1690 | unsigned long flags; | 1689 | unsigned long flags; |
1691 | struct timespec64 ts; | 1690 | struct timespec64 ts; |
1692 | struct timespec tmp; | ||
1693 | s32 orig_tai, tai; | 1691 | s32 orig_tai, tai; |
1694 | int ret; | 1692 | int ret; |
1695 | 1693 | ||
@@ -1709,8 +1707,7 @@ int do_adjtimex(struct timex *txc) | |||
1709 | return ret; | 1707 | return ret; |
1710 | } | 1708 | } |
1711 | 1709 | ||
1712 | getnstimeofday(&tmp); | 1710 | getnstimeofday64(&ts); |
1713 | ts = timespec_to_timespec64(tmp); | ||
1714 | 1711 | ||
1715 | raw_spin_lock_irqsave(&timekeeper_lock, flags); | 1712 | raw_spin_lock_irqsave(&timekeeper_lock, flags); |
1716 | write_seqcount_begin(&timekeeper_seq); | 1713 | write_seqcount_begin(&timekeeper_seq); |