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=cN3pSOZp3tdiFx9tWmu5ByabzJm13+gGeA4JGYR3J5Z6y7XNA1oTWW01rMBEyyeV129f vmMv18wwyXzxDfmvuUOJHEoD6OMVVYtndXbPpshsRL/nIa3RiIC9YhO9J9aJW3duexhh6 rFuG23128++2RLMb3PIxvUdVwzB4w+DHUc14LbcqFA5WZFuC+k5HzUjkLMQevb58xmPkK qVKgSnqJgJkf480rCABUvDOKUL1FU5HCnHE6H73kn5L9iXm1ZE0cyie642tUcXsNm/2GX bzBf5IdIaZqeJAiDvQ3hOkAVLPAb42xTPQun1Q8S9+GS7tr5IskiIZdx+Fb/Lje/opQ== 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=cDmPSbYo7+ByGgtT0dYCTbzXavAyiHKM4DTdZEYbq0bgiSX1nuRdudWhUk7JXd+D8OIZ 3TKkxTavmyxH0WQIh1rAWbT0W4ibskj/3OYHPiBKOZl4gftWB40Ss92A6OXnvE+NE45Jd PnMziGRsrbQj4JmxXHb58S13DZMAyik1W7p3Yvk94XiGNuVmtJRZ8P3YKjhrOAmDNaLWN W7fO41fXZi8Y2YiYgBeXWIAMZ1tUksbS4ARlgt8gdto/JgNeduBcWHmEJhAW0hJY2TsNR W/lGnhDUMWKUMXy7agmKC05cMT0rODNE3X/bKH2JS/Uf4C0d97J9i2Wt/lV9GSMWjpQ== 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 89455606A31A for ; Tue, 1 Dec 2026 05:49:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 89455606A31A 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, unprotected) 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: sched-ext@lists.linux.dev 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