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