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