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