Re: [PATCH v13 30/36] selftests/sched: Test parameter changes in deadline_bw_test

From: sashiko-bot

Date: Tue Dec 01 2026 - 14:34:36 EST


Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] selftests/sched: dead test modes in pi_asleep(), deboost_case(),
and helpers
--

commit 3c3e678183963bfa600f0de3703c72db233a7225
Author: Mathieu Desnoyers <mathieu.desnoyers@xxxxxxxxxxxx>

selftests/sched: Test parameter changes in deadline_bw_test

This commit adds 24 parameter-change and constrained-gap test cases to
deadline_bw_test and waits for bandwidth and debt release between cases 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 07beae8ca202d..bca333d5498c6 100644
> --- a/tools/testing/selftests/sched/deadline/deadline_bw_test.c
> +++ b/tools/testing/selftests/sched/deadline/deadline_bw_test.c

[ ... ]

> @@ -893,30 +929,50 @@ static void *sleeping_owner(void *arg)
>
> /*
> * A SCHED_OTHER owner takes pi_lock and sleeps 400ms while holding it.
> - * The main thread then waits 20ms for the lock, 5 times. For each wait it
> - * becomes a deadline task of 5ms every 50ms. Each wait boosts the
> + * The main thread then waits 20ms for the lock, @rounds times. For each
> + * wait it becomes a deadline task of 5ms every 50ms. Each wait boosts the
> * sleeping owner, and its timeout deboosts it. Every wait must time out.
> + *
> + * With @was_dl, the owner was a deadline task of 30ms every 100ms before.
> + * It ran 1ms and slept. The main thread switched it to SCHED_OTHER 200ms
> + * later, past its 0-lag time.
> */
> -static int pi_other_owner_asleep(void)
> +static int pi_asleep(int was_dl, int rounds)

[ ... ]

> +static int pi_other_owner_asleep(void)
> +{
> + return pi_asleep(0, 5);
> +}
> +
> /*
> * Run as the owner thread. Become a deadline task of 30ms every 100ms,
> * and take pi_lock. Hold it for 300ms, spinning 2ms and sleeping 5ms in
> @@ -1632,9 +1693,9 @@ static atomic_int owner_first_period_ms;
> static _Atomic pid_t donor_tid;
>
> /*
> - * Run as the owner O of deboost_resets_period(). Store the CPU time of
> - * step 4, in ms, in owner_first_period_ms. Return NULL, 1 on an error, or
> - * 2 if no waiter boosted it within 1s.
> + * Run as the owner O of deboost_case(). @arg is its @mode. Store the CPU
> + * time of step 4, in ms, in owner_first_period_ms. Return NULL, 1 on an
> + * error, or 2 if no waiter boosted it within 1s.
> */
> static void *deboosted_owner(void *arg)
> {
> @@ -1642,6 +1703,17 @@ static void *deboosted_owner(void *arg)
> int err;
>
> owner_tid = gettid_();
> + if (arg == (void *)1L) {
> + err = set_deadline(0, 60 * NSEC_PER_MSEC, PERIOD);
> + if (err) {
> + ksft_print_msg("the owner refused as a deadline task: %s\n",
> + strerror(-err));
> + return (void *)1;
> + }
> + spin_ns(NSEC_PER_MSEC);
> + sem_post(&owner_ready);
> + sem_wait_sig(&owner_go);
> + }

[ ... ]

> +/* Run deboost_case() with a plain SCHED_OTHER owner. */
> +static int deboost_resets_period(void)
> +{
> + return deboost_case(0);
> +}
> +
> /*
> * Return the runtime that the deadline task @tid has left, in ns, from
> * dl.runtime in /proc/<tid>/sched. Return -1 if it cannot be read.
> @@ -1779,14 +1891,16 @@ static long long dl_runtime_left(pid_t tid)
> #define REFILL_DONOR_RUNTIME (2 * NSEC_PER_MSEC)
> #define REFILL_DONOR_PERIOD (10 * NSEC_PER_MSEC)
>
> -static sem_t refill_donor_ready;
> -static atomic_int refill_donor_locking;
> -static _Atomic long long refill_owner_left;
> +static sem_t refill_donor_ready, refill_measured;
> +static atomic_int refill_donor_locking, refill_hold_donor;
> +static _Atomic long long refill_owner_left, refill_owner_read_ms;

[ ... ]

> +/* Run refill_case() with an owner that stays on its own runtime. */
> +static int deboost_keeps_own_runtime(void)
> +{
> + return refill_case(1);
> +}
> +
> +static sem_t ret_ready, ret_go;
> +static _Atomic pid_t ret_tid;
> +static atomic_int ret_first_period_ms;
> +
> +/*
> + * Run as the thread of the return cases. Become a deadline task of 50ms
> + * every 100ms and run 20ms. 30ms of runtime are left, and the 0-lag time
> + * is about 20ms ahead. Then change to new parameters, as @arg says:
> + * - 0: the thread switches itself to SCHED_OTHER and back to
> + * SCHED_DEADLINE, while it runs.
> + * - 1: the thread sleeps. The main thread switches it to SCHED_OTHER and
> + * back.
> + * - 2: the thread changes its own parameters while it runs. It stays in
> + * SCHED_DEADLINE.
> + * - 3: as 2, while a donor boosts the thread. The thread takes pi_lock and
> + * wakes the donor up. The donor blocks on pi_lock. The thread then
> + * changes its parameters, and unlocks.
> + * - 4: as 2, to a constrained deadline: 8ms in 20ms, every 100ms.
> + * - 5: the thread sleeps. The main thread changes it to 8ms in 20ms,
> + * every 100ms.

[ ... ]

> +static int return_running_new_params(void)
> +{
> + return return_case(0);
> +}
> +
> +/* The same, for a task that leaves and comes back while it sleeps. */
> +static int return_asleep_new_params(void)
> +{
> + return return_case(1);
> +}
> +
> +/* The same, for a task that changes its parameters within the class. */
> +static int change_running_new_params(void)
> +{
> + return return_case(2);
> +}
> +
> +/*
> + * A running task of 50ms every 100ms has 30ms left. It changes itself to
> + * 8ms in 20ms, every 100ms. Its deadline stays 80ms ahead, further than
> + * the new 20ms. The check of the runtime left uses the new density over
> + * those 80ms. That allows 32ms, so the check keeps the 30ms. The task
> + * must keep no more than its new 8ms.
> + */
> +static int change_constrained_new_params(void)
> +{
> + return return_case(4);
> +}
> +
> +/*
> + * The same, for a task that the main thread changes while it sleeps. The
> + * check is at its wakeup.
> + */
> +static int wake_constrained_new_params(void)
> +{
> + return return_case(5);
> +}

[Severity: Low]
Are several new test modes in pi_asleep(), deboost_case(), refill_case(),
and return_case() missing wrappers and entries in p_cases[]?

This patch adds code and documentation for five scenarios that are never
called:
- pi_asleep() adds a was_dl != 0 branch, but is only called as
pi_asleep(0, 5) in pi_other_owner_asleep().
- deboost_case() and deboosted_owner() add modes 1 and 2, but
deboost_resets_period() only calls deboost_case(0). Also, in mode 1 of
deboosted_owner(), if set_deadline() fails, the thread returns without
posting owner_ready, so deboost_case(1) would wait for the full 5s
timeout in sem_wait_for(&owner_ready, 5000).
- refill_case() adds a spin_ms == 8 branch and refill_donor() adds
refill_hold_donor and refill_measured, but deboost_keeps_own_runtime()
only calls refill_case(1) and the two new globals are never initialized
or set.
- return_case() and returner() add mode 3, while wrappers and p_cases[]
entries are only added for modes 0, 1, 2, 4, and 5.

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