]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
sched: Make __do_set_cpus_allowed() use the sched_change pattern
authorPeter Zijlstra <peterz@infradead.org>
Tue, 9 Sep 2025 11:16:23 +0000 (13:16 +0200)
committerPeter Zijlstra <peterz@infradead.org>
Thu, 16 Oct 2025 09:13:53 +0000 (11:13 +0200)
Now that do_set_cpus_allowed() holds all the regular locks, convert it
to use the sched_change pattern helper.

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Juri Lelli <juri.lelli@redhat.com>
Acked-by: Tejun Heo <tj@kernel.org>
Acked-by: Vincent Guittot <vincent.guittot@linaro.org>
kernel/sched/core.c

index 638bffd4c1a2b3f9b85cbdb633e7990f40437a52..e932439ae6dabe32cfdfb968c4bb7f563c20d0d9 100644 (file)
@@ -2664,28 +2664,12 @@ void set_cpus_allowed_common(struct task_struct *p, struct affinity_context *ctx
 static void
 do_set_cpus_allowed(struct task_struct *p, struct affinity_context *ctx)
 {
-       struct rq *rq = task_rq(p);
-       bool queued, running;
-
-       lockdep_assert_held(&p->pi_lock);
-       lockdep_assert_rq_held(rq);
-
-       queued = task_on_rq_queued(p);
-       running = task_current_donor(rq, p);
-
-       if (queued)
-               dequeue_task(rq, p, DEQUEUE_SAVE | DEQUEUE_NOCLOCK);
+       u32 flags = DEQUEUE_SAVE | DEQUEUE_NOCLOCK;
 
-       if (running)
-               put_prev_task(rq, p);
-
-       p->sched_class->set_cpus_allowed(p, ctx);
-       mm_set_cpus_allowed(p->mm, ctx->new_mask);
-
-       if (queued)
-               enqueue_task(rq, p, ENQUEUE_RESTORE | ENQUEUE_NOCLOCK);
-       if (running)
-               set_next_task(rq, p);
+       scoped_guard (sched_change, p, flags) {
+               p->sched_class->set_cpus_allowed(p, ctx);
+               mm_set_cpus_allowed(p->mm, ctx->new_mask);
+       }
 }
 
 /*