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> | |
24 | #include <urcu/compiler.h> | |
f488575f | 25 | #include <urcu/rculist.h> |
1c324e59 | 26 | #include <lttng/ust-events.h> |
1c324e59 | 27 | #include <lttng/ringbuffer-config.h> |
a8909ba5 | 28 | #include <lttng/ust-compiler.h> |
000b8662 | 29 | #include <lttng/tracepoint.h> |
44c72f10 | 30 | #include <string.h> |
1c324e59 | 31 | |
000b8662 MD |
32 | #undef tp_list_for_each_entry_rcu |
33 | #define tp_list_for_each_entry_rcu(pos, head, member) \ | |
34 | for (pos = cds_list_entry(tp_rcu_dereference_bp((head)->next), __typeof__(*pos), member); \ | |
35 | &pos->member != (head); \ | |
36 | pos = cds_list_entry(tp_rcu_dereference_bp(pos->member.next), __typeof__(*pos), member)) | |
37 | ||
1c324e59 MD |
38 | /* |
39 | * TRACEPOINT_EVENT_CLASS declares a class of tracepoints receiving the | |
40 | * same arguments and having the same field layout. | |
41 | * | |
42 | * TRACEPOINT_EVENT_INSTANCE declares an instance of a tracepoint, with | |
43 | * its own provider and name. It refers to a class (template). | |
44 | * | |
45 | * TRACEPOINT_EVENT declared both a class and an instance and does a | |
46 | * direct mapping from the instance to the class. | |
47 | */ | |
48 | ||
49 | #undef TRACEPOINT_EVENT | |
50 | #define TRACEPOINT_EVENT(_provider, _name, _args, _fields) \ | |
51 | TRACEPOINT_EVENT_CLASS(_provider, _name, \ | |
52 | _TP_PARAMS(_args), \ | |
53 | _TP_PARAMS(_fields)) \ | |
54 | TRACEPOINT_EVENT_INSTANCE(_provider, _name, _name, \ | |
68755429 | 55 | _TP_PARAMS(_args)) |
1c324e59 MD |
56 | |
57 | /* Helpers */ | |
58 | #define _TP_ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) | |
59 | ||
60 | #define _tp_max_t(type, x, y) \ | |
61 | ({ \ | |
62 | type __max1 = (x); \ | |
63 | type __max2 = (y); \ | |
64 | __max1 > __max2 ? __max1: __max2; \ | |
65 | }) | |
66 | ||
67 | /* | |
68 | * Stage 0 of tracepoint event generation. | |
69 | * | |
70 | * Check that each TRACEPOINT_EVENT provider argument match the | |
71 | * TRACEPOINT_PROVIDER by creating dummy callbacks. | |
72 | */ | |
73 | ||
74 | /* Reset all macros within TRACEPOINT_EVENT */ | |
75 | #include <lttng/ust-tracepoint-event-reset.h> | |
76 | ||
77 | static inline | |
78 | void _TP_COMBINE_TOKENS(__tracepoint_provider_mismatch_, TRACEPOINT_PROVIDER)(void) | |
79 | { | |
80 | } | |
81 | ||
82 | #undef TRACEPOINT_EVENT_CLASS | |
83 | #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \ | |
84 | __tracepoint_provider_mismatch_##_provider(); | |
85 | ||
86 | #undef TRACEPOINT_EVENT_INSTANCE | |
87 | #define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \ | |
88 | __tracepoint_provider_mismatch_##_provider(); | |
89 | ||
e8bd1da7 | 90 | static inline |
1c324e59 MD |
91 | void _TP_COMBINE_TOKENS(__tracepoint_provider_check_, TRACEPOINT_PROVIDER)(void) |
92 | { | |
93 | #include TRACEPOINT_INCLUDE | |
94 | } | |
95 | ||
f56cd1d5 MD |
96 | /* |
97 | * Stage 0.1 of tracepoint event generation. | |
98 | * | |
99 | * Check that each TRACEPOINT_EVENT provider:name does not exceed the | |
100 | * tracepoint name length limit. | |
101 | */ | |
102 | ||
103 | /* Reset all macros within TRACEPOINT_EVENT */ | |
104 | #include <lttng/ust-tracepoint-event-reset.h> | |
105 | ||
106 | #undef TRACEPOINT_EVENT_INSTANCE | |
107 | #define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \ | |
108 | static const char \ | |
109 | __tp_name_len_check##_provider##___##_name[LTTNG_UST_SYM_NAME_LEN] \ | |
110 | __attribute__((unused)) = \ | |
111 | #_provider ":" #_name; | |
112 | ||
113 | #include TRACEPOINT_INCLUDE | |
114 | ||
1c324e59 MD |
115 | /* |
116 | * Stage 1 of tracepoint event generation. | |
117 | * | |
118 | * Create event field type metadata section. | |
119 | * Each event produce an array of fields. | |
120 | */ | |
121 | ||
122 | /* Reset all macros within TRACEPOINT_EVENT */ | |
123 | #include <lttng/ust-tracepoint-event-reset.h> | |
4774c8f3 MD |
124 | #include <lttng/ust-tracepoint-event-write.h> |
125 | #include <lttng/ust-tracepoint-event-nowrite.h> | |
1c324e59 | 126 | |
4774c8f3 | 127 | #undef _ctf_integer_ext |
180901e6 | 128 | #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \ |
1c324e59 MD |
129 | { \ |
130 | .name = #_item, \ | |
131 | .type = __type_integer(_type, _byte_order, _base, none),\ | |
180901e6 | 132 | .nowrite = _nowrite, \ |
1c324e59 MD |
133 | }, |
134 | ||
4774c8f3 | 135 | #undef _ctf_float |
180901e6 | 136 | #define _ctf_float(_type, _item, _src, _nowrite) \ |
1c324e59 MD |
137 | { \ |
138 | .name = #_item, \ | |
139 | .type = __type_float(_type), \ | |
180901e6 | 140 | .nowrite = _nowrite, \ |
1c324e59 MD |
141 | }, |
142 | ||
4774c8f3 | 143 | #undef _ctf_array_encoded |
180901e6 | 144 | #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _nowrite) \ |
1c324e59 MD |
145 | { \ |
146 | .name = #_item, \ | |
147 | .type = \ | |
148 | { \ | |
149 | .atype = atype_array, \ | |
150 | .u.array = \ | |
151 | { \ | |
152 | .length = _length, \ | |
153 | .elem_type = __type_integer(_type, BYTE_ORDER, 10, _encoding), \ | |
154 | }, \ | |
155 | }, \ | |
180901e6 | 156 | .nowrite = _nowrite, \ |
1c324e59 MD |
157 | }, |
158 | ||
4774c8f3 MD |
159 | #undef _ctf_sequence_encoded |
160 | #define _ctf_sequence_encoded(_type, _item, _src, \ | |
180901e6 | 161 | _length_type, _src_length, _encoding, _nowrite) \ |
1c324e59 MD |
162 | { \ |
163 | .name = #_item, \ | |
164 | .type = \ | |
165 | { \ | |
166 | .atype = atype_sequence, \ | |
167 | .u.sequence = \ | |
168 | { \ | |
169 | .length_type = __type_integer(_length_type, BYTE_ORDER, 10, none), \ | |
170 | .elem_type = __type_integer(_type, BYTE_ORDER, 10, _encoding), \ | |
171 | }, \ | |
172 | }, \ | |
180901e6 | 173 | .nowrite = _nowrite, \ |
1c324e59 MD |
174 | }, |
175 | ||
4774c8f3 | 176 | #undef _ctf_string |
180901e6 | 177 | #define _ctf_string(_item, _src, _nowrite) \ |
1c324e59 MD |
178 | { \ |
179 | .name = #_item, \ | |
180 | .type = \ | |
181 | { \ | |
182 | .atype = atype_string, \ | |
183 | .u.basic.string.encoding = lttng_encode_UTF8, \ | |
184 | }, \ | |
180901e6 | 185 | .nowrite = _nowrite, \ |
1c324e59 MD |
186 | }, |
187 | ||
188 | #undef TP_FIELDS | |
2eda209b | 189 | #define TP_FIELDS(...) __VA_ARGS__ /* Only one used in this phase */ |
1c324e59 MD |
190 | |
191 | #undef TRACEPOINT_EVENT_CLASS | |
192 | #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \ | |
193 | static const struct lttng_event_field __event_fields___##_provider##___##_name[] = { \ | |
194 | _fields \ | |
195 | }; | |
196 | ||
197 | #include TRACEPOINT_INCLUDE | |
198 | ||
199 | /* | |
200 | * Stage 2 of tracepoint event generation. | |
201 | * | |
202 | * Create probe callback prototypes. | |
203 | */ | |
204 | ||
205 | /* Reset all macros within TRACEPOINT_EVENT */ | |
206 | #include <lttng/ust-tracepoint-event-reset.h> | |
207 | ||
208 | #undef TP_ARGS | |
2eda209b | 209 | #define TP_ARGS(...) __VA_ARGS__ |
1c324e59 MD |
210 | |
211 | #undef TRACEPOINT_EVENT_CLASS | |
212 | #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \ | |
213 | static void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)); | |
214 | ||
215 | #include TRACEPOINT_INCLUDE | |
216 | ||
217 | /* | |
218 | * Stage 3 of tracepoint event generation. | |
219 | * | |
1c324e59 MD |
220 | * Create static inline function that calculates event size. |
221 | */ | |
222 | ||
223 | /* Reset all macros within TRACEPOINT_EVENT */ | |
224 | #include <lttng/ust-tracepoint-event-reset.h> | |
4774c8f3 | 225 | #include <lttng/ust-tracepoint-event-write.h> |
1c324e59 | 226 | |
4774c8f3 | 227 | #undef _ctf_integer_ext |
180901e6 | 228 | #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \ |
1c324e59 MD |
229 | __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \ |
230 | __event_len += sizeof(_type); | |
231 | ||
4774c8f3 | 232 | #undef _ctf_float |
180901e6 | 233 | #define _ctf_float(_type, _item, _src, _nowrite) \ |
1c324e59 MD |
234 | __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \ |
235 | __event_len += sizeof(_type); | |
236 | ||
4774c8f3 | 237 | #undef _ctf_array_encoded |
180901e6 | 238 | #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _nowrite) \ |
1c324e59 MD |
239 | __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \ |
240 | __event_len += sizeof(_type) * (_length); | |
241 | ||
4774c8f3 MD |
242 | #undef _ctf_sequence_encoded |
243 | #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \ | |
180901e6 | 244 | _src_length, _encoding, _nowrite) \ |
1c324e59 MD |
245 | __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_length_type)); \ |
246 | __event_len += sizeof(_length_type); \ | |
247 | __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \ | |
248 | __dynamic_len[__dynamic_len_idx] = (_src_length); \ | |
249 | __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \ | |
250 | __dynamic_len_idx++; | |
251 | ||
4774c8f3 | 252 | #undef _ctf_string |
180901e6 | 253 | #define _ctf_string(_item, _src, _nowrite) \ |
1c324e59 MD |
254 | __event_len += __dynamic_len[__dynamic_len_idx++] = strlen(_src) + 1; |
255 | ||
256 | #undef TP_ARGS | |
2eda209b | 257 | #define TP_ARGS(...) __VA_ARGS__ |
1c324e59 MD |
258 | |
259 | #undef TP_FIELDS | |
2eda209b | 260 | #define TP_FIELDS(...) __VA_ARGS__ |
1c324e59 MD |
261 | |
262 | #undef TRACEPOINT_EVENT_CLASS | |
a8909ba5 PW |
263 | #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \ |
264 | static inline lttng_ust_notrace \ | |
265 | size_t __event_get_size__##_provider##___##_name(size_t *__dynamic_len, _TP_ARGS_DATA_PROTO(_args)); \ | |
266 | static inline \ | |
267 | size_t __event_get_size__##_provider##___##_name(size_t *__dynamic_len, _TP_ARGS_DATA_PROTO(_args)) \ | |
1c324e59 MD |
268 | { \ |
269 | size_t __event_len = 0; \ | |
270 | unsigned int __dynamic_len_idx = 0; \ | |
271 | \ | |
272 | if (0) \ | |
273 | (void) __dynamic_len_idx; /* don't warn if unused */ \ | |
274 | _fields \ | |
275 | return __event_len; \ | |
276 | } | |
277 | ||
278 | #include TRACEPOINT_INCLUDE | |
279 | ||
1ddfd641 MD |
280 | /* |
281 | * Stage 3.1 of tracepoint event generation. | |
282 | * | |
283 | * Create static inline function that layout the filter stack data. | |
4774c8f3 | 284 | * We make both write and nowrite data available to the filter. |
1ddfd641 MD |
285 | */ |
286 | ||
287 | /* Reset all macros within TRACEPOINT_EVENT */ | |
288 | #include <lttng/ust-tracepoint-event-reset.h> | |
4774c8f3 MD |
289 | #include <lttng/ust-tracepoint-event-write.h> |
290 | #include <lttng/ust-tracepoint-event-nowrite.h> | |
1ddfd641 | 291 | |
4774c8f3 | 292 | #undef _ctf_integer_ext |
180901e6 | 293 | #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \ |
fa099471 MD |
294 | if (lttng_is_signed_type(_type)) { \ |
295 | int64_t __ctf_tmp_int64 = (int64_t) (_type) (_src); \ | |
296 | memcpy(__stack_data, &__ctf_tmp_int64, sizeof(int64_t)); \ | |
297 | } else { \ | |
298 | uint64_t __ctf_tmp_uint64 = (uint64_t) (_type) (_src); \ | |
299 | memcpy(__stack_data, &__ctf_tmp_uint64, sizeof(uint64_t)); \ | |
300 | } \ | |
1ddfd641 MD |
301 | __stack_data += sizeof(int64_t); |
302 | ||
4774c8f3 | 303 | #undef _ctf_float |
180901e6 | 304 | #define _ctf_float(_type, _item, _src, _nowrite) \ |
fa099471 MD |
305 | { \ |
306 | double __ctf_tmp_double = (double) (_type) (_src); \ | |
307 | memcpy(__stack_data, &__ctf_tmp_double, sizeof(double)); \ | |
308 | __stack_data += sizeof(double); \ | |
309 | } | |
1ddfd641 | 310 | |
4774c8f3 | 311 | #undef _ctf_array_encoded |
180901e6 | 312 | #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _nowrite) \ |
fa099471 MD |
313 | { \ |
314 | unsigned long __ctf_tmp_ulong = (unsigned long) (_length); \ | |
59034aab | 315 | const void *__ctf_tmp_ptr = (_src); \ |
fa099471 MD |
316 | memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \ |
317 | __stack_data += sizeof(unsigned long); \ | |
c4261b0a | 318 | memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void **)); \ |
fa099471 MD |
319 | __stack_data += sizeof(void **); \ |
320 | } | |
1ddfd641 | 321 | |
4774c8f3 MD |
322 | #undef _ctf_sequence_encoded |
323 | #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \ | |
180901e6 | 324 | _src_length, _encoding, _nowrite) \ |
fa099471 MD |
325 | { \ |
326 | unsigned long __ctf_tmp_ulong = (unsigned long) (_src_length); \ | |
59034aab | 327 | const void *__ctf_tmp_ptr = (_src); \ |
fa099471 MD |
328 | memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \ |
329 | __stack_data += sizeof(unsigned long); \ | |
c4261b0a | 330 | memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void **)); \ |
fa099471 MD |
331 | __stack_data += sizeof(void **); \ |
332 | } | |
1ddfd641 | 333 | |
4774c8f3 | 334 | #undef _ctf_string |
180901e6 | 335 | #define _ctf_string(_item, _src, _nowrite) \ |
fa099471 | 336 | { \ |
59034aab | 337 | const void *__ctf_tmp_ptr = (_src); \ |
c4261b0a | 338 | memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void **)); \ |
27f4b609 | 339 | __stack_data += sizeof(void **); \ |
fa099471 | 340 | } |
1ddfd641 MD |
341 | |
342 | #undef TP_ARGS | |
343 | #define TP_ARGS(...) __VA_ARGS__ | |
344 | ||
345 | #undef TP_FIELDS | |
346 | #define TP_FIELDS(...) __VA_ARGS__ | |
347 | ||
348 | #undef TRACEPOINT_EVENT_CLASS | |
349 | #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \ | |
350 | static inline \ | |
351 | void __event_prepare_filter_stack__##_provider##___##_name(char *__stack_data,\ | |
352 | _TP_ARGS_DATA_PROTO(_args)) \ | |
353 | { \ | |
354 | _fields \ | |
355 | } | |
356 | ||
357 | #include TRACEPOINT_INCLUDE | |
358 | ||
359 | ||
360 | ||
1c324e59 | 361 | /* |
df854e41 | 362 | * Stage 4 of tracepoint event generation. |
1c324e59 MD |
363 | * |
364 | * Create static inline function that calculates event payload alignment. | |
365 | */ | |
366 | ||
367 | /* Reset all macros within TRACEPOINT_EVENT */ | |
368 | #include <lttng/ust-tracepoint-event-reset.h> | |
4774c8f3 | 369 | #include <lttng/ust-tracepoint-event-write.h> |
1c324e59 | 370 | |
4774c8f3 | 371 | #undef _ctf_integer_ext |
180901e6 | 372 | #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \ |
1c324e59 MD |
373 | __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type)); |
374 | ||
4774c8f3 | 375 | #undef _ctf_float |
180901e6 | 376 | #define _ctf_float(_type, _item, _src, _nowrite) \ |
1c324e59 MD |
377 | __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type)); |
378 | ||
4774c8f3 | 379 | #undef _ctf_array_encoded |
180901e6 | 380 | #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _nowrite) \ |
1c324e59 MD |
381 | __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type)); |
382 | ||
4774c8f3 MD |
383 | #undef _ctf_sequence_encoded |
384 | #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \ | |
180901e6 | 385 | _src_length, _encoding, _nowrite) \ |
1c324e59 MD |
386 | __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_length_type)); \ |
387 | __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type)); | |
388 | ||
4774c8f3 | 389 | #undef _ctf_string |
180901e6 | 390 | #define _ctf_string(_item, _src, _nowrite) |
1c324e59 MD |
391 | |
392 | #undef TP_ARGS | |
2eda209b | 393 | #define TP_ARGS(...) __VA_ARGS__ |
1c324e59 MD |
394 | |
395 | #undef TP_FIELDS | |
2eda209b | 396 | #define TP_FIELDS(...) __VA_ARGS__ |
1c324e59 MD |
397 | |
398 | #undef TRACEPOINT_EVENT_CLASS | |
399 | #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \ | |
a8909ba5 PW |
400 | static inline lttng_ust_notrace \ |
401 | size_t __event_get_align__##_provider##___##_name(_TP_ARGS_PROTO(_args)); \ | |
1c324e59 MD |
402 | static inline \ |
403 | size_t __event_get_align__##_provider##___##_name(_TP_ARGS_PROTO(_args)) \ | |
404 | { \ | |
405 | size_t __event_align = 1; \ | |
406 | _fields \ | |
407 | return __event_align; \ | |
408 | } | |
409 | ||
410 | #include TRACEPOINT_INCLUDE | |
411 | ||
412 | ||
413 | /* | |
df854e41 | 414 | * Stage 5 of tracepoint event generation. |
1c324e59 MD |
415 | * |
416 | * Create the probe function. This function calls event size calculation | |
417 | * and writes event data into the buffer. | |
418 | */ | |
419 | ||
420 | /* Reset all macros within TRACEPOINT_EVENT */ | |
421 | #include <lttng/ust-tracepoint-event-reset.h> | |
4774c8f3 | 422 | #include <lttng/ust-tracepoint-event-write.h> |
1c324e59 | 423 | |
4774c8f3 | 424 | #undef _ctf_integer_ext |
180901e6 | 425 | #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \ |
1c324e59 MD |
426 | { \ |
427 | _type __tmp = (_src); \ | |
428 | lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp));\ | |
429 | __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\ | |
430 | } | |
431 | ||
4774c8f3 | 432 | #undef _ctf_float |
180901e6 | 433 | #define _ctf_float(_type, _item, _src, _nowrite) \ |
1c324e59 MD |
434 | { \ |
435 | _type __tmp = (_src); \ | |
436 | lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp));\ | |
437 | __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\ | |
438 | } | |
439 | ||
4774c8f3 | 440 | #undef _ctf_array_encoded |
180901e6 | 441 | #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _nowrite) \ |
1c324e59 MD |
442 | lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \ |
443 | __chan->ops->event_write(&__ctx, _src, sizeof(_type) * (_length)); | |
444 | ||
4774c8f3 MD |
445 | #undef _ctf_sequence_encoded |
446 | #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \ | |
180901e6 | 447 | _src_length, _encoding, _nowrite) \ |
1c324e59 | 448 | { \ |
d71b57b9 | 449 | _length_type __tmpl = __stackvar.__dynamic_len[__dynamic_len_idx]; \ |
1c324e59 MD |
450 | lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_length_type));\ |
451 | __chan->ops->event_write(&__ctx, &__tmpl, sizeof(_length_type));\ | |
452 | } \ | |
453 | lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \ | |
454 | __chan->ops->event_write(&__ctx, _src, \ | |
455 | sizeof(_type) * __get_dynamic_len(dest)); | |
456 | ||
4774c8f3 | 457 | #undef _ctf_string |
180901e6 | 458 | #define _ctf_string(_item, _src, _nowrite) \ |
1c324e59 MD |
459 | lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(*(_src))); \ |
460 | __chan->ops->event_write(&__ctx, _src, __get_dynamic_len(dest)); | |
461 | ||
462 | /* Beware: this get len actually consumes the len value */ | |
463 | #undef __get_dynamic_len | |
d71b57b9 | 464 | #define __get_dynamic_len(field) __stackvar.__dynamic_len[__dynamic_len_idx++] |
1c324e59 MD |
465 | |
466 | #undef TP_ARGS | |
2eda209b | 467 | #define TP_ARGS(...) __VA_ARGS__ |
1c324e59 MD |
468 | |
469 | #undef TP_FIELDS | |
2eda209b | 470 | #define TP_FIELDS(...) __VA_ARGS__ |
1c324e59 | 471 | |
1ddfd641 MD |
472 | /* |
473 | * Using twice size for filter stack data to hold size and pointer for | |
474 | * each field (worse case). For integers, max size required is 64-bit. | |
475 | * Same for double-precision floats. Those fit within | |
476 | * 2*sizeof(unsigned long) for all supported architectures. | |
61ce3223 | 477 | * Perform UNION (||) of filter runtime list. |
1ddfd641 | 478 | */ |
1c324e59 MD |
479 | #undef TRACEPOINT_EVENT_CLASS |
480 | #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \ | |
a8909ba5 PW |
481 | static lttng_ust_notrace \ |
482 | void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)); \ | |
483 | static \ | |
484 | void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)) \ | |
1c324e59 | 485 | { \ |
7dd08bec MD |
486 | struct lttng_event *__event = __tp_data; \ |
487 | struct lttng_channel *__chan = __event->chan; \ | |
f280cb51 | 488 | struct lttng_ust_lib_ring_buffer_ctx __ctx; \ |
1c324e59 MD |
489 | size_t __event_len, __event_align; \ |
490 | size_t __dynamic_len_idx = 0; \ | |
d71b57b9 | 491 | union { \ |
1ddfd641 MD |
492 | size_t __dynamic_len[_TP_ARRAY_SIZE(__event_fields___##_provider##___##_name)]; \ |
493 | char __filter_stack_data[2 * sizeof(unsigned long) * _TP_ARRAY_SIZE(__event_fields___##_provider##___##_name)]; \ | |
d71b57b9 | 494 | } __stackvar; \ |
1c324e59 MD |
495 | int __ret; \ |
496 | \ | |
497 | if (0) \ | |
498 | (void) __dynamic_len_idx; /* don't warn if unused */ \ | |
499 | if (caa_unlikely(!CMM_ACCESS_ONCE(__chan->session->active))) \ | |
500 | return; \ | |
501 | if (caa_unlikely(!CMM_ACCESS_ONCE(__chan->enabled))) \ | |
502 | return; \ | |
503 | if (caa_unlikely(!CMM_ACCESS_ONCE(__event->enabled))) \ | |
504 | return; \ | |
1b436e01 MD |
505 | if (caa_unlikely(!TP_RCU_LINK_TEST())) \ |
506 | return; \ | |
e58095ef | 507 | if (caa_unlikely(!cds_list_empty(&__event->bytecode_runtime_head))) { \ |
f488575f | 508 | struct lttng_bytecode_runtime *bc_runtime; \ |
dcdeaff0 | 509 | int __filter_record = __event->has_enablers_without_bytecode; \ |
f488575f | 510 | \ |
1ddfd641 | 511 | __event_prepare_filter_stack__##_provider##___##_name(__stackvar.__filter_stack_data, \ |
f488575f | 512 | _TP_ARGS_DATA_VAR(_args)); \ |
000b8662 | 513 | tp_list_for_each_entry_rcu(bc_runtime, &__event->bytecode_runtime_head, node) { \ |
61ce3223 | 514 | if (caa_unlikely(bc_runtime->filter(bc_runtime, \ |
8a92ed2a MD |
515 | __stackvar.__filter_stack_data) & LTTNG_FILTER_RECORD_FLAG)) \ |
516 | __filter_record = 1; \ | |
f488575f | 517 | } \ |
8a92ed2a | 518 | if (caa_likely(!__filter_record)) \ |
61ce3223 | 519 | return; \ |
1ddfd641 MD |
520 | } \ |
521 | __event_len = __event_get_size__##_provider##___##_name(__stackvar.__dynamic_len, \ | |
1c324e59 MD |
522 | _TP_ARGS_DATA_VAR(_args)); \ |
523 | __event_align = __event_get_align__##_provider##___##_name(_TP_ARGS_VAR(_args)); \ | |
524 | lib_ring_buffer_ctx_init(&__ctx, __chan->chan, __event, __event_len, \ | |
525 | __event_align, -1, __chan->handle); \ | |
526 | __ret = __chan->ops->event_reserve(&__ctx, __event->id); \ | |
527 | if (__ret < 0) \ | |
528 | return; \ | |
529 | _fields \ | |
530 | __chan->ops->event_commit(&__ctx); \ | |
531 | } | |
532 | ||
533 | #include TRACEPOINT_INCLUDE | |
534 | ||
535 | #undef __get_dynamic_len | |
536 | ||
68755429 MD |
537 | /* |
538 | * Stage 5.1 of tracepoint event generation. | |
539 | * | |
540 | * Create probe signature | |
541 | */ | |
542 | ||
543 | /* Reset all macros within TRACEPOINT_EVENT */ | |
544 | #include <lttng/ust-tracepoint-event-reset.h> | |
545 | ||
546 | #undef TP_ARGS | |
2eda209b | 547 | #define TP_ARGS(...) __VA_ARGS__ |
9eb06182 MD |
548 | |
549 | #define _TP_EXTRACT_STRING2(...) #__VA_ARGS__ | |
68755429 MD |
550 | |
551 | #undef TRACEPOINT_EVENT_CLASS | |
552 | #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \ | |
553 | const char __tp_event_signature___##_provider##___##_name[] = \ | |
9eb06182 | 554 | _TP_EXTRACT_STRING2(_args); |
68755429 MD |
555 | |
556 | #include TRACEPOINT_INCLUDE | |
557 | ||
9eb06182 MD |
558 | #undef _TP_EXTRACT_STRING2 |
559 | ||
05ceaafd | 560 | /* |
882a56d7 | 561 | * Stage 6 of tracepoint event generation. |
1c324e59 | 562 | * |
df854e41 MD |
563 | * Tracepoint loglevel mapping definition generation. We generate a |
564 | * symbol for each mapping for a provider/event to ensure at most a 1 to | |
565 | * 1 mapping between events and loglevels. If the symbol is repeated, | |
566 | * the compiler will complain. | |
05ceaafd MD |
567 | */ |
568 | ||
569 | /* Reset all macros within TRACEPOINT_EVENT */ | |
570 | #include <lttng/ust-tracepoint-event-reset.h> | |
571 | ||
572 | #undef TRACEPOINT_LOGLEVEL | |
457a6b58 MD |
573 | #define TRACEPOINT_LOGLEVEL(__provider, __name, __loglevel) \ |
574 | static const int _loglevel_value___##__provider##___##__name = __loglevel; \ | |
575 | static const int *_loglevel___##__provider##___##__name = \ | |
576 | &_loglevel_value___##__provider##___##__name; | |
df854e41 MD |
577 | |
578 | #include TRACEPOINT_INCLUDE | |
579 | ||
6ddc916d MD |
580 | /* |
581 | * Stage 6.1 of tracepoint event generation. | |
582 | * | |
583 | * Tracepoint UML URI info. | |
584 | */ | |
585 | ||
586 | /* Reset all macros within TRACEPOINT_EVENT */ | |
587 | #include <lttng/ust-tracepoint-event-reset.h> | |
588 | ||
589 | #undef TRACEPOINT_MODEL_EMF_URI | |
590 | #define TRACEPOINT_MODEL_EMF_URI(__provider, __name, __uri) \ | |
591 | static const char *_model_emf_uri___##__provider##___##__name = __uri; | |
592 | ||
593 | #include TRACEPOINT_INCLUDE | |
594 | ||
df854e41 | 595 | /* |
882a56d7 | 596 | * Stage 7.1 of tracepoint event generation. |
df854e41 MD |
597 | * |
598 | * Create events description structures. We use a weakref because | |
599 | * loglevels are optional. If not declared, the event will point to the | |
600 | * a loglevel that contains NULL. | |
601 | */ | |
602 | ||
603 | /* Reset all macros within TRACEPOINT_EVENT */ | |
604 | #include <lttng/ust-tracepoint-event-reset.h> | |
605 | ||
606 | #undef TRACEPOINT_EVENT_INSTANCE | |
607 | #define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \ | |
882a56d7 MD |
608 | static const int * \ |
609 | __ref_loglevel___##_provider##___##_name \ | |
610 | __attribute__((weakref ("_loglevel___" #_provider "___" #_name))); \ | |
6ddc916d MD |
611 | static const char * \ |
612 | __ref_model_emf_uri___##_provider##___##_name \ | |
613 | __attribute__((weakref ("_model_emf_uri___" #_provider "___" #_name)));\ | |
df854e41 MD |
614 | const struct lttng_event_desc __event_desc___##_provider##_##_name = { \ |
615 | .fields = __event_fields___##_provider##___##_template, \ | |
616 | .name = #_provider ":" #_name, \ | |
fbdeb5ec | 617 | .probe_callback = (void (*)(void)) &__event_probe__##_provider##___##_template,\ |
df854e41 | 618 | .nr_fields = _TP_ARRAY_SIZE(__event_fields___##_provider##___##_template), \ |
882a56d7 | 619 | .loglevel = &__ref_loglevel___##_provider##___##_name, \ |
68755429 | 620 | .signature = __tp_event_signature___##_provider##___##_template, \ |
6ddc916d | 621 | .u.ext.model_emf_uri = &__ref_model_emf_uri___##_provider##___##_name, \ |
df854e41 MD |
622 | }; |
623 | ||
624 | #include TRACEPOINT_INCLUDE | |
05ceaafd | 625 | |
df854e41 | 626 | /* |
882a56d7 | 627 | * Stage 7.2 of tracepoint event generation. |
df854e41 MD |
628 | * |
629 | * Create array of events. | |
630 | */ | |
631 | ||
632 | /* Reset all macros within TRACEPOINT_EVENT */ | |
633 | #include <lttng/ust-tracepoint-event-reset.h> | |
634 | ||
635 | #undef TRACEPOINT_EVENT_INSTANCE | |
636 | #define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \ | |
637 | &__event_desc___##_provider##_##_name, | |
638 | ||
639 | static const struct lttng_event_desc *_TP_COMBINE_TOKENS(__event_desc___, TRACEPOINT_PROVIDER)[] = { | |
05ceaafd MD |
640 | #include TRACEPOINT_INCLUDE |
641 | }; | |
642 | ||
df854e41 | 643 | |
05ceaafd | 644 | /* |
882a56d7 | 645 | * Stage 8 of tracepoint event generation. |
05ceaafd MD |
646 | * |
647 | * Create a toplevel descriptor for the whole probe. | |
648 | */ | |
649 | ||
650 | /* non-const because list head will be modified when registered. */ | |
651 | static struct lttng_probe_desc _TP_COMBINE_TOKENS(__probe_desc___, TRACEPOINT_PROVIDER) = { | |
df854e41 | 652 | .provider = __tp_stringify(TRACEPOINT_PROVIDER), |
05ceaafd MD |
653 | .event_desc = _TP_COMBINE_TOKENS(__event_desc___, TRACEPOINT_PROVIDER), |
654 | .nr_events = _TP_ARRAY_SIZE(_TP_COMBINE_TOKENS(__event_desc___, TRACEPOINT_PROVIDER)), | |
71d31690 MD |
655 | .major = LTTNG_UST_PROVIDER_MAJOR, |
656 | .minor = LTTNG_UST_PROVIDER_MINOR, | |
05ceaafd MD |
657 | }; |
658 | ||
659 | /* | |
882a56d7 | 660 | * Stage 9 of tracepoint event generation. |
05ceaafd | 661 | * |
1c324e59 | 662 | * Register/unregister probes at module load/unload. |
628e1d81 MD |
663 | * |
664 | * Generate the constructor as an externally visible symbol for use when | |
665 | * linking the probe statically. | |
1c324e59 MD |
666 | */ |
667 | ||
668 | /* Reset all macros within TRACEPOINT_EVENT */ | |
669 | #include <lttng/ust-tracepoint-event-reset.h> | |
a8909ba5 PW |
670 | static void lttng_ust_notrace __attribute__((constructor)) |
671 | _TP_COMBINE_TOKENS(__lttng_events_init__, TRACEPOINT_PROVIDER)(void); | |
672 | static void | |
1c324e59 MD |
673 | _TP_COMBINE_TOKENS(__lttng_events_init__, TRACEPOINT_PROVIDER)(void) |
674 | { | |
675 | int ret; | |
676 | ||
e8bd1da7 MD |
677 | /* |
678 | * __tracepoint_provider_check_ ## TRACEPOINT_PROVIDER() is a | |
679 | * static inline function that ensures every probe PROVIDER | |
680 | * argument match the provider within which they appear. It | |
681 | * calls empty static inline functions, and therefore has no | |
682 | * runtime effect. However, if it detects an error, a linker | |
683 | * error will appear. | |
684 | */ | |
685 | _TP_COMBINE_TOKENS(__tracepoint_provider_check_, TRACEPOINT_PROVIDER)(); | |
7dd08bec | 686 | ret = lttng_probe_register(&_TP_COMBINE_TOKENS(__probe_desc___, TRACEPOINT_PROVIDER)); |
1c324e59 MD |
687 | assert(!ret); |
688 | } | |
689 | ||
a8909ba5 PW |
690 | static void lttng_ust_notrace __attribute__((destructor)) |
691 | _TP_COMBINE_TOKENS(__lttng_events_exit__, TRACEPOINT_PROVIDER)(void); | |
692 | static void | |
1c324e59 MD |
693 | _TP_COMBINE_TOKENS(__lttng_events_exit__, TRACEPOINT_PROVIDER)(void) |
694 | { | |
7dd08bec | 695 | lttng_probe_unregister(&_TP_COMBINE_TOKENS(__probe_desc___, TRACEPOINT_PROVIDER)); |
1c324e59 | 696 | } |
628e1d81 MD |
697 | |
698 | int _TP_COMBINE_TOKENS(__tracepoint_provider_, TRACEPOINT_PROVIDER); |