Fix: Cast from pointer to different integer size warning
[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>
44c72f10 31#include <string.h>
1c324e59 32
000b8662
MD
33#undef tp_list_for_each_entry_rcu
34#define tp_list_for_each_entry_rcu(pos, head, member) \
35 for (pos = cds_list_entry(tp_rcu_dereference_bp((head)->next), __typeof__(*pos), member); \
36 &pos->member != (head); \
37 pos = cds_list_entry(tp_rcu_dereference_bp(pos->member.next), __typeof__(*pos), member))
38
1c324e59
MD
39/*
40 * TRACEPOINT_EVENT_CLASS declares a class of tracepoints receiving the
41 * same arguments and having the same field layout.
42 *
43 * TRACEPOINT_EVENT_INSTANCE declares an instance of a tracepoint, with
44 * its own provider and name. It refers to a class (template).
45 *
46 * TRACEPOINT_EVENT declared both a class and an instance and does a
47 * direct mapping from the instance to the class.
48 */
49
50#undef TRACEPOINT_EVENT
51#define TRACEPOINT_EVENT(_provider, _name, _args, _fields) \
52 TRACEPOINT_EVENT_CLASS(_provider, _name, \
53 _TP_PARAMS(_args), \
54 _TP_PARAMS(_fields)) \
55 TRACEPOINT_EVENT_INSTANCE(_provider, _name, _name, \
68755429 56 _TP_PARAMS(_args))
1c324e59
MD
57
58/* Helpers */
59#define _TP_ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
60
61#define _tp_max_t(type, x, y) \
62 ({ \
63 type __max1 = (x); \
64 type __max2 = (y); \
65 __max1 > __max2 ? __max1: __max2; \
66 })
67
68/*
69 * Stage 0 of tracepoint event generation.
70 *
71 * Check that each TRACEPOINT_EVENT provider argument match the
72 * TRACEPOINT_PROVIDER by creating dummy callbacks.
73 */
74
75/* Reset all macros within TRACEPOINT_EVENT */
76#include <lttng/ust-tracepoint-event-reset.h>
77
78static inline
79void _TP_COMBINE_TOKENS(__tracepoint_provider_mismatch_, TRACEPOINT_PROVIDER)(void)
80{
81}
82
83#undef TRACEPOINT_EVENT_CLASS
84#define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
85 __tracepoint_provider_mismatch_##_provider();
86
87#undef TRACEPOINT_EVENT_INSTANCE
88#define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
89 __tracepoint_provider_mismatch_##_provider();
90
e8bd1da7 91static inline
1c324e59
MD
92void _TP_COMBINE_TOKENS(__tracepoint_provider_check_, TRACEPOINT_PROVIDER)(void)
93{
94#include TRACEPOINT_INCLUDE
95}
96
f56cd1d5
MD
97/*
98 * Stage 0.1 of tracepoint event generation.
99 *
100 * Check that each TRACEPOINT_EVENT provider:name does not exceed the
101 * tracepoint name length limit.
102 */
103
104/* Reset all macros within TRACEPOINT_EVENT */
105#include <lttng/ust-tracepoint-event-reset.h>
106
107#undef TRACEPOINT_EVENT_INSTANCE
108#define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
109static const char \
110 __tp_name_len_check##_provider##___##_name[LTTNG_UST_SYM_NAME_LEN] \
111 __attribute__((unused)) = \
112 #_provider ":" #_name;
113
114#include TRACEPOINT_INCLUDE
115
1c324e59
MD
116/*
117 * Stage 1 of tracepoint event generation.
118 *
119 * Create event field type metadata section.
120 * Each event produce an array of fields.
121 */
122
123/* Reset all macros within TRACEPOINT_EVENT */
124#include <lttng/ust-tracepoint-event-reset.h>
4774c8f3
MD
125#include <lttng/ust-tracepoint-event-write.h>
126#include <lttng/ust-tracepoint-event-nowrite.h>
1c324e59 127
4774c8f3 128#undef _ctf_integer_ext
180901e6 129#define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
1c324e59
MD
130 { \
131 .name = #_item, \
132 .type = __type_integer(_type, _byte_order, _base, none),\
180901e6 133 .nowrite = _nowrite, \
1c324e59
MD
134 },
135
4774c8f3 136#undef _ctf_float
180901e6 137#define _ctf_float(_type, _item, _src, _nowrite) \
1c324e59
MD
138 { \
139 .name = #_item, \
140 .type = __type_float(_type), \
180901e6 141 .nowrite = _nowrite, \
1c324e59
MD
142 },
143
4774c8f3 144#undef _ctf_array_encoded
180901e6 145#define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _nowrite) \
1c324e59
MD
146 { \
147 .name = #_item, \
148 .type = \
149 { \
150 .atype = atype_array, \
46d52200 151 .u = \
1c324e59 152 { \
46d52200
ZT
153 .array = \
154 { \
155 .elem_type = __type_integer(_type, BYTE_ORDER, 10, _encoding), \
156 .length = _length, \
157 } \
158 } \
1c324e59 159 }, \
180901e6 160 .nowrite = _nowrite, \
1c324e59
MD
161 },
162
4774c8f3
MD
163#undef _ctf_sequence_encoded
164#define _ctf_sequence_encoded(_type, _item, _src, \
180901e6 165 _length_type, _src_length, _encoding, _nowrite) \
1c324e59
MD
166 { \
167 .name = #_item, \
168 .type = \
169 { \
170 .atype = atype_sequence, \
46d52200 171 .u = \
1c324e59 172 { \
46d52200
ZT
173 .sequence = \
174 { \
175 .length_type = __type_integer(_length_type, BYTE_ORDER, 10, none), \
176 .elem_type = __type_integer(_type, BYTE_ORDER, 10, _encoding), \
177 }, \
1c324e59
MD
178 }, \
179 }, \
180901e6 180 .nowrite = _nowrite, \
1c324e59
MD
181 },
182
4774c8f3 183#undef _ctf_string
180901e6 184#define _ctf_string(_item, _src, _nowrite) \
1c324e59
MD
185 { \
186 .name = #_item, \
187 .type = \
188 { \
189 .atype = atype_string, \
46d52200
ZT
190 .u = \
191 { \
192 .basic = { .string = { .encoding = lttng_encode_UTF8 } } \
193 }, \
1c324e59 194 }, \
180901e6 195 .nowrite = _nowrite, \
1c324e59
MD
196 },
197
198#undef TP_FIELDS
2eda209b 199#define TP_FIELDS(...) __VA_ARGS__ /* Only one used in this phase */
1c324e59
MD
200
201#undef TRACEPOINT_EVENT_CLASS
202#define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
203 static const struct lttng_event_field __event_fields___##_provider##___##_name[] = { \
204 _fields \
205 };
206
207#include TRACEPOINT_INCLUDE
208
209/*
210 * Stage 2 of tracepoint event generation.
211 *
212 * Create probe callback prototypes.
213 */
214
215/* Reset all macros within TRACEPOINT_EVENT */
216#include <lttng/ust-tracepoint-event-reset.h>
217
218#undef TP_ARGS
2eda209b 219#define TP_ARGS(...) __VA_ARGS__
1c324e59
MD
220
221#undef TRACEPOINT_EVENT_CLASS
222#define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
223static void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args));
224
225#include TRACEPOINT_INCLUDE
226
227/*
228 * Stage 3 of tracepoint event generation.
229 *
1c324e59
MD
230 * Create static inline function that calculates event size.
231 */
232
233/* Reset all macros within TRACEPOINT_EVENT */
234#include <lttng/ust-tracepoint-event-reset.h>
4774c8f3 235#include <lttng/ust-tracepoint-event-write.h>
1c324e59 236
4774c8f3 237#undef _ctf_integer_ext
180901e6 238#define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
1c324e59
MD
239 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
240 __event_len += sizeof(_type);
241
4774c8f3 242#undef _ctf_float
180901e6 243#define _ctf_float(_type, _item, _src, _nowrite) \
1c324e59
MD
244 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
245 __event_len += sizeof(_type);
246
4774c8f3 247#undef _ctf_array_encoded
180901e6 248#define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _nowrite) \
1c324e59
MD
249 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
250 __event_len += sizeof(_type) * (_length);
251
4774c8f3
MD
252#undef _ctf_sequence_encoded
253#define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
180901e6 254 _src_length, _encoding, _nowrite) \
1c324e59
MD
255 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_length_type)); \
256 __event_len += sizeof(_length_type); \
257 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
258 __dynamic_len[__dynamic_len_idx] = (_src_length); \
259 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
260 __dynamic_len_idx++;
261
4774c8f3 262#undef _ctf_string
180901e6 263#define _ctf_string(_item, _src, _nowrite) \
1c324e59
MD
264 __event_len += __dynamic_len[__dynamic_len_idx++] = strlen(_src) + 1;
265
266#undef TP_ARGS
2eda209b 267#define TP_ARGS(...) __VA_ARGS__
1c324e59
MD
268
269#undef TP_FIELDS
2eda209b 270#define TP_FIELDS(...) __VA_ARGS__
1c324e59
MD
271
272#undef TRACEPOINT_EVENT_CLASS
a8909ba5
PW
273#define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
274static inline lttng_ust_notrace \
275size_t __event_get_size__##_provider##___##_name(size_t *__dynamic_len, _TP_ARGS_DATA_PROTO(_args)); \
276static inline \
277size_t __event_get_size__##_provider##___##_name(size_t *__dynamic_len, _TP_ARGS_DATA_PROTO(_args)) \
1c324e59
MD
278{ \
279 size_t __event_len = 0; \
280 unsigned int __dynamic_len_idx = 0; \
281 \
282 if (0) \
283 (void) __dynamic_len_idx; /* don't warn if unused */ \
284 _fields \
285 return __event_len; \
286}
287
288#include TRACEPOINT_INCLUDE
289
1ddfd641
MD
290/*
291 * Stage 3.1 of tracepoint event generation.
292 *
293 * Create static inline function that layout the filter stack data.
4774c8f3 294 * We make both write and nowrite data available to the filter.
1ddfd641
MD
295 */
296
297/* Reset all macros within TRACEPOINT_EVENT */
298#include <lttng/ust-tracepoint-event-reset.h>
4774c8f3
MD
299#include <lttng/ust-tracepoint-event-write.h>
300#include <lttng/ust-tracepoint-event-nowrite.h>
1ddfd641 301
4774c8f3 302#undef _ctf_integer_ext
180901e6 303#define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
fa099471 304 if (lttng_is_signed_type(_type)) { \
3ebeea0d
MD
305 int64_t __ctf_tmp_int64; \
306 switch (sizeof(_type)) { \
307 case 1: \
308 { \
309 union { _type t; int8_t v; } __tmp = { (_type) (_src) }; \
310 __ctf_tmp_int64 = (int64_t) __tmp.v; \
311 break; \
312 } \
313 case 2: \
314 { \
315 union { _type t; int16_t v; } __tmp = { (_type) (_src) }; \
316 __ctf_tmp_int64 = (int64_t) __tmp.v; \
317 break; \
318 } \
319 case 4: \
320 { \
321 union { _type t; int32_t v; } __tmp = { (_type) (_src) }; \
322 __ctf_tmp_int64 = (int64_t) __tmp.v; \
323 break; \
324 } \
325 case 8: \
326 { \
327 union { _type t; int64_t v; } __tmp = { (_type) (_src) }; \
328 __ctf_tmp_int64 = (int64_t) __tmp.v; \
329 break; \
330 } \
331 default: \
332 abort(); \
333 }; \
fa099471
MD
334 memcpy(__stack_data, &__ctf_tmp_int64, sizeof(int64_t)); \
335 } else { \
3ebeea0d
MD
336 uint64_t __ctf_tmp_uint64; \
337 switch (sizeof(_type)) { \
338 case 1: \
339 { \
340 union { _type t; uint8_t v; } __tmp = { (_type) (_src) }; \
341 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
342 break; \
343 } \
344 case 2: \
345 { \
346 union { _type t; uint16_t v; } __tmp = { (_type) (_src) }; \
347 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
348 break; \
349 } \
350 case 4: \
351 { \
352 union { _type t; uint32_t v; } __tmp = { (_type) (_src) }; \
353 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
354 break; \
355 } \
356 case 8: \
357 { \
358 union { _type t; uint64_t v; } __tmp = { (_type) (_src) }; \
359 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
360 break; \
361 } \
362 default: \
363 abort(); \
364 }; \
fa099471
MD
365 memcpy(__stack_data, &__ctf_tmp_uint64, sizeof(uint64_t)); \
366 } \
1ddfd641
MD
367 __stack_data += sizeof(int64_t);
368
4774c8f3 369#undef _ctf_float
180901e6 370#define _ctf_float(_type, _item, _src, _nowrite) \
fa099471
MD
371 { \
372 double __ctf_tmp_double = (double) (_type) (_src); \
373 memcpy(__stack_data, &__ctf_tmp_double, sizeof(double)); \
374 __stack_data += sizeof(double); \
375 }
1ddfd641 376
4774c8f3 377#undef _ctf_array_encoded
180901e6 378#define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _nowrite) \
fa099471
MD
379 { \
380 unsigned long __ctf_tmp_ulong = (unsigned long) (_length); \
59034aab 381 const void *__ctf_tmp_ptr = (_src); \
fa099471
MD
382 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
383 __stack_data += sizeof(unsigned long); \
c4261b0a 384 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void **)); \
fa099471
MD
385 __stack_data += sizeof(void **); \
386 }
1ddfd641 387
4774c8f3
MD
388#undef _ctf_sequence_encoded
389#define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
180901e6 390 _src_length, _encoding, _nowrite) \
fa099471
MD
391 { \
392 unsigned long __ctf_tmp_ulong = (unsigned long) (_src_length); \
59034aab 393 const void *__ctf_tmp_ptr = (_src); \
fa099471
MD
394 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
395 __stack_data += sizeof(unsigned long); \
c4261b0a 396 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void **)); \
fa099471
MD
397 __stack_data += sizeof(void **); \
398 }
1ddfd641 399
4774c8f3 400#undef _ctf_string
180901e6 401#define _ctf_string(_item, _src, _nowrite) \
fa099471 402 { \
59034aab 403 const void *__ctf_tmp_ptr = (_src); \
c4261b0a 404 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void **)); \
27f4b609 405 __stack_data += sizeof(void **); \
fa099471 406 }
1ddfd641
MD
407
408#undef TP_ARGS
409#define TP_ARGS(...) __VA_ARGS__
410
411#undef TP_FIELDS
412#define TP_FIELDS(...) __VA_ARGS__
413
414#undef TRACEPOINT_EVENT_CLASS
415#define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
416static inline \
417void __event_prepare_filter_stack__##_provider##___##_name(char *__stack_data,\
418 _TP_ARGS_DATA_PROTO(_args)) \
419{ \
420 _fields \
421}
422
423#include TRACEPOINT_INCLUDE
424
425
426
1c324e59 427/*
df854e41 428 * Stage 4 of tracepoint event generation.
1c324e59
MD
429 *
430 * Create static inline function that calculates event payload alignment.
431 */
432
433/* Reset all macros within TRACEPOINT_EVENT */
434#include <lttng/ust-tracepoint-event-reset.h>
4774c8f3 435#include <lttng/ust-tracepoint-event-write.h>
1c324e59 436
4774c8f3 437#undef _ctf_integer_ext
180901e6 438#define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
1c324e59
MD
439 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
440
4774c8f3 441#undef _ctf_float
180901e6 442#define _ctf_float(_type, _item, _src, _nowrite) \
1c324e59
MD
443 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
444
4774c8f3 445#undef _ctf_array_encoded
180901e6 446#define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _nowrite) \
1c324e59
MD
447 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
448
4774c8f3
MD
449#undef _ctf_sequence_encoded
450#define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
180901e6 451 _src_length, _encoding, _nowrite) \
1c324e59
MD
452 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_length_type)); \
453 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
454
4774c8f3 455#undef _ctf_string
180901e6 456#define _ctf_string(_item, _src, _nowrite)
1c324e59
MD
457
458#undef TP_ARGS
2eda209b 459#define TP_ARGS(...) __VA_ARGS__
1c324e59
MD
460
461#undef TP_FIELDS
2eda209b 462#define TP_FIELDS(...) __VA_ARGS__
1c324e59
MD
463
464#undef TRACEPOINT_EVENT_CLASS
465#define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
a8909ba5
PW
466static inline lttng_ust_notrace \
467size_t __event_get_align__##_provider##___##_name(_TP_ARGS_PROTO(_args)); \
1c324e59
MD
468static inline \
469size_t __event_get_align__##_provider##___##_name(_TP_ARGS_PROTO(_args)) \
470{ \
471 size_t __event_align = 1; \
472 _fields \
473 return __event_align; \
474}
475
476#include TRACEPOINT_INCLUDE
477
478
479/*
df854e41 480 * Stage 5 of tracepoint event generation.
1c324e59
MD
481 *
482 * Create the probe function. This function calls event size calculation
483 * and writes event data into the buffer.
484 */
485
486/* Reset all macros within TRACEPOINT_EVENT */
487#include <lttng/ust-tracepoint-event-reset.h>
4774c8f3 488#include <lttng/ust-tracepoint-event-write.h>
1c324e59 489
4774c8f3 490#undef _ctf_integer_ext
180901e6 491#define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
1c324e59
MD
492 { \
493 _type __tmp = (_src); \
494 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp));\
495 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
496 }
497
4774c8f3 498#undef _ctf_float
180901e6 499#define _ctf_float(_type, _item, _src, _nowrite) \
1c324e59
MD
500 { \
501 _type __tmp = (_src); \
502 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp));\
503 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
504 }
505
4774c8f3 506#undef _ctf_array_encoded
180901e6 507#define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _nowrite) \
1c324e59
MD
508 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
509 __chan->ops->event_write(&__ctx, _src, sizeof(_type) * (_length));
510
4774c8f3
MD
511#undef _ctf_sequence_encoded
512#define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
180901e6 513 _src_length, _encoding, _nowrite) \
1c324e59 514 { \
d71b57b9 515 _length_type __tmpl = __stackvar.__dynamic_len[__dynamic_len_idx]; \
1c324e59
MD
516 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_length_type));\
517 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(_length_type));\
518 } \
519 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
520 __chan->ops->event_write(&__ctx, _src, \
521 sizeof(_type) * __get_dynamic_len(dest));
522
4774c8f3 523#undef _ctf_string
180901e6 524#define _ctf_string(_item, _src, _nowrite) \
1c324e59
MD
525 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(*(_src))); \
526 __chan->ops->event_write(&__ctx, _src, __get_dynamic_len(dest));
527
528/* Beware: this get len actually consumes the len value */
529#undef __get_dynamic_len
d71b57b9 530#define __get_dynamic_len(field) __stackvar.__dynamic_len[__dynamic_len_idx++]
1c324e59
MD
531
532#undef TP_ARGS
2eda209b 533#define TP_ARGS(...) __VA_ARGS__
1c324e59
MD
534
535#undef TP_FIELDS
2eda209b 536#define TP_FIELDS(...) __VA_ARGS__
1c324e59 537
95c25348
PW
538/*
539 * For state dump, check that "session" argument (mandatory) matches the
540 * session this event belongs to. Ensures that we write state dump data only
541 * into the started session, not into all sessions.
542 */
543#undef _TP_SESSION_CHECK
544#ifdef TP_SESSION_CHECK
545#define _TP_SESSION_CHECK(session, csession) (session == csession)
546#else /* TP_SESSION_CHECK */
547#define _TP_SESSION_CHECK(session, csession) 1
548#endif /* TP_SESSION_CHECK */
549
1ddfd641
MD
550/*
551 * Using twice size for filter stack data to hold size and pointer for
552 * each field (worse case). For integers, max size required is 64-bit.
553 * Same for double-precision floats. Those fit within
554 * 2*sizeof(unsigned long) for all supported architectures.
61ce3223 555 * Perform UNION (||) of filter runtime list.
1ddfd641 556 */
1c324e59
MD
557#undef TRACEPOINT_EVENT_CLASS
558#define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
a8909ba5
PW
559static lttng_ust_notrace \
560void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)); \
561static \
562void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)) \
1c324e59 563{ \
46d52200 564 struct lttng_event *__event = (struct lttng_event *) __tp_data; \
7dd08bec 565 struct lttng_channel *__chan = __event->chan; \
f280cb51 566 struct lttng_ust_lib_ring_buffer_ctx __ctx; \
1c324e59
MD
567 size_t __event_len, __event_align; \
568 size_t __dynamic_len_idx = 0; \
d71b57b9 569 union { \
1ddfd641
MD
570 size_t __dynamic_len[_TP_ARRAY_SIZE(__event_fields___##_provider##___##_name)]; \
571 char __filter_stack_data[2 * sizeof(unsigned long) * _TP_ARRAY_SIZE(__event_fields___##_provider##___##_name)]; \
d71b57b9 572 } __stackvar; \
1c324e59
MD
573 int __ret; \
574 \
575 if (0) \
576 (void) __dynamic_len_idx; /* don't warn if unused */ \
95c25348
PW
577 if (!_TP_SESSION_CHECK(session, __chan->session)) \
578 return; \
1c324e59
MD
579 if (caa_unlikely(!CMM_ACCESS_ONCE(__chan->session->active))) \
580 return; \
581 if (caa_unlikely(!CMM_ACCESS_ONCE(__chan->enabled))) \
582 return; \
583 if (caa_unlikely(!CMM_ACCESS_ONCE(__event->enabled))) \
584 return; \
1b436e01
MD
585 if (caa_unlikely(!TP_RCU_LINK_TEST())) \
586 return; \
e58095ef 587 if (caa_unlikely(!cds_list_empty(&__event->bytecode_runtime_head))) { \
f488575f 588 struct lttng_bytecode_runtime *bc_runtime; \
dcdeaff0 589 int __filter_record = __event->has_enablers_without_bytecode; \
f488575f 590 \
1ddfd641 591 __event_prepare_filter_stack__##_provider##___##_name(__stackvar.__filter_stack_data, \
f488575f 592 _TP_ARGS_DATA_VAR(_args)); \
000b8662 593 tp_list_for_each_entry_rcu(bc_runtime, &__event->bytecode_runtime_head, node) { \
61ce3223 594 if (caa_unlikely(bc_runtime->filter(bc_runtime, \
8a92ed2a
MD
595 __stackvar.__filter_stack_data) & LTTNG_FILTER_RECORD_FLAG)) \
596 __filter_record = 1; \
f488575f 597 } \
8a92ed2a 598 if (caa_likely(!__filter_record)) \
61ce3223 599 return; \
1ddfd641
MD
600 } \
601 __event_len = __event_get_size__##_provider##___##_name(__stackvar.__dynamic_len, \
1c324e59
MD
602 _TP_ARGS_DATA_VAR(_args)); \
603 __event_align = __event_get_align__##_provider##___##_name(_TP_ARGS_VAR(_args)); \
604 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, __event, __event_len, \
605 __event_align, -1, __chan->handle); \
96f85541 606 __ctx.ip = __builtin_return_address(0); \
1c324e59
MD
607 __ret = __chan->ops->event_reserve(&__ctx, __event->id); \
608 if (__ret < 0) \
609 return; \
610 _fields \
611 __chan->ops->event_commit(&__ctx); \
612}
613
614#include TRACEPOINT_INCLUDE
615
616#undef __get_dynamic_len
617
68755429
MD
618/*
619 * Stage 5.1 of tracepoint event generation.
620 *
621 * Create probe signature
622 */
623
624/* Reset all macros within TRACEPOINT_EVENT */
625#include <lttng/ust-tracepoint-event-reset.h>
626
627#undef TP_ARGS
2eda209b 628#define TP_ARGS(...) __VA_ARGS__
9eb06182
MD
629
630#define _TP_EXTRACT_STRING2(...) #__VA_ARGS__
68755429
MD
631
632#undef TRACEPOINT_EVENT_CLASS
633#define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
634const char __tp_event_signature___##_provider##___##_name[] = \
9eb06182 635 _TP_EXTRACT_STRING2(_args);
68755429
MD
636
637#include TRACEPOINT_INCLUDE
638
9eb06182
MD
639#undef _TP_EXTRACT_STRING2
640
05ceaafd 641/*
882a56d7 642 * Stage 6 of tracepoint event generation.
1c324e59 643 *
df854e41
MD
644 * Tracepoint loglevel mapping definition generation. We generate a
645 * symbol for each mapping for a provider/event to ensure at most a 1 to
646 * 1 mapping between events and loglevels. If the symbol is repeated,
647 * the compiler will complain.
05ceaafd
MD
648 */
649
650/* Reset all macros within TRACEPOINT_EVENT */
651#include <lttng/ust-tracepoint-event-reset.h>
652
653#undef TRACEPOINT_LOGLEVEL
457a6b58
MD
654#define TRACEPOINT_LOGLEVEL(__provider, __name, __loglevel) \
655static const int _loglevel_value___##__provider##___##__name = __loglevel; \
656static const int *_loglevel___##__provider##___##__name = \
657 &_loglevel_value___##__provider##___##__name;
df854e41
MD
658
659#include TRACEPOINT_INCLUDE
660
6ddc916d
MD
661/*
662 * Stage 6.1 of tracepoint event generation.
663 *
664 * Tracepoint UML URI info.
665 */
666
667/* Reset all macros within TRACEPOINT_EVENT */
668#include <lttng/ust-tracepoint-event-reset.h>
669
670#undef TRACEPOINT_MODEL_EMF_URI
671#define TRACEPOINT_MODEL_EMF_URI(__provider, __name, __uri) \
672static const char *_model_emf_uri___##__provider##___##__name = __uri;
673
674#include TRACEPOINT_INCLUDE
675
df854e41 676/*
882a56d7 677 * Stage 7.1 of tracepoint event generation.
df854e41
MD
678 *
679 * Create events description structures. We use a weakref because
680 * loglevels are optional. If not declared, the event will point to the
681 * a loglevel that contains NULL.
682 */
683
684/* Reset all macros within TRACEPOINT_EVENT */
685#include <lttng/ust-tracepoint-event-reset.h>
686
687#undef TRACEPOINT_EVENT_INSTANCE
688#define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
882a56d7
MD
689static const int * \
690 __ref_loglevel___##_provider##___##_name \
691 __attribute__((weakref ("_loglevel___" #_provider "___" #_name))); \
6ddc916d
MD
692static const char * \
693 __ref_model_emf_uri___##_provider##___##_name \
694 __attribute__((weakref ("_model_emf_uri___" #_provider "___" #_name)));\
df854e41 695const struct lttng_event_desc __event_desc___##_provider##_##_name = { \
df854e41 696 .name = #_provider ":" #_name, \
fbdeb5ec 697 .probe_callback = (void (*)(void)) &__event_probe__##_provider##___##_template,\
46d52200
ZT
698 .ctx = NULL, \
699 .fields = __event_fields___##_provider##___##_template, \
df854e41 700 .nr_fields = _TP_ARRAY_SIZE(__event_fields___##_provider##___##_template), \
882a56d7 701 .loglevel = &__ref_loglevel___##_provider##___##_name, \
68755429 702 .signature = __tp_event_signature___##_provider##___##_template, \
46d52200 703 .u = { .ext = { .model_emf_uri = &__ref_model_emf_uri___##_provider##___##_name } }, \
df854e41
MD
704};
705
706#include TRACEPOINT_INCLUDE
05ceaafd 707
df854e41 708/*
882a56d7 709 * Stage 7.2 of tracepoint event generation.
df854e41
MD
710 *
711 * Create array of events.
712 */
713
714/* Reset all macros within TRACEPOINT_EVENT */
715#include <lttng/ust-tracepoint-event-reset.h>
716
717#undef TRACEPOINT_EVENT_INSTANCE
718#define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
719 &__event_desc___##_provider##_##_name,
720
721static const struct lttng_event_desc *_TP_COMBINE_TOKENS(__event_desc___, TRACEPOINT_PROVIDER)[] = {
05ceaafd
MD
722#include TRACEPOINT_INCLUDE
723};
724
df854e41 725
05ceaafd 726/*
882a56d7 727 * Stage 8 of tracepoint event generation.
05ceaafd
MD
728 *
729 * Create a toplevel descriptor for the whole probe.
730 */
731
732/* non-const because list head will be modified when registered. */
733static struct lttng_probe_desc _TP_COMBINE_TOKENS(__probe_desc___, TRACEPOINT_PROVIDER) = {
df854e41 734 .provider = __tp_stringify(TRACEPOINT_PROVIDER),
05ceaafd
MD
735 .event_desc = _TP_COMBINE_TOKENS(__event_desc___, TRACEPOINT_PROVIDER),
736 .nr_events = _TP_ARRAY_SIZE(_TP_COMBINE_TOKENS(__event_desc___, TRACEPOINT_PROVIDER)),
46d52200
ZT
737 .head = { NULL, NULL },
738 .lazy_init_head = { NULL, NULL },
739 .lazy = 0,
71d31690
MD
740 .major = LTTNG_UST_PROVIDER_MAJOR,
741 .minor = LTTNG_UST_PROVIDER_MINOR,
05ceaafd
MD
742};
743
f0cc794d
MD
744static int _TP_COMBINE_TOKENS(__probe_register_refcount___, TRACEPOINT_PROVIDER);
745
05ceaafd 746/*
882a56d7 747 * Stage 9 of tracepoint event generation.
05ceaafd 748 *
1c324e59 749 * Register/unregister probes at module load/unload.
628e1d81
MD
750 *
751 * Generate the constructor as an externally visible symbol for use when
752 * linking the probe statically.
f0cc794d
MD
753 *
754 * Register refcount is protected by libc dynamic loader mutex.
1c324e59
MD
755 */
756
757/* Reset all macros within TRACEPOINT_EVENT */
758#include <lttng/ust-tracepoint-event-reset.h>
a8909ba5
PW
759static void lttng_ust_notrace __attribute__((constructor))
760_TP_COMBINE_TOKENS(__lttng_events_init__, TRACEPOINT_PROVIDER)(void);
761static void
1c324e59
MD
762_TP_COMBINE_TOKENS(__lttng_events_init__, TRACEPOINT_PROVIDER)(void)
763{
764 int ret;
765
f0cc794d
MD
766 if (_TP_COMBINE_TOKENS(__probe_register_refcount___,
767 TRACEPOINT_PROVIDER)++) {
768 return;
769 }
e8bd1da7
MD
770 /*
771 * __tracepoint_provider_check_ ## TRACEPOINT_PROVIDER() is a
772 * static inline function that ensures every probe PROVIDER
773 * argument match the provider within which they appear. It
774 * calls empty static inline functions, and therefore has no
775 * runtime effect. However, if it detects an error, a linker
776 * error will appear.
777 */
778 _TP_COMBINE_TOKENS(__tracepoint_provider_check_, TRACEPOINT_PROVIDER)();
7dd08bec 779 ret = lttng_probe_register(&_TP_COMBINE_TOKENS(__probe_desc___, TRACEPOINT_PROVIDER));
7d381d6e
MD
780 if (ret) {
781 fprintf(stderr, "LTTng-UST: Error (%d) while registering tracepoint probe. Duplicate registration of tracepoint probes having the same name is not allowed.\n", ret);
782 abort();
783 }
1c324e59
MD
784}
785
a8909ba5
PW
786static void lttng_ust_notrace __attribute__((destructor))
787_TP_COMBINE_TOKENS(__lttng_events_exit__, TRACEPOINT_PROVIDER)(void);
788static void
1c324e59
MD
789_TP_COMBINE_TOKENS(__lttng_events_exit__, TRACEPOINT_PROVIDER)(void)
790{
f0cc794d
MD
791 if (--_TP_COMBINE_TOKENS(__probe_register_refcount___,
792 TRACEPOINT_PROVIDER)) {
793 return;
794 }
7dd08bec 795 lttng_probe_unregister(&_TP_COMBINE_TOKENS(__probe_desc___, TRACEPOINT_PROVIDER));
1c324e59 796}
628e1d81
MD
797
798int _TP_COMBINE_TOKENS(__tracepoint_provider_, TRACEPOINT_PROVIDER);
This page took 0.066572 seconds and 4 git commands to generate.