From nobody Thu Apr 9 18:55:16 2026 Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2299E3AE708 for ; Fri, 6 Mar 2026 14:03:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772805826; cv=none; b=JSj3IsGjEEv7bQ0SC3NzmGfBvo4NNDpebbVGBVbWBeTMuvK0UV2hdJaaP+QWEW8R8ShsmVKaJLEZ4yUUbkAQUVPIJ8aF02rhsYtho5BacJJcTHI+NdXJhI1ArXp3WW3Upx2sJpB1WEA9uRKAYYDR5Eh43IDjROJ4KPSvmtQUEHM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772805826; c=relaxed/simple; bh=BZeeJ1JML7xaZoBvWAKlQYnkV7F90b7mZuzv0ATZ6Jw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JuFd1UrO2OB751tocm3p42kuTBTr2TjDeKZfthBcIW81GscLekybpYpWsbBrzgnVGFW4vZisRSlMswPrBO2nS+hU1yb36AyIELl1cTd7LnNBZMvJ8trPRZkI+BoKW99JGHf8n1UhWiAM5VCG8kejrBDjm8K1U3ZW8xf+FIOkBaM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=BTynWW/r; arc=none smtp.client-ip=209.85.214.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="BTynWW/r" Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-2a7a9b8ed69so104074225ad.2 for ; Fri, 06 Mar 2026 06:03:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1772805824; x=1773410624; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=6TnQKdPGtTuRU+46cutq94eviTJ71u1qZiPiKlbjQJQ=; b=BTynWW/rBPZ4TsF4UVh/IPVXD6/0mfdrGZdQmVJ48xToAKHY0g1CDJuqDZb2Zs6TIf wJoQNbl6uRp0C35s+bYbEPtQMCOsgD4En9gqjYPGle+Wr1LkW/TfKWj0P7FFrtLqxcdf KQ2E8sVGvXNIPvS5MeSOGgdVFq9ixcdh+xmyMyX4jTroAcuH/PLyeKz+RHVwkZTPb4et m7c0lKkfg10eG5RwdiAvirjJTSvTl/WInPiqj/mcM4KrU0j/DsDrolUpiG7nD7M9sUcO yuEB8L9izI5nFLyL0UKuGHcGHZKR8EK6zYOLnL4/FX6NS6DyuqVQSNsixd1BREiWzWfB YDdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772805824; x=1773410624; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=6TnQKdPGtTuRU+46cutq94eviTJ71u1qZiPiKlbjQJQ=; b=ruAePR3IJxDqmw1fJw9Ve6V2GqOgR9yncyBO7rixrIT/slIEJJEwB9PNOyUnwRSVKI kDywpl4RMrIvFLN1cvdvigs18iIpdr0Oj8WXhK+ihtMKp6948viWlH/2IO2rj9d7LPfn HB8JvbzjLKatCoW9RM5keS/yYkJDQ51xzrjOjNedRpyamFY50Cf43bsEQSQWJmPstqxW knq+tBxLloBEVOsA5XQrzRYWU2keNpTqNQ3kEUTHlIrNqlfRdzWItqg7dGot7b6BII6p vUJNkETHXwKeH2H0LvHtKVA1m9IHE1X0SHWGehpgQUWYVdIKDBbsTygLYCp9lPtbHATU MAGw== X-Forwarded-Encrypted: i=1; AJvYcCV/y5gNLoB7pniI0Oykl4wYNGwCXqH+DHFEpDxjQWgFifr5rbPZI2mjwl+ZEKoUxFZoPVSNbj4dArH+Boo=@vger.kernel.org X-Gm-Message-State: AOJu0YyRpVqLiL5/PChGCkAlPyCVEskotoR0npdHmSJk0h2pEyqhn9Oj bcb/v1wlxu0D56fNxzuAsDnp/Fd04E02ItVAvxwyOa74TquhPYDEtucq57vgQw7M X-Gm-Gg: ATEYQzzfwqLHB0br+Cz+GdPsRYSY/r1eH66si69whF2ygVDR4Fgq496C1bBLrsvPfJ0 mtJKpfZZn1I5RpscyJxAhdHW0VF5uRqZRh6KrhF2K9T4afLCor0OAciOOD1DFdF914d3GWutb/d qu81gds1xlFi8PrAZNBA9/gAeJsIlLrtEHB8WukJN6vvWDiUnxOSpKEXudkCQA49PCWkFK5eaCV cUClQAKkv0KHH/E9BgvbtSjaPJrQVf77xqAao7GUdUpJKNSmj3VS9IOrt4n3LwgQoD7/RXhCuxH eidQLY3/1CAJte/Ucz9NeKmEy9AKFSabPh4C/sDvQD/OAyu3wns8ZEFIx7hZrJFnqmCn11vHCLx 5txkeq1/GthVHMMv4JKGwbcXLUevQETdfbSIodY6oRFAWKgteIkQAN0fNEKE1lcHYxJgn7yTOW5 LGIS+Jl/5VuoU5xpzAZM7lUmkiVLVBMIhWOZj03OUL+prAEL+zypjNxeE+bbAq4KD29FbX0F6FH qI= X-Received: by 2002:a17:902:f78a:b0:2ae:4948:f866 with SMTP id d9443c01a7336-2ae8239bd5emr22877785ad.22.1772805824108; Fri, 06 Mar 2026 06:03:44 -0800 (PST) Received: from mi-HP-ProDesk-680-G6-PCI-Microtower-PC.mioffice.cn ([43.224.245.226]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2ae840ccb6csm29134715ad.92.2026.03.06.06.03.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Mar 2026 06:03:43 -0800 (PST) From: zhidao su X-Google-Original-From: zhidao su To: tj@kernel.org, sched-ext@lists.linux.dev, linux-kernel@vger.kernel.org Cc: void@manifault.com, arighi@nvidia.com, changwoo@igalia.com, linux-kselftest@vger.kernel.org, Su Zhidao Subject: [PATCH 4/5] sched_ext/selftests: Add bypass mode operational test Date: Fri, 6 Mar 2026 22:03:24 +0800 Message-ID: <20260306140325.2710927-5-suzhidao@xiaomi.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260306140325.2710927-1-suzhidao@xiaomi.com> References: <20260306140325.2710927-1-suzhidao@xiaomi.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Su Zhidao Add a test that verifies the sched_ext bypass mechanism does not prevent tasks from running to completion. The test attaches a minimal global FIFO scheduler, spawns worker processes that complete a fixed computation, detaches the scheduler (which triggers bypass mode while workers are still active), and verifies all workers complete successfully under bypass mode. This exercises the scheduler attach/detach lifecycle and verifies that bypass mode (activated during unregistration to guarantee forward progress) does not stall running tasks. Signed-off-by: Su Zhidao --- tools/testing/selftests/sched_ext/Makefile | 1 + .../testing/selftests/sched_ext/bypass.bpf.c | 32 ++++++ tools/testing/selftests/sched_ext/bypass.c | 105 ++++++++++++++++++ 3 files changed, 138 insertions(+) create mode 100644 tools/testing/selftests/sched_ext/bypass.bpf.c create mode 100644 tools/testing/selftests/sched_ext/bypass.c diff --git a/tools/testing/selftests/sched_ext/Makefile b/tools/testing/sel= ftests/sched_ext/Makefile index a3bbe2c7911b..5fb6278d3f97 100644 --- a/tools/testing/selftests/sched_ext/Makefile +++ b/tools/testing/selftests/sched_ext/Makefile @@ -162,6 +162,7 @@ endef all_test_bpfprogs :=3D $(foreach prog,$(wildcard *.bpf.c),$(INCLUDE_DIR)/$= (patsubst %.c,%.skel.h,$(prog))) =20 auto-test-targets :=3D \ + bypass \ create_dsq \ dequeue \ enq_last_no_enq_fails \ diff --git a/tools/testing/selftests/sched_ext/bypass.bpf.c b/tools/testing= /selftests/sched_ext/bypass.bpf.c new file mode 100644 index 000000000000..cb37c8df6834 --- /dev/null +++ b/tools/testing/selftests/sched_ext/bypass.bpf.c @@ -0,0 +1,32 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * BPF scheduler for bypass mode operational test. + * + * Implements a minimal global FIFO scheduler. The userspace side + * attaches this scheduler, runs worker tasks to completion, and + * verifies that tasks complete successfully. + * + * Copyright (c) 2026 Xiaomi Corporation. + */ +#include + +char _license[] SEC("license") =3D "GPL"; + +UEI_DEFINE(uei); + +void BPF_STRUCT_OPS(bypass_enqueue, struct task_struct *p, u64 enq_flags) +{ + scx_bpf_dsq_insert(p, SCX_DSQ_GLOBAL, SCX_SLICE_DFL, enq_flags); +} + +void BPF_STRUCT_OPS(bypass_exit, struct scx_exit_info *ei) +{ + UEI_RECORD(uei, ei); +} + +SEC(".struct_ops.link") +struct sched_ext_ops bypass_ops =3D { + .enqueue =3D (void *)bypass_enqueue, + .exit =3D (void *)bypass_exit, + .name =3D "bypass_test", +}; diff --git a/tools/testing/selftests/sched_ext/bypass.c b/tools/testing/sel= ftests/sched_ext/bypass.c new file mode 100644 index 000000000000..952f09d76bdb --- /dev/null +++ b/tools/testing/selftests/sched_ext/bypass.c @@ -0,0 +1,105 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Verify the sched_ext bypass mechanism: spawn worker tasks and ensure + * they run to completion while a BPF scheduler is active. + * + * The bypass mechanism (activated on scheduler unregistration) must + * guarantee forward progress. This test verifies that worker tasks + * complete successfully when the scheduler is detached. + * + * Copyright (c) 2026 Xiaomi Corporation. + */ +#define _GNU_SOURCE +#include +#include +#include +#include +#include "scx_test.h" +#include "bypass.bpf.skel.h" + +#define NUM_BYPASS_WORKERS 4 + +static void worker_fn(void) +{ + volatile int sum =3D 0; + int i; + + /* + * Do enough work to still be running when bpf_link__destroy() + * is called, ensuring tasks are active during bypass mode. + */ + for (i =3D 0; i < 10000000; i++) + sum +=3D i; +} + +static enum scx_test_status setup(void **ctx) +{ + struct bypass *skel; + + skel =3D bypass__open(); + SCX_FAIL_IF(!skel, "Failed to open bypass skel"); + SCX_ENUM_INIT(skel); + SCX_FAIL_IF(bypass__load(skel), "Failed to load bypass skel"); + + *ctx =3D skel; + return SCX_TEST_PASS; +} + +static enum scx_test_status run(void *ctx) +{ + struct bypass *skel =3D ctx; + struct bpf_link *link; + pid_t pids[NUM_BYPASS_WORKERS]; + int i, status; + + link =3D bpf_map__attach_struct_ops(skel->maps.bypass_ops); + SCX_FAIL_IF(!link, "Failed to attach bypass scheduler"); + + /* + * Spawn worker processes. These must complete successfully + * even as the scheduler is active and then detached (which + * triggers bypass mode). + */ + for (i =3D 0; i < NUM_BYPASS_WORKERS; i++) { + pids[i] =3D fork(); + SCX_FAIL_IF(pids[i] < 0, "fork() failed for worker %d", i); + + if (pids[i] =3D=3D 0) { + worker_fn(); + _exit(0); + } + } + + /* + * Detach the scheduler while workers are still running. This + * triggers bypass mode, which must guarantee forward progress + * for all active tasks. + */ + bpf_link__destroy(link); + + /* Workers must complete successfully under bypass mode */ + for (i =3D 0; i < NUM_BYPASS_WORKERS; i++) { + SCX_FAIL_IF(waitpid(pids[i], &status, 0) !=3D pids[i], + "waitpid failed for worker %d", i); + SCX_FAIL_IF(!WIFEXITED(status) || WEXITSTATUS(status) !=3D 0, + "Worker %d did not exit cleanly", i); + } + + SCX_EQ(skel->data->uei.kind, EXIT_KIND(SCX_EXIT_UNREG)); + + return SCX_TEST_PASS; +} + +static void cleanup(void *ctx) +{ + bypass__destroy(ctx); +} + +struct scx_test bypass_test =3D { + .name =3D "bypass", + .description =3D "Verify tasks complete during bypass mode", + .setup =3D setup, + .run =3D run, + .cleanup =3D cleanup, +}; +REGISTER_SCX_TEST(&bypass_test) --=20 2.43.0