tracepoint probe refactoring: Move provider name to provider descriptor
[lttng-ust.git] / include / lttng / ust-tracepoint-event.h
... / ...
CommitLineData
1/*
2 * SPDX-License-Identifier: MIT
3 *
4 * Copyright (C) 2011-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 */
6
7#include <stdint.h>
8#include <stdio.h>
9#include <stdlib.h>
10#include <urcu/compiler.h>
11#include <urcu/rculist.h>
12#include <lttng/ust-events.h>
13#include <lttng/ringbuffer-context.h>
14#include <lttng/ust-arch.h>
15#include <lttng/ust-compiler.h>
16#include <lttng/tracepoint.h>
17#include <lttng/ust-endian.h>
18#include <string.h>
19
20#define __LTTNG_UST_NULL_STRING "(null)"
21
22#undef tp_list_for_each_entry_rcu
23#define tp_list_for_each_entry_rcu(pos, head, member) \
24 for (pos = cds_list_entry(tp_rcu_dereference((head)->next), __typeof__(*pos), member); \
25 &pos->member != (head); \
26 pos = cds_list_entry(tp_rcu_dereference(pos->member.next), __typeof__(*pos), member))
27
28/*
29 * TRACEPOINT_EVENT_CLASS declares a class of tracepoints receiving the
30 * same arguments and having the same field layout.
31 *
32 * TRACEPOINT_EVENT_INSTANCE declares an instance of a tracepoint, with
33 * its own provider and name. It refers to a class (template).
34 *
35 * TRACEPOINT_EVENT declared both a class and an instance and does a
36 * direct mapping from the instance to the class.
37 */
38
39#undef TRACEPOINT_EVENT
40#define TRACEPOINT_EVENT(_provider, _name, _args, _fields) \
41 _TRACEPOINT_EVENT_CLASS(_provider, _name, \
42 _TP_PARAMS(_args), \
43 _TP_PARAMS(_fields)) \
44 _TRACEPOINT_EVENT_INSTANCE(_provider, _name, _name, \
45 _TP_PARAMS(_args))
46
47#undef TRACEPOINT_EVENT_CLASS
48#define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
49 _TRACEPOINT_EVENT_CLASS(_provider, _name, _TP_PARAMS(_args), _TP_PARAMS(_fields))
50
51#undef TRACEPOINT_EVENT_INSTANCE
52#define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
53 _TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _TP_PARAMS(_args))
54
55/* Helpers */
56#define _TP_ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
57
58#define _tp_max_t(type, x, y) \
59 ({ \
60 type __max1 = (x); \
61 type __max2 = (y); \
62 __max1 > __max2 ? __max1: __max2; \
63 })
64
65/*
66 * Stage 0 of tracepoint event generation.
67 *
68 * Check that each TRACEPOINT_EVENT provider argument match the
69 * TRACEPOINT_PROVIDER by creating dummy callbacks.
70 */
71
72/* Reset all macros within TRACEPOINT_EVENT */
73#include <lttng/ust-tracepoint-event-reset.h>
74
75static inline lttng_ust_notrace
76void _TP_COMBINE_TOKENS(__tracepoint_provider_mismatch_, TRACEPOINT_PROVIDER)(void);
77static inline
78void _TP_COMBINE_TOKENS(__tracepoint_provider_mismatch_, TRACEPOINT_PROVIDER)(void)
79{
80}
81
82#undef _TRACEPOINT_EVENT_CLASS
83#define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
84 __tracepoint_provider_mismatch_##_provider();
85
86#undef _TRACEPOINT_EVENT_INSTANCE
87#define _TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
88 __tracepoint_provider_mismatch_##_provider();
89
90static inline lttng_ust_notrace
91void _TP_COMBINE_TOKENS(__tracepoint_provider_check_, TRACEPOINT_PROVIDER)(void);
92static inline
93void _TP_COMBINE_TOKENS(__tracepoint_provider_check_, TRACEPOINT_PROVIDER)(void)
94{
95#include TRACEPOINT_INCLUDE
96}
97
98/*
99 * Stage 0.1 of tracepoint event generation.
100 *
101 * Check that each TRACEPOINT_EVENT provider:name does not exceed the
102 * tracepoint name length limit.
103 */
104
105/* Reset all macros within TRACEPOINT_EVENT */
106#include <lttng/ust-tracepoint-event-reset.h>
107
108#undef _TRACEPOINT_EVENT_INSTANCE
109#define _TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
110static const char \
111 __tp_name_len_check##_provider##___##_name[LTTNG_UST_ABI_SYM_NAME_LEN] \
112 __attribute__((unused)) = \
113 #_provider ":" #_name;
114
115#include TRACEPOINT_INCLUDE
116
117/*
118 * Stage 0.2 of tracepoint event generation.
119 *
120 * Create dummy trace prototypes for each event class, and for each used
121 * template. This will allow checking whether the prototypes from the
122 * class and the instance using the class actually match.
123 */
124
125/* Reset all macros within TRACEPOINT_EVENT */
126#include <lttng/ust-tracepoint-event-reset.h>
127
128#undef TP_ARGS
129#define TP_ARGS(...) __VA_ARGS__
130
131#undef _TRACEPOINT_EVENT_INSTANCE
132#define _TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
133void __event_template_proto___##_provider##___##_template(_TP_ARGS_DATA_PROTO(_args));
134
135#undef _TRACEPOINT_EVENT_CLASS
136#define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
137void __event_template_proto___##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args));
138
139#include TRACEPOINT_INCLUDE
140
141/*
142 * Stage 0.9 of tracepoint event generation
143 *
144 * Unfolding the enums
145 */
146#include <lttng/ust-tracepoint-event-reset.h>
147
148/* Enumeration entry (single value) */
149#undef ctf_enum_value
150#define ctf_enum_value(_string, _value) \
151 __LTTNG_COMPOUND_LITERAL(struct lttng_ust_enum_entry, { \
152 .struct_size = sizeof(struct lttng_ust_enum_entry), \
153 .start = { \
154 .value = lttng_is_signed_type(__typeof__(_value)) ? \
155 (long long) (_value) : (_value), \
156 .signedness = lttng_is_signed_type(__typeof__(_value)), \
157 }, \
158 .end = { \
159 .value = lttng_is_signed_type(__typeof__(_value)) ? \
160 (long long) (_value) : (_value), \
161 .signedness = lttng_is_signed_type(__typeof__(_value)), \
162 }, \
163 .string = (_string), \
164 }),
165
166/* Enumeration entry (range) */
167#undef ctf_enum_range
168#define ctf_enum_range(_string, _range_start, _range_end) \
169 __LTTNG_COMPOUND_LITERAL(struct lttng_ust_enum_entry, { \
170 .struct_size = sizeof(struct lttng_ust_enum_entry), \
171 .start = { \
172 .value = lttng_is_signed_type(__typeof__(_range_start)) ? \
173 (long long) (_range_start) : (_range_start), \
174 .signedness = lttng_is_signed_type(__typeof__(_range_start)), \
175 }, \
176 .end = { \
177 .value = lttng_is_signed_type(__typeof__(_range_end)) ? \
178 (long long) (_range_end) : (_range_end), \
179 .signedness = lttng_is_signed_type(__typeof__(_range_end)), \
180 }, \
181 .string = (_string), \
182 }),
183
184/* Enumeration entry (automatic value; follows the rules of CTF) */
185#undef ctf_enum_auto
186#define ctf_enum_auto(_string) \
187 __LTTNG_COMPOUND_LITERAL(struct lttng_ust_enum_entry, { \
188 .struct_size = sizeof(struct lttng_ust_enum_entry), \
189 .start = { \
190 .value = -1ULL, \
191 .signedness = 0, \
192 }, \
193 .end = { \
194 .value = -1ULL, \
195 .signedness = 0, \
196 }, \
197 .string = (_string), \
198 .options = LTTNG_UST_ENUM_ENTRY_OPTION_IS_AUTO, \
199 }),
200
201#undef TP_ENUM_VALUES
202#define TP_ENUM_VALUES(...) \
203 __VA_ARGS__
204
205#undef TRACEPOINT_ENUM
206#define TRACEPOINT_ENUM(_provider, _name, _values) \
207 struct lttng_ust_enum_entry *__enum_values__##_provider##_##_name[] = { \
208 _values \
209 ctf_enum_value("", 0) /* Dummy, 0-len array forbidden by C99. */ \
210 };
211#include TRACEPOINT_INCLUDE
212
213/*
214 * Stage 0.9.1
215 * Verifying array and sequence elements are of an integer type.
216 */
217
218/* Reset all macros within TRACEPOINT_EVENT */
219#include <lttng/ust-tracepoint-event-reset.h>
220#include <lttng/ust-tracepoint-event-write.h>
221#include <lttng/ust-tracepoint-event-nowrite.h>
222
223#undef _ctf_array_encoded
224#define _ctf_array_encoded(_type, _item, _src, _byte_order, \
225 _length, _encoding, _nowrite, \
226 _elem_type_base) \
227 _lttng_array_element_type_is_supported(_type, _item)
228
229#undef _ctf_sequence_encoded
230#define _ctf_sequence_encoded(_type, _item, _src, _byte_order, \
231 _length_type, _src_length, _encoding, _nowrite, \
232 _elem_type_base) \
233 _lttng_array_element_type_is_supported(_type, _item)
234
235#undef TP_FIELDS
236#define TP_FIELDS(...) __VA_ARGS__ /* Only one used in this phase */
237
238#undef _TRACEPOINT_EVENT_CLASS
239#define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
240 _fields
241
242#include TRACEPOINT_INCLUDE
243
244/*
245 * Stage 1 of tracepoint event generation.
246 *
247 * Create event field type metadata section.
248 * Each event produce an array of fields.
249 */
250
251/* Reset all macros within TRACEPOINT_EVENT */
252#include <lttng/ust-tracepoint-event-reset.h>
253#include <lttng/ust-tracepoint-event-write.h>
254#include <lttng/ust-tracepoint-event-nowrite.h>
255
256#undef _ctf_integer_ext
257#define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
258 __LTTNG_COMPOUND_LITERAL(struct lttng_ust_event_field, { \
259 .struct_size = sizeof(struct lttng_ust_event_field), \
260 .name = #_item, \
261 .type = lttng_ust_type_integer_define(_type, _byte_order, _base), \
262 .nowrite = _nowrite, \
263 .nofilter = 0, \
264 }),
265
266#undef _ctf_float
267#define _ctf_float(_type, _item, _src, _nowrite) \
268 __LTTNG_COMPOUND_LITERAL(struct lttng_ust_event_field, { \
269 .struct_size = sizeof(struct lttng_ust_event_field), \
270 .name = #_item, \
271 .type = lttng_ust_type_float_define(_type), \
272 .nowrite = _nowrite, \
273 .nofilter = 0, \
274 }),
275
276#undef _ctf_array_encoded
277#define _ctf_array_encoded(_type, _item, _src, _byte_order, \
278 _length, _encoding, _nowrite, \
279 _elem_type_base) \
280 __LTTNG_COMPOUND_LITERAL(struct lttng_ust_event_field, { \
281 .struct_size = sizeof(struct lttng_ust_event_field), \
282 .name = #_item, \
283 .type = (struct lttng_ust_type_common *) __LTTNG_COMPOUND_LITERAL(struct lttng_ust_type_array, { \
284 .parent = { \
285 .type = lttng_ust_type_array, \
286 }, \
287 .struct_size = sizeof(struct lttng_ust_type_array), \
288 .elem_type = lttng_ust_type_integer_define(_type, _byte_order, _elem_type_base), \
289 .length = _length, \
290 .alignment = 0, \
291 .encoding = lttng_ust_string_encoding_##_encoding, \
292 }), \
293 .nowrite = _nowrite, \
294 .nofilter = 0, \
295 }),
296
297#undef _ctf_sequence_encoded
298#define _ctf_sequence_encoded(_type, _item, _src, _byte_order, \
299 _length_type, _src_length, _encoding, _nowrite, \
300 _elem_type_base) \
301 __LTTNG_COMPOUND_LITERAL(struct lttng_ust_event_field, { \
302 .struct_size = sizeof(struct lttng_ust_event_field), \
303 .name = "_" #_item "_length", \
304 .type = lttng_ust_type_integer_define(_length_type, BYTE_ORDER, 10), \
305 .nowrite = _nowrite, \
306 .nofilter = 1, \
307 }), \
308 __LTTNG_COMPOUND_LITERAL(struct lttng_ust_event_field, { \
309 .struct_size = sizeof(struct lttng_ust_event_field), \
310 .name = #_item, \
311 .type = (struct lttng_ust_type_common *) __LTTNG_COMPOUND_LITERAL(struct lttng_ust_type_sequence, { \
312 .parent = { \
313 .type = lttng_ust_type_sequence, \
314 }, \
315 .struct_size = sizeof(struct lttng_ust_type_sequence), \
316 .length_name = "_" #_item "_length", \
317 .elem_type = lttng_ust_type_integer_define(_type, _byte_order, _elem_type_base), \
318 .alignment = 0, \
319 .encoding = lttng_ust_string_encoding_##_encoding, \
320 }), \
321 .nowrite = _nowrite, \
322 .nofilter = 0, \
323 }),
324
325#undef _ctf_string
326#define _ctf_string(_item, _src, _nowrite) \
327 __LTTNG_COMPOUND_LITERAL(struct lttng_ust_event_field, { \
328 .struct_size = sizeof(struct lttng_ust_event_field), \
329 .name = #_item, \
330 .type = (struct lttng_ust_type_common *) __LTTNG_COMPOUND_LITERAL(struct lttng_ust_type_string, { \
331 .parent = { \
332 .type = lttng_ust_type_string, \
333 }, \
334 .struct_size = sizeof(struct lttng_ust_type_string), \
335 .encoding = lttng_ust_string_encoding_UTF8, \
336 }), \
337 .nowrite = _nowrite, \
338 .nofilter = 0, \
339 }),
340
341#undef _ctf_enum
342#define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
343 __LTTNG_COMPOUND_LITERAL(struct lttng_ust_event_field, { \
344 .struct_size = sizeof(struct lttng_ust_event_field), \
345 .name = #_item, \
346 .type = (struct lttng_ust_type_common *) __LTTNG_COMPOUND_LITERAL(struct lttng_ust_type_enum, { \
347 .parent = { \
348 .type = lttng_ust_type_enum, \
349 }, \
350 .struct_size = sizeof(struct lttng_ust_type_enum), \
351 .desc = &__enum_##_provider##_##_name, \
352 .container_type = lttng_ust_type_integer_define(_type, BYTE_ORDER, 10), \
353 }), \
354 .nowrite = _nowrite, \
355 .nofilter = 0, \
356 }),
357
358#undef TP_FIELDS
359#define TP_FIELDS(...) __VA_ARGS__ /* Only one used in this phase */
360
361#undef _TRACEPOINT_EVENT_CLASS
362#define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
363 static struct lttng_ust_event_field *__event_fields___##_provider##___##_name[] = { \
364 _fields \
365 ctf_integer(int, dummy, 0) /* Dummy, C99 forbids 0-len array. */ \
366 };
367
368#undef TRACEPOINT_ENUM
369#define TRACEPOINT_ENUM(_provider, _name, _values) \
370 static struct lttng_ust_enum_desc __enum_##_provider##_##_name = { \
371 .struct_size = sizeof(struct lttng_ust_enum_desc), \
372 .name = #_provider "_" #_name, \
373 .entries = __enum_values__##_provider##_##_name, \
374 .nr_entries = _TP_ARRAY_SIZE(__enum_values__##_provider##_##_name) - 1, \
375 };
376
377#include TRACEPOINT_INCLUDE
378
379/*
380 * Stage 2 of tracepoint event generation.
381 *
382 * Create probe callback prototypes.
383 */
384
385/* Reset all macros within TRACEPOINT_EVENT */
386#include <lttng/ust-tracepoint-event-reset.h>
387
388#undef TP_ARGS
389#define TP_ARGS(...) __VA_ARGS__
390
391#undef _TRACEPOINT_EVENT_CLASS
392#define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
393static void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args));
394
395#include TRACEPOINT_INCLUDE
396
397/*
398 * Stage 3.0 of tracepoint event generation.
399 *
400 * Create static inline function that calculates event size.
401 */
402
403/* Reset all macros within TRACEPOINT_EVENT */
404#include <lttng/ust-tracepoint-event-reset.h>
405#include <lttng/ust-tracepoint-event-write.h>
406
407#undef _ctf_integer_ext
408#define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
409 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
410 __event_len += sizeof(_type);
411
412#undef _ctf_float
413#define _ctf_float(_type, _item, _src, _nowrite) \
414 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
415 __event_len += sizeof(_type);
416
417#undef _ctf_array_encoded
418#define _ctf_array_encoded(_type, _item, _src, _byte_order, _length, _encoding, \
419 _nowrite, _elem_type_base) \
420 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
421 __event_len += sizeof(_type) * (_length);
422
423#undef _ctf_sequence_encoded
424#define _ctf_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
425 _src_length, _encoding, _nowrite, _elem_type_base) \
426 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_length_type)); \
427 __event_len += sizeof(_length_type); \
428 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
429 __dynamic_len[__dynamic_len_idx] = (_src_length); \
430 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
431 __dynamic_len_idx++;
432
433#undef _ctf_string
434#define _ctf_string(_item, _src, _nowrite) \
435 __event_len += __dynamic_len[__dynamic_len_idx++] = \
436 strlen((_src) ? (_src) : __LTTNG_UST_NULL_STRING) + 1;
437
438#undef _ctf_enum
439#define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
440 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
441
442#undef TP_ARGS
443#define TP_ARGS(...) __VA_ARGS__
444
445#undef TP_FIELDS
446#define TP_FIELDS(...) __VA_ARGS__
447
448#undef _TRACEPOINT_EVENT_CLASS
449#define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
450static inline lttng_ust_notrace \
451size_t __event_get_size__##_provider##___##_name(size_t *__dynamic_len, _TP_ARGS_DATA_PROTO(_args)); \
452static inline \
453size_t __event_get_size__##_provider##___##_name(size_t *__dynamic_len, _TP_ARGS_DATA_PROTO(_args)) \
454{ \
455 size_t __event_len = 0; \
456 unsigned int __dynamic_len_idx = 0; \
457 \
458 if (0) \
459 (void) __dynamic_len_idx; /* don't warn if unused */ \
460 _fields \
461 return __event_len; \
462}
463
464#include TRACEPOINT_INCLUDE
465
466/*
467 * Stage 3.1 of tracepoint event generation.
468 *
469 * Create static inline function that layout the filter stack data.
470 * We make both write and nowrite data available to the filter.
471 */
472
473/* Reset all macros within TRACEPOINT_EVENT */
474#include <lttng/ust-tracepoint-event-reset.h>
475#include <lttng/ust-tracepoint-event-write.h>
476#include <lttng/ust-tracepoint-event-nowrite.h>
477
478#undef _ctf_integer_ext
479#define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
480 if (lttng_is_signed_type(_type)) { \
481 int64_t __ctf_tmp_int64; \
482 switch (sizeof(_type)) { \
483 case 1: \
484 { \
485 union { _type t; int8_t v; } __tmp = { (_type) (_src) }; \
486 __ctf_tmp_int64 = (int64_t) __tmp.v; \
487 break; \
488 } \
489 case 2: \
490 { \
491 union { _type t; int16_t v; } __tmp = { (_type) (_src) }; \
492 if (_byte_order != BYTE_ORDER) \
493 __tmp.v = bswap_16(__tmp.v); \
494 __ctf_tmp_int64 = (int64_t) __tmp.v; \
495 break; \
496 } \
497 case 4: \
498 { \
499 union { _type t; int32_t v; } __tmp = { (_type) (_src) }; \
500 if (_byte_order != BYTE_ORDER) \
501 __tmp.v = bswap_32(__tmp.v); \
502 __ctf_tmp_int64 = (int64_t) __tmp.v; \
503 break; \
504 } \
505 case 8: \
506 { \
507 union { _type t; int64_t v; } __tmp = { (_type) (_src) }; \
508 if (_byte_order != BYTE_ORDER) \
509 __tmp.v = bswap_64(__tmp.v); \
510 __ctf_tmp_int64 = (int64_t) __tmp.v; \
511 break; \
512 } \
513 default: \
514 abort(); \
515 }; \
516 memcpy(__stack_data, &__ctf_tmp_int64, sizeof(int64_t)); \
517 } else { \
518 uint64_t __ctf_tmp_uint64; \
519 switch (sizeof(_type)) { \
520 case 1: \
521 { \
522 union { _type t; uint8_t v; } __tmp = { (_type) (_src) }; \
523 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
524 break; \
525 } \
526 case 2: \
527 { \
528 union { _type t; uint16_t v; } __tmp = { (_type) (_src) }; \
529 if (_byte_order != BYTE_ORDER) \
530 __tmp.v = bswap_16(__tmp.v); \
531 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
532 break; \
533 } \
534 case 4: \
535 { \
536 union { _type t; uint32_t v; } __tmp = { (_type) (_src) }; \
537 if (_byte_order != BYTE_ORDER) \
538 __tmp.v = bswap_32(__tmp.v); \
539 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
540 break; \
541 } \
542 case 8: \
543 { \
544 union { _type t; uint64_t v; } __tmp = { (_type) (_src) }; \
545 if (_byte_order != BYTE_ORDER) \
546 __tmp.v = bswap_64(__tmp.v); \
547 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
548 break; \
549 } \
550 default: \
551 abort(); \
552 }; \
553 memcpy(__stack_data, &__ctf_tmp_uint64, sizeof(uint64_t)); \
554 } \
555 __stack_data += sizeof(int64_t);
556
557#undef _ctf_float
558#define _ctf_float(_type, _item, _src, _nowrite) \
559 { \
560 double __ctf_tmp_double = (double) (_type) (_src); \
561 memcpy(__stack_data, &__ctf_tmp_double, sizeof(double)); \
562 __stack_data += sizeof(double); \
563 }
564
565#undef _ctf_array_encoded
566#define _ctf_array_encoded(_type, _item, _src, _byte_order, _length, \
567 _encoding, _nowrite, _elem_type_base) \
568 { \
569 unsigned long __ctf_tmp_ulong = (unsigned long) (_length); \
570 const void *__ctf_tmp_ptr = (_src); \
571 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
572 __stack_data += sizeof(unsigned long); \
573 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
574 __stack_data += sizeof(void *); \
575 }
576
577#undef _ctf_sequence_encoded
578#define _ctf_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
579 _src_length, _encoding, _nowrite, _elem_type_base) \
580 { \
581 unsigned long __ctf_tmp_ulong = (unsigned long) (_src_length); \
582 const void *__ctf_tmp_ptr = (_src); \
583 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
584 __stack_data += sizeof(unsigned long); \
585 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
586 __stack_data += sizeof(void *); \
587 }
588
589#undef _ctf_string
590#define _ctf_string(_item, _src, _nowrite) \
591 { \
592 const void *__ctf_tmp_ptr = \
593 ((_src) ? (_src) : __LTTNG_UST_NULL_STRING); \
594 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
595 __stack_data += sizeof(void *); \
596 }
597
598#undef _ctf_enum
599#define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
600 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
601
602#undef TP_ARGS
603#define TP_ARGS(...) __VA_ARGS__
604
605#undef TP_FIELDS
606#define TP_FIELDS(...) __VA_ARGS__
607
608#undef _TRACEPOINT_EVENT_CLASS
609#define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
610static inline \
611void __event_prepare_interpreter_stack__##_provider##___##_name(char *__stack_data,\
612 _TP_ARGS_DATA_PROTO(_args)) \
613{ \
614 _fields \
615}
616
617#include TRACEPOINT_INCLUDE
618
619/*
620 * Stage 4 of tracepoint event generation.
621 *
622 * Create static inline function that calculates event payload alignment.
623 */
624
625/* Reset all macros within TRACEPOINT_EVENT */
626#include <lttng/ust-tracepoint-event-reset.h>
627#include <lttng/ust-tracepoint-event-write.h>
628
629#undef _ctf_integer_ext
630#define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
631 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
632
633#undef _ctf_float
634#define _ctf_float(_type, _item, _src, _nowrite) \
635 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
636
637#undef _ctf_array_encoded
638#define _ctf_array_encoded(_type, _item, _src, _byte_order, _length, \
639 _encoding, _nowrite, _elem_type_base) \
640 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
641
642#undef _ctf_sequence_encoded
643#define _ctf_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
644 _src_length, _encoding, _nowrite, _elem_type_base) \
645 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_length_type)); \
646 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
647
648#undef _ctf_string
649#define _ctf_string(_item, _src, _nowrite)
650
651#undef _ctf_enum
652#define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
653 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
654
655#undef TP_ARGS
656#define TP_ARGS(...) __VA_ARGS__
657
658#undef TP_FIELDS
659#define TP_FIELDS(...) __VA_ARGS__
660
661#undef _TRACEPOINT_EVENT_CLASS
662#define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
663static inline lttng_ust_notrace \
664size_t __event_get_align__##_provider##___##_name(_TP_ARGS_PROTO(_args)); \
665static inline \
666size_t __event_get_align__##_provider##___##_name(_TP_ARGS_PROTO(_args)) \
667{ \
668 size_t __event_align = 1; \
669 _fields \
670 return __event_align; \
671}
672
673#include TRACEPOINT_INCLUDE
674
675
676/*
677 * Stage 5 of tracepoint event generation.
678 *
679 * Create the probe function. This function calls event size calculation
680 * and writes event data into the buffer.
681 */
682
683/* Reset all macros within TRACEPOINT_EVENT */
684#include <lttng/ust-tracepoint-event-reset.h>
685#include <lttng/ust-tracepoint-event-write.h>
686
687#undef _ctf_integer_ext
688#define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
689 { \
690 _type __tmp = (_src); \
691 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp));\
692 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
693 }
694
695#undef _ctf_float
696#define _ctf_float(_type, _item, _src, _nowrite) \
697 { \
698 _type __tmp = (_src); \
699 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp));\
700 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
701 }
702
703#undef _ctf_array_encoded
704#define _ctf_array_encoded(_type, _item, _src, _byte_order, _length, \
705 _encoding, _nowrite, _elem_type_base) \
706 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
707 if (lttng_ust_string_encoding_##_encoding == lttng_ust_string_encoding_none) \
708 __chan->ops->event_write(&__ctx, _src, sizeof(_type) * (_length)); \
709 else \
710 __chan->ops->event_pstrcpy_pad(&__ctx, (const char *) (_src), _length); \
711
712#undef _ctf_sequence_encoded
713#define _ctf_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
714 _src_length, _encoding, _nowrite, _elem_type_base) \
715 { \
716 _length_type __tmpl = __stackvar.__dynamic_len[__dynamic_len_idx]; \
717 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_length_type));\
718 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(_length_type));\
719 } \
720 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
721 if (lttng_ust_string_encoding_##_encoding == lttng_ust_string_encoding_none) \
722 __chan->ops->event_write(&__ctx, _src, \
723 sizeof(_type) * __get_dynamic_len(dest)); \
724 else \
725 __chan->ops->event_pstrcpy_pad(&__ctx, (const char *) (_src), __get_dynamic_len(dest)); \
726
727#undef _ctf_string
728#define _ctf_string(_item, _src, _nowrite) \
729 { \
730 const char *__ctf_tmp_string = \
731 ((_src) ? (_src) : __LTTNG_UST_NULL_STRING); \
732 lib_ring_buffer_align_ctx(&__ctx, \
733 lttng_alignof(*__ctf_tmp_string)); \
734 __chan->ops->event_strcpy(&__ctx, __ctf_tmp_string, \
735 __get_dynamic_len(dest)); \
736 }
737
738
739#undef _ctf_enum
740#define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
741 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
742
743/* Beware: this get len actually consumes the len value */
744#undef __get_dynamic_len
745#define __get_dynamic_len(field) __stackvar.__dynamic_len[__dynamic_len_idx++]
746
747#undef TP_ARGS
748#define TP_ARGS(...) __VA_ARGS__
749
750#undef TP_FIELDS
751#define TP_FIELDS(...) __VA_ARGS__
752
753/*
754 * For state dump, check that "session" argument (mandatory) matches the
755 * session this event belongs to. Ensures that we write state dump data only
756 * into the started session, not into all sessions.
757 */
758#undef _TP_SESSION_CHECK
759#ifdef TP_SESSION_CHECK
760#define _TP_SESSION_CHECK(session, csession) (session == csession)
761#else /* TP_SESSION_CHECK */
762#define _TP_SESSION_CHECK(session, csession) 1
763#endif /* TP_SESSION_CHECK */
764
765/*
766 * Use of __builtin_return_address(0) sometimes seems to cause stack
767 * corruption on 32-bit PowerPC. Disable this feature on that
768 * architecture for now by always using the NULL value for the ip
769 * context.
770 */
771#undef _TP_IP_PARAM
772#ifdef TP_IP_PARAM
773#define _TP_IP_PARAM(x) (x)
774#else /* TP_IP_PARAM */
775
776#if defined(LTTNG_UST_ARCH_PPC) && !defined(LTTNG_UST_ARCH_PPC64)
777#define _TP_IP_PARAM(x) NULL
778#else
779#define _TP_IP_PARAM(x) __builtin_return_address(0)
780#endif
781
782#endif /* TP_IP_PARAM */
783
784/*
785 * Using twice size for filter stack data to hold size and pointer for
786 * each field (worse case). For integers, max size required is 64-bit.
787 * Same for double-precision floats. Those fit within
788 * 2*sizeof(unsigned long) for all supported architectures.
789 * Perform UNION (||) of filter runtime list.
790 */
791#undef _TRACEPOINT_EVENT_CLASS
792#define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
793static lttng_ust_notrace \
794void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)); \
795static \
796void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)) \
797{ \
798 struct lttng_ust_event_common *__event = (struct lttng_ust_event_common *) __tp_data; \
799 size_t __dynamic_len_idx = 0; \
800 const size_t __num_fields = _TP_ARRAY_SIZE(__event_fields___##_provider##___##_name) - 1; \
801 union { \
802 size_t __dynamic_len[__num_fields]; \
803 char __interpreter_stack_data[2 * sizeof(unsigned long) * __num_fields]; \
804 } __stackvar; \
805 int __ret; \
806 bool __interpreter_stack_prepared = false; \
807 \
808 if (0) \
809 (void) __dynamic_len_idx; /* don't warn if unused */ \
810 switch (__event->type) { \
811 case LTTNG_UST_EVENT_TYPE_RECORDER: \
812 { \
813 struct lttng_ust_event_recorder *__event_recorder = (struct lttng_ust_event_recorder *) __event->child; \
814 struct lttng_ust_channel_buffer *__chan = __event_recorder->chan; \
815 struct lttng_ust_channel_common *__chan_common = __chan->parent; \
816 \
817 if (!_TP_SESSION_CHECK(session, __chan_common->session)) \
818 return; \
819 if (caa_unlikely(!CMM_ACCESS_ONCE(__chan_common->session->active))) \
820 return; \
821 if (caa_unlikely(!CMM_ACCESS_ONCE(__chan_common->enabled))) \
822 return; \
823 break; \
824 } \
825 case LTTNG_UST_EVENT_TYPE_NOTIFIER: \
826 break; \
827 } \
828 if (caa_unlikely(!CMM_ACCESS_ONCE(__event->enabled))) \
829 return; \
830 if (caa_unlikely(!TP_RCU_LINK_TEST())) \
831 return; \
832 if (caa_unlikely(CMM_ACCESS_ONCE(__event->eval_filter))) { \
833 __event_prepare_interpreter_stack__##_provider##___##_name(__stackvar.__interpreter_stack_data, \
834 _TP_ARGS_DATA_VAR(_args)); \
835 __interpreter_stack_prepared = true; \
836 if (caa_likely(__event->run_filter(__event, \
837 __stackvar.__interpreter_stack_data, NULL) != LTTNG_UST_EVENT_FILTER_ACCEPT)) \
838 return; \
839 } \
840 switch (__event->type) { \
841 case LTTNG_UST_EVENT_TYPE_RECORDER: \
842 { \
843 size_t __event_len, __event_align; \
844 struct lttng_ust_event_recorder *__event_recorder = (struct lttng_ust_event_recorder *) __event->child; \
845 struct lttng_ust_channel_buffer *__chan = __event_recorder->chan; \
846 struct lttng_ust_lib_ring_buffer_ctx __ctx; \
847 struct lttng_ust_stack_ctx __lttng_ctx; \
848 \
849 __event_len = __event_get_size__##_provider##___##_name(__stackvar.__dynamic_len, \
850 _TP_ARGS_DATA_VAR(_args)); \
851 __event_align = __event_get_align__##_provider##___##_name(_TP_ARGS_VAR(_args)); \
852 memset(&__lttng_ctx, 0, sizeof(__lttng_ctx)); \
853 __lttng_ctx.struct_size = sizeof(struct lttng_ust_stack_ctx); \
854 __lttng_ctx.event_recorder = __event_recorder; \
855 lib_ring_buffer_ctx_init(&__ctx, NULL, &__lttng_ctx, __event_len, __event_align); \
856 __ctx.ip = _TP_IP_PARAM(TP_IP_PARAM); \
857 __ret = __chan->ops->event_reserve(&__ctx, __event_recorder->id); \
858 if (__ret < 0) \
859 return; \
860 _fields \
861 __chan->ops->event_commit(&__ctx); \
862 break; \
863 } \
864 case LTTNG_UST_EVENT_TYPE_NOTIFIER: \
865 { \
866 struct lttng_ust_event_notifier *__event_notifier = (struct lttng_ust_event_notifier *) __event->child; \
867 struct lttng_ust_notification_ctx __notif_ctx; \
868 \
869 __notif_ctx.struct_size = sizeof(struct lttng_ust_notification_ctx); \
870 __notif_ctx.eval_capture = CMM_ACCESS_ONCE(__event_notifier->eval_capture); \
871 \
872 if (caa_unlikely(!__interpreter_stack_prepared && __notif_ctx.eval_capture)) \
873 __event_prepare_interpreter_stack__##_provider##___##_name(__stackvar.__interpreter_stack_data, \
874 _TP_ARGS_DATA_VAR(_args)); \
875 \
876 __event_notifier->notification_send(__event_notifier, \
877 __stackvar.__interpreter_stack_data, \
878 &__notif_ctx); \
879 break; \
880 } \
881 } \
882}
883
884#include TRACEPOINT_INCLUDE
885
886#undef __get_dynamic_len
887
888/*
889 * Stage 5.1 of tracepoint event generation.
890 *
891 * Create probe signature
892 */
893
894/* Reset all macros within TRACEPOINT_EVENT */
895#include <lttng/ust-tracepoint-event-reset.h>
896
897#undef TP_ARGS
898#define TP_ARGS(...) __VA_ARGS__
899
900#define _TP_EXTRACT_STRING2(...) #__VA_ARGS__
901
902#undef _TRACEPOINT_EVENT_CLASS
903#define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
904static const char __tp_event_signature___##_provider##___##_name[] = \
905 _TP_EXTRACT_STRING2(_args);
906
907#include TRACEPOINT_INCLUDE
908
909#undef _TP_EXTRACT_STRING2
910
911/*
912 * Stage 6 of tracepoint event generation.
913 *
914 * Tracepoint loglevel mapping definition generation. We generate a
915 * symbol for each mapping for a provider/event to ensure at most a 1 to
916 * 1 mapping between events and loglevels. If the symbol is repeated,
917 * the compiler will complain.
918 */
919
920/* Reset all macros within TRACEPOINT_EVENT */
921#include <lttng/ust-tracepoint-event-reset.h>
922
923/*
924 * Declare _loglevel___##__provider##___##__name as non-static, with
925 * hidden visibility for c++ handling of weakref. We do a weakref to the
926 * symbol in a later stage, which requires that the symbol is not
927 * mangled.
928 */
929#ifdef __cplusplus
930#define LTTNG_TP_EXTERN_C extern "C"
931#else
932#define LTTNG_TP_EXTERN_C
933#endif
934
935#undef TRACEPOINT_LOGLEVEL
936#define TRACEPOINT_LOGLEVEL(__provider, __name, __loglevel) \
937static const int _loglevel_value___##__provider##___##__name = __loglevel; \
938LTTNG_TP_EXTERN_C const int *_loglevel___##__provider##___##__name \
939 __attribute__((visibility("hidden"))) = \
940 &_loglevel_value___##__provider##___##__name;
941
942#include TRACEPOINT_INCLUDE
943
944#undef LTTNG_TP_EXTERN_C
945
946/*
947 * Stage 6.1 of tracepoint event generation.
948 *
949 * Tracepoint UML URI info.
950 */
951
952/* Reset all macros within TRACEPOINT_EVENT */
953#include <lttng/ust-tracepoint-event-reset.h>
954
955/*
956 * Declare _model_emf_uri___##__provider##___##__name as non-static,
957 * with hidden visibility for c++ handling of weakref. We do a weakref
958 * to the symbol in a later stage, which requires that the symbol is not
959 * mangled.
960 */
961#ifdef __cplusplus
962#define LTTNG_TP_EXTERN_C extern "C"
963#else
964#define LTTNG_TP_EXTERN_C
965#endif
966
967#undef TRACEPOINT_MODEL_EMF_URI
968#define TRACEPOINT_MODEL_EMF_URI(__provider, __name, __uri) \
969LTTNG_TP_EXTERN_C const char *_model_emf_uri___##__provider##___##__name \
970 __attribute__((visibility("hidden"))) = __uri; \
971
972#include TRACEPOINT_INCLUDE
973
974#undef LTTNG_TP_EXTERN_C
975
976/*
977 * Stage 7.0 of tracepoint event generation.
978 *
979 * Declare toplevel descriptor for the whole probe.
980 * Unlike C, C++ does not allow tentative definitions. Therefore, we
981 * need to explicitly declare the variable with "extern", using hidden
982 * visibility to keep this symbol from being exported to the global
983 * symbol table.
984 */
985
986extern struct lttng_ust_probe_desc _TP_COMBINE_TOKENS(__probe_desc___, TRACEPOINT_PROVIDER)
987 __attribute__((visibility("hidden")));
988
989/*
990 * Stage 7.1 of tracepoint event generation.
991 *
992 * Create events description structures. We use a weakref because
993 * loglevels are optional. If not declared, the event will point to the
994 * a loglevel that contains NULL.
995 */
996
997/* Reset all macros within TRACEPOINT_EVENT */
998#include <lttng/ust-tracepoint-event-reset.h>
999
1000#undef _TRACEPOINT_EVENT_INSTANCE
1001#define _TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
1002static const int * \
1003 __ref_loglevel___##_provider##___##_name \
1004 __attribute__((weakref ("_loglevel___" #_provider "___" #_name))); \
1005static const char * \
1006 __ref_model_emf_uri___##_provider##___##_name \
1007 __attribute__((weakref ("_model_emf_uri___" #_provider "___" #_name)));\
1008static struct lttng_ust_event_desc __event_desc___##_provider##_##_name = { \
1009 .struct_size = sizeof(struct lttng_ust_event_desc), \
1010 .event_name = #_name, \
1011 .probe_desc = &__probe_desc___##_provider, \
1012 .probe_callback = (void (*)(void)) &__event_probe__##_provider##___##_template, \
1013 .ctx = NULL, \
1014 .fields = __event_fields___##_provider##___##_template, \
1015 .nr_fields = _TP_ARRAY_SIZE(__event_fields___##_provider##___##_template) - 1, \
1016 .loglevel = &__ref_loglevel___##_provider##___##_name, \
1017 .signature = __tp_event_signature___##_provider##___##_template, \
1018 .model_emf_uri = &__ref_model_emf_uri___##_provider##___##_name, \
1019};
1020
1021#include TRACEPOINT_INCLUDE
1022
1023/*
1024 * Stage 7.2 of tracepoint event generation.
1025 *
1026 * Create array of events.
1027 */
1028
1029/* Reset all macros within TRACEPOINT_EVENT */
1030#include <lttng/ust-tracepoint-event-reset.h>
1031
1032#undef _TRACEPOINT_EVENT_INSTANCE
1033#define _TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
1034 &__event_desc___##_provider##_##_name,
1035
1036static struct lttng_ust_event_desc *_TP_COMBINE_TOKENS(__event_desc___, TRACEPOINT_PROVIDER)[] = {
1037#include TRACEPOINT_INCLUDE
1038 NULL, /* Dummy, C99 forbids 0-len array. */
1039};
1040
1041
1042/*
1043 * Stage 8 of tracepoint event generation.
1044 *
1045 * Create a toplevel descriptor for the whole probe.
1046 */
1047
1048struct lttng_ust_probe_desc _TP_COMBINE_TOKENS(__probe_desc___, TRACEPOINT_PROVIDER) = {
1049 .struct_size = sizeof(struct lttng_ust_probe_desc),
1050 .provider_name = __tp_stringify(TRACEPOINT_PROVIDER),
1051 .event_desc = _TP_COMBINE_TOKENS(__event_desc___, TRACEPOINT_PROVIDER),
1052 .nr_events = _TP_ARRAY_SIZE(_TP_COMBINE_TOKENS(__event_desc___, TRACEPOINT_PROVIDER)) - 1,
1053 .head = { NULL, NULL },
1054 .lazy_init_head = { NULL, NULL },
1055 .lazy = 0,
1056 .major = LTTNG_UST_PROVIDER_MAJOR,
1057 .minor = LTTNG_UST_PROVIDER_MINOR,
1058};
1059
1060static int _TP_COMBINE_TOKENS(__probe_register_refcount___, TRACEPOINT_PROVIDER);
1061
1062/*
1063 * Stage 9 of tracepoint event generation.
1064 *
1065 * Register/unregister probes at module load/unload.
1066 *
1067 * Generate the constructor as an externally visible symbol for use when
1068 * linking the probe statically.
1069 *
1070 * Register refcount is protected by libc dynamic loader mutex.
1071 */
1072
1073/* Reset all macros within TRACEPOINT_EVENT */
1074#include <lttng/ust-tracepoint-event-reset.h>
1075static void lttng_ust_notrace __attribute__((constructor))
1076_TP_COMBINE_TOKENS(__lttng_events_init__, TRACEPOINT_PROVIDER)(void);
1077static void
1078_TP_COMBINE_TOKENS(__lttng_events_init__, TRACEPOINT_PROVIDER)(void)
1079{
1080 int ret;
1081
1082 if (_TP_COMBINE_TOKENS(__probe_register_refcount___,
1083 TRACEPOINT_PROVIDER)++) {
1084 return;
1085 }
1086 /*
1087 * __tracepoint_provider_check_ ## TRACEPOINT_PROVIDER() is a
1088 * static inline function that ensures every probe PROVIDER
1089 * argument match the provider within which they appear. It
1090 * calls empty static inline functions, and therefore has no
1091 * runtime effect. However, if it detects an error, a linker
1092 * error will appear.
1093 */
1094 _TP_COMBINE_TOKENS(__tracepoint_provider_check_, TRACEPOINT_PROVIDER)();
1095 ret = lttng_ust_probe_register(&_TP_COMBINE_TOKENS(__probe_desc___, TRACEPOINT_PROVIDER));
1096 if (ret) {
1097 fprintf(stderr, "LTTng-UST: Error (%d) while registering tracepoint probe.\n", ret);
1098 abort();
1099 }
1100}
1101
1102static void lttng_ust_notrace __attribute__((destructor))
1103_TP_COMBINE_TOKENS(__lttng_events_exit__, TRACEPOINT_PROVIDER)(void);
1104static void
1105_TP_COMBINE_TOKENS(__lttng_events_exit__, TRACEPOINT_PROVIDER)(void)
1106{
1107 if (--_TP_COMBINE_TOKENS(__probe_register_refcount___,
1108 TRACEPOINT_PROVIDER)) {
1109 return;
1110 }
1111 lttng_ust_probe_unregister(&_TP_COMBINE_TOKENS(__probe_desc___, TRACEPOINT_PROVIDER));
1112}
1113
1114int _TP_COMBINE_TOKENS(__tracepoint_provider_, TRACEPOINT_PROVIDER)
1115__attribute__((visibility("default")));
This page took 0.027384 seconds and 4 git commands to generate.