aboutsummaryrefslogtreecommitdiffstats
path: root/include/trace/ftrace.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/trace/ftrace.h')
-rw-r--r--include/trace/ftrace.h149
1 files changed, 107 insertions, 42 deletions
diff --git a/include/trace/ftrace.h b/include/trace/ftrace.h
index c3417c13e3ed..2969f65d8002 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 * TRACE_EVENT_TEMPLATE 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 TRACE_EVENT_TEMPLATE 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 TRACE_EVENT_TEMPLATE(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,13 +56,15 @@
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 TRACE_EVENT_TEMPLATE
40#define TRACE_EVENT(name, proto, args, tstruct, assign, print) \ 60#define TRACE_EVENT_TEMPLATE(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
48#undef __cpparg 70#undef __cpparg
@@ -89,12 +111,15 @@
89#undef __string 111#undef __string
90#define __string(item, src) __dynamic_array(char, item, -1) 112#define __string(item, src) __dynamic_array(char, item, -1)
91 113
92#undef TRACE_EVENT 114#undef TRACE_EVENT_TEMPLATE
93#define TRACE_EVENT(call, proto, args, tstruct, assign, print) \ 115#define TRACE_EVENT_TEMPLATE(call, proto, args, tstruct, assign, print) \
94 struct ftrace_data_offsets_##call { \ 116 struct ftrace_data_offsets_##call { \
95 tstruct; \ 117 tstruct; \
96 }; 118 };
97 119
120#undef DEFINE_EVENT
121#define DEFINE_EVENT(template, name, proto, args)
122
98#include TRACE_INCLUDE(TRACE_INCLUDE_FILE) 123#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
99 124
100/* 125/*
@@ -170,8 +195,8 @@
170#undef TP_perf_assign 195#undef TP_perf_assign
171#define TP_perf_assign(args...) 196#define TP_perf_assign(args...)
172 197
173#undef TRACE_EVENT 198#undef TRACE_EVENT_TEMPLATE
174#define TRACE_EVENT(call, proto, args, tstruct, func, print) \ 199#define TRACE_EVENT_TEMPLATE(call, proto, args, tstruct, func, print) \
175static int \ 200static int \
176ftrace_format_##call(struct ftrace_event_call *unused, \ 201ftrace_format_##call(struct ftrace_event_call *unused, \
177 struct trace_seq *s) \ 202 struct trace_seq *s) \
@@ -186,6 +211,9 @@ ftrace_format_##call(struct ftrace_event_call *unused, \
186 return ret; \ 211 return ret; \
187} 212}
188 213
214#undef DEFINE_EVENT
215#define DEFINE_EVENT(template, name, proto, args)
216
189#include TRACE_INCLUDE(TRACE_INCLUDE_FILE) 217#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
190 218
191/* 219/*
@@ -255,10 +283,11 @@ ftrace_format_##call(struct ftrace_event_call *unused, \
255 ftrace_print_symbols_seq(p, value, symbols); \ 283 ftrace_print_symbols_seq(p, value, symbols); \
256 }) 284 })
257 285
258#undef TRACE_EVENT 286#undef TRACE_EVENT_TEMPLATE
259#define TRACE_EVENT(call, proto, args, tstruct, assign, print) \ 287#define TRACE_EVENT_TEMPLATE(call, proto, args, tstruct, assign, print) \
260static enum print_line_t \ 288static enum print_line_t \
261ftrace_raw_output_##call(struct trace_iterator *iter, int flags) \ 289ftrace_raw_output_id_##call(int event_id, const char *name, \
290 struct trace_iterator *iter, int flags) \
262{ \ 291{ \
263 struct trace_seq *s = &iter->seq; \ 292 struct trace_seq *s = &iter->seq; \
264 struct ftrace_raw_##call *field; \ 293 struct ftrace_raw_##call *field; \
@@ -268,7 +297,7 @@ ftrace_raw_output_##call(struct trace_iterator *iter, int flags) \
268 \ 297 \
269 entry = iter->ent; \ 298 entry = iter->ent; \
270 \ 299 \
271 if (entry->type != event_##call.id) { \ 300 if (entry->type != event_id) { \
272 WARN_ON_ONCE(1); \ 301 WARN_ON_ONCE(1); \
273 return TRACE_TYPE_UNHANDLED; \ 302 return TRACE_TYPE_UNHANDLED; \
274 } \ 303 } \
@@ -277,14 +306,25 @@ ftrace_raw_output_##call(struct trace_iterator *iter, int flags) \
277 \ 306 \
278 p = &get_cpu_var(ftrace_event_seq); \ 307 p = &get_cpu_var(ftrace_event_seq); \
279 trace_seq_init(p); \ 308 trace_seq_init(p); \
280 ret = trace_seq_printf(s, #call ": " print); \ 309 ret = trace_seq_printf(s, "%s: ", name); \
310 if (ret) \
311 ret = trace_seq_printf(s, print); \
281 put_cpu(); \ 312 put_cpu(); \
282 if (!ret) \ 313 if (!ret) \
283 return TRACE_TYPE_PARTIAL_LINE; \ 314 return TRACE_TYPE_PARTIAL_LINE; \
284 \ 315 \
285 return TRACE_TYPE_HANDLED; \ 316 return TRACE_TYPE_HANDLED; \
286} 317}
287 318
319#undef DEFINE_EVENT
320#define DEFINE_EVENT(template, name, proto, args) \
321static enum print_line_t \
322ftrace_raw_output_##name(struct trace_iterator *iter, int flags) \
323{ \
324 return ftrace_raw_output_id_##template(event_##name.id, \
325 #name, iter, flags); \
326}
327
288#include TRACE_INCLUDE(TRACE_INCLUDE_FILE) 328#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
289 329
290#undef __field_ext 330#undef __field_ext
@@ -318,8 +358,8 @@ ftrace_raw_output_##call(struct trace_iterator *iter, int flags) \
318#undef __string 358#undef __string
319#define __string(item, src) __dynamic_array(char, item, -1) 359#define __string(item, src) __dynamic_array(char, item, -1)
320 360
321#undef TRACE_EVENT 361#undef TRACE_EVENT_TEMPLATE
322#define TRACE_EVENT(call, proto, args, tstruct, func, print) \ 362#define TRACE_EVENT_TEMPLATE(call, proto, args, tstruct, func, print) \
323static int \ 363static int \
324ftrace_define_fields_##call(struct ftrace_event_call *event_call) \ 364ftrace_define_fields_##call(struct ftrace_event_call *event_call) \
325{ \ 365{ \
@@ -335,6 +375,9 @@ ftrace_define_fields_##call(struct ftrace_event_call *event_call) \
335 return ret; \ 375 return ret; \
336} 376}
337 377
378#undef DEFINE_EVENT
379#define DEFINE_EVENT(template, name, proto, args)
380
338#include TRACE_INCLUDE(TRACE_INCLUDE_FILE) 381#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
339 382
340/* 383/*
@@ -361,10 +404,10 @@ ftrace_define_fields_##call(struct ftrace_event_call *event_call) \
361 __data_size += (len) * sizeof(type); 404 __data_size += (len) * sizeof(type);
362 405
363#undef __string 406#undef __string
364#define __string(item, src) __dynamic_array(char, item, strlen(src) + 1) \ 407#define __string(item, src) __dynamic_array(char, item, strlen(src) + 1)
365 408
366#undef TRACE_EVENT 409#undef TRACE_EVENT_TEMPLATE
367#define TRACE_EVENT(call, proto, args, tstruct, assign, print) \ 410#define TRACE_EVENT_TEMPLATE(call, proto, args, tstruct, assign, print) \
368static inline int ftrace_get_offsets_##call( \ 411static inline int ftrace_get_offsets_##call( \
369 struct ftrace_data_offsets_##call *__data_offsets, proto) \ 412 struct ftrace_data_offsets_##call *__data_offsets, proto) \
370{ \ 413{ \
@@ -376,6 +419,9 @@ static inline int ftrace_get_offsets_##call( \
376 return __data_size; \ 419 return __data_size; \
377} 420}
378 421
422#undef DEFINE_EVENT
423#define DEFINE_EVENT(template, name, proto, args)
424
379#include TRACE_INCLUDE(TRACE_INCLUDE_FILE) 425#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
380 426
381#ifdef CONFIG_EVENT_PROFILE 427#ifdef CONFIG_EVENT_PROFILE
@@ -397,19 +443,22 @@ static inline int ftrace_get_offsets_##call( \
397 * 443 *
398 */ 444 */
399 445
400#undef TRACE_EVENT 446#undef TRACE_EVENT_TEMPLATE
401#define TRACE_EVENT(call, proto, args, tstruct, assign, print) \ 447#define TRACE_EVENT_TEMPLATE(call, proto, args, tstruct, assign, print)
448
449#undef DEFINE_EVENT
450#define DEFINE_EVENT(template, name, proto, args) \
402 \ 451 \
403static void ftrace_profile_##call(proto); \ 452static void ftrace_profile_##name(proto); \
404 \ 453 \
405static int ftrace_profile_enable_##call(struct ftrace_event_call *unused)\ 454static int ftrace_profile_enable_##name(struct ftrace_event_call *unused)\
406{ \ 455{ \
407 return register_trace_##call(ftrace_profile_##call); \ 456 return register_trace_##name(ftrace_profile_##name); \
408} \ 457} \
409 \ 458 \
410static void ftrace_profile_disable_##call(struct ftrace_event_call *unused)\ 459static void ftrace_profile_disable_##name(struct ftrace_event_call *unused)\
411{ \ 460{ \
412 unregister_trace_##call(ftrace_profile_##call); \ 461 unregister_trace_##name(ftrace_profile_##name); \
413} 462}
414 463
415#include TRACE_INCLUDE(TRACE_INCLUDE_FILE) 464#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
@@ -550,15 +599,13 @@ static void ftrace_profile_disable_##call(struct ftrace_event_call *unused)\
550#define __assign_str(dst, src) \ 599#define __assign_str(dst, src) \
551 strcpy(__get_str(dst), src); 600 strcpy(__get_str(dst), src);
552 601
553#undef TRACE_EVENT 602#undef TRACE_EVENT_TEMPLATE
554#define TRACE_EVENT(call, proto, args, tstruct, assign, print) \ 603#define TRACE_EVENT_TEMPLATE(call, proto, args, tstruct, assign, print) \
555 \
556static struct ftrace_event_call event_##call; \
557 \ 604 \
558static void ftrace_raw_event_##call(proto) \ 605static void ftrace_raw_event_id_##call(struct ftrace_event_call *event_call, \
606 proto) \
559{ \ 607{ \
560 struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\ 608 struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\
561 struct ftrace_event_call *event_call = &event_##call; \
562 struct ring_buffer_event *event; \ 609 struct ring_buffer_event *event; \
563 struct ftrace_raw_##call *entry; \ 610 struct ftrace_raw_##call *entry; \
564 struct ring_buffer *buffer; \ 611 struct ring_buffer *buffer; \
@@ -572,7 +619,7 @@ static void ftrace_raw_event_##call(proto) \
572 __data_size = ftrace_get_offsets_##call(&__data_offsets, args); \ 619 __data_size = ftrace_get_offsets_##call(&__data_offsets, args); \
573 \ 620 \
574 event = trace_current_buffer_lock_reserve(&buffer, \ 621 event = trace_current_buffer_lock_reserve(&buffer, \
575 event_##call.id, \ 622 event_call->id, \
576 sizeof(*entry) + __data_size, \ 623 sizeof(*entry) + __data_size, \
577 irq_flags, pc); \ 624 irq_flags, pc); \
578 if (!event) \ 625 if (!event) \
@@ -587,6 +634,14 @@ static void ftrace_raw_event_##call(proto) \
587 if (!filter_current_check_discard(buffer, event_call, entry, event)) \ 634 if (!filter_current_check_discard(buffer, event_call, entry, event)) \
588 trace_nowake_buffer_unlock_commit(buffer, \ 635 trace_nowake_buffer_unlock_commit(buffer, \
589 event, irq_flags, pc); \ 636 event, irq_flags, pc); \
637}
638
639#undef DEFINE_EVENT
640#define DEFINE_EVENT(template, call, proto, args) \
641 \
642static void ftrace_raw_event_##call(proto) \
643{ \
644 ftrace_raw_event_id_##template(&event_##call, args); \
590} \ 645} \
591 \ 646 \
592static int ftrace_raw_reg_event_##call(struct ftrace_event_call *unused)\ 647static int ftrace_raw_reg_event_##call(struct ftrace_event_call *unused)\
@@ -630,8 +685,8 @@ __attribute__((section("_ftrace_events"))) event_##call = { \
630 .raw_init = ftrace_raw_init_event_##call, \ 685 .raw_init = ftrace_raw_init_event_##call, \
631 .regfunc = ftrace_raw_reg_event_##call, \ 686 .regfunc = ftrace_raw_reg_event_##call, \
632 .unregfunc = ftrace_raw_unreg_event_##call, \ 687 .unregfunc = ftrace_raw_unreg_event_##call, \
633 .show_format = ftrace_format_##call, \ 688 .show_format = ftrace_format_##template, \
634 .define_fields = ftrace_define_fields_##call, \ 689 .define_fields = ftrace_define_fields_##template, \
635 _TRACE_PROFILE_INIT(call) \ 690 _TRACE_PROFILE_INIT(call) \
636} 691}
637 692
@@ -719,14 +774,15 @@ __attribute__((section("_ftrace_events"))) event_##call = { \
719#undef __perf_count 774#undef __perf_count
720#define __perf_count(c) __count = (c) 775#define __perf_count(c) __count = (c)
721 776
722#undef TRACE_EVENT 777#undef TRACE_EVENT_TEMPLATE
723#define TRACE_EVENT(call, proto, args, tstruct, assign, print) \ 778#define TRACE_EVENT_TEMPLATE(call, proto, args, tstruct, assign, print) \
724static void ftrace_profile_##call(proto) \ 779static void \
780ftrace_profile_templ_##call(struct ftrace_event_call *event_call, \
781 proto) \
725{ \ 782{ \
726 struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\ 783 struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\
727 extern int perf_swevent_get_recursion_context(void); \ 784 extern int perf_swevent_get_recursion_context(void); \
728 extern void perf_swevent_put_recursion_context(int rctx); \ 785 extern void perf_swevent_put_recursion_context(int rctx); \
729 struct ftrace_event_call *event_call = &event_##call; \
730 extern void perf_tp_event(int, u64, u64, void *, int); \ 786 extern void perf_tp_event(int, u64, u64, void *, int); \
731 struct ftrace_raw_##call *entry; \ 787 struct ftrace_raw_##call *entry; \
732 u64 __addr = 0, __count = 1; \ 788 u64 __addr = 0, __count = 1; \
@@ -789,6 +845,15 @@ end_recursion: \
789 \ 845 \
790} 846}
791 847
848#undef DEFINE_EVENT
849#define DEFINE_EVENT(template, call, proto, args) \
850static void ftrace_profile_##call(proto) \
851{ \
852 struct ftrace_event_call *event_call = &event_##call; \
853 \
854 ftrace_profile_templ_##template(event_call, args); \
855}
856
792#include TRACE_INCLUDE(TRACE_INCLUDE_FILE) 857#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
793#endif /* CONFIG_EVENT_PROFILE */ 858#endif /* CONFIG_EVENT_PROFILE */
794 859