summaryrefslogtreecommitdiffstats
path: root/kernel
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2013-02-13 19:29:10 -0800
committerTejun Heo <tj@kernel.org>2013-02-13 19:29:10 -0800
commit8d03ecfe471802d6afe97da97722b6924533aa82 (patch)
tree1178cacfdd36358665f9a4c6325329346b221dd0 /kernel
parent1dd638149f1f9d7d7dbb32591d5c7c2a0ea36264 (diff)
downloadlinux-8d03ecfe471802d6afe97da97722b6924533aa82.tar.bz2
workqueue: reimplement is_chained_work() using current_wq_worker()
is_chained_work() was added before current_wq_worker() and implemented its own ham-fisted way of finding out whether %current is a workqueue worker - it iterates through all possible workers. Drop the custom implementation and reimplement using current_wq_worker(). Signed-off-by: Tejun Heo <tj@kernel.org>
Diffstat (limited to 'kernel')
-rw-r--r--kernel/workqueue.c33
1 files changed, 8 insertions, 25 deletions
diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index 0d26ab3aee59..ea7f696f1060 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -1159,35 +1159,18 @@ static void insert_work(struct cpu_workqueue_struct *cwq,
/*
* Test whether @work is being queued from another work executing on the
- * same workqueue. This is rather expensive and should only be used from
- * cold paths.
+ * same workqueue.
*/
static bool is_chained_work(struct workqueue_struct *wq)
{
- unsigned long flags;
- unsigned int cpu;
-
- for_each_cwq_cpu(cpu, wq) {
- struct cpu_workqueue_struct *cwq = get_cwq(cpu, wq);
- struct worker_pool *pool = cwq->pool;
- struct worker *worker;
- struct hlist_node *pos;
- int i;
+ struct worker *worker;
- spin_lock_irqsave(&pool->lock, flags);
- for_each_busy_worker(worker, i, pos, pool) {
- if (worker->task != current)
- continue;
- spin_unlock_irqrestore(&pool->lock, flags);
- /*
- * I'm @worker, no locking necessary. See if @work
- * is headed to the same workqueue.
- */
- return worker->current_cwq->wq == wq;
- }
- spin_unlock_irqrestore(&pool->lock, flags);
- }
- return false;
+ worker = current_wq_worker();
+ /*
+ * Return %true iff I'm a worker execuing a work item on @wq. If
+ * I'm @worker, it's safe to dereference it without locking.
+ */
+ return worker && worker->current_cwq->wq == wq;
}
static void __queue_work(unsigned int cpu, struct workqueue_struct *wq,