The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Andrea Righi <arighi@nvidia.com>
To: Changwoo Min <changwoo@igalia.com>
Cc: tj@kernel.org, void@manifault.com, david.dai@linux.dev,
	Gavin Guo <gavinguo@igalia.com>,
	kernel-dev@igalia.com, sched-ext@lists.linux.dev,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 0/6] sched_ext: Add p->scx.bpf_priv for O(1) task context lookup
Date: Sun, 6 Dec 2026 11:57:16 +0100	[thread overview]
Message-ID: <axU_jN4f4Ob8NVOt@gpd4> (raw)
In-Reply-To: <20261206053728.2026272-1-changwoo@igalia.com>

Hi Changwoo,

On Sun, Dec 06, 2026 at 02:37:22PM +0900, Changwoo Min wrote:
> 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 value belongs to the scheduler that owns the task, from
> after ops.init_task() until ops.exit_task(), and the kernel clears it
> after ops.exit_task(). The kfunc checks the ownership under the task's
> locks. Like scx_bpf_cpuperf_set(), it can be called from an op called
> for the task or with no lock held.
> 
> With sub-schedulers, a task that a scheduler reaches may belong to
> another scheduler. scx_bpf_sched_id() returns the calling scheduler's
> id, which is never reused, and scx_task_sched_id() in compat.bpf.h the
> id of the task's owner. A reader holding the task's locks compares the
> two, and a lockless one tags the value with its id.
> 
> - Patch 1 adds scx_bpf_sched_id() and scx_task_sched_id().
> - Patch 3 adds p->scx.bpf_priv and scx_bpf_task_set_priv().
> - Patch 4 converts scx_qmap as an example.
> - Patches 2, 5 and 6 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. 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 (31f4eeaf9b7b).

I left a couple of comments, but none of them are blockers (same for the
issues reported by sashiko I think), so for the whole series feel free
to add my:

Reviewed-by: Andrea Righi <arighi@nvidia.com>

Thanks,
-Andrea

> 
> ChangeLog v2 -> v3:
>  - Address all the review comments from Tejun, Andrea and Sashiko.
>  - Drop "sched_ext: Reset task fields after ops.exit_task()", applied
>    as 82cd5232be43.
>  - Drop "sched_ext: Mark a task enabled before ops.enable()" (Tejun).
>  - The value belongs to the task's owner, from after ops.init_task()
>    until ops.exit_task(), and is cleared after ops.exit_task() (Tejun).
>  - scx_bpf_task_set_priv() checks the ownership under the task's locks,
>    like scx_bpf_cpuperf_set(), and tracing programs can't call it
>    (Tejun). Publish the value with smp_wmb() and WRITE_ONCE().
>  - Replace the scx_bpf_task_sched_id() kfunc with the CO-RE helper
>    scx_task_sched_id() (Andrea), which reports 0 for an unowned task
>    (Tejun). Set the task state in one store, as the helper reads it.
>  - Document how a reader checks the owner: compare the ids under the
>    task's locks, or tag the value.
>  - scx_qmap: Clear the value in qmap_exit_task(), use it in
>    qmap_dump_task() (Tejun), and read it with scx_bpf_task_priv().
>  - Selftests: Test the new lifetime, the locking rules and
>    ops.init_task() in sub-scheduler handoffs. Count only the test's own
>    tasks and work in a PID namespace (Tejun). Associate the syscall
>    programs with the scheduler, use SCHED_OTHER instead of SCHED_FIFO,
>    fix the skeleton leaks and SCX_EQ() double evaluations, check that
>    the ops and writes the tests depend on actually ran, and skip where
>    sub-schedulers aren't supported (Sashiko).
> 
> 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
> v2: https://lore.kernel.org/r/20261203045618.982539-1-changwoo@igalia.com
> 
> Changwoo Min (6):
>   sched_ext: Add scx_bpf_sched_id() and scx_task_sched_id()
>   selftests/sched_ext: Test scx_bpf_sched_id() and scx_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                     |  11 +
>  kernel/sched/ext/ext.c                        | 111 +++++-
>  tools/sched_ext/include/scx/compat.bpf.h      |  85 +++++
>  tools/sched_ext/scx_qmap.bpf.c                |  69 +++-
>  tools/testing/selftests/sched_ext/Makefile    |   3 +
>  .../selftests/sched_ext/sched_id.bpf.c        |  43 +++
>  tools/testing/selftests/sched_ext/sched_id.c  | 129 +++++++
>  .../selftests/sched_ext/sub_handoff.bpf.c     | 166 +++++++++
>  .../testing/selftests/sched_ext/sub_handoff.c | 341 ++++++++++++++++++
>  .../selftests/sched_ext/task_bpf_priv.bpf.c   | 129 +++++++
>  .../selftests/sched_ext/task_bpf_priv.c       | 195 ++++++++++
>  11 files changed, 1276 insertions(+), 6 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: 31f4eeaf9b7bc78f210475a551e7d61840514c03
> -- 
> 2.56.1
> 

      parent reply	other threads:[~2026-12-06 10:57 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-06  5:37 [PATCH v3 0/6] sched_ext: Add p->scx.bpf_priv for O(1) task context lookup Changwoo Min
2026-12-06  5:37 ` [PATCH v3 1/6] sched_ext: Add scx_bpf_sched_id() and scx_task_sched_id() Changwoo Min
2026-12-06 10:54   ` Andrea Righi
2026-12-06  5:37 ` [PATCH v3 2/6] selftests/sched_ext: Test " Changwoo Min
2026-12-06  5:37 ` [PATCH v3 3/6] sched_ext: Add p->scx.bpf_priv for O(1) task context lookup Changwoo Min
2026-12-06  8:15   ` Andrea Righi
2026-12-06  5:37 ` [PATCH v3 4/6] sched_ext: scx_qmap: Cache task_ctx in p->scx.bpf_priv Changwoo Min
2026-12-06  5:37 ` [PATCH v3 5/6] selftests/sched_ext: Test p->scx.bpf_priv across class changes Changwoo Min
2026-12-06  5:37 ` [PATCH v3 6/6] selftests/sched_ext: Test task field reset across sub-scheduler handoffs Changwoo Min
2026-12-06 10:57 ` Andrea Righi [this message]

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=axU_jN4f4Ob8NVOt@gpd4 \
    --to=arighi@nvidia.com \
    --cc=changwoo@igalia.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