aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/linux/timekeeper_internal.h10
-rw-r--r--kernel/time/ntp.c8
-rw-r--r--kernel/time/ntp_internal.h2
-rw-r--r--kernel/time/timekeeping.c172
-rw-r--r--kernel/time/timekeeping_debug.c2
-rw-r--r--kernel/time/timekeeping_internal.h2
6 files changed, 109 insertions, 87 deletions
diff --git a/include/linux/timekeeper_internal.h b/include/linux/timekeeper_internal.h
index c1825eb436ed..1b05491e10f9 100644
--- a/include/linux/timekeeper_internal.h
+++ b/include/linux/timekeeper_internal.h
@@ -55,15 +55,15 @@ struct timekeeper {
55 * - wall_to_monotonic is no longer the boot time, getboottime must be 55 * - wall_to_monotonic is no longer the boot time, getboottime must be
56 * used instead. 56 * used instead.
57 */ 57 */
58 struct timespec wall_to_monotonic; 58 struct timespec64 wall_to_monotonic;
59 /* Offset clock monotonic -> clock realtime */ 59 /* Offset clock monotonic -> clock realtime */
60 ktime_t offs_real; 60 ktime_t offs_real;
61 /* time spent in suspend */ 61 /* time spent in suspend */
62 struct timespec total_sleep_time; 62 struct timespec64 total_sleep_time;
63 /* Offset clock monotonic -> clock boottime */ 63 /* Offset clock monotonic -> clock boottime */
64 ktime_t offs_boot; 64 ktime_t offs_boot;
65 /* The raw monotonic time for the CLOCK_MONOTONIC_RAW posix clock. */ 65 /* The raw monotonic time for the CLOCK_MONOTONIC_RAW posix clock. */
66 struct timespec raw_time; 66 struct timespec64 raw_time;
67 /* The current UTC to TAI offset in seconds */ 67 /* The current UTC to TAI offset in seconds */
68 s32 tai_offset; 68 s32 tai_offset;
69 /* Offset clock monotonic -> clock tai */ 69 /* Offset clock monotonic -> clock tai */
@@ -71,9 +71,9 @@ struct timekeeper {
71 71
72}; 72};
73 73
74static inline struct timespec tk_xtime(struct timekeeper *tk) 74static inline struct timespec64 tk_xtime(struct timekeeper *tk)
75{ 75{
76 struct timespec ts; 76 struct timespec64 ts;
77 77
78 ts.tv_sec = tk->xtime_sec; 78 ts.tv_sec = tk->xtime_sec;
79 ts.tv_nsec = (long)(tk->xtime_nsec >> tk->shift); 79 ts.tv_nsec = (long)(tk->xtime_nsec >> tk->shift);
diff --git a/kernel/time/ntp.c b/kernel/time/ntp.c
index 33db43a39515..6e87df94122f 100644
--- a/kernel/time/ntp.c
+++ b/kernel/time/ntp.c
@@ -531,7 +531,7 @@ void ntp_notify_cmos_timer(void) { }
531/* 531/*
532 * Propagate a new txc->status value into the NTP state: 532 * Propagate a new txc->status value into the NTP state:
533 */ 533 */
534static inline void process_adj_status(struct timex *txc, struct timespec *ts) 534static inline void process_adj_status(struct timex *txc, struct timespec64 *ts)
535{ 535{
536 if ((time_status & STA_PLL) && !(txc->status & STA_PLL)) { 536 if ((time_status & STA_PLL) && !(txc->status & STA_PLL)) {
537 time_state = TIME_OK; 537 time_state = TIME_OK;
@@ -554,7 +554,7 @@ static inline void process_adj_status(struct timex *txc, struct timespec *ts)
554 554
555 555
556static inline void process_adjtimex_modes(struct timex *txc, 556static inline void process_adjtimex_modes(struct timex *txc,
557 struct timespec *ts, 557 struct timespec64 *ts,
558 s32 *time_tai) 558 s32 *time_tai)
559{ 559{
560 if (txc->modes & ADJ_STATUS) 560 if (txc->modes & ADJ_STATUS)
@@ -640,7 +640,7 @@ int ntp_validate_timex(struct timex *txc)
640 * adjtimex mainly allows reading (and writing, if superuser) of 640 * adjtimex mainly allows reading (and writing, if superuser) of
641 * kernel time-keeping variables. used by xntpd. 641 * kernel time-keeping variables. used by xntpd.
642 */ 642 */
643int __do_adjtimex(struct timex *txc, struct timespec *ts, s32 *time_tai) 643int __do_adjtimex(struct timex *txc, struct timespec64 *ts, s32 *time_tai)
644{ 644{
645 int result; 645 int result;
646 646
@@ -684,7 +684,7 @@ int __do_adjtimex(struct timex *txc, struct timespec *ts, s32 *time_tai)
684 /* fill PPS status fields */ 684 /* fill PPS status fields */
685 pps_fill_timex(txc); 685 pps_fill_timex(txc);
686 686
687 txc->time.tv_sec = ts->tv_sec; 687 txc->time.tv_sec = (time_t)ts->tv_sec;
688 txc->time.tv_usec = ts->tv_nsec; 688 txc->time.tv_usec = ts->tv_nsec;
689 if (!(time_status & STA_NANO)) 689 if (!(time_status & STA_NANO))
690 txc->time.tv_usec /= NSEC_PER_USEC; 690 txc->time.tv_usec /= NSEC_PER_USEC;
diff --git a/kernel/time/ntp_internal.h b/kernel/time/ntp_internal.h
index 1950cb4ca2a4..bbd102ad9df7 100644
--- a/kernel/time/ntp_internal.h
+++ b/kernel/time/ntp_internal.h
@@ -7,6 +7,6 @@ extern void ntp_clear(void);
7extern u64 ntp_tick_length(void); 7extern u64 ntp_tick_length(void);
8extern int second_overflow(unsigned long secs); 8extern int second_overflow(unsigned long secs);
9extern int ntp_validate_timex(struct timex *); 9extern int ntp_validate_timex(struct timex *);
10extern int __do_adjtimex(struct timex *, struct timespec *, s32 *); 10extern int __do_adjtimex(struct timex *, struct timespec64 *, s32 *);
11extern void __hardpps(const struct timespec *, const struct timespec *); 11extern void __hardpps(const struct timespec *, const struct timespec *);
12#endif /* _LINUX_NTP_INTERNAL_H */ 12#endif /* _LINUX_NTP_INTERNAL_H */
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index cafef242d8f9..84a2075c3eb4 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -51,43 +51,43 @@ static inline void tk_normalize_xtime(struct timekeeper *tk)
51 } 51 }
52} 52}
53 53
54static void tk_set_xtime(struct timekeeper *tk, const struct timespec *ts) 54static void tk_set_xtime(struct timekeeper *tk, const struct timespec64 *ts)
55{ 55{
56 tk->xtime_sec = ts->tv_sec; 56 tk->xtime_sec = ts->tv_sec;
57 tk->xtime_nsec = (u64)ts->tv_nsec << tk->shift; 57 tk->xtime_nsec = (u64)ts->tv_nsec << tk->shift;
58} 58}
59 59
60static void tk_xtime_add(struct timekeeper *tk, const struct timespec *ts) 60static void tk_xtime_add(struct timekeeper *tk, const struct timespec64 *ts)
61{ 61{
62 tk->xtime_sec += ts->tv_sec; 62 tk->xtime_sec += ts->tv_sec;
63 tk->xtime_nsec += (u64)ts->tv_nsec << tk->shift; 63 tk->xtime_nsec += (u64)ts->tv_nsec << tk->shift;
64 tk_normalize_xtime(tk); 64 tk_normalize_xtime(tk);
65} 65}
66 66
67static void tk_set_wall_to_mono(struct timekeeper *tk, struct timespec wtm) 67static void tk_set_wall_to_mono(struct timekeeper *tk, struct timespec64 wtm)
68{ 68{
69 struct timespec tmp; 69 struct timespec64 tmp;
70 70
71 /* 71 /*
72 * Verify consistency of: offset_real = -wall_to_monotonic 72 * Verify consistency of: offset_real = -wall_to_monotonic
73 * before modifying anything 73 * before modifying anything
74 */ 74 */
75 set_normalized_timespec(&tmp, -tk->wall_to_monotonic.tv_sec, 75 set_normalized_timespec64(&tmp, -tk->wall_to_monotonic.tv_sec,
76 -tk->wall_to_monotonic.tv_nsec); 76 -tk->wall_to_monotonic.tv_nsec);
77 WARN_ON_ONCE(tk->offs_real.tv64 != timespec_to_ktime(tmp).tv64); 77 WARN_ON_ONCE(tk->offs_real.tv64 != timespec64_to_ktime(tmp).tv64);
78 tk->wall_to_monotonic = wtm; 78 tk->wall_to_monotonic = wtm;
79 set_normalized_timespec(&tmp, -wtm.tv_sec, -wtm.tv_nsec); 79 set_normalized_timespec64(&tmp, -wtm.tv_sec, -wtm.tv_nsec);
80 tk->offs_real = timespec_to_ktime(tmp); 80 tk->offs_real = timespec64_to_ktime(tmp);
81 tk->offs_tai = ktime_add(tk->offs_real, ktime_set(tk->tai_offset, 0)); 81 tk->offs_tai = ktime_add(tk->offs_real, ktime_set(tk->tai_offset, 0));
82} 82}
83 83
84static void tk_set_sleep_time(struct timekeeper *tk, struct timespec t) 84static void tk_set_sleep_time(struct timekeeper *tk, struct timespec64 t)
85{ 85{
86 /* Verify consistency before modifying */ 86 /* Verify consistency before modifying */
87 WARN_ON_ONCE(tk->offs_boot.tv64 != timespec_to_ktime(tk->total_sleep_time).tv64); 87 WARN_ON_ONCE(tk->offs_boot.tv64 != timespec64_to_ktime(tk->total_sleep_time).tv64);
88 88
89 tk->total_sleep_time = t; 89 tk->total_sleep_time = t;
90 tk->offs_boot = timespec_to_ktime(t); 90 tk->offs_boot = timespec64_to_ktime(t);
91} 91}
92 92
93/** 93/**
@@ -281,7 +281,7 @@ static void timekeeping_forward_now(struct timekeeper *tk)
281 tk_normalize_xtime(tk); 281 tk_normalize_xtime(tk);
282 282
283 nsec = clocksource_cyc2ns(cycle_delta, clock->mult, clock->shift); 283 nsec = clocksource_cyc2ns(cycle_delta, clock->mult, clock->shift);
284 timespec_add_ns(&tk->raw_time, nsec); 284 timespec64_add_ns(&tk->raw_time, nsec);
285} 285}
286 286
287/** 287/**
@@ -360,7 +360,7 @@ EXPORT_SYMBOL_GPL(ktime_get);
360void ktime_get_ts(struct timespec *ts) 360void ktime_get_ts(struct timespec *ts)
361{ 361{
362 struct timekeeper *tk = &timekeeper; 362 struct timekeeper *tk = &timekeeper;
363 struct timespec tomono; 363 struct timespec64 ts64, tomono;
364 s64 nsec; 364 s64 nsec;
365 unsigned int seq; 365 unsigned int seq;
366 366
@@ -368,15 +368,16 @@ 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 ts->tv_sec = tk->xtime_sec; 371 ts64.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 ts->tv_sec += tomono.tv_sec; 377 ts64.tv_sec += tomono.tv_sec;
378 ts->tv_nsec = 0; 378 ts64.tv_nsec = 0;
379 timespec_add_ns(ts, nsec + tomono.tv_nsec); 379 timespec64_add_ns(&ts64, nsec + tomono.tv_nsec);
380 *ts = timespec64_to_timespec(ts64);
380} 381}
381EXPORT_SYMBOL_GPL(ktime_get_ts); 382EXPORT_SYMBOL_GPL(ktime_get_ts);
382 383
@@ -390,6 +391,7 @@ EXPORT_SYMBOL_GPL(ktime_get_ts);
390void timekeeping_clocktai(struct timespec *ts) 391void timekeeping_clocktai(struct timespec *ts)
391{ 392{
392 struct timekeeper *tk = &timekeeper; 393 struct timekeeper *tk = &timekeeper;
394 struct timespec64 ts64;
393 unsigned long seq; 395 unsigned long seq;
394 u64 nsecs; 396 u64 nsecs;
395 397
@@ -398,13 +400,14 @@ void timekeeping_clocktai(struct timespec *ts)
398 do { 400 do {
399 seq = read_seqcount_begin(&timekeeper_seq); 401 seq = read_seqcount_begin(&timekeeper_seq);
400 402
401 ts->tv_sec = tk->xtime_sec + tk->tai_offset; 403 ts64.tv_sec = tk->xtime_sec + tk->tai_offset;
402 nsecs = timekeeping_get_ns(tk); 404 nsecs = timekeeping_get_ns(tk);
403 405
404 } while (read_seqcount_retry(&timekeeper_seq, seq)); 406 } while (read_seqcount_retry(&timekeeper_seq, seq));
405 407
406 ts->tv_nsec = 0; 408 ts64.tv_nsec = 0;
407 timespec_add_ns(ts, nsecs); 409 timespec64_add_ns(&ts64, nsecs);
410 *ts = timespec64_to_timespec(ts64);
408 411
409} 412}
410EXPORT_SYMBOL(timekeeping_clocktai); 413EXPORT_SYMBOL(timekeeping_clocktai);
@@ -446,7 +449,7 @@ void getnstime_raw_and_real(struct timespec *ts_raw, struct timespec *ts_real)
446 do { 449 do {
447 seq = read_seqcount_begin(&timekeeper_seq); 450 seq = read_seqcount_begin(&timekeeper_seq);
448 451
449 *ts_raw = tk->raw_time; 452 *ts_raw = timespec64_to_timespec(tk->raw_time);
450 ts_real->tv_sec = tk->xtime_sec; 453 ts_real->tv_sec = tk->xtime_sec;
451 ts_real->tv_nsec = 0; 454 ts_real->tv_nsec = 0;
452 455
@@ -487,7 +490,7 @@ EXPORT_SYMBOL(do_gettimeofday);
487int do_settimeofday(const struct timespec *tv) 490int do_settimeofday(const struct timespec *tv)
488{ 491{
489 struct timekeeper *tk = &timekeeper; 492 struct timekeeper *tk = &timekeeper;
490 struct timespec ts_delta, xt; 493 struct timespec64 ts_delta, xt, tmp;
491 unsigned long flags; 494 unsigned long flags;
492 495
493 if (!timespec_valid_strict(tv)) 496 if (!timespec_valid_strict(tv))
@@ -502,9 +505,10 @@ int do_settimeofday(const struct timespec *tv)
502 ts_delta.tv_sec = tv->tv_sec - xt.tv_sec; 505 ts_delta.tv_sec = tv->tv_sec - xt.tv_sec;
503 ts_delta.tv_nsec = tv->tv_nsec - xt.tv_nsec; 506 ts_delta.tv_nsec = tv->tv_nsec - xt.tv_nsec;
504 507
505 tk_set_wall_to_mono(tk, timespec_sub(tk->wall_to_monotonic, ts_delta)); 508 tk_set_wall_to_mono(tk, timespec64_sub(tk->wall_to_monotonic, ts_delta));
506 509
507 tk_set_xtime(tk, tv); 510 tmp = timespec_to_timespec64(*tv);
511 tk_set_xtime(tk, &tmp);
508 512
509 timekeeping_update(tk, TK_CLEAR_NTP | TK_MIRROR | TK_CLOCK_WAS_SET); 513 timekeeping_update(tk, TK_CLEAR_NTP | TK_MIRROR | TK_CLOCK_WAS_SET);
510 514
@@ -528,26 +532,28 @@ int timekeeping_inject_offset(struct timespec *ts)
528{ 532{
529 struct timekeeper *tk = &timekeeper; 533 struct timekeeper *tk = &timekeeper;
530 unsigned long flags; 534 unsigned long flags;
531 struct timespec tmp; 535 struct timespec64 ts64, tmp;
532 int ret = 0; 536 int ret = 0;
533 537
534 if ((unsigned long)ts->tv_nsec >= NSEC_PER_SEC) 538 if ((unsigned long)ts->tv_nsec >= NSEC_PER_SEC)
535 return -EINVAL; 539 return -EINVAL;
536 540
541 ts64 = timespec_to_timespec64(*ts);
542
537 raw_spin_lock_irqsave(&timekeeper_lock, flags); 543 raw_spin_lock_irqsave(&timekeeper_lock, flags);
538 write_seqcount_begin(&timekeeper_seq); 544 write_seqcount_begin(&timekeeper_seq);
539 545
540 timekeeping_forward_now(tk); 546 timekeeping_forward_now(tk);
541 547
542 /* Make sure the proposed value is valid */ 548 /* Make sure the proposed value is valid */
543 tmp = timespec_add(tk_xtime(tk), *ts); 549 tmp = timespec64_add(tk_xtime(tk), ts64);
544 if (!timespec_valid_strict(&tmp)) { 550 if (!timespec64_valid_strict(&tmp)) {
545 ret = -EINVAL; 551 ret = -EINVAL;
546 goto error; 552 goto error;
547 } 553 }
548 554
549 tk_xtime_add(tk, ts); 555 tk_xtime_add(tk, &ts64);
550 tk_set_wall_to_mono(tk, timespec_sub(tk->wall_to_monotonic, *ts)); 556 tk_set_wall_to_mono(tk, timespec64_sub(tk->wall_to_monotonic, ts64));
551 557
552error: /* even if we error out, we forwarded the time, so call update */ 558error: /* even if we error out, we forwarded the time, so call update */
553 timekeeping_update(tk, TK_CLEAR_NTP | TK_MIRROR | TK_CLOCK_WAS_SET); 559 timekeeping_update(tk, TK_CLEAR_NTP | TK_MIRROR | TK_CLOCK_WAS_SET);
@@ -691,17 +697,19 @@ EXPORT_SYMBOL_GPL(ktime_get_real);
691void getrawmonotonic(struct timespec *ts) 697void getrawmonotonic(struct timespec *ts)
692{ 698{
693 struct timekeeper *tk = &timekeeper; 699 struct timekeeper *tk = &timekeeper;
700 struct timespec64 ts64;
694 unsigned long seq; 701 unsigned long seq;
695 s64 nsecs; 702 s64 nsecs;
696 703
697 do { 704 do {
698 seq = read_seqcount_begin(&timekeeper_seq); 705 seq = read_seqcount_begin(&timekeeper_seq);
699 nsecs = timekeeping_get_ns_raw(tk); 706 nsecs = timekeeping_get_ns_raw(tk);
700 *ts = tk->raw_time; 707 ts64 = tk->raw_time;
701 708
702 } while (read_seqcount_retry(&timekeeper_seq, seq)); 709 } while (read_seqcount_retry(&timekeeper_seq, seq));
703 710
704 timespec_add_ns(ts, nsecs); 711 timespec64_add_ns(&ts64, nsecs);
712 *ts = timespec64_to_timespec(ts64);
705} 713}
706EXPORT_SYMBOL(getrawmonotonic); 714EXPORT_SYMBOL(getrawmonotonic);
707 715
@@ -781,11 +789,12 @@ void __init timekeeping_init(void)
781 struct timekeeper *tk = &timekeeper; 789 struct timekeeper *tk = &timekeeper;
782 struct clocksource *clock; 790 struct clocksource *clock;
783 unsigned long flags; 791 unsigned long flags;
784 struct timespec now, boot, tmp; 792 struct timespec64 now, boot, tmp;
785 793 struct timespec ts;
786 read_persistent_clock(&now);
787 794
788 if (!timespec_valid_strict(&now)) { 795 read_persistent_clock(&ts);
796 now = timespec_to_timespec64(ts);
797 if (!timespec64_valid_strict(&now)) {
789 pr_warn("WARNING: Persistent clock returned invalid value!\n" 798 pr_warn("WARNING: Persistent clock returned invalid value!\n"
790 " Check your CMOS/BIOS settings.\n"); 799 " Check your CMOS/BIOS settings.\n");
791 now.tv_sec = 0; 800 now.tv_sec = 0;
@@ -793,8 +802,9 @@ void __init timekeeping_init(void)
793 } else if (now.tv_sec || now.tv_nsec) 802 } else if (now.tv_sec || now.tv_nsec)
794 persistent_clock_exist = true; 803 persistent_clock_exist = true;
795 804
796 read_boot_clock(&boot); 805 read_boot_clock(&ts);
797 if (!timespec_valid_strict(&boot)) { 806 boot = timespec_to_timespec64(ts);
807 if (!timespec64_valid_strict(&boot)) {
798 pr_warn("WARNING: Boot clock returned invalid value!\n" 808 pr_warn("WARNING: Boot clock returned invalid value!\n"
799 " Check your CMOS/BIOS settings.\n"); 809 " Check your CMOS/BIOS settings.\n");
800 boot.tv_sec = 0; 810 boot.tv_sec = 0;
@@ -816,7 +826,7 @@ void __init timekeeping_init(void)
816 if (boot.tv_sec == 0 && boot.tv_nsec == 0) 826 if (boot.tv_sec == 0 && boot.tv_nsec == 0)
817 boot = tk_xtime(tk); 827 boot = tk_xtime(tk);
818 828
819 set_normalized_timespec(&tmp, -boot.tv_sec, -boot.tv_nsec); 829 set_normalized_timespec64(&tmp, -boot.tv_sec, -boot.tv_nsec);
820 tk_set_wall_to_mono(tk, tmp); 830 tk_set_wall_to_mono(tk, tmp);
821 831
822 tmp.tv_sec = 0; 832 tmp.tv_sec = 0;
@@ -830,7 +840,7 @@ void __init timekeeping_init(void)
830} 840}
831 841
832/* time in seconds when suspend began */ 842/* time in seconds when suspend began */
833static struct timespec timekeeping_suspend_time; 843static struct timespec64 timekeeping_suspend_time;
834 844
835/** 845/**
836 * __timekeeping_inject_sleeptime - Internal function to add sleep interval 846 * __timekeeping_inject_sleeptime - Internal function to add sleep interval
@@ -840,17 +850,17 @@ static struct timespec timekeeping_suspend_time;
840 * adds the sleep offset to the timekeeping variables. 850 * adds the sleep offset to the timekeeping variables.
841 */ 851 */
842static void __timekeeping_inject_sleeptime(struct timekeeper *tk, 852static void __timekeeping_inject_sleeptime(struct timekeeper *tk,
843 struct timespec *delta) 853 struct timespec64 *delta)
844{ 854{
845 if (!timespec_valid_strict(delta)) { 855 if (!timespec64_valid_strict(delta)) {
846 printk_deferred(KERN_WARNING 856 printk_deferred(KERN_WARNING
847 "__timekeeping_inject_sleeptime: Invalid " 857 "__timekeeping_inject_sleeptime: Invalid "
848 "sleep delta value!\n"); 858 "sleep delta value!\n");
849 return; 859 return;
850 } 860 }
851 tk_xtime_add(tk, delta); 861 tk_xtime_add(tk, delta);
852 tk_set_wall_to_mono(tk, timespec_sub(tk->wall_to_monotonic, *delta)); 862 tk_set_wall_to_mono(tk, timespec64_sub(tk->wall_to_monotonic, *delta));
853 tk_set_sleep_time(tk, timespec_add(tk->total_sleep_time, *delta)); 863 tk_set_sleep_time(tk, timespec64_add(tk->total_sleep_time, *delta));
854 tk_debug_account_sleep_time(delta); 864 tk_debug_account_sleep_time(delta);
855} 865}
856 866
@@ -867,6 +877,7 @@ static void __timekeeping_inject_sleeptime(struct timekeeper *tk,
867void timekeeping_inject_sleeptime(struct timespec *delta) 877void timekeeping_inject_sleeptime(struct timespec *delta)
868{ 878{
869 struct timekeeper *tk = &timekeeper; 879 struct timekeeper *tk = &timekeeper;
880 struct timespec64 tmp;
870 unsigned long flags; 881 unsigned long flags;
871 882
872 /* 883 /*
@@ -881,7 +892,8 @@ void timekeeping_inject_sleeptime(struct timespec *delta)
881 892
882 timekeeping_forward_now(tk); 893 timekeeping_forward_now(tk);
883 894
884 __timekeeping_inject_sleeptime(tk, delta); 895 tmp = timespec_to_timespec64(*delta);
896 __timekeeping_inject_sleeptime(tk, &tmp);
885 897
886 timekeeping_update(tk, TK_CLEAR_NTP | TK_MIRROR | TK_CLOCK_WAS_SET); 898 timekeeping_update(tk, TK_CLEAR_NTP | TK_MIRROR | TK_CLOCK_WAS_SET);
887 899
@@ -904,11 +916,13 @@ static void timekeeping_resume(void)
904 struct timekeeper *tk = &timekeeper; 916 struct timekeeper *tk = &timekeeper;
905 struct clocksource *clock = tk->clock; 917 struct clocksource *clock = tk->clock;
906 unsigned long flags; 918 unsigned long flags;
907 struct timespec ts_new, ts_delta; 919 struct timespec64 ts_new, ts_delta;
920 struct timespec tmp;
908 cycle_t cycle_now, cycle_delta; 921 cycle_t cycle_now, cycle_delta;
909 bool suspendtime_found = false; 922 bool suspendtime_found = false;
910 923
911 read_persistent_clock(&ts_new); 924 read_persistent_clock(&tmp);
925 ts_new = timespec_to_timespec64(tmp);
912 926
913 clockevents_resume(); 927 clockevents_resume();
914 clocksource_resume(); 928 clocksource_resume();
@@ -951,10 +965,10 @@ static void timekeeping_resume(void)
951 } 965 }
952 nsec += ((u64) cycle_delta * mult) >> shift; 966 nsec += ((u64) cycle_delta * mult) >> shift;
953 967
954 ts_delta = ns_to_timespec(nsec); 968 ts_delta = ns_to_timespec64(nsec);
955 suspendtime_found = true; 969 suspendtime_found = true;
956 } else if (timespec_compare(&ts_new, &timekeeping_suspend_time) > 0) { 970 } else if (timespec64_compare(&ts_new, &timekeeping_suspend_time) > 0) {
957 ts_delta = timespec_sub(ts_new, timekeeping_suspend_time); 971 ts_delta = timespec64_sub(ts_new, timekeeping_suspend_time);
958 suspendtime_found = true; 972 suspendtime_found = true;
959 } 973 }
960 974
@@ -981,10 +995,12 @@ static int timekeeping_suspend(void)
981{ 995{
982 struct timekeeper *tk = &timekeeper; 996 struct timekeeper *tk = &timekeeper;
983 unsigned long flags; 997 unsigned long flags;
984 struct timespec delta, delta_delta; 998 struct timespec64 delta, delta_delta;
985 static struct timespec old_delta; 999 static struct timespec64 old_delta;
1000 struct timespec tmp;
986 1001
987 read_persistent_clock(&timekeeping_suspend_time); 1002 read_persistent_clock(&tmp);
1003 timekeeping_suspend_time = timespec_to_timespec64(tmp);
988 1004
989 /* 1005 /*
990 * On some systems the persistent_clock can not be detected at 1006 * On some systems the persistent_clock can not be detected at
@@ -1005,8 +1021,8 @@ static int timekeeping_suspend(void)
1005 * try to compensate so the difference in system time 1021 * try to compensate so the difference in system time
1006 * and persistent_clock time stays close to constant. 1022 * and persistent_clock time stays close to constant.
1007 */ 1023 */
1008 delta = timespec_sub(tk_xtime(tk), timekeeping_suspend_time); 1024 delta = timespec64_sub(tk_xtime(tk), timekeeping_suspend_time);
1009 delta_delta = timespec_sub(delta, old_delta); 1025 delta_delta = timespec64_sub(delta, old_delta);
1010 if (abs(delta_delta.tv_sec) >= 2) { 1026 if (abs(delta_delta.tv_sec) >= 2) {
1011 /* 1027 /*
1012 * if delta_delta is too large, assume time correction 1028 * if delta_delta is too large, assume time correction
@@ -1016,7 +1032,7 @@ static int timekeeping_suspend(void)
1016 } else { 1032 } else {
1017 /* Otherwise try to adjust old_system to compensate */ 1033 /* Otherwise try to adjust old_system to compensate */
1018 timekeeping_suspend_time = 1034 timekeeping_suspend_time =
1019 timespec_add(timekeeping_suspend_time, delta_delta); 1035 timespec64_add(timekeeping_suspend_time, delta_delta);
1020 } 1036 }
1021 1037
1022 timekeeping_update(tk, TK_MIRROR); 1038 timekeeping_update(tk, TK_MIRROR);
@@ -1253,14 +1269,14 @@ static inline unsigned int accumulate_nsecs_to_secs(struct timekeeper *tk)
1253 /* Figure out if its a leap sec and apply if needed */ 1269 /* Figure out if its a leap sec and apply if needed */
1254 leap = second_overflow(tk->xtime_sec); 1270 leap = second_overflow(tk->xtime_sec);
1255 if (unlikely(leap)) { 1271 if (unlikely(leap)) {
1256 struct timespec ts; 1272 struct timespec64 ts;
1257 1273
1258 tk->xtime_sec += leap; 1274 tk->xtime_sec += leap;
1259 1275
1260 ts.tv_sec = leap; 1276 ts.tv_sec = leap;
1261 ts.tv_nsec = 0; 1277 ts.tv_nsec = 0;
1262 tk_set_wall_to_mono(tk, 1278 tk_set_wall_to_mono(tk,
1263 timespec_sub(tk->wall_to_monotonic, ts)); 1279 timespec64_sub(tk->wall_to_monotonic, ts));
1264 1280
1265 __timekeeping_set_tai_offset(tk, tk->tai_offset - leap); 1281 __timekeeping_set_tai_offset(tk, tk->tai_offset - leap);
1266 1282
@@ -1469,7 +1485,7 @@ EXPORT_SYMBOL_GPL(getboottime);
1469void get_monotonic_boottime(struct timespec *ts) 1485void get_monotonic_boottime(struct timespec *ts)
1470{ 1486{
1471 struct timekeeper *tk = &timekeeper; 1487 struct timekeeper *tk = &timekeeper;
1472 struct timespec tomono, sleep; 1488 struct timespec64 tomono, sleep, ret;
1473 s64 nsec; 1489 s64 nsec;
1474 unsigned int seq; 1490 unsigned int seq;
1475 1491
@@ -1477,16 +1493,17 @@ void get_monotonic_boottime(struct timespec *ts)
1477 1493
1478 do { 1494 do {
1479 seq = read_seqcount_begin(&timekeeper_seq); 1495 seq = read_seqcount_begin(&timekeeper_seq);
1480 ts->tv_sec = tk->xtime_sec; 1496 ret.tv_sec = tk->xtime_sec;
1481 nsec = timekeeping_get_ns(tk); 1497 nsec = timekeeping_get_ns(tk);
1482 tomono = tk->wall_to_monotonic; 1498 tomono = tk->wall_to_monotonic;
1483 sleep = tk->total_sleep_time; 1499 sleep = tk->total_sleep_time;
1484 1500
1485 } while (read_seqcount_retry(&timekeeper_seq, seq)); 1501 } while (read_seqcount_retry(&timekeeper_seq, seq));
1486 1502
1487 ts->tv_sec += tomono.tv_sec + sleep.tv_sec; 1503 ret.tv_sec += tomono.tv_sec + sleep.tv_sec;
1488 ts->tv_nsec = 0; 1504 ret.tv_nsec = 0;
1489 timespec_add_ns(ts, nsec + tomono.tv_nsec + sleep.tv_nsec); 1505 timespec64_add_ns(&ret, nsec + tomono.tv_nsec + sleep.tv_nsec);
1506 *ts = timespec64_to_timespec(ret);
1490} 1507}
1491EXPORT_SYMBOL_GPL(get_monotonic_boottime); 1508EXPORT_SYMBOL_GPL(get_monotonic_boottime);
1492 1509
@@ -1514,8 +1531,11 @@ EXPORT_SYMBOL_GPL(ktime_get_boottime);
1514void monotonic_to_bootbased(struct timespec *ts) 1531void monotonic_to_bootbased(struct timespec *ts)
1515{ 1532{
1516 struct timekeeper *tk = &timekeeper; 1533 struct timekeeper *tk = &timekeeper;
1534 struct timespec64 ts64;
1517 1535
1518 *ts = timespec_add(*ts, tk->total_sleep_time); 1536 ts64 = timespec_to_timespec64(*ts);
1537 ts64 = timespec64_add(ts64, tk->total_sleep_time);
1538 *ts = timespec64_to_timespec(ts64);
1519} 1539}
1520EXPORT_SYMBOL_GPL(monotonic_to_bootbased); 1540EXPORT_SYMBOL_GPL(monotonic_to_bootbased);
1521 1541
@@ -1531,13 +1551,13 @@ struct timespec __current_kernel_time(void)
1531{ 1551{
1532 struct timekeeper *tk = &timekeeper; 1552 struct timekeeper *tk = &timekeeper;
1533 1553
1534 return tk_xtime(tk); 1554 return timespec64_to_timespec(tk_xtime(tk));
1535} 1555}
1536 1556
1537struct timespec current_kernel_time(void) 1557struct timespec current_kernel_time(void)
1538{ 1558{
1539 struct timekeeper *tk = &timekeeper; 1559 struct timekeeper *tk = &timekeeper;
1540 struct timespec now; 1560 struct timespec64 now;
1541 unsigned long seq; 1561 unsigned long seq;
1542 1562
1543 do { 1563 do {
@@ -1546,14 +1566,14 @@ struct timespec current_kernel_time(void)
1546 now = tk_xtime(tk); 1566 now = tk_xtime(tk);
1547 } while (read_seqcount_retry(&timekeeper_seq, seq)); 1567 } while (read_seqcount_retry(&timekeeper_seq, seq));
1548 1568
1549 return now; 1569 return timespec64_to_timespec(now);
1550} 1570}
1551EXPORT_SYMBOL(current_kernel_time); 1571EXPORT_SYMBOL(current_kernel_time);
1552 1572
1553struct timespec get_monotonic_coarse(void) 1573struct timespec get_monotonic_coarse(void)
1554{ 1574{
1555 struct timekeeper *tk = &timekeeper; 1575 struct timekeeper *tk = &timekeeper;
1556 struct timespec now, mono; 1576 struct timespec64 now, mono;
1557 unsigned long seq; 1577 unsigned long seq;
1558 1578
1559 do { 1579 do {
@@ -1563,9 +1583,10 @@ struct timespec get_monotonic_coarse(void)
1563 mono = tk->wall_to_monotonic; 1583 mono = tk->wall_to_monotonic;
1564 } while (read_seqcount_retry(&timekeeper_seq, seq)); 1584 } while (read_seqcount_retry(&timekeeper_seq, seq));
1565 1585
1566 set_normalized_timespec(&now, now.tv_sec + mono.tv_sec, 1586 set_normalized_timespec64(&now, now.tv_sec + mono.tv_sec,
1567 now.tv_nsec + mono.tv_nsec); 1587 now.tv_nsec + mono.tv_nsec);
1568 return now; 1588
1589 return timespec64_to_timespec(now);
1569} 1590}
1570 1591
1571/* 1592/*
@@ -1589,7 +1610,7 @@ ktime_t ktime_get_update_offsets_tick(ktime_t *offs_real, ktime_t *offs_boot,
1589 ktime_t *offs_tai) 1610 ktime_t *offs_tai)
1590{ 1611{
1591 struct timekeeper *tk = &timekeeper; 1612 struct timekeeper *tk = &timekeeper;
1592 struct timespec ts; 1613 struct timespec64 ts;
1593 ktime_t now; 1614 ktime_t now;
1594 unsigned int seq; 1615 unsigned int seq;
1595 1616
@@ -1597,7 +1618,6 @@ ktime_t ktime_get_update_offsets_tick(ktime_t *offs_real, ktime_t *offs_boot,
1597 seq = read_seqcount_begin(&timekeeper_seq); 1618 seq = read_seqcount_begin(&timekeeper_seq);
1598 1619
1599 ts = tk_xtime(tk); 1620 ts = tk_xtime(tk);
1600
1601 *offs_real = tk->offs_real; 1621 *offs_real = tk->offs_real;
1602 *offs_boot = tk->offs_boot; 1622 *offs_boot = tk->offs_boot;
1603 *offs_tai = tk->offs_tai; 1623 *offs_tai = tk->offs_tai;
@@ -1650,14 +1670,14 @@ ktime_t ktime_get_monotonic_offset(void)
1650{ 1670{
1651 struct timekeeper *tk = &timekeeper; 1671 struct timekeeper *tk = &timekeeper;
1652 unsigned long seq; 1672 unsigned long seq;
1653 struct timespec wtom; 1673 struct timespec64 wtom;
1654 1674
1655 do { 1675 do {
1656 seq = read_seqcount_begin(&timekeeper_seq); 1676 seq = read_seqcount_begin(&timekeeper_seq);
1657 wtom = tk->wall_to_monotonic; 1677 wtom = tk->wall_to_monotonic;
1658 } while (read_seqcount_retry(&timekeeper_seq, seq)); 1678 } while (read_seqcount_retry(&timekeeper_seq, seq));
1659 1679
1660 return timespec_to_ktime(wtom); 1680 return timespec64_to_ktime(wtom);
1661} 1681}
1662EXPORT_SYMBOL_GPL(ktime_get_monotonic_offset); 1682EXPORT_SYMBOL_GPL(ktime_get_monotonic_offset);
1663 1683
@@ -1668,7 +1688,8 @@ int do_adjtimex(struct timex *txc)
1668{ 1688{
1669 struct timekeeper *tk = &timekeeper; 1689 struct timekeeper *tk = &timekeeper;
1670 unsigned long flags; 1690 unsigned long flags;
1671 struct timespec ts; 1691 struct timespec64 ts;
1692 struct timespec tmp;
1672 s32 orig_tai, tai; 1693 s32 orig_tai, tai;
1673 int ret; 1694 int ret;
1674 1695
@@ -1688,7 +1709,8 @@ int do_adjtimex(struct timex *txc)
1688 return ret; 1709 return ret;
1689 } 1710 }
1690 1711
1691 getnstimeofday(&ts); 1712 getnstimeofday(&tmp);
1713 ts = timespec_to_timespec64(tmp);
1692 1714
1693 raw_spin_lock_irqsave(&timekeeper_lock, flags); 1715 raw_spin_lock_irqsave(&timekeeper_lock, flags);
1694 write_seqcount_begin(&timekeeper_seq); 1716 write_seqcount_begin(&timekeeper_seq);
diff --git a/kernel/time/timekeeping_debug.c b/kernel/time/timekeeping_debug.c
index 4d54f97558df..f6bd65236712 100644
--- a/kernel/time/timekeeping_debug.c
+++ b/kernel/time/timekeeping_debug.c
@@ -67,7 +67,7 @@ static int __init tk_debug_sleep_time_init(void)
67} 67}
68late_initcall(tk_debug_sleep_time_init); 68late_initcall(tk_debug_sleep_time_init);
69 69
70void tk_debug_account_sleep_time(struct timespec *t) 70void tk_debug_account_sleep_time(struct timespec64 *t)
71{ 71{
72 sleep_time_bin[fls(t->tv_sec)]++; 72 sleep_time_bin[fls(t->tv_sec)]++;
73} 73}
diff --git a/kernel/time/timekeeping_internal.h b/kernel/time/timekeeping_internal.h
index 13323ea08ffa..e3d28ad236f9 100644
--- a/kernel/time/timekeeping_internal.h
+++ b/kernel/time/timekeeping_internal.h
@@ -6,7 +6,7 @@
6#include <linux/time.h> 6#include <linux/time.h>
7 7
8#ifdef CONFIG_DEBUG_FS 8#ifdef CONFIG_DEBUG_FS
9extern void tk_debug_account_sleep_time(struct timespec *t); 9extern void tk_debug_account_sleep_time(struct timespec64 *t);
10#else 10#else
11#define tk_debug_account_sleep_time(x) 11#define tk_debug_account_sleep_time(x)
12#endif 12#endif