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