]> git.neil.brown.name Git - history.git/commitdiff
[PATCH] Add a usecs_to_jiffies() function
authorNishanth Aravamudan <nacc@us.ibm.com>
Wed, 2 Feb 2005 00:49:39 +0000 (16:49 -0800)
committerLinus Torvalds <torvalds@ppc970.osdl.org>
Wed, 2 Feb 2005 00:49:39 +0000 (16:49 -0800)
Add a usecs_to_jiffies() function.  This will be used in one of my
subsequent patches.  With the potential for dynamic HZ values much higher
than 1000, we may need to consider times as small as usecs in terms of
jiffies.  We have msecs_to_jiffies(), jiffies_to_msecs() and
jiffies_to_usecs(), but no usecs_to_jiffies().

Signed-off-by: Nishanth Aravamudan <nacc@us.ibm.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
include/linux/jiffies.h

index d882d689519ae4ef4a3bff3321c09e1001ef85ab..5808e8041e0c372eb9c8c65d334621c47837e38f 100644 (file)
@@ -287,6 +287,19 @@ static inline unsigned long msecs_to_jiffies(const unsigned int m)
 #endif
 }
 
+static inline unsigned long usecs_to_jiffies(const unsigned int u)
+{
+       if (u > jiffies_to_usecs(MAX_JIFFY_OFFSET))
+               return MAX_JIFFY_OFFSET;
+#if HZ <= 1000 && !(1000 % HZ)
+       return (u + (1000000 / HZ) - 1000) / (1000000 / HZ);
+#elif HZ > 1000 && !(HZ % 1000)
+       return u * (HZ / 1000000);
+#else
+       return (u * HZ + 999999) / 1000000;
+#endif
+}
+
 /*
  * The TICK_NSEC - 1 rounds up the value to the next resolution.  Note
  * that a remainder subtract here would not do the right thing as the