Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

sched: Simplify migration_cpu_stop()

Since, when ->stop_pending, only the stopper can uninstall
p->migration_pending. This could simplify a few ifs, because:

(pending != NULL) => (pending == p->migration_pending)

Also, the fatty comment above affine_move_task() probably needs a bit
of gardening.

Signed-off-by: Valentin Schneider <valentin.schneider@arm.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>

authored by

Valentin Schneider and committed by
Ingo Molnar
e140749c ce29ddc4

+18 -9
+18 -9
kernel/sched/core.c
··· 1927 1927 rq_lock(rq, &rf); 1928 1928 1929 1929 /* 1930 + * If we were passed a pending, then ->stop_pending was set, thus 1931 + * p->migration_pending must have remained stable. 1932 + */ 1933 + WARN_ON_ONCE(pending && pending != p->migration_pending); 1934 + 1935 + /* 1930 1936 * If task_rq(p) != rq, it cannot be migrated here, because we're 1931 1937 * holding rq->lock, if p->on_rq == 0 it cannot get enqueued because 1932 1938 * we're holding p->pi_lock. ··· 1942 1936 goto out; 1943 1937 1944 1938 if (pending) { 1945 - if (p->migration_pending == pending) 1946 - p->migration_pending = NULL; 1939 + p->migration_pending = NULL; 1947 1940 complete = true; 1948 1941 } 1949 1942 ··· 1981 1976 * somewhere allowed, we're done. 1982 1977 */ 1983 1978 if (cpumask_test_cpu(task_cpu(p), p->cpus_ptr)) { 1984 - if (p->migration_pending == pending) 1985 - p->migration_pending = NULL; 1979 + p->migration_pending = NULL; 1986 1980 complete = true; 1987 1981 goto out; 1988 1982 } ··· 2169 2165 * 2170 2166 * (1) In the cases covered above. There is one more where the completion is 2171 2167 * signaled within affine_move_task() itself: when a subsequent affinity request 2172 - * cancels the need for an active migration. Consider: 2168 + * occurs after the stopper bailed out due to the targeted task still being 2169 + * Migrate-Disable. Consider: 2173 2170 * 2174 2171 * Initial conditions: P0->cpus_mask = [0, 1] 2175 2172 * 2176 - * P0@CPU0 P1 P2 2177 - * 2178 - * migrate_disable(); 2179 - * <preempted> 2173 + * CPU0 P1 P2 2174 + * <P0> 2175 + * migrate_disable(); 2176 + * <preempted> 2180 2177 * set_cpus_allowed_ptr(P0, [1]); 2181 2178 * <blocks> 2179 + * <migration/0> 2180 + * migration_cpu_stop() 2181 + * is_migration_disabled() 2182 + * <bails> 2182 2183 * set_cpus_allowed_ptr(P0, [0, 1]); 2183 2184 * <signal completion> 2184 2185 * <awakes>