mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: ebiederm@xmission.com (Eric W. Biederman)
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Oleg Nesterov <oleg@tv-sign.ru>,
	Davide Libenzi <davidel@xmailserver.org>,
	Ingo Molnar <mingo@elte.hu>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	"Rafael J. Wysocki" <rjw@sisk.pl>,
	Roland McGrath <roland@redhat.com>,
	Rusty Russell <rusty@rustcorp.com.au>,
	linux-kernel@vger.kernel.org, <linux-arch@vger.kernel.org>
Subject: [PATCH] kthread: Simplify kthread_create.
Date: Fri, 13 Apr 2007 21:17:39 -0600	[thread overview]
Message-ID: <m1vefzmyp8.fsf_-_@ebiederm.dsl.xmission.com> (raw)
In-Reply-To: <m1zm5bmywm.fsf@ebiederm.dsl.xmission.com> (Eric W. Biederman's message of "Fri, 13 Apr 2007 21:13:13 -0600")


This removes an unneeded completion from kthread_create and moves
wake_up_process out of the kthread_create_lock making it clear that
wake_up_process doesn't need the protection of the
kthread_create_lock.

Signed-off-by: Eric W. Biederman <ebiederm@xmission.com>
---
 kernel/kthread.c |   16 ++++++----------
 1 files changed, 6 insertions(+), 10 deletions(-)

diff --git a/kernel/kthread.c b/kernel/kthread.c
index 06c7e51..cd89b49 100644
--- a/kernel/kthread.c
+++ b/kernel/kthread.c
@@ -24,7 +24,6 @@ struct kthread_create_info
 	/* Information passed to kthread() from kthreadd. */
 	int (*threadfn)(void *data);
 	void *data;
-	struct completion started;
 
 	/* Result passed back to kthread_create() from kthreadd. */
 	struct task_struct *result;
@@ -41,6 +40,9 @@ static int kthread(void *_create)
 	void *data;
 	int ret = -EINTR;
 
+	/* Report which task_struct I am */
+	create->result = current;
+
 	/* Setup a completion on this thread's stack */
 	init_completion(&done);
 	current->vfork_done = &done;
@@ -51,7 +53,7 @@ static int kthread(void *_create)
 
 	/* OK, tell user we're spawned, wait for stop or wakeup */
 	__set_current_state(TASK_INTERRUPTIBLE);
-	complete(&create->started);
+	complete(&create->done);
 	schedule();
 
 	if (!kthread_should_stop())
@@ -68,13 +70,8 @@ static void create_kthread(struct kthread_create_info *create)
 	pid = kernel_thread(kthread, create, CLONE_FS | CLONE_FILES | SIGCHLD);
 	if (pid < 0) {
 		create->result = ERR_PTR(pid);
-	} else {
-		wait_for_completion(&create->started);
-		read_lock(&tasklist_lock);
-		create->result = find_task_by_pid(pid);
-		read_unlock(&tasklist_lock);
+		complete(&create->done);
 	}
-	complete(&create->done);
 }
 
 /**
@@ -105,14 +102,13 @@ struct task_struct *kthread_create(int (*threadfn)(void *data),
 
 	create.threadfn = threadfn;
 	create.data = data;
-	init_completion(&create.started);
 	init_completion(&create.done);
 
 	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)) {
-- 
1.5.0.g53756


  reply	other threads:[~2007-04-14  3:19 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-04-13 13:02 [PATCH 3/3] make kthread_stop() scalable Oleg Nesterov
2007-04-13 23:44 ` Eric W. Biederman
2007-04-14 18:02   ` Oleg Nesterov
2007-04-14 18:34     ` Eric W. Biederman
2007-04-14 18:50       ` Oleg Nesterov
2007-04-14  3:13 ` [PATCH] kthread: Enhance kthread_stop to abort interruptible sleeps Eric W. Biederman
2007-04-14  3:17   ` Eric W. Biederman [this message]
2007-04-14 18:35   ` Oleg Nesterov
2007-04-14 19:04     ` Eric W. Biederman
2007-04-14 19:34       ` Oleg Nesterov
2007-04-24 10:09   ` Andrew Morton
2007-04-24 10:30     ` Eric W. Biederman
2007-04-24 10:42       ` Andrew Morton
2007-04-24 11:11         ` Eric W. Biederman
2007-04-24 15:05       ` Oleg Nesterov
2007-04-24 15:53         ` Oleg Nesterov
2007-04-24 17:18           ` Eric W. Biederman
2007-04-24 20:27             ` Oleg Nesterov
2007-04-24 21:19               ` Eric W. Biederman

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=m1vefzmyp8.fsf_-_@ebiederm.dsl.xmission.com \
    --to=ebiederm@xmission.com \
    --cc=akpm@linux-foundation.org \
    --cc=davidel@xmailserver.org \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=oleg@tv-sign.ru \
    --cc=rjw@sisk.pl \
    --cc=roland@redhat.com \
    --cc=rusty@rustcorp.com.au \
    --cc=torvalds@linux-foundation.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®