From: Tejun Heo <tj@kernel.org>
To: Peter Boonstoppel <pboonstoppel@nvidia.com>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
Paul Gortmaker <paul.gortmaker@windriver.com>,
Henrique de Moraes Holschuh <ibm-acpi@hmh.eng.br>,
Andy Walls <awalls@md.metrocast.net>,
Diwakar Tundlam <dtundlam@nvidia.com>,
Peter Zijlstra <peterz@infradead.org>,
Oleg Nesterov <oleg@redhat.com>
Subject: Re: [PATCH 1/1] kthread: disable preemption during complete()
Date: Wed, 25 Jul 2012 15:40:44 -0700 [thread overview]
Message-ID: <20120725224044.GC32378@google.com> (raw)
In-Reply-To: <5FBF8E85CA34454794F0F7ECBA79798F379D36485E@HQMAIL04.nvidia.com>
(cc'ing Oleg and Peter)
On Wed, Jul 25, 2012 at 03:35:32PM -0700, Peter Boonstoppel wrote:
> 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@nvidia.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();
Shouldn't this happen before setting current state to UNINTERRUPTIBLE?
What prevents preemption happening right above preempt_disable()?
> complete(&create->done);
> + preempt_enable_no_resched();
> +
> schedule();
PeterZ, Oleg, can you guys please review this?
Thanks.
--
tejun
next prev parent reply other threads:[~2012-07-25 22:40 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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
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=20120725224044.GC32378@google.com \
--to=tj@kernel.org \
--cc=awalls@md.metrocast.net \
--cc=dtundlam@nvidia.com \
--cc=ibm-acpi@hmh.eng.br \
--cc=linux-kernel@vger.kernel.org \
--cc=oleg@redhat.com \
--cc=paul.gortmaker@windriver.com \
--cc=pboonstoppel@nvidia.com \
--cc=peterz@infradead.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