From: William Lee Irwin III Optimize the cases where HZ is a divisor of 1000 or vice-versa in JIFFIES_TO_MSECS() and MSECS_TO_JIFFIES() by allowing the nonvanishing(!) integral ratios to appear as a parenthesized expressions eligible for constant folding optimizations. --- 25-akpm/include/linux/time.h | 12 ++++++------ 1 files changed, 6 insertions(+), 6 deletions(-) diff -puN include/linux/time.h~msec_to_jiffies-fixups-speedup include/linux/time.h --- 25/include/linux/time.h~msec_to_jiffies-fixups-speedup Wed May 12 15:33:17 2004 +++ 25-akpm/include/linux/time.h Wed May 12 15:33:17 2004 @@ -184,12 +184,12 @@ struct timezone { * Avoid unnecessary multiplications/divisions in the * two most common HZ cases: */ -#if HZ == 1000 -# define JIFFIES_TO_MSECS(x) (x) -# define MSECS_TO_JIFFIES(x) (x) -#elif HZ == 100 -# define JIFFIES_TO_MSECS(x) ((x) * 10) -# define MSECS_TO_JIFFIES(x) (((x) + 9) / 10) +#if HZ <= 1000 && !(1000 % HZ) +# define JIFFIES_TO_MSECS(j) ((1000/HZ)*(j)) +# define MSECS_TO_JIFFIES(m) (((m) + (1000/HZ) - 1)/(1000/HZ)) +#elif HZ > 1000 && !(HZ % 1000) +# define JIFFIES_TO_MSECS(j) (((j) + (HZ/1000) - 1)/(HZ/1000)) +# define MSECS_TO_JIFFIES(m) ((m)*(HZ/1000)) #else # define JIFFIES_TO_MSECS(x) (((x) * 1000) / HZ) # define MSECS_TO_JIFFIES(x) (((x) * HZ + 999) / 1000) _