[PATCH] proc: Do not overflow get_{idle,iowait}_time for nohz

From: Michal Hocko
Date: Fri Dec 02 2011 - 10:17:03 EST


get_{idle,iowait}_time use usecs_to_cputime to translate micro seconds
time to cputime64_t. This is just an alias to usecs_to_jiffies which
reduces the data type from u64 to unsigned int and also checks whether
the given paramerer overflows jiffies_to_usecs(MAX_JIFFY_OFFSET) and
returns MAX_JIFFY_OFFSET in that case. How much we overflow depends on
CONFIG_HZ and especially for CONFIG_HZ_300 it is quite low (1431649781).

This results in a bug when people saw [h]top going mad reporting 100%
CPU usage even though there was basically no CPU load at all. The reason
was simply that /proc/stat stopped reporting idle/io_wait changes (and
reported MAX_JIFFY_OFFSET) and so the only change happenning was for
user system time.

Let's use nsecs_to_jiffies64 instead as it doesn't overflow.

Signed-off-by: Michal Hocko <mhocko@xxxxxxx>
---
fs/proc/stat.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/proc/stat.c b/fs/proc/stat.c
index 42b274d..2a30d67 100644
--- a/fs/proc/stat.c
+++ b/fs/proc/stat.c
@@ -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 = usecs_to_cputime(idle_time);
+ idle = nsecs_to_jiffies64(1000 * idle_time);

return idle;
}
@@ -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 = usecs_to_cputime(iowait_time);
+ iowait = nsecs_to_jiffies64(1000 * iowait_time);

return iowait;
}
--
1.7.7.3


--
Michal Hocko
SUSE Labs
SUSE LINUX s.r.o.
Lihovarska 1060/12
190 00 Praha 9
Czech Republic
--
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/