Skip to content

Commit 741ba80

Browse files
author
Peter Zijlstra
committed
sched: Relax the set_cpus_allowed_ptr() semantics
Now that we have KTHREAD_IS_PER_CPU to denote the critical per-cpu tasks to retain during CPU offline, we can relax the warning in set_cpus_allowed_ptr(). Any spurious kthread that wants to get on at the last minute will get pushed off before it can run. While during CPU online there is no harm, and actual benefit, to allowing kthreads back on early, it simplifies hotplug code and fixes a number of outstanding races. Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Reviewed-by: Lai jiangshan <[email protected]> Reviewed-by: Valentin Schneider <[email protected]> Tested-by: Valentin Schneider <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 5ba2ffb commit 741ba80

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

kernel/sched/core.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2342,7 +2342,9 @@ static int __set_cpus_allowed_ptr(struct task_struct *p,
23422342

23432343
if (p->flags & PF_KTHREAD || is_migration_disabled(p)) {
23442344
/*
2345-
* Kernel threads are allowed on online && !active CPUs.
2345+
* Kernel threads are allowed on online && !active CPUs,
2346+
* however, during cpu-hot-unplug, even these might get pushed
2347+
* away if not KTHREAD_IS_PER_CPU.
23462348
*
23472349
* Specifically, migration_disabled() tasks must not fail the
23482350
* cpumask_any_and_distribute() pick below, esp. so on
@@ -2386,16 +2388,6 @@ static int __set_cpus_allowed_ptr(struct task_struct *p,
23862388

23872389
__do_set_cpus_allowed(p, new_mask, flags);
23882390

2389-
if (p->flags & PF_KTHREAD) {
2390-
/*
2391-
* For kernel threads that do indeed end up on online &&
2392-
* !active we want to ensure they are strict per-CPU threads.
2393-
*/
2394-
WARN_ON(cpumask_intersects(new_mask, cpu_online_mask) &&
2395-
!cpumask_intersects(new_mask, cpu_active_mask) &&
2396-
p->nr_cpus_allowed != 1);
2397-
}
2398-
23992391
return affine_move_task(rq, p, &rf, dest_cpu, flags);
24002392

24012393
out:
@@ -7518,6 +7510,13 @@ int sched_cpu_deactivate(unsigned int cpu)
75187510
int ret;
75197511

75207512
set_cpu_active(cpu, false);
7513+
7514+
/*
7515+
* From this point forward, this CPU will refuse to run any task that
7516+
* is not: migrate_disable() or KTHREAD_IS_PER_CPU, and will actively
7517+
* push those tasks away until this gets cleared, see
7518+
* sched_cpu_dying().
7519+
*/
75217520
balance_push_set(cpu, true);
75227521

75237522
/*

0 commit comments

Comments
 (0)