1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Copyright (c) 2023 Meta Platforms, Inc. and affiliates.
7 #ifndef __SCHED_EXT_COMMON_H
8 #define __SCHED_EXT_COMMON_H
11 #error "Should not be included by BPF programs"
29 #define SCX_BUG(__fmt, ...) \
31 fprintf(stderr, "[SCX_BUG] %s:%d", __FILE__, __LINE__); \
33 fprintf(stderr, " (%s)\n", strerror(errno)); \
35 fprintf(stderr, "\n"); \
36 fprintf(stderr, __fmt __VA_OPT__(,) __VA_ARGS__); \
37 fprintf(stderr, "\n"); \
42 #define SCX_BUG_ON(__cond, __fmt, ...) \
45 SCX_BUG((__fmt) __VA_OPT__(,) __VA_ARGS__); \
49 * RESIZE_ARRAY - Convenience macro for resizing a BPF array
50 * @__skel: the skeleton containing the array
51 * @elfsec: the data section of the BPF program in which the array exists
52 * @arr: the name of the array
53 * @n: the desired array element count
55 * For BPF arrays declared with RESIZABLE_ARRAY(), this macro performs two
56 * operations. It resizes the map which corresponds to the custom data
57 * section that contains the target array. As a side effect, the BTF info for
58 * the array is adjusted so that the array length is sized to cover the new
59 * data section size. The second operation is reassigning the skeleton pointer
60 * for that custom data section so that it points to the newly memory mapped
63 #define RESIZE_ARRAY(__skel, elfsec, arr, n) \
66 bpf_map__set_value_size((__skel)->maps.elfsec##_##arr, \
67 sizeof((__skel)->elfsec##_##arr->arr[0]) * (n)); \
68 (__skel)->elfsec##_##arr = \
69 bpf_map__initial_value((__skel)->maps.elfsec##_##arr, &__sz); \
72 #include "user_exit_info.h"
75 #endif /* __SCHED_EXT_COMMON_H */