diff options
author | Eric Dumazet <dada1@cosmosbay.com> | 2007-05-08 03:25:32 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2007-05-08 14:15:01 -0400 |
commit | 753e9c5cd9b123156152c66c816f751954b15e53 (patch) | |
tree | fc70e4358be312e11ce0c258ead7b996dbd7d59e | |
parent | 2e17c5508fa015f2c7690e29041f437e9308c64f (diff) |
Optimize timespec_trunc()
The first thing done by timespec_trunc() is :
if (gran <= jiffies_to_usecs(1) * 1000)
This should really be a test against a constant known at compile time.
Alas, it isnt. jiffies_to_usec() was unilined so C compiler emits a function
call and a multiply to compute : a CONSTANT.
mov $0x1,%edi
mov %rbx,0xffffffffffffffe8(%rbp)
mov %r12,0xfffffffffffffff0(%rbp)
mov %edx,%ebx
mov %rsi,0xffffffffffffffc8(%rbp)
mov %rsi,%r12
callq ffffffff80232010 <jiffies_to_usecs>
imul $0x3e8,%eax,%eax
cmp %ebx,%eax
This patch reorders kernel/time.c a bit so that jiffies_to_usecs() is defined
before timespec_trunc() so that compiler now generates :
cmp $0x3d0900,%edx (HZ=250 on my machine)
This gives a better code (timespec_trunc() becoming a leaf function), and
shorter kernel size as well.
Signed-off-by: Eric Dumazet <dada1@cosmosbay.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: john stultz <johnstul@us.ibm.com>
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>
-rw-r--r-- | kernel/time.c | 60 |
1 files changed, 30 insertions, 30 deletions
diff --git a/kernel/time.c b/kernel/time.c index ba18ec4899bd..6d98ab72f38b 100644 --- a/kernel/time.c +++ b/kernel/time.c | |||
@@ -247,6 +247,36 @@ struct timespec current_fs_time(struct super_block *sb) | |||
247 | } | 247 | } |
248 | EXPORT_SYMBOL(current_fs_time); | 248 | EXPORT_SYMBOL(current_fs_time); |
249 | 249 | ||
250 | /* | ||
251 | * Convert jiffies to milliseconds and back. | ||
252 | * | ||
253 | * Avoid unnecessary multiplications/divisions in the | ||
254 | * two most common HZ cases: | ||
255 | */ | ||
256 | unsigned int inline jiffies_to_msecs(const unsigned long j) | ||
257 | { | ||
258 | #if HZ <= MSEC_PER_SEC && !(MSEC_PER_SEC % HZ) | ||
259 | return (MSEC_PER_SEC / HZ) * j; | ||
260 | #elif HZ > MSEC_PER_SEC && !(HZ % MSEC_PER_SEC) | ||
261 | return (j + (HZ / MSEC_PER_SEC) - 1)/(HZ / MSEC_PER_SEC); | ||
262 | #else | ||
263 | return (j * MSEC_PER_SEC) / HZ; | ||
264 | #endif | ||
265 | } | ||
266 | EXPORT_SYMBOL(jiffies_to_msecs); | ||
267 | |||
268 | unsigned int inline jiffies_to_usecs(const unsigned long j) | ||
269 | { | ||
270 | #if HZ <= USEC_PER_SEC && !(USEC_PER_SEC % HZ) | ||
271 | return (USEC_PER_SEC / HZ) * j; | ||
272 | #elif HZ > USEC_PER_SEC && !(HZ % USEC_PER_SEC) | ||
273 | return (j + (HZ / USEC_PER_SEC) - 1)/(HZ / USEC_PER_SEC); | ||
274 | #else | ||
275 | return (j * USEC_PER_SEC) / HZ; | ||
276 | #endif | ||
277 | } | ||
278 | EXPORT_SYMBOL(jiffies_to_usecs); | ||
279 | |||
250 | /** | 280 | /** |
251 | * timespec_trunc - Truncate timespec to a granularity | 281 | * timespec_trunc - Truncate timespec to a granularity |
252 | * @t: Timespec | 282 | * @t: Timespec |
@@ -473,36 +503,6 @@ struct timeval ns_to_timeval(const s64 nsec) | |||
473 | EXPORT_SYMBOL(ns_to_timeval); | 503 | EXPORT_SYMBOL(ns_to_timeval); |
474 | 504 | ||
475 | /* | 505 | /* |
476 | * Convert jiffies to milliseconds and back. | ||
477 | * | ||
478 | * Avoid unnecessary multiplications/divisions in the | ||
479 | * two most common HZ cases: | ||
480 | */ | ||
481 | unsigned int jiffies_to_msecs(const unsigned long j) | ||
482 | { | ||
483 | #if HZ <= MSEC_PER_SEC && !(MSEC_PER_SEC % HZ) | ||
484 | return (MSEC_PER_SEC / HZ) * j; | ||
485 | #elif HZ > MSEC_PER_SEC && !(HZ % MSEC_PER_SEC) | ||
486 | return (j + (HZ / MSEC_PER_SEC) - 1)/(HZ / MSEC_PER_SEC); | ||
487 | #else | ||
488 | return (j * MSEC_PER_SEC) / HZ; | ||
489 | #endif | ||
490 | } | ||
491 | EXPORT_SYMBOL(jiffies_to_msecs); | ||
492 | |||
493 | unsigned int jiffies_to_usecs(const unsigned long j) | ||
494 | { | ||
495 | #if HZ <= USEC_PER_SEC && !(USEC_PER_SEC % HZ) | ||
496 | return (USEC_PER_SEC / HZ) * j; | ||
497 | #elif HZ > USEC_PER_SEC && !(HZ % USEC_PER_SEC) | ||
498 | return (j + (HZ / USEC_PER_SEC) - 1)/(HZ / USEC_PER_SEC); | ||
499 | #else | ||
500 | return (j * USEC_PER_SEC) / HZ; | ||
501 | #endif | ||
502 | } | ||
503 | EXPORT_SYMBOL(jiffies_to_usecs); | ||
504 | |||
505 | /* | ||
506 | * When we convert to jiffies then we interpret incoming values | 506 | * When we convert to jiffies then we interpret incoming values |
507 | * the following way: | 507 | * the following way: |
508 | * | 508 | * |