Skip to contentSkip to conversation

cputime: fix account_steal_time.

PATCH New Martin Schwidefsky 1 participant 1 message Jan 14, 2005

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cputime: fix account_steal_time.

Hi Andrew,
after the cputime patches have hit BitKeeper, Uli had a look at them and being Uli he found a bug. Actually three bugs but they are all in the same function. The bugs are only relevant for an architecture that uses account_steal_time which is currently s390 only.

blue skies,
Martin.

---

[PATCH] cputime: fix account_steal_time.

From: Ulrich Weigand <[email protected]>
From: Martin Schwidefsky <[email protected]>

account_steal_time called for idle doesn't work correctly:
1) steal time while idle needs to be added to the system time of idle to get correct uptime numbers
3) if there is an i/o request outstanding the steal time should be added to iowait, even if the hypervisor scheduled another virtual cpu since we are still waiting for i/o.
2) steal time while idle without an i/o request outstanding has to be added to cpustat->idle and not to cpustat->system.

diffstat:

 kernel/sched.c |   14 +++++++++-----
 1 files changed, 9 insertions(+), 5 deletions(-)
kernel/sched.c +9 -5
diff -urN linux-2.6/kernel/sched.c linux-2.6-patched/kernel/sched.c
@@ -2383,13 +2383,17 @@
 void account_steal_time(struct task_struct *p, cputime_t steal)
 {
 	struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
-	cputime64_t steal64 = cputime_to_cputime64(steal);
+	cputime64_t tmp = cputime_to_cputime64(steal);
 	runqueue_t *rq = this_rq();
 
-	if (p == rq->idle)
-		cpustat->system = cputime64_add(cpustat->system, steal64);
-	else
-		cpustat->steal = cputime64_add(cpustat->steal, steal64);
+	if (p == rq->idle) {
+		p->stime = cputime_add(p->stime, steal);
+		if (atomic_read(&rq->nr_iowait) > 0)
+			cpustat->iowait = cputime64_add(cpustat->iowait, tmp);
+		else
+			cpustat->idle = cputime64_add(cpustat->idle, tmp);
+	} else
+		cpustat->steal = cputime64_add(cpustat->steal, tmp);
 }
 
 /*