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