Fix: loglevel and model_emf_uri build fix
[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
23#include <stdio.h>
7d381d6e 24#include <stdlib.h>
1c324e59 25#include <urcu/compiler.h>
f488575f 26#include <urcu/rculist.h>
1c324e59 27#include <lttng/ust-events.h>
1c324e59 28#include <lttng/ringbuffer-config.h>
a8909ba5 29#include <lttng/ust-compiler.h>
000b8662 30#include <lttng/tracepoint.h>
7018d9d4 31#include <byteswap.h>
44c72f10 32#include <string.h>
1c324e59 33
24a39530
PP
34#define __LTTNG_UST_NULL_STRING "(null)"
35
000b8662
MD
36#undef tp_list_for_each_entry_rcu
37#define tp_list_for_each_entry_rcu(pos, head, member) \
38 for (pos = cds_list_entry(tp_rcu_dereference_bp((head)->next), __typeof__(*pos), member); \
39 &pos->member != (head); \
40 pos = cds_list_entry(tp_rcu_dereference_bp(pos->member.next), __typeof__(*pos), member))
41
1c324e59
MD
42/*
43 * TRACEPOINT_EVENT_CLASS declares a class of tracepoints receiving the
44 * same arguments and having the same field layout.
45 *
46 * TRACEPOINT_EVENT_INSTANCE declares an instance of a tracepoint, with
47 * its own provider and name. It refers to a class (template).
48 *
49 * TRACEPOINT_EVENT declared both a class and an instance and does a
50 * direct mapping from the instance to the class.
51 */
52
53#undef TRACEPOINT_EVENT
54#define TRACEPOINT_EVENT(_provider, _name, _args, _fields) \
55 TRACEPOINT_EVENT_CLASS(_provider, _name, \
56 _TP_PARAMS(_args), \
57 _TP_PARAMS(_fields)) \
58 TRACEPOINT_EVENT_INSTANCE(_provider, _name, _name, \
68755429 59 _TP_PARAMS(_args))
1c324e59
MD
60
61/* Helpers */
62#define _TP_ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
63
64#define _tp_max_t(type, x, y) \
65 ({ \
66 type __max1 = (x); \
67 type __max2 = (y); \
68 __max1 > __max2 ? __max1: __max2; \
69 })
70
71/*
72 * Stage 0 of tracepoint event generation.
73 *
74 * Check that each TRACEPOINT_EVENT provider argument match the
75 * TRACEPOINT_PROVIDER by creating dummy callbacks.
76 */
77
78/* Reset all macros within TRACEPOINT_EVENT */
79#include <lttng/ust-tracepoint-event-reset.h>
80
7ce6b21d
PW
81static inline lttng_ust_notrace
82void _TP_COMBINE_TOKENS(__tracepoint_provider_mismatch_, TRACEPOINT_PROVIDER)(void);
1c324e59
MD
83static inline
84void _TP_COMBINE_TOKENS(__tracepoint_provider_mismatch_, TRACEPOINT_PROVIDER)(void)
85{
86}
87
88#undef TRACEPOINT_EVENT_CLASS
89#define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
90 __tracepoint_provider_mismatch_##_provider();
91
92#undef TRACEPOINT_EVENT_INSTANCE
93#define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
94 __tracepoint_provider_mismatch_##_provider();
95
7ce6b21d
PW
96static inline lttng_ust_notrace
97void _TP_COMBINE_TOKENS(__tracepoint_provider_check_, TRACEPOINT_PROVIDER)(void);
e8bd1da7 98static inline
1c324e59
MD
99void _TP_COMBINE_TOKENS(__tracepoint_provider_check_, TRACEPOINT_PROVIDER)(void)
100{
101#include TRACEPOINT_INCLUDE
102}
103
f56cd1d5
MD
104/*
105 * Stage 0.1 of tracepoint event generation.
106 *
107 * Check that each TRACEPOINT_EVENT provider:name does not exceed the
108 * tracepoint name length limit.
109 */
110
111/* Reset all macros within TRACEPOINT_EVENT */
112#include <lttng/ust-tracepoint-event-reset.h>
113
114#undef TRACEPOINT_EVENT_INSTANCE
115#define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
116static const char \
117 __tp_name_len_check##_provider##___##_name[LTTNG_UST_SYM_NAME_LEN] \
118 __attribute__((unused)) = \
119 #_provider ":" #_name;
120
121#include TRACEPOINT_INCLUDE
122
c785c634
MD
123/*
124 * Stage 0.9 of tracepoint event generation
125 *
126 * Unfolding the enums
127 */
128#include <lttng/ust-tracepoint-event-reset.h>
129
130/* Enumeration entry (single value) */
131#undef ctf_enum_value
132#define ctf_enum_value(_string, _value) \
16940765
MD
133 { \
134 .start = { \
16940765
MD
135 .value = lttng_is_signed_type(__typeof__(_value)) ? \
136 (long long) (_value) : (_value), \
73d2b7cb 137 .signedness = lttng_is_signed_type(__typeof__(_value)), \
16940765
MD
138 }, \
139 .end = { \
16940765
MD
140 .value = lttng_is_signed_type(__typeof__(_value)) ? \
141 (long long) (_value) : (_value), \
73d2b7cb 142 .signedness = lttng_is_signed_type(__typeof__(_value)), \
16940765
MD
143 }, \
144 .string = (_string), \
145 },
c785c634
MD
146
147/* Enumeration entry (range) */
148#undef ctf_enum_range
149#define ctf_enum_range(_string, _range_start, _range_end) \
16940765
MD
150 { \
151 .start = { \
16940765
MD
152 .value = lttng_is_signed_type(__typeof__(_range_start)) ? \
153 (long long) (_range_start) : (_range_start), \
73d2b7cb 154 .signedness = lttng_is_signed_type(__typeof__(_range_start)), \
16940765
MD
155 }, \
156 .end = { \
16940765
MD
157 .value = lttng_is_signed_type(__typeof__(_range_end)) ? \
158 (long long) (_range_end) : (_range_end), \
73d2b7cb 159 .signedness = lttng_is_signed_type(__typeof__(_range_end)), \
16940765
MD
160 }, \
161 .string = (_string), \
162 },
c785c634
MD
163
164#undef TP_ENUM_VALUES
165#define TP_ENUM_VALUES(...) \
166 __VA_ARGS__
167
168#undef TRACEPOINT_ENUM
169#define TRACEPOINT_ENUM(_provider, _name, _values) \
170 const struct lttng_enum_entry __enum_values__##_provider##_##_name[] = { \
171 _values \
792310b7 172 ctf_enum_value("", 0) /* Dummy, 0-len array forbidden by C99. */ \
c785c634
MD
173 };
174
175#include TRACEPOINT_INCLUDE
176
1c324e59
MD
177/*
178 * Stage 1 of tracepoint event generation.
179 *
180 * Create event field type metadata section.
181 * Each event produce an array of fields.
182 */
183
184/* Reset all macros within TRACEPOINT_EVENT */
185#include <lttng/ust-tracepoint-event-reset.h>
4774c8f3
MD
186#include <lttng/ust-tracepoint-event-write.h>
187#include <lttng/ust-tracepoint-event-nowrite.h>
1c324e59 188
4774c8f3 189#undef _ctf_integer_ext
180901e6 190#define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
1c324e59
MD
191 { \
192 .name = #_item, \
193 .type = __type_integer(_type, _byte_order, _base, none),\
180901e6 194 .nowrite = _nowrite, \
1c324e59
MD
195 },
196
4774c8f3 197#undef _ctf_float
180901e6 198#define _ctf_float(_type, _item, _src, _nowrite) \
1c324e59
MD
199 { \
200 .name = #_item, \
201 .type = __type_float(_type), \
180901e6 202 .nowrite = _nowrite, \
1c324e59
MD
203 },
204
4774c8f3 205#undef _ctf_array_encoded
180901e6 206#define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _nowrite) \
1c324e59
MD
207 { \
208 .name = #_item, \
209 .type = \
210 { \
211 .atype = atype_array, \
46d52200 212 .u = \
1c324e59 213 { \
46d52200
ZT
214 .array = \
215 { \
216 .elem_type = __type_integer(_type, BYTE_ORDER, 10, _encoding), \
217 .length = _length, \
218 } \
219 } \
1c324e59 220 }, \
180901e6 221 .nowrite = _nowrite, \
1c324e59
MD
222 },
223
4774c8f3 224#undef _ctf_sequence_encoded
f968510a
PP
225#define _ctf_sequence_encoded(_type, _item, _src, \
226 _length_type, _src_length, _encoding, _nowrite, \
227 _elem_type_base) \
1c324e59
MD
228 { \
229 .name = #_item, \
230 .type = \
231 { \
232 .atype = atype_sequence, \
46d52200 233 .u = \
1c324e59 234 { \
46d52200
ZT
235 .sequence = \
236 { \
237 .length_type = __type_integer(_length_type, BYTE_ORDER, 10, none), \
f968510a 238 .elem_type = __type_integer(_type, BYTE_ORDER, _elem_type_base, _encoding), \
46d52200 239 }, \
1c324e59
MD
240 }, \
241 }, \
180901e6 242 .nowrite = _nowrite, \
1c324e59
MD
243 },
244
4774c8f3 245#undef _ctf_string
180901e6 246#define _ctf_string(_item, _src, _nowrite) \
1c324e59
MD
247 { \
248 .name = #_item, \
249 .type = \
250 { \
251 .atype = atype_string, \
46d52200
ZT
252 .u = \
253 { \
254 .basic = { .string = { .encoding = lttng_encode_UTF8 } } \
255 }, \
1c324e59 256 }, \
180901e6 257 .nowrite = _nowrite, \
1c324e59
MD
258 },
259
c785c634
MD
260#undef _ctf_enum
261#define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
262 { \
263 .name = #_item, \
264 .type = { \
265 .atype = atype_enum, \
266 .u = { \
267 .basic = { \
268 .enumeration = { \
269 .desc = &__enum_##_provider##_##_name, \
270 .container_type = { \
271 .size = sizeof(_type) * CHAR_BIT, \
272 .alignment = lttng_alignof(_type) * CHAR_BIT, \
273 .signedness = lttng_is_signed_type(_type), \
274 .reverse_byte_order = 0, \
275 .base = 10, \
276 .encoding = lttng_encode_none, \
277 }, \
278 }, \
279 }, \
280 }, \
281 }, \
282 .nowrite = _nowrite, \
283 },
284
1c324e59 285#undef TP_FIELDS
2eda209b 286#define TP_FIELDS(...) __VA_ARGS__ /* Only one used in this phase */
1c324e59
MD
287
288#undef TRACEPOINT_EVENT_CLASS
289#define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
290 static const struct lttng_event_field __event_fields___##_provider##___##_name[] = { \
291 _fields \
792310b7 292 ctf_integer(int, dummy, 0) /* Dummy, C99 forbids 0-len array. */ \
1c324e59
MD
293 };
294
c785c634
MD
295#undef TRACEPOINT_ENUM
296#define TRACEPOINT_ENUM(_provider, _name, _values) \
297 static const struct lttng_enum_desc __enum_##_provider##_##_name = { \
298 .name = #_provider "_" #_name, \
299 .entries = __enum_values__##_provider##_##_name, \
792310b7 300 .nr_entries = _TP_ARRAY_SIZE(__enum_values__##_provider##_##_name) - 1, \
c785c634
MD
301 };
302
1c324e59
MD
303#include TRACEPOINT_INCLUDE
304
305/*
306 * Stage 2 of tracepoint event generation.
307 *
308 * Create probe callback prototypes.
309 */
310
311/* Reset all macros within TRACEPOINT_EVENT */
312#include <lttng/ust-tracepoint-event-reset.h>
313
314#undef TP_ARGS
2eda209b 315#define TP_ARGS(...) __VA_ARGS__
1c324e59
MD
316
317#undef TRACEPOINT_EVENT_CLASS
318#define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
319static void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args));
320
321#include TRACEPOINT_INCLUDE
322
323/*
c785c634 324 * Stage 3.0 of tracepoint event generation.
1c324e59 325 *
1c324e59
MD
326 * Create static inline function that calculates event size.
327 */
328
329/* Reset all macros within TRACEPOINT_EVENT */
330#include <lttng/ust-tracepoint-event-reset.h>
4774c8f3 331#include <lttng/ust-tracepoint-event-write.h>
1c324e59 332
4774c8f3 333#undef _ctf_integer_ext
180901e6 334#define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
1c324e59
MD
335 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
336 __event_len += sizeof(_type);
337
4774c8f3 338#undef _ctf_float
180901e6 339#define _ctf_float(_type, _item, _src, _nowrite) \
1c324e59
MD
340 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
341 __event_len += sizeof(_type);
342
4774c8f3 343#undef _ctf_array_encoded
180901e6 344#define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _nowrite) \
1c324e59
MD
345 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
346 __event_len += sizeof(_type) * (_length);
347
4774c8f3 348#undef _ctf_sequence_encoded
f968510a
PP
349#define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
350 _src_length, _encoding, _nowrite, _elem_type_base) \
1c324e59
MD
351 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_length_type)); \
352 __event_len += sizeof(_length_type); \
353 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
354 __dynamic_len[__dynamic_len_idx] = (_src_length); \
355 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
356 __dynamic_len_idx++;
357
4774c8f3 358#undef _ctf_string
180901e6 359#define _ctf_string(_item, _src, _nowrite) \
24a39530
PP
360 __event_len += __dynamic_len[__dynamic_len_idx++] = \
361 strlen((_src) ? (_src) : __LTTNG_UST_NULL_STRING) + 1;
1c324e59 362
c785c634
MD
363#undef _ctf_enum
364#define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
365 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
366
1c324e59 367#undef TP_ARGS
2eda209b 368#define TP_ARGS(...) __VA_ARGS__
1c324e59
MD
369
370#undef TP_FIELDS
2eda209b 371#define TP_FIELDS(...) __VA_ARGS__
1c324e59
MD
372
373#undef TRACEPOINT_EVENT_CLASS
a8909ba5
PW
374#define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
375static inline lttng_ust_notrace \
376size_t __event_get_size__##_provider##___##_name(size_t *__dynamic_len, _TP_ARGS_DATA_PROTO(_args)); \
377static inline \
378size_t __event_get_size__##_provider##___##_name(size_t *__dynamic_len, _TP_ARGS_DATA_PROTO(_args)) \
1c324e59
MD
379{ \
380 size_t __event_len = 0; \
381 unsigned int __dynamic_len_idx = 0; \
382 \
383 if (0) \
384 (void) __dynamic_len_idx; /* don't warn if unused */ \
385 _fields \
386 return __event_len; \
387}
388
389#include TRACEPOINT_INCLUDE
390
1ddfd641
MD
391/*
392 * Stage 3.1 of tracepoint event generation.
393 *
394 * Create static inline function that layout the filter stack data.
4774c8f3 395 * We make both write and nowrite data available to the filter.
1ddfd641
MD
396 */
397
398/* Reset all macros within TRACEPOINT_EVENT */
399#include <lttng/ust-tracepoint-event-reset.h>
4774c8f3
MD
400#include <lttng/ust-tracepoint-event-write.h>
401#include <lttng/ust-tracepoint-event-nowrite.h>
1ddfd641 402
4774c8f3 403#undef _ctf_integer_ext
180901e6 404#define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
fa099471 405 if (lttng_is_signed_type(_type)) { \
3ebeea0d
MD
406 int64_t __ctf_tmp_int64; \
407 switch (sizeof(_type)) { \
408 case 1: \
409 { \
410 union { _type t; int8_t v; } __tmp = { (_type) (_src) }; \
411 __ctf_tmp_int64 = (int64_t) __tmp.v; \
412 break; \
413 } \
414 case 2: \
415 { \
416 union { _type t; int16_t v; } __tmp = { (_type) (_src) }; \
7018d9d4
MD
417 if (_byte_order != BYTE_ORDER) \
418 __tmp.v = bswap_16(__tmp.v); \
3ebeea0d
MD
419 __ctf_tmp_int64 = (int64_t) __tmp.v; \
420 break; \
421 } \
422 case 4: \
423 { \
424 union { _type t; int32_t v; } __tmp = { (_type) (_src) }; \
7018d9d4
MD
425 if (_byte_order != BYTE_ORDER) \
426 __tmp.v = bswap_32(__tmp.v); \
3ebeea0d
MD
427 __ctf_tmp_int64 = (int64_t) __tmp.v; \
428 break; \
429 } \
430 case 8: \
431 { \
432 union { _type t; int64_t v; } __tmp = { (_type) (_src) }; \
7018d9d4
MD
433 if (_byte_order != BYTE_ORDER) \
434 __tmp.v = bswap_64(__tmp.v); \
3ebeea0d
MD
435 __ctf_tmp_int64 = (int64_t) __tmp.v; \
436 break; \
437 } \
438 default: \
439 abort(); \
440 }; \
fa099471
MD
441 memcpy(__stack_data, &__ctf_tmp_int64, sizeof(int64_t)); \
442 } else { \
3ebeea0d
MD
443 uint64_t __ctf_tmp_uint64; \
444 switch (sizeof(_type)) { \
445 case 1: \
446 { \
447 union { _type t; uint8_t v; } __tmp = { (_type) (_src) }; \
448 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
449 break; \
450 } \
451 case 2: \
452 { \
453 union { _type t; uint16_t v; } __tmp = { (_type) (_src) }; \
7018d9d4
MD
454 if (_byte_order != BYTE_ORDER) \
455 __tmp.v = bswap_16(__tmp.v); \
3ebeea0d
MD
456 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
457 break; \
458 } \
459 case 4: \
460 { \
461 union { _type t; uint32_t v; } __tmp = { (_type) (_src) }; \
7018d9d4
MD
462 if (_byte_order != BYTE_ORDER) \
463 __tmp.v = bswap_32(__tmp.v); \
3ebeea0d
MD
464 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
465 break; \
466 } \
467 case 8: \
468 { \
469 union { _type t; uint64_t v; } __tmp = { (_type) (_src) }; \
7018d9d4
MD
470 if (_byte_order != BYTE_ORDER) \
471 __tmp.v = bswap_64(__tmp.v); \
3ebeea0d
MD
472 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
473 break; \
474 } \
475 default: \
476 abort(); \
477 }; \
fa099471
MD
478 memcpy(__stack_data, &__ctf_tmp_uint64, sizeof(uint64_t)); \
479 } \
1ddfd641
MD
480 __stack_data += sizeof(int64_t);
481
4774c8f3 482#undef _ctf_float
180901e6 483#define _ctf_float(_type, _item, _src, _nowrite) \
fa099471
MD
484 { \
485 double __ctf_tmp_double = (double) (_type) (_src); \
486 memcpy(__stack_data, &__ctf_tmp_double, sizeof(double)); \
487 __stack_data += sizeof(double); \
488 }
1ddfd641 489
4774c8f3 490#undef _ctf_array_encoded
180901e6 491#define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _nowrite) \
fa099471
MD
492 { \
493 unsigned long __ctf_tmp_ulong = (unsigned long) (_length); \
59034aab 494 const void *__ctf_tmp_ptr = (_src); \
fa099471
MD
495 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
496 __stack_data += sizeof(unsigned long); \
b1239ad6
MD
497 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
498 __stack_data += sizeof(void *); \
fa099471 499 }
1ddfd641 500
4774c8f3
MD
501#undef _ctf_sequence_encoded
502#define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
f968510a 503 _src_length, _encoding, _nowrite, _elem_type_base) \
fa099471
MD
504 { \
505 unsigned long __ctf_tmp_ulong = (unsigned long) (_src_length); \
59034aab 506 const void *__ctf_tmp_ptr = (_src); \
fa099471
MD
507 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
508 __stack_data += sizeof(unsigned long); \
b1239ad6
MD
509 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
510 __stack_data += sizeof(void *); \
fa099471 511 }
1ddfd641 512
4774c8f3 513#undef _ctf_string
180901e6 514#define _ctf_string(_item, _src, _nowrite) \
fa099471 515 { \
24a39530
PP
516 const void *__ctf_tmp_ptr = \
517 ((_src) ? (_src) : __LTTNG_UST_NULL_STRING); \
b1239ad6
MD
518 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
519 __stack_data += sizeof(void *); \
fa099471 520 }
1ddfd641 521
c785c634
MD
522#undef _ctf_enum
523#define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
524 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
525
1ddfd641
MD
526#undef TP_ARGS
527#define TP_ARGS(...) __VA_ARGS__
528
529#undef TP_FIELDS
530#define TP_FIELDS(...) __VA_ARGS__
531
532#undef TRACEPOINT_EVENT_CLASS
533#define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
534static inline \
535void __event_prepare_filter_stack__##_provider##___##_name(char *__stack_data,\
536 _TP_ARGS_DATA_PROTO(_args)) \
537{ \
538 _fields \
539}
540
541#include TRACEPOINT_INCLUDE
542
1c324e59 543/*
df854e41 544 * Stage 4 of tracepoint event generation.
1c324e59
MD
545 *
546 * Create static inline function that calculates event payload alignment.
547 */
548
549/* Reset all macros within TRACEPOINT_EVENT */
550#include <lttng/ust-tracepoint-event-reset.h>
4774c8f3 551#include <lttng/ust-tracepoint-event-write.h>
1c324e59 552
4774c8f3 553#undef _ctf_integer_ext
180901e6 554#define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
1c324e59
MD
555 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
556
4774c8f3 557#undef _ctf_float
180901e6 558#define _ctf_float(_type, _item, _src, _nowrite) \
1c324e59
MD
559 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
560
4774c8f3 561#undef _ctf_array_encoded
180901e6 562#define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _nowrite) \
1c324e59
MD
563 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
564
4774c8f3 565#undef _ctf_sequence_encoded
f968510a
PP
566#define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
567 _src_length, _encoding, _nowrite, _elem_type_base) \
1c324e59
MD
568 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_length_type)); \
569 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
570
4774c8f3 571#undef _ctf_string
180901e6 572#define _ctf_string(_item, _src, _nowrite)
1c324e59 573
c785c634
MD
574#undef _ctf_enum
575#define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
576 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
577
1c324e59 578#undef TP_ARGS
2eda209b 579#define TP_ARGS(...) __VA_ARGS__
1c324e59
MD
580
581#undef TP_FIELDS
2eda209b 582#define TP_FIELDS(...) __VA_ARGS__
1c324e59
MD
583
584#undef TRACEPOINT_EVENT_CLASS
585#define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
a8909ba5
PW
586static inline lttng_ust_notrace \
587size_t __event_get_align__##_provider##___##_name(_TP_ARGS_PROTO(_args)); \
1c324e59
MD
588static inline \
589size_t __event_get_align__##_provider##___##_name(_TP_ARGS_PROTO(_args)) \
590{ \
591 size_t __event_align = 1; \
592 _fields \
593 return __event_align; \
594}
595
596#include TRACEPOINT_INCLUDE
597
598
599/*
df854e41 600 * Stage 5 of tracepoint event generation.
1c324e59
MD
601 *
602 * Create the probe function. This function calls event size calculation
603 * and writes event data into the buffer.
604 */
605
606/* Reset all macros within TRACEPOINT_EVENT */
607#include <lttng/ust-tracepoint-event-reset.h>
4774c8f3 608#include <lttng/ust-tracepoint-event-write.h>
1c324e59 609
4774c8f3 610#undef _ctf_integer_ext
180901e6 611#define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
1c324e59
MD
612 { \
613 _type __tmp = (_src); \
614 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp));\
615 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
616 }
617
4774c8f3 618#undef _ctf_float
180901e6 619#define _ctf_float(_type, _item, _src, _nowrite) \
1c324e59
MD
620 { \
621 _type __tmp = (_src); \
622 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp));\
623 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
624 }
625
4774c8f3 626#undef _ctf_array_encoded
180901e6 627#define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _nowrite) \
1c324e59
MD
628 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
629 __chan->ops->event_write(&__ctx, _src, sizeof(_type) * (_length));
630
4774c8f3
MD
631#undef _ctf_sequence_encoded
632#define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
f968510a 633 _src_length, _encoding, _nowrite, _elem_type_base) \
1c324e59 634 { \
d71b57b9 635 _length_type __tmpl = __stackvar.__dynamic_len[__dynamic_len_idx]; \
1c324e59
MD
636 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_length_type));\
637 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(_length_type));\
638 } \
639 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
640 __chan->ops->event_write(&__ctx, _src, \
641 sizeof(_type) * __get_dynamic_len(dest));
642
a44c74d9
MD
643/*
644 * __chan->ops->u.has_strcpy is a flag letting us know if the LTTng-UST
645 * tracepoint provider ABI implements event_strcpy. This dynamic check
646 * can be removed when the tracepoint provider ABI moves to 2.
647 */
648#if (LTTNG_UST_PROVIDER_MAJOR > 1)
649#error "Tracepoint probe provider major version has changed. Please remove dynamic check for has_strcpy."
650#endif
651
4774c8f3 652#undef _ctf_string
180901e6 653#define _ctf_string(_item, _src, _nowrite) \
24a39530
PP
654 { \
655 const char *__ctf_tmp_string = \
656 ((_src) ? (_src) : __LTTNG_UST_NULL_STRING); \
657 lib_ring_buffer_align_ctx(&__ctx, \
658 lttng_alignof(*__ctf_tmp_string)); \
659 if (__chan->ops->u.has_strcpy) \
660 __chan->ops->event_strcpy(&__ctx, __ctf_tmp_string, \
661 __get_dynamic_len(dest)); \
662 else \
663 __chan->ops->event_write(&__ctx, __ctf_tmp_string, \
664 __get_dynamic_len(dest)); \
665 }
666
1c324e59 667
c785c634
MD
668#undef _ctf_enum
669#define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
670 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
671
1c324e59
MD
672/* Beware: this get len actually consumes the len value */
673#undef __get_dynamic_len
d71b57b9 674#define __get_dynamic_len(field) __stackvar.__dynamic_len[__dynamic_len_idx++]
1c324e59
MD
675
676#undef TP_ARGS
2eda209b 677#define TP_ARGS(...) __VA_ARGS__
1c324e59
MD
678
679#undef TP_FIELDS
2eda209b 680#define TP_FIELDS(...) __VA_ARGS__
1c324e59 681
95c25348
PW
682/*
683 * For state dump, check that "session" argument (mandatory) matches the
684 * session this event belongs to. Ensures that we write state dump data only
685 * into the started session, not into all sessions.
686 */
687#undef _TP_SESSION_CHECK
688#ifdef TP_SESSION_CHECK
689#define _TP_SESSION_CHECK(session, csession) (session == csession)
690#else /* TP_SESSION_CHECK */
691#define _TP_SESSION_CHECK(session, csession) 1
692#endif /* TP_SESSION_CHECK */
693
97904b41
MD
694/*
695 * Use of __builtin_return_address(0) sometimes seems to cause stack
696 * corruption on 32-bit PowerPC. Disable this feature on that
697 * architecture for now by always using the NULL value for the ip
698 * context.
699 */
5dadb547
MD
700#undef _TP_IP_PARAM
701#ifdef TP_IP_PARAM
e1d09f9e 702#define _TP_IP_PARAM(x) (x)
5dadb547 703#else /* TP_IP_PARAM */
97904b41
MD
704
705#if defined(__PPC__) && !defined(__PPC64__)
706#define _TP_IP_PARAM(x) NULL
707#else /* #if defined(__PPC__) && !defined(__PPC64__) */
e1d09f9e 708#define _TP_IP_PARAM(x) __builtin_return_address(0)
97904b41
MD
709#endif /* #else #if defined(__PPC__) && !defined(__PPC64__) */
710
5dadb547
MD
711#endif /* TP_IP_PARAM */
712
1ddfd641
MD
713/*
714 * Using twice size for filter stack data to hold size and pointer for
715 * each field (worse case). For integers, max size required is 64-bit.
716 * Same for double-precision floats. Those fit within
717 * 2*sizeof(unsigned long) for all supported architectures.
61ce3223 718 * Perform UNION (||) of filter runtime list.
1ddfd641 719 */
1c324e59
MD
720#undef TRACEPOINT_EVENT_CLASS
721#define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
a8909ba5
PW
722static lttng_ust_notrace \
723void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)); \
724static \
725void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)) \
1c324e59 726{ \
53569322 727 struct lttng_event *__event = (struct lttng_event *) __tp_data; \
7dd08bec 728 struct lttng_channel *__chan = __event->chan; \
f280cb51 729 struct lttng_ust_lib_ring_buffer_ctx __ctx; \
53569322 730 struct lttng_stack_ctx __lttng_ctx; \
1c324e59
MD
731 size_t __event_len, __event_align; \
732 size_t __dynamic_len_idx = 0; \
d71b57b9 733 union { \
792310b7
MD
734 size_t __dynamic_len[_TP_ARRAY_SIZE(__event_fields___##_provider##___##_name) - 1]; \
735 char __filter_stack_data[2 * sizeof(unsigned long) * (_TP_ARRAY_SIZE(__event_fields___##_provider##___##_name) - 1)]; \
d71b57b9 736 } __stackvar; \
1c324e59
MD
737 int __ret; \
738 \
739 if (0) \
740 (void) __dynamic_len_idx; /* don't warn if unused */ \
95c25348
PW
741 if (!_TP_SESSION_CHECK(session, __chan->session)) \
742 return; \
1c324e59
MD
743 if (caa_unlikely(!CMM_ACCESS_ONCE(__chan->session->active))) \
744 return; \
745 if (caa_unlikely(!CMM_ACCESS_ONCE(__chan->enabled))) \
746 return; \
747 if (caa_unlikely(!CMM_ACCESS_ONCE(__event->enabled))) \
748 return; \
1b436e01
MD
749 if (caa_unlikely(!TP_RCU_LINK_TEST())) \
750 return; \
e58095ef 751 if (caa_unlikely(!cds_list_empty(&__event->bytecode_runtime_head))) { \
f488575f 752 struct lttng_bytecode_runtime *bc_runtime; \
dcdeaff0 753 int __filter_record = __event->has_enablers_without_bytecode; \
f488575f 754 \
1ddfd641 755 __event_prepare_filter_stack__##_provider##___##_name(__stackvar.__filter_stack_data, \
f488575f 756 _TP_ARGS_DATA_VAR(_args)); \
000b8662 757 tp_list_for_each_entry_rcu(bc_runtime, &__event->bytecode_runtime_head, node) { \
61ce3223 758 if (caa_unlikely(bc_runtime->filter(bc_runtime, \
8a92ed2a
MD
759 __stackvar.__filter_stack_data) & LTTNG_FILTER_RECORD_FLAG)) \
760 __filter_record = 1; \
f488575f 761 } \
8a92ed2a 762 if (caa_likely(!__filter_record)) \
61ce3223 763 return; \
1ddfd641
MD
764 } \
765 __event_len = __event_get_size__##_provider##___##_name(__stackvar.__dynamic_len, \
1c324e59
MD
766 _TP_ARGS_DATA_VAR(_args)); \
767 __event_align = __event_get_align__##_provider##___##_name(_TP_ARGS_VAR(_args)); \
53569322
MD
768 memset(&__lttng_ctx, 0, sizeof(__lttng_ctx)); \
769 __lttng_ctx.event = __event; \
770 __lttng_ctx.chan_ctx = tp_rcu_dereference_bp(__chan->ctx); \
771 __lttng_ctx.event_ctx = tp_rcu_dereference_bp(__event->ctx); \
1c324e59 772 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, __event, __event_len, \
53569322 773 __event_align, -1, __chan->handle, &__lttng_ctx); \
e1d09f9e 774 __ctx.ip = _TP_IP_PARAM(TP_IP_PARAM); \
1c324e59
MD
775 __ret = __chan->ops->event_reserve(&__ctx, __event->id); \
776 if (__ret < 0) \
777 return; \
778 _fields \
779 __chan->ops->event_commit(&__ctx); \
780}
781
782#include TRACEPOINT_INCLUDE
783
784#undef __get_dynamic_len
785
68755429
MD
786/*
787 * Stage 5.1 of tracepoint event generation.
788 *
789 * Create probe signature
790 */
791
792/* Reset all macros within TRACEPOINT_EVENT */
793#include <lttng/ust-tracepoint-event-reset.h>
794
795#undef TP_ARGS
2eda209b 796#define TP_ARGS(...) __VA_ARGS__
9eb06182
MD
797
798#define _TP_EXTRACT_STRING2(...) #__VA_ARGS__
68755429
MD
799
800#undef TRACEPOINT_EVENT_CLASS
801#define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
52ecff8a 802static const char __tp_event_signature___##_provider##___##_name[] = \
9eb06182 803 _TP_EXTRACT_STRING2(_args);
68755429
MD
804
805#include TRACEPOINT_INCLUDE
806
9eb06182
MD
807#undef _TP_EXTRACT_STRING2
808
05ceaafd 809/*
882a56d7 810 * Stage 6 of tracepoint event generation.
1c324e59 811 *
df854e41
MD
812 * Tracepoint loglevel mapping definition generation. We generate a
813 * symbol for each mapping for a provider/event to ensure at most a 1 to
814 * 1 mapping between events and loglevels. If the symbol is repeated,
815 * the compiler will complain.
05ceaafd
MD
816 */
817
818/* Reset all macros within TRACEPOINT_EVENT */
819#include <lttng/ust-tracepoint-event-reset.h>
820
958b101d
MD
821/*
822 * Declare _loglevel___##__provider##___##__name as non-static, with
823 * hidden visibility for c++ handling of weakref. We do a weakref to the
824 * symbol in a later stage, which requires that the symbol is not
825 * mangled.
826 */
827#ifdef __cplusplus
828#define LTTNG_TP_EXTERN_C extern "C"
829#else
830#define LTTNG_TP_EXTERN_C
831#endif
832
05ceaafd 833#undef TRACEPOINT_LOGLEVEL
457a6b58
MD
834#define TRACEPOINT_LOGLEVEL(__provider, __name, __loglevel) \
835static const int _loglevel_value___##__provider##___##__name = __loglevel; \
958b101d
MD
836LTTNG_TP_EXTERN_C const int *_loglevel___##__provider##___##__name \
837 __attribute__((visibility("hidden"))) = \
457a6b58 838 &_loglevel_value___##__provider##___##__name;
df854e41
MD
839
840#include TRACEPOINT_INCLUDE
841
958b101d 842#undef LTTNG_TP_EXTERN_C
958b101d 843
6ddc916d
MD
844/*
845 * Stage 6.1 of tracepoint event generation.
846 *
847 * Tracepoint UML URI info.
848 */
849
850/* Reset all macros within TRACEPOINT_EVENT */
851#include <lttng/ust-tracepoint-event-reset.h>
852
958b101d
MD
853/*
854 * Declare _model_emf_uri___##__provider##___##__name as non-static,
855 * with hidden visibility for c++ handling of weakref. We do a weakref
856 * to the symbol in a later stage, which requires that the symbol is not
857 * mangled.
858 */
859#ifdef __cplusplus
860#define LTTNG_TP_EXTERN_C extern "C"
861#else
862#define LTTNG_TP_EXTERN_C
863#endif
864
6ddc916d
MD
865#undef TRACEPOINT_MODEL_EMF_URI
866#define TRACEPOINT_MODEL_EMF_URI(__provider, __name, __uri) \
958b101d 867LTTNG_TP_EXTERN_C const char *_model_emf_uri___##__provider##___##__name \
0ab954a9 868 __attribute__((visibility("hidden"))) = __uri; \
6ddc916d
MD
869
870#include TRACEPOINT_INCLUDE
871
958b101d 872#undef LTTNG_TP_EXTERN_C
958b101d 873
df854e41 874/*
882a56d7 875 * Stage 7.1 of tracepoint event generation.
df854e41
MD
876 *
877 * Create events description structures. We use a weakref because
878 * loglevels are optional. If not declared, the event will point to the
879 * a loglevel that contains NULL.
880 */
881
882/* Reset all macros within TRACEPOINT_EVENT */
883#include <lttng/ust-tracepoint-event-reset.h>
884
885#undef TRACEPOINT_EVENT_INSTANCE
886#define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
882a56d7
MD
887static const int * \
888 __ref_loglevel___##_provider##___##_name \
889 __attribute__((weakref ("_loglevel___" #_provider "___" #_name))); \
6ddc916d
MD
890static const char * \
891 __ref_model_emf_uri___##_provider##___##_name \
892 __attribute__((weakref ("_model_emf_uri___" #_provider "___" #_name)));\
52ecff8a 893static const struct lttng_event_desc __event_desc___##_provider##_##_name = { \
df854e41 894 .name = #_provider ":" #_name, \
fbdeb5ec 895 .probe_callback = (void (*)(void)) &__event_probe__##_provider##___##_template,\
46d52200
ZT
896 .ctx = NULL, \
897 .fields = __event_fields___##_provider##___##_template, \
792310b7 898 .nr_fields = _TP_ARRAY_SIZE(__event_fields___##_provider##___##_template) - 1, \
882a56d7 899 .loglevel = &__ref_loglevel___##_provider##___##_name, \
68755429 900 .signature = __tp_event_signature___##_provider##___##_template, \
c785c634
MD
901 .u = { \
902 .ext = { \
903 .model_emf_uri = &__ref_model_emf_uri___##_provider##___##_name, \
904 }, \
905 }, \
df854e41
MD
906};
907
908#include TRACEPOINT_INCLUDE
05ceaafd 909
df854e41 910/*
882a56d7 911 * Stage 7.2 of tracepoint event generation.
df854e41
MD
912 *
913 * Create array of events.
914 */
915
916/* Reset all macros within TRACEPOINT_EVENT */
917#include <lttng/ust-tracepoint-event-reset.h>
918
919#undef TRACEPOINT_EVENT_INSTANCE
920#define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
921 &__event_desc___##_provider##_##_name,
922
923static const struct lttng_event_desc *_TP_COMBINE_TOKENS(__event_desc___, TRACEPOINT_PROVIDER)[] = {
05ceaafd 924#include TRACEPOINT_INCLUDE
792310b7 925 NULL, /* Dummy, C99 forbids 0-len array. */
05ceaafd
MD
926};
927
df854e41 928
05ceaafd 929/*
882a56d7 930 * Stage 8 of tracepoint event generation.
05ceaafd
MD
931 *
932 * Create a toplevel descriptor for the whole probe.
933 */
934
935/* non-const because list head will be modified when registered. */
936static struct lttng_probe_desc _TP_COMBINE_TOKENS(__probe_desc___, TRACEPOINT_PROVIDER) = {
df854e41 937 .provider = __tp_stringify(TRACEPOINT_PROVIDER),
05ceaafd 938 .event_desc = _TP_COMBINE_TOKENS(__event_desc___, TRACEPOINT_PROVIDER),
792310b7 939 .nr_events = _TP_ARRAY_SIZE(_TP_COMBINE_TOKENS(__event_desc___, TRACEPOINT_PROVIDER)) - 1,
46d52200
ZT
940 .head = { NULL, NULL },
941 .lazy_init_head = { NULL, NULL },
942 .lazy = 0,
71d31690
MD
943 .major = LTTNG_UST_PROVIDER_MAJOR,
944 .minor = LTTNG_UST_PROVIDER_MINOR,
05ceaafd
MD
945};
946
f0cc794d
MD
947static int _TP_COMBINE_TOKENS(__probe_register_refcount___, TRACEPOINT_PROVIDER);
948
05ceaafd 949/*
882a56d7 950 * Stage 9 of tracepoint event generation.
05ceaafd 951 *
1c324e59 952 * Register/unregister probes at module load/unload.
628e1d81
MD
953 *
954 * Generate the constructor as an externally visible symbol for use when
955 * linking the probe statically.
f0cc794d
MD
956 *
957 * Register refcount is protected by libc dynamic loader mutex.
1c324e59
MD
958 */
959
960/* Reset all macros within TRACEPOINT_EVENT */
961#include <lttng/ust-tracepoint-event-reset.h>
a8909ba5
PW
962static void lttng_ust_notrace __attribute__((constructor))
963_TP_COMBINE_TOKENS(__lttng_events_init__, TRACEPOINT_PROVIDER)(void);
964static void
1c324e59
MD
965_TP_COMBINE_TOKENS(__lttng_events_init__, TRACEPOINT_PROVIDER)(void)
966{
967 int ret;
968
f0cc794d
MD
969 if (_TP_COMBINE_TOKENS(__probe_register_refcount___,
970 TRACEPOINT_PROVIDER)++) {
971 return;
972 }
e8bd1da7
MD
973 /*
974 * __tracepoint_provider_check_ ## TRACEPOINT_PROVIDER() is a
975 * static inline function that ensures every probe PROVIDER
976 * argument match the provider within which they appear. It
977 * calls empty static inline functions, and therefore has no
978 * runtime effect. However, if it detects an error, a linker
979 * error will appear.
980 */
981 _TP_COMBINE_TOKENS(__tracepoint_provider_check_, TRACEPOINT_PROVIDER)();
7dd08bec 982 ret = lttng_probe_register(&_TP_COMBINE_TOKENS(__probe_desc___, TRACEPOINT_PROVIDER));
7d381d6e
MD
983 if (ret) {
984 fprintf(stderr, "LTTng-UST: Error (%d) while registering tracepoint probe. Duplicate registration of tracepoint probes having the same name is not allowed.\n", ret);
985 abort();
986 }
1c324e59
MD
987}
988
a8909ba5
PW
989static void lttng_ust_notrace __attribute__((destructor))
990_TP_COMBINE_TOKENS(__lttng_events_exit__, TRACEPOINT_PROVIDER)(void);
991static void
1c324e59
MD
992_TP_COMBINE_TOKENS(__lttng_events_exit__, TRACEPOINT_PROVIDER)(void)
993{
f0cc794d
MD
994 if (--_TP_COMBINE_TOKENS(__probe_register_refcount___,
995 TRACEPOINT_PROVIDER)) {
996 return;
997 }
7dd08bec 998 lttng_probe_unregister(&_TP_COMBINE_TOKENS(__probe_desc___, TRACEPOINT_PROVIDER));
1c324e59 999}
628e1d81
MD
1000
1001int _TP_COMBINE_TOKENS(__tracepoint_provider_, TRACEPOINT_PROVIDER);
This page took 0.0785 seconds and 4 git commands to generate.