The Linux Kernel Mailing List
 help / color / mirror / Atom feed
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 v14 13/39] selftests/sched: Test SCHED_DEADLINE bandwidth across a root domain rebuild
Date: Thu, 03 Dec 2026 16:10:14 +0000	[thread overview]
Message-ID: <sashiko-outbox-248180@kernel.org> (raw)
In-Reply-To: <223b82dcc06380b475bb5299f51e0a07da9cab5a.1796296313.git.mathieu.desnoyers@efficios.com>

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@efficios.com>

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@efficios.com?part=13

  reply	other threads:[~2026-12-03 16:10 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03 14:58 [PATCH v14 00/39] sched/deadline: bandwidth accounting fixes and selftests Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 01/39] sched/deadline: Hold a reference on the deadline donor of a boosted task Mathieu Desnoyers
2026-12-03 15:44   ` sashiko-bot
2026-12-03 14:58 ` [PATCH v14 02/39] sched/deadline: Replenish a throttled task boosted while asleep Mathieu Desnoyers
2026-12-03 15:29   ` sashiko-bot
2026-12-03 14:58 ` [PATCH v14 03/39] sched/deadline: Do not truncate a bandwidth to 32 bits in __dl_add/sub() Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 04/39] sched/deadline: Count the 0-lag time from the next period Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 05/39] sched/deadline: Clear dl_overrun under the rq lock Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 06/39] sched/deadline: Admit a returning task without the bandwidth it holds Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 07/39] sched/deadline: Leave an active task alone in the inactive timer Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 08/39] sched/deadline: Keep the deadline of a departed constrained task Mathieu Desnoyers
2026-12-03 15:45   ` sashiko-bot
2026-12-03 14:58 ` [PATCH v14 09/39] sched/deadline: Keep departing bandwidth across a root domain rebuild Mathieu Desnoyers
2026-12-03 15:49   ` sashiko-bot
2026-12-03 14:58 ` [PATCH v14 10/39] sched/deadline: Rebuild the root domains' accounting from the task list Mathieu Desnoyers
2026-12-03 15:57   ` sashiko-bot
2026-12-03 14:58 ` [PATCH v14 11/39] sched/deadline: Record the root domain holding a task's bandwidth Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 12/39] sched/deadline: Leave a dying task out of a rebuild of the accounting Mathieu Desnoyers
2026-12-03 16:20   ` sashiko-bot
2026-12-03 14:58 ` [PATCH v14 13/39] selftests/sched: Test SCHED_DEADLINE bandwidth across a root domain rebuild Mathieu Desnoyers
2026-12-03 16:10   ` sashiko-bot [this message]
2026-12-03 14:58 ` [PATCH v14 14/39] selftests/sched: Test the root domain rebuild in deadline_bw_test Mathieu Desnoyers
2026-12-03 16:10   ` sashiko-bot
2026-12-03 14:58 ` [PATCH v14 15/39] sched/deadline: Move a task's bandwidth only where room was made Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 16/39] cgroup/cpuset: Wait for an attach before rebuilding the sched domains Mathieu Desnoyers
2026-12-03 16:22   ` sashiko-bot
2026-12-03 14:58 ` [PATCH v14 17/39] sched: Make deadline policy and affinity changes wait for a cpuset attach Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 18/39] cgroup/cpuset: Give back the bandwidth an attach did not move Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 19/39] cgroup/cpuset: Reserve the bandwidth in the root domain a task moves to Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 20/39] selftests/sched: Test cpuset moves in deadline_bw_test Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 21/39] sched/deadline: Make a rebuild count a task in the root domain it runs in Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 22/39] sched/deadline: Move a task's bandwidth to " Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 23/39] sched/deadline: Keep a task in the root domain that counts its bandwidth Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 24/39] sched/deadline: Keep the last CPU a task has in its root domain Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 25/39] cgroup/cpuset: Refuse to take a deadline task out of " Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 26/39] selftests/sched: Test the root domain of a task in deadline_bw_test Mathieu Desnoyers
2026-12-03 17:25   ` sashiko-bot
2026-12-03 14:58 ` [PATCH v14 27/39] sched/deadline: Count only active CPUs when spreading extra_bw Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 28/39] sched/deadline: Cancel the replenishment timer with the parameters Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 29/39] sched/deadline: Cap the runtime left of a constrained task at dl_runtime Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 30/39] sched/deadline: Check the runtime of a task that comes back runnable Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 31/39] sched/deadline: Record the start of the period Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 32/39] sched/deadline: Keep the debt of a task across a change of parameters Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 33/39] selftests/sched: Test parameter changes in deadline_bw_test Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 34/39] sched/deadline: Count a task that departs while a rebuild walks the tasks Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 35/39] sched/deadline: Count again a departed task that a boost brings back Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 36/39] sched/deadline: Keep a reaped deadline task in a rebuild Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 37/39] sched/deadline: Warn when a runqueue keeps the bandwidth of a task Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 38/39] selftests/sched: Test PI against hotplug and rebuilds in deadline_bw_test Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 39/39] selftests/sched: Share the helpers of the deadline tests 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-248180@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox