Skip to content

Commit 58b1a45

Browse files
Peter ZijlstraIngo Molnar
authored andcommitted
sched: Collate affine_move_task() stoppers
The SCA_MIGRATE_ENABLE and task_running() cases are almost identical, collapse them to avoid further duplication. Fixes: 6d337ea ("sched: Fix migrate_disable() vs set_cpus_allowed_ptr()") Cc: [email protected] Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Reviewed-by: Valentin Schneider <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent c20cf06 commit 58b1a45

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

kernel/sched/core.c

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2239,30 +2239,23 @@ static int affine_move_task(struct rq *rq, struct task_struct *p, struct rq_flag
22392239
return -EINVAL;
22402240
}
22412241

2242-
if (flags & SCA_MIGRATE_ENABLE) {
2243-
2244-
refcount_inc(&pending->refs); /* pending->{arg,stop_work} */
2245-
p->migration_flags &= ~MDF_PUSH;
2246-
task_rq_unlock(rq, p, rf);
2247-
2248-
stop_one_cpu_nowait(cpu_of(rq), migration_cpu_stop,
2249-
&pending->arg, &pending->stop_work);
2250-
2251-
return 0;
2252-
}
2253-
22542242
if (task_running(rq, p) || p->state == TASK_WAKING) {
22552243
/*
2256-
* Lessen races (and headaches) by delegating
2257-
* is_migration_disabled(p) checks to the stopper, which will
2258-
* run on the same CPU as said p.
2244+
* MIGRATE_ENABLE gets here because 'p == current', but for
2245+
* anything else we cannot do is_migration_disabled(), punt
2246+
* and have the stopper function handle it all race-free.
22592247
*/
2248+
22602249
refcount_inc(&pending->refs); /* pending->{arg,stop_work} */
2250+
if (flags & SCA_MIGRATE_ENABLE)
2251+
p->migration_flags &= ~MDF_PUSH;
22612252
task_rq_unlock(rq, p, rf);
22622253

22632254
stop_one_cpu_nowait(cpu_of(rq), migration_cpu_stop,
22642255
&pending->arg, &pending->stop_work);
22652256

2257+
if (flags & SCA_MIGRATE_ENABLE)
2258+
return 0;
22662259
} else {
22672260

22682261
if (!is_migration_disabled(p)) {

0 commit comments

Comments
 (0)