diff options
Diffstat (limited to 'include/trace/ftrace.h')
| -rw-r--r-- | include/trace/ftrace.h | 340 |
1 files changed, 273 insertions, 67 deletions
diff --git a/include/trace/ftrace.h b/include/trace/ftrace.h index cc0d9667e182..d1b3de9c1a71 100644 --- a/include/trace/ftrace.h +++ b/include/trace/ftrace.h | |||
| @@ -18,6 +18,26 @@ | |||
| 18 | 18 | ||
| 19 | #include <linux/ftrace_event.h> | 19 | #include <linux/ftrace_event.h> |
| 20 | 20 | ||
| 21 | /* | ||
| 22 | * DECLARE_EVENT_CLASS can be used to add a generic function | ||
| 23 | * handlers for events. That is, if all events have the same | ||
| 24 | * parameters and just have distinct trace points. | ||
| 25 | * Each tracepoint can be defined with DEFINE_EVENT and that | ||
| 26 | * will map the DECLARE_EVENT_CLASS to the tracepoint. | ||
| 27 | * | ||
| 28 | * TRACE_EVENT is a one to one mapping between tracepoint and template. | ||
| 29 | */ | ||
| 30 | #undef TRACE_EVENT | ||
| 31 | #define TRACE_EVENT(name, proto, args, tstruct, assign, print) \ | ||
| 32 | DECLARE_EVENT_CLASS(name, \ | ||
| 33 | PARAMS(proto), \ | ||
| 34 | PARAMS(args), \ | ||
| 35 | PARAMS(tstruct), \ | ||
| 36 | PARAMS(assign), \ | ||
| 37 | PARAMS(print)); \ | ||
| 38 | DEFINE_EVENT(name, name, PARAMS(proto), PARAMS(args)); | ||
| 39 | |||
| 40 | |||
| 21 | #undef __field | 41 | #undef __field |
| 22 | #define __field(type, item) type item; | 42 | #define __field(type, item) type item; |
| 23 | 43 | ||
| @@ -36,15 +56,21 @@ | |||
| 36 | #undef TP_STRUCT__entry | 56 | #undef TP_STRUCT__entry |
| 37 | #define TP_STRUCT__entry(args...) args | 57 | #define TP_STRUCT__entry(args...) args |
| 38 | 58 | ||
| 39 | #undef TRACE_EVENT | 59 | #undef DECLARE_EVENT_CLASS |
| 40 | #define TRACE_EVENT(name, proto, args, tstruct, assign, print) \ | 60 | #define DECLARE_EVENT_CLASS(name, proto, args, tstruct, assign, print) \ |
| 41 | struct ftrace_raw_##name { \ | 61 | struct ftrace_raw_##name { \ |
| 42 | struct trace_entry ent; \ | 62 | struct trace_entry ent; \ |
| 43 | tstruct \ | 63 | tstruct \ |
| 44 | char __data[0]; \ | 64 | char __data[0]; \ |
| 45 | }; \ | 65 | }; |
| 66 | #undef DEFINE_EVENT | ||
| 67 | #define DEFINE_EVENT(template, name, proto, args) \ | ||
| 46 | static struct ftrace_event_call event_##name | 68 | static struct ftrace_event_call event_##name |
| 47 | 69 | ||
| 70 | #undef DEFINE_EVENT_PRINT | ||
| 71 | #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \ | ||
| 72 | DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args)) | ||
| 73 | |||
| 48 | #undef __cpparg | 74 | #undef __cpparg |
| 49 | #define __cpparg(arg...) arg | 75 | #define __cpparg(arg...) arg |
| 50 | 76 | ||
| @@ -89,12 +115,19 @@ | |||
| 89 | #undef __string | 115 | #undef __string |
| 90 | #define __string(item, src) __dynamic_array(char, item, -1) | 116 | #define __string(item, src) __dynamic_array(char, item, -1) |
| 91 | 117 | ||
| 92 | #undef TRACE_EVENT | 118 | #undef DECLARE_EVENT_CLASS |
| 93 | #define TRACE_EVENT(call, proto, args, tstruct, assign, print) \ | 119 | #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \ |
| 94 | struct ftrace_data_offsets_##call { \ | 120 | struct ftrace_data_offsets_##call { \ |
| 95 | tstruct; \ | 121 | tstruct; \ |
| 96 | }; | 122 | }; |
| 97 | 123 | ||
| 124 | #undef DEFINE_EVENT | ||
| 125 | #define DEFINE_EVENT(template, name, proto, args) | ||
| 126 | |||
| 127 | #undef DEFINE_EVENT_PRINT | ||
| 128 | #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \ | ||
| 129 | DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args)) | ||
| 130 | |||
| 98 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) | 131 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
| 99 | 132 | ||
| 100 | /* | 133 | /* |
| @@ -120,9 +153,10 @@ | |||
| 120 | #undef __field | 153 | #undef __field |
| 121 | #define __field(type, item) \ | 154 | #define __field(type, item) \ |
| 122 | ret = trace_seq_printf(s, "\tfield:" #type " " #item ";\t" \ | 155 | ret = trace_seq_printf(s, "\tfield:" #type " " #item ";\t" \ |
| 123 | "offset:%u;\tsize:%u;\n", \ | 156 | "offset:%u;\tsize:%u;\tsigned:%u;\n", \ |
| 124 | (unsigned int)offsetof(typeof(field), item), \ | 157 | (unsigned int)offsetof(typeof(field), item), \ |
| 125 | (unsigned int)sizeof(field.item)); \ | 158 | (unsigned int)sizeof(field.item), \ |
| 159 | (unsigned int)is_signed_type(type)); \ | ||
| 126 | if (!ret) \ | 160 | if (!ret) \ |
| 127 | return 0; | 161 | return 0; |
| 128 | 162 | ||
| @@ -132,19 +166,21 @@ | |||
| 132 | #undef __array | 166 | #undef __array |
| 133 | #define __array(type, item, len) \ | 167 | #define __array(type, item, len) \ |
| 134 | ret = trace_seq_printf(s, "\tfield:" #type " " #item "[" #len "];\t" \ | 168 | ret = trace_seq_printf(s, "\tfield:" #type " " #item "[" #len "];\t" \ |
| 135 | "offset:%u;\tsize:%u;\n", \ | 169 | "offset:%u;\tsize:%u;\tsigned:%u;\n", \ |
| 136 | (unsigned int)offsetof(typeof(field), item), \ | 170 | (unsigned int)offsetof(typeof(field), item), \ |
| 137 | (unsigned int)sizeof(field.item)); \ | 171 | (unsigned int)sizeof(field.item), \ |
| 172 | (unsigned int)is_signed_type(type)); \ | ||
| 138 | if (!ret) \ | 173 | if (!ret) \ |
| 139 | return 0; | 174 | return 0; |
| 140 | 175 | ||
| 141 | #undef __dynamic_array | 176 | #undef __dynamic_array |
| 142 | #define __dynamic_array(type, item, len) \ | 177 | #define __dynamic_array(type, item, len) \ |
| 143 | ret = trace_seq_printf(s, "\tfield:__data_loc " #type "[] " #item ";\t"\ | 178 | ret = trace_seq_printf(s, "\tfield:__data_loc " #type "[] " #item ";\t"\ |
| 144 | "offset:%u;\tsize:%u;\n", \ | 179 | "offset:%u;\tsize:%u;\tsigned:%u;\n", \ |
| 145 | (unsigned int)offsetof(typeof(field), \ | 180 | (unsigned int)offsetof(typeof(field), \ |
| 146 | __data_loc_##item), \ | 181 | __data_loc_##item), \ |
| 147 | (unsigned int)sizeof(field.__data_loc_##item)); \ | 182 | (unsigned int)sizeof(field.__data_loc_##item), \ |
| 183 | (unsigned int)is_signed_type(type)); \ | ||
| 148 | if (!ret) \ | 184 | if (!ret) \ |
| 149 | return 0; | 185 | return 0; |
| 150 | 186 | ||
| @@ -159,7 +195,7 @@ | |||
| 159 | #undef __get_str | 195 | #undef __get_str |
| 160 | 196 | ||
| 161 | #undef TP_printk | 197 | #undef TP_printk |
| 162 | #define TP_printk(fmt, args...) "%s, %s\n", #fmt, __stringify(args) | 198 | #define TP_printk(fmt, args...) "\"%s\", %s\n", fmt, __stringify(args) |
| 163 | 199 | ||
| 164 | #undef TP_fast_assign | 200 | #undef TP_fast_assign |
| 165 | #define TP_fast_assign(args...) args | 201 | #define TP_fast_assign(args...) args |
| @@ -167,17 +203,50 @@ | |||
| 167 | #undef TP_perf_assign | 203 | #undef TP_perf_assign |
| 168 | #define TP_perf_assign(args...) | 204 | #define TP_perf_assign(args...) |
| 169 | 205 | ||
| 170 | #undef TRACE_EVENT | 206 | #undef DECLARE_EVENT_CLASS |
| 171 | #define TRACE_EVENT(call, proto, args, tstruct, func, print) \ | 207 | #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, func, print) \ |
| 172 | static int \ | 208 | static int \ |
| 173 | ftrace_format_##call(struct ftrace_event_call *unused, \ | 209 | ftrace_format_setup_##call(struct ftrace_event_call *unused, \ |
| 174 | struct trace_seq *s) \ | 210 | struct trace_seq *s) \ |
| 175 | { \ | 211 | { \ |
| 176 | struct ftrace_raw_##call field __attribute__((unused)); \ | 212 | struct ftrace_raw_##call field __attribute__((unused)); \ |
| 177 | int ret = 0; \ | 213 | int ret = 0; \ |
| 178 | \ | 214 | \ |
| 179 | tstruct; \ | 215 | tstruct; \ |
| 180 | \ | 216 | \ |
| 217 | return ret; \ | ||
| 218 | } \ | ||
| 219 | \ | ||
| 220 | static int \ | ||
| 221 | ftrace_format_##call(struct ftrace_event_call *unused, \ | ||
| 222 | struct trace_seq *s) \ | ||
| 223 | { \ | ||
| 224 | int ret = 0; \ | ||
| 225 | \ | ||
| 226 | ret = ftrace_format_setup_##call(unused, s); \ | ||
| 227 | if (!ret) \ | ||
| 228 | return ret; \ | ||
| 229 | \ | ||
| 230 | ret = trace_seq_printf(s, "\nprint fmt: " print); \ | ||
| 231 | \ | ||
| 232 | return ret; \ | ||
| 233 | } | ||
| 234 | |||
| 235 | #undef DEFINE_EVENT | ||
| 236 | #define DEFINE_EVENT(template, name, proto, args) | ||
| 237 | |||
| 238 | #undef DEFINE_EVENT_PRINT | ||
| 239 | #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \ | ||
| 240 | static int \ | ||
| 241 | ftrace_format_##name(struct ftrace_event_call *unused, \ | ||
| 242 | struct trace_seq *s) \ | ||
| 243 | { \ | ||
| 244 | int ret = 0; \ | ||
| 245 | \ | ||
| 246 | ret = ftrace_format_setup_##template(unused, s); \ | ||
| 247 | if (!ret) \ | ||
| 248 | return ret; \ | ||
| 249 | \ | ||
| 181 | trace_seq_printf(s, "\nprint fmt: " print); \ | 250 | trace_seq_printf(s, "\nprint fmt: " print); \ |
| 182 | \ | 251 | \ |
| 183 | return ret; \ | 252 | return ret; \ |
| @@ -252,10 +321,11 @@ ftrace_format_##call(struct ftrace_event_call *unused, \ | |||
| 252 | ftrace_print_symbols_seq(p, value, symbols); \ | 321 | ftrace_print_symbols_seq(p, value, symbols); \ |
| 253 | }) | 322 | }) |
| 254 | 323 | ||
| 255 | #undef TRACE_EVENT | 324 | #undef DECLARE_EVENT_CLASS |
| 256 | #define TRACE_EVENT(call, proto, args, tstruct, assign, print) \ | 325 | #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \ |
| 257 | static enum print_line_t \ | 326 | static enum print_line_t \ |
| 258 | ftrace_raw_output_##call(struct trace_iterator *iter, int flags) \ | 327 | ftrace_raw_output_id_##call(int event_id, const char *name, \ |
| 328 | struct trace_iterator *iter, int flags) \ | ||
| 259 | { \ | 329 | { \ |
| 260 | struct trace_seq *s = &iter->seq; \ | 330 | struct trace_seq *s = &iter->seq; \ |
| 261 | struct ftrace_raw_##call *field; \ | 331 | struct ftrace_raw_##call *field; \ |
| @@ -265,6 +335,47 @@ ftrace_raw_output_##call(struct trace_iterator *iter, int flags) \ | |||
| 265 | \ | 335 | \ |
| 266 | entry = iter->ent; \ | 336 | entry = iter->ent; \ |
| 267 | \ | 337 | \ |
| 338 | if (entry->type != event_id) { \ | ||
| 339 | WARN_ON_ONCE(1); \ | ||
| 340 | return TRACE_TYPE_UNHANDLED; \ | ||
| 341 | } \ | ||
| 342 | \ | ||
| 343 | field = (typeof(field))entry; \ | ||
| 344 | \ | ||
| 345 | p = &get_cpu_var(ftrace_event_seq); \ | ||
| 346 | trace_seq_init(p); \ | ||
| 347 | ret = trace_seq_printf(s, "%s: ", name); \ | ||
| 348 | if (ret) \ | ||
| 349 | ret = trace_seq_printf(s, print); \ | ||
| 350 | put_cpu(); \ | ||
| 351 | if (!ret) \ | ||
| 352 | return TRACE_TYPE_PARTIAL_LINE; \ | ||
| 353 | \ | ||
| 354 | return TRACE_TYPE_HANDLED; \ | ||
| 355 | } | ||
| 356 | |||
| 357 | #undef DEFINE_EVENT | ||
| 358 | #define DEFINE_EVENT(template, name, proto, args) \ | ||
| 359 | static enum print_line_t \ | ||
| 360 | ftrace_raw_output_##name(struct trace_iterator *iter, int flags) \ | ||
| 361 | { \ | ||
| 362 | return ftrace_raw_output_id_##template(event_##name.id, \ | ||
| 363 | #name, iter, flags); \ | ||
| 364 | } | ||
| 365 | |||
| 366 | #undef DEFINE_EVENT_PRINT | ||
| 367 | #define DEFINE_EVENT_PRINT(template, call, proto, args, print) \ | ||
| 368 | static enum print_line_t \ | ||
| 369 | ftrace_raw_output_##call(struct trace_iterator *iter, int flags) \ | ||
| 370 | { \ | ||
| 371 | struct trace_seq *s = &iter->seq; \ | ||
| 372 | struct ftrace_raw_##template *field; \ | ||
| 373 | struct trace_entry *entry; \ | ||
| 374 | struct trace_seq *p; \ | ||
| 375 | int ret; \ | ||
| 376 | \ | ||
| 377 | entry = iter->ent; \ | ||
| 378 | \ | ||
| 268 | if (entry->type != event_##call.id) { \ | 379 | if (entry->type != event_##call.id) { \ |
| 269 | WARN_ON_ONCE(1); \ | 380 | WARN_ON_ONCE(1); \ |
| 270 | return TRACE_TYPE_UNHANDLED; \ | 381 | return TRACE_TYPE_UNHANDLED; \ |
| @@ -274,14 +385,16 @@ ftrace_raw_output_##call(struct trace_iterator *iter, int flags) \ | |||
| 274 | \ | 385 | \ |
| 275 | p = &get_cpu_var(ftrace_event_seq); \ | 386 | p = &get_cpu_var(ftrace_event_seq); \ |
| 276 | trace_seq_init(p); \ | 387 | trace_seq_init(p); \ |
| 277 | ret = trace_seq_printf(s, #call ": " print); \ | 388 | ret = trace_seq_printf(s, "%s: ", #call); \ |
| 389 | if (ret) \ | ||
| 390 | ret = trace_seq_printf(s, print); \ | ||
| 278 | put_cpu(); \ | 391 | put_cpu(); \ |
| 279 | if (!ret) \ | 392 | if (!ret) \ |
| 280 | return TRACE_TYPE_PARTIAL_LINE; \ | 393 | return TRACE_TYPE_PARTIAL_LINE; \ |
| 281 | \ | 394 | \ |
| 282 | return TRACE_TYPE_HANDLED; \ | 395 | return TRACE_TYPE_HANDLED; \ |
| 283 | } | 396 | } |
| 284 | 397 | ||
| 285 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) | 398 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
| 286 | 399 | ||
| 287 | #undef __field_ext | 400 | #undef __field_ext |
| @@ -315,8 +428,8 @@ ftrace_raw_output_##call(struct trace_iterator *iter, int flags) \ | |||
| 315 | #undef __string | 428 | #undef __string |
| 316 | #define __string(item, src) __dynamic_array(char, item, -1) | 429 | #define __string(item, src) __dynamic_array(char, item, -1) |
| 317 | 430 | ||
| 318 | #undef TRACE_EVENT | 431 | #undef DECLARE_EVENT_CLASS |
| 319 | #define TRACE_EVENT(call, proto, args, tstruct, func, print) \ | 432 | #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, func, print) \ |
| 320 | static int \ | 433 | static int \ |
| 321 | ftrace_define_fields_##call(struct ftrace_event_call *event_call) \ | 434 | ftrace_define_fields_##call(struct ftrace_event_call *event_call) \ |
| 322 | { \ | 435 | { \ |
| @@ -332,6 +445,13 @@ ftrace_define_fields_##call(struct ftrace_event_call *event_call) \ | |||
| 332 | return ret; \ | 445 | return ret; \ |
| 333 | } | 446 | } |
| 334 | 447 | ||
| 448 | #undef DEFINE_EVENT | ||
| 449 | #define DEFINE_EVENT(template, name, proto, args) | ||
| 450 | |||
| 451 | #undef DEFINE_EVENT_PRINT | ||
| 452 | #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \ | ||
| 453 | DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args)) | ||
| 454 | |||
| 335 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) | 455 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
| 336 | 456 | ||
| 337 | /* | 457 | /* |
| @@ -358,10 +478,10 @@ ftrace_define_fields_##call(struct ftrace_event_call *event_call) \ | |||
| 358 | __data_size += (len) * sizeof(type); | 478 | __data_size += (len) * sizeof(type); |
| 359 | 479 | ||
| 360 | #undef __string | 480 | #undef __string |
| 361 | #define __string(item, src) __dynamic_array(char, item, strlen(src) + 1) \ | 481 | #define __string(item, src) __dynamic_array(char, item, strlen(src) + 1) |
| 362 | 482 | ||
| 363 | #undef TRACE_EVENT | 483 | #undef DECLARE_EVENT_CLASS |
| 364 | #define TRACE_EVENT(call, proto, args, tstruct, assign, print) \ | 484 | #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \ |
| 365 | static inline int ftrace_get_offsets_##call( \ | 485 | static inline int ftrace_get_offsets_##call( \ |
| 366 | struct ftrace_data_offsets_##call *__data_offsets, proto) \ | 486 | struct ftrace_data_offsets_##call *__data_offsets, proto) \ |
| 367 | { \ | 487 | { \ |
| @@ -373,6 +493,13 @@ static inline int ftrace_get_offsets_##call( \ | |||
| 373 | return __data_size; \ | 493 | return __data_size; \ |
| 374 | } | 494 | } |
| 375 | 495 | ||
| 496 | #undef DEFINE_EVENT | ||
| 497 | #define DEFINE_EVENT(template, name, proto, args) | ||
| 498 | |||
| 499 | #undef DEFINE_EVENT_PRINT | ||
| 500 | #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \ | ||
| 501 | DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args)) | ||
| 502 | |||
| 376 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) | 503 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
| 377 | 504 | ||
| 378 | #ifdef CONFIG_EVENT_PROFILE | 505 | #ifdef CONFIG_EVENT_PROFILE |
| @@ -394,21 +521,28 @@ static inline int ftrace_get_offsets_##call( \ | |||
| 394 | * | 521 | * |
| 395 | */ | 522 | */ |
| 396 | 523 | ||
| 397 | #undef TRACE_EVENT | 524 | #undef DECLARE_EVENT_CLASS |
| 398 | #define TRACE_EVENT(call, proto, args, tstruct, assign, print) \ | 525 | #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) |
| 526 | |||
| 527 | #undef DEFINE_EVENT | ||
| 528 | #define DEFINE_EVENT(template, name, proto, args) \ | ||
| 399 | \ | 529 | \ |
| 400 | static void ftrace_profile_##call(proto); \ | 530 | static void ftrace_profile_##name(proto); \ |
| 401 | \ | 531 | \ |
| 402 | static int ftrace_profile_enable_##call(void) \ | 532 | static int ftrace_profile_enable_##name(struct ftrace_event_call *unused)\ |
| 403 | { \ | 533 | { \ |
| 404 | return register_trace_##call(ftrace_profile_##call); \ | 534 | return register_trace_##name(ftrace_profile_##name); \ |
| 405 | } \ | 535 | } \ |
| 406 | \ | 536 | \ |
| 407 | static void ftrace_profile_disable_##call(void) \ | 537 | static void ftrace_profile_disable_##name(struct ftrace_event_call *unused)\ |
| 408 | { \ | 538 | { \ |
| 409 | unregister_trace_##call(ftrace_profile_##call); \ | 539 | unregister_trace_##name(ftrace_profile_##name); \ |
| 410 | } | 540 | } |
| 411 | 541 | ||
| 542 | #undef DEFINE_EVENT_PRINT | ||
| 543 | #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \ | ||
| 544 | DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args)) | ||
| 545 | |||
| 412 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) | 546 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
| 413 | 547 | ||
| 414 | #endif | 548 | #endif |
| @@ -423,7 +557,7 @@ static void ftrace_profile_disable_##call(void) \ | |||
| 423 | * event_trace_printk(_RET_IP_, "<call>: " <fmt>); | 557 | * event_trace_printk(_RET_IP_, "<call>: " <fmt>); |
| 424 | * } | 558 | * } |
| 425 | * | 559 | * |
| 426 | * static int ftrace_reg_event_<call>(void) | 560 | * static int ftrace_reg_event_<call>(struct ftrace_event_call *unused) |
| 427 | * { | 561 | * { |
| 428 | * int ret; | 562 | * int ret; |
| 429 | * | 563 | * |
| @@ -434,7 +568,7 @@ static void ftrace_profile_disable_##call(void) \ | |||
| 434 | * return ret; | 568 | * return ret; |
| 435 | * } | 569 | * } |
| 436 | * | 570 | * |
| 437 | * static void ftrace_unreg_event_<call>(void) | 571 | * static void ftrace_unreg_event_<call>(struct ftrace_event_call *unused) |
| 438 | * { | 572 | * { |
| 439 | * unregister_trace_<call>(ftrace_event_<call>); | 573 | * unregister_trace_<call>(ftrace_event_<call>); |
| 440 | * } | 574 | * } |
| @@ -469,7 +603,7 @@ static void ftrace_profile_disable_##call(void) \ | |||
| 469 | * trace_current_buffer_unlock_commit(buffer, event, irq_flags, pc); | 603 | * trace_current_buffer_unlock_commit(buffer, event, irq_flags, pc); |
| 470 | * } | 604 | * } |
| 471 | * | 605 | * |
| 472 | * static int ftrace_raw_reg_event_<call>(void) | 606 | * static int ftrace_raw_reg_event_<call>(struct ftrace_event_call *unused) |
| 473 | * { | 607 | * { |
| 474 | * int ret; | 608 | * int ret; |
| 475 | * | 609 | * |
| @@ -480,7 +614,7 @@ static void ftrace_profile_disable_##call(void) \ | |||
| 480 | * return ret; | 614 | * return ret; |
| 481 | * } | 615 | * } |
| 482 | * | 616 | * |
| 483 | * static void ftrace_unreg_event_<call>(void) | 617 | * static void ftrace_unreg_event_<call>(struct ftrace_event_call *unused) |
| 484 | * { | 618 | * { |
| 485 | * unregister_trace_<call>(ftrace_raw_event_<call>); | 619 | * unregister_trace_<call>(ftrace_raw_event_<call>); |
| 486 | * } | 620 | * } |
| @@ -489,7 +623,7 @@ static void ftrace_profile_disable_##call(void) \ | |||
| 489 | * .trace = ftrace_raw_output_<call>, <-- stage 2 | 623 | * .trace = ftrace_raw_output_<call>, <-- stage 2 |
| 490 | * }; | 624 | * }; |
| 491 | * | 625 | * |
| 492 | * static int ftrace_raw_init_event_<call>(void) | 626 | * static int ftrace_raw_init_event_<call>(struct ftrace_event_call *unused) |
| 493 | * { | 627 | * { |
| 494 | * int id; | 628 | * int id; |
| 495 | * | 629 | * |
| @@ -547,15 +681,13 @@ static void ftrace_profile_disable_##call(void) \ | |||
| 547 | #define __assign_str(dst, src) \ | 681 | #define __assign_str(dst, src) \ |
| 548 | strcpy(__get_str(dst), src); | 682 | strcpy(__get_str(dst), src); |
| 549 | 683 | ||
| 550 | #undef TRACE_EVENT | 684 | #undef DECLARE_EVENT_CLASS |
| 551 | #define TRACE_EVENT(call, proto, args, tstruct, assign, print) \ | 685 | #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \ |
| 552 | \ | 686 | \ |
| 553 | static struct ftrace_event_call event_##call; \ | 687 | static void ftrace_raw_event_id_##call(struct ftrace_event_call *event_call, \ |
| 554 | \ | 688 | proto) \ |
| 555 | static void ftrace_raw_event_##call(proto) \ | ||
| 556 | { \ | 689 | { \ |
| 557 | struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\ | 690 | struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\ |
| 558 | struct ftrace_event_call *event_call = &event_##call; \ | ||
| 559 | struct ring_buffer_event *event; \ | 691 | struct ring_buffer_event *event; \ |
| 560 | struct ftrace_raw_##call *entry; \ | 692 | struct ftrace_raw_##call *entry; \ |
| 561 | struct ring_buffer *buffer; \ | 693 | struct ring_buffer *buffer; \ |
| @@ -569,7 +701,7 @@ static void ftrace_raw_event_##call(proto) \ | |||
| 569 | __data_size = ftrace_get_offsets_##call(&__data_offsets, args); \ | 701 | __data_size = ftrace_get_offsets_##call(&__data_offsets, args); \ |
| 570 | \ | 702 | \ |
| 571 | event = trace_current_buffer_lock_reserve(&buffer, \ | 703 | event = trace_current_buffer_lock_reserve(&buffer, \ |
| 572 | event_##call.id, \ | 704 | event_call->id, \ |
| 573 | sizeof(*entry) + __data_size, \ | 705 | sizeof(*entry) + __data_size, \ |
| 574 | irq_flags, pc); \ | 706 | irq_flags, pc); \ |
| 575 | if (!event) \ | 707 | if (!event) \ |
| @@ -584,9 +716,17 @@ static void ftrace_raw_event_##call(proto) \ | |||
| 584 | if (!filter_current_check_discard(buffer, event_call, entry, event)) \ | 716 | if (!filter_current_check_discard(buffer, event_call, entry, event)) \ |
| 585 | trace_nowake_buffer_unlock_commit(buffer, \ | 717 | trace_nowake_buffer_unlock_commit(buffer, \ |
| 586 | event, irq_flags, pc); \ | 718 | event, irq_flags, pc); \ |
| 719 | } | ||
| 720 | |||
| 721 | #undef DEFINE_EVENT | ||
| 722 | #define DEFINE_EVENT(template, call, proto, args) \ | ||
| 723 | \ | ||
| 724 | static void ftrace_raw_event_##call(proto) \ | ||
| 725 | { \ | ||
| 726 | ftrace_raw_event_id_##template(&event_##call, args); \ | ||
| 587 | } \ | 727 | } \ |
| 588 | \ | 728 | \ |
| 589 | static int ftrace_raw_reg_event_##call(void *ptr) \ | 729 | static int ftrace_raw_reg_event_##call(struct ftrace_event_call *unused)\ |
| 590 | { \ | 730 | { \ |
| 591 | int ret; \ | 731 | int ret; \ |
| 592 | \ | 732 | \ |
| @@ -597,7 +737,7 @@ static int ftrace_raw_reg_event_##call(void *ptr) \ | |||
| 597 | return ret; \ | 737 | return ret; \ |
| 598 | } \ | 738 | } \ |
| 599 | \ | 739 | \ |
| 600 | static void ftrace_raw_unreg_event_##call(void *ptr) \ | 740 | static void ftrace_raw_unreg_event_##call(struct ftrace_event_call *unused)\ |
| 601 | { \ | 741 | { \ |
| 602 | unregister_trace_##call(ftrace_raw_event_##call); \ | 742 | unregister_trace_##call(ftrace_raw_event_##call); \ |
| 603 | } \ | 743 | } \ |
| @@ -606,7 +746,7 @@ static struct trace_event ftrace_event_type_##call = { \ | |||
| 606 | .trace = ftrace_raw_output_##call, \ | 746 | .trace = ftrace_raw_output_##call, \ |
| 607 | }; \ | 747 | }; \ |
| 608 | \ | 748 | \ |
| 609 | static int ftrace_raw_init_event_##call(void) \ | 749 | static int ftrace_raw_init_event_##call(struct ftrace_event_call *unused)\ |
| 610 | { \ | 750 | { \ |
| 611 | int id; \ | 751 | int id; \ |
| 612 | \ | 752 | \ |
| @@ -616,7 +756,36 @@ static int ftrace_raw_init_event_##call(void) \ | |||
| 616 | event_##call.id = id; \ | 756 | event_##call.id = id; \ |
| 617 | INIT_LIST_HEAD(&event_##call.fields); \ | 757 | INIT_LIST_HEAD(&event_##call.fields); \ |
| 618 | return 0; \ | 758 | return 0; \ |
| 619 | } \ | 759 | } |
| 760 | |||
| 761 | #undef DEFINE_EVENT_PRINT | ||
| 762 | #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \ | ||
| 763 | DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args)) | ||
| 764 | |||
| 765 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) | ||
| 766 | |||
| 767 | #undef DECLARE_EVENT_CLASS | ||
| 768 | #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) | ||
| 769 | |||
| 770 | #undef DEFINE_EVENT | ||
| 771 | #define DEFINE_EVENT(template, call, proto, args) \ | ||
| 772 | \ | ||
| 773 | static struct ftrace_event_call __used \ | ||
| 774 | __attribute__((__aligned__(4))) \ | ||
| 775 | __attribute__((section("_ftrace_events"))) event_##call = { \ | ||
| 776 | .name = #call, \ | ||
| 777 | .system = __stringify(TRACE_SYSTEM), \ | ||
| 778 | .event = &ftrace_event_type_##call, \ | ||
| 779 | .raw_init = ftrace_raw_init_event_##call, \ | ||
| 780 | .regfunc = ftrace_raw_reg_event_##call, \ | ||
| 781 | .unregfunc = ftrace_raw_unreg_event_##call, \ | ||
| 782 | .show_format = ftrace_format_##template, \ | ||
| 783 | .define_fields = ftrace_define_fields_##template, \ | ||
| 784 | _TRACE_PROFILE_INIT(call) \ | ||
| 785 | } | ||
| 786 | |||
| 787 | #undef DEFINE_EVENT_PRINT | ||
| 788 | #define DEFINE_EVENT_PRINT(template, call, proto, args, print) \ | ||
| 620 | \ | 789 | \ |
| 621 | static struct ftrace_event_call __used \ | 790 | static struct ftrace_event_call __used \ |
| 622 | __attribute__((__aligned__(4))) \ | 791 | __attribute__((__aligned__(4))) \ |
| @@ -628,7 +797,7 @@ __attribute__((section("_ftrace_events"))) event_##call = { \ | |||
| 628 | .regfunc = ftrace_raw_reg_event_##call, \ | 797 | .regfunc = ftrace_raw_reg_event_##call, \ |
| 629 | .unregfunc = ftrace_raw_unreg_event_##call, \ | 798 | .unregfunc = ftrace_raw_unreg_event_##call, \ |
| 630 | .show_format = ftrace_format_##call, \ | 799 | .show_format = ftrace_format_##call, \ |
| 631 | .define_fields = ftrace_define_fields_##call, \ | 800 | .define_fields = ftrace_define_fields_##template, \ |
| 632 | _TRACE_PROFILE_INIT(call) \ | 801 | _TRACE_PROFILE_INIT(call) \ |
| 633 | } | 802 | } |
| 634 | 803 | ||
| @@ -646,6 +815,7 @@ __attribute__((section("_ftrace_events"))) event_##call = { \ | |||
| 646 | * struct ftrace_event_call *event_call = &event_<call>; | 815 | * struct ftrace_event_call *event_call = &event_<call>; |
| 647 | * extern void perf_tp_event(int, u64, u64, void *, int); | 816 | * extern void perf_tp_event(int, u64, u64, void *, int); |
| 648 | * struct ftrace_raw_##call *entry; | 817 | * struct ftrace_raw_##call *entry; |
| 818 | * struct perf_trace_buf *trace_buf; | ||
| 649 | * u64 __addr = 0, __count = 1; | 819 | * u64 __addr = 0, __count = 1; |
| 650 | * unsigned long irq_flags; | 820 | * unsigned long irq_flags; |
| 651 | * struct trace_entry *ent; | 821 | * struct trace_entry *ent; |
| @@ -670,14 +840,25 @@ __attribute__((section("_ftrace_events"))) event_##call = { \ | |||
| 670 | * __cpu = smp_processor_id(); | 840 | * __cpu = smp_processor_id(); |
| 671 | * | 841 | * |
| 672 | * if (in_nmi()) | 842 | * if (in_nmi()) |
| 673 | * raw_data = rcu_dereference(trace_profile_buf_nmi); | 843 | * trace_buf = rcu_dereference(perf_trace_buf_nmi); |
| 674 | * else | 844 | * else |
| 675 | * raw_data = rcu_dereference(trace_profile_buf); | 845 | * trace_buf = rcu_dereference(perf_trace_buf); |
| 676 | * | 846 | * |
| 677 | * if (!raw_data) | 847 | * if (!trace_buf) |
| 678 | * goto end; | 848 | * goto end; |
| 679 | * | 849 | * |
| 680 | * raw_data = per_cpu_ptr(raw_data, __cpu); | 850 | * trace_buf = per_cpu_ptr(trace_buf, __cpu); |
| 851 | * | ||
| 852 | * // Avoid recursion from perf that could mess up the buffer | ||
| 853 | * if (trace_buf->recursion++) | ||
| 854 | * goto end_recursion; | ||
| 855 | * | ||
| 856 | * raw_data = trace_buf->buf; | ||
| 857 | * | ||
| 858 | * // Make recursion update visible before entering perf_tp_event | ||
| 859 | * // so that we protect from perf recursions. | ||
| 860 | * | ||
| 861 | * barrier(); | ||
| 681 | * | 862 | * |
| 682 | * //zero dead bytes from alignment to avoid stack leak to userspace: | 863 | * //zero dead bytes from alignment to avoid stack leak to userspace: |
| 683 | * *(u64 *)(&raw_data[__entry_size - sizeof(u64)]) = 0ULL; | 864 | * *(u64 *)(&raw_data[__entry_size - sizeof(u64)]) = 0ULL; |
| @@ -704,21 +885,26 @@ __attribute__((section("_ftrace_events"))) event_##call = { \ | |||
| 704 | #undef __perf_count | 885 | #undef __perf_count |
| 705 | #define __perf_count(c) __count = (c) | 886 | #define __perf_count(c) __count = (c) |
| 706 | 887 | ||
| 707 | #undef TRACE_EVENT | 888 | #undef DECLARE_EVENT_CLASS |
| 708 | #define TRACE_EVENT(call, proto, args, tstruct, assign, print) \ | 889 | #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \ |
| 709 | static void ftrace_profile_##call(proto) \ | 890 | static void \ |
| 891 | ftrace_profile_templ_##call(struct ftrace_event_call *event_call, \ | ||
| 892 | proto) \ | ||
| 710 | { \ | 893 | { \ |
| 711 | struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\ | 894 | struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\ |
| 712 | struct ftrace_event_call *event_call = &event_##call; \ | 895 | extern int perf_swevent_get_recursion_context(void); \ |
| 713 | extern void perf_tp_event(int, u64, u64, void *, int); \ | 896 | extern void perf_swevent_put_recursion_context(int rctx); \ |
| 897 | extern void perf_tp_event(int, u64, u64, void *, int); \ | ||
| 714 | struct ftrace_raw_##call *entry; \ | 898 | struct ftrace_raw_##call *entry; \ |
| 715 | u64 __addr = 0, __count = 1; \ | 899 | u64 __addr = 0, __count = 1; \ |
| 716 | unsigned long irq_flags; \ | 900 | unsigned long irq_flags; \ |
| 717 | struct trace_entry *ent; \ | 901 | struct trace_entry *ent; \ |
| 718 | int __entry_size; \ | 902 | int __entry_size; \ |
| 719 | int __data_size; \ | 903 | int __data_size; \ |
| 904 | char *trace_buf; \ | ||
| 720 | char *raw_data; \ | 905 | char *raw_data; \ |
| 721 | int __cpu; \ | 906 | int __cpu; \ |
| 907 | int rctx; \ | ||
| 722 | int pc; \ | 908 | int pc; \ |
| 723 | \ | 909 | \ |
| 724 | pc = preempt_count(); \ | 910 | pc = preempt_count(); \ |
| @@ -733,17 +919,22 @@ static void ftrace_profile_##call(proto) \ | |||
| 733 | return; \ | 919 | return; \ |
| 734 | \ | 920 | \ |
| 735 | local_irq_save(irq_flags); \ | 921 | local_irq_save(irq_flags); \ |
| 922 | \ | ||
| 923 | rctx = perf_swevent_get_recursion_context(); \ | ||
| 924 | if (rctx < 0) \ | ||
| 925 | goto end_recursion; \ | ||
| 926 | \ | ||
| 736 | __cpu = smp_processor_id(); \ | 927 | __cpu = smp_processor_id(); \ |
| 737 | \ | 928 | \ |
| 738 | if (in_nmi()) \ | 929 | if (in_nmi()) \ |
| 739 | raw_data = rcu_dereference(trace_profile_buf_nmi); \ | 930 | trace_buf = rcu_dereference(perf_trace_buf_nmi); \ |
| 740 | else \ | 931 | else \ |
| 741 | raw_data = rcu_dereference(trace_profile_buf); \ | 932 | trace_buf = rcu_dereference(perf_trace_buf); \ |
| 742 | \ | 933 | \ |
| 743 | if (!raw_data) \ | 934 | if (!trace_buf) \ |
| 744 | goto end; \ | 935 | goto end; \ |
| 745 | \ | 936 | \ |
| 746 | raw_data = per_cpu_ptr(raw_data, __cpu); \ | 937 | raw_data = per_cpu_ptr(trace_buf, __cpu); \ |
| 747 | \ | 938 | \ |
| 748 | *(u64 *)(&raw_data[__entry_size - sizeof(u64)]) = 0ULL; \ | 939 | *(u64 *)(&raw_data[__entry_size - sizeof(u64)]) = 0ULL; \ |
| 749 | entry = (struct ftrace_raw_##call *)raw_data; \ | 940 | entry = (struct ftrace_raw_##call *)raw_data; \ |
| @@ -759,10 +950,25 @@ static void ftrace_profile_##call(proto) \ | |||
| 759 | __entry_size); \ | 950 | __entry_size); \ |
| 760 | \ | 951 | \ |
| 761 | end: \ | 952 | end: \ |
| 953 | perf_swevent_put_recursion_context(rctx); \ | ||
| 954 | end_recursion: \ | ||
| 762 | local_irq_restore(irq_flags); \ | 955 | local_irq_restore(irq_flags); \ |
| 763 | \ | 956 | \ |
| 764 | } | 957 | } |
| 765 | 958 | ||
| 959 | #undef DEFINE_EVENT | ||
| 960 | #define DEFINE_EVENT(template, call, proto, args) \ | ||
| 961 | static void ftrace_profile_##call(proto) \ | ||
| 962 | { \ | ||
| 963 | struct ftrace_event_call *event_call = &event_##call; \ | ||
| 964 | \ | ||
| 965 | ftrace_profile_templ_##template(event_call, args); \ | ||
| 966 | } | ||
| 967 | |||
| 968 | #undef DEFINE_EVENT_PRINT | ||
| 969 | #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \ | ||
| 970 | DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args)) | ||
| 971 | |||
| 766 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) | 972 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
| 767 | #endif /* CONFIG_EVENT_PROFILE */ | 973 | #endif /* CONFIG_EVENT_PROFILE */ |
| 768 | 974 | ||
