public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Andrea Righi <arighi@nvidia.com>
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>,
	Joel Fernandes <joelagnelf@nvidia.com>, Tejun Heo <tj@kernel.org>,
	David Vernet <void@manifault.com>,
	Changwoo Min <changwoo@igalia.com>, Shuah Khan <shuah@kernel.org>
Cc: sched-ext@lists.linux.dev, bpf@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Luigi De Matteis <ldematteis123@gmail.com>
Subject: [PATCH 06/14] sched_ext: Add a DL server for sched_ext tasks
Date: Fri, 17 Oct 2025 11:25:53 +0200	[thread overview]
Message-ID: <20251017093214.70029-7-arighi@nvidia.com> (raw)
In-Reply-To: <20251017093214.70029-1-arighi@nvidia.com>

From: Joel Fernandes <joelagnelf@nvidia.com>

sched_ext currently suffers starvation due to RT. The same workload when
converted to EXT can get zero runtime if RT is 100% running, causing EXT
processes to stall. Fix it by adding a DL server for EXT.

A kselftest is also provided later to verify:

./runner -t rt_stall
===== START =====
TEST: rt_stall
DESCRIPTION: Verify that RT tasks cannot stall SCHED_EXT tasks
OUTPUT:
TAP version 13
1..1
ok 1 PASS: CFS task got more than 4.00% of runtime

[ arighi: drop ->balance() now that pick_task() has an rf argument ]

Cc: Luigi De Matteis <ldematteis123@gmail.com>
Co-developed-by: Andrea Righi <arighi@nvidia.com>
Signed-off-by: Andrea Righi <arighi@nvidia.com>
Signed-off-by: Joel Fernandes <joelagnelf@nvidia.com>
---
 kernel/sched/core.c     |  3 +++
 kernel/sched/deadline.c |  2 +-
 kernel/sched/ext.c      | 51 +++++++++++++++++++++++++++++++++++++++--
 kernel/sched/sched.h    |  2 ++
 4 files changed, 55 insertions(+), 3 deletions(-)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 096e8d03d85e7..31a9c9381c63f 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -8679,6 +8679,9 @@ void __init sched_init(void)
 		hrtick_rq_init(rq);
 		atomic_set(&rq->nr_iowait, 0);
 		fair_server_init(rq);
+#ifdef CONFIG_SCHED_CLASS_EXT
+		ext_server_init(rq);
+#endif
 
 #ifdef CONFIG_SCHED_CORE
 		rq->core = rq;
diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
index 0680e0186577a..3c1fd2190949e 100644
--- a/kernel/sched/deadline.c
+++ b/kernel/sched/deadline.c
@@ -1504,7 +1504,7 @@ static void update_curr_dl_se(struct rq *rq, struct sched_dl_entity *dl_se, s64
 	 * The fair server (sole dl_server) does not account for real-time
 	 * workload because it is running fair work.
 	 */
-	if (dl_se == &rq->fair_server)
+	if (dl_se->dl_server)
 		return;
 
 #ifdef CONFIG_RT_GROUP_SCHED
diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c
index adff739b396ce..bc2aaa3236fd4 100644
--- a/kernel/sched/ext.c
+++ b/kernel/sched/ext.c
@@ -881,6 +881,9 @@ static void update_curr_scx(struct rq *rq)
 		if (!curr->scx.slice)
 			touch_core_sched(rq, curr);
 	}
+
+	if (dl_server_active(&rq->ext_server))
+		dl_server_update(&rq->ext_server, delta_exec);
 }
 
 static bool scx_dsq_priq_less(struct rb_node *node_a,
@@ -1388,6 +1391,15 @@ static void enqueue_task_scx(struct rq *rq, struct task_struct *p, int enq_flags
 	if (enq_flags & SCX_ENQ_WAKEUP)
 		touch_core_sched(rq, p);
 
+	if (rq->scx.nr_running == 1) {
+		/* Account for idle runtime */
+		if (!rq->nr_running)
+			dl_server_update_idle_time(rq, rq->curr, &rq->ext_server);
+
+		/* Start dl_server if this is the first task being enqueued */
+		dl_server_start(&rq->ext_server);
+	}
+
 	do_enqueue_task(rq, p, enq_flags, sticky_cpu);
 out:
 	rq->scx.flags &= ~SCX_RQ_IN_WAKEUP;
@@ -1487,6 +1499,11 @@ static bool dequeue_task_scx(struct rq *rq, struct task_struct *p, int deq_flags
 	sub_nr_running(rq, 1);
 
 	dispatch_dequeue(rq, p);
+
+	/* Stop the server if this was the last task */
+	if (rq->scx.nr_running == 0)
+		dl_server_stop(&rq->ext_server);
+
 	return true;
 }
 
@@ -2987,6 +3004,15 @@ static void switching_to_scx(struct rq *rq, struct task_struct *p)
 static void switched_from_scx(struct rq *rq, struct task_struct *p)
 {
 	scx_disable_task(p);
+
+	/*
+	 * After class switch, if the DL server is still active, restart it so
+	 * that DL timers will be queued, in case SCX switched to higher class.
+	 */
+	if (dl_server_active(&rq->ext_server)) {
+		dl_server_stop(&rq->ext_server);
+		dl_server_start(&rq->ext_server);
+	}
 }
 
 static void wakeup_preempt_scx(struct rq *rq, struct task_struct *p,int wake_flags) {}
@@ -6498,8 +6524,8 @@ __bpf_kfunc u32 scx_bpf_cpuperf_cur(s32 cpu)
  * relative scale between 0 and %SCX_CPUPERF_ONE. This determines how the
  * schedutil cpufreq governor chooses the target frequency.
  *
- * The actual performance level chosen, CPU grouping, and the overhead and
- * latency of the operations are dependent on the hardware and cpufreq driver in
+ * The actual performance level chosen, CPU grouping, and the overhead and latency
+ * of the operations are dependent on the hardware and cpufreq driver in
  * use. Consult hardware and cpufreq documentation for more information. The
  * current performance level can be monitored using scx_bpf_cpuperf_cur().
  */
@@ -6874,6 +6900,27 @@ BTF_ID_FLAGS(func, scx_bpf_now)
 BTF_ID_FLAGS(func, scx_bpf_events, KF_TRUSTED_ARGS)
 BTF_KFUNCS_END(scx_kfunc_ids_any)
 
+/*
+ * Select the next task to run from the ext scheduling class.
+ */
+static struct task_struct *
+ext_server_pick_task(struct sched_dl_entity *dl_se, struct rq_flags *rf)
+{
+	return pick_task_scx(dl_se->rq, rf);
+}
+
+/*
+ * Initialize the ext server deadline entity.
+ */
+void ext_server_init(struct rq *rq)
+{
+	struct sched_dl_entity *dl_se = &rq->ext_server;
+
+	init_dl_entity(dl_se);
+
+	dl_server_init(dl_se, rq, ext_server_pick_task);
+}
+
 static const struct btf_kfunc_id_set scx_kfunc_set_any = {
 	.owner			= THIS_MODULE,
 	.set			= &scx_kfunc_ids_any,
diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index fa2fb64c1f3bf..55f8fbb306517 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -415,6 +415,7 @@ extern void dl_server_update_idle_time(struct rq *rq,
 		    struct task_struct *p,
 		    struct sched_dl_entity *rq_dl_server);
 extern void fair_server_init(struct rq *rq);
+extern void ext_server_init(struct rq *rq);
 extern void __dl_server_attach_root(struct sched_dl_entity *dl_se, struct rq *rq);
 extern int dl_server_apply_params(struct sched_dl_entity *dl_se,
 		    u64 runtime, u64 period, bool init);
@@ -1153,6 +1154,7 @@ struct rq {
 #endif
 
 	struct sched_dl_entity	fair_server;
+	struct sched_dl_entity	ext_server;
 
 #ifdef CONFIG_FAIR_GROUP_SCHED
 	/* list of leaf cfs_rq on this CPU: */
-- 
2.51.0


  parent reply	other threads:[~2025-10-17  9:33 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-17  9:25 [PATCHSET v9 sched_ext/for-6.19] Add a deadline server for sched_ext tasks Andrea Righi
2025-10-17  9:25 ` [PATCH 01/14] sched/debug: Fix updating of ppos on server write ops Andrea Righi
2025-10-20  8:36   ` Juri Lelli
2025-10-17  9:25 ` [PATCH 02/14] sched/debug: Stop and start server based on if it was active Andrea Righi
2025-10-20  9:12   ` Juri Lelli
2025-10-20  9:27     ` Juri Lelli
2025-10-17  9:25 ` [PATCH 03/14] sched/deadline: Clear the defer params Andrea Righi
2025-10-17  9:25 ` [PATCH 04/14] sched/deadline: Return EBUSY if dl_bw_cpus is zero Andrea Righi
2025-10-20  9:49   ` Juri Lelli
2025-10-20 13:38     ` Andrea Righi
2025-10-20 14:03       ` Andrea Righi
2025-10-20 14:12         ` Juri Lelli
2025-10-17  9:25 ` [PATCH 05/14] sched: Add a server arg to dl_server_update_idle_time() Andrea Righi
2025-10-20  9:54   ` Juri Lelli
2025-10-20 12:49   ` Peter Zijlstra
2025-10-17  9:25 ` Andrea Righi [this message]
2025-10-17 15:40   ` [PATCH 06/14] sched_ext: Add a DL server for sched_ext tasks Tejun Heo
2025-10-17 19:00     ` Andrea Righi
2025-10-17 15:47   ` Tejun Heo
2025-10-17 18:58     ` Andrea Righi
2025-10-17 19:04       ` Tejun Heo
2025-10-17 19:06         ` Andrea Righi
2025-10-20 11:58   ` Juri Lelli
2025-10-20 13:50     ` Andrea Righi
2025-10-20 14:09       ` Juri Lelli
2025-10-17  9:25 ` [PATCH 07/14] sched/debug: Add support to change sched_ext server params Andrea Righi
2025-10-20 12:45   ` Juri Lelli
2025-10-21  6:23     ` Andrea Righi
2025-10-17  9:25 ` [PATCH 08/14] sched/deadline: Add support to remove DL server's bandwidth contribution Andrea Righi
2025-10-20 13:46   ` Juri Lelli
2025-10-17  9:25 ` [PATCH 09/14] sched/deadline: Account ext server bandwidth Andrea Righi
2025-10-17  9:25 ` [PATCH 10/14] sched/deadline: Allow to initialize DL server when needed Andrea Righi
2025-10-17  9:25 ` [PATCH 11/14] sched/deadline: Fix DL server crash in inactive_timer callback Andrea Righi
2025-10-17  9:25 ` [PATCH 12/14] sched_ext: Selectively enable ext and fair DL servers Andrea Righi
2025-10-17  9:26 ` [PATCH 13/14] selftests/sched_ext: Add test for sched_ext dl_server Andrea Righi
2025-10-19 19:04   ` Emil Tsalapatis
2025-10-20 13:22     ` Andrea Righi
2025-10-20 13:44       ` Andrea Righi
2025-10-20 13:26   ` Christian Loehle
2025-10-20 13:55     ` Andrea Righi
2025-10-20 14:00       ` Andrea Righi
2025-10-20 14:21       ` Christian Loehle
2025-10-23 15:01         ` Christian Loehle
2025-10-23 15:11           ` Andrea Righi
2025-10-17  9:26 ` [PATCH 14/14] selftests/sched_ext: Add test for DL server total_bw consistency Andrea Righi

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=20251017093214.70029-7-arighi@nvidia.com \
    --to=arighi@nvidia.com \
    --cc=bpf@vger.kernel.org \
    --cc=bsegall@google.com \
    --cc=changwoo@igalia.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=joelagnelf@nvidia.com \
    --cc=juri.lelli@redhat.com \
    --cc=ldematteis123@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mgorman@suse.de \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=sched-ext@lists.linux.dev \
    --cc=shuah@kernel.org \
    --cc=tj@kernel.org \
    --cc=vincent.guittot@linaro.org \
    --cc=void@manifault.com \
    --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