aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/time
diff options
context:
space:
mode:
authorJohn Stultz <john.stultz@linaro.org>2012-07-13 01:21:53 -0400
committerThomas Gleixner <tglx@linutronix.de>2012-07-15 04:39:06 -0400
commit1e75fa8be9fb61e1af46b5b3b176347a4c958ca1 (patch)
treeb353cf5c5ae0c17e7813d7e1e86a403227b35fc7 /kernel/time
parentfee84c43e6afc42295ae8058cbbef9ea5633926c (diff)
time: Condense timekeeper.xtime into xtime_sec
The timekeeper struct has a xtime_nsec, which keeps the sub-nanosecond remainder. This ends up being somewhat duplicative of the timekeeper.xtime.tv_nsec value, and we have to do extra work to keep them apart, copying the full nsec portion out and back in over and over. This patch simplifies some of the logic by taking the timekeeper xtime value and splitting it into timekeeper.xtime_sec and reuses the timekeeper.xtime_nsec for the sub-second portion (stored in higher res shifted nanoseconds). This simplifies some of the accumulation logic. And will allow for more accurate timekeeping once the vsyscall code is updated to use the shifted nanosecond remainder. Signed-off-by: John Stultz <john.stultz@linaro.org> Reviewed-by: Ingo Molnar <mingo@kernel.org> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Richard Cochran <richardcochran@gmail.com> Cc: Prarit Bhargava <prarit@redhat.com> Link: http://lkml.kernel.org/r/1342156917-25092-5-git-send-email-john.stultz@linaro.org Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Diffstat (limited to 'kernel/time')
-rw-r--r--kernel/time/timekeeping.c181
1 files changed, 110 insertions, 71 deletions
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index 4fd83df0b14d..b98d9bd73e5e 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -38,8 +38,11 @@ struct timekeeper {
38 /* Raw nano seconds accumulated per NTP interval. */ 38 /* Raw nano seconds accumulated per NTP interval. */
39 u32 raw_interval; 39 u32 raw_interval;
40 40
41 /* Clock shifted nano seconds remainder not stored in xtime.tv_nsec. */ 41 /* Current CLOCK_REALTIME time in seconds */
42 u64 xtime_sec;
43 /* Clock shifted nano seconds */
42 u64 xtime_nsec; 44 u64 xtime_nsec;
45
43 /* Difference between accumulated time and NTP time in ntp 46 /* Difference between accumulated time and NTP time in ntp
44 * shifted nano seconds. */ 47 * shifted nano seconds. */
45 s64 ntp_error; 48 s64 ntp_error;
@@ -47,8 +50,6 @@ struct timekeeper {
47 * ntp shifted nano seconds. */ 50 * ntp shifted nano seconds. */
48 u32 ntp_error_shift; 51 u32 ntp_error_shift;
49 52
50 /* The current time */
51 struct timespec xtime;
52 /* 53 /*
53 * wall_to_monotonic is what we need to add to xtime (or xtime corrected 54 * wall_to_monotonic is what we need to add to xtime (or xtime corrected
54 * for sub jiffie times) to get to monotonic time. Monotonic is pegged 55 * for sub jiffie times) to get to monotonic time. Monotonic is pegged
@@ -84,11 +85,37 @@ static struct timekeeper timekeeper;
84 */ 85 */
85__cacheline_aligned_in_smp DEFINE_SEQLOCK(xtime_lock); 86__cacheline_aligned_in_smp DEFINE_SEQLOCK(xtime_lock);
86 87
87
88/* flag for if timekeeping is suspended */ 88/* flag for if timekeeping is suspended */
89int __read_mostly timekeeping_suspended; 89int __read_mostly timekeeping_suspended;
90 90
91static inline void tk_normalize_xtime(struct timekeeper *tk)
92{
93 while (tk->xtime_nsec >= ((u64)NSEC_PER_SEC << tk->shift)) {
94 tk->xtime_nsec -= (u64)NSEC_PER_SEC << tk->shift;
95 tk->xtime_sec++;
96 }
97}
98
99static struct timespec tk_xtime(struct timekeeper *tk)
100{
101 struct timespec ts;
102
103 ts.tv_sec = tk->xtime_sec;
104 ts.tv_nsec = (long)(tk->xtime_nsec >> tk->shift);
105 return ts;
106}
91 107
108static void tk_set_xtime(struct timekeeper *tk, const struct timespec *ts)
109{
110 tk->xtime_sec = ts->tv_sec;
111 tk->xtime_nsec = ts->tv_nsec << tk->shift;
112}
113
114static void tk_xtime_add(struct timekeeper *tk, const struct timespec *ts)
115{
116 tk->xtime_sec += ts->tv_sec;
117 tk->xtime_nsec += ts->tv_nsec << tk->shift;
118}
92 119
93/** 120/**
94 * timekeeper_setup_internals - Set up internals to use clocksource clock. 121 * timekeeper_setup_internals - Set up internals to use clocksource clock.
@@ -104,7 +131,9 @@ static void timekeeper_setup_internals(struct clocksource *clock)
104{ 131{
105 cycle_t interval; 132 cycle_t interval;
106 u64 tmp, ntpinterval; 133 u64 tmp, ntpinterval;
134 struct clocksource *old_clock;
107 135
136 old_clock = timekeeper.clock;
108 timekeeper.clock = clock; 137 timekeeper.clock = clock;
109 clock->cycle_last = clock->read(clock); 138 clock->cycle_last = clock->read(clock);
110 139
@@ -126,7 +155,14 @@ static void timekeeper_setup_internals(struct clocksource *clock)
126 timekeeper.raw_interval = 155 timekeeper.raw_interval =
127 ((u64) interval * clock->mult) >> clock->shift; 156 ((u64) interval * clock->mult) >> clock->shift;
128 157
129 timekeeper.xtime_nsec = 0; 158 /* if changing clocks, convert xtime_nsec shift units */
159 if (old_clock) {
160 int shift_change = clock->shift - old_clock->shift;
161 if (shift_change < 0)
162 timekeeper.xtime_nsec >>= -shift_change;
163 else
164 timekeeper.xtime_nsec <<= shift_change;
165 }
130 timekeeper.shift = clock->shift; 166 timekeeper.shift = clock->shift;
131 167
132 timekeeper.ntp_error = 0; 168 timekeeper.ntp_error = 0;
@@ -145,6 +181,7 @@ static inline s64 timekeeping_get_ns(void)
145{ 181{
146 cycle_t cycle_now, cycle_delta; 182 cycle_t cycle_now, cycle_delta;
147 struct clocksource *clock; 183 struct clocksource *clock;
184 s64 nsec;
148 185
149 /* read clocksource: */ 186 /* read clocksource: */
150 clock = timekeeper.clock; 187 clock = timekeeper.clock;
@@ -153,9 +190,8 @@ static inline s64 timekeeping_get_ns(void)
153 /* calculate the delta since the last update_wall_time: */ 190 /* calculate the delta since the last update_wall_time: */
154 cycle_delta = (cycle_now - clock->cycle_last) & clock->mask; 191 cycle_delta = (cycle_now - clock->cycle_last) & clock->mask;
155 192
156 /* return delta convert to nanoseconds using ntp adjusted mult. */ 193 nsec = cycle_delta * timekeeper.mult + timekeeper.xtime_nsec;
157 return clocksource_cyc2ns(cycle_delta, timekeeper.mult, 194 return nsec >> timekeeper.shift;
158 timekeeper.shift);
159} 195}
160 196
161static inline s64 timekeeping_get_ns_raw(void) 197static inline s64 timekeeping_get_ns_raw(void)
@@ -185,12 +221,15 @@ static void update_rt_offset(void)
185/* must hold write on timekeeper.lock */ 221/* must hold write on timekeeper.lock */
186static void timekeeping_update(bool clearntp) 222static void timekeeping_update(bool clearntp)
187{ 223{
224 struct timespec xt;
225
188 if (clearntp) { 226 if (clearntp) {
189 timekeeper.ntp_error = 0; 227 timekeeper.ntp_error = 0;
190 ntp_clear(); 228 ntp_clear();
191 } 229 }
192 update_rt_offset(); 230 update_rt_offset();
193 update_vsyscall(&timekeeper.xtime, &timekeeper.wall_to_monotonic, 231 xt = tk_xtime(&timekeeper);
232 update_vsyscall(&xt, &timekeeper.wall_to_monotonic,
194 timekeeper.clock, timekeeper.mult); 233 timekeeper.clock, timekeeper.mult);
195} 234}
196 235
@@ -213,13 +252,12 @@ static void timekeeping_forward_now(void)
213 cycle_delta = (cycle_now - clock->cycle_last) & clock->mask; 252 cycle_delta = (cycle_now - clock->cycle_last) & clock->mask;
214 clock->cycle_last = cycle_now; 253 clock->cycle_last = cycle_now;
215 254
216 nsec = clocksource_cyc2ns(cycle_delta, timekeeper.mult, 255 timekeeper.xtime_nsec += cycle_delta * timekeeper.mult;
217 timekeeper.shift);
218 256
219 /* If arch requires, add in gettimeoffset() */ 257 /* If arch requires, add in gettimeoffset() */
220 nsec += arch_gettimeoffset(); 258 timekeeper.xtime_nsec += arch_gettimeoffset() << timekeeper.shift;
221 259
222 timespec_add_ns(&timekeeper.xtime, nsec); 260 tk_normalize_xtime(&timekeeper);
223 261
224 nsec = clocksource_cyc2ns(cycle_delta, clock->mult, clock->shift); 262 nsec = clocksource_cyc2ns(cycle_delta, clock->mult, clock->shift);
225 timespec_add_ns(&timekeeper.raw_time, nsec); 263 timespec_add_ns(&timekeeper.raw_time, nsec);
@@ -234,15 +272,15 @@ static void timekeeping_forward_now(void)
234void getnstimeofday(struct timespec *ts) 272void getnstimeofday(struct timespec *ts)
235{ 273{
236 unsigned long seq; 274 unsigned long seq;
237 s64 nsecs; 275 s64 nsecs = 0;
238 276
239 WARN_ON(timekeeping_suspended); 277 WARN_ON(timekeeping_suspended);
240 278
241 do { 279 do {
242 seq = read_seqbegin(&timekeeper.lock); 280 seq = read_seqbegin(&timekeeper.lock);
243 281
244 *ts = timekeeper.xtime; 282 ts->tv_sec = timekeeper.xtime_sec;
245 nsecs = timekeeping_get_ns(); 283 ts->tv_nsec = timekeeping_get_ns();
246 284
247 /* If arch requires, add in gettimeoffset() */ 285 /* If arch requires, add in gettimeoffset() */
248 nsecs += arch_gettimeoffset(); 286 nsecs += arch_gettimeoffset();
@@ -262,11 +300,10 @@ ktime_t ktime_get(void)
262 300
263 do { 301 do {
264 seq = read_seqbegin(&timekeeper.lock); 302 seq = read_seqbegin(&timekeeper.lock);
265 secs = timekeeper.xtime.tv_sec + 303 secs = timekeeper.xtime_sec +
266 timekeeper.wall_to_monotonic.tv_sec; 304 timekeeper.wall_to_monotonic.tv_sec;
267 nsecs = timekeeper.xtime.tv_nsec + 305 nsecs = timekeeping_get_ns() +
268 timekeeper.wall_to_monotonic.tv_nsec; 306 timekeeper.wall_to_monotonic.tv_nsec;
269 nsecs += timekeeping_get_ns();
270 /* If arch requires, add in gettimeoffset() */ 307 /* If arch requires, add in gettimeoffset() */
271 nsecs += arch_gettimeoffset(); 308 nsecs += arch_gettimeoffset();
272 309
@@ -291,22 +328,21 @@ void ktime_get_ts(struct timespec *ts)
291{ 328{
292 struct timespec tomono; 329 struct timespec tomono;
293 unsigned int seq; 330 unsigned int seq;
294 s64 nsecs;
295 331
296 WARN_ON(timekeeping_suspended); 332 WARN_ON(timekeeping_suspended);
297 333
298 do { 334 do {
299 seq = read_seqbegin(&timekeeper.lock); 335 seq = read_seqbegin(&timekeeper.lock);
300 *ts = timekeeper.xtime; 336 ts->tv_sec = timekeeper.xtime_sec;
337 ts->tv_nsec = timekeeping_get_ns();
301 tomono = timekeeper.wall_to_monotonic; 338 tomono = timekeeper.wall_to_monotonic;
302 nsecs = timekeeping_get_ns();
303 /* If arch requires, add in gettimeoffset() */ 339 /* If arch requires, add in gettimeoffset() */
304 nsecs += arch_gettimeoffset(); 340 ts->tv_nsec += arch_gettimeoffset();
305 341
306 } while (read_seqretry(&timekeeper.lock, seq)); 342 } while (read_seqretry(&timekeeper.lock, seq));
307 343
308 set_normalized_timespec(ts, ts->tv_sec + tomono.tv_sec, 344 set_normalized_timespec(ts, ts->tv_sec + tomono.tv_sec,
309 ts->tv_nsec + tomono.tv_nsec + nsecs); 345 ts->tv_nsec + tomono.tv_nsec);
310} 346}
311EXPORT_SYMBOL_GPL(ktime_get_ts); 347EXPORT_SYMBOL_GPL(ktime_get_ts);
312 348
@@ -334,7 +370,8 @@ void getnstime_raw_and_real(struct timespec *ts_raw, struct timespec *ts_real)
334 seq = read_seqbegin(&timekeeper.lock); 370 seq = read_seqbegin(&timekeeper.lock);
335 371
336 *ts_raw = timekeeper.raw_time; 372 *ts_raw = timekeeper.raw_time;
337 *ts_real = timekeeper.xtime; 373 ts_real->tv_sec = timekeeper.xtime_sec;
374 ts_real->tv_nsec = 0;
338 375
339 nsecs_raw = timekeeping_get_ns_raw(); 376 nsecs_raw = timekeeping_get_ns_raw();
340 nsecs_real = timekeeping_get_ns(); 377 nsecs_real = timekeeping_get_ns();
@@ -377,7 +414,7 @@ EXPORT_SYMBOL(do_gettimeofday);
377 */ 414 */
378int do_settimeofday(const struct timespec *tv) 415int do_settimeofday(const struct timespec *tv)
379{ 416{
380 struct timespec ts_delta; 417 struct timespec ts_delta, xt;
381 unsigned long flags; 418 unsigned long flags;
382 419
383 if ((unsigned long)tv->tv_nsec >= NSEC_PER_SEC) 420 if ((unsigned long)tv->tv_nsec >= NSEC_PER_SEC)
@@ -387,12 +424,15 @@ int do_settimeofday(const struct timespec *tv)
387 424
388 timekeeping_forward_now(); 425 timekeeping_forward_now();
389 426
390 ts_delta.tv_sec = tv->tv_sec - timekeeper.xtime.tv_sec; 427 xt = tk_xtime(&timekeeper);
391 ts_delta.tv_nsec = tv->tv_nsec - timekeeper.xtime.tv_nsec; 428 ts_delta.tv_sec = tv->tv_sec - xt.tv_sec;
429 ts_delta.tv_nsec = tv->tv_nsec - xt.tv_nsec;
430
392 timekeeper.wall_to_monotonic = 431 timekeeper.wall_to_monotonic =
393 timespec_sub(timekeeper.wall_to_monotonic, ts_delta); 432 timespec_sub(timekeeper.wall_to_monotonic, ts_delta);
394 433
395 timekeeper.xtime = *tv; 434 tk_set_xtime(&timekeeper, tv);
435
396 timekeeping_update(true); 436 timekeeping_update(true);
397 437
398 write_sequnlock_irqrestore(&timekeeper.lock, flags); 438 write_sequnlock_irqrestore(&timekeeper.lock, flags);
@@ -422,7 +462,8 @@ int timekeeping_inject_offset(struct timespec *ts)
422 462
423 timekeeping_forward_now(); 463 timekeeping_forward_now();
424 464
425 timekeeper.xtime = timespec_add(timekeeper.xtime, *ts); 465
466 tk_xtime_add(&timekeeper, ts);
426 timekeeper.wall_to_monotonic = 467 timekeeper.wall_to_monotonic =
427 timespec_sub(timekeeper.wall_to_monotonic, *ts); 468 timespec_sub(timekeeper.wall_to_monotonic, *ts);
428 469
@@ -606,14 +647,12 @@ void __init timekeeping_init(void)
606 clock->enable(clock); 647 clock->enable(clock);
607 timekeeper_setup_internals(clock); 648 timekeeper_setup_internals(clock);
608 649
609 timekeeper.xtime.tv_sec = now.tv_sec; 650 tk_set_xtime(&timekeeper, &now);
610 timekeeper.xtime.tv_nsec = now.tv_nsec;
611 timekeeper.raw_time.tv_sec = 0; 651 timekeeper.raw_time.tv_sec = 0;
612 timekeeper.raw_time.tv_nsec = 0; 652 timekeeper.raw_time.tv_nsec = 0;
613 if (boot.tv_sec == 0 && boot.tv_nsec == 0) { 653 if (boot.tv_sec == 0 && boot.tv_nsec == 0)
614 boot.tv_sec = timekeeper.xtime.tv_sec; 654 boot = tk_xtime(&timekeeper);
615 boot.tv_nsec = timekeeper.xtime.tv_nsec; 655
616 }
617 set_normalized_timespec(&timekeeper.wall_to_monotonic, 656 set_normalized_timespec(&timekeeper.wall_to_monotonic,
618 -boot.tv_sec, -boot.tv_nsec); 657 -boot.tv_sec, -boot.tv_nsec);
619 update_rt_offset(); 658 update_rt_offset();
@@ -646,7 +685,7 @@ static void __timekeeping_inject_sleeptime(struct timespec *delta)
646 return; 685 return;
647 } 686 }
648 687
649 timekeeper.xtime = timespec_add(timekeeper.xtime, *delta); 688 tk_xtime_add(&timekeeper, delta);
650 timekeeper.wall_to_monotonic = 689 timekeeper.wall_to_monotonic =
651 timespec_sub(timekeeper.wall_to_monotonic, *delta); 690 timespec_sub(timekeeper.wall_to_monotonic, *delta);
652 update_sleep_time(timespec_add(timekeeper.total_sleep_time, *delta)); 691 update_sleep_time(timespec_add(timekeeper.total_sleep_time, *delta));
@@ -742,7 +781,7 @@ static int timekeeping_suspend(void)
742 * try to compensate so the difference in system time 781 * try to compensate so the difference in system time
743 * and persistent_clock time stays close to constant. 782 * and persistent_clock time stays close to constant.
744 */ 783 */
745 delta = timespec_sub(timekeeper.xtime, timekeeping_suspend_time); 784 delta = timespec_sub(tk_xtime(&timekeeper), timekeeping_suspend_time);
746 delta_delta = timespec_sub(delta, old_delta); 785 delta_delta = timespec_sub(delta, old_delta);
747 if (abs(delta_delta.tv_sec) >= 2) { 786 if (abs(delta_delta.tv_sec) >= 2) {
748 /* 787 /*
@@ -977,9 +1016,9 @@ static cycle_t logarithmic_accumulation(cycle_t offset, u32 shift)
977 while (timekeeper.xtime_nsec >= nsecps) { 1016 while (timekeeper.xtime_nsec >= nsecps) {
978 int leap; 1017 int leap;
979 timekeeper.xtime_nsec -= nsecps; 1018 timekeeper.xtime_nsec -= nsecps;
980 timekeeper.xtime.tv_sec++; 1019 timekeeper.xtime_sec++;
981 leap = second_overflow(timekeeper.xtime.tv_sec); 1020 leap = second_overflow(timekeeper.xtime_sec);
982 timekeeper.xtime.tv_sec += leap; 1021 timekeeper.xtime_sec += leap;
983 timekeeper.wall_to_monotonic.tv_sec -= leap; 1022 timekeeper.wall_to_monotonic.tv_sec -= leap;
984 if (leap) 1023 if (leap)
985 clock_was_set_delayed(); 1024 clock_was_set_delayed();
@@ -1015,6 +1054,7 @@ static void update_wall_time(void)
1015 cycle_t offset; 1054 cycle_t offset;
1016 int shift = 0, maxshift; 1055 int shift = 0, maxshift;
1017 unsigned long flags; 1056 unsigned long flags;
1057 s64 remainder;
1018 1058
1019 write_seqlock_irqsave(&timekeeper.lock, flags); 1059 write_seqlock_irqsave(&timekeeper.lock, flags);
1020 1060
@@ -1029,8 +1069,6 @@ static void update_wall_time(void)
1029#else 1069#else
1030 offset = (clock->read(clock) - clock->cycle_last) & clock->mask; 1070 offset = (clock->read(clock) - clock->cycle_last) & clock->mask;
1031#endif 1071#endif
1032 timekeeper.xtime_nsec = (s64)timekeeper.xtime.tv_nsec <<
1033 timekeeper.shift;
1034 1072
1035 /* 1073 /*
1036 * With NO_HZ we may have to accumulate many cycle_intervals 1074 * With NO_HZ we may have to accumulate many cycle_intervals
@@ -1076,28 +1114,31 @@ static void update_wall_time(void)
1076 timekeeper.ntp_error += neg << timekeeper.ntp_error_shift; 1114 timekeeper.ntp_error += neg << timekeeper.ntp_error_shift;
1077 } 1115 }
1078 1116
1079
1080 /* 1117 /*
1081 * Store full nanoseconds into xtime after rounding it up and 1118 * Store only full nanoseconds into xtime_nsec after rounding
1082 * add the remainder to the error difference. 1119 * it up and add the remainder to the error difference.
1083 */ 1120 * XXX - This is necessary to avoid small 1ns inconsistnecies caused
1084 timekeeper.xtime.tv_nsec = ((s64)timekeeper.xtime_nsec >> 1121 * by truncating the remainder in vsyscalls. However, it causes
1085 timekeeper.shift) + 1; 1122 * additional work to be done in timekeeping_adjust(). Once
1086 timekeeper.xtime_nsec -= (s64)timekeeper.xtime.tv_nsec << 1123 * the vsyscall implementations are converted to use xtime_nsec
1087 timekeeper.shift; 1124 * (shifted nanoseconds), this can be killed.
1088 timekeeper.ntp_error += timekeeper.xtime_nsec << 1125 */
1089 timekeeper.ntp_error_shift; 1126 remainder = timekeeper.xtime_nsec & ((1 << timekeeper.shift) - 1);
1127 timekeeper.xtime_nsec -= remainder;
1128 timekeeper.xtime_nsec += 1 << timekeeper.shift;
1129 timekeeper.ntp_error += remainder << timekeeper.ntp_error_shift;
1090 1130
1091 /* 1131 /*
1092 * Finally, make sure that after the rounding 1132 * Finally, make sure that after the rounding
1093 * xtime.tv_nsec isn't larger than NSEC_PER_SEC 1133 * xtime_nsec isn't larger than NSEC_PER_SEC
1094 */ 1134 */
1095 if (unlikely(timekeeper.xtime.tv_nsec >= NSEC_PER_SEC)) { 1135 if (unlikely(timekeeper.xtime_nsec >=
1136 ((u64)NSEC_PER_SEC << timekeeper.shift))) {
1096 int leap; 1137 int leap;
1097 timekeeper.xtime.tv_nsec -= NSEC_PER_SEC; 1138 timekeeper.xtime_nsec -= (u64)NSEC_PER_SEC << timekeeper.shift;
1098 timekeeper.xtime.tv_sec++; 1139 timekeeper.xtime_sec++;
1099 leap = second_overflow(timekeeper.xtime.tv_sec); 1140 leap = second_overflow(timekeeper.xtime_sec);
1100 timekeeper.xtime.tv_sec += leap; 1141 timekeeper.xtime_sec += leap;
1101 timekeeper.wall_to_monotonic.tv_sec -= leap; 1142 timekeeper.wall_to_monotonic.tv_sec -= leap;
1102 if (leap) 1143 if (leap)
1103 clock_was_set_delayed(); 1144 clock_was_set_delayed();
@@ -1148,21 +1189,20 @@ void get_monotonic_boottime(struct timespec *ts)
1148{ 1189{
1149 struct timespec tomono, sleep; 1190 struct timespec tomono, sleep;
1150 unsigned int seq; 1191 unsigned int seq;
1151 s64 nsecs;
1152 1192
1153 WARN_ON(timekeeping_suspended); 1193 WARN_ON(timekeeping_suspended);
1154 1194
1155 do { 1195 do {
1156 seq = read_seqbegin(&timekeeper.lock); 1196 seq = read_seqbegin(&timekeeper.lock);
1157 *ts = timekeeper.xtime; 1197 ts->tv_sec = timekeeper.xtime_sec;
1198 ts->tv_nsec = timekeeping_get_ns();
1158 tomono = timekeeper.wall_to_monotonic; 1199 tomono = timekeeper.wall_to_monotonic;
1159 sleep = timekeeper.total_sleep_time; 1200 sleep = timekeeper.total_sleep_time;
1160 nsecs = timekeeping_get_ns();
1161 1201
1162 } while (read_seqretry(&timekeeper.lock, seq)); 1202 } while (read_seqretry(&timekeeper.lock, seq));
1163 1203
1164 set_normalized_timespec(ts, ts->tv_sec + tomono.tv_sec + sleep.tv_sec, 1204 set_normalized_timespec(ts, ts->tv_sec + tomono.tv_sec + sleep.tv_sec,
1165 ts->tv_nsec + tomono.tv_nsec + sleep.tv_nsec + nsecs); 1205 ts->tv_nsec + tomono.tv_nsec + sleep.tv_nsec);
1166} 1206}
1167EXPORT_SYMBOL_GPL(get_monotonic_boottime); 1207EXPORT_SYMBOL_GPL(get_monotonic_boottime);
1168 1208
@@ -1195,13 +1235,13 @@ EXPORT_SYMBOL_GPL(monotonic_to_bootbased);
1195 1235
1196unsigned long get_seconds(void) 1236unsigned long get_seconds(void)
1197{ 1237{
1198 return timekeeper.xtime.tv_sec; 1238 return timekeeper.xtime_sec;
1199} 1239}
1200EXPORT_SYMBOL(get_seconds); 1240EXPORT_SYMBOL(get_seconds);
1201 1241
1202struct timespec __current_kernel_time(void) 1242struct timespec __current_kernel_time(void)
1203{ 1243{
1204 return timekeeper.xtime; 1244 return tk_xtime(&timekeeper);
1205} 1245}
1206 1246
1207struct timespec current_kernel_time(void) 1247struct timespec current_kernel_time(void)
@@ -1212,7 +1252,7 @@ struct timespec current_kernel_time(void)
1212 do { 1252 do {
1213 seq = read_seqbegin(&timekeeper.lock); 1253 seq = read_seqbegin(&timekeeper.lock);
1214 1254
1215 now = timekeeper.xtime; 1255 now = tk_xtime(&timekeeper);
1216 } while (read_seqretry(&timekeeper.lock, seq)); 1256 } while (read_seqretry(&timekeeper.lock, seq));
1217 1257
1218 return now; 1258 return now;
@@ -1227,7 +1267,7 @@ struct timespec get_monotonic_coarse(void)
1227 do { 1267 do {
1228 seq = read_seqbegin(&timekeeper.lock); 1268 seq = read_seqbegin(&timekeeper.lock);
1229 1269
1230 now = timekeeper.xtime; 1270 now = tk_xtime(&timekeeper);
1231 mono = timekeeper.wall_to_monotonic; 1271 mono = timekeeper.wall_to_monotonic;
1232 } while (read_seqretry(&timekeeper.lock, seq)); 1272 } while (read_seqretry(&timekeeper.lock, seq));
1233 1273
@@ -1262,7 +1302,7 @@ void get_xtime_and_monotonic_and_sleep_offset(struct timespec *xtim,
1262 1302
1263 do { 1303 do {
1264 seq = read_seqbegin(&timekeeper.lock); 1304 seq = read_seqbegin(&timekeeper.lock);
1265 *xtim = timekeeper.xtime; 1305 *xtim = tk_xtime(&timekeeper);
1266 *wtom = timekeeper.wall_to_monotonic; 1306 *wtom = timekeeper.wall_to_monotonic;
1267 *sleep = timekeeper.total_sleep_time; 1307 *sleep = timekeeper.total_sleep_time;
1268 } while (read_seqretry(&timekeeper.lock, seq)); 1308 } while (read_seqretry(&timekeeper.lock, seq));
@@ -1286,9 +1326,8 @@ ktime_t ktime_get_update_offsets(ktime_t *offs_real, ktime_t *offs_boot)
1286 do { 1326 do {
1287 seq = read_seqbegin(&timekeeper.lock); 1327 seq = read_seqbegin(&timekeeper.lock);
1288 1328
1289 secs = timekeeper.xtime.tv_sec; 1329 secs = timekeeper.xtime_sec;
1290 nsecs = timekeeper.xtime.tv_nsec; 1330 nsecs = timekeeping_get_ns();
1291 nsecs += timekeeping_get_ns();
1292 /* If arch requires, add in gettimeoffset() */ 1331 /* If arch requires, add in gettimeoffset() */
1293 nsecs += arch_gettimeoffset(); 1332 nsecs += arch_gettimeoffset();
1294 1333