Path: blob/master/tools/sched_ext/include/scx/user_exit_info.h
29271 views
/* SPDX-License-Identifier: GPL-2.0 */1/*2* Define struct user_exit_info which is shared between BPF and userspace parts3* to communicate exit status and other information.4*5* Copyright (c) 2022 Meta Platforms, Inc. and affiliates.6* Copyright (c) 2022 Tejun Heo <[email protected]>7* Copyright (c) 2022 David Vernet <[email protected]>8*/9#ifndef __USER_EXIT_INFO_H10#define __USER_EXIT_INFO_H1112#include <stdio.h>13#include <stdbool.h>1415#include "user_exit_info_common.h"1617/* no need to call the following explicitly if SCX_OPS_LOAD() is used */18#define UEI_SET_SIZE(__skel, __ops_name, __uei_name) ({ \19u32 __len = (__skel)->struct_ops.__ops_name->exit_dump_len ?: UEI_DUMP_DFL_LEN; \20(__skel)->rodata->__uei_name##_dump_len = __len; \21RESIZE_ARRAY((__skel), data, __uei_name##_dump, __len); \22})2324#define UEI_EXITED(__skel, __uei_name) ({ \25/* use __sync to force memory barrier */ \26__sync_val_compare_and_swap(&(__skel)->data->__uei_name.kind, -1, -1); \27})2829#define UEI_REPORT(__skel, __uei_name) ({ \30struct user_exit_info *__uei = &(__skel)->data->__uei_name; \31char *__uei_dump = (__skel)->data_##__uei_name##_dump->__uei_name##_dump; \32if (__uei_dump[0] != '\0') { \33fputs("\nDEBUG DUMP\n", stderr); \34fputs("================================================================================\n\n", stderr); \35fputs(__uei_dump, stderr); \36fputs("\n================================================================================\n\n", stderr); \37} \38fprintf(stderr, "EXIT: %s", __uei->reason); \39if (__uei->msg[0] != '\0') \40fprintf(stderr, " (%s)", __uei->msg); \41fputs("\n", stderr); \42__uei->exit_code; \43})4445/*46* We can't import vmlinux.h while compiling user C code. Let's duplicate47* scx_exit_code definition.48*/49enum scx_exit_code {50/* Reasons */51SCX_ECODE_RSN_HOTPLUG = 1LLU << 32,5253/* Actions */54SCX_ECODE_ACT_RESTART = 1LLU << 48,55};5657enum uei_ecode_mask {58UEI_ECODE_USER_MASK = ((1LLU << 32) - 1),59UEI_ECODE_SYS_RSN_MASK = ((1LLU << 16) - 1) << 32,60UEI_ECODE_SYS_ACT_MASK = ((1LLU << 16) - 1) << 48,61};6263/*64* These macro interpret the ecode returned from UEI_REPORT().65*/66#define UEI_ECODE_USER(__ecode) ((__ecode) & UEI_ECODE_USER_MASK)67#define UEI_ECODE_SYS_RSN(__ecode) ((__ecode) & UEI_ECODE_SYS_RSN_MASK)68#define UEI_ECODE_SYS_ACT(__ecode) ((__ecode) & UEI_ECODE_SYS_ACT_MASK)6970#define UEI_ECODE_RESTART(__ecode) (UEI_ECODE_SYS_ACT((__ecode)) == SCX_ECODE_ACT_RESTART)7172#endif /* __USER_EXIT_INFO_H */737475