For the common cases where 1000 is a multiple of HZ, or HZ is a multiple of 1000, jiffies_to_msecs() never returns zero when passed a non-zero time period. However, if HZ > 1000 and not an integer multiple of 1000 (e.g. 1024 or 1200, as used on alpha and DECstation), jiffies_to_msecs() may return zero for small non-zero time periods. This may break code that relies on receiving back a non-zero value. jiffies_to_usecs() does not need such a fix: one jiffy can only be less than one µs if HZ > 1000000, and such large values of HZ are already rejected at build time, twice: - include/linux/jiffies.h does #error if HZ >= 12288, - kernel/time/time.c has BUILD_BUG_ON(HZ > USEC_PER_SEC). Broken since forever.
Unified · Split
| @@ -28,6 +28,7 @@ · 27 unmodified lines | |||
| 28 | */ | 28 | */ |
| 29 | 29 | ||
| 30 | #include <linux/export.h> | 30 | #include <linux/export.h> |
| 31 | #include <linux/kernel.h> | ||
| 31 | #include <linux/timex.h> | 32 | #include <linux/timex.h> |
| 32 | #include <linux/capability.h> | 33 | #include <linux/capability.h> |
| 33 | #include <linux/timekeeper_internal.h> | 34 | #include <linux/timekeeper_internal.h> |
| @@ -314,9 +315,10 @@ unsigned int jiffies_to_msecs(const unsigned long j) · 280 unmodified lines | |||
| 314 | return (j + (HZ / MSEC_PER_SEC) - 1)/(HZ / MSEC_PER_SEC); | 315 | return (j + (HZ / MSEC_PER_SEC) - 1)/(HZ / MSEC_PER_SEC); |
| 315 | #else | 316 | #else |
| 316 | # if BITS_PER_LONG == 32 | 317 | # if BITS_PER_LONG == 32 |
| 317 | return (HZ_TO_MSEC_MUL32 * j) >> HZ_TO_MSEC_SHR32; | 318 | return (HZ_TO_MSEC_MUL32 * j + (1ULL << HZ_TO_MSEC_SHR32) - 1) >> |
| 319 | HZ_TO_MSEC_SHR32; | ||
| 318 | # else | 320 | # else |
| 319 | return (j * HZ_TO_MSEC_NUM) / HZ_TO_MSEC_DEN; | 321 | return DIV_ROUND_UP(j * HZ_TO_MSEC_NUM, HZ_TO_MSEC_DEN); |
| 320 | # endif | 322 | # endif |
| 321 | #endif | 323 | #endif |
| 322 | } | 324 | } |