scx_bpf_pick_idle_cpu(9)
π scx_bpf_pick_idle_cpu β Kernel API Manual β¨
okay bestie, welcome to the Kernel API Manual page for scx_bpf_pick_idle_cpu(9) π this one's short and sweet but there's some real lore in the warnings, so stay with me π«Ά
β¨ NAME β¨
scx_bpf_pick_idle_cpu β pick and claim an idle cpu π literally it goes shopping for a free CPU and takes it home, no cap
π¦ SYNOPSIS π¦
__bpf_kfunc s32 scx_bpf_pick_idle_cpu (const struct cpumask
*cpus_allowed , u64 flags , const struct bpf_prog_aux *aux );
πΈ ARGUMENTS πΈ
cpus_allowedβ the allowed cpumask, i.e. your little menu of CPUs it's allowed to pick from πflagsβSCX_PICK_IDLE_*flags, the vibe modifiers β¨auxβ this one's the implicit BPF argument giving access tobpf_prog_aux, and ngl it's hidden from BPF progs π so you don't really touch it, she's just there
π DESCRIPTION π
So the whole gig: it picks and claims an idle cpu inside cpus_allowed. On success you get the picked idle cpu number back, slay π and if no matching cpu was found you get -EBUSY π that's it, that's the return contract.
β οΈ ok now the important part, do NOT skip this π Idle CPU tracking may race against CPU scheduling state transitions. Like, this function may totally return-EBUSYjust because CPUs are in the middle of transitioning into the idle state. And if the caller then assumes there will be dispatch events on those CPUs because they were all busy β the scheduler may end up stalling with CPUs idling while there are pending tasks π± so to guarantee there will be at least one dispatch event in the near future, usescx_bpf_pick_any_cpuandscx_bpf_kick_cpuπ₯ fr fr, that's the move.
More things to know, bestie:
- It's unavailable if
ops.update_idleis implemented andSCX_OPS_KEEP_BUILTIN_IDLEis not set π« - It always returns an error if
SCX_OPS_BUILTIN_IDLE_PER_NODEis set β in that case usescx_bpf_pick_idle_cpu_nodeinstead π§ periodt
π SEE ALSO π
Kernel file ./kernel/sched/ext/idle.c β and the whole friend group π:
scx_bpf_cpu_node(9)scx_bpf_select_cpu_dfl(9)__scx_bpf_select_cpu_and(9)scx_bpf_get_idle_cpumask_node(9)scx_bpf_get_idle_cpumask(9)scx_bpf_get_idle_smtmask_node(9)scx_bpf_get_idle_smtmask(9)scx_bpf_put_idle_cpumask(9)scx_bpf_test_and_clear_cpu_idle(9)scx_bpf_pick_idle_cpu_node(9)scx_bpf_pick_any_cpu_node(9)scx_bpf_pick_any_cpu(9)
π that's the whole page angel, go pick some idle CPUs responsibly π
mwah π this one comes from ./kernel/sched/ext, dated October 2026, and yeah it's the scx_bpf_pick_idle_cpu(9) page β see you in the next one bestie π«Άβ¨
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms