lkml.org 
[lkml]   [2004]   [Apr]   [14]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
SubjectRe: /proc or ps tools bug? 2.6.3, time is off
> diff -Nru a/include/linux/times.h b/include/linux/times.h
> --- a/include/linux/times.h Tue Apr 13 15:00:25 2004
> +++ b/include/linux/times.h Tue Apr 13 15:00:25 2004
> @@ -7,7 +7,12 @@
> #include <asm/param.h>
>
> #if (HZ % USER_HZ)==0
> -# define jiffies_to_clock_t(x) ((x) / (HZ / USER_HZ))
> +static inline long jiffies_to_clock_t(long x)
> +{
> + u64 tmp = (u64)x * TICK_NSEC;
> + x = do_div(tmp, (NSEC_PER_SEC / USER_HZ));
> + return (long)tmp;
> +}
> #else
> # define jiffies_to_clock_t(x) ((clock_t) jiffies_64_to_clock_t((u64) x))
> #endif

Excuse me for barging in lately and innocently, but I find this patch
hard to comprehend:
- shouldn't a foo_to_clock_t() function return a clock?
- the x = seems superfluous
- the #if is not a shortcut anymore, so why keep it?
Shouldn't this patch be more like the following
(completely untested)?

Tim


diff -urp --exclude-from dontdiff linux-2.6.5/include/linux/times.h linux-2.6.5-jfix1/include/linux/times.h
--- linux-2.6.5/include/linux/times.h 2004-02-04 04:43:09.000000000 +0100
+++ linux-2.6.5-jfix1/include/linux/times.h 2004-04-14 13:48:57.000000000 +0200
@@ -6,11 +6,16 @@
#include <asm/types.h>
#include <asm/param.h>

-#if (HZ % USER_HZ)==0
-# define jiffies_to_clock_t(x) ((x) / (HZ / USER_HZ))
-#else
-# define jiffies_to_clock_t(x) ((clock_t) jiffies_64_to_clock_t((u64) x))
-#endif
+static inline clock_t jiffies_to_clock_t(long x)
+{
+#if (TICK_NSEC % (NSEC_PER_SEC / USER_HZ)) == 0
+ return x / (HZ / USER_HZ);
+#else
+ u64 tmp = (u64)x * TICK_NSEC;
+ do_div(tmp, (NSEC_PER_SEC / USER_HZ));
+ return (long)tmp;
+#endif
+}

static inline unsigned long clock_t_to_jiffies(unsigned long x)
{
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
\
 
 \ /
  Last update: 2005-03-22 14:02    [W:0.155 / U:0.136 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site