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