Commit cdd140bd authored by Oleg Nesterov's avatar Oleg Nesterov Committed by Linus Torvalds

kthreads: simplify the startup synchronization

We use two completions two create the kernel thread, this is a bit ugly.
kthread() wakes up create_kthread() via ->started, then create_kthread()
wakes up the caller kthread_create() via ->done.  But kthread() does not
need to wait for kthread(), it can just return.  Instead kthread() itself
can wake up the caller of kthread_create().

Kill kthread_create_info->started, ->done is enough.  This improves the
scalability a bit and sijmplifies the code.

The only problem if kernel_thread() fails, in that case create_kthread()
must do complete(&create->done).
Signed-off-by: default avatarOleg Nesterov <oleg@redhat.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Pavel Emelyanov <xemul@openvz.org>
Cc: Rusty Russell <rusty@rustcorp.com.au>
Cc: Vitaliy Gusev <vgusev@openvz.org
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent e1eb1ebc
...@@ -27,7 +27,6 @@ struct kthread_create_info ...@@ -27,7 +27,6 @@ struct kthread_create_info
/* Information passed to kthread() from kthreadd. */ /* Information passed to kthread() from kthreadd. */
int (*threadfn)(void *data); int (*threadfn)(void *data);
void *data; void *data;
struct completion started;
/* Result passed back to kthread_create() from kthreadd. */ /* Result passed back to kthread_create() from kthreadd. */
struct task_struct *result; struct task_struct *result;
...@@ -75,7 +74,7 @@ static int kthread(void *_create) ...@@ -75,7 +74,7 @@ static int kthread(void *_create)
/* OK, tell user we're spawned, wait for stop or wakeup */ /* OK, tell user we're spawned, wait for stop or wakeup */
__set_current_state(TASK_UNINTERRUPTIBLE); __set_current_state(TASK_UNINTERRUPTIBLE);
create->result = current; create->result = current;
complete(&create->started); complete(&create->done);
schedule(); schedule();
if (!kthread_should_stop()) if (!kthread_should_stop())
...@@ -95,11 +94,10 @@ static void create_kthread(struct kthread_create_info *create) ...@@ -95,11 +94,10 @@ static void create_kthread(struct kthread_create_info *create)
/* We want our own signal handler (we take no signals by default). */ /* We want our own signal handler (we take no signals by default). */
pid = kernel_thread(kthread, create, CLONE_FS | CLONE_FILES | SIGCHLD); pid = kernel_thread(kthread, create, CLONE_FS | CLONE_FILES | SIGCHLD);
if (pid < 0) if (pid < 0) {
create->result = ERR_PTR(pid); create->result = ERR_PTR(pid);
else complete(&create->done);
wait_for_completion(&create->started); }
complete(&create->done);
} }
/** /**
...@@ -130,7 +128,6 @@ struct task_struct *kthread_create(int (*threadfn)(void *data), ...@@ -130,7 +128,6 @@ struct task_struct *kthread_create(int (*threadfn)(void *data),
create.threadfn = threadfn; create.threadfn = threadfn;
create.data = data; create.data = data;
init_completion(&create.started);
init_completion(&create.done); init_completion(&create.done);
spin_lock(&kthread_create_lock); spin_lock(&kthread_create_lock);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment