diff options
| author | Nicholas Mc Guire <hofrat@osadl.org> | 2015-05-18 08:19:13 -0400 |
|---|---|---|
| committer | Thomas Gleixner <tglx@linutronix.de> | 2015-05-19 09:13:46 -0400 |
| commit | ca42aaf0c8616cde6161ea4391dff364efeee46a (patch) | |
| tree | d09e7cd821103669ac324650536e5bfb9a14fb7c /kernel/time | |
| parent | 0a227985d4a993a322ff72ecbaeee2611d624216 (diff) | |
time: Refactor msecs_to_jiffies
Refactor the msecs_to_jiffies conditional code part in time.c and
jiffies.h putting it into conditional functions rather than #ifdefs
to improve readability.
[ tglx: Verified that there is no binary code change ]
Signed-off-by: Nicholas Mc Guire <hofrat@osadl.org>
Cc: Masahiro Yamada <yamada.m@jp.panasonic.com>
Cc: Sam Ravnborg <sam@ravnborg.org>
Cc: Joe Perches <joe@perches.com>
Cc: John Stultz <john.stultz@linaro.org>
Cc: Andrew Hunter <ahh@google.com>
Cc: Paul Turner <pjt@google.com>
Cc: Michal Marek <mmarek@suse.cz>
Link: http://lkml.kernel.org/r/1431951554-5563-2-git-send-email-hofrat@osadl.org
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Diffstat (limited to 'kernel/time')
| -rw-r--r-- | kernel/time/time.c | 59 |
1 files changed, 19 insertions, 40 deletions
diff --git a/kernel/time/time.c b/kernel/time/time.c index 4fa1d26a9843..c42c2c3214fe 100644 --- a/kernel/time/time.c +++ b/kernel/time/time.c | |||
| @@ -483,9 +483,11 @@ struct timespec64 ns_to_timespec64(const s64 nsec) | |||
| 483 | } | 483 | } |
| 484 | EXPORT_SYMBOL(ns_to_timespec64); | 484 | EXPORT_SYMBOL(ns_to_timespec64); |
| 485 | #endif | 485 | #endif |
| 486 | /* | 486 | /** |
| 487 | * When we convert to jiffies then we interpret incoming values | 487 | * msecs_to_jiffies: - convert milliseconds to jiffies |
| 488 | * the following way: | 488 | * @m: time in milliseconds |
| 489 | * | ||
| 490 | * conversion is done as follows: | ||
| 489 | * | 491 | * |
| 490 | * - negative values mean 'infinite timeout' (MAX_JIFFY_OFFSET) | 492 | * - negative values mean 'infinite timeout' (MAX_JIFFY_OFFSET) |
| 491 | * | 493 | * |
| @@ -493,51 +495,28 @@ EXPORT_SYMBOL(ns_to_timespec64); | |||
| 493 | * MAX_JIFFY_OFFSET values] mean 'infinite timeout' too. | 495 | * MAX_JIFFY_OFFSET values] mean 'infinite timeout' too. |
| 494 | * | 496 | * |
| 495 | * - all other values are converted to jiffies by either multiplying | 497 | * - all other values are converted to jiffies by either multiplying |
| 496 | * the input value by a factor or dividing it with a factor | 498 | * the input value by a factor or dividing it with a factor and |
| 497 | * | 499 | * handling any 32-bit overflows. |
| 498 | * We must also be careful about 32-bit overflows. | 500 | * for the details see __msecs_to_jiffies() |
| 501 | * | ||
| 502 | * msecs_to_jiffies() checks for the passed in value being a constant | ||
| 503 | * via __builtin_constant_p() allowing gcc to eliminate most of the | ||
| 504 | * code, __msecs_to_jiffies() is called if the value passed does not | ||
| 505 | * allow constant folding and the actual conversion must be done at | ||
| 506 | * runtime. | ||
| 507 | * the _msecs_to_jiffies helpers are the HZ dependent conversion | ||
| 508 | * routines found in include/linux/jiffies.h | ||
| 499 | */ | 509 | */ |
| 500 | unsigned long msecs_to_jiffies(const unsigned int m) | 510 | unsigned long __msecs_to_jiffies(const unsigned int m) |
| 501 | { | 511 | { |
| 502 | /* | 512 | /* |
| 503 | * Negative value, means infinite timeout: | 513 | * Negative value, means infinite timeout: |
| 504 | */ | 514 | */ |
| 505 | if ((int)m < 0) | 515 | if ((int)m < 0) |
| 506 | return MAX_JIFFY_OFFSET; | 516 | return MAX_JIFFY_OFFSET; |
| 507 | 517 | return _msecs_to_jiffies(m); | |
| 508 | #if HZ <= MSEC_PER_SEC && !(MSEC_PER_SEC % HZ) | ||
| 509 | /* | ||
| 510 | * HZ is equal to or smaller than 1000, and 1000 is a nice | ||
| 511 | * round multiple of HZ, divide with the factor between them, | ||
| 512 | * but round upwards: | ||
| 513 | */ | ||
| 514 | return (m + (MSEC_PER_SEC / HZ) - 1) / (MSEC_PER_SEC / HZ); | ||
| 515 | #elif HZ > MSEC_PER_SEC && !(HZ % MSEC_PER_SEC) | ||
| 516 | /* | ||
| 517 | * HZ is larger than 1000, and HZ is a nice round multiple of | ||
| 518 | * 1000 - simply multiply with the factor between them. | ||
| 519 | * | ||
| 520 | * But first make sure the multiplication result cannot | ||
| 521 | * overflow: | ||
| 522 | */ | ||
| 523 | if (m > jiffies_to_msecs(MAX_JIFFY_OFFSET)) | ||
| 524 | return MAX_JIFFY_OFFSET; | ||
| 525 | |||
| 526 | return m * (HZ / MSEC_PER_SEC); | ||
| 527 | #else | ||
| 528 | /* | ||
| 529 | * Generic case - multiply, round and divide. But first | ||
| 530 | * check that if we are doing a net multiplication, that | ||
| 531 | * we wouldn't overflow: | ||
| 532 | */ | ||
| 533 | if (HZ > MSEC_PER_SEC && m > jiffies_to_msecs(MAX_JIFFY_OFFSET)) | ||
| 534 | return MAX_JIFFY_OFFSET; | ||
| 535 | |||
| 536 | return (MSEC_TO_HZ_MUL32 * m + MSEC_TO_HZ_ADJ32) | ||
| 537 | >> MSEC_TO_HZ_SHR32; | ||
| 538 | #endif | ||
| 539 | } | 518 | } |
| 540 | EXPORT_SYMBOL(msecs_to_jiffies); | 519 | EXPORT_SYMBOL(__msecs_to_jiffies); |
| 541 | 520 | ||
| 542 | unsigned long usecs_to_jiffies(const unsigned int u) | 521 | unsigned long usecs_to_jiffies(const unsigned int u) |
| 543 | { | 522 | { |
