]> git.proxmox.com Git - mirror_ubuntu-disco-kernel.git/commitdiff
workqueue: change value of lcpu in __queue_delayed_work_on()
authorJoonsoo Kim <js1304@gmail.com>
Wed, 15 Aug 2012 14:25:38 +0000 (23:25 +0900)
committerTejun Heo <tj@kernel.org>
Thu, 16 Aug 2012 21:21:15 +0000 (14:21 -0700)
We assign cpu id into work struct's data field in __queue_delayed_work_on().
In current implementation, when work is come in first time,
current running cpu id is assigned.
If we do __queue_delayed_work_on() with CPU A on CPU B,
__queue_work() invoked in delayed_work_timer_fn() go into
the following sub-optimal path in case of WQ_NON_REENTRANT.

gcwq = get_gcwq(cpu);
if (wq->flags & WQ_NON_REENTRANT &&
(last_gcwq = get_work_gcwq(work)) && last_gcwq != gcwq) {

Change lcpu to @cpu and rechange lcpu to local cpu if lcpu is WORK_CPU_UNBOUND.
It is sufficient to prevent to go into sub-optimal path.

tj: Slightly rephrased the comment.

Signed-off-by: Joonsoo Kim <js1304@gmail.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
kernel/workqueue.c

index c29f2dc0f4fc41b4463c4904c9cee6374fa7123d..99ee9b9392643b7802040dea5f2744aa73ea1d27 100644 (file)
@@ -1356,9 +1356,15 @@ static void __queue_delayed_work(int cpu, struct workqueue_struct *wq,
        if (!(wq->flags & WQ_UNBOUND)) {
                struct global_cwq *gcwq = get_work_gcwq(work);
 
-               if (gcwq && gcwq->cpu != WORK_CPU_UNBOUND)
+               /*
+                * If we cannot get the last gcwq from @work directly,
+                * select the last CPU such that it avoids unnecessarily
+                * triggering non-reentrancy check in __queue_work().
+                */
+               lcpu = cpu;
+               if (gcwq)
                        lcpu = gcwq->cpu;
-               else
+               if (lcpu == WORK_CPU_UNBOUND)
                        lcpu = raw_smp_processor_id();
        } else {
                lcpu = WORK_CPU_UNBOUND;