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