Skip to content

Commit df3cb4e

Browse files
Xunlei PangPeter Zijlstra
authored andcommitted
sched/fair: Fix wrong cpu selecting from isolated domain
We've met problems that occasionally tasks with full cpumask (e.g. by putting it into a cpuset or setting to full affinity) were migrated to our isolated cpus in production environment. After some analysis, we found that it is due to the current select_idle_smt() not considering the sched_domain mask. Steps to reproduce on my 31-CPU hyperthreads machine: 1. with boot parameter: "isolcpus=domain,2-31" (thread lists: 0,16 and 1,17) 2. cgcreate -g cpu:test; cgexec -g cpu:test "test_threads" 3. some threads will be migrated to the isolated cpu16~17. Fix it by checking the valid domain mask in select_idle_smt(). Fixes: 10e2f1a ("sched/core: Rewrite and improve select_idle_siblings()) Reported-by: Wetp Zhang <wetp.zy@linux.alibaba.com> Signed-off-by: Xunlei Pang <xlpang@linux.alibaba.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Reviewed-by: Jiang Biao <benbjiang@tencent.com> Reviewed-by: Vincent Guittot <vincent.guittot@linaro.org> Link: https://lkml.kernel.org/r/1600930127-76857-1-git-send-email-xlpang@linux.alibaba.com
1 parent 51bd512 commit df3cb4e

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

kernel/sched/fair.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6080,15 +6080,16 @@ static int select_idle_core(struct task_struct *p, struct sched_domain *sd, int
60806080
/*
60816081
* Scan the local SMT mask for idle CPUs.
60826082
*/
6083-
static int select_idle_smt(struct task_struct *p, int target)
6083+
static int select_idle_smt(struct task_struct *p, struct sched_domain *sd, int target)
60846084
{
60856085
int cpu;
60866086

60876087
if (!static_branch_likely(&sched_smt_present))
60886088
return -1;
60896089

60906090
for_each_cpu(cpu, cpu_smt_mask(target)) {
6091-
if (!cpumask_test_cpu(cpu, p->cpus_ptr))
6091+
if (!cpumask_test_cpu(cpu, p->cpus_ptr) ||
6092+
!cpumask_test_cpu(cpu, sched_domain_span(sd)))
60926093
continue;
60936094
if (available_idle_cpu(cpu) || sched_idle_cpu(cpu))
60946095
return cpu;
@@ -6104,7 +6105,7 @@ static inline int select_idle_core(struct task_struct *p, struct sched_domain *s
61046105
return -1;
61056106
}
61066107

6107-
static inline int select_idle_smt(struct task_struct *p, int target)
6108+
static inline int select_idle_smt(struct task_struct *p, struct sched_domain *sd, int target)
61086109
{
61096110
return -1;
61106111
}
@@ -6279,7 +6280,7 @@ static int select_idle_sibling(struct task_struct *p, int prev, int target)
62796280
if ((unsigned)i < nr_cpumask_bits)
62806281
return i;
62816282

6282-
i = select_idle_smt(p, target);
6283+
i = select_idle_smt(p, sd, target);
62836284
if ((unsigned)i < nr_cpumask_bits)
62846285
return i;
62856286

0 commit comments

Comments
 (0)