mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Qiliang Yuan <qiliang.yuan@linux.dev>
To: Ingo Molnar <mingo@redhat.com>,
	Peter Zijlstra <peterz@infradead.org>,
	 Juri Lelli <juri.lelli@redhat.com>,
	 Vincent Guittot <vincent.guittot@linaro.org>,
	 Dietmar Eggemann <dietmar.eggemann@arm.com>,
	 Steven Rostedt <rostedt@goodmis.org>,
	Ben Segall <bsegall@google.com>,  Mel Gorman <mgorman@suse.de>,
	Valentin Schneider <vschneid@redhat.com>,
	 K Prateek Nayak <kprateek.nayak@amd.com>
Cc: Li kunyu <likunyu@open-hieco.net>,
	linux-kernel@vger.kernel.org,
	 Qiliang Yuan <qiliang.yuan@linux.dev>
Subject: [PATCH v3 1/3] sched: Give root domain moves their own sched_class callbacks
Date: Fri, 20 Nov 2026 21:57:24 -0500	[thread overview]
Message-ID: <20261120-bug-sched-fair-offline-active-v3-1-325e9eefa56d@linux.dev> (raw)
In-Reply-To: <20261120-bug-sched-fair-offline-active-v3-0-325e9eefa56d@linux.dev>

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@amd.com>
Signed-off-by: Qiliang Yuan <qiliang.yuan@linux.dev>
---
 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


  reply	other threads:[~2026-11-21  2:57 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-21  2:57 [PATCH v3 0/3] sched/fair: Cut per-group work from sched domain rebuilds Qiliang Yuan
2026-11-21  2:57 ` Qiliang Yuan [this message]
2026-11-21  2:57 ` [PATCH v3 2/3] sched: Keep CPUs that stay active online across root domain moves Qiliang Yuan
2026-11-21  2:57 ` [PATCH v3 3/3] sched/fair: Drop the active CPU check from unthrottle_offline_cfs_rqs() Qiliang Yuan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261120-bug-sched-fair-offline-active-v3-1-325e9eefa56d@linux.dev \
    --to=qiliang.yuan@linux.dev \
    --cc=bsegall@google.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=juri.lelli@redhat.com \
    --cc=kprateek.nayak@amd.com \
    --cc=likunyu@open-hieco.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mgorman@suse.de \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=vincent.guittot@linaro.org \
    --cc=vschneid@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®