]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
sched: Move attach_one_task and attach_task helpers to sched.h
authorJohn Stultz <jstultz@google.com>
Tue, 24 Mar 2026 19:13:24 +0000 (19:13 +0000)
committerPeter Zijlstra <peterz@infradead.org>
Fri, 3 Apr 2026 12:23:40 +0000 (14:23 +0200)
The fair scheduler locally introduced attach_one_task() and
attach_task() helpers, but these could be generically useful so
move this code to sched.h so we can use them elsewhere.

One minor tweak made to utilize guard(rq_lock)(rq) to simplifiy
the function.

Suggested-by: K Prateek Nayak <kprateek.nayak@amd.com>
Signed-off-by: John Stultz <jstultz@google.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: K Prateek Nayak <kprateek.nayak@amd.com>
Link: https://patch.msgid.link/20260324191337.1841376-10-jstultz@google.com
kernel/sched/fair.c
kernel/sched/sched.h

index 7f35dd40d7efb9e86d93230f031ef1164bb68854..41293d5d9b75c805bdd7b217bc35b08611626506 100644 (file)
@@ -9946,32 +9946,6 @@ next:
        return detached;
 }
 
-/*
- * attach_task() -- attach the task detached by detach_task() to its new rq.
- */
-static void attach_task(struct rq *rq, struct task_struct *p)
-{
-       lockdep_assert_rq_held(rq);
-
-       WARN_ON_ONCE(task_rq(p) != rq);
-       activate_task(rq, p, ENQUEUE_NOCLOCK);
-       wakeup_preempt(rq, p, 0);
-}
-
-/*
- * attach_one_task() -- attaches the task returned from detach_one_task() to
- * its new rq.
- */
-static void attach_one_task(struct rq *rq, struct task_struct *p)
-{
-       struct rq_flags rf;
-
-       rq_lock(rq, &rf);
-       update_rq_clock(rq);
-       attach_task(rq, p);
-       rq_unlock(rq, &rf);
-}
-
 /*
  * attach_tasks() -- attaches all tasks detached by detach_tasks() to their
  * new rq.
index a2629d025c9094e01d66ff0bff66e9d1b6d43430..9594355a36811cc742c7c83de7941dac306771e4 100644 (file)
@@ -3012,6 +3012,29 @@ extern void deactivate_task(struct rq *rq, struct task_struct *p, int flags);
 
 extern void wakeup_preempt(struct rq *rq, struct task_struct *p, int flags);
 
+/*
+ * attach_task() -- attach the task detached by detach_task() to its new rq.
+ */
+static inline void attach_task(struct rq *rq, struct task_struct *p)
+{
+       lockdep_assert_rq_held(rq);
+
+       WARN_ON_ONCE(task_rq(p) != rq);
+       activate_task(rq, p, ENQUEUE_NOCLOCK);
+       wakeup_preempt(rq, p, 0);
+}
+
+/*
+ * attach_one_task() -- attaches the task returned from detach_one_task() to
+ * its new rq.
+ */
+static inline void attach_one_task(struct rq *rq, struct task_struct *p)
+{
+       guard(rq_lock)(rq);
+       update_rq_clock(rq);
+       attach_task(rq, p);
+}
+
 #ifdef CONFIG_PREEMPT_RT
 # define SCHED_NR_MIGRATE_BREAK 8
 #else