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 | |
| 76 | static int dummy_set_flag(u32 old_flags, u32 bit, int set) |
| 77 | { |
| 78 | return 0; |
| 79 | } |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 80 | |
| 81 | /* |
Steven Rostedt | 7ffbd48 | 2012-10-11 12:14:25 -0400 | [diff] [blame] | 82 | * To prevent the comm cache from being overwritten when no |
| 83 | * tracing is active, only save the comm when a trace event |
| 84 | * occurred. |
| 85 | */ |
| 86 | static DEFINE_PER_CPU(bool, trace_cmdline_save); |
| 87 | |
| 88 | /* |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 89 | * Kill all tracing for good (never come back). |
| 90 | * It is initialized to 1 but will turn to zero if the initialization |
| 91 | * of the tracer is successful. But that is the only place that sets |
| 92 | * this back to zero. |
| 93 | */ |
Hannes Eder | 4fd2735 | 2009-02-10 19:44:12 +0100 | [diff] [blame] | 94 | static int tracing_disabled = 1; |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 95 | |
Christoph Lameter | 9288f99 | 2009-10-07 19:17:45 -0400 | [diff] [blame] | 96 | DEFINE_PER_CPU(int, ftrace_cpu_disabled); |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 97 | |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 98 | cpumask_var_t __read_mostly tracing_buffer_mask; |
Steven Rostedt | ab46428 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 99 | |
Steven Rostedt | 944ac42 | 2008-10-23 19:26:08 -0400 | [diff] [blame] | 100 | /* |
| 101 | * ftrace_dump_on_oops - variable to dump ftrace buffer on oops |
| 102 | * |
| 103 | * If there is an oops (or kernel panic) and the ftrace_dump_on_oops |
| 104 | * is set, then ftrace_dump is called. This will output the contents |
| 105 | * of the ftrace buffers to the console. This is very useful for |
| 106 | * capturing traces that lead to crashes and outputing it to a |
| 107 | * serial console. |
| 108 | * |
| 109 | * It is default off, but you can enable it with either specifying |
| 110 | * "ftrace_dump_on_oops" in the kernel command line, or setting |
Frederic Weisbecker | cecbca9 | 2010-04-18 19:08:41 +0200 | [diff] [blame] | 111 | * /proc/sys/kernel/ftrace_dump_on_oops |
| 112 | * Set 1 if you want to dump buffers of all CPUs |
| 113 | * 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] | 114 | */ |
Frederic Weisbecker | cecbca9 | 2010-04-18 19:08:41 +0200 | [diff] [blame] | 115 | |
| 116 | enum ftrace_dump_mode ftrace_dump_on_oops; |
Steven Rostedt | 944ac42 | 2008-10-23 19:26:08 -0400 | [diff] [blame] | 117 | |
Steven Rostedt (Red Hat) | de7edd3 | 2013-06-14 16:21:43 -0400 | [diff] [blame] | 118 | /* When set, tracing will stop when a WARN*() is hit */ |
| 119 | int __disable_trace_on_warning; |
| 120 | |
Steven Rostedt | b2821ae | 2009-02-02 21:38:32 -0500 | [diff] [blame] | 121 | static int tracing_set_tracer(const char *buf); |
| 122 | |
Li Zefan | ee6c2c1 | 2009-09-18 14:06:47 +0800 | [diff] [blame] | 123 | #define MAX_TRACER_SIZE 100 |
| 124 | static char bootup_tracer_buf[MAX_TRACER_SIZE] __initdata; |
Steven Rostedt | b2821ae | 2009-02-02 21:38:32 -0500 | [diff] [blame] | 125 | static char *default_bootup_tracer; |
Peter Zijlstra | d9e5407 | 2008-11-01 19:57:37 +0100 | [diff] [blame] | 126 | |
Steven Rostedt (Red Hat) | 55034cd | 2013-03-07 22:48:09 -0500 | [diff] [blame] | 127 | static bool allocate_snapshot; |
| 128 | |
Frederic Weisbecker | 1beee96 | 2009-10-14 20:50:32 +0200 | [diff] [blame] | 129 | static int __init set_cmdline_ftrace(char *str) |
Peter Zijlstra | d9e5407 | 2008-11-01 19:57:37 +0100 | [diff] [blame] | 130 | { |
Chen Gang | 67012ab | 2013-04-08 12:06:44 +0800 | [diff] [blame] | 131 | strlcpy(bootup_tracer_buf, str, MAX_TRACER_SIZE); |
Steven Rostedt | b2821ae | 2009-02-02 21:38:32 -0500 | [diff] [blame] | 132 | default_bootup_tracer = bootup_tracer_buf; |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 133 | /* We are using ftrace early, expand it */ |
Steven Rostedt (Red Hat) | 55034cd | 2013-03-07 22:48:09 -0500 | [diff] [blame] | 134 | ring_buffer_expanded = true; |
Peter Zijlstra | d9e5407 | 2008-11-01 19:57:37 +0100 | [diff] [blame] | 135 | return 1; |
| 136 | } |
Frederic Weisbecker | 1beee96 | 2009-10-14 20:50:32 +0200 | [diff] [blame] | 137 | __setup("ftrace=", set_cmdline_ftrace); |
Peter Zijlstra | d9e5407 | 2008-11-01 19:57:37 +0100 | [diff] [blame] | 138 | |
Steven Rostedt | 944ac42 | 2008-10-23 19:26:08 -0400 | [diff] [blame] | 139 | static int __init set_ftrace_dump_on_oops(char *str) |
| 140 | { |
Frederic Weisbecker | cecbca9 | 2010-04-18 19:08:41 +0200 | [diff] [blame] | 141 | if (*str++ != '=' || !*str) { |
| 142 | ftrace_dump_on_oops = DUMP_ALL; |
| 143 | return 1; |
| 144 | } |
| 145 | |
| 146 | if (!strcmp("orig_cpu", str)) { |
| 147 | ftrace_dump_on_oops = DUMP_ORIG; |
| 148 | return 1; |
| 149 | } |
| 150 | |
| 151 | return 0; |
Steven Rostedt | 944ac42 | 2008-10-23 19:26:08 -0400 | [diff] [blame] | 152 | } |
| 153 | __setup("ftrace_dump_on_oops", set_ftrace_dump_on_oops); |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 154 | |
Steven Rostedt (Red Hat) | de7edd3 | 2013-06-14 16:21:43 -0400 | [diff] [blame] | 155 | static int __init stop_trace_on_warning(char *str) |
| 156 | { |
| 157 | __disable_trace_on_warning = 1; |
| 158 | return 1; |
| 159 | } |
| 160 | __setup("traceoff_on_warning=", stop_trace_on_warning); |
| 161 | |
Steven Rostedt (Red Hat) | 3209cff | 2013-03-12 11:17:54 -0400 | [diff] [blame] | 162 | static int __init boot_alloc_snapshot(char *str) |
Steven Rostedt (Red Hat) | 55034cd | 2013-03-07 22:48:09 -0500 | [diff] [blame] | 163 | { |
| 164 | allocate_snapshot = true; |
| 165 | /* We also need the main ring buffer expanded */ |
| 166 | ring_buffer_expanded = true; |
| 167 | return 1; |
| 168 | } |
Steven Rostedt (Red Hat) | 3209cff | 2013-03-12 11:17:54 -0400 | [diff] [blame] | 169 | __setup("alloc_snapshot", boot_alloc_snapshot); |
Steven Rostedt (Red Hat) | 55034cd | 2013-03-07 22:48:09 -0500 | [diff] [blame] | 170 | |
Steven Rostedt | 7bcfaf5 | 2012-11-01 22:56:07 -0400 | [diff] [blame] | 171 | |
| 172 | static char trace_boot_options_buf[MAX_TRACER_SIZE] __initdata; |
| 173 | static char *trace_boot_options __initdata; |
| 174 | |
| 175 | static int __init set_trace_boot_options(char *str) |
| 176 | { |
Chen Gang | 67012ab | 2013-04-08 12:06:44 +0800 | [diff] [blame] | 177 | strlcpy(trace_boot_options_buf, str, MAX_TRACER_SIZE); |
Steven Rostedt | 7bcfaf5 | 2012-11-01 22:56:07 -0400 | [diff] [blame] | 178 | trace_boot_options = trace_boot_options_buf; |
| 179 | return 0; |
| 180 | } |
| 181 | __setup("trace_options=", set_trace_boot_options); |
| 182 | |
Steven Rostedt (Red Hat) | de7edd3 | 2013-06-14 16:21:43 -0400 | [diff] [blame] | 183 | |
Lai Jiangshan | cf8e347 | 2009-03-30 13:48:00 +0800 | [diff] [blame] | 184 | unsigned long long ns2usecs(cycle_t nsec) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 185 | { |
| 186 | nsec += 500; |
| 187 | do_div(nsec, 1000); |
| 188 | return nsec; |
| 189 | } |
| 190 | |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 191 | /* |
| 192 | * The global_trace is the descriptor that holds the tracing |
| 193 | * buffers for the live tracing. For each CPU, it contains |
| 194 | * a link list of pages that will store trace entries. The |
| 195 | * page descriptor of the pages in the memory is used to hold |
| 196 | * the link list by linking the lru item in the page descriptor |
| 197 | * to each of the pages in the buffer per CPU. |
| 198 | * |
| 199 | * For each active CPU there is a data field that holds the |
| 200 | * pages for the buffer for that CPU. Each CPU has the same number |
| 201 | * of pages allocated for its buffer. |
| 202 | */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 203 | static struct trace_array global_trace; |
| 204 | |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 205 | LIST_HEAD(ftrace_trace_arrays); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 206 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 207 | int filter_current_check_discard(struct ring_buffer *buffer, |
| 208 | struct ftrace_event_call *call, void *rec, |
Tom Zanussi | eb02ce0 | 2009-04-08 03:15:54 -0500 | [diff] [blame] | 209 | struct ring_buffer_event *event) |
| 210 | { |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 211 | return filter_check_discard(call, rec, buffer, event); |
Tom Zanussi | eb02ce0 | 2009-04-08 03:15:54 -0500 | [diff] [blame] | 212 | } |
Steven Rostedt | 17c873e | 2009-04-10 18:12:50 -0400 | [diff] [blame] | 213 | EXPORT_SYMBOL_GPL(filter_current_check_discard); |
Tom Zanussi | eb02ce0 | 2009-04-08 03:15:54 -0500 | [diff] [blame] | 214 | |
Steven Rostedt | 37886f6 | 2009-03-17 17:22:06 -0400 | [diff] [blame] | 215 | cycle_t ftrace_now(int cpu) |
| 216 | { |
| 217 | u64 ts; |
| 218 | |
| 219 | /* Early boot up does not have a buffer yet */ |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 220 | if (!global_trace.trace_buffer.buffer) |
Steven Rostedt | 37886f6 | 2009-03-17 17:22:06 -0400 | [diff] [blame] | 221 | return trace_clock_local(); |
| 222 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 223 | ts = ring_buffer_time_stamp(global_trace.trace_buffer.buffer, cpu); |
| 224 | ring_buffer_normalize_time_stamp(global_trace.trace_buffer.buffer, cpu, &ts); |
Steven Rostedt | 37886f6 | 2009-03-17 17:22:06 -0400 | [diff] [blame] | 225 | |
| 226 | return ts; |
| 227 | } |
| 228 | |
Steven Rostedt (Red Hat) | 10246fa | 2013-07-01 15:58:24 -0400 | [diff] [blame^] | 229 | /** |
| 230 | * tracing_is_enabled - Show if global_trace has been disabled |
| 231 | * |
| 232 | * Shows if the global trace has been enabled or not. It uses the |
| 233 | * mirror flag "buffer_disabled" to be used in fast paths such as for |
| 234 | * the irqsoff tracer. But it may be inaccurate due to races. If you |
| 235 | * need to know the accurate state, use tracing_is_on() which is a little |
| 236 | * slower, but accurate. |
| 237 | */ |
Steven Rostedt | 9036990 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 238 | int tracing_is_enabled(void) |
| 239 | { |
Steven Rostedt (Red Hat) | 10246fa | 2013-07-01 15:58:24 -0400 | [diff] [blame^] | 240 | /* |
| 241 | * For quick access (irqsoff uses this in fast path), just |
| 242 | * return the mirror variable of the state of the ring buffer. |
| 243 | * It's a little racy, but we don't really care. |
| 244 | */ |
| 245 | smp_rmb(); |
| 246 | return !global_trace.buffer_disabled; |
Steven Rostedt | 9036990 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 247 | } |
| 248 | |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 249 | /* |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 250 | * trace_buf_size is the size in bytes that is allocated |
| 251 | * for a buffer. Note, the number of bytes is always rounded |
| 252 | * to page size. |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 253 | * |
| 254 | * This number is purposely set to a low number of 16384. |
| 255 | * If the dump on oops happens, it will be much appreciated |
| 256 | * to not have to wait for all that output. Anyway this can be |
| 257 | * boot time and run time configurable. |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 258 | */ |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 259 | #define TRACE_BUF_SIZE_DEFAULT 1441792UL /* 16384 * 88 (sizeof(entry)) */ |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 260 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 261 | static unsigned long trace_buf_size = TRACE_BUF_SIZE_DEFAULT; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 262 | |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 263 | /* trace_types holds a link list of available tracers. */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 264 | static struct tracer *trace_types __read_mostly; |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 265 | |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 266 | /* |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 267 | * trace_types_lock is used to protect the trace_types list. |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 268 | */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 269 | static DEFINE_MUTEX(trace_types_lock); |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 270 | |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 271 | /* |
| 272 | * serialize the access of the ring buffer |
| 273 | * |
| 274 | * ring buffer serializes readers, but it is low level protection. |
| 275 | * The validity of the events (which returns by ring_buffer_peek() ..etc) |
| 276 | * are not protected by ring buffer. |
| 277 | * |
| 278 | * The content of events may become garbage if we allow other process consumes |
| 279 | * these events concurrently: |
| 280 | * A) the page of the consumed events may become a normal page |
| 281 | * (not reader page) in ring buffer, and this page will be rewrited |
| 282 | * by events producer. |
| 283 | * B) The page of the consumed events may become a page for splice_read, |
| 284 | * and this page will be returned to system. |
| 285 | * |
| 286 | * These primitives allow multi process access to different cpu ring buffer |
| 287 | * concurrently. |
| 288 | * |
| 289 | * These primitives don't distinguish read-only and read-consume access. |
| 290 | * Multi read-only access are also serialized. |
| 291 | */ |
| 292 | |
| 293 | #ifdef CONFIG_SMP |
| 294 | static DECLARE_RWSEM(all_cpu_access_lock); |
| 295 | static DEFINE_PER_CPU(struct mutex, cpu_access_lock); |
| 296 | |
| 297 | static inline void trace_access_lock(int cpu) |
| 298 | { |
Steven Rostedt | ae3b509 | 2013-01-23 15:22:59 -0500 | [diff] [blame] | 299 | if (cpu == RING_BUFFER_ALL_CPUS) { |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 300 | /* gain it for accessing the whole ring buffer. */ |
| 301 | down_write(&all_cpu_access_lock); |
| 302 | } else { |
| 303 | /* gain it for accessing a cpu ring buffer. */ |
| 304 | |
Steven Rostedt | ae3b509 | 2013-01-23 15:22:59 -0500 | [diff] [blame] | 305 | /* Firstly block other trace_access_lock(RING_BUFFER_ALL_CPUS). */ |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 306 | down_read(&all_cpu_access_lock); |
| 307 | |
| 308 | /* Secondly block other access to this @cpu ring buffer. */ |
| 309 | mutex_lock(&per_cpu(cpu_access_lock, cpu)); |
| 310 | } |
| 311 | } |
| 312 | |
| 313 | static inline void trace_access_unlock(int cpu) |
| 314 | { |
Steven Rostedt | ae3b509 | 2013-01-23 15:22:59 -0500 | [diff] [blame] | 315 | if (cpu == RING_BUFFER_ALL_CPUS) { |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 316 | up_write(&all_cpu_access_lock); |
| 317 | } else { |
| 318 | mutex_unlock(&per_cpu(cpu_access_lock, cpu)); |
| 319 | up_read(&all_cpu_access_lock); |
| 320 | } |
| 321 | } |
| 322 | |
| 323 | static inline void trace_access_lock_init(void) |
| 324 | { |
| 325 | int cpu; |
| 326 | |
| 327 | for_each_possible_cpu(cpu) |
| 328 | mutex_init(&per_cpu(cpu_access_lock, cpu)); |
| 329 | } |
| 330 | |
| 331 | #else |
| 332 | |
| 333 | static DEFINE_MUTEX(access_lock); |
| 334 | |
| 335 | static inline void trace_access_lock(int cpu) |
| 336 | { |
| 337 | (void)cpu; |
| 338 | mutex_lock(&access_lock); |
| 339 | } |
| 340 | |
| 341 | static inline void trace_access_unlock(int cpu) |
| 342 | { |
| 343 | (void)cpu; |
| 344 | mutex_unlock(&access_lock); |
| 345 | } |
| 346 | |
| 347 | static inline void trace_access_lock_init(void) |
| 348 | { |
| 349 | } |
| 350 | |
| 351 | #endif |
| 352 | |
Steven Rostedt | ee6bce5 | 2008-11-12 17:52:37 -0500 | [diff] [blame] | 353 | /* trace_flags holds trace_options default values */ |
Steven Rostedt | 12ef7d4 | 2008-11-12 17:52:38 -0500 | [diff] [blame] | 354 | unsigned long trace_flags = TRACE_ITER_PRINT_PARENT | TRACE_ITER_PRINTK | |
Steven Rostedt | a2a16d6 | 2009-03-24 23:17:58 -0400 | [diff] [blame] | 355 | TRACE_ITER_ANNOTATE | TRACE_ITER_CONTEXT_INFO | TRACE_ITER_SLEEP_TIME | |
Steven Rostedt | 77271ce | 2011-11-17 09:34:33 -0500 | [diff] [blame] | 356 | 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] | 357 | TRACE_ITER_IRQ_INFO | TRACE_ITER_MARKERS | TRACE_ITER_FUNCTION; |
Vaibhav Nagarnaik | e7e2ee8 | 2011-05-10 13:27:21 -0700 | [diff] [blame] | 358 | |
Steven Rostedt (Red Hat) | 10246fa | 2013-07-01 15:58:24 -0400 | [diff] [blame^] | 359 | void tracer_tracing_on(struct trace_array *tr) |
| 360 | { |
| 361 | if (tr->trace_buffer.buffer) |
| 362 | ring_buffer_record_on(tr->trace_buffer.buffer); |
| 363 | /* |
| 364 | * This flag is looked at when buffers haven't been allocated |
| 365 | * yet, or by some tracers (like irqsoff), that just want to |
| 366 | * know if the ring buffer has been disabled, but it can handle |
| 367 | * races of where it gets disabled but we still do a record. |
| 368 | * As the check is in the fast path of the tracers, it is more |
| 369 | * important to be fast than accurate. |
| 370 | */ |
| 371 | tr->buffer_disabled = 0; |
| 372 | /* Make the flag seen by readers */ |
| 373 | smp_wmb(); |
| 374 | } |
| 375 | |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 376 | /** |
Steven Rostedt | 499e547 | 2012-02-22 15:50:28 -0500 | [diff] [blame] | 377 | * tracing_on - enable tracing buffers |
| 378 | * |
| 379 | * This function enables tracing buffers that may have been |
| 380 | * disabled with tracing_off. |
| 381 | */ |
| 382 | void tracing_on(void) |
| 383 | { |
Steven Rostedt (Red Hat) | 10246fa | 2013-07-01 15:58:24 -0400 | [diff] [blame^] | 384 | tracer_tracing_on(&global_trace); |
Steven Rostedt | 499e547 | 2012-02-22 15:50:28 -0500 | [diff] [blame] | 385 | } |
| 386 | EXPORT_SYMBOL_GPL(tracing_on); |
| 387 | |
| 388 | /** |
Steven Rostedt (Red Hat) | 09ae723 | 2013-03-08 21:02:34 -0500 | [diff] [blame] | 389 | * __trace_puts - write a constant string into the trace buffer. |
| 390 | * @ip: The address of the caller |
| 391 | * @str: The constant string to write |
| 392 | * @size: The size of the string. |
| 393 | */ |
| 394 | int __trace_puts(unsigned long ip, const char *str, int size) |
| 395 | { |
| 396 | struct ring_buffer_event *event; |
| 397 | struct ring_buffer *buffer; |
| 398 | struct print_entry *entry; |
| 399 | unsigned long irq_flags; |
| 400 | int alloc; |
| 401 | |
| 402 | alloc = sizeof(*entry) + size + 2; /* possible \n added */ |
| 403 | |
| 404 | local_save_flags(irq_flags); |
| 405 | buffer = global_trace.trace_buffer.buffer; |
| 406 | event = trace_buffer_lock_reserve(buffer, TRACE_PRINT, alloc, |
| 407 | irq_flags, preempt_count()); |
| 408 | if (!event) |
| 409 | return 0; |
| 410 | |
| 411 | entry = ring_buffer_event_data(event); |
| 412 | entry->ip = ip; |
| 413 | |
| 414 | memcpy(&entry->buf, str, size); |
| 415 | |
| 416 | /* Add a newline if necessary */ |
| 417 | if (entry->buf[size - 1] != '\n') { |
| 418 | entry->buf[size] = '\n'; |
| 419 | entry->buf[size + 1] = '\0'; |
| 420 | } else |
| 421 | entry->buf[size] = '\0'; |
| 422 | |
| 423 | __buffer_unlock_commit(buffer, event); |
| 424 | |
| 425 | return size; |
| 426 | } |
| 427 | EXPORT_SYMBOL_GPL(__trace_puts); |
| 428 | |
| 429 | /** |
| 430 | * __trace_bputs - write the pointer to a constant string into trace buffer |
| 431 | * @ip: The address of the caller |
| 432 | * @str: The constant string to write to the buffer to |
| 433 | */ |
| 434 | int __trace_bputs(unsigned long ip, const char *str) |
| 435 | { |
| 436 | struct ring_buffer_event *event; |
| 437 | struct ring_buffer *buffer; |
| 438 | struct bputs_entry *entry; |
| 439 | unsigned long irq_flags; |
| 440 | int size = sizeof(struct bputs_entry); |
| 441 | |
| 442 | local_save_flags(irq_flags); |
| 443 | buffer = global_trace.trace_buffer.buffer; |
| 444 | event = trace_buffer_lock_reserve(buffer, TRACE_BPUTS, size, |
| 445 | irq_flags, preempt_count()); |
| 446 | if (!event) |
| 447 | return 0; |
| 448 | |
| 449 | entry = ring_buffer_event_data(event); |
| 450 | entry->ip = ip; |
| 451 | entry->str = str; |
| 452 | |
| 453 | __buffer_unlock_commit(buffer, event); |
| 454 | |
| 455 | return 1; |
| 456 | } |
| 457 | EXPORT_SYMBOL_GPL(__trace_bputs); |
| 458 | |
Steven Rostedt (Red Hat) | ad909e2 | 2013-03-06 21:45:37 -0500 | [diff] [blame] | 459 | #ifdef CONFIG_TRACER_SNAPSHOT |
| 460 | /** |
| 461 | * trace_snapshot - take a snapshot of the current buffer. |
| 462 | * |
| 463 | * This causes a swap between the snapshot buffer and the current live |
| 464 | * tracing buffer. You can use this to take snapshots of the live |
| 465 | * trace when some condition is triggered, but continue to trace. |
| 466 | * |
| 467 | * Note, make sure to allocate the snapshot with either |
| 468 | * a tracing_snapshot_alloc(), or by doing it manually |
| 469 | * with: echo 1 > /sys/kernel/debug/tracing/snapshot |
| 470 | * |
| 471 | * If the snapshot buffer is not allocated, it will stop tracing. |
| 472 | * Basically making a permanent snapshot. |
| 473 | */ |
| 474 | void tracing_snapshot(void) |
| 475 | { |
| 476 | struct trace_array *tr = &global_trace; |
| 477 | struct tracer *tracer = tr->current_trace; |
| 478 | unsigned long flags; |
| 479 | |
Steven Rostedt (Red Hat) | 1b22e38 | 2013-03-09 00:56:08 -0500 | [diff] [blame] | 480 | if (in_nmi()) { |
| 481 | internal_trace_puts("*** SNAPSHOT CALLED FROM NMI CONTEXT ***\n"); |
| 482 | internal_trace_puts("*** snapshot is being ignored ***\n"); |
| 483 | return; |
| 484 | } |
| 485 | |
Steven Rostedt (Red Hat) | ad909e2 | 2013-03-06 21:45:37 -0500 | [diff] [blame] | 486 | if (!tr->allocated_snapshot) { |
Steven Rostedt (Red Hat) | ca268da | 2013-03-09 00:40:58 -0500 | [diff] [blame] | 487 | internal_trace_puts("*** SNAPSHOT NOT ALLOCATED ***\n"); |
| 488 | internal_trace_puts("*** stopping trace here! ***\n"); |
Steven Rostedt (Red Hat) | ad909e2 | 2013-03-06 21:45:37 -0500 | [diff] [blame] | 489 | tracing_off(); |
| 490 | return; |
| 491 | } |
| 492 | |
| 493 | /* Note, snapshot can not be used when the tracer uses it */ |
| 494 | if (tracer->use_max_tr) { |
Steven Rostedt (Red Hat) | ca268da | 2013-03-09 00:40:58 -0500 | [diff] [blame] | 495 | internal_trace_puts("*** LATENCY TRACER ACTIVE ***\n"); |
| 496 | internal_trace_puts("*** Can not use snapshot (sorry) ***\n"); |
Steven Rostedt (Red Hat) | ad909e2 | 2013-03-06 21:45:37 -0500 | [diff] [blame] | 497 | return; |
| 498 | } |
| 499 | |
| 500 | local_irq_save(flags); |
| 501 | update_max_tr(tr, current, smp_processor_id()); |
| 502 | local_irq_restore(flags); |
| 503 | } |
Steven Rostedt (Red Hat) | 1b22e38 | 2013-03-09 00:56:08 -0500 | [diff] [blame] | 504 | EXPORT_SYMBOL_GPL(tracing_snapshot); |
Steven Rostedt (Red Hat) | ad909e2 | 2013-03-06 21:45:37 -0500 | [diff] [blame] | 505 | |
| 506 | static int resize_buffer_duplicate_size(struct trace_buffer *trace_buf, |
| 507 | struct trace_buffer *size_buf, int cpu_id); |
Steven Rostedt (Red Hat) | 3209cff | 2013-03-12 11:17:54 -0400 | [diff] [blame] | 508 | static void set_buffer_entries(struct trace_buffer *buf, unsigned long val); |
| 509 | |
| 510 | static int alloc_snapshot(struct trace_array *tr) |
| 511 | { |
| 512 | int ret; |
| 513 | |
| 514 | if (!tr->allocated_snapshot) { |
| 515 | |
| 516 | /* allocate spare buffer */ |
| 517 | ret = resize_buffer_duplicate_size(&tr->max_buffer, |
| 518 | &tr->trace_buffer, RING_BUFFER_ALL_CPUS); |
| 519 | if (ret < 0) |
| 520 | return ret; |
| 521 | |
| 522 | tr->allocated_snapshot = true; |
| 523 | } |
| 524 | |
| 525 | return 0; |
| 526 | } |
| 527 | |
| 528 | void free_snapshot(struct trace_array *tr) |
| 529 | { |
| 530 | /* |
| 531 | * We don't free the ring buffer. instead, resize it because |
| 532 | * The max_tr ring buffer has some state (e.g. ring->clock) and |
| 533 | * we want preserve it. |
| 534 | */ |
| 535 | ring_buffer_resize(tr->max_buffer.buffer, 1, RING_BUFFER_ALL_CPUS); |
| 536 | set_buffer_entries(&tr->max_buffer, 1); |
| 537 | tracing_reset_online_cpus(&tr->max_buffer); |
| 538 | tr->allocated_snapshot = false; |
| 539 | } |
Steven Rostedt (Red Hat) | ad909e2 | 2013-03-06 21:45:37 -0500 | [diff] [blame] | 540 | |
| 541 | /** |
| 542 | * trace_snapshot_alloc - allocate and take a snapshot of the current buffer. |
| 543 | * |
| 544 | * This is similar to trace_snapshot(), but it will allocate the |
| 545 | * snapshot buffer if it isn't already allocated. Use this only |
| 546 | * where it is safe to sleep, as the allocation may sleep. |
| 547 | * |
| 548 | * This causes a swap between the snapshot buffer and the current live |
| 549 | * tracing buffer. You can use this to take snapshots of the live |
| 550 | * trace when some condition is triggered, but continue to trace. |
| 551 | */ |
| 552 | void tracing_snapshot_alloc(void) |
| 553 | { |
| 554 | struct trace_array *tr = &global_trace; |
| 555 | int ret; |
| 556 | |
Steven Rostedt (Red Hat) | 3209cff | 2013-03-12 11:17:54 -0400 | [diff] [blame] | 557 | ret = alloc_snapshot(tr); |
| 558 | if (WARN_ON(ret < 0)) |
| 559 | return; |
Steven Rostedt (Red Hat) | ad909e2 | 2013-03-06 21:45:37 -0500 | [diff] [blame] | 560 | |
| 561 | tracing_snapshot(); |
| 562 | } |
Steven Rostedt (Red Hat) | 1b22e38 | 2013-03-09 00:56:08 -0500 | [diff] [blame] | 563 | EXPORT_SYMBOL_GPL(tracing_snapshot_alloc); |
Steven Rostedt (Red Hat) | ad909e2 | 2013-03-06 21:45:37 -0500 | [diff] [blame] | 564 | #else |
| 565 | void tracing_snapshot(void) |
| 566 | { |
| 567 | WARN_ONCE(1, "Snapshot feature not enabled, but internal snapshot used"); |
| 568 | } |
Steven Rostedt (Red Hat) | 1b22e38 | 2013-03-09 00:56:08 -0500 | [diff] [blame] | 569 | EXPORT_SYMBOL_GPL(tracing_snapshot); |
Steven Rostedt (Red Hat) | ad909e2 | 2013-03-06 21:45:37 -0500 | [diff] [blame] | 570 | void tracing_snapshot_alloc(void) |
| 571 | { |
| 572 | /* Give warning */ |
| 573 | tracing_snapshot(); |
| 574 | } |
Steven Rostedt (Red Hat) | 1b22e38 | 2013-03-09 00:56:08 -0500 | [diff] [blame] | 575 | EXPORT_SYMBOL_GPL(tracing_snapshot_alloc); |
Steven Rostedt (Red Hat) | ad909e2 | 2013-03-06 21:45:37 -0500 | [diff] [blame] | 576 | #endif /* CONFIG_TRACER_SNAPSHOT */ |
| 577 | |
Steven Rostedt (Red Hat) | 10246fa | 2013-07-01 15:58:24 -0400 | [diff] [blame^] | 578 | void tracer_tracing_off(struct trace_array *tr) |
| 579 | { |
| 580 | if (tr->trace_buffer.buffer) |
| 581 | ring_buffer_record_off(tr->trace_buffer.buffer); |
| 582 | /* |
| 583 | * This flag is looked at when buffers haven't been allocated |
| 584 | * yet, or by some tracers (like irqsoff), that just want to |
| 585 | * know if the ring buffer has been disabled, but it can handle |
| 586 | * races of where it gets disabled but we still do a record. |
| 587 | * As the check is in the fast path of the tracers, it is more |
| 588 | * important to be fast than accurate. |
| 589 | */ |
| 590 | tr->buffer_disabled = 1; |
| 591 | /* Make the flag seen by readers */ |
| 592 | smp_wmb(); |
| 593 | } |
| 594 | |
Steven Rostedt | 499e547 | 2012-02-22 15:50:28 -0500 | [diff] [blame] | 595 | /** |
| 596 | * tracing_off - turn off tracing buffers |
| 597 | * |
| 598 | * This function stops the tracing buffers from recording data. |
| 599 | * It does not disable any overhead the tracers themselves may |
| 600 | * be causing. This function simply causes all recording to |
| 601 | * the ring buffers to fail. |
| 602 | */ |
| 603 | void tracing_off(void) |
| 604 | { |
Steven Rostedt (Red Hat) | 10246fa | 2013-07-01 15:58:24 -0400 | [diff] [blame^] | 605 | tracer_tracing_off(&global_trace); |
Steven Rostedt | 499e547 | 2012-02-22 15:50:28 -0500 | [diff] [blame] | 606 | } |
| 607 | EXPORT_SYMBOL_GPL(tracing_off); |
| 608 | |
Steven Rostedt (Red Hat) | de7edd3 | 2013-06-14 16:21:43 -0400 | [diff] [blame] | 609 | void disable_trace_on_warning(void) |
| 610 | { |
| 611 | if (__disable_trace_on_warning) |
| 612 | tracing_off(); |
| 613 | } |
| 614 | |
Steven Rostedt | 499e547 | 2012-02-22 15:50:28 -0500 | [diff] [blame] | 615 | /** |
Steven Rostedt (Red Hat) | 10246fa | 2013-07-01 15:58:24 -0400 | [diff] [blame^] | 616 | * tracer_tracing_is_on - show real state of ring buffer enabled |
| 617 | * @tr : the trace array to know if ring buffer is enabled |
| 618 | * |
| 619 | * Shows real state of the ring buffer if it is enabled or not. |
| 620 | */ |
| 621 | int tracer_tracing_is_on(struct trace_array *tr) |
| 622 | { |
| 623 | if (tr->trace_buffer.buffer) |
| 624 | return ring_buffer_record_is_on(tr->trace_buffer.buffer); |
| 625 | return !tr->buffer_disabled; |
| 626 | } |
| 627 | |
| 628 | /** |
Steven Rostedt | 499e547 | 2012-02-22 15:50:28 -0500 | [diff] [blame] | 629 | * tracing_is_on - show state of ring buffers enabled |
| 630 | */ |
| 631 | int tracing_is_on(void) |
| 632 | { |
Steven Rostedt (Red Hat) | 10246fa | 2013-07-01 15:58:24 -0400 | [diff] [blame^] | 633 | return tracer_tracing_is_on(&global_trace); |
Steven Rostedt | 499e547 | 2012-02-22 15:50:28 -0500 | [diff] [blame] | 634 | } |
| 635 | EXPORT_SYMBOL_GPL(tracing_is_on); |
| 636 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 637 | static int __init set_buf_size(char *str) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 638 | { |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 639 | unsigned long buf_size; |
Steven Rostedt | c6caeeb | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 640 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 641 | if (!str) |
| 642 | return 0; |
Li Zefan | 9d612be | 2009-06-24 17:33:15 +0800 | [diff] [blame] | 643 | buf_size = memparse(str, &str); |
Steven Rostedt | c6caeeb | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 644 | /* nr_entries can not be zero */ |
Li Zefan | 9d612be | 2009-06-24 17:33:15 +0800 | [diff] [blame] | 645 | if (buf_size == 0) |
Steven Rostedt | c6caeeb | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 646 | return 0; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 647 | trace_buf_size = buf_size; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 648 | return 1; |
| 649 | } |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 650 | __setup("trace_buf_size=", set_buf_size); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 651 | |
Tim Bird | 0e95017 | 2010-02-25 15:36:43 -0800 | [diff] [blame] | 652 | static int __init set_tracing_thresh(char *str) |
| 653 | { |
Wang Tianhong | 87abb3b | 2012-08-02 14:02:00 +0800 | [diff] [blame] | 654 | unsigned long threshold; |
Tim Bird | 0e95017 | 2010-02-25 15:36:43 -0800 | [diff] [blame] | 655 | int ret; |
| 656 | |
| 657 | if (!str) |
| 658 | return 0; |
Daniel Walter | bcd83ea | 2012-09-26 22:08:38 +0200 | [diff] [blame] | 659 | ret = kstrtoul(str, 0, &threshold); |
Tim Bird | 0e95017 | 2010-02-25 15:36:43 -0800 | [diff] [blame] | 660 | if (ret < 0) |
| 661 | return 0; |
Wang Tianhong | 87abb3b | 2012-08-02 14:02:00 +0800 | [diff] [blame] | 662 | tracing_thresh = threshold * 1000; |
Tim Bird | 0e95017 | 2010-02-25 15:36:43 -0800 | [diff] [blame] | 663 | return 1; |
| 664 | } |
| 665 | __setup("tracing_thresh=", set_tracing_thresh); |
| 666 | |
Steven Rostedt | 57f50be | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 667 | unsigned long nsecs_to_usecs(unsigned long nsecs) |
| 668 | { |
| 669 | return nsecs / 1000; |
| 670 | } |
| 671 | |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 672 | /* These must match the bit postions in trace_iterator_flags */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 673 | static const char *trace_options[] = { |
| 674 | "print-parent", |
| 675 | "sym-offset", |
| 676 | "sym-addr", |
| 677 | "verbose", |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 678 | "raw", |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 679 | "hex", |
Ingo Molnar | cb0f12a | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 680 | "bin", |
Soeren Sandmann Pedersen | 2a2cc8f | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 681 | "block", |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 682 | "stacktrace", |
Ingo Molnar | 5e1607a | 2009-03-05 10:24:48 +0100 | [diff] [blame] | 683 | "trace_printk", |
Steven Rostedt | b2a866f | 2008-11-03 23:15:57 -0500 | [diff] [blame] | 684 | "ftrace_preempt", |
Steven Rostedt | 9f029e8 | 2008-11-12 15:24:24 -0500 | [diff] [blame] | 685 | "branch", |
Steven Rostedt | 12ef7d4 | 2008-11-12 17:52:38 -0500 | [diff] [blame] | 686 | "annotate", |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 687 | "userstacktrace", |
Török Edwin | b54d3de | 2008-11-22 13:28:48 +0200 | [diff] [blame] | 688 | "sym-userobj", |
Frederic Weisbecker | 66896a8 | 2008-12-13 20:18:13 +0100 | [diff] [blame] | 689 | "printk-msg-only", |
Frederic Weisbecker | c4a8e8b | 2009-02-02 20:29:21 -0200 | [diff] [blame] | 690 | "context-info", |
Steven Rostedt | c032ef64 | 2009-03-04 20:34:24 -0500 | [diff] [blame] | 691 | "latency-format", |
Steven Rostedt | be6f164 | 2009-03-24 11:06:24 -0400 | [diff] [blame] | 692 | "sleep-time", |
Steven Rostedt | a2a16d6 | 2009-03-24 23:17:58 -0400 | [diff] [blame] | 693 | "graph-time", |
Li Zefan | e870e9a | 2010-07-02 11:07:32 +0800 | [diff] [blame] | 694 | "record-cmd", |
David Sharp | 750912f | 2010-12-08 13:46:47 -0800 | [diff] [blame] | 695 | "overwrite", |
Steven Rostedt | cf30cf6 | 2011-06-14 22:44:07 -0400 | [diff] [blame] | 696 | "disable_on_free", |
Steven Rostedt | 77271ce | 2011-11-17 09:34:33 -0500 | [diff] [blame] | 697 | "irq-info", |
Mandeep Singh Baines | 5224c3a | 2012-09-07 18:12:19 -0700 | [diff] [blame] | 698 | "markers", |
Steven Rostedt (Red Hat) | 328df47 | 2013-03-14 12:10:40 -0400 | [diff] [blame] | 699 | "function-trace", |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 700 | NULL |
| 701 | }; |
| 702 | |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 703 | static struct { |
| 704 | u64 (*func)(void); |
| 705 | const char *name; |
David Sharp | 8be0709 | 2012-11-13 12:18:22 -0800 | [diff] [blame] | 706 | int in_ns; /* is this clock in nanoseconds? */ |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 707 | } trace_clocks[] = { |
David Sharp | 8be0709 | 2012-11-13 12:18:22 -0800 | [diff] [blame] | 708 | { trace_clock_local, "local", 1 }, |
| 709 | { trace_clock_global, "global", 1 }, |
| 710 | { trace_clock_counter, "counter", 0 }, |
Steven Rostedt (Red Hat) | 8aacf01 | 2013-03-14 13:13:45 -0400 | [diff] [blame] | 711 | { trace_clock_jiffies, "uptime", 1 }, |
Steven Rostedt (Red Hat) | 76f1191 | 2013-03-14 17:53:25 -0400 | [diff] [blame] | 712 | { trace_clock, "perf", 1 }, |
David Sharp | 8cbd9cc | 2012-11-13 12:18:21 -0800 | [diff] [blame] | 713 | ARCH_TRACE_CLOCKS |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 714 | }; |
| 715 | |
| 716 | int trace_clock_id; |
| 717 | |
jolsa@redhat.com | b63f39e | 2009-09-11 17:29:27 +0200 | [diff] [blame] | 718 | /* |
| 719 | * trace_parser_get_init - gets the buffer for trace parser |
| 720 | */ |
| 721 | int trace_parser_get_init(struct trace_parser *parser, int size) |
| 722 | { |
| 723 | memset(parser, 0, sizeof(*parser)); |
| 724 | |
| 725 | parser->buffer = kmalloc(size, GFP_KERNEL); |
| 726 | if (!parser->buffer) |
| 727 | return 1; |
| 728 | |
| 729 | parser->size = size; |
| 730 | return 0; |
| 731 | } |
| 732 | |
| 733 | /* |
| 734 | * trace_parser_put - frees the buffer for trace parser |
| 735 | */ |
| 736 | void trace_parser_put(struct trace_parser *parser) |
| 737 | { |
| 738 | kfree(parser->buffer); |
| 739 | } |
| 740 | |
| 741 | /* |
| 742 | * trace_get_user - reads the user input string separated by space |
| 743 | * (matched by isspace(ch)) |
| 744 | * |
| 745 | * For each string found the 'struct trace_parser' is updated, |
| 746 | * and the function returns. |
| 747 | * |
| 748 | * Returns number of bytes read. |
| 749 | * |
| 750 | * See kernel/trace/trace.h for 'struct trace_parser' details. |
| 751 | */ |
| 752 | int trace_get_user(struct trace_parser *parser, const char __user *ubuf, |
| 753 | size_t cnt, loff_t *ppos) |
| 754 | { |
| 755 | char ch; |
| 756 | size_t read = 0; |
| 757 | ssize_t ret; |
| 758 | |
| 759 | if (!*ppos) |
| 760 | trace_parser_clear(parser); |
| 761 | |
| 762 | ret = get_user(ch, ubuf++); |
| 763 | if (ret) |
| 764 | goto out; |
| 765 | |
| 766 | read++; |
| 767 | cnt--; |
| 768 | |
| 769 | /* |
| 770 | * The parser is not finished with the last write, |
| 771 | * continue reading the user input without skipping spaces. |
| 772 | */ |
| 773 | if (!parser->cont) { |
| 774 | /* skip white space */ |
| 775 | while (cnt && isspace(ch)) { |
| 776 | ret = get_user(ch, ubuf++); |
| 777 | if (ret) |
| 778 | goto out; |
| 779 | read++; |
| 780 | cnt--; |
| 781 | } |
| 782 | |
| 783 | /* only spaces were written */ |
| 784 | if (isspace(ch)) { |
| 785 | *ppos += read; |
| 786 | ret = read; |
| 787 | goto out; |
| 788 | } |
| 789 | |
| 790 | parser->idx = 0; |
| 791 | } |
| 792 | |
| 793 | /* read the non-space input */ |
| 794 | while (cnt && !isspace(ch)) { |
Li Zefan | 3c235a3 | 2009-09-22 13:51:54 +0800 | [diff] [blame] | 795 | if (parser->idx < parser->size - 1) |
jolsa@redhat.com | b63f39e | 2009-09-11 17:29:27 +0200 | [diff] [blame] | 796 | parser->buffer[parser->idx++] = ch; |
| 797 | else { |
| 798 | ret = -EINVAL; |
| 799 | goto out; |
| 800 | } |
| 801 | ret = get_user(ch, ubuf++); |
| 802 | if (ret) |
| 803 | goto out; |
| 804 | read++; |
| 805 | cnt--; |
| 806 | } |
| 807 | |
| 808 | /* We either got finished input or we have to wait for another call. */ |
| 809 | if (isspace(ch)) { |
| 810 | parser->buffer[parser->idx] = 0; |
| 811 | parser->cont = false; |
| 812 | } else { |
| 813 | parser->cont = true; |
| 814 | parser->buffer[parser->idx++] = ch; |
| 815 | } |
| 816 | |
| 817 | *ppos += read; |
| 818 | ret = read; |
| 819 | |
| 820 | out: |
| 821 | return ret; |
| 822 | } |
| 823 | |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 824 | ssize_t trace_seq_to_user(struct trace_seq *s, char __user *ubuf, size_t cnt) |
| 825 | { |
| 826 | int len; |
| 827 | int ret; |
| 828 | |
Steven Rostedt | 2dc5d12 | 2009-03-04 19:10:05 -0500 | [diff] [blame] | 829 | if (!cnt) |
| 830 | return 0; |
| 831 | |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 832 | if (s->len <= s->readpos) |
| 833 | return -EBUSY; |
| 834 | |
| 835 | len = s->len - s->readpos; |
| 836 | if (cnt > len) |
| 837 | cnt = len; |
| 838 | ret = copy_to_user(ubuf, s->buffer + s->readpos, cnt); |
Steven Rostedt | 2dc5d12 | 2009-03-04 19:10:05 -0500 | [diff] [blame] | 839 | if (ret == cnt) |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 840 | return -EFAULT; |
| 841 | |
Steven Rostedt | 2dc5d12 | 2009-03-04 19:10:05 -0500 | [diff] [blame] | 842 | cnt -= ret; |
| 843 | |
Steven Rostedt | e74da52 | 2009-03-04 20:31:11 -0500 | [diff] [blame] | 844 | s->readpos += cnt; |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 845 | return cnt; |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 846 | } |
| 847 | |
Dmitri Vorobiev | b8b9426 | 2009-03-22 19:11:11 +0200 | [diff] [blame] | 848 | 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] | 849 | { |
| 850 | int len; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 851 | |
| 852 | if (s->len <= s->readpos) |
| 853 | return -EBUSY; |
| 854 | |
| 855 | len = s->len - s->readpos; |
| 856 | if (cnt > len) |
| 857 | cnt = len; |
Dan Carpenter | 5a26c8f | 2012-04-20 09:31:45 +0300 | [diff] [blame] | 858 | memcpy(buf, s->buffer + s->readpos, cnt); |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 859 | |
Steven Rostedt | e74da52 | 2009-03-04 20:31:11 -0500 | [diff] [blame] | 860 | s->readpos += cnt; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 861 | return cnt; |
| 862 | } |
| 863 | |
Steven Rostedt | 5d4a9db | 2009-08-27 16:52:21 -0400 | [diff] [blame] | 864 | /* |
| 865 | * ftrace_max_lock is used to protect the swapping of buffers |
| 866 | * when taking a max snapshot. The buffers themselves are |
| 867 | * protected by per_cpu spinlocks. But the action of the swap |
| 868 | * needs its own lock. |
| 869 | * |
Thomas Gleixner | 445c895 | 2009-12-02 19:49:50 +0100 | [diff] [blame] | 870 | * This is defined as a arch_spinlock_t in order to help |
Steven Rostedt | 5d4a9db | 2009-08-27 16:52:21 -0400 | [diff] [blame] | 871 | * with performance when lockdep debugging is enabled. |
| 872 | * |
| 873 | * It is also used in other places outside the update_max_tr |
| 874 | * so it needs to be defined outside of the |
| 875 | * CONFIG_TRACER_MAX_TRACE. |
| 876 | */ |
Thomas Gleixner | 445c895 | 2009-12-02 19:49:50 +0100 | [diff] [blame] | 877 | static arch_spinlock_t ftrace_max_lock = |
Thomas Gleixner | edc35bd | 2009-12-03 12:38:57 +0100 | [diff] [blame] | 878 | (arch_spinlock_t)__ARCH_SPIN_LOCK_UNLOCKED; |
Steven Rostedt | 5d4a9db | 2009-08-27 16:52:21 -0400 | [diff] [blame] | 879 | |
Tim Bird | 0e95017 | 2010-02-25 15:36:43 -0800 | [diff] [blame] | 880 | unsigned long __read_mostly tracing_thresh; |
| 881 | |
Steven Rostedt | 5d4a9db | 2009-08-27 16:52:21 -0400 | [diff] [blame] | 882 | #ifdef CONFIG_TRACER_MAX_TRACE |
| 883 | unsigned long __read_mostly tracing_max_latency; |
Steven Rostedt | 5d4a9db | 2009-08-27 16:52:21 -0400 | [diff] [blame] | 884 | |
| 885 | /* |
| 886 | * Copy the new maximum trace into the separate maximum-trace |
| 887 | * structure. (this way the maximum trace is permanently saved, |
| 888 | * for later retrieval via /sys/kernel/debug/tracing/latency_trace) |
| 889 | */ |
| 890 | static void |
| 891 | __update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu) |
| 892 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 893 | struct trace_buffer *trace_buf = &tr->trace_buffer; |
| 894 | struct trace_buffer *max_buf = &tr->max_buffer; |
| 895 | struct trace_array_cpu *data = per_cpu_ptr(trace_buf->data, cpu); |
| 896 | 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] | 897 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 898 | max_buf->cpu = cpu; |
| 899 | max_buf->time_start = data->preempt_timestamp; |
Steven Rostedt | 5d4a9db | 2009-08-27 16:52:21 -0400 | [diff] [blame] | 900 | |
Steven Rostedt | 8248ac0 | 2009-09-02 12:27:41 -0400 | [diff] [blame] | 901 | max_data->saved_latency = tracing_max_latency; |
| 902 | max_data->critical_start = data->critical_start; |
| 903 | max_data->critical_end = data->critical_end; |
Steven Rostedt | 5d4a9db | 2009-08-27 16:52:21 -0400 | [diff] [blame] | 904 | |
Arnaldo Carvalho de Melo | 1acaa1b | 2010-03-05 18:23:50 -0300 | [diff] [blame] | 905 | memcpy(max_data->comm, tsk->comm, TASK_COMM_LEN); |
Steven Rostedt | 8248ac0 | 2009-09-02 12:27:41 -0400 | [diff] [blame] | 906 | max_data->pid = tsk->pid; |
Steven Rostedt (Red Hat) | f17a519 | 2013-05-30 21:10:37 -0400 | [diff] [blame] | 907 | /* |
| 908 | * If tsk == current, then use current_uid(), as that does not use |
| 909 | * RCU. The irq tracer can be called out of RCU scope. |
| 910 | */ |
| 911 | if (tsk == current) |
| 912 | max_data->uid = current_uid(); |
| 913 | else |
| 914 | max_data->uid = task_uid(tsk); |
| 915 | |
Steven Rostedt | 8248ac0 | 2009-09-02 12:27:41 -0400 | [diff] [blame] | 916 | max_data->nice = tsk->static_prio - 20 - MAX_RT_PRIO; |
| 917 | max_data->policy = tsk->policy; |
| 918 | max_data->rt_priority = tsk->rt_priority; |
Steven Rostedt | 5d4a9db | 2009-08-27 16:52:21 -0400 | [diff] [blame] | 919 | |
| 920 | /* record this tasks comm */ |
| 921 | tracing_record_cmdline(tsk); |
| 922 | } |
| 923 | |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 924 | /** |
| 925 | * update_max_tr - snapshot all trace buffers from global_trace to max_tr |
| 926 | * @tr: tracer |
| 927 | * @tsk: the task with the latency |
| 928 | * @cpu: The cpu that initiated the trace. |
| 929 | * |
| 930 | * Flip the buffers between the @tr and the max_tr and record information |
| 931 | * about which task was the cause of this latency. |
| 932 | */ |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 933 | void |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 934 | update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu) |
| 935 | { |
Steven Rostedt (Red Hat) | 2721e72 | 2013-03-12 11:32:32 -0400 | [diff] [blame] | 936 | struct ring_buffer *buf; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 937 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 938 | if (tr->stop_count) |
Steven Rostedt | b8de7bd1 | 2009-08-31 22:32:27 -0400 | [diff] [blame] | 939 | return; |
| 940 | |
Steven Rostedt | 4c11d7a | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 941 | WARN_ON_ONCE(!irqs_disabled()); |
Steven Rostedt | 34600f0 | 2013-01-22 13:35:11 -0500 | [diff] [blame] | 942 | |
Steven Rostedt (Red Hat) | 45ad21c | 2013-03-05 18:25:02 -0500 | [diff] [blame] | 943 | if (!tr->allocated_snapshot) { |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 944 | /* Only the nop tracer should hit this when disabling */ |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 945 | WARN_ON_ONCE(tr->current_trace != &nop_trace); |
KOSAKI Motohiro | ef710e1 | 2010-07-01 14:34:35 +0900 | [diff] [blame] | 946 | return; |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 947 | } |
Steven Rostedt | 34600f0 | 2013-01-22 13:35:11 -0500 | [diff] [blame] | 948 | |
Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 949 | arch_spin_lock(&ftrace_max_lock); |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 950 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 951 | buf = tr->trace_buffer.buffer; |
| 952 | tr->trace_buffer.buffer = tr->max_buffer.buffer; |
| 953 | tr->max_buffer.buffer = buf; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 954 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 955 | __update_max_tr(tr, tsk, cpu); |
Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 956 | arch_spin_unlock(&ftrace_max_lock); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 957 | } |
| 958 | |
| 959 | /** |
| 960 | * update_max_tr_single - only copy one trace over, and reset the rest |
| 961 | * @tr - tracer |
| 962 | * @tsk - task with the latency |
| 963 | * @cpu - the cpu of the buffer to copy. |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 964 | * |
| 965 | * 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] | 966 | */ |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 967 | void |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 968 | update_max_tr_single(struct trace_array *tr, struct task_struct *tsk, int cpu) |
| 969 | { |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 970 | int ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 971 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 972 | if (tr->stop_count) |
Steven Rostedt | b8de7bd1 | 2009-08-31 22:32:27 -0400 | [diff] [blame] | 973 | return; |
| 974 | |
Steven Rostedt | 4c11d7a | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 975 | WARN_ON_ONCE(!irqs_disabled()); |
Steven Rostedt | 6c24499 | 2013-04-29 20:08:14 -0400 | [diff] [blame] | 976 | if (!tr->allocated_snapshot) { |
Steven Rostedt (Red Hat) | 2930e04 | 2013-03-26 17:33:00 -0400 | [diff] [blame] | 977 | /* Only the nop tracer should hit this when disabling */ |
Linus Torvalds | 9e8529a | 2013-04-29 13:55:38 -0700 | [diff] [blame] | 978 | WARN_ON_ONCE(tr->current_trace != &nop_trace); |
KOSAKI Motohiro | ef710e1 | 2010-07-01 14:34:35 +0900 | [diff] [blame] | 979 | return; |
Steven Rostedt (Red Hat) | 2930e04 | 2013-03-26 17:33:00 -0400 | [diff] [blame] | 980 | } |
KOSAKI Motohiro | ef710e1 | 2010-07-01 14:34:35 +0900 | [diff] [blame] | 981 | |
Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 982 | arch_spin_lock(&ftrace_max_lock); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 983 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 984 | 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] | 985 | |
Steven Rostedt | e8165dbb | 2009-09-03 19:13:05 -0400 | [diff] [blame] | 986 | if (ret == -EBUSY) { |
| 987 | /* |
| 988 | * We failed to swap the buffer due to a commit taking |
| 989 | * place on this CPU. We fail to record, but we reset |
| 990 | * the max trace buffer (no one writes directly to it) |
| 991 | * and flag that it failed. |
| 992 | */ |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 993 | trace_array_printk_buf(tr->max_buffer.buffer, _THIS_IP_, |
Steven Rostedt | e8165dbb | 2009-09-03 19:13:05 -0400 | [diff] [blame] | 994 | "Failed to swap buffers due to commit in progress\n"); |
| 995 | } |
| 996 | |
Steven Rostedt | e8165dbb | 2009-09-03 19:13:05 -0400 | [diff] [blame] | 997 | WARN_ON_ONCE(ret && ret != -EAGAIN && ret != -EBUSY); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 998 | |
| 999 | __update_max_tr(tr, tsk, cpu); |
Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 1000 | arch_spin_unlock(&ftrace_max_lock); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1001 | } |
Steven Rostedt | 5d4a9db | 2009-08-27 16:52:21 -0400 | [diff] [blame] | 1002 | #endif /* CONFIG_TRACER_MAX_TRACE */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1003 | |
Steven Rostedt | 0d5c6e1 | 2012-11-01 20:54:21 -0400 | [diff] [blame] | 1004 | static void default_wait_pipe(struct trace_iterator *iter) |
| 1005 | { |
Steven Rostedt (Red Hat) | 1569345 | 2013-02-28 19:59:17 -0500 | [diff] [blame] | 1006 | /* Iterators are static, they should be filled or empty */ |
| 1007 | if (trace_buffer_iter(iter, iter->cpu_file)) |
| 1008 | return; |
Steven Rostedt | 0d5c6e1 | 2012-11-01 20:54:21 -0400 | [diff] [blame] | 1009 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1010 | ring_buffer_wait(iter->trace_buffer->buffer, iter->cpu_file); |
Steven Rostedt | 0d5c6e1 | 2012-11-01 20:54:21 -0400 | [diff] [blame] | 1011 | } |
| 1012 | |
Steven Rostedt (Red Hat) | f4e781c | 2013-03-07 11:10:56 -0500 | [diff] [blame] | 1013 | #ifdef CONFIG_FTRACE_STARTUP_TEST |
| 1014 | static int run_tracer_selftest(struct tracer *type) |
| 1015 | { |
| 1016 | struct trace_array *tr = &global_trace; |
| 1017 | struct tracer *saved_tracer = tr->current_trace; |
| 1018 | int ret; |
| 1019 | |
| 1020 | if (!type->selftest || tracing_selftest_disabled) |
| 1021 | return 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1022 | |
| 1023 | /* |
Steven Rostedt (Red Hat) | f4e781c | 2013-03-07 11:10:56 -0500 | [diff] [blame] | 1024 | * Run a selftest on this tracer. |
| 1025 | * Here we reset the trace buffer, and set the current |
| 1026 | * tracer to be this tracer. The tracer can then run some |
| 1027 | * internal tracing to verify that everything is in order. |
| 1028 | * If we fail, we do not register this tracer. |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 1029 | */ |
Steven Rostedt (Red Hat) | f4e781c | 2013-03-07 11:10:56 -0500 | [diff] [blame] | 1030 | tracing_reset_online_cpus(&tr->trace_buffer); |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 1031 | |
Steven Rostedt (Red Hat) | f4e781c | 2013-03-07 11:10:56 -0500 | [diff] [blame] | 1032 | tr->current_trace = type; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1033 | |
Steven Rostedt (Red Hat) | f4e781c | 2013-03-07 11:10:56 -0500 | [diff] [blame] | 1034 | #ifdef CONFIG_TRACER_MAX_TRACE |
| 1035 | if (type->use_max_tr) { |
| 1036 | /* If we expanded the buffers, make sure the max is expanded too */ |
| 1037 | if (ring_buffer_expanded) |
| 1038 | ring_buffer_resize(tr->max_buffer.buffer, trace_buf_size, |
| 1039 | RING_BUFFER_ALL_CPUS); |
| 1040 | tr->allocated_snapshot = true; |
| 1041 | } |
| 1042 | #endif |
| 1043 | |
| 1044 | /* the test is responsible for initializing and enabling */ |
| 1045 | pr_info("Testing tracer %s: ", type->name); |
| 1046 | ret = type->selftest(type, tr); |
| 1047 | /* the test is responsible for resetting too */ |
| 1048 | tr->current_trace = saved_tracer; |
| 1049 | if (ret) { |
| 1050 | printk(KERN_CONT "FAILED!\n"); |
| 1051 | /* Add the warning after printing 'FAILED' */ |
| 1052 | WARN_ON(1); |
| 1053 | return -1; |
| 1054 | } |
| 1055 | /* Only reset on passing, to avoid touching corrupted buffers */ |
| 1056 | tracing_reset_online_cpus(&tr->trace_buffer); |
| 1057 | |
| 1058 | #ifdef CONFIG_TRACER_MAX_TRACE |
| 1059 | if (type->use_max_tr) { |
| 1060 | tr->allocated_snapshot = false; |
| 1061 | |
| 1062 | /* Shrink the max buffer again */ |
| 1063 | if (ring_buffer_expanded) |
| 1064 | ring_buffer_resize(tr->max_buffer.buffer, 1, |
| 1065 | RING_BUFFER_ALL_CPUS); |
| 1066 | } |
| 1067 | #endif |
| 1068 | |
| 1069 | printk(KERN_CONT "PASSED\n"); |
| 1070 | return 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1071 | } |
Steven Rostedt (Red Hat) | f4e781c | 2013-03-07 11:10:56 -0500 | [diff] [blame] | 1072 | #else |
| 1073 | static inline int run_tracer_selftest(struct tracer *type) |
| 1074 | { |
| 1075 | return 0; |
| 1076 | } |
| 1077 | #endif /* CONFIG_FTRACE_STARTUP_TEST */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1078 | |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 1079 | /** |
| 1080 | * register_tracer - register a tracer with the ftrace system. |
| 1081 | * @type - the plugin for the tracer |
| 1082 | * |
| 1083 | * Register a new plugin tracer. |
| 1084 | */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1085 | int register_tracer(struct tracer *type) |
| 1086 | { |
| 1087 | struct tracer *t; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1088 | int ret = 0; |
| 1089 | |
| 1090 | if (!type->name) { |
| 1091 | pr_info("Tracer must have a name\n"); |
| 1092 | return -1; |
| 1093 | } |
| 1094 | |
Dan Carpenter | 24a461d | 2010-07-10 12:06:44 +0200 | [diff] [blame] | 1095 | if (strlen(type->name) >= MAX_TRACER_SIZE) { |
Li Zefan | ee6c2c1 | 2009-09-18 14:06:47 +0800 | [diff] [blame] | 1096 | pr_info("Tracer has a name longer than %d\n", MAX_TRACER_SIZE); |
| 1097 | return -1; |
| 1098 | } |
| 1099 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1100 | mutex_lock(&trace_types_lock); |
Ingo Molnar | 86fa2f6 | 2008-11-19 10:00:15 +0100 | [diff] [blame] | 1101 | |
Frederic Weisbecker | 8e1b82e | 2008-12-06 03:41:33 +0100 | [diff] [blame] | 1102 | tracing_selftest_running = true; |
| 1103 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1104 | for (t = trace_types; t; t = t->next) { |
| 1105 | if (strcmp(type->name, t->name) == 0) { |
| 1106 | /* already found */ |
Li Zefan | ee6c2c1 | 2009-09-18 14:06:47 +0800 | [diff] [blame] | 1107 | pr_info("Tracer %s already registered\n", |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1108 | type->name); |
| 1109 | ret = -1; |
| 1110 | goto out; |
| 1111 | } |
| 1112 | } |
| 1113 | |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 1114 | if (!type->set_flag) |
| 1115 | type->set_flag = &dummy_set_flag; |
| 1116 | if (!type->flags) |
| 1117 | type->flags = &dummy_tracer_flags; |
| 1118 | else |
| 1119 | if (!type->flags->opts) |
| 1120 | type->flags->opts = dummy_tracer_opt; |
Frederic Weisbecker | 6eaaa5d | 2009-02-11 02:25:00 +0100 | [diff] [blame] | 1121 | if (!type->wait_pipe) |
| 1122 | type->wait_pipe = default_wait_pipe; |
| 1123 | |
Steven Rostedt (Red Hat) | f4e781c | 2013-03-07 11:10:56 -0500 | [diff] [blame] | 1124 | ret = run_tracer_selftest(type); |
| 1125 | if (ret < 0) |
| 1126 | goto out; |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 1127 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1128 | type->next = trace_types; |
| 1129 | trace_types = type; |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 1130 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1131 | out: |
Frederic Weisbecker | 8e1b82e | 2008-12-06 03:41:33 +0100 | [diff] [blame] | 1132 | tracing_selftest_running = false; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1133 | mutex_unlock(&trace_types_lock); |
| 1134 | |
Steven Rostedt | dac7494 | 2009-02-05 01:13:38 -0500 | [diff] [blame] | 1135 | if (ret || !default_bootup_tracer) |
| 1136 | goto out_unlock; |
Steven Rostedt | b2821ae | 2009-02-02 21:38:32 -0500 | [diff] [blame] | 1137 | |
Li Zefan | ee6c2c1 | 2009-09-18 14:06:47 +0800 | [diff] [blame] | 1138 | if (strncmp(default_bootup_tracer, type->name, MAX_TRACER_SIZE)) |
Steven Rostedt | dac7494 | 2009-02-05 01:13:38 -0500 | [diff] [blame] | 1139 | goto out_unlock; |
| 1140 | |
| 1141 | printk(KERN_INFO "Starting tracer '%s'\n", type->name); |
| 1142 | /* Do we want this tracer to start on bootup? */ |
| 1143 | tracing_set_tracer(type->name); |
| 1144 | default_bootup_tracer = NULL; |
| 1145 | /* disable other selftests, since this will break it. */ |
Steven Rostedt (Red Hat) | 55034cd | 2013-03-07 22:48:09 -0500 | [diff] [blame] | 1146 | tracing_selftest_disabled = true; |
Steven Rostedt | dac7494 | 2009-02-05 01:13:38 -0500 | [diff] [blame] | 1147 | #ifdef CONFIG_FTRACE_STARTUP_TEST |
| 1148 | printk(KERN_INFO "Disabling FTRACE selftests due to running tracer '%s'\n", |
| 1149 | type->name); |
| 1150 | #endif |
| 1151 | |
| 1152 | out_unlock: |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1153 | return ret; |
| 1154 | } |
| 1155 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1156 | void tracing_reset(struct trace_buffer *buf, int cpu) |
Steven Rostedt | f633903 | 2009-09-04 12:35:16 -0400 | [diff] [blame] | 1157 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1158 | struct ring_buffer *buffer = buf->buffer; |
Steven Rostedt | f633903 | 2009-09-04 12:35:16 -0400 | [diff] [blame] | 1159 | |
Hiraku Toyooka | a541641 | 2012-12-19 16:02:34 +0900 | [diff] [blame] | 1160 | if (!buffer) |
| 1161 | return; |
| 1162 | |
Steven Rostedt | f633903 | 2009-09-04 12:35:16 -0400 | [diff] [blame] | 1163 | ring_buffer_record_disable(buffer); |
| 1164 | |
| 1165 | /* Make sure all commits have finished */ |
| 1166 | synchronize_sched(); |
Steven Rostedt | 6817968 | 2012-05-08 20:57:53 -0400 | [diff] [blame] | 1167 | ring_buffer_reset_cpu(buffer, cpu); |
Steven Rostedt | f633903 | 2009-09-04 12:35:16 -0400 | [diff] [blame] | 1168 | |
| 1169 | ring_buffer_record_enable(buffer); |
| 1170 | } |
| 1171 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1172 | void tracing_reset_online_cpus(struct trace_buffer *buf) |
Pekka J Enberg | 213cc06 | 2008-12-19 12:08:39 +0200 | [diff] [blame] | 1173 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1174 | struct ring_buffer *buffer = buf->buffer; |
Pekka J Enberg | 213cc06 | 2008-12-19 12:08:39 +0200 | [diff] [blame] | 1175 | int cpu; |
| 1176 | |
Hiraku Toyooka | a541641 | 2012-12-19 16:02:34 +0900 | [diff] [blame] | 1177 | if (!buffer) |
| 1178 | return; |
| 1179 | |
Steven Rostedt | 621968c | 2009-09-04 12:02:35 -0400 | [diff] [blame] | 1180 | ring_buffer_record_disable(buffer); |
| 1181 | |
| 1182 | /* Make sure all commits have finished */ |
| 1183 | synchronize_sched(); |
| 1184 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1185 | buf->time_start = ftrace_now(buf->cpu); |
Pekka J Enberg | 213cc06 | 2008-12-19 12:08:39 +0200 | [diff] [blame] | 1186 | |
| 1187 | for_each_online_cpu(cpu) |
Steven Rostedt | 6817968 | 2012-05-08 20:57:53 -0400 | [diff] [blame] | 1188 | ring_buffer_reset_cpu(buffer, cpu); |
Steven Rostedt | 621968c | 2009-09-04 12:02:35 -0400 | [diff] [blame] | 1189 | |
| 1190 | ring_buffer_record_enable(buffer); |
Pekka J Enberg | 213cc06 | 2008-12-19 12:08:39 +0200 | [diff] [blame] | 1191 | } |
| 1192 | |
Steven Rostedt | 9456f0f | 2009-05-06 21:54:09 -0400 | [diff] [blame] | 1193 | void tracing_reset_current(int cpu) |
| 1194 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1195 | tracing_reset(&global_trace.trace_buffer, cpu); |
Steven Rostedt | 9456f0f | 2009-05-06 21:54:09 -0400 | [diff] [blame] | 1196 | } |
| 1197 | |
Steven Rostedt (Red Hat) | 873c642 | 2013-03-04 23:26:06 -0500 | [diff] [blame] | 1198 | void tracing_reset_all_online_cpus(void) |
Steven Rostedt | 9456f0f | 2009-05-06 21:54:09 -0400 | [diff] [blame] | 1199 | { |
Steven Rostedt (Red Hat) | 873c642 | 2013-03-04 23:26:06 -0500 | [diff] [blame] | 1200 | struct trace_array *tr; |
| 1201 | |
| 1202 | mutex_lock(&trace_types_lock); |
| 1203 | list_for_each_entry(tr, &ftrace_trace_arrays, list) { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1204 | tracing_reset_online_cpus(&tr->trace_buffer); |
| 1205 | #ifdef CONFIG_TRACER_MAX_TRACE |
| 1206 | tracing_reset_online_cpus(&tr->max_buffer); |
| 1207 | #endif |
Steven Rostedt (Red Hat) | 873c642 | 2013-03-04 23:26:06 -0500 | [diff] [blame] | 1208 | } |
| 1209 | mutex_unlock(&trace_types_lock); |
Steven Rostedt | 9456f0f | 2009-05-06 21:54:09 -0400 | [diff] [blame] | 1210 | } |
| 1211 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1212 | #define SAVED_CMDLINES 128 |
Thomas Gleixner | 2c7eea4 | 2009-03-18 09:03:19 +0100 | [diff] [blame] | 1213 | #define NO_CMDLINE_MAP UINT_MAX |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1214 | static unsigned map_pid_to_cmdline[PID_MAX_DEFAULT+1]; |
| 1215 | static unsigned map_cmdline_to_pid[SAVED_CMDLINES]; |
| 1216 | static char saved_cmdlines[SAVED_CMDLINES][TASK_COMM_LEN]; |
| 1217 | static int cmdline_idx; |
Thomas Gleixner | edc35bd | 2009-12-03 12:38:57 +0100 | [diff] [blame] | 1218 | static arch_spinlock_t trace_cmdline_lock = __ARCH_SPIN_LOCK_UNLOCKED; |
Steven Rostedt | 25b0b44 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 1219 | |
Steven Rostedt | 25b0b44 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 1220 | /* temporary disable recording */ |
Hannes Eder | 4fd2735 | 2009-02-10 19:44:12 +0100 | [diff] [blame] | 1221 | static atomic_t trace_record_cmdline_disabled __read_mostly; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1222 | |
| 1223 | static void trace_init_cmdlines(void) |
| 1224 | { |
Thomas Gleixner | 2c7eea4 | 2009-03-18 09:03:19 +0100 | [diff] [blame] | 1225 | memset(&map_pid_to_cmdline, NO_CMDLINE_MAP, sizeof(map_pid_to_cmdline)); |
| 1226 | 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] | 1227 | cmdline_idx = 0; |
| 1228 | } |
| 1229 | |
Carsten Emde | b5130b1 | 2009-09-13 01:43:07 +0200 | [diff] [blame] | 1230 | int is_tracing_stopped(void) |
| 1231 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 1232 | return global_trace.stop_count; |
Carsten Emde | b5130b1 | 2009-09-13 01:43:07 +0200 | [diff] [blame] | 1233 | } |
| 1234 | |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1235 | /** |
Steven Rostedt | 69bb54e | 2008-11-21 12:59:38 -0500 | [diff] [blame] | 1236 | * ftrace_off_permanent - disable all ftrace code permanently |
| 1237 | * |
| 1238 | * This should only be called when a serious anomally has |
| 1239 | * been detected. This will turn off the function tracing, |
| 1240 | * ring buffers, and other tracing utilites. It takes no |
| 1241 | * locks and can be called from any context. |
| 1242 | */ |
| 1243 | void ftrace_off_permanent(void) |
| 1244 | { |
| 1245 | tracing_disabled = 1; |
| 1246 | ftrace_stop(); |
| 1247 | tracing_off_permanent(); |
| 1248 | } |
| 1249 | |
| 1250 | /** |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1251 | * tracing_start - quick start of the tracer |
| 1252 | * |
| 1253 | * If tracing is enabled but was stopped by tracing_stop, |
| 1254 | * this will start the tracer back up. |
| 1255 | */ |
| 1256 | void tracing_start(void) |
| 1257 | { |
| 1258 | struct ring_buffer *buffer; |
| 1259 | unsigned long flags; |
| 1260 | |
| 1261 | if (tracing_disabled) |
| 1262 | return; |
| 1263 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 1264 | raw_spin_lock_irqsave(&global_trace.start_lock, flags); |
| 1265 | if (--global_trace.stop_count) { |
| 1266 | if (global_trace.stop_count < 0) { |
Steven Rostedt | b06a830 | 2009-01-22 14:26:15 -0500 | [diff] [blame] | 1267 | /* Someone screwed up their debugging */ |
| 1268 | WARN_ON_ONCE(1); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 1269 | global_trace.stop_count = 0; |
Steven Rostedt | b06a830 | 2009-01-22 14:26:15 -0500 | [diff] [blame] | 1270 | } |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1271 | goto out; |
| 1272 | } |
| 1273 | |
Steven Rostedt | a2f8071 | 2010-03-12 19:56:00 -0500 | [diff] [blame] | 1274 | /* Prevent the buffers from switching */ |
| 1275 | arch_spin_lock(&ftrace_max_lock); |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1276 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1277 | buffer = global_trace.trace_buffer.buffer; |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1278 | if (buffer) |
| 1279 | ring_buffer_record_enable(buffer); |
| 1280 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1281 | #ifdef CONFIG_TRACER_MAX_TRACE |
| 1282 | buffer = global_trace.max_buffer.buffer; |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1283 | if (buffer) |
| 1284 | ring_buffer_record_enable(buffer); |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1285 | #endif |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1286 | |
Steven Rostedt | a2f8071 | 2010-03-12 19:56:00 -0500 | [diff] [blame] | 1287 | arch_spin_unlock(&ftrace_max_lock); |
| 1288 | |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1289 | ftrace_start(); |
| 1290 | out: |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 1291 | raw_spin_unlock_irqrestore(&global_trace.start_lock, flags); |
| 1292 | } |
| 1293 | |
| 1294 | static void tracing_start_tr(struct trace_array *tr) |
| 1295 | { |
| 1296 | struct ring_buffer *buffer; |
| 1297 | unsigned long flags; |
| 1298 | |
| 1299 | if (tracing_disabled) |
| 1300 | return; |
| 1301 | |
| 1302 | /* If global, we need to also start the max tracer */ |
| 1303 | if (tr->flags & TRACE_ARRAY_FL_GLOBAL) |
| 1304 | return tracing_start(); |
| 1305 | |
| 1306 | raw_spin_lock_irqsave(&tr->start_lock, flags); |
| 1307 | |
| 1308 | if (--tr->stop_count) { |
| 1309 | if (tr->stop_count < 0) { |
| 1310 | /* Someone screwed up their debugging */ |
| 1311 | WARN_ON_ONCE(1); |
| 1312 | tr->stop_count = 0; |
| 1313 | } |
| 1314 | goto out; |
| 1315 | } |
| 1316 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1317 | buffer = tr->trace_buffer.buffer; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 1318 | if (buffer) |
| 1319 | ring_buffer_record_enable(buffer); |
| 1320 | |
| 1321 | out: |
| 1322 | raw_spin_unlock_irqrestore(&tr->start_lock, flags); |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1323 | } |
| 1324 | |
| 1325 | /** |
| 1326 | * tracing_stop - quick stop of the tracer |
| 1327 | * |
| 1328 | * Light weight way to stop tracing. Use in conjunction with |
| 1329 | * tracing_start. |
| 1330 | */ |
| 1331 | void tracing_stop(void) |
| 1332 | { |
| 1333 | struct ring_buffer *buffer; |
| 1334 | unsigned long flags; |
| 1335 | |
| 1336 | ftrace_stop(); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 1337 | raw_spin_lock_irqsave(&global_trace.start_lock, flags); |
| 1338 | if (global_trace.stop_count++) |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1339 | goto out; |
| 1340 | |
Steven Rostedt | a2f8071 | 2010-03-12 19:56:00 -0500 | [diff] [blame] | 1341 | /* Prevent the buffers from switching */ |
| 1342 | arch_spin_lock(&ftrace_max_lock); |
| 1343 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1344 | buffer = global_trace.trace_buffer.buffer; |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1345 | if (buffer) |
| 1346 | ring_buffer_record_disable(buffer); |
| 1347 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1348 | #ifdef CONFIG_TRACER_MAX_TRACE |
| 1349 | buffer = global_trace.max_buffer.buffer; |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1350 | if (buffer) |
| 1351 | ring_buffer_record_disable(buffer); |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1352 | #endif |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1353 | |
Steven Rostedt | a2f8071 | 2010-03-12 19:56:00 -0500 | [diff] [blame] | 1354 | arch_spin_unlock(&ftrace_max_lock); |
| 1355 | |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1356 | out: |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 1357 | raw_spin_unlock_irqrestore(&global_trace.start_lock, flags); |
| 1358 | } |
| 1359 | |
| 1360 | static void tracing_stop_tr(struct trace_array *tr) |
| 1361 | { |
| 1362 | struct ring_buffer *buffer; |
| 1363 | unsigned long flags; |
| 1364 | |
| 1365 | /* If global, we need to also stop the max tracer */ |
| 1366 | if (tr->flags & TRACE_ARRAY_FL_GLOBAL) |
| 1367 | return tracing_stop(); |
| 1368 | |
| 1369 | raw_spin_lock_irqsave(&tr->start_lock, flags); |
| 1370 | if (tr->stop_count++) |
| 1371 | goto out; |
| 1372 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1373 | buffer = tr->trace_buffer.buffer; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 1374 | if (buffer) |
| 1375 | ring_buffer_record_disable(buffer); |
| 1376 | |
| 1377 | out: |
| 1378 | raw_spin_unlock_irqrestore(&tr->start_lock, flags); |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1379 | } |
| 1380 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1381 | void trace_stop_cmdline_recording(void); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1382 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1383 | static void trace_save_cmdline(struct task_struct *tsk) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1384 | { |
Carsten Emde | a635cf0 | 2009-03-18 09:00:41 +0100 | [diff] [blame] | 1385 | unsigned pid, idx; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1386 | |
| 1387 | if (!tsk->pid || unlikely(tsk->pid > PID_MAX_DEFAULT)) |
| 1388 | return; |
| 1389 | |
| 1390 | /* |
| 1391 | * It's not the end of the world if we don't get |
| 1392 | * the lock, but we also don't want to spin |
| 1393 | * nor do we want to disable interrupts, |
| 1394 | * so if we miss here, then better luck next time. |
| 1395 | */ |
Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 1396 | if (!arch_spin_trylock(&trace_cmdline_lock)) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1397 | return; |
| 1398 | |
| 1399 | idx = map_pid_to_cmdline[tsk->pid]; |
Thomas Gleixner | 2c7eea4 | 2009-03-18 09:03:19 +0100 | [diff] [blame] | 1400 | if (idx == NO_CMDLINE_MAP) { |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1401 | idx = (cmdline_idx + 1) % SAVED_CMDLINES; |
| 1402 | |
Carsten Emde | a635cf0 | 2009-03-18 09:00:41 +0100 | [diff] [blame] | 1403 | /* |
| 1404 | * Check whether the cmdline buffer at idx has a pid |
| 1405 | * mapped. We are going to overwrite that entry so we |
| 1406 | * need to clear the map_pid_to_cmdline. Otherwise we |
| 1407 | * would read the new comm for the old pid. |
| 1408 | */ |
| 1409 | pid = map_cmdline_to_pid[idx]; |
| 1410 | if (pid != NO_CMDLINE_MAP) |
| 1411 | map_pid_to_cmdline[pid] = NO_CMDLINE_MAP; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1412 | |
Carsten Emde | a635cf0 | 2009-03-18 09:00:41 +0100 | [diff] [blame] | 1413 | map_cmdline_to_pid[idx] = tsk->pid; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1414 | map_pid_to_cmdline[tsk->pid] = idx; |
| 1415 | |
| 1416 | cmdline_idx = idx; |
| 1417 | } |
| 1418 | |
| 1419 | memcpy(&saved_cmdlines[idx], tsk->comm, TASK_COMM_LEN); |
| 1420 | |
Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 1421 | arch_spin_unlock(&trace_cmdline_lock); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1422 | } |
| 1423 | |
Steven Rostedt | 4ca53085 | 2009-03-16 19:20:15 -0400 | [diff] [blame] | 1424 | void trace_find_cmdline(int pid, char comm[]) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1425 | { |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1426 | unsigned map; |
| 1427 | |
Steven Rostedt | 4ca53085 | 2009-03-16 19:20:15 -0400 | [diff] [blame] | 1428 | if (!pid) { |
| 1429 | strcpy(comm, "<idle>"); |
| 1430 | return; |
| 1431 | } |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1432 | |
Steven Rostedt | 74bf407 | 2010-01-25 15:11:53 -0500 | [diff] [blame] | 1433 | if (WARN_ON_ONCE(pid < 0)) { |
| 1434 | strcpy(comm, "<XXX>"); |
| 1435 | return; |
| 1436 | } |
| 1437 | |
Steven Rostedt | 4ca53085 | 2009-03-16 19:20:15 -0400 | [diff] [blame] | 1438 | if (pid > PID_MAX_DEFAULT) { |
| 1439 | strcpy(comm, "<...>"); |
| 1440 | return; |
| 1441 | } |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1442 | |
Heiko Carstens | 5b6045a | 2009-05-26 17:28:02 +0200 | [diff] [blame] | 1443 | preempt_disable(); |
Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 1444 | arch_spin_lock(&trace_cmdline_lock); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1445 | map = map_pid_to_cmdline[pid]; |
Thomas Gleixner | 50d8875 | 2009-03-18 08:58:44 +0100 | [diff] [blame] | 1446 | if (map != NO_CMDLINE_MAP) |
| 1447 | strcpy(comm, saved_cmdlines[map]); |
| 1448 | else |
| 1449 | strcpy(comm, "<...>"); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1450 | |
Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 1451 | arch_spin_unlock(&trace_cmdline_lock); |
Heiko Carstens | 5b6045a | 2009-05-26 17:28:02 +0200 | [diff] [blame] | 1452 | preempt_enable(); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1453 | } |
| 1454 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1455 | void tracing_record_cmdline(struct task_struct *tsk) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1456 | { |
Steven Rostedt | 0fb9656 | 2012-05-11 14:25:30 -0400 | [diff] [blame] | 1457 | if (atomic_read(&trace_record_cmdline_disabled) || !tracing_is_on()) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1458 | return; |
| 1459 | |
Steven Rostedt | 7ffbd48 | 2012-10-11 12:14:25 -0400 | [diff] [blame] | 1460 | if (!__this_cpu_read(trace_cmdline_save)) |
| 1461 | return; |
| 1462 | |
| 1463 | __this_cpu_write(trace_cmdline_save, false); |
| 1464 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1465 | trace_save_cmdline(tsk); |
| 1466 | } |
| 1467 | |
Pekka Paalanen | 45dcd8b | 2008-09-16 21:56:41 +0300 | [diff] [blame] | 1468 | void |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 1469 | tracing_generic_entry_update(struct trace_entry *entry, unsigned long flags, |
| 1470 | int pc) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1471 | { |
| 1472 | struct task_struct *tsk = current; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1473 | |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1474 | entry->preempt_count = pc & 0xff; |
| 1475 | entry->pid = (tsk) ? tsk->pid : 0; |
| 1476 | entry->flags = |
Steven Rostedt | 9244489 | 2008-10-24 09:42:59 -0400 | [diff] [blame] | 1477 | #ifdef CONFIG_TRACE_IRQFLAGS_SUPPORT |
Steven Rostedt | 2e2ca15 | 2008-08-01 12:26:40 -0400 | [diff] [blame] | 1478 | (irqs_disabled_flags(flags) ? TRACE_FLAG_IRQS_OFF : 0) | |
Steven Rostedt | 9244489 | 2008-10-24 09:42:59 -0400 | [diff] [blame] | 1479 | #else |
| 1480 | TRACE_FLAG_IRQS_NOSUPPORT | |
| 1481 | #endif |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1482 | ((pc & HARDIRQ_MASK) ? TRACE_FLAG_HARDIRQ : 0) | |
| 1483 | ((pc & SOFTIRQ_MASK) ? TRACE_FLAG_SOFTIRQ : 0) | |
| 1484 | (need_resched() ? TRACE_FLAG_NEED_RESCHED : 0); |
| 1485 | } |
Frederic Weisbecker | f413cdb | 2009-08-07 01:25:54 +0200 | [diff] [blame] | 1486 | EXPORT_SYMBOL_GPL(tracing_generic_entry_update); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1487 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1488 | struct ring_buffer_event * |
| 1489 | trace_buffer_lock_reserve(struct ring_buffer *buffer, |
| 1490 | int type, |
| 1491 | unsigned long len, |
| 1492 | unsigned long flags, int pc) |
Arnaldo Carvalho de Melo | 51a763d | 2009-02-05 16:14:13 -0200 | [diff] [blame] | 1493 | { |
| 1494 | struct ring_buffer_event *event; |
| 1495 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1496 | event = ring_buffer_lock_reserve(buffer, len); |
Arnaldo Carvalho de Melo | 51a763d | 2009-02-05 16:14:13 -0200 | [diff] [blame] | 1497 | if (event != NULL) { |
| 1498 | struct trace_entry *ent = ring_buffer_event_data(event); |
| 1499 | |
| 1500 | tracing_generic_entry_update(ent, flags, pc); |
| 1501 | ent->type = type; |
| 1502 | } |
| 1503 | |
| 1504 | return event; |
| 1505 | } |
Arnaldo Carvalho de Melo | 51a763d | 2009-02-05 16:14:13 -0200 | [diff] [blame] | 1506 | |
Steven Rostedt | 7ffbd48 | 2012-10-11 12:14:25 -0400 | [diff] [blame] | 1507 | void |
| 1508 | __buffer_unlock_commit(struct ring_buffer *buffer, struct ring_buffer_event *event) |
| 1509 | { |
| 1510 | __this_cpu_write(trace_cmdline_save, true); |
| 1511 | ring_buffer_unlock_commit(buffer, event); |
| 1512 | } |
| 1513 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1514 | static inline void |
| 1515 | __trace_buffer_unlock_commit(struct ring_buffer *buffer, |
| 1516 | struct ring_buffer_event *event, |
Steven Rostedt | 0d5c6e1 | 2012-11-01 20:54:21 -0400 | [diff] [blame] | 1517 | unsigned long flags, int pc) |
Arnaldo Carvalho de Melo | 51a763d | 2009-02-05 16:14:13 -0200 | [diff] [blame] | 1518 | { |
Steven Rostedt | 7ffbd48 | 2012-10-11 12:14:25 -0400 | [diff] [blame] | 1519 | __buffer_unlock_commit(buffer, event); |
Arnaldo Carvalho de Melo | 51a763d | 2009-02-05 16:14:13 -0200 | [diff] [blame] | 1520 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1521 | ftrace_trace_stack(buffer, flags, 6, pc); |
| 1522 | ftrace_trace_userstack(buffer, flags, pc); |
Frederic Weisbecker | 07edf71 | 2009-03-22 23:10:46 +0100 | [diff] [blame] | 1523 | } |
| 1524 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1525 | void trace_buffer_unlock_commit(struct ring_buffer *buffer, |
| 1526 | struct ring_buffer_event *event, |
| 1527 | unsigned long flags, int pc) |
Frederic Weisbecker | 07edf71 | 2009-03-22 23:10:46 +0100 | [diff] [blame] | 1528 | { |
Steven Rostedt | 0d5c6e1 | 2012-11-01 20:54:21 -0400 | [diff] [blame] | 1529 | __trace_buffer_unlock_commit(buffer, event, flags, pc); |
Arnaldo Carvalho de Melo | 51a763d | 2009-02-05 16:14:13 -0200 | [diff] [blame] | 1530 | } |
Steven Rostedt | 0d5c6e1 | 2012-11-01 20:54:21 -0400 | [diff] [blame] | 1531 | EXPORT_SYMBOL_GPL(trace_buffer_unlock_commit); |
Arnaldo Carvalho de Melo | 51a763d | 2009-02-05 16:14:13 -0200 | [diff] [blame] | 1532 | |
Steven Rostedt | ef5580d | 2009-02-27 19:38:04 -0500 | [diff] [blame] | 1533 | struct ring_buffer_event * |
Steven Rostedt | ccb469a | 2012-08-02 10:32:10 -0400 | [diff] [blame] | 1534 | trace_event_buffer_lock_reserve(struct ring_buffer **current_rb, |
| 1535 | struct ftrace_event_file *ftrace_file, |
| 1536 | int type, unsigned long len, |
| 1537 | unsigned long flags, int pc) |
| 1538 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1539 | *current_rb = ftrace_file->tr->trace_buffer.buffer; |
Steven Rostedt | ccb469a | 2012-08-02 10:32:10 -0400 | [diff] [blame] | 1540 | return trace_buffer_lock_reserve(*current_rb, |
| 1541 | type, len, flags, pc); |
| 1542 | } |
| 1543 | EXPORT_SYMBOL_GPL(trace_event_buffer_lock_reserve); |
| 1544 | |
| 1545 | struct ring_buffer_event * |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1546 | trace_current_buffer_lock_reserve(struct ring_buffer **current_rb, |
| 1547 | int type, unsigned long len, |
Steven Rostedt | ef5580d | 2009-02-27 19:38:04 -0500 | [diff] [blame] | 1548 | unsigned long flags, int pc) |
| 1549 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1550 | *current_rb = global_trace.trace_buffer.buffer; |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1551 | return trace_buffer_lock_reserve(*current_rb, |
Steven Rostedt | ef5580d | 2009-02-27 19:38:04 -0500 | [diff] [blame] | 1552 | type, len, flags, pc); |
| 1553 | } |
Steven Rostedt | 94487d6 | 2009-05-05 19:22:53 -0400 | [diff] [blame] | 1554 | EXPORT_SYMBOL_GPL(trace_current_buffer_lock_reserve); |
Steven Rostedt | ef5580d | 2009-02-27 19:38:04 -0500 | [diff] [blame] | 1555 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1556 | void trace_current_buffer_unlock_commit(struct ring_buffer *buffer, |
| 1557 | struct ring_buffer_event *event, |
Steven Rostedt | ef5580d | 2009-02-27 19:38:04 -0500 | [diff] [blame] | 1558 | unsigned long flags, int pc) |
| 1559 | { |
Steven Rostedt | 0d5c6e1 | 2012-11-01 20:54:21 -0400 | [diff] [blame] | 1560 | __trace_buffer_unlock_commit(buffer, event, flags, pc); |
Frederic Weisbecker | 07edf71 | 2009-03-22 23:10:46 +0100 | [diff] [blame] | 1561 | } |
Steven Rostedt | 94487d6 | 2009-05-05 19:22:53 -0400 | [diff] [blame] | 1562 | EXPORT_SYMBOL_GPL(trace_current_buffer_unlock_commit); |
Frederic Weisbecker | 07edf71 | 2009-03-22 23:10:46 +0100 | [diff] [blame] | 1563 | |
Steven Rostedt | 0d5c6e1 | 2012-11-01 20:54:21 -0400 | [diff] [blame] | 1564 | void trace_buffer_unlock_commit_regs(struct ring_buffer *buffer, |
| 1565 | struct ring_buffer_event *event, |
| 1566 | unsigned long flags, int pc, |
| 1567 | struct pt_regs *regs) |
Masami Hiramatsu | 1fd8df2 | 2011-06-08 16:09:34 +0900 | [diff] [blame] | 1568 | { |
Steven Rostedt | 7ffbd48 | 2012-10-11 12:14:25 -0400 | [diff] [blame] | 1569 | __buffer_unlock_commit(buffer, event); |
Masami Hiramatsu | 1fd8df2 | 2011-06-08 16:09:34 +0900 | [diff] [blame] | 1570 | |
| 1571 | ftrace_trace_stack_regs(buffer, flags, 0, pc, regs); |
| 1572 | ftrace_trace_userstack(buffer, flags, pc); |
| 1573 | } |
Steven Rostedt | 0d5c6e1 | 2012-11-01 20:54:21 -0400 | [diff] [blame] | 1574 | EXPORT_SYMBOL_GPL(trace_buffer_unlock_commit_regs); |
Masami Hiramatsu | 1fd8df2 | 2011-06-08 16:09:34 +0900 | [diff] [blame] | 1575 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1576 | void trace_current_buffer_discard_commit(struct ring_buffer *buffer, |
| 1577 | struct ring_buffer_event *event) |
Steven Rostedt | 77d9f46 | 2009-04-02 01:16:59 -0400 | [diff] [blame] | 1578 | { |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1579 | ring_buffer_discard_commit(buffer, event); |
Steven Rostedt | ef5580d | 2009-02-27 19:38:04 -0500 | [diff] [blame] | 1580 | } |
Steven Rostedt | 12acd47 | 2009-04-17 16:01:56 -0400 | [diff] [blame] | 1581 | EXPORT_SYMBOL_GPL(trace_current_buffer_discard_commit); |
Steven Rostedt | ef5580d | 2009-02-27 19:38:04 -0500 | [diff] [blame] | 1582 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1583 | void |
Arnaldo Carvalho de Melo | 7be4215 | 2009-02-05 01:13:37 -0500 | [diff] [blame] | 1584 | trace_function(struct trace_array *tr, |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 1585 | unsigned long ip, unsigned long parent_ip, unsigned long flags, |
| 1586 | int pc) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1587 | { |
Tom Zanussi | e1112b4 | 2009-03-31 00:48:49 -0500 | [diff] [blame] | 1588 | struct ftrace_event_call *call = &event_function; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1589 | struct ring_buffer *buffer = tr->trace_buffer.buffer; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1590 | struct ring_buffer_event *event; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1591 | struct ftrace_entry *entry; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1592 | |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 1593 | /* If we are reading the ring buffer, don't trace */ |
Rusty Russell | dd17c8f | 2009-10-29 22:34:15 +0900 | [diff] [blame] | 1594 | if (unlikely(__this_cpu_read(ftrace_cpu_disabled))) |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 1595 | return; |
| 1596 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1597 | event = trace_buffer_lock_reserve(buffer, TRACE_FN, sizeof(*entry), |
Arnaldo Carvalho de Melo | 51a763d | 2009-02-05 16:14:13 -0200 | [diff] [blame] | 1598 | flags, pc); |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1599 | if (!event) |
| 1600 | return; |
| 1601 | entry = ring_buffer_event_data(event); |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1602 | entry->ip = ip; |
| 1603 | entry->parent_ip = parent_ip; |
Tom Zanussi | e1112b4 | 2009-03-31 00:48:49 -0500 | [diff] [blame] | 1604 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1605 | if (!filter_check_discard(call, entry, buffer, event)) |
Steven Rostedt | 7ffbd48 | 2012-10-11 12:14:25 -0400 | [diff] [blame] | 1606 | __buffer_unlock_commit(buffer, event); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1607 | } |
| 1608 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1609 | void |
Ingo Molnar | 2e0f576 | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 1610 | ftrace(struct trace_array *tr, struct trace_array_cpu *data, |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 1611 | unsigned long ip, unsigned long parent_ip, unsigned long flags, |
| 1612 | int pc) |
Ingo Molnar | 2e0f576 | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 1613 | { |
| 1614 | if (likely(!atomic_read(&data->disabled))) |
Arnaldo Carvalho de Melo | 7be4215 | 2009-02-05 01:13:37 -0500 | [diff] [blame] | 1615 | trace_function(tr, ip, parent_ip, flags, pc); |
Ingo Molnar | 2e0f576 | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 1616 | } |
| 1617 | |
Frederic Weisbecker | c0a0d0d | 2009-07-29 17:51:13 +0200 | [diff] [blame] | 1618 | #ifdef CONFIG_STACKTRACE |
Steven Rostedt | 4a9bd3f | 2011-07-14 16:36:53 -0400 | [diff] [blame] | 1619 | |
| 1620 | #define FTRACE_STACK_MAX_ENTRIES (PAGE_SIZE / sizeof(unsigned long)) |
| 1621 | struct ftrace_stack { |
| 1622 | unsigned long calls[FTRACE_STACK_MAX_ENTRIES]; |
| 1623 | }; |
| 1624 | |
| 1625 | static DEFINE_PER_CPU(struct ftrace_stack, ftrace_stack); |
| 1626 | static DEFINE_PER_CPU(int, ftrace_stack_reserve); |
| 1627 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1628 | static void __ftrace_trace_stack(struct ring_buffer *buffer, |
Steven Rostedt | 5361499 | 2009-01-15 19:12:40 -0500 | [diff] [blame] | 1629 | unsigned long flags, |
Masami Hiramatsu | 1fd8df2 | 2011-06-08 16:09:34 +0900 | [diff] [blame] | 1630 | int skip, int pc, struct pt_regs *regs) |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1631 | { |
Tom Zanussi | e1112b4 | 2009-03-31 00:48:49 -0500 | [diff] [blame] | 1632 | struct ftrace_event_call *call = &event_kernel_stack; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1633 | struct ring_buffer_event *event; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1634 | struct stack_entry *entry; |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1635 | struct stack_trace trace; |
Steven Rostedt | 4a9bd3f | 2011-07-14 16:36:53 -0400 | [diff] [blame] | 1636 | int use_stack; |
| 1637 | int size = FTRACE_STACK_ENTRIES; |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1638 | |
| 1639 | trace.nr_entries = 0; |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1640 | trace.skip = skip; |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1641 | |
Steven Rostedt | 4a9bd3f | 2011-07-14 16:36:53 -0400 | [diff] [blame] | 1642 | /* |
| 1643 | * Since events can happen in NMIs there's no safe way to |
| 1644 | * use the per cpu ftrace_stacks. We reserve it and if an interrupt |
| 1645 | * or NMI comes in, it will just have to use the default |
| 1646 | * FTRACE_STACK_SIZE. |
| 1647 | */ |
| 1648 | preempt_disable_notrace(); |
| 1649 | |
Shan Wei | 8214652 | 2012-11-19 13:21:01 +0800 | [diff] [blame] | 1650 | use_stack = __this_cpu_inc_return(ftrace_stack_reserve); |
Steven Rostedt | 4a9bd3f | 2011-07-14 16:36:53 -0400 | [diff] [blame] | 1651 | /* |
| 1652 | * We don't need any atomic variables, just a barrier. |
| 1653 | * If an interrupt comes in, we don't care, because it would |
| 1654 | * have exited and put the counter back to what we want. |
| 1655 | * We just need a barrier to keep gcc from moving things |
| 1656 | * around. |
| 1657 | */ |
| 1658 | barrier(); |
| 1659 | if (use_stack == 1) { |
| 1660 | trace.entries = &__get_cpu_var(ftrace_stack).calls[0]; |
| 1661 | trace.max_entries = FTRACE_STACK_MAX_ENTRIES; |
| 1662 | |
| 1663 | if (regs) |
| 1664 | save_stack_trace_regs(regs, &trace); |
| 1665 | else |
| 1666 | save_stack_trace(&trace); |
| 1667 | |
| 1668 | if (trace.nr_entries > size) |
| 1669 | size = trace.nr_entries; |
| 1670 | } else |
| 1671 | /* From now on, use_stack is a boolean */ |
| 1672 | use_stack = 0; |
| 1673 | |
| 1674 | size *= sizeof(unsigned long); |
| 1675 | |
| 1676 | event = trace_buffer_lock_reserve(buffer, TRACE_STACK, |
| 1677 | sizeof(*entry) + size, flags, pc); |
| 1678 | if (!event) |
| 1679 | goto out; |
| 1680 | entry = ring_buffer_event_data(event); |
| 1681 | |
| 1682 | memset(&entry->caller, 0, size); |
| 1683 | |
| 1684 | if (use_stack) |
| 1685 | memcpy(&entry->caller, trace.entries, |
| 1686 | trace.nr_entries * sizeof(unsigned long)); |
| 1687 | else { |
| 1688 | trace.max_entries = FTRACE_STACK_ENTRIES; |
| 1689 | trace.entries = entry->caller; |
| 1690 | if (regs) |
| 1691 | save_stack_trace_regs(regs, &trace); |
| 1692 | else |
| 1693 | save_stack_trace(&trace); |
| 1694 | } |
| 1695 | |
| 1696 | entry->size = trace.nr_entries; |
| 1697 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1698 | if (!filter_check_discard(call, entry, buffer, event)) |
Steven Rostedt | 7ffbd48 | 2012-10-11 12:14:25 -0400 | [diff] [blame] | 1699 | __buffer_unlock_commit(buffer, event); |
Steven Rostedt | 4a9bd3f | 2011-07-14 16:36:53 -0400 | [diff] [blame] | 1700 | |
| 1701 | out: |
| 1702 | /* Again, don't let gcc optimize things here */ |
| 1703 | barrier(); |
Shan Wei | 8214652 | 2012-11-19 13:21:01 +0800 | [diff] [blame] | 1704 | __this_cpu_dec(ftrace_stack_reserve); |
Steven Rostedt | 4a9bd3f | 2011-07-14 16:36:53 -0400 | [diff] [blame] | 1705 | preempt_enable_notrace(); |
| 1706 | |
Ingo Molnar | f0a920d | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 1707 | } |
| 1708 | |
Masami Hiramatsu | 1fd8df2 | 2011-06-08 16:09:34 +0900 | [diff] [blame] | 1709 | void ftrace_trace_stack_regs(struct ring_buffer *buffer, unsigned long flags, |
| 1710 | int skip, int pc, struct pt_regs *regs) |
| 1711 | { |
| 1712 | if (!(trace_flags & TRACE_ITER_STACKTRACE)) |
| 1713 | return; |
| 1714 | |
| 1715 | __ftrace_trace_stack(buffer, flags, skip, pc, regs); |
| 1716 | } |
| 1717 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1718 | void ftrace_trace_stack(struct ring_buffer *buffer, unsigned long flags, |
| 1719 | int skip, int pc) |
Steven Rostedt | 5361499 | 2009-01-15 19:12:40 -0500 | [diff] [blame] | 1720 | { |
| 1721 | if (!(trace_flags & TRACE_ITER_STACKTRACE)) |
| 1722 | return; |
| 1723 | |
Masami Hiramatsu | 1fd8df2 | 2011-06-08 16:09:34 +0900 | [diff] [blame] | 1724 | __ftrace_trace_stack(buffer, flags, skip, pc, NULL); |
Steven Rostedt | 5361499 | 2009-01-15 19:12:40 -0500 | [diff] [blame] | 1725 | } |
| 1726 | |
Frederic Weisbecker | c0a0d0d | 2009-07-29 17:51:13 +0200 | [diff] [blame] | 1727 | void __trace_stack(struct trace_array *tr, unsigned long flags, int skip, |
| 1728 | int pc) |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 1729 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1730 | __ftrace_trace_stack(tr->trace_buffer.buffer, flags, skip, pc, NULL); |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 1731 | } |
| 1732 | |
Steven Rostedt | 0388938 | 2009-12-11 09:48:22 -0500 | [diff] [blame] | 1733 | /** |
| 1734 | * 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] | 1735 | * @skip: Number of functions to skip (helper handlers) |
Steven Rostedt | 0388938 | 2009-12-11 09:48:22 -0500 | [diff] [blame] | 1736 | */ |
Steven Rostedt (Red Hat) | c142be8 | 2013-03-13 09:55:57 -0400 | [diff] [blame] | 1737 | void trace_dump_stack(int skip) |
Steven Rostedt | 0388938 | 2009-12-11 09:48:22 -0500 | [diff] [blame] | 1738 | { |
| 1739 | unsigned long flags; |
| 1740 | |
| 1741 | if (tracing_disabled || tracing_selftest_running) |
Steven Rostedt | e36c545 | 2009-12-14 15:58:33 -0500 | [diff] [blame] | 1742 | return; |
Steven Rostedt | 0388938 | 2009-12-11 09:48:22 -0500 | [diff] [blame] | 1743 | |
| 1744 | local_save_flags(flags); |
| 1745 | |
Steven Rostedt (Red Hat) | c142be8 | 2013-03-13 09:55:57 -0400 | [diff] [blame] | 1746 | /* |
| 1747 | * Skip 3 more, seems to get us at the caller of |
| 1748 | * this function. |
| 1749 | */ |
| 1750 | skip += 3; |
| 1751 | __ftrace_trace_stack(global_trace.trace_buffer.buffer, |
| 1752 | flags, skip, preempt_count(), NULL); |
Steven Rostedt | 0388938 | 2009-12-11 09:48:22 -0500 | [diff] [blame] | 1753 | } |
| 1754 | |
Steven Rostedt | 91e86e5 | 2010-11-10 12:56:12 +0100 | [diff] [blame] | 1755 | static DEFINE_PER_CPU(int, user_stack_count); |
| 1756 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1757 | void |
| 1758 | 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] | 1759 | { |
Tom Zanussi | e1112b4 | 2009-03-31 00:48:49 -0500 | [diff] [blame] | 1760 | struct ftrace_event_call *call = &event_user_stack; |
Török Edwin | 8d7c6a9 | 2008-11-23 12:39:06 +0200 | [diff] [blame] | 1761 | struct ring_buffer_event *event; |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 1762 | struct userstack_entry *entry; |
| 1763 | struct stack_trace trace; |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 1764 | |
| 1765 | if (!(trace_flags & TRACE_ITER_USERSTACKTRACE)) |
| 1766 | return; |
| 1767 | |
Steven Rostedt | b634587 | 2010-03-12 20:03:30 -0500 | [diff] [blame] | 1768 | /* |
| 1769 | * NMIs can not handle page faults, even with fix ups. |
| 1770 | * The save user stack can (and often does) fault. |
| 1771 | */ |
| 1772 | if (unlikely(in_nmi())) |
| 1773 | return; |
| 1774 | |
Steven Rostedt | 91e86e5 | 2010-11-10 12:56:12 +0100 | [diff] [blame] | 1775 | /* |
| 1776 | * prevent recursion, since the user stack tracing may |
| 1777 | * trigger other kernel events. |
| 1778 | */ |
| 1779 | preempt_disable(); |
| 1780 | if (__this_cpu_read(user_stack_count)) |
| 1781 | goto out; |
| 1782 | |
| 1783 | __this_cpu_inc(user_stack_count); |
| 1784 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1785 | event = trace_buffer_lock_reserve(buffer, TRACE_USER_STACK, |
Arnaldo Carvalho de Melo | 51a763d | 2009-02-05 16:14:13 -0200 | [diff] [blame] | 1786 | sizeof(*entry), flags, pc); |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 1787 | if (!event) |
Li Zefan | 1dbd195 | 2010-12-09 15:47:56 +0800 | [diff] [blame] | 1788 | goto out_drop_count; |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 1789 | entry = ring_buffer_event_data(event); |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 1790 | |
Steven Rostedt | 48659d3 | 2009-09-11 11:36:23 -0400 | [diff] [blame] | 1791 | entry->tgid = current->tgid; |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 1792 | memset(&entry->caller, 0, sizeof(entry->caller)); |
| 1793 | |
| 1794 | trace.nr_entries = 0; |
| 1795 | trace.max_entries = FTRACE_STACK_ENTRIES; |
| 1796 | trace.skip = 0; |
| 1797 | trace.entries = entry->caller; |
| 1798 | |
| 1799 | save_stack_trace_user(&trace); |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1800 | if (!filter_check_discard(call, entry, buffer, event)) |
Steven Rostedt | 7ffbd48 | 2012-10-11 12:14:25 -0400 | [diff] [blame] | 1801 | __buffer_unlock_commit(buffer, event); |
Steven Rostedt | 91e86e5 | 2010-11-10 12:56:12 +0100 | [diff] [blame] | 1802 | |
Li Zefan | 1dbd195 | 2010-12-09 15:47:56 +0800 | [diff] [blame] | 1803 | out_drop_count: |
Steven Rostedt | 91e86e5 | 2010-11-10 12:56:12 +0100 | [diff] [blame] | 1804 | __this_cpu_dec(user_stack_count); |
Steven Rostedt | 91e86e5 | 2010-11-10 12:56:12 +0100 | [diff] [blame] | 1805 | out: |
| 1806 | preempt_enable(); |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 1807 | } |
| 1808 | |
Hannes Eder | 4fd2735 | 2009-02-10 19:44:12 +0100 | [diff] [blame] | 1809 | #ifdef UNUSED |
| 1810 | 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] | 1811 | { |
Arnaldo Carvalho de Melo | 7be4215 | 2009-02-05 01:13:37 -0500 | [diff] [blame] | 1812 | ftrace_trace_userstack(tr, flags, preempt_count()); |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 1813 | } |
Hannes Eder | 4fd2735 | 2009-02-10 19:44:12 +0100 | [diff] [blame] | 1814 | #endif /* UNUSED */ |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 1815 | |
Frederic Weisbecker | c0a0d0d | 2009-07-29 17:51:13 +0200 | [diff] [blame] | 1816 | #endif /* CONFIG_STACKTRACE */ |
| 1817 | |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 1818 | /* created for use with alloc_percpu */ |
| 1819 | struct trace_buffer_struct { |
| 1820 | char buffer[TRACE_BUF_SIZE]; |
| 1821 | }; |
| 1822 | |
| 1823 | static struct trace_buffer_struct *trace_percpu_buffer; |
| 1824 | static struct trace_buffer_struct *trace_percpu_sirq_buffer; |
| 1825 | static struct trace_buffer_struct *trace_percpu_irq_buffer; |
| 1826 | static struct trace_buffer_struct *trace_percpu_nmi_buffer; |
| 1827 | |
| 1828 | /* |
| 1829 | * The buffer used is dependent on the context. There is a per cpu |
| 1830 | * buffer for normal context, softirq contex, hard irq context and |
| 1831 | * for NMI context. Thise allows for lockless recording. |
| 1832 | * |
| 1833 | * Note, if the buffers failed to be allocated, then this returns NULL |
| 1834 | */ |
| 1835 | static char *get_trace_buf(void) |
| 1836 | { |
| 1837 | struct trace_buffer_struct *percpu_buffer; |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 1838 | |
| 1839 | /* |
| 1840 | * If we have allocated per cpu buffers, then we do not |
| 1841 | * need to do any locking. |
| 1842 | */ |
| 1843 | if (in_nmi()) |
| 1844 | percpu_buffer = trace_percpu_nmi_buffer; |
| 1845 | else if (in_irq()) |
| 1846 | percpu_buffer = trace_percpu_irq_buffer; |
| 1847 | else if (in_softirq()) |
| 1848 | percpu_buffer = trace_percpu_sirq_buffer; |
| 1849 | else |
| 1850 | percpu_buffer = trace_percpu_buffer; |
| 1851 | |
| 1852 | if (!percpu_buffer) |
| 1853 | return NULL; |
| 1854 | |
Shan Wei | d8a0349 | 2012-11-13 09:53:04 +0800 | [diff] [blame] | 1855 | return this_cpu_ptr(&percpu_buffer->buffer[0]); |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 1856 | } |
| 1857 | |
| 1858 | static int alloc_percpu_trace_buffer(void) |
| 1859 | { |
| 1860 | struct trace_buffer_struct *buffers; |
| 1861 | struct trace_buffer_struct *sirq_buffers; |
| 1862 | struct trace_buffer_struct *irq_buffers; |
| 1863 | struct trace_buffer_struct *nmi_buffers; |
| 1864 | |
| 1865 | buffers = alloc_percpu(struct trace_buffer_struct); |
| 1866 | if (!buffers) |
| 1867 | goto err_warn; |
| 1868 | |
| 1869 | sirq_buffers = alloc_percpu(struct trace_buffer_struct); |
| 1870 | if (!sirq_buffers) |
| 1871 | goto err_sirq; |
| 1872 | |
| 1873 | irq_buffers = alloc_percpu(struct trace_buffer_struct); |
| 1874 | if (!irq_buffers) |
| 1875 | goto err_irq; |
| 1876 | |
| 1877 | nmi_buffers = alloc_percpu(struct trace_buffer_struct); |
| 1878 | if (!nmi_buffers) |
| 1879 | goto err_nmi; |
| 1880 | |
| 1881 | trace_percpu_buffer = buffers; |
| 1882 | trace_percpu_sirq_buffer = sirq_buffers; |
| 1883 | trace_percpu_irq_buffer = irq_buffers; |
| 1884 | trace_percpu_nmi_buffer = nmi_buffers; |
| 1885 | |
| 1886 | return 0; |
| 1887 | |
| 1888 | err_nmi: |
| 1889 | free_percpu(irq_buffers); |
| 1890 | err_irq: |
| 1891 | free_percpu(sirq_buffers); |
| 1892 | err_sirq: |
| 1893 | free_percpu(buffers); |
| 1894 | err_warn: |
| 1895 | WARN(1, "Could not allocate percpu trace_printk buffer"); |
| 1896 | return -ENOMEM; |
| 1897 | } |
| 1898 | |
Steven Rostedt | 8169883 | 2012-10-11 10:15:05 -0400 | [diff] [blame] | 1899 | static int buffers_allocated; |
| 1900 | |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 1901 | void trace_printk_init_buffers(void) |
| 1902 | { |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 1903 | if (buffers_allocated) |
| 1904 | return; |
| 1905 | |
| 1906 | if (alloc_percpu_trace_buffer()) |
| 1907 | return; |
| 1908 | |
| 1909 | pr_info("ftrace: Allocated trace_printk buffers\n"); |
| 1910 | |
Steven Rostedt | b382ede6 | 2012-10-10 21:44:34 -0400 | [diff] [blame] | 1911 | /* Expand the buffers to set size */ |
| 1912 | tracing_update_buffers(); |
| 1913 | |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 1914 | buffers_allocated = 1; |
Steven Rostedt | 8169883 | 2012-10-11 10:15:05 -0400 | [diff] [blame] | 1915 | |
| 1916 | /* |
| 1917 | * trace_printk_init_buffers() can be called by modules. |
| 1918 | * If that happens, then we need to start cmdline recording |
| 1919 | * directly here. If the global_trace.buffer is already |
| 1920 | * allocated here, then this was called by module code. |
| 1921 | */ |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1922 | if (global_trace.trace_buffer.buffer) |
Steven Rostedt | 8169883 | 2012-10-11 10:15:05 -0400 | [diff] [blame] | 1923 | tracing_start_cmdline_record(); |
| 1924 | } |
| 1925 | |
| 1926 | void trace_printk_start_comm(void) |
| 1927 | { |
| 1928 | /* Start tracing comms if trace printk is set */ |
| 1929 | if (!buffers_allocated) |
| 1930 | return; |
| 1931 | tracing_start_cmdline_record(); |
| 1932 | } |
| 1933 | |
| 1934 | static void trace_printk_start_stop_comm(int enabled) |
| 1935 | { |
| 1936 | if (!buffers_allocated) |
| 1937 | return; |
| 1938 | |
| 1939 | if (enabled) |
| 1940 | tracing_start_cmdline_record(); |
| 1941 | else |
| 1942 | tracing_stop_cmdline_record(); |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 1943 | } |
| 1944 | |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 1945 | /** |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 1946 | * trace_vbprintk - write binary msg to tracing buffer |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 1947 | * |
| 1948 | */ |
Steven Rostedt | 40ce74f | 2009-03-19 14:03:53 -0400 | [diff] [blame] | 1949 | int trace_vbprintk(unsigned long ip, const char *fmt, va_list args) |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 1950 | { |
Tom Zanussi | e1112b4 | 2009-03-31 00:48:49 -0500 | [diff] [blame] | 1951 | struct ftrace_event_call *call = &event_bprint; |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 1952 | struct ring_buffer_event *event; |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1953 | struct ring_buffer *buffer; |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 1954 | struct trace_array *tr = &global_trace; |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 1955 | struct bprint_entry *entry; |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 1956 | unsigned long flags; |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 1957 | char *tbuffer; |
| 1958 | int len = 0, size, pc; |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 1959 | |
| 1960 | if (unlikely(tracing_selftest_running || tracing_disabled)) |
| 1961 | return 0; |
| 1962 | |
| 1963 | /* Don't pollute graph traces with trace_vprintk internals */ |
| 1964 | pause_graph_tracing(); |
| 1965 | |
| 1966 | pc = preempt_count(); |
Steven Rostedt | 5168ae5 | 2010-06-03 09:36:50 -0400 | [diff] [blame] | 1967 | preempt_disable_notrace(); |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 1968 | |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 1969 | tbuffer = get_trace_buf(); |
| 1970 | if (!tbuffer) { |
| 1971 | len = 0; |
| 1972 | goto out; |
| 1973 | } |
| 1974 | |
| 1975 | len = vbin_printf((u32 *)tbuffer, TRACE_BUF_SIZE/sizeof(int), fmt, args); |
| 1976 | |
| 1977 | if (len > TRACE_BUF_SIZE/sizeof(int) || len < 0) |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 1978 | goto out; |
| 1979 | |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 1980 | local_save_flags(flags); |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 1981 | size = sizeof(*entry) + sizeof(u32) * len; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1982 | buffer = tr->trace_buffer.buffer; |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1983 | event = trace_buffer_lock_reserve(buffer, TRACE_BPRINT, size, |
| 1984 | flags, pc); |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 1985 | if (!event) |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 1986 | goto out; |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 1987 | entry = ring_buffer_event_data(event); |
| 1988 | entry->ip = ip; |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 1989 | entry->fmt = fmt; |
| 1990 | |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 1991 | memcpy(entry->buf, tbuffer, sizeof(u32) * len); |
Steven Rostedt | d931369 | 2010-01-06 17:27:11 -0500 | [diff] [blame] | 1992 | if (!filter_check_discard(call, entry, buffer, event)) { |
Steven Rostedt | 7ffbd48 | 2012-10-11 12:14:25 -0400 | [diff] [blame] | 1993 | __buffer_unlock_commit(buffer, event); |
Steven Rostedt | d931369 | 2010-01-06 17:27:11 -0500 | [diff] [blame] | 1994 | ftrace_trace_stack(buffer, flags, 6, pc); |
| 1995 | } |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 1996 | |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 1997 | out: |
Steven Rostedt | 5168ae5 | 2010-06-03 09:36:50 -0400 | [diff] [blame] | 1998 | preempt_enable_notrace(); |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 1999 | unpause_graph_tracing(); |
| 2000 | |
| 2001 | return len; |
| 2002 | } |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 2003 | EXPORT_SYMBOL_GPL(trace_vbprintk); |
| 2004 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2005 | static int |
| 2006 | __trace_array_vprintk(struct ring_buffer *buffer, |
| 2007 | unsigned long ip, const char *fmt, va_list args) |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 2008 | { |
Tom Zanussi | e1112b4 | 2009-03-31 00:48:49 -0500 | [diff] [blame] | 2009 | struct ftrace_event_call *call = &event_print; |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 2010 | struct ring_buffer_event *event; |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 2011 | int len = 0, size, pc; |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 2012 | struct print_entry *entry; |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 2013 | unsigned long flags; |
| 2014 | char *tbuffer; |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 2015 | |
| 2016 | if (tracing_disabled || tracing_selftest_running) |
| 2017 | return 0; |
| 2018 | |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 2019 | /* Don't pollute graph traces with trace_vprintk internals */ |
| 2020 | pause_graph_tracing(); |
| 2021 | |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 2022 | pc = preempt_count(); |
| 2023 | preempt_disable_notrace(); |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 2024 | |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 2025 | |
| 2026 | tbuffer = get_trace_buf(); |
| 2027 | if (!tbuffer) { |
| 2028 | len = 0; |
| 2029 | goto out; |
| 2030 | } |
| 2031 | |
| 2032 | len = vsnprintf(tbuffer, TRACE_BUF_SIZE, fmt, args); |
| 2033 | if (len > TRACE_BUF_SIZE) |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 2034 | goto out; |
| 2035 | |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 2036 | local_save_flags(flags); |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 2037 | size = sizeof(*entry) + len + 1; |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 2038 | event = trace_buffer_lock_reserve(buffer, TRACE_PRINT, size, |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 2039 | flags, pc); |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 2040 | if (!event) |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 2041 | goto out; |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 2042 | entry = ring_buffer_event_data(event); |
Carsten Emde | c13d2f7 | 2009-11-16 20:56:13 +0100 | [diff] [blame] | 2043 | entry->ip = ip; |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 2044 | |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 2045 | memcpy(&entry->buf, tbuffer, len); |
Carsten Emde | c13d2f7 | 2009-11-16 20:56:13 +0100 | [diff] [blame] | 2046 | entry->buf[len] = '\0'; |
Steven Rostedt | d931369 | 2010-01-06 17:27:11 -0500 | [diff] [blame] | 2047 | if (!filter_check_discard(call, entry, buffer, event)) { |
Steven Rostedt | 7ffbd48 | 2012-10-11 12:14:25 -0400 | [diff] [blame] | 2048 | __buffer_unlock_commit(buffer, event); |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 2049 | ftrace_trace_stack(buffer, flags, 6, pc); |
Steven Rostedt | d931369 | 2010-01-06 17:27:11 -0500 | [diff] [blame] | 2050 | } |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 2051 | out: |
| 2052 | preempt_enable_notrace(); |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 2053 | unpause_graph_tracing(); |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 2054 | |
| 2055 | return len; |
| 2056 | } |
Steven Rostedt | 659372d | 2009-09-03 19:11:07 -0400 | [diff] [blame] | 2057 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2058 | int trace_array_vprintk(struct trace_array *tr, |
| 2059 | unsigned long ip, const char *fmt, va_list args) |
| 2060 | { |
| 2061 | return __trace_array_vprintk(tr->trace_buffer.buffer, ip, fmt, args); |
| 2062 | } |
| 2063 | |
| 2064 | int trace_array_printk(struct trace_array *tr, |
| 2065 | unsigned long ip, const char *fmt, ...) |
| 2066 | { |
| 2067 | int ret; |
| 2068 | va_list ap; |
| 2069 | |
| 2070 | if (!(trace_flags & TRACE_ITER_PRINTK)) |
| 2071 | return 0; |
| 2072 | |
| 2073 | va_start(ap, fmt); |
| 2074 | ret = trace_array_vprintk(tr, ip, fmt, ap); |
| 2075 | va_end(ap); |
| 2076 | return ret; |
| 2077 | } |
| 2078 | |
| 2079 | int trace_array_printk_buf(struct ring_buffer *buffer, |
| 2080 | unsigned long ip, const char *fmt, ...) |
| 2081 | { |
| 2082 | int ret; |
| 2083 | va_list ap; |
| 2084 | |
| 2085 | if (!(trace_flags & TRACE_ITER_PRINTK)) |
| 2086 | return 0; |
| 2087 | |
| 2088 | va_start(ap, fmt); |
| 2089 | ret = __trace_array_vprintk(buffer, ip, fmt, ap); |
| 2090 | va_end(ap); |
| 2091 | return ret; |
| 2092 | } |
| 2093 | |
Steven Rostedt | 659372d | 2009-09-03 19:11:07 -0400 | [diff] [blame] | 2094 | int trace_vprintk(unsigned long ip, const char *fmt, va_list args) |
| 2095 | { |
Steven Rostedt | a813a15 | 2009-10-09 01:41:35 -0400 | [diff] [blame] | 2096 | return trace_array_vprintk(&global_trace, ip, fmt, args); |
Steven Rostedt | 659372d | 2009-09-03 19:11:07 -0400 | [diff] [blame] | 2097 | } |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 2098 | EXPORT_SYMBOL_GPL(trace_vprintk); |
| 2099 | |
Robert Richter | e2ac8ef | 2008-11-12 12:59:32 +0100 | [diff] [blame] | 2100 | static void trace_iterator_increment(struct trace_iterator *iter) |
Steven Rostedt | 5a90f57 | 2008-09-03 17:42:51 -0400 | [diff] [blame] | 2101 | { |
Steven Rostedt | 6d158a8 | 2012-06-27 20:46:14 -0400 | [diff] [blame] | 2102 | struct ring_buffer_iter *buf_iter = trace_buffer_iter(iter, iter->cpu); |
| 2103 | |
Steven Rostedt | 5a90f57 | 2008-09-03 17:42:51 -0400 | [diff] [blame] | 2104 | iter->idx++; |
Steven Rostedt | 6d158a8 | 2012-06-27 20:46:14 -0400 | [diff] [blame] | 2105 | if (buf_iter) |
| 2106 | ring_buffer_read(buf_iter, NULL); |
Steven Rostedt | 5a90f57 | 2008-09-03 17:42:51 -0400 | [diff] [blame] | 2107 | } |
| 2108 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 2109 | static struct trace_entry * |
Steven Rostedt | bc21b47 | 2010-03-31 19:49:26 -0400 | [diff] [blame] | 2110 | peek_next_entry(struct trace_iterator *iter, int cpu, u64 *ts, |
| 2111 | unsigned long *lost_events) |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2112 | { |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2113 | struct ring_buffer_event *event; |
Steven Rostedt | 6d158a8 | 2012-06-27 20:46:14 -0400 | [diff] [blame] | 2114 | struct ring_buffer_iter *buf_iter = trace_buffer_iter(iter, cpu); |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2115 | |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 2116 | if (buf_iter) |
| 2117 | event = ring_buffer_iter_peek(buf_iter, ts); |
| 2118 | else |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2119 | event = ring_buffer_peek(iter->trace_buffer->buffer, cpu, ts, |
Steven Rostedt | bc21b47 | 2010-03-31 19:49:26 -0400 | [diff] [blame] | 2120 | lost_events); |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 2121 | |
Steven Rostedt | 4a9bd3f | 2011-07-14 16:36:53 -0400 | [diff] [blame] | 2122 | if (event) { |
| 2123 | iter->ent_size = ring_buffer_event_length(event); |
| 2124 | return ring_buffer_event_data(event); |
| 2125 | } |
| 2126 | iter->ent_size = 0; |
| 2127 | return NULL; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2128 | } |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 2129 | |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2130 | static struct trace_entry * |
Steven Rostedt | bc21b47 | 2010-03-31 19:49:26 -0400 | [diff] [blame] | 2131 | __find_next_entry(struct trace_iterator *iter, int *ent_cpu, |
| 2132 | unsigned long *missing_events, u64 *ent_ts) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2133 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2134 | struct ring_buffer *buffer = iter->trace_buffer->buffer; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2135 | struct trace_entry *ent, *next = NULL; |
Lai Jiangshan | aa27497 | 2010-04-05 17:11:05 +0800 | [diff] [blame] | 2136 | unsigned long lost_events = 0, next_lost = 0; |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 2137 | int cpu_file = iter->cpu_file; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2138 | u64 next_ts = 0, ts; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2139 | int next_cpu = -1; |
Steven Rostedt | 12b5da3 | 2012-03-27 10:43:28 -0400 | [diff] [blame] | 2140 | int next_size = 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2141 | int cpu; |
| 2142 | |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 2143 | /* |
| 2144 | * If we are in a per_cpu trace file, don't bother by iterating over |
| 2145 | * all cpu and peek directly. |
| 2146 | */ |
Steven Rostedt | ae3b509 | 2013-01-23 15:22:59 -0500 | [diff] [blame] | 2147 | if (cpu_file > RING_BUFFER_ALL_CPUS) { |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 2148 | if (ring_buffer_empty_cpu(buffer, cpu_file)) |
| 2149 | return NULL; |
Steven Rostedt | bc21b47 | 2010-03-31 19:49:26 -0400 | [diff] [blame] | 2150 | ent = peek_next_entry(iter, cpu_file, ent_ts, missing_events); |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 2151 | if (ent_cpu) |
| 2152 | *ent_cpu = cpu_file; |
| 2153 | |
| 2154 | return ent; |
| 2155 | } |
| 2156 | |
Steven Rostedt | ab46428 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 2157 | for_each_tracing_cpu(cpu) { |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2158 | |
| 2159 | if (ring_buffer_empty_cpu(buffer, cpu)) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2160 | continue; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2161 | |
Steven Rostedt | bc21b47 | 2010-03-31 19:49:26 -0400 | [diff] [blame] | 2162 | ent = peek_next_entry(iter, cpu, &ts, &lost_events); |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2163 | |
Ingo Molnar | cdd31cd2 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2164 | /* |
| 2165 | * Pick the entry with the smallest timestamp: |
| 2166 | */ |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2167 | if (ent && (!next || ts < next_ts)) { |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2168 | next = ent; |
| 2169 | next_cpu = cpu; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2170 | next_ts = ts; |
Steven Rostedt | bc21b47 | 2010-03-31 19:49:26 -0400 | [diff] [blame] | 2171 | next_lost = lost_events; |
Steven Rostedt | 12b5da3 | 2012-03-27 10:43:28 -0400 | [diff] [blame] | 2172 | next_size = iter->ent_size; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2173 | } |
| 2174 | } |
| 2175 | |
Steven Rostedt | 12b5da3 | 2012-03-27 10:43:28 -0400 | [diff] [blame] | 2176 | iter->ent_size = next_size; |
| 2177 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2178 | if (ent_cpu) |
| 2179 | *ent_cpu = next_cpu; |
| 2180 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2181 | if (ent_ts) |
| 2182 | *ent_ts = next_ts; |
| 2183 | |
Steven Rostedt | bc21b47 | 2010-03-31 19:49:26 -0400 | [diff] [blame] | 2184 | if (missing_events) |
| 2185 | *missing_events = next_lost; |
| 2186 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2187 | return next; |
| 2188 | } |
| 2189 | |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2190 | /* Find the next real entry, without updating the iterator itself */ |
Frederic Weisbecker | c4a8e8b | 2009-02-02 20:29:21 -0200 | [diff] [blame] | 2191 | struct trace_entry *trace_find_next_entry(struct trace_iterator *iter, |
| 2192 | int *ent_cpu, u64 *ent_ts) |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2193 | { |
Steven Rostedt | bc21b47 | 2010-03-31 19:49:26 -0400 | [diff] [blame] | 2194 | return __find_next_entry(iter, ent_cpu, NULL, ent_ts); |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2195 | } |
Ingo Molnar | 8c523a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2196 | |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2197 | /* 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] | 2198 | void *trace_find_next_entry_inc(struct trace_iterator *iter) |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2199 | { |
Steven Rostedt | bc21b47 | 2010-03-31 19:49:26 -0400 | [diff] [blame] | 2200 | iter->ent = __find_next_entry(iter, &iter->cpu, |
| 2201 | &iter->lost_events, &iter->ts); |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2202 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2203 | if (iter->ent) |
Robert Richter | e2ac8ef | 2008-11-12 12:59:32 +0100 | [diff] [blame] | 2204 | trace_iterator_increment(iter); |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2205 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2206 | return iter->ent ? iter : NULL; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2207 | } |
| 2208 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 2209 | static void trace_consume(struct trace_iterator *iter) |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2210 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2211 | ring_buffer_consume(iter->trace_buffer->buffer, iter->cpu, &iter->ts, |
Steven Rostedt | bc21b47 | 2010-03-31 19:49:26 -0400 | [diff] [blame] | 2212 | &iter->lost_events); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2213 | } |
| 2214 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 2215 | 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] | 2216 | { |
| 2217 | struct trace_iterator *iter = m->private; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2218 | int i = (int)*pos; |
Ingo Molnar | 4e3c333 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 2219 | void *ent; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2220 | |
Steven Rostedt | a63ce5b | 2009-12-07 09:11:39 -0500 | [diff] [blame] | 2221 | WARN_ON_ONCE(iter->leftover); |
| 2222 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2223 | (*pos)++; |
| 2224 | |
| 2225 | /* can't go backwards */ |
| 2226 | if (iter->idx > i) |
| 2227 | return NULL; |
| 2228 | |
| 2229 | if (iter->idx < 0) |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 2230 | ent = trace_find_next_entry_inc(iter); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2231 | else |
| 2232 | ent = iter; |
| 2233 | |
| 2234 | while (ent && iter->idx < i) |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 2235 | ent = trace_find_next_entry_inc(iter); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2236 | |
| 2237 | iter->pos = *pos; |
| 2238 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2239 | return ent; |
| 2240 | } |
| 2241 | |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 2242 | void tracing_iter_reset(struct trace_iterator *iter, int cpu) |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 2243 | { |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 2244 | struct ring_buffer_event *event; |
| 2245 | struct ring_buffer_iter *buf_iter; |
| 2246 | unsigned long entries = 0; |
| 2247 | u64 ts; |
| 2248 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2249 | per_cpu_ptr(iter->trace_buffer->data, cpu)->skipped_entries = 0; |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 2250 | |
Steven Rostedt | 6d158a8 | 2012-06-27 20:46:14 -0400 | [diff] [blame] | 2251 | buf_iter = trace_buffer_iter(iter, cpu); |
| 2252 | if (!buf_iter) |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 2253 | return; |
| 2254 | |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 2255 | ring_buffer_iter_reset(buf_iter); |
| 2256 | |
| 2257 | /* |
| 2258 | * We could have the case with the max latency tracers |
| 2259 | * that a reset never took place on a cpu. This is evident |
| 2260 | * by the timestamp being before the start of the buffer. |
| 2261 | */ |
| 2262 | while ((event = ring_buffer_iter_peek(buf_iter, &ts))) { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2263 | if (ts >= iter->trace_buffer->time_start) |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 2264 | break; |
| 2265 | entries++; |
| 2266 | ring_buffer_read(buf_iter, NULL); |
| 2267 | } |
| 2268 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2269 | per_cpu_ptr(iter->trace_buffer->data, cpu)->skipped_entries = entries; |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 2270 | } |
| 2271 | |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 2272 | /* |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 2273 | * The current tracer is copied to avoid a global locking |
| 2274 | * all around. |
| 2275 | */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2276 | static void *s_start(struct seq_file *m, loff_t *pos) |
| 2277 | { |
| 2278 | struct trace_iterator *iter = m->private; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 2279 | struct trace_array *tr = iter->tr; |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 2280 | int cpu_file = iter->cpu_file; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2281 | void *p = NULL; |
| 2282 | loff_t l = 0; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2283 | int cpu; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2284 | |
Hiraku Toyooka | 2fd196e | 2012-12-26 11:52:52 +0900 | [diff] [blame] | 2285 | /* |
| 2286 | * copy the tracer to avoid using a global lock all around. |
| 2287 | * iter->trace is a copy of current_trace, the pointer to the |
| 2288 | * name may be used instead of a strcmp(), as iter->trace->name |
| 2289 | * will point to the same string as current_trace->name. |
| 2290 | */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2291 | mutex_lock(&trace_types_lock); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 2292 | if (unlikely(tr->current_trace && iter->trace->name != tr->current_trace->name)) |
| 2293 | *iter->trace = *tr->current_trace; |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 2294 | mutex_unlock(&trace_types_lock); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2295 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2296 | #ifdef CONFIG_TRACER_MAX_TRACE |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 2297 | if (iter->snapshot && iter->trace->use_max_tr) |
| 2298 | return ERR_PTR(-EBUSY); |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2299 | #endif |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 2300 | |
| 2301 | if (!iter->snapshot) |
| 2302 | atomic_inc(&trace_record_cmdline_disabled); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2303 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2304 | if (*pos != iter->pos) { |
| 2305 | iter->ent = NULL; |
| 2306 | iter->cpu = 0; |
| 2307 | iter->idx = -1; |
| 2308 | |
Steven Rostedt | ae3b509 | 2013-01-23 15:22:59 -0500 | [diff] [blame] | 2309 | if (cpu_file == RING_BUFFER_ALL_CPUS) { |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 2310 | for_each_tracing_cpu(cpu) |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 2311 | tracing_iter_reset(iter, cpu); |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 2312 | } else |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 2313 | tracing_iter_reset(iter, cpu_file); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2314 | |
Lai Jiangshan | ac91d85 | 2010-03-02 17:54:50 +0800 | [diff] [blame] | 2315 | iter->leftover = 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2316 | for (p = iter; p && l < *pos; p = s_next(m, p, &l)) |
| 2317 | ; |
| 2318 | |
| 2319 | } else { |
Steven Rostedt | a63ce5b | 2009-12-07 09:11:39 -0500 | [diff] [blame] | 2320 | /* |
| 2321 | * If we overflowed the seq_file before, then we want |
| 2322 | * to just reuse the trace_seq buffer again. |
| 2323 | */ |
| 2324 | if (iter->leftover) |
| 2325 | p = iter; |
| 2326 | else { |
| 2327 | l = *pos - 1; |
| 2328 | p = s_next(m, p, &l); |
| 2329 | } |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2330 | } |
| 2331 | |
Lai Jiangshan | 4f53596 | 2009-05-18 19:35:34 +0800 | [diff] [blame] | 2332 | trace_event_read_lock(); |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 2333 | trace_access_lock(cpu_file); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2334 | return p; |
| 2335 | } |
| 2336 | |
| 2337 | static void s_stop(struct seq_file *m, void *p) |
| 2338 | { |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 2339 | struct trace_iterator *iter = m->private; |
| 2340 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2341 | #ifdef CONFIG_TRACER_MAX_TRACE |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 2342 | if (iter->snapshot && iter->trace->use_max_tr) |
| 2343 | return; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2344 | #endif |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 2345 | |
| 2346 | if (!iter->snapshot) |
| 2347 | atomic_dec(&trace_record_cmdline_disabled); |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2348 | |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 2349 | trace_access_unlock(iter->cpu_file); |
Lai Jiangshan | 4f53596 | 2009-05-18 19:35:34 +0800 | [diff] [blame] | 2350 | trace_event_read_unlock(); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2351 | } |
| 2352 | |
Steven Rostedt | 39eaf7e | 2011-11-17 10:35:16 -0500 | [diff] [blame] | 2353 | static void |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2354 | get_total_entries(struct trace_buffer *buf, |
| 2355 | unsigned long *total, unsigned long *entries) |
Steven Rostedt | 39eaf7e | 2011-11-17 10:35:16 -0500 | [diff] [blame] | 2356 | { |
| 2357 | unsigned long count; |
| 2358 | int cpu; |
| 2359 | |
| 2360 | *total = 0; |
| 2361 | *entries = 0; |
| 2362 | |
| 2363 | for_each_tracing_cpu(cpu) { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2364 | count = ring_buffer_entries_cpu(buf->buffer, cpu); |
Steven Rostedt | 39eaf7e | 2011-11-17 10:35:16 -0500 | [diff] [blame] | 2365 | /* |
| 2366 | * If this buffer has skipped entries, then we hold all |
| 2367 | * entries for the trace and we need to ignore the |
| 2368 | * ones before the time stamp. |
| 2369 | */ |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2370 | if (per_cpu_ptr(buf->data, cpu)->skipped_entries) { |
| 2371 | count -= per_cpu_ptr(buf->data, cpu)->skipped_entries; |
Steven Rostedt | 39eaf7e | 2011-11-17 10:35:16 -0500 | [diff] [blame] | 2372 | /* total is the same as the entries */ |
| 2373 | *total += count; |
| 2374 | } else |
| 2375 | *total += count + |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2376 | ring_buffer_overrun_cpu(buf->buffer, cpu); |
Steven Rostedt | 39eaf7e | 2011-11-17 10:35:16 -0500 | [diff] [blame] | 2377 | *entries += count; |
| 2378 | } |
| 2379 | } |
| 2380 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 2381 | static void print_lat_help_header(struct seq_file *m) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2382 | { |
Michael Ellerman | a616835 | 2008-08-20 16:36:11 -0700 | [diff] [blame] | 2383 | seq_puts(m, "# _------=> CPU# \n"); |
| 2384 | seq_puts(m, "# / _-----=> irqs-off \n"); |
| 2385 | seq_puts(m, "# | / _----=> need-resched \n"); |
| 2386 | seq_puts(m, "# || / _---=> hardirq/softirq \n"); |
| 2387 | seq_puts(m, "# ||| / _--=> preempt-depth \n"); |
Steven Rostedt | e6e1e25 | 2011-03-09 10:41:56 -0500 | [diff] [blame] | 2388 | seq_puts(m, "# |||| / delay \n"); |
| 2389 | seq_puts(m, "# cmd pid ||||| time | caller \n"); |
| 2390 | seq_puts(m, "# \\ / ||||| \\ | / \n"); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2391 | } |
| 2392 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2393 | 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] | 2394 | { |
Steven Rostedt | 39eaf7e | 2011-11-17 10:35:16 -0500 | [diff] [blame] | 2395 | unsigned long total; |
| 2396 | unsigned long entries; |
| 2397 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2398 | get_total_entries(buf, &total, &entries); |
Steven Rostedt | 39eaf7e | 2011-11-17 10:35:16 -0500 | [diff] [blame] | 2399 | seq_printf(m, "# entries-in-buffer/entries-written: %lu/%lu #P:%d\n", |
| 2400 | entries, total, num_online_cpus()); |
| 2401 | seq_puts(m, "#\n"); |
| 2402 | } |
| 2403 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2404 | 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] | 2405 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2406 | print_event_info(buf, m); |
Steven Rostedt | 77271ce | 2011-11-17 09:34:33 -0500 | [diff] [blame] | 2407 | seq_puts(m, "# TASK-PID CPU# TIMESTAMP FUNCTION\n"); |
Michael Ellerman | a616835 | 2008-08-20 16:36:11 -0700 | [diff] [blame] | 2408 | seq_puts(m, "# | | | | |\n"); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2409 | } |
| 2410 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2411 | 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] | 2412 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2413 | print_event_info(buf, m); |
Steven Rostedt | 77271ce | 2011-11-17 09:34:33 -0500 | [diff] [blame] | 2414 | seq_puts(m, "# _-----=> irqs-off\n"); |
| 2415 | seq_puts(m, "# / _----=> need-resched\n"); |
| 2416 | seq_puts(m, "# | / _---=> hardirq/softirq\n"); |
| 2417 | seq_puts(m, "# || / _--=> preempt-depth\n"); |
| 2418 | seq_puts(m, "# ||| / delay\n"); |
| 2419 | seq_puts(m, "# TASK-PID CPU# |||| TIMESTAMP FUNCTION\n"); |
| 2420 | seq_puts(m, "# | | | |||| | |\n"); |
| 2421 | } |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2422 | |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 2423 | void |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2424 | print_trace_header(struct seq_file *m, struct trace_iterator *iter) |
| 2425 | { |
| 2426 | unsigned long sym_flags = (trace_flags & TRACE_ITER_SYM_MASK); |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2427 | struct trace_buffer *buf = iter->trace_buffer; |
| 2428 | struct trace_array_cpu *data = per_cpu_ptr(buf->data, buf->cpu); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 2429 | struct tracer *type = iter->trace; |
Steven Rostedt | 39eaf7e | 2011-11-17 10:35:16 -0500 | [diff] [blame] | 2430 | unsigned long entries; |
| 2431 | unsigned long total; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2432 | const char *name = "preemption"; |
| 2433 | |
Steven Rostedt (Red Hat) | d840f71 | 2013-02-01 18:38:47 -0500 | [diff] [blame] | 2434 | name = type->name; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2435 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2436 | get_total_entries(buf, &total, &entries); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2437 | |
KOSAKI Motohiro | 888b55d | 2009-03-08 13:12:43 +0900 | [diff] [blame] | 2438 | seq_printf(m, "# %s latency trace v1.1.5 on %s\n", |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2439 | name, UTS_RELEASE); |
KOSAKI Motohiro | 888b55d | 2009-03-08 13:12:43 +0900 | [diff] [blame] | 2440 | seq_puts(m, "# -----------------------------------" |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2441 | "---------------------------------\n"); |
KOSAKI Motohiro | 888b55d | 2009-03-08 13:12:43 +0900 | [diff] [blame] | 2442 | seq_printf(m, "# latency: %lu us, #%lu/%lu, CPU#%d |" |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2443 | " (M:%s VP:%d, KP:%d, SP:%d HP:%d", |
Steven Rostedt | 57f50be | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 2444 | nsecs_to_usecs(data->saved_latency), |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2445 | entries, |
Steven Rostedt | 4c11d7a | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 2446 | total, |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2447 | buf->cpu, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2448 | #if defined(CONFIG_PREEMPT_NONE) |
| 2449 | "server", |
| 2450 | #elif defined(CONFIG_PREEMPT_VOLUNTARY) |
| 2451 | "desktop", |
Steven Rostedt | b5c21b4 | 2008-07-10 20:58:12 -0400 | [diff] [blame] | 2452 | #elif defined(CONFIG_PREEMPT) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2453 | "preempt", |
| 2454 | #else |
| 2455 | "unknown", |
| 2456 | #endif |
| 2457 | /* These are reserved for later use */ |
| 2458 | 0, 0, 0, 0); |
| 2459 | #ifdef CONFIG_SMP |
| 2460 | seq_printf(m, " #P:%d)\n", num_online_cpus()); |
| 2461 | #else |
| 2462 | seq_puts(m, ")\n"); |
| 2463 | #endif |
KOSAKI Motohiro | 888b55d | 2009-03-08 13:12:43 +0900 | [diff] [blame] | 2464 | seq_puts(m, "# -----------------\n"); |
| 2465 | seq_printf(m, "# | task: %.16s-%d " |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2466 | "(uid:%d nice:%ld policy:%ld rt_prio:%ld)\n", |
Eric W. Biederman | d20b92a | 2012-03-13 16:02:19 -0700 | [diff] [blame] | 2467 | data->comm, data->pid, |
| 2468 | from_kuid_munged(seq_user_ns(m), data->uid), data->nice, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2469 | data->policy, data->rt_priority); |
KOSAKI Motohiro | 888b55d | 2009-03-08 13:12:43 +0900 | [diff] [blame] | 2470 | seq_puts(m, "# -----------------\n"); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2471 | |
| 2472 | if (data->critical_start) { |
KOSAKI Motohiro | 888b55d | 2009-03-08 13:12:43 +0900 | [diff] [blame] | 2473 | seq_puts(m, "# => started at: "); |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2474 | seq_print_ip_sym(&iter->seq, data->critical_start, sym_flags); |
| 2475 | trace_print_seq(m, &iter->seq); |
KOSAKI Motohiro | 888b55d | 2009-03-08 13:12:43 +0900 | [diff] [blame] | 2476 | seq_puts(m, "\n# => ended at: "); |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2477 | seq_print_ip_sym(&iter->seq, data->critical_end, sym_flags); |
| 2478 | trace_print_seq(m, &iter->seq); |
Steven Rostedt | 8248ac0 | 2009-09-02 12:27:41 -0400 | [diff] [blame] | 2479 | seq_puts(m, "\n#\n"); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2480 | } |
| 2481 | |
KOSAKI Motohiro | 888b55d | 2009-03-08 13:12:43 +0900 | [diff] [blame] | 2482 | seq_puts(m, "#\n"); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2483 | } |
| 2484 | |
Steven Rostedt | a309720 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 2485 | static void test_cpu_buff_start(struct trace_iterator *iter) |
| 2486 | { |
| 2487 | struct trace_seq *s = &iter->seq; |
| 2488 | |
Steven Rostedt | 12ef7d4 | 2008-11-12 17:52:38 -0500 | [diff] [blame] | 2489 | if (!(trace_flags & TRACE_ITER_ANNOTATE)) |
| 2490 | return; |
| 2491 | |
| 2492 | if (!(iter->iter_flags & TRACE_FILE_ANNOTATE)) |
| 2493 | return; |
| 2494 | |
Rusty Russell | 4462344 | 2009-01-01 10:12:23 +1030 | [diff] [blame] | 2495 | if (cpumask_test_cpu(iter->cpu, iter->started)) |
Steven Rostedt | a309720 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 2496 | return; |
| 2497 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2498 | if (per_cpu_ptr(iter->trace_buffer->data, iter->cpu)->skipped_entries) |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 2499 | return; |
| 2500 | |
Rusty Russell | 4462344 | 2009-01-01 10:12:23 +1030 | [diff] [blame] | 2501 | cpumask_set_cpu(iter->cpu, iter->started); |
Frederic Weisbecker | b0dfa97 | 2009-04-01 22:53:08 +0200 | [diff] [blame] | 2502 | |
| 2503 | /* Don't print started cpu buffer for the first entry of the trace */ |
| 2504 | if (iter->idx > 1) |
| 2505 | trace_seq_printf(s, "##### CPU %u buffer started ####\n", |
| 2506 | iter->cpu); |
Steven Rostedt | a309720 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 2507 | } |
| 2508 | |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 2509 | static enum print_line_t print_trace_fmt(struct trace_iterator *iter) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2510 | { |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2511 | struct trace_seq *s = &iter->seq; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2512 | unsigned long sym_flags = (trace_flags & TRACE_ITER_SYM_MASK); |
Ingo Molnar | 4e3c333 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 2513 | struct trace_entry *entry; |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 2514 | struct trace_event *event; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2515 | |
Ingo Molnar | 4e3c333 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 2516 | entry = iter->ent; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2517 | |
Steven Rostedt | a309720 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 2518 | test_cpu_buff_start(iter); |
| 2519 | |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 2520 | event = ftrace_find_event(entry->type); |
Frederic Weisbecker | c4a8e8b | 2009-02-02 20:29:21 -0200 | [diff] [blame] | 2521 | |
| 2522 | if (trace_flags & TRACE_ITER_CONTEXT_INFO) { |
Steven Rostedt | 27d48be | 2009-03-04 21:57:29 -0500 | [diff] [blame] | 2523 | if (iter->iter_flags & TRACE_FILE_LAT_FMT) { |
| 2524 | if (!trace_print_lat_context(iter)) |
| 2525 | goto partial; |
| 2526 | } else { |
| 2527 | if (!trace_print_context(iter)) |
| 2528 | goto partial; |
| 2529 | } |
Frederic Weisbecker | c4a8e8b | 2009-02-02 20:29:21 -0200 | [diff] [blame] | 2530 | } |
| 2531 | |
Arnaldo Carvalho de Melo | 268ccda | 2009-02-04 20:16:39 -0200 | [diff] [blame] | 2532 | if (event) |
Steven Rostedt | a9a5776 | 2010-04-22 18:46:14 -0400 | [diff] [blame] | 2533 | return event->funcs->trace(iter, sym_flags, event); |
Arnaldo Carvalho de Melo | d9793bd | 2009-02-03 20:20:41 -0200 | [diff] [blame] | 2534 | |
| 2535 | if (!trace_seq_printf(s, "Unknown type %d\n", entry->type)) |
| 2536 | goto partial; |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 2537 | |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 2538 | return TRACE_TYPE_HANDLED; |
Arnaldo Carvalho de Melo | d9793bd | 2009-02-03 20:20:41 -0200 | [diff] [blame] | 2539 | partial: |
| 2540 | return TRACE_TYPE_PARTIAL_LINE; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2541 | } |
| 2542 | |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 2543 | static enum print_line_t print_raw_fmt(struct trace_iterator *iter) |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2544 | { |
| 2545 | struct trace_seq *s = &iter->seq; |
| 2546 | struct trace_entry *entry; |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 2547 | struct trace_event *event; |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2548 | |
| 2549 | entry = iter->ent; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2550 | |
Frederic Weisbecker | c4a8e8b | 2009-02-02 20:29:21 -0200 | [diff] [blame] | 2551 | if (trace_flags & TRACE_ITER_CONTEXT_INFO) { |
Arnaldo Carvalho de Melo | d9793bd | 2009-02-03 20:20:41 -0200 | [diff] [blame] | 2552 | if (!trace_seq_printf(s, "%d %d %llu ", |
| 2553 | entry->pid, iter->cpu, iter->ts)) |
| 2554 | goto partial; |
Frederic Weisbecker | c4a8e8b | 2009-02-02 20:29:21 -0200 | [diff] [blame] | 2555 | } |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2556 | |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 2557 | event = ftrace_find_event(entry->type); |
Arnaldo Carvalho de Melo | 268ccda | 2009-02-04 20:16:39 -0200 | [diff] [blame] | 2558 | if (event) |
Steven Rostedt | a9a5776 | 2010-04-22 18:46:14 -0400 | [diff] [blame] | 2559 | return event->funcs->raw(iter, 0, event); |
Arnaldo Carvalho de Melo | d9793bd | 2009-02-03 20:20:41 -0200 | [diff] [blame] | 2560 | |
| 2561 | if (!trace_seq_printf(s, "%d ?\n", entry->type)) |
| 2562 | goto partial; |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 2563 | |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 2564 | return TRACE_TYPE_HANDLED; |
Arnaldo Carvalho de Melo | d9793bd | 2009-02-03 20:20:41 -0200 | [diff] [blame] | 2565 | partial: |
| 2566 | return TRACE_TYPE_PARTIAL_LINE; |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2567 | } |
| 2568 | |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 2569 | static enum print_line_t print_hex_fmt(struct trace_iterator *iter) |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 2570 | { |
| 2571 | struct trace_seq *s = &iter->seq; |
| 2572 | unsigned char newline = '\n'; |
| 2573 | struct trace_entry *entry; |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 2574 | struct trace_event *event; |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 2575 | |
| 2576 | entry = iter->ent; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2577 | |
Frederic Weisbecker | c4a8e8b | 2009-02-02 20:29:21 -0200 | [diff] [blame] | 2578 | if (trace_flags & TRACE_ITER_CONTEXT_INFO) { |
| 2579 | SEQ_PUT_HEX_FIELD_RET(s, entry->pid); |
| 2580 | SEQ_PUT_HEX_FIELD_RET(s, iter->cpu); |
| 2581 | SEQ_PUT_HEX_FIELD_RET(s, iter->ts); |
| 2582 | } |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 2583 | |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 2584 | event = ftrace_find_event(entry->type); |
Arnaldo Carvalho de Melo | 268ccda | 2009-02-04 20:16:39 -0200 | [diff] [blame] | 2585 | if (event) { |
Steven Rostedt | a9a5776 | 2010-04-22 18:46:14 -0400 | [diff] [blame] | 2586 | 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] | 2587 | if (ret != TRACE_TYPE_HANDLED) |
| 2588 | return ret; |
| 2589 | } |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 2590 | |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 2591 | SEQ_PUT_FIELD_RET(s, newline); |
| 2592 | |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 2593 | return TRACE_TYPE_HANDLED; |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 2594 | } |
| 2595 | |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 2596 | static enum print_line_t print_bin_fmt(struct trace_iterator *iter) |
Ingo Molnar | cb0f12a | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2597 | { |
| 2598 | struct trace_seq *s = &iter->seq; |
| 2599 | struct trace_entry *entry; |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 2600 | struct trace_event *event; |
Ingo Molnar | cb0f12a | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2601 | |
| 2602 | entry = iter->ent; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2603 | |
Frederic Weisbecker | c4a8e8b | 2009-02-02 20:29:21 -0200 | [diff] [blame] | 2604 | if (trace_flags & TRACE_ITER_CONTEXT_INFO) { |
| 2605 | SEQ_PUT_FIELD_RET(s, entry->pid); |
Steven Rostedt | 1830b52 | 2009-02-07 19:38:43 -0500 | [diff] [blame] | 2606 | SEQ_PUT_FIELD_RET(s, iter->cpu); |
Frederic Weisbecker | c4a8e8b | 2009-02-02 20:29:21 -0200 | [diff] [blame] | 2607 | SEQ_PUT_FIELD_RET(s, iter->ts); |
| 2608 | } |
Ingo Molnar | cb0f12a | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2609 | |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 2610 | event = ftrace_find_event(entry->type); |
Steven Rostedt | a9a5776 | 2010-04-22 18:46:14 -0400 | [diff] [blame] | 2611 | return event ? event->funcs->binary(iter, 0, event) : |
| 2612 | TRACE_TYPE_HANDLED; |
Ingo Molnar | cb0f12a | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2613 | } |
| 2614 | |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 2615 | int trace_empty(struct trace_iterator *iter) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2616 | { |
Steven Rostedt | 6d158a8 | 2012-06-27 20:46:14 -0400 | [diff] [blame] | 2617 | struct ring_buffer_iter *buf_iter; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2618 | int cpu; |
| 2619 | |
Steven Rostedt | 9aba60f | 2009-03-11 19:52:30 -0400 | [diff] [blame] | 2620 | /* If we are looking at one CPU buffer, only check that one */ |
Steven Rostedt | ae3b509 | 2013-01-23 15:22:59 -0500 | [diff] [blame] | 2621 | if (iter->cpu_file != RING_BUFFER_ALL_CPUS) { |
Steven Rostedt | 9aba60f | 2009-03-11 19:52:30 -0400 | [diff] [blame] | 2622 | cpu = iter->cpu_file; |
Steven Rostedt | 6d158a8 | 2012-06-27 20:46:14 -0400 | [diff] [blame] | 2623 | buf_iter = trace_buffer_iter(iter, cpu); |
| 2624 | if (buf_iter) { |
| 2625 | if (!ring_buffer_iter_empty(buf_iter)) |
Steven Rostedt | 9aba60f | 2009-03-11 19:52:30 -0400 | [diff] [blame] | 2626 | return 0; |
| 2627 | } else { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2628 | if (!ring_buffer_empty_cpu(iter->trace_buffer->buffer, cpu)) |
Steven Rostedt | 9aba60f | 2009-03-11 19:52:30 -0400 | [diff] [blame] | 2629 | return 0; |
| 2630 | } |
| 2631 | return 1; |
| 2632 | } |
| 2633 | |
Steven Rostedt | ab46428 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 2634 | for_each_tracing_cpu(cpu) { |
Steven Rostedt | 6d158a8 | 2012-06-27 20:46:14 -0400 | [diff] [blame] | 2635 | buf_iter = trace_buffer_iter(iter, cpu); |
| 2636 | if (buf_iter) { |
| 2637 | if (!ring_buffer_iter_empty(buf_iter)) |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 2638 | return 0; |
| 2639 | } else { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2640 | if (!ring_buffer_empty_cpu(iter->trace_buffer->buffer, cpu)) |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 2641 | return 0; |
| 2642 | } |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2643 | } |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 2644 | |
Frederic Weisbecker | 797d371 | 2008-09-30 18:13:45 +0200 | [diff] [blame] | 2645 | return 1; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2646 | } |
| 2647 | |
Lai Jiangshan | 4f53596 | 2009-05-18 19:35:34 +0800 | [diff] [blame] | 2648 | /* Called with trace_event_read_lock() held. */ |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 2649 | enum print_line_t print_trace_line(struct trace_iterator *iter) |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2650 | { |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 2651 | enum print_line_t ret; |
| 2652 | |
Jiri Olsa | ee5e51f | 2011-03-25 12:05:18 +0100 | [diff] [blame] | 2653 | if (iter->lost_events && |
| 2654 | !trace_seq_printf(&iter->seq, "CPU:%d [LOST %lu EVENTS]\n", |
| 2655 | iter->cpu, iter->lost_events)) |
| 2656 | return TRACE_TYPE_PARTIAL_LINE; |
Steven Rostedt | bc21b47 | 2010-03-31 19:49:26 -0400 | [diff] [blame] | 2657 | |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 2658 | if (iter->trace && iter->trace->print_line) { |
| 2659 | ret = iter->trace->print_line(iter); |
| 2660 | if (ret != TRACE_TYPE_UNHANDLED) |
| 2661 | return ret; |
| 2662 | } |
Thomas Gleixner | 72829bc | 2008-05-23 21:37:28 +0200 | [diff] [blame] | 2663 | |
Steven Rostedt (Red Hat) | 09ae723 | 2013-03-08 21:02:34 -0500 | [diff] [blame] | 2664 | if (iter->ent->type == TRACE_BPUTS && |
| 2665 | trace_flags & TRACE_ITER_PRINTK && |
| 2666 | trace_flags & TRACE_ITER_PRINTK_MSGONLY) |
| 2667 | return trace_print_bputs_msg_only(iter); |
| 2668 | |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 2669 | if (iter->ent->type == TRACE_BPRINT && |
| 2670 | trace_flags & TRACE_ITER_PRINTK && |
| 2671 | trace_flags & TRACE_ITER_PRINTK_MSGONLY) |
Steven Rostedt | 5ef841f | 2009-03-19 12:20:38 -0400 | [diff] [blame] | 2672 | return trace_print_bprintk_msg_only(iter); |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 2673 | |
Frederic Weisbecker | 66896a8 | 2008-12-13 20:18:13 +0100 | [diff] [blame] | 2674 | if (iter->ent->type == TRACE_PRINT && |
| 2675 | trace_flags & TRACE_ITER_PRINTK && |
| 2676 | trace_flags & TRACE_ITER_PRINTK_MSGONLY) |
Steven Rostedt | 5ef841f | 2009-03-19 12:20:38 -0400 | [diff] [blame] | 2677 | return trace_print_printk_msg_only(iter); |
Frederic Weisbecker | 66896a8 | 2008-12-13 20:18:13 +0100 | [diff] [blame] | 2678 | |
Ingo Molnar | cb0f12a | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2679 | if (trace_flags & TRACE_ITER_BIN) |
| 2680 | return print_bin_fmt(iter); |
| 2681 | |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 2682 | if (trace_flags & TRACE_ITER_HEX) |
| 2683 | return print_hex_fmt(iter); |
| 2684 | |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2685 | if (trace_flags & TRACE_ITER_RAW) |
| 2686 | return print_raw_fmt(iter); |
| 2687 | |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2688 | return print_trace_fmt(iter); |
| 2689 | } |
| 2690 | |
Jiri Olsa | 7e9a49e | 2011-11-07 16:08:49 +0100 | [diff] [blame] | 2691 | void trace_latency_header(struct seq_file *m) |
| 2692 | { |
| 2693 | struct trace_iterator *iter = m->private; |
| 2694 | |
| 2695 | /* print nothing if the buffers are empty */ |
| 2696 | if (trace_empty(iter)) |
| 2697 | return; |
| 2698 | |
| 2699 | if (iter->iter_flags & TRACE_FILE_LAT_FMT) |
| 2700 | print_trace_header(m, iter); |
| 2701 | |
| 2702 | if (!(trace_flags & TRACE_ITER_VERBOSE)) |
| 2703 | print_lat_help_header(m); |
| 2704 | } |
| 2705 | |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 2706 | void trace_default_header(struct seq_file *m) |
| 2707 | { |
| 2708 | struct trace_iterator *iter = m->private; |
| 2709 | |
Jiri Olsa | f56e7f8 | 2011-06-03 16:58:49 +0200 | [diff] [blame] | 2710 | if (!(trace_flags & TRACE_ITER_CONTEXT_INFO)) |
| 2711 | return; |
| 2712 | |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 2713 | if (iter->iter_flags & TRACE_FILE_LAT_FMT) { |
| 2714 | /* print nothing if the buffers are empty */ |
| 2715 | if (trace_empty(iter)) |
| 2716 | return; |
| 2717 | print_trace_header(m, iter); |
| 2718 | if (!(trace_flags & TRACE_ITER_VERBOSE)) |
| 2719 | print_lat_help_header(m); |
| 2720 | } else { |
Steven Rostedt | 77271ce | 2011-11-17 09:34:33 -0500 | [diff] [blame] | 2721 | if (!(trace_flags & TRACE_ITER_VERBOSE)) { |
| 2722 | if (trace_flags & TRACE_ITER_IRQ_INFO) |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2723 | print_func_help_header_irq(iter->trace_buffer, m); |
Steven Rostedt | 77271ce | 2011-11-17 09:34:33 -0500 | [diff] [blame] | 2724 | else |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2725 | print_func_help_header(iter->trace_buffer, m); |
Steven Rostedt | 77271ce | 2011-11-17 09:34:33 -0500 | [diff] [blame] | 2726 | } |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 2727 | } |
| 2728 | } |
| 2729 | |
Steven Rostedt | e0a413f | 2011-09-29 21:26:16 -0400 | [diff] [blame] | 2730 | static void test_ftrace_alive(struct seq_file *m) |
| 2731 | { |
| 2732 | if (!ftrace_is_dead()) |
| 2733 | return; |
| 2734 | seq_printf(m, "# WARNING: FUNCTION TRACING IS CORRUPTED\n"); |
| 2735 | seq_printf(m, "# MAY BE MISSING FUNCTION EVENTS\n"); |
| 2736 | } |
| 2737 | |
Steven Rostedt (Red Hat) | d8741e2 | 2013-03-05 10:25:16 -0500 | [diff] [blame] | 2738 | #ifdef CONFIG_TRACER_MAX_TRACE |
Steven Rostedt (Red Hat) | f1affca | 2013-03-05 14:35:11 -0500 | [diff] [blame] | 2739 | static void show_snapshot_main_help(struct seq_file *m) |
Steven Rostedt (Red Hat) | d8741e2 | 2013-03-05 10:25:16 -0500 | [diff] [blame] | 2740 | { |
Steven Rostedt (Red Hat) | d8741e2 | 2013-03-05 10:25:16 -0500 | [diff] [blame] | 2741 | seq_printf(m, "# echo 0 > snapshot : Clears and frees snapshot buffer\n"); |
| 2742 | seq_printf(m, "# echo 1 > snapshot : Allocates snapshot buffer, if not already allocated.\n"); |
| 2743 | seq_printf(m, "# Takes a snapshot of the main buffer.\n"); |
| 2744 | seq_printf(m, "# echo 2 > snapshot : Clears snapshot buffer (but does not allocate)\n"); |
| 2745 | seq_printf(m, "# (Doesn't have to be '2' works with any number that\n"); |
| 2746 | seq_printf(m, "# is not a '0' or '1')\n"); |
| 2747 | } |
Steven Rostedt (Red Hat) | f1affca | 2013-03-05 14:35:11 -0500 | [diff] [blame] | 2748 | |
| 2749 | static void show_snapshot_percpu_help(struct seq_file *m) |
| 2750 | { |
| 2751 | seq_printf(m, "# echo 0 > snapshot : Invalid for per_cpu snapshot file.\n"); |
| 2752 | #ifdef CONFIG_RING_BUFFER_ALLOW_SWAP |
| 2753 | seq_printf(m, "# echo 1 > snapshot : Allocates snapshot buffer, if not already allocated.\n"); |
| 2754 | seq_printf(m, "# Takes a snapshot of the main buffer for this cpu.\n"); |
| 2755 | #else |
| 2756 | seq_printf(m, "# echo 1 > snapshot : Not supported with this kernel.\n"); |
| 2757 | seq_printf(m, "# Must use main snapshot file to allocate.\n"); |
| 2758 | #endif |
| 2759 | seq_printf(m, "# echo 2 > snapshot : Clears this cpu's snapshot buffer (but does not allocate)\n"); |
| 2760 | seq_printf(m, "# (Doesn't have to be '2' works with any number that\n"); |
| 2761 | seq_printf(m, "# is not a '0' or '1')\n"); |
| 2762 | } |
| 2763 | |
Steven Rostedt (Red Hat) | d8741e2 | 2013-03-05 10:25:16 -0500 | [diff] [blame] | 2764 | static void print_snapshot_help(struct seq_file *m, struct trace_iterator *iter) |
| 2765 | { |
Steven Rostedt (Red Hat) | 45ad21c | 2013-03-05 18:25:02 -0500 | [diff] [blame] | 2766 | if (iter->tr->allocated_snapshot) |
Steven Rostedt (Red Hat) | d8741e2 | 2013-03-05 10:25:16 -0500 | [diff] [blame] | 2767 | seq_printf(m, "#\n# * Snapshot is allocated *\n#\n"); |
| 2768 | else |
| 2769 | seq_printf(m, "#\n# * Snapshot is freed *\n#\n"); |
| 2770 | |
| 2771 | seq_printf(m, "# Snapshot commands:\n"); |
Steven Rostedt (Red Hat) | f1affca | 2013-03-05 14:35:11 -0500 | [diff] [blame] | 2772 | if (iter->cpu_file == RING_BUFFER_ALL_CPUS) |
| 2773 | show_snapshot_main_help(m); |
| 2774 | else |
| 2775 | show_snapshot_percpu_help(m); |
Steven Rostedt (Red Hat) | d8741e2 | 2013-03-05 10:25:16 -0500 | [diff] [blame] | 2776 | } |
| 2777 | #else |
| 2778 | /* Should never be called */ |
| 2779 | static inline void print_snapshot_help(struct seq_file *m, struct trace_iterator *iter) { } |
| 2780 | #endif |
| 2781 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2782 | static int s_show(struct seq_file *m, void *v) |
| 2783 | { |
| 2784 | struct trace_iterator *iter = v; |
Steven Rostedt | a63ce5b | 2009-12-07 09:11:39 -0500 | [diff] [blame] | 2785 | int ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2786 | |
| 2787 | if (iter->ent == NULL) { |
| 2788 | if (iter->tr) { |
| 2789 | seq_printf(m, "# tracer: %s\n", iter->trace->name); |
| 2790 | seq_puts(m, "#\n"); |
Steven Rostedt | e0a413f | 2011-09-29 21:26:16 -0400 | [diff] [blame] | 2791 | test_ftrace_alive(m); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2792 | } |
Steven Rostedt (Red Hat) | d8741e2 | 2013-03-05 10:25:16 -0500 | [diff] [blame] | 2793 | if (iter->snapshot && trace_empty(iter)) |
| 2794 | print_snapshot_help(m, iter); |
| 2795 | else if (iter->trace && iter->trace->print_header) |
Markus Metzger | 8bba1bf | 2008-11-25 09:12:31 +0100 | [diff] [blame] | 2796 | iter->trace->print_header(m); |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 2797 | else |
| 2798 | trace_default_header(m); |
| 2799 | |
Steven Rostedt | a63ce5b | 2009-12-07 09:11:39 -0500 | [diff] [blame] | 2800 | } else if (iter->leftover) { |
| 2801 | /* |
| 2802 | * If we filled the seq_file buffer earlier, we |
| 2803 | * want to just show it now. |
| 2804 | */ |
| 2805 | ret = trace_print_seq(m, &iter->seq); |
| 2806 | |
| 2807 | /* ret should this time be zero, but you never know */ |
| 2808 | iter->leftover = ret; |
| 2809 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2810 | } else { |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2811 | print_trace_line(iter); |
Steven Rostedt | a63ce5b | 2009-12-07 09:11:39 -0500 | [diff] [blame] | 2812 | ret = trace_print_seq(m, &iter->seq); |
| 2813 | /* |
| 2814 | * If we overflow the seq_file buffer, then it will |
| 2815 | * ask us for this data again at start up. |
| 2816 | * Use that instead. |
| 2817 | * ret is 0 if seq_file write succeeded. |
| 2818 | * -1 otherwise. |
| 2819 | */ |
| 2820 | iter->leftover = ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2821 | } |
| 2822 | |
| 2823 | return 0; |
| 2824 | } |
| 2825 | |
James Morris | 88e9d34 | 2009-09-22 16:43:43 -0700 | [diff] [blame] | 2826 | static const struct seq_operations tracer_seq_ops = { |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2827 | .start = s_start, |
| 2828 | .next = s_next, |
| 2829 | .stop = s_stop, |
| 2830 | .show = s_show, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2831 | }; |
| 2832 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 2833 | static struct trace_iterator * |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 2834 | __tracing_open(struct inode *inode, struct file *file, bool snapshot) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2835 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 2836 | struct trace_cpu *tc = inode->i_private; |
| 2837 | struct trace_array *tr = tc->tr; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2838 | struct trace_iterator *iter; |
Jiri Olsa | 50e18b9 | 2012-04-25 10:23:39 +0200 | [diff] [blame] | 2839 | int cpu; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2840 | |
Steven Rostedt | 85a2f9b | 2009-02-27 00:12:38 -0500 | [diff] [blame] | 2841 | if (tracing_disabled) |
| 2842 | return ERR_PTR(-ENODEV); |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 2843 | |
Jiri Olsa | 50e18b9 | 2012-04-25 10:23:39 +0200 | [diff] [blame] | 2844 | iter = __seq_open_private(file, &tracer_seq_ops, sizeof(*iter)); |
Steven Rostedt | 85a2f9b | 2009-02-27 00:12:38 -0500 | [diff] [blame] | 2845 | if (!iter) |
| 2846 | return ERR_PTR(-ENOMEM); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2847 | |
Steven Rostedt | 6d158a8 | 2012-06-27 20:46:14 -0400 | [diff] [blame] | 2848 | iter->buffer_iter = kzalloc(sizeof(*iter->buffer_iter) * num_possible_cpus(), |
| 2849 | GFP_KERNEL); |
Dan Carpenter | 93574fc | 2012-07-11 09:35:08 +0300 | [diff] [blame] | 2850 | if (!iter->buffer_iter) |
| 2851 | goto release; |
| 2852 | |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 2853 | /* |
| 2854 | * We make a copy of the current tracer to avoid concurrent |
| 2855 | * changes on it while we are reading. |
| 2856 | */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2857 | mutex_lock(&trace_types_lock); |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 2858 | iter->trace = kzalloc(sizeof(*iter->trace), GFP_KERNEL); |
Steven Rostedt | 85a2f9b | 2009-02-27 00:12:38 -0500 | [diff] [blame] | 2859 | if (!iter->trace) |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 2860 | goto fail; |
Steven Rostedt | 85a2f9b | 2009-02-27 00:12:38 -0500 | [diff] [blame] | 2861 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 2862 | *iter->trace = *tr->current_trace; |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 2863 | |
Li Zefan | 79f5599 | 2009-06-15 14:58:26 +0800 | [diff] [blame] | 2864 | if (!zalloc_cpumask_var(&iter->started, GFP_KERNEL)) |
Frederic Weisbecker | b0dfa97 | 2009-04-01 22:53:08 +0200 | [diff] [blame] | 2865 | goto fail; |
| 2866 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2867 | iter->tr = tr; |
| 2868 | |
| 2869 | #ifdef CONFIG_TRACER_MAX_TRACE |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 2870 | /* Currently only the top directory has a snapshot */ |
| 2871 | if (tr->current_trace->print_max || snapshot) |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2872 | iter->trace_buffer = &tr->max_buffer; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2873 | else |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2874 | #endif |
| 2875 | iter->trace_buffer = &tr->trace_buffer; |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 2876 | iter->snapshot = snapshot; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2877 | iter->pos = -1; |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 2878 | mutex_init(&iter->mutex); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 2879 | iter->cpu_file = tc->cpu; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2880 | |
Markus Metzger | 8bba1bf | 2008-11-25 09:12:31 +0100 | [diff] [blame] | 2881 | /* Notify the tracer early; before we stop tracing. */ |
| 2882 | if (iter->trace && iter->trace->open) |
Markus Metzger | a93751c | 2008-12-11 13:53:26 +0100 | [diff] [blame] | 2883 | iter->trace->open(iter); |
Markus Metzger | 8bba1bf | 2008-11-25 09:12:31 +0100 | [diff] [blame] | 2884 | |
Steven Rostedt | 12ef7d4 | 2008-11-12 17:52:38 -0500 | [diff] [blame] | 2885 | /* Annotate start of buffers if we had overruns */ |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2886 | if (ring_buffer_overruns(iter->trace_buffer->buffer)) |
Steven Rostedt | 12ef7d4 | 2008-11-12 17:52:38 -0500 | [diff] [blame] | 2887 | iter->iter_flags |= TRACE_FILE_ANNOTATE; |
| 2888 | |
David Sharp | 8be0709 | 2012-11-13 12:18:22 -0800 | [diff] [blame] | 2889 | /* Output in nanoseconds only if we are using a clock in nanoseconds. */ |
| 2890 | if (trace_clocks[trace_clock_id].in_ns) |
| 2891 | iter->iter_flags |= TRACE_FILE_TIME_IN_NS; |
| 2892 | |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 2893 | /* stop the trace while dumping if we are not opening "snapshot" */ |
| 2894 | if (!iter->snapshot) |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 2895 | tracing_stop_tr(tr); |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 2896 | |
Steven Rostedt | ae3b509 | 2013-01-23 15:22:59 -0500 | [diff] [blame] | 2897 | if (iter->cpu_file == RING_BUFFER_ALL_CPUS) { |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 2898 | for_each_tracing_cpu(cpu) { |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 2899 | iter->buffer_iter[cpu] = |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2900 | ring_buffer_read_prepare(iter->trace_buffer->buffer, cpu); |
David Miller | 72c9ddf | 2010-04-20 15:47:11 -0700 | [diff] [blame] | 2901 | } |
| 2902 | ring_buffer_read_prepare_sync(); |
| 2903 | for_each_tracing_cpu(cpu) { |
| 2904 | ring_buffer_read_start(iter->buffer_iter[cpu]); |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 2905 | tracing_iter_reset(iter, cpu); |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 2906 | } |
| 2907 | } else { |
| 2908 | cpu = iter->cpu_file; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2909 | iter->buffer_iter[cpu] = |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2910 | ring_buffer_read_prepare(iter->trace_buffer->buffer, cpu); |
David Miller | 72c9ddf | 2010-04-20 15:47:11 -0700 | [diff] [blame] | 2911 | ring_buffer_read_prepare_sync(); |
| 2912 | ring_buffer_read_start(iter->buffer_iter[cpu]); |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 2913 | tracing_iter_reset(iter, cpu); |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2914 | } |
| 2915 | |
Steven Rostedt (Red Hat) | a695cb5 | 2013-03-06 15:27:24 -0500 | [diff] [blame] | 2916 | tr->ref++; |
| 2917 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2918 | mutex_unlock(&trace_types_lock); |
| 2919 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2920 | return iter; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2921 | |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 2922 | fail: |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2923 | mutex_unlock(&trace_types_lock); |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 2924 | kfree(iter->trace); |
Steven Rostedt | 6d158a8 | 2012-06-27 20:46:14 -0400 | [diff] [blame] | 2925 | kfree(iter->buffer_iter); |
Dan Carpenter | 93574fc | 2012-07-11 09:35:08 +0300 | [diff] [blame] | 2926 | release: |
Jiri Olsa | 50e18b9 | 2012-04-25 10:23:39 +0200 | [diff] [blame] | 2927 | seq_release_private(inode, file); |
| 2928 | return ERR_PTR(-ENOMEM); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2929 | } |
| 2930 | |
| 2931 | int tracing_open_generic(struct inode *inode, struct file *filp) |
| 2932 | { |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 2933 | if (tracing_disabled) |
| 2934 | return -ENODEV; |
| 2935 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2936 | filp->private_data = inode->i_private; |
| 2937 | return 0; |
| 2938 | } |
| 2939 | |
Hannes Eder | 4fd2735 | 2009-02-10 19:44:12 +0100 | [diff] [blame] | 2940 | static int tracing_release(struct inode *inode, struct file *file) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2941 | { |
matt mooney | 907f278 | 2010-09-27 19:04:53 -0700 | [diff] [blame] | 2942 | struct seq_file *m = file->private_data; |
Steven Rostedt | 4acd4d0 | 2009-03-18 10:40:24 -0400 | [diff] [blame] | 2943 | struct trace_iterator *iter; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 2944 | struct trace_array *tr; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2945 | int cpu; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2946 | |
Steven Rostedt | 4acd4d0 | 2009-03-18 10:40:24 -0400 | [diff] [blame] | 2947 | if (!(file->f_mode & FMODE_READ)) |
| 2948 | return 0; |
| 2949 | |
| 2950 | iter = m->private; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2951 | tr = iter->tr; |
Steven Rostedt | 4acd4d0 | 2009-03-18 10:40:24 -0400 | [diff] [blame] | 2952 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2953 | mutex_lock(&trace_types_lock); |
Steven Rostedt (Red Hat) | a695cb5 | 2013-03-06 15:27:24 -0500 | [diff] [blame] | 2954 | |
| 2955 | WARN_ON(!tr->ref); |
| 2956 | tr->ref--; |
| 2957 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2958 | for_each_tracing_cpu(cpu) { |
| 2959 | if (iter->buffer_iter[cpu]) |
| 2960 | ring_buffer_read_finish(iter->buffer_iter[cpu]); |
| 2961 | } |
| 2962 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2963 | if (iter->trace && iter->trace->close) |
| 2964 | iter->trace->close(iter); |
| 2965 | |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 2966 | if (!iter->snapshot) |
| 2967 | /* reenable tracing if it was previously enabled */ |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 2968 | tracing_start_tr(tr); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2969 | mutex_unlock(&trace_types_lock); |
| 2970 | |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 2971 | mutex_destroy(&iter->mutex); |
Frederic Weisbecker | b0dfa97 | 2009-04-01 22:53:08 +0200 | [diff] [blame] | 2972 | free_cpumask_var(iter->started); |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 2973 | kfree(iter->trace); |
Steven Rostedt | 6d158a8 | 2012-06-27 20:46:14 -0400 | [diff] [blame] | 2974 | kfree(iter->buffer_iter); |
Jiri Olsa | 50e18b9 | 2012-04-25 10:23:39 +0200 | [diff] [blame] | 2975 | seq_release_private(inode, file); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2976 | return 0; |
| 2977 | } |
| 2978 | |
| 2979 | static int tracing_open(struct inode *inode, struct file *file) |
| 2980 | { |
Steven Rostedt | 85a2f9b | 2009-02-27 00:12:38 -0500 | [diff] [blame] | 2981 | struct trace_iterator *iter; |
| 2982 | int ret = 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2983 | |
Steven Rostedt | 4acd4d0 | 2009-03-18 10:40:24 -0400 | [diff] [blame] | 2984 | /* If this file was open for write, then erase contents */ |
| 2985 | if ((file->f_mode & FMODE_WRITE) && |
Steven Rostedt | 8650ae3 | 2009-07-22 23:29:30 -0400 | [diff] [blame] | 2986 | (file->f_flags & O_TRUNC)) { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 2987 | struct trace_cpu *tc = inode->i_private; |
| 2988 | struct trace_array *tr = tc->tr; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2989 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 2990 | if (tc->cpu == RING_BUFFER_ALL_CPUS) |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2991 | tracing_reset_online_cpus(&tr->trace_buffer); |
Steven Rostedt | 4acd4d0 | 2009-03-18 10:40:24 -0400 | [diff] [blame] | 2992 | else |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2993 | tracing_reset(&tr->trace_buffer, tc->cpu); |
Steven Rostedt | 4acd4d0 | 2009-03-18 10:40:24 -0400 | [diff] [blame] | 2994 | } |
| 2995 | |
| 2996 | if (file->f_mode & FMODE_READ) { |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 2997 | iter = __tracing_open(inode, file, false); |
Steven Rostedt | 4acd4d0 | 2009-03-18 10:40:24 -0400 | [diff] [blame] | 2998 | if (IS_ERR(iter)) |
| 2999 | ret = PTR_ERR(iter); |
| 3000 | else if (trace_flags & TRACE_ITER_LATENCY_FMT) |
| 3001 | iter->iter_flags |= TRACE_FILE_LAT_FMT; |
| 3002 | } |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3003 | return ret; |
| 3004 | } |
| 3005 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 3006 | static void * |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3007 | t_next(struct seq_file *m, void *v, loff_t *pos) |
| 3008 | { |
Li Zefan | f129e96 | 2009-06-24 09:53:44 +0800 | [diff] [blame] | 3009 | struct tracer *t = v; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3010 | |
| 3011 | (*pos)++; |
| 3012 | |
| 3013 | if (t) |
| 3014 | t = t->next; |
| 3015 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3016 | return t; |
| 3017 | } |
| 3018 | |
| 3019 | static void *t_start(struct seq_file *m, loff_t *pos) |
| 3020 | { |
Li Zefan | f129e96 | 2009-06-24 09:53:44 +0800 | [diff] [blame] | 3021 | struct tracer *t; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3022 | loff_t l = 0; |
| 3023 | |
| 3024 | mutex_lock(&trace_types_lock); |
Li Zefan | f129e96 | 2009-06-24 09:53:44 +0800 | [diff] [blame] | 3025 | 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] | 3026 | ; |
| 3027 | |
| 3028 | return t; |
| 3029 | } |
| 3030 | |
| 3031 | static void t_stop(struct seq_file *m, void *p) |
| 3032 | { |
| 3033 | mutex_unlock(&trace_types_lock); |
| 3034 | } |
| 3035 | |
| 3036 | static int t_show(struct seq_file *m, void *v) |
| 3037 | { |
| 3038 | struct tracer *t = v; |
| 3039 | |
| 3040 | if (!t) |
| 3041 | return 0; |
| 3042 | |
| 3043 | seq_printf(m, "%s", t->name); |
| 3044 | if (t->next) |
| 3045 | seq_putc(m, ' '); |
| 3046 | else |
| 3047 | seq_putc(m, '\n'); |
| 3048 | |
| 3049 | return 0; |
| 3050 | } |
| 3051 | |
James Morris | 88e9d34 | 2009-09-22 16:43:43 -0700 | [diff] [blame] | 3052 | static const struct seq_operations show_traces_seq_ops = { |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3053 | .start = t_start, |
| 3054 | .next = t_next, |
| 3055 | .stop = t_stop, |
| 3056 | .show = t_show, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3057 | }; |
| 3058 | |
| 3059 | static int show_traces_open(struct inode *inode, struct file *file) |
| 3060 | { |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 3061 | if (tracing_disabled) |
| 3062 | return -ENODEV; |
| 3063 | |
Li Zefan | f129e96 | 2009-06-24 09:53:44 +0800 | [diff] [blame] | 3064 | return seq_open(file, &show_traces_seq_ops); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3065 | } |
| 3066 | |
Steven Rostedt | 4acd4d0 | 2009-03-18 10:40:24 -0400 | [diff] [blame] | 3067 | static ssize_t |
| 3068 | tracing_write_stub(struct file *filp, const char __user *ubuf, |
| 3069 | size_t count, loff_t *ppos) |
| 3070 | { |
| 3071 | return count; |
| 3072 | } |
| 3073 | |
Slava Pestov | 364829b | 2010-11-24 15:13:16 -0800 | [diff] [blame] | 3074 | static loff_t tracing_seek(struct file *file, loff_t offset, int origin) |
| 3075 | { |
| 3076 | if (file->f_mode & FMODE_READ) |
| 3077 | return seq_lseek(file, offset, origin); |
| 3078 | else |
| 3079 | return 0; |
| 3080 | } |
| 3081 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 3082 | static const struct file_operations tracing_fops = { |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3083 | .open = tracing_open, |
| 3084 | .read = seq_read, |
Steven Rostedt | 4acd4d0 | 2009-03-18 10:40:24 -0400 | [diff] [blame] | 3085 | .write = tracing_write_stub, |
Slava Pestov | 364829b | 2010-11-24 15:13:16 -0800 | [diff] [blame] | 3086 | .llseek = tracing_seek, |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3087 | .release = tracing_release, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3088 | }; |
| 3089 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 3090 | static const struct file_operations show_traces_fops = { |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3091 | .open = show_traces_open, |
| 3092 | .read = seq_read, |
| 3093 | .release = seq_release, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 3094 | .llseek = seq_lseek, |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3095 | }; |
| 3096 | |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3097 | /* |
| 3098 | * Only trace on a CPU if the bitmask is set: |
| 3099 | */ |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 3100 | static cpumask_var_t tracing_cpumask; |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3101 | |
| 3102 | /* |
| 3103 | * The tracer itself will not take this lock, but still we want |
| 3104 | * to provide a consistent cpumask to user-space: |
| 3105 | */ |
| 3106 | static DEFINE_MUTEX(tracing_cpumask_update_lock); |
| 3107 | |
| 3108 | /* |
| 3109 | * Temporary storage for the character representation of the |
| 3110 | * CPU bitmask (and one more byte for the newline): |
| 3111 | */ |
| 3112 | static char mask_str[NR_CPUS + 1]; |
| 3113 | |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3114 | static ssize_t |
| 3115 | tracing_cpumask_read(struct file *filp, char __user *ubuf, |
| 3116 | size_t count, loff_t *ppos) |
| 3117 | { |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3118 | int len; |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3119 | |
| 3120 | mutex_lock(&tracing_cpumask_update_lock); |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3121 | |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 3122 | len = cpumask_scnprintf(mask_str, count, tracing_cpumask); |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3123 | if (count - len < 2) { |
| 3124 | count = -EINVAL; |
| 3125 | goto out_err; |
| 3126 | } |
| 3127 | len += sprintf(mask_str + len, "\n"); |
| 3128 | count = simple_read_from_buffer(ubuf, count, ppos, mask_str, NR_CPUS+1); |
| 3129 | |
| 3130 | out_err: |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3131 | mutex_unlock(&tracing_cpumask_update_lock); |
| 3132 | |
| 3133 | return count; |
| 3134 | } |
| 3135 | |
| 3136 | static ssize_t |
| 3137 | tracing_cpumask_write(struct file *filp, const char __user *ubuf, |
| 3138 | size_t count, loff_t *ppos) |
| 3139 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3140 | struct trace_array *tr = filp->private_data; |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 3141 | cpumask_var_t tracing_cpumask_new; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3142 | int err, cpu; |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 3143 | |
| 3144 | if (!alloc_cpumask_var(&tracing_cpumask_new, GFP_KERNEL)) |
| 3145 | return -ENOMEM; |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3146 | |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 3147 | err = cpumask_parse_user(ubuf, count, tracing_cpumask_new); |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3148 | if (err) |
| 3149 | goto err_unlock; |
| 3150 | |
Li Zefan | 215368e | 2009-06-15 10:56:42 +0800 | [diff] [blame] | 3151 | mutex_lock(&tracing_cpumask_update_lock); |
| 3152 | |
Steven Rostedt | a5e2588 | 2008-12-02 15:34:05 -0500 | [diff] [blame] | 3153 | local_irq_disable(); |
Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 3154 | arch_spin_lock(&ftrace_max_lock); |
Steven Rostedt | ab46428 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 3155 | for_each_tracing_cpu(cpu) { |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3156 | /* |
| 3157 | * Increase/decrease the disabled counter if we are |
| 3158 | * about to flip a bit in the cpumask: |
| 3159 | */ |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 3160 | if (cpumask_test_cpu(cpu, tracing_cpumask) && |
| 3161 | !cpumask_test_cpu(cpu, tracing_cpumask_new)) { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3162 | atomic_inc(&per_cpu_ptr(tr->trace_buffer.data, cpu)->disabled); |
| 3163 | ring_buffer_record_disable_cpu(tr->trace_buffer.buffer, cpu); |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3164 | } |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 3165 | if (!cpumask_test_cpu(cpu, tracing_cpumask) && |
| 3166 | cpumask_test_cpu(cpu, tracing_cpumask_new)) { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3167 | atomic_dec(&per_cpu_ptr(tr->trace_buffer.data, cpu)->disabled); |
| 3168 | ring_buffer_record_enable_cpu(tr->trace_buffer.buffer, cpu); |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3169 | } |
| 3170 | } |
Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 3171 | arch_spin_unlock(&ftrace_max_lock); |
Steven Rostedt | a5e2588 | 2008-12-02 15:34:05 -0500 | [diff] [blame] | 3172 | local_irq_enable(); |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3173 | |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 3174 | cpumask_copy(tracing_cpumask, tracing_cpumask_new); |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3175 | |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3176 | mutex_unlock(&tracing_cpumask_update_lock); |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 3177 | free_cpumask_var(tracing_cpumask_new); |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3178 | |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3179 | return count; |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3180 | |
| 3181 | err_unlock: |
Li Zefan | 215368e | 2009-06-15 10:56:42 +0800 | [diff] [blame] | 3182 | free_cpumask_var(tracing_cpumask_new); |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3183 | |
| 3184 | return err; |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3185 | } |
| 3186 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 3187 | static const struct file_operations tracing_cpumask_fops = { |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3188 | .open = tracing_open_generic, |
| 3189 | .read = tracing_cpumask_read, |
| 3190 | .write = tracing_cpumask_write, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 3191 | .llseek = generic_file_llseek, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3192 | }; |
| 3193 | |
Li Zefan | fdb372e | 2009-12-08 11:15:59 +0800 | [diff] [blame] | 3194 | static int tracing_trace_options_show(struct seq_file *m, void *v) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3195 | { |
Steven Rostedt | d8e83d2 | 2009-02-26 23:55:58 -0500 | [diff] [blame] | 3196 | struct tracer_opt *trace_opts; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3197 | struct trace_array *tr = m->private; |
Steven Rostedt | d8e83d2 | 2009-02-26 23:55:58 -0500 | [diff] [blame] | 3198 | u32 tracer_flags; |
Steven Rostedt | d8e83d2 | 2009-02-26 23:55:58 -0500 | [diff] [blame] | 3199 | int i; |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 3200 | |
Steven Rostedt | d8e83d2 | 2009-02-26 23:55:58 -0500 | [diff] [blame] | 3201 | mutex_lock(&trace_types_lock); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3202 | tracer_flags = tr->current_trace->flags->val; |
| 3203 | trace_opts = tr->current_trace->flags->opts; |
Steven Rostedt | d8e83d2 | 2009-02-26 23:55:58 -0500 | [diff] [blame] | 3204 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3205 | for (i = 0; trace_options[i]; i++) { |
| 3206 | if (trace_flags & (1 << i)) |
Li Zefan | fdb372e | 2009-12-08 11:15:59 +0800 | [diff] [blame] | 3207 | seq_printf(m, "%s\n", trace_options[i]); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3208 | else |
Li Zefan | fdb372e | 2009-12-08 11:15:59 +0800 | [diff] [blame] | 3209 | seq_printf(m, "no%s\n", trace_options[i]); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3210 | } |
| 3211 | |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 3212 | for (i = 0; trace_opts[i].name; i++) { |
| 3213 | if (tracer_flags & trace_opts[i].bit) |
Li Zefan | fdb372e | 2009-12-08 11:15:59 +0800 | [diff] [blame] | 3214 | seq_printf(m, "%s\n", trace_opts[i].name); |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 3215 | else |
Li Zefan | fdb372e | 2009-12-08 11:15:59 +0800 | [diff] [blame] | 3216 | seq_printf(m, "no%s\n", trace_opts[i].name); |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 3217 | } |
Steven Rostedt | d8e83d2 | 2009-02-26 23:55:58 -0500 | [diff] [blame] | 3218 | mutex_unlock(&trace_types_lock); |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 3219 | |
Li Zefan | fdb372e | 2009-12-08 11:15:59 +0800 | [diff] [blame] | 3220 | return 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3221 | } |
| 3222 | |
Li Zefan | 8d18eaa | 2009-12-08 11:17:06 +0800 | [diff] [blame] | 3223 | static int __set_tracer_option(struct tracer *trace, |
| 3224 | struct tracer_flags *tracer_flags, |
| 3225 | struct tracer_opt *opts, int neg) |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 3226 | { |
Li Zefan | 8d18eaa | 2009-12-08 11:17:06 +0800 | [diff] [blame] | 3227 | int ret; |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 3228 | |
Li Zefan | 8d18eaa | 2009-12-08 11:17:06 +0800 | [diff] [blame] | 3229 | ret = trace->set_flag(tracer_flags->val, opts->bit, !neg); |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 3230 | if (ret) |
| 3231 | return ret; |
| 3232 | |
| 3233 | if (neg) |
Zhaolei | 7770841 | 2009-08-07 18:53:21 +0800 | [diff] [blame] | 3234 | tracer_flags->val &= ~opts->bit; |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 3235 | else |
Zhaolei | 7770841 | 2009-08-07 18:53:21 +0800 | [diff] [blame] | 3236 | tracer_flags->val |= opts->bit; |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 3237 | return 0; |
| 3238 | } |
| 3239 | |
Li Zefan | 8d18eaa | 2009-12-08 11:17:06 +0800 | [diff] [blame] | 3240 | /* Try to assign a tracer specific option */ |
| 3241 | static int set_tracer_option(struct tracer *trace, char *cmp, int neg) |
| 3242 | { |
| 3243 | struct tracer_flags *tracer_flags = trace->flags; |
| 3244 | struct tracer_opt *opts = NULL; |
| 3245 | int i; |
| 3246 | |
| 3247 | for (i = 0; tracer_flags->opts[i].name; i++) { |
| 3248 | opts = &tracer_flags->opts[i]; |
| 3249 | |
| 3250 | if (strcmp(cmp, opts->name) == 0) |
| 3251 | return __set_tracer_option(trace, trace->flags, |
| 3252 | opts, neg); |
| 3253 | } |
| 3254 | |
| 3255 | return -EINVAL; |
| 3256 | } |
| 3257 | |
Steven Rostedt (Red Hat) | 613f04a | 2013-03-14 15:03:53 -0400 | [diff] [blame] | 3258 | /* Some tracers require overwrite to stay enabled */ |
| 3259 | int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set) |
| 3260 | { |
| 3261 | if (tracer->enabled && (mask & TRACE_ITER_OVERWRITE) && !set) |
| 3262 | return -1; |
| 3263 | |
| 3264 | return 0; |
| 3265 | } |
| 3266 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3267 | 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] | 3268 | { |
| 3269 | /* do nothing if flag is already set */ |
| 3270 | if (!!(trace_flags & mask) == !!enabled) |
Steven Rostedt (Red Hat) | 613f04a | 2013-03-14 15:03:53 -0400 | [diff] [blame] | 3271 | return 0; |
| 3272 | |
| 3273 | /* Give the tracer a chance to approve the change */ |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3274 | if (tr->current_trace->flag_changed) |
| 3275 | 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] | 3276 | return -EINVAL; |
Steven Rostedt | af4617b | 2009-03-17 18:09:55 -0400 | [diff] [blame] | 3277 | |
| 3278 | if (enabled) |
| 3279 | trace_flags |= mask; |
| 3280 | else |
| 3281 | trace_flags &= ~mask; |
Li Zefan | e870e9a | 2010-07-02 11:07:32 +0800 | [diff] [blame] | 3282 | |
| 3283 | if (mask == TRACE_ITER_RECORD_CMD) |
| 3284 | trace_event_enable_cmd_record(enabled); |
David Sharp | 750912f | 2010-12-08 13:46:47 -0800 | [diff] [blame] | 3285 | |
Steven Rostedt (Red Hat) | 8090282 | 2013-03-14 14:20:54 -0400 | [diff] [blame] | 3286 | if (mask == TRACE_ITER_OVERWRITE) { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3287 | ring_buffer_change_overwrite(tr->trace_buffer.buffer, enabled); |
Steven Rostedt (Red Hat) | 8090282 | 2013-03-14 14:20:54 -0400 | [diff] [blame] | 3288 | #ifdef CONFIG_TRACER_MAX_TRACE |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3289 | ring_buffer_change_overwrite(tr->max_buffer.buffer, enabled); |
Steven Rostedt (Red Hat) | 8090282 | 2013-03-14 14:20:54 -0400 | [diff] [blame] | 3290 | #endif |
| 3291 | } |
Steven Rostedt | 8169883 | 2012-10-11 10:15:05 -0400 | [diff] [blame] | 3292 | |
| 3293 | if (mask == TRACE_ITER_PRINTK) |
| 3294 | trace_printk_start_stop_comm(enabled); |
Steven Rostedt (Red Hat) | 613f04a | 2013-03-14 15:03:53 -0400 | [diff] [blame] | 3295 | |
| 3296 | return 0; |
Steven Rostedt | af4617b | 2009-03-17 18:09:55 -0400 | [diff] [blame] | 3297 | } |
| 3298 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3299 | static int trace_set_options(struct trace_array *tr, char *option) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3300 | { |
Li Zefan | 8d18eaa | 2009-12-08 11:17:06 +0800 | [diff] [blame] | 3301 | char *cmp; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3302 | int neg = 0; |
Steven Rostedt (Red Hat) | 613f04a | 2013-03-14 15:03:53 -0400 | [diff] [blame] | 3303 | int ret = -ENODEV; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3304 | int i; |
| 3305 | |
Steven Rostedt | 7bcfaf5 | 2012-11-01 22:56:07 -0400 | [diff] [blame] | 3306 | cmp = strstrip(option); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3307 | |
Li Zefan | 8d18eaa | 2009-12-08 11:17:06 +0800 | [diff] [blame] | 3308 | if (strncmp(cmp, "no", 2) == 0) { |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3309 | neg = 1; |
| 3310 | cmp += 2; |
| 3311 | } |
| 3312 | |
Steven Rostedt (Red Hat) | 69d34da | 2013-03-14 13:50:56 -0400 | [diff] [blame] | 3313 | mutex_lock(&trace_types_lock); |
| 3314 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3315 | for (i = 0; trace_options[i]; i++) { |
Li Zefan | 8d18eaa | 2009-12-08 11:17:06 +0800 | [diff] [blame] | 3316 | if (strcmp(cmp, trace_options[i]) == 0) { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3317 | ret = set_tracer_flag(tr, 1 << i, !neg); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3318 | break; |
| 3319 | } |
| 3320 | } |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 3321 | |
| 3322 | /* 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] | 3323 | if (!trace_options[i]) |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3324 | ret = set_tracer_option(tr->current_trace, cmp, neg); |
Steven Rostedt (Red Hat) | 69d34da | 2013-03-14 13:50:56 -0400 | [diff] [blame] | 3325 | |
| 3326 | mutex_unlock(&trace_types_lock); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3327 | |
Steven Rostedt | 7bcfaf5 | 2012-11-01 22:56:07 -0400 | [diff] [blame] | 3328 | return ret; |
| 3329 | } |
| 3330 | |
| 3331 | static ssize_t |
| 3332 | tracing_trace_options_write(struct file *filp, const char __user *ubuf, |
| 3333 | size_t cnt, loff_t *ppos) |
| 3334 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3335 | struct seq_file *m = filp->private_data; |
| 3336 | struct trace_array *tr = m->private; |
Steven Rostedt | 7bcfaf5 | 2012-11-01 22:56:07 -0400 | [diff] [blame] | 3337 | char buf[64]; |
Steven Rostedt (Red Hat) | 613f04a | 2013-03-14 15:03:53 -0400 | [diff] [blame] | 3338 | int ret; |
Steven Rostedt | 7bcfaf5 | 2012-11-01 22:56:07 -0400 | [diff] [blame] | 3339 | |
| 3340 | if (cnt >= sizeof(buf)) |
| 3341 | return -EINVAL; |
| 3342 | |
| 3343 | if (copy_from_user(&buf, ubuf, cnt)) |
| 3344 | return -EFAULT; |
| 3345 | |
Steven Rostedt | a8dd217 | 2013-01-09 20:54:17 -0500 | [diff] [blame] | 3346 | buf[cnt] = 0; |
| 3347 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3348 | ret = trace_set_options(tr, buf); |
Steven Rostedt (Red Hat) | 613f04a | 2013-03-14 15:03:53 -0400 | [diff] [blame] | 3349 | if (ret < 0) |
| 3350 | return ret; |
Steven Rostedt | 7bcfaf5 | 2012-11-01 22:56:07 -0400 | [diff] [blame] | 3351 | |
Jiri Olsa | cf8517c | 2009-10-23 19:36:16 -0400 | [diff] [blame] | 3352 | *ppos += cnt; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3353 | |
| 3354 | return cnt; |
| 3355 | } |
| 3356 | |
Li Zefan | fdb372e | 2009-12-08 11:15:59 +0800 | [diff] [blame] | 3357 | static int tracing_trace_options_open(struct inode *inode, struct file *file) |
| 3358 | { |
| 3359 | if (tracing_disabled) |
| 3360 | return -ENODEV; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3361 | |
| 3362 | return single_open(file, tracing_trace_options_show, inode->i_private); |
Li Zefan | fdb372e | 2009-12-08 11:15:59 +0800 | [diff] [blame] | 3363 | } |
| 3364 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 3365 | static const struct file_operations tracing_iter_fops = { |
Li Zefan | fdb372e | 2009-12-08 11:15:59 +0800 | [diff] [blame] | 3366 | .open = tracing_trace_options_open, |
| 3367 | .read = seq_read, |
| 3368 | .llseek = seq_lseek, |
| 3369 | .release = single_release, |
Steven Rostedt | ee6bce5 | 2008-11-12 17:52:37 -0500 | [diff] [blame] | 3370 | .write = tracing_trace_options_write, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3371 | }; |
| 3372 | |
Ingo Molnar | 7bd2f24 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 3373 | static const char readme_msg[] = |
| 3374 | "tracing mini-HOWTO:\n\n" |
Steven Rostedt (Red Hat) | 22f4564 | 2013-03-15 17:23:20 -0400 | [diff] [blame] | 3375 | "# echo 0 > tracing_on : quick way to disable tracing\n" |
| 3376 | "# echo 1 > tracing_on : quick way to re-enable tracing\n\n" |
| 3377 | " Important files:\n" |
| 3378 | " trace\t\t\t- The static contents of the buffer\n" |
| 3379 | "\t\t\t To clear the buffer write into this file: echo > trace\n" |
| 3380 | " trace_pipe\t\t- A consuming read to see the contents of the buffer\n" |
| 3381 | " current_tracer\t- function and latency tracers\n" |
| 3382 | " available_tracers\t- list of configured tracers for current_tracer\n" |
| 3383 | " buffer_size_kb\t- view and modify size of per cpu buffer\n" |
| 3384 | " buffer_total_size_kb - view total size of all cpu buffers\n\n" |
| 3385 | " trace_clock\t\t-change the clock used to order events\n" |
| 3386 | " local: Per cpu clock but may not be synced across CPUs\n" |
| 3387 | " global: Synced across CPUs but slows tracing down.\n" |
| 3388 | " counter: Not a clock, but just an increment\n" |
| 3389 | " uptime: Jiffy counter from time of boot\n" |
| 3390 | " perf: Same clock that perf events use\n" |
| 3391 | #ifdef CONFIG_X86_64 |
| 3392 | " x86-tsc: TSC cycle counter\n" |
| 3393 | #endif |
| 3394 | "\n trace_marker\t\t- Writes into this file writes into the kernel buffer\n" |
| 3395 | " tracing_cpumask\t- Limit which CPUs to trace\n" |
| 3396 | " instances\t\t- Make sub-buffers with: mkdir instances/foo\n" |
| 3397 | "\t\t\t Remove sub-buffer with rmdir\n" |
| 3398 | " trace_options\t\t- Set format or modify how tracing happens\n" |
| 3399 | "\t\t\t Disable an option by adding a suffix 'no' to the option name\n" |
| 3400 | #ifdef CONFIG_DYNAMIC_FTRACE |
| 3401 | "\n available_filter_functions - list of functions that can be filtered on\n" |
| 3402 | " set_ftrace_filter\t- echo function name in here to only trace these functions\n" |
| 3403 | " accepts: func_full_name, *func_end, func_begin*, *func_middle*\n" |
| 3404 | " modules: Can select a group via module\n" |
| 3405 | " Format: :mod:<module-name>\n" |
| 3406 | " example: echo :mod:ext3 > set_ftrace_filter\n" |
| 3407 | " triggers: a command to perform when function is hit\n" |
| 3408 | " Format: <function>:<trigger>[:count]\n" |
| 3409 | " trigger: traceon, traceoff\n" |
| 3410 | " enable_event:<system>:<event>\n" |
| 3411 | " disable_event:<system>:<event>\n" |
| 3412 | #ifdef CONFIG_STACKTRACE |
| 3413 | " stacktrace\n" |
| 3414 | #endif |
| 3415 | #ifdef CONFIG_TRACER_SNAPSHOT |
| 3416 | " snapshot\n" |
| 3417 | #endif |
| 3418 | " example: echo do_fault:traceoff > set_ftrace_filter\n" |
| 3419 | " echo do_trap:traceoff:3 > set_ftrace_filter\n" |
| 3420 | " The first one will disable tracing every time do_fault is hit\n" |
| 3421 | " The second will disable tracing at most 3 times when do_trap is hit\n" |
| 3422 | " The first time do trap is hit and it disables tracing, the counter\n" |
| 3423 | " will decrement to 2. If tracing is already disabled, the counter\n" |
| 3424 | " will not decrement. It only decrements when the trigger did work\n" |
| 3425 | " To remove trigger without count:\n" |
| 3426 | " echo '!<function>:<trigger> > set_ftrace_filter\n" |
| 3427 | " To remove trigger with a count:\n" |
| 3428 | " echo '!<function>:<trigger>:0 > set_ftrace_filter\n" |
| 3429 | " set_ftrace_notrace\t- echo function name in here to never trace.\n" |
| 3430 | " accepts: func_full_name, *func_end, func_begin*, *func_middle*\n" |
| 3431 | " modules: Can select a group via module command :mod:\n" |
| 3432 | " Does not accept triggers\n" |
| 3433 | #endif /* CONFIG_DYNAMIC_FTRACE */ |
| 3434 | #ifdef CONFIG_FUNCTION_TRACER |
| 3435 | " set_ftrace_pid\t- Write pid(s) to only function trace those pids (function)\n" |
| 3436 | #endif |
| 3437 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER |
| 3438 | " set_graph_function\t- Trace the nested calls of a function (function_graph)\n" |
| 3439 | " max_graph_depth\t- Trace a limited depth of nested calls (0 is unlimited)\n" |
| 3440 | #endif |
| 3441 | #ifdef CONFIG_TRACER_SNAPSHOT |
| 3442 | "\n snapshot\t\t- Like 'trace' but shows the content of the static snapshot buffer\n" |
| 3443 | "\t\t\t Read the contents for more information\n" |
| 3444 | #endif |
| 3445 | #ifdef CONFIG_STACKTRACE |
| 3446 | " stack_trace\t\t- Shows the max stack trace when active\n" |
| 3447 | " stack_max_size\t- Shows current max stack size that was traced\n" |
| 3448 | "\t\t\t Write into this file to reset the max size (trigger a new trace)\n" |
| 3449 | #ifdef CONFIG_DYNAMIC_FTRACE |
| 3450 | " stack_trace_filter\t- Like set_ftrace_filter but limits what stack_trace traces\n" |
| 3451 | #endif |
| 3452 | #endif /* CONFIG_STACKTRACE */ |
Ingo Molnar | 7bd2f24 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 3453 | ; |
| 3454 | |
| 3455 | static ssize_t |
| 3456 | tracing_readme_read(struct file *filp, char __user *ubuf, |
| 3457 | size_t cnt, loff_t *ppos) |
| 3458 | { |
| 3459 | return simple_read_from_buffer(ubuf, cnt, ppos, |
| 3460 | readme_msg, strlen(readme_msg)); |
| 3461 | } |
| 3462 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 3463 | static const struct file_operations tracing_readme_fops = { |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3464 | .open = tracing_open_generic, |
| 3465 | .read = tracing_readme_read, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 3466 | .llseek = generic_file_llseek, |
Ingo Molnar | 7bd2f24 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 3467 | }; |
| 3468 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3469 | static ssize_t |
Avadh Patel | 69abe6a | 2009-04-10 16:04:48 -0400 | [diff] [blame] | 3470 | tracing_saved_cmdlines_read(struct file *file, char __user *ubuf, |
| 3471 | size_t cnt, loff_t *ppos) |
| 3472 | { |
| 3473 | char *buf_comm; |
| 3474 | char *file_buf; |
| 3475 | char *buf; |
| 3476 | int len = 0; |
| 3477 | int pid; |
| 3478 | int i; |
| 3479 | |
| 3480 | file_buf = kmalloc(SAVED_CMDLINES*(16+TASK_COMM_LEN), GFP_KERNEL); |
| 3481 | if (!file_buf) |
| 3482 | return -ENOMEM; |
| 3483 | |
| 3484 | buf_comm = kmalloc(TASK_COMM_LEN, GFP_KERNEL); |
| 3485 | if (!buf_comm) { |
| 3486 | kfree(file_buf); |
| 3487 | return -ENOMEM; |
| 3488 | } |
| 3489 | |
| 3490 | buf = file_buf; |
| 3491 | |
| 3492 | for (i = 0; i < SAVED_CMDLINES; i++) { |
| 3493 | int r; |
| 3494 | |
| 3495 | pid = map_cmdline_to_pid[i]; |
| 3496 | if (pid == -1 || pid == NO_CMDLINE_MAP) |
| 3497 | continue; |
| 3498 | |
| 3499 | trace_find_cmdline(pid, buf_comm); |
| 3500 | r = sprintf(buf, "%d %s\n", pid, buf_comm); |
| 3501 | buf += r; |
| 3502 | len += r; |
| 3503 | } |
| 3504 | |
| 3505 | len = simple_read_from_buffer(ubuf, cnt, ppos, |
| 3506 | file_buf, len); |
| 3507 | |
| 3508 | kfree(file_buf); |
| 3509 | kfree(buf_comm); |
| 3510 | |
| 3511 | return len; |
| 3512 | } |
| 3513 | |
| 3514 | static const struct file_operations tracing_saved_cmdlines_fops = { |
| 3515 | .open = tracing_open_generic, |
| 3516 | .read = tracing_saved_cmdlines_read, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 3517 | .llseek = generic_file_llseek, |
Avadh Patel | 69abe6a | 2009-04-10 16:04:48 -0400 | [diff] [blame] | 3518 | }; |
| 3519 | |
| 3520 | static ssize_t |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3521 | tracing_set_trace_read(struct file *filp, char __user *ubuf, |
| 3522 | size_t cnt, loff_t *ppos) |
| 3523 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3524 | struct trace_array *tr = filp->private_data; |
Li Zefan | ee6c2c1 | 2009-09-18 14:06:47 +0800 | [diff] [blame] | 3525 | char buf[MAX_TRACER_SIZE+2]; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3526 | int r; |
| 3527 | |
| 3528 | mutex_lock(&trace_types_lock); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3529 | r = sprintf(buf, "%s\n", tr->current_trace->name); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3530 | mutex_unlock(&trace_types_lock); |
| 3531 | |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3532 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, r); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3533 | } |
| 3534 | |
Arnaldo Carvalho de Melo | b6f11df | 2009-02-05 18:02:00 -0200 | [diff] [blame] | 3535 | int tracer_init(struct tracer *t, struct trace_array *tr) |
| 3536 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3537 | tracing_reset_online_cpus(&tr->trace_buffer); |
Arnaldo Carvalho de Melo | b6f11df | 2009-02-05 18:02:00 -0200 | [diff] [blame] | 3538 | return t->init(tr); |
| 3539 | } |
| 3540 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3541 | static void set_buffer_entries(struct trace_buffer *buf, unsigned long val) |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 3542 | { |
| 3543 | int cpu; |
Steven Rostedt (Red Hat) | 737223f | 2013-03-05 21:13:47 -0500 | [diff] [blame] | 3544 | |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 3545 | for_each_tracing_cpu(cpu) |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3546 | per_cpu_ptr(buf->data, cpu)->entries = val; |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 3547 | } |
| 3548 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3549 | #ifdef CONFIG_TRACER_MAX_TRACE |
Hiraku Toyooka | d60da50 | 2012-10-17 11:56:16 +0900 | [diff] [blame] | 3550 | /* 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] | 3551 | static int resize_buffer_duplicate_size(struct trace_buffer *trace_buf, |
| 3552 | struct trace_buffer *size_buf, int cpu_id) |
Hiraku Toyooka | d60da50 | 2012-10-17 11:56:16 +0900 | [diff] [blame] | 3553 | { |
| 3554 | int cpu, ret = 0; |
| 3555 | |
| 3556 | if (cpu_id == RING_BUFFER_ALL_CPUS) { |
| 3557 | for_each_tracing_cpu(cpu) { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3558 | ret = ring_buffer_resize(trace_buf->buffer, |
| 3559 | per_cpu_ptr(size_buf->data, cpu)->entries, cpu); |
Hiraku Toyooka | d60da50 | 2012-10-17 11:56:16 +0900 | [diff] [blame] | 3560 | if (ret < 0) |
| 3561 | break; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3562 | per_cpu_ptr(trace_buf->data, cpu)->entries = |
| 3563 | per_cpu_ptr(size_buf->data, cpu)->entries; |
Hiraku Toyooka | d60da50 | 2012-10-17 11:56:16 +0900 | [diff] [blame] | 3564 | } |
| 3565 | } else { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3566 | ret = ring_buffer_resize(trace_buf->buffer, |
| 3567 | per_cpu_ptr(size_buf->data, cpu_id)->entries, cpu_id); |
Hiraku Toyooka | d60da50 | 2012-10-17 11:56:16 +0900 | [diff] [blame] | 3568 | if (ret == 0) |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3569 | per_cpu_ptr(trace_buf->data, cpu_id)->entries = |
| 3570 | per_cpu_ptr(size_buf->data, cpu_id)->entries; |
Hiraku Toyooka | d60da50 | 2012-10-17 11:56:16 +0900 | [diff] [blame] | 3571 | } |
| 3572 | |
| 3573 | return ret; |
| 3574 | } |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3575 | #endif /* CONFIG_TRACER_MAX_TRACE */ |
Hiraku Toyooka | d60da50 | 2012-10-17 11:56:16 +0900 | [diff] [blame] | 3576 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3577 | static int __tracing_resize_ring_buffer(struct trace_array *tr, |
| 3578 | unsigned long size, int cpu) |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 3579 | { |
| 3580 | int ret; |
| 3581 | |
| 3582 | /* |
| 3583 | * If kernel or user changes the size of the ring buffer |
Steven Rostedt | a123c52 | 2009-03-12 11:21:08 -0400 | [diff] [blame] | 3584 | * we use the size that was given, and we can forget about |
| 3585 | * expanding it later. |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 3586 | */ |
Steven Rostedt (Red Hat) | 55034cd | 2013-03-07 22:48:09 -0500 | [diff] [blame] | 3587 | ring_buffer_expanded = true; |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 3588 | |
Steven Rostedt | b382ede6 | 2012-10-10 21:44:34 -0400 | [diff] [blame] | 3589 | /* May be called before buffers are initialized */ |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3590 | if (!tr->trace_buffer.buffer) |
Steven Rostedt | b382ede6 | 2012-10-10 21:44:34 -0400 | [diff] [blame] | 3591 | return 0; |
| 3592 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3593 | ret = ring_buffer_resize(tr->trace_buffer.buffer, size, cpu); |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 3594 | if (ret < 0) |
| 3595 | return ret; |
| 3596 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3597 | #ifdef CONFIG_TRACER_MAX_TRACE |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3598 | if (!(tr->flags & TRACE_ARRAY_FL_GLOBAL) || |
| 3599 | !tr->current_trace->use_max_tr) |
KOSAKI Motohiro | ef710e1 | 2010-07-01 14:34:35 +0900 | [diff] [blame] | 3600 | goto out; |
| 3601 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3602 | ret = ring_buffer_resize(tr->max_buffer.buffer, size, cpu); |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 3603 | if (ret < 0) { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3604 | int r = resize_buffer_duplicate_size(&tr->trace_buffer, |
| 3605 | &tr->trace_buffer, cpu); |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 3606 | if (r < 0) { |
Steven Rostedt | a123c52 | 2009-03-12 11:21:08 -0400 | [diff] [blame] | 3607 | /* |
| 3608 | * AARGH! We are left with different |
| 3609 | * size max buffer!!!! |
| 3610 | * The max buffer is our "snapshot" buffer. |
| 3611 | * When a tracer needs a snapshot (one of the |
| 3612 | * latency tracers), it swaps the max buffer |
| 3613 | * with the saved snap shot. We succeeded to |
| 3614 | * update the size of the main buffer, but failed to |
| 3615 | * update the size of the max buffer. But when we tried |
| 3616 | * to reset the main buffer to the original size, we |
| 3617 | * failed there too. This is very unlikely to |
| 3618 | * happen, but if it does, warn and kill all |
| 3619 | * tracing. |
| 3620 | */ |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 3621 | WARN_ON(1); |
| 3622 | tracing_disabled = 1; |
| 3623 | } |
| 3624 | return ret; |
| 3625 | } |
| 3626 | |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 3627 | if (cpu == RING_BUFFER_ALL_CPUS) |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3628 | set_buffer_entries(&tr->max_buffer, size); |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 3629 | else |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3630 | per_cpu_ptr(tr->max_buffer.data, cpu)->entries = size; |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 3631 | |
KOSAKI Motohiro | ef710e1 | 2010-07-01 14:34:35 +0900 | [diff] [blame] | 3632 | out: |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3633 | #endif /* CONFIG_TRACER_MAX_TRACE */ |
| 3634 | |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 3635 | if (cpu == RING_BUFFER_ALL_CPUS) |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3636 | set_buffer_entries(&tr->trace_buffer, size); |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 3637 | else |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3638 | per_cpu_ptr(tr->trace_buffer.data, cpu)->entries = size; |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 3639 | |
| 3640 | return ret; |
| 3641 | } |
| 3642 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3643 | static ssize_t tracing_resize_ring_buffer(struct trace_array *tr, |
| 3644 | unsigned long size, int cpu_id) |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 3645 | { |
Vaibhav Nagarnaik | 83f4031 | 2012-05-03 18:59:50 -0700 | [diff] [blame] | 3646 | int ret = size; |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 3647 | |
| 3648 | mutex_lock(&trace_types_lock); |
| 3649 | |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 3650 | if (cpu_id != RING_BUFFER_ALL_CPUS) { |
| 3651 | /* make sure, this cpu is enabled in the mask */ |
| 3652 | if (!cpumask_test_cpu(cpu_id, tracing_buffer_mask)) { |
| 3653 | ret = -EINVAL; |
| 3654 | goto out; |
| 3655 | } |
| 3656 | } |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 3657 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3658 | ret = __tracing_resize_ring_buffer(tr, size, cpu_id); |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 3659 | if (ret < 0) |
| 3660 | ret = -ENOMEM; |
| 3661 | |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 3662 | out: |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 3663 | mutex_unlock(&trace_types_lock); |
| 3664 | |
| 3665 | return ret; |
| 3666 | } |
| 3667 | |
KOSAKI Motohiro | ef710e1 | 2010-07-01 14:34:35 +0900 | [diff] [blame] | 3668 | |
Steven Rostedt | 1852fcc | 2009-03-11 14:33:00 -0400 | [diff] [blame] | 3669 | /** |
| 3670 | * tracing_update_buffers - used by tracing facility to expand ring buffers |
| 3671 | * |
| 3672 | * To save on memory when the tracing is never used on a system with it |
| 3673 | * configured in. The ring buffers are set to a minimum size. But once |
| 3674 | * a user starts to use the tracing facility, then they need to grow |
| 3675 | * to their default size. |
| 3676 | * |
| 3677 | * This function is to be called when a tracer is about to be used. |
| 3678 | */ |
| 3679 | int tracing_update_buffers(void) |
| 3680 | { |
| 3681 | int ret = 0; |
| 3682 | |
Steven Rostedt | 1027fcb | 2009-03-12 11:33:20 -0400 | [diff] [blame] | 3683 | mutex_lock(&trace_types_lock); |
Steven Rostedt | 1852fcc | 2009-03-11 14:33:00 -0400 | [diff] [blame] | 3684 | if (!ring_buffer_expanded) |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3685 | ret = __tracing_resize_ring_buffer(&global_trace, trace_buf_size, |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 3686 | RING_BUFFER_ALL_CPUS); |
Steven Rostedt | 1027fcb | 2009-03-12 11:33:20 -0400 | [diff] [blame] | 3687 | mutex_unlock(&trace_types_lock); |
Steven Rostedt | 1852fcc | 2009-03-11 14:33:00 -0400 | [diff] [blame] | 3688 | |
| 3689 | return ret; |
| 3690 | } |
| 3691 | |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 3692 | struct trace_option_dentry; |
| 3693 | |
| 3694 | static struct trace_option_dentry * |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3695 | create_trace_option_files(struct trace_array *tr, struct tracer *tracer); |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 3696 | |
| 3697 | static void |
| 3698 | destroy_trace_option_files(struct trace_option_dentry *topts); |
| 3699 | |
Steven Rostedt | b2821ae | 2009-02-02 21:38:32 -0500 | [diff] [blame] | 3700 | static int tracing_set_tracer(const char *buf) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3701 | { |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 3702 | static struct trace_option_dentry *topts; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3703 | struct trace_array *tr = &global_trace; |
| 3704 | struct tracer *t; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3705 | #ifdef CONFIG_TRACER_MAX_TRACE |
Steven Rostedt | 34600f0 | 2013-01-22 13:35:11 -0500 | [diff] [blame] | 3706 | bool had_max_tr; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3707 | #endif |
Peter Zijlstra | d9e5407 | 2008-11-01 19:57:37 +0100 | [diff] [blame] | 3708 | int ret = 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3709 | |
Steven Rostedt | 1027fcb | 2009-03-12 11:33:20 -0400 | [diff] [blame] | 3710 | mutex_lock(&trace_types_lock); |
| 3711 | |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 3712 | if (!ring_buffer_expanded) { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3713 | ret = __tracing_resize_ring_buffer(tr, trace_buf_size, |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 3714 | RING_BUFFER_ALL_CPUS); |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 3715 | if (ret < 0) |
Frederic Weisbecker | 59f586d | 2009-03-15 22:10:39 +0100 | [diff] [blame] | 3716 | goto out; |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 3717 | ret = 0; |
| 3718 | } |
| 3719 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3720 | for (t = trace_types; t; t = t->next) { |
| 3721 | if (strcmp(t->name, buf) == 0) |
| 3722 | break; |
| 3723 | } |
Frederic Weisbecker | c2931e0 | 2008-10-04 22:04:44 +0200 | [diff] [blame] | 3724 | if (!t) { |
| 3725 | ret = -EINVAL; |
| 3726 | goto out; |
| 3727 | } |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3728 | if (t == tr->current_trace) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3729 | goto out; |
| 3730 | |
Steven Rostedt | 9f029e8 | 2008-11-12 15:24:24 -0500 | [diff] [blame] | 3731 | trace_branch_disable(); |
Steven Rostedt (Red Hat) | 613f04a | 2013-03-14 15:03:53 -0400 | [diff] [blame] | 3732 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3733 | tr->current_trace->enabled = false; |
Steven Rostedt (Red Hat) | 613f04a | 2013-03-14 15:03:53 -0400 | [diff] [blame] | 3734 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3735 | if (tr->current_trace->reset) |
| 3736 | tr->current_trace->reset(tr); |
Steven Rostedt | 34600f0 | 2013-01-22 13:35:11 -0500 | [diff] [blame] | 3737 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3738 | /* Current trace needs to be nop_trace before synchronize_sched */ |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3739 | tr->current_trace = &nop_trace; |
Steven Rostedt | 34600f0 | 2013-01-22 13:35:11 -0500 | [diff] [blame] | 3740 | |
Steven Rostedt (Red Hat) | 45ad21c | 2013-03-05 18:25:02 -0500 | [diff] [blame] | 3741 | #ifdef CONFIG_TRACER_MAX_TRACE |
| 3742 | had_max_tr = tr->allocated_snapshot; |
Steven Rostedt | 34600f0 | 2013-01-22 13:35:11 -0500 | [diff] [blame] | 3743 | |
| 3744 | if (had_max_tr && !t->use_max_tr) { |
| 3745 | /* |
| 3746 | * We need to make sure that the update_max_tr sees that |
| 3747 | * current_trace changed to nop_trace to keep it from |
| 3748 | * swapping the buffers after we resize it. |
| 3749 | * The update_max_tr is called from interrupts disabled |
| 3750 | * so a synchronized_sched() is sufficient. |
| 3751 | */ |
| 3752 | synchronize_sched(); |
Steven Rostedt (Red Hat) | 3209cff | 2013-03-12 11:17:54 -0400 | [diff] [blame] | 3753 | free_snapshot(tr); |
KOSAKI Motohiro | ef710e1 | 2010-07-01 14:34:35 +0900 | [diff] [blame] | 3754 | } |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3755 | #endif |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 3756 | destroy_trace_option_files(topts); |
| 3757 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3758 | topts = create_trace_option_files(tr, t); |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3759 | |
| 3760 | #ifdef CONFIG_TRACER_MAX_TRACE |
Steven Rostedt | 34600f0 | 2013-01-22 13:35:11 -0500 | [diff] [blame] | 3761 | if (t->use_max_tr && !had_max_tr) { |
Steven Rostedt (Red Hat) | 3209cff | 2013-03-12 11:17:54 -0400 | [diff] [blame] | 3762 | ret = alloc_snapshot(tr); |
Hiraku Toyooka | d60da50 | 2012-10-17 11:56:16 +0900 | [diff] [blame] | 3763 | if (ret < 0) |
| 3764 | goto out; |
KOSAKI Motohiro | ef710e1 | 2010-07-01 14:34:35 +0900 | [diff] [blame] | 3765 | } |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3766 | #endif |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 3767 | |
Frederic Weisbecker | 1c80025 | 2008-11-16 05:57:26 +0100 | [diff] [blame] | 3768 | if (t->init) { |
Arnaldo Carvalho de Melo | b6f11df | 2009-02-05 18:02:00 -0200 | [diff] [blame] | 3769 | ret = tracer_init(t, tr); |
Frederic Weisbecker | 1c80025 | 2008-11-16 05:57:26 +0100 | [diff] [blame] | 3770 | if (ret) |
| 3771 | goto out; |
| 3772 | } |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3773 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3774 | tr->current_trace = t; |
| 3775 | tr->current_trace->enabled = true; |
Steven Rostedt | 9f029e8 | 2008-11-12 15:24:24 -0500 | [diff] [blame] | 3776 | trace_branch_enable(tr); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3777 | out: |
| 3778 | mutex_unlock(&trace_types_lock); |
| 3779 | |
Peter Zijlstra | d9e5407 | 2008-11-01 19:57:37 +0100 | [diff] [blame] | 3780 | return ret; |
| 3781 | } |
| 3782 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3783 | static ssize_t |
| 3784 | tracing_set_trace_write(struct file *filp, const char __user *ubuf, |
| 3785 | size_t cnt, loff_t *ppos) |
| 3786 | { |
Li Zefan | ee6c2c1 | 2009-09-18 14:06:47 +0800 | [diff] [blame] | 3787 | char buf[MAX_TRACER_SIZE+1]; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3788 | int i; |
| 3789 | size_t ret; |
Frederic Weisbecker | e6e7a65 | 2008-11-16 05:53:19 +0100 | [diff] [blame] | 3790 | int err; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3791 | |
Steven Rostedt | 60063a6 | 2008-10-28 10:44:24 -0400 | [diff] [blame] | 3792 | ret = cnt; |
| 3793 | |
Li Zefan | ee6c2c1 | 2009-09-18 14:06:47 +0800 | [diff] [blame] | 3794 | if (cnt > MAX_TRACER_SIZE) |
| 3795 | cnt = MAX_TRACER_SIZE; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3796 | |
| 3797 | if (copy_from_user(&buf, ubuf, cnt)) |
| 3798 | return -EFAULT; |
| 3799 | |
| 3800 | buf[cnt] = 0; |
| 3801 | |
| 3802 | /* strip ending whitespace. */ |
| 3803 | for (i = cnt - 1; i > 0 && isspace(buf[i]); i--) |
| 3804 | buf[i] = 0; |
| 3805 | |
Frederic Weisbecker | e6e7a65 | 2008-11-16 05:53:19 +0100 | [diff] [blame] | 3806 | err = tracing_set_tracer(buf); |
| 3807 | if (err) |
| 3808 | return err; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3809 | |
Jiri Olsa | cf8517c | 2009-10-23 19:36:16 -0400 | [diff] [blame] | 3810 | *ppos += ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3811 | |
Frederic Weisbecker | c2931e0 | 2008-10-04 22:04:44 +0200 | [diff] [blame] | 3812 | return ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3813 | } |
| 3814 | |
| 3815 | static ssize_t |
| 3816 | tracing_max_lat_read(struct file *filp, char __user *ubuf, |
| 3817 | size_t cnt, loff_t *ppos) |
| 3818 | { |
| 3819 | unsigned long *ptr = filp->private_data; |
| 3820 | char buf[64]; |
| 3821 | int r; |
| 3822 | |
Steven Rostedt | cffae43 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 3823 | r = snprintf(buf, sizeof(buf), "%ld\n", |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3824 | *ptr == (unsigned long)-1 ? -1 : nsecs_to_usecs(*ptr)); |
Steven Rostedt | cffae43 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 3825 | if (r > sizeof(buf)) |
| 3826 | r = sizeof(buf); |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3827 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, r); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3828 | } |
| 3829 | |
| 3830 | static ssize_t |
| 3831 | tracing_max_lat_write(struct file *filp, const char __user *ubuf, |
| 3832 | size_t cnt, loff_t *ppos) |
| 3833 | { |
Hannes Eder | 5e39841 | 2009-02-10 19:44:34 +0100 | [diff] [blame] | 3834 | unsigned long *ptr = filp->private_data; |
Hannes Eder | 5e39841 | 2009-02-10 19:44:34 +0100 | [diff] [blame] | 3835 | unsigned long val; |
Steven Rostedt | c6caeeb | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 3836 | int ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3837 | |
Peter Huewe | 22fe9b5 | 2011-06-07 21:58:27 +0200 | [diff] [blame] | 3838 | ret = kstrtoul_from_user(ubuf, cnt, 10, &val); |
| 3839 | if (ret) |
Steven Rostedt | c6caeeb | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 3840 | return ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3841 | |
| 3842 | *ptr = val * 1000; |
| 3843 | |
| 3844 | return cnt; |
| 3845 | } |
| 3846 | |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3847 | static int tracing_open_pipe(struct inode *inode, struct file *filp) |
| 3848 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3849 | struct trace_cpu *tc = inode->i_private; |
| 3850 | struct trace_array *tr = tc->tr; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3851 | struct trace_iterator *iter; |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 3852 | int ret = 0; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3853 | |
| 3854 | if (tracing_disabled) |
| 3855 | return -ENODEV; |
| 3856 | |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 3857 | mutex_lock(&trace_types_lock); |
| 3858 | |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3859 | /* create a buffer to store the information to pass to userspace */ |
| 3860 | iter = kzalloc(sizeof(*iter), GFP_KERNEL); |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 3861 | if (!iter) { |
| 3862 | ret = -ENOMEM; |
| 3863 | goto out; |
| 3864 | } |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3865 | |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 3866 | /* |
| 3867 | * We make a copy of the current tracer to avoid concurrent |
| 3868 | * changes on it while we are reading. |
| 3869 | */ |
| 3870 | iter->trace = kmalloc(sizeof(*iter->trace), GFP_KERNEL); |
| 3871 | if (!iter->trace) { |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 3872 | ret = -ENOMEM; |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 3873 | goto fail; |
| 3874 | } |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3875 | *iter->trace = *tr->current_trace; |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 3876 | |
| 3877 | if (!alloc_cpumask_var(&iter->started, GFP_KERNEL)) { |
| 3878 | ret = -ENOMEM; |
| 3879 | goto fail; |
Rusty Russell | 4462344 | 2009-01-01 10:12:23 +1030 | [diff] [blame] | 3880 | } |
| 3881 | |
Steven Rostedt | a309720 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 3882 | /* trace pipe does not show start of buffer */ |
Rusty Russell | 4462344 | 2009-01-01 10:12:23 +1030 | [diff] [blame] | 3883 | cpumask_setall(iter->started); |
Steven Rostedt | a309720 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 3884 | |
Steven Rostedt | 112f38a7 | 2009-06-01 15:16:05 -0400 | [diff] [blame] | 3885 | if (trace_flags & TRACE_ITER_LATENCY_FMT) |
| 3886 | iter->iter_flags |= TRACE_FILE_LAT_FMT; |
| 3887 | |
David Sharp | 8be0709 | 2012-11-13 12:18:22 -0800 | [diff] [blame] | 3888 | /* Output in nanoseconds only if we are using a clock in nanoseconds. */ |
| 3889 | if (trace_clocks[trace_clock_id].in_ns) |
| 3890 | iter->iter_flags |= TRACE_FILE_TIME_IN_NS; |
| 3891 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3892 | iter->cpu_file = tc->cpu; |
| 3893 | iter->tr = tc->tr; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3894 | iter->trace_buffer = &tc->tr->trace_buffer; |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 3895 | mutex_init(&iter->mutex); |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3896 | filp->private_data = iter; |
| 3897 | |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 3898 | if (iter->trace->pipe_open) |
| 3899 | iter->trace->pipe_open(iter); |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 3900 | |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 3901 | nonseekable_open(inode, filp); |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 3902 | out: |
| 3903 | mutex_unlock(&trace_types_lock); |
| 3904 | return ret; |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 3905 | |
| 3906 | fail: |
| 3907 | kfree(iter->trace); |
| 3908 | kfree(iter); |
| 3909 | mutex_unlock(&trace_types_lock); |
| 3910 | return ret; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3911 | } |
| 3912 | |
| 3913 | static int tracing_release_pipe(struct inode *inode, struct file *file) |
| 3914 | { |
| 3915 | struct trace_iterator *iter = file->private_data; |
| 3916 | |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 3917 | mutex_lock(&trace_types_lock); |
| 3918 | |
Steven Rostedt | 29bf4a5 | 2009-12-09 12:37:43 -0500 | [diff] [blame] | 3919 | if (iter->trace->pipe_close) |
Steven Rostedt | c521efd | 2009-12-07 09:06:24 -0500 | [diff] [blame] | 3920 | iter->trace->pipe_close(iter); |
| 3921 | |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 3922 | mutex_unlock(&trace_types_lock); |
| 3923 | |
Rusty Russell | 4462344 | 2009-01-01 10:12:23 +1030 | [diff] [blame] | 3924 | free_cpumask_var(iter->started); |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 3925 | mutex_destroy(&iter->mutex); |
| 3926 | kfree(iter->trace); |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3927 | kfree(iter); |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3928 | |
| 3929 | return 0; |
| 3930 | } |
| 3931 | |
Soeren Sandmann Pedersen | 2a2cc8f | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 3932 | static unsigned int |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 3933 | 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] | 3934 | { |
Steven Rostedt (Red Hat) | 1569345 | 2013-02-28 19:59:17 -0500 | [diff] [blame] | 3935 | /* Iterators are static, they should be filled or empty */ |
| 3936 | if (trace_buffer_iter(iter, iter->cpu_file)) |
| 3937 | return POLLIN | POLLRDNORM; |
Soeren Sandmann Pedersen | 2a2cc8f | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 3938 | |
Steven Rostedt (Red Hat) | 1569345 | 2013-02-28 19:59:17 -0500 | [diff] [blame] | 3939 | if (trace_flags & TRACE_ITER_BLOCK) |
Soeren Sandmann Pedersen | 2a2cc8f | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 3940 | /* |
| 3941 | * Always select as readable when in blocking mode |
| 3942 | */ |
| 3943 | return POLLIN | POLLRDNORM; |
Steven Rostedt (Red Hat) | 1569345 | 2013-02-28 19:59:17 -0500 | [diff] [blame] | 3944 | else |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3945 | 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] | 3946 | filp, poll_table); |
Soeren Sandmann Pedersen | 2a2cc8f | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 3947 | } |
Soeren Sandmann Pedersen | 2a2cc8f | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 3948 | |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 3949 | static unsigned int |
| 3950 | tracing_poll_pipe(struct file *filp, poll_table *poll_table) |
| 3951 | { |
| 3952 | struct trace_iterator *iter = filp->private_data; |
| 3953 | |
| 3954 | return trace_poll(iter, filp, poll_table); |
Soeren Sandmann Pedersen | 2a2cc8f | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 3955 | } |
| 3956 | |
Frederic Weisbecker | 6eaaa5d | 2009-02-11 02:25:00 +0100 | [diff] [blame] | 3957 | /* |
| 3958 | * This is a make-shift waitqueue. |
| 3959 | * A tracer might use this callback on some rare cases: |
| 3960 | * |
| 3961 | * 1) the current tracer might hold the runqueue lock when it wakes up |
| 3962 | * a reader, hence a deadlock (sched, function, and function graph tracers) |
| 3963 | * 2) the function tracers, trace all functions, we don't want |
| 3964 | * the overhead of calling wake_up and friends |
| 3965 | * (and tracing them too) |
| 3966 | * |
| 3967 | * Anyway, this is really very primitive wakeup. |
| 3968 | */ |
| 3969 | void poll_wait_pipe(struct trace_iterator *iter) |
| 3970 | { |
| 3971 | set_current_state(TASK_INTERRUPTIBLE); |
| 3972 | /* sleep for 100 msecs, and try again. */ |
| 3973 | schedule_timeout(HZ / 10); |
| 3974 | } |
| 3975 | |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 3976 | /* Must be called with trace_types_lock mutex held. */ |
| 3977 | static int tracing_wait_pipe(struct file *filp) |
| 3978 | { |
| 3979 | struct trace_iterator *iter = filp->private_data; |
| 3980 | |
| 3981 | while (trace_empty(iter)) { |
| 3982 | |
| 3983 | if ((filp->f_flags & O_NONBLOCK)) { |
| 3984 | return -EAGAIN; |
| 3985 | } |
| 3986 | |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 3987 | mutex_unlock(&iter->mutex); |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 3988 | |
Frederic Weisbecker | 6eaaa5d | 2009-02-11 02:25:00 +0100 | [diff] [blame] | 3989 | iter->trace->wait_pipe(iter); |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 3990 | |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 3991 | mutex_lock(&iter->mutex); |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 3992 | |
Frederic Weisbecker | 6eaaa5d | 2009-02-11 02:25:00 +0100 | [diff] [blame] | 3993 | if (signal_pending(current)) |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 3994 | return -EINTR; |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 3995 | |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 3996 | /* |
Liu Bo | 250bfd3 | 2013-01-14 10:54:11 +0800 | [diff] [blame] | 3997 | * We block until we read something and tracing is disabled. |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 3998 | * We still block if tracing is disabled, but we have never |
| 3999 | * read anything. This allows a user to cat this file, and |
| 4000 | * then enable tracing. But after we have read something, |
| 4001 | * we give an EOF when tracing is again disabled. |
| 4002 | * |
| 4003 | * iter->pos will be 0 if we haven't read anything. |
| 4004 | */ |
Steven Rostedt (Red Hat) | 10246fa | 2013-07-01 15:58:24 -0400 | [diff] [blame^] | 4005 | if (!tracing_is_on() && iter->pos) |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 4006 | break; |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 4007 | } |
| 4008 | |
| 4009 | return 1; |
| 4010 | } |
| 4011 | |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4012 | /* |
| 4013 | * Consumer reader. |
| 4014 | */ |
| 4015 | static ssize_t |
| 4016 | tracing_read_pipe(struct file *filp, char __user *ubuf, |
| 4017 | size_t cnt, loff_t *ppos) |
| 4018 | { |
| 4019 | struct trace_iterator *iter = filp->private_data; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4020 | struct trace_array *tr = iter->tr; |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 4021 | ssize_t sret; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4022 | |
| 4023 | /* return any leftover data */ |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 4024 | sret = trace_seq_to_user(&iter->seq, ubuf, cnt); |
| 4025 | if (sret != -EBUSY) |
| 4026 | return sret; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4027 | |
Steven Rostedt | f952075 | 2009-03-02 14:04:40 -0500 | [diff] [blame] | 4028 | trace_seq_init(&iter->seq); |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4029 | |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 4030 | /* copy the tracer to avoid using a global lock all around */ |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 4031 | mutex_lock(&trace_types_lock); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4032 | if (unlikely(iter->trace->name != tr->current_trace->name)) |
| 4033 | *iter->trace = *tr->current_trace; |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 4034 | mutex_unlock(&trace_types_lock); |
| 4035 | |
| 4036 | /* |
| 4037 | * Avoid more than one consumer on a single file descriptor |
| 4038 | * This is just a matter of traces coherency, the ring buffer itself |
| 4039 | * is protected. |
| 4040 | */ |
| 4041 | mutex_lock(&iter->mutex); |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 4042 | if (iter->trace->read) { |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 4043 | sret = iter->trace->read(iter, filp, ubuf, cnt, ppos); |
| 4044 | if (sret) |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 4045 | goto out; |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 4046 | } |
| 4047 | |
Pekka Paalanen | 9ff4b97 | 2008-09-29 20:23:48 +0200 | [diff] [blame] | 4048 | waitagain: |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 4049 | sret = tracing_wait_pipe(filp); |
| 4050 | if (sret <= 0) |
| 4051 | goto out; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4052 | |
| 4053 | /* stop when tracing is finished */ |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 4054 | if (trace_empty(iter)) { |
| 4055 | sret = 0; |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 4056 | goto out; |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 4057 | } |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4058 | |
| 4059 | if (cnt >= PAGE_SIZE) |
| 4060 | cnt = PAGE_SIZE - 1; |
| 4061 | |
Steven Rostedt | 53d0aa7 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 4062 | /* reset all but tr, trace, and overruns */ |
Steven Rostedt | 53d0aa7 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 4063 | memset(&iter->seq, 0, |
| 4064 | sizeof(struct trace_iterator) - |
| 4065 | offsetof(struct trace_iterator, seq)); |
Steven Rostedt | 4823ed7 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 4066 | iter->pos = -1; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4067 | |
Lai Jiangshan | 4f53596 | 2009-05-18 19:35:34 +0800 | [diff] [blame] | 4068 | trace_event_read_lock(); |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 4069 | trace_access_lock(iter->cpu_file); |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 4070 | while (trace_find_next_entry_inc(iter) != NULL) { |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 4071 | enum print_line_t ret; |
Steven Rostedt | 088b1e42 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 4072 | int len = iter->seq.len; |
| 4073 | |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 4074 | ret = print_trace_line(iter); |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 4075 | if (ret == TRACE_TYPE_PARTIAL_LINE) { |
Steven Rostedt | 088b1e42 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 4076 | /* don't print partial lines */ |
| 4077 | iter->seq.len = len; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4078 | break; |
Steven Rostedt | 088b1e42 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 4079 | } |
Frederic Weisbecker | b91facc | 2009-02-06 18:30:44 +0100 | [diff] [blame] | 4080 | if (ret != TRACE_TYPE_NO_CONSUME) |
| 4081 | trace_consume(iter); |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4082 | |
| 4083 | if (iter->seq.len >= cnt) |
| 4084 | break; |
Jiri Olsa | ee5e51f | 2011-03-25 12:05:18 +0100 | [diff] [blame] | 4085 | |
| 4086 | /* |
| 4087 | * Setting the full flag means we reached the trace_seq buffer |
| 4088 | * size and we should leave by partial output condition above. |
| 4089 | * One of the trace_seq_* functions is not used properly. |
| 4090 | */ |
| 4091 | WARN_ONCE(iter->seq.full, "full flag set for trace type %d", |
| 4092 | iter->ent->type); |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4093 | } |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 4094 | trace_access_unlock(iter->cpu_file); |
Lai Jiangshan | 4f53596 | 2009-05-18 19:35:34 +0800 | [diff] [blame] | 4095 | trace_event_read_unlock(); |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4096 | |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4097 | /* Now copy what we have to the user */ |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 4098 | sret = trace_seq_to_user(&iter->seq, ubuf, cnt); |
| 4099 | if (iter->seq.readpos >= iter->seq.len) |
Steven Rostedt | f952075 | 2009-03-02 14:04:40 -0500 | [diff] [blame] | 4100 | trace_seq_init(&iter->seq); |
Pekka Paalanen | 9ff4b97 | 2008-09-29 20:23:48 +0200 | [diff] [blame] | 4101 | |
| 4102 | /* |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 4103 | * 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] | 4104 | * entries, go back to wait for more entries. |
| 4105 | */ |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 4106 | if (sret == -EBUSY) |
Pekka Paalanen | 9ff4b97 | 2008-09-29 20:23:48 +0200 | [diff] [blame] | 4107 | goto waitagain; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4108 | |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 4109 | out: |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 4110 | mutex_unlock(&iter->mutex); |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 4111 | |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 4112 | return sret; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4113 | } |
| 4114 | |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4115 | static void tracing_pipe_buf_release(struct pipe_inode_info *pipe, |
| 4116 | struct pipe_buffer *buf) |
| 4117 | { |
| 4118 | __free_page(buf->page); |
| 4119 | } |
| 4120 | |
| 4121 | static void tracing_spd_release_pipe(struct splice_pipe_desc *spd, |
| 4122 | unsigned int idx) |
| 4123 | { |
| 4124 | __free_page(spd->pages[idx]); |
| 4125 | } |
| 4126 | |
Alexey Dobriyan | 28dfef8 | 2009-12-15 16:46:48 -0800 | [diff] [blame] | 4127 | static const struct pipe_buf_operations tracing_pipe_buf_ops = { |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 4128 | .can_merge = 0, |
| 4129 | .map = generic_pipe_buf_map, |
| 4130 | .unmap = generic_pipe_buf_unmap, |
| 4131 | .confirm = generic_pipe_buf_confirm, |
| 4132 | .release = tracing_pipe_buf_release, |
| 4133 | .steal = generic_pipe_buf_steal, |
| 4134 | .get = generic_pipe_buf_get, |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4135 | }; |
| 4136 | |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 4137 | static size_t |
Frederic Weisbecker | fa7c7f6 | 2009-02-11 02:51:30 +0100 | [diff] [blame] | 4138 | tracing_fill_pipe_page(size_t rem, struct trace_iterator *iter) |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 4139 | { |
| 4140 | size_t count; |
| 4141 | int ret; |
| 4142 | |
| 4143 | /* Seq buffer is page-sized, exactly what we need. */ |
| 4144 | for (;;) { |
| 4145 | count = iter->seq.len; |
| 4146 | ret = print_trace_line(iter); |
| 4147 | count = iter->seq.len - count; |
| 4148 | if (rem < count) { |
| 4149 | rem = 0; |
| 4150 | iter->seq.len -= count; |
| 4151 | break; |
| 4152 | } |
| 4153 | if (ret == TRACE_TYPE_PARTIAL_LINE) { |
| 4154 | iter->seq.len -= count; |
| 4155 | break; |
| 4156 | } |
| 4157 | |
Lai Jiangshan | 74e7ff8 | 2009-07-28 20:17:22 +0800 | [diff] [blame] | 4158 | if (ret != TRACE_TYPE_NO_CONSUME) |
| 4159 | trace_consume(iter); |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 4160 | rem -= count; |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 4161 | if (!trace_find_next_entry_inc(iter)) { |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 4162 | rem = 0; |
| 4163 | iter->ent = NULL; |
| 4164 | break; |
| 4165 | } |
| 4166 | } |
| 4167 | |
| 4168 | return rem; |
| 4169 | } |
| 4170 | |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4171 | static ssize_t tracing_splice_read_pipe(struct file *filp, |
| 4172 | loff_t *ppos, |
| 4173 | struct pipe_inode_info *pipe, |
| 4174 | size_t len, |
| 4175 | unsigned int flags) |
| 4176 | { |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 4177 | struct page *pages_def[PIPE_DEF_BUFFERS]; |
| 4178 | struct partial_page partial_def[PIPE_DEF_BUFFERS]; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4179 | struct trace_iterator *iter = filp->private_data; |
| 4180 | struct splice_pipe_desc spd = { |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 4181 | .pages = pages_def, |
| 4182 | .partial = partial_def, |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 4183 | .nr_pages = 0, /* This gets updated below. */ |
Eric Dumazet | 047fe36 | 2012-06-12 15:24:40 +0200 | [diff] [blame] | 4184 | .nr_pages_max = PIPE_DEF_BUFFERS, |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 4185 | .flags = flags, |
| 4186 | .ops = &tracing_pipe_buf_ops, |
| 4187 | .spd_release = tracing_spd_release_pipe, |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4188 | }; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4189 | struct trace_array *tr = iter->tr; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4190 | ssize_t ret; |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 4191 | size_t rem; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4192 | unsigned int i; |
| 4193 | |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 4194 | if (splice_grow_spd(pipe, &spd)) |
| 4195 | return -ENOMEM; |
| 4196 | |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 4197 | /* copy the tracer to avoid using a global lock all around */ |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4198 | mutex_lock(&trace_types_lock); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4199 | if (unlikely(iter->trace->name != tr->current_trace->name)) |
| 4200 | *iter->trace = *tr->current_trace; |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 4201 | mutex_unlock(&trace_types_lock); |
| 4202 | |
| 4203 | mutex_lock(&iter->mutex); |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4204 | |
| 4205 | if (iter->trace->splice_read) { |
| 4206 | ret = iter->trace->splice_read(iter, filp, |
| 4207 | ppos, pipe, len, flags); |
| 4208 | if (ret) |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 4209 | goto out_err; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4210 | } |
| 4211 | |
| 4212 | ret = tracing_wait_pipe(filp); |
| 4213 | if (ret <= 0) |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 4214 | goto out_err; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4215 | |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 4216 | if (!iter->ent && !trace_find_next_entry_inc(iter)) { |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4217 | ret = -EFAULT; |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 4218 | goto out_err; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4219 | } |
| 4220 | |
Lai Jiangshan | 4f53596 | 2009-05-18 19:35:34 +0800 | [diff] [blame] | 4221 | trace_event_read_lock(); |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 4222 | trace_access_lock(iter->cpu_file); |
Lai Jiangshan | 4f53596 | 2009-05-18 19:35:34 +0800 | [diff] [blame] | 4223 | |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4224 | /* Fill as many pages as possible. */ |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 4225 | for (i = 0, rem = len; i < pipe->buffers && rem; i++) { |
| 4226 | spd.pages[i] = alloc_page(GFP_KERNEL); |
| 4227 | if (!spd.pages[i]) |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 4228 | break; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4229 | |
Frederic Weisbecker | fa7c7f6 | 2009-02-11 02:51:30 +0100 | [diff] [blame] | 4230 | rem = tracing_fill_pipe_page(rem, iter); |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4231 | |
| 4232 | /* Copy the data into the page, so we can start over. */ |
| 4233 | ret = trace_seq_to_buffer(&iter->seq, |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 4234 | page_address(spd.pages[i]), |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4235 | iter->seq.len); |
| 4236 | if (ret < 0) { |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 4237 | __free_page(spd.pages[i]); |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4238 | break; |
| 4239 | } |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 4240 | spd.partial[i].offset = 0; |
| 4241 | spd.partial[i].len = iter->seq.len; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4242 | |
Steven Rostedt | f952075 | 2009-03-02 14:04:40 -0500 | [diff] [blame] | 4243 | trace_seq_init(&iter->seq); |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4244 | } |
| 4245 | |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 4246 | trace_access_unlock(iter->cpu_file); |
Lai Jiangshan | 4f53596 | 2009-05-18 19:35:34 +0800 | [diff] [blame] | 4247 | trace_event_read_unlock(); |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 4248 | mutex_unlock(&iter->mutex); |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4249 | |
| 4250 | spd.nr_pages = i; |
| 4251 | |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 4252 | ret = splice_to_pipe(pipe, &spd); |
| 4253 | out: |
Eric Dumazet | 047fe36 | 2012-06-12 15:24:40 +0200 | [diff] [blame] | 4254 | splice_shrink_spd(&spd); |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 4255 | return ret; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4256 | |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 4257 | out_err: |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 4258 | mutex_unlock(&iter->mutex); |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 4259 | goto out; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4260 | } |
| 4261 | |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 4262 | static ssize_t |
| 4263 | tracing_entries_read(struct file *filp, char __user *ubuf, |
| 4264 | size_t cnt, loff_t *ppos) |
| 4265 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4266 | struct trace_cpu *tc = filp->private_data; |
| 4267 | struct trace_array *tr = tc->tr; |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 4268 | char buf[64]; |
| 4269 | int r = 0; |
| 4270 | ssize_t ret; |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 4271 | |
Steven Rostedt | db526ca | 2009-03-12 13:53:25 -0400 | [diff] [blame] | 4272 | mutex_lock(&trace_types_lock); |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 4273 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4274 | if (tc->cpu == RING_BUFFER_ALL_CPUS) { |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 4275 | int cpu, buf_size_same; |
| 4276 | unsigned long size; |
| 4277 | |
| 4278 | size = 0; |
| 4279 | buf_size_same = 1; |
| 4280 | /* check if all cpu sizes are same */ |
| 4281 | for_each_tracing_cpu(cpu) { |
| 4282 | /* fill in the size from first enabled cpu */ |
| 4283 | if (size == 0) |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4284 | size = per_cpu_ptr(tr->trace_buffer.data, cpu)->entries; |
| 4285 | if (size != per_cpu_ptr(tr->trace_buffer.data, cpu)->entries) { |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 4286 | buf_size_same = 0; |
| 4287 | break; |
| 4288 | } |
| 4289 | } |
| 4290 | |
| 4291 | if (buf_size_same) { |
| 4292 | if (!ring_buffer_expanded) |
| 4293 | r = sprintf(buf, "%lu (expanded: %lu)\n", |
| 4294 | size >> 10, |
| 4295 | trace_buf_size >> 10); |
| 4296 | else |
| 4297 | r = sprintf(buf, "%lu\n", size >> 10); |
| 4298 | } else |
| 4299 | r = sprintf(buf, "X\n"); |
| 4300 | } else |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4301 | r = sprintf(buf, "%lu\n", per_cpu_ptr(tr->trace_buffer.data, tc->cpu)->entries >> 10); |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 4302 | |
Steven Rostedt | db526ca | 2009-03-12 13:53:25 -0400 | [diff] [blame] | 4303 | mutex_unlock(&trace_types_lock); |
| 4304 | |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 4305 | ret = simple_read_from_buffer(ubuf, cnt, ppos, buf, r); |
| 4306 | return ret; |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 4307 | } |
| 4308 | |
| 4309 | static ssize_t |
| 4310 | tracing_entries_write(struct file *filp, const char __user *ubuf, |
| 4311 | size_t cnt, loff_t *ppos) |
| 4312 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4313 | struct trace_cpu *tc = filp->private_data; |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 4314 | unsigned long val; |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 4315 | int ret; |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 4316 | |
Peter Huewe | 22fe9b5 | 2011-06-07 21:58:27 +0200 | [diff] [blame] | 4317 | ret = kstrtoul_from_user(ubuf, cnt, 10, &val); |
| 4318 | if (ret) |
Steven Rostedt | c6caeeb | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 4319 | return ret; |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 4320 | |
| 4321 | /* must have at least 1 entry */ |
| 4322 | if (!val) |
| 4323 | return -EINVAL; |
| 4324 | |
Steven Rostedt | 1696b2b | 2008-11-13 00:09:35 -0500 | [diff] [blame] | 4325 | /* value is in KB */ |
| 4326 | val <<= 10; |
| 4327 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4328 | ret = tracing_resize_ring_buffer(tc->tr, val, tc->cpu); |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 4329 | if (ret < 0) |
| 4330 | return ret; |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 4331 | |
Jiri Olsa | cf8517c | 2009-10-23 19:36:16 -0400 | [diff] [blame] | 4332 | *ppos += cnt; |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 4333 | |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 4334 | return cnt; |
| 4335 | } |
Steven Rostedt | bf5e651 | 2008-11-10 21:46:00 -0500 | [diff] [blame] | 4336 | |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 4337 | static ssize_t |
Vaibhav Nagarnaik | f81ab07 | 2011-08-16 14:46:15 -0700 | [diff] [blame] | 4338 | tracing_total_entries_read(struct file *filp, char __user *ubuf, |
| 4339 | size_t cnt, loff_t *ppos) |
| 4340 | { |
| 4341 | struct trace_array *tr = filp->private_data; |
| 4342 | char buf[64]; |
| 4343 | int r, cpu; |
| 4344 | unsigned long size = 0, expanded_size = 0; |
| 4345 | |
| 4346 | mutex_lock(&trace_types_lock); |
| 4347 | for_each_tracing_cpu(cpu) { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4348 | size += per_cpu_ptr(tr->trace_buffer.data, cpu)->entries >> 10; |
Vaibhav Nagarnaik | f81ab07 | 2011-08-16 14:46:15 -0700 | [diff] [blame] | 4349 | if (!ring_buffer_expanded) |
| 4350 | expanded_size += trace_buf_size >> 10; |
| 4351 | } |
| 4352 | if (ring_buffer_expanded) |
| 4353 | r = sprintf(buf, "%lu\n", size); |
| 4354 | else |
| 4355 | r = sprintf(buf, "%lu (expanded: %lu)\n", size, expanded_size); |
| 4356 | mutex_unlock(&trace_types_lock); |
| 4357 | |
| 4358 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, r); |
| 4359 | } |
| 4360 | |
| 4361 | static ssize_t |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 4362 | tracing_free_buffer_write(struct file *filp, const char __user *ubuf, |
| 4363 | size_t cnt, loff_t *ppos) |
| 4364 | { |
| 4365 | /* |
| 4366 | * There is no need to read what the user has written, this function |
| 4367 | * is just to make sure that there is no error when "echo" is used |
| 4368 | */ |
| 4369 | |
| 4370 | *ppos += cnt; |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 4371 | |
| 4372 | return cnt; |
| 4373 | } |
| 4374 | |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 4375 | static int |
| 4376 | tracing_free_buffer_release(struct inode *inode, struct file *filp) |
| 4377 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4378 | struct trace_array *tr = inode->i_private; |
| 4379 | |
Steven Rostedt | cf30cf6 | 2011-06-14 22:44:07 -0400 | [diff] [blame] | 4380 | /* disable tracing ? */ |
| 4381 | if (trace_flags & TRACE_ITER_STOP_ON_FREE) |
| 4382 | tracing_off(); |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 4383 | /* resize the ring buffer to 0 */ |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4384 | tracing_resize_ring_buffer(tr, 0, RING_BUFFER_ALL_CPUS); |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 4385 | |
| 4386 | return 0; |
| 4387 | } |
| 4388 | |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 4389 | static ssize_t |
| 4390 | tracing_mark_write(struct file *filp, const char __user *ubuf, |
| 4391 | size_t cnt, loff_t *fpos) |
| 4392 | { |
Steven Rostedt | d696b58 | 2011-09-22 11:50:27 -0400 | [diff] [blame] | 4393 | unsigned long addr = (unsigned long)ubuf; |
| 4394 | struct ring_buffer_event *event; |
| 4395 | struct ring_buffer *buffer; |
| 4396 | struct print_entry *entry; |
| 4397 | unsigned long irq_flags; |
| 4398 | struct page *pages[2]; |
Steven Rostedt | 6edb2a8 | 2012-05-11 23:28:49 -0400 | [diff] [blame] | 4399 | void *map_page[2]; |
Steven Rostedt | d696b58 | 2011-09-22 11:50:27 -0400 | [diff] [blame] | 4400 | int nr_pages = 1; |
| 4401 | ssize_t written; |
Steven Rostedt | d696b58 | 2011-09-22 11:50:27 -0400 | [diff] [blame] | 4402 | int offset; |
| 4403 | int size; |
| 4404 | int len; |
| 4405 | int ret; |
Steven Rostedt | 6edb2a8 | 2012-05-11 23:28:49 -0400 | [diff] [blame] | 4406 | int i; |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 4407 | |
Steven Rostedt | c76f069 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 4408 | if (tracing_disabled) |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 4409 | return -EINVAL; |
| 4410 | |
Mandeep Singh Baines | 5224c3a | 2012-09-07 18:12:19 -0700 | [diff] [blame] | 4411 | if (!(trace_flags & TRACE_ITER_MARKERS)) |
| 4412 | return -EINVAL; |
| 4413 | |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 4414 | if (cnt > TRACE_BUF_SIZE) |
| 4415 | cnt = TRACE_BUF_SIZE; |
| 4416 | |
Steven Rostedt | d696b58 | 2011-09-22 11:50:27 -0400 | [diff] [blame] | 4417 | /* |
| 4418 | * Userspace is injecting traces into the kernel trace buffer. |
| 4419 | * We want to be as non intrusive as possible. |
| 4420 | * To do so, we do not want to allocate any special buffers |
| 4421 | * or take any locks, but instead write the userspace data |
| 4422 | * straight into the ring buffer. |
| 4423 | * |
| 4424 | * First we need to pin the userspace buffer into memory, |
| 4425 | * which, most likely it is, because it just referenced it. |
| 4426 | * But there's no guarantee that it is. By using get_user_pages_fast() |
| 4427 | * and kmap_atomic/kunmap_atomic() we can get access to the |
| 4428 | * pages directly. We then write the data directly into the |
| 4429 | * ring buffer. |
| 4430 | */ |
| 4431 | BUILD_BUG_ON(TRACE_BUF_SIZE >= PAGE_SIZE); |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 4432 | |
Steven Rostedt | d696b58 | 2011-09-22 11:50:27 -0400 | [diff] [blame] | 4433 | /* check if we cross pages */ |
| 4434 | if ((addr & PAGE_MASK) != ((addr + cnt) & PAGE_MASK)) |
| 4435 | nr_pages = 2; |
| 4436 | |
| 4437 | offset = addr & (PAGE_SIZE - 1); |
| 4438 | addr &= PAGE_MASK; |
| 4439 | |
| 4440 | ret = get_user_pages_fast(addr, nr_pages, 0, pages); |
| 4441 | if (ret < nr_pages) { |
| 4442 | while (--ret >= 0) |
| 4443 | put_page(pages[ret]); |
| 4444 | written = -EFAULT; |
| 4445 | goto out; |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 4446 | } |
| 4447 | |
Steven Rostedt | 6edb2a8 | 2012-05-11 23:28:49 -0400 | [diff] [blame] | 4448 | for (i = 0; i < nr_pages; i++) |
| 4449 | map_page[i] = kmap_atomic(pages[i]); |
Steven Rostedt | d696b58 | 2011-09-22 11:50:27 -0400 | [diff] [blame] | 4450 | |
| 4451 | local_save_flags(irq_flags); |
| 4452 | size = sizeof(*entry) + cnt + 2; /* possible \n added */ |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4453 | buffer = global_trace.trace_buffer.buffer; |
Steven Rostedt | d696b58 | 2011-09-22 11:50:27 -0400 | [diff] [blame] | 4454 | event = trace_buffer_lock_reserve(buffer, TRACE_PRINT, size, |
| 4455 | irq_flags, preempt_count()); |
| 4456 | if (!event) { |
| 4457 | /* Ring buffer disabled, return as if not open for write */ |
| 4458 | written = -EBADF; |
| 4459 | goto out_unlock; |
| 4460 | } |
| 4461 | |
| 4462 | entry = ring_buffer_event_data(event); |
| 4463 | entry->ip = _THIS_IP_; |
| 4464 | |
| 4465 | if (nr_pages == 2) { |
| 4466 | len = PAGE_SIZE - offset; |
Steven Rostedt | 6edb2a8 | 2012-05-11 23:28:49 -0400 | [diff] [blame] | 4467 | memcpy(&entry->buf, map_page[0] + offset, len); |
| 4468 | memcpy(&entry->buf[len], map_page[1], cnt - len); |
Steven Rostedt | d696b58 | 2011-09-22 11:50:27 -0400 | [diff] [blame] | 4469 | } else |
Steven Rostedt | 6edb2a8 | 2012-05-11 23:28:49 -0400 | [diff] [blame] | 4470 | memcpy(&entry->buf, map_page[0] + offset, cnt); |
Steven Rostedt | d696b58 | 2011-09-22 11:50:27 -0400 | [diff] [blame] | 4471 | |
| 4472 | if (entry->buf[cnt - 1] != '\n') { |
| 4473 | entry->buf[cnt] = '\n'; |
| 4474 | entry->buf[cnt + 1] = '\0'; |
| 4475 | } else |
| 4476 | entry->buf[cnt] = '\0'; |
| 4477 | |
Steven Rostedt | 7ffbd48 | 2012-10-11 12:14:25 -0400 | [diff] [blame] | 4478 | __buffer_unlock_commit(buffer, event); |
Steven Rostedt | d696b58 | 2011-09-22 11:50:27 -0400 | [diff] [blame] | 4479 | |
| 4480 | written = cnt; |
| 4481 | |
Marcin Slusarz | 1aa54bc | 2010-07-28 01:18:01 +0200 | [diff] [blame] | 4482 | *fpos += written; |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 4483 | |
Steven Rostedt | d696b58 | 2011-09-22 11:50:27 -0400 | [diff] [blame] | 4484 | out_unlock: |
Steven Rostedt | 6edb2a8 | 2012-05-11 23:28:49 -0400 | [diff] [blame] | 4485 | for (i = 0; i < nr_pages; i++){ |
| 4486 | kunmap_atomic(map_page[i]); |
| 4487 | put_page(pages[i]); |
| 4488 | } |
Steven Rostedt | d696b58 | 2011-09-22 11:50:27 -0400 | [diff] [blame] | 4489 | out: |
Marcin Slusarz | 1aa54bc | 2010-07-28 01:18:01 +0200 | [diff] [blame] | 4490 | return written; |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 4491 | } |
| 4492 | |
Li Zefan | 13f16d2 | 2009-12-08 11:16:11 +0800 | [diff] [blame] | 4493 | static int tracing_clock_show(struct seq_file *m, void *v) |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 4494 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4495 | struct trace_array *tr = m->private; |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 4496 | int i; |
| 4497 | |
| 4498 | for (i = 0; i < ARRAY_SIZE(trace_clocks); i++) |
Li Zefan | 13f16d2 | 2009-12-08 11:16:11 +0800 | [diff] [blame] | 4499 | seq_printf(m, |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 4500 | "%s%s%s%s", i ? " " : "", |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4501 | i == tr->clock_id ? "[" : "", trace_clocks[i].name, |
| 4502 | i == tr->clock_id ? "]" : ""); |
Li Zefan | 13f16d2 | 2009-12-08 11:16:11 +0800 | [diff] [blame] | 4503 | seq_putc(m, '\n'); |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 4504 | |
Li Zefan | 13f16d2 | 2009-12-08 11:16:11 +0800 | [diff] [blame] | 4505 | return 0; |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 4506 | } |
| 4507 | |
| 4508 | static ssize_t tracing_clock_write(struct file *filp, const char __user *ubuf, |
| 4509 | size_t cnt, loff_t *fpos) |
| 4510 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4511 | struct seq_file *m = filp->private_data; |
| 4512 | struct trace_array *tr = m->private; |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 4513 | char buf[64]; |
| 4514 | const char *clockstr; |
| 4515 | int i; |
| 4516 | |
| 4517 | if (cnt >= sizeof(buf)) |
| 4518 | return -EINVAL; |
| 4519 | |
| 4520 | if (copy_from_user(&buf, ubuf, cnt)) |
| 4521 | return -EFAULT; |
| 4522 | |
| 4523 | buf[cnt] = 0; |
| 4524 | |
| 4525 | clockstr = strstrip(buf); |
| 4526 | |
| 4527 | for (i = 0; i < ARRAY_SIZE(trace_clocks); i++) { |
| 4528 | if (strcmp(trace_clocks[i].name, clockstr) == 0) |
| 4529 | break; |
| 4530 | } |
| 4531 | if (i == ARRAY_SIZE(trace_clocks)) |
| 4532 | return -EINVAL; |
| 4533 | |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 4534 | mutex_lock(&trace_types_lock); |
| 4535 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4536 | tr->clock_id = i; |
| 4537 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4538 | ring_buffer_set_clock(tr->trace_buffer.buffer, trace_clocks[i].func); |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 4539 | |
David Sharp | 60303ed | 2012-10-11 16:27:52 -0700 | [diff] [blame] | 4540 | /* |
| 4541 | * New clock may not be consistent with the previous clock. |
| 4542 | * Reset the buffer so that it doesn't have incomparable timestamps. |
| 4543 | */ |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4544 | tracing_reset_online_cpus(&global_trace.trace_buffer); |
| 4545 | |
| 4546 | #ifdef CONFIG_TRACER_MAX_TRACE |
| 4547 | if (tr->flags & TRACE_ARRAY_FL_GLOBAL && tr->max_buffer.buffer) |
| 4548 | ring_buffer_set_clock(tr->max_buffer.buffer, trace_clocks[i].func); |
| 4549 | tracing_reset_online_cpus(&global_trace.max_buffer); |
| 4550 | #endif |
David Sharp | 60303ed | 2012-10-11 16:27:52 -0700 | [diff] [blame] | 4551 | |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 4552 | mutex_unlock(&trace_types_lock); |
| 4553 | |
| 4554 | *fpos += cnt; |
| 4555 | |
| 4556 | return cnt; |
| 4557 | } |
| 4558 | |
Li Zefan | 13f16d2 | 2009-12-08 11:16:11 +0800 | [diff] [blame] | 4559 | static int tracing_clock_open(struct inode *inode, struct file *file) |
| 4560 | { |
| 4561 | if (tracing_disabled) |
| 4562 | return -ENODEV; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4563 | |
| 4564 | return single_open(file, tracing_clock_show, inode->i_private); |
Li Zefan | 13f16d2 | 2009-12-08 11:16:11 +0800 | [diff] [blame] | 4565 | } |
| 4566 | |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 4567 | struct ftrace_buffer_info { |
| 4568 | struct trace_iterator iter; |
| 4569 | void *spare; |
| 4570 | unsigned int read; |
| 4571 | }; |
| 4572 | |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4573 | #ifdef CONFIG_TRACER_SNAPSHOT |
| 4574 | static int tracing_snapshot_open(struct inode *inode, struct file *file) |
| 4575 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4576 | struct trace_cpu *tc = inode->i_private; |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4577 | struct trace_iterator *iter; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4578 | struct seq_file *m; |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4579 | int ret = 0; |
| 4580 | |
| 4581 | if (file->f_mode & FMODE_READ) { |
| 4582 | iter = __tracing_open(inode, file, true); |
| 4583 | if (IS_ERR(iter)) |
| 4584 | ret = PTR_ERR(iter); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4585 | } else { |
| 4586 | /* Writes still need the seq_file to hold the private data */ |
| 4587 | m = kzalloc(sizeof(*m), GFP_KERNEL); |
| 4588 | if (!m) |
| 4589 | return -ENOMEM; |
| 4590 | iter = kzalloc(sizeof(*iter), GFP_KERNEL); |
| 4591 | if (!iter) { |
| 4592 | kfree(m); |
| 4593 | return -ENOMEM; |
| 4594 | } |
| 4595 | iter->tr = tc->tr; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4596 | iter->trace_buffer = &tc->tr->max_buffer; |
Steven Rostedt (Red Hat) | f1affca | 2013-03-05 14:35:11 -0500 | [diff] [blame] | 4597 | iter->cpu_file = tc->cpu; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4598 | m->private = iter; |
| 4599 | file->private_data = m; |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4600 | } |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4601 | |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4602 | return ret; |
| 4603 | } |
| 4604 | |
| 4605 | static ssize_t |
| 4606 | tracing_snapshot_write(struct file *filp, const char __user *ubuf, size_t cnt, |
| 4607 | loff_t *ppos) |
| 4608 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4609 | struct seq_file *m = filp->private_data; |
| 4610 | struct trace_iterator *iter = m->private; |
| 4611 | struct trace_array *tr = iter->tr; |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4612 | unsigned long val; |
| 4613 | int ret; |
| 4614 | |
| 4615 | ret = tracing_update_buffers(); |
| 4616 | if (ret < 0) |
| 4617 | return ret; |
| 4618 | |
| 4619 | ret = kstrtoul_from_user(ubuf, cnt, 10, &val); |
| 4620 | if (ret) |
| 4621 | return ret; |
| 4622 | |
| 4623 | mutex_lock(&trace_types_lock); |
| 4624 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4625 | if (tr->current_trace->use_max_tr) { |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4626 | ret = -EBUSY; |
| 4627 | goto out; |
| 4628 | } |
| 4629 | |
| 4630 | switch (val) { |
| 4631 | case 0: |
Steven Rostedt (Red Hat) | f1affca | 2013-03-05 14:35:11 -0500 | [diff] [blame] | 4632 | if (iter->cpu_file != RING_BUFFER_ALL_CPUS) { |
| 4633 | ret = -EINVAL; |
| 4634 | break; |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4635 | } |
Steven Rostedt (Red Hat) | 3209cff | 2013-03-12 11:17:54 -0400 | [diff] [blame] | 4636 | if (tr->allocated_snapshot) |
| 4637 | free_snapshot(tr); |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4638 | break; |
| 4639 | case 1: |
Steven Rostedt (Red Hat) | f1affca | 2013-03-05 14:35:11 -0500 | [diff] [blame] | 4640 | /* Only allow per-cpu swap if the ring buffer supports it */ |
| 4641 | #ifndef CONFIG_RING_BUFFER_ALLOW_SWAP |
| 4642 | if (iter->cpu_file != RING_BUFFER_ALL_CPUS) { |
| 4643 | ret = -EINVAL; |
| 4644 | break; |
| 4645 | } |
| 4646 | #endif |
Steven Rostedt (Red Hat) | 45ad21c | 2013-03-05 18:25:02 -0500 | [diff] [blame] | 4647 | if (!tr->allocated_snapshot) { |
Steven Rostedt (Red Hat) | 3209cff | 2013-03-12 11:17:54 -0400 | [diff] [blame] | 4648 | ret = alloc_snapshot(tr); |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4649 | if (ret < 0) |
| 4650 | break; |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4651 | } |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4652 | local_irq_disable(); |
| 4653 | /* Now, we're going to swap */ |
Steven Rostedt (Red Hat) | f1affca | 2013-03-05 14:35:11 -0500 | [diff] [blame] | 4654 | if (iter->cpu_file == RING_BUFFER_ALL_CPUS) |
Steven Rostedt (Red Hat) | ce9bae5 | 2013-03-05 21:23:55 -0500 | [diff] [blame] | 4655 | update_max_tr(tr, current, smp_processor_id()); |
Steven Rostedt (Red Hat) | f1affca | 2013-03-05 14:35:11 -0500 | [diff] [blame] | 4656 | else |
Steven Rostedt (Red Hat) | ce9bae5 | 2013-03-05 21:23:55 -0500 | [diff] [blame] | 4657 | update_max_tr_single(tr, current, iter->cpu_file); |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4658 | local_irq_enable(); |
| 4659 | break; |
| 4660 | default: |
Steven Rostedt (Red Hat) | 45ad21c | 2013-03-05 18:25:02 -0500 | [diff] [blame] | 4661 | if (tr->allocated_snapshot) { |
Steven Rostedt (Red Hat) | f1affca | 2013-03-05 14:35:11 -0500 | [diff] [blame] | 4662 | if (iter->cpu_file == RING_BUFFER_ALL_CPUS) |
| 4663 | tracing_reset_online_cpus(&tr->max_buffer); |
| 4664 | else |
| 4665 | tracing_reset(&tr->max_buffer, iter->cpu_file); |
| 4666 | } |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4667 | break; |
| 4668 | } |
| 4669 | |
| 4670 | if (ret >= 0) { |
| 4671 | *ppos += cnt; |
| 4672 | ret = cnt; |
| 4673 | } |
| 4674 | out: |
| 4675 | mutex_unlock(&trace_types_lock); |
| 4676 | return ret; |
| 4677 | } |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4678 | |
| 4679 | static int tracing_snapshot_release(struct inode *inode, struct file *file) |
| 4680 | { |
| 4681 | struct seq_file *m = file->private_data; |
| 4682 | |
| 4683 | if (file->f_mode & FMODE_READ) |
| 4684 | return tracing_release(inode, file); |
| 4685 | |
| 4686 | /* If write only, the seq_file is just a stub */ |
| 4687 | if (m) |
| 4688 | kfree(m->private); |
| 4689 | kfree(m); |
| 4690 | |
| 4691 | return 0; |
| 4692 | } |
| 4693 | |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 4694 | static int tracing_buffers_open(struct inode *inode, struct file *filp); |
| 4695 | static ssize_t tracing_buffers_read(struct file *filp, char __user *ubuf, |
| 4696 | size_t count, loff_t *ppos); |
| 4697 | static int tracing_buffers_release(struct inode *inode, struct file *file); |
| 4698 | static ssize_t tracing_buffers_splice_read(struct file *file, loff_t *ppos, |
| 4699 | struct pipe_inode_info *pipe, size_t len, unsigned int flags); |
| 4700 | |
| 4701 | static int snapshot_raw_open(struct inode *inode, struct file *filp) |
| 4702 | { |
| 4703 | struct ftrace_buffer_info *info; |
| 4704 | int ret; |
| 4705 | |
| 4706 | ret = tracing_buffers_open(inode, filp); |
| 4707 | if (ret < 0) |
| 4708 | return ret; |
| 4709 | |
| 4710 | info = filp->private_data; |
| 4711 | |
| 4712 | if (info->iter.trace->use_max_tr) { |
| 4713 | tracing_buffers_release(inode, filp); |
| 4714 | return -EBUSY; |
| 4715 | } |
| 4716 | |
| 4717 | info->iter.snapshot = true; |
| 4718 | info->iter.trace_buffer = &info->iter.tr->max_buffer; |
| 4719 | |
| 4720 | return ret; |
| 4721 | } |
| 4722 | |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4723 | #endif /* CONFIG_TRACER_SNAPSHOT */ |
| 4724 | |
| 4725 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 4726 | static const struct file_operations tracing_max_lat_fops = { |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4727 | .open = tracing_open_generic, |
| 4728 | .read = tracing_max_lat_read, |
| 4729 | .write = tracing_max_lat_write, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 4730 | .llseek = generic_file_llseek, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4731 | }; |
| 4732 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 4733 | static const struct file_operations set_tracer_fops = { |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4734 | .open = tracing_open_generic, |
| 4735 | .read = tracing_set_trace_read, |
| 4736 | .write = tracing_set_trace_write, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 4737 | .llseek = generic_file_llseek, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4738 | }; |
| 4739 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 4740 | static const struct file_operations tracing_pipe_fops = { |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4741 | .open = tracing_open_pipe, |
Soeren Sandmann Pedersen | 2a2cc8f | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 4742 | .poll = tracing_poll_pipe, |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4743 | .read = tracing_read_pipe, |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4744 | .splice_read = tracing_splice_read_pipe, |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4745 | .release = tracing_release_pipe, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 4746 | .llseek = no_llseek, |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4747 | }; |
| 4748 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 4749 | static const struct file_operations tracing_entries_fops = { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4750 | .open = tracing_open_generic, |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 4751 | .read = tracing_entries_read, |
| 4752 | .write = tracing_entries_write, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 4753 | .llseek = generic_file_llseek, |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 4754 | }; |
| 4755 | |
Vaibhav Nagarnaik | f81ab07 | 2011-08-16 14:46:15 -0700 | [diff] [blame] | 4756 | static const struct file_operations tracing_total_entries_fops = { |
| 4757 | .open = tracing_open_generic, |
| 4758 | .read = tracing_total_entries_read, |
| 4759 | .llseek = generic_file_llseek, |
| 4760 | }; |
| 4761 | |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 4762 | static const struct file_operations tracing_free_buffer_fops = { |
| 4763 | .write = tracing_free_buffer_write, |
| 4764 | .release = tracing_free_buffer_release, |
| 4765 | }; |
| 4766 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 4767 | static const struct file_operations tracing_mark_fops = { |
Frédéric Weisbecker | 43a1538 | 2008-09-21 20:16:30 +0200 | [diff] [blame] | 4768 | .open = tracing_open_generic, |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 4769 | .write = tracing_mark_write, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 4770 | .llseek = generic_file_llseek, |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 4771 | }; |
| 4772 | |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 4773 | static const struct file_operations trace_clock_fops = { |
Li Zefan | 13f16d2 | 2009-12-08 11:16:11 +0800 | [diff] [blame] | 4774 | .open = tracing_clock_open, |
| 4775 | .read = seq_read, |
| 4776 | .llseek = seq_lseek, |
| 4777 | .release = single_release, |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 4778 | .write = tracing_clock_write, |
| 4779 | }; |
| 4780 | |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4781 | #ifdef CONFIG_TRACER_SNAPSHOT |
| 4782 | static const struct file_operations snapshot_fops = { |
| 4783 | .open = tracing_snapshot_open, |
| 4784 | .read = seq_read, |
| 4785 | .write = tracing_snapshot_write, |
| 4786 | .llseek = tracing_seek, |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4787 | .release = tracing_snapshot_release, |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4788 | }; |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4789 | |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 4790 | static const struct file_operations snapshot_raw_fops = { |
| 4791 | .open = snapshot_raw_open, |
| 4792 | .read = tracing_buffers_read, |
| 4793 | .release = tracing_buffers_release, |
| 4794 | .splice_read = tracing_buffers_splice_read, |
| 4795 | .llseek = no_llseek, |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4796 | }; |
| 4797 | |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 4798 | #endif /* CONFIG_TRACER_SNAPSHOT */ |
| 4799 | |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4800 | static int tracing_buffers_open(struct inode *inode, struct file *filp) |
| 4801 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4802 | struct trace_cpu *tc = inode->i_private; |
| 4803 | struct trace_array *tr = tc->tr; |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4804 | struct ftrace_buffer_info *info; |
| 4805 | |
| 4806 | if (tracing_disabled) |
| 4807 | return -ENODEV; |
| 4808 | |
| 4809 | info = kzalloc(sizeof(*info), GFP_KERNEL); |
| 4810 | if (!info) |
| 4811 | return -ENOMEM; |
| 4812 | |
Steven Rostedt (Red Hat) | a695cb5 | 2013-03-06 15:27:24 -0500 | [diff] [blame] | 4813 | mutex_lock(&trace_types_lock); |
| 4814 | |
| 4815 | tr->ref++; |
| 4816 | |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 4817 | info->iter.tr = tr; |
| 4818 | info->iter.cpu_file = tc->cpu; |
Steven Rostedt | b627344 | 2013-02-28 13:44:11 -0500 | [diff] [blame] | 4819 | info->iter.trace = tr->current_trace; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4820 | info->iter.trace_buffer = &tr->trace_buffer; |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 4821 | info->spare = NULL; |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4822 | /* Force reading ring buffer for first read */ |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 4823 | info->read = (unsigned int)-1; |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4824 | |
| 4825 | filp->private_data = info; |
| 4826 | |
Steven Rostedt (Red Hat) | a695cb5 | 2013-03-06 15:27:24 -0500 | [diff] [blame] | 4827 | mutex_unlock(&trace_types_lock); |
| 4828 | |
Lai Jiangshan | d1e7e02 | 2009-04-02 15:16:56 +0800 | [diff] [blame] | 4829 | return nonseekable_open(inode, filp); |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4830 | } |
| 4831 | |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 4832 | static unsigned int |
| 4833 | tracing_buffers_poll(struct file *filp, poll_table *poll_table) |
| 4834 | { |
| 4835 | struct ftrace_buffer_info *info = filp->private_data; |
| 4836 | struct trace_iterator *iter = &info->iter; |
| 4837 | |
| 4838 | return trace_poll(iter, filp, poll_table); |
| 4839 | } |
| 4840 | |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4841 | static ssize_t |
| 4842 | tracing_buffers_read(struct file *filp, char __user *ubuf, |
| 4843 | size_t count, loff_t *ppos) |
| 4844 | { |
| 4845 | struct ftrace_buffer_info *info = filp->private_data; |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 4846 | struct trace_iterator *iter = &info->iter; |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4847 | ssize_t ret; |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 4848 | ssize_t size; |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4849 | |
Steven Rostedt | 2dc5d12 | 2009-03-04 19:10:05 -0500 | [diff] [blame] | 4850 | if (!count) |
| 4851 | return 0; |
| 4852 | |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 4853 | mutex_lock(&trace_types_lock); |
| 4854 | |
| 4855 | #ifdef CONFIG_TRACER_MAX_TRACE |
| 4856 | if (iter->snapshot && iter->tr->current_trace->use_max_tr) { |
| 4857 | size = -EBUSY; |
| 4858 | goto out_unlock; |
| 4859 | } |
| 4860 | #endif |
| 4861 | |
Lai Jiangshan | ddd538f | 2009-04-02 15:16:59 +0800 | [diff] [blame] | 4862 | if (!info->spare) |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4863 | info->spare = ring_buffer_alloc_read_page(iter->trace_buffer->buffer, |
| 4864 | iter->cpu_file); |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 4865 | size = -ENOMEM; |
Lai Jiangshan | ddd538f | 2009-04-02 15:16:59 +0800 | [diff] [blame] | 4866 | if (!info->spare) |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 4867 | goto out_unlock; |
Lai Jiangshan | ddd538f | 2009-04-02 15:16:59 +0800 | [diff] [blame] | 4868 | |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4869 | /* Do we have previous read data to read? */ |
| 4870 | if (info->read < PAGE_SIZE) |
| 4871 | goto read; |
| 4872 | |
Steven Rostedt | b627344 | 2013-02-28 13:44:11 -0500 | [diff] [blame] | 4873 | again: |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 4874 | trace_access_lock(iter->cpu_file); |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4875 | ret = ring_buffer_read_page(iter->trace_buffer->buffer, |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4876 | &info->spare, |
| 4877 | count, |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 4878 | iter->cpu_file, 0); |
| 4879 | trace_access_unlock(iter->cpu_file); |
Steven Rostedt | b627344 | 2013-02-28 13:44:11 -0500 | [diff] [blame] | 4880 | |
| 4881 | if (ret < 0) { |
| 4882 | if (trace_empty(iter)) { |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 4883 | if ((filp->f_flags & O_NONBLOCK)) { |
| 4884 | size = -EAGAIN; |
| 4885 | goto out_unlock; |
| 4886 | } |
| 4887 | mutex_unlock(&trace_types_lock); |
Steven Rostedt | b627344 | 2013-02-28 13:44:11 -0500 | [diff] [blame] | 4888 | iter->trace->wait_pipe(iter); |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 4889 | mutex_lock(&trace_types_lock); |
| 4890 | if (signal_pending(current)) { |
| 4891 | size = -EINTR; |
| 4892 | goto out_unlock; |
| 4893 | } |
Steven Rostedt | b627344 | 2013-02-28 13:44:11 -0500 | [diff] [blame] | 4894 | goto again; |
| 4895 | } |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 4896 | size = 0; |
| 4897 | goto out_unlock; |
Steven Rostedt | b627344 | 2013-02-28 13:44:11 -0500 | [diff] [blame] | 4898 | } |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4899 | |
Steven Rostedt | 436fc28 | 2011-10-14 10:44:25 -0400 | [diff] [blame] | 4900 | info->read = 0; |
Steven Rostedt | b627344 | 2013-02-28 13:44:11 -0500 | [diff] [blame] | 4901 | read: |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4902 | size = PAGE_SIZE - info->read; |
| 4903 | if (size > count) |
| 4904 | size = count; |
| 4905 | |
| 4906 | ret = copy_to_user(ubuf, info->spare + info->read, size); |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 4907 | if (ret == size) { |
| 4908 | size = -EFAULT; |
| 4909 | goto out_unlock; |
| 4910 | } |
Steven Rostedt | 2dc5d12 | 2009-03-04 19:10:05 -0500 | [diff] [blame] | 4911 | size -= ret; |
| 4912 | |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4913 | *ppos += size; |
| 4914 | info->read += size; |
| 4915 | |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 4916 | out_unlock: |
| 4917 | mutex_unlock(&trace_types_lock); |
| 4918 | |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4919 | return size; |
| 4920 | } |
| 4921 | |
| 4922 | static int tracing_buffers_release(struct inode *inode, struct file *file) |
| 4923 | { |
| 4924 | struct ftrace_buffer_info *info = file->private_data; |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 4925 | struct trace_iterator *iter = &info->iter; |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4926 | |
Steven Rostedt (Red Hat) | a695cb5 | 2013-03-06 15:27:24 -0500 | [diff] [blame] | 4927 | mutex_lock(&trace_types_lock); |
| 4928 | |
| 4929 | WARN_ON(!iter->tr->ref); |
| 4930 | iter->tr->ref--; |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4931 | |
Lai Jiangshan | ddd538f | 2009-04-02 15:16:59 +0800 | [diff] [blame] | 4932 | if (info->spare) |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4933 | ring_buffer_free_read_page(iter->trace_buffer->buffer, info->spare); |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4934 | kfree(info); |
| 4935 | |
Steven Rostedt (Red Hat) | a695cb5 | 2013-03-06 15:27:24 -0500 | [diff] [blame] | 4936 | mutex_unlock(&trace_types_lock); |
| 4937 | |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4938 | return 0; |
| 4939 | } |
| 4940 | |
| 4941 | struct buffer_ref { |
| 4942 | struct ring_buffer *buffer; |
| 4943 | void *page; |
| 4944 | int ref; |
| 4945 | }; |
| 4946 | |
| 4947 | static void buffer_pipe_buf_release(struct pipe_inode_info *pipe, |
| 4948 | struct pipe_buffer *buf) |
| 4949 | { |
| 4950 | struct buffer_ref *ref = (struct buffer_ref *)buf->private; |
| 4951 | |
| 4952 | if (--ref->ref) |
| 4953 | return; |
| 4954 | |
| 4955 | ring_buffer_free_read_page(ref->buffer, ref->page); |
| 4956 | kfree(ref); |
| 4957 | buf->private = 0; |
| 4958 | } |
| 4959 | |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4960 | static void buffer_pipe_buf_get(struct pipe_inode_info *pipe, |
| 4961 | struct pipe_buffer *buf) |
| 4962 | { |
| 4963 | struct buffer_ref *ref = (struct buffer_ref *)buf->private; |
| 4964 | |
| 4965 | ref->ref++; |
| 4966 | } |
| 4967 | |
| 4968 | /* Pipe buffer operations for a buffer. */ |
Alexey Dobriyan | 28dfef8 | 2009-12-15 16:46:48 -0800 | [diff] [blame] | 4969 | static const struct pipe_buf_operations buffer_pipe_buf_ops = { |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4970 | .can_merge = 0, |
| 4971 | .map = generic_pipe_buf_map, |
| 4972 | .unmap = generic_pipe_buf_unmap, |
| 4973 | .confirm = generic_pipe_buf_confirm, |
| 4974 | .release = buffer_pipe_buf_release, |
Masami Hiramatsu | d55cb6c | 2012-08-09 21:31:10 +0900 | [diff] [blame] | 4975 | .steal = generic_pipe_buf_steal, |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4976 | .get = buffer_pipe_buf_get, |
| 4977 | }; |
| 4978 | |
| 4979 | /* |
| 4980 | * Callback from splice_to_pipe(), if we need to release some pages |
| 4981 | * at the end of the spd in case we error'ed out in filling the pipe. |
| 4982 | */ |
| 4983 | static void buffer_spd_release(struct splice_pipe_desc *spd, unsigned int i) |
| 4984 | { |
| 4985 | struct buffer_ref *ref = |
| 4986 | (struct buffer_ref *)spd->partial[i].private; |
| 4987 | |
| 4988 | if (--ref->ref) |
| 4989 | return; |
| 4990 | |
| 4991 | ring_buffer_free_read_page(ref->buffer, ref->page); |
| 4992 | kfree(ref); |
| 4993 | spd->partial[i].private = 0; |
| 4994 | } |
| 4995 | |
| 4996 | static ssize_t |
| 4997 | tracing_buffers_splice_read(struct file *file, loff_t *ppos, |
| 4998 | struct pipe_inode_info *pipe, size_t len, |
| 4999 | unsigned int flags) |
| 5000 | { |
| 5001 | struct ftrace_buffer_info *info = file->private_data; |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 5002 | struct trace_iterator *iter = &info->iter; |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 5003 | struct partial_page partial_def[PIPE_DEF_BUFFERS]; |
| 5004 | struct page *pages_def[PIPE_DEF_BUFFERS]; |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5005 | struct splice_pipe_desc spd = { |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 5006 | .pages = pages_def, |
| 5007 | .partial = partial_def, |
Eric Dumazet | 047fe36 | 2012-06-12 15:24:40 +0200 | [diff] [blame] | 5008 | .nr_pages_max = PIPE_DEF_BUFFERS, |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5009 | .flags = flags, |
| 5010 | .ops = &buffer_pipe_buf_ops, |
| 5011 | .spd_release = buffer_spd_release, |
| 5012 | }; |
| 5013 | struct buffer_ref *ref; |
Steven Rostedt | 93459c6 | 2009-04-29 00:23:13 -0400 | [diff] [blame] | 5014 | int entries, size, i; |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 5015 | ssize_t ret; |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5016 | |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 5017 | mutex_lock(&trace_types_lock); |
| 5018 | |
| 5019 | #ifdef CONFIG_TRACER_MAX_TRACE |
| 5020 | if (iter->snapshot && iter->tr->current_trace->use_max_tr) { |
| 5021 | ret = -EBUSY; |
| 5022 | goto out; |
| 5023 | } |
| 5024 | #endif |
| 5025 | |
| 5026 | if (splice_grow_spd(pipe, &spd)) { |
| 5027 | ret = -ENOMEM; |
| 5028 | goto out; |
| 5029 | } |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 5030 | |
Lai Jiangshan | 93cfb3c | 2009-04-02 15:17:08 +0800 | [diff] [blame] | 5031 | if (*ppos & (PAGE_SIZE - 1)) { |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 5032 | ret = -EINVAL; |
| 5033 | goto out; |
Lai Jiangshan | 93cfb3c | 2009-04-02 15:17:08 +0800 | [diff] [blame] | 5034 | } |
| 5035 | |
| 5036 | if (len & (PAGE_SIZE - 1)) { |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 5037 | if (len < PAGE_SIZE) { |
| 5038 | ret = -EINVAL; |
| 5039 | goto out; |
| 5040 | } |
Lai Jiangshan | 93cfb3c | 2009-04-02 15:17:08 +0800 | [diff] [blame] | 5041 | len &= PAGE_MASK; |
| 5042 | } |
| 5043 | |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 5044 | again: |
| 5045 | trace_access_lock(iter->cpu_file); |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5046 | entries = ring_buffer_entries_cpu(iter->trace_buffer->buffer, iter->cpu_file); |
Steven Rostedt | 93459c6 | 2009-04-29 00:23:13 -0400 | [diff] [blame] | 5047 | |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 5048 | for (i = 0; i < pipe->buffers && len && entries; i++, len -= PAGE_SIZE) { |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5049 | struct page *page; |
| 5050 | int r; |
| 5051 | |
| 5052 | ref = kzalloc(sizeof(*ref), GFP_KERNEL); |
| 5053 | if (!ref) |
| 5054 | break; |
| 5055 | |
Steven Rostedt | 7267fa6 | 2009-04-29 00:16:21 -0400 | [diff] [blame] | 5056 | ref->ref = 1; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5057 | ref->buffer = iter->trace_buffer->buffer; |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 5058 | ref->page = ring_buffer_alloc_read_page(ref->buffer, iter->cpu_file); |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5059 | if (!ref->page) { |
| 5060 | kfree(ref); |
| 5061 | break; |
| 5062 | } |
| 5063 | |
| 5064 | r = ring_buffer_read_page(ref->buffer, &ref->page, |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 5065 | len, iter->cpu_file, 1); |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5066 | if (r < 0) { |
Vaibhav Nagarnaik | 7ea5906 | 2011-05-03 17:56:42 -0700 | [diff] [blame] | 5067 | ring_buffer_free_read_page(ref->buffer, ref->page); |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5068 | kfree(ref); |
| 5069 | break; |
| 5070 | } |
| 5071 | |
| 5072 | /* |
| 5073 | * zero out any left over data, this is going to |
| 5074 | * user land. |
| 5075 | */ |
| 5076 | size = ring_buffer_page_len(ref->page); |
| 5077 | if (size < PAGE_SIZE) |
| 5078 | memset(ref->page + size, 0, PAGE_SIZE - size); |
| 5079 | |
| 5080 | page = virt_to_page(ref->page); |
| 5081 | |
| 5082 | spd.pages[i] = page; |
| 5083 | spd.partial[i].len = PAGE_SIZE; |
| 5084 | spd.partial[i].offset = 0; |
| 5085 | spd.partial[i].private = (unsigned long)ref; |
| 5086 | spd.nr_pages++; |
Lai Jiangshan | 93cfb3c | 2009-04-02 15:17:08 +0800 | [diff] [blame] | 5087 | *ppos += PAGE_SIZE; |
Steven Rostedt | 93459c6 | 2009-04-29 00:23:13 -0400 | [diff] [blame] | 5088 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5089 | entries = ring_buffer_entries_cpu(iter->trace_buffer->buffer, iter->cpu_file); |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5090 | } |
| 5091 | |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 5092 | trace_access_unlock(iter->cpu_file); |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5093 | spd.nr_pages = i; |
| 5094 | |
| 5095 | /* did we read anything? */ |
| 5096 | if (!spd.nr_pages) { |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 5097 | if ((file->f_flags & O_NONBLOCK) || (flags & SPLICE_F_NONBLOCK)) { |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5098 | ret = -EAGAIN; |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 5099 | goto out; |
| 5100 | } |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 5101 | mutex_unlock(&trace_types_lock); |
Steven Rostedt | b627344 | 2013-02-28 13:44:11 -0500 | [diff] [blame] | 5102 | iter->trace->wait_pipe(iter); |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 5103 | mutex_lock(&trace_types_lock); |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 5104 | if (signal_pending(current)) { |
| 5105 | ret = -EINTR; |
| 5106 | goto out; |
| 5107 | } |
| 5108 | goto again; |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5109 | } |
| 5110 | |
| 5111 | ret = splice_to_pipe(pipe, &spd); |
Eric Dumazet | 047fe36 | 2012-06-12 15:24:40 +0200 | [diff] [blame] | 5112 | splice_shrink_spd(&spd); |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 5113 | out: |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 5114 | mutex_unlock(&trace_types_lock); |
| 5115 | |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5116 | return ret; |
| 5117 | } |
| 5118 | |
| 5119 | static const struct file_operations tracing_buffers_fops = { |
| 5120 | .open = tracing_buffers_open, |
| 5121 | .read = tracing_buffers_read, |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 5122 | .poll = tracing_buffers_poll, |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5123 | .release = tracing_buffers_release, |
| 5124 | .splice_read = tracing_buffers_splice_read, |
| 5125 | .llseek = no_llseek, |
| 5126 | }; |
| 5127 | |
Steven Rostedt | c8d7718 | 2009-04-29 18:03:45 -0400 | [diff] [blame] | 5128 | static ssize_t |
| 5129 | tracing_stats_read(struct file *filp, char __user *ubuf, |
| 5130 | size_t count, loff_t *ppos) |
| 5131 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5132 | struct trace_cpu *tc = filp->private_data; |
| 5133 | struct trace_array *tr = tc->tr; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5134 | struct trace_buffer *trace_buf = &tr->trace_buffer; |
Steven Rostedt | c8d7718 | 2009-04-29 18:03:45 -0400 | [diff] [blame] | 5135 | struct trace_seq *s; |
| 5136 | unsigned long cnt; |
Vaibhav Nagarnaik | c64e148 | 2011-08-16 14:46:16 -0700 | [diff] [blame] | 5137 | unsigned long long t; |
| 5138 | unsigned long usec_rem; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5139 | int cpu = tc->cpu; |
Steven Rostedt | c8d7718 | 2009-04-29 18:03:45 -0400 | [diff] [blame] | 5140 | |
Li Zefan | e4f2d10 | 2009-06-15 10:57:28 +0800 | [diff] [blame] | 5141 | s = kmalloc(sizeof(*s), GFP_KERNEL); |
Steven Rostedt | c8d7718 | 2009-04-29 18:03:45 -0400 | [diff] [blame] | 5142 | if (!s) |
Roel Kluin | a646365 | 2009-11-11 22:26:35 +0100 | [diff] [blame] | 5143 | return -ENOMEM; |
Steven Rostedt | c8d7718 | 2009-04-29 18:03:45 -0400 | [diff] [blame] | 5144 | |
| 5145 | trace_seq_init(s); |
| 5146 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5147 | cnt = ring_buffer_entries_cpu(trace_buf->buffer, cpu); |
Steven Rostedt | c8d7718 | 2009-04-29 18:03:45 -0400 | [diff] [blame] | 5148 | trace_seq_printf(s, "entries: %ld\n", cnt); |
| 5149 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5150 | cnt = ring_buffer_overrun_cpu(trace_buf->buffer, cpu); |
Steven Rostedt | c8d7718 | 2009-04-29 18:03:45 -0400 | [diff] [blame] | 5151 | trace_seq_printf(s, "overrun: %ld\n", cnt); |
| 5152 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5153 | cnt = ring_buffer_commit_overrun_cpu(trace_buf->buffer, cpu); |
Steven Rostedt | c8d7718 | 2009-04-29 18:03:45 -0400 | [diff] [blame] | 5154 | trace_seq_printf(s, "commit overrun: %ld\n", cnt); |
| 5155 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5156 | cnt = ring_buffer_bytes_cpu(trace_buf->buffer, cpu); |
Vaibhav Nagarnaik | c64e148 | 2011-08-16 14:46:16 -0700 | [diff] [blame] | 5157 | trace_seq_printf(s, "bytes: %ld\n", cnt); |
| 5158 | |
Yoshihiro YUNOMAE | 11043d8b | 2012-11-13 12:18:23 -0800 | [diff] [blame] | 5159 | if (trace_clocks[trace_clock_id].in_ns) { |
| 5160 | /* local or global for trace_clock */ |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5161 | t = ns2usecs(ring_buffer_oldest_event_ts(trace_buf->buffer, cpu)); |
Yoshihiro YUNOMAE | 11043d8b | 2012-11-13 12:18:23 -0800 | [diff] [blame] | 5162 | usec_rem = do_div(t, USEC_PER_SEC); |
| 5163 | trace_seq_printf(s, "oldest event ts: %5llu.%06lu\n", |
| 5164 | t, usec_rem); |
Vaibhav Nagarnaik | c64e148 | 2011-08-16 14:46:16 -0700 | [diff] [blame] | 5165 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5166 | t = ns2usecs(ring_buffer_time_stamp(trace_buf->buffer, cpu)); |
Yoshihiro YUNOMAE | 11043d8b | 2012-11-13 12:18:23 -0800 | [diff] [blame] | 5167 | usec_rem = do_div(t, USEC_PER_SEC); |
| 5168 | trace_seq_printf(s, "now ts: %5llu.%06lu\n", t, usec_rem); |
| 5169 | } else { |
| 5170 | /* counter or tsc mode for trace_clock */ |
| 5171 | trace_seq_printf(s, "oldest event ts: %llu\n", |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5172 | ring_buffer_oldest_event_ts(trace_buf->buffer, cpu)); |
Yoshihiro YUNOMAE | 11043d8b | 2012-11-13 12:18:23 -0800 | [diff] [blame] | 5173 | |
| 5174 | trace_seq_printf(s, "now ts: %llu\n", |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5175 | ring_buffer_time_stamp(trace_buf->buffer, cpu)); |
Yoshihiro YUNOMAE | 11043d8b | 2012-11-13 12:18:23 -0800 | [diff] [blame] | 5176 | } |
Vaibhav Nagarnaik | c64e148 | 2011-08-16 14:46:16 -0700 | [diff] [blame] | 5177 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5178 | cnt = ring_buffer_dropped_events_cpu(trace_buf->buffer, cpu); |
Slava Pestov | 884bfe8 | 2011-07-15 14:23:58 -0700 | [diff] [blame] | 5179 | trace_seq_printf(s, "dropped events: %ld\n", cnt); |
| 5180 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5181 | cnt = ring_buffer_read_events_cpu(trace_buf->buffer, cpu); |
Steven Rostedt (Red Hat) | ad96470 | 2013-01-29 17:45:49 -0500 | [diff] [blame] | 5182 | trace_seq_printf(s, "read events: %ld\n", cnt); |
| 5183 | |
Steven Rostedt | c8d7718 | 2009-04-29 18:03:45 -0400 | [diff] [blame] | 5184 | count = simple_read_from_buffer(ubuf, count, ppos, s->buffer, s->len); |
| 5185 | |
| 5186 | kfree(s); |
| 5187 | |
| 5188 | return count; |
| 5189 | } |
| 5190 | |
| 5191 | static const struct file_operations tracing_stats_fops = { |
| 5192 | .open = tracing_open_generic, |
| 5193 | .read = tracing_stats_read, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 5194 | .llseek = generic_file_llseek, |
Steven Rostedt | c8d7718 | 2009-04-29 18:03:45 -0400 | [diff] [blame] | 5195 | }; |
| 5196 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5197 | #ifdef CONFIG_DYNAMIC_FTRACE |
| 5198 | |
Steven Rostedt | b807c3d | 2008-10-30 16:08:33 -0400 | [diff] [blame] | 5199 | int __weak ftrace_arch_read_dyn_info(char *buf, int size) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5200 | { |
Steven Rostedt | b807c3d | 2008-10-30 16:08:33 -0400 | [diff] [blame] | 5201 | return 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5202 | } |
| 5203 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5204 | static ssize_t |
Steven Rostedt | b807c3d | 2008-10-30 16:08:33 -0400 | [diff] [blame] | 5205 | tracing_read_dyn_info(struct file *filp, char __user *ubuf, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5206 | size_t cnt, loff_t *ppos) |
| 5207 | { |
Steven Rostedt | a26a2a2 | 2008-10-31 00:03:22 -0400 | [diff] [blame] | 5208 | static char ftrace_dyn_info_buffer[1024]; |
| 5209 | static DEFINE_MUTEX(dyn_info_mutex); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5210 | unsigned long *p = filp->private_data; |
Steven Rostedt | b807c3d | 2008-10-30 16:08:33 -0400 | [diff] [blame] | 5211 | char *buf = ftrace_dyn_info_buffer; |
Steven Rostedt | a26a2a2 | 2008-10-31 00:03:22 -0400 | [diff] [blame] | 5212 | int size = ARRAY_SIZE(ftrace_dyn_info_buffer); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5213 | int r; |
| 5214 | |
Steven Rostedt | b807c3d | 2008-10-30 16:08:33 -0400 | [diff] [blame] | 5215 | mutex_lock(&dyn_info_mutex); |
| 5216 | r = sprintf(buf, "%ld ", *p); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5217 | |
Steven Rostedt | a26a2a2 | 2008-10-31 00:03:22 -0400 | [diff] [blame] | 5218 | r += ftrace_arch_read_dyn_info(buf+r, (size-1)-r); |
Steven Rostedt | b807c3d | 2008-10-30 16:08:33 -0400 | [diff] [blame] | 5219 | buf[r++] = '\n'; |
| 5220 | |
| 5221 | r = simple_read_from_buffer(ubuf, cnt, ppos, buf, r); |
| 5222 | |
| 5223 | mutex_unlock(&dyn_info_mutex); |
| 5224 | |
| 5225 | return r; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5226 | } |
| 5227 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 5228 | static const struct file_operations tracing_dyn_info_fops = { |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 5229 | .open = tracing_open_generic, |
Steven Rostedt | b807c3d | 2008-10-30 16:08:33 -0400 | [diff] [blame] | 5230 | .read = tracing_read_dyn_info, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 5231 | .llseek = generic_file_llseek, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5232 | }; |
Steven Rostedt (Red Hat) | 77fd5c1 | 2013-03-12 11:49:18 -0400 | [diff] [blame] | 5233 | #endif /* CONFIG_DYNAMIC_FTRACE */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5234 | |
Steven Rostedt (Red Hat) | 77fd5c1 | 2013-03-12 11:49:18 -0400 | [diff] [blame] | 5235 | #if defined(CONFIG_TRACER_SNAPSHOT) && defined(CONFIG_DYNAMIC_FTRACE) |
| 5236 | static void |
| 5237 | ftrace_snapshot(unsigned long ip, unsigned long parent_ip, void **data) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5238 | { |
Steven Rostedt (Red Hat) | 77fd5c1 | 2013-03-12 11:49:18 -0400 | [diff] [blame] | 5239 | tracing_snapshot(); |
| 5240 | } |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5241 | |
Steven Rostedt (Red Hat) | 77fd5c1 | 2013-03-12 11:49:18 -0400 | [diff] [blame] | 5242 | static void |
| 5243 | ftrace_count_snapshot(unsigned long ip, unsigned long parent_ip, void **data) |
| 5244 | { |
| 5245 | unsigned long *count = (long *)data; |
| 5246 | |
| 5247 | if (!*count) |
| 5248 | return; |
| 5249 | |
| 5250 | if (*count != -1) |
| 5251 | (*count)--; |
| 5252 | |
| 5253 | tracing_snapshot(); |
| 5254 | } |
| 5255 | |
| 5256 | static int |
| 5257 | ftrace_snapshot_print(struct seq_file *m, unsigned long ip, |
| 5258 | struct ftrace_probe_ops *ops, void *data) |
| 5259 | { |
| 5260 | long count = (long)data; |
| 5261 | |
| 5262 | seq_printf(m, "%ps:", (void *)ip); |
| 5263 | |
| 5264 | seq_printf(m, "snapshot"); |
| 5265 | |
| 5266 | if (count == -1) |
| 5267 | seq_printf(m, ":unlimited\n"); |
| 5268 | else |
| 5269 | seq_printf(m, ":count=%ld\n", count); |
| 5270 | |
| 5271 | return 0; |
| 5272 | } |
| 5273 | |
| 5274 | static struct ftrace_probe_ops snapshot_probe_ops = { |
| 5275 | .func = ftrace_snapshot, |
| 5276 | .print = ftrace_snapshot_print, |
| 5277 | }; |
| 5278 | |
| 5279 | static struct ftrace_probe_ops snapshot_count_probe_ops = { |
| 5280 | .func = ftrace_count_snapshot, |
| 5281 | .print = ftrace_snapshot_print, |
| 5282 | }; |
| 5283 | |
| 5284 | static int |
| 5285 | ftrace_trace_snapshot_callback(struct ftrace_hash *hash, |
| 5286 | char *glob, char *cmd, char *param, int enable) |
| 5287 | { |
| 5288 | struct ftrace_probe_ops *ops; |
| 5289 | void *count = (void *)-1; |
| 5290 | char *number; |
| 5291 | int ret; |
| 5292 | |
| 5293 | /* hash funcs only work with set_ftrace_filter */ |
| 5294 | if (!enable) |
| 5295 | return -EINVAL; |
| 5296 | |
| 5297 | ops = param ? &snapshot_count_probe_ops : &snapshot_probe_ops; |
| 5298 | |
| 5299 | if (glob[0] == '!') { |
| 5300 | unregister_ftrace_function_probe_func(glob+1, ops); |
| 5301 | return 0; |
| 5302 | } |
| 5303 | |
| 5304 | if (!param) |
| 5305 | goto out_reg; |
| 5306 | |
| 5307 | number = strsep(¶m, ":"); |
| 5308 | |
| 5309 | if (!strlen(number)) |
| 5310 | goto out_reg; |
| 5311 | |
| 5312 | /* |
| 5313 | * We use the callback data field (which is a pointer) |
| 5314 | * as our counter. |
| 5315 | */ |
| 5316 | ret = kstrtoul(number, 0, (unsigned long *)&count); |
| 5317 | if (ret) |
| 5318 | return ret; |
| 5319 | |
| 5320 | out_reg: |
| 5321 | ret = register_ftrace_function_probe(glob, ops, count); |
| 5322 | |
| 5323 | if (ret >= 0) |
| 5324 | alloc_snapshot(&global_trace); |
| 5325 | |
| 5326 | return ret < 0 ? ret : 0; |
| 5327 | } |
| 5328 | |
| 5329 | static struct ftrace_func_command ftrace_snapshot_cmd = { |
| 5330 | .name = "snapshot", |
| 5331 | .func = ftrace_trace_snapshot_callback, |
| 5332 | }; |
| 5333 | |
| 5334 | static int register_snapshot_cmd(void) |
| 5335 | { |
| 5336 | return register_ftrace_command(&ftrace_snapshot_cmd); |
| 5337 | } |
| 5338 | #else |
| 5339 | static inline int register_snapshot_cmd(void) { return 0; } |
| 5340 | #endif /* defined(CONFIG_TRACER_SNAPSHOT) && defined(CONFIG_DYNAMIC_FTRACE) */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5341 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5342 | struct dentry *tracing_init_dentry_tr(struct trace_array *tr) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5343 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5344 | if (tr->dir) |
| 5345 | return tr->dir; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5346 | |
Frederic Weisbecker | 3e1f60b | 2009-03-22 23:10:45 +0100 | [diff] [blame] | 5347 | if (!debugfs_initialized()) |
| 5348 | return NULL; |
| 5349 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5350 | if (tr->flags & TRACE_ARRAY_FL_GLOBAL) |
| 5351 | tr->dir = debugfs_create_dir("tracing", NULL); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5352 | |
zhangwei(Jovi) | 687c878 | 2013-03-11 15:13:29 +0800 | [diff] [blame] | 5353 | if (!tr->dir) |
| 5354 | pr_warn_once("Could not create debugfs directory 'tracing'\n"); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5355 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5356 | return tr->dir; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5357 | } |
| 5358 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5359 | struct dentry *tracing_init_dentry(void) |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 5360 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5361 | return tracing_init_dentry_tr(&global_trace); |
| 5362 | } |
| 5363 | |
| 5364 | static struct dentry *tracing_dentry_percpu(struct trace_array *tr, int cpu) |
| 5365 | { |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 5366 | struct dentry *d_tracer; |
| 5367 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5368 | if (tr->percpu_dir) |
| 5369 | return tr->percpu_dir; |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 5370 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5371 | d_tracer = tracing_init_dentry_tr(tr); |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 5372 | if (!d_tracer) |
| 5373 | return NULL; |
| 5374 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5375 | tr->percpu_dir = debugfs_create_dir("per_cpu", d_tracer); |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 5376 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5377 | WARN_ONCE(!tr->percpu_dir, |
| 5378 | "Could not create debugfs directory 'per_cpu/%d'\n", cpu); |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 5379 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5380 | return tr->percpu_dir; |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 5381 | } |
| 5382 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5383 | static void |
| 5384 | tracing_init_debugfs_percpu(struct trace_array *tr, long cpu) |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 5385 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5386 | struct trace_array_cpu *data = per_cpu_ptr(tr->trace_buffer.data, cpu); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5387 | struct dentry *d_percpu = tracing_dentry_percpu(tr, cpu); |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 5388 | struct dentry *d_cpu; |
Steven Rostedt | dd49a38 | 2010-10-20 21:51:26 -0400 | [diff] [blame] | 5389 | char cpu_dir[30]; /* 30 characters should be more than enough */ |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 5390 | |
Namhyung Kim | 0a3d7ce | 2012-04-23 10:11:57 +0900 | [diff] [blame] | 5391 | if (!d_percpu) |
| 5392 | return; |
| 5393 | |
Steven Rostedt | dd49a38 | 2010-10-20 21:51:26 -0400 | [diff] [blame] | 5394 | snprintf(cpu_dir, 30, "cpu%ld", cpu); |
Frederic Weisbecker | 8656e7a | 2009-02-26 00:41:38 +0100 | [diff] [blame] | 5395 | d_cpu = debugfs_create_dir(cpu_dir, d_percpu); |
| 5396 | if (!d_cpu) { |
| 5397 | pr_warning("Could not create debugfs '%s' entry\n", cpu_dir); |
| 5398 | return; |
| 5399 | } |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 5400 | |
Frederic Weisbecker | 8656e7a | 2009-02-26 00:41:38 +0100 | [diff] [blame] | 5401 | /* per cpu trace_pipe */ |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 5402 | trace_create_file("trace_pipe", 0444, d_cpu, |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5403 | (void *)&data->trace_cpu, &tracing_pipe_fops); |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 5404 | |
| 5405 | /* per cpu trace */ |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 5406 | trace_create_file("trace", 0644, d_cpu, |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5407 | (void *)&data->trace_cpu, &tracing_fops); |
Steven Rostedt | 7f96f93 | 2009-03-13 00:37:42 -0400 | [diff] [blame] | 5408 | |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 5409 | trace_create_file("trace_pipe_raw", 0444, d_cpu, |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5410 | (void *)&data->trace_cpu, &tracing_buffers_fops); |
Steven Rostedt | c8d7718 | 2009-04-29 18:03:45 -0400 | [diff] [blame] | 5411 | |
| 5412 | trace_create_file("stats", 0444, d_cpu, |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5413 | (void *)&data->trace_cpu, &tracing_stats_fops); |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 5414 | |
| 5415 | trace_create_file("buffer_size_kb", 0444, d_cpu, |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5416 | (void *)&data->trace_cpu, &tracing_entries_fops); |
Steven Rostedt (Red Hat) | f1affca | 2013-03-05 14:35:11 -0500 | [diff] [blame] | 5417 | |
| 5418 | #ifdef CONFIG_TRACER_SNAPSHOT |
| 5419 | trace_create_file("snapshot", 0644, d_cpu, |
| 5420 | (void *)&data->trace_cpu, &snapshot_fops); |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 5421 | |
| 5422 | trace_create_file("snapshot_raw", 0444, d_cpu, |
| 5423 | (void *)&data->trace_cpu, &snapshot_raw_fops); |
Steven Rostedt (Red Hat) | f1affca | 2013-03-05 14:35:11 -0500 | [diff] [blame] | 5424 | #endif |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 5425 | } |
| 5426 | |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 5427 | #ifdef CONFIG_FTRACE_SELFTEST |
| 5428 | /* Let selftest have access to static functions in this file */ |
| 5429 | #include "trace_selftest.c" |
| 5430 | #endif |
| 5431 | |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 5432 | struct trace_option_dentry { |
| 5433 | struct tracer_opt *opt; |
| 5434 | struct tracer_flags *flags; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5435 | struct trace_array *tr; |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 5436 | struct dentry *entry; |
| 5437 | }; |
| 5438 | |
| 5439 | static ssize_t |
| 5440 | trace_options_read(struct file *filp, char __user *ubuf, size_t cnt, |
| 5441 | loff_t *ppos) |
| 5442 | { |
| 5443 | struct trace_option_dentry *topt = filp->private_data; |
| 5444 | char *buf; |
| 5445 | |
| 5446 | if (topt->flags->val & topt->opt->bit) |
| 5447 | buf = "1\n"; |
| 5448 | else |
| 5449 | buf = "0\n"; |
| 5450 | |
| 5451 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, 2); |
| 5452 | } |
| 5453 | |
| 5454 | static ssize_t |
| 5455 | trace_options_write(struct file *filp, const char __user *ubuf, size_t cnt, |
| 5456 | loff_t *ppos) |
| 5457 | { |
| 5458 | struct trace_option_dentry *topt = filp->private_data; |
| 5459 | unsigned long val; |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 5460 | int ret; |
| 5461 | |
Peter Huewe | 22fe9b5 | 2011-06-07 21:58:27 +0200 | [diff] [blame] | 5462 | ret = kstrtoul_from_user(ubuf, cnt, 10, &val); |
| 5463 | if (ret) |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 5464 | return ret; |
| 5465 | |
Li Zefan | 8d18eaa | 2009-12-08 11:17:06 +0800 | [diff] [blame] | 5466 | if (val != 0 && val != 1) |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 5467 | return -EINVAL; |
Li Zefan | 8d18eaa | 2009-12-08 11:17:06 +0800 | [diff] [blame] | 5468 | |
| 5469 | if (!!(topt->flags->val & topt->opt->bit) != val) { |
| 5470 | mutex_lock(&trace_types_lock); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5471 | ret = __set_tracer_option(topt->tr->current_trace, topt->flags, |
Steven Rostedt | c757bea | 2009-12-21 22:35:16 -0500 | [diff] [blame] | 5472 | topt->opt, !val); |
Li Zefan | 8d18eaa | 2009-12-08 11:17:06 +0800 | [diff] [blame] | 5473 | mutex_unlock(&trace_types_lock); |
| 5474 | if (ret) |
| 5475 | return ret; |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 5476 | } |
| 5477 | |
| 5478 | *ppos += cnt; |
| 5479 | |
| 5480 | return cnt; |
| 5481 | } |
| 5482 | |
| 5483 | |
| 5484 | static const struct file_operations trace_options_fops = { |
| 5485 | .open = tracing_open_generic, |
| 5486 | .read = trace_options_read, |
| 5487 | .write = trace_options_write, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 5488 | .llseek = generic_file_llseek, |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 5489 | }; |
| 5490 | |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5491 | static ssize_t |
| 5492 | trace_options_core_read(struct file *filp, char __user *ubuf, size_t cnt, |
| 5493 | loff_t *ppos) |
| 5494 | { |
| 5495 | long index = (long)filp->private_data; |
| 5496 | char *buf; |
| 5497 | |
| 5498 | if (trace_flags & (1 << index)) |
| 5499 | buf = "1\n"; |
| 5500 | else |
| 5501 | buf = "0\n"; |
| 5502 | |
| 5503 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, 2); |
| 5504 | } |
| 5505 | |
| 5506 | static ssize_t |
| 5507 | trace_options_core_write(struct file *filp, const char __user *ubuf, size_t cnt, |
| 5508 | loff_t *ppos) |
| 5509 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5510 | struct trace_array *tr = &global_trace; |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5511 | long index = (long)filp->private_data; |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5512 | unsigned long val; |
| 5513 | int ret; |
| 5514 | |
Peter Huewe | 22fe9b5 | 2011-06-07 21:58:27 +0200 | [diff] [blame] | 5515 | ret = kstrtoul_from_user(ubuf, cnt, 10, &val); |
| 5516 | if (ret) |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5517 | return ret; |
| 5518 | |
Zhaolei | f2d84b6 | 2009-08-07 18:55:48 +0800 | [diff] [blame] | 5519 | if (val != 0 && val != 1) |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5520 | return -EINVAL; |
Steven Rostedt (Red Hat) | 69d34da | 2013-03-14 13:50:56 -0400 | [diff] [blame] | 5521 | |
| 5522 | mutex_lock(&trace_types_lock); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5523 | ret = set_tracer_flag(tr, 1 << index, val); |
Steven Rostedt (Red Hat) | 69d34da | 2013-03-14 13:50:56 -0400 | [diff] [blame] | 5524 | mutex_unlock(&trace_types_lock); |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5525 | |
Steven Rostedt (Red Hat) | 613f04a | 2013-03-14 15:03:53 -0400 | [diff] [blame] | 5526 | if (ret < 0) |
| 5527 | return ret; |
| 5528 | |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5529 | *ppos += cnt; |
| 5530 | |
| 5531 | return cnt; |
| 5532 | } |
| 5533 | |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5534 | static const struct file_operations trace_options_core_fops = { |
| 5535 | .open = tracing_open_generic, |
| 5536 | .read = trace_options_core_read, |
| 5537 | .write = trace_options_core_write, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 5538 | .llseek = generic_file_llseek, |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5539 | }; |
| 5540 | |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 5541 | struct dentry *trace_create_file(const char *name, |
Al Viro | f4ae40a6 | 2011-07-24 04:33:43 -0400 | [diff] [blame] | 5542 | umode_t mode, |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 5543 | struct dentry *parent, |
| 5544 | void *data, |
| 5545 | const struct file_operations *fops) |
| 5546 | { |
| 5547 | struct dentry *ret; |
| 5548 | |
| 5549 | ret = debugfs_create_file(name, mode, parent, data, fops); |
| 5550 | if (!ret) |
| 5551 | pr_warning("Could not create debugfs '%s' entry\n", name); |
| 5552 | |
| 5553 | return ret; |
| 5554 | } |
| 5555 | |
| 5556 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5557 | static struct dentry *trace_options_init_dentry(struct trace_array *tr) |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5558 | { |
| 5559 | struct dentry *d_tracer; |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5560 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5561 | if (tr->options) |
| 5562 | return tr->options; |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5563 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5564 | d_tracer = tracing_init_dentry_tr(tr); |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5565 | if (!d_tracer) |
| 5566 | return NULL; |
| 5567 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5568 | tr->options = debugfs_create_dir("options", d_tracer); |
| 5569 | if (!tr->options) { |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5570 | pr_warning("Could not create debugfs directory 'options'\n"); |
| 5571 | return NULL; |
| 5572 | } |
| 5573 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5574 | return tr->options; |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5575 | } |
| 5576 | |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 5577 | static void |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5578 | create_trace_option_file(struct trace_array *tr, |
| 5579 | struct trace_option_dentry *topt, |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 5580 | struct tracer_flags *flags, |
| 5581 | struct tracer_opt *opt) |
| 5582 | { |
| 5583 | struct dentry *t_options; |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 5584 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5585 | t_options = trace_options_init_dentry(tr); |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 5586 | if (!t_options) |
| 5587 | return; |
| 5588 | |
| 5589 | topt->flags = flags; |
| 5590 | topt->opt = opt; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5591 | topt->tr = tr; |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 5592 | |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 5593 | topt->entry = trace_create_file(opt->name, 0644, t_options, topt, |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 5594 | &trace_options_fops); |
| 5595 | |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 5596 | } |
| 5597 | |
| 5598 | static struct trace_option_dentry * |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5599 | create_trace_option_files(struct trace_array *tr, struct tracer *tracer) |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 5600 | { |
| 5601 | struct trace_option_dentry *topts; |
| 5602 | struct tracer_flags *flags; |
| 5603 | struct tracer_opt *opts; |
| 5604 | int cnt; |
| 5605 | |
| 5606 | if (!tracer) |
| 5607 | return NULL; |
| 5608 | |
| 5609 | flags = tracer->flags; |
| 5610 | |
| 5611 | if (!flags || !flags->opts) |
| 5612 | return NULL; |
| 5613 | |
| 5614 | opts = flags->opts; |
| 5615 | |
| 5616 | for (cnt = 0; opts[cnt].name; cnt++) |
| 5617 | ; |
| 5618 | |
Steven Rostedt | 0cfe824 | 2009-02-27 10:51:10 -0500 | [diff] [blame] | 5619 | topts = kcalloc(cnt + 1, sizeof(*topts), GFP_KERNEL); |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 5620 | if (!topts) |
| 5621 | return NULL; |
| 5622 | |
| 5623 | for (cnt = 0; opts[cnt].name; cnt++) |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5624 | create_trace_option_file(tr, &topts[cnt], flags, |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 5625 | &opts[cnt]); |
| 5626 | |
| 5627 | return topts; |
| 5628 | } |
| 5629 | |
| 5630 | static void |
| 5631 | destroy_trace_option_files(struct trace_option_dentry *topts) |
| 5632 | { |
| 5633 | int cnt; |
| 5634 | |
| 5635 | if (!topts) |
| 5636 | return; |
| 5637 | |
| 5638 | for (cnt = 0; topts[cnt].opt; cnt++) { |
| 5639 | if (topts[cnt].entry) |
| 5640 | debugfs_remove(topts[cnt].entry); |
| 5641 | } |
| 5642 | |
| 5643 | kfree(topts); |
| 5644 | } |
| 5645 | |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5646 | static struct dentry * |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5647 | create_trace_option_core_file(struct trace_array *tr, |
| 5648 | const char *option, long index) |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5649 | { |
| 5650 | struct dentry *t_options; |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5651 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5652 | t_options = trace_options_init_dentry(tr); |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5653 | if (!t_options) |
| 5654 | return NULL; |
| 5655 | |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 5656 | return trace_create_file(option, 0644, t_options, (void *)index, |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5657 | &trace_options_core_fops); |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5658 | } |
| 5659 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5660 | static __init void create_trace_options_dir(struct trace_array *tr) |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5661 | { |
| 5662 | struct dentry *t_options; |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5663 | int i; |
| 5664 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5665 | t_options = trace_options_init_dentry(tr); |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5666 | if (!t_options) |
| 5667 | return; |
| 5668 | |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 5669 | for (i = 0; trace_options[i]; i++) |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5670 | create_trace_option_core_file(tr, trace_options[i], i); |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5671 | } |
| 5672 | |
Steven Rostedt | 499e547 | 2012-02-22 15:50:28 -0500 | [diff] [blame] | 5673 | static ssize_t |
| 5674 | rb_simple_read(struct file *filp, char __user *ubuf, |
| 5675 | size_t cnt, loff_t *ppos) |
| 5676 | { |
Steven Rostedt | 348f0fc | 2012-04-16 15:41:28 -0400 | [diff] [blame] | 5677 | struct trace_array *tr = filp->private_data; |
Steven Rostedt | 499e547 | 2012-02-22 15:50:28 -0500 | [diff] [blame] | 5678 | char buf[64]; |
| 5679 | int r; |
| 5680 | |
Steven Rostedt (Red Hat) | 10246fa | 2013-07-01 15:58:24 -0400 | [diff] [blame^] | 5681 | r = tracer_tracing_is_on(tr); |
Steven Rostedt | 499e547 | 2012-02-22 15:50:28 -0500 | [diff] [blame] | 5682 | r = sprintf(buf, "%d\n", r); |
| 5683 | |
| 5684 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, r); |
| 5685 | } |
| 5686 | |
| 5687 | static ssize_t |
| 5688 | rb_simple_write(struct file *filp, const char __user *ubuf, |
| 5689 | size_t cnt, loff_t *ppos) |
| 5690 | { |
Steven Rostedt | 348f0fc | 2012-04-16 15:41:28 -0400 | [diff] [blame] | 5691 | struct trace_array *tr = filp->private_data; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5692 | struct ring_buffer *buffer = tr->trace_buffer.buffer; |
Steven Rostedt | 499e547 | 2012-02-22 15:50:28 -0500 | [diff] [blame] | 5693 | unsigned long val; |
| 5694 | int ret; |
| 5695 | |
| 5696 | ret = kstrtoul_from_user(ubuf, cnt, 10, &val); |
| 5697 | if (ret) |
| 5698 | return ret; |
| 5699 | |
| 5700 | if (buffer) { |
Steven Rostedt | 2df8f8a | 2013-01-11 16:14:10 -0500 | [diff] [blame] | 5701 | mutex_lock(&trace_types_lock); |
| 5702 | if (val) { |
Steven Rostedt (Red Hat) | 10246fa | 2013-07-01 15:58:24 -0400 | [diff] [blame^] | 5703 | tracer_tracing_on(tr); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5704 | if (tr->current_trace->start) |
| 5705 | tr->current_trace->start(tr); |
Steven Rostedt | 2df8f8a | 2013-01-11 16:14:10 -0500 | [diff] [blame] | 5706 | } else { |
Steven Rostedt (Red Hat) | 10246fa | 2013-07-01 15:58:24 -0400 | [diff] [blame^] | 5707 | tracer_tracing_off(tr); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5708 | if (tr->current_trace->stop) |
| 5709 | tr->current_trace->stop(tr); |
Steven Rostedt | 2df8f8a | 2013-01-11 16:14:10 -0500 | [diff] [blame] | 5710 | } |
| 5711 | mutex_unlock(&trace_types_lock); |
Steven Rostedt | 499e547 | 2012-02-22 15:50:28 -0500 | [diff] [blame] | 5712 | } |
| 5713 | |
| 5714 | (*ppos)++; |
| 5715 | |
| 5716 | return cnt; |
| 5717 | } |
| 5718 | |
| 5719 | static const struct file_operations rb_simple_fops = { |
| 5720 | .open = tracing_open_generic, |
| 5721 | .read = rb_simple_read, |
| 5722 | .write = rb_simple_write, |
| 5723 | .llseek = default_llseek, |
| 5724 | }; |
| 5725 | |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 5726 | struct dentry *trace_instance_dir; |
| 5727 | |
| 5728 | static void |
| 5729 | init_tracer_debugfs(struct trace_array *tr, struct dentry *d_tracer); |
| 5730 | |
Steven Rostedt (Red Hat) | 737223f | 2013-03-05 21:13:47 -0500 | [diff] [blame] | 5731 | static void init_trace_buffers(struct trace_array *tr, struct trace_buffer *buf) |
| 5732 | { |
| 5733 | int cpu; |
| 5734 | |
| 5735 | for_each_tracing_cpu(cpu) { |
| 5736 | memset(per_cpu_ptr(buf->data, cpu), 0, sizeof(struct trace_array_cpu)); |
| 5737 | per_cpu_ptr(buf->data, cpu)->trace_cpu.cpu = cpu; |
| 5738 | per_cpu_ptr(buf->data, cpu)->trace_cpu.tr = tr; |
| 5739 | } |
| 5740 | } |
| 5741 | |
Steven Rostedt (Red Hat) | 55034cd | 2013-03-07 22:48:09 -0500 | [diff] [blame] | 5742 | static int |
| 5743 | 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] | 5744 | { |
| 5745 | enum ring_buffer_flags rb_flags; |
Steven Rostedt (Red Hat) | 737223f | 2013-03-05 21:13:47 -0500 | [diff] [blame] | 5746 | |
| 5747 | rb_flags = trace_flags & TRACE_ITER_OVERWRITE ? RB_FL_OVERWRITE : 0; |
| 5748 | |
Steven Rostedt (Red Hat) | 55034cd | 2013-03-07 22:48:09 -0500 | [diff] [blame] | 5749 | buf->buffer = ring_buffer_alloc(size, rb_flags); |
| 5750 | if (!buf->buffer) |
| 5751 | return -ENOMEM; |
Steven Rostedt (Red Hat) | 737223f | 2013-03-05 21:13:47 -0500 | [diff] [blame] | 5752 | |
Steven Rostedt (Red Hat) | 55034cd | 2013-03-07 22:48:09 -0500 | [diff] [blame] | 5753 | buf->data = alloc_percpu(struct trace_array_cpu); |
| 5754 | if (!buf->data) { |
| 5755 | ring_buffer_free(buf->buffer); |
| 5756 | return -ENOMEM; |
| 5757 | } |
Steven Rostedt (Red Hat) | 737223f | 2013-03-05 21:13:47 -0500 | [diff] [blame] | 5758 | |
Steven Rostedt (Red Hat) | 55034cd | 2013-03-07 22:48:09 -0500 | [diff] [blame] | 5759 | init_trace_buffers(tr, buf); |
Steven Rostedt (Red Hat) | 737223f | 2013-03-05 21:13:47 -0500 | [diff] [blame] | 5760 | |
| 5761 | /* Allocate the first page for all buffers */ |
| 5762 | set_buffer_entries(&tr->trace_buffer, |
| 5763 | ring_buffer_size(tr->trace_buffer.buffer, 0)); |
| 5764 | |
Steven Rostedt (Red Hat) | 55034cd | 2013-03-07 22:48:09 -0500 | [diff] [blame] | 5765 | return 0; |
| 5766 | } |
| 5767 | |
| 5768 | static int allocate_trace_buffers(struct trace_array *tr, int size) |
| 5769 | { |
| 5770 | int ret; |
| 5771 | |
| 5772 | ret = allocate_trace_buffer(tr, &tr->trace_buffer, size); |
| 5773 | if (ret) |
| 5774 | return ret; |
| 5775 | |
Steven Rostedt (Red Hat) | 737223f | 2013-03-05 21:13:47 -0500 | [diff] [blame] | 5776 | #ifdef CONFIG_TRACER_MAX_TRACE |
Steven Rostedt (Red Hat) | 55034cd | 2013-03-07 22:48:09 -0500 | [diff] [blame] | 5777 | ret = allocate_trace_buffer(tr, &tr->max_buffer, |
| 5778 | allocate_snapshot ? size : 1); |
| 5779 | if (WARN_ON(ret)) { |
| 5780 | ring_buffer_free(tr->trace_buffer.buffer); |
| 5781 | free_percpu(tr->trace_buffer.data); |
| 5782 | return -ENOMEM; |
| 5783 | } |
| 5784 | tr->allocated_snapshot = allocate_snapshot; |
Steven Rostedt (Red Hat) | 737223f | 2013-03-05 21:13:47 -0500 | [diff] [blame] | 5785 | |
Steven Rostedt (Red Hat) | 55034cd | 2013-03-07 22:48:09 -0500 | [diff] [blame] | 5786 | /* |
| 5787 | * Only the top level trace array gets its snapshot allocated |
| 5788 | * from the kernel command line. |
| 5789 | */ |
| 5790 | allocate_snapshot = false; |
Steven Rostedt (Red Hat) | 737223f | 2013-03-05 21:13:47 -0500 | [diff] [blame] | 5791 | #endif |
| 5792 | return 0; |
Steven Rostedt (Red Hat) | 737223f | 2013-03-05 21:13:47 -0500 | [diff] [blame] | 5793 | } |
| 5794 | |
| 5795 | static int new_instance_create(const char *name) |
| 5796 | { |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 5797 | struct trace_array *tr; |
| 5798 | int ret; |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 5799 | |
| 5800 | mutex_lock(&trace_types_lock); |
| 5801 | |
| 5802 | ret = -EEXIST; |
| 5803 | list_for_each_entry(tr, &ftrace_trace_arrays, list) { |
| 5804 | if (tr->name && strcmp(tr->name, name) == 0) |
| 5805 | goto out_unlock; |
| 5806 | } |
| 5807 | |
| 5808 | ret = -ENOMEM; |
| 5809 | tr = kzalloc(sizeof(*tr), GFP_KERNEL); |
| 5810 | if (!tr) |
| 5811 | goto out_unlock; |
| 5812 | |
| 5813 | tr->name = kstrdup(name, GFP_KERNEL); |
| 5814 | if (!tr->name) |
| 5815 | goto out_free_tr; |
| 5816 | |
| 5817 | raw_spin_lock_init(&tr->start_lock); |
| 5818 | |
| 5819 | tr->current_trace = &nop_trace; |
| 5820 | |
| 5821 | INIT_LIST_HEAD(&tr->systems); |
| 5822 | INIT_LIST_HEAD(&tr->events); |
| 5823 | |
Steven Rostedt (Red Hat) | 737223f | 2013-03-05 21:13:47 -0500 | [diff] [blame] | 5824 | if (allocate_trace_buffers(tr, trace_buf_size) < 0) |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 5825 | goto out_free_tr; |
| 5826 | |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 5827 | /* Holder for file callbacks */ |
| 5828 | tr->trace_cpu.cpu = RING_BUFFER_ALL_CPUS; |
| 5829 | tr->trace_cpu.tr = tr; |
| 5830 | |
| 5831 | tr->dir = debugfs_create_dir(name, trace_instance_dir); |
| 5832 | if (!tr->dir) |
| 5833 | goto out_free_tr; |
| 5834 | |
| 5835 | ret = event_trace_add_tracer(tr->dir, tr); |
| 5836 | if (ret) |
| 5837 | goto out_free_tr; |
| 5838 | |
| 5839 | init_tracer_debugfs(tr, tr->dir); |
| 5840 | |
| 5841 | list_add(&tr->list, &ftrace_trace_arrays); |
| 5842 | |
| 5843 | mutex_unlock(&trace_types_lock); |
| 5844 | |
| 5845 | return 0; |
| 5846 | |
| 5847 | out_free_tr: |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5848 | if (tr->trace_buffer.buffer) |
| 5849 | ring_buffer_free(tr->trace_buffer.buffer); |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 5850 | kfree(tr->name); |
| 5851 | kfree(tr); |
| 5852 | |
| 5853 | out_unlock: |
| 5854 | mutex_unlock(&trace_types_lock); |
| 5855 | |
| 5856 | return ret; |
| 5857 | |
| 5858 | } |
| 5859 | |
Steven Rostedt | 0c8916c | 2012-08-07 16:14:16 -0400 | [diff] [blame] | 5860 | static int instance_delete(const char *name) |
| 5861 | { |
| 5862 | struct trace_array *tr; |
| 5863 | int found = 0; |
| 5864 | int ret; |
| 5865 | |
| 5866 | mutex_lock(&trace_types_lock); |
| 5867 | |
| 5868 | ret = -ENODEV; |
| 5869 | list_for_each_entry(tr, &ftrace_trace_arrays, list) { |
| 5870 | if (tr->name && strcmp(tr->name, name) == 0) { |
| 5871 | found = 1; |
| 5872 | break; |
| 5873 | } |
| 5874 | } |
| 5875 | if (!found) |
| 5876 | goto out_unlock; |
| 5877 | |
Steven Rostedt (Red Hat) | a695cb5 | 2013-03-06 15:27:24 -0500 | [diff] [blame] | 5878 | ret = -EBUSY; |
| 5879 | if (tr->ref) |
| 5880 | goto out_unlock; |
| 5881 | |
Steven Rostedt | 0c8916c | 2012-08-07 16:14:16 -0400 | [diff] [blame] | 5882 | list_del(&tr->list); |
| 5883 | |
| 5884 | event_trace_del_tracer(tr); |
| 5885 | debugfs_remove_recursive(tr->dir); |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5886 | free_percpu(tr->trace_buffer.data); |
| 5887 | ring_buffer_free(tr->trace_buffer.buffer); |
Steven Rostedt | 0c8916c | 2012-08-07 16:14:16 -0400 | [diff] [blame] | 5888 | |
| 5889 | kfree(tr->name); |
| 5890 | kfree(tr); |
| 5891 | |
| 5892 | ret = 0; |
| 5893 | |
| 5894 | out_unlock: |
| 5895 | mutex_unlock(&trace_types_lock); |
| 5896 | |
| 5897 | return ret; |
| 5898 | } |
| 5899 | |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 5900 | static int instance_mkdir (struct inode *inode, struct dentry *dentry, umode_t mode) |
| 5901 | { |
| 5902 | struct dentry *parent; |
| 5903 | int ret; |
| 5904 | |
| 5905 | /* Paranoid: Make sure the parent is the "instances" directory */ |
| 5906 | parent = hlist_entry(inode->i_dentry.first, struct dentry, d_alias); |
| 5907 | if (WARN_ON_ONCE(parent != trace_instance_dir)) |
| 5908 | return -ENOENT; |
| 5909 | |
| 5910 | /* |
| 5911 | * The inode mutex is locked, but debugfs_create_dir() will also |
| 5912 | * take the mutex. As the instances directory can not be destroyed |
| 5913 | * or changed in any other way, it is safe to unlock it, and |
| 5914 | * let the dentry try. If two users try to make the same dir at |
| 5915 | * the same time, then the new_instance_create() will determine the |
| 5916 | * winner. |
| 5917 | */ |
| 5918 | mutex_unlock(&inode->i_mutex); |
| 5919 | |
| 5920 | ret = new_instance_create(dentry->d_iname); |
| 5921 | |
| 5922 | mutex_lock(&inode->i_mutex); |
| 5923 | |
| 5924 | return ret; |
| 5925 | } |
| 5926 | |
Steven Rostedt | 0c8916c | 2012-08-07 16:14:16 -0400 | [diff] [blame] | 5927 | static int instance_rmdir(struct inode *inode, struct dentry *dentry) |
| 5928 | { |
| 5929 | struct dentry *parent; |
| 5930 | int ret; |
| 5931 | |
| 5932 | /* Paranoid: Make sure the parent is the "instances" directory */ |
| 5933 | parent = hlist_entry(inode->i_dentry.first, struct dentry, d_alias); |
| 5934 | if (WARN_ON_ONCE(parent != trace_instance_dir)) |
| 5935 | return -ENOENT; |
| 5936 | |
| 5937 | /* The caller did a dget() on dentry */ |
| 5938 | mutex_unlock(&dentry->d_inode->i_mutex); |
| 5939 | |
| 5940 | /* |
| 5941 | * The inode mutex is locked, but debugfs_create_dir() will also |
| 5942 | * take the mutex. As the instances directory can not be destroyed |
| 5943 | * or changed in any other way, it is safe to unlock it, and |
| 5944 | * let the dentry try. If two users try to make the same dir at |
| 5945 | * the same time, then the instance_delete() will determine the |
| 5946 | * winner. |
| 5947 | */ |
| 5948 | mutex_unlock(&inode->i_mutex); |
| 5949 | |
| 5950 | ret = instance_delete(dentry->d_iname); |
| 5951 | |
| 5952 | mutex_lock_nested(&inode->i_mutex, I_MUTEX_PARENT); |
| 5953 | mutex_lock(&dentry->d_inode->i_mutex); |
| 5954 | |
| 5955 | return ret; |
| 5956 | } |
| 5957 | |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 5958 | static const struct inode_operations instance_dir_inode_operations = { |
| 5959 | .lookup = simple_lookup, |
| 5960 | .mkdir = instance_mkdir, |
Steven Rostedt | 0c8916c | 2012-08-07 16:14:16 -0400 | [diff] [blame] | 5961 | .rmdir = instance_rmdir, |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 5962 | }; |
| 5963 | |
| 5964 | static __init void create_trace_instances(struct dentry *d_tracer) |
| 5965 | { |
| 5966 | trace_instance_dir = debugfs_create_dir("instances", d_tracer); |
| 5967 | if (WARN_ON(!trace_instance_dir)) |
| 5968 | return; |
| 5969 | |
| 5970 | /* Hijack the dir inode operations, to allow mkdir */ |
| 5971 | trace_instance_dir->d_inode->i_op = &instance_dir_inode_operations; |
| 5972 | } |
| 5973 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5974 | static void |
| 5975 | init_tracer_debugfs(struct trace_array *tr, struct dentry *d_tracer) |
| 5976 | { |
Steven Rostedt (Red Hat) | 121aaee | 2013-03-05 21:52:25 -0500 | [diff] [blame] | 5977 | int cpu; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5978 | |
| 5979 | trace_create_file("trace_options", 0644, d_tracer, |
| 5980 | tr, &tracing_iter_fops); |
| 5981 | |
| 5982 | trace_create_file("trace", 0644, d_tracer, |
| 5983 | (void *)&tr->trace_cpu, &tracing_fops); |
| 5984 | |
| 5985 | trace_create_file("trace_pipe", 0444, d_tracer, |
| 5986 | (void *)&tr->trace_cpu, &tracing_pipe_fops); |
| 5987 | |
| 5988 | trace_create_file("buffer_size_kb", 0644, d_tracer, |
| 5989 | (void *)&tr->trace_cpu, &tracing_entries_fops); |
| 5990 | |
| 5991 | trace_create_file("buffer_total_size_kb", 0444, d_tracer, |
| 5992 | tr, &tracing_total_entries_fops); |
| 5993 | |
Wang YanQing | 238ae93 | 2013-05-26 16:52:01 +0800 | [diff] [blame] | 5994 | trace_create_file("free_buffer", 0200, d_tracer, |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5995 | tr, &tracing_free_buffer_fops); |
| 5996 | |
| 5997 | trace_create_file("trace_marker", 0220, d_tracer, |
| 5998 | tr, &tracing_mark_fops); |
| 5999 | |
| 6000 | trace_create_file("trace_clock", 0644, d_tracer, tr, |
| 6001 | &trace_clock_fops); |
| 6002 | |
| 6003 | trace_create_file("tracing_on", 0644, d_tracer, |
| 6004 | tr, &rb_simple_fops); |
Steven Rostedt (Red Hat) | ce9bae5 | 2013-03-05 21:23:55 -0500 | [diff] [blame] | 6005 | |
| 6006 | #ifdef CONFIG_TRACER_SNAPSHOT |
| 6007 | trace_create_file("snapshot", 0644, d_tracer, |
| 6008 | (void *)&tr->trace_cpu, &snapshot_fops); |
| 6009 | #endif |
Steven Rostedt (Red Hat) | 121aaee | 2013-03-05 21:52:25 -0500 | [diff] [blame] | 6010 | |
| 6011 | for_each_tracing_cpu(cpu) |
| 6012 | tracing_init_debugfs_percpu(tr, cpu); |
| 6013 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6014 | } |
| 6015 | |
Frédéric Weisbecker | b5ad384 | 2008-09-23 11:34:32 +0100 | [diff] [blame] | 6016 | static __init int tracer_init_debugfs(void) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 6017 | { |
| 6018 | struct dentry *d_tracer; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 6019 | |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 6020 | trace_access_lock_init(); |
| 6021 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 6022 | d_tracer = tracing_init_dentry(); |
Namhyung Kim | ed6f1c9 | 2013-04-10 09:18:12 +0900 | [diff] [blame] | 6023 | if (!d_tracer) |
| 6024 | return 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 6025 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6026 | init_tracer_debugfs(&global_trace, d_tracer); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 6027 | |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 6028 | trace_create_file("tracing_cpumask", 0644, d_tracer, |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6029 | &global_trace, &tracing_cpumask_fops); |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 6030 | |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 6031 | trace_create_file("available_tracers", 0444, d_tracer, |
| 6032 | &global_trace, &show_traces_fops); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 6033 | |
Li Zefan | 339ae5d | 2009-04-17 10:34:30 +0800 | [diff] [blame] | 6034 | trace_create_file("current_tracer", 0644, d_tracer, |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 6035 | &global_trace, &set_tracer_fops); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 6036 | |
Steven Rostedt | 5d4a9db | 2009-08-27 16:52:21 -0400 | [diff] [blame] | 6037 | #ifdef CONFIG_TRACER_MAX_TRACE |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 6038 | trace_create_file("tracing_max_latency", 0644, d_tracer, |
| 6039 | &tracing_max_latency, &tracing_max_lat_fops); |
Tim Bird | 0e95017 | 2010-02-25 15:36:43 -0800 | [diff] [blame] | 6040 | #endif |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 6041 | |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 6042 | trace_create_file("tracing_thresh", 0644, d_tracer, |
| 6043 | &tracing_thresh, &tracing_max_lat_fops); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 6044 | |
Li Zefan | 339ae5d | 2009-04-17 10:34:30 +0800 | [diff] [blame] | 6045 | trace_create_file("README", 0444, d_tracer, |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 6046 | NULL, &tracing_readme_fops); |
Ingo Molnar | 7bd2f24 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 6047 | |
Avadh Patel | 69abe6a | 2009-04-10 16:04:48 -0400 | [diff] [blame] | 6048 | trace_create_file("saved_cmdlines", 0444, d_tracer, |
| 6049 | NULL, &tracing_saved_cmdlines_fops); |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 6050 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 6051 | #ifdef CONFIG_DYNAMIC_FTRACE |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 6052 | trace_create_file("dyn_ftrace_total_info", 0444, d_tracer, |
| 6053 | &ftrace_update_tot_cnt, &tracing_dyn_info_fops); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 6054 | #endif |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 6055 | |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 6056 | create_trace_instances(d_tracer); |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 6057 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6058 | create_trace_options_dir(&global_trace); |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 6059 | |
Frédéric Weisbecker | b5ad384 | 2008-09-23 11:34:32 +0100 | [diff] [blame] | 6060 | return 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 6061 | } |
| 6062 | |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 6063 | static int trace_panic_handler(struct notifier_block *this, |
| 6064 | unsigned long event, void *unused) |
| 6065 | { |
Steven Rostedt | 944ac42 | 2008-10-23 19:26:08 -0400 | [diff] [blame] | 6066 | if (ftrace_dump_on_oops) |
Frederic Weisbecker | cecbca9 | 2010-04-18 19:08:41 +0200 | [diff] [blame] | 6067 | ftrace_dump(ftrace_dump_on_oops); |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 6068 | return NOTIFY_OK; |
| 6069 | } |
| 6070 | |
| 6071 | static struct notifier_block trace_panic_notifier = { |
| 6072 | .notifier_call = trace_panic_handler, |
| 6073 | .next = NULL, |
| 6074 | .priority = 150 /* priority: INT_MAX >= x >= 0 */ |
| 6075 | }; |
| 6076 | |
| 6077 | static int trace_die_handler(struct notifier_block *self, |
| 6078 | unsigned long val, |
| 6079 | void *data) |
| 6080 | { |
| 6081 | switch (val) { |
| 6082 | case DIE_OOPS: |
Steven Rostedt | 944ac42 | 2008-10-23 19:26:08 -0400 | [diff] [blame] | 6083 | if (ftrace_dump_on_oops) |
Frederic Weisbecker | cecbca9 | 2010-04-18 19:08:41 +0200 | [diff] [blame] | 6084 | ftrace_dump(ftrace_dump_on_oops); |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 6085 | break; |
| 6086 | default: |
| 6087 | break; |
| 6088 | } |
| 6089 | return NOTIFY_OK; |
| 6090 | } |
| 6091 | |
| 6092 | static struct notifier_block trace_die_notifier = { |
| 6093 | .notifier_call = trace_die_handler, |
| 6094 | .priority = 200 |
| 6095 | }; |
| 6096 | |
| 6097 | /* |
| 6098 | * printk is set to max of 1024, we really don't need it that big. |
| 6099 | * Nothing should be printing 1000 characters anyway. |
| 6100 | */ |
| 6101 | #define TRACE_MAX_PRINT 1000 |
| 6102 | |
| 6103 | /* |
| 6104 | * Define here KERN_TRACE so that we have one place to modify |
| 6105 | * it if we decide to change what log level the ftrace dump |
| 6106 | * should be at. |
| 6107 | */ |
Steven Rostedt | 428aee1 | 2009-01-14 12:24:42 -0500 | [diff] [blame] | 6108 | #define KERN_TRACE KERN_EMERG |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 6109 | |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 6110 | void |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 6111 | trace_printk_seq(struct trace_seq *s) |
| 6112 | { |
| 6113 | /* Probably should print a warning here. */ |
zhangwei(Jovi) | bd6df18 | 2013-03-11 15:13:37 +0800 | [diff] [blame] | 6114 | if (s->len >= TRACE_MAX_PRINT) |
| 6115 | s->len = TRACE_MAX_PRINT; |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 6116 | |
| 6117 | /* should be zero ended, but we are paranoid. */ |
| 6118 | s->buffer[s->len] = 0; |
| 6119 | |
| 6120 | printk(KERN_TRACE "%s", s->buffer); |
| 6121 | |
Steven Rostedt | f952075 | 2009-03-02 14:04:40 -0500 | [diff] [blame] | 6122 | trace_seq_init(s); |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 6123 | } |
| 6124 | |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 6125 | void trace_init_global_iter(struct trace_iterator *iter) |
| 6126 | { |
| 6127 | iter->tr = &global_trace; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6128 | iter->trace = iter->tr->current_trace; |
Steven Rostedt | ae3b509 | 2013-01-23 15:22:59 -0500 | [diff] [blame] | 6129 | iter->cpu_file = RING_BUFFER_ALL_CPUS; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 6130 | iter->trace_buffer = &global_trace.trace_buffer; |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 6131 | } |
| 6132 | |
Steven Rostedt (Red Hat) | 7fe70b5 | 2013-03-15 13:10:35 -0400 | [diff] [blame] | 6133 | void ftrace_dump(enum ftrace_dump_mode oops_dump_mode) |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 6134 | { |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 6135 | /* use static because iter can be a bit big for the stack */ |
| 6136 | static struct trace_iterator iter; |
Steven Rostedt (Red Hat) | 7fe70b5 | 2013-03-15 13:10:35 -0400 | [diff] [blame] | 6137 | static atomic_t dump_running; |
Frederic Weisbecker | cf586b6 | 2009-03-22 05:04:35 +0100 | [diff] [blame] | 6138 | unsigned int old_userobj; |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 6139 | unsigned long flags; |
| 6140 | int cnt = 0, cpu; |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 6141 | |
Steven Rostedt (Red Hat) | 7fe70b5 | 2013-03-15 13:10:35 -0400 | [diff] [blame] | 6142 | /* Only allow one dump user at a time. */ |
| 6143 | if (atomic_inc_return(&dump_running) != 1) { |
| 6144 | atomic_dec(&dump_running); |
| 6145 | return; |
Steven Rostedt | e0a413f | 2011-09-29 21:26:16 -0400 | [diff] [blame] | 6146 | } |
| 6147 | |
Steven Rostedt (Red Hat) | 7fe70b5 | 2013-03-15 13:10:35 -0400 | [diff] [blame] | 6148 | /* |
| 6149 | * Always turn off tracing when we dump. |
| 6150 | * We don't need to show trace output of what happens |
| 6151 | * between multiple crashes. |
| 6152 | * |
| 6153 | * If the user does a sysrq-z, then they can re-enable |
| 6154 | * tracing with echo 1 > tracing_on. |
| 6155 | */ |
| 6156 | tracing_off(); |
| 6157 | |
| 6158 | local_irq_save(flags); |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 6159 | |
Jovi Zhang | 38dbe0b | 2013-01-25 18:03:07 +0800 | [diff] [blame] | 6160 | /* Simulate the iterator */ |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 6161 | trace_init_global_iter(&iter); |
| 6162 | |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 6163 | for_each_tracing_cpu(cpu) { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 6164 | atomic_inc(&per_cpu_ptr(iter.tr->trace_buffer.data, cpu)->disabled); |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 6165 | } |
| 6166 | |
Frederic Weisbecker | cf586b6 | 2009-03-22 05:04:35 +0100 | [diff] [blame] | 6167 | old_userobj = trace_flags & TRACE_ITER_SYM_USEROBJ; |
| 6168 | |
Török Edwin | b54d3de | 2008-11-22 13:28:48 +0200 | [diff] [blame] | 6169 | /* don't look at user memory in panic mode */ |
| 6170 | trace_flags &= ~TRACE_ITER_SYM_USEROBJ; |
| 6171 | |
Frederic Weisbecker | cecbca9 | 2010-04-18 19:08:41 +0200 | [diff] [blame] | 6172 | switch (oops_dump_mode) { |
| 6173 | case DUMP_ALL: |
Steven Rostedt | ae3b509 | 2013-01-23 15:22:59 -0500 | [diff] [blame] | 6174 | iter.cpu_file = RING_BUFFER_ALL_CPUS; |
Frederic Weisbecker | cecbca9 | 2010-04-18 19:08:41 +0200 | [diff] [blame] | 6175 | break; |
| 6176 | case DUMP_ORIG: |
| 6177 | iter.cpu_file = raw_smp_processor_id(); |
| 6178 | break; |
| 6179 | case DUMP_NONE: |
| 6180 | goto out_enable; |
| 6181 | default: |
| 6182 | printk(KERN_TRACE "Bad dumping mode, switching to all CPUs dump\n"); |
Steven Rostedt | ae3b509 | 2013-01-23 15:22:59 -0500 | [diff] [blame] | 6183 | iter.cpu_file = RING_BUFFER_ALL_CPUS; |
Frederic Weisbecker | cecbca9 | 2010-04-18 19:08:41 +0200 | [diff] [blame] | 6184 | } |
| 6185 | |
| 6186 | printk(KERN_TRACE "Dumping ftrace buffer:\n"); |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 6187 | |
Steven Rostedt (Red Hat) | 7fe70b5 | 2013-03-15 13:10:35 -0400 | [diff] [blame] | 6188 | /* Did function tracer already get disabled? */ |
| 6189 | if (ftrace_is_dead()) { |
| 6190 | printk("# WARNING: FUNCTION TRACING IS CORRUPTED\n"); |
| 6191 | printk("# MAY BE MISSING FUNCTION EVENTS\n"); |
| 6192 | } |
| 6193 | |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 6194 | /* |
| 6195 | * We need to stop all tracing on all CPUS to read the |
| 6196 | * the next buffer. This is a bit expensive, but is |
| 6197 | * not done often. We fill all what we can read, |
| 6198 | * and then release the locks again. |
| 6199 | */ |
| 6200 | |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 6201 | while (!trace_empty(&iter)) { |
| 6202 | |
| 6203 | if (!cnt) |
| 6204 | printk(KERN_TRACE "---------------------------------\n"); |
| 6205 | |
| 6206 | cnt++; |
| 6207 | |
| 6208 | /* reset all but tr, trace, and overruns */ |
| 6209 | memset(&iter.seq, 0, |
| 6210 | sizeof(struct trace_iterator) - |
| 6211 | offsetof(struct trace_iterator, seq)); |
| 6212 | iter.iter_flags |= TRACE_FILE_LAT_FMT; |
| 6213 | iter.pos = -1; |
| 6214 | |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 6215 | if (trace_find_next_entry_inc(&iter) != NULL) { |
Lai Jiangshan | 74e7ff8 | 2009-07-28 20:17:22 +0800 | [diff] [blame] | 6216 | int ret; |
| 6217 | |
| 6218 | ret = print_trace_line(&iter); |
| 6219 | if (ret != TRACE_TYPE_NO_CONSUME) |
| 6220 | trace_consume(&iter); |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 6221 | } |
Steven Rostedt | b892e5c | 2012-03-01 22:06:48 -0500 | [diff] [blame] | 6222 | touch_nmi_watchdog(); |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 6223 | |
| 6224 | trace_printk_seq(&iter.seq); |
| 6225 | } |
| 6226 | |
| 6227 | if (!cnt) |
| 6228 | printk(KERN_TRACE " (ftrace buffer empty)\n"); |
| 6229 | else |
| 6230 | printk(KERN_TRACE "---------------------------------\n"); |
| 6231 | |
Frederic Weisbecker | cecbca9 | 2010-04-18 19:08:41 +0200 | [diff] [blame] | 6232 | out_enable: |
Steven Rostedt (Red Hat) | 7fe70b5 | 2013-03-15 13:10:35 -0400 | [diff] [blame] | 6233 | trace_flags |= old_userobj; |
Frederic Weisbecker | cf586b6 | 2009-03-22 05:04:35 +0100 | [diff] [blame] | 6234 | |
Steven Rostedt (Red Hat) | 7fe70b5 | 2013-03-15 13:10:35 -0400 | [diff] [blame] | 6235 | for_each_tracing_cpu(cpu) { |
| 6236 | atomic_dec(&per_cpu_ptr(iter.trace_buffer->data, cpu)->disabled); |
Frederic Weisbecker | cf586b6 | 2009-03-22 05:04:35 +0100 | [diff] [blame] | 6237 | } |
Steven Rostedt (Red Hat) | 7fe70b5 | 2013-03-15 13:10:35 -0400 | [diff] [blame] | 6238 | atomic_dec(&dump_running); |
Steven Rostedt | cd891ae | 2009-04-28 11:39:34 -0400 | [diff] [blame] | 6239 | local_irq_restore(flags); |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 6240 | } |
Paul E. McKenney | a8eecf2 | 2011-10-02 11:01:15 -0700 | [diff] [blame] | 6241 | EXPORT_SYMBOL_GPL(ftrace_dump); |
Frederic Weisbecker | cf586b6 | 2009-03-22 05:04:35 +0100 | [diff] [blame] | 6242 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 6243 | __init static int tracer_alloc_buffers(void) |
| 6244 | { |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 6245 | int ring_buf_size; |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 6246 | int ret = -ENOMEM; |
| 6247 | |
David Sharp | 750912f | 2010-12-08 13:46:47 -0800 | [diff] [blame] | 6248 | |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 6249 | if (!alloc_cpumask_var(&tracing_buffer_mask, GFP_KERNEL)) |
| 6250 | goto out; |
| 6251 | |
| 6252 | if (!alloc_cpumask_var(&tracing_cpumask, GFP_KERNEL)) |
| 6253 | goto out_free_buffer_mask; |
| 6254 | |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 6255 | /* Only allocate trace_printk buffers if a trace_printk exists */ |
| 6256 | if (__stop___trace_bprintk_fmt != __start___trace_bprintk_fmt) |
Steven Rostedt | 8169883 | 2012-10-11 10:15:05 -0400 | [diff] [blame] | 6257 | /* Must be called before global_trace.buffer is allocated */ |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 6258 | trace_printk_init_buffers(); |
| 6259 | |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 6260 | /* To save memory, keep the ring buffer size to its minimum */ |
| 6261 | if (ring_buffer_expanded) |
| 6262 | ring_buf_size = trace_buf_size; |
| 6263 | else |
| 6264 | ring_buf_size = 1; |
| 6265 | |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 6266 | cpumask_copy(tracing_buffer_mask, cpu_possible_mask); |
| 6267 | cpumask_copy(tracing_cpumask, cpu_all_mask); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 6268 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6269 | raw_spin_lock_init(&global_trace.start_lock); |
| 6270 | |
Steven Rostedt | ab46428 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 6271 | /* TODO: make the number of buffers hot pluggable with CPUS */ |
Steven Rostedt (Red Hat) | 737223f | 2013-03-05 21:13:47 -0500 | [diff] [blame] | 6272 | if (allocate_trace_buffers(&global_trace, ring_buf_size) < 0) { |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 6273 | printk(KERN_ERR "tracer: failed to allocate ring buffer!\n"); |
| 6274 | WARN_ON(1); |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 6275 | goto out_free_cpumask; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 6276 | } |
Steven Rostedt | a7603ff | 2012-08-06 16:24:11 -0400 | [diff] [blame] | 6277 | |
Steven Rostedt | 499e547 | 2012-02-22 15:50:28 -0500 | [diff] [blame] | 6278 | if (global_trace.buffer_disabled) |
| 6279 | tracing_off(); |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 6280 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 6281 | trace_init_cmdlines(); |
| 6282 | |
Steven Rostedt (Red Hat) | ca16431 | 2013-05-23 11:51:10 -0400 | [diff] [blame] | 6283 | /* |
| 6284 | * register_tracer() might reference current_trace, so it |
| 6285 | * needs to be set before we register anything. This is |
| 6286 | * just a bootstrap of current_trace anyway. |
| 6287 | */ |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6288 | global_trace.current_trace = &nop_trace; |
| 6289 | |
Steven Rostedt (Red Hat) | ca16431 | 2013-05-23 11:51:10 -0400 | [diff] [blame] | 6290 | register_tracer(&nop_trace); |
| 6291 | |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 6292 | /* All seems OK, enable tracing */ |
| 6293 | tracing_disabled = 0; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 6294 | |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 6295 | atomic_notifier_chain_register(&panic_notifier_list, |
| 6296 | &trace_panic_notifier); |
| 6297 | |
| 6298 | register_die_notifier(&trace_die_notifier); |
Frederic Weisbecker | 2fc1dfb | 2009-03-16 01:45:03 +0100 | [diff] [blame] | 6299 | |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 6300 | global_trace.flags = TRACE_ARRAY_FL_GLOBAL; |
| 6301 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6302 | /* Holder for file callbacks */ |
| 6303 | global_trace.trace_cpu.cpu = RING_BUFFER_ALL_CPUS; |
| 6304 | global_trace.trace_cpu.tr = &global_trace; |
| 6305 | |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 6306 | INIT_LIST_HEAD(&global_trace.systems); |
| 6307 | INIT_LIST_HEAD(&global_trace.events); |
| 6308 | list_add(&global_trace.list, &ftrace_trace_arrays); |
| 6309 | |
Steven Rostedt | 7bcfaf5 | 2012-11-01 22:56:07 -0400 | [diff] [blame] | 6310 | while (trace_boot_options) { |
| 6311 | char *option; |
| 6312 | |
| 6313 | option = strsep(&trace_boot_options, ","); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6314 | trace_set_options(&global_trace, option); |
Steven Rostedt | 7bcfaf5 | 2012-11-01 22:56:07 -0400 | [diff] [blame] | 6315 | } |
| 6316 | |
Steven Rostedt (Red Hat) | 77fd5c1 | 2013-03-12 11:49:18 -0400 | [diff] [blame] | 6317 | register_snapshot_cmd(); |
| 6318 | |
Frederic Weisbecker | 2fc1dfb | 2009-03-16 01:45:03 +0100 | [diff] [blame] | 6319 | return 0; |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 6320 | |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 6321 | out_free_cpumask: |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 6322 | free_percpu(global_trace.trace_buffer.data); |
| 6323 | #ifdef CONFIG_TRACER_MAX_TRACE |
| 6324 | free_percpu(global_trace.max_buffer.data); |
| 6325 | #endif |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 6326 | free_cpumask_var(tracing_cpumask); |
| 6327 | out_free_buffer_mask: |
| 6328 | free_cpumask_var(tracing_buffer_mask); |
| 6329 | out: |
| 6330 | return ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 6331 | } |
Steven Rostedt | b2821ae | 2009-02-02 21:38:32 -0500 | [diff] [blame] | 6332 | |
| 6333 | __init static int clear_boot_tracer(void) |
| 6334 | { |
| 6335 | /* |
| 6336 | * The default tracer at boot buffer is an init section. |
| 6337 | * This function is called in lateinit. If we did not |
| 6338 | * find the boot tracer, then clear it out, to prevent |
| 6339 | * later registration from accessing the buffer that is |
| 6340 | * about to be freed. |
| 6341 | */ |
| 6342 | if (!default_bootup_tracer) |
| 6343 | return 0; |
| 6344 | |
| 6345 | printk(KERN_INFO "ftrace bootup tracer '%s' not registered.\n", |
| 6346 | default_bootup_tracer); |
| 6347 | default_bootup_tracer = NULL; |
| 6348 | |
| 6349 | return 0; |
| 6350 | } |
| 6351 | |
Frédéric Weisbecker | b5ad384 | 2008-09-23 11:34:32 +0100 | [diff] [blame] | 6352 | early_initcall(tracer_alloc_buffers); |
| 6353 | fs_initcall(tracer_init_debugfs); |
Steven Rostedt | b2821ae | 2009-02-02 21:38:32 -0500 | [diff] [blame] | 6354 | late_initcall(clear_boot_tracer); |