public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/1] kthread: disable preemption during complete()
@ 2012-07-25  0:05 Peter Boonstoppel
  2012-07-25  0:09 ` Tejun Heo
  0 siblings, 1 reply; 10+ messages in thread
From: Peter Boonstoppel @ 2012-07-25  0:05 UTC (permalink / raw)
  To: linux-kernel@vger.kernel.org, Tejun Heo, Paul Gortmaker,
	Henrique de Moraes Holschuh, Andy Walls
  Cc: Diwakar Tundlam

After a kthread is created it signals the requester using complete()
and enters TASK_UNINTERRUPTIBLE. However, since complete() wakes up
the requesting thread this can cause a preemption. The preemption will
not remove the task from the runqueue (for that schedule() has to be
invoked directly).

This is a problem if directly after kthread creation you try to do a
kthread_bind(), which will block in HZ steps until the thread is off
the runqueue.

This patch disables preemption during complete(), since we call
schedule() directly afterwards, so it will correctly enter
TASK_UNINTERRUPTIBLE. This speeds up kthread creation/binding during
cpu hotplug significantly.

Change-Id: I856ddd4e01ebdb198ba90f343b4a0c5933fd2b23
Signed-off-by: Peter Boonstoppel <pboonstoppel@nvidia.com>
---
 kernel/kthread.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/kernel/kthread.c b/kernel/kthread.c
index b579af5..f681b14 100644
--- a/kernel/kthread.c
+++ b/kernel/kthread.c
@@ -16,6 +16,8 @@
 #include <linux/mutex.h>
 #include <linux/slab.h>
 #include <linux/freezer.h>
+#include <linux/preempt.h>
+#include <linux/thread_info.h>
 #include <trace/events/sched.h>
 
 static DEFINE_SPINLOCK(kthread_create_lock);
@@ -113,7 +115,10 @@ static int kthread(void *_create)
 	/* OK, tell user we're spawned, wait for stop or wakeup */
 	__set_current_state(TASK_UNINTERRUPTIBLE);
 	create->result = current;
+	preempt_disable();
 	complete(&create->done);
+	clear_need_resched();
+	preempt_enable_no_resched();
 	schedule();
 
 	ret = -EINTR;
-- 
1.7.0.4

^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2012-08-01  7:14 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-07-25  0:05 [PATCH 1/1] kthread: disable preemption during complete() Peter Boonstoppel
2012-07-25  0:09 ` Tejun Heo
2012-07-25 22:35   ` Peter Boonstoppel
2012-07-25 22:40     ` Tejun Heo
2012-07-26  8:04       ` Peter Zijlstra
2012-07-26 10:47         ` Thomas Gleixner
2012-07-26 15:54           ` Oleg Nesterov
2012-07-26 19:29             ` Peter Zijlstra
2012-07-26 21:16           ` Peter Boonstoppel
2012-08-01  7:14             ` Thomas Gleixner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox