diff options
| author | David Vernet <dvernet@meta.com> | 2024-06-18 10:09:21 -1000 |
|---|---|---|
| committer | Tejun Heo <tj@kernel.org> | 2024-06-18 10:09:21 -1000 |
| commit | a5db7817af780db6a7f290c79677eff4fd13c5fa (patch) | |
| tree | bf8e0b59f0caf553044f0d0f9afe3cdb412f412e /tools/testing/selftests/sched_ext/hotplug.bpf.c | |
| parent | fa48e8d2c7b58d242c1db3a09c14f4274e055087 (diff) | |
| download | linux-next-a5db7817af780db6a7f290c79677eff4fd13c5fa.tar.gz linux-next-a5db7817af780db6a7f290c79677eff4fd13c5fa.zip | |
sched_ext: Add selftests
Add basic selftests.
Signed-off-by: David Vernet <dvernet@meta.com>
Acked-by: Tejun Heo <tj@kernel.org>
Diffstat (limited to 'tools/testing/selftests/sched_ext/hotplug.bpf.c')
| -rw-r--r-- | tools/testing/selftests/sched_ext/hotplug.bpf.c | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/tools/testing/selftests/sched_ext/hotplug.bpf.c b/tools/testing/selftests/sched_ext/hotplug.bpf.c new file mode 100644 index 000000000000..8f2601db39f3 --- /dev/null +++ b/tools/testing/selftests/sched_ext/hotplug.bpf.c @@ -0,0 +1,61 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (c) 2024 Meta Platforms, Inc. and affiliates. + * Copyright (c) 2024 David Vernet <dvernet@meta.com> + */ + +#include <scx/common.bpf.h> + +char _license[] SEC("license") = "GPL"; + +#include "hotplug_test.h" + +UEI_DEFINE(uei); + +void BPF_STRUCT_OPS(hotplug_exit, struct scx_exit_info *ei) +{ + UEI_RECORD(uei, ei); +} + +static void exit_from_hotplug(s32 cpu, bool onlining) +{ + /* + * Ignored, just used to verify that we can invoke blocking kfuncs + * from the hotplug path. + */ + scx_bpf_create_dsq(0, -1); + + s64 code = SCX_ECODE_ACT_RESTART | HOTPLUG_EXIT_RSN; + + if (onlining) + code |= HOTPLUG_ONLINING; + + scx_bpf_exit(code, "hotplug event detected (%d going %s)", cpu, + onlining ? "online" : "offline"); +} + +void BPF_STRUCT_OPS_SLEEPABLE(hotplug_cpu_online, s32 cpu) +{ + exit_from_hotplug(cpu, true); +} + +void BPF_STRUCT_OPS_SLEEPABLE(hotplug_cpu_offline, s32 cpu) +{ + exit_from_hotplug(cpu, false); +} + +SEC(".struct_ops.link") +struct sched_ext_ops hotplug_cb_ops = { + .cpu_online = hotplug_cpu_online, + .cpu_offline = hotplug_cpu_offline, + .exit = hotplug_exit, + .name = "hotplug_cbs", + .timeout_ms = 1000U, +}; + +SEC(".struct_ops.link") +struct sched_ext_ops hotplug_nocb_ops = { + .exit = hotplug_exit, + .name = "hotplug_nocbs", + .timeout_ms = 1000U, +}; |
