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