Skip to content

Commit accaf6e

Browse files
oleg-nesterovingomolnar
authored andcommitted
stop_machine: Clean up the usage of the preemption counter in cpu_stopper_thread()
1. Change this code to use preempt_count_inc/preempt_count_dec; this way it works even if CONFIG_PREEMPT_COUNT=n, and we avoid the unnecessary __preempt_schedule() check (stop_sched_class is not preemptible). And this makes clear that we only want to make preempt_count() != 0 for __might_sleep() / schedule_debug(). 2. Change WARN_ONCE() to use %pf to print the function name and remove kallsyms_lookup/ksym_buf. 3. Move "int ret" into the "if (work)" block, this looks more consistent. Signed-off-by: Oleg Nesterov <oleg@redhat.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Acked-by: Tejun Heo <tj@kernel.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Mike Galbraith <efault@gmx.de> Cc: Milos Vyletel <milos@redhat.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Prarit Bhargava <prarit@redhat.com> Cc: Thomas Gleixner <tglx@linutronix.de> Link: http://lkml.kernel.org/r/20151115193332.GA8281@redhat.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent dd2e312 commit accaf6e

1 file changed

Lines changed: 5 additions & 10 deletions

File tree

‎kernel/stop_machine.c‎

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,6 @@ static void cpu_stopper_thread(unsigned int cpu)
435435
{
436436
struct cpu_stopper *stopper = &per_cpu(cpu_stopper, cpu);
437437
struct cpu_stop_work *work;
438-
int ret;
439438

440439
repeat:
441440
work = NULL;
@@ -451,23 +450,19 @@ static void cpu_stopper_thread(unsigned int cpu)
451450
cpu_stop_fn_t fn = work->fn;
452451
void *arg = work->arg;
453452
struct cpu_stop_done *done = work->done;
454-
char ksym_buf[KSYM_NAME_LEN] __maybe_unused;
453+
int ret;
455454

456-
/* cpu stop callbacks are not allowed to sleep */
457-
preempt_disable();
455+
/* cpu stop callbacks must not sleep, make in_atomic() == T */
456+
preempt_count_inc();
458457
ret = fn(arg);
459458
if (done) {
460459
if (ret)
461460
done->ret = ret;
462461
cpu_stop_signal_done(done);
463462
}
464-
/* restore preemption and check it's still balanced */
465-
preempt_enable();
463+
preempt_count_dec();
466464
WARN_ONCE(preempt_count(),
467-
"cpu_stop: %s(%p) leaked preempt count\n",
468-
kallsyms_lookup((unsigned long)fn, NULL, NULL, NULL,
469-
ksym_buf), arg);
470-
465+
"cpu_stop: %pf(%p) leaked preempt count\n", fn, arg);
471466
goto repeat;
472467
}
473468
}

0 commit comments

Comments
 (0)