Re: MSEC_TO_JIFFIES is messed up...

From: Paul Wagland
Date: Thu May 13 2004 - 12:41:25 EST


Nit pick I'm sure... but....

On May 13, 2004, at 0:18, William Lee Irwin III wrote:

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.


-- wli


Index: linux-2.5/include/linux/time.h
===================================================================
--- linux-2.5.orig/include/linux/time.h 2004-05-12 15:04:10.000000000 -0700
+++ linux-2.5/include/linux/time.h 2004-05-12 15:12:49.000000000 -0700
@@ -184,12 +184,12 @@
* 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)

Also, can we keep the same parameter name across all of the macros?

This changes behaviour when HZ==(z)000

JIFFIES_TO_MSECS goes from
((x) * 1000) / (z)000 to (((x) + (z) - 1)/(z))

i.e. for x=1, z=2 this goes from ((1)*1000)/2000)=0 to (((1)+(2)-1)/2)=1

However, MSECS_TO_JIFFIES remains the same going from
(((x) * (z)000 + 999) / 1000) to ((x)*(z))

I.e. they basically reduce down to the same thing (modulo overflows)

All of the other permuations look correct to me...

Cheers,
Paul

Attachment: PGP.sig
Description: This is a digitally signed message part