KFunc scx_bpf_cpu_curr
Return remote CPU's current task
Definition
Callers must hold RCU read lock (KF_RCU).
Parameters
cpu: CPU of interest
Returns
The remote CPU's current task
Signature
struct task_struct *scx_bpf_cpu_curr(s32 cpu)
Note
The pointer returned by the kfunc may be NULL. Hence, it forces the user to do a NULL check on the pointer returned from the kfunc before making use of it (dereferencing or passing to another helper).
Note
This kfunc is RCU protected. This means that the kfunc can be called from RCU read-side critical section.
If a program isn't called from RCU read-side critical section, such as sleepable programs, the
bpf_rcu_read_lock and
bpf_rcu_read_unlock to protect the calls to such KFuncs.
Usage
scx_bpf_cpu_curr Provides a way for scx schedulers to check the current task of a remote run queue without assuming its lock is held.
Before its introduction, many scx schedulers make use of scx_bpf_cpu_rq to check a remote current cpu (for example to see if it should be preempted). This is problematic because scx_bpf_cpu_rq provides access to all fields of struct run queue, most of which aren't safe to use without holding the associated run queue lock.
Program types
The following program types can make use of this kfunc:
Example
Docs could be improved
This part of the docs is incomplete, contributions are very welcome