Re: [PATCH] system timer: fix crash in <100Hz system timer

From: Andrew Morton
Date: Wed Jan 09 2008 - 02:16:10 EST


On Sat, 5 Jan 2008 16:16:55 -0600 David Fries <david@xxxxxxxxx> wrote:

> --- a/kernel/time.c
> +++ b/kernel/time.c
> @@ -565,7 +565,11 @@ EXPORT_SYMBOL(jiffies_to_timeval);
> clock_t jiffies_to_clock_t(long x)
> {
> #if (TICK_NSEC % (NSEC_PER_SEC / USER_HZ)) == 0
> + #if HZ < USER_HZ
> + return x * (USER_HZ / HZ);
> + #else
> return x / (HZ / USER_HZ);
> + #endif
> #else
> u64 tmp = (u64)x * TICK_NSEC;
> do_div(tmp, (NSEC_PER_SEC / USER_HZ));
> @@ -598,7 +602,12 @@ EXPORT_SYMBOL(clock_t_to_jiffies);
> u64 jiffies_64_to_clock_t(u64 x)
> {
> #if (TICK_NSEC % (NSEC_PER_SEC / USER_HZ)) == 0
> - do_div(x, HZ / USER_HZ);
> + #if HZ < USER_HZ
> + x *= USER_HZ;
> + do_div(x, HZ);
> + #else
> + do_div(x, HZ / USER_HZ);
> + #endif
> #else

Somwhat off-topic:

I guess HZ=USER_HZ is a not-uncommon case, and it's pretty silly calling
do_div(x, 1) all the time. How about we optimise that case?

Perhaps there are other places...


--- a/kernel/time.c~speed-up-jiffies-conversion-functions-if-hz==user_hz
+++ a/kernel/time.c
@@ -618,8 +618,10 @@ u64 jiffies_64_to_clock_t(u64 x)
# if HZ < USER_HZ
x *= USER_HZ;
do_div(x, HZ);
-# else
+# elif HZ > USER_HZ
do_div(x, HZ / USER_HZ);
+# else
+ /* Nothing to do */
# endif
#else
/*
_

--
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/