From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=213.97.179.56 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796104143; b=HvRvFKRtBY7E9yltuplydIhGOTonmjmF/W/8tIXdEuDU3jpqkZ0Hv4VkVqhE8tKiJJaJ skrWu1UzBZAeBrOz+rxI2iLCoOwgio38hiHrQBrtV9Y2NnyRa4riyyZ+ml6/c3wbY92Vy TNJ2pti7N+g2T8BxI760tcCIqqB/y1yIt13dsyNB3xnAsKyCZoYsMizwnlO1PZ0tTZs32 TJLka8ZJfiUXUX+X3DdRVHzP+UuVDMfq4+slXwURW3SjzYcgI50qo4PsSsBaPTAamZp4q 2SYvdnk9ywzArDAOPFj3bS5otc6AYJ6UkJiMG/mUqUW/Ek5HWVFYzHRpalvSqlXtZ7Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796104143; h=DMARC-Filter:DKIM-Signature:Received:From:To:Cc:Subject:Date: Message-ID:X-Mailer:MIME-Version:Content-Transfer-Encoding; bh=2lmJ2L9UWpE2GFZ0+8PZTkM3K5dkwaP+RvdSWhkgozs=; b=M+pl4ZDnbKziyJKL/gR9M026BF8CRgPlnjNLILjU6xcMKEYaxMkCU95psDryc8bnhKce IdIz9H7D3aJbDJneVGwJbBnBMeLvwQ/mUNwJxqXCXQlAGddE2fgVIqfT300aVrlo+T9PF 8AM9JDSflsUOtiUxP+uhzFp7DmdrHD7/N9ajltCgG9UK169VrcyyinUy4TE/3Z3avEcbc DldoNRbHErCTpmi2iRSKQhbTV3S8uUnm3dlS6pDv8WQGArVqIxAyPBRDJ/ORDeAlvzsP7 sm5vsdKCG2F5AIpDvmDo599d4DPEFxVNRoah9XDu4OvFq8+3tvRC7iPsJ+55D8/ogEw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass header.d=igalia.com header.i=@igalia.com header.a=rsa-sha256 header.s=20170329 header.b="EBd0xGe/"; arc=none smtp.remote-ip=213.97.179.56 Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (prime256v1) server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 303B5606A320 for ; Tue, 1 Dec 2026 05:49:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 303B5606A320 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.a=rsa-sha256 header.s=20170329 header.b=EBd0xGe/ DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:Message-ID:Date:Subject: Cc:To:From:From:Reply-To; bh=2lmJ2L9UWpE2GFZ0+8PZTkM3K5dkwaP+RvdSWhkgozs=; t=1796104142; x=2111464142; b=EBd0xGe/dtaCxzoLH73a686dVuZ4uWIKyixcxHH6sURyrpL rnIXzBUXi0a7OYodEiPsh4k3Gw1uYzF8Tfr5hy+chu+o9IttDpx7DAvEAn9DJo0UjSF0ujNOZS8TQ 5rOU26jsH/I5j9K0XJbpMJo4rVG400bqWC55nsfYaWlbdGqannlG3GP3vLm6VoqXMSLbVa1n9JkgA KolcBTdirKVLxGodrZ+V07IrDqBV7UxEy8cpOEEGGBVVuXK0PUhbbS/BI8e3Q+fODmg5mMq7gaC9F E/8M+XaYbsNY75nxuBVLgdC9bzK4dz6o5y8gApPzfwBWxDpZQu/sF/gek8Sk6Yig==; Received: from [58.29.145.179] (helo=localhost) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1xYGjY-00000000UfQ-3gy5; Tue, 01 Dec 2026 06:48:57 +0100 From: Changwoo Min To: tj@kernel.org, void@manifault.com, arighi@nvidia.com, changwoo@igalia.com Cc: david.dai@linux.dev, Gavin Guo , kernel-dev@igalia.com, sched-ext@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH 0/5] sched_ext: Add p->scx.bpf_data for O(1) task context lookup Date: Tue, 1 Dec 2026 14:48:45 +0900 Message-ID: <20261201054850.780664-1-changwoo@igalia.com> X-Mailer: git-send-email 2.56.1 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit BPF schedulers keep their per-task context in task local storage, or in an arena allocation reached through it, and look it up in nearly every callback. Each lookup is a bpf_task_storage_get() call. This series adds p->scx.bpf_data, an opaque u64 that the task's scheduler sets with scx_bpf_task_set_data(), typically to an arena pointer to its task context. Any BPF program, tracing programs included, reads it with a plain load. The kernel clears it after ops.disable(). With sub-schedulers, a task a scheduler reaches may belong to another scheduler. scx_bpf_sched_id() and scx_bpf_task_sched_id() let a scheduler tag the value with its own id, which is never reused, and recognize its own values. - Patch 1 adds scx_bpf_sched_id() and scx_bpf_task_sched_id(). - Patch 3 adds p->scx.bpf_data and scx_bpf_task_set_data(). - Patch 4 converts scx_qmap as an example. - Patches 2 and 5 add selftests. The scx side uses the field in its shared task data library and in scx_lavd: https://github.com/multics69/scx/tree/changwoo/taskc-caching scx_lavd without and with that branch was compared on a 2-socket AMD EPYC 9R45 machine with 192 CPUs (SMT off), running 7.4-rc4 with this series. Under sysbench OLTP against MariaDB, at a fixed request rate of 60% of the saturation throughput, bpf_stats shows ops.select_cpu() 9% and ops.running() 12% cheaper per call. The BPF programs of scx_lavd use 6% less of the total CPU time. The other workloads were MariaDB at a fixed rate of 80% and with one closed-loop connection per CPU, memcached under memtier, schbench, stress-ng futex, fork and exec, kernel builds and rt-app. None got worse. stress-ng futex throughput improved by 10% and the memtier p99 latency by 12%. The series is based on sched_ext/for-next (7c9543b954aa). Changwoo Min (5): sched_ext: Add scx_bpf_sched_id() and scx_bpf_task_sched_id() selftests/sched_ext: Test scx_bpf_sched_id() and scx_bpf_task_sched_id() sched_ext: Add p->scx.bpf_data for O(1) task context lookup sched_ext: scx_qmap: Cache task_ctx in p->scx.bpf_data selftests/sched_ext: Test p->scx.bpf_data across class changes include/linux/sched/ext.h | 12 ++ kernel/sched/ext/ext.c | 89 ++++++++++++- tools/sched_ext/include/scx/compat.bpf.h | 46 +++++++ tools/sched_ext/scx_qmap.bpf.c | 58 +++++++++ tools/testing/selftests/sched_ext/Makefile | 2 + .../selftests/sched_ext/sched_id.bpf.c | 47 +++++++ tools/testing/selftests/sched_ext/sched_id.c | 103 +++++++++++++++ .../selftests/sched_ext/task_bpf_data.bpf.c | 64 +++++++++ .../selftests/sched_ext/task_bpf_data.c | 123 ++++++++++++++++++ 9 files changed, 540 insertions(+), 4 deletions(-) create mode 100644 tools/testing/selftests/sched_ext/sched_id.bpf.c create mode 100644 tools/testing/selftests/sched_ext/sched_id.c create mode 100644 tools/testing/selftests/sched_ext/task_bpf_data.bpf.c create mode 100644 tools/testing/selftests/sched_ext/task_bpf_data.c -- 2.56.1