Commit
5ba2ffba13a1 ("sched: Fix CPU hotplug / tighten is_per_cpu_kthread()")
had to special-case the idle task when checking for per-CPU kthreads. This is
due to the idle task not having its own struct kthread, which is where we'd
store KTHREAD_IS_PER_CPU.
From staring at Yejune's recent patch [1], it turns out the idle task is also
missing PF_NO_SETAFFINITY.
Patch 1 cleans this up, patch 2 is Yejune's v1 which depends on it.
Note: I remember seeing some patch(es) from Peter tackling this exact
problem, but I couldn't find them again.
[1]: http://lore.kernel.org/r/[email protected]
Cheers,
Valentin
Valentin Schneider (1):
sched: Make the idle task quack like a per-CPU kthread
Yejune Deng (1):
lib/smp_processor_id: Use is_percpu_thread() instead of
nr_cpus_allowed
include/linux/kthread.h | 2 ++
kernel/kthread.c | 30 ++++++++++++++++++------------
kernel/sched/core.c | 21 +++++++++++++++------
lib/smp_processor_id.c | 6 +-----
4 files changed, 36 insertions(+), 23 deletions(-)
--
2.25.1
From: Yejune Deng <[email protected]>
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 <[email protected]>
[Amended changelog]
Signed-off-by: Valentin Schneider <[email protected]>
---
lib/smp_processor_id.c | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
diff --git a/lib/smp_processor_id.c b/lib/smp_processor_id.c
index 1c1dbd300325..046ac6297c78 100644
--- a/lib/smp_processor_id.c
+++ b/lib/smp_processor_id.c
@@ -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
--
2.25.1
On Mon, May 10, 2021 at 04:10:22PM +0100, Valentin Schneider wrote:
> Note: I remember seeing some patch(es) from Peter tackling this exact
> problem, but I couldn't find them again.
Found it (by accident), yours is nicer though :-)
> Valentin Schneider (1):
> sched: Make the idle task quack like a per-CPU kthread
>
> Yejune Deng (1):
> lib/smp_processor_id: Use is_percpu_thread() instead of
> nr_cpus_allowed
>
> include/linux/kthread.h | 2 ++
> kernel/kthread.c | 30 ++++++++++++++++++------------
> kernel/sched/core.c | 21 +++++++++++++++------
> lib/smp_processor_id.c | 6 +-----
> 4 files changed, 36 insertions(+), 23 deletions(-)
Thanks!
The following commit has been merged into the sched/core branch of tip:
Commit-ID: 0019699518cc026b5bd912425be8e424843d5b33
Gitweb: https://git.kernel.org/tip/0019699518cc026b5bd912425be8e424843d5b33
Author: Yejune Deng <[email protected]>
AuthorDate: Mon, 10 May 2021 16:10:24 +01:00
Committer: Peter Zijlstra <[email protected]>
CommitterDate: Tue, 18 May 2021 12:53:54 +02:00
lib/smp_processor_id: Use is_percpu_thread() instead of nr_cpus_allowed
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().
[Amended changelog]
Signed-off-by: Valentin Schneider <[email protected]>
Signed-off-by: Yejune Deng <[email protected]>
Signed-off-by: Peter Zijlstra (Intel) <[email protected]>
Link: https://lkml.kernel.org/r/[email protected]
---
lib/smp_processor_id.c | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
diff --git a/lib/smp_processor_id.c b/lib/smp_processor_id.c
index 1c1dbd3..046ac62 100644
--- a/lib/smp_processor_id.c
+++ b/lib/smp_processor_id.c
@@ -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
The following commit has been merged into the sched/core branch of tip:
Commit-ID: 570a752b7a9bd03b50ad6420cd7f10092cc11bd3
Gitweb: https://git.kernel.org/tip/570a752b7a9bd03b50ad6420cd7f10092cc11bd3
Author: Yejune Deng <[email protected]>
AuthorDate: Mon, 10 May 2021 16:10:24 +01:00
Committer: Peter Zijlstra <[email protected]>
CommitterDate: Wed, 19 May 2021 10:51:40 +02:00
lib/smp_processor_id: Use is_percpu_thread() instead of nr_cpus_allowed
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 <[email protected]>
[Amended changelog]
Signed-off-by: Valentin Schneider <[email protected]>
Signed-off-by: Peter Zijlstra (Intel) <[email protected]>
Link: https://lkml.kernel.org/r/[email protected]
---
lib/smp_processor_id.c | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
diff --git a/lib/smp_processor_id.c b/lib/smp_processor_id.c
index 1c1dbd3..046ac62 100644
--- a/lib/smp_processor_id.c
+++ b/lib/smp_processor_id.c
@@ -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