Linux Audio

Check our new training course

Loading...
v5.4
  1/* SPDX-License-Identifier: GPL-2.0 */
  2
  3#undef TRACE_SYSTEM_VAR
  4
  5#ifdef CONFIG_BPF_EVENTS
  6
  7#undef __entry
  8#define __entry entry
  9
 10#undef __get_dynamic_array
 11#define __get_dynamic_array(field)	\
 12		((void *)__entry + (__entry->__data_loc_##field & 0xffff))
 13
 14#undef __get_dynamic_array_len
 15#define __get_dynamic_array_len(field)	\
 16		((__entry->__data_loc_##field >> 16) & 0xffff)
 17
 18#undef __get_str
 19#define __get_str(field) ((char *)__get_dynamic_array(field))
 20
 21#undef __get_bitmask
 22#define __get_bitmask(field) (char *)__get_dynamic_array(field)
 23
 24#undef __perf_count
 25#define __perf_count(c)	(c)
 26
 27#undef __perf_task
 28#define __perf_task(t)	(t)
 29
 
 
 30/* cast any integer, pointer, or small struct to u64 */
 31#define UINTTYPE(size) \
 32	__typeof__(__builtin_choose_expr(size == 1,  (u8)1, \
 33		   __builtin_choose_expr(size == 2, (u16)2, \
 34		   __builtin_choose_expr(size == 4, (u32)3, \
 35		   __builtin_choose_expr(size == 8, (u64)4, \
 36					 (void)5)))))
 37#define __CAST_TO_U64(x) ({ \
 38	typeof(x) __src = (x); \
 39	UINTTYPE(sizeof(x)) __dst; \
 40	memcpy(&__dst, &__src, sizeof(__dst)); \
 41	(u64)__dst; })
 42
 43#define __CAST1(a,...) __CAST_TO_U64(a)
 44#define __CAST2(a,...) __CAST_TO_U64(a), __CAST1(__VA_ARGS__)
 45#define __CAST3(a,...) __CAST_TO_U64(a), __CAST2(__VA_ARGS__)
 46#define __CAST4(a,...) __CAST_TO_U64(a), __CAST3(__VA_ARGS__)
 47#define __CAST5(a,...) __CAST_TO_U64(a), __CAST4(__VA_ARGS__)
 48#define __CAST6(a,...) __CAST_TO_U64(a), __CAST5(__VA_ARGS__)
 49#define __CAST7(a,...) __CAST_TO_U64(a), __CAST6(__VA_ARGS__)
 50#define __CAST8(a,...) __CAST_TO_U64(a), __CAST7(__VA_ARGS__)
 51#define __CAST9(a,...) __CAST_TO_U64(a), __CAST8(__VA_ARGS__)
 52#define __CAST10(a,...) __CAST_TO_U64(a), __CAST9(__VA_ARGS__)
 53#define __CAST11(a,...) __CAST_TO_U64(a), __CAST10(__VA_ARGS__)
 54#define __CAST12(a,...) __CAST_TO_U64(a), __CAST11(__VA_ARGS__)
 55/* tracepoints with more than 12 arguments will hit build error */
 56#define CAST_TO_U64(...) CONCATENATE(__CAST, COUNT_ARGS(__VA_ARGS__))(__VA_ARGS__)
 57
 58#undef DECLARE_EVENT_CLASS
 59#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print)	\
 60static notrace void							\
 61__bpf_trace_##call(void *__data, proto)					\
 62{									\
 63	struct bpf_prog *prog = __data;					\
 64	CONCATENATE(bpf_trace_run, COUNT_ARGS(args))(prog, CAST_TO_U64(args));	\
 65}
 66
 
 
 
 
 67/*
 68 * This part is compiled out, it is only here as a build time check
 69 * to make sure that if the tracepoint handling changes, the
 70 * bpf probe will fail to compile unless it too is updated.
 71 */
 72#define __DEFINE_EVENT(template, call, proto, args, size)		\
 73static inline void bpf_test_probe_##call(void)				\
 74{									\
 75	check_trace_callback_type_##call(__bpf_trace_##template);	\
 76}									\
 77static struct bpf_raw_event_map	__used					\
 78	__attribute__((section("__bpf_raw_tp_map")))			\
 79__bpf_trace_tp_map_##call = {						\
 80	.tp		= &__tracepoint_##call,				\
 81	.bpf_func	= (void *)__bpf_trace_##template,		\
 82	.num_args	= COUNT_ARGS(args),				\
 83	.writable_size	= size,						\
 
 
 
 
 
 84};
 85
 86#define FIRST(x, ...) x
 87
 88#undef DEFINE_EVENT_WRITABLE
 89#define DEFINE_EVENT_WRITABLE(template, call, proto, args, size)	\
 90static inline void bpf_test_buffer_##call(void)				\
 91{									\
 92	/* BUILD_BUG_ON() is ignored if the code is completely eliminated, but \
 93	 * BUILD_BUG_ON_ZERO() uses a different mechanism that is not	\
 94	 * dead-code-eliminated.					\
 95	 */								\
 96	FIRST(proto);							\
 97	(void)BUILD_BUG_ON_ZERO(size != sizeof(*FIRST(args)));		\
 98}									\
 99__DEFINE_EVENT(template, call, PARAMS(proto), PARAMS(args), size)
 
 
 
 
100
101#undef DEFINE_EVENT
102#define DEFINE_EVENT(template, call, proto, args)			\
103	__DEFINE_EVENT(template, call, PARAMS(proto), PARAMS(args), 0)
104
105#undef DEFINE_EVENT_PRINT
106#define DEFINE_EVENT_PRINT(template, name, proto, args, print)	\
107	DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
108
 
 
 
 
 
 
 
 
 
 
 
109#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
110
 
111#undef DEFINE_EVENT_WRITABLE
 
112#undef __DEFINE_EVENT
113#undef FIRST
114
115#endif /* CONFIG_BPF_EVENTS */
v6.9.4
  1/* SPDX-License-Identifier: GPL-2.0 */
  2
  3#undef TRACE_SYSTEM_VAR
  4
  5#ifdef CONFIG_BPF_EVENTS
  6
  7#include "stages/stage6_event_callback.h"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
  8
  9#undef __perf_count
 10#define __perf_count(c)	(c)
 11
 12#undef __perf_task
 13#define __perf_task(t)	(t)
 14
 15#include <linux/args.h>
 16
 17/* cast any integer, pointer, or small struct to u64 */
 18#define UINTTYPE(size) \
 19	__typeof__(__builtin_choose_expr(size == 1,  (u8)1, \
 20		   __builtin_choose_expr(size == 2, (u16)2, \
 21		   __builtin_choose_expr(size == 4, (u32)3, \
 22		   __builtin_choose_expr(size == 8, (u64)4, \
 23					 (void)5)))))
 24#define __CAST_TO_U64(x) ({ \
 25	typeof(x) __src = (x); \
 26	UINTTYPE(sizeof(x)) __dst; \
 27	memcpy(&__dst, &__src, sizeof(__dst)); \
 28	(u64)__dst; })
 29
 30#define __CAST1(a,...) __CAST_TO_U64(a)
 31#define __CAST2(a,...) __CAST_TO_U64(a), __CAST1(__VA_ARGS__)
 32#define __CAST3(a,...) __CAST_TO_U64(a), __CAST2(__VA_ARGS__)
 33#define __CAST4(a,...) __CAST_TO_U64(a), __CAST3(__VA_ARGS__)
 34#define __CAST5(a,...) __CAST_TO_U64(a), __CAST4(__VA_ARGS__)
 35#define __CAST6(a,...) __CAST_TO_U64(a), __CAST5(__VA_ARGS__)
 36#define __CAST7(a,...) __CAST_TO_U64(a), __CAST6(__VA_ARGS__)
 37#define __CAST8(a,...) __CAST_TO_U64(a), __CAST7(__VA_ARGS__)
 38#define __CAST9(a,...) __CAST_TO_U64(a), __CAST8(__VA_ARGS__)
 39#define __CAST10(a,...) __CAST_TO_U64(a), __CAST9(__VA_ARGS__)
 40#define __CAST11(a,...) __CAST_TO_U64(a), __CAST10(__VA_ARGS__)
 41#define __CAST12(a,...) __CAST_TO_U64(a), __CAST11(__VA_ARGS__)
 42/* tracepoints with more than 12 arguments will hit build error */
 43#define CAST_TO_U64(...) CONCATENATE(__CAST, COUNT_ARGS(__VA_ARGS__))(__VA_ARGS__)
 44
 45#define __BPF_DECLARE_TRACE(call, proto, args)				\
 
 46static notrace void							\
 47__bpf_trace_##call(void *__data, proto)					\
 48{									\
 49	struct bpf_prog *prog = __data;					\
 50	CONCATENATE(bpf_trace_run, COUNT_ARGS(args))(prog, CAST_TO_U64(args));	\
 51}
 52
 53#undef DECLARE_EVENT_CLASS
 54#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print)	\
 55	__BPF_DECLARE_TRACE(call, PARAMS(proto), PARAMS(args))
 56
 57/*
 58 * This part is compiled out, it is only here as a build time check
 59 * to make sure that if the tracepoint handling changes, the
 60 * bpf probe will fail to compile unless it too is updated.
 61 */
 62#define __DEFINE_EVENT(template, call, proto, args, size)		\
 63static inline void bpf_test_probe_##call(void)				\
 64{									\
 65	check_trace_callback_type_##call(__bpf_trace_##template);	\
 66}									\
 67typedef void (*btf_trace_##call)(void *__data, proto);			\
 68static union {								\
 69	struct bpf_raw_event_map event;					\
 70	btf_trace_##call handler;					\
 71} __bpf_trace_tp_map_##call __used					\
 72__section("__bpf_raw_tp_map") = {					\
 73	.event = {							\
 74		.tp		= &__tracepoint_##call,			\
 75		.bpf_func	= __bpf_trace_##template,		\
 76		.num_args	= COUNT_ARGS(args),			\
 77		.writable_size	= size,					\
 78	},								\
 79};
 80
 81#define FIRST(x, ...) x
 82
 83#define __CHECK_WRITABLE_BUF_SIZE(call, proto, args, size)		\
 
 84static inline void bpf_test_buffer_##call(void)				\
 85{									\
 86	/* BUILD_BUG_ON() is ignored if the code is completely eliminated, but \
 87	 * BUILD_BUG_ON_ZERO() uses a different mechanism that is not	\
 88	 * dead-code-eliminated.					\
 89	 */								\
 90	FIRST(proto);							\
 91	(void)BUILD_BUG_ON_ZERO(size != sizeof(*FIRST(args)));		\
 92}
 93
 94#undef DEFINE_EVENT_WRITABLE
 95#define DEFINE_EVENT_WRITABLE(template, call, proto, args, size) \
 96	__CHECK_WRITABLE_BUF_SIZE(call, PARAMS(proto), PARAMS(args), size) \
 97	__DEFINE_EVENT(template, call, PARAMS(proto), PARAMS(args), size)
 98
 99#undef DEFINE_EVENT
100#define DEFINE_EVENT(template, call, proto, args)			\
101	__DEFINE_EVENT(template, call, PARAMS(proto), PARAMS(args), 0)
102
103#undef DEFINE_EVENT_PRINT
104#define DEFINE_EVENT_PRINT(template, name, proto, args, print)	\
105	DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
106
107#undef DECLARE_TRACE
108#define DECLARE_TRACE(call, proto, args)				\
109	__BPF_DECLARE_TRACE(call, PARAMS(proto), PARAMS(args))		\
110	__DEFINE_EVENT(call, call, PARAMS(proto), PARAMS(args), 0)
111
112#undef DECLARE_TRACE_WRITABLE
113#define DECLARE_TRACE_WRITABLE(call, proto, args, size) \
114	__CHECK_WRITABLE_BUF_SIZE(call, PARAMS(proto), PARAMS(args), size) \
115	__BPF_DECLARE_TRACE(call, PARAMS(proto), PARAMS(args)) \
116	__DEFINE_EVENT(call, call, PARAMS(proto), PARAMS(args), size)
117
118#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
119
120#undef DECLARE_TRACE_WRITABLE
121#undef DEFINE_EVENT_WRITABLE
122#undef __CHECK_WRITABLE_BUF_SIZE
123#undef __DEFINE_EVENT
124#undef FIRST
125
126#endif /* CONFIG_BPF_EVENTS */