diff options
Diffstat (limited to 'kernel/time.c')
-rw-r--r-- | kernel/time.c | 32 |
1 files changed, 24 insertions, 8 deletions
diff --git a/kernel/time.c b/kernel/time.c index f04791f69408..ffe19149d770 100644 --- a/kernel/time.c +++ b/kernel/time.c | |||
@@ -57,14 +57,17 @@ EXPORT_SYMBOL(sys_tz); | |||
57 | */ | 57 | */ |
58 | asmlinkage long sys_time(time_t __user * tloc) | 58 | asmlinkage long sys_time(time_t __user * tloc) |
59 | { | 59 | { |
60 | time_t i; | 60 | /* |
61 | struct timeval tv; | 61 | * We read xtime.tv_sec atomically - it's updated |
62 | * atomically by update_wall_time(), so no need to | ||
63 | * even read-lock the xtime seqlock: | ||
64 | */ | ||
65 | time_t i = xtime.tv_sec; | ||
62 | 66 | ||
63 | do_gettimeofday(&tv); | 67 | smp_rmb(); /* sys_time() results are coherent */ |
64 | i = tv.tv_sec; | ||
65 | 68 | ||
66 | if (tloc) { | 69 | if (tloc) { |
67 | if (put_user(i,tloc)) | 70 | if (put_user(i, tloc)) |
68 | i = -EFAULT; | 71 | i = -EFAULT; |
69 | } | 72 | } |
70 | return i; | 73 | return i; |
@@ -373,12 +376,25 @@ void do_gettimeofday (struct timeval *tv) | |||
373 | 376 | ||
374 | tv->tv_sec = sec; | 377 | tv->tv_sec = sec; |
375 | tv->tv_usec = usec; | 378 | tv->tv_usec = usec; |
376 | } | ||
377 | 379 | ||
380 | /* | ||
381 | * Make sure xtime.tv_sec [returned by sys_time()] always | ||
382 | * follows the gettimeofday() result precisely. This | ||
383 | * condition is extremely unlikely, it can hit at most | ||
384 | * once per second: | ||
385 | */ | ||
386 | if (unlikely(xtime.tv_sec != tv->tv_sec)) { | ||
387 | unsigned long flags; | ||
388 | |||
389 | write_seqlock_irqsave(&xtime_lock, flags); | ||
390 | update_wall_time(); | ||
391 | write_sequnlock_irqrestore(&xtime_lock, flags); | ||
392 | } | ||
393 | } | ||
378 | EXPORT_SYMBOL(do_gettimeofday); | 394 | EXPORT_SYMBOL(do_gettimeofday); |
379 | 395 | ||
396 | #else /* CONFIG_TIME_INTERPOLATION */ | ||
380 | 397 | ||
381 | #else | ||
382 | #ifndef CONFIG_GENERIC_TIME | 398 | #ifndef CONFIG_GENERIC_TIME |
383 | /* | 399 | /* |
384 | * Simulate gettimeofday using do_gettimeofday which only allows a timeval | 400 | * Simulate gettimeofday using do_gettimeofday which only allows a timeval |
@@ -394,7 +410,7 @@ void getnstimeofday(struct timespec *tv) | |||
394 | } | 410 | } |
395 | EXPORT_SYMBOL_GPL(getnstimeofday); | 411 | EXPORT_SYMBOL_GPL(getnstimeofday); |
396 | #endif | 412 | #endif |
397 | #endif | 413 | #endif /* CONFIG_TIME_INTERPOLATION */ |
398 | 414 | ||
399 | /* Converts Gregorian date to seconds since 1970-01-01 00:00:00. | 415 | /* Converts Gregorian date to seconds since 1970-01-01 00:00:00. |
400 | * Assumes input in normal date format, i.e. 1980-12-31 23:59:59 | 416 | * Assumes input in normal date format, i.e. 1980-12-31 23:59:59 |