Commit 2c6b47de17c75d553de3e2fb426d8298d2074585
Committed by
Linus Torvalds
1 parent
0de085bb47
Exists in
master
and in
39 other branches
Cleanup non-arch xtime uses, use get_seconds() or current_kernel_time().
This avoids use of the kernel-internal "xtime" variable directly outside of the actual time-related functions. Instead, use the helper functions that we already have available to us. This doesn't actually change any behaviour, but this will allow us to fix the fact that "xtime" isn't updated very often with CONFIG_NO_HZ (because much of the realtime information is maintained as separate offsets to 'xtime'), which has caused interfaces that use xtime directly to get a time that is out of sync with the real-time clock by up to a third of a second or so. Signed-off-by: John Stultz <johnstul@us.ibm.com> Cc: Ingo Molnar <mingo@elte.hu> Cc: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Showing 13 changed files with 34 additions and 33 deletions Side-by-side Diff
drivers/rtc/class.c
... | ... | @@ -46,6 +46,7 @@ |
46 | 46 | { |
47 | 47 | struct rtc_device *rtc = to_rtc_device(dev); |
48 | 48 | struct rtc_time tm; |
49 | + struct timespec ts = current_kernel_time(); | |
49 | 50 | |
50 | 51 | if (strncmp(rtc->dev.bus_id, |
51 | 52 | CONFIG_RTC_HCTOSYS_DEVICE, |
... | ... | @@ -57,8 +58,8 @@ |
57 | 58 | |
58 | 59 | /* RTC precision is 1 second; adjust delta for avg 1/2 sec err */ |
59 | 60 | set_normalized_timespec(&delta, |
60 | - xtime.tv_sec - oldtime, | |
61 | - xtime.tv_nsec - (NSEC_PER_SEC >> 1)); | |
61 | + ts.tv_sec - oldtime, | |
62 | + ts.tv_nsec - (NSEC_PER_SEC >> 1)); | |
62 | 63 | |
63 | 64 | return 0; |
64 | 65 | } |
drivers/s390/net/ctcmain.c
... | ... | @@ -674,7 +674,7 @@ |
674 | 674 | int first = 1; |
675 | 675 | int i; |
676 | 676 | unsigned long duration; |
677 | - struct timespec done_stamp = xtime; | |
677 | + struct timespec done_stamp = current_kernel_time(); | |
678 | 678 | |
679 | 679 | DBF_TEXT(trace, 4, __FUNCTION__); |
680 | 680 | |
... | ... | @@ -730,7 +730,7 @@ |
730 | 730 | spin_unlock(&ch->collect_lock); |
731 | 731 | ch->ccw[1].count = ch->trans_skb->len; |
732 | 732 | fsm_addtimer(&ch->timer, CTC_TIMEOUT_5SEC, CH_EVENT_TIMER, ch); |
733 | - ch->prof.send_stamp = xtime; | |
733 | + ch->prof.send_stamp = current_kernel_time(); | |
734 | 734 | rc = ccw_device_start(ch->cdev, &ch->ccw[0], |
735 | 735 | (unsigned long) ch, 0xff, 0); |
736 | 736 | ch->prof.doios_multi++; |
... | ... | @@ -2281,7 +2281,7 @@ |
2281 | 2281 | fsm_newstate(ch->fsm, CH_STATE_TX); |
2282 | 2282 | fsm_addtimer(&ch->timer, CTC_TIMEOUT_5SEC, CH_EVENT_TIMER, ch); |
2283 | 2283 | spin_lock_irqsave(get_ccwdev_lock(ch->cdev), saveflags); |
2284 | - ch->prof.send_stamp = xtime; | |
2284 | + ch->prof.send_stamp = current_kernel_time(); | |
2285 | 2285 | rc = ccw_device_start(ch->cdev, &ch->ccw[ccw_idx], |
2286 | 2286 | (unsigned long) ch, 0xff, 0); |
2287 | 2287 | spin_unlock_irqrestore(get_ccwdev_lock(ch->cdev), saveflags); |
drivers/s390/net/netiucv.c
... | ... | @@ -753,7 +753,7 @@ |
753 | 753 | |
754 | 754 | header.next = 0; |
755 | 755 | memcpy(skb_put(conn->tx_buff, NETIUCV_HDRLEN), &header, NETIUCV_HDRLEN); |
756 | - conn->prof.send_stamp = xtime; | |
756 | + conn->prof.send_stamp = current_kernel_time(); | |
757 | 757 | txmsg.class = 0; |
758 | 758 | txmsg.tag = 0; |
759 | 759 | rc = iucv_message_send(conn->path, &txmsg, 0, 0, |
... | ... | @@ -1185,7 +1185,7 @@ |
1185 | 1185 | memcpy(skb_put(nskb, NETIUCV_HDRLEN), &header, NETIUCV_HDRLEN); |
1186 | 1186 | |
1187 | 1187 | fsm_newstate(conn->fsm, CONN_STATE_TX); |
1188 | - conn->prof.send_stamp = xtime; | |
1188 | + conn->prof.send_stamp = current_kernel_time(); | |
1189 | 1189 | |
1190 | 1190 | msg.tag = 1; |
1191 | 1191 | msg.class = 0; |
include/linux/time.h
... | ... | @@ -107,7 +107,7 @@ |
107 | 107 | struct timespec current_kernel_time(void); |
108 | 108 | |
109 | 109 | #define CURRENT_TIME (current_kernel_time()) |
110 | -#define CURRENT_TIME_SEC ((struct timespec) { xtime.tv_sec, 0 }) | |
110 | +#define CURRENT_TIME_SEC ((struct timespec) { get_seconds(), 0 }) | |
111 | 111 | |
112 | 112 | extern void do_gettimeofday(struct timeval *tv); |
113 | 113 | extern int do_settimeofday(struct timespec *tv); |
kernel/acct.c
... | ... | @@ -468,7 +468,7 @@ |
468 | 468 | } |
469 | 469 | #endif |
470 | 470 | do_div(elapsed, AHZ); |
471 | - ac.ac_btime = xtime.tv_sec - elapsed; | |
471 | + ac.ac_btime = get_seconds() - elapsed; | |
472 | 472 | /* we really need to bite the bullet and change layout */ |
473 | 473 | ac.ac_uid = current->uid; |
474 | 474 | ac.ac_gid = current->gid; |
kernel/hrtimer.c
kernel/time.c
... | ... | @@ -215,22 +215,6 @@ |
215 | 215 | return copy_to_user(txc_p, &txc, sizeof(struct timex)) ? -EFAULT : ret; |
216 | 216 | } |
217 | 217 | |
218 | -inline struct timespec current_kernel_time(void) | |
219 | -{ | |
220 | - struct timespec now; | |
221 | - unsigned long seq; | |
222 | - | |
223 | - do { | |
224 | - seq = read_seqbegin(&xtime_lock); | |
225 | - | |
226 | - now = xtime; | |
227 | - } while (read_seqretry(&xtime_lock, seq)); | |
228 | - | |
229 | - return now; | |
230 | -} | |
231 | - | |
232 | -EXPORT_SYMBOL(current_kernel_time); | |
233 | - | |
234 | 218 | /** |
235 | 219 | * current_fs_time - Return FS time |
236 | 220 | * @sb: Superblock. |
kernel/time/timekeeping.c
... | ... | @@ -509,4 +509,20 @@ |
509 | 509 | { |
510 | 510 | ts->tv_sec += total_sleep_time; |
511 | 511 | } |
512 | + | |
513 | +struct timespec current_kernel_time(void) | |
514 | +{ | |
515 | + struct timespec now; | |
516 | + unsigned long seq; | |
517 | + | |
518 | + do { | |
519 | + seq = read_seqbegin(&xtime_lock); | |
520 | + | |
521 | + now = xtime; | |
522 | + } while (read_seqretry(&xtime_lock, seq)); | |
523 | + | |
524 | + return now; | |
525 | +} | |
526 | + | |
527 | +EXPORT_SYMBOL(current_kernel_time); |
kernel/tsacct.c
... | ... | @@ -39,7 +39,7 @@ |
39 | 39 | ac_etime = timespec_to_ns(&ts); |
40 | 40 | do_div(ac_etime, NSEC_PER_USEC); |
41 | 41 | stats->ac_etime = ac_etime; |
42 | - stats->ac_btime = xtime.tv_sec - ts.tv_sec; | |
42 | + stats->ac_btime = get_seconds() - ts.tv_sec; | |
43 | 43 | if (thread_group_leader(tsk)) { |
44 | 44 | stats->ac_exitcode = tsk->exit_code; |
45 | 45 | if (tsk->flags & PF_FORKNOEXEC) |
net/rxrpc/af_rxrpc.c
net/rxrpc/ar-connection.c
... | ... | @@ -791,7 +791,7 @@ |
791 | 791 | |
792 | 792 | ASSERTCMP(atomic_read(&conn->usage), >, 0); |
793 | 793 | |
794 | - conn->put_time = xtime.tv_sec; | |
794 | + conn->put_time = get_seconds(); | |
795 | 795 | if (atomic_dec_and_test(&conn->usage)) { |
796 | 796 | _debug("zombie"); |
797 | 797 | rxrpc_queue_delayed_work(&rxrpc_connection_reap, 0); |
... | ... | @@ -835,7 +835,7 @@ |
835 | 835 | |
836 | 836 | _enter(""); |
837 | 837 | |
838 | - now = xtime.tv_sec; | |
838 | + now = get_seconds(); | |
839 | 839 | earliest = ULONG_MAX; |
840 | 840 | |
841 | 841 | write_lock_bh(&rxrpc_connection_lock); |
net/rxrpc/ar-transport.c
... | ... | @@ -183,7 +183,7 @@ |
183 | 183 | |
184 | 184 | ASSERTCMP(atomic_read(&trans->usage), >, 0); |
185 | 185 | |
186 | - trans->put_time = xtime.tv_sec; | |
186 | + trans->put_time = get_seconds(); | |
187 | 187 | if (unlikely(atomic_dec_and_test(&trans->usage))) |
188 | 188 | _debug("zombie"); |
189 | 189 | /* let the reaper determine the timeout to avoid a race with |
... | ... | @@ -219,7 +219,7 @@ |
219 | 219 | |
220 | 220 | _enter(""); |
221 | 221 | |
222 | - now = xtime.tv_sec; | |
222 | + now = get_seconds(); | |
223 | 223 | earliest = ULONG_MAX; |
224 | 224 | |
225 | 225 | /* extract all the transports that have been dead too long */ |