From nobody Mon Jun 8 12:13:50 2026 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F28C7368D73; Fri, 29 May 2026 10:45:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780051544; cv=none; b=WsXHDIMGHu7ox6EfD1V1gWbLFhZnOnHz/7pWbE3WEUt2GWnwhuNR+o2shFtGjhM3tAczxuhoro9POi8/1RLkVXqC9wlV8t5l1VUogIpNlHbuBhqJU+DMFAoiIC6xdZFYBpZeduZey8hkIFiStQSJdEKcfFN4E4/TfcWfyXN80+k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780051544; c=relaxed/simple; bh=vIPH0JS2efLaAD9725s3+lhljeJPXv6kesisjAf2UPw=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=WmL7Kyoh+uiihEIDVwJ/AWJmzLC+RefVyiIU6Rp28uJIT6dqybWI40vg/HYG45l0xFU/m3n13573iztu6Qo8uUG4IlFsY4MPYseRrxRAWkWkKIjgu2HjAMRlJTGxo1xzDa9oStMv6N3A8h6EDHri8blyPEpJdG6I02ZqI8D5x94= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=GsjV2W/F; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=D7Xy5D+l; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="GsjV2W/F"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="D7Xy5D+l" Date: Fri, 29 May 2026 10:45:38 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1780051540; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZLzuKuW2Ru6cgqr+hQxk4lS0CIusekwnLq/JWHk8mRg=; b=GsjV2W/FnjeWzh6AM8o7udnLA2GTjwjclA2tLpXk0QqPtVbTi5kddbkTKOKF2zBkcLEvsA JOfkrLA7EzNxdfM4IeTH4QirlkTpZVGzxpFgN7vWTOj+E130MgFNiirYWGLQFceWJa0iEO ZMfx6SdEtnsnGyG1obb4W9QwHD5tkfBhlnTMMj9+rMT7SvDwRp8Tqpm55S0NqFrsALhpdx H3HJYTHSzbK8c3LyQ/YUYJs6qrvFnrUHpBVGcWni3Y8PQQkW2Rvd4hZs2vldoQriun0/xF Cqa2TB6S9Zg9iDde3qh9pSYITpTtG/VWynR8OJsquJyuiDOf0//2fSFdMinvDQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1780051540; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZLzuKuW2Ru6cgqr+hQxk4lS0CIusekwnLq/JWHk8mRg=; b=D7Xy5D+lnQ2eFhivc9sns3OZj9uTdMiCctUKU/ANlk8G4h1H6bN4ZtZY36OrBwbzCjDLBk 3lzOchYc4HyPVKAg== From: "tip-bot2 for Andrea Righi" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: sched/core] selftests/sched_ext: Validate dl_server attach/detach in total_bw test Cc: Andrea Righi , "Peter Zijlstra (Intel)" , Juri Lelli , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20260526164420.638711-3-arighi@nvidia.com> References: <20260526164420.638711-3-arighi@nvidia.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <178005153896.1039918.2079572306335732681.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The following commit has been merged into the sched/core branch of tip: Commit-ID: c6aa07996802c77e90337fa30259cb1cd06c2609 Gitweb: https://git.kernel.org/tip/c6aa07996802c77e90337fa30259cb1cd= 06c2609 Author: Andrea Righi AuthorDate: Tue, 26 May 2026 18:42:49 +02:00 Committer: Peter Zijlstra CommitterDate: Fri, 29 May 2026 12:43:16 +02:00 selftests/sched_ext: Validate dl_server attach/detach in total_bw test Extend the total_bw selftest to validate the fair/ext dl_server auto-attach/detach operations. After the existing consistency checks, the test now doubles the fair_server's runtime on every CPU via debugfs and verifies that: 1. total_bw grew after the customization (proves fair_server was attached and apply_params() honored the dl_bw_attached flag), 2. with the minimal BPF scheduler loaded, total_bw drops back to the baseline value (proves fair_server was detached and ext_server was attached at its own default runtime), 3. after unload total_bw matches the doubled value from step 1 (proves fair_server was re-attached with the runtime customization preserved across the load/unload cycle). Signed-off-by: Andrea Righi Signed-off-by: Peter Zijlstra (Intel) Acked-by: Juri Lelli Link: https://patch.msgid.link/20260526164420.638711-3-arighi@nvidia.com --- tools/testing/selftests/sched_ext/total_bw.c | 201 +++++++++++++++++- 1 file changed, 200 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/sched_ext/total_bw.c b/tools/testing/s= elftests/sched_ext/total_bw.c index 5b0a619..2af01ce 100644 --- a/tools/testing/selftests/sched_ext/total_bw.c +++ b/tools/testing/selftests/sched_ext/total_bw.c @@ -100,6 +100,98 @@ static int read_total_bw_values(long *bw_values, int m= ax_cpus) return cpu_count; } =20 +/* + * Read a per-CPU dl_server param (runtime or period) from debugfs. + * Returns the value in nanoseconds, or -1 on failure. + */ +static long read_server_param(const char *server, const char *param, int c= pu) +{ + char path[128]; + long value =3D -1; + FILE *fp; + + snprintf(path, sizeof(path), + "/sys/kernel/debug/sched/%s_server/cpu%d/%s", + server, cpu, param); + fp =3D fopen(path, "r"); + if (!fp) + return -1; + if (fscanf(fp, "%ld", &value) !=3D 1) + value =3D -1; + fclose(fp); + + return value; +} + +/* + * Write a per-CPU dl_server param to debugfs. Returns 0 on success. + */ +static int write_server_param(const char *server, const char *param, + int cpu, long value) +{ + char path[128]; + FILE *fp; + int ret =3D 0; + + snprintf(path, sizeof(path), + "/sys/kernel/debug/sched/%s_server/cpu%d/%s", + server, cpu, param); + fp =3D fopen(path, "w"); + if (!fp) + return -1; + if (fprintf(fp, "%ld", value) < 0) + ret =3D -1; + if (fclose(fp) !=3D 0) + ret =3D -1; + + return ret; +} + +static int read_fair_runtime_all(int nr_cpus, long *runtimes) +{ + int i; + + for (i =3D 0; i < nr_cpus; i++) { + runtimes[i] =3D read_server_param("fair", "runtime", i); + if (runtimes[i] <=3D 0) + return -1; + } + + return 0; +} + +static int write_fair_runtime_all(int nr_cpus, long value) +{ + int i; + + for (i =3D 0; i < nr_cpus; i++) { + if (write_server_param("fair", "runtime", i, value) < 0) { + SCX_ERR("Failed to write fair_server runtime on CPU %d", i); + return -1; + } + } + + return 0; +} + +/* + * Restore per-CPU fair_server runtimes. + */ +static int restore_fair_runtime_all(int nr_cpus, const long *runtimes) +{ + int ret =3D 0; + int i; + + for (i =3D 0; i < nr_cpus; i++) { + if (write_server_param("fair", "runtime", i, runtimes[i]) < 0) { + SCX_ERR("Failed to restore fair_server runtime on CPU %d", i); + ret =3D -1; + } + } + + return ret; +} + static bool verify_total_bw_consistency(long *bw_values, int count) { int i; @@ -217,6 +309,9 @@ static enum scx_test_status run(void *ctx) struct bpf_link *link; long loaded_bw[MAX_CPUS]; long unloaded_bw[MAX_CPUS]; + long doubled_bw[MAX_CPUS]; + long original_runtime[MAX_CPUS], doubled_runtime; + enum scx_test_status ret; int i; =20 /* Test scenario 2: BPF program loaded */ @@ -257,7 +352,111 @@ static enum scx_test_status run(void *ctx) } =20 fprintf(stderr, "All total_bw values are consistent across all scenarios\= n"); - return SCX_TEST_PASS; + + /* + * Validate auto-register/unregister of dl_server bandwidth reservations. + * + * Doubling fair_server's runtime doubles its bw contribution. With a + * full-mode BPF scheduler (minimal_ops), the kernel should detach + * fair_server and attach ext_server, dropping total_bw back to its + * pre-customization (default ext_server-only) value. On unload, the + * fair_server reservation should come back with its customized runtime + * preserved, so total_bw doubles again. + */ + if (read_fair_runtime_all(test_ctx->nr_cpus, original_runtime) < 0) { + fprintf(stderr, "Skipping attach/detach validation: debugfs not accessib= le\n"); + return SCX_TEST_PASS; + } + doubled_runtime =3D original_runtime[0] * 2; + + fprintf(stderr, + "Setting fair_server runtime to %ld ns on all CPUs (orig %ld)\n", + doubled_runtime, original_runtime[0]); + + if (write_fair_runtime_all(test_ctx->nr_cpus, doubled_runtime) < 0) { + ret =3D SCX_TEST_FAIL; + goto restore; + } + + if (fetch_verify_total_bw(doubled_bw, test_ctx->nr_cpus) < 0) { + SCX_ERR("Failed to get stable values after doubling fair runtime"); + ret =3D SCX_TEST_FAIL; + goto restore; + } + + /* + * After doubling the runtime, fair_server's bw contribution must grow. + * We don't assert exactly 2x, because the kernel's to_ratio() truncates + * the value, so 2 * to_ratio(period, runtime) and + * to_ratio(period, 2 * runtime) can differ. + */ + for (i =3D 0; i < test_ctx->nr_cpus; i++) { + if (doubled_bw[i] <=3D test_ctx->baseline_bw[i]) { + SCX_ERR("CPU%d: fair did not increase total_bw (baseline=3D%ld, doubled= =3D%ld)", + i, test_ctx->baseline_bw[i], doubled_bw[i]); + ret =3D SCX_TEST_FAIL; + goto restore; + } + } + + link =3D bpf_map__attach_struct_ops(test_ctx->skel->maps.minimal_ops); + if (!link) { + SCX_ERR("Failed to attach scheduler for detach test"); + ret =3D SCX_TEST_FAIL; + goto restore; + } + + if (fetch_verify_total_bw(loaded_bw, test_ctx->nr_cpus) < 0) { + SCX_ERR("Failed to get stable values with BPF loaded (detach test)"); + bpf_link__destroy(link); + ret =3D SCX_TEST_FAIL; + goto restore; + } + + /* + * In full mode the customized fair_server is detached and ext_server is + * attached at its default runtime, total_bw must match baseline. + */ + for (i =3D 0; i < test_ctx->nr_cpus; i++) { + if (loaded_bw[i] !=3D test_ctx->baseline_bw[i]) { + SCX_ERR("CPU%d: expected bw %ld (fair detached, ext default), got %ld", + i, test_ctx->baseline_bw[i], loaded_bw[i]); + bpf_link__destroy(link); + ret =3D SCX_TEST_FAIL; + goto restore; + } + } + + bpf_link__destroy(link); + + if (fetch_verify_total_bw(unloaded_bw, test_ctx->nr_cpus) < 0) { + SCX_ERR("Failed to get stable values after BPF unload (detach test)"); + ret =3D SCX_TEST_FAIL; + goto restore; + } + + /* + * After unload, fair_server is re-attached with its preserved 2x + * runtime, so total_bw should return to the doubled value. + */ + for (i =3D 0; i < test_ctx->nr_cpus; i++) { + if (unloaded_bw[i] !=3D doubled_bw[i]) { + SCX_ERR("CPU%d: BPF unloaded: expected %ld (fair restored at 2x), got %= ld", + i, doubled_bw[i], unloaded_bw[i]); + ret =3D SCX_TEST_FAIL; + goto restore; + } + } + + fprintf(stderr, + "dl_server attach/detach with customized fair runtime verified\n"); + ret =3D SCX_TEST_PASS; + +restore: + if (restore_fair_runtime_all(test_ctx->nr_cpus, original_runtime) < 0) + SCX_ERR("Failed to fully restore per-CPU fair_server runtimes"); + + return ret; } =20 static void cleanup(void *ctx)