From: Andrea Righi <arighi@nvidia.com>
To: Jonathan Bastari Thamrin <thamrinjonathan@gmail.com>
Cc: Tejun Heo <tj@kernel.org>, David Vernet <void@manifault.com>,
Changwoo Min <changwoo@igalia.com>, Shuah Khan <shuah@kernel.org>,
Joel Fernandes <joelagnelf@nvidia.com>,
Emil Tsalapatis <emil@etsalapatis.com>,
"Peter Zijlstra (Intel)" <peterz@infradead.org>,
sched-ext@lists.linux.dev, linux-kselftest@vger.kernel.org,
linux-kernel@vger.kernel.org,
Ihor Solodrai <ihor.solodrai@linux.dev>,
Cheng-Yang Chou <yphbchou0911@gmail.com>
Subject: Re: [PATCH sched_ext for-7.4-fixes v2] selftests/sched_ext: Fix flaky rt_stall measurement
Date: Sun, 15 Nov 2026 16:48:31 +0100 [thread overview]
Message-ID: <avnUTwcpMLKf1LwR@gpd4> (raw)
In-Reply-To: <20261115-scx-rt-stall-v2-1-926678b214c6@gmail.com>
Hi Jonathan,
On Sun, Nov 15, 2026 at 10:11:23PM +0700, Jonathan Bastari Thamrin wrote:
> In sched_stress_test(), the DL server budget on CORE_ID is shared with
> other FAIR/EXT tasks, including the parent task when unpinned. The
> parent can also be slow to start as it has to wait for the DL server
> before reaching sleep() while the RT task still runs. The runtime of
> each task is read as a total since fork instead of during sleep() and
> is measured in USER_HZ units (10ms). These 3 factors skew the ratio and
> cause CI flakes. An EXT task got as little as ~0.18s on CI, which is a
> 3.0-3.9% share against a minimum 4%.
This may not fully fix the CI flakes, since per-CPU kthreads on CORE_ID
can still consume the budget, but it's definitely an improvement. Maybe
just say "reduce measurement noise" instead of "fix CI flakes". And we
can lower the threshold later, if we still see same flakiness.
>
> With the parent pinned to CORE_ID, the RT task had already run for
> ~0.95s before sleep(), so it was measured at 5.69s in a 5s window and
> the EXT share dropped to ~4.2% against the 4% threshold.
>
> Measure CPU time using per-task CPU clocks via clock_getcpuclockid()
> with deltas before and after sleep to get an accurate measurement
> window while also pinning the parent off CORE_ID. With the parent
> pinned to another CPU, RT measures ~4.75s and EXT share stays between
> 4.86% and 5.10% over 20 runs.
>
> Fixes: be621a76341c ("selftests/sched_ext: Add test for sched_ext dl_server")
> Link: https://github.com/kernel-patches/vmtest/issues/458
> Suggested-by: Andrea Righi <arighi@nvidia.com>
> Cc: Ihor Solodrai <ihor.solodrai@linux.dev>
> Cc: Cheng-Yang Chou <yphbchou0911@gmail.com>
> Signed-off-by: Jonathan Bastari Thamrin <thamrinjonathan@gmail.com>
> ---
> Changes in v2:
> - Read CPU time with clock_getcpuclockid() and clock_gettime() instead of
> /proc/<pid>/stat to avoid USER_HZ rounding (Andrea)
> - Pin parent off CORE_ID so it doesn't share DL server budget (Andrea)
> - Threshold unchanged: 4.86-5.10% over 20 runs, but was unable to
> reproduce kthreads noise similar to CI, happy to lower threshold to 3%
> if needed
> - Link to v1: https://lore.kernel.org/r/20261114-scx-rt-stall-v1-1-4188a9378067@gmail.com
> ---
> tools/testing/selftests/sched_ext/rt_stall.c | 88 ++++++++++++++++++++--------
> 1 file changed, 65 insertions(+), 23 deletions(-)
>
> diff --git a/tools/testing/selftests/sched_ext/rt_stall.c b/tools/testing/selftests/sched_ext/rt_stall.c
> index a1552b38a6e8..c5027fd6b682 100644
> --- a/tools/testing/selftests/sched_ext/rt_stall.c
> +++ b/tools/testing/selftests/sched_ext/rt_stall.c
> @@ -21,6 +21,9 @@
> #define CORE_ID 0 /* CPU to pin tasks to */
> #define RUN_TIME 5 /* How long to run the test in seconds */
>
> +static cpu_set_t old_mask;
> +static bool affinity_saved;
> +
> /* Signal the parent that setup is complete by writing to a pipe */
> static void signal_ready(int fd)
> {
> @@ -82,43 +85,57 @@ static void set_sched(int policy, int priority)
> }
> }
>
> -/* Get process runtime from /proc/<pid>/stat */
> +/* Get process runtime from CPU clock */
> static float get_process_runtime(int pid)
> {
> - char path[256];
> - FILE *file;
> - long utime, stime;
> - int fields;
> -
> - snprintf(path, sizeof(path), "/proc/%d/stat", pid);
> - file = fopen(path, "r");
> - if (file == NULL) {
> - perror("Failed to open stat file");
> + clockid_t clk;
> + struct timespec ts;
> + int err;
> +
> + err = clock_getcpuclockid(pid, &clk);
> + if (err) {
> + fprintf(stderr, "Failed to get clock ID: %s\n", strerror(err));
> + return -1;
> + }
> +
> + if (clock_gettime(clk, &ts) == -1) {
> + perror("Failed to get clock time");
> return -1;
> }
>
> - /* Skip the first 13 fields and read the 14th and 15th */
> - fields = fscanf(file,
> - "%*d %*s %*c %*d %*d %*d %*d %*d %*u %*u %*u %*u %*u %lu %lu",
> - &utime, &stime);
> - fclose(file);
> + return ts.tv_sec + ts.tv_nsec / 1e9;
> +}
>
> - if (fields != 2) {
> - fprintf(stderr, "Failed to read stat file\n");
> +/* Move parent off of CORE_ID so it doesn't share DL server budget */
> +static int pin_parent_off_core(void)
> +{
> + if (sched_getaffinity(0, sizeof(old_mask), &old_mask) != 0) {
> + perror("sched_getaffinity");
> return -1;
> }
>
> - /* Calculate the total time spent in the process */
> - long total_time = utime + stime;
> - long ticks_per_second = sysconf(_SC_CLK_TCK);
> - float runtime_seconds = total_time * 1.0 / ticks_per_second;
> + for (int cpu = 0; cpu < CPU_SETSIZE; cpu++) {
> + if (CPU_ISSET(cpu, &old_mask) && cpu != CORE_ID) {
> + cpu_set_t mask;
> +
> + CPU_ZERO(&mask);
> + CPU_SET(cpu, &mask);
> + if (sched_setaffinity(0, sizeof(mask), &mask)) {
> + perror("sched_setaffinity");
> + return -1;
> + }
> + affinity_saved = true;
> + return 0;
> + }
> + }
>
> - return runtime_seconds;
> + return 1; /* No other CPU available */
> }
>
> static enum scx_test_status setup(void **ctx)
> {
> struct rt_stall *skel;
> + int err;
>
> if (!__COMPAT_struct_has_field("rq", "ext_server")) {
> fprintf(stderr, "SKIP: ext DL server not supported\n");
> @@ -132,6 +149,9 @@ static enum scx_test_status setup(void **ctx)
>
> *ctx = skel;
>
> + err = pin_parent_off_core();
> + SCX_FAIL_IF(err == -1, "Failed to pin parent CPU");
> +
> return SCX_TEST_PASS;
> }
>
> @@ -149,7 +169,7 @@ static bool sched_stress_test(bool is_ext)
> const float expected_min_ratio = 0.04; /* 4% */
While at it, can you also add a comment mentionig that the dl_server
budget is shared with the other EXT/FAIR tasks on CORE_ID (e.g., per-CPU
kthreads, etc.)?
With these small changes:
Reviewed-by: Andrea Righi <arighi@nvidia.com>
Thanks,
-Andrea
prev parent reply other threads:[~2026-11-15 15:48 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-15 15:11 [PATCH sched_ext for-7.4-fixes v2] selftests/sched_ext: Fix flaky rt_stall measurement Jonathan Bastari Thamrin
2026-11-15 15:11 ` Jonathan Bastari Thamrin via B4 Relay
2026-11-15 15:19 ` sashiko-bot
2026-11-15 15:48 ` Andrea Righi [this message]
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=avnUTwcpMLKf1LwR@gpd4 \
--to=arighi@nvidia.com \
--cc=changwoo@igalia.com \
--cc=emil@etsalapatis.com \
--cc=ihor.solodrai@linux.dev \
--cc=joelagnelf@nvidia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=peterz@infradead.org \
--cc=sched-ext@lists.linux.dev \
--cc=shuah@kernel.org \
--cc=thamrinjonathan@gmail.com \
--cc=tj@kernel.org \
--cc=void@manifault.com \
--cc=yphbchou0911@gmail.com \
/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.