Skip to content

Commit f83ee19

Browse files
Peter Zijlstraingomolnar
authored andcommitted
kthread: Simplify kthread_park() completion
Oleg explains the reason we could hit park+park is that smpboot_update_cpumask_percpu_thread()'s for_each_cpu_and(cpu, &tmp, cpu_online_mask) smpboot_park_kthread(); turns into: for ((cpu) = 0; (cpu) < 1; (cpu)++, (void)mask, (void)and) smpboot_park_kthread(); on UP, ignoring the mask. But since we just completely removed that function, this is no longer relevant. So revert commit: b1f5b37 ("kthread: Allow kthread_park() on a parked kthread") Suggested-by: Oleg Nesterov <oleg@redhat.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: linux-kernel@vger.kernel.org Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent 167a886 commit f83ee19

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

‎kernel/kthread.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ static void __kthread_parkme(struct kthread *self)
190190
if (!test_bit(KTHREAD_SHOULD_PARK, &self->flags))
191191
break;
192192

193-
complete_all(&self->parked);
193+
complete(&self->parked);
194194
schedule();
195195
}
196196
__set_current_state(TASK_RUNNING);
@@ -465,7 +465,6 @@ void kthread_unpark(struct task_struct *k)
465465
if (test_bit(KTHREAD_IS_PER_CPU, &kthread->flags))
466466
__kthread_bind(k, kthread->cpu, TASK_PARKED);
467467

468-
reinit_completion(&kthread->parked);
469468
clear_bit(KTHREAD_SHOULD_PARK, &kthread->flags);
470469
/*
471470
* __kthread_parkme() will either see !SHOULD_PARK or get the wakeup.
@@ -493,6 +492,9 @@ int kthread_park(struct task_struct *k)
493492
if (WARN_ON(k->flags & PF_EXITING))
494493
return -ENOSYS;
495494

495+
if (WARN_ON_ONCE(test_bit(KTHREAD_SHOULD_PARK, &kthread->flags)))
496+
return -EBUSY;
497+
496498
set_bit(KTHREAD_SHOULD_PARK, &kthread->flags);
497499
if (k != current) {
498500
wake_up_process(k);

0 commit comments

Comments
 (0)