Skip to main content

scx_rustsched_build/scx_rustsched/
kfuncs.rs

1// SPDX-License-Identifier: GPL-2.0-only
2// Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES.
3
4// The kfuncs the program calls, declared once for both sides: src/kfuncs.rs
5// includes this file to declare them to Rust, and the build includes it to
6// add their prototypes to the object's BTF and to export them to the
7// linker. Parameter types are the names both sides define, see each
8// kfuncs! macro. A #[weak] kfunc may be missing from the kernel, which
9// libbpf then resolves to zero. A #[sized] kfunc takes a trailing size
10// parameter on kernels that pass the structure's size. A #[safe] kfunc
11// takes no pointer, so no argument can make it touch memory it should
12// not, and Rust code calls it without `unsafe`.
13kfuncs! {
14    #[safe] fn scx_bpf_cid_to_cpu(cid: I32) -> I32;
15    fn scx_bpf_dsq_insert(task: TaskPtr, dsq_id: U64, slice: U64, enq_flags: U64);
16    fn bpf_arena_alloc_pages(map: VoidPtr, address: VoidPtr, count: U32, node: I32, flags: U64) -> VoidPtr;
17    fn bpf_cpumask_test_cpu(cpu: U32, mask: CpumaskPtr) -> Bool;
18    #[safe] fn scx_bpf_nr_online_cids() -> U32;
19    #[safe] fn scx_bpf_cid_curr(cid: I32) -> TaskPtr;
20    #[sized] fn scx_bpf_cid_topo(cid: I32, out: TopoPtr);
21    fn scx_bpf_task_cid(task: TaskPtr) -> I32;
22    #[safe] fn scx_bpf_dsq_nr_queued(dsq_id: U64) -> I32;
23    #[safe] fn scx_bpf_now() -> U64;
24    fn scx_bpf_task_set_slice(task: TaskPtr, slice: U64) -> Bool;
25    fn scx_bpf_task_running(task: TaskPtr) -> Bool;
26    #[safe] fn scx_bpf_kick_cid(cid: I32, flags: U64);
27    #[safe] fn scx_bpf_nr_cpu_ids() -> U32;
28    #[safe] fn scx_bpf_tid_to_task(tid: U64) -> TaskPtr;
29    fn bpf_task_acquire(task: TaskPtr) -> TaskPtr;
30    fn bpf_task_release(task: TaskPtr);
31    #[safe] fn scx_bpf_cidperf_set(cid: I32, perf: U32) -> I32;
32    #[safe] fn scx_bpf_this_cid() -> I32;
33    #[safe] fn scx_bpf_cpu_to_cid(cpu: I32) -> I32;
34    fn scx_bpf_task_set_dsq_vtime(task: TaskPtr, vtime: U64) -> Bool;
35    fn scx_bpf_task_cgroup(task: TaskPtr) -> CgroupPtr;
36    fn bpf_cgroup_ancestor(cgroup: CgroupPtr, level: I32) -> CgroupPtr;
37    fn bpf_cgroup_release(cgroup: CgroupPtr);
38    fn bpf_cgroup_from_id(id: U64) -> CgroupPtr;
39    fn bpf_arena_free_pages(map: VoidPtr, address: VoidPtr, count: U32);
40    fn scx_bpf_dump_bstr(fmt: BytePtr, data: U64Ptr, data__sz: U32);
41    #[weak] #[safe] fn scx_bpf_cid_node(cid: I32) -> I32;
42    #[weak] fn scx_bpf_cgroup_nr_cpus(cgroup: CgroupPtr) -> U32;
43}