History

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().

Xunlei Pang committed 6 years ago

Commit df3cb4e1 parent 51bd5121 file · +5 −4Browse files

Showing the changes to kernel (1 of 1 file). Show all

Unified · Split

kernel/sched/fair.c+5−4
@@ -6080,7 +6080,7 @@ static int select_idle_core(struct task_struct *p, struct sched_domain *sd, int · 6079 unmodified lines
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
@@ -6088,7 +6088,8 @@ static int select_idle_smt(struct task_struct *p, int target) · 1 unmodified line
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 · 9 unmodified lines
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 @@ symmetric: · 168 unmodified lines
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

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t