aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorXiao Guangrong <xiaoguangrong@cn.fujitsu.com>2010-01-27 20:32:29 -0500
committerFrederic Weisbecker <fweisbec@gmail.com>2010-01-28 20:02:57 -0500
commit430ad5a600a83956749307b13257c464c3826b55 (patch)
tree9cd3dd3f54e29397ff303478de9fe6902f675b9b /include
parent339ce1a4dc2ca26444c4f65c31b71a5056f3bb0b (diff)
perf: Factorize trace events raw sample buffer operations
Introduce ftrace_perf_buf_prepare() and ftrace_perf_buf_submit() to gather the common code that operates on raw events sampling buffer. This cleans up redundant code between regular trace events, syscall events and kprobe events. Changelog v1->v2: - Rename function name as per Masami and Frederic's suggestion - Add __kprobes for ftrace_perf_buf_prepare() and make ftrace_perf_buf_submit() inline as per Masami's suggestion - Export ftrace_perf_buf_prepare since modules will use it Signed-off-by: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com> Acked-by: Masami Hiramatsu <mhiramat@redhat.com> Cc: Ingo Molnar <mingo@elte.hu> Cc: Steven Rostedt <rostedt@goodmis.org> Cc: Paul Mackerras <paulus@samba.org> Cc: Jason Baron <jbaron@redhat.com> Cc: Peter Zijlstra <peterz@infradead.org> LKML-Reference: <4B60E92D.9000808@cn.fujitsu.com> Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Diffstat (limited to 'include')
-rw-r--r--include/linux/ftrace_event.h18
-rw-r--r--include/trace/ftrace.h48
2 files changed, 21 insertions, 45 deletions
diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
index 0a09e758c7d3..cd95919d9ff3 100644
--- a/include/linux/ftrace_event.h
+++ b/include/linux/ftrace_event.h
@@ -5,6 +5,7 @@
5#include <linux/trace_seq.h> 5#include <linux/trace_seq.h>
6#include <linux/percpu.h> 6#include <linux/percpu.h>
7#include <linux/hardirq.h> 7#include <linux/hardirq.h>
8#include <linux/perf_event.h>
8 9
9struct trace_array; 10struct trace_array;
10struct tracer; 11struct tracer;
@@ -138,9 +139,6 @@ struct ftrace_event_call {
138 139
139#define FTRACE_MAX_PROFILE_SIZE 2048 140#define FTRACE_MAX_PROFILE_SIZE 2048
140 141
141extern char *perf_trace_buf;
142extern char *perf_trace_buf_nmi;
143
144#define MAX_FILTER_PRED 32 142#define MAX_FILTER_PRED 32
145#define MAX_FILTER_STR_VAL 256 /* Should handle KSYM_SYMBOL_LEN */ 143#define MAX_FILTER_STR_VAL 256 /* Should handle KSYM_SYMBOL_LEN */
146 144
@@ -195,6 +193,20 @@ extern void ftrace_profile_disable(int event_id);
195extern int ftrace_profile_set_filter(struct perf_event *event, int event_id, 193extern int ftrace_profile_set_filter(struct perf_event *event, int event_id,
196 char *filter_str); 194 char *filter_str);
197extern void ftrace_profile_free_filter(struct perf_event *event); 195extern void ftrace_profile_free_filter(struct perf_event *event);
196extern void *
197ftrace_perf_buf_prepare(int size, unsigned short type, int *rctxp,
198 unsigned long *irq_flags);
199
200static inline void
201ftrace_perf_buf_submit(void *raw_data, int size, int rctx, u64 addr,
202 u64 count, unsigned long irq_flags)
203{
204 struct trace_entry *entry = raw_data;
205
206 perf_tp_event(entry->type, addr, count, raw_data, size);
207 perf_swevent_put_recursion_context(rctx);
208 local_irq_restore(irq_flags);
209}
198#endif 210#endif
199 211
200#endif /* _LINUX_FTRACE_EVENT_H */ 212#endif /* _LINUX_FTRACE_EVENT_H */
diff --git a/include/trace/ftrace.h b/include/trace/ftrace.h
index 4a46a60c2077..f2c09e4d656c 100644
--- a/include/trace/ftrace.h
+++ b/include/trace/ftrace.h
@@ -850,22 +850,12 @@ ftrace_profile_templ_##call(struct ftrace_event_call *event_call, \
850 proto) \ 850 proto) \
851{ \ 851{ \
852 struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\ 852 struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\
853 extern int perf_swevent_get_recursion_context(void); \
854 extern void perf_swevent_put_recursion_context(int rctx); \
855 extern void perf_tp_event(int, u64, u64, void *, int); \
856 struct ftrace_raw_##call *entry; \ 853 struct ftrace_raw_##call *entry; \
857 u64 __addr = 0, __count = 1; \ 854 u64 __addr = 0, __count = 1; \
858 unsigned long irq_flags; \ 855 unsigned long irq_flags; \
859 struct trace_entry *ent; \
860 int __entry_size; \ 856 int __entry_size; \
861 int __data_size; \ 857 int __data_size; \
862 char *trace_buf; \
863 char *raw_data; \
864 int __cpu; \
865 int rctx; \ 858 int rctx; \
866 int pc; \
867 \
868 pc = preempt_count(); \
869 \ 859 \
870 __data_size = ftrace_get_offsets_##call(&__data_offsets, args); \ 860 __data_size = ftrace_get_offsets_##call(&__data_offsets, args); \
871 __entry_size = ALIGN(__data_size + sizeof(*entry) + sizeof(u32),\ 861 __entry_size = ALIGN(__data_size + sizeof(*entry) + sizeof(u32),\
@@ -875,42 +865,16 @@ ftrace_profile_templ_##call(struct ftrace_event_call *event_call, \
875 if (WARN_ONCE(__entry_size > FTRACE_MAX_PROFILE_SIZE, \ 865 if (WARN_ONCE(__entry_size > FTRACE_MAX_PROFILE_SIZE, \
876 "profile buffer not large enough")) \ 866 "profile buffer not large enough")) \
877 return; \ 867 return; \
878 \ 868 entry = (struct ftrace_raw_##call *)ftrace_perf_buf_prepare( \
879 local_irq_save(irq_flags); \ 869 __entry_size, event_call->id, &rctx, &irq_flags); \
880 \ 870 if (!entry) \
881 rctx = perf_swevent_get_recursion_context(); \ 871 return; \
882 if (rctx < 0) \
883 goto end_recursion; \
884 \
885 __cpu = smp_processor_id(); \
886 \
887 if (in_nmi()) \
888 trace_buf = rcu_dereference(perf_trace_buf_nmi); \
889 else \
890 trace_buf = rcu_dereference(perf_trace_buf); \
891 \
892 if (!trace_buf) \
893 goto end; \
894 \
895 raw_data = per_cpu_ptr(trace_buf, __cpu); \
896 \
897 *(u64 *)(&raw_data[__entry_size - sizeof(u64)]) = 0ULL; \
898 entry = (struct ftrace_raw_##call *)raw_data; \
899 ent = &entry->ent; \
900 tracing_generic_entry_update(ent, irq_flags, pc); \
901 ent->type = event_call->id; \
902 \
903 tstruct \ 872 tstruct \
904 \ 873 \
905 { assign; } \ 874 { assign; } \
906 \ 875 \
907 perf_tp_event(event_call->id, __addr, __count, entry, \ 876 ftrace_perf_buf_submit(entry, __entry_size, rctx, __addr, \
908 __entry_size); \ 877 __count, irq_flags); \
909 \
910end: \
911 perf_swevent_put_recursion_context(rctx); \
912end_recursion: \
913 local_irq_restore(irq_flags); \
914} 878}
915 879
916#undef DEFINE_EVENT 880#undef DEFINE_EVENT