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_cpu_curr()

Provide scx_bpf_cpu_curr() as a way for scx schedulers to check the curr
task of a remote rq without assuming its lock is held.

Many scx schedulers make use of scx_bpf_cpu_rq() to check a remote curr
(e.g. to see if it should be preempted). This is problematic because
scx_bpf_cpu_rq() provides access to all fields of struct rq, most of
which aren't safe to use without holding the associated rq lock.

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
20b15809 e0ca1696

+15
+14
kernel/sched/ext.c
··· 6380 6380 } 6381 6381 6382 6382 /** 6383 + * scx_bpf_cpu_curr - Return remote CPU's curr task 6384 + * @cpu: CPU of interest 6385 + * 6386 + * Callers must hold RCU read lock (KF_RCU). 6387 + */ 6388 + __bpf_kfunc struct task_struct *scx_bpf_cpu_curr(s32 cpu) 6389 + { 6390 + if (!kf_cpu_valid(cpu, NULL)) 6391 + return NULL; 6392 + return rcu_dereference(cpu_rq(cpu)->curr); 6393 + } 6394 + 6395 + /** 6383 6396 * scx_bpf_task_cgroup - Return the sched cgroup of a task 6384 6397 * @p: task of interest 6385 6398 * ··· 6557 6544 BTF_ID_FLAGS(func, scx_bpf_task_cpu, KF_RCU) 6558 6545 BTF_ID_FLAGS(func, scx_bpf_cpu_rq) 6559 6546 BTF_ID_FLAGS(func, scx_bpf_locked_rq, KF_RET_NULL) 6547 + BTF_ID_FLAGS(func, scx_bpf_cpu_curr, KF_RET_NULL | KF_RCU) 6560 6548 #ifdef CONFIG_CGROUP_SCHED 6561 6549 BTF_ID_FLAGS(func, scx_bpf_task_cgroup, KF_RCU | KF_ACQUIRE) 6562 6550 #endif
+1
tools/sched_ext/include/scx/common.bpf.h
··· 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 106 struct rq *scx_bpf_locked_rq(void) __ksym; 107 + struct task_struct *scx_bpf_cpu_curr(s32 cpu) __ksym; 107 108 struct cgroup *scx_bpf_task_cgroup(struct task_struct *p) __ksym __weak; 108 109 u64 scx_bpf_now(void) __ksym __weak; 109 110 void scx_bpf_events(struct scx_event_stats *events, size_t events__sz) __ksym __weak;