Re: [PATCH v2] sched: Check sched_domain before computing group power.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Nov 12, 2013 at 10:11:26PM +0530, Srikar Dronamraju wrote:
> After Commit-id 863bffc80898 (sched/fair: Fix group power_orig
> computation), we might end up computing group power before the
> sched_domain for a cpu is updated.
> 
> Update with cpu_power, if rq->sd is not yet updated.
> 
> Signed-off-by: Srikar Dronamraju <srikar@xxxxxxxxxxxxxxxxxx>
> ---
> Changelog since v1: Fix divide by zero errors that can result because
> power/power_orig was set to 0.

Duh yes!, init_sched_groups_power() is called before we attach the
actual domains, so the above will _always_ fail for the
build_sched_domain() case.

I was a bit puzzled how we could ever have 0 since surely at least the
current cpu should have some !0 contribution, but no!

---
Subject: sched: Check sched_domain before computing group power
From: Srikar Dronamraju <srikar@xxxxxxxxxxxxxxxxxx>
Date: Tue, 12 Nov 2013 22:11:26 +0530

After Commit-id 863bffc80898 (sched/fair: Fix group power_orig
computation), we can dereference rq->sd before its set.

Fix this by falling back to power_of() in this case and add a comment
explaining things.

Cc: mikey@xxxxxxxxxxx
Cc: mingo@xxxxxxxxxx
Cc: hpa@xxxxxxxxx
Cc: tglx@xxxxxxxxxxxxx
Signed-off-by: Srikar Dronamraju <srikar@xxxxxxxxxxxxxxxxxx>
[peterz: added comment and tweaked patch]
Signed-off-by: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
Link: http://lkml.kernel.org/r/20131112164126.GF2559@xxxxxxxxxxxxxxxxxx
---
 kernel/sched/fair.c |   27 ++++++++++++++++++++++++---
 1 file changed, 24 insertions(+), 3 deletions(-)

--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -5354,10 +5354,31 @@ void update_group_power(struct sched_dom
 		 */
 
 		for_each_cpu(cpu, sched_group_cpus(sdg)) {
-			struct sched_group *sg = cpu_rq(cpu)->sd->groups;
+			struct sched_group_power *sgp;
+			struct rq *rq = cpu_rq(cpu);
 
-			power_orig += sg->sgp->power_orig;
-			power += sg->sgp->power;
+			/*
+			 * build_sched_domains() -> init_sched_groups_power()
+			 * gets here before we've attached the domains to the
+			 * runqueues.
+			 *
+			 * Use power_of(), which is set irrespective of domains
+			 * in update_cpu_power().
+			 *
+			 * This avoids power/power_orig from being 0 and
+			 * causing divide-by-zero issues on boot.
+			 *
+			 * Runtime updates will correct power_orig.
+			 */
+			if (!rq->sd) {
+				power_orig += power_of(cpu);
+				power += power_of(cpu);
+				continue;
+			}
+
+			sgp = rq->sd->groups->sgp;
+			power_orig += sgp->power_orig;
+			power += sgp->power;
 		}
 	} else  {
 		/*
--
To unsubscribe from this list: send the line "unsubscribe linux-tip-commits" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Stable Commits]     [Linux Stable Kernel]     [Linux Kernel]     [Linux USB Devel]     [Linux Video &Media]     [Linux Audio Users]     [Yosemite News]     [Linux SCSI]

  Powered by Linux