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