[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <5FBF8E85CA34454794F0F7ECBA79798F379D36485E@HQMAIL04.nvidia.com>
Date: Wed, 25 Jul 2012 15:35:32 -0700
From: Peter Boonstoppel <pboonstoppel@...dia.com>
To: Tejun Heo <tj@...nel.org>
CC: "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
Paul Gortmaker <paul.gortmaker@...driver.com>,
Henrique de Moraes Holschuh <ibm-acpi@....eng.br>,
Andy Walls <awalls@...metrocast.net>,
Diwakar Tundlam <dtundlam@...dia.com>
Subject: RE: [PATCH 1/1] kthread: disable preemption during complete()
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.
Signed-off-by: Peter Boonstoppel <pboonstoppel@...dia.com>
---
kernel/kthread.c | 11 +++++++++++
1 files changed, 11 insertions(+), 0 deletions(-)
diff --git a/kernel/kthread.c b/kernel/kthread.c
index b579af5..757d8dd 100644
--- a/kernel/kthread.c
+++ b/kernel/kthread.c
@@ -16,6 +16,7 @@
#include <linux/mutex.h>
#include <linux/slab.h>
#include <linux/freezer.h>
+#include <linux/preempt.h>
#include <trace/events/sched.h>
static DEFINE_SPINLOCK(kthread_create_lock);
@@ -113,7 +114,17 @@ static int kthread(void *_create)
/* OK, tell user we're spawned, wait for stop or wakeup */
__set_current_state(TASK_UNINTERRUPTIBLE);
create->result = current;
+
+ /*
+ * Disable preemption so we enter TASK_UNINTERRUPTIBLE after
+ * complete() instead of possibly being preempted. This speeds
+ * up clients that do a kthread_bind() directly after
+ * creation.
+ */
+ preempt_disable();
complete(&create->done);
+ preempt_enable_no_resched();
+
schedule();
ret = -EINTR;
--
1.7.0.4
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists