[2.6 PATCH] include/linux/jiffies.h cputime miscalculation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



static inline clock_t jiffies_to_clock_t(long x)
uses a signed long as input (jiffies) while the return value of
static inline unsigned long clock_t_to_jiffies(unsigned long x)
is an unsigned long.

As long as x is <= 0x7FFFFFFF everything is fine in jiffies_to_clock_t()
but when x is >= 0x80000000 the return value of the function is
miscalculated.

I've noticed this while watching the stats of long running processes
(/proc/<PID>/stat) on i386 machines. Up to ~35785 minutes of consumed
CPU-time for a process it's ok but only one minute later there's a huge
jump in the reported CPU-time to ~319786 minutes.

With the Patch you can get straight up to ~71571 minutes of CPU time
until
you'll restart at 0 (jiffies 32bit wrap around from (2**32)-1 to 0)

For non-i386 you may get other periods of time until the overflow
happens.

Signed-off-by: Oliver Weihe <[email protected]>

Patch based on 2.6.11.7

--- include/linux/jiffies.h.orig 2005-04-18 14:57:42.000000000 +0200
+++ include/linux/jiffies.h     2005-04-18 14:58:05.000000000 +0200
@@ -380,7 +380,7 @@ jiffies_to_timeval(const unsigned long j
 /*
  * Convert jiffies/jiffies_64 to clock_t and back.
  */
-static inline clock_t jiffies_to_clock_t(long x)
+static inline clock_t jiffies_to_clock_t(unsigned long x)
 {
 #if (TICK_NSEC % (NSEC_PER_SEC / USER_HZ)) == 0
        return x / (HZ / USER_HZ);

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

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux