[PATCH 4/4] selftests/sched_ext: Check that blocked donors are never enqueued unadmitted
From: Andrea Righi
Date: Thu Nov 26 2026 - 06:18:09 EST
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@xxxxxxxxxx>
---
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