Remove unused tp_list_for_each_entry_rcu
[lttng-ust.git] / include / lttng / ust-tracepoint-event.h
CommitLineData
1c324e59 1/*
c0c0989a 2 * SPDX-License-Identifier: MIT
1c324e59 3 *
c0c0989a 4 * Copyright (C) 2011-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
1c324e59
MD
5 */
6
fb31eb73 7#include <stdint.h>
1c324e59 8#include <stdio.h>
7d381d6e 9#include <stdlib.h>
1c324e59 10#include <urcu/compiler.h>
f488575f 11#include <urcu/rculist.h>
1c324e59 12#include <lttng/ust-events.h>
0b4b8811 13#include <lttng/ust-ringbuffer-context.h>
2eba8e39 14#include <lttng/ust-arch.h>
a8909ba5 15#include <lttng/ust-compiler.h>
000b8662 16#include <lttng/tracepoint.h>
3208818b 17#include <lttng/ust-endian.h>
4849bc7a 18#include <lttng/ust-api-compat.h>
44c72f10 19#include <string.h>
1c324e59 20
ee0889a3 21#define LTTNG_UST__NULL_STRING "(null)"
24a39530 22
1c324e59 23/*
7f2f82c3 24 * LTTNG_UST_TRACEPOINT_EVENT_CLASS declares a class of tracepoints receiving the
1c324e59
MD
25 * same arguments and having the same field layout.
26 *
7f2f82c3 27 * LTTNG_UST_TRACEPOINT_EVENT_INSTANCE declares an instance of a tracepoint, with
1c324e59
MD
28 * its own provider and name. It refers to a class (template).
29 *
7f2f82c3 30 * LTTNG_UST_TRACEPOINT_EVENT declared both a class and an instance and does a
1c324e59
MD
31 * direct mapping from the instance to the class.
32 */
33
7f2f82c3
MJ
34#undef LTTNG_UST_TRACEPOINT_EVENT
35#define LTTNG_UST_TRACEPOINT_EVENT(_provider, _name, _args, _fields) \
36 LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, \
6eddcb06
MJ
37 LTTNG_UST__TP_PARAMS(_args), \
38 LTTNG_UST__TP_PARAMS(_fields)) \
7f2f82c3 39 LTTNG_UST__TRACEPOINT_EVENT_INSTANCE(_provider, _name, _name, \
6eddcb06 40 LTTNG_UST__TP_PARAMS(_args))
1c324e59 41
7f2f82c3
MJ
42#undef LTTNG_UST_TRACEPOINT_EVENT_CLASS
43#define LTTNG_UST_TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
6eddcb06 44 LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, LTTNG_UST__TP_PARAMS(_args), LTTNG_UST__TP_PARAMS(_fields))
f8021d08 45
7f2f82c3
MJ
46#undef LTTNG_UST_TRACEPOINT_EVENT_INSTANCE
47#define LTTNG_UST_TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
6eddcb06 48 LTTNG_UST__TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, LTTNG_UST__TP_PARAMS(_args))
f8021d08 49
1c324e59 50/* Helpers */
ca6ed78d 51#define LTTNG_UST__TP_ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
1c324e59 52
1210ca90 53#define lttng_ust__tp_max_t(type, x, y) \
1c324e59 54 ({ \
1210ca90
MJ
55 type lttng_ust__max1 = (x); \
56 type lttng_ust__max2 = (y); \
57 lttng_ust__max1 > lttng_ust__max2 ? lttng_ust__max1: lttng_ust__max2; \
1c324e59
MD
58 })
59
60/*
61 * Stage 0 of tracepoint event generation.
62 *
7f2f82c3 63 * Check that each LTTNG_UST_TRACEPOINT_EVENT provider argument match the
5b393d64 64 * LTTNG_UST_TRACEPOINT_PROVIDER by creating dummy callbacks.
1c324e59
MD
65 */
66
7f2f82c3 67/* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
1c324e59
MD
68#include <lttng/ust-tracepoint-event-reset.h>
69
106ff4da 70static inline
5b393d64 71void LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust_tracepoint_provider_mismatch_, LTTNG_UST_TRACEPOINT_PROVIDER)(void)
106ff4da 72 lttng_ust_notrace;
1c324e59 73static inline
5b393d64 74void LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust_tracepoint_provider_mismatch_, LTTNG_UST_TRACEPOINT_PROVIDER)(void)
1c324e59
MD
75{
76}
77
7f2f82c3
MJ
78#undef LTTNG_UST__TRACEPOINT_EVENT_CLASS
79#define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
0274f7f2 80 lttng_ust_tracepoint_provider_mismatch_##_provider();
1c324e59 81
7f2f82c3
MJ
82#undef LTTNG_UST__TRACEPOINT_EVENT_INSTANCE
83#define LTTNG_UST__TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
0274f7f2 84 lttng_ust_tracepoint_provider_mismatch_##_provider();
1c324e59 85
106ff4da 86static inline
5b393d64 87void LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust_tracepoint_provider_check_, LTTNG_UST_TRACEPOINT_PROVIDER)(void)
106ff4da 88 lttng_ust_notrace;
e8bd1da7 89static inline
5b393d64 90void LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust_tracepoint_provider_check_, LTTNG_UST_TRACEPOINT_PROVIDER)(void)
1c324e59 91{
bb71a8ea 92#include LTTNG_UST_TRACEPOINT_INCLUDE
1c324e59
MD
93}
94
f56cd1d5
MD
95/*
96 * Stage 0.1 of tracepoint event generation.
97 *
7f2f82c3 98 * Check that each LTTNG_UST_TRACEPOINT_EVENT provider:name does not exceed the
f56cd1d5
MD
99 * tracepoint name length limit.
100 */
101
7f2f82c3 102/* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
f56cd1d5
MD
103#include <lttng/ust-tracepoint-event-reset.h>
104
7f2f82c3
MJ
105#undef LTTNG_UST__TRACEPOINT_EVENT_INSTANCE
106#define LTTNG_UST__TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
81b16412 107 lttng_ust_tracepoint_validate_name_len(_provider, _name);
f56cd1d5 108
bb71a8ea 109#include LTTNG_UST_TRACEPOINT_INCLUDE
f56cd1d5 110
c75c0422
MD
111/*
112 * Stage 0.2 of tracepoint event generation.
113 *
114 * Create dummy trace prototypes for each event class, and for each used
115 * template. This will allow checking whether the prototypes from the
116 * class and the instance using the class actually match.
117 */
118
7f2f82c3 119/* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
c75c0422
MD
120#include <lttng/ust-tracepoint-event-reset.h>
121
cadfcbfc
MJ
122#undef LTTNG_UST_TP_ARGS
123#define LTTNG_UST_TP_ARGS(...) __VA_ARGS__
c75c0422 124
7f2f82c3
MJ
125#undef LTTNG_UST__TRACEPOINT_EVENT_INSTANCE
126#define LTTNG_UST__TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
bfcc2759 127void lttng_ust__event_template_proto___##_provider##___##_template(LTTNG_UST__TP_ARGS_DATA_PROTO(_args));
c75c0422 128
7f2f82c3
MJ
129#undef LTTNG_UST__TRACEPOINT_EVENT_CLASS
130#define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
bfcc2759 131void lttng_ust__event_template_proto___##_provider##___##_name(LTTNG_UST__TP_ARGS_DATA_PROTO(_args));
c75c0422 132
bb71a8ea 133#include LTTNG_UST_TRACEPOINT_INCLUDE
c75c0422 134
c785c634
MD
135/*
136 * Stage 0.9 of tracepoint event generation
137 *
138 * Unfolding the enums
139 */
140#include <lttng/ust-tracepoint-event-reset.h>
141
142/* Enumeration entry (single value) */
78684808
MJ
143#undef lttng_ust_field_enum_value
144#define lttng_ust_field_enum_value(_string, _value) \
5defa774 145 LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_enum_entry, { \
891d6b55 146 .struct_size = sizeof(struct lttng_ust_enum_entry), \
a6f80644 147 .start = { \
eae3c729 148 .value = lttng_ust_is_signed_type(__typeof__(_value)) ? \
a6f80644 149 (long long) (_value) : (_value), \
eae3c729 150 .signedness = lttng_ust_is_signed_type(__typeof__(_value)), \
a6f80644
MD
151 }, \
152 .end = { \
eae3c729 153 .value = lttng_ust_is_signed_type(__typeof__(_value)) ? \
a6f80644 154 (long long) (_value) : (_value), \
eae3c729 155 .signedness = lttng_ust_is_signed_type(__typeof__(_value)), \
a6f80644
MD
156 }, \
157 .string = (_string), \
891d6b55 158 }),
c785c634
MD
159
160/* Enumeration entry (range) */
78684808
MJ
161#undef lttng_ust_field_enum_range
162#define lttng_ust_field_enum_range(_string, _range_start, _range_end) \
5defa774 163 LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_enum_entry, { \
891d6b55 164 .struct_size = sizeof(struct lttng_ust_enum_entry), \
a6f80644 165 .start = { \
eae3c729 166 .value = lttng_ust_is_signed_type(__typeof__(_range_start)) ? \
a6f80644 167 (long long) (_range_start) : (_range_start), \
eae3c729 168 .signedness = lttng_ust_is_signed_type(__typeof__(_range_start)), \
a6f80644
MD
169 }, \
170 .end = { \
eae3c729 171 .value = lttng_ust_is_signed_type(__typeof__(_range_end)) ? \
a6f80644 172 (long long) (_range_end) : (_range_end), \
eae3c729 173 .signedness = lttng_ust_is_signed_type(__typeof__(_range_end)), \
a6f80644
MD
174 }, \
175 .string = (_string), \
891d6b55 176 }),
c785c634 177
3e762260 178/* Enumeration entry (automatic value; follows the rules of CTF) */
78684808
MJ
179#undef lttng_ust_field_enum_auto
180#define lttng_ust_field_enum_auto(_string) \
5defa774 181 LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_enum_entry, { \
891d6b55 182 .struct_size = sizeof(struct lttng_ust_enum_entry), \
3e762260
PP
183 .start = { \
184 .value = -1ULL, \
185 .signedness = 0, \
186 }, \
187 .end = { \
188 .value = -1ULL, \
189 .signedness = 0, \
190 }, \
191 .string = (_string), \
1a37a873 192 .options = LTTNG_UST_ENUM_ENTRY_OPTION_IS_AUTO, \
891d6b55 193 }),
3e762260 194
4849bc7a
MJ
195#undef LTTNG_UST_TP_ENUM_VALUES
196#define LTTNG_UST_TP_ENUM_VALUES(...) \
c785c634
MD
197 __VA_ARGS__
198
4849bc7a
MJ
199#if LTTNG_UST_COMPAT_API(0)
200# undef TP_ENUM_VALUES
201# define TP_ENUM_VALUES LTTNG_UST_TP_ENUM_VALUES
202#endif /* #if LTTNG_UST_COMPAT_API(0) */
203
2ebf164b
MJ
204#undef LTTNG_UST_TRACEPOINT_ENUM
205#define LTTNG_UST_TRACEPOINT_ENUM(_provider, _name, _values) \
3d33ca1d 206 const struct lttng_ust_enum_entry * const __enum_values__##_provider##_##_name[] = { \
c785c634 207 _values \
78684808 208 lttng_ust_field_enum_value("", 0) /* Dummy, 0-len array forbidden by C99. */ \
c785c634 209 };
bb71a8ea 210#include LTTNG_UST_TRACEPOINT_INCLUDE
2df82195
FD
211
212/*
213 * Stage 0.9.1
214 * Verifying array and sequence elements are of an integer type.
215 */
216
7f2f82c3 217/* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
2df82195
FD
218#include <lttng/ust-tracepoint-event-reset.h>
219#include <lttng/ust-tracepoint-event-write.h>
220#include <lttng/ust-tracepoint-event-nowrite.h>
221
10937ee5
MJ
222#undef lttng_ust__field_array_encoded
223#define lttng_ust__field_array_encoded(_type, _item, _src, _byte_order, \
2df82195
FD
224 _length, _encoding, _nowrite, \
225 _elem_type_base) \
10937ee5 226 lttng_ust_field_array_element_type_is_supported(_type, _item);
2df82195 227
1d188af9
MJ
228#undef lttng_ust__field_sequence_encoded
229#define lttng_ust__field_sequence_encoded(_type, _item, _src, _byte_order, \
2df82195
FD
230 _length_type, _src_length, _encoding, _nowrite, \
231 _elem_type_base) \
10937ee5 232 lttng_ust_field_array_element_type_is_supported(_type, _item);
2df82195 233
efa14d16
MJ
234#undef LTTNG_UST_TP_FIELDS
235#define LTTNG_UST_TP_FIELDS(...) __VA_ARGS__ /* Only one used in this phase */
2df82195 236
7f2f82c3
MJ
237#undef LTTNG_UST__TRACEPOINT_EVENT_CLASS
238#define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
2df82195 239 _fields
c785c634 240
bb71a8ea 241#include LTTNG_UST_TRACEPOINT_INCLUDE
c785c634 242
1c324e59
MD
243/*
244 * Stage 1 of tracepoint event generation.
245 *
246 * Create event field type metadata section.
247 * Each event produce an array of fields.
248 */
249
7f2f82c3 250/* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
1c324e59 251#include <lttng/ust-tracepoint-event-reset.h>
4774c8f3
MD
252#include <lttng/ust-tracepoint-event-write.h>
253#include <lttng/ust-tracepoint-event-nowrite.h>
1c324e59 254
b4064f28
MJ
255#undef lttng_ust__field_integer_ext
256#define lttng_ust__field_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
5defa774 257 LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, { \
25cff019
MD
258 .struct_size = sizeof(struct lttng_ust_event_field), \
259 .name = #_item, \
a084756d 260 .type = lttng_ust_type_integer_define(_type, _byte_order, _base), \
25cff019
MD
261 .nowrite = _nowrite, \
262 .nofilter = 0, \
263 }),
1c324e59 264
891226fc
MJ
265#undef lttng_ust__field_float
266#define lttng_ust__field_float(_type, _item, _src, _nowrite) \
5defa774 267 LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, { \
25cff019
MD
268 .struct_size = sizeof(struct lttng_ust_event_field), \
269 .name = #_item, \
a084756d 270 .type = lttng_ust_type_float_define(_type), \
25cff019
MD
271 .nowrite = _nowrite, \
272 .nofilter = 0, \
273 }),
1c324e59 274
10937ee5
MJ
275#undef lttng_ust__field_array_encoded
276#define lttng_ust__field_array_encoded(_type, _item, _src, _byte_order, \
f3ec4cb5
MD
277 _length, _encoding, _nowrite, \
278 _elem_type_base) \
5defa774 279 LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, { \
25cff019
MD
280 .struct_size = sizeof(struct lttng_ust_event_field), \
281 .name = #_item, \
5defa774 282 .type = (const struct lttng_ust_type_common *) LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_type_array, { \
a084756d
MD
283 .parent = { \
284 .type = lttng_ust_type_array, \
285 }, \
286 .struct_size = sizeof(struct lttng_ust_type_array), \
287 .elem_type = lttng_ust_type_integer_define(_type, _byte_order, _elem_type_base), \
288 .length = _length, \
289 .alignment = 0, \
290 .encoding = lttng_ust_string_encoding_##_encoding, \
291 }), \
25cff019
MD
292 .nowrite = _nowrite, \
293 .nofilter = 0, \
294 }),
1c324e59 295
1d188af9
MJ
296#undef lttng_ust__field_sequence_encoded
297#define lttng_ust__field_sequence_encoded(_type, _item, _src, _byte_order, \
f968510a
PP
298 _length_type, _src_length, _encoding, _nowrite, \
299 _elem_type_base) \
5defa774 300 LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, { \
25cff019
MD
301 .struct_size = sizeof(struct lttng_ust_event_field), \
302 .name = "_" #_item "_length", \
baa8acf3 303 .type = lttng_ust_type_integer_define(_length_type, LTTNG_UST_BYTE_ORDER, 10), \
25cff019
MD
304 .nowrite = _nowrite, \
305 .nofilter = 1, \
306 }), \
5defa774 307 LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, { \
25cff019
MD
308 .struct_size = sizeof(struct lttng_ust_event_field), \
309 .name = #_item, \
5defa774 310 .type = (const struct lttng_ust_type_common *) LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_type_sequence, { \
a084756d
MD
311 .parent = { \
312 .type = lttng_ust_type_sequence, \
1c324e59 313 }, \
a084756d
MD
314 .struct_size = sizeof(struct lttng_ust_type_sequence), \
315 .length_name = "_" #_item "_length", \
316 .elem_type = lttng_ust_type_integer_define(_type, _byte_order, _elem_type_base), \
317 .alignment = 0, \
318 .encoding = lttng_ust_string_encoding_##_encoding, \
319 }), \
25cff019
MD
320 .nowrite = _nowrite, \
321 .nofilter = 0, \
322 }),
1c324e59 323
3202f63a
MJ
324#undef lttng_ust__field_string
325#define lttng_ust__field_string(_item, _src, _nowrite) \
5defa774 326 LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, { \
25cff019
MD
327 .struct_size = sizeof(struct lttng_ust_event_field), \
328 .name = #_item, \
5defa774 329 .type = (const struct lttng_ust_type_common *) LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_type_string, { \
a084756d
MD
330 .parent = { \
331 .type = lttng_ust_type_string, \
46d52200 332 }, \
a084756d
MD
333 .struct_size = sizeof(struct lttng_ust_type_string), \
334 .encoding = lttng_ust_string_encoding_UTF8, \
335 }), \
25cff019
MD
336 .nowrite = _nowrite, \
337 .nofilter = 0, \
338 }),
1c324e59 339
ddde62ca
MJ
340#undef lttng_ust__field_unused
341#define lttng_ust__field_unused(_src)
5152f6df 342
78684808
MJ
343#undef lttng_ust__field_enum
344#define lttng_ust__field_enum(_provider, _name, _type, _item, _src, _nowrite) \
5defa774 345 LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, { \
25cff019 346 .struct_size = sizeof(struct lttng_ust_event_field), \
c785c634 347 .name = #_item, \
5defa774 348 .type = (const struct lttng_ust_type_common *) LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_type_enum, { \
a084756d
MD
349 .parent = { \
350 .type = lttng_ust_type_enum, \
c785c634 351 }, \
a084756d
MD
352 .struct_size = sizeof(struct lttng_ust_type_enum), \
353 .desc = &__enum_##_provider##_##_name, \
baa8acf3 354 .container_type = lttng_ust_type_integer_define(_type, LTTNG_UST_BYTE_ORDER, 10), \
a084756d 355 }), \
c785c634 356 .nowrite = _nowrite, \
25cff019
MD
357 .nofilter = 0, \
358 }),
c785c634 359
efa14d16
MJ
360#undef LTTNG_UST_TP_FIELDS
361#define LTTNG_UST_TP_FIELDS(...) __VA_ARGS__ /* Only one used in this phase */
1c324e59 362
7f2f82c3
MJ
363#undef LTTNG_UST__TRACEPOINT_EVENT_CLASS
364#define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
bfcc2759 365 static const struct lttng_ust_event_field * const lttng_ust__event_fields___##_provider##___##_name[] = { \
1c324e59 366 _fields \
b4064f28 367 lttng_ust_field_integer(int, dummy, 0) /* Dummy, C99 forbids 0-len array. */ \
1c324e59
MD
368 };
369
2ebf164b
MJ
370#undef LTTNG_UST_TRACEPOINT_ENUM
371#define LTTNG_UST_TRACEPOINT_ENUM(_provider, _name, _values) \
4e48b5d2 372 static const struct lttng_ust_enum_desc __enum_##_provider##_##_name = { \
a084756d 373 .struct_size = sizeof(struct lttng_ust_enum_desc), \
c785c634
MD
374 .name = #_provider "_" #_name, \
375 .entries = __enum_values__##_provider##_##_name, \
ca6ed78d 376 .nr_entries = LTTNG_UST__TP_ARRAY_SIZE(__enum_values__##_provider##_##_name) - 1, \
c785c634
MD
377 };
378
bb71a8ea 379#include LTTNG_UST_TRACEPOINT_INCLUDE
1c324e59
MD
380
381/*
382 * Stage 2 of tracepoint event generation.
383 *
384 * Create probe callback prototypes.
385 */
386
7f2f82c3 387/* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
1c324e59
MD
388#include <lttng/ust-tracepoint-event-reset.h>
389
cadfcbfc
MJ
390#undef LTTNG_UST_TP_ARGS
391#define LTTNG_UST_TP_ARGS(...) __VA_ARGS__
1c324e59 392
7f2f82c3
MJ
393#undef LTTNG_UST__TRACEPOINT_EVENT_CLASS
394#define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
bfcc2759 395static void lttng_ust__event_probe__##_provider##___##_name(LTTNG_UST__TP_ARGS_DATA_PROTO(_args));
1c324e59 396
bb71a8ea 397#include LTTNG_UST_TRACEPOINT_INCLUDE
1c324e59
MD
398
399/*
c785c634 400 * Stage 3.0 of tracepoint event generation.
1c324e59 401 *
1c324e59
MD
402 * Create static inline function that calculates event size.
403 */
404
7f2f82c3 405/* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
1c324e59 406#include <lttng/ust-tracepoint-event-reset.h>
4774c8f3 407#include <lttng/ust-tracepoint-event-write.h>
1c324e59 408
b4064f28
MJ
409#undef lttng_ust__field_integer_ext
410#define lttng_ust__field_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
5152f6df
MJ
411 if (0) \
412 (void) (_src); /* Unused */ \
b5457df5 413 __event_len += lttng_ust_ring_buffer_align(__event_len, lttng_ust_rb_alignof(_type)); \
1c324e59
MD
414 __event_len += sizeof(_type);
415
891226fc
MJ
416#undef lttng_ust__field_float
417#define lttng_ust__field_float(_type, _item, _src, _nowrite) \
5152f6df
MJ
418 if (0) \
419 (void) (_src); /* Unused */ \
b5457df5 420 __event_len += lttng_ust_ring_buffer_align(__event_len, lttng_ust_rb_alignof(_type)); \
1c324e59
MD
421 __event_len += sizeof(_type);
422
10937ee5
MJ
423#undef lttng_ust__field_array_encoded
424#define lttng_ust__field_array_encoded(_type, _item, _src, _byte_order, _length, _encoding, \
f3ec4cb5 425 _nowrite, _elem_type_base) \
5152f6df
MJ
426 if (0) \
427 (void) (_src); /* Unused */ \
b5457df5 428 __event_len += lttng_ust_ring_buffer_align(__event_len, lttng_ust_rb_alignof(_type)); \
1c324e59
MD
429 __event_len += sizeof(_type) * (_length);
430
1d188af9
MJ
431#undef lttng_ust__field_sequence_encoded
432#define lttng_ust__field_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
f968510a 433 _src_length, _encoding, _nowrite, _elem_type_base) \
5152f6df
MJ
434 if (0) \
435 (void) (_src); /* Unused */ \
b5457df5 436 __event_len += lttng_ust_ring_buffer_align(__event_len, lttng_ust_rb_alignof(_length_type)); \
1c324e59 437 __event_len += sizeof(_length_type); \
b5457df5 438 __event_len += lttng_ust_ring_buffer_align(__event_len, lttng_ust_rb_alignof(_type)); \
1c324e59
MD
439 __dynamic_len[__dynamic_len_idx] = (_src_length); \
440 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
441 __dynamic_len_idx++;
442
3202f63a
MJ
443#undef lttng_ust__field_string
444#define lttng_ust__field_string(_item, _src, _nowrite) \
24a39530 445 __event_len += __dynamic_len[__dynamic_len_idx++] = \
ee0889a3 446 strlen((_src) ? (_src) : LTTNG_UST__NULL_STRING) + 1;
1c324e59 447
ddde62ca
MJ
448#undef lttng_ust__field_unused
449#define lttng_ust__field_unused(_src) \
5152f6df
MJ
450 if (0) \
451 (void) (_src); /* Unused */
452
78684808
MJ
453#undef lttng_ust__field_enum
454#define lttng_ust__field_enum(_provider, _name, _type, _item, _src, _nowrite) \
b4064f28 455 lttng_ust__field_integer_ext(_type, _item, _src, LTTNG_UST_BYTE_ORDER, 10, _nowrite)
c785c634 456
cadfcbfc
MJ
457#undef LTTNG_UST_TP_ARGS
458#define LTTNG_UST_TP_ARGS(...) __VA_ARGS__
1c324e59 459
efa14d16
MJ
460#undef LTTNG_UST_TP_FIELDS
461#define LTTNG_UST_TP_FIELDS(...) __VA_ARGS__
1c324e59 462
7f2f82c3
MJ
463#undef LTTNG_UST__TRACEPOINT_EVENT_CLASS
464#define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
106ff4da 465static inline \
bfcc2759 466size_t lttng_ust__event_get_size__##_provider##___##_name(size_t *__dynamic_len, LTTNG_UST__TP_ARGS_DATA_PROTO(_args)) \
106ff4da 467 lttng_ust_notrace; \
a8909ba5 468static inline \
bfcc2759 469size_t lttng_ust__event_get_size__##_provider##___##_name( \
5152f6df 470 size_t *__dynamic_len __attribute__((__unused__)), \
6eddcb06 471 LTTNG_UST__TP_ARGS_DATA_PROTO(_args)) \
1c324e59
MD
472{ \
473 size_t __event_len = 0; \
5152f6df 474 unsigned int __dynamic_len_idx __attribute__((__unused__)) = 0; \
1c324e59
MD
475 \
476 if (0) \
5152f6df
MJ
477 (void) __tp_data; /* don't warn if unused */ \
478 \
1c324e59
MD
479 _fields \
480 return __event_len; \
481}
482
bb71a8ea 483#include LTTNG_UST_TRACEPOINT_INCLUDE
1c324e59 484
1ddfd641
MD
485/*
486 * Stage 3.1 of tracepoint event generation.
487 *
488 * Create static inline function that layout the filter stack data.
4774c8f3 489 * We make both write and nowrite data available to the filter.
1ddfd641
MD
490 */
491
7f2f82c3 492/* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
1ddfd641 493#include <lttng/ust-tracepoint-event-reset.h>
4774c8f3
MD
494#include <lttng/ust-tracepoint-event-write.h>
495#include <lttng/ust-tracepoint-event-nowrite.h>
1ddfd641 496
b4064f28
MJ
497#undef lttng_ust__field_integer_ext
498#define lttng_ust__field_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
eae3c729 499 if (lttng_ust_is_signed_type(_type)) { \
3ebeea0d
MD
500 int64_t __ctf_tmp_int64; \
501 switch (sizeof(_type)) { \
502 case 1: \
503 { \
504 union { _type t; int8_t v; } __tmp = { (_type) (_src) }; \
505 __ctf_tmp_int64 = (int64_t) __tmp.v; \
506 break; \
507 } \
508 case 2: \
509 { \
510 union { _type t; int16_t v; } __tmp = { (_type) (_src) }; \
baa8acf3
MJ
511 if (_byte_order != LTTNG_UST_BYTE_ORDER) \
512 __tmp.v = lttng_ust_bswap_16(__tmp.v); \
3ebeea0d
MD
513 __ctf_tmp_int64 = (int64_t) __tmp.v; \
514 break; \
515 } \
516 case 4: \
517 { \
518 union { _type t; int32_t v; } __tmp = { (_type) (_src) }; \
baa8acf3
MJ
519 if (_byte_order != LTTNG_UST_BYTE_ORDER) \
520 __tmp.v = lttng_ust_bswap_32(__tmp.v); \
3ebeea0d
MD
521 __ctf_tmp_int64 = (int64_t) __tmp.v; \
522 break; \
523 } \
524 case 8: \
525 { \
526 union { _type t; int64_t v; } __tmp = { (_type) (_src) }; \
baa8acf3
MJ
527 if (_byte_order != LTTNG_UST_BYTE_ORDER) \
528 __tmp.v = lttng_ust_bswap_64(__tmp.v); \
3ebeea0d
MD
529 __ctf_tmp_int64 = (int64_t) __tmp.v; \
530 break; \
531 } \
532 default: \
533 abort(); \
534 }; \
fa099471
MD
535 memcpy(__stack_data, &__ctf_tmp_int64, sizeof(int64_t)); \
536 } else { \
3ebeea0d
MD
537 uint64_t __ctf_tmp_uint64; \
538 switch (sizeof(_type)) { \
539 case 1: \
540 { \
541 union { _type t; uint8_t v; } __tmp = { (_type) (_src) }; \
542 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
543 break; \
544 } \
545 case 2: \
546 { \
547 union { _type t; uint16_t v; } __tmp = { (_type) (_src) }; \
baa8acf3
MJ
548 if (_byte_order != LTTNG_UST_BYTE_ORDER) \
549 __tmp.v = lttng_ust_bswap_16(__tmp.v); \
3ebeea0d
MD
550 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
551 break; \
552 } \
553 case 4: \
554 { \
555 union { _type t; uint32_t v; } __tmp = { (_type) (_src) }; \
baa8acf3
MJ
556 if (_byte_order != LTTNG_UST_BYTE_ORDER) \
557 __tmp.v = lttng_ust_bswap_32(__tmp.v); \
3ebeea0d
MD
558 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
559 break; \
560 } \
561 case 8: \
562 { \
563 union { _type t; uint64_t v; } __tmp = { (_type) (_src) }; \
baa8acf3
MJ
564 if (_byte_order != LTTNG_UST_BYTE_ORDER) \
565 __tmp.v = lttng_ust_bswap_64(__tmp.v); \
3ebeea0d
MD
566 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
567 break; \
568 } \
569 default: \
570 abort(); \
571 }; \
fa099471
MD
572 memcpy(__stack_data, &__ctf_tmp_uint64, sizeof(uint64_t)); \
573 } \
1ddfd641
MD
574 __stack_data += sizeof(int64_t);
575
891226fc
MJ
576#undef lttng_ust__field_float
577#define lttng_ust__field_float(_type, _item, _src, _nowrite) \
fa099471
MD
578 { \
579 double __ctf_tmp_double = (double) (_type) (_src); \
580 memcpy(__stack_data, &__ctf_tmp_double, sizeof(double)); \
581 __stack_data += sizeof(double); \
582 }
1ddfd641 583
10937ee5
MJ
584#undef lttng_ust__field_array_encoded
585#define lttng_ust__field_array_encoded(_type, _item, _src, _byte_order, _length, \
f3ec4cb5 586 _encoding, _nowrite, _elem_type_base) \
fa099471
MD
587 { \
588 unsigned long __ctf_tmp_ulong = (unsigned long) (_length); \
59034aab 589 const void *__ctf_tmp_ptr = (_src); \
fa099471
MD
590 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
591 __stack_data += sizeof(unsigned long); \
b1239ad6
MD
592 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
593 __stack_data += sizeof(void *); \
fa099471 594 }
1ddfd641 595
1d188af9
MJ
596#undef lttng_ust__field_sequence_encoded
597#define lttng_ust__field_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
f968510a 598 _src_length, _encoding, _nowrite, _elem_type_base) \
fa099471
MD
599 { \
600 unsigned long __ctf_tmp_ulong = (unsigned long) (_src_length); \
59034aab 601 const void *__ctf_tmp_ptr = (_src); \
fa099471
MD
602 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
603 __stack_data += sizeof(unsigned long); \
b1239ad6
MD
604 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
605 __stack_data += sizeof(void *); \
fa099471 606 }
1ddfd641 607
3202f63a
MJ
608#undef lttng_ust__field_string
609#define lttng_ust__field_string(_item, _src, _nowrite) \
fa099471 610 { \
24a39530 611 const void *__ctf_tmp_ptr = \
ee0889a3 612 ((_src) ? (_src) : LTTNG_UST__NULL_STRING); \
b1239ad6
MD
613 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
614 __stack_data += sizeof(void *); \
fa099471 615 }
1ddfd641 616
ddde62ca
MJ
617#undef lttng_ust__field_unused
618#define lttng_ust__field_unused(_src) \
5152f6df
MJ
619 if (0) \
620 (void) (_src);
621
78684808
MJ
622#undef lttng_ust__field_enum
623#define lttng_ust__field_enum(_provider, _name, _type, _item, _src, _nowrite) \
b4064f28 624 lttng_ust__field_integer_ext(_type, _item, _src, LTTNG_UST_BYTE_ORDER, 10, _nowrite)
c785c634 625
cadfcbfc
MJ
626#undef LTTNG_UST_TP_ARGS
627#define LTTNG_UST_TP_ARGS(...) __VA_ARGS__
1ddfd641 628
efa14d16
MJ
629#undef LTTNG_UST_TP_FIELDS
630#define LTTNG_UST_TP_FIELDS(...) __VA_ARGS__
1ddfd641 631
7f2f82c3
MJ
632#undef LTTNG_UST__TRACEPOINT_EVENT_CLASS
633#define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
1ddfd641 634static inline \
bfcc2759 635void lttng_ust__event_prepare_interpreter_stack__##_provider##___##_name(char *__stack_data,\
6eddcb06 636 LTTNG_UST__TP_ARGS_DATA_PROTO(_args)) \
1ddfd641 637{ \
5152f6df
MJ
638 if (0) { \
639 (void) __tp_data; /* don't warn if unused */ \
640 (void) __stack_data; /* don't warn if unused */ \
641 } \
642 \
1ddfd641
MD
643 _fields \
644}
645
bb71a8ea 646#include LTTNG_UST_TRACEPOINT_INCLUDE
1ddfd641 647
1c324e59 648/*
df854e41 649 * Stage 4 of tracepoint event generation.
1c324e59
MD
650 *
651 * Create static inline function that calculates event payload alignment.
652 */
653
7f2f82c3 654/* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
1c324e59 655#include <lttng/ust-tracepoint-event-reset.h>
4774c8f3 656#include <lttng/ust-tracepoint-event-write.h>
1c324e59 657
b4064f28
MJ
658#undef lttng_ust__field_integer_ext
659#define lttng_ust__field_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
5152f6df
MJ
660 if (0) \
661 (void) (_src); /* Unused */ \
bfcc2759 662 lttng_ust__event_align = lttng_ust__tp_max_t(size_t, lttng_ust__event_align, lttng_ust_rb_alignof(_type));
1c324e59 663
891226fc
MJ
664#undef lttng_ust__field_float
665#define lttng_ust__field_float(_type, _item, _src, _nowrite) \
5152f6df
MJ
666 if (0) \
667 (void) (_src); /* Unused */ \
bfcc2759 668 lttng_ust__event_align = lttng_ust__tp_max_t(size_t, lttng_ust__event_align, lttng_ust_rb_alignof(_type));
1c324e59 669
10937ee5
MJ
670#undef lttng_ust__field_array_encoded
671#define lttng_ust__field_array_encoded(_type, _item, _src, _byte_order, _length, \
f3ec4cb5 672 _encoding, _nowrite, _elem_type_base) \
5152f6df
MJ
673 if (0) \
674 (void) (_src); /* Unused */ \
bfcc2759 675 lttng_ust__event_align = lttng_ust__tp_max_t(size_t, lttng_ust__event_align, lttng_ust_rb_alignof(_type));
1c324e59 676
1d188af9
MJ
677#undef lttng_ust__field_sequence_encoded
678#define lttng_ust__field_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
f968510a 679 _src_length, _encoding, _nowrite, _elem_type_base) \
5152f6df
MJ
680 if (0) \
681 (void) (_src); /* Unused */ \
682 if (0) \
683 (void) (_src_length); /* Unused */ \
bfcc2759
MJ
684 lttng_ust__event_align = lttng_ust__tp_max_t(size_t, lttng_ust__event_align, lttng_ust_rb_alignof(_length_type)); \
685 lttng_ust__event_align = lttng_ust__tp_max_t(size_t, lttng_ust__event_align, lttng_ust_rb_alignof(_type));
1c324e59 686
3202f63a
MJ
687#undef lttng_ust__field_string
688#define lttng_ust__field_string(_item, _src, _nowrite) \
5152f6df
MJ
689 if (0) \
690 (void) (_src); /* Unused */
691
ddde62ca
MJ
692#undef lttng_ust__field_unused
693#define lttng_ust__field_unused(_src) \
5152f6df
MJ
694 if (0) \
695 (void) (_src); /* Unused */
1c324e59 696
78684808
MJ
697#undef lttng_ust__field_enum
698#define lttng_ust__field_enum(_provider, _name, _type, _item, _src, _nowrite) \
b4064f28 699 lttng_ust__field_integer_ext(_type, _item, _src, LTTNG_UST_BYTE_ORDER, 10, _nowrite)
c785c634 700
cadfcbfc
MJ
701#undef LTTNG_UST_TP_ARGS
702#define LTTNG_UST_TP_ARGS(...) __VA_ARGS__
1c324e59 703
efa14d16
MJ
704#undef LTTNG_UST_TP_FIELDS
705#define LTTNG_UST_TP_FIELDS(...) __VA_ARGS__
1c324e59 706
7f2f82c3
MJ
707#undef LTTNG_UST__TRACEPOINT_EVENT_CLASS
708#define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
106ff4da 709static inline \
bfcc2759 710size_t lttng_ust__event_get_align__##_provider##___##_name(LTTNG_UST__TP_ARGS_PROTO(_args)) \
106ff4da 711 lttng_ust_notrace; \
1c324e59 712static inline \
bfcc2759 713size_t lttng_ust__event_get_align__##_provider##___##_name(LTTNG_UST__TP_ARGS_PROTO(_args)) \
1c324e59 714{ \
bfcc2759 715 size_t lttng_ust__event_align = 1; \
1c324e59 716 _fields \
bfcc2759 717 return lttng_ust__event_align; \
1c324e59
MD
718}
719
bb71a8ea 720#include LTTNG_UST_TRACEPOINT_INCLUDE
1c324e59
MD
721
722
723/*
df854e41 724 * Stage 5 of tracepoint event generation.
1c324e59
MD
725 *
726 * Create the probe function. This function calls event size calculation
727 * and writes event data into the buffer.
728 */
729
7f2f82c3 730/* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
1c324e59 731#include <lttng/ust-tracepoint-event-reset.h>
4774c8f3 732#include <lttng/ust-tracepoint-event-write.h>
1c324e59 733
b4064f28
MJ
734#undef lttng_ust__field_integer_ext
735#define lttng_ust__field_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
1c324e59
MD
736 { \
737 _type __tmp = (_src); \
8936b6c0 738 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp), lttng_ust_rb_alignof(__tmp));\
1c324e59
MD
739 }
740
891226fc
MJ
741#undef lttng_ust__field_float
742#define lttng_ust__field_float(_type, _item, _src, _nowrite) \
1c324e59
MD
743 { \
744 _type __tmp = (_src); \
8936b6c0 745 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp), lttng_ust_rb_alignof(__tmp));\
1c324e59
MD
746 }
747
10937ee5
MJ
748#undef lttng_ust__field_array_encoded
749#define lttng_ust__field_array_encoded(_type, _item, _src, _byte_order, _length, \
f3ec4cb5 750 _encoding, _nowrite, _elem_type_base) \
27927814 751 if (lttng_ust_string_encoding_##_encoding == lttng_ust_string_encoding_none) \
8936b6c0 752 __chan->ops->event_write(&__ctx, _src, sizeof(_type) * (_length), lttng_ust_rb_alignof(_type)); \
27927814 753 else \
879f9b0a 754 __chan->ops->event_pstrcpy_pad(&__ctx, (const char *) (_src), _length); \
1c324e59 755
1d188af9
MJ
756#undef lttng_ust__field_sequence_encoded
757#define lttng_ust__field_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
f968510a 758 _src_length, _encoding, _nowrite, _elem_type_base) \
1c324e59 759 { \
d71b57b9 760 _length_type __tmpl = __stackvar.__dynamic_len[__dynamic_len_idx]; \
8936b6c0 761 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(_length_type), lttng_ust_rb_alignof(_length_type));\
1c324e59 762 } \
27927814
MD
763 if (lttng_ust_string_encoding_##_encoding == lttng_ust_string_encoding_none) \
764 __chan->ops->event_write(&__ctx, _src, \
bae1f483 765 sizeof(_type) * lttng_ust__get_dynamic_len(dest), lttng_ust_rb_alignof(_type)); \
27927814 766 else \
bae1f483 767 __chan->ops->event_pstrcpy_pad(&__ctx, (const char *) (_src), lttng_ust__get_dynamic_len(dest)); \
1c324e59 768
3202f63a
MJ
769#undef lttng_ust__field_string
770#define lttng_ust__field_string(_item, _src, _nowrite) \
24a39530
PP
771 { \
772 const char *__ctf_tmp_string = \
ee0889a3 773 ((_src) ? (_src) : LTTNG_UST__NULL_STRING); \
f9ec4a97 774 __chan->ops->event_strcpy(&__ctx, __ctf_tmp_string, \
bae1f483 775 lttng_ust__get_dynamic_len(dest)); \
24a39530
PP
776 }
777
ddde62ca
MJ
778#undef lttng_ust__field_unused
779#define lttng_ust__field_unused(_src)
1c324e59 780
78684808
MJ
781#undef lttng_ust__field_enum
782#define lttng_ust__field_enum(_provider, _name, _type, _item, _src, _nowrite) \
b4064f28 783 lttng_ust__field_integer_ext(_type, _item, _src, LTTNG_UST_BYTE_ORDER, 10, _nowrite)
c785c634 784
1c324e59 785/* Beware: this get len actually consumes the len value */
bae1f483
MJ
786#undef lttng_ust__get_dynamic_len
787#define lttng_ust__get_dynamic_len(field) __stackvar.__dynamic_len[__dynamic_len_idx++]
1c324e59 788
cadfcbfc
MJ
789#undef LTTNG_UST_TP_ARGS
790#define LTTNG_UST_TP_ARGS(...) __VA_ARGS__
1c324e59 791
efa14d16
MJ
792#undef LTTNG_UST_TP_FIELDS
793#define LTTNG_UST_TP_FIELDS(...) __VA_ARGS__
1c324e59 794
95c25348
PW
795/*
796 * For state dump, check that "session" argument (mandatory) matches the
797 * session this event belongs to. Ensures that we write state dump data only
798 * into the started session, not into all sessions.
799 */
91fe3e13
MJ
800#undef LTTNG_UST__TP_SESSION_CHECK
801#ifdef LTTNG_UST_TP_SESSION_CHECK
802#define LTTNG_UST__TP_SESSION_CHECK(session, csession) (session == csession)
95c25348 803#else /* TP_SESSION_CHECK */
91fe3e13 804#define LTTNG_UST__TP_SESSION_CHECK(session, csession) 1
95c25348
PW
805#endif /* TP_SESSION_CHECK */
806
97904b41
MD
807/*
808 * Use of __builtin_return_address(0) sometimes seems to cause stack
809 * corruption on 32-bit PowerPC. Disable this feature on that
810 * architecture for now by always using the NULL value for the ip
811 * context.
812 */
c28c4a88
MJ
813#undef LTTNG_UST__TP_IP_PARAM
814
815#ifdef LTTNG_UST_TP_IP_PARAM
816#define LTTNG_UST__TP_IP_PARAM(x) (x)
5dadb547 817#else /* TP_IP_PARAM */
97904b41 818
2eba8e39 819#if defined(LTTNG_UST_ARCH_PPC) && !defined(LTTNG_UST_ARCH_PPC64)
c28c4a88 820#define LTTNG_UST__TP_IP_PARAM(x) NULL
2eba8e39 821#else
c28c4a88 822#define LTTNG_UST__TP_IP_PARAM(x) __builtin_return_address(0)
2eba8e39 823#endif
97904b41 824
5dadb547
MD
825#endif /* TP_IP_PARAM */
826
1ddfd641
MD
827/*
828 * Using twice size for filter stack data to hold size and pointer for
829 * each field (worse case). For integers, max size required is 64-bit.
830 * Same for double-precision floats. Those fit within
831 * 2*sizeof(unsigned long) for all supported architectures.
61ce3223 832 * Perform UNION (||) of filter runtime list.
1ddfd641 833 */
7f2f82c3
MJ
834#undef LTTNG_UST__TRACEPOINT_EVENT_CLASS
835#define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
106ff4da 836static \
bfcc2759 837void lttng_ust__event_probe__##_provider##___##_name(LTTNG_UST__TP_ARGS_DATA_PROTO(_args)) \
106ff4da 838 lttng_ust_notrace; \
a8909ba5 839static \
bfcc2759 840void lttng_ust__event_probe__##_provider##___##_name(LTTNG_UST__TP_ARGS_DATA_PROTO(_args)) \
1c324e59 841{ \
ba99fbe2 842 struct lttng_ust_event_common *__event = (struct lttng_ust_event_common *) __tp_data; \
1c324e59 843 size_t __dynamic_len_idx = 0; \
bfcc2759 844 const size_t __num_fields = LTTNG_UST__TP_ARRAY_SIZE(lttng_ust__event_fields___##_provider##___##_name) - 1; \
d71b57b9 845 union { \
75026e9f 846 size_t __dynamic_len[__num_fields]; \
ba99fbe2 847 char __interpreter_stack_data[2 * sizeof(unsigned long) * __num_fields]; \
d71b57b9 848 } __stackvar; \
1c324e59 849 int __ret; \
a2e4d05e 850 bool __interpreter_stack_prepared = false; \
1c324e59
MD
851 \
852 if (0) \
853 (void) __dynamic_len_idx; /* don't warn if unused */ \
ba99fbe2
MD
854 switch (__event->type) { \
855 case LTTNG_UST_EVENT_TYPE_RECORDER: \
856 { \
bfcc2759
MJ
857 struct lttng_ust_event_recorder *lttng_ust__event_recorder = (struct lttng_ust_event_recorder *) __event->child; \
858 struct lttng_ust_channel_buffer *__chan = lttng_ust__event_recorder->chan; \
e7bc0ef6 859 struct lttng_ust_channel_common *__chan_common = __chan->parent; \
ba99fbe2 860 \
91fe3e13 861 if (!LTTNG_UST__TP_SESSION_CHECK(session, __chan_common->session)) \
ba99fbe2 862 return; \
e7bc0ef6 863 if (caa_unlikely(!CMM_ACCESS_ONCE(__chan_common->session->active))) \
ba99fbe2 864 return; \
e7bc0ef6 865 if (caa_unlikely(!CMM_ACCESS_ONCE(__chan_common->enabled))) \
ba99fbe2
MD
866 return; \
867 break; \
868 } \
869 case LTTNG_UST_EVENT_TYPE_NOTIFIER: \
870 break; \
871 } \
872 if (caa_unlikely(!CMM_ACCESS_ONCE(__event->enabled))) \
1c324e59 873 return; \
251c9f75 874 if (caa_unlikely(!LTTNG_UST_TP_RCU_LINK_TEST())) \
1b436e01 875 return; \
a2e4d05e 876 if (caa_unlikely(CMM_ACCESS_ONCE(__event->eval_filter))) { \
bfcc2759 877 lttng_ust__event_prepare_interpreter_stack__##_provider##___##_name(__stackvar.__interpreter_stack_data, \
6eddcb06 878 LTTNG_UST__TP_ARGS_DATA_VAR(_args)); \
a2e4d05e
MD
879 __interpreter_stack_prepared = true; \
880 if (caa_likely(__event->run_filter(__event, \
881 __stackvar.__interpreter_stack_data, NULL) != LTTNG_UST_EVENT_FILTER_ACCEPT)) \
61ce3223 882 return; \
1ddfd641 883 } \
ba99fbe2
MD
884 switch (__event->type) { \
885 case LTTNG_UST_EVENT_TYPE_RECORDER: \
886 { \
bfcc2759
MJ
887 size_t __event_len, lttng_ust__event_align; \
888 struct lttng_ust_event_recorder *lttng_ust__event_recorder = (struct lttng_ust_event_recorder *) __event->child; \
889 struct lttng_ust_channel_buffer *__chan = lttng_ust__event_recorder->chan; \
b5457df5 890 struct lttng_ust_ring_buffer_ctx __ctx; \
ba99fbe2 891 \
bfcc2759 892 __event_len = lttng_ust__event_get_size__##_provider##___##_name(__stackvar.__dynamic_len, \
6eddcb06 893 LTTNG_UST__TP_ARGS_DATA_VAR(_args)); \
bfcc2759
MJ
894 lttng_ust__event_align = lttng_ust__event_get_align__##_provider##___##_name(LTTNG_UST__TP_ARGS_VAR(_args)); \
895 lttng_ust_ring_buffer_ctx_init(&__ctx, lttng_ust__event_recorder, __event_len, lttng_ust__event_align, \
c28c4a88 896 LTTNG_UST__TP_IP_PARAM(LTTNG_UST_TP_IP_PARAM)); \
8936b6c0 897 __ret = __chan->ops->event_reserve(&__ctx); \
ba99fbe2
MD
898 if (__ret < 0) \
899 return; \
900 _fields \
901 __chan->ops->event_commit(&__ctx); \
902 break; \
903 } \
904 case LTTNG_UST_EVENT_TYPE_NOTIFIER: \
905 { \
bfcc2759 906 struct lttng_ust_event_notifier *lttng_ust__event_notifier = (struct lttng_ust_event_notifier *) __event->child; \
a2e4d05e
MD
907 struct lttng_ust_notification_ctx __notif_ctx; \
908 \
909 __notif_ctx.struct_size = sizeof(struct lttng_ust_notification_ctx); \
bfcc2759 910 __notif_ctx.eval_capture = CMM_ACCESS_ONCE(lttng_ust__event_notifier->eval_capture); \
ba99fbe2 911 \
a2e4d05e 912 if (caa_unlikely(!__interpreter_stack_prepared && __notif_ctx.eval_capture)) \
bfcc2759 913 lttng_ust__event_prepare_interpreter_stack__##_provider##___##_name(__stackvar.__interpreter_stack_data, \
6eddcb06 914 LTTNG_UST__TP_ARGS_DATA_VAR(_args)); \
ba99fbe2 915 \
bfcc2759 916 lttng_ust__event_notifier->notification_send(lttng_ust__event_notifier, \
a2e4d05e
MD
917 __stackvar.__interpreter_stack_data, \
918 &__notif_ctx); \
ba99fbe2
MD
919 break; \
920 } \
921 } \
1c324e59
MD
922}
923
bb71a8ea 924#include LTTNG_UST_TRACEPOINT_INCLUDE
1c324e59 925
bae1f483 926#undef lttng_ust__get_dynamic_len
1c324e59 927
68755429
MD
928/*
929 * Stage 5.1 of tracepoint event generation.
930 *
931 * Create probe signature
932 */
933
7f2f82c3 934/* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
68755429
MD
935#include <lttng/ust-tracepoint-event-reset.h>
936
cadfcbfc
MJ
937#undef LTTNG_UST_TP_ARGS
938#define LTTNG_UST_TP_ARGS(...) __VA_ARGS__
9eb06182 939
4a36f0f1 940#define LTTNG_UST__TP_EXTRACT_STRING2(...) #__VA_ARGS__
68755429 941
7f2f82c3
MJ
942#undef LTTNG_UST__TRACEPOINT_EVENT_CLASS
943#define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
ff82b7c1 944static const char __tp_event_signature___##_provider##___##_name[] = \
4a36f0f1 945 LTTNG_UST__TP_EXTRACT_STRING2(_args);
68755429 946
bb71a8ea 947#include LTTNG_UST_TRACEPOINT_INCLUDE
68755429 948
4a36f0f1 949#undef LTTNG_UST__TP_EXTRACT_STRING2
9eb06182 950
05ceaafd 951/*
882a56d7 952 * Stage 6 of tracepoint event generation.
1c324e59 953 *
df854e41
MD
954 * Tracepoint loglevel mapping definition generation. We generate a
955 * symbol for each mapping for a provider/event to ensure at most a 1 to
956 * 1 mapping between events and loglevels. If the symbol is repeated,
957 * the compiler will complain.
05ceaafd
MD
958 */
959
7f2f82c3 960/* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
05ceaafd
MD
961#include <lttng/ust-tracepoint-event-reset.h>
962
4ea4f80e
MD
963/*
964 * Declare _loglevel___##__provider##___##__name as non-static, with
965 * hidden visibility for c++ handling of weakref. We do a weakref to the
966 * symbol in a later stage, which requires that the symbol is not
967 * mangled.
968 */
969#ifdef __cplusplus
fc6d7bef 970#define LTTNG_UST_TP_EXTERN_C extern "C"
4ea4f80e 971#else
fc6d7bef 972#define LTTNG_UST_TP_EXTERN_C
4ea4f80e
MD
973#endif
974
612e9ce4
MJ
975#undef LTTNG_UST_TRACEPOINT_LOGLEVEL
976#define LTTNG_UST_TRACEPOINT_LOGLEVEL(__provider, __name, __loglevel) \
3d33ca1d
MD
977static const int _loglevel_value___##__provider##___##__name = __loglevel; \
978LTTNG_UST_TP_EXTERN_C const int * const _loglevel___##__provider##___##__name \
979 __attribute__((visibility("hidden"))) = \
457a6b58 980 &_loglevel_value___##__provider##___##__name;
df854e41 981
bb71a8ea 982#include LTTNG_UST_TRACEPOINT_INCLUDE
df854e41 983
fc6d7bef 984#undef LTTNG_UST_TP_EXTERN_C
4ea4f80e 985
6ddc916d
MD
986/*
987 * Stage 6.1 of tracepoint event generation.
988 *
989 * Tracepoint UML URI info.
990 */
991
7f2f82c3 992/* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
6ddc916d
MD
993#include <lttng/ust-tracepoint-event-reset.h>
994
4ea4f80e
MD
995/*
996 * Declare _model_emf_uri___##__provider##___##__name as non-static,
997 * with hidden visibility for c++ handling of weakref. We do a weakref
998 * to the symbol in a later stage, which requires that the symbol is not
999 * mangled.
1000 */
1001#ifdef __cplusplus
fc6d7bef 1002#define LTTNG_UST_TP_EXTERN_C extern "C"
4ea4f80e 1003#else
fc6d7bef 1004#define LTTNG_UST_TP_EXTERN_C
4ea4f80e
MD
1005#endif
1006
dbcc2f92
MJ
1007#undef LTTNG_UST_TRACEPOINT_MODEL_EMF_URI
1008#define LTTNG_UST_TRACEPOINT_MODEL_EMF_URI(__provider, __name, __uri) \
3d33ca1d 1009LTTNG_UST_TP_EXTERN_C const char * const _model_emf_uri___##__provider##___##__name \
082802f9 1010 __attribute__((visibility("hidden"))) = __uri; \
6ddc916d 1011
bb71a8ea 1012#include LTTNG_UST_TRACEPOINT_INCLUDE
6ddc916d 1013
fc6d7bef 1014#undef LTTNG_UST_TP_EXTERN_C
4ea4f80e 1015
5b4c6da4
MD
1016/*
1017 * Stage 7.0 of tracepoint event generation.
1018 *
1019 * Declare toplevel descriptor for the whole probe.
1020 * Unlike C, C++ does not allow tentative definitions. Therefore, we
1021 * need to explicitly declare the variable with "extern", using hidden
1022 * visibility to keep this symbol from being exported to the global
1023 * symbol table.
1024 */
1025
c9201081 1026extern const struct lttng_ust_probe_desc LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_desc___, LTTNG_UST_TRACEPOINT_PROVIDER)
5b4c6da4
MD
1027 __attribute__((visibility("hidden")));
1028
df854e41 1029/*
882a56d7 1030 * Stage 7.1 of tracepoint event generation.
df854e41
MD
1031 *
1032 * Create events description structures. We use a weakref because
3d33ca1d 1033 * loglevels are optional. If not declared, the event will point to
df854e41 1034 * a loglevel that contains NULL.
3d33ca1d
MD
1035 *
1036 * C++ requires that const objects have a user-declared default
1037 * constructor. However, in both C++ and C, weakref cannot be
1038 * initialized because it causes the weakref attribute to be ignored.
1039 * Therefore, the loglevel and model_emf_uri pointers are not const
1040 * to ensure C++ compilers default-initialize them.
df854e41
MD
1041 */
1042
7f2f82c3 1043/* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
df854e41
MD
1044#include <lttng/ust-tracepoint-event-reset.h>
1045
7f2f82c3
MJ
1046#undef LTTNG_UST__TRACEPOINT_EVENT_INSTANCE
1047#define LTTNG_UST__TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
882a56d7
MD
1048static const int * \
1049 __ref_loglevel___##_provider##___##_name \
1050 __attribute__((weakref ("_loglevel___" #_provider "___" #_name))); \
6ddc916d
MD
1051static const char * \
1052 __ref_model_emf_uri___##_provider##___##_name \
1053 __attribute__((weakref ("_model_emf_uri___" #_provider "___" #_name)));\
bfcc2759 1054static const struct lttng_ust_event_desc lttng_ust__event_desc___##_provider##_##_name = { \
dc11f93f 1055 .struct_size = sizeof(struct lttng_ust_event_desc), \
5b4c6da4 1056 .event_name = #_name, \
c9201081 1057 .probe_desc = &lttng_ust__probe_desc___##_provider, \
bfcc2759
MJ
1058 .probe_callback = (void (*)(void)) &lttng_ust__event_probe__##_provider##___##_template, \
1059 .fields = lttng_ust__event_fields___##_provider##___##_template, \
1060 .nr_fields = LTTNG_UST__TP_ARRAY_SIZE(lttng_ust__event_fields___##_provider##___##_template) - 1, \
882a56d7 1061 .loglevel = &__ref_loglevel___##_provider##___##_name, \
68755429 1062 .signature = __tp_event_signature___##_provider##___##_template, \
dc11f93f 1063 .model_emf_uri = &__ref_model_emf_uri___##_provider##___##_name, \
df854e41
MD
1064};
1065
bb71a8ea 1066#include LTTNG_UST_TRACEPOINT_INCLUDE
05ceaafd 1067
df854e41 1068/*
882a56d7 1069 * Stage 7.2 of tracepoint event generation.
df854e41
MD
1070 *
1071 * Create array of events.
1072 */
1073
7f2f82c3 1074/* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
df854e41
MD
1075#include <lttng/ust-tracepoint-event-reset.h>
1076
7f2f82c3
MJ
1077#undef LTTNG_UST__TRACEPOINT_EVENT_INSTANCE
1078#define LTTNG_UST__TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
bfcc2759 1079 &lttng_ust__event_desc___##_provider##_##_name,
df854e41 1080
bfcc2759 1081static const struct lttng_ust_event_desc * const LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__event_desc___, LTTNG_UST_TRACEPOINT_PROVIDER)[] = {
bb71a8ea 1082#include LTTNG_UST_TRACEPOINT_INCLUDE
1c80c909 1083 NULL, /* Dummy, C99 forbids 0-len array. */
05ceaafd
MD
1084};
1085
df854e41 1086
05ceaafd 1087/*
882a56d7 1088 * Stage 8 of tracepoint event generation.
05ceaafd
MD
1089 *
1090 * Create a toplevel descriptor for the whole probe.
1091 */
1092
c9201081 1093const struct lttng_ust_probe_desc LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_desc___, LTTNG_UST_TRACEPOINT_PROVIDER) = {
dc11f93f 1094 .struct_size = sizeof(struct lttng_ust_probe_desc),
061fc37a 1095 .provider_name = lttng_ust__tp_stringify(LTTNG_UST_TRACEPOINT_PROVIDER),
bfcc2759
MJ
1096 .event_desc = LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__event_desc___, LTTNG_UST_TRACEPOINT_PROVIDER),
1097 .nr_events = LTTNG_UST__TP_ARRAY_SIZE(LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__event_desc___, LTTNG_UST_TRACEPOINT_PROVIDER)) - 1,
71d31690
MD
1098 .major = LTTNG_UST_PROVIDER_MAJOR,
1099 .minor = LTTNG_UST_PROVIDER_MINOR,
05ceaafd
MD
1100};
1101
03221919 1102static int LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_register_refcount___, LTTNG_UST_TRACEPOINT_PROVIDER);
f082dde9 1103static struct lttng_ust_registered_probe *LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_register_cookie___, LTTNG_UST_TRACEPOINT_PROVIDER);
f0cc794d 1104
05ceaafd 1105/*
882a56d7 1106 * Stage 9 of tracepoint event generation.
05ceaafd 1107 *
1c324e59 1108 * Register/unregister probes at module load/unload.
628e1d81
MD
1109 *
1110 * Generate the constructor as an externally visible symbol for use when
1111 * linking the probe statically.
f0cc794d
MD
1112 *
1113 * Register refcount is protected by libc dynamic loader mutex.
1c324e59
MD
1114 */
1115
7f2f82c3 1116/* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
1c324e59 1117#include <lttng/ust-tracepoint-event-reset.h>
465a0d04 1118static void
11bce056 1119LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__events_init__, LTTNG_UST_TRACEPOINT_PROVIDER)(void)
465a0d04 1120 lttng_ust_notrace __attribute__((constructor));
a8909ba5 1121static void
11bce056 1122LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__events_init__, LTTNG_UST_TRACEPOINT_PROVIDER)(void)
1c324e59 1123{
4e48b5d2 1124 struct lttng_ust_registered_probe *reg_probe;
1c324e59 1125
03221919 1126 if (LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_register_refcount___,
5b393d64 1127 LTTNG_UST_TRACEPOINT_PROVIDER)++) {
f0cc794d
MD
1128 return;
1129 }
e8bd1da7 1130 /*
5b393d64 1131 * lttng_ust_tracepoint_provider_check_ ## LTTNG_UST_TRACEPOINT_PROVIDER() is a
e8bd1da7
MD
1132 * static inline function that ensures every probe PROVIDER
1133 * argument match the provider within which they appear. It
1134 * calls empty static inline functions, and therefore has no
1135 * runtime effect. However, if it detects an error, a linker
1136 * error will appear.
1137 */
5b393d64 1138 LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust_tracepoint_provider_check_, LTTNG_UST_TRACEPOINT_PROVIDER)();
f082dde9 1139 assert(!LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_register_cookie___, LTTNG_UST_TRACEPOINT_PROVIDER));
c9201081 1140 reg_probe = lttng_ust_probe_register(&LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_desc___, LTTNG_UST_TRACEPOINT_PROVIDER));
4e48b5d2
MD
1141 if (!reg_probe) {
1142 fprintf(stderr, "LTTng-UST: Error while registering tracepoint probe.\n");
7d381d6e
MD
1143 abort();
1144 }
f082dde9 1145 LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_register_cookie___, LTTNG_UST_TRACEPOINT_PROVIDER) = reg_probe;
1c324e59
MD
1146}
1147
c589eca2 1148static void
638ce920 1149LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__events_exit__, LTTNG_UST_TRACEPOINT_PROVIDER)(void)
c589eca2 1150 lttng_ust_notrace __attribute__((destructor));
a8909ba5 1151static void
638ce920 1152LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__events_exit__, LTTNG_UST_TRACEPOINT_PROVIDER)(void)
1c324e59 1153{
03221919 1154 if (--LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_register_refcount___,
5b393d64 1155 LTTNG_UST_TRACEPOINT_PROVIDER)) {
f0cc794d
MD
1156 return;
1157 }
f082dde9
MJ
1158 lttng_ust_probe_unregister(LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_register_cookie___, LTTNG_UST_TRACEPOINT_PROVIDER));
1159 LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_register_cookie___, LTTNG_UST_TRACEPOINT_PROVIDER) = NULL;
1c324e59 1160}
628e1d81 1161
5b393d64 1162int LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust_tracepoint_provider_, LTTNG_UST_TRACEPOINT_PROVIDER)
1d18d519 1163 __attribute__((visibility("default")));
This page took 0.142373 seconds and 4 git commands to generate.