mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andrea Righi <arighi@nvidia.com>
To: Peter Zijlstra <peterz@infradead.org>, Tejun Heo <tj@kernel.org>
Cc: Ingo Molnar <mingo@redhat.com>,
	Juri Lelli <juri.lelli@redhat.com>,
	Vincent Guittot <vincent.guittot@linaro.org>,
	Dietmar Eggemann <dietmar.eggemann@arm.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Ben Segall <bsegall@google.com>, Mel Gorman <mgorman@suse.de>,
	Valentin Schneider <vschneid@redhat.com>,
	K Prateek Nayak <kprateek.nayak@amd.com>,
	John Stultz <jstultz@google.com>,
	David Vernet <void@manifault.com>,
	Changwoo Min <changwoo@igalia.com>, Tao Cui <cuitao@kylinos.cn>,
	sched-ext@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: [PATCH 4/4] selftests/sched_ext: Check that blocked donors are never enqueued unadmitted
Date: Thu, 26 Nov 2026 12:14:00 +0100	[thread overview]
Message-ID: <20261126111649.208476-5-arighi@nvidia.com> (raw)
In-Reply-To: <20261126111649.208476-1-arighi@nvidia.com>

enq_blocked attaches the BPF scheduler while the fair class retains a
mutex-blocked donor, so the root enable moves the donor into sched_ext
through switching_to_scx(), the same path taken by every other class
transition into sched_ext, such as PI deboost or sched_setscheduler().

On top of the donor state checks, verify that ops.enqueue() never sees a
retained donor without SCX_ENQ_BLOCKED during the whole run, including
the scheduler attachment. A full wakeup enqueue happens before
is_blocked is cleared, so SCX_ENQ_WAKEUP enqueues are not counted.

Signed-off-by: Andrea Righi <arighi@nvidia.com>
---
 tools/testing/selftests/sched_ext/enq_blocked.bpf.c |  9 +++++++++
 tools/testing/selftests/sched_ext/enq_blocked.c     | 11 +++++++++--
 2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/sched_ext/enq_blocked.bpf.c b/tools/testing/selftests/sched_ext/enq_blocked.bpf.c
index 212690bf4e07b..72d562f16b694 100644
--- a/tools/testing/selftests/sched_ext/enq_blocked.bpf.c
+++ b/tools/testing/selftests/sched_ext/enq_blocked.bpf.c
@@ -20,6 +20,7 @@ u64 nr_blocked_enqueues_donor_cpu;
 u64 nr_blocked_enqueues_owner_cpu;
 u64 nr_blocked_enqueues_other_cpu;
 u64 nr_blocked_wakeups;
+u64 nr_unadmitted_enqueues;
 static u64 vtime_now;
 
 UEI_DEFINE(uei);
@@ -34,6 +35,14 @@ void BPF_STRUCT_OPS(enq_blocked_enqueue, struct task_struct *p, u64 enq_flags)
 {
 	u64 vtime = p->scx.dsq_vtime;
 
+	/*
+	 * A retained proxy donor must only be enqueued with SCX_ENQ_BLOCKED. A
+	 * full wakeup enqueue happens before is_blocked is cleared.
+	 */
+	if (p->pid == donor_pid && p->is_blocked &&
+	    !(enq_flags & (SCX_ENQ_BLOCKED | SCX_ENQ_WAKEUP)))
+		__sync_fetch_and_add(&nr_unadmitted_enqueues, 1);
+
 	if (enq_flags & SCX_ENQ_BLOCKED) {
 		int cpu = scx_bpf_task_cpu(p);
 
diff --git a/tools/testing/selftests/sched_ext/enq_blocked.c b/tools/testing/selftests/sched_ext/enq_blocked.c
index 54ee5633c5720..ec6ffb9625fb8 100644
--- a/tools/testing/selftests/sched_ext/enq_blocked.c
+++ b/tools/testing/selftests/sched_ext/enq_blocked.c
@@ -497,7 +497,7 @@ static enum scx_test_status run_one(bool enq_blocked, bool cross_cpu,
 	size_t i, nr_contenders, nr_contenders_started = 0;
 	size_t nr_contenders_joined = 0;
 	u64 nr_blocked, nr_blocked_donor_cpu, nr_blocked_owner_cpu;
-	u64 nr_blocked_other_cpu, nr_blocked_wakeups;
+	u64 nr_blocked_other_cpu, nr_blocked_wakeups, nr_unadmitted;
 	struct enq_blocked_stats stats;
 
 	err = select_test_cpus(cross_cpu, &allowed_cpus, &thread_ctx.donor_cpu,
@@ -815,6 +815,7 @@ static enum scx_test_status run_one(bool enq_blocked, bool cross_cpu,
 	nr_blocked_owner_cpu = skel->bss->nr_blocked_enqueues_owner_cpu;
 	nr_blocked_other_cpu = skel->bss->nr_blocked_enqueues_other_cpu;
 	nr_blocked_wakeups = skel->bss->nr_blocked_wakeups;
+	nr_unadmitted = skel->bss->nr_unadmitted_enqueues;
 	result->nr_blocked_enqueues = nr_blocked;
 	result->nr_blocked_enqueues_donor_cpu = nr_blocked_donor_cpu;
 	result->nr_blocked_enqueues_owner_cpu = nr_blocked_owner_cpu;
@@ -830,8 +831,14 @@ static enum scx_test_status run_one(bool enq_blocked, bool cross_cpu,
 	       (unsigned long long)nr_blocked_other_cpu);
 	printf("  nr_blocked_wakeups=%llu\n",
 	       (unsigned long long)nr_blocked_wakeups);
+	printf("  nr_unadmitted_enqueues=%llu\n",
+	       (unsigned long long)nr_unadmitted);
 	if (status == SCX_TEST_PASS) {
-		if (enq_blocked && proxy_enabled && !nr_blocked) {
+		if (nr_unadmitted) {
+			SCX_ERR("ops.enqueue() received %llu blocked donors without SCX_ENQ_BLOCKED",
+				(unsigned long long)nr_unadmitted);
+			status = SCX_TEST_FAIL;
+		} else if (enq_blocked && proxy_enabled && !nr_blocked) {
 			SCX_ERR("ops.enqueue() did not receive the blocked donor");
 			status = SCX_TEST_FAIL;
 		} else if ((!enq_blocked || !proxy_enabled) && nr_blocked) {
-- 
2.56.1


      parent reply	other threads:[~2026-11-26 11:17 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-26 11:13 [PATCHSET sched_ext/for-7.5] sched/proxy: Handle retained donors on scheduling class transitions Andrea Righi
2026-11-26 11:13 ` [PATCH 1/4] sched: Let switching_to() decide whether to keep a retained proxy donor Andrea Righi
2026-11-26 16:01   ` Peter Zijlstra
2026-11-26 11:13 ` [PATCH 2/4] sched_ext: Make SCX_OPS_ENQ_BLOCKED a hierarchy-wide setting Andrea Righi
2026-11-26 11:13 ` [PATCH 3/4] sched: Remove sched_proxy_block_task() Andrea Righi
2026-11-26 11:14 ` 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=20261126111649.208476-5-arighi@nvidia.com \
    --to=arighi@nvidia.com \
    --cc=bsegall@google.com \
    --cc=changwoo@igalia.com \
    --cc=cuitao@kylinos.cn \
    --cc=dietmar.eggemann@arm.com \
    --cc=jstultz@google.com \
    --cc=juri.lelli@redhat.com \
    --cc=kprateek.nayak@amd.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mgorman@suse.de \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=sched-ext@lists.linux.dev \
    --cc=tj@kernel.org \
    --cc=vincent.guittot@linaro.org \
    --cc=void@manifault.com \
    --cc=vschneid@redhat.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

all inboxes | Powered by JetHome®