From: Tejun Heo <tj@kernel.org>
To: linux-kernel@vger.kernel.org
Cc: Lai Jiangshan <laijs@cn.fujitsu.com>
Subject: [PATCH 2/2 wq/for-3.9] workqueue: reimplement is_chained_work() using current_wq_worker()
Date: Wed, 13 Feb 2013 19:27:05 -0800 [thread overview]
Message-ID: <20130214032705.GG9057@htj.dyndns.org> (raw)
In-Reply-To: <20130214032633.GF9057@htj.dyndns.org>
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>
---
kernel/workqueue.c | 33 ++++++++-------------------------
1 file changed, 8 insertions(+), 25 deletions(-)
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -1159,35 +1159,18 @@ static void insert_work(struct cpu_workq
/*
* 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;
+ struct worker *worker;
- 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;
-
- 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,
next prev parent reply other threads:[~2013-02-14 3:27 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-02-14 3:26 [PATCH 1/2 wq/for-3.9] workqueue: fix is_chained_work() regression Tejun Heo
2013-02-14 3:27 ` Tejun Heo [this message]
2013-02-16 17:06 ` [PATCH 2/2 wq/for-3.9] workqueue: reimplement is_chained_work() using current_wq_worker() Lai Jiangshan
2013-02-18 17:03 ` Tejun Heo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20130214032705.GG9057@htj.dyndns.org \
--to=tj@kernel.org \
--cc=laijs@cn.fujitsu.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®