Tracepoint API namespacing 'TRACEPOINT_INCLUDE'
[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>
44c72f10 18#include <string.h>
1c324e59 19
24a39530
PP
20#define __LTTNG_UST_NULL_STRING "(null)"
21
000b8662
MD
22#undef tp_list_for_each_entry_rcu
23#define tp_list_for_each_entry_rcu(pos, head, member) \
10544ee8 24 for (pos = cds_list_entry(tp_rcu_dereference((head)->next), __typeof__(*pos), member); \
000b8662 25 &pos->member != (head); \
10544ee8 26 pos = cds_list_entry(tp_rcu_dereference(pos->member.next), __typeof__(*pos), member))
000b8662 27
1c324e59 28/*
7f2f82c3 29 * LTTNG_UST_TRACEPOINT_EVENT_CLASS declares a class of tracepoints receiving the
1c324e59
MD
30 * same arguments and having the same field layout.
31 *
7f2f82c3 32 * LTTNG_UST_TRACEPOINT_EVENT_INSTANCE declares an instance of a tracepoint, with
1c324e59
MD
33 * its own provider and name. It refers to a class (template).
34 *
7f2f82c3 35 * LTTNG_UST_TRACEPOINT_EVENT declared both a class and an instance and does a
1c324e59
MD
36 * direct mapping from the instance to the class.
37 */
38
7f2f82c3
MJ
39#undef LTTNG_UST_TRACEPOINT_EVENT
40#define LTTNG_UST_TRACEPOINT_EVENT(_provider, _name, _args, _fields) \
41 LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, \
6eddcb06
MJ
42 LTTNG_UST__TP_PARAMS(_args), \
43 LTTNG_UST__TP_PARAMS(_fields)) \
7f2f82c3 44 LTTNG_UST__TRACEPOINT_EVENT_INSTANCE(_provider, _name, _name, \
6eddcb06 45 LTTNG_UST__TP_PARAMS(_args))
1c324e59 46
7f2f82c3
MJ
47#undef LTTNG_UST_TRACEPOINT_EVENT_CLASS
48#define LTTNG_UST_TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
6eddcb06 49 LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, LTTNG_UST__TP_PARAMS(_args), LTTNG_UST__TP_PARAMS(_fields))
f8021d08 50
7f2f82c3
MJ
51#undef LTTNG_UST_TRACEPOINT_EVENT_INSTANCE
52#define LTTNG_UST_TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
6eddcb06 53 LTTNG_UST__TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, LTTNG_UST__TP_PARAMS(_args))
f8021d08 54
1c324e59
MD
55/* Helpers */
56#define _TP_ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
57
58#define _tp_max_t(type, x, y) \
59 ({ \
60 type __max1 = (x); \
61 type __max2 = (y); \
62 __max1 > __max2 ? __max1: __max2; \
63 })
64
65/*
66 * Stage 0 of tracepoint event generation.
67 *
7f2f82c3 68 * Check that each LTTNG_UST_TRACEPOINT_EVENT provider argument match the
1c324e59
MD
69 * TRACEPOINT_PROVIDER by creating dummy callbacks.
70 */
71
7f2f82c3 72/* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
1c324e59
MD
73#include <lttng/ust-tracepoint-event-reset.h>
74
106ff4da 75static inline
aec5037b 76void LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust_tracepoint_provider_mismatch_, TRACEPOINT_PROVIDER)(void)
106ff4da 77 lttng_ust_notrace;
1c324e59 78static inline
aec5037b 79void LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust_tracepoint_provider_mismatch_, TRACEPOINT_PROVIDER)(void)
1c324e59
MD
80{
81}
82
7f2f82c3
MJ
83#undef LTTNG_UST__TRACEPOINT_EVENT_CLASS
84#define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
0274f7f2 85 lttng_ust_tracepoint_provider_mismatch_##_provider();
1c324e59 86
7f2f82c3
MJ
87#undef LTTNG_UST__TRACEPOINT_EVENT_INSTANCE
88#define LTTNG_UST__TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
0274f7f2 89 lttng_ust_tracepoint_provider_mismatch_##_provider();
1c324e59 90
106ff4da 91static inline
aec5037b 92void LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust_tracepoint_provider_check_, TRACEPOINT_PROVIDER)(void)
106ff4da 93 lttng_ust_notrace;
e8bd1da7 94static inline
aec5037b 95void LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust_tracepoint_provider_check_, TRACEPOINT_PROVIDER)(void)
1c324e59 96{
bb71a8ea 97#include LTTNG_UST_TRACEPOINT_INCLUDE
1c324e59
MD
98}
99
f56cd1d5
MD
100/*
101 * Stage 0.1 of tracepoint event generation.
102 *
7f2f82c3 103 * Check that each LTTNG_UST_TRACEPOINT_EVENT provider:name does not exceed the
f56cd1d5
MD
104 * tracepoint name length limit.
105 */
106
7f2f82c3 107/* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
f56cd1d5
MD
108#include <lttng/ust-tracepoint-event-reset.h>
109
7f2f82c3
MJ
110#undef LTTNG_UST__TRACEPOINT_EVENT_INSTANCE
111#define LTTNG_UST__TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
81b16412 112 lttng_ust_tracepoint_validate_name_len(_provider, _name);
f56cd1d5 113
bb71a8ea 114#include LTTNG_UST_TRACEPOINT_INCLUDE
f56cd1d5 115
c75c0422
MD
116/*
117 * Stage 0.2 of tracepoint event generation.
118 *
119 * Create dummy trace prototypes for each event class, and for each used
120 * template. This will allow checking whether the prototypes from the
121 * class and the instance using the class actually match.
122 */
123
7f2f82c3 124/* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
c75c0422
MD
125#include <lttng/ust-tracepoint-event-reset.h>
126
cadfcbfc
MJ
127#undef LTTNG_UST_TP_ARGS
128#define LTTNG_UST_TP_ARGS(...) __VA_ARGS__
c75c0422 129
7f2f82c3
MJ
130#undef LTTNG_UST__TRACEPOINT_EVENT_INSTANCE
131#define LTTNG_UST__TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
6eddcb06 132void __event_template_proto___##_provider##___##_template(LTTNG_UST__TP_ARGS_DATA_PROTO(_args));
c75c0422 133
7f2f82c3
MJ
134#undef LTTNG_UST__TRACEPOINT_EVENT_CLASS
135#define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
6eddcb06 136void __event_template_proto___##_provider##___##_name(LTTNG_UST__TP_ARGS_DATA_PROTO(_args));
c75c0422 137
bb71a8ea 138#include LTTNG_UST_TRACEPOINT_INCLUDE
c75c0422 139
c785c634
MD
140/*
141 * Stage 0.9 of tracepoint event generation
142 *
143 * Unfolding the enums
144 */
145#include <lttng/ust-tracepoint-event-reset.h>
146
147/* Enumeration entry (single value) */
148#undef ctf_enum_value
149#define ctf_enum_value(_string, _value) \
5defa774 150 LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_enum_entry, { \
891d6b55 151 .struct_size = sizeof(struct lttng_ust_enum_entry), \
a6f80644 152 .start = { \
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 .end = { \
eae3c729 158 .value = lttng_ust_is_signed_type(__typeof__(_value)) ? \
a6f80644 159 (long long) (_value) : (_value), \
eae3c729 160 .signedness = lttng_ust_is_signed_type(__typeof__(_value)), \
a6f80644
MD
161 }, \
162 .string = (_string), \
891d6b55 163 }),
c785c634
MD
164
165/* Enumeration entry (range) */
166#undef ctf_enum_range
167#define ctf_enum_range(_string, _range_start, _range_end) \
5defa774 168 LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_enum_entry, { \
891d6b55 169 .struct_size = sizeof(struct lttng_ust_enum_entry), \
a6f80644 170 .start = { \
eae3c729 171 .value = lttng_ust_is_signed_type(__typeof__(_range_start)) ? \
a6f80644 172 (long long) (_range_start) : (_range_start), \
eae3c729 173 .signedness = lttng_ust_is_signed_type(__typeof__(_range_start)), \
a6f80644
MD
174 }, \
175 .end = { \
eae3c729 176 .value = lttng_ust_is_signed_type(__typeof__(_range_end)) ? \
a6f80644 177 (long long) (_range_end) : (_range_end), \
eae3c729 178 .signedness = lttng_ust_is_signed_type(__typeof__(_range_end)), \
a6f80644
MD
179 }, \
180 .string = (_string), \
891d6b55 181 }),
c785c634 182
3e762260
PP
183/* Enumeration entry (automatic value; follows the rules of CTF) */
184#undef ctf_enum_auto
891d6b55 185#define ctf_enum_auto(_string) \
5defa774 186 LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_enum_entry, { \
891d6b55 187 .struct_size = sizeof(struct lttng_ust_enum_entry), \
3e762260
PP
188 .start = { \
189 .value = -1ULL, \
190 .signedness = 0, \
191 }, \
192 .end = { \
193 .value = -1ULL, \
194 .signedness = 0, \
195 }, \
196 .string = (_string), \
1a37a873 197 .options = LTTNG_UST_ENUM_ENTRY_OPTION_IS_AUTO, \
891d6b55 198 }),
3e762260 199
c785c634
MD
200#undef TP_ENUM_VALUES
201#define TP_ENUM_VALUES(...) \
202 __VA_ARGS__
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 \
1c80c909 208 ctf_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
222#undef _ctf_array_encoded
223#define _ctf_array_encoded(_type, _item, _src, _byte_order, \
224 _length, _encoding, _nowrite, \
225 _elem_type_base) \
b4c54822 226 lttng_ust_ctf_array_element_type_is_supported(_type, _item);
2df82195
FD
227
228#undef _ctf_sequence_encoded
229#define _ctf_sequence_encoded(_type, _item, _src, _byte_order, \
230 _length_type, _src_length, _encoding, _nowrite, \
231 _elem_type_base) \
b4c54822 232 lttng_ust_ctf_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
4774c8f3 255#undef _ctf_integer_ext
25cff019 256#define _ctf_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
4774c8f3 265#undef _ctf_float
180901e6 266#define _ctf_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
4774c8f3 275#undef _ctf_array_encoded
f3ec4cb5
MD
276#define _ctf_array_encoded(_type, _item, _src, _byte_order, \
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
4774c8f3 296#undef _ctf_sequence_encoded
48d660d1 297#define _ctf_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", \
a084756d 303 .type = lttng_ust_type_integer_define(_length_type, 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
4774c8f3 324#undef _ctf_string
180901e6 325#define _ctf_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
5152f6df
MJ
340#undef _ctf_unused
341#define _ctf_unused(_src)
342
c785c634
MD
343#undef _ctf_enum
344#define _ctf_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, \
354 .container_type = lttng_ust_type_integer_define(_type, BYTE_ORDER, 10), \
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) \
3d33ca1d 365 static const struct lttng_ust_event_field * const __event_fields___##_provider##___##_name[] = { \
1c324e59 366 _fields \
1c80c909 367 ctf_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, \
1c80c909 376 .nr_entries = _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) \
6eddcb06 395static void __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
4774c8f3 409#undef _ctf_integer_ext
180901e6 410#define _ctf_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
4774c8f3 416#undef _ctf_float
180901e6 417#define _ctf_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
4774c8f3 423#undef _ctf_array_encoded
f3ec4cb5
MD
424#define _ctf_array_encoded(_type, _item, _src, _byte_order, _length, _encoding, \
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
4774c8f3 431#undef _ctf_sequence_encoded
48d660d1 432#define _ctf_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
4774c8f3 443#undef _ctf_string
180901e6 444#define _ctf_string(_item, _src, _nowrite) \
24a39530
PP
445 __event_len += __dynamic_len[__dynamic_len_idx++] = \
446 strlen((_src) ? (_src) : __LTTNG_UST_NULL_STRING) + 1;
1c324e59 447
5152f6df
MJ
448#undef _ctf_unused
449#define _ctf_unused(_src) \
450 if (0) \
451 (void) (_src); /* Unused */
452
c785c634
MD
453#undef _ctf_enum
454#define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
455 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
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 \
6eddcb06 466size_t __event_get_size__##_provider##___##_name(size_t *__dynamic_len, LTTNG_UST__TP_ARGS_DATA_PROTO(_args)) \
106ff4da 467 lttng_ust_notrace; \
a8909ba5 468static inline \
5152f6df
MJ
469size_t __event_get_size__##_provider##___##_name( \
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
4774c8f3 497#undef _ctf_integer_ext
180901e6 498#define _ctf_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) }; \
39ad74cf
MD
511 if (_byte_order != BYTE_ORDER) \
512 __tmp.v = 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) }; \
39ad74cf
MD
519 if (_byte_order != BYTE_ORDER) \
520 __tmp.v = 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) }; \
39ad74cf
MD
527 if (_byte_order != BYTE_ORDER) \
528 __tmp.v = 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) }; \
39ad74cf
MD
548 if (_byte_order != BYTE_ORDER) \
549 __tmp.v = 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) }; \
39ad74cf
MD
556 if (_byte_order != BYTE_ORDER) \
557 __tmp.v = 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) }; \
39ad74cf
MD
564 if (_byte_order != BYTE_ORDER) \
565 __tmp.v = 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
4774c8f3 576#undef _ctf_float
180901e6 577#define _ctf_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
4774c8f3 584#undef _ctf_array_encoded
f3ec4cb5
MD
585#define _ctf_array_encoded(_type, _item, _src, _byte_order, _length, \
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
4774c8f3 596#undef _ctf_sequence_encoded
48d660d1 597#define _ctf_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
4774c8f3 608#undef _ctf_string
180901e6 609#define _ctf_string(_item, _src, _nowrite) \
fa099471 610 { \
24a39530
PP
611 const void *__ctf_tmp_ptr = \
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
5152f6df
MJ
617#undef _ctf_unused
618#define _ctf_unused(_src) \
619 if (0) \
620 (void) (_src);
621
c785c634
MD
622#undef _ctf_enum
623#define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
624 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
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 \
d37ecb3f 635void __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
4774c8f3 658#undef _ctf_integer_ext
180901e6 659#define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
5152f6df
MJ
660 if (0) \
661 (void) (_src); /* Unused */ \
dc325c1d 662 __event_align = _tp_max_t(size_t, __event_align, lttng_ust_rb_alignof(_type));
1c324e59 663
4774c8f3 664#undef _ctf_float
180901e6 665#define _ctf_float(_type, _item, _src, _nowrite) \
5152f6df
MJ
666 if (0) \
667 (void) (_src); /* Unused */ \
dc325c1d 668 __event_align = _tp_max_t(size_t, __event_align, lttng_ust_rb_alignof(_type));
1c324e59 669
4774c8f3 670#undef _ctf_array_encoded
f3ec4cb5
MD
671#define _ctf_array_encoded(_type, _item, _src, _byte_order, _length, \
672 _encoding, _nowrite, _elem_type_base) \
5152f6df
MJ
673 if (0) \
674 (void) (_src); /* Unused */ \
dc325c1d 675 __event_align = _tp_max_t(size_t, __event_align, lttng_ust_rb_alignof(_type));
1c324e59 676
4774c8f3 677#undef _ctf_sequence_encoded
48d660d1 678#define _ctf_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 */ \
dc325c1d
MJ
684 __event_align = _tp_max_t(size_t, __event_align, lttng_ust_rb_alignof(_length_type)); \
685 __event_align = _tp_max_t(size_t, __event_align, lttng_ust_rb_alignof(_type));
1c324e59 686
4774c8f3 687#undef _ctf_string
5152f6df
MJ
688#define _ctf_string(_item, _src, _nowrite) \
689 if (0) \
690 (void) (_src); /* Unused */
691
692#undef _ctf_unused
693#define _ctf_unused(_src) \
694 if (0) \
695 (void) (_src); /* Unused */
1c324e59 696
c785c634
MD
697#undef _ctf_enum
698#define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
699 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
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 \
6eddcb06 710size_t __event_get_align__##_provider##___##_name(LTTNG_UST__TP_ARGS_PROTO(_args)) \
106ff4da 711 lttng_ust_notrace; \
1c324e59 712static inline \
6eddcb06 713size_t __event_get_align__##_provider##___##_name(LTTNG_UST__TP_ARGS_PROTO(_args)) \
1c324e59
MD
714{ \
715 size_t __event_align = 1; \
716 _fields \
717 return __event_align; \
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
4774c8f3 734#undef _ctf_integer_ext
180901e6 735#define _ctf_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
4774c8f3 741#undef _ctf_float
180901e6 742#define _ctf_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
4774c8f3 748#undef _ctf_array_encoded
f3ec4cb5
MD
749#define _ctf_array_encoded(_type, _item, _src, _byte_order, _length, \
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
4774c8f3 756#undef _ctf_sequence_encoded
48d660d1 757#define _ctf_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, \
8936b6c0 765 sizeof(_type) * __get_dynamic_len(dest), lttng_ust_rb_alignof(_type)); \
27927814 766 else \
879f9b0a 767 __chan->ops->event_pstrcpy_pad(&__ctx, (const char *) (_src), __get_dynamic_len(dest)); \
1c324e59 768
4774c8f3 769#undef _ctf_string
8936b6c0 770#define _ctf_string(_item, _src, _nowrite) \
24a39530
PP
771 { \
772 const char *__ctf_tmp_string = \
773 ((_src) ? (_src) : __LTTNG_UST_NULL_STRING); \
f9ec4a97
MD
774 __chan->ops->event_strcpy(&__ctx, __ctf_tmp_string, \
775 __get_dynamic_len(dest)); \
24a39530
PP
776 }
777
5152f6df
MJ
778#undef _ctf_unused
779#define _ctf_unused(_src)
1c324e59 780
c785c634
MD
781#undef _ctf_enum
782#define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
783 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
784
1c324e59
MD
785/* Beware: this get len actually consumes the len value */
786#undef __get_dynamic_len
d71b57b9 787#define __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 */
800#undef _TP_SESSION_CHECK
801#ifdef TP_SESSION_CHECK
802#define _TP_SESSION_CHECK(session, csession) (session == csession)
803#else /* TP_SESSION_CHECK */
804#define _TP_SESSION_CHECK(session, csession) 1
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 */
5dadb547
MD
813#undef _TP_IP_PARAM
814#ifdef TP_IP_PARAM
e1d09f9e 815#define _TP_IP_PARAM(x) (x)
5dadb547 816#else /* TP_IP_PARAM */
97904b41 817
2eba8e39 818#if defined(LTTNG_UST_ARCH_PPC) && !defined(LTTNG_UST_ARCH_PPC64)
97904b41 819#define _TP_IP_PARAM(x) NULL
2eba8e39 820#else
e1d09f9e 821#define _TP_IP_PARAM(x) __builtin_return_address(0)
2eba8e39 822#endif
97904b41 823
5dadb547
MD
824#endif /* TP_IP_PARAM */
825
1ddfd641
MD
826/*
827 * Using twice size for filter stack data to hold size and pointer for
828 * each field (worse case). For integers, max size required is 64-bit.
829 * Same for double-precision floats. Those fit within
830 * 2*sizeof(unsigned long) for all supported architectures.
61ce3223 831 * Perform UNION (||) of filter runtime list.
1ddfd641 832 */
7f2f82c3
MJ
833#undef LTTNG_UST__TRACEPOINT_EVENT_CLASS
834#define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
106ff4da 835static \
6eddcb06 836void __event_probe__##_provider##___##_name(LTTNG_UST__TP_ARGS_DATA_PROTO(_args)) \
106ff4da 837 lttng_ust_notrace; \
a8909ba5 838static \
6eddcb06 839void __event_probe__##_provider##___##_name(LTTNG_UST__TP_ARGS_DATA_PROTO(_args)) \
1c324e59 840{ \
ba99fbe2 841 struct lttng_ust_event_common *__event = (struct lttng_ust_event_common *) __tp_data; \
1c324e59 842 size_t __dynamic_len_idx = 0; \
75026e9f 843 const size_t __num_fields = _TP_ARRAY_SIZE(__event_fields___##_provider##___##_name) - 1; \
d71b57b9 844 union { \
75026e9f 845 size_t __dynamic_len[__num_fields]; \
ba99fbe2 846 char __interpreter_stack_data[2 * sizeof(unsigned long) * __num_fields]; \
d71b57b9 847 } __stackvar; \
1c324e59 848 int __ret; \
a2e4d05e 849 bool __interpreter_stack_prepared = false; \
1c324e59
MD
850 \
851 if (0) \
852 (void) __dynamic_len_idx; /* don't warn if unused */ \
ba99fbe2
MD
853 switch (__event->type) { \
854 case LTTNG_UST_EVENT_TYPE_RECORDER: \
855 { \
856 struct lttng_ust_event_recorder *__event_recorder = (struct lttng_ust_event_recorder *) __event->child; \
e7bc0ef6
MD
857 struct lttng_ust_channel_buffer *__chan = __event_recorder->chan; \
858 struct lttng_ust_channel_common *__chan_common = __chan->parent; \
ba99fbe2 859 \
e7bc0ef6 860 if (!_TP_SESSION_CHECK(session, __chan_common->session)) \
ba99fbe2 861 return; \
e7bc0ef6 862 if (caa_unlikely(!CMM_ACCESS_ONCE(__chan_common->session->active))) \
ba99fbe2 863 return; \
e7bc0ef6 864 if (caa_unlikely(!CMM_ACCESS_ONCE(__chan_common->enabled))) \
ba99fbe2
MD
865 return; \
866 break; \
867 } \
868 case LTTNG_UST_EVENT_TYPE_NOTIFIER: \
869 break; \
870 } \
871 if (caa_unlikely(!CMM_ACCESS_ONCE(__event->enabled))) \
1c324e59 872 return; \
1b436e01
MD
873 if (caa_unlikely(!TP_RCU_LINK_TEST())) \
874 return; \
a2e4d05e 875 if (caa_unlikely(CMM_ACCESS_ONCE(__event->eval_filter))) { \
ba99fbe2 876 __event_prepare_interpreter_stack__##_provider##___##_name(__stackvar.__interpreter_stack_data, \
6eddcb06 877 LTTNG_UST__TP_ARGS_DATA_VAR(_args)); \
a2e4d05e
MD
878 __interpreter_stack_prepared = true; \
879 if (caa_likely(__event->run_filter(__event, \
880 __stackvar.__interpreter_stack_data, NULL) != LTTNG_UST_EVENT_FILTER_ACCEPT)) \
61ce3223 881 return; \
1ddfd641 882 } \
ba99fbe2
MD
883 switch (__event->type) { \
884 case LTTNG_UST_EVENT_TYPE_RECORDER: \
885 { \
886 size_t __event_len, __event_align; \
887 struct lttng_ust_event_recorder *__event_recorder = (struct lttng_ust_event_recorder *) __event->child; \
e7bc0ef6 888 struct lttng_ust_channel_buffer *__chan = __event_recorder->chan; \
b5457df5 889 struct lttng_ust_ring_buffer_ctx __ctx; \
ba99fbe2
MD
890 \
891 __event_len = __event_get_size__##_provider##___##_name(__stackvar.__dynamic_len, \
6eddcb06
MJ
892 LTTNG_UST__TP_ARGS_DATA_VAR(_args)); \
893 __event_align = __event_get_align__##_provider##___##_name(LTTNG_UST__TP_ARGS_VAR(_args)); \
b5457df5 894 lttng_ust_ring_buffer_ctx_init(&__ctx, __event_recorder, __event_len, __event_align, \
8936b6c0
MD
895 _TP_IP_PARAM(TP_IP_PARAM)); \
896 __ret = __chan->ops->event_reserve(&__ctx); \
ba99fbe2
MD
897 if (__ret < 0) \
898 return; \
899 _fields \
900 __chan->ops->event_commit(&__ctx); \
901 break; \
902 } \
903 case LTTNG_UST_EVENT_TYPE_NOTIFIER: \
904 { \
905 struct lttng_ust_event_notifier *__event_notifier = (struct lttng_ust_event_notifier *) __event->child; \
a2e4d05e
MD
906 struct lttng_ust_notification_ctx __notif_ctx; \
907 \
908 __notif_ctx.struct_size = sizeof(struct lttng_ust_notification_ctx); \
909 __notif_ctx.eval_capture = CMM_ACCESS_ONCE(__event_notifier->eval_capture); \
ba99fbe2 910 \
a2e4d05e 911 if (caa_unlikely(!__interpreter_stack_prepared && __notif_ctx.eval_capture)) \
ba99fbe2 912 __event_prepare_interpreter_stack__##_provider##___##_name(__stackvar.__interpreter_stack_data, \
6eddcb06 913 LTTNG_UST__TP_ARGS_DATA_VAR(_args)); \
ba99fbe2
MD
914 \
915 __event_notifier->notification_send(__event_notifier, \
a2e4d05e
MD
916 __stackvar.__interpreter_stack_data, \
917 &__notif_ctx); \
ba99fbe2
MD
918 break; \
919 } \
920 } \
1c324e59
MD
921}
922
bb71a8ea 923#include LTTNG_UST_TRACEPOINT_INCLUDE
1c324e59
MD
924
925#undef __get_dynamic_len
926
68755429
MD
927/*
928 * Stage 5.1 of tracepoint event generation.
929 *
930 * Create probe signature
931 */
932
7f2f82c3 933/* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
68755429
MD
934#include <lttng/ust-tracepoint-event-reset.h>
935
cadfcbfc
MJ
936#undef LTTNG_UST_TP_ARGS
937#define LTTNG_UST_TP_ARGS(...) __VA_ARGS__
9eb06182
MD
938
939#define _TP_EXTRACT_STRING2(...) #__VA_ARGS__
68755429 940
7f2f82c3
MJ
941#undef LTTNG_UST__TRACEPOINT_EVENT_CLASS
942#define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
ff82b7c1 943static const char __tp_event_signature___##_provider##___##_name[] = \
9eb06182 944 _TP_EXTRACT_STRING2(_args);
68755429 945
bb71a8ea 946#include LTTNG_UST_TRACEPOINT_INCLUDE
68755429 947
9eb06182
MD
948#undef _TP_EXTRACT_STRING2
949
05ceaafd 950/*
882a56d7 951 * Stage 6 of tracepoint event generation.
1c324e59 952 *
df854e41
MD
953 * Tracepoint loglevel mapping definition generation. We generate a
954 * symbol for each mapping for a provider/event to ensure at most a 1 to
955 * 1 mapping between events and loglevels. If the symbol is repeated,
956 * the compiler will complain.
05ceaafd
MD
957 */
958
7f2f82c3 959/* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
05ceaafd
MD
960#include <lttng/ust-tracepoint-event-reset.h>
961
4ea4f80e
MD
962/*
963 * Declare _loglevel___##__provider##___##__name as non-static, with
964 * hidden visibility for c++ handling of weakref. We do a weakref to the
965 * symbol in a later stage, which requires that the symbol is not
966 * mangled.
967 */
968#ifdef __cplusplus
fc6d7bef 969#define LTTNG_UST_TP_EXTERN_C extern "C"
4ea4f80e 970#else
fc6d7bef 971#define LTTNG_UST_TP_EXTERN_C
4ea4f80e
MD
972#endif
973
612e9ce4
MJ
974#undef LTTNG_UST_TRACEPOINT_LOGLEVEL
975#define LTTNG_UST_TRACEPOINT_LOGLEVEL(__provider, __name, __loglevel) \
3d33ca1d
MD
976static const int _loglevel_value___##__provider##___##__name = __loglevel; \
977LTTNG_UST_TP_EXTERN_C const int * const _loglevel___##__provider##___##__name \
978 __attribute__((visibility("hidden"))) = \
457a6b58 979 &_loglevel_value___##__provider##___##__name;
df854e41 980
bb71a8ea 981#include LTTNG_UST_TRACEPOINT_INCLUDE
df854e41 982
fc6d7bef 983#undef LTTNG_UST_TP_EXTERN_C
4ea4f80e 984
6ddc916d
MD
985/*
986 * Stage 6.1 of tracepoint event generation.
987 *
988 * Tracepoint UML URI info.
989 */
990
7f2f82c3 991/* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
6ddc916d
MD
992#include <lttng/ust-tracepoint-event-reset.h>
993
4ea4f80e
MD
994/*
995 * Declare _model_emf_uri___##__provider##___##__name as non-static,
996 * with hidden visibility for c++ handling of weakref. We do a weakref
997 * to the symbol in a later stage, which requires that the symbol is not
998 * mangled.
999 */
1000#ifdef __cplusplus
fc6d7bef 1001#define LTTNG_UST_TP_EXTERN_C extern "C"
4ea4f80e 1002#else
fc6d7bef 1003#define LTTNG_UST_TP_EXTERN_C
4ea4f80e
MD
1004#endif
1005
dbcc2f92
MJ
1006#undef LTTNG_UST_TRACEPOINT_MODEL_EMF_URI
1007#define LTTNG_UST_TRACEPOINT_MODEL_EMF_URI(__provider, __name, __uri) \
3d33ca1d 1008LTTNG_UST_TP_EXTERN_C const char * const _model_emf_uri___##__provider##___##__name \
082802f9 1009 __attribute__((visibility("hidden"))) = __uri; \
6ddc916d 1010
bb71a8ea 1011#include LTTNG_UST_TRACEPOINT_INCLUDE
6ddc916d 1012
fc6d7bef 1013#undef LTTNG_UST_TP_EXTERN_C
4ea4f80e 1014
5b4c6da4
MD
1015/*
1016 * Stage 7.0 of tracepoint event generation.
1017 *
1018 * Declare toplevel descriptor for the whole probe.
1019 * Unlike C, C++ does not allow tentative definitions. Therefore, we
1020 * need to explicitly declare the variable with "extern", using hidden
1021 * visibility to keep this symbol from being exported to the global
1022 * symbol table.
1023 */
1024
aec5037b 1025extern const struct lttng_ust_probe_desc LTTNG_UST__TP_COMBINE_TOKENS(__probe_desc___, TRACEPOINT_PROVIDER)
5b4c6da4
MD
1026 __attribute__((visibility("hidden")));
1027
df854e41 1028/*
882a56d7 1029 * Stage 7.1 of tracepoint event generation.
df854e41
MD
1030 *
1031 * Create events description structures. We use a weakref because
3d33ca1d 1032 * loglevels are optional. If not declared, the event will point to
df854e41 1033 * a loglevel that contains NULL.
3d33ca1d
MD
1034 *
1035 * C++ requires that const objects have a user-declared default
1036 * constructor. However, in both C++ and C, weakref cannot be
1037 * initialized because it causes the weakref attribute to be ignored.
1038 * Therefore, the loglevel and model_emf_uri pointers are not const
1039 * to ensure C++ compilers default-initialize them.
df854e41
MD
1040 */
1041
7f2f82c3 1042/* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
df854e41
MD
1043#include <lttng/ust-tracepoint-event-reset.h>
1044
7f2f82c3
MJ
1045#undef LTTNG_UST__TRACEPOINT_EVENT_INSTANCE
1046#define LTTNG_UST__TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
882a56d7
MD
1047static const int * \
1048 __ref_loglevel___##_provider##___##_name \
1049 __attribute__((weakref ("_loglevel___" #_provider "___" #_name))); \
6ddc916d
MD
1050static const char * \
1051 __ref_model_emf_uri___##_provider##___##_name \
1052 __attribute__((weakref ("_model_emf_uri___" #_provider "___" #_name)));\
4e48b5d2 1053static const struct lttng_ust_event_desc __event_desc___##_provider##_##_name = { \
dc11f93f 1054 .struct_size = sizeof(struct lttng_ust_event_desc), \
5b4c6da4
MD
1055 .event_name = #_name, \
1056 .probe_desc = &__probe_desc___##_provider, \
dc11f93f 1057 .probe_callback = (void (*)(void)) &__event_probe__##_provider##___##_template, \
46d52200 1058 .fields = __event_fields___##_provider##___##_template, \
1c80c909 1059 .nr_fields = _TP_ARRAY_SIZE(__event_fields___##_provider##___##_template) - 1, \
882a56d7 1060 .loglevel = &__ref_loglevel___##_provider##___##_name, \
68755429 1061 .signature = __tp_event_signature___##_provider##___##_template, \
dc11f93f 1062 .model_emf_uri = &__ref_model_emf_uri___##_provider##___##_name, \
df854e41
MD
1063};
1064
bb71a8ea 1065#include LTTNG_UST_TRACEPOINT_INCLUDE
05ceaafd 1066
df854e41 1067/*
882a56d7 1068 * Stage 7.2 of tracepoint event generation.
df854e41
MD
1069 *
1070 * Create array of events.
1071 */
1072
7f2f82c3 1073/* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
df854e41
MD
1074#include <lttng/ust-tracepoint-event-reset.h>
1075
7f2f82c3
MJ
1076#undef LTTNG_UST__TRACEPOINT_EVENT_INSTANCE
1077#define LTTNG_UST__TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
df854e41
MD
1078 &__event_desc___##_provider##_##_name,
1079
aec5037b 1080static const struct lttng_ust_event_desc * const LTTNG_UST__TP_COMBINE_TOKENS(__event_desc___, TRACEPOINT_PROVIDER)[] = {
bb71a8ea 1081#include LTTNG_UST_TRACEPOINT_INCLUDE
1c80c909 1082 NULL, /* Dummy, C99 forbids 0-len array. */
05ceaafd
MD
1083};
1084
df854e41 1085
05ceaafd 1086/*
882a56d7 1087 * Stage 8 of tracepoint event generation.
05ceaafd
MD
1088 *
1089 * Create a toplevel descriptor for the whole probe.
1090 */
1091
aec5037b 1092const struct lttng_ust_probe_desc LTTNG_UST__TP_COMBINE_TOKENS(__probe_desc___, TRACEPOINT_PROVIDER) = {
dc11f93f 1093 .struct_size = sizeof(struct lttng_ust_probe_desc),
5b4c6da4 1094 .provider_name = __tp_stringify(TRACEPOINT_PROVIDER),
aec5037b
MJ
1095 .event_desc = LTTNG_UST__TP_COMBINE_TOKENS(__event_desc___, TRACEPOINT_PROVIDER),
1096 .nr_events = _TP_ARRAY_SIZE(LTTNG_UST__TP_COMBINE_TOKENS(__event_desc___, TRACEPOINT_PROVIDER)) - 1,
71d31690
MD
1097 .major = LTTNG_UST_PROVIDER_MAJOR,
1098 .minor = LTTNG_UST_PROVIDER_MINOR,
05ceaafd
MD
1099};
1100
aec5037b
MJ
1101static int LTTNG_UST__TP_COMBINE_TOKENS(__probe_register_refcount___, TRACEPOINT_PROVIDER);
1102static struct lttng_ust_registered_probe *LTTNG_UST__TP_COMBINE_TOKENS(__lttng_ust_probe_register_cookie___, TRACEPOINT_PROVIDER);
f0cc794d 1103
05ceaafd 1104/*
882a56d7 1105 * Stage 9 of tracepoint event generation.
05ceaafd 1106 *
1c324e59 1107 * Register/unregister probes at module load/unload.
628e1d81
MD
1108 *
1109 * Generate the constructor as an externally visible symbol for use when
1110 * linking the probe statically.
f0cc794d
MD
1111 *
1112 * Register refcount is protected by libc dynamic loader mutex.
1c324e59
MD
1113 */
1114
7f2f82c3 1115/* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
1c324e59 1116#include <lttng/ust-tracepoint-event-reset.h>
465a0d04 1117static void
aec5037b 1118LTTNG_UST__TP_COMBINE_TOKENS(__lttng_ust_events_init__, TRACEPOINT_PROVIDER)(void)
465a0d04 1119 lttng_ust_notrace __attribute__((constructor));
a8909ba5 1120static void
aec5037b 1121LTTNG_UST__TP_COMBINE_TOKENS(__lttng_ust_events_init__, TRACEPOINT_PROVIDER)(void)
1c324e59 1122{
4e48b5d2 1123 struct lttng_ust_registered_probe *reg_probe;
1c324e59 1124
aec5037b 1125 if (LTTNG_UST__TP_COMBINE_TOKENS(__probe_register_refcount___,
f0cc794d
MD
1126 TRACEPOINT_PROVIDER)++) {
1127 return;
1128 }
e8bd1da7 1129 /*
0274f7f2 1130 * lttng_ust_tracepoint_provider_check_ ## TRACEPOINT_PROVIDER() is a
e8bd1da7
MD
1131 * static inline function that ensures every probe PROVIDER
1132 * argument match the provider within which they appear. It
1133 * calls empty static inline functions, and therefore has no
1134 * runtime effect. However, if it detects an error, a linker
1135 * error will appear.
1136 */
aec5037b
MJ
1137 LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust_tracepoint_provider_check_, TRACEPOINT_PROVIDER)();
1138 assert(!LTTNG_UST__TP_COMBINE_TOKENS(__lttng_ust_probe_register_cookie___, TRACEPOINT_PROVIDER));
1139 reg_probe = lttng_ust_probe_register(&LTTNG_UST__TP_COMBINE_TOKENS(__probe_desc___, TRACEPOINT_PROVIDER));
4e48b5d2
MD
1140 if (!reg_probe) {
1141 fprintf(stderr, "LTTng-UST: Error while registering tracepoint probe.\n");
7d381d6e
MD
1142 abort();
1143 }
aec5037b 1144 LTTNG_UST__TP_COMBINE_TOKENS(__lttng_ust_probe_register_cookie___, TRACEPOINT_PROVIDER) = reg_probe;
1c324e59
MD
1145}
1146
c589eca2 1147static void
aec5037b 1148LTTNG_UST__TP_COMBINE_TOKENS(__lttng_ust_events_exit__, TRACEPOINT_PROVIDER)(void)
c589eca2 1149 lttng_ust_notrace __attribute__((destructor));
a8909ba5 1150static void
aec5037b 1151LTTNG_UST__TP_COMBINE_TOKENS(__lttng_ust_events_exit__, TRACEPOINT_PROVIDER)(void)
1c324e59 1152{
aec5037b 1153 if (--LTTNG_UST__TP_COMBINE_TOKENS(__probe_register_refcount___,
f0cc794d
MD
1154 TRACEPOINT_PROVIDER)) {
1155 return;
1156 }
aec5037b
MJ
1157 lttng_ust_probe_unregister(LTTNG_UST__TP_COMBINE_TOKENS(__lttng_ust_probe_register_cookie___, TRACEPOINT_PROVIDER));
1158 LTTNG_UST__TP_COMBINE_TOKENS(__lttng_ust_probe_register_cookie___, TRACEPOINT_PROVIDER) = NULL;
1c324e59 1159}
628e1d81 1160
aec5037b 1161int LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust_tracepoint_provider_, TRACEPOINT_PROVIDER)
1d18d519 1162 __attribute__((visibility("default")));
This page took 0.132967 seconds and 4 git commands to generate.