Skip to content

Commit da07d2f

Browse files
qais-yousefPeter Zijlstra
authored andcommitted
sched/fair: Fixes for capacity inversion detection
Traversing the Perf Domains requires rcu_read_lock() to be held and is conditional on sched_energy_enabled(). Ensure right protections applied. Also skip capacity inversion detection for our own pd; which was an error. Fixes: 44c7b80 ("sched/fair: Detect capacity inversion") Reported-by: Dietmar Eggemann <dietmar.eggemann@arm.com> Signed-off-by: Qais Yousef (Google) <qyousef@layalina.io> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Reviewed-by: Vincent Guittot <vincent.guittot@linaro.org> Link: https://lore.kernel.org/r/20230112122708.330667-3-qyousef@layalina.io
1 parent e26fd28 commit da07d2f

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

kernel/sched/fair.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8868,16 +8868,23 @@ static void update_cpu_capacity(struct sched_domain *sd, int cpu)
88688868
* * Thermal pressure will impact all cpus in this perf domain
88698869
* equally.
88708870
*/
8871-
if (static_branch_unlikely(&sched_asym_cpucapacity)) {
8871+
if (sched_energy_enabled()) {
88728872
unsigned long inv_cap = capacity_orig - thermal_load_avg(rq);
8873-
struct perf_domain *pd = rcu_dereference(rq->rd->pd);
8873+
struct perf_domain *pd;
8874+
8875+
rcu_read_lock();
88748876

8877+
pd = rcu_dereference(rq->rd->pd);
88758878
rq->cpu_capacity_inverted = 0;
88768879

88778880
for (; pd; pd = pd->next) {
88788881
struct cpumask *pd_span = perf_domain_span(pd);
88798882
unsigned long pd_cap_orig, pd_cap;
88808883

8884+
/* We can't be inverted against our own pd */
8885+
if (cpumask_test_cpu(cpu_of(rq), pd_span))
8886+
continue;
8887+
88818888
cpu = cpumask_any(pd_span);
88828889
pd_cap_orig = arch_scale_cpu_capacity(cpu);
88838890

@@ -8902,6 +8909,8 @@ static void update_cpu_capacity(struct sched_domain *sd, int cpu)
89028909
break;
89038910
}
89048911
}
8912+
8913+
rcu_read_unlock();
89058914
}
89068915

89078916
trace_sched_cpu_capacity_tp(rq);

0 commit comments

Comments
 (0)