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=1796273792; b=wVi2cqPnjOFSHNJeRCKdgOThw04LBNwqAerexuDRyeuilIjFC8MOxz4IgvOSUOcjy4sH Inww9WvSt3nBpnpWlJY5lEH76gXW8k5DOTCzHt5EgdCX1ds2RvyMC/Kpxla/EDcbunN7j 6SZ6U8SuUHr48YlbvLC2XCjY2p6mSmi9aqGFj+yq40kE/KBGOmHQReqph3rNxuo0R16Bg 7kN6XRm3MjVJGFRlaSfX8i8fDIKYGVWeO5cb91o+AAqcPZRNgefTqOi00HANKpywMCHO5 Ewkf319O2nCrfLZakNjRmtmOH0StlxFivYGT5zxN8YrUpiEhk43eLcjRbQKSbzYZ1UA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796273792; h=DMARC-Filter:DKIM-Signature:Received:From:To:Cc:Subject:Date: Message-ID:X-Mailer:MIME-Version:Content-Transfer-Encoding; bh=kUZhzINzaxNLgxWGDRwDrrI7LFdGbMOEoaz2hX/OZ2I=; b=bxW/iVpxmGMOuETadBt9efS85xr+6GU0d0Htj7NVdY3axjgdU76CZZwQtYyuoUbLN4Bp 6ZtvvfQJs+BM8pFjU+MOhxhBl0esU8dpmjTSLZ4+tFfQ7sZruDL1tZmN4o8zmmkI5zWXQ wRC+oKCaKFDwWQrRQd4kWfC5zqKCR+Rk4upzrazpPBMCqpx5LDggZen54EjtILmKLhaZ+ AA9s8M2tHmKwrDRGLxWTQ9dCMcvEGC5Gmknp03sB5PjF203niTN244C6j9o+Ei+9i9U9u ttroUFqJ7uFPsTxaoYMZ/Tn6SAbqkA6myucFSFqhF0o6G/KBK/ge3nn8GcGf+Z+ZqmQ== 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=IGuFZFX5; 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 4B1C4606A322 for ; Thu, 3 Dec 2026 04:56:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 4B1C4606A322 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=IGuFZFX5 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=kUZhzINzaxNLgxWGDRwDrrI7LFdGbMOEoaz2hX/OZ2I=; t=1796273791; x=2111633791; b=IGuFZFX5rwWR4GXA7jug3fnIfRVlGjs8D2vgfOJFb18iUJ3 i1Ey4axpvS/chQLw0xbswukgENgKg5WsyiXTlWk0gRJcXJWDo6Tu09yh/nHkGW6o4N0CMpC/VMFT1 gQeUCQjVkQGgtBv5MnTwEK6N3Y6kT3eRd852r7g6D9gZvevplJYdXXdX+E0cLJXh6HQo+EenRe1yE w+6733weDqTujPmC1fABezpDbZhiagPcO2zBLRTbMjRfcBt0wawsvcraAtWmEM+tqWQPbUWUp876/ s0hElSR4VvrFQDA9m8SbTbaSftsMf6yxJydn6pDiRCd+15CNTRc911UjILSCtuRg==; 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) (envelope-from ) id 1xYyro-00000001Twi-1fdP; Thu, 03 Dec 2026 05:56:25 +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 v2 0/8] sched_ext: Add p->scx.bpf_priv for O(1) task context lookup Date: Thu, 3 Dec 2026 13:56:10 +0900 Message-ID: <20261203045618.982539-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_priv, an opaque u64 that the task's scheduler sets with scx_bpf_task_set_priv(), 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 when the task leaves the scheduler's control, after the last op the scheduler runs for the task. 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 resets the task fields after ops.exit_task(), so that a value ops.exit_task() writes doesn't reach the next scheduler in a sub-scheduler handoff. It fixes dsq_vtime today. - Patch 2 marks a task enabled before ops.enable(), so that scx_bpf_task_set_priv() can accept only enabled tasks. - Patch 3 adds scx_bpf_sched_id() and scx_bpf_task_sched_id(). - Patch 5 adds p->scx.bpf_priv and scx_bpf_task_set_priv(). - Patch 6 converts scx_qmap as an example. - Patches 4, 7 and 8 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 v1 of 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 (05fb9c3599fa). ChangeLog v1 -> v2: - Rename p->scx.bpf_data to p->scx.bpf_priv, scx_bpf_task_set_data() to scx_bpf_task_set_priv() and the compat reader scx_bpf_task_data() to scx_bpf_task_priv() (Andrea). - Reset the task fields after ops.exit_task() instead of before it (new patch 1). ops.exit_task() could set a value that reached the next scheduler in a sub-scheduler handoff (reported by Andrea). - Mark a task enabled before ops.enable() (new patch 2, suggested by Andrea). scx_bpf_task_set_priv() now accepts only enabled tasks, which drops v1's exception for ops.enable(). - Add a selftest for the sub-scheduler handoffs (new patch 8). v1: https://lore.kernel.org/r/20261201054850.780664-1-changwoo@igalia.com Changwoo Min (8): sched_ext: Reset task fields after ops.exit_task() sched_ext: Mark a task enabled before ops.enable() 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_priv for O(1) task context lookup sched_ext: scx_qmap: Cache task_ctx in p->scx.bpf_priv selftests/sched_ext: Test p->scx.bpf_priv across class changes selftests/sched_ext: Test task field reset across sub-scheduler handoffs include/linux/sched/ext.h | 13 + kernel/sched/ext/ext.c | 104 ++++++- tools/sched_ext/include/scx/compat.bpf.h | 46 +++ tools/sched_ext/scx_qmap.bpf.c | 58 ++++ tools/testing/selftests/sched_ext/Makefile | 3 + .../selftests/sched_ext/sched_id.bpf.c | 47 ++++ tools/testing/selftests/sched_ext/sched_id.c | 103 +++++++ .../selftests/sched_ext/sub_handoff.bpf.c | 102 +++++++ .../testing/selftests/sched_ext/sub_handoff.c | 265 ++++++++++++++++++ .../selftests/sched_ext/task_bpf_priv.bpf.c | 64 +++++ .../selftests/sched_ext/task_bpf_priv.c | 147 ++++++++++ 11 files changed, 944 insertions(+), 8 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/sub_handoff.bpf.c create mode 100644 tools/testing/selftests/sched_ext/sub_handoff.c create mode 100644 tools/testing/selftests/sched_ext/task_bpf_priv.bpf.c create mode 100644 tools/testing/selftests/sched_ext/task_bpf_priv.c base-commit: 05fb9c3599fafa37ff5d02519afec32d45c4a295 -- 2.56.1