From: Peter Zijlstra <peterz@infradead.org>
To: "Kohli, Gaurav" <gkohli@codeaurora.org>
Cc: tglx@linutronix.de, mpe@ellerman.id.au, dzickus@redhat.com,
mingo@kernel.org, bigeasy@linutronix.de,
linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org,
Neeraj Upadhyay <neeraju@codeaurora.org>
Subject: Re: [PATCH] kthread/smpboot: Serialize kthread parking against wakeup
Date: Tue, 24 Apr 2018 20:05:04 +0200 [thread overview]
Message-ID: <20180424180504.GV4043@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <3e823654-9701-9b01-43fc-1a29feb7a298@codeaurora.org>
On Tue, Apr 24, 2018 at 08:12:49PM +0530, Kohli, Gaurav wrote:
> @@ -157,6 +156,7 @@ static int smpboot_thread_fn(void *data)
>
> if (!ht->thread_should_run(td->cpu)) {
>
> preempt_enable_no_resched();
>
> + set_current_state(TASK_INTERRUPTIBLE);
>
> schedule();
>
> } else {
>
> __set_current_state(TASK_RUNNING);
>
> Please suggest if this approach is better.
Bah, my brain isn't working... see below for the 'correct' version of
your second patch.
But this violates the normal pattern; see the comment near
set_current_state(). That pattern ensures the thread either sees the
wakeup condition or the actual wakeup.
I'm thinking that with this patch there is a scenario where we'll miss
both the kthread_should_park() and the actual wakeup and end up not
doing anything.
I do the like the end result, but I suspect it's buggy.
---
kernel/smpboot.c | 7 +------
1 file changed, 1 insertion(+), 6 deletions(-)
diff --git a/kernel/smpboot.c b/kernel/smpboot.c
index 5043e7433f4b..5bdf57f2ce68 100644
--- a/kernel/smpboot.c
+++ b/kernel/smpboot.c
@@ -109,10 +109,8 @@ static int smpboot_thread_fn(void *data)
struct smp_hotplug_thread *ht = td->ht;
while (1) {
- set_current_state(TASK_INTERRUPTIBLE);
preempt_disable();
if (kthread_should_stop()) {
- __set_current_state(TASK_RUNNING);
preempt_enable();
/* cleanup must mirror setup */
if (ht->cleanup && td->status != HP_THREAD_NONE)
@@ -122,7 +120,6 @@ static int smpboot_thread_fn(void *data)
}
if (kthread_should_park()) {
- __set_current_state(TASK_RUNNING);
preempt_enable();
if (ht->park && td->status == HP_THREAD_ACTIVE) {
BUG_ON(td->cpu != smp_processor_id());
@@ -139,7 +136,6 @@ static int smpboot_thread_fn(void *data)
/* Check for state change setup */
switch (td->status) {
case HP_THREAD_NONE:
- __set_current_state(TASK_RUNNING);
preempt_enable();
if (ht->setup)
ht->setup(td->cpu);
@@ -147,7 +143,6 @@ static int smpboot_thread_fn(void *data)
continue;
case HP_THREAD_PARKED:
- __set_current_state(TASK_RUNNING);
preempt_enable();
if (ht->unpark)
ht->unpark(td->cpu);
@@ -156,10 +151,10 @@ static int smpboot_thread_fn(void *data)
}
if (!ht->thread_should_run(td->cpu)) {
+ set_current_state(TASK_IDLE);
preempt_enable_no_resched();
schedule();
} else {
- __set_current_state(TASK_RUNNING);
preempt_enable();
ht->thread_fn(td->cpu);
}
next prev parent reply other threads:[~2018-04-24 18:05 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-24 9:28 [PATCH] kthread/smpboot: Serialize kthread parking against wakeup Gaurav Kohli
2018-04-24 14:42 ` Kohli, Gaurav
2018-04-24 18:05 ` Peter Zijlstra [this message]
2018-04-24 18:26 ` Peter Zijlstra
2018-04-24 18:46 ` Kohli, Gaurav
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=20180424180504.GV4043@hirez.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=bigeasy@linutronix.de \
--cc=dzickus@redhat.com \
--cc=gkohli@codeaurora.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=mpe@ellerman.id.au \
--cc=neeraju@codeaurora.org \
--cc=tglx@linutronix.de \
/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