__scx_bpf_select_cpu_and(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… NAME πŸ’…

__scx_bpf_select_cpu_and β€” arg-wrapped CPU selection, but make it cpumask 🎯 (and yes bestie, this is a section 9 entry from the Kernel API Manual, we're in kernel-land now)


✨ SYNOPSIS ✨

__bpf_kfunc s32 __scx_bpf_select_cpu_and (struct task_struct *p , const
struct cpumask *cpus_allowed , struct scx_bpf_select_cpu_and_args *args
, const struct bpf_prog_aux *aux );

okay so it's giving very long signature energy, but that's literally the whole point of this function, iykyk 🫢


πŸŽ€ ARGUMENTS πŸŽ€

  • p β€” the task_struct we're picking a CPU for. main character of the operation, honestly πŸ‘‘
  • cpus_allowed β€” a cpumask of the CPUs that are actually allowed. the guest list, if you will 🎟️
  • args β€” a struct holding the rest of the arguments, because we ran out of room (more on that below 😭):
    • args->prev_cpu β€” the CPU that p was on previously, i.e. where it's coming from
    • args->wake_flags β€” the SCX_WAKE_* flags
    • args->flags β€” the SCX_PICK_IDLE* flags
  • aux β€” the implicit BPF argument giving access to bpf_prog_aux, and it's hidden from BPF progs. you literally can't touch this one from your BPF program, it's for the kernel's eyes only πŸ™ˆ

πŸ’– DESCRIPTION πŸ’–

So here's the tea, bestie πŸ“: this is a wrapper kfunc that takes its arguments through a struct, and it does that for one extremely relatable reason β€” to work around BPF's 5 argument limit. like, five args, that's the whole budget, that's all BPF gives you πŸ’€

BPF programs should not call this directly. instead use scx_bpf_select_cpu_and, which is provided as an inline wrapper in common.bpf.h. that's your entry point, periodt ✨

You can call it from ops.select_cpu, from ops.enqueue, or from an unlocked context such as a BPF test_run call β€” but only as long as built-in CPU selection is enabled, which means either:

  • ops.update_idle is missing, or
  • SCX_OPS_KEEP_BUILTIN_IDLE is set
no built-in idle selection? then this vibe check fails, fr fr. make sure one of those two conditions holds πŸ™

Also super important matching situation: p, args->prev_cpu and args->wake_flags match ops.select_cpu. same crew, same semantics 🧚

🌸 What it gives back

It returns the selected idle CPU πŸ’« β€” and listen, that CPU gets automatically awakened upon returning from ops.select_cpu, and you can use it for direct dispatch. Or, if there's no idle CPU available, you get a negative value instead 😭 that's the "nobody's home" answer.


🌈 SEE ALSO 🌈

Kernel file ./kernel/sched/ext/idle.c, plus the whole friend group:


okay that's the whole page, slay πŸŽ€ this one lives in ./kernel/sched/ext and it's dated October 2026 β€” so yeah, it's a little time-traveling queen from the future, we stan a forward-thinking manpage πŸ‘‘πŸ’œ

πŸ“¦ where this page comes from