Re: [PATCH v14 33/39] selftests/sched: Test parameter changes in deadline_bw_test

From: sashiko-bot

Date: Thu Dec 03 2026 - 12:56:05 EST


Thank you for your contribution! Sashiko AI review found 9 potential
issues to consider:
- [Medium] selftests/sched: run_p_cases() skips debt wait without
debugfs
- [Low] selftests/sched: reenter_runnable_in_gap() 2ms window races with
SCHED_OTHER
- [Low] selftests/sched: reenter_pi_blocked_in_gap() fails instead of
skipping ENOSYS
- [Low] selftests/sched: constrained_after_job() fails instead of
skipping on EBUSY
- [Low] selftests/sched: params_swap_overload() uses unchecked zero t0
on stall
- [Low] selftests/sched: timeout checked before syscall error in
params_return_full()
- [Low] selftests/sched: ignored negative error from probe() in
params_return_full()
- [Low] selftests/sched: stale exited TID used on admission error in
deadline_bw_test
- [Low] selftests/sched: redundant sched/debug scans and 40s waits in
run_p_cases()
--

commit 35a6d94959219214223fe0bdf45f6150f74deca4
Author: Mathieu Desnoyers <mathieu.desnoyers@xxxxxxxxxxxx>

selftests/sched: Test parameter changes in deadline_bw_test

This commit adds 25 test cases to deadline_bw_test covering SCHED_DEADLINE
parameter changes, constrained-deadline gap re-entry, and bandwidth
retention, and adds post-case bandwidth drain waits in run_p_cases().

> diff --git a/tools/testing/selftests/sched/deadline/deadline_bw_test.c b/tools/testing/selftests/sched/deadline/deadline_bw_test.c
> index dbe0de739e476..58ec444cf1bbf 100644
> --- a/tools/testing/selftests/sched/deadline/deadline_bw_test.c
> +++ b/tools/testing/selftests/sched/deadline/deadline_bw_test.c

[ ... ]

> @@ -1455,6 +1477,82 @@ static int params_refused(void)

[ ... ]

> + err = set_other(t_tid);
> + if (!err)
> + err = set_deadline(t_tid, 60 * NSEC_PER_MSEC, PERIOD);
> + slept = now_ns() - rt_t_slept;
> + if (slept > 15 * NSEC_PER_MSEC) {
> + /* Too late: the 0-lag time may have passed. */
> + ksft_print_msg("T switched back %llums after it slept\n",
> + (unsigned long long)(slept / NSEC_PER_MSEC));
> + ret = KSFT_SKIP;
> + } else if (err) {
> + ksft_print_msg("T refused back as a deadline task: %s\n", strerror(-err));
> + ret = KSFT_FAIL;
> + }

[Severity: Low]
Should err be checked before slept > 15 * NSEC_PER_MSEC here?

Passing T's 0-lag time releases its old 60% bandwidth, so a late switch can
only make a zero err inconclusive. A non-zero err (such as -EBUSY on a
kernel without the fix) is still a real failure, but checking slept first
downgrades it to KSFT_SKIP whenever jitter pushes slept past 15ms.

> + if (ret == KSFT_PASS && probe(NULL) >= 6) {
> + ksft_print_msg("P has room for two tasks of 60%%\n");
> + ret = KSFT_SKIP;
> + }

[Severity: Low]
What happens if probe(NULL) fails and returns -1 here?

-1 >= 6 is false, so a probe() error falls through as KSFT_PASS without
verifying that P lacks room for two 60% tasks. Capturing the return value
and handling < 0 (as measured() does) would avoid masking probe failures.

[ ... ]

> @@ -1867,169 +1966,1833 @@ static void *refill_owner(void *arg)

[ ... ]

> + shrink_tid = gettid_();
> + err = set_deadline(0, 10 * NSEC_PER_MSEC, PERIOD);
> + t0 = now_ns();
> + shrink_t0 = t0;
> + sem_post(&shrink_ready);
> + if (err) {
> + ksft_print_msg("T refused as a deadline task: %s\n", strerror(-err));
> + return (void *)1;
> + }

[Severity: Low]
Can wake_after_deadline_shrunk() operate on a stale TID when set_deadline()
fails in shrink_t()?

shrink_t() posts shrink_ready and exits immediately on error without
recording an error flag, which autoreaps the thread and releases shrink_tid
before pthread_join(). wake_after_deadline_shrunk() then sleeps until
105ms and calls proc_state_of(shrink_tid) and
set_constrained(shrink_tid, ...) on the exited TID. The same pattern
appears in widen_t()/deadline_widened_asleep(), shorten_t()/shorten_case(),
and flip_t()/params_flip_no_gain(); storing err before sem_post() and
aborting early (as pr_h() and vic_b() do) would avoid it.

[ ... ]

> +static void *cmix_a(void *arg)
> +{
> + int err = set_deadline(0, 15 * NSEC_PER_MSEC, PERIOD);
> +
> + if (err) {
> + ksft_print_msg("A refused as a deadline task: %s\n", strerror(-err));
> + cmix_stop = 1;
> + sem_post(&cmix_go);
> + return (void *)1;
> + }

[Severity: Low]
Should constrained_after_job() return KSFT_SKIP instead of KSFT_FAIL when
cmix_a() or cmix_b() gets -EBUSY?

Together with the 5% fair server, B (75%) and A (15%) require the full 95%
default admission limit. On systems where sched_rt_runtime_us is lower or
the fair/ext server reserves more than 5%, set_deadline() returns -EBUSY,
which currently fails the test rather than skipping as
params_swap_overload() does.

[ ... ]

> + rb2_t_locking = 1;
> + if (syscall(SYS_futex, &rb2_pi, FUTEX_LOCK_PI | FUTEX_PRIVATE_FLAG,
> + 0, NULL, NULL, 0)) {
> + ksft_print_msg("FUTEX_LOCK_PI: %s\n", strerror(errno));
> + set_other(0);
> + return (void *)1;
> + }

[Severity: Low]
Should reenter_pi_blocked_in_gap() skip on ENOSYS and wake the main thread
immediately if FUTEX_LOCK_PI fails?

Unlike the other PI cases, this one bypasses pi_init() and invokes
FUTEX_LOCK_PI directly, which returns -ENOSYS when CONFIG_FUTEX_PI is
disabled. Because rb2_t() returns without setting rb2_t_locking negative,
the main thread stalls for the full 1s wait_for() timeout and returns
KSFT_FAIL instead of KSFT_SKIP.

[ ... ]

> + while (!rr_stop) {
> + uint64_t t = now_ns(), b = rr_back_at;
> +
> + if (b && !rr_t_ran && t > b + 2 * NSEC_PER_MSEC)
> + rr_t_ran = t;
> + }

[ ... ]

> + /* Store it before the switch back. A T given a new period runs at once. */
> + rr_back_at = now_ns();
> + err = set_constrained(rr_t_tid, 10 * NSEC_PER_MSEC, 20 * NSEC_PER_MSEC, 5 * PERIOD);

[Severity: Low]
Can the 2ms grace window in rr_t() expire while T is still running as
SCHED_OTHER, causing a false failure in reenter_runnable_in_gap()?

Both threads share P's single CPU, and T is already runnable as SCHED_OTHER
when rr_back_at is published:

reenter_runnable_in_gap()
set_other(rr_t_tid)
rr_back_at = now_ns()
<preempted by rr_t as SCHED_OTHER>
spins for > 2ms (e.g. EEVDF slice or HZ=250/HZ=100 tick)
rr_t_ran = t <-- recorded while SCHED_OTHER
set_constrained(rr_t_tid, ...)

On systems with 4+ CPUs (where the EEVDF base slice exceeds 2ms) or
HZ=250/HZ=100 kernels, T can run past b + 2ms before set_constrained()
takes effect. Checking sched_getscheduler(0) == SCHED_DEADLINE before
recording rr_t_ran would avoid the race.

[ ... ]

> @@ -5937,6 +7832,144 @@ static int params_waking(void)

[ ... ]

> + while (!err && (t = now_ns()) < start + SW_SETTLE + SW_WINDOW) {
> + if (!t0 && t >= start + SW_SETTLE) {
> + t0 = t;
> + cpu0[0] = sw_state[2];
> + cpu0[1] = sw_state[3];
> + }

[ ... ]

> + t1 = now_ns();
> + used[0] = sw_state[2] - cpu0[0];
> + used[1] = sw_state[3] - cpu0[1];
> + if (err) {
> + ksft_print_msg("a change refused: %s\n", strerror(-err));
> + goto out;
> + }
> + if (100000 * (used[0] + used[1]) >= SW_MAX_SHARE * (long long)(t1 - t0)) {

[Severity: Low]
What if the main process stalls past start + SW_SETTLE + SW_WINDOW before
any loop iteration sets t0?

The loop exits with t0 still 0, so t1 - t0 becomes total monotonic uptime
since boot. That inflates the denominator and lets the test silently pass
without measuring the window (and can overflow signed long long if uptime
exceeds ~3.4 years). Checking !t0 || t1 <= t0 and skipping or failing
would catch this.

[ ... ]

> @@ -11250,6 +13319,12 @@ static void run_p_cases(void)
> }
> for (i = 0; i < N_P_CASES; i++) {
> const struct p_case *c = &p_cases[i];
> + long long bw0 = total_bw_of(top_cpu(1));
> + long this0[3];
> + int k;
> +
> + for (k = 0; k < 3; k++)
> + this0[k] = this_bw_of(top_cpu(k + 1));
>
> if (ok && make_p()) {
> remove_p();

[ ... ]

> @@ -11269,6 +13344,34 @@ static void run_p_cases(void)
> ret = c->fn();
> remove_p();
> server_restore();
> + /*
> + * A task of the case can keep its bandwidth counted after it
> + * exits: until its 0-lag time, or until its debt is repaid. Wait
> + * for that, so that the next case starts from the same total_bw.
> + * A lower total_bw also ends the wait. Bandwidth lost by a case
> + * would never come back, and the wait would then cost the whole
> + * 10s.
> + */
> + if (bw0 >= 0 &&
> + wait_for_step(10000, 10 * NSEC_PER_MSEC,
> + total_bw_of(top_cpu(1)) <= bw0))
> + ksft_print_msg("%s: total_bw %lld after the case, %lld before\n",
> + c->name, total_bw_of(top_cpu(1)), bw0);
> + /*
> + * this_bw can stay higher than total_bw shows. A task moved to
> + * another cpuset while it sleeps leaves its bandwidth in the
> + * this_bw of its old CPU until it wakes up or dies. Wait for
> + * the three CPUs that random_mix() checks.
> + */
> + for (k = 0; k < 3; k++) {
> + int cpu = top_cpu(k + 1);
> +
> + if (this0[k] >= 0 &&
> + wait_for_step(10000, 10 * NSEC_PER_MSEC,
> + this_bw_of(cpu) <= this0[k]))
> + ksft_print_msg("%s: this_bw of CPU %d %ld after the case, %ld before\n",
> + c->name, cpu, this_bw_of(cpu), this0[k]);
> + }
> report(c->name, ret);
> }

[Severity: Medium]
Does skipping these post-case waits when debugfs is unavailable still leave
random_mix() failing after params_swap_overload()?

total_bw_of() and this_bw_of() both return -1 without
/sys/kernel/debug/sched/debug, so both wait loops are bypassed completely.
params_swap_overload() runs right before random_mix() and exits while its
reaped children still carry multi-second 0-lag debt on P's CPU; when
random_mix() falls back to admission-only checks without debugfs,
probe(cg_p) measures a depressed base_p before the debt drains, and
admits_in() fails once the debt expires mid-test.

[Severity: Low]
Can these pre- and post-case sched/debug reads be combined into a single
pass and guarded by ok?

Right now run_p_cases() does four separate full scans of
/sys/kernel/debug/sched/debug per case even when !ok causes all cases to
skip, and each scan walks every thread on every CPU up to top_cpu(1..3).
After each case, the four sequential 10s wait loops can also stall up to
40s (4,000 full scans) on a leaking case, risking the 600s kselftest
timeout; polling all four values in one pass inside a single wait loop
would avoid both.

--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1796296313.git.mathieu.desnoyers@xxxxxxxxxxxx?part=33