1 /* SPDX-License-Identifier: GPL-2.0 */
3 /* Stage 5 definitions for creating trace events */
6 * remember the offset of each array from the beginning of the event.
12 #ifndef __STAGE5_STRING_SRC_H
13 #define __STAGE5_STRING_SRC_H
14 static inline const char *__string_src(const char *str)
17 return EVENT_NULL_STR;
20 #endif /* __STAGE5_STRING_SRC_H */
23 * Fields should never declare an array: i.e. __field(int, arr[5])
24 * If they do, it will cause issues in parsing and possibly corrupt the
25 * events. To prevent that from happening, test the sizeof() a fictitious
26 * type called "struct _test_no_array_##item" which will fail if "item"
27 * contains array elements (like "arr[5]").
29 * If you hit this, use __array(int, arr, 5) instead.
32 #define __field(type, item) \
33 { (void)sizeof(struct _test_no_array_##item *); }
36 #define __field_ext(type, item, filter_type) \
37 { (void)sizeof(struct _test_no_array_##item *); }
40 #define __field_struct(type, item) \
41 { (void)sizeof(struct _test_no_array_##item *); }
43 #undef __field_struct_ext
44 #define __field_struct_ext(type, item, filter_type) \
45 { (void)sizeof(struct _test_no_array_##item *); }
48 #define __array(type, item, len)
50 #undef __dynamic_array
51 #define __dynamic_array(type, item, len) \
52 __item_length = (len) * sizeof(type); \
53 __data_offsets->item = __data_size + \
54 offsetof(typeof(*entry), __data); \
55 __data_offsets->item |= __item_length << 16; \
56 __data_size += __item_length;
59 #define __string(item, src) __dynamic_array(char, item, \
60 strlen(__string_src(src)) + 1) \
61 __data_offsets->item##_ptr_ = src;
64 #define __string_len(item, src, len) __dynamic_array(char, item, (len) + 1)\
65 __data_offsets->item##_ptr_ = src;
68 #define __vstring(item, fmt, ap) __dynamic_array(char, item, \
69 __trace_event_vstr_len(fmt, ap))
71 #undef __rel_dynamic_array
72 #define __rel_dynamic_array(type, item, len) \
73 __item_length = (len) * sizeof(type); \
74 __data_offsets->item = __data_size + \
75 offsetof(typeof(*entry), __data) - \
76 offsetof(typeof(*entry), __rel_loc_##item) - \
78 __data_offsets->item |= __item_length << 16; \
79 __data_size += __item_length;
82 #define __rel_string(item, src) __rel_dynamic_array(char, item, \
83 strlen(__string_src(src)) + 1) \
84 __data_offsets->item##_ptr_ = src;
86 #undef __rel_string_len
87 #define __rel_string_len(item, src, len) __rel_dynamic_array(char, item, (len) + 1)\
88 __data_offsets->item##_ptr_ = src;
91 * __bitmask_size_in_bytes_raw is the number of bytes needed to hold
92 * num_possible_cpus().
94 #define __bitmask_size_in_bytes_raw(nr_bits) \
97 #define __bitmask_size_in_longs(nr_bits) \
98 ((__bitmask_size_in_bytes_raw(nr_bits) + \
99 ((BITS_PER_LONG / 8) - 1)) / (BITS_PER_LONG / 8))
102 * __bitmask_size_in_bytes is the number of bytes needed to hold
103 * num_possible_cpus() padded out to the nearest long. This is what
104 * is saved in the buffer, just to be consistent.
106 #define __bitmask_size_in_bytes(nr_bits) \
107 (__bitmask_size_in_longs(nr_bits) * (BITS_PER_LONG / 8))
110 #define __bitmask(item, nr_bits) __dynamic_array(unsigned long, item, \
111 __bitmask_size_in_longs(nr_bits))
114 #define __cpumask(item) __bitmask(item, nr_cpumask_bits)
117 #define __rel_bitmask(item, nr_bits) __rel_dynamic_array(unsigned long, item, \
118 __bitmask_size_in_longs(nr_bits))
121 #define __rel_cpumask(item) __rel_bitmask(item, nr_cpumask_bits)
124 #define __sockaddr(field, len) __dynamic_array(u8, field, len)
126 #undef __rel_sockaddr
127 #define __rel_sockaddr(field, len) __rel_dynamic_array(u8, field, len)