mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Dmitry Adamushko <dmitry.adamushko@gmail.com>
To: Andrew Morton <akpm@linux-foundation.org>, linux-kernel@vger.kernel.org
Cc: Nick Piggin <nickpiggin@yahoo.com.au>,
	Ingo Molnar <mingo@elte.hu>, Rusty Russel <rusty@rustcorp.com.au>,
	"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Andy Whitcroft <apw@shadowen.org>,
	dmitry.adamushko@gmail.com
Subject: [PATCH 2/2] kthread: call wake_up_process() whithout the lock being held
Date: Wed, 20 Feb 2008 22:39:32 +0100	[thread overview]
Message-ID: <1203543572.6307.28.camel@earth> (raw)

From: Dmitry Adamushko <dmitry.adamushko@gmail.com>
Subject: kthread: call wake_up_process() whithout the lock being held
    
- from the POV of synchronization, there should be no need to call wake_up_process()
with the 'kthread_create_lock' being held;
    
- moreover, in order to support a lockless check for list_empty(&kthread_create_list)
in kthreadd() :
    
 	set_current_state(TASK_INTERRUPTIBLE);
    	if (list_empty(&kthread_create_list))
    		schedule();
    
we must ensure that a modification of the list (i.e. list_add_tail()) has been completed
by the moment a state of the task is checked in try_to_wake_up().
i.e. they must not be re-ordered.
    
wake_up_process() (i.e. try_to_wake_up() effectively) doesn't provide a full mb.
By moving wake_up_process() out of the locked section, we get an UNLOCK/LOCK
pair (LOCK is in try_to_wake_up()) which is guaranteed to act as a full mb.
    
Signed-off-by: Dmitry Adamushko <dmitry.adamushko@gmail.com>


diff --git a/kernel/kthread.c b/kernel/kthread.c
index d7a7897..ec68e0f 100644
--- a/kernel/kthread.c
+++ b/kernel/kthread.c
@@ -158,9 +158,9 @@ struct task_struct *kthread_create(int (*threadfn)(void *data),
 
 	spin_lock(&kthread_create_lock);
 	list_add_tail(&create.list, &kthread_create_list);
-	wake_up_process(kthreadd_task);
 	spin_unlock(&kthread_create_lock);
 
+	wake_up_process(kthreadd_task);
 	wait_for_completion(&create.done);
 
 	if (!IS_ERR(create.result)) {



                 reply	other threads:[~2008-02-20 21:39 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=1203543572.6307.28.camel@earth \
    --to=dmitry.adamushko@gmail.com \
    --cc=a.p.zijlstra@chello.nl \
    --cc=akpm@linux-foundation.org \
    --cc=apw@shadowen.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=nickpiggin@yahoo.com.au \
    --cc=paulmck@linux.vnet.ibm.com \
    --cc=rusty@rustcorp.com.au \
    /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®