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: Introduce scx_bpf_locked_rq()

Most fields in scx_bpf_cpu_rq() assume that its rq_lock is held.
Furthermore they become meaningless without rq lock, too.
Make a safer version of scx_bpf_cpu_rq() that only returns a rq
if we hold rq lock of that rq.

Also mark the new scx_bpf_locked_rq() as returning NULL as
scx_bpf_cpu_rq() should've been too.

Signed-off-by: Christian Loehle <christian.loehle@arm.com>
Acked-by: Andrea Righi <arighi@nvidia.com>
Signed-off-by: Tejun Heo <tj@kernel.org>

authored by

Christian Loehle and committed by
Tejun Heo
e0ca1696 a5bd6ba3

+24
+23
kernel/sched/ext.c
··· 6358 6358 } 6359 6359 6360 6360 /** 6361 + * scx_bpf_locked_rq - Return the rq currently locked by SCX 6362 + * 6363 + * Returns the rq if a rq lock is currently held by SCX. 6364 + * Otherwise emits an error and returns NULL. 6365 + */ 6366 + __bpf_kfunc struct rq *scx_bpf_locked_rq(void) 6367 + { 6368 + struct rq *rq; 6369 + 6370 + preempt_disable(); 6371 + rq = scx_locked_rq(); 6372 + if (!rq) { 6373 + preempt_enable(); 6374 + scx_kf_error("accessing rq without holding rq lock"); 6375 + return NULL; 6376 + } 6377 + preempt_enable(); 6378 + 6379 + return rq; 6380 + } 6381 + 6382 + /** 6361 6383 * scx_bpf_task_cgroup - Return the sched cgroup of a task 6362 6384 * @p: task of interest 6363 6385 * ··· 6543 6521 BTF_ID_FLAGS(func, scx_bpf_task_running, KF_RCU) 6544 6522 BTF_ID_FLAGS(func, scx_bpf_task_cpu, KF_RCU) 6545 6523 BTF_ID_FLAGS(func, scx_bpf_cpu_rq) 6524 + BTF_ID_FLAGS(func, scx_bpf_locked_rq, KF_RET_NULL) 6546 6525 #ifdef CONFIG_CGROUP_SCHED 6547 6526 BTF_ID_FLAGS(func, scx_bpf_task_cgroup, KF_RCU | KF_ACQUIRE) 6548 6527 #endif
+1
tools/sched_ext/include/scx/common.bpf.h
··· 103 103 bool scx_bpf_task_running(const struct task_struct *p) __ksym; 104 104 s32 scx_bpf_task_cpu(const struct task_struct *p) __ksym; 105 105 struct rq *scx_bpf_cpu_rq(s32 cpu) __ksym; 106 + struct rq *scx_bpf_locked_rq(void) __ksym; 106 107 struct cgroup *scx_bpf_task_cgroup(struct task_struct *p) __ksym __weak; 107 108 u64 scx_bpf_now(void) __ksym __weak; 108 109 void scx_bpf_events(struct scx_event_stats *events, size_t events__sz) __ksym __weak;