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