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