| 1 | #include <lttng.h> |
| 2 | #include <lttng-types.h> |
| 3 | #include <linux/debugfs.h> |
| 4 | #include <linux/ringbuffer/frontend_types.h> |
| 5 | #include "../ltt-events.h" |
| 6 | #include "../ltt-tracer-core.h" |
| 7 | |
| 8 | struct lttng_event_field { |
| 9 | const char *name; |
| 10 | const struct lttng_type type; |
| 11 | }; |
| 12 | |
| 13 | struct lttng_event_desc { |
| 14 | const struct lttng_event_field *fields; |
| 15 | const char *name; |
| 16 | unsigned int nr_fields; |
| 17 | }; |
| 18 | |
| 19 | /* |
| 20 | * Macro declarations used for all stages. |
| 21 | */ |
| 22 | |
| 23 | /* |
| 24 | * DECLARE_EVENT_CLASS can be used to add a generic function |
| 25 | * handlers for events. That is, if all events have the same |
| 26 | * parameters and just have distinct trace points. |
| 27 | * Each tracepoint can be defined with DEFINE_EVENT and that |
| 28 | * will map the DECLARE_EVENT_CLASS to the tracepoint. |
| 29 | * |
| 30 | * TRACE_EVENT is a one to one mapping between tracepoint and template. |
| 31 | */ |
| 32 | |
| 33 | #undef TRACE_EVENT |
| 34 | #define TRACE_EVENT(name, proto, args, tstruct, assign, print) \ |
| 35 | DECLARE_EVENT_CLASS(name, \ |
| 36 | PARAMS(proto), \ |
| 37 | PARAMS(args), \ |
| 38 | PARAMS(tstruct), \ |
| 39 | PARAMS(assign), \ |
| 40 | PARAMS(print)) \ |
| 41 | DEFINE_EVENT(name, name, PARAMS(proto), PARAMS(args)) |
| 42 | |
| 43 | #undef DEFINE_EVENT_PRINT |
| 44 | #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \ |
| 45 | DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args)) |
| 46 | |
| 47 | /* Callbacks are meaningless to LTTng. */ |
| 48 | #undef TRACE_EVENT_FN |
| 49 | #define TRACE_EVENT_FN(name, proto, args, tstruct, \ |
| 50 | assign, print, reg, unreg) \ |
| 51 | TRACE_EVENT(name, PARAMS(proto), PARAMS(args), \ |
| 52 | PARAMS(tstruct), PARAMS(assign), PARAMS(print)) \ |
| 53 | |
| 54 | /* |
| 55 | * Stage 1 of the trace events. |
| 56 | * |
| 57 | * Create event field type metadata section. |
| 58 | * Each event produce an array of fields. |
| 59 | */ |
| 60 | |
| 61 | #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */ |
| 62 | |
| 63 | /* Named field types must be defined in lttng-types.h */ |
| 64 | |
| 65 | #undef __field |
| 66 | #define __field(_type, _item) \ |
| 67 | { .name = #_item, .type = { .atype = atype_integer, .name = #_type} }, |
| 68 | |
| 69 | #undef __field_ext |
| 70 | #define __field_ext(_type, _item, _filter_type) __field(_type, _item) |
| 71 | |
| 72 | #undef __array |
| 73 | #define __array(_type, _item, _length) \ |
| 74 | { \ |
| 75 | .name = #_item, \ |
| 76 | .type = { \ |
| 77 | .atype = atype_array, \ |
| 78 | .name = NULL, \ |
| 79 | .u.array.elem_type = #_type, \ |
| 80 | .u.array.length = _length, \ |
| 81 | }, \ |
| 82 | }, |
| 83 | |
| 84 | #undef __dynamic_array |
| 85 | #define __dynamic_array(_type, _item, _length) \ |
| 86 | { \ |
| 87 | .name = #_item, \ |
| 88 | .type = { \ |
| 89 | .atype = atype_sequence, \ |
| 90 | .name = NULL, \ |
| 91 | .u.sequence.elem_type = #_type, \ |
| 92 | .u.sequence.length_type = "u32", \ |
| 93 | }, \ |
| 94 | }, |
| 95 | |
| 96 | #undef __string |
| 97 | #define __string(_item, _src) \ |
| 98 | { \ |
| 99 | .name = #_item, \ |
| 100 | .type = { \ |
| 101 | .atype = atype_string, \ |
| 102 | .name = NULL, \ |
| 103 | .u.string.encoding = lttng_encode_UTF8, \ |
| 104 | }, \ |
| 105 | }, |
| 106 | |
| 107 | #undef TP_STRUCT__entry |
| 108 | #define TP_STRUCT__entry(args...) args /* Only one used in this phase */ |
| 109 | |
| 110 | #undef DECLARE_EVENT_CLASS |
| 111 | #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \ |
| 112 | static const struct lttng_event_field __event_fields___##_name[] = { \ |
| 113 | _tstruct \ |
| 114 | }; |
| 115 | |
| 116 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
| 117 | |
| 118 | /* |
| 119 | * Stage 2 of the trace events. |
| 120 | * |
| 121 | * Create an array of events. |
| 122 | */ |
| 123 | |
| 124 | /* Named field types must be defined in lttng-types.h */ |
| 125 | |
| 126 | #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */ |
| 127 | |
| 128 | #undef DEFINE_EVENT |
| 129 | #define DEFINE_EVENT(_template, _name, _proto, _args) \ |
| 130 | { \ |
| 131 | .fields = __event_fields___##_template, \ |
| 132 | .name = #_name, \ |
| 133 | .nr_fields = ARRAY_SIZE(__event_fields___##_template), \ |
| 134 | }, |
| 135 | |
| 136 | #define TP_ID1(_token, _system) _token##_system |
| 137 | #define TP_ID(_token, _system) TP_ID1(_token, _system) |
| 138 | |
| 139 | static const struct lttng_event_desc TP_ID(__event_desc___, TRACE_SYSTEM)[] = { |
| 140 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
| 141 | }; |
| 142 | |
| 143 | #undef TP_ID1 |
| 144 | #undef TP_ID |
| 145 | |
| 146 | /* |
| 147 | * Stage 3 of the trace events. |
| 148 | * |
| 149 | * Create seq file metadata output. |
| 150 | */ |
| 151 | |
| 152 | #define TP_ID1(_token, _system) _token##_system |
| 153 | #define TP_ID(_token, _system) TP_ID1(_token, _system) |
| 154 | #define module_init_eval1(_token, _system) module_init(_token##_system) |
| 155 | #define module_init_eval(_token, _system) module_init_eval1(_token, _system) |
| 156 | #define module_exit_eval1(_token, _system) module_exit(_token##_system) |
| 157 | #define module_exit_eval(_token, _system) module_exit_eval1(_token, _system) |
| 158 | |
| 159 | static void *TP_ID(__lttng_seq_start__, TRACE_SYSTEM)(struct seq_file *m, |
| 160 | loff_t *pos) |
| 161 | { |
| 162 | const struct lttng_event_desc *desc = |
| 163 | &TP_ID(__event_desc___, TRACE_SYSTEM)[*pos]; |
| 164 | |
| 165 | if (desc > &TP_ID(__event_desc___, TRACE_SYSTEM) |
| 166 | [ARRAY_SIZE(TP_ID(__event_desc___, TRACE_SYSTEM)) - 1]) |
| 167 | return NULL; |
| 168 | return (void *) desc; |
| 169 | } |
| 170 | |
| 171 | static void *TP_ID(__lttng_seq_next__, TRACE_SYSTEM)(struct seq_file *m, |
| 172 | void *p, loff_t *ppos) |
| 173 | { |
| 174 | const struct lttng_event_desc *desc = |
| 175 | &TP_ID(__event_desc___, TRACE_SYSTEM)[++(*ppos)]; |
| 176 | |
| 177 | if (desc > &TP_ID(__event_desc___, TRACE_SYSTEM) |
| 178 | [ARRAY_SIZE(TP_ID(__event_desc___, TRACE_SYSTEM)) - 1]) |
| 179 | return NULL; |
| 180 | return (void *) desc; |
| 181 | } |
| 182 | |
| 183 | static void TP_ID(__lttng_seq_stop__, TRACE_SYSTEM)(struct seq_file *m, |
| 184 | void *p) |
| 185 | { |
| 186 | } |
| 187 | |
| 188 | static int TP_ID(__lttng_seq_show__, TRACE_SYSTEM)(struct seq_file *m, |
| 189 | void *p) |
| 190 | { |
| 191 | const struct lttng_event_desc *desc = p; |
| 192 | int i; |
| 193 | |
| 194 | seq_printf(m, "event {\n" |
| 195 | "\tname = %s;\n" |
| 196 | "\tid = UNKNOWN;\n" |
| 197 | "\tstream = UNKNOWN;\n" |
| 198 | "\tfields = {\n", |
| 199 | desc->name); |
| 200 | for (i = 0; i < desc->nr_fields; i++) { |
| 201 | if (desc->fields[i].type.name) /* Named type */ |
| 202 | seq_printf(m, "\t\t%s", |
| 203 | desc->fields[i].type.name); |
| 204 | else /* Nameless type */ |
| 205 | lttng_print_event_type(m, 2, &desc->fields[i].type); |
| 206 | seq_printf(m, " %s;\n", desc->fields[i].name); |
| 207 | } |
| 208 | seq_printf(m, "\t};\n"); |
| 209 | seq_printf(m, "};\n"); |
| 210 | return 0; |
| 211 | } |
| 212 | |
| 213 | static const |
| 214 | struct seq_operations TP_ID(__lttng_types_seq_ops__, TRACE_SYSTEM) = { |
| 215 | .start = TP_ID(__lttng_seq_start__, TRACE_SYSTEM), |
| 216 | .next = TP_ID(__lttng_seq_next__, TRACE_SYSTEM), |
| 217 | .stop = TP_ID(__lttng_seq_stop__, TRACE_SYSTEM), |
| 218 | .show = TP_ID(__lttng_seq_show__, TRACE_SYSTEM), |
| 219 | }; |
| 220 | |
| 221 | static int |
| 222 | TP_ID(__lttng_types_open__, TRACE_SYSTEM)(struct inode *inode, struct file *file) |
| 223 | { |
| 224 | return seq_open(file, &TP_ID(__lttng_types_seq_ops__, TRACE_SYSTEM)); |
| 225 | } |
| 226 | |
| 227 | static const |
| 228 | struct file_operations TP_ID(__lttng_types_fops__, TRACE_SYSTEM) = { |
| 229 | .open = TP_ID(__lttng_types_open__, TRACE_SYSTEM), |
| 230 | .read = seq_read, |
| 231 | .llseek = seq_lseek, |
| 232 | .release = seq_release_private, |
| 233 | }; |
| 234 | |
| 235 | static struct dentry *TP_ID(__lttng_types_dentry__, TRACE_SYSTEM); |
| 236 | |
| 237 | static int TP_ID(__lttng_types_init__, TRACE_SYSTEM)(void) |
| 238 | { |
| 239 | int ret = 0; |
| 240 | |
| 241 | TP_ID(__lttng_types_dentry__, TRACE_SYSTEM) = |
| 242 | debugfs_create_file("lttng-events-" __stringify(TRACE_SYSTEM), |
| 243 | S_IWUSR, NULL, NULL, |
| 244 | &TP_ID(__lttng_types_fops__, TRACE_SYSTEM)); |
| 245 | if (IS_ERR(TP_ID(__lttng_types_dentry__, TRACE_SYSTEM)) |
| 246 | || !TP_ID(__lttng_types_dentry__, TRACE_SYSTEM)) { |
| 247 | printk(KERN_ERR "Error creating LTTng type export file\n"); |
| 248 | ret = -ENOMEM; |
| 249 | goto error; |
| 250 | } |
| 251 | error: |
| 252 | return ret; |
| 253 | } |
| 254 | |
| 255 | module_init_eval(__lttng_types_init__, TRACE_SYSTEM); |
| 256 | |
| 257 | static void TP_ID(__lttng_types_exit__, TRACE_SYSTEM)(void) |
| 258 | { |
| 259 | debugfs_remove(TP_ID(__lttng_types_dentry__, TRACE_SYSTEM)); |
| 260 | } |
| 261 | |
| 262 | module_exit_eval(__lttng_types_exit__, TRACE_SYSTEM); |
| 263 | |
| 264 | #undef module_init_eval |
| 265 | #undef module_exit_eval |
| 266 | #undef TP_ID1 |
| 267 | #undef TP_ID |
| 268 | |
| 269 | /* |
| 270 | * Stage 4 of the trace events. |
| 271 | * |
| 272 | * Create static inline function that calculates event size. |
| 273 | */ |
| 274 | |
| 275 | #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */ |
| 276 | |
| 277 | /* Named field types must be defined in lttng-types.h */ |
| 278 | |
| 279 | #undef __field |
| 280 | #define __field(_type, _item) \ |
| 281 | __event_len += lib_ring_buffer_align(__event_len, __alignof__(_type)); \ |
| 282 | __event_len += sizeof(_type); |
| 283 | |
| 284 | #undef __field_ext |
| 285 | #define __field_ext(_type, _item, _filter_type) __field(_type, _item) |
| 286 | |
| 287 | #undef __array |
| 288 | #define __array(_type, _item, _length) \ |
| 289 | __event_len += lib_ring_buffer_align(__event_len, __alignof__(_type)); \ |
| 290 | __event_len += sizeof(_type) * (_length); |
| 291 | |
| 292 | #undef __dynamic_array |
| 293 | #define __dynamic_array(_type, _item, _length) \ |
| 294 | __event_len += lib_ring_buffer_align(__event_len, __alignof__(u32)); \ |
| 295 | __event_len += sizeof(u32); \ |
| 296 | __event_len += lib_ring_buffer_align(__event_len, __alignof__(_type)); \ |
| 297 | __event_len += sizeof(_type) * (_length); |
| 298 | |
| 299 | #undef __string |
| 300 | #define __string(_item, _src) \ |
| 301 | __event_len += __dynamic_len[__dynamic_len_idx++] = strlen(_src) + 1; |
| 302 | |
| 303 | #undef TP_PROTO |
| 304 | #define TP_PROTO(args...) args |
| 305 | |
| 306 | #undef TP_STRUCT__entry |
| 307 | #define TP_STRUCT__entry(args...) args |
| 308 | |
| 309 | #undef DECLARE_EVENT_CLASS |
| 310 | #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \ |
| 311 | static inline size_t __event_get_size__##_name(size_t *__dynamic_len, _proto) \ |
| 312 | { \ |
| 313 | size_t __event_len = 0; \ |
| 314 | unsigned int __dynamic_len_idx = 0; \ |
| 315 | \ |
| 316 | if (0) \ |
| 317 | (void) __dynamic_len_idx; /* don't warn if unused */ \ |
| 318 | _tstruct \ |
| 319 | return __event_len; \ |
| 320 | } |
| 321 | |
| 322 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
| 323 | |
| 324 | |
| 325 | |
| 326 | /* |
| 327 | * Stage 5 of the trace events. |
| 328 | * |
| 329 | * Create static inline function that calculates event payload alignment. |
| 330 | */ |
| 331 | |
| 332 | #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */ |
| 333 | |
| 334 | /* Named field types must be defined in lttng-types.h */ |
| 335 | |
| 336 | #undef __field |
| 337 | #define __field(_type, _item) \ |
| 338 | __event_align = max_t(size_t, __event_align, __alignof__(_type)); |
| 339 | |
| 340 | #undef __field_ext |
| 341 | #define __field_ext(_type, _item, _filter_type) __field(_type, _item) |
| 342 | |
| 343 | #undef __array |
| 344 | #define __array(_type, _item, _length) \ |
| 345 | __event_align = max_t(size_t, __event_align, __alignof__(_type)); |
| 346 | |
| 347 | #undef __dynamic_array |
| 348 | #define __dynamic_array(_type, _item, _length) \ |
| 349 | __event_align = max_t(size_t, __event_align, __alignof__(u32)); \ |
| 350 | __event_align = max_t(size_t, __event_align, __alignof__(_type)); |
| 351 | |
| 352 | #undef __string |
| 353 | #define __string(_item, _src) |
| 354 | |
| 355 | #undef TP_PROTO |
| 356 | #define TP_PROTO(args...) args |
| 357 | |
| 358 | #undef TP_STRUCT__entry |
| 359 | #define TP_STRUCT__entry(args...) args |
| 360 | |
| 361 | #undef DECLARE_EVENT_CLASS |
| 362 | #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \ |
| 363 | static inline size_t __event_get_align__##_name(_proto) \ |
| 364 | { \ |
| 365 | size_t __event_align = 1; \ |
| 366 | _tstruct \ |
| 367 | return __event_align; \ |
| 368 | } |
| 369 | |
| 370 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
| 371 | |
| 372 | |
| 373 | /* |
| 374 | * Stage 6 of the trace events. |
| 375 | * |
| 376 | * Create structure declaration that allows the "assign" macros to access the |
| 377 | * field types. |
| 378 | */ |
| 379 | |
| 380 | #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */ |
| 381 | |
| 382 | /* Named field types must be defined in lttng-types.h */ |
| 383 | |
| 384 | #undef __field |
| 385 | #define __field(_type, _item) _type _item; |
| 386 | |
| 387 | #undef __field_ext |
| 388 | #define __field_ext(_type, _item, _filter_type) __field(_type, _item) |
| 389 | |
| 390 | #undef __array |
| 391 | #define __array(_type, _item, _length) _type _item; |
| 392 | |
| 393 | #undef __dynamic_array |
| 394 | #define __dynamic_array(_type, _item, _length) _type _item; |
| 395 | |
| 396 | #undef __string |
| 397 | #define __string(_item, _src) char _item; |
| 398 | |
| 399 | #undef TP_STRUCT__entry |
| 400 | #define TP_STRUCT__entry(args...) args |
| 401 | |
| 402 | #undef DECLARE_EVENT_CLASS |
| 403 | #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \ |
| 404 | struct __event_typemap__##_name { \ |
| 405 | _tstruct \ |
| 406 | }; |
| 407 | |
| 408 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
| 409 | |
| 410 | |
| 411 | /* |
| 412 | * Stage 7 of the trace events. |
| 413 | * |
| 414 | * Create the probe function : call even size calculation and write event data |
| 415 | * into the buffer. |
| 416 | * |
| 417 | * We use both the field and assignment macros to write the fields in the order |
| 418 | * defined in the field declaration. The field declarations control the |
| 419 | * execution order, jumping to the appropriate assignment block. |
| 420 | */ |
| 421 | |
| 422 | #include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */ |
| 423 | |
| 424 | #undef __field |
| 425 | #define __field(_type, _item) \ |
| 426 | goto __assign_##_item; \ |
| 427 | __end_field_##_item: |
| 428 | |
| 429 | #undef __field_ext |
| 430 | #define __field_ext(_type, _item, _filter_type) __field(_type, _item) |
| 431 | |
| 432 | #undef __array |
| 433 | #define __array(_type, _item, _length) \ |
| 434 | goto __assign_##_item; \ |
| 435 | __end_field_##_item: |
| 436 | |
| 437 | #undef __dynamic_array |
| 438 | #define __dynamic_array(_type, _item, _length) \ |
| 439 | goto __assign_##_item##_1; \ |
| 440 | __end_field_##_item##_1: \ |
| 441 | goto __assign_##_item##_2; \ |
| 442 | __end_field_##_item##_2: |
| 443 | |
| 444 | #undef __string |
| 445 | #define __string(_item, _src) \ |
| 446 | goto __assign_##_item; \ |
| 447 | __end_field_##_item: |
| 448 | |
| 449 | /* |
| 450 | * Macros mapping tp_assign() to "=", tp_memcpy() to memcpy() and tp_strcpy() to |
| 451 | * strcpy(). |
| 452 | */ |
| 453 | #undef tp_assign |
| 454 | #define tp_assign(dest, src) \ |
| 455 | __assign_##dest: \ |
| 456 | { \ |
| 457 | __typeof__(__typemap.dest) __tmp = (src); \ |
| 458 | lib_ring_buffer_align_ctx(&ctx, __alignof__(__tmp)); \ |
| 459 | __chan->ops->event_write(&ctx, &__tmp, sizeof(__tmp)); \ |
| 460 | } \ |
| 461 | goto __end_field_##dest; |
| 462 | |
| 463 | #undef tp_memcpy |
| 464 | #define tp_memcpy(dest, src, len) \ |
| 465 | __assign_##dest: \ |
| 466 | lib_ring_buffer_align_ctx(&ctx, __alignof__(__typemap.dest)); \ |
| 467 | __chan->ops->event_write(&ctx, src, len); \ |
| 468 | goto __end_field_##dest; |
| 469 | |
| 470 | #undef tp_memcpy_dyn |
| 471 | #define tp_memcpy_dyn(dest, src, len) \ |
| 472 | __assign_##dest##_1: \ |
| 473 | { \ |
| 474 | u32 __tmpl = (len); \ |
| 475 | lib_ring_buffer_align_ctx(&ctx, __alignof__(u32)); \ |
| 476 | __chan->ops->event_write(&ctx, &__tmpl, sizeof(u32)); \ |
| 477 | } \ |
| 478 | goto __end_field_##dest##_1; \ |
| 479 | __assign_##dest##_2: \ |
| 480 | lib_ring_buffer_align_ctx(&ctx, __alignof__(__typemap.dest)); \ |
| 481 | __chan->ops->event_write(&ctx, src, len); \ |
| 482 | goto __end_field_##dest##_2; |
| 483 | |
| 484 | #undef tp_strcpy |
| 485 | #define tp_strcpy(dest, src) \ |
| 486 | tp_memcpy(dest, src, __get_dynamic_array_len(dest)) |
| 487 | |
| 488 | /* Named field types must be defined in lttng-types.h */ |
| 489 | |
| 490 | #undef __get_str |
| 491 | #define __get_str(field) field |
| 492 | |
| 493 | #undef __get_dynamic_array |
| 494 | #define __get_dynamic_array(field) field |
| 495 | |
| 496 | /* Beware: this get len actually consumes the len value */ |
| 497 | #undef __get_dynamic_array_len |
| 498 | #define __get_dynamic_array_len(field) __dynamic_len[__dynamic_len_idx++] |
| 499 | |
| 500 | #undef TP_PROTO |
| 501 | #define TP_PROTO(args...) args |
| 502 | |
| 503 | #undef TP_ARGS |
| 504 | #define TP_ARGS(args...) args |
| 505 | |
| 506 | #undef TP_STRUCT__entry |
| 507 | #define TP_STRUCT__entry(args...) args |
| 508 | |
| 509 | #undef TP_fast_assign |
| 510 | #define TP_fast_assign(args...) args |
| 511 | |
| 512 | #undef DECLARE_EVENT_CLASS |
| 513 | #define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \ |
| 514 | static void __event_probe__##_name(void *__data, _proto) \ |
| 515 | { \ |
| 516 | struct ltt_event *__event = __data; \ |
| 517 | struct ltt_channel *__chan = __event->chan; \ |
| 518 | struct lib_ring_buffer_ctx ctx; \ |
| 519 | size_t __event_len, __event_align; \ |
| 520 | size_t __dynamic_len_idx = 0; \ |
| 521 | size_t __dynamic_len[ARRAY_SIZE(__event_fields___##_name)]; \ |
| 522 | struct __event_typemap__##_name __typemap; \ |
| 523 | int __ret; \ |
| 524 | \ |
| 525 | if (0) \ |
| 526 | (void) __dynamic_len_idx; /* don't warn if unused */ \ |
| 527 | __event_len = __event_get_size__##_name(__dynamic_len, _args); \ |
| 528 | __event_align = __event_get_align__##_name(_args); \ |
| 529 | lib_ring_buffer_ctx_init(&ctx, __chan->chan, NULL, __event_len, \ |
| 530 | __event_align, -1); \ |
| 531 | __ret = __chan->ops->event_reserve(&ctx); \ |
| 532 | if (__ret < 0) \ |
| 533 | return; \ |
| 534 | /* Control code (field ordering) */ \ |
| 535 | _tstruct \ |
| 536 | __chan->ops->event_commit(&ctx); \ |
| 537 | return; \ |
| 538 | /* Copy code, steered by control code */ \ |
| 539 | _assign \ |
| 540 | } |
| 541 | |
| 542 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
| 543 | |
| 544 | |
| 545 | #if 0 |
| 546 | |
| 547 | #include <linux/ftrace_event.h> |
| 548 | |
| 549 | /* |
| 550 | * DECLARE_EVENT_CLASS can be used to add a generic function |
| 551 | * handlers for events. That is, if all events have the same |
| 552 | * parameters and just have distinct trace points. |
| 553 | * Each tracepoint can be defined with DEFINE_EVENT and that |
| 554 | * will map the DECLARE_EVENT_CLASS to the tracepoint. |
| 555 | * |
| 556 | * TRACE_EVENT is a one to one mapping between tracepoint and template. |
| 557 | */ |
| 558 | #undef TRACE_EVENT |
| 559 | #define TRACE_EVENT(name, proto, args, tstruct, assign, print) \ |
| 560 | DECLARE_EVENT_CLASS(name, \ |
| 561 | PARAMS(proto), \ |
| 562 | PARAMS(args), \ |
| 563 | PARAMS(tstruct), \ |
| 564 | PARAMS(assign), \ |
| 565 | PARAMS(print)); \ |
| 566 | DEFINE_EVENT(name, name, PARAMS(proto), PARAMS(args)); |
| 567 | |
| 568 | |
| 569 | #undef __field |
| 570 | #define __field(type, item) type item; |
| 571 | |
| 572 | #undef __field_ext |
| 573 | #define __field_ext(type, item, filter_type) type item; |
| 574 | |
| 575 | #undef __array |
| 576 | #define __array(type, item, len) type item[len]; |
| 577 | |
| 578 | #undef __dynamic_array |
| 579 | #define __dynamic_array(type, item, len) u32 __data_loc_##item; |
| 580 | |
| 581 | #undef __string |
| 582 | #define __string(item, src) __dynamic_array(char, item, -1) |
| 583 | |
| 584 | #undef TP_STRUCT__entry |
| 585 | #define TP_STRUCT__entry(args...) args |
| 586 | |
| 587 | #undef DECLARE_EVENT_CLASS |
| 588 | #define DECLARE_EVENT_CLASS(name, proto, args, tstruct, assign, print) \ |
| 589 | struct ftrace_raw_##name { \ |
| 590 | struct trace_entry ent; \ |
| 591 | tstruct \ |
| 592 | char __data[0]; \ |
| 593 | }; \ |
| 594 | \ |
| 595 | static struct ftrace_event_class event_class_##name; |
| 596 | |
| 597 | #undef DEFINE_EVENT |
| 598 | #define DEFINE_EVENT(template, name, proto, args) \ |
| 599 | static struct ftrace_event_call __used \ |
| 600 | __attribute__((__aligned__(4))) event_##name |
| 601 | |
| 602 | #undef DEFINE_EVENT_PRINT |
| 603 | #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \ |
| 604 | DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args)) |
| 605 | |
| 606 | /* Callbacks are meaningless to ftrace. */ |
| 607 | #undef TRACE_EVENT_FN |
| 608 | #define TRACE_EVENT_FN(name, proto, args, tstruct, \ |
| 609 | assign, print, reg, unreg) \ |
| 610 | TRACE_EVENT(name, PARAMS(proto), PARAMS(args), \ |
| 611 | PARAMS(tstruct), PARAMS(assign), PARAMS(print)) \ |
| 612 | |
| 613 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
| 614 | |
| 615 | |
| 616 | /* |
| 617 | * Stage 2 of the trace events. |
| 618 | * |
| 619 | * Create static inline function that calculates event size. |
| 620 | */ |
| 621 | |
| 622 | #undef __field |
| 623 | #define __field(type, item) |
| 624 | |
| 625 | #undef __field_ext |
| 626 | #define __field_ext(type, item, filter_type) |
| 627 | |
| 628 | #undef __array |
| 629 | #define __array(type, item, len) |
| 630 | |
| 631 | #undef __dynamic_array |
| 632 | #define __dynamic_array(type, item, len) u32 item; |
| 633 | |
| 634 | #undef __string |
| 635 | #define __string(item, src) __dynamic_array(char, item, -1) |
| 636 | |
| 637 | #undef DECLARE_EVENT_CLASS |
| 638 | #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \ |
| 639 | struct ftrace_data_offsets_##call { \ |
| 640 | tstruct; \ |
| 641 | }; |
| 642 | |
| 643 | #undef DEFINE_EVENT |
| 644 | #define DEFINE_EVENT(template, name, proto, args) |
| 645 | |
| 646 | #undef DEFINE_EVENT_PRINT |
| 647 | #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \ |
| 648 | DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args)) |
| 649 | |
| 650 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
| 651 | |
| 652 | /* |
| 653 | * Stage 3 of the trace events. |
| 654 | * |
| 655 | * Create the probe function : call even size calculation and write event data |
| 656 | * into the buffer. |
| 657 | */ |
| 658 | |
| 659 | #undef __entry |
| 660 | #define __entry field |
| 661 | |
| 662 | #undef TP_printk |
| 663 | #define TP_printk(fmt, args...) fmt "\n", args |
| 664 | |
| 665 | #undef __get_dynamic_array |
| 666 | #define __get_dynamic_array(field) \ |
| 667 | ((void *)__entry + (__entry->__data_loc_##field & 0xffff)) |
| 668 | |
| 669 | #undef __get_str |
| 670 | #define __get_str(field) (char *)__get_dynamic_array(field) |
| 671 | |
| 672 | #undef __print_flags |
| 673 | #define __print_flags(flag, delim, flag_array...) \ |
| 674 | ({ \ |
| 675 | static const struct trace_print_flags __flags[] = \ |
| 676 | { flag_array, { -1, NULL }}; \ |
| 677 | ftrace_print_flags_seq(p, delim, flag, __flags); \ |
| 678 | }) |
| 679 | |
| 680 | #undef __print_symbolic |
| 681 | #define __print_symbolic(value, symbol_array...) \ |
| 682 | ({ \ |
| 683 | static const struct trace_print_flags symbols[] = \ |
| 684 | { symbol_array, { -1, NULL }}; \ |
| 685 | ftrace_print_symbols_seq(p, value, symbols); \ |
| 686 | }) |
| 687 | |
| 688 | #undef __print_hex |
| 689 | #define __print_hex(buf, buf_len) ftrace_print_hex_seq(p, buf, buf_len) |
| 690 | |
| 691 | #undef DECLARE_EVENT_CLASS |
| 692 | #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \ |
| 693 | static notrace enum print_line_t \ |
| 694 | ftrace_raw_output_##call(struct trace_iterator *iter, int flags, \ |
| 695 | struct trace_event *trace_event) \ |
| 696 | { \ |
| 697 | struct ftrace_event_call *event; \ |
| 698 | struct trace_seq *s = &iter->seq; \ |
| 699 | struct ftrace_raw_##call *field; \ |
| 700 | struct trace_entry *entry; \ |
| 701 | struct trace_seq *p = &iter->tmp_seq; \ |
| 702 | int ret; \ |
| 703 | \ |
| 704 | event = container_of(trace_event, struct ftrace_event_call, \ |
| 705 | event); \ |
| 706 | \ |
| 707 | entry = iter->ent; \ |
| 708 | \ |
| 709 | if (entry->type != event->event.type) { \ |
| 710 | WARN_ON_ONCE(1); \ |
| 711 | return TRACE_TYPE_UNHANDLED; \ |
| 712 | } \ |
| 713 | \ |
| 714 | field = (typeof(field))entry; \ |
| 715 | \ |
| 716 | trace_seq_init(p); \ |
| 717 | ret = trace_seq_printf(s, "%s: ", event->name); \ |
| 718 | if (ret) \ |
| 719 | ret = trace_seq_printf(s, print); \ |
| 720 | if (!ret) \ |
| 721 | return TRACE_TYPE_PARTIAL_LINE; \ |
| 722 | \ |
| 723 | return TRACE_TYPE_HANDLED; \ |
| 724 | } \ |
| 725 | static struct trace_event_functions ftrace_event_type_funcs_##call = { \ |
| 726 | .trace = ftrace_raw_output_##call, \ |
| 727 | }; |
| 728 | |
| 729 | #undef DEFINE_EVENT_PRINT |
| 730 | #define DEFINE_EVENT_PRINT(template, call, proto, args, print) \ |
| 731 | static notrace enum print_line_t \ |
| 732 | ftrace_raw_output_##call(struct trace_iterator *iter, int flags, \ |
| 733 | struct trace_event *event) \ |
| 734 | { \ |
| 735 | struct trace_seq *s = &iter->seq; \ |
| 736 | struct ftrace_raw_##template *field; \ |
| 737 | struct trace_entry *entry; \ |
| 738 | struct trace_seq *p = &iter->tmp_seq; \ |
| 739 | int ret; \ |
| 740 | \ |
| 741 | entry = iter->ent; \ |
| 742 | \ |
| 743 | if (entry->type != event_##call.event.type) { \ |
| 744 | WARN_ON_ONCE(1); \ |
| 745 | return TRACE_TYPE_UNHANDLED; \ |
| 746 | } \ |
| 747 | \ |
| 748 | field = (typeof(field))entry; \ |
| 749 | \ |
| 750 | trace_seq_init(p); \ |
| 751 | ret = trace_seq_printf(s, "%s: ", #call); \ |
| 752 | if (ret) \ |
| 753 | ret = trace_seq_printf(s, print); \ |
| 754 | if (!ret) \ |
| 755 | return TRACE_TYPE_PARTIAL_LINE; \ |
| 756 | \ |
| 757 | return TRACE_TYPE_HANDLED; \ |
| 758 | } \ |
| 759 | static struct trace_event_functions ftrace_event_type_funcs_##call = { \ |
| 760 | .trace = ftrace_raw_output_##call, \ |
| 761 | }; |
| 762 | |
| 763 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
| 764 | |
| 765 | #undef __field_ext |
| 766 | #define __field_ext(type, item, filter_type) \ |
| 767 | ret = trace_define_field(event_call, #type, #item, \ |
| 768 | offsetof(typeof(field), item), \ |
| 769 | sizeof(field.item), \ |
| 770 | is_signed_type(type), filter_type); \ |
| 771 | if (ret) \ |
| 772 | return ret; |
| 773 | |
| 774 | #undef __field |
| 775 | #define __field(type, item) __field_ext(type, item, FILTER_OTHER) |
| 776 | |
| 777 | #undef __array |
| 778 | #define __array(type, item, len) \ |
| 779 | BUILD_BUG_ON(len > MAX_FILTER_STR_VAL); \ |
| 780 | ret = trace_define_field(event_call, #type "[" #len "]", #item, \ |
| 781 | offsetof(typeof(field), item), \ |
| 782 | sizeof(field.item), \ |
| 783 | is_signed_type(type), FILTER_OTHER); \ |
| 784 | if (ret) \ |
| 785 | return ret; |
| 786 | |
| 787 | #undef __dynamic_array |
| 788 | #define __dynamic_array(type, item, len) \ |
| 789 | ret = trace_define_field(event_call, "__data_loc " #type "[]", #item, \ |
| 790 | offsetof(typeof(field), __data_loc_##item), \ |
| 791 | sizeof(field.__data_loc_##item), \ |
| 792 | is_signed_type(type), FILTER_OTHER); |
| 793 | |
| 794 | #undef __string |
| 795 | #define __string(item, src) __dynamic_array(char, item, -1) |
| 796 | |
| 797 | #undef DECLARE_EVENT_CLASS |
| 798 | #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, func, print) \ |
| 799 | static int notrace \ |
| 800 | ftrace_define_fields_##call(struct ftrace_event_call *event_call) \ |
| 801 | { \ |
| 802 | struct ftrace_raw_##call field; \ |
| 803 | int ret; \ |
| 804 | \ |
| 805 | tstruct; \ |
| 806 | \ |
| 807 | return ret; \ |
| 808 | } |
| 809 | |
| 810 | #undef DEFINE_EVENT |
| 811 | #define DEFINE_EVENT(template, name, proto, args) |
| 812 | |
| 813 | #undef DEFINE_EVENT_PRINT |
| 814 | #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \ |
| 815 | DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args)) |
| 816 | |
| 817 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
| 818 | |
| 819 | /* |
| 820 | * remember the offset of each array from the beginning of the event. |
| 821 | */ |
| 822 | |
| 823 | #undef __entry |
| 824 | #define __entry entry |
| 825 | |
| 826 | #undef __field |
| 827 | #define __field(type, item) |
| 828 | |
| 829 | #undef __field_ext |
| 830 | #define __field_ext(type, item, filter_type) |
| 831 | |
| 832 | #undef __array |
| 833 | #define __array(type, item, len) |
| 834 | |
| 835 | #undef __dynamic_array |
| 836 | #define __dynamic_array(type, item, len) \ |
| 837 | __data_offsets->item = __data_size + \ |
| 838 | offsetof(typeof(*entry), __data); \ |
| 839 | __data_offsets->item |= (len * sizeof(type)) << 16; \ |
| 840 | __data_size += (len) * sizeof(type); |
| 841 | |
| 842 | #undef __string |
| 843 | #define __string(item, src) __dynamic_array(char, item, strlen(src) + 1) |
| 844 | |
| 845 | #undef DECLARE_EVENT_CLASS |
| 846 | #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \ |
| 847 | static inline notrace int ftrace_get_offsets_##call( \ |
| 848 | struct ftrace_data_offsets_##call *__data_offsets, proto) \ |
| 849 | { \ |
| 850 | int __data_size = 0; \ |
| 851 | struct ftrace_raw_##call __maybe_unused *entry; \ |
| 852 | \ |
| 853 | tstruct; \ |
| 854 | \ |
| 855 | return __data_size; \ |
| 856 | } |
| 857 | |
| 858 | #undef DEFINE_EVENT |
| 859 | #define DEFINE_EVENT(template, name, proto, args) |
| 860 | |
| 861 | #undef DEFINE_EVENT_PRINT |
| 862 | #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \ |
| 863 | DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args)) |
| 864 | |
| 865 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
| 866 | |
| 867 | /* |
| 868 | * Stage 4 of the trace events. |
| 869 | * |
| 870 | * Override the macros in <trace/trace_events.h> to include the following: |
| 871 | * |
| 872 | * For those macros defined with TRACE_EVENT: |
| 873 | * |
| 874 | * static struct ftrace_event_call event_<call>; |
| 875 | * |
| 876 | * static void ftrace_raw_event_<call>(void *__data, proto) |
| 877 | * { |
| 878 | * struct ftrace_event_call *event_call = __data; |
| 879 | * struct ftrace_data_offsets_<call> __maybe_unused __data_offsets; |
| 880 | * struct ring_buffer_event *event; |
| 881 | * struct ftrace_raw_<call> *entry; <-- defined in stage 1 |
| 882 | * struct ring_buffer *buffer; |
| 883 | * unsigned long irq_flags; |
| 884 | * int __data_size; |
| 885 | * int pc; |
| 886 | * |
| 887 | * local_save_flags(irq_flags); |
| 888 | * pc = preempt_count(); |
| 889 | * |
| 890 | * __data_size = ftrace_get_offsets_<call>(&__data_offsets, args); |
| 891 | * |
| 892 | * event = trace_current_buffer_lock_reserve(&buffer, |
| 893 | * event_<call>->event.type, |
| 894 | * sizeof(*entry) + __data_size, |
| 895 | * irq_flags, pc); |
| 896 | * if (!event) |
| 897 | * return; |
| 898 | * entry = ring_buffer_event_data(event); |
| 899 | * |
| 900 | * { <assign>; } <-- Here we assign the entries by the __field and |
| 901 | * __array macros. |
| 902 | * |
| 903 | * if (!filter_current_check_discard(buffer, event_call, entry, event)) |
| 904 | * trace_current_buffer_unlock_commit(buffer, |
| 905 | * event, irq_flags, pc); |
| 906 | * } |
| 907 | * |
| 908 | * static struct trace_event ftrace_event_type_<call> = { |
| 909 | * .trace = ftrace_raw_output_<call>, <-- stage 2 |
| 910 | * }; |
| 911 | * |
| 912 | * static const char print_fmt_<call>[] = <TP_printk>; |
| 913 | * |
| 914 | * static struct ftrace_event_class __used event_class_<template> = { |
| 915 | * .system = "<system>", |
| 916 | * .define_fields = ftrace_define_fields_<call>, |
| 917 | * .fields = LIST_HEAD_INIT(event_class_##call.fields), |
| 918 | * .raw_init = trace_event_raw_init, |
| 919 | * .probe = ftrace_raw_event_##call, |
| 920 | * .reg = ftrace_event_reg, |
| 921 | * }; |
| 922 | * |
| 923 | * static struct ftrace_event_call __used |
| 924 | * __attribute__((__aligned__(4))) |
| 925 | * __attribute__((section("_ftrace_events"))) event_<call> = { |
| 926 | * .name = "<call>", |
| 927 | * .class = event_class_<template>, |
| 928 | * .event = &ftrace_event_type_<call>, |
| 929 | * .print_fmt = print_fmt_<call>, |
| 930 | * }; |
| 931 | * |
| 932 | */ |
| 933 | |
| 934 | #ifdef CONFIG_PERF_EVENTS |
| 935 | |
| 936 | #define _TRACE_PERF_PROTO(call, proto) \ |
| 937 | static notrace void \ |
| 938 | perf_trace_##call(void *__data, proto); |
| 939 | |
| 940 | #define _TRACE_PERF_INIT(call) \ |
| 941 | .perf_probe = perf_trace_##call, |
| 942 | |
| 943 | #else |
| 944 | #define _TRACE_PERF_PROTO(call, proto) |
| 945 | #define _TRACE_PERF_INIT(call) |
| 946 | #endif /* CONFIG_PERF_EVENTS */ |
| 947 | |
| 948 | #undef __entry |
| 949 | #define __entry entry |
| 950 | |
| 951 | #undef __field |
| 952 | #define __field(type, item) |
| 953 | |
| 954 | #undef __array |
| 955 | #define __array(type, item, len) |
| 956 | |
| 957 | #undef __dynamic_array |
| 958 | #define __dynamic_array(type, item, len) \ |
| 959 | __entry->__data_loc_##item = __data_offsets.item; |
| 960 | |
| 961 | #undef __string |
| 962 | #define __string(item, src) __dynamic_array(char, item, -1) \ |
| 963 | |
| 964 | #undef __assign_str |
| 965 | #define __assign_str(dst, src) \ |
| 966 | strcpy(__get_str(dst), src); |
| 967 | |
| 968 | #undef TP_fast_assign |
| 969 | #define TP_fast_assign(args...) args |
| 970 | |
| 971 | #undef TP_perf_assign |
| 972 | #define TP_perf_assign(args...) |
| 973 | |
| 974 | #undef DECLARE_EVENT_CLASS |
| 975 | #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \ |
| 976 | \ |
| 977 | static notrace void \ |
| 978 | ftrace_raw_event_##call(void *__data, proto) \ |
| 979 | { \ |
| 980 | struct ftrace_event_call *event_call = __data; \ |
| 981 | struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\ |
| 982 | struct ring_buffer_event *event; \ |
| 983 | struct ftrace_raw_##call *entry; \ |
| 984 | struct ring_buffer *buffer; \ |
| 985 | unsigned long irq_flags; \ |
| 986 | int __data_size; \ |
| 987 | int pc; \ |
| 988 | \ |
| 989 | local_save_flags(irq_flags); \ |
| 990 | pc = preempt_count(); \ |
| 991 | \ |
| 992 | __data_size = ftrace_get_offsets_##call(&__data_offsets, args); \ |
| 993 | \ |
| 994 | event = trace_current_buffer_lock_reserve(&buffer, \ |
| 995 | event_call->event.type, \ |
| 996 | sizeof(*entry) + __data_size, \ |
| 997 | irq_flags, pc); \ |
| 998 | if (!event) \ |
| 999 | return; \ |
| 1000 | entry = ring_buffer_event_data(event); \ |
| 1001 | \ |
| 1002 | tstruct \ |
| 1003 | \ |
| 1004 | { assign; } \ |
| 1005 | \ |
| 1006 | if (!filter_current_check_discard(buffer, event_call, entry, event)) \ |
| 1007 | trace_nowake_buffer_unlock_commit(buffer, \ |
| 1008 | event, irq_flags, pc); \ |
| 1009 | } |
| 1010 | /* |
| 1011 | * The ftrace_test_probe is compiled out, it is only here as a build time check |
| 1012 | * to make sure that if the tracepoint handling changes, the ftrace probe will |
| 1013 | * fail to compile unless it too is updated. |
| 1014 | */ |
| 1015 | |
| 1016 | #undef DEFINE_EVENT |
| 1017 | #define DEFINE_EVENT(template, call, proto, args) \ |
| 1018 | static inline void ftrace_test_probe_##call(void) \ |
| 1019 | { \ |
| 1020 | check_trace_callback_type_##call(ftrace_raw_event_##template); \ |
| 1021 | } |
| 1022 | |
| 1023 | #undef DEFINE_EVENT_PRINT |
| 1024 | #define DEFINE_EVENT_PRINT(template, name, proto, args, print) |
| 1025 | |
| 1026 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
| 1027 | |
| 1028 | #undef __entry |
| 1029 | #define __entry REC |
| 1030 | |
| 1031 | #undef __print_flags |
| 1032 | #undef __print_symbolic |
| 1033 | #undef __get_dynamic_array |
| 1034 | #undef __get_str |
| 1035 | |
| 1036 | #undef TP_printk |
| 1037 | #define TP_printk(fmt, args...) "\"" fmt "\", " __stringify(args) |
| 1038 | |
| 1039 | #undef DECLARE_EVENT_CLASS |
| 1040 | #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \ |
| 1041 | _TRACE_PERF_PROTO(call, PARAMS(proto)); \ |
| 1042 | static const char print_fmt_##call[] = print; \ |
| 1043 | static struct ftrace_event_class __used event_class_##call = { \ |
| 1044 | .system = __stringify(TRACE_SYSTEM), \ |
| 1045 | .define_fields = ftrace_define_fields_##call, \ |
| 1046 | .fields = LIST_HEAD_INIT(event_class_##call.fields),\ |
| 1047 | .raw_init = trace_event_raw_init, \ |
| 1048 | .probe = ftrace_raw_event_##call, \ |
| 1049 | .reg = ftrace_event_reg, \ |
| 1050 | _TRACE_PERF_INIT(call) \ |
| 1051 | }; |
| 1052 | |
| 1053 | #undef DEFINE_EVENT |
| 1054 | #define DEFINE_EVENT(template, call, proto, args) \ |
| 1055 | \ |
| 1056 | static struct ftrace_event_call __used \ |
| 1057 | __attribute__((__aligned__(4))) \ |
| 1058 | __attribute__((section("_ftrace_events"))) event_##call = { \ |
| 1059 | .name = #call, \ |
| 1060 | .class = &event_class_##template, \ |
| 1061 | .event.funcs = &ftrace_event_type_funcs_##template, \ |
| 1062 | .print_fmt = print_fmt_##template, \ |
| 1063 | }; |
| 1064 | |
| 1065 | #undef DEFINE_EVENT_PRINT |
| 1066 | #define DEFINE_EVENT_PRINT(template, call, proto, args, print) \ |
| 1067 | \ |
| 1068 | static const char print_fmt_##call[] = print; \ |
| 1069 | \ |
| 1070 | static struct ftrace_event_call __used \ |
| 1071 | __attribute__((__aligned__(4))) \ |
| 1072 | __attribute__((section("_ftrace_events"))) event_##call = { \ |
| 1073 | .name = #call, \ |
| 1074 | .class = &event_class_##template, \ |
| 1075 | .event.funcs = &ftrace_event_type_funcs_##call, \ |
| 1076 | .print_fmt = print_fmt_##call, \ |
| 1077 | } |
| 1078 | |
| 1079 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
| 1080 | |
| 1081 | /* |
| 1082 | * Define the insertion callback to perf events |
| 1083 | * |
| 1084 | * The job is very similar to ftrace_raw_event_<call> except that we don't |
| 1085 | * insert in the ring buffer but in a perf counter. |
| 1086 | * |
| 1087 | * static void ftrace_perf_<call>(proto) |
| 1088 | * { |
| 1089 | * struct ftrace_data_offsets_<call> __maybe_unused __data_offsets; |
| 1090 | * struct ftrace_event_call *event_call = &event_<call>; |
| 1091 | * extern void perf_tp_event(int, u64, u64, void *, int); |
| 1092 | * struct ftrace_raw_##call *entry; |
| 1093 | * struct perf_trace_buf *trace_buf; |
| 1094 | * u64 __addr = 0, __count = 1; |
| 1095 | * unsigned long irq_flags; |
| 1096 | * struct trace_entry *ent; |
| 1097 | * int __entry_size; |
| 1098 | * int __data_size; |
| 1099 | * int __cpu |
| 1100 | * int pc; |
| 1101 | * |
| 1102 | * pc = preempt_count(); |
| 1103 | * |
| 1104 | * __data_size = ftrace_get_offsets_<call>(&__data_offsets, args); |
| 1105 | * |
| 1106 | * // Below we want to get the aligned size by taking into account |
| 1107 | * // the u32 field that will later store the buffer size |
| 1108 | * __entry_size = ALIGN(__data_size + sizeof(*entry) + sizeof(u32), |
| 1109 | * sizeof(u64)); |
| 1110 | * __entry_size -= sizeof(u32); |
| 1111 | * |
| 1112 | * // Protect the non nmi buffer |
| 1113 | * // This also protects the rcu read side |
| 1114 | * local_irq_save(irq_flags); |
| 1115 | * __cpu = smp_processor_id(); |
| 1116 | * |
| 1117 | * if (in_nmi()) |
| 1118 | * trace_buf = rcu_dereference_sched(perf_trace_buf_nmi); |
| 1119 | * else |
| 1120 | * trace_buf = rcu_dereference_sched(perf_trace_buf); |
| 1121 | * |
| 1122 | * if (!trace_buf) |
| 1123 | * goto end; |
| 1124 | * |
| 1125 | * trace_buf = per_cpu_ptr(trace_buf, __cpu); |
| 1126 | * |
| 1127 | * // Avoid recursion from perf that could mess up the buffer |
| 1128 | * if (trace_buf->recursion++) |
| 1129 | * goto end_recursion; |
| 1130 | * |
| 1131 | * raw_data = trace_buf->buf; |
| 1132 | * |
| 1133 | * // Make recursion update visible before entering perf_tp_event |
| 1134 | * // so that we protect from perf recursions. |
| 1135 | * |
| 1136 | * barrier(); |
| 1137 | * |
| 1138 | * //zero dead bytes from alignment to avoid stack leak to userspace: |
| 1139 | * *(u64 *)(&raw_data[__entry_size - sizeof(u64)]) = 0ULL; |
| 1140 | * entry = (struct ftrace_raw_<call> *)raw_data; |
| 1141 | * ent = &entry->ent; |
| 1142 | * tracing_generic_entry_update(ent, irq_flags, pc); |
| 1143 | * ent->type = event_call->id; |
| 1144 | * |
| 1145 | * <tstruct> <- do some jobs with dynamic arrays |
| 1146 | * |
| 1147 | * <assign> <- affect our values |
| 1148 | * |
| 1149 | * perf_tp_event(event_call->id, __addr, __count, entry, |
| 1150 | * __entry_size); <- submit them to perf counter |
| 1151 | * |
| 1152 | * } |
| 1153 | */ |
| 1154 | |
| 1155 | #ifdef CONFIG_PERF_EVENTS |
| 1156 | |
| 1157 | #undef __entry |
| 1158 | #define __entry entry |
| 1159 | |
| 1160 | #undef __get_dynamic_array |
| 1161 | #define __get_dynamic_array(field) \ |
| 1162 | ((void *)__entry + (__entry->__data_loc_##field & 0xffff)) |
| 1163 | |
| 1164 | #undef __get_str |
| 1165 | #define __get_str(field) (char *)__get_dynamic_array(field) |
| 1166 | |
| 1167 | #undef __perf_addr |
| 1168 | #define __perf_addr(a) __addr = (a) |
| 1169 | |
| 1170 | #undef __perf_count |
| 1171 | #define __perf_count(c) __count = (c) |
| 1172 | |
| 1173 | #undef DECLARE_EVENT_CLASS |
| 1174 | #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \ |
| 1175 | static notrace void \ |
| 1176 | perf_trace_##call(void *__data, proto) \ |
| 1177 | { \ |
| 1178 | struct ftrace_event_call *event_call = __data; \ |
| 1179 | struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\ |
| 1180 | struct ftrace_raw_##call *entry; \ |
| 1181 | struct pt_regs __regs; \ |
| 1182 | u64 __addr = 0, __count = 1; \ |
| 1183 | struct hlist_head *head; \ |
| 1184 | int __entry_size; \ |
| 1185 | int __data_size; \ |
| 1186 | int rctx; \ |
| 1187 | \ |
| 1188 | perf_fetch_caller_regs(&__regs); \ |
| 1189 | \ |
| 1190 | __data_size = ftrace_get_offsets_##call(&__data_offsets, args); \ |
| 1191 | __entry_size = ALIGN(__data_size + sizeof(*entry) + sizeof(u32),\ |
| 1192 | sizeof(u64)); \ |
| 1193 | __entry_size -= sizeof(u32); \ |
| 1194 | \ |
| 1195 | if (WARN_ONCE(__entry_size > PERF_MAX_TRACE_SIZE, \ |
| 1196 | "profile buffer not large enough")) \ |
| 1197 | return; \ |
| 1198 | \ |
| 1199 | entry = (struct ftrace_raw_##call *)perf_trace_buf_prepare( \ |
| 1200 | __entry_size, event_call->event.type, &__regs, &rctx); \ |
| 1201 | if (!entry) \ |
| 1202 | return; \ |
| 1203 | \ |
| 1204 | tstruct \ |
| 1205 | \ |
| 1206 | { assign; } \ |
| 1207 | \ |
| 1208 | head = this_cpu_ptr(event_call->perf_events); \ |
| 1209 | perf_trace_buf_submit(entry, __entry_size, rctx, __addr, \ |
| 1210 | __count, &__regs, head); \ |
| 1211 | } |
| 1212 | |
| 1213 | /* |
| 1214 | * This part is compiled out, it is only here as a build time check |
| 1215 | * to make sure that if the tracepoint handling changes, the |
| 1216 | * perf probe will fail to compile unless it too is updated. |
| 1217 | */ |
| 1218 | #undef DEFINE_EVENT |
| 1219 | #define DEFINE_EVENT(template, call, proto, args) \ |
| 1220 | static inline void perf_test_probe_##call(void) \ |
| 1221 | { \ |
| 1222 | check_trace_callback_type_##call(perf_trace_##template); \ |
| 1223 | } |
| 1224 | |
| 1225 | |
| 1226 | #undef DEFINE_EVENT_PRINT |
| 1227 | #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \ |
| 1228 | DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args)) |
| 1229 | |
| 1230 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
| 1231 | #endif /* CONFIG_PERF_EVENTS */ |
| 1232 | |
| 1233 | #undef _TRACE_PROFILE_INIT |
| 1234 | #endif //0 |