diff options
author | Anton Vorontsov <anton.vorontsov@linaro.org> | 2012-07-17 17:26:15 -0400 |
---|---|---|
committer | Anton Vorontsov <anton.vorontsov@linaro.org> | 2012-09-07 01:16:58 -0400 |
commit | 65f8c95e46a1827ae8bbc52a817ea308dd7d65ae (patch) | |
tree | adc856e8b50441b055350d8f1d83e3f641c77456 /fs/pstore | |
parent | b4a871bce619dc5ca03cc6c78e1c467ceacb8e7e (diff) |
pstore/ftrace: Convert to its own enable/disable debugfs knob
With this patch we no longer reuse function tracer infrastructure, now
we register our own tracer back-end via a debugfs knob.
It's a bit more code, but that is the only downside. On the bright side we
have:
- Ability to make persistent_ram module removable (when needed, we can
move ftrace_ops struct into a module). Note that persistent_ram is still
not removable for other reasons, but with this patch it's just one
thing less to worry about;
- Pstore part is more isolated from the generic function tracer. We tried
it already by registering our own tracer in available_tracers, but that
way we're loosing ability to see the traces while we record them to
pstore. This solution is somewhere in the middle: we only register
"internal ftracer" back-end, but not the "front-end";
- When there is only pstore tracing enabled, the kernel will only write
to the pstore buffer, omitting function tracer buffer (which, of course,
still can be enabled via 'echo function > current_tracer').
Suggested-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Anton Vorontsov <anton.vorontsov@linaro.org>
Diffstat (limited to 'fs/pstore')
-rw-r--r-- | fs/pstore/Kconfig | 1 | ||||
-rw-r--r-- | fs/pstore/ftrace.c | 96 | ||||
-rw-r--r-- | fs/pstore/internal.h | 6 | ||||
-rw-r--r-- | fs/pstore/platform.c | 1 |
4 files changed, 103 insertions, 1 deletions
diff --git a/fs/pstore/Kconfig b/fs/pstore/Kconfig index d39bb5cce883..ca71db69da07 100644 --- a/fs/pstore/Kconfig +++ b/fs/pstore/Kconfig | |||
@@ -23,6 +23,7 @@ config PSTORE_FTRACE | |||
23 | bool "Persistent function tracer" | 23 | bool "Persistent function tracer" |
24 | depends on PSTORE | 24 | depends on PSTORE |
25 | depends on FUNCTION_TRACER | 25 | depends on FUNCTION_TRACER |
26 | depends on DEBUG_FS | ||
26 | help | 27 | help |
27 | With this option kernel traces function calls into a persistent | 28 | With this option kernel traces function calls into a persistent |
28 | ram buffer that can be decoded and dumped after reboot through | 29 | ram buffer that can be decoded and dumped after reboot through |
diff --git a/fs/pstore/ftrace.c b/fs/pstore/ftrace.c index a130d484b7d3..2d57e1ac0115 100644 --- a/fs/pstore/ftrace.c +++ b/fs/pstore/ftrace.c | |||
@@ -17,19 +17,113 @@ | |||
17 | #include <linux/percpu.h> | 17 | #include <linux/percpu.h> |
18 | #include <linux/smp.h> | 18 | #include <linux/smp.h> |
19 | #include <linux/atomic.h> | 19 | #include <linux/atomic.h> |
20 | #include <linux/types.h> | ||
21 | #include <linux/mutex.h> | ||
22 | #include <linux/ftrace.h> | ||
23 | #include <linux/fs.h> | ||
24 | #include <linux/debugfs.h> | ||
25 | #include <linux/err.h> | ||
26 | #include <linux/cache.h> | ||
20 | #include <asm/barrier.h> | 27 | #include <asm/barrier.h> |
21 | #include "internal.h" | 28 | #include "internal.h" |
22 | 29 | ||
23 | void notrace pstore_ftrace_call(unsigned long ip, unsigned long parent_ip) | 30 | static void notrace pstore_ftrace_call(unsigned long ip, |
31 | unsigned long parent_ip) | ||
24 | { | 32 | { |
33 | unsigned long flags; | ||
25 | struct pstore_ftrace_record rec = {}; | 34 | struct pstore_ftrace_record rec = {}; |
26 | 35 | ||
27 | if (unlikely(oops_in_progress)) | 36 | if (unlikely(oops_in_progress)) |
28 | return; | 37 | return; |
29 | 38 | ||
39 | local_irq_save(flags); | ||
40 | |||
30 | rec.ip = ip; | 41 | rec.ip = ip; |
31 | rec.parent_ip = parent_ip; | 42 | rec.parent_ip = parent_ip; |
32 | pstore_ftrace_encode_cpu(&rec, raw_smp_processor_id()); | 43 | pstore_ftrace_encode_cpu(&rec, raw_smp_processor_id()); |
33 | psinfo->write_buf(PSTORE_TYPE_FTRACE, 0, NULL, 0, (void *)&rec, | 44 | psinfo->write_buf(PSTORE_TYPE_FTRACE, 0, NULL, 0, (void *)&rec, |
34 | sizeof(rec), psinfo); | 45 | sizeof(rec), psinfo); |
46 | |||
47 | local_irq_restore(flags); | ||
48 | } | ||
49 | |||
50 | static struct ftrace_ops pstore_ftrace_ops __read_mostly = { | ||
51 | .func = pstore_ftrace_call, | ||
52 | }; | ||
53 | |||
54 | static DEFINE_MUTEX(pstore_ftrace_lock); | ||
55 | static bool pstore_ftrace_enabled; | ||
56 | |||
57 | static ssize_t pstore_ftrace_knob_write(struct file *f, const char __user *buf, | ||
58 | size_t count, loff_t *ppos) | ||
59 | { | ||
60 | u8 on; | ||
61 | ssize_t ret; | ||
62 | |||
63 | ret = kstrtou8_from_user(buf, count, 2, &on); | ||
64 | if (ret) | ||
65 | return ret; | ||
66 | |||
67 | mutex_lock(&pstore_ftrace_lock); | ||
68 | |||
69 | if (!on ^ pstore_ftrace_enabled) | ||
70 | goto out; | ||
71 | |||
72 | if (on) | ||
73 | ret = register_ftrace_function(&pstore_ftrace_ops); | ||
74 | else | ||
75 | ret = unregister_ftrace_function(&pstore_ftrace_ops); | ||
76 | if (ret) { | ||
77 | pr_err("%s: unable to %sregister ftrace ops: %zd\n", | ||
78 | __func__, on ? "" : "un", ret); | ||
79 | goto err; | ||
80 | } | ||
81 | |||
82 | pstore_ftrace_enabled = on; | ||
83 | out: | ||
84 | ret = count; | ||
85 | err: | ||
86 | mutex_unlock(&pstore_ftrace_lock); | ||
87 | |||
88 | return ret; | ||
89 | } | ||
90 | |||
91 | static ssize_t pstore_ftrace_knob_read(struct file *f, char __user *buf, | ||
92 | size_t count, loff_t *ppos) | ||
93 | { | ||
94 | char val[] = { '0' + pstore_ftrace_enabled, '\n' }; | ||
95 | |||
96 | return simple_read_from_buffer(buf, count, ppos, val, sizeof(val)); | ||
97 | } | ||
98 | |||
99 | static const struct file_operations pstore_knob_fops = { | ||
100 | .open = simple_open, | ||
101 | .read = pstore_ftrace_knob_read, | ||
102 | .write = pstore_ftrace_knob_write, | ||
103 | }; | ||
104 | |||
105 | void pstore_register_ftrace(void) | ||
106 | { | ||
107 | struct dentry *dir; | ||
108 | struct dentry *file; | ||
109 | |||
110 | if (!psinfo->write_buf) | ||
111 | return; | ||
112 | |||
113 | dir = debugfs_create_dir("pstore", NULL); | ||
114 | if (!dir) { | ||
115 | pr_err("%s: unable to create pstore directory\n", __func__); | ||
116 | return; | ||
117 | } | ||
118 | |||
119 | file = debugfs_create_file("record_ftrace", 0600, dir, NULL, | ||
120 | &pstore_knob_fops); | ||
121 | if (!file) { | ||
122 | pr_err("%s: unable to create record_ftrace file\n", __func__); | ||
123 | goto err_file; | ||
124 | } | ||
125 | |||
126 | return; | ||
127 | err_file: | ||
128 | debugfs_remove(dir); | ||
35 | } | 129 | } |
diff --git a/fs/pstore/internal.h b/fs/pstore/internal.h index 0d0d3b7d5f12..4847f588b7d5 100644 --- a/fs/pstore/internal.h +++ b/fs/pstore/internal.h | |||
@@ -39,6 +39,12 @@ pstore_ftrace_decode_cpu(struct pstore_ftrace_record *rec) | |||
39 | #endif | 39 | #endif |
40 | } | 40 | } |
41 | 41 | ||
42 | #ifdef CONFIG_PSTORE_FTRACE | ||
43 | extern void pstore_register_ftrace(void); | ||
44 | #else | ||
45 | static inline void pstore_register_ftrace(void) {} | ||
46 | #endif | ||
47 | |||
42 | extern struct pstore_info *psinfo; | 48 | extern struct pstore_info *psinfo; |
43 | 49 | ||
44 | extern void pstore_set_kmsg_bytes(int); | 50 | extern void pstore_set_kmsg_bytes(int); |
diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c index 29996e8793a7..6c23eab7f76c 100644 --- a/fs/pstore/platform.c +++ b/fs/pstore/platform.c | |||
@@ -236,6 +236,7 @@ int pstore_register(struct pstore_info *psi) | |||
236 | 236 | ||
237 | kmsg_dump_register(&pstore_dumper); | 237 | kmsg_dump_register(&pstore_dumper); |
238 | pstore_register_console(); | 238 | pstore_register_console(); |
239 | pstore_register_ftrace(); | ||
239 | 240 | ||
240 | if (pstore_update_ms >= 0) { | 241 | if (pstore_update_ms >= 0) { |
241 | pstore_timer.expires = jiffies + | 242 | pstore_timer.expires = jiffies + |