[PATCH] proc: consider time when ticks are off when reporting idletime

From: Michal Hocko
Date: Mon Jul 25 2011 - 10:16:26 EST


---
fs/proc/stat.c | 3 +++
kernel/time/tick-sched.c | 20 ++++++++++++++++++++
2 files changed, 23 insertions(+), 0 deletions(-)

diff --git a/fs/proc/stat.c b/fs/proc/stat.c
index 9758b65..970ec81 100644
--- a/fs/proc/stat.c
+++ b/fs/proc/stat.c
@@ -21,6 +21,8 @@
#define arch_idle_time(cpu) 0
#endif

+cputime64_t nohz_idle_shift(int cpu);
+
static int show_stat(struct seq_file *p, void *v)
{
int i, j;
@@ -44,6 +46,7 @@ static int show_stat(struct seq_file *p, void *v)
system = cputime64_add(system, kstat_cpu(i).cpustat.system);
idle = cputime64_add(idle, kstat_cpu(i).cpustat.idle);
idle = cputime64_add(idle, arch_idle_time(i));
+ idle = cputime64_add(idle, nohz_idle_shift(i));
iowait = cputime64_add(iowait, kstat_cpu(i).cpustat.iowait);
irq = cputime64_add(irq, kstat_cpu(i).cpustat.irq);
softirq = cputime64_add(softirq, kstat_cpu(i).cpustat.softirq);
diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c
index d5097c4..57d11fa 100644
--- a/kernel/time/tick-sched.c
+++ b/kernel/time/tick-sched.c
@@ -194,6 +194,26 @@ static ktime_t tick_nohz_start_idle(int cpu, struct tick_sched *ts)
return now;
}

+cputime64_t nohz_idle_shift(int cpu)
+{
+ struct tick_sched *ts = &per_cpu(tick_cpu_sched, cpu);
+ cputime64_t notick_idle = 0;
+
+ if (ts->idle_active && time_after(ts->next_jiffies, jiffies)) {
+ /*
+ * we are idle and not ticking due to NOHZ so the
+ * kernel doesn't account for the idle. Let's use
+ * last_jiffies. We are screwed when jiffies overflow
+ * of course but what else we can do?
+ */
+ notick_idle = cputime64_add(notick_idle,
+ jiffies_to_cputime(
+ jiffies - ts->last_jiffies));
+ }
+
+ return notick_idle;
+}
+
/**
* get_cpu_idle_time_us - get the total idle time of a cpu
* @cpu: CPU number to query
--
1.7.5.4


--
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/