All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/5] sched_ext: Add p->scx.bpf_data for O(1) task context lookup
@ 2026-12-01  5:48 Changwoo Min
  2026-12-01  5:48 ` [PATCH 1/5] sched_ext: Add scx_bpf_sched_id() and scx_bpf_task_sched_id() Changwoo Min
                   ` (4 more replies)
  0 siblings, 5 replies; 8+ messages in thread
From: Changwoo Min @ 2026-12-01  5:48 UTC (permalink / raw)
  To: tj, void, arighi, changwoo
  Cc: david.dai, Gavin Guo, kernel-dev, sched-ext, linux-kernel

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


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2026-12-01 11:04 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-01  5:48 [PATCH 0/5] sched_ext: Add p->scx.bpf_data for O(1) task context lookup Changwoo Min
2026-12-01  5:48 ` [PATCH 1/5] sched_ext: Add scx_bpf_sched_id() and scx_bpf_task_sched_id() Changwoo Min
2026-12-01  5:48 ` [PATCH 2/5] selftests/sched_ext: Test " Changwoo Min
2026-12-01  5:48 ` [PATCH 3/5] sched_ext: Add p->scx.bpf_data for O(1) task context lookup Changwoo Min
2026-12-01  7:48   ` Andrea Righi
2026-12-01 11:04     ` Changwoo Min
2026-12-01  5:48 ` [PATCH 4/5] sched_ext: scx_qmap: Cache task_ctx in p->scx.bpf_data Changwoo Min
2026-12-01  5:48 ` [PATCH 5/5] selftests/sched_ext: Test p->scx.bpf_data across class changes Changwoo Min

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.