From: sashiko-bot@kernel.org
To: "Mathieu Desnoyers" <mathieu.desnoyers@efficios.com>
Cc: linux-rt-devel@lists.linux.dev, tj@kernel.org,
hannes@cmpxchg.org, mkoutny@suse.com,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 16/16] selftests/sched: Add a test of SCHED_DEADLINE bandwidth accounting
Date: Wed, 18 Nov 2026 21:04:46 +0000 [thread overview]
Message-ID: <sashiko-outbox-221967@kernel.org> (raw)
In-Reply-To: <92d746027d4034afb4e9c55bd1b686312a2401ab.1795031605.git.mathieu.desnoyers@efficios.com>
Thank you for your contribution! Sashiko AI review found 9 potential
issues to consider:
- [Medium] selftests/sched: sub-cgroup start and unconditional cpu
toggle in move_cancelled()
- [Medium] selftests/sched: broken PI and runtime logic in
deboost_new_params_reboost()
- [Medium] selftests/sched: pi_chain_donor_leaves() fails due to
unpropagated dl.pi_se
- [Medium] selftests/sched: rebuild_record_taken() fails under
isolcpus=domain,0,1
- [Low] selftests/sched: rebuild_record_taken() fails instead of
skipping without debugfs
- [Low] selftests/sched: data race on late.done and unjoined thread in
move_cancelled()
- [Low] selftests/sched: unchecked -1 error return from probe() in
bandwidth comparisons
- [Low] selftests/sched: unused variables, write-only fair_tid, and dead
mode branches
- [Low] selftests/sched: re-init of active robust mutex shm_lock in
shm_lock_init()
--
commit ec25de481fdb21f02eb990530342399d3485450d
Author: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
selftests/sched: Add a test of SCHED_DEADLINE bandwidth accounting
This commit adds deadline_bw_test, a kselftest covering SCHED_DEADLINE
bandwidth accounting across priority inheritance, parameter changes,
cpuset moves, task deaths, yields, runtime overruns, bandwidth
reclaiming, fair server changes, and CPU hotplug.
Link: https://github.com/jlelli/sched-deadline-tests
> diff --git a/tools/testing/selftests/sched/deadline/deadline_bw_test.c b/tools/testing/selftests/sched/deadline/deadline_bw_test.c
> new file mode 100644
> index 0000000000000..1e64402f90df0
> --- /dev/null
> +++ b/tools/testing/selftests/sched/deadline/deadline_bw_test.c
[ ... ]
> + sem_post(&rb_donor_go);
> + t0 = now_ns();
> + while (!rb_donor_locking || proc_state_of(donor_tid) != 'S') {
> + if (now_ns() - t0 > NSEC_PER_SEC) {
> + ksft_print_msg("the donor did not block on the lock\n");
> + err = -1;
> + goto out;
> + }
> + }
> + err = set_deadline(rb_waiter_tid, 2 * NSEC_PER_MSEC, PERIOD);
> + if (err) {
> + ksft_print_msg("the waiter refused as a deadline task: %s\n",
> + strerror(-err));
> + goto out;
> + }
> + err = set_deadline(0, 5 * NSEC_PER_MSEC, PERIOD);
[Severity: Medium]
Does deboost_new_params_reboost() exercise reboosting after a deboost as
its comment describes?
When reboost_owner() calls set_deadline() on rb_waiter_tid while W is
blocked on pi_lock, W is not queued on a runqueue, so __setparam_dl()
updates W's static parameters and switched_to_dl() returns without setting
W->dl.deadline. rt_mutex_adjust_pi() then copies W->dl.deadline (0) into
W's waiter node on pi_lock, which sorts ahead of D's deadline in
rt_waiter_node_less() and makes W the top waiter boosting O immediately,
before D times out.
Also, when O calls set_deadline() on itself while running, the kernel
enqueues O with ENQUEUE_RESTORE | ENQUEUE_MOVE without replenishing, and
rt_mutex_setprio() on deboost does not compare O's remaining runtime
against its new static runtime or start a new period, so the test passes
without testing a reboost on deboost.
[ ... ]
> +static pthread_mutex_t pi_lock2;
> +static sem_t holder_go;
> +static atomic_int holder_holds, chain_waits, donor_done, x_waits, l2_takes;
> +static atomic_int chain_rank, x_rank;
> +static _Atomic pid_t x_tid, fair_tid;
[ ... ]
> + donor_tid = 0;
> + x_tid = 0;
> + fair_tid = 0;
> + return 0;
> +}
[Severity: Low]
fair_tid is set in pi_init_lock2() but never read, which triggers a
-Wunused-but-set-variable warning under -Wall. Similarly, nisol and isol
in main() are populated by read_online(&isol, 1) and never used or freed,
sleeper_cpu is never modified from -1 (leaving the sleeper_cpu >= 0 block
in dl_sleeper_tid() unreachable), struct hp_case::no_hp is never set, and
several helper modes (was_dl != 0 in pi_asleep(), modes 1 and 2 in
deboost_case(), spin_ms == 8 in refill_case(), modes 0 and 2..5 in
return_case(), and MV_YIELDED in mover()) have no callers.
[ ... ]
> + have[LV_Z] = !pthread_create(&t[LV_Z], NULL, leave_waiter, (void *)2L);
> + if (!have[LV_Z] ||
> + wait_for(1000, (leave_tid[LV_Z] && proc_state_of(leave_tid[LV_Z]) == 'S') ||
> + leave_err)) {
> + ksft_print_msg("Z never blocked on L1\n");
> + goto out;
> + }
> + sleep_ns(10 * NSEC_PER_MSEC); /* the chain walk of Z is done */
> + err = leave_err ? -EINVAL : set_other(leave_tid[LV_W]);
[Severity: Medium]
Does pi_chain_donor_leaves() fail because Z is never propagated past M to
O as O's donor?
When Z blocks on L1, task_blocks_on_rt_mutex() updates M->dl.pi_se to
&Z->dl, but M is sleeping on L2, so M->prio (-1) and M->dl.deadline do not
change. In rt_mutex_adjust_prio_chain(), rt_waiter_node_equal() sees that
M's waiter node on L2 still matches M's prio and deadline and stops without
requeueing M on L2 or calling rt_mutex_adjust_prio() on O:
kernel/locking/rtmutex.c:rt_mutex_adjust_prio_chain() {
...
if (rt_waiter_node_equal(&waiter->tree, task_to_waiter_node(task))) {
if (!detect_deadlock)
goto out_unlock_pi;
else
requeue = false;
}
...
}
O->dl.pi_se therefore stays &W->dl. After set_other(leave_tid[LV_W]) and
the 250ms sleep clear W's deadline parameters, waking O replenishes O from
W's zeroed parameters with runtime = 0 and deadline = rq_clock(rq), so O
preempts and starves Y on P's CPU and fails the y_ns < 30ms check.
[ ... ]
> +/* What late_setter() does, and the result. */
> +static struct {
> + pid_t pid;
> + uint64_t runtime;
> + uint64_t delay;
> + atomic_int go;
> + int ret;
> + uint64_t done;
> +} late;
> +
> +/*
> + * Make late.pid a deadline task of late.runtime every 100ms, late.delay
> + * ns after late.go. Store the result in late.ret and the time it returned
> + * in late.done.
> + */
> +static void *late_setter(void *arg)
> +{
> + uint64_t start;
> +
> + while (!late.go)
> + ;
> + start = now_ns();
> + while (now_ns() - start < late.delay)
> + ;
> + late.ret = set_deadline(late.pid, late.runtime, PERIOD);
> + late.done = now_ns();
> + return arg;
> +}
[ ... ]
> +static int move_cancelled(void)
> +{
> + int with_p, with_r, ret = KSFT_PASS, i, err;
> + const char *name = "move_cancelled";
> + uint64_t start, len;
> + pid_t pid;
> +
> + mv_state[0] = 0;
> + mv_state[3] = 0;
> + mv_state[4] = 0;
> + mv_state[5] = 0;
> + pid = pinned_mover(2048, 1);
> + if (pid < 0 || child_up(name, 0) || wait_for(5000, mv_state[5])) {
> + reap(pid);
> + return mv_state[0] == -2 ? KSFT_SKIP : KSFT_FAIL;
> + }
> + if (mv_state[5] < 0 || write_file(root, "cgroup.subtree_control", "+cpu")) {
> + ksft_print_msg("%s: no SCHED_FIFO thread or no cpu controller\n", name);
> + reap(pid);
> + return KSFT_SKIP;
> + }
[ ... ]
> + if (wait_for(5000, late.done)) {
> + ksft_print_msg("%s: sched_setattr() still waits after a cancelled move\n",
> + name);
> + ret = KSFT_FAIL;
> + break; /* the thread cannot be joined */
> + }
> + join(t);
> + if (late.ret) {
> + ksft_print_msg("%s: sched_setattr: %s\n", name, strerror(-late.ret));
> + ret = KSFT_FAIL;
> + }
> + }
> + sleep_ns(3 * PERIOD);
> + if (ret == KSFT_PASS &&
> + (admits_in(cg_p, with_p, "P, after the cancelled moves") ||
> + admits_in(root, with_r, "the root domain of the process")))
> + ret = KSFT_FAIL;
> +out:
> + reap(pid);
> + if (write_file(root, "cgroup.subtree_control", "-cpu"))
> + ksft_print_msg("%s: the cpu controller stays enabled\n", name);
> + return ret;
> +}
[Severity: Medium]
What happens in move_cancelled() when deadline_bw_test is started from a
non-root cgroup (such as a systemd session or service cgroup)?
Unlike kill_case() and death_group(), main() and move_cancelled() never
move the test process into root before forking pinned_mover(2048, 1).
With CONFIG_RT_GROUP_SCHED=y, a non-root cgroup has no RT runtime by
default, so either fifo_sleeper() fails sched_setscheduler(SCHED_FIFO)
with EPERM when +cpu is already enabled, or enabling +cpu on root fails
with EINVAL while the child cgroup contains a SCHED_FIFO task, causing
move_cancelled() to always skip. Also, unlike run_p_cases() and
cs_setup() with +cpuset, move_cancelled() unconditionally writes -cpu to
root/cgroup.subtree_control at exit even if the cpu controller was already
enabled before the test ran.
[Severity: Low]
In the same loop, late.done is a plain uint64_t written by late_setter()
while move_cancelled() polls it in wait_for(5000, late.done), which is a
data race. If that wait times out, breaking out before join(t) also
leaves t unjoined in the main process even though reap(pid) at out: kills
pid and unblocks late_setter().
[ ... ]
> +/* Set up shm_lock. Return 0, or -1 if it cannot be set up. */
> +static int shm_lock_init(void)
> +{
> + pthread_mutexattr_t a;
> + int err;
> +
> + err = pthread_mutexattr_init(&a);
> + if (!err)
> + err = pthread_mutexattr_setpshared(&a, PTHREAD_PROCESS_SHARED);
> + if (!err)
> + err = pthread_mutexattr_setprotocol(&a, PTHREAD_PRIO_INHERIT);
> + if (!err)
> + err = pthread_mutexattr_setrobust(&a, PTHREAD_MUTEX_ROBUST);
> + if (!err)
> + err = pthread_mutex_init(shm_lock, &a);
[ ... ]
> + } else {
> + reap(waiter);
> + waiter = -1;
> + sleep_ns(50 * NSEC_PER_MSEC); /* the owner deboosted asleep */
> + }
> +out:
> + reap(waiter);
> + reap(owner);
> + return ret;
> +}
[Severity: Low]
Does shm_lock_init() re-initialize shm_lock without destroying it across
death_pi_waiter, death_pi_owner, and death_pi_deadline_owner?
shm_lock lives in MAP_SHARED memory, and in death_pi_waiter, reap(owner)
kills the owner with SIGKILL while it still holds shm_lock, leaving the
robust mutex in the FUTEX_OWNER_DIED state when the next test case calls
pthread_mutex_init(shm_lock, &a). shm_lock_init() (and
pi_chain_two_owners()) also omits pthread_mutexattr_destroy(&a).
[ ... ]
> +static int hotplug_server(void)
> +{
> + int base, off10, off30;
> +
> + if (server_set(hp_cpu, SERVER_RUNTIME, SERVER_PERIOD)) {
> + ksft_print_msg("the fair server of CPU %d cannot be set\n", hp_cpu);
> + return KSFT_SKIP;
> + }
> + base = probe(NULL);
> + if (cpu_online(hp_cpu, 0)) {
> + ksft_print_msg("offline of CPU %d refused\n", hp_cpu);
> + return KSFT_FAIL;
> + }
> + off10 = probe(NULL);
> + cpu_up(hp_cpu);
> + if (server_set(hp_cpu, 3 * SERVER_RUNTIME, SERVER_PERIOD) ||
> + admits(base - 2, "a fair server of 30%"))
> + return KSFT_FAIL;
> + if (cpu_online(hp_cpu, 0)) {
> + ksft_print_msg("offline of CPU %d refused, its fair server at 30%%\n", hp_cpu);
> + return KSFT_FAIL;
> + }
> + off30 = probe(NULL);
> + cpu_up(hp_cpu);
> + if (off30 != off10) {
[Severity: Low]
Can hotplug_server() pass when probe(NULL) fails and returns -1?
If both offline probes return -1, off30 != off10 evaluates to false; base
is not checked for <= 0 either. move_refused() and move_zero_bw()
similarly compare probe(cg_p) != base_p || probe(root) != base_r without
checking whether base_p or base_r failed with -1.
[ ... ]
> +static int rebuild_record_taken(void)
> +{
> + int a = top_cpu(3), b = top_cpu(2), c = online[0], d = top_cpu(1);
> + int fd[2] = { -1, -1 }, i, n, err, cpu, ret = KSFT_SKIP;
> + long long q, h, q0, h0, bw;
> + char buf[4096];
> + pid_t pid = -1;
> +
> + if (ncpus < 4 || !cpu_hotpluggable(a) || !cpu_hotpluggable(b) ||
> + !cpu_hotpluggable(d)) {
> + ksft_print_msg("needs 4 CPUs, 3 of them hotpluggable\n");
> + return KSFT_SKIP;
> + }
> + if (cs_setup())
> + return KSFT_SKIP;
> + /* Q has every housekeeping CPU but A, B and D. */
> + for (i = n = 0; i < ncpus - 3; i++)
> + n += snprintf(buf + n, sizeof(buf) - n, "%s%d", n ? "," : "",
> + online[i]);
> + if (make_partition_cpus(cs_q, buf)) {
> + ksft_print_msg("Q cannot be a partition root of CPUs %s\n", buf);
> + goto out;
> + }
> + ret = KSFT_FAIL;
> + err = cpu_online(d, 0);
> + if (err) {
> + ksft_print_msg("offline of CPU %d: %s\n", d, strerror(-err));
> + goto out;
> + }
> + bw = total_bw_of(a);
> + if (bw == -1 || pipe(fd)) {
> + ksft_print_msg("no total_bw of CPU %d, or no pipe\n", a);
> + goto out;
> + }
[Severity: Low]
Should rebuild_record_taken() return KSFT_SKIP instead of KSFT_FAIL when
total_bw_of(a) returns -1 because /sys/kernel/debug/sched/debug is not
available?
ret is set to KSFT_FAIL before total_bw_of(a) is checked, whereas the
other debugfs-dependent cases skip when debugfs files cannot be read.
> + mv_state[0] = 0;
> + mv_state[1] = 0;
> + pid = fork_child("a deadline task");
> + if (!pid) {
> + cpu_set_t set;
> + char ch;
> +
> + CPU_ZERO(&set);
> + CPU_SET(a, &set);
> + CPU_SET(b, &set);
> + if (sched_setaffinity(0, sizeof(set), &set) ||
> + set_deadline(0, 10 * NSEC_PER_MSEC, PERIOD)) {
[ ... ]
> + if (fallback_wake(fd[1], pid))
> + goto out;
> + /* Go on after a failure: the totals tell more. */
> + cpu = task_cpu_of(pid);
> + if (cpu != c)
> + ksft_print_msg("woken on CPU %d, not %d\n", cpu, c);
> + else if (!totals_check("woken", d, c, q, h))
> + ret = KSFT_PASS;
> + reap(pid);
> + pid = -1;
> + sleep_ns(3 * PERIOD);
> + if (totals_of(d, c, &q0, &h0)) {
> + ret = KSFT_FAIL;
> + goto out;
> + }
> + if (q != q0 || h != h0 + bw) {
> + ksft_print_msg("Q counts %lld of %lld, the root cgroup %lld\n",
> + q - q0, bw, h - h0);
> + ret = KSFT_FAIL;
> + }
[Severity: Medium]
Does rebuild_record_taken() fail when CPU 0 is isolated with
isolcpus=domain,0,1?
When CPU 0 is isolated, online[0] is the first housekeeping CPU (for
example, c = 2). The child in the root cgroup overwrites its inherited
housekeeping affinity with {a, b}. Once a and b are taken offline and
cs_q takes the remaining housekeeping CPUs except c,
dl_add_task_root_domain() queries cpuset_cpus_allowed_locked() for
top_cpuset, which includes the isolated CPUs 0 and 1, so
cpumask_first_and(cpu_active_mask, msk) picks CPU 0 and adds bw to CPU 0's
default root domain rather than CPU c's housekeeping root domain (leaving
h == h0 instead of h0 + bw). Likewise, waking pid via fallback_wake()
hits select_fallback_rq() -> cpuset_cpus_allowed_fallback(), which resets
pid's affinity to top_cpuset.cpus_allowed and wakes pid on CPU 0 instead
of CPU c.
--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1795031605.git.mathieu.desnoyers@efficios.com?part=16
next prev parent reply other threads:[~2026-11-18 21:04 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-18 20:06 [PATCH 00/16] sched/deadline: first bandwidth accounting fixes and selftests Mathieu Desnoyers
2026-11-18 20:06 ` [PATCH 01/16] sched: Refuse SCHED_FLAG_KEEP_PARAMS that would change the policy or the class Mathieu Desnoyers
2026-11-18 20:06 ` [PATCH 02/16] sched/deadline: Do not admit bandwidth for parameters that are kept Mathieu Desnoyers
2026-11-18 20:06 ` [PATCH 03/16] sched: Let a task boosted by a deadline waiter change its policy Mathieu Desnoyers
2026-11-18 20:06 ` [PATCH 04/16] sched/deadline: Do not divide by zero active CPUs of a root domain Mathieu Desnoyers
2026-11-18 20:23 ` sashiko-bot
2026-11-18 21:08 ` Mathieu Desnoyers
2026-11-18 20:06 ` [PATCH 05/16] sched/deadline: Refuse dl_server debugfs writes while the rq is offline Mathieu Desnoyers
2026-11-18 20:06 ` [PATCH 06/16] sched: Take cpuset_mutex for a deadline policy change only with pi Mathieu Desnoyers
2026-11-18 20:17 ` sashiko-bot
2026-11-18 21:09 ` Mathieu Desnoyers
2026-11-18 20:06 ` [PATCH 07/16] sched/deadline: Do not lose a throttled task switched out and back Mathieu Desnoyers
2026-11-18 20:31 ` sashiko-bot
2026-11-18 21:09 ` Mathieu Desnoyers
2026-11-18 20:06 ` [PATCH 08/16] sched/deadline: Do not replenish a boost from cleared parameters Mathieu Desnoyers
2026-11-18 20:35 ` sashiko-bot
2026-11-18 21:10 ` Mathieu Desnoyers
2026-11-18 20:06 ` [PATCH 09/16] sched/deadline: Reset the deadline and the runtime with the parameters Mathieu Desnoyers
2026-11-18 20:38 ` sashiko-bot
2026-11-18 21:10 ` Mathieu Desnoyers
2026-11-18 20:06 ` [PATCH 10/16] sched/deadline: Release the bandwidth of a task that leaves the class asleep Mathieu Desnoyers
2026-11-18 20:06 ` [PATCH 11/16] sched/deadline: Reject SCHED_DEADLINE on exited tasks Mathieu Desnoyers
2026-11-18 20:06 ` [PATCH 12/16] sched/deadline: Fix this_bw when a task is changed during a remote wakeup Mathieu Desnoyers
2026-11-18 20:46 ` sashiko-bot
2026-11-18 21:11 ` Mathieu Desnoyers
2026-11-18 20:06 ` [PATCH 13/16] sched/deadline: Check SCHED_DEADLINE affinity under the rq lock Mathieu Desnoyers
2026-11-18 20:06 ` [PATCH 14/16] sched/debug: Show the deadline bandwidth of each runqueue Mathieu Desnoyers
2026-11-18 20:06 ` [PATCH 15/16] selftests/sched: Add a test of SCHED_DEADLINE policy round trips Mathieu Desnoyers
2026-11-18 20:06 ` [PATCH 16/16] selftests/sched: Add a test of SCHED_DEADLINE bandwidth accounting Mathieu Desnoyers
2026-11-18 21:04 ` sashiko-bot [this message]
2026-11-18 21:12 ` Mathieu Desnoyers
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-221967@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=hannes@cmpxchg.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rt-devel@lists.linux.dev \
--cc=mathieu.desnoyers@efficios.com \
--cc=mkoutny@suse.com \
--cc=sashiko-reviews@lists.linux.dev \
--cc=tj@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.