Skip to content

SCX eBPF macro scx_bpf_exit

v6.12

The scx_bpf_exit macro wraps the scx_bpf_exit_bstr kfunc with variadic arguments instead of an array of u64. Using this macro will cause the scheduler to exit cleanly with the specified exit code being passed to user space.

Definition

#define scx_bpf_exit(code, fmt, args...)                            \
({                                                                  \
    scx_bpf_bstr_preamble(fmt, args)                                \
    scx_bpf_exit_bstr(code, ___fmt, ___param, sizeof(___param));    \
    ___scx_bpf_bstr_format_checker(fmt, ##args);                    \
})

Usage

This macro can be used in an error path of the BPF scheduler that you expect to be hit under normal circumstances.

Example

/* SPDX-License-Identifier: GPL-2.0 */
/*
 * Create and destroy DSQs in a loop.
 *
 * Copyright (c) 2024 Meta Platforms, Inc. and affiliates.
 * Copyright (c) 2024 David Vernet <dvernet@meta.com>
 */

s32 BPF_STRUCT_OPS_SLEEPABLE(create_dsq_init_task, struct task_struct *p,
                 struct scx_init_task_args *args)
{
    s32 err;

    err = scx_bpf_create_dsq(p->pid, -1);
    if (err)
        scx_bpf_error("Failed to create DSQ for %s[%d]",
                  p->comm, p->pid);

    return err;
}