From 755a27e7e4c817dd51ade41668b380f26026899c Mon Sep 17 00:00:00 2001 From: Nicolas Iooss Date: Sun, 3 May 2015 18:18:02 +0800 Subject: [PATCH 01/33] tracing: remove unused ftrace_output_event() prototype The prototype of ftrace_output_event was added by commit 1d6bae966e90 ("tracing: Move raw output code from macro to standalone function") but this function was not defined anywhere, and is still nowhere to be found. Link: http://lkml.kernel.org/r/1430648282-25792-1-git-send-email-nicolas.iooss_linux@m4x.org Signed-off-by: Nicolas Iooss Signed-off-by: Steven Rostedt --- include/linux/ftrace_event.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h index f9ecf63d47f1..65ce6de91307 100644 --- a/include/linux/ftrace_event.h +++ b/include/linux/ftrace_event.h @@ -219,9 +219,6 @@ struct ftrace_event_class { extern int ftrace_event_reg(struct ftrace_event_call *event, enum trace_reg type, void *data); -int ftrace_output_event(struct trace_iterator *iter, struct ftrace_event_call *event, - char *fmt, ...); - int ftrace_event_define_field(struct ftrace_event_call *call, char *type, int len, char *item, int offset, int field_size, int sign, int filter); From 7e255d346c12888f7cce4b89a03a5fe5e9196ab1 Mon Sep 17 00:00:00 2001 From: Jerry Snitselaar Date: Thu, 30 Apr 2015 08:10:24 -0700 Subject: [PATCH 02/33] tracing: Export tracing clock functions Critical tracepoint hooks should never call anything that takes a lock, so they are unable to call getrawmonotonic() or ktime_get(). Export the rest of the tracing clock functions so can be used in tracepoint hooks. Background: We have a customer that adds their own module and registers a tracepoint hook to sched_wakeup. They were using ktime_get() for a time source, but it grabs a seq lock and caused a deadlock to occur. Link: http://lkml.kernel.org/r/1430406624-22609-1-git-send-email-jsnitsel@redhat.com Signed-off-by: Jerry Snitselaar Signed-off-by: Steven Rostedt --- kernel/trace/trace_clock.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/kernel/trace/trace_clock.c b/kernel/trace/trace_clock.c index 57b67b1f24d1..0f06532a755b 100644 --- a/kernel/trace/trace_clock.c +++ b/kernel/trace/trace_clock.c @@ -56,6 +56,7 @@ u64 notrace trace_clock(void) { return local_clock(); } +EXPORT_SYMBOL_GPL(trace_clock); /* * trace_jiffy_clock(): Simply use jiffies as a clock counter. @@ -68,6 +69,7 @@ u64 notrace trace_clock_jiffies(void) { return jiffies_64_to_clock_t(jiffies_64 - INITIAL_JIFFIES); } +EXPORT_SYMBOL_GPL(trace_clock_jiffies); /* * trace_clock_global(): special globally coherent trace clock @@ -123,6 +125,7 @@ u64 notrace trace_clock_global(void) return now; } +EXPORT_SYMBOL_GPL(trace_clock_global); static atomic64_t trace_counter; From aabfa5f28f717d3e53102ab088e9cc903741221a Mon Sep 17 00:00:00 2001 From: Drew Richardson Date: Fri, 8 May 2015 07:30:39 -0700 Subject: [PATCH 03/33] ftrace: Provide trace clock monotonic raw Expose the NMI safe accessor to the monotonic raw clock to the tracer. The mono clock was added with commit 1b3e5c0936046e7e023149ddc8946d21c2ea20eb. The advantage of the monotonic raw clock is that it will advance more constantly than the monotonic clock. Imagine someone is trying to optimize a particular program to reduce instructions executed for a given workload while minimizing the effect on runtime. Also suppose that NTP is running and potentially making larger adjustments to the monotonic clock. If NTP is adjusting the monotonic clock to advance more rapidly, the program will appear to use fewer instructions per second but run longer than if the monotonic raw clock had been used. The total number of instructions observed would be the same regardless of the clock source used, but how it's attributed to time would be affected. Conversely if NTP is adjusting the monotonic clock to advance more slowly, the program will appear to use more instructions per second but run more quickly. Of course there are many sources that can cause jitter in performance measurements on modern processors, but let's remove NTP from the list. The monotonic raw clock can also be useful for tracing early boot, e.g. when debugging issues with NTP. Link: http://lkml.kernel.org/r/20150508143037.GB1276@dreric01-Precision-T1650 Acked-by: Thomas Gleixner Acked-by: Peter Zijlstra Acked-by: John Stultz Acked-by: Mathieu Desnoyers Signed-off-by: Drew Richardson Signed-off-by: Steven Rostedt --- kernel/trace/trace.c | 1 + 1 file changed, 1 insertion(+) diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index 05330494a0df..458031c31a37 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -876,6 +876,7 @@ static struct { { trace_clock_jiffies, "uptime", 0 }, { trace_clock, "perf", 1 }, { ktime_get_mono_fast_ns, "mono", 1 }, + { ktime_get_raw_fast_ns, "mono_raw", 1 }, ARCH_TRACE_CLOCKS }; From f267caab44451baa70d25fa3191a68bb79ad1b08 Mon Sep 17 00:00:00 2001 From: "Steven Rostedt (Red Hat)" Date: Wed, 13 May 2015 14:03:51 -0400 Subject: [PATCH 04/33] tracing: Remove unused prototype ftrace_event_define_field() ftrace_event_define_field() has a prototype defined but never used. Remove it. Signed-off-by: Steven Rostedt --- include/linux/ftrace_event.h | 8 -------- 1 file changed, 8 deletions(-) diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h index 65ce6de91307..f8465d65f3c7 100644 --- a/include/linux/ftrace_event.h +++ b/include/linux/ftrace_event.h @@ -219,10 +219,6 @@ struct ftrace_event_class { extern int ftrace_event_reg(struct ftrace_event_call *event, enum trace_reg type, void *data); -int ftrace_event_define_field(struct ftrace_event_call *call, - char *type, int len, char *item, int offset, - int field_size, int sign, int filter); - struct ftrace_event_buffer { struct ring_buffer *buffer; struct ring_buffer_event *event; @@ -238,10 +234,6 @@ void *ftrace_event_buffer_reserve(struct ftrace_event_buffer *fbuffer, void ftrace_event_buffer_commit(struct ftrace_event_buffer *fbuffer); -int ftrace_event_define_field(struct ftrace_event_call *call, - char *type, int len, char *item, int offset, - int field_size, int sign, int filter); - enum { TRACE_EVENT_FL_FILTERED_BIT, TRACE_EVENT_FL_CAP_ANY_BIT, From 2167ae727215714d25fe44945cdbe6157f7ac481 Mon Sep 17 00:00:00 2001 From: "Steven Rostedt (Red Hat)" Date: Wed, 29 Apr 2015 09:57:36 -0400 Subject: [PATCH 05/33] tracing: Rename trace/ftrace.h to trace/trace_events.h The name "ftrace" really refers to the function hook infrastructure. It is not about the TRACE_EVENT() macros. The file trace/ftrace.h was originally written to be mostly focused toward the "ftrace" code (that in kernel/trace/) but ended up being generic and used by perf and others. Rename the file to be less confusing about what infrastructure it belongs to. Signed-off-by: Steven Rostedt --- include/trace/define_trace.h | 2 +- include/trace/{ftrace.h => trace_events.h} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename include/trace/{ftrace.h => trace_events.h} (100%) diff --git a/include/trace/define_trace.h b/include/trace/define_trace.h index 02e1003568a4..b13ba2fc76f7 100644 --- a/include/trace/define_trace.h +++ b/include/trace/define_trace.h @@ -87,7 +87,7 @@ #define DECLARE_TRACE(name, proto, args) #ifdef CONFIG_EVENT_TRACING -#include +#include #endif #undef TRACE_EVENT diff --git a/include/trace/ftrace.h b/include/trace/trace_events.h similarity index 100% rename from include/trace/ftrace.h rename to include/trace/trace_events.h From ee53bbd172571c944bc2d01b4846fc7c49ebd353 Mon Sep 17 00:00:00 2001 From: "Steven Rostedt (Red Hat)" Date: Wed, 29 Apr 2015 13:11:00 -0400 Subject: [PATCH 06/33] tracing: Move the perf code out of trace_event.h The trace_event.h file is for the generic trace event code. Move the perf related code into its own trace header file perf.h Signed-off-by: Steven Rostedt --- include/trace/define_trace.h | 1 + include/trace/perf.h | 350 ++++++++++++++++++++++++++++++++++ include/trace/trace_events.h | 351 ----------------------------------- 3 files changed, 351 insertions(+), 351 deletions(-) create mode 100644 include/trace/perf.h diff --git a/include/trace/define_trace.h b/include/trace/define_trace.h index b13ba2fc76f7..09b3880105a9 100644 --- a/include/trace/define_trace.h +++ b/include/trace/define_trace.h @@ -88,6 +88,7 @@ #ifdef CONFIG_EVENT_TRACING #include +#include #endif #undef TRACE_EVENT diff --git a/include/trace/perf.h b/include/trace/perf.h new file mode 100644 index 000000000000..5e82add1647b --- /dev/null +++ b/include/trace/perf.h @@ -0,0 +1,350 @@ +/* + * Stage 4 of the trace events. + * + * Override the macros in to include the following: + * + * For those macros defined with TRACE_EVENT: + * + * static struct ftrace_event_call event_; + * + * static void ftrace_raw_event_(void *__data, proto) + * { + * struct ftrace_event_file *ftrace_file = __data; + * struct ftrace_event_call *event_call = ftrace_file->event_call; + * struct ftrace_data_offsets_ __maybe_unused __data_offsets; + * unsigned long eflags = ftrace_file->flags; + * enum event_trigger_type __tt = ETT_NONE; + * struct ring_buffer_event *event; + * struct ftrace_raw_ *entry; <-- defined in stage 1 + * struct ring_buffer *buffer; + * unsigned long irq_flags; + * int __data_size; + * int pc; + * + * if (!(eflags & FTRACE_EVENT_FL_TRIGGER_COND)) { + * if (eflags & FTRACE_EVENT_FL_TRIGGER_MODE) + * event_triggers_call(ftrace_file, NULL); + * if (eflags & FTRACE_EVENT_FL_SOFT_DISABLED) + * return; + * } + * + * local_save_flags(irq_flags); + * pc = preempt_count(); + * + * __data_size = ftrace_get_offsets_(&__data_offsets, args); + * + * event = trace_event_buffer_lock_reserve(&buffer, ftrace_file, + * event_->event.type, + * sizeof(*entry) + __data_size, + * irq_flags, pc); + * if (!event) + * return; + * entry = ring_buffer_event_data(event); + * + * { ; } <-- Here we assign the entries by the __field and + * __array macros. + * + * if (eflags & FTRACE_EVENT_FL_TRIGGER_COND) + * __tt = event_triggers_call(ftrace_file, entry); + * + * if (test_bit(FTRACE_EVENT_FL_SOFT_DISABLED_BIT, + * &ftrace_file->flags)) + * ring_buffer_discard_commit(buffer, event); + * else if (!filter_check_discard(ftrace_file, entry, buffer, event)) + * trace_buffer_unlock_commit(buffer, event, irq_flags, pc); + * + * if (__tt) + * event_triggers_post_call(ftrace_file, __tt); + * } + * + * static struct trace_event ftrace_event_type_ = { + * .trace = ftrace_raw_output_, <-- stage 2 + * }; + * + * static char print_fmt_[] = ; + * + * static struct ftrace_event_class __used event_class_