SCX eBPF macro BPF_STRUCT_OPS
The BPF_STRUCT_OPS
macro makes it easier to define sleepable struct ops programs correctly.
Definition
Usage
This macro can be used to shorted the definition of a sleepable struct ops programs. It places the program in an ELF section starting with struct_ops.s/
and names the program with the given name, this signals the loader of the program type. It also unpacks the program context into the arguments specified via args
. See BPF_PROG
for details.
Example
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2024 Meta Platforms, Inc. and affiliates.
* Copyright (c) 2024 David Vernet <dvernet@meta.com>
*/
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);
}