diff options
-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 | * |