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