* [PATCH 2/4] kthreads: simplify the startup synchronization
@ 2009-01-30 12:33 Oleg Nesterov
2009-01-31 11:39 ` Rusty Russell
0 siblings, 1 reply; 2+ messages in thread
From: Oleg Nesterov @ 2009-01-30 12:33 UTC (permalink / raw)
To: Andrew Morton
Cc: Christoph Hellwig, Eric W. Biederman, Ingo Molnar,
Pavel Emelyanov, Rusty Russell, Vitaliy Gusev, linux-kernel
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: Oleg Nesterov <oleg@redhat.com>
--- 6.29-rc3/kernel/kthread.c~2_COMPLETION 2009-01-30 09:46:29.000000000 +0100
+++ 6.29-rc3/kernel/kthread.c 2009-01-30 10:45:18.000000000 +0100
@@ -29,7 +29,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;
@@ -77,7 +76,7 @@ static int kthread(void *_create)
/* OK, tell user we're spawned, wait for stop or wakeup */
__set_current_state(TASK_UNINTERRUPTIBLE);
create->result = current;
- complete(&create->started);
+ complete(&create->done);
schedule();
if (!kthread_should_stop())
@@ -99,10 +98,8 @@ static void create_kthread(struct kthrea
pid = kernel_thread(kthread, create, CLONE_FS | CLONE_FILES | SIGCHLD);
if (pid < 0) {
create->result = ERR_PTR(pid);
- } else {
- wait_for_completion(&create->started);
+ complete(&create->done);
}
- complete(&create->done);
}
/**
@@ -133,7 +130,6 @@ struct task_struct *kthread_create(int (
create.threadfn = threadfn;
create.data = data;
- init_completion(&create.started);
init_completion(&create.done);
spin_lock(&kthread_create_lock);
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH 2/4] kthreads: simplify the startup synchronization
2009-01-30 12:33 [PATCH 2/4] kthreads: simplify the startup synchronization Oleg Nesterov
@ 2009-01-31 11:39 ` Rusty Russell
0 siblings, 0 replies; 2+ messages in thread
From: Rusty Russell @ 2009-01-31 11:39 UTC (permalink / raw)
To: Oleg Nesterov
Cc: Andrew Morton, Christoph Hellwig, Eric W. Biederman, Ingo Molnar,
Pavel Emelyanov, Vitaliy Gusev, linux-kernel
On Friday 30 January 2009 23:03:54 Oleg Nesterov wrote:
> 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: Oleg Nesterov <oleg@redhat.com>
Nice! I'll apply this one after the minor respin of 1/4.
Thanks,
Rusty.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2009-01-31 11:40 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-01-30 12:33 [PATCH 2/4] kthreads: simplify the startup synchronization Oleg Nesterov
2009-01-31 11:39 ` Rusty Russell
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox