Skip to content

Commit 37316dd

Browse files
committed
scx: Auto-release example scheduler struct_ops on program exit
When a BPF scheduler user-space program exits, the struct_ops map that it attaches to to load the BPF program is not automatically detached. This can cause the map and progs to remain loaded, which in turn will cause future attempts to load a new scheduling program to fail. In commit 8d1608d ("libbpf: Create a bpf_link in bpf_map__attach_struct_ops()"), Kui-feng updated bpf_map__attach_struct_ops() to create an actual link for the struct_ops map, which in turn makes it automatically close the map when the owning program exits. This patch updates the example schedulers to leverage this by updating their sections to SEC(".struct_ops.link"). Signed-off-by: David Vernet <[email protected]>
1 parent f6b15c3 commit 37316dd

7 files changed

+7
-7
lines changed

tools/sched_ext/atropos/src/bpf/atropos.bpf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,7 @@ void BPF_STRUCT_OPS(atropos_exit, struct scx_exit_info *ei)
723723
exit_type = ei->type;
724724
}
725725

726-
SEC(".struct_ops")
726+
SEC(".struct_ops.link")
727727
struct sched_ext_ops atropos = {
728728
.select_cpu = (void *)atropos_select_cpu,
729729
.enqueue = (void *)atropos_enqueue,

tools/sched_ext/scx_example_central.bpf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ void BPF_STRUCT_OPS(central_exit, struct scx_exit_info *ei)
314314
uei_record(&uei, ei);
315315
}
316316

317-
SEC(".struct_ops")
317+
SEC(".struct_ops.link")
318318
struct sched_ext_ops central_ops = {
319319
/*
320320
* We are offloading all scheduling decisions to the central CPU and

tools/sched_ext/scx_example_flatcg.bpf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -853,7 +853,7 @@ void BPF_STRUCT_OPS(fcg_exit, struct scx_exit_info *ei)
853853
uei_record(&uei, ei);
854854
}
855855

856-
SEC(".struct_ops")
856+
SEC(".struct_ops.link")
857857
struct sched_ext_ops flatcg_ops = {
858858
.enqueue = (void *)fcg_enqueue,
859859
.dispatch = (void *)fcg_dispatch,

tools/sched_ext/scx_example_pair.bpf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ void BPF_STRUCT_OPS(pair_exit, struct scx_exit_info *ei)
613613
uei_record(&uei, ei);
614614
}
615615

616-
SEC(".struct_ops")
616+
SEC(".struct_ops.link")
617617
struct sched_ext_ops pair_ops = {
618618
.enqueue = (void *)pair_enqueue,
619619
.dispatch = (void *)pair_dispatch,

tools/sched_ext/scx_example_qmap.bpf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ void BPF_STRUCT_OPS(qmap_exit, struct scx_exit_info *ei)
384384
uei_record(&uei, ei);
385385
}
386386

387-
SEC(".struct_ops")
387+
SEC(".struct_ops.link")
388388
struct sched_ext_ops qmap_ops = {
389389
.select_cpu = (void *)qmap_select_cpu,
390390
.enqueue = (void *)qmap_enqueue,

tools/sched_ext/scx_example_simple.bpf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ void BPF_STRUCT_OPS(simple_exit, struct scx_exit_info *ei)
117117
uei_record(&uei, ei);
118118
}
119119

120-
SEC(".struct_ops")
120+
SEC(".struct_ops.link")
121121
struct sched_ext_ops simple_ops = {
122122
.enqueue = (void *)simple_enqueue,
123123
.running = (void *)simple_running,

tools/sched_ext/scx_example_userland.bpf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ void BPF_STRUCT_OPS(userland_exit, struct scx_exit_info *ei)
249249
uei_record(&uei, ei);
250250
}
251251

252-
SEC(".struct_ops")
252+
SEC(".struct_ops.link")
253253
struct sched_ext_ops userland_ops = {
254254
.select_cpu = (void *)userland_select_cpu,
255255
.enqueue = (void *)userland_enqueue,

0 commit comments

Comments
 (0)