mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2] sched/fair: fix sgc->{min,max}_capacity miscalculate
@ 2020-01-04 13:08 Peng Liu
  2020-01-06  9:25 ` Dietmar Eggemann
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Peng Liu @ 2020-01-04 13:08 UTC (permalink / raw)
  To: linux-kernel
  Cc: mingo, peterz, juri.lelli, vincent.guittot, dietmar.eggemann,
	rostedt, bsegall, mgorman, qais.yousef, morten.rasmussen,
	valentin.schneider

commit bf475ce0a3dd ("sched/fair: Add per-CPU min capacity to
sched_group_capacity") introduced per-cpu min_capacity.

commit e3d6d0cb66f2 ("sched/fair: Add sched_group per-CPU max capacity")
introduced per-cpu max_capacity.

Here, capacity is the accumulated sum of (maybe) many CPUs' capacity.
Compare with capacity to get {min,max}_capacity makes no sense. Instead,
we should compare one by one in each iteration to get
sgc->{min,max}_capacity of the group.

Also, the only CPU in rq->sd->groups should be rq's CPU. Thus,
capacity_of(cpu_of(rq)) should be equal to rq->sd->groups->sgc->capacity.
Code can be simplified by removing the if/else.

Signed-off-by: Peng Liu <iwtbavbm@gmail.com>
Reviewed-by: Valentin Schneider <valentin.schneider@arm.com>
---
v1: https://lkml.org/lkml/2019/12/30/502

 kernel/sched/fair.c | 26 ++++----------------------
 1 file changed, 4 insertions(+), 22 deletions(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 2d170b5da0e3..e14698a8ee38 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -7793,29 +7793,11 @@ void update_group_capacity(struct sched_domain *sd, int cpu)
 		 */
 
 		for_each_cpu(cpu, sched_group_span(sdg)) {
-			struct sched_group_capacity *sgc;
-			struct rq *rq = cpu_rq(cpu);
+			unsigned long cpu_cap = capacity_of(cpu);
 
-			/*
-			 * build_sched_domains() -> init_sched_groups_capacity()
-			 * gets here before we've attached the domains to the
-			 * runqueues.
-			 *
-			 * Use capacity_of(), which is set irrespective of domains
-			 * in update_cpu_capacity().
-			 *
-			 * This avoids capacity from being 0 and
-			 * causing divide-by-zero issues on boot.
-			 */
-			if (unlikely(!rq->sd)) {
-				capacity += capacity_of(cpu);
-			} else {
-				sgc = rq->sd->groups->sgc;
-				capacity += sgc->capacity;
-			}
-
-			min_capacity = min(capacity, min_capacity);
-			max_capacity = max(capacity, max_capacity);
+			min_capacity = min(cpu_cap, min_capacity);
+			max_capacity = max(cpu_cap, max_capacity);
+			capacity += cpu_cap;
 		}
 	} else  {
 		/*
-- 
2.17.1


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2020-01-17 10:09 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-04 13:08 [PATCH v2] sched/fair: fix sgc->{min,max}_capacity miscalculate Peng Liu
2020-01-06  9:25 ` Dietmar Eggemann
2020-01-06 10:28   ` Peter Zijlstra
2020-01-06 14:49   ` Peng Liu
2020-01-06 10:23 ` Peter Zijlstra
2020-01-06 14:52   ` Peng Liu
2020-01-17 10:08 ` [tip: sched/core] sched/fair: Fix sgc->{min,max}_capacity calculation for SD_OVERLAP tip-bot2 for Peng Liu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®