tracing: Factorize the events profile accounting
authorFrederic Weisbecker <fweisbec@gmail.com>
Thu, 17 Sep 2009 22:54:43 +0000 (00:54 +0200)
committerFrederic Weisbecker <fweisbec@gmail.com>
Fri, 18 Sep 2009 04:14:32 +0000 (06:14 +0200)
Factorize the events enabling accounting in a common tracing core
helper. This reduces the size of the profile_enable() and
profile_disable() callbacks for each trace events.

Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Acked-by: Li Zefan <lizf@cn.fujitsu.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Jason Baron <jbaron@redhat.com>
Cc: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Ingo Molnar <mingo@elte.hu>
include/linux/ftrace_event.h
include/linux/syscalls.h
include/trace/ftrace.h
kernel/trace/trace_event_profile.c

index bd099ba82ccc5700353eb5c04a7ab967fb8b0482..bc103d7b1ca8bc42ac1b57f6de966c10e60a5e9a 100644 (file)
@@ -130,8 +130,8 @@ struct ftrace_event_call {
        void                    *data;
 
        atomic_t                profile_count;
-       int                     (*profile_enable)(struct ftrace_event_call *);
-       void                    (*profile_disable)(struct ftrace_event_call *);
+       int                     (*profile_enable)(void);
+       void                    (*profile_disable)(void);
 };
 
 #define MAX_FILTER_PRED                32
index a8e37821cc607481f7ac9e4e527623958eda4252..7d9803cbb20ff74a082d4a166395aff1448b4f90 100644 (file)
@@ -100,33 +100,25 @@ struct perf_counter_attr;
 
 #ifdef CONFIG_EVENT_PROFILE
 #define TRACE_SYS_ENTER_PROFILE(sname)                                        \
-static int prof_sysenter_enable_##sname(struct ftrace_event_call *event_call)  \
+static int prof_sysenter_enable_##sname(void)                                 \
 {                                                                             \
-       int ret = 0;                                                           \
-       if (!atomic_inc_return(&event_enter_##sname.profile_count))            \
-               ret = reg_prof_syscall_enter("sys"#sname);                     \
-       return ret;                                                            \
+       return reg_prof_syscall_enter("sys"#sname);                            \
 }                                                                             \
                                                                               \
-static void prof_sysenter_disable_##sname(struct ftrace_event_call *event_call)\
+static void prof_sysenter_disable_##sname(void)                                       \
 {                                                                             \
-       if (atomic_add_negative(-1, &event_enter_##sname.profile_count))       \
-               unreg_prof_syscall_enter("sys"#sname);                         \
+       unreg_prof_syscall_enter("sys"#sname);                                 \
 }
 
 #define TRACE_SYS_EXIT_PROFILE(sname)                                         \
-static int prof_sysexit_enable_##sname(struct ftrace_event_call *event_call)   \
+static int prof_sysexit_enable_##sname(void)                                  \
 {                                                                             \
-       int ret = 0;                                                           \
-       if (!atomic_inc_return(&event_exit_##sname.profile_count))             \
-               ret = reg_prof_syscall_exit("sys"#sname);                      \
-       return ret;                                                            \
+       return reg_prof_syscall_exit("sys"#sname);                             \
 }                                                                             \
                                                                               \
-static void prof_sysexit_disable_##sname(struct ftrace_event_call *event_call) \
+static void prof_sysexit_disable_##sname(void)                                \
 {                                                                              \
-       if (atomic_add_negative(-1, &event_exit_##sname.profile_count))        \
-               unreg_prof_syscall_exit("sys"#sname);                          \
+       unreg_prof_syscall_exit("sys"#sname);                                  \
 }
 
 #define TRACE_SYS_ENTER_PROFILE_INIT(sname)                                   \
index 72a3b437b8299eef59a0a30cfca73ab84d431d61..a822087857e98cf6d3a9e9fb2332d28197b4a2da 100644 (file)
@@ -382,20 +382,14 @@ static inline int ftrace_get_offsets_##call(                              \
  *
  * NOTE: The insertion profile callback (ftrace_profile_<call>) is defined later
  *
- * static int ftrace_profile_enable_<call>(struct ftrace_event_call *event_call)
+ * static int ftrace_profile_enable_<call>(void)
  * {
- *     int ret = 0;
- *
- *     if (!atomic_inc_return(&event_call->profile_count))
- *             ret = register_trace_<call>(ftrace_profile_<call>);
- *
- *     return ret;
+ *     return register_trace_<call>(ftrace_profile_<call>);
  * }
  *
- * static void ftrace_profile_disable_<call>(struct ftrace_event_call *event_call)
+ * static void ftrace_profile_disable_<call>(void)
  * {
- *     if (atomic_add_negative(-1, &event->call->profile_count))
- *             unregister_trace_<call>(ftrace_profile_<call>);
+ *     unregister_trace_<call>(ftrace_profile_<call>);
  * }
  *
  */
@@ -405,20 +399,14 @@ static inline int ftrace_get_offsets_##call(                              \
                                                                        \
 static void ftrace_profile_##call(proto);                              \
                                                                        \
-static int ftrace_profile_enable_##call(struct ftrace_event_call *event_call) \
+static int ftrace_profile_enable_##call(void)                          \
 {                                                                      \
-       int ret = 0;                                                    \
-                                                                       \
-       if (!atomic_inc_return(&event_call->profile_count))             \
-               ret = register_trace_##call(ftrace_profile_##call);     \
-                                                                       \
-       return ret;                                                     \
+       return register_trace_##call(ftrace_profile_##call);            \
 }                                                                      \
                                                                        \
-static void ftrace_profile_disable_##call(struct ftrace_event_call *event_call)\
+static void ftrace_profile_disable_##call(void)                                \
 {                                                                      \
-       if (atomic_add_negative(-1, &event_call->profile_count))        \
-               unregister_trace_##call(ftrace_profile_##call);         \
+       unregister_trace_##call(ftrace_profile_##call);                 \
 }
 
 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
index 55a25c933d159d5a289265e604d608d96277e63c..df4a74efd50cf02db2166e83be7d45abcbfb0dd1 100644 (file)
@@ -8,6 +8,14 @@
 #include <linux/module.h>
 #include "trace.h"
 
+static int ftrace_profile_enable_event(struct ftrace_event_call *event)
+{
+       if (atomic_inc_return(&event->profile_count))
+               return 0;
+
+       return event->profile_enable();
+}
+
 int ftrace_profile_enable(int event_id)
 {
        struct ftrace_event_call *event;
@@ -17,7 +25,7 @@ int ftrace_profile_enable(int event_id)
        list_for_each_entry(event, &ftrace_events, list) {
                if (event->id == event_id && event->profile_enable &&
                    try_module_get(event->mod)) {
-                       ret = event->profile_enable(event);
+                       ret = ftrace_profile_enable_event(event);
                        break;
                }
        }
@@ -26,6 +34,14 @@ int ftrace_profile_enable(int event_id)
        return ret;
 }
 
+static void ftrace_profile_disable_event(struct ftrace_event_call *event)
+{
+       if (!atomic_add_negative(-1, &event->profile_count))
+               return;
+
+       event->profile_disable();
+}
+
 void ftrace_profile_disable(int event_id)
 {
        struct ftrace_event_call *event;
@@ -33,7 +49,7 @@ void ftrace_profile_disable(int event_id)
        mutex_lock(&event_mutex);
        list_for_each_entry(event, &ftrace_events, list) {
                if (event->id == event_id) {
-                       event->profile_disable(event);
+                       ftrace_profile_disable_event(event);
                        module_put(event->mod);
                        break;
                }