sched_ext: Rename dispatch and consume kfuncs
Subsystems (3)
Tejun Heo
reviewerPATCH 1/1 sched_ext: Rename dispatch and consume kfuncs
Hello,
[v1] -> v2: Comment and documentation updates.
In sched_ext API, a repeatedly reported pain point is the overuse of the verb "dispatch" and confusion around "consume":
- ops.dispatch()
- scx_bpf_dispatch[_vtime]()
- scx_bpf_consume()
- scx_bpf_dispatch[_vtime]_from_dsq*()
This overloading of the term is historical. Originally, there were only built-in DSQs and moving a task into a DSQ always dispatched it for execution. Using the verb "dispatch" for the kfuncs to move tasks into these DSQs made sense.
Later, user DSQs were added and scx_bpf_dispatch[_vtime]() updated to be able to insert tasks into any DSQ. The only allowed DSQ to DSQ transfer was from a non-local DSQ to a local DSQ and this operation was named "consume". This was already confusing as a task could be dispatched to a user DSQ from ops.enqueue() and then the DSQ would have to be consumed in ops.dispatch(). Later addition of scx_bpf_dispatch_from_dsq*() made the confusion even worse as "dispatch" in this context meant moving a task to an arbitrary DSQ from a user DSQ.
Clean up the API with the following renames:
1. scx_bpf_dispatch[_vtime]() -> scx_bpf_dsq_insert[_vtime]()
2. scx_bpf_consume() -> scx_bpf_dsq_move_to_local()
3. scx_bpf_dispatch[_vtime]_from_dsq*() -> scx_bpf_dsq_move[_vtime]*()
This patchset is on top of sched_ext/for-6.13 72b85bf6a7f6 ("sched_ext:
scx_bpf_dispatch_from_dsq_set_*() are allowed from unlocked context") and contains the following patches:
0001-sched_ext-Rename-scx_bpf_dispatch-_vtime-to-scx_bpf_.patch 0002-sched_ext-Rename-scx_bpf_consume-to-scx_bpf_dsq_move.patch 0003-sched_ext-Rename-scx_bpf_dispatch-_vtime-_from_dsq-s.patch
and is always available in the following git branch:
git://git.kernel.org/pub/scm/linux/kernel/git/tj/sched_ext.git scx-api-rename-dispatch-v2
diffstat follows. Thanks.
Documentation/scheduler/sched-ext.rst | 71 ++++++------- kernel/sched/ext.c | 243 +++++++++++++++++++++++++++++----------------- tools/sched_ext/include/scx/common.bpf.h | 18 +-- tools/sched_ext/include/scx/compat.bpf.h | 117 +++++++++++++++++++--- tools/sched_ext/scx_central.bpf.c | 14 +- tools/sched_ext/scx_flatcg.bpf.c | 20 ++- tools/sched_ext/scx_qmap.bpf.c | 36 +++--- tools/sched_ext/scx_simple.bpf.c | 16 +-- 8 files changed, 348 insertions(+), 187 deletions(-)
--
tejun
Tejun Heo
reviewerPATCH 1/3 sched_ext: Rename scx_bpf_dispatch[_vtime]() to scx_bpf_dsq_insert[_vtime]()
In sched_ext API, a repeatedly reported pain point is the overuse of the verb "dispatch" and confusion around "consume":
- ops.dispatch()
- scx_bpf_dispatch[_vtime]()
- scx_bpf_consume()
- scx_bpf_dispatch[_vtime]_from_dsq*()
This overloading of the term is historical. Originally, there were only built-in DSQs and moving a task into a DSQ always dispatched it for execution. Using the verb "dispatch" for the kfuncs to move tasks into these DSQs made sense.
Later, user DSQs were added and scx_bpf_dispatch[_vtime]() updated to be able to insert tasks into any DSQ. The only allowed DSQ to DSQ transfer was from a non-local DSQ to a local DSQ and this operation was named "consume". This was already confusing as a task could be dispatched to a user DSQ from ops.enqueue() and then the DSQ would have to be consumed in ops.dispatch(). Later addition of scx_bpf_dispatch_from_dsq*() made the confusion even worse as "dispatch" in this context meant moving a task to an arbitrary DSQ from a user DSQ.
Clean up the API with the following renames:
1. scx_bpf_dispatch[_vtime]() -> scx_bpf_dsq_insert[_vtime]()
2. scx_bpf_consume() -> scx_bpf_dsq_move_to_local()
3. scx_bpf_dispatch[_vtime]_from_dsq*() -> scx_bpf_dsq_move[_vtime]*()
This patch performs the first set of renames. Compatibility is maintained by:
- The previous kfunc names are still provided by the kernel so that old binaries can run. Kernel generates a warning when the old names are used.
- compat.bpf.h provides wrappers for the new names which automatically fall back to the old names when running on older kernels. They also trigger build error if old names are used for new builds.
The compat features will be dropped after v6.15.
v2: Documentation updates.
--- Documentation/scheduler/sched-ext.rst | 50 +++++----- kernel/sched/ext.c | 111 +++++++++++++---------- tools/sched_ext/include/scx/common.bpf.h | 4 +- tools/sched_ext/include/scx/compat.bpf.h | 26 ++++++ tools/sched_ext/scx_central.bpf.c | 10 +- tools/sched_ext/scx_flatcg.bpf.c | 14 +-- tools/sched_ext/scx_qmap.bpf.c | 12 +-- tools/sched_ext/scx_simple.bpf.c | 14 +-- 8 files changed, 144 insertions(+), 97 deletions(-)
Documentation/scheduler/sched-ext.rst +25 -25
@@ -130,7 +130,7 @@ optional. The following modified excerpt is from * Decide which CPU a task should be migrated to before being * enqueued (either at wakeup, fork time, or exec time). If an * idle core is found by the default ops.select_cpu() implementation, - * then dispatch the task directly to SCX_DSQ_LOCAL and skip the + * then insert the task directly into SCX_DSQ_LOCAL and skip the * ops.enqueue() callback. * * Note that this implementation has exactly the same behavior as the
@@ -148,15 +148,15 @@ optional. The following modified excerpt is from cpu = scx_bpf_select_cpu_dfl(p, prev_cpu, wake_flags, &direct); if (direct) - scx_bpf_dispatch(p, SCX_DSQ_LOCAL, SCX_SLICE_DFL, 0); + scx_bpf_dsq_insert(p, SCX_DSQ_LOCAL, SCX_SLICE_DFL, 0); return cpu; } /* - * Do a direct dispatch of a task to the global DSQ. This ops.enqueue() - * callback will only be invoked if we failed to find a core to dispatch - * to in ops.select_cpu() above. + * Do a direct insertion of a task to the global DSQ. This ops.enqueue() + * callback will only be invoked if we failed to find a core to insert + * into in ops.select_cpu() above. * * Note that this implementation has exactly the same behavior as the * default ops.enqueue implementation, which just dispatches the task
@@ -166,7 +166,7 @@ optional. The following modified excerpt is from */ void BPF_STRUCT_OPS(simple_enqueue, struct task_struct *p, u64 enq_flags) { - scx_bpf_dispatch(p, SCX_DSQ_GLOBAL, SCX_SLICE_DFL, enq_flags); + scx_bpf_dsq_insert(p, SCX_DSQ_GLOBAL, SCX_SLICE_DFL, enq_flags); } s32 BPF_STRUCT_OPS_SLEEPABLE(simple_init)
@@ -202,7 +202,7 @@ and one local dsq per CPU (``SCX_DSQ_LOCAL``). The BPF scheduler can manage an arbitrary number of dsq's using ``scx_bpf_create_dsq()`` and ``scx_bpf_destroy_dsq()``. -A CPU always executes a task from its local DSQ. A task is "dispatched" to a +A CPU always executes a task from its local DSQ. A task is "inserted" into a DSQ. A non-local DSQ is "consumed" to transfer a task to the consuming CPU's local DSQ.
@@ -229,26 +229,26 @@ The following briefly shows how a waking task is scheduled and executed. scheduler can wake up any cpu using the ``scx_bpf_kick_cpu()`` helper, using ``ops.select_cpu()`` judiciously can be simpler and more efficient. - A task can be immediately dispatched to a DSQ from ``ops.select_cpu()`` by - calling ``scx_bpf_dispatch()``. If the task is dispatched to - ``SCX_DSQ_LOCAL`` from ``ops.select_cpu()``, it will be dispatched to the + A task can be immediately inserted into a DSQ from ``ops.select_cpu()`` + by calling ``scx_bpf_dsq_insert()``. If the task is inserted into + ``SCX_DSQ_LOCAL`` from ``ops.select_cpu()``, it will be inserted into the local DSQ of whichever CPU is returned from ``ops.select_cpu()``. - Additionally, dispatching directly from ``ops.select_cpu()`` will cause the + Additionally, inserting directly from ``ops.select_cpu()`` will cause the ``ops.enqueue()`` callback to be skipped. Note that the scheduler core will ignore an invalid CPU selection, for example, if it's outside the allowed cpumask of the task. 2. Once the target CPU is selected, ``ops.enqueue()`` is invoked (unless the - task was dispatched directly from ``ops.select_cpu()``). ``ops.enqueue()`` + task was inserted directly from ``ops.select_cpu()``). ``ops.enqueue()`` can make one of the following decisions: - * Immediately dispatch the task to either the global or local DSQ by - calling ``scx_bpf_dispatch()`` with ``SCX_DSQ_GLOBAL`` or + * Immediately insert the task into either the global or local DSQ by + calling ``scx_bpf_dsq_insert()`` with ``SCX_DSQ_GLOBAL`` or ``SCX_DSQ_LOCAL``, respectively. - * Immediately dispatch the task to a custom DSQ by calling - ``scx_bpf_dispatch()`` with a DSQ ID which is smaller than 2^63. + * Immediately insert the task into a custom DSQ by calling + ``scx_bpf_dsq_insert()`` with a DSQ ID which is smaller than 2^63. * Queue the task on the BPF side.
@@ -257,11 +257,11 @@ The following briefly shows how a waking task is scheduled and executed. run, ``ops.dispatch()`` is invoked which can use the following two functions to populate the local DSQ. - * ``scx_bpf_dispatch()`` dispatches a task to a DSQ. Any target DSQ can - be used - ``SCX_DSQ_LOCAL``, ``SCX_DSQ_LOCAL_ON | cpu``, - ``SCX_DSQ_GLOBAL`` or a custom DSQ. While ``scx_bpf_dispatch()`` + * ``scx_bpf_dsq_insert()`` inserts a task to a DSQ. Any target DSQ can be + used - ``SCX_DSQ_LOCAL``, ``SCX_DSQ_LOCAL_ON | cpu``, + ``SCX_DSQ_GLOBAL`` or a custom DSQ. While ``scx_bpf_dsq_insert()`` currently can't be called with BPF locks held, this is being worked on - and will be supported. ``scx_bpf_dispatch()`` schedules dispatching + and will be supported. ``scx_bpf_dsq_insert()`` schedules insertion rather than performing them immediately. There can be up to ``ops.dispatch_max_batch`` pending tasks.
@@ -288,12 +288,12 @@ built-in DSQs are used, there is no need to implement ``ops.dispatch()`` as a task is never queued on the BPF scheduler and both the local and global DSQs are consumed automatically. -``scx_bpf_dispatch()`` queues the task on the FIFO of the target DSQ. Use -``scx_bpf_dispatch_vtime()`` for the priority queue. Internal DSQs such as +``scx_bpf_dsq_insert()`` inserts the task on the FIFO of the target DSQ. Use +``scx_bpf_dsq_insert_vtime()`` for the priority queue. Internal DSQs such as ``SCX_DSQ_LOCAL`` and ``SCX_DSQ_GLOBAL`` do not support priority-queue -dispatching, and must be dispatched to with ``scx_bpf_dispatch()``. See the -function documentation and usage in ``tools/sched_ext/scx_simple.bpf.c`` for -more information. +dispatching, and must be dispatched to with ``scx_bpf_dsq_insert()``. See +the function documentation and usage in ``tools/sched_ext/scx_simple.bpf.c`` +for more information. Where to Look =============
kernel/sched/ext.c +65 -46
236 lines not on this page · raw message
tools/sched_ext/include/scx/common.bpf.h +2 -2
@@ -36,8 +36,8 @@ static inline void ___vmlinux_h_sanity_check___(void) s32 scx_bpf_create_dsq(u64 dsq_id, s32 node) __ksym; s32 scx_bpf_select_cpu_dfl(struct task_struct *p, s32 prev_cpu, u64 wake_flags, bool *is_idle) __ksym; -void scx_bpf_dispatch(struct task_struct *p, u64 dsq_id, u64 slice, u64 enq_flags) __ksym; -void scx_bpf_dispatch_vtime(struct task_struct *p, u64 dsq_id, u64 slice, u64 vtime, u64 enq_flags) __ksym; +void scx_bpf_dsq_insert(struct task_struct *p, u64 dsq_id, u64 slice, u64 enq_flags) __ksym __weak; +void scx_bpf_dsq_insert_vtime(struct task_struct *p, u64 dsq_id, u64 slice, u64 vtime, u64 enq_flags) __ksym __weak; u32 scx_bpf_dispatch_nr_slots(void) __ksym; void scx_bpf_dispatch_cancel(void) __ksym; bool scx_bpf_consume(u64 dsq_id) __ksym;
tools/sched_ext/include/scx/compat.bpf.h +26 -0
@@ -34,6 +34,32 @@ (bpf_ksym_exists (scx_bpf_dispatch_vtime_from_dsq) ? \scx_bpf_dispatch_vtime_from_dsq ((it), (p), (dsq_id), (enq_flags)) : false) +/* +* v6.13: The verb `dispatch` was too overloaded and confusing. kfuncs are +* renamed to unload the verb. +* +* Build error is triggered if old names are used. New binaries work with both +* new and old names. The compat macros will be removed on v6.15 release. + */ +void scx_bpf_dispatch___compat(struct task_struct *p, u64 dsq_id, u64 slice, u64 enq_flags) __ksym __weak; +void scx_bpf_dispatch_vtime___compat(struct task_struct *p, u64 dsq_id, u64 slice, u64 vtime, u64 enq_flags) __ksym __weak; + +#define scx_bpf_dsq_insert (p, dsq_id, slice, enq_flags) \ + (bpf_ksym_exists(scx_bpf_dsq_insert) ? \ + scx_bpf_dsq_insert((p), (dsq_id), (slice), (enq_flags)) : \ + scx_bpf_dispatch___compat((p), (dsq_id), (slice), (enq_flags))) + +#define scx_bpf_dsq_insert_vtime (p, dsq_id, slice, vtime, enq_flags) \ + (bpf_ksym_exists(scx_bpf_dsq_insert_vtime) ? \ + scx_bpf_dsq_insert_vtime((p), (dsq_id), (slice), (vtime), (enq_flags)) : \ + scx_bpf_dispatch_vtime___compat((p), (dsq_id), (slice), (vtime), (enq_flags))) + +#define scx_bpf_dispatch (p, dsq_id, slice, enq_flags) \ + _Static_assert(false, "scx_bpf_dispatch() renamed to scx_bpf_dsq_insert()") + +#define scx_bpf_dispatch_vtime (p, dsq_id, slice, vtime, enq_flags) \ + _Static_assert(false, "scx_bpf_dispatch_vtime() renamed to scx_bpf_dsq_insert_vtime()") +/* * Define sched_ext_ops. This may be expanded to define multiple variants for * backward compatibility. See compat.h::SCX_OPS_LOAD/ATTACH().
tools/sched_ext/scx_central.bpf.c +5 -5
@@ -118,14 +118,14 @@ void BPF_STRUCT_OPS(central_enqueue, struct task_struct *p, u64 enq_flags)*/ if ((p->flags &PF_KTHREAD ) && p->nr_cpus_allowed ==1 ) {__sync_fetch_and_add (&nr_locals,1 ); -scx_bpf_dispatch (p,SCX_DSQ_LOCAL ,SCX_SLICE_INF , - enq_flags |SCX_ENQ_PREEMPT ); +scx_bpf_dsq_insert (p,SCX_DSQ_LOCAL ,SCX_SLICE_INF , + enq_flags |SCX_ENQ_PREEMPT );return ; }if (bpf_map_push_elem (¢ral_q, &pid,0 )) {__sync_fetch_and_add (&nr_overflows,1 ); -scx_bpf_dispatch (p,FALLBACK_DSQ_ID ,SCX_SLICE_INF , enq_flags); +scx_bpf_dsq_insert (p,FALLBACK_DSQ_ID ,SCX_SLICE_INF , enq_flags);return ; }
@@ -158,7 +158,7 @@ static bool dispatch_to_cpu(s32 cpu)*/ if (!bpf_cpumask_test_cpu (cpu, p->cpus_ptr)) {__sync_fetch_and_add (&nr_mismatches,1 ); -scx_bpf_dispatch (p,FALLBACK_DSQ_ID ,SCX_SLICE_INF ,0 ); +scx_bpf_dsq_insert (p,FALLBACK_DSQ_ID ,SCX_SLICE_INF ,0 );bpf_task_release (p);/* * We might run out of dispatch buffer slots if we continue dispatching
@@ -172,7 +172,7 @@ static bool dispatch_to_cpu(s32 cpu) }/* dispatch to local and mark that @cpu doesn't need more */ -scx_bpf_dispatch (p,SCX_DSQ_LOCAL_ON | cpu,SCX_SLICE_INF ,0 ); +scx_bpf_dsq_insert (p,SCX_DSQ_LOCAL_ON | cpu,SCX_SLICE_INF ,0 );if (cpu != central_cpu)scx_bpf_kick_cpu (cpu,SCX_KICK_IDLE );
tools/sched_ext/scx_flatcg.bpf.c +8 -6
@@ -341,7 +341,7 @@ s32 BPF_STRUCT_OPS(fcg_select_cpu, struct task_struct *p, s32 prev_cpu, u64 wakeif (is_idle) {set_bypassed_at (p, taskc);stat_inc (FCG_STAT_LOCAL ); -scx_bpf_dispatch (p,SCX_DSQ_LOCAL ,SCX_SLICE_DFL ,0 ); +scx_bpf_dsq_insert (p,SCX_DSQ_LOCAL ,SCX_SLICE_DFL ,0 ); }return cpu;
@@ -377,10 +377,12 @@ void BPF_STRUCT_OPS(fcg_enqueue, struct task_struct *p, u64 enq_flags)*/ if (p->nr_cpus_allowed ==1 && (p->flags &PF_KTHREAD )) {stat_inc (FCG_STAT_LOCAL ); -scx_bpf_dispatch (p,SCX_DSQ_LOCAL ,SCX_SLICE_DFL , enq_flags); +scx_bpf_dsq_insert (p,SCX_DSQ_LOCAL ,SCX_SLICE_DFL , + enq_flags); }else {stat_inc (FCG_STAT_GLOBAL ); -scx_bpf_dispatch (p,FALLBACK_DSQ ,SCX_SLICE_DFL , enq_flags); +scx_bpf_dsq_insert (p,FALLBACK_DSQ ,SCX_SLICE_DFL , + enq_flags); }return ; }
@@ -391,7 +393,7 @@ void BPF_STRUCT_OPS(fcg_enqueue, struct task_struct *p, u64 enq_flags) goto out_release;if (fifo_sched) { -scx_bpf_dispatch (p, cgrp->kn->id,SCX_SLICE_DFL , enq_flags); +scx_bpf_dsq_insert (p, cgrp->kn->id,SCX_SLICE_DFL , enq_flags); }else {u64 tvtime = p->scx.dsq_vtime;
@@ -402,8 +404,8 @@ void BPF_STRUCT_OPS(fcg_enqueue, struct task_struct *p, u64 enq_flags)if (vtime_before (tvtime, cgc->tvtime_now -SCX_SLICE_DFL )) tvtime = cgc->tvtime_now -SCX_SLICE_DFL ; -scx_bpf_dispatch_vtime (p, cgrp->kn->id,SCX_SLICE_DFL , - tvtime, enq_flags); +scx_bpf_dsq_insert_vtime (p, cgrp->kn->id,SCX_SLICE_DFL , + tvtime, enq_flags); }cgrp_enqueued (cgrp, cgc);
tools/sched_ext/scx_qmap.bpf.c +6 -6
@@ -226,7 +226,7 @@ void BPF_STRUCT_OPS(qmap_enqueue, struct task_struct *p, u64 enq_flags)*/ if (tctx->force_local) { tctx->force_local = false; -scx_bpf_dispatch (p,SCX_DSQ_LOCAL , slice_ns, enq_flags); +scx_bpf_dsq_insert (p,SCX_DSQ_LOCAL , slice_ns, enq_flags);return ; }
@@ -234,7 +234,7 @@ void BPF_STRUCT_OPS(qmap_enqueue, struct task_struct *p, u64 enq_flags)if (!(enq_flags &SCX_ENQ_CPU_SELECTED ) && (cpu =pick_direct_dispatch_cpu (p,scx_bpf_task_cpu (p))) >=0 ) {__sync_fetch_and_add (&nr_ddsp_from_enq,1 ); -scx_bpf_dispatch (p,SCX_DSQ_LOCAL_ON | cpu, slice_ns, enq_flags); +scx_bpf_dsq_insert (p,SCX_DSQ_LOCAL_ON | cpu, slice_ns, enq_flags);return ; }
@@ -247,7 +247,7 @@ void BPF_STRUCT_OPS(qmap_enqueue, struct task_struct *p, u64 enq_flags)if (enq_flags &SCX_ENQ_REENQ ) {s32 cpu; -scx_bpf_dispatch (p,SHARED_DSQ ,0 , enq_flags); +scx_bpf_dsq_insert (p,SHARED_DSQ ,0 , enq_flags); cpu =scx_bpf_pick_idle_cpu (p->cpus_ptr,0 );if (cpu >=0 )scx_bpf_kick_cpu (cpu,SCX_KICK_IDLE );
@@ -262,7 +262,7 @@ void BPF_STRUCT_OPS(qmap_enqueue, struct task_struct *p, u64 enq_flags)/* Queue on the selected FIFO. If the FIFO overflows, punt to global. */ if (bpf_map_push_elem (ring, &pid,0 )) { -scx_bpf_dispatch (p,SHARED_DSQ , slice_ns, enq_flags); +scx_bpf_dsq_insert (p,SHARED_DSQ , slice_ns, enq_flags);return ; }
@@ -385,7 +385,7 @@ void BPF_STRUCT_OPS(qmap_dispatch, s32 cpu, struct task_struct *prev)*/ p =bpf_task_from_pid (2 );if (p) { -scx_bpf_dispatch (p,SCX_DSQ_LOCAL , slice_ns,0 ); +scx_bpf_dsq_insert (p,SCX_DSQ_LOCAL , slice_ns,0 );bpf_task_release (p);return ; }
@@ -431,7 +431,7 @@ void BPF_STRUCT_OPS(qmap_dispatch, s32 cpu, struct task_struct *prev)update_core_sched_head_seq (p);__sync_fetch_and_add (&nr_dispatched,1 ); -scx_bpf_dispatch (p,SHARED_DSQ , slice_ns,0 ); +scx_bpf_dsq_insert (p,SHARED_DSQ , slice_ns,0 );bpf_task_release (p); batch--;
tools/sched_ext/scx_simple.bpf.c +7 -7
@@ -31,10 +31,10 @@ UEI_DEFINE(uei);/* * Built-in DSQs such as SCX_DSQ_GLOBAL cannot be used as priority queues -* (meaning, cannot be dispatched to with scx_bpf_dispatch_vtime()). We +* (meaning, cannot be dispatched to with scx_bpf_dsq_insert_vtime()). We * therefore create a separate DSQ with ID 0 that we dispatch to and consume -* from. If scx_simple only supported global FIFO scheduling, then we could -* just use SCX_DSQ_GLOBAL. +* from. If scx_simple only supported global FIFO scheduling, then we could just +* use SCX_DSQ_GLOBAL. */ #define SHARED_DSQ 0
@@ -65,7 +65,7 @@ s32 BPF_STRUCT_OPS(simple_select_cpu, struct task_struct *p, s32 prev_cpu, u64 w cpu =scx_bpf_select_cpu_dfl (p, prev_cpu, wake_flags, &is_idle);if (is_idle) {stat_inc (0 );/* count local queueing */ -scx_bpf_dispatch (p,SCX_DSQ_LOCAL ,SCX_SLICE_DFL ,0 ); +scx_bpf_dsq_insert (p,SCX_DSQ_LOCAL ,SCX_SLICE_DFL ,0 ); }return cpu;
@@ -76,7 +76,7 @@ void BPF_STRUCT_OPS(simple_enqueue, struct task_struct *p, u64 enq_flags)stat_inc (1 );/* count global queueing */ if (fifo_sched) { -scx_bpf_dispatch (p,SHARED_DSQ ,SCX_SLICE_DFL , enq_flags); +scx_bpf_dsq_insert (p,SHARED_DSQ ,SCX_SLICE_DFL , enq_flags); }else {u64 vtime = p->scx.dsq_vtime;
@@ -87,8 +87,8 @@ void BPF_STRUCT_OPS(simple_enqueue, struct task_struct *p, u64 enq_flags)if (vtime_before (vtime, vtime_now -SCX_SLICE_DFL )) vtime = vtime_now -SCX_SLICE_DFL ; -scx_bpf_dispatch_vtime (p,SHARED_DSQ ,SCX_SLICE_DFL , vtime, - enq_flags); +scx_bpf_dsq_insert_vtime (p,SHARED_DSQ ,SCX_SLICE_DFL , vtime, + enq_flags); } }
Signature · 1 line
2.47.0
Tejun Heo
reviewerPATCH 2/3 sched_ext: Rename scx_bpf_consume() to scx_bpf_dsq_move_to_local()
In reply to Tejun HeoIn sched_ext API, a repeatedly reported pain point is the overuse of the verb "dispatch" and confusion around "consume":
- ops.dispatch()
- scx_bpf_dispatch[_vtime]()
- scx_bpf_consume()
- scx_bpf_dispatch[_vtime]_from_dsq*()
This overloading of the term is historical. Originally, there were only built-in DSQs and moving a task into a DSQ always dispatched it for execution. Using the verb "dispatch" for the kfuncs to move tasks into these DSQs made sense.
Later, user DSQs were added and scx_bpf_dispatch[_vtime]() updated to be able to insert tasks into any DSQ. The only allowed DSQ to DSQ transfer was from a non-local DSQ to a local DSQ and this operation was named "consume". This was already confusing as a task could be dispatched to a user DSQ from ops.enqueue() and then the DSQ would have to be consumed in ops.dispatch(). Later addition of scx_bpf_dispatch_from_dsq*() made the confusion even worse as "dispatch" in this context meant moving a task to an arbitrary DSQ from a user DSQ.
Clean up the API with the following renames:
1. scx_bpf_dispatch[_vtime]() -> scx_bpf_dsq_insert[_vtime]()
2. scx_bpf_consume() -> scx_bpf_dsq_move_to_local()
3. scx_bpf_dispatch[_vtime]_from_dsq*() -> scx_bpf_dsq_move[_vtime]*()
This patch performs the second rename. Compatibility is maintained by:
- The previous kfunc names are still provided by the kernel so that old binaries can run. Kernel generates a warning when the old names are used.
- compat.bpf.h provides wrappers for the new names which automatically fall back to the old names when running on older kernels. They also trigger build error if old names are used for new builds.
The compat features will be dropped after v6.15.
v2: Comment and documentation updates.
--- Documentation/scheduler/sched-ext.rst | 21 ++++++----- kernel/sched/ext.c | 45 +++++++++++++++--------- tools/sched_ext/include/scx/common.bpf.h | 2 +- tools/sched_ext/include/scx/compat.bpf.h | 11 ++++++ tools/sched_ext/scx_central.bpf.c | 4 +-- tools/sched_ext/scx_flatcg.bpf.c | 6 ++-- tools/sched_ext/scx_qmap.bpf.c | 4 +-- tools/sched_ext/scx_simple.bpf.c | 2 +- 8 files changed, 58 insertions(+), 37 deletions(-)
Documentation/scheduler/sched-ext.rst +10 -11
@@ -203,13 +203,12 @@ an arbitrary number of dsq's using ``scx_bpf_create_dsq()`` and ``scx_bpf_destroy_dsq()``. A CPU always executes a task from its local DSQ. A task is "inserted" into a -DSQ. A non-local DSQ is "consumed" to transfer a task to the consuming CPU's -local DSQ. +DSQ. A task in a non-local DSQ is "move"d into the target CPU's local DSQ. When a CPU is looking for the next task to run, if the local DSQ is not -empty, the first task is picked. Otherwise, the CPU tries to consume the -global DSQ. If that doesn't yield a runnable task either, ``ops.dispatch()`` -is invoked. +empty, the first task is picked. Otherwise, the CPU tries to move a task +from the global DSQ. If that doesn't yield a runnable task either, +``ops.dispatch()`` is invoked. Scheduling Cycle ----------------
@@ -265,15 +264,15 @@ The following briefly shows how a waking task is scheduled and executed. rather than performing them immediately. There can be up to ``ops.dispatch_max_batch`` pending tasks. - * ``scx_bpf_consume()`` tranfers a task from the specified non-local DSQ - to the dispatching DSQ. This function cannot be called with any BPF - locks held. ``scx_bpf_consume()`` flushes the pending dispatched tasks - before trying to consume the specified DSQ. + * ``scx_bpf_move_to_local()`` moves a task from the specified non-local + DSQ to the dispatching DSQ. This function cannot be called with any BPF + locks held. ``scx_bpf_move_to_local()`` flushes the pending insertions + tasks before trying to move from the specified DSQ. 4. After ``ops.dispatch()`` returns, if there are tasks in the local DSQ, the CPU runs the first one. If empty, the following steps are taken: - * Try to consume the global DSQ. If successful, run the task. + * Try to move from the global DSQ. If successful, run the task. * If ``ops.dispatch()`` has dispatched any tasks, retry #3.
@@ -286,7 +285,7 @@ Note that the BPF scheduler can always choose to dispatch tasks immediately in ``ops.enqueue()`` as illustrated in the above simple example. If only the built-in DSQs are used, there is no need to implement ``ops.dispatch()`` as a task is never queued on the BPF scheduler and both the local and global -DSQs are consumed automatically. +DSQs are executed automatically. ``scx_bpf_dsq_insert()`` inserts the task on the FIFO of the target DSQ. Use ``scx_bpf_dsq_insert_vtime()`` for the priority queue. Internal DSQs such as
kernel/sched/ext.c +28 -17
98 lines not on this page · raw message
tools/sched_ext/include/scx/common.bpf.h +1 -1
@@ -40,7 +40,7 @@ void scx_bpf_dsq_insert(struct task_struct *p, u64 dsq_id, u64 slice, u64 enq_fl void scx_bpf_dsq_insert_vtime(struct task_struct *p, u64 dsq_id, u64 slice, u64 vtime, u64 enq_flags) __ksym __weak; u32 scx_bpf_dispatch_nr_slots(void) __ksym; void scx_bpf_dispatch_cancel(void) __ksym; -bool scx_bpf_consume(u64 dsq_id) __ksym; +bool scx_bpf_dsq_move_to_local(u64 dsq_id) __ksym; void scx_bpf_dispatch_from_dsq_set_slice(struct bpf_iter_scx_dsq *it__iter, u64 slice) __ksym __weak; void scx_bpf_dispatch_from_dsq_set_vtime(struct bpf_iter_scx_dsq *it__iter, u64 vtime) __ksym __weak; bool scx_bpf_dispatch_from_dsq(struct bpf_iter_scx_dsq *it__iter, struct task_struct *p, u64 dsq_id, u64 enq_flags) __ksym __weak;
tools/sched_ext/include/scx/compat.bpf.h +11 -0
@@ -43,6 +43,7 @@*/ void scx_bpf_dispatch___compat(struct task_struct *p, u64 dsq_id, u64 slice, u64 enq_flags) __ksym __weak; void scx_bpf_dispatch_vtime___compat(struct task_struct *p, u64 dsq_id, u64 slice, u64 vtime, u64 enq_flags) __ksym __weak; +bool scx_bpf_consume___compat(u64 dsq_id) __ksym __weak;#define scx_bpf_dsq_insert (p, dsq_id, slice, enq_flags) \ (bpf_ksym_exists(scx_bpf_dsq_insert) ? \
@@ -54,12 +55,22 @@ void scx_bpf_dispatch_vtime___compat(struct task_struct *p, u64 dsq_id, u64 slic scx_bpf_dsq_insert_vtime((p), (dsq_id), (slice), (vtime), (enq_flags)) : \ scx_bpf_dispatch_vtime___compat((p), (dsq_id), (slice), (vtime), (enq_flags))) +#define scx_bpf_dsq_move_to_local (dsq_id) \ + (bpf_ksym_exists(scx_bpf_dsq_move_to_local) ? \ + scx_bpf_dsq_move_to_local((dsq_id)) : \ + scx_bpf_consume___compat((dsq_id))) +#define scx_bpf_dispatch (p, dsq_id, slice, enq_flags) \ _Static_assert(false, "scx_bpf_dispatch() renamed to scx_bpf_dsq_insert()")#define scx_bpf_dispatch_vtime (p, dsq_id, slice, vtime, enq_flags) \ _Static_assert(false, "scx_bpf_dispatch_vtime() renamed to scx_bpf_dsq_insert_vtime()") +#define scx_bpf_consume (dsq_id) ({ \ + _Static_assert(false, "scx_bpf_consume() renamed to scx_bpf_dsq_move_to_local()"); \ + false; \ +}) +/* * Define sched_ext_ops. This may be expanded to define multiple variants for * backward compatibility. See compat.h::SCX_OPS_LOAD/ATTACH().
tools/sched_ext/scx_central.bpf.c +2 -2
@@ -219,13 +219,13 @@ void BPF_STRUCT_OPS(central_dispatch, s32 cpu, struct task_struct *prev) }/* look for a task to run on the central CPU */ -if (scx_bpf_consume (FALLBACK_DSQ_ID )) +if (scx_bpf_dsq_move_to_local (FALLBACK_DSQ_ID ))return ;dispatch_to_cpu (central_cpu); }else {bool *gimme; -if (scx_bpf_consume (FALLBACK_DSQ_ID )) +if (scx_bpf_dsq_move_to_local (FALLBACK_DSQ_ID ))return ; gimme =ARRAY_ELEM_PTR (cpu_gimme_task, cpu, nr_cpu_ids);
tools/sched_ext/scx_flatcg.bpf.c +3 -3
@@ -665,7 +665,7 @@ static bool try_pick_next_cgroup(u64 *cgidp) goto out_free; } -if (!scx_bpf_consume (cgid)) { +if (!scx_bpf_dsq_move_to_local (cgid)) {bpf_cgroup_release (cgrp);stat_inc (FCG_STAT_PNC_EMPTY ); goto out_stash;
@@ -745,7 +745,7 @@ void BPF_STRUCT_OPS(fcg_dispatch, s32 cpu, struct task_struct *prev) goto pick_next_cgroup;if (vtime_before (now, cpuc->cur_at + cgrp_slice_ns)) { -if (scx_bpf_consume (cpuc->cur_cgid)) { +if (scx_bpf_dsq_move_to_local (cpuc->cur_cgid)) {stat_inc (FCG_STAT_CNS_KEEP );return ; }
@@ -785,7 +785,7 @@ void BPF_STRUCT_OPS(fcg_dispatch, s32 cpu, struct task_struct *prev) pick_next_cgroup: cpuc->cur_at = now; -if (scx_bpf_consume (FALLBACK_DSQ )) { +if (scx_bpf_dsq_move_to_local (FALLBACK_DSQ )) { cpuc->cur_cgid =0 ;return ; }
tools/sched_ext/scx_qmap.bpf.c +2 -2
@@ -374,7 +374,7 @@ void BPF_STRUCT_OPS(qmap_dispatch, s32 cpu, struct task_struct *prev)if (dispatch_highpri (false))return ; -if (!nr_highpri_queued &&scx_bpf_consume (SHARED_DSQ )) +if (!nr_highpri_queued &&scx_bpf_dsq_move_to_local (SHARED_DSQ ))return ;if (dsp_inf_loop_after && nr_dispatched > dsp_inf_loop_after) {
@@ -439,7 +439,7 @@ void BPF_STRUCT_OPS(qmap_dispatch, s32 cpu, struct task_struct *prev)if (!batch || !scx_bpf_dispatch_nr_slots ()) {if (dispatch_highpri (false))return ; -scx_bpf_consume (SHARED_DSQ ); +scx_bpf_dsq_move_to_local (SHARED_DSQ );return ; }if (!cpuc->dsp_cnt)
tools/sched_ext/scx_simple.bpf.c +1 -1
@@ -94,7 +94,7 @@ void BPF_STRUCT_OPS(simple_enqueue, struct task_struct *p, u64 enq_flags)void BPF_STRUCT_OPS (simple_dispatch ,s32 cpu,struct task_struct *prev) { -scx_bpf_consume (SHARED_DSQ ); +scx_bpf_dsq_move_to_local (SHARED_DSQ ); }void BPF_STRUCT_OPS (simple_running ,struct task_struct *p)
Signature · 1 line
2.47.0
Tejun Heo
reviewerPATCH 3/3 sched_ext: Rename scx_bpf_dispatch[_vtime]_from_dsq*() -> scx_bpf_dsq_move[_vtime]*()
In reply to Tejun HeoIn sched_ext API, a repeatedly reported pain point is the overuse of the verb "dispatch" and confusion around "consume":
- ops.dispatch()
- scx_bpf_dispatch[_vtime]()
- scx_bpf_consume()
- scx_bpf_dispatch[_vtime]_from_dsq*()
This overloading of the term is historical. Originally, there were only built-in DSQs and moving a task into a DSQ always dispatched it for execution. Using the verb "dispatch" for the kfuncs to move tasks into these DSQs made sense.
Later, user DSQs were added and scx_bpf_dispatch[_vtime]() updated to be able to insert tasks into any DSQ. The only allowed DSQ to DSQ transfer was from a non-local DSQ to a local DSQ and this operation was named "consume". This was already confusing as a task could be dispatched to a user DSQ from ops.enqueue() and then the DSQ would have to be consumed in ops.dispatch(). Later addition of scx_bpf_dispatch_from_dsq*() made the confusion even worse as "dispatch" in this context meant moving a task to an arbitrary DSQ from a user DSQ.
Clean up the API with the following renames:
1. scx_bpf_dispatch[_vtime]() -> scx_bpf_dsq_insert[_vtime]()
2. scx_bpf_consume() -> scx_bpf_dsq_move_to_local()
3. scx_bpf_dispatch[_vtime]_from_dsq*() -> scx_bpf_dsq_move[_vtime]*()
This patch performs the third set of renames. Compatibility is maintained by:
- The previous kfunc names are still provided by the kernel so that old binaries can run. Kernel generates a warning when the old names are used.
- compat.bpf.h provides wrappers for the new names which automatically fall back to the old names when running on older kernels. They also trigger build error if old names are used for new builds.
- scx_bpf_dispatch[_vtime]_from_dsq*() were already wrapped in __COMPAT macros as they were introduced during v6.12 cycle. Wrap new API in __COMPAT macros too and trigger build errors on both __COMPAT prefixed and naked usages of the old names.
The compat features will be dropped after v6.15.
--- kernel/sched/ext.c | 97 +++++++++++++++++------- tools/sched_ext/include/scx/common.bpf.h | 12 +-- tools/sched_ext/include/scx/compat.bpf.h | 82 ++++++++++++++++---- tools/sched_ext/scx_qmap.bpf.c | 20 ++--- 4 files changed, 152 insertions(+), 59 deletions(-)
kernel/sched/ext.c +68 -29
@@ -6422,9 +6422,8 @@ static const struct btf_kfunc_id_set scx_kfunc_set_enqueue_dispatch = { .set = &scx_kfunc_ids_enqueue_dispatch, }; -static bool scx_dispatch_from_dsq (struct bpf_iter_scx_dsq_kern *kit, -struct task_struct *p,u64 dsq_id, -u64 enq_flags) +static bool scx_dsq_move (struct bpf_iter_scx_dsq_kern *kit, +struct task_struct *p,u64 dsq_id,u64 enq_flags) {struct scx_dispatch_q *src_dsq = kit->dsq, *dst_dsq;struct rq *this_rq, *src_rq, *locked_rq;
@@ -6594,16 +6593,16 @@ __bpf_kfunc bool scx_bpf_consume(u64 dsq_id) }/** -* scx_bpf_dispatch_from_dsq_set_slice - Override slice when dispatching from DSQ +* scx_bpf_dsq_move_set_slice - Override slice when moving between DSQs * @it__iter: DSQ iterator in progress -* @slice: duration the dispatched task can run for in nsecs +* @slice: duration the moved task can run for in nsecs * -* Override the slice of the next task that will be dispatched from @it__iter -* using scx_bpf_dispatch_from_dsq[_vtime](). If this function is not called, -* the previous slice duration is kept. +* Override the slice of the next task that will be moved from @it__iter using +* scx_bpf_dsq_move[_vtime](). If this function is not called, the previous +* slice duration is kept. */ -__bpf_kfunc void scx_bpf_dispatch_from_dsq_set_slice( -struct bpf_iter_scx_dsq *it__iter,u64 slice) +__bpf_kfunc void scx_bpf_dsq_move_set_slice(struct bpf_iter_scx_dsq *it__iter, +u64 slice) {struct bpf_iter_scx_dsq_kern *kit = (void *)it__iter;
@@ -6611,18 +6610,26 @@ __bpf_kfunc void scx_bpf_dispatch_from_dsq_set_slice( kit->cursor.flags |= __SCX_DSQ_ITER_HAS_SLICE; } +/* for backward compatibility, will be removed in v6.15 */ +__bpf_kfunc void scx_bpf_dispatch_from_dsq_set_slice( +struct bpf_iter_scx_dsq *it__iter,u64 slice) +{ +printk_deferred_once (KERN_WARNING "sched_ext: scx_bpf_dispatch_from_dsq_set_slice() renamed to scx_bpf_dsq_move_set_slice()" ); +scx_bpf_dsq_move_set_slice (it__iter, slice); +} +/** -* scx_bpf_dispatch_from_dsq_set_vtime - Override vtime when dispatching from DSQ +* scx_bpf_dsq_move_set_vtime - Override vtime when moving between DSQs * @it__iter: DSQ iterator in progress * @vtime: task's ordering inside the vtime-sorted queue of the target DSQ * -* Override the vtime of the next task that will be dispatched from @it__iter -* using scx_bpf_dispatch_from_dsq_vtime(). If this function is not called, the -* previous slice vtime is kept. If scx_bpf_dispatch_from_dsq() is used to -* dispatch the next task, the override is ignored and cleared. +* Override the vtime of the next task that will be moved from @it__iter using +* scx_bpf_dsq_move_vtime(). If this function is not called, the previous slice +* vtime is kept. If scx_bpf_dsq_move() is used to dispatch the next task, the +* override is ignored and cleared. */ -__bpf_kfunc void scx_bpf_dispatch_from_dsq_set_vtime( -struct bpf_iter_scx_dsq *it__iter,u64 vtime) +__bpf_kfunc void scx_bpf_dsq_move_set_vtime(struct bpf_iter_scx_dsq *it__iter, +u64 vtime) {struct bpf_iter_scx_dsq_kern *kit = (void *)it__iter;
@@ -6630,8 +6637,16 @@ __bpf_kfunc void scx_bpf_dispatch_from_dsq_set_vtime( kit->cursor.flags |= __SCX_DSQ_ITER_HAS_VTIME; } +/* for backward compatibility, will be removed in v6.15 */ +__bpf_kfunc void scx_bpf_dispatch_from_dsq_set_vtime( +struct bpf_iter_scx_dsq *it__iter,u64 vtime) +{ +printk_deferred_once (KERN_WARNING "sched_ext: scx_bpf_dispatch_from_dsq_set_vtime() renamed to scx_bpf_dsq_move_set_vtime()" ); +scx_bpf_dsq_move_set_vtime (it__iter, vtime); +} +/** -* scx_bpf_dispatch_from_dsq - Move a task from DSQ iteration to a DSQ +* scx_bpf_dsq_move - Move a task from DSQ iteration to a DSQ * @it__iter: DSQ iterator in progress * @p: task to transfer * @dsq_id: DSQ to move @p to
@@ -6646,8 +6661,7 @@ __bpf_kfunc void scx_bpf_dispatch_from_dsq_set_vtime(* @p was obtained from the DSQ iteration. @p just has to be on the DSQ and have * been queued before the iteration started. * -* @p's slice is kept by default. Use scx_bpf_dispatch_from_dsq_set_slice() to -* update. +* @p's slice is kept by default. Use scx_bpf_dsq_move_set_slice() to update. * * Can be called from ops.dispatch() or any BPF context which doesn't hold a rq * lock (e.g. BPF timers or SYSCALL programs).
@@ -6655,16 +6669,25 @@ __bpf_kfunc void scx_bpf_dispatch_from_dsq_set_vtime(* Returns %true if @p has been consumed, %false if @p had already been consumed * or dequeued. */ +__bpf_kfunc bool scx_bpf_dsq_move(struct bpf_iter_scx_dsq *it__iter, +struct task_struct *p,u64 dsq_id, +u64 enq_flags) +{ +return scx_dsq_move ((struct bpf_iter_scx_dsq_kern *)it__iter, + p, dsq_id, enq_flags); +} + +/* for backward compatibility, will be removed in v6.15 */ __bpf_kfunc bool scx_bpf_dispatch_from_dsq(struct bpf_iter_scx_dsq *it__iter,struct task_struct *p,u64 dsq_id,u64 enq_flags) { -return scx_dispatch_from_dsq ((struct bpf_iter_scx_dsq_kern *)it__iter, - p, dsq_id, enq_flags); +printk_deferred_once (KERN_WARNING "sched_ext: scx_bpf_dispatch_from_dsq() renamed to scx_bpf_dsq_move()" ); +return scx_bpf_dsq_move (it__iter, p, dsq_id, enq_flags); }/** -* scx_bpf_dispatch_vtime_from_dsq - Move a task from DSQ iteration to a PRIQ DSQ +* scx_bpf_dsq_move_vtime - Move a task from DSQ iteration to a PRIQ DSQ * @it__iter: DSQ iterator in progress * @p: task to transfer * @dsq_id: DSQ to move @p to
@@ -6674,19 +6697,27 @@ __bpf_kfunc bool scx_bpf_dispatch_from_dsq(struct bpf_iter_scx_dsq *it__iter,* priority queue of the DSQ specified by @dsq_id. The destination must be a * user DSQ as only user DSQs support priority queue. * -* @p's slice and vtime are kept by default. Use -* scx_bpf_dispatch_from_dsq_set_slice() and -* scx_bpf_dispatch_from_dsq_set_vtime() to update. +* @p's slice and vtime are kept by default. Use scx_bpf_dsq_move_set_slice() +* and scx_bpf_dsq_move_set_vtime() to update. * -* All other aspects are identical to scx_bpf_dispatch_from_dsq(). See +* All other aspects are identical to scx_bpf_dsq_move(). See * scx_bpf_dsq_insert_vtime() for more information on @vtime. */ +__bpf_kfunc bool scx_bpf_dsq_move_vtime(struct bpf_iter_scx_dsq *it__iter, +struct task_struct *p,u64 dsq_id, +u64 enq_flags) +{ +return scx_dsq_move ((struct bpf_iter_scx_dsq_kern *)it__iter, + p, dsq_id, enq_flags |SCX_ENQ_DSQ_PRIQ ); +} + +/* for backward compatibility, will be removed in v6.15 */ __bpf_kfunc bool scx_bpf_dispatch_vtime_from_dsq(struct bpf_iter_scx_dsq *it__iter,struct task_struct *p,u64 dsq_id,u64 enq_flags) { -return scx_dispatch_from_dsq ((struct bpf_iter_scx_dsq_kern *)it__iter, - p, dsq_id, enq_flags |SCX_ENQ_DSQ_PRIQ ); +printk_deferred_once (KERN_WARNING "sched_ext: scx_bpf_dispatch_from_dsq_vtime() renamed to scx_bpf_dsq_move_vtime()" ); +return scx_bpf_dsq_move_vtime (it__iter, p, dsq_id, enq_flags); }__bpf_kfunc_end_defs ();
@@ -6696,6 +6727,10 @@ BTF_ID_FLAGS(func, scx_bpf_dispatch_nr_slots) BTF_ID_FLAGS(func, scx_bpf_dispatch_cancel) BTF_ID_FLAGS(func, scx_bpf_dsq_move_to_local) BTF_ID_FLAGS(func, scx_bpf_consume) +BTF_ID_FLAGS(func, scx_bpf_dsq_move_set_slice) +BTF_ID_FLAGS(func, scx_bpf_dsq_move_set_vtime) +BTF_ID_FLAGS(func, scx_bpf_dsq_move, KF_RCU) +BTF_ID_FLAGS(func, scx_bpf_dsq_move_vtime, KF_RCU) BTF_ID_FLAGS(func, scx_bpf_dispatch_from_dsq_set_slice) BTF_ID_FLAGS(func, scx_bpf_dispatch_from_dsq_set_vtime)BTF_ID_FLAGS (func, scx_bpf_dispatch_from_dsq,KF_RCU )
@@ -6796,6 +6831,10 @@ __bpf_kfunc_end_defs(); BTF_KFUNCS_START(scx_kfunc_ids_unlocked) BTF_ID_FLAGS(func, scx_bpf_create_dsq, KF_SLEEPABLE) +BTF_ID_FLAGS(func, scx_bpf_dsq_move_set_slice) +BTF_ID_FLAGS(func, scx_bpf_dsq_move_set_vtime) +BTF_ID_FLAGS(func, scx_bpf_dsq_move, KF_RCU) +BTF_ID_FLAGS(func, scx_bpf_dsq_move_vtime, KF_RCU) BTF_ID_FLAGS(func, scx_bpf_dispatch_from_dsq_set_slice) BTF_ID_FLAGS(func, scx_bpf_dispatch_from_dsq_set_vtime) BTF_ID_FLAGS(func, scx_bpf_dispatch_from_dsq, KF_RCU)
tools/sched_ext/include/scx/common.bpf.h +6 -6
@@ -41,10 +41,10 @@ void scx_bpf_dsq_insert_vtime(struct task_struct *p, u64 dsq_id, u64 slice, u64 u32 scx_bpf_dispatch_nr_slots(void) __ksym; void scx_bpf_dispatch_cancel(void) __ksym; bool scx_bpf_dsq_move_to_local(u64 dsq_id) __ksym; -void scx_bpf_dispatch_from_dsq_set_slice(struct bpf_iter_scx_dsq *it__iter, u64 slice) __ksym __weak; -void scx_bpf_dispatch_from_dsq_set_vtime(struct bpf_iter_scx_dsq *it__iter, u64 vtime) __ksym __weak; -bool scx_bpf_dispatch_from_dsq(struct bpf_iter_scx_dsq *it__iter, struct task_struct *p, u64 dsq_id, u64 enq_flags) __ksym __weak; -bool scx_bpf_dispatch_vtime_from_dsq(struct bpf_iter_scx_dsq *it__iter, struct task_struct *p, u64 dsq_id, u64 enq_flags) __ksym __weak; +void scx_bpf_dsq_move_set_slice(struct bpf_iter_scx_dsq *it__iter, u64 slice) __ksym; +void scx_bpf_dsq_move_set_vtime(struct bpf_iter_scx_dsq *it__iter, u64 vtime) __ksym; +bool scx_bpf_dsq_move(struct bpf_iter_scx_dsq *it__iter, struct task_struct *p, u64 dsq_id, u64 enq_flags) __ksym __weak; +bool scx_bpf_dsq_move_vtime(struct bpf_iter_scx_dsq *it__iter, struct task_struct *p, u64 dsq_id, u64 enq_flags) __ksym __weak; u32 scx_bpf_reenqueue_local(void) __ksym; void scx_bpf_kick_cpu(s32 cpu, u64 flags) __ksym; s32 scx_bpf_dsq_nr_queued(u64 dsq_id) __ksym;
@@ -74,8 +74,8 @@ struct rq *scx_bpf_cpu_rq(s32 cpu) __ksym;struct cgroup *scx_bpf_task_cgroup (struct task_struct *p) __ksym__weak ;/* -* Use the following as @it__iter when calling -* scx_bpf_dispatch[_vtime]_from_dsq() from within bpf_for_each() loops. +* Use the following as @it__iter when calling scx_bpf_dsq_move[_vtime]() from +* within bpf_for_each() loops. */ #define BPF_FOR_EACH_ITER (&___it)
tools/sched_ext/include/scx/compat.bpf.h +68 -14
110 lines not on this page · raw message
tools/sched_ext/scx_qmap.bpf.c +10 -10
@@ -294,10 +294,10 @@ static void update_core_sched_head_seq(struct task_struct *p) }/* -* To demonstrate the use of scx_bpf_dispatch_from_dsq(), implement silly -* selective priority boosting mechanism by scanning SHARED_DSQ looking for -* highpri tasks, moving them to HIGHPRI_DSQ and then consuming them first. This -* makes minor difference only when dsp_batch is larger than 1. +* To demonstrate the use of scx_bpf_dsq_move(), implement silly selective +* priority boosting mechanism by scanning SHARED_DSQ looking for highpri tasks, +* moving them to HIGHPRI_DSQ and then consuming them first. This makes minor +* difference only when dsp_batch is larger than 1. * * scx_bpf_dispatch[_vtime]_from_dsq() are allowed both from ops.dispatch() and * non-rq-lock holding BPF programs. As demonstration, this function is called
@@ -318,11 +318,11 @@ static bool dispatch_highpri(bool from_timer)if (tctx->highpri) {/* exercise the set_*() and vtime interface too */ -__COMPAT_scx_bpf_dispatch_from_dsq_set_slice ( +__COMPAT_scx_bpf_dsq_move_set_slice (BPF_FOR_EACH_ITER , slice_ns *2 ); -__COMPAT_scx_bpf_dispatch_from_dsq_set_vtime ( +__COMPAT_scx_bpf_dsq_move_set_vtime (BPF_FOR_EACH_ITER , highpri_seq++); -__COMPAT_scx_bpf_dispatch_vtime_from_dsq ( +__COMPAT_scx_bpf_dsq_move_vtime (BPF_FOR_EACH_ITER , p,HIGHPRI_DSQ ,0 ); } }
@@ -340,9 +340,9 @@ static bool dispatch_highpri(bool from_timer)else cpu =scx_bpf_pick_any_cpu (p->cpus_ptr,0 ); -if (__COMPAT_scx_bpf_dispatch_from_dsq (BPF_FOR_EACH_ITER , p, -SCX_DSQ_LOCAL_ON | cpu, -SCX_ENQ_PREEMPT )) { +if (__COMPAT_scx_bpf_dsq_move (BPF_FOR_EACH_ITER , p, +SCX_DSQ_LOCAL_ON | cpu, +SCX_ENQ_PREEMPT )) {if (cpu == this_cpu) { dispatched = true;__sync_fetch_and_add (&nr_expedited_local,1 );
Signature · 1 line
2.47.0
Hi Tejun,
Quoted 40 lines · Tejun Heo
Hello,
[v1] -> v2: Comment and documentation updates.
In
sched_extAPI, a repeatedly reported pain point is the overuse of the verb "dispatch" and confusion around "consume":-
ops.dispatch()
- scx_bpf_dispatch[_vtime]()
-scx_bpf_consume()
- scx_bpf_dispatch[_vtime]_from_dsq*()This overloading of the term is historical. Originally, there were only built-in DSQs and moving a task into a DSQ always dispatched it for execution. Using the verb "dispatch" for the kfuncs to move tasks into these DSQs made sense.
Later, user DSQs were added and scx_bpf_dispatch[_vtime]() updated to be able to insert tasks into any DSQ. The only allowed DSQ to DSQ transfer was from a non-local DSQ to a local DSQ and this operation was named "consume". This was already confusing as a task could be dispatched to a user DSQ from
ops.enqueue()and then the DSQ would have to be consumed inops.dispatch(). Later addition of scx_bpf_dispatch_from_dsq*() made the confusion even worse as "dispatch" in this context meant moving a task to an arbitrary DSQ from a user DSQ.Clean up the API with the following renames:
1. scx_bpf_dispatch[_vtime]() -> scx_bpf_dsq_insert[_vtime]()
2.scx_bpf_consume()->scx_bpf_dsq_move_to_local()
3. scx_bpf_dispatch[_vtime]_from_dsq*() -> scx_bpf_dsq_move[_vtime]*()This patchset is on top of sched_ext/for-6.13
72b85bf6a7f6("sched_ext:
scx_bpf_dispatch_from_dsq_set_*() are allowed from unlocked context") and contains the following patches:0001-sched_ext-Rename-scx_bpf_dispatch-_vtime-to-scx_bpf_.patch 0002-sched_ext-Rename-scx_bpf_consume-to-scx_bpf_dsq_move.patch 0003-sched_ext-Rename-scx_bpf_dispatch-_vtime-_from_dsq-s.patch
Quoted 5 lines
and is always available in the following git branch:
git://git.kernel.org/pub/scm/linux/kernel/git/tj/sched_ext.gitscx-api-rename-dispatch-v2diffstat follows. Thanks.
Looks good to me, thanks!
-Andrea
Hello,
Quoted 40 lines · Tejun Heo
Hello,
[v1] -> v2: Comment and documentation updates.
In
sched_extAPI, a repeatedly reported pain point is the overuse of the verb "dispatch" and confusion around "consume":-
ops.dispatch()
- scx_bpf_dispatch[_vtime]()
-scx_bpf_consume()
- scx_bpf_dispatch[_vtime]_from_dsq*()This overloading of the term is historical. Originally, there were only built-in DSQs and moving a task into a DSQ always dispatched it for execution. Using the verb "dispatch" for the kfuncs to move tasks into these DSQs made sense.
Later, user DSQs were added and scx_bpf_dispatch[_vtime]() updated to be able to insert tasks into any DSQ. The only allowed DSQ to DSQ transfer was from a non-local DSQ to a local DSQ and this operation was named "consume". This was already confusing as a task could be dispatched to a user DSQ from
ops.enqueue()and then the DSQ would have to be consumed inops.dispatch(). Later addition of scx_bpf_dispatch_from_dsq*() made the confusion even worse as "dispatch" in this context meant moving a task to an arbitrary DSQ from a user DSQ.Clean up the API with the following renames:
1. scx_bpf_dispatch[_vtime]() -> scx_bpf_dsq_insert[_vtime]()
2.scx_bpf_consume()->scx_bpf_dsq_move_to_local()
3. scx_bpf_dispatch[_vtime]_from_dsq*() -> scx_bpf_dsq_move[_vtime]*()This patchset is on top of sched_ext/for-6.13
72b85bf6a7f6("sched_ext:
scx_bpf_dispatch_from_dsq_set_*() are allowed from unlocked context") and contains the following patches:0001-sched_ext-Rename-scx_bpf_dispatch-_vtime-to-scx_bpf_.patch 0002-sched_ext-Rename-scx_bpf_consume-to-scx_bpf_dsq_move.patch 0003-sched_ext-Rename-scx_bpf_dispatch-_vtime-_from_dsq-s.patch
Quoted 5 lines
and is always available in the following git branch:
git://git.kernel.org/pub/scm/linux/kernel/git/tj/sched_ext.gitscx-api-rename-dispatch-v2diffstat follows. Thanks.
Looks good to me. Thanks!
Regards,
Changwoo Min
Johannes Bechberger
Acked-byHello,
On 24. 11. 11. 05:02, Tejun Heo wrote:
•••
Quoted 26 lines
Hello,
[v1] -> v2: Comment and documentation updates.
Insched_extAPI, a repeatedly reported pain point is the overuse of the verb "dispatch" and confusion around "consume":
-ops.dispatch()
- scx_bpf_dispatch[_vtime]()
-scx_bpf_consume()
- scx_bpf_dispatch[_vtime]_from_dsq*()
This overloading of the term is historical. Originally, there were only built-in DSQs and moving a task into a DSQ always dispatched it for execution. Using the verb "dispatch" for the kfuncs to move tasks into these DSQs made sense.
Later, user DSQs were added and scx_bpf_dispatch[_vtime]() updated to be able to insert tasks into any DSQ. The only allowed DSQ to DSQ transfer was from a non-local DSQ to a local DSQ and this operation was named "consume". This was already confusing as a task could be dispatched to a user DSQ fromops.enqueue()and then the DSQ would have to be consumed inops.dispatch(). Later addition of scx_bpf_dispatch_from_dsq*() made the confusion even worse as "dispatch" in this context meant moving a task to an arbitrary DSQ from a user DSQ.
Clean up the API with the following renames:
1. scx_bpf_dispatch[_vtime]() -> scx_bpf_dsq_insert[_vtime]()
2.scx_bpf_consume()->scx_bpf_dsq_move_to_local()
3. scx_bpf_dispatch[_vtime]_from_dsq*() -> scx_bpf_dsq_move[_vtime]*() This patchset is on top of sched_ext/for-6.1372b85bf6a7f6("sched_ext:
Quoted 9 lines
scx_bpf_dispatch_from_dsq_set_*() are allowed from unlocked context") and
contains the following patches:
0001-sched_ext-Rename-scx_bpf_dispatch-_vtime-to-scx_bpf_.patch
0002-sched_ext-Rename-scx_bpf_consume-to-scx_bpf_dsq_move.patch
0003-sched_ext-Rename-scx_bpf_dispatch-_vtime-_from_dsq-s.patch
and is always available in the following git branch:
git://git.kernel.org/pub/scm/linux/kernel/git/tj/sched_ext.githttp://git.kernel.org/pub/scm/linux/kernel/git/tj/sched_ext.git scx-api-rename-dispatch-v2 diffstat follows. Thanks.
Looks good to me too. Thanks for your effort :)
Regards
Johannes Bechberger
Re: [PATCH 3/3] sched_ext: Rename scx_bpf_dispatch[_vtime]_from_dsq*() -> scx_bpf_dsq_move[_vtime]*()
In reply to Tejun HeoHello,
Quoted 11 lines · Tejun Heo
In
sched_extAPI, a repeatedly reported pain point is the overuse of the verb "dispatch" and confusion around "consume": [...]Clean up the API with the following renames:
1. scx_bpf_dispatch[_vtime]() -> scx_bpf_dsq_insert[_vtime]()
2.scx_bpf_consume()->scx_bpf_dsq_move_to_local()
3. scx_bpf_dispatch[_vtime]_from_dsq*() -> scx_bpf_dsq_move[_vtime]*()This patch performs the third set of renames. Compatibility is maintained
by: [...]
Thanks Tejun.
For the whole series,
Giovanni
On Sun, Nov 10, 2024 at 10:02:50AM -1000, Tejun Heo wrote:
...
Quoted 6 lines
Clean up the API with the following renames:
1. scx_bpf_dispatch[_vtime]() -> scx_bpf_dsq_insert[_vtime]()
2.scx_bpf_consume()->scx_bpf_dsq_move_to_local()
3. scx_bpf_dispatch[_vtime]_from_dsq*() -> scx_bpf_dsq_move[_vtime]*()
Quoted 7 lines
This patchset is on top of sched_ext/for-6.13
72b85bf6a7f6("sched_ext:
scx_bpf_dispatch_from_dsq_set_*() are allowed from unlocked context") and contains the following patches:0001-sched_ext-Rename-scx_bpf_dispatch-_vtime-to-scx_bpf_.patch 0002-sched_ext-Rename-scx_bpf_consume-to-scx_bpf_dsq_move.patch 0003-sched_ext-Rename-scx_bpf_dispatch-_vtime-_from_dsq-s.patch
Applied to sched_ext/for-6.13.
Thanks.
Signature · 1 line
tejun
Quoted 32 lines · Tejun Heo
Hello,
[v1] -> v2: Comment and documentation updates.
In
sched_extAPI, a repeatedly reported pain point is the overuse of the verb "dispatch" and confusion around "consume":-
ops.dispatch()
- scx_bpf_dispatch[_vtime]()
-scx_bpf_consume()
- scx_bpf_dispatch[_vtime]_from_dsq*()This overloading of the term is historical. Originally, there were only built-in DSQs and moving a task into a DSQ always dispatched it for execution. Using the verb "dispatch" for the kfuncs to move tasks into these DSQs made sense.
Later, user DSQs were added and scx_bpf_dispatch[_vtime]() updated to be able to insert tasks into any DSQ. The only allowed DSQ to DSQ transfer was from a non-local DSQ to a local DSQ and this operation was named "consume". This was already confusing as a task could be dispatched to a user DSQ from
ops.enqueue()and then the DSQ would have to be consumed inops.dispatch(). Later addition of scx_bpf_dispatch_from_dsq*() made the confusion even worse as "dispatch" in this context meant moving a task to an arbitrary DSQ from a user DSQ.Clean up the API with the following renames:
1. scx_bpf_dispatch[_vtime]() -> scx_bpf_dsq_insert[_vtime]()
2.scx_bpf_consume()->scx_bpf_dsq_move_to_local()
3. scx_bpf_dispatch[_vtime]_from_dsq*() -> scx_bpf_dsq_move[_vtime]*()
Quoted 7 lines
This patchset is on top of sched_ext/for-6.13
72b85bf6a7f6("sched_ext:
scx_bpf_dispatch_from_dsq_set_*() are allowed from unlocked context") and contains the following patches:0001-sched_ext-Rename-scx_bpf_dispatch-_vtime-to-scx_bpf_.patch 0002-sched_ext-Rename-scx_bpf_consume-to-scx_bpf_dsq_move.patch 0003-sched_ext-Rename-scx_bpf_dispatch-_vtime-_from_dsq-s.patch
For the series: