mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Lai Jiangshan <laijs@cn.fujitsu.com>
To: <linux-kernel@vger.kernel.org>
Cc: Tejun Heo <tj@kernel.org>, Lai Jiangshan <laijs@cn.fujitsu.com>
Subject: [PATCH 1/3] workqueue: migrate the new worker before add it to idle_list
Date: Sat, 26 Jul 2014 11:04:49 +0800	[thread overview]
Message-ID: <1406343900-32423-2-git-send-email-laijs@cn.fujitsu.com> (raw)
In-Reply-To: <1406343900-32423-1-git-send-email-laijs@cn.fujitsu.com>

There is an undocumented requirement for create_worker() that it can
only be called from existing worker (aka. manager) except the first call.

The reason is that the current create_worker() queues the new worker to
idle_list at first and then wake up it.  But the new worker is not
guaranteed to be migrated until it is waken up.  Thus the
wq_worker_sleeping() may see the new non-local worker from the idle_list
if this block of code is not executed on the local CPU to disable
wq_worker_sleeping().  Existing worker can guarantee to run on local
CPU when !DISASSOCIATED, so create_worker() is required to be called
from existing worker/manager only currently.

But we are planning to allow create_worker() to be called out side
from its workers and the requirement should be alleviated.  So we exchange
the order of the code, the new worker is woken up before queued
to idle_list.

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
---
 kernel/workqueue.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index 370f947..1d44d8d 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -1708,8 +1708,13 @@ static struct worker *create_worker(struct worker_pool *pool)
 	/* start the newly created worker */
 	spin_lock_irq(&pool->lock);
 	worker->pool->nr_workers++;
-	worker_enter_idle(worker);
+	/*
+	 * Wake up the worker at first and then queue it to the idle_list,
+	 * so that it is ensued that the wq_worker_sleeping() sees the worker
+	 * had been migrated properly when sees this worker in the idle_list.
+	 */
 	wake_up_process(worker->task);
+	worker_enter_idle(worker);
 	spin_unlock_irq(&pool->lock);
 
 	return worker;
-- 
1.7.4.4


  reply	other threads:[~2014-07-26  3:04 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-26  3:04 [PATCH 0/3] workqueue: offload the worker-management out from kworker Lai Jiangshan
2014-07-26  3:04 ` Lai Jiangshan [this message]
2014-07-26  3:04 ` [PATCH 2/3] workqueue: use dedicated creater kthread for all pools Lai Jiangshan
2014-07-28 18:55   ` Tejun Heo
2014-07-29  1:26     ` Lai Jiangshan
2014-07-29  2:16       ` Tejun Heo
2014-07-29  9:16         ` [PATCH RFC 2/2 V2] " Lai Jiangshan
2014-07-29 15:04           ` Tejun Heo
2014-07-30  0:32             ` Lai Jiangshan
2014-07-30  3:23               ` Tejun Heo
2014-07-30  3:46                 ` Lai Jiangshan
2014-07-30  3:46                   ` Tejun Heo
2014-07-26  3:04 ` [PATCH 3/3] workqueue: cleanup may_start_working() 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=1406343900-32423-2-git-send-email-laijs@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

all inboxes | Powered by JetHome®