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