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