Skip to content

Commit aa202f1

Browse files
Hillf Dantonhtejun
authored andcommitted
workqueue: don't use wq_select_unbound_cpu() for bound works
wq_select_unbound_cpu() is designed for unbound workqueues only, but it's wrongly called when using a bound workqueue too. Fixing this ensures work queued to a bound workqueue with cpu=WORK_CPU_UNBOUND always runs on the local CPU. Before, that would happen only if wq_unbound_cpumask happened to include it (likely almost always the case), or was empty, or we got lucky with forced round-robin placement. So restricting /sys/devices/virtual/workqueue/cpumask to a small subset of a machine's CPUs would cause some bound work items to run unexpectedly there. Fixes: ef55718 ("workqueue: schedule WORK_CPU_UNBOUND work on wq_unbound_cpumask CPUs") Cc: [email protected] # v4.5+ Signed-off-by: Hillf Danton <[email protected]> [dj: massage changelog] Signed-off-by: Daniel Jordan <[email protected]> Cc: Tejun Heo <[email protected]> Cc: Lai Jiangshan <[email protected]> Cc: [email protected] Signed-off-by: Tejun Heo <[email protected]>
1 parent dbb92f8 commit aa202f1

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

kernel/workqueue.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1411,14 +1411,16 @@ static void __queue_work(int cpu, struct workqueue_struct *wq,
14111411
return;
14121412
rcu_read_lock();
14131413
retry:
1414-
if (req_cpu == WORK_CPU_UNBOUND)
1415-
cpu = wq_select_unbound_cpu(raw_smp_processor_id());
1416-
14171414
/* pwq which will be used unless @work is executing elsewhere */
1418-
if (!(wq->flags & WQ_UNBOUND))
1419-
pwq = per_cpu_ptr(wq->cpu_pwqs, cpu);
1420-
else
1415+
if (wq->flags & WQ_UNBOUND) {
1416+
if (req_cpu == WORK_CPU_UNBOUND)
1417+
cpu = wq_select_unbound_cpu(raw_smp_processor_id());
14211418
pwq = unbound_pwq_by_node(wq, cpu_to_node(cpu));
1419+
} else {
1420+
if (req_cpu == WORK_CPU_UNBOUND)
1421+
cpu = raw_smp_processor_id();
1422+
pwq = per_cpu_ptr(wq->cpu_pwqs, cpu);
1423+
}
14221424

14231425
/*
14241426
* If @work was previously on a different pool, it might still be

0 commit comments

Comments
 (0)