Skip to content

Commit

Permalink
procfs: do not confuse jiffies with cputime64_t
Browse files Browse the repository at this point in the history
Commit 2a95ea6 ("procfs: do not overflow get_{idle,iowait}_time
for nohz") did not take into account that one some architectures jiffies
and cputime use different units.

This causes get_idle_time() to return numbers in the wrong units, making
the idle time fields in /proc/stat wrong.

Instead of converting the usec value returned by
get_cpu_{idle,iowait}_time_us to units of jiffies, use the new function
usecs_to_cputime64 to convert it to the correct unit of cputime64_t.

Signed-off-by: Andreas Schwab <[email protected]>
Acked-by: Michal Hocko <[email protected]>
Cc: Arnd Bergmann <[email protected]>
Cc: "Artem S. Tashkinov" <[email protected]>
Cc: Dave Jones <[email protected]>
Cc: Alexey Dobriyan <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: "Luck, Tony" <[email protected]>
Cc: Benjamin Herrenschmidt <[email protected]>
Cc: Martin Schwidefsky <[email protected]>
Cc: Heiko Carstens <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
andreas-schwab authored and torvalds committed Dec 30, 2011
1 parent e26a511 commit 3484563
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions arch/ia64/include/asm/cputime.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ typedef u64 cputime64_t;
*/
#define cputime_to_usecs(__ct) ((__ct) / NSEC_PER_USEC)
#define usecs_to_cputime(__usecs) ((__usecs) * NSEC_PER_USEC)
#define usecs_to_cputime64(__usecs) usecs_to_cputime(__usecs)

/*
* Convert cputime <-> seconds
Expand Down
2 changes: 2 additions & 0 deletions arch/powerpc/include/asm/cputime.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ static inline cputime_t usecs_to_cputime(const unsigned long us)
return ct;
}

#define usecs_to_cputime64(us) usecs_to_cputime(us)

/*
* Convert cputime <-> seconds
*/
Expand Down
2 changes: 2 additions & 0 deletions arch/s390/include/asm/cputime.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ usecs_to_cputime(const unsigned int m)
return (cputime_t) m * 4096;
}

#define usecs_to_cputime64(m) usecs_to_cputime(m)

/*
* Convert cputime to milliseconds and back.
*/
Expand Down
4 changes: 2 additions & 2 deletions fs/proc/stat.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ static cputime64_t get_idle_time(int cpu)
idle = kstat_cpu(cpu).cpustat.idle;
idle = cputime64_add(idle, arch_idle_time(cpu));
} else
idle = nsecs_to_jiffies64(1000 * idle_time);
idle = usecs_to_cputime64(idle_time);

return idle;
}
Expand All @@ -46,7 +46,7 @@ static cputime64_t get_iowait_time(int cpu)
/* !NO_HZ so we can rely on cpustat.iowait */
iowait = kstat_cpu(cpu).cpustat.iowait;
else
iowait = nsecs_to_jiffies64(1000 * iowait_time);
iowait = usecs_to_cputime64(iowait_time);

return iowait;
}
Expand Down
1 change: 1 addition & 0 deletions include/asm-generic/cputime.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ typedef u64 cputime64_t;
*/
#define cputime_to_usecs(__ct) jiffies_to_usecs(__ct)
#define usecs_to_cputime(__msecs) usecs_to_jiffies(__msecs)
#define usecs_to_cputime64(__msecs) nsecs_to_jiffies64((__msecs) * 1000)

/*
* Convert cputime to seconds and back.
Expand Down

0 comments on commit 3484563

Please sign in to comment.