nohz: stat: Fix CPU idle time accounting
Bo Yan [Fri, 22 Mar 2013 21:03:26 +0000 (14:03 -0700)]
Since cpustat[CPUTIME_IDLE] is never connected to ts->idle_sleeptime,
never read from cpustat[CPUTIME_IDLE] when reporting stats in
/proc/stat.

Note this was rejected by Michal Hocko when it was initially proposed
by Martin Schwidefsky in LKML, so if you want to upstream it, better
find an alternative (either completely disable cpustat[CPUTIME_IDLE]
for CONFIG_NO_HZ or somehow connect them to keep them in sync.)

bug 1190321

Change-Id: Idc92488910b826aff850a010016d8326c7ab9e6c
Signed-off-by: Bo Yan <byan@nvidia.com>
Reviewed-on: http://git-master/r/212224
(cherry picked from commit e7a9220f5883bf3816e24895a34239a34a7d9ece)
Reviewed-on: http://git-master/r/212907
GVS: Gerrit_Virtual_Submit
Reviewed-by: Liang Cheng (SW) <licheng@nvidia.com>

kernel/time/tick-sched.c

index 4251374..da00c96 100644 (file)
@@ -482,7 +482,7 @@ u64 get_cpu_idle_time_us(int cpu, u64 *last_update_time)
                update_ts_time_stats(cpu, ts, now, last_update_time);
                idle = ts->idle_sleeptime;
        } else {
-               if (ts->idle_active && !nr_iowait_cpu(cpu)) {
+               if (cpu_online(cpu) && ts->idle_active && !nr_iowait_cpu(cpu)) {
                        ktime_t delta = ktime_sub(now, ts->idle_entrytime);
 
                        idle = ktime_add(ts->idle_sleeptime, delta);
@@ -523,7 +523,8 @@ u64 get_cpu_iowait_time_us(int cpu, u64 *last_update_time)
                update_ts_time_stats(cpu, ts, now, last_update_time);
                iowait = ts->iowait_sleeptime;
        } else {
-               if (ts->idle_active && nr_iowait_cpu(cpu) > 0) {
+               if (cpu_online(cpu) && ts->idle_active &&
+                                               nr_iowait_cpu(cpu) > 0) {
                        ktime_t delta = ktime_sub(now, ts->idle_entrytime);
 
                        iowait = ktime_add(ts->iowait_sleeptime, delta);