Remove runtime dependency on liburcu shared objects
[lttng-ust.git] / include / lttng / ust-tracepoint-event.h
CommitLineData
1c324e59 1/*
e92f3e28 2 * Copyright (c) 2011-2012 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
1c324e59 3 *
e92f3e28
MD
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
1c324e59 10 *
e92f3e28
MD
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
d2428e87
MD
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
1c324e59
MD
21 */
22
fb31eb73 23#include <stdint.h>
1c324e59 24#include <stdio.h>
7d381d6e 25#include <stdlib.h>
1c324e59 26#include <urcu/compiler.h>
f488575f 27#include <urcu/rculist.h>
1c324e59 28#include <lttng/ust-events.h>
1c324e59 29#include <lttng/ringbuffer-config.h>
a8909ba5 30#include <lttng/ust-compiler.h>
000b8662 31#include <lttng/tracepoint.h>
3208818b 32#include <lttng/ust-endian.h>
44c72f10 33#include <string.h>
1c324e59 34
24a39530
PP
35#define __LTTNG_UST_NULL_STRING "(null)"
36
000b8662
MD
37#undef tp_list_for_each_entry_rcu
38#define tp_list_for_each_entry_rcu(pos, head, member) \
10544ee8 39 for (pos = cds_list_entry(tp_rcu_dereference((head)->next), __typeof__(*pos), member); \
000b8662 40 &pos->member != (head); \
10544ee8 41 pos = cds_list_entry(tp_rcu_dereference(pos->member.next), __typeof__(*pos), member))
000b8662 42
1c324e59
MD
43/*
44 * TRACEPOINT_EVENT_CLASS declares a class of tracepoints receiving the
45 * same arguments and having the same field layout.
46 *
47 * TRACEPOINT_EVENT_INSTANCE declares an instance of a tracepoint, with
48 * its own provider and name. It refers to a class (template).
49 *
50 * TRACEPOINT_EVENT declared both a class and an instance and does a
51 * direct mapping from the instance to the class.
52 */
53
54#undef TRACEPOINT_EVENT
55#define TRACEPOINT_EVENT(_provider, _name, _args, _fields) \
56 TRACEPOINT_EVENT_CLASS(_provider, _name, \
57 _TP_PARAMS(_args), \
58 _TP_PARAMS(_fields)) \
59 TRACEPOINT_EVENT_INSTANCE(_provider, _name, _name, \
68755429 60 _TP_PARAMS(_args))
1c324e59
MD
61
62/* Helpers */
63#define _TP_ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
64
65#define _tp_max_t(type, x, y) \
66 ({ \
67 type __max1 = (x); \
68 type __max2 = (y); \
69 __max1 > __max2 ? __max1: __max2; \
70 })
71
72/*
73 * Stage 0 of tracepoint event generation.
74 *
75 * Check that each TRACEPOINT_EVENT provider argument match the
76 * TRACEPOINT_PROVIDER by creating dummy callbacks.
77 */
78
79/* Reset all macros within TRACEPOINT_EVENT */
80#include <lttng/ust-tracepoint-event-reset.h>
81
7ce6b21d
PW
82static inline lttng_ust_notrace
83void _TP_COMBINE_TOKENS(__tracepoint_provider_mismatch_, TRACEPOINT_PROVIDER)(void);
1c324e59
MD
84static inline
85void _TP_COMBINE_TOKENS(__tracepoint_provider_mismatch_, TRACEPOINT_PROVIDER)(void)
86{
87}
88
89#undef TRACEPOINT_EVENT_CLASS
90#define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
91 __tracepoint_provider_mismatch_##_provider();
92
93#undef TRACEPOINT_EVENT_INSTANCE
94#define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
95 __tracepoint_provider_mismatch_##_provider();
96
7ce6b21d
PW
97static inline lttng_ust_notrace
98void _TP_COMBINE_TOKENS(__tracepoint_provider_check_, TRACEPOINT_PROVIDER)(void);
e8bd1da7 99static inline
1c324e59
MD
100void _TP_COMBINE_TOKENS(__tracepoint_provider_check_, TRACEPOINT_PROVIDER)(void)
101{
102#include TRACEPOINT_INCLUDE
103}
104
f56cd1d5
MD
105/*
106 * Stage 0.1 of tracepoint event generation.
107 *
108 * Check that each TRACEPOINT_EVENT provider:name does not exceed the
109 * tracepoint name length limit.
110 */
111
112/* Reset all macros within TRACEPOINT_EVENT */
113#include <lttng/ust-tracepoint-event-reset.h>
114
115#undef TRACEPOINT_EVENT_INSTANCE
116#define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
117static const char \
118 __tp_name_len_check##_provider##___##_name[LTTNG_UST_SYM_NAME_LEN] \
119 __attribute__((unused)) = \
120 #_provider ":" #_name;
121
122#include TRACEPOINT_INCLUDE
123
c75c0422
MD
124/*
125 * Stage 0.2 of tracepoint event generation.
126 *
127 * Create dummy trace prototypes for each event class, and for each used
128 * template. This will allow checking whether the prototypes from the
129 * class and the instance using the class actually match.
130 */
131
132/* Reset all macros within TRACEPOINT_EVENT */
133#include <lttng/ust-tracepoint-event-reset.h>
134
135#undef TP_ARGS
136#define TP_ARGS(...) __VA_ARGS__
137
138#undef TRACEPOINT_EVENT_INSTANCE
139#define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
140void __event_template_proto___##_provider##___##_template(_TP_ARGS_DATA_PROTO(_args));
141
142#undef TRACEPOINT_EVENT_CLASS
143#define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
144void __event_template_proto___##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args));
145
146#include TRACEPOINT_INCLUDE
147
c785c634
MD
148/*
149 * Stage 0.9 of tracepoint event generation
150 *
151 * Unfolding the enums
152 */
153#include <lttng/ust-tracepoint-event-reset.h>
154
155/* Enumeration entry (single value) */
156#undef ctf_enum_value
157#define ctf_enum_value(_string, _value) \
a6f80644
MD
158 { \
159 .start = { \
a6f80644
MD
160 .value = lttng_is_signed_type(__typeof__(_value)) ? \
161 (long long) (_value) : (_value), \
2c3f4c28 162 .signedness = lttng_is_signed_type(__typeof__(_value)), \
a6f80644
MD
163 }, \
164 .end = { \
a6f80644
MD
165 .value = lttng_is_signed_type(__typeof__(_value)) ? \
166 (long long) (_value) : (_value), \
2c3f4c28 167 .signedness = lttng_is_signed_type(__typeof__(_value)), \
a6f80644
MD
168 }, \
169 .string = (_string), \
170 },
c785c634
MD
171
172/* Enumeration entry (range) */
173#undef ctf_enum_range
174#define ctf_enum_range(_string, _range_start, _range_end) \
a6f80644
MD
175 { \
176 .start = { \
a6f80644
MD
177 .value = lttng_is_signed_type(__typeof__(_range_start)) ? \
178 (long long) (_range_start) : (_range_start), \
2c3f4c28 179 .signedness = lttng_is_signed_type(__typeof__(_range_start)), \
a6f80644
MD
180 }, \
181 .end = { \
a6f80644
MD
182 .value = lttng_is_signed_type(__typeof__(_range_end)) ? \
183 (long long) (_range_end) : (_range_end), \
2c3f4c28 184 .signedness = lttng_is_signed_type(__typeof__(_range_end)), \
a6f80644
MD
185 }, \
186 .string = (_string), \
187 },
c785c634 188
3e762260
PP
189/* Enumeration entry (automatic value; follows the rules of CTF) */
190#undef ctf_enum_auto
191#define ctf_enum_auto(_string) \
192 { \
193 .start = { \
194 .value = -1ULL, \
195 .signedness = 0, \
196 }, \
197 .end = { \
198 .value = -1ULL, \
199 .signedness = 0, \
200 }, \
201 .string = (_string), \
202 .u = { \
203 .extra = { \
204 .options = LTTNG_ENUM_ENTRY_OPTION_IS_AUTO, \
205 }, \
206 }, \
207 },
208
c785c634
MD
209#undef TP_ENUM_VALUES
210#define TP_ENUM_VALUES(...) \
211 __VA_ARGS__
212
213#undef TRACEPOINT_ENUM
214#define TRACEPOINT_ENUM(_provider, _name, _values) \
215 const struct lttng_enum_entry __enum_values__##_provider##_##_name[] = { \
216 _values \
1c80c909 217 ctf_enum_value("", 0) /* Dummy, 0-len array forbidden by C99. */ \
c785c634 218 };
2df82195
FD
219#include TRACEPOINT_INCLUDE
220
221/*
222 * Stage 0.9.1
223 * Verifying array and sequence elements are of an integer type.
224 */
225
226/* Reset all macros within TRACEPOINT_EVENT */
227#include <lttng/ust-tracepoint-event-reset.h>
228#include <lttng/ust-tracepoint-event-write.h>
229#include <lttng/ust-tracepoint-event-nowrite.h>
230
231#undef _ctf_array_encoded
232#define _ctf_array_encoded(_type, _item, _src, _byte_order, \
233 _length, _encoding, _nowrite, \
234 _elem_type_base) \
235 _lttng_array_element_type_is_supported(_type, _item)
236
237#undef _ctf_sequence_encoded
238#define _ctf_sequence_encoded(_type, _item, _src, _byte_order, \
239 _length_type, _src_length, _encoding, _nowrite, \
240 _elem_type_base) \
241 _lttng_array_element_type_is_supported(_type, _item)
242
243#undef TP_FIELDS
244#define TP_FIELDS(...) __VA_ARGS__ /* Only one used in this phase */
245
246#undef TRACEPOINT_EVENT_CLASS
247#define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
248 _fields
c785c634
MD
249
250#include TRACEPOINT_INCLUDE
251
1c324e59
MD
252/*
253 * Stage 1 of tracepoint event generation.
254 *
255 * Create event field type metadata section.
256 * Each event produce an array of fields.
257 */
258
259/* Reset all macros within TRACEPOINT_EVENT */
260#include <lttng/ust-tracepoint-event-reset.h>
4774c8f3
MD
261#include <lttng/ust-tracepoint-event-write.h>
262#include <lttng/ust-tracepoint-event-nowrite.h>
1c324e59 263
4774c8f3 264#undef _ctf_integer_ext
180901e6 265#define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
1c324e59
MD
266 { \
267 .name = #_item, \
268 .type = __type_integer(_type, _byte_order, _base, none),\
180901e6 269 .nowrite = _nowrite, \
218deb69
MD
270 .u = { \
271 .ext = { \
272 .nofilter = 0, \
273 }, \
274 }, \
1c324e59
MD
275 },
276
4774c8f3 277#undef _ctf_float
180901e6 278#define _ctf_float(_type, _item, _src, _nowrite) \
1c324e59
MD
279 { \
280 .name = #_item, \
281 .type = __type_float(_type), \
180901e6 282 .nowrite = _nowrite, \
218deb69
MD
283 .u = { \
284 .ext = { \
285 .nofilter = 0, \
286 }, \
287 }, \
1c324e59
MD
288 },
289
4774c8f3 290#undef _ctf_array_encoded
f3ec4cb5
MD
291#define _ctf_array_encoded(_type, _item, _src, _byte_order, \
292 _length, _encoding, _nowrite, \
293 _elem_type_base) \
1c324e59
MD
294 { \
295 .name = #_item, \
296 .type = \
297 { \
218deb69 298 .atype = atype_array_nestable, \
46d52200 299 .u = \
1c324e59 300 { \
218deb69 301 .array_nestable = \
46d52200 302 { \
218deb69
MD
303 .elem_type = __LTTNG_COMPOUND_LITERAL(struct lttng_type, \
304 __type_integer(_type, _byte_order, _elem_type_base, _encoding)), \
46d52200 305 .length = _length, \
218deb69 306 .alignment = 0, \
46d52200
ZT
307 } \
308 } \
1c324e59 309 }, \
180901e6 310 .nowrite = _nowrite, \
218deb69
MD
311 .u = { \
312 .ext = { \
313 .nofilter = 0, \
314 }, \
315 }, \
1c324e59
MD
316 },
317
4774c8f3 318#undef _ctf_sequence_encoded
48d660d1 319#define _ctf_sequence_encoded(_type, _item, _src, _byte_order, \
f968510a
PP
320 _length_type, _src_length, _encoding, _nowrite, \
321 _elem_type_base) \
218deb69
MD
322 { \
323 .name = "_" #_item "_length", \
324 .type = __type_integer(_length_type, BYTE_ORDER, 10, none), \
325 .nowrite = _nowrite, \
326 .u = { \
327 .ext = { \
328 .nofilter = 1, \
329 }, \
330 }, \
331 }, \
1c324e59
MD
332 { \
333 .name = #_item, \
334 .type = \
335 { \
218deb69 336 .atype = atype_sequence_nestable, \
46d52200 337 .u = \
1c324e59 338 { \
218deb69 339 .sequence_nestable = \
46d52200 340 { \
218deb69
MD
341 .length_name = "_" #_item "_length", \
342 .elem_type = __LTTNG_COMPOUND_LITERAL(struct lttng_type, \
343 __type_integer(_type, _byte_order, _elem_type_base, _encoding)), \
344 .alignment = 0, \
46d52200 345 }, \
1c324e59
MD
346 }, \
347 }, \
180901e6 348 .nowrite = _nowrite, \
218deb69
MD
349 .u = { \
350 .ext = { \
351 .nofilter = 0, \
352 }, \
353 }, \
1c324e59
MD
354 },
355
4774c8f3 356#undef _ctf_string
180901e6 357#define _ctf_string(_item, _src, _nowrite) \
1c324e59
MD
358 { \
359 .name = #_item, \
360 .type = \
361 { \
362 .atype = atype_string, \
46d52200
ZT
363 .u = \
364 { \
218deb69 365 .string = { .encoding = lttng_encode_UTF8 } \
46d52200 366 }, \
1c324e59 367 }, \
180901e6 368 .nowrite = _nowrite, \
218deb69
MD
369 .u = { \
370 .ext = { \
371 .nofilter = 0, \
372 }, \
373 }, \
1c324e59
MD
374 },
375
c785c634
MD
376#undef _ctf_enum
377#define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
378 { \
379 .name = #_item, \
380 .type = { \
218deb69 381 .atype = atype_enum_nestable, \
c785c634 382 .u = { \
218deb69
MD
383 .enum_nestable = { \
384 .desc = &__enum_##_provider##_##_name, \
385 .container_type = __LTTNG_COMPOUND_LITERAL(struct lttng_type, \
386 __type_integer(_type, BYTE_ORDER, 10, none)), \
387 }, \
c785c634
MD
388 }, \
389 }, \
390 .nowrite = _nowrite, \
218deb69
MD
391 .u = { \
392 .ext = { \
393 .nofilter = 0, \
394 }, \
395 }, \
c785c634
MD
396 },
397
1c324e59 398#undef TP_FIELDS
2eda209b 399#define TP_FIELDS(...) __VA_ARGS__ /* Only one used in this phase */
1c324e59
MD
400
401#undef TRACEPOINT_EVENT_CLASS
402#define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
403 static const struct lttng_event_field __event_fields___##_provider##___##_name[] = { \
404 _fields \
1c80c909 405 ctf_integer(int, dummy, 0) /* Dummy, C99 forbids 0-len array. */ \
1c324e59
MD
406 };
407
c785c634
MD
408#undef TRACEPOINT_ENUM
409#define TRACEPOINT_ENUM(_provider, _name, _values) \
410 static const struct lttng_enum_desc __enum_##_provider##_##_name = { \
411 .name = #_provider "_" #_name, \
412 .entries = __enum_values__##_provider##_##_name, \
1c80c909 413 .nr_entries = _TP_ARRAY_SIZE(__enum_values__##_provider##_##_name) - 1, \
c785c634
MD
414 };
415
1c324e59
MD
416#include TRACEPOINT_INCLUDE
417
418/*
419 * Stage 2 of tracepoint event generation.
420 *
421 * Create probe callback prototypes.
422 */
423
424/* Reset all macros within TRACEPOINT_EVENT */
425#include <lttng/ust-tracepoint-event-reset.h>
426
427#undef TP_ARGS
2eda209b 428#define TP_ARGS(...) __VA_ARGS__
1c324e59
MD
429
430#undef TRACEPOINT_EVENT_CLASS
431#define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
432static void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args));
433
434#include TRACEPOINT_INCLUDE
435
d8d2416d
FD
436/*
437 * Stage 2.1 of tracepoint event generation.
438 *
439 * Create probe event notifier callback prototypes.
440 */
441
442/* Reset all macros within TRACEPOINT_EVENT */
443#include <lttng/ust-tracepoint-event-reset.h>
444
445#undef TP_ARGS
446#define TP_ARGS(...) __VA_ARGS__
447
448#undef TRACEPOINT_EVENT_CLASS
449#define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
450static void __event_notifier_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args));
451
452#include TRACEPOINT_INCLUDE
453
1c324e59 454/*
c785c634 455 * Stage 3.0 of tracepoint event generation.
1c324e59 456 *
1c324e59
MD
457 * Create static inline function that calculates event size.
458 */
459
460/* Reset all macros within TRACEPOINT_EVENT */
461#include <lttng/ust-tracepoint-event-reset.h>
4774c8f3 462#include <lttng/ust-tracepoint-event-write.h>
1c324e59 463
4774c8f3 464#undef _ctf_integer_ext
180901e6 465#define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
1c324e59
MD
466 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
467 __event_len += sizeof(_type);
468
4774c8f3 469#undef _ctf_float
180901e6 470#define _ctf_float(_type, _item, _src, _nowrite) \
1c324e59
MD
471 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
472 __event_len += sizeof(_type);
473
4774c8f3 474#undef _ctf_array_encoded
f3ec4cb5
MD
475#define _ctf_array_encoded(_type, _item, _src, _byte_order, _length, _encoding, \
476 _nowrite, _elem_type_base) \
1c324e59
MD
477 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
478 __event_len += sizeof(_type) * (_length);
479
4774c8f3 480#undef _ctf_sequence_encoded
48d660d1 481#define _ctf_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
f968510a 482 _src_length, _encoding, _nowrite, _elem_type_base) \
1c324e59
MD
483 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_length_type)); \
484 __event_len += sizeof(_length_type); \
485 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
486 __dynamic_len[__dynamic_len_idx] = (_src_length); \
487 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
488 __dynamic_len_idx++;
489
4774c8f3 490#undef _ctf_string
180901e6 491#define _ctf_string(_item, _src, _nowrite) \
24a39530
PP
492 __event_len += __dynamic_len[__dynamic_len_idx++] = \
493 strlen((_src) ? (_src) : __LTTNG_UST_NULL_STRING) + 1;
1c324e59 494
c785c634
MD
495#undef _ctf_enum
496#define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
497 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
498
1c324e59 499#undef TP_ARGS
2eda209b 500#define TP_ARGS(...) __VA_ARGS__
1c324e59
MD
501
502#undef TP_FIELDS
2eda209b 503#define TP_FIELDS(...) __VA_ARGS__
1c324e59
MD
504
505#undef TRACEPOINT_EVENT_CLASS
a8909ba5
PW
506#define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
507static inline lttng_ust_notrace \
508size_t __event_get_size__##_provider##___##_name(size_t *__dynamic_len, _TP_ARGS_DATA_PROTO(_args)); \
509static inline \
510size_t __event_get_size__##_provider##___##_name(size_t *__dynamic_len, _TP_ARGS_DATA_PROTO(_args)) \
1c324e59
MD
511{ \
512 size_t __event_len = 0; \
513 unsigned int __dynamic_len_idx = 0; \
514 \
515 if (0) \
516 (void) __dynamic_len_idx; /* don't warn if unused */ \
517 _fields \
518 return __event_len; \
519}
520
521#include TRACEPOINT_INCLUDE
522
1ddfd641
MD
523/*
524 * Stage 3.1 of tracepoint event generation.
525 *
526 * Create static inline function that layout the filter stack data.
4774c8f3 527 * We make both write and nowrite data available to the filter.
1ddfd641
MD
528 */
529
530/* Reset all macros within TRACEPOINT_EVENT */
531#include <lttng/ust-tracepoint-event-reset.h>
4774c8f3
MD
532#include <lttng/ust-tracepoint-event-write.h>
533#include <lttng/ust-tracepoint-event-nowrite.h>
1ddfd641 534
4774c8f3 535#undef _ctf_integer_ext
180901e6 536#define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
fa099471 537 if (lttng_is_signed_type(_type)) { \
3ebeea0d
MD
538 int64_t __ctf_tmp_int64; \
539 switch (sizeof(_type)) { \
540 case 1: \
541 { \
542 union { _type t; int8_t v; } __tmp = { (_type) (_src) }; \
543 __ctf_tmp_int64 = (int64_t) __tmp.v; \
544 break; \
545 } \
546 case 2: \
547 { \
548 union { _type t; int16_t v; } __tmp = { (_type) (_src) }; \
39ad74cf
MD
549 if (_byte_order != BYTE_ORDER) \
550 __tmp.v = bswap_16(__tmp.v); \
3ebeea0d
MD
551 __ctf_tmp_int64 = (int64_t) __tmp.v; \
552 break; \
553 } \
554 case 4: \
555 { \
556 union { _type t; int32_t v; } __tmp = { (_type) (_src) }; \
39ad74cf
MD
557 if (_byte_order != BYTE_ORDER) \
558 __tmp.v = bswap_32(__tmp.v); \
3ebeea0d
MD
559 __ctf_tmp_int64 = (int64_t) __tmp.v; \
560 break; \
561 } \
562 case 8: \
563 { \
564 union { _type t; int64_t v; } __tmp = { (_type) (_src) }; \
39ad74cf
MD
565 if (_byte_order != BYTE_ORDER) \
566 __tmp.v = bswap_64(__tmp.v); \
3ebeea0d
MD
567 __ctf_tmp_int64 = (int64_t) __tmp.v; \
568 break; \
569 } \
570 default: \
571 abort(); \
572 }; \
fa099471
MD
573 memcpy(__stack_data, &__ctf_tmp_int64, sizeof(int64_t)); \
574 } else { \
3ebeea0d
MD
575 uint64_t __ctf_tmp_uint64; \
576 switch (sizeof(_type)) { \
577 case 1: \
578 { \
579 union { _type t; uint8_t v; } __tmp = { (_type) (_src) }; \
580 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
581 break; \
582 } \
583 case 2: \
584 { \
585 union { _type t; uint16_t v; } __tmp = { (_type) (_src) }; \
39ad74cf
MD
586 if (_byte_order != BYTE_ORDER) \
587 __tmp.v = bswap_16(__tmp.v); \
3ebeea0d
MD
588 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
589 break; \
590 } \
591 case 4: \
592 { \
593 union { _type t; uint32_t v; } __tmp = { (_type) (_src) }; \
39ad74cf
MD
594 if (_byte_order != BYTE_ORDER) \
595 __tmp.v = bswap_32(__tmp.v); \
3ebeea0d
MD
596 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
597 break; \
598 } \
599 case 8: \
600 { \
601 union { _type t; uint64_t v; } __tmp = { (_type) (_src) }; \
39ad74cf
MD
602 if (_byte_order != BYTE_ORDER) \
603 __tmp.v = bswap_64(__tmp.v); \
3ebeea0d
MD
604 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
605 break; \
606 } \
607 default: \
608 abort(); \
609 }; \
fa099471
MD
610 memcpy(__stack_data, &__ctf_tmp_uint64, sizeof(uint64_t)); \
611 } \
1ddfd641
MD
612 __stack_data += sizeof(int64_t);
613
4774c8f3 614#undef _ctf_float
180901e6 615#define _ctf_float(_type, _item, _src, _nowrite) \
fa099471
MD
616 { \
617 double __ctf_tmp_double = (double) (_type) (_src); \
618 memcpy(__stack_data, &__ctf_tmp_double, sizeof(double)); \
619 __stack_data += sizeof(double); \
620 }
1ddfd641 621
4774c8f3 622#undef _ctf_array_encoded
f3ec4cb5
MD
623#define _ctf_array_encoded(_type, _item, _src, _byte_order, _length, \
624 _encoding, _nowrite, _elem_type_base) \
fa099471
MD
625 { \
626 unsigned long __ctf_tmp_ulong = (unsigned long) (_length); \
59034aab 627 const void *__ctf_tmp_ptr = (_src); \
fa099471
MD
628 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
629 __stack_data += sizeof(unsigned long); \
b1239ad6
MD
630 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
631 __stack_data += sizeof(void *); \
fa099471 632 }
1ddfd641 633
4774c8f3 634#undef _ctf_sequence_encoded
48d660d1 635#define _ctf_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
f968510a 636 _src_length, _encoding, _nowrite, _elem_type_base) \
fa099471
MD
637 { \
638 unsigned long __ctf_tmp_ulong = (unsigned long) (_src_length); \
59034aab 639 const void *__ctf_tmp_ptr = (_src); \
fa099471
MD
640 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
641 __stack_data += sizeof(unsigned long); \
b1239ad6
MD
642 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
643 __stack_data += sizeof(void *); \
fa099471 644 }
1ddfd641 645
4774c8f3 646#undef _ctf_string
180901e6 647#define _ctf_string(_item, _src, _nowrite) \
fa099471 648 { \
24a39530
PP
649 const void *__ctf_tmp_ptr = \
650 ((_src) ? (_src) : __LTTNG_UST_NULL_STRING); \
b1239ad6
MD
651 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
652 __stack_data += sizeof(void *); \
fa099471 653 }
1ddfd641 654
c785c634
MD
655#undef _ctf_enum
656#define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
657 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
658
1ddfd641
MD
659#undef TP_ARGS
660#define TP_ARGS(...) __VA_ARGS__
661
662#undef TP_FIELDS
663#define TP_FIELDS(...) __VA_ARGS__
664
665#undef TRACEPOINT_EVENT_CLASS
666#define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
667static inline \
d37ecb3f 668void __event_prepare_interpreter_stack__##_provider##___##_name(char *__stack_data,\
1ddfd641
MD
669 _TP_ARGS_DATA_PROTO(_args)) \
670{ \
671 _fields \
672}
673
674#include TRACEPOINT_INCLUDE
675
1c324e59 676/*
df854e41 677 * Stage 4 of tracepoint event generation.
1c324e59
MD
678 *
679 * Create static inline function that calculates event payload alignment.
680 */
681
682/* Reset all macros within TRACEPOINT_EVENT */
683#include <lttng/ust-tracepoint-event-reset.h>
4774c8f3 684#include <lttng/ust-tracepoint-event-write.h>
1c324e59 685
4774c8f3 686#undef _ctf_integer_ext
180901e6 687#define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
1c324e59
MD
688 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
689
4774c8f3 690#undef _ctf_float
180901e6 691#define _ctf_float(_type, _item, _src, _nowrite) \
1c324e59
MD
692 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
693
4774c8f3 694#undef _ctf_array_encoded
f3ec4cb5
MD
695#define _ctf_array_encoded(_type, _item, _src, _byte_order, _length, \
696 _encoding, _nowrite, _elem_type_base) \
1c324e59
MD
697 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
698
4774c8f3 699#undef _ctf_sequence_encoded
48d660d1 700#define _ctf_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
f968510a 701 _src_length, _encoding, _nowrite, _elem_type_base) \
1c324e59
MD
702 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_length_type)); \
703 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
704
4774c8f3 705#undef _ctf_string
180901e6 706#define _ctf_string(_item, _src, _nowrite)
1c324e59 707
c785c634
MD
708#undef _ctf_enum
709#define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
710 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
711
1c324e59 712#undef TP_ARGS
2eda209b 713#define TP_ARGS(...) __VA_ARGS__
1c324e59
MD
714
715#undef TP_FIELDS
2eda209b 716#define TP_FIELDS(...) __VA_ARGS__
1c324e59
MD
717
718#undef TRACEPOINT_EVENT_CLASS
719#define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
a8909ba5
PW
720static inline lttng_ust_notrace \
721size_t __event_get_align__##_provider##___##_name(_TP_ARGS_PROTO(_args)); \
1c324e59
MD
722static inline \
723size_t __event_get_align__##_provider##___##_name(_TP_ARGS_PROTO(_args)) \
724{ \
725 size_t __event_align = 1; \
726 _fields \
727 return __event_align; \
728}
729
730#include TRACEPOINT_INCLUDE
731
732
733/*
df854e41 734 * Stage 5 of tracepoint event generation.
1c324e59
MD
735 *
736 * Create the probe function. This function calls event size calculation
737 * and writes event data into the buffer.
738 */
739
740/* Reset all macros within TRACEPOINT_EVENT */
741#include <lttng/ust-tracepoint-event-reset.h>
4774c8f3 742#include <lttng/ust-tracepoint-event-write.h>
1c324e59 743
4774c8f3 744#undef _ctf_integer_ext
180901e6 745#define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
1c324e59
MD
746 { \
747 _type __tmp = (_src); \
748 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp));\
749 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
750 }
751
4774c8f3 752#undef _ctf_float
180901e6 753#define _ctf_float(_type, _item, _src, _nowrite) \
1c324e59
MD
754 { \
755 _type __tmp = (_src); \
756 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp));\
757 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
758 }
759
4774c8f3 760#undef _ctf_array_encoded
f3ec4cb5
MD
761#define _ctf_array_encoded(_type, _item, _src, _byte_order, _length, \
762 _encoding, _nowrite, _elem_type_base) \
1c324e59
MD
763 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
764 __chan->ops->event_write(&__ctx, _src, sizeof(_type) * (_length));
765
4774c8f3 766#undef _ctf_sequence_encoded
48d660d1 767#define _ctf_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
f968510a 768 _src_length, _encoding, _nowrite, _elem_type_base) \
1c324e59 769 { \
d71b57b9 770 _length_type __tmpl = __stackvar.__dynamic_len[__dynamic_len_idx]; \
1c324e59
MD
771 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_length_type));\
772 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(_length_type));\
773 } \
774 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
775 __chan->ops->event_write(&__ctx, _src, \
776 sizeof(_type) * __get_dynamic_len(dest));
777
4774c8f3 778#undef _ctf_string
180901e6 779#define _ctf_string(_item, _src, _nowrite) \
24a39530
PP
780 { \
781 const char *__ctf_tmp_string = \
782 ((_src) ? (_src) : __LTTNG_UST_NULL_STRING); \
783 lib_ring_buffer_align_ctx(&__ctx, \
784 lttng_alignof(*__ctf_tmp_string)); \
f9ec4a97
MD
785 __chan->ops->event_strcpy(&__ctx, __ctf_tmp_string, \
786 __get_dynamic_len(dest)); \
24a39530
PP
787 }
788
1c324e59 789
c785c634
MD
790#undef _ctf_enum
791#define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
792 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
793
1c324e59
MD
794/* Beware: this get len actually consumes the len value */
795#undef __get_dynamic_len
d71b57b9 796#define __get_dynamic_len(field) __stackvar.__dynamic_len[__dynamic_len_idx++]
1c324e59
MD
797
798#undef TP_ARGS
2eda209b 799#define TP_ARGS(...) __VA_ARGS__
1c324e59
MD
800
801#undef TP_FIELDS
2eda209b 802#define TP_FIELDS(...) __VA_ARGS__
1c324e59 803
95c25348
PW
804/*
805 * For state dump, check that "session" argument (mandatory) matches the
806 * session this event belongs to. Ensures that we write state dump data only
807 * into the started session, not into all sessions.
808 */
809#undef _TP_SESSION_CHECK
810#ifdef TP_SESSION_CHECK
811#define _TP_SESSION_CHECK(session, csession) (session == csession)
812#else /* TP_SESSION_CHECK */
813#define _TP_SESSION_CHECK(session, csession) 1
814#endif /* TP_SESSION_CHECK */
815
97904b41
MD
816/*
817 * Use of __builtin_return_address(0) sometimes seems to cause stack
818 * corruption on 32-bit PowerPC. Disable this feature on that
819 * architecture for now by always using the NULL value for the ip
820 * context.
821 */
5dadb547
MD
822#undef _TP_IP_PARAM
823#ifdef TP_IP_PARAM
e1d09f9e 824#define _TP_IP_PARAM(x) (x)
5dadb547 825#else /* TP_IP_PARAM */
97904b41
MD
826
827#if defined(__PPC__) && !defined(__PPC64__)
828#define _TP_IP_PARAM(x) NULL
829#else /* #if defined(__PPC__) && !defined(__PPC64__) */
e1d09f9e 830#define _TP_IP_PARAM(x) __builtin_return_address(0)
97904b41
MD
831#endif /* #else #if defined(__PPC__) && !defined(__PPC64__) */
832
5dadb547
MD
833#endif /* TP_IP_PARAM */
834
1ddfd641
MD
835/*
836 * Using twice size for filter stack data to hold size and pointer for
837 * each field (worse case). For integers, max size required is 64-bit.
838 * Same for double-precision floats. Those fit within
839 * 2*sizeof(unsigned long) for all supported architectures.
61ce3223 840 * Perform UNION (||) of filter runtime list.
1ddfd641 841 */
1c324e59
MD
842#undef TRACEPOINT_EVENT_CLASS
843#define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
a8909ba5
PW
844static lttng_ust_notrace \
845void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)); \
846static \
847void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)) \
1c324e59 848{ \
53569322 849 struct lttng_event *__event = (struct lttng_event *) __tp_data; \
7dd08bec 850 struct lttng_channel *__chan = __event->chan; \
f280cb51 851 struct lttng_ust_lib_ring_buffer_ctx __ctx; \
53569322 852 struct lttng_stack_ctx __lttng_ctx; \
1c324e59
MD
853 size_t __event_len, __event_align; \
854 size_t __dynamic_len_idx = 0; \
75026e9f 855 const size_t __num_fields = _TP_ARRAY_SIZE(__event_fields___##_provider##___##_name) - 1; \
d71b57b9 856 union { \
75026e9f
FD
857 size_t __dynamic_len[__num_fields]; \
858 char __filter_stack_data[2 * sizeof(unsigned long) * __num_fields]; \
d71b57b9 859 } __stackvar; \
1c324e59
MD
860 int __ret; \
861 \
862 if (0) \
863 (void) __dynamic_len_idx; /* don't warn if unused */ \
95c25348
PW
864 if (!_TP_SESSION_CHECK(session, __chan->session)) \
865 return; \
1c324e59
MD
866 if (caa_unlikely(!CMM_ACCESS_ONCE(__chan->session->active))) \
867 return; \
868 if (caa_unlikely(!CMM_ACCESS_ONCE(__chan->enabled))) \
869 return; \
870 if (caa_unlikely(!CMM_ACCESS_ONCE(__event->enabled))) \
871 return; \
1b436e01
MD
872 if (caa_unlikely(!TP_RCU_LINK_TEST())) \
873 return; \
a56fd376
FD
874 if (caa_unlikely(!cds_list_empty(&__event->filter_bytecode_runtime_head))) { \
875 struct lttng_bytecode_runtime *__filter_bc_runtime; \
dcdeaff0 876 int __filter_record = __event->has_enablers_without_bytecode; \
f488575f 877 \
d37ecb3f 878 __event_prepare_interpreter_stack__##_provider##___##_name(__stackvar.__filter_stack_data, \
f488575f 879 _TP_ARGS_DATA_VAR(_args)); \
a56fd376 880 tp_list_for_each_entry_rcu(__filter_bc_runtime, &__event->filter_bytecode_runtime_head, node) { \
c42416df 881 if (caa_unlikely(__filter_bc_runtime->interpreter_funcs.filter(__filter_bc_runtime, \
04aa13f8 882 __stackvar.__filter_stack_data) & LTTNG_INTERPRETER_RECORD_FLAG)) { \
8a92ed2a 883 __filter_record = 1; \
5ffb7c14
FD
884 break; \
885 } \
f488575f 886 } \
8a92ed2a 887 if (caa_likely(!__filter_record)) \
61ce3223 888 return; \
1ddfd641
MD
889 } \
890 __event_len = __event_get_size__##_provider##___##_name(__stackvar.__dynamic_len, \
1c324e59
MD
891 _TP_ARGS_DATA_VAR(_args)); \
892 __event_align = __event_get_align__##_provider##___##_name(_TP_ARGS_VAR(_args)); \
53569322
MD
893 memset(&__lttng_ctx, 0, sizeof(__lttng_ctx)); \
894 __lttng_ctx.event = __event; \
10544ee8
MD
895 __lttng_ctx.chan_ctx = tp_rcu_dereference(__chan->ctx); \
896 __lttng_ctx.event_ctx = tp_rcu_dereference(__event->ctx); \
1c324e59 897 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, __event, __event_len, \
53569322 898 __event_align, -1, __chan->handle, &__lttng_ctx); \
e1d09f9e 899 __ctx.ip = _TP_IP_PARAM(TP_IP_PARAM); \
1c324e59
MD
900 __ret = __chan->ops->event_reserve(&__ctx, __event->id); \
901 if (__ret < 0) \
902 return; \
903 _fields \
904 __chan->ops->event_commit(&__ctx); \
905}
906
907#include TRACEPOINT_INCLUDE
908
909#undef __get_dynamic_len
910
68755429
MD
911/*
912 * Stage 5.1 of tracepoint event generation.
913 *
914 * Create probe signature
915 */
916
917/* Reset all macros within TRACEPOINT_EVENT */
918#include <lttng/ust-tracepoint-event-reset.h>
919
920#undef TP_ARGS
2eda209b 921#define TP_ARGS(...) __VA_ARGS__
9eb06182
MD
922
923#define _TP_EXTRACT_STRING2(...) #__VA_ARGS__
68755429
MD
924
925#undef TRACEPOINT_EVENT_CLASS
926#define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
ff82b7c1 927static const char __tp_event_signature___##_provider##___##_name[] = \
9eb06182 928 _TP_EXTRACT_STRING2(_args);
68755429
MD
929
930#include TRACEPOINT_INCLUDE
931
9eb06182
MD
932#undef _TP_EXTRACT_STRING2
933
d8d2416d
FD
934/*
935 * Stage 5.2 of tracepoint event generation.
936 *
937 * Create the event notifier probe function.
938 */
939#undef TRACEPOINT_EVENT_CLASS
940#define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
941static lttng_ust_notrace \
942void __event_notifier_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)); \
943static \
944void __event_notifier_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)) \
945{ \
946 struct lttng_event_notifier *__event_notifier = (struct lttng_event_notifier *) __tp_data; \
947 const size_t __num_fields = _TP_ARRAY_SIZE(__event_fields___##_provider##___##_name) - 1;\
948 union { \
949 size_t __dynamic_len[__num_fields]; \
d37ecb3f 950 char __interpreter_stack_data[2 * sizeof(unsigned long) * __num_fields]; \
d8d2416d
FD
951 } __stackvar; \
952 if (caa_unlikely(!CMM_ACCESS_ONCE(__event_notifier->enabled))) \
953 return; \
954 if (caa_unlikely(!TP_RCU_LINK_TEST())) \
955 return; \
956 if (caa_unlikely(!cds_list_empty(&__event_notifier->filter_bytecode_runtime_head))) { \
957 struct lttng_bytecode_runtime *__filter_bc_runtime; \
958 int __filter_record = __event_notifier->has_enablers_without_bytecode; \
959 \
d37ecb3f 960 __event_prepare_interpreter_stack__##_provider##___##_name(__stackvar.__interpreter_stack_data, \
d8d2416d
FD
961 _TP_ARGS_DATA_VAR(_args)); \
962 tp_list_for_each_entry_rcu(__filter_bc_runtime, &__event_notifier->filter_bytecode_runtime_head, node) { \
c42416df 963 if (caa_unlikely(__filter_bc_runtime->interpreter_funcs.filter(__filter_bc_runtime, \
d37ecb3f 964 __stackvar.__interpreter_stack_data) & LTTNG_INTERPRETER_RECORD_FLAG)) \
d8d2416d
FD
965 __filter_record = 1; \
966 } \
967 if (caa_likely(!__filter_record)) \
968 return; \
969 } \
d37ecb3f
FD
970 if (caa_unlikely(!cds_list_empty(&__event_notifier->capture_bytecode_runtime_head))) \
971 __event_prepare_interpreter_stack__##_provider##___##_name(__stackvar.__interpreter_stack_data, \
972 _TP_ARGS_DATA_VAR(_args)); \
d8d2416d 973 \
d37ecb3f
FD
974 lttng_event_notifier_notification_send(__event_notifier, \
975 __stackvar.__interpreter_stack_data); \
d8d2416d
FD
976}
977
978#include TRACEPOINT_INCLUDE
979
05ceaafd 980/*
882a56d7 981 * Stage 6 of tracepoint event generation.
1c324e59 982 *
df854e41
MD
983 * Tracepoint loglevel mapping definition generation. We generate a
984 * symbol for each mapping for a provider/event to ensure at most a 1 to
985 * 1 mapping between events and loglevels. If the symbol is repeated,
986 * the compiler will complain.
05ceaafd
MD
987 */
988
989/* Reset all macros within TRACEPOINT_EVENT */
990#include <lttng/ust-tracepoint-event-reset.h>
991
4ea4f80e
MD
992/*
993 * Declare _loglevel___##__provider##___##__name as non-static, with
994 * hidden visibility for c++ handling of weakref. We do a weakref to the
995 * symbol in a later stage, which requires that the symbol is not
996 * mangled.
997 */
998#ifdef __cplusplus
999#define LTTNG_TP_EXTERN_C extern "C"
1000#else
1001#define LTTNG_TP_EXTERN_C
1002#endif
1003
05ceaafd 1004#undef TRACEPOINT_LOGLEVEL
457a6b58
MD
1005#define TRACEPOINT_LOGLEVEL(__provider, __name, __loglevel) \
1006static const int _loglevel_value___##__provider##___##__name = __loglevel; \
4ea4f80e
MD
1007LTTNG_TP_EXTERN_C const int *_loglevel___##__provider##___##__name \
1008 __attribute__((visibility("hidden"))) = \
457a6b58 1009 &_loglevel_value___##__provider##___##__name;
df854e41
MD
1010
1011#include TRACEPOINT_INCLUDE
1012
4ea4f80e 1013#undef LTTNG_TP_EXTERN_C
4ea4f80e 1014
6ddc916d
MD
1015/*
1016 * Stage 6.1 of tracepoint event generation.
1017 *
1018 * Tracepoint UML URI info.
1019 */
1020
1021/* Reset all macros within TRACEPOINT_EVENT */
1022#include <lttng/ust-tracepoint-event-reset.h>
1023
4ea4f80e
MD
1024/*
1025 * Declare _model_emf_uri___##__provider##___##__name as non-static,
1026 * with hidden visibility for c++ handling of weakref. We do a weakref
1027 * to the symbol in a later stage, which requires that the symbol is not
1028 * mangled.
1029 */
1030#ifdef __cplusplus
1031#define LTTNG_TP_EXTERN_C extern "C"
1032#else
1033#define LTTNG_TP_EXTERN_C
1034#endif
1035
6ddc916d
MD
1036#undef TRACEPOINT_MODEL_EMF_URI
1037#define TRACEPOINT_MODEL_EMF_URI(__provider, __name, __uri) \
4ea4f80e 1038LTTNG_TP_EXTERN_C const char *_model_emf_uri___##__provider##___##__name \
082802f9 1039 __attribute__((visibility("hidden"))) = __uri; \
6ddc916d
MD
1040
1041#include TRACEPOINT_INCLUDE
1042
4ea4f80e 1043#undef LTTNG_TP_EXTERN_C
4ea4f80e 1044
df854e41 1045/*
882a56d7 1046 * Stage 7.1 of tracepoint event generation.
df854e41
MD
1047 *
1048 * Create events description structures. We use a weakref because
1049 * loglevels are optional. If not declared, the event will point to the
1050 * a loglevel that contains NULL.
1051 */
1052
1053/* Reset all macros within TRACEPOINT_EVENT */
1054#include <lttng/ust-tracepoint-event-reset.h>
1055
1056#undef TRACEPOINT_EVENT_INSTANCE
1057#define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
882a56d7
MD
1058static const int * \
1059 __ref_loglevel___##_provider##___##_name \
1060 __attribute__((weakref ("_loglevel___" #_provider "___" #_name))); \
6ddc916d
MD
1061static const char * \
1062 __ref_model_emf_uri___##_provider##___##_name \
1063 __attribute__((weakref ("_model_emf_uri___" #_provider "___" #_name)));\
ff82b7c1 1064static const struct lttng_event_desc __event_desc___##_provider##_##_name = { \
df854e41 1065 .name = #_provider ":" #_name, \
fbdeb5ec 1066 .probe_callback = (void (*)(void)) &__event_probe__##_provider##___##_template,\
46d52200
ZT
1067 .ctx = NULL, \
1068 .fields = __event_fields___##_provider##___##_template, \
1c80c909 1069 .nr_fields = _TP_ARRAY_SIZE(__event_fields___##_provider##___##_template) - 1, \
882a56d7 1070 .loglevel = &__ref_loglevel___##_provider##___##_name, \
68755429 1071 .signature = __tp_event_signature___##_provider##___##_template, \
c785c634
MD
1072 .u = { \
1073 .ext = { \
1074 .model_emf_uri = &__ref_model_emf_uri___##_provider##___##_name, \
d8d2416d 1075 .event_notifier_callback = (void (*)(void)) &__event_notifier_probe__##_provider##___##_template,\
c785c634
MD
1076 }, \
1077 }, \
df854e41
MD
1078};
1079
1080#include TRACEPOINT_INCLUDE
05ceaafd 1081
df854e41 1082/*
882a56d7 1083 * Stage 7.2 of tracepoint event generation.
df854e41
MD
1084 *
1085 * Create array of events.
1086 */
1087
1088/* Reset all macros within TRACEPOINT_EVENT */
1089#include <lttng/ust-tracepoint-event-reset.h>
1090
1091#undef TRACEPOINT_EVENT_INSTANCE
1092#define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
1093 &__event_desc___##_provider##_##_name,
1094
1095static const struct lttng_event_desc *_TP_COMBINE_TOKENS(__event_desc___, TRACEPOINT_PROVIDER)[] = {
05ceaafd 1096#include TRACEPOINT_INCLUDE
1c80c909 1097 NULL, /* Dummy, C99 forbids 0-len array. */
05ceaafd
MD
1098};
1099
df854e41 1100
05ceaafd 1101/*
882a56d7 1102 * Stage 8 of tracepoint event generation.
05ceaafd
MD
1103 *
1104 * Create a toplevel descriptor for the whole probe.
1105 */
1106
1107/* non-const because list head will be modified when registered. */
1108static struct lttng_probe_desc _TP_COMBINE_TOKENS(__probe_desc___, TRACEPOINT_PROVIDER) = {
df854e41 1109 .provider = __tp_stringify(TRACEPOINT_PROVIDER),
05ceaafd 1110 .event_desc = _TP_COMBINE_TOKENS(__event_desc___, TRACEPOINT_PROVIDER),
1c80c909 1111 .nr_events = _TP_ARRAY_SIZE(_TP_COMBINE_TOKENS(__event_desc___, TRACEPOINT_PROVIDER)) - 1,
46d52200
ZT
1112 .head = { NULL, NULL },
1113 .lazy_init_head = { NULL, NULL },
1114 .lazy = 0,
71d31690
MD
1115 .major = LTTNG_UST_PROVIDER_MAJOR,
1116 .minor = LTTNG_UST_PROVIDER_MINOR,
05ceaafd
MD
1117};
1118
f0cc794d
MD
1119static int _TP_COMBINE_TOKENS(__probe_register_refcount___, TRACEPOINT_PROVIDER);
1120
05ceaafd 1121/*
882a56d7 1122 * Stage 9 of tracepoint event generation.
05ceaafd 1123 *
1c324e59 1124 * Register/unregister probes at module load/unload.
628e1d81
MD
1125 *
1126 * Generate the constructor as an externally visible symbol for use when
1127 * linking the probe statically.
f0cc794d
MD
1128 *
1129 * Register refcount is protected by libc dynamic loader mutex.
1c324e59
MD
1130 */
1131
1132/* Reset all macros within TRACEPOINT_EVENT */
1133#include <lttng/ust-tracepoint-event-reset.h>
a8909ba5
PW
1134static void lttng_ust_notrace __attribute__((constructor))
1135_TP_COMBINE_TOKENS(__lttng_events_init__, TRACEPOINT_PROVIDER)(void);
1136static void
1c324e59
MD
1137_TP_COMBINE_TOKENS(__lttng_events_init__, TRACEPOINT_PROVIDER)(void)
1138{
1139 int ret;
1140
f0cc794d
MD
1141 if (_TP_COMBINE_TOKENS(__probe_register_refcount___,
1142 TRACEPOINT_PROVIDER)++) {
1143 return;
1144 }
e8bd1da7
MD
1145 /*
1146 * __tracepoint_provider_check_ ## TRACEPOINT_PROVIDER() is a
1147 * static inline function that ensures every probe PROVIDER
1148 * argument match the provider within which they appear. It
1149 * calls empty static inline functions, and therefore has no
1150 * runtime effect. However, if it detects an error, a linker
1151 * error will appear.
1152 */
1153 _TP_COMBINE_TOKENS(__tracepoint_provider_check_, TRACEPOINT_PROVIDER)();
7dd08bec 1154 ret = lttng_probe_register(&_TP_COMBINE_TOKENS(__probe_desc___, TRACEPOINT_PROVIDER));
7d381d6e 1155 if (ret) {
0fdd0b89 1156 fprintf(stderr, "LTTng-UST: Error (%d) while registering tracepoint probe.\n", ret);
7d381d6e
MD
1157 abort();
1158 }
1c324e59
MD
1159}
1160
a8909ba5
PW
1161static void lttng_ust_notrace __attribute__((destructor))
1162_TP_COMBINE_TOKENS(__lttng_events_exit__, TRACEPOINT_PROVIDER)(void);
1163static void
1c324e59
MD
1164_TP_COMBINE_TOKENS(__lttng_events_exit__, TRACEPOINT_PROVIDER)(void)
1165{
f0cc794d
MD
1166 if (--_TP_COMBINE_TOKENS(__probe_register_refcount___,
1167 TRACEPOINT_PROVIDER)) {
1168 return;
1169 }
7dd08bec 1170 lttng_probe_unregister(&_TP_COMBINE_TOKENS(__probe_desc___, TRACEPOINT_PROVIDER));
1c324e59 1171}
628e1d81
MD
1172
1173int _TP_COMBINE_TOKENS(__tracepoint_provider_, TRACEPOINT_PROVIDER);
This page took 0.089643 seconds and 4 git commands to generate.