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 | */ |
Li Zefan | 020e5f8 | 2009-07-01 10:47:05 +0800 | [diff] [blame] | 50 | int 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 | b2821ae | 2009-02-02 21:38:32 -0500 | [diff] [blame] | 118 | static int tracing_set_tracer(const char *buf); |
| 119 | |
Li Zefan | ee6c2c1 | 2009-09-18 14:06:47 +0800 | [diff] [blame] | 120 | #define MAX_TRACER_SIZE 100 |
| 121 | static char bootup_tracer_buf[MAX_TRACER_SIZE] __initdata; |
Steven Rostedt | b2821ae | 2009-02-02 21:38:32 -0500 | [diff] [blame] | 122 | static char *default_bootup_tracer; |
Peter Zijlstra | d9e5407 | 2008-11-01 19:57:37 +0100 | [diff] [blame] | 123 | |
Frederic Weisbecker | 1beee96 | 2009-10-14 20:50:32 +0200 | [diff] [blame] | 124 | static int __init set_cmdline_ftrace(char *str) |
Peter Zijlstra | d9e5407 | 2008-11-01 19:57:37 +0100 | [diff] [blame] | 125 | { |
Li Zefan | ee6c2c1 | 2009-09-18 14:06:47 +0800 | [diff] [blame] | 126 | strncpy(bootup_tracer_buf, str, MAX_TRACER_SIZE); |
Steven Rostedt | b2821ae | 2009-02-02 21:38:32 -0500 | [diff] [blame] | 127 | default_bootup_tracer = bootup_tracer_buf; |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 128 | /* We are using ftrace early, expand it */ |
| 129 | ring_buffer_expanded = 1; |
Peter Zijlstra | d9e5407 | 2008-11-01 19:57:37 +0100 | [diff] [blame] | 130 | return 1; |
| 131 | } |
Frederic Weisbecker | 1beee96 | 2009-10-14 20:50:32 +0200 | [diff] [blame] | 132 | __setup("ftrace=", set_cmdline_ftrace); |
Peter Zijlstra | d9e5407 | 2008-11-01 19:57:37 +0100 | [diff] [blame] | 133 | |
Steven Rostedt | 944ac42 | 2008-10-23 19:26:08 -0400 | [diff] [blame] | 134 | static int __init set_ftrace_dump_on_oops(char *str) |
| 135 | { |
Frederic Weisbecker | cecbca9 | 2010-04-18 19:08:41 +0200 | [diff] [blame] | 136 | if (*str++ != '=' || !*str) { |
| 137 | ftrace_dump_on_oops = DUMP_ALL; |
| 138 | return 1; |
| 139 | } |
| 140 | |
| 141 | if (!strcmp("orig_cpu", str)) { |
| 142 | ftrace_dump_on_oops = DUMP_ORIG; |
| 143 | return 1; |
| 144 | } |
| 145 | |
| 146 | return 0; |
Steven Rostedt | 944ac42 | 2008-10-23 19:26:08 -0400 | [diff] [blame] | 147 | } |
| 148 | __setup("ftrace_dump_on_oops", set_ftrace_dump_on_oops); |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 149 | |
Steven Rostedt | 7bcfaf5 | 2012-11-01 22:56:07 -0400 | [diff] [blame] | 150 | |
| 151 | static char trace_boot_options_buf[MAX_TRACER_SIZE] __initdata; |
| 152 | static char *trace_boot_options __initdata; |
| 153 | |
| 154 | static int __init set_trace_boot_options(char *str) |
| 155 | { |
| 156 | strncpy(trace_boot_options_buf, str, MAX_TRACER_SIZE); |
| 157 | trace_boot_options = trace_boot_options_buf; |
| 158 | return 0; |
| 159 | } |
| 160 | __setup("trace_options=", set_trace_boot_options); |
| 161 | |
Lai Jiangshan | cf8e347 | 2009-03-30 13:48:00 +0800 | [diff] [blame] | 162 | unsigned long long ns2usecs(cycle_t nsec) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 163 | { |
| 164 | nsec += 500; |
| 165 | do_div(nsec, 1000); |
| 166 | return nsec; |
| 167 | } |
| 168 | |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 169 | /* |
| 170 | * The global_trace is the descriptor that holds the tracing |
| 171 | * buffers for the live tracing. For each CPU, it contains |
| 172 | * a link list of pages that will store trace entries. The |
| 173 | * page descriptor of the pages in the memory is used to hold |
| 174 | * the link list by linking the lru item in the page descriptor |
| 175 | * to each of the pages in the buffer per CPU. |
| 176 | * |
| 177 | * For each active CPU there is a data field that holds the |
| 178 | * pages for the buffer for that CPU. Each CPU has the same number |
| 179 | * of pages allocated for its buffer. |
| 180 | */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 181 | static struct trace_array global_trace; |
| 182 | |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 183 | LIST_HEAD(ftrace_trace_arrays); |
| 184 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 185 | int filter_current_check_discard(struct ring_buffer *buffer, |
| 186 | struct ftrace_event_call *call, void *rec, |
Tom Zanussi | eb02ce0 | 2009-04-08 03:15:54 -0500 | [diff] [blame] | 187 | struct ring_buffer_event *event) |
| 188 | { |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 189 | return filter_check_discard(call, rec, buffer, event); |
Tom Zanussi | eb02ce0 | 2009-04-08 03:15:54 -0500 | [diff] [blame] | 190 | } |
Steven Rostedt | 17c873e | 2009-04-10 18:12:50 -0400 | [diff] [blame] | 191 | EXPORT_SYMBOL_GPL(filter_current_check_discard); |
Tom Zanussi | eb02ce0 | 2009-04-08 03:15:54 -0500 | [diff] [blame] | 192 | |
Steven Rostedt | 37886f6 | 2009-03-17 17:22:06 -0400 | [diff] [blame] | 193 | cycle_t ftrace_now(int cpu) |
| 194 | { |
| 195 | u64 ts; |
| 196 | |
| 197 | /* Early boot up does not have a buffer yet */ |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 198 | if (!global_trace.trace_buffer.buffer) |
Steven Rostedt | 37886f6 | 2009-03-17 17:22:06 -0400 | [diff] [blame] | 199 | return trace_clock_local(); |
| 200 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 201 | ts = ring_buffer_time_stamp(global_trace.trace_buffer.buffer, cpu); |
| 202 | ring_buffer_normalize_time_stamp(global_trace.trace_buffer.buffer, cpu, &ts); |
Steven Rostedt | 37886f6 | 2009-03-17 17:22:06 -0400 | [diff] [blame] | 203 | |
| 204 | return ts; |
| 205 | } |
| 206 | |
Steven Rostedt | 9036990 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 207 | int tracing_is_enabled(void) |
| 208 | { |
Steven Rostedt | 0fb9656 | 2012-05-11 14:25:30 -0400 | [diff] [blame] | 209 | return tracing_is_on(); |
Steven Rostedt | 9036990 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 210 | } |
| 211 | |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 212 | /* |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 213 | * trace_buf_size is the size in bytes that is allocated |
| 214 | * for a buffer. Note, the number of bytes is always rounded |
| 215 | * to page size. |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 216 | * |
| 217 | * This number is purposely set to a low number of 16384. |
| 218 | * If the dump on oops happens, it will be much appreciated |
| 219 | * to not have to wait for all that output. Anyway this can be |
| 220 | * boot time and run time configurable. |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 221 | */ |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 222 | #define TRACE_BUF_SIZE_DEFAULT 1441792UL /* 16384 * 88 (sizeof(entry)) */ |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 223 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 224 | static unsigned long trace_buf_size = TRACE_BUF_SIZE_DEFAULT; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 225 | |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 226 | /* trace_types holds a link list of available tracers. */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 227 | static struct tracer *trace_types __read_mostly; |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 228 | |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 229 | /* |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 230 | * trace_types_lock is used to protect the trace_types list. |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 231 | */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 232 | static DEFINE_MUTEX(trace_types_lock); |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 233 | |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 234 | /* |
| 235 | * serialize the access of the ring buffer |
| 236 | * |
| 237 | * ring buffer serializes readers, but it is low level protection. |
| 238 | * The validity of the events (which returns by ring_buffer_peek() ..etc) |
| 239 | * are not protected by ring buffer. |
| 240 | * |
| 241 | * The content of events may become garbage if we allow other process consumes |
| 242 | * these events concurrently: |
| 243 | * A) the page of the consumed events may become a normal page |
| 244 | * (not reader page) in ring buffer, and this page will be rewrited |
| 245 | * by events producer. |
| 246 | * B) The page of the consumed events may become a page for splice_read, |
| 247 | * and this page will be returned to system. |
| 248 | * |
| 249 | * These primitives allow multi process access to different cpu ring buffer |
| 250 | * concurrently. |
| 251 | * |
| 252 | * These primitives don't distinguish read-only and read-consume access. |
| 253 | * Multi read-only access are also serialized. |
| 254 | */ |
| 255 | |
| 256 | #ifdef CONFIG_SMP |
| 257 | static DECLARE_RWSEM(all_cpu_access_lock); |
| 258 | static DEFINE_PER_CPU(struct mutex, cpu_access_lock); |
| 259 | |
| 260 | static inline void trace_access_lock(int cpu) |
| 261 | { |
Steven Rostedt | ae3b509 | 2013-01-23 15:22:59 -0500 | [diff] [blame] | 262 | if (cpu == RING_BUFFER_ALL_CPUS) { |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 263 | /* gain it for accessing the whole ring buffer. */ |
| 264 | down_write(&all_cpu_access_lock); |
| 265 | } else { |
| 266 | /* gain it for accessing a cpu ring buffer. */ |
| 267 | |
Steven Rostedt | ae3b509 | 2013-01-23 15:22:59 -0500 | [diff] [blame] | 268 | /* Firstly block other trace_access_lock(RING_BUFFER_ALL_CPUS). */ |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 269 | down_read(&all_cpu_access_lock); |
| 270 | |
| 271 | /* Secondly block other access to this @cpu ring buffer. */ |
| 272 | mutex_lock(&per_cpu(cpu_access_lock, cpu)); |
| 273 | } |
| 274 | } |
| 275 | |
| 276 | static inline void trace_access_unlock(int cpu) |
| 277 | { |
Steven Rostedt | ae3b509 | 2013-01-23 15:22:59 -0500 | [diff] [blame] | 278 | if (cpu == RING_BUFFER_ALL_CPUS) { |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 279 | up_write(&all_cpu_access_lock); |
| 280 | } else { |
| 281 | mutex_unlock(&per_cpu(cpu_access_lock, cpu)); |
| 282 | up_read(&all_cpu_access_lock); |
| 283 | } |
| 284 | } |
| 285 | |
| 286 | static inline void trace_access_lock_init(void) |
| 287 | { |
| 288 | int cpu; |
| 289 | |
| 290 | for_each_possible_cpu(cpu) |
| 291 | mutex_init(&per_cpu(cpu_access_lock, cpu)); |
| 292 | } |
| 293 | |
| 294 | #else |
| 295 | |
| 296 | static DEFINE_MUTEX(access_lock); |
| 297 | |
| 298 | static inline void trace_access_lock(int cpu) |
| 299 | { |
| 300 | (void)cpu; |
| 301 | mutex_lock(&access_lock); |
| 302 | } |
| 303 | |
| 304 | static inline void trace_access_unlock(int cpu) |
| 305 | { |
| 306 | (void)cpu; |
| 307 | mutex_unlock(&access_lock); |
| 308 | } |
| 309 | |
| 310 | static inline void trace_access_lock_init(void) |
| 311 | { |
| 312 | } |
| 313 | |
| 314 | #endif |
| 315 | |
Steven Rostedt | ee6bce5 | 2008-11-12 17:52:37 -0500 | [diff] [blame] | 316 | /* trace_flags holds trace_options default values */ |
Steven Rostedt | 12ef7d4 | 2008-11-12 17:52:38 -0500 | [diff] [blame] | 317 | unsigned long trace_flags = TRACE_ITER_PRINT_PARENT | TRACE_ITER_PRINTK | |
Steven Rostedt | a2a16d6 | 2009-03-24 23:17:58 -0400 | [diff] [blame] | 318 | TRACE_ITER_ANNOTATE | TRACE_ITER_CONTEXT_INFO | TRACE_ITER_SLEEP_TIME | |
Steven Rostedt | 77271ce | 2011-11-17 09:34:33 -0500 | [diff] [blame] | 319 | TRACE_ITER_GRAPH_TIME | TRACE_ITER_RECORD_CMD | TRACE_ITER_OVERWRITE | |
Mandeep Singh Baines | 5224c3a | 2012-09-07 18:12:19 -0700 | [diff] [blame] | 320 | TRACE_ITER_IRQ_INFO | TRACE_ITER_MARKERS; |
Ingo Molnar | 4e65551 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 321 | |
Steven Rostedt | 0d5c6e1 | 2012-11-01 20:54:21 -0400 | [diff] [blame] | 322 | /** |
Steven Rostedt | 499e547 | 2012-02-22 15:50:28 -0500 | [diff] [blame] | 323 | * tracing_on - enable tracing buffers |
| 324 | * |
| 325 | * This function enables tracing buffers that may have been |
| 326 | * disabled with tracing_off. |
| 327 | */ |
| 328 | void tracing_on(void) |
| 329 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 330 | if (global_trace.trace_buffer.buffer) |
| 331 | ring_buffer_record_on(global_trace.trace_buffer.buffer); |
Steven Rostedt | 499e547 | 2012-02-22 15:50:28 -0500 | [diff] [blame] | 332 | /* |
| 333 | * This flag is only looked at when buffers haven't been |
| 334 | * allocated yet. We don't really care about the race |
| 335 | * between setting this flag and actually turning |
| 336 | * on the buffer. |
| 337 | */ |
| 338 | global_trace.buffer_disabled = 0; |
| 339 | } |
| 340 | EXPORT_SYMBOL_GPL(tracing_on); |
| 341 | |
| 342 | /** |
| 343 | * tracing_off - turn off tracing buffers |
| 344 | * |
| 345 | * This function stops the tracing buffers from recording data. |
| 346 | * It does not disable any overhead the tracers themselves may |
| 347 | * be causing. This function simply causes all recording to |
| 348 | * the ring buffers to fail. |
| 349 | */ |
| 350 | void tracing_off(void) |
| 351 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 352 | if (global_trace.trace_buffer.buffer) |
| 353 | ring_buffer_record_off(global_trace.trace_buffer.buffer); |
Steven Rostedt | 499e547 | 2012-02-22 15:50:28 -0500 | [diff] [blame] | 354 | /* |
| 355 | * This flag is only looked at when buffers haven't been |
| 356 | * allocated yet. We don't really care about the race |
| 357 | * between setting this flag and actually turning |
| 358 | * on the buffer. |
| 359 | */ |
| 360 | global_trace.buffer_disabled = 1; |
| 361 | } |
| 362 | EXPORT_SYMBOL_GPL(tracing_off); |
| 363 | |
| 364 | /** |
| 365 | * tracing_is_on - show state of ring buffers enabled |
| 366 | */ |
| 367 | int tracing_is_on(void) |
| 368 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 369 | if (global_trace.trace_buffer.buffer) |
| 370 | return ring_buffer_record_is_on(global_trace.trace_buffer.buffer); |
Steven Rostedt | 499e547 | 2012-02-22 15:50:28 -0500 | [diff] [blame] | 371 | return !global_trace.buffer_disabled; |
| 372 | } |
| 373 | EXPORT_SYMBOL_GPL(tracing_is_on); |
| 374 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 375 | static int __init set_buf_size(char *str) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 376 | { |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 377 | unsigned long buf_size; |
Steven Rostedt | c6caeeb | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 378 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 379 | if (!str) |
| 380 | return 0; |
Li Zefan | 9d612be | 2009-06-24 17:33:15 +0800 | [diff] [blame] | 381 | buf_size = memparse(str, &str); |
Steven Rostedt | c6caeeb | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 382 | /* nr_entries can not be zero */ |
Li Zefan | 9d612be | 2009-06-24 17:33:15 +0800 | [diff] [blame] | 383 | if (buf_size == 0) |
Steven Rostedt | c6caeeb | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 384 | return 0; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 385 | trace_buf_size = buf_size; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 386 | return 1; |
| 387 | } |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 388 | __setup("trace_buf_size=", set_buf_size); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 389 | |
Tim Bird | 0e95017 | 2010-02-25 15:36:43 -0800 | [diff] [blame] | 390 | static int __init set_tracing_thresh(char *str) |
| 391 | { |
Wang Tianhong | 87abb3b | 2012-08-02 14:02:00 +0800 | [diff] [blame] | 392 | unsigned long threshold; |
Tim Bird | 0e95017 | 2010-02-25 15:36:43 -0800 | [diff] [blame] | 393 | int ret; |
| 394 | |
| 395 | if (!str) |
| 396 | return 0; |
Daniel Walter | bcd83ea | 2012-09-26 22:08:38 +0200 | [diff] [blame] | 397 | ret = kstrtoul(str, 0, &threshold); |
Tim Bird | 0e95017 | 2010-02-25 15:36:43 -0800 | [diff] [blame] | 398 | if (ret < 0) |
| 399 | return 0; |
Wang Tianhong | 87abb3b | 2012-08-02 14:02:00 +0800 | [diff] [blame] | 400 | tracing_thresh = threshold * 1000; |
Tim Bird | 0e95017 | 2010-02-25 15:36:43 -0800 | [diff] [blame] | 401 | return 1; |
| 402 | } |
| 403 | __setup("tracing_thresh=", set_tracing_thresh); |
| 404 | |
Steven Rostedt | 57f50be | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 405 | unsigned long nsecs_to_usecs(unsigned long nsecs) |
| 406 | { |
| 407 | return nsecs / 1000; |
| 408 | } |
| 409 | |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 410 | /* These must match the bit postions in trace_iterator_flags */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 411 | static const char *trace_options[] = { |
| 412 | "print-parent", |
| 413 | "sym-offset", |
| 414 | "sym-addr", |
| 415 | "verbose", |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 416 | "raw", |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 417 | "hex", |
Ingo Molnar | cb0f12a | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 418 | "bin", |
Soeren Sandmann Pedersen | 2a2cc8f | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 419 | "block", |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 420 | "stacktrace", |
Ingo Molnar | 5e1607a | 2009-03-05 10:24:48 +0100 | [diff] [blame] | 421 | "trace_printk", |
Steven Rostedt | b2a866f | 2008-11-03 23:15:57 -0500 | [diff] [blame] | 422 | "ftrace_preempt", |
Steven Rostedt | 9f029e8 | 2008-11-12 15:24:24 -0500 | [diff] [blame] | 423 | "branch", |
Steven Rostedt | 12ef7d4 | 2008-11-12 17:52:38 -0500 | [diff] [blame] | 424 | "annotate", |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 425 | "userstacktrace", |
Török Edwin | b54d3de | 2008-11-22 13:28:48 +0200 | [diff] [blame] | 426 | "sym-userobj", |
Frederic Weisbecker | 66896a8 | 2008-12-13 20:18:13 +0100 | [diff] [blame] | 427 | "printk-msg-only", |
Frederic Weisbecker | c4a8e8b | 2009-02-02 20:29:21 -0200 | [diff] [blame] | 428 | "context-info", |
Steven Rostedt | c032ef64 | 2009-03-04 20:34:24 -0500 | [diff] [blame] | 429 | "latency-format", |
Steven Rostedt | be6f164 | 2009-03-24 11:06:24 -0400 | [diff] [blame] | 430 | "sleep-time", |
Steven Rostedt | a2a16d6 | 2009-03-24 23:17:58 -0400 | [diff] [blame] | 431 | "graph-time", |
Li Zefan | e870e9a | 2010-07-02 11:07:32 +0800 | [diff] [blame] | 432 | "record-cmd", |
David Sharp | 750912f | 2010-12-08 13:46:47 -0800 | [diff] [blame] | 433 | "overwrite", |
Steven Rostedt | cf30cf6 | 2011-06-14 22:44:07 -0400 | [diff] [blame] | 434 | "disable_on_free", |
Steven Rostedt | 77271ce | 2011-11-17 09:34:33 -0500 | [diff] [blame] | 435 | "irq-info", |
Mandeep Singh Baines | 5224c3a | 2012-09-07 18:12:19 -0700 | [diff] [blame] | 436 | "markers", |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 437 | NULL |
| 438 | }; |
| 439 | |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 440 | static struct { |
| 441 | u64 (*func)(void); |
| 442 | const char *name; |
David Sharp | 8be0709 | 2012-11-13 12:18:22 -0800 | [diff] [blame] | 443 | int in_ns; /* is this clock in nanoseconds? */ |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 444 | } trace_clocks[] = { |
David Sharp | 8be0709 | 2012-11-13 12:18:22 -0800 | [diff] [blame] | 445 | { trace_clock_local, "local", 1 }, |
| 446 | { trace_clock_global, "global", 1 }, |
| 447 | { trace_clock_counter, "counter", 0 }, |
David Sharp | 8cbd9cc | 2012-11-13 12:18:21 -0800 | [diff] [blame] | 448 | ARCH_TRACE_CLOCKS |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 449 | }; |
| 450 | |
| 451 | int trace_clock_id; |
| 452 | |
jolsa@redhat.com | b63f39e | 2009-09-11 17:29:27 +0200 | [diff] [blame] | 453 | /* |
| 454 | * trace_parser_get_init - gets the buffer for trace parser |
| 455 | */ |
| 456 | int trace_parser_get_init(struct trace_parser *parser, int size) |
| 457 | { |
| 458 | memset(parser, 0, sizeof(*parser)); |
| 459 | |
| 460 | parser->buffer = kmalloc(size, GFP_KERNEL); |
| 461 | if (!parser->buffer) |
| 462 | return 1; |
| 463 | |
| 464 | parser->size = size; |
| 465 | return 0; |
| 466 | } |
| 467 | |
| 468 | /* |
| 469 | * trace_parser_put - frees the buffer for trace parser |
| 470 | */ |
| 471 | void trace_parser_put(struct trace_parser *parser) |
| 472 | { |
| 473 | kfree(parser->buffer); |
| 474 | } |
| 475 | |
| 476 | /* |
| 477 | * trace_get_user - reads the user input string separated by space |
| 478 | * (matched by isspace(ch)) |
| 479 | * |
| 480 | * For each string found the 'struct trace_parser' is updated, |
| 481 | * and the function returns. |
| 482 | * |
| 483 | * Returns number of bytes read. |
| 484 | * |
| 485 | * See kernel/trace/trace.h for 'struct trace_parser' details. |
| 486 | */ |
| 487 | int trace_get_user(struct trace_parser *parser, const char __user *ubuf, |
| 488 | size_t cnt, loff_t *ppos) |
| 489 | { |
| 490 | char ch; |
| 491 | size_t read = 0; |
| 492 | ssize_t ret; |
| 493 | |
| 494 | if (!*ppos) |
| 495 | trace_parser_clear(parser); |
| 496 | |
| 497 | ret = get_user(ch, ubuf++); |
| 498 | if (ret) |
| 499 | goto out; |
| 500 | |
| 501 | read++; |
| 502 | cnt--; |
| 503 | |
| 504 | /* |
| 505 | * The parser is not finished with the last write, |
| 506 | * continue reading the user input without skipping spaces. |
| 507 | */ |
| 508 | if (!parser->cont) { |
| 509 | /* skip white space */ |
| 510 | while (cnt && isspace(ch)) { |
| 511 | ret = get_user(ch, ubuf++); |
| 512 | if (ret) |
| 513 | goto out; |
| 514 | read++; |
| 515 | cnt--; |
| 516 | } |
| 517 | |
| 518 | /* only spaces were written */ |
| 519 | if (isspace(ch)) { |
| 520 | *ppos += read; |
| 521 | ret = read; |
| 522 | goto out; |
| 523 | } |
| 524 | |
| 525 | parser->idx = 0; |
| 526 | } |
| 527 | |
| 528 | /* read the non-space input */ |
| 529 | while (cnt && !isspace(ch)) { |
Li Zefan | 3c235a3 | 2009-09-22 13:51:54 +0800 | [diff] [blame] | 530 | if (parser->idx < parser->size - 1) |
jolsa@redhat.com | b63f39e | 2009-09-11 17:29:27 +0200 | [diff] [blame] | 531 | parser->buffer[parser->idx++] = ch; |
| 532 | else { |
| 533 | ret = -EINVAL; |
| 534 | goto out; |
| 535 | } |
| 536 | ret = get_user(ch, ubuf++); |
| 537 | if (ret) |
| 538 | goto out; |
| 539 | read++; |
| 540 | cnt--; |
| 541 | } |
| 542 | |
| 543 | /* We either got finished input or we have to wait for another call. */ |
| 544 | if (isspace(ch)) { |
| 545 | parser->buffer[parser->idx] = 0; |
| 546 | parser->cont = false; |
| 547 | } else { |
| 548 | parser->cont = true; |
| 549 | parser->buffer[parser->idx++] = ch; |
| 550 | } |
| 551 | |
| 552 | *ppos += read; |
| 553 | ret = read; |
| 554 | |
| 555 | out: |
| 556 | return ret; |
| 557 | } |
| 558 | |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 559 | ssize_t trace_seq_to_user(struct trace_seq *s, char __user *ubuf, size_t cnt) |
| 560 | { |
| 561 | int len; |
| 562 | int ret; |
| 563 | |
Steven Rostedt | 2dc5d12 | 2009-03-04 19:10:05 -0500 | [diff] [blame] | 564 | if (!cnt) |
| 565 | return 0; |
| 566 | |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 567 | if (s->len <= s->readpos) |
| 568 | return -EBUSY; |
| 569 | |
| 570 | len = s->len - s->readpos; |
| 571 | if (cnt > len) |
| 572 | cnt = len; |
| 573 | ret = copy_to_user(ubuf, s->buffer + s->readpos, cnt); |
Steven Rostedt | 2dc5d12 | 2009-03-04 19:10:05 -0500 | [diff] [blame] | 574 | if (ret == cnt) |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 575 | return -EFAULT; |
| 576 | |
Steven Rostedt | 2dc5d12 | 2009-03-04 19:10:05 -0500 | [diff] [blame] | 577 | cnt -= ret; |
| 578 | |
Steven Rostedt | e74da52 | 2009-03-04 20:31:11 -0500 | [diff] [blame] | 579 | s->readpos += cnt; |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 580 | return cnt; |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 581 | } |
| 582 | |
Dmitri Vorobiev | b8b9426 | 2009-03-22 19:11:11 +0200 | [diff] [blame] | 583 | 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] | 584 | { |
| 585 | int len; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 586 | |
| 587 | if (s->len <= s->readpos) |
| 588 | return -EBUSY; |
| 589 | |
| 590 | len = s->len - s->readpos; |
| 591 | if (cnt > len) |
| 592 | cnt = len; |
Dan Carpenter | 5a26c8f | 2012-04-20 09:31:45 +0300 | [diff] [blame] | 593 | memcpy(buf, s->buffer + s->readpos, cnt); |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 594 | |
Steven Rostedt | e74da52 | 2009-03-04 20:31:11 -0500 | [diff] [blame] | 595 | s->readpos += cnt; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 596 | return cnt; |
| 597 | } |
| 598 | |
Steven Rostedt | 5d4a9db | 2009-08-27 16:52:21 -0400 | [diff] [blame] | 599 | /* |
| 600 | * ftrace_max_lock is used to protect the swapping of buffers |
| 601 | * when taking a max snapshot. The buffers themselves are |
| 602 | * protected by per_cpu spinlocks. But the action of the swap |
| 603 | * needs its own lock. |
| 604 | * |
Thomas Gleixner | 445c895 | 2009-12-02 19:49:50 +0100 | [diff] [blame] | 605 | * This is defined as a arch_spinlock_t in order to help |
Steven Rostedt | 5d4a9db | 2009-08-27 16:52:21 -0400 | [diff] [blame] | 606 | * with performance when lockdep debugging is enabled. |
| 607 | * |
| 608 | * It is also used in other places outside the update_max_tr |
| 609 | * so it needs to be defined outside of the |
| 610 | * CONFIG_TRACER_MAX_TRACE. |
| 611 | */ |
Thomas Gleixner | 445c895 | 2009-12-02 19:49:50 +0100 | [diff] [blame] | 612 | static arch_spinlock_t ftrace_max_lock = |
Thomas Gleixner | edc35bd | 2009-12-03 12:38:57 +0100 | [diff] [blame] | 613 | (arch_spinlock_t)__ARCH_SPIN_LOCK_UNLOCKED; |
Steven Rostedt | 5d4a9db | 2009-08-27 16:52:21 -0400 | [diff] [blame] | 614 | |
Tim Bird | 0e95017 | 2010-02-25 15:36:43 -0800 | [diff] [blame] | 615 | unsigned long __read_mostly tracing_thresh; |
| 616 | |
Steven Rostedt | 5d4a9db | 2009-08-27 16:52:21 -0400 | [diff] [blame] | 617 | #ifdef CONFIG_TRACER_MAX_TRACE |
| 618 | unsigned long __read_mostly tracing_max_latency; |
Steven Rostedt | 5d4a9db | 2009-08-27 16:52:21 -0400 | [diff] [blame] | 619 | |
| 620 | /* |
| 621 | * Copy the new maximum trace into the separate maximum-trace |
| 622 | * structure. (this way the maximum trace is permanently saved, |
| 623 | * for later retrieval via /sys/kernel/debug/tracing/latency_trace) |
| 624 | */ |
| 625 | static void |
| 626 | __update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu) |
| 627 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 628 | struct trace_buffer *trace_buf = &tr->trace_buffer; |
| 629 | struct trace_buffer *max_buf = &tr->max_buffer; |
| 630 | struct trace_array_cpu *data = per_cpu_ptr(trace_buf->data, cpu); |
| 631 | 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] | 632 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 633 | max_buf->cpu = cpu; |
| 634 | max_buf->time_start = data->preempt_timestamp; |
Steven Rostedt | 5d4a9db | 2009-08-27 16:52:21 -0400 | [diff] [blame] | 635 | |
Steven Rostedt | 8248ac0 | 2009-09-02 12:27:41 -0400 | [diff] [blame] | 636 | max_data->saved_latency = tracing_max_latency; |
| 637 | max_data->critical_start = data->critical_start; |
| 638 | max_data->critical_end = data->critical_end; |
Steven Rostedt | 5d4a9db | 2009-08-27 16:52:21 -0400 | [diff] [blame] | 639 | |
Arnaldo Carvalho de Melo | 1acaa1b | 2010-03-05 18:23:50 -0300 | [diff] [blame] | 640 | memcpy(max_data->comm, tsk->comm, TASK_COMM_LEN); |
Steven Rostedt | 8248ac0 | 2009-09-02 12:27:41 -0400 | [diff] [blame] | 641 | max_data->pid = tsk->pid; |
| 642 | max_data->uid = task_uid(tsk); |
| 643 | max_data->nice = tsk->static_prio - 20 - MAX_RT_PRIO; |
| 644 | max_data->policy = tsk->policy; |
| 645 | max_data->rt_priority = tsk->rt_priority; |
Steven Rostedt | 5d4a9db | 2009-08-27 16:52:21 -0400 | [diff] [blame] | 646 | |
| 647 | /* record this tasks comm */ |
| 648 | tracing_record_cmdline(tsk); |
| 649 | } |
| 650 | |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 651 | /** |
| 652 | * update_max_tr - snapshot all trace buffers from global_trace to max_tr |
| 653 | * @tr: tracer |
| 654 | * @tsk: the task with the latency |
| 655 | * @cpu: The cpu that initiated the trace. |
| 656 | * |
| 657 | * Flip the buffers between the @tr and the max_tr and record information |
| 658 | * about which task was the cause of this latency. |
| 659 | */ |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 660 | void |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 661 | update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu) |
| 662 | { |
Steven Rostedt (Red Hat) | 2721e72 | 2013-03-12 11:32:32 -0400 | [diff] [blame] | 663 | struct ring_buffer *buf; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 664 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 665 | if (tr->stop_count) |
Steven Rostedt | b8de7bd1 | 2009-08-31 22:32:27 -0400 | [diff] [blame] | 666 | return; |
| 667 | |
Steven Rostedt | 4c11d7a | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 668 | WARN_ON_ONCE(!irqs_disabled()); |
Steven Rostedt | 34600f0 | 2013-01-22 13:35:11 -0500 | [diff] [blame] | 669 | |
Steven Rostedt (Red Hat) | 45ad21c | 2013-03-05 18:25:02 -0500 | [diff] [blame] | 670 | if (!tr->allocated_snapshot) { |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 671 | /* Only the nop tracer should hit this when disabling */ |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 672 | WARN_ON_ONCE(tr->current_trace != &nop_trace); |
KOSAKI Motohiro | ef710e1 | 2010-07-01 14:34:35 +0900 | [diff] [blame] | 673 | return; |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 674 | } |
Steven Rostedt | 34600f0 | 2013-01-22 13:35:11 -0500 | [diff] [blame] | 675 | |
Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 676 | arch_spin_lock(&ftrace_max_lock); |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 677 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 678 | buf = tr->trace_buffer.buffer; |
| 679 | tr->trace_buffer.buffer = tr->max_buffer.buffer; |
| 680 | tr->max_buffer.buffer = buf; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 681 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 682 | __update_max_tr(tr, tsk, cpu); |
Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 683 | arch_spin_unlock(&ftrace_max_lock); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 684 | } |
| 685 | |
| 686 | /** |
| 687 | * update_max_tr_single - only copy one trace over, and reset the rest |
| 688 | * @tr - tracer |
| 689 | * @tsk - task with the latency |
| 690 | * @cpu - the cpu of the buffer to copy. |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 691 | * |
| 692 | * 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] | 693 | */ |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 694 | void |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 695 | update_max_tr_single(struct trace_array *tr, struct task_struct *tsk, int cpu) |
| 696 | { |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 697 | int ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 698 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 699 | if (tr->stop_count) |
Steven Rostedt | b8de7bd1 | 2009-08-31 22:32:27 -0400 | [diff] [blame] | 700 | return; |
| 701 | |
Steven Rostedt | 4c11d7a | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 702 | WARN_ON_ONCE(!irqs_disabled()); |
Steven Rostedt (Red Hat) | 45ad21c | 2013-03-05 18:25:02 -0500 | [diff] [blame] | 703 | if (WARN_ON_ONCE(!tr->allocated_snapshot)) |
KOSAKI Motohiro | ef710e1 | 2010-07-01 14:34:35 +0900 | [diff] [blame] | 704 | return; |
KOSAKI Motohiro | ef710e1 | 2010-07-01 14:34:35 +0900 | [diff] [blame] | 705 | |
Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 706 | arch_spin_lock(&ftrace_max_lock); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 707 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 708 | 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] | 709 | |
Steven Rostedt | e8165dbb | 2009-09-03 19:13:05 -0400 | [diff] [blame] | 710 | if (ret == -EBUSY) { |
| 711 | /* |
| 712 | * We failed to swap the buffer due to a commit taking |
| 713 | * place on this CPU. We fail to record, but we reset |
| 714 | * the max trace buffer (no one writes directly to it) |
| 715 | * and flag that it failed. |
| 716 | */ |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 717 | trace_array_printk_buf(tr->max_buffer.buffer, _THIS_IP_, |
Steven Rostedt | e8165dbb | 2009-09-03 19:13:05 -0400 | [diff] [blame] | 718 | "Failed to swap buffers due to commit in progress\n"); |
| 719 | } |
| 720 | |
Steven Rostedt | e8165dbb | 2009-09-03 19:13:05 -0400 | [diff] [blame] | 721 | WARN_ON_ONCE(ret && ret != -EAGAIN && ret != -EBUSY); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 722 | |
| 723 | __update_max_tr(tr, tsk, cpu); |
Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 724 | arch_spin_unlock(&ftrace_max_lock); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 725 | } |
Steven Rostedt | 5d4a9db | 2009-08-27 16:52:21 -0400 | [diff] [blame] | 726 | #endif /* CONFIG_TRACER_MAX_TRACE */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 727 | |
Steven Rostedt | 0d5c6e1 | 2012-11-01 20:54:21 -0400 | [diff] [blame] | 728 | static void default_wait_pipe(struct trace_iterator *iter) |
| 729 | { |
Steven Rostedt (Red Hat) | 1569345 | 2013-02-28 19:59:17 -0500 | [diff] [blame] | 730 | /* Iterators are static, they should be filled or empty */ |
| 731 | if (trace_buffer_iter(iter, iter->cpu_file)) |
| 732 | return; |
Steven Rostedt | 0d5c6e1 | 2012-11-01 20:54:21 -0400 | [diff] [blame] | 733 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 734 | ring_buffer_wait(iter->trace_buffer->buffer, iter->cpu_file); |
Steven Rostedt | 0d5c6e1 | 2012-11-01 20:54:21 -0400 | [diff] [blame] | 735 | } |
| 736 | |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 737 | /** |
| 738 | * register_tracer - register a tracer with the ftrace system. |
| 739 | * @type - the plugin for the tracer |
| 740 | * |
| 741 | * Register a new plugin tracer. |
| 742 | */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 743 | int register_tracer(struct tracer *type) |
| 744 | { |
| 745 | struct tracer *t; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 746 | int ret = 0; |
| 747 | |
| 748 | if (!type->name) { |
| 749 | pr_info("Tracer must have a name\n"); |
| 750 | return -1; |
| 751 | } |
| 752 | |
Dan Carpenter | 24a461d | 2010-07-10 12:06:44 +0200 | [diff] [blame] | 753 | if (strlen(type->name) >= MAX_TRACER_SIZE) { |
Li Zefan | ee6c2c1 | 2009-09-18 14:06:47 +0800 | [diff] [blame] | 754 | pr_info("Tracer has a name longer than %d\n", MAX_TRACER_SIZE); |
| 755 | return -1; |
| 756 | } |
| 757 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 758 | mutex_lock(&trace_types_lock); |
Ingo Molnar | 86fa2f6 | 2008-11-19 10:00:15 +0100 | [diff] [blame] | 759 | |
Frederic Weisbecker | 8e1b82e | 2008-12-06 03:41:33 +0100 | [diff] [blame] | 760 | tracing_selftest_running = true; |
| 761 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 762 | for (t = trace_types; t; t = t->next) { |
| 763 | if (strcmp(type->name, t->name) == 0) { |
| 764 | /* already found */ |
Li Zefan | ee6c2c1 | 2009-09-18 14:06:47 +0800 | [diff] [blame] | 765 | pr_info("Tracer %s already registered\n", |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 766 | type->name); |
| 767 | ret = -1; |
| 768 | goto out; |
| 769 | } |
| 770 | } |
| 771 | |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 772 | if (!type->set_flag) |
| 773 | type->set_flag = &dummy_set_flag; |
| 774 | if (!type->flags) |
| 775 | type->flags = &dummy_tracer_flags; |
| 776 | else |
| 777 | if (!type->flags->opts) |
| 778 | type->flags->opts = dummy_tracer_opt; |
Frederic Weisbecker | 6eaaa5d | 2009-02-11 02:25:00 +0100 | [diff] [blame] | 779 | if (!type->wait_pipe) |
| 780 | type->wait_pipe = default_wait_pipe; |
| 781 | |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 782 | |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 783 | #ifdef CONFIG_FTRACE_STARTUP_TEST |
Steven Rostedt | b2821ae | 2009-02-02 21:38:32 -0500 | [diff] [blame] | 784 | if (type->selftest && !tracing_selftest_disabled) { |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 785 | struct trace_array *tr = &global_trace; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 786 | struct tracer *saved_tracer = tr->current_trace; |
Frederic Weisbecker | ff32504 | 2008-12-04 23:47:35 +0100 | [diff] [blame] | 787 | |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 788 | /* |
| 789 | * Run a selftest on this tracer. |
| 790 | * Here we reset the trace buffer, and set the current |
| 791 | * tracer to be this tracer. The tracer can then run some |
| 792 | * internal tracing to verify that everything is in order. |
| 793 | * If we fail, we do not register this tracer. |
| 794 | */ |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 795 | tracing_reset_online_cpus(&tr->trace_buffer); |
Ingo Molnar | 86fa2f6 | 2008-11-19 10:00:15 +0100 | [diff] [blame] | 796 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 797 | tr->current_trace = type; |
Steven Rostedt | 4a0b166 | 2011-03-09 20:09:26 -0500 | [diff] [blame] | 798 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 799 | #ifdef CONFIG_TRACER_MAX_TRACE |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 800 | if (type->use_max_tr) { |
| 801 | /* If we expanded the buffers, make sure the max is expanded too */ |
| 802 | if (ring_buffer_expanded) |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 803 | ring_buffer_resize(tr->max_buffer.buffer, trace_buf_size, |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 804 | RING_BUFFER_ALL_CPUS); |
Steven Rostedt (Red Hat) | 45ad21c | 2013-03-05 18:25:02 -0500 | [diff] [blame] | 805 | tr->allocated_snapshot = true; |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 806 | } |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 807 | #endif |
Steven Rostedt | 4a0b166 | 2011-03-09 20:09:26 -0500 | [diff] [blame] | 808 | |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 809 | /* the test is responsible for initializing and enabling */ |
| 810 | pr_info("Testing tracer %s: ", type->name); |
| 811 | ret = type->selftest(type, tr); |
| 812 | /* the test is responsible for resetting too */ |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 813 | tr->current_trace = saved_tracer; |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 814 | if (ret) { |
| 815 | printk(KERN_CONT "FAILED!\n"); |
Steven Rostedt | 0be61eb | 2012-06-18 09:28:16 -0400 | [diff] [blame] | 816 | /* Add the warning after printing 'FAILED' */ |
| 817 | WARN_ON(1); |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 818 | goto out; |
| 819 | } |
Steven Rostedt | 1d4db00 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 820 | /* Only reset on passing, to avoid touching corrupted buffers */ |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 821 | tracing_reset_online_cpus(&tr->trace_buffer); |
Ingo Molnar | 86fa2f6 | 2008-11-19 10:00:15 +0100 | [diff] [blame] | 822 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 823 | #ifdef CONFIG_TRACER_MAX_TRACE |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 824 | if (type->use_max_tr) { |
Steven Rostedt (Red Hat) | 45ad21c | 2013-03-05 18:25:02 -0500 | [diff] [blame] | 825 | tr->allocated_snapshot = false; |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 826 | |
| 827 | /* Shrink the max buffer again */ |
| 828 | if (ring_buffer_expanded) |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 829 | ring_buffer_resize(tr->max_buffer.buffer, 1, |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 830 | RING_BUFFER_ALL_CPUS); |
| 831 | } |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 832 | #endif |
Steven Rostedt | 4a0b166 | 2011-03-09 20:09:26 -0500 | [diff] [blame] | 833 | |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 834 | printk(KERN_CONT "PASSED\n"); |
| 835 | } |
| 836 | #endif |
| 837 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 838 | type->next = trace_types; |
| 839 | trace_types = type; |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 840 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 841 | out: |
Frederic Weisbecker | 8e1b82e | 2008-12-06 03:41:33 +0100 | [diff] [blame] | 842 | tracing_selftest_running = false; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 843 | mutex_unlock(&trace_types_lock); |
| 844 | |
Steven Rostedt | dac7494 | 2009-02-05 01:13:38 -0500 | [diff] [blame] | 845 | if (ret || !default_bootup_tracer) |
| 846 | goto out_unlock; |
Steven Rostedt | b2821ae | 2009-02-02 21:38:32 -0500 | [diff] [blame] | 847 | |
Li Zefan | ee6c2c1 | 2009-09-18 14:06:47 +0800 | [diff] [blame] | 848 | if (strncmp(default_bootup_tracer, type->name, MAX_TRACER_SIZE)) |
Steven Rostedt | dac7494 | 2009-02-05 01:13:38 -0500 | [diff] [blame] | 849 | goto out_unlock; |
| 850 | |
| 851 | printk(KERN_INFO "Starting tracer '%s'\n", type->name); |
| 852 | /* Do we want this tracer to start on bootup? */ |
| 853 | tracing_set_tracer(type->name); |
| 854 | default_bootup_tracer = NULL; |
| 855 | /* disable other selftests, since this will break it. */ |
| 856 | tracing_selftest_disabled = 1; |
| 857 | #ifdef CONFIG_FTRACE_STARTUP_TEST |
| 858 | printk(KERN_INFO "Disabling FTRACE selftests due to running tracer '%s'\n", |
| 859 | type->name); |
| 860 | #endif |
| 861 | |
| 862 | out_unlock: |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 863 | return ret; |
| 864 | } |
| 865 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 866 | void tracing_reset(struct trace_buffer *buf, int cpu) |
Steven Rostedt | f633903 | 2009-09-04 12:35:16 -0400 | [diff] [blame] | 867 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 868 | struct ring_buffer *buffer = buf->buffer; |
Steven Rostedt | f633903 | 2009-09-04 12:35:16 -0400 | [diff] [blame] | 869 | |
Hiraku Toyooka | a541641 | 2012-12-19 16:02:34 +0900 | [diff] [blame] | 870 | if (!buffer) |
| 871 | return; |
| 872 | |
Steven Rostedt | f633903 | 2009-09-04 12:35:16 -0400 | [diff] [blame] | 873 | ring_buffer_record_disable(buffer); |
| 874 | |
| 875 | /* Make sure all commits have finished */ |
| 876 | synchronize_sched(); |
Steven Rostedt | 6817968 | 2012-05-08 20:57:53 -0400 | [diff] [blame] | 877 | ring_buffer_reset_cpu(buffer, cpu); |
Steven Rostedt | f633903 | 2009-09-04 12:35:16 -0400 | [diff] [blame] | 878 | |
| 879 | ring_buffer_record_enable(buffer); |
| 880 | } |
| 881 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 882 | void tracing_reset_online_cpus(struct trace_buffer *buf) |
Pekka J Enberg | 213cc06 | 2008-12-19 12:08:39 +0200 | [diff] [blame] | 883 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 884 | struct ring_buffer *buffer = buf->buffer; |
Pekka J Enberg | 213cc06 | 2008-12-19 12:08:39 +0200 | [diff] [blame] | 885 | int cpu; |
| 886 | |
Hiraku Toyooka | a541641 | 2012-12-19 16:02:34 +0900 | [diff] [blame] | 887 | if (!buffer) |
| 888 | return; |
| 889 | |
Steven Rostedt | 621968c | 2009-09-04 12:02:35 -0400 | [diff] [blame] | 890 | ring_buffer_record_disable(buffer); |
| 891 | |
| 892 | /* Make sure all commits have finished */ |
| 893 | synchronize_sched(); |
| 894 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 895 | buf->time_start = ftrace_now(buf->cpu); |
Pekka J Enberg | 213cc06 | 2008-12-19 12:08:39 +0200 | [diff] [blame] | 896 | |
| 897 | for_each_online_cpu(cpu) |
Steven Rostedt | 6817968 | 2012-05-08 20:57:53 -0400 | [diff] [blame] | 898 | ring_buffer_reset_cpu(buffer, cpu); |
Steven Rostedt | 621968c | 2009-09-04 12:02:35 -0400 | [diff] [blame] | 899 | |
| 900 | ring_buffer_record_enable(buffer); |
Pekka J Enberg | 213cc06 | 2008-12-19 12:08:39 +0200 | [diff] [blame] | 901 | } |
| 902 | |
Steven Rostedt | 9456f0f | 2009-05-06 21:54:09 -0400 | [diff] [blame] | 903 | void tracing_reset_current(int cpu) |
| 904 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 905 | tracing_reset(&global_trace.trace_buffer, cpu); |
Steven Rostedt | 9456f0f | 2009-05-06 21:54:09 -0400 | [diff] [blame] | 906 | } |
| 907 | |
Steven Rostedt (Red Hat) | 873c642 | 2013-03-04 23:26:06 -0500 | [diff] [blame] | 908 | void tracing_reset_all_online_cpus(void) |
Steven Rostedt | 9456f0f | 2009-05-06 21:54:09 -0400 | [diff] [blame] | 909 | { |
Steven Rostedt (Red Hat) | 873c642 | 2013-03-04 23:26:06 -0500 | [diff] [blame] | 910 | struct trace_array *tr; |
| 911 | |
| 912 | mutex_lock(&trace_types_lock); |
| 913 | list_for_each_entry(tr, &ftrace_trace_arrays, list) { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 914 | tracing_reset_online_cpus(&tr->trace_buffer); |
| 915 | #ifdef CONFIG_TRACER_MAX_TRACE |
| 916 | tracing_reset_online_cpus(&tr->max_buffer); |
| 917 | #endif |
Steven Rostedt (Red Hat) | 873c642 | 2013-03-04 23:26:06 -0500 | [diff] [blame] | 918 | } |
| 919 | mutex_unlock(&trace_types_lock); |
Steven Rostedt | 9456f0f | 2009-05-06 21:54:09 -0400 | [diff] [blame] | 920 | } |
| 921 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 922 | #define SAVED_CMDLINES 128 |
Thomas Gleixner | 2c7eea4 | 2009-03-18 09:03:19 +0100 | [diff] [blame] | 923 | #define NO_CMDLINE_MAP UINT_MAX |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 924 | static unsigned map_pid_to_cmdline[PID_MAX_DEFAULT+1]; |
| 925 | static unsigned map_cmdline_to_pid[SAVED_CMDLINES]; |
| 926 | static char saved_cmdlines[SAVED_CMDLINES][TASK_COMM_LEN]; |
| 927 | static int cmdline_idx; |
Thomas Gleixner | edc35bd | 2009-12-03 12:38:57 +0100 | [diff] [blame] | 928 | static arch_spinlock_t trace_cmdline_lock = __ARCH_SPIN_LOCK_UNLOCKED; |
Steven Rostedt | 25b0b44 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 929 | |
Steven Rostedt | 25b0b44 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 930 | /* temporary disable recording */ |
Hannes Eder | 4fd2735 | 2009-02-10 19:44:12 +0100 | [diff] [blame] | 931 | static atomic_t trace_record_cmdline_disabled __read_mostly; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 932 | |
| 933 | static void trace_init_cmdlines(void) |
| 934 | { |
Thomas Gleixner | 2c7eea4 | 2009-03-18 09:03:19 +0100 | [diff] [blame] | 935 | memset(&map_pid_to_cmdline, NO_CMDLINE_MAP, sizeof(map_pid_to_cmdline)); |
| 936 | 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] | 937 | cmdline_idx = 0; |
| 938 | } |
| 939 | |
Carsten Emde | b5130b1 | 2009-09-13 01:43:07 +0200 | [diff] [blame] | 940 | int is_tracing_stopped(void) |
| 941 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 942 | return global_trace.stop_count; |
Carsten Emde | b5130b1 | 2009-09-13 01:43:07 +0200 | [diff] [blame] | 943 | } |
| 944 | |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 945 | /** |
Steven Rostedt | 69bb54e | 2008-11-21 12:59:38 -0500 | [diff] [blame] | 946 | * ftrace_off_permanent - disable all ftrace code permanently |
| 947 | * |
| 948 | * This should only be called when a serious anomally has |
| 949 | * been detected. This will turn off the function tracing, |
| 950 | * ring buffers, and other tracing utilites. It takes no |
| 951 | * locks and can be called from any context. |
| 952 | */ |
| 953 | void ftrace_off_permanent(void) |
| 954 | { |
| 955 | tracing_disabled = 1; |
| 956 | ftrace_stop(); |
| 957 | tracing_off_permanent(); |
| 958 | } |
| 959 | |
| 960 | /** |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 961 | * tracing_start - quick start of the tracer |
| 962 | * |
| 963 | * If tracing is enabled but was stopped by tracing_stop, |
| 964 | * this will start the tracer back up. |
| 965 | */ |
| 966 | void tracing_start(void) |
| 967 | { |
| 968 | struct ring_buffer *buffer; |
| 969 | unsigned long flags; |
| 970 | |
| 971 | if (tracing_disabled) |
| 972 | return; |
| 973 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 974 | raw_spin_lock_irqsave(&global_trace.start_lock, flags); |
| 975 | if (--global_trace.stop_count) { |
| 976 | if (global_trace.stop_count < 0) { |
Steven Rostedt | b06a830 | 2009-01-22 14:26:15 -0500 | [diff] [blame] | 977 | /* Someone screwed up their debugging */ |
| 978 | WARN_ON_ONCE(1); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 979 | global_trace.stop_count = 0; |
Steven Rostedt | b06a830 | 2009-01-22 14:26:15 -0500 | [diff] [blame] | 980 | } |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 981 | goto out; |
| 982 | } |
| 983 | |
Steven Rostedt | a2f8071 | 2010-03-12 19:56:00 -0500 | [diff] [blame] | 984 | /* Prevent the buffers from switching */ |
| 985 | arch_spin_lock(&ftrace_max_lock); |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 986 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 987 | buffer = global_trace.trace_buffer.buffer; |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 988 | if (buffer) |
| 989 | ring_buffer_record_enable(buffer); |
| 990 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 991 | #ifdef CONFIG_TRACER_MAX_TRACE |
| 992 | buffer = global_trace.max_buffer.buffer; |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 993 | if (buffer) |
| 994 | ring_buffer_record_enable(buffer); |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 995 | #endif |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 996 | |
Steven Rostedt | a2f8071 | 2010-03-12 19:56:00 -0500 | [diff] [blame] | 997 | arch_spin_unlock(&ftrace_max_lock); |
| 998 | |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 999 | ftrace_start(); |
| 1000 | out: |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 1001 | raw_spin_unlock_irqrestore(&global_trace.start_lock, flags); |
| 1002 | } |
| 1003 | |
| 1004 | static void tracing_start_tr(struct trace_array *tr) |
| 1005 | { |
| 1006 | struct ring_buffer *buffer; |
| 1007 | unsigned long flags; |
| 1008 | |
| 1009 | if (tracing_disabled) |
| 1010 | return; |
| 1011 | |
| 1012 | /* If global, we need to also start the max tracer */ |
| 1013 | if (tr->flags & TRACE_ARRAY_FL_GLOBAL) |
| 1014 | return tracing_start(); |
| 1015 | |
| 1016 | raw_spin_lock_irqsave(&tr->start_lock, flags); |
| 1017 | |
| 1018 | if (--tr->stop_count) { |
| 1019 | if (tr->stop_count < 0) { |
| 1020 | /* Someone screwed up their debugging */ |
| 1021 | WARN_ON_ONCE(1); |
| 1022 | tr->stop_count = 0; |
| 1023 | } |
| 1024 | goto out; |
| 1025 | } |
| 1026 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1027 | buffer = tr->trace_buffer.buffer; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 1028 | if (buffer) |
| 1029 | ring_buffer_record_enable(buffer); |
| 1030 | |
| 1031 | out: |
| 1032 | raw_spin_unlock_irqrestore(&tr->start_lock, flags); |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1033 | } |
| 1034 | |
| 1035 | /** |
| 1036 | * tracing_stop - quick stop of the tracer |
| 1037 | * |
| 1038 | * Light weight way to stop tracing. Use in conjunction with |
| 1039 | * tracing_start. |
| 1040 | */ |
| 1041 | void tracing_stop(void) |
| 1042 | { |
| 1043 | struct ring_buffer *buffer; |
| 1044 | unsigned long flags; |
| 1045 | |
| 1046 | ftrace_stop(); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 1047 | raw_spin_lock_irqsave(&global_trace.start_lock, flags); |
| 1048 | if (global_trace.stop_count++) |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1049 | goto out; |
| 1050 | |
Steven Rostedt | a2f8071 | 2010-03-12 19:56:00 -0500 | [diff] [blame] | 1051 | /* Prevent the buffers from switching */ |
| 1052 | arch_spin_lock(&ftrace_max_lock); |
| 1053 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1054 | buffer = global_trace.trace_buffer.buffer; |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1055 | if (buffer) |
| 1056 | ring_buffer_record_disable(buffer); |
| 1057 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1058 | #ifdef CONFIG_TRACER_MAX_TRACE |
| 1059 | buffer = global_trace.max_buffer.buffer; |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1060 | if (buffer) |
| 1061 | ring_buffer_record_disable(buffer); |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1062 | #endif |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1063 | |
Steven Rostedt | a2f8071 | 2010-03-12 19:56:00 -0500 | [diff] [blame] | 1064 | arch_spin_unlock(&ftrace_max_lock); |
| 1065 | |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1066 | out: |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 1067 | raw_spin_unlock_irqrestore(&global_trace.start_lock, flags); |
| 1068 | } |
| 1069 | |
| 1070 | static void tracing_stop_tr(struct trace_array *tr) |
| 1071 | { |
| 1072 | struct ring_buffer *buffer; |
| 1073 | unsigned long flags; |
| 1074 | |
| 1075 | /* If global, we need to also stop the max tracer */ |
| 1076 | if (tr->flags & TRACE_ARRAY_FL_GLOBAL) |
| 1077 | return tracing_stop(); |
| 1078 | |
| 1079 | raw_spin_lock_irqsave(&tr->start_lock, flags); |
| 1080 | if (tr->stop_count++) |
| 1081 | goto out; |
| 1082 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1083 | buffer = tr->trace_buffer.buffer; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 1084 | if (buffer) |
| 1085 | ring_buffer_record_disable(buffer); |
| 1086 | |
| 1087 | out: |
| 1088 | raw_spin_unlock_irqrestore(&tr->start_lock, flags); |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1089 | } |
| 1090 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1091 | void trace_stop_cmdline_recording(void); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1092 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1093 | static void trace_save_cmdline(struct task_struct *tsk) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1094 | { |
Carsten Emde | a635cf0 | 2009-03-18 09:00:41 +0100 | [diff] [blame] | 1095 | unsigned pid, idx; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1096 | |
| 1097 | if (!tsk->pid || unlikely(tsk->pid > PID_MAX_DEFAULT)) |
| 1098 | return; |
| 1099 | |
| 1100 | /* |
| 1101 | * It's not the end of the world if we don't get |
| 1102 | * the lock, but we also don't want to spin |
| 1103 | * nor do we want to disable interrupts, |
| 1104 | * so if we miss here, then better luck next time. |
| 1105 | */ |
Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 1106 | if (!arch_spin_trylock(&trace_cmdline_lock)) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1107 | return; |
| 1108 | |
| 1109 | idx = map_pid_to_cmdline[tsk->pid]; |
Thomas Gleixner | 2c7eea4 | 2009-03-18 09:03:19 +0100 | [diff] [blame] | 1110 | if (idx == NO_CMDLINE_MAP) { |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1111 | idx = (cmdline_idx + 1) % SAVED_CMDLINES; |
| 1112 | |
Carsten Emde | a635cf0 | 2009-03-18 09:00:41 +0100 | [diff] [blame] | 1113 | /* |
| 1114 | * Check whether the cmdline buffer at idx has a pid |
| 1115 | * mapped. We are going to overwrite that entry so we |
| 1116 | * need to clear the map_pid_to_cmdline. Otherwise we |
| 1117 | * would read the new comm for the old pid. |
| 1118 | */ |
| 1119 | pid = map_cmdline_to_pid[idx]; |
| 1120 | if (pid != NO_CMDLINE_MAP) |
| 1121 | map_pid_to_cmdline[pid] = NO_CMDLINE_MAP; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1122 | |
Carsten Emde | a635cf0 | 2009-03-18 09:00:41 +0100 | [diff] [blame] | 1123 | map_cmdline_to_pid[idx] = tsk->pid; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1124 | map_pid_to_cmdline[tsk->pid] = idx; |
| 1125 | |
| 1126 | cmdline_idx = idx; |
| 1127 | } |
| 1128 | |
| 1129 | memcpy(&saved_cmdlines[idx], tsk->comm, TASK_COMM_LEN); |
| 1130 | |
Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 1131 | arch_spin_unlock(&trace_cmdline_lock); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1132 | } |
| 1133 | |
Steven Rostedt | 4ca53085 | 2009-03-16 19:20:15 -0400 | [diff] [blame] | 1134 | void trace_find_cmdline(int pid, char comm[]) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1135 | { |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1136 | unsigned map; |
| 1137 | |
Steven Rostedt | 4ca53085 | 2009-03-16 19:20:15 -0400 | [diff] [blame] | 1138 | if (!pid) { |
| 1139 | strcpy(comm, "<idle>"); |
| 1140 | return; |
| 1141 | } |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1142 | |
Steven Rostedt | 74bf407 | 2010-01-25 15:11:53 -0500 | [diff] [blame] | 1143 | if (WARN_ON_ONCE(pid < 0)) { |
| 1144 | strcpy(comm, "<XXX>"); |
| 1145 | return; |
| 1146 | } |
| 1147 | |
Steven Rostedt | 4ca53085 | 2009-03-16 19:20:15 -0400 | [diff] [blame] | 1148 | if (pid > PID_MAX_DEFAULT) { |
| 1149 | strcpy(comm, "<...>"); |
| 1150 | return; |
| 1151 | } |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1152 | |
Heiko Carstens | 5b6045a | 2009-05-26 17:28:02 +0200 | [diff] [blame] | 1153 | preempt_disable(); |
Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 1154 | arch_spin_lock(&trace_cmdline_lock); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1155 | map = map_pid_to_cmdline[pid]; |
Thomas Gleixner | 50d8875 | 2009-03-18 08:58:44 +0100 | [diff] [blame] | 1156 | if (map != NO_CMDLINE_MAP) |
| 1157 | strcpy(comm, saved_cmdlines[map]); |
| 1158 | else |
| 1159 | strcpy(comm, "<...>"); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1160 | |
Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 1161 | arch_spin_unlock(&trace_cmdline_lock); |
Heiko Carstens | 5b6045a | 2009-05-26 17:28:02 +0200 | [diff] [blame] | 1162 | preempt_enable(); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1163 | } |
| 1164 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1165 | void tracing_record_cmdline(struct task_struct *tsk) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1166 | { |
Steven Rostedt | 0fb9656 | 2012-05-11 14:25:30 -0400 | [diff] [blame] | 1167 | if (atomic_read(&trace_record_cmdline_disabled) || !tracing_is_on()) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1168 | return; |
| 1169 | |
Steven Rostedt | 7ffbd48 | 2012-10-11 12:14:25 -0400 | [diff] [blame] | 1170 | if (!__this_cpu_read(trace_cmdline_save)) |
| 1171 | return; |
| 1172 | |
| 1173 | __this_cpu_write(trace_cmdline_save, false); |
| 1174 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1175 | trace_save_cmdline(tsk); |
| 1176 | } |
| 1177 | |
Pekka Paalanen | 45dcd8b | 2008-09-16 21:56:41 +0300 | [diff] [blame] | 1178 | void |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 1179 | tracing_generic_entry_update(struct trace_entry *entry, unsigned long flags, |
| 1180 | int pc) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1181 | { |
| 1182 | struct task_struct *tsk = current; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1183 | |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1184 | entry->preempt_count = pc & 0xff; |
| 1185 | entry->pid = (tsk) ? tsk->pid : 0; |
| 1186 | entry->flags = |
Steven Rostedt | 9244489 | 2008-10-24 09:42:59 -0400 | [diff] [blame] | 1187 | #ifdef CONFIG_TRACE_IRQFLAGS_SUPPORT |
Steven Rostedt | 2e2ca15 | 2008-08-01 12:26:40 -0400 | [diff] [blame] | 1188 | (irqs_disabled_flags(flags) ? TRACE_FLAG_IRQS_OFF : 0) | |
Steven Rostedt | 9244489 | 2008-10-24 09:42:59 -0400 | [diff] [blame] | 1189 | #else |
| 1190 | TRACE_FLAG_IRQS_NOSUPPORT | |
| 1191 | #endif |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1192 | ((pc & HARDIRQ_MASK) ? TRACE_FLAG_HARDIRQ : 0) | |
| 1193 | ((pc & SOFTIRQ_MASK) ? TRACE_FLAG_SOFTIRQ : 0) | |
| 1194 | (need_resched() ? TRACE_FLAG_NEED_RESCHED : 0); |
| 1195 | } |
Frederic Weisbecker | f413cdb | 2009-08-07 01:25:54 +0200 | [diff] [blame] | 1196 | EXPORT_SYMBOL_GPL(tracing_generic_entry_update); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1197 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1198 | struct ring_buffer_event * |
| 1199 | trace_buffer_lock_reserve(struct ring_buffer *buffer, |
| 1200 | int type, |
| 1201 | unsigned long len, |
| 1202 | unsigned long flags, int pc) |
Arnaldo Carvalho de Melo | 51a763d | 2009-02-05 16:14:13 -0200 | [diff] [blame] | 1203 | { |
| 1204 | struct ring_buffer_event *event; |
| 1205 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1206 | event = ring_buffer_lock_reserve(buffer, len); |
Arnaldo Carvalho de Melo | 51a763d | 2009-02-05 16:14:13 -0200 | [diff] [blame] | 1207 | if (event != NULL) { |
| 1208 | struct trace_entry *ent = ring_buffer_event_data(event); |
| 1209 | |
| 1210 | tracing_generic_entry_update(ent, flags, pc); |
| 1211 | ent->type = type; |
| 1212 | } |
| 1213 | |
| 1214 | return event; |
| 1215 | } |
Arnaldo Carvalho de Melo | 51a763d | 2009-02-05 16:14:13 -0200 | [diff] [blame] | 1216 | |
Steven Rostedt | 7ffbd48 | 2012-10-11 12:14:25 -0400 | [diff] [blame] | 1217 | void |
| 1218 | __buffer_unlock_commit(struct ring_buffer *buffer, struct ring_buffer_event *event) |
| 1219 | { |
| 1220 | __this_cpu_write(trace_cmdline_save, true); |
| 1221 | ring_buffer_unlock_commit(buffer, event); |
| 1222 | } |
| 1223 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1224 | static inline void |
| 1225 | __trace_buffer_unlock_commit(struct ring_buffer *buffer, |
| 1226 | struct ring_buffer_event *event, |
Steven Rostedt | 0d5c6e1 | 2012-11-01 20:54:21 -0400 | [diff] [blame] | 1227 | unsigned long flags, int pc) |
Arnaldo Carvalho de Melo | 51a763d | 2009-02-05 16:14:13 -0200 | [diff] [blame] | 1228 | { |
Steven Rostedt | 7ffbd48 | 2012-10-11 12:14:25 -0400 | [diff] [blame] | 1229 | __buffer_unlock_commit(buffer, event); |
Arnaldo Carvalho de Melo | 51a763d | 2009-02-05 16:14:13 -0200 | [diff] [blame] | 1230 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1231 | ftrace_trace_stack(buffer, flags, 6, pc); |
| 1232 | ftrace_trace_userstack(buffer, flags, pc); |
Frederic Weisbecker | 07edf71 | 2009-03-22 23:10:46 +0100 | [diff] [blame] | 1233 | } |
| 1234 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1235 | void trace_buffer_unlock_commit(struct ring_buffer *buffer, |
| 1236 | struct ring_buffer_event *event, |
| 1237 | unsigned long flags, int pc) |
Frederic Weisbecker | 07edf71 | 2009-03-22 23:10:46 +0100 | [diff] [blame] | 1238 | { |
Steven Rostedt | 0d5c6e1 | 2012-11-01 20:54:21 -0400 | [diff] [blame] | 1239 | __trace_buffer_unlock_commit(buffer, event, flags, pc); |
Arnaldo Carvalho de Melo | 51a763d | 2009-02-05 16:14:13 -0200 | [diff] [blame] | 1240 | } |
Steven Rostedt | 0d5c6e1 | 2012-11-01 20:54:21 -0400 | [diff] [blame] | 1241 | EXPORT_SYMBOL_GPL(trace_buffer_unlock_commit); |
Arnaldo Carvalho de Melo | 51a763d | 2009-02-05 16:14:13 -0200 | [diff] [blame] | 1242 | |
Steven Rostedt | ef5580d | 2009-02-27 19:38:04 -0500 | [diff] [blame] | 1243 | struct ring_buffer_event * |
Steven Rostedt | ccb469a | 2012-08-02 10:32:10 -0400 | [diff] [blame] | 1244 | trace_event_buffer_lock_reserve(struct ring_buffer **current_rb, |
| 1245 | struct ftrace_event_file *ftrace_file, |
| 1246 | int type, unsigned long len, |
| 1247 | unsigned long flags, int pc) |
| 1248 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1249 | *current_rb = ftrace_file->tr->trace_buffer.buffer; |
Steven Rostedt | ccb469a | 2012-08-02 10:32:10 -0400 | [diff] [blame] | 1250 | return trace_buffer_lock_reserve(*current_rb, |
| 1251 | type, len, flags, pc); |
| 1252 | } |
| 1253 | EXPORT_SYMBOL_GPL(trace_event_buffer_lock_reserve); |
| 1254 | |
| 1255 | struct ring_buffer_event * |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1256 | trace_current_buffer_lock_reserve(struct ring_buffer **current_rb, |
| 1257 | int type, unsigned long len, |
Steven Rostedt | ef5580d | 2009-02-27 19:38:04 -0500 | [diff] [blame] | 1258 | unsigned long flags, int pc) |
| 1259 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1260 | *current_rb = global_trace.trace_buffer.buffer; |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1261 | return trace_buffer_lock_reserve(*current_rb, |
Steven Rostedt | ef5580d | 2009-02-27 19:38:04 -0500 | [diff] [blame] | 1262 | type, len, flags, pc); |
| 1263 | } |
Steven Rostedt | 94487d6 | 2009-05-05 19:22:53 -0400 | [diff] [blame] | 1264 | EXPORT_SYMBOL_GPL(trace_current_buffer_lock_reserve); |
Steven Rostedt | ef5580d | 2009-02-27 19:38:04 -0500 | [diff] [blame] | 1265 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1266 | void trace_current_buffer_unlock_commit(struct ring_buffer *buffer, |
| 1267 | struct ring_buffer_event *event, |
Steven Rostedt | ef5580d | 2009-02-27 19:38:04 -0500 | [diff] [blame] | 1268 | unsigned long flags, int pc) |
| 1269 | { |
Steven Rostedt | 0d5c6e1 | 2012-11-01 20:54:21 -0400 | [diff] [blame] | 1270 | __trace_buffer_unlock_commit(buffer, event, flags, pc); |
Frederic Weisbecker | 07edf71 | 2009-03-22 23:10:46 +0100 | [diff] [blame] | 1271 | } |
Steven Rostedt | 94487d6 | 2009-05-05 19:22:53 -0400 | [diff] [blame] | 1272 | EXPORT_SYMBOL_GPL(trace_current_buffer_unlock_commit); |
Frederic Weisbecker | 07edf71 | 2009-03-22 23:10:46 +0100 | [diff] [blame] | 1273 | |
Steven Rostedt | 0d5c6e1 | 2012-11-01 20:54:21 -0400 | [diff] [blame] | 1274 | void trace_buffer_unlock_commit_regs(struct ring_buffer *buffer, |
| 1275 | struct ring_buffer_event *event, |
| 1276 | unsigned long flags, int pc, |
| 1277 | struct pt_regs *regs) |
Masami Hiramatsu | 1fd8df2 | 2011-06-08 16:09:34 +0900 | [diff] [blame] | 1278 | { |
Steven Rostedt | 7ffbd48 | 2012-10-11 12:14:25 -0400 | [diff] [blame] | 1279 | __buffer_unlock_commit(buffer, event); |
Masami Hiramatsu | 1fd8df2 | 2011-06-08 16:09:34 +0900 | [diff] [blame] | 1280 | |
| 1281 | ftrace_trace_stack_regs(buffer, flags, 0, pc, regs); |
| 1282 | ftrace_trace_userstack(buffer, flags, pc); |
| 1283 | } |
Steven Rostedt | 0d5c6e1 | 2012-11-01 20:54:21 -0400 | [diff] [blame] | 1284 | EXPORT_SYMBOL_GPL(trace_buffer_unlock_commit_regs); |
Masami Hiramatsu | 1fd8df2 | 2011-06-08 16:09:34 +0900 | [diff] [blame] | 1285 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1286 | void trace_current_buffer_discard_commit(struct ring_buffer *buffer, |
| 1287 | struct ring_buffer_event *event) |
Steven Rostedt | 77d9f46 | 2009-04-02 01:16:59 -0400 | [diff] [blame] | 1288 | { |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1289 | ring_buffer_discard_commit(buffer, event); |
Steven Rostedt | ef5580d | 2009-02-27 19:38:04 -0500 | [diff] [blame] | 1290 | } |
Steven Rostedt | 12acd47 | 2009-04-17 16:01:56 -0400 | [diff] [blame] | 1291 | EXPORT_SYMBOL_GPL(trace_current_buffer_discard_commit); |
Steven Rostedt | ef5580d | 2009-02-27 19:38:04 -0500 | [diff] [blame] | 1292 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1293 | void |
Arnaldo Carvalho de Melo | 7be4215 | 2009-02-05 01:13:37 -0500 | [diff] [blame] | 1294 | trace_function(struct trace_array *tr, |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 1295 | unsigned long ip, unsigned long parent_ip, unsigned long flags, |
| 1296 | int pc) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1297 | { |
Tom Zanussi | e1112b4 | 2009-03-31 00:48:49 -0500 | [diff] [blame] | 1298 | struct ftrace_event_call *call = &event_function; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1299 | struct ring_buffer *buffer = tr->trace_buffer.buffer; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1300 | struct ring_buffer_event *event; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1301 | struct ftrace_entry *entry; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1302 | |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 1303 | /* If we are reading the ring buffer, don't trace */ |
Rusty Russell | dd17c8f | 2009-10-29 22:34:15 +0900 | [diff] [blame] | 1304 | if (unlikely(__this_cpu_read(ftrace_cpu_disabled))) |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 1305 | return; |
| 1306 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1307 | event = trace_buffer_lock_reserve(buffer, TRACE_FN, sizeof(*entry), |
Arnaldo Carvalho de Melo | 51a763d | 2009-02-05 16:14:13 -0200 | [diff] [blame] | 1308 | flags, pc); |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1309 | if (!event) |
| 1310 | return; |
| 1311 | entry = ring_buffer_event_data(event); |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1312 | entry->ip = ip; |
| 1313 | entry->parent_ip = parent_ip; |
Tom Zanussi | e1112b4 | 2009-03-31 00:48:49 -0500 | [diff] [blame] | 1314 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1315 | if (!filter_check_discard(call, entry, buffer, event)) |
Steven Rostedt | 7ffbd48 | 2012-10-11 12:14:25 -0400 | [diff] [blame] | 1316 | __buffer_unlock_commit(buffer, event); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1317 | } |
| 1318 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1319 | void |
Ingo Molnar | 2e0f576 | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 1320 | ftrace(struct trace_array *tr, struct trace_array_cpu *data, |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 1321 | unsigned long ip, unsigned long parent_ip, unsigned long flags, |
| 1322 | int pc) |
Ingo Molnar | 2e0f576 | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 1323 | { |
| 1324 | if (likely(!atomic_read(&data->disabled))) |
Arnaldo Carvalho de Melo | 7be4215 | 2009-02-05 01:13:37 -0500 | [diff] [blame] | 1325 | trace_function(tr, ip, parent_ip, flags, pc); |
Ingo Molnar | 2e0f576 | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 1326 | } |
| 1327 | |
Frederic Weisbecker | c0a0d0d | 2009-07-29 17:51:13 +0200 | [diff] [blame] | 1328 | #ifdef CONFIG_STACKTRACE |
Steven Rostedt | 4a9bd3f | 2011-07-14 16:36:53 -0400 | [diff] [blame] | 1329 | |
| 1330 | #define FTRACE_STACK_MAX_ENTRIES (PAGE_SIZE / sizeof(unsigned long)) |
| 1331 | struct ftrace_stack { |
| 1332 | unsigned long calls[FTRACE_STACK_MAX_ENTRIES]; |
| 1333 | }; |
| 1334 | |
| 1335 | static DEFINE_PER_CPU(struct ftrace_stack, ftrace_stack); |
| 1336 | static DEFINE_PER_CPU(int, ftrace_stack_reserve); |
| 1337 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1338 | static void __ftrace_trace_stack(struct ring_buffer *buffer, |
Steven Rostedt | 5361499 | 2009-01-15 19:12:40 -0500 | [diff] [blame] | 1339 | unsigned long flags, |
Masami Hiramatsu | 1fd8df2 | 2011-06-08 16:09:34 +0900 | [diff] [blame] | 1340 | int skip, int pc, struct pt_regs *regs) |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1341 | { |
Tom Zanussi | e1112b4 | 2009-03-31 00:48:49 -0500 | [diff] [blame] | 1342 | struct ftrace_event_call *call = &event_kernel_stack; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1343 | struct ring_buffer_event *event; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1344 | struct stack_entry *entry; |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1345 | struct stack_trace trace; |
Steven Rostedt | 4a9bd3f | 2011-07-14 16:36:53 -0400 | [diff] [blame] | 1346 | int use_stack; |
| 1347 | int size = FTRACE_STACK_ENTRIES; |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1348 | |
| 1349 | trace.nr_entries = 0; |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1350 | trace.skip = skip; |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1351 | |
Steven Rostedt | 4a9bd3f | 2011-07-14 16:36:53 -0400 | [diff] [blame] | 1352 | /* |
| 1353 | * Since events can happen in NMIs there's no safe way to |
| 1354 | * use the per cpu ftrace_stacks. We reserve it and if an interrupt |
| 1355 | * or NMI comes in, it will just have to use the default |
| 1356 | * FTRACE_STACK_SIZE. |
| 1357 | */ |
| 1358 | preempt_disable_notrace(); |
| 1359 | |
Shan Wei | 8214652 | 2012-11-19 13:21:01 +0800 | [diff] [blame] | 1360 | use_stack = __this_cpu_inc_return(ftrace_stack_reserve); |
Steven Rostedt | 4a9bd3f | 2011-07-14 16:36:53 -0400 | [diff] [blame] | 1361 | /* |
| 1362 | * We don't need any atomic variables, just a barrier. |
| 1363 | * If an interrupt comes in, we don't care, because it would |
| 1364 | * have exited and put the counter back to what we want. |
| 1365 | * We just need a barrier to keep gcc from moving things |
| 1366 | * around. |
| 1367 | */ |
| 1368 | barrier(); |
| 1369 | if (use_stack == 1) { |
| 1370 | trace.entries = &__get_cpu_var(ftrace_stack).calls[0]; |
| 1371 | trace.max_entries = FTRACE_STACK_MAX_ENTRIES; |
| 1372 | |
| 1373 | if (regs) |
| 1374 | save_stack_trace_regs(regs, &trace); |
| 1375 | else |
| 1376 | save_stack_trace(&trace); |
| 1377 | |
| 1378 | if (trace.nr_entries > size) |
| 1379 | size = trace.nr_entries; |
| 1380 | } else |
| 1381 | /* From now on, use_stack is a boolean */ |
| 1382 | use_stack = 0; |
| 1383 | |
| 1384 | size *= sizeof(unsigned long); |
| 1385 | |
| 1386 | event = trace_buffer_lock_reserve(buffer, TRACE_STACK, |
| 1387 | sizeof(*entry) + size, flags, pc); |
| 1388 | if (!event) |
| 1389 | goto out; |
| 1390 | entry = ring_buffer_event_data(event); |
| 1391 | |
| 1392 | memset(&entry->caller, 0, size); |
| 1393 | |
| 1394 | if (use_stack) |
| 1395 | memcpy(&entry->caller, trace.entries, |
| 1396 | trace.nr_entries * sizeof(unsigned long)); |
| 1397 | else { |
| 1398 | trace.max_entries = FTRACE_STACK_ENTRIES; |
| 1399 | trace.entries = entry->caller; |
| 1400 | if (regs) |
| 1401 | save_stack_trace_regs(regs, &trace); |
| 1402 | else |
| 1403 | save_stack_trace(&trace); |
| 1404 | } |
| 1405 | |
| 1406 | entry->size = trace.nr_entries; |
| 1407 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1408 | if (!filter_check_discard(call, entry, buffer, event)) |
Steven Rostedt | 7ffbd48 | 2012-10-11 12:14:25 -0400 | [diff] [blame] | 1409 | __buffer_unlock_commit(buffer, event); |
Steven Rostedt | 4a9bd3f | 2011-07-14 16:36:53 -0400 | [diff] [blame] | 1410 | |
| 1411 | out: |
| 1412 | /* Again, don't let gcc optimize things here */ |
| 1413 | barrier(); |
Shan Wei | 8214652 | 2012-11-19 13:21:01 +0800 | [diff] [blame] | 1414 | __this_cpu_dec(ftrace_stack_reserve); |
Steven Rostedt | 4a9bd3f | 2011-07-14 16:36:53 -0400 | [diff] [blame] | 1415 | preempt_enable_notrace(); |
| 1416 | |
Ingo Molnar | f0a920d | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 1417 | } |
| 1418 | |
Masami Hiramatsu | 1fd8df2 | 2011-06-08 16:09:34 +0900 | [diff] [blame] | 1419 | void ftrace_trace_stack_regs(struct ring_buffer *buffer, unsigned long flags, |
| 1420 | int skip, int pc, struct pt_regs *regs) |
| 1421 | { |
| 1422 | if (!(trace_flags & TRACE_ITER_STACKTRACE)) |
| 1423 | return; |
| 1424 | |
| 1425 | __ftrace_trace_stack(buffer, flags, skip, pc, regs); |
| 1426 | } |
| 1427 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1428 | void ftrace_trace_stack(struct ring_buffer *buffer, unsigned long flags, |
| 1429 | int skip, int pc) |
Steven Rostedt | 5361499 | 2009-01-15 19:12:40 -0500 | [diff] [blame] | 1430 | { |
| 1431 | if (!(trace_flags & TRACE_ITER_STACKTRACE)) |
| 1432 | return; |
| 1433 | |
Masami Hiramatsu | 1fd8df2 | 2011-06-08 16:09:34 +0900 | [diff] [blame] | 1434 | __ftrace_trace_stack(buffer, flags, skip, pc, NULL); |
Steven Rostedt | 5361499 | 2009-01-15 19:12:40 -0500 | [diff] [blame] | 1435 | } |
| 1436 | |
Frederic Weisbecker | c0a0d0d | 2009-07-29 17:51:13 +0200 | [diff] [blame] | 1437 | void __trace_stack(struct trace_array *tr, unsigned long flags, int skip, |
| 1438 | int pc) |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 1439 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1440 | __ftrace_trace_stack(tr->trace_buffer.buffer, flags, skip, pc, NULL); |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 1441 | } |
| 1442 | |
Steven Rostedt | 0388938 | 2009-12-11 09:48:22 -0500 | [diff] [blame] | 1443 | /** |
| 1444 | * trace_dump_stack - record a stack back trace in the trace buffer |
| 1445 | */ |
| 1446 | void trace_dump_stack(void) |
| 1447 | { |
| 1448 | unsigned long flags; |
| 1449 | |
| 1450 | if (tracing_disabled || tracing_selftest_running) |
Steven Rostedt | e36c545 | 2009-12-14 15:58:33 -0500 | [diff] [blame] | 1451 | return; |
Steven Rostedt | 0388938 | 2009-12-11 09:48:22 -0500 | [diff] [blame] | 1452 | |
| 1453 | local_save_flags(flags); |
| 1454 | |
| 1455 | /* skipping 3 traces, seems to get us at the caller of this function */ |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1456 | __ftrace_trace_stack(global_trace.trace_buffer.buffer, flags, 3, |
| 1457 | preempt_count(), NULL); |
Steven Rostedt | 0388938 | 2009-12-11 09:48:22 -0500 | [diff] [blame] | 1458 | } |
| 1459 | |
Steven Rostedt | 91e86e5 | 2010-11-10 12:56:12 +0100 | [diff] [blame] | 1460 | static DEFINE_PER_CPU(int, user_stack_count); |
| 1461 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1462 | void |
| 1463 | 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] | 1464 | { |
Tom Zanussi | e1112b4 | 2009-03-31 00:48:49 -0500 | [diff] [blame] | 1465 | struct ftrace_event_call *call = &event_user_stack; |
Török Edwin | 8d7c6a9 | 2008-11-23 12:39:06 +0200 | [diff] [blame] | 1466 | struct ring_buffer_event *event; |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 1467 | struct userstack_entry *entry; |
| 1468 | struct stack_trace trace; |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 1469 | |
| 1470 | if (!(trace_flags & TRACE_ITER_USERSTACKTRACE)) |
| 1471 | return; |
| 1472 | |
Steven Rostedt | b634587 | 2010-03-12 20:03:30 -0500 | [diff] [blame] | 1473 | /* |
| 1474 | * NMIs can not handle page faults, even with fix ups. |
| 1475 | * The save user stack can (and often does) fault. |
| 1476 | */ |
| 1477 | if (unlikely(in_nmi())) |
| 1478 | return; |
| 1479 | |
Steven Rostedt | 91e86e5 | 2010-11-10 12:56:12 +0100 | [diff] [blame] | 1480 | /* |
| 1481 | * prevent recursion, since the user stack tracing may |
| 1482 | * trigger other kernel events. |
| 1483 | */ |
| 1484 | preempt_disable(); |
| 1485 | if (__this_cpu_read(user_stack_count)) |
| 1486 | goto out; |
| 1487 | |
| 1488 | __this_cpu_inc(user_stack_count); |
| 1489 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1490 | event = trace_buffer_lock_reserve(buffer, TRACE_USER_STACK, |
Arnaldo Carvalho de Melo | 51a763d | 2009-02-05 16:14:13 -0200 | [diff] [blame] | 1491 | sizeof(*entry), flags, pc); |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 1492 | if (!event) |
Li Zefan | 1dbd195 | 2010-12-09 15:47:56 +0800 | [diff] [blame] | 1493 | goto out_drop_count; |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 1494 | entry = ring_buffer_event_data(event); |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 1495 | |
Steven Rostedt | 48659d3 | 2009-09-11 11:36:23 -0400 | [diff] [blame] | 1496 | entry->tgid = current->tgid; |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 1497 | memset(&entry->caller, 0, sizeof(entry->caller)); |
| 1498 | |
| 1499 | trace.nr_entries = 0; |
| 1500 | trace.max_entries = FTRACE_STACK_ENTRIES; |
| 1501 | trace.skip = 0; |
| 1502 | trace.entries = entry->caller; |
| 1503 | |
| 1504 | save_stack_trace_user(&trace); |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1505 | if (!filter_check_discard(call, entry, buffer, event)) |
Steven Rostedt | 7ffbd48 | 2012-10-11 12:14:25 -0400 | [diff] [blame] | 1506 | __buffer_unlock_commit(buffer, event); |
Steven Rostedt | 91e86e5 | 2010-11-10 12:56:12 +0100 | [diff] [blame] | 1507 | |
Li Zefan | 1dbd195 | 2010-12-09 15:47:56 +0800 | [diff] [blame] | 1508 | out_drop_count: |
Steven Rostedt | 91e86e5 | 2010-11-10 12:56:12 +0100 | [diff] [blame] | 1509 | __this_cpu_dec(user_stack_count); |
Steven Rostedt | 91e86e5 | 2010-11-10 12:56:12 +0100 | [diff] [blame] | 1510 | out: |
| 1511 | preempt_enable(); |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 1512 | } |
| 1513 | |
Hannes Eder | 4fd2735 | 2009-02-10 19:44:12 +0100 | [diff] [blame] | 1514 | #ifdef UNUSED |
| 1515 | 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] | 1516 | { |
Arnaldo Carvalho de Melo | 7be4215 | 2009-02-05 01:13:37 -0500 | [diff] [blame] | 1517 | ftrace_trace_userstack(tr, flags, preempt_count()); |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 1518 | } |
Hannes Eder | 4fd2735 | 2009-02-10 19:44:12 +0100 | [diff] [blame] | 1519 | #endif /* UNUSED */ |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 1520 | |
Frederic Weisbecker | c0a0d0d | 2009-07-29 17:51:13 +0200 | [diff] [blame] | 1521 | #endif /* CONFIG_STACKTRACE */ |
| 1522 | |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 1523 | /* created for use with alloc_percpu */ |
| 1524 | struct trace_buffer_struct { |
| 1525 | char buffer[TRACE_BUF_SIZE]; |
| 1526 | }; |
| 1527 | |
| 1528 | static struct trace_buffer_struct *trace_percpu_buffer; |
| 1529 | static struct trace_buffer_struct *trace_percpu_sirq_buffer; |
| 1530 | static struct trace_buffer_struct *trace_percpu_irq_buffer; |
| 1531 | static struct trace_buffer_struct *trace_percpu_nmi_buffer; |
| 1532 | |
| 1533 | /* |
| 1534 | * The buffer used is dependent on the context. There is a per cpu |
| 1535 | * buffer for normal context, softirq contex, hard irq context and |
| 1536 | * for NMI context. Thise allows for lockless recording. |
| 1537 | * |
| 1538 | * Note, if the buffers failed to be allocated, then this returns NULL |
| 1539 | */ |
| 1540 | static char *get_trace_buf(void) |
| 1541 | { |
| 1542 | struct trace_buffer_struct *percpu_buffer; |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 1543 | |
| 1544 | /* |
| 1545 | * If we have allocated per cpu buffers, then we do not |
| 1546 | * need to do any locking. |
| 1547 | */ |
| 1548 | if (in_nmi()) |
| 1549 | percpu_buffer = trace_percpu_nmi_buffer; |
| 1550 | else if (in_irq()) |
| 1551 | percpu_buffer = trace_percpu_irq_buffer; |
| 1552 | else if (in_softirq()) |
| 1553 | percpu_buffer = trace_percpu_sirq_buffer; |
| 1554 | else |
| 1555 | percpu_buffer = trace_percpu_buffer; |
| 1556 | |
| 1557 | if (!percpu_buffer) |
| 1558 | return NULL; |
| 1559 | |
Shan Wei | d8a0349 | 2012-11-13 09:53:04 +0800 | [diff] [blame] | 1560 | return this_cpu_ptr(&percpu_buffer->buffer[0]); |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 1561 | } |
| 1562 | |
| 1563 | static int alloc_percpu_trace_buffer(void) |
| 1564 | { |
| 1565 | struct trace_buffer_struct *buffers; |
| 1566 | struct trace_buffer_struct *sirq_buffers; |
| 1567 | struct trace_buffer_struct *irq_buffers; |
| 1568 | struct trace_buffer_struct *nmi_buffers; |
| 1569 | |
| 1570 | buffers = alloc_percpu(struct trace_buffer_struct); |
| 1571 | if (!buffers) |
| 1572 | goto err_warn; |
| 1573 | |
| 1574 | sirq_buffers = alloc_percpu(struct trace_buffer_struct); |
| 1575 | if (!sirq_buffers) |
| 1576 | goto err_sirq; |
| 1577 | |
| 1578 | irq_buffers = alloc_percpu(struct trace_buffer_struct); |
| 1579 | if (!irq_buffers) |
| 1580 | goto err_irq; |
| 1581 | |
| 1582 | nmi_buffers = alloc_percpu(struct trace_buffer_struct); |
| 1583 | if (!nmi_buffers) |
| 1584 | goto err_nmi; |
| 1585 | |
| 1586 | trace_percpu_buffer = buffers; |
| 1587 | trace_percpu_sirq_buffer = sirq_buffers; |
| 1588 | trace_percpu_irq_buffer = irq_buffers; |
| 1589 | trace_percpu_nmi_buffer = nmi_buffers; |
| 1590 | |
| 1591 | return 0; |
| 1592 | |
| 1593 | err_nmi: |
| 1594 | free_percpu(irq_buffers); |
| 1595 | err_irq: |
| 1596 | free_percpu(sirq_buffers); |
| 1597 | err_sirq: |
| 1598 | free_percpu(buffers); |
| 1599 | err_warn: |
| 1600 | WARN(1, "Could not allocate percpu trace_printk buffer"); |
| 1601 | return -ENOMEM; |
| 1602 | } |
| 1603 | |
Steven Rostedt | 8169883 | 2012-10-11 10:15:05 -0400 | [diff] [blame] | 1604 | static int buffers_allocated; |
| 1605 | |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 1606 | void trace_printk_init_buffers(void) |
| 1607 | { |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 1608 | if (buffers_allocated) |
| 1609 | return; |
| 1610 | |
| 1611 | if (alloc_percpu_trace_buffer()) |
| 1612 | return; |
| 1613 | |
| 1614 | pr_info("ftrace: Allocated trace_printk buffers\n"); |
| 1615 | |
Steven Rostedt | b382ede6 | 2012-10-10 21:44:34 -0400 | [diff] [blame] | 1616 | /* Expand the buffers to set size */ |
| 1617 | tracing_update_buffers(); |
| 1618 | |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 1619 | buffers_allocated = 1; |
Steven Rostedt | 8169883 | 2012-10-11 10:15:05 -0400 | [diff] [blame] | 1620 | |
| 1621 | /* |
| 1622 | * trace_printk_init_buffers() can be called by modules. |
| 1623 | * If that happens, then we need to start cmdline recording |
| 1624 | * directly here. If the global_trace.buffer is already |
| 1625 | * allocated here, then this was called by module code. |
| 1626 | */ |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1627 | if (global_trace.trace_buffer.buffer) |
Steven Rostedt | 8169883 | 2012-10-11 10:15:05 -0400 | [diff] [blame] | 1628 | tracing_start_cmdline_record(); |
| 1629 | } |
| 1630 | |
| 1631 | void trace_printk_start_comm(void) |
| 1632 | { |
| 1633 | /* Start tracing comms if trace printk is set */ |
| 1634 | if (!buffers_allocated) |
| 1635 | return; |
| 1636 | tracing_start_cmdline_record(); |
| 1637 | } |
| 1638 | |
| 1639 | static void trace_printk_start_stop_comm(int enabled) |
| 1640 | { |
| 1641 | if (!buffers_allocated) |
| 1642 | return; |
| 1643 | |
| 1644 | if (enabled) |
| 1645 | tracing_start_cmdline_record(); |
| 1646 | else |
| 1647 | tracing_stop_cmdline_record(); |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 1648 | } |
| 1649 | |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 1650 | /** |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 1651 | * trace_vbprintk - write binary msg to tracing buffer |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 1652 | * |
| 1653 | */ |
Steven Rostedt | 40ce74f | 2009-03-19 14:03:53 -0400 | [diff] [blame] | 1654 | int trace_vbprintk(unsigned long ip, const char *fmt, va_list args) |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 1655 | { |
Tom Zanussi | e1112b4 | 2009-03-31 00:48:49 -0500 | [diff] [blame] | 1656 | struct ftrace_event_call *call = &event_bprint; |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 1657 | struct ring_buffer_event *event; |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1658 | struct ring_buffer *buffer; |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 1659 | struct trace_array *tr = &global_trace; |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 1660 | struct bprint_entry *entry; |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 1661 | unsigned long flags; |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 1662 | char *tbuffer; |
| 1663 | int len = 0, size, pc; |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 1664 | |
| 1665 | if (unlikely(tracing_selftest_running || tracing_disabled)) |
| 1666 | return 0; |
| 1667 | |
| 1668 | /* Don't pollute graph traces with trace_vprintk internals */ |
| 1669 | pause_graph_tracing(); |
| 1670 | |
| 1671 | pc = preempt_count(); |
Steven Rostedt | 5168ae5 | 2010-06-03 09:36:50 -0400 | [diff] [blame] | 1672 | preempt_disable_notrace(); |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 1673 | |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 1674 | tbuffer = get_trace_buf(); |
| 1675 | if (!tbuffer) { |
| 1676 | len = 0; |
| 1677 | goto out; |
| 1678 | } |
| 1679 | |
| 1680 | len = vbin_printf((u32 *)tbuffer, TRACE_BUF_SIZE/sizeof(int), fmt, args); |
| 1681 | |
| 1682 | if (len > TRACE_BUF_SIZE/sizeof(int) || len < 0) |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 1683 | goto out; |
| 1684 | |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 1685 | local_save_flags(flags); |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 1686 | size = sizeof(*entry) + sizeof(u32) * len; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1687 | buffer = tr->trace_buffer.buffer; |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1688 | event = trace_buffer_lock_reserve(buffer, TRACE_BPRINT, size, |
| 1689 | flags, pc); |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 1690 | if (!event) |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 1691 | goto out; |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 1692 | entry = ring_buffer_event_data(event); |
| 1693 | entry->ip = ip; |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 1694 | entry->fmt = fmt; |
| 1695 | |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 1696 | memcpy(entry->buf, tbuffer, sizeof(u32) * len); |
Steven Rostedt | d931369 | 2010-01-06 17:27:11 -0500 | [diff] [blame] | 1697 | if (!filter_check_discard(call, entry, buffer, event)) { |
Steven Rostedt | 7ffbd48 | 2012-10-11 12:14:25 -0400 | [diff] [blame] | 1698 | __buffer_unlock_commit(buffer, event); |
Steven Rostedt | d931369 | 2010-01-06 17:27:11 -0500 | [diff] [blame] | 1699 | ftrace_trace_stack(buffer, flags, 6, pc); |
| 1700 | } |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 1701 | |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 1702 | out: |
Steven Rostedt | 5168ae5 | 2010-06-03 09:36:50 -0400 | [diff] [blame] | 1703 | preempt_enable_notrace(); |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 1704 | unpause_graph_tracing(); |
| 1705 | |
| 1706 | return len; |
| 1707 | } |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 1708 | EXPORT_SYMBOL_GPL(trace_vbprintk); |
| 1709 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1710 | static int |
| 1711 | __trace_array_vprintk(struct ring_buffer *buffer, |
| 1712 | unsigned long ip, const char *fmt, va_list args) |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 1713 | { |
Tom Zanussi | e1112b4 | 2009-03-31 00:48:49 -0500 | [diff] [blame] | 1714 | struct ftrace_event_call *call = &event_print; |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 1715 | struct ring_buffer_event *event; |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 1716 | int len = 0, size, pc; |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 1717 | struct print_entry *entry; |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 1718 | unsigned long flags; |
| 1719 | char *tbuffer; |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 1720 | |
| 1721 | if (tracing_disabled || tracing_selftest_running) |
| 1722 | return 0; |
| 1723 | |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 1724 | /* Don't pollute graph traces with trace_vprintk internals */ |
| 1725 | pause_graph_tracing(); |
| 1726 | |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 1727 | pc = preempt_count(); |
| 1728 | preempt_disable_notrace(); |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 1729 | |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 1730 | |
| 1731 | tbuffer = get_trace_buf(); |
| 1732 | if (!tbuffer) { |
| 1733 | len = 0; |
| 1734 | goto out; |
| 1735 | } |
| 1736 | |
| 1737 | len = vsnprintf(tbuffer, TRACE_BUF_SIZE, fmt, args); |
| 1738 | if (len > TRACE_BUF_SIZE) |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 1739 | goto out; |
| 1740 | |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 1741 | local_save_flags(flags); |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 1742 | size = sizeof(*entry) + len + 1; |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1743 | event = trace_buffer_lock_reserve(buffer, TRACE_PRINT, size, |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 1744 | flags, pc); |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 1745 | if (!event) |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 1746 | goto out; |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 1747 | entry = ring_buffer_event_data(event); |
Carsten Emde | c13d2f7 | 2009-11-16 20:56:13 +0100 | [diff] [blame] | 1748 | entry->ip = ip; |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 1749 | |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 1750 | memcpy(&entry->buf, tbuffer, len); |
Carsten Emde | c13d2f7 | 2009-11-16 20:56:13 +0100 | [diff] [blame] | 1751 | entry->buf[len] = '\0'; |
Steven Rostedt | d931369 | 2010-01-06 17:27:11 -0500 | [diff] [blame] | 1752 | if (!filter_check_discard(call, entry, buffer, event)) { |
Steven Rostedt | 7ffbd48 | 2012-10-11 12:14:25 -0400 | [diff] [blame] | 1753 | __buffer_unlock_commit(buffer, event); |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 1754 | ftrace_trace_stack(buffer, flags, 6, pc); |
Steven Rostedt | d931369 | 2010-01-06 17:27:11 -0500 | [diff] [blame] | 1755 | } |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 1756 | out: |
| 1757 | preempt_enable_notrace(); |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 1758 | unpause_graph_tracing(); |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 1759 | |
| 1760 | return len; |
| 1761 | } |
Steven Rostedt | 659372d | 2009-09-03 19:11:07 -0400 | [diff] [blame] | 1762 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1763 | int trace_array_vprintk(struct trace_array *tr, |
| 1764 | unsigned long ip, const char *fmt, va_list args) |
| 1765 | { |
| 1766 | return __trace_array_vprintk(tr->trace_buffer.buffer, ip, fmt, args); |
| 1767 | } |
| 1768 | |
| 1769 | int trace_array_printk(struct trace_array *tr, |
| 1770 | unsigned long ip, const char *fmt, ...) |
| 1771 | { |
| 1772 | int ret; |
| 1773 | va_list ap; |
| 1774 | |
| 1775 | if (!(trace_flags & TRACE_ITER_PRINTK)) |
| 1776 | return 0; |
| 1777 | |
| 1778 | va_start(ap, fmt); |
| 1779 | ret = trace_array_vprintk(tr, ip, fmt, ap); |
| 1780 | va_end(ap); |
| 1781 | return ret; |
| 1782 | } |
| 1783 | |
| 1784 | int trace_array_printk_buf(struct ring_buffer *buffer, |
| 1785 | unsigned long ip, const char *fmt, ...) |
| 1786 | { |
| 1787 | int ret; |
| 1788 | va_list ap; |
| 1789 | |
| 1790 | if (!(trace_flags & TRACE_ITER_PRINTK)) |
| 1791 | return 0; |
| 1792 | |
| 1793 | va_start(ap, fmt); |
| 1794 | ret = __trace_array_vprintk(buffer, ip, fmt, ap); |
| 1795 | va_end(ap); |
| 1796 | return ret; |
| 1797 | } |
| 1798 | |
Steven Rostedt | 659372d | 2009-09-03 19:11:07 -0400 | [diff] [blame] | 1799 | int trace_vprintk(unsigned long ip, const char *fmt, va_list args) |
| 1800 | { |
Steven Rostedt | a813a15 | 2009-10-09 01:41:35 -0400 | [diff] [blame] | 1801 | return trace_array_vprintk(&global_trace, ip, fmt, args); |
Steven Rostedt | 659372d | 2009-09-03 19:11:07 -0400 | [diff] [blame] | 1802 | } |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 1803 | EXPORT_SYMBOL_GPL(trace_vprintk); |
| 1804 | |
Robert Richter | e2ac8ef | 2008-11-12 12:59:32 +0100 | [diff] [blame] | 1805 | static void trace_iterator_increment(struct trace_iterator *iter) |
Steven Rostedt | 5a90f57 | 2008-09-03 17:42:51 -0400 | [diff] [blame] | 1806 | { |
Steven Rostedt | 6d158a8 | 2012-06-27 20:46:14 -0400 | [diff] [blame] | 1807 | struct ring_buffer_iter *buf_iter = trace_buffer_iter(iter, iter->cpu); |
| 1808 | |
Steven Rostedt | 5a90f57 | 2008-09-03 17:42:51 -0400 | [diff] [blame] | 1809 | iter->idx++; |
Steven Rostedt | 6d158a8 | 2012-06-27 20:46:14 -0400 | [diff] [blame] | 1810 | if (buf_iter) |
| 1811 | ring_buffer_read(buf_iter, NULL); |
Steven Rostedt | 5a90f57 | 2008-09-03 17:42:51 -0400 | [diff] [blame] | 1812 | } |
| 1813 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1814 | static struct trace_entry * |
Steven Rostedt | bc21b47 | 2010-03-31 19:49:26 -0400 | [diff] [blame] | 1815 | peek_next_entry(struct trace_iterator *iter, int cpu, u64 *ts, |
| 1816 | unsigned long *lost_events) |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1817 | { |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1818 | struct ring_buffer_event *event; |
Steven Rostedt | 6d158a8 | 2012-06-27 20:46:14 -0400 | [diff] [blame] | 1819 | struct ring_buffer_iter *buf_iter = trace_buffer_iter(iter, cpu); |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1820 | |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 1821 | if (buf_iter) |
| 1822 | event = ring_buffer_iter_peek(buf_iter, ts); |
| 1823 | else |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1824 | event = ring_buffer_peek(iter->trace_buffer->buffer, cpu, ts, |
Steven Rostedt | bc21b47 | 2010-03-31 19:49:26 -0400 | [diff] [blame] | 1825 | lost_events); |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 1826 | |
Steven Rostedt | 4a9bd3f | 2011-07-14 16:36:53 -0400 | [diff] [blame] | 1827 | if (event) { |
| 1828 | iter->ent_size = ring_buffer_event_length(event); |
| 1829 | return ring_buffer_event_data(event); |
| 1830 | } |
| 1831 | iter->ent_size = 0; |
| 1832 | return NULL; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1833 | } |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 1834 | |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1835 | static struct trace_entry * |
Steven Rostedt | bc21b47 | 2010-03-31 19:49:26 -0400 | [diff] [blame] | 1836 | __find_next_entry(struct trace_iterator *iter, int *ent_cpu, |
| 1837 | unsigned long *missing_events, u64 *ent_ts) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1838 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1839 | struct ring_buffer *buffer = iter->trace_buffer->buffer; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1840 | struct trace_entry *ent, *next = NULL; |
Lai Jiangshan | aa27497 | 2010-04-05 17:11:05 +0800 | [diff] [blame] | 1841 | unsigned long lost_events = 0, next_lost = 0; |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 1842 | int cpu_file = iter->cpu_file; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1843 | u64 next_ts = 0, ts; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1844 | int next_cpu = -1; |
Steven Rostedt | 12b5da3 | 2012-03-27 10:43:28 -0400 | [diff] [blame] | 1845 | int next_size = 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1846 | int cpu; |
| 1847 | |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 1848 | /* |
| 1849 | * If we are in a per_cpu trace file, don't bother by iterating over |
| 1850 | * all cpu and peek directly. |
| 1851 | */ |
Steven Rostedt | ae3b509 | 2013-01-23 15:22:59 -0500 | [diff] [blame] | 1852 | if (cpu_file > RING_BUFFER_ALL_CPUS) { |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 1853 | if (ring_buffer_empty_cpu(buffer, cpu_file)) |
| 1854 | return NULL; |
Steven Rostedt | bc21b47 | 2010-03-31 19:49:26 -0400 | [diff] [blame] | 1855 | ent = peek_next_entry(iter, cpu_file, ent_ts, missing_events); |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 1856 | if (ent_cpu) |
| 1857 | *ent_cpu = cpu_file; |
| 1858 | |
| 1859 | return ent; |
| 1860 | } |
| 1861 | |
Steven Rostedt | ab46428 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 1862 | for_each_tracing_cpu(cpu) { |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1863 | |
| 1864 | if (ring_buffer_empty_cpu(buffer, cpu)) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1865 | continue; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1866 | |
Steven Rostedt | bc21b47 | 2010-03-31 19:49:26 -0400 | [diff] [blame] | 1867 | ent = peek_next_entry(iter, cpu, &ts, &lost_events); |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1868 | |
Ingo Molnar | cdd31cd2 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1869 | /* |
| 1870 | * Pick the entry with the smallest timestamp: |
| 1871 | */ |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1872 | if (ent && (!next || ts < next_ts)) { |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1873 | next = ent; |
| 1874 | next_cpu = cpu; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1875 | next_ts = ts; |
Steven Rostedt | bc21b47 | 2010-03-31 19:49:26 -0400 | [diff] [blame] | 1876 | next_lost = lost_events; |
Steven Rostedt | 12b5da3 | 2012-03-27 10:43:28 -0400 | [diff] [blame] | 1877 | next_size = iter->ent_size; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1878 | } |
| 1879 | } |
| 1880 | |
Steven Rostedt | 12b5da3 | 2012-03-27 10:43:28 -0400 | [diff] [blame] | 1881 | iter->ent_size = next_size; |
| 1882 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1883 | if (ent_cpu) |
| 1884 | *ent_cpu = next_cpu; |
| 1885 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1886 | if (ent_ts) |
| 1887 | *ent_ts = next_ts; |
| 1888 | |
Steven Rostedt | bc21b47 | 2010-03-31 19:49:26 -0400 | [diff] [blame] | 1889 | if (missing_events) |
| 1890 | *missing_events = next_lost; |
| 1891 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1892 | return next; |
| 1893 | } |
| 1894 | |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1895 | /* Find the next real entry, without updating the iterator itself */ |
Frederic Weisbecker | c4a8e8b | 2009-02-02 20:29:21 -0200 | [diff] [blame] | 1896 | struct trace_entry *trace_find_next_entry(struct trace_iterator *iter, |
| 1897 | int *ent_cpu, u64 *ent_ts) |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1898 | { |
Steven Rostedt | bc21b47 | 2010-03-31 19:49:26 -0400 | [diff] [blame] | 1899 | return __find_next_entry(iter, ent_cpu, NULL, ent_ts); |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1900 | } |
Ingo Molnar | 8c523a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1901 | |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1902 | /* 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] | 1903 | void *trace_find_next_entry_inc(struct trace_iterator *iter) |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1904 | { |
Steven Rostedt | bc21b47 | 2010-03-31 19:49:26 -0400 | [diff] [blame] | 1905 | iter->ent = __find_next_entry(iter, &iter->cpu, |
| 1906 | &iter->lost_events, &iter->ts); |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1907 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1908 | if (iter->ent) |
Robert Richter | e2ac8ef | 2008-11-12 12:59:32 +0100 | [diff] [blame] | 1909 | trace_iterator_increment(iter); |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1910 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1911 | return iter->ent ? iter : NULL; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1912 | } |
| 1913 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1914 | static void trace_consume(struct trace_iterator *iter) |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1915 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1916 | ring_buffer_consume(iter->trace_buffer->buffer, iter->cpu, &iter->ts, |
Steven Rostedt | bc21b47 | 2010-03-31 19:49:26 -0400 | [diff] [blame] | 1917 | &iter->lost_events); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1918 | } |
| 1919 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1920 | 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] | 1921 | { |
| 1922 | struct trace_iterator *iter = m->private; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1923 | int i = (int)*pos; |
Ingo Molnar | 4e3c333 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 1924 | void *ent; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1925 | |
Steven Rostedt | a63ce5b | 2009-12-07 09:11:39 -0500 | [diff] [blame] | 1926 | WARN_ON_ONCE(iter->leftover); |
| 1927 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1928 | (*pos)++; |
| 1929 | |
| 1930 | /* can't go backwards */ |
| 1931 | if (iter->idx > i) |
| 1932 | return NULL; |
| 1933 | |
| 1934 | if (iter->idx < 0) |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 1935 | ent = trace_find_next_entry_inc(iter); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1936 | else |
| 1937 | ent = iter; |
| 1938 | |
| 1939 | while (ent && iter->idx < i) |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 1940 | ent = trace_find_next_entry_inc(iter); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1941 | |
| 1942 | iter->pos = *pos; |
| 1943 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1944 | return ent; |
| 1945 | } |
| 1946 | |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 1947 | void tracing_iter_reset(struct trace_iterator *iter, int cpu) |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 1948 | { |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 1949 | struct ring_buffer_event *event; |
| 1950 | struct ring_buffer_iter *buf_iter; |
| 1951 | unsigned long entries = 0; |
| 1952 | u64 ts; |
| 1953 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1954 | per_cpu_ptr(iter->trace_buffer->data, cpu)->skipped_entries = 0; |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 1955 | |
Steven Rostedt | 6d158a8 | 2012-06-27 20:46:14 -0400 | [diff] [blame] | 1956 | buf_iter = trace_buffer_iter(iter, cpu); |
| 1957 | if (!buf_iter) |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 1958 | return; |
| 1959 | |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 1960 | ring_buffer_iter_reset(buf_iter); |
| 1961 | |
| 1962 | /* |
| 1963 | * We could have the case with the max latency tracers |
| 1964 | * that a reset never took place on a cpu. This is evident |
| 1965 | * by the timestamp being before the start of the buffer. |
| 1966 | */ |
| 1967 | while ((event = ring_buffer_iter_peek(buf_iter, &ts))) { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1968 | if (ts >= iter->trace_buffer->time_start) |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 1969 | break; |
| 1970 | entries++; |
| 1971 | ring_buffer_read(buf_iter, NULL); |
| 1972 | } |
| 1973 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1974 | per_cpu_ptr(iter->trace_buffer->data, cpu)->skipped_entries = entries; |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 1975 | } |
| 1976 | |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 1977 | /* |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 1978 | * The current tracer is copied to avoid a global locking |
| 1979 | * all around. |
| 1980 | */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1981 | static void *s_start(struct seq_file *m, loff_t *pos) |
| 1982 | { |
| 1983 | struct trace_iterator *iter = m->private; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 1984 | struct trace_array *tr = iter->tr; |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 1985 | int cpu_file = iter->cpu_file; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1986 | void *p = NULL; |
| 1987 | loff_t l = 0; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1988 | int cpu; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1989 | |
Hiraku Toyooka | 2fd196e | 2012-12-26 11:52:52 +0900 | [diff] [blame] | 1990 | /* |
| 1991 | * copy the tracer to avoid using a global lock all around. |
| 1992 | * iter->trace is a copy of current_trace, the pointer to the |
| 1993 | * name may be used instead of a strcmp(), as iter->trace->name |
| 1994 | * will point to the same string as current_trace->name. |
| 1995 | */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1996 | mutex_lock(&trace_types_lock); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 1997 | if (unlikely(tr->current_trace && iter->trace->name != tr->current_trace->name)) |
| 1998 | *iter->trace = *tr->current_trace; |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 1999 | mutex_unlock(&trace_types_lock); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2000 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2001 | #ifdef CONFIG_TRACER_MAX_TRACE |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 2002 | if (iter->snapshot && iter->trace->use_max_tr) |
| 2003 | return ERR_PTR(-EBUSY); |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2004 | #endif |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 2005 | |
| 2006 | if (!iter->snapshot) |
| 2007 | atomic_inc(&trace_record_cmdline_disabled); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2008 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2009 | if (*pos != iter->pos) { |
| 2010 | iter->ent = NULL; |
| 2011 | iter->cpu = 0; |
| 2012 | iter->idx = -1; |
| 2013 | |
Steven Rostedt | ae3b509 | 2013-01-23 15:22:59 -0500 | [diff] [blame] | 2014 | if (cpu_file == RING_BUFFER_ALL_CPUS) { |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 2015 | for_each_tracing_cpu(cpu) |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 2016 | tracing_iter_reset(iter, cpu); |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 2017 | } else |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 2018 | tracing_iter_reset(iter, cpu_file); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2019 | |
Lai Jiangshan | ac91d85 | 2010-03-02 17:54:50 +0800 | [diff] [blame] | 2020 | iter->leftover = 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2021 | for (p = iter; p && l < *pos; p = s_next(m, p, &l)) |
| 2022 | ; |
| 2023 | |
| 2024 | } else { |
Steven Rostedt | a63ce5b | 2009-12-07 09:11:39 -0500 | [diff] [blame] | 2025 | /* |
| 2026 | * If we overflowed the seq_file before, then we want |
| 2027 | * to just reuse the trace_seq buffer again. |
| 2028 | */ |
| 2029 | if (iter->leftover) |
| 2030 | p = iter; |
| 2031 | else { |
| 2032 | l = *pos - 1; |
| 2033 | p = s_next(m, p, &l); |
| 2034 | } |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2035 | } |
| 2036 | |
Lai Jiangshan | 4f53596 | 2009-05-18 19:35:34 +0800 | [diff] [blame] | 2037 | trace_event_read_lock(); |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 2038 | trace_access_lock(cpu_file); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2039 | return p; |
| 2040 | } |
| 2041 | |
| 2042 | static void s_stop(struct seq_file *m, void *p) |
| 2043 | { |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 2044 | struct trace_iterator *iter = m->private; |
| 2045 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2046 | #ifdef CONFIG_TRACER_MAX_TRACE |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 2047 | if (iter->snapshot && iter->trace->use_max_tr) |
| 2048 | return; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2049 | #endif |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 2050 | |
| 2051 | if (!iter->snapshot) |
| 2052 | atomic_dec(&trace_record_cmdline_disabled); |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2053 | |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 2054 | trace_access_unlock(iter->cpu_file); |
Lai Jiangshan | 4f53596 | 2009-05-18 19:35:34 +0800 | [diff] [blame] | 2055 | trace_event_read_unlock(); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2056 | } |
| 2057 | |
Steven Rostedt | 39eaf7e | 2011-11-17 10:35:16 -0500 | [diff] [blame] | 2058 | static void |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2059 | get_total_entries(struct trace_buffer *buf, |
| 2060 | unsigned long *total, unsigned long *entries) |
Steven Rostedt | 39eaf7e | 2011-11-17 10:35:16 -0500 | [diff] [blame] | 2061 | { |
| 2062 | unsigned long count; |
| 2063 | int cpu; |
| 2064 | |
| 2065 | *total = 0; |
| 2066 | *entries = 0; |
| 2067 | |
| 2068 | for_each_tracing_cpu(cpu) { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2069 | count = ring_buffer_entries_cpu(buf->buffer, cpu); |
Steven Rostedt | 39eaf7e | 2011-11-17 10:35:16 -0500 | [diff] [blame] | 2070 | /* |
| 2071 | * If this buffer has skipped entries, then we hold all |
| 2072 | * entries for the trace and we need to ignore the |
| 2073 | * ones before the time stamp. |
| 2074 | */ |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2075 | if (per_cpu_ptr(buf->data, cpu)->skipped_entries) { |
| 2076 | count -= per_cpu_ptr(buf->data, cpu)->skipped_entries; |
Steven Rostedt | 39eaf7e | 2011-11-17 10:35:16 -0500 | [diff] [blame] | 2077 | /* total is the same as the entries */ |
| 2078 | *total += count; |
| 2079 | } else |
| 2080 | *total += count + |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2081 | ring_buffer_overrun_cpu(buf->buffer, cpu); |
Steven Rostedt | 39eaf7e | 2011-11-17 10:35:16 -0500 | [diff] [blame] | 2082 | *entries += count; |
| 2083 | } |
| 2084 | } |
| 2085 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 2086 | static void print_lat_help_header(struct seq_file *m) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2087 | { |
Michael Ellerman | a616835 | 2008-08-20 16:36:11 -0700 | [diff] [blame] | 2088 | seq_puts(m, "# _------=> CPU# \n"); |
| 2089 | seq_puts(m, "# / _-----=> irqs-off \n"); |
| 2090 | seq_puts(m, "# | / _----=> need-resched \n"); |
| 2091 | seq_puts(m, "# || / _---=> hardirq/softirq \n"); |
| 2092 | seq_puts(m, "# ||| / _--=> preempt-depth \n"); |
Steven Rostedt | e6e1e25 | 2011-03-09 10:41:56 -0500 | [diff] [blame] | 2093 | seq_puts(m, "# |||| / delay \n"); |
| 2094 | seq_puts(m, "# cmd pid ||||| time | caller \n"); |
| 2095 | seq_puts(m, "# \\ / ||||| \\ | / \n"); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2096 | } |
| 2097 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2098 | 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] | 2099 | { |
Steven Rostedt | 39eaf7e | 2011-11-17 10:35:16 -0500 | [diff] [blame] | 2100 | unsigned long total; |
| 2101 | unsigned long entries; |
| 2102 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2103 | get_total_entries(buf, &total, &entries); |
Steven Rostedt | 39eaf7e | 2011-11-17 10:35:16 -0500 | [diff] [blame] | 2104 | seq_printf(m, "# entries-in-buffer/entries-written: %lu/%lu #P:%d\n", |
| 2105 | entries, total, num_online_cpus()); |
| 2106 | seq_puts(m, "#\n"); |
| 2107 | } |
| 2108 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2109 | 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] | 2110 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2111 | print_event_info(buf, m); |
Steven Rostedt | 77271ce | 2011-11-17 09:34:33 -0500 | [diff] [blame] | 2112 | seq_puts(m, "# TASK-PID CPU# TIMESTAMP FUNCTION\n"); |
Michael Ellerman | a616835 | 2008-08-20 16:36:11 -0700 | [diff] [blame] | 2113 | seq_puts(m, "# | | | | |\n"); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2114 | } |
| 2115 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2116 | 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] | 2117 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2118 | print_event_info(buf, m); |
Steven Rostedt | 77271ce | 2011-11-17 09:34:33 -0500 | [diff] [blame] | 2119 | seq_puts(m, "# _-----=> irqs-off\n"); |
| 2120 | seq_puts(m, "# / _----=> need-resched\n"); |
| 2121 | seq_puts(m, "# | / _---=> hardirq/softirq\n"); |
| 2122 | seq_puts(m, "# || / _--=> preempt-depth\n"); |
| 2123 | seq_puts(m, "# ||| / delay\n"); |
| 2124 | seq_puts(m, "# TASK-PID CPU# |||| TIMESTAMP FUNCTION\n"); |
| 2125 | seq_puts(m, "# | | | |||| | |\n"); |
| 2126 | } |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2127 | |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 2128 | void |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2129 | print_trace_header(struct seq_file *m, struct trace_iterator *iter) |
| 2130 | { |
| 2131 | unsigned long sym_flags = (trace_flags & TRACE_ITER_SYM_MASK); |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2132 | struct trace_buffer *buf = iter->trace_buffer; |
| 2133 | struct trace_array_cpu *data = per_cpu_ptr(buf->data, buf->cpu); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 2134 | struct tracer *type = iter->trace; |
Steven Rostedt | 39eaf7e | 2011-11-17 10:35:16 -0500 | [diff] [blame] | 2135 | unsigned long entries; |
| 2136 | unsigned long total; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2137 | const char *name = "preemption"; |
| 2138 | |
Steven Rostedt (Red Hat) | d840f71 | 2013-02-01 18:38:47 -0500 | [diff] [blame] | 2139 | name = type->name; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2140 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2141 | get_total_entries(buf, &total, &entries); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2142 | |
KOSAKI Motohiro | 888b55d | 2009-03-08 13:12:43 +0900 | [diff] [blame] | 2143 | seq_printf(m, "# %s latency trace v1.1.5 on %s\n", |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2144 | name, UTS_RELEASE); |
KOSAKI Motohiro | 888b55d | 2009-03-08 13:12:43 +0900 | [diff] [blame] | 2145 | seq_puts(m, "# -----------------------------------" |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2146 | "---------------------------------\n"); |
KOSAKI Motohiro | 888b55d | 2009-03-08 13:12:43 +0900 | [diff] [blame] | 2147 | seq_printf(m, "# latency: %lu us, #%lu/%lu, CPU#%d |" |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2148 | " (M:%s VP:%d, KP:%d, SP:%d HP:%d", |
Steven Rostedt | 57f50be | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 2149 | nsecs_to_usecs(data->saved_latency), |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2150 | entries, |
Steven Rostedt | 4c11d7a | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 2151 | total, |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2152 | buf->cpu, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2153 | #if defined(CONFIG_PREEMPT_NONE) |
| 2154 | "server", |
| 2155 | #elif defined(CONFIG_PREEMPT_VOLUNTARY) |
| 2156 | "desktop", |
Steven Rostedt | b5c21b4 | 2008-07-10 20:58:12 -0400 | [diff] [blame] | 2157 | #elif defined(CONFIG_PREEMPT) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2158 | "preempt", |
| 2159 | #else |
| 2160 | "unknown", |
| 2161 | #endif |
| 2162 | /* These are reserved for later use */ |
| 2163 | 0, 0, 0, 0); |
| 2164 | #ifdef CONFIG_SMP |
| 2165 | seq_printf(m, " #P:%d)\n", num_online_cpus()); |
| 2166 | #else |
| 2167 | seq_puts(m, ")\n"); |
| 2168 | #endif |
KOSAKI Motohiro | 888b55d | 2009-03-08 13:12:43 +0900 | [diff] [blame] | 2169 | seq_puts(m, "# -----------------\n"); |
| 2170 | seq_printf(m, "# | task: %.16s-%d " |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2171 | "(uid:%d nice:%ld policy:%ld rt_prio:%ld)\n", |
Eric W. Biederman | d20b92a | 2012-03-13 16:02:19 -0700 | [diff] [blame] | 2172 | data->comm, data->pid, |
| 2173 | from_kuid_munged(seq_user_ns(m), data->uid), data->nice, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2174 | data->policy, data->rt_priority); |
KOSAKI Motohiro | 888b55d | 2009-03-08 13:12:43 +0900 | [diff] [blame] | 2175 | seq_puts(m, "# -----------------\n"); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2176 | |
| 2177 | if (data->critical_start) { |
KOSAKI Motohiro | 888b55d | 2009-03-08 13:12:43 +0900 | [diff] [blame] | 2178 | seq_puts(m, "# => started at: "); |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2179 | seq_print_ip_sym(&iter->seq, data->critical_start, sym_flags); |
| 2180 | trace_print_seq(m, &iter->seq); |
KOSAKI Motohiro | 888b55d | 2009-03-08 13:12:43 +0900 | [diff] [blame] | 2181 | seq_puts(m, "\n# => ended at: "); |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2182 | seq_print_ip_sym(&iter->seq, data->critical_end, sym_flags); |
| 2183 | trace_print_seq(m, &iter->seq); |
Steven Rostedt | 8248ac0 | 2009-09-02 12:27:41 -0400 | [diff] [blame] | 2184 | seq_puts(m, "\n#\n"); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2185 | } |
| 2186 | |
KOSAKI Motohiro | 888b55d | 2009-03-08 13:12:43 +0900 | [diff] [blame] | 2187 | seq_puts(m, "#\n"); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2188 | } |
| 2189 | |
Steven Rostedt | a309720 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 2190 | static void test_cpu_buff_start(struct trace_iterator *iter) |
| 2191 | { |
| 2192 | struct trace_seq *s = &iter->seq; |
| 2193 | |
Steven Rostedt | 12ef7d4 | 2008-11-12 17:52:38 -0500 | [diff] [blame] | 2194 | if (!(trace_flags & TRACE_ITER_ANNOTATE)) |
| 2195 | return; |
| 2196 | |
| 2197 | if (!(iter->iter_flags & TRACE_FILE_ANNOTATE)) |
| 2198 | return; |
| 2199 | |
Rusty Russell | 4462344 | 2009-01-01 10:12:23 +1030 | [diff] [blame] | 2200 | if (cpumask_test_cpu(iter->cpu, iter->started)) |
Steven Rostedt | a309720 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 2201 | return; |
| 2202 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2203 | if (per_cpu_ptr(iter->trace_buffer->data, iter->cpu)->skipped_entries) |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 2204 | return; |
| 2205 | |
Rusty Russell | 4462344 | 2009-01-01 10:12:23 +1030 | [diff] [blame] | 2206 | cpumask_set_cpu(iter->cpu, iter->started); |
Frederic Weisbecker | b0dfa97 | 2009-04-01 22:53:08 +0200 | [diff] [blame] | 2207 | |
| 2208 | /* Don't print started cpu buffer for the first entry of the trace */ |
| 2209 | if (iter->idx > 1) |
| 2210 | trace_seq_printf(s, "##### CPU %u buffer started ####\n", |
| 2211 | iter->cpu); |
Steven Rostedt | a309720 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 2212 | } |
| 2213 | |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 2214 | static enum print_line_t print_trace_fmt(struct trace_iterator *iter) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2215 | { |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2216 | struct trace_seq *s = &iter->seq; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2217 | unsigned long sym_flags = (trace_flags & TRACE_ITER_SYM_MASK); |
Ingo Molnar | 4e3c333 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 2218 | struct trace_entry *entry; |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 2219 | struct trace_event *event; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2220 | |
Ingo Molnar | 4e3c333 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 2221 | entry = iter->ent; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2222 | |
Steven Rostedt | a309720 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 2223 | test_cpu_buff_start(iter); |
| 2224 | |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 2225 | event = ftrace_find_event(entry->type); |
Frederic Weisbecker | c4a8e8b | 2009-02-02 20:29:21 -0200 | [diff] [blame] | 2226 | |
| 2227 | if (trace_flags & TRACE_ITER_CONTEXT_INFO) { |
Steven Rostedt | 27d48be | 2009-03-04 21:57:29 -0500 | [diff] [blame] | 2228 | if (iter->iter_flags & TRACE_FILE_LAT_FMT) { |
| 2229 | if (!trace_print_lat_context(iter)) |
| 2230 | goto partial; |
| 2231 | } else { |
| 2232 | if (!trace_print_context(iter)) |
| 2233 | goto partial; |
| 2234 | } |
Frederic Weisbecker | c4a8e8b | 2009-02-02 20:29:21 -0200 | [diff] [blame] | 2235 | } |
| 2236 | |
Arnaldo Carvalho de Melo | 268ccda | 2009-02-04 20:16:39 -0200 | [diff] [blame] | 2237 | if (event) |
Steven Rostedt | a9a5776 | 2010-04-22 18:46:14 -0400 | [diff] [blame] | 2238 | return event->funcs->trace(iter, sym_flags, event); |
Arnaldo Carvalho de Melo | d9793bd | 2009-02-03 20:20:41 -0200 | [diff] [blame] | 2239 | |
| 2240 | if (!trace_seq_printf(s, "Unknown type %d\n", entry->type)) |
| 2241 | goto partial; |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 2242 | |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 2243 | return TRACE_TYPE_HANDLED; |
Arnaldo Carvalho de Melo | d9793bd | 2009-02-03 20:20:41 -0200 | [diff] [blame] | 2244 | partial: |
| 2245 | return TRACE_TYPE_PARTIAL_LINE; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2246 | } |
| 2247 | |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 2248 | static enum print_line_t print_raw_fmt(struct trace_iterator *iter) |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2249 | { |
| 2250 | struct trace_seq *s = &iter->seq; |
| 2251 | struct trace_entry *entry; |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 2252 | struct trace_event *event; |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2253 | |
| 2254 | entry = iter->ent; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2255 | |
Frederic Weisbecker | c4a8e8b | 2009-02-02 20:29:21 -0200 | [diff] [blame] | 2256 | if (trace_flags & TRACE_ITER_CONTEXT_INFO) { |
Arnaldo Carvalho de Melo | d9793bd | 2009-02-03 20:20:41 -0200 | [diff] [blame] | 2257 | if (!trace_seq_printf(s, "%d %d %llu ", |
| 2258 | entry->pid, iter->cpu, iter->ts)) |
| 2259 | goto partial; |
Frederic Weisbecker | c4a8e8b | 2009-02-02 20:29:21 -0200 | [diff] [blame] | 2260 | } |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2261 | |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 2262 | event = ftrace_find_event(entry->type); |
Arnaldo Carvalho de Melo | 268ccda | 2009-02-04 20:16:39 -0200 | [diff] [blame] | 2263 | if (event) |
Steven Rostedt | a9a5776 | 2010-04-22 18:46:14 -0400 | [diff] [blame] | 2264 | return event->funcs->raw(iter, 0, event); |
Arnaldo Carvalho de Melo | d9793bd | 2009-02-03 20:20:41 -0200 | [diff] [blame] | 2265 | |
| 2266 | if (!trace_seq_printf(s, "%d ?\n", entry->type)) |
| 2267 | goto partial; |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 2268 | |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 2269 | return TRACE_TYPE_HANDLED; |
Arnaldo Carvalho de Melo | d9793bd | 2009-02-03 20:20:41 -0200 | [diff] [blame] | 2270 | partial: |
| 2271 | return TRACE_TYPE_PARTIAL_LINE; |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2272 | } |
| 2273 | |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 2274 | static enum print_line_t print_hex_fmt(struct trace_iterator *iter) |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 2275 | { |
| 2276 | struct trace_seq *s = &iter->seq; |
| 2277 | unsigned char newline = '\n'; |
| 2278 | struct trace_entry *entry; |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 2279 | struct trace_event *event; |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 2280 | |
| 2281 | entry = iter->ent; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2282 | |
Frederic Weisbecker | c4a8e8b | 2009-02-02 20:29:21 -0200 | [diff] [blame] | 2283 | if (trace_flags & TRACE_ITER_CONTEXT_INFO) { |
| 2284 | SEQ_PUT_HEX_FIELD_RET(s, entry->pid); |
| 2285 | SEQ_PUT_HEX_FIELD_RET(s, iter->cpu); |
| 2286 | SEQ_PUT_HEX_FIELD_RET(s, iter->ts); |
| 2287 | } |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 2288 | |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 2289 | event = ftrace_find_event(entry->type); |
Arnaldo Carvalho de Melo | 268ccda | 2009-02-04 20:16:39 -0200 | [diff] [blame] | 2290 | if (event) { |
Steven Rostedt | a9a5776 | 2010-04-22 18:46:14 -0400 | [diff] [blame] | 2291 | 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] | 2292 | if (ret != TRACE_TYPE_HANDLED) |
| 2293 | return ret; |
| 2294 | } |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 2295 | |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 2296 | SEQ_PUT_FIELD_RET(s, newline); |
| 2297 | |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 2298 | return TRACE_TYPE_HANDLED; |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 2299 | } |
| 2300 | |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 2301 | static enum print_line_t print_bin_fmt(struct trace_iterator *iter) |
Ingo Molnar | cb0f12a | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2302 | { |
| 2303 | struct trace_seq *s = &iter->seq; |
| 2304 | struct trace_entry *entry; |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 2305 | struct trace_event *event; |
Ingo Molnar | cb0f12a | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2306 | |
| 2307 | entry = iter->ent; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2308 | |
Frederic Weisbecker | c4a8e8b | 2009-02-02 20:29:21 -0200 | [diff] [blame] | 2309 | if (trace_flags & TRACE_ITER_CONTEXT_INFO) { |
| 2310 | SEQ_PUT_FIELD_RET(s, entry->pid); |
Steven Rostedt | 1830b52 | 2009-02-07 19:38:43 -0500 | [diff] [blame] | 2311 | SEQ_PUT_FIELD_RET(s, iter->cpu); |
Frederic Weisbecker | c4a8e8b | 2009-02-02 20:29:21 -0200 | [diff] [blame] | 2312 | SEQ_PUT_FIELD_RET(s, iter->ts); |
| 2313 | } |
Ingo Molnar | cb0f12a | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2314 | |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 2315 | event = ftrace_find_event(entry->type); |
Steven Rostedt | a9a5776 | 2010-04-22 18:46:14 -0400 | [diff] [blame] | 2316 | return event ? event->funcs->binary(iter, 0, event) : |
| 2317 | TRACE_TYPE_HANDLED; |
Ingo Molnar | cb0f12a | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2318 | } |
| 2319 | |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 2320 | int trace_empty(struct trace_iterator *iter) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2321 | { |
Steven Rostedt | 6d158a8 | 2012-06-27 20:46:14 -0400 | [diff] [blame] | 2322 | struct ring_buffer_iter *buf_iter; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2323 | int cpu; |
| 2324 | |
Steven Rostedt | 9aba60f | 2009-03-11 19:52:30 -0400 | [diff] [blame] | 2325 | /* If we are looking at one CPU buffer, only check that one */ |
Steven Rostedt | ae3b509 | 2013-01-23 15:22:59 -0500 | [diff] [blame] | 2326 | if (iter->cpu_file != RING_BUFFER_ALL_CPUS) { |
Steven Rostedt | 9aba60f | 2009-03-11 19:52:30 -0400 | [diff] [blame] | 2327 | cpu = iter->cpu_file; |
Steven Rostedt | 6d158a8 | 2012-06-27 20:46:14 -0400 | [diff] [blame] | 2328 | buf_iter = trace_buffer_iter(iter, cpu); |
| 2329 | if (buf_iter) { |
| 2330 | if (!ring_buffer_iter_empty(buf_iter)) |
Steven Rostedt | 9aba60f | 2009-03-11 19:52:30 -0400 | [diff] [blame] | 2331 | return 0; |
| 2332 | } else { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2333 | if (!ring_buffer_empty_cpu(iter->trace_buffer->buffer, cpu)) |
Steven Rostedt | 9aba60f | 2009-03-11 19:52:30 -0400 | [diff] [blame] | 2334 | return 0; |
| 2335 | } |
| 2336 | return 1; |
| 2337 | } |
| 2338 | |
Steven Rostedt | ab46428 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 2339 | for_each_tracing_cpu(cpu) { |
Steven Rostedt | 6d158a8 | 2012-06-27 20:46:14 -0400 | [diff] [blame] | 2340 | buf_iter = trace_buffer_iter(iter, cpu); |
| 2341 | if (buf_iter) { |
| 2342 | if (!ring_buffer_iter_empty(buf_iter)) |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 2343 | return 0; |
| 2344 | } else { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2345 | if (!ring_buffer_empty_cpu(iter->trace_buffer->buffer, cpu)) |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 2346 | return 0; |
| 2347 | } |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2348 | } |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 2349 | |
Frederic Weisbecker | 797d371 | 2008-09-30 18:13:45 +0200 | [diff] [blame] | 2350 | return 1; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2351 | } |
| 2352 | |
Lai Jiangshan | 4f53596 | 2009-05-18 19:35:34 +0800 | [diff] [blame] | 2353 | /* Called with trace_event_read_lock() held. */ |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 2354 | enum print_line_t print_trace_line(struct trace_iterator *iter) |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2355 | { |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 2356 | enum print_line_t ret; |
| 2357 | |
Jiri Olsa | ee5e51f | 2011-03-25 12:05:18 +0100 | [diff] [blame] | 2358 | if (iter->lost_events && |
| 2359 | !trace_seq_printf(&iter->seq, "CPU:%d [LOST %lu EVENTS]\n", |
| 2360 | iter->cpu, iter->lost_events)) |
| 2361 | return TRACE_TYPE_PARTIAL_LINE; |
Steven Rostedt | bc21b47 | 2010-03-31 19:49:26 -0400 | [diff] [blame] | 2362 | |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 2363 | if (iter->trace && iter->trace->print_line) { |
| 2364 | ret = iter->trace->print_line(iter); |
| 2365 | if (ret != TRACE_TYPE_UNHANDLED) |
| 2366 | return ret; |
| 2367 | } |
Thomas Gleixner | 72829bc | 2008-05-23 21:37:28 +0200 | [diff] [blame] | 2368 | |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 2369 | if (iter->ent->type == TRACE_BPRINT && |
| 2370 | trace_flags & TRACE_ITER_PRINTK && |
| 2371 | trace_flags & TRACE_ITER_PRINTK_MSGONLY) |
Steven Rostedt | 5ef841f | 2009-03-19 12:20:38 -0400 | [diff] [blame] | 2372 | return trace_print_bprintk_msg_only(iter); |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 2373 | |
Frederic Weisbecker | 66896a8 | 2008-12-13 20:18:13 +0100 | [diff] [blame] | 2374 | if (iter->ent->type == TRACE_PRINT && |
| 2375 | trace_flags & TRACE_ITER_PRINTK && |
| 2376 | trace_flags & TRACE_ITER_PRINTK_MSGONLY) |
Steven Rostedt | 5ef841f | 2009-03-19 12:20:38 -0400 | [diff] [blame] | 2377 | return trace_print_printk_msg_only(iter); |
Frederic Weisbecker | 66896a8 | 2008-12-13 20:18:13 +0100 | [diff] [blame] | 2378 | |
Ingo Molnar | cb0f12a | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2379 | if (trace_flags & TRACE_ITER_BIN) |
| 2380 | return print_bin_fmt(iter); |
| 2381 | |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 2382 | if (trace_flags & TRACE_ITER_HEX) |
| 2383 | return print_hex_fmt(iter); |
| 2384 | |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2385 | if (trace_flags & TRACE_ITER_RAW) |
| 2386 | return print_raw_fmt(iter); |
| 2387 | |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2388 | return print_trace_fmt(iter); |
| 2389 | } |
| 2390 | |
Jiri Olsa | 7e9a49e | 2011-11-07 16:08:49 +0100 | [diff] [blame] | 2391 | void trace_latency_header(struct seq_file *m) |
| 2392 | { |
| 2393 | struct trace_iterator *iter = m->private; |
| 2394 | |
| 2395 | /* print nothing if the buffers are empty */ |
| 2396 | if (trace_empty(iter)) |
| 2397 | return; |
| 2398 | |
| 2399 | if (iter->iter_flags & TRACE_FILE_LAT_FMT) |
| 2400 | print_trace_header(m, iter); |
| 2401 | |
| 2402 | if (!(trace_flags & TRACE_ITER_VERBOSE)) |
| 2403 | print_lat_help_header(m); |
| 2404 | } |
| 2405 | |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 2406 | void trace_default_header(struct seq_file *m) |
| 2407 | { |
| 2408 | struct trace_iterator *iter = m->private; |
| 2409 | |
Jiri Olsa | f56e7f8 | 2011-06-03 16:58:49 +0200 | [diff] [blame] | 2410 | if (!(trace_flags & TRACE_ITER_CONTEXT_INFO)) |
| 2411 | return; |
| 2412 | |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 2413 | if (iter->iter_flags & TRACE_FILE_LAT_FMT) { |
| 2414 | /* print nothing if the buffers are empty */ |
| 2415 | if (trace_empty(iter)) |
| 2416 | return; |
| 2417 | print_trace_header(m, iter); |
| 2418 | if (!(trace_flags & TRACE_ITER_VERBOSE)) |
| 2419 | print_lat_help_header(m); |
| 2420 | } else { |
Steven Rostedt | 77271ce | 2011-11-17 09:34:33 -0500 | [diff] [blame] | 2421 | if (!(trace_flags & TRACE_ITER_VERBOSE)) { |
| 2422 | if (trace_flags & TRACE_ITER_IRQ_INFO) |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2423 | print_func_help_header_irq(iter->trace_buffer, m); |
Steven Rostedt | 77271ce | 2011-11-17 09:34:33 -0500 | [diff] [blame] | 2424 | else |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2425 | print_func_help_header(iter->trace_buffer, m); |
Steven Rostedt | 77271ce | 2011-11-17 09:34:33 -0500 | [diff] [blame] | 2426 | } |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 2427 | } |
| 2428 | } |
| 2429 | |
Steven Rostedt | e0a413f | 2011-09-29 21:26:16 -0400 | [diff] [blame] | 2430 | static void test_ftrace_alive(struct seq_file *m) |
| 2431 | { |
| 2432 | if (!ftrace_is_dead()) |
| 2433 | return; |
| 2434 | seq_printf(m, "# WARNING: FUNCTION TRACING IS CORRUPTED\n"); |
| 2435 | seq_printf(m, "# MAY BE MISSING FUNCTION EVENTS\n"); |
| 2436 | } |
| 2437 | |
Steven Rostedt (Red Hat) | d8741e2 | 2013-03-05 10:25:16 -0500 | [diff] [blame] | 2438 | #ifdef CONFIG_TRACER_MAX_TRACE |
Steven Rostedt (Red Hat) | f1affca | 2013-03-05 14:35:11 -0500 | [diff] [blame] | 2439 | static void show_snapshot_main_help(struct seq_file *m) |
| 2440 | { |
| 2441 | seq_printf(m, "# echo 0 > snapshot : Clears and frees snapshot buffer\n"); |
| 2442 | seq_printf(m, "# echo 1 > snapshot : Allocates snapshot buffer, if not already allocated.\n"); |
| 2443 | seq_printf(m, "# Takes a snapshot of the main buffer.\n"); |
| 2444 | seq_printf(m, "# echo 2 > snapshot : Clears snapshot buffer (but does not allocate)\n"); |
| 2445 | seq_printf(m, "# (Doesn't have to be '2' works with any number that\n"); |
| 2446 | seq_printf(m, "# is not a '0' or '1')\n"); |
| 2447 | } |
| 2448 | |
| 2449 | static void show_snapshot_percpu_help(struct seq_file *m) |
| 2450 | { |
| 2451 | seq_printf(m, "# echo 0 > snapshot : Invalid for per_cpu snapshot file.\n"); |
| 2452 | #ifdef CONFIG_RING_BUFFER_ALLOW_SWAP |
| 2453 | seq_printf(m, "# echo 1 > snapshot : Allocates snapshot buffer, if not already allocated.\n"); |
| 2454 | seq_printf(m, "# Takes a snapshot of the main buffer for this cpu.\n"); |
| 2455 | #else |
| 2456 | seq_printf(m, "# echo 1 > snapshot : Not supported with this kernel.\n"); |
| 2457 | seq_printf(m, "# Must use main snapshot file to allocate.\n"); |
| 2458 | #endif |
| 2459 | seq_printf(m, "# echo 2 > snapshot : Clears this cpu's snapshot buffer (but does not allocate)\n"); |
| 2460 | seq_printf(m, "# (Doesn't have to be '2' works with any number that\n"); |
| 2461 | seq_printf(m, "# is not a '0' or '1')\n"); |
| 2462 | } |
| 2463 | |
Steven Rostedt (Red Hat) | d8741e2 | 2013-03-05 10:25:16 -0500 | [diff] [blame] | 2464 | static void print_snapshot_help(struct seq_file *m, struct trace_iterator *iter) |
| 2465 | { |
Steven Rostedt (Red Hat) | 45ad21c | 2013-03-05 18:25:02 -0500 | [diff] [blame] | 2466 | if (iter->tr->allocated_snapshot) |
Steven Rostedt (Red Hat) | d8741e2 | 2013-03-05 10:25:16 -0500 | [diff] [blame] | 2467 | seq_printf(m, "#\n# * Snapshot is allocated *\n#\n"); |
| 2468 | else |
| 2469 | seq_printf(m, "#\n# * Snapshot is freed *\n#\n"); |
| 2470 | |
| 2471 | seq_printf(m, "# Snapshot commands:\n"); |
Steven Rostedt (Red Hat) | f1affca | 2013-03-05 14:35:11 -0500 | [diff] [blame] | 2472 | if (iter->cpu_file == RING_BUFFER_ALL_CPUS) |
| 2473 | show_snapshot_main_help(m); |
| 2474 | else |
| 2475 | show_snapshot_percpu_help(m); |
Steven Rostedt (Red Hat) | d8741e2 | 2013-03-05 10:25:16 -0500 | [diff] [blame] | 2476 | } |
| 2477 | #else |
| 2478 | /* Should never be called */ |
| 2479 | static inline void print_snapshot_help(struct seq_file *m, struct trace_iterator *iter) { } |
| 2480 | #endif |
| 2481 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2482 | static int s_show(struct seq_file *m, void *v) |
| 2483 | { |
| 2484 | struct trace_iterator *iter = v; |
Steven Rostedt | a63ce5b | 2009-12-07 09:11:39 -0500 | [diff] [blame] | 2485 | int ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2486 | |
| 2487 | if (iter->ent == NULL) { |
| 2488 | if (iter->tr) { |
| 2489 | seq_printf(m, "# tracer: %s\n", iter->trace->name); |
| 2490 | seq_puts(m, "#\n"); |
Steven Rostedt | e0a413f | 2011-09-29 21:26:16 -0400 | [diff] [blame] | 2491 | test_ftrace_alive(m); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2492 | } |
Steven Rostedt (Red Hat) | d8741e2 | 2013-03-05 10:25:16 -0500 | [diff] [blame] | 2493 | if (iter->snapshot && trace_empty(iter)) |
| 2494 | print_snapshot_help(m, iter); |
| 2495 | else if (iter->trace && iter->trace->print_header) |
Markus Metzger | 8bba1bf | 2008-11-25 09:12:31 +0100 | [diff] [blame] | 2496 | iter->trace->print_header(m); |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 2497 | else |
| 2498 | trace_default_header(m); |
| 2499 | |
Steven Rostedt | a63ce5b | 2009-12-07 09:11:39 -0500 | [diff] [blame] | 2500 | } else if (iter->leftover) { |
| 2501 | /* |
| 2502 | * If we filled the seq_file buffer earlier, we |
| 2503 | * want to just show it now. |
| 2504 | */ |
| 2505 | ret = trace_print_seq(m, &iter->seq); |
| 2506 | |
| 2507 | /* ret should this time be zero, but you never know */ |
| 2508 | iter->leftover = ret; |
| 2509 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2510 | } else { |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2511 | print_trace_line(iter); |
Steven Rostedt | a63ce5b | 2009-12-07 09:11:39 -0500 | [diff] [blame] | 2512 | ret = trace_print_seq(m, &iter->seq); |
| 2513 | /* |
| 2514 | * If we overflow the seq_file buffer, then it will |
| 2515 | * ask us for this data again at start up. |
| 2516 | * Use that instead. |
| 2517 | * ret is 0 if seq_file write succeeded. |
| 2518 | * -1 otherwise. |
| 2519 | */ |
| 2520 | iter->leftover = ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2521 | } |
| 2522 | |
| 2523 | return 0; |
| 2524 | } |
| 2525 | |
James Morris | 88e9d34 | 2009-09-22 16:43:43 -0700 | [diff] [blame] | 2526 | static const struct seq_operations tracer_seq_ops = { |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2527 | .start = s_start, |
| 2528 | .next = s_next, |
| 2529 | .stop = s_stop, |
| 2530 | .show = s_show, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2531 | }; |
| 2532 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 2533 | static struct trace_iterator * |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 2534 | __tracing_open(struct inode *inode, struct file *file, bool snapshot) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2535 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 2536 | struct trace_cpu *tc = inode->i_private; |
| 2537 | struct trace_array *tr = tc->tr; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2538 | struct trace_iterator *iter; |
Jiri Olsa | 50e18b9 | 2012-04-25 10:23:39 +0200 | [diff] [blame] | 2539 | int cpu; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2540 | |
Steven Rostedt | 85a2f9b | 2009-02-27 00:12:38 -0500 | [diff] [blame] | 2541 | if (tracing_disabled) |
| 2542 | return ERR_PTR(-ENODEV); |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 2543 | |
Jiri Olsa | 50e18b9 | 2012-04-25 10:23:39 +0200 | [diff] [blame] | 2544 | iter = __seq_open_private(file, &tracer_seq_ops, sizeof(*iter)); |
Steven Rostedt | 85a2f9b | 2009-02-27 00:12:38 -0500 | [diff] [blame] | 2545 | if (!iter) |
| 2546 | return ERR_PTR(-ENOMEM); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2547 | |
Steven Rostedt | 6d158a8 | 2012-06-27 20:46:14 -0400 | [diff] [blame] | 2548 | iter->buffer_iter = kzalloc(sizeof(*iter->buffer_iter) * num_possible_cpus(), |
| 2549 | GFP_KERNEL); |
Dan Carpenter | 93574fc | 2012-07-11 09:35:08 +0300 | [diff] [blame] | 2550 | if (!iter->buffer_iter) |
| 2551 | goto release; |
| 2552 | |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 2553 | /* |
| 2554 | * We make a copy of the current tracer to avoid concurrent |
| 2555 | * changes on it while we are reading. |
| 2556 | */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2557 | mutex_lock(&trace_types_lock); |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 2558 | iter->trace = kzalloc(sizeof(*iter->trace), GFP_KERNEL); |
Steven Rostedt | 85a2f9b | 2009-02-27 00:12:38 -0500 | [diff] [blame] | 2559 | if (!iter->trace) |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 2560 | goto fail; |
Steven Rostedt | 85a2f9b | 2009-02-27 00:12:38 -0500 | [diff] [blame] | 2561 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 2562 | *iter->trace = *tr->current_trace; |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 2563 | |
Li Zefan | 79f5599 | 2009-06-15 14:58:26 +0800 | [diff] [blame] | 2564 | if (!zalloc_cpumask_var(&iter->started, GFP_KERNEL)) |
Frederic Weisbecker | b0dfa97 | 2009-04-01 22:53:08 +0200 | [diff] [blame] | 2565 | goto fail; |
| 2566 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2567 | iter->tr = tr; |
| 2568 | |
| 2569 | #ifdef CONFIG_TRACER_MAX_TRACE |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 2570 | /* Currently only the top directory has a snapshot */ |
| 2571 | if (tr->current_trace->print_max || snapshot) |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2572 | iter->trace_buffer = &tr->max_buffer; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2573 | else |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2574 | #endif |
| 2575 | iter->trace_buffer = &tr->trace_buffer; |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 2576 | iter->snapshot = snapshot; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2577 | iter->pos = -1; |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 2578 | mutex_init(&iter->mutex); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 2579 | iter->cpu_file = tc->cpu; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2580 | |
Markus Metzger | 8bba1bf | 2008-11-25 09:12:31 +0100 | [diff] [blame] | 2581 | /* Notify the tracer early; before we stop tracing. */ |
| 2582 | if (iter->trace && iter->trace->open) |
Markus Metzger | a93751c | 2008-12-11 13:53:26 +0100 | [diff] [blame] | 2583 | iter->trace->open(iter); |
Markus Metzger | 8bba1bf | 2008-11-25 09:12:31 +0100 | [diff] [blame] | 2584 | |
Steven Rostedt | 12ef7d4 | 2008-11-12 17:52:38 -0500 | [diff] [blame] | 2585 | /* Annotate start of buffers if we had overruns */ |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2586 | if (ring_buffer_overruns(iter->trace_buffer->buffer)) |
Steven Rostedt | 12ef7d4 | 2008-11-12 17:52:38 -0500 | [diff] [blame] | 2587 | iter->iter_flags |= TRACE_FILE_ANNOTATE; |
| 2588 | |
David Sharp | 8be0709 | 2012-11-13 12:18:22 -0800 | [diff] [blame] | 2589 | /* Output in nanoseconds only if we are using a clock in nanoseconds. */ |
| 2590 | if (trace_clocks[trace_clock_id].in_ns) |
| 2591 | iter->iter_flags |= TRACE_FILE_TIME_IN_NS; |
| 2592 | |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 2593 | /* stop the trace while dumping if we are not opening "snapshot" */ |
| 2594 | if (!iter->snapshot) |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 2595 | tracing_stop_tr(tr); |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 2596 | |
Steven Rostedt | ae3b509 | 2013-01-23 15:22:59 -0500 | [diff] [blame] | 2597 | if (iter->cpu_file == RING_BUFFER_ALL_CPUS) { |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 2598 | for_each_tracing_cpu(cpu) { |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 2599 | iter->buffer_iter[cpu] = |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2600 | ring_buffer_read_prepare(iter->trace_buffer->buffer, cpu); |
David Miller | 72c9ddf | 2010-04-20 15:47:11 -0700 | [diff] [blame] | 2601 | } |
| 2602 | ring_buffer_read_prepare_sync(); |
| 2603 | for_each_tracing_cpu(cpu) { |
| 2604 | ring_buffer_read_start(iter->buffer_iter[cpu]); |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 2605 | tracing_iter_reset(iter, cpu); |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 2606 | } |
| 2607 | } else { |
| 2608 | cpu = iter->cpu_file; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2609 | iter->buffer_iter[cpu] = |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2610 | ring_buffer_read_prepare(iter->trace_buffer->buffer, cpu); |
David Miller | 72c9ddf | 2010-04-20 15:47:11 -0700 | [diff] [blame] | 2611 | ring_buffer_read_prepare_sync(); |
| 2612 | ring_buffer_read_start(iter->buffer_iter[cpu]); |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 2613 | tracing_iter_reset(iter, cpu); |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2614 | } |
| 2615 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2616 | mutex_unlock(&trace_types_lock); |
| 2617 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2618 | return iter; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2619 | |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 2620 | fail: |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2621 | mutex_unlock(&trace_types_lock); |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 2622 | kfree(iter->trace); |
Steven Rostedt | 6d158a8 | 2012-06-27 20:46:14 -0400 | [diff] [blame] | 2623 | kfree(iter->buffer_iter); |
Dan Carpenter | 93574fc | 2012-07-11 09:35:08 +0300 | [diff] [blame] | 2624 | release: |
Jiri Olsa | 50e18b9 | 2012-04-25 10:23:39 +0200 | [diff] [blame] | 2625 | seq_release_private(inode, file); |
| 2626 | return ERR_PTR(-ENOMEM); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2627 | } |
| 2628 | |
| 2629 | int tracing_open_generic(struct inode *inode, struct file *filp) |
| 2630 | { |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 2631 | if (tracing_disabled) |
| 2632 | return -ENODEV; |
| 2633 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2634 | filp->private_data = inode->i_private; |
| 2635 | return 0; |
| 2636 | } |
| 2637 | |
Hannes Eder | 4fd2735 | 2009-02-10 19:44:12 +0100 | [diff] [blame] | 2638 | static int tracing_release(struct inode *inode, struct file *file) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2639 | { |
matt mooney | 907f278 | 2010-09-27 19:04:53 -0700 | [diff] [blame] | 2640 | struct seq_file *m = file->private_data; |
Steven Rostedt | 4acd4d0 | 2009-03-18 10:40:24 -0400 | [diff] [blame] | 2641 | struct trace_iterator *iter; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 2642 | struct trace_array *tr; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2643 | int cpu; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2644 | |
Steven Rostedt | 4acd4d0 | 2009-03-18 10:40:24 -0400 | [diff] [blame] | 2645 | if (!(file->f_mode & FMODE_READ)) |
| 2646 | return 0; |
| 2647 | |
| 2648 | iter = m->private; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2649 | tr = iter->tr; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 2650 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2651 | mutex_lock(&trace_types_lock); |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2652 | for_each_tracing_cpu(cpu) { |
| 2653 | if (iter->buffer_iter[cpu]) |
| 2654 | ring_buffer_read_finish(iter->buffer_iter[cpu]); |
| 2655 | } |
| 2656 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2657 | if (iter->trace && iter->trace->close) |
| 2658 | iter->trace->close(iter); |
| 2659 | |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 2660 | if (!iter->snapshot) |
| 2661 | /* reenable tracing if it was previously enabled */ |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 2662 | tracing_start_tr(tr); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2663 | mutex_unlock(&trace_types_lock); |
| 2664 | |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 2665 | mutex_destroy(&iter->mutex); |
Frederic Weisbecker | b0dfa97 | 2009-04-01 22:53:08 +0200 | [diff] [blame] | 2666 | free_cpumask_var(iter->started); |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 2667 | kfree(iter->trace); |
Steven Rostedt | 6d158a8 | 2012-06-27 20:46:14 -0400 | [diff] [blame] | 2668 | kfree(iter->buffer_iter); |
Jiri Olsa | 50e18b9 | 2012-04-25 10:23:39 +0200 | [diff] [blame] | 2669 | seq_release_private(inode, file); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2670 | return 0; |
| 2671 | } |
| 2672 | |
| 2673 | static int tracing_open(struct inode *inode, struct file *file) |
| 2674 | { |
Steven Rostedt | 85a2f9b | 2009-02-27 00:12:38 -0500 | [diff] [blame] | 2675 | struct trace_iterator *iter; |
| 2676 | int ret = 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2677 | |
Steven Rostedt | 4acd4d0 | 2009-03-18 10:40:24 -0400 | [diff] [blame] | 2678 | /* If this file was open for write, then erase contents */ |
| 2679 | if ((file->f_mode & FMODE_WRITE) && |
Steven Rostedt | 8650ae3 | 2009-07-22 23:29:30 -0400 | [diff] [blame] | 2680 | (file->f_flags & O_TRUNC)) { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 2681 | struct trace_cpu *tc = inode->i_private; |
| 2682 | struct trace_array *tr = tc->tr; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2683 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 2684 | if (tc->cpu == RING_BUFFER_ALL_CPUS) |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2685 | tracing_reset_online_cpus(&tr->trace_buffer); |
Steven Rostedt | 4acd4d0 | 2009-03-18 10:40:24 -0400 | [diff] [blame] | 2686 | else |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2687 | tracing_reset(&tr->trace_buffer, tc->cpu); |
Steven Rostedt | 4acd4d0 | 2009-03-18 10:40:24 -0400 | [diff] [blame] | 2688 | } |
| 2689 | |
| 2690 | if (file->f_mode & FMODE_READ) { |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 2691 | iter = __tracing_open(inode, file, false); |
Steven Rostedt | 4acd4d0 | 2009-03-18 10:40:24 -0400 | [diff] [blame] | 2692 | if (IS_ERR(iter)) |
| 2693 | ret = PTR_ERR(iter); |
| 2694 | else if (trace_flags & TRACE_ITER_LATENCY_FMT) |
| 2695 | iter->iter_flags |= TRACE_FILE_LAT_FMT; |
| 2696 | } |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2697 | return ret; |
| 2698 | } |
| 2699 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 2700 | static void * |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2701 | t_next(struct seq_file *m, void *v, loff_t *pos) |
| 2702 | { |
Li Zefan | f129e96 | 2009-06-24 09:53:44 +0800 | [diff] [blame] | 2703 | struct tracer *t = v; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2704 | |
| 2705 | (*pos)++; |
| 2706 | |
| 2707 | if (t) |
| 2708 | t = t->next; |
| 2709 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2710 | return t; |
| 2711 | } |
| 2712 | |
| 2713 | static void *t_start(struct seq_file *m, loff_t *pos) |
| 2714 | { |
Li Zefan | f129e96 | 2009-06-24 09:53:44 +0800 | [diff] [blame] | 2715 | struct tracer *t; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2716 | loff_t l = 0; |
| 2717 | |
| 2718 | mutex_lock(&trace_types_lock); |
Li Zefan | f129e96 | 2009-06-24 09:53:44 +0800 | [diff] [blame] | 2719 | 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] | 2720 | ; |
| 2721 | |
| 2722 | return t; |
| 2723 | } |
| 2724 | |
| 2725 | static void t_stop(struct seq_file *m, void *p) |
| 2726 | { |
| 2727 | mutex_unlock(&trace_types_lock); |
| 2728 | } |
| 2729 | |
| 2730 | static int t_show(struct seq_file *m, void *v) |
| 2731 | { |
| 2732 | struct tracer *t = v; |
| 2733 | |
| 2734 | if (!t) |
| 2735 | return 0; |
| 2736 | |
| 2737 | seq_printf(m, "%s", t->name); |
| 2738 | if (t->next) |
| 2739 | seq_putc(m, ' '); |
| 2740 | else |
| 2741 | seq_putc(m, '\n'); |
| 2742 | |
| 2743 | return 0; |
| 2744 | } |
| 2745 | |
James Morris | 88e9d34 | 2009-09-22 16:43:43 -0700 | [diff] [blame] | 2746 | static const struct seq_operations show_traces_seq_ops = { |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2747 | .start = t_start, |
| 2748 | .next = t_next, |
| 2749 | .stop = t_stop, |
| 2750 | .show = t_show, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2751 | }; |
| 2752 | |
| 2753 | static int show_traces_open(struct inode *inode, struct file *file) |
| 2754 | { |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 2755 | if (tracing_disabled) |
| 2756 | return -ENODEV; |
| 2757 | |
Li Zefan | f129e96 | 2009-06-24 09:53:44 +0800 | [diff] [blame] | 2758 | return seq_open(file, &show_traces_seq_ops); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2759 | } |
| 2760 | |
Steven Rostedt | 4acd4d0 | 2009-03-18 10:40:24 -0400 | [diff] [blame] | 2761 | static ssize_t |
| 2762 | tracing_write_stub(struct file *filp, const char __user *ubuf, |
| 2763 | size_t count, loff_t *ppos) |
| 2764 | { |
| 2765 | return count; |
| 2766 | } |
| 2767 | |
Slava Pestov | 364829b | 2010-11-24 15:13:16 -0800 | [diff] [blame] | 2768 | static loff_t tracing_seek(struct file *file, loff_t offset, int origin) |
| 2769 | { |
| 2770 | if (file->f_mode & FMODE_READ) |
| 2771 | return seq_lseek(file, offset, origin); |
| 2772 | else |
| 2773 | return 0; |
| 2774 | } |
| 2775 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 2776 | static const struct file_operations tracing_fops = { |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2777 | .open = tracing_open, |
| 2778 | .read = seq_read, |
Steven Rostedt | 4acd4d0 | 2009-03-18 10:40:24 -0400 | [diff] [blame] | 2779 | .write = tracing_write_stub, |
Slava Pestov | 364829b | 2010-11-24 15:13:16 -0800 | [diff] [blame] | 2780 | .llseek = tracing_seek, |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2781 | .release = tracing_release, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2782 | }; |
| 2783 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 2784 | static const struct file_operations show_traces_fops = { |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2785 | .open = show_traces_open, |
| 2786 | .read = seq_read, |
| 2787 | .release = seq_release, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 2788 | .llseek = seq_lseek, |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2789 | }; |
| 2790 | |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2791 | /* |
| 2792 | * Only trace on a CPU if the bitmask is set: |
| 2793 | */ |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 2794 | static cpumask_var_t tracing_cpumask; |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2795 | |
| 2796 | /* |
| 2797 | * The tracer itself will not take this lock, but still we want |
| 2798 | * to provide a consistent cpumask to user-space: |
| 2799 | */ |
| 2800 | static DEFINE_MUTEX(tracing_cpumask_update_lock); |
| 2801 | |
| 2802 | /* |
| 2803 | * Temporary storage for the character representation of the |
| 2804 | * CPU bitmask (and one more byte for the newline): |
| 2805 | */ |
| 2806 | static char mask_str[NR_CPUS + 1]; |
| 2807 | |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2808 | static ssize_t |
| 2809 | tracing_cpumask_read(struct file *filp, char __user *ubuf, |
| 2810 | size_t count, loff_t *ppos) |
| 2811 | { |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2812 | int len; |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2813 | |
| 2814 | mutex_lock(&tracing_cpumask_update_lock); |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2815 | |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 2816 | len = cpumask_scnprintf(mask_str, count, tracing_cpumask); |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2817 | if (count - len < 2) { |
| 2818 | count = -EINVAL; |
| 2819 | goto out_err; |
| 2820 | } |
| 2821 | len += sprintf(mask_str + len, "\n"); |
| 2822 | count = simple_read_from_buffer(ubuf, count, ppos, mask_str, NR_CPUS+1); |
| 2823 | |
| 2824 | out_err: |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2825 | mutex_unlock(&tracing_cpumask_update_lock); |
| 2826 | |
| 2827 | return count; |
| 2828 | } |
| 2829 | |
| 2830 | static ssize_t |
| 2831 | tracing_cpumask_write(struct file *filp, const char __user *ubuf, |
| 2832 | size_t count, loff_t *ppos) |
| 2833 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 2834 | struct trace_array *tr = filp->private_data; |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 2835 | cpumask_var_t tracing_cpumask_new; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 2836 | int err, cpu; |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 2837 | |
| 2838 | if (!alloc_cpumask_var(&tracing_cpumask_new, GFP_KERNEL)) |
| 2839 | return -ENOMEM; |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2840 | |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 2841 | err = cpumask_parse_user(ubuf, count, tracing_cpumask_new); |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2842 | if (err) |
| 2843 | goto err_unlock; |
| 2844 | |
Li Zefan | 215368e | 2009-06-15 10:56:42 +0800 | [diff] [blame] | 2845 | mutex_lock(&tracing_cpumask_update_lock); |
| 2846 | |
Steven Rostedt | a5e2588 | 2008-12-02 15:34:05 -0500 | [diff] [blame] | 2847 | local_irq_disable(); |
Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 2848 | arch_spin_lock(&ftrace_max_lock); |
Steven Rostedt | ab46428 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 2849 | for_each_tracing_cpu(cpu) { |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2850 | /* |
| 2851 | * Increase/decrease the disabled counter if we are |
| 2852 | * about to flip a bit in the cpumask: |
| 2853 | */ |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 2854 | if (cpumask_test_cpu(cpu, tracing_cpumask) && |
| 2855 | !cpumask_test_cpu(cpu, tracing_cpumask_new)) { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2856 | atomic_inc(&per_cpu_ptr(tr->trace_buffer.data, cpu)->disabled); |
| 2857 | ring_buffer_record_disable_cpu(tr->trace_buffer.buffer, cpu); |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2858 | } |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 2859 | if (!cpumask_test_cpu(cpu, tracing_cpumask) && |
| 2860 | cpumask_test_cpu(cpu, tracing_cpumask_new)) { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2861 | atomic_dec(&per_cpu_ptr(tr->trace_buffer.data, cpu)->disabled); |
| 2862 | ring_buffer_record_enable_cpu(tr->trace_buffer.buffer, cpu); |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2863 | } |
| 2864 | } |
Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 2865 | arch_spin_unlock(&ftrace_max_lock); |
Steven Rostedt | a5e2588 | 2008-12-02 15:34:05 -0500 | [diff] [blame] | 2866 | local_irq_enable(); |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2867 | |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 2868 | cpumask_copy(tracing_cpumask, tracing_cpumask_new); |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2869 | |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2870 | mutex_unlock(&tracing_cpumask_update_lock); |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 2871 | free_cpumask_var(tracing_cpumask_new); |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2872 | |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2873 | return count; |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2874 | |
| 2875 | err_unlock: |
Li Zefan | 215368e | 2009-06-15 10:56:42 +0800 | [diff] [blame] | 2876 | free_cpumask_var(tracing_cpumask_new); |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2877 | |
| 2878 | return err; |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2879 | } |
| 2880 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 2881 | static const struct file_operations tracing_cpumask_fops = { |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2882 | .open = tracing_open_generic, |
| 2883 | .read = tracing_cpumask_read, |
| 2884 | .write = tracing_cpumask_write, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 2885 | .llseek = generic_file_llseek, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2886 | }; |
| 2887 | |
Li Zefan | fdb372e | 2009-12-08 11:15:59 +0800 | [diff] [blame] | 2888 | static int tracing_trace_options_show(struct seq_file *m, void *v) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2889 | { |
Steven Rostedt | d8e83d2 | 2009-02-26 23:55:58 -0500 | [diff] [blame] | 2890 | struct tracer_opt *trace_opts; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 2891 | struct trace_array *tr = m->private; |
Steven Rostedt | d8e83d2 | 2009-02-26 23:55:58 -0500 | [diff] [blame] | 2892 | u32 tracer_flags; |
Steven Rostedt | d8e83d2 | 2009-02-26 23:55:58 -0500 | [diff] [blame] | 2893 | int i; |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 2894 | |
Steven Rostedt | d8e83d2 | 2009-02-26 23:55:58 -0500 | [diff] [blame] | 2895 | mutex_lock(&trace_types_lock); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 2896 | tracer_flags = tr->current_trace->flags->val; |
| 2897 | trace_opts = tr->current_trace->flags->opts; |
Steven Rostedt | d8e83d2 | 2009-02-26 23:55:58 -0500 | [diff] [blame] | 2898 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2899 | for (i = 0; trace_options[i]; i++) { |
| 2900 | if (trace_flags & (1 << i)) |
Li Zefan | fdb372e | 2009-12-08 11:15:59 +0800 | [diff] [blame] | 2901 | seq_printf(m, "%s\n", trace_options[i]); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2902 | else |
Li Zefan | fdb372e | 2009-12-08 11:15:59 +0800 | [diff] [blame] | 2903 | seq_printf(m, "no%s\n", trace_options[i]); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2904 | } |
| 2905 | |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 2906 | for (i = 0; trace_opts[i].name; i++) { |
| 2907 | if (tracer_flags & trace_opts[i].bit) |
Li Zefan | fdb372e | 2009-12-08 11:15:59 +0800 | [diff] [blame] | 2908 | seq_printf(m, "%s\n", trace_opts[i].name); |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 2909 | else |
Li Zefan | fdb372e | 2009-12-08 11:15:59 +0800 | [diff] [blame] | 2910 | seq_printf(m, "no%s\n", trace_opts[i].name); |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 2911 | } |
Steven Rostedt | d8e83d2 | 2009-02-26 23:55:58 -0500 | [diff] [blame] | 2912 | mutex_unlock(&trace_types_lock); |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 2913 | |
Li Zefan | fdb372e | 2009-12-08 11:15:59 +0800 | [diff] [blame] | 2914 | return 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2915 | } |
| 2916 | |
Li Zefan | 8d18eaa | 2009-12-08 11:17:06 +0800 | [diff] [blame] | 2917 | static int __set_tracer_option(struct tracer *trace, |
| 2918 | struct tracer_flags *tracer_flags, |
| 2919 | struct tracer_opt *opts, int neg) |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 2920 | { |
Li Zefan | 8d18eaa | 2009-12-08 11:17:06 +0800 | [diff] [blame] | 2921 | int ret; |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 2922 | |
Li Zefan | 8d18eaa | 2009-12-08 11:17:06 +0800 | [diff] [blame] | 2923 | ret = trace->set_flag(tracer_flags->val, opts->bit, !neg); |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 2924 | if (ret) |
| 2925 | return ret; |
| 2926 | |
| 2927 | if (neg) |
Zhaolei | 7770841 | 2009-08-07 18:53:21 +0800 | [diff] [blame] | 2928 | tracer_flags->val &= ~opts->bit; |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 2929 | else |
Zhaolei | 7770841 | 2009-08-07 18:53:21 +0800 | [diff] [blame] | 2930 | tracer_flags->val |= opts->bit; |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 2931 | return 0; |
| 2932 | } |
| 2933 | |
Li Zefan | 8d18eaa | 2009-12-08 11:17:06 +0800 | [diff] [blame] | 2934 | /* Try to assign a tracer specific option */ |
| 2935 | static int set_tracer_option(struct tracer *trace, char *cmp, int neg) |
| 2936 | { |
| 2937 | struct tracer_flags *tracer_flags = trace->flags; |
| 2938 | struct tracer_opt *opts = NULL; |
| 2939 | int i; |
| 2940 | |
| 2941 | for (i = 0; tracer_flags->opts[i].name; i++) { |
| 2942 | opts = &tracer_flags->opts[i]; |
| 2943 | |
| 2944 | if (strcmp(cmp, opts->name) == 0) |
| 2945 | return __set_tracer_option(trace, trace->flags, |
| 2946 | opts, neg); |
| 2947 | } |
| 2948 | |
| 2949 | return -EINVAL; |
| 2950 | } |
| 2951 | |
Steven Rostedt (Red Hat) | 613f04a | 2013-03-14 15:03:53 -0400 | [diff] [blame] | 2952 | /* Some tracers require overwrite to stay enabled */ |
| 2953 | int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set) |
| 2954 | { |
| 2955 | if (tracer->enabled && (mask & TRACE_ITER_OVERWRITE) && !set) |
| 2956 | return -1; |
| 2957 | |
| 2958 | return 0; |
| 2959 | } |
| 2960 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 2961 | 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] | 2962 | { |
| 2963 | /* do nothing if flag is already set */ |
| 2964 | if (!!(trace_flags & mask) == !!enabled) |
Steven Rostedt (Red Hat) | 613f04a | 2013-03-14 15:03:53 -0400 | [diff] [blame] | 2965 | return 0; |
| 2966 | |
| 2967 | /* Give the tracer a chance to approve the change */ |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 2968 | if (tr->current_trace->flag_changed) |
| 2969 | 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] | 2970 | return -EINVAL; |
Steven Rostedt | af4617b | 2009-03-17 18:09:55 -0400 | [diff] [blame] | 2971 | |
| 2972 | if (enabled) |
| 2973 | trace_flags |= mask; |
| 2974 | else |
| 2975 | trace_flags &= ~mask; |
Li Zefan | e870e9a | 2010-07-02 11:07:32 +0800 | [diff] [blame] | 2976 | |
| 2977 | if (mask == TRACE_ITER_RECORD_CMD) |
| 2978 | trace_event_enable_cmd_record(enabled); |
David Sharp | 750912f | 2010-12-08 13:46:47 -0800 | [diff] [blame] | 2979 | |
Steven Rostedt (Red Hat) | 8090282 | 2013-03-14 14:20:54 -0400 | [diff] [blame] | 2980 | if (mask == TRACE_ITER_OVERWRITE) { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2981 | ring_buffer_change_overwrite(tr->trace_buffer.buffer, enabled); |
Steven Rostedt (Red Hat) | 8090282 | 2013-03-14 14:20:54 -0400 | [diff] [blame] | 2982 | #ifdef CONFIG_TRACER_MAX_TRACE |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2983 | ring_buffer_change_overwrite(tr->max_buffer.buffer, enabled); |
Steven Rostedt (Red Hat) | 8090282 | 2013-03-14 14:20:54 -0400 | [diff] [blame] | 2984 | #endif |
| 2985 | } |
Steven Rostedt | 8169883 | 2012-10-11 10:15:05 -0400 | [diff] [blame] | 2986 | |
| 2987 | if (mask == TRACE_ITER_PRINTK) |
| 2988 | trace_printk_start_stop_comm(enabled); |
Steven Rostedt (Red Hat) | 613f04a | 2013-03-14 15:03:53 -0400 | [diff] [blame] | 2989 | |
| 2990 | return 0; |
Steven Rostedt | af4617b | 2009-03-17 18:09:55 -0400 | [diff] [blame] | 2991 | } |
| 2992 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 2993 | static int trace_set_options(struct trace_array *tr, char *option) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2994 | { |
Li Zefan | 8d18eaa | 2009-12-08 11:17:06 +0800 | [diff] [blame] | 2995 | char *cmp; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2996 | int neg = 0; |
Steven Rostedt (Red Hat) | 613f04a | 2013-03-14 15:03:53 -0400 | [diff] [blame] | 2997 | int ret = -ENODEV; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2998 | int i; |
| 2999 | |
Steven Rostedt | 7bcfaf5 | 2012-11-01 22:56:07 -0400 | [diff] [blame] | 3000 | cmp = strstrip(option); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3001 | |
Li Zefan | 8d18eaa | 2009-12-08 11:17:06 +0800 | [diff] [blame] | 3002 | if (strncmp(cmp, "no", 2) == 0) { |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3003 | neg = 1; |
| 3004 | cmp += 2; |
| 3005 | } |
| 3006 | |
Steven Rostedt (Red Hat) | 69d34da | 2013-03-14 13:50:56 -0400 | [diff] [blame] | 3007 | mutex_lock(&trace_types_lock); |
| 3008 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3009 | for (i = 0; trace_options[i]; i++) { |
Li Zefan | 8d18eaa | 2009-12-08 11:17:06 +0800 | [diff] [blame] | 3010 | if (strcmp(cmp, trace_options[i]) == 0) { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3011 | ret = set_tracer_flag(tr, 1 << i, !neg); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3012 | break; |
| 3013 | } |
| 3014 | } |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 3015 | |
| 3016 | /* 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] | 3017 | if (!trace_options[i]) |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3018 | ret = set_tracer_option(tr->current_trace, cmp, neg); |
Steven Rostedt (Red Hat) | 69d34da | 2013-03-14 13:50:56 -0400 | [diff] [blame] | 3019 | |
| 3020 | mutex_unlock(&trace_types_lock); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3021 | |
Steven Rostedt | 7bcfaf5 | 2012-11-01 22:56:07 -0400 | [diff] [blame] | 3022 | return ret; |
| 3023 | } |
| 3024 | |
| 3025 | static ssize_t |
| 3026 | tracing_trace_options_write(struct file *filp, const char __user *ubuf, |
| 3027 | size_t cnt, loff_t *ppos) |
| 3028 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3029 | struct seq_file *m = filp->private_data; |
| 3030 | struct trace_array *tr = m->private; |
Steven Rostedt | 7bcfaf5 | 2012-11-01 22:56:07 -0400 | [diff] [blame] | 3031 | char buf[64]; |
Steven Rostedt (Red Hat) | 613f04a | 2013-03-14 15:03:53 -0400 | [diff] [blame] | 3032 | int ret; |
Steven Rostedt | 7bcfaf5 | 2012-11-01 22:56:07 -0400 | [diff] [blame] | 3033 | |
| 3034 | if (cnt >= sizeof(buf)) |
| 3035 | return -EINVAL; |
| 3036 | |
| 3037 | if (copy_from_user(&buf, ubuf, cnt)) |
| 3038 | return -EFAULT; |
| 3039 | |
Steven Rostedt | a8dd217 | 2013-01-09 20:54:17 -0500 | [diff] [blame] | 3040 | buf[cnt] = 0; |
| 3041 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3042 | ret = trace_set_options(tr, buf); |
Steven Rostedt (Red Hat) | 613f04a | 2013-03-14 15:03:53 -0400 | [diff] [blame] | 3043 | if (ret < 0) |
| 3044 | return ret; |
Steven Rostedt | 7bcfaf5 | 2012-11-01 22:56:07 -0400 | [diff] [blame] | 3045 | |
Jiri Olsa | cf8517c | 2009-10-23 19:36:16 -0400 | [diff] [blame] | 3046 | *ppos += cnt; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3047 | |
| 3048 | return cnt; |
| 3049 | } |
| 3050 | |
Li Zefan | fdb372e | 2009-12-08 11:15:59 +0800 | [diff] [blame] | 3051 | static int tracing_trace_options_open(struct inode *inode, struct file *file) |
| 3052 | { |
| 3053 | if (tracing_disabled) |
| 3054 | return -ENODEV; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3055 | |
| 3056 | return single_open(file, tracing_trace_options_show, inode->i_private); |
Li Zefan | fdb372e | 2009-12-08 11:15:59 +0800 | [diff] [blame] | 3057 | } |
| 3058 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 3059 | static const struct file_operations tracing_iter_fops = { |
Li Zefan | fdb372e | 2009-12-08 11:15:59 +0800 | [diff] [blame] | 3060 | .open = tracing_trace_options_open, |
| 3061 | .read = seq_read, |
| 3062 | .llseek = seq_lseek, |
| 3063 | .release = single_release, |
Steven Rostedt | ee6bce5 | 2008-11-12 17:52:37 -0500 | [diff] [blame] | 3064 | .write = tracing_trace_options_write, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3065 | }; |
| 3066 | |
Ingo Molnar | 7bd2f24 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 3067 | static const char readme_msg[] = |
| 3068 | "tracing mini-HOWTO:\n\n" |
GeunSik Lim | 156f5a7 | 2009-06-02 15:01:37 +0900 | [diff] [blame] | 3069 | "# mount -t debugfs nodev /sys/kernel/debug\n\n" |
| 3070 | "# cat /sys/kernel/debug/tracing/available_tracers\n" |
Geunsik Lim | 1e42e83 | 2012-02-08 19:05:36 +0900 | [diff] [blame] | 3071 | "wakeup wakeup_rt preemptirqsoff preemptoff irqsoff function nop\n\n" |
GeunSik Lim | 156f5a7 | 2009-06-02 15:01:37 +0900 | [diff] [blame] | 3072 | "# cat /sys/kernel/debug/tracing/current_tracer\n" |
Nikanth Karthikesan | bc2b687 | 2009-03-23 11:58:31 +0530 | [diff] [blame] | 3073 | "nop\n" |
Geunsik Lim | 1e42e83 | 2012-02-08 19:05:36 +0900 | [diff] [blame] | 3074 | "# echo wakeup > /sys/kernel/debug/tracing/current_tracer\n" |
GeunSik Lim | 156f5a7 | 2009-06-02 15:01:37 +0900 | [diff] [blame] | 3075 | "# cat /sys/kernel/debug/tracing/current_tracer\n" |
Geunsik Lim | 1e42e83 | 2012-02-08 19:05:36 +0900 | [diff] [blame] | 3076 | "wakeup\n" |
GeunSik Lim | 156f5a7 | 2009-06-02 15:01:37 +0900 | [diff] [blame] | 3077 | "# cat /sys/kernel/debug/tracing/trace_options\n" |
Ingo Molnar | 7bd2f24 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 3078 | "noprint-parent nosym-offset nosym-addr noverbose\n" |
GeunSik Lim | 156f5a7 | 2009-06-02 15:01:37 +0900 | [diff] [blame] | 3079 | "# echo print-parent > /sys/kernel/debug/tracing/trace_options\n" |
Geunsik Lim | 9b5f8b3 | 2011-08-12 14:30:22 +0900 | [diff] [blame] | 3080 | "# echo 1 > /sys/kernel/debug/tracing/tracing_on\n" |
GeunSik Lim | 156f5a7 | 2009-06-02 15:01:37 +0900 | [diff] [blame] | 3081 | "# cat /sys/kernel/debug/tracing/trace > /tmp/trace.txt\n" |
Geunsik Lim | 9b5f8b3 | 2011-08-12 14:30:22 +0900 | [diff] [blame] | 3082 | "# echo 0 > /sys/kernel/debug/tracing/tracing_on\n" |
Ingo Molnar | 7bd2f24 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 3083 | ; |
| 3084 | |
| 3085 | static ssize_t |
| 3086 | tracing_readme_read(struct file *filp, char __user *ubuf, |
| 3087 | size_t cnt, loff_t *ppos) |
| 3088 | { |
| 3089 | return simple_read_from_buffer(ubuf, cnt, ppos, |
| 3090 | readme_msg, strlen(readme_msg)); |
| 3091 | } |
| 3092 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 3093 | static const struct file_operations tracing_readme_fops = { |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3094 | .open = tracing_open_generic, |
| 3095 | .read = tracing_readme_read, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 3096 | .llseek = generic_file_llseek, |
Ingo Molnar | 7bd2f24 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 3097 | }; |
| 3098 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3099 | static ssize_t |
Avadh Patel | 69abe6a | 2009-04-10 16:04:48 -0400 | [diff] [blame] | 3100 | tracing_saved_cmdlines_read(struct file *file, char __user *ubuf, |
| 3101 | size_t cnt, loff_t *ppos) |
| 3102 | { |
| 3103 | char *buf_comm; |
| 3104 | char *file_buf; |
| 3105 | char *buf; |
| 3106 | int len = 0; |
| 3107 | int pid; |
| 3108 | int i; |
| 3109 | |
| 3110 | file_buf = kmalloc(SAVED_CMDLINES*(16+TASK_COMM_LEN), GFP_KERNEL); |
| 3111 | if (!file_buf) |
| 3112 | return -ENOMEM; |
| 3113 | |
| 3114 | buf_comm = kmalloc(TASK_COMM_LEN, GFP_KERNEL); |
| 3115 | if (!buf_comm) { |
| 3116 | kfree(file_buf); |
| 3117 | return -ENOMEM; |
| 3118 | } |
| 3119 | |
| 3120 | buf = file_buf; |
| 3121 | |
| 3122 | for (i = 0; i < SAVED_CMDLINES; i++) { |
| 3123 | int r; |
| 3124 | |
| 3125 | pid = map_cmdline_to_pid[i]; |
| 3126 | if (pid == -1 || pid == NO_CMDLINE_MAP) |
| 3127 | continue; |
| 3128 | |
| 3129 | trace_find_cmdline(pid, buf_comm); |
| 3130 | r = sprintf(buf, "%d %s\n", pid, buf_comm); |
| 3131 | buf += r; |
| 3132 | len += r; |
| 3133 | } |
| 3134 | |
| 3135 | len = simple_read_from_buffer(ubuf, cnt, ppos, |
| 3136 | file_buf, len); |
| 3137 | |
| 3138 | kfree(file_buf); |
| 3139 | kfree(buf_comm); |
| 3140 | |
| 3141 | return len; |
| 3142 | } |
| 3143 | |
| 3144 | static const struct file_operations tracing_saved_cmdlines_fops = { |
| 3145 | .open = tracing_open_generic, |
| 3146 | .read = tracing_saved_cmdlines_read, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 3147 | .llseek = generic_file_llseek, |
Avadh Patel | 69abe6a | 2009-04-10 16:04:48 -0400 | [diff] [blame] | 3148 | }; |
| 3149 | |
| 3150 | static ssize_t |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3151 | tracing_set_trace_read(struct file *filp, char __user *ubuf, |
| 3152 | size_t cnt, loff_t *ppos) |
| 3153 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3154 | struct trace_array *tr = filp->private_data; |
Li Zefan | ee6c2c1 | 2009-09-18 14:06:47 +0800 | [diff] [blame] | 3155 | char buf[MAX_TRACER_SIZE+2]; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3156 | int r; |
| 3157 | |
| 3158 | mutex_lock(&trace_types_lock); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3159 | r = sprintf(buf, "%s\n", tr->current_trace->name); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3160 | mutex_unlock(&trace_types_lock); |
| 3161 | |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3162 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, r); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3163 | } |
| 3164 | |
Arnaldo Carvalho de Melo | b6f11df | 2009-02-05 18:02:00 -0200 | [diff] [blame] | 3165 | int tracer_init(struct tracer *t, struct trace_array *tr) |
| 3166 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3167 | tracing_reset_online_cpus(&tr->trace_buffer); |
Arnaldo Carvalho de Melo | b6f11df | 2009-02-05 18:02:00 -0200 | [diff] [blame] | 3168 | return t->init(tr); |
| 3169 | } |
| 3170 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3171 | static void set_buffer_entries(struct trace_buffer *buf, unsigned long val) |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 3172 | { |
| 3173 | int cpu; |
Steven Rostedt (Red Hat) | 737223f | 2013-03-05 21:13:47 -0500 | [diff] [blame^] | 3174 | |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 3175 | for_each_tracing_cpu(cpu) |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3176 | per_cpu_ptr(buf->data, cpu)->entries = val; |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 3177 | } |
| 3178 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3179 | #ifdef CONFIG_TRACER_MAX_TRACE |
Hiraku Toyooka | d60da50 | 2012-10-17 11:56:16 +0900 | [diff] [blame] | 3180 | /* 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] | 3181 | static int resize_buffer_duplicate_size(struct trace_buffer *trace_buf, |
| 3182 | struct trace_buffer *size_buf, int cpu_id) |
Hiraku Toyooka | d60da50 | 2012-10-17 11:56:16 +0900 | [diff] [blame] | 3183 | { |
| 3184 | int cpu, ret = 0; |
| 3185 | |
| 3186 | if (cpu_id == RING_BUFFER_ALL_CPUS) { |
| 3187 | for_each_tracing_cpu(cpu) { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3188 | ret = ring_buffer_resize(trace_buf->buffer, |
| 3189 | per_cpu_ptr(size_buf->data, cpu)->entries, cpu); |
Hiraku Toyooka | d60da50 | 2012-10-17 11:56:16 +0900 | [diff] [blame] | 3190 | if (ret < 0) |
| 3191 | break; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3192 | per_cpu_ptr(trace_buf->data, cpu)->entries = |
| 3193 | per_cpu_ptr(size_buf->data, cpu)->entries; |
Hiraku Toyooka | d60da50 | 2012-10-17 11:56:16 +0900 | [diff] [blame] | 3194 | } |
| 3195 | } else { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3196 | ret = ring_buffer_resize(trace_buf->buffer, |
| 3197 | per_cpu_ptr(size_buf->data, cpu_id)->entries, cpu_id); |
Hiraku Toyooka | d60da50 | 2012-10-17 11:56:16 +0900 | [diff] [blame] | 3198 | if (ret == 0) |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3199 | per_cpu_ptr(trace_buf->data, cpu_id)->entries = |
| 3200 | per_cpu_ptr(size_buf->data, cpu_id)->entries; |
Hiraku Toyooka | d60da50 | 2012-10-17 11:56:16 +0900 | [diff] [blame] | 3201 | } |
| 3202 | |
| 3203 | return ret; |
| 3204 | } |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3205 | #endif /* CONFIG_TRACER_MAX_TRACE */ |
Hiraku Toyooka | d60da50 | 2012-10-17 11:56:16 +0900 | [diff] [blame] | 3206 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3207 | static int __tracing_resize_ring_buffer(struct trace_array *tr, |
| 3208 | unsigned long size, int cpu) |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 3209 | { |
| 3210 | int ret; |
| 3211 | |
| 3212 | /* |
| 3213 | * If kernel or user changes the size of the ring buffer |
Steven Rostedt | a123c52 | 2009-03-12 11:21:08 -0400 | [diff] [blame] | 3214 | * we use the size that was given, and we can forget about |
| 3215 | * expanding it later. |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 3216 | */ |
| 3217 | ring_buffer_expanded = 1; |
| 3218 | |
Steven Rostedt | b382ede6 | 2012-10-10 21:44:34 -0400 | [diff] [blame] | 3219 | /* May be called before buffers are initialized */ |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3220 | if (!tr->trace_buffer.buffer) |
Steven Rostedt | b382ede6 | 2012-10-10 21:44:34 -0400 | [diff] [blame] | 3221 | return 0; |
| 3222 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3223 | ret = ring_buffer_resize(tr->trace_buffer.buffer, size, cpu); |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 3224 | if (ret < 0) |
| 3225 | return ret; |
| 3226 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3227 | #ifdef CONFIG_TRACER_MAX_TRACE |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3228 | if (!(tr->flags & TRACE_ARRAY_FL_GLOBAL) || |
| 3229 | !tr->current_trace->use_max_tr) |
KOSAKI Motohiro | ef710e1 | 2010-07-01 14:34:35 +0900 | [diff] [blame] | 3230 | goto out; |
| 3231 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3232 | ret = ring_buffer_resize(tr->max_buffer.buffer, size, cpu); |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 3233 | if (ret < 0) { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3234 | int r = resize_buffer_duplicate_size(&tr->trace_buffer, |
| 3235 | &tr->trace_buffer, cpu); |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 3236 | if (r < 0) { |
Steven Rostedt | a123c52 | 2009-03-12 11:21:08 -0400 | [diff] [blame] | 3237 | /* |
| 3238 | * AARGH! We are left with different |
| 3239 | * size max buffer!!!! |
| 3240 | * The max buffer is our "snapshot" buffer. |
| 3241 | * When a tracer needs a snapshot (one of the |
| 3242 | * latency tracers), it swaps the max buffer |
| 3243 | * with the saved snap shot. We succeeded to |
| 3244 | * update the size of the main buffer, but failed to |
| 3245 | * update the size of the max buffer. But when we tried |
| 3246 | * to reset the main buffer to the original size, we |
| 3247 | * failed there too. This is very unlikely to |
| 3248 | * happen, but if it does, warn and kill all |
| 3249 | * tracing. |
| 3250 | */ |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 3251 | WARN_ON(1); |
| 3252 | tracing_disabled = 1; |
| 3253 | } |
| 3254 | return ret; |
| 3255 | } |
| 3256 | |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 3257 | if (cpu == RING_BUFFER_ALL_CPUS) |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3258 | set_buffer_entries(&tr->max_buffer, size); |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 3259 | else |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3260 | per_cpu_ptr(tr->max_buffer.data, cpu)->entries = size; |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 3261 | |
KOSAKI Motohiro | ef710e1 | 2010-07-01 14:34:35 +0900 | [diff] [blame] | 3262 | out: |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3263 | #endif /* CONFIG_TRACER_MAX_TRACE */ |
| 3264 | |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 3265 | if (cpu == RING_BUFFER_ALL_CPUS) |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3266 | set_buffer_entries(&tr->trace_buffer, size); |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 3267 | else |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3268 | per_cpu_ptr(tr->trace_buffer.data, cpu)->entries = size; |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 3269 | |
| 3270 | return ret; |
| 3271 | } |
| 3272 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3273 | static ssize_t tracing_resize_ring_buffer(struct trace_array *tr, |
| 3274 | unsigned long size, int cpu_id) |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 3275 | { |
Vaibhav Nagarnaik | 83f4031 | 2012-05-03 18:59:50 -0700 | [diff] [blame] | 3276 | int ret = size; |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 3277 | |
| 3278 | mutex_lock(&trace_types_lock); |
| 3279 | |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 3280 | if (cpu_id != RING_BUFFER_ALL_CPUS) { |
| 3281 | /* make sure, this cpu is enabled in the mask */ |
| 3282 | if (!cpumask_test_cpu(cpu_id, tracing_buffer_mask)) { |
| 3283 | ret = -EINVAL; |
| 3284 | goto out; |
| 3285 | } |
| 3286 | } |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 3287 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3288 | ret = __tracing_resize_ring_buffer(tr, size, cpu_id); |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 3289 | if (ret < 0) |
| 3290 | ret = -ENOMEM; |
| 3291 | |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 3292 | out: |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 3293 | mutex_unlock(&trace_types_lock); |
| 3294 | |
| 3295 | return ret; |
| 3296 | } |
| 3297 | |
KOSAKI Motohiro | ef710e1 | 2010-07-01 14:34:35 +0900 | [diff] [blame] | 3298 | |
Steven Rostedt | 1852fcc | 2009-03-11 14:33:00 -0400 | [diff] [blame] | 3299 | /** |
| 3300 | * tracing_update_buffers - used by tracing facility to expand ring buffers |
| 3301 | * |
| 3302 | * To save on memory when the tracing is never used on a system with it |
| 3303 | * configured in. The ring buffers are set to a minimum size. But once |
| 3304 | * a user starts to use the tracing facility, then they need to grow |
| 3305 | * to their default size. |
| 3306 | * |
| 3307 | * This function is to be called when a tracer is about to be used. |
| 3308 | */ |
| 3309 | int tracing_update_buffers(void) |
| 3310 | { |
| 3311 | int ret = 0; |
| 3312 | |
Steven Rostedt | 1027fcb | 2009-03-12 11:33:20 -0400 | [diff] [blame] | 3313 | mutex_lock(&trace_types_lock); |
Steven Rostedt | 1852fcc | 2009-03-11 14:33:00 -0400 | [diff] [blame] | 3314 | if (!ring_buffer_expanded) |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3315 | ret = __tracing_resize_ring_buffer(&global_trace, trace_buf_size, |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 3316 | RING_BUFFER_ALL_CPUS); |
Steven Rostedt | 1027fcb | 2009-03-12 11:33:20 -0400 | [diff] [blame] | 3317 | mutex_unlock(&trace_types_lock); |
Steven Rostedt | 1852fcc | 2009-03-11 14:33:00 -0400 | [diff] [blame] | 3318 | |
| 3319 | return ret; |
| 3320 | } |
| 3321 | |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 3322 | struct trace_option_dentry; |
| 3323 | |
| 3324 | static struct trace_option_dentry * |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3325 | create_trace_option_files(struct trace_array *tr, struct tracer *tracer); |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 3326 | |
| 3327 | static void |
| 3328 | destroy_trace_option_files(struct trace_option_dentry *topts); |
| 3329 | |
Steven Rostedt | b2821ae | 2009-02-02 21:38:32 -0500 | [diff] [blame] | 3330 | static int tracing_set_tracer(const char *buf) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3331 | { |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 3332 | static struct trace_option_dentry *topts; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3333 | struct trace_array *tr = &global_trace; |
| 3334 | struct tracer *t; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3335 | #ifdef CONFIG_TRACER_MAX_TRACE |
Steven Rostedt | 34600f0 | 2013-01-22 13:35:11 -0500 | [diff] [blame] | 3336 | bool had_max_tr; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3337 | #endif |
Peter Zijlstra | d9e5407 | 2008-11-01 19:57:37 +0100 | [diff] [blame] | 3338 | int ret = 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3339 | |
Steven Rostedt | 1027fcb | 2009-03-12 11:33:20 -0400 | [diff] [blame] | 3340 | mutex_lock(&trace_types_lock); |
| 3341 | |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 3342 | if (!ring_buffer_expanded) { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3343 | ret = __tracing_resize_ring_buffer(tr, trace_buf_size, |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 3344 | RING_BUFFER_ALL_CPUS); |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 3345 | if (ret < 0) |
Frederic Weisbecker | 59f586d | 2009-03-15 22:10:39 +0100 | [diff] [blame] | 3346 | goto out; |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 3347 | ret = 0; |
| 3348 | } |
| 3349 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3350 | for (t = trace_types; t; t = t->next) { |
| 3351 | if (strcmp(t->name, buf) == 0) |
| 3352 | break; |
| 3353 | } |
Frederic Weisbecker | c2931e0 | 2008-10-04 22:04:44 +0200 | [diff] [blame] | 3354 | if (!t) { |
| 3355 | ret = -EINVAL; |
| 3356 | goto out; |
| 3357 | } |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3358 | if (t == tr->current_trace) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3359 | goto out; |
| 3360 | |
Steven Rostedt | 9f029e8 | 2008-11-12 15:24:24 -0500 | [diff] [blame] | 3361 | trace_branch_disable(); |
Steven Rostedt (Red Hat) | 613f04a | 2013-03-14 15:03:53 -0400 | [diff] [blame] | 3362 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3363 | tr->current_trace->enabled = false; |
Steven Rostedt (Red Hat) | 613f04a | 2013-03-14 15:03:53 -0400 | [diff] [blame] | 3364 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3365 | if (tr->current_trace->reset) |
| 3366 | tr->current_trace->reset(tr); |
Steven Rostedt | 34600f0 | 2013-01-22 13:35:11 -0500 | [diff] [blame] | 3367 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3368 | /* Current trace needs to be nop_trace before synchronize_sched */ |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3369 | tr->current_trace = &nop_trace; |
Steven Rostedt | 34600f0 | 2013-01-22 13:35:11 -0500 | [diff] [blame] | 3370 | |
Steven Rostedt (Red Hat) | 45ad21c | 2013-03-05 18:25:02 -0500 | [diff] [blame] | 3371 | #ifdef CONFIG_TRACER_MAX_TRACE |
| 3372 | had_max_tr = tr->allocated_snapshot; |
| 3373 | |
Steven Rostedt | 34600f0 | 2013-01-22 13:35:11 -0500 | [diff] [blame] | 3374 | if (had_max_tr && !t->use_max_tr) { |
| 3375 | /* |
| 3376 | * We need to make sure that the update_max_tr sees that |
| 3377 | * current_trace changed to nop_trace to keep it from |
| 3378 | * swapping the buffers after we resize it. |
| 3379 | * The update_max_tr is called from interrupts disabled |
| 3380 | * so a synchronized_sched() is sufficient. |
| 3381 | */ |
| 3382 | synchronize_sched(); |
KOSAKI Motohiro | ef710e1 | 2010-07-01 14:34:35 +0900 | [diff] [blame] | 3383 | /* |
| 3384 | * We don't free the ring buffer. instead, resize it because |
| 3385 | * The max_tr ring buffer has some state (e.g. ring->clock) and |
| 3386 | * we want preserve it. |
| 3387 | */ |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3388 | ring_buffer_resize(tr->max_buffer.buffer, 1, RING_BUFFER_ALL_CPUS); |
| 3389 | set_buffer_entries(&tr->max_buffer, 1); |
| 3390 | tracing_reset_online_cpus(&tr->max_buffer); |
Steven Rostedt (Red Hat) | 45ad21c | 2013-03-05 18:25:02 -0500 | [diff] [blame] | 3391 | tr->allocated_snapshot = false; |
KOSAKI Motohiro | ef710e1 | 2010-07-01 14:34:35 +0900 | [diff] [blame] | 3392 | } |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3393 | #endif |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 3394 | destroy_trace_option_files(topts); |
| 3395 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3396 | topts = create_trace_option_files(tr, t); |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3397 | |
| 3398 | #ifdef CONFIG_TRACER_MAX_TRACE |
Steven Rostedt | 34600f0 | 2013-01-22 13:35:11 -0500 | [diff] [blame] | 3399 | if (t->use_max_tr && !had_max_tr) { |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 3400 | /* we need to make per cpu buffer sizes equivalent */ |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3401 | ret = resize_buffer_duplicate_size(&tr->max_buffer, &tr->trace_buffer, |
Hiraku Toyooka | d60da50 | 2012-10-17 11:56:16 +0900 | [diff] [blame] | 3402 | RING_BUFFER_ALL_CPUS); |
| 3403 | if (ret < 0) |
| 3404 | goto out; |
Steven Rostedt (Red Hat) | 45ad21c | 2013-03-05 18:25:02 -0500 | [diff] [blame] | 3405 | tr->allocated_snapshot = true; |
KOSAKI Motohiro | ef710e1 | 2010-07-01 14:34:35 +0900 | [diff] [blame] | 3406 | } |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3407 | #endif |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 3408 | |
Frederic Weisbecker | 1c80025 | 2008-11-16 05:57:26 +0100 | [diff] [blame] | 3409 | if (t->init) { |
Arnaldo Carvalho de Melo | b6f11df | 2009-02-05 18:02:00 -0200 | [diff] [blame] | 3410 | ret = tracer_init(t, tr); |
Frederic Weisbecker | 1c80025 | 2008-11-16 05:57:26 +0100 | [diff] [blame] | 3411 | if (ret) |
| 3412 | goto out; |
| 3413 | } |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3414 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3415 | tr->current_trace = t; |
| 3416 | tr->current_trace->enabled = true; |
Steven Rostedt | 9f029e8 | 2008-11-12 15:24:24 -0500 | [diff] [blame] | 3417 | trace_branch_enable(tr); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3418 | out: |
| 3419 | mutex_unlock(&trace_types_lock); |
| 3420 | |
Peter Zijlstra | d9e5407 | 2008-11-01 19:57:37 +0100 | [diff] [blame] | 3421 | return ret; |
| 3422 | } |
| 3423 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3424 | static ssize_t |
| 3425 | tracing_set_trace_write(struct file *filp, const char __user *ubuf, |
| 3426 | size_t cnt, loff_t *ppos) |
| 3427 | { |
Li Zefan | ee6c2c1 | 2009-09-18 14:06:47 +0800 | [diff] [blame] | 3428 | char buf[MAX_TRACER_SIZE+1]; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3429 | int i; |
| 3430 | size_t ret; |
Frederic Weisbecker | e6e7a65 | 2008-11-16 05:53:19 +0100 | [diff] [blame] | 3431 | int err; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3432 | |
Steven Rostedt | 60063a6 | 2008-10-28 10:44:24 -0400 | [diff] [blame] | 3433 | ret = cnt; |
| 3434 | |
Li Zefan | ee6c2c1 | 2009-09-18 14:06:47 +0800 | [diff] [blame] | 3435 | if (cnt > MAX_TRACER_SIZE) |
| 3436 | cnt = MAX_TRACER_SIZE; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3437 | |
| 3438 | if (copy_from_user(&buf, ubuf, cnt)) |
| 3439 | return -EFAULT; |
| 3440 | |
| 3441 | buf[cnt] = 0; |
| 3442 | |
| 3443 | /* strip ending whitespace. */ |
| 3444 | for (i = cnt - 1; i > 0 && isspace(buf[i]); i--) |
| 3445 | buf[i] = 0; |
| 3446 | |
Frederic Weisbecker | e6e7a65 | 2008-11-16 05:53:19 +0100 | [diff] [blame] | 3447 | err = tracing_set_tracer(buf); |
| 3448 | if (err) |
| 3449 | return err; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3450 | |
Jiri Olsa | cf8517c | 2009-10-23 19:36:16 -0400 | [diff] [blame] | 3451 | *ppos += ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3452 | |
Frederic Weisbecker | c2931e0 | 2008-10-04 22:04:44 +0200 | [diff] [blame] | 3453 | return ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3454 | } |
| 3455 | |
| 3456 | static ssize_t |
| 3457 | tracing_max_lat_read(struct file *filp, char __user *ubuf, |
| 3458 | size_t cnt, loff_t *ppos) |
| 3459 | { |
| 3460 | unsigned long *ptr = filp->private_data; |
| 3461 | char buf[64]; |
| 3462 | int r; |
| 3463 | |
Steven Rostedt | cffae43 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 3464 | r = snprintf(buf, sizeof(buf), "%ld\n", |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3465 | *ptr == (unsigned long)-1 ? -1 : nsecs_to_usecs(*ptr)); |
Steven Rostedt | cffae43 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 3466 | if (r > sizeof(buf)) |
| 3467 | r = sizeof(buf); |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3468 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, r); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3469 | } |
| 3470 | |
| 3471 | static ssize_t |
| 3472 | tracing_max_lat_write(struct file *filp, const char __user *ubuf, |
| 3473 | size_t cnt, loff_t *ppos) |
| 3474 | { |
Hannes Eder | 5e39841 | 2009-02-10 19:44:34 +0100 | [diff] [blame] | 3475 | unsigned long *ptr = filp->private_data; |
Hannes Eder | 5e39841 | 2009-02-10 19:44:34 +0100 | [diff] [blame] | 3476 | unsigned long val; |
Steven Rostedt | c6caeeb | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 3477 | int ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3478 | |
Peter Huewe | 22fe9b5 | 2011-06-07 21:58:27 +0200 | [diff] [blame] | 3479 | ret = kstrtoul_from_user(ubuf, cnt, 10, &val); |
| 3480 | if (ret) |
Steven Rostedt | c6caeeb | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 3481 | return ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3482 | |
| 3483 | *ptr = val * 1000; |
| 3484 | |
| 3485 | return cnt; |
| 3486 | } |
| 3487 | |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3488 | static int tracing_open_pipe(struct inode *inode, struct file *filp) |
| 3489 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3490 | struct trace_cpu *tc = inode->i_private; |
| 3491 | struct trace_array *tr = tc->tr; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3492 | struct trace_iterator *iter; |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 3493 | int ret = 0; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3494 | |
| 3495 | if (tracing_disabled) |
| 3496 | return -ENODEV; |
| 3497 | |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 3498 | mutex_lock(&trace_types_lock); |
| 3499 | |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3500 | /* create a buffer to store the information to pass to userspace */ |
| 3501 | iter = kzalloc(sizeof(*iter), GFP_KERNEL); |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 3502 | if (!iter) { |
| 3503 | ret = -ENOMEM; |
| 3504 | goto out; |
| 3505 | } |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3506 | |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 3507 | /* |
| 3508 | * We make a copy of the current tracer to avoid concurrent |
| 3509 | * changes on it while we are reading. |
| 3510 | */ |
| 3511 | iter->trace = kmalloc(sizeof(*iter->trace), GFP_KERNEL); |
| 3512 | if (!iter->trace) { |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 3513 | ret = -ENOMEM; |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 3514 | goto fail; |
| 3515 | } |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3516 | *iter->trace = *tr->current_trace; |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 3517 | |
| 3518 | if (!alloc_cpumask_var(&iter->started, GFP_KERNEL)) { |
| 3519 | ret = -ENOMEM; |
| 3520 | goto fail; |
Rusty Russell | 4462344 | 2009-01-01 10:12:23 +1030 | [diff] [blame] | 3521 | } |
| 3522 | |
Steven Rostedt | a309720 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 3523 | /* trace pipe does not show start of buffer */ |
Rusty Russell | 4462344 | 2009-01-01 10:12:23 +1030 | [diff] [blame] | 3524 | cpumask_setall(iter->started); |
Steven Rostedt | a309720 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 3525 | |
Steven Rostedt | 112f38a7 | 2009-06-01 15:16:05 -0400 | [diff] [blame] | 3526 | if (trace_flags & TRACE_ITER_LATENCY_FMT) |
| 3527 | iter->iter_flags |= TRACE_FILE_LAT_FMT; |
| 3528 | |
David Sharp | 8be0709 | 2012-11-13 12:18:22 -0800 | [diff] [blame] | 3529 | /* Output in nanoseconds only if we are using a clock in nanoseconds. */ |
| 3530 | if (trace_clocks[trace_clock_id].in_ns) |
| 3531 | iter->iter_flags |= TRACE_FILE_TIME_IN_NS; |
| 3532 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3533 | iter->cpu_file = tc->cpu; |
| 3534 | iter->tr = tc->tr; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3535 | iter->trace_buffer = &tc->tr->trace_buffer; |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 3536 | mutex_init(&iter->mutex); |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3537 | filp->private_data = iter; |
| 3538 | |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 3539 | if (iter->trace->pipe_open) |
| 3540 | iter->trace->pipe_open(iter); |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 3541 | |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 3542 | nonseekable_open(inode, filp); |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 3543 | out: |
| 3544 | mutex_unlock(&trace_types_lock); |
| 3545 | return ret; |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 3546 | |
| 3547 | fail: |
| 3548 | kfree(iter->trace); |
| 3549 | kfree(iter); |
| 3550 | mutex_unlock(&trace_types_lock); |
| 3551 | return ret; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3552 | } |
| 3553 | |
| 3554 | static int tracing_release_pipe(struct inode *inode, struct file *file) |
| 3555 | { |
| 3556 | struct trace_iterator *iter = file->private_data; |
| 3557 | |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 3558 | mutex_lock(&trace_types_lock); |
| 3559 | |
Steven Rostedt | 29bf4a5 | 2009-12-09 12:37:43 -0500 | [diff] [blame] | 3560 | if (iter->trace->pipe_close) |
Steven Rostedt | c521efd | 2009-12-07 09:06:24 -0500 | [diff] [blame] | 3561 | iter->trace->pipe_close(iter); |
| 3562 | |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 3563 | mutex_unlock(&trace_types_lock); |
| 3564 | |
Rusty Russell | 4462344 | 2009-01-01 10:12:23 +1030 | [diff] [blame] | 3565 | free_cpumask_var(iter->started); |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 3566 | mutex_destroy(&iter->mutex); |
| 3567 | kfree(iter->trace); |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3568 | kfree(iter); |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3569 | |
| 3570 | return 0; |
| 3571 | } |
| 3572 | |
Soeren Sandmann Pedersen | 2a2cc8f | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 3573 | static unsigned int |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 3574 | 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] | 3575 | { |
Steven Rostedt (Red Hat) | 1569345 | 2013-02-28 19:59:17 -0500 | [diff] [blame] | 3576 | /* Iterators are static, they should be filled or empty */ |
| 3577 | if (trace_buffer_iter(iter, iter->cpu_file)) |
| 3578 | return POLLIN | POLLRDNORM; |
| 3579 | |
| 3580 | if (trace_flags & TRACE_ITER_BLOCK) |
Soeren Sandmann Pedersen | 2a2cc8f | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 3581 | /* |
| 3582 | * Always select as readable when in blocking mode |
| 3583 | */ |
| 3584 | return POLLIN | POLLRDNORM; |
Steven Rostedt (Red Hat) | 1569345 | 2013-02-28 19:59:17 -0500 | [diff] [blame] | 3585 | else |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3586 | 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] | 3587 | filp, poll_table); |
Soeren Sandmann Pedersen | 2a2cc8f | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 3588 | } |
| 3589 | |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 3590 | static unsigned int |
| 3591 | tracing_poll_pipe(struct file *filp, poll_table *poll_table) |
| 3592 | { |
| 3593 | struct trace_iterator *iter = filp->private_data; |
| 3594 | |
| 3595 | return trace_poll(iter, filp, poll_table); |
| 3596 | } |
| 3597 | |
Frederic Weisbecker | 6eaaa5d | 2009-02-11 02:25:00 +0100 | [diff] [blame] | 3598 | /* |
| 3599 | * This is a make-shift waitqueue. |
| 3600 | * A tracer might use this callback on some rare cases: |
| 3601 | * |
| 3602 | * 1) the current tracer might hold the runqueue lock when it wakes up |
| 3603 | * a reader, hence a deadlock (sched, function, and function graph tracers) |
| 3604 | * 2) the function tracers, trace all functions, we don't want |
| 3605 | * the overhead of calling wake_up and friends |
| 3606 | * (and tracing them too) |
| 3607 | * |
| 3608 | * Anyway, this is really very primitive wakeup. |
| 3609 | */ |
| 3610 | void poll_wait_pipe(struct trace_iterator *iter) |
| 3611 | { |
| 3612 | set_current_state(TASK_INTERRUPTIBLE); |
| 3613 | /* sleep for 100 msecs, and try again. */ |
| 3614 | schedule_timeout(HZ / 10); |
| 3615 | } |
| 3616 | |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 3617 | /* Must be called with trace_types_lock mutex held. */ |
| 3618 | static int tracing_wait_pipe(struct file *filp) |
| 3619 | { |
| 3620 | struct trace_iterator *iter = filp->private_data; |
| 3621 | |
| 3622 | while (trace_empty(iter)) { |
| 3623 | |
| 3624 | if ((filp->f_flags & O_NONBLOCK)) { |
| 3625 | return -EAGAIN; |
| 3626 | } |
| 3627 | |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 3628 | mutex_unlock(&iter->mutex); |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 3629 | |
Frederic Weisbecker | 6eaaa5d | 2009-02-11 02:25:00 +0100 | [diff] [blame] | 3630 | iter->trace->wait_pipe(iter); |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 3631 | |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 3632 | mutex_lock(&iter->mutex); |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 3633 | |
Frederic Weisbecker | 6eaaa5d | 2009-02-11 02:25:00 +0100 | [diff] [blame] | 3634 | if (signal_pending(current)) |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 3635 | return -EINTR; |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 3636 | |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 3637 | /* |
Liu Bo | 250bfd3 | 2013-01-14 10:54:11 +0800 | [diff] [blame] | 3638 | * We block until we read something and tracing is disabled. |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 3639 | * We still block if tracing is disabled, but we have never |
| 3640 | * read anything. This allows a user to cat this file, and |
| 3641 | * then enable tracing. But after we have read something, |
| 3642 | * we give an EOF when tracing is again disabled. |
| 3643 | * |
| 3644 | * iter->pos will be 0 if we haven't read anything. |
| 3645 | */ |
Liu Bo | 250bfd3 | 2013-01-14 10:54:11 +0800 | [diff] [blame] | 3646 | if (!tracing_is_enabled() && iter->pos) |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 3647 | break; |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 3648 | } |
| 3649 | |
| 3650 | return 1; |
| 3651 | } |
| 3652 | |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3653 | /* |
| 3654 | * Consumer reader. |
| 3655 | */ |
| 3656 | static ssize_t |
| 3657 | tracing_read_pipe(struct file *filp, char __user *ubuf, |
| 3658 | size_t cnt, loff_t *ppos) |
| 3659 | { |
| 3660 | struct trace_iterator *iter = filp->private_data; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3661 | struct trace_array *tr = iter->tr; |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 3662 | ssize_t sret; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3663 | |
| 3664 | /* return any leftover data */ |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 3665 | sret = trace_seq_to_user(&iter->seq, ubuf, cnt); |
| 3666 | if (sret != -EBUSY) |
| 3667 | return sret; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3668 | |
Steven Rostedt | f952075 | 2009-03-02 14:04:40 -0500 | [diff] [blame] | 3669 | trace_seq_init(&iter->seq); |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3670 | |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 3671 | /* copy the tracer to avoid using a global lock all around */ |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 3672 | mutex_lock(&trace_types_lock); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3673 | if (unlikely(iter->trace->name != tr->current_trace->name)) |
| 3674 | *iter->trace = *tr->current_trace; |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 3675 | mutex_unlock(&trace_types_lock); |
| 3676 | |
| 3677 | /* |
| 3678 | * Avoid more than one consumer on a single file descriptor |
| 3679 | * This is just a matter of traces coherency, the ring buffer itself |
| 3680 | * is protected. |
| 3681 | */ |
| 3682 | mutex_lock(&iter->mutex); |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 3683 | if (iter->trace->read) { |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 3684 | sret = iter->trace->read(iter, filp, ubuf, cnt, ppos); |
| 3685 | if (sret) |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 3686 | goto out; |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 3687 | } |
| 3688 | |
Pekka Paalanen | 9ff4b97 | 2008-09-29 20:23:48 +0200 | [diff] [blame] | 3689 | waitagain: |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 3690 | sret = tracing_wait_pipe(filp); |
| 3691 | if (sret <= 0) |
| 3692 | goto out; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3693 | |
| 3694 | /* stop when tracing is finished */ |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 3695 | if (trace_empty(iter)) { |
| 3696 | sret = 0; |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 3697 | goto out; |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 3698 | } |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3699 | |
| 3700 | if (cnt >= PAGE_SIZE) |
| 3701 | cnt = PAGE_SIZE - 1; |
| 3702 | |
Steven Rostedt | 53d0aa7 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 3703 | /* reset all but tr, trace, and overruns */ |
Steven Rostedt | 53d0aa7 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 3704 | memset(&iter->seq, 0, |
| 3705 | sizeof(struct trace_iterator) - |
| 3706 | offsetof(struct trace_iterator, seq)); |
Steven Rostedt | 4823ed7 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 3707 | iter->pos = -1; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3708 | |
Lai Jiangshan | 4f53596 | 2009-05-18 19:35:34 +0800 | [diff] [blame] | 3709 | trace_event_read_lock(); |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 3710 | trace_access_lock(iter->cpu_file); |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 3711 | while (trace_find_next_entry_inc(iter) != NULL) { |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 3712 | enum print_line_t ret; |
Steven Rostedt | 088b1e42 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 3713 | int len = iter->seq.len; |
| 3714 | |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 3715 | ret = print_trace_line(iter); |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 3716 | if (ret == TRACE_TYPE_PARTIAL_LINE) { |
Steven Rostedt | 088b1e42 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 3717 | /* don't print partial lines */ |
| 3718 | iter->seq.len = len; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3719 | break; |
Steven Rostedt | 088b1e42 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 3720 | } |
Frederic Weisbecker | b91facc | 2009-02-06 18:30:44 +0100 | [diff] [blame] | 3721 | if (ret != TRACE_TYPE_NO_CONSUME) |
| 3722 | trace_consume(iter); |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3723 | |
| 3724 | if (iter->seq.len >= cnt) |
| 3725 | break; |
Jiri Olsa | ee5e51f | 2011-03-25 12:05:18 +0100 | [diff] [blame] | 3726 | |
| 3727 | /* |
| 3728 | * Setting the full flag means we reached the trace_seq buffer |
| 3729 | * size and we should leave by partial output condition above. |
| 3730 | * One of the trace_seq_* functions is not used properly. |
| 3731 | */ |
| 3732 | WARN_ONCE(iter->seq.full, "full flag set for trace type %d", |
| 3733 | iter->ent->type); |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3734 | } |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 3735 | trace_access_unlock(iter->cpu_file); |
Lai Jiangshan | 4f53596 | 2009-05-18 19:35:34 +0800 | [diff] [blame] | 3736 | trace_event_read_unlock(); |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3737 | |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3738 | /* Now copy what we have to the user */ |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 3739 | sret = trace_seq_to_user(&iter->seq, ubuf, cnt); |
| 3740 | if (iter->seq.readpos >= iter->seq.len) |
Steven Rostedt | f952075 | 2009-03-02 14:04:40 -0500 | [diff] [blame] | 3741 | trace_seq_init(&iter->seq); |
Pekka Paalanen | 9ff4b97 | 2008-09-29 20:23:48 +0200 | [diff] [blame] | 3742 | |
| 3743 | /* |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 3744 | * 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] | 3745 | * entries, go back to wait for more entries. |
| 3746 | */ |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 3747 | if (sret == -EBUSY) |
Pekka Paalanen | 9ff4b97 | 2008-09-29 20:23:48 +0200 | [diff] [blame] | 3748 | goto waitagain; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3749 | |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 3750 | out: |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 3751 | mutex_unlock(&iter->mutex); |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 3752 | |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 3753 | return sret; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3754 | } |
| 3755 | |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 3756 | static void tracing_pipe_buf_release(struct pipe_inode_info *pipe, |
| 3757 | struct pipe_buffer *buf) |
| 3758 | { |
| 3759 | __free_page(buf->page); |
| 3760 | } |
| 3761 | |
| 3762 | static void tracing_spd_release_pipe(struct splice_pipe_desc *spd, |
| 3763 | unsigned int idx) |
| 3764 | { |
| 3765 | __free_page(spd->pages[idx]); |
| 3766 | } |
| 3767 | |
Alexey Dobriyan | 28dfef8 | 2009-12-15 16:46:48 -0800 | [diff] [blame] | 3768 | static const struct pipe_buf_operations tracing_pipe_buf_ops = { |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 3769 | .can_merge = 0, |
| 3770 | .map = generic_pipe_buf_map, |
| 3771 | .unmap = generic_pipe_buf_unmap, |
| 3772 | .confirm = generic_pipe_buf_confirm, |
| 3773 | .release = tracing_pipe_buf_release, |
| 3774 | .steal = generic_pipe_buf_steal, |
| 3775 | .get = generic_pipe_buf_get, |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 3776 | }; |
| 3777 | |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 3778 | static size_t |
Frederic Weisbecker | fa7c7f6 | 2009-02-11 02:51:30 +0100 | [diff] [blame] | 3779 | tracing_fill_pipe_page(size_t rem, struct trace_iterator *iter) |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 3780 | { |
| 3781 | size_t count; |
| 3782 | int ret; |
| 3783 | |
| 3784 | /* Seq buffer is page-sized, exactly what we need. */ |
| 3785 | for (;;) { |
| 3786 | count = iter->seq.len; |
| 3787 | ret = print_trace_line(iter); |
| 3788 | count = iter->seq.len - count; |
| 3789 | if (rem < count) { |
| 3790 | rem = 0; |
| 3791 | iter->seq.len -= count; |
| 3792 | break; |
| 3793 | } |
| 3794 | if (ret == TRACE_TYPE_PARTIAL_LINE) { |
| 3795 | iter->seq.len -= count; |
| 3796 | break; |
| 3797 | } |
| 3798 | |
Lai Jiangshan | 74e7ff8 | 2009-07-28 20:17:22 +0800 | [diff] [blame] | 3799 | if (ret != TRACE_TYPE_NO_CONSUME) |
| 3800 | trace_consume(iter); |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 3801 | rem -= count; |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 3802 | if (!trace_find_next_entry_inc(iter)) { |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 3803 | rem = 0; |
| 3804 | iter->ent = NULL; |
| 3805 | break; |
| 3806 | } |
| 3807 | } |
| 3808 | |
| 3809 | return rem; |
| 3810 | } |
| 3811 | |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 3812 | static ssize_t tracing_splice_read_pipe(struct file *filp, |
| 3813 | loff_t *ppos, |
| 3814 | struct pipe_inode_info *pipe, |
| 3815 | size_t len, |
| 3816 | unsigned int flags) |
| 3817 | { |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 3818 | struct page *pages_def[PIPE_DEF_BUFFERS]; |
| 3819 | struct partial_page partial_def[PIPE_DEF_BUFFERS]; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 3820 | struct trace_iterator *iter = filp->private_data; |
| 3821 | struct splice_pipe_desc spd = { |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 3822 | .pages = pages_def, |
| 3823 | .partial = partial_def, |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 3824 | .nr_pages = 0, /* This gets updated below. */ |
Eric Dumazet | 047fe36 | 2012-06-12 15:24:40 +0200 | [diff] [blame] | 3825 | .nr_pages_max = PIPE_DEF_BUFFERS, |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 3826 | .flags = flags, |
| 3827 | .ops = &tracing_pipe_buf_ops, |
| 3828 | .spd_release = tracing_spd_release_pipe, |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 3829 | }; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3830 | struct trace_array *tr = iter->tr; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 3831 | ssize_t ret; |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 3832 | size_t rem; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 3833 | unsigned int i; |
| 3834 | |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 3835 | if (splice_grow_spd(pipe, &spd)) |
| 3836 | return -ENOMEM; |
| 3837 | |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 3838 | /* copy the tracer to avoid using a global lock all around */ |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 3839 | mutex_lock(&trace_types_lock); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3840 | if (unlikely(iter->trace->name != tr->current_trace->name)) |
| 3841 | *iter->trace = *tr->current_trace; |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 3842 | mutex_unlock(&trace_types_lock); |
| 3843 | |
| 3844 | mutex_lock(&iter->mutex); |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 3845 | |
| 3846 | if (iter->trace->splice_read) { |
| 3847 | ret = iter->trace->splice_read(iter, filp, |
| 3848 | ppos, pipe, len, flags); |
| 3849 | if (ret) |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 3850 | goto out_err; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 3851 | } |
| 3852 | |
| 3853 | ret = tracing_wait_pipe(filp); |
| 3854 | if (ret <= 0) |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 3855 | goto out_err; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 3856 | |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 3857 | if (!iter->ent && !trace_find_next_entry_inc(iter)) { |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 3858 | ret = -EFAULT; |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 3859 | goto out_err; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 3860 | } |
| 3861 | |
Lai Jiangshan | 4f53596 | 2009-05-18 19:35:34 +0800 | [diff] [blame] | 3862 | trace_event_read_lock(); |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 3863 | trace_access_lock(iter->cpu_file); |
Lai Jiangshan | 4f53596 | 2009-05-18 19:35:34 +0800 | [diff] [blame] | 3864 | |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 3865 | /* Fill as many pages as possible. */ |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 3866 | for (i = 0, rem = len; i < pipe->buffers && rem; i++) { |
| 3867 | spd.pages[i] = alloc_page(GFP_KERNEL); |
| 3868 | if (!spd.pages[i]) |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 3869 | break; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 3870 | |
Frederic Weisbecker | fa7c7f6 | 2009-02-11 02:51:30 +0100 | [diff] [blame] | 3871 | rem = tracing_fill_pipe_page(rem, iter); |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 3872 | |
| 3873 | /* Copy the data into the page, so we can start over. */ |
| 3874 | ret = trace_seq_to_buffer(&iter->seq, |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 3875 | page_address(spd.pages[i]), |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 3876 | iter->seq.len); |
| 3877 | if (ret < 0) { |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 3878 | __free_page(spd.pages[i]); |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 3879 | break; |
| 3880 | } |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 3881 | spd.partial[i].offset = 0; |
| 3882 | spd.partial[i].len = iter->seq.len; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 3883 | |
Steven Rostedt | f952075 | 2009-03-02 14:04:40 -0500 | [diff] [blame] | 3884 | trace_seq_init(&iter->seq); |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 3885 | } |
| 3886 | |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 3887 | trace_access_unlock(iter->cpu_file); |
Lai Jiangshan | 4f53596 | 2009-05-18 19:35:34 +0800 | [diff] [blame] | 3888 | trace_event_read_unlock(); |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 3889 | mutex_unlock(&iter->mutex); |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 3890 | |
| 3891 | spd.nr_pages = i; |
| 3892 | |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 3893 | ret = splice_to_pipe(pipe, &spd); |
| 3894 | out: |
Eric Dumazet | 047fe36 | 2012-06-12 15:24:40 +0200 | [diff] [blame] | 3895 | splice_shrink_spd(&spd); |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 3896 | return ret; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 3897 | |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 3898 | out_err: |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 3899 | mutex_unlock(&iter->mutex); |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 3900 | goto out; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 3901 | } |
| 3902 | |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 3903 | static ssize_t |
| 3904 | tracing_entries_read(struct file *filp, char __user *ubuf, |
| 3905 | size_t cnt, loff_t *ppos) |
| 3906 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3907 | struct trace_cpu *tc = filp->private_data; |
| 3908 | struct trace_array *tr = tc->tr; |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 3909 | char buf[64]; |
| 3910 | int r = 0; |
| 3911 | ssize_t ret; |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 3912 | |
Steven Rostedt | db526ca | 2009-03-12 13:53:25 -0400 | [diff] [blame] | 3913 | mutex_lock(&trace_types_lock); |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 3914 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3915 | if (tc->cpu == RING_BUFFER_ALL_CPUS) { |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 3916 | int cpu, buf_size_same; |
| 3917 | unsigned long size; |
| 3918 | |
| 3919 | size = 0; |
| 3920 | buf_size_same = 1; |
| 3921 | /* check if all cpu sizes are same */ |
| 3922 | for_each_tracing_cpu(cpu) { |
| 3923 | /* fill in the size from first enabled cpu */ |
| 3924 | if (size == 0) |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3925 | size = per_cpu_ptr(tr->trace_buffer.data, cpu)->entries; |
| 3926 | if (size != per_cpu_ptr(tr->trace_buffer.data, cpu)->entries) { |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 3927 | buf_size_same = 0; |
| 3928 | break; |
| 3929 | } |
| 3930 | } |
| 3931 | |
| 3932 | if (buf_size_same) { |
| 3933 | if (!ring_buffer_expanded) |
| 3934 | r = sprintf(buf, "%lu (expanded: %lu)\n", |
| 3935 | size >> 10, |
| 3936 | trace_buf_size >> 10); |
| 3937 | else |
| 3938 | r = sprintf(buf, "%lu\n", size >> 10); |
| 3939 | } else |
| 3940 | r = sprintf(buf, "X\n"); |
| 3941 | } else |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3942 | 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] | 3943 | |
Steven Rostedt | db526ca | 2009-03-12 13:53:25 -0400 | [diff] [blame] | 3944 | mutex_unlock(&trace_types_lock); |
| 3945 | |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 3946 | ret = simple_read_from_buffer(ubuf, cnt, ppos, buf, r); |
| 3947 | return ret; |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 3948 | } |
| 3949 | |
| 3950 | static ssize_t |
| 3951 | tracing_entries_write(struct file *filp, const char __user *ubuf, |
| 3952 | size_t cnt, loff_t *ppos) |
| 3953 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3954 | struct trace_cpu *tc = filp->private_data; |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 3955 | unsigned long val; |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 3956 | int ret; |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 3957 | |
Peter Huewe | 22fe9b5 | 2011-06-07 21:58:27 +0200 | [diff] [blame] | 3958 | ret = kstrtoul_from_user(ubuf, cnt, 10, &val); |
| 3959 | if (ret) |
Steven Rostedt | c6caeeb | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 3960 | return ret; |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 3961 | |
| 3962 | /* must have at least 1 entry */ |
| 3963 | if (!val) |
| 3964 | return -EINVAL; |
| 3965 | |
Steven Rostedt | 1696b2b | 2008-11-13 00:09:35 -0500 | [diff] [blame] | 3966 | /* value is in KB */ |
| 3967 | val <<= 10; |
| 3968 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3969 | ret = tracing_resize_ring_buffer(tc->tr, val, tc->cpu); |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 3970 | if (ret < 0) |
| 3971 | return ret; |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 3972 | |
Jiri Olsa | cf8517c | 2009-10-23 19:36:16 -0400 | [diff] [blame] | 3973 | *ppos += cnt; |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 3974 | |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 3975 | return cnt; |
| 3976 | } |
Steven Rostedt | bf5e651 | 2008-11-10 21:46:00 -0500 | [diff] [blame] | 3977 | |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 3978 | static ssize_t |
Vaibhav Nagarnaik | f81ab07 | 2011-08-16 14:46:15 -0700 | [diff] [blame] | 3979 | tracing_total_entries_read(struct file *filp, char __user *ubuf, |
| 3980 | size_t cnt, loff_t *ppos) |
| 3981 | { |
| 3982 | struct trace_array *tr = filp->private_data; |
| 3983 | char buf[64]; |
| 3984 | int r, cpu; |
| 3985 | unsigned long size = 0, expanded_size = 0; |
| 3986 | |
| 3987 | mutex_lock(&trace_types_lock); |
| 3988 | for_each_tracing_cpu(cpu) { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3989 | size += per_cpu_ptr(tr->trace_buffer.data, cpu)->entries >> 10; |
Vaibhav Nagarnaik | f81ab07 | 2011-08-16 14:46:15 -0700 | [diff] [blame] | 3990 | if (!ring_buffer_expanded) |
| 3991 | expanded_size += trace_buf_size >> 10; |
| 3992 | } |
| 3993 | if (ring_buffer_expanded) |
| 3994 | r = sprintf(buf, "%lu\n", size); |
| 3995 | else |
| 3996 | r = sprintf(buf, "%lu (expanded: %lu)\n", size, expanded_size); |
| 3997 | mutex_unlock(&trace_types_lock); |
| 3998 | |
| 3999 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, r); |
| 4000 | } |
| 4001 | |
| 4002 | static ssize_t |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 4003 | tracing_free_buffer_write(struct file *filp, const char __user *ubuf, |
| 4004 | size_t cnt, loff_t *ppos) |
| 4005 | { |
| 4006 | /* |
| 4007 | * There is no need to read what the user has written, this function |
| 4008 | * is just to make sure that there is no error when "echo" is used |
| 4009 | */ |
| 4010 | |
| 4011 | *ppos += cnt; |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 4012 | |
| 4013 | return cnt; |
| 4014 | } |
| 4015 | |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 4016 | static int |
| 4017 | tracing_free_buffer_release(struct inode *inode, struct file *filp) |
| 4018 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4019 | struct trace_array *tr = inode->i_private; |
| 4020 | |
Steven Rostedt | cf30cf6 | 2011-06-14 22:44:07 -0400 | [diff] [blame] | 4021 | /* disable tracing ? */ |
| 4022 | if (trace_flags & TRACE_ITER_STOP_ON_FREE) |
| 4023 | tracing_off(); |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 4024 | /* resize the ring buffer to 0 */ |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4025 | tracing_resize_ring_buffer(tr, 0, RING_BUFFER_ALL_CPUS); |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 4026 | |
| 4027 | return 0; |
| 4028 | } |
| 4029 | |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 4030 | static ssize_t |
| 4031 | tracing_mark_write(struct file *filp, const char __user *ubuf, |
| 4032 | size_t cnt, loff_t *fpos) |
| 4033 | { |
Steven Rostedt | d696b58 | 2011-09-22 11:50:27 -0400 | [diff] [blame] | 4034 | unsigned long addr = (unsigned long)ubuf; |
| 4035 | struct ring_buffer_event *event; |
| 4036 | struct ring_buffer *buffer; |
| 4037 | struct print_entry *entry; |
| 4038 | unsigned long irq_flags; |
| 4039 | struct page *pages[2]; |
Steven Rostedt | 6edb2a8 | 2012-05-11 23:28:49 -0400 | [diff] [blame] | 4040 | void *map_page[2]; |
Steven Rostedt | d696b58 | 2011-09-22 11:50:27 -0400 | [diff] [blame] | 4041 | int nr_pages = 1; |
| 4042 | ssize_t written; |
Steven Rostedt | d696b58 | 2011-09-22 11:50:27 -0400 | [diff] [blame] | 4043 | int offset; |
| 4044 | int size; |
| 4045 | int len; |
| 4046 | int ret; |
Steven Rostedt | 6edb2a8 | 2012-05-11 23:28:49 -0400 | [diff] [blame] | 4047 | int i; |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 4048 | |
Steven Rostedt | c76f069 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 4049 | if (tracing_disabled) |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 4050 | return -EINVAL; |
| 4051 | |
Mandeep Singh Baines | 5224c3a | 2012-09-07 18:12:19 -0700 | [diff] [blame] | 4052 | if (!(trace_flags & TRACE_ITER_MARKERS)) |
| 4053 | return -EINVAL; |
| 4054 | |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 4055 | if (cnt > TRACE_BUF_SIZE) |
| 4056 | cnt = TRACE_BUF_SIZE; |
| 4057 | |
Steven Rostedt | d696b58 | 2011-09-22 11:50:27 -0400 | [diff] [blame] | 4058 | /* |
| 4059 | * Userspace is injecting traces into the kernel trace buffer. |
| 4060 | * We want to be as non intrusive as possible. |
| 4061 | * To do so, we do not want to allocate any special buffers |
| 4062 | * or take any locks, but instead write the userspace data |
| 4063 | * straight into the ring buffer. |
| 4064 | * |
| 4065 | * First we need to pin the userspace buffer into memory, |
| 4066 | * which, most likely it is, because it just referenced it. |
| 4067 | * But there's no guarantee that it is. By using get_user_pages_fast() |
| 4068 | * and kmap_atomic/kunmap_atomic() we can get access to the |
| 4069 | * pages directly. We then write the data directly into the |
| 4070 | * ring buffer. |
| 4071 | */ |
| 4072 | BUILD_BUG_ON(TRACE_BUF_SIZE >= PAGE_SIZE); |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 4073 | |
Steven Rostedt | d696b58 | 2011-09-22 11:50:27 -0400 | [diff] [blame] | 4074 | /* check if we cross pages */ |
| 4075 | if ((addr & PAGE_MASK) != ((addr + cnt) & PAGE_MASK)) |
| 4076 | nr_pages = 2; |
| 4077 | |
| 4078 | offset = addr & (PAGE_SIZE - 1); |
| 4079 | addr &= PAGE_MASK; |
| 4080 | |
| 4081 | ret = get_user_pages_fast(addr, nr_pages, 0, pages); |
| 4082 | if (ret < nr_pages) { |
| 4083 | while (--ret >= 0) |
| 4084 | put_page(pages[ret]); |
| 4085 | written = -EFAULT; |
| 4086 | goto out; |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 4087 | } |
| 4088 | |
Steven Rostedt | 6edb2a8 | 2012-05-11 23:28:49 -0400 | [diff] [blame] | 4089 | for (i = 0; i < nr_pages; i++) |
| 4090 | map_page[i] = kmap_atomic(pages[i]); |
Steven Rostedt | d696b58 | 2011-09-22 11:50:27 -0400 | [diff] [blame] | 4091 | |
| 4092 | local_save_flags(irq_flags); |
| 4093 | size = sizeof(*entry) + cnt + 2; /* possible \n added */ |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4094 | buffer = global_trace.trace_buffer.buffer; |
Steven Rostedt | d696b58 | 2011-09-22 11:50:27 -0400 | [diff] [blame] | 4095 | event = trace_buffer_lock_reserve(buffer, TRACE_PRINT, size, |
| 4096 | irq_flags, preempt_count()); |
| 4097 | if (!event) { |
| 4098 | /* Ring buffer disabled, return as if not open for write */ |
| 4099 | written = -EBADF; |
| 4100 | goto out_unlock; |
| 4101 | } |
| 4102 | |
| 4103 | entry = ring_buffer_event_data(event); |
| 4104 | entry->ip = _THIS_IP_; |
| 4105 | |
| 4106 | if (nr_pages == 2) { |
| 4107 | len = PAGE_SIZE - offset; |
Steven Rostedt | 6edb2a8 | 2012-05-11 23:28:49 -0400 | [diff] [blame] | 4108 | memcpy(&entry->buf, map_page[0] + offset, len); |
| 4109 | memcpy(&entry->buf[len], map_page[1], cnt - len); |
Steven Rostedt | d696b58 | 2011-09-22 11:50:27 -0400 | [diff] [blame] | 4110 | } else |
Steven Rostedt | 6edb2a8 | 2012-05-11 23:28:49 -0400 | [diff] [blame] | 4111 | memcpy(&entry->buf, map_page[0] + offset, cnt); |
Steven Rostedt | d696b58 | 2011-09-22 11:50:27 -0400 | [diff] [blame] | 4112 | |
| 4113 | if (entry->buf[cnt - 1] != '\n') { |
| 4114 | entry->buf[cnt] = '\n'; |
| 4115 | entry->buf[cnt + 1] = '\0'; |
| 4116 | } else |
| 4117 | entry->buf[cnt] = '\0'; |
| 4118 | |
Steven Rostedt | 7ffbd48 | 2012-10-11 12:14:25 -0400 | [diff] [blame] | 4119 | __buffer_unlock_commit(buffer, event); |
Steven Rostedt | d696b58 | 2011-09-22 11:50:27 -0400 | [diff] [blame] | 4120 | |
| 4121 | written = cnt; |
| 4122 | |
Marcin Slusarz | 1aa54bc | 2010-07-28 01:18:01 +0200 | [diff] [blame] | 4123 | *fpos += written; |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 4124 | |
Steven Rostedt | d696b58 | 2011-09-22 11:50:27 -0400 | [diff] [blame] | 4125 | out_unlock: |
Steven Rostedt | 6edb2a8 | 2012-05-11 23:28:49 -0400 | [diff] [blame] | 4126 | for (i = 0; i < nr_pages; i++){ |
| 4127 | kunmap_atomic(map_page[i]); |
| 4128 | put_page(pages[i]); |
| 4129 | } |
Steven Rostedt | d696b58 | 2011-09-22 11:50:27 -0400 | [diff] [blame] | 4130 | out: |
Marcin Slusarz | 1aa54bc | 2010-07-28 01:18:01 +0200 | [diff] [blame] | 4131 | return written; |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 4132 | } |
| 4133 | |
Li Zefan | 13f16d2 | 2009-12-08 11:16:11 +0800 | [diff] [blame] | 4134 | static int tracing_clock_show(struct seq_file *m, void *v) |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 4135 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4136 | struct trace_array *tr = m->private; |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 4137 | int i; |
| 4138 | |
| 4139 | for (i = 0; i < ARRAY_SIZE(trace_clocks); i++) |
Li Zefan | 13f16d2 | 2009-12-08 11:16:11 +0800 | [diff] [blame] | 4140 | seq_printf(m, |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 4141 | "%s%s%s%s", i ? " " : "", |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4142 | i == tr->clock_id ? "[" : "", trace_clocks[i].name, |
| 4143 | i == tr->clock_id ? "]" : ""); |
Li Zefan | 13f16d2 | 2009-12-08 11:16:11 +0800 | [diff] [blame] | 4144 | seq_putc(m, '\n'); |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 4145 | |
Li Zefan | 13f16d2 | 2009-12-08 11:16:11 +0800 | [diff] [blame] | 4146 | return 0; |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 4147 | } |
| 4148 | |
| 4149 | static ssize_t tracing_clock_write(struct file *filp, const char __user *ubuf, |
| 4150 | size_t cnt, loff_t *fpos) |
| 4151 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4152 | struct seq_file *m = filp->private_data; |
| 4153 | struct trace_array *tr = m->private; |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 4154 | char buf[64]; |
| 4155 | const char *clockstr; |
| 4156 | int i; |
| 4157 | |
| 4158 | if (cnt >= sizeof(buf)) |
| 4159 | return -EINVAL; |
| 4160 | |
| 4161 | if (copy_from_user(&buf, ubuf, cnt)) |
| 4162 | return -EFAULT; |
| 4163 | |
| 4164 | buf[cnt] = 0; |
| 4165 | |
| 4166 | clockstr = strstrip(buf); |
| 4167 | |
| 4168 | for (i = 0; i < ARRAY_SIZE(trace_clocks); i++) { |
| 4169 | if (strcmp(trace_clocks[i].name, clockstr) == 0) |
| 4170 | break; |
| 4171 | } |
| 4172 | if (i == ARRAY_SIZE(trace_clocks)) |
| 4173 | return -EINVAL; |
| 4174 | |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 4175 | mutex_lock(&trace_types_lock); |
| 4176 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4177 | tr->clock_id = i; |
| 4178 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4179 | ring_buffer_set_clock(tr->trace_buffer.buffer, trace_clocks[i].func); |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 4180 | |
David Sharp | 60303ed | 2012-10-11 16:27:52 -0700 | [diff] [blame] | 4181 | /* |
| 4182 | * New clock may not be consistent with the previous clock. |
| 4183 | * Reset the buffer so that it doesn't have incomparable timestamps. |
| 4184 | */ |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4185 | tracing_reset_online_cpus(&global_trace.trace_buffer); |
| 4186 | |
| 4187 | #ifdef CONFIG_TRACER_MAX_TRACE |
| 4188 | if (tr->flags & TRACE_ARRAY_FL_GLOBAL && tr->max_buffer.buffer) |
| 4189 | ring_buffer_set_clock(tr->max_buffer.buffer, trace_clocks[i].func); |
| 4190 | tracing_reset_online_cpus(&global_trace.max_buffer); |
| 4191 | #endif |
David Sharp | 60303ed | 2012-10-11 16:27:52 -0700 | [diff] [blame] | 4192 | |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 4193 | mutex_unlock(&trace_types_lock); |
| 4194 | |
| 4195 | *fpos += cnt; |
| 4196 | |
| 4197 | return cnt; |
| 4198 | } |
| 4199 | |
Li Zefan | 13f16d2 | 2009-12-08 11:16:11 +0800 | [diff] [blame] | 4200 | static int tracing_clock_open(struct inode *inode, struct file *file) |
| 4201 | { |
| 4202 | if (tracing_disabled) |
| 4203 | return -ENODEV; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4204 | |
| 4205 | return single_open(file, tracing_clock_show, inode->i_private); |
Li Zefan | 13f16d2 | 2009-12-08 11:16:11 +0800 | [diff] [blame] | 4206 | } |
| 4207 | |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 4208 | struct ftrace_buffer_info { |
| 4209 | struct trace_iterator iter; |
| 4210 | void *spare; |
| 4211 | unsigned int read; |
| 4212 | }; |
| 4213 | |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4214 | #ifdef CONFIG_TRACER_SNAPSHOT |
| 4215 | static int tracing_snapshot_open(struct inode *inode, struct file *file) |
| 4216 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4217 | struct trace_cpu *tc = inode->i_private; |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4218 | struct trace_iterator *iter; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4219 | struct seq_file *m; |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4220 | int ret = 0; |
| 4221 | |
| 4222 | if (file->f_mode & FMODE_READ) { |
| 4223 | iter = __tracing_open(inode, file, true); |
| 4224 | if (IS_ERR(iter)) |
| 4225 | ret = PTR_ERR(iter); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4226 | } else { |
| 4227 | /* Writes still need the seq_file to hold the private data */ |
| 4228 | m = kzalloc(sizeof(*m), GFP_KERNEL); |
| 4229 | if (!m) |
| 4230 | return -ENOMEM; |
| 4231 | iter = kzalloc(sizeof(*iter), GFP_KERNEL); |
| 4232 | if (!iter) { |
| 4233 | kfree(m); |
| 4234 | return -ENOMEM; |
| 4235 | } |
| 4236 | iter->tr = tc->tr; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4237 | iter->trace_buffer = &tc->tr->max_buffer; |
Steven Rostedt (Red Hat) | f1affca | 2013-03-05 14:35:11 -0500 | [diff] [blame] | 4238 | iter->cpu_file = tc->cpu; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4239 | m->private = iter; |
| 4240 | file->private_data = m; |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4241 | } |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4242 | |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4243 | return ret; |
| 4244 | } |
| 4245 | |
| 4246 | static ssize_t |
| 4247 | tracing_snapshot_write(struct file *filp, const char __user *ubuf, size_t cnt, |
| 4248 | loff_t *ppos) |
| 4249 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4250 | struct seq_file *m = filp->private_data; |
| 4251 | struct trace_iterator *iter = m->private; |
| 4252 | struct trace_array *tr = iter->tr; |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4253 | unsigned long val; |
| 4254 | int ret; |
| 4255 | |
| 4256 | ret = tracing_update_buffers(); |
| 4257 | if (ret < 0) |
| 4258 | return ret; |
| 4259 | |
| 4260 | ret = kstrtoul_from_user(ubuf, cnt, 10, &val); |
| 4261 | if (ret) |
| 4262 | return ret; |
| 4263 | |
| 4264 | mutex_lock(&trace_types_lock); |
| 4265 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4266 | if (tr->current_trace->use_max_tr) { |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4267 | ret = -EBUSY; |
| 4268 | goto out; |
| 4269 | } |
| 4270 | |
| 4271 | switch (val) { |
| 4272 | case 0: |
Steven Rostedt (Red Hat) | f1affca | 2013-03-05 14:35:11 -0500 | [diff] [blame] | 4273 | if (iter->cpu_file != RING_BUFFER_ALL_CPUS) { |
| 4274 | ret = -EINVAL; |
| 4275 | break; |
| 4276 | } |
Steven Rostedt (Red Hat) | 45ad21c | 2013-03-05 18:25:02 -0500 | [diff] [blame] | 4277 | if (tr->allocated_snapshot) { |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4278 | /* free spare buffer */ |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4279 | ring_buffer_resize(tr->max_buffer.buffer, 1, |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4280 | RING_BUFFER_ALL_CPUS); |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4281 | set_buffer_entries(&tr->max_buffer, 1); |
| 4282 | tracing_reset_online_cpus(&tr->max_buffer); |
Steven Rostedt (Red Hat) | 45ad21c | 2013-03-05 18:25:02 -0500 | [diff] [blame] | 4283 | tr->allocated_snapshot = false; |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4284 | } |
| 4285 | break; |
| 4286 | case 1: |
Steven Rostedt (Red Hat) | f1affca | 2013-03-05 14:35:11 -0500 | [diff] [blame] | 4287 | /* Only allow per-cpu swap if the ring buffer supports it */ |
| 4288 | #ifndef CONFIG_RING_BUFFER_ALLOW_SWAP |
| 4289 | if (iter->cpu_file != RING_BUFFER_ALL_CPUS) { |
| 4290 | ret = -EINVAL; |
| 4291 | break; |
| 4292 | } |
| 4293 | #endif |
Steven Rostedt (Red Hat) | 45ad21c | 2013-03-05 18:25:02 -0500 | [diff] [blame] | 4294 | if (!tr->allocated_snapshot) { |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4295 | /* allocate spare buffer */ |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4296 | ret = resize_buffer_duplicate_size(&tr->max_buffer, |
| 4297 | &tr->trace_buffer, RING_BUFFER_ALL_CPUS); |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4298 | if (ret < 0) |
| 4299 | break; |
Steven Rostedt (Red Hat) | 45ad21c | 2013-03-05 18:25:02 -0500 | [diff] [blame] | 4300 | tr->allocated_snapshot = true; |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4301 | } |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4302 | local_irq_disable(); |
| 4303 | /* Now, we're going to swap */ |
Steven Rostedt (Red Hat) | f1affca | 2013-03-05 14:35:11 -0500 | [diff] [blame] | 4304 | if (iter->cpu_file == RING_BUFFER_ALL_CPUS) |
| 4305 | update_max_tr(&global_trace, current, smp_processor_id()); |
| 4306 | else |
| 4307 | update_max_tr_single(&global_trace, current, iter->cpu_file); |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4308 | local_irq_enable(); |
| 4309 | break; |
| 4310 | default: |
Steven Rostedt (Red Hat) | 45ad21c | 2013-03-05 18:25:02 -0500 | [diff] [blame] | 4311 | if (tr->allocated_snapshot) { |
Steven Rostedt (Red Hat) | f1affca | 2013-03-05 14:35:11 -0500 | [diff] [blame] | 4312 | if (iter->cpu_file == RING_BUFFER_ALL_CPUS) |
| 4313 | tracing_reset_online_cpus(&tr->max_buffer); |
| 4314 | else |
| 4315 | tracing_reset(&tr->max_buffer, iter->cpu_file); |
| 4316 | } |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4317 | break; |
| 4318 | } |
| 4319 | |
| 4320 | if (ret >= 0) { |
| 4321 | *ppos += cnt; |
| 4322 | ret = cnt; |
| 4323 | } |
| 4324 | out: |
| 4325 | mutex_unlock(&trace_types_lock); |
| 4326 | return ret; |
| 4327 | } |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4328 | |
| 4329 | static int tracing_snapshot_release(struct inode *inode, struct file *file) |
| 4330 | { |
| 4331 | struct seq_file *m = file->private_data; |
| 4332 | |
| 4333 | if (file->f_mode & FMODE_READ) |
| 4334 | return tracing_release(inode, file); |
| 4335 | |
| 4336 | /* If write only, the seq_file is just a stub */ |
| 4337 | if (m) |
| 4338 | kfree(m->private); |
| 4339 | kfree(m); |
| 4340 | |
| 4341 | return 0; |
| 4342 | } |
| 4343 | |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 4344 | static int tracing_buffers_open(struct inode *inode, struct file *filp); |
| 4345 | static ssize_t tracing_buffers_read(struct file *filp, char __user *ubuf, |
| 4346 | size_t count, loff_t *ppos); |
| 4347 | static int tracing_buffers_release(struct inode *inode, struct file *file); |
| 4348 | static ssize_t tracing_buffers_splice_read(struct file *file, loff_t *ppos, |
| 4349 | struct pipe_inode_info *pipe, size_t len, unsigned int flags); |
| 4350 | |
| 4351 | static int snapshot_raw_open(struct inode *inode, struct file *filp) |
| 4352 | { |
| 4353 | struct ftrace_buffer_info *info; |
| 4354 | int ret; |
| 4355 | |
| 4356 | ret = tracing_buffers_open(inode, filp); |
| 4357 | if (ret < 0) |
| 4358 | return ret; |
| 4359 | |
| 4360 | info = filp->private_data; |
| 4361 | |
| 4362 | if (info->iter.trace->use_max_tr) { |
| 4363 | tracing_buffers_release(inode, filp); |
| 4364 | return -EBUSY; |
| 4365 | } |
| 4366 | |
| 4367 | info->iter.snapshot = true; |
| 4368 | info->iter.trace_buffer = &info->iter.tr->max_buffer; |
| 4369 | |
| 4370 | return ret; |
| 4371 | } |
| 4372 | |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4373 | #endif /* CONFIG_TRACER_SNAPSHOT */ |
| 4374 | |
| 4375 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 4376 | static const struct file_operations tracing_max_lat_fops = { |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4377 | .open = tracing_open_generic, |
| 4378 | .read = tracing_max_lat_read, |
| 4379 | .write = tracing_max_lat_write, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 4380 | .llseek = generic_file_llseek, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4381 | }; |
| 4382 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 4383 | static const struct file_operations set_tracer_fops = { |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4384 | .open = tracing_open_generic, |
| 4385 | .read = tracing_set_trace_read, |
| 4386 | .write = tracing_set_trace_write, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 4387 | .llseek = generic_file_llseek, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4388 | }; |
| 4389 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 4390 | static const struct file_operations tracing_pipe_fops = { |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4391 | .open = tracing_open_pipe, |
Soeren Sandmann Pedersen | 2a2cc8f | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 4392 | .poll = tracing_poll_pipe, |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4393 | .read = tracing_read_pipe, |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4394 | .splice_read = tracing_splice_read_pipe, |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4395 | .release = tracing_release_pipe, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 4396 | .llseek = no_llseek, |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4397 | }; |
| 4398 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 4399 | static const struct file_operations tracing_entries_fops = { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4400 | .open = tracing_open_generic, |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 4401 | .read = tracing_entries_read, |
| 4402 | .write = tracing_entries_write, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 4403 | .llseek = generic_file_llseek, |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 4404 | }; |
| 4405 | |
Vaibhav Nagarnaik | f81ab07 | 2011-08-16 14:46:15 -0700 | [diff] [blame] | 4406 | static const struct file_operations tracing_total_entries_fops = { |
| 4407 | .open = tracing_open_generic, |
| 4408 | .read = tracing_total_entries_read, |
| 4409 | .llseek = generic_file_llseek, |
| 4410 | }; |
| 4411 | |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 4412 | static const struct file_operations tracing_free_buffer_fops = { |
| 4413 | .write = tracing_free_buffer_write, |
| 4414 | .release = tracing_free_buffer_release, |
| 4415 | }; |
| 4416 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 4417 | static const struct file_operations tracing_mark_fops = { |
Frédéric Weisbecker | 43a1538 | 2008-09-21 20:16:30 +0200 | [diff] [blame] | 4418 | .open = tracing_open_generic, |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 4419 | .write = tracing_mark_write, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 4420 | .llseek = generic_file_llseek, |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 4421 | }; |
| 4422 | |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 4423 | static const struct file_operations trace_clock_fops = { |
Li Zefan | 13f16d2 | 2009-12-08 11:16:11 +0800 | [diff] [blame] | 4424 | .open = tracing_clock_open, |
| 4425 | .read = seq_read, |
| 4426 | .llseek = seq_lseek, |
| 4427 | .release = single_release, |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 4428 | .write = tracing_clock_write, |
| 4429 | }; |
| 4430 | |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4431 | #ifdef CONFIG_TRACER_SNAPSHOT |
| 4432 | static const struct file_operations snapshot_fops = { |
| 4433 | .open = tracing_snapshot_open, |
| 4434 | .read = seq_read, |
| 4435 | .write = tracing_snapshot_write, |
| 4436 | .llseek = tracing_seek, |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4437 | .release = tracing_snapshot_release, |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4438 | }; |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4439 | |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 4440 | static const struct file_operations snapshot_raw_fops = { |
| 4441 | .open = snapshot_raw_open, |
| 4442 | .read = tracing_buffers_read, |
| 4443 | .release = tracing_buffers_release, |
| 4444 | .splice_read = tracing_buffers_splice_read, |
| 4445 | .llseek = no_llseek, |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4446 | }; |
| 4447 | |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 4448 | #endif /* CONFIG_TRACER_SNAPSHOT */ |
| 4449 | |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4450 | static int tracing_buffers_open(struct inode *inode, struct file *filp) |
| 4451 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4452 | struct trace_cpu *tc = inode->i_private; |
| 4453 | struct trace_array *tr = tc->tr; |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4454 | struct ftrace_buffer_info *info; |
| 4455 | |
| 4456 | if (tracing_disabled) |
| 4457 | return -ENODEV; |
| 4458 | |
| 4459 | info = kzalloc(sizeof(*info), GFP_KERNEL); |
| 4460 | if (!info) |
| 4461 | return -ENOMEM; |
| 4462 | |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 4463 | info->iter.tr = tr; |
| 4464 | info->iter.cpu_file = tc->cpu; |
Steven Rostedt | b627344 | 2013-02-28 13:44:11 -0500 | [diff] [blame] | 4465 | info->iter.trace = tr->current_trace; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4466 | info->iter.trace_buffer = &tr->trace_buffer; |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 4467 | info->spare = NULL; |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4468 | /* Force reading ring buffer for first read */ |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 4469 | info->read = (unsigned int)-1; |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4470 | |
| 4471 | filp->private_data = info; |
| 4472 | |
Lai Jiangshan | d1e7e02 | 2009-04-02 15:16:56 +0800 | [diff] [blame] | 4473 | return nonseekable_open(inode, filp); |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4474 | } |
| 4475 | |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 4476 | static unsigned int |
| 4477 | tracing_buffers_poll(struct file *filp, poll_table *poll_table) |
| 4478 | { |
| 4479 | struct ftrace_buffer_info *info = filp->private_data; |
| 4480 | struct trace_iterator *iter = &info->iter; |
| 4481 | |
| 4482 | return trace_poll(iter, filp, poll_table); |
| 4483 | } |
| 4484 | |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4485 | static ssize_t |
| 4486 | tracing_buffers_read(struct file *filp, char __user *ubuf, |
| 4487 | size_t count, loff_t *ppos) |
| 4488 | { |
| 4489 | struct ftrace_buffer_info *info = filp->private_data; |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 4490 | struct trace_iterator *iter = &info->iter; |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4491 | ssize_t ret; |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 4492 | ssize_t size; |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4493 | |
Steven Rostedt | 2dc5d12 | 2009-03-04 19:10:05 -0500 | [diff] [blame] | 4494 | if (!count) |
| 4495 | return 0; |
| 4496 | |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 4497 | mutex_lock(&trace_types_lock); |
| 4498 | |
| 4499 | #ifdef CONFIG_TRACER_MAX_TRACE |
| 4500 | if (iter->snapshot && iter->tr->current_trace->use_max_tr) { |
| 4501 | size = -EBUSY; |
| 4502 | goto out_unlock; |
| 4503 | } |
| 4504 | #endif |
| 4505 | |
Lai Jiangshan | ddd538f | 2009-04-02 15:16:59 +0800 | [diff] [blame] | 4506 | if (!info->spare) |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4507 | info->spare = ring_buffer_alloc_read_page(iter->trace_buffer->buffer, |
| 4508 | iter->cpu_file); |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 4509 | size = -ENOMEM; |
Lai Jiangshan | ddd538f | 2009-04-02 15:16:59 +0800 | [diff] [blame] | 4510 | if (!info->spare) |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 4511 | goto out_unlock; |
Lai Jiangshan | ddd538f | 2009-04-02 15:16:59 +0800 | [diff] [blame] | 4512 | |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4513 | /* Do we have previous read data to read? */ |
| 4514 | if (info->read < PAGE_SIZE) |
| 4515 | goto read; |
| 4516 | |
Steven Rostedt | b627344 | 2013-02-28 13:44:11 -0500 | [diff] [blame] | 4517 | again: |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 4518 | trace_access_lock(iter->cpu_file); |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4519 | ret = ring_buffer_read_page(iter->trace_buffer->buffer, |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4520 | &info->spare, |
| 4521 | count, |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 4522 | iter->cpu_file, 0); |
| 4523 | trace_access_unlock(iter->cpu_file); |
Steven Rostedt | b627344 | 2013-02-28 13:44:11 -0500 | [diff] [blame] | 4524 | |
| 4525 | if (ret < 0) { |
| 4526 | if (trace_empty(iter)) { |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 4527 | if ((filp->f_flags & O_NONBLOCK)) { |
| 4528 | size = -EAGAIN; |
| 4529 | goto out_unlock; |
| 4530 | } |
| 4531 | mutex_unlock(&trace_types_lock); |
Steven Rostedt | b627344 | 2013-02-28 13:44:11 -0500 | [diff] [blame] | 4532 | iter->trace->wait_pipe(iter); |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 4533 | mutex_lock(&trace_types_lock); |
| 4534 | if (signal_pending(current)) { |
| 4535 | size = -EINTR; |
| 4536 | goto out_unlock; |
| 4537 | } |
Steven Rostedt | b627344 | 2013-02-28 13:44:11 -0500 | [diff] [blame] | 4538 | goto again; |
| 4539 | } |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 4540 | size = 0; |
| 4541 | goto out_unlock; |
Steven Rostedt | b627344 | 2013-02-28 13:44:11 -0500 | [diff] [blame] | 4542 | } |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4543 | |
Steven Rostedt | 436fc28 | 2011-10-14 10:44:25 -0400 | [diff] [blame] | 4544 | info->read = 0; |
Steven Rostedt | b627344 | 2013-02-28 13:44:11 -0500 | [diff] [blame] | 4545 | read: |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4546 | size = PAGE_SIZE - info->read; |
| 4547 | if (size > count) |
| 4548 | size = count; |
| 4549 | |
| 4550 | ret = copy_to_user(ubuf, info->spare + info->read, size); |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 4551 | if (ret == size) { |
| 4552 | size = -EFAULT; |
| 4553 | goto out_unlock; |
| 4554 | } |
Steven Rostedt | 2dc5d12 | 2009-03-04 19:10:05 -0500 | [diff] [blame] | 4555 | size -= ret; |
| 4556 | |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4557 | *ppos += size; |
| 4558 | info->read += size; |
| 4559 | |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 4560 | out_unlock: |
| 4561 | mutex_unlock(&trace_types_lock); |
| 4562 | |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4563 | return size; |
| 4564 | } |
| 4565 | |
| 4566 | static int tracing_buffers_release(struct inode *inode, struct file *file) |
| 4567 | { |
| 4568 | struct ftrace_buffer_info *info = file->private_data; |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 4569 | struct trace_iterator *iter = &info->iter; |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4570 | |
Lai Jiangshan | ddd538f | 2009-04-02 15:16:59 +0800 | [diff] [blame] | 4571 | if (info->spare) |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4572 | ring_buffer_free_read_page(iter->trace_buffer->buffer, info->spare); |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4573 | kfree(info); |
| 4574 | |
| 4575 | return 0; |
| 4576 | } |
| 4577 | |
| 4578 | struct buffer_ref { |
| 4579 | struct ring_buffer *buffer; |
| 4580 | void *page; |
| 4581 | int ref; |
| 4582 | }; |
| 4583 | |
| 4584 | static void buffer_pipe_buf_release(struct pipe_inode_info *pipe, |
| 4585 | struct pipe_buffer *buf) |
| 4586 | { |
| 4587 | struct buffer_ref *ref = (struct buffer_ref *)buf->private; |
| 4588 | |
| 4589 | if (--ref->ref) |
| 4590 | return; |
| 4591 | |
| 4592 | ring_buffer_free_read_page(ref->buffer, ref->page); |
| 4593 | kfree(ref); |
| 4594 | buf->private = 0; |
| 4595 | } |
| 4596 | |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4597 | static void buffer_pipe_buf_get(struct pipe_inode_info *pipe, |
| 4598 | struct pipe_buffer *buf) |
| 4599 | { |
| 4600 | struct buffer_ref *ref = (struct buffer_ref *)buf->private; |
| 4601 | |
| 4602 | ref->ref++; |
| 4603 | } |
| 4604 | |
| 4605 | /* Pipe buffer operations for a buffer. */ |
Alexey Dobriyan | 28dfef8 | 2009-12-15 16:46:48 -0800 | [diff] [blame] | 4606 | static const struct pipe_buf_operations buffer_pipe_buf_ops = { |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4607 | .can_merge = 0, |
| 4608 | .map = generic_pipe_buf_map, |
| 4609 | .unmap = generic_pipe_buf_unmap, |
| 4610 | .confirm = generic_pipe_buf_confirm, |
| 4611 | .release = buffer_pipe_buf_release, |
Masami Hiramatsu | d55cb6c | 2012-08-09 21:31:10 +0900 | [diff] [blame] | 4612 | .steal = generic_pipe_buf_steal, |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4613 | .get = buffer_pipe_buf_get, |
| 4614 | }; |
| 4615 | |
| 4616 | /* |
| 4617 | * Callback from splice_to_pipe(), if we need to release some pages |
| 4618 | * at the end of the spd in case we error'ed out in filling the pipe. |
| 4619 | */ |
| 4620 | static void buffer_spd_release(struct splice_pipe_desc *spd, unsigned int i) |
| 4621 | { |
| 4622 | struct buffer_ref *ref = |
| 4623 | (struct buffer_ref *)spd->partial[i].private; |
| 4624 | |
| 4625 | if (--ref->ref) |
| 4626 | return; |
| 4627 | |
| 4628 | ring_buffer_free_read_page(ref->buffer, ref->page); |
| 4629 | kfree(ref); |
| 4630 | spd->partial[i].private = 0; |
| 4631 | } |
| 4632 | |
| 4633 | static ssize_t |
| 4634 | tracing_buffers_splice_read(struct file *file, loff_t *ppos, |
| 4635 | struct pipe_inode_info *pipe, size_t len, |
| 4636 | unsigned int flags) |
| 4637 | { |
| 4638 | struct ftrace_buffer_info *info = file->private_data; |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 4639 | struct trace_iterator *iter = &info->iter; |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 4640 | struct partial_page partial_def[PIPE_DEF_BUFFERS]; |
| 4641 | struct page *pages_def[PIPE_DEF_BUFFERS]; |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4642 | struct splice_pipe_desc spd = { |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 4643 | .pages = pages_def, |
| 4644 | .partial = partial_def, |
Eric Dumazet | 047fe36 | 2012-06-12 15:24:40 +0200 | [diff] [blame] | 4645 | .nr_pages_max = PIPE_DEF_BUFFERS, |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4646 | .flags = flags, |
| 4647 | .ops = &buffer_pipe_buf_ops, |
| 4648 | .spd_release = buffer_spd_release, |
| 4649 | }; |
| 4650 | struct buffer_ref *ref; |
Steven Rostedt | 93459c6 | 2009-04-29 00:23:13 -0400 | [diff] [blame] | 4651 | int entries, size, i; |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 4652 | ssize_t ret; |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4653 | |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 4654 | mutex_lock(&trace_types_lock); |
| 4655 | |
| 4656 | #ifdef CONFIG_TRACER_MAX_TRACE |
| 4657 | if (iter->snapshot && iter->tr->current_trace->use_max_tr) { |
| 4658 | ret = -EBUSY; |
| 4659 | goto out; |
| 4660 | } |
| 4661 | #endif |
| 4662 | |
| 4663 | if (splice_grow_spd(pipe, &spd)) { |
| 4664 | ret = -ENOMEM; |
| 4665 | goto out; |
| 4666 | } |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 4667 | |
Lai Jiangshan | 93cfb3c | 2009-04-02 15:17:08 +0800 | [diff] [blame] | 4668 | if (*ppos & (PAGE_SIZE - 1)) { |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 4669 | ret = -EINVAL; |
| 4670 | goto out; |
Lai Jiangshan | 93cfb3c | 2009-04-02 15:17:08 +0800 | [diff] [blame] | 4671 | } |
| 4672 | |
| 4673 | if (len & (PAGE_SIZE - 1)) { |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 4674 | if (len < PAGE_SIZE) { |
| 4675 | ret = -EINVAL; |
| 4676 | goto out; |
| 4677 | } |
Lai Jiangshan | 93cfb3c | 2009-04-02 15:17:08 +0800 | [diff] [blame] | 4678 | len &= PAGE_MASK; |
| 4679 | } |
| 4680 | |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 4681 | again: |
| 4682 | trace_access_lock(iter->cpu_file); |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4683 | entries = ring_buffer_entries_cpu(iter->trace_buffer->buffer, iter->cpu_file); |
Steven Rostedt | 93459c6 | 2009-04-29 00:23:13 -0400 | [diff] [blame] | 4684 | |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 4685 | for (i = 0; i < pipe->buffers && len && entries; i++, len -= PAGE_SIZE) { |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4686 | struct page *page; |
| 4687 | int r; |
| 4688 | |
| 4689 | ref = kzalloc(sizeof(*ref), GFP_KERNEL); |
| 4690 | if (!ref) |
| 4691 | break; |
| 4692 | |
Steven Rostedt | 7267fa6 | 2009-04-29 00:16:21 -0400 | [diff] [blame] | 4693 | ref->ref = 1; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4694 | ref->buffer = iter->trace_buffer->buffer; |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 4695 | ref->page = ring_buffer_alloc_read_page(ref->buffer, iter->cpu_file); |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4696 | if (!ref->page) { |
| 4697 | kfree(ref); |
| 4698 | break; |
| 4699 | } |
| 4700 | |
| 4701 | r = ring_buffer_read_page(ref->buffer, &ref->page, |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 4702 | len, iter->cpu_file, 1); |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4703 | if (r < 0) { |
Vaibhav Nagarnaik | 7ea5906 | 2011-05-03 17:56:42 -0700 | [diff] [blame] | 4704 | ring_buffer_free_read_page(ref->buffer, ref->page); |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4705 | kfree(ref); |
| 4706 | break; |
| 4707 | } |
| 4708 | |
| 4709 | /* |
| 4710 | * zero out any left over data, this is going to |
| 4711 | * user land. |
| 4712 | */ |
| 4713 | size = ring_buffer_page_len(ref->page); |
| 4714 | if (size < PAGE_SIZE) |
| 4715 | memset(ref->page + size, 0, PAGE_SIZE - size); |
| 4716 | |
| 4717 | page = virt_to_page(ref->page); |
| 4718 | |
| 4719 | spd.pages[i] = page; |
| 4720 | spd.partial[i].len = PAGE_SIZE; |
| 4721 | spd.partial[i].offset = 0; |
| 4722 | spd.partial[i].private = (unsigned long)ref; |
| 4723 | spd.nr_pages++; |
Lai Jiangshan | 93cfb3c | 2009-04-02 15:17:08 +0800 | [diff] [blame] | 4724 | *ppos += PAGE_SIZE; |
Steven Rostedt | 93459c6 | 2009-04-29 00:23:13 -0400 | [diff] [blame] | 4725 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4726 | entries = ring_buffer_entries_cpu(iter->trace_buffer->buffer, iter->cpu_file); |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4727 | } |
| 4728 | |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 4729 | trace_access_unlock(iter->cpu_file); |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4730 | spd.nr_pages = i; |
| 4731 | |
| 4732 | /* did we read anything? */ |
| 4733 | if (!spd.nr_pages) { |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 4734 | if ((file->f_flags & O_NONBLOCK) || (flags & SPLICE_F_NONBLOCK)) { |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4735 | ret = -EAGAIN; |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 4736 | goto out; |
| 4737 | } |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 4738 | mutex_unlock(&trace_types_lock); |
Steven Rostedt | b627344 | 2013-02-28 13:44:11 -0500 | [diff] [blame] | 4739 | iter->trace->wait_pipe(iter); |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 4740 | mutex_lock(&trace_types_lock); |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 4741 | if (signal_pending(current)) { |
| 4742 | ret = -EINTR; |
| 4743 | goto out; |
| 4744 | } |
| 4745 | goto again; |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4746 | } |
| 4747 | |
| 4748 | ret = splice_to_pipe(pipe, &spd); |
Eric Dumazet | 047fe36 | 2012-06-12 15:24:40 +0200 | [diff] [blame] | 4749 | splice_shrink_spd(&spd); |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 4750 | out: |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 4751 | mutex_unlock(&trace_types_lock); |
| 4752 | |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4753 | return ret; |
| 4754 | } |
| 4755 | |
| 4756 | static const struct file_operations tracing_buffers_fops = { |
| 4757 | .open = tracing_buffers_open, |
| 4758 | .read = tracing_buffers_read, |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 4759 | .poll = tracing_buffers_poll, |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4760 | .release = tracing_buffers_release, |
| 4761 | .splice_read = tracing_buffers_splice_read, |
| 4762 | .llseek = no_llseek, |
| 4763 | }; |
| 4764 | |
Steven Rostedt | c8d7718 | 2009-04-29 18:03:45 -0400 | [diff] [blame] | 4765 | static ssize_t |
| 4766 | tracing_stats_read(struct file *filp, char __user *ubuf, |
| 4767 | size_t count, loff_t *ppos) |
| 4768 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4769 | struct trace_cpu *tc = filp->private_data; |
| 4770 | struct trace_array *tr = tc->tr; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4771 | struct trace_buffer *trace_buf = &tr->trace_buffer; |
Steven Rostedt | c8d7718 | 2009-04-29 18:03:45 -0400 | [diff] [blame] | 4772 | struct trace_seq *s; |
| 4773 | unsigned long cnt; |
Vaibhav Nagarnaik | c64e148 | 2011-08-16 14:46:16 -0700 | [diff] [blame] | 4774 | unsigned long long t; |
| 4775 | unsigned long usec_rem; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4776 | int cpu = tc->cpu; |
Steven Rostedt | c8d7718 | 2009-04-29 18:03:45 -0400 | [diff] [blame] | 4777 | |
Li Zefan | e4f2d10 | 2009-06-15 10:57:28 +0800 | [diff] [blame] | 4778 | s = kmalloc(sizeof(*s), GFP_KERNEL); |
Steven Rostedt | c8d7718 | 2009-04-29 18:03:45 -0400 | [diff] [blame] | 4779 | if (!s) |
Roel Kluin | a646365 | 2009-11-11 22:26:35 +0100 | [diff] [blame] | 4780 | return -ENOMEM; |
Steven Rostedt | c8d7718 | 2009-04-29 18:03:45 -0400 | [diff] [blame] | 4781 | |
| 4782 | trace_seq_init(s); |
| 4783 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4784 | cnt = ring_buffer_entries_cpu(trace_buf->buffer, cpu); |
Steven Rostedt | c8d7718 | 2009-04-29 18:03:45 -0400 | [diff] [blame] | 4785 | trace_seq_printf(s, "entries: %ld\n", cnt); |
| 4786 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4787 | cnt = ring_buffer_overrun_cpu(trace_buf->buffer, cpu); |
Steven Rostedt | c8d7718 | 2009-04-29 18:03:45 -0400 | [diff] [blame] | 4788 | trace_seq_printf(s, "overrun: %ld\n", cnt); |
| 4789 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4790 | cnt = ring_buffer_commit_overrun_cpu(trace_buf->buffer, cpu); |
Steven Rostedt | c8d7718 | 2009-04-29 18:03:45 -0400 | [diff] [blame] | 4791 | trace_seq_printf(s, "commit overrun: %ld\n", cnt); |
| 4792 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4793 | cnt = ring_buffer_bytes_cpu(trace_buf->buffer, cpu); |
Vaibhav Nagarnaik | c64e148 | 2011-08-16 14:46:16 -0700 | [diff] [blame] | 4794 | trace_seq_printf(s, "bytes: %ld\n", cnt); |
| 4795 | |
Yoshihiro YUNOMAE | 11043d8b | 2012-11-13 12:18:23 -0800 | [diff] [blame] | 4796 | if (trace_clocks[trace_clock_id].in_ns) { |
| 4797 | /* local or global for trace_clock */ |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4798 | t = ns2usecs(ring_buffer_oldest_event_ts(trace_buf->buffer, cpu)); |
Yoshihiro YUNOMAE | 11043d8b | 2012-11-13 12:18:23 -0800 | [diff] [blame] | 4799 | usec_rem = do_div(t, USEC_PER_SEC); |
| 4800 | trace_seq_printf(s, "oldest event ts: %5llu.%06lu\n", |
| 4801 | t, usec_rem); |
Vaibhav Nagarnaik | c64e148 | 2011-08-16 14:46:16 -0700 | [diff] [blame] | 4802 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4803 | t = ns2usecs(ring_buffer_time_stamp(trace_buf->buffer, cpu)); |
Yoshihiro YUNOMAE | 11043d8b | 2012-11-13 12:18:23 -0800 | [diff] [blame] | 4804 | usec_rem = do_div(t, USEC_PER_SEC); |
| 4805 | trace_seq_printf(s, "now ts: %5llu.%06lu\n", t, usec_rem); |
| 4806 | } else { |
| 4807 | /* counter or tsc mode for trace_clock */ |
| 4808 | trace_seq_printf(s, "oldest event ts: %llu\n", |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4809 | ring_buffer_oldest_event_ts(trace_buf->buffer, cpu)); |
Yoshihiro YUNOMAE | 11043d8b | 2012-11-13 12:18:23 -0800 | [diff] [blame] | 4810 | |
| 4811 | trace_seq_printf(s, "now ts: %llu\n", |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4812 | ring_buffer_time_stamp(trace_buf->buffer, cpu)); |
Yoshihiro YUNOMAE | 11043d8b | 2012-11-13 12:18:23 -0800 | [diff] [blame] | 4813 | } |
Vaibhav Nagarnaik | c64e148 | 2011-08-16 14:46:16 -0700 | [diff] [blame] | 4814 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4815 | cnt = ring_buffer_dropped_events_cpu(trace_buf->buffer, cpu); |
Slava Pestov | 884bfe8 | 2011-07-15 14:23:58 -0700 | [diff] [blame] | 4816 | trace_seq_printf(s, "dropped events: %ld\n", cnt); |
| 4817 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4818 | cnt = ring_buffer_read_events_cpu(trace_buf->buffer, cpu); |
Steven Rostedt (Red Hat) | ad96470 | 2013-01-29 17:45:49 -0500 | [diff] [blame] | 4819 | trace_seq_printf(s, "read events: %ld\n", cnt); |
| 4820 | |
Steven Rostedt | c8d7718 | 2009-04-29 18:03:45 -0400 | [diff] [blame] | 4821 | count = simple_read_from_buffer(ubuf, count, ppos, s->buffer, s->len); |
| 4822 | |
| 4823 | kfree(s); |
| 4824 | |
| 4825 | return count; |
| 4826 | } |
| 4827 | |
| 4828 | static const struct file_operations tracing_stats_fops = { |
| 4829 | .open = tracing_open_generic, |
| 4830 | .read = tracing_stats_read, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 4831 | .llseek = generic_file_llseek, |
Steven Rostedt | c8d7718 | 2009-04-29 18:03:45 -0400 | [diff] [blame] | 4832 | }; |
| 4833 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4834 | #ifdef CONFIG_DYNAMIC_FTRACE |
| 4835 | |
Steven Rostedt | b807c3d | 2008-10-30 16:08:33 -0400 | [diff] [blame] | 4836 | int __weak ftrace_arch_read_dyn_info(char *buf, int size) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4837 | { |
Steven Rostedt | b807c3d | 2008-10-30 16:08:33 -0400 | [diff] [blame] | 4838 | return 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4839 | } |
| 4840 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4841 | static ssize_t |
Steven Rostedt | b807c3d | 2008-10-30 16:08:33 -0400 | [diff] [blame] | 4842 | tracing_read_dyn_info(struct file *filp, char __user *ubuf, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4843 | size_t cnt, loff_t *ppos) |
| 4844 | { |
Steven Rostedt | a26a2a2 | 2008-10-31 00:03:22 -0400 | [diff] [blame] | 4845 | static char ftrace_dyn_info_buffer[1024]; |
| 4846 | static DEFINE_MUTEX(dyn_info_mutex); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4847 | unsigned long *p = filp->private_data; |
Steven Rostedt | b807c3d | 2008-10-30 16:08:33 -0400 | [diff] [blame] | 4848 | char *buf = ftrace_dyn_info_buffer; |
Steven Rostedt | a26a2a2 | 2008-10-31 00:03:22 -0400 | [diff] [blame] | 4849 | int size = ARRAY_SIZE(ftrace_dyn_info_buffer); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4850 | int r; |
| 4851 | |
Steven Rostedt | b807c3d | 2008-10-30 16:08:33 -0400 | [diff] [blame] | 4852 | mutex_lock(&dyn_info_mutex); |
| 4853 | r = sprintf(buf, "%ld ", *p); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4854 | |
Steven Rostedt | a26a2a2 | 2008-10-31 00:03:22 -0400 | [diff] [blame] | 4855 | r += ftrace_arch_read_dyn_info(buf+r, (size-1)-r); |
Steven Rostedt | b807c3d | 2008-10-30 16:08:33 -0400 | [diff] [blame] | 4856 | buf[r++] = '\n'; |
| 4857 | |
| 4858 | r = simple_read_from_buffer(ubuf, cnt, ppos, buf, r); |
| 4859 | |
| 4860 | mutex_unlock(&dyn_info_mutex); |
| 4861 | |
| 4862 | return r; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4863 | } |
| 4864 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 4865 | static const struct file_operations tracing_dyn_info_fops = { |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4866 | .open = tracing_open_generic, |
Steven Rostedt | b807c3d | 2008-10-30 16:08:33 -0400 | [diff] [blame] | 4867 | .read = tracing_read_dyn_info, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 4868 | .llseek = generic_file_llseek, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4869 | }; |
| 4870 | #endif |
| 4871 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4872 | struct dentry *tracing_init_dentry_tr(struct trace_array *tr) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4873 | { |
| 4874 | static int once; |
| 4875 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4876 | if (tr->dir) |
| 4877 | return tr->dir; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4878 | |
Frederic Weisbecker | 3e1f60b | 2009-03-22 23:10:45 +0100 | [diff] [blame] | 4879 | if (!debugfs_initialized()) |
| 4880 | return NULL; |
| 4881 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4882 | if (tr->flags & TRACE_ARRAY_FL_GLOBAL) |
| 4883 | tr->dir = debugfs_create_dir("tracing", NULL); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4884 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4885 | if (!tr->dir && !once) { |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4886 | once = 1; |
| 4887 | pr_warning("Could not create debugfs directory 'tracing'\n"); |
| 4888 | return NULL; |
| 4889 | } |
| 4890 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4891 | return tr->dir; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4892 | } |
| 4893 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4894 | struct dentry *tracing_init_dentry(void) |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 4895 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4896 | return tracing_init_dentry_tr(&global_trace); |
| 4897 | } |
| 4898 | |
| 4899 | static struct dentry *tracing_dentry_percpu(struct trace_array *tr, int cpu) |
| 4900 | { |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 4901 | struct dentry *d_tracer; |
| 4902 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4903 | if (tr->percpu_dir) |
| 4904 | return tr->percpu_dir; |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 4905 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4906 | d_tracer = tracing_init_dentry_tr(tr); |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 4907 | if (!d_tracer) |
| 4908 | return NULL; |
| 4909 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4910 | tr->percpu_dir = debugfs_create_dir("per_cpu", d_tracer); |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 4911 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4912 | WARN_ONCE(!tr->percpu_dir, |
| 4913 | "Could not create debugfs directory 'per_cpu/%d'\n", cpu); |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 4914 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4915 | return tr->percpu_dir; |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 4916 | } |
| 4917 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4918 | static void |
| 4919 | tracing_init_debugfs_percpu(struct trace_array *tr, long cpu) |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 4920 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4921 | 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] | 4922 | struct dentry *d_percpu = tracing_dentry_percpu(tr, cpu); |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 4923 | struct dentry *d_cpu; |
Steven Rostedt | dd49a38 | 2010-10-20 21:51:26 -0400 | [diff] [blame] | 4924 | char cpu_dir[30]; /* 30 characters should be more than enough */ |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 4925 | |
Namhyung Kim | 0a3d7ce | 2012-04-23 10:11:57 +0900 | [diff] [blame] | 4926 | if (!d_percpu) |
| 4927 | return; |
| 4928 | |
Steven Rostedt | dd49a38 | 2010-10-20 21:51:26 -0400 | [diff] [blame] | 4929 | snprintf(cpu_dir, 30, "cpu%ld", cpu); |
Frederic Weisbecker | 8656e7a | 2009-02-26 00:41:38 +0100 | [diff] [blame] | 4930 | d_cpu = debugfs_create_dir(cpu_dir, d_percpu); |
| 4931 | if (!d_cpu) { |
| 4932 | pr_warning("Could not create debugfs '%s' entry\n", cpu_dir); |
| 4933 | return; |
| 4934 | } |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 4935 | |
Frederic Weisbecker | 8656e7a | 2009-02-26 00:41:38 +0100 | [diff] [blame] | 4936 | /* per cpu trace_pipe */ |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 4937 | trace_create_file("trace_pipe", 0444, d_cpu, |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4938 | (void *)&data->trace_cpu, &tracing_pipe_fops); |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 4939 | |
| 4940 | /* per cpu trace */ |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 4941 | trace_create_file("trace", 0644, d_cpu, |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4942 | (void *)&data->trace_cpu, &tracing_fops); |
Steven Rostedt | 7f96f93 | 2009-03-13 00:37:42 -0400 | [diff] [blame] | 4943 | |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 4944 | trace_create_file("trace_pipe_raw", 0444, d_cpu, |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4945 | (void *)&data->trace_cpu, &tracing_buffers_fops); |
Steven Rostedt | c8d7718 | 2009-04-29 18:03:45 -0400 | [diff] [blame] | 4946 | |
| 4947 | trace_create_file("stats", 0444, d_cpu, |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4948 | (void *)&data->trace_cpu, &tracing_stats_fops); |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 4949 | |
| 4950 | trace_create_file("buffer_size_kb", 0444, d_cpu, |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4951 | (void *)&data->trace_cpu, &tracing_entries_fops); |
Steven Rostedt (Red Hat) | f1affca | 2013-03-05 14:35:11 -0500 | [diff] [blame] | 4952 | |
| 4953 | #ifdef CONFIG_TRACER_SNAPSHOT |
| 4954 | trace_create_file("snapshot", 0644, d_cpu, |
| 4955 | (void *)&data->trace_cpu, &snapshot_fops); |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 4956 | |
| 4957 | trace_create_file("snapshot_raw", 0444, d_cpu, |
| 4958 | (void *)&data->trace_cpu, &snapshot_raw_fops); |
Steven Rostedt (Red Hat) | f1affca | 2013-03-05 14:35:11 -0500 | [diff] [blame] | 4959 | #endif |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 4960 | } |
| 4961 | |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 4962 | #ifdef CONFIG_FTRACE_SELFTEST |
| 4963 | /* Let selftest have access to static functions in this file */ |
| 4964 | #include "trace_selftest.c" |
| 4965 | #endif |
| 4966 | |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 4967 | struct trace_option_dentry { |
| 4968 | struct tracer_opt *opt; |
| 4969 | struct tracer_flags *flags; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4970 | struct trace_array *tr; |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 4971 | struct dentry *entry; |
| 4972 | }; |
| 4973 | |
| 4974 | static ssize_t |
| 4975 | trace_options_read(struct file *filp, char __user *ubuf, size_t cnt, |
| 4976 | loff_t *ppos) |
| 4977 | { |
| 4978 | struct trace_option_dentry *topt = filp->private_data; |
| 4979 | char *buf; |
| 4980 | |
| 4981 | if (topt->flags->val & topt->opt->bit) |
| 4982 | buf = "1\n"; |
| 4983 | else |
| 4984 | buf = "0\n"; |
| 4985 | |
| 4986 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, 2); |
| 4987 | } |
| 4988 | |
| 4989 | static ssize_t |
| 4990 | trace_options_write(struct file *filp, const char __user *ubuf, size_t cnt, |
| 4991 | loff_t *ppos) |
| 4992 | { |
| 4993 | struct trace_option_dentry *topt = filp->private_data; |
| 4994 | unsigned long val; |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 4995 | int ret; |
| 4996 | |
Peter Huewe | 22fe9b5 | 2011-06-07 21:58:27 +0200 | [diff] [blame] | 4997 | ret = kstrtoul_from_user(ubuf, cnt, 10, &val); |
| 4998 | if (ret) |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 4999 | return ret; |
| 5000 | |
Li Zefan | 8d18eaa | 2009-12-08 11:17:06 +0800 | [diff] [blame] | 5001 | if (val != 0 && val != 1) |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 5002 | return -EINVAL; |
Li Zefan | 8d18eaa | 2009-12-08 11:17:06 +0800 | [diff] [blame] | 5003 | |
| 5004 | if (!!(topt->flags->val & topt->opt->bit) != val) { |
| 5005 | mutex_lock(&trace_types_lock); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5006 | ret = __set_tracer_option(topt->tr->current_trace, topt->flags, |
Steven Rostedt | c757bea | 2009-12-21 22:35:16 -0500 | [diff] [blame] | 5007 | topt->opt, !val); |
Li Zefan | 8d18eaa | 2009-12-08 11:17:06 +0800 | [diff] [blame] | 5008 | mutex_unlock(&trace_types_lock); |
| 5009 | if (ret) |
| 5010 | return ret; |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 5011 | } |
| 5012 | |
| 5013 | *ppos += cnt; |
| 5014 | |
| 5015 | return cnt; |
| 5016 | } |
| 5017 | |
| 5018 | |
| 5019 | static const struct file_operations trace_options_fops = { |
| 5020 | .open = tracing_open_generic, |
| 5021 | .read = trace_options_read, |
| 5022 | .write = trace_options_write, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 5023 | .llseek = generic_file_llseek, |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 5024 | }; |
| 5025 | |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5026 | static ssize_t |
| 5027 | trace_options_core_read(struct file *filp, char __user *ubuf, size_t cnt, |
| 5028 | loff_t *ppos) |
| 5029 | { |
| 5030 | long index = (long)filp->private_data; |
| 5031 | char *buf; |
| 5032 | |
| 5033 | if (trace_flags & (1 << index)) |
| 5034 | buf = "1\n"; |
| 5035 | else |
| 5036 | buf = "0\n"; |
| 5037 | |
| 5038 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, 2); |
| 5039 | } |
| 5040 | |
| 5041 | static ssize_t |
| 5042 | trace_options_core_write(struct file *filp, const char __user *ubuf, size_t cnt, |
| 5043 | loff_t *ppos) |
| 5044 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5045 | struct trace_array *tr = &global_trace; |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5046 | long index = (long)filp->private_data; |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5047 | unsigned long val; |
| 5048 | int ret; |
| 5049 | |
Peter Huewe | 22fe9b5 | 2011-06-07 21:58:27 +0200 | [diff] [blame] | 5050 | ret = kstrtoul_from_user(ubuf, cnt, 10, &val); |
| 5051 | if (ret) |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5052 | return ret; |
| 5053 | |
Zhaolei | f2d84b6 | 2009-08-07 18:55:48 +0800 | [diff] [blame] | 5054 | if (val != 0 && val != 1) |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5055 | return -EINVAL; |
Steven Rostedt (Red Hat) | 69d34da | 2013-03-14 13:50:56 -0400 | [diff] [blame] | 5056 | |
| 5057 | mutex_lock(&trace_types_lock); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5058 | ret = set_tracer_flag(tr, 1 << index, val); |
Steven Rostedt (Red Hat) | 69d34da | 2013-03-14 13:50:56 -0400 | [diff] [blame] | 5059 | mutex_unlock(&trace_types_lock); |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5060 | |
Steven Rostedt (Red Hat) | 613f04a | 2013-03-14 15:03:53 -0400 | [diff] [blame] | 5061 | if (ret < 0) |
| 5062 | return ret; |
| 5063 | |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5064 | *ppos += cnt; |
| 5065 | |
| 5066 | return cnt; |
| 5067 | } |
| 5068 | |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5069 | static const struct file_operations trace_options_core_fops = { |
| 5070 | .open = tracing_open_generic, |
| 5071 | .read = trace_options_core_read, |
| 5072 | .write = trace_options_core_write, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 5073 | .llseek = generic_file_llseek, |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5074 | }; |
| 5075 | |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 5076 | struct dentry *trace_create_file(const char *name, |
Al Viro | f4ae40a6 | 2011-07-24 04:33:43 -0400 | [diff] [blame] | 5077 | umode_t mode, |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 5078 | struct dentry *parent, |
| 5079 | void *data, |
| 5080 | const struct file_operations *fops) |
| 5081 | { |
| 5082 | struct dentry *ret; |
| 5083 | |
| 5084 | ret = debugfs_create_file(name, mode, parent, data, fops); |
| 5085 | if (!ret) |
| 5086 | pr_warning("Could not create debugfs '%s' entry\n", name); |
| 5087 | |
| 5088 | return ret; |
| 5089 | } |
| 5090 | |
| 5091 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5092 | static struct dentry *trace_options_init_dentry(struct trace_array *tr) |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5093 | { |
| 5094 | struct dentry *d_tracer; |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5095 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5096 | if (tr->options) |
| 5097 | return tr->options; |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5098 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5099 | d_tracer = tracing_init_dentry_tr(tr); |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5100 | if (!d_tracer) |
| 5101 | return NULL; |
| 5102 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5103 | tr->options = debugfs_create_dir("options", d_tracer); |
| 5104 | if (!tr->options) { |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5105 | pr_warning("Could not create debugfs directory 'options'\n"); |
| 5106 | return NULL; |
| 5107 | } |
| 5108 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5109 | return tr->options; |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5110 | } |
| 5111 | |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 5112 | static void |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5113 | create_trace_option_file(struct trace_array *tr, |
| 5114 | struct trace_option_dentry *topt, |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 5115 | struct tracer_flags *flags, |
| 5116 | struct tracer_opt *opt) |
| 5117 | { |
| 5118 | struct dentry *t_options; |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 5119 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5120 | t_options = trace_options_init_dentry(tr); |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 5121 | if (!t_options) |
| 5122 | return; |
| 5123 | |
| 5124 | topt->flags = flags; |
| 5125 | topt->opt = opt; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5126 | topt->tr = tr; |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 5127 | |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 5128 | topt->entry = trace_create_file(opt->name, 0644, t_options, topt, |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 5129 | &trace_options_fops); |
| 5130 | |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 5131 | } |
| 5132 | |
| 5133 | static struct trace_option_dentry * |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5134 | create_trace_option_files(struct trace_array *tr, struct tracer *tracer) |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 5135 | { |
| 5136 | struct trace_option_dentry *topts; |
| 5137 | struct tracer_flags *flags; |
| 5138 | struct tracer_opt *opts; |
| 5139 | int cnt; |
| 5140 | |
| 5141 | if (!tracer) |
| 5142 | return NULL; |
| 5143 | |
| 5144 | flags = tracer->flags; |
| 5145 | |
| 5146 | if (!flags || !flags->opts) |
| 5147 | return NULL; |
| 5148 | |
| 5149 | opts = flags->opts; |
| 5150 | |
| 5151 | for (cnt = 0; opts[cnt].name; cnt++) |
| 5152 | ; |
| 5153 | |
Steven Rostedt | 0cfe824 | 2009-02-27 10:51:10 -0500 | [diff] [blame] | 5154 | topts = kcalloc(cnt + 1, sizeof(*topts), GFP_KERNEL); |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 5155 | if (!topts) |
| 5156 | return NULL; |
| 5157 | |
| 5158 | for (cnt = 0; opts[cnt].name; cnt++) |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5159 | create_trace_option_file(tr, &topts[cnt], flags, |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 5160 | &opts[cnt]); |
| 5161 | |
| 5162 | return topts; |
| 5163 | } |
| 5164 | |
| 5165 | static void |
| 5166 | destroy_trace_option_files(struct trace_option_dentry *topts) |
| 5167 | { |
| 5168 | int cnt; |
| 5169 | |
| 5170 | if (!topts) |
| 5171 | return; |
| 5172 | |
| 5173 | for (cnt = 0; topts[cnt].opt; cnt++) { |
| 5174 | if (topts[cnt].entry) |
| 5175 | debugfs_remove(topts[cnt].entry); |
| 5176 | } |
| 5177 | |
| 5178 | kfree(topts); |
| 5179 | } |
| 5180 | |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5181 | static struct dentry * |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5182 | create_trace_option_core_file(struct trace_array *tr, |
| 5183 | const char *option, long index) |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5184 | { |
| 5185 | struct dentry *t_options; |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5186 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5187 | t_options = trace_options_init_dentry(tr); |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5188 | if (!t_options) |
| 5189 | return NULL; |
| 5190 | |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 5191 | return trace_create_file(option, 0644, t_options, (void *)index, |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5192 | &trace_options_core_fops); |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5193 | } |
| 5194 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5195 | static __init void create_trace_options_dir(struct trace_array *tr) |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5196 | { |
| 5197 | struct dentry *t_options; |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5198 | int i; |
| 5199 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5200 | t_options = trace_options_init_dentry(tr); |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5201 | if (!t_options) |
| 5202 | return; |
| 5203 | |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 5204 | for (i = 0; trace_options[i]; i++) |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5205 | create_trace_option_core_file(tr, trace_options[i], i); |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5206 | } |
| 5207 | |
Steven Rostedt | 499e547 | 2012-02-22 15:50:28 -0500 | [diff] [blame] | 5208 | static ssize_t |
| 5209 | rb_simple_read(struct file *filp, char __user *ubuf, |
| 5210 | size_t cnt, loff_t *ppos) |
| 5211 | { |
Steven Rostedt | 348f0fc | 2012-04-16 15:41:28 -0400 | [diff] [blame] | 5212 | struct trace_array *tr = filp->private_data; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5213 | struct ring_buffer *buffer = tr->trace_buffer.buffer; |
Steven Rostedt | 499e547 | 2012-02-22 15:50:28 -0500 | [diff] [blame] | 5214 | char buf[64]; |
| 5215 | int r; |
| 5216 | |
| 5217 | if (buffer) |
| 5218 | r = ring_buffer_record_is_on(buffer); |
| 5219 | else |
| 5220 | r = 0; |
| 5221 | |
| 5222 | r = sprintf(buf, "%d\n", r); |
| 5223 | |
| 5224 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, r); |
| 5225 | } |
| 5226 | |
| 5227 | static ssize_t |
| 5228 | rb_simple_write(struct file *filp, const char __user *ubuf, |
| 5229 | size_t cnt, loff_t *ppos) |
| 5230 | { |
Steven Rostedt | 348f0fc | 2012-04-16 15:41:28 -0400 | [diff] [blame] | 5231 | struct trace_array *tr = filp->private_data; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5232 | struct ring_buffer *buffer = tr->trace_buffer.buffer; |
Steven Rostedt | 499e547 | 2012-02-22 15:50:28 -0500 | [diff] [blame] | 5233 | unsigned long val; |
| 5234 | int ret; |
| 5235 | |
| 5236 | ret = kstrtoul_from_user(ubuf, cnt, 10, &val); |
| 5237 | if (ret) |
| 5238 | return ret; |
| 5239 | |
| 5240 | if (buffer) { |
Steven Rostedt | 2df8f8a | 2013-01-11 16:14:10 -0500 | [diff] [blame] | 5241 | mutex_lock(&trace_types_lock); |
| 5242 | if (val) { |
Steven Rostedt | 499e547 | 2012-02-22 15:50:28 -0500 | [diff] [blame] | 5243 | ring_buffer_record_on(buffer); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5244 | if (tr->current_trace->start) |
| 5245 | tr->current_trace->start(tr); |
Steven Rostedt | 2df8f8a | 2013-01-11 16:14:10 -0500 | [diff] [blame] | 5246 | } else { |
Steven Rostedt | 499e547 | 2012-02-22 15:50:28 -0500 | [diff] [blame] | 5247 | ring_buffer_record_off(buffer); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5248 | if (tr->current_trace->stop) |
| 5249 | tr->current_trace->stop(tr); |
Steven Rostedt | 2df8f8a | 2013-01-11 16:14:10 -0500 | [diff] [blame] | 5250 | } |
| 5251 | mutex_unlock(&trace_types_lock); |
Steven Rostedt | 499e547 | 2012-02-22 15:50:28 -0500 | [diff] [blame] | 5252 | } |
| 5253 | |
| 5254 | (*ppos)++; |
| 5255 | |
| 5256 | return cnt; |
| 5257 | } |
| 5258 | |
| 5259 | static const struct file_operations rb_simple_fops = { |
| 5260 | .open = tracing_open_generic, |
| 5261 | .read = rb_simple_read, |
| 5262 | .write = rb_simple_write, |
| 5263 | .llseek = default_llseek, |
| 5264 | }; |
| 5265 | |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 5266 | struct dentry *trace_instance_dir; |
| 5267 | |
| 5268 | static void |
| 5269 | init_tracer_debugfs(struct trace_array *tr, struct dentry *d_tracer); |
| 5270 | |
Steven Rostedt (Red Hat) | 737223f | 2013-03-05 21:13:47 -0500 | [diff] [blame^] | 5271 | static void init_trace_buffers(struct trace_array *tr, struct trace_buffer *buf) |
| 5272 | { |
| 5273 | int cpu; |
| 5274 | |
| 5275 | for_each_tracing_cpu(cpu) { |
| 5276 | memset(per_cpu_ptr(buf->data, cpu), 0, sizeof(struct trace_array_cpu)); |
| 5277 | per_cpu_ptr(buf->data, cpu)->trace_cpu.cpu = cpu; |
| 5278 | per_cpu_ptr(buf->data, cpu)->trace_cpu.tr = tr; |
| 5279 | } |
| 5280 | } |
| 5281 | |
| 5282 | static int allocate_trace_buffers(struct trace_array *tr, int size) |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 5283 | { |
| 5284 | enum ring_buffer_flags rb_flags; |
Steven Rostedt (Red Hat) | 737223f | 2013-03-05 21:13:47 -0500 | [diff] [blame^] | 5285 | |
| 5286 | rb_flags = trace_flags & TRACE_ITER_OVERWRITE ? RB_FL_OVERWRITE : 0; |
| 5287 | |
| 5288 | tr->trace_buffer.buffer = ring_buffer_alloc(size, rb_flags); |
| 5289 | if (!tr->trace_buffer.buffer) |
| 5290 | goto out_free; |
| 5291 | |
| 5292 | tr->trace_buffer.data = alloc_percpu(struct trace_array_cpu); |
| 5293 | if (!tr->trace_buffer.data) |
| 5294 | goto out_free; |
| 5295 | |
| 5296 | init_trace_buffers(tr, &tr->trace_buffer); |
| 5297 | |
| 5298 | /* Allocate the first page for all buffers */ |
| 5299 | set_buffer_entries(&tr->trace_buffer, |
| 5300 | ring_buffer_size(tr->trace_buffer.buffer, 0)); |
| 5301 | |
| 5302 | #ifdef CONFIG_TRACER_MAX_TRACE |
| 5303 | |
| 5304 | tr->max_buffer.buffer = ring_buffer_alloc(1, rb_flags); |
| 5305 | if (!tr->max_buffer.buffer) |
| 5306 | goto out_free; |
| 5307 | |
| 5308 | tr->max_buffer.data = alloc_percpu(struct trace_array_cpu); |
| 5309 | if (!tr->max_buffer.data) |
| 5310 | goto out_free; |
| 5311 | |
| 5312 | init_trace_buffers(tr, &tr->max_buffer); |
| 5313 | |
| 5314 | set_buffer_entries(&tr->max_buffer, 1); |
| 5315 | #endif |
| 5316 | return 0; |
| 5317 | |
| 5318 | out_free: |
| 5319 | if (tr->trace_buffer.buffer) |
| 5320 | ring_buffer_free(tr->trace_buffer.buffer); |
| 5321 | free_percpu(tr->trace_buffer.data); |
| 5322 | |
| 5323 | #ifdef CONFIG_TRACER_MAX_TRACE |
| 5324 | if (tr->max_buffer.buffer) |
| 5325 | ring_buffer_free(tr->max_buffer.buffer); |
| 5326 | free_percpu(tr->max_buffer.data); |
| 5327 | #endif |
| 5328 | return -ENOMEM; |
| 5329 | } |
| 5330 | |
| 5331 | static int new_instance_create(const char *name) |
| 5332 | { |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 5333 | struct trace_array *tr; |
| 5334 | int ret; |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 5335 | |
| 5336 | mutex_lock(&trace_types_lock); |
| 5337 | |
| 5338 | ret = -EEXIST; |
| 5339 | list_for_each_entry(tr, &ftrace_trace_arrays, list) { |
| 5340 | if (tr->name && strcmp(tr->name, name) == 0) |
| 5341 | goto out_unlock; |
| 5342 | } |
| 5343 | |
| 5344 | ret = -ENOMEM; |
| 5345 | tr = kzalloc(sizeof(*tr), GFP_KERNEL); |
| 5346 | if (!tr) |
| 5347 | goto out_unlock; |
| 5348 | |
| 5349 | tr->name = kstrdup(name, GFP_KERNEL); |
| 5350 | if (!tr->name) |
| 5351 | goto out_free_tr; |
| 5352 | |
| 5353 | raw_spin_lock_init(&tr->start_lock); |
| 5354 | |
| 5355 | tr->current_trace = &nop_trace; |
| 5356 | |
| 5357 | INIT_LIST_HEAD(&tr->systems); |
| 5358 | INIT_LIST_HEAD(&tr->events); |
| 5359 | |
Steven Rostedt (Red Hat) | 737223f | 2013-03-05 21:13:47 -0500 | [diff] [blame^] | 5360 | if (allocate_trace_buffers(tr, trace_buf_size) < 0) |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 5361 | goto out_free_tr; |
| 5362 | |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 5363 | /* Holder for file callbacks */ |
| 5364 | tr->trace_cpu.cpu = RING_BUFFER_ALL_CPUS; |
| 5365 | tr->trace_cpu.tr = tr; |
| 5366 | |
| 5367 | tr->dir = debugfs_create_dir(name, trace_instance_dir); |
| 5368 | if (!tr->dir) |
| 5369 | goto out_free_tr; |
| 5370 | |
| 5371 | ret = event_trace_add_tracer(tr->dir, tr); |
| 5372 | if (ret) |
| 5373 | goto out_free_tr; |
| 5374 | |
| 5375 | init_tracer_debugfs(tr, tr->dir); |
| 5376 | |
| 5377 | list_add(&tr->list, &ftrace_trace_arrays); |
| 5378 | |
| 5379 | mutex_unlock(&trace_types_lock); |
| 5380 | |
| 5381 | return 0; |
| 5382 | |
| 5383 | out_free_tr: |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5384 | if (tr->trace_buffer.buffer) |
| 5385 | ring_buffer_free(tr->trace_buffer.buffer); |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 5386 | kfree(tr->name); |
| 5387 | kfree(tr); |
| 5388 | |
| 5389 | out_unlock: |
| 5390 | mutex_unlock(&trace_types_lock); |
| 5391 | |
| 5392 | return ret; |
| 5393 | |
| 5394 | } |
| 5395 | |
Steven Rostedt | 0c8916c | 2012-08-07 16:14:16 -0400 | [diff] [blame] | 5396 | static int instance_delete(const char *name) |
| 5397 | { |
| 5398 | struct trace_array *tr; |
| 5399 | int found = 0; |
| 5400 | int ret; |
| 5401 | |
| 5402 | mutex_lock(&trace_types_lock); |
| 5403 | |
| 5404 | ret = -ENODEV; |
| 5405 | list_for_each_entry(tr, &ftrace_trace_arrays, list) { |
| 5406 | if (tr->name && strcmp(tr->name, name) == 0) { |
| 5407 | found = 1; |
| 5408 | break; |
| 5409 | } |
| 5410 | } |
| 5411 | if (!found) |
| 5412 | goto out_unlock; |
| 5413 | |
| 5414 | list_del(&tr->list); |
| 5415 | |
| 5416 | event_trace_del_tracer(tr); |
| 5417 | debugfs_remove_recursive(tr->dir); |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5418 | free_percpu(tr->trace_buffer.data); |
| 5419 | ring_buffer_free(tr->trace_buffer.buffer); |
Steven Rostedt | 0c8916c | 2012-08-07 16:14:16 -0400 | [diff] [blame] | 5420 | |
| 5421 | kfree(tr->name); |
| 5422 | kfree(tr); |
| 5423 | |
| 5424 | ret = 0; |
| 5425 | |
| 5426 | out_unlock: |
| 5427 | mutex_unlock(&trace_types_lock); |
| 5428 | |
| 5429 | return ret; |
| 5430 | } |
| 5431 | |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 5432 | static int instance_mkdir (struct inode *inode, struct dentry *dentry, umode_t mode) |
| 5433 | { |
| 5434 | struct dentry *parent; |
| 5435 | int ret; |
| 5436 | |
| 5437 | /* Paranoid: Make sure the parent is the "instances" directory */ |
| 5438 | parent = hlist_entry(inode->i_dentry.first, struct dentry, d_alias); |
| 5439 | if (WARN_ON_ONCE(parent != trace_instance_dir)) |
| 5440 | return -ENOENT; |
| 5441 | |
| 5442 | /* |
| 5443 | * The inode mutex is locked, but debugfs_create_dir() will also |
| 5444 | * take the mutex. As the instances directory can not be destroyed |
| 5445 | * or changed in any other way, it is safe to unlock it, and |
| 5446 | * let the dentry try. If two users try to make the same dir at |
| 5447 | * the same time, then the new_instance_create() will determine the |
| 5448 | * winner. |
| 5449 | */ |
| 5450 | mutex_unlock(&inode->i_mutex); |
| 5451 | |
| 5452 | ret = new_instance_create(dentry->d_iname); |
| 5453 | |
| 5454 | mutex_lock(&inode->i_mutex); |
| 5455 | |
| 5456 | return ret; |
| 5457 | } |
| 5458 | |
Steven Rostedt | 0c8916c | 2012-08-07 16:14:16 -0400 | [diff] [blame] | 5459 | static int instance_rmdir(struct inode *inode, struct dentry *dentry) |
| 5460 | { |
| 5461 | struct dentry *parent; |
| 5462 | int ret; |
| 5463 | |
| 5464 | /* Paranoid: Make sure the parent is the "instances" directory */ |
| 5465 | parent = hlist_entry(inode->i_dentry.first, struct dentry, d_alias); |
| 5466 | if (WARN_ON_ONCE(parent != trace_instance_dir)) |
| 5467 | return -ENOENT; |
| 5468 | |
| 5469 | /* The caller did a dget() on dentry */ |
| 5470 | mutex_unlock(&dentry->d_inode->i_mutex); |
| 5471 | |
| 5472 | /* |
| 5473 | * The inode mutex is locked, but debugfs_create_dir() will also |
| 5474 | * take the mutex. As the instances directory can not be destroyed |
| 5475 | * or changed in any other way, it is safe to unlock it, and |
| 5476 | * let the dentry try. If two users try to make the same dir at |
| 5477 | * the same time, then the instance_delete() will determine the |
| 5478 | * winner. |
| 5479 | */ |
| 5480 | mutex_unlock(&inode->i_mutex); |
| 5481 | |
| 5482 | ret = instance_delete(dentry->d_iname); |
| 5483 | |
| 5484 | mutex_lock_nested(&inode->i_mutex, I_MUTEX_PARENT); |
| 5485 | mutex_lock(&dentry->d_inode->i_mutex); |
| 5486 | |
| 5487 | return ret; |
| 5488 | } |
| 5489 | |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 5490 | static const struct inode_operations instance_dir_inode_operations = { |
| 5491 | .lookup = simple_lookup, |
| 5492 | .mkdir = instance_mkdir, |
Steven Rostedt | 0c8916c | 2012-08-07 16:14:16 -0400 | [diff] [blame] | 5493 | .rmdir = instance_rmdir, |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 5494 | }; |
| 5495 | |
| 5496 | static __init void create_trace_instances(struct dentry *d_tracer) |
| 5497 | { |
| 5498 | trace_instance_dir = debugfs_create_dir("instances", d_tracer); |
| 5499 | if (WARN_ON(!trace_instance_dir)) |
| 5500 | return; |
| 5501 | |
| 5502 | /* Hijack the dir inode operations, to allow mkdir */ |
| 5503 | trace_instance_dir->d_inode->i_op = &instance_dir_inode_operations; |
| 5504 | } |
| 5505 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5506 | static void |
| 5507 | init_tracer_debugfs(struct trace_array *tr, struct dentry *d_tracer) |
| 5508 | { |
| 5509 | |
| 5510 | trace_create_file("trace_options", 0644, d_tracer, |
| 5511 | tr, &tracing_iter_fops); |
| 5512 | |
| 5513 | trace_create_file("trace", 0644, d_tracer, |
| 5514 | (void *)&tr->trace_cpu, &tracing_fops); |
| 5515 | |
| 5516 | trace_create_file("trace_pipe", 0444, d_tracer, |
| 5517 | (void *)&tr->trace_cpu, &tracing_pipe_fops); |
| 5518 | |
| 5519 | trace_create_file("buffer_size_kb", 0644, d_tracer, |
| 5520 | (void *)&tr->trace_cpu, &tracing_entries_fops); |
| 5521 | |
| 5522 | trace_create_file("buffer_total_size_kb", 0444, d_tracer, |
| 5523 | tr, &tracing_total_entries_fops); |
| 5524 | |
| 5525 | trace_create_file("free_buffer", 0644, d_tracer, |
| 5526 | tr, &tracing_free_buffer_fops); |
| 5527 | |
| 5528 | trace_create_file("trace_marker", 0220, d_tracer, |
| 5529 | tr, &tracing_mark_fops); |
| 5530 | |
| 5531 | trace_create_file("trace_clock", 0644, d_tracer, tr, |
| 5532 | &trace_clock_fops); |
| 5533 | |
| 5534 | trace_create_file("tracing_on", 0644, d_tracer, |
| 5535 | tr, &rb_simple_fops); |
| 5536 | } |
| 5537 | |
Frédéric Weisbecker | b5ad384 | 2008-09-23 11:34:32 +0100 | [diff] [blame] | 5538 | static __init int tracer_init_debugfs(void) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5539 | { |
| 5540 | struct dentry *d_tracer; |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 5541 | int cpu; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5542 | |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 5543 | trace_access_lock_init(); |
| 5544 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5545 | d_tracer = tracing_init_dentry(); |
| 5546 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5547 | init_tracer_debugfs(&global_trace, d_tracer); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5548 | |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 5549 | trace_create_file("tracing_cpumask", 0644, d_tracer, |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5550 | &global_trace, &tracing_cpumask_fops); |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 5551 | |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 5552 | trace_create_file("available_tracers", 0444, d_tracer, |
| 5553 | &global_trace, &show_traces_fops); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5554 | |
Li Zefan | 339ae5d | 2009-04-17 10:34:30 +0800 | [diff] [blame] | 5555 | trace_create_file("current_tracer", 0644, d_tracer, |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 5556 | &global_trace, &set_tracer_fops); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5557 | |
Steven Rostedt | 5d4a9db | 2009-08-27 16:52:21 -0400 | [diff] [blame] | 5558 | #ifdef CONFIG_TRACER_MAX_TRACE |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 5559 | trace_create_file("tracing_max_latency", 0644, d_tracer, |
| 5560 | &tracing_max_latency, &tracing_max_lat_fops); |
Tim Bird | 0e95017 | 2010-02-25 15:36:43 -0800 | [diff] [blame] | 5561 | #endif |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5562 | |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 5563 | trace_create_file("tracing_thresh", 0644, d_tracer, |
| 5564 | &tracing_thresh, &tracing_max_lat_fops); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5565 | |
Li Zefan | 339ae5d | 2009-04-17 10:34:30 +0800 | [diff] [blame] | 5566 | trace_create_file("README", 0444, d_tracer, |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 5567 | NULL, &tracing_readme_fops); |
Ingo Molnar | 7bd2f24 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 5568 | |
Avadh Patel | 69abe6a | 2009-04-10 16:04:48 -0400 | [diff] [blame] | 5569 | trace_create_file("saved_cmdlines", 0444, d_tracer, |
| 5570 | NULL, &tracing_saved_cmdlines_fops); |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 5571 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5572 | #ifdef CONFIG_DYNAMIC_FTRACE |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 5573 | trace_create_file("dyn_ftrace_total_info", 0444, d_tracer, |
| 5574 | &ftrace_update_tot_cnt, &tracing_dyn_info_fops); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5575 | #endif |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 5576 | |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 5577 | #ifdef CONFIG_TRACER_SNAPSHOT |
| 5578 | trace_create_file("snapshot", 0644, d_tracer, |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5579 | (void *)&global_trace.trace_cpu, &snapshot_fops); |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 5580 | #endif |
| 5581 | |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 5582 | create_trace_instances(d_tracer); |
| 5583 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5584 | create_trace_options_dir(&global_trace); |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 5585 | |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 5586 | for_each_tracing_cpu(cpu) |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5587 | tracing_init_debugfs_percpu(&global_trace, cpu); |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 5588 | |
Frédéric Weisbecker | b5ad384 | 2008-09-23 11:34:32 +0100 | [diff] [blame] | 5589 | return 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5590 | } |
| 5591 | |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 5592 | static int trace_panic_handler(struct notifier_block *this, |
| 5593 | unsigned long event, void *unused) |
| 5594 | { |
Steven Rostedt | 944ac42 | 2008-10-23 19:26:08 -0400 | [diff] [blame] | 5595 | if (ftrace_dump_on_oops) |
Frederic Weisbecker | cecbca9 | 2010-04-18 19:08:41 +0200 | [diff] [blame] | 5596 | ftrace_dump(ftrace_dump_on_oops); |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 5597 | return NOTIFY_OK; |
| 5598 | } |
| 5599 | |
| 5600 | static struct notifier_block trace_panic_notifier = { |
| 5601 | .notifier_call = trace_panic_handler, |
| 5602 | .next = NULL, |
| 5603 | .priority = 150 /* priority: INT_MAX >= x >= 0 */ |
| 5604 | }; |
| 5605 | |
| 5606 | static int trace_die_handler(struct notifier_block *self, |
| 5607 | unsigned long val, |
| 5608 | void *data) |
| 5609 | { |
| 5610 | switch (val) { |
| 5611 | case DIE_OOPS: |
Steven Rostedt | 944ac42 | 2008-10-23 19:26:08 -0400 | [diff] [blame] | 5612 | if (ftrace_dump_on_oops) |
Frederic Weisbecker | cecbca9 | 2010-04-18 19:08:41 +0200 | [diff] [blame] | 5613 | ftrace_dump(ftrace_dump_on_oops); |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 5614 | break; |
| 5615 | default: |
| 5616 | break; |
| 5617 | } |
| 5618 | return NOTIFY_OK; |
| 5619 | } |
| 5620 | |
| 5621 | static struct notifier_block trace_die_notifier = { |
| 5622 | .notifier_call = trace_die_handler, |
| 5623 | .priority = 200 |
| 5624 | }; |
| 5625 | |
| 5626 | /* |
| 5627 | * printk is set to max of 1024, we really don't need it that big. |
| 5628 | * Nothing should be printing 1000 characters anyway. |
| 5629 | */ |
| 5630 | #define TRACE_MAX_PRINT 1000 |
| 5631 | |
| 5632 | /* |
| 5633 | * Define here KERN_TRACE so that we have one place to modify |
| 5634 | * it if we decide to change what log level the ftrace dump |
| 5635 | * should be at. |
| 5636 | */ |
Steven Rostedt | 428aee1 | 2009-01-14 12:24:42 -0500 | [diff] [blame] | 5637 | #define KERN_TRACE KERN_EMERG |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 5638 | |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 5639 | void |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 5640 | trace_printk_seq(struct trace_seq *s) |
| 5641 | { |
| 5642 | /* Probably should print a warning here. */ |
| 5643 | if (s->len >= 1000) |
| 5644 | s->len = 1000; |
| 5645 | |
| 5646 | /* should be zero ended, but we are paranoid. */ |
| 5647 | s->buffer[s->len] = 0; |
| 5648 | |
| 5649 | printk(KERN_TRACE "%s", s->buffer); |
| 5650 | |
Steven Rostedt | f952075 | 2009-03-02 14:04:40 -0500 | [diff] [blame] | 5651 | trace_seq_init(s); |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 5652 | } |
| 5653 | |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 5654 | void trace_init_global_iter(struct trace_iterator *iter) |
| 5655 | { |
| 5656 | iter->tr = &global_trace; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5657 | iter->trace = iter->tr->current_trace; |
Steven Rostedt | ae3b509 | 2013-01-23 15:22:59 -0500 | [diff] [blame] | 5658 | iter->cpu_file = RING_BUFFER_ALL_CPUS; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5659 | iter->trace_buffer = &global_trace.trace_buffer; |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 5660 | } |
| 5661 | |
Frederic Weisbecker | cecbca9 | 2010-04-18 19:08:41 +0200 | [diff] [blame] | 5662 | static void |
| 5663 | __ftrace_dump(bool disable_tracing, enum ftrace_dump_mode oops_dump_mode) |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 5664 | { |
Thomas Gleixner | 445c895 | 2009-12-02 19:49:50 +0100 | [diff] [blame] | 5665 | static arch_spinlock_t ftrace_dump_lock = |
Thomas Gleixner | edc35bd | 2009-12-03 12:38:57 +0100 | [diff] [blame] | 5666 | (arch_spinlock_t)__ARCH_SPIN_LOCK_UNLOCKED; |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 5667 | /* use static because iter can be a bit big for the stack */ |
| 5668 | static struct trace_iterator iter; |
Frederic Weisbecker | cf586b6 | 2009-03-22 05:04:35 +0100 | [diff] [blame] | 5669 | unsigned int old_userobj; |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 5670 | static int dump_ran; |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 5671 | unsigned long flags; |
| 5672 | int cnt = 0, cpu; |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 5673 | |
| 5674 | /* only one dump */ |
Steven Rostedt | cd891ae | 2009-04-28 11:39:34 -0400 | [diff] [blame] | 5675 | local_irq_save(flags); |
Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 5676 | arch_spin_lock(&ftrace_dump_lock); |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 5677 | if (dump_ran) |
| 5678 | goto out; |
| 5679 | |
| 5680 | dump_ran = 1; |
| 5681 | |
Steven Rostedt | 0ee6b6c | 2009-01-14 14:50:19 -0500 | [diff] [blame] | 5682 | tracing_off(); |
Frederic Weisbecker | cf586b6 | 2009-03-22 05:04:35 +0100 | [diff] [blame] | 5683 | |
Steven Rostedt | e0a413f | 2011-09-29 21:26:16 -0400 | [diff] [blame] | 5684 | /* Did function tracer already get disabled? */ |
| 5685 | if (ftrace_is_dead()) { |
| 5686 | printk("# WARNING: FUNCTION TRACING IS CORRUPTED\n"); |
| 5687 | printk("# MAY BE MISSING FUNCTION EVENTS\n"); |
| 5688 | } |
| 5689 | |
Frederic Weisbecker | cf586b6 | 2009-03-22 05:04:35 +0100 | [diff] [blame] | 5690 | if (disable_tracing) |
| 5691 | ftrace_kill(); |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 5692 | |
Jovi Zhang | 38dbe0b | 2013-01-25 18:03:07 +0800 | [diff] [blame] | 5693 | /* Simulate the iterator */ |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 5694 | trace_init_global_iter(&iter); |
| 5695 | |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 5696 | for_each_tracing_cpu(cpu) { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5697 | atomic_inc(&per_cpu_ptr(iter.tr->trace_buffer.data, cpu)->disabled); |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 5698 | } |
| 5699 | |
Frederic Weisbecker | cf586b6 | 2009-03-22 05:04:35 +0100 | [diff] [blame] | 5700 | old_userobj = trace_flags & TRACE_ITER_SYM_USEROBJ; |
| 5701 | |
Török Edwin | b54d3de | 2008-11-22 13:28:48 +0200 | [diff] [blame] | 5702 | /* don't look at user memory in panic mode */ |
| 5703 | trace_flags &= ~TRACE_ITER_SYM_USEROBJ; |
| 5704 | |
Frederic Weisbecker | cecbca9 | 2010-04-18 19:08:41 +0200 | [diff] [blame] | 5705 | switch (oops_dump_mode) { |
| 5706 | case DUMP_ALL: |
Steven Rostedt | ae3b509 | 2013-01-23 15:22:59 -0500 | [diff] [blame] | 5707 | iter.cpu_file = RING_BUFFER_ALL_CPUS; |
Frederic Weisbecker | cecbca9 | 2010-04-18 19:08:41 +0200 | [diff] [blame] | 5708 | break; |
| 5709 | case DUMP_ORIG: |
| 5710 | iter.cpu_file = raw_smp_processor_id(); |
| 5711 | break; |
| 5712 | case DUMP_NONE: |
| 5713 | goto out_enable; |
| 5714 | default: |
| 5715 | printk(KERN_TRACE "Bad dumping mode, switching to all CPUs dump\n"); |
Steven Rostedt | ae3b509 | 2013-01-23 15:22:59 -0500 | [diff] [blame] | 5716 | iter.cpu_file = RING_BUFFER_ALL_CPUS; |
Frederic Weisbecker | cecbca9 | 2010-04-18 19:08:41 +0200 | [diff] [blame] | 5717 | } |
| 5718 | |
| 5719 | printk(KERN_TRACE "Dumping ftrace buffer:\n"); |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 5720 | |
| 5721 | /* |
| 5722 | * We need to stop all tracing on all CPUS to read the |
| 5723 | * the next buffer. This is a bit expensive, but is |
| 5724 | * not done often. We fill all what we can read, |
| 5725 | * and then release the locks again. |
| 5726 | */ |
| 5727 | |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 5728 | while (!trace_empty(&iter)) { |
| 5729 | |
| 5730 | if (!cnt) |
| 5731 | printk(KERN_TRACE "---------------------------------\n"); |
| 5732 | |
| 5733 | cnt++; |
| 5734 | |
| 5735 | /* reset all but tr, trace, and overruns */ |
| 5736 | memset(&iter.seq, 0, |
| 5737 | sizeof(struct trace_iterator) - |
| 5738 | offsetof(struct trace_iterator, seq)); |
| 5739 | iter.iter_flags |= TRACE_FILE_LAT_FMT; |
| 5740 | iter.pos = -1; |
| 5741 | |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 5742 | if (trace_find_next_entry_inc(&iter) != NULL) { |
Lai Jiangshan | 74e7ff8 | 2009-07-28 20:17:22 +0800 | [diff] [blame] | 5743 | int ret; |
| 5744 | |
| 5745 | ret = print_trace_line(&iter); |
| 5746 | if (ret != TRACE_TYPE_NO_CONSUME) |
| 5747 | trace_consume(&iter); |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 5748 | } |
Steven Rostedt | b892e5c | 2012-03-01 22:06:48 -0500 | [diff] [blame] | 5749 | touch_nmi_watchdog(); |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 5750 | |
| 5751 | trace_printk_seq(&iter.seq); |
| 5752 | } |
| 5753 | |
| 5754 | if (!cnt) |
| 5755 | printk(KERN_TRACE " (ftrace buffer empty)\n"); |
| 5756 | else |
| 5757 | printk(KERN_TRACE "---------------------------------\n"); |
| 5758 | |
Frederic Weisbecker | cecbca9 | 2010-04-18 19:08:41 +0200 | [diff] [blame] | 5759 | out_enable: |
Frederic Weisbecker | cf586b6 | 2009-03-22 05:04:35 +0100 | [diff] [blame] | 5760 | /* Re-enable tracing if requested */ |
| 5761 | if (!disable_tracing) { |
| 5762 | trace_flags |= old_userobj; |
| 5763 | |
| 5764 | for_each_tracing_cpu(cpu) { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5765 | atomic_dec(&per_cpu_ptr(iter.trace_buffer->data, cpu)->disabled); |
Frederic Weisbecker | cf586b6 | 2009-03-22 05:04:35 +0100 | [diff] [blame] | 5766 | } |
| 5767 | tracing_on(); |
| 5768 | } |
| 5769 | |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 5770 | out: |
Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 5771 | arch_spin_unlock(&ftrace_dump_lock); |
Steven Rostedt | cd891ae | 2009-04-28 11:39:34 -0400 | [diff] [blame] | 5772 | local_irq_restore(flags); |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 5773 | } |
| 5774 | |
Frederic Weisbecker | cf586b6 | 2009-03-22 05:04:35 +0100 | [diff] [blame] | 5775 | /* By default: disable tracing after the dump */ |
Frederic Weisbecker | cecbca9 | 2010-04-18 19:08:41 +0200 | [diff] [blame] | 5776 | void ftrace_dump(enum ftrace_dump_mode oops_dump_mode) |
Frederic Weisbecker | cf586b6 | 2009-03-22 05:04:35 +0100 | [diff] [blame] | 5777 | { |
Frederic Weisbecker | cecbca9 | 2010-04-18 19:08:41 +0200 | [diff] [blame] | 5778 | __ftrace_dump(true, oops_dump_mode); |
Frederic Weisbecker | cf586b6 | 2009-03-22 05:04:35 +0100 | [diff] [blame] | 5779 | } |
Paul E. McKenney | a8eecf2 | 2011-10-02 11:01:15 -0700 | [diff] [blame] | 5780 | EXPORT_SYMBOL_GPL(ftrace_dump); |
Frederic Weisbecker | cf586b6 | 2009-03-22 05:04:35 +0100 | [diff] [blame] | 5781 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5782 | __init static int tracer_alloc_buffers(void) |
| 5783 | { |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 5784 | int ring_buf_size; |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 5785 | int ret = -ENOMEM; |
| 5786 | |
David Sharp | 750912f | 2010-12-08 13:46:47 -0800 | [diff] [blame] | 5787 | |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 5788 | if (!alloc_cpumask_var(&tracing_buffer_mask, GFP_KERNEL)) |
| 5789 | goto out; |
| 5790 | |
| 5791 | if (!alloc_cpumask_var(&tracing_cpumask, GFP_KERNEL)) |
| 5792 | goto out_free_buffer_mask; |
| 5793 | |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 5794 | /* Only allocate trace_printk buffers if a trace_printk exists */ |
| 5795 | if (__stop___trace_bprintk_fmt != __start___trace_bprintk_fmt) |
Steven Rostedt | 8169883 | 2012-10-11 10:15:05 -0400 | [diff] [blame] | 5796 | /* Must be called before global_trace.buffer is allocated */ |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 5797 | trace_printk_init_buffers(); |
| 5798 | |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 5799 | /* To save memory, keep the ring buffer size to its minimum */ |
| 5800 | if (ring_buffer_expanded) |
| 5801 | ring_buf_size = trace_buf_size; |
| 5802 | else |
| 5803 | ring_buf_size = 1; |
| 5804 | |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 5805 | cpumask_copy(tracing_buffer_mask, cpu_possible_mask); |
| 5806 | cpumask_copy(tracing_cpumask, cpu_all_mask); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5807 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5808 | raw_spin_lock_init(&global_trace.start_lock); |
| 5809 | |
Steven Rostedt | ab46428 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 5810 | /* TODO: make the number of buffers hot pluggable with CPUS */ |
Steven Rostedt (Red Hat) | 737223f | 2013-03-05 21:13:47 -0500 | [diff] [blame^] | 5811 | if (allocate_trace_buffers(&global_trace, ring_buf_size) < 0) { |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 5812 | printk(KERN_ERR "tracer: failed to allocate ring buffer!\n"); |
| 5813 | WARN_ON(1); |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 5814 | goto out_free_cpumask; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 5815 | } |
Steven Rostedt | a7603ff | 2012-08-06 16:24:11 -0400 | [diff] [blame] | 5816 | |
Steven Rostedt | 499e547 | 2012-02-22 15:50:28 -0500 | [diff] [blame] | 5817 | if (global_trace.buffer_disabled) |
| 5818 | tracing_off(); |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 5819 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5820 | trace_init_cmdlines(); |
| 5821 | |
Frédéric Weisbecker | 43a1538 | 2008-09-21 20:16:30 +0200 | [diff] [blame] | 5822 | register_tracer(&nop_trace); |
Steven Rostedt (Red Hat) | d840f71 | 2013-02-01 18:38:47 -0500 | [diff] [blame] | 5823 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5824 | global_trace.current_trace = &nop_trace; |
| 5825 | |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 5826 | /* All seems OK, enable tracing */ |
| 5827 | tracing_disabled = 0; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 5828 | |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 5829 | atomic_notifier_chain_register(&panic_notifier_list, |
| 5830 | &trace_panic_notifier); |
| 5831 | |
| 5832 | register_die_notifier(&trace_die_notifier); |
Frederic Weisbecker | 2fc1dfb | 2009-03-16 01:45:03 +0100 | [diff] [blame] | 5833 | |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 5834 | global_trace.flags = TRACE_ARRAY_FL_GLOBAL; |
| 5835 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5836 | /* Holder for file callbacks */ |
| 5837 | global_trace.trace_cpu.cpu = RING_BUFFER_ALL_CPUS; |
| 5838 | global_trace.trace_cpu.tr = &global_trace; |
| 5839 | |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 5840 | INIT_LIST_HEAD(&global_trace.systems); |
| 5841 | INIT_LIST_HEAD(&global_trace.events); |
| 5842 | list_add(&global_trace.list, &ftrace_trace_arrays); |
| 5843 | |
Steven Rostedt | 7bcfaf5 | 2012-11-01 22:56:07 -0400 | [diff] [blame] | 5844 | while (trace_boot_options) { |
| 5845 | char *option; |
| 5846 | |
| 5847 | option = strsep(&trace_boot_options, ","); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5848 | trace_set_options(&global_trace, option); |
Steven Rostedt | 7bcfaf5 | 2012-11-01 22:56:07 -0400 | [diff] [blame] | 5849 | } |
| 5850 | |
Frederic Weisbecker | 2fc1dfb | 2009-03-16 01:45:03 +0100 | [diff] [blame] | 5851 | return 0; |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 5852 | |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 5853 | out_free_cpumask: |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5854 | free_percpu(global_trace.trace_buffer.data); |
| 5855 | #ifdef CONFIG_TRACER_MAX_TRACE |
| 5856 | free_percpu(global_trace.max_buffer.data); |
| 5857 | #endif |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 5858 | free_cpumask_var(tracing_cpumask); |
| 5859 | out_free_buffer_mask: |
| 5860 | free_cpumask_var(tracing_buffer_mask); |
| 5861 | out: |
| 5862 | return ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5863 | } |
Steven Rostedt | b2821ae | 2009-02-02 21:38:32 -0500 | [diff] [blame] | 5864 | |
| 5865 | __init static int clear_boot_tracer(void) |
| 5866 | { |
| 5867 | /* |
| 5868 | * The default tracer at boot buffer is an init section. |
| 5869 | * This function is called in lateinit. If we did not |
| 5870 | * find the boot tracer, then clear it out, to prevent |
| 5871 | * later registration from accessing the buffer that is |
| 5872 | * about to be freed. |
| 5873 | */ |
| 5874 | if (!default_bootup_tracer) |
| 5875 | return 0; |
| 5876 | |
| 5877 | printk(KERN_INFO "ftrace bootup tracer '%s' not registered.\n", |
| 5878 | default_bootup_tracer); |
| 5879 | default_bootup_tracer = NULL; |
| 5880 | |
| 5881 | return 0; |
| 5882 | } |
| 5883 | |
Frédéric Weisbecker | b5ad384 | 2008-09-23 11:34:32 +0100 | [diff] [blame] | 5884 | early_initcall(tracer_alloc_buffers); |
| 5885 | fs_initcall(tracer_init_debugfs); |
Steven Rostedt | b2821ae | 2009-02-02 21:38:32 -0500 | [diff] [blame] | 5886 | late_initcall(clear_boot_tracer); |