From 8e765d0ad1eec6a3effde88891b01859fa71a3c7 Mon Sep 17 00:00:00 2001 From: Ian Abbott Date: Mon, 21 Aug 2006 16:25:12 +0000 Subject: [PATCH] Fix for SuSE 9.0 2.4.21 kernel. Simplify jiffies_to_msecs() and msecs_to_jiffies() to avoid preprocessor optimisations that depend on HZ being a C constant expression. Just round the result up to the nearest integer. The supported range of input values (avoiding arithmetic overflow) is now less than that of the Linux versions of these functions for common values of HZ, but that's unlikely to cause any problems (and if it does we can fix it by making the functions more complicated). --- include/linux/time.h | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/include/linux/time.h b/include/linux/time.h index fccbff54..4fdf7eb0 100644 --- a/include/linux/time.h +++ b/include/linux/time.h @@ -10,24 +10,14 @@ static inline unsigned int jiffies_to_msecs(const unsigned long j) { -#if HZ <= 1000 && !(1000 % HZ) - return (1000 / HZ) * j; -#elif HZ > 1000 && !(HZ % 1000) - return (j + (HZ / 1000) - 1)/(HZ / 1000); -#else - return (j * 1000) / HZ; -#endif + /* This works for jiffies values up to ((ULONG_MAX + 1 - HZ) / 1000) */ + return (j * 1000 + HZ - 1) / HZ; } static inline unsigned long msecs_to_jiffies(const unsigned int m) { -#if HZ <= 1000 && !(1000 % HZ) - return (m + (1000 / HZ) - 1) / (1000 / HZ); -#elif HZ > 1000 && !(HZ % 1000) - return m * (HZ / 1000); -#else + /* This works for msecs values up to ((ULONG_MAX - 999) / HZ) */ return (m * HZ + 999) / 1000; -#endif }; #endif -- 2.26.2