Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

selftests/sched_ext: Fix rt_stall flaky failure

The rt_stall test measures the runtime ratio between an EXT and an RT
task pinned to the same CPU, verifying that the deadline server prevents
RT tasks from starving SCHED_EXT tasks. It expects the EXT task to get
at least 4% of CPU time.

The test is flaky because sched_stress_test() calls sleep(RUN_TIME)
immediately after fork(), without waiting for the RT child to complete
its setup (set_affinity + set_sched). If the RT child experiences
scheduling latency before completing setup, that delay eats into the
measurement window: the RT child runs for less than RUN_TIME seconds,
and the EXT task's measured ratio drops below the 4% threshold.

For example, in the failing CI run [1]:
EXT=0.140s RT=4.750s total=4.890s (expected ~5.0s)
ratio=2.86% < 4% → FAIL

The 110ms gap (5.0 - 4.89) corresponds to the RT child's setup time
being counted inside the measurement window, during which fewer
deadline server ticks fire for the EXT task.

Fix by using pipes to synchronize: each child signals the parent after
completing its setup, and the parent waits for both signals before
starting sleep(RUN_TIME). This ensures the measurement window only
counts time when both tasks are fully configured and competing.

[1] https://github.com/kernel-patches/bpf/actions/runs/21961895809/job/63442490449

Fixes: be621a76341c ("selftests/sched_ext: Add test for sched_ext dl_server")
Assisted-by: claude-opus-4-6-v1
Signed-off-by: Ihor Solodrai <ihor.solodrai@linux.dev>
Reviewed-by: Andrea Righi <arighi@nvidia.com>
Signed-off-by: Tejun Heo <tj@kernel.org>

authored by

Ihor Solodrai and committed by
Tejun Heo
0b82cc33 048714d9

+49
+49
tools/testing/selftests/sched_ext/rt_stall.c
··· 23 23 #define CORE_ID 0 /* CPU to pin tasks to */ 24 24 #define RUN_TIME 5 /* How long to run the test in seconds */ 25 25 26 + /* Signal the parent that setup is complete by writing to a pipe */ 27 + static void signal_ready(int fd) 28 + { 29 + char c = 1; 30 + 31 + if (write(fd, &c, 1) != 1) { 32 + perror("write to ready pipe"); 33 + exit(EXIT_FAILURE); 34 + } 35 + close(fd); 36 + } 37 + 38 + /* Wait for a child to signal readiness via a pipe */ 39 + static void wait_ready(int fd) 40 + { 41 + char c; 42 + 43 + if (read(fd, &c, 1) != 1) { 44 + perror("read from ready pipe"); 45 + exit(EXIT_FAILURE); 46 + } 47 + close(fd); 48 + } 49 + 26 50 /* Simple busy-wait function for test tasks */ 27 51 static void process_func(void) 28 52 { ··· 146 122 147 123 float ext_runtime, rt_runtime, actual_ratio; 148 124 int ext_pid, rt_pid; 125 + int ext_ready[2], rt_ready[2]; 149 126 150 127 ksft_print_header(); 151 128 ksft_set_plan(1); 152 129 130 + if (pipe(ext_ready) || pipe(rt_ready)) { 131 + perror("pipe"); 132 + ksft_exit_fail(); 133 + } 134 + 153 135 /* Create and set up a EXT task */ 154 136 ext_pid = fork(); 155 137 if (ext_pid == 0) { 138 + close(ext_ready[0]); 139 + close(rt_ready[0]); 140 + close(rt_ready[1]); 156 141 set_affinity(CORE_ID); 142 + signal_ready(ext_ready[1]); 157 143 process_func(); 158 144 exit(0); 159 145 } else if (ext_pid < 0) { ··· 174 140 /* Create an RT task */ 175 141 rt_pid = fork(); 176 142 if (rt_pid == 0) { 143 + close(ext_ready[0]); 144 + close(ext_ready[1]); 145 + close(rt_ready[0]); 177 146 set_affinity(CORE_ID); 178 147 set_sched(SCHED_FIFO, 50); 148 + signal_ready(rt_ready[1]); 179 149 process_func(); 180 150 exit(0); 181 151 } else if (rt_pid < 0) { 182 152 perror("fork for RT task"); 183 153 ksft_exit_fail(); 184 154 } 155 + 156 + /* 157 + * Wait for both children to complete their setup (affinity and 158 + * scheduling policy) before starting the measurement window. 159 + * This prevents flaky failures caused by the RT child's setup 160 + * time eating into the measurement period. 161 + */ 162 + close(ext_ready[1]); 163 + close(rt_ready[1]); 164 + wait_ready(ext_ready[0]); 165 + wait_ready(rt_ready[0]); 185 166 186 167 /* Let the processes run for the specified time */ 187 168 sleep(RUN_TIME);