Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1 | /* |
| 2 | * ring buffer based function tracer |
| 3 | * |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4 | * Copyright (C) 2007-2012 Steven Rostedt <srostedt@redhat.com> |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5 | * Copyright (C) 2008 Ingo Molnar <mingo@redhat.com> |
| 6 | * |
| 7 | * Originally taken from the RT patch by: |
| 8 | * Arnaldo Carvalho de Melo <acme@redhat.com> |
| 9 | * |
| 10 | * Based on code from the latency_tracer, that is: |
| 11 | * Copyright (C) 2004-2006 Ingo Molnar |
Nadia Yvette Chambers | 6d49e35 | 2012-12-06 10:39:54 +0100 | [diff] [blame] | 12 | * Copyright (C) 2004 Nadia Yvette Chambers |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 13 | */ |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 14 | #include <linux/ring_buffer.h> |
Sam Ravnborg | 273b281 | 2009-10-18 00:52:28 +0200 | [diff] [blame] | 15 | #include <generated/utsrelease.h> |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 16 | #include <linux/stacktrace.h> |
| 17 | #include <linux/writeback.h> |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 18 | #include <linux/kallsyms.h> |
| 19 | #include <linux/seq_file.h> |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 20 | #include <linux/notifier.h> |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 21 | #include <linux/irqflags.h> |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 22 | #include <linux/debugfs.h> |
Steven Rostedt | 4c11d7a | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 23 | #include <linux/pagemap.h> |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 24 | #include <linux/hardirq.h> |
| 25 | #include <linux/linkage.h> |
| 26 | #include <linux/uaccess.h> |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 27 | #include <linux/kprobes.h> |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 28 | #include <linux/ftrace.h> |
| 29 | #include <linux/module.h> |
| 30 | #include <linux/percpu.h> |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 31 | #include <linux/splice.h> |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 32 | #include <linux/kdebug.h> |
Frederic Weisbecker | 5f0c6c0 | 2009-03-27 14:22:10 +0100 | [diff] [blame] | 33 | #include <linux/string.h> |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 34 | #include <linux/rwsem.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 35 | #include <linux/slab.h> |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 36 | #include <linux/ctype.h> |
| 37 | #include <linux/init.h> |
Soeren Sandmann Pedersen | 2a2cc8f | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 38 | #include <linux/poll.h> |
Steven Rostedt | b892e5c | 2012-03-01 22:06:48 -0500 | [diff] [blame] | 39 | #include <linux/nmi.h> |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 40 | #include <linux/fs.h> |
Clark Williams | 8bd75c7 | 2013-02-07 09:47:07 -0600 | [diff] [blame] | 41 | #include <linux/sched/rt.h> |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 42 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 43 | #include "trace.h" |
Steven Rostedt | f0868d1 | 2008-12-23 23:24:12 -0500 | [diff] [blame] | 44 | #include "trace_output.h" |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 45 | |
Frederic Weisbecker | 8e1b82e | 2008-12-06 03:41:33 +0100 | [diff] [blame] | 46 | /* |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 47 | * On boot up, the ring buffer is set to the minimum size, so that |
| 48 | * we do not waste memory on systems that are not using tracing. |
| 49 | */ |
Steven Rostedt (Red Hat) | 55034cd | 2013-03-07 22:48:09 -0500 | [diff] [blame] | 50 | bool ring_buffer_expanded; |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 51 | |
| 52 | /* |
Frederic Weisbecker | 8e1b82e | 2008-12-06 03:41:33 +0100 | [diff] [blame] | 53 | * We need to change this state when a selftest is running. |
Frederic Weisbecker | ff32504 | 2008-12-04 23:47:35 +0100 | [diff] [blame] | 54 | * A selftest will lurk into the ring-buffer to count the |
| 55 | * entries inserted during the selftest although some concurrent |
Ingo Molnar | 5e1607a | 2009-03-05 10:24:48 +0100 | [diff] [blame] | 56 | * insertions into the ring-buffer such as trace_printk could occurred |
Frederic Weisbecker | ff32504 | 2008-12-04 23:47:35 +0100 | [diff] [blame] | 57 | * at the same time, giving false positive or negative results. |
| 58 | */ |
Frederic Weisbecker | 8e1b82e | 2008-12-06 03:41:33 +0100 | [diff] [blame] | 59 | static bool __read_mostly tracing_selftest_running; |
Frederic Weisbecker | ff32504 | 2008-12-04 23:47:35 +0100 | [diff] [blame] | 60 | |
Steven Rostedt | b2821ae | 2009-02-02 21:38:32 -0500 | [diff] [blame] | 61 | /* |
| 62 | * If a tracer is running, we do not want to run SELFTEST. |
| 63 | */ |
Li Zefan | 020e5f8 | 2009-07-01 10:47:05 +0800 | [diff] [blame] | 64 | bool __read_mostly tracing_selftest_disabled; |
Steven Rostedt | b2821ae | 2009-02-02 21:38:32 -0500 | [diff] [blame] | 65 | |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 66 | /* For tracers that don't implement custom flags */ |
| 67 | static struct tracer_opt dummy_tracer_opt[] = { |
| 68 | { } |
| 69 | }; |
| 70 | |
| 71 | static struct tracer_flags dummy_tracer_flags = { |
| 72 | .val = 0, |
| 73 | .opts = dummy_tracer_opt |
| 74 | }; |
| 75 | |
Steven Rostedt (Red Hat) | 8c1a49a | 2014-01-10 11:13:54 -0500 | [diff] [blame^] | 76 | static int |
| 77 | dummy_set_flag(struct trace_array *tr, u32 old_flags, u32 bit, int set) |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 78 | { |
| 79 | return 0; |
| 80 | } |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 81 | |
| 82 | /* |
Steven Rostedt | 7ffbd48 | 2012-10-11 12:14:25 -0400 | [diff] [blame] | 83 | * To prevent the comm cache from being overwritten when no |
| 84 | * tracing is active, only save the comm when a trace event |
| 85 | * occurred. |
| 86 | */ |
| 87 | static DEFINE_PER_CPU(bool, trace_cmdline_save); |
| 88 | |
| 89 | /* |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 90 | * Kill all tracing for good (never come back). |
| 91 | * It is initialized to 1 but will turn to zero if the initialization |
| 92 | * of the tracer is successful. But that is the only place that sets |
| 93 | * this back to zero. |
| 94 | */ |
Hannes Eder | 4fd2735 | 2009-02-10 19:44:12 +0100 | [diff] [blame] | 95 | static int tracing_disabled = 1; |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 96 | |
Christoph Lameter | 9288f99 | 2009-10-07 19:17:45 -0400 | [diff] [blame] | 97 | DEFINE_PER_CPU(int, ftrace_cpu_disabled); |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 98 | |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 99 | cpumask_var_t __read_mostly tracing_buffer_mask; |
Steven Rostedt | ab46428 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 100 | |
Steven Rostedt | 944ac42 | 2008-10-23 19:26:08 -0400 | [diff] [blame] | 101 | /* |
| 102 | * ftrace_dump_on_oops - variable to dump ftrace buffer on oops |
| 103 | * |
| 104 | * If there is an oops (or kernel panic) and the ftrace_dump_on_oops |
| 105 | * is set, then ftrace_dump is called. This will output the contents |
| 106 | * of the ftrace buffers to the console. This is very useful for |
| 107 | * capturing traces that lead to crashes and outputing it to a |
| 108 | * serial console. |
| 109 | * |
| 110 | * It is default off, but you can enable it with either specifying |
| 111 | * "ftrace_dump_on_oops" in the kernel command line, or setting |
Frederic Weisbecker | cecbca9 | 2010-04-18 19:08:41 +0200 | [diff] [blame] | 112 | * /proc/sys/kernel/ftrace_dump_on_oops |
| 113 | * Set 1 if you want to dump buffers of all CPUs |
| 114 | * Set 2 if you want to dump the buffer of the CPU that triggered oops |
Steven Rostedt | 944ac42 | 2008-10-23 19:26:08 -0400 | [diff] [blame] | 115 | */ |
Frederic Weisbecker | cecbca9 | 2010-04-18 19:08:41 +0200 | [diff] [blame] | 116 | |
| 117 | enum ftrace_dump_mode ftrace_dump_on_oops; |
Steven Rostedt | 944ac42 | 2008-10-23 19:26:08 -0400 | [diff] [blame] | 118 | |
Steven Rostedt (Red Hat) | de7edd3 | 2013-06-14 16:21:43 -0400 | [diff] [blame] | 119 | /* When set, tracing will stop when a WARN*() is hit */ |
| 120 | int __disable_trace_on_warning; |
| 121 | |
Steven Rostedt | b2821ae | 2009-02-02 21:38:32 -0500 | [diff] [blame] | 122 | static int tracing_set_tracer(const char *buf); |
| 123 | |
Li Zefan | ee6c2c1 | 2009-09-18 14:06:47 +0800 | [diff] [blame] | 124 | #define MAX_TRACER_SIZE 100 |
| 125 | static char bootup_tracer_buf[MAX_TRACER_SIZE] __initdata; |
Steven Rostedt | b2821ae | 2009-02-02 21:38:32 -0500 | [diff] [blame] | 126 | static char *default_bootup_tracer; |
Peter Zijlstra | d9e5407 | 2008-11-01 19:57:37 +0100 | [diff] [blame] | 127 | |
Steven Rostedt (Red Hat) | 55034cd | 2013-03-07 22:48:09 -0500 | [diff] [blame] | 128 | static bool allocate_snapshot; |
| 129 | |
Frederic Weisbecker | 1beee96 | 2009-10-14 20:50:32 +0200 | [diff] [blame] | 130 | static int __init set_cmdline_ftrace(char *str) |
Peter Zijlstra | d9e5407 | 2008-11-01 19:57:37 +0100 | [diff] [blame] | 131 | { |
Chen Gang | 67012ab | 2013-04-08 12:06:44 +0800 | [diff] [blame] | 132 | strlcpy(bootup_tracer_buf, str, MAX_TRACER_SIZE); |
Steven Rostedt | b2821ae | 2009-02-02 21:38:32 -0500 | [diff] [blame] | 133 | default_bootup_tracer = bootup_tracer_buf; |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 134 | /* We are using ftrace early, expand it */ |
Steven Rostedt (Red Hat) | 55034cd | 2013-03-07 22:48:09 -0500 | [diff] [blame] | 135 | ring_buffer_expanded = true; |
Peter Zijlstra | d9e5407 | 2008-11-01 19:57:37 +0100 | [diff] [blame] | 136 | return 1; |
| 137 | } |
Frederic Weisbecker | 1beee96 | 2009-10-14 20:50:32 +0200 | [diff] [blame] | 138 | __setup("ftrace=", set_cmdline_ftrace); |
Peter Zijlstra | d9e5407 | 2008-11-01 19:57:37 +0100 | [diff] [blame] | 139 | |
Steven Rostedt | 944ac42 | 2008-10-23 19:26:08 -0400 | [diff] [blame] | 140 | static int __init set_ftrace_dump_on_oops(char *str) |
| 141 | { |
Frederic Weisbecker | cecbca9 | 2010-04-18 19:08:41 +0200 | [diff] [blame] | 142 | if (*str++ != '=' || !*str) { |
| 143 | ftrace_dump_on_oops = DUMP_ALL; |
| 144 | return 1; |
| 145 | } |
| 146 | |
| 147 | if (!strcmp("orig_cpu", str)) { |
| 148 | ftrace_dump_on_oops = DUMP_ORIG; |
| 149 | return 1; |
| 150 | } |
| 151 | |
| 152 | return 0; |
Steven Rostedt | 944ac42 | 2008-10-23 19:26:08 -0400 | [diff] [blame] | 153 | } |
| 154 | __setup("ftrace_dump_on_oops", set_ftrace_dump_on_oops); |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 155 | |
Steven Rostedt (Red Hat) | de7edd3 | 2013-06-14 16:21:43 -0400 | [diff] [blame] | 156 | static int __init stop_trace_on_warning(char *str) |
| 157 | { |
| 158 | __disable_trace_on_warning = 1; |
| 159 | return 1; |
| 160 | } |
| 161 | __setup("traceoff_on_warning=", stop_trace_on_warning); |
| 162 | |
Steven Rostedt (Red Hat) | 3209cff | 2013-03-12 11:17:54 -0400 | [diff] [blame] | 163 | static int __init boot_alloc_snapshot(char *str) |
Steven Rostedt (Red Hat) | 55034cd | 2013-03-07 22:48:09 -0500 | [diff] [blame] | 164 | { |
| 165 | allocate_snapshot = true; |
| 166 | /* We also need the main ring buffer expanded */ |
| 167 | ring_buffer_expanded = true; |
| 168 | return 1; |
| 169 | } |
Steven Rostedt (Red Hat) | 3209cff | 2013-03-12 11:17:54 -0400 | [diff] [blame] | 170 | __setup("alloc_snapshot", boot_alloc_snapshot); |
Steven Rostedt (Red Hat) | 55034cd | 2013-03-07 22:48:09 -0500 | [diff] [blame] | 171 | |
Steven Rostedt | 7bcfaf5 | 2012-11-01 22:56:07 -0400 | [diff] [blame] | 172 | |
| 173 | static char trace_boot_options_buf[MAX_TRACER_SIZE] __initdata; |
| 174 | static char *trace_boot_options __initdata; |
| 175 | |
| 176 | static int __init set_trace_boot_options(char *str) |
| 177 | { |
Chen Gang | 67012ab | 2013-04-08 12:06:44 +0800 | [diff] [blame] | 178 | strlcpy(trace_boot_options_buf, str, MAX_TRACER_SIZE); |
Steven Rostedt | 7bcfaf5 | 2012-11-01 22:56:07 -0400 | [diff] [blame] | 179 | trace_boot_options = trace_boot_options_buf; |
| 180 | return 0; |
| 181 | } |
| 182 | __setup("trace_options=", set_trace_boot_options); |
| 183 | |
Steven Rostedt (Red Hat) | de7edd3 | 2013-06-14 16:21:43 -0400 | [diff] [blame] | 184 | |
Lai Jiangshan | cf8e347 | 2009-03-30 13:48:00 +0800 | [diff] [blame] | 185 | unsigned long long ns2usecs(cycle_t nsec) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 186 | { |
| 187 | nsec += 500; |
| 188 | do_div(nsec, 1000); |
| 189 | return nsec; |
| 190 | } |
| 191 | |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 192 | /* |
| 193 | * The global_trace is the descriptor that holds the tracing |
| 194 | * buffers for the live tracing. For each CPU, it contains |
| 195 | * a link list of pages that will store trace entries. The |
| 196 | * page descriptor of the pages in the memory is used to hold |
| 197 | * the link list by linking the lru item in the page descriptor |
| 198 | * to each of the pages in the buffer per CPU. |
| 199 | * |
| 200 | * For each active CPU there is a data field that holds the |
| 201 | * pages for the buffer for that CPU. Each CPU has the same number |
| 202 | * of pages allocated for its buffer. |
| 203 | */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 204 | static struct trace_array global_trace; |
| 205 | |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 206 | LIST_HEAD(ftrace_trace_arrays); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 207 | |
Steven Rostedt (Red Hat) | ff45196 | 2013-07-01 22:50:29 -0400 | [diff] [blame] | 208 | int trace_array_get(struct trace_array *this_tr) |
| 209 | { |
| 210 | struct trace_array *tr; |
| 211 | int ret = -ENODEV; |
| 212 | |
| 213 | mutex_lock(&trace_types_lock); |
| 214 | list_for_each_entry(tr, &ftrace_trace_arrays, list) { |
| 215 | if (tr == this_tr) { |
| 216 | tr->ref++; |
| 217 | ret = 0; |
| 218 | break; |
| 219 | } |
| 220 | } |
| 221 | mutex_unlock(&trace_types_lock); |
| 222 | |
| 223 | return ret; |
| 224 | } |
| 225 | |
| 226 | static void __trace_array_put(struct trace_array *this_tr) |
| 227 | { |
| 228 | WARN_ON(!this_tr->ref); |
| 229 | this_tr->ref--; |
| 230 | } |
| 231 | |
| 232 | void trace_array_put(struct trace_array *this_tr) |
| 233 | { |
| 234 | mutex_lock(&trace_types_lock); |
| 235 | __trace_array_put(this_tr); |
| 236 | mutex_unlock(&trace_types_lock); |
| 237 | } |
| 238 | |
Tom Zanussi | f306cc8 | 2013-10-24 08:34:17 -0500 | [diff] [blame] | 239 | int filter_check_discard(struct ftrace_event_file *file, void *rec, |
| 240 | struct ring_buffer *buffer, |
| 241 | struct ring_buffer_event *event) |
Tom Zanussi | eb02ce0 | 2009-04-08 03:15:54 -0500 | [diff] [blame] | 242 | { |
Tom Zanussi | f306cc8 | 2013-10-24 08:34:17 -0500 | [diff] [blame] | 243 | if (unlikely(file->flags & FTRACE_EVENT_FL_FILTERED) && |
| 244 | !filter_match_preds(file->filter, rec)) { |
| 245 | ring_buffer_discard_commit(buffer, event); |
| 246 | return 1; |
| 247 | } |
| 248 | |
| 249 | return 0; |
Tom Zanussi | eb02ce0 | 2009-04-08 03:15:54 -0500 | [diff] [blame] | 250 | } |
Tom Zanussi | f306cc8 | 2013-10-24 08:34:17 -0500 | [diff] [blame] | 251 | EXPORT_SYMBOL_GPL(filter_check_discard); |
| 252 | |
| 253 | int call_filter_check_discard(struct ftrace_event_call *call, void *rec, |
| 254 | struct ring_buffer *buffer, |
| 255 | struct ring_buffer_event *event) |
| 256 | { |
| 257 | if (unlikely(call->flags & TRACE_EVENT_FL_FILTERED) && |
| 258 | !filter_match_preds(call->filter, rec)) { |
| 259 | ring_buffer_discard_commit(buffer, event); |
| 260 | return 1; |
| 261 | } |
| 262 | |
| 263 | return 0; |
| 264 | } |
| 265 | EXPORT_SYMBOL_GPL(call_filter_check_discard); |
Tom Zanussi | eb02ce0 | 2009-04-08 03:15:54 -0500 | [diff] [blame] | 266 | |
Alexander Z Lam | 9457158 | 2013-08-02 18:36:16 -0700 | [diff] [blame] | 267 | cycle_t buffer_ftrace_now(struct trace_buffer *buf, int cpu) |
Steven Rostedt | 37886f6 | 2009-03-17 17:22:06 -0400 | [diff] [blame] | 268 | { |
| 269 | u64 ts; |
| 270 | |
| 271 | /* Early boot up does not have a buffer yet */ |
Alexander Z Lam | 9457158 | 2013-08-02 18:36:16 -0700 | [diff] [blame] | 272 | if (!buf->buffer) |
Steven Rostedt | 37886f6 | 2009-03-17 17:22:06 -0400 | [diff] [blame] | 273 | return trace_clock_local(); |
| 274 | |
Alexander Z Lam | 9457158 | 2013-08-02 18:36:16 -0700 | [diff] [blame] | 275 | ts = ring_buffer_time_stamp(buf->buffer, cpu); |
| 276 | ring_buffer_normalize_time_stamp(buf->buffer, cpu, &ts); |
Steven Rostedt | 37886f6 | 2009-03-17 17:22:06 -0400 | [diff] [blame] | 277 | |
| 278 | return ts; |
| 279 | } |
| 280 | |
Alexander Z Lam | 9457158 | 2013-08-02 18:36:16 -0700 | [diff] [blame] | 281 | cycle_t ftrace_now(int cpu) |
| 282 | { |
| 283 | return buffer_ftrace_now(&global_trace.trace_buffer, cpu); |
| 284 | } |
| 285 | |
Steven Rostedt (Red Hat) | 10246fa | 2013-07-01 15:58:24 -0400 | [diff] [blame] | 286 | /** |
| 287 | * tracing_is_enabled - Show if global_trace has been disabled |
| 288 | * |
| 289 | * Shows if the global trace has been enabled or not. It uses the |
| 290 | * mirror flag "buffer_disabled" to be used in fast paths such as for |
| 291 | * the irqsoff tracer. But it may be inaccurate due to races. If you |
| 292 | * need to know the accurate state, use tracing_is_on() which is a little |
| 293 | * slower, but accurate. |
| 294 | */ |
Steven Rostedt | 9036990 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 295 | int tracing_is_enabled(void) |
| 296 | { |
Steven Rostedt (Red Hat) | 10246fa | 2013-07-01 15:58:24 -0400 | [diff] [blame] | 297 | /* |
| 298 | * For quick access (irqsoff uses this in fast path), just |
| 299 | * return the mirror variable of the state of the ring buffer. |
| 300 | * It's a little racy, but we don't really care. |
| 301 | */ |
| 302 | smp_rmb(); |
| 303 | return !global_trace.buffer_disabled; |
Steven Rostedt | 9036990 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 304 | } |
| 305 | |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 306 | /* |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 307 | * trace_buf_size is the size in bytes that is allocated |
| 308 | * for a buffer. Note, the number of bytes is always rounded |
| 309 | * to page size. |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 310 | * |
| 311 | * This number is purposely set to a low number of 16384. |
| 312 | * If the dump on oops happens, it will be much appreciated |
| 313 | * to not have to wait for all that output. Anyway this can be |
| 314 | * boot time and run time configurable. |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 315 | */ |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 316 | #define TRACE_BUF_SIZE_DEFAULT 1441792UL /* 16384 * 88 (sizeof(entry)) */ |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 317 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 318 | static unsigned long trace_buf_size = TRACE_BUF_SIZE_DEFAULT; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 319 | |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 320 | /* trace_types holds a link list of available tracers. */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 321 | static struct tracer *trace_types __read_mostly; |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 322 | |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 323 | /* |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 324 | * trace_types_lock is used to protect the trace_types list. |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 325 | */ |
Alexander Z Lam | a822741 | 2013-07-01 19:37:54 -0700 | [diff] [blame] | 326 | DEFINE_MUTEX(trace_types_lock); |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 327 | |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 328 | /* |
| 329 | * serialize the access of the ring buffer |
| 330 | * |
| 331 | * ring buffer serializes readers, but it is low level protection. |
| 332 | * The validity of the events (which returns by ring_buffer_peek() ..etc) |
| 333 | * are not protected by ring buffer. |
| 334 | * |
| 335 | * The content of events may become garbage if we allow other process consumes |
| 336 | * these events concurrently: |
| 337 | * A) the page of the consumed events may become a normal page |
| 338 | * (not reader page) in ring buffer, and this page will be rewrited |
| 339 | * by events producer. |
| 340 | * B) The page of the consumed events may become a page for splice_read, |
| 341 | * and this page will be returned to system. |
| 342 | * |
| 343 | * These primitives allow multi process access to different cpu ring buffer |
| 344 | * concurrently. |
| 345 | * |
| 346 | * These primitives don't distinguish read-only and read-consume access. |
| 347 | * Multi read-only access are also serialized. |
| 348 | */ |
| 349 | |
| 350 | #ifdef CONFIG_SMP |
| 351 | static DECLARE_RWSEM(all_cpu_access_lock); |
| 352 | static DEFINE_PER_CPU(struct mutex, cpu_access_lock); |
| 353 | |
| 354 | static inline void trace_access_lock(int cpu) |
| 355 | { |
Steven Rostedt | ae3b509 | 2013-01-23 15:22:59 -0500 | [diff] [blame] | 356 | if (cpu == RING_BUFFER_ALL_CPUS) { |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 357 | /* gain it for accessing the whole ring buffer. */ |
| 358 | down_write(&all_cpu_access_lock); |
| 359 | } else { |
| 360 | /* gain it for accessing a cpu ring buffer. */ |
| 361 | |
Steven Rostedt | ae3b509 | 2013-01-23 15:22:59 -0500 | [diff] [blame] | 362 | /* Firstly block other trace_access_lock(RING_BUFFER_ALL_CPUS). */ |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 363 | down_read(&all_cpu_access_lock); |
| 364 | |
| 365 | /* Secondly block other access to this @cpu ring buffer. */ |
| 366 | mutex_lock(&per_cpu(cpu_access_lock, cpu)); |
| 367 | } |
| 368 | } |
| 369 | |
| 370 | static inline void trace_access_unlock(int cpu) |
| 371 | { |
Steven Rostedt | ae3b509 | 2013-01-23 15:22:59 -0500 | [diff] [blame] | 372 | if (cpu == RING_BUFFER_ALL_CPUS) { |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 373 | up_write(&all_cpu_access_lock); |
| 374 | } else { |
| 375 | mutex_unlock(&per_cpu(cpu_access_lock, cpu)); |
| 376 | up_read(&all_cpu_access_lock); |
| 377 | } |
| 378 | } |
| 379 | |
| 380 | static inline void trace_access_lock_init(void) |
| 381 | { |
| 382 | int cpu; |
| 383 | |
| 384 | for_each_possible_cpu(cpu) |
| 385 | mutex_init(&per_cpu(cpu_access_lock, cpu)); |
| 386 | } |
| 387 | |
| 388 | #else |
| 389 | |
| 390 | static DEFINE_MUTEX(access_lock); |
| 391 | |
| 392 | static inline void trace_access_lock(int cpu) |
| 393 | { |
| 394 | (void)cpu; |
| 395 | mutex_lock(&access_lock); |
| 396 | } |
| 397 | |
| 398 | static inline void trace_access_unlock(int cpu) |
| 399 | { |
| 400 | (void)cpu; |
| 401 | mutex_unlock(&access_lock); |
| 402 | } |
| 403 | |
| 404 | static inline void trace_access_lock_init(void) |
| 405 | { |
| 406 | } |
| 407 | |
| 408 | #endif |
| 409 | |
Steven Rostedt | ee6bce5 | 2008-11-12 17:52:37 -0500 | [diff] [blame] | 410 | /* trace_flags holds trace_options default values */ |
Steven Rostedt | 12ef7d4 | 2008-11-12 17:52:38 -0500 | [diff] [blame] | 411 | unsigned long trace_flags = TRACE_ITER_PRINT_PARENT | TRACE_ITER_PRINTK | |
Steven Rostedt | a2a16d6 | 2009-03-24 23:17:58 -0400 | [diff] [blame] | 412 | TRACE_ITER_ANNOTATE | TRACE_ITER_CONTEXT_INFO | TRACE_ITER_SLEEP_TIME | |
Steven Rostedt | 77271ce | 2011-11-17 09:34:33 -0500 | [diff] [blame] | 413 | TRACE_ITER_GRAPH_TIME | TRACE_ITER_RECORD_CMD | TRACE_ITER_OVERWRITE | |
Steven Rostedt (Red Hat) | 328df47 | 2013-03-14 12:10:40 -0400 | [diff] [blame] | 414 | TRACE_ITER_IRQ_INFO | TRACE_ITER_MARKERS | TRACE_ITER_FUNCTION; |
Vaibhav Nagarnaik | e7e2ee8 | 2011-05-10 13:27:21 -0700 | [diff] [blame] | 415 | |
Steven Rostedt (Red Hat) | 5280bce | 2013-07-02 19:59:57 -0400 | [diff] [blame] | 416 | static void tracer_tracing_on(struct trace_array *tr) |
Steven Rostedt (Red Hat) | 10246fa | 2013-07-01 15:58:24 -0400 | [diff] [blame] | 417 | { |
| 418 | if (tr->trace_buffer.buffer) |
| 419 | ring_buffer_record_on(tr->trace_buffer.buffer); |
| 420 | /* |
| 421 | * This flag is looked at when buffers haven't been allocated |
| 422 | * yet, or by some tracers (like irqsoff), that just want to |
| 423 | * know if the ring buffer has been disabled, but it can handle |
| 424 | * races of where it gets disabled but we still do a record. |
| 425 | * As the check is in the fast path of the tracers, it is more |
| 426 | * important to be fast than accurate. |
| 427 | */ |
| 428 | tr->buffer_disabled = 0; |
| 429 | /* Make the flag seen by readers */ |
| 430 | smp_wmb(); |
| 431 | } |
| 432 | |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 433 | /** |
Steven Rostedt | 499e547 | 2012-02-22 15:50:28 -0500 | [diff] [blame] | 434 | * tracing_on - enable tracing buffers |
| 435 | * |
| 436 | * This function enables tracing buffers that may have been |
| 437 | * disabled with tracing_off. |
| 438 | */ |
| 439 | void tracing_on(void) |
| 440 | { |
Steven Rostedt (Red Hat) | 10246fa | 2013-07-01 15:58:24 -0400 | [diff] [blame] | 441 | tracer_tracing_on(&global_trace); |
Steven Rostedt | 499e547 | 2012-02-22 15:50:28 -0500 | [diff] [blame] | 442 | } |
| 443 | EXPORT_SYMBOL_GPL(tracing_on); |
| 444 | |
| 445 | /** |
Steven Rostedt (Red Hat) | 09ae723 | 2013-03-08 21:02:34 -0500 | [diff] [blame] | 446 | * __trace_puts - write a constant string into the trace buffer. |
| 447 | * @ip: The address of the caller |
| 448 | * @str: The constant string to write |
| 449 | * @size: The size of the string. |
| 450 | */ |
| 451 | int __trace_puts(unsigned long ip, const char *str, int size) |
| 452 | { |
| 453 | struct ring_buffer_event *event; |
| 454 | struct ring_buffer *buffer; |
| 455 | struct print_entry *entry; |
| 456 | unsigned long irq_flags; |
| 457 | int alloc; |
| 458 | |
Steven Rostedt (Red Hat) | 3132e10 | 2014-01-23 12:27:59 -0500 | [diff] [blame] | 459 | if (unlikely(tracing_selftest_running || tracing_disabled)) |
| 460 | return 0; |
| 461 | |
Steven Rostedt (Red Hat) | 09ae723 | 2013-03-08 21:02:34 -0500 | [diff] [blame] | 462 | alloc = sizeof(*entry) + size + 2; /* possible \n added */ |
| 463 | |
| 464 | local_save_flags(irq_flags); |
| 465 | buffer = global_trace.trace_buffer.buffer; |
| 466 | event = trace_buffer_lock_reserve(buffer, TRACE_PRINT, alloc, |
| 467 | irq_flags, preempt_count()); |
| 468 | if (!event) |
| 469 | return 0; |
| 470 | |
| 471 | entry = ring_buffer_event_data(event); |
| 472 | entry->ip = ip; |
| 473 | |
| 474 | memcpy(&entry->buf, str, size); |
| 475 | |
| 476 | /* Add a newline if necessary */ |
| 477 | if (entry->buf[size - 1] != '\n') { |
| 478 | entry->buf[size] = '\n'; |
| 479 | entry->buf[size + 1] = '\0'; |
| 480 | } else |
| 481 | entry->buf[size] = '\0'; |
| 482 | |
| 483 | __buffer_unlock_commit(buffer, event); |
| 484 | |
| 485 | return size; |
| 486 | } |
| 487 | EXPORT_SYMBOL_GPL(__trace_puts); |
| 488 | |
| 489 | /** |
| 490 | * __trace_bputs - write the pointer to a constant string into trace buffer |
| 491 | * @ip: The address of the caller |
| 492 | * @str: The constant string to write to the buffer to |
| 493 | */ |
| 494 | int __trace_bputs(unsigned long ip, const char *str) |
| 495 | { |
| 496 | struct ring_buffer_event *event; |
| 497 | struct ring_buffer *buffer; |
| 498 | struct bputs_entry *entry; |
| 499 | unsigned long irq_flags; |
| 500 | int size = sizeof(struct bputs_entry); |
| 501 | |
Steven Rostedt (Red Hat) | 3132e10 | 2014-01-23 12:27:59 -0500 | [diff] [blame] | 502 | if (unlikely(tracing_selftest_running || tracing_disabled)) |
| 503 | return 0; |
| 504 | |
Steven Rostedt (Red Hat) | 09ae723 | 2013-03-08 21:02:34 -0500 | [diff] [blame] | 505 | local_save_flags(irq_flags); |
| 506 | buffer = global_trace.trace_buffer.buffer; |
| 507 | event = trace_buffer_lock_reserve(buffer, TRACE_BPUTS, size, |
| 508 | irq_flags, preempt_count()); |
| 509 | if (!event) |
| 510 | return 0; |
| 511 | |
| 512 | entry = ring_buffer_event_data(event); |
| 513 | entry->ip = ip; |
| 514 | entry->str = str; |
| 515 | |
| 516 | __buffer_unlock_commit(buffer, event); |
| 517 | |
| 518 | return 1; |
| 519 | } |
| 520 | EXPORT_SYMBOL_GPL(__trace_bputs); |
| 521 | |
Steven Rostedt (Red Hat) | ad909e2 | 2013-03-06 21:45:37 -0500 | [diff] [blame] | 522 | #ifdef CONFIG_TRACER_SNAPSHOT |
| 523 | /** |
| 524 | * trace_snapshot - take a snapshot of the current buffer. |
| 525 | * |
| 526 | * This causes a swap between the snapshot buffer and the current live |
| 527 | * tracing buffer. You can use this to take snapshots of the live |
| 528 | * trace when some condition is triggered, but continue to trace. |
| 529 | * |
| 530 | * Note, make sure to allocate the snapshot with either |
| 531 | * a tracing_snapshot_alloc(), or by doing it manually |
| 532 | * with: echo 1 > /sys/kernel/debug/tracing/snapshot |
| 533 | * |
| 534 | * If the snapshot buffer is not allocated, it will stop tracing. |
| 535 | * Basically making a permanent snapshot. |
| 536 | */ |
| 537 | void tracing_snapshot(void) |
| 538 | { |
| 539 | struct trace_array *tr = &global_trace; |
| 540 | struct tracer *tracer = tr->current_trace; |
| 541 | unsigned long flags; |
| 542 | |
Steven Rostedt (Red Hat) | 1b22e38 | 2013-03-09 00:56:08 -0500 | [diff] [blame] | 543 | if (in_nmi()) { |
| 544 | internal_trace_puts("*** SNAPSHOT CALLED FROM NMI CONTEXT ***\n"); |
| 545 | internal_trace_puts("*** snapshot is being ignored ***\n"); |
| 546 | return; |
| 547 | } |
| 548 | |
Steven Rostedt (Red Hat) | ad909e2 | 2013-03-06 21:45:37 -0500 | [diff] [blame] | 549 | if (!tr->allocated_snapshot) { |
Steven Rostedt (Red Hat) | ca268da | 2013-03-09 00:40:58 -0500 | [diff] [blame] | 550 | internal_trace_puts("*** SNAPSHOT NOT ALLOCATED ***\n"); |
| 551 | internal_trace_puts("*** stopping trace here! ***\n"); |
Steven Rostedt (Red Hat) | ad909e2 | 2013-03-06 21:45:37 -0500 | [diff] [blame] | 552 | tracing_off(); |
| 553 | return; |
| 554 | } |
| 555 | |
| 556 | /* Note, snapshot can not be used when the tracer uses it */ |
| 557 | if (tracer->use_max_tr) { |
Steven Rostedt (Red Hat) | ca268da | 2013-03-09 00:40:58 -0500 | [diff] [blame] | 558 | internal_trace_puts("*** LATENCY TRACER ACTIVE ***\n"); |
| 559 | internal_trace_puts("*** Can not use snapshot (sorry) ***\n"); |
Steven Rostedt (Red Hat) | ad909e2 | 2013-03-06 21:45:37 -0500 | [diff] [blame] | 560 | return; |
| 561 | } |
| 562 | |
| 563 | local_irq_save(flags); |
| 564 | update_max_tr(tr, current, smp_processor_id()); |
| 565 | local_irq_restore(flags); |
| 566 | } |
Steven Rostedt (Red Hat) | 1b22e38 | 2013-03-09 00:56:08 -0500 | [diff] [blame] | 567 | EXPORT_SYMBOL_GPL(tracing_snapshot); |
Steven Rostedt (Red Hat) | ad909e2 | 2013-03-06 21:45:37 -0500 | [diff] [blame] | 568 | |
| 569 | static int resize_buffer_duplicate_size(struct trace_buffer *trace_buf, |
| 570 | struct trace_buffer *size_buf, int cpu_id); |
Steven Rostedt (Red Hat) | 3209cff | 2013-03-12 11:17:54 -0400 | [diff] [blame] | 571 | static void set_buffer_entries(struct trace_buffer *buf, unsigned long val); |
| 572 | |
| 573 | static int alloc_snapshot(struct trace_array *tr) |
| 574 | { |
| 575 | int ret; |
| 576 | |
| 577 | if (!tr->allocated_snapshot) { |
| 578 | |
| 579 | /* allocate spare buffer */ |
| 580 | ret = resize_buffer_duplicate_size(&tr->max_buffer, |
| 581 | &tr->trace_buffer, RING_BUFFER_ALL_CPUS); |
| 582 | if (ret < 0) |
| 583 | return ret; |
| 584 | |
| 585 | tr->allocated_snapshot = true; |
| 586 | } |
| 587 | |
| 588 | return 0; |
| 589 | } |
| 590 | |
| 591 | void free_snapshot(struct trace_array *tr) |
| 592 | { |
| 593 | /* |
| 594 | * We don't free the ring buffer. instead, resize it because |
| 595 | * The max_tr ring buffer has some state (e.g. ring->clock) and |
| 596 | * we want preserve it. |
| 597 | */ |
| 598 | ring_buffer_resize(tr->max_buffer.buffer, 1, RING_BUFFER_ALL_CPUS); |
| 599 | set_buffer_entries(&tr->max_buffer, 1); |
| 600 | tracing_reset_online_cpus(&tr->max_buffer); |
| 601 | tr->allocated_snapshot = false; |
| 602 | } |
Steven Rostedt (Red Hat) | ad909e2 | 2013-03-06 21:45:37 -0500 | [diff] [blame] | 603 | |
| 604 | /** |
Tom Zanussi | 93e31ff | 2013-10-24 08:59:26 -0500 | [diff] [blame] | 605 | * tracing_alloc_snapshot - allocate snapshot buffer. |
| 606 | * |
| 607 | * This only allocates the snapshot buffer if it isn't already |
| 608 | * allocated - it doesn't also take a snapshot. |
| 609 | * |
| 610 | * This is meant to be used in cases where the snapshot buffer needs |
| 611 | * to be set up for events that can't sleep but need to be able to |
| 612 | * trigger a snapshot. |
| 613 | */ |
| 614 | int tracing_alloc_snapshot(void) |
| 615 | { |
| 616 | struct trace_array *tr = &global_trace; |
| 617 | int ret; |
| 618 | |
| 619 | ret = alloc_snapshot(tr); |
| 620 | WARN_ON(ret < 0); |
| 621 | |
| 622 | return ret; |
| 623 | } |
| 624 | EXPORT_SYMBOL_GPL(tracing_alloc_snapshot); |
| 625 | |
| 626 | /** |
Steven Rostedt (Red Hat) | ad909e2 | 2013-03-06 21:45:37 -0500 | [diff] [blame] | 627 | * trace_snapshot_alloc - allocate and take a snapshot of the current buffer. |
| 628 | * |
| 629 | * This is similar to trace_snapshot(), but it will allocate the |
| 630 | * snapshot buffer if it isn't already allocated. Use this only |
| 631 | * where it is safe to sleep, as the allocation may sleep. |
| 632 | * |
| 633 | * This causes a swap between the snapshot buffer and the current live |
| 634 | * tracing buffer. You can use this to take snapshots of the live |
| 635 | * trace when some condition is triggered, but continue to trace. |
| 636 | */ |
| 637 | void tracing_snapshot_alloc(void) |
| 638 | { |
Steven Rostedt (Red Hat) | ad909e2 | 2013-03-06 21:45:37 -0500 | [diff] [blame] | 639 | int ret; |
| 640 | |
Tom Zanussi | 93e31ff | 2013-10-24 08:59:26 -0500 | [diff] [blame] | 641 | ret = tracing_alloc_snapshot(); |
| 642 | if (ret < 0) |
Steven Rostedt (Red Hat) | 3209cff | 2013-03-12 11:17:54 -0400 | [diff] [blame] | 643 | return; |
Steven Rostedt (Red Hat) | ad909e2 | 2013-03-06 21:45:37 -0500 | [diff] [blame] | 644 | |
| 645 | tracing_snapshot(); |
| 646 | } |
Steven Rostedt (Red Hat) | 1b22e38 | 2013-03-09 00:56:08 -0500 | [diff] [blame] | 647 | EXPORT_SYMBOL_GPL(tracing_snapshot_alloc); |
Steven Rostedt (Red Hat) | ad909e2 | 2013-03-06 21:45:37 -0500 | [diff] [blame] | 648 | #else |
| 649 | void tracing_snapshot(void) |
| 650 | { |
| 651 | WARN_ONCE(1, "Snapshot feature not enabled, but internal snapshot used"); |
| 652 | } |
Steven Rostedt (Red Hat) | 1b22e38 | 2013-03-09 00:56:08 -0500 | [diff] [blame] | 653 | EXPORT_SYMBOL_GPL(tracing_snapshot); |
Tom Zanussi | 93e31ff | 2013-10-24 08:59:26 -0500 | [diff] [blame] | 654 | int tracing_alloc_snapshot(void) |
| 655 | { |
| 656 | WARN_ONCE(1, "Snapshot feature not enabled, but snapshot allocation used"); |
| 657 | return -ENODEV; |
| 658 | } |
| 659 | EXPORT_SYMBOL_GPL(tracing_alloc_snapshot); |
Steven Rostedt (Red Hat) | ad909e2 | 2013-03-06 21:45:37 -0500 | [diff] [blame] | 660 | void tracing_snapshot_alloc(void) |
| 661 | { |
| 662 | /* Give warning */ |
| 663 | tracing_snapshot(); |
| 664 | } |
Steven Rostedt (Red Hat) | 1b22e38 | 2013-03-09 00:56:08 -0500 | [diff] [blame] | 665 | EXPORT_SYMBOL_GPL(tracing_snapshot_alloc); |
Steven Rostedt (Red Hat) | ad909e2 | 2013-03-06 21:45:37 -0500 | [diff] [blame] | 666 | #endif /* CONFIG_TRACER_SNAPSHOT */ |
| 667 | |
Steven Rostedt (Red Hat) | 5280bce | 2013-07-02 19:59:57 -0400 | [diff] [blame] | 668 | static void tracer_tracing_off(struct trace_array *tr) |
Steven Rostedt (Red Hat) | 10246fa | 2013-07-01 15:58:24 -0400 | [diff] [blame] | 669 | { |
| 670 | if (tr->trace_buffer.buffer) |
| 671 | ring_buffer_record_off(tr->trace_buffer.buffer); |
| 672 | /* |
| 673 | * This flag is looked at when buffers haven't been allocated |
| 674 | * yet, or by some tracers (like irqsoff), that just want to |
| 675 | * know if the ring buffer has been disabled, but it can handle |
| 676 | * races of where it gets disabled but we still do a record. |
| 677 | * As the check is in the fast path of the tracers, it is more |
| 678 | * important to be fast than accurate. |
| 679 | */ |
| 680 | tr->buffer_disabled = 1; |
| 681 | /* Make the flag seen by readers */ |
| 682 | smp_wmb(); |
| 683 | } |
| 684 | |
Steven Rostedt | 499e547 | 2012-02-22 15:50:28 -0500 | [diff] [blame] | 685 | /** |
| 686 | * tracing_off - turn off tracing buffers |
| 687 | * |
| 688 | * This function stops the tracing buffers from recording data. |
| 689 | * It does not disable any overhead the tracers themselves may |
| 690 | * be causing. This function simply causes all recording to |
| 691 | * the ring buffers to fail. |
| 692 | */ |
| 693 | void tracing_off(void) |
| 694 | { |
Steven Rostedt (Red Hat) | 10246fa | 2013-07-01 15:58:24 -0400 | [diff] [blame] | 695 | tracer_tracing_off(&global_trace); |
Steven Rostedt | 499e547 | 2012-02-22 15:50:28 -0500 | [diff] [blame] | 696 | } |
| 697 | EXPORT_SYMBOL_GPL(tracing_off); |
| 698 | |
Steven Rostedt (Red Hat) | de7edd3 | 2013-06-14 16:21:43 -0400 | [diff] [blame] | 699 | void disable_trace_on_warning(void) |
| 700 | { |
| 701 | if (__disable_trace_on_warning) |
| 702 | tracing_off(); |
| 703 | } |
| 704 | |
Steven Rostedt | 499e547 | 2012-02-22 15:50:28 -0500 | [diff] [blame] | 705 | /** |
Steven Rostedt (Red Hat) | 10246fa | 2013-07-01 15:58:24 -0400 | [diff] [blame] | 706 | * tracer_tracing_is_on - show real state of ring buffer enabled |
| 707 | * @tr : the trace array to know if ring buffer is enabled |
| 708 | * |
| 709 | * Shows real state of the ring buffer if it is enabled or not. |
| 710 | */ |
Steven Rostedt (Red Hat) | 5280bce | 2013-07-02 19:59:57 -0400 | [diff] [blame] | 711 | static int tracer_tracing_is_on(struct trace_array *tr) |
Steven Rostedt (Red Hat) | 10246fa | 2013-07-01 15:58:24 -0400 | [diff] [blame] | 712 | { |
| 713 | if (tr->trace_buffer.buffer) |
| 714 | return ring_buffer_record_is_on(tr->trace_buffer.buffer); |
| 715 | return !tr->buffer_disabled; |
| 716 | } |
| 717 | |
Steven Rostedt | 499e547 | 2012-02-22 15:50:28 -0500 | [diff] [blame] | 718 | /** |
| 719 | * tracing_is_on - show state of ring buffers enabled |
| 720 | */ |
| 721 | int tracing_is_on(void) |
| 722 | { |
Steven Rostedt (Red Hat) | 10246fa | 2013-07-01 15:58:24 -0400 | [diff] [blame] | 723 | return tracer_tracing_is_on(&global_trace); |
Steven Rostedt | 499e547 | 2012-02-22 15:50:28 -0500 | [diff] [blame] | 724 | } |
| 725 | EXPORT_SYMBOL_GPL(tracing_is_on); |
| 726 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 727 | static int __init set_buf_size(char *str) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 728 | { |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 729 | unsigned long buf_size; |
Steven Rostedt | c6caeeb | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 730 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 731 | if (!str) |
| 732 | return 0; |
Li Zefan | 9d612be | 2009-06-24 17:33:15 +0800 | [diff] [blame] | 733 | buf_size = memparse(str, &str); |
Steven Rostedt | c6caeeb | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 734 | /* nr_entries can not be zero */ |
Li Zefan | 9d612be | 2009-06-24 17:33:15 +0800 | [diff] [blame] | 735 | if (buf_size == 0) |
Steven Rostedt | c6caeeb | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 736 | return 0; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 737 | trace_buf_size = buf_size; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 738 | return 1; |
| 739 | } |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 740 | __setup("trace_buf_size=", set_buf_size); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 741 | |
Tim Bird | 0e95017 | 2010-02-25 15:36:43 -0800 | [diff] [blame] | 742 | static int __init set_tracing_thresh(char *str) |
| 743 | { |
Wang Tianhong | 87abb3b | 2012-08-02 14:02:00 +0800 | [diff] [blame] | 744 | unsigned long threshold; |
Tim Bird | 0e95017 | 2010-02-25 15:36:43 -0800 | [diff] [blame] | 745 | int ret; |
| 746 | |
| 747 | if (!str) |
| 748 | return 0; |
Daniel Walter | bcd83ea | 2012-09-26 22:08:38 +0200 | [diff] [blame] | 749 | ret = kstrtoul(str, 0, &threshold); |
Tim Bird | 0e95017 | 2010-02-25 15:36:43 -0800 | [diff] [blame] | 750 | if (ret < 0) |
| 751 | return 0; |
Wang Tianhong | 87abb3b | 2012-08-02 14:02:00 +0800 | [diff] [blame] | 752 | tracing_thresh = threshold * 1000; |
Tim Bird | 0e95017 | 2010-02-25 15:36:43 -0800 | [diff] [blame] | 753 | return 1; |
| 754 | } |
| 755 | __setup("tracing_thresh=", set_tracing_thresh); |
| 756 | |
Steven Rostedt | 57f50be | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 757 | unsigned long nsecs_to_usecs(unsigned long nsecs) |
| 758 | { |
| 759 | return nsecs / 1000; |
| 760 | } |
| 761 | |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 762 | /* These must match the bit postions in trace_iterator_flags */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 763 | static const char *trace_options[] = { |
| 764 | "print-parent", |
| 765 | "sym-offset", |
| 766 | "sym-addr", |
| 767 | "verbose", |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 768 | "raw", |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 769 | "hex", |
Ingo Molnar | cb0f12a | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 770 | "bin", |
Soeren Sandmann Pedersen | 2a2cc8f | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 771 | "block", |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 772 | "stacktrace", |
Ingo Molnar | 5e1607a | 2009-03-05 10:24:48 +0100 | [diff] [blame] | 773 | "trace_printk", |
Steven Rostedt | b2a866f | 2008-11-03 23:15:57 -0500 | [diff] [blame] | 774 | "ftrace_preempt", |
Steven Rostedt | 9f029e8 | 2008-11-12 15:24:24 -0500 | [diff] [blame] | 775 | "branch", |
Steven Rostedt | 12ef7d4 | 2008-11-12 17:52:38 -0500 | [diff] [blame] | 776 | "annotate", |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 777 | "userstacktrace", |
Török Edwin | b54d3de | 2008-11-22 13:28:48 +0200 | [diff] [blame] | 778 | "sym-userobj", |
Frederic Weisbecker | 66896a8 | 2008-12-13 20:18:13 +0100 | [diff] [blame] | 779 | "printk-msg-only", |
Frederic Weisbecker | c4a8e8b | 2009-02-02 20:29:21 -0200 | [diff] [blame] | 780 | "context-info", |
Steven Rostedt | c032ef64 | 2009-03-04 20:34:24 -0500 | [diff] [blame] | 781 | "latency-format", |
Steven Rostedt | be6f164 | 2009-03-24 11:06:24 -0400 | [diff] [blame] | 782 | "sleep-time", |
Steven Rostedt | a2a16d6 | 2009-03-24 23:17:58 -0400 | [diff] [blame] | 783 | "graph-time", |
Li Zefan | e870e9a | 2010-07-02 11:07:32 +0800 | [diff] [blame] | 784 | "record-cmd", |
David Sharp | 750912f | 2010-12-08 13:46:47 -0800 | [diff] [blame] | 785 | "overwrite", |
Steven Rostedt | cf30cf6 | 2011-06-14 22:44:07 -0400 | [diff] [blame] | 786 | "disable_on_free", |
Steven Rostedt | 77271ce | 2011-11-17 09:34:33 -0500 | [diff] [blame] | 787 | "irq-info", |
Mandeep Singh Baines | 5224c3a | 2012-09-07 18:12:19 -0700 | [diff] [blame] | 788 | "markers", |
Steven Rostedt (Red Hat) | 328df47 | 2013-03-14 12:10:40 -0400 | [diff] [blame] | 789 | "function-trace", |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 790 | NULL |
| 791 | }; |
| 792 | |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 793 | static struct { |
| 794 | u64 (*func)(void); |
| 795 | const char *name; |
David Sharp | 8be0709 | 2012-11-13 12:18:22 -0800 | [diff] [blame] | 796 | int in_ns; /* is this clock in nanoseconds? */ |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 797 | } trace_clocks[] = { |
David Sharp | 8be0709 | 2012-11-13 12:18:22 -0800 | [diff] [blame] | 798 | { trace_clock_local, "local", 1 }, |
| 799 | { trace_clock_global, "global", 1 }, |
| 800 | { trace_clock_counter, "counter", 0 }, |
Steven Rostedt (Red Hat) | 8aacf01 | 2013-03-14 13:13:45 -0400 | [diff] [blame] | 801 | { trace_clock_jiffies, "uptime", 1 }, |
Steven Rostedt (Red Hat) | 76f1191 | 2013-03-14 17:53:25 -0400 | [diff] [blame] | 802 | { trace_clock, "perf", 1 }, |
David Sharp | 8cbd9cc | 2012-11-13 12:18:21 -0800 | [diff] [blame] | 803 | ARCH_TRACE_CLOCKS |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 804 | }; |
| 805 | |
jolsa@redhat.com | b63f39e | 2009-09-11 17:29:27 +0200 | [diff] [blame] | 806 | /* |
| 807 | * trace_parser_get_init - gets the buffer for trace parser |
| 808 | */ |
| 809 | int trace_parser_get_init(struct trace_parser *parser, int size) |
| 810 | { |
| 811 | memset(parser, 0, sizeof(*parser)); |
| 812 | |
| 813 | parser->buffer = kmalloc(size, GFP_KERNEL); |
| 814 | if (!parser->buffer) |
| 815 | return 1; |
| 816 | |
| 817 | parser->size = size; |
| 818 | return 0; |
| 819 | } |
| 820 | |
| 821 | /* |
| 822 | * trace_parser_put - frees the buffer for trace parser |
| 823 | */ |
| 824 | void trace_parser_put(struct trace_parser *parser) |
| 825 | { |
| 826 | kfree(parser->buffer); |
| 827 | } |
| 828 | |
| 829 | /* |
| 830 | * trace_get_user - reads the user input string separated by space |
| 831 | * (matched by isspace(ch)) |
| 832 | * |
| 833 | * For each string found the 'struct trace_parser' is updated, |
| 834 | * and the function returns. |
| 835 | * |
| 836 | * Returns number of bytes read. |
| 837 | * |
| 838 | * See kernel/trace/trace.h for 'struct trace_parser' details. |
| 839 | */ |
| 840 | int trace_get_user(struct trace_parser *parser, const char __user *ubuf, |
| 841 | size_t cnt, loff_t *ppos) |
| 842 | { |
| 843 | char ch; |
| 844 | size_t read = 0; |
| 845 | ssize_t ret; |
| 846 | |
| 847 | if (!*ppos) |
| 848 | trace_parser_clear(parser); |
| 849 | |
| 850 | ret = get_user(ch, ubuf++); |
| 851 | if (ret) |
| 852 | goto out; |
| 853 | |
| 854 | read++; |
| 855 | cnt--; |
| 856 | |
| 857 | /* |
| 858 | * The parser is not finished with the last write, |
| 859 | * continue reading the user input without skipping spaces. |
| 860 | */ |
| 861 | if (!parser->cont) { |
| 862 | /* skip white space */ |
| 863 | while (cnt && isspace(ch)) { |
| 864 | ret = get_user(ch, ubuf++); |
| 865 | if (ret) |
| 866 | goto out; |
| 867 | read++; |
| 868 | cnt--; |
| 869 | } |
| 870 | |
| 871 | /* only spaces were written */ |
| 872 | if (isspace(ch)) { |
| 873 | *ppos += read; |
| 874 | ret = read; |
| 875 | goto out; |
| 876 | } |
| 877 | |
| 878 | parser->idx = 0; |
| 879 | } |
| 880 | |
| 881 | /* read the non-space input */ |
| 882 | while (cnt && !isspace(ch)) { |
Li Zefan | 3c235a3 | 2009-09-22 13:51:54 +0800 | [diff] [blame] | 883 | if (parser->idx < parser->size - 1) |
jolsa@redhat.com | b63f39e | 2009-09-11 17:29:27 +0200 | [diff] [blame] | 884 | parser->buffer[parser->idx++] = ch; |
| 885 | else { |
| 886 | ret = -EINVAL; |
| 887 | goto out; |
| 888 | } |
| 889 | ret = get_user(ch, ubuf++); |
| 890 | if (ret) |
| 891 | goto out; |
| 892 | read++; |
| 893 | cnt--; |
| 894 | } |
| 895 | |
| 896 | /* We either got finished input or we have to wait for another call. */ |
| 897 | if (isspace(ch)) { |
| 898 | parser->buffer[parser->idx] = 0; |
| 899 | parser->cont = false; |
Steven Rostedt | 057db84 | 2013-10-09 22:23:23 -0400 | [diff] [blame] | 900 | } else if (parser->idx < parser->size - 1) { |
jolsa@redhat.com | b63f39e | 2009-09-11 17:29:27 +0200 | [diff] [blame] | 901 | parser->cont = true; |
| 902 | parser->buffer[parser->idx++] = ch; |
Steven Rostedt | 057db84 | 2013-10-09 22:23:23 -0400 | [diff] [blame] | 903 | } else { |
| 904 | ret = -EINVAL; |
| 905 | goto out; |
jolsa@redhat.com | b63f39e | 2009-09-11 17:29:27 +0200 | [diff] [blame] | 906 | } |
| 907 | |
| 908 | *ppos += read; |
| 909 | ret = read; |
| 910 | |
| 911 | out: |
| 912 | return ret; |
| 913 | } |
| 914 | |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 915 | ssize_t trace_seq_to_user(struct trace_seq *s, char __user *ubuf, size_t cnt) |
| 916 | { |
| 917 | int len; |
| 918 | int ret; |
| 919 | |
Steven Rostedt | 2dc5d12 | 2009-03-04 19:10:05 -0500 | [diff] [blame] | 920 | if (!cnt) |
| 921 | return 0; |
| 922 | |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 923 | if (s->len <= s->readpos) |
| 924 | return -EBUSY; |
| 925 | |
| 926 | len = s->len - s->readpos; |
| 927 | if (cnt > len) |
| 928 | cnt = len; |
| 929 | ret = copy_to_user(ubuf, s->buffer + s->readpos, cnt); |
Steven Rostedt | 2dc5d12 | 2009-03-04 19:10:05 -0500 | [diff] [blame] | 930 | if (ret == cnt) |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 931 | return -EFAULT; |
| 932 | |
Steven Rostedt | 2dc5d12 | 2009-03-04 19:10:05 -0500 | [diff] [blame] | 933 | cnt -= ret; |
| 934 | |
Steven Rostedt | e74da52 | 2009-03-04 20:31:11 -0500 | [diff] [blame] | 935 | s->readpos += cnt; |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 936 | return cnt; |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 937 | } |
| 938 | |
Dmitri Vorobiev | b8b9426 | 2009-03-22 19:11:11 +0200 | [diff] [blame] | 939 | static ssize_t trace_seq_to_buffer(struct trace_seq *s, void *buf, size_t cnt) |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 940 | { |
| 941 | int len; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 942 | |
| 943 | if (s->len <= s->readpos) |
| 944 | return -EBUSY; |
| 945 | |
| 946 | len = s->len - s->readpos; |
| 947 | if (cnt > len) |
| 948 | cnt = len; |
Dan Carpenter | 5a26c8f | 2012-04-20 09:31:45 +0300 | [diff] [blame] | 949 | memcpy(buf, s->buffer + s->readpos, cnt); |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 950 | |
Steven Rostedt | e74da52 | 2009-03-04 20:31:11 -0500 | [diff] [blame] | 951 | s->readpos += cnt; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 952 | return cnt; |
| 953 | } |
| 954 | |
Steven Rostedt | 5d4a9db | 2009-08-27 16:52:21 -0400 | [diff] [blame] | 955 | /* |
| 956 | * ftrace_max_lock is used to protect the swapping of buffers |
| 957 | * when taking a max snapshot. The buffers themselves are |
| 958 | * protected by per_cpu spinlocks. But the action of the swap |
| 959 | * needs its own lock. |
| 960 | * |
Thomas Gleixner | 445c895 | 2009-12-02 19:49:50 +0100 | [diff] [blame] | 961 | * This is defined as a arch_spinlock_t in order to help |
Steven Rostedt | 5d4a9db | 2009-08-27 16:52:21 -0400 | [diff] [blame] | 962 | * with performance when lockdep debugging is enabled. |
| 963 | * |
| 964 | * It is also used in other places outside the update_max_tr |
| 965 | * so it needs to be defined outside of the |
| 966 | * CONFIG_TRACER_MAX_TRACE. |
| 967 | */ |
Thomas Gleixner | 445c895 | 2009-12-02 19:49:50 +0100 | [diff] [blame] | 968 | static arch_spinlock_t ftrace_max_lock = |
Thomas Gleixner | edc35bd | 2009-12-03 12:38:57 +0100 | [diff] [blame] | 969 | (arch_spinlock_t)__ARCH_SPIN_LOCK_UNLOCKED; |
Steven Rostedt | 5d4a9db | 2009-08-27 16:52:21 -0400 | [diff] [blame] | 970 | |
Tim Bird | 0e95017 | 2010-02-25 15:36:43 -0800 | [diff] [blame] | 971 | unsigned long __read_mostly tracing_thresh; |
| 972 | |
Steven Rostedt | 5d4a9db | 2009-08-27 16:52:21 -0400 | [diff] [blame] | 973 | #ifdef CONFIG_TRACER_MAX_TRACE |
| 974 | unsigned long __read_mostly tracing_max_latency; |
Steven Rostedt | 5d4a9db | 2009-08-27 16:52:21 -0400 | [diff] [blame] | 975 | |
| 976 | /* |
| 977 | * Copy the new maximum trace into the separate maximum-trace |
| 978 | * structure. (this way the maximum trace is permanently saved, |
| 979 | * for later retrieval via /sys/kernel/debug/tracing/latency_trace) |
| 980 | */ |
| 981 | static void |
| 982 | __update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu) |
| 983 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 984 | struct trace_buffer *trace_buf = &tr->trace_buffer; |
| 985 | struct trace_buffer *max_buf = &tr->max_buffer; |
| 986 | struct trace_array_cpu *data = per_cpu_ptr(trace_buf->data, cpu); |
| 987 | struct trace_array_cpu *max_data = per_cpu_ptr(max_buf->data, cpu); |
Steven Rostedt | 5d4a9db | 2009-08-27 16:52:21 -0400 | [diff] [blame] | 988 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 989 | max_buf->cpu = cpu; |
| 990 | max_buf->time_start = data->preempt_timestamp; |
Steven Rostedt | 5d4a9db | 2009-08-27 16:52:21 -0400 | [diff] [blame] | 991 | |
Steven Rostedt | 8248ac0 | 2009-09-02 12:27:41 -0400 | [diff] [blame] | 992 | max_data->saved_latency = tracing_max_latency; |
| 993 | max_data->critical_start = data->critical_start; |
| 994 | max_data->critical_end = data->critical_end; |
Steven Rostedt | 5d4a9db | 2009-08-27 16:52:21 -0400 | [diff] [blame] | 995 | |
Arnaldo Carvalho de Melo | 1acaa1b | 2010-03-05 18:23:50 -0300 | [diff] [blame] | 996 | memcpy(max_data->comm, tsk->comm, TASK_COMM_LEN); |
Steven Rostedt | 8248ac0 | 2009-09-02 12:27:41 -0400 | [diff] [blame] | 997 | max_data->pid = tsk->pid; |
Steven Rostedt (Red Hat) | f17a519 | 2013-05-30 21:10:37 -0400 | [diff] [blame] | 998 | /* |
| 999 | * If tsk == current, then use current_uid(), as that does not use |
| 1000 | * RCU. The irq tracer can be called out of RCU scope. |
| 1001 | */ |
| 1002 | if (tsk == current) |
| 1003 | max_data->uid = current_uid(); |
| 1004 | else |
| 1005 | max_data->uid = task_uid(tsk); |
| 1006 | |
Steven Rostedt | 8248ac0 | 2009-09-02 12:27:41 -0400 | [diff] [blame] | 1007 | max_data->nice = tsk->static_prio - 20 - MAX_RT_PRIO; |
| 1008 | max_data->policy = tsk->policy; |
| 1009 | max_data->rt_priority = tsk->rt_priority; |
Steven Rostedt | 5d4a9db | 2009-08-27 16:52:21 -0400 | [diff] [blame] | 1010 | |
| 1011 | /* record this tasks comm */ |
| 1012 | tracing_record_cmdline(tsk); |
| 1013 | } |
| 1014 | |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 1015 | /** |
| 1016 | * update_max_tr - snapshot all trace buffers from global_trace to max_tr |
| 1017 | * @tr: tracer |
| 1018 | * @tsk: the task with the latency |
| 1019 | * @cpu: The cpu that initiated the trace. |
| 1020 | * |
| 1021 | * Flip the buffers between the @tr and the max_tr and record information |
| 1022 | * about which task was the cause of this latency. |
| 1023 | */ |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1024 | void |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1025 | update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu) |
| 1026 | { |
Steven Rostedt (Red Hat) | 2721e72 | 2013-03-12 11:32:32 -0400 | [diff] [blame] | 1027 | struct ring_buffer *buf; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1028 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 1029 | if (tr->stop_count) |
Steven Rostedt | b8de7bd1 | 2009-08-31 22:32:27 -0400 | [diff] [blame] | 1030 | return; |
| 1031 | |
Steven Rostedt | 4c11d7a | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1032 | WARN_ON_ONCE(!irqs_disabled()); |
Steven Rostedt | 34600f0 | 2013-01-22 13:35:11 -0500 | [diff] [blame] | 1033 | |
Steven Rostedt (Red Hat) | 45ad21c | 2013-03-05 18:25:02 -0500 | [diff] [blame] | 1034 | if (!tr->allocated_snapshot) { |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 1035 | /* Only the nop tracer should hit this when disabling */ |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 1036 | WARN_ON_ONCE(tr->current_trace != &nop_trace); |
KOSAKI Motohiro | ef710e1 | 2010-07-01 14:34:35 +0900 | [diff] [blame] | 1037 | return; |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 1038 | } |
Steven Rostedt | 34600f0 | 2013-01-22 13:35:11 -0500 | [diff] [blame] | 1039 | |
Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 1040 | arch_spin_lock(&ftrace_max_lock); |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1041 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1042 | buf = tr->trace_buffer.buffer; |
| 1043 | tr->trace_buffer.buffer = tr->max_buffer.buffer; |
| 1044 | tr->max_buffer.buffer = buf; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1045 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1046 | __update_max_tr(tr, tsk, cpu); |
Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 1047 | arch_spin_unlock(&ftrace_max_lock); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1048 | } |
| 1049 | |
| 1050 | /** |
| 1051 | * update_max_tr_single - only copy one trace over, and reset the rest |
| 1052 | * @tr - tracer |
| 1053 | * @tsk - task with the latency |
| 1054 | * @cpu - the cpu of the buffer to copy. |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 1055 | * |
| 1056 | * Flip the trace of a single CPU buffer between the @tr and the max_tr. |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1057 | */ |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1058 | void |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1059 | update_max_tr_single(struct trace_array *tr, struct task_struct *tsk, int cpu) |
| 1060 | { |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1061 | int ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1062 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 1063 | if (tr->stop_count) |
Steven Rostedt | b8de7bd1 | 2009-08-31 22:32:27 -0400 | [diff] [blame] | 1064 | return; |
| 1065 | |
Steven Rostedt | 4c11d7a | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1066 | WARN_ON_ONCE(!irqs_disabled()); |
Steven Rostedt | 6c24499 | 2013-04-29 20:08:14 -0400 | [diff] [blame] | 1067 | if (!tr->allocated_snapshot) { |
Steven Rostedt (Red Hat) | 2930e04 | 2013-03-26 17:33:00 -0400 | [diff] [blame] | 1068 | /* Only the nop tracer should hit this when disabling */ |
Linus Torvalds | 9e8529a | 2013-04-29 13:55:38 -0700 | [diff] [blame] | 1069 | WARN_ON_ONCE(tr->current_trace != &nop_trace); |
KOSAKI Motohiro | ef710e1 | 2010-07-01 14:34:35 +0900 | [diff] [blame] | 1070 | return; |
Steven Rostedt (Red Hat) | 2930e04 | 2013-03-26 17:33:00 -0400 | [diff] [blame] | 1071 | } |
KOSAKI Motohiro | ef710e1 | 2010-07-01 14:34:35 +0900 | [diff] [blame] | 1072 | |
Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 1073 | arch_spin_lock(&ftrace_max_lock); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1074 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1075 | ret = ring_buffer_swap_cpu(tr->max_buffer.buffer, tr->trace_buffer.buffer, cpu); |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1076 | |
Steven Rostedt | e8165dbb | 2009-09-03 19:13:05 -0400 | [diff] [blame] | 1077 | if (ret == -EBUSY) { |
| 1078 | /* |
| 1079 | * We failed to swap the buffer due to a commit taking |
| 1080 | * place on this CPU. We fail to record, but we reset |
| 1081 | * the max trace buffer (no one writes directly to it) |
| 1082 | * and flag that it failed. |
| 1083 | */ |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1084 | trace_array_printk_buf(tr->max_buffer.buffer, _THIS_IP_, |
Steven Rostedt | e8165dbb | 2009-09-03 19:13:05 -0400 | [diff] [blame] | 1085 | "Failed to swap buffers due to commit in progress\n"); |
| 1086 | } |
| 1087 | |
Steven Rostedt | e8165dbb | 2009-09-03 19:13:05 -0400 | [diff] [blame] | 1088 | WARN_ON_ONCE(ret && ret != -EAGAIN && ret != -EBUSY); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1089 | |
| 1090 | __update_max_tr(tr, tsk, cpu); |
Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 1091 | arch_spin_unlock(&ftrace_max_lock); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1092 | } |
Steven Rostedt | 5d4a9db | 2009-08-27 16:52:21 -0400 | [diff] [blame] | 1093 | #endif /* CONFIG_TRACER_MAX_TRACE */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1094 | |
Steven Rostedt | 0d5c6e1 | 2012-11-01 20:54:21 -0400 | [diff] [blame] | 1095 | static void default_wait_pipe(struct trace_iterator *iter) |
| 1096 | { |
Steven Rostedt (Red Hat) | 1569345 | 2013-02-28 19:59:17 -0500 | [diff] [blame] | 1097 | /* Iterators are static, they should be filled or empty */ |
| 1098 | if (trace_buffer_iter(iter, iter->cpu_file)) |
| 1099 | return; |
Steven Rostedt | 0d5c6e1 | 2012-11-01 20:54:21 -0400 | [diff] [blame] | 1100 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1101 | ring_buffer_wait(iter->trace_buffer->buffer, iter->cpu_file); |
Steven Rostedt | 0d5c6e1 | 2012-11-01 20:54:21 -0400 | [diff] [blame] | 1102 | } |
| 1103 | |
Steven Rostedt (Red Hat) | f4e781c | 2013-03-07 11:10:56 -0500 | [diff] [blame] | 1104 | #ifdef CONFIG_FTRACE_STARTUP_TEST |
| 1105 | static int run_tracer_selftest(struct tracer *type) |
| 1106 | { |
| 1107 | struct trace_array *tr = &global_trace; |
| 1108 | struct tracer *saved_tracer = tr->current_trace; |
| 1109 | int ret; |
| 1110 | |
| 1111 | if (!type->selftest || tracing_selftest_disabled) |
| 1112 | return 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1113 | |
| 1114 | /* |
Steven Rostedt (Red Hat) | f4e781c | 2013-03-07 11:10:56 -0500 | [diff] [blame] | 1115 | * Run a selftest on this tracer. |
| 1116 | * Here we reset the trace buffer, and set the current |
| 1117 | * tracer to be this tracer. The tracer can then run some |
| 1118 | * internal tracing to verify that everything is in order. |
| 1119 | * If we fail, we do not register this tracer. |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 1120 | */ |
Steven Rostedt (Red Hat) | f4e781c | 2013-03-07 11:10:56 -0500 | [diff] [blame] | 1121 | tracing_reset_online_cpus(&tr->trace_buffer); |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 1122 | |
Steven Rostedt (Red Hat) | f4e781c | 2013-03-07 11:10:56 -0500 | [diff] [blame] | 1123 | tr->current_trace = type; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1124 | |
Steven Rostedt (Red Hat) | f4e781c | 2013-03-07 11:10:56 -0500 | [diff] [blame] | 1125 | #ifdef CONFIG_TRACER_MAX_TRACE |
| 1126 | if (type->use_max_tr) { |
| 1127 | /* If we expanded the buffers, make sure the max is expanded too */ |
| 1128 | if (ring_buffer_expanded) |
| 1129 | ring_buffer_resize(tr->max_buffer.buffer, trace_buf_size, |
| 1130 | RING_BUFFER_ALL_CPUS); |
| 1131 | tr->allocated_snapshot = true; |
| 1132 | } |
| 1133 | #endif |
| 1134 | |
| 1135 | /* the test is responsible for initializing and enabling */ |
| 1136 | pr_info("Testing tracer %s: ", type->name); |
| 1137 | ret = type->selftest(type, tr); |
| 1138 | /* the test is responsible for resetting too */ |
| 1139 | tr->current_trace = saved_tracer; |
| 1140 | if (ret) { |
| 1141 | printk(KERN_CONT "FAILED!\n"); |
| 1142 | /* Add the warning after printing 'FAILED' */ |
| 1143 | WARN_ON(1); |
| 1144 | return -1; |
| 1145 | } |
| 1146 | /* Only reset on passing, to avoid touching corrupted buffers */ |
| 1147 | tracing_reset_online_cpus(&tr->trace_buffer); |
| 1148 | |
| 1149 | #ifdef CONFIG_TRACER_MAX_TRACE |
| 1150 | if (type->use_max_tr) { |
| 1151 | tr->allocated_snapshot = false; |
| 1152 | |
| 1153 | /* Shrink the max buffer again */ |
| 1154 | if (ring_buffer_expanded) |
| 1155 | ring_buffer_resize(tr->max_buffer.buffer, 1, |
| 1156 | RING_BUFFER_ALL_CPUS); |
| 1157 | } |
| 1158 | #endif |
| 1159 | |
| 1160 | printk(KERN_CONT "PASSED\n"); |
| 1161 | return 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1162 | } |
Steven Rostedt (Red Hat) | f4e781c | 2013-03-07 11:10:56 -0500 | [diff] [blame] | 1163 | #else |
| 1164 | static inline int run_tracer_selftest(struct tracer *type) |
| 1165 | { |
| 1166 | return 0; |
| 1167 | } |
| 1168 | #endif /* CONFIG_FTRACE_STARTUP_TEST */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1169 | |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 1170 | /** |
| 1171 | * register_tracer - register a tracer with the ftrace system. |
| 1172 | * @type - the plugin for the tracer |
| 1173 | * |
| 1174 | * Register a new plugin tracer. |
| 1175 | */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1176 | int register_tracer(struct tracer *type) |
| 1177 | { |
| 1178 | struct tracer *t; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1179 | int ret = 0; |
| 1180 | |
| 1181 | if (!type->name) { |
| 1182 | pr_info("Tracer must have a name\n"); |
| 1183 | return -1; |
| 1184 | } |
| 1185 | |
Dan Carpenter | 24a461d | 2010-07-10 12:06:44 +0200 | [diff] [blame] | 1186 | if (strlen(type->name) >= MAX_TRACER_SIZE) { |
Li Zefan | ee6c2c1 | 2009-09-18 14:06:47 +0800 | [diff] [blame] | 1187 | pr_info("Tracer has a name longer than %d\n", MAX_TRACER_SIZE); |
| 1188 | return -1; |
| 1189 | } |
| 1190 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1191 | mutex_lock(&trace_types_lock); |
Ingo Molnar | 86fa2f6 | 2008-11-19 10:00:15 +0100 | [diff] [blame] | 1192 | |
Frederic Weisbecker | 8e1b82e | 2008-12-06 03:41:33 +0100 | [diff] [blame] | 1193 | tracing_selftest_running = true; |
| 1194 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1195 | for (t = trace_types; t; t = t->next) { |
| 1196 | if (strcmp(type->name, t->name) == 0) { |
| 1197 | /* already found */ |
Li Zefan | ee6c2c1 | 2009-09-18 14:06:47 +0800 | [diff] [blame] | 1198 | pr_info("Tracer %s already registered\n", |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1199 | type->name); |
| 1200 | ret = -1; |
| 1201 | goto out; |
| 1202 | } |
| 1203 | } |
| 1204 | |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 1205 | if (!type->set_flag) |
| 1206 | type->set_flag = &dummy_set_flag; |
| 1207 | if (!type->flags) |
| 1208 | type->flags = &dummy_tracer_flags; |
| 1209 | else |
| 1210 | if (!type->flags->opts) |
| 1211 | type->flags->opts = dummy_tracer_opt; |
Frederic Weisbecker | 6eaaa5d | 2009-02-11 02:25:00 +0100 | [diff] [blame] | 1212 | if (!type->wait_pipe) |
| 1213 | type->wait_pipe = default_wait_pipe; |
| 1214 | |
Steven Rostedt (Red Hat) | f4e781c | 2013-03-07 11:10:56 -0500 | [diff] [blame] | 1215 | ret = run_tracer_selftest(type); |
| 1216 | if (ret < 0) |
| 1217 | goto out; |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 1218 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1219 | type->next = trace_types; |
| 1220 | trace_types = type; |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 1221 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1222 | out: |
Frederic Weisbecker | 8e1b82e | 2008-12-06 03:41:33 +0100 | [diff] [blame] | 1223 | tracing_selftest_running = false; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1224 | mutex_unlock(&trace_types_lock); |
| 1225 | |
Steven Rostedt | dac7494 | 2009-02-05 01:13:38 -0500 | [diff] [blame] | 1226 | if (ret || !default_bootup_tracer) |
| 1227 | goto out_unlock; |
Steven Rostedt | b2821ae | 2009-02-02 21:38:32 -0500 | [diff] [blame] | 1228 | |
Li Zefan | ee6c2c1 | 2009-09-18 14:06:47 +0800 | [diff] [blame] | 1229 | if (strncmp(default_bootup_tracer, type->name, MAX_TRACER_SIZE)) |
Steven Rostedt | dac7494 | 2009-02-05 01:13:38 -0500 | [diff] [blame] | 1230 | goto out_unlock; |
| 1231 | |
| 1232 | printk(KERN_INFO "Starting tracer '%s'\n", type->name); |
| 1233 | /* Do we want this tracer to start on bootup? */ |
| 1234 | tracing_set_tracer(type->name); |
| 1235 | default_bootup_tracer = NULL; |
| 1236 | /* disable other selftests, since this will break it. */ |
Steven Rostedt (Red Hat) | 55034cd | 2013-03-07 22:48:09 -0500 | [diff] [blame] | 1237 | tracing_selftest_disabled = true; |
Steven Rostedt | dac7494 | 2009-02-05 01:13:38 -0500 | [diff] [blame] | 1238 | #ifdef CONFIG_FTRACE_STARTUP_TEST |
| 1239 | printk(KERN_INFO "Disabling FTRACE selftests due to running tracer '%s'\n", |
| 1240 | type->name); |
| 1241 | #endif |
| 1242 | |
| 1243 | out_unlock: |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1244 | return ret; |
| 1245 | } |
| 1246 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1247 | void tracing_reset(struct trace_buffer *buf, int cpu) |
Steven Rostedt | f633903 | 2009-09-04 12:35:16 -0400 | [diff] [blame] | 1248 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1249 | struct ring_buffer *buffer = buf->buffer; |
Steven Rostedt | f633903 | 2009-09-04 12:35:16 -0400 | [diff] [blame] | 1250 | |
Hiraku Toyooka | a541641 | 2012-12-19 16:02:34 +0900 | [diff] [blame] | 1251 | if (!buffer) |
| 1252 | return; |
| 1253 | |
Steven Rostedt | f633903 | 2009-09-04 12:35:16 -0400 | [diff] [blame] | 1254 | ring_buffer_record_disable(buffer); |
| 1255 | |
| 1256 | /* Make sure all commits have finished */ |
| 1257 | synchronize_sched(); |
Steven Rostedt | 6817968 | 2012-05-08 20:57:53 -0400 | [diff] [blame] | 1258 | ring_buffer_reset_cpu(buffer, cpu); |
Steven Rostedt | f633903 | 2009-09-04 12:35:16 -0400 | [diff] [blame] | 1259 | |
| 1260 | ring_buffer_record_enable(buffer); |
| 1261 | } |
| 1262 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1263 | void tracing_reset_online_cpus(struct trace_buffer *buf) |
Pekka J Enberg | 213cc06 | 2008-12-19 12:08:39 +0200 | [diff] [blame] | 1264 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1265 | struct ring_buffer *buffer = buf->buffer; |
Pekka J Enberg | 213cc06 | 2008-12-19 12:08:39 +0200 | [diff] [blame] | 1266 | int cpu; |
| 1267 | |
Hiraku Toyooka | a541641 | 2012-12-19 16:02:34 +0900 | [diff] [blame] | 1268 | if (!buffer) |
| 1269 | return; |
| 1270 | |
Steven Rostedt | 621968c | 2009-09-04 12:02:35 -0400 | [diff] [blame] | 1271 | ring_buffer_record_disable(buffer); |
| 1272 | |
| 1273 | /* Make sure all commits have finished */ |
| 1274 | synchronize_sched(); |
| 1275 | |
Alexander Z Lam | 9457158 | 2013-08-02 18:36:16 -0700 | [diff] [blame] | 1276 | buf->time_start = buffer_ftrace_now(buf, buf->cpu); |
Pekka J Enberg | 213cc06 | 2008-12-19 12:08:39 +0200 | [diff] [blame] | 1277 | |
| 1278 | for_each_online_cpu(cpu) |
Steven Rostedt | 6817968 | 2012-05-08 20:57:53 -0400 | [diff] [blame] | 1279 | ring_buffer_reset_cpu(buffer, cpu); |
Steven Rostedt | 621968c | 2009-09-04 12:02:35 -0400 | [diff] [blame] | 1280 | |
| 1281 | ring_buffer_record_enable(buffer); |
Pekka J Enberg | 213cc06 | 2008-12-19 12:08:39 +0200 | [diff] [blame] | 1282 | } |
| 1283 | |
Steven Rostedt (Red Hat) | 09d8091 | 2013-07-23 22:21:59 -0400 | [diff] [blame] | 1284 | /* Must have trace_types_lock held */ |
Steven Rostedt (Red Hat) | 873c642 | 2013-03-04 23:26:06 -0500 | [diff] [blame] | 1285 | void tracing_reset_all_online_cpus(void) |
Steven Rostedt | 9456f0f | 2009-05-06 21:54:09 -0400 | [diff] [blame] | 1286 | { |
Steven Rostedt (Red Hat) | 873c642 | 2013-03-04 23:26:06 -0500 | [diff] [blame] | 1287 | struct trace_array *tr; |
| 1288 | |
Steven Rostedt (Red Hat) | 873c642 | 2013-03-04 23:26:06 -0500 | [diff] [blame] | 1289 | list_for_each_entry(tr, &ftrace_trace_arrays, list) { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1290 | tracing_reset_online_cpus(&tr->trace_buffer); |
| 1291 | #ifdef CONFIG_TRACER_MAX_TRACE |
| 1292 | tracing_reset_online_cpus(&tr->max_buffer); |
| 1293 | #endif |
Steven Rostedt (Red Hat) | 873c642 | 2013-03-04 23:26:06 -0500 | [diff] [blame] | 1294 | } |
Steven Rostedt | 9456f0f | 2009-05-06 21:54:09 -0400 | [diff] [blame] | 1295 | } |
| 1296 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1297 | #define SAVED_CMDLINES 128 |
Thomas Gleixner | 2c7eea4 | 2009-03-18 09:03:19 +0100 | [diff] [blame] | 1298 | #define NO_CMDLINE_MAP UINT_MAX |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1299 | static unsigned map_pid_to_cmdline[PID_MAX_DEFAULT+1]; |
| 1300 | static unsigned map_cmdline_to_pid[SAVED_CMDLINES]; |
| 1301 | static char saved_cmdlines[SAVED_CMDLINES][TASK_COMM_LEN]; |
| 1302 | static int cmdline_idx; |
Thomas Gleixner | edc35bd | 2009-12-03 12:38:57 +0100 | [diff] [blame] | 1303 | static arch_spinlock_t trace_cmdline_lock = __ARCH_SPIN_LOCK_UNLOCKED; |
Steven Rostedt | 25b0b44 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 1304 | |
Steven Rostedt | 25b0b44 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 1305 | /* temporary disable recording */ |
Hannes Eder | 4fd2735 | 2009-02-10 19:44:12 +0100 | [diff] [blame] | 1306 | static atomic_t trace_record_cmdline_disabled __read_mostly; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1307 | |
| 1308 | static void trace_init_cmdlines(void) |
| 1309 | { |
Thomas Gleixner | 2c7eea4 | 2009-03-18 09:03:19 +0100 | [diff] [blame] | 1310 | memset(&map_pid_to_cmdline, NO_CMDLINE_MAP, sizeof(map_pid_to_cmdline)); |
| 1311 | memset(&map_cmdline_to_pid, NO_CMDLINE_MAP, sizeof(map_cmdline_to_pid)); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1312 | cmdline_idx = 0; |
| 1313 | } |
| 1314 | |
Carsten Emde | b5130b1 | 2009-09-13 01:43:07 +0200 | [diff] [blame] | 1315 | int is_tracing_stopped(void) |
| 1316 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 1317 | return global_trace.stop_count; |
Carsten Emde | b5130b1 | 2009-09-13 01:43:07 +0200 | [diff] [blame] | 1318 | } |
| 1319 | |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1320 | /** |
| 1321 | * tracing_start - quick start of the tracer |
| 1322 | * |
| 1323 | * If tracing is enabled but was stopped by tracing_stop, |
| 1324 | * this will start the tracer back up. |
| 1325 | */ |
| 1326 | void tracing_start(void) |
| 1327 | { |
| 1328 | struct ring_buffer *buffer; |
| 1329 | unsigned long flags; |
| 1330 | |
| 1331 | if (tracing_disabled) |
| 1332 | return; |
| 1333 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 1334 | raw_spin_lock_irqsave(&global_trace.start_lock, flags); |
| 1335 | if (--global_trace.stop_count) { |
| 1336 | if (global_trace.stop_count < 0) { |
Steven Rostedt | b06a830 | 2009-01-22 14:26:15 -0500 | [diff] [blame] | 1337 | /* Someone screwed up their debugging */ |
| 1338 | WARN_ON_ONCE(1); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 1339 | global_trace.stop_count = 0; |
Steven Rostedt | b06a830 | 2009-01-22 14:26:15 -0500 | [diff] [blame] | 1340 | } |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1341 | goto out; |
| 1342 | } |
| 1343 | |
Steven Rostedt | a2f8071 | 2010-03-12 19:56:00 -0500 | [diff] [blame] | 1344 | /* Prevent the buffers from switching */ |
| 1345 | arch_spin_lock(&ftrace_max_lock); |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1346 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1347 | buffer = global_trace.trace_buffer.buffer; |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1348 | if (buffer) |
| 1349 | ring_buffer_record_enable(buffer); |
| 1350 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1351 | #ifdef CONFIG_TRACER_MAX_TRACE |
| 1352 | buffer = global_trace.max_buffer.buffer; |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1353 | if (buffer) |
| 1354 | ring_buffer_record_enable(buffer); |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1355 | #endif |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1356 | |
Steven Rostedt | a2f8071 | 2010-03-12 19:56:00 -0500 | [diff] [blame] | 1357 | arch_spin_unlock(&ftrace_max_lock); |
| 1358 | |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1359 | ftrace_start(); |
| 1360 | out: |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 1361 | raw_spin_unlock_irqrestore(&global_trace.start_lock, flags); |
| 1362 | } |
| 1363 | |
| 1364 | static void tracing_start_tr(struct trace_array *tr) |
| 1365 | { |
| 1366 | struct ring_buffer *buffer; |
| 1367 | unsigned long flags; |
| 1368 | |
| 1369 | if (tracing_disabled) |
| 1370 | return; |
| 1371 | |
| 1372 | /* If global, we need to also start the max tracer */ |
| 1373 | if (tr->flags & TRACE_ARRAY_FL_GLOBAL) |
| 1374 | return tracing_start(); |
| 1375 | |
| 1376 | raw_spin_lock_irqsave(&tr->start_lock, flags); |
| 1377 | |
| 1378 | if (--tr->stop_count) { |
| 1379 | if (tr->stop_count < 0) { |
| 1380 | /* Someone screwed up their debugging */ |
| 1381 | WARN_ON_ONCE(1); |
| 1382 | tr->stop_count = 0; |
| 1383 | } |
| 1384 | goto out; |
| 1385 | } |
| 1386 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1387 | buffer = tr->trace_buffer.buffer; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 1388 | if (buffer) |
| 1389 | ring_buffer_record_enable(buffer); |
| 1390 | |
| 1391 | out: |
| 1392 | raw_spin_unlock_irqrestore(&tr->start_lock, flags); |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1393 | } |
| 1394 | |
| 1395 | /** |
| 1396 | * tracing_stop - quick stop of the tracer |
| 1397 | * |
| 1398 | * Light weight way to stop tracing. Use in conjunction with |
| 1399 | * tracing_start. |
| 1400 | */ |
| 1401 | void tracing_stop(void) |
| 1402 | { |
| 1403 | struct ring_buffer *buffer; |
| 1404 | unsigned long flags; |
| 1405 | |
| 1406 | ftrace_stop(); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 1407 | raw_spin_lock_irqsave(&global_trace.start_lock, flags); |
| 1408 | if (global_trace.stop_count++) |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1409 | goto out; |
| 1410 | |
Steven Rostedt | a2f8071 | 2010-03-12 19:56:00 -0500 | [diff] [blame] | 1411 | /* Prevent the buffers from switching */ |
| 1412 | arch_spin_lock(&ftrace_max_lock); |
| 1413 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1414 | buffer = global_trace.trace_buffer.buffer; |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1415 | if (buffer) |
| 1416 | ring_buffer_record_disable(buffer); |
| 1417 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1418 | #ifdef CONFIG_TRACER_MAX_TRACE |
| 1419 | buffer = global_trace.max_buffer.buffer; |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1420 | if (buffer) |
| 1421 | ring_buffer_record_disable(buffer); |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1422 | #endif |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1423 | |
Steven Rostedt | a2f8071 | 2010-03-12 19:56:00 -0500 | [diff] [blame] | 1424 | arch_spin_unlock(&ftrace_max_lock); |
| 1425 | |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1426 | out: |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 1427 | raw_spin_unlock_irqrestore(&global_trace.start_lock, flags); |
| 1428 | } |
| 1429 | |
| 1430 | static void tracing_stop_tr(struct trace_array *tr) |
| 1431 | { |
| 1432 | struct ring_buffer *buffer; |
| 1433 | unsigned long flags; |
| 1434 | |
| 1435 | /* If global, we need to also stop the max tracer */ |
| 1436 | if (tr->flags & TRACE_ARRAY_FL_GLOBAL) |
| 1437 | return tracing_stop(); |
| 1438 | |
| 1439 | raw_spin_lock_irqsave(&tr->start_lock, flags); |
| 1440 | if (tr->stop_count++) |
| 1441 | goto out; |
| 1442 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1443 | buffer = tr->trace_buffer.buffer; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 1444 | if (buffer) |
| 1445 | ring_buffer_record_disable(buffer); |
| 1446 | |
| 1447 | out: |
| 1448 | raw_spin_unlock_irqrestore(&tr->start_lock, flags); |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1449 | } |
| 1450 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1451 | void trace_stop_cmdline_recording(void); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1452 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1453 | static void trace_save_cmdline(struct task_struct *tsk) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1454 | { |
Carsten Emde | a635cf0 | 2009-03-18 09:00:41 +0100 | [diff] [blame] | 1455 | unsigned pid, idx; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1456 | |
| 1457 | if (!tsk->pid || unlikely(tsk->pid > PID_MAX_DEFAULT)) |
| 1458 | return; |
| 1459 | |
| 1460 | /* |
| 1461 | * It's not the end of the world if we don't get |
| 1462 | * the lock, but we also don't want to spin |
| 1463 | * nor do we want to disable interrupts, |
| 1464 | * so if we miss here, then better luck next time. |
| 1465 | */ |
Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 1466 | if (!arch_spin_trylock(&trace_cmdline_lock)) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1467 | return; |
| 1468 | |
| 1469 | idx = map_pid_to_cmdline[tsk->pid]; |
Thomas Gleixner | 2c7eea4 | 2009-03-18 09:03:19 +0100 | [diff] [blame] | 1470 | if (idx == NO_CMDLINE_MAP) { |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1471 | idx = (cmdline_idx + 1) % SAVED_CMDLINES; |
| 1472 | |
Carsten Emde | a635cf0 | 2009-03-18 09:00:41 +0100 | [diff] [blame] | 1473 | /* |
| 1474 | * Check whether the cmdline buffer at idx has a pid |
| 1475 | * mapped. We are going to overwrite that entry so we |
| 1476 | * need to clear the map_pid_to_cmdline. Otherwise we |
| 1477 | * would read the new comm for the old pid. |
| 1478 | */ |
| 1479 | pid = map_cmdline_to_pid[idx]; |
| 1480 | if (pid != NO_CMDLINE_MAP) |
| 1481 | map_pid_to_cmdline[pid] = NO_CMDLINE_MAP; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1482 | |
Carsten Emde | a635cf0 | 2009-03-18 09:00:41 +0100 | [diff] [blame] | 1483 | map_cmdline_to_pid[idx] = tsk->pid; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1484 | map_pid_to_cmdline[tsk->pid] = idx; |
| 1485 | |
| 1486 | cmdline_idx = idx; |
| 1487 | } |
| 1488 | |
| 1489 | memcpy(&saved_cmdlines[idx], tsk->comm, TASK_COMM_LEN); |
| 1490 | |
Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 1491 | arch_spin_unlock(&trace_cmdline_lock); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1492 | } |
| 1493 | |
Steven Rostedt | 4ca53085 | 2009-03-16 19:20:15 -0400 | [diff] [blame] | 1494 | void trace_find_cmdline(int pid, char comm[]) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1495 | { |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1496 | unsigned map; |
| 1497 | |
Steven Rostedt | 4ca53085 | 2009-03-16 19:20:15 -0400 | [diff] [blame] | 1498 | if (!pid) { |
| 1499 | strcpy(comm, "<idle>"); |
| 1500 | return; |
| 1501 | } |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1502 | |
Steven Rostedt | 74bf407 | 2010-01-25 15:11:53 -0500 | [diff] [blame] | 1503 | if (WARN_ON_ONCE(pid < 0)) { |
| 1504 | strcpy(comm, "<XXX>"); |
| 1505 | return; |
| 1506 | } |
| 1507 | |
Steven Rostedt | 4ca53085 | 2009-03-16 19:20:15 -0400 | [diff] [blame] | 1508 | if (pid > PID_MAX_DEFAULT) { |
| 1509 | strcpy(comm, "<...>"); |
| 1510 | return; |
| 1511 | } |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1512 | |
Heiko Carstens | 5b6045a | 2009-05-26 17:28:02 +0200 | [diff] [blame] | 1513 | preempt_disable(); |
Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 1514 | arch_spin_lock(&trace_cmdline_lock); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1515 | map = map_pid_to_cmdline[pid]; |
Thomas Gleixner | 50d8875 | 2009-03-18 08:58:44 +0100 | [diff] [blame] | 1516 | if (map != NO_CMDLINE_MAP) |
| 1517 | strcpy(comm, saved_cmdlines[map]); |
| 1518 | else |
| 1519 | strcpy(comm, "<...>"); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1520 | |
Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 1521 | arch_spin_unlock(&trace_cmdline_lock); |
Heiko Carstens | 5b6045a | 2009-05-26 17:28:02 +0200 | [diff] [blame] | 1522 | preempt_enable(); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1523 | } |
| 1524 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1525 | void tracing_record_cmdline(struct task_struct *tsk) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1526 | { |
Steven Rostedt | 0fb9656 | 2012-05-11 14:25:30 -0400 | [diff] [blame] | 1527 | if (atomic_read(&trace_record_cmdline_disabled) || !tracing_is_on()) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1528 | return; |
| 1529 | |
Steven Rostedt | 7ffbd48 | 2012-10-11 12:14:25 -0400 | [diff] [blame] | 1530 | if (!__this_cpu_read(trace_cmdline_save)) |
| 1531 | return; |
| 1532 | |
| 1533 | __this_cpu_write(trace_cmdline_save, false); |
| 1534 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1535 | trace_save_cmdline(tsk); |
| 1536 | } |
| 1537 | |
Pekka Paalanen | 45dcd8b | 2008-09-16 21:56:41 +0300 | [diff] [blame] | 1538 | void |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 1539 | tracing_generic_entry_update(struct trace_entry *entry, unsigned long flags, |
| 1540 | int pc) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1541 | { |
| 1542 | struct task_struct *tsk = current; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1543 | |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1544 | entry->preempt_count = pc & 0xff; |
| 1545 | entry->pid = (tsk) ? tsk->pid : 0; |
| 1546 | entry->flags = |
Steven Rostedt | 9244489 | 2008-10-24 09:42:59 -0400 | [diff] [blame] | 1547 | #ifdef CONFIG_TRACE_IRQFLAGS_SUPPORT |
Steven Rostedt | 2e2ca15 | 2008-08-01 12:26:40 -0400 | [diff] [blame] | 1548 | (irqs_disabled_flags(flags) ? TRACE_FLAG_IRQS_OFF : 0) | |
Steven Rostedt | 9244489 | 2008-10-24 09:42:59 -0400 | [diff] [blame] | 1549 | #else |
| 1550 | TRACE_FLAG_IRQS_NOSUPPORT | |
| 1551 | #endif |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1552 | ((pc & HARDIRQ_MASK) ? TRACE_FLAG_HARDIRQ : 0) | |
| 1553 | ((pc & SOFTIRQ_MASK) ? TRACE_FLAG_SOFTIRQ : 0) | |
Peter Zijlstra | e5137b5 | 2013-10-04 17:28:26 +0200 | [diff] [blame] | 1554 | (tif_need_resched() ? TRACE_FLAG_NEED_RESCHED : 0) | |
| 1555 | (test_preempt_need_resched() ? TRACE_FLAG_PREEMPT_RESCHED : 0); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1556 | } |
Frederic Weisbecker | f413cdb | 2009-08-07 01:25:54 +0200 | [diff] [blame] | 1557 | EXPORT_SYMBOL_GPL(tracing_generic_entry_update); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1558 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1559 | struct ring_buffer_event * |
| 1560 | trace_buffer_lock_reserve(struct ring_buffer *buffer, |
| 1561 | int type, |
| 1562 | unsigned long len, |
| 1563 | unsigned long flags, int pc) |
Arnaldo Carvalho de Melo | 51a763d | 2009-02-05 16:14:13 -0200 | [diff] [blame] | 1564 | { |
| 1565 | struct ring_buffer_event *event; |
| 1566 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1567 | event = ring_buffer_lock_reserve(buffer, len); |
Arnaldo Carvalho de Melo | 51a763d | 2009-02-05 16:14:13 -0200 | [diff] [blame] | 1568 | if (event != NULL) { |
| 1569 | struct trace_entry *ent = ring_buffer_event_data(event); |
| 1570 | |
| 1571 | tracing_generic_entry_update(ent, flags, pc); |
| 1572 | ent->type = type; |
| 1573 | } |
| 1574 | |
| 1575 | return event; |
| 1576 | } |
Arnaldo Carvalho de Melo | 51a763d | 2009-02-05 16:14:13 -0200 | [diff] [blame] | 1577 | |
Steven Rostedt | 7ffbd48 | 2012-10-11 12:14:25 -0400 | [diff] [blame] | 1578 | void |
| 1579 | __buffer_unlock_commit(struct ring_buffer *buffer, struct ring_buffer_event *event) |
| 1580 | { |
| 1581 | __this_cpu_write(trace_cmdline_save, true); |
| 1582 | ring_buffer_unlock_commit(buffer, event); |
| 1583 | } |
| 1584 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1585 | static inline void |
| 1586 | __trace_buffer_unlock_commit(struct ring_buffer *buffer, |
| 1587 | struct ring_buffer_event *event, |
Steven Rostedt | 0d5c6e1 | 2012-11-01 20:54:21 -0400 | [diff] [blame] | 1588 | unsigned long flags, int pc) |
Arnaldo Carvalho de Melo | 51a763d | 2009-02-05 16:14:13 -0200 | [diff] [blame] | 1589 | { |
Steven Rostedt | 7ffbd48 | 2012-10-11 12:14:25 -0400 | [diff] [blame] | 1590 | __buffer_unlock_commit(buffer, event); |
Arnaldo Carvalho de Melo | 51a763d | 2009-02-05 16:14:13 -0200 | [diff] [blame] | 1591 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1592 | ftrace_trace_stack(buffer, flags, 6, pc); |
| 1593 | ftrace_trace_userstack(buffer, flags, pc); |
Frederic Weisbecker | 07edf71 | 2009-03-22 23:10:46 +0100 | [diff] [blame] | 1594 | } |
| 1595 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1596 | void trace_buffer_unlock_commit(struct ring_buffer *buffer, |
| 1597 | struct ring_buffer_event *event, |
| 1598 | unsigned long flags, int pc) |
Frederic Weisbecker | 07edf71 | 2009-03-22 23:10:46 +0100 | [diff] [blame] | 1599 | { |
Steven Rostedt | 0d5c6e1 | 2012-11-01 20:54:21 -0400 | [diff] [blame] | 1600 | __trace_buffer_unlock_commit(buffer, event, flags, pc); |
Arnaldo Carvalho de Melo | 51a763d | 2009-02-05 16:14:13 -0200 | [diff] [blame] | 1601 | } |
Steven Rostedt | 0d5c6e1 | 2012-11-01 20:54:21 -0400 | [diff] [blame] | 1602 | EXPORT_SYMBOL_GPL(trace_buffer_unlock_commit); |
Arnaldo Carvalho de Melo | 51a763d | 2009-02-05 16:14:13 -0200 | [diff] [blame] | 1603 | |
Steven Rostedt | ef5580d | 2009-02-27 19:38:04 -0500 | [diff] [blame] | 1604 | struct ring_buffer_event * |
Steven Rostedt | ccb469a | 2012-08-02 10:32:10 -0400 | [diff] [blame] | 1605 | trace_event_buffer_lock_reserve(struct ring_buffer **current_rb, |
| 1606 | struct ftrace_event_file *ftrace_file, |
| 1607 | int type, unsigned long len, |
| 1608 | unsigned long flags, int pc) |
| 1609 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1610 | *current_rb = ftrace_file->tr->trace_buffer.buffer; |
Steven Rostedt | ccb469a | 2012-08-02 10:32:10 -0400 | [diff] [blame] | 1611 | return trace_buffer_lock_reserve(*current_rb, |
| 1612 | type, len, flags, pc); |
| 1613 | } |
| 1614 | EXPORT_SYMBOL_GPL(trace_event_buffer_lock_reserve); |
| 1615 | |
| 1616 | struct ring_buffer_event * |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1617 | trace_current_buffer_lock_reserve(struct ring_buffer **current_rb, |
| 1618 | int type, unsigned long len, |
Steven Rostedt | ef5580d | 2009-02-27 19:38:04 -0500 | [diff] [blame] | 1619 | unsigned long flags, int pc) |
| 1620 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1621 | *current_rb = global_trace.trace_buffer.buffer; |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1622 | return trace_buffer_lock_reserve(*current_rb, |
Steven Rostedt | ef5580d | 2009-02-27 19:38:04 -0500 | [diff] [blame] | 1623 | type, len, flags, pc); |
| 1624 | } |
Steven Rostedt | 94487d6 | 2009-05-05 19:22:53 -0400 | [diff] [blame] | 1625 | EXPORT_SYMBOL_GPL(trace_current_buffer_lock_reserve); |
Steven Rostedt | ef5580d | 2009-02-27 19:38:04 -0500 | [diff] [blame] | 1626 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1627 | void trace_current_buffer_unlock_commit(struct ring_buffer *buffer, |
| 1628 | struct ring_buffer_event *event, |
Steven Rostedt | ef5580d | 2009-02-27 19:38:04 -0500 | [diff] [blame] | 1629 | unsigned long flags, int pc) |
| 1630 | { |
Steven Rostedt | 0d5c6e1 | 2012-11-01 20:54:21 -0400 | [diff] [blame] | 1631 | __trace_buffer_unlock_commit(buffer, event, flags, pc); |
Frederic Weisbecker | 07edf71 | 2009-03-22 23:10:46 +0100 | [diff] [blame] | 1632 | } |
Steven Rostedt | 94487d6 | 2009-05-05 19:22:53 -0400 | [diff] [blame] | 1633 | EXPORT_SYMBOL_GPL(trace_current_buffer_unlock_commit); |
Frederic Weisbecker | 07edf71 | 2009-03-22 23:10:46 +0100 | [diff] [blame] | 1634 | |
Steven Rostedt | 0d5c6e1 | 2012-11-01 20:54:21 -0400 | [diff] [blame] | 1635 | void trace_buffer_unlock_commit_regs(struct ring_buffer *buffer, |
| 1636 | struct ring_buffer_event *event, |
| 1637 | unsigned long flags, int pc, |
| 1638 | struct pt_regs *regs) |
Masami Hiramatsu | 1fd8df2 | 2011-06-08 16:09:34 +0900 | [diff] [blame] | 1639 | { |
Steven Rostedt | 7ffbd48 | 2012-10-11 12:14:25 -0400 | [diff] [blame] | 1640 | __buffer_unlock_commit(buffer, event); |
Masami Hiramatsu | 1fd8df2 | 2011-06-08 16:09:34 +0900 | [diff] [blame] | 1641 | |
| 1642 | ftrace_trace_stack_regs(buffer, flags, 0, pc, regs); |
| 1643 | ftrace_trace_userstack(buffer, flags, pc); |
| 1644 | } |
Steven Rostedt | 0d5c6e1 | 2012-11-01 20:54:21 -0400 | [diff] [blame] | 1645 | EXPORT_SYMBOL_GPL(trace_buffer_unlock_commit_regs); |
Masami Hiramatsu | 1fd8df2 | 2011-06-08 16:09:34 +0900 | [diff] [blame] | 1646 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1647 | void trace_current_buffer_discard_commit(struct ring_buffer *buffer, |
| 1648 | struct ring_buffer_event *event) |
Steven Rostedt | 77d9f46 | 2009-04-02 01:16:59 -0400 | [diff] [blame] | 1649 | { |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1650 | ring_buffer_discard_commit(buffer, event); |
Steven Rostedt | ef5580d | 2009-02-27 19:38:04 -0500 | [diff] [blame] | 1651 | } |
Steven Rostedt | 12acd47 | 2009-04-17 16:01:56 -0400 | [diff] [blame] | 1652 | EXPORT_SYMBOL_GPL(trace_current_buffer_discard_commit); |
Steven Rostedt | ef5580d | 2009-02-27 19:38:04 -0500 | [diff] [blame] | 1653 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1654 | void |
Arnaldo Carvalho de Melo | 7be4215 | 2009-02-05 01:13:37 -0500 | [diff] [blame] | 1655 | trace_function(struct trace_array *tr, |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 1656 | unsigned long ip, unsigned long parent_ip, unsigned long flags, |
| 1657 | int pc) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1658 | { |
Tom Zanussi | e1112b4 | 2009-03-31 00:48:49 -0500 | [diff] [blame] | 1659 | struct ftrace_event_call *call = &event_function; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1660 | struct ring_buffer *buffer = tr->trace_buffer.buffer; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1661 | struct ring_buffer_event *event; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1662 | struct ftrace_entry *entry; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1663 | |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 1664 | /* If we are reading the ring buffer, don't trace */ |
Rusty Russell | dd17c8f | 2009-10-29 22:34:15 +0900 | [diff] [blame] | 1665 | if (unlikely(__this_cpu_read(ftrace_cpu_disabled))) |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 1666 | return; |
| 1667 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1668 | event = trace_buffer_lock_reserve(buffer, TRACE_FN, sizeof(*entry), |
Arnaldo Carvalho de Melo | 51a763d | 2009-02-05 16:14:13 -0200 | [diff] [blame] | 1669 | flags, pc); |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1670 | if (!event) |
| 1671 | return; |
| 1672 | entry = ring_buffer_event_data(event); |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1673 | entry->ip = ip; |
| 1674 | entry->parent_ip = parent_ip; |
Tom Zanussi | e1112b4 | 2009-03-31 00:48:49 -0500 | [diff] [blame] | 1675 | |
Tom Zanussi | f306cc8 | 2013-10-24 08:34:17 -0500 | [diff] [blame] | 1676 | if (!call_filter_check_discard(call, entry, buffer, event)) |
Steven Rostedt | 7ffbd48 | 2012-10-11 12:14:25 -0400 | [diff] [blame] | 1677 | __buffer_unlock_commit(buffer, event); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1678 | } |
| 1679 | |
Frederic Weisbecker | c0a0d0d | 2009-07-29 17:51:13 +0200 | [diff] [blame] | 1680 | #ifdef CONFIG_STACKTRACE |
Steven Rostedt | 4a9bd3f | 2011-07-14 16:36:53 -0400 | [diff] [blame] | 1681 | |
| 1682 | #define FTRACE_STACK_MAX_ENTRIES (PAGE_SIZE / sizeof(unsigned long)) |
| 1683 | struct ftrace_stack { |
| 1684 | unsigned long calls[FTRACE_STACK_MAX_ENTRIES]; |
| 1685 | }; |
| 1686 | |
| 1687 | static DEFINE_PER_CPU(struct ftrace_stack, ftrace_stack); |
| 1688 | static DEFINE_PER_CPU(int, ftrace_stack_reserve); |
| 1689 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1690 | static void __ftrace_trace_stack(struct ring_buffer *buffer, |
Steven Rostedt | 5361499 | 2009-01-15 19:12:40 -0500 | [diff] [blame] | 1691 | unsigned long flags, |
Masami Hiramatsu | 1fd8df2 | 2011-06-08 16:09:34 +0900 | [diff] [blame] | 1692 | int skip, int pc, struct pt_regs *regs) |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1693 | { |
Tom Zanussi | e1112b4 | 2009-03-31 00:48:49 -0500 | [diff] [blame] | 1694 | struct ftrace_event_call *call = &event_kernel_stack; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1695 | struct ring_buffer_event *event; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1696 | struct stack_entry *entry; |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1697 | struct stack_trace trace; |
Steven Rostedt | 4a9bd3f | 2011-07-14 16:36:53 -0400 | [diff] [blame] | 1698 | int use_stack; |
| 1699 | int size = FTRACE_STACK_ENTRIES; |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1700 | |
| 1701 | trace.nr_entries = 0; |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1702 | trace.skip = skip; |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1703 | |
Steven Rostedt | 4a9bd3f | 2011-07-14 16:36:53 -0400 | [diff] [blame] | 1704 | /* |
| 1705 | * Since events can happen in NMIs there's no safe way to |
| 1706 | * use the per cpu ftrace_stacks. We reserve it and if an interrupt |
| 1707 | * or NMI comes in, it will just have to use the default |
| 1708 | * FTRACE_STACK_SIZE. |
| 1709 | */ |
| 1710 | preempt_disable_notrace(); |
| 1711 | |
Shan Wei | 8214652 | 2012-11-19 13:21:01 +0800 | [diff] [blame] | 1712 | use_stack = __this_cpu_inc_return(ftrace_stack_reserve); |
Steven Rostedt | 4a9bd3f | 2011-07-14 16:36:53 -0400 | [diff] [blame] | 1713 | /* |
| 1714 | * We don't need any atomic variables, just a barrier. |
| 1715 | * If an interrupt comes in, we don't care, because it would |
| 1716 | * have exited and put the counter back to what we want. |
| 1717 | * We just need a barrier to keep gcc from moving things |
| 1718 | * around. |
| 1719 | */ |
| 1720 | barrier(); |
| 1721 | if (use_stack == 1) { |
| 1722 | trace.entries = &__get_cpu_var(ftrace_stack).calls[0]; |
| 1723 | trace.max_entries = FTRACE_STACK_MAX_ENTRIES; |
| 1724 | |
| 1725 | if (regs) |
| 1726 | save_stack_trace_regs(regs, &trace); |
| 1727 | else |
| 1728 | save_stack_trace(&trace); |
| 1729 | |
| 1730 | if (trace.nr_entries > size) |
| 1731 | size = trace.nr_entries; |
| 1732 | } else |
| 1733 | /* From now on, use_stack is a boolean */ |
| 1734 | use_stack = 0; |
| 1735 | |
| 1736 | size *= sizeof(unsigned long); |
| 1737 | |
| 1738 | event = trace_buffer_lock_reserve(buffer, TRACE_STACK, |
| 1739 | sizeof(*entry) + size, flags, pc); |
| 1740 | if (!event) |
| 1741 | goto out; |
| 1742 | entry = ring_buffer_event_data(event); |
| 1743 | |
| 1744 | memset(&entry->caller, 0, size); |
| 1745 | |
| 1746 | if (use_stack) |
| 1747 | memcpy(&entry->caller, trace.entries, |
| 1748 | trace.nr_entries * sizeof(unsigned long)); |
| 1749 | else { |
| 1750 | trace.max_entries = FTRACE_STACK_ENTRIES; |
| 1751 | trace.entries = entry->caller; |
| 1752 | if (regs) |
| 1753 | save_stack_trace_regs(regs, &trace); |
| 1754 | else |
| 1755 | save_stack_trace(&trace); |
| 1756 | } |
| 1757 | |
| 1758 | entry->size = trace.nr_entries; |
| 1759 | |
Tom Zanussi | f306cc8 | 2013-10-24 08:34:17 -0500 | [diff] [blame] | 1760 | if (!call_filter_check_discard(call, entry, buffer, event)) |
Steven Rostedt | 7ffbd48 | 2012-10-11 12:14:25 -0400 | [diff] [blame] | 1761 | __buffer_unlock_commit(buffer, event); |
Steven Rostedt | 4a9bd3f | 2011-07-14 16:36:53 -0400 | [diff] [blame] | 1762 | |
| 1763 | out: |
| 1764 | /* Again, don't let gcc optimize things here */ |
| 1765 | barrier(); |
Shan Wei | 8214652 | 2012-11-19 13:21:01 +0800 | [diff] [blame] | 1766 | __this_cpu_dec(ftrace_stack_reserve); |
Steven Rostedt | 4a9bd3f | 2011-07-14 16:36:53 -0400 | [diff] [blame] | 1767 | preempt_enable_notrace(); |
| 1768 | |
Ingo Molnar | f0a920d | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 1769 | } |
| 1770 | |
Masami Hiramatsu | 1fd8df2 | 2011-06-08 16:09:34 +0900 | [diff] [blame] | 1771 | void ftrace_trace_stack_regs(struct ring_buffer *buffer, unsigned long flags, |
| 1772 | int skip, int pc, struct pt_regs *regs) |
| 1773 | { |
| 1774 | if (!(trace_flags & TRACE_ITER_STACKTRACE)) |
| 1775 | return; |
| 1776 | |
| 1777 | __ftrace_trace_stack(buffer, flags, skip, pc, regs); |
| 1778 | } |
| 1779 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1780 | void ftrace_trace_stack(struct ring_buffer *buffer, unsigned long flags, |
| 1781 | int skip, int pc) |
Steven Rostedt | 5361499 | 2009-01-15 19:12:40 -0500 | [diff] [blame] | 1782 | { |
| 1783 | if (!(trace_flags & TRACE_ITER_STACKTRACE)) |
| 1784 | return; |
| 1785 | |
Masami Hiramatsu | 1fd8df2 | 2011-06-08 16:09:34 +0900 | [diff] [blame] | 1786 | __ftrace_trace_stack(buffer, flags, skip, pc, NULL); |
Steven Rostedt | 5361499 | 2009-01-15 19:12:40 -0500 | [diff] [blame] | 1787 | } |
| 1788 | |
Frederic Weisbecker | c0a0d0d | 2009-07-29 17:51:13 +0200 | [diff] [blame] | 1789 | void __trace_stack(struct trace_array *tr, unsigned long flags, int skip, |
| 1790 | int pc) |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 1791 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1792 | __ftrace_trace_stack(tr->trace_buffer.buffer, flags, skip, pc, NULL); |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 1793 | } |
| 1794 | |
Steven Rostedt | 0388938 | 2009-12-11 09:48:22 -0500 | [diff] [blame] | 1795 | /** |
| 1796 | * trace_dump_stack - record a stack back trace in the trace buffer |
Steven Rostedt (Red Hat) | c142be8 | 2013-03-13 09:55:57 -0400 | [diff] [blame] | 1797 | * @skip: Number of functions to skip (helper handlers) |
Steven Rostedt | 0388938 | 2009-12-11 09:48:22 -0500 | [diff] [blame] | 1798 | */ |
Steven Rostedt (Red Hat) | c142be8 | 2013-03-13 09:55:57 -0400 | [diff] [blame] | 1799 | void trace_dump_stack(int skip) |
Steven Rostedt | 0388938 | 2009-12-11 09:48:22 -0500 | [diff] [blame] | 1800 | { |
| 1801 | unsigned long flags; |
| 1802 | |
| 1803 | if (tracing_disabled || tracing_selftest_running) |
Steven Rostedt | e36c545 | 2009-12-14 15:58:33 -0500 | [diff] [blame] | 1804 | return; |
Steven Rostedt | 0388938 | 2009-12-11 09:48:22 -0500 | [diff] [blame] | 1805 | |
| 1806 | local_save_flags(flags); |
| 1807 | |
Steven Rostedt (Red Hat) | c142be8 | 2013-03-13 09:55:57 -0400 | [diff] [blame] | 1808 | /* |
| 1809 | * Skip 3 more, seems to get us at the caller of |
| 1810 | * this function. |
| 1811 | */ |
| 1812 | skip += 3; |
| 1813 | __ftrace_trace_stack(global_trace.trace_buffer.buffer, |
| 1814 | flags, skip, preempt_count(), NULL); |
Steven Rostedt | 0388938 | 2009-12-11 09:48:22 -0500 | [diff] [blame] | 1815 | } |
| 1816 | |
Steven Rostedt | 91e86e5 | 2010-11-10 12:56:12 +0100 | [diff] [blame] | 1817 | static DEFINE_PER_CPU(int, user_stack_count); |
| 1818 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1819 | void |
| 1820 | ftrace_trace_userstack(struct ring_buffer *buffer, unsigned long flags, int pc) |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 1821 | { |
Tom Zanussi | e1112b4 | 2009-03-31 00:48:49 -0500 | [diff] [blame] | 1822 | struct ftrace_event_call *call = &event_user_stack; |
Török Edwin | 8d7c6a9 | 2008-11-23 12:39:06 +0200 | [diff] [blame] | 1823 | struct ring_buffer_event *event; |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 1824 | struct userstack_entry *entry; |
| 1825 | struct stack_trace trace; |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 1826 | |
| 1827 | if (!(trace_flags & TRACE_ITER_USERSTACKTRACE)) |
| 1828 | return; |
| 1829 | |
Steven Rostedt | b634587 | 2010-03-12 20:03:30 -0500 | [diff] [blame] | 1830 | /* |
| 1831 | * NMIs can not handle page faults, even with fix ups. |
| 1832 | * The save user stack can (and often does) fault. |
| 1833 | */ |
| 1834 | if (unlikely(in_nmi())) |
| 1835 | return; |
| 1836 | |
Steven Rostedt | 91e86e5 | 2010-11-10 12:56:12 +0100 | [diff] [blame] | 1837 | /* |
| 1838 | * prevent recursion, since the user stack tracing may |
| 1839 | * trigger other kernel events. |
| 1840 | */ |
| 1841 | preempt_disable(); |
| 1842 | if (__this_cpu_read(user_stack_count)) |
| 1843 | goto out; |
| 1844 | |
| 1845 | __this_cpu_inc(user_stack_count); |
| 1846 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1847 | event = trace_buffer_lock_reserve(buffer, TRACE_USER_STACK, |
Arnaldo Carvalho de Melo | 51a763d | 2009-02-05 16:14:13 -0200 | [diff] [blame] | 1848 | sizeof(*entry), flags, pc); |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 1849 | if (!event) |
Li Zefan | 1dbd195 | 2010-12-09 15:47:56 +0800 | [diff] [blame] | 1850 | goto out_drop_count; |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 1851 | entry = ring_buffer_event_data(event); |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 1852 | |
Steven Rostedt | 48659d3 | 2009-09-11 11:36:23 -0400 | [diff] [blame] | 1853 | entry->tgid = current->tgid; |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 1854 | memset(&entry->caller, 0, sizeof(entry->caller)); |
| 1855 | |
| 1856 | trace.nr_entries = 0; |
| 1857 | trace.max_entries = FTRACE_STACK_ENTRIES; |
| 1858 | trace.skip = 0; |
| 1859 | trace.entries = entry->caller; |
| 1860 | |
| 1861 | save_stack_trace_user(&trace); |
Tom Zanussi | f306cc8 | 2013-10-24 08:34:17 -0500 | [diff] [blame] | 1862 | if (!call_filter_check_discard(call, entry, buffer, event)) |
Steven Rostedt | 7ffbd48 | 2012-10-11 12:14:25 -0400 | [diff] [blame] | 1863 | __buffer_unlock_commit(buffer, event); |
Steven Rostedt | 91e86e5 | 2010-11-10 12:56:12 +0100 | [diff] [blame] | 1864 | |
Li Zefan | 1dbd195 | 2010-12-09 15:47:56 +0800 | [diff] [blame] | 1865 | out_drop_count: |
Steven Rostedt | 91e86e5 | 2010-11-10 12:56:12 +0100 | [diff] [blame] | 1866 | __this_cpu_dec(user_stack_count); |
Steven Rostedt | 91e86e5 | 2010-11-10 12:56:12 +0100 | [diff] [blame] | 1867 | out: |
| 1868 | preempt_enable(); |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 1869 | } |
| 1870 | |
Hannes Eder | 4fd2735 | 2009-02-10 19:44:12 +0100 | [diff] [blame] | 1871 | #ifdef UNUSED |
| 1872 | static void __trace_userstack(struct trace_array *tr, unsigned long flags) |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 1873 | { |
Arnaldo Carvalho de Melo | 7be4215 | 2009-02-05 01:13:37 -0500 | [diff] [blame] | 1874 | ftrace_trace_userstack(tr, flags, preempt_count()); |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 1875 | } |
Hannes Eder | 4fd2735 | 2009-02-10 19:44:12 +0100 | [diff] [blame] | 1876 | #endif /* UNUSED */ |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 1877 | |
Frederic Weisbecker | c0a0d0d | 2009-07-29 17:51:13 +0200 | [diff] [blame] | 1878 | #endif /* CONFIG_STACKTRACE */ |
| 1879 | |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 1880 | /* created for use with alloc_percpu */ |
| 1881 | struct trace_buffer_struct { |
| 1882 | char buffer[TRACE_BUF_SIZE]; |
| 1883 | }; |
| 1884 | |
| 1885 | static struct trace_buffer_struct *trace_percpu_buffer; |
| 1886 | static struct trace_buffer_struct *trace_percpu_sirq_buffer; |
| 1887 | static struct trace_buffer_struct *trace_percpu_irq_buffer; |
| 1888 | static struct trace_buffer_struct *trace_percpu_nmi_buffer; |
| 1889 | |
| 1890 | /* |
| 1891 | * The buffer used is dependent on the context. There is a per cpu |
| 1892 | * buffer for normal context, softirq contex, hard irq context and |
| 1893 | * for NMI context. Thise allows for lockless recording. |
| 1894 | * |
| 1895 | * Note, if the buffers failed to be allocated, then this returns NULL |
| 1896 | */ |
| 1897 | static char *get_trace_buf(void) |
| 1898 | { |
| 1899 | struct trace_buffer_struct *percpu_buffer; |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 1900 | |
| 1901 | /* |
| 1902 | * If we have allocated per cpu buffers, then we do not |
| 1903 | * need to do any locking. |
| 1904 | */ |
| 1905 | if (in_nmi()) |
| 1906 | percpu_buffer = trace_percpu_nmi_buffer; |
| 1907 | else if (in_irq()) |
| 1908 | percpu_buffer = trace_percpu_irq_buffer; |
| 1909 | else if (in_softirq()) |
| 1910 | percpu_buffer = trace_percpu_sirq_buffer; |
| 1911 | else |
| 1912 | percpu_buffer = trace_percpu_buffer; |
| 1913 | |
| 1914 | if (!percpu_buffer) |
| 1915 | return NULL; |
| 1916 | |
Shan Wei | d8a0349 | 2012-11-13 09:53:04 +0800 | [diff] [blame] | 1917 | return this_cpu_ptr(&percpu_buffer->buffer[0]); |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 1918 | } |
| 1919 | |
| 1920 | static int alloc_percpu_trace_buffer(void) |
| 1921 | { |
| 1922 | struct trace_buffer_struct *buffers; |
| 1923 | struct trace_buffer_struct *sirq_buffers; |
| 1924 | struct trace_buffer_struct *irq_buffers; |
| 1925 | struct trace_buffer_struct *nmi_buffers; |
| 1926 | |
| 1927 | buffers = alloc_percpu(struct trace_buffer_struct); |
| 1928 | if (!buffers) |
| 1929 | goto err_warn; |
| 1930 | |
| 1931 | sirq_buffers = alloc_percpu(struct trace_buffer_struct); |
| 1932 | if (!sirq_buffers) |
| 1933 | goto err_sirq; |
| 1934 | |
| 1935 | irq_buffers = alloc_percpu(struct trace_buffer_struct); |
| 1936 | if (!irq_buffers) |
| 1937 | goto err_irq; |
| 1938 | |
| 1939 | nmi_buffers = alloc_percpu(struct trace_buffer_struct); |
| 1940 | if (!nmi_buffers) |
| 1941 | goto err_nmi; |
| 1942 | |
| 1943 | trace_percpu_buffer = buffers; |
| 1944 | trace_percpu_sirq_buffer = sirq_buffers; |
| 1945 | trace_percpu_irq_buffer = irq_buffers; |
| 1946 | trace_percpu_nmi_buffer = nmi_buffers; |
| 1947 | |
| 1948 | return 0; |
| 1949 | |
| 1950 | err_nmi: |
| 1951 | free_percpu(irq_buffers); |
| 1952 | err_irq: |
| 1953 | free_percpu(sirq_buffers); |
| 1954 | err_sirq: |
| 1955 | free_percpu(buffers); |
| 1956 | err_warn: |
| 1957 | WARN(1, "Could not allocate percpu trace_printk buffer"); |
| 1958 | return -ENOMEM; |
| 1959 | } |
| 1960 | |
Steven Rostedt | 8169883 | 2012-10-11 10:15:05 -0400 | [diff] [blame] | 1961 | static int buffers_allocated; |
| 1962 | |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 1963 | void trace_printk_init_buffers(void) |
| 1964 | { |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 1965 | if (buffers_allocated) |
| 1966 | return; |
| 1967 | |
| 1968 | if (alloc_percpu_trace_buffer()) |
| 1969 | return; |
| 1970 | |
| 1971 | pr_info("ftrace: Allocated trace_printk buffers\n"); |
| 1972 | |
Steven Rostedt | b382ede6 | 2012-10-10 21:44:34 -0400 | [diff] [blame] | 1973 | /* Expand the buffers to set size */ |
| 1974 | tracing_update_buffers(); |
| 1975 | |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 1976 | buffers_allocated = 1; |
Steven Rostedt | 8169883 | 2012-10-11 10:15:05 -0400 | [diff] [blame] | 1977 | |
| 1978 | /* |
| 1979 | * trace_printk_init_buffers() can be called by modules. |
| 1980 | * If that happens, then we need to start cmdline recording |
| 1981 | * directly here. If the global_trace.buffer is already |
| 1982 | * allocated here, then this was called by module code. |
| 1983 | */ |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1984 | if (global_trace.trace_buffer.buffer) |
Steven Rostedt | 8169883 | 2012-10-11 10:15:05 -0400 | [diff] [blame] | 1985 | tracing_start_cmdline_record(); |
| 1986 | } |
| 1987 | |
| 1988 | void trace_printk_start_comm(void) |
| 1989 | { |
| 1990 | /* Start tracing comms if trace printk is set */ |
| 1991 | if (!buffers_allocated) |
| 1992 | return; |
| 1993 | tracing_start_cmdline_record(); |
| 1994 | } |
| 1995 | |
| 1996 | static void trace_printk_start_stop_comm(int enabled) |
| 1997 | { |
| 1998 | if (!buffers_allocated) |
| 1999 | return; |
| 2000 | |
| 2001 | if (enabled) |
| 2002 | tracing_start_cmdline_record(); |
| 2003 | else |
| 2004 | tracing_stop_cmdline_record(); |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 2005 | } |
| 2006 | |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 2007 | /** |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 2008 | * trace_vbprintk - write binary msg to tracing buffer |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 2009 | * |
| 2010 | */ |
Steven Rostedt | 40ce74f | 2009-03-19 14:03:53 -0400 | [diff] [blame] | 2011 | int trace_vbprintk(unsigned long ip, const char *fmt, va_list args) |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 2012 | { |
Tom Zanussi | e1112b4 | 2009-03-31 00:48:49 -0500 | [diff] [blame] | 2013 | struct ftrace_event_call *call = &event_bprint; |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 2014 | struct ring_buffer_event *event; |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 2015 | struct ring_buffer *buffer; |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 2016 | struct trace_array *tr = &global_trace; |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 2017 | struct bprint_entry *entry; |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 2018 | unsigned long flags; |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 2019 | char *tbuffer; |
| 2020 | int len = 0, size, pc; |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 2021 | |
| 2022 | if (unlikely(tracing_selftest_running || tracing_disabled)) |
| 2023 | return 0; |
| 2024 | |
| 2025 | /* Don't pollute graph traces with trace_vprintk internals */ |
| 2026 | pause_graph_tracing(); |
| 2027 | |
| 2028 | pc = preempt_count(); |
Steven Rostedt | 5168ae5 | 2010-06-03 09:36:50 -0400 | [diff] [blame] | 2029 | preempt_disable_notrace(); |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 2030 | |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 2031 | tbuffer = get_trace_buf(); |
| 2032 | if (!tbuffer) { |
| 2033 | len = 0; |
| 2034 | goto out; |
| 2035 | } |
| 2036 | |
| 2037 | len = vbin_printf((u32 *)tbuffer, TRACE_BUF_SIZE/sizeof(int), fmt, args); |
| 2038 | |
| 2039 | if (len > TRACE_BUF_SIZE/sizeof(int) || len < 0) |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 2040 | goto out; |
| 2041 | |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 2042 | local_save_flags(flags); |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 2043 | size = sizeof(*entry) + sizeof(u32) * len; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2044 | buffer = tr->trace_buffer.buffer; |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 2045 | event = trace_buffer_lock_reserve(buffer, TRACE_BPRINT, size, |
| 2046 | flags, pc); |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 2047 | if (!event) |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 2048 | goto out; |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 2049 | entry = ring_buffer_event_data(event); |
| 2050 | entry->ip = ip; |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 2051 | entry->fmt = fmt; |
| 2052 | |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 2053 | memcpy(entry->buf, tbuffer, sizeof(u32) * len); |
Tom Zanussi | f306cc8 | 2013-10-24 08:34:17 -0500 | [diff] [blame] | 2054 | if (!call_filter_check_discard(call, entry, buffer, event)) { |
Steven Rostedt | 7ffbd48 | 2012-10-11 12:14:25 -0400 | [diff] [blame] | 2055 | __buffer_unlock_commit(buffer, event); |
Steven Rostedt | d931369 | 2010-01-06 17:27:11 -0500 | [diff] [blame] | 2056 | ftrace_trace_stack(buffer, flags, 6, pc); |
| 2057 | } |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 2058 | |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 2059 | out: |
Steven Rostedt | 5168ae5 | 2010-06-03 09:36:50 -0400 | [diff] [blame] | 2060 | preempt_enable_notrace(); |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 2061 | unpause_graph_tracing(); |
| 2062 | |
| 2063 | return len; |
| 2064 | } |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 2065 | EXPORT_SYMBOL_GPL(trace_vbprintk); |
| 2066 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2067 | static int |
| 2068 | __trace_array_vprintk(struct ring_buffer *buffer, |
| 2069 | unsigned long ip, const char *fmt, va_list args) |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 2070 | { |
Tom Zanussi | e1112b4 | 2009-03-31 00:48:49 -0500 | [diff] [blame] | 2071 | struct ftrace_event_call *call = &event_print; |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 2072 | struct ring_buffer_event *event; |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 2073 | int len = 0, size, pc; |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 2074 | struct print_entry *entry; |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 2075 | unsigned long flags; |
| 2076 | char *tbuffer; |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 2077 | |
| 2078 | if (tracing_disabled || tracing_selftest_running) |
| 2079 | return 0; |
| 2080 | |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 2081 | /* Don't pollute graph traces with trace_vprintk internals */ |
| 2082 | pause_graph_tracing(); |
| 2083 | |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 2084 | pc = preempt_count(); |
| 2085 | preempt_disable_notrace(); |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 2086 | |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 2087 | |
| 2088 | tbuffer = get_trace_buf(); |
| 2089 | if (!tbuffer) { |
| 2090 | len = 0; |
| 2091 | goto out; |
| 2092 | } |
| 2093 | |
| 2094 | len = vsnprintf(tbuffer, TRACE_BUF_SIZE, fmt, args); |
| 2095 | if (len > TRACE_BUF_SIZE) |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 2096 | goto out; |
| 2097 | |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 2098 | local_save_flags(flags); |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 2099 | size = sizeof(*entry) + len + 1; |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 2100 | event = trace_buffer_lock_reserve(buffer, TRACE_PRINT, size, |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 2101 | flags, pc); |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 2102 | if (!event) |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 2103 | goto out; |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 2104 | entry = ring_buffer_event_data(event); |
Carsten Emde | c13d2f7 | 2009-11-16 20:56:13 +0100 | [diff] [blame] | 2105 | entry->ip = ip; |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 2106 | |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 2107 | memcpy(&entry->buf, tbuffer, len); |
Carsten Emde | c13d2f7 | 2009-11-16 20:56:13 +0100 | [diff] [blame] | 2108 | entry->buf[len] = '\0'; |
Tom Zanussi | f306cc8 | 2013-10-24 08:34:17 -0500 | [diff] [blame] | 2109 | if (!call_filter_check_discard(call, entry, buffer, event)) { |
Steven Rostedt | 7ffbd48 | 2012-10-11 12:14:25 -0400 | [diff] [blame] | 2110 | __buffer_unlock_commit(buffer, event); |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 2111 | ftrace_trace_stack(buffer, flags, 6, pc); |
Steven Rostedt | d931369 | 2010-01-06 17:27:11 -0500 | [diff] [blame] | 2112 | } |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 2113 | out: |
| 2114 | preempt_enable_notrace(); |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 2115 | unpause_graph_tracing(); |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 2116 | |
| 2117 | return len; |
| 2118 | } |
Steven Rostedt | 659372d | 2009-09-03 19:11:07 -0400 | [diff] [blame] | 2119 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2120 | int trace_array_vprintk(struct trace_array *tr, |
| 2121 | unsigned long ip, const char *fmt, va_list args) |
| 2122 | { |
| 2123 | return __trace_array_vprintk(tr->trace_buffer.buffer, ip, fmt, args); |
| 2124 | } |
| 2125 | |
| 2126 | int trace_array_printk(struct trace_array *tr, |
| 2127 | unsigned long ip, const char *fmt, ...) |
| 2128 | { |
| 2129 | int ret; |
| 2130 | va_list ap; |
| 2131 | |
| 2132 | if (!(trace_flags & TRACE_ITER_PRINTK)) |
| 2133 | return 0; |
| 2134 | |
| 2135 | va_start(ap, fmt); |
| 2136 | ret = trace_array_vprintk(tr, ip, fmt, ap); |
| 2137 | va_end(ap); |
| 2138 | return ret; |
| 2139 | } |
| 2140 | |
| 2141 | int trace_array_printk_buf(struct ring_buffer *buffer, |
| 2142 | unsigned long ip, const char *fmt, ...) |
| 2143 | { |
| 2144 | int ret; |
| 2145 | va_list ap; |
| 2146 | |
| 2147 | if (!(trace_flags & TRACE_ITER_PRINTK)) |
| 2148 | return 0; |
| 2149 | |
| 2150 | va_start(ap, fmt); |
| 2151 | ret = __trace_array_vprintk(buffer, ip, fmt, ap); |
| 2152 | va_end(ap); |
| 2153 | return ret; |
| 2154 | } |
| 2155 | |
Steven Rostedt | 659372d | 2009-09-03 19:11:07 -0400 | [diff] [blame] | 2156 | int trace_vprintk(unsigned long ip, const char *fmt, va_list args) |
| 2157 | { |
Steven Rostedt | a813a15 | 2009-10-09 01:41:35 -0400 | [diff] [blame] | 2158 | return trace_array_vprintk(&global_trace, ip, fmt, args); |
Steven Rostedt | 659372d | 2009-09-03 19:11:07 -0400 | [diff] [blame] | 2159 | } |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 2160 | EXPORT_SYMBOL_GPL(trace_vprintk); |
| 2161 | |
Robert Richter | e2ac8ef | 2008-11-12 12:59:32 +0100 | [diff] [blame] | 2162 | static void trace_iterator_increment(struct trace_iterator *iter) |
Steven Rostedt | 5a90f57 | 2008-09-03 17:42:51 -0400 | [diff] [blame] | 2163 | { |
Steven Rostedt | 6d158a8 | 2012-06-27 20:46:14 -0400 | [diff] [blame] | 2164 | struct ring_buffer_iter *buf_iter = trace_buffer_iter(iter, iter->cpu); |
| 2165 | |
Steven Rostedt | 5a90f57 | 2008-09-03 17:42:51 -0400 | [diff] [blame] | 2166 | iter->idx++; |
Steven Rostedt | 6d158a8 | 2012-06-27 20:46:14 -0400 | [diff] [blame] | 2167 | if (buf_iter) |
| 2168 | ring_buffer_read(buf_iter, NULL); |
Steven Rostedt | 5a90f57 | 2008-09-03 17:42:51 -0400 | [diff] [blame] | 2169 | } |
| 2170 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 2171 | static struct trace_entry * |
Steven Rostedt | bc21b47 | 2010-03-31 19:49:26 -0400 | [diff] [blame] | 2172 | peek_next_entry(struct trace_iterator *iter, int cpu, u64 *ts, |
| 2173 | unsigned long *lost_events) |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2174 | { |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2175 | struct ring_buffer_event *event; |
Steven Rostedt | 6d158a8 | 2012-06-27 20:46:14 -0400 | [diff] [blame] | 2176 | struct ring_buffer_iter *buf_iter = trace_buffer_iter(iter, cpu); |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2177 | |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 2178 | if (buf_iter) |
| 2179 | event = ring_buffer_iter_peek(buf_iter, ts); |
| 2180 | else |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2181 | event = ring_buffer_peek(iter->trace_buffer->buffer, cpu, ts, |
Steven Rostedt | bc21b47 | 2010-03-31 19:49:26 -0400 | [diff] [blame] | 2182 | lost_events); |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 2183 | |
Steven Rostedt | 4a9bd3f | 2011-07-14 16:36:53 -0400 | [diff] [blame] | 2184 | if (event) { |
| 2185 | iter->ent_size = ring_buffer_event_length(event); |
| 2186 | return ring_buffer_event_data(event); |
| 2187 | } |
| 2188 | iter->ent_size = 0; |
| 2189 | return NULL; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2190 | } |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 2191 | |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2192 | static struct trace_entry * |
Steven Rostedt | bc21b47 | 2010-03-31 19:49:26 -0400 | [diff] [blame] | 2193 | __find_next_entry(struct trace_iterator *iter, int *ent_cpu, |
| 2194 | unsigned long *missing_events, u64 *ent_ts) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2195 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2196 | struct ring_buffer *buffer = iter->trace_buffer->buffer; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2197 | struct trace_entry *ent, *next = NULL; |
Lai Jiangshan | aa27497 | 2010-04-05 17:11:05 +0800 | [diff] [blame] | 2198 | unsigned long lost_events = 0, next_lost = 0; |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 2199 | int cpu_file = iter->cpu_file; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2200 | u64 next_ts = 0, ts; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2201 | int next_cpu = -1; |
Steven Rostedt | 12b5da3 | 2012-03-27 10:43:28 -0400 | [diff] [blame] | 2202 | int next_size = 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2203 | int cpu; |
| 2204 | |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 2205 | /* |
| 2206 | * If we are in a per_cpu trace file, don't bother by iterating over |
| 2207 | * all cpu and peek directly. |
| 2208 | */ |
Steven Rostedt | ae3b509 | 2013-01-23 15:22:59 -0500 | [diff] [blame] | 2209 | if (cpu_file > RING_BUFFER_ALL_CPUS) { |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 2210 | if (ring_buffer_empty_cpu(buffer, cpu_file)) |
| 2211 | return NULL; |
Steven Rostedt | bc21b47 | 2010-03-31 19:49:26 -0400 | [diff] [blame] | 2212 | ent = peek_next_entry(iter, cpu_file, ent_ts, missing_events); |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 2213 | if (ent_cpu) |
| 2214 | *ent_cpu = cpu_file; |
| 2215 | |
| 2216 | return ent; |
| 2217 | } |
| 2218 | |
Steven Rostedt | ab46428 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 2219 | for_each_tracing_cpu(cpu) { |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2220 | |
| 2221 | if (ring_buffer_empty_cpu(buffer, cpu)) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2222 | continue; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2223 | |
Steven Rostedt | bc21b47 | 2010-03-31 19:49:26 -0400 | [diff] [blame] | 2224 | ent = peek_next_entry(iter, cpu, &ts, &lost_events); |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2225 | |
Ingo Molnar | cdd31cd2 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2226 | /* |
| 2227 | * Pick the entry with the smallest timestamp: |
| 2228 | */ |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2229 | if (ent && (!next || ts < next_ts)) { |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2230 | next = ent; |
| 2231 | next_cpu = cpu; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2232 | next_ts = ts; |
Steven Rostedt | bc21b47 | 2010-03-31 19:49:26 -0400 | [diff] [blame] | 2233 | next_lost = lost_events; |
Steven Rostedt | 12b5da3 | 2012-03-27 10:43:28 -0400 | [diff] [blame] | 2234 | next_size = iter->ent_size; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2235 | } |
| 2236 | } |
| 2237 | |
Steven Rostedt | 12b5da3 | 2012-03-27 10:43:28 -0400 | [diff] [blame] | 2238 | iter->ent_size = next_size; |
| 2239 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2240 | if (ent_cpu) |
| 2241 | *ent_cpu = next_cpu; |
| 2242 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2243 | if (ent_ts) |
| 2244 | *ent_ts = next_ts; |
| 2245 | |
Steven Rostedt | bc21b47 | 2010-03-31 19:49:26 -0400 | [diff] [blame] | 2246 | if (missing_events) |
| 2247 | *missing_events = next_lost; |
| 2248 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2249 | return next; |
| 2250 | } |
| 2251 | |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2252 | /* Find the next real entry, without updating the iterator itself */ |
Frederic Weisbecker | c4a8e8b | 2009-02-02 20:29:21 -0200 | [diff] [blame] | 2253 | struct trace_entry *trace_find_next_entry(struct trace_iterator *iter, |
| 2254 | int *ent_cpu, u64 *ent_ts) |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2255 | { |
Steven Rostedt | bc21b47 | 2010-03-31 19:49:26 -0400 | [diff] [blame] | 2256 | return __find_next_entry(iter, ent_cpu, NULL, ent_ts); |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2257 | } |
Ingo Molnar | 8c523a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2258 | |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2259 | /* Find the next real entry, and increment the iterator to the next entry */ |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 2260 | void *trace_find_next_entry_inc(struct trace_iterator *iter) |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2261 | { |
Steven Rostedt | bc21b47 | 2010-03-31 19:49:26 -0400 | [diff] [blame] | 2262 | iter->ent = __find_next_entry(iter, &iter->cpu, |
| 2263 | &iter->lost_events, &iter->ts); |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2264 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2265 | if (iter->ent) |
Robert Richter | e2ac8ef | 2008-11-12 12:59:32 +0100 | [diff] [blame] | 2266 | trace_iterator_increment(iter); |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2267 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2268 | return iter->ent ? iter : NULL; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2269 | } |
| 2270 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 2271 | static void trace_consume(struct trace_iterator *iter) |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2272 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2273 | ring_buffer_consume(iter->trace_buffer->buffer, iter->cpu, &iter->ts, |
Steven Rostedt | bc21b47 | 2010-03-31 19:49:26 -0400 | [diff] [blame] | 2274 | &iter->lost_events); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2275 | } |
| 2276 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 2277 | static void *s_next(struct seq_file *m, void *v, loff_t *pos) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2278 | { |
| 2279 | struct trace_iterator *iter = m->private; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2280 | int i = (int)*pos; |
Ingo Molnar | 4e3c333 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 2281 | void *ent; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2282 | |
Steven Rostedt | a63ce5b | 2009-12-07 09:11:39 -0500 | [diff] [blame] | 2283 | WARN_ON_ONCE(iter->leftover); |
| 2284 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2285 | (*pos)++; |
| 2286 | |
| 2287 | /* can't go backwards */ |
| 2288 | if (iter->idx > i) |
| 2289 | return NULL; |
| 2290 | |
| 2291 | if (iter->idx < 0) |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 2292 | ent = trace_find_next_entry_inc(iter); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2293 | else |
| 2294 | ent = iter; |
| 2295 | |
| 2296 | while (ent && iter->idx < i) |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 2297 | ent = trace_find_next_entry_inc(iter); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2298 | |
| 2299 | iter->pos = *pos; |
| 2300 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2301 | return ent; |
| 2302 | } |
| 2303 | |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 2304 | void tracing_iter_reset(struct trace_iterator *iter, int cpu) |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 2305 | { |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 2306 | struct ring_buffer_event *event; |
| 2307 | struct ring_buffer_iter *buf_iter; |
| 2308 | unsigned long entries = 0; |
| 2309 | u64 ts; |
| 2310 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2311 | per_cpu_ptr(iter->trace_buffer->data, cpu)->skipped_entries = 0; |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 2312 | |
Steven Rostedt | 6d158a8 | 2012-06-27 20:46:14 -0400 | [diff] [blame] | 2313 | buf_iter = trace_buffer_iter(iter, cpu); |
| 2314 | if (!buf_iter) |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 2315 | return; |
| 2316 | |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 2317 | ring_buffer_iter_reset(buf_iter); |
| 2318 | |
| 2319 | /* |
| 2320 | * We could have the case with the max latency tracers |
| 2321 | * that a reset never took place on a cpu. This is evident |
| 2322 | * by the timestamp being before the start of the buffer. |
| 2323 | */ |
| 2324 | while ((event = ring_buffer_iter_peek(buf_iter, &ts))) { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2325 | if (ts >= iter->trace_buffer->time_start) |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 2326 | break; |
| 2327 | entries++; |
| 2328 | ring_buffer_read(buf_iter, NULL); |
| 2329 | } |
| 2330 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2331 | per_cpu_ptr(iter->trace_buffer->data, cpu)->skipped_entries = entries; |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 2332 | } |
| 2333 | |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 2334 | /* |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 2335 | * The current tracer is copied to avoid a global locking |
| 2336 | * all around. |
| 2337 | */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2338 | static void *s_start(struct seq_file *m, loff_t *pos) |
| 2339 | { |
| 2340 | struct trace_iterator *iter = m->private; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 2341 | struct trace_array *tr = iter->tr; |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 2342 | int cpu_file = iter->cpu_file; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2343 | void *p = NULL; |
| 2344 | loff_t l = 0; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2345 | int cpu; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2346 | |
Hiraku Toyooka | 2fd196e | 2012-12-26 11:52:52 +0900 | [diff] [blame] | 2347 | /* |
| 2348 | * copy the tracer to avoid using a global lock all around. |
| 2349 | * iter->trace is a copy of current_trace, the pointer to the |
| 2350 | * name may be used instead of a strcmp(), as iter->trace->name |
| 2351 | * will point to the same string as current_trace->name. |
| 2352 | */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2353 | mutex_lock(&trace_types_lock); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 2354 | if (unlikely(tr->current_trace && iter->trace->name != tr->current_trace->name)) |
| 2355 | *iter->trace = *tr->current_trace; |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 2356 | mutex_unlock(&trace_types_lock); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2357 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2358 | #ifdef CONFIG_TRACER_MAX_TRACE |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 2359 | if (iter->snapshot && iter->trace->use_max_tr) |
| 2360 | return ERR_PTR(-EBUSY); |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2361 | #endif |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 2362 | |
| 2363 | if (!iter->snapshot) |
| 2364 | atomic_inc(&trace_record_cmdline_disabled); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2365 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2366 | if (*pos != iter->pos) { |
| 2367 | iter->ent = NULL; |
| 2368 | iter->cpu = 0; |
| 2369 | iter->idx = -1; |
| 2370 | |
Steven Rostedt | ae3b509 | 2013-01-23 15:22:59 -0500 | [diff] [blame] | 2371 | if (cpu_file == RING_BUFFER_ALL_CPUS) { |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 2372 | for_each_tracing_cpu(cpu) |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 2373 | tracing_iter_reset(iter, cpu); |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 2374 | } else |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 2375 | tracing_iter_reset(iter, cpu_file); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2376 | |
Lai Jiangshan | ac91d85 | 2010-03-02 17:54:50 +0800 | [diff] [blame] | 2377 | iter->leftover = 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2378 | for (p = iter; p && l < *pos; p = s_next(m, p, &l)) |
| 2379 | ; |
| 2380 | |
| 2381 | } else { |
Steven Rostedt | a63ce5b | 2009-12-07 09:11:39 -0500 | [diff] [blame] | 2382 | /* |
| 2383 | * If we overflowed the seq_file before, then we want |
| 2384 | * to just reuse the trace_seq buffer again. |
| 2385 | */ |
| 2386 | if (iter->leftover) |
| 2387 | p = iter; |
| 2388 | else { |
| 2389 | l = *pos - 1; |
| 2390 | p = s_next(m, p, &l); |
| 2391 | } |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2392 | } |
| 2393 | |
Lai Jiangshan | 4f53596 | 2009-05-18 19:35:34 +0800 | [diff] [blame] | 2394 | trace_event_read_lock(); |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 2395 | trace_access_lock(cpu_file); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2396 | return p; |
| 2397 | } |
| 2398 | |
| 2399 | static void s_stop(struct seq_file *m, void *p) |
| 2400 | { |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 2401 | struct trace_iterator *iter = m->private; |
| 2402 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2403 | #ifdef CONFIG_TRACER_MAX_TRACE |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 2404 | if (iter->snapshot && iter->trace->use_max_tr) |
| 2405 | return; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2406 | #endif |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 2407 | |
| 2408 | if (!iter->snapshot) |
| 2409 | atomic_dec(&trace_record_cmdline_disabled); |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2410 | |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 2411 | trace_access_unlock(iter->cpu_file); |
Lai Jiangshan | 4f53596 | 2009-05-18 19:35:34 +0800 | [diff] [blame] | 2412 | trace_event_read_unlock(); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2413 | } |
| 2414 | |
Steven Rostedt | 39eaf7e | 2011-11-17 10:35:16 -0500 | [diff] [blame] | 2415 | static void |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2416 | get_total_entries(struct trace_buffer *buf, |
| 2417 | unsigned long *total, unsigned long *entries) |
Steven Rostedt | 39eaf7e | 2011-11-17 10:35:16 -0500 | [diff] [blame] | 2418 | { |
| 2419 | unsigned long count; |
| 2420 | int cpu; |
| 2421 | |
| 2422 | *total = 0; |
| 2423 | *entries = 0; |
| 2424 | |
| 2425 | for_each_tracing_cpu(cpu) { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2426 | count = ring_buffer_entries_cpu(buf->buffer, cpu); |
Steven Rostedt | 39eaf7e | 2011-11-17 10:35:16 -0500 | [diff] [blame] | 2427 | /* |
| 2428 | * If this buffer has skipped entries, then we hold all |
| 2429 | * entries for the trace and we need to ignore the |
| 2430 | * ones before the time stamp. |
| 2431 | */ |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2432 | if (per_cpu_ptr(buf->data, cpu)->skipped_entries) { |
| 2433 | count -= per_cpu_ptr(buf->data, cpu)->skipped_entries; |
Steven Rostedt | 39eaf7e | 2011-11-17 10:35:16 -0500 | [diff] [blame] | 2434 | /* total is the same as the entries */ |
| 2435 | *total += count; |
| 2436 | } else |
| 2437 | *total += count + |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2438 | ring_buffer_overrun_cpu(buf->buffer, cpu); |
Steven Rostedt | 39eaf7e | 2011-11-17 10:35:16 -0500 | [diff] [blame] | 2439 | *entries += count; |
| 2440 | } |
| 2441 | } |
| 2442 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 2443 | static void print_lat_help_header(struct seq_file *m) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2444 | { |
Michael Ellerman | a616835 | 2008-08-20 16:36:11 -0700 | [diff] [blame] | 2445 | seq_puts(m, "# _------=> CPU# \n"); |
| 2446 | seq_puts(m, "# / _-----=> irqs-off \n"); |
| 2447 | seq_puts(m, "# | / _----=> need-resched \n"); |
| 2448 | seq_puts(m, "# || / _---=> hardirq/softirq \n"); |
| 2449 | seq_puts(m, "# ||| / _--=> preempt-depth \n"); |
Steven Rostedt | e6e1e25 | 2011-03-09 10:41:56 -0500 | [diff] [blame] | 2450 | seq_puts(m, "# |||| / delay \n"); |
| 2451 | seq_puts(m, "# cmd pid ||||| time | caller \n"); |
| 2452 | seq_puts(m, "# \\ / ||||| \\ | / \n"); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2453 | } |
| 2454 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2455 | static void print_event_info(struct trace_buffer *buf, struct seq_file *m) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2456 | { |
Steven Rostedt | 39eaf7e | 2011-11-17 10:35:16 -0500 | [diff] [blame] | 2457 | unsigned long total; |
| 2458 | unsigned long entries; |
| 2459 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2460 | get_total_entries(buf, &total, &entries); |
Steven Rostedt | 39eaf7e | 2011-11-17 10:35:16 -0500 | [diff] [blame] | 2461 | seq_printf(m, "# entries-in-buffer/entries-written: %lu/%lu #P:%d\n", |
| 2462 | entries, total, num_online_cpus()); |
| 2463 | seq_puts(m, "#\n"); |
| 2464 | } |
| 2465 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2466 | static void print_func_help_header(struct trace_buffer *buf, struct seq_file *m) |
Steven Rostedt | 39eaf7e | 2011-11-17 10:35:16 -0500 | [diff] [blame] | 2467 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2468 | print_event_info(buf, m); |
Steven Rostedt | 77271ce | 2011-11-17 09:34:33 -0500 | [diff] [blame] | 2469 | seq_puts(m, "# TASK-PID CPU# TIMESTAMP FUNCTION\n"); |
Michael Ellerman | a616835 | 2008-08-20 16:36:11 -0700 | [diff] [blame] | 2470 | seq_puts(m, "# | | | | |\n"); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2471 | } |
| 2472 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2473 | static void print_func_help_header_irq(struct trace_buffer *buf, struct seq_file *m) |
Steven Rostedt | 77271ce | 2011-11-17 09:34:33 -0500 | [diff] [blame] | 2474 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2475 | print_event_info(buf, m); |
Steven Rostedt | 77271ce | 2011-11-17 09:34:33 -0500 | [diff] [blame] | 2476 | seq_puts(m, "# _-----=> irqs-off\n"); |
| 2477 | seq_puts(m, "# / _----=> need-resched\n"); |
| 2478 | seq_puts(m, "# | / _---=> hardirq/softirq\n"); |
| 2479 | seq_puts(m, "# || / _--=> preempt-depth\n"); |
| 2480 | seq_puts(m, "# ||| / delay\n"); |
| 2481 | seq_puts(m, "# TASK-PID CPU# |||| TIMESTAMP FUNCTION\n"); |
| 2482 | seq_puts(m, "# | | | |||| | |\n"); |
| 2483 | } |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2484 | |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 2485 | void |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2486 | print_trace_header(struct seq_file *m, struct trace_iterator *iter) |
| 2487 | { |
| 2488 | unsigned long sym_flags = (trace_flags & TRACE_ITER_SYM_MASK); |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2489 | struct trace_buffer *buf = iter->trace_buffer; |
| 2490 | struct trace_array_cpu *data = per_cpu_ptr(buf->data, buf->cpu); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 2491 | struct tracer *type = iter->trace; |
Steven Rostedt | 39eaf7e | 2011-11-17 10:35:16 -0500 | [diff] [blame] | 2492 | unsigned long entries; |
| 2493 | unsigned long total; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2494 | const char *name = "preemption"; |
| 2495 | |
Steven Rostedt (Red Hat) | d840f71 | 2013-02-01 18:38:47 -0500 | [diff] [blame] | 2496 | name = type->name; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2497 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2498 | get_total_entries(buf, &total, &entries); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2499 | |
KOSAKI Motohiro | 888b55d | 2009-03-08 13:12:43 +0900 | [diff] [blame] | 2500 | seq_printf(m, "# %s latency trace v1.1.5 on %s\n", |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2501 | name, UTS_RELEASE); |
KOSAKI Motohiro | 888b55d | 2009-03-08 13:12:43 +0900 | [diff] [blame] | 2502 | seq_puts(m, "# -----------------------------------" |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2503 | "---------------------------------\n"); |
KOSAKI Motohiro | 888b55d | 2009-03-08 13:12:43 +0900 | [diff] [blame] | 2504 | seq_printf(m, "# latency: %lu us, #%lu/%lu, CPU#%d |" |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2505 | " (M:%s VP:%d, KP:%d, SP:%d HP:%d", |
Steven Rostedt | 57f50be | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 2506 | nsecs_to_usecs(data->saved_latency), |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2507 | entries, |
Steven Rostedt | 4c11d7a | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 2508 | total, |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2509 | buf->cpu, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2510 | #if defined(CONFIG_PREEMPT_NONE) |
| 2511 | "server", |
| 2512 | #elif defined(CONFIG_PREEMPT_VOLUNTARY) |
| 2513 | "desktop", |
Steven Rostedt | b5c21b4 | 2008-07-10 20:58:12 -0400 | [diff] [blame] | 2514 | #elif defined(CONFIG_PREEMPT) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2515 | "preempt", |
| 2516 | #else |
| 2517 | "unknown", |
| 2518 | #endif |
| 2519 | /* These are reserved for later use */ |
| 2520 | 0, 0, 0, 0); |
| 2521 | #ifdef CONFIG_SMP |
| 2522 | seq_printf(m, " #P:%d)\n", num_online_cpus()); |
| 2523 | #else |
| 2524 | seq_puts(m, ")\n"); |
| 2525 | #endif |
KOSAKI Motohiro | 888b55d | 2009-03-08 13:12:43 +0900 | [diff] [blame] | 2526 | seq_puts(m, "# -----------------\n"); |
| 2527 | seq_printf(m, "# | task: %.16s-%d " |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2528 | "(uid:%d nice:%ld policy:%ld rt_prio:%ld)\n", |
Eric W. Biederman | d20b92a | 2012-03-13 16:02:19 -0700 | [diff] [blame] | 2529 | data->comm, data->pid, |
| 2530 | from_kuid_munged(seq_user_ns(m), data->uid), data->nice, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2531 | data->policy, data->rt_priority); |
KOSAKI Motohiro | 888b55d | 2009-03-08 13:12:43 +0900 | [diff] [blame] | 2532 | seq_puts(m, "# -----------------\n"); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2533 | |
| 2534 | if (data->critical_start) { |
KOSAKI Motohiro | 888b55d | 2009-03-08 13:12:43 +0900 | [diff] [blame] | 2535 | seq_puts(m, "# => started at: "); |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2536 | seq_print_ip_sym(&iter->seq, data->critical_start, sym_flags); |
| 2537 | trace_print_seq(m, &iter->seq); |
KOSAKI Motohiro | 888b55d | 2009-03-08 13:12:43 +0900 | [diff] [blame] | 2538 | seq_puts(m, "\n# => ended at: "); |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2539 | seq_print_ip_sym(&iter->seq, data->critical_end, sym_flags); |
| 2540 | trace_print_seq(m, &iter->seq); |
Steven Rostedt | 8248ac0 | 2009-09-02 12:27:41 -0400 | [diff] [blame] | 2541 | seq_puts(m, "\n#\n"); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2542 | } |
| 2543 | |
KOSAKI Motohiro | 888b55d | 2009-03-08 13:12:43 +0900 | [diff] [blame] | 2544 | seq_puts(m, "#\n"); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2545 | } |
| 2546 | |
Steven Rostedt | a309720 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 2547 | static void test_cpu_buff_start(struct trace_iterator *iter) |
| 2548 | { |
| 2549 | struct trace_seq *s = &iter->seq; |
| 2550 | |
Steven Rostedt | 12ef7d4 | 2008-11-12 17:52:38 -0500 | [diff] [blame] | 2551 | if (!(trace_flags & TRACE_ITER_ANNOTATE)) |
| 2552 | return; |
| 2553 | |
| 2554 | if (!(iter->iter_flags & TRACE_FILE_ANNOTATE)) |
| 2555 | return; |
| 2556 | |
Rusty Russell | 4462344 | 2009-01-01 10:12:23 +1030 | [diff] [blame] | 2557 | if (cpumask_test_cpu(iter->cpu, iter->started)) |
Steven Rostedt | a309720 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 2558 | return; |
| 2559 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2560 | if (per_cpu_ptr(iter->trace_buffer->data, iter->cpu)->skipped_entries) |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 2561 | return; |
| 2562 | |
Rusty Russell | 4462344 | 2009-01-01 10:12:23 +1030 | [diff] [blame] | 2563 | cpumask_set_cpu(iter->cpu, iter->started); |
Frederic Weisbecker | b0dfa97 | 2009-04-01 22:53:08 +0200 | [diff] [blame] | 2564 | |
| 2565 | /* Don't print started cpu buffer for the first entry of the trace */ |
| 2566 | if (iter->idx > 1) |
| 2567 | trace_seq_printf(s, "##### CPU %u buffer started ####\n", |
| 2568 | iter->cpu); |
Steven Rostedt | a309720 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 2569 | } |
| 2570 | |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 2571 | static enum print_line_t print_trace_fmt(struct trace_iterator *iter) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2572 | { |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2573 | struct trace_seq *s = &iter->seq; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2574 | unsigned long sym_flags = (trace_flags & TRACE_ITER_SYM_MASK); |
Ingo Molnar | 4e3c333 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 2575 | struct trace_entry *entry; |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 2576 | struct trace_event *event; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2577 | |
Ingo Molnar | 4e3c333 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 2578 | entry = iter->ent; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2579 | |
Steven Rostedt | a309720 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 2580 | test_cpu_buff_start(iter); |
| 2581 | |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 2582 | event = ftrace_find_event(entry->type); |
Frederic Weisbecker | c4a8e8b | 2009-02-02 20:29:21 -0200 | [diff] [blame] | 2583 | |
| 2584 | if (trace_flags & TRACE_ITER_CONTEXT_INFO) { |
Steven Rostedt | 27d48be | 2009-03-04 21:57:29 -0500 | [diff] [blame] | 2585 | if (iter->iter_flags & TRACE_FILE_LAT_FMT) { |
| 2586 | if (!trace_print_lat_context(iter)) |
| 2587 | goto partial; |
| 2588 | } else { |
| 2589 | if (!trace_print_context(iter)) |
| 2590 | goto partial; |
| 2591 | } |
Frederic Weisbecker | c4a8e8b | 2009-02-02 20:29:21 -0200 | [diff] [blame] | 2592 | } |
| 2593 | |
Arnaldo Carvalho de Melo | 268ccda | 2009-02-04 20:16:39 -0200 | [diff] [blame] | 2594 | if (event) |
Steven Rostedt | a9a5776 | 2010-04-22 18:46:14 -0400 | [diff] [blame] | 2595 | return event->funcs->trace(iter, sym_flags, event); |
Arnaldo Carvalho de Melo | d9793bd | 2009-02-03 20:20:41 -0200 | [diff] [blame] | 2596 | |
| 2597 | if (!trace_seq_printf(s, "Unknown type %d\n", entry->type)) |
| 2598 | goto partial; |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 2599 | |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 2600 | return TRACE_TYPE_HANDLED; |
Arnaldo Carvalho de Melo | d9793bd | 2009-02-03 20:20:41 -0200 | [diff] [blame] | 2601 | partial: |
| 2602 | return TRACE_TYPE_PARTIAL_LINE; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2603 | } |
| 2604 | |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 2605 | static enum print_line_t print_raw_fmt(struct trace_iterator *iter) |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2606 | { |
| 2607 | struct trace_seq *s = &iter->seq; |
| 2608 | struct trace_entry *entry; |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 2609 | struct trace_event *event; |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2610 | |
| 2611 | entry = iter->ent; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2612 | |
Frederic Weisbecker | c4a8e8b | 2009-02-02 20:29:21 -0200 | [diff] [blame] | 2613 | if (trace_flags & TRACE_ITER_CONTEXT_INFO) { |
Arnaldo Carvalho de Melo | d9793bd | 2009-02-03 20:20:41 -0200 | [diff] [blame] | 2614 | if (!trace_seq_printf(s, "%d %d %llu ", |
| 2615 | entry->pid, iter->cpu, iter->ts)) |
| 2616 | goto partial; |
Frederic Weisbecker | c4a8e8b | 2009-02-02 20:29:21 -0200 | [diff] [blame] | 2617 | } |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2618 | |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 2619 | event = ftrace_find_event(entry->type); |
Arnaldo Carvalho de Melo | 268ccda | 2009-02-04 20:16:39 -0200 | [diff] [blame] | 2620 | if (event) |
Steven Rostedt | a9a5776 | 2010-04-22 18:46:14 -0400 | [diff] [blame] | 2621 | return event->funcs->raw(iter, 0, event); |
Arnaldo Carvalho de Melo | d9793bd | 2009-02-03 20:20:41 -0200 | [diff] [blame] | 2622 | |
| 2623 | if (!trace_seq_printf(s, "%d ?\n", entry->type)) |
| 2624 | goto partial; |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 2625 | |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 2626 | return TRACE_TYPE_HANDLED; |
Arnaldo Carvalho de Melo | d9793bd | 2009-02-03 20:20:41 -0200 | [diff] [blame] | 2627 | partial: |
| 2628 | return TRACE_TYPE_PARTIAL_LINE; |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2629 | } |
| 2630 | |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 2631 | static enum print_line_t print_hex_fmt(struct trace_iterator *iter) |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 2632 | { |
| 2633 | struct trace_seq *s = &iter->seq; |
| 2634 | unsigned char newline = '\n'; |
| 2635 | struct trace_entry *entry; |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 2636 | struct trace_event *event; |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 2637 | |
| 2638 | entry = iter->ent; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2639 | |
Frederic Weisbecker | c4a8e8b | 2009-02-02 20:29:21 -0200 | [diff] [blame] | 2640 | if (trace_flags & TRACE_ITER_CONTEXT_INFO) { |
| 2641 | SEQ_PUT_HEX_FIELD_RET(s, entry->pid); |
| 2642 | SEQ_PUT_HEX_FIELD_RET(s, iter->cpu); |
| 2643 | SEQ_PUT_HEX_FIELD_RET(s, iter->ts); |
| 2644 | } |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 2645 | |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 2646 | event = ftrace_find_event(entry->type); |
Arnaldo Carvalho de Melo | 268ccda | 2009-02-04 20:16:39 -0200 | [diff] [blame] | 2647 | if (event) { |
Steven Rostedt | a9a5776 | 2010-04-22 18:46:14 -0400 | [diff] [blame] | 2648 | enum print_line_t ret = event->funcs->hex(iter, 0, event); |
Arnaldo Carvalho de Melo | d9793bd | 2009-02-03 20:20:41 -0200 | [diff] [blame] | 2649 | if (ret != TRACE_TYPE_HANDLED) |
| 2650 | return ret; |
| 2651 | } |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 2652 | |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 2653 | SEQ_PUT_FIELD_RET(s, newline); |
| 2654 | |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 2655 | return TRACE_TYPE_HANDLED; |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 2656 | } |
| 2657 | |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 2658 | static enum print_line_t print_bin_fmt(struct trace_iterator *iter) |
Ingo Molnar | cb0f12a | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2659 | { |
| 2660 | struct trace_seq *s = &iter->seq; |
| 2661 | struct trace_entry *entry; |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 2662 | struct trace_event *event; |
Ingo Molnar | cb0f12a | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2663 | |
| 2664 | entry = iter->ent; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2665 | |
Frederic Weisbecker | c4a8e8b | 2009-02-02 20:29:21 -0200 | [diff] [blame] | 2666 | if (trace_flags & TRACE_ITER_CONTEXT_INFO) { |
| 2667 | SEQ_PUT_FIELD_RET(s, entry->pid); |
Steven Rostedt | 1830b52 | 2009-02-07 19:38:43 -0500 | [diff] [blame] | 2668 | SEQ_PUT_FIELD_RET(s, iter->cpu); |
Frederic Weisbecker | c4a8e8b | 2009-02-02 20:29:21 -0200 | [diff] [blame] | 2669 | SEQ_PUT_FIELD_RET(s, iter->ts); |
| 2670 | } |
Ingo Molnar | cb0f12a | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2671 | |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 2672 | event = ftrace_find_event(entry->type); |
Steven Rostedt | a9a5776 | 2010-04-22 18:46:14 -0400 | [diff] [blame] | 2673 | return event ? event->funcs->binary(iter, 0, event) : |
| 2674 | TRACE_TYPE_HANDLED; |
Ingo Molnar | cb0f12a | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2675 | } |
| 2676 | |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 2677 | int trace_empty(struct trace_iterator *iter) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2678 | { |
Steven Rostedt | 6d158a8 | 2012-06-27 20:46:14 -0400 | [diff] [blame] | 2679 | struct ring_buffer_iter *buf_iter; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2680 | int cpu; |
| 2681 | |
Steven Rostedt | 9aba60f | 2009-03-11 19:52:30 -0400 | [diff] [blame] | 2682 | /* If we are looking at one CPU buffer, only check that one */ |
Steven Rostedt | ae3b509 | 2013-01-23 15:22:59 -0500 | [diff] [blame] | 2683 | if (iter->cpu_file != RING_BUFFER_ALL_CPUS) { |
Steven Rostedt | 9aba60f | 2009-03-11 19:52:30 -0400 | [diff] [blame] | 2684 | cpu = iter->cpu_file; |
Steven Rostedt | 6d158a8 | 2012-06-27 20:46:14 -0400 | [diff] [blame] | 2685 | buf_iter = trace_buffer_iter(iter, cpu); |
| 2686 | if (buf_iter) { |
| 2687 | if (!ring_buffer_iter_empty(buf_iter)) |
Steven Rostedt | 9aba60f | 2009-03-11 19:52:30 -0400 | [diff] [blame] | 2688 | return 0; |
| 2689 | } else { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2690 | if (!ring_buffer_empty_cpu(iter->trace_buffer->buffer, cpu)) |
Steven Rostedt | 9aba60f | 2009-03-11 19:52:30 -0400 | [diff] [blame] | 2691 | return 0; |
| 2692 | } |
| 2693 | return 1; |
| 2694 | } |
| 2695 | |
Steven Rostedt | ab46428 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 2696 | for_each_tracing_cpu(cpu) { |
Steven Rostedt | 6d158a8 | 2012-06-27 20:46:14 -0400 | [diff] [blame] | 2697 | buf_iter = trace_buffer_iter(iter, cpu); |
| 2698 | if (buf_iter) { |
| 2699 | if (!ring_buffer_iter_empty(buf_iter)) |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 2700 | return 0; |
| 2701 | } else { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2702 | if (!ring_buffer_empty_cpu(iter->trace_buffer->buffer, cpu)) |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 2703 | return 0; |
| 2704 | } |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2705 | } |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 2706 | |
Frederic Weisbecker | 797d371 | 2008-09-30 18:13:45 +0200 | [diff] [blame] | 2707 | return 1; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2708 | } |
| 2709 | |
Lai Jiangshan | 4f53596 | 2009-05-18 19:35:34 +0800 | [diff] [blame] | 2710 | /* Called with trace_event_read_lock() held. */ |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 2711 | enum print_line_t print_trace_line(struct trace_iterator *iter) |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2712 | { |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 2713 | enum print_line_t ret; |
| 2714 | |
Jiri Olsa | ee5e51f | 2011-03-25 12:05:18 +0100 | [diff] [blame] | 2715 | if (iter->lost_events && |
| 2716 | !trace_seq_printf(&iter->seq, "CPU:%d [LOST %lu EVENTS]\n", |
| 2717 | iter->cpu, iter->lost_events)) |
| 2718 | return TRACE_TYPE_PARTIAL_LINE; |
Steven Rostedt | bc21b47 | 2010-03-31 19:49:26 -0400 | [diff] [blame] | 2719 | |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 2720 | if (iter->trace && iter->trace->print_line) { |
| 2721 | ret = iter->trace->print_line(iter); |
| 2722 | if (ret != TRACE_TYPE_UNHANDLED) |
| 2723 | return ret; |
| 2724 | } |
Thomas Gleixner | 72829bc | 2008-05-23 21:37:28 +0200 | [diff] [blame] | 2725 | |
Steven Rostedt (Red Hat) | 09ae723 | 2013-03-08 21:02:34 -0500 | [diff] [blame] | 2726 | if (iter->ent->type == TRACE_BPUTS && |
| 2727 | trace_flags & TRACE_ITER_PRINTK && |
| 2728 | trace_flags & TRACE_ITER_PRINTK_MSGONLY) |
| 2729 | return trace_print_bputs_msg_only(iter); |
| 2730 | |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 2731 | if (iter->ent->type == TRACE_BPRINT && |
| 2732 | trace_flags & TRACE_ITER_PRINTK && |
| 2733 | trace_flags & TRACE_ITER_PRINTK_MSGONLY) |
Steven Rostedt | 5ef841f | 2009-03-19 12:20:38 -0400 | [diff] [blame] | 2734 | return trace_print_bprintk_msg_only(iter); |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 2735 | |
Frederic Weisbecker | 66896a8 | 2008-12-13 20:18:13 +0100 | [diff] [blame] | 2736 | if (iter->ent->type == TRACE_PRINT && |
| 2737 | trace_flags & TRACE_ITER_PRINTK && |
| 2738 | trace_flags & TRACE_ITER_PRINTK_MSGONLY) |
Steven Rostedt | 5ef841f | 2009-03-19 12:20:38 -0400 | [diff] [blame] | 2739 | return trace_print_printk_msg_only(iter); |
Frederic Weisbecker | 66896a8 | 2008-12-13 20:18:13 +0100 | [diff] [blame] | 2740 | |
Ingo Molnar | cb0f12a | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2741 | if (trace_flags & TRACE_ITER_BIN) |
| 2742 | return print_bin_fmt(iter); |
| 2743 | |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 2744 | if (trace_flags & TRACE_ITER_HEX) |
| 2745 | return print_hex_fmt(iter); |
| 2746 | |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2747 | if (trace_flags & TRACE_ITER_RAW) |
| 2748 | return print_raw_fmt(iter); |
| 2749 | |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2750 | return print_trace_fmt(iter); |
| 2751 | } |
| 2752 | |
Jiri Olsa | 7e9a49e | 2011-11-07 16:08:49 +0100 | [diff] [blame] | 2753 | void trace_latency_header(struct seq_file *m) |
| 2754 | { |
| 2755 | struct trace_iterator *iter = m->private; |
| 2756 | |
| 2757 | /* print nothing if the buffers are empty */ |
| 2758 | if (trace_empty(iter)) |
| 2759 | return; |
| 2760 | |
| 2761 | if (iter->iter_flags & TRACE_FILE_LAT_FMT) |
| 2762 | print_trace_header(m, iter); |
| 2763 | |
| 2764 | if (!(trace_flags & TRACE_ITER_VERBOSE)) |
| 2765 | print_lat_help_header(m); |
| 2766 | } |
| 2767 | |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 2768 | void trace_default_header(struct seq_file *m) |
| 2769 | { |
| 2770 | struct trace_iterator *iter = m->private; |
| 2771 | |
Jiri Olsa | f56e7f8 | 2011-06-03 16:58:49 +0200 | [diff] [blame] | 2772 | if (!(trace_flags & TRACE_ITER_CONTEXT_INFO)) |
| 2773 | return; |
| 2774 | |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 2775 | if (iter->iter_flags & TRACE_FILE_LAT_FMT) { |
| 2776 | /* print nothing if the buffers are empty */ |
| 2777 | if (trace_empty(iter)) |
| 2778 | return; |
| 2779 | print_trace_header(m, iter); |
| 2780 | if (!(trace_flags & TRACE_ITER_VERBOSE)) |
| 2781 | print_lat_help_header(m); |
| 2782 | } else { |
Steven Rostedt | 77271ce | 2011-11-17 09:34:33 -0500 | [diff] [blame] | 2783 | if (!(trace_flags & TRACE_ITER_VERBOSE)) { |
| 2784 | if (trace_flags & TRACE_ITER_IRQ_INFO) |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2785 | print_func_help_header_irq(iter->trace_buffer, m); |
Steven Rostedt | 77271ce | 2011-11-17 09:34:33 -0500 | [diff] [blame] | 2786 | else |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2787 | print_func_help_header(iter->trace_buffer, m); |
Steven Rostedt | 77271ce | 2011-11-17 09:34:33 -0500 | [diff] [blame] | 2788 | } |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 2789 | } |
| 2790 | } |
| 2791 | |
Steven Rostedt | e0a413f | 2011-09-29 21:26:16 -0400 | [diff] [blame] | 2792 | static void test_ftrace_alive(struct seq_file *m) |
| 2793 | { |
| 2794 | if (!ftrace_is_dead()) |
| 2795 | return; |
| 2796 | seq_printf(m, "# WARNING: FUNCTION TRACING IS CORRUPTED\n"); |
| 2797 | seq_printf(m, "# MAY BE MISSING FUNCTION EVENTS\n"); |
| 2798 | } |
| 2799 | |
Steven Rostedt (Red Hat) | d8741e2 | 2013-03-05 10:25:16 -0500 | [diff] [blame] | 2800 | #ifdef CONFIG_TRACER_MAX_TRACE |
Steven Rostedt (Red Hat) | f1affca | 2013-03-05 14:35:11 -0500 | [diff] [blame] | 2801 | static void show_snapshot_main_help(struct seq_file *m) |
Steven Rostedt (Red Hat) | d8741e2 | 2013-03-05 10:25:16 -0500 | [diff] [blame] | 2802 | { |
Steven Rostedt (Red Hat) | d8741e2 | 2013-03-05 10:25:16 -0500 | [diff] [blame] | 2803 | seq_printf(m, "# echo 0 > snapshot : Clears and frees snapshot buffer\n"); |
| 2804 | seq_printf(m, "# echo 1 > snapshot : Allocates snapshot buffer, if not already allocated.\n"); |
| 2805 | seq_printf(m, "# Takes a snapshot of the main buffer.\n"); |
Wang YanQing | b9be6d0 | 2013-09-14 12:59:16 +0800 | [diff] [blame] | 2806 | seq_printf(m, "# echo 2 > snapshot : Clears snapshot buffer (but does not allocate or free)\n"); |
Steven Rostedt (Red Hat) | d8741e2 | 2013-03-05 10:25:16 -0500 | [diff] [blame] | 2807 | seq_printf(m, "# (Doesn't have to be '2' works with any number that\n"); |
| 2808 | seq_printf(m, "# is not a '0' or '1')\n"); |
| 2809 | } |
Steven Rostedt (Red Hat) | f1affca | 2013-03-05 14:35:11 -0500 | [diff] [blame] | 2810 | |
| 2811 | static void show_snapshot_percpu_help(struct seq_file *m) |
| 2812 | { |
| 2813 | seq_printf(m, "# echo 0 > snapshot : Invalid for per_cpu snapshot file.\n"); |
| 2814 | #ifdef CONFIG_RING_BUFFER_ALLOW_SWAP |
| 2815 | seq_printf(m, "# echo 1 > snapshot : Allocates snapshot buffer, if not already allocated.\n"); |
| 2816 | seq_printf(m, "# Takes a snapshot of the main buffer for this cpu.\n"); |
| 2817 | #else |
| 2818 | seq_printf(m, "# echo 1 > snapshot : Not supported with this kernel.\n"); |
| 2819 | seq_printf(m, "# Must use main snapshot file to allocate.\n"); |
| 2820 | #endif |
| 2821 | seq_printf(m, "# echo 2 > snapshot : Clears this cpu's snapshot buffer (but does not allocate)\n"); |
| 2822 | seq_printf(m, "# (Doesn't have to be '2' works with any number that\n"); |
| 2823 | seq_printf(m, "# is not a '0' or '1')\n"); |
| 2824 | } |
| 2825 | |
Steven Rostedt (Red Hat) | d8741e2 | 2013-03-05 10:25:16 -0500 | [diff] [blame] | 2826 | static void print_snapshot_help(struct seq_file *m, struct trace_iterator *iter) |
| 2827 | { |
Steven Rostedt (Red Hat) | 45ad21c | 2013-03-05 18:25:02 -0500 | [diff] [blame] | 2828 | if (iter->tr->allocated_snapshot) |
Steven Rostedt (Red Hat) | d8741e2 | 2013-03-05 10:25:16 -0500 | [diff] [blame] | 2829 | seq_printf(m, "#\n# * Snapshot is allocated *\n#\n"); |
| 2830 | else |
| 2831 | seq_printf(m, "#\n# * Snapshot is freed *\n#\n"); |
| 2832 | |
| 2833 | seq_printf(m, "# Snapshot commands:\n"); |
Steven Rostedt (Red Hat) | f1affca | 2013-03-05 14:35:11 -0500 | [diff] [blame] | 2834 | if (iter->cpu_file == RING_BUFFER_ALL_CPUS) |
| 2835 | show_snapshot_main_help(m); |
| 2836 | else |
| 2837 | show_snapshot_percpu_help(m); |
Steven Rostedt (Red Hat) | d8741e2 | 2013-03-05 10:25:16 -0500 | [diff] [blame] | 2838 | } |
| 2839 | #else |
| 2840 | /* Should never be called */ |
| 2841 | static inline void print_snapshot_help(struct seq_file *m, struct trace_iterator *iter) { } |
| 2842 | #endif |
| 2843 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2844 | static int s_show(struct seq_file *m, void *v) |
| 2845 | { |
| 2846 | struct trace_iterator *iter = v; |
Steven Rostedt | a63ce5b | 2009-12-07 09:11:39 -0500 | [diff] [blame] | 2847 | int ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2848 | |
| 2849 | if (iter->ent == NULL) { |
| 2850 | if (iter->tr) { |
| 2851 | seq_printf(m, "# tracer: %s\n", iter->trace->name); |
| 2852 | seq_puts(m, "#\n"); |
Steven Rostedt | e0a413f | 2011-09-29 21:26:16 -0400 | [diff] [blame] | 2853 | test_ftrace_alive(m); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2854 | } |
Steven Rostedt (Red Hat) | d8741e2 | 2013-03-05 10:25:16 -0500 | [diff] [blame] | 2855 | if (iter->snapshot && trace_empty(iter)) |
| 2856 | print_snapshot_help(m, iter); |
| 2857 | else if (iter->trace && iter->trace->print_header) |
Markus Metzger | 8bba1bf | 2008-11-25 09:12:31 +0100 | [diff] [blame] | 2858 | iter->trace->print_header(m); |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 2859 | else |
| 2860 | trace_default_header(m); |
| 2861 | |
Steven Rostedt | a63ce5b | 2009-12-07 09:11:39 -0500 | [diff] [blame] | 2862 | } else if (iter->leftover) { |
| 2863 | /* |
| 2864 | * If we filled the seq_file buffer earlier, we |
| 2865 | * want to just show it now. |
| 2866 | */ |
| 2867 | ret = trace_print_seq(m, &iter->seq); |
| 2868 | |
| 2869 | /* ret should this time be zero, but you never know */ |
| 2870 | iter->leftover = ret; |
| 2871 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2872 | } else { |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2873 | print_trace_line(iter); |
Steven Rostedt | a63ce5b | 2009-12-07 09:11:39 -0500 | [diff] [blame] | 2874 | ret = trace_print_seq(m, &iter->seq); |
| 2875 | /* |
| 2876 | * If we overflow the seq_file buffer, then it will |
| 2877 | * ask us for this data again at start up. |
| 2878 | * Use that instead. |
| 2879 | * ret is 0 if seq_file write succeeded. |
| 2880 | * -1 otherwise. |
| 2881 | */ |
| 2882 | iter->leftover = ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2883 | } |
| 2884 | |
| 2885 | return 0; |
| 2886 | } |
| 2887 | |
Oleg Nesterov | 649e9c70 | 2013-07-23 17:25:54 +0200 | [diff] [blame] | 2888 | /* |
| 2889 | * Should be used after trace_array_get(), trace_types_lock |
| 2890 | * ensures that i_cdev was already initialized. |
| 2891 | */ |
| 2892 | static inline int tracing_get_cpu(struct inode *inode) |
| 2893 | { |
| 2894 | if (inode->i_cdev) /* See trace_create_cpu_file() */ |
| 2895 | return (long)inode->i_cdev - 1; |
| 2896 | return RING_BUFFER_ALL_CPUS; |
| 2897 | } |
| 2898 | |
James Morris | 88e9d34 | 2009-09-22 16:43:43 -0700 | [diff] [blame] | 2899 | static const struct seq_operations tracer_seq_ops = { |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2900 | .start = s_start, |
| 2901 | .next = s_next, |
| 2902 | .stop = s_stop, |
| 2903 | .show = s_show, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2904 | }; |
| 2905 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 2906 | static struct trace_iterator * |
Oleg Nesterov | 6484c71 | 2013-07-23 17:26:10 +0200 | [diff] [blame] | 2907 | __tracing_open(struct inode *inode, struct file *file, bool snapshot) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2908 | { |
Oleg Nesterov | 6484c71 | 2013-07-23 17:26:10 +0200 | [diff] [blame] | 2909 | struct trace_array *tr = inode->i_private; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2910 | struct trace_iterator *iter; |
Jiri Olsa | 50e18b9 | 2012-04-25 10:23:39 +0200 | [diff] [blame] | 2911 | int cpu; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2912 | |
Steven Rostedt | 85a2f9b | 2009-02-27 00:12:38 -0500 | [diff] [blame] | 2913 | if (tracing_disabled) |
| 2914 | return ERR_PTR(-ENODEV); |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 2915 | |
Jiri Olsa | 50e18b9 | 2012-04-25 10:23:39 +0200 | [diff] [blame] | 2916 | iter = __seq_open_private(file, &tracer_seq_ops, sizeof(*iter)); |
Steven Rostedt | 85a2f9b | 2009-02-27 00:12:38 -0500 | [diff] [blame] | 2917 | if (!iter) |
| 2918 | return ERR_PTR(-ENOMEM); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2919 | |
Steven Rostedt | 6d158a8 | 2012-06-27 20:46:14 -0400 | [diff] [blame] | 2920 | iter->buffer_iter = kzalloc(sizeof(*iter->buffer_iter) * num_possible_cpus(), |
| 2921 | GFP_KERNEL); |
Dan Carpenter | 93574fc | 2012-07-11 09:35:08 +0300 | [diff] [blame] | 2922 | if (!iter->buffer_iter) |
| 2923 | goto release; |
| 2924 | |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 2925 | /* |
| 2926 | * We make a copy of the current tracer to avoid concurrent |
| 2927 | * changes on it while we are reading. |
| 2928 | */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2929 | mutex_lock(&trace_types_lock); |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 2930 | iter->trace = kzalloc(sizeof(*iter->trace), GFP_KERNEL); |
Steven Rostedt | 85a2f9b | 2009-02-27 00:12:38 -0500 | [diff] [blame] | 2931 | if (!iter->trace) |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 2932 | goto fail; |
Steven Rostedt | 85a2f9b | 2009-02-27 00:12:38 -0500 | [diff] [blame] | 2933 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 2934 | *iter->trace = *tr->current_trace; |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 2935 | |
Li Zefan | 79f5599 | 2009-06-15 14:58:26 +0800 | [diff] [blame] | 2936 | if (!zalloc_cpumask_var(&iter->started, GFP_KERNEL)) |
Frederic Weisbecker | b0dfa97 | 2009-04-01 22:53:08 +0200 | [diff] [blame] | 2937 | goto fail; |
| 2938 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2939 | iter->tr = tr; |
| 2940 | |
| 2941 | #ifdef CONFIG_TRACER_MAX_TRACE |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 2942 | /* Currently only the top directory has a snapshot */ |
| 2943 | if (tr->current_trace->print_max || snapshot) |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2944 | iter->trace_buffer = &tr->max_buffer; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2945 | else |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2946 | #endif |
| 2947 | iter->trace_buffer = &tr->trace_buffer; |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 2948 | iter->snapshot = snapshot; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2949 | iter->pos = -1; |
Oleg Nesterov | 6484c71 | 2013-07-23 17:26:10 +0200 | [diff] [blame] | 2950 | iter->cpu_file = tracing_get_cpu(inode); |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 2951 | mutex_init(&iter->mutex); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2952 | |
Markus Metzger | 8bba1bf | 2008-11-25 09:12:31 +0100 | [diff] [blame] | 2953 | /* Notify the tracer early; before we stop tracing. */ |
| 2954 | if (iter->trace && iter->trace->open) |
Markus Metzger | a93751c | 2008-12-11 13:53:26 +0100 | [diff] [blame] | 2955 | iter->trace->open(iter); |
Markus Metzger | 8bba1bf | 2008-11-25 09:12:31 +0100 | [diff] [blame] | 2956 | |
Steven Rostedt | 12ef7d4 | 2008-11-12 17:52:38 -0500 | [diff] [blame] | 2957 | /* Annotate start of buffers if we had overruns */ |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2958 | if (ring_buffer_overruns(iter->trace_buffer->buffer)) |
Steven Rostedt | 12ef7d4 | 2008-11-12 17:52:38 -0500 | [diff] [blame] | 2959 | iter->iter_flags |= TRACE_FILE_ANNOTATE; |
| 2960 | |
David Sharp | 8be0709 | 2012-11-13 12:18:22 -0800 | [diff] [blame] | 2961 | /* Output in nanoseconds only if we are using a clock in nanoseconds. */ |
Yoshihiro YUNOMAE | 58e8eed | 2013-04-23 10:32:39 +0900 | [diff] [blame] | 2962 | if (trace_clocks[tr->clock_id].in_ns) |
David Sharp | 8be0709 | 2012-11-13 12:18:22 -0800 | [diff] [blame] | 2963 | iter->iter_flags |= TRACE_FILE_TIME_IN_NS; |
| 2964 | |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 2965 | /* stop the trace while dumping if we are not opening "snapshot" */ |
| 2966 | if (!iter->snapshot) |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 2967 | tracing_stop_tr(tr); |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 2968 | |
Steven Rostedt | ae3b509 | 2013-01-23 15:22:59 -0500 | [diff] [blame] | 2969 | if (iter->cpu_file == RING_BUFFER_ALL_CPUS) { |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 2970 | for_each_tracing_cpu(cpu) { |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 2971 | iter->buffer_iter[cpu] = |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2972 | ring_buffer_read_prepare(iter->trace_buffer->buffer, cpu); |
David Miller | 72c9ddf | 2010-04-20 15:47:11 -0700 | [diff] [blame] | 2973 | } |
| 2974 | ring_buffer_read_prepare_sync(); |
| 2975 | for_each_tracing_cpu(cpu) { |
| 2976 | ring_buffer_read_start(iter->buffer_iter[cpu]); |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 2977 | tracing_iter_reset(iter, cpu); |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 2978 | } |
| 2979 | } else { |
| 2980 | cpu = iter->cpu_file; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2981 | iter->buffer_iter[cpu] = |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2982 | ring_buffer_read_prepare(iter->trace_buffer->buffer, cpu); |
David Miller | 72c9ddf | 2010-04-20 15:47:11 -0700 | [diff] [blame] | 2983 | ring_buffer_read_prepare_sync(); |
| 2984 | ring_buffer_read_start(iter->buffer_iter[cpu]); |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 2985 | tracing_iter_reset(iter, cpu); |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2986 | } |
| 2987 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2988 | mutex_unlock(&trace_types_lock); |
| 2989 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2990 | return iter; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2991 | |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 2992 | fail: |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2993 | mutex_unlock(&trace_types_lock); |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 2994 | kfree(iter->trace); |
Steven Rostedt | 6d158a8 | 2012-06-27 20:46:14 -0400 | [diff] [blame] | 2995 | kfree(iter->buffer_iter); |
Dan Carpenter | 93574fc | 2012-07-11 09:35:08 +0300 | [diff] [blame] | 2996 | release: |
Jiri Olsa | 50e18b9 | 2012-04-25 10:23:39 +0200 | [diff] [blame] | 2997 | seq_release_private(inode, file); |
| 2998 | return ERR_PTR(-ENOMEM); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2999 | } |
| 3000 | |
| 3001 | int tracing_open_generic(struct inode *inode, struct file *filp) |
| 3002 | { |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 3003 | if (tracing_disabled) |
| 3004 | return -ENODEV; |
| 3005 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3006 | filp->private_data = inode->i_private; |
| 3007 | return 0; |
| 3008 | } |
| 3009 | |
Geyslan G. Bem | 2e86421 | 2013-10-18 21:15:54 -0300 | [diff] [blame] | 3010 | bool tracing_is_disabled(void) |
| 3011 | { |
| 3012 | return (tracing_disabled) ? true: false; |
| 3013 | } |
| 3014 | |
Steven Rostedt (Red Hat) | 7b85af6 | 2013-07-01 23:34:22 -0400 | [diff] [blame] | 3015 | /* |
| 3016 | * Open and update trace_array ref count. |
| 3017 | * Must have the current trace_array passed to it. |
| 3018 | */ |
Steven Rostedt (Red Hat) | dcc3022 | 2013-07-02 20:30:52 -0400 | [diff] [blame] | 3019 | static int tracing_open_generic_tr(struct inode *inode, struct file *filp) |
Steven Rostedt (Red Hat) | 7b85af6 | 2013-07-01 23:34:22 -0400 | [diff] [blame] | 3020 | { |
| 3021 | struct trace_array *tr = inode->i_private; |
| 3022 | |
| 3023 | if (tracing_disabled) |
| 3024 | return -ENODEV; |
| 3025 | |
| 3026 | if (trace_array_get(tr) < 0) |
| 3027 | return -ENODEV; |
| 3028 | |
| 3029 | filp->private_data = inode->i_private; |
| 3030 | |
| 3031 | return 0; |
Steven Rostedt (Red Hat) | 7b85af6 | 2013-07-01 23:34:22 -0400 | [diff] [blame] | 3032 | } |
| 3033 | |
Hannes Eder | 4fd2735 | 2009-02-10 19:44:12 +0100 | [diff] [blame] | 3034 | static int tracing_release(struct inode *inode, struct file *file) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3035 | { |
Oleg Nesterov | 6484c71 | 2013-07-23 17:26:10 +0200 | [diff] [blame] | 3036 | struct trace_array *tr = inode->i_private; |
matt mooney | 907f278 | 2010-09-27 19:04:53 -0700 | [diff] [blame] | 3037 | struct seq_file *m = file->private_data; |
Steven Rostedt | 4acd4d0 | 2009-03-18 10:40:24 -0400 | [diff] [blame] | 3038 | struct trace_iterator *iter; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 3039 | int cpu; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3040 | |
Steven Rostedt (Red Hat) | ff45196 | 2013-07-01 22:50:29 -0400 | [diff] [blame] | 3041 | if (!(file->f_mode & FMODE_READ)) { |
Oleg Nesterov | 6484c71 | 2013-07-23 17:26:10 +0200 | [diff] [blame] | 3042 | trace_array_put(tr); |
Steven Rostedt | 4acd4d0 | 2009-03-18 10:40:24 -0400 | [diff] [blame] | 3043 | return 0; |
Steven Rostedt (Red Hat) | ff45196 | 2013-07-01 22:50:29 -0400 | [diff] [blame] | 3044 | } |
Steven Rostedt | 4acd4d0 | 2009-03-18 10:40:24 -0400 | [diff] [blame] | 3045 | |
Oleg Nesterov | 6484c71 | 2013-07-23 17:26:10 +0200 | [diff] [blame] | 3046 | /* Writes do not use seq_file */ |
Steven Rostedt | 4acd4d0 | 2009-03-18 10:40:24 -0400 | [diff] [blame] | 3047 | iter = m->private; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3048 | mutex_lock(&trace_types_lock); |
Steven Rostedt (Red Hat) | a695cb5 | 2013-03-06 15:27:24 -0500 | [diff] [blame] | 3049 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 3050 | for_each_tracing_cpu(cpu) { |
| 3051 | if (iter->buffer_iter[cpu]) |
| 3052 | ring_buffer_read_finish(iter->buffer_iter[cpu]); |
| 3053 | } |
| 3054 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3055 | if (iter->trace && iter->trace->close) |
| 3056 | iter->trace->close(iter); |
| 3057 | |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 3058 | if (!iter->snapshot) |
| 3059 | /* reenable tracing if it was previously enabled */ |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3060 | tracing_start_tr(tr); |
Alexander Z Lam | f77d09a | 2013-07-18 11:18:44 -0700 | [diff] [blame] | 3061 | |
| 3062 | __trace_array_put(tr); |
| 3063 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3064 | mutex_unlock(&trace_types_lock); |
| 3065 | |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 3066 | mutex_destroy(&iter->mutex); |
Frederic Weisbecker | b0dfa97 | 2009-04-01 22:53:08 +0200 | [diff] [blame] | 3067 | free_cpumask_var(iter->started); |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 3068 | kfree(iter->trace); |
Steven Rostedt | 6d158a8 | 2012-06-27 20:46:14 -0400 | [diff] [blame] | 3069 | kfree(iter->buffer_iter); |
Jiri Olsa | 50e18b9 | 2012-04-25 10:23:39 +0200 | [diff] [blame] | 3070 | seq_release_private(inode, file); |
Steven Rostedt (Red Hat) | ff45196 | 2013-07-01 22:50:29 -0400 | [diff] [blame] | 3071 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3072 | return 0; |
| 3073 | } |
| 3074 | |
Steven Rostedt (Red Hat) | 7b85af6 | 2013-07-01 23:34:22 -0400 | [diff] [blame] | 3075 | static int tracing_release_generic_tr(struct inode *inode, struct file *file) |
| 3076 | { |
| 3077 | struct trace_array *tr = inode->i_private; |
| 3078 | |
| 3079 | trace_array_put(tr); |
| 3080 | return 0; |
| 3081 | } |
| 3082 | |
Steven Rostedt (Red Hat) | 7b85af6 | 2013-07-01 23:34:22 -0400 | [diff] [blame] | 3083 | static int tracing_single_release_tr(struct inode *inode, struct file *file) |
| 3084 | { |
| 3085 | struct trace_array *tr = inode->i_private; |
| 3086 | |
| 3087 | trace_array_put(tr); |
| 3088 | |
| 3089 | return single_release(inode, file); |
| 3090 | } |
| 3091 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3092 | static int tracing_open(struct inode *inode, struct file *file) |
| 3093 | { |
Oleg Nesterov | 6484c71 | 2013-07-23 17:26:10 +0200 | [diff] [blame] | 3094 | struct trace_array *tr = inode->i_private; |
Steven Rostedt | 85a2f9b | 2009-02-27 00:12:38 -0500 | [diff] [blame] | 3095 | struct trace_iterator *iter; |
| 3096 | int ret = 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3097 | |
Steven Rostedt (Red Hat) | ff45196 | 2013-07-01 22:50:29 -0400 | [diff] [blame] | 3098 | if (trace_array_get(tr) < 0) |
| 3099 | return -ENODEV; |
| 3100 | |
Steven Rostedt | 4acd4d0 | 2009-03-18 10:40:24 -0400 | [diff] [blame] | 3101 | /* If this file was open for write, then erase contents */ |
Oleg Nesterov | 6484c71 | 2013-07-23 17:26:10 +0200 | [diff] [blame] | 3102 | if ((file->f_mode & FMODE_WRITE) && (file->f_flags & O_TRUNC)) { |
| 3103 | int cpu = tracing_get_cpu(inode); |
| 3104 | |
| 3105 | if (cpu == RING_BUFFER_ALL_CPUS) |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3106 | tracing_reset_online_cpus(&tr->trace_buffer); |
Steven Rostedt | 4acd4d0 | 2009-03-18 10:40:24 -0400 | [diff] [blame] | 3107 | else |
Oleg Nesterov | 6484c71 | 2013-07-23 17:26:10 +0200 | [diff] [blame] | 3108 | tracing_reset(&tr->trace_buffer, cpu); |
Steven Rostedt | 4acd4d0 | 2009-03-18 10:40:24 -0400 | [diff] [blame] | 3109 | } |
| 3110 | |
| 3111 | if (file->f_mode & FMODE_READ) { |
Oleg Nesterov | 6484c71 | 2013-07-23 17:26:10 +0200 | [diff] [blame] | 3112 | iter = __tracing_open(inode, file, false); |
Steven Rostedt | 4acd4d0 | 2009-03-18 10:40:24 -0400 | [diff] [blame] | 3113 | if (IS_ERR(iter)) |
| 3114 | ret = PTR_ERR(iter); |
| 3115 | else if (trace_flags & TRACE_ITER_LATENCY_FMT) |
| 3116 | iter->iter_flags |= TRACE_FILE_LAT_FMT; |
| 3117 | } |
Steven Rostedt (Red Hat) | ff45196 | 2013-07-01 22:50:29 -0400 | [diff] [blame] | 3118 | |
| 3119 | if (ret < 0) |
| 3120 | trace_array_put(tr); |
| 3121 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3122 | return ret; |
| 3123 | } |
| 3124 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 3125 | static void * |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3126 | t_next(struct seq_file *m, void *v, loff_t *pos) |
| 3127 | { |
Li Zefan | f129e96 | 2009-06-24 09:53:44 +0800 | [diff] [blame] | 3128 | struct tracer *t = v; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3129 | |
| 3130 | (*pos)++; |
| 3131 | |
| 3132 | if (t) |
| 3133 | t = t->next; |
| 3134 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3135 | return t; |
| 3136 | } |
| 3137 | |
| 3138 | static void *t_start(struct seq_file *m, loff_t *pos) |
| 3139 | { |
Li Zefan | f129e96 | 2009-06-24 09:53:44 +0800 | [diff] [blame] | 3140 | struct tracer *t; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3141 | loff_t l = 0; |
| 3142 | |
| 3143 | mutex_lock(&trace_types_lock); |
Li Zefan | f129e96 | 2009-06-24 09:53:44 +0800 | [diff] [blame] | 3144 | for (t = trace_types; t && l < *pos; t = t_next(m, t, &l)) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3145 | ; |
| 3146 | |
| 3147 | return t; |
| 3148 | } |
| 3149 | |
| 3150 | static void t_stop(struct seq_file *m, void *p) |
| 3151 | { |
| 3152 | mutex_unlock(&trace_types_lock); |
| 3153 | } |
| 3154 | |
| 3155 | static int t_show(struct seq_file *m, void *v) |
| 3156 | { |
| 3157 | struct tracer *t = v; |
| 3158 | |
| 3159 | if (!t) |
| 3160 | return 0; |
| 3161 | |
| 3162 | seq_printf(m, "%s", t->name); |
| 3163 | if (t->next) |
| 3164 | seq_putc(m, ' '); |
| 3165 | else |
| 3166 | seq_putc(m, '\n'); |
| 3167 | |
| 3168 | return 0; |
| 3169 | } |
| 3170 | |
James Morris | 88e9d34 | 2009-09-22 16:43:43 -0700 | [diff] [blame] | 3171 | static const struct seq_operations show_traces_seq_ops = { |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3172 | .start = t_start, |
| 3173 | .next = t_next, |
| 3174 | .stop = t_stop, |
| 3175 | .show = t_show, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3176 | }; |
| 3177 | |
| 3178 | static int show_traces_open(struct inode *inode, struct file *file) |
| 3179 | { |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 3180 | if (tracing_disabled) |
| 3181 | return -ENODEV; |
| 3182 | |
Li Zefan | f129e96 | 2009-06-24 09:53:44 +0800 | [diff] [blame] | 3183 | return seq_open(file, &show_traces_seq_ops); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3184 | } |
| 3185 | |
Steven Rostedt | 4acd4d0 | 2009-03-18 10:40:24 -0400 | [diff] [blame] | 3186 | static ssize_t |
| 3187 | tracing_write_stub(struct file *filp, const char __user *ubuf, |
| 3188 | size_t count, loff_t *ppos) |
| 3189 | { |
| 3190 | return count; |
| 3191 | } |
| 3192 | |
Steven Rostedt (Red Hat) | 098c879 | 2013-12-21 17:39:40 -0500 | [diff] [blame] | 3193 | loff_t tracing_lseek(struct file *file, loff_t offset, int whence) |
Slava Pestov | 364829b | 2010-11-24 15:13:16 -0800 | [diff] [blame] | 3194 | { |
Steven Rostedt (Red Hat) | 098c879 | 2013-12-21 17:39:40 -0500 | [diff] [blame] | 3195 | int ret; |
| 3196 | |
Slava Pestov | 364829b | 2010-11-24 15:13:16 -0800 | [diff] [blame] | 3197 | if (file->f_mode & FMODE_READ) |
Steven Rostedt (Red Hat) | 098c879 | 2013-12-21 17:39:40 -0500 | [diff] [blame] | 3198 | ret = seq_lseek(file, offset, whence); |
Slava Pestov | 364829b | 2010-11-24 15:13:16 -0800 | [diff] [blame] | 3199 | else |
Steven Rostedt (Red Hat) | 098c879 | 2013-12-21 17:39:40 -0500 | [diff] [blame] | 3200 | file->f_pos = ret = 0; |
| 3201 | |
| 3202 | return ret; |
Slava Pestov | 364829b | 2010-11-24 15:13:16 -0800 | [diff] [blame] | 3203 | } |
| 3204 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 3205 | static const struct file_operations tracing_fops = { |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3206 | .open = tracing_open, |
| 3207 | .read = seq_read, |
Steven Rostedt | 4acd4d0 | 2009-03-18 10:40:24 -0400 | [diff] [blame] | 3208 | .write = tracing_write_stub, |
Steven Rostedt (Red Hat) | 098c879 | 2013-12-21 17:39:40 -0500 | [diff] [blame] | 3209 | .llseek = tracing_lseek, |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3210 | .release = tracing_release, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3211 | }; |
| 3212 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 3213 | static const struct file_operations show_traces_fops = { |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3214 | .open = show_traces_open, |
| 3215 | .read = seq_read, |
| 3216 | .release = seq_release, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 3217 | .llseek = seq_lseek, |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3218 | }; |
| 3219 | |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3220 | /* |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3221 | * The tracer itself will not take this lock, but still we want |
| 3222 | * to provide a consistent cpumask to user-space: |
| 3223 | */ |
| 3224 | static DEFINE_MUTEX(tracing_cpumask_update_lock); |
| 3225 | |
| 3226 | /* |
| 3227 | * Temporary storage for the character representation of the |
| 3228 | * CPU bitmask (and one more byte for the newline): |
| 3229 | */ |
| 3230 | static char mask_str[NR_CPUS + 1]; |
| 3231 | |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3232 | static ssize_t |
| 3233 | tracing_cpumask_read(struct file *filp, char __user *ubuf, |
| 3234 | size_t count, loff_t *ppos) |
| 3235 | { |
Alexander Z Lam | ccfe9e4 | 2013-08-08 09:47:45 -0700 | [diff] [blame] | 3236 | struct trace_array *tr = file_inode(filp)->i_private; |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3237 | int len; |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3238 | |
| 3239 | mutex_lock(&tracing_cpumask_update_lock); |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3240 | |
Alexander Z Lam | ccfe9e4 | 2013-08-08 09:47:45 -0700 | [diff] [blame] | 3241 | len = cpumask_scnprintf(mask_str, count, tr->tracing_cpumask); |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3242 | if (count - len < 2) { |
| 3243 | count = -EINVAL; |
| 3244 | goto out_err; |
| 3245 | } |
| 3246 | len += sprintf(mask_str + len, "\n"); |
| 3247 | count = simple_read_from_buffer(ubuf, count, ppos, mask_str, NR_CPUS+1); |
| 3248 | |
| 3249 | out_err: |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3250 | mutex_unlock(&tracing_cpumask_update_lock); |
| 3251 | |
| 3252 | return count; |
| 3253 | } |
| 3254 | |
| 3255 | static ssize_t |
| 3256 | tracing_cpumask_write(struct file *filp, const char __user *ubuf, |
| 3257 | size_t count, loff_t *ppos) |
| 3258 | { |
Alexander Z Lam | ccfe9e4 | 2013-08-08 09:47:45 -0700 | [diff] [blame] | 3259 | struct trace_array *tr = file_inode(filp)->i_private; |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 3260 | cpumask_var_t tracing_cpumask_new; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3261 | int err, cpu; |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 3262 | |
| 3263 | if (!alloc_cpumask_var(&tracing_cpumask_new, GFP_KERNEL)) |
| 3264 | return -ENOMEM; |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3265 | |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 3266 | err = cpumask_parse_user(ubuf, count, tracing_cpumask_new); |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3267 | if (err) |
| 3268 | goto err_unlock; |
| 3269 | |
Li Zefan | 215368e | 2009-06-15 10:56:42 +0800 | [diff] [blame] | 3270 | mutex_lock(&tracing_cpumask_update_lock); |
| 3271 | |
Steven Rostedt | a5e2588 | 2008-12-02 15:34:05 -0500 | [diff] [blame] | 3272 | local_irq_disable(); |
Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 3273 | arch_spin_lock(&ftrace_max_lock); |
Steven Rostedt | ab46428 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 3274 | for_each_tracing_cpu(cpu) { |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3275 | /* |
| 3276 | * Increase/decrease the disabled counter if we are |
| 3277 | * about to flip a bit in the cpumask: |
| 3278 | */ |
Alexander Z Lam | ccfe9e4 | 2013-08-08 09:47:45 -0700 | [diff] [blame] | 3279 | if (cpumask_test_cpu(cpu, tr->tracing_cpumask) && |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 3280 | !cpumask_test_cpu(cpu, tracing_cpumask_new)) { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3281 | atomic_inc(&per_cpu_ptr(tr->trace_buffer.data, cpu)->disabled); |
| 3282 | ring_buffer_record_disable_cpu(tr->trace_buffer.buffer, cpu); |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3283 | } |
Alexander Z Lam | ccfe9e4 | 2013-08-08 09:47:45 -0700 | [diff] [blame] | 3284 | if (!cpumask_test_cpu(cpu, tr->tracing_cpumask) && |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 3285 | cpumask_test_cpu(cpu, tracing_cpumask_new)) { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3286 | atomic_dec(&per_cpu_ptr(tr->trace_buffer.data, cpu)->disabled); |
| 3287 | ring_buffer_record_enable_cpu(tr->trace_buffer.buffer, cpu); |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3288 | } |
| 3289 | } |
Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 3290 | arch_spin_unlock(&ftrace_max_lock); |
Steven Rostedt | a5e2588 | 2008-12-02 15:34:05 -0500 | [diff] [blame] | 3291 | local_irq_enable(); |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3292 | |
Alexander Z Lam | ccfe9e4 | 2013-08-08 09:47:45 -0700 | [diff] [blame] | 3293 | cpumask_copy(tr->tracing_cpumask, tracing_cpumask_new); |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3294 | |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3295 | mutex_unlock(&tracing_cpumask_update_lock); |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 3296 | free_cpumask_var(tracing_cpumask_new); |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3297 | |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3298 | return count; |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3299 | |
| 3300 | err_unlock: |
Li Zefan | 215368e | 2009-06-15 10:56:42 +0800 | [diff] [blame] | 3301 | free_cpumask_var(tracing_cpumask_new); |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3302 | |
| 3303 | return err; |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3304 | } |
| 3305 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 3306 | static const struct file_operations tracing_cpumask_fops = { |
Alexander Z Lam | ccfe9e4 | 2013-08-08 09:47:45 -0700 | [diff] [blame] | 3307 | .open = tracing_open_generic_tr, |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3308 | .read = tracing_cpumask_read, |
| 3309 | .write = tracing_cpumask_write, |
Alexander Z Lam | ccfe9e4 | 2013-08-08 09:47:45 -0700 | [diff] [blame] | 3310 | .release = tracing_release_generic_tr, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 3311 | .llseek = generic_file_llseek, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3312 | }; |
| 3313 | |
Li Zefan | fdb372e | 2009-12-08 11:15:59 +0800 | [diff] [blame] | 3314 | static int tracing_trace_options_show(struct seq_file *m, void *v) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3315 | { |
Steven Rostedt | d8e83d2 | 2009-02-26 23:55:58 -0500 | [diff] [blame] | 3316 | struct tracer_opt *trace_opts; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3317 | struct trace_array *tr = m->private; |
Steven Rostedt | d8e83d2 | 2009-02-26 23:55:58 -0500 | [diff] [blame] | 3318 | u32 tracer_flags; |
Steven Rostedt | d8e83d2 | 2009-02-26 23:55:58 -0500 | [diff] [blame] | 3319 | int i; |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 3320 | |
Steven Rostedt | d8e83d2 | 2009-02-26 23:55:58 -0500 | [diff] [blame] | 3321 | mutex_lock(&trace_types_lock); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3322 | tracer_flags = tr->current_trace->flags->val; |
| 3323 | trace_opts = tr->current_trace->flags->opts; |
Steven Rostedt | d8e83d2 | 2009-02-26 23:55:58 -0500 | [diff] [blame] | 3324 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3325 | for (i = 0; trace_options[i]; i++) { |
| 3326 | if (trace_flags & (1 << i)) |
Li Zefan | fdb372e | 2009-12-08 11:15:59 +0800 | [diff] [blame] | 3327 | seq_printf(m, "%s\n", trace_options[i]); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3328 | else |
Li Zefan | fdb372e | 2009-12-08 11:15:59 +0800 | [diff] [blame] | 3329 | seq_printf(m, "no%s\n", trace_options[i]); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3330 | } |
| 3331 | |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 3332 | for (i = 0; trace_opts[i].name; i++) { |
| 3333 | if (tracer_flags & trace_opts[i].bit) |
Li Zefan | fdb372e | 2009-12-08 11:15:59 +0800 | [diff] [blame] | 3334 | seq_printf(m, "%s\n", trace_opts[i].name); |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 3335 | else |
Li Zefan | fdb372e | 2009-12-08 11:15:59 +0800 | [diff] [blame] | 3336 | seq_printf(m, "no%s\n", trace_opts[i].name); |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 3337 | } |
Steven Rostedt | d8e83d2 | 2009-02-26 23:55:58 -0500 | [diff] [blame] | 3338 | mutex_unlock(&trace_types_lock); |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 3339 | |
Li Zefan | fdb372e | 2009-12-08 11:15:59 +0800 | [diff] [blame] | 3340 | return 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3341 | } |
| 3342 | |
Steven Rostedt (Red Hat) | 8c1a49a | 2014-01-10 11:13:54 -0500 | [diff] [blame^] | 3343 | static int __set_tracer_option(struct trace_array *tr, |
Li Zefan | 8d18eaa | 2009-12-08 11:17:06 +0800 | [diff] [blame] | 3344 | struct tracer_flags *tracer_flags, |
| 3345 | struct tracer_opt *opts, int neg) |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 3346 | { |
Steven Rostedt (Red Hat) | 8c1a49a | 2014-01-10 11:13:54 -0500 | [diff] [blame^] | 3347 | struct tracer *trace = tr->current_trace; |
Li Zefan | 8d18eaa | 2009-12-08 11:17:06 +0800 | [diff] [blame] | 3348 | int ret; |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 3349 | |
Steven Rostedt (Red Hat) | 8c1a49a | 2014-01-10 11:13:54 -0500 | [diff] [blame^] | 3350 | ret = trace->set_flag(tr, tracer_flags->val, opts->bit, !neg); |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 3351 | if (ret) |
| 3352 | return ret; |
| 3353 | |
| 3354 | if (neg) |
Zhaolei | 7770841 | 2009-08-07 18:53:21 +0800 | [diff] [blame] | 3355 | tracer_flags->val &= ~opts->bit; |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 3356 | else |
Zhaolei | 7770841 | 2009-08-07 18:53:21 +0800 | [diff] [blame] | 3357 | tracer_flags->val |= opts->bit; |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 3358 | return 0; |
| 3359 | } |
| 3360 | |
Li Zefan | 8d18eaa | 2009-12-08 11:17:06 +0800 | [diff] [blame] | 3361 | /* Try to assign a tracer specific option */ |
Steven Rostedt (Red Hat) | 8c1a49a | 2014-01-10 11:13:54 -0500 | [diff] [blame^] | 3362 | static int set_tracer_option(struct trace_array *tr, char *cmp, int neg) |
Li Zefan | 8d18eaa | 2009-12-08 11:17:06 +0800 | [diff] [blame] | 3363 | { |
Steven Rostedt (Red Hat) | 8c1a49a | 2014-01-10 11:13:54 -0500 | [diff] [blame^] | 3364 | struct tracer *trace = tr->current_trace; |
Li Zefan | 8d18eaa | 2009-12-08 11:17:06 +0800 | [diff] [blame] | 3365 | struct tracer_flags *tracer_flags = trace->flags; |
| 3366 | struct tracer_opt *opts = NULL; |
| 3367 | int i; |
| 3368 | |
| 3369 | for (i = 0; tracer_flags->opts[i].name; i++) { |
| 3370 | opts = &tracer_flags->opts[i]; |
| 3371 | |
| 3372 | if (strcmp(cmp, opts->name) == 0) |
Steven Rostedt (Red Hat) | 8c1a49a | 2014-01-10 11:13:54 -0500 | [diff] [blame^] | 3373 | return __set_tracer_option(tr, trace->flags, opts, neg); |
Li Zefan | 8d18eaa | 2009-12-08 11:17:06 +0800 | [diff] [blame] | 3374 | } |
| 3375 | |
| 3376 | return -EINVAL; |
| 3377 | } |
| 3378 | |
Steven Rostedt (Red Hat) | 613f04a | 2013-03-14 15:03:53 -0400 | [diff] [blame] | 3379 | /* Some tracers require overwrite to stay enabled */ |
| 3380 | int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set) |
| 3381 | { |
| 3382 | if (tracer->enabled && (mask & TRACE_ITER_OVERWRITE) && !set) |
| 3383 | return -1; |
| 3384 | |
| 3385 | return 0; |
| 3386 | } |
| 3387 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3388 | int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled) |
Steven Rostedt | af4617b | 2009-03-17 18:09:55 -0400 | [diff] [blame] | 3389 | { |
| 3390 | /* do nothing if flag is already set */ |
| 3391 | if (!!(trace_flags & mask) == !!enabled) |
Steven Rostedt (Red Hat) | 613f04a | 2013-03-14 15:03:53 -0400 | [diff] [blame] | 3392 | return 0; |
| 3393 | |
| 3394 | /* Give the tracer a chance to approve the change */ |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3395 | if (tr->current_trace->flag_changed) |
| 3396 | if (tr->current_trace->flag_changed(tr->current_trace, mask, !!enabled)) |
Steven Rostedt (Red Hat) | 613f04a | 2013-03-14 15:03:53 -0400 | [diff] [blame] | 3397 | return -EINVAL; |
Steven Rostedt | af4617b | 2009-03-17 18:09:55 -0400 | [diff] [blame] | 3398 | |
| 3399 | if (enabled) |
| 3400 | trace_flags |= mask; |
| 3401 | else |
| 3402 | trace_flags &= ~mask; |
Li Zefan | e870e9a | 2010-07-02 11:07:32 +0800 | [diff] [blame] | 3403 | |
| 3404 | if (mask == TRACE_ITER_RECORD_CMD) |
| 3405 | trace_event_enable_cmd_record(enabled); |
David Sharp | 750912f | 2010-12-08 13:46:47 -0800 | [diff] [blame] | 3406 | |
Steven Rostedt (Red Hat) | 8090282 | 2013-03-14 14:20:54 -0400 | [diff] [blame] | 3407 | if (mask == TRACE_ITER_OVERWRITE) { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3408 | ring_buffer_change_overwrite(tr->trace_buffer.buffer, enabled); |
Steven Rostedt (Red Hat) | 8090282 | 2013-03-14 14:20:54 -0400 | [diff] [blame] | 3409 | #ifdef CONFIG_TRACER_MAX_TRACE |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3410 | ring_buffer_change_overwrite(tr->max_buffer.buffer, enabled); |
Steven Rostedt (Red Hat) | 8090282 | 2013-03-14 14:20:54 -0400 | [diff] [blame] | 3411 | #endif |
| 3412 | } |
Steven Rostedt | 8169883 | 2012-10-11 10:15:05 -0400 | [diff] [blame] | 3413 | |
| 3414 | if (mask == TRACE_ITER_PRINTK) |
| 3415 | trace_printk_start_stop_comm(enabled); |
Steven Rostedt (Red Hat) | 613f04a | 2013-03-14 15:03:53 -0400 | [diff] [blame] | 3416 | |
| 3417 | return 0; |
Steven Rostedt | af4617b | 2009-03-17 18:09:55 -0400 | [diff] [blame] | 3418 | } |
| 3419 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3420 | static int trace_set_options(struct trace_array *tr, char *option) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3421 | { |
Li Zefan | 8d18eaa | 2009-12-08 11:17:06 +0800 | [diff] [blame] | 3422 | char *cmp; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3423 | int neg = 0; |
Steven Rostedt (Red Hat) | 613f04a | 2013-03-14 15:03:53 -0400 | [diff] [blame] | 3424 | int ret = -ENODEV; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3425 | int i; |
| 3426 | |
Steven Rostedt | 7bcfaf5 | 2012-11-01 22:56:07 -0400 | [diff] [blame] | 3427 | cmp = strstrip(option); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3428 | |
Li Zefan | 8d18eaa | 2009-12-08 11:17:06 +0800 | [diff] [blame] | 3429 | if (strncmp(cmp, "no", 2) == 0) { |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3430 | neg = 1; |
| 3431 | cmp += 2; |
| 3432 | } |
| 3433 | |
Steven Rostedt (Red Hat) | 69d34da | 2013-03-14 13:50:56 -0400 | [diff] [blame] | 3434 | mutex_lock(&trace_types_lock); |
| 3435 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3436 | for (i = 0; trace_options[i]; i++) { |
Li Zefan | 8d18eaa | 2009-12-08 11:17:06 +0800 | [diff] [blame] | 3437 | if (strcmp(cmp, trace_options[i]) == 0) { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3438 | ret = set_tracer_flag(tr, 1 << i, !neg); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3439 | break; |
| 3440 | } |
| 3441 | } |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 3442 | |
| 3443 | /* If no option could be set, test the specific tracer options */ |
Steven Rostedt (Red Hat) | 69d34da | 2013-03-14 13:50:56 -0400 | [diff] [blame] | 3444 | if (!trace_options[i]) |
Steven Rostedt (Red Hat) | 8c1a49a | 2014-01-10 11:13:54 -0500 | [diff] [blame^] | 3445 | ret = set_tracer_option(tr, cmp, neg); |
Steven Rostedt (Red Hat) | 69d34da | 2013-03-14 13:50:56 -0400 | [diff] [blame] | 3446 | |
| 3447 | mutex_unlock(&trace_types_lock); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3448 | |
Steven Rostedt | 7bcfaf5 | 2012-11-01 22:56:07 -0400 | [diff] [blame] | 3449 | return ret; |
| 3450 | } |
| 3451 | |
| 3452 | static ssize_t |
| 3453 | tracing_trace_options_write(struct file *filp, const char __user *ubuf, |
| 3454 | size_t cnt, loff_t *ppos) |
| 3455 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3456 | struct seq_file *m = filp->private_data; |
| 3457 | struct trace_array *tr = m->private; |
Steven Rostedt | 7bcfaf5 | 2012-11-01 22:56:07 -0400 | [diff] [blame] | 3458 | char buf[64]; |
Steven Rostedt (Red Hat) | 613f04a | 2013-03-14 15:03:53 -0400 | [diff] [blame] | 3459 | int ret; |
Steven Rostedt | 7bcfaf5 | 2012-11-01 22:56:07 -0400 | [diff] [blame] | 3460 | |
| 3461 | if (cnt >= sizeof(buf)) |
| 3462 | return -EINVAL; |
| 3463 | |
| 3464 | if (copy_from_user(&buf, ubuf, cnt)) |
| 3465 | return -EFAULT; |
| 3466 | |
Steven Rostedt | a8dd217 | 2013-01-09 20:54:17 -0500 | [diff] [blame] | 3467 | buf[cnt] = 0; |
| 3468 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3469 | ret = trace_set_options(tr, buf); |
Steven Rostedt (Red Hat) | 613f04a | 2013-03-14 15:03:53 -0400 | [diff] [blame] | 3470 | if (ret < 0) |
| 3471 | return ret; |
Steven Rostedt | 7bcfaf5 | 2012-11-01 22:56:07 -0400 | [diff] [blame] | 3472 | |
Jiri Olsa | cf8517c | 2009-10-23 19:36:16 -0400 | [diff] [blame] | 3473 | *ppos += cnt; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3474 | |
| 3475 | return cnt; |
| 3476 | } |
| 3477 | |
Li Zefan | fdb372e | 2009-12-08 11:15:59 +0800 | [diff] [blame] | 3478 | static int tracing_trace_options_open(struct inode *inode, struct file *file) |
| 3479 | { |
Steven Rostedt (Red Hat) | 7b85af6 | 2013-07-01 23:34:22 -0400 | [diff] [blame] | 3480 | struct trace_array *tr = inode->i_private; |
Alexander Z Lam | f77d09a | 2013-07-18 11:18:44 -0700 | [diff] [blame] | 3481 | int ret; |
Steven Rostedt (Red Hat) | 7b85af6 | 2013-07-01 23:34:22 -0400 | [diff] [blame] | 3482 | |
Li Zefan | fdb372e | 2009-12-08 11:15:59 +0800 | [diff] [blame] | 3483 | if (tracing_disabled) |
| 3484 | return -ENODEV; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3485 | |
Steven Rostedt (Red Hat) | 7b85af6 | 2013-07-01 23:34:22 -0400 | [diff] [blame] | 3486 | if (trace_array_get(tr) < 0) |
| 3487 | return -ENODEV; |
| 3488 | |
Alexander Z Lam | f77d09a | 2013-07-18 11:18:44 -0700 | [diff] [blame] | 3489 | ret = single_open(file, tracing_trace_options_show, inode->i_private); |
| 3490 | if (ret < 0) |
| 3491 | trace_array_put(tr); |
| 3492 | |
| 3493 | return ret; |
Li Zefan | fdb372e | 2009-12-08 11:15:59 +0800 | [diff] [blame] | 3494 | } |
| 3495 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 3496 | static const struct file_operations tracing_iter_fops = { |
Li Zefan | fdb372e | 2009-12-08 11:15:59 +0800 | [diff] [blame] | 3497 | .open = tracing_trace_options_open, |
| 3498 | .read = seq_read, |
| 3499 | .llseek = seq_lseek, |
Steven Rostedt (Red Hat) | 7b85af6 | 2013-07-01 23:34:22 -0400 | [diff] [blame] | 3500 | .release = tracing_single_release_tr, |
Steven Rostedt | ee6bce5 | 2008-11-12 17:52:37 -0500 | [diff] [blame] | 3501 | .write = tracing_trace_options_write, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3502 | }; |
| 3503 | |
Ingo Molnar | 7bd2f24 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 3504 | static const char readme_msg[] = |
| 3505 | "tracing mini-HOWTO:\n\n" |
Steven Rostedt (Red Hat) | 22f4564 | 2013-03-15 17:23:20 -0400 | [diff] [blame] | 3506 | "# echo 0 > tracing_on : quick way to disable tracing\n" |
| 3507 | "# echo 1 > tracing_on : quick way to re-enable tracing\n\n" |
| 3508 | " Important files:\n" |
| 3509 | " trace\t\t\t- The static contents of the buffer\n" |
| 3510 | "\t\t\t To clear the buffer write into this file: echo > trace\n" |
| 3511 | " trace_pipe\t\t- A consuming read to see the contents of the buffer\n" |
| 3512 | " current_tracer\t- function and latency tracers\n" |
| 3513 | " available_tracers\t- list of configured tracers for current_tracer\n" |
| 3514 | " buffer_size_kb\t- view and modify size of per cpu buffer\n" |
| 3515 | " buffer_total_size_kb - view total size of all cpu buffers\n\n" |
| 3516 | " trace_clock\t\t-change the clock used to order events\n" |
| 3517 | " local: Per cpu clock but may not be synced across CPUs\n" |
| 3518 | " global: Synced across CPUs but slows tracing down.\n" |
| 3519 | " counter: Not a clock, but just an increment\n" |
| 3520 | " uptime: Jiffy counter from time of boot\n" |
| 3521 | " perf: Same clock that perf events use\n" |
| 3522 | #ifdef CONFIG_X86_64 |
| 3523 | " x86-tsc: TSC cycle counter\n" |
| 3524 | #endif |
| 3525 | "\n trace_marker\t\t- Writes into this file writes into the kernel buffer\n" |
| 3526 | " tracing_cpumask\t- Limit which CPUs to trace\n" |
| 3527 | " instances\t\t- Make sub-buffers with: mkdir instances/foo\n" |
| 3528 | "\t\t\t Remove sub-buffer with rmdir\n" |
| 3529 | " trace_options\t\t- Set format or modify how tracing happens\n" |
Steven Rostedt (Red Hat) | 71485c4 | 2014-01-23 00:10:04 -0500 | [diff] [blame] | 3530 | "\t\t\t Disable an option by adding a suffix 'no' to the\n" |
| 3531 | "\t\t\t option name\n" |
Steven Rostedt (Red Hat) | 22f4564 | 2013-03-15 17:23:20 -0400 | [diff] [blame] | 3532 | #ifdef CONFIG_DYNAMIC_FTRACE |
| 3533 | "\n available_filter_functions - list of functions that can be filtered on\n" |
Steven Rostedt (Red Hat) | 71485c4 | 2014-01-23 00:10:04 -0500 | [diff] [blame] | 3534 | " set_ftrace_filter\t- echo function name in here to only trace these\n" |
| 3535 | "\t\t\t functions\n" |
| 3536 | "\t accepts: func_full_name, *func_end, func_begin*, *func_middle*\n" |
| 3537 | "\t modules: Can select a group via module\n" |
| 3538 | "\t Format: :mod:<module-name>\n" |
| 3539 | "\t example: echo :mod:ext3 > set_ftrace_filter\n" |
| 3540 | "\t triggers: a command to perform when function is hit\n" |
| 3541 | "\t Format: <function>:<trigger>[:count]\n" |
| 3542 | "\t trigger: traceon, traceoff\n" |
| 3543 | "\t\t enable_event:<system>:<event>\n" |
| 3544 | "\t\t disable_event:<system>:<event>\n" |
Steven Rostedt (Red Hat) | 22f4564 | 2013-03-15 17:23:20 -0400 | [diff] [blame] | 3545 | #ifdef CONFIG_STACKTRACE |
Steven Rostedt (Red Hat) | 71485c4 | 2014-01-23 00:10:04 -0500 | [diff] [blame] | 3546 | "\t\t stacktrace\n" |
Steven Rostedt (Red Hat) | 22f4564 | 2013-03-15 17:23:20 -0400 | [diff] [blame] | 3547 | #endif |
| 3548 | #ifdef CONFIG_TRACER_SNAPSHOT |
Steven Rostedt (Red Hat) | 71485c4 | 2014-01-23 00:10:04 -0500 | [diff] [blame] | 3549 | "\t\t snapshot\n" |
Steven Rostedt (Red Hat) | 22f4564 | 2013-03-15 17:23:20 -0400 | [diff] [blame] | 3550 | #endif |
Steven Rostedt (Red Hat) | 71485c4 | 2014-01-23 00:10:04 -0500 | [diff] [blame] | 3551 | "\t example: echo do_fault:traceoff > set_ftrace_filter\n" |
| 3552 | "\t echo do_trap:traceoff:3 > set_ftrace_filter\n" |
| 3553 | "\t The first one will disable tracing every time do_fault is hit\n" |
| 3554 | "\t The second will disable tracing at most 3 times when do_trap is hit\n" |
| 3555 | "\t The first time do trap is hit and it disables tracing, the\n" |
| 3556 | "\t counter will decrement to 2. If tracing is already disabled,\n" |
| 3557 | "\t the counter will not decrement. It only decrements when the\n" |
| 3558 | "\t trigger did work\n" |
| 3559 | "\t To remove trigger without count:\n" |
| 3560 | "\t echo '!<function>:<trigger> > set_ftrace_filter\n" |
| 3561 | "\t To remove trigger with a count:\n" |
| 3562 | "\t echo '!<function>:<trigger>:0 > set_ftrace_filter\n" |
Steven Rostedt (Red Hat) | 22f4564 | 2013-03-15 17:23:20 -0400 | [diff] [blame] | 3563 | " set_ftrace_notrace\t- echo function name in here to never trace.\n" |
Steven Rostedt (Red Hat) | 71485c4 | 2014-01-23 00:10:04 -0500 | [diff] [blame] | 3564 | "\t accepts: func_full_name, *func_end, func_begin*, *func_middle*\n" |
| 3565 | "\t modules: Can select a group via module command :mod:\n" |
| 3566 | "\t Does not accept triggers\n" |
Steven Rostedt (Red Hat) | 22f4564 | 2013-03-15 17:23:20 -0400 | [diff] [blame] | 3567 | #endif /* CONFIG_DYNAMIC_FTRACE */ |
| 3568 | #ifdef CONFIG_FUNCTION_TRACER |
Steven Rostedt (Red Hat) | 71485c4 | 2014-01-23 00:10:04 -0500 | [diff] [blame] | 3569 | " set_ftrace_pid\t- Write pid(s) to only function trace those pids\n" |
| 3570 | "\t\t (function)\n" |
Steven Rostedt (Red Hat) | 22f4564 | 2013-03-15 17:23:20 -0400 | [diff] [blame] | 3571 | #endif |
| 3572 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER |
| 3573 | " set_graph_function\t- Trace the nested calls of a function (function_graph)\n" |
| 3574 | " max_graph_depth\t- Trace a limited depth of nested calls (0 is unlimited)\n" |
| 3575 | #endif |
| 3576 | #ifdef CONFIG_TRACER_SNAPSHOT |
Steven Rostedt (Red Hat) | 71485c4 | 2014-01-23 00:10:04 -0500 | [diff] [blame] | 3577 | "\n snapshot\t\t- Like 'trace' but shows the content of the static\n" |
| 3578 | "\t\t\t snapshot buffer. Read the contents for more\n" |
| 3579 | "\t\t\t information\n" |
Steven Rostedt (Red Hat) | 22f4564 | 2013-03-15 17:23:20 -0400 | [diff] [blame] | 3580 | #endif |
zhangwei(Jovi) | 991821c | 2013-07-15 16:32:34 +0800 | [diff] [blame] | 3581 | #ifdef CONFIG_STACK_TRACER |
Steven Rostedt (Red Hat) | 22f4564 | 2013-03-15 17:23:20 -0400 | [diff] [blame] | 3582 | " stack_trace\t\t- Shows the max stack trace when active\n" |
| 3583 | " stack_max_size\t- Shows current max stack size that was traced\n" |
Steven Rostedt (Red Hat) | 71485c4 | 2014-01-23 00:10:04 -0500 | [diff] [blame] | 3584 | "\t\t\t Write into this file to reset the max size (trigger a\n" |
| 3585 | "\t\t\t new trace)\n" |
Steven Rostedt (Red Hat) | 22f4564 | 2013-03-15 17:23:20 -0400 | [diff] [blame] | 3586 | #ifdef CONFIG_DYNAMIC_FTRACE |
Steven Rostedt (Red Hat) | 71485c4 | 2014-01-23 00:10:04 -0500 | [diff] [blame] | 3587 | " stack_trace_filter\t- Like set_ftrace_filter but limits what stack_trace\n" |
| 3588 | "\t\t\t traces\n" |
Steven Rostedt (Red Hat) | 22f4564 | 2013-03-15 17:23:20 -0400 | [diff] [blame] | 3589 | #endif |
zhangwei(Jovi) | 991821c | 2013-07-15 16:32:34 +0800 | [diff] [blame] | 3590 | #endif /* CONFIG_STACK_TRACER */ |
Tom Zanussi | 26f2556 | 2014-01-17 15:11:44 -0600 | [diff] [blame] | 3591 | " events/\t\t- Directory containing all trace event subsystems:\n" |
| 3592 | " enable\t\t- Write 0/1 to enable/disable tracing of all events\n" |
| 3593 | " events/<system>/\t- Directory containing all trace events for <system>:\n" |
Steven Rostedt (Red Hat) | 71485c4 | 2014-01-23 00:10:04 -0500 | [diff] [blame] | 3594 | " enable\t\t- Write 0/1 to enable/disable tracing of all <system>\n" |
| 3595 | "\t\t\t events\n" |
Tom Zanussi | 26f2556 | 2014-01-17 15:11:44 -0600 | [diff] [blame] | 3596 | " filter\t\t- If set, only events passing filter are traced\n" |
Steven Rostedt (Red Hat) | 71485c4 | 2014-01-23 00:10:04 -0500 | [diff] [blame] | 3597 | " events/<system>/<event>/\t- Directory containing control files for\n" |
| 3598 | "\t\t\t <event>:\n" |
Tom Zanussi | 26f2556 | 2014-01-17 15:11:44 -0600 | [diff] [blame] | 3599 | " enable\t\t- Write 0/1 to enable/disable tracing of <event>\n" |
| 3600 | " filter\t\t- If set, only events passing filter are traced\n" |
| 3601 | " trigger\t\t- If set, a command to perform when event is hit\n" |
Steven Rostedt (Red Hat) | 71485c4 | 2014-01-23 00:10:04 -0500 | [diff] [blame] | 3602 | "\t Format: <trigger>[:count][if <filter>]\n" |
| 3603 | "\t trigger: traceon, traceoff\n" |
| 3604 | "\t enable_event:<system>:<event>\n" |
| 3605 | "\t disable_event:<system>:<event>\n" |
Tom Zanussi | 26f2556 | 2014-01-17 15:11:44 -0600 | [diff] [blame] | 3606 | #ifdef CONFIG_STACKTRACE |
Steven Rostedt (Red Hat) | 71485c4 | 2014-01-23 00:10:04 -0500 | [diff] [blame] | 3607 | "\t\t stacktrace\n" |
Tom Zanussi | 26f2556 | 2014-01-17 15:11:44 -0600 | [diff] [blame] | 3608 | #endif |
| 3609 | #ifdef CONFIG_TRACER_SNAPSHOT |
Steven Rostedt (Red Hat) | 71485c4 | 2014-01-23 00:10:04 -0500 | [diff] [blame] | 3610 | "\t\t snapshot\n" |
Tom Zanussi | 26f2556 | 2014-01-17 15:11:44 -0600 | [diff] [blame] | 3611 | #endif |
Steven Rostedt (Red Hat) | 71485c4 | 2014-01-23 00:10:04 -0500 | [diff] [blame] | 3612 | "\t example: echo traceoff > events/block/block_unplug/trigger\n" |
| 3613 | "\t echo traceoff:3 > events/block/block_unplug/trigger\n" |
| 3614 | "\t echo 'enable_event:kmem:kmalloc:3 if nr_rq > 1' > \\\n" |
| 3615 | "\t events/block/block_unplug/trigger\n" |
| 3616 | "\t The first disables tracing every time block_unplug is hit.\n" |
| 3617 | "\t The second disables tracing the first 3 times block_unplug is hit.\n" |
| 3618 | "\t The third enables the kmalloc event the first 3 times block_unplug\n" |
| 3619 | "\t is hit and has value of greater than 1 for the 'nr_rq' event field.\n" |
| 3620 | "\t Like function triggers, the counter is only decremented if it\n" |
| 3621 | "\t enabled or disabled tracing.\n" |
| 3622 | "\t To remove a trigger without a count:\n" |
| 3623 | "\t echo '!<trigger> > <system>/<event>/trigger\n" |
| 3624 | "\t To remove a trigger with a count:\n" |
| 3625 | "\t echo '!<trigger>:0 > <system>/<event>/trigger\n" |
| 3626 | "\t Filters can be ignored when removing a trigger.\n" |
Ingo Molnar | 7bd2f24 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 3627 | ; |
| 3628 | |
| 3629 | static ssize_t |
| 3630 | tracing_readme_read(struct file *filp, char __user *ubuf, |
| 3631 | size_t cnt, loff_t *ppos) |
| 3632 | { |
| 3633 | return simple_read_from_buffer(ubuf, cnt, ppos, |
| 3634 | readme_msg, strlen(readme_msg)); |
| 3635 | } |
| 3636 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 3637 | static const struct file_operations tracing_readme_fops = { |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3638 | .open = tracing_open_generic, |
| 3639 | .read = tracing_readme_read, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 3640 | .llseek = generic_file_llseek, |
Ingo Molnar | 7bd2f24 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 3641 | }; |
| 3642 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3643 | static ssize_t |
Avadh Patel | 69abe6a | 2009-04-10 16:04:48 -0400 | [diff] [blame] | 3644 | tracing_saved_cmdlines_read(struct file *file, char __user *ubuf, |
| 3645 | size_t cnt, loff_t *ppos) |
| 3646 | { |
| 3647 | char *buf_comm; |
| 3648 | char *file_buf; |
| 3649 | char *buf; |
| 3650 | int len = 0; |
| 3651 | int pid; |
| 3652 | int i; |
| 3653 | |
| 3654 | file_buf = kmalloc(SAVED_CMDLINES*(16+TASK_COMM_LEN), GFP_KERNEL); |
| 3655 | if (!file_buf) |
| 3656 | return -ENOMEM; |
| 3657 | |
| 3658 | buf_comm = kmalloc(TASK_COMM_LEN, GFP_KERNEL); |
| 3659 | if (!buf_comm) { |
| 3660 | kfree(file_buf); |
| 3661 | return -ENOMEM; |
| 3662 | } |
| 3663 | |
| 3664 | buf = file_buf; |
| 3665 | |
| 3666 | for (i = 0; i < SAVED_CMDLINES; i++) { |
| 3667 | int r; |
| 3668 | |
| 3669 | pid = map_cmdline_to_pid[i]; |
| 3670 | if (pid == -1 || pid == NO_CMDLINE_MAP) |
| 3671 | continue; |
| 3672 | |
| 3673 | trace_find_cmdline(pid, buf_comm); |
| 3674 | r = sprintf(buf, "%d %s\n", pid, buf_comm); |
| 3675 | buf += r; |
| 3676 | len += r; |
| 3677 | } |
| 3678 | |
| 3679 | len = simple_read_from_buffer(ubuf, cnt, ppos, |
| 3680 | file_buf, len); |
| 3681 | |
| 3682 | kfree(file_buf); |
| 3683 | kfree(buf_comm); |
| 3684 | |
| 3685 | return len; |
| 3686 | } |
| 3687 | |
| 3688 | static const struct file_operations tracing_saved_cmdlines_fops = { |
| 3689 | .open = tracing_open_generic, |
| 3690 | .read = tracing_saved_cmdlines_read, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 3691 | .llseek = generic_file_llseek, |
Avadh Patel | 69abe6a | 2009-04-10 16:04:48 -0400 | [diff] [blame] | 3692 | }; |
| 3693 | |
| 3694 | static ssize_t |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3695 | tracing_set_trace_read(struct file *filp, char __user *ubuf, |
| 3696 | size_t cnt, loff_t *ppos) |
| 3697 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3698 | struct trace_array *tr = filp->private_data; |
Li Zefan | ee6c2c1 | 2009-09-18 14:06:47 +0800 | [diff] [blame] | 3699 | char buf[MAX_TRACER_SIZE+2]; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3700 | int r; |
| 3701 | |
| 3702 | mutex_lock(&trace_types_lock); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3703 | r = sprintf(buf, "%s\n", tr->current_trace->name); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3704 | mutex_unlock(&trace_types_lock); |
| 3705 | |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3706 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, r); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3707 | } |
| 3708 | |
Arnaldo Carvalho de Melo | b6f11df | 2009-02-05 18:02:00 -0200 | [diff] [blame] | 3709 | int tracer_init(struct tracer *t, struct trace_array *tr) |
| 3710 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3711 | tracing_reset_online_cpus(&tr->trace_buffer); |
Arnaldo Carvalho de Melo | b6f11df | 2009-02-05 18:02:00 -0200 | [diff] [blame] | 3712 | return t->init(tr); |
| 3713 | } |
| 3714 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3715 | static void set_buffer_entries(struct trace_buffer *buf, unsigned long val) |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 3716 | { |
| 3717 | int cpu; |
Steven Rostedt (Red Hat) | 737223f | 2013-03-05 21:13:47 -0500 | [diff] [blame] | 3718 | |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 3719 | for_each_tracing_cpu(cpu) |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3720 | per_cpu_ptr(buf->data, cpu)->entries = val; |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 3721 | } |
| 3722 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3723 | #ifdef CONFIG_TRACER_MAX_TRACE |
Hiraku Toyooka | d60da50 | 2012-10-17 11:56:16 +0900 | [diff] [blame] | 3724 | /* resize @tr's buffer to the size of @size_tr's entries */ |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3725 | static int resize_buffer_duplicate_size(struct trace_buffer *trace_buf, |
| 3726 | struct trace_buffer *size_buf, int cpu_id) |
Hiraku Toyooka | d60da50 | 2012-10-17 11:56:16 +0900 | [diff] [blame] | 3727 | { |
| 3728 | int cpu, ret = 0; |
| 3729 | |
| 3730 | if (cpu_id == RING_BUFFER_ALL_CPUS) { |
| 3731 | for_each_tracing_cpu(cpu) { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3732 | ret = ring_buffer_resize(trace_buf->buffer, |
| 3733 | per_cpu_ptr(size_buf->data, cpu)->entries, cpu); |
Hiraku Toyooka | d60da50 | 2012-10-17 11:56:16 +0900 | [diff] [blame] | 3734 | if (ret < 0) |
| 3735 | break; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3736 | per_cpu_ptr(trace_buf->data, cpu)->entries = |
| 3737 | per_cpu_ptr(size_buf->data, cpu)->entries; |
Hiraku Toyooka | d60da50 | 2012-10-17 11:56:16 +0900 | [diff] [blame] | 3738 | } |
| 3739 | } else { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3740 | ret = ring_buffer_resize(trace_buf->buffer, |
| 3741 | per_cpu_ptr(size_buf->data, cpu_id)->entries, cpu_id); |
Hiraku Toyooka | d60da50 | 2012-10-17 11:56:16 +0900 | [diff] [blame] | 3742 | if (ret == 0) |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3743 | per_cpu_ptr(trace_buf->data, cpu_id)->entries = |
| 3744 | per_cpu_ptr(size_buf->data, cpu_id)->entries; |
Hiraku Toyooka | d60da50 | 2012-10-17 11:56:16 +0900 | [diff] [blame] | 3745 | } |
| 3746 | |
| 3747 | return ret; |
| 3748 | } |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3749 | #endif /* CONFIG_TRACER_MAX_TRACE */ |
Hiraku Toyooka | d60da50 | 2012-10-17 11:56:16 +0900 | [diff] [blame] | 3750 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3751 | static int __tracing_resize_ring_buffer(struct trace_array *tr, |
| 3752 | unsigned long size, int cpu) |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 3753 | { |
| 3754 | int ret; |
| 3755 | |
| 3756 | /* |
| 3757 | * If kernel or user changes the size of the ring buffer |
Steven Rostedt | a123c52 | 2009-03-12 11:21:08 -0400 | [diff] [blame] | 3758 | * we use the size that was given, and we can forget about |
| 3759 | * expanding it later. |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 3760 | */ |
Steven Rostedt (Red Hat) | 55034cd | 2013-03-07 22:48:09 -0500 | [diff] [blame] | 3761 | ring_buffer_expanded = true; |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 3762 | |
Steven Rostedt | b382ede6 | 2012-10-10 21:44:34 -0400 | [diff] [blame] | 3763 | /* May be called before buffers are initialized */ |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3764 | if (!tr->trace_buffer.buffer) |
Steven Rostedt | b382ede6 | 2012-10-10 21:44:34 -0400 | [diff] [blame] | 3765 | return 0; |
| 3766 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3767 | ret = ring_buffer_resize(tr->trace_buffer.buffer, size, cpu); |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 3768 | if (ret < 0) |
| 3769 | return ret; |
| 3770 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3771 | #ifdef CONFIG_TRACER_MAX_TRACE |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3772 | if (!(tr->flags & TRACE_ARRAY_FL_GLOBAL) || |
| 3773 | !tr->current_trace->use_max_tr) |
KOSAKI Motohiro | ef710e1 | 2010-07-01 14:34:35 +0900 | [diff] [blame] | 3774 | goto out; |
| 3775 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3776 | ret = ring_buffer_resize(tr->max_buffer.buffer, size, cpu); |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 3777 | if (ret < 0) { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3778 | int r = resize_buffer_duplicate_size(&tr->trace_buffer, |
| 3779 | &tr->trace_buffer, cpu); |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 3780 | if (r < 0) { |
Steven Rostedt | a123c52 | 2009-03-12 11:21:08 -0400 | [diff] [blame] | 3781 | /* |
| 3782 | * AARGH! We are left with different |
| 3783 | * size max buffer!!!! |
| 3784 | * The max buffer is our "snapshot" buffer. |
| 3785 | * When a tracer needs a snapshot (one of the |
| 3786 | * latency tracers), it swaps the max buffer |
| 3787 | * with the saved snap shot. We succeeded to |
| 3788 | * update the size of the main buffer, but failed to |
| 3789 | * update the size of the max buffer. But when we tried |
| 3790 | * to reset the main buffer to the original size, we |
| 3791 | * failed there too. This is very unlikely to |
| 3792 | * happen, but if it does, warn and kill all |
| 3793 | * tracing. |
| 3794 | */ |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 3795 | WARN_ON(1); |
| 3796 | tracing_disabled = 1; |
| 3797 | } |
| 3798 | return ret; |
| 3799 | } |
| 3800 | |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 3801 | if (cpu == RING_BUFFER_ALL_CPUS) |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3802 | set_buffer_entries(&tr->max_buffer, size); |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 3803 | else |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3804 | per_cpu_ptr(tr->max_buffer.data, cpu)->entries = size; |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 3805 | |
KOSAKI Motohiro | ef710e1 | 2010-07-01 14:34:35 +0900 | [diff] [blame] | 3806 | out: |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3807 | #endif /* CONFIG_TRACER_MAX_TRACE */ |
| 3808 | |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 3809 | if (cpu == RING_BUFFER_ALL_CPUS) |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3810 | set_buffer_entries(&tr->trace_buffer, size); |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 3811 | else |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3812 | per_cpu_ptr(tr->trace_buffer.data, cpu)->entries = size; |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 3813 | |
| 3814 | return ret; |
| 3815 | } |
| 3816 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3817 | static ssize_t tracing_resize_ring_buffer(struct trace_array *tr, |
| 3818 | unsigned long size, int cpu_id) |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 3819 | { |
Vaibhav Nagarnaik | 83f4031 | 2012-05-03 18:59:50 -0700 | [diff] [blame] | 3820 | int ret = size; |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 3821 | |
| 3822 | mutex_lock(&trace_types_lock); |
| 3823 | |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 3824 | if (cpu_id != RING_BUFFER_ALL_CPUS) { |
| 3825 | /* make sure, this cpu is enabled in the mask */ |
| 3826 | if (!cpumask_test_cpu(cpu_id, tracing_buffer_mask)) { |
| 3827 | ret = -EINVAL; |
| 3828 | goto out; |
| 3829 | } |
| 3830 | } |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 3831 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3832 | ret = __tracing_resize_ring_buffer(tr, size, cpu_id); |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 3833 | if (ret < 0) |
| 3834 | ret = -ENOMEM; |
| 3835 | |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 3836 | out: |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 3837 | mutex_unlock(&trace_types_lock); |
| 3838 | |
| 3839 | return ret; |
| 3840 | } |
| 3841 | |
KOSAKI Motohiro | ef710e1 | 2010-07-01 14:34:35 +0900 | [diff] [blame] | 3842 | |
Steven Rostedt | 1852fcc | 2009-03-11 14:33:00 -0400 | [diff] [blame] | 3843 | /** |
| 3844 | * tracing_update_buffers - used by tracing facility to expand ring buffers |
| 3845 | * |
| 3846 | * To save on memory when the tracing is never used on a system with it |
| 3847 | * configured in. The ring buffers are set to a minimum size. But once |
| 3848 | * a user starts to use the tracing facility, then they need to grow |
| 3849 | * to their default size. |
| 3850 | * |
| 3851 | * This function is to be called when a tracer is about to be used. |
| 3852 | */ |
| 3853 | int tracing_update_buffers(void) |
| 3854 | { |
| 3855 | int ret = 0; |
| 3856 | |
Steven Rostedt | 1027fcb | 2009-03-12 11:33:20 -0400 | [diff] [blame] | 3857 | mutex_lock(&trace_types_lock); |
Steven Rostedt | 1852fcc | 2009-03-11 14:33:00 -0400 | [diff] [blame] | 3858 | if (!ring_buffer_expanded) |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3859 | ret = __tracing_resize_ring_buffer(&global_trace, trace_buf_size, |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 3860 | RING_BUFFER_ALL_CPUS); |
Steven Rostedt | 1027fcb | 2009-03-12 11:33:20 -0400 | [diff] [blame] | 3861 | mutex_unlock(&trace_types_lock); |
Steven Rostedt | 1852fcc | 2009-03-11 14:33:00 -0400 | [diff] [blame] | 3862 | |
| 3863 | return ret; |
| 3864 | } |
| 3865 | |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 3866 | struct trace_option_dentry; |
| 3867 | |
| 3868 | static struct trace_option_dentry * |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3869 | create_trace_option_files(struct trace_array *tr, struct tracer *tracer); |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 3870 | |
| 3871 | static void |
| 3872 | destroy_trace_option_files(struct trace_option_dentry *topts); |
| 3873 | |
Steven Rostedt | b2821ae | 2009-02-02 21:38:32 -0500 | [diff] [blame] | 3874 | static int tracing_set_tracer(const char *buf) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3875 | { |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 3876 | static struct trace_option_dentry *topts; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3877 | struct trace_array *tr = &global_trace; |
| 3878 | struct tracer *t; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3879 | #ifdef CONFIG_TRACER_MAX_TRACE |
Steven Rostedt | 34600f0 | 2013-01-22 13:35:11 -0500 | [diff] [blame] | 3880 | bool had_max_tr; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3881 | #endif |
Peter Zijlstra | d9e5407 | 2008-11-01 19:57:37 +0100 | [diff] [blame] | 3882 | int ret = 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3883 | |
Steven Rostedt | 1027fcb | 2009-03-12 11:33:20 -0400 | [diff] [blame] | 3884 | mutex_lock(&trace_types_lock); |
| 3885 | |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 3886 | if (!ring_buffer_expanded) { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3887 | ret = __tracing_resize_ring_buffer(tr, trace_buf_size, |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 3888 | RING_BUFFER_ALL_CPUS); |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 3889 | if (ret < 0) |
Frederic Weisbecker | 59f586d | 2009-03-15 22:10:39 +0100 | [diff] [blame] | 3890 | goto out; |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 3891 | ret = 0; |
| 3892 | } |
| 3893 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3894 | for (t = trace_types; t; t = t->next) { |
| 3895 | if (strcmp(t->name, buf) == 0) |
| 3896 | break; |
| 3897 | } |
Frederic Weisbecker | c2931e0 | 2008-10-04 22:04:44 +0200 | [diff] [blame] | 3898 | if (!t) { |
| 3899 | ret = -EINVAL; |
| 3900 | goto out; |
| 3901 | } |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3902 | if (t == tr->current_trace) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3903 | goto out; |
| 3904 | |
Steven Rostedt | 9f029e8 | 2008-11-12 15:24:24 -0500 | [diff] [blame] | 3905 | trace_branch_disable(); |
Steven Rostedt (Red Hat) | 613f04a | 2013-03-14 15:03:53 -0400 | [diff] [blame] | 3906 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3907 | tr->current_trace->enabled = false; |
Steven Rostedt (Red Hat) | 613f04a | 2013-03-14 15:03:53 -0400 | [diff] [blame] | 3908 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3909 | if (tr->current_trace->reset) |
| 3910 | tr->current_trace->reset(tr); |
Steven Rostedt | 34600f0 | 2013-01-22 13:35:11 -0500 | [diff] [blame] | 3911 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3912 | /* Current trace needs to be nop_trace before synchronize_sched */ |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3913 | tr->current_trace = &nop_trace; |
Steven Rostedt | 34600f0 | 2013-01-22 13:35:11 -0500 | [diff] [blame] | 3914 | |
Steven Rostedt (Red Hat) | 45ad21c | 2013-03-05 18:25:02 -0500 | [diff] [blame] | 3915 | #ifdef CONFIG_TRACER_MAX_TRACE |
| 3916 | had_max_tr = tr->allocated_snapshot; |
Steven Rostedt | 34600f0 | 2013-01-22 13:35:11 -0500 | [diff] [blame] | 3917 | |
| 3918 | if (had_max_tr && !t->use_max_tr) { |
| 3919 | /* |
| 3920 | * We need to make sure that the update_max_tr sees that |
| 3921 | * current_trace changed to nop_trace to keep it from |
| 3922 | * swapping the buffers after we resize it. |
| 3923 | * The update_max_tr is called from interrupts disabled |
| 3924 | * so a synchronized_sched() is sufficient. |
| 3925 | */ |
| 3926 | synchronize_sched(); |
Steven Rostedt (Red Hat) | 3209cff | 2013-03-12 11:17:54 -0400 | [diff] [blame] | 3927 | free_snapshot(tr); |
KOSAKI Motohiro | ef710e1 | 2010-07-01 14:34:35 +0900 | [diff] [blame] | 3928 | } |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3929 | #endif |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 3930 | destroy_trace_option_files(topts); |
| 3931 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3932 | topts = create_trace_option_files(tr, t); |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3933 | |
| 3934 | #ifdef CONFIG_TRACER_MAX_TRACE |
Steven Rostedt | 34600f0 | 2013-01-22 13:35:11 -0500 | [diff] [blame] | 3935 | if (t->use_max_tr && !had_max_tr) { |
Steven Rostedt (Red Hat) | 3209cff | 2013-03-12 11:17:54 -0400 | [diff] [blame] | 3936 | ret = alloc_snapshot(tr); |
Hiraku Toyooka | d60da50 | 2012-10-17 11:56:16 +0900 | [diff] [blame] | 3937 | if (ret < 0) |
| 3938 | goto out; |
KOSAKI Motohiro | ef710e1 | 2010-07-01 14:34:35 +0900 | [diff] [blame] | 3939 | } |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3940 | #endif |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 3941 | |
Frederic Weisbecker | 1c80025 | 2008-11-16 05:57:26 +0100 | [diff] [blame] | 3942 | if (t->init) { |
Arnaldo Carvalho de Melo | b6f11df | 2009-02-05 18:02:00 -0200 | [diff] [blame] | 3943 | ret = tracer_init(t, tr); |
Frederic Weisbecker | 1c80025 | 2008-11-16 05:57:26 +0100 | [diff] [blame] | 3944 | if (ret) |
| 3945 | goto out; |
| 3946 | } |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3947 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3948 | tr->current_trace = t; |
| 3949 | tr->current_trace->enabled = true; |
Steven Rostedt | 9f029e8 | 2008-11-12 15:24:24 -0500 | [diff] [blame] | 3950 | trace_branch_enable(tr); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3951 | out: |
| 3952 | mutex_unlock(&trace_types_lock); |
| 3953 | |
Peter Zijlstra | d9e5407 | 2008-11-01 19:57:37 +0100 | [diff] [blame] | 3954 | return ret; |
| 3955 | } |
| 3956 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3957 | static ssize_t |
| 3958 | tracing_set_trace_write(struct file *filp, const char __user *ubuf, |
| 3959 | size_t cnt, loff_t *ppos) |
| 3960 | { |
Li Zefan | ee6c2c1 | 2009-09-18 14:06:47 +0800 | [diff] [blame] | 3961 | char buf[MAX_TRACER_SIZE+1]; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3962 | int i; |
| 3963 | size_t ret; |
Frederic Weisbecker | e6e7a65 | 2008-11-16 05:53:19 +0100 | [diff] [blame] | 3964 | int err; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3965 | |
Steven Rostedt | 60063a6 | 2008-10-28 10:44:24 -0400 | [diff] [blame] | 3966 | ret = cnt; |
| 3967 | |
Li Zefan | ee6c2c1 | 2009-09-18 14:06:47 +0800 | [diff] [blame] | 3968 | if (cnt > MAX_TRACER_SIZE) |
| 3969 | cnt = MAX_TRACER_SIZE; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3970 | |
| 3971 | if (copy_from_user(&buf, ubuf, cnt)) |
| 3972 | return -EFAULT; |
| 3973 | |
| 3974 | buf[cnt] = 0; |
| 3975 | |
| 3976 | /* strip ending whitespace. */ |
| 3977 | for (i = cnt - 1; i > 0 && isspace(buf[i]); i--) |
| 3978 | buf[i] = 0; |
| 3979 | |
Frederic Weisbecker | e6e7a65 | 2008-11-16 05:53:19 +0100 | [diff] [blame] | 3980 | err = tracing_set_tracer(buf); |
| 3981 | if (err) |
| 3982 | return err; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3983 | |
Jiri Olsa | cf8517c | 2009-10-23 19:36:16 -0400 | [diff] [blame] | 3984 | *ppos += ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3985 | |
Frederic Weisbecker | c2931e0 | 2008-10-04 22:04:44 +0200 | [diff] [blame] | 3986 | return ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3987 | } |
| 3988 | |
| 3989 | static ssize_t |
| 3990 | tracing_max_lat_read(struct file *filp, char __user *ubuf, |
| 3991 | size_t cnt, loff_t *ppos) |
| 3992 | { |
| 3993 | unsigned long *ptr = filp->private_data; |
| 3994 | char buf[64]; |
| 3995 | int r; |
| 3996 | |
Steven Rostedt | cffae43 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 3997 | r = snprintf(buf, sizeof(buf), "%ld\n", |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3998 | *ptr == (unsigned long)-1 ? -1 : nsecs_to_usecs(*ptr)); |
Steven Rostedt | cffae43 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 3999 | if (r > sizeof(buf)) |
| 4000 | r = sizeof(buf); |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4001 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, r); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4002 | } |
| 4003 | |
| 4004 | static ssize_t |
| 4005 | tracing_max_lat_write(struct file *filp, const char __user *ubuf, |
| 4006 | size_t cnt, loff_t *ppos) |
| 4007 | { |
Hannes Eder | 5e39841 | 2009-02-10 19:44:34 +0100 | [diff] [blame] | 4008 | unsigned long *ptr = filp->private_data; |
Hannes Eder | 5e39841 | 2009-02-10 19:44:34 +0100 | [diff] [blame] | 4009 | unsigned long val; |
Steven Rostedt | c6caeeb | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 4010 | int ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4011 | |
Peter Huewe | 22fe9b5 | 2011-06-07 21:58:27 +0200 | [diff] [blame] | 4012 | ret = kstrtoul_from_user(ubuf, cnt, 10, &val); |
| 4013 | if (ret) |
Steven Rostedt | c6caeeb | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 4014 | return ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4015 | |
| 4016 | *ptr = val * 1000; |
| 4017 | |
| 4018 | return cnt; |
| 4019 | } |
| 4020 | |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4021 | static int tracing_open_pipe(struct inode *inode, struct file *filp) |
| 4022 | { |
Oleg Nesterov | 1554420 | 2013-07-23 17:25:57 +0200 | [diff] [blame] | 4023 | struct trace_array *tr = inode->i_private; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4024 | struct trace_iterator *iter; |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 4025 | int ret = 0; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4026 | |
| 4027 | if (tracing_disabled) |
| 4028 | return -ENODEV; |
| 4029 | |
Steven Rostedt (Red Hat) | 7b85af6 | 2013-07-01 23:34:22 -0400 | [diff] [blame] | 4030 | if (trace_array_get(tr) < 0) |
| 4031 | return -ENODEV; |
| 4032 | |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 4033 | mutex_lock(&trace_types_lock); |
| 4034 | |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4035 | /* create a buffer to store the information to pass to userspace */ |
| 4036 | iter = kzalloc(sizeof(*iter), GFP_KERNEL); |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 4037 | if (!iter) { |
| 4038 | ret = -ENOMEM; |
Alexander Z Lam | f77d09a | 2013-07-18 11:18:44 -0700 | [diff] [blame] | 4039 | __trace_array_put(tr); |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 4040 | goto out; |
| 4041 | } |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4042 | |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 4043 | /* |
| 4044 | * We make a copy of the current tracer to avoid concurrent |
| 4045 | * changes on it while we are reading. |
| 4046 | */ |
| 4047 | iter->trace = kmalloc(sizeof(*iter->trace), GFP_KERNEL); |
| 4048 | if (!iter->trace) { |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 4049 | ret = -ENOMEM; |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 4050 | goto fail; |
| 4051 | } |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4052 | *iter->trace = *tr->current_trace; |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 4053 | |
| 4054 | if (!alloc_cpumask_var(&iter->started, GFP_KERNEL)) { |
| 4055 | ret = -ENOMEM; |
| 4056 | goto fail; |
Rusty Russell | 4462344 | 2009-01-01 10:12:23 +1030 | [diff] [blame] | 4057 | } |
| 4058 | |
Steven Rostedt | a309720 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 4059 | /* trace pipe does not show start of buffer */ |
Rusty Russell | 4462344 | 2009-01-01 10:12:23 +1030 | [diff] [blame] | 4060 | cpumask_setall(iter->started); |
Steven Rostedt | a309720 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 4061 | |
Steven Rostedt | 112f38a7 | 2009-06-01 15:16:05 -0400 | [diff] [blame] | 4062 | if (trace_flags & TRACE_ITER_LATENCY_FMT) |
| 4063 | iter->iter_flags |= TRACE_FILE_LAT_FMT; |
| 4064 | |
David Sharp | 8be0709 | 2012-11-13 12:18:22 -0800 | [diff] [blame] | 4065 | /* Output in nanoseconds only if we are using a clock in nanoseconds. */ |
Yoshihiro YUNOMAE | 58e8eed | 2013-04-23 10:32:39 +0900 | [diff] [blame] | 4066 | if (trace_clocks[tr->clock_id].in_ns) |
David Sharp | 8be0709 | 2012-11-13 12:18:22 -0800 | [diff] [blame] | 4067 | iter->iter_flags |= TRACE_FILE_TIME_IN_NS; |
| 4068 | |
Oleg Nesterov | 1554420 | 2013-07-23 17:25:57 +0200 | [diff] [blame] | 4069 | iter->tr = tr; |
| 4070 | iter->trace_buffer = &tr->trace_buffer; |
| 4071 | iter->cpu_file = tracing_get_cpu(inode); |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 4072 | mutex_init(&iter->mutex); |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4073 | filp->private_data = iter; |
| 4074 | |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 4075 | if (iter->trace->pipe_open) |
| 4076 | iter->trace->pipe_open(iter); |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 4077 | |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 4078 | nonseekable_open(inode, filp); |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 4079 | out: |
| 4080 | mutex_unlock(&trace_types_lock); |
| 4081 | return ret; |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 4082 | |
| 4083 | fail: |
| 4084 | kfree(iter->trace); |
| 4085 | kfree(iter); |
Steven Rostedt (Red Hat) | 7b85af6 | 2013-07-01 23:34:22 -0400 | [diff] [blame] | 4086 | __trace_array_put(tr); |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 4087 | mutex_unlock(&trace_types_lock); |
| 4088 | return ret; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4089 | } |
| 4090 | |
| 4091 | static int tracing_release_pipe(struct inode *inode, struct file *file) |
| 4092 | { |
| 4093 | struct trace_iterator *iter = file->private_data; |
Oleg Nesterov | 1554420 | 2013-07-23 17:25:57 +0200 | [diff] [blame] | 4094 | struct trace_array *tr = inode->i_private; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4095 | |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 4096 | mutex_lock(&trace_types_lock); |
| 4097 | |
Steven Rostedt | 29bf4a5 | 2009-12-09 12:37:43 -0500 | [diff] [blame] | 4098 | if (iter->trace->pipe_close) |
Steven Rostedt | c521efd | 2009-12-07 09:06:24 -0500 | [diff] [blame] | 4099 | iter->trace->pipe_close(iter); |
| 4100 | |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 4101 | mutex_unlock(&trace_types_lock); |
| 4102 | |
Rusty Russell | 4462344 | 2009-01-01 10:12:23 +1030 | [diff] [blame] | 4103 | free_cpumask_var(iter->started); |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 4104 | mutex_destroy(&iter->mutex); |
| 4105 | kfree(iter->trace); |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4106 | kfree(iter); |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4107 | |
Steven Rostedt (Red Hat) | 7b85af6 | 2013-07-01 23:34:22 -0400 | [diff] [blame] | 4108 | trace_array_put(tr); |
| 4109 | |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4110 | return 0; |
| 4111 | } |
| 4112 | |
Soeren Sandmann Pedersen | 2a2cc8f | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 4113 | static unsigned int |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 4114 | trace_poll(struct trace_iterator *iter, struct file *filp, poll_table *poll_table) |
Soeren Sandmann Pedersen | 2a2cc8f | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 4115 | { |
Steven Rostedt (Red Hat) | 1569345 | 2013-02-28 19:59:17 -0500 | [diff] [blame] | 4116 | /* Iterators are static, they should be filled or empty */ |
| 4117 | if (trace_buffer_iter(iter, iter->cpu_file)) |
| 4118 | return POLLIN | POLLRDNORM; |
Soeren Sandmann Pedersen | 2a2cc8f | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 4119 | |
Steven Rostedt (Red Hat) | 1569345 | 2013-02-28 19:59:17 -0500 | [diff] [blame] | 4120 | if (trace_flags & TRACE_ITER_BLOCK) |
Soeren Sandmann Pedersen | 2a2cc8f | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 4121 | /* |
| 4122 | * Always select as readable when in blocking mode |
| 4123 | */ |
| 4124 | return POLLIN | POLLRDNORM; |
Steven Rostedt (Red Hat) | 1569345 | 2013-02-28 19:59:17 -0500 | [diff] [blame] | 4125 | else |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4126 | return ring_buffer_poll_wait(iter->trace_buffer->buffer, iter->cpu_file, |
Steven Rostedt (Red Hat) | 1569345 | 2013-02-28 19:59:17 -0500 | [diff] [blame] | 4127 | filp, poll_table); |
Soeren Sandmann Pedersen | 2a2cc8f | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 4128 | } |
Soeren Sandmann Pedersen | 2a2cc8f | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 4129 | |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 4130 | static unsigned int |
| 4131 | tracing_poll_pipe(struct file *filp, poll_table *poll_table) |
| 4132 | { |
| 4133 | struct trace_iterator *iter = filp->private_data; |
| 4134 | |
| 4135 | return trace_poll(iter, filp, poll_table); |
Soeren Sandmann Pedersen | 2a2cc8f | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 4136 | } |
| 4137 | |
Frederic Weisbecker | 6eaaa5d | 2009-02-11 02:25:00 +0100 | [diff] [blame] | 4138 | /* |
| 4139 | * This is a make-shift waitqueue. |
| 4140 | * A tracer might use this callback on some rare cases: |
| 4141 | * |
| 4142 | * 1) the current tracer might hold the runqueue lock when it wakes up |
| 4143 | * a reader, hence a deadlock (sched, function, and function graph tracers) |
| 4144 | * 2) the function tracers, trace all functions, we don't want |
| 4145 | * the overhead of calling wake_up and friends |
| 4146 | * (and tracing them too) |
| 4147 | * |
| 4148 | * Anyway, this is really very primitive wakeup. |
| 4149 | */ |
| 4150 | void poll_wait_pipe(struct trace_iterator *iter) |
| 4151 | { |
| 4152 | set_current_state(TASK_INTERRUPTIBLE); |
| 4153 | /* sleep for 100 msecs, and try again. */ |
| 4154 | schedule_timeout(HZ / 10); |
| 4155 | } |
| 4156 | |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 4157 | /* Must be called with trace_types_lock mutex held. */ |
| 4158 | static int tracing_wait_pipe(struct file *filp) |
| 4159 | { |
| 4160 | struct trace_iterator *iter = filp->private_data; |
| 4161 | |
| 4162 | while (trace_empty(iter)) { |
| 4163 | |
| 4164 | if ((filp->f_flags & O_NONBLOCK)) { |
| 4165 | return -EAGAIN; |
| 4166 | } |
| 4167 | |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 4168 | mutex_unlock(&iter->mutex); |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 4169 | |
Frederic Weisbecker | 6eaaa5d | 2009-02-11 02:25:00 +0100 | [diff] [blame] | 4170 | iter->trace->wait_pipe(iter); |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 4171 | |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 4172 | mutex_lock(&iter->mutex); |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 4173 | |
Frederic Weisbecker | 6eaaa5d | 2009-02-11 02:25:00 +0100 | [diff] [blame] | 4174 | if (signal_pending(current)) |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 4175 | return -EINTR; |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 4176 | |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 4177 | /* |
Liu Bo | 250bfd3 | 2013-01-14 10:54:11 +0800 | [diff] [blame] | 4178 | * We block until we read something and tracing is disabled. |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 4179 | * We still block if tracing is disabled, but we have never |
| 4180 | * read anything. This allows a user to cat this file, and |
| 4181 | * then enable tracing. But after we have read something, |
| 4182 | * we give an EOF when tracing is again disabled. |
| 4183 | * |
| 4184 | * iter->pos will be 0 if we haven't read anything. |
| 4185 | */ |
Steven Rostedt (Red Hat) | 10246fa | 2013-07-01 15:58:24 -0400 | [diff] [blame] | 4186 | if (!tracing_is_on() && iter->pos) |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 4187 | break; |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 4188 | } |
| 4189 | |
| 4190 | return 1; |
| 4191 | } |
| 4192 | |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4193 | /* |
| 4194 | * Consumer reader. |
| 4195 | */ |
| 4196 | static ssize_t |
| 4197 | tracing_read_pipe(struct file *filp, char __user *ubuf, |
| 4198 | size_t cnt, loff_t *ppos) |
| 4199 | { |
| 4200 | struct trace_iterator *iter = filp->private_data; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4201 | struct trace_array *tr = iter->tr; |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 4202 | ssize_t sret; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4203 | |
| 4204 | /* return any leftover data */ |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 4205 | sret = trace_seq_to_user(&iter->seq, ubuf, cnt); |
| 4206 | if (sret != -EBUSY) |
| 4207 | return sret; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4208 | |
Steven Rostedt | f952075 | 2009-03-02 14:04:40 -0500 | [diff] [blame] | 4209 | trace_seq_init(&iter->seq); |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4210 | |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 4211 | /* copy the tracer to avoid using a global lock all around */ |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 4212 | mutex_lock(&trace_types_lock); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4213 | if (unlikely(iter->trace->name != tr->current_trace->name)) |
| 4214 | *iter->trace = *tr->current_trace; |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 4215 | mutex_unlock(&trace_types_lock); |
| 4216 | |
| 4217 | /* |
| 4218 | * Avoid more than one consumer on a single file descriptor |
| 4219 | * This is just a matter of traces coherency, the ring buffer itself |
| 4220 | * is protected. |
| 4221 | */ |
| 4222 | mutex_lock(&iter->mutex); |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 4223 | if (iter->trace->read) { |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 4224 | sret = iter->trace->read(iter, filp, ubuf, cnt, ppos); |
| 4225 | if (sret) |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 4226 | goto out; |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 4227 | } |
| 4228 | |
Pekka Paalanen | 9ff4b97 | 2008-09-29 20:23:48 +0200 | [diff] [blame] | 4229 | waitagain: |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 4230 | sret = tracing_wait_pipe(filp); |
| 4231 | if (sret <= 0) |
| 4232 | goto out; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4233 | |
| 4234 | /* stop when tracing is finished */ |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 4235 | if (trace_empty(iter)) { |
| 4236 | sret = 0; |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 4237 | goto out; |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 4238 | } |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4239 | |
| 4240 | if (cnt >= PAGE_SIZE) |
| 4241 | cnt = PAGE_SIZE - 1; |
| 4242 | |
Steven Rostedt | 53d0aa7 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 4243 | /* reset all but tr, trace, and overruns */ |
Steven Rostedt | 53d0aa7 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 4244 | memset(&iter->seq, 0, |
| 4245 | sizeof(struct trace_iterator) - |
| 4246 | offsetof(struct trace_iterator, seq)); |
Andrew Vagin | ed5467d | 2013-08-02 21:16:43 +0400 | [diff] [blame] | 4247 | cpumask_clear(iter->started); |
Steven Rostedt | 4823ed7 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 4248 | iter->pos = -1; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4249 | |
Lai Jiangshan | 4f53596 | 2009-05-18 19:35:34 +0800 | [diff] [blame] | 4250 | trace_event_read_lock(); |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 4251 | trace_access_lock(iter->cpu_file); |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 4252 | while (trace_find_next_entry_inc(iter) != NULL) { |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 4253 | enum print_line_t ret; |
Steven Rostedt | 088b1e42 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 4254 | int len = iter->seq.len; |
| 4255 | |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 4256 | ret = print_trace_line(iter); |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 4257 | if (ret == TRACE_TYPE_PARTIAL_LINE) { |
Steven Rostedt | 088b1e42 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 4258 | /* don't print partial lines */ |
| 4259 | iter->seq.len = len; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4260 | break; |
Steven Rostedt | 088b1e42 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 4261 | } |
Frederic Weisbecker | b91facc | 2009-02-06 18:30:44 +0100 | [diff] [blame] | 4262 | if (ret != TRACE_TYPE_NO_CONSUME) |
| 4263 | trace_consume(iter); |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4264 | |
| 4265 | if (iter->seq.len >= cnt) |
| 4266 | break; |
Jiri Olsa | ee5e51f | 2011-03-25 12:05:18 +0100 | [diff] [blame] | 4267 | |
| 4268 | /* |
| 4269 | * Setting the full flag means we reached the trace_seq buffer |
| 4270 | * size and we should leave by partial output condition above. |
| 4271 | * One of the trace_seq_* functions is not used properly. |
| 4272 | */ |
| 4273 | WARN_ONCE(iter->seq.full, "full flag set for trace type %d", |
| 4274 | iter->ent->type); |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4275 | } |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 4276 | trace_access_unlock(iter->cpu_file); |
Lai Jiangshan | 4f53596 | 2009-05-18 19:35:34 +0800 | [diff] [blame] | 4277 | trace_event_read_unlock(); |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4278 | |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4279 | /* Now copy what we have to the user */ |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 4280 | sret = trace_seq_to_user(&iter->seq, ubuf, cnt); |
| 4281 | if (iter->seq.readpos >= iter->seq.len) |
Steven Rostedt | f952075 | 2009-03-02 14:04:40 -0500 | [diff] [blame] | 4282 | trace_seq_init(&iter->seq); |
Pekka Paalanen | 9ff4b97 | 2008-09-29 20:23:48 +0200 | [diff] [blame] | 4283 | |
| 4284 | /* |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 4285 | * If there was nothing to send to user, in spite of consuming trace |
Pekka Paalanen | 9ff4b97 | 2008-09-29 20:23:48 +0200 | [diff] [blame] | 4286 | * entries, go back to wait for more entries. |
| 4287 | */ |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 4288 | if (sret == -EBUSY) |
Pekka Paalanen | 9ff4b97 | 2008-09-29 20:23:48 +0200 | [diff] [blame] | 4289 | goto waitagain; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4290 | |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 4291 | out: |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 4292 | mutex_unlock(&iter->mutex); |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 4293 | |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 4294 | return sret; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4295 | } |
| 4296 | |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4297 | static void tracing_spd_release_pipe(struct splice_pipe_desc *spd, |
| 4298 | unsigned int idx) |
| 4299 | { |
| 4300 | __free_page(spd->pages[idx]); |
| 4301 | } |
| 4302 | |
Alexey Dobriyan | 28dfef8 | 2009-12-15 16:46:48 -0800 | [diff] [blame] | 4303 | static const struct pipe_buf_operations tracing_pipe_buf_ops = { |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 4304 | .can_merge = 0, |
| 4305 | .map = generic_pipe_buf_map, |
| 4306 | .unmap = generic_pipe_buf_unmap, |
| 4307 | .confirm = generic_pipe_buf_confirm, |
Al Viro | 92fdd98 | 2014-01-17 07:53:39 -0500 | [diff] [blame] | 4308 | .release = generic_pipe_buf_release, |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 4309 | .steal = generic_pipe_buf_steal, |
| 4310 | .get = generic_pipe_buf_get, |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4311 | }; |
| 4312 | |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 4313 | static size_t |
Frederic Weisbecker | fa7c7f6 | 2009-02-11 02:51:30 +0100 | [diff] [blame] | 4314 | tracing_fill_pipe_page(size_t rem, struct trace_iterator *iter) |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 4315 | { |
| 4316 | size_t count; |
| 4317 | int ret; |
| 4318 | |
| 4319 | /* Seq buffer is page-sized, exactly what we need. */ |
| 4320 | for (;;) { |
| 4321 | count = iter->seq.len; |
| 4322 | ret = print_trace_line(iter); |
| 4323 | count = iter->seq.len - count; |
| 4324 | if (rem < count) { |
| 4325 | rem = 0; |
| 4326 | iter->seq.len -= count; |
| 4327 | break; |
| 4328 | } |
| 4329 | if (ret == TRACE_TYPE_PARTIAL_LINE) { |
| 4330 | iter->seq.len -= count; |
| 4331 | break; |
| 4332 | } |
| 4333 | |
Lai Jiangshan | 74e7ff8 | 2009-07-28 20:17:22 +0800 | [diff] [blame] | 4334 | if (ret != TRACE_TYPE_NO_CONSUME) |
| 4335 | trace_consume(iter); |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 4336 | rem -= count; |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 4337 | if (!trace_find_next_entry_inc(iter)) { |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 4338 | rem = 0; |
| 4339 | iter->ent = NULL; |
| 4340 | break; |
| 4341 | } |
| 4342 | } |
| 4343 | |
| 4344 | return rem; |
| 4345 | } |
| 4346 | |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4347 | static ssize_t tracing_splice_read_pipe(struct file *filp, |
| 4348 | loff_t *ppos, |
| 4349 | struct pipe_inode_info *pipe, |
| 4350 | size_t len, |
| 4351 | unsigned int flags) |
| 4352 | { |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 4353 | struct page *pages_def[PIPE_DEF_BUFFERS]; |
| 4354 | struct partial_page partial_def[PIPE_DEF_BUFFERS]; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4355 | struct trace_iterator *iter = filp->private_data; |
| 4356 | struct splice_pipe_desc spd = { |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 4357 | .pages = pages_def, |
| 4358 | .partial = partial_def, |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 4359 | .nr_pages = 0, /* This gets updated below. */ |
Eric Dumazet | 047fe36 | 2012-06-12 15:24:40 +0200 | [diff] [blame] | 4360 | .nr_pages_max = PIPE_DEF_BUFFERS, |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 4361 | .flags = flags, |
| 4362 | .ops = &tracing_pipe_buf_ops, |
| 4363 | .spd_release = tracing_spd_release_pipe, |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4364 | }; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4365 | struct trace_array *tr = iter->tr; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4366 | ssize_t ret; |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 4367 | size_t rem; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4368 | unsigned int i; |
| 4369 | |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 4370 | if (splice_grow_spd(pipe, &spd)) |
| 4371 | return -ENOMEM; |
| 4372 | |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 4373 | /* copy the tracer to avoid using a global lock all around */ |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4374 | mutex_lock(&trace_types_lock); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4375 | if (unlikely(iter->trace->name != tr->current_trace->name)) |
| 4376 | *iter->trace = *tr->current_trace; |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 4377 | mutex_unlock(&trace_types_lock); |
| 4378 | |
| 4379 | mutex_lock(&iter->mutex); |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4380 | |
| 4381 | if (iter->trace->splice_read) { |
| 4382 | ret = iter->trace->splice_read(iter, filp, |
| 4383 | ppos, pipe, len, flags); |
| 4384 | if (ret) |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 4385 | goto out_err; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4386 | } |
| 4387 | |
| 4388 | ret = tracing_wait_pipe(filp); |
| 4389 | if (ret <= 0) |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 4390 | goto out_err; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4391 | |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 4392 | if (!iter->ent && !trace_find_next_entry_inc(iter)) { |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4393 | ret = -EFAULT; |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 4394 | goto out_err; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4395 | } |
| 4396 | |
Lai Jiangshan | 4f53596 | 2009-05-18 19:35:34 +0800 | [diff] [blame] | 4397 | trace_event_read_lock(); |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 4398 | trace_access_lock(iter->cpu_file); |
Lai Jiangshan | 4f53596 | 2009-05-18 19:35:34 +0800 | [diff] [blame] | 4399 | |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4400 | /* Fill as many pages as possible. */ |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 4401 | for (i = 0, rem = len; i < pipe->buffers && rem; i++) { |
| 4402 | spd.pages[i] = alloc_page(GFP_KERNEL); |
| 4403 | if (!spd.pages[i]) |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 4404 | break; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4405 | |
Frederic Weisbecker | fa7c7f6 | 2009-02-11 02:51:30 +0100 | [diff] [blame] | 4406 | rem = tracing_fill_pipe_page(rem, iter); |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4407 | |
| 4408 | /* Copy the data into the page, so we can start over. */ |
| 4409 | ret = trace_seq_to_buffer(&iter->seq, |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 4410 | page_address(spd.pages[i]), |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4411 | iter->seq.len); |
| 4412 | if (ret < 0) { |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 4413 | __free_page(spd.pages[i]); |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4414 | break; |
| 4415 | } |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 4416 | spd.partial[i].offset = 0; |
| 4417 | spd.partial[i].len = iter->seq.len; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4418 | |
Steven Rostedt | f952075 | 2009-03-02 14:04:40 -0500 | [diff] [blame] | 4419 | trace_seq_init(&iter->seq); |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4420 | } |
| 4421 | |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 4422 | trace_access_unlock(iter->cpu_file); |
Lai Jiangshan | 4f53596 | 2009-05-18 19:35:34 +0800 | [diff] [blame] | 4423 | trace_event_read_unlock(); |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 4424 | mutex_unlock(&iter->mutex); |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4425 | |
| 4426 | spd.nr_pages = i; |
| 4427 | |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 4428 | ret = splice_to_pipe(pipe, &spd); |
| 4429 | out: |
Eric Dumazet | 047fe36 | 2012-06-12 15:24:40 +0200 | [diff] [blame] | 4430 | splice_shrink_spd(&spd); |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 4431 | return ret; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4432 | |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 4433 | out_err: |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 4434 | mutex_unlock(&iter->mutex); |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 4435 | goto out; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4436 | } |
| 4437 | |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 4438 | static ssize_t |
| 4439 | tracing_entries_read(struct file *filp, char __user *ubuf, |
| 4440 | size_t cnt, loff_t *ppos) |
| 4441 | { |
Oleg Nesterov | 0bc392e | 2013-07-23 17:26:06 +0200 | [diff] [blame] | 4442 | struct inode *inode = file_inode(filp); |
| 4443 | struct trace_array *tr = inode->i_private; |
| 4444 | int cpu = tracing_get_cpu(inode); |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 4445 | char buf[64]; |
| 4446 | int r = 0; |
| 4447 | ssize_t ret; |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 4448 | |
Steven Rostedt | db526ca | 2009-03-12 13:53:25 -0400 | [diff] [blame] | 4449 | mutex_lock(&trace_types_lock); |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 4450 | |
Oleg Nesterov | 0bc392e | 2013-07-23 17:26:06 +0200 | [diff] [blame] | 4451 | if (cpu == RING_BUFFER_ALL_CPUS) { |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 4452 | int cpu, buf_size_same; |
| 4453 | unsigned long size; |
| 4454 | |
| 4455 | size = 0; |
| 4456 | buf_size_same = 1; |
| 4457 | /* check if all cpu sizes are same */ |
| 4458 | for_each_tracing_cpu(cpu) { |
| 4459 | /* fill in the size from first enabled cpu */ |
| 4460 | if (size == 0) |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4461 | size = per_cpu_ptr(tr->trace_buffer.data, cpu)->entries; |
| 4462 | if (size != per_cpu_ptr(tr->trace_buffer.data, cpu)->entries) { |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 4463 | buf_size_same = 0; |
| 4464 | break; |
| 4465 | } |
| 4466 | } |
| 4467 | |
| 4468 | if (buf_size_same) { |
| 4469 | if (!ring_buffer_expanded) |
| 4470 | r = sprintf(buf, "%lu (expanded: %lu)\n", |
| 4471 | size >> 10, |
| 4472 | trace_buf_size >> 10); |
| 4473 | else |
| 4474 | r = sprintf(buf, "%lu\n", size >> 10); |
| 4475 | } else |
| 4476 | r = sprintf(buf, "X\n"); |
| 4477 | } else |
Oleg Nesterov | 0bc392e | 2013-07-23 17:26:06 +0200 | [diff] [blame] | 4478 | r = sprintf(buf, "%lu\n", per_cpu_ptr(tr->trace_buffer.data, cpu)->entries >> 10); |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 4479 | |
Steven Rostedt | db526ca | 2009-03-12 13:53:25 -0400 | [diff] [blame] | 4480 | mutex_unlock(&trace_types_lock); |
| 4481 | |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 4482 | ret = simple_read_from_buffer(ubuf, cnt, ppos, buf, r); |
| 4483 | return ret; |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 4484 | } |
| 4485 | |
| 4486 | static ssize_t |
| 4487 | tracing_entries_write(struct file *filp, const char __user *ubuf, |
| 4488 | size_t cnt, loff_t *ppos) |
| 4489 | { |
Oleg Nesterov | 0bc392e | 2013-07-23 17:26:06 +0200 | [diff] [blame] | 4490 | struct inode *inode = file_inode(filp); |
| 4491 | struct trace_array *tr = inode->i_private; |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 4492 | unsigned long val; |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 4493 | int ret; |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 4494 | |
Peter Huewe | 22fe9b5 | 2011-06-07 21:58:27 +0200 | [diff] [blame] | 4495 | ret = kstrtoul_from_user(ubuf, cnt, 10, &val); |
| 4496 | if (ret) |
Steven Rostedt | c6caeeb | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 4497 | return ret; |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 4498 | |
| 4499 | /* must have at least 1 entry */ |
| 4500 | if (!val) |
| 4501 | return -EINVAL; |
| 4502 | |
Steven Rostedt | 1696b2b | 2008-11-13 00:09:35 -0500 | [diff] [blame] | 4503 | /* value is in KB */ |
| 4504 | val <<= 10; |
Oleg Nesterov | 0bc392e | 2013-07-23 17:26:06 +0200 | [diff] [blame] | 4505 | ret = tracing_resize_ring_buffer(tr, val, tracing_get_cpu(inode)); |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 4506 | if (ret < 0) |
| 4507 | return ret; |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 4508 | |
Jiri Olsa | cf8517c | 2009-10-23 19:36:16 -0400 | [diff] [blame] | 4509 | *ppos += cnt; |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 4510 | |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 4511 | return cnt; |
| 4512 | } |
Steven Rostedt | bf5e651 | 2008-11-10 21:46:00 -0500 | [diff] [blame] | 4513 | |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 4514 | static ssize_t |
Vaibhav Nagarnaik | f81ab07 | 2011-08-16 14:46:15 -0700 | [diff] [blame] | 4515 | tracing_total_entries_read(struct file *filp, char __user *ubuf, |
| 4516 | size_t cnt, loff_t *ppos) |
| 4517 | { |
| 4518 | struct trace_array *tr = filp->private_data; |
| 4519 | char buf[64]; |
| 4520 | int r, cpu; |
| 4521 | unsigned long size = 0, expanded_size = 0; |
| 4522 | |
| 4523 | mutex_lock(&trace_types_lock); |
| 4524 | for_each_tracing_cpu(cpu) { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4525 | size += per_cpu_ptr(tr->trace_buffer.data, cpu)->entries >> 10; |
Vaibhav Nagarnaik | f81ab07 | 2011-08-16 14:46:15 -0700 | [diff] [blame] | 4526 | if (!ring_buffer_expanded) |
| 4527 | expanded_size += trace_buf_size >> 10; |
| 4528 | } |
| 4529 | if (ring_buffer_expanded) |
| 4530 | r = sprintf(buf, "%lu\n", size); |
| 4531 | else |
| 4532 | r = sprintf(buf, "%lu (expanded: %lu)\n", size, expanded_size); |
| 4533 | mutex_unlock(&trace_types_lock); |
| 4534 | |
| 4535 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, r); |
| 4536 | } |
| 4537 | |
| 4538 | static ssize_t |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 4539 | tracing_free_buffer_write(struct file *filp, const char __user *ubuf, |
| 4540 | size_t cnt, loff_t *ppos) |
| 4541 | { |
| 4542 | /* |
| 4543 | * There is no need to read what the user has written, this function |
| 4544 | * is just to make sure that there is no error when "echo" is used |
| 4545 | */ |
| 4546 | |
| 4547 | *ppos += cnt; |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 4548 | |
| 4549 | return cnt; |
| 4550 | } |
| 4551 | |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 4552 | static int |
| 4553 | tracing_free_buffer_release(struct inode *inode, struct file *filp) |
| 4554 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4555 | struct trace_array *tr = inode->i_private; |
| 4556 | |
Steven Rostedt | cf30cf6 | 2011-06-14 22:44:07 -0400 | [diff] [blame] | 4557 | /* disable tracing ? */ |
| 4558 | if (trace_flags & TRACE_ITER_STOP_ON_FREE) |
Alexander Z Lam | 711e124 | 2013-08-02 18:36:15 -0700 | [diff] [blame] | 4559 | tracer_tracing_off(tr); |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 4560 | /* resize the ring buffer to 0 */ |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4561 | tracing_resize_ring_buffer(tr, 0, RING_BUFFER_ALL_CPUS); |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 4562 | |
Steven Rostedt (Red Hat) | 7b85af6 | 2013-07-01 23:34:22 -0400 | [diff] [blame] | 4563 | trace_array_put(tr); |
| 4564 | |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 4565 | return 0; |
| 4566 | } |
| 4567 | |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 4568 | static ssize_t |
| 4569 | tracing_mark_write(struct file *filp, const char __user *ubuf, |
| 4570 | size_t cnt, loff_t *fpos) |
| 4571 | { |
Steven Rostedt | d696b58 | 2011-09-22 11:50:27 -0400 | [diff] [blame] | 4572 | unsigned long addr = (unsigned long)ubuf; |
Alexander Z Lam | 2d71619 | 2013-07-01 15:31:24 -0700 | [diff] [blame] | 4573 | struct trace_array *tr = filp->private_data; |
Steven Rostedt | d696b58 | 2011-09-22 11:50:27 -0400 | [diff] [blame] | 4574 | struct ring_buffer_event *event; |
| 4575 | struct ring_buffer *buffer; |
| 4576 | struct print_entry *entry; |
| 4577 | unsigned long irq_flags; |
| 4578 | struct page *pages[2]; |
Steven Rostedt | 6edb2a8 | 2012-05-11 23:28:49 -0400 | [diff] [blame] | 4579 | void *map_page[2]; |
Steven Rostedt | d696b58 | 2011-09-22 11:50:27 -0400 | [diff] [blame] | 4580 | int nr_pages = 1; |
| 4581 | ssize_t written; |
Steven Rostedt | d696b58 | 2011-09-22 11:50:27 -0400 | [diff] [blame] | 4582 | int offset; |
| 4583 | int size; |
| 4584 | int len; |
| 4585 | int ret; |
Steven Rostedt | 6edb2a8 | 2012-05-11 23:28:49 -0400 | [diff] [blame] | 4586 | int i; |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 4587 | |
Steven Rostedt | c76f069 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 4588 | if (tracing_disabled) |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 4589 | return -EINVAL; |
| 4590 | |
Mandeep Singh Baines | 5224c3a | 2012-09-07 18:12:19 -0700 | [diff] [blame] | 4591 | if (!(trace_flags & TRACE_ITER_MARKERS)) |
| 4592 | return -EINVAL; |
| 4593 | |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 4594 | if (cnt > TRACE_BUF_SIZE) |
| 4595 | cnt = TRACE_BUF_SIZE; |
| 4596 | |
Steven Rostedt | d696b58 | 2011-09-22 11:50:27 -0400 | [diff] [blame] | 4597 | /* |
| 4598 | * Userspace is injecting traces into the kernel trace buffer. |
| 4599 | * We want to be as non intrusive as possible. |
| 4600 | * To do so, we do not want to allocate any special buffers |
| 4601 | * or take any locks, but instead write the userspace data |
| 4602 | * straight into the ring buffer. |
| 4603 | * |
| 4604 | * First we need to pin the userspace buffer into memory, |
| 4605 | * which, most likely it is, because it just referenced it. |
| 4606 | * But there's no guarantee that it is. By using get_user_pages_fast() |
| 4607 | * and kmap_atomic/kunmap_atomic() we can get access to the |
| 4608 | * pages directly. We then write the data directly into the |
| 4609 | * ring buffer. |
| 4610 | */ |
| 4611 | BUILD_BUG_ON(TRACE_BUF_SIZE >= PAGE_SIZE); |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 4612 | |
Steven Rostedt | d696b58 | 2011-09-22 11:50:27 -0400 | [diff] [blame] | 4613 | /* check if we cross pages */ |
| 4614 | if ((addr & PAGE_MASK) != ((addr + cnt) & PAGE_MASK)) |
| 4615 | nr_pages = 2; |
| 4616 | |
| 4617 | offset = addr & (PAGE_SIZE - 1); |
| 4618 | addr &= PAGE_MASK; |
| 4619 | |
| 4620 | ret = get_user_pages_fast(addr, nr_pages, 0, pages); |
| 4621 | if (ret < nr_pages) { |
| 4622 | while (--ret >= 0) |
| 4623 | put_page(pages[ret]); |
| 4624 | written = -EFAULT; |
| 4625 | goto out; |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 4626 | } |
| 4627 | |
Steven Rostedt | 6edb2a8 | 2012-05-11 23:28:49 -0400 | [diff] [blame] | 4628 | for (i = 0; i < nr_pages; i++) |
| 4629 | map_page[i] = kmap_atomic(pages[i]); |
Steven Rostedt | d696b58 | 2011-09-22 11:50:27 -0400 | [diff] [blame] | 4630 | |
| 4631 | local_save_flags(irq_flags); |
| 4632 | size = sizeof(*entry) + cnt + 2; /* possible \n added */ |
Alexander Z Lam | 2d71619 | 2013-07-01 15:31:24 -0700 | [diff] [blame] | 4633 | buffer = tr->trace_buffer.buffer; |
Steven Rostedt | d696b58 | 2011-09-22 11:50:27 -0400 | [diff] [blame] | 4634 | event = trace_buffer_lock_reserve(buffer, TRACE_PRINT, size, |
| 4635 | irq_flags, preempt_count()); |
| 4636 | if (!event) { |
| 4637 | /* Ring buffer disabled, return as if not open for write */ |
| 4638 | written = -EBADF; |
| 4639 | goto out_unlock; |
| 4640 | } |
| 4641 | |
| 4642 | entry = ring_buffer_event_data(event); |
| 4643 | entry->ip = _THIS_IP_; |
| 4644 | |
| 4645 | if (nr_pages == 2) { |
| 4646 | len = PAGE_SIZE - offset; |
Steven Rostedt | 6edb2a8 | 2012-05-11 23:28:49 -0400 | [diff] [blame] | 4647 | memcpy(&entry->buf, map_page[0] + offset, len); |
| 4648 | memcpy(&entry->buf[len], map_page[1], cnt - len); |
Steven Rostedt | d696b58 | 2011-09-22 11:50:27 -0400 | [diff] [blame] | 4649 | } else |
Steven Rostedt | 6edb2a8 | 2012-05-11 23:28:49 -0400 | [diff] [blame] | 4650 | memcpy(&entry->buf, map_page[0] + offset, cnt); |
Steven Rostedt | d696b58 | 2011-09-22 11:50:27 -0400 | [diff] [blame] | 4651 | |
| 4652 | if (entry->buf[cnt - 1] != '\n') { |
| 4653 | entry->buf[cnt] = '\n'; |
| 4654 | entry->buf[cnt + 1] = '\0'; |
| 4655 | } else |
| 4656 | entry->buf[cnt] = '\0'; |
| 4657 | |
Steven Rostedt | 7ffbd48 | 2012-10-11 12:14:25 -0400 | [diff] [blame] | 4658 | __buffer_unlock_commit(buffer, event); |
Steven Rostedt | d696b58 | 2011-09-22 11:50:27 -0400 | [diff] [blame] | 4659 | |
| 4660 | written = cnt; |
| 4661 | |
Marcin Slusarz | 1aa54bc | 2010-07-28 01:18:01 +0200 | [diff] [blame] | 4662 | *fpos += written; |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 4663 | |
Steven Rostedt | d696b58 | 2011-09-22 11:50:27 -0400 | [diff] [blame] | 4664 | out_unlock: |
Steven Rostedt | 6edb2a8 | 2012-05-11 23:28:49 -0400 | [diff] [blame] | 4665 | for (i = 0; i < nr_pages; i++){ |
| 4666 | kunmap_atomic(map_page[i]); |
| 4667 | put_page(pages[i]); |
| 4668 | } |
Steven Rostedt | d696b58 | 2011-09-22 11:50:27 -0400 | [diff] [blame] | 4669 | out: |
Marcin Slusarz | 1aa54bc | 2010-07-28 01:18:01 +0200 | [diff] [blame] | 4670 | return written; |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 4671 | } |
| 4672 | |
Li Zefan | 13f16d2 | 2009-12-08 11:16:11 +0800 | [diff] [blame] | 4673 | static int tracing_clock_show(struct seq_file *m, void *v) |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 4674 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4675 | struct trace_array *tr = m->private; |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 4676 | int i; |
| 4677 | |
| 4678 | for (i = 0; i < ARRAY_SIZE(trace_clocks); i++) |
Li Zefan | 13f16d2 | 2009-12-08 11:16:11 +0800 | [diff] [blame] | 4679 | seq_printf(m, |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 4680 | "%s%s%s%s", i ? " " : "", |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4681 | i == tr->clock_id ? "[" : "", trace_clocks[i].name, |
| 4682 | i == tr->clock_id ? "]" : ""); |
Li Zefan | 13f16d2 | 2009-12-08 11:16:11 +0800 | [diff] [blame] | 4683 | seq_putc(m, '\n'); |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 4684 | |
Li Zefan | 13f16d2 | 2009-12-08 11:16:11 +0800 | [diff] [blame] | 4685 | return 0; |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 4686 | } |
| 4687 | |
| 4688 | static ssize_t tracing_clock_write(struct file *filp, const char __user *ubuf, |
| 4689 | size_t cnt, loff_t *fpos) |
| 4690 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4691 | struct seq_file *m = filp->private_data; |
| 4692 | struct trace_array *tr = m->private; |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 4693 | char buf[64]; |
| 4694 | const char *clockstr; |
| 4695 | int i; |
| 4696 | |
| 4697 | if (cnt >= sizeof(buf)) |
| 4698 | return -EINVAL; |
| 4699 | |
| 4700 | if (copy_from_user(&buf, ubuf, cnt)) |
| 4701 | return -EFAULT; |
| 4702 | |
| 4703 | buf[cnt] = 0; |
| 4704 | |
| 4705 | clockstr = strstrip(buf); |
| 4706 | |
| 4707 | for (i = 0; i < ARRAY_SIZE(trace_clocks); i++) { |
| 4708 | if (strcmp(trace_clocks[i].name, clockstr) == 0) |
| 4709 | break; |
| 4710 | } |
| 4711 | if (i == ARRAY_SIZE(trace_clocks)) |
| 4712 | return -EINVAL; |
| 4713 | |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 4714 | mutex_lock(&trace_types_lock); |
| 4715 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4716 | tr->clock_id = i; |
| 4717 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4718 | ring_buffer_set_clock(tr->trace_buffer.buffer, trace_clocks[i].func); |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 4719 | |
David Sharp | 60303ed | 2012-10-11 16:27:52 -0700 | [diff] [blame] | 4720 | /* |
| 4721 | * New clock may not be consistent with the previous clock. |
| 4722 | * Reset the buffer so that it doesn't have incomparable timestamps. |
| 4723 | */ |
Alexander Z Lam | 9457158 | 2013-08-02 18:36:16 -0700 | [diff] [blame] | 4724 | tracing_reset_online_cpus(&tr->trace_buffer); |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4725 | |
| 4726 | #ifdef CONFIG_TRACER_MAX_TRACE |
| 4727 | if (tr->flags & TRACE_ARRAY_FL_GLOBAL && tr->max_buffer.buffer) |
| 4728 | ring_buffer_set_clock(tr->max_buffer.buffer, trace_clocks[i].func); |
Alexander Z Lam | 9457158 | 2013-08-02 18:36:16 -0700 | [diff] [blame] | 4729 | tracing_reset_online_cpus(&tr->max_buffer); |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4730 | #endif |
David Sharp | 60303ed | 2012-10-11 16:27:52 -0700 | [diff] [blame] | 4731 | |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 4732 | mutex_unlock(&trace_types_lock); |
| 4733 | |
| 4734 | *fpos += cnt; |
| 4735 | |
| 4736 | return cnt; |
| 4737 | } |
| 4738 | |
Li Zefan | 13f16d2 | 2009-12-08 11:16:11 +0800 | [diff] [blame] | 4739 | static int tracing_clock_open(struct inode *inode, struct file *file) |
| 4740 | { |
Steven Rostedt (Red Hat) | 7b85af6 | 2013-07-01 23:34:22 -0400 | [diff] [blame] | 4741 | struct trace_array *tr = inode->i_private; |
| 4742 | int ret; |
| 4743 | |
Li Zefan | 13f16d2 | 2009-12-08 11:16:11 +0800 | [diff] [blame] | 4744 | if (tracing_disabled) |
| 4745 | return -ENODEV; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4746 | |
Steven Rostedt (Red Hat) | 7b85af6 | 2013-07-01 23:34:22 -0400 | [diff] [blame] | 4747 | if (trace_array_get(tr)) |
| 4748 | return -ENODEV; |
| 4749 | |
| 4750 | ret = single_open(file, tracing_clock_show, inode->i_private); |
| 4751 | if (ret < 0) |
| 4752 | trace_array_put(tr); |
| 4753 | |
| 4754 | return ret; |
Li Zefan | 13f16d2 | 2009-12-08 11:16:11 +0800 | [diff] [blame] | 4755 | } |
| 4756 | |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 4757 | struct ftrace_buffer_info { |
| 4758 | struct trace_iterator iter; |
| 4759 | void *spare; |
| 4760 | unsigned int read; |
| 4761 | }; |
| 4762 | |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4763 | #ifdef CONFIG_TRACER_SNAPSHOT |
| 4764 | static int tracing_snapshot_open(struct inode *inode, struct file *file) |
| 4765 | { |
Oleg Nesterov | 6484c71 | 2013-07-23 17:26:10 +0200 | [diff] [blame] | 4766 | struct trace_array *tr = inode->i_private; |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4767 | struct trace_iterator *iter; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4768 | struct seq_file *m; |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4769 | int ret = 0; |
| 4770 | |
Steven Rostedt (Red Hat) | ff45196 | 2013-07-01 22:50:29 -0400 | [diff] [blame] | 4771 | if (trace_array_get(tr) < 0) |
| 4772 | return -ENODEV; |
| 4773 | |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4774 | if (file->f_mode & FMODE_READ) { |
Oleg Nesterov | 6484c71 | 2013-07-23 17:26:10 +0200 | [diff] [blame] | 4775 | iter = __tracing_open(inode, file, true); |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4776 | if (IS_ERR(iter)) |
| 4777 | ret = PTR_ERR(iter); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4778 | } else { |
| 4779 | /* Writes still need the seq_file to hold the private data */ |
Alexander Z Lam | f77d09a | 2013-07-18 11:18:44 -0700 | [diff] [blame] | 4780 | ret = -ENOMEM; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4781 | m = kzalloc(sizeof(*m), GFP_KERNEL); |
| 4782 | if (!m) |
Alexander Z Lam | f77d09a | 2013-07-18 11:18:44 -0700 | [diff] [blame] | 4783 | goto out; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4784 | iter = kzalloc(sizeof(*iter), GFP_KERNEL); |
| 4785 | if (!iter) { |
| 4786 | kfree(m); |
Alexander Z Lam | f77d09a | 2013-07-18 11:18:44 -0700 | [diff] [blame] | 4787 | goto out; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4788 | } |
Alexander Z Lam | f77d09a | 2013-07-18 11:18:44 -0700 | [diff] [blame] | 4789 | ret = 0; |
| 4790 | |
Steven Rostedt (Red Hat) | ff45196 | 2013-07-01 22:50:29 -0400 | [diff] [blame] | 4791 | iter->tr = tr; |
Oleg Nesterov | 6484c71 | 2013-07-23 17:26:10 +0200 | [diff] [blame] | 4792 | iter->trace_buffer = &tr->max_buffer; |
| 4793 | iter->cpu_file = tracing_get_cpu(inode); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4794 | m->private = iter; |
| 4795 | file->private_data = m; |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4796 | } |
Alexander Z Lam | f77d09a | 2013-07-18 11:18:44 -0700 | [diff] [blame] | 4797 | out: |
Steven Rostedt (Red Hat) | ff45196 | 2013-07-01 22:50:29 -0400 | [diff] [blame] | 4798 | if (ret < 0) |
| 4799 | trace_array_put(tr); |
| 4800 | |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4801 | return ret; |
| 4802 | } |
| 4803 | |
| 4804 | static ssize_t |
| 4805 | tracing_snapshot_write(struct file *filp, const char __user *ubuf, size_t cnt, |
| 4806 | loff_t *ppos) |
| 4807 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4808 | struct seq_file *m = filp->private_data; |
| 4809 | struct trace_iterator *iter = m->private; |
| 4810 | struct trace_array *tr = iter->tr; |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4811 | unsigned long val; |
| 4812 | int ret; |
| 4813 | |
| 4814 | ret = tracing_update_buffers(); |
| 4815 | if (ret < 0) |
| 4816 | return ret; |
| 4817 | |
| 4818 | ret = kstrtoul_from_user(ubuf, cnt, 10, &val); |
| 4819 | if (ret) |
| 4820 | return ret; |
| 4821 | |
| 4822 | mutex_lock(&trace_types_lock); |
| 4823 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4824 | if (tr->current_trace->use_max_tr) { |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4825 | ret = -EBUSY; |
| 4826 | goto out; |
| 4827 | } |
| 4828 | |
| 4829 | switch (val) { |
| 4830 | case 0: |
Steven Rostedt (Red Hat) | f1affca | 2013-03-05 14:35:11 -0500 | [diff] [blame] | 4831 | if (iter->cpu_file != RING_BUFFER_ALL_CPUS) { |
| 4832 | ret = -EINVAL; |
| 4833 | break; |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4834 | } |
Steven Rostedt (Red Hat) | 3209cff | 2013-03-12 11:17:54 -0400 | [diff] [blame] | 4835 | if (tr->allocated_snapshot) |
| 4836 | free_snapshot(tr); |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4837 | break; |
| 4838 | case 1: |
Steven Rostedt (Red Hat) | f1affca | 2013-03-05 14:35:11 -0500 | [diff] [blame] | 4839 | /* Only allow per-cpu swap if the ring buffer supports it */ |
| 4840 | #ifndef CONFIG_RING_BUFFER_ALLOW_SWAP |
| 4841 | if (iter->cpu_file != RING_BUFFER_ALL_CPUS) { |
| 4842 | ret = -EINVAL; |
| 4843 | break; |
| 4844 | } |
| 4845 | #endif |
Steven Rostedt (Red Hat) | 45ad21c | 2013-03-05 18:25:02 -0500 | [diff] [blame] | 4846 | if (!tr->allocated_snapshot) { |
Steven Rostedt (Red Hat) | 3209cff | 2013-03-12 11:17:54 -0400 | [diff] [blame] | 4847 | ret = alloc_snapshot(tr); |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4848 | if (ret < 0) |
| 4849 | break; |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4850 | } |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4851 | local_irq_disable(); |
| 4852 | /* Now, we're going to swap */ |
Steven Rostedt (Red Hat) | f1affca | 2013-03-05 14:35:11 -0500 | [diff] [blame] | 4853 | if (iter->cpu_file == RING_BUFFER_ALL_CPUS) |
Steven Rostedt (Red Hat) | ce9bae5 | 2013-03-05 21:23:55 -0500 | [diff] [blame] | 4854 | update_max_tr(tr, current, smp_processor_id()); |
Steven Rostedt (Red Hat) | f1affca | 2013-03-05 14:35:11 -0500 | [diff] [blame] | 4855 | else |
Steven Rostedt (Red Hat) | ce9bae5 | 2013-03-05 21:23:55 -0500 | [diff] [blame] | 4856 | update_max_tr_single(tr, current, iter->cpu_file); |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4857 | local_irq_enable(); |
| 4858 | break; |
| 4859 | default: |
Steven Rostedt (Red Hat) | 45ad21c | 2013-03-05 18:25:02 -0500 | [diff] [blame] | 4860 | if (tr->allocated_snapshot) { |
Steven Rostedt (Red Hat) | f1affca | 2013-03-05 14:35:11 -0500 | [diff] [blame] | 4861 | if (iter->cpu_file == RING_BUFFER_ALL_CPUS) |
| 4862 | tracing_reset_online_cpus(&tr->max_buffer); |
| 4863 | else |
| 4864 | tracing_reset(&tr->max_buffer, iter->cpu_file); |
| 4865 | } |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4866 | break; |
| 4867 | } |
| 4868 | |
| 4869 | if (ret >= 0) { |
| 4870 | *ppos += cnt; |
| 4871 | ret = cnt; |
| 4872 | } |
| 4873 | out: |
| 4874 | mutex_unlock(&trace_types_lock); |
| 4875 | return ret; |
| 4876 | } |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4877 | |
| 4878 | static int tracing_snapshot_release(struct inode *inode, struct file *file) |
| 4879 | { |
| 4880 | struct seq_file *m = file->private_data; |
Steven Rostedt (Red Hat) | ff45196 | 2013-07-01 22:50:29 -0400 | [diff] [blame] | 4881 | int ret; |
| 4882 | |
| 4883 | ret = tracing_release(inode, file); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4884 | |
| 4885 | if (file->f_mode & FMODE_READ) |
Steven Rostedt (Red Hat) | ff45196 | 2013-07-01 22:50:29 -0400 | [diff] [blame] | 4886 | return ret; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4887 | |
| 4888 | /* If write only, the seq_file is just a stub */ |
| 4889 | if (m) |
| 4890 | kfree(m->private); |
| 4891 | kfree(m); |
| 4892 | |
| 4893 | return 0; |
| 4894 | } |
| 4895 | |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 4896 | static int tracing_buffers_open(struct inode *inode, struct file *filp); |
| 4897 | static ssize_t tracing_buffers_read(struct file *filp, char __user *ubuf, |
| 4898 | size_t count, loff_t *ppos); |
| 4899 | static int tracing_buffers_release(struct inode *inode, struct file *file); |
| 4900 | static ssize_t tracing_buffers_splice_read(struct file *file, loff_t *ppos, |
| 4901 | struct pipe_inode_info *pipe, size_t len, unsigned int flags); |
| 4902 | |
| 4903 | static int snapshot_raw_open(struct inode *inode, struct file *filp) |
| 4904 | { |
| 4905 | struct ftrace_buffer_info *info; |
| 4906 | int ret; |
| 4907 | |
| 4908 | ret = tracing_buffers_open(inode, filp); |
| 4909 | if (ret < 0) |
| 4910 | return ret; |
| 4911 | |
| 4912 | info = filp->private_data; |
| 4913 | |
| 4914 | if (info->iter.trace->use_max_tr) { |
| 4915 | tracing_buffers_release(inode, filp); |
| 4916 | return -EBUSY; |
| 4917 | } |
| 4918 | |
| 4919 | info->iter.snapshot = true; |
| 4920 | info->iter.trace_buffer = &info->iter.tr->max_buffer; |
| 4921 | |
| 4922 | return ret; |
| 4923 | } |
| 4924 | |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4925 | #endif /* CONFIG_TRACER_SNAPSHOT */ |
| 4926 | |
| 4927 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 4928 | static const struct file_operations tracing_max_lat_fops = { |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4929 | .open = tracing_open_generic, |
| 4930 | .read = tracing_max_lat_read, |
| 4931 | .write = tracing_max_lat_write, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 4932 | .llseek = generic_file_llseek, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4933 | }; |
| 4934 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 4935 | static const struct file_operations set_tracer_fops = { |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4936 | .open = tracing_open_generic, |
| 4937 | .read = tracing_set_trace_read, |
| 4938 | .write = tracing_set_trace_write, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 4939 | .llseek = generic_file_llseek, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4940 | }; |
| 4941 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 4942 | static const struct file_operations tracing_pipe_fops = { |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4943 | .open = tracing_open_pipe, |
Soeren Sandmann Pedersen | 2a2cc8f | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 4944 | .poll = tracing_poll_pipe, |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4945 | .read = tracing_read_pipe, |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4946 | .splice_read = tracing_splice_read_pipe, |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4947 | .release = tracing_release_pipe, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 4948 | .llseek = no_llseek, |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4949 | }; |
| 4950 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 4951 | static const struct file_operations tracing_entries_fops = { |
Oleg Nesterov | 0bc392e | 2013-07-23 17:26:06 +0200 | [diff] [blame] | 4952 | .open = tracing_open_generic_tr, |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 4953 | .read = tracing_entries_read, |
| 4954 | .write = tracing_entries_write, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 4955 | .llseek = generic_file_llseek, |
Oleg Nesterov | 0bc392e | 2013-07-23 17:26:06 +0200 | [diff] [blame] | 4956 | .release = tracing_release_generic_tr, |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 4957 | }; |
| 4958 | |
Vaibhav Nagarnaik | f81ab07 | 2011-08-16 14:46:15 -0700 | [diff] [blame] | 4959 | static const struct file_operations tracing_total_entries_fops = { |
Steven Rostedt (Red Hat) | 7b85af6 | 2013-07-01 23:34:22 -0400 | [diff] [blame] | 4960 | .open = tracing_open_generic_tr, |
Vaibhav Nagarnaik | f81ab07 | 2011-08-16 14:46:15 -0700 | [diff] [blame] | 4961 | .read = tracing_total_entries_read, |
| 4962 | .llseek = generic_file_llseek, |
Steven Rostedt (Red Hat) | 7b85af6 | 2013-07-01 23:34:22 -0400 | [diff] [blame] | 4963 | .release = tracing_release_generic_tr, |
Vaibhav Nagarnaik | f81ab07 | 2011-08-16 14:46:15 -0700 | [diff] [blame] | 4964 | }; |
| 4965 | |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 4966 | static const struct file_operations tracing_free_buffer_fops = { |
Steven Rostedt (Red Hat) | 7b85af6 | 2013-07-01 23:34:22 -0400 | [diff] [blame] | 4967 | .open = tracing_open_generic_tr, |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 4968 | .write = tracing_free_buffer_write, |
| 4969 | .release = tracing_free_buffer_release, |
| 4970 | }; |
| 4971 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 4972 | static const struct file_operations tracing_mark_fops = { |
Steven Rostedt (Red Hat) | 7b85af6 | 2013-07-01 23:34:22 -0400 | [diff] [blame] | 4973 | .open = tracing_open_generic_tr, |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 4974 | .write = tracing_mark_write, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 4975 | .llseek = generic_file_llseek, |
Steven Rostedt (Red Hat) | 7b85af6 | 2013-07-01 23:34:22 -0400 | [diff] [blame] | 4976 | .release = tracing_release_generic_tr, |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 4977 | }; |
| 4978 | |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 4979 | static const struct file_operations trace_clock_fops = { |
Li Zefan | 13f16d2 | 2009-12-08 11:16:11 +0800 | [diff] [blame] | 4980 | .open = tracing_clock_open, |
| 4981 | .read = seq_read, |
| 4982 | .llseek = seq_lseek, |
Steven Rostedt (Red Hat) | 7b85af6 | 2013-07-01 23:34:22 -0400 | [diff] [blame] | 4983 | .release = tracing_single_release_tr, |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 4984 | .write = tracing_clock_write, |
| 4985 | }; |
| 4986 | |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4987 | #ifdef CONFIG_TRACER_SNAPSHOT |
| 4988 | static const struct file_operations snapshot_fops = { |
| 4989 | .open = tracing_snapshot_open, |
| 4990 | .read = seq_read, |
| 4991 | .write = tracing_snapshot_write, |
Steven Rostedt (Red Hat) | 098c879 | 2013-12-21 17:39:40 -0500 | [diff] [blame] | 4992 | .llseek = tracing_lseek, |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4993 | .release = tracing_snapshot_release, |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4994 | }; |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4995 | |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 4996 | static const struct file_operations snapshot_raw_fops = { |
| 4997 | .open = snapshot_raw_open, |
| 4998 | .read = tracing_buffers_read, |
| 4999 | .release = tracing_buffers_release, |
| 5000 | .splice_read = tracing_buffers_splice_read, |
| 5001 | .llseek = no_llseek, |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5002 | }; |
| 5003 | |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 5004 | #endif /* CONFIG_TRACER_SNAPSHOT */ |
| 5005 | |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5006 | static int tracing_buffers_open(struct inode *inode, struct file *filp) |
| 5007 | { |
Oleg Nesterov | 46ef2be | 2013-07-23 17:26:00 +0200 | [diff] [blame] | 5008 | struct trace_array *tr = inode->i_private; |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5009 | struct ftrace_buffer_info *info; |
Steven Rostedt (Red Hat) | 7b85af6 | 2013-07-01 23:34:22 -0400 | [diff] [blame] | 5010 | int ret; |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5011 | |
| 5012 | if (tracing_disabled) |
| 5013 | return -ENODEV; |
| 5014 | |
Steven Rostedt (Red Hat) | 7b85af6 | 2013-07-01 23:34:22 -0400 | [diff] [blame] | 5015 | if (trace_array_get(tr) < 0) |
| 5016 | return -ENODEV; |
| 5017 | |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5018 | info = kzalloc(sizeof(*info), GFP_KERNEL); |
Steven Rostedt (Red Hat) | 7b85af6 | 2013-07-01 23:34:22 -0400 | [diff] [blame] | 5019 | if (!info) { |
| 5020 | trace_array_put(tr); |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5021 | return -ENOMEM; |
Steven Rostedt (Red Hat) | 7b85af6 | 2013-07-01 23:34:22 -0400 | [diff] [blame] | 5022 | } |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5023 | |
Steven Rostedt (Red Hat) | a695cb5 | 2013-03-06 15:27:24 -0500 | [diff] [blame] | 5024 | mutex_lock(&trace_types_lock); |
| 5025 | |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 5026 | info->iter.tr = tr; |
Oleg Nesterov | 46ef2be | 2013-07-23 17:26:00 +0200 | [diff] [blame] | 5027 | info->iter.cpu_file = tracing_get_cpu(inode); |
Steven Rostedt | b627344 | 2013-02-28 13:44:11 -0500 | [diff] [blame] | 5028 | info->iter.trace = tr->current_trace; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5029 | info->iter.trace_buffer = &tr->trace_buffer; |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 5030 | info->spare = NULL; |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5031 | /* Force reading ring buffer for first read */ |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 5032 | info->read = (unsigned int)-1; |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5033 | |
| 5034 | filp->private_data = info; |
| 5035 | |
Steven Rostedt (Red Hat) | a695cb5 | 2013-03-06 15:27:24 -0500 | [diff] [blame] | 5036 | mutex_unlock(&trace_types_lock); |
| 5037 | |
Steven Rostedt (Red Hat) | 7b85af6 | 2013-07-01 23:34:22 -0400 | [diff] [blame] | 5038 | ret = nonseekable_open(inode, filp); |
| 5039 | if (ret < 0) |
| 5040 | trace_array_put(tr); |
| 5041 | |
| 5042 | return ret; |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5043 | } |
| 5044 | |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 5045 | static unsigned int |
| 5046 | tracing_buffers_poll(struct file *filp, poll_table *poll_table) |
| 5047 | { |
| 5048 | struct ftrace_buffer_info *info = filp->private_data; |
| 5049 | struct trace_iterator *iter = &info->iter; |
| 5050 | |
| 5051 | return trace_poll(iter, filp, poll_table); |
| 5052 | } |
| 5053 | |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5054 | static ssize_t |
| 5055 | tracing_buffers_read(struct file *filp, char __user *ubuf, |
| 5056 | size_t count, loff_t *ppos) |
| 5057 | { |
| 5058 | struct ftrace_buffer_info *info = filp->private_data; |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 5059 | struct trace_iterator *iter = &info->iter; |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5060 | ssize_t ret; |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 5061 | ssize_t size; |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5062 | |
Steven Rostedt | 2dc5d12 | 2009-03-04 19:10:05 -0500 | [diff] [blame] | 5063 | if (!count) |
| 5064 | return 0; |
| 5065 | |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 5066 | mutex_lock(&trace_types_lock); |
| 5067 | |
| 5068 | #ifdef CONFIG_TRACER_MAX_TRACE |
| 5069 | if (iter->snapshot && iter->tr->current_trace->use_max_tr) { |
| 5070 | size = -EBUSY; |
| 5071 | goto out_unlock; |
| 5072 | } |
| 5073 | #endif |
| 5074 | |
Lai Jiangshan | ddd538f | 2009-04-02 15:16:59 +0800 | [diff] [blame] | 5075 | if (!info->spare) |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5076 | info->spare = ring_buffer_alloc_read_page(iter->trace_buffer->buffer, |
| 5077 | iter->cpu_file); |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 5078 | size = -ENOMEM; |
Lai Jiangshan | ddd538f | 2009-04-02 15:16:59 +0800 | [diff] [blame] | 5079 | if (!info->spare) |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 5080 | goto out_unlock; |
Lai Jiangshan | ddd538f | 2009-04-02 15:16:59 +0800 | [diff] [blame] | 5081 | |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5082 | /* Do we have previous read data to read? */ |
| 5083 | if (info->read < PAGE_SIZE) |
| 5084 | goto read; |
| 5085 | |
Steven Rostedt | b627344 | 2013-02-28 13:44:11 -0500 | [diff] [blame] | 5086 | again: |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 5087 | trace_access_lock(iter->cpu_file); |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5088 | ret = ring_buffer_read_page(iter->trace_buffer->buffer, |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5089 | &info->spare, |
| 5090 | count, |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 5091 | iter->cpu_file, 0); |
| 5092 | trace_access_unlock(iter->cpu_file); |
Steven Rostedt | b627344 | 2013-02-28 13:44:11 -0500 | [diff] [blame] | 5093 | |
| 5094 | if (ret < 0) { |
| 5095 | if (trace_empty(iter)) { |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 5096 | if ((filp->f_flags & O_NONBLOCK)) { |
| 5097 | size = -EAGAIN; |
| 5098 | goto out_unlock; |
| 5099 | } |
| 5100 | mutex_unlock(&trace_types_lock); |
Steven Rostedt | b627344 | 2013-02-28 13:44:11 -0500 | [diff] [blame] | 5101 | iter->trace->wait_pipe(iter); |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 5102 | mutex_lock(&trace_types_lock); |
| 5103 | if (signal_pending(current)) { |
| 5104 | size = -EINTR; |
| 5105 | goto out_unlock; |
| 5106 | } |
Steven Rostedt | b627344 | 2013-02-28 13:44:11 -0500 | [diff] [blame] | 5107 | goto again; |
| 5108 | } |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 5109 | size = 0; |
| 5110 | goto out_unlock; |
Steven Rostedt | b627344 | 2013-02-28 13:44:11 -0500 | [diff] [blame] | 5111 | } |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5112 | |
Steven Rostedt | 436fc28 | 2011-10-14 10:44:25 -0400 | [diff] [blame] | 5113 | info->read = 0; |
Steven Rostedt | b627344 | 2013-02-28 13:44:11 -0500 | [diff] [blame] | 5114 | read: |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5115 | size = PAGE_SIZE - info->read; |
| 5116 | if (size > count) |
| 5117 | size = count; |
| 5118 | |
| 5119 | ret = copy_to_user(ubuf, info->spare + info->read, size); |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 5120 | if (ret == size) { |
| 5121 | size = -EFAULT; |
| 5122 | goto out_unlock; |
| 5123 | } |
Steven Rostedt | 2dc5d12 | 2009-03-04 19:10:05 -0500 | [diff] [blame] | 5124 | size -= ret; |
| 5125 | |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5126 | *ppos += size; |
| 5127 | info->read += size; |
| 5128 | |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 5129 | out_unlock: |
| 5130 | mutex_unlock(&trace_types_lock); |
| 5131 | |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5132 | return size; |
| 5133 | } |
| 5134 | |
| 5135 | static int tracing_buffers_release(struct inode *inode, struct file *file) |
| 5136 | { |
| 5137 | struct ftrace_buffer_info *info = file->private_data; |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 5138 | struct trace_iterator *iter = &info->iter; |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5139 | |
Steven Rostedt (Red Hat) | a695cb5 | 2013-03-06 15:27:24 -0500 | [diff] [blame] | 5140 | mutex_lock(&trace_types_lock); |
| 5141 | |
Steven Rostedt (Red Hat) | ff45196 | 2013-07-01 22:50:29 -0400 | [diff] [blame] | 5142 | __trace_array_put(iter->tr); |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5143 | |
Lai Jiangshan | ddd538f | 2009-04-02 15:16:59 +0800 | [diff] [blame] | 5144 | if (info->spare) |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5145 | ring_buffer_free_read_page(iter->trace_buffer->buffer, info->spare); |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5146 | kfree(info); |
| 5147 | |
Steven Rostedt (Red Hat) | a695cb5 | 2013-03-06 15:27:24 -0500 | [diff] [blame] | 5148 | mutex_unlock(&trace_types_lock); |
| 5149 | |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5150 | return 0; |
| 5151 | } |
| 5152 | |
| 5153 | struct buffer_ref { |
| 5154 | struct ring_buffer *buffer; |
| 5155 | void *page; |
| 5156 | int ref; |
| 5157 | }; |
| 5158 | |
| 5159 | static void buffer_pipe_buf_release(struct pipe_inode_info *pipe, |
| 5160 | struct pipe_buffer *buf) |
| 5161 | { |
| 5162 | struct buffer_ref *ref = (struct buffer_ref *)buf->private; |
| 5163 | |
| 5164 | if (--ref->ref) |
| 5165 | return; |
| 5166 | |
| 5167 | ring_buffer_free_read_page(ref->buffer, ref->page); |
| 5168 | kfree(ref); |
| 5169 | buf->private = 0; |
| 5170 | } |
| 5171 | |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5172 | static void buffer_pipe_buf_get(struct pipe_inode_info *pipe, |
| 5173 | struct pipe_buffer *buf) |
| 5174 | { |
| 5175 | struct buffer_ref *ref = (struct buffer_ref *)buf->private; |
| 5176 | |
| 5177 | ref->ref++; |
| 5178 | } |
| 5179 | |
| 5180 | /* Pipe buffer operations for a buffer. */ |
Alexey Dobriyan | 28dfef8 | 2009-12-15 16:46:48 -0800 | [diff] [blame] | 5181 | static const struct pipe_buf_operations buffer_pipe_buf_ops = { |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5182 | .can_merge = 0, |
| 5183 | .map = generic_pipe_buf_map, |
| 5184 | .unmap = generic_pipe_buf_unmap, |
| 5185 | .confirm = generic_pipe_buf_confirm, |
| 5186 | .release = buffer_pipe_buf_release, |
Masami Hiramatsu | d55cb6c | 2012-08-09 21:31:10 +0900 | [diff] [blame] | 5187 | .steal = generic_pipe_buf_steal, |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5188 | .get = buffer_pipe_buf_get, |
| 5189 | }; |
| 5190 | |
| 5191 | /* |
| 5192 | * Callback from splice_to_pipe(), if we need to release some pages |
| 5193 | * at the end of the spd in case we error'ed out in filling the pipe. |
| 5194 | */ |
| 5195 | static void buffer_spd_release(struct splice_pipe_desc *spd, unsigned int i) |
| 5196 | { |
| 5197 | struct buffer_ref *ref = |
| 5198 | (struct buffer_ref *)spd->partial[i].private; |
| 5199 | |
| 5200 | if (--ref->ref) |
| 5201 | return; |
| 5202 | |
| 5203 | ring_buffer_free_read_page(ref->buffer, ref->page); |
| 5204 | kfree(ref); |
| 5205 | spd->partial[i].private = 0; |
| 5206 | } |
| 5207 | |
| 5208 | static ssize_t |
| 5209 | tracing_buffers_splice_read(struct file *file, loff_t *ppos, |
| 5210 | struct pipe_inode_info *pipe, size_t len, |
| 5211 | unsigned int flags) |
| 5212 | { |
| 5213 | struct ftrace_buffer_info *info = file->private_data; |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 5214 | struct trace_iterator *iter = &info->iter; |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 5215 | struct partial_page partial_def[PIPE_DEF_BUFFERS]; |
| 5216 | struct page *pages_def[PIPE_DEF_BUFFERS]; |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5217 | struct splice_pipe_desc spd = { |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 5218 | .pages = pages_def, |
| 5219 | .partial = partial_def, |
Eric Dumazet | 047fe36 | 2012-06-12 15:24:40 +0200 | [diff] [blame] | 5220 | .nr_pages_max = PIPE_DEF_BUFFERS, |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5221 | .flags = flags, |
| 5222 | .ops = &buffer_pipe_buf_ops, |
| 5223 | .spd_release = buffer_spd_release, |
| 5224 | }; |
| 5225 | struct buffer_ref *ref; |
Steven Rostedt | 93459c6 | 2009-04-29 00:23:13 -0400 | [diff] [blame] | 5226 | int entries, size, i; |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 5227 | ssize_t ret; |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5228 | |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 5229 | mutex_lock(&trace_types_lock); |
| 5230 | |
| 5231 | #ifdef CONFIG_TRACER_MAX_TRACE |
| 5232 | if (iter->snapshot && iter->tr->current_trace->use_max_tr) { |
| 5233 | ret = -EBUSY; |
| 5234 | goto out; |
| 5235 | } |
| 5236 | #endif |
| 5237 | |
| 5238 | if (splice_grow_spd(pipe, &spd)) { |
| 5239 | ret = -ENOMEM; |
| 5240 | goto out; |
| 5241 | } |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 5242 | |
Lai Jiangshan | 93cfb3c | 2009-04-02 15:17:08 +0800 | [diff] [blame] | 5243 | if (*ppos & (PAGE_SIZE - 1)) { |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 5244 | ret = -EINVAL; |
| 5245 | goto out; |
Lai Jiangshan | 93cfb3c | 2009-04-02 15:17:08 +0800 | [diff] [blame] | 5246 | } |
| 5247 | |
| 5248 | if (len & (PAGE_SIZE - 1)) { |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 5249 | if (len < PAGE_SIZE) { |
| 5250 | ret = -EINVAL; |
| 5251 | goto out; |
| 5252 | } |
Lai Jiangshan | 93cfb3c | 2009-04-02 15:17:08 +0800 | [diff] [blame] | 5253 | len &= PAGE_MASK; |
| 5254 | } |
| 5255 | |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 5256 | again: |
| 5257 | trace_access_lock(iter->cpu_file); |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5258 | entries = ring_buffer_entries_cpu(iter->trace_buffer->buffer, iter->cpu_file); |
Steven Rostedt | 93459c6 | 2009-04-29 00:23:13 -0400 | [diff] [blame] | 5259 | |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 5260 | for (i = 0; i < pipe->buffers && len && entries; i++, len -= PAGE_SIZE) { |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5261 | struct page *page; |
| 5262 | int r; |
| 5263 | |
| 5264 | ref = kzalloc(sizeof(*ref), GFP_KERNEL); |
| 5265 | if (!ref) |
| 5266 | break; |
| 5267 | |
Steven Rostedt | 7267fa6 | 2009-04-29 00:16:21 -0400 | [diff] [blame] | 5268 | ref->ref = 1; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5269 | ref->buffer = iter->trace_buffer->buffer; |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 5270 | ref->page = ring_buffer_alloc_read_page(ref->buffer, iter->cpu_file); |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5271 | if (!ref->page) { |
| 5272 | kfree(ref); |
| 5273 | break; |
| 5274 | } |
| 5275 | |
| 5276 | r = ring_buffer_read_page(ref->buffer, &ref->page, |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 5277 | len, iter->cpu_file, 1); |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5278 | if (r < 0) { |
Vaibhav Nagarnaik | 7ea5906 | 2011-05-03 17:56:42 -0700 | [diff] [blame] | 5279 | ring_buffer_free_read_page(ref->buffer, ref->page); |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5280 | kfree(ref); |
| 5281 | break; |
| 5282 | } |
| 5283 | |
| 5284 | /* |
| 5285 | * zero out any left over data, this is going to |
| 5286 | * user land. |
| 5287 | */ |
| 5288 | size = ring_buffer_page_len(ref->page); |
| 5289 | if (size < PAGE_SIZE) |
| 5290 | memset(ref->page + size, 0, PAGE_SIZE - size); |
| 5291 | |
| 5292 | page = virt_to_page(ref->page); |
| 5293 | |
| 5294 | spd.pages[i] = page; |
| 5295 | spd.partial[i].len = PAGE_SIZE; |
| 5296 | spd.partial[i].offset = 0; |
| 5297 | spd.partial[i].private = (unsigned long)ref; |
| 5298 | spd.nr_pages++; |
Lai Jiangshan | 93cfb3c | 2009-04-02 15:17:08 +0800 | [diff] [blame] | 5299 | *ppos += PAGE_SIZE; |
Steven Rostedt | 93459c6 | 2009-04-29 00:23:13 -0400 | [diff] [blame] | 5300 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5301 | entries = ring_buffer_entries_cpu(iter->trace_buffer->buffer, iter->cpu_file); |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5302 | } |
| 5303 | |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 5304 | trace_access_unlock(iter->cpu_file); |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5305 | spd.nr_pages = i; |
| 5306 | |
| 5307 | /* did we read anything? */ |
| 5308 | if (!spd.nr_pages) { |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 5309 | if ((file->f_flags & O_NONBLOCK) || (flags & SPLICE_F_NONBLOCK)) { |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5310 | ret = -EAGAIN; |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 5311 | goto out; |
| 5312 | } |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 5313 | mutex_unlock(&trace_types_lock); |
Steven Rostedt | b627344 | 2013-02-28 13:44:11 -0500 | [diff] [blame] | 5314 | iter->trace->wait_pipe(iter); |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 5315 | mutex_lock(&trace_types_lock); |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 5316 | if (signal_pending(current)) { |
| 5317 | ret = -EINTR; |
| 5318 | goto out; |
| 5319 | } |
| 5320 | goto again; |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5321 | } |
| 5322 | |
| 5323 | ret = splice_to_pipe(pipe, &spd); |
Eric Dumazet | 047fe36 | 2012-06-12 15:24:40 +0200 | [diff] [blame] | 5324 | splice_shrink_spd(&spd); |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 5325 | out: |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 5326 | mutex_unlock(&trace_types_lock); |
| 5327 | |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5328 | return ret; |
| 5329 | } |
| 5330 | |
| 5331 | static const struct file_operations tracing_buffers_fops = { |
| 5332 | .open = tracing_buffers_open, |
| 5333 | .read = tracing_buffers_read, |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 5334 | .poll = tracing_buffers_poll, |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5335 | .release = tracing_buffers_release, |
| 5336 | .splice_read = tracing_buffers_splice_read, |
| 5337 | .llseek = no_llseek, |
| 5338 | }; |
| 5339 | |
Steven Rostedt | c8d7718 | 2009-04-29 18:03:45 -0400 | [diff] [blame] | 5340 | static ssize_t |
| 5341 | tracing_stats_read(struct file *filp, char __user *ubuf, |
| 5342 | size_t count, loff_t *ppos) |
| 5343 | { |
Oleg Nesterov | 4d3435b | 2013-07-23 17:26:03 +0200 | [diff] [blame] | 5344 | struct inode *inode = file_inode(filp); |
| 5345 | struct trace_array *tr = inode->i_private; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5346 | struct trace_buffer *trace_buf = &tr->trace_buffer; |
Oleg Nesterov | 4d3435b | 2013-07-23 17:26:03 +0200 | [diff] [blame] | 5347 | int cpu = tracing_get_cpu(inode); |
Steven Rostedt | c8d7718 | 2009-04-29 18:03:45 -0400 | [diff] [blame] | 5348 | struct trace_seq *s; |
| 5349 | unsigned long cnt; |
Vaibhav Nagarnaik | c64e148 | 2011-08-16 14:46:16 -0700 | [diff] [blame] | 5350 | unsigned long long t; |
| 5351 | unsigned long usec_rem; |
Steven Rostedt | c8d7718 | 2009-04-29 18:03:45 -0400 | [diff] [blame] | 5352 | |
Li Zefan | e4f2d10 | 2009-06-15 10:57:28 +0800 | [diff] [blame] | 5353 | s = kmalloc(sizeof(*s), GFP_KERNEL); |
Steven Rostedt | c8d7718 | 2009-04-29 18:03:45 -0400 | [diff] [blame] | 5354 | if (!s) |
Roel Kluin | a646365 | 2009-11-11 22:26:35 +0100 | [diff] [blame] | 5355 | return -ENOMEM; |
Steven Rostedt | c8d7718 | 2009-04-29 18:03:45 -0400 | [diff] [blame] | 5356 | |
| 5357 | trace_seq_init(s); |
| 5358 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5359 | cnt = ring_buffer_entries_cpu(trace_buf->buffer, cpu); |
Steven Rostedt | c8d7718 | 2009-04-29 18:03:45 -0400 | [diff] [blame] | 5360 | trace_seq_printf(s, "entries: %ld\n", cnt); |
| 5361 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5362 | cnt = ring_buffer_overrun_cpu(trace_buf->buffer, cpu); |
Steven Rostedt | c8d7718 | 2009-04-29 18:03:45 -0400 | [diff] [blame] | 5363 | trace_seq_printf(s, "overrun: %ld\n", cnt); |
| 5364 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5365 | cnt = ring_buffer_commit_overrun_cpu(trace_buf->buffer, cpu); |
Steven Rostedt | c8d7718 | 2009-04-29 18:03:45 -0400 | [diff] [blame] | 5366 | trace_seq_printf(s, "commit overrun: %ld\n", cnt); |
| 5367 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5368 | cnt = ring_buffer_bytes_cpu(trace_buf->buffer, cpu); |
Vaibhav Nagarnaik | c64e148 | 2011-08-16 14:46:16 -0700 | [diff] [blame] | 5369 | trace_seq_printf(s, "bytes: %ld\n", cnt); |
| 5370 | |
Yoshihiro YUNOMAE | 58e8eed | 2013-04-23 10:32:39 +0900 | [diff] [blame] | 5371 | if (trace_clocks[tr->clock_id].in_ns) { |
Yoshihiro YUNOMAE | 11043d8b | 2012-11-13 12:18:23 -0800 | [diff] [blame] | 5372 | /* local or global for trace_clock */ |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5373 | t = ns2usecs(ring_buffer_oldest_event_ts(trace_buf->buffer, cpu)); |
Yoshihiro YUNOMAE | 11043d8b | 2012-11-13 12:18:23 -0800 | [diff] [blame] | 5374 | usec_rem = do_div(t, USEC_PER_SEC); |
| 5375 | trace_seq_printf(s, "oldest event ts: %5llu.%06lu\n", |
| 5376 | t, usec_rem); |
Vaibhav Nagarnaik | c64e148 | 2011-08-16 14:46:16 -0700 | [diff] [blame] | 5377 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5378 | t = ns2usecs(ring_buffer_time_stamp(trace_buf->buffer, cpu)); |
Yoshihiro YUNOMAE | 11043d8b | 2012-11-13 12:18:23 -0800 | [diff] [blame] | 5379 | usec_rem = do_div(t, USEC_PER_SEC); |
| 5380 | trace_seq_printf(s, "now ts: %5llu.%06lu\n", t, usec_rem); |
| 5381 | } else { |
| 5382 | /* counter or tsc mode for trace_clock */ |
| 5383 | trace_seq_printf(s, "oldest event ts: %llu\n", |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5384 | ring_buffer_oldest_event_ts(trace_buf->buffer, cpu)); |
Yoshihiro YUNOMAE | 11043d8b | 2012-11-13 12:18:23 -0800 | [diff] [blame] | 5385 | |
| 5386 | trace_seq_printf(s, "now ts: %llu\n", |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5387 | ring_buffer_time_stamp(trace_buf->buffer, cpu)); |
Yoshihiro YUNOMAE | 11043d8b | 2012-11-13 12:18:23 -0800 | [diff] [blame] | 5388 | } |
Vaibhav Nagarnaik | c64e148 | 2011-08-16 14:46:16 -0700 | [diff] [blame] | 5389 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5390 | cnt = ring_buffer_dropped_events_cpu(trace_buf->buffer, cpu); |
Slava Pestov | 884bfe8 | 2011-07-15 14:23:58 -0700 | [diff] [blame] | 5391 | trace_seq_printf(s, "dropped events: %ld\n", cnt); |
| 5392 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5393 | cnt = ring_buffer_read_events_cpu(trace_buf->buffer, cpu); |
Steven Rostedt (Red Hat) | ad96470 | 2013-01-29 17:45:49 -0500 | [diff] [blame] | 5394 | trace_seq_printf(s, "read events: %ld\n", cnt); |
| 5395 | |
Steven Rostedt | c8d7718 | 2009-04-29 18:03:45 -0400 | [diff] [blame] | 5396 | count = simple_read_from_buffer(ubuf, count, ppos, s->buffer, s->len); |
| 5397 | |
| 5398 | kfree(s); |
| 5399 | |
| 5400 | return count; |
| 5401 | } |
| 5402 | |
| 5403 | static const struct file_operations tracing_stats_fops = { |
Oleg Nesterov | 4d3435b | 2013-07-23 17:26:03 +0200 | [diff] [blame] | 5404 | .open = tracing_open_generic_tr, |
Steven Rostedt | c8d7718 | 2009-04-29 18:03:45 -0400 | [diff] [blame] | 5405 | .read = tracing_stats_read, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 5406 | .llseek = generic_file_llseek, |
Oleg Nesterov | 4d3435b | 2013-07-23 17:26:03 +0200 | [diff] [blame] | 5407 | .release = tracing_release_generic_tr, |
Steven Rostedt | c8d7718 | 2009-04-29 18:03:45 -0400 | [diff] [blame] | 5408 | }; |
| 5409 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5410 | #ifdef CONFIG_DYNAMIC_FTRACE |
| 5411 | |
Steven Rostedt | b807c3d | 2008-10-30 16:08:33 -0400 | [diff] [blame] | 5412 | int __weak ftrace_arch_read_dyn_info(char *buf, int size) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5413 | { |
Steven Rostedt | b807c3d | 2008-10-30 16:08:33 -0400 | [diff] [blame] | 5414 | return 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5415 | } |
| 5416 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5417 | static ssize_t |
Steven Rostedt | b807c3d | 2008-10-30 16:08:33 -0400 | [diff] [blame] | 5418 | tracing_read_dyn_info(struct file *filp, char __user *ubuf, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5419 | size_t cnt, loff_t *ppos) |
| 5420 | { |
Steven Rostedt | a26a2a2 | 2008-10-31 00:03:22 -0400 | [diff] [blame] | 5421 | static char ftrace_dyn_info_buffer[1024]; |
| 5422 | static DEFINE_MUTEX(dyn_info_mutex); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5423 | unsigned long *p = filp->private_data; |
Steven Rostedt | b807c3d | 2008-10-30 16:08:33 -0400 | [diff] [blame] | 5424 | char *buf = ftrace_dyn_info_buffer; |
Steven Rostedt | a26a2a2 | 2008-10-31 00:03:22 -0400 | [diff] [blame] | 5425 | int size = ARRAY_SIZE(ftrace_dyn_info_buffer); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5426 | int r; |
| 5427 | |
Steven Rostedt | b807c3d | 2008-10-30 16:08:33 -0400 | [diff] [blame] | 5428 | mutex_lock(&dyn_info_mutex); |
| 5429 | r = sprintf(buf, "%ld ", *p); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5430 | |
Steven Rostedt | a26a2a2 | 2008-10-31 00:03:22 -0400 | [diff] [blame] | 5431 | r += ftrace_arch_read_dyn_info(buf+r, (size-1)-r); |
Steven Rostedt | b807c3d | 2008-10-30 16:08:33 -0400 | [diff] [blame] | 5432 | buf[r++] = '\n'; |
| 5433 | |
| 5434 | r = simple_read_from_buffer(ubuf, cnt, ppos, buf, r); |
| 5435 | |
| 5436 | mutex_unlock(&dyn_info_mutex); |
| 5437 | |
| 5438 | return r; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5439 | } |
| 5440 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 5441 | static const struct file_operations tracing_dyn_info_fops = { |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 5442 | .open = tracing_open_generic, |
Steven Rostedt | b807c3d | 2008-10-30 16:08:33 -0400 | [diff] [blame] | 5443 | .read = tracing_read_dyn_info, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 5444 | .llseek = generic_file_llseek, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5445 | }; |
Steven Rostedt (Red Hat) | 77fd5c1 | 2013-03-12 11:49:18 -0400 | [diff] [blame] | 5446 | #endif /* CONFIG_DYNAMIC_FTRACE */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5447 | |
Steven Rostedt (Red Hat) | 77fd5c1 | 2013-03-12 11:49:18 -0400 | [diff] [blame] | 5448 | #if defined(CONFIG_TRACER_SNAPSHOT) && defined(CONFIG_DYNAMIC_FTRACE) |
| 5449 | static void |
| 5450 | ftrace_snapshot(unsigned long ip, unsigned long parent_ip, void **data) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5451 | { |
Steven Rostedt (Red Hat) | 77fd5c1 | 2013-03-12 11:49:18 -0400 | [diff] [blame] | 5452 | tracing_snapshot(); |
| 5453 | } |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5454 | |
Steven Rostedt (Red Hat) | 77fd5c1 | 2013-03-12 11:49:18 -0400 | [diff] [blame] | 5455 | static void |
| 5456 | ftrace_count_snapshot(unsigned long ip, unsigned long parent_ip, void **data) |
| 5457 | { |
| 5458 | unsigned long *count = (long *)data; |
| 5459 | |
| 5460 | if (!*count) |
| 5461 | return; |
| 5462 | |
| 5463 | if (*count != -1) |
| 5464 | (*count)--; |
| 5465 | |
| 5466 | tracing_snapshot(); |
| 5467 | } |
| 5468 | |
| 5469 | static int |
| 5470 | ftrace_snapshot_print(struct seq_file *m, unsigned long ip, |
| 5471 | struct ftrace_probe_ops *ops, void *data) |
| 5472 | { |
| 5473 | long count = (long)data; |
| 5474 | |
| 5475 | seq_printf(m, "%ps:", (void *)ip); |
| 5476 | |
| 5477 | seq_printf(m, "snapshot"); |
| 5478 | |
| 5479 | if (count == -1) |
| 5480 | seq_printf(m, ":unlimited\n"); |
| 5481 | else |
| 5482 | seq_printf(m, ":count=%ld\n", count); |
| 5483 | |
| 5484 | return 0; |
| 5485 | } |
| 5486 | |
| 5487 | static struct ftrace_probe_ops snapshot_probe_ops = { |
| 5488 | .func = ftrace_snapshot, |
| 5489 | .print = ftrace_snapshot_print, |
| 5490 | }; |
| 5491 | |
| 5492 | static struct ftrace_probe_ops snapshot_count_probe_ops = { |
| 5493 | .func = ftrace_count_snapshot, |
| 5494 | .print = ftrace_snapshot_print, |
| 5495 | }; |
| 5496 | |
| 5497 | static int |
| 5498 | ftrace_trace_snapshot_callback(struct ftrace_hash *hash, |
| 5499 | char *glob, char *cmd, char *param, int enable) |
| 5500 | { |
| 5501 | struct ftrace_probe_ops *ops; |
| 5502 | void *count = (void *)-1; |
| 5503 | char *number; |
| 5504 | int ret; |
| 5505 | |
| 5506 | /* hash funcs only work with set_ftrace_filter */ |
| 5507 | if (!enable) |
| 5508 | return -EINVAL; |
| 5509 | |
| 5510 | ops = param ? &snapshot_count_probe_ops : &snapshot_probe_ops; |
| 5511 | |
| 5512 | if (glob[0] == '!') { |
| 5513 | unregister_ftrace_function_probe_func(glob+1, ops); |
| 5514 | return 0; |
| 5515 | } |
| 5516 | |
| 5517 | if (!param) |
| 5518 | goto out_reg; |
| 5519 | |
| 5520 | number = strsep(¶m, ":"); |
| 5521 | |
| 5522 | if (!strlen(number)) |
| 5523 | goto out_reg; |
| 5524 | |
| 5525 | /* |
| 5526 | * We use the callback data field (which is a pointer) |
| 5527 | * as our counter. |
| 5528 | */ |
| 5529 | ret = kstrtoul(number, 0, (unsigned long *)&count); |
| 5530 | if (ret) |
| 5531 | return ret; |
| 5532 | |
| 5533 | out_reg: |
| 5534 | ret = register_ftrace_function_probe(glob, ops, count); |
| 5535 | |
| 5536 | if (ret >= 0) |
| 5537 | alloc_snapshot(&global_trace); |
| 5538 | |
| 5539 | return ret < 0 ? ret : 0; |
| 5540 | } |
| 5541 | |
| 5542 | static struct ftrace_func_command ftrace_snapshot_cmd = { |
| 5543 | .name = "snapshot", |
| 5544 | .func = ftrace_trace_snapshot_callback, |
| 5545 | }; |
| 5546 | |
Tom Zanussi | 38de93a | 2013-10-24 08:34:18 -0500 | [diff] [blame] | 5547 | static __init int register_snapshot_cmd(void) |
Steven Rostedt (Red Hat) | 77fd5c1 | 2013-03-12 11:49:18 -0400 | [diff] [blame] | 5548 | { |
| 5549 | return register_ftrace_command(&ftrace_snapshot_cmd); |
| 5550 | } |
| 5551 | #else |
Tom Zanussi | 38de93a | 2013-10-24 08:34:18 -0500 | [diff] [blame] | 5552 | static inline __init int register_snapshot_cmd(void) { return 0; } |
Steven Rostedt (Red Hat) | 77fd5c1 | 2013-03-12 11:49:18 -0400 | [diff] [blame] | 5553 | #endif /* defined(CONFIG_TRACER_SNAPSHOT) && defined(CONFIG_DYNAMIC_FTRACE) */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5554 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5555 | struct dentry *tracing_init_dentry_tr(struct trace_array *tr) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5556 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5557 | if (tr->dir) |
| 5558 | return tr->dir; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5559 | |
Frederic Weisbecker | 3e1f60b | 2009-03-22 23:10:45 +0100 | [diff] [blame] | 5560 | if (!debugfs_initialized()) |
| 5561 | return NULL; |
| 5562 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5563 | if (tr->flags & TRACE_ARRAY_FL_GLOBAL) |
| 5564 | tr->dir = debugfs_create_dir("tracing", NULL); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5565 | |
zhangwei(Jovi) | 687c878 | 2013-03-11 15:13:29 +0800 | [diff] [blame] | 5566 | if (!tr->dir) |
| 5567 | pr_warn_once("Could not create debugfs directory 'tracing'\n"); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5568 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5569 | return tr->dir; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5570 | } |
| 5571 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5572 | struct dentry *tracing_init_dentry(void) |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 5573 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5574 | return tracing_init_dentry_tr(&global_trace); |
| 5575 | } |
| 5576 | |
| 5577 | static struct dentry *tracing_dentry_percpu(struct trace_array *tr, int cpu) |
| 5578 | { |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 5579 | struct dentry *d_tracer; |
| 5580 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5581 | if (tr->percpu_dir) |
| 5582 | return tr->percpu_dir; |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 5583 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5584 | d_tracer = tracing_init_dentry_tr(tr); |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 5585 | if (!d_tracer) |
| 5586 | return NULL; |
| 5587 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5588 | tr->percpu_dir = debugfs_create_dir("per_cpu", d_tracer); |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 5589 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5590 | WARN_ONCE(!tr->percpu_dir, |
| 5591 | "Could not create debugfs directory 'per_cpu/%d'\n", cpu); |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 5592 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5593 | return tr->percpu_dir; |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 5594 | } |
| 5595 | |
Oleg Nesterov | 649e9c70 | 2013-07-23 17:25:54 +0200 | [diff] [blame] | 5596 | static struct dentry * |
| 5597 | trace_create_cpu_file(const char *name, umode_t mode, struct dentry *parent, |
| 5598 | void *data, long cpu, const struct file_operations *fops) |
| 5599 | { |
| 5600 | struct dentry *ret = trace_create_file(name, mode, parent, data, fops); |
| 5601 | |
| 5602 | if (ret) /* See tracing_get_cpu() */ |
| 5603 | ret->d_inode->i_cdev = (void *)(cpu + 1); |
| 5604 | return ret; |
| 5605 | } |
| 5606 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5607 | static void |
| 5608 | tracing_init_debugfs_percpu(struct trace_array *tr, long cpu) |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 5609 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5610 | struct dentry *d_percpu = tracing_dentry_percpu(tr, cpu); |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 5611 | struct dentry *d_cpu; |
Steven Rostedt | dd49a38 | 2010-10-20 21:51:26 -0400 | [diff] [blame] | 5612 | char cpu_dir[30]; /* 30 characters should be more than enough */ |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 5613 | |
Namhyung Kim | 0a3d7ce | 2012-04-23 10:11:57 +0900 | [diff] [blame] | 5614 | if (!d_percpu) |
| 5615 | return; |
| 5616 | |
Steven Rostedt | dd49a38 | 2010-10-20 21:51:26 -0400 | [diff] [blame] | 5617 | snprintf(cpu_dir, 30, "cpu%ld", cpu); |
Frederic Weisbecker | 8656e7a | 2009-02-26 00:41:38 +0100 | [diff] [blame] | 5618 | d_cpu = debugfs_create_dir(cpu_dir, d_percpu); |
| 5619 | if (!d_cpu) { |
| 5620 | pr_warning("Could not create debugfs '%s' entry\n", cpu_dir); |
| 5621 | return; |
| 5622 | } |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 5623 | |
Frederic Weisbecker | 8656e7a | 2009-02-26 00:41:38 +0100 | [diff] [blame] | 5624 | /* per cpu trace_pipe */ |
Oleg Nesterov | 649e9c70 | 2013-07-23 17:25:54 +0200 | [diff] [blame] | 5625 | trace_create_cpu_file("trace_pipe", 0444, d_cpu, |
Oleg Nesterov | 1554420 | 2013-07-23 17:25:57 +0200 | [diff] [blame] | 5626 | tr, cpu, &tracing_pipe_fops); |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 5627 | |
| 5628 | /* per cpu trace */ |
Oleg Nesterov | 649e9c70 | 2013-07-23 17:25:54 +0200 | [diff] [blame] | 5629 | trace_create_cpu_file("trace", 0644, d_cpu, |
Oleg Nesterov | 6484c71 | 2013-07-23 17:26:10 +0200 | [diff] [blame] | 5630 | tr, cpu, &tracing_fops); |
Steven Rostedt | 7f96f93 | 2009-03-13 00:37:42 -0400 | [diff] [blame] | 5631 | |
Oleg Nesterov | 649e9c70 | 2013-07-23 17:25:54 +0200 | [diff] [blame] | 5632 | trace_create_cpu_file("trace_pipe_raw", 0444, d_cpu, |
Oleg Nesterov | 46ef2be | 2013-07-23 17:26:00 +0200 | [diff] [blame] | 5633 | tr, cpu, &tracing_buffers_fops); |
Steven Rostedt | c8d7718 | 2009-04-29 18:03:45 -0400 | [diff] [blame] | 5634 | |
Oleg Nesterov | 649e9c70 | 2013-07-23 17:25:54 +0200 | [diff] [blame] | 5635 | trace_create_cpu_file("stats", 0444, d_cpu, |
Oleg Nesterov | 4d3435b | 2013-07-23 17:26:03 +0200 | [diff] [blame] | 5636 | tr, cpu, &tracing_stats_fops); |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 5637 | |
Oleg Nesterov | 649e9c70 | 2013-07-23 17:25:54 +0200 | [diff] [blame] | 5638 | trace_create_cpu_file("buffer_size_kb", 0444, d_cpu, |
Oleg Nesterov | 0bc392e | 2013-07-23 17:26:06 +0200 | [diff] [blame] | 5639 | tr, cpu, &tracing_entries_fops); |
Steven Rostedt (Red Hat) | f1affca | 2013-03-05 14:35:11 -0500 | [diff] [blame] | 5640 | |
| 5641 | #ifdef CONFIG_TRACER_SNAPSHOT |
Oleg Nesterov | 649e9c70 | 2013-07-23 17:25:54 +0200 | [diff] [blame] | 5642 | trace_create_cpu_file("snapshot", 0644, d_cpu, |
Oleg Nesterov | 6484c71 | 2013-07-23 17:26:10 +0200 | [diff] [blame] | 5643 | tr, cpu, &snapshot_fops); |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 5644 | |
Oleg Nesterov | 649e9c70 | 2013-07-23 17:25:54 +0200 | [diff] [blame] | 5645 | trace_create_cpu_file("snapshot_raw", 0444, d_cpu, |
Oleg Nesterov | 46ef2be | 2013-07-23 17:26:00 +0200 | [diff] [blame] | 5646 | tr, cpu, &snapshot_raw_fops); |
Steven Rostedt (Red Hat) | f1affca | 2013-03-05 14:35:11 -0500 | [diff] [blame] | 5647 | #endif |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 5648 | } |
| 5649 | |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 5650 | #ifdef CONFIG_FTRACE_SELFTEST |
| 5651 | /* Let selftest have access to static functions in this file */ |
| 5652 | #include "trace_selftest.c" |
| 5653 | #endif |
| 5654 | |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 5655 | struct trace_option_dentry { |
| 5656 | struct tracer_opt *opt; |
| 5657 | struct tracer_flags *flags; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5658 | struct trace_array *tr; |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 5659 | struct dentry *entry; |
| 5660 | }; |
| 5661 | |
| 5662 | static ssize_t |
| 5663 | trace_options_read(struct file *filp, char __user *ubuf, size_t cnt, |
| 5664 | loff_t *ppos) |
| 5665 | { |
| 5666 | struct trace_option_dentry *topt = filp->private_data; |
| 5667 | char *buf; |
| 5668 | |
| 5669 | if (topt->flags->val & topt->opt->bit) |
| 5670 | buf = "1\n"; |
| 5671 | else |
| 5672 | buf = "0\n"; |
| 5673 | |
| 5674 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, 2); |
| 5675 | } |
| 5676 | |
| 5677 | static ssize_t |
| 5678 | trace_options_write(struct file *filp, const char __user *ubuf, size_t cnt, |
| 5679 | loff_t *ppos) |
| 5680 | { |
| 5681 | struct trace_option_dentry *topt = filp->private_data; |
| 5682 | unsigned long val; |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 5683 | int ret; |
| 5684 | |
Peter Huewe | 22fe9b5 | 2011-06-07 21:58:27 +0200 | [diff] [blame] | 5685 | ret = kstrtoul_from_user(ubuf, cnt, 10, &val); |
| 5686 | if (ret) |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 5687 | return ret; |
| 5688 | |
Li Zefan | 8d18eaa | 2009-12-08 11:17:06 +0800 | [diff] [blame] | 5689 | if (val != 0 && val != 1) |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 5690 | return -EINVAL; |
Li Zefan | 8d18eaa | 2009-12-08 11:17:06 +0800 | [diff] [blame] | 5691 | |
| 5692 | if (!!(topt->flags->val & topt->opt->bit) != val) { |
| 5693 | mutex_lock(&trace_types_lock); |
Steven Rostedt (Red Hat) | 8c1a49a | 2014-01-10 11:13:54 -0500 | [diff] [blame^] | 5694 | ret = __set_tracer_option(topt->tr, topt->flags, |
Steven Rostedt | c757bea | 2009-12-21 22:35:16 -0500 | [diff] [blame] | 5695 | topt->opt, !val); |
Li Zefan | 8d18eaa | 2009-12-08 11:17:06 +0800 | [diff] [blame] | 5696 | mutex_unlock(&trace_types_lock); |
| 5697 | if (ret) |
| 5698 | return ret; |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 5699 | } |
| 5700 | |
| 5701 | *ppos += cnt; |
| 5702 | |
| 5703 | return cnt; |
| 5704 | } |
| 5705 | |
| 5706 | |
| 5707 | static const struct file_operations trace_options_fops = { |
| 5708 | .open = tracing_open_generic, |
| 5709 | .read = trace_options_read, |
| 5710 | .write = trace_options_write, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 5711 | .llseek = generic_file_llseek, |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 5712 | }; |
| 5713 | |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5714 | static ssize_t |
| 5715 | trace_options_core_read(struct file *filp, char __user *ubuf, size_t cnt, |
| 5716 | loff_t *ppos) |
| 5717 | { |
| 5718 | long index = (long)filp->private_data; |
| 5719 | char *buf; |
| 5720 | |
| 5721 | if (trace_flags & (1 << index)) |
| 5722 | buf = "1\n"; |
| 5723 | else |
| 5724 | buf = "0\n"; |
| 5725 | |
| 5726 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, 2); |
| 5727 | } |
| 5728 | |
| 5729 | static ssize_t |
| 5730 | trace_options_core_write(struct file *filp, const char __user *ubuf, size_t cnt, |
| 5731 | loff_t *ppos) |
| 5732 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5733 | struct trace_array *tr = &global_trace; |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5734 | long index = (long)filp->private_data; |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5735 | unsigned long val; |
| 5736 | int ret; |
| 5737 | |
Peter Huewe | 22fe9b5 | 2011-06-07 21:58:27 +0200 | [diff] [blame] | 5738 | ret = kstrtoul_from_user(ubuf, cnt, 10, &val); |
| 5739 | if (ret) |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5740 | return ret; |
| 5741 | |
Zhaolei | f2d84b6 | 2009-08-07 18:55:48 +0800 | [diff] [blame] | 5742 | if (val != 0 && val != 1) |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5743 | return -EINVAL; |
Steven Rostedt (Red Hat) | 69d34da | 2013-03-14 13:50:56 -0400 | [diff] [blame] | 5744 | |
| 5745 | mutex_lock(&trace_types_lock); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5746 | ret = set_tracer_flag(tr, 1 << index, val); |
Steven Rostedt (Red Hat) | 69d34da | 2013-03-14 13:50:56 -0400 | [diff] [blame] | 5747 | mutex_unlock(&trace_types_lock); |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5748 | |
Steven Rostedt (Red Hat) | 613f04a | 2013-03-14 15:03:53 -0400 | [diff] [blame] | 5749 | if (ret < 0) |
| 5750 | return ret; |
| 5751 | |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5752 | *ppos += cnt; |
| 5753 | |
| 5754 | return cnt; |
| 5755 | } |
| 5756 | |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5757 | static const struct file_operations trace_options_core_fops = { |
| 5758 | .open = tracing_open_generic, |
| 5759 | .read = trace_options_core_read, |
| 5760 | .write = trace_options_core_write, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 5761 | .llseek = generic_file_llseek, |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5762 | }; |
| 5763 | |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 5764 | struct dentry *trace_create_file(const char *name, |
Al Viro | f4ae40a6 | 2011-07-24 04:33:43 -0400 | [diff] [blame] | 5765 | umode_t mode, |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 5766 | struct dentry *parent, |
| 5767 | void *data, |
| 5768 | const struct file_operations *fops) |
| 5769 | { |
| 5770 | struct dentry *ret; |
| 5771 | |
| 5772 | ret = debugfs_create_file(name, mode, parent, data, fops); |
| 5773 | if (!ret) |
| 5774 | pr_warning("Could not create debugfs '%s' entry\n", name); |
| 5775 | |
| 5776 | return ret; |
| 5777 | } |
| 5778 | |
| 5779 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5780 | static struct dentry *trace_options_init_dentry(struct trace_array *tr) |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5781 | { |
| 5782 | struct dentry *d_tracer; |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5783 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5784 | if (tr->options) |
| 5785 | return tr->options; |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5786 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5787 | d_tracer = tracing_init_dentry_tr(tr); |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5788 | if (!d_tracer) |
| 5789 | return NULL; |
| 5790 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5791 | tr->options = debugfs_create_dir("options", d_tracer); |
| 5792 | if (!tr->options) { |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5793 | pr_warning("Could not create debugfs directory 'options'\n"); |
| 5794 | return NULL; |
| 5795 | } |
| 5796 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5797 | return tr->options; |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5798 | } |
| 5799 | |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 5800 | static void |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5801 | create_trace_option_file(struct trace_array *tr, |
| 5802 | struct trace_option_dentry *topt, |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 5803 | struct tracer_flags *flags, |
| 5804 | struct tracer_opt *opt) |
| 5805 | { |
| 5806 | struct dentry *t_options; |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 5807 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5808 | t_options = trace_options_init_dentry(tr); |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 5809 | if (!t_options) |
| 5810 | return; |
| 5811 | |
| 5812 | topt->flags = flags; |
| 5813 | topt->opt = opt; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5814 | topt->tr = tr; |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 5815 | |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 5816 | topt->entry = trace_create_file(opt->name, 0644, t_options, topt, |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 5817 | &trace_options_fops); |
| 5818 | |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 5819 | } |
| 5820 | |
| 5821 | static struct trace_option_dentry * |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5822 | create_trace_option_files(struct trace_array *tr, struct tracer *tracer) |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 5823 | { |
| 5824 | struct trace_option_dentry *topts; |
| 5825 | struct tracer_flags *flags; |
| 5826 | struct tracer_opt *opts; |
| 5827 | int cnt; |
| 5828 | |
| 5829 | if (!tracer) |
| 5830 | return NULL; |
| 5831 | |
| 5832 | flags = tracer->flags; |
| 5833 | |
| 5834 | if (!flags || !flags->opts) |
| 5835 | return NULL; |
| 5836 | |
| 5837 | opts = flags->opts; |
| 5838 | |
| 5839 | for (cnt = 0; opts[cnt].name; cnt++) |
| 5840 | ; |
| 5841 | |
Steven Rostedt | 0cfe824 | 2009-02-27 10:51:10 -0500 | [diff] [blame] | 5842 | topts = kcalloc(cnt + 1, sizeof(*topts), GFP_KERNEL); |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 5843 | if (!topts) |
| 5844 | return NULL; |
| 5845 | |
| 5846 | for (cnt = 0; opts[cnt].name; cnt++) |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5847 | create_trace_option_file(tr, &topts[cnt], flags, |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 5848 | &opts[cnt]); |
| 5849 | |
| 5850 | return topts; |
| 5851 | } |
| 5852 | |
| 5853 | static void |
| 5854 | destroy_trace_option_files(struct trace_option_dentry *topts) |
| 5855 | { |
| 5856 | int cnt; |
| 5857 | |
| 5858 | if (!topts) |
| 5859 | return; |
| 5860 | |
| 5861 | for (cnt = 0; topts[cnt].opt; cnt++) { |
| 5862 | if (topts[cnt].entry) |
| 5863 | debugfs_remove(topts[cnt].entry); |
| 5864 | } |
| 5865 | |
| 5866 | kfree(topts); |
| 5867 | } |
| 5868 | |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5869 | static struct dentry * |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5870 | create_trace_option_core_file(struct trace_array *tr, |
| 5871 | const char *option, long index) |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5872 | { |
| 5873 | struct dentry *t_options; |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5874 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5875 | t_options = trace_options_init_dentry(tr); |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5876 | if (!t_options) |
| 5877 | return NULL; |
| 5878 | |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 5879 | return trace_create_file(option, 0644, t_options, (void *)index, |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5880 | &trace_options_core_fops); |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5881 | } |
| 5882 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5883 | static __init void create_trace_options_dir(struct trace_array *tr) |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5884 | { |
| 5885 | struct dentry *t_options; |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5886 | int i; |
| 5887 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5888 | t_options = trace_options_init_dentry(tr); |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5889 | if (!t_options) |
| 5890 | return; |
| 5891 | |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 5892 | for (i = 0; trace_options[i]; i++) |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5893 | create_trace_option_core_file(tr, trace_options[i], i); |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5894 | } |
| 5895 | |
Steven Rostedt | 499e547 | 2012-02-22 15:50:28 -0500 | [diff] [blame] | 5896 | static ssize_t |
| 5897 | rb_simple_read(struct file *filp, char __user *ubuf, |
| 5898 | size_t cnt, loff_t *ppos) |
| 5899 | { |
Steven Rostedt | 348f0fc | 2012-04-16 15:41:28 -0400 | [diff] [blame] | 5900 | struct trace_array *tr = filp->private_data; |
Steven Rostedt | 499e547 | 2012-02-22 15:50:28 -0500 | [diff] [blame] | 5901 | char buf[64]; |
| 5902 | int r; |
| 5903 | |
Steven Rostedt (Red Hat) | 10246fa | 2013-07-01 15:58:24 -0400 | [diff] [blame] | 5904 | r = tracer_tracing_is_on(tr); |
Steven Rostedt | 499e547 | 2012-02-22 15:50:28 -0500 | [diff] [blame] | 5905 | r = sprintf(buf, "%d\n", r); |
| 5906 | |
| 5907 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, r); |
| 5908 | } |
| 5909 | |
| 5910 | static ssize_t |
| 5911 | rb_simple_write(struct file *filp, const char __user *ubuf, |
| 5912 | size_t cnt, loff_t *ppos) |
| 5913 | { |
Steven Rostedt | 348f0fc | 2012-04-16 15:41:28 -0400 | [diff] [blame] | 5914 | struct trace_array *tr = filp->private_data; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5915 | struct ring_buffer *buffer = tr->trace_buffer.buffer; |
Steven Rostedt | 499e547 | 2012-02-22 15:50:28 -0500 | [diff] [blame] | 5916 | unsigned long val; |
| 5917 | int ret; |
| 5918 | |
| 5919 | ret = kstrtoul_from_user(ubuf, cnt, 10, &val); |
| 5920 | if (ret) |
| 5921 | return ret; |
| 5922 | |
| 5923 | if (buffer) { |
Steven Rostedt | 2df8f8a | 2013-01-11 16:14:10 -0500 | [diff] [blame] | 5924 | mutex_lock(&trace_types_lock); |
| 5925 | if (val) { |
Steven Rostedt (Red Hat) | 10246fa | 2013-07-01 15:58:24 -0400 | [diff] [blame] | 5926 | tracer_tracing_on(tr); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5927 | if (tr->current_trace->start) |
| 5928 | tr->current_trace->start(tr); |
Steven Rostedt | 2df8f8a | 2013-01-11 16:14:10 -0500 | [diff] [blame] | 5929 | } else { |
Steven Rostedt (Red Hat) | 10246fa | 2013-07-01 15:58:24 -0400 | [diff] [blame] | 5930 | tracer_tracing_off(tr); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5931 | if (tr->current_trace->stop) |
| 5932 | tr->current_trace->stop(tr); |
Steven Rostedt | 2df8f8a | 2013-01-11 16:14:10 -0500 | [diff] [blame] | 5933 | } |
| 5934 | mutex_unlock(&trace_types_lock); |
Steven Rostedt | 499e547 | 2012-02-22 15:50:28 -0500 | [diff] [blame] | 5935 | } |
| 5936 | |
| 5937 | (*ppos)++; |
| 5938 | |
| 5939 | return cnt; |
| 5940 | } |
| 5941 | |
| 5942 | static const struct file_operations rb_simple_fops = { |
Steven Rostedt (Red Hat) | 7b85af6 | 2013-07-01 23:34:22 -0400 | [diff] [blame] | 5943 | .open = tracing_open_generic_tr, |
Steven Rostedt | 499e547 | 2012-02-22 15:50:28 -0500 | [diff] [blame] | 5944 | .read = rb_simple_read, |
| 5945 | .write = rb_simple_write, |
Steven Rostedt (Red Hat) | 7b85af6 | 2013-07-01 23:34:22 -0400 | [diff] [blame] | 5946 | .release = tracing_release_generic_tr, |
Steven Rostedt | 499e547 | 2012-02-22 15:50:28 -0500 | [diff] [blame] | 5947 | .llseek = default_llseek, |
| 5948 | }; |
| 5949 | |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 5950 | struct dentry *trace_instance_dir; |
| 5951 | |
| 5952 | static void |
| 5953 | init_tracer_debugfs(struct trace_array *tr, struct dentry *d_tracer); |
| 5954 | |
Steven Rostedt (Red Hat) | 55034cd | 2013-03-07 22:48:09 -0500 | [diff] [blame] | 5955 | static int |
| 5956 | allocate_trace_buffer(struct trace_array *tr, struct trace_buffer *buf, int size) |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 5957 | { |
| 5958 | enum ring_buffer_flags rb_flags; |
Steven Rostedt (Red Hat) | 737223f | 2013-03-05 21:13:47 -0500 | [diff] [blame] | 5959 | |
| 5960 | rb_flags = trace_flags & TRACE_ITER_OVERWRITE ? RB_FL_OVERWRITE : 0; |
| 5961 | |
Steven Rostedt (Red Hat) | dced341 | 2014-01-14 10:19:46 -0500 | [diff] [blame] | 5962 | buf->tr = tr; |
| 5963 | |
Steven Rostedt (Red Hat) | 55034cd | 2013-03-07 22:48:09 -0500 | [diff] [blame] | 5964 | buf->buffer = ring_buffer_alloc(size, rb_flags); |
| 5965 | if (!buf->buffer) |
| 5966 | return -ENOMEM; |
Steven Rostedt (Red Hat) | 737223f | 2013-03-05 21:13:47 -0500 | [diff] [blame] | 5967 | |
Steven Rostedt (Red Hat) | 55034cd | 2013-03-07 22:48:09 -0500 | [diff] [blame] | 5968 | buf->data = alloc_percpu(struct trace_array_cpu); |
| 5969 | if (!buf->data) { |
| 5970 | ring_buffer_free(buf->buffer); |
| 5971 | return -ENOMEM; |
| 5972 | } |
Steven Rostedt (Red Hat) | 737223f | 2013-03-05 21:13:47 -0500 | [diff] [blame] | 5973 | |
Steven Rostedt (Red Hat) | 737223f | 2013-03-05 21:13:47 -0500 | [diff] [blame] | 5974 | /* Allocate the first page for all buffers */ |
| 5975 | set_buffer_entries(&tr->trace_buffer, |
| 5976 | ring_buffer_size(tr->trace_buffer.buffer, 0)); |
| 5977 | |
Steven Rostedt (Red Hat) | 55034cd | 2013-03-07 22:48:09 -0500 | [diff] [blame] | 5978 | return 0; |
| 5979 | } |
| 5980 | |
| 5981 | static int allocate_trace_buffers(struct trace_array *tr, int size) |
| 5982 | { |
| 5983 | int ret; |
| 5984 | |
| 5985 | ret = allocate_trace_buffer(tr, &tr->trace_buffer, size); |
| 5986 | if (ret) |
| 5987 | return ret; |
| 5988 | |
Steven Rostedt (Red Hat) | 737223f | 2013-03-05 21:13:47 -0500 | [diff] [blame] | 5989 | #ifdef CONFIG_TRACER_MAX_TRACE |
Steven Rostedt (Red Hat) | 55034cd | 2013-03-07 22:48:09 -0500 | [diff] [blame] | 5990 | ret = allocate_trace_buffer(tr, &tr->max_buffer, |
| 5991 | allocate_snapshot ? size : 1); |
| 5992 | if (WARN_ON(ret)) { |
| 5993 | ring_buffer_free(tr->trace_buffer.buffer); |
| 5994 | free_percpu(tr->trace_buffer.data); |
| 5995 | return -ENOMEM; |
| 5996 | } |
| 5997 | tr->allocated_snapshot = allocate_snapshot; |
Steven Rostedt (Red Hat) | 737223f | 2013-03-05 21:13:47 -0500 | [diff] [blame] | 5998 | |
Steven Rostedt (Red Hat) | 55034cd | 2013-03-07 22:48:09 -0500 | [diff] [blame] | 5999 | /* |
| 6000 | * Only the top level trace array gets its snapshot allocated |
| 6001 | * from the kernel command line. |
| 6002 | */ |
| 6003 | allocate_snapshot = false; |
Steven Rostedt (Red Hat) | 737223f | 2013-03-05 21:13:47 -0500 | [diff] [blame] | 6004 | #endif |
| 6005 | return 0; |
Steven Rostedt (Red Hat) | 737223f | 2013-03-05 21:13:47 -0500 | [diff] [blame] | 6006 | } |
| 6007 | |
| 6008 | static int new_instance_create(const char *name) |
| 6009 | { |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 6010 | struct trace_array *tr; |
| 6011 | int ret; |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 6012 | |
| 6013 | mutex_lock(&trace_types_lock); |
| 6014 | |
| 6015 | ret = -EEXIST; |
| 6016 | list_for_each_entry(tr, &ftrace_trace_arrays, list) { |
| 6017 | if (tr->name && strcmp(tr->name, name) == 0) |
| 6018 | goto out_unlock; |
| 6019 | } |
| 6020 | |
| 6021 | ret = -ENOMEM; |
| 6022 | tr = kzalloc(sizeof(*tr), GFP_KERNEL); |
| 6023 | if (!tr) |
| 6024 | goto out_unlock; |
| 6025 | |
| 6026 | tr->name = kstrdup(name, GFP_KERNEL); |
| 6027 | if (!tr->name) |
| 6028 | goto out_free_tr; |
| 6029 | |
Alexander Z Lam | ccfe9e4 | 2013-08-08 09:47:45 -0700 | [diff] [blame] | 6030 | if (!alloc_cpumask_var(&tr->tracing_cpumask, GFP_KERNEL)) |
| 6031 | goto out_free_tr; |
| 6032 | |
| 6033 | cpumask_copy(tr->tracing_cpumask, cpu_all_mask); |
| 6034 | |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 6035 | raw_spin_lock_init(&tr->start_lock); |
| 6036 | |
| 6037 | tr->current_trace = &nop_trace; |
| 6038 | |
| 6039 | INIT_LIST_HEAD(&tr->systems); |
| 6040 | INIT_LIST_HEAD(&tr->events); |
| 6041 | |
Steven Rostedt (Red Hat) | 737223f | 2013-03-05 21:13:47 -0500 | [diff] [blame] | 6042 | if (allocate_trace_buffers(tr, trace_buf_size) < 0) |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 6043 | goto out_free_tr; |
| 6044 | |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 6045 | tr->dir = debugfs_create_dir(name, trace_instance_dir); |
| 6046 | if (!tr->dir) |
| 6047 | goto out_free_tr; |
| 6048 | |
| 6049 | ret = event_trace_add_tracer(tr->dir, tr); |
Alexander Z Lam | 609e85a | 2013-07-10 17:34:34 -0700 | [diff] [blame] | 6050 | if (ret) { |
| 6051 | debugfs_remove_recursive(tr->dir); |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 6052 | goto out_free_tr; |
Alexander Z Lam | 609e85a | 2013-07-10 17:34:34 -0700 | [diff] [blame] | 6053 | } |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 6054 | |
| 6055 | init_tracer_debugfs(tr, tr->dir); |
| 6056 | |
| 6057 | list_add(&tr->list, &ftrace_trace_arrays); |
| 6058 | |
| 6059 | mutex_unlock(&trace_types_lock); |
| 6060 | |
| 6061 | return 0; |
| 6062 | |
| 6063 | out_free_tr: |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 6064 | if (tr->trace_buffer.buffer) |
| 6065 | ring_buffer_free(tr->trace_buffer.buffer); |
Alexander Z Lam | ccfe9e4 | 2013-08-08 09:47:45 -0700 | [diff] [blame] | 6066 | free_cpumask_var(tr->tracing_cpumask); |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 6067 | kfree(tr->name); |
| 6068 | kfree(tr); |
| 6069 | |
| 6070 | out_unlock: |
| 6071 | mutex_unlock(&trace_types_lock); |
| 6072 | |
| 6073 | return ret; |
| 6074 | |
| 6075 | } |
| 6076 | |
Steven Rostedt | 0c8916c | 2012-08-07 16:14:16 -0400 | [diff] [blame] | 6077 | static int instance_delete(const char *name) |
| 6078 | { |
| 6079 | struct trace_array *tr; |
| 6080 | int found = 0; |
| 6081 | int ret; |
| 6082 | |
| 6083 | mutex_lock(&trace_types_lock); |
| 6084 | |
| 6085 | ret = -ENODEV; |
| 6086 | list_for_each_entry(tr, &ftrace_trace_arrays, list) { |
| 6087 | if (tr->name && strcmp(tr->name, name) == 0) { |
| 6088 | found = 1; |
| 6089 | break; |
| 6090 | } |
| 6091 | } |
| 6092 | if (!found) |
| 6093 | goto out_unlock; |
| 6094 | |
Steven Rostedt (Red Hat) | a695cb5 | 2013-03-06 15:27:24 -0500 | [diff] [blame] | 6095 | ret = -EBUSY; |
| 6096 | if (tr->ref) |
| 6097 | goto out_unlock; |
| 6098 | |
Steven Rostedt | 0c8916c | 2012-08-07 16:14:16 -0400 | [diff] [blame] | 6099 | list_del(&tr->list); |
| 6100 | |
| 6101 | event_trace_del_tracer(tr); |
| 6102 | debugfs_remove_recursive(tr->dir); |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 6103 | free_percpu(tr->trace_buffer.data); |
| 6104 | ring_buffer_free(tr->trace_buffer.buffer); |
Steven Rostedt | 0c8916c | 2012-08-07 16:14:16 -0400 | [diff] [blame] | 6105 | |
| 6106 | kfree(tr->name); |
| 6107 | kfree(tr); |
| 6108 | |
| 6109 | ret = 0; |
| 6110 | |
| 6111 | out_unlock: |
| 6112 | mutex_unlock(&trace_types_lock); |
| 6113 | |
| 6114 | return ret; |
| 6115 | } |
| 6116 | |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 6117 | static int instance_mkdir (struct inode *inode, struct dentry *dentry, umode_t mode) |
| 6118 | { |
| 6119 | struct dentry *parent; |
| 6120 | int ret; |
| 6121 | |
| 6122 | /* Paranoid: Make sure the parent is the "instances" directory */ |
| 6123 | parent = hlist_entry(inode->i_dentry.first, struct dentry, d_alias); |
| 6124 | if (WARN_ON_ONCE(parent != trace_instance_dir)) |
| 6125 | return -ENOENT; |
| 6126 | |
| 6127 | /* |
| 6128 | * The inode mutex is locked, but debugfs_create_dir() will also |
| 6129 | * take the mutex. As the instances directory can not be destroyed |
| 6130 | * or changed in any other way, it is safe to unlock it, and |
| 6131 | * let the dentry try. If two users try to make the same dir at |
| 6132 | * the same time, then the new_instance_create() will determine the |
| 6133 | * winner. |
| 6134 | */ |
| 6135 | mutex_unlock(&inode->i_mutex); |
| 6136 | |
| 6137 | ret = new_instance_create(dentry->d_iname); |
| 6138 | |
| 6139 | mutex_lock(&inode->i_mutex); |
| 6140 | |
| 6141 | return ret; |
| 6142 | } |
| 6143 | |
Steven Rostedt | 0c8916c | 2012-08-07 16:14:16 -0400 | [diff] [blame] | 6144 | static int instance_rmdir(struct inode *inode, struct dentry *dentry) |
| 6145 | { |
| 6146 | struct dentry *parent; |
| 6147 | int ret; |
| 6148 | |
| 6149 | /* Paranoid: Make sure the parent is the "instances" directory */ |
| 6150 | parent = hlist_entry(inode->i_dentry.first, struct dentry, d_alias); |
| 6151 | if (WARN_ON_ONCE(parent != trace_instance_dir)) |
| 6152 | return -ENOENT; |
| 6153 | |
| 6154 | /* The caller did a dget() on dentry */ |
| 6155 | mutex_unlock(&dentry->d_inode->i_mutex); |
| 6156 | |
| 6157 | /* |
| 6158 | * The inode mutex is locked, but debugfs_create_dir() will also |
| 6159 | * take the mutex. As the instances directory can not be destroyed |
| 6160 | * or changed in any other way, it is safe to unlock it, and |
| 6161 | * let the dentry try. If two users try to make the same dir at |
| 6162 | * the same time, then the instance_delete() will determine the |
| 6163 | * winner. |
| 6164 | */ |
| 6165 | mutex_unlock(&inode->i_mutex); |
| 6166 | |
| 6167 | ret = instance_delete(dentry->d_iname); |
| 6168 | |
| 6169 | mutex_lock_nested(&inode->i_mutex, I_MUTEX_PARENT); |
| 6170 | mutex_lock(&dentry->d_inode->i_mutex); |
| 6171 | |
| 6172 | return ret; |
| 6173 | } |
| 6174 | |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 6175 | static const struct inode_operations instance_dir_inode_operations = { |
| 6176 | .lookup = simple_lookup, |
| 6177 | .mkdir = instance_mkdir, |
Steven Rostedt | 0c8916c | 2012-08-07 16:14:16 -0400 | [diff] [blame] | 6178 | .rmdir = instance_rmdir, |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 6179 | }; |
| 6180 | |
| 6181 | static __init void create_trace_instances(struct dentry *d_tracer) |
| 6182 | { |
| 6183 | trace_instance_dir = debugfs_create_dir("instances", d_tracer); |
| 6184 | if (WARN_ON(!trace_instance_dir)) |
| 6185 | return; |
| 6186 | |
| 6187 | /* Hijack the dir inode operations, to allow mkdir */ |
| 6188 | trace_instance_dir->d_inode->i_op = &instance_dir_inode_operations; |
| 6189 | } |
| 6190 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6191 | static void |
| 6192 | init_tracer_debugfs(struct trace_array *tr, struct dentry *d_tracer) |
| 6193 | { |
Steven Rostedt (Red Hat) | 121aaee | 2013-03-05 21:52:25 -0500 | [diff] [blame] | 6194 | int cpu; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6195 | |
Alexander Z Lam | ccfe9e4 | 2013-08-08 09:47:45 -0700 | [diff] [blame] | 6196 | trace_create_file("tracing_cpumask", 0644, d_tracer, |
| 6197 | tr, &tracing_cpumask_fops); |
| 6198 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6199 | trace_create_file("trace_options", 0644, d_tracer, |
| 6200 | tr, &tracing_iter_fops); |
| 6201 | |
| 6202 | trace_create_file("trace", 0644, d_tracer, |
Oleg Nesterov | 6484c71 | 2013-07-23 17:26:10 +0200 | [diff] [blame] | 6203 | tr, &tracing_fops); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6204 | |
| 6205 | trace_create_file("trace_pipe", 0444, d_tracer, |
Oleg Nesterov | 1554420 | 2013-07-23 17:25:57 +0200 | [diff] [blame] | 6206 | tr, &tracing_pipe_fops); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6207 | |
| 6208 | trace_create_file("buffer_size_kb", 0644, d_tracer, |
Oleg Nesterov | 0bc392e | 2013-07-23 17:26:06 +0200 | [diff] [blame] | 6209 | tr, &tracing_entries_fops); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6210 | |
| 6211 | trace_create_file("buffer_total_size_kb", 0444, d_tracer, |
| 6212 | tr, &tracing_total_entries_fops); |
| 6213 | |
Wang YanQing | 238ae93 | 2013-05-26 16:52:01 +0800 | [diff] [blame] | 6214 | trace_create_file("free_buffer", 0200, d_tracer, |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6215 | tr, &tracing_free_buffer_fops); |
| 6216 | |
| 6217 | trace_create_file("trace_marker", 0220, d_tracer, |
| 6218 | tr, &tracing_mark_fops); |
| 6219 | |
| 6220 | trace_create_file("trace_clock", 0644, d_tracer, tr, |
| 6221 | &trace_clock_fops); |
| 6222 | |
| 6223 | trace_create_file("tracing_on", 0644, d_tracer, |
Oleg Nesterov | 6484c71 | 2013-07-23 17:26:10 +0200 | [diff] [blame] | 6224 | tr, &rb_simple_fops); |
Steven Rostedt (Red Hat) | ce9bae5 | 2013-03-05 21:23:55 -0500 | [diff] [blame] | 6225 | |
| 6226 | #ifdef CONFIG_TRACER_SNAPSHOT |
| 6227 | trace_create_file("snapshot", 0644, d_tracer, |
Oleg Nesterov | 6484c71 | 2013-07-23 17:26:10 +0200 | [diff] [blame] | 6228 | tr, &snapshot_fops); |
Steven Rostedt (Red Hat) | ce9bae5 | 2013-03-05 21:23:55 -0500 | [diff] [blame] | 6229 | #endif |
Steven Rostedt (Red Hat) | 121aaee | 2013-03-05 21:52:25 -0500 | [diff] [blame] | 6230 | |
| 6231 | for_each_tracing_cpu(cpu) |
| 6232 | tracing_init_debugfs_percpu(tr, cpu); |
| 6233 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6234 | } |
| 6235 | |
Frédéric Weisbecker | b5ad384 | 2008-09-23 11:34:32 +0100 | [diff] [blame] | 6236 | static __init int tracer_init_debugfs(void) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 6237 | { |
| 6238 | struct dentry *d_tracer; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 6239 | |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 6240 | trace_access_lock_init(); |
| 6241 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 6242 | d_tracer = tracing_init_dentry(); |
Namhyung Kim | ed6f1c9 | 2013-04-10 09:18:12 +0900 | [diff] [blame] | 6243 | if (!d_tracer) |
| 6244 | return 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 6245 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6246 | init_tracer_debugfs(&global_trace, d_tracer); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 6247 | |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 6248 | trace_create_file("available_tracers", 0444, d_tracer, |
| 6249 | &global_trace, &show_traces_fops); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 6250 | |
Li Zefan | 339ae5d | 2009-04-17 10:34:30 +0800 | [diff] [blame] | 6251 | trace_create_file("current_tracer", 0644, d_tracer, |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 6252 | &global_trace, &set_tracer_fops); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 6253 | |
Steven Rostedt | 5d4a9db | 2009-08-27 16:52:21 -0400 | [diff] [blame] | 6254 | #ifdef CONFIG_TRACER_MAX_TRACE |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 6255 | trace_create_file("tracing_max_latency", 0644, d_tracer, |
| 6256 | &tracing_max_latency, &tracing_max_lat_fops); |
Tim Bird | 0e95017 | 2010-02-25 15:36:43 -0800 | [diff] [blame] | 6257 | #endif |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 6258 | |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 6259 | trace_create_file("tracing_thresh", 0644, d_tracer, |
| 6260 | &tracing_thresh, &tracing_max_lat_fops); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 6261 | |
Li Zefan | 339ae5d | 2009-04-17 10:34:30 +0800 | [diff] [blame] | 6262 | trace_create_file("README", 0444, d_tracer, |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 6263 | NULL, &tracing_readme_fops); |
Ingo Molnar | 7bd2f24 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 6264 | |
Avadh Patel | 69abe6a | 2009-04-10 16:04:48 -0400 | [diff] [blame] | 6265 | trace_create_file("saved_cmdlines", 0444, d_tracer, |
| 6266 | NULL, &tracing_saved_cmdlines_fops); |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 6267 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 6268 | #ifdef CONFIG_DYNAMIC_FTRACE |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 6269 | trace_create_file("dyn_ftrace_total_info", 0444, d_tracer, |
| 6270 | &ftrace_update_tot_cnt, &tracing_dyn_info_fops); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 6271 | #endif |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 6272 | |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 6273 | create_trace_instances(d_tracer); |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 6274 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6275 | create_trace_options_dir(&global_trace); |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 6276 | |
Frédéric Weisbecker | b5ad384 | 2008-09-23 11:34:32 +0100 | [diff] [blame] | 6277 | return 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 6278 | } |
| 6279 | |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 6280 | static int trace_panic_handler(struct notifier_block *this, |
| 6281 | unsigned long event, void *unused) |
| 6282 | { |
Steven Rostedt | 944ac42 | 2008-10-23 19:26:08 -0400 | [diff] [blame] | 6283 | if (ftrace_dump_on_oops) |
Frederic Weisbecker | cecbca9 | 2010-04-18 19:08:41 +0200 | [diff] [blame] | 6284 | ftrace_dump(ftrace_dump_on_oops); |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 6285 | return NOTIFY_OK; |
| 6286 | } |
| 6287 | |
| 6288 | static struct notifier_block trace_panic_notifier = { |
| 6289 | .notifier_call = trace_panic_handler, |
| 6290 | .next = NULL, |
| 6291 | .priority = 150 /* priority: INT_MAX >= x >= 0 */ |
| 6292 | }; |
| 6293 | |
| 6294 | static int trace_die_handler(struct notifier_block *self, |
| 6295 | unsigned long val, |
| 6296 | void *data) |
| 6297 | { |
| 6298 | switch (val) { |
| 6299 | case DIE_OOPS: |
Steven Rostedt | 944ac42 | 2008-10-23 19:26:08 -0400 | [diff] [blame] | 6300 | if (ftrace_dump_on_oops) |
Frederic Weisbecker | cecbca9 | 2010-04-18 19:08:41 +0200 | [diff] [blame] | 6301 | ftrace_dump(ftrace_dump_on_oops); |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 6302 | break; |
| 6303 | default: |
| 6304 | break; |
| 6305 | } |
| 6306 | return NOTIFY_OK; |
| 6307 | } |
| 6308 | |
| 6309 | static struct notifier_block trace_die_notifier = { |
| 6310 | .notifier_call = trace_die_handler, |
| 6311 | .priority = 200 |
| 6312 | }; |
| 6313 | |
| 6314 | /* |
| 6315 | * printk is set to max of 1024, we really don't need it that big. |
| 6316 | * Nothing should be printing 1000 characters anyway. |
| 6317 | */ |
| 6318 | #define TRACE_MAX_PRINT 1000 |
| 6319 | |
| 6320 | /* |
| 6321 | * Define here KERN_TRACE so that we have one place to modify |
| 6322 | * it if we decide to change what log level the ftrace dump |
| 6323 | * should be at. |
| 6324 | */ |
Steven Rostedt | 428aee1 | 2009-01-14 12:24:42 -0500 | [diff] [blame] | 6325 | #define KERN_TRACE KERN_EMERG |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 6326 | |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 6327 | void |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 6328 | trace_printk_seq(struct trace_seq *s) |
| 6329 | { |
| 6330 | /* Probably should print a warning here. */ |
zhangwei(Jovi) | bd6df18 | 2013-03-11 15:13:37 +0800 | [diff] [blame] | 6331 | if (s->len >= TRACE_MAX_PRINT) |
| 6332 | s->len = TRACE_MAX_PRINT; |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 6333 | |
| 6334 | /* should be zero ended, but we are paranoid. */ |
| 6335 | s->buffer[s->len] = 0; |
| 6336 | |
| 6337 | printk(KERN_TRACE "%s", s->buffer); |
| 6338 | |
Steven Rostedt | f952075 | 2009-03-02 14:04:40 -0500 | [diff] [blame] | 6339 | trace_seq_init(s); |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 6340 | } |
| 6341 | |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 6342 | void trace_init_global_iter(struct trace_iterator *iter) |
| 6343 | { |
| 6344 | iter->tr = &global_trace; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6345 | iter->trace = iter->tr->current_trace; |
Steven Rostedt | ae3b509 | 2013-01-23 15:22:59 -0500 | [diff] [blame] | 6346 | iter->cpu_file = RING_BUFFER_ALL_CPUS; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 6347 | iter->trace_buffer = &global_trace.trace_buffer; |
Cody P Schafer | b2f974d | 2013-10-23 11:49:57 -0700 | [diff] [blame] | 6348 | |
| 6349 | if (iter->trace && iter->trace->open) |
| 6350 | iter->trace->open(iter); |
| 6351 | |
| 6352 | /* Annotate start of buffers if we had overruns */ |
| 6353 | if (ring_buffer_overruns(iter->trace_buffer->buffer)) |
| 6354 | iter->iter_flags |= TRACE_FILE_ANNOTATE; |
| 6355 | |
| 6356 | /* Output in nanoseconds only if we are using a clock in nanoseconds. */ |
| 6357 | if (trace_clocks[iter->tr->clock_id].in_ns) |
| 6358 | iter->iter_flags |= TRACE_FILE_TIME_IN_NS; |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 6359 | } |
| 6360 | |
Steven Rostedt (Red Hat) | 7fe70b5 | 2013-03-15 13:10:35 -0400 | [diff] [blame] | 6361 | void ftrace_dump(enum ftrace_dump_mode oops_dump_mode) |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 6362 | { |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 6363 | /* use static because iter can be a bit big for the stack */ |
| 6364 | static struct trace_iterator iter; |
Steven Rostedt (Red Hat) | 7fe70b5 | 2013-03-15 13:10:35 -0400 | [diff] [blame] | 6365 | static atomic_t dump_running; |
Frederic Weisbecker | cf586b6 | 2009-03-22 05:04:35 +0100 | [diff] [blame] | 6366 | unsigned int old_userobj; |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 6367 | unsigned long flags; |
| 6368 | int cnt = 0, cpu; |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 6369 | |
Steven Rostedt (Red Hat) | 7fe70b5 | 2013-03-15 13:10:35 -0400 | [diff] [blame] | 6370 | /* Only allow one dump user at a time. */ |
| 6371 | if (atomic_inc_return(&dump_running) != 1) { |
| 6372 | atomic_dec(&dump_running); |
| 6373 | return; |
Steven Rostedt | e0a413f | 2011-09-29 21:26:16 -0400 | [diff] [blame] | 6374 | } |
| 6375 | |
Steven Rostedt (Red Hat) | 7fe70b5 | 2013-03-15 13:10:35 -0400 | [diff] [blame] | 6376 | /* |
| 6377 | * Always turn off tracing when we dump. |
| 6378 | * We don't need to show trace output of what happens |
| 6379 | * between multiple crashes. |
| 6380 | * |
| 6381 | * If the user does a sysrq-z, then they can re-enable |
| 6382 | * tracing with echo 1 > tracing_on. |
| 6383 | */ |
| 6384 | tracing_off(); |
| 6385 | |
| 6386 | local_irq_save(flags); |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 6387 | |
Jovi Zhang | 38dbe0b | 2013-01-25 18:03:07 +0800 | [diff] [blame] | 6388 | /* Simulate the iterator */ |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 6389 | trace_init_global_iter(&iter); |
| 6390 | |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 6391 | for_each_tracing_cpu(cpu) { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 6392 | atomic_inc(&per_cpu_ptr(iter.tr->trace_buffer.data, cpu)->disabled); |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 6393 | } |
| 6394 | |
Frederic Weisbecker | cf586b6 | 2009-03-22 05:04:35 +0100 | [diff] [blame] | 6395 | old_userobj = trace_flags & TRACE_ITER_SYM_USEROBJ; |
| 6396 | |
Török Edwin | b54d3de | 2008-11-22 13:28:48 +0200 | [diff] [blame] | 6397 | /* don't look at user memory in panic mode */ |
| 6398 | trace_flags &= ~TRACE_ITER_SYM_USEROBJ; |
| 6399 | |
Frederic Weisbecker | cecbca9 | 2010-04-18 19:08:41 +0200 | [diff] [blame] | 6400 | switch (oops_dump_mode) { |
| 6401 | case DUMP_ALL: |
Steven Rostedt | ae3b509 | 2013-01-23 15:22:59 -0500 | [diff] [blame] | 6402 | iter.cpu_file = RING_BUFFER_ALL_CPUS; |
Frederic Weisbecker | cecbca9 | 2010-04-18 19:08:41 +0200 | [diff] [blame] | 6403 | break; |
| 6404 | case DUMP_ORIG: |
| 6405 | iter.cpu_file = raw_smp_processor_id(); |
| 6406 | break; |
| 6407 | case DUMP_NONE: |
| 6408 | goto out_enable; |
| 6409 | default: |
| 6410 | printk(KERN_TRACE "Bad dumping mode, switching to all CPUs dump\n"); |
Steven Rostedt | ae3b509 | 2013-01-23 15:22:59 -0500 | [diff] [blame] | 6411 | iter.cpu_file = RING_BUFFER_ALL_CPUS; |
Frederic Weisbecker | cecbca9 | 2010-04-18 19:08:41 +0200 | [diff] [blame] | 6412 | } |
| 6413 | |
| 6414 | printk(KERN_TRACE "Dumping ftrace buffer:\n"); |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 6415 | |
Steven Rostedt (Red Hat) | 7fe70b5 | 2013-03-15 13:10:35 -0400 | [diff] [blame] | 6416 | /* Did function tracer already get disabled? */ |
| 6417 | if (ftrace_is_dead()) { |
| 6418 | printk("# WARNING: FUNCTION TRACING IS CORRUPTED\n"); |
| 6419 | printk("# MAY BE MISSING FUNCTION EVENTS\n"); |
| 6420 | } |
| 6421 | |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 6422 | /* |
| 6423 | * We need to stop all tracing on all CPUS to read the |
| 6424 | * the next buffer. This is a bit expensive, but is |
| 6425 | * not done often. We fill all what we can read, |
| 6426 | * and then release the locks again. |
| 6427 | */ |
| 6428 | |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 6429 | while (!trace_empty(&iter)) { |
| 6430 | |
| 6431 | if (!cnt) |
| 6432 | printk(KERN_TRACE "---------------------------------\n"); |
| 6433 | |
| 6434 | cnt++; |
| 6435 | |
| 6436 | /* reset all but tr, trace, and overruns */ |
| 6437 | memset(&iter.seq, 0, |
| 6438 | sizeof(struct trace_iterator) - |
| 6439 | offsetof(struct trace_iterator, seq)); |
| 6440 | iter.iter_flags |= TRACE_FILE_LAT_FMT; |
| 6441 | iter.pos = -1; |
| 6442 | |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 6443 | if (trace_find_next_entry_inc(&iter) != NULL) { |
Lai Jiangshan | 74e7ff8 | 2009-07-28 20:17:22 +0800 | [diff] [blame] | 6444 | int ret; |
| 6445 | |
| 6446 | ret = print_trace_line(&iter); |
| 6447 | if (ret != TRACE_TYPE_NO_CONSUME) |
| 6448 | trace_consume(&iter); |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 6449 | } |
Steven Rostedt | b892e5c | 2012-03-01 22:06:48 -0500 | [diff] [blame] | 6450 | touch_nmi_watchdog(); |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 6451 | |
| 6452 | trace_printk_seq(&iter.seq); |
| 6453 | } |
| 6454 | |
| 6455 | if (!cnt) |
| 6456 | printk(KERN_TRACE " (ftrace buffer empty)\n"); |
| 6457 | else |
| 6458 | printk(KERN_TRACE "---------------------------------\n"); |
| 6459 | |
Frederic Weisbecker | cecbca9 | 2010-04-18 19:08:41 +0200 | [diff] [blame] | 6460 | out_enable: |
Steven Rostedt (Red Hat) | 7fe70b5 | 2013-03-15 13:10:35 -0400 | [diff] [blame] | 6461 | trace_flags |= old_userobj; |
Frederic Weisbecker | cf586b6 | 2009-03-22 05:04:35 +0100 | [diff] [blame] | 6462 | |
Steven Rostedt (Red Hat) | 7fe70b5 | 2013-03-15 13:10:35 -0400 | [diff] [blame] | 6463 | for_each_tracing_cpu(cpu) { |
| 6464 | atomic_dec(&per_cpu_ptr(iter.trace_buffer->data, cpu)->disabled); |
Frederic Weisbecker | cf586b6 | 2009-03-22 05:04:35 +0100 | [diff] [blame] | 6465 | } |
Steven Rostedt (Red Hat) | 7fe70b5 | 2013-03-15 13:10:35 -0400 | [diff] [blame] | 6466 | atomic_dec(&dump_running); |
Steven Rostedt | cd891ae | 2009-04-28 11:39:34 -0400 | [diff] [blame] | 6467 | local_irq_restore(flags); |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 6468 | } |
Paul E. McKenney | a8eecf2 | 2011-10-02 11:01:15 -0700 | [diff] [blame] | 6469 | EXPORT_SYMBOL_GPL(ftrace_dump); |
Frederic Weisbecker | cf586b6 | 2009-03-22 05:04:35 +0100 | [diff] [blame] | 6470 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 6471 | __init static int tracer_alloc_buffers(void) |
| 6472 | { |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 6473 | int ring_buf_size; |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 6474 | int ret = -ENOMEM; |
| 6475 | |
David Sharp | 750912f | 2010-12-08 13:46:47 -0800 | [diff] [blame] | 6476 | |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 6477 | if (!alloc_cpumask_var(&tracing_buffer_mask, GFP_KERNEL)) |
| 6478 | goto out; |
| 6479 | |
Alexander Z Lam | ccfe9e4 | 2013-08-08 09:47:45 -0700 | [diff] [blame] | 6480 | if (!alloc_cpumask_var(&global_trace.tracing_cpumask, GFP_KERNEL)) |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 6481 | goto out_free_buffer_mask; |
| 6482 | |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 6483 | /* Only allocate trace_printk buffers if a trace_printk exists */ |
| 6484 | if (__stop___trace_bprintk_fmt != __start___trace_bprintk_fmt) |
Steven Rostedt | 8169883 | 2012-10-11 10:15:05 -0400 | [diff] [blame] | 6485 | /* Must be called before global_trace.buffer is allocated */ |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 6486 | trace_printk_init_buffers(); |
| 6487 | |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 6488 | /* To save memory, keep the ring buffer size to its minimum */ |
| 6489 | if (ring_buffer_expanded) |
| 6490 | ring_buf_size = trace_buf_size; |
| 6491 | else |
| 6492 | ring_buf_size = 1; |
| 6493 | |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 6494 | cpumask_copy(tracing_buffer_mask, cpu_possible_mask); |
Alexander Z Lam | ccfe9e4 | 2013-08-08 09:47:45 -0700 | [diff] [blame] | 6495 | cpumask_copy(global_trace.tracing_cpumask, cpu_all_mask); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 6496 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6497 | raw_spin_lock_init(&global_trace.start_lock); |
| 6498 | |
Steven Rostedt | ab46428 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 6499 | /* TODO: make the number of buffers hot pluggable with CPUS */ |
Steven Rostedt (Red Hat) | 737223f | 2013-03-05 21:13:47 -0500 | [diff] [blame] | 6500 | if (allocate_trace_buffers(&global_trace, ring_buf_size) < 0) { |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 6501 | printk(KERN_ERR "tracer: failed to allocate ring buffer!\n"); |
| 6502 | WARN_ON(1); |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 6503 | goto out_free_cpumask; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 6504 | } |
Steven Rostedt | a7603ff | 2012-08-06 16:24:11 -0400 | [diff] [blame] | 6505 | |
Steven Rostedt | 499e547 | 2012-02-22 15:50:28 -0500 | [diff] [blame] | 6506 | if (global_trace.buffer_disabled) |
| 6507 | tracing_off(); |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 6508 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 6509 | trace_init_cmdlines(); |
| 6510 | |
Steven Rostedt (Red Hat) | ca16431 | 2013-05-23 11:51:10 -0400 | [diff] [blame] | 6511 | /* |
| 6512 | * register_tracer() might reference current_trace, so it |
| 6513 | * needs to be set before we register anything. This is |
| 6514 | * just a bootstrap of current_trace anyway. |
| 6515 | */ |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6516 | global_trace.current_trace = &nop_trace; |
| 6517 | |
Steven Rostedt (Red Hat) | ca16431 | 2013-05-23 11:51:10 -0400 | [diff] [blame] | 6518 | register_tracer(&nop_trace); |
| 6519 | |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 6520 | /* All seems OK, enable tracing */ |
| 6521 | tracing_disabled = 0; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 6522 | |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 6523 | atomic_notifier_chain_register(&panic_notifier_list, |
| 6524 | &trace_panic_notifier); |
| 6525 | |
| 6526 | register_die_notifier(&trace_die_notifier); |
Frederic Weisbecker | 2fc1dfb | 2009-03-16 01:45:03 +0100 | [diff] [blame] | 6527 | |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 6528 | global_trace.flags = TRACE_ARRAY_FL_GLOBAL; |
| 6529 | |
| 6530 | INIT_LIST_HEAD(&global_trace.systems); |
| 6531 | INIT_LIST_HEAD(&global_trace.events); |
| 6532 | list_add(&global_trace.list, &ftrace_trace_arrays); |
| 6533 | |
Steven Rostedt | 7bcfaf5 | 2012-11-01 22:56:07 -0400 | [diff] [blame] | 6534 | while (trace_boot_options) { |
| 6535 | char *option; |
| 6536 | |
| 6537 | option = strsep(&trace_boot_options, ","); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6538 | trace_set_options(&global_trace, option); |
Steven Rostedt | 7bcfaf5 | 2012-11-01 22:56:07 -0400 | [diff] [blame] | 6539 | } |
| 6540 | |
Steven Rostedt (Red Hat) | 77fd5c1 | 2013-03-12 11:49:18 -0400 | [diff] [blame] | 6541 | register_snapshot_cmd(); |
| 6542 | |
Frederic Weisbecker | 2fc1dfb | 2009-03-16 01:45:03 +0100 | [diff] [blame] | 6543 | return 0; |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 6544 | |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 6545 | out_free_cpumask: |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 6546 | free_percpu(global_trace.trace_buffer.data); |
| 6547 | #ifdef CONFIG_TRACER_MAX_TRACE |
| 6548 | free_percpu(global_trace.max_buffer.data); |
| 6549 | #endif |
Alexander Z Lam | ccfe9e4 | 2013-08-08 09:47:45 -0700 | [diff] [blame] | 6550 | free_cpumask_var(global_trace.tracing_cpumask); |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 6551 | out_free_buffer_mask: |
| 6552 | free_cpumask_var(tracing_buffer_mask); |
| 6553 | out: |
| 6554 | return ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 6555 | } |
Steven Rostedt | b2821ae | 2009-02-02 21:38:32 -0500 | [diff] [blame] | 6556 | |
| 6557 | __init static int clear_boot_tracer(void) |
| 6558 | { |
| 6559 | /* |
| 6560 | * The default tracer at boot buffer is an init section. |
| 6561 | * This function is called in lateinit. If we did not |
| 6562 | * find the boot tracer, then clear it out, to prevent |
| 6563 | * later registration from accessing the buffer that is |
| 6564 | * about to be freed. |
| 6565 | */ |
| 6566 | if (!default_bootup_tracer) |
| 6567 | return 0; |
| 6568 | |
| 6569 | printk(KERN_INFO "ftrace bootup tracer '%s' not registered.\n", |
| 6570 | default_bootup_tracer); |
| 6571 | default_bootup_tracer = NULL; |
| 6572 | |
| 6573 | return 0; |
| 6574 | } |
| 6575 | |
Frédéric Weisbecker | b5ad384 | 2008-09-23 11:34:32 +0100 | [diff] [blame] | 6576 | early_initcall(tracer_alloc_buffers); |
| 6577 | fs_initcall(tracer_init_debugfs); |
Steven Rostedt | b2821ae | 2009-02-02 21:38:32 -0500 | [diff] [blame] | 6578 | late_initcall(clear_boot_tracer); |