Skip to content

Commit 0fdef1d

Browse files
committed
Update sched_ext_simple to current sched_ext kfunc ABI
Signed-off-by: Cong Wang <cwang@multikernel.io>
1 parent 271a8bb commit 0fdef1d

1 file changed

Lines changed: 22 additions & 22 deletions

File tree

examples/sched_ext_simple.ks

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@
33

44
include "sched_ext_ops.kh"
55

6-
// kfuncs declarations (extracted from BTF)
7-
extern scx_bpf_select_cpu_dfl(p: *u8, prev_cpu: i32, wake_flags: u64, direct: *bool) -> i32
8-
extern scx_bpf_dsq_insert(p: *u8, dsq_id: u64, slice: u64, enq_flags: u64) -> void
9-
extern scx_bpf_consume(dsq_id: u64, cpu: i32, flags: u64) -> i32
6+
// kfuncs declarations (signatures match the kernel BTF for sched_ext)
7+
extern scx_bpf_select_cpu_dfl(p: *task_struct, prev_cpu: i32, wake_flags: u64, is_idle: *bool) -> i32
8+
extern scx_bpf_dsq_insert(p: *task_struct, dsq_id: u64, slice: u64, enq_flags: u64) -> void
9+
extern scx_bpf_dsq_move_to_local(dsq_id: u64) -> bool
1010

1111
// Simple FIFO scheduler implementation
1212
@struct_ops("sched_ext_ops")
1313
impl simple_fifo_scheduler {
1414

1515
// Select CPU for a waking task
16-
fn select_cpu(p: *u8, prev_cpu: i32, wake_flags: u64) -> i32 {
16+
fn select_cpu(p: *task_struct, prev_cpu: i32, wake_flags: u64) -> i32 {
1717
// Use default CPU selection with direct dispatch if idle core found
1818
var direct: bool = false
1919
var cpu = scx_bpf_select_cpu_dfl(p, prev_cpu, wake_flags, &direct)
@@ -27,56 +27,56 @@ impl simple_fifo_scheduler {
2727
}
2828

2929
// Enqueue task into global FIFO queue
30-
fn enqueue(p: *u8, enq_flags: u64) -> void {
30+
fn enqueue(p: *task_struct, enq_flags: u64) -> void {
3131
// Simple FIFO: insert all tasks into global DSQ
3232
scx_bpf_dsq_insert(p, SCX_DSQ_GLOBAL, SCX_SLICE_DFL, enq_flags)
3333
}
3434

3535
// Dispatch tasks from global queue to local CPU
36-
fn dispatch(cpu: i32, prev: *u8) -> void {
37-
// Try to consume a task from the global DSQ
38-
if (scx_bpf_consume(SCX_DSQ_GLOBAL, cpu, 0) == 0) {
36+
fn dispatch(cpu: i32, prev: *task_struct) -> void {
37+
// Try to move a task from the global DSQ to this CPU's local DSQ
38+
if (!scx_bpf_dsq_move_to_local(SCX_DSQ_GLOBAL)) {
3939
// No tasks available, CPU will go idle
4040
}
4141
}
4242

4343
// Task becomes runnable
44-
fn runnable(p: *u8, enq_flags: u64) -> void {
44+
fn runnable(p: *task_struct, enq_flags: u64) -> void {
4545
// Optional: track runnable tasks
4646
// For simple FIFO, we don't need special handling
4747
}
48-
48+
4949
// Task starts running
50-
fn running(p: *u8) -> void {
50+
fn running(p: *task_struct) -> void {
5151
// Optional: track running tasks
5252
// For simple FIFO, we don't need special handling
5353
}
54-
54+
5555
// Task stops running
56-
fn stopping(p: *u8, runnable: bool) -> void {
56+
fn stopping(p: *task_struct, runnable: bool) -> void {
5757
// Optional: handle task stopping
5858
// For simple FIFO, we don't need special handling
5959
}
60-
60+
6161
// Task becomes quiescent
62-
fn quiescent(p: *u8, deq_flags: u64) -> void {
62+
fn quiescent(p: *task_struct, deq_flags: u64) -> void {
6363
// Optional: handle quiescent tasks
6464
// For simple FIFO, we don't need special handling
6565
}
66-
66+
6767
// Initialize new task
68-
fn init_task(p: *u8, args: *u8) -> i32 {
68+
fn init_task(p: *task_struct, args: *u8) -> i32 {
6969
// Return 0 for success
7070
return 0
7171
}
72-
72+
7373
// Clean up exiting task
74-
fn exit_task(p: *u8, args: *u8) -> void {
74+
fn exit_task(p: *task_struct, args: *u8) -> void {
7575
// Optional cleanup for exiting tasks
7676
}
77-
77+
7878
// Enable scheduler
79-
fn enable(p: *u8) -> void {
79+
fn enable(p: *task_struct) -> void {
8080
// Optional: scheduler enable logic
8181
}
8282

0 commit comments

Comments
 (0)