From: sashiko-bot@kernel.org
To: "Kuba Piecuch" <jpiecuch@google.com>
Cc: sched-ext@lists.linux.dev
Subject: Re: [PATCH 2/2] selftests/sched_ext: Add core_forceidle test for voluntary idle picks
Date: Tue, 01 Dec 2026 12:26:52 +0000 [thread overview]
Message-ID: <sashiko-outbox-243256@kernel.org> (raw)
In-Reply-To: <20261201120123.3678974-3-jpiecuch@google.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] selftests/sched_ext: Phase 2 in run() bypasses core-wide
pick_next_task()
--
commit ad2b5e66c62d106475f2b8ad4083ca89741fc68e
Author: Kuba Piecuch <jpiecuch@google.com>
selftests/sched_ext: Add core_forceidle test for voluntary idle picks
This commit adds a sched_ext selftest that verifies core-scheduling
forced-idle accounting across three phases when a task with a core cookie
is parked on a user DSQ and its CPU voluntarily picks idle.
> diff --git a/tools/testing/selftests/sched_ext/core_forceidle.bpf.c b/tools/testing/selftests/sched_ext/core_forceidle.bpf.c
> new file mode 100644
> index 0000000000000..12c8be46cc126
> --- /dev/null
> +++ b/tools/testing/selftests/sched_ext/core_forceidle.bpf.c
> @@ -0,0 +1,176 @@
[ ... ]
> +void BPF_STRUCT_OPS(core_forceidle_enqueue, struct task_struct *p, u64 enq_flags)
> +{
> + u32 ph = phase;
> +
> + if (p->pid == parked_pid) {
> + if ((ph == 1 || ph == 2) && (enq_flags & SCX_ENQ_LAST)) {
> + scx_bpf_dsq_insert(p, PARK_DSQ, 1000000ULL, enq_flags);
> + parked_in_dsq = 1;
> + return;
> + }
> + scx_bpf_dsq_insert(p, SCX_DSQ_LOCAL, 1000000ULL, enq_flags);
> + return;
> + }
> +
> + if (p->pid == busy_pid) {
> + scx_bpf_dsq_insert(p, SCX_DSQ_LOCAL, SCX_SLICE_DFL, enq_flags);
> + return;
> + }
> +
> + scx_bpf_dsq_insert(p, SCX_DSQ_GLOBAL, SCX_SLICE_DFL, enq_flags);
> +}
> +
> +void BPF_STRUCT_OPS(core_forceidle_dispatch, s32 cpu, struct task_struct *prev)
> +{
> + if (cpu == sib0 && phase != 1 && phase != 2)
> + scx_bpf_dsq_move_to_local(PARK_DSQ, 0);
> +}
[ ... ]
> diff --git a/tools/testing/selftests/sched_ext/core_forceidle.c b/tools/testing/selftests/sched_ext/core_forceidle.c
> new file mode 100644
> index 0000000000000..962863b3c0c19
> --- /dev/null
> +++ b/tools/testing/selftests/sched_ext/core_forceidle.c
> @@ -0,0 +1,490 @@
[ ... ]
> +static enum scx_test_status run(void *ctx_ptr)
> +{
> + struct core_forceidle_ctx *ctx = ctx_ptr;
> + struct core_forceidle *skel = ctx->skel;
> + struct worker_state parked_st = { .wake_pipe = { -1, -1 }, .ready_pipe = { -1, -1 } };
> + struct worker_state busy_st = { .wake_pipe = { -1, -1 }, .ready_pipe = { -1, -1 } };
> + struct bpf_link *link = NULL;
> + enum scx_test_status status = SCX_TEST_FAIL;
> + char c = 1;
> +
> + if (start_worker(&parked_st, ctx->sib0, true, false)) {
> + SCX_ERR("Failed to start parked worker");
> + goto out;
> + }
> + /*
> + * Leave busy_st untagged (cookie 0) so unrelated untagged kernel
> + * threads on sib0 match it in Phase 2 instead of causing genuine
> + * forced idle, while Phase 3 still sees a cookie mismatch against
> + * parked_st.
> + */
> + if (start_worker(&busy_st, ctx->sib1, false, true)) {
> + SCX_ERR("Failed to start busy worker");
> + goto out;
> + }
[ ... ]
> + /*
> + * Phase 1: sib0's cookied task is parked in PARK_DSQ on SCX_ENQ_LAST
> + * while sib1 is idle (occ == 0). Neither sibling is forced idle.
> + */
> + __atomic_store_n(&skel->bss->phase, 1, __ATOMIC_RELEASE);
> + if (!wait_u32_nonzero(&skel->bss->phase1_obs, WAIT_TIMEOUT_MS)) {
> + SCX_ERR("Phase 1: sib0 never entered voluntary idle");
> + goto out;
> + }
> + /* Let ticks fire so __sched_core_account_forceidle() runs if buggy. */
> + usleep(50000);
> +
> + /*
> + * Phase 2: sib0 stays voluntarily idle with parked_pid in PARK_DSQ
> + * while busy_pid (different cookie) runs on sib1 (occ == 1).
> + */
> + __atomic_store_n(&skel->bss->phase, 2, __ATOMIC_RELEASE);
> + __atomic_store_n(&busy_st.pause_flag, 0, __ATOMIC_RELEASE);
> + if (write(busy_st.wake_pipe[1], &c, 1) != 1) {
> + SCX_ERR("Phase 2: failed to wake busy worker");
> + goto out;
> + }
[Severity: Medium]
Does Phase 2 ever enter the core-wide selection loop in pick_next_task()?
When Phase 1 parks parked_st in PARK_DSQ and both siblings pick idle,
pick_next_task() resets rq->core->core_cookie to 0 while
rq->core->core_forceidle_count remains 0. Because
core_forceidle_dispatch() keeps PARK_DSQ parked when phase is 2,
parked_st never runs on sib0 between Phase 1 and Phase 2, and the
ph == 2 branch in core_forceidle_enqueue() is never reached.
When Phase 2 wakes untagged busy_st (core_cookie == 0) on sib1,
pick_next_task() sees !need_sync && !next->core_cookie and takes the
single-rq fast path to out_set_next, bypassing the core-wide sibling loop
where occ == 1 and core_forceidle_count are evaluated. Also, busy_running
in core_forceidle.bpf.c is updated in running/stopping but never read.
Should parked_st be unparked once busy_st is running on sib1 so that
sib0 enters Phase 2 with a non-zero core_cookie before re-parking on
SCX_ENQ_LAST?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261201120123.3678974-1-jpiecuch@google.com?part=2
next prev parent reply other threads:[~2026-12-01 12:26 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 12:03 [PATCH 0/2] sched/core: Don't count voluntary idle picks as forced idle Kuba Piecuch
2026-12-01 12:03 ` [PATCH 1/2] " Kuba Piecuch
2026-12-01 15:11 ` Tejun Heo
2026-12-01 12:03 ` [PATCH 2/2] selftests/sched_ext: Add core_forceidle test for voluntary idle picks Kuba Piecuch
2026-12-01 12:26 ` sashiko-bot [this message]
2026-12-01 15:15 ` Kuba Piecuch
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-243256@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=jpiecuch@google.com \
--cc=sashiko-reviews@lists.linux.dev \
--cc=sched-ext@lists.linux.dev \
/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.