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 v14 38/39] selftests/sched: Test PI against hotplug and rebuilds in deadline_bw_test
Date: Thu, 03 Dec 2026 18:07:05 +0000	[thread overview]
Message-ID: <sashiko-outbox-248338@kernel.org> (raw)
In-Reply-To: <ceab3fa46a86f65e713bb4f465dfd302910f82ab.1796296314.git.mathieu.desnoyers@efficios.com>

Thank you for your contribution! Sashiko AI review found 7 potential
issues to consider:
- [Medium] selftests/sched: untracked continue in
  pi_deboost_during_rebuild() loop
- [Low] selftests/sched: race_w() publishes rs->w_tid before
  set_deadline()
- [Low] selftests/sched: unbounded dmax can pass 0-lag time in
  deadline_bw_test
- [Low] selftests/sched: pi_deboost_during_rebuild() fails instead of
  skipping
- [Low] selftests/sched: dmax calibrated before deadline tasks in
  deadline_bw_test
- [Low] selftests/sched: missing w_done check in
  pi_deboost_during_rebuild()
- [Low] selftests/sched: heavy sched/debug polling in
  pi_deboost_during_rebuild()
--

commit 422a087312079e778dce123e41c2cb32e6f07e4b
Author: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>

selftests/sched: Test PI against hotplug and rebuilds in deadline_bw_test

This commit adds two priority-inheritance test cases to deadline_bw_test:
pi_departed_offline_boost and pi_deboost_during_rebuild.

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

[ ... ]

> @@ -12504,6 +12663,322 @@ static int affinity_vs_setattr(void)

[ ... ]

> +static void *race_w(void *arg)
> +{
> +	int i = 0;
> +
> +	rs->w_tid = gettid_();
> +	if (set_deadline(0, RACE_W_RUNTIME, RACE_W_PERIOD)) {
> +		set_flag(&rs->w_err, -1);
> +		return arg;
> +	}

[Severity: Low]
Can publishing rs->w_tid before set_deadline() race with the parent's
startup check in pi_deboost_during_rebuild()?

parent                              W (race_w)
                                    rs->w_tid = gettid_()
wait_for(..., rs->w_tid && ...)
  sees rs->w_tid != 0, w_err == 0
                                    set_deadline(...) fails
                                      set_flag(&rs->w_err, -1)
                                      return arg
sleep_ns(100ms)
base = total_bw_of(...) - bw_w  <-- W was never admitted

Because rs->w_tid is visible before set_deadline() finishes, the parent can
pass its startup wait with rs->w_err == 0, compute a corrupted base, and
fail later in round 1 instead of catching the startup failure.  Even when
set_deadline() succeeds, a delay past the 100ms sleep leaves base off by
-bw_w.  Moving rs->w_tid = gettid_() after the set_deadline() check closes
both races.

[ ... ]

> +		if (enter(cg, getpid()) || pthread_mutexattr_init(&a) ||
> +		    pthread_mutexattr_setprotocol(&a, PTHREAD_PRIO_INHERIT) ||
> +		    pthread_mutex_init(&race_m, &a) || pthread_mutex_lock(&race_m) ||
> +		    pthread_create(&w, NULL, race_w, NULL)) {
> +			set_flag(&rs->w_err, -1);
> +			_exit(1);
> +		}

[Severity: Low]
Should missing PTHREAD_PRIO_INHERIT support skip the test instead of
failing it?

Other PI cases in deadline_bw_test.c (such as pi_init() callers and
shm_lock_init()) return KSFT_SKIP when PI mutex setup fails, whereas here
rs->w_err = -1 jumps to out: with ret left at KSFT_FAIL.  Distinguishing
PI mutex initialization failure from other setup errors would keep this
case consistent with kselftest policy on kernels without CONFIG_FUTEX_PI
or C libraries without PI mutex support.

[ ... ]

> +	/* The longest of 8 writes to Q sets the range of the timeouts. */
> +	for (i = 0; i < 8; i++) {
> +		uint64_t t = now_ns();
> +
> +		if (toggle_q(&q_root)) {
> +			ksft_print_msg("Q cannot change between root and member\n");
> +			ret = KSFT_SKIP;
> +			goto out;
> +		}
> +		d = now_ns() - t;
> +		if (d > dmax)
> +			dmax = d;
> +	}

[Severity: Low]
Does calibrating dmax before starting race_t(cg_r) miss the 1000-thread
tasklist walk?

When no SCHED_DEADLINE task exists yet, dl_nr_bw_tasks is 0 and
dl_rebuild_rd_accounting() returns early before walking
for_each_process_thread().  During the actual rounds, W and T are deadline
tasks, so the walk runs at the end of partition_sched_domains_locked() and
can fall past the 1.2 * dmax lead window, reducing race coverage.  Running
the 8 calibration writes after race_t(cg_r) starts W would measure the full
rebuild duration.

[ ... ]

> +		if (wait_for_step(100, 100 * NSEC_PER_USEC, proc_state_of(rs->t_tid) == 'S'))
> +			continue;

[Severity: Medium]
Can this continue allow pi_deboost_during_rebuild() to report KSFT_PASS
after executing zero rounds?

If runtime overhead exceeds the 2ms margin left after spin_ns(), T gets
throttled in state 'R' for ~180ms, exceeding the 100ms wait on every
iteration until the 25-second loop ends and unconditionally sets
ret = KSFT_PASS.  Tracking completed rounds and failing or skipping when
none complete would prevent a silent pass.

Also, jumping to continue skips set_other(rs->t_tid), so T stays in
SCHED_DEADLINE with identical parameters and the next round's
set_deadline() hits the no-op path in __sched_setscheduler() instead of
starting a fresh period.

> +		/* Leave W 20ms to block, then time out within the write. */
> +		lead = (int64_t)((double)rand() / RAND_MAX * 1.2 * dmax);
> +		abs = realtime_ns() + 20 * NSEC_PER_MSEC + dmax;
> +		rs->w_abs = abs;
> +		set_flag(&rs->w_go, i);
> +		if (wait_for_step(100, 100 * NSEC_PER_USEC, rs->w_blocked == i) ||
> +		    wait_for_step(100, 100 * NSEC_PER_USEC, proc_state_of(rs->w_tid) == 'S')) {
> +			ksft_print_msg("round %d: W did not block\n", i);
> +			goto out;
> +		}
> +		if (set_other(rs->t_tid)) {
> +			ksft_print_msg("round %d: T cannot leave SCHED_DEADLINE\n", i);
> +			goto out;
> +		}
> +		if (prio_of(rs->t_tid) != DL_TASK_PRIO) {
> +			ksft_print_msg("round %d: W does not boost T\n", i);
> +			goto out;
> +		}

[Severity: Low]
Can an early timeout of W trigger a spurious "W does not boost T" failure?

parent                              W (race_w)
abs = realtime_ns() + 20ms + dmax
set_flag(&rs->w_go, i)
                                    rs->w_blocked = i
                                    pthread_mutex_timedlock(&race_m, &ts)
(delayed > 20ms + dmax)               times out, deboosts T
                                    set_flag(&rs->w_done, i)
                                    wait_change(&rs->w_go, i)  (state 'S')
proc_state_of(rs->w_tid) == 'S'
set_other(rs->t_tid)
prio_of(rs->t_tid) != DL_TASK_PRIO  <-- spurious KSFT_FAIL

Because wait_change() also sleeps in state 'S', the parent cannot tell
whether W is still blocked on race_m or has already timed out and
deboosted T.  Checking rs->w_done == i before treating the prio check as a
kernel PI failure would distinguish an early timeout from a boost bug.

[ ... ]

> +		tb = total_bw_of(cpu[0]);
> +		if (tb != base + bw_w + bw_t) {
> +			ksft_print_msg("round %d: total_bw of R %lld, %lld expected%s\n",
> +				       i, tb, base + bw_w + bw_t,
> +				       tb == base + bw_w ? ": T is missing" : "");

[Severity: Low]
Can an uncapped dmax push this total_bw_of(cpu[0]) read past T's 0-lag
time and cause a false failure?

T's 0-lag time is at most ~162ms after it sleeps, while when lead is near
0, toggle_q() finishes roughly 20ms + 2 * dmax after T slept.  On slower,
virtualized, or debug kernels where dmax is ~70ms or more (or a single
rebuild stalls), T's inactive timer can legitimately release bw_t before
this read runs.  Bounding dmax or checking elapsed time since T slept, as
pi_departed_offline_boost() does, would avoid false KSFT_FAIL results.

[ ... ]

> +		/* Past the 0-lag time of T: R counts W only. */
> +		if (wait_for_step(1000, 5 * NSEC_PER_MSEC, total_bw_of(cpu[0]) == base + bw_w)) {

[Severity: Low]
Will polling total_bw_of(cpu[0]) every 5ms scale poorly on large SMP
systems?

Partition R is placed on top_cpu(4) and top_cpu(3), so each call to
total_bw_of(cpu[0]) streams /sys/kernel/debug/sched/debug across nearly
every online CPU, and print_rq() walks all threads (including the 1000
filler threads) under rcu_read_lock() for each CPU printed.  Polling every
5ms across T's ~100-130ms 0-lag wait cuts into round throughput and makes
the earlier total_bw_of(cpu[0]) read more likely to overrun the 0-lag
window; placing R on low-numbered CPUs or sleeping toward the 0-lag time
before polling would reduce that overhead.

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

  reply	other threads:[~2026-12-03 18:07 UTC|newest]

Thread overview: 61+ 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-04 17:26   ` Peter Zijlstra
2026-12-04 18:03     ` Mathieu Desnoyers
2026-12-04 18:23       ` Sebastian Andrzej Siewior
2026-12-04 18:38       ` Mathieu Desnoyers
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
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 17:39   ` sashiko-bot
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 17:42   ` sashiko-bot
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 17:56   ` sashiko-bot
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 18:01   ` sashiko-bot
2026-12-03 14:58 ` [PATCH v14 36/39] sched/deadline: Keep a reaped deadline task in a rebuild Mathieu Desnoyers
2026-12-03 18:14   ` sashiko-bot
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 18:05   ` sashiko-bot
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 18:07   ` sashiko-bot [this message]
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-248338@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.