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