Skip to content

bpf.scx: compile minimal sched_ext schedulers - #81

Open
sneaky-potato wants to merge 5 commits into
masterfrom
feat/scx/struct_ops
Open

sneaky-potato wants to merge 5 commits into
masterfrom
feat/scx/struct_ops

Conversation

@sneaky-potato

Copy link
Copy Markdown
Member

Add bpf.scx.scheduler to compile a minimal scheduler with a name and init callback into a BPF struct_ops object. Read the scheduler layout from kernel BTF, emit the required sections and relocations, and add loader support to register the resulting scheduler. Document the API and its use.

Related to #15

sneaky-potato and others added 5 commits November 28, 2026 00:08
A struct_ops object attaches to no device: the kernel registers it as a
unit. The loader learns two verbs for it, beside the attach a program
takes. `scheduler` answers whether the object carries a struct_ops map,
which is how the CLI tells a scheduler from an xdp or tc program before
it loads one. `register` attaches each struct_ops map with
`bpf_map__attach_struct_ops` and pins its link as `<root>/<name>-link`,
the way `attach` pins a program's, so the link holds the scheduler once
the command has exited and `detach`, reading that `-link` pin, unregisters
it with no change of its own.

`load` stops pinning a struct_ops map: the pinned link holds the
registration, as libbpf's own struct_ops skeletons leave the map to it,
so pinning the map too would persist a second holder with nothing to open
it.

`bpf.scx`'s doc names the `lunatik run` path the CLI wires over this.

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
bpf.scx writes a sched_ext scheduler, which `lunatik run` registers with no
device, but the guide, written for device programs, says nothing of it. A
Schedulers section now does: the minimal scheduler, a name and an init callback
that returns 0; that it takes no device, so `lunatik run` takes no `--dev` and
one given a scheduler is refused; that the run registers its struct_ops and pins
the link that holds it, and the stop unregisters it; and that it compiles only
where the kernel's BTF carries `sched_ext_ops`, a kernel built with
CONFIG_SCHED_CLASS_EXT, 6.12 and later.

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant