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