[PATCH 2/2] selftests/sched: Let the FIFO task block in cs_dl_server_test

From: Fernand Sieber

Date: Tue Nov 24 2026 - 04:41:50 EST


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@xxxxxxxxx>
Closes: https://lore.kernel.org/all/20261124080737.1988-1-kmehltretter@xxxxxxxxx/
Signed-off-by: Fernand Sieber <sieberf@xxxxxxxxxx>
---
.../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