[PATCH v3 1/3] sched: Give root domain moves their own sched_class callbacks

From: Qiliang Yuan

Date: Fri Nov 20 2026 - 21:57:52 EST


The rq_online() and rq_offline() callbacks run when a CPU comes up or
goes down, and also when rq_attach_root() moves an active CPU to a new
root domain during a sched domain rebuild. rt and dl use them for state
kept in the root domain: the overload masks, cpupri, cpudl and the RT
runtime shared within it. fair uses them for task group state, which
does not depend on the root domain.

With one pair of callbacks for both events, a class cannot do only the
work that a root domain move needs, so every rebuild runs the fair
hotplug work for all active CPUs.

Add rq_attach_root() and rq_detach_root() to struct sched_class for the
root domain state and convert rt and dl to them. Have set_rq_online()
and set_rq_offline() call both kinds of callbacks class by class, so
that every class still runs at the same points and in the same order.

Suggested-by: K Prateek Nayak <kprateek.nayak@xxxxxxx>
Signed-off-by: Qiliang Yuan <qiliang.yuan@xxxxxxxxx>
---
kernel/sched/core.c | 4 ++++
kernel/sched/cpudeadline.c | 5 +++--
kernel/sched/deadline.c | 8 ++++----
kernel/sched/rt.c | 8 ++++----
kernel/sched/sched.h | 6 ++++++
5 files changed, 21 insertions(+), 10 deletions(-)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 8b4e4a6f4ae02..ca920a302ecba 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -8553,6 +8553,8 @@ void set_rq_online(struct rq *rq)
rq->online = 1;

for_each_class(class) {
+ if (class->rq_attach_root)
+ class->rq_attach_root(rq);
if (class->rq_online)
class->rq_online(rq);
}
@@ -8569,6 +8571,8 @@ void set_rq_offline(struct rq *rq)
for_each_class(class) {
if (class->rq_offline)
class->rq_offline(rq);
+ if (class->rq_detach_root)
+ class->rq_detach_root(rq);
}

cpumask_clear_cpu(rq->cpu, rd->online);
diff --git a/kernel/sched/cpudeadline.c b/kernel/sched/cpudeadline.c
index 0a2b7e30fd10c..8e2a95f846278 100644
--- a/kernel/sched/cpudeadline.c
+++ b/kernel/sched/cpudeadline.c
@@ -185,8 +185,9 @@ void cpudl_clear(struct cpudl *cp, int cpu, bool online)
if (old_idx == IDX_INVALID) {
/*
* Nothing to remove if old_idx was invalid.
- * This could happen if rq_online_dl or rq_offline_dl is
- * called for a CPU without -dl tasks running.
+ * This could happen if rq_attach_root_dl() or
+ * rq_detach_root_dl() is called for a CPU without -dl
+ * tasks running.
*/
} else {
new_cpu = cp->elements[cp->size - 1].cpu;
diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
index 61b6a6d781715..fcbf53500083e 100644
--- a/kernel/sched/deadline.c
+++ b/kernel/sched/deadline.c
@@ -3366,7 +3366,7 @@ bool dl_task_needs_bw_move(struct task_struct *p,
}

/* Assumes rq->lock is held */
-static void rq_online_dl(struct rq *rq)
+static void rq_attach_root_dl(struct rq *rq)
{
if (rq->dl.overloaded)
dl_set_overload(rq);
@@ -3379,7 +3379,7 @@ static void rq_online_dl(struct rq *rq)
}

/* Assumes rq->lock is held */
-static void rq_offline_dl(struct rq *rq)
+static void rq_detach_root_dl(struct rq *rq)
{
if (rq->dl.overloaded)
dl_clear_overload(rq);
@@ -3664,8 +3664,8 @@ DEFINE_SCHED_CLASS(dl) = {
.select_task_rq = select_task_rq_dl,
.migrate_task_rq = migrate_task_rq_dl,
.set_cpus_allowed = set_cpus_allowed_dl,
- .rq_online = rq_online_dl,
- .rq_offline = rq_offline_dl,
+ .rq_attach_root = rq_attach_root_dl,
+ .rq_detach_root = rq_detach_root_dl,
.task_woken = task_woken_dl,
.find_lock_rq = find_lock_later_rq,

diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c
index 81a71aa5f094a..45d10334f7253 100644
--- a/kernel/sched/rt.c
+++ b/kernel/sched/rt.c
@@ -2398,7 +2398,7 @@ static void task_woken_rt(struct rq *rq, struct task_struct *p)
}

/* Assumes rq->lock is held */
-static void rq_online_rt(struct rq *rq)
+static void rq_attach_root_rt(struct rq *rq)
{
if (rq->rt.overloaded)
rt_set_overload(rq);
@@ -2409,7 +2409,7 @@ static void rq_online_rt(struct rq *rq)
}

/* Assumes rq->lock is held */
-static void rq_offline_rt(struct rq *rq)
+static void rq_detach_root_rt(struct rq *rq)
{
if (rq->rt.overloaded)
rt_clear_overload(rq);
@@ -2626,8 +2626,8 @@ DEFINE_SCHED_CLASS(rt) = {
.balance = balance_rt,
.select_task_rq = select_task_rq_rt,
.set_cpus_allowed = set_cpus_allowed_common,
- .rq_online = rq_online_rt,
- .rq_offline = rq_offline_rt,
+ .rq_attach_root = rq_attach_root_rt,
+ .rq_detach_root = rq_detach_root_rt,
.task_woken = task_woken_rt,
.switched_from = switched_from_rt,
.find_lock_rq = find_lock_lowest_rq,
diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index e957524c3ee52..a24801d2058b4 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -2799,6 +2799,12 @@ struct sched_class {
void (*rq_online)(struct rq *rq);
void (*rq_offline)(struct rq *rq);

+ /*
+ * Move an online rq to or from a root domain: rq->lock
+ */
+ void (*rq_attach_root)(struct rq *rq);
+ void (*rq_detach_root)(struct rq *rq);
+
/*
* push_cpu_stop: p->pi_lock && rq->lock
*/

--
2.43.0