Commit 49cc01f4 authored by Nishanth Aravamudan's avatar Nishanth Aravamudan Committed by Linus Torvalds

[PATCH] include/jiffies: fix usecs_to_jiffies()/jiffies_to_usecs() math

Fixes the math of both jiffies_to_usecs() and usecs_to_jiffies() which
improperly assume the same rounding point -- 1,000 -- as jiffies_to_msecs()
and msecs_to_jiffies(), when in fact it should be 1,000,000.  Furthermore,
the actual math of both functions is actually wrong and will lead to more
than just rounding errors.
Signed-off-by: default avatarNishanth Aravamudan <nacc@us.ibm.com>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 14d23203
......@@ -265,10 +265,10 @@ static inline unsigned int jiffies_to_msecs(const unsigned long j)
static inline unsigned int jiffies_to_usecs(const unsigned long j)
{
#if HZ <= 1000 && !(1000 % HZ)
#if HZ <= 1000000 && !(1000000 % HZ)
return (1000000 / HZ) * j;
#elif HZ > 1000 && !(HZ % 1000)
return (j*1000 + (HZ - 1000))/(HZ / 1000);
#elif HZ > 1000000 && !(HZ % 1000000)
return (j + (HZ / 1000000) - 1)/(HZ / 1000000);
#else
return (j * 1000000) / HZ;
#endif
......@@ -291,9 +291,9 @@ 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)
#if HZ <= 1000000 && !(1000000 % HZ)
return (u + (1000000 / HZ) - 1) / (1000000 / HZ);
#elif HZ > 1000000 && !(HZ % 1000000)
return u * (HZ / 1000000);
#else
return (u * HZ + 999999) / 1000000;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment