Sched_ext development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Cheng-Yang Chou" <yphbchou0911@gmail.com>
Cc: sched-ext@lists.linux.dev
Subject: Re: [PATCH 3/3] selftests/sched_ext: Add dispatch_cookie test
Date: Fri, 15 May 2026 18:19:21 +0000	[thread overview]
Message-ID: <20260515181922.6739CC2BCB3@smtp.kernel.org> (raw)
In-Reply-To: <20260515172807.254804-4-yphbchou0911@gmail.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] Child processes spin indefinitely and will leak if the parent terminates unexpectedly.
- [Medium] The dispatch operation returns immediately without attempting to dispatch another task if `bpf_task_from_pid()` fails, potentially leaving runnable tasks stranded.
--

commit 91ea259621d3c40168f6eb29f9526e50de76f0b2
Author: Cheng-Yang Chou <yphbchou0911@gmail.com>

selftests/sched_ext: Add dispatch_cookie test

This commit adds a new sched_ext selftest to exercise the dispatch
transaction API (scx_bpf_dsq_insert_begin and scx_bpf_dsq_insert_commit).
It uses a BPF scheduler with a queue map and a userspace program that forks
multiple spinning children, flipping their CPU affinities to trigger dequeue
and re-enqueue cycles.

> diff --git a/tools/testing/selftests/sched_ext/dispatch_cookie.bpf.c b/tools/testing/selftests/sched_ext/dispatch_cookie.bpf.c
> new file mode 100644
> index 0000000000000..160a77ed9000f
> --- /dev/null
> +++ b/tools/testing/selftests/sched_ext/dispatch_cookie.bpf.c

[ ... ]

> +void BPF_STRUCT_OPS(dispatch_cookie_dispatch, s32 cpu,
> +		    struct task_struct *prev)
> +{
> +	s32 pid;
> +	struct task_struct *p;
> +	u64 *stored, token;
> +
> +	if (bpf_map_pop_elem(&queue, &pid))
> +		return;
> +
> +	p = bpf_task_from_pid(pid);
> +	if (!p)
> +		return;

If a task exits and bpf_task_from_pid(pid) returns NULL, does returning
early here prevent other valid tasks in the queue from being dispatched?

Since ops.dispatch() expects a task to be inserted into a DSQ, would it be
better to loop and try popping another PID instead of returning immediately
and leaving the CPU idle?

[ ... ]

> diff --git a/tools/testing/selftests/sched_ext/dispatch_cookie.c b/tools/testing/selftests/sched_ext/dispatch_cookie.c
> new file mode 100644
> index 0000000000000..047d9ea1822b9
> --- /dev/null
> +++ b/tools/testing/selftests/sched_ext/dispatch_cookie.c

[ ... ]

> +	for (i = 0; i < NUM_CHILDREN; i++) {
> +		pids[i] = fork();
> +		if (pids[i] == 0) {
> +			while (1)
> +				sched_yield();
> +		}
> +		if (pids[i] > 0)
> +			nforked++;
> +	}

If the test is interrupted (e.g., via SIGINT, SIGTERM, or a test framework
timeout) before reaching the cleanup code, will these spinning children be
leaked and consume 100% of the CPUs indefinitely?

Could this be prevented by calling prctl(PR_SET_PDEATHSIG, SIGKILL) in the
child processes immediately after fork()?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260515172807.254804-1-yphbchou0911@gmail.com?part=3

      reply	other threads:[~2026-05-15 18:19 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-15 17:27 [PATCH v4 sched_ext/for-7.2 0/3] sched_ext: Add dispatch transaction API Cheng-Yang Chou
2026-05-15 17:27 ` [PATCH 1/3] sched_ext: Rename scx_dsq_insert_commit() to scx_dsq_insert_stage() Cheng-Yang Chou
2026-05-15 17:27 ` [PATCH 2/3] sched_ext: Add dispatch transaction API Cheng-Yang Chou
2026-05-15 17:59   ` sashiko-bot
2026-05-15 17:27 ` [PATCH 3/3] selftests/sched_ext: Add dispatch_cookie test Cheng-Yang Chou
2026-05-15 18:19   ` sashiko-bot [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=20260515181922.6739CC2BCB3@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=sched-ext@lists.linux.dev \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox