scx_bpf_pick_any_cpu(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… scx_bpf_pick_any_cpu β€” from the Kernel API Manual, bestie ✨

Okay so picture this: it's a scx_bpf_pick_any_cpu(9) kind of day, the manual name is Kernel API Manual, and this function is literally the friend who's like "I'll find us a seat, don't even worry." Obsessed. Let's get into it 🫢


🌸 NAME 🌸

scx_bpf_pick_any_cpu β€” picks and claims an idle CPU if there's one available, or just picks any CPU. No cap, that's the whole vibe check πŸ’–


✨ SYNOPSIS ✨

__bpf_kfunc s32 scx_bpf_pick_any_cpu (const struct cpumask *cpus_allowed
, u64 flags , const struct bpf_prog_aux *aux );

πŸŽ€ ARGUMENTS πŸŽ€

  • cpus_allowed β€” the allowed cpumask, aka the guest list for this CPU party πŸ’Œ
  • flags β€” the SCX_PICK_IDLE_* flags. Cute little modifiers, iykyk.
  • aux β€” the implicit BPF argument that gives you access to bpf_prog_aux, which is hidden from BPF progs. Lowkey a backstage pass 🎟️

πŸ¦‹ DESCRIPTION πŸ¦‹

So here's the tea: this function picks and claims an idle CPU inside cpus_allowed. And if none of them is available? It just picks any CPU in there anyway. It's guaranteed to succeed, and it returns the picked idle CPU number as long as cpus_allowed isn't empty. Slay ✨

If cpus_allowed is empty, you get -EBUSY back instead. Not the vibe, but that's the deal 😭

Heads up bestie: if ops.update_idle is implemented and SCX_OPS_KEEP_BUILTIN_IDLE is not set, this function literally can't tell which CPUs are idle, so it will always just pick any CPU. It's giving "no thoughts, head empty" πŸ’€
Also important: if SCX_OPS_BUILTIN_IDLE_PER_NODE is set, this function always returns an error, no exceptions. In that case use scx_bpf_pick_any_cpu_node instead, periodt.

🌈 SEE ALSO 🌈

The Kernel file ./kernel/sched/ext/idle.c is where the magic lives, and honestly the whole friend group is iconic:


Okay that's the whole page, mwah πŸ’‹ This one came straight outta ./kernel/sched/ext, dated October 2026 β€” go off, king πŸ‘‘πŸ¦‹πŸ’œ

πŸ“¦ where this page comes from