From: Lai Jiangshan <laijs@cn.fujitsu.com>
To: Tejun Heo <tj@kernel.org>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH 04/12] workqueue: simplify is_chained_work()
Date: Fri, 28 Sep 2012 17:52:02 +0800 [thread overview]
Message-ID: <50657342.6000008@cn.fujitsu.com> (raw)
In-Reply-To: <20120926182837.GE12544@google.com>
On 09/27/2012 02:28 AM, Tejun Heo wrote:
> On Thu, Sep 27, 2012 at 01:20:35AM +0800, Lai Jiangshan wrote:
>> is_chained_work() is too complicated. we can simply found out
>> whether current task is worker by PF_WQ_WORKER or wq->rescuer.
>>
>> Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
>> ---
>> kernel/workqueue.c | 36 ++++++++++++------------------------
>> 1 files changed, 12 insertions(+), 24 deletions(-)
>>
>> diff --git a/kernel/workqueue.c b/kernel/workqueue.c
>> index e41c562..c718b94 100644
>> --- a/kernel/workqueue.c
>> +++ b/kernel/workqueue.c
>> @@ -1182,34 +1182,22 @@ 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;
>> + struct worker *worker = NULL;
>>
>> - for_each_gcwq_cpu(cpu) {
>> - struct global_cwq *gcwq = get_gcwq(cpu);
>> - struct worker *worker;
>> - struct hlist_node *pos;
>> - int i;
>> + if (wq->rescuer && current == wq->rescuer->task) /* rescuer_thread() */
>> + worker = wq->rescuer;
>> + else if (current->flags & PF_WQ_WORKER) /* worker_thread() */
>> + worker = kthread_data(current);
>>
>> - spin_lock_irqsave(&gcwq->lock, flags);
>> - for_each_busy_worker(worker, i, pos, gcwq) {
>> - if (worker->task != current)
>> - continue;
>> - spin_unlock_irqrestore(&gcwq->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(&gcwq->lock, flags);
>> - }
>> - return false;
>> + /*
>> + * I'm @worker, no locking necessary. See if @work
>> + * is headed to the same workqueue.
>> + */
>> + return worker && worker->current_cwq->wq == wq;
if current is a worker and ...
>
> How about,
>
> if (wq->rescuer && current == wq->rescuer->task)
> worker = wq->rescuer;
> else if (current->flags & PF_WQ_WORKER)
> worker = kthread_data(current);
> else
> return NULL;
>
> return worker->curent_cwq->wq == wq;
>
Hi, Tejun
Your code is good, but I don't think I need to resend(and use your code).
Main reason: I think the readability of your is the same as mine,
and your add two lines.
Tiny reason: my code uses only one return. (I don't always keep one return,
but I try to keep it if it is still clean)
Is there any other reason to change it?
Thanks,
Lai.
next prev parent reply other threads:[~2012-09-28 9:49 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-26 17:20 [PATCH 00/12] workqueue: simple cleanups Lai Jiangshan
2012-09-26 17:20 ` [PATCH 01/12] workqueue: add WORKER_RESCUER Lai Jiangshan
2012-09-26 18:07 ` Tejun Heo
2012-09-28 10:11 ` Lai Jiangshan
2012-09-26 17:20 ` [PATCH 02/12] workqueue: disallow set_cpus_allowed_ptr() from work item Lai Jiangshan
2012-09-26 18:12 ` Tejun Heo
2012-09-26 17:20 ` [PATCH 03/12] workqueue: remove WORKER_PREP from rescuer Lai Jiangshan
2012-09-26 18:24 ` Tejun Heo
2012-09-28 10:04 ` Lai Jiangshan
2012-09-30 7:39 ` Tejun Heo
2012-09-26 17:20 ` [PATCH 04/12] workqueue: simplify is_chained_work() Lai Jiangshan
2012-09-26 18:28 ` Tejun Heo
2012-09-28 9:52 ` Lai Jiangshan [this message]
2012-09-30 7:32 ` Tejun Heo
2012-09-26 17:20 ` [PATCH 05/12] workqueue: don't wake up other workers in rescuer Lai Jiangshan
2012-09-26 18:34 ` Tejun Heo
2012-09-28 10:18 ` Lai Jiangshan
2012-09-26 17:20 ` [PATCH 06/12] workqueue: destroy_worker() can only destory idle worker not just created worker Lai Jiangshan
2012-09-26 18:35 ` Tejun Heo
2012-09-26 17:20 ` [PATCH 07/12] workqueue: remove WORKER_STARTED Lai Jiangshan
2012-09-26 18:36 ` Tejun Heo
2012-09-28 9:52 ` Lai Jiangshan
2012-09-26 17:20 ` [PATCH 08/12] workqueue: fix comments of insert_work() Lai Jiangshan
2012-09-26 17:20 ` [PATCH 09/12] workqueue: declare system_highpri_wq Lai Jiangshan
2012-09-26 17:20 ` [PATCH 10/12] cpu-hotplug.txt: fix comments of work_on_cpu() Lai Jiangshan
2012-09-26 17:20 ` [RFC PATCH 11/12] workqueue: add WQ_CPU_INTENSIVE to system_long_wq Lai Jiangshan
2012-09-26 18:38 ` Tejun Heo
2012-09-28 8:06 ` Lai Jiangshan
2012-09-30 7:22 ` Tejun Heo
2012-09-26 17:20 ` [PATCH 12/12] workqueue: avoid work_on_cpu() to interfere system_wq Lai Jiangshan
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=50657342.6000008@cn.fujitsu.com \
--to=laijs@cn.fujitsu.com \
--cc=linux-kernel@vger.kernel.org \
--cc=tj@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