aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/time
diff options
context:
space:
mode:
authorThomas Gleixner <tglx@linutronix.de>2012-02-15 14:29:18 -0500
committerThomas Gleixner <tglx@linutronix.de>2012-02-15 14:29:18 -0500
commit97ac984d2feec885d10f900591431088eab42021 (patch)
treee66e4e2ecb428d6ea45a6495b0675e3531ba23d1 /kernel/time
parent8682df25ca9afd3aac30f2c72d00bd98de2118e8 (diff)
parentcc06268c6a87db156af2daed6e96a936b955cc82 (diff)
Merge branch 'fortglx/3.4/time' of git://git.linaro.org/people/jstultz/linux into timers/core
Diffstat (limited to 'kernel/time')
-rw-r--r--kernel/time/ntp.c83
-rw-r--r--kernel/time/timekeeping.c338
2 files changed, 247 insertions, 174 deletions
diff --git a/kernel/time/ntp.c b/kernel/time/ntp.c
index f6117a4c7cb8..17fb1b9807d0 100644
--- a/kernel/time/ntp.c
+++ b/kernel/time/ntp.c
@@ -22,13 +22,16 @@
22 * NTP timekeeping variables: 22 * NTP timekeeping variables:
23 */ 23 */
24 24
25DEFINE_SPINLOCK(ntp_lock);
26
27
25/* USER_HZ period (usecs): */ 28/* USER_HZ period (usecs): */
26unsigned long tick_usec = TICK_USEC; 29unsigned long tick_usec = TICK_USEC;
27 30
28/* ACTHZ period (nsecs): */ 31/* ACTHZ period (nsecs): */
29unsigned long tick_nsec; 32unsigned long tick_nsec;
30 33
31u64 tick_length; 34static u64 tick_length;
32static u64 tick_length_base; 35static u64 tick_length_base;
33 36
34static struct hrtimer leap_timer; 37static struct hrtimer leap_timer;
@@ -49,7 +52,7 @@ static struct hrtimer leap_timer;
49static int time_state = TIME_OK; 52static int time_state = TIME_OK;
50 53
51/* clock status bits: */ 54/* clock status bits: */
52int time_status = STA_UNSYNC; 55static int time_status = STA_UNSYNC;
53 56
54/* TAI offset (secs): */ 57/* TAI offset (secs): */
55static long time_tai; 58static long time_tai;
@@ -133,7 +136,7 @@ static inline void pps_reset_freq_interval(void)
133/** 136/**
134 * pps_clear - Clears the PPS state variables 137 * pps_clear - Clears the PPS state variables
135 * 138 *
136 * Must be called while holding a write on the xtime_lock 139 * Must be called while holding a write on the ntp_lock
137 */ 140 */
138static inline void pps_clear(void) 141static inline void pps_clear(void)
139{ 142{
@@ -149,7 +152,7 @@ static inline void pps_clear(void)
149 * the last PPS signal. When it reaches 0, indicate that PPS signal is 152 * the last PPS signal. When it reaches 0, indicate that PPS signal is
150 * missing. 153 * missing.
151 * 154 *
152 * Must be called while holding a write on the xtime_lock 155 * Must be called while holding a write on the ntp_lock
153 */ 156 */
154static inline void pps_dec_valid(void) 157static inline void pps_dec_valid(void)
155{ 158{
@@ -233,6 +236,17 @@ static inline void pps_fill_timex(struct timex *txc)
233 236
234#endif /* CONFIG_NTP_PPS */ 237#endif /* CONFIG_NTP_PPS */
235 238
239
240/**
241 * ntp_synced - Returns 1 if the NTP status is not UNSYNC
242 *
243 */
244static inline int ntp_synced(void)
245{
246 return !(time_status & STA_UNSYNC);
247}
248
249
236/* 250/*
237 * NTP methods: 251 * NTP methods:
238 */ 252 */
@@ -330,11 +344,13 @@ static void ntp_update_offset(long offset)
330 344
331/** 345/**
332 * ntp_clear - Clears the NTP state variables 346 * ntp_clear - Clears the NTP state variables
333 *
334 * Must be called while holding a write on the xtime_lock
335 */ 347 */
336void ntp_clear(void) 348void ntp_clear(void)
337{ 349{
350 unsigned long flags;
351
352 spin_lock_irqsave(&ntp_lock, flags);
353
338 time_adjust = 0; /* stop active adjtime() */ 354 time_adjust = 0; /* stop active adjtime() */
339 time_status |= STA_UNSYNC; 355 time_status |= STA_UNSYNC;
340 time_maxerror = NTP_PHASE_LIMIT; 356 time_maxerror = NTP_PHASE_LIMIT;
@@ -347,8 +363,23 @@ void ntp_clear(void)
347 363
348 /* Clear PPS state variables */ 364 /* Clear PPS state variables */
349 pps_clear(); 365 pps_clear();
366 spin_unlock_irqrestore(&ntp_lock, flags);
367
350} 368}
351 369
370
371u64 ntp_tick_length(void)
372{
373 unsigned long flags;
374 s64 ret;
375
376 spin_lock_irqsave(&ntp_lock, flags);
377 ret = tick_length;
378 spin_unlock_irqrestore(&ntp_lock, flags);
379 return ret;
380}
381
382
352/* 383/*
353 * Leap second processing. If in leap-insert state at the end of the 384 * Leap second processing. If in leap-insert state at the end of the
354 * day, the system clock is set back one second; if in leap-delete 385 * day, the system clock is set back one second; if in leap-delete
@@ -357,14 +388,15 @@ void ntp_clear(void)
357static enum hrtimer_restart ntp_leap_second(struct hrtimer *timer) 388static enum hrtimer_restart ntp_leap_second(struct hrtimer *timer)
358{ 389{
359 enum hrtimer_restart res = HRTIMER_NORESTART; 390 enum hrtimer_restart res = HRTIMER_NORESTART;
391 unsigned long flags;
392 int leap = 0;
360 393
361 write_seqlock(&xtime_lock); 394 spin_lock_irqsave(&ntp_lock, flags);
362
363 switch (time_state) { 395 switch (time_state) {
364 case TIME_OK: 396 case TIME_OK:
365 break; 397 break;
366 case TIME_INS: 398 case TIME_INS:
367 timekeeping_leap_insert(-1); 399 leap = -1;
368 time_state = TIME_OOP; 400 time_state = TIME_OOP;
369 printk(KERN_NOTICE 401 printk(KERN_NOTICE
370 "Clock: inserting leap second 23:59:60 UTC\n"); 402 "Clock: inserting leap second 23:59:60 UTC\n");
@@ -372,7 +404,7 @@ static enum hrtimer_restart ntp_leap_second(struct hrtimer *timer)
372 res = HRTIMER_RESTART; 404 res = HRTIMER_RESTART;
373 break; 405 break;
374 case TIME_DEL: 406 case TIME_DEL:
375 timekeeping_leap_insert(1); 407 leap = 1;
376 time_tai--; 408 time_tai--;
377 time_state = TIME_WAIT; 409 time_state = TIME_WAIT;
378 printk(KERN_NOTICE 410 printk(KERN_NOTICE
@@ -387,8 +419,14 @@ static enum hrtimer_restart ntp_leap_second(struct hrtimer *timer)
387 time_state = TIME_OK; 419 time_state = TIME_OK;
388 break; 420 break;
389 } 421 }
422 spin_unlock_irqrestore(&ntp_lock, flags);
390 423
391 write_sequnlock(&xtime_lock); 424 /*
425 * We have to call this outside of the ntp_lock to keep
426 * the proper locking hierarchy
427 */
428 if (leap)
429 timekeeping_leap_insert(leap);
392 430
393 return res; 431 return res;
394} 432}
@@ -404,6 +442,9 @@ static enum hrtimer_restart ntp_leap_second(struct hrtimer *timer)
404void second_overflow(void) 442void second_overflow(void)
405{ 443{
406 s64 delta; 444 s64 delta;
445 unsigned long flags;
446
447 spin_lock_irqsave(&ntp_lock, flags);
407 448
408 /* Bump the maxerror field */ 449 /* Bump the maxerror field */
409 time_maxerror += MAXFREQ / NSEC_PER_USEC; 450 time_maxerror += MAXFREQ / NSEC_PER_USEC;
@@ -423,23 +464,25 @@ void second_overflow(void)
423 pps_dec_valid(); 464 pps_dec_valid();
424 465
425 if (!time_adjust) 466 if (!time_adjust)
426 return; 467 goto out;
427 468
428 if (time_adjust > MAX_TICKADJ) { 469 if (time_adjust > MAX_TICKADJ) {
429 time_adjust -= MAX_TICKADJ; 470 time_adjust -= MAX_TICKADJ;
430 tick_length += MAX_TICKADJ_SCALED; 471 tick_length += MAX_TICKADJ_SCALED;
431 return; 472 goto out;
432 } 473 }
433 474
434 if (time_adjust < -MAX_TICKADJ) { 475 if (time_adjust < -MAX_TICKADJ) {
435 time_adjust += MAX_TICKADJ; 476 time_adjust += MAX_TICKADJ;
436 tick_length -= MAX_TICKADJ_SCALED; 477 tick_length -= MAX_TICKADJ_SCALED;
437 return; 478 goto out;
438 } 479 }
439 480
440 tick_length += (s64)(time_adjust * NSEC_PER_USEC / NTP_INTERVAL_FREQ) 481 tick_length += (s64)(time_adjust * NSEC_PER_USEC / NTP_INTERVAL_FREQ)
441 << NTP_SCALE_SHIFT; 482 << NTP_SCALE_SHIFT;
442 time_adjust = 0; 483 time_adjust = 0;
484out:
485 spin_unlock_irqrestore(&ntp_lock, flags);
443} 486}
444 487
445#ifdef CONFIG_GENERIC_CMOS_UPDATE 488#ifdef CONFIG_GENERIC_CMOS_UPDATE
@@ -663,7 +706,7 @@ int do_adjtimex(struct timex *txc)
663 706
664 getnstimeofday(&ts); 707 getnstimeofday(&ts);
665 708
666 write_seqlock_irq(&xtime_lock); 709 spin_lock_irq(&ntp_lock);
667 710
668 if (txc->modes & ADJ_ADJTIME) { 711 if (txc->modes & ADJ_ADJTIME) {
669 long save_adjust = time_adjust; 712 long save_adjust = time_adjust;
@@ -705,7 +748,7 @@ int do_adjtimex(struct timex *txc)
705 /* fill PPS status fields */ 748 /* fill PPS status fields */
706 pps_fill_timex(txc); 749 pps_fill_timex(txc);
707 750
708 write_sequnlock_irq(&xtime_lock); 751 spin_unlock_irq(&ntp_lock);
709 752
710 txc->time.tv_sec = ts.tv_sec; 753 txc->time.tv_sec = ts.tv_sec;
711 txc->time.tv_usec = ts.tv_nsec; 754 txc->time.tv_usec = ts.tv_nsec;
@@ -903,7 +946,7 @@ void hardpps(const struct timespec *phase_ts, const struct timespec *raw_ts)
903 946
904 pts_norm = pps_normalize_ts(*phase_ts); 947 pts_norm = pps_normalize_ts(*phase_ts);
905 948
906 write_seqlock_irqsave(&xtime_lock, flags); 949 spin_lock_irqsave(&ntp_lock, flags);
907 950
908 /* clear the error bits, they will be set again if needed */ 951 /* clear the error bits, they will be set again if needed */
909 time_status &= ~(STA_PPSJITTER | STA_PPSWANDER | STA_PPSERROR); 952 time_status &= ~(STA_PPSJITTER | STA_PPSWANDER | STA_PPSERROR);
@@ -916,7 +959,7 @@ void hardpps(const struct timespec *phase_ts, const struct timespec *raw_ts)
916 * just start the frequency interval */ 959 * just start the frequency interval */
917 if (unlikely(pps_fbase.tv_sec == 0)) { 960 if (unlikely(pps_fbase.tv_sec == 0)) {
918 pps_fbase = *raw_ts; 961 pps_fbase = *raw_ts;
919 write_sequnlock_irqrestore(&xtime_lock, flags); 962 spin_unlock_irqrestore(&ntp_lock, flags);
920 return; 963 return;
921 } 964 }
922 965
@@ -931,7 +974,7 @@ void hardpps(const struct timespec *phase_ts, const struct timespec *raw_ts)
931 time_status |= STA_PPSJITTER; 974 time_status |= STA_PPSJITTER;
932 /* restart the frequency calibration interval */ 975 /* restart the frequency calibration interval */
933 pps_fbase = *raw_ts; 976 pps_fbase = *raw_ts;
934 write_sequnlock_irqrestore(&xtime_lock, flags); 977 spin_unlock_irqrestore(&ntp_lock, flags);
935 pr_err("hardpps: PPSJITTER: bad pulse\n"); 978 pr_err("hardpps: PPSJITTER: bad pulse\n");
936 return; 979 return;
937 } 980 }
@@ -948,7 +991,7 @@ void hardpps(const struct timespec *phase_ts, const struct timespec *raw_ts)
948 991
949 hardpps_update_phase(pts_norm.nsec); 992 hardpps_update_phase(pts_norm.nsec);
950 993
951 write_sequnlock_irqrestore(&xtime_lock, flags); 994 spin_unlock_irqrestore(&ntp_lock, flags);
952} 995}
953EXPORT_SYMBOL(hardpps); 996EXPORT_SYMBOL(hardpps);
954 997
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index 0c6358186401..403c2a092830 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -25,6 +25,8 @@
25struct timekeeper { 25struct timekeeper {
26 /* Current clocksource used for timekeeping. */ 26 /* Current clocksource used for timekeeping. */
27 struct clocksource *clock; 27 struct clocksource *clock;
28 /* NTP adjusted clock multiplier */
29 u32 mult;
28 /* The shift value of the current clocksource. */ 30 /* The shift value of the current clocksource. */
29 int shift; 31 int shift;
30 32
@@ -45,12 +47,47 @@ struct timekeeper {
45 /* Shift conversion between clock shifted nano seconds and 47 /* Shift conversion between clock shifted nano seconds and
46 * ntp shifted nano seconds. */ 48 * ntp shifted nano seconds. */
47 int ntp_error_shift; 49 int ntp_error_shift;
48 /* NTP adjusted clock multiplier */ 50
49 u32 mult; 51 /* The current time */
52 struct timespec xtime;
53 /*
54 * wall_to_monotonic is what we need to add to xtime (or xtime corrected
55 * for sub jiffie times) to get to monotonic time. Monotonic is pegged
56 * at zero at system boot time, so wall_to_monotonic will be negative,
57 * however, we will ALWAYS keep the tv_nsec part positive so we can use
58 * the usual normalization.
59 *
60 * wall_to_monotonic is moved after resume from suspend for the
61 * monotonic time not to jump. We need to add total_sleep_time to
62 * wall_to_monotonic to get the real boot based time offset.
63 *
64 * - wall_to_monotonic is no longer the boot time, getboottime must be
65 * used instead.
66 */
67 struct timespec wall_to_monotonic;
68 /* time spent in suspend */
69 struct timespec total_sleep_time;
70 /* The raw monotonic time for the CLOCK_MONOTONIC_RAW posix clock. */
71 struct timespec raw_time;
72
73 /* Seqlock for all timekeeper values */
74 seqlock_t lock;
50}; 75};
51 76
52static struct timekeeper timekeeper; 77static struct timekeeper timekeeper;
53 78
79/*
80 * This read-write spinlock protects us from races in SMP while
81 * playing with xtime.
82 */
83__cacheline_aligned_in_smp DEFINE_SEQLOCK(xtime_lock);
84
85
86/* flag for if timekeeping is suspended */
87int __read_mostly timekeeping_suspended;
88
89
90
54/** 91/**
55 * timekeeper_setup_internals - Set up internals to use clocksource clock. 92 * timekeeper_setup_internals - Set up internals to use clocksource clock.
56 * 93 *
@@ -135,47 +172,28 @@ static inline s64 timekeeping_get_ns_raw(void)
135 return clocksource_cyc2ns(cycle_delta, clock->mult, clock->shift); 172 return clocksource_cyc2ns(cycle_delta, clock->mult, clock->shift);
136} 173}
137 174
138/* 175/* must hold write on timekeeper.lock */
139 * This read-write spinlock protects us from races in SMP while 176static void timekeeping_update(bool clearntp)
140 * playing with xtime. 177{
141 */ 178 if (clearntp) {
142__cacheline_aligned_in_smp DEFINE_SEQLOCK(xtime_lock); 179 timekeeper.ntp_error = 0;
143 180 ntp_clear();
144 181 }
145/* 182 update_vsyscall(&timekeeper.xtime, &timekeeper.wall_to_monotonic,
146 * The current time 183 timekeeper.clock, timekeeper.mult);
147 * wall_to_monotonic is what we need to add to xtime (or xtime corrected 184}
148 * for sub jiffie times) to get to monotonic time. Monotonic is pegged
149 * at zero at system boot time, so wall_to_monotonic will be negative,
150 * however, we will ALWAYS keep the tv_nsec part positive so we can use
151 * the usual normalization.
152 *
153 * wall_to_monotonic is moved after resume from suspend for the monotonic
154 * time not to jump. We need to add total_sleep_time to wall_to_monotonic
155 * to get the real boot based time offset.
156 *
157 * - wall_to_monotonic is no longer the boot time, getboottime must be
158 * used instead.
159 */
160static struct timespec xtime __attribute__ ((aligned (16)));
161static struct timespec wall_to_monotonic __attribute__ ((aligned (16)));
162static struct timespec total_sleep_time;
163
164/*
165 * The raw monotonic time for the CLOCK_MONOTONIC_RAW posix clock.
166 */
167static struct timespec raw_time;
168 185
169/* flag for if timekeeping is suspended */
170int __read_mostly timekeeping_suspended;
171 186
172/* must hold xtime_lock */
173void timekeeping_leap_insert(int leapsecond) 187void timekeeping_leap_insert(int leapsecond)
174{ 188{
175 xtime.tv_sec += leapsecond; 189 unsigned long flags;
176 wall_to_monotonic.tv_sec -= leapsecond; 190
177 update_vsyscall(&xtime, &wall_to_monotonic, timekeeper.clock, 191 write_seqlock_irqsave(&timekeeper.lock, flags);
178 timekeeper.mult); 192 timekeeper.xtime.tv_sec += leapsecond;
193 timekeeper.wall_to_monotonic.tv_sec -= leapsecond;
194 timekeeping_update(false);
195 write_sequnlock_irqrestore(&timekeeper.lock, flags);
196
179} 197}
180 198
181/** 199/**
@@ -202,10 +220,10 @@ static void timekeeping_forward_now(void)
202 /* If arch requires, add in gettimeoffset() */ 220 /* If arch requires, add in gettimeoffset() */
203 nsec += arch_gettimeoffset(); 221 nsec += arch_gettimeoffset();
204 222
205 timespec_add_ns(&xtime, nsec); 223 timespec_add_ns(&timekeeper.xtime, nsec);
206 224
207 nsec = clocksource_cyc2ns(cycle_delta, clock->mult, clock->shift); 225 nsec = clocksource_cyc2ns(cycle_delta, clock->mult, clock->shift);
208 timespec_add_ns(&raw_time, nsec); 226 timespec_add_ns(&timekeeper.raw_time, nsec);
209} 227}
210 228
211/** 229/**
@@ -222,15 +240,15 @@ void getnstimeofday(struct timespec *ts)
222 WARN_ON(timekeeping_suspended); 240 WARN_ON(timekeeping_suspended);
223 241
224 do { 242 do {
225 seq = read_seqbegin(&xtime_lock); 243 seq = read_seqbegin(&timekeeper.lock);
226 244
227 *ts = xtime; 245 *ts = timekeeper.xtime;
228 nsecs = timekeeping_get_ns(); 246 nsecs = timekeeping_get_ns();
229 247
230 /* If arch requires, add in gettimeoffset() */ 248 /* If arch requires, add in gettimeoffset() */
231 nsecs += arch_gettimeoffset(); 249 nsecs += arch_gettimeoffset();
232 250
233 } while (read_seqretry(&xtime_lock, seq)); 251 } while (read_seqretry(&timekeeper.lock, seq));
234 252
235 timespec_add_ns(ts, nsecs); 253 timespec_add_ns(ts, nsecs);
236} 254}
@@ -245,14 +263,16 @@ ktime_t ktime_get(void)
245 WARN_ON(timekeeping_suspended); 263 WARN_ON(timekeeping_suspended);
246 264
247 do { 265 do {
248 seq = read_seqbegin(&xtime_lock); 266 seq = read_seqbegin(&timekeeper.lock);
249 secs = xtime.tv_sec + wall_to_monotonic.tv_sec; 267 secs = timekeeper.xtime.tv_sec +
250 nsecs = xtime.tv_nsec + wall_to_monotonic.tv_nsec; 268 timekeeper.wall_to_monotonic.tv_sec;
269 nsecs = timekeeper.xtime.tv_nsec +
270 timekeeper.wall_to_monotonic.tv_nsec;
251 nsecs += timekeeping_get_ns(); 271 nsecs += timekeeping_get_ns();
252 /* If arch requires, add in gettimeoffset() */ 272 /* If arch requires, add in gettimeoffset() */
253 nsecs += arch_gettimeoffset(); 273 nsecs += arch_gettimeoffset();
254 274
255 } while (read_seqretry(&xtime_lock, seq)); 275 } while (read_seqretry(&timekeeper.lock, seq));
256 /* 276 /*
257 * Use ktime_set/ktime_add_ns to create a proper ktime on 277 * Use ktime_set/ktime_add_ns to create a proper ktime on
258 * 32-bit architectures without CONFIG_KTIME_SCALAR. 278 * 32-bit architectures without CONFIG_KTIME_SCALAR.
@@ -278,14 +298,14 @@ void ktime_get_ts(struct timespec *ts)
278 WARN_ON(timekeeping_suspended); 298 WARN_ON(timekeeping_suspended);
279 299
280 do { 300 do {
281 seq = read_seqbegin(&xtime_lock); 301 seq = read_seqbegin(&timekeeper.lock);
282 *ts = xtime; 302 *ts = timekeeper.xtime;
283 tomono = wall_to_monotonic; 303 tomono = timekeeper.wall_to_monotonic;
284 nsecs = timekeeping_get_ns(); 304 nsecs = timekeeping_get_ns();
285 /* If arch requires, add in gettimeoffset() */ 305 /* If arch requires, add in gettimeoffset() */
286 nsecs += arch_gettimeoffset(); 306 nsecs += arch_gettimeoffset();
287 307
288 } while (read_seqretry(&xtime_lock, seq)); 308 } while (read_seqretry(&timekeeper.lock, seq));
289 309
290 set_normalized_timespec(ts, ts->tv_sec + tomono.tv_sec, 310 set_normalized_timespec(ts, ts->tv_sec + tomono.tv_sec,
291 ts->tv_nsec + tomono.tv_nsec + nsecs); 311 ts->tv_nsec + tomono.tv_nsec + nsecs);
@@ -313,10 +333,10 @@ void getnstime_raw_and_real(struct timespec *ts_raw, struct timespec *ts_real)
313 do { 333 do {
314 u32 arch_offset; 334 u32 arch_offset;
315 335
316 seq = read_seqbegin(&xtime_lock); 336 seq = read_seqbegin(&timekeeper.lock);
317 337
318 *ts_raw = raw_time; 338 *ts_raw = timekeeper.raw_time;
319 *ts_real = xtime; 339 *ts_real = timekeeper.xtime;
320 340
321 nsecs_raw = timekeeping_get_ns_raw(); 341 nsecs_raw = timekeeping_get_ns_raw();
322 nsecs_real = timekeeping_get_ns(); 342 nsecs_real = timekeeping_get_ns();
@@ -326,7 +346,7 @@ void getnstime_raw_and_real(struct timespec *ts_raw, struct timespec *ts_real)
326 nsecs_raw += arch_offset; 346 nsecs_raw += arch_offset;
327 nsecs_real += arch_offset; 347 nsecs_real += arch_offset;
328 348
329 } while (read_seqretry(&xtime_lock, seq)); 349 } while (read_seqretry(&timekeeper.lock, seq));
330 350
331 timespec_add_ns(ts_raw, nsecs_raw); 351 timespec_add_ns(ts_raw, nsecs_raw);
332 timespec_add_ns(ts_real, nsecs_real); 352 timespec_add_ns(ts_real, nsecs_real);
@@ -365,23 +385,19 @@ int do_settimeofday(const struct timespec *tv)
365 if ((unsigned long)tv->tv_nsec >= NSEC_PER_SEC) 385 if ((unsigned long)tv->tv_nsec >= NSEC_PER_SEC)
366 return -EINVAL; 386 return -EINVAL;
367 387
368 write_seqlock_irqsave(&xtime_lock, flags); 388 write_seqlock_irqsave(&timekeeper.lock, flags);
369 389
370 timekeeping_forward_now(); 390 timekeeping_forward_now();
371 391
372 ts_delta.tv_sec = tv->tv_sec - xtime.tv_sec; 392 ts_delta.tv_sec = tv->tv_sec - timekeeper.xtime.tv_sec;
373 ts_delta.tv_nsec = tv->tv_nsec - xtime.tv_nsec; 393 ts_delta.tv_nsec = tv->tv_nsec - timekeeper.xtime.tv_nsec;
374 wall_to_monotonic = timespec_sub(wall_to_monotonic, ts_delta); 394 timekeeper.wall_to_monotonic =
375 395 timespec_sub(timekeeper.wall_to_monotonic, ts_delta);
376 xtime = *tv;
377 396
378 timekeeper.ntp_error = 0; 397 timekeeper.xtime = *tv;
379 ntp_clear(); 398 timekeeping_update(true);
380
381 update_vsyscall(&xtime, &wall_to_monotonic, timekeeper.clock,
382 timekeeper.mult);
383 399
384 write_sequnlock_irqrestore(&xtime_lock, flags); 400 write_sequnlock_irqrestore(&timekeeper.lock, flags);
385 401
386 /* signal hrtimers about time change */ 402 /* signal hrtimers about time change */
387 clock_was_set(); 403 clock_was_set();
@@ -405,20 +421,17 @@ int timekeeping_inject_offset(struct timespec *ts)
405 if ((unsigned long)ts->tv_nsec >= NSEC_PER_SEC) 421 if ((unsigned long)ts->tv_nsec >= NSEC_PER_SEC)
406 return -EINVAL; 422 return -EINVAL;
407 423
408 write_seqlock_irqsave(&xtime_lock, flags); 424 write_seqlock_irqsave(&timekeeper.lock, flags);
409 425
410 timekeeping_forward_now(); 426 timekeeping_forward_now();
411 427
412 xtime = timespec_add(xtime, *ts); 428 timekeeper.xtime = timespec_add(timekeeper.xtime, *ts);
413 wall_to_monotonic = timespec_sub(wall_to_monotonic, *ts); 429 timekeeper.wall_to_monotonic =
414 430 timespec_sub(timekeeper.wall_to_monotonic, *ts);
415 timekeeper.ntp_error = 0;
416 ntp_clear();
417 431
418 update_vsyscall(&xtime, &wall_to_monotonic, timekeeper.clock, 432 timekeeping_update(true);
419 timekeeper.mult);
420 433
421 write_sequnlock_irqrestore(&xtime_lock, flags); 434 write_sequnlock_irqrestore(&timekeeper.lock, flags);
422 435
423 /* signal hrtimers about time change */ 436 /* signal hrtimers about time change */
424 clock_was_set(); 437 clock_was_set();
@@ -490,11 +503,11 @@ void getrawmonotonic(struct timespec *ts)
490 s64 nsecs; 503 s64 nsecs;
491 504
492 do { 505 do {
493 seq = read_seqbegin(&xtime_lock); 506 seq = read_seqbegin(&timekeeper.lock);
494 nsecs = timekeeping_get_ns_raw(); 507 nsecs = timekeeping_get_ns_raw();
495 *ts = raw_time; 508 *ts = timekeeper.raw_time;
496 509
497 } while (read_seqretry(&xtime_lock, seq)); 510 } while (read_seqretry(&timekeeper.lock, seq));
498 511
499 timespec_add_ns(ts, nsecs); 512 timespec_add_ns(ts, nsecs);
500} 513}
@@ -510,24 +523,30 @@ int timekeeping_valid_for_hres(void)
510 int ret; 523 int ret;
511 524
512 do { 525 do {
513 seq = read_seqbegin(&xtime_lock); 526 seq = read_seqbegin(&timekeeper.lock);
514 527
515 ret = timekeeper.clock->flags & CLOCK_SOURCE_VALID_FOR_HRES; 528 ret = timekeeper.clock->flags & CLOCK_SOURCE_VALID_FOR_HRES;
516 529
517 } while (read_seqretry(&xtime_lock, seq)); 530 } while (read_seqretry(&timekeeper.lock, seq));
518 531
519 return ret; 532 return ret;
520} 533}
521 534
522/** 535/**
523 * timekeeping_max_deferment - Returns max time the clocksource can be deferred 536 * timekeeping_max_deferment - Returns max time the clocksource can be deferred
524 *
525 * Caller must observe xtime_lock via read_seqbegin/read_seqretry to
526 * ensure that the clocksource does not change!
527 */ 537 */
528u64 timekeeping_max_deferment(void) 538u64 timekeeping_max_deferment(void)
529{ 539{
530 return timekeeper.clock->max_idle_ns; 540 unsigned long seq;
541 u64 ret;
542 do {
543 seq = read_seqbegin(&timekeeper.lock);
544
545 ret = timekeeper.clock->max_idle_ns;
546
547 } while (read_seqretry(&timekeeper.lock, seq));
548
549 return ret;
531} 550}
532 551
533/** 552/**
@@ -572,28 +591,29 @@ void __init timekeeping_init(void)
572 read_persistent_clock(&now); 591 read_persistent_clock(&now);
573 read_boot_clock(&boot); 592 read_boot_clock(&boot);
574 593
575 write_seqlock_irqsave(&xtime_lock, flags); 594 seqlock_init(&timekeeper.lock);
576 595
577 ntp_init(); 596 ntp_init();
578 597
598 write_seqlock_irqsave(&timekeeper.lock, flags);
579 clock = clocksource_default_clock(); 599 clock = clocksource_default_clock();
580 if (clock->enable) 600 if (clock->enable)
581 clock->enable(clock); 601 clock->enable(clock);
582 timekeeper_setup_internals(clock); 602 timekeeper_setup_internals(clock);
583 603
584 xtime.tv_sec = now.tv_sec; 604 timekeeper.xtime.tv_sec = now.tv_sec;
585 xtime.tv_nsec = now.tv_nsec; 605 timekeeper.xtime.tv_nsec = now.tv_nsec;
586 raw_time.tv_sec = 0; 606 timekeeper.raw_time.tv_sec = 0;
587 raw_time.tv_nsec = 0; 607 timekeeper.raw_time.tv_nsec = 0;
588 if (boot.tv_sec == 0 && boot.tv_nsec == 0) { 608 if (boot.tv_sec == 0 && boot.tv_nsec == 0) {
589 boot.tv_sec = xtime.tv_sec; 609 boot.tv_sec = timekeeper.xtime.tv_sec;
590 boot.tv_nsec = xtime.tv_nsec; 610 boot.tv_nsec = timekeeper.xtime.tv_nsec;
591 } 611 }
592 set_normalized_timespec(&wall_to_monotonic, 612 set_normalized_timespec(&timekeeper.wall_to_monotonic,
593 -boot.tv_sec, -boot.tv_nsec); 613 -boot.tv_sec, -boot.tv_nsec);
594 total_sleep_time.tv_sec = 0; 614 timekeeper.total_sleep_time.tv_sec = 0;
595 total_sleep_time.tv_nsec = 0; 615 timekeeper.total_sleep_time.tv_nsec = 0;
596 write_sequnlock_irqrestore(&xtime_lock, flags); 616 write_sequnlock_irqrestore(&timekeeper.lock, flags);
597} 617}
598 618
599/* time in seconds when suspend began */ 619/* time in seconds when suspend began */
@@ -614,9 +634,11 @@ static void __timekeeping_inject_sleeptime(struct timespec *delta)
614 return; 634 return;
615 } 635 }
616 636
617 xtime = timespec_add(xtime, *delta); 637 timekeeper.xtime = timespec_add(timekeeper.xtime, *delta);
618 wall_to_monotonic = timespec_sub(wall_to_monotonic, *delta); 638 timekeeper.wall_to_monotonic =
619 total_sleep_time = timespec_add(total_sleep_time, *delta); 639 timespec_sub(timekeeper.wall_to_monotonic, *delta);
640 timekeeper.total_sleep_time = timespec_add(
641 timekeeper.total_sleep_time, *delta);
620} 642}
621 643
622 644
@@ -640,17 +662,15 @@ void timekeeping_inject_sleeptime(struct timespec *delta)
640 if (!(ts.tv_sec == 0 && ts.tv_nsec == 0)) 662 if (!(ts.tv_sec == 0 && ts.tv_nsec == 0))
641 return; 663 return;
642 664
643 write_seqlock_irqsave(&xtime_lock, flags); 665 write_seqlock_irqsave(&timekeeper.lock, flags);
666
644 timekeeping_forward_now(); 667 timekeeping_forward_now();
645 668
646 __timekeeping_inject_sleeptime(delta); 669 __timekeeping_inject_sleeptime(delta);
647 670
648 timekeeper.ntp_error = 0; 671 timekeeping_update(true);
649 ntp_clear();
650 update_vsyscall(&xtime, &wall_to_monotonic, timekeeper.clock,
651 timekeeper.mult);
652 672
653 write_sequnlock_irqrestore(&xtime_lock, flags); 673 write_sequnlock_irqrestore(&timekeeper.lock, flags);
654 674
655 /* signal hrtimers about time change */ 675 /* signal hrtimers about time change */
656 clock_was_set(); 676 clock_was_set();
@@ -673,7 +693,7 @@ static void timekeeping_resume(void)
673 693
674 clocksource_resume(); 694 clocksource_resume();
675 695
676 write_seqlock_irqsave(&xtime_lock, flags); 696 write_seqlock_irqsave(&timekeeper.lock, flags);
677 697
678 if (timespec_compare(&ts, &timekeeping_suspend_time) > 0) { 698 if (timespec_compare(&ts, &timekeeping_suspend_time) > 0) {
679 ts = timespec_sub(ts, timekeeping_suspend_time); 699 ts = timespec_sub(ts, timekeeping_suspend_time);
@@ -683,7 +703,7 @@ static void timekeeping_resume(void)
683 timekeeper.clock->cycle_last = timekeeper.clock->read(timekeeper.clock); 703 timekeeper.clock->cycle_last = timekeeper.clock->read(timekeeper.clock);
684 timekeeper.ntp_error = 0; 704 timekeeper.ntp_error = 0;
685 timekeeping_suspended = 0; 705 timekeeping_suspended = 0;
686 write_sequnlock_irqrestore(&xtime_lock, flags); 706 write_sequnlock_irqrestore(&timekeeper.lock, flags);
687 707
688 touch_softlockup_watchdog(); 708 touch_softlockup_watchdog();
689 709
@@ -701,7 +721,7 @@ static int timekeeping_suspend(void)
701 721
702 read_persistent_clock(&timekeeping_suspend_time); 722 read_persistent_clock(&timekeeping_suspend_time);
703 723
704 write_seqlock_irqsave(&xtime_lock, flags); 724 write_seqlock_irqsave(&timekeeper.lock, flags);
705 timekeeping_forward_now(); 725 timekeeping_forward_now();
706 timekeeping_suspended = 1; 726 timekeeping_suspended = 1;
707 727
@@ -711,7 +731,7 @@ static int timekeeping_suspend(void)
711 * try to compensate so the difference in system time 731 * try to compensate so the difference in system time
712 * and persistent_clock time stays close to constant. 732 * and persistent_clock time stays close to constant.
713 */ 733 */
714 delta = timespec_sub(xtime, timekeeping_suspend_time); 734 delta = timespec_sub(timekeeper.xtime, timekeeping_suspend_time);
715 delta_delta = timespec_sub(delta, old_delta); 735 delta_delta = timespec_sub(delta, old_delta);
716 if (abs(delta_delta.tv_sec) >= 2) { 736 if (abs(delta_delta.tv_sec) >= 2) {
717 /* 737 /*
@@ -724,7 +744,7 @@ static int timekeeping_suspend(void)
724 timekeeping_suspend_time = 744 timekeeping_suspend_time =
725 timespec_add(timekeeping_suspend_time, delta_delta); 745 timespec_add(timekeeping_suspend_time, delta_delta);
726 } 746 }
727 write_sequnlock_irqrestore(&xtime_lock, flags); 747 write_sequnlock_irqrestore(&timekeeper.lock, flags);
728 748
729 clockevents_notify(CLOCK_EVT_NOTIFY_SUSPEND, NULL); 749 clockevents_notify(CLOCK_EVT_NOTIFY_SUSPEND, NULL);
730 clocksource_suspend(); 750 clocksource_suspend();
@@ -775,7 +795,7 @@ static __always_inline int timekeeping_bigadjust(s64 error, s64 *interval,
775 * Now calculate the error in (1 << look_ahead) ticks, but first 795 * Now calculate the error in (1 << look_ahead) ticks, but first
776 * remove the single look ahead already included in the error. 796 * remove the single look ahead already included in the error.
777 */ 797 */
778 tick_error = tick_length >> (timekeeper.ntp_error_shift + 1); 798 tick_error = ntp_tick_length() >> (timekeeper.ntp_error_shift + 1);
779 tick_error -= timekeeper.xtime_interval >> 1; 799 tick_error -= timekeeper.xtime_interval >> 1;
780 error = ((error - tick_error) >> look_ahead) + tick_error; 800 error = ((error - tick_error) >> look_ahead) + tick_error;
781 801
@@ -943,22 +963,22 @@ static cycle_t logarithmic_accumulation(cycle_t offset, int shift)
943 timekeeper.xtime_nsec += timekeeper.xtime_interval << shift; 963 timekeeper.xtime_nsec += timekeeper.xtime_interval << shift;
944 while (timekeeper.xtime_nsec >= nsecps) { 964 while (timekeeper.xtime_nsec >= nsecps) {
945 timekeeper.xtime_nsec -= nsecps; 965 timekeeper.xtime_nsec -= nsecps;
946 xtime.tv_sec++; 966 timekeeper.xtime.tv_sec++;
947 second_overflow(); 967 second_overflow();
948 } 968 }
949 969
950 /* Accumulate raw time */ 970 /* Accumulate raw time */
951 raw_nsecs = timekeeper.raw_interval << shift; 971 raw_nsecs = timekeeper.raw_interval << shift;
952 raw_nsecs += raw_time.tv_nsec; 972 raw_nsecs += timekeeper.raw_time.tv_nsec;
953 if (raw_nsecs >= NSEC_PER_SEC) { 973 if (raw_nsecs >= NSEC_PER_SEC) {
954 u64 raw_secs = raw_nsecs; 974 u64 raw_secs = raw_nsecs;
955 raw_nsecs = do_div(raw_secs, NSEC_PER_SEC); 975 raw_nsecs = do_div(raw_secs, NSEC_PER_SEC);
956 raw_time.tv_sec += raw_secs; 976 timekeeper.raw_time.tv_sec += raw_secs;
957 } 977 }
958 raw_time.tv_nsec = raw_nsecs; 978 timekeeper.raw_time.tv_nsec = raw_nsecs;
959 979
960 /* Accumulate error between NTP and clock interval */ 980 /* Accumulate error between NTP and clock interval */
961 timekeeper.ntp_error += tick_length << shift; 981 timekeeper.ntp_error += ntp_tick_length() << shift;
962 timekeeper.ntp_error -= 982 timekeeper.ntp_error -=
963 (timekeeper.xtime_interval + timekeeper.xtime_remainder) << 983 (timekeeper.xtime_interval + timekeeper.xtime_remainder) <<
964 (timekeeper.ntp_error_shift + shift); 984 (timekeeper.ntp_error_shift + shift);
@@ -970,17 +990,19 @@ static cycle_t logarithmic_accumulation(cycle_t offset, int shift)
970/** 990/**
971 * update_wall_time - Uses the current clocksource to increment the wall time 991 * update_wall_time - Uses the current clocksource to increment the wall time
972 * 992 *
973 * Called from the timer interrupt, must hold a write on xtime_lock.
974 */ 993 */
975static void update_wall_time(void) 994static void update_wall_time(void)
976{ 995{
977 struct clocksource *clock; 996 struct clocksource *clock;
978 cycle_t offset; 997 cycle_t offset;
979 int shift = 0, maxshift; 998 int shift = 0, maxshift;
999 unsigned long flags;
1000
1001 write_seqlock_irqsave(&timekeeper.lock, flags);
980 1002
981 /* Make sure we're fully resumed: */ 1003 /* Make sure we're fully resumed: */
982 if (unlikely(timekeeping_suspended)) 1004 if (unlikely(timekeeping_suspended))
983 return; 1005 goto out;
984 1006
985 clock = timekeeper.clock; 1007 clock = timekeeper.clock;
986 1008
@@ -989,7 +1011,8 @@ static void update_wall_time(void)
989#else 1011#else
990 offset = (clock->read(clock) - clock->cycle_last) & clock->mask; 1012 offset = (clock->read(clock) - clock->cycle_last) & clock->mask;
991#endif 1013#endif
992 timekeeper.xtime_nsec = (s64)xtime.tv_nsec << timekeeper.shift; 1014 timekeeper.xtime_nsec = (s64)timekeeper.xtime.tv_nsec <<
1015 timekeeper.shift;
993 1016
994 /* 1017 /*
995 * With NO_HZ we may have to accumulate many cycle_intervals 1018 * With NO_HZ we may have to accumulate many cycle_intervals
@@ -1002,7 +1025,7 @@ static void update_wall_time(void)
1002 shift = ilog2(offset) - ilog2(timekeeper.cycle_interval); 1025 shift = ilog2(offset) - ilog2(timekeeper.cycle_interval);
1003 shift = max(0, shift); 1026 shift = max(0, shift);
1004 /* Bound shift to one less then what overflows tick_length */ 1027 /* Bound shift to one less then what overflows tick_length */
1005 maxshift = (8*sizeof(tick_length) - (ilog2(tick_length)+1)) - 1; 1028 maxshift = (64 - (ilog2(ntp_tick_length())+1)) - 1;
1006 shift = min(shift, maxshift); 1029 shift = min(shift, maxshift);
1007 while (offset >= timekeeper.cycle_interval) { 1030 while (offset >= timekeeper.cycle_interval) {
1008 offset = logarithmic_accumulation(offset, shift); 1031 offset = logarithmic_accumulation(offset, shift);
@@ -1040,8 +1063,10 @@ static void update_wall_time(void)
1040 * Store full nanoseconds into xtime after rounding it up and 1063 * Store full nanoseconds into xtime after rounding it up and
1041 * add the remainder to the error difference. 1064 * add the remainder to the error difference.
1042 */ 1065 */
1043 xtime.tv_nsec = ((s64) timekeeper.xtime_nsec >> timekeeper.shift) + 1; 1066 timekeeper.xtime.tv_nsec = ((s64)timekeeper.xtime_nsec >>
1044 timekeeper.xtime_nsec -= (s64) xtime.tv_nsec << timekeeper.shift; 1067 timekeeper.shift) + 1;
1068 timekeeper.xtime_nsec -= (s64)timekeeper.xtime.tv_nsec <<
1069 timekeeper.shift;
1045 timekeeper.ntp_error += timekeeper.xtime_nsec << 1070 timekeeper.ntp_error += timekeeper.xtime_nsec <<
1046 timekeeper.ntp_error_shift; 1071 timekeeper.ntp_error_shift;
1047 1072
@@ -1049,15 +1074,17 @@ static void update_wall_time(void)
1049 * Finally, make sure that after the rounding 1074 * Finally, make sure that after the rounding
1050 * xtime.tv_nsec isn't larger then NSEC_PER_SEC 1075 * xtime.tv_nsec isn't larger then NSEC_PER_SEC
1051 */ 1076 */
1052 if (unlikely(xtime.tv_nsec >= NSEC_PER_SEC)) { 1077 if (unlikely(timekeeper.xtime.tv_nsec >= NSEC_PER_SEC)) {
1053 xtime.tv_nsec -= NSEC_PER_SEC; 1078 timekeeper.xtime.tv_nsec -= NSEC_PER_SEC;
1054 xtime.tv_sec++; 1079 timekeeper.xtime.tv_sec++;
1055 second_overflow(); 1080 second_overflow();
1056 } 1081 }
1057 1082
1058 /* check to see if there is a new clocksource to use */ 1083 timekeeping_update(false);
1059 update_vsyscall(&xtime, &wall_to_monotonic, timekeeper.clock, 1084
1060 timekeeper.mult); 1085out:
1086 write_sequnlock_irqrestore(&timekeeper.lock, flags);
1087
1061} 1088}
1062 1089
1063/** 1090/**
@@ -1074,8 +1101,10 @@ static void update_wall_time(void)
1074void getboottime(struct timespec *ts) 1101void getboottime(struct timespec *ts)
1075{ 1102{
1076 struct timespec boottime = { 1103 struct timespec boottime = {
1077 .tv_sec = wall_to_monotonic.tv_sec + total_sleep_time.tv_sec, 1104 .tv_sec = timekeeper.wall_to_monotonic.tv_sec +
1078 .tv_nsec = wall_to_monotonic.tv_nsec + total_sleep_time.tv_nsec 1105 timekeeper.total_sleep_time.tv_sec,
1106 .tv_nsec = timekeeper.wall_to_monotonic.tv_nsec +
1107 timekeeper.total_sleep_time.tv_nsec
1079 }; 1108 };
1080 1109
1081 set_normalized_timespec(ts, -boottime.tv_sec, -boottime.tv_nsec); 1110 set_normalized_timespec(ts, -boottime.tv_sec, -boottime.tv_nsec);
@@ -1101,13 +1130,13 @@ void get_monotonic_boottime(struct timespec *ts)
1101 WARN_ON(timekeeping_suspended); 1130 WARN_ON(timekeeping_suspended);
1102 1131
1103 do { 1132 do {
1104 seq = read_seqbegin(&xtime_lock); 1133 seq = read_seqbegin(&timekeeper.lock);
1105 *ts = xtime; 1134 *ts = timekeeper.xtime;
1106 tomono = wall_to_monotonic; 1135 tomono = timekeeper.wall_to_monotonic;
1107 sleep = total_sleep_time; 1136 sleep = timekeeper.total_sleep_time;
1108 nsecs = timekeeping_get_ns(); 1137 nsecs = timekeeping_get_ns();
1109 1138
1110 } while (read_seqretry(&xtime_lock, seq)); 1139 } while (read_seqretry(&timekeeper.lock, seq));
1111 1140
1112 set_normalized_timespec(ts, ts->tv_sec + tomono.tv_sec + sleep.tv_sec, 1141 set_normalized_timespec(ts, ts->tv_sec + tomono.tv_sec + sleep.tv_sec,
1113 ts->tv_nsec + tomono.tv_nsec + sleep.tv_nsec + nsecs); 1142 ts->tv_nsec + tomono.tv_nsec + sleep.tv_nsec + nsecs);
@@ -1137,19 +1166,19 @@ EXPORT_SYMBOL_GPL(ktime_get_boottime);
1137 */ 1166 */
1138void monotonic_to_bootbased(struct timespec *ts) 1167void monotonic_to_bootbased(struct timespec *ts)
1139{ 1168{
1140 *ts = timespec_add(*ts, total_sleep_time); 1169 *ts = timespec_add(*ts, timekeeper.total_sleep_time);
1141} 1170}
1142EXPORT_SYMBOL_GPL(monotonic_to_bootbased); 1171EXPORT_SYMBOL_GPL(monotonic_to_bootbased);
1143 1172
1144unsigned long get_seconds(void) 1173unsigned long get_seconds(void)
1145{ 1174{
1146 return xtime.tv_sec; 1175 return timekeeper.xtime.tv_sec;
1147} 1176}
1148EXPORT_SYMBOL(get_seconds); 1177EXPORT_SYMBOL(get_seconds);
1149 1178
1150struct timespec __current_kernel_time(void) 1179struct timespec __current_kernel_time(void)
1151{ 1180{
1152 return xtime; 1181 return timekeeper.xtime;
1153} 1182}
1154 1183
1155struct timespec current_kernel_time(void) 1184struct timespec current_kernel_time(void)
@@ -1158,10 +1187,10 @@ struct timespec current_kernel_time(void)
1158 unsigned long seq; 1187 unsigned long seq;
1159 1188
1160 do { 1189 do {
1161 seq = read_seqbegin(&xtime_lock); 1190 seq = read_seqbegin(&timekeeper.lock);
1162 1191
1163 now = xtime; 1192 now = timekeeper.xtime;
1164 } while (read_seqretry(&xtime_lock, seq)); 1193 } while (read_seqretry(&timekeeper.lock, seq));
1165 1194
1166 return now; 1195 return now;
1167} 1196}
@@ -1173,11 +1202,11 @@ struct timespec get_monotonic_coarse(void)
1173 unsigned long seq; 1202 unsigned long seq;
1174 1203
1175 do { 1204 do {
1176 seq = read_seqbegin(&xtime_lock); 1205 seq = read_seqbegin(&timekeeper.lock);
1177 1206
1178 now = xtime; 1207 now = timekeeper.xtime;
1179 mono = wall_to_monotonic; 1208 mono = timekeeper.wall_to_monotonic;
1180 } while (read_seqretry(&xtime_lock, seq)); 1209 } while (read_seqretry(&timekeeper.lock, seq));
1181 1210
1182 set_normalized_timespec(&now, now.tv_sec + mono.tv_sec, 1211 set_normalized_timespec(&now, now.tv_sec + mono.tv_sec,
1183 now.tv_nsec + mono.tv_nsec); 1212 now.tv_nsec + mono.tv_nsec);
@@ -1209,11 +1238,11 @@ void get_xtime_and_monotonic_and_sleep_offset(struct timespec *xtim,
1209 unsigned long seq; 1238 unsigned long seq;
1210 1239
1211 do { 1240 do {
1212 seq = read_seqbegin(&xtime_lock); 1241 seq = read_seqbegin(&timekeeper.lock);
1213 *xtim = xtime; 1242 *xtim = timekeeper.xtime;
1214 *wtom = wall_to_monotonic; 1243 *wtom = timekeeper.wall_to_monotonic;
1215 *sleep = total_sleep_time; 1244 *sleep = timekeeper.total_sleep_time;
1216 } while (read_seqretry(&xtime_lock, seq)); 1245 } while (read_seqretry(&timekeeper.lock, seq));
1217} 1246}
1218 1247
1219/** 1248/**
@@ -1225,9 +1254,10 @@ ktime_t ktime_get_monotonic_offset(void)
1225 struct timespec wtom; 1254 struct timespec wtom;
1226 1255
1227 do { 1256 do {
1228 seq = read_seqbegin(&xtime_lock); 1257 seq = read_seqbegin(&timekeeper.lock);
1229 wtom = wall_to_monotonic; 1258 wtom = timekeeper.wall_to_monotonic;
1230 } while (read_seqretry(&xtime_lock, seq)); 1259 } while (read_seqretry(&timekeeper.lock, seq));
1260
1231 return timespec_to_ktime(wtom); 1261 return timespec_to_ktime(wtom);
1232} 1262}
1233 1263