Merge branch 'perf-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux-2.6-block.git] / include / trace / ftrace.h
index 0804cd5948035d9dd8d59084e946c1d32cad330c..16253db38d73274e329a20519023b342db7e7bd1 100644 (file)
  *
  *     field = (typeof(field))entry;
  *
- *     p = get_cpu_var(ftrace_event_seq);
+ *     p = &get_cpu_var(ftrace_event_seq);
  *     trace_seq_init(p);
- *     ret = trace_seq_printf(s, <TP_printk> "\n");
+ *     ret = trace_seq_printf(s, "%s: ", <call>);
+ *     if (ret)
+ *             ret = trace_seq_printf(s, <TP_printk> "\n");
  *     put_cpu();
  *     if (!ret)
  *             return TRACE_TYPE_PARTIAL_LINE;
@@ -401,18 +403,18 @@ static inline notrace int ftrace_get_offsets_##call(                      \
 #undef DEFINE_EVENT
 #define DEFINE_EVENT(template, name, proto, args)                      \
                                                                        \
-static void ftrace_profile_##name(proto);                              \
+static void perf_trace_##name(proto);                                  \
                                                                        \
 static notrace int                                                     \
-ftrace_profile_enable_##name(struct ftrace_event_call *unused)         \
+perf_trace_enable_##name(struct ftrace_event_call *unused)             \
 {                                                                      \
-       return register_trace_##name(ftrace_profile_##name);            \
+       return register_trace_##name(perf_trace_##name);                \
 }                                                                      \
                                                                        \
 static notrace void                                                    \
-ftrace_profile_disable_##name(struct ftrace_event_call *unused)                \
+perf_trace_disable_##name(struct ftrace_event_call *unused)            \
 {                                                                      \
-       unregister_trace_##name(ftrace_profile_##name);                 \
+       unregister_trace_##name(perf_trace_##name);                     \
 }
 
 #undef DEFINE_EVENT_PRINT
@@ -450,38 +452,38 @@ ftrace_profile_disable_##name(struct ftrace_event_call *unused)           \
  *
  * static void ftrace_raw_event_<call>(proto)
  * {
+ *     struct ftrace_data_offsets_<call> __maybe_unused __data_offsets;
  *     struct ring_buffer_event *event;
  *     struct ftrace_raw_<call> *entry; <-- defined in stage 1
  *     struct ring_buffer *buffer;
  *     unsigned long irq_flags;
+ *     int __data_size;
  *     int pc;
  *
  *     local_save_flags(irq_flags);
  *     pc = preempt_count();
  *
+ *     __data_size = ftrace_get_offsets_<call>(&__data_offsets, args);
+ *
  *     event = trace_current_buffer_lock_reserve(&buffer,
  *                               event_<call>.id,
- *                               sizeof(struct ftrace_raw_<call>),
+ *                               sizeof(*entry) + __data_size,
  *                               irq_flags, pc);
  *     if (!event)
  *             return;
  *     entry   = ring_buffer_event_data(event);
  *
- *     <assign>;  <-- Here we assign the entries by the __field and
- *                     __array macros.
+ *     { <assign>; }  <-- Here we assign the entries by the __field and
+ *                        __array macros.
  *
- *     trace_current_buffer_unlock_commit(buffer, event, irq_flags, pc);
+ *     if (!filter_current_check_discard(buffer, event_call, entry, event))
+ *             trace_current_buffer_unlock_commit(buffer,
+ *                                                event, irq_flags, pc);
  * }
  *
  * static int ftrace_raw_reg_event_<call>(struct ftrace_event_call *unused)
  * {
- *     int ret;
- *
- *     ret = register_trace_<call>(ftrace_raw_event_<call>);
- *     if (!ret)
- *             pr_info("event trace: Could not activate trace point "
- *                     "probe to <call>");
- *     return ret;
+ *     return register_trace_<call>(ftrace_raw_event_<call>);
  * }
  *
  * static void ftrace_unreg_event_<call>(struct ftrace_event_call *unused)
@@ -493,6 +495,8 @@ ftrace_profile_disable_##name(struct ftrace_event_call *unused)             \
  *     .trace                  = ftrace_raw_output_<call>, <-- stage 2
  * };
  *
+ * static const char print_fmt_<call>[] = <TP_printk>;
+ *
  * static struct ftrace_event_call __used
  * __attribute__((__aligned__(4)))
  * __attribute__((section("_ftrace_events"))) event_<call> = {
@@ -501,18 +505,20 @@ ftrace_profile_disable_##name(struct ftrace_event_call *unused)           \
  *     .raw_init               = trace_event_raw_init,
  *     .regfunc                = ftrace_reg_event_<call>,
  *     .unregfunc              = ftrace_unreg_event_<call>,
+ *     .print_fmt              = print_fmt_<call>,
+ *     .define_fields          = ftrace_define_fields_<call>,
  * }
  *
  */
 
 #ifdef CONFIG_PERF_EVENTS
 
-#define _TRACE_PROFILE_INIT(call)                                      \
-       .profile_enable = ftrace_profile_enable_##call,                 \
-       .profile_disable = ftrace_profile_disable_##call,
+#define _TRACE_PERF_INIT(call)                                         \
+       .perf_event_enable = perf_trace_enable_##call,                  \
+       .perf_event_disable = perf_trace_disable_##call,
 
 #else
-#define _TRACE_PROFILE_INIT(call)
+#define _TRACE_PERF_INIT(call)
 #endif /* CONFIG_PERF_EVENTS */
 
 #undef __entry
@@ -569,7 +575,6 @@ ftrace_raw_event_id_##call(struct ftrace_event_call *event_call,    \
                return;                                                 \
        entry   = ring_buffer_event_data(event);                        \
                                                                        \
-                                                                       \
        tstruct                                                         \
                                                                        \
        { assign; }                                                     \
@@ -638,7 +643,7 @@ __attribute__((section("_ftrace_events"))) event_##call = {         \
        .unregfunc              = ftrace_raw_unreg_event_##call,        \
        .print_fmt              = print_fmt_##template,                 \
        .define_fields          = ftrace_define_fields_##template,      \
-       _TRACE_PROFILE_INIT(call)                                       \
+       _TRACE_PERF_INIT(call)                                  \
 }
 
 #undef DEFINE_EVENT_PRINT
@@ -657,18 +662,18 @@ __attribute__((section("_ftrace_events"))) event_##call = {               \
        .unregfunc              = ftrace_raw_unreg_event_##call,        \
        .print_fmt              = print_fmt_##call,                     \
        .define_fields          = ftrace_define_fields_##template,      \
-       _TRACE_PROFILE_INIT(call)                                       \
+       _TRACE_PERF_INIT(call)                                  \
 }
 
 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
 
 /*
- * Define the insertion callback to profile events
+ * Define the insertion callback to perf events
  *
  * The job is very similar to ftrace_raw_event_<call> except that we don't
  * insert in the ring buffer but in a perf counter.
  *
- * static void ftrace_profile_<call>(proto)
+ * static void ftrace_perf_<call>(proto)
  * {
  *     struct ftrace_data_offsets_<call> __maybe_unused __data_offsets;
  *     struct ftrace_event_call *event_call = &event_<call>;
@@ -699,9 +704,9 @@ __attribute__((section("_ftrace_events"))) event_##call = {         \
  *     __cpu = smp_processor_id();
  *
  *     if (in_nmi())
- *             trace_buf = rcu_dereference(perf_trace_buf_nmi);
+ *             trace_buf = rcu_dereference_sched(perf_trace_buf_nmi);
  *     else
- *             trace_buf = rcu_dereference(perf_trace_buf);
+ *             trace_buf = rcu_dereference_sched(perf_trace_buf);
  *
  *     if (!trace_buf)
  *             goto end;
@@ -757,8 +762,8 @@ __attribute__((section("_ftrace_events"))) event_##call = {         \
 #undef DECLARE_EVENT_CLASS
 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
 static notrace void                                                    \
-ftrace_profile_templ_##call(struct ftrace_event_call *event_call,      \
-                           proto)                                      \
+perf_trace_templ_##call(struct ftrace_event_call *event_call,          \
+                       struct pt_regs *__regs, proto)                  \
 {                                                                      \
        struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\
        struct ftrace_raw_##call *entry;                                \
@@ -773,10 +778,10 @@ ftrace_profile_templ_##call(struct ftrace_event_call *event_call, \
                             sizeof(u64));                              \
        __entry_size -= sizeof(u32);                                    \
                                                                        \
-       if (WARN_ONCE(__entry_size > FTRACE_MAX_PROFILE_SIZE,           \
+       if (WARN_ONCE(__entry_size > PERF_MAX_TRACE_SIZE,               \
                      "profile buffer not large enough"))               \
                return;                                                 \
-       entry = (struct ftrace_raw_##call *)ftrace_perf_buf_prepare(    \
+       entry = (struct ftrace_raw_##call *)perf_trace_buf_prepare(     \
                __entry_size, event_call->id, &rctx, &irq_flags);       \
        if (!entry)                                                     \
                return;                                                 \
@@ -784,17 +789,22 @@ ftrace_profile_templ_##call(struct ftrace_event_call *event_call, \
                                                                        \
        { assign; }                                                     \
                                                                        \
-       ftrace_perf_buf_submit(entry, __entry_size, rctx, __addr,       \
-                              __count, irq_flags);                     \
+       perf_trace_buf_submit(entry, __entry_size, rctx, __addr,        \
+                              __count, irq_flags, __regs);             \
 }
 
 #undef DEFINE_EVENT
-#define DEFINE_EVENT(template, call, proto, args)              \
-static notrace void ftrace_profile_##call(proto)               \
-{                                                              \
-       struct ftrace_event_call *event_call = &event_##call;   \
-                                                               \
-       ftrace_profile_templ_##template(event_call, args);      \
+#define DEFINE_EVENT(template, call, proto, args)                      \
+static notrace void perf_trace_##call(proto)                           \
+{                                                                      \
+       struct ftrace_event_call *event_call = &event_##call;           \
+       struct pt_regs *__regs = &get_cpu_var(perf_trace_regs);         \
+                                                                       \
+       perf_fetch_caller_regs(__regs, 1);                              \
+                                                                       \
+       perf_trace_templ_##template(event_call, __regs, args);          \
+                                                                       \
+       put_cpu_var(perf_trace_regs);                                   \
 }
 
 #undef DEFINE_EVENT_PRINT