Skip to contentSkip to conversation

Sched fix stale value in average load per task

PATCH Applied Balbir Singh 2 participants 6 messages Nov 12, 2008

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Sched fix stale value in average load per task

cpu_avg_load_per_task() returns a stale value when nr_running is 0. It returns an older stale (caculated when nr_running was non zero) value. This patch returns and sets rq->avg_load_per_task to zero when nr_running is 0.

Compile and boot tested on a x86_64 box.

---

 kernel/sched.c |    2 ++
 1 file changed, 2 insertions(+)
kernel/sched.c renamed from kernel/sched.c~sched-fix-stale-load-avg +2 -0
diff -puN kernel/sched.c~sched-fix-stale-load-avg kernel/sched.c
@@ -1430,6 +1430,8 @@ static unsigned long cpu_avg_load_per_ta
 
 	if (rq->nr_running)
 		rq->avg_load_per_task = rq->load.weight / rq->nr_running;
+	else
+		rq->avg_load_per_task = 0;
 
 	return rq->avg_load_per_task;
 }

_

Signature · 1 line
	Balbir
Applied
#1 lore raw
Quoted 5 lines · Balbir Singh

cpu_avg_load_per_task() returns a stale value when nr_running is 0. It returns an older stale (caculated when nr_running was non zero) value. This patch returns and sets rq->avg_load_per_task to zero when nr_running is 0.

Quoted 7 lines

Compile and boot tested on a x86_64 box.

---

 kernel/sched.c |    2 ++
 1 file changed, 2 insertions(+)

applied to tip/sched/urgent, thanks Balbir!

i'm wondering, have you observed load-balancer misbehavior due to this load-average imprecision bug, on some workload? (or have you found this via code review)

Ingo

#2 lore raw
Quoted 12 lines · Ingo Molnar
Quoted 10 lines · Balbir Singh

cpu_avg_load_per_task() returns a stale value when nr_running is 0. It returns an older stale (caculated when nr_running was non zero) value. This patch returns and sets rq->avg_load_per_task to zero when nr_running is 0.

Compile and boot tested on a x86_64 box.

---

Quoted 8 lines
Quoted 2 lines
 kernel/sched.c |    2 ++
 1 file changed, 2 insertions(+)

applied to tip/sched/urgent, thanks Balbir!

i'm wondering, have you observed load-balancer misbehavior due to this load-average imprecision bug, on some workload? (or have you found this via code review)

Thanks, Ingo!

I found this issue through code review. I did not see any misbehaviour yet due to load-average imprecision.

Signature · 4 lines
	Balbir

PS: FYI: I missed this email, since my name was missing in the to and cc list.
Could you check to see if there is any issue with your mailer, I'll do the same.
#3 lore raw
In reply to Balbir Singh

Review

Quoted 4 lines · Balbir Singh
(quoted diff) +2 -0
+	else
+		rq->avg_load_per_task = 0;
 
 	return rq->avg_load_per_task;

On second thoughts, does this look better? (Based on Mike Galbraith's suggestion)

cpu_avg_load_per_task() returns a stale value when nr_running is 0. It returns an older stale (caculated when nr_running was non zero) value. This patch returns and sets rq->avg_load_per_task to zero when nr_running is 0.

---

 kernel/sched.c |   10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
kernel/sched.c renamed from kernel/sched.c~sched-fix-stale-load-avg +4 -6
diff -puN kernel/sched.c~sched-fix-stale-load-avg kernel/sched.c
@@ -571,8 +571,6 @@ struct rq {
 	int cpu;
 	int online;
 
-	unsigned long avg_load_per_task;
-
 	struct task_struct *migration_thread;
 	struct list_head migration_queue;
 #endif
@@ -1428,10 +1426,10 @@ static unsigned long cpu_avg_load_per_ta
 {
 	struct rq *rq = cpu_rq(cpu);
 
-	if (rq->nr_running)
-		rq->avg_load_per_task = rq->load.weight / rq->nr_running;
-
-	return rq->avg_load_per_task;
+	if (unlikely(!rq->nr_running))
+		return 0;
+	else
+		return rq->load.weight / rq->nr_running;
 }
 
 #ifdef CONFIG_FAIR_GROUP_SCHED

_

Signature · 1 line
	Balbir
#4 lore raw
Quoted 9 lines · Balbir Singh

kernel/sched.c static unsigned long cpu_avg_load_per_ta

Quoted 4 lines · Balbir Singh
kernel/sched.c renamed from kernel/sched.c~sched-fix-stale-load-avg +2 -0
+	else
+		rq->avg_load_per_task = 0;
 
 	return rq->avg_load_per_task;

On second thoughts, does this look better? (Based on Mike Galbraith's suggestion)

yes - but could you send it as a delta patch against your previous patch please? We want the simpler patch for tip/sched/urgent, as a v2.6.28 fix - the removal of rq->avg_load_per_task can wait until v2.6.29. (Please also include Mike's Ack in the patch if he acks the patch.)

Ingo

#5 lore raw
Quoted 11 lines · Ingo Molnar
Quoted 8 lines · Balbir Singh

kernel/sched.c static unsigned long cpu_avg_load_per_ta

Quoted 4 lines · Balbir Singh
kernel/sched.c renamed from kernel/sched.c~sched-fix-stale-load-avg +2 -0
+	else
+		rq->avg_load_per_task = 0;
 
 	return rq->avg_load_per_task;

On second thoughts, does this look better? (Based on Mike Galbraith's suggestion)

Quoted 5 lines

yes - but could you send it as a delta patch against your previous patch please? We want the simpler patch for tip/sched/urgent, as a v2.6.28 fix - the removal of rq->avg_load_per_task can wait until v2.6.29. (Please also include Mike's Ack in the patch if he acks the patch.)

Fair enough. I'll send out the delta tomorrow.

Signature · 1 line
	Balbir