From 0cd5c16bcc7c46ec82a8e1bc6c5ed53039c6da97 Mon Sep 17 00:00:00 2001 From: David Vernet Date: Thu, 4 Apr 2024 14:43:27 -0500 Subject: [PATCH 1/3] scx: Add a few missing config options from selftests Let's include some options necessary for BTF Signed-off-by: David Vernet --- tools/testing/selftests/sched_ext/config | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tools/testing/selftests/sched_ext/config b/tools/testing/selftests/sched_ext/config index fef8f81ad3776..0de9b4ee249d3 100644 --- a/tools/testing/selftests/sched_ext/config +++ b/tools/testing/selftests/sched_ext/config @@ -3,3 +3,7 @@ CONFIG_SCHED_CLASS_EXT=y CONFIG_CGROUPS=y CONFIG_CGROUP_SCHED=y CONFIG_EXT_GROUP_SCHED=y +CONFIG_BPF=y +CONFIG_BPF_SYSCALL=y +CONFIG_DEBUG_INFO=y +CONFIG_DEBUG_INFO_BTF=y From e138c7c51b604b72a7b4f326eb49fb2872e40790 Mon Sep 17 00:00:00 2001 From: David Vernet Date: Thu, 4 Apr 2024 14:57:02 -0500 Subject: [PATCH 2/3] scx: Update minimal testcase to be completely minimal Now that libbpf has been fixed to accommodate a struct_ops map with no struct_ops progs, let's update the minimal testcase to not have any struct_ops progs. Signed-off-by: David Vernet --- tools/testing/selftests/sched_ext/minimal.bpf.c | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/tools/testing/selftests/sched_ext/minimal.bpf.c b/tools/testing/selftests/sched_ext/minimal.bpf.c index 14b3d44d90db5..6a7eccef01045 100644 --- a/tools/testing/selftests/sched_ext/minimal.bpf.c +++ b/tools/testing/selftests/sched_ext/minimal.bpf.c @@ -3,9 +3,8 @@ * A completely minimal scheduler. * * This scheduler defines the absolute minimal set of struct sched_ext_ops - * fields: its name (and until a bug is fixed in libbpf, also an ops.running() - * callback). It should _not_ fail to be loaded, and can be used to exercise - * the default scheduling paths in ext.c. + * fields: its name. It should _not_ fail to be loaded, and can be used to + * exercise the default scheduling paths in ext.c. * * Copyright (c) 2023 Meta Platforms, Inc. and affiliates. * Copyright (c) 2023 David Vernet @@ -16,17 +15,7 @@ char _license[] SEC("license") = "GPL"; -void BPF_STRUCT_OPS(minimal_running, struct task_struct *p) -{} - SEC(".struct_ops.link") struct sched_ext_ops minimal_ops = { - /* - * It shouldn't be necessary to define this minimal_running op, but - * libbpf currently expects that a struct_ops map will always have at - * least one struct_ops prog when loading. Until that issue is fixed, - * let's also define a minimal prog so that we can load and test. - */ - .enable = minimal_running, .name = "minimal", }; From 635e5f8093ad93d1910f2c0e45b054b6f60135b0 Mon Sep 17 00:00:00 2001 From: David Vernet Date: Thu, 4 Apr 2024 16:02:15 -0500 Subject: [PATCH 3/3] scx: Use __COMPAT_ENUM_OR_ZERO for reading exit values Instead of hard-coding the enum values, let's use libbpf to read them. Also fix a bug in prog_run. Signed-off-by: David Vernet --- .../selftests/sched_ext/ddsp_bogus_dsq_fail.c | 2 +- .../selftests/sched_ext/ddsp_vtimelocal_fail.c | 2 +- tools/testing/selftests/sched_ext/exit.c | 4 ++-- tools/testing/selftests/sched_ext/prog_run.c | 6 +++--- tools/testing/selftests/sched_ext/scx_test.h | 15 ++------------- .../sched_ext/select_cpu_dispatch_bad_dsq.c | 2 +- .../sched_ext/select_cpu_dispatch_dbl_dsp.c | 2 +- 7 files changed, 11 insertions(+), 22 deletions(-) diff --git a/tools/testing/selftests/sched_ext/ddsp_bogus_dsq_fail.c b/tools/testing/selftests/sched_ext/ddsp_bogus_dsq_fail.c index 7893152c0d9e4..e65d22f23f3bc 100644 --- a/tools/testing/selftests/sched_ext/ddsp_bogus_dsq_fail.c +++ b/tools/testing/selftests/sched_ext/ddsp_bogus_dsq_fail.c @@ -32,7 +32,7 @@ static enum scx_test_status run(void *ctx) sleep(1); - SCX_EQ(skel->data->uei.kind, SCX_EXIT_ERROR); + SCX_EQ(skel->data->uei.kind, EXIT_KIND(SCX_EXIT_ERROR)); bpf_link__destroy(link); return SCX_TEST_PASS; diff --git a/tools/testing/selftests/sched_ext/ddsp_vtimelocal_fail.c b/tools/testing/selftests/sched_ext/ddsp_vtimelocal_fail.c index 00033990eef5c..abafee587cd60 100644 --- a/tools/testing/selftests/sched_ext/ddsp_vtimelocal_fail.c +++ b/tools/testing/selftests/sched_ext/ddsp_vtimelocal_fail.c @@ -31,7 +31,7 @@ static enum scx_test_status run(void *ctx) sleep(1); - SCX_EQ(skel->data->uei.kind, SCX_EXIT_ERROR); + SCX_EQ(skel->data->uei.kind, EXIT_KIND(SCX_EXIT_ERROR)); bpf_link__destroy(link); return SCX_TEST_PASS; diff --git a/tools/testing/selftests/sched_ext/exit.c b/tools/testing/selftests/sched_ext/exit.c index 730072ad0eb0d..31bcd06e21cd3 100644 --- a/tools/testing/selftests/sched_ext/exit.c +++ b/tools/testing/selftests/sched_ext/exit.c @@ -33,10 +33,10 @@ static enum scx_test_status run(void *ctx) } /* Assumes uei.kind is written last */ - while (skel->data->uei.kind == SCX_EXIT_NONE) + while (skel->data->uei.kind == EXIT_KIND(SCX_EXIT_NONE)) sched_yield(); - SCX_EQ(skel->data->uei.kind, SCX_EXIT_UNREG_BPF); + SCX_EQ(skel->data->uei.kind, EXIT_KIND(SCX_EXIT_UNREG_BPF)); SCX_EQ(skel->data->uei.exit_code, tc); sprintf(buf, "%d", tc); SCX_ASSERT(!strcmp(skel->data->uei.msg, buf)); diff --git a/tools/testing/selftests/sched_ext/prog_run.c b/tools/testing/selftests/sched_ext/prog_run.c index 9613762172891..aab20301582e1 100644 --- a/tools/testing/selftests/sched_ext/prog_run.c +++ b/tools/testing/selftests/sched_ext/prog_run.c @@ -46,14 +46,14 @@ static enum scx_test_status run(void *ctx) return SCX_TEST_FAIL; } - //err = bpf_prog_test_run_opts(prog_fd, &topts); + err = bpf_prog_test_run_opts(prog_fd, &topts); SCX_EQ(err, 0); /* Assumes uei.kind is written last */ - while (skel->data->uei.kind == SCX_EXIT_NONE) + while (skel->data->uei.kind == EXIT_KIND(SCX_EXIT_NONE)) sched_yield(); - SCX_EQ(skel->data->uei.kind, SCX_EXIT_UNREG_BPF); + SCX_EQ(skel->data->uei.kind, EXIT_KIND(SCX_EXIT_UNREG_BPF)); SCX_EQ(skel->data->uei.exit_code, 0xdeadbeef); close(prog_fd); bpf_link__destroy(link); diff --git a/tools/testing/selftests/sched_ext/scx_test.h b/tools/testing/selftests/sched_ext/scx_test.h index 849ff241b5566..b9acda2d1666b 100644 --- a/tools/testing/selftests/sched_ext/scx_test.h +++ b/tools/testing/selftests/sched_ext/scx_test.h @@ -10,6 +10,7 @@ #include #include +#include enum scx_test_status { SCX_TEST_PASS = 0, @@ -17,19 +18,7 @@ enum scx_test_status { SCX_TEST_FAIL, }; -/* Copied from include/linux/sched/ext.h */ -enum scx_test_exit_kind { - SCX_EXIT_NONE, - SCX_EXIT_DONE, - - SCX_EXIT_UNREG = 64, /* User-space initiated unregistration */ - SCX_EXIT_UNREG_BPF, /* BPF-initiated unregistration */ - SCX_EXIT_SYSRQ, /* requested by 'S' sysrq */ - - SCX_EXIT_ERROR = 1024, /* runtime error, error msg contains details */ - SCX_EXIT_ERROR_BPF, /* ERROR but triggered through scx_bpf_error() */ - SCX_EXIT_ERROR_STALL, /* watchdog detected stalled runnable tasks */ -}; +#define EXIT_KIND(__ent) __COMPAT_ENUM_OR_ZERO("scx_exit_kind", #__ent) struct scx_test { /** diff --git a/tools/testing/selftests/sched_ext/select_cpu_dispatch_bad_dsq.c b/tools/testing/selftests/sched_ext/select_cpu_dispatch_bad_dsq.c index 4e3a575c3e32e..47eb6ed7627d9 100644 --- a/tools/testing/selftests/sched_ext/select_cpu_dispatch_bad_dsq.c +++ b/tools/testing/selftests/sched_ext/select_cpu_dispatch_bad_dsq.c @@ -32,7 +32,7 @@ static enum scx_test_status run(void *ctx) sleep(1); - SCX_EQ(skel->data->uei.kind, SCX_EXIT_ERROR); + SCX_EQ(skel->data->uei.kind, EXIT_KIND(SCX_EXIT_ERROR)); bpf_link__destroy(link); return SCX_TEST_PASS; diff --git a/tools/testing/selftests/sched_ext/select_cpu_dispatch_dbl_dsp.c b/tools/testing/selftests/sched_ext/select_cpu_dispatch_dbl_dsp.c index 8259c314bff67..48ff028a3c46d 100644 --- a/tools/testing/selftests/sched_ext/select_cpu_dispatch_dbl_dsp.c +++ b/tools/testing/selftests/sched_ext/select_cpu_dispatch_dbl_dsp.c @@ -32,7 +32,7 @@ static enum scx_test_status run(void *ctx) sleep(1); - SCX_EQ(skel->data->uei.kind, SCX_EXIT_ERROR); + SCX_EQ(skel->data->uei.kind, EXIT_KIND(SCX_EXIT_ERROR)); bpf_link__destroy(link); return SCX_TEST_PASS;