Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

sched_ext: Make scx_bpf_dsq_insert*() return bool

In preparation for hierarchical schedulers, change scx_bpf_dsq_insert() and
scx_bpf_dsq_insert_vtime() to return bool instead of void. With
sub-schedulers, there will be no reliable way to guarantee a task is still
owned by the sub-scheduler at insertion time (e.g., the task may have been
migrated to another scheduler). The bool return value will enable
sub-schedulers to detect and gracefully handle insertion failures.

For the root scheduler, insertion failures will continue to trigger scheduler
abort via scx_error(), so existing code doesn't need to check the return
value. Backward compatibility is maintained through compat wrappers.

Also update scx_bpf_dsq_move() documentation to clarify that it can return
false for sub-schedulers when @dsq_id points to a disallowed local DSQ.

Reviewed-by: Changwoo Min <changwoo@igalia.com>
Reviewed-by: Emil Tsalapatis <emil@etsalapatis.com>
Acked-by: Andrea Righi <arighi@nvidia.com>
Signed-off-by: Tejun Heo <tj@kernel.org>

Tejun Heo cded46d9 c0d630ba

+56 -15
+34 -11
kernel/sched/ext.c
··· 5426 5426 * exhaustion. If zero, the current residual slice is maintained. If 5427 5427 * %SCX_SLICE_INF, @p never expires and the BPF scheduler must kick the CPU with 5428 5428 * scx_bpf_kick_cpu() to trigger scheduling. 5429 + * 5430 + * Returns %true on successful insertion, %false on failure. On the root 5431 + * scheduler, %false return triggers scheduler abort and the caller doesn't need 5432 + * to check the return value. 5429 5433 */ 5430 - __bpf_kfunc void scx_bpf_dsq_insert(struct task_struct *p, u64 dsq_id, u64 slice, 5434 + __bpf_kfunc bool scx_bpf_dsq_insert(struct task_struct *p, u64 dsq_id, u64 slice, 5431 5435 u64 enq_flags) 5432 5436 { 5433 5437 struct scx_sched *sch; ··· 5439 5435 guard(rcu)(); 5440 5436 sch = rcu_dereference(scx_root); 5441 5437 if (unlikely(!sch)) 5442 - return; 5438 + return false; 5443 5439 5444 5440 if (!scx_dsq_insert_preamble(sch, p, enq_flags)) 5445 - return; 5441 + return false; 5446 5442 5447 5443 if (slice) 5448 5444 p->scx.slice = slice; ··· 5450 5446 p->scx.slice = p->scx.slice ?: 1; 5451 5447 5452 5448 scx_dsq_insert_commit(sch, p, dsq_id, enq_flags); 5449 + 5450 + return true; 5453 5451 } 5454 5452 5455 - static void scx_dsq_insert_vtime(struct scx_sched *sch, struct task_struct *p, 5453 + /* 5454 + * COMPAT: Will be removed in v6.23. 5455 + */ 5456 + __bpf_kfunc void scx_bpf_dsq_insert___compat(struct task_struct *p, u64 dsq_id, 5457 + u64 slice, u64 enq_flags) 5458 + { 5459 + scx_bpf_dsq_insert(p, dsq_id, slice, enq_flags); 5460 + } 5461 + 5462 + static bool scx_dsq_insert_vtime(struct scx_sched *sch, struct task_struct *p, 5456 5463 u64 dsq_id, u64 slice, u64 vtime, u64 enq_flags) 5457 5464 { 5458 5465 if (!scx_dsq_insert_preamble(sch, p, enq_flags)) 5459 - return; 5466 + return false; 5460 5467 5461 5468 if (slice) 5462 5469 p->scx.slice = slice; ··· 5477 5462 p->scx.dsq_vtime = vtime; 5478 5463 5479 5464 scx_dsq_insert_commit(sch, p, dsq_id, enq_flags | SCX_ENQ_DSQ_PRIQ); 5465 + 5466 + return true; 5480 5467 } 5481 5468 5482 5469 struct scx_bpf_dsq_insert_vtime_args { ··· 5514 5497 * function must not be called on a DSQ which already has one or more FIFO tasks 5515 5498 * queued and vice-versa. Also, the built-in DSQs (SCX_DSQ_LOCAL and 5516 5499 * SCX_DSQ_GLOBAL) cannot be used as priority queues. 5500 + * 5501 + * Returns %true on successful insertion, %false on failure. On the root 5502 + * scheduler, %false return triggers scheduler abort and the caller doesn't need 5503 + * to check the return value. 5517 5504 */ 5518 - __bpf_kfunc void 5505 + __bpf_kfunc bool 5519 5506 __scx_bpf_dsq_insert_vtime(struct task_struct *p, 5520 5507 struct scx_bpf_dsq_insert_vtime_args *args) 5521 5508 { ··· 5529 5508 5530 5509 sch = rcu_dereference(scx_root); 5531 5510 if (unlikely(!sch)) 5532 - return; 5511 + return false; 5533 5512 5534 - scx_dsq_insert_vtime(sch, p, args->dsq_id, args->slice, args->vtime, 5535 - args->enq_flags); 5513 + return scx_dsq_insert_vtime(sch, p, args->dsq_id, args->slice, 5514 + args->vtime, args->enq_flags); 5536 5515 } 5537 5516 5538 5517 /* ··· 5556 5535 5557 5536 BTF_KFUNCS_START(scx_kfunc_ids_enqueue_dispatch) 5558 5537 BTF_ID_FLAGS(func, scx_bpf_dsq_insert, KF_RCU) 5538 + BTF_ID_FLAGS(func, scx_bpf_dsq_insert___compat, KF_RCU) 5559 5539 BTF_ID_FLAGS(func, __scx_bpf_dsq_insert_vtime, KF_RCU) 5560 5540 BTF_ID_FLAGS(func, scx_bpf_dsq_insert_vtime, KF_RCU) 5561 5541 BTF_KFUNCS_END(scx_kfunc_ids_enqueue_dispatch) ··· 5811 5789 * Can be called from ops.dispatch() or any BPF context which doesn't hold a rq 5812 5790 * lock (e.g. BPF timers or SYSCALL programs). 5813 5791 * 5814 - * Returns %true if @p has been consumed, %false if @p had already been consumed 5815 - * or dequeued. 5792 + * Returns %true if @p has been consumed, %false if @p had already been 5793 + * consumed, dequeued, or, for sub-scheds, @dsq_id points to a disallowed local 5794 + * DSQ. 5816 5795 */ 5817 5796 __bpf_kfunc bool scx_bpf_dsq_move(struct bpf_iter_scx_dsq *it__iter, 5818 5797 struct task_struct *p, u64 dsq_id,
+1 -2
tools/sched_ext/include/scx/common.bpf.h
··· 62 62 s32 scx_bpf_select_cpu_dfl(struct task_struct *p, s32 prev_cpu, u64 wake_flags, bool *is_idle) __ksym; 63 63 s32 __scx_bpf_select_cpu_and(struct task_struct *p, const struct cpumask *cpus_allowed, 64 64 struct scx_bpf_select_cpu_and_args *args) __ksym __weak; 65 - void scx_bpf_dsq_insert(struct task_struct *p, u64 dsq_id, u64 slice, u64 enq_flags) __ksym __weak; 66 - void __scx_bpf_dsq_insert_vtime(struct task_struct *p, struct scx_bpf_dsq_insert_vtime_args *args) __ksym __weak; 65 + bool __scx_bpf_dsq_insert_vtime(struct task_struct *p, struct scx_bpf_dsq_insert_vtime_args *args) __ksym __weak; 67 66 u32 scx_bpf_dispatch_nr_slots(void) __ksym; 68 67 void scx_bpf_dispatch_cancel(void) __ksym; 69 68 bool scx_bpf_dsq_move_to_local(u64 dsq_id) __ksym __weak;
+21 -2
tools/sched_ext/include/scx/compat.bpf.h
··· 196 196 * Inline wrapper that packs scalar arguments into a struct and calls 197 197 * __scx_bpf_dsq_insert_vtime(). See __scx_bpf_dsq_insert_vtime() for details. 198 198 */ 199 - static inline void 199 + static inline bool 200 200 scx_bpf_dsq_insert_vtime(struct task_struct *p, u64 dsq_id, u64 slice, u64 vtime, 201 201 u64 enq_flags) 202 202 { ··· 208 208 .enq_flags = enq_flags, 209 209 }; 210 210 211 - __scx_bpf_dsq_insert_vtime(p, &args); 211 + return __scx_bpf_dsq_insert_vtime(p, &args); 212 212 } else { 213 213 scx_bpf_dsq_insert_vtime___compat(p, dsq_id, slice, vtime, 214 214 enq_flags); 215 + return true; 216 + } 217 + } 218 + 219 + /* 220 + * v6.19: scx_bpf_dsq_insert() now returns bool instead of void. Move 221 + * scx_bpf_dsq_insert() decl to common.bpf.h and drop compat helper after v6.22. 222 + */ 223 + bool scx_bpf_dsq_insert___new(struct task_struct *p, u64 dsq_id, u64 slice, u64 enq_flags) __ksym __weak; 224 + void scx_bpf_dsq_insert___compat(struct task_struct *p, u64 dsq_id, u64 slice, u64 enq_flags) __ksym __weak; 225 + 226 + static inline bool 227 + scx_bpf_dsq_insert(struct task_struct *p, u64 dsq_id, u64 slice, u64 enq_flags) 228 + { 229 + if (bpf_ksym_exists(scx_bpf_dsq_insert___new)) { 230 + return scx_bpf_dsq_insert___new(p, dsq_id, slice, enq_flags); 231 + } else { 232 + scx_bpf_dsq_insert___compat(p, dsq_id, slice, enq_flags); 233 + return true; 215 234 } 216 235 } 217 236