All of lore.kernel.org
 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 v8 05/33] selftests/sched: Test SCHED_DEADLINE bandwidth across a root domain rebuild
Date: Thu, 19 Nov 2026 20:28:50 +0000	[thread overview]
Message-ID: <sashiko-outbox-224022@kernel.org> (raw)
In-Reply-To: <2c85e2efab1ae7eb89b6d6e334c933348486c542.1795116790.git.mathieu.desnoyers@efficios.com>

Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [Medium] selftests/sched: missing isolated/sparse CPU handling and
  code duplication
- [Low] selftests/sched: missing 0-lag wait on early exit in
  test_rebuild()
- [Low] selftests/sched: undersized path buffer in make_partition()
- [Low] selftests/sched: missing PR_SET_PDEATHSIG in departing() and
  sleeper()
--

commit 61b9ca4442ef766ed51f3c6ad77a1ac959261741
Author: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>

selftests/sched: Test SCHED_DEADLINE bandwidth across a root domain rebuild

This commit adds the deadline_rebuild_test selftest to verify that
SCHED_DEADLINE bandwidth of tasks that exit or leave the policy before
their 0-lag time is preserved across cpuset partition root domain
rebuilds.

> 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..714a0ff03f1b9
> --- /dev/null
> +++ b/tools/testing/selftests/sched/deadline/deadline_rebuild_test.c
> @@ -0,0 +1,497 @@

[ ... ]

> +/* 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], 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;
> +	snprintf(path, sizeof(path), "%s/cpuset.cpus.partition", cg);
> +	if (read_file(path, buf, sizeof(buf)) || strcmp(buf, "root\n"))
> +		return -1;
> +	return 0;
> +}

[Severity: Low]
Can snprintf() truncate path[] here and trigger a -Wformat-truncation
warning when make_partition() is inlined with cg_p or cg_q (which are
sized PATH_MAX)?  Sizing path[] to PATH_MAX + 32, as main() does for
cgroup.subtree_control, avoids the truncation warning.

[ ... ]

> +static pid_t departing(const char *cg, enum depart how, int fd[2])
> +{
> +	pid_t pid = fork();
> +
> +	if (pid < 0)
> +		ksft_print_msg("fork: %s\n", strerror(errno));
> +	if (!pid) {
> +		uint64_t t0;
> +
> +		close(fd[0]);
> +		if (cg && enter(cg, getpid()))
> +			_exit(2);
> +		if (set_deadline(0, 400 * NSEC_PER_MSEC))
> +			_exit(3);
> +		t0 = cpu_time_ns();
> +		while (cpu_time_ns() - t0 < 380 * NSEC_PER_MSEC)
> +			;
> +		if (how == DIES)
> +			_exit(0);
> +		if (set_other(0) || write(fd[1], "x", 1) != 1)
> +			_exit(4);
> +		for (;;)
> +			pause();
> +	}

[ ... ]

> +static pid_t sleeper(const char *cg)
> +{
> +	int fd[2];
> +	pid_t pid;
> +	char c;
> +
> +	if (pipe(fd))
> +		return -1;
> +	pid = fork();
> +	if (pid < 0)
> +		ksft_print_msg("fork: %s\n", strerror(errno));
> +	if (!pid) {
> +		close(fd[0]);
> +		if (enter(cg, getpid()) || write(fd[1], "x", 1) != 1)
> +			_exit(1);
> +		for (;;)
> +			pause();
> +	}

[Severity: Low]
If the test runner is killed by a signal or kselftest timeout while
children from departing() or sleeper() are alive, will those children stay
blocked in pause() inside cg_p holding SCHED_DEADLINE bandwidth and
preventing cg_p from being removed?  Using a fork_child() helper with
prctl(PR_SET_PDEATHSIG, SIGKILL), like deadline_switch_test.c and
deadline_bw_test.c do, ensures children exit with the test.

[ ... ]

> +static int test_rebuild(enum depart how)
> +{
> +	int ret = KSFT_FAIL, fd[2], err;
> +	pid_t pid = -1;
> +
> +	if (pipe(fd))
> +		return KSFT_FAIL;
> +	if (make_partition(cg_p, ncpus - 1)) {
> +		ksft_print_msg("no partition root on CPU %d\n", ncpus - 1);
> +		ret = KSFT_SKIP;
> +		goto out;
> +	}
> +	pid = departing(cg_p, how, fd);
> +	err = departed(&pid, how, fd[0]);
> +	if (err) {
> +		ksft_print_msg("the deadline task failed (%d)\n", err);
> +		goto out;
> +	}
> +	if (make_partition(cg_q, ncpus - 2)) {
> +		ksft_print_msg("no partition root on CPU %d\n", ncpus - 2);
> +		ret = KSFT_SKIP;
> +		goto out;
> +	}
> +	/*
> +	 * Wait past the 0-lag time. In the SWITCHED_OUT case the task is still
> +	 * alive then: it sleeps in P as a SCHED_OTHER task.
> +	 */
> +	sleep_ns(1500 * NSEC_PER_MSEC);
> +	ret = check_p();
> +out:
> +	reap(pid);
> +	remove_partition(cg_q);
> +	remove_partition(cg_p);
> +	close(fd[0]);
> +	if (fd[1] >= 0)
> +		close(fd[1]);
> +	return ret;
> +}
> +
> +/*
> + * Have a task outside P switch to SCHED_OTHER and sleep. Before its 0-lag
> + * time, move it into P and kill it. Then check P.
> + */
> +static int test_move(void)
> +{
> +	int ret = KSFT_FAIL, fd[2], err;
> +	pid_t pid = -1;
> +
> +	if (pipe(fd))
> +		return KSFT_FAIL;
> +	if (make_partition(cg_p, ncpus - 1)) {
> +		ksft_print_msg("no partition root on CPU %d\n", ncpus - 1);
> +		ret = KSFT_SKIP;
> +		goto out;
> +	}
> +	pid = departing(NULL, SWITCHED_OUT, fd);
> +	err = departed(&pid, SWITCHED_OUT, fd[0]);
> +	if (err) {
> +		ksft_print_msg("the deadline task failed (%d)\n", err);
> +		goto out;
> +	}
> +	if (enter(cg_p, pid)) {
> +		ksft_print_msg("the task cannot move into P\n");
> +		goto out;
> +	}

[Severity: Low]
If make_partition(cg_q, ncpus - 2) in test_rebuild() or enter(cg_p, pid)
in test_move() fails after departed() has succeeded, does jumping directly
to out skip waiting for the departed task's 0-lag inactive timer?  The
next test case in main() would then start while the 400ms/1000ms bandwidth
is still pending removal from the root domain.

[ ... ]

> +int main(void)
> +{
> +	char buf[256], path[PATH_MAX + 32];
> +	int added;
> +
> +	ksft_print_header();
> +	if (geteuid())
> +		ksft_exit_skip("needs root\n");
> +	ncpus = get_nprocs();
> +	if (ncpus < 3)
> +		ksft_exit_skip("needs 3 CPUs\n");

[Severity: Medium]
Can picking CPUs ncpus - 1 and ncpus - 2 from get_nprocs() fail when
online CPU numbering has gaps or when isolcpus=domain is configured?

Unlike deadline_bw_test.c, which reads /sys/devices/system/cpu/online and
/sys/devices/system/cpu/isolated, picks online non-isolated CPUs, and
restricts task affinity away from isolated CPUs, this test assumes online
CPUs are contiguously numbered 0..ncpus-1 and none are isolated.  When
isolcpus=domain is used (which deadline_bw_test.c requires for many of its
cases), ncpus - 1 or ncpus - 2 can be isolated or offline, and in
test_move() the child spawned by departing(NULL, SWITCHED_OUT, fd)
inherits root-cgroup affinity that includes isolated CPUs, causing
set_deadline() to fail.

Since roughly half of this file duplicates the cgroup v2, partition, and
SCHED_DEADLINE helpers from deadline_bw_test.c in the same directory,
could these helpers be shared (or these three cases folded into
deadline_bw_test.c) so online and isolated CPUs are handled consistently?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1795116790.git.mathieu.desnoyers@efficios.com?part=5

  reply	other threads:[~2026-11-19 20:28 UTC|newest]

Thread overview: 57+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19 20:15 [PATCH v8 00/33] sched/deadline: bandwidth accounting fixes and selftests Mathieu Desnoyers
2026-11-19 20:15 ` [PATCH v8 01/33] sched/deadline: Keep departing bandwidth across a root domain rebuild Mathieu Desnoyers
2026-11-19 20:15 ` [PATCH v8 02/33] sched/deadline: Rebuild the root domains' accounting from the task list Mathieu Desnoyers
2026-11-19 20:15 ` [PATCH v8 03/33] sched/deadline: Record the root domain holding a task's bandwidth Mathieu Desnoyers
2026-11-19 20:51   ` sashiko-bot
2026-11-20 13:48     ` Mathieu Desnoyers
2026-11-19 20:15 ` [PATCH v8 04/33] sched/deadline: Leave a dying task out of a rebuild of the accounting Mathieu Desnoyers
2026-11-19 20:15 ` [PATCH v8 05/33] selftests/sched: Test SCHED_DEADLINE bandwidth across a root domain rebuild Mathieu Desnoyers
2026-11-19 20:28   ` sashiko-bot [this message]
2026-11-20 13:49     ` Mathieu Desnoyers
2026-11-19 20:15 ` [PATCH v8 06/33] selftests/sched: Test the root domain rebuild in deadline_bw_test Mathieu Desnoyers
2026-11-19 20:15 ` [PATCH v8 07/33] sched/deadline: Move a task's bandwidth only where room was made Mathieu Desnoyers
2026-11-19 20:15 ` [PATCH v8 08/33] cgroup/cpuset: Wait for an attach before rebuilding the sched domains Mathieu Desnoyers
2026-11-19 20:15 ` [PATCH v8 09/33] sched: Make deadline policy and affinity changes wait for a cpuset attach Mathieu Desnoyers
2026-11-19 20:15 ` [PATCH v8 10/33] cgroup/cpuset: Give back the bandwidth an attach did not move Mathieu Desnoyers
2026-11-19 20:15 ` [PATCH v8 11/33] cgroup/cpuset: Reserve the bandwidth in the root domain a task moves to Mathieu Desnoyers
2026-11-19 20:15 ` [PATCH v8 12/33] selftests/sched: Test cpuset moves in deadline_bw_test Mathieu Desnoyers
2026-11-19 20:15 ` [PATCH v8 13/33] sched/deadline: Make a rebuild count a task in the root domain it runs in Mathieu Desnoyers
2026-11-19 20:15 ` [PATCH v8 14/33] sched/deadline: Move a task's bandwidth to " Mathieu Desnoyers
2026-11-19 20:53   ` sashiko-bot
2026-11-20 13:49     ` Mathieu Desnoyers
2026-11-19 20:15 ` [PATCH v8 15/33] sched/deadline: Keep a task in the root domain that counts its bandwidth Mathieu Desnoyers
2026-11-19 20:55   ` sashiko-bot
2026-11-20 13:50     ` Mathieu Desnoyers
2026-11-19 20:15 ` [PATCH v8 16/33] sched/deadline: Keep the last CPU a task has in its root domain Mathieu Desnoyers
2026-11-19 20:22   ` Mathieu Desnoyers
2026-11-19 20:48   ` sashiko-bot
2026-11-20 13:51     ` Mathieu Desnoyers
2026-11-19 20:15 ` [PATCH v8 17/33] cgroup/cpuset: Refuse to take a deadline task out of " Mathieu Desnoyers
2026-11-19 20:43   ` sashiko-bot
2026-11-20 13:51     ` Mathieu Desnoyers
2026-11-19 20:15 ` [PATCH v8 18/33] selftests/sched: Test the root domain of a task in deadline_bw_test Mathieu Desnoyers
2026-11-19 20:27   ` sashiko-bot
2026-11-20 13:51     ` Mathieu Desnoyers
2026-11-19 20:15 ` [PATCH v8 19/33] sched/deadline: Count only active CPUs when spreading extra_bw Mathieu Desnoyers
2026-11-19 20:15 ` [PATCH v8 20/33] rtmutex: Continue the chain walk when a waiter's deadline donor changes Mathieu Desnoyers
2026-11-19 20:16 ` [PATCH v8 21/33] rtmutex: Continue the walk when the owner's top waiter changes lock Mathieu Desnoyers
2026-11-19 20:16 ` [PATCH v8 22/33] selftests/sched: Test the rtmutex chain walk in deadline_bw_test Mathieu Desnoyers
2026-11-19 20:16 ` [PATCH v8 23/33] sched/deadline: Reset the donor's runtime at a deboost in the class Mathieu Desnoyers
2026-11-19 20:53   ` sashiko-bot
2026-11-20 13:52     ` Mathieu Desnoyers
2026-11-19 20:16 ` [PATCH v8 24/33] sched/deadline: Replenish a throttled task boosted while asleep Mathieu Desnoyers
2026-11-19 20:16 ` [PATCH v8 25/33] sched/deadline: Count the bandwidth a boosted task is given Mathieu Desnoyers
2026-11-19 20:16 ` [PATCH v8 26/33] sched/deadline: Start a period for a task that enters the class blocked Mathieu Desnoyers
2026-11-19 20:57   ` sashiko-bot
2026-11-20 13:52     ` Mathieu Desnoyers
2026-11-19 20:16 ` [PATCH v8 27/33] sched/deadline: Start a period at a deboost out of the class Mathieu Desnoyers
2026-11-19 20:47   ` sashiko-bot
2026-11-20 13:53     ` Mathieu Desnoyers
2026-11-19 20:16 ` [PATCH v8 28/33] selftests/sched: Test deadline boosts in deadline_bw_test Mathieu Desnoyers
2026-11-19 20:16 ` [PATCH v8 29/33] sched/deadline: Cancel the replenishment timer with the parameters Mathieu Desnoyers
2026-11-19 20:16 ` [PATCH v8 30/33] sched/deadline: Cap the runtime left of a constrained task at dl_runtime Mathieu Desnoyers
2026-11-19 20:16 ` [PATCH v8 31/33] sched/deadline: Check the runtime of a task that comes back runnable Mathieu Desnoyers
2026-11-19 20:16 ` [PATCH v8 32/33] sched/deadline: Check the runtime of a task whose parameters change Mathieu Desnoyers
2026-11-19 20:59   ` sashiko-bot
2026-11-20 13:53     ` Mathieu Desnoyers
2026-11-19 20:16 ` [PATCH v8 33/33] selftests/sched: Test parameter changes in deadline_bw_test 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-224022@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.