Skip to content

Commit

Permalink
lib/smp_processor_id: Use is_percpu_thread() instead of nr_cpus_allowed
Browse files Browse the repository at this point in the history
is_percpu_thread() more elegantly handles SMP vs UP, and further checks the
presence of PF_NO_SETAFFINITY. This lets us catch cases where
check_preemption_disabled() can race with a concurrent sched_setaffinity().

Signed-off-by: Yejune Deng <yejune.deng@gmail.com>
[Amended changelog]
Signed-off-by: Valentin Schneider <valentin.schneider@arm.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/20210510151024.2448573-3-valentin.schneider@arm.com
  • Loading branch information
Yejune Deng authored and Peter Zijlstra committed May 19, 2021
1 parent 00b89fe commit 570a752
Showing 1 changed file with 1 addition and 5 deletions.
6 changes: 1 addition & 5 deletions lib/smp_processor_id.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@ unsigned int check_preemption_disabled(const char *what1, const char *what2)
if (irqs_disabled())
goto out;

/*
* Kernel threads bound to a single CPU can safely use
* smp_processor_id():
*/
if (current->nr_cpus_allowed == 1)
if (is_percpu_thread())
goto out;

#ifdef CONFIG_SMP
Expand Down

0 comments on commit 570a752

Please sign in to comment.