* [PATCH] workqueue: don't use wq_select_unbound_cpu() for bound works
@ 2020-01-25 1:14 Daniel Jordan
2020-02-12 21:08 ` Tejun Heo
0 siblings, 1 reply; 2+ messages in thread
From: Daniel Jordan @ 2020-01-25 1:14 UTC (permalink / raw)
To: Tejun Heo, Lai Jiangshan; +Cc: Hillf Danton, Daniel Jordan, linux-kernel
From: Hillf Danton <hdanton@sina.com>
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: ef557180447f ("workqueue: schedule WORK_CPU_UNBOUND work on wq_unbound_cpumask CPUs")
Signed-off-by: Hillf Danton <hdanton@sina.com>
[dj: massage changelog]
Signed-off-by: Daniel Jordan <daniel.m.jordan@oracle.com>
Cc: Tejun Heo <tj@kernel.org>
Cc: Lai Jiangshan <jiangshanlai@gmail.com>
Cc: linux-kernel@vger.kernel.org
---
kernel/workqueue.c | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index cfc923558e04..6978892b0d8a 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -1411,14 +1411,16 @@ static void __queue_work(int cpu, struct workqueue_struct *wq,
return;
rcu_read_lock();
retry:
- if (req_cpu == WORK_CPU_UNBOUND)
- cpu = wq_select_unbound_cpu(raw_smp_processor_id());
-
/* pwq which will be used unless @work is executing elsewhere */
- if (!(wq->flags & WQ_UNBOUND))
- pwq = per_cpu_ptr(wq->cpu_pwqs, cpu);
- else
+ if (wq->flags & WQ_UNBOUND) {
+ if (req_cpu == WORK_CPU_UNBOUND)
+ cpu = wq_select_unbound_cpu(raw_smp_processor_id());
pwq = unbound_pwq_by_node(wq, cpu_to_node(cpu));
+ } else {
+ if (req_cpu == WORK_CPU_UNBOUND)
+ cpu = raw_smp_processor_id();
+ pwq = per_cpu_ptr(wq->cpu_pwqs, cpu);
+ }
/*
* If @work was previously on a different pool, it might still be
--
2.24.1
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] workqueue: don't use wq_select_unbound_cpu() for bound works
2020-01-25 1:14 [PATCH] workqueue: don't use wq_select_unbound_cpu() for bound works Daniel Jordan
@ 2020-02-12 21:08 ` Tejun Heo
0 siblings, 0 replies; 2+ messages in thread
From: Tejun Heo @ 2020-02-12 21:08 UTC (permalink / raw)
To: Daniel Jordan; +Cc: Lai Jiangshan, Hillf Danton, linux-kernel
On Fri, Jan 24, 2020 at 08:14:45PM -0500, Daniel Jordan wrote:
> From: Hillf Danton <hdanton@sina.com>
>
> 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: ef557180447f ("workqueue: schedule WORK_CPU_UNBOUND work on wq_unbound_cpumask CPUs")
> Signed-off-by: Hillf Danton <hdanton@sina.com>
> [dj: massage changelog]
> Signed-off-by: Daniel Jordan <daniel.m.jordan@oracle.com>
> Cc: Tejun Heo <tj@kernel.org>
> Cc: Lai Jiangshan <jiangshanlai@gmail.com>
> Cc: linux-kernel@vger.kernel.org
Applied to wq/for-5.6-fixes.
Thanks.
--
tejun
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-02-12 21:08 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-25 1:14 [PATCH] workqueue: don't use wq_select_unbound_cpu() for bound works Daniel Jordan
2020-02-12 21:08 ` Tejun Heo
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®