diff options
| author | Ingo Molnar <mingo@elte.hu> | 2007-07-16 02:41:18 -0400 |
|---|---|---|
| committer | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2007-07-16 12:05:48 -0400 |
| commit | 4e44f3497d41db4c3b9051c61410dee8ae4fb49c (patch) | |
| tree | 8c54919894c8f6ac629c6c28cee8fb504721d652 /kernel | |
| parent | f482394ccbca7234d29cc146d4a2b94f976ce5a1 (diff) | |
sys_time() speedup
Improve performance of sys_time(). sys_time() returns time in seconds, but
it does so by calling do_gettimeofday() and then returning the tv_sec
portion of the GTOD time. But the data structure "xtime", which is updated
by every timer/scheduler tick, already offers HZ granularity time.
The patch improves the sysbench OLTP macrobenchmark significantly:
2.6.22-rc6:
#threads
1: transactions: 3733 (373.21 per sec.)
2: transactions: 6676 (667.46 per sec.)
3: transactions: 6957 (695.50 per sec.)
4: transactions: 7055 (705.48 per sec.)
5: transactions: 6596 (659.33 per sec.)
2.6.22-rc6 + sys_time.patch:
1: transactions: 4005 (400.47 per sec.)
2: transactions: 7379 (737.77 per sec.)
3: transactions: 7347 (734.49 per sec.)
4: transactions: 7468 (746.65 per sec.)
5: transactions: 7428 (742.47 per sec.)
Mixed API uses of gettimeofday() and time() are guaranteed to be coherent
via the use of a at-most-once-per-second slowpath that updates xtime.
[akpm@linux-foundation.org: build fixes]
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Cc: John Stultz <johnstul@us.ibm.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Roman Zippel <zippel@linux-m68k.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'kernel')
| -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 |
