diff options
| author | Lai Jiangshan <laijs@cn.fujitsu.com> | 2009-03-06 11:21:48 -0500 |
|---|---|---|
| committer | Ingo Molnar <mingo@elte.hu> | 2009-03-06 11:59:11 -0500 |
| commit | 1ba28e02a18cbdbea123836f6c98efb09cbf59ec (patch) | |
| tree | 41df06a06c702152902ffd7250f284a6efe9b0da /kernel/trace | |
| parent | 1427cdf0592368bdec57276edaf714040ee8744f (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.c | 15 | ||||
| -rw-r--r-- | kernel/trace/trace_bprintk.c | 87 |
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 | } |
| 3849 | EXPORT_SYMBOL_GPL(trace_vbprintk); | 3849 | EXPORT_SYMBOL_GPL(trace_vbprintk); |
| 3850 | 3850 | ||
| 3851 | int __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 | } | ||
| 3864 | EXPORT_SYMBOL_GPL(__trace_bprintk); | ||
| 3865 | |||
| 3851 | static int trace_panic_handler(struct notifier_block *this, | 3866 | static 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 */ |
| 23 | static DEFINE_MUTEX(btrace_mutex); | 25 | static DEFINE_MUTEX(btrace_mutex); |
| 24 | static 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 | */ | ||
| 30 | static LIST_HEAD(trace_bprintk_fmt_list); | ||
| 31 | |||
| 32 | struct trace_bprintk_fmt { | ||
| 33 | struct list_head list; | ||
| 34 | char fmt[0]; | ||
| 35 | }; | ||
| 36 | |||
| 25 | 37 | ||
| 26 | static inline void lock_btrace(void) | 38 | static 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 | ||
| 36 | static void get_btrace_metadata(void) | 48 | |
| 49 | static 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 | ||
| 43 | static void put_btrace_metadata(void) | 59 | static |
| 60 | void 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 | ||
| 83 | static 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 | ||
| 99 | module_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 | ||
| 108 | struct notifier_block module_trace_bprintk_format_nb = { | ||
| 109 | .notifier_call = module_trace_bprintk_format_notify, | ||
| 110 | }; | ||
| 111 | |||
| 50 | /* events tracer */ | 112 | /* events tracer */ |
| 51 | int trace_bprintk_enable; | 113 | int trace_bprintk_enable; |
| 52 | 114 | ||
| 53 | static void start_bprintk_trace(struct trace_array *tr) | 115 | static 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 | ||
| 67 | static int init_bprintk_trace(struct trace_array *tr) | 127 | static int init_bprintk_trace(struct trace_array *tr) |
| @@ -81,7 +141,14 @@ static struct tracer bprintk_trace __read_mostly = | |||
| 81 | 141 | ||
| 82 | static __init int init_bprintk(void) | 142 | static __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 | ||
| 87 | device_initcall(init_bprintk); | 154 | device_initcall(init_bprintk); |
