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 MD |
109 | static const char \ |
110 | __tp_name_len_check##_provider##___##_name[LTTNG_UST_SYM_NAME_LEN] \ | |
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) \ | |
bb84a1ec | 424 | static void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)); \ |
d8d2416d FD |
425 | static void __event_notifier_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)); |
426 | ||
427 | #include TRACEPOINT_INCLUDE | |
428 | ||
1c324e59 | 429 | /* |
c785c634 | 430 | * Stage 3.0 of tracepoint event generation. |
1c324e59 | 431 | * |
1c324e59 MD |
432 | * Create static inline function that calculates event size. |
433 | */ | |
434 | ||
435 | /* Reset all macros within TRACEPOINT_EVENT */ | |
436 | #include <lttng/ust-tracepoint-event-reset.h> | |
4774c8f3 | 437 | #include <lttng/ust-tracepoint-event-write.h> |
1c324e59 | 438 | |
4774c8f3 | 439 | #undef _ctf_integer_ext |
180901e6 | 440 | #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \ |
1c324e59 MD |
441 | __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \ |
442 | __event_len += sizeof(_type); | |
443 | ||
4774c8f3 | 444 | #undef _ctf_float |
180901e6 | 445 | #define _ctf_float(_type, _item, _src, _nowrite) \ |
1c324e59 MD |
446 | __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \ |
447 | __event_len += sizeof(_type); | |
448 | ||
4774c8f3 | 449 | #undef _ctf_array_encoded |
f3ec4cb5 MD |
450 | #define _ctf_array_encoded(_type, _item, _src, _byte_order, _length, _encoding, \ |
451 | _nowrite, _elem_type_base) \ | |
1c324e59 MD |
452 | __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \ |
453 | __event_len += sizeof(_type) * (_length); | |
454 | ||
4774c8f3 | 455 | #undef _ctf_sequence_encoded |
48d660d1 | 456 | #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \ |
f968510a | 457 | _src_length, _encoding, _nowrite, _elem_type_base) \ |
1c324e59 MD |
458 | __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_length_type)); \ |
459 | __event_len += sizeof(_length_type); \ | |
460 | __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \ | |
461 | __dynamic_len[__dynamic_len_idx] = (_src_length); \ | |
462 | __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \ | |
463 | __dynamic_len_idx++; | |
464 | ||
4774c8f3 | 465 | #undef _ctf_string |
180901e6 | 466 | #define _ctf_string(_item, _src, _nowrite) \ |
24a39530 PP |
467 | __event_len += __dynamic_len[__dynamic_len_idx++] = \ |
468 | strlen((_src) ? (_src) : __LTTNG_UST_NULL_STRING) + 1; | |
1c324e59 | 469 | |
c785c634 MD |
470 | #undef _ctf_enum |
471 | #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \ | |
472 | _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite) | |
473 | ||
1c324e59 | 474 | #undef TP_ARGS |
2eda209b | 475 | #define TP_ARGS(...) __VA_ARGS__ |
1c324e59 MD |
476 | |
477 | #undef TP_FIELDS | |
2eda209b | 478 | #define TP_FIELDS(...) __VA_ARGS__ |
1c324e59 | 479 | |
f8021d08 CB |
480 | #undef _TRACEPOINT_EVENT_CLASS |
481 | #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \ | |
a8909ba5 PW |
482 | static inline lttng_ust_notrace \ |
483 | size_t __event_get_size__##_provider##___##_name(size_t *__dynamic_len, _TP_ARGS_DATA_PROTO(_args)); \ | |
484 | static inline \ | |
485 | size_t __event_get_size__##_provider##___##_name(size_t *__dynamic_len, _TP_ARGS_DATA_PROTO(_args)) \ | |
1c324e59 MD |
486 | { \ |
487 | size_t __event_len = 0; \ | |
488 | unsigned int __dynamic_len_idx = 0; \ | |
489 | \ | |
490 | if (0) \ | |
491 | (void) __dynamic_len_idx; /* don't warn if unused */ \ | |
492 | _fields \ | |
493 | return __event_len; \ | |
494 | } | |
495 | ||
496 | #include TRACEPOINT_INCLUDE | |
497 | ||
1ddfd641 MD |
498 | /* |
499 | * Stage 3.1 of tracepoint event generation. | |
500 | * | |
501 | * Create static inline function that layout the filter stack data. | |
4774c8f3 | 502 | * We make both write and nowrite data available to the filter. |
1ddfd641 MD |
503 | */ |
504 | ||
505 | /* Reset all macros within TRACEPOINT_EVENT */ | |
506 | #include <lttng/ust-tracepoint-event-reset.h> | |
4774c8f3 MD |
507 | #include <lttng/ust-tracepoint-event-write.h> |
508 | #include <lttng/ust-tracepoint-event-nowrite.h> | |
1ddfd641 | 509 | |
4774c8f3 | 510 | #undef _ctf_integer_ext |
180901e6 | 511 | #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \ |
fa099471 | 512 | if (lttng_is_signed_type(_type)) { \ |
3ebeea0d MD |
513 | int64_t __ctf_tmp_int64; \ |
514 | switch (sizeof(_type)) { \ | |
515 | case 1: \ | |
516 | { \ | |
517 | union { _type t; int8_t v; } __tmp = { (_type) (_src) }; \ | |
518 | __ctf_tmp_int64 = (int64_t) __tmp.v; \ | |
519 | break; \ | |
520 | } \ | |
521 | case 2: \ | |
522 | { \ | |
523 | union { _type t; int16_t v; } __tmp = { (_type) (_src) }; \ | |
39ad74cf MD |
524 | if (_byte_order != BYTE_ORDER) \ |
525 | __tmp.v = bswap_16(__tmp.v); \ | |
3ebeea0d MD |
526 | __ctf_tmp_int64 = (int64_t) __tmp.v; \ |
527 | break; \ | |
528 | } \ | |
529 | case 4: \ | |
530 | { \ | |
531 | union { _type t; int32_t v; } __tmp = { (_type) (_src) }; \ | |
39ad74cf MD |
532 | if (_byte_order != BYTE_ORDER) \ |
533 | __tmp.v = bswap_32(__tmp.v); \ | |
3ebeea0d MD |
534 | __ctf_tmp_int64 = (int64_t) __tmp.v; \ |
535 | break; \ | |
536 | } \ | |
537 | case 8: \ | |
538 | { \ | |
539 | union { _type t; int64_t v; } __tmp = { (_type) (_src) }; \ | |
39ad74cf MD |
540 | if (_byte_order != BYTE_ORDER) \ |
541 | __tmp.v = bswap_64(__tmp.v); \ | |
3ebeea0d MD |
542 | __ctf_tmp_int64 = (int64_t) __tmp.v; \ |
543 | break; \ | |
544 | } \ | |
545 | default: \ | |
546 | abort(); \ | |
547 | }; \ | |
fa099471 MD |
548 | memcpy(__stack_data, &__ctf_tmp_int64, sizeof(int64_t)); \ |
549 | } else { \ | |
3ebeea0d MD |
550 | uint64_t __ctf_tmp_uint64; \ |
551 | switch (sizeof(_type)) { \ | |
552 | case 1: \ | |
553 | { \ | |
554 | union { _type t; uint8_t v; } __tmp = { (_type) (_src) }; \ | |
555 | __ctf_tmp_uint64 = (uint64_t) __tmp.v; \ | |
556 | break; \ | |
557 | } \ | |
558 | case 2: \ | |
559 | { \ | |
560 | union { _type t; uint16_t v; } __tmp = { (_type) (_src) }; \ | |
39ad74cf MD |
561 | if (_byte_order != BYTE_ORDER) \ |
562 | __tmp.v = bswap_16(__tmp.v); \ | |
3ebeea0d MD |
563 | __ctf_tmp_uint64 = (uint64_t) __tmp.v; \ |
564 | break; \ | |
565 | } \ | |
566 | case 4: \ | |
567 | { \ | |
568 | union { _type t; uint32_t v; } __tmp = { (_type) (_src) }; \ | |
39ad74cf MD |
569 | if (_byte_order != BYTE_ORDER) \ |
570 | __tmp.v = bswap_32(__tmp.v); \ | |
3ebeea0d MD |
571 | __ctf_tmp_uint64 = (uint64_t) __tmp.v; \ |
572 | break; \ | |
573 | } \ | |
574 | case 8: \ | |
575 | { \ | |
576 | union { _type t; uint64_t v; } __tmp = { (_type) (_src) }; \ | |
39ad74cf MD |
577 | if (_byte_order != BYTE_ORDER) \ |
578 | __tmp.v = bswap_64(__tmp.v); \ | |
3ebeea0d MD |
579 | __ctf_tmp_uint64 = (uint64_t) __tmp.v; \ |
580 | break; \ | |
581 | } \ | |
582 | default: \ | |
583 | abort(); \ | |
584 | }; \ | |
fa099471 MD |
585 | memcpy(__stack_data, &__ctf_tmp_uint64, sizeof(uint64_t)); \ |
586 | } \ | |
1ddfd641 MD |
587 | __stack_data += sizeof(int64_t); |
588 | ||
4774c8f3 | 589 | #undef _ctf_float |
180901e6 | 590 | #define _ctf_float(_type, _item, _src, _nowrite) \ |
fa099471 MD |
591 | { \ |
592 | double __ctf_tmp_double = (double) (_type) (_src); \ | |
593 | memcpy(__stack_data, &__ctf_tmp_double, sizeof(double)); \ | |
594 | __stack_data += sizeof(double); \ | |
595 | } | |
1ddfd641 | 596 | |
4774c8f3 | 597 | #undef _ctf_array_encoded |
f3ec4cb5 MD |
598 | #define _ctf_array_encoded(_type, _item, _src, _byte_order, _length, \ |
599 | _encoding, _nowrite, _elem_type_base) \ | |
fa099471 MD |
600 | { \ |
601 | unsigned long __ctf_tmp_ulong = (unsigned long) (_length); \ | |
59034aab | 602 | const void *__ctf_tmp_ptr = (_src); \ |
fa099471 MD |
603 | memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \ |
604 | __stack_data += sizeof(unsigned long); \ | |
b1239ad6 MD |
605 | memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \ |
606 | __stack_data += sizeof(void *); \ | |
fa099471 | 607 | } |
1ddfd641 | 608 | |
4774c8f3 | 609 | #undef _ctf_sequence_encoded |
48d660d1 | 610 | #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \ |
f968510a | 611 | _src_length, _encoding, _nowrite, _elem_type_base) \ |
fa099471 MD |
612 | { \ |
613 | unsigned long __ctf_tmp_ulong = (unsigned long) (_src_length); \ | |
59034aab | 614 | const void *__ctf_tmp_ptr = (_src); \ |
fa099471 MD |
615 | memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \ |
616 | __stack_data += sizeof(unsigned long); \ | |
b1239ad6 MD |
617 | memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \ |
618 | __stack_data += sizeof(void *); \ | |
fa099471 | 619 | } |
1ddfd641 | 620 | |
4774c8f3 | 621 | #undef _ctf_string |
180901e6 | 622 | #define _ctf_string(_item, _src, _nowrite) \ |
fa099471 | 623 | { \ |
24a39530 PP |
624 | const void *__ctf_tmp_ptr = \ |
625 | ((_src) ? (_src) : __LTTNG_UST_NULL_STRING); \ | |
b1239ad6 MD |
626 | memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \ |
627 | __stack_data += sizeof(void *); \ | |
fa099471 | 628 | } |
1ddfd641 | 629 | |
c785c634 MD |
630 | #undef _ctf_enum |
631 | #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \ | |
632 | _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite) | |
633 | ||
1ddfd641 MD |
634 | #undef TP_ARGS |
635 | #define TP_ARGS(...) __VA_ARGS__ | |
636 | ||
637 | #undef TP_FIELDS | |
638 | #define TP_FIELDS(...) __VA_ARGS__ | |
639 | ||
f8021d08 CB |
640 | #undef _TRACEPOINT_EVENT_CLASS |
641 | #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \ | |
1ddfd641 | 642 | static inline \ |
d37ecb3f | 643 | void __event_prepare_interpreter_stack__##_provider##___##_name(char *__stack_data,\ |
1ddfd641 MD |
644 | _TP_ARGS_DATA_PROTO(_args)) \ |
645 | { \ | |
646 | _fields \ | |
647 | } | |
648 | ||
649 | #include TRACEPOINT_INCLUDE | |
650 | ||
1c324e59 | 651 | /* |
df854e41 | 652 | * Stage 4 of tracepoint event generation. |
1c324e59 MD |
653 | * |
654 | * Create static inline function that calculates event payload alignment. | |
655 | */ | |
656 | ||
657 | /* Reset all macros within TRACEPOINT_EVENT */ | |
658 | #include <lttng/ust-tracepoint-event-reset.h> | |
4774c8f3 | 659 | #include <lttng/ust-tracepoint-event-write.h> |
1c324e59 | 660 | |
4774c8f3 | 661 | #undef _ctf_integer_ext |
180901e6 | 662 | #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \ |
1c324e59 MD |
663 | __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type)); |
664 | ||
4774c8f3 | 665 | #undef _ctf_float |
180901e6 | 666 | #define _ctf_float(_type, _item, _src, _nowrite) \ |
1c324e59 MD |
667 | __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type)); |
668 | ||
4774c8f3 | 669 | #undef _ctf_array_encoded |
f3ec4cb5 MD |
670 | #define _ctf_array_encoded(_type, _item, _src, _byte_order, _length, \ |
671 | _encoding, _nowrite, _elem_type_base) \ | |
1c324e59 MD |
672 | __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type)); |
673 | ||
4774c8f3 | 674 | #undef _ctf_sequence_encoded |
48d660d1 | 675 | #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \ |
f968510a | 676 | _src_length, _encoding, _nowrite, _elem_type_base) \ |
1c324e59 MD |
677 | __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_length_type)); \ |
678 | __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type)); | |
679 | ||
4774c8f3 | 680 | #undef _ctf_string |
180901e6 | 681 | #define _ctf_string(_item, _src, _nowrite) |
1c324e59 | 682 | |
c785c634 MD |
683 | #undef _ctf_enum |
684 | #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \ | |
685 | _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite) | |
686 | ||
1c324e59 | 687 | #undef TP_ARGS |
2eda209b | 688 | #define TP_ARGS(...) __VA_ARGS__ |
1c324e59 MD |
689 | |
690 | #undef TP_FIELDS | |
2eda209b | 691 | #define TP_FIELDS(...) __VA_ARGS__ |
1c324e59 | 692 | |
f8021d08 CB |
693 | #undef _TRACEPOINT_EVENT_CLASS |
694 | #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \ | |
a8909ba5 PW |
695 | static inline lttng_ust_notrace \ |
696 | size_t __event_get_align__##_provider##___##_name(_TP_ARGS_PROTO(_args)); \ | |
1c324e59 MD |
697 | static inline \ |
698 | size_t __event_get_align__##_provider##___##_name(_TP_ARGS_PROTO(_args)) \ | |
699 | { \ | |
700 | size_t __event_align = 1; \ | |
701 | _fields \ | |
702 | return __event_align; \ | |
703 | } | |
704 | ||
705 | #include TRACEPOINT_INCLUDE | |
706 | ||
707 | ||
708 | /* | |
df854e41 | 709 | * Stage 5 of tracepoint event generation. |
1c324e59 MD |
710 | * |
711 | * Create the probe function. This function calls event size calculation | |
712 | * and writes event data into the buffer. | |
713 | */ | |
714 | ||
715 | /* Reset all macros within TRACEPOINT_EVENT */ | |
716 | #include <lttng/ust-tracepoint-event-reset.h> | |
4774c8f3 | 717 | #include <lttng/ust-tracepoint-event-write.h> |
1c324e59 | 718 | |
4774c8f3 | 719 | #undef _ctf_integer_ext |
180901e6 | 720 | #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \ |
1c324e59 MD |
721 | { \ |
722 | _type __tmp = (_src); \ | |
723 | lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp));\ | |
724 | __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\ | |
725 | } | |
726 | ||
4774c8f3 | 727 | #undef _ctf_float |
180901e6 | 728 | #define _ctf_float(_type, _item, _src, _nowrite) \ |
1c324e59 MD |
729 | { \ |
730 | _type __tmp = (_src); \ | |
731 | lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp));\ | |
732 | __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\ | |
733 | } | |
734 | ||
4774c8f3 | 735 | #undef _ctf_array_encoded |
f3ec4cb5 MD |
736 | #define _ctf_array_encoded(_type, _item, _src, _byte_order, _length, \ |
737 | _encoding, _nowrite, _elem_type_base) \ | |
1c324e59 MD |
738 | lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \ |
739 | __chan->ops->event_write(&__ctx, _src, sizeof(_type) * (_length)); | |
740 | ||
4774c8f3 | 741 | #undef _ctf_sequence_encoded |
48d660d1 | 742 | #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \ |
f968510a | 743 | _src_length, _encoding, _nowrite, _elem_type_base) \ |
1c324e59 | 744 | { \ |
d71b57b9 | 745 | _length_type __tmpl = __stackvar.__dynamic_len[__dynamic_len_idx]; \ |
1c324e59 MD |
746 | lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_length_type));\ |
747 | __chan->ops->event_write(&__ctx, &__tmpl, sizeof(_length_type));\ | |
748 | } \ | |
749 | lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \ | |
750 | __chan->ops->event_write(&__ctx, _src, \ | |
751 | sizeof(_type) * __get_dynamic_len(dest)); | |
752 | ||
4774c8f3 | 753 | #undef _ctf_string |
180901e6 | 754 | #define _ctf_string(_item, _src, _nowrite) \ |
24a39530 PP |
755 | { \ |
756 | const char *__ctf_tmp_string = \ | |
757 | ((_src) ? (_src) : __LTTNG_UST_NULL_STRING); \ | |
758 | lib_ring_buffer_align_ctx(&__ctx, \ | |
759 | lttng_alignof(*__ctf_tmp_string)); \ | |
f9ec4a97 MD |
760 | __chan->ops->event_strcpy(&__ctx, __ctf_tmp_string, \ |
761 | __get_dynamic_len(dest)); \ | |
24a39530 PP |
762 | } |
763 | ||
1c324e59 | 764 | |
c785c634 MD |
765 | #undef _ctf_enum |
766 | #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \ | |
767 | _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite) | |
768 | ||
1c324e59 MD |
769 | /* Beware: this get len actually consumes the len value */ |
770 | #undef __get_dynamic_len | |
d71b57b9 | 771 | #define __get_dynamic_len(field) __stackvar.__dynamic_len[__dynamic_len_idx++] |
1c324e59 MD |
772 | |
773 | #undef TP_ARGS | |
2eda209b | 774 | #define TP_ARGS(...) __VA_ARGS__ |
1c324e59 MD |
775 | |
776 | #undef TP_FIELDS | |
2eda209b | 777 | #define TP_FIELDS(...) __VA_ARGS__ |
1c324e59 | 778 | |
95c25348 PW |
779 | /* |
780 | * For state dump, check that "session" argument (mandatory) matches the | |
781 | * session this event belongs to. Ensures that we write state dump data only | |
782 | * into the started session, not into all sessions. | |
783 | */ | |
784 | #undef _TP_SESSION_CHECK | |
785 | #ifdef TP_SESSION_CHECK | |
786 | #define _TP_SESSION_CHECK(session, csession) (session == csession) | |
787 | #else /* TP_SESSION_CHECK */ | |
788 | #define _TP_SESSION_CHECK(session, csession) 1 | |
789 | #endif /* TP_SESSION_CHECK */ | |
790 | ||
97904b41 MD |
791 | /* |
792 | * Use of __builtin_return_address(0) sometimes seems to cause stack | |
793 | * corruption on 32-bit PowerPC. Disable this feature on that | |
794 | * architecture for now by always using the NULL value for the ip | |
795 | * context. | |
796 | */ | |
5dadb547 MD |
797 | #undef _TP_IP_PARAM |
798 | #ifdef TP_IP_PARAM | |
e1d09f9e | 799 | #define _TP_IP_PARAM(x) (x) |
5dadb547 | 800 | #else /* TP_IP_PARAM */ |
97904b41 MD |
801 | |
802 | #if defined(__PPC__) && !defined(__PPC64__) | |
803 | #define _TP_IP_PARAM(x) NULL | |
804 | #else /* #if defined(__PPC__) && !defined(__PPC64__) */ | |
e1d09f9e | 805 | #define _TP_IP_PARAM(x) __builtin_return_address(0) |
97904b41 MD |
806 | #endif /* #else #if defined(__PPC__) && !defined(__PPC64__) */ |
807 | ||
5dadb547 MD |
808 | #endif /* TP_IP_PARAM */ |
809 | ||
1ddfd641 MD |
810 | /* |
811 | * Using twice size for filter stack data to hold size and pointer for | |
812 | * each field (worse case). For integers, max size required is 64-bit. | |
813 | * Same for double-precision floats. Those fit within | |
814 | * 2*sizeof(unsigned long) for all supported architectures. | |
61ce3223 | 815 | * Perform UNION (||) of filter runtime list. |
1ddfd641 | 816 | */ |
f8021d08 CB |
817 | #undef _TRACEPOINT_EVENT_CLASS |
818 | #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \ | |
a8909ba5 PW |
819 | static lttng_ust_notrace \ |
820 | void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)); \ | |
821 | static \ | |
822 | void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)) \ | |
1c324e59 | 823 | { \ |
53569322 | 824 | struct lttng_event *__event = (struct lttng_event *) __tp_data; \ |
bb84a1ec MD |
825 | struct lttng_event_container *__container = __event->container; \ |
826 | struct lttng_session *__session = __container->session; \ | |
f280cb51 | 827 | struct lttng_ust_lib_ring_buffer_ctx __ctx; \ |
53569322 | 828 | struct lttng_stack_ctx __lttng_ctx; \ |
1c324e59 | 829 | size_t __dynamic_len_idx = 0; \ |
75026e9f | 830 | const size_t __num_fields = _TP_ARRAY_SIZE(__event_fields___##_provider##___##_name) - 1; \ |
d71b57b9 | 831 | union { \ |
75026e9f FD |
832 | size_t __dynamic_len[__num_fields]; \ |
833 | char __filter_stack_data[2 * sizeof(unsigned long) * __num_fields]; \ | |
d71b57b9 | 834 | } __stackvar; \ |
1c324e59 MD |
835 | int __ret; \ |
836 | \ | |
837 | if (0) \ | |
838 | (void) __dynamic_len_idx; /* don't warn if unused */ \ | |
bb84a1ec | 839 | if (!_TP_SESSION_CHECK(session, __container->session)) \ |
95c25348 | 840 | return; \ |
bb84a1ec | 841 | if (caa_unlikely(!CMM_ACCESS_ONCE(__session->active))) \ |
1c324e59 | 842 | return; \ |
bb84a1ec | 843 | if (caa_unlikely(!CMM_ACCESS_ONCE(__container->enabled))) \ |
1c324e59 MD |
844 | return; \ |
845 | if (caa_unlikely(!CMM_ACCESS_ONCE(__event->enabled))) \ | |
846 | return; \ | |
1b436e01 MD |
847 | if (caa_unlikely(!TP_RCU_LINK_TEST())) \ |
848 | return; \ | |
a56fd376 | 849 | if (caa_unlikely(!cds_list_empty(&__event->filter_bytecode_runtime_head))) { \ |
bb84a1ec | 850 | struct lttng_bytecode_runtime *__filter_bc_runtime; \ |
dcdeaff0 | 851 | int __filter_record = __event->has_enablers_without_bytecode; \ |
f488575f | 852 | \ |
d37ecb3f | 853 | __event_prepare_interpreter_stack__##_provider##___##_name(__stackvar.__filter_stack_data, \ |
f488575f | 854 | _TP_ARGS_DATA_VAR(_args)); \ |
a56fd376 | 855 | tp_list_for_each_entry_rcu(__filter_bc_runtime, &__event->filter_bytecode_runtime_head, node) { \ |
c42416df | 856 | if (caa_unlikely(__filter_bc_runtime->interpreter_funcs.filter(__filter_bc_runtime, \ |
04aa13f8 | 857 | __stackvar.__filter_stack_data) & LTTNG_INTERPRETER_RECORD_FLAG)) { \ |
8a92ed2a | 858 | __filter_record = 1; \ |
5ffb7c14 FD |
859 | break; \ |
860 | } \ | |
f488575f | 861 | } \ |
8a92ed2a | 862 | if (caa_likely(!__filter_record)) \ |
61ce3223 | 863 | return; \ |
1ddfd641 | 864 | } \ |
bb84a1ec MD |
865 | switch (__container->type) { \ |
866 | case LTTNG_EVENT_CONTAINER_CHANNEL: \ | |
867 | { \ | |
868 | struct lttng_channel *__chan = lttng_event_container_get_channel(__container); \ | |
869 | size_t __event_len, __event_align; \ | |
870 | \ | |
871 | __event_len = __event_get_size__##_provider##___##_name(__stackvar.__dynamic_len, \ | |
872 | _TP_ARGS_DATA_VAR(_args)); \ | |
873 | __event_align = __event_get_align__##_provider##___##_name(_TP_ARGS_VAR(_args)); \ | |
874 | memset(&__lttng_ctx, 0, sizeof(__lttng_ctx)); \ | |
875 | __lttng_ctx.event = __event; \ | |
876 | __lttng_ctx.chan_ctx = tp_rcu_dereference(__chan->ctx); \ | |
877 | __lttng_ctx.event_ctx = tp_rcu_dereference(__event->ctx); \ | |
878 | lib_ring_buffer_ctx_init(&__ctx, __chan->chan, __event, __event_len, \ | |
879 | __event_align, -1, __chan->handle, &__lttng_ctx); \ | |
880 | __ctx.ip = _TP_IP_PARAM(TP_IP_PARAM); \ | |
881 | __ret = __chan->ops->event_reserve(&__ctx, __event->id); \ | |
882 | if (__ret < 0) \ | |
883 | return; \ | |
884 | _fields \ | |
885 | __chan->ops->event_commit(&__ctx); \ | |
886 | break; \ | |
887 | } \ | |
888 | case LTTNG_EVENT_CONTAINER_COUNTER: \ | |
889 | { \ | |
890 | struct lttng_counter *__counter = lttng_event_container_get_counter(__container); \ | |
891 | size_t __index = __event->id; \ | |
892 | \ | |
893 | (void) __counter->ops->counter_add(__counter->counter, &__index, 1); \ | |
894 | break; \ | |
895 | } \ | |
896 | } \ | |
1c324e59 MD |
897 | } |
898 | ||
899 | #include TRACEPOINT_INCLUDE | |
900 | ||
901 | #undef __get_dynamic_len | |
902 | ||
68755429 MD |
903 | /* |
904 | * Stage 5.1 of tracepoint event generation. | |
905 | * | |
906 | * Create probe signature | |
907 | */ | |
908 | ||
909 | /* Reset all macros within TRACEPOINT_EVENT */ | |
910 | #include <lttng/ust-tracepoint-event-reset.h> | |
911 | ||
912 | #undef TP_ARGS | |
2eda209b | 913 | #define TP_ARGS(...) __VA_ARGS__ |
9eb06182 MD |
914 | |
915 | #define _TP_EXTRACT_STRING2(...) #__VA_ARGS__ | |
68755429 | 916 | |
f8021d08 CB |
917 | #undef _TRACEPOINT_EVENT_CLASS |
918 | #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \ | |
ff82b7c1 | 919 | static const char __tp_event_signature___##_provider##___##_name[] = \ |
9eb06182 | 920 | _TP_EXTRACT_STRING2(_args); |
68755429 MD |
921 | |
922 | #include TRACEPOINT_INCLUDE | |
923 | ||
9eb06182 MD |
924 | #undef _TP_EXTRACT_STRING2 |
925 | ||
d8d2416d FD |
926 | /* |
927 | * Stage 5.2 of tracepoint event generation. | |
928 | * | |
929 | * Create the event notifier probe function. | |
930 | */ | |
f8021d08 CB |
931 | #undef _TRACEPOINT_EVENT_CLASS |
932 | #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \ | |
d8d2416d FD |
933 | static lttng_ust_notrace \ |
934 | void __event_notifier_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)); \ | |
935 | static \ | |
936 | void __event_notifier_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)) \ | |
937 | { \ | |
938 | struct lttng_event_notifier *__event_notifier = (struct lttng_event_notifier *) __tp_data; \ | |
939 | const size_t __num_fields = _TP_ARRAY_SIZE(__event_fields___##_provider##___##_name) - 1;\ | |
940 | union { \ | |
941 | size_t __dynamic_len[__num_fields]; \ | |
d37ecb3f | 942 | char __interpreter_stack_data[2 * sizeof(unsigned long) * __num_fields]; \ |
d8d2416d | 943 | } __stackvar; \ |
cab88ff8 | 944 | \ |
d8d2416d FD |
945 | if (caa_unlikely(!CMM_ACCESS_ONCE(__event_notifier->enabled))) \ |
946 | return; \ | |
947 | if (caa_unlikely(!TP_RCU_LINK_TEST())) \ | |
948 | return; \ | |
949 | if (caa_unlikely(!cds_list_empty(&__event_notifier->filter_bytecode_runtime_head))) { \ | |
950 | struct lttng_bytecode_runtime *__filter_bc_runtime; \ | |
951 | int __filter_record = __event_notifier->has_enablers_without_bytecode; \ | |
952 | \ | |
d37ecb3f | 953 | __event_prepare_interpreter_stack__##_provider##___##_name(__stackvar.__interpreter_stack_data, \ |
d8d2416d FD |
954 | _TP_ARGS_DATA_VAR(_args)); \ |
955 | tp_list_for_each_entry_rcu(__filter_bc_runtime, &__event_notifier->filter_bytecode_runtime_head, node) { \ | |
c42416df | 956 | if (caa_unlikely(__filter_bc_runtime->interpreter_funcs.filter(__filter_bc_runtime, \ |
d37ecb3f | 957 | __stackvar.__interpreter_stack_data) & LTTNG_INTERPRETER_RECORD_FLAG)) \ |
d8d2416d FD |
958 | __filter_record = 1; \ |
959 | } \ | |
960 | if (caa_likely(!__filter_record)) \ | |
961 | return; \ | |
962 | } \ | |
d37ecb3f FD |
963 | if (caa_unlikely(!cds_list_empty(&__event_notifier->capture_bytecode_runtime_head))) \ |
964 | __event_prepare_interpreter_stack__##_provider##___##_name(__stackvar.__interpreter_stack_data, \ | |
965 | _TP_ARGS_DATA_VAR(_args)); \ | |
d8d2416d | 966 | \ |
cab88ff8 | 967 | __event_notifier->notification_send(__event_notifier, \ |
d37ecb3f | 968 | __stackvar.__interpreter_stack_data); \ |
d8d2416d FD |
969 | } |
970 | ||
971 | #include TRACEPOINT_INCLUDE | |
972 | ||
05ceaafd | 973 | /* |
882a56d7 | 974 | * Stage 6 of tracepoint event generation. |
1c324e59 | 975 | * |
df854e41 MD |
976 | * Tracepoint loglevel mapping definition generation. We generate a |
977 | * symbol for each mapping for a provider/event to ensure at most a 1 to | |
978 | * 1 mapping between events and loglevels. If the symbol is repeated, | |
979 | * the compiler will complain. | |
05ceaafd MD |
980 | */ |
981 | ||
982 | /* Reset all macros within TRACEPOINT_EVENT */ | |
983 | #include <lttng/ust-tracepoint-event-reset.h> | |
984 | ||
4ea4f80e MD |
985 | /* |
986 | * Declare _loglevel___##__provider##___##__name as non-static, with | |
987 | * hidden visibility for c++ handling of weakref. We do a weakref to the | |
988 | * symbol in a later stage, which requires that the symbol is not | |
989 | * mangled. | |
990 | */ | |
991 | #ifdef __cplusplus | |
992 | #define LTTNG_TP_EXTERN_C extern "C" | |
993 | #else | |
994 | #define LTTNG_TP_EXTERN_C | |
995 | #endif | |
996 | ||
05ceaafd | 997 | #undef TRACEPOINT_LOGLEVEL |
457a6b58 MD |
998 | #define TRACEPOINT_LOGLEVEL(__provider, __name, __loglevel) \ |
999 | static const int _loglevel_value___##__provider##___##__name = __loglevel; \ | |
4ea4f80e MD |
1000 | LTTNG_TP_EXTERN_C const int *_loglevel___##__provider##___##__name \ |
1001 | __attribute__((visibility("hidden"))) = \ | |
457a6b58 | 1002 | &_loglevel_value___##__provider##___##__name; |
df854e41 MD |
1003 | |
1004 | #include TRACEPOINT_INCLUDE | |
1005 | ||
4ea4f80e | 1006 | #undef LTTNG_TP_EXTERN_C |
4ea4f80e | 1007 | |
6ddc916d MD |
1008 | /* |
1009 | * Stage 6.1 of tracepoint event generation. | |
1010 | * | |
1011 | * Tracepoint UML URI info. | |
1012 | */ | |
1013 | ||
1014 | /* Reset all macros within TRACEPOINT_EVENT */ | |
1015 | #include <lttng/ust-tracepoint-event-reset.h> | |
1016 | ||
4ea4f80e MD |
1017 | /* |
1018 | * Declare _model_emf_uri___##__provider##___##__name as non-static, | |
1019 | * with hidden visibility for c++ handling of weakref. We do a weakref | |
1020 | * to the symbol in a later stage, which requires that the symbol is not | |
1021 | * mangled. | |
1022 | */ | |
1023 | #ifdef __cplusplus | |
1024 | #define LTTNG_TP_EXTERN_C extern "C" | |
1025 | #else | |
1026 | #define LTTNG_TP_EXTERN_C | |
1027 | #endif | |
1028 | ||
6ddc916d MD |
1029 | #undef TRACEPOINT_MODEL_EMF_URI |
1030 | #define TRACEPOINT_MODEL_EMF_URI(__provider, __name, __uri) \ | |
4ea4f80e | 1031 | LTTNG_TP_EXTERN_C const char *_model_emf_uri___##__provider##___##__name \ |
082802f9 | 1032 | __attribute__((visibility("hidden"))) = __uri; \ |
6ddc916d MD |
1033 | |
1034 | #include TRACEPOINT_INCLUDE | |
1035 | ||
4ea4f80e | 1036 | #undef LTTNG_TP_EXTERN_C |
4ea4f80e | 1037 | |
df854e41 | 1038 | /* |
882a56d7 | 1039 | * Stage 7.1 of tracepoint event generation. |
df854e41 MD |
1040 | * |
1041 | * Create events description structures. We use a weakref because | |
1042 | * loglevels are optional. If not declared, the event will point to the | |
1043 | * a loglevel that contains NULL. | |
1044 | */ | |
1045 | ||
1046 | /* Reset all macros within TRACEPOINT_EVENT */ | |
1047 | #include <lttng/ust-tracepoint-event-reset.h> | |
1048 | ||
f8021d08 CB |
1049 | #undef _TRACEPOINT_EVENT_INSTANCE |
1050 | #define _TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \ | |
882a56d7 MD |
1051 | static const int * \ |
1052 | __ref_loglevel___##_provider##___##_name \ | |
1053 | __attribute__((weakref ("_loglevel___" #_provider "___" #_name))); \ | |
6ddc916d MD |
1054 | static const char * \ |
1055 | __ref_model_emf_uri___##_provider##___##_name \ | |
1056 | __attribute__((weakref ("_model_emf_uri___" #_provider "___" #_name)));\ | |
ff82b7c1 | 1057 | static const struct lttng_event_desc __event_desc___##_provider##_##_name = { \ |
df854e41 | 1058 | .name = #_provider ":" #_name, \ |
fbdeb5ec | 1059 | .probe_callback = (void (*)(void)) &__event_probe__##_provider##___##_template,\ |
46d52200 ZT |
1060 | .ctx = NULL, \ |
1061 | .fields = __event_fields___##_provider##___##_template, \ | |
1c80c909 | 1062 | .nr_fields = _TP_ARRAY_SIZE(__event_fields___##_provider##___##_template) - 1, \ |
882a56d7 | 1063 | .loglevel = &__ref_loglevel___##_provider##___##_name, \ |
68755429 | 1064 | .signature = __tp_event_signature___##_provider##___##_template, \ |
c785c634 MD |
1065 | .u = { \ |
1066 | .ext = { \ | |
1067 | .model_emf_uri = &__ref_model_emf_uri___##_provider##___##_name, \ | |
d8d2416d | 1068 | .event_notifier_callback = (void (*)(void)) &__event_notifier_probe__##_provider##___##_template,\ |
c785c634 MD |
1069 | }, \ |
1070 | }, \ | |
df854e41 MD |
1071 | }; |
1072 | ||
1073 | #include TRACEPOINT_INCLUDE | |
05ceaafd | 1074 | |
df854e41 | 1075 | /* |
882a56d7 | 1076 | * Stage 7.2 of tracepoint event generation. |
df854e41 MD |
1077 | * |
1078 | * Create array of events. | |
1079 | */ | |
1080 | ||
1081 | /* Reset all macros within TRACEPOINT_EVENT */ | |
1082 | #include <lttng/ust-tracepoint-event-reset.h> | |
1083 | ||
f8021d08 CB |
1084 | #undef _TRACEPOINT_EVENT_INSTANCE |
1085 | #define _TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \ | |
df854e41 MD |
1086 | &__event_desc___##_provider##_##_name, |
1087 | ||
1088 | static const struct lttng_event_desc *_TP_COMBINE_TOKENS(__event_desc___, TRACEPOINT_PROVIDER)[] = { | |
05ceaafd | 1089 | #include TRACEPOINT_INCLUDE |
1c80c909 | 1090 | NULL, /* Dummy, C99 forbids 0-len array. */ |
05ceaafd MD |
1091 | }; |
1092 | ||
df854e41 | 1093 | |
05ceaafd | 1094 | /* |
882a56d7 | 1095 | * Stage 8 of tracepoint event generation. |
05ceaafd MD |
1096 | * |
1097 | * Create a toplevel descriptor for the whole probe. | |
1098 | */ | |
1099 | ||
1100 | /* non-const because list head will be modified when registered. */ | |
1101 | static struct lttng_probe_desc _TP_COMBINE_TOKENS(__probe_desc___, TRACEPOINT_PROVIDER) = { | |
df854e41 | 1102 | .provider = __tp_stringify(TRACEPOINT_PROVIDER), |
05ceaafd | 1103 | .event_desc = _TP_COMBINE_TOKENS(__event_desc___, TRACEPOINT_PROVIDER), |
1c80c909 | 1104 | .nr_events = _TP_ARRAY_SIZE(_TP_COMBINE_TOKENS(__event_desc___, TRACEPOINT_PROVIDER)) - 1, |
46d52200 ZT |
1105 | .head = { NULL, NULL }, |
1106 | .lazy_init_head = { NULL, NULL }, | |
1107 | .lazy = 0, | |
71d31690 MD |
1108 | .major = LTTNG_UST_PROVIDER_MAJOR, |
1109 | .minor = LTTNG_UST_PROVIDER_MINOR, | |
05ceaafd MD |
1110 | }; |
1111 | ||
f0cc794d MD |
1112 | static int _TP_COMBINE_TOKENS(__probe_register_refcount___, TRACEPOINT_PROVIDER); |
1113 | ||
05ceaafd | 1114 | /* |
882a56d7 | 1115 | * Stage 9 of tracepoint event generation. |
05ceaafd | 1116 | * |
1c324e59 | 1117 | * Register/unregister probes at module load/unload. |
628e1d81 MD |
1118 | * |
1119 | * Generate the constructor as an externally visible symbol for use when | |
1120 | * linking the probe statically. | |
f0cc794d MD |
1121 | * |
1122 | * Register refcount is protected by libc dynamic loader mutex. | |
1c324e59 MD |
1123 | */ |
1124 | ||
1125 | /* Reset all macros within TRACEPOINT_EVENT */ | |
1126 | #include <lttng/ust-tracepoint-event-reset.h> | |
a8909ba5 PW |
1127 | static void lttng_ust_notrace __attribute__((constructor)) |
1128 | _TP_COMBINE_TOKENS(__lttng_events_init__, TRACEPOINT_PROVIDER)(void); | |
1129 | static void | |
1c324e59 MD |
1130 | _TP_COMBINE_TOKENS(__lttng_events_init__, TRACEPOINT_PROVIDER)(void) |
1131 | { | |
1132 | int ret; | |
1133 | ||
f0cc794d MD |
1134 | if (_TP_COMBINE_TOKENS(__probe_register_refcount___, |
1135 | TRACEPOINT_PROVIDER)++) { | |
1136 | return; | |
1137 | } | |
e8bd1da7 MD |
1138 | /* |
1139 | * __tracepoint_provider_check_ ## TRACEPOINT_PROVIDER() is a | |
1140 | * static inline function that ensures every probe PROVIDER | |
1141 | * argument match the provider within which they appear. It | |
1142 | * calls empty static inline functions, and therefore has no | |
1143 | * runtime effect. However, if it detects an error, a linker | |
1144 | * error will appear. | |
1145 | */ | |
1146 | _TP_COMBINE_TOKENS(__tracepoint_provider_check_, TRACEPOINT_PROVIDER)(); | |
7dd08bec | 1147 | ret = lttng_probe_register(&_TP_COMBINE_TOKENS(__probe_desc___, TRACEPOINT_PROVIDER)); |
7d381d6e | 1148 | if (ret) { |
0fdd0b89 | 1149 | fprintf(stderr, "LTTng-UST: Error (%d) while registering tracepoint probe.\n", ret); |
7d381d6e MD |
1150 | abort(); |
1151 | } | |
1c324e59 MD |
1152 | } |
1153 | ||
a8909ba5 PW |
1154 | static void lttng_ust_notrace __attribute__((destructor)) |
1155 | _TP_COMBINE_TOKENS(__lttng_events_exit__, TRACEPOINT_PROVIDER)(void); | |
1156 | static void | |
1c324e59 MD |
1157 | _TP_COMBINE_TOKENS(__lttng_events_exit__, TRACEPOINT_PROVIDER)(void) |
1158 | { | |
f0cc794d MD |
1159 | if (--_TP_COMBINE_TOKENS(__probe_register_refcount___, |
1160 | TRACEPOINT_PROVIDER)) { | |
1161 | return; | |
1162 | } | |
7dd08bec | 1163 | lttng_probe_unregister(&_TP_COMBINE_TOKENS(__probe_desc___, TRACEPOINT_PROVIDER)); |
1c324e59 | 1164 | } |
628e1d81 | 1165 | |
6c8cfec7 MD |
1166 | int _TP_COMBINE_TOKENS(__tracepoint_provider_, TRACEPOINT_PROVIDER) |
1167 | __attribute__((visibility("default"))); |