mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Fernand Sieber <sieberf@amazon.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Fernand Sieber <sieberf@amazon.com>,
	Karl Mehltretter <kmehltretter@gmail.com>,
	<stable@vger.kernel.org>, Ingo Molnar <mingo@redhat.com>,
	Juri Lelli <juri.lelli@redhat.com>,
	Vincent Guittot <vincent.guittot@linaro.org>,
	Shuah Khan <shuah@kernel.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>,
	"Daniel Bristot de Oliveira" <bristot@kernel.org>,
	Joel Fernandes <joelagnelf@nvidia.com>,
	Josh Don <joshdon@google.com>, <linux-kernel@vger.kernel.org>,
	<linux-kselftest@vger.kernel.org>, <nh-open-source@amazon.com>,
	Fahad Mubeen <fmubeen@amazon.de>,
	"David Woodhouse" <dwmw@amazon.co.uk>,
	Misha Karataiev <karataev@amazon.com>,
	Hendrik Borghorst <hborghor@amazon.de>,
	Ibrahim Elshahed <lshahed@amazon.de>
Subject: [PATCH 2/2] selftests/sched: Let the FIFO task block in cs_dl_server_test
Date: Tue, 24 Nov 2026 11:40:31 +0200	[thread overview]
Message-ID: <0bea929ef61909f5eb5038d111027e1d5e710fee.1795510960.git.sieberf@amazon.com> (raw)
In-Reply-To: <cover.1795510960.git.sieberf@amazon.com>

The FIFO child of cs_dl_server_test never blocks, so forced idle on its
sibling only ends through the fair server's pick. The test therefore
missed forced idle charged to the fair server when the cookied task
blocks and the sibling's core-wide pick ends forced idle.

Run the test a second time with the FIFO child spinning 800us and
sleeping 10us, and hold that pass to the same floor of half the fair
server's reservation.

Reported-by: Karl Mehltretter <kmehltretter@gmail.com>
Closes: https://lore.kernel.org/all/20261124080737.1988-1-kmehltretter@gmail.com/
Signed-off-by: Fernand Sieber <sieberf@amazon.com>
---
 .../selftests/sched/cs_dl_server_test.c       | 107 +++++++++++-------
 1 file changed, 68 insertions(+), 39 deletions(-)

diff --git a/tools/testing/selftests/sched/cs_dl_server_test.c b/tools/testing/selftests/sched/cs_dl_server_test.c
index 38aa005080f1f..c085f7059e054 100644
--- a/tools/testing/selftests/sched/cs_dl_server_test.c
+++ b/tools/testing/selftests/sched/cs_dl_server_test.c
@@ -14,6 +14,10 @@
  * whenever the FIFO task runs, and checks that the CFS task still gets a
  * sensible fraction of the fair server's reservation.
  *
+ * A second pass lets the FIFO task sleep briefly between spins, so forced idle
+ * mostly ends through the core-wide pick made when the FIFO task blocks rather
+ * than through the fair server.
+ *
  * Copyright (c) 2026 Amazon.com, Inc. or its affiliates.
  */
 #define _GNU_SOURCE
@@ -21,6 +25,7 @@
 #include <limits.h>
 #include <sched.h>
 #include <signal.h>
+#include <stdbool.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -48,6 +53,8 @@ enum pid_type {PIDTYPE_PID = 0, PIDTYPE_TGID, PIDTYPE_PGID};
 
 #define RUN_TIME	5	/* measurement window, in seconds */
 #define FIFO_PRIO	50
+#define FIFO_SPIN_US	800	/* blocking pass: spin this long ... */
+#define FIFO_SLEEP_US	10	/* ... then sleep this long */
 
 /*
  * The reservation is only approached, not reached: every slice the fair server
@@ -208,6 +215,20 @@ static double monotonic_now(void)
 	return ts.tv_sec + ts.tv_nsec / 1000000000.0;
 }
 
+/* Spin for FIFO_SPIN_US, then sleep for FIFO_SLEEP_US, until killed. */
+static void spin_sleep_forever(void)
+{
+	struct timespec nap = { .tv_nsec = FIFO_SLEEP_US * 1000 };
+	double until;
+
+	while (1) {
+		until = monotonic_now() + FIFO_SPIN_US / 1000000.0;
+		while (monotonic_now() < until)
+			;
+		nanosleep(&nap, NULL);
+	}
+}
+
 /*
  * Diagnostic only: how long the FIFO task's CPU was forced idle. Needs
  * CONFIG_SCHEDSTATS and schedstats enabled, so it must not gate the result.
@@ -233,7 +254,7 @@ static void print_forced_idle(pid_t pid)
 }
 
 /* Cookied SCHED_FIFO spinner. Only this task gets a cookie. */
-static void fifo_child(int cpu, int ready_fd)
+static void fifo_child(int cpu, int ready_fd, bool blocks)
 {
 	struct sched_param param = { .sched_priority = FIFO_PRIO };
 
@@ -252,6 +273,8 @@ static void fifo_child(int cpu, int ready_fd)
 		signal_status(ready_fd, CHILD_ERROR);
 	}
 	signal_status(ready_fd, CHILD_READY);
+	if (blocks)
+		spin_sleep_forever();
 	spin_forever();
 }
 
@@ -287,45 +310,18 @@ static void kill_child(pid_t *pid)
 	*pid = -1;
 }
 
-int main(void)
+/*
+ * Run the FIFO and CFS spinners for RUN_TIME and check the CFS task's share.
+ * With @blocks the FIFO task sleeps between spins.
+ */
+static void test_forced_idle(int sib0, int sib1, double want, bool blocks)
 {
-	double fifo_runtime, cfs_start, cfs_end, t_start, t_end, share, want;
-	unsigned long long runtime, period;
+	double fifo_runtime, cfs_start, cfs_end, t_start, t_end, share;
 	pid_t fifo_pid = -1, cfs_pid = -1;
 	int fifo_ready[2], cfs_ready[2];
-	unsigned long long cookie;
-	int sib0, sib1;
+	const char *pass = blocks ? " (FIFO task sleeps)" : "";
 	char status;
 
-	ksft_print_header();
-	ksft_set_plan(1);
-
-	if (read_sibling_pair(&sib0, &sib1)) {
-		ksft_test_result_skip("CPU0 has no SMT sibling\n");
-		ksft_finished();
-	}
-	ksft_print_msg("SMT siblings: CPU%d (FIFO) and CPU%d (CFS)\n", sib0, sib1);
-
-	if (prctl(PR_SCHED_CORE, PR_SCHED_CORE_GET, 0, PIDTYPE_PID,
-		  (unsigned long)&cookie)) {
-		ksft_test_result_skip("core scheduling unavailable: %s\n",
-				      strerror(errno));
-		ksft_finished();
-	}
-
-	if (read_fair_server(sib1, &runtime, &period)) {
-		ksft_test_result_skip("cannot read " FAIR_SERVER "/cpu%d, debugfs not mounted?\n",
-				      sib1);
-		ksft_finished();
-	}
-	if (!runtime || !period) {
-		ksft_test_result_skip("fair server on CPU%d is disabled (%llu/%llu)\n",
-				      sib1, runtime, period);
-		ksft_finished();
-	}
-	ksft_print_msg("CPU%d fair server reservation: %llu/%llu ns = %.3f%%\n",
-		       sib1, runtime, period, 100.0 * runtime / period);
-
 	if (pipe(fifo_ready) || pipe(cfs_ready))
 		ksft_exit_fail_perror("pipe");
 
@@ -334,7 +330,7 @@ int main(void)
 		close(fifo_ready[0]);
 		close(cfs_ready[0]);
 		close(cfs_ready[1]);
-		fifo_child(sib0, fifo_ready[1]);
+		fifo_child(sib0, fifo_ready[1], blocks);
 	} else if (fifo_pid < 0) {
 		ksft_exit_fail_perror("fork FIFO child");
 	}
@@ -348,7 +344,7 @@ int main(void)
 		close(cfs_ready[1]);
 		if (status == CHILD_EPERM) {
 			ksft_test_result_skip("need privileges for SCHED_FIFO\n");
-			ksft_finished();
+			return;
 		}
 		ksft_exit_fail_msg("FIFO child setup failed\n");
 	}
@@ -388,7 +384,6 @@ int main(void)
 		ksft_exit_fail_msg("cannot read CLOCK_MONOTONIC\n");
 
 	share = (cfs_end - cfs_start) / (t_end - t_start);
-	want = MIN_SHARE_OF_RESERVATION * runtime / period;
 
 	ksft_print_msg("FIFO task ran %.3fs, CFS task ran %.3fs over %.3fs\n",
 		       fifo_runtime, cfs_end - cfs_start, t_end - t_start);
@@ -396,7 +391,41 @@ int main(void)
 		       sib1, share * 100, want * 100);
 
 	ksft_test_result(share >= want,
-			 "CFS task gets the fair server reservation while forced idle\n");
+			 "CFS task gets the fair server reservation while forced idle%s\n",
+			 pass);
+}
+
+int main(void)
+{
+	unsigned long long runtime, period;
+	unsigned long long cookie;
+	int sib0, sib1;
+	double want;
+
+	ksft_print_header();
+
+	if (read_sibling_pair(&sib0, &sib1))
+		ksft_exit_skip("CPU0 has no SMT sibling\n");
+	ksft_print_msg("SMT siblings: CPU%d (FIFO) and CPU%d (CFS)\n", sib0, sib1);
+
+	if (prctl(PR_SCHED_CORE, PR_SCHED_CORE_GET, 0, PIDTYPE_PID,
+		  (unsigned long)&cookie))
+		ksft_exit_skip("core scheduling unavailable: %s\n",
+			       strerror(errno));
+
+	if (read_fair_server(sib1, &runtime, &period))
+		ksft_exit_skip("cannot read " FAIR_SERVER "/cpu%d, debugfs not mounted?\n",
+			       sib1);
+	if (!runtime || !period)
+		ksft_exit_skip("fair server on CPU%d is disabled (%llu/%llu)\n",
+			       sib1, runtime, period);
+	ksft_print_msg("CPU%d fair server reservation: %llu/%llu ns = %.3f%%\n",
+		       sib1, runtime, period, 100.0 * runtime / period);
+
+	ksft_set_plan(2);
+	want = MIN_SHARE_OF_RESERVATION * runtime / period;
+	test_forced_idle(sib0, sib1, want, false);
+	test_forced_idle(sib0, sib1, want, true);
 
 	ksft_finished();
 }
-- 
2.47.3




Amazon Development Centre (South Africa) (Proprietary) Limited
29 Gogosoa Street, Observatory, Cape Town, Western Cape, 7925, South Africa
Registration Number: 2004 / 034463 / 07


  parent reply	other threads:[~2026-11-24  9:41 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-12 16:15 [PATCH 0/5] sched: Fix DL server starvation under core scheduling Fernand Sieber
2026-11-12 16:15 ` [PATCH 1/5] sched/core: Clear stale rq->dl_server when core-sched replaces a pick Fernand Sieber
2026-11-22 22:49   ` [tip: sched/urgent] sched/deadline: " tip-bot2 for Fernand Sieber
2026-11-23  9:44   ` tip-bot2 for Fernand Sieber
2026-11-12 16:15 ` [PATCH 2/5] sched/core: Keep a sibling's DL server link in the core-wide pick Fernand Sieber
2026-11-18 13:50   ` Peter Zijlstra
2026-11-18 13:58     ` Peter Zijlstra
2026-11-12 16:15 ` [PATCH 3/5] sched/core: Rank DL server picks as deadline " Fernand Sieber
2026-11-18 13:52   ` Peter Zijlstra
2026-11-23  9:55   ` [tip: sched/core] " tip-bot2 for Fernand Sieber
2026-11-12 16:15 ` [PATCH 4/5] sched/deadline: Don't charge core-sched forced idle to the DL servers Fernand Sieber
2026-11-22 22:49   ` [tip: sched/urgent] " tip-bot2 for Fernand Sieber
2026-11-23  9:44   ` tip-bot2 for Fernand Sieber
2026-11-24  8:07   ` [PATCH 4/5] " Karl Mehltretter
2026-11-24  9:40     ` [PATCH 0/2] sched/deadline: Fix forced idle charged when a sibling ends it Fernand Sieber
2026-11-24  9:40       ` [PATCH 1/2] sched/deadline: Keep forced idle uncharged " Fernand Sieber
2026-11-24  9:40       ` Fernand Sieber [this message]
2026-11-24  9:46     ` [PATCH 4/5] sched/deadline: Don't charge core-sched forced idle to the DL servers Fernand Sieber
2026-11-12 16:15 ` [PATCH 5/5] selftests/sched: Add a core-sched forced-idle DL server test Fernand Sieber
2026-11-22 22:49   ` [tip: sched/urgent] " tip-bot2 for Fernand Sieber
2026-11-23 15:37     ` Fernand Sieber
2026-11-23  9:44   ` tip-bot2 for Fernand Sieber

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=0bea929ef61909f5eb5038d111027e1d5e710fee.1795510960.git.sieberf@amazon.com \
    --to=sieberf@amazon.com \
    --cc=bristot@kernel.org \
    --cc=bsegall@google.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=dwmw@amazon.co.uk \
    --cc=fmubeen@amazon.de \
    --cc=hborghor@amazon.de \
    --cc=joelagnelf@nvidia.com \
    --cc=joshdon@google.com \
    --cc=juri.lelli@redhat.com \
    --cc=karataev@amazon.com \
    --cc=kmehltretter@gmail.com \
    --cc=kprateek.nayak@amd.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=lshahed@amazon.de \
    --cc=mgorman@suse.de \
    --cc=mingo@redhat.com \
    --cc=nh-open-source@amazon.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=shuah@kernel.org \
    --cc=stable@vger.kernel.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®