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