Re: MSEC_TO_JIFFIES is messed up...

From: Andrew Morton
Date: Thu May 13 2004 - 17:40:16 EST


Jeff Garzik <jgarzik@xxxxxxxxx> wrote:
>
> For whomever winds up doing this work, I have two requests:
>
> * use a type-safe inline rather than purely a macro, as some drivers do
> * replace msecs_to_jiffies() occurrences as well as MSECS_TO_JIFFIES()
> (and ditto for jiffies_to_msecs)



Use typesafe inlines for the jiffies-to-millisecond conversion functions.

This means that milliseconds officially takes the type `unsigned int'. All
current callers seem to be OK with that.

Drivers need to be fixed up to use this instead of their private versions.


---

25-akpm/include/linux/time.h | 25 +++++++++++++++++++------
1 files changed, 19 insertions(+), 6 deletions(-)

diff -puN include/linux/time.h~MSEC_TO_JIFFIES-inline include/linux/time.h
--- 25/include/linux/time.h~MSEC_TO_JIFFIES-inline Thu May 13 15:13:19 2004
+++ 25-akpm/include/linux/time.h Thu May 13 15:23:58 2004
@@ -184,16 +184,29 @@ struct timezone {
* Avoid unnecessary multiplications/divisions in the
* two most common HZ cases:
*/
+static inline unsigned int jiffies_to_msecs(unsigned long j)
+{
#if HZ <= 1000 && !(1000 % HZ)
-# define JIFFIES_TO_MSECS(j) ((1000/HZ)*(j))
-# define MSECS_TO_JIFFIES(m) (((m) + (1000/HZ) - 1)/(1000/HZ))
+ return (1000 / HZ) * j;
#elif HZ > 1000 && !(HZ % 1000)
-# define JIFFIES_TO_MSECS(j) (((j) + (HZ/1000) - 1)/(HZ/1000))
-# define MSECS_TO_JIFFIES(m) ((m)*(HZ/1000))
+ return (j + (HZ / 1000) - 1)/(HZ / 1000);
#else
-# define JIFFIES_TO_MSECS(j) (((j) * 1000) / HZ)
-# define MSECS_TO_JIFFIES(m) (((m) * HZ + 999) / 1000)
+ return (j * 1000) / HZ;
#endif
+}
+static inline unsigned long msecs_to_jiffies(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
+ return (m * HZ + 999) / 1000;
+#endif
+}
+
+#define JIFFIES_TO_MSECS(j) jiffies_to_msecs(j)
+#define MSECS_TO_JIFFIES(m) msecs_to_jiffies(m)

/*
* The TICK_NSEC - 1 rounds up the value to the next resolution. Note

_

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/