aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/trace
diff options
context:
space:
mode:
authorLai Jiangshan <laijs@cn.fujitsu.com>2009-03-06 11:21:48 -0500
committerIngo Molnar <mingo@elte.hu>2009-03-06 11:59:11 -0500
commit1ba28e02a18cbdbea123836f6c98efb09cbf59ec (patch)
tree41df06a06c702152902ffd7250f284a6efe9b0da /kernel/trace
parent1427cdf0592368bdec57276edaf714040ee8744f (diff)
tracing: add trace_bprintk()
Impact: add a generic printk() for tracing, like trace_printk() trace_bprintk() uses the infrastructure to record events on ring_buffer. [ fweisbec@gmail.com: ported to latest -tip, made it work if !CONFIG_MODULES, never free the format strings from modules because we can't keep track of them and conditionnaly create the ftrace format strings section (reported by Steven Rostedt) ] Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com> Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com> Acked-by: Steven Rostedt <rostedt@goodmis.org> LKML-Reference: <1236356510-8381-4-git-send-email-fweisbec@gmail.com> Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'kernel/trace')
-rw-r--r--kernel/trace/trace.c15
-rw-r--r--kernel/trace/trace_bprintk.c87
2 files changed, 92 insertions, 10 deletions
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index ff53509e19f8..46b3cd7a5752 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -3848,6 +3848,21 @@ out:
3848} 3848}
3849EXPORT_SYMBOL_GPL(trace_vbprintk); 3849EXPORT_SYMBOL_GPL(trace_vbprintk);
3850 3850
3851int __trace_bprintk(unsigned long ip, const char *fmt, ...)
3852{
3853 int ret;
3854 va_list ap;
3855
3856 if (!fmt)
3857 return 0;
3858
3859 va_start(ap, fmt);
3860 ret = trace_vbprintk(ip, fmt, ap);
3861 va_end(ap);
3862 return ret;
3863}
3864EXPORT_SYMBOL_GPL(__trace_bprintk);
3865
3851static int trace_panic_handler(struct notifier_block *this, 3866static int trace_panic_handler(struct notifier_block *this,
3852 unsigned long event, void *unused) 3867 unsigned long event, void *unused)
3853{ 3868{
diff --git a/kernel/trace/trace_bprintk.c b/kernel/trace/trace_bprintk.c
index 1f8e532c3fb9..f4c245a5cd33 100644
--- a/kernel/trace/trace_bprintk.c
+++ b/kernel/trace/trace_bprintk.c
@@ -19,9 +19,21 @@
19 19
20#include "trace.h" 20#include "trace.h"
21 21
22#ifdef CONFIG_MODULES
23
22/* binary printk basic */ 24/* binary printk basic */
23static DEFINE_MUTEX(btrace_mutex); 25static DEFINE_MUTEX(btrace_mutex);
24static int btrace_metadata_count; 26/*
27 * modules trace_bprintk()'s formats are autosaved in struct trace_bprintk_fmt
28 * which are queued on trace_bprintk_fmt_list.
29 */
30static LIST_HEAD(trace_bprintk_fmt_list);
31
32struct trace_bprintk_fmt {
33 struct list_head list;
34 char fmt[0];
35};
36
25 37
26static inline void lock_btrace(void) 38static inline void lock_btrace(void)
27{ 39{
@@ -33,26 +45,75 @@ static inline void unlock_btrace(void)
33 mutex_unlock(&btrace_mutex); 45 mutex_unlock(&btrace_mutex);
34} 46}
35 47
36static void get_btrace_metadata(void) 48
49static inline struct trace_bprintk_fmt *lookup_format(const char *fmt)
37{ 50{
38 lock_btrace(); 51 struct trace_bprintk_fmt *pos;
39 btrace_metadata_count++; 52 list_for_each_entry(pos, &trace_bprintk_fmt_list, list) {
40 unlock_btrace(); 53 if (!strcmp(pos->fmt, fmt))
54 return pos;
55 }
56 return NULL;
41} 57}
42 58
43static void put_btrace_metadata(void) 59static
60void hold_module_trace_bprintk_format(const char **start, const char **end)
44{ 61{
62 const char **iter;
45 lock_btrace(); 63 lock_btrace();
46 btrace_metadata_count--; 64 for (iter = start; iter < end; iter++) {
65 struct trace_bprintk_fmt *tb_fmt = lookup_format(*iter);
66 if (tb_fmt) {
67 *iter = tb_fmt->fmt;
68 continue;
69 }
70
71 tb_fmt = kmalloc(offsetof(struct trace_bprintk_fmt, fmt)
72 + strlen(*iter) + 1, GFP_KERNEL);
73 if (tb_fmt) {
74 list_add_tail(&tb_fmt->list, &trace_bprintk_fmt_list);
75 strcpy(tb_fmt->fmt, *iter);
76 *iter = tb_fmt->fmt;
77 } else
78 *iter = NULL;
79 }
47 unlock_btrace(); 80 unlock_btrace();
48} 81}
49 82
83static int module_trace_bprintk_format_notify(struct notifier_block *self,
84 unsigned long val, void *data)
85{
86 struct module *mod = data;
87 if (mod->num_trace_bprintk_fmt) {
88 const char **start = mod->trace_bprintk_fmt_start;
89 const char **end = start + mod->num_trace_bprintk_fmt;
90
91 if (val == MODULE_STATE_COMING)
92 hold_module_trace_bprintk_format(start, end);
93 }
94 return 0;
95}
96
97#else /* !CONFIG_MODULES */
98__init static int
99module_trace_bprintk_format_notify(struct notifier_block *self,
100 unsigned long val, void *data)
101{
102 return 0;
103}
104#endif /* CONFIG_MODULES */
105
106
107__initdata_or_module static
108struct notifier_block module_trace_bprintk_format_nb = {
109 .notifier_call = module_trace_bprintk_format_notify,
110};
111
50/* events tracer */ 112/* events tracer */
51int trace_bprintk_enable; 113int trace_bprintk_enable;
52 114
53static void start_bprintk_trace(struct trace_array *tr) 115static void start_bprintk_trace(struct trace_array *tr)
54{ 116{
55 get_btrace_metadata();
56 tracing_reset_online_cpus(tr); 117 tracing_reset_online_cpus(tr);
57 trace_bprintk_enable = 1; 118 trace_bprintk_enable = 1;
58} 119}
@@ -61,7 +122,6 @@ static void stop_bprintk_trace(struct trace_array *tr)
61{ 122{
62 trace_bprintk_enable = 0; 123 trace_bprintk_enable = 0;
63 tracing_reset_online_cpus(tr); 124 tracing_reset_online_cpus(tr);
64 put_btrace_metadata();
65} 125}
66 126
67static int init_bprintk_trace(struct trace_array *tr) 127static int init_bprintk_trace(struct trace_array *tr)
@@ -81,7 +141,14 @@ static struct tracer bprintk_trace __read_mostly =
81 141
82static __init int init_bprintk(void) 142static __init int init_bprintk(void)
83{ 143{
84 return register_tracer(&bprintk_trace); 144 int ret = register_module_notifier(&module_trace_bprintk_format_nb);
145 if (ret)
146 return ret;
147
148 ret = register_tracer(&bprintk_trace);
149 if (ret)
150 unregister_module_notifier(&module_trace_bprintk_format_nb);
151 return ret;
85} 152}
86 153
87device_initcall(init_bprintk); 154device_initcall(init_bprintk);