| 1 | /* |
| 2 | * lttng-events.h |
| 3 | * |
| 4 | * Copyright (C) 2009 Steven Rostedt <rostedt@goodmis.org> |
| 5 | * Copyright (C) 2009-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
| 6 | * |
| 7 | * This library is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU Lesser General Public |
| 9 | * License as published by the Free Software Foundation; only |
| 10 | * version 2.1 of the License. |
| 11 | * |
| 12 | * This library is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * Lesser General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU Lesser General Public |
| 18 | * License along with this library; if not, write to the Free Software |
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 20 | */ |
| 21 | #include <linux/uaccess.h> |
| 22 | #include <linux/debugfs.h> |
| 23 | #include "lttng.h" |
| 24 | #include "lttng-types.h" |
| 25 | #include "../wrapper/vmalloc.h" /* for wrapper_vmalloc_sync_all() */ |
| 26 | #include "../wrapper/ringbuffer/frontend_types.h" |
| 27 | #include "../lttng-events.h" |
| 28 | #include "../lttng-tracer-core.h" |
| 29 | |
| 30 | /* |
| 31 | * Macro declarations used for all stages. |
| 32 | */ |
| 33 | |
| 34 | /* |
| 35 | * DECLARE_EVENT_CLASS can be used to add a generic function |
| 36 | * handlers for events. That is, if all events have the same |
| 37 | * parameters and just have distinct trace points. |
| 38 | * Each tracepoint can be defined with DEFINE_EVENT and that |
| 39 | * will map the DECLARE_EVENT_CLASS to the tracepoint. |
| 40 | * |
| 41 | * TRACE_EVENT is a one to one mapping between tracepoint and template. |
| 42 | */ |
| 43 | |
| 44 | #undef TRACE_EVENT |
| 45 | #define TRACE_EVENT(name, proto, args, tstruct, assign, print) \ |
| 46 | DECLARE_EVENT_CLASS(name, \ |
| 47 | PARAMS(proto), \ |
| 48 | PARAMS(args), \ |
| 49 | PARAMS(tstruct), \ |
| 50 | PARAMS(assign), \ |
| 51 | PARAMS(print)) \ |
| 52 | DEFINE_EVENT(name, name, PARAMS(proto), PARAMS(args)) |
| 53 | |
| 54 | #undef TRACE_EVENT_NOARGS |
| 55 | #define TRACE_EVENT_NOARGS(name, tstruct, assign, print) \ |
| 56 | DECLARE_EVENT_CLASS_NOARGS(name, \ |
| 57 | PARAMS(tstruct), \ |
| 58 | PARAMS(assign), \ |
| 59 | PARAMS(print)) \ |
| 60 | DEFINE_EVENT_NOARGS(name, name) |
| 61 | |
| 62 | |
| 63 | #undef DEFINE_EVENT_PRINT |
| 64 | #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \ |
| 65 | DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args)) |
| 66 | |
| 67 | /* Callbacks are meaningless to LTTng. */ |
| 68 | #undef TRACE_EVENT_FN |
| 69 | #define TRACE_EVENT_FN(name, proto, args, tstruct, \ |
| 70 | assign, print, reg, unreg) \ |
| 71 | TRACE_EVENT(name, PARAMS(proto), PARAMS(args), \ |
| 72 | PARAMS(tstruct), PARAMS(assign), PARAMS(print)) \ |
| 73 | |
| 74 | /* |
| 75 | * Stage 1 of the trace events. |
| 76 | * |
| 77 | * Create dummy trace calls for each events, verifying that the LTTng module |
| 78 | * TRACE_EVENT headers match the kernel arguments. Will be optimized out by the |
| 79 | * compiler. |
| 80 | */ |
| 81 | |
| 82 | #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */ |
| 83 | |
| 84 | #undef TP_PROTO |
| 85 | #define TP_PROTO(args...) args |
| 86 | |
| 87 | #undef TP_ARGS |
| 88 | #define TP_ARGS(args...) args |
| 89 | |
| 90 | #undef DEFINE_EVENT |
| 91 | #define DEFINE_EVENT(_template, _name, _proto, _args) \ |
| 92 | void trace_##_name(_proto); |
| 93 | |
| 94 | #undef DEFINE_EVENT_NOARGS |
| 95 | #define DEFINE_EVENT_NOARGS(_template, _name) \ |
| 96 | void trace_##_name(void *__data); |
| 97 | |
| 98 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
| 99 | |
| 100 | /* |
| 101 | * Stage 2 of the trace events. |
| 102 | * |
| 103 | * Create event field type metadata section. |
| 104 | * Each event produce an array of fields. |
| 105 | */ |
| 106 | |
| 107 | #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */ |
| 108 | |
| 109 | /* Named field types must be defined in lttng-types.h */ |
| 110 | |
| 111 | #undef __field_full |
| 112 | #define __field_full(_type, _item, _order, _base) \ |
| 113 | { \ |
| 114 | .name = #_item, \ |
| 115 | .type = __type_integer(_type, _order, _base, none), \ |
| 116 | }, |
| 117 | |
| 118 | #undef __field |
| 119 | #define __field(_type, _item) \ |
| 120 | __field_full(_type, _item, __BYTE_ORDER, 10) |
| 121 | |
| 122 | #undef __field_ext |
| 123 | #define __field_ext(_type, _item, _filter_type) \ |
| 124 | __field(_type, _item) |
| 125 | |
| 126 | #undef __field_hex |
| 127 | #define __field_hex(_type, _item) \ |
| 128 | __field_full(_type, _item, __BYTE_ORDER, 16) |
| 129 | |
| 130 | #undef __field_network |
| 131 | #define __field_network(_type, _item) \ |
| 132 | __field_full(_type, _item, __BIG_ENDIAN, 10) |
| 133 | |
| 134 | #undef __field_network_hex |
| 135 | #define __field_network_hex(_type, _item) \ |
| 136 | __field_full(_type, _item, __BIG_ENDIAN, 16) |
| 137 | |
| 138 | #undef __array_enc_ext |
| 139 | #define __array_enc_ext(_type, _item, _length, _order, _base, _encoding)\ |
| 140 | { \ |
| 141 | .name = #_item, \ |
| 142 | .type = \ |
| 143 | { \ |
| 144 | .atype = atype_array, \ |
| 145 | .u.array = \ |
| 146 | { \ |
| 147 | .length = _length, \ |
| 148 | .elem_type = __type_integer(_type, _order, _base, _encoding), \ |
| 149 | }, \ |
| 150 | }, \ |
| 151 | }, |
| 152 | |
| 153 | #undef __array |
| 154 | #define __array(_type, _item, _length) \ |
| 155 | __array_enc_ext(_type, _item, _length, __BYTE_ORDER, 10, none) |
| 156 | |
| 157 | #undef __array_text |
| 158 | #define __array_text(_type, _item, _length) \ |
| 159 | __array_enc_ext(_type, _item, _length, __BYTE_ORDER, 10, UTF8) |
| 160 | |
| 161 | #undef __array_hex |
| 162 | #define __array_hex(_type, _item, _length) \ |
| 163 | __array_enc_ext(_type, _item, _length, __BYTE_ORDER, 16, none) |
| 164 | |
| 165 | #undef __dynamic_array_enc_ext |
| 166 | #define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding) \ |
| 167 | { \ |
| 168 | .name = #_item, \ |
| 169 | .type = \ |
| 170 | { \ |
| 171 | .atype = atype_sequence, \ |
| 172 | .u.sequence = \ |
| 173 | { \ |
| 174 | .length_type = __type_integer(u32, __BYTE_ORDER, 10, none), \ |
| 175 | .elem_type = __type_integer(_type, _order, _base, _encoding), \ |
| 176 | }, \ |
| 177 | }, \ |
| 178 | }, |
| 179 | |
| 180 | #undef __dynamic_array |
| 181 | #define __dynamic_array(_type, _item, _length) \ |
| 182 | __dynamic_array_enc_ext(_type, _item, _length, __BYTE_ORDER, 10, none) |
| 183 | |
| 184 | #undef __dynamic_array_text |
| 185 | #define __dynamic_array_text(_type, _item, _length) \ |
| 186 | __dynamic_array_enc_ext(_type, _item, _length, __BYTE_ORDER, 10, UTF8) |
| 187 | |
| 188 | #undef __dynamic_array_hex |
| 189 | #define __dynamic_array_hex(_type, _item, _length) \ |
| 190 | __dynamic_array_enc_ext(_type, _item, _length, __BYTE_ORDER, 16, none) |
| 191 | |
| 192 | #undef __string |
| 193 | #define __string(_item, _src) \ |
| 194 | { \ |
| 195 | .name = #_item, \ |
| 196 | .type = \ |
| 197 | { \ |
| 198 | .atype = atype_string, \ |
| 199 | .u.basic.string.encoding = lttng_encode_UTF8, \ |
| 200 | }, \ |
| 201 | }, |
| 202 | |
| 203 | #undef __string_from_user |
| 204 | #define __string_from_user(_item, _src) \ |
| 205 | __string(_item, _src) |
| 206 | |
| 207 | #undef TP_STRUCT__entry |
| 208 | #define TP_STRUCT__entry(args...) args /* Only one used in this phase */ |
| 209 | |
| 210 | #undef DECLARE_EVENT_CLASS_NOARGS |
| 211 | #define DECLARE_EVENT_CLASS_NOARGS(_name, _tstruct, _assign, _print) \ |
| 212 | static const struct lttng_event_field __event_fields___##_name[] = { \ |
| 213 | _tstruct \ |
| 214 | }; |
| 215 | |
| 216 | #undef DECLARE_EVENT_CLASS |
| 217 | #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \ |
| 218 | DECLARE_EVENT_CLASS_NOARGS(_name, PARAMS(_tstruct), PARAMS(_assign), \ |
| 219 | PARAMS(_print)) |
| 220 | |
| 221 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
| 222 | |
| 223 | /* |
| 224 | * Stage 3 of the trace events. |
| 225 | * |
| 226 | * Create probe callback prototypes. |
| 227 | */ |
| 228 | |
| 229 | #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */ |
| 230 | |
| 231 | #undef TP_PROTO |
| 232 | #define TP_PROTO(args...) args |
| 233 | |
| 234 | #undef DECLARE_EVENT_CLASS |
| 235 | #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \ |
| 236 | static void __event_probe__##_name(void *__data, _proto); |
| 237 | |
| 238 | #undef DECLARE_EVENT_CLASS_NOARGS |
| 239 | #define DECLARE_EVENT_CLASS_NOARGS(_name, _tstruct, _assign, _print) \ |
| 240 | static void __event_probe__##_name(void *__data); |
| 241 | |
| 242 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
| 243 | |
| 244 | /* |
| 245 | * Stage 3.9 of the trace events. |
| 246 | * |
| 247 | * Create event descriptions. |
| 248 | */ |
| 249 | |
| 250 | /* Named field types must be defined in lttng-types.h */ |
| 251 | |
| 252 | #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */ |
| 253 | |
| 254 | #ifndef TP_PROBE_CB |
| 255 | #define TP_PROBE_CB(_template) &__event_probe__##_template |
| 256 | #endif |
| 257 | |
| 258 | #undef DEFINE_EVENT_NOARGS |
| 259 | #define DEFINE_EVENT_NOARGS(_template, _name) \ |
| 260 | static const struct lttng_event_desc __event_desc___##_name = { \ |
| 261 | .fields = __event_fields___##_template, \ |
| 262 | .name = #_name, \ |
| 263 | .probe_callback = (void *) TP_PROBE_CB(_template), \ |
| 264 | .nr_fields = ARRAY_SIZE(__event_fields___##_template), \ |
| 265 | .owner = THIS_MODULE, \ |
| 266 | }; |
| 267 | |
| 268 | #undef DEFINE_EVENT |
| 269 | #define DEFINE_EVENT(_template, _name, _proto, _args) \ |
| 270 | DEFINE_EVENT_NOARGS(_template, _name) |
| 271 | |
| 272 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
| 273 | |
| 274 | |
| 275 | /* |
| 276 | * Stage 4 of the trace events. |
| 277 | * |
| 278 | * Create an array of event description pointers. |
| 279 | */ |
| 280 | |
| 281 | /* Named field types must be defined in lttng-types.h */ |
| 282 | |
| 283 | #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */ |
| 284 | |
| 285 | #undef DEFINE_EVENT_NOARGS |
| 286 | #define DEFINE_EVENT_NOARGS(_template, _name) \ |
| 287 | &__event_desc___##_name, |
| 288 | |
| 289 | #undef DEFINE_EVENT |
| 290 | #define DEFINE_EVENT(_template, _name, _proto, _args) \ |
| 291 | DEFINE_EVENT_NOARGS(_template, _name) |
| 292 | |
| 293 | #define TP_ID1(_token, _system) _token##_system |
| 294 | #define TP_ID(_token, _system) TP_ID1(_token, _system) |
| 295 | |
| 296 | static const struct lttng_event_desc *TP_ID(__event_desc___, TRACE_SYSTEM)[] = { |
| 297 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
| 298 | }; |
| 299 | |
| 300 | #undef TP_ID1 |
| 301 | #undef TP_ID |
| 302 | |
| 303 | |
| 304 | /* |
| 305 | * Stage 5 of the trace events. |
| 306 | * |
| 307 | * Create a toplevel descriptor for the whole probe. |
| 308 | */ |
| 309 | |
| 310 | #define TP_ID1(_token, _system) _token##_system |
| 311 | #define TP_ID(_token, _system) TP_ID1(_token, _system) |
| 312 | |
| 313 | /* non-const because list head will be modified when registered. */ |
| 314 | static __used struct lttng_probe_desc TP_ID(__probe_desc___, TRACE_SYSTEM) = { |
| 315 | .event_desc = TP_ID(__event_desc___, TRACE_SYSTEM), |
| 316 | .nr_events = ARRAY_SIZE(TP_ID(__event_desc___, TRACE_SYSTEM)), |
| 317 | }; |
| 318 | |
| 319 | #undef TP_ID1 |
| 320 | #undef TP_ID |
| 321 | |
| 322 | /* |
| 323 | * Stage 6 of the trace events. |
| 324 | * |
| 325 | * Create static inline function that calculates event size. |
| 326 | */ |
| 327 | |
| 328 | #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */ |
| 329 | |
| 330 | /* Named field types must be defined in lttng-types.h */ |
| 331 | |
| 332 | #undef __field_full |
| 333 | #define __field_full(_type, _item, _order, _base) \ |
| 334 | __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \ |
| 335 | __event_len += sizeof(_type); |
| 336 | |
| 337 | #undef __array_enc_ext |
| 338 | #define __array_enc_ext(_type, _item, _length, _order, _base, _encoding) \ |
| 339 | __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \ |
| 340 | __event_len += sizeof(_type) * (_length); |
| 341 | |
| 342 | #undef __dynamic_array_enc_ext |
| 343 | #define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding)\ |
| 344 | __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(u32)); \ |
| 345 | __event_len += sizeof(u32); \ |
| 346 | __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \ |
| 347 | __dynamic_len[__dynamic_len_idx] = (_length); \ |
| 348 | __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \ |
| 349 | __dynamic_len_idx++; |
| 350 | |
| 351 | #undef __string |
| 352 | #define __string(_item, _src) \ |
| 353 | __event_len += __dynamic_len[__dynamic_len_idx++] = strlen(_src) + 1; |
| 354 | |
| 355 | /* |
| 356 | * strlen_user includes \0. If returns 0, it faulted, so we set size to |
| 357 | * 1 (\0 only). |
| 358 | */ |
| 359 | #undef __string_from_user |
| 360 | #define __string_from_user(_item, _src) \ |
| 361 | __event_len += __dynamic_len[__dynamic_len_idx++] = \ |
| 362 | max_t(size_t, strlen_user(_src), 1); |
| 363 | |
| 364 | #undef TP_PROTO |
| 365 | #define TP_PROTO(args...) args |
| 366 | |
| 367 | #undef TP_STRUCT__entry |
| 368 | #define TP_STRUCT__entry(args...) args |
| 369 | |
| 370 | #undef DECLARE_EVENT_CLASS |
| 371 | #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \ |
| 372 | static inline size_t __event_get_size__##_name(size_t *__dynamic_len, _proto) \ |
| 373 | { \ |
| 374 | size_t __event_len = 0; \ |
| 375 | unsigned int __dynamic_len_idx = 0; \ |
| 376 | \ |
| 377 | if (0) \ |
| 378 | (void) __dynamic_len_idx; /* don't warn if unused */ \ |
| 379 | _tstruct \ |
| 380 | return __event_len; \ |
| 381 | } |
| 382 | |
| 383 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
| 384 | |
| 385 | /* |
| 386 | * Stage 7 of the trace events. |
| 387 | * |
| 388 | * Create static inline function that calculates event payload alignment. |
| 389 | */ |
| 390 | |
| 391 | #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */ |
| 392 | |
| 393 | /* Named field types must be defined in lttng-types.h */ |
| 394 | |
| 395 | #undef __field_full |
| 396 | #define __field_full(_type, _item, _order, _base) \ |
| 397 | __event_align = max_t(size_t, __event_align, lttng_alignof(_type)); |
| 398 | |
| 399 | #undef __array_enc_ext |
| 400 | #define __array_enc_ext(_type, _item, _length, _order, _base, _encoding) \ |
| 401 | __event_align = max_t(size_t, __event_align, lttng_alignof(_type)); |
| 402 | |
| 403 | #undef __dynamic_array_enc_ext |
| 404 | #define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding)\ |
| 405 | __event_align = max_t(size_t, __event_align, lttng_alignof(u32)); \ |
| 406 | __event_align = max_t(size_t, __event_align, lttng_alignof(_type)); |
| 407 | |
| 408 | #undef __string |
| 409 | #define __string(_item, _src) |
| 410 | |
| 411 | #undef __string_from_user |
| 412 | #define __string_from_user(_item, _src) |
| 413 | |
| 414 | #undef TP_PROTO |
| 415 | #define TP_PROTO(args...) args |
| 416 | |
| 417 | #undef TP_STRUCT__entry |
| 418 | #define TP_STRUCT__entry(args...) args |
| 419 | |
| 420 | #undef DECLARE_EVENT_CLASS |
| 421 | #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \ |
| 422 | static inline size_t __event_get_align__##_name(_proto) \ |
| 423 | { \ |
| 424 | size_t __event_align = 1; \ |
| 425 | _tstruct \ |
| 426 | return __event_align; \ |
| 427 | } |
| 428 | |
| 429 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
| 430 | |
| 431 | |
| 432 | /* |
| 433 | * Stage 8 of the trace events. |
| 434 | * |
| 435 | * Create structure declaration that allows the "assign" macros to access the |
| 436 | * field types. |
| 437 | */ |
| 438 | |
| 439 | #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */ |
| 440 | |
| 441 | /* Named field types must be defined in lttng-types.h */ |
| 442 | |
| 443 | #undef __field_full |
| 444 | #define __field_full(_type, _item, _order, _base) _type _item; |
| 445 | |
| 446 | #undef __array_enc_ext |
| 447 | #define __array_enc_ext(_type, _item, _length, _order, _base, _encoding) \ |
| 448 | _type _item; |
| 449 | |
| 450 | #undef __dynamic_array_enc_ext |
| 451 | #define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding)\ |
| 452 | _type _item; |
| 453 | |
| 454 | #undef __string |
| 455 | #define __string(_item, _src) char _item; |
| 456 | |
| 457 | #undef __string_from_user |
| 458 | #define __string_from_user(_item, _src) \ |
| 459 | __string(_item, _src) |
| 460 | |
| 461 | #undef TP_STRUCT__entry |
| 462 | #define TP_STRUCT__entry(args...) args |
| 463 | |
| 464 | #undef DECLARE_EVENT_CLASS |
| 465 | #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \ |
| 466 | struct __event_typemap__##_name { \ |
| 467 | _tstruct \ |
| 468 | }; |
| 469 | |
| 470 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
| 471 | |
| 472 | |
| 473 | /* |
| 474 | * Stage 9 of the trace events. |
| 475 | * |
| 476 | * Create the probe function : call even size calculation and write event data |
| 477 | * into the buffer. |
| 478 | * |
| 479 | * We use both the field and assignment macros to write the fields in the order |
| 480 | * defined in the field declaration. The field declarations control the |
| 481 | * execution order, jumping to the appropriate assignment block. |
| 482 | */ |
| 483 | |
| 484 | #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */ |
| 485 | |
| 486 | #undef __field_full |
| 487 | #define __field_full(_type, _item, _order, _base) \ |
| 488 | goto __assign_##_item; \ |
| 489 | __end_field_##_item: |
| 490 | |
| 491 | #undef __array_enc_ext |
| 492 | #define __array_enc_ext(_type, _item, _length, _order, _base, _encoding)\ |
| 493 | goto __assign_##_item; \ |
| 494 | __end_field_##_item: |
| 495 | |
| 496 | #undef __dynamic_array_enc_ext |
| 497 | #define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding)\ |
| 498 | goto __assign_##_item##_1; \ |
| 499 | __end_field_##_item##_1: \ |
| 500 | goto __assign_##_item##_2; \ |
| 501 | __end_field_##_item##_2: |
| 502 | |
| 503 | #undef __string |
| 504 | #define __string(_item, _src) \ |
| 505 | goto __assign_##_item; \ |
| 506 | __end_field_##_item: |
| 507 | |
| 508 | #undef __string_from_user |
| 509 | #define __string_from_user(_item, _src) \ |
| 510 | __string(_item, _src) |
| 511 | |
| 512 | /* |
| 513 | * Macros mapping tp_assign() to "=", tp_memcpy() to memcpy() and tp_strcpy() to |
| 514 | * strcpy(). |
| 515 | */ |
| 516 | #undef tp_assign |
| 517 | #define tp_assign(dest, src) \ |
| 518 | __assign_##dest: \ |
| 519 | { \ |
| 520 | __typeof__(__typemap.dest) __tmp = (src); \ |
| 521 | lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp)); \ |
| 522 | __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\ |
| 523 | } \ |
| 524 | goto __end_field_##dest; |
| 525 | |
| 526 | #undef tp_memcpy |
| 527 | #define tp_memcpy(dest, src, len) \ |
| 528 | __assign_##dest: \ |
| 529 | if (0) \ |
| 530 | (void) __typemap.dest; \ |
| 531 | lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__typemap.dest)); \ |
| 532 | __chan->ops->event_write(&__ctx, src, len); \ |
| 533 | goto __end_field_##dest; |
| 534 | |
| 535 | #undef tp_memcpy_dyn |
| 536 | #define tp_memcpy_dyn(dest, src) \ |
| 537 | __assign_##dest##_1: \ |
| 538 | { \ |
| 539 | u32 __tmpl = __dynamic_len[__dynamic_len_idx]; \ |
| 540 | lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(u32)); \ |
| 541 | __chan->ops->event_write(&__ctx, &__tmpl, sizeof(u32)); \ |
| 542 | } \ |
| 543 | goto __end_field_##dest##_1; \ |
| 544 | __assign_##dest##_2: \ |
| 545 | lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__typemap.dest)); \ |
| 546 | __chan->ops->event_write(&__ctx, src, \ |
| 547 | sizeof(__typemap.dest) * __get_dynamic_array_len(dest));\ |
| 548 | goto __end_field_##dest##_2; |
| 549 | |
| 550 | #undef tp_memcpy_from_user |
| 551 | #define tp_memcpy_from_user(dest, src, len) \ |
| 552 | __assign_##dest: \ |
| 553 | if (0) \ |
| 554 | (void) __typemap.dest; \ |
| 555 | lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__typemap.dest)); \ |
| 556 | __chan->ops->event_write_from_user(&__ctx, src, len); \ |
| 557 | goto __end_field_##dest; |
| 558 | |
| 559 | /* |
| 560 | * The string length including the final \0. |
| 561 | */ |
| 562 | #undef tp_copy_string_from_user |
| 563 | #define tp_copy_string_from_user(dest, src) \ |
| 564 | __assign_##dest: \ |
| 565 | { \ |
| 566 | size_t __ustrlen; \ |
| 567 | \ |
| 568 | if (0) \ |
| 569 | (void) __typemap.dest; \ |
| 570 | lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__typemap.dest));\ |
| 571 | __ustrlen = __get_dynamic_array_len(dest); \ |
| 572 | if (likely(__ustrlen > 1)) { \ |
| 573 | __chan->ops->event_write_from_user(&__ctx, src, \ |
| 574 | __ustrlen - 1); \ |
| 575 | } \ |
| 576 | __chan->ops->event_memset(&__ctx, 0, 1); \ |
| 577 | } \ |
| 578 | goto __end_field_##dest; |
| 579 | #undef tp_strcpy |
| 580 | #define tp_strcpy(dest, src) \ |
| 581 | tp_memcpy(dest, src, __get_dynamic_array_len(dest)) |
| 582 | |
| 583 | /* Named field types must be defined in lttng-types.h */ |
| 584 | |
| 585 | #undef __get_str |
| 586 | #define __get_str(field) field |
| 587 | |
| 588 | #undef __get_dynamic_array |
| 589 | #define __get_dynamic_array(field) field |
| 590 | |
| 591 | /* Beware: this get len actually consumes the len value */ |
| 592 | #undef __get_dynamic_array_len |
| 593 | #define __get_dynamic_array_len(field) __dynamic_len[__dynamic_len_idx++] |
| 594 | |
| 595 | #undef TP_PROTO |
| 596 | #define TP_PROTO(args...) args |
| 597 | |
| 598 | #undef TP_ARGS |
| 599 | #define TP_ARGS(args...) args |
| 600 | |
| 601 | #undef TP_STRUCT__entry |
| 602 | #define TP_STRUCT__entry(args...) args |
| 603 | |
| 604 | #undef TP_fast_assign |
| 605 | #define TP_fast_assign(args...) args |
| 606 | |
| 607 | /* |
| 608 | * For state dump, check that "session" argument (mandatory) matches the |
| 609 | * session this event belongs to. Ensures that we write state dump data only |
| 610 | * into the started session, not into all sessions. |
| 611 | */ |
| 612 | #ifdef TP_SESSION_CHECK |
| 613 | #define _TP_SESSION_CHECK(session, csession) (session == csession) |
| 614 | #else /* TP_SESSION_CHECK */ |
| 615 | #define _TP_SESSION_CHECK(session, csession) 1 |
| 616 | #endif /* TP_SESSION_CHECK */ |
| 617 | |
| 618 | #undef DECLARE_EVENT_CLASS |
| 619 | #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \ |
| 620 | static void __event_probe__##_name(void *__data, _proto) \ |
| 621 | { \ |
| 622 | struct lttng_event *__event = __data; \ |
| 623 | struct lttng_channel *__chan = __event->chan; \ |
| 624 | struct lib_ring_buffer_ctx __ctx; \ |
| 625 | size_t __event_len, __event_align; \ |
| 626 | size_t __dynamic_len_idx = 0; \ |
| 627 | size_t __dynamic_len[ARRAY_SIZE(__event_fields___##_name)]; \ |
| 628 | struct __event_typemap__##_name __typemap; \ |
| 629 | int __ret; \ |
| 630 | \ |
| 631 | if (0) { \ |
| 632 | (void) __dynamic_len_idx; /* don't warn if unused */ \ |
| 633 | (void) __typemap; /* don't warn if unused */ \ |
| 634 | } \ |
| 635 | if (!_TP_SESSION_CHECK(session, __chan->session)) \ |
| 636 | return; \ |
| 637 | if (unlikely(!ACCESS_ONCE(__chan->session->active))) \ |
| 638 | return; \ |
| 639 | if (unlikely(!ACCESS_ONCE(__chan->enabled))) \ |
| 640 | return; \ |
| 641 | if (unlikely(!ACCESS_ONCE(__event->enabled))) \ |
| 642 | return; \ |
| 643 | __event_len = __event_get_size__##_name(__dynamic_len, _args); \ |
| 644 | __event_align = __event_get_align__##_name(_args); \ |
| 645 | lib_ring_buffer_ctx_init(&__ctx, __chan->chan, __event, __event_len, \ |
| 646 | __event_align, -1); \ |
| 647 | __ret = __chan->ops->event_reserve(&__ctx, __event->id); \ |
| 648 | if (__ret < 0) \ |
| 649 | return; \ |
| 650 | /* Control code (field ordering) */ \ |
| 651 | _tstruct \ |
| 652 | __chan->ops->event_commit(&__ctx); \ |
| 653 | return; \ |
| 654 | /* Copy code, steered by control code */ \ |
| 655 | _assign \ |
| 656 | } |
| 657 | |
| 658 | #undef DECLARE_EVENT_CLASS_NOARGS |
| 659 | #define DECLARE_EVENT_CLASS_NOARGS(_name, _tstruct, _assign, _print) \ |
| 660 | static void __event_probe__##_name(void *__data) \ |
| 661 | { \ |
| 662 | struct lttng_event *__event = __data; \ |
| 663 | struct lttng_channel *__chan = __event->chan; \ |
| 664 | struct lib_ring_buffer_ctx __ctx; \ |
| 665 | size_t __event_len, __event_align; \ |
| 666 | int __ret; \ |
| 667 | \ |
| 668 | if (!_TP_SESSION_CHECK(session, __chan->session)) \ |
| 669 | return; \ |
| 670 | if (unlikely(!ACCESS_ONCE(__chan->session->active))) \ |
| 671 | return; \ |
| 672 | if (unlikely(!ACCESS_ONCE(__chan->enabled))) \ |
| 673 | return; \ |
| 674 | if (unlikely(!ACCESS_ONCE(__event->enabled))) \ |
| 675 | return; \ |
| 676 | __event_len = 0; \ |
| 677 | __event_align = 1; \ |
| 678 | lib_ring_buffer_ctx_init(&__ctx, __chan->chan, __event, __event_len, \ |
| 679 | __event_align, -1); \ |
| 680 | __ret = __chan->ops->event_reserve(&__ctx, __event->id); \ |
| 681 | if (__ret < 0) \ |
| 682 | return; \ |
| 683 | /* Control code (field ordering) */ \ |
| 684 | _tstruct \ |
| 685 | __chan->ops->event_commit(&__ctx); \ |
| 686 | return; \ |
| 687 | /* Copy code, steered by control code */ \ |
| 688 | _assign \ |
| 689 | } |
| 690 | |
| 691 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
| 692 | |
| 693 | /* |
| 694 | * Stage 10 of the trace events. |
| 695 | * |
| 696 | * Register/unregister probes at module load/unload. |
| 697 | */ |
| 698 | |
| 699 | #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */ |
| 700 | |
| 701 | #define TP_ID1(_token, _system) _token##_system |
| 702 | #define TP_ID(_token, _system) TP_ID1(_token, _system) |
| 703 | #define module_init_eval1(_token, _system) module_init(_token##_system) |
| 704 | #define module_init_eval(_token, _system) module_init_eval1(_token, _system) |
| 705 | #define module_exit_eval1(_token, _system) module_exit(_token##_system) |
| 706 | #define module_exit_eval(_token, _system) module_exit_eval1(_token, _system) |
| 707 | |
| 708 | #ifndef TP_MODULE_OVERRIDE |
| 709 | static int TP_ID(__lttng_events_init__, TRACE_SYSTEM)(void) |
| 710 | { |
| 711 | wrapper_vmalloc_sync_all(); |
| 712 | return lttng_probe_register(&TP_ID(__probe_desc___, TRACE_SYSTEM)); |
| 713 | } |
| 714 | |
| 715 | module_init_eval(__lttng_events_init__, TRACE_SYSTEM); |
| 716 | |
| 717 | static void TP_ID(__lttng_events_exit__, TRACE_SYSTEM)(void) |
| 718 | { |
| 719 | lttng_probe_unregister(&TP_ID(__probe_desc___, TRACE_SYSTEM)); |
| 720 | } |
| 721 | |
| 722 | module_exit_eval(__lttng_events_exit__, TRACE_SYSTEM); |
| 723 | #endif |
| 724 | |
| 725 | #undef module_init_eval |
| 726 | #undef module_exit_eval |
| 727 | #undef TP_ID1 |
| 728 | #undef TP_ID |
| 729 | |
| 730 | #undef TP_PROTO |
| 731 | #undef TP_ARGS |
| 732 | #undef TRACE_EVENT_FLAGS |