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