[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20260121123118.964704-1-arighi@nvidia.com>
Date: Wed, 21 Jan 2026 13:25:29 +0100
From: Andrea Righi <arighi@...dia.com>
To: Tejun Heo <tj@...nel.org>,
David Vernet <void@...ifault.com>,
Changwoo Min <changwoo@...lia.com>
Cc: Emil Tsalapatis <emil@...alapatis.com>,
Daniel Hodges <hodgesd@...a.com>,
sched-ext@...ts.linux.dev,
linux-kernel@...r.kernel.org
Subject: [PATCHSET v2 sched_ext/for-6.20] sched_ext: Fix ops.dequeue() semantics
The callback ops.dequeue() is provided to let BPF schedulers observe when a
task leaves the scheduler, either because it is dispatched or due to a task
property change. However, this callback is currently unreliable and not
invoked systematically, which can result in missed ops.dequeue() events.
In particular, once a task is removed from the BPF scheduler, either due to
dispatch or a property change, visibility of the task is lost and the
sched_ext core may not invoke ops.dequeue(). This breaks accurate
accounting (i.e., per-DSQ queued runtime sums) and prevents reliable
tracking of task lifecycle transitions.
This patch set fixes the semantics of ops.dequeue(), ensuring that every
ops.enqueue() is balanced by a corresponding ops.dequeue() invocation. In
addition, ops.dequeue() is now properly invoked when tasks are removed from
the sched_ext class, such as on task property changes.
To distinguish between a dispatch dequeue and a property change dequeue,
introduce a new dequeue flag: SCX_DEQ_ASYNC (I'm open to suggestions to
find a better name for this flag). BPF schedulers can use this flag to
distinguish between regular dispatch dequeues (SCX_DSQ_ASYNC unset) and
property change dequeues (SCX_DEQ_ASYNC set).
In addition, a kselftest is provided to validate the behavior of
ops.dequeue() in all the different cases.
Together, these changes allow BPF schedulers to reliably track task
ownership and maintain accurate accounting.
Changes in v2:
- Distinguish between "dispatch" dequeues and "property change" dequeues
(flag SCX_DSQ_ASYNC)
- Link to v1: https://lore.kernel.org/all/20251219224450.2537941-1-arighi@nvidia.com
Andrea Righi (2):
sched_ext: Fix ops.dequeue() semantics
selftests/sched_ext: Add test to validate ops.dequeue() semantics
Documentation/scheduler/sched-ext.rst | 33 ++++
include/linux/sched/ext.h | 11 ++
kernel/sched/ext.c | 63 ++++++-
kernel/sched/ext_internal.h | 6 +
tools/sched_ext/include/scx/enum_defs.autogen.h | 2 +
tools/sched_ext/include/scx/enums.autogen.bpf.h | 2 +
tools/sched_ext/include/scx/enums.autogen.h | 1 +
tools/testing/selftests/sched_ext/Makefile | 1 +
tools/testing/selftests/sched_ext/dequeue.bpf.c | 209 ++++++++++++++++++++++++
tools/testing/selftests/sched_ext/dequeue.c | 182 +++++++++++++++++++++
10 files changed, 508 insertions(+), 2 deletions(-)
create mode 100644 tools/testing/selftests/sched_ext/dequeue.bpf.c
create mode 100644 tools/testing/selftests/sched_ext/dequeue.c
Powered by blists - more mailing lists