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