Re: [PATCH v14 13/39] selftests/sched: Test SCHED_DEADLINE bandwidth across a root domain rebuild
From: sashiko-bot
Date: Thu Dec 03 2026 - 11:10:26 EST
Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [Medium] selftests/sched: hardcoded bandwidth thresholds fail on
asymmetric CPUs
- [Low] selftests/sched: stale cg_q partition skips rebuild in
make_partition()
- [Low] selftests/sched: kill() before set_other() in reap() arms 0-lag
timer
- [Low] selftests/sched: pick_cpus() truncates CPU mask at CPU_SETSIZE
(1024)
--
commit 16912fc7803a3b5fd74783e0eb69b402ea2af6a7
Author: Mathieu Desnoyers <mathieu.desnoyers@xxxxxxxxxxxx>
selftests/sched: Test SCHED_DEADLINE bandwidth across a root domain rebuild
This patch adds deadline_rebuild_test to test that SCHED_DEADLINE bandwidth
from departing tasks is accounted correctly across root domain rebuilds and
partition moves.
> diff --git a/tools/testing/selftests/sched/deadline/deadline_rebuild_test.c b/tools/testing/selftests/sched/deadline/deadline_rebuild_test.c
> new file mode 100644
> index 0000000000000..735c3c65e156a
> --- /dev/null
> +++ b/tools/testing/selftests/sched/deadline/deadline_rebuild_test.c
> @@ -0,0 +1,587 @@
[ ... ]
> +static void reap(pid_t pid)
> +{
> + int status;
> +
> + if (pid <= 0)
> + return;
> + if (kill(pid, SIGKILL) && errno != ESRCH)
> + ksft_print_msg("kill %d: %s\n", pid, strerror(errno));
> + /* Ignore the result: the task may be dead already. */
> + set_other(pid);
> + while (waitpid(pid, &status, 0) != pid) {
[Severity: Low]
Can sending SIGKILL before set_other() in reap() leave a 0-lag reservation
behind for the next test case?
In check_p(), sleeper child a is admitted to SCHED_DEADLINE at 600ms/1000ms
while paused, so its dl_se->deadline is still 0. Calling kill(a, SIGKILL)
first wakes a under SCHED_DEADLINE into a fresh period:
parent child a (on cpu_p)
reap(a)
kill(a, SIGKILL)
enqueue_task_dl() -> new period
runs SIGKILL / do_exit() for dt > 0
set_other(a) task_non_contending() -> arms inactive_timer
test_rebuild() skips sleep
...
set_deadline(400ms) <-- EBUSY if timer still armed
Because test_rebuild() clears ran before check_p(), it skips the post-test
1.5s wait before starting switched_out_before_rebuild. If a's inactive
timer has not fired by the time the next case requests 400ms/1000ms on
cpu_p, admission exceeds P's capacity and fails spuriously with EBUSY.
Calling set_other(pid) before kill(pid, SIGKILL) switches a while
dl_se->deadline is still 0, so dl_time_to_zerolag() returns -1 and releases
the bandwidth immediately.
[ ... ]
> +/* Make @cg a partition root of CPU @cpu alone. Return 0, or -1 on error. */
> +static int make_partition(const char *cg, int cpu)
> +{
> + char path[PATH_MAX + 32], buf[32];
> +
> + if (mkdir(cg, 0755) && errno != EEXIST)
> + return -1;
> + snprintf(buf, sizeof(buf), "%d", cpu);
> + if (write_file(cg, "cpuset.cpus", buf) || write_file(cg, "cpuset.cpus.partition", "root"))
> + return -1;
[Severity: Low]
Could tolerating EEXIST here skip the root domain rebuild when a stale
cg_q partition is left behind?
If a previous run was interrupted while deadline_rebuild_q existed as an
active partition root on cpu_q, both writes become kernel no-ops:
update_cpumask() returns early when the cpumask is unchanged, and
update_prstate() returns early when the partition is already a root.
test_rebuild(DIES) would then never trigger a rebuild before the 0-lag
time and silently pass even on a buggy kernel.
Removing stale cg_p and cg_q directories at startup, or resetting
cpuset.cpus.partition to "member" before setting "root", would prevent
this.
[ ... ]
> + e1 = set_deadline(a, 600 * NSEC_PER_MSEC);
> + e2 = set_deadline(b, 600 * NSEC_PER_MSEC);
> + if (e1)
> + ksft_print_msg("a first task refused in P: %s\n", strerror(-e1));
[Severity: Medium]
Will this hardcoded 600ms/1000ms threshold cause false failures on
asymmetric CPUs?
pick_cpus() always selects the highest online non-isolated CPU for cpu_p,
which on asymmetric topologies such as Intel hybrid or ARM big.LITTLE is
often a lower-capacity core. Because __dl_overflow() scales dl_b->bw by
cpu_p's capacity, a one-CPU partition on a core with capacity below roughly
680/1024 cannot admit 600ms/1000ms after the default 95% RT cap and 5%
fair_server, so the first set_deadline() fails with EBUSY on a healthy
kernel.
Separately, main() only skips when sched_rt_runtime_us is negative; when
sched_rt_runtime_us is 0 or the RT runtime ratio is too small for the
hardcoded 400ms and 600ms runtimes, the test fails instead of skipping.
Probing or scaling runtimes to P's available capacity, or skipping when P
cannot admit the required bandwidth, would avoid these false failures.
[ ... ]
> +static int pick_cpus(void)
> +{
> + static char online[CPU_SETSIZE], isol[CPU_SETSIZE];
> + char buf[4096];
> + int cpu, n = 0;
> +
> + if (read_file("/sys/devices/system/cpu/online", buf, sizeof(buf)))
> + return 0;
> + parse_cpulist(buf, online, CPU_SETSIZE);
> + if (!read_file("/sys/devices/system/cpu/isolated", buf, sizeof(buf)))
> + parse_cpulist(buf, isol, CPU_SETSIZE);
[Severity: Low]
Does capping online[], isol[], and hk_set at CPU_SETSIZE (1024) break
moved_after_switch_out on systems with online CPUs >= 1024?
When main() passes sizeof(hk_set) to sched_setaffinity(),
get_user_cpu_mask() clears every CPU bit >= 1024 in the test process and
its children. In test_move(), the child forked outside P inherits that
truncated cpus_mask, which no longer covers the online non-isolated CPUs
>= 1024 in the root domain span, so __sched_setscheduler() rejects
SCHED_DEADLINE with EPERM and the test fails.
Sizing the mask dynamically with CPU_ALLOC() and CPU_ALLOC_SIZE() from
the highest online CPU would avoid truncating the affinity mask.
--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1796296313.git.mathieu.desnoyers@xxxxxxxxxxxx?part=13