mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Changwoo Min <changwoo@igalia.com>
To: tj@kernel.org, void@manifault.com, arighi@nvidia.com,
	changwoo@igalia.com
Cc: david.dai@linux.dev, Gavin Guo <gavinguo@igalia.com>,
	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	[thread overview]
Message-ID: <20261203045618.982539-1-changwoo@igalia.com> (raw)

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


             reply	other threads:[~2026-12-03  4:56 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03  4:56 Changwoo Min [this message]
2026-12-03  4:56 ` [PATCH v2 1/8] sched_ext: Reset task fields after ops.exit_task() Changwoo Min
2026-12-03  4:56 ` [PATCH v2 2/8] sched_ext: Mark a task enabled before ops.enable() Changwoo Min
2026-12-03  4:56 ` [PATCH v2 3/8] sched_ext: Add scx_bpf_sched_id() and scx_bpf_task_sched_id() Changwoo Min
2026-12-03  4:56 ` [PATCH v2 4/8] selftests/sched_ext: Test " Changwoo Min
2026-12-03  4:56 ` [PATCH v2 5/8] sched_ext: Add p->scx.bpf_priv for O(1) task context lookup Changwoo Min
2026-12-03  4:56 ` [PATCH v2 6/8] sched_ext: scx_qmap: Cache task_ctx in p->scx.bpf_priv Changwoo Min
2026-12-03  4:56 ` [PATCH v2 7/8] selftests/sched_ext: Test p->scx.bpf_priv across class changes Changwoo Min
2026-12-03  4:56 ` [PATCH v2 8/8] selftests/sched_ext: Test task field reset across sub-scheduler handoffs Changwoo Min

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261203045618.982539-1-changwoo@igalia.com \
    --to=changwoo@igalia.com \
    --cc=arighi@nvidia.com \
    --cc=david.dai@linux.dev \
    --cc=gavinguo@igalia.com \
    --cc=kernel-dev@igalia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sched-ext@lists.linux.dev \
    --cc=tj@kernel.org \
    --cc=void@manifault.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®