Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1 | /* |
| 2 | * ring buffer based function tracer |
| 3 | * |
| 4 | * Copyright (C) 2007-2008 Steven Rostedt <srostedt@redhat.com> |
| 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 |
| 12 | * Copyright (C) 2004 William Lee Irwin III |
| 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 | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 39 | #include <linux/fs.h> |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 40 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 41 | #include "trace.h" |
Steven Rostedt | f0868d1 | 2008-12-23 23:24:12 -0500 | [diff] [blame] | 42 | #include "trace_output.h" |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 43 | |
Frederic Weisbecker | 8e1b82e | 2008-12-06 03:41:33 +0100 | [diff] [blame] | 44 | /* |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 45 | * On boot up, the ring buffer is set to the minimum size, so that |
| 46 | * we do not waste memory on systems that are not using tracing. |
| 47 | */ |
Li Zefan | 020e5f8 | 2009-07-01 10:47:05 +0800 | [diff] [blame] | 48 | int ring_buffer_expanded; |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 49 | |
| 50 | /* |
Frederic Weisbecker | 8e1b82e | 2008-12-06 03:41:33 +0100 | [diff] [blame] | 51 | * We need to change this state when a selftest is running. |
Frederic Weisbecker | ff32504 | 2008-12-04 23:47:35 +0100 | [diff] [blame] | 52 | * A selftest will lurk into the ring-buffer to count the |
| 53 | * entries inserted during the selftest although some concurrent |
Ingo Molnar | 5e1607a | 2009-03-05 10:24:48 +0100 | [diff] [blame] | 54 | * insertions into the ring-buffer such as trace_printk could occurred |
Frederic Weisbecker | ff32504 | 2008-12-04 23:47:35 +0100 | [diff] [blame] | 55 | * at the same time, giving false positive or negative results. |
| 56 | */ |
Frederic Weisbecker | 8e1b82e | 2008-12-06 03:41:33 +0100 | [diff] [blame] | 57 | static bool __read_mostly tracing_selftest_running; |
Frederic Weisbecker | ff32504 | 2008-12-04 23:47:35 +0100 | [diff] [blame] | 58 | |
Steven Rostedt | b2821ae | 2009-02-02 21:38:32 -0500 | [diff] [blame] | 59 | /* |
| 60 | * If a tracer is running, we do not want to run SELFTEST. |
| 61 | */ |
Li Zefan | 020e5f8 | 2009-07-01 10:47:05 +0800 | [diff] [blame] | 62 | bool __read_mostly tracing_selftest_disabled; |
Steven Rostedt | b2821ae | 2009-02-02 21:38:32 -0500 | [diff] [blame] | 63 | |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 64 | /* For tracers that don't implement custom flags */ |
| 65 | static struct tracer_opt dummy_tracer_opt[] = { |
| 66 | { } |
| 67 | }; |
| 68 | |
| 69 | static struct tracer_flags dummy_tracer_flags = { |
| 70 | .val = 0, |
| 71 | .opts = dummy_tracer_opt |
| 72 | }; |
| 73 | |
| 74 | static int dummy_set_flag(u32 old_flags, u32 bit, int set) |
| 75 | { |
| 76 | return 0; |
| 77 | } |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 78 | |
| 79 | /* |
| 80 | * Kill all tracing for good (never come back). |
| 81 | * It is initialized to 1 but will turn to zero if the initialization |
| 82 | * of the tracer is successful. But that is the only place that sets |
| 83 | * this back to zero. |
| 84 | */ |
Hannes Eder | 4fd2735 | 2009-02-10 19:44:12 +0100 | [diff] [blame] | 85 | static int tracing_disabled = 1; |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 86 | |
Christoph Lameter | 9288f99 | 2009-10-07 19:17:45 -0400 | [diff] [blame] | 87 | DEFINE_PER_CPU(int, ftrace_cpu_disabled); |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 88 | |
| 89 | static inline void ftrace_disable_cpu(void) |
| 90 | { |
| 91 | preempt_disable(); |
Rusty Russell | dd17c8f | 2009-10-29 22:34:15 +0900 | [diff] [blame] | 92 | __this_cpu_inc(ftrace_cpu_disabled); |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | static inline void ftrace_enable_cpu(void) |
| 96 | { |
Rusty Russell | dd17c8f | 2009-10-29 22:34:15 +0900 | [diff] [blame] | 97 | __this_cpu_dec(ftrace_cpu_disabled); |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 98 | preempt_enable(); |
| 99 | } |
| 100 | |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 101 | cpumask_var_t __read_mostly tracing_buffer_mask; |
Steven Rostedt | ab46428 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 102 | |
Steven Rostedt | 944ac42 | 2008-10-23 19:26:08 -0400 | [diff] [blame] | 103 | /* |
| 104 | * ftrace_dump_on_oops - variable to dump ftrace buffer on oops |
| 105 | * |
| 106 | * If there is an oops (or kernel panic) and the ftrace_dump_on_oops |
| 107 | * is set, then ftrace_dump is called. This will output the contents |
| 108 | * of the ftrace buffers to the console. This is very useful for |
| 109 | * capturing traces that lead to crashes and outputing it to a |
| 110 | * serial console. |
| 111 | * |
| 112 | * It is default off, but you can enable it with either specifying |
| 113 | * "ftrace_dump_on_oops" in the kernel command line, or setting |
Frederic Weisbecker | cecbca9 | 2010-04-18 19:08:41 +0200 | [diff] [blame] | 114 | * /proc/sys/kernel/ftrace_dump_on_oops |
| 115 | * Set 1 if you want to dump buffers of all CPUs |
| 116 | * 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] | 117 | */ |
Frederic Weisbecker | cecbca9 | 2010-04-18 19:08:41 +0200 | [diff] [blame] | 118 | |
| 119 | enum ftrace_dump_mode ftrace_dump_on_oops; |
Steven Rostedt | 944ac42 | 2008-10-23 19:26:08 -0400 | [diff] [blame] | 120 | |
Steven Rostedt | b2821ae | 2009-02-02 21:38:32 -0500 | [diff] [blame] | 121 | static int tracing_set_tracer(const char *buf); |
| 122 | |
Li Zefan | ee6c2c1 | 2009-09-18 14:06:47 +0800 | [diff] [blame] | 123 | #define MAX_TRACER_SIZE 100 |
| 124 | static char bootup_tracer_buf[MAX_TRACER_SIZE] __initdata; |
Steven Rostedt | b2821ae | 2009-02-02 21:38:32 -0500 | [diff] [blame] | 125 | static char *default_bootup_tracer; |
Peter Zijlstra | d9e5407 | 2008-11-01 19:57:37 +0100 | [diff] [blame] | 126 | |
Frederic Weisbecker | 1beee96 | 2009-10-14 20:50:32 +0200 | [diff] [blame] | 127 | static int __init set_cmdline_ftrace(char *str) |
Peter Zijlstra | d9e5407 | 2008-11-01 19:57:37 +0100 | [diff] [blame] | 128 | { |
Li Zefan | ee6c2c1 | 2009-09-18 14:06:47 +0800 | [diff] [blame] | 129 | strncpy(bootup_tracer_buf, str, MAX_TRACER_SIZE); |
Steven Rostedt | b2821ae | 2009-02-02 21:38:32 -0500 | [diff] [blame] | 130 | default_bootup_tracer = bootup_tracer_buf; |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 131 | /* We are using ftrace early, expand it */ |
| 132 | ring_buffer_expanded = 1; |
Peter Zijlstra | d9e5407 | 2008-11-01 19:57:37 +0100 | [diff] [blame] | 133 | return 1; |
| 134 | } |
Frederic Weisbecker | 1beee96 | 2009-10-14 20:50:32 +0200 | [diff] [blame] | 135 | __setup("ftrace=", set_cmdline_ftrace); |
Peter Zijlstra | d9e5407 | 2008-11-01 19:57:37 +0100 | [diff] [blame] | 136 | |
Steven Rostedt | 944ac42 | 2008-10-23 19:26:08 -0400 | [diff] [blame] | 137 | static int __init set_ftrace_dump_on_oops(char *str) |
| 138 | { |
Frederic Weisbecker | cecbca9 | 2010-04-18 19:08:41 +0200 | [diff] [blame] | 139 | if (*str++ != '=' || !*str) { |
| 140 | ftrace_dump_on_oops = DUMP_ALL; |
| 141 | return 1; |
| 142 | } |
| 143 | |
| 144 | if (!strcmp("orig_cpu", str)) { |
| 145 | ftrace_dump_on_oops = DUMP_ORIG; |
| 146 | return 1; |
| 147 | } |
| 148 | |
| 149 | return 0; |
Steven Rostedt | 944ac42 | 2008-10-23 19:26:08 -0400 | [diff] [blame] | 150 | } |
| 151 | __setup("ftrace_dump_on_oops", set_ftrace_dump_on_oops); |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 152 | |
Lai Jiangshan | cf8e347 | 2009-03-30 13:48:00 +0800 | [diff] [blame] | 153 | unsigned long long ns2usecs(cycle_t nsec) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 154 | { |
| 155 | nsec += 500; |
| 156 | do_div(nsec, 1000); |
| 157 | return nsec; |
| 158 | } |
| 159 | |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 160 | /* |
| 161 | * The global_trace is the descriptor that holds the tracing |
| 162 | * buffers for the live tracing. For each CPU, it contains |
| 163 | * a link list of pages that will store trace entries. The |
| 164 | * page descriptor of the pages in the memory is used to hold |
| 165 | * the link list by linking the lru item in the page descriptor |
| 166 | * to each of the pages in the buffer per CPU. |
| 167 | * |
| 168 | * For each active CPU there is a data field that holds the |
| 169 | * pages for the buffer for that CPU. Each CPU has the same number |
| 170 | * of pages allocated for its buffer. |
| 171 | */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 172 | static struct trace_array global_trace; |
| 173 | |
| 174 | static DEFINE_PER_CPU(struct trace_array_cpu, global_trace_cpu); |
| 175 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 176 | int filter_current_check_discard(struct ring_buffer *buffer, |
| 177 | struct ftrace_event_call *call, void *rec, |
Tom Zanussi | eb02ce0 | 2009-04-08 03:15:54 -0500 | [diff] [blame] | 178 | struct ring_buffer_event *event) |
| 179 | { |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 180 | return filter_check_discard(call, rec, buffer, event); |
Tom Zanussi | eb02ce0 | 2009-04-08 03:15:54 -0500 | [diff] [blame] | 181 | } |
Steven Rostedt | 17c873e | 2009-04-10 18:12:50 -0400 | [diff] [blame] | 182 | EXPORT_SYMBOL_GPL(filter_current_check_discard); |
Tom Zanussi | eb02ce0 | 2009-04-08 03:15:54 -0500 | [diff] [blame] | 183 | |
Steven Rostedt | 37886f6 | 2009-03-17 17:22:06 -0400 | [diff] [blame] | 184 | cycle_t ftrace_now(int cpu) |
| 185 | { |
| 186 | u64 ts; |
| 187 | |
| 188 | /* Early boot up does not have a buffer yet */ |
| 189 | if (!global_trace.buffer) |
| 190 | return trace_clock_local(); |
| 191 | |
| 192 | ts = ring_buffer_time_stamp(global_trace.buffer, cpu); |
| 193 | ring_buffer_normalize_time_stamp(global_trace.buffer, cpu, &ts); |
| 194 | |
| 195 | return ts; |
| 196 | } |
| 197 | |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 198 | /* |
| 199 | * The max_tr is used to snapshot the global_trace when a maximum |
| 200 | * latency is reached. Some tracers will use this to store a maximum |
| 201 | * trace while it continues examining live traces. |
| 202 | * |
| 203 | * The buffers for the max_tr are set up the same as the global_trace. |
| 204 | * When a snapshot is taken, the link list of the max_tr is swapped |
| 205 | * with the link list of the global_trace and the buffers are reset for |
| 206 | * the global_trace so the tracing can continue. |
| 207 | */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 208 | static struct trace_array max_tr; |
| 209 | |
Tejun Heo | 9705f69 | 2009-10-29 22:34:13 +0900 | [diff] [blame] | 210 | static DEFINE_PER_CPU(struct trace_array_cpu, max_tr_data); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 211 | |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 212 | /* tracer_enabled is used to toggle activation of a tracer */ |
Steven Rostedt | 26994ea | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 213 | static int tracer_enabled = 1; |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 214 | |
Steven Rostedt | 9036990 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 215 | /** |
| 216 | * tracing_is_enabled - return tracer_enabled status |
| 217 | * |
| 218 | * This function is used by other tracers to know the status |
| 219 | * of the tracer_enabled flag. Tracers may use this function |
| 220 | * to know if it should enable their features when starting |
| 221 | * up. See irqsoff tracer for an example (start_irqsoff_tracer). |
| 222 | */ |
| 223 | int tracing_is_enabled(void) |
| 224 | { |
| 225 | return tracer_enabled; |
| 226 | } |
| 227 | |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 228 | /* |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 229 | * trace_buf_size is the size in bytes that is allocated |
| 230 | * for a buffer. Note, the number of bytes is always rounded |
| 231 | * to page size. |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 232 | * |
| 233 | * This number is purposely set to a low number of 16384. |
| 234 | * If the dump on oops happens, it will be much appreciated |
| 235 | * to not have to wait for all that output. Anyway this can be |
| 236 | * boot time and run time configurable. |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 237 | */ |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 238 | #define TRACE_BUF_SIZE_DEFAULT 1441792UL /* 16384 * 88 (sizeof(entry)) */ |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 239 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 240 | static unsigned long trace_buf_size = TRACE_BUF_SIZE_DEFAULT; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 241 | |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 242 | /* trace_types holds a link list of available tracers. */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 243 | static struct tracer *trace_types __read_mostly; |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 244 | |
| 245 | /* current_trace points to the tracer that is currently active */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 246 | static struct tracer *current_trace __read_mostly; |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 247 | |
| 248 | /* |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 249 | * trace_types_lock is used to protect the trace_types list. |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 250 | */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 251 | static DEFINE_MUTEX(trace_types_lock); |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 252 | |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 253 | /* |
| 254 | * serialize the access of the ring buffer |
| 255 | * |
| 256 | * ring buffer serializes readers, but it is low level protection. |
| 257 | * The validity of the events (which returns by ring_buffer_peek() ..etc) |
| 258 | * are not protected by ring buffer. |
| 259 | * |
| 260 | * The content of events may become garbage if we allow other process consumes |
| 261 | * these events concurrently: |
| 262 | * A) the page of the consumed events may become a normal page |
| 263 | * (not reader page) in ring buffer, and this page will be rewrited |
| 264 | * by events producer. |
| 265 | * B) The page of the consumed events may become a page for splice_read, |
| 266 | * and this page will be returned to system. |
| 267 | * |
| 268 | * These primitives allow multi process access to different cpu ring buffer |
| 269 | * concurrently. |
| 270 | * |
| 271 | * These primitives don't distinguish read-only and read-consume access. |
| 272 | * Multi read-only access are also serialized. |
| 273 | */ |
| 274 | |
| 275 | #ifdef CONFIG_SMP |
| 276 | static DECLARE_RWSEM(all_cpu_access_lock); |
| 277 | static DEFINE_PER_CPU(struct mutex, cpu_access_lock); |
| 278 | |
| 279 | static inline void trace_access_lock(int cpu) |
| 280 | { |
| 281 | if (cpu == TRACE_PIPE_ALL_CPU) { |
| 282 | /* gain it for accessing the whole ring buffer. */ |
| 283 | down_write(&all_cpu_access_lock); |
| 284 | } else { |
| 285 | /* gain it for accessing a cpu ring buffer. */ |
| 286 | |
| 287 | /* Firstly block other trace_access_lock(TRACE_PIPE_ALL_CPU). */ |
| 288 | down_read(&all_cpu_access_lock); |
| 289 | |
| 290 | /* Secondly block other access to this @cpu ring buffer. */ |
| 291 | mutex_lock(&per_cpu(cpu_access_lock, cpu)); |
| 292 | } |
| 293 | } |
| 294 | |
| 295 | static inline void trace_access_unlock(int cpu) |
| 296 | { |
| 297 | if (cpu == TRACE_PIPE_ALL_CPU) { |
| 298 | up_write(&all_cpu_access_lock); |
| 299 | } else { |
| 300 | mutex_unlock(&per_cpu(cpu_access_lock, cpu)); |
| 301 | up_read(&all_cpu_access_lock); |
| 302 | } |
| 303 | } |
| 304 | |
| 305 | static inline void trace_access_lock_init(void) |
| 306 | { |
| 307 | int cpu; |
| 308 | |
| 309 | for_each_possible_cpu(cpu) |
| 310 | mutex_init(&per_cpu(cpu_access_lock, cpu)); |
| 311 | } |
| 312 | |
| 313 | #else |
| 314 | |
| 315 | static DEFINE_MUTEX(access_lock); |
| 316 | |
| 317 | static inline void trace_access_lock(int cpu) |
| 318 | { |
| 319 | (void)cpu; |
| 320 | mutex_lock(&access_lock); |
| 321 | } |
| 322 | |
| 323 | static inline void trace_access_unlock(int cpu) |
| 324 | { |
| 325 | (void)cpu; |
| 326 | mutex_unlock(&access_lock); |
| 327 | } |
| 328 | |
| 329 | static inline void trace_access_lock_init(void) |
| 330 | { |
| 331 | } |
| 332 | |
| 333 | #endif |
| 334 | |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 335 | /* trace_wait is a waitqueue for tasks blocked on trace_poll */ |
Ingo Molnar | 4e65551 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 336 | static DECLARE_WAIT_QUEUE_HEAD(trace_wait); |
| 337 | |
Steven Rostedt | ee6bce5 | 2008-11-12 17:52:37 -0500 | [diff] [blame] | 338 | /* trace_flags holds trace_options default values */ |
Steven Rostedt | 12ef7d4 | 2008-11-12 17:52:38 -0500 | [diff] [blame] | 339 | unsigned long trace_flags = TRACE_ITER_PRINT_PARENT | TRACE_ITER_PRINTK | |
Steven Rostedt | a2a16d6 | 2009-03-24 23:17:58 -0400 | [diff] [blame] | 340 | TRACE_ITER_ANNOTATE | TRACE_ITER_CONTEXT_INFO | TRACE_ITER_SLEEP_TIME | |
David Sharp | 750912f | 2010-12-08 13:46:47 -0800 | [diff] [blame] | 341 | TRACE_ITER_GRAPH_TIME | TRACE_ITER_RECORD_CMD | TRACE_ITER_OVERWRITE; |
Ingo Molnar | 4e65551 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 342 | |
Steven Rostedt | b8de7bd1 | 2009-08-31 22:32:27 -0400 | [diff] [blame] | 343 | static int trace_stop_count; |
| 344 | static DEFINE_SPINLOCK(tracing_start_lock); |
| 345 | |
Vaibhav Nagarnaik | e7e2ee8 | 2011-05-10 13:27:21 -0700 | [diff] [blame] | 346 | static void wakeup_work_handler(struct work_struct *work) |
| 347 | { |
| 348 | wake_up(&trace_wait); |
| 349 | } |
| 350 | |
| 351 | static DECLARE_DELAYED_WORK(wakeup_work, wakeup_work_handler); |
| 352 | |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 353 | /** |
| 354 | * trace_wake_up - wake up tasks waiting for trace input |
| 355 | * |
Vaibhav Nagarnaik | e7e2ee8 | 2011-05-10 13:27:21 -0700 | [diff] [blame] | 356 | * Schedules a delayed work to wake up any task that is blocked on the |
| 357 | * trace_wait queue. These is used with trace_poll for tasks polling the |
| 358 | * trace. |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 359 | */ |
Ingo Molnar | 4e65551 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 360 | void trace_wake_up(void) |
| 361 | { |
Vaibhav Nagarnaik | e7e2ee8 | 2011-05-10 13:27:21 -0700 | [diff] [blame] | 362 | const unsigned long delay = msecs_to_jiffies(2); |
Andrew Morton | 89f19f0 | 2009-09-19 11:55:44 -0700 | [diff] [blame] | 363 | |
| 364 | if (trace_flags & TRACE_ITER_BLOCK) |
| 365 | return; |
Vaibhav Nagarnaik | e7e2ee8 | 2011-05-10 13:27:21 -0700 | [diff] [blame] | 366 | schedule_delayed_work(&wakeup_work, delay); |
Ingo Molnar | 4e65551 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 367 | } |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 368 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 369 | static int __init set_buf_size(char *str) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 370 | { |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 371 | unsigned long buf_size; |
Steven Rostedt | c6caeeb | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 372 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 373 | if (!str) |
| 374 | return 0; |
Li Zefan | 9d612be | 2009-06-24 17:33:15 +0800 | [diff] [blame] | 375 | buf_size = memparse(str, &str); |
Steven Rostedt | c6caeeb | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 376 | /* nr_entries can not be zero */ |
Li Zefan | 9d612be | 2009-06-24 17:33:15 +0800 | [diff] [blame] | 377 | if (buf_size == 0) |
Steven Rostedt | c6caeeb | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 378 | return 0; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 379 | trace_buf_size = buf_size; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 380 | return 1; |
| 381 | } |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 382 | __setup("trace_buf_size=", set_buf_size); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 383 | |
Tim Bird | 0e95017 | 2010-02-25 15:36:43 -0800 | [diff] [blame] | 384 | static int __init set_tracing_thresh(char *str) |
| 385 | { |
| 386 | unsigned long threshhold; |
| 387 | int ret; |
| 388 | |
| 389 | if (!str) |
| 390 | return 0; |
| 391 | ret = strict_strtoul(str, 0, &threshhold); |
| 392 | if (ret < 0) |
| 393 | return 0; |
| 394 | tracing_thresh = threshhold * 1000; |
| 395 | return 1; |
| 396 | } |
| 397 | __setup("tracing_thresh=", set_tracing_thresh); |
| 398 | |
Steven Rostedt | 57f50be | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 399 | unsigned long nsecs_to_usecs(unsigned long nsecs) |
| 400 | { |
| 401 | return nsecs / 1000; |
| 402 | } |
| 403 | |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 404 | /* These must match the bit postions in trace_iterator_flags */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 405 | static const char *trace_options[] = { |
| 406 | "print-parent", |
| 407 | "sym-offset", |
| 408 | "sym-addr", |
| 409 | "verbose", |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 410 | "raw", |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 411 | "hex", |
Ingo Molnar | cb0f12a | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 412 | "bin", |
Soeren Sandmann Pedersen | 2a2cc8f | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 413 | "block", |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 414 | "stacktrace", |
Ingo Molnar | 5e1607a | 2009-03-05 10:24:48 +0100 | [diff] [blame] | 415 | "trace_printk", |
Steven Rostedt | b2a866f | 2008-11-03 23:15:57 -0500 | [diff] [blame] | 416 | "ftrace_preempt", |
Steven Rostedt | 9f029e8 | 2008-11-12 15:24:24 -0500 | [diff] [blame] | 417 | "branch", |
Steven Rostedt | 12ef7d4 | 2008-11-12 17:52:38 -0500 | [diff] [blame] | 418 | "annotate", |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 419 | "userstacktrace", |
Török Edwin | b54d3de | 2008-11-22 13:28:48 +0200 | [diff] [blame] | 420 | "sym-userobj", |
Frederic Weisbecker | 66896a8 | 2008-12-13 20:18:13 +0100 | [diff] [blame] | 421 | "printk-msg-only", |
Frederic Weisbecker | c4a8e8b | 2009-02-02 20:29:21 -0200 | [diff] [blame] | 422 | "context-info", |
Steven Rostedt | c032ef64 | 2009-03-04 20:34:24 -0500 | [diff] [blame] | 423 | "latency-format", |
Steven Rostedt | be6f164 | 2009-03-24 11:06:24 -0400 | [diff] [blame] | 424 | "sleep-time", |
Steven Rostedt | a2a16d6 | 2009-03-24 23:17:58 -0400 | [diff] [blame] | 425 | "graph-time", |
Li Zefan | e870e9a | 2010-07-02 11:07:32 +0800 | [diff] [blame] | 426 | "record-cmd", |
David Sharp | 750912f | 2010-12-08 13:46:47 -0800 | [diff] [blame] | 427 | "overwrite", |
Steven Rostedt | cf30cf6 | 2011-06-14 22:44:07 -0400 | [diff] [blame^] | 428 | "disable_on_free", |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 429 | NULL |
| 430 | }; |
| 431 | |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 432 | static struct { |
| 433 | u64 (*func)(void); |
| 434 | const char *name; |
| 435 | } trace_clocks[] = { |
| 436 | { trace_clock_local, "local" }, |
| 437 | { trace_clock_global, "global" }, |
| 438 | }; |
| 439 | |
| 440 | int trace_clock_id; |
| 441 | |
jolsa@redhat.com | b63f39e | 2009-09-11 17:29:27 +0200 | [diff] [blame] | 442 | /* |
| 443 | * trace_parser_get_init - gets the buffer for trace parser |
| 444 | */ |
| 445 | int trace_parser_get_init(struct trace_parser *parser, int size) |
| 446 | { |
| 447 | memset(parser, 0, sizeof(*parser)); |
| 448 | |
| 449 | parser->buffer = kmalloc(size, GFP_KERNEL); |
| 450 | if (!parser->buffer) |
| 451 | return 1; |
| 452 | |
| 453 | parser->size = size; |
| 454 | return 0; |
| 455 | } |
| 456 | |
| 457 | /* |
| 458 | * trace_parser_put - frees the buffer for trace parser |
| 459 | */ |
| 460 | void trace_parser_put(struct trace_parser *parser) |
| 461 | { |
| 462 | kfree(parser->buffer); |
| 463 | } |
| 464 | |
| 465 | /* |
| 466 | * trace_get_user - reads the user input string separated by space |
| 467 | * (matched by isspace(ch)) |
| 468 | * |
| 469 | * For each string found the 'struct trace_parser' is updated, |
| 470 | * and the function returns. |
| 471 | * |
| 472 | * Returns number of bytes read. |
| 473 | * |
| 474 | * See kernel/trace/trace.h for 'struct trace_parser' details. |
| 475 | */ |
| 476 | int trace_get_user(struct trace_parser *parser, const char __user *ubuf, |
| 477 | size_t cnt, loff_t *ppos) |
| 478 | { |
| 479 | char ch; |
| 480 | size_t read = 0; |
| 481 | ssize_t ret; |
| 482 | |
| 483 | if (!*ppos) |
| 484 | trace_parser_clear(parser); |
| 485 | |
| 486 | ret = get_user(ch, ubuf++); |
| 487 | if (ret) |
| 488 | goto out; |
| 489 | |
| 490 | read++; |
| 491 | cnt--; |
| 492 | |
| 493 | /* |
| 494 | * The parser is not finished with the last write, |
| 495 | * continue reading the user input without skipping spaces. |
| 496 | */ |
| 497 | if (!parser->cont) { |
| 498 | /* skip white space */ |
| 499 | while (cnt && isspace(ch)) { |
| 500 | ret = get_user(ch, ubuf++); |
| 501 | if (ret) |
| 502 | goto out; |
| 503 | read++; |
| 504 | cnt--; |
| 505 | } |
| 506 | |
| 507 | /* only spaces were written */ |
| 508 | if (isspace(ch)) { |
| 509 | *ppos += read; |
| 510 | ret = read; |
| 511 | goto out; |
| 512 | } |
| 513 | |
| 514 | parser->idx = 0; |
| 515 | } |
| 516 | |
| 517 | /* read the non-space input */ |
| 518 | while (cnt && !isspace(ch)) { |
Li Zefan | 3c235a3 | 2009-09-22 13:51:54 +0800 | [diff] [blame] | 519 | if (parser->idx < parser->size - 1) |
jolsa@redhat.com | b63f39e | 2009-09-11 17:29:27 +0200 | [diff] [blame] | 520 | parser->buffer[parser->idx++] = ch; |
| 521 | else { |
| 522 | ret = -EINVAL; |
| 523 | goto out; |
| 524 | } |
| 525 | ret = get_user(ch, ubuf++); |
| 526 | if (ret) |
| 527 | goto out; |
| 528 | read++; |
| 529 | cnt--; |
| 530 | } |
| 531 | |
| 532 | /* We either got finished input or we have to wait for another call. */ |
| 533 | if (isspace(ch)) { |
| 534 | parser->buffer[parser->idx] = 0; |
| 535 | parser->cont = false; |
| 536 | } else { |
| 537 | parser->cont = true; |
| 538 | parser->buffer[parser->idx++] = ch; |
| 539 | } |
| 540 | |
| 541 | *ppos += read; |
| 542 | ret = read; |
| 543 | |
| 544 | out: |
| 545 | return ret; |
| 546 | } |
| 547 | |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 548 | ssize_t trace_seq_to_user(struct trace_seq *s, char __user *ubuf, size_t cnt) |
| 549 | { |
| 550 | int len; |
| 551 | int ret; |
| 552 | |
Steven Rostedt | 2dc5d12 | 2009-03-04 19:10:05 -0500 | [diff] [blame] | 553 | if (!cnt) |
| 554 | return 0; |
| 555 | |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 556 | if (s->len <= s->readpos) |
| 557 | return -EBUSY; |
| 558 | |
| 559 | len = s->len - s->readpos; |
| 560 | if (cnt > len) |
| 561 | cnt = len; |
| 562 | ret = copy_to_user(ubuf, s->buffer + s->readpos, cnt); |
Steven Rostedt | 2dc5d12 | 2009-03-04 19:10:05 -0500 | [diff] [blame] | 563 | if (ret == cnt) |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 564 | return -EFAULT; |
| 565 | |
Steven Rostedt | 2dc5d12 | 2009-03-04 19:10:05 -0500 | [diff] [blame] | 566 | cnt -= ret; |
| 567 | |
Steven Rostedt | e74da52 | 2009-03-04 20:31:11 -0500 | [diff] [blame] | 568 | s->readpos += cnt; |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 569 | return cnt; |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 570 | } |
| 571 | |
Dmitri Vorobiev | b8b9426 | 2009-03-22 19:11:11 +0200 | [diff] [blame] | 572 | 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] | 573 | { |
| 574 | int len; |
| 575 | void *ret; |
| 576 | |
| 577 | if (s->len <= s->readpos) |
| 578 | return -EBUSY; |
| 579 | |
| 580 | len = s->len - s->readpos; |
| 581 | if (cnt > len) |
| 582 | cnt = len; |
| 583 | ret = memcpy(buf, s->buffer + s->readpos, cnt); |
| 584 | if (!ret) |
| 585 | return -EFAULT; |
| 586 | |
Steven Rostedt | e74da52 | 2009-03-04 20:31:11 -0500 | [diff] [blame] | 587 | s->readpos += cnt; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 588 | return cnt; |
| 589 | } |
| 590 | |
Steven Rostedt | 5d4a9db | 2009-08-27 16:52:21 -0400 | [diff] [blame] | 591 | /* |
| 592 | * ftrace_max_lock is used to protect the swapping of buffers |
| 593 | * when taking a max snapshot. The buffers themselves are |
| 594 | * protected by per_cpu spinlocks. But the action of the swap |
| 595 | * needs its own lock. |
| 596 | * |
Thomas Gleixner | 445c895 | 2009-12-02 19:49:50 +0100 | [diff] [blame] | 597 | * This is defined as a arch_spinlock_t in order to help |
Steven Rostedt | 5d4a9db | 2009-08-27 16:52:21 -0400 | [diff] [blame] | 598 | * with performance when lockdep debugging is enabled. |
| 599 | * |
| 600 | * It is also used in other places outside the update_max_tr |
| 601 | * so it needs to be defined outside of the |
| 602 | * CONFIG_TRACER_MAX_TRACE. |
| 603 | */ |
Thomas Gleixner | 445c895 | 2009-12-02 19:49:50 +0100 | [diff] [blame] | 604 | static arch_spinlock_t ftrace_max_lock = |
Thomas Gleixner | edc35bd | 2009-12-03 12:38:57 +0100 | [diff] [blame] | 605 | (arch_spinlock_t)__ARCH_SPIN_LOCK_UNLOCKED; |
Steven Rostedt | 5d4a9db | 2009-08-27 16:52:21 -0400 | [diff] [blame] | 606 | |
Tim Bird | 0e95017 | 2010-02-25 15:36:43 -0800 | [diff] [blame] | 607 | unsigned long __read_mostly tracing_thresh; |
| 608 | |
Steven Rostedt | 5d4a9db | 2009-08-27 16:52:21 -0400 | [diff] [blame] | 609 | #ifdef CONFIG_TRACER_MAX_TRACE |
| 610 | unsigned long __read_mostly tracing_max_latency; |
Steven Rostedt | 5d4a9db | 2009-08-27 16:52:21 -0400 | [diff] [blame] | 611 | |
| 612 | /* |
| 613 | * Copy the new maximum trace into the separate maximum-trace |
| 614 | * structure. (this way the maximum trace is permanently saved, |
| 615 | * for later retrieval via /sys/kernel/debug/tracing/latency_trace) |
| 616 | */ |
| 617 | static void |
| 618 | __update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu) |
| 619 | { |
| 620 | struct trace_array_cpu *data = tr->data[cpu]; |
Arnaldo Carvalho de Melo | 1acaa1b | 2010-03-05 18:23:50 -0300 | [diff] [blame] | 621 | struct trace_array_cpu *max_data; |
Steven Rostedt | 5d4a9db | 2009-08-27 16:52:21 -0400 | [diff] [blame] | 622 | |
| 623 | max_tr.cpu = cpu; |
| 624 | max_tr.time_start = data->preempt_timestamp; |
| 625 | |
Steven Rostedt | 8248ac0 | 2009-09-02 12:27:41 -0400 | [diff] [blame] | 626 | max_data = max_tr.data[cpu]; |
| 627 | max_data->saved_latency = tracing_max_latency; |
| 628 | max_data->critical_start = data->critical_start; |
| 629 | max_data->critical_end = data->critical_end; |
Steven Rostedt | 5d4a9db | 2009-08-27 16:52:21 -0400 | [diff] [blame] | 630 | |
Arnaldo Carvalho de Melo | 1acaa1b | 2010-03-05 18:23:50 -0300 | [diff] [blame] | 631 | memcpy(max_data->comm, tsk->comm, TASK_COMM_LEN); |
Steven Rostedt | 8248ac0 | 2009-09-02 12:27:41 -0400 | [diff] [blame] | 632 | max_data->pid = tsk->pid; |
| 633 | max_data->uid = task_uid(tsk); |
| 634 | max_data->nice = tsk->static_prio - 20 - MAX_RT_PRIO; |
| 635 | max_data->policy = tsk->policy; |
| 636 | max_data->rt_priority = tsk->rt_priority; |
Steven Rostedt | 5d4a9db | 2009-08-27 16:52:21 -0400 | [diff] [blame] | 637 | |
| 638 | /* record this tasks comm */ |
| 639 | tracing_record_cmdline(tsk); |
| 640 | } |
| 641 | |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 642 | /** |
| 643 | * update_max_tr - snapshot all trace buffers from global_trace to max_tr |
| 644 | * @tr: tracer |
| 645 | * @tsk: the task with the latency |
| 646 | * @cpu: The cpu that initiated the trace. |
| 647 | * |
| 648 | * Flip the buffers between the @tr and the max_tr and record information |
| 649 | * about which task was the cause of this latency. |
| 650 | */ |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 651 | void |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 652 | update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu) |
| 653 | { |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 654 | struct ring_buffer *buf = tr->buffer; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 655 | |
Steven Rostedt | b8de7bd1 | 2009-08-31 22:32:27 -0400 | [diff] [blame] | 656 | if (trace_stop_count) |
| 657 | return; |
| 658 | |
Steven Rostedt | 4c11d7a | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 659 | WARN_ON_ONCE(!irqs_disabled()); |
KOSAKI Motohiro | ef710e1 | 2010-07-01 14:34:35 +0900 | [diff] [blame] | 660 | if (!current_trace->use_max_tr) { |
| 661 | WARN_ON_ONCE(1); |
| 662 | return; |
| 663 | } |
Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 664 | arch_spin_lock(&ftrace_max_lock); |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 665 | |
| 666 | tr->buffer = max_tr.buffer; |
| 667 | max_tr.buffer = buf; |
| 668 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 669 | __update_max_tr(tr, tsk, cpu); |
Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 670 | arch_spin_unlock(&ftrace_max_lock); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 671 | } |
| 672 | |
| 673 | /** |
| 674 | * update_max_tr_single - only copy one trace over, and reset the rest |
| 675 | * @tr - tracer |
| 676 | * @tsk - task with the latency |
| 677 | * @cpu - the cpu of the buffer to copy. |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 678 | * |
| 679 | * 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] | 680 | */ |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 681 | void |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 682 | update_max_tr_single(struct trace_array *tr, struct task_struct *tsk, int cpu) |
| 683 | { |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 684 | int ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 685 | |
Steven Rostedt | b8de7bd1 | 2009-08-31 22:32:27 -0400 | [diff] [blame] | 686 | if (trace_stop_count) |
| 687 | return; |
| 688 | |
Steven Rostedt | 4c11d7a | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 689 | WARN_ON_ONCE(!irqs_disabled()); |
KOSAKI Motohiro | ef710e1 | 2010-07-01 14:34:35 +0900 | [diff] [blame] | 690 | if (!current_trace->use_max_tr) { |
| 691 | WARN_ON_ONCE(1); |
| 692 | return; |
| 693 | } |
| 694 | |
Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 695 | arch_spin_lock(&ftrace_max_lock); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 696 | |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 697 | ftrace_disable_cpu(); |
| 698 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 699 | ret = ring_buffer_swap_cpu(max_tr.buffer, tr->buffer, cpu); |
| 700 | |
Steven Rostedt | e8165dbb | 2009-09-03 19:13:05 -0400 | [diff] [blame] | 701 | if (ret == -EBUSY) { |
| 702 | /* |
| 703 | * We failed to swap the buffer due to a commit taking |
| 704 | * place on this CPU. We fail to record, but we reset |
| 705 | * the max trace buffer (no one writes directly to it) |
| 706 | * and flag that it failed. |
| 707 | */ |
| 708 | trace_array_printk(&max_tr, _THIS_IP_, |
| 709 | "Failed to swap buffers due to commit in progress\n"); |
| 710 | } |
| 711 | |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 712 | ftrace_enable_cpu(); |
| 713 | |
Steven Rostedt | e8165dbb | 2009-09-03 19:13:05 -0400 | [diff] [blame] | 714 | WARN_ON_ONCE(ret && ret != -EAGAIN && ret != -EBUSY); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 715 | |
| 716 | __update_max_tr(tr, tsk, cpu); |
Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 717 | arch_spin_unlock(&ftrace_max_lock); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 718 | } |
Steven Rostedt | 5d4a9db | 2009-08-27 16:52:21 -0400 | [diff] [blame] | 719 | #endif /* CONFIG_TRACER_MAX_TRACE */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 720 | |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 721 | /** |
| 722 | * register_tracer - register a tracer with the ftrace system. |
| 723 | * @type - the plugin for the tracer |
| 724 | * |
| 725 | * Register a new plugin tracer. |
| 726 | */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 727 | int register_tracer(struct tracer *type) |
Hannes Eder | e7669b8 | 2009-02-10 19:44:45 +0100 | [diff] [blame] | 728 | __releases(kernel_lock) |
| 729 | __acquires(kernel_lock) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 730 | { |
| 731 | struct tracer *t; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 732 | int ret = 0; |
| 733 | |
| 734 | if (!type->name) { |
| 735 | pr_info("Tracer must have a name\n"); |
| 736 | return -1; |
| 737 | } |
| 738 | |
Dan Carpenter | 24a461d | 2010-07-10 12:06:44 +0200 | [diff] [blame] | 739 | if (strlen(type->name) >= MAX_TRACER_SIZE) { |
Li Zefan | ee6c2c1 | 2009-09-18 14:06:47 +0800 | [diff] [blame] | 740 | pr_info("Tracer has a name longer than %d\n", MAX_TRACER_SIZE); |
| 741 | return -1; |
| 742 | } |
| 743 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 744 | mutex_lock(&trace_types_lock); |
Ingo Molnar | 86fa2f6 | 2008-11-19 10:00:15 +0100 | [diff] [blame] | 745 | |
Frederic Weisbecker | 8e1b82e | 2008-12-06 03:41:33 +0100 | [diff] [blame] | 746 | tracing_selftest_running = true; |
| 747 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 748 | for (t = trace_types; t; t = t->next) { |
| 749 | if (strcmp(type->name, t->name) == 0) { |
| 750 | /* already found */ |
Li Zefan | ee6c2c1 | 2009-09-18 14:06:47 +0800 | [diff] [blame] | 751 | pr_info("Tracer %s already registered\n", |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 752 | type->name); |
| 753 | ret = -1; |
| 754 | goto out; |
| 755 | } |
| 756 | } |
| 757 | |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 758 | if (!type->set_flag) |
| 759 | type->set_flag = &dummy_set_flag; |
| 760 | if (!type->flags) |
| 761 | type->flags = &dummy_tracer_flags; |
| 762 | else |
| 763 | if (!type->flags->opts) |
| 764 | type->flags->opts = dummy_tracer_opt; |
Frederic Weisbecker | 6eaaa5d | 2009-02-11 02:25:00 +0100 | [diff] [blame] | 765 | if (!type->wait_pipe) |
| 766 | type->wait_pipe = default_wait_pipe; |
| 767 | |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 768 | |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 769 | #ifdef CONFIG_FTRACE_STARTUP_TEST |
Steven Rostedt | b2821ae | 2009-02-02 21:38:32 -0500 | [diff] [blame] | 770 | if (type->selftest && !tracing_selftest_disabled) { |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 771 | struct tracer *saved_tracer = current_trace; |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 772 | struct trace_array *tr = &global_trace; |
Frederic Weisbecker | ff32504 | 2008-12-04 23:47:35 +0100 | [diff] [blame] | 773 | |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 774 | /* |
| 775 | * Run a selftest on this tracer. |
| 776 | * Here we reset the trace buffer, and set the current |
| 777 | * tracer to be this tracer. The tracer can then run some |
| 778 | * internal tracing to verify that everything is in order. |
| 779 | * If we fail, we do not register this tracer. |
| 780 | */ |
Steven Rostedt | 76f0d07 | 2009-09-04 12:12:39 -0400 | [diff] [blame] | 781 | tracing_reset_online_cpus(tr); |
Ingo Molnar | 86fa2f6 | 2008-11-19 10:00:15 +0100 | [diff] [blame] | 782 | |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 783 | current_trace = type; |
Steven Rostedt | 4a0b166 | 2011-03-09 20:09:26 -0500 | [diff] [blame] | 784 | |
| 785 | /* If we expanded the buffers, make sure the max is expanded too */ |
| 786 | if (ring_buffer_expanded && type->use_max_tr) |
| 787 | ring_buffer_resize(max_tr.buffer, trace_buf_size); |
| 788 | |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 789 | /* the test is responsible for initializing and enabling */ |
| 790 | pr_info("Testing tracer %s: ", type->name); |
| 791 | ret = type->selftest(type, tr); |
| 792 | /* the test is responsible for resetting too */ |
| 793 | current_trace = saved_tracer; |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 794 | if (ret) { |
| 795 | printk(KERN_CONT "FAILED!\n"); |
| 796 | goto out; |
| 797 | } |
Steven Rostedt | 1d4db00 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 798 | /* Only reset on passing, to avoid touching corrupted buffers */ |
Steven Rostedt | 76f0d07 | 2009-09-04 12:12:39 -0400 | [diff] [blame] | 799 | tracing_reset_online_cpus(tr); |
Ingo Molnar | 86fa2f6 | 2008-11-19 10:00:15 +0100 | [diff] [blame] | 800 | |
Steven Rostedt | 4a0b166 | 2011-03-09 20:09:26 -0500 | [diff] [blame] | 801 | /* Shrink the max buffer again */ |
| 802 | if (ring_buffer_expanded && type->use_max_tr) |
| 803 | ring_buffer_resize(max_tr.buffer, 1); |
| 804 | |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 805 | printk(KERN_CONT "PASSED\n"); |
| 806 | } |
| 807 | #endif |
| 808 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 809 | type->next = trace_types; |
| 810 | trace_types = type; |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 811 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 812 | out: |
Frederic Weisbecker | 8e1b82e | 2008-12-06 03:41:33 +0100 | [diff] [blame] | 813 | tracing_selftest_running = false; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 814 | mutex_unlock(&trace_types_lock); |
| 815 | |
Steven Rostedt | dac7494 | 2009-02-05 01:13:38 -0500 | [diff] [blame] | 816 | if (ret || !default_bootup_tracer) |
| 817 | goto out_unlock; |
Steven Rostedt | b2821ae | 2009-02-02 21:38:32 -0500 | [diff] [blame] | 818 | |
Li Zefan | ee6c2c1 | 2009-09-18 14:06:47 +0800 | [diff] [blame] | 819 | if (strncmp(default_bootup_tracer, type->name, MAX_TRACER_SIZE)) |
Steven Rostedt | dac7494 | 2009-02-05 01:13:38 -0500 | [diff] [blame] | 820 | goto out_unlock; |
| 821 | |
| 822 | printk(KERN_INFO "Starting tracer '%s'\n", type->name); |
| 823 | /* Do we want this tracer to start on bootup? */ |
| 824 | tracing_set_tracer(type->name); |
| 825 | default_bootup_tracer = NULL; |
| 826 | /* disable other selftests, since this will break it. */ |
| 827 | tracing_selftest_disabled = 1; |
| 828 | #ifdef CONFIG_FTRACE_STARTUP_TEST |
| 829 | printk(KERN_INFO "Disabling FTRACE selftests due to running tracer '%s'\n", |
| 830 | type->name); |
| 831 | #endif |
| 832 | |
| 833 | out_unlock: |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 834 | return ret; |
| 835 | } |
| 836 | |
| 837 | void unregister_tracer(struct tracer *type) |
| 838 | { |
| 839 | struct tracer **t; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 840 | |
| 841 | mutex_lock(&trace_types_lock); |
| 842 | for (t = &trace_types; *t; t = &(*t)->next) { |
| 843 | if (*t == type) |
| 844 | goto found; |
| 845 | } |
Li Zefan | ee6c2c1 | 2009-09-18 14:06:47 +0800 | [diff] [blame] | 846 | pr_info("Tracer %s not registered\n", type->name); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 847 | goto out; |
| 848 | |
| 849 | found: |
| 850 | *t = (*t)->next; |
Arnaldo Carvalho de Melo | b5db03c | 2009-02-07 18:52:59 -0200 | [diff] [blame] | 851 | |
| 852 | if (type == current_trace && tracer_enabled) { |
| 853 | tracer_enabled = 0; |
| 854 | tracing_stop(); |
| 855 | if (current_trace->stop) |
| 856 | current_trace->stop(&global_trace); |
| 857 | current_trace = &nop_trace; |
| 858 | } |
Li Zefan | ee6c2c1 | 2009-09-18 14:06:47 +0800 | [diff] [blame] | 859 | out: |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 860 | mutex_unlock(&trace_types_lock); |
| 861 | } |
| 862 | |
Steven Rostedt | 283740c | 2010-03-12 19:48:41 -0500 | [diff] [blame] | 863 | static void __tracing_reset(struct ring_buffer *buffer, int cpu) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 864 | { |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 865 | ftrace_disable_cpu(); |
Steven Rostedt | 283740c | 2010-03-12 19:48:41 -0500 | [diff] [blame] | 866 | ring_buffer_reset_cpu(buffer, cpu); |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 867 | ftrace_enable_cpu(); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 868 | } |
| 869 | |
Steven Rostedt | f633903 | 2009-09-04 12:35:16 -0400 | [diff] [blame] | 870 | void tracing_reset(struct trace_array *tr, int cpu) |
| 871 | { |
| 872 | struct ring_buffer *buffer = tr->buffer; |
| 873 | |
| 874 | ring_buffer_record_disable(buffer); |
| 875 | |
| 876 | /* Make sure all commits have finished */ |
| 877 | synchronize_sched(); |
Steven Rostedt | 283740c | 2010-03-12 19:48:41 -0500 | [diff] [blame] | 878 | __tracing_reset(buffer, cpu); |
Steven Rostedt | f633903 | 2009-09-04 12:35:16 -0400 | [diff] [blame] | 879 | |
| 880 | ring_buffer_record_enable(buffer); |
| 881 | } |
| 882 | |
Pekka J Enberg | 213cc06 | 2008-12-19 12:08:39 +0200 | [diff] [blame] | 883 | void tracing_reset_online_cpus(struct trace_array *tr) |
| 884 | { |
Steven Rostedt | 621968c | 2009-09-04 12:02:35 -0400 | [diff] [blame] | 885 | struct ring_buffer *buffer = tr->buffer; |
Pekka J Enberg | 213cc06 | 2008-12-19 12:08:39 +0200 | [diff] [blame] | 886 | int cpu; |
| 887 | |
Steven Rostedt | 621968c | 2009-09-04 12:02:35 -0400 | [diff] [blame] | 888 | ring_buffer_record_disable(buffer); |
| 889 | |
| 890 | /* Make sure all commits have finished */ |
| 891 | synchronize_sched(); |
| 892 | |
Pekka J Enberg | 213cc06 | 2008-12-19 12:08:39 +0200 | [diff] [blame] | 893 | tr->time_start = ftrace_now(tr->cpu); |
| 894 | |
| 895 | for_each_online_cpu(cpu) |
Steven Rostedt | 283740c | 2010-03-12 19:48:41 -0500 | [diff] [blame] | 896 | __tracing_reset(buffer, cpu); |
Steven Rostedt | 621968c | 2009-09-04 12:02:35 -0400 | [diff] [blame] | 897 | |
| 898 | ring_buffer_record_enable(buffer); |
Pekka J Enberg | 213cc06 | 2008-12-19 12:08:39 +0200 | [diff] [blame] | 899 | } |
| 900 | |
Steven Rostedt | 9456f0f | 2009-05-06 21:54:09 -0400 | [diff] [blame] | 901 | void tracing_reset_current(int cpu) |
| 902 | { |
| 903 | tracing_reset(&global_trace, cpu); |
| 904 | } |
| 905 | |
| 906 | void tracing_reset_current_online_cpus(void) |
| 907 | { |
| 908 | tracing_reset_online_cpus(&global_trace); |
| 909 | } |
| 910 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 911 | #define SAVED_CMDLINES 128 |
Thomas Gleixner | 2c7eea4 | 2009-03-18 09:03:19 +0100 | [diff] [blame] | 912 | #define NO_CMDLINE_MAP UINT_MAX |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 913 | static unsigned map_pid_to_cmdline[PID_MAX_DEFAULT+1]; |
| 914 | static unsigned map_cmdline_to_pid[SAVED_CMDLINES]; |
| 915 | static char saved_cmdlines[SAVED_CMDLINES][TASK_COMM_LEN]; |
| 916 | static int cmdline_idx; |
Thomas Gleixner | edc35bd | 2009-12-03 12:38:57 +0100 | [diff] [blame] | 917 | static arch_spinlock_t trace_cmdline_lock = __ARCH_SPIN_LOCK_UNLOCKED; |
Steven Rostedt | 25b0b44 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 918 | |
Steven Rostedt | 25b0b44 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 919 | /* temporary disable recording */ |
Hannes Eder | 4fd2735 | 2009-02-10 19:44:12 +0100 | [diff] [blame] | 920 | static atomic_t trace_record_cmdline_disabled __read_mostly; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 921 | |
| 922 | static void trace_init_cmdlines(void) |
| 923 | { |
Thomas Gleixner | 2c7eea4 | 2009-03-18 09:03:19 +0100 | [diff] [blame] | 924 | memset(&map_pid_to_cmdline, NO_CMDLINE_MAP, sizeof(map_pid_to_cmdline)); |
| 925 | 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] | 926 | cmdline_idx = 0; |
| 927 | } |
| 928 | |
Carsten Emde | b5130b1 | 2009-09-13 01:43:07 +0200 | [diff] [blame] | 929 | int is_tracing_stopped(void) |
| 930 | { |
| 931 | return trace_stop_count; |
| 932 | } |
| 933 | |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 934 | /** |
Steven Rostedt | 69bb54e | 2008-11-21 12:59:38 -0500 | [diff] [blame] | 935 | * ftrace_off_permanent - disable all ftrace code permanently |
| 936 | * |
| 937 | * This should only be called when a serious anomally has |
| 938 | * been detected. This will turn off the function tracing, |
| 939 | * ring buffers, and other tracing utilites. It takes no |
| 940 | * locks and can be called from any context. |
| 941 | */ |
| 942 | void ftrace_off_permanent(void) |
| 943 | { |
| 944 | tracing_disabled = 1; |
| 945 | ftrace_stop(); |
| 946 | tracing_off_permanent(); |
| 947 | } |
| 948 | |
| 949 | /** |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 950 | * tracing_start - quick start of the tracer |
| 951 | * |
| 952 | * If tracing is enabled but was stopped by tracing_stop, |
| 953 | * this will start the tracer back up. |
| 954 | */ |
| 955 | void tracing_start(void) |
| 956 | { |
| 957 | struct ring_buffer *buffer; |
| 958 | unsigned long flags; |
| 959 | |
| 960 | if (tracing_disabled) |
| 961 | return; |
| 962 | |
| 963 | spin_lock_irqsave(&tracing_start_lock, flags); |
Steven Rostedt | b06a830 | 2009-01-22 14:26:15 -0500 | [diff] [blame] | 964 | if (--trace_stop_count) { |
| 965 | if (trace_stop_count < 0) { |
| 966 | /* Someone screwed up their debugging */ |
| 967 | WARN_ON_ONCE(1); |
| 968 | trace_stop_count = 0; |
| 969 | } |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 970 | goto out; |
| 971 | } |
| 972 | |
Steven Rostedt | a2f8071 | 2010-03-12 19:56:00 -0500 | [diff] [blame] | 973 | /* Prevent the buffers from switching */ |
| 974 | arch_spin_lock(&ftrace_max_lock); |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 975 | |
| 976 | buffer = global_trace.buffer; |
| 977 | if (buffer) |
| 978 | ring_buffer_record_enable(buffer); |
| 979 | |
| 980 | buffer = max_tr.buffer; |
| 981 | if (buffer) |
| 982 | ring_buffer_record_enable(buffer); |
| 983 | |
Steven Rostedt | a2f8071 | 2010-03-12 19:56:00 -0500 | [diff] [blame] | 984 | arch_spin_unlock(&ftrace_max_lock); |
| 985 | |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 986 | ftrace_start(); |
| 987 | out: |
| 988 | spin_unlock_irqrestore(&tracing_start_lock, flags); |
| 989 | } |
| 990 | |
| 991 | /** |
| 992 | * tracing_stop - quick stop of the tracer |
| 993 | * |
| 994 | * Light weight way to stop tracing. Use in conjunction with |
| 995 | * tracing_start. |
| 996 | */ |
| 997 | void tracing_stop(void) |
| 998 | { |
| 999 | struct ring_buffer *buffer; |
| 1000 | unsigned long flags; |
| 1001 | |
| 1002 | ftrace_stop(); |
| 1003 | spin_lock_irqsave(&tracing_start_lock, flags); |
| 1004 | if (trace_stop_count++) |
| 1005 | goto out; |
| 1006 | |
Steven Rostedt | a2f8071 | 2010-03-12 19:56:00 -0500 | [diff] [blame] | 1007 | /* Prevent the buffers from switching */ |
| 1008 | arch_spin_lock(&ftrace_max_lock); |
| 1009 | |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1010 | buffer = global_trace.buffer; |
| 1011 | if (buffer) |
| 1012 | ring_buffer_record_disable(buffer); |
| 1013 | |
| 1014 | buffer = max_tr.buffer; |
| 1015 | if (buffer) |
| 1016 | ring_buffer_record_disable(buffer); |
| 1017 | |
Steven Rostedt | a2f8071 | 2010-03-12 19:56:00 -0500 | [diff] [blame] | 1018 | arch_spin_unlock(&ftrace_max_lock); |
| 1019 | |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1020 | out: |
| 1021 | spin_unlock_irqrestore(&tracing_start_lock, flags); |
| 1022 | } |
| 1023 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1024 | void trace_stop_cmdline_recording(void); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1025 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1026 | static void trace_save_cmdline(struct task_struct *tsk) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1027 | { |
Carsten Emde | a635cf0 | 2009-03-18 09:00:41 +0100 | [diff] [blame] | 1028 | unsigned pid, idx; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1029 | |
| 1030 | if (!tsk->pid || unlikely(tsk->pid > PID_MAX_DEFAULT)) |
| 1031 | return; |
| 1032 | |
| 1033 | /* |
| 1034 | * It's not the end of the world if we don't get |
| 1035 | * the lock, but we also don't want to spin |
| 1036 | * nor do we want to disable interrupts, |
| 1037 | * so if we miss here, then better luck next time. |
| 1038 | */ |
Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 1039 | if (!arch_spin_trylock(&trace_cmdline_lock)) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1040 | return; |
| 1041 | |
| 1042 | idx = map_pid_to_cmdline[tsk->pid]; |
Thomas Gleixner | 2c7eea4 | 2009-03-18 09:03:19 +0100 | [diff] [blame] | 1043 | if (idx == NO_CMDLINE_MAP) { |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1044 | idx = (cmdline_idx + 1) % SAVED_CMDLINES; |
| 1045 | |
Carsten Emde | a635cf0 | 2009-03-18 09:00:41 +0100 | [diff] [blame] | 1046 | /* |
| 1047 | * Check whether the cmdline buffer at idx has a pid |
| 1048 | * mapped. We are going to overwrite that entry so we |
| 1049 | * need to clear the map_pid_to_cmdline. Otherwise we |
| 1050 | * would read the new comm for the old pid. |
| 1051 | */ |
| 1052 | pid = map_cmdline_to_pid[idx]; |
| 1053 | if (pid != NO_CMDLINE_MAP) |
| 1054 | map_pid_to_cmdline[pid] = NO_CMDLINE_MAP; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1055 | |
Carsten Emde | a635cf0 | 2009-03-18 09:00:41 +0100 | [diff] [blame] | 1056 | map_cmdline_to_pid[idx] = tsk->pid; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1057 | map_pid_to_cmdline[tsk->pid] = idx; |
| 1058 | |
| 1059 | cmdline_idx = idx; |
| 1060 | } |
| 1061 | |
| 1062 | memcpy(&saved_cmdlines[idx], tsk->comm, TASK_COMM_LEN); |
| 1063 | |
Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 1064 | arch_spin_unlock(&trace_cmdline_lock); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1065 | } |
| 1066 | |
Steven Rostedt | 4ca53085 | 2009-03-16 19:20:15 -0400 | [diff] [blame] | 1067 | void trace_find_cmdline(int pid, char comm[]) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1068 | { |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1069 | unsigned map; |
| 1070 | |
Steven Rostedt | 4ca53085 | 2009-03-16 19:20:15 -0400 | [diff] [blame] | 1071 | if (!pid) { |
| 1072 | strcpy(comm, "<idle>"); |
| 1073 | return; |
| 1074 | } |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1075 | |
Steven Rostedt | 74bf407 | 2010-01-25 15:11:53 -0500 | [diff] [blame] | 1076 | if (WARN_ON_ONCE(pid < 0)) { |
| 1077 | strcpy(comm, "<XXX>"); |
| 1078 | return; |
| 1079 | } |
| 1080 | |
Steven Rostedt | 4ca53085 | 2009-03-16 19:20:15 -0400 | [diff] [blame] | 1081 | if (pid > PID_MAX_DEFAULT) { |
| 1082 | strcpy(comm, "<...>"); |
| 1083 | return; |
| 1084 | } |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1085 | |
Heiko Carstens | 5b6045a | 2009-05-26 17:28:02 +0200 | [diff] [blame] | 1086 | preempt_disable(); |
Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 1087 | arch_spin_lock(&trace_cmdline_lock); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1088 | map = map_pid_to_cmdline[pid]; |
Thomas Gleixner | 50d8875 | 2009-03-18 08:58:44 +0100 | [diff] [blame] | 1089 | if (map != NO_CMDLINE_MAP) |
| 1090 | strcpy(comm, saved_cmdlines[map]); |
| 1091 | else |
| 1092 | strcpy(comm, "<...>"); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1093 | |
Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 1094 | arch_spin_unlock(&trace_cmdline_lock); |
Heiko Carstens | 5b6045a | 2009-05-26 17:28:02 +0200 | [diff] [blame] | 1095 | preempt_enable(); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1096 | } |
| 1097 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1098 | void tracing_record_cmdline(struct task_struct *tsk) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1099 | { |
Thomas Gleixner | 18aecd3 | 2009-03-18 08:56:58 +0100 | [diff] [blame] | 1100 | if (atomic_read(&trace_record_cmdline_disabled) || !tracer_enabled || |
| 1101 | !tracing_is_on()) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1102 | return; |
| 1103 | |
| 1104 | trace_save_cmdline(tsk); |
| 1105 | } |
| 1106 | |
Pekka Paalanen | 45dcd8b | 2008-09-16 21:56:41 +0300 | [diff] [blame] | 1107 | void |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 1108 | tracing_generic_entry_update(struct trace_entry *entry, unsigned long flags, |
| 1109 | int pc) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1110 | { |
| 1111 | struct task_struct *tsk = current; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1112 | |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1113 | entry->preempt_count = pc & 0xff; |
| 1114 | entry->pid = (tsk) ? tsk->pid : 0; |
Arjan van de Ven | a3a4a5a | 2011-05-05 23:55:18 -0400 | [diff] [blame] | 1115 | entry->padding = 0; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1116 | entry->flags = |
Steven Rostedt | 9244489 | 2008-10-24 09:42:59 -0400 | [diff] [blame] | 1117 | #ifdef CONFIG_TRACE_IRQFLAGS_SUPPORT |
Steven Rostedt | 2e2ca15 | 2008-08-01 12:26:40 -0400 | [diff] [blame] | 1118 | (irqs_disabled_flags(flags) ? TRACE_FLAG_IRQS_OFF : 0) | |
Steven Rostedt | 9244489 | 2008-10-24 09:42:59 -0400 | [diff] [blame] | 1119 | #else |
| 1120 | TRACE_FLAG_IRQS_NOSUPPORT | |
| 1121 | #endif |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1122 | ((pc & HARDIRQ_MASK) ? TRACE_FLAG_HARDIRQ : 0) | |
| 1123 | ((pc & SOFTIRQ_MASK) ? TRACE_FLAG_SOFTIRQ : 0) | |
| 1124 | (need_resched() ? TRACE_FLAG_NEED_RESCHED : 0); |
| 1125 | } |
Frederic Weisbecker | f413cdb | 2009-08-07 01:25:54 +0200 | [diff] [blame] | 1126 | EXPORT_SYMBOL_GPL(tracing_generic_entry_update); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1127 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1128 | struct ring_buffer_event * |
| 1129 | trace_buffer_lock_reserve(struct ring_buffer *buffer, |
| 1130 | int type, |
| 1131 | unsigned long len, |
| 1132 | unsigned long flags, int pc) |
Arnaldo Carvalho de Melo | 51a763d | 2009-02-05 16:14:13 -0200 | [diff] [blame] | 1133 | { |
| 1134 | struct ring_buffer_event *event; |
| 1135 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1136 | event = ring_buffer_lock_reserve(buffer, len); |
Arnaldo Carvalho de Melo | 51a763d | 2009-02-05 16:14:13 -0200 | [diff] [blame] | 1137 | if (event != NULL) { |
| 1138 | struct trace_entry *ent = ring_buffer_event_data(event); |
| 1139 | |
| 1140 | tracing_generic_entry_update(ent, flags, pc); |
| 1141 | ent->type = type; |
| 1142 | } |
| 1143 | |
| 1144 | return event; |
| 1145 | } |
Arnaldo Carvalho de Melo | 51a763d | 2009-02-05 16:14:13 -0200 | [diff] [blame] | 1146 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1147 | static inline void |
| 1148 | __trace_buffer_unlock_commit(struct ring_buffer *buffer, |
| 1149 | struct ring_buffer_event *event, |
| 1150 | unsigned long flags, int pc, |
| 1151 | int wake) |
Arnaldo Carvalho de Melo | 51a763d | 2009-02-05 16:14:13 -0200 | [diff] [blame] | 1152 | { |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1153 | ring_buffer_unlock_commit(buffer, event); |
Arnaldo Carvalho de Melo | 51a763d | 2009-02-05 16:14:13 -0200 | [diff] [blame] | 1154 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1155 | ftrace_trace_stack(buffer, flags, 6, pc); |
| 1156 | ftrace_trace_userstack(buffer, flags, pc); |
Frederic Weisbecker | 07edf71 | 2009-03-22 23:10:46 +0100 | [diff] [blame] | 1157 | |
| 1158 | if (wake) |
| 1159 | trace_wake_up(); |
| 1160 | } |
| 1161 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1162 | void trace_buffer_unlock_commit(struct ring_buffer *buffer, |
| 1163 | struct ring_buffer_event *event, |
| 1164 | unsigned long flags, int pc) |
Frederic Weisbecker | 07edf71 | 2009-03-22 23:10:46 +0100 | [diff] [blame] | 1165 | { |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1166 | __trace_buffer_unlock_commit(buffer, event, flags, pc, 1); |
Arnaldo Carvalho de Melo | 51a763d | 2009-02-05 16:14:13 -0200 | [diff] [blame] | 1167 | } |
| 1168 | |
Steven Rostedt | ef5580d | 2009-02-27 19:38:04 -0500 | [diff] [blame] | 1169 | struct ring_buffer_event * |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1170 | trace_current_buffer_lock_reserve(struct ring_buffer **current_rb, |
| 1171 | int type, unsigned long len, |
Steven Rostedt | ef5580d | 2009-02-27 19:38:04 -0500 | [diff] [blame] | 1172 | unsigned long flags, int pc) |
| 1173 | { |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1174 | *current_rb = global_trace.buffer; |
| 1175 | return trace_buffer_lock_reserve(*current_rb, |
Steven Rostedt | ef5580d | 2009-02-27 19:38:04 -0500 | [diff] [blame] | 1176 | type, len, flags, pc); |
| 1177 | } |
Steven Rostedt | 94487d6 | 2009-05-05 19:22:53 -0400 | [diff] [blame] | 1178 | EXPORT_SYMBOL_GPL(trace_current_buffer_lock_reserve); |
Steven Rostedt | ef5580d | 2009-02-27 19:38:04 -0500 | [diff] [blame] | 1179 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1180 | void trace_current_buffer_unlock_commit(struct ring_buffer *buffer, |
| 1181 | struct ring_buffer_event *event, |
Steven Rostedt | ef5580d | 2009-02-27 19:38:04 -0500 | [diff] [blame] | 1182 | unsigned long flags, int pc) |
| 1183 | { |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1184 | __trace_buffer_unlock_commit(buffer, event, flags, pc, 1); |
Frederic Weisbecker | 07edf71 | 2009-03-22 23:10:46 +0100 | [diff] [blame] | 1185 | } |
Steven Rostedt | 94487d6 | 2009-05-05 19:22:53 -0400 | [diff] [blame] | 1186 | EXPORT_SYMBOL_GPL(trace_current_buffer_unlock_commit); |
Frederic Weisbecker | 07edf71 | 2009-03-22 23:10:46 +0100 | [diff] [blame] | 1187 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1188 | void trace_nowake_buffer_unlock_commit(struct ring_buffer *buffer, |
| 1189 | struct ring_buffer_event *event, |
| 1190 | unsigned long flags, int pc) |
Frederic Weisbecker | 07edf71 | 2009-03-22 23:10:46 +0100 | [diff] [blame] | 1191 | { |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1192 | __trace_buffer_unlock_commit(buffer, event, flags, pc, 0); |
Steven Rostedt | ef5580d | 2009-02-27 19:38:04 -0500 | [diff] [blame] | 1193 | } |
Steven Rostedt | 94487d6 | 2009-05-05 19:22:53 -0400 | [diff] [blame] | 1194 | EXPORT_SYMBOL_GPL(trace_nowake_buffer_unlock_commit); |
Steven Rostedt | 77d9f46 | 2009-04-02 01:16:59 -0400 | [diff] [blame] | 1195 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1196 | void trace_current_buffer_discard_commit(struct ring_buffer *buffer, |
| 1197 | struct ring_buffer_event *event) |
Steven Rostedt | 77d9f46 | 2009-04-02 01:16:59 -0400 | [diff] [blame] | 1198 | { |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1199 | ring_buffer_discard_commit(buffer, event); |
Steven Rostedt | ef5580d | 2009-02-27 19:38:04 -0500 | [diff] [blame] | 1200 | } |
Steven Rostedt | 12acd47 | 2009-04-17 16:01:56 -0400 | [diff] [blame] | 1201 | EXPORT_SYMBOL_GPL(trace_current_buffer_discard_commit); |
Steven Rostedt | ef5580d | 2009-02-27 19:38:04 -0500 | [diff] [blame] | 1202 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1203 | void |
Arnaldo Carvalho de Melo | 7be4215 | 2009-02-05 01:13:37 -0500 | [diff] [blame] | 1204 | trace_function(struct trace_array *tr, |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 1205 | unsigned long ip, unsigned long parent_ip, unsigned long flags, |
| 1206 | int pc) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1207 | { |
Tom Zanussi | e1112b4 | 2009-03-31 00:48:49 -0500 | [diff] [blame] | 1208 | struct ftrace_event_call *call = &event_function; |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1209 | struct ring_buffer *buffer = tr->buffer; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1210 | struct ring_buffer_event *event; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1211 | struct ftrace_entry *entry; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1212 | |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 1213 | /* If we are reading the ring buffer, don't trace */ |
Rusty Russell | dd17c8f | 2009-10-29 22:34:15 +0900 | [diff] [blame] | 1214 | if (unlikely(__this_cpu_read(ftrace_cpu_disabled))) |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 1215 | return; |
| 1216 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1217 | event = trace_buffer_lock_reserve(buffer, TRACE_FN, sizeof(*entry), |
Arnaldo Carvalho de Melo | 51a763d | 2009-02-05 16:14:13 -0200 | [diff] [blame] | 1218 | flags, pc); |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1219 | if (!event) |
| 1220 | return; |
| 1221 | entry = ring_buffer_event_data(event); |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1222 | entry->ip = ip; |
| 1223 | entry->parent_ip = parent_ip; |
Tom Zanussi | e1112b4 | 2009-03-31 00:48:49 -0500 | [diff] [blame] | 1224 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1225 | if (!filter_check_discard(call, entry, buffer, event)) |
| 1226 | ring_buffer_unlock_commit(buffer, event); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1227 | } |
| 1228 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1229 | void |
Ingo Molnar | 2e0f576 | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 1230 | ftrace(struct trace_array *tr, struct trace_array_cpu *data, |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 1231 | unsigned long ip, unsigned long parent_ip, unsigned long flags, |
| 1232 | int pc) |
Ingo Molnar | 2e0f576 | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 1233 | { |
| 1234 | if (likely(!atomic_read(&data->disabled))) |
Arnaldo Carvalho de Melo | 7be4215 | 2009-02-05 01:13:37 -0500 | [diff] [blame] | 1235 | trace_function(tr, ip, parent_ip, flags, pc); |
Ingo Molnar | 2e0f576 | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 1236 | } |
| 1237 | |
Frederic Weisbecker | c0a0d0d | 2009-07-29 17:51:13 +0200 | [diff] [blame] | 1238 | #ifdef CONFIG_STACKTRACE |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1239 | static void __ftrace_trace_stack(struct ring_buffer *buffer, |
Steven Rostedt | 5361499 | 2009-01-15 19:12:40 -0500 | [diff] [blame] | 1240 | unsigned long flags, |
| 1241 | int skip, int pc) |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1242 | { |
Tom Zanussi | e1112b4 | 2009-03-31 00:48:49 -0500 | [diff] [blame] | 1243 | struct ftrace_event_call *call = &event_kernel_stack; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1244 | struct ring_buffer_event *event; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1245 | struct stack_entry *entry; |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1246 | struct stack_trace trace; |
| 1247 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1248 | event = trace_buffer_lock_reserve(buffer, TRACE_STACK, |
Arnaldo Carvalho de Melo | 51a763d | 2009-02-05 16:14:13 -0200 | [diff] [blame] | 1249 | sizeof(*entry), flags, pc); |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1250 | if (!event) |
| 1251 | return; |
| 1252 | entry = ring_buffer_event_data(event); |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1253 | memset(&entry->caller, 0, sizeof(entry->caller)); |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1254 | |
| 1255 | trace.nr_entries = 0; |
| 1256 | trace.max_entries = FTRACE_STACK_ENTRIES; |
| 1257 | trace.skip = skip; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1258 | trace.entries = entry->caller; |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1259 | |
| 1260 | save_stack_trace(&trace); |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1261 | if (!filter_check_discard(call, entry, buffer, event)) |
| 1262 | ring_buffer_unlock_commit(buffer, event); |
Ingo Molnar | f0a920d | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 1263 | } |
| 1264 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1265 | void ftrace_trace_stack(struct ring_buffer *buffer, unsigned long flags, |
| 1266 | int skip, int pc) |
Steven Rostedt | 5361499 | 2009-01-15 19:12:40 -0500 | [diff] [blame] | 1267 | { |
| 1268 | if (!(trace_flags & TRACE_ITER_STACKTRACE)) |
| 1269 | return; |
| 1270 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1271 | __ftrace_trace_stack(buffer, flags, skip, pc); |
Steven Rostedt | 5361499 | 2009-01-15 19:12:40 -0500 | [diff] [blame] | 1272 | } |
| 1273 | |
Frederic Weisbecker | c0a0d0d | 2009-07-29 17:51:13 +0200 | [diff] [blame] | 1274 | void __trace_stack(struct trace_array *tr, unsigned long flags, int skip, |
| 1275 | int pc) |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 1276 | { |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1277 | __ftrace_trace_stack(tr->buffer, flags, skip, pc); |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 1278 | } |
| 1279 | |
Steven Rostedt | 0388938 | 2009-12-11 09:48:22 -0500 | [diff] [blame] | 1280 | /** |
| 1281 | * trace_dump_stack - record a stack back trace in the trace buffer |
| 1282 | */ |
| 1283 | void trace_dump_stack(void) |
| 1284 | { |
| 1285 | unsigned long flags; |
| 1286 | |
| 1287 | if (tracing_disabled || tracing_selftest_running) |
Steven Rostedt | e36c545 | 2009-12-14 15:58:33 -0500 | [diff] [blame] | 1288 | return; |
Steven Rostedt | 0388938 | 2009-12-11 09:48:22 -0500 | [diff] [blame] | 1289 | |
| 1290 | local_save_flags(flags); |
| 1291 | |
| 1292 | /* skipping 3 traces, seems to get us at the caller of this function */ |
| 1293 | __ftrace_trace_stack(global_trace.buffer, flags, 3, preempt_count()); |
| 1294 | } |
| 1295 | |
Steven Rostedt | 91e86e5 | 2010-11-10 12:56:12 +0100 | [diff] [blame] | 1296 | static DEFINE_PER_CPU(int, user_stack_count); |
| 1297 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1298 | void |
| 1299 | 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] | 1300 | { |
Tom Zanussi | e1112b4 | 2009-03-31 00:48:49 -0500 | [diff] [blame] | 1301 | struct ftrace_event_call *call = &event_user_stack; |
Török Edwin | 8d7c6a9 | 2008-11-23 12:39:06 +0200 | [diff] [blame] | 1302 | struct ring_buffer_event *event; |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 1303 | struct userstack_entry *entry; |
| 1304 | struct stack_trace trace; |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 1305 | |
| 1306 | if (!(trace_flags & TRACE_ITER_USERSTACKTRACE)) |
| 1307 | return; |
| 1308 | |
Steven Rostedt | b634587 | 2010-03-12 20:03:30 -0500 | [diff] [blame] | 1309 | /* |
| 1310 | * NMIs can not handle page faults, even with fix ups. |
| 1311 | * The save user stack can (and often does) fault. |
| 1312 | */ |
| 1313 | if (unlikely(in_nmi())) |
| 1314 | return; |
| 1315 | |
Steven Rostedt | 91e86e5 | 2010-11-10 12:56:12 +0100 | [diff] [blame] | 1316 | /* |
| 1317 | * prevent recursion, since the user stack tracing may |
| 1318 | * trigger other kernel events. |
| 1319 | */ |
| 1320 | preempt_disable(); |
| 1321 | if (__this_cpu_read(user_stack_count)) |
| 1322 | goto out; |
| 1323 | |
| 1324 | __this_cpu_inc(user_stack_count); |
| 1325 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1326 | event = trace_buffer_lock_reserve(buffer, TRACE_USER_STACK, |
Arnaldo Carvalho de Melo | 51a763d | 2009-02-05 16:14:13 -0200 | [diff] [blame] | 1327 | sizeof(*entry), flags, pc); |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 1328 | if (!event) |
Li Zefan | 1dbd195 | 2010-12-09 15:47:56 +0800 | [diff] [blame] | 1329 | goto out_drop_count; |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 1330 | entry = ring_buffer_event_data(event); |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 1331 | |
Steven Rostedt | 48659d3 | 2009-09-11 11:36:23 -0400 | [diff] [blame] | 1332 | entry->tgid = current->tgid; |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 1333 | memset(&entry->caller, 0, sizeof(entry->caller)); |
| 1334 | |
| 1335 | trace.nr_entries = 0; |
| 1336 | trace.max_entries = FTRACE_STACK_ENTRIES; |
| 1337 | trace.skip = 0; |
| 1338 | trace.entries = entry->caller; |
| 1339 | |
| 1340 | save_stack_trace_user(&trace); |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1341 | if (!filter_check_discard(call, entry, buffer, event)) |
| 1342 | ring_buffer_unlock_commit(buffer, event); |
Steven Rostedt | 91e86e5 | 2010-11-10 12:56:12 +0100 | [diff] [blame] | 1343 | |
Li Zefan | 1dbd195 | 2010-12-09 15:47:56 +0800 | [diff] [blame] | 1344 | out_drop_count: |
Steven Rostedt | 91e86e5 | 2010-11-10 12:56:12 +0100 | [diff] [blame] | 1345 | __this_cpu_dec(user_stack_count); |
Steven Rostedt | 91e86e5 | 2010-11-10 12:56:12 +0100 | [diff] [blame] | 1346 | out: |
| 1347 | preempt_enable(); |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 1348 | } |
| 1349 | |
Hannes Eder | 4fd2735 | 2009-02-10 19:44:12 +0100 | [diff] [blame] | 1350 | #ifdef UNUSED |
| 1351 | 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] | 1352 | { |
Arnaldo Carvalho de Melo | 7be4215 | 2009-02-05 01:13:37 -0500 | [diff] [blame] | 1353 | ftrace_trace_userstack(tr, flags, preempt_count()); |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 1354 | } |
Hannes Eder | 4fd2735 | 2009-02-10 19:44:12 +0100 | [diff] [blame] | 1355 | #endif /* UNUSED */ |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 1356 | |
Frederic Weisbecker | c0a0d0d | 2009-07-29 17:51:13 +0200 | [diff] [blame] | 1357 | #endif /* CONFIG_STACKTRACE */ |
| 1358 | |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 1359 | /** |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 1360 | * trace_vbprintk - write binary msg to tracing buffer |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 1361 | * |
| 1362 | */ |
Steven Rostedt | 40ce74f | 2009-03-19 14:03:53 -0400 | [diff] [blame] | 1363 | int trace_vbprintk(unsigned long ip, const char *fmt, va_list args) |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 1364 | { |
Thomas Gleixner | 445c895 | 2009-12-02 19:49:50 +0100 | [diff] [blame] | 1365 | static arch_spinlock_t trace_buf_lock = |
Thomas Gleixner | edc35bd | 2009-12-03 12:38:57 +0100 | [diff] [blame] | 1366 | (arch_spinlock_t)__ARCH_SPIN_LOCK_UNLOCKED; |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 1367 | static u32 trace_buf[TRACE_BUF_SIZE]; |
| 1368 | |
Tom Zanussi | e1112b4 | 2009-03-31 00:48:49 -0500 | [diff] [blame] | 1369 | struct ftrace_event_call *call = &event_bprint; |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 1370 | struct ring_buffer_event *event; |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1371 | struct ring_buffer *buffer; |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 1372 | struct trace_array *tr = &global_trace; |
| 1373 | struct trace_array_cpu *data; |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 1374 | struct bprint_entry *entry; |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 1375 | unsigned long flags; |
Steven Rostedt | 3189cdb | 2009-04-17 16:13:55 -0400 | [diff] [blame] | 1376 | int disable; |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 1377 | int cpu, len = 0, size, pc; |
| 1378 | |
| 1379 | if (unlikely(tracing_selftest_running || tracing_disabled)) |
| 1380 | return 0; |
| 1381 | |
| 1382 | /* Don't pollute graph traces with trace_vprintk internals */ |
| 1383 | pause_graph_tracing(); |
| 1384 | |
| 1385 | pc = preempt_count(); |
Steven Rostedt | 5168ae5 | 2010-06-03 09:36:50 -0400 | [diff] [blame] | 1386 | preempt_disable_notrace(); |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 1387 | cpu = raw_smp_processor_id(); |
| 1388 | data = tr->data[cpu]; |
| 1389 | |
Steven Rostedt | 3189cdb | 2009-04-17 16:13:55 -0400 | [diff] [blame] | 1390 | disable = atomic_inc_return(&data->disabled); |
| 1391 | if (unlikely(disable != 1)) |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 1392 | goto out; |
| 1393 | |
Steven Rostedt | 80370cb | 2009-03-10 17:16:35 -0400 | [diff] [blame] | 1394 | /* Lockdep uses trace_printk for lock tracing */ |
| 1395 | local_irq_save(flags); |
Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 1396 | arch_spin_lock(&trace_buf_lock); |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 1397 | len = vbin_printf(trace_buf, TRACE_BUF_SIZE, fmt, args); |
| 1398 | |
| 1399 | if (len > TRACE_BUF_SIZE || len < 0) |
| 1400 | goto out_unlock; |
| 1401 | |
| 1402 | size = sizeof(*entry) + sizeof(u32) * len; |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1403 | buffer = tr->buffer; |
| 1404 | event = trace_buffer_lock_reserve(buffer, TRACE_BPRINT, size, |
| 1405 | flags, pc); |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 1406 | if (!event) |
| 1407 | goto out_unlock; |
| 1408 | entry = ring_buffer_event_data(event); |
| 1409 | entry->ip = ip; |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 1410 | entry->fmt = fmt; |
| 1411 | |
| 1412 | memcpy(entry->buf, trace_buf, sizeof(u32) * len); |
Steven Rostedt | d931369 | 2010-01-06 17:27:11 -0500 | [diff] [blame] | 1413 | if (!filter_check_discard(call, entry, buffer, event)) { |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1414 | ring_buffer_unlock_commit(buffer, event); |
Steven Rostedt | d931369 | 2010-01-06 17:27:11 -0500 | [diff] [blame] | 1415 | ftrace_trace_stack(buffer, flags, 6, pc); |
| 1416 | } |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 1417 | |
| 1418 | out_unlock: |
Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 1419 | arch_spin_unlock(&trace_buf_lock); |
Steven Rostedt | 80370cb | 2009-03-10 17:16:35 -0400 | [diff] [blame] | 1420 | local_irq_restore(flags); |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 1421 | |
| 1422 | out: |
Steven Rostedt | 3189cdb | 2009-04-17 16:13:55 -0400 | [diff] [blame] | 1423 | atomic_dec_return(&data->disabled); |
Steven Rostedt | 5168ae5 | 2010-06-03 09:36:50 -0400 | [diff] [blame] | 1424 | preempt_enable_notrace(); |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 1425 | unpause_graph_tracing(); |
| 1426 | |
| 1427 | return len; |
| 1428 | } |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 1429 | EXPORT_SYMBOL_GPL(trace_vbprintk); |
| 1430 | |
Steven Rostedt | 659372d | 2009-09-03 19:11:07 -0400 | [diff] [blame] | 1431 | int trace_array_printk(struct trace_array *tr, |
| 1432 | unsigned long ip, const char *fmt, ...) |
| 1433 | { |
| 1434 | int ret; |
| 1435 | va_list ap; |
| 1436 | |
| 1437 | if (!(trace_flags & TRACE_ITER_PRINTK)) |
| 1438 | return 0; |
| 1439 | |
| 1440 | va_start(ap, fmt); |
| 1441 | ret = trace_array_vprintk(tr, ip, fmt, ap); |
| 1442 | va_end(ap); |
| 1443 | return ret; |
| 1444 | } |
| 1445 | |
| 1446 | int trace_array_vprintk(struct trace_array *tr, |
| 1447 | unsigned long ip, const char *fmt, va_list args) |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 1448 | { |
Thomas Gleixner | edc35bd | 2009-12-03 12:38:57 +0100 | [diff] [blame] | 1449 | static arch_spinlock_t trace_buf_lock = __ARCH_SPIN_LOCK_UNLOCKED; |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 1450 | static char trace_buf[TRACE_BUF_SIZE]; |
| 1451 | |
Tom Zanussi | e1112b4 | 2009-03-31 00:48:49 -0500 | [diff] [blame] | 1452 | struct ftrace_event_call *call = &event_print; |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 1453 | struct ring_buffer_event *event; |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1454 | struct ring_buffer *buffer; |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 1455 | struct trace_array_cpu *data; |
| 1456 | int cpu, len = 0, size, pc; |
| 1457 | struct print_entry *entry; |
| 1458 | unsigned long irq_flags; |
Steven Rostedt | 3189cdb | 2009-04-17 16:13:55 -0400 | [diff] [blame] | 1459 | int disable; |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 1460 | |
| 1461 | if (tracing_disabled || tracing_selftest_running) |
| 1462 | return 0; |
| 1463 | |
| 1464 | pc = preempt_count(); |
| 1465 | preempt_disable_notrace(); |
| 1466 | cpu = raw_smp_processor_id(); |
| 1467 | data = tr->data[cpu]; |
| 1468 | |
Steven Rostedt | 3189cdb | 2009-04-17 16:13:55 -0400 | [diff] [blame] | 1469 | disable = atomic_inc_return(&data->disabled); |
| 1470 | if (unlikely(disable != 1)) |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 1471 | goto out; |
| 1472 | |
| 1473 | pause_graph_tracing(); |
| 1474 | raw_local_irq_save(irq_flags); |
Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 1475 | arch_spin_lock(&trace_buf_lock); |
Carsten Emde | f294248 | 2009-12-06 14:02:44 +0100 | [diff] [blame] | 1476 | len = vsnprintf(trace_buf, TRACE_BUF_SIZE, fmt, args); |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 1477 | |
| 1478 | size = sizeof(*entry) + len + 1; |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1479 | buffer = tr->buffer; |
| 1480 | event = trace_buffer_lock_reserve(buffer, TRACE_PRINT, size, |
| 1481 | irq_flags, pc); |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 1482 | if (!event) |
| 1483 | goto out_unlock; |
| 1484 | entry = ring_buffer_event_data(event); |
Carsten Emde | c13d2f7 | 2009-11-16 20:56:13 +0100 | [diff] [blame] | 1485 | entry->ip = ip; |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 1486 | |
| 1487 | memcpy(&entry->buf, trace_buf, len); |
Carsten Emde | c13d2f7 | 2009-11-16 20:56:13 +0100 | [diff] [blame] | 1488 | entry->buf[len] = '\0'; |
Steven Rostedt | d931369 | 2010-01-06 17:27:11 -0500 | [diff] [blame] | 1489 | if (!filter_check_discard(call, entry, buffer, event)) { |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1490 | ring_buffer_unlock_commit(buffer, event); |
Steven Rostedt | d931369 | 2010-01-06 17:27:11 -0500 | [diff] [blame] | 1491 | ftrace_trace_stack(buffer, irq_flags, 6, pc); |
| 1492 | } |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 1493 | |
| 1494 | out_unlock: |
Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 1495 | arch_spin_unlock(&trace_buf_lock); |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 1496 | raw_local_irq_restore(irq_flags); |
| 1497 | unpause_graph_tracing(); |
| 1498 | out: |
Steven Rostedt | 3189cdb | 2009-04-17 16:13:55 -0400 | [diff] [blame] | 1499 | atomic_dec_return(&data->disabled); |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 1500 | preempt_enable_notrace(); |
| 1501 | |
| 1502 | return len; |
| 1503 | } |
Steven Rostedt | 659372d | 2009-09-03 19:11:07 -0400 | [diff] [blame] | 1504 | |
| 1505 | int trace_vprintk(unsigned long ip, const char *fmt, va_list args) |
| 1506 | { |
Steven Rostedt | a813a15 | 2009-10-09 01:41:35 -0400 | [diff] [blame] | 1507 | return trace_array_vprintk(&global_trace, ip, fmt, args); |
Steven Rostedt | 659372d | 2009-09-03 19:11:07 -0400 | [diff] [blame] | 1508 | } |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 1509 | EXPORT_SYMBOL_GPL(trace_vprintk); |
| 1510 | |
Robert Richter | e2ac8ef | 2008-11-12 12:59:32 +0100 | [diff] [blame] | 1511 | static void trace_iterator_increment(struct trace_iterator *iter) |
Steven Rostedt | 5a90f57 | 2008-09-03 17:42:51 -0400 | [diff] [blame] | 1512 | { |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 1513 | /* Don't allow ftrace to trace into the ring buffers */ |
| 1514 | ftrace_disable_cpu(); |
| 1515 | |
Steven Rostedt | 5a90f57 | 2008-09-03 17:42:51 -0400 | [diff] [blame] | 1516 | iter->idx++; |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 1517 | if (iter->buffer_iter[iter->cpu]) |
| 1518 | ring_buffer_read(iter->buffer_iter[iter->cpu], NULL); |
| 1519 | |
| 1520 | ftrace_enable_cpu(); |
Steven Rostedt | 5a90f57 | 2008-09-03 17:42:51 -0400 | [diff] [blame] | 1521 | } |
| 1522 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1523 | static struct trace_entry * |
Steven Rostedt | bc21b47 | 2010-03-31 19:49:26 -0400 | [diff] [blame] | 1524 | peek_next_entry(struct trace_iterator *iter, int cpu, u64 *ts, |
| 1525 | unsigned long *lost_events) |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1526 | { |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1527 | struct ring_buffer_event *event; |
| 1528 | struct ring_buffer_iter *buf_iter = iter->buffer_iter[cpu]; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1529 | |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 1530 | /* Don't allow ftrace to trace into the ring buffers */ |
| 1531 | ftrace_disable_cpu(); |
| 1532 | |
| 1533 | if (buf_iter) |
| 1534 | event = ring_buffer_iter_peek(buf_iter, ts); |
| 1535 | else |
Steven Rostedt | bc21b47 | 2010-03-31 19:49:26 -0400 | [diff] [blame] | 1536 | event = ring_buffer_peek(iter->tr->buffer, cpu, ts, |
| 1537 | lost_events); |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 1538 | |
| 1539 | ftrace_enable_cpu(); |
| 1540 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1541 | return event ? ring_buffer_event_data(event) : NULL; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1542 | } |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 1543 | |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1544 | static struct trace_entry * |
Steven Rostedt | bc21b47 | 2010-03-31 19:49:26 -0400 | [diff] [blame] | 1545 | __find_next_entry(struct trace_iterator *iter, int *ent_cpu, |
| 1546 | unsigned long *missing_events, u64 *ent_ts) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1547 | { |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1548 | struct ring_buffer *buffer = iter->tr->buffer; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1549 | struct trace_entry *ent, *next = NULL; |
Lai Jiangshan | aa27497 | 2010-04-05 17:11:05 +0800 | [diff] [blame] | 1550 | unsigned long lost_events = 0, next_lost = 0; |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 1551 | int cpu_file = iter->cpu_file; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1552 | u64 next_ts = 0, ts; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1553 | int next_cpu = -1; |
| 1554 | int cpu; |
| 1555 | |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 1556 | /* |
| 1557 | * If we are in a per_cpu trace file, don't bother by iterating over |
| 1558 | * all cpu and peek directly. |
| 1559 | */ |
| 1560 | if (cpu_file > TRACE_PIPE_ALL_CPU) { |
| 1561 | if (ring_buffer_empty_cpu(buffer, cpu_file)) |
| 1562 | return NULL; |
Steven Rostedt | bc21b47 | 2010-03-31 19:49:26 -0400 | [diff] [blame] | 1563 | ent = peek_next_entry(iter, cpu_file, ent_ts, missing_events); |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 1564 | if (ent_cpu) |
| 1565 | *ent_cpu = cpu_file; |
| 1566 | |
| 1567 | return ent; |
| 1568 | } |
| 1569 | |
Steven Rostedt | ab46428 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 1570 | for_each_tracing_cpu(cpu) { |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1571 | |
| 1572 | if (ring_buffer_empty_cpu(buffer, cpu)) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1573 | continue; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1574 | |
Steven Rostedt | bc21b47 | 2010-03-31 19:49:26 -0400 | [diff] [blame] | 1575 | ent = peek_next_entry(iter, cpu, &ts, &lost_events); |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1576 | |
Ingo Molnar | cdd31cd2 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1577 | /* |
| 1578 | * Pick the entry with the smallest timestamp: |
| 1579 | */ |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1580 | if (ent && (!next || ts < next_ts)) { |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1581 | next = ent; |
| 1582 | next_cpu = cpu; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1583 | next_ts = ts; |
Steven Rostedt | bc21b47 | 2010-03-31 19:49:26 -0400 | [diff] [blame] | 1584 | next_lost = lost_events; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1585 | } |
| 1586 | } |
| 1587 | |
| 1588 | if (ent_cpu) |
| 1589 | *ent_cpu = next_cpu; |
| 1590 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1591 | if (ent_ts) |
| 1592 | *ent_ts = next_ts; |
| 1593 | |
Steven Rostedt | bc21b47 | 2010-03-31 19:49:26 -0400 | [diff] [blame] | 1594 | if (missing_events) |
| 1595 | *missing_events = next_lost; |
| 1596 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1597 | return next; |
| 1598 | } |
| 1599 | |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1600 | /* Find the next real entry, without updating the iterator itself */ |
Frederic Weisbecker | c4a8e8b | 2009-02-02 20:29:21 -0200 | [diff] [blame] | 1601 | struct trace_entry *trace_find_next_entry(struct trace_iterator *iter, |
| 1602 | int *ent_cpu, u64 *ent_ts) |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1603 | { |
Steven Rostedt | bc21b47 | 2010-03-31 19:49:26 -0400 | [diff] [blame] | 1604 | return __find_next_entry(iter, ent_cpu, NULL, ent_ts); |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1605 | } |
Ingo Molnar | 8c523a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1606 | |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1607 | /* 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] | 1608 | void *trace_find_next_entry_inc(struct trace_iterator *iter) |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1609 | { |
Steven Rostedt | bc21b47 | 2010-03-31 19:49:26 -0400 | [diff] [blame] | 1610 | iter->ent = __find_next_entry(iter, &iter->cpu, |
| 1611 | &iter->lost_events, &iter->ts); |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1612 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1613 | if (iter->ent) |
Robert Richter | e2ac8ef | 2008-11-12 12:59:32 +0100 | [diff] [blame] | 1614 | trace_iterator_increment(iter); |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1615 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1616 | return iter->ent ? iter : NULL; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1617 | } |
| 1618 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1619 | static void trace_consume(struct trace_iterator *iter) |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1620 | { |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 1621 | /* Don't allow ftrace to trace into the ring buffers */ |
| 1622 | ftrace_disable_cpu(); |
Steven Rostedt | bc21b47 | 2010-03-31 19:49:26 -0400 | [diff] [blame] | 1623 | ring_buffer_consume(iter->tr->buffer, iter->cpu, &iter->ts, |
| 1624 | &iter->lost_events); |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 1625 | ftrace_enable_cpu(); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1626 | } |
| 1627 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1628 | 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] | 1629 | { |
| 1630 | struct trace_iterator *iter = m->private; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1631 | int i = (int)*pos; |
Ingo Molnar | 4e3c333 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 1632 | void *ent; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1633 | |
Steven Rostedt | a63ce5b | 2009-12-07 09:11:39 -0500 | [diff] [blame] | 1634 | WARN_ON_ONCE(iter->leftover); |
| 1635 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1636 | (*pos)++; |
| 1637 | |
| 1638 | /* can't go backwards */ |
| 1639 | if (iter->idx > i) |
| 1640 | return NULL; |
| 1641 | |
| 1642 | if (iter->idx < 0) |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 1643 | ent = trace_find_next_entry_inc(iter); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1644 | else |
| 1645 | ent = iter; |
| 1646 | |
| 1647 | while (ent && iter->idx < i) |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 1648 | ent = trace_find_next_entry_inc(iter); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1649 | |
| 1650 | iter->pos = *pos; |
| 1651 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1652 | return ent; |
| 1653 | } |
| 1654 | |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 1655 | void tracing_iter_reset(struct trace_iterator *iter, int cpu) |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 1656 | { |
| 1657 | struct trace_array *tr = iter->tr; |
| 1658 | struct ring_buffer_event *event; |
| 1659 | struct ring_buffer_iter *buf_iter; |
| 1660 | unsigned long entries = 0; |
| 1661 | u64 ts; |
| 1662 | |
| 1663 | tr->data[cpu]->skipped_entries = 0; |
| 1664 | |
| 1665 | if (!iter->buffer_iter[cpu]) |
| 1666 | return; |
| 1667 | |
| 1668 | buf_iter = iter->buffer_iter[cpu]; |
| 1669 | ring_buffer_iter_reset(buf_iter); |
| 1670 | |
| 1671 | /* |
| 1672 | * We could have the case with the max latency tracers |
| 1673 | * that a reset never took place on a cpu. This is evident |
| 1674 | * by the timestamp being before the start of the buffer. |
| 1675 | */ |
| 1676 | while ((event = ring_buffer_iter_peek(buf_iter, &ts))) { |
| 1677 | if (ts >= iter->tr->time_start) |
| 1678 | break; |
| 1679 | entries++; |
| 1680 | ring_buffer_read(buf_iter, NULL); |
| 1681 | } |
| 1682 | |
| 1683 | tr->data[cpu]->skipped_entries = entries; |
| 1684 | } |
| 1685 | |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 1686 | /* |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 1687 | * The current tracer is copied to avoid a global locking |
| 1688 | * all around. |
| 1689 | */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1690 | static void *s_start(struct seq_file *m, loff_t *pos) |
| 1691 | { |
| 1692 | struct trace_iterator *iter = m->private; |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 1693 | static struct tracer *old_tracer; |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 1694 | int cpu_file = iter->cpu_file; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1695 | void *p = NULL; |
| 1696 | loff_t l = 0; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1697 | int cpu; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1698 | |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 1699 | /* copy the tracer to avoid using a global lock all around */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1700 | mutex_lock(&trace_types_lock); |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 1701 | if (unlikely(old_tracer != current_trace && current_trace)) { |
| 1702 | old_tracer = current_trace; |
| 1703 | *iter->trace = *current_trace; |
Steven Rostedt | d15f57f | 2008-05-12 21:20:56 +0200 | [diff] [blame] | 1704 | } |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 1705 | mutex_unlock(&trace_types_lock); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1706 | |
| 1707 | atomic_inc(&trace_record_cmdline_disabled); |
| 1708 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1709 | if (*pos != iter->pos) { |
| 1710 | iter->ent = NULL; |
| 1711 | iter->cpu = 0; |
| 1712 | iter->idx = -1; |
| 1713 | |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 1714 | ftrace_disable_cpu(); |
| 1715 | |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 1716 | if (cpu_file == TRACE_PIPE_ALL_CPU) { |
| 1717 | for_each_tracing_cpu(cpu) |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 1718 | tracing_iter_reset(iter, cpu); |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 1719 | } else |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 1720 | tracing_iter_reset(iter, cpu_file); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1721 | |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 1722 | ftrace_enable_cpu(); |
| 1723 | |
Lai Jiangshan | ac91d85 | 2010-03-02 17:54:50 +0800 | [diff] [blame] | 1724 | iter->leftover = 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1725 | for (p = iter; p && l < *pos; p = s_next(m, p, &l)) |
| 1726 | ; |
| 1727 | |
| 1728 | } else { |
Steven Rostedt | a63ce5b | 2009-12-07 09:11:39 -0500 | [diff] [blame] | 1729 | /* |
| 1730 | * If we overflowed the seq_file before, then we want |
| 1731 | * to just reuse the trace_seq buffer again. |
| 1732 | */ |
| 1733 | if (iter->leftover) |
| 1734 | p = iter; |
| 1735 | else { |
| 1736 | l = *pos - 1; |
| 1737 | p = s_next(m, p, &l); |
| 1738 | } |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1739 | } |
| 1740 | |
Lai Jiangshan | 4f53596 | 2009-05-18 19:35:34 +0800 | [diff] [blame] | 1741 | trace_event_read_lock(); |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 1742 | trace_access_lock(cpu_file); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1743 | return p; |
| 1744 | } |
| 1745 | |
| 1746 | static void s_stop(struct seq_file *m, void *p) |
| 1747 | { |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 1748 | struct trace_iterator *iter = m->private; |
| 1749 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1750 | atomic_dec(&trace_record_cmdline_disabled); |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 1751 | trace_access_unlock(iter->cpu_file); |
Lai Jiangshan | 4f53596 | 2009-05-18 19:35:34 +0800 | [diff] [blame] | 1752 | trace_event_read_unlock(); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1753 | } |
| 1754 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1755 | static void print_lat_help_header(struct seq_file *m) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1756 | { |
Michael Ellerman | a616835 | 2008-08-20 16:36:11 -0700 | [diff] [blame] | 1757 | seq_puts(m, "# _------=> CPU# \n"); |
| 1758 | seq_puts(m, "# / _-----=> irqs-off \n"); |
| 1759 | seq_puts(m, "# | / _----=> need-resched \n"); |
| 1760 | seq_puts(m, "# || / _---=> hardirq/softirq \n"); |
| 1761 | seq_puts(m, "# ||| / _--=> preempt-depth \n"); |
Steven Rostedt | e6e1e25 | 2011-03-09 10:41:56 -0500 | [diff] [blame] | 1762 | seq_puts(m, "# |||| / delay \n"); |
| 1763 | seq_puts(m, "# cmd pid ||||| time | caller \n"); |
| 1764 | seq_puts(m, "# \\ / ||||| \\ | / \n"); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1765 | } |
| 1766 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1767 | static void print_func_help_header(struct seq_file *m) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1768 | { |
Michael Ellerman | a616835 | 2008-08-20 16:36:11 -0700 | [diff] [blame] | 1769 | seq_puts(m, "# TASK-PID CPU# TIMESTAMP FUNCTION\n"); |
| 1770 | seq_puts(m, "# | | | | |\n"); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1771 | } |
| 1772 | |
| 1773 | |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 1774 | void |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1775 | print_trace_header(struct seq_file *m, struct trace_iterator *iter) |
| 1776 | { |
| 1777 | unsigned long sym_flags = (trace_flags & TRACE_ITER_SYM_MASK); |
| 1778 | struct trace_array *tr = iter->tr; |
| 1779 | struct trace_array_cpu *data = tr->data[tr->cpu]; |
| 1780 | struct tracer *type = current_trace; |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 1781 | unsigned long entries = 0; |
| 1782 | unsigned long total = 0; |
| 1783 | unsigned long count; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1784 | const char *name = "preemption"; |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 1785 | int cpu; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1786 | |
| 1787 | if (type) |
| 1788 | name = type->name; |
| 1789 | |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 1790 | |
| 1791 | for_each_tracing_cpu(cpu) { |
| 1792 | count = ring_buffer_entries_cpu(tr->buffer, cpu); |
| 1793 | /* |
| 1794 | * If this buffer has skipped entries, then we hold all |
| 1795 | * entries for the trace and we need to ignore the |
| 1796 | * ones before the time stamp. |
| 1797 | */ |
| 1798 | if (tr->data[cpu]->skipped_entries) { |
| 1799 | count -= tr->data[cpu]->skipped_entries; |
| 1800 | /* total is the same as the entries */ |
| 1801 | total += count; |
| 1802 | } else |
| 1803 | total += count + |
| 1804 | ring_buffer_overrun_cpu(tr->buffer, cpu); |
| 1805 | entries += count; |
| 1806 | } |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1807 | |
KOSAKI Motohiro | 888b55d | 2009-03-08 13:12:43 +0900 | [diff] [blame] | 1808 | seq_printf(m, "# %s latency trace v1.1.5 on %s\n", |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1809 | name, UTS_RELEASE); |
KOSAKI Motohiro | 888b55d | 2009-03-08 13:12:43 +0900 | [diff] [blame] | 1810 | seq_puts(m, "# -----------------------------------" |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1811 | "---------------------------------\n"); |
KOSAKI Motohiro | 888b55d | 2009-03-08 13:12:43 +0900 | [diff] [blame] | 1812 | seq_printf(m, "# latency: %lu us, #%lu/%lu, CPU#%d |" |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1813 | " (M:%s VP:%d, KP:%d, SP:%d HP:%d", |
Steven Rostedt | 57f50be | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 1814 | nsecs_to_usecs(data->saved_latency), |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1815 | entries, |
Steven Rostedt | 4c11d7a | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1816 | total, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1817 | tr->cpu, |
| 1818 | #if defined(CONFIG_PREEMPT_NONE) |
| 1819 | "server", |
| 1820 | #elif defined(CONFIG_PREEMPT_VOLUNTARY) |
| 1821 | "desktop", |
Steven Rostedt | b5c21b4 | 2008-07-10 20:58:12 -0400 | [diff] [blame] | 1822 | #elif defined(CONFIG_PREEMPT) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1823 | "preempt", |
| 1824 | #else |
| 1825 | "unknown", |
| 1826 | #endif |
| 1827 | /* These are reserved for later use */ |
| 1828 | 0, 0, 0, 0); |
| 1829 | #ifdef CONFIG_SMP |
| 1830 | seq_printf(m, " #P:%d)\n", num_online_cpus()); |
| 1831 | #else |
| 1832 | seq_puts(m, ")\n"); |
| 1833 | #endif |
KOSAKI Motohiro | 888b55d | 2009-03-08 13:12:43 +0900 | [diff] [blame] | 1834 | seq_puts(m, "# -----------------\n"); |
| 1835 | seq_printf(m, "# | task: %.16s-%d " |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1836 | "(uid:%d nice:%ld policy:%ld rt_prio:%ld)\n", |
| 1837 | data->comm, data->pid, data->uid, data->nice, |
| 1838 | data->policy, data->rt_priority); |
KOSAKI Motohiro | 888b55d | 2009-03-08 13:12:43 +0900 | [diff] [blame] | 1839 | seq_puts(m, "# -----------------\n"); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1840 | |
| 1841 | if (data->critical_start) { |
KOSAKI Motohiro | 888b55d | 2009-03-08 13:12:43 +0900 | [diff] [blame] | 1842 | seq_puts(m, "# => started at: "); |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1843 | seq_print_ip_sym(&iter->seq, data->critical_start, sym_flags); |
| 1844 | trace_print_seq(m, &iter->seq); |
KOSAKI Motohiro | 888b55d | 2009-03-08 13:12:43 +0900 | [diff] [blame] | 1845 | seq_puts(m, "\n# => ended at: "); |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1846 | seq_print_ip_sym(&iter->seq, data->critical_end, sym_flags); |
| 1847 | trace_print_seq(m, &iter->seq); |
Steven Rostedt | 8248ac0 | 2009-09-02 12:27:41 -0400 | [diff] [blame] | 1848 | seq_puts(m, "\n#\n"); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1849 | } |
| 1850 | |
KOSAKI Motohiro | 888b55d | 2009-03-08 13:12:43 +0900 | [diff] [blame] | 1851 | seq_puts(m, "#\n"); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1852 | } |
| 1853 | |
Steven Rostedt | a309720 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 1854 | static void test_cpu_buff_start(struct trace_iterator *iter) |
| 1855 | { |
| 1856 | struct trace_seq *s = &iter->seq; |
| 1857 | |
Steven Rostedt | 12ef7d4 | 2008-11-12 17:52:38 -0500 | [diff] [blame] | 1858 | if (!(trace_flags & TRACE_ITER_ANNOTATE)) |
| 1859 | return; |
| 1860 | |
| 1861 | if (!(iter->iter_flags & TRACE_FILE_ANNOTATE)) |
| 1862 | return; |
| 1863 | |
Rusty Russell | 4462344 | 2009-01-01 10:12:23 +1030 | [diff] [blame] | 1864 | if (cpumask_test_cpu(iter->cpu, iter->started)) |
Steven Rostedt | a309720 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 1865 | return; |
| 1866 | |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 1867 | if (iter->tr->data[iter->cpu]->skipped_entries) |
| 1868 | return; |
| 1869 | |
Rusty Russell | 4462344 | 2009-01-01 10:12:23 +1030 | [diff] [blame] | 1870 | cpumask_set_cpu(iter->cpu, iter->started); |
Frederic Weisbecker | b0dfa97 | 2009-04-01 22:53:08 +0200 | [diff] [blame] | 1871 | |
| 1872 | /* Don't print started cpu buffer for the first entry of the trace */ |
| 1873 | if (iter->idx > 1) |
| 1874 | trace_seq_printf(s, "##### CPU %u buffer started ####\n", |
| 1875 | iter->cpu); |
Steven Rostedt | a309720 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 1876 | } |
| 1877 | |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 1878 | static enum print_line_t print_trace_fmt(struct trace_iterator *iter) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1879 | { |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1880 | struct trace_seq *s = &iter->seq; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1881 | unsigned long sym_flags = (trace_flags & TRACE_ITER_SYM_MASK); |
Ingo Molnar | 4e3c333 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 1882 | struct trace_entry *entry; |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 1883 | struct trace_event *event; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1884 | |
Ingo Molnar | 4e3c333 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 1885 | entry = iter->ent; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1886 | |
Steven Rostedt | a309720 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 1887 | test_cpu_buff_start(iter); |
| 1888 | |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 1889 | event = ftrace_find_event(entry->type); |
Frederic Weisbecker | c4a8e8b | 2009-02-02 20:29:21 -0200 | [diff] [blame] | 1890 | |
| 1891 | if (trace_flags & TRACE_ITER_CONTEXT_INFO) { |
Steven Rostedt | 27d48be | 2009-03-04 21:57:29 -0500 | [diff] [blame] | 1892 | if (iter->iter_flags & TRACE_FILE_LAT_FMT) { |
| 1893 | if (!trace_print_lat_context(iter)) |
| 1894 | goto partial; |
| 1895 | } else { |
| 1896 | if (!trace_print_context(iter)) |
| 1897 | goto partial; |
| 1898 | } |
Frederic Weisbecker | c4a8e8b | 2009-02-02 20:29:21 -0200 | [diff] [blame] | 1899 | } |
| 1900 | |
Arnaldo Carvalho de Melo | 268ccda | 2009-02-04 20:16:39 -0200 | [diff] [blame] | 1901 | if (event) |
Steven Rostedt | a9a5776 | 2010-04-22 18:46:14 -0400 | [diff] [blame] | 1902 | return event->funcs->trace(iter, sym_flags, event); |
Arnaldo Carvalho de Melo | d9793bd | 2009-02-03 20:20:41 -0200 | [diff] [blame] | 1903 | |
| 1904 | if (!trace_seq_printf(s, "Unknown type %d\n", entry->type)) |
| 1905 | goto partial; |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 1906 | |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 1907 | return TRACE_TYPE_HANDLED; |
Arnaldo Carvalho de Melo | d9793bd | 2009-02-03 20:20:41 -0200 | [diff] [blame] | 1908 | partial: |
| 1909 | return TRACE_TYPE_PARTIAL_LINE; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1910 | } |
| 1911 | |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 1912 | static enum print_line_t print_raw_fmt(struct trace_iterator *iter) |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 1913 | { |
| 1914 | struct trace_seq *s = &iter->seq; |
| 1915 | struct trace_entry *entry; |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 1916 | struct trace_event *event; |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 1917 | |
| 1918 | entry = iter->ent; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1919 | |
Frederic Weisbecker | c4a8e8b | 2009-02-02 20:29:21 -0200 | [diff] [blame] | 1920 | if (trace_flags & TRACE_ITER_CONTEXT_INFO) { |
Arnaldo Carvalho de Melo | d9793bd | 2009-02-03 20:20:41 -0200 | [diff] [blame] | 1921 | if (!trace_seq_printf(s, "%d %d %llu ", |
| 1922 | entry->pid, iter->cpu, iter->ts)) |
| 1923 | goto partial; |
Frederic Weisbecker | c4a8e8b | 2009-02-02 20:29:21 -0200 | [diff] [blame] | 1924 | } |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 1925 | |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 1926 | event = ftrace_find_event(entry->type); |
Arnaldo Carvalho de Melo | 268ccda | 2009-02-04 20:16:39 -0200 | [diff] [blame] | 1927 | if (event) |
Steven Rostedt | a9a5776 | 2010-04-22 18:46:14 -0400 | [diff] [blame] | 1928 | return event->funcs->raw(iter, 0, event); |
Arnaldo Carvalho de Melo | d9793bd | 2009-02-03 20:20:41 -0200 | [diff] [blame] | 1929 | |
| 1930 | if (!trace_seq_printf(s, "%d ?\n", entry->type)) |
| 1931 | goto partial; |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 1932 | |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 1933 | return TRACE_TYPE_HANDLED; |
Arnaldo Carvalho de Melo | d9793bd | 2009-02-03 20:20:41 -0200 | [diff] [blame] | 1934 | partial: |
| 1935 | return TRACE_TYPE_PARTIAL_LINE; |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 1936 | } |
| 1937 | |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 1938 | static enum print_line_t print_hex_fmt(struct trace_iterator *iter) |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 1939 | { |
| 1940 | struct trace_seq *s = &iter->seq; |
| 1941 | unsigned char newline = '\n'; |
| 1942 | struct trace_entry *entry; |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 1943 | struct trace_event *event; |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 1944 | |
| 1945 | entry = iter->ent; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1946 | |
Frederic Weisbecker | c4a8e8b | 2009-02-02 20:29:21 -0200 | [diff] [blame] | 1947 | if (trace_flags & TRACE_ITER_CONTEXT_INFO) { |
| 1948 | SEQ_PUT_HEX_FIELD_RET(s, entry->pid); |
| 1949 | SEQ_PUT_HEX_FIELD_RET(s, iter->cpu); |
| 1950 | SEQ_PUT_HEX_FIELD_RET(s, iter->ts); |
| 1951 | } |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 1952 | |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 1953 | event = ftrace_find_event(entry->type); |
Arnaldo Carvalho de Melo | 268ccda | 2009-02-04 20:16:39 -0200 | [diff] [blame] | 1954 | if (event) { |
Steven Rostedt | a9a5776 | 2010-04-22 18:46:14 -0400 | [diff] [blame] | 1955 | 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] | 1956 | if (ret != TRACE_TYPE_HANDLED) |
| 1957 | return ret; |
| 1958 | } |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 1959 | |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 1960 | SEQ_PUT_FIELD_RET(s, newline); |
| 1961 | |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 1962 | return TRACE_TYPE_HANDLED; |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 1963 | } |
| 1964 | |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 1965 | static enum print_line_t print_bin_fmt(struct trace_iterator *iter) |
Ingo Molnar | cb0f12a | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 1966 | { |
| 1967 | struct trace_seq *s = &iter->seq; |
| 1968 | struct trace_entry *entry; |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 1969 | struct trace_event *event; |
Ingo Molnar | cb0f12a | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 1970 | |
| 1971 | entry = iter->ent; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1972 | |
Frederic Weisbecker | c4a8e8b | 2009-02-02 20:29:21 -0200 | [diff] [blame] | 1973 | if (trace_flags & TRACE_ITER_CONTEXT_INFO) { |
| 1974 | SEQ_PUT_FIELD_RET(s, entry->pid); |
Steven Rostedt | 1830b52 | 2009-02-07 19:38:43 -0500 | [diff] [blame] | 1975 | SEQ_PUT_FIELD_RET(s, iter->cpu); |
Frederic Weisbecker | c4a8e8b | 2009-02-02 20:29:21 -0200 | [diff] [blame] | 1976 | SEQ_PUT_FIELD_RET(s, iter->ts); |
| 1977 | } |
Ingo Molnar | cb0f12a | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 1978 | |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 1979 | event = ftrace_find_event(entry->type); |
Steven Rostedt | a9a5776 | 2010-04-22 18:46:14 -0400 | [diff] [blame] | 1980 | return event ? event->funcs->binary(iter, 0, event) : |
| 1981 | TRACE_TYPE_HANDLED; |
Ingo Molnar | cb0f12a | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 1982 | } |
| 1983 | |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 1984 | int trace_empty(struct trace_iterator *iter) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1985 | { |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1986 | int cpu; |
| 1987 | |
Steven Rostedt | 9aba60f | 2009-03-11 19:52:30 -0400 | [diff] [blame] | 1988 | /* If we are looking at one CPU buffer, only check that one */ |
| 1989 | if (iter->cpu_file != TRACE_PIPE_ALL_CPU) { |
| 1990 | cpu = iter->cpu_file; |
| 1991 | if (iter->buffer_iter[cpu]) { |
| 1992 | if (!ring_buffer_iter_empty(iter->buffer_iter[cpu])) |
| 1993 | return 0; |
| 1994 | } else { |
| 1995 | if (!ring_buffer_empty_cpu(iter->tr->buffer, cpu)) |
| 1996 | return 0; |
| 1997 | } |
| 1998 | return 1; |
| 1999 | } |
| 2000 | |
Steven Rostedt | ab46428 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 2001 | for_each_tracing_cpu(cpu) { |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 2002 | if (iter->buffer_iter[cpu]) { |
| 2003 | if (!ring_buffer_iter_empty(iter->buffer_iter[cpu])) |
| 2004 | return 0; |
| 2005 | } else { |
| 2006 | if (!ring_buffer_empty_cpu(iter->tr->buffer, cpu)) |
| 2007 | return 0; |
| 2008 | } |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2009 | } |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 2010 | |
Frederic Weisbecker | 797d371 | 2008-09-30 18:13:45 +0200 | [diff] [blame] | 2011 | return 1; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2012 | } |
| 2013 | |
Lai Jiangshan | 4f53596 | 2009-05-18 19:35:34 +0800 | [diff] [blame] | 2014 | /* Called with trace_event_read_lock() held. */ |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 2015 | enum print_line_t print_trace_line(struct trace_iterator *iter) |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2016 | { |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 2017 | enum print_line_t ret; |
| 2018 | |
Jiri Olsa | ee5e51f | 2011-03-25 12:05:18 +0100 | [diff] [blame] | 2019 | if (iter->lost_events && |
| 2020 | !trace_seq_printf(&iter->seq, "CPU:%d [LOST %lu EVENTS]\n", |
| 2021 | iter->cpu, iter->lost_events)) |
| 2022 | return TRACE_TYPE_PARTIAL_LINE; |
Steven Rostedt | bc21b47 | 2010-03-31 19:49:26 -0400 | [diff] [blame] | 2023 | |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 2024 | if (iter->trace && iter->trace->print_line) { |
| 2025 | ret = iter->trace->print_line(iter); |
| 2026 | if (ret != TRACE_TYPE_UNHANDLED) |
| 2027 | return ret; |
| 2028 | } |
Thomas Gleixner | 72829bc | 2008-05-23 21:37:28 +0200 | [diff] [blame] | 2029 | |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 2030 | if (iter->ent->type == TRACE_BPRINT && |
| 2031 | trace_flags & TRACE_ITER_PRINTK && |
| 2032 | trace_flags & TRACE_ITER_PRINTK_MSGONLY) |
Steven Rostedt | 5ef841f | 2009-03-19 12:20:38 -0400 | [diff] [blame] | 2033 | return trace_print_bprintk_msg_only(iter); |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 2034 | |
Frederic Weisbecker | 66896a8 | 2008-12-13 20:18:13 +0100 | [diff] [blame] | 2035 | if (iter->ent->type == TRACE_PRINT && |
| 2036 | trace_flags & TRACE_ITER_PRINTK && |
| 2037 | trace_flags & TRACE_ITER_PRINTK_MSGONLY) |
Steven Rostedt | 5ef841f | 2009-03-19 12:20:38 -0400 | [diff] [blame] | 2038 | return trace_print_printk_msg_only(iter); |
Frederic Weisbecker | 66896a8 | 2008-12-13 20:18:13 +0100 | [diff] [blame] | 2039 | |
Ingo Molnar | cb0f12a | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2040 | if (trace_flags & TRACE_ITER_BIN) |
| 2041 | return print_bin_fmt(iter); |
| 2042 | |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 2043 | if (trace_flags & TRACE_ITER_HEX) |
| 2044 | return print_hex_fmt(iter); |
| 2045 | |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2046 | if (trace_flags & TRACE_ITER_RAW) |
| 2047 | return print_raw_fmt(iter); |
| 2048 | |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2049 | return print_trace_fmt(iter); |
| 2050 | } |
| 2051 | |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 2052 | void trace_default_header(struct seq_file *m) |
| 2053 | { |
| 2054 | struct trace_iterator *iter = m->private; |
| 2055 | |
| 2056 | if (iter->iter_flags & TRACE_FILE_LAT_FMT) { |
| 2057 | /* print nothing if the buffers are empty */ |
| 2058 | if (trace_empty(iter)) |
| 2059 | return; |
| 2060 | print_trace_header(m, iter); |
| 2061 | if (!(trace_flags & TRACE_ITER_VERBOSE)) |
| 2062 | print_lat_help_header(m); |
| 2063 | } else { |
| 2064 | if (!(trace_flags & TRACE_ITER_VERBOSE)) |
| 2065 | print_func_help_header(m); |
| 2066 | } |
| 2067 | } |
| 2068 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2069 | static int s_show(struct seq_file *m, void *v) |
| 2070 | { |
| 2071 | struct trace_iterator *iter = v; |
Steven Rostedt | a63ce5b | 2009-12-07 09:11:39 -0500 | [diff] [blame] | 2072 | int ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2073 | |
| 2074 | if (iter->ent == NULL) { |
| 2075 | if (iter->tr) { |
| 2076 | seq_printf(m, "# tracer: %s\n", iter->trace->name); |
| 2077 | seq_puts(m, "#\n"); |
| 2078 | } |
Markus Metzger | 8bba1bf | 2008-11-25 09:12:31 +0100 | [diff] [blame] | 2079 | if (iter->trace && iter->trace->print_header) |
| 2080 | iter->trace->print_header(m); |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 2081 | else |
| 2082 | trace_default_header(m); |
| 2083 | |
Steven Rostedt | a63ce5b | 2009-12-07 09:11:39 -0500 | [diff] [blame] | 2084 | } else if (iter->leftover) { |
| 2085 | /* |
| 2086 | * If we filled the seq_file buffer earlier, we |
| 2087 | * want to just show it now. |
| 2088 | */ |
| 2089 | ret = trace_print_seq(m, &iter->seq); |
| 2090 | |
| 2091 | /* ret should this time be zero, but you never know */ |
| 2092 | iter->leftover = ret; |
| 2093 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2094 | } else { |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2095 | print_trace_line(iter); |
Steven Rostedt | a63ce5b | 2009-12-07 09:11:39 -0500 | [diff] [blame] | 2096 | ret = trace_print_seq(m, &iter->seq); |
| 2097 | /* |
| 2098 | * If we overflow the seq_file buffer, then it will |
| 2099 | * ask us for this data again at start up. |
| 2100 | * Use that instead. |
| 2101 | * ret is 0 if seq_file write succeeded. |
| 2102 | * -1 otherwise. |
| 2103 | */ |
| 2104 | iter->leftover = ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2105 | } |
| 2106 | |
| 2107 | return 0; |
| 2108 | } |
| 2109 | |
James Morris | 88e9d34 | 2009-09-22 16:43:43 -0700 | [diff] [blame] | 2110 | static const struct seq_operations tracer_seq_ops = { |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2111 | .start = s_start, |
| 2112 | .next = s_next, |
| 2113 | .stop = s_stop, |
| 2114 | .show = s_show, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2115 | }; |
| 2116 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 2117 | static struct trace_iterator * |
Steven Rostedt | 85a2f9b | 2009-02-27 00:12:38 -0500 | [diff] [blame] | 2118 | __tracing_open(struct inode *inode, struct file *file) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2119 | { |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 2120 | long cpu_file = (long) inode->i_private; |
Steven Rostedt | 85a2f9b | 2009-02-27 00:12:38 -0500 | [diff] [blame] | 2121 | void *fail_ret = ERR_PTR(-ENOMEM); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2122 | struct trace_iterator *iter; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2123 | struct seq_file *m; |
Steven Rostedt | 85a2f9b | 2009-02-27 00:12:38 -0500 | [diff] [blame] | 2124 | int cpu, ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2125 | |
Steven Rostedt | 85a2f9b | 2009-02-27 00:12:38 -0500 | [diff] [blame] | 2126 | if (tracing_disabled) |
| 2127 | return ERR_PTR(-ENODEV); |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 2128 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2129 | iter = kzalloc(sizeof(*iter), GFP_KERNEL); |
Steven Rostedt | 85a2f9b | 2009-02-27 00:12:38 -0500 | [diff] [blame] | 2130 | if (!iter) |
| 2131 | return ERR_PTR(-ENOMEM); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2132 | |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 2133 | /* |
| 2134 | * We make a copy of the current tracer to avoid concurrent |
| 2135 | * changes on it while we are reading. |
| 2136 | */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2137 | mutex_lock(&trace_types_lock); |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 2138 | iter->trace = kzalloc(sizeof(*iter->trace), GFP_KERNEL); |
Steven Rostedt | 85a2f9b | 2009-02-27 00:12:38 -0500 | [diff] [blame] | 2139 | if (!iter->trace) |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 2140 | goto fail; |
Steven Rostedt | 85a2f9b | 2009-02-27 00:12:38 -0500 | [diff] [blame] | 2141 | |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 2142 | if (current_trace) |
| 2143 | *iter->trace = *current_trace; |
| 2144 | |
Li Zefan | 79f5599 | 2009-06-15 14:58:26 +0800 | [diff] [blame] | 2145 | if (!zalloc_cpumask_var(&iter->started, GFP_KERNEL)) |
Frederic Weisbecker | b0dfa97 | 2009-04-01 22:53:08 +0200 | [diff] [blame] | 2146 | goto fail; |
| 2147 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2148 | if (current_trace && current_trace->print_max) |
| 2149 | iter->tr = &max_tr; |
| 2150 | else |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 2151 | iter->tr = &global_trace; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2152 | iter->pos = -1; |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 2153 | mutex_init(&iter->mutex); |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 2154 | iter->cpu_file = cpu_file; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2155 | |
Markus Metzger | 8bba1bf | 2008-11-25 09:12:31 +0100 | [diff] [blame] | 2156 | /* Notify the tracer early; before we stop tracing. */ |
| 2157 | if (iter->trace && iter->trace->open) |
Markus Metzger | a93751c | 2008-12-11 13:53:26 +0100 | [diff] [blame] | 2158 | iter->trace->open(iter); |
Markus Metzger | 8bba1bf | 2008-11-25 09:12:31 +0100 | [diff] [blame] | 2159 | |
Steven Rostedt | 12ef7d4 | 2008-11-12 17:52:38 -0500 | [diff] [blame] | 2160 | /* Annotate start of buffers if we had overruns */ |
| 2161 | if (ring_buffer_overruns(iter->tr->buffer)) |
| 2162 | iter->iter_flags |= TRACE_FILE_ANNOTATE; |
| 2163 | |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 2164 | /* stop the trace while dumping */ |
| 2165 | tracing_stop(); |
| 2166 | |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 2167 | if (iter->cpu_file == TRACE_PIPE_ALL_CPU) { |
| 2168 | for_each_tracing_cpu(cpu) { |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 2169 | iter->buffer_iter[cpu] = |
David Miller | 72c9ddf | 2010-04-20 15:47:11 -0700 | [diff] [blame] | 2170 | ring_buffer_read_prepare(iter->tr->buffer, cpu); |
| 2171 | } |
| 2172 | ring_buffer_read_prepare_sync(); |
| 2173 | for_each_tracing_cpu(cpu) { |
| 2174 | ring_buffer_read_start(iter->buffer_iter[cpu]); |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 2175 | tracing_iter_reset(iter, cpu); |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 2176 | } |
| 2177 | } else { |
| 2178 | cpu = iter->cpu_file; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2179 | iter->buffer_iter[cpu] = |
David Miller | 72c9ddf | 2010-04-20 15:47:11 -0700 | [diff] [blame] | 2180 | ring_buffer_read_prepare(iter->tr->buffer, cpu); |
| 2181 | ring_buffer_read_prepare_sync(); |
| 2182 | ring_buffer_read_start(iter->buffer_iter[cpu]); |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 2183 | tracing_iter_reset(iter, cpu); |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2184 | } |
| 2185 | |
Steven Rostedt | 85a2f9b | 2009-02-27 00:12:38 -0500 | [diff] [blame] | 2186 | ret = seq_open(file, &tracer_seq_ops); |
| 2187 | if (ret < 0) { |
| 2188 | fail_ret = ERR_PTR(ret); |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2189 | goto fail_buffer; |
Steven Rostedt | 85a2f9b | 2009-02-27 00:12:38 -0500 | [diff] [blame] | 2190 | } |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2191 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2192 | m = file->private_data; |
| 2193 | m->private = iter; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2194 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2195 | mutex_unlock(&trace_types_lock); |
| 2196 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2197 | return iter; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2198 | |
| 2199 | fail_buffer: |
| 2200 | for_each_tracing_cpu(cpu) { |
| 2201 | if (iter->buffer_iter[cpu]) |
| 2202 | ring_buffer_read_finish(iter->buffer_iter[cpu]); |
| 2203 | } |
Frederic Weisbecker | b0dfa97 | 2009-04-01 22:53:08 +0200 | [diff] [blame] | 2204 | free_cpumask_var(iter->started); |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 2205 | tracing_start(); |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 2206 | fail: |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2207 | mutex_unlock(&trace_types_lock); |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 2208 | kfree(iter->trace); |
Julia Lawall | 0bb943c | 2008-11-14 19:05:31 +0100 | [diff] [blame] | 2209 | kfree(iter); |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2210 | |
Steven Rostedt | 85a2f9b | 2009-02-27 00:12:38 -0500 | [diff] [blame] | 2211 | return fail_ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2212 | } |
| 2213 | |
| 2214 | int tracing_open_generic(struct inode *inode, struct file *filp) |
| 2215 | { |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 2216 | if (tracing_disabled) |
| 2217 | return -ENODEV; |
| 2218 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2219 | filp->private_data = inode->i_private; |
| 2220 | return 0; |
| 2221 | } |
| 2222 | |
Hannes Eder | 4fd2735 | 2009-02-10 19:44:12 +0100 | [diff] [blame] | 2223 | static int tracing_release(struct inode *inode, struct file *file) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2224 | { |
matt mooney | 907f278 | 2010-09-27 19:04:53 -0700 | [diff] [blame] | 2225 | struct seq_file *m = file->private_data; |
Steven Rostedt | 4acd4d0 | 2009-03-18 10:40:24 -0400 | [diff] [blame] | 2226 | struct trace_iterator *iter; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2227 | int cpu; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2228 | |
Steven Rostedt | 4acd4d0 | 2009-03-18 10:40:24 -0400 | [diff] [blame] | 2229 | if (!(file->f_mode & FMODE_READ)) |
| 2230 | return 0; |
| 2231 | |
| 2232 | iter = m->private; |
| 2233 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2234 | mutex_lock(&trace_types_lock); |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2235 | for_each_tracing_cpu(cpu) { |
| 2236 | if (iter->buffer_iter[cpu]) |
| 2237 | ring_buffer_read_finish(iter->buffer_iter[cpu]); |
| 2238 | } |
| 2239 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2240 | if (iter->trace && iter->trace->close) |
| 2241 | iter->trace->close(iter); |
| 2242 | |
| 2243 | /* reenable tracing if it was previously enabled */ |
Steven Rostedt | 9036990 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 2244 | tracing_start(); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2245 | mutex_unlock(&trace_types_lock); |
| 2246 | |
| 2247 | seq_release(inode, file); |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 2248 | mutex_destroy(&iter->mutex); |
Frederic Weisbecker | b0dfa97 | 2009-04-01 22:53:08 +0200 | [diff] [blame] | 2249 | free_cpumask_var(iter->started); |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 2250 | kfree(iter->trace); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2251 | kfree(iter); |
| 2252 | return 0; |
| 2253 | } |
| 2254 | |
| 2255 | static int tracing_open(struct inode *inode, struct file *file) |
| 2256 | { |
Steven Rostedt | 85a2f9b | 2009-02-27 00:12:38 -0500 | [diff] [blame] | 2257 | struct trace_iterator *iter; |
| 2258 | int ret = 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2259 | |
Steven Rostedt | 4acd4d0 | 2009-03-18 10:40:24 -0400 | [diff] [blame] | 2260 | /* If this file was open for write, then erase contents */ |
| 2261 | if ((file->f_mode & FMODE_WRITE) && |
Steven Rostedt | 8650ae3 | 2009-07-22 23:29:30 -0400 | [diff] [blame] | 2262 | (file->f_flags & O_TRUNC)) { |
Steven Rostedt | 4acd4d0 | 2009-03-18 10:40:24 -0400 | [diff] [blame] | 2263 | long cpu = (long) inode->i_private; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2264 | |
Steven Rostedt | 4acd4d0 | 2009-03-18 10:40:24 -0400 | [diff] [blame] | 2265 | if (cpu == TRACE_PIPE_ALL_CPU) |
| 2266 | tracing_reset_online_cpus(&global_trace); |
| 2267 | else |
| 2268 | tracing_reset(&global_trace, cpu); |
| 2269 | } |
| 2270 | |
| 2271 | if (file->f_mode & FMODE_READ) { |
| 2272 | iter = __tracing_open(inode, file); |
| 2273 | if (IS_ERR(iter)) |
| 2274 | ret = PTR_ERR(iter); |
| 2275 | else if (trace_flags & TRACE_ITER_LATENCY_FMT) |
| 2276 | iter->iter_flags |= TRACE_FILE_LAT_FMT; |
| 2277 | } |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2278 | return ret; |
| 2279 | } |
| 2280 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 2281 | static void * |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2282 | t_next(struct seq_file *m, void *v, loff_t *pos) |
| 2283 | { |
Li Zefan | f129e96 | 2009-06-24 09:53:44 +0800 | [diff] [blame] | 2284 | struct tracer *t = v; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2285 | |
| 2286 | (*pos)++; |
| 2287 | |
| 2288 | if (t) |
| 2289 | t = t->next; |
| 2290 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2291 | return t; |
| 2292 | } |
| 2293 | |
| 2294 | static void *t_start(struct seq_file *m, loff_t *pos) |
| 2295 | { |
Li Zefan | f129e96 | 2009-06-24 09:53:44 +0800 | [diff] [blame] | 2296 | struct tracer *t; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2297 | loff_t l = 0; |
| 2298 | |
| 2299 | mutex_lock(&trace_types_lock); |
Li Zefan | f129e96 | 2009-06-24 09:53:44 +0800 | [diff] [blame] | 2300 | 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] | 2301 | ; |
| 2302 | |
| 2303 | return t; |
| 2304 | } |
| 2305 | |
| 2306 | static void t_stop(struct seq_file *m, void *p) |
| 2307 | { |
| 2308 | mutex_unlock(&trace_types_lock); |
| 2309 | } |
| 2310 | |
| 2311 | static int t_show(struct seq_file *m, void *v) |
| 2312 | { |
| 2313 | struct tracer *t = v; |
| 2314 | |
| 2315 | if (!t) |
| 2316 | return 0; |
| 2317 | |
| 2318 | seq_printf(m, "%s", t->name); |
| 2319 | if (t->next) |
| 2320 | seq_putc(m, ' '); |
| 2321 | else |
| 2322 | seq_putc(m, '\n'); |
| 2323 | |
| 2324 | return 0; |
| 2325 | } |
| 2326 | |
James Morris | 88e9d34 | 2009-09-22 16:43:43 -0700 | [diff] [blame] | 2327 | static const struct seq_operations show_traces_seq_ops = { |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2328 | .start = t_start, |
| 2329 | .next = t_next, |
| 2330 | .stop = t_stop, |
| 2331 | .show = t_show, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2332 | }; |
| 2333 | |
| 2334 | static int show_traces_open(struct inode *inode, struct file *file) |
| 2335 | { |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 2336 | if (tracing_disabled) |
| 2337 | return -ENODEV; |
| 2338 | |
Li Zefan | f129e96 | 2009-06-24 09:53:44 +0800 | [diff] [blame] | 2339 | return seq_open(file, &show_traces_seq_ops); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2340 | } |
| 2341 | |
Steven Rostedt | 4acd4d0 | 2009-03-18 10:40:24 -0400 | [diff] [blame] | 2342 | static ssize_t |
| 2343 | tracing_write_stub(struct file *filp, const char __user *ubuf, |
| 2344 | size_t count, loff_t *ppos) |
| 2345 | { |
| 2346 | return count; |
| 2347 | } |
| 2348 | |
Slava Pestov | 364829b | 2010-11-24 15:13:16 -0800 | [diff] [blame] | 2349 | static loff_t tracing_seek(struct file *file, loff_t offset, int origin) |
| 2350 | { |
| 2351 | if (file->f_mode & FMODE_READ) |
| 2352 | return seq_lseek(file, offset, origin); |
| 2353 | else |
| 2354 | return 0; |
| 2355 | } |
| 2356 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 2357 | static const struct file_operations tracing_fops = { |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2358 | .open = tracing_open, |
| 2359 | .read = seq_read, |
Steven Rostedt | 4acd4d0 | 2009-03-18 10:40:24 -0400 | [diff] [blame] | 2360 | .write = tracing_write_stub, |
Slava Pestov | 364829b | 2010-11-24 15:13:16 -0800 | [diff] [blame] | 2361 | .llseek = tracing_seek, |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2362 | .release = tracing_release, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2363 | }; |
| 2364 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 2365 | static const struct file_operations show_traces_fops = { |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2366 | .open = show_traces_open, |
| 2367 | .read = seq_read, |
| 2368 | .release = seq_release, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 2369 | .llseek = seq_lseek, |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2370 | }; |
| 2371 | |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2372 | /* |
| 2373 | * Only trace on a CPU if the bitmask is set: |
| 2374 | */ |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 2375 | static cpumask_var_t tracing_cpumask; |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2376 | |
| 2377 | /* |
| 2378 | * The tracer itself will not take this lock, but still we want |
| 2379 | * to provide a consistent cpumask to user-space: |
| 2380 | */ |
| 2381 | static DEFINE_MUTEX(tracing_cpumask_update_lock); |
| 2382 | |
| 2383 | /* |
| 2384 | * Temporary storage for the character representation of the |
| 2385 | * CPU bitmask (and one more byte for the newline): |
| 2386 | */ |
| 2387 | static char mask_str[NR_CPUS + 1]; |
| 2388 | |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2389 | static ssize_t |
| 2390 | tracing_cpumask_read(struct file *filp, char __user *ubuf, |
| 2391 | size_t count, loff_t *ppos) |
| 2392 | { |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2393 | int len; |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2394 | |
| 2395 | mutex_lock(&tracing_cpumask_update_lock); |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2396 | |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 2397 | len = cpumask_scnprintf(mask_str, count, tracing_cpumask); |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2398 | if (count - len < 2) { |
| 2399 | count = -EINVAL; |
| 2400 | goto out_err; |
| 2401 | } |
| 2402 | len += sprintf(mask_str + len, "\n"); |
| 2403 | count = simple_read_from_buffer(ubuf, count, ppos, mask_str, NR_CPUS+1); |
| 2404 | |
| 2405 | out_err: |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2406 | mutex_unlock(&tracing_cpumask_update_lock); |
| 2407 | |
| 2408 | return count; |
| 2409 | } |
| 2410 | |
| 2411 | static ssize_t |
| 2412 | tracing_cpumask_write(struct file *filp, const char __user *ubuf, |
| 2413 | size_t count, loff_t *ppos) |
| 2414 | { |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2415 | int err, cpu; |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 2416 | cpumask_var_t tracing_cpumask_new; |
| 2417 | |
| 2418 | if (!alloc_cpumask_var(&tracing_cpumask_new, GFP_KERNEL)) |
| 2419 | return -ENOMEM; |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2420 | |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 2421 | err = cpumask_parse_user(ubuf, count, tracing_cpumask_new); |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2422 | if (err) |
| 2423 | goto err_unlock; |
| 2424 | |
Li Zefan | 215368e | 2009-06-15 10:56:42 +0800 | [diff] [blame] | 2425 | mutex_lock(&tracing_cpumask_update_lock); |
| 2426 | |
Steven Rostedt | a5e2588 | 2008-12-02 15:34:05 -0500 | [diff] [blame] | 2427 | local_irq_disable(); |
Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 2428 | arch_spin_lock(&ftrace_max_lock); |
Steven Rostedt | ab46428 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 2429 | for_each_tracing_cpu(cpu) { |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2430 | /* |
| 2431 | * Increase/decrease the disabled counter if we are |
| 2432 | * about to flip a bit in the cpumask: |
| 2433 | */ |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 2434 | if (cpumask_test_cpu(cpu, tracing_cpumask) && |
| 2435 | !cpumask_test_cpu(cpu, tracing_cpumask_new)) { |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2436 | atomic_inc(&global_trace.data[cpu]->disabled); |
| 2437 | } |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 2438 | if (!cpumask_test_cpu(cpu, tracing_cpumask) && |
| 2439 | cpumask_test_cpu(cpu, tracing_cpumask_new)) { |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2440 | atomic_dec(&global_trace.data[cpu]->disabled); |
| 2441 | } |
| 2442 | } |
Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 2443 | arch_spin_unlock(&ftrace_max_lock); |
Steven Rostedt | a5e2588 | 2008-12-02 15:34:05 -0500 | [diff] [blame] | 2444 | local_irq_enable(); |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2445 | |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 2446 | cpumask_copy(tracing_cpumask, tracing_cpumask_new); |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2447 | |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2448 | mutex_unlock(&tracing_cpumask_update_lock); |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 2449 | free_cpumask_var(tracing_cpumask_new); |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2450 | |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2451 | return count; |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2452 | |
| 2453 | err_unlock: |
Li Zefan | 215368e | 2009-06-15 10:56:42 +0800 | [diff] [blame] | 2454 | free_cpumask_var(tracing_cpumask_new); |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2455 | |
| 2456 | return err; |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2457 | } |
| 2458 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 2459 | static const struct file_operations tracing_cpumask_fops = { |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2460 | .open = tracing_open_generic, |
| 2461 | .read = tracing_cpumask_read, |
| 2462 | .write = tracing_cpumask_write, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 2463 | .llseek = generic_file_llseek, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2464 | }; |
| 2465 | |
Li Zefan | fdb372e | 2009-12-08 11:15:59 +0800 | [diff] [blame] | 2466 | static int tracing_trace_options_show(struct seq_file *m, void *v) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2467 | { |
Steven Rostedt | d8e83d2 | 2009-02-26 23:55:58 -0500 | [diff] [blame] | 2468 | struct tracer_opt *trace_opts; |
| 2469 | u32 tracer_flags; |
Steven Rostedt | d8e83d2 | 2009-02-26 23:55:58 -0500 | [diff] [blame] | 2470 | int i; |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 2471 | |
Steven Rostedt | d8e83d2 | 2009-02-26 23:55:58 -0500 | [diff] [blame] | 2472 | mutex_lock(&trace_types_lock); |
| 2473 | tracer_flags = current_trace->flags->val; |
| 2474 | trace_opts = current_trace->flags->opts; |
| 2475 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2476 | for (i = 0; trace_options[i]; i++) { |
| 2477 | if (trace_flags & (1 << i)) |
Li Zefan | fdb372e | 2009-12-08 11:15:59 +0800 | [diff] [blame] | 2478 | seq_printf(m, "%s\n", trace_options[i]); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2479 | else |
Li Zefan | fdb372e | 2009-12-08 11:15:59 +0800 | [diff] [blame] | 2480 | seq_printf(m, "no%s\n", trace_options[i]); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2481 | } |
| 2482 | |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 2483 | for (i = 0; trace_opts[i].name; i++) { |
| 2484 | if (tracer_flags & trace_opts[i].bit) |
Li Zefan | fdb372e | 2009-12-08 11:15:59 +0800 | [diff] [blame] | 2485 | seq_printf(m, "%s\n", trace_opts[i].name); |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 2486 | else |
Li Zefan | fdb372e | 2009-12-08 11:15:59 +0800 | [diff] [blame] | 2487 | seq_printf(m, "no%s\n", trace_opts[i].name); |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 2488 | } |
Steven Rostedt | d8e83d2 | 2009-02-26 23:55:58 -0500 | [diff] [blame] | 2489 | mutex_unlock(&trace_types_lock); |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 2490 | |
Li Zefan | fdb372e | 2009-12-08 11:15:59 +0800 | [diff] [blame] | 2491 | return 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2492 | } |
| 2493 | |
Li Zefan | 8d18eaa | 2009-12-08 11:17:06 +0800 | [diff] [blame] | 2494 | static int __set_tracer_option(struct tracer *trace, |
| 2495 | struct tracer_flags *tracer_flags, |
| 2496 | struct tracer_opt *opts, int neg) |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 2497 | { |
Li Zefan | 8d18eaa | 2009-12-08 11:17:06 +0800 | [diff] [blame] | 2498 | int ret; |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 2499 | |
Li Zefan | 8d18eaa | 2009-12-08 11:17:06 +0800 | [diff] [blame] | 2500 | ret = trace->set_flag(tracer_flags->val, opts->bit, !neg); |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 2501 | if (ret) |
| 2502 | return ret; |
| 2503 | |
| 2504 | if (neg) |
Zhaolei | 7770841 | 2009-08-07 18:53:21 +0800 | [diff] [blame] | 2505 | tracer_flags->val &= ~opts->bit; |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 2506 | else |
Zhaolei | 7770841 | 2009-08-07 18:53:21 +0800 | [diff] [blame] | 2507 | tracer_flags->val |= opts->bit; |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 2508 | return 0; |
| 2509 | } |
| 2510 | |
Li Zefan | 8d18eaa | 2009-12-08 11:17:06 +0800 | [diff] [blame] | 2511 | /* Try to assign a tracer specific option */ |
| 2512 | static int set_tracer_option(struct tracer *trace, char *cmp, int neg) |
| 2513 | { |
| 2514 | struct tracer_flags *tracer_flags = trace->flags; |
| 2515 | struct tracer_opt *opts = NULL; |
| 2516 | int i; |
| 2517 | |
| 2518 | for (i = 0; tracer_flags->opts[i].name; i++) { |
| 2519 | opts = &tracer_flags->opts[i]; |
| 2520 | |
| 2521 | if (strcmp(cmp, opts->name) == 0) |
| 2522 | return __set_tracer_option(trace, trace->flags, |
| 2523 | opts, neg); |
| 2524 | } |
| 2525 | |
| 2526 | return -EINVAL; |
| 2527 | } |
| 2528 | |
Steven Rostedt | af4617b | 2009-03-17 18:09:55 -0400 | [diff] [blame] | 2529 | static void set_tracer_flags(unsigned int mask, int enabled) |
| 2530 | { |
| 2531 | /* do nothing if flag is already set */ |
| 2532 | if (!!(trace_flags & mask) == !!enabled) |
| 2533 | return; |
| 2534 | |
| 2535 | if (enabled) |
| 2536 | trace_flags |= mask; |
| 2537 | else |
| 2538 | trace_flags &= ~mask; |
Li Zefan | e870e9a | 2010-07-02 11:07:32 +0800 | [diff] [blame] | 2539 | |
| 2540 | if (mask == TRACE_ITER_RECORD_CMD) |
| 2541 | trace_event_enable_cmd_record(enabled); |
David Sharp | 750912f | 2010-12-08 13:46:47 -0800 | [diff] [blame] | 2542 | |
| 2543 | if (mask == TRACE_ITER_OVERWRITE) |
| 2544 | ring_buffer_change_overwrite(global_trace.buffer, enabled); |
Steven Rostedt | af4617b | 2009-03-17 18:09:55 -0400 | [diff] [blame] | 2545 | } |
| 2546 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2547 | static ssize_t |
Steven Rostedt | ee6bce5 | 2008-11-12 17:52:37 -0500 | [diff] [blame] | 2548 | tracing_trace_options_write(struct file *filp, const char __user *ubuf, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2549 | size_t cnt, loff_t *ppos) |
| 2550 | { |
| 2551 | char buf[64]; |
Li Zefan | 8d18eaa | 2009-12-08 11:17:06 +0800 | [diff] [blame] | 2552 | char *cmp; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2553 | int neg = 0; |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 2554 | int ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2555 | int i; |
| 2556 | |
Steven Rostedt | cffae43 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 2557 | if (cnt >= sizeof(buf)) |
| 2558 | return -EINVAL; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2559 | |
| 2560 | if (copy_from_user(&buf, ubuf, cnt)) |
| 2561 | return -EFAULT; |
| 2562 | |
| 2563 | buf[cnt] = 0; |
Li Zefan | 8d18eaa | 2009-12-08 11:17:06 +0800 | [diff] [blame] | 2564 | cmp = strstrip(buf); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2565 | |
Li Zefan | 8d18eaa | 2009-12-08 11:17:06 +0800 | [diff] [blame] | 2566 | if (strncmp(cmp, "no", 2) == 0) { |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2567 | neg = 1; |
| 2568 | cmp += 2; |
| 2569 | } |
| 2570 | |
| 2571 | for (i = 0; trace_options[i]; i++) { |
Li Zefan | 8d18eaa | 2009-12-08 11:17:06 +0800 | [diff] [blame] | 2572 | if (strcmp(cmp, trace_options[i]) == 0) { |
Steven Rostedt | af4617b | 2009-03-17 18:09:55 -0400 | [diff] [blame] | 2573 | set_tracer_flags(1 << i, !neg); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2574 | break; |
| 2575 | } |
| 2576 | } |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 2577 | |
| 2578 | /* If no option could be set, test the specific tracer options */ |
| 2579 | if (!trace_options[i]) { |
Steven Rostedt | d8e83d2 | 2009-02-26 23:55:58 -0500 | [diff] [blame] | 2580 | mutex_lock(&trace_types_lock); |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 2581 | ret = set_tracer_option(current_trace, cmp, neg); |
Steven Rostedt | d8e83d2 | 2009-02-26 23:55:58 -0500 | [diff] [blame] | 2582 | mutex_unlock(&trace_types_lock); |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 2583 | if (ret) |
| 2584 | return ret; |
| 2585 | } |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2586 | |
Jiri Olsa | cf8517c | 2009-10-23 19:36:16 -0400 | [diff] [blame] | 2587 | *ppos += cnt; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2588 | |
| 2589 | return cnt; |
| 2590 | } |
| 2591 | |
Li Zefan | fdb372e | 2009-12-08 11:15:59 +0800 | [diff] [blame] | 2592 | static int tracing_trace_options_open(struct inode *inode, struct file *file) |
| 2593 | { |
| 2594 | if (tracing_disabled) |
| 2595 | return -ENODEV; |
| 2596 | return single_open(file, tracing_trace_options_show, NULL); |
| 2597 | } |
| 2598 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 2599 | static const struct file_operations tracing_iter_fops = { |
Li Zefan | fdb372e | 2009-12-08 11:15:59 +0800 | [diff] [blame] | 2600 | .open = tracing_trace_options_open, |
| 2601 | .read = seq_read, |
| 2602 | .llseek = seq_lseek, |
| 2603 | .release = single_release, |
Steven Rostedt | ee6bce5 | 2008-11-12 17:52:37 -0500 | [diff] [blame] | 2604 | .write = tracing_trace_options_write, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2605 | }; |
| 2606 | |
Ingo Molnar | 7bd2f24 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 2607 | static const char readme_msg[] = |
| 2608 | "tracing mini-HOWTO:\n\n" |
GeunSik Lim | 156f5a7 | 2009-06-02 15:01:37 +0900 | [diff] [blame] | 2609 | "# mount -t debugfs nodev /sys/kernel/debug\n\n" |
| 2610 | "# cat /sys/kernel/debug/tracing/available_tracers\n" |
Nikanth Karthikesan | bc2b687 | 2009-03-23 11:58:31 +0530 | [diff] [blame] | 2611 | "wakeup preemptirqsoff preemptoff irqsoff function sched_switch nop\n\n" |
GeunSik Lim | 156f5a7 | 2009-06-02 15:01:37 +0900 | [diff] [blame] | 2612 | "# cat /sys/kernel/debug/tracing/current_tracer\n" |
Nikanth Karthikesan | bc2b687 | 2009-03-23 11:58:31 +0530 | [diff] [blame] | 2613 | "nop\n" |
GeunSik Lim | 156f5a7 | 2009-06-02 15:01:37 +0900 | [diff] [blame] | 2614 | "# echo sched_switch > /sys/kernel/debug/tracing/current_tracer\n" |
| 2615 | "# cat /sys/kernel/debug/tracing/current_tracer\n" |
Ingo Molnar | 7bd2f24 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 2616 | "sched_switch\n" |
GeunSik Lim | 156f5a7 | 2009-06-02 15:01:37 +0900 | [diff] [blame] | 2617 | "# cat /sys/kernel/debug/tracing/trace_options\n" |
Ingo Molnar | 7bd2f24 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 2618 | "noprint-parent nosym-offset nosym-addr noverbose\n" |
GeunSik Lim | 156f5a7 | 2009-06-02 15:01:37 +0900 | [diff] [blame] | 2619 | "# echo print-parent > /sys/kernel/debug/tracing/trace_options\n" |
| 2620 | "# echo 1 > /sys/kernel/debug/tracing/tracing_enabled\n" |
| 2621 | "# cat /sys/kernel/debug/tracing/trace > /tmp/trace.txt\n" |
| 2622 | "# echo 0 > /sys/kernel/debug/tracing/tracing_enabled\n" |
Ingo Molnar | 7bd2f24 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 2623 | ; |
| 2624 | |
| 2625 | static ssize_t |
| 2626 | tracing_readme_read(struct file *filp, char __user *ubuf, |
| 2627 | size_t cnt, loff_t *ppos) |
| 2628 | { |
| 2629 | return simple_read_from_buffer(ubuf, cnt, ppos, |
| 2630 | readme_msg, strlen(readme_msg)); |
| 2631 | } |
| 2632 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 2633 | static const struct file_operations tracing_readme_fops = { |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2634 | .open = tracing_open_generic, |
| 2635 | .read = tracing_readme_read, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 2636 | .llseek = generic_file_llseek, |
Ingo Molnar | 7bd2f24 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 2637 | }; |
| 2638 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2639 | static ssize_t |
Avadh Patel | 69abe6a | 2009-04-10 16:04:48 -0400 | [diff] [blame] | 2640 | tracing_saved_cmdlines_read(struct file *file, char __user *ubuf, |
| 2641 | size_t cnt, loff_t *ppos) |
| 2642 | { |
| 2643 | char *buf_comm; |
| 2644 | char *file_buf; |
| 2645 | char *buf; |
| 2646 | int len = 0; |
| 2647 | int pid; |
| 2648 | int i; |
| 2649 | |
| 2650 | file_buf = kmalloc(SAVED_CMDLINES*(16+TASK_COMM_LEN), GFP_KERNEL); |
| 2651 | if (!file_buf) |
| 2652 | return -ENOMEM; |
| 2653 | |
| 2654 | buf_comm = kmalloc(TASK_COMM_LEN, GFP_KERNEL); |
| 2655 | if (!buf_comm) { |
| 2656 | kfree(file_buf); |
| 2657 | return -ENOMEM; |
| 2658 | } |
| 2659 | |
| 2660 | buf = file_buf; |
| 2661 | |
| 2662 | for (i = 0; i < SAVED_CMDLINES; i++) { |
| 2663 | int r; |
| 2664 | |
| 2665 | pid = map_cmdline_to_pid[i]; |
| 2666 | if (pid == -1 || pid == NO_CMDLINE_MAP) |
| 2667 | continue; |
| 2668 | |
| 2669 | trace_find_cmdline(pid, buf_comm); |
| 2670 | r = sprintf(buf, "%d %s\n", pid, buf_comm); |
| 2671 | buf += r; |
| 2672 | len += r; |
| 2673 | } |
| 2674 | |
| 2675 | len = simple_read_from_buffer(ubuf, cnt, ppos, |
| 2676 | file_buf, len); |
| 2677 | |
| 2678 | kfree(file_buf); |
| 2679 | kfree(buf_comm); |
| 2680 | |
| 2681 | return len; |
| 2682 | } |
| 2683 | |
| 2684 | static const struct file_operations tracing_saved_cmdlines_fops = { |
| 2685 | .open = tracing_open_generic, |
| 2686 | .read = tracing_saved_cmdlines_read, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 2687 | .llseek = generic_file_llseek, |
Avadh Patel | 69abe6a | 2009-04-10 16:04:48 -0400 | [diff] [blame] | 2688 | }; |
| 2689 | |
| 2690 | static ssize_t |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2691 | tracing_ctrl_read(struct file *filp, char __user *ubuf, |
| 2692 | size_t cnt, loff_t *ppos) |
| 2693 | { |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2694 | char buf[64]; |
| 2695 | int r; |
| 2696 | |
Steven Rostedt | 9036990 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 2697 | r = sprintf(buf, "%u\n", tracer_enabled); |
Ingo Molnar | 4e3c333 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 2698 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, r); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2699 | } |
| 2700 | |
| 2701 | static ssize_t |
| 2702 | tracing_ctrl_write(struct file *filp, const char __user *ubuf, |
| 2703 | size_t cnt, loff_t *ppos) |
| 2704 | { |
| 2705 | struct trace_array *tr = filp->private_data; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2706 | char buf[64]; |
Hannes Eder | 5e39841 | 2009-02-10 19:44:34 +0100 | [diff] [blame] | 2707 | unsigned long val; |
Steven Rostedt | c6caeeb | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 2708 | int ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2709 | |
Steven Rostedt | cffae43 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 2710 | if (cnt >= sizeof(buf)) |
| 2711 | return -EINVAL; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2712 | |
| 2713 | if (copy_from_user(&buf, ubuf, cnt)) |
| 2714 | return -EFAULT; |
| 2715 | |
| 2716 | buf[cnt] = 0; |
| 2717 | |
Steven Rostedt | c6caeeb | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 2718 | ret = strict_strtoul(buf, 10, &val); |
| 2719 | if (ret < 0) |
| 2720 | return ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2721 | |
| 2722 | val = !!val; |
| 2723 | |
| 2724 | mutex_lock(&trace_types_lock); |
Steven Rostedt | 9036990 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 2725 | if (tracer_enabled ^ val) { |
Steven Rostedt | 6752ab4 | 2011-02-08 13:54:06 -0500 | [diff] [blame] | 2726 | |
| 2727 | /* Only need to warn if this is used to change the state */ |
| 2728 | WARN_ONCE(1, "tracing_enabled is deprecated. Use tracing_on"); |
| 2729 | |
Steven Rostedt | 9036990 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 2730 | if (val) { |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2731 | tracer_enabled = 1; |
Steven Rostedt | 9036990 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 2732 | if (current_trace->start) |
| 2733 | current_trace->start(tr); |
| 2734 | tracing_start(); |
| 2735 | } else { |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2736 | tracer_enabled = 0; |
Steven Rostedt | 9036990 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 2737 | tracing_stop(); |
| 2738 | if (current_trace->stop) |
| 2739 | current_trace->stop(tr); |
| 2740 | } |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2741 | } |
| 2742 | mutex_unlock(&trace_types_lock); |
| 2743 | |
Jiri Olsa | cf8517c | 2009-10-23 19:36:16 -0400 | [diff] [blame] | 2744 | *ppos += cnt; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2745 | |
| 2746 | return cnt; |
| 2747 | } |
| 2748 | |
| 2749 | static ssize_t |
| 2750 | tracing_set_trace_read(struct file *filp, char __user *ubuf, |
| 2751 | size_t cnt, loff_t *ppos) |
| 2752 | { |
Li Zefan | ee6c2c1 | 2009-09-18 14:06:47 +0800 | [diff] [blame] | 2753 | char buf[MAX_TRACER_SIZE+2]; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2754 | int r; |
| 2755 | |
| 2756 | mutex_lock(&trace_types_lock); |
| 2757 | if (current_trace) |
| 2758 | r = sprintf(buf, "%s\n", current_trace->name); |
| 2759 | else |
| 2760 | r = sprintf(buf, "\n"); |
| 2761 | mutex_unlock(&trace_types_lock); |
| 2762 | |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2763 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, r); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2764 | } |
| 2765 | |
Arnaldo Carvalho de Melo | b6f11df | 2009-02-05 18:02:00 -0200 | [diff] [blame] | 2766 | int tracer_init(struct tracer *t, struct trace_array *tr) |
| 2767 | { |
| 2768 | tracing_reset_online_cpus(tr); |
| 2769 | return t->init(tr); |
| 2770 | } |
| 2771 | |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 2772 | static int __tracing_resize_ring_buffer(unsigned long size) |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 2773 | { |
| 2774 | int ret; |
| 2775 | |
| 2776 | /* |
| 2777 | * If kernel or user changes the size of the ring buffer |
Steven Rostedt | a123c52 | 2009-03-12 11:21:08 -0400 | [diff] [blame] | 2778 | * we use the size that was given, and we can forget about |
| 2779 | * expanding it later. |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 2780 | */ |
| 2781 | ring_buffer_expanded = 1; |
| 2782 | |
| 2783 | ret = ring_buffer_resize(global_trace.buffer, size); |
| 2784 | if (ret < 0) |
| 2785 | return ret; |
| 2786 | |
KOSAKI Motohiro | ef710e1 | 2010-07-01 14:34:35 +0900 | [diff] [blame] | 2787 | if (!current_trace->use_max_tr) |
| 2788 | goto out; |
| 2789 | |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 2790 | ret = ring_buffer_resize(max_tr.buffer, size); |
| 2791 | if (ret < 0) { |
| 2792 | int r; |
| 2793 | |
| 2794 | r = ring_buffer_resize(global_trace.buffer, |
| 2795 | global_trace.entries); |
| 2796 | if (r < 0) { |
Steven Rostedt | a123c52 | 2009-03-12 11:21:08 -0400 | [diff] [blame] | 2797 | /* |
| 2798 | * AARGH! We are left with different |
| 2799 | * size max buffer!!!! |
| 2800 | * The max buffer is our "snapshot" buffer. |
| 2801 | * When a tracer needs a snapshot (one of the |
| 2802 | * latency tracers), it swaps the max buffer |
| 2803 | * with the saved snap shot. We succeeded to |
| 2804 | * update the size of the main buffer, but failed to |
| 2805 | * update the size of the max buffer. But when we tried |
| 2806 | * to reset the main buffer to the original size, we |
| 2807 | * failed there too. This is very unlikely to |
| 2808 | * happen, but if it does, warn and kill all |
| 2809 | * tracing. |
| 2810 | */ |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 2811 | WARN_ON(1); |
| 2812 | tracing_disabled = 1; |
| 2813 | } |
| 2814 | return ret; |
| 2815 | } |
| 2816 | |
KOSAKI Motohiro | ef710e1 | 2010-07-01 14:34:35 +0900 | [diff] [blame] | 2817 | max_tr.entries = size; |
| 2818 | out: |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 2819 | global_trace.entries = size; |
| 2820 | |
| 2821 | return ret; |
| 2822 | } |
| 2823 | |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 2824 | static ssize_t tracing_resize_ring_buffer(unsigned long size) |
| 2825 | { |
| 2826 | int cpu, ret = size; |
| 2827 | |
| 2828 | mutex_lock(&trace_types_lock); |
| 2829 | |
| 2830 | tracing_stop(); |
| 2831 | |
| 2832 | /* disable all cpu buffers */ |
| 2833 | for_each_tracing_cpu(cpu) { |
| 2834 | if (global_trace.data[cpu]) |
| 2835 | atomic_inc(&global_trace.data[cpu]->disabled); |
| 2836 | if (max_tr.data[cpu]) |
| 2837 | atomic_inc(&max_tr.data[cpu]->disabled); |
| 2838 | } |
| 2839 | |
| 2840 | if (size != global_trace.entries) |
| 2841 | ret = __tracing_resize_ring_buffer(size); |
| 2842 | |
| 2843 | if (ret < 0) |
| 2844 | ret = -ENOMEM; |
| 2845 | |
| 2846 | for_each_tracing_cpu(cpu) { |
| 2847 | if (global_trace.data[cpu]) |
| 2848 | atomic_dec(&global_trace.data[cpu]->disabled); |
| 2849 | if (max_tr.data[cpu]) |
| 2850 | atomic_dec(&max_tr.data[cpu]->disabled); |
| 2851 | } |
| 2852 | |
| 2853 | tracing_start(); |
| 2854 | mutex_unlock(&trace_types_lock); |
| 2855 | |
| 2856 | return ret; |
| 2857 | } |
| 2858 | |
KOSAKI Motohiro | ef710e1 | 2010-07-01 14:34:35 +0900 | [diff] [blame] | 2859 | |
Steven Rostedt | 1852fcc | 2009-03-11 14:33:00 -0400 | [diff] [blame] | 2860 | /** |
| 2861 | * tracing_update_buffers - used by tracing facility to expand ring buffers |
| 2862 | * |
| 2863 | * To save on memory when the tracing is never used on a system with it |
| 2864 | * configured in. The ring buffers are set to a minimum size. But once |
| 2865 | * a user starts to use the tracing facility, then they need to grow |
| 2866 | * to their default size. |
| 2867 | * |
| 2868 | * This function is to be called when a tracer is about to be used. |
| 2869 | */ |
| 2870 | int tracing_update_buffers(void) |
| 2871 | { |
| 2872 | int ret = 0; |
| 2873 | |
Steven Rostedt | 1027fcb | 2009-03-12 11:33:20 -0400 | [diff] [blame] | 2874 | mutex_lock(&trace_types_lock); |
Steven Rostedt | 1852fcc | 2009-03-11 14:33:00 -0400 | [diff] [blame] | 2875 | if (!ring_buffer_expanded) |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 2876 | ret = __tracing_resize_ring_buffer(trace_buf_size); |
Steven Rostedt | 1027fcb | 2009-03-12 11:33:20 -0400 | [diff] [blame] | 2877 | mutex_unlock(&trace_types_lock); |
Steven Rostedt | 1852fcc | 2009-03-11 14:33:00 -0400 | [diff] [blame] | 2878 | |
| 2879 | return ret; |
| 2880 | } |
| 2881 | |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 2882 | struct trace_option_dentry; |
| 2883 | |
| 2884 | static struct trace_option_dentry * |
| 2885 | create_trace_option_files(struct tracer *tracer); |
| 2886 | |
| 2887 | static void |
| 2888 | destroy_trace_option_files(struct trace_option_dentry *topts); |
| 2889 | |
Steven Rostedt | b2821ae | 2009-02-02 21:38:32 -0500 | [diff] [blame] | 2890 | static int tracing_set_tracer(const char *buf) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2891 | { |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 2892 | static struct trace_option_dentry *topts; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2893 | struct trace_array *tr = &global_trace; |
| 2894 | struct tracer *t; |
Peter Zijlstra | d9e5407 | 2008-11-01 19:57:37 +0100 | [diff] [blame] | 2895 | int ret = 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2896 | |
Steven Rostedt | 1027fcb | 2009-03-12 11:33:20 -0400 | [diff] [blame] | 2897 | mutex_lock(&trace_types_lock); |
| 2898 | |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 2899 | if (!ring_buffer_expanded) { |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 2900 | ret = __tracing_resize_ring_buffer(trace_buf_size); |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 2901 | if (ret < 0) |
Frederic Weisbecker | 59f586d | 2009-03-15 22:10:39 +0100 | [diff] [blame] | 2902 | goto out; |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 2903 | ret = 0; |
| 2904 | } |
| 2905 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2906 | for (t = trace_types; t; t = t->next) { |
| 2907 | if (strcmp(t->name, buf) == 0) |
| 2908 | break; |
| 2909 | } |
Frederic Weisbecker | c2931e0 | 2008-10-04 22:04:44 +0200 | [diff] [blame] | 2910 | if (!t) { |
| 2911 | ret = -EINVAL; |
| 2912 | goto out; |
| 2913 | } |
| 2914 | if (t == current_trace) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2915 | goto out; |
| 2916 | |
Steven Rostedt | 9f029e8 | 2008-11-12 15:24:24 -0500 | [diff] [blame] | 2917 | trace_branch_disable(); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2918 | if (current_trace && current_trace->reset) |
| 2919 | current_trace->reset(tr); |
KOSAKI Motohiro | ef710e1 | 2010-07-01 14:34:35 +0900 | [diff] [blame] | 2920 | if (current_trace && current_trace->use_max_tr) { |
| 2921 | /* |
| 2922 | * We don't free the ring buffer. instead, resize it because |
| 2923 | * The max_tr ring buffer has some state (e.g. ring->clock) and |
| 2924 | * we want preserve it. |
| 2925 | */ |
| 2926 | ring_buffer_resize(max_tr.buffer, 1); |
| 2927 | max_tr.entries = 1; |
| 2928 | } |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 2929 | destroy_trace_option_files(topts); |
| 2930 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2931 | current_trace = t; |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 2932 | |
| 2933 | topts = create_trace_option_files(current_trace); |
KOSAKI Motohiro | ef710e1 | 2010-07-01 14:34:35 +0900 | [diff] [blame] | 2934 | if (current_trace->use_max_tr) { |
| 2935 | ret = ring_buffer_resize(max_tr.buffer, global_trace.entries); |
| 2936 | if (ret < 0) |
| 2937 | goto out; |
| 2938 | max_tr.entries = global_trace.entries; |
| 2939 | } |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 2940 | |
Frederic Weisbecker | 1c80025 | 2008-11-16 05:57:26 +0100 | [diff] [blame] | 2941 | if (t->init) { |
Arnaldo Carvalho de Melo | b6f11df | 2009-02-05 18:02:00 -0200 | [diff] [blame] | 2942 | ret = tracer_init(t, tr); |
Frederic Weisbecker | 1c80025 | 2008-11-16 05:57:26 +0100 | [diff] [blame] | 2943 | if (ret) |
| 2944 | goto out; |
| 2945 | } |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2946 | |
Steven Rostedt | 9f029e8 | 2008-11-12 15:24:24 -0500 | [diff] [blame] | 2947 | trace_branch_enable(tr); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2948 | out: |
| 2949 | mutex_unlock(&trace_types_lock); |
| 2950 | |
Peter Zijlstra | d9e5407 | 2008-11-01 19:57:37 +0100 | [diff] [blame] | 2951 | return ret; |
| 2952 | } |
| 2953 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2954 | static ssize_t |
| 2955 | tracing_set_trace_write(struct file *filp, const char __user *ubuf, |
| 2956 | size_t cnt, loff_t *ppos) |
| 2957 | { |
Li Zefan | ee6c2c1 | 2009-09-18 14:06:47 +0800 | [diff] [blame] | 2958 | char buf[MAX_TRACER_SIZE+1]; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2959 | int i; |
| 2960 | size_t ret; |
Frederic Weisbecker | e6e7a65 | 2008-11-16 05:53:19 +0100 | [diff] [blame] | 2961 | int err; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2962 | |
Steven Rostedt | 60063a6 | 2008-10-28 10:44:24 -0400 | [diff] [blame] | 2963 | ret = cnt; |
| 2964 | |
Li Zefan | ee6c2c1 | 2009-09-18 14:06:47 +0800 | [diff] [blame] | 2965 | if (cnt > MAX_TRACER_SIZE) |
| 2966 | cnt = MAX_TRACER_SIZE; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2967 | |
| 2968 | if (copy_from_user(&buf, ubuf, cnt)) |
| 2969 | return -EFAULT; |
| 2970 | |
| 2971 | buf[cnt] = 0; |
| 2972 | |
| 2973 | /* strip ending whitespace. */ |
| 2974 | for (i = cnt - 1; i > 0 && isspace(buf[i]); i--) |
| 2975 | buf[i] = 0; |
| 2976 | |
Frederic Weisbecker | e6e7a65 | 2008-11-16 05:53:19 +0100 | [diff] [blame] | 2977 | err = tracing_set_tracer(buf); |
| 2978 | if (err) |
| 2979 | return err; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2980 | |
Jiri Olsa | cf8517c | 2009-10-23 19:36:16 -0400 | [diff] [blame] | 2981 | *ppos += ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2982 | |
Frederic Weisbecker | c2931e0 | 2008-10-04 22:04:44 +0200 | [diff] [blame] | 2983 | return ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2984 | } |
| 2985 | |
| 2986 | static ssize_t |
| 2987 | tracing_max_lat_read(struct file *filp, char __user *ubuf, |
| 2988 | size_t cnt, loff_t *ppos) |
| 2989 | { |
| 2990 | unsigned long *ptr = filp->private_data; |
| 2991 | char buf[64]; |
| 2992 | int r; |
| 2993 | |
Steven Rostedt | cffae43 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 2994 | r = snprintf(buf, sizeof(buf), "%ld\n", |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2995 | *ptr == (unsigned long)-1 ? -1 : nsecs_to_usecs(*ptr)); |
Steven Rostedt | cffae43 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 2996 | if (r > sizeof(buf)) |
| 2997 | r = sizeof(buf); |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2998 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, r); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2999 | } |
| 3000 | |
| 3001 | static ssize_t |
| 3002 | tracing_max_lat_write(struct file *filp, const char __user *ubuf, |
| 3003 | size_t cnt, loff_t *ppos) |
| 3004 | { |
Hannes Eder | 5e39841 | 2009-02-10 19:44:34 +0100 | [diff] [blame] | 3005 | unsigned long *ptr = filp->private_data; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3006 | char buf[64]; |
Hannes Eder | 5e39841 | 2009-02-10 19:44:34 +0100 | [diff] [blame] | 3007 | unsigned long val; |
Steven Rostedt | c6caeeb | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 3008 | int ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3009 | |
Steven Rostedt | cffae43 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 3010 | if (cnt >= sizeof(buf)) |
| 3011 | return -EINVAL; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3012 | |
| 3013 | if (copy_from_user(&buf, ubuf, cnt)) |
| 3014 | return -EFAULT; |
| 3015 | |
| 3016 | buf[cnt] = 0; |
| 3017 | |
Steven Rostedt | c6caeeb | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 3018 | ret = strict_strtoul(buf, 10, &val); |
| 3019 | if (ret < 0) |
| 3020 | return ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3021 | |
| 3022 | *ptr = val * 1000; |
| 3023 | |
| 3024 | return cnt; |
| 3025 | } |
| 3026 | |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3027 | static int tracing_open_pipe(struct inode *inode, struct file *filp) |
| 3028 | { |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 3029 | long cpu_file = (long) inode->i_private; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3030 | struct trace_iterator *iter; |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 3031 | int ret = 0; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3032 | |
| 3033 | if (tracing_disabled) |
| 3034 | return -ENODEV; |
| 3035 | |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 3036 | mutex_lock(&trace_types_lock); |
| 3037 | |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3038 | /* create a buffer to store the information to pass to userspace */ |
| 3039 | iter = kzalloc(sizeof(*iter), GFP_KERNEL); |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 3040 | if (!iter) { |
| 3041 | ret = -ENOMEM; |
| 3042 | goto out; |
| 3043 | } |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3044 | |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 3045 | /* |
| 3046 | * We make a copy of the current tracer to avoid concurrent |
| 3047 | * changes on it while we are reading. |
| 3048 | */ |
| 3049 | iter->trace = kmalloc(sizeof(*iter->trace), GFP_KERNEL); |
| 3050 | if (!iter->trace) { |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 3051 | ret = -ENOMEM; |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 3052 | goto fail; |
| 3053 | } |
| 3054 | if (current_trace) |
| 3055 | *iter->trace = *current_trace; |
| 3056 | |
| 3057 | if (!alloc_cpumask_var(&iter->started, GFP_KERNEL)) { |
| 3058 | ret = -ENOMEM; |
| 3059 | goto fail; |
Rusty Russell | 4462344 | 2009-01-01 10:12:23 +1030 | [diff] [blame] | 3060 | } |
| 3061 | |
Steven Rostedt | a309720 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 3062 | /* trace pipe does not show start of buffer */ |
Rusty Russell | 4462344 | 2009-01-01 10:12:23 +1030 | [diff] [blame] | 3063 | cpumask_setall(iter->started); |
Steven Rostedt | a309720 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 3064 | |
Steven Rostedt | 112f38a7 | 2009-06-01 15:16:05 -0400 | [diff] [blame] | 3065 | if (trace_flags & TRACE_ITER_LATENCY_FMT) |
| 3066 | iter->iter_flags |= TRACE_FILE_LAT_FMT; |
| 3067 | |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 3068 | iter->cpu_file = cpu_file; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3069 | iter->tr = &global_trace; |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 3070 | mutex_init(&iter->mutex); |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3071 | filp->private_data = iter; |
| 3072 | |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 3073 | if (iter->trace->pipe_open) |
| 3074 | iter->trace->pipe_open(iter); |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 3075 | |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 3076 | nonseekable_open(inode, filp); |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 3077 | out: |
| 3078 | mutex_unlock(&trace_types_lock); |
| 3079 | return ret; |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 3080 | |
| 3081 | fail: |
| 3082 | kfree(iter->trace); |
| 3083 | kfree(iter); |
| 3084 | mutex_unlock(&trace_types_lock); |
| 3085 | return ret; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3086 | } |
| 3087 | |
| 3088 | static int tracing_release_pipe(struct inode *inode, struct file *file) |
| 3089 | { |
| 3090 | struct trace_iterator *iter = file->private_data; |
| 3091 | |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 3092 | mutex_lock(&trace_types_lock); |
| 3093 | |
Steven Rostedt | 29bf4a5 | 2009-12-09 12:37:43 -0500 | [diff] [blame] | 3094 | if (iter->trace->pipe_close) |
Steven Rostedt | c521efd | 2009-12-07 09:06:24 -0500 | [diff] [blame] | 3095 | iter->trace->pipe_close(iter); |
| 3096 | |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 3097 | mutex_unlock(&trace_types_lock); |
| 3098 | |
Rusty Russell | 4462344 | 2009-01-01 10:12:23 +1030 | [diff] [blame] | 3099 | free_cpumask_var(iter->started); |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 3100 | mutex_destroy(&iter->mutex); |
| 3101 | kfree(iter->trace); |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3102 | kfree(iter); |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3103 | |
| 3104 | return 0; |
| 3105 | } |
| 3106 | |
Soeren Sandmann Pedersen | 2a2cc8f | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 3107 | static unsigned int |
| 3108 | tracing_poll_pipe(struct file *filp, poll_table *poll_table) |
| 3109 | { |
| 3110 | struct trace_iterator *iter = filp->private_data; |
| 3111 | |
| 3112 | if (trace_flags & TRACE_ITER_BLOCK) { |
| 3113 | /* |
| 3114 | * Always select as readable when in blocking mode |
| 3115 | */ |
| 3116 | return POLLIN | POLLRDNORM; |
Ingo Molnar | afc2abc | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 3117 | } else { |
Soeren Sandmann Pedersen | 2a2cc8f | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 3118 | if (!trace_empty(iter)) |
| 3119 | return POLLIN | POLLRDNORM; |
| 3120 | poll_wait(filp, &trace_wait, poll_table); |
| 3121 | if (!trace_empty(iter)) |
| 3122 | return POLLIN | POLLRDNORM; |
| 3123 | |
| 3124 | return 0; |
| 3125 | } |
| 3126 | } |
| 3127 | |
Frederic Weisbecker | 6eaaa5d | 2009-02-11 02:25:00 +0100 | [diff] [blame] | 3128 | |
| 3129 | void default_wait_pipe(struct trace_iterator *iter) |
| 3130 | { |
| 3131 | DEFINE_WAIT(wait); |
| 3132 | |
| 3133 | prepare_to_wait(&trace_wait, &wait, TASK_INTERRUPTIBLE); |
| 3134 | |
| 3135 | if (trace_empty(iter)) |
| 3136 | schedule(); |
| 3137 | |
| 3138 | finish_wait(&trace_wait, &wait); |
| 3139 | } |
| 3140 | |
| 3141 | /* |
| 3142 | * This is a make-shift waitqueue. |
| 3143 | * A tracer might use this callback on some rare cases: |
| 3144 | * |
| 3145 | * 1) the current tracer might hold the runqueue lock when it wakes up |
| 3146 | * a reader, hence a deadlock (sched, function, and function graph tracers) |
| 3147 | * 2) the function tracers, trace all functions, we don't want |
| 3148 | * the overhead of calling wake_up and friends |
| 3149 | * (and tracing them too) |
| 3150 | * |
| 3151 | * Anyway, this is really very primitive wakeup. |
| 3152 | */ |
| 3153 | void poll_wait_pipe(struct trace_iterator *iter) |
| 3154 | { |
| 3155 | set_current_state(TASK_INTERRUPTIBLE); |
| 3156 | /* sleep for 100 msecs, and try again. */ |
| 3157 | schedule_timeout(HZ / 10); |
| 3158 | } |
| 3159 | |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 3160 | /* Must be called with trace_types_lock mutex held. */ |
| 3161 | static int tracing_wait_pipe(struct file *filp) |
| 3162 | { |
| 3163 | struct trace_iterator *iter = filp->private_data; |
| 3164 | |
| 3165 | while (trace_empty(iter)) { |
| 3166 | |
| 3167 | if ((filp->f_flags & O_NONBLOCK)) { |
| 3168 | return -EAGAIN; |
| 3169 | } |
| 3170 | |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 3171 | mutex_unlock(&iter->mutex); |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 3172 | |
Frederic Weisbecker | 6eaaa5d | 2009-02-11 02:25:00 +0100 | [diff] [blame] | 3173 | iter->trace->wait_pipe(iter); |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 3174 | |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 3175 | mutex_lock(&iter->mutex); |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 3176 | |
Frederic Weisbecker | 6eaaa5d | 2009-02-11 02:25:00 +0100 | [diff] [blame] | 3177 | if (signal_pending(current)) |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 3178 | return -EINTR; |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 3179 | |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 3180 | /* |
| 3181 | * We block until we read something and tracing is disabled. |
| 3182 | * We still block if tracing is disabled, but we have never |
| 3183 | * read anything. This allows a user to cat this file, and |
| 3184 | * then enable tracing. But after we have read something, |
| 3185 | * we give an EOF when tracing is again disabled. |
| 3186 | * |
| 3187 | * iter->pos will be 0 if we haven't read anything. |
| 3188 | */ |
| 3189 | if (!tracer_enabled && iter->pos) |
| 3190 | break; |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 3191 | } |
| 3192 | |
| 3193 | return 1; |
| 3194 | } |
| 3195 | |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3196 | /* |
| 3197 | * Consumer reader. |
| 3198 | */ |
| 3199 | static ssize_t |
| 3200 | tracing_read_pipe(struct file *filp, char __user *ubuf, |
| 3201 | size_t cnt, loff_t *ppos) |
| 3202 | { |
| 3203 | struct trace_iterator *iter = filp->private_data; |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 3204 | static struct tracer *old_tracer; |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 3205 | ssize_t sret; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3206 | |
| 3207 | /* return any leftover data */ |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 3208 | sret = trace_seq_to_user(&iter->seq, ubuf, cnt); |
| 3209 | if (sret != -EBUSY) |
| 3210 | return sret; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3211 | |
Steven Rostedt | f952075 | 2009-03-02 14:04:40 -0500 | [diff] [blame] | 3212 | trace_seq_init(&iter->seq); |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3213 | |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 3214 | /* copy the tracer to avoid using a global lock all around */ |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 3215 | mutex_lock(&trace_types_lock); |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 3216 | if (unlikely(old_tracer != current_trace && current_trace)) { |
| 3217 | old_tracer = current_trace; |
| 3218 | *iter->trace = *current_trace; |
| 3219 | } |
| 3220 | mutex_unlock(&trace_types_lock); |
| 3221 | |
| 3222 | /* |
| 3223 | * Avoid more than one consumer on a single file descriptor |
| 3224 | * This is just a matter of traces coherency, the ring buffer itself |
| 3225 | * is protected. |
| 3226 | */ |
| 3227 | mutex_lock(&iter->mutex); |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 3228 | if (iter->trace->read) { |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 3229 | sret = iter->trace->read(iter, filp, ubuf, cnt, ppos); |
| 3230 | if (sret) |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 3231 | goto out; |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 3232 | } |
| 3233 | |
Pekka Paalanen | 9ff4b97 | 2008-09-29 20:23:48 +0200 | [diff] [blame] | 3234 | waitagain: |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 3235 | sret = tracing_wait_pipe(filp); |
| 3236 | if (sret <= 0) |
| 3237 | goto out; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3238 | |
| 3239 | /* stop when tracing is finished */ |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 3240 | if (trace_empty(iter)) { |
| 3241 | sret = 0; |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 3242 | goto out; |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 3243 | } |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3244 | |
| 3245 | if (cnt >= PAGE_SIZE) |
| 3246 | cnt = PAGE_SIZE - 1; |
| 3247 | |
Steven Rostedt | 53d0aa7 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 3248 | /* reset all but tr, trace, and overruns */ |
Steven Rostedt | 53d0aa7 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 3249 | memset(&iter->seq, 0, |
| 3250 | sizeof(struct trace_iterator) - |
| 3251 | offsetof(struct trace_iterator, seq)); |
Steven Rostedt | 4823ed7 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 3252 | iter->pos = -1; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3253 | |
Lai Jiangshan | 4f53596 | 2009-05-18 19:35:34 +0800 | [diff] [blame] | 3254 | trace_event_read_lock(); |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 3255 | trace_access_lock(iter->cpu_file); |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 3256 | while (trace_find_next_entry_inc(iter) != NULL) { |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 3257 | enum print_line_t ret; |
Steven Rostedt | 088b1e42 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 3258 | int len = iter->seq.len; |
| 3259 | |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 3260 | ret = print_trace_line(iter); |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 3261 | if (ret == TRACE_TYPE_PARTIAL_LINE) { |
Steven Rostedt | 088b1e42 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 3262 | /* don't print partial lines */ |
| 3263 | iter->seq.len = len; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3264 | break; |
Steven Rostedt | 088b1e42 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 3265 | } |
Frederic Weisbecker | b91facc | 2009-02-06 18:30:44 +0100 | [diff] [blame] | 3266 | if (ret != TRACE_TYPE_NO_CONSUME) |
| 3267 | trace_consume(iter); |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3268 | |
| 3269 | if (iter->seq.len >= cnt) |
| 3270 | break; |
Jiri Olsa | ee5e51f | 2011-03-25 12:05:18 +0100 | [diff] [blame] | 3271 | |
| 3272 | /* |
| 3273 | * Setting the full flag means we reached the trace_seq buffer |
| 3274 | * size and we should leave by partial output condition above. |
| 3275 | * One of the trace_seq_* functions is not used properly. |
| 3276 | */ |
| 3277 | WARN_ONCE(iter->seq.full, "full flag set for trace type %d", |
| 3278 | iter->ent->type); |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3279 | } |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 3280 | trace_access_unlock(iter->cpu_file); |
Lai Jiangshan | 4f53596 | 2009-05-18 19:35:34 +0800 | [diff] [blame] | 3281 | trace_event_read_unlock(); |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3282 | |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3283 | /* Now copy what we have to the user */ |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 3284 | sret = trace_seq_to_user(&iter->seq, ubuf, cnt); |
| 3285 | if (iter->seq.readpos >= iter->seq.len) |
Steven Rostedt | f952075 | 2009-03-02 14:04:40 -0500 | [diff] [blame] | 3286 | trace_seq_init(&iter->seq); |
Pekka Paalanen | 9ff4b97 | 2008-09-29 20:23:48 +0200 | [diff] [blame] | 3287 | |
| 3288 | /* |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 3289 | * 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] | 3290 | * entries, go back to wait for more entries. |
| 3291 | */ |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 3292 | if (sret == -EBUSY) |
Pekka Paalanen | 9ff4b97 | 2008-09-29 20:23:48 +0200 | [diff] [blame] | 3293 | goto waitagain; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3294 | |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 3295 | out: |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 3296 | mutex_unlock(&iter->mutex); |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 3297 | |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 3298 | return sret; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3299 | } |
| 3300 | |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 3301 | static void tracing_pipe_buf_release(struct pipe_inode_info *pipe, |
| 3302 | struct pipe_buffer *buf) |
| 3303 | { |
| 3304 | __free_page(buf->page); |
| 3305 | } |
| 3306 | |
| 3307 | static void tracing_spd_release_pipe(struct splice_pipe_desc *spd, |
| 3308 | unsigned int idx) |
| 3309 | { |
| 3310 | __free_page(spd->pages[idx]); |
| 3311 | } |
| 3312 | |
Alexey Dobriyan | 28dfef8 | 2009-12-15 16:46:48 -0800 | [diff] [blame] | 3313 | static const struct pipe_buf_operations tracing_pipe_buf_ops = { |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 3314 | .can_merge = 0, |
| 3315 | .map = generic_pipe_buf_map, |
| 3316 | .unmap = generic_pipe_buf_unmap, |
| 3317 | .confirm = generic_pipe_buf_confirm, |
| 3318 | .release = tracing_pipe_buf_release, |
| 3319 | .steal = generic_pipe_buf_steal, |
| 3320 | .get = generic_pipe_buf_get, |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 3321 | }; |
| 3322 | |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 3323 | static size_t |
Frederic Weisbecker | fa7c7f6 | 2009-02-11 02:51:30 +0100 | [diff] [blame] | 3324 | tracing_fill_pipe_page(size_t rem, struct trace_iterator *iter) |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 3325 | { |
| 3326 | size_t count; |
| 3327 | int ret; |
| 3328 | |
| 3329 | /* Seq buffer is page-sized, exactly what we need. */ |
| 3330 | for (;;) { |
| 3331 | count = iter->seq.len; |
| 3332 | ret = print_trace_line(iter); |
| 3333 | count = iter->seq.len - count; |
| 3334 | if (rem < count) { |
| 3335 | rem = 0; |
| 3336 | iter->seq.len -= count; |
| 3337 | break; |
| 3338 | } |
| 3339 | if (ret == TRACE_TYPE_PARTIAL_LINE) { |
| 3340 | iter->seq.len -= count; |
| 3341 | break; |
| 3342 | } |
| 3343 | |
Lai Jiangshan | 74e7ff8 | 2009-07-28 20:17:22 +0800 | [diff] [blame] | 3344 | if (ret != TRACE_TYPE_NO_CONSUME) |
| 3345 | trace_consume(iter); |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 3346 | rem -= count; |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 3347 | if (!trace_find_next_entry_inc(iter)) { |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 3348 | rem = 0; |
| 3349 | iter->ent = NULL; |
| 3350 | break; |
| 3351 | } |
| 3352 | } |
| 3353 | |
| 3354 | return rem; |
| 3355 | } |
| 3356 | |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 3357 | static ssize_t tracing_splice_read_pipe(struct file *filp, |
| 3358 | loff_t *ppos, |
| 3359 | struct pipe_inode_info *pipe, |
| 3360 | size_t len, |
| 3361 | unsigned int flags) |
| 3362 | { |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 3363 | struct page *pages_def[PIPE_DEF_BUFFERS]; |
| 3364 | struct partial_page partial_def[PIPE_DEF_BUFFERS]; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 3365 | struct trace_iterator *iter = filp->private_data; |
| 3366 | struct splice_pipe_desc spd = { |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 3367 | .pages = pages_def, |
| 3368 | .partial = partial_def, |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 3369 | .nr_pages = 0, /* This gets updated below. */ |
| 3370 | .flags = flags, |
| 3371 | .ops = &tracing_pipe_buf_ops, |
| 3372 | .spd_release = tracing_spd_release_pipe, |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 3373 | }; |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 3374 | static struct tracer *old_tracer; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 3375 | ssize_t ret; |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 3376 | size_t rem; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 3377 | unsigned int i; |
| 3378 | |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 3379 | if (splice_grow_spd(pipe, &spd)) |
| 3380 | return -ENOMEM; |
| 3381 | |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 3382 | /* copy the tracer to avoid using a global lock all around */ |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 3383 | mutex_lock(&trace_types_lock); |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 3384 | if (unlikely(old_tracer != current_trace && current_trace)) { |
| 3385 | old_tracer = current_trace; |
| 3386 | *iter->trace = *current_trace; |
| 3387 | } |
| 3388 | mutex_unlock(&trace_types_lock); |
| 3389 | |
| 3390 | mutex_lock(&iter->mutex); |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 3391 | |
| 3392 | if (iter->trace->splice_read) { |
| 3393 | ret = iter->trace->splice_read(iter, filp, |
| 3394 | ppos, pipe, len, flags); |
| 3395 | if (ret) |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 3396 | goto out_err; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 3397 | } |
| 3398 | |
| 3399 | ret = tracing_wait_pipe(filp); |
| 3400 | if (ret <= 0) |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 3401 | goto out_err; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 3402 | |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 3403 | if (!iter->ent && !trace_find_next_entry_inc(iter)) { |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 3404 | ret = -EFAULT; |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 3405 | goto out_err; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 3406 | } |
| 3407 | |
Lai Jiangshan | 4f53596 | 2009-05-18 19:35:34 +0800 | [diff] [blame] | 3408 | trace_event_read_lock(); |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 3409 | trace_access_lock(iter->cpu_file); |
Lai Jiangshan | 4f53596 | 2009-05-18 19:35:34 +0800 | [diff] [blame] | 3410 | |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 3411 | /* Fill as many pages as possible. */ |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 3412 | for (i = 0, rem = len; i < pipe->buffers && rem; i++) { |
| 3413 | spd.pages[i] = alloc_page(GFP_KERNEL); |
| 3414 | if (!spd.pages[i]) |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 3415 | break; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 3416 | |
Frederic Weisbecker | fa7c7f6 | 2009-02-11 02:51:30 +0100 | [diff] [blame] | 3417 | rem = tracing_fill_pipe_page(rem, iter); |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 3418 | |
| 3419 | /* Copy the data into the page, so we can start over. */ |
| 3420 | ret = trace_seq_to_buffer(&iter->seq, |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 3421 | page_address(spd.pages[i]), |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 3422 | iter->seq.len); |
| 3423 | if (ret < 0) { |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 3424 | __free_page(spd.pages[i]); |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 3425 | break; |
| 3426 | } |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 3427 | spd.partial[i].offset = 0; |
| 3428 | spd.partial[i].len = iter->seq.len; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 3429 | |
Steven Rostedt | f952075 | 2009-03-02 14:04:40 -0500 | [diff] [blame] | 3430 | trace_seq_init(&iter->seq); |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 3431 | } |
| 3432 | |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 3433 | trace_access_unlock(iter->cpu_file); |
Lai Jiangshan | 4f53596 | 2009-05-18 19:35:34 +0800 | [diff] [blame] | 3434 | trace_event_read_unlock(); |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 3435 | mutex_unlock(&iter->mutex); |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 3436 | |
| 3437 | spd.nr_pages = i; |
| 3438 | |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 3439 | ret = splice_to_pipe(pipe, &spd); |
| 3440 | out: |
| 3441 | splice_shrink_spd(pipe, &spd); |
| 3442 | return ret; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 3443 | |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 3444 | out_err: |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 3445 | mutex_unlock(&iter->mutex); |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 3446 | goto out; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 3447 | } |
| 3448 | |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 3449 | static ssize_t |
| 3450 | tracing_entries_read(struct file *filp, char __user *ubuf, |
| 3451 | size_t cnt, loff_t *ppos) |
| 3452 | { |
| 3453 | struct trace_array *tr = filp->private_data; |
Steven Rostedt | db526ca | 2009-03-12 13:53:25 -0400 | [diff] [blame] | 3454 | char buf[96]; |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 3455 | int r; |
| 3456 | |
Steven Rostedt | db526ca | 2009-03-12 13:53:25 -0400 | [diff] [blame] | 3457 | mutex_lock(&trace_types_lock); |
| 3458 | if (!ring_buffer_expanded) |
| 3459 | r = sprintf(buf, "%lu (expanded: %lu)\n", |
| 3460 | tr->entries >> 10, |
| 3461 | trace_buf_size >> 10); |
| 3462 | else |
| 3463 | r = sprintf(buf, "%lu\n", tr->entries >> 10); |
| 3464 | mutex_unlock(&trace_types_lock); |
| 3465 | |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 3466 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, r); |
| 3467 | } |
| 3468 | |
| 3469 | static ssize_t |
| 3470 | tracing_entries_write(struct file *filp, const char __user *ubuf, |
| 3471 | size_t cnt, loff_t *ppos) |
| 3472 | { |
| 3473 | unsigned long val; |
| 3474 | char buf[64]; |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 3475 | int ret; |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 3476 | |
Steven Rostedt | cffae43 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 3477 | if (cnt >= sizeof(buf)) |
| 3478 | return -EINVAL; |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 3479 | |
| 3480 | if (copy_from_user(&buf, ubuf, cnt)) |
| 3481 | return -EFAULT; |
| 3482 | |
| 3483 | buf[cnt] = 0; |
| 3484 | |
Steven Rostedt | c6caeeb | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 3485 | ret = strict_strtoul(buf, 10, &val); |
| 3486 | if (ret < 0) |
| 3487 | return ret; |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 3488 | |
| 3489 | /* must have at least 1 entry */ |
| 3490 | if (!val) |
| 3491 | return -EINVAL; |
| 3492 | |
Steven Rostedt | 1696b2b | 2008-11-13 00:09:35 -0500 | [diff] [blame] | 3493 | /* value is in KB */ |
| 3494 | val <<= 10; |
| 3495 | |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 3496 | ret = tracing_resize_ring_buffer(val); |
| 3497 | if (ret < 0) |
| 3498 | return ret; |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 3499 | |
Jiri Olsa | cf8517c | 2009-10-23 19:36:16 -0400 | [diff] [blame] | 3500 | *ppos += cnt; |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 3501 | |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 3502 | return cnt; |
| 3503 | } |
Steven Rostedt | bf5e651 | 2008-11-10 21:46:00 -0500 | [diff] [blame] | 3504 | |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 3505 | static ssize_t |
| 3506 | tracing_free_buffer_write(struct file *filp, const char __user *ubuf, |
| 3507 | size_t cnt, loff_t *ppos) |
| 3508 | { |
| 3509 | /* |
| 3510 | * There is no need to read what the user has written, this function |
| 3511 | * is just to make sure that there is no error when "echo" is used |
| 3512 | */ |
| 3513 | |
| 3514 | *ppos += cnt; |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 3515 | |
| 3516 | return cnt; |
| 3517 | } |
| 3518 | |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 3519 | static int |
| 3520 | tracing_free_buffer_release(struct inode *inode, struct file *filp) |
| 3521 | { |
Steven Rostedt | cf30cf6 | 2011-06-14 22:44:07 -0400 | [diff] [blame^] | 3522 | /* disable tracing ? */ |
| 3523 | if (trace_flags & TRACE_ITER_STOP_ON_FREE) |
| 3524 | tracing_off(); |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 3525 | /* resize the ring buffer to 0 */ |
| 3526 | tracing_resize_ring_buffer(0); |
| 3527 | |
| 3528 | return 0; |
| 3529 | } |
| 3530 | |
Carsten Emde | f294248 | 2009-12-06 14:02:44 +0100 | [diff] [blame] | 3531 | static int mark_printk(const char *fmt, ...) |
| 3532 | { |
| 3533 | int ret; |
| 3534 | va_list args; |
| 3535 | va_start(args, fmt); |
| 3536 | ret = trace_vprintk(0, fmt, args); |
| 3537 | va_end(args); |
| 3538 | return ret; |
| 3539 | } |
| 3540 | |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 3541 | static ssize_t |
| 3542 | tracing_mark_write(struct file *filp, const char __user *ubuf, |
| 3543 | size_t cnt, loff_t *fpos) |
| 3544 | { |
| 3545 | char *buf; |
Marcin Slusarz | 1aa54bc | 2010-07-28 01:18:01 +0200 | [diff] [blame] | 3546 | size_t written; |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 3547 | |
Steven Rostedt | c76f069 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 3548 | if (tracing_disabled) |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 3549 | return -EINVAL; |
| 3550 | |
| 3551 | if (cnt > TRACE_BUF_SIZE) |
| 3552 | cnt = TRACE_BUF_SIZE; |
| 3553 | |
Carsten Emde | c13d2f7 | 2009-11-16 20:56:13 +0100 | [diff] [blame] | 3554 | buf = kmalloc(cnt + 2, GFP_KERNEL); |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 3555 | if (buf == NULL) |
| 3556 | return -ENOMEM; |
| 3557 | |
| 3558 | if (copy_from_user(buf, ubuf, cnt)) { |
| 3559 | kfree(buf); |
| 3560 | return -EFAULT; |
| 3561 | } |
Carsten Emde | c13d2f7 | 2009-11-16 20:56:13 +0100 | [diff] [blame] | 3562 | if (buf[cnt-1] != '\n') { |
| 3563 | buf[cnt] = '\n'; |
| 3564 | buf[cnt+1] = '\0'; |
| 3565 | } else |
| 3566 | buf[cnt] = '\0'; |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 3567 | |
Marcin Slusarz | 1aa54bc | 2010-07-28 01:18:01 +0200 | [diff] [blame] | 3568 | written = mark_printk("%s", buf); |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 3569 | kfree(buf); |
Marcin Slusarz | 1aa54bc | 2010-07-28 01:18:01 +0200 | [diff] [blame] | 3570 | *fpos += written; |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 3571 | |
Marcin Slusarz | 1aa54bc | 2010-07-28 01:18:01 +0200 | [diff] [blame] | 3572 | /* don't tell userspace we wrote more - it might confuse them */ |
| 3573 | if (written > cnt) |
| 3574 | written = cnt; |
| 3575 | |
| 3576 | return written; |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 3577 | } |
| 3578 | |
Li Zefan | 13f16d2 | 2009-12-08 11:16:11 +0800 | [diff] [blame] | 3579 | static int tracing_clock_show(struct seq_file *m, void *v) |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 3580 | { |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 3581 | int i; |
| 3582 | |
| 3583 | for (i = 0; i < ARRAY_SIZE(trace_clocks); i++) |
Li Zefan | 13f16d2 | 2009-12-08 11:16:11 +0800 | [diff] [blame] | 3584 | seq_printf(m, |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 3585 | "%s%s%s%s", i ? " " : "", |
| 3586 | i == trace_clock_id ? "[" : "", trace_clocks[i].name, |
| 3587 | i == trace_clock_id ? "]" : ""); |
Li Zefan | 13f16d2 | 2009-12-08 11:16:11 +0800 | [diff] [blame] | 3588 | seq_putc(m, '\n'); |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 3589 | |
Li Zefan | 13f16d2 | 2009-12-08 11:16:11 +0800 | [diff] [blame] | 3590 | return 0; |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 3591 | } |
| 3592 | |
| 3593 | static ssize_t tracing_clock_write(struct file *filp, const char __user *ubuf, |
| 3594 | size_t cnt, loff_t *fpos) |
| 3595 | { |
| 3596 | char buf[64]; |
| 3597 | const char *clockstr; |
| 3598 | int i; |
| 3599 | |
| 3600 | if (cnt >= sizeof(buf)) |
| 3601 | return -EINVAL; |
| 3602 | |
| 3603 | if (copy_from_user(&buf, ubuf, cnt)) |
| 3604 | return -EFAULT; |
| 3605 | |
| 3606 | buf[cnt] = 0; |
| 3607 | |
| 3608 | clockstr = strstrip(buf); |
| 3609 | |
| 3610 | for (i = 0; i < ARRAY_SIZE(trace_clocks); i++) { |
| 3611 | if (strcmp(trace_clocks[i].name, clockstr) == 0) |
| 3612 | break; |
| 3613 | } |
| 3614 | if (i == ARRAY_SIZE(trace_clocks)) |
| 3615 | return -EINVAL; |
| 3616 | |
| 3617 | trace_clock_id = i; |
| 3618 | |
| 3619 | mutex_lock(&trace_types_lock); |
| 3620 | |
| 3621 | ring_buffer_set_clock(global_trace.buffer, trace_clocks[i].func); |
| 3622 | if (max_tr.buffer) |
| 3623 | ring_buffer_set_clock(max_tr.buffer, trace_clocks[i].func); |
| 3624 | |
| 3625 | mutex_unlock(&trace_types_lock); |
| 3626 | |
| 3627 | *fpos += cnt; |
| 3628 | |
| 3629 | return cnt; |
| 3630 | } |
| 3631 | |
Li Zefan | 13f16d2 | 2009-12-08 11:16:11 +0800 | [diff] [blame] | 3632 | static int tracing_clock_open(struct inode *inode, struct file *file) |
| 3633 | { |
| 3634 | if (tracing_disabled) |
| 3635 | return -ENODEV; |
| 3636 | return single_open(file, tracing_clock_show, NULL); |
| 3637 | } |
| 3638 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 3639 | static const struct file_operations tracing_max_lat_fops = { |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3640 | .open = tracing_open_generic, |
| 3641 | .read = tracing_max_lat_read, |
| 3642 | .write = tracing_max_lat_write, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 3643 | .llseek = generic_file_llseek, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3644 | }; |
| 3645 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 3646 | static const struct file_operations tracing_ctrl_fops = { |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3647 | .open = tracing_open_generic, |
| 3648 | .read = tracing_ctrl_read, |
| 3649 | .write = tracing_ctrl_write, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 3650 | .llseek = generic_file_llseek, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3651 | }; |
| 3652 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 3653 | static const struct file_operations set_tracer_fops = { |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3654 | .open = tracing_open_generic, |
| 3655 | .read = tracing_set_trace_read, |
| 3656 | .write = tracing_set_trace_write, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 3657 | .llseek = generic_file_llseek, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3658 | }; |
| 3659 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 3660 | static const struct file_operations tracing_pipe_fops = { |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3661 | .open = tracing_open_pipe, |
Soeren Sandmann Pedersen | 2a2cc8f | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 3662 | .poll = tracing_poll_pipe, |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3663 | .read = tracing_read_pipe, |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 3664 | .splice_read = tracing_splice_read_pipe, |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3665 | .release = tracing_release_pipe, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 3666 | .llseek = no_llseek, |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3667 | }; |
| 3668 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 3669 | static const struct file_operations tracing_entries_fops = { |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 3670 | .open = tracing_open_generic, |
| 3671 | .read = tracing_entries_read, |
| 3672 | .write = tracing_entries_write, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 3673 | .llseek = generic_file_llseek, |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 3674 | }; |
| 3675 | |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 3676 | static const struct file_operations tracing_free_buffer_fops = { |
| 3677 | .write = tracing_free_buffer_write, |
| 3678 | .release = tracing_free_buffer_release, |
| 3679 | }; |
| 3680 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 3681 | static const struct file_operations tracing_mark_fops = { |
Frédéric Weisbecker | 43a1538 | 2008-09-21 20:16:30 +0200 | [diff] [blame] | 3682 | .open = tracing_open_generic, |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 3683 | .write = tracing_mark_write, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 3684 | .llseek = generic_file_llseek, |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 3685 | }; |
| 3686 | |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 3687 | static const struct file_operations trace_clock_fops = { |
Li Zefan | 13f16d2 | 2009-12-08 11:16:11 +0800 | [diff] [blame] | 3688 | .open = tracing_clock_open, |
| 3689 | .read = seq_read, |
| 3690 | .llseek = seq_lseek, |
| 3691 | .release = single_release, |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 3692 | .write = tracing_clock_write, |
| 3693 | }; |
| 3694 | |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 3695 | struct ftrace_buffer_info { |
| 3696 | struct trace_array *tr; |
| 3697 | void *spare; |
| 3698 | int cpu; |
| 3699 | unsigned int read; |
| 3700 | }; |
| 3701 | |
| 3702 | static int tracing_buffers_open(struct inode *inode, struct file *filp) |
| 3703 | { |
| 3704 | int cpu = (int)(long)inode->i_private; |
| 3705 | struct ftrace_buffer_info *info; |
| 3706 | |
| 3707 | if (tracing_disabled) |
| 3708 | return -ENODEV; |
| 3709 | |
| 3710 | info = kzalloc(sizeof(*info), GFP_KERNEL); |
| 3711 | if (!info) |
| 3712 | return -ENOMEM; |
| 3713 | |
| 3714 | info->tr = &global_trace; |
| 3715 | info->cpu = cpu; |
Lai Jiangshan | ddd538f | 2009-04-02 15:16:59 +0800 | [diff] [blame] | 3716 | info->spare = NULL; |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 3717 | /* Force reading ring buffer for first read */ |
| 3718 | info->read = (unsigned int)-1; |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 3719 | |
| 3720 | filp->private_data = info; |
| 3721 | |
Lai Jiangshan | d1e7e02 | 2009-04-02 15:16:56 +0800 | [diff] [blame] | 3722 | return nonseekable_open(inode, filp); |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 3723 | } |
| 3724 | |
| 3725 | static ssize_t |
| 3726 | tracing_buffers_read(struct file *filp, char __user *ubuf, |
| 3727 | size_t count, loff_t *ppos) |
| 3728 | { |
| 3729 | struct ftrace_buffer_info *info = filp->private_data; |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 3730 | ssize_t ret; |
| 3731 | size_t size; |
| 3732 | |
Steven Rostedt | 2dc5d12 | 2009-03-04 19:10:05 -0500 | [diff] [blame] | 3733 | if (!count) |
| 3734 | return 0; |
| 3735 | |
Lai Jiangshan | ddd538f | 2009-04-02 15:16:59 +0800 | [diff] [blame] | 3736 | if (!info->spare) |
Vaibhav Nagarnaik | 7ea5906 | 2011-05-03 17:56:42 -0700 | [diff] [blame] | 3737 | info->spare = ring_buffer_alloc_read_page(info->tr->buffer, info->cpu); |
Lai Jiangshan | ddd538f | 2009-04-02 15:16:59 +0800 | [diff] [blame] | 3738 | if (!info->spare) |
| 3739 | return -ENOMEM; |
| 3740 | |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 3741 | /* Do we have previous read data to read? */ |
| 3742 | if (info->read < PAGE_SIZE) |
| 3743 | goto read; |
| 3744 | |
| 3745 | info->read = 0; |
| 3746 | |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 3747 | trace_access_lock(info->cpu); |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 3748 | ret = ring_buffer_read_page(info->tr->buffer, |
| 3749 | &info->spare, |
| 3750 | count, |
| 3751 | info->cpu, 0); |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 3752 | trace_access_unlock(info->cpu); |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 3753 | if (ret < 0) |
| 3754 | return 0; |
| 3755 | |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 3756 | read: |
| 3757 | size = PAGE_SIZE - info->read; |
| 3758 | if (size > count) |
| 3759 | size = count; |
| 3760 | |
| 3761 | ret = copy_to_user(ubuf, info->spare + info->read, size); |
Steven Rostedt | 2dc5d12 | 2009-03-04 19:10:05 -0500 | [diff] [blame] | 3762 | if (ret == size) |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 3763 | return -EFAULT; |
Steven Rostedt | 2dc5d12 | 2009-03-04 19:10:05 -0500 | [diff] [blame] | 3764 | size -= ret; |
| 3765 | |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 3766 | *ppos += size; |
| 3767 | info->read += size; |
| 3768 | |
| 3769 | return size; |
| 3770 | } |
| 3771 | |
| 3772 | static int tracing_buffers_release(struct inode *inode, struct file *file) |
| 3773 | { |
| 3774 | struct ftrace_buffer_info *info = file->private_data; |
| 3775 | |
Lai Jiangshan | ddd538f | 2009-04-02 15:16:59 +0800 | [diff] [blame] | 3776 | if (info->spare) |
| 3777 | ring_buffer_free_read_page(info->tr->buffer, info->spare); |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 3778 | kfree(info); |
| 3779 | |
| 3780 | return 0; |
| 3781 | } |
| 3782 | |
| 3783 | struct buffer_ref { |
| 3784 | struct ring_buffer *buffer; |
| 3785 | void *page; |
| 3786 | int ref; |
| 3787 | }; |
| 3788 | |
| 3789 | static void buffer_pipe_buf_release(struct pipe_inode_info *pipe, |
| 3790 | struct pipe_buffer *buf) |
| 3791 | { |
| 3792 | struct buffer_ref *ref = (struct buffer_ref *)buf->private; |
| 3793 | |
| 3794 | if (--ref->ref) |
| 3795 | return; |
| 3796 | |
| 3797 | ring_buffer_free_read_page(ref->buffer, ref->page); |
| 3798 | kfree(ref); |
| 3799 | buf->private = 0; |
| 3800 | } |
| 3801 | |
| 3802 | static int buffer_pipe_buf_steal(struct pipe_inode_info *pipe, |
| 3803 | struct pipe_buffer *buf) |
| 3804 | { |
| 3805 | return 1; |
| 3806 | } |
| 3807 | |
| 3808 | static void buffer_pipe_buf_get(struct pipe_inode_info *pipe, |
| 3809 | struct pipe_buffer *buf) |
| 3810 | { |
| 3811 | struct buffer_ref *ref = (struct buffer_ref *)buf->private; |
| 3812 | |
| 3813 | ref->ref++; |
| 3814 | } |
| 3815 | |
| 3816 | /* Pipe buffer operations for a buffer. */ |
Alexey Dobriyan | 28dfef8 | 2009-12-15 16:46:48 -0800 | [diff] [blame] | 3817 | static const struct pipe_buf_operations buffer_pipe_buf_ops = { |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 3818 | .can_merge = 0, |
| 3819 | .map = generic_pipe_buf_map, |
| 3820 | .unmap = generic_pipe_buf_unmap, |
| 3821 | .confirm = generic_pipe_buf_confirm, |
| 3822 | .release = buffer_pipe_buf_release, |
| 3823 | .steal = buffer_pipe_buf_steal, |
| 3824 | .get = buffer_pipe_buf_get, |
| 3825 | }; |
| 3826 | |
| 3827 | /* |
| 3828 | * Callback from splice_to_pipe(), if we need to release some pages |
| 3829 | * at the end of the spd in case we error'ed out in filling the pipe. |
| 3830 | */ |
| 3831 | static void buffer_spd_release(struct splice_pipe_desc *spd, unsigned int i) |
| 3832 | { |
| 3833 | struct buffer_ref *ref = |
| 3834 | (struct buffer_ref *)spd->partial[i].private; |
| 3835 | |
| 3836 | if (--ref->ref) |
| 3837 | return; |
| 3838 | |
| 3839 | ring_buffer_free_read_page(ref->buffer, ref->page); |
| 3840 | kfree(ref); |
| 3841 | spd->partial[i].private = 0; |
| 3842 | } |
| 3843 | |
| 3844 | static ssize_t |
| 3845 | tracing_buffers_splice_read(struct file *file, loff_t *ppos, |
| 3846 | struct pipe_inode_info *pipe, size_t len, |
| 3847 | unsigned int flags) |
| 3848 | { |
| 3849 | struct ftrace_buffer_info *info = file->private_data; |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 3850 | struct partial_page partial_def[PIPE_DEF_BUFFERS]; |
| 3851 | struct page *pages_def[PIPE_DEF_BUFFERS]; |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 3852 | struct splice_pipe_desc spd = { |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 3853 | .pages = pages_def, |
| 3854 | .partial = partial_def, |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 3855 | .flags = flags, |
| 3856 | .ops = &buffer_pipe_buf_ops, |
| 3857 | .spd_release = buffer_spd_release, |
| 3858 | }; |
| 3859 | struct buffer_ref *ref; |
Steven Rostedt | 93459c6 | 2009-04-29 00:23:13 -0400 | [diff] [blame] | 3860 | int entries, size, i; |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 3861 | size_t ret; |
| 3862 | |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 3863 | if (splice_grow_spd(pipe, &spd)) |
| 3864 | return -ENOMEM; |
| 3865 | |
Lai Jiangshan | 93cfb3c | 2009-04-02 15:17:08 +0800 | [diff] [blame] | 3866 | if (*ppos & (PAGE_SIZE - 1)) { |
| 3867 | WARN_ONCE(1, "Ftrace: previous read must page-align\n"); |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 3868 | ret = -EINVAL; |
| 3869 | goto out; |
Lai Jiangshan | 93cfb3c | 2009-04-02 15:17:08 +0800 | [diff] [blame] | 3870 | } |
| 3871 | |
| 3872 | if (len & (PAGE_SIZE - 1)) { |
| 3873 | WARN_ONCE(1, "Ftrace: splice_read should page-align\n"); |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 3874 | if (len < PAGE_SIZE) { |
| 3875 | ret = -EINVAL; |
| 3876 | goto out; |
| 3877 | } |
Lai Jiangshan | 93cfb3c | 2009-04-02 15:17:08 +0800 | [diff] [blame] | 3878 | len &= PAGE_MASK; |
| 3879 | } |
| 3880 | |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 3881 | trace_access_lock(info->cpu); |
Steven Rostedt | 93459c6 | 2009-04-29 00:23:13 -0400 | [diff] [blame] | 3882 | entries = ring_buffer_entries_cpu(info->tr->buffer, info->cpu); |
| 3883 | |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 3884 | for (i = 0; i < pipe->buffers && len && entries; i++, len -= PAGE_SIZE) { |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 3885 | struct page *page; |
| 3886 | int r; |
| 3887 | |
| 3888 | ref = kzalloc(sizeof(*ref), GFP_KERNEL); |
| 3889 | if (!ref) |
| 3890 | break; |
| 3891 | |
Steven Rostedt | 7267fa6 | 2009-04-29 00:16:21 -0400 | [diff] [blame] | 3892 | ref->ref = 1; |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 3893 | ref->buffer = info->tr->buffer; |
Vaibhav Nagarnaik | 7ea5906 | 2011-05-03 17:56:42 -0700 | [diff] [blame] | 3894 | ref->page = ring_buffer_alloc_read_page(ref->buffer, info->cpu); |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 3895 | if (!ref->page) { |
| 3896 | kfree(ref); |
| 3897 | break; |
| 3898 | } |
| 3899 | |
| 3900 | r = ring_buffer_read_page(ref->buffer, &ref->page, |
Steven Rostedt | f2957f1 | 2009-04-29 00:26:30 -0400 | [diff] [blame] | 3901 | len, info->cpu, 1); |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 3902 | if (r < 0) { |
Vaibhav Nagarnaik | 7ea5906 | 2011-05-03 17:56:42 -0700 | [diff] [blame] | 3903 | ring_buffer_free_read_page(ref->buffer, ref->page); |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 3904 | kfree(ref); |
| 3905 | break; |
| 3906 | } |
| 3907 | |
| 3908 | /* |
| 3909 | * zero out any left over data, this is going to |
| 3910 | * user land. |
| 3911 | */ |
| 3912 | size = ring_buffer_page_len(ref->page); |
| 3913 | if (size < PAGE_SIZE) |
| 3914 | memset(ref->page + size, 0, PAGE_SIZE - size); |
| 3915 | |
| 3916 | page = virt_to_page(ref->page); |
| 3917 | |
| 3918 | spd.pages[i] = page; |
| 3919 | spd.partial[i].len = PAGE_SIZE; |
| 3920 | spd.partial[i].offset = 0; |
| 3921 | spd.partial[i].private = (unsigned long)ref; |
| 3922 | spd.nr_pages++; |
Lai Jiangshan | 93cfb3c | 2009-04-02 15:17:08 +0800 | [diff] [blame] | 3923 | *ppos += PAGE_SIZE; |
Steven Rostedt | 93459c6 | 2009-04-29 00:23:13 -0400 | [diff] [blame] | 3924 | |
| 3925 | entries = ring_buffer_entries_cpu(info->tr->buffer, info->cpu); |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 3926 | } |
| 3927 | |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 3928 | trace_access_unlock(info->cpu); |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 3929 | spd.nr_pages = i; |
| 3930 | |
| 3931 | /* did we read anything? */ |
| 3932 | if (!spd.nr_pages) { |
| 3933 | if (flags & SPLICE_F_NONBLOCK) |
| 3934 | ret = -EAGAIN; |
| 3935 | else |
| 3936 | ret = 0; |
| 3937 | /* TODO: block */ |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 3938 | goto out; |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 3939 | } |
| 3940 | |
| 3941 | ret = splice_to_pipe(pipe, &spd); |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 3942 | splice_shrink_spd(pipe, &spd); |
| 3943 | out: |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 3944 | return ret; |
| 3945 | } |
| 3946 | |
| 3947 | static const struct file_operations tracing_buffers_fops = { |
| 3948 | .open = tracing_buffers_open, |
| 3949 | .read = tracing_buffers_read, |
| 3950 | .release = tracing_buffers_release, |
| 3951 | .splice_read = tracing_buffers_splice_read, |
| 3952 | .llseek = no_llseek, |
| 3953 | }; |
| 3954 | |
Steven Rostedt | c8d7718 | 2009-04-29 18:03:45 -0400 | [diff] [blame] | 3955 | static ssize_t |
| 3956 | tracing_stats_read(struct file *filp, char __user *ubuf, |
| 3957 | size_t count, loff_t *ppos) |
| 3958 | { |
| 3959 | unsigned long cpu = (unsigned long)filp->private_data; |
| 3960 | struct trace_array *tr = &global_trace; |
| 3961 | struct trace_seq *s; |
| 3962 | unsigned long cnt; |
| 3963 | |
Li Zefan | e4f2d10 | 2009-06-15 10:57:28 +0800 | [diff] [blame] | 3964 | s = kmalloc(sizeof(*s), GFP_KERNEL); |
Steven Rostedt | c8d7718 | 2009-04-29 18:03:45 -0400 | [diff] [blame] | 3965 | if (!s) |
Roel Kluin | a646365 | 2009-11-11 22:26:35 +0100 | [diff] [blame] | 3966 | return -ENOMEM; |
Steven Rostedt | c8d7718 | 2009-04-29 18:03:45 -0400 | [diff] [blame] | 3967 | |
| 3968 | trace_seq_init(s); |
| 3969 | |
| 3970 | cnt = ring_buffer_entries_cpu(tr->buffer, cpu); |
| 3971 | trace_seq_printf(s, "entries: %ld\n", cnt); |
| 3972 | |
| 3973 | cnt = ring_buffer_overrun_cpu(tr->buffer, cpu); |
| 3974 | trace_seq_printf(s, "overrun: %ld\n", cnt); |
| 3975 | |
| 3976 | cnt = ring_buffer_commit_overrun_cpu(tr->buffer, cpu); |
| 3977 | trace_seq_printf(s, "commit overrun: %ld\n", cnt); |
| 3978 | |
Steven Rostedt | c8d7718 | 2009-04-29 18:03:45 -0400 | [diff] [blame] | 3979 | count = simple_read_from_buffer(ubuf, count, ppos, s->buffer, s->len); |
| 3980 | |
| 3981 | kfree(s); |
| 3982 | |
| 3983 | return count; |
| 3984 | } |
| 3985 | |
| 3986 | static const struct file_operations tracing_stats_fops = { |
| 3987 | .open = tracing_open_generic, |
| 3988 | .read = tracing_stats_read, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 3989 | .llseek = generic_file_llseek, |
Steven Rostedt | c8d7718 | 2009-04-29 18:03:45 -0400 | [diff] [blame] | 3990 | }; |
| 3991 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3992 | #ifdef CONFIG_DYNAMIC_FTRACE |
| 3993 | |
Steven Rostedt | b807c3d | 2008-10-30 16:08:33 -0400 | [diff] [blame] | 3994 | int __weak ftrace_arch_read_dyn_info(char *buf, int size) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3995 | { |
Steven Rostedt | b807c3d | 2008-10-30 16:08:33 -0400 | [diff] [blame] | 3996 | return 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3997 | } |
| 3998 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3999 | static ssize_t |
Steven Rostedt | b807c3d | 2008-10-30 16:08:33 -0400 | [diff] [blame] | 4000 | tracing_read_dyn_info(struct file *filp, char __user *ubuf, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4001 | size_t cnt, loff_t *ppos) |
| 4002 | { |
Steven Rostedt | a26a2a2 | 2008-10-31 00:03:22 -0400 | [diff] [blame] | 4003 | static char ftrace_dyn_info_buffer[1024]; |
| 4004 | static DEFINE_MUTEX(dyn_info_mutex); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4005 | unsigned long *p = filp->private_data; |
Steven Rostedt | b807c3d | 2008-10-30 16:08:33 -0400 | [diff] [blame] | 4006 | char *buf = ftrace_dyn_info_buffer; |
Steven Rostedt | a26a2a2 | 2008-10-31 00:03:22 -0400 | [diff] [blame] | 4007 | int size = ARRAY_SIZE(ftrace_dyn_info_buffer); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4008 | int r; |
| 4009 | |
Steven Rostedt | b807c3d | 2008-10-30 16:08:33 -0400 | [diff] [blame] | 4010 | mutex_lock(&dyn_info_mutex); |
| 4011 | r = sprintf(buf, "%ld ", *p); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4012 | |
Steven Rostedt | a26a2a2 | 2008-10-31 00:03:22 -0400 | [diff] [blame] | 4013 | r += ftrace_arch_read_dyn_info(buf+r, (size-1)-r); |
Steven Rostedt | b807c3d | 2008-10-30 16:08:33 -0400 | [diff] [blame] | 4014 | buf[r++] = '\n'; |
| 4015 | |
| 4016 | r = simple_read_from_buffer(ubuf, cnt, ppos, buf, r); |
| 4017 | |
| 4018 | mutex_unlock(&dyn_info_mutex); |
| 4019 | |
| 4020 | return r; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4021 | } |
| 4022 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 4023 | static const struct file_operations tracing_dyn_info_fops = { |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4024 | .open = tracing_open_generic, |
Steven Rostedt | b807c3d | 2008-10-30 16:08:33 -0400 | [diff] [blame] | 4025 | .read = tracing_read_dyn_info, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 4026 | .llseek = generic_file_llseek, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4027 | }; |
| 4028 | #endif |
| 4029 | |
| 4030 | static struct dentry *d_tracer; |
| 4031 | |
| 4032 | struct dentry *tracing_init_dentry(void) |
| 4033 | { |
| 4034 | static int once; |
| 4035 | |
| 4036 | if (d_tracer) |
| 4037 | return d_tracer; |
| 4038 | |
Frederic Weisbecker | 3e1f60b | 2009-03-22 23:10:45 +0100 | [diff] [blame] | 4039 | if (!debugfs_initialized()) |
| 4040 | return NULL; |
| 4041 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4042 | d_tracer = debugfs_create_dir("tracing", NULL); |
| 4043 | |
| 4044 | if (!d_tracer && !once) { |
| 4045 | once = 1; |
| 4046 | pr_warning("Could not create debugfs directory 'tracing'\n"); |
| 4047 | return NULL; |
| 4048 | } |
| 4049 | |
| 4050 | return d_tracer; |
| 4051 | } |
| 4052 | |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 4053 | static struct dentry *d_percpu; |
| 4054 | |
| 4055 | struct dentry *tracing_dentry_percpu(void) |
| 4056 | { |
| 4057 | static int once; |
| 4058 | struct dentry *d_tracer; |
| 4059 | |
| 4060 | if (d_percpu) |
| 4061 | return d_percpu; |
| 4062 | |
| 4063 | d_tracer = tracing_init_dentry(); |
| 4064 | |
| 4065 | if (!d_tracer) |
| 4066 | return NULL; |
| 4067 | |
| 4068 | d_percpu = debugfs_create_dir("per_cpu", d_tracer); |
| 4069 | |
| 4070 | if (!d_percpu && !once) { |
| 4071 | once = 1; |
| 4072 | pr_warning("Could not create debugfs directory 'per_cpu'\n"); |
| 4073 | return NULL; |
| 4074 | } |
| 4075 | |
| 4076 | return d_percpu; |
| 4077 | } |
| 4078 | |
| 4079 | static void tracing_init_debugfs_percpu(long cpu) |
| 4080 | { |
| 4081 | struct dentry *d_percpu = tracing_dentry_percpu(); |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 4082 | struct dentry *d_cpu; |
Steven Rostedt | dd49a38 | 2010-10-20 21:51:26 -0400 | [diff] [blame] | 4083 | char cpu_dir[30]; /* 30 characters should be more than enough */ |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 4084 | |
Steven Rostedt | dd49a38 | 2010-10-20 21:51:26 -0400 | [diff] [blame] | 4085 | snprintf(cpu_dir, 30, "cpu%ld", cpu); |
Frederic Weisbecker | 8656e7a | 2009-02-26 00:41:38 +0100 | [diff] [blame] | 4086 | d_cpu = debugfs_create_dir(cpu_dir, d_percpu); |
| 4087 | if (!d_cpu) { |
| 4088 | pr_warning("Could not create debugfs '%s' entry\n", cpu_dir); |
| 4089 | return; |
| 4090 | } |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 4091 | |
Frederic Weisbecker | 8656e7a | 2009-02-26 00:41:38 +0100 | [diff] [blame] | 4092 | /* per cpu trace_pipe */ |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 4093 | trace_create_file("trace_pipe", 0444, d_cpu, |
| 4094 | (void *) cpu, &tracing_pipe_fops); |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 4095 | |
| 4096 | /* per cpu trace */ |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 4097 | trace_create_file("trace", 0644, d_cpu, |
| 4098 | (void *) cpu, &tracing_fops); |
Steven Rostedt | 7f96f93 | 2009-03-13 00:37:42 -0400 | [diff] [blame] | 4099 | |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 4100 | trace_create_file("trace_pipe_raw", 0444, d_cpu, |
| 4101 | (void *) cpu, &tracing_buffers_fops); |
Steven Rostedt | c8d7718 | 2009-04-29 18:03:45 -0400 | [diff] [blame] | 4102 | |
| 4103 | trace_create_file("stats", 0444, d_cpu, |
| 4104 | (void *) cpu, &tracing_stats_fops); |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 4105 | } |
| 4106 | |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 4107 | #ifdef CONFIG_FTRACE_SELFTEST |
| 4108 | /* Let selftest have access to static functions in this file */ |
| 4109 | #include "trace_selftest.c" |
| 4110 | #endif |
| 4111 | |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 4112 | struct trace_option_dentry { |
| 4113 | struct tracer_opt *opt; |
| 4114 | struct tracer_flags *flags; |
| 4115 | struct dentry *entry; |
| 4116 | }; |
| 4117 | |
| 4118 | static ssize_t |
| 4119 | trace_options_read(struct file *filp, char __user *ubuf, size_t cnt, |
| 4120 | loff_t *ppos) |
| 4121 | { |
| 4122 | struct trace_option_dentry *topt = filp->private_data; |
| 4123 | char *buf; |
| 4124 | |
| 4125 | if (topt->flags->val & topt->opt->bit) |
| 4126 | buf = "1\n"; |
| 4127 | else |
| 4128 | buf = "0\n"; |
| 4129 | |
| 4130 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, 2); |
| 4131 | } |
| 4132 | |
| 4133 | static ssize_t |
| 4134 | trace_options_write(struct file *filp, const char __user *ubuf, size_t cnt, |
| 4135 | loff_t *ppos) |
| 4136 | { |
| 4137 | struct trace_option_dentry *topt = filp->private_data; |
| 4138 | unsigned long val; |
| 4139 | char buf[64]; |
| 4140 | int ret; |
| 4141 | |
| 4142 | if (cnt >= sizeof(buf)) |
| 4143 | return -EINVAL; |
| 4144 | |
| 4145 | if (copy_from_user(&buf, ubuf, cnt)) |
| 4146 | return -EFAULT; |
| 4147 | |
| 4148 | buf[cnt] = 0; |
| 4149 | |
| 4150 | ret = strict_strtoul(buf, 10, &val); |
| 4151 | if (ret < 0) |
| 4152 | return ret; |
| 4153 | |
Li Zefan | 8d18eaa | 2009-12-08 11:17:06 +0800 | [diff] [blame] | 4154 | if (val != 0 && val != 1) |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 4155 | return -EINVAL; |
Li Zefan | 8d18eaa | 2009-12-08 11:17:06 +0800 | [diff] [blame] | 4156 | |
| 4157 | if (!!(topt->flags->val & topt->opt->bit) != val) { |
| 4158 | mutex_lock(&trace_types_lock); |
| 4159 | ret = __set_tracer_option(current_trace, topt->flags, |
Steven Rostedt | c757bea | 2009-12-21 22:35:16 -0500 | [diff] [blame] | 4160 | topt->opt, !val); |
Li Zefan | 8d18eaa | 2009-12-08 11:17:06 +0800 | [diff] [blame] | 4161 | mutex_unlock(&trace_types_lock); |
| 4162 | if (ret) |
| 4163 | return ret; |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 4164 | } |
| 4165 | |
| 4166 | *ppos += cnt; |
| 4167 | |
| 4168 | return cnt; |
| 4169 | } |
| 4170 | |
| 4171 | |
| 4172 | static const struct file_operations trace_options_fops = { |
| 4173 | .open = tracing_open_generic, |
| 4174 | .read = trace_options_read, |
| 4175 | .write = trace_options_write, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 4176 | .llseek = generic_file_llseek, |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 4177 | }; |
| 4178 | |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 4179 | static ssize_t |
| 4180 | trace_options_core_read(struct file *filp, char __user *ubuf, size_t cnt, |
| 4181 | loff_t *ppos) |
| 4182 | { |
| 4183 | long index = (long)filp->private_data; |
| 4184 | char *buf; |
| 4185 | |
| 4186 | if (trace_flags & (1 << index)) |
| 4187 | buf = "1\n"; |
| 4188 | else |
| 4189 | buf = "0\n"; |
| 4190 | |
| 4191 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, 2); |
| 4192 | } |
| 4193 | |
| 4194 | static ssize_t |
| 4195 | trace_options_core_write(struct file *filp, const char __user *ubuf, size_t cnt, |
| 4196 | loff_t *ppos) |
| 4197 | { |
| 4198 | long index = (long)filp->private_data; |
| 4199 | char buf[64]; |
| 4200 | unsigned long val; |
| 4201 | int ret; |
| 4202 | |
| 4203 | if (cnt >= sizeof(buf)) |
| 4204 | return -EINVAL; |
| 4205 | |
| 4206 | if (copy_from_user(&buf, ubuf, cnt)) |
| 4207 | return -EFAULT; |
| 4208 | |
| 4209 | buf[cnt] = 0; |
| 4210 | |
| 4211 | ret = strict_strtoul(buf, 10, &val); |
| 4212 | if (ret < 0) |
| 4213 | return ret; |
| 4214 | |
Zhaolei | f2d84b6 | 2009-08-07 18:55:48 +0800 | [diff] [blame] | 4215 | if (val != 0 && val != 1) |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 4216 | return -EINVAL; |
Zhaolei | f2d84b6 | 2009-08-07 18:55:48 +0800 | [diff] [blame] | 4217 | set_tracer_flags(1 << index, val); |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 4218 | |
| 4219 | *ppos += cnt; |
| 4220 | |
| 4221 | return cnt; |
| 4222 | } |
| 4223 | |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 4224 | static const struct file_operations trace_options_core_fops = { |
| 4225 | .open = tracing_open_generic, |
| 4226 | .read = trace_options_core_read, |
| 4227 | .write = trace_options_core_write, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 4228 | .llseek = generic_file_llseek, |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 4229 | }; |
| 4230 | |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 4231 | struct dentry *trace_create_file(const char *name, |
| 4232 | mode_t mode, |
| 4233 | struct dentry *parent, |
| 4234 | void *data, |
| 4235 | const struct file_operations *fops) |
| 4236 | { |
| 4237 | struct dentry *ret; |
| 4238 | |
| 4239 | ret = debugfs_create_file(name, mode, parent, data, fops); |
| 4240 | if (!ret) |
| 4241 | pr_warning("Could not create debugfs '%s' entry\n", name); |
| 4242 | |
| 4243 | return ret; |
| 4244 | } |
| 4245 | |
| 4246 | |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 4247 | static struct dentry *trace_options_init_dentry(void) |
| 4248 | { |
| 4249 | struct dentry *d_tracer; |
| 4250 | static struct dentry *t_options; |
| 4251 | |
| 4252 | if (t_options) |
| 4253 | return t_options; |
| 4254 | |
| 4255 | d_tracer = tracing_init_dentry(); |
| 4256 | if (!d_tracer) |
| 4257 | return NULL; |
| 4258 | |
| 4259 | t_options = debugfs_create_dir("options", d_tracer); |
| 4260 | if (!t_options) { |
| 4261 | pr_warning("Could not create debugfs directory 'options'\n"); |
| 4262 | return NULL; |
| 4263 | } |
| 4264 | |
| 4265 | return t_options; |
| 4266 | } |
| 4267 | |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 4268 | static void |
| 4269 | create_trace_option_file(struct trace_option_dentry *topt, |
| 4270 | struct tracer_flags *flags, |
| 4271 | struct tracer_opt *opt) |
| 4272 | { |
| 4273 | struct dentry *t_options; |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 4274 | |
| 4275 | t_options = trace_options_init_dentry(); |
| 4276 | if (!t_options) |
| 4277 | return; |
| 4278 | |
| 4279 | topt->flags = flags; |
| 4280 | topt->opt = opt; |
| 4281 | |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 4282 | topt->entry = trace_create_file(opt->name, 0644, t_options, topt, |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 4283 | &trace_options_fops); |
| 4284 | |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 4285 | } |
| 4286 | |
| 4287 | static struct trace_option_dentry * |
| 4288 | create_trace_option_files(struct tracer *tracer) |
| 4289 | { |
| 4290 | struct trace_option_dentry *topts; |
| 4291 | struct tracer_flags *flags; |
| 4292 | struct tracer_opt *opts; |
| 4293 | int cnt; |
| 4294 | |
| 4295 | if (!tracer) |
| 4296 | return NULL; |
| 4297 | |
| 4298 | flags = tracer->flags; |
| 4299 | |
| 4300 | if (!flags || !flags->opts) |
| 4301 | return NULL; |
| 4302 | |
| 4303 | opts = flags->opts; |
| 4304 | |
| 4305 | for (cnt = 0; opts[cnt].name; cnt++) |
| 4306 | ; |
| 4307 | |
Steven Rostedt | 0cfe824 | 2009-02-27 10:51:10 -0500 | [diff] [blame] | 4308 | topts = kcalloc(cnt + 1, sizeof(*topts), GFP_KERNEL); |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 4309 | if (!topts) |
| 4310 | return NULL; |
| 4311 | |
| 4312 | for (cnt = 0; opts[cnt].name; cnt++) |
| 4313 | create_trace_option_file(&topts[cnt], flags, |
| 4314 | &opts[cnt]); |
| 4315 | |
| 4316 | return topts; |
| 4317 | } |
| 4318 | |
| 4319 | static void |
| 4320 | destroy_trace_option_files(struct trace_option_dentry *topts) |
| 4321 | { |
| 4322 | int cnt; |
| 4323 | |
| 4324 | if (!topts) |
| 4325 | return; |
| 4326 | |
| 4327 | for (cnt = 0; topts[cnt].opt; cnt++) { |
| 4328 | if (topts[cnt].entry) |
| 4329 | debugfs_remove(topts[cnt].entry); |
| 4330 | } |
| 4331 | |
| 4332 | kfree(topts); |
| 4333 | } |
| 4334 | |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 4335 | static struct dentry * |
| 4336 | create_trace_option_core_file(const char *option, long index) |
| 4337 | { |
| 4338 | struct dentry *t_options; |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 4339 | |
| 4340 | t_options = trace_options_init_dentry(); |
| 4341 | if (!t_options) |
| 4342 | return NULL; |
| 4343 | |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 4344 | return trace_create_file(option, 0644, t_options, (void *)index, |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 4345 | &trace_options_core_fops); |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 4346 | } |
| 4347 | |
| 4348 | static __init void create_trace_options_dir(void) |
| 4349 | { |
| 4350 | struct dentry *t_options; |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 4351 | int i; |
| 4352 | |
| 4353 | t_options = trace_options_init_dentry(); |
| 4354 | if (!t_options) |
| 4355 | return; |
| 4356 | |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 4357 | for (i = 0; trace_options[i]; i++) |
| 4358 | create_trace_option_core_file(trace_options[i], i); |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 4359 | } |
| 4360 | |
Frédéric Weisbecker | b5ad384 | 2008-09-23 11:34:32 +0100 | [diff] [blame] | 4361 | static __init int tracer_init_debugfs(void) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4362 | { |
| 4363 | struct dentry *d_tracer; |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 4364 | int cpu; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4365 | |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 4366 | trace_access_lock_init(); |
| 4367 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4368 | d_tracer = tracing_init_dentry(); |
| 4369 | |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 4370 | trace_create_file("tracing_enabled", 0644, d_tracer, |
| 4371 | &global_trace, &tracing_ctrl_fops); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4372 | |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 4373 | trace_create_file("trace_options", 0644, d_tracer, |
| 4374 | NULL, &tracing_iter_fops); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4375 | |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 4376 | trace_create_file("tracing_cpumask", 0644, d_tracer, |
| 4377 | NULL, &tracing_cpumask_fops); |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 4378 | |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 4379 | trace_create_file("trace", 0644, d_tracer, |
| 4380 | (void *) TRACE_PIPE_ALL_CPU, &tracing_fops); |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 4381 | |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 4382 | trace_create_file("available_tracers", 0444, d_tracer, |
| 4383 | &global_trace, &show_traces_fops); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4384 | |
Li Zefan | 339ae5d | 2009-04-17 10:34:30 +0800 | [diff] [blame] | 4385 | trace_create_file("current_tracer", 0644, d_tracer, |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 4386 | &global_trace, &set_tracer_fops); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4387 | |
Steven Rostedt | 5d4a9db | 2009-08-27 16:52:21 -0400 | [diff] [blame] | 4388 | #ifdef CONFIG_TRACER_MAX_TRACE |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 4389 | trace_create_file("tracing_max_latency", 0644, d_tracer, |
| 4390 | &tracing_max_latency, &tracing_max_lat_fops); |
Tim Bird | 0e95017 | 2010-02-25 15:36:43 -0800 | [diff] [blame] | 4391 | #endif |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4392 | |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 4393 | trace_create_file("tracing_thresh", 0644, d_tracer, |
| 4394 | &tracing_thresh, &tracing_max_lat_fops); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4395 | |
Li Zefan | 339ae5d | 2009-04-17 10:34:30 +0800 | [diff] [blame] | 4396 | trace_create_file("README", 0444, d_tracer, |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 4397 | NULL, &tracing_readme_fops); |
Ingo Molnar | 7bd2f24 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 4398 | |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 4399 | trace_create_file("trace_pipe", 0444, d_tracer, |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 4400 | (void *) TRACE_PIPE_ALL_CPU, &tracing_pipe_fops); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4401 | |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 4402 | trace_create_file("buffer_size_kb", 0644, d_tracer, |
| 4403 | &global_trace, &tracing_entries_fops); |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 4404 | |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 4405 | trace_create_file("free_buffer", 0644, d_tracer, |
| 4406 | &global_trace, &tracing_free_buffer_fops); |
| 4407 | |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 4408 | trace_create_file("trace_marker", 0220, d_tracer, |
| 4409 | NULL, &tracing_mark_fops); |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 4410 | |
Avadh Patel | 69abe6a | 2009-04-10 16:04:48 -0400 | [diff] [blame] | 4411 | trace_create_file("saved_cmdlines", 0444, d_tracer, |
| 4412 | NULL, &tracing_saved_cmdlines_fops); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4413 | |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 4414 | trace_create_file("trace_clock", 0644, d_tracer, NULL, |
| 4415 | &trace_clock_fops); |
| 4416 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4417 | #ifdef CONFIG_DYNAMIC_FTRACE |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 4418 | trace_create_file("dyn_ftrace_total_info", 0444, d_tracer, |
| 4419 | &ftrace_update_tot_cnt, &tracing_dyn_info_fops); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4420 | #endif |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 4421 | |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 4422 | create_trace_options_dir(); |
| 4423 | |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 4424 | for_each_tracing_cpu(cpu) |
| 4425 | tracing_init_debugfs_percpu(cpu); |
| 4426 | |
Frédéric Weisbecker | b5ad384 | 2008-09-23 11:34:32 +0100 | [diff] [blame] | 4427 | return 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4428 | } |
| 4429 | |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 4430 | static int trace_panic_handler(struct notifier_block *this, |
| 4431 | unsigned long event, void *unused) |
| 4432 | { |
Steven Rostedt | 944ac42 | 2008-10-23 19:26:08 -0400 | [diff] [blame] | 4433 | if (ftrace_dump_on_oops) |
Frederic Weisbecker | cecbca9 | 2010-04-18 19:08:41 +0200 | [diff] [blame] | 4434 | ftrace_dump(ftrace_dump_on_oops); |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 4435 | return NOTIFY_OK; |
| 4436 | } |
| 4437 | |
| 4438 | static struct notifier_block trace_panic_notifier = { |
| 4439 | .notifier_call = trace_panic_handler, |
| 4440 | .next = NULL, |
| 4441 | .priority = 150 /* priority: INT_MAX >= x >= 0 */ |
| 4442 | }; |
| 4443 | |
| 4444 | static int trace_die_handler(struct notifier_block *self, |
| 4445 | unsigned long val, |
| 4446 | void *data) |
| 4447 | { |
| 4448 | switch (val) { |
| 4449 | case DIE_OOPS: |
Steven Rostedt | 944ac42 | 2008-10-23 19:26:08 -0400 | [diff] [blame] | 4450 | if (ftrace_dump_on_oops) |
Frederic Weisbecker | cecbca9 | 2010-04-18 19:08:41 +0200 | [diff] [blame] | 4451 | ftrace_dump(ftrace_dump_on_oops); |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 4452 | break; |
| 4453 | default: |
| 4454 | break; |
| 4455 | } |
| 4456 | return NOTIFY_OK; |
| 4457 | } |
| 4458 | |
| 4459 | static struct notifier_block trace_die_notifier = { |
| 4460 | .notifier_call = trace_die_handler, |
| 4461 | .priority = 200 |
| 4462 | }; |
| 4463 | |
| 4464 | /* |
| 4465 | * printk is set to max of 1024, we really don't need it that big. |
| 4466 | * Nothing should be printing 1000 characters anyway. |
| 4467 | */ |
| 4468 | #define TRACE_MAX_PRINT 1000 |
| 4469 | |
| 4470 | /* |
| 4471 | * Define here KERN_TRACE so that we have one place to modify |
| 4472 | * it if we decide to change what log level the ftrace dump |
| 4473 | * should be at. |
| 4474 | */ |
Steven Rostedt | 428aee1 | 2009-01-14 12:24:42 -0500 | [diff] [blame] | 4475 | #define KERN_TRACE KERN_EMERG |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 4476 | |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 4477 | void |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 4478 | trace_printk_seq(struct trace_seq *s) |
| 4479 | { |
| 4480 | /* Probably should print a warning here. */ |
| 4481 | if (s->len >= 1000) |
| 4482 | s->len = 1000; |
| 4483 | |
| 4484 | /* should be zero ended, but we are paranoid. */ |
| 4485 | s->buffer[s->len] = 0; |
| 4486 | |
| 4487 | printk(KERN_TRACE "%s", s->buffer); |
| 4488 | |
Steven Rostedt | f952075 | 2009-03-02 14:04:40 -0500 | [diff] [blame] | 4489 | trace_seq_init(s); |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 4490 | } |
| 4491 | |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 4492 | void trace_init_global_iter(struct trace_iterator *iter) |
| 4493 | { |
| 4494 | iter->tr = &global_trace; |
| 4495 | iter->trace = current_trace; |
| 4496 | iter->cpu_file = TRACE_PIPE_ALL_CPU; |
| 4497 | } |
| 4498 | |
Frederic Weisbecker | cecbca9 | 2010-04-18 19:08:41 +0200 | [diff] [blame] | 4499 | static void |
| 4500 | __ftrace_dump(bool disable_tracing, enum ftrace_dump_mode oops_dump_mode) |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 4501 | { |
Thomas Gleixner | 445c895 | 2009-12-02 19:49:50 +0100 | [diff] [blame] | 4502 | static arch_spinlock_t ftrace_dump_lock = |
Thomas Gleixner | edc35bd | 2009-12-03 12:38:57 +0100 | [diff] [blame] | 4503 | (arch_spinlock_t)__ARCH_SPIN_LOCK_UNLOCKED; |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 4504 | /* use static because iter can be a bit big for the stack */ |
| 4505 | static struct trace_iterator iter; |
Frederic Weisbecker | cf586b6 | 2009-03-22 05:04:35 +0100 | [diff] [blame] | 4506 | unsigned int old_userobj; |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 4507 | static int dump_ran; |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 4508 | unsigned long flags; |
| 4509 | int cnt = 0, cpu; |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 4510 | |
| 4511 | /* only one dump */ |
Steven Rostedt | cd891ae | 2009-04-28 11:39:34 -0400 | [diff] [blame] | 4512 | local_irq_save(flags); |
Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 4513 | arch_spin_lock(&ftrace_dump_lock); |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 4514 | if (dump_ran) |
| 4515 | goto out; |
| 4516 | |
| 4517 | dump_ran = 1; |
| 4518 | |
Steven Rostedt | 0ee6b6c | 2009-01-14 14:50:19 -0500 | [diff] [blame] | 4519 | tracing_off(); |
Frederic Weisbecker | cf586b6 | 2009-03-22 05:04:35 +0100 | [diff] [blame] | 4520 | |
| 4521 | if (disable_tracing) |
| 4522 | ftrace_kill(); |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 4523 | |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 4524 | trace_init_global_iter(&iter); |
| 4525 | |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 4526 | for_each_tracing_cpu(cpu) { |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 4527 | atomic_inc(&iter.tr->data[cpu]->disabled); |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 4528 | } |
| 4529 | |
Frederic Weisbecker | cf586b6 | 2009-03-22 05:04:35 +0100 | [diff] [blame] | 4530 | old_userobj = trace_flags & TRACE_ITER_SYM_USEROBJ; |
| 4531 | |
Török Edwin | b54d3de | 2008-11-22 13:28:48 +0200 | [diff] [blame] | 4532 | /* don't look at user memory in panic mode */ |
| 4533 | trace_flags &= ~TRACE_ITER_SYM_USEROBJ; |
| 4534 | |
Steven Rostedt | e543ad7 | 2009-03-04 18:20:36 -0500 | [diff] [blame] | 4535 | /* Simulate the iterator */ |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 4536 | iter.tr = &global_trace; |
| 4537 | iter.trace = current_trace; |
Frederic Weisbecker | cecbca9 | 2010-04-18 19:08:41 +0200 | [diff] [blame] | 4538 | |
| 4539 | switch (oops_dump_mode) { |
| 4540 | case DUMP_ALL: |
| 4541 | iter.cpu_file = TRACE_PIPE_ALL_CPU; |
| 4542 | break; |
| 4543 | case DUMP_ORIG: |
| 4544 | iter.cpu_file = raw_smp_processor_id(); |
| 4545 | break; |
| 4546 | case DUMP_NONE: |
| 4547 | goto out_enable; |
| 4548 | default: |
| 4549 | printk(KERN_TRACE "Bad dumping mode, switching to all CPUs dump\n"); |
| 4550 | iter.cpu_file = TRACE_PIPE_ALL_CPU; |
| 4551 | } |
| 4552 | |
| 4553 | printk(KERN_TRACE "Dumping ftrace buffer:\n"); |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 4554 | |
| 4555 | /* |
| 4556 | * We need to stop all tracing on all CPUS to read the |
| 4557 | * the next buffer. This is a bit expensive, but is |
| 4558 | * not done often. We fill all what we can read, |
| 4559 | * and then release the locks again. |
| 4560 | */ |
| 4561 | |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 4562 | while (!trace_empty(&iter)) { |
| 4563 | |
| 4564 | if (!cnt) |
| 4565 | printk(KERN_TRACE "---------------------------------\n"); |
| 4566 | |
| 4567 | cnt++; |
| 4568 | |
| 4569 | /* reset all but tr, trace, and overruns */ |
| 4570 | memset(&iter.seq, 0, |
| 4571 | sizeof(struct trace_iterator) - |
| 4572 | offsetof(struct trace_iterator, seq)); |
| 4573 | iter.iter_flags |= TRACE_FILE_LAT_FMT; |
| 4574 | iter.pos = -1; |
| 4575 | |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 4576 | if (trace_find_next_entry_inc(&iter) != NULL) { |
Lai Jiangshan | 74e7ff8 | 2009-07-28 20:17:22 +0800 | [diff] [blame] | 4577 | int ret; |
| 4578 | |
| 4579 | ret = print_trace_line(&iter); |
| 4580 | if (ret != TRACE_TYPE_NO_CONSUME) |
| 4581 | trace_consume(&iter); |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 4582 | } |
| 4583 | |
| 4584 | trace_printk_seq(&iter.seq); |
| 4585 | } |
| 4586 | |
| 4587 | if (!cnt) |
| 4588 | printk(KERN_TRACE " (ftrace buffer empty)\n"); |
| 4589 | else |
| 4590 | printk(KERN_TRACE "---------------------------------\n"); |
| 4591 | |
Frederic Weisbecker | cecbca9 | 2010-04-18 19:08:41 +0200 | [diff] [blame] | 4592 | out_enable: |
Frederic Weisbecker | cf586b6 | 2009-03-22 05:04:35 +0100 | [diff] [blame] | 4593 | /* Re-enable tracing if requested */ |
| 4594 | if (!disable_tracing) { |
| 4595 | trace_flags |= old_userobj; |
| 4596 | |
| 4597 | for_each_tracing_cpu(cpu) { |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 4598 | atomic_dec(&iter.tr->data[cpu]->disabled); |
Frederic Weisbecker | cf586b6 | 2009-03-22 05:04:35 +0100 | [diff] [blame] | 4599 | } |
| 4600 | tracing_on(); |
| 4601 | } |
| 4602 | |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 4603 | out: |
Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 4604 | arch_spin_unlock(&ftrace_dump_lock); |
Steven Rostedt | cd891ae | 2009-04-28 11:39:34 -0400 | [diff] [blame] | 4605 | local_irq_restore(flags); |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 4606 | } |
| 4607 | |
Frederic Weisbecker | cf586b6 | 2009-03-22 05:04:35 +0100 | [diff] [blame] | 4608 | /* By default: disable tracing after the dump */ |
Frederic Weisbecker | cecbca9 | 2010-04-18 19:08:41 +0200 | [diff] [blame] | 4609 | void ftrace_dump(enum ftrace_dump_mode oops_dump_mode) |
Frederic Weisbecker | cf586b6 | 2009-03-22 05:04:35 +0100 | [diff] [blame] | 4610 | { |
Frederic Weisbecker | cecbca9 | 2010-04-18 19:08:41 +0200 | [diff] [blame] | 4611 | __ftrace_dump(true, oops_dump_mode); |
Frederic Weisbecker | cf586b6 | 2009-03-22 05:04:35 +0100 | [diff] [blame] | 4612 | } |
| 4613 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4614 | __init static int tracer_alloc_buffers(void) |
| 4615 | { |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 4616 | int ring_buf_size; |
David Sharp | 750912f | 2010-12-08 13:46:47 -0800 | [diff] [blame] | 4617 | enum ring_buffer_flags rb_flags; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4618 | int i; |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 4619 | int ret = -ENOMEM; |
| 4620 | |
David Sharp | 750912f | 2010-12-08 13:46:47 -0800 | [diff] [blame] | 4621 | |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 4622 | if (!alloc_cpumask_var(&tracing_buffer_mask, GFP_KERNEL)) |
| 4623 | goto out; |
| 4624 | |
| 4625 | if (!alloc_cpumask_var(&tracing_cpumask, GFP_KERNEL)) |
| 4626 | goto out_free_buffer_mask; |
| 4627 | |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 4628 | /* To save memory, keep the ring buffer size to its minimum */ |
| 4629 | if (ring_buffer_expanded) |
| 4630 | ring_buf_size = trace_buf_size; |
| 4631 | else |
| 4632 | ring_buf_size = 1; |
| 4633 | |
David Sharp | 750912f | 2010-12-08 13:46:47 -0800 | [diff] [blame] | 4634 | rb_flags = trace_flags & TRACE_ITER_OVERWRITE ? RB_FL_OVERWRITE : 0; |
| 4635 | |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 4636 | cpumask_copy(tracing_buffer_mask, cpu_possible_mask); |
| 4637 | cpumask_copy(tracing_cpumask, cpu_all_mask); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4638 | |
Steven Rostedt | ab46428 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 4639 | /* TODO: make the number of buffers hot pluggable with CPUS */ |
David Sharp | 750912f | 2010-12-08 13:46:47 -0800 | [diff] [blame] | 4640 | global_trace.buffer = ring_buffer_alloc(ring_buf_size, rb_flags); |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 4641 | if (!global_trace.buffer) { |
| 4642 | printk(KERN_ERR "tracer: failed to allocate ring buffer!\n"); |
| 4643 | WARN_ON(1); |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 4644 | goto out_free_cpumask; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 4645 | } |
| 4646 | global_trace.entries = ring_buffer_size(global_trace.buffer); |
| 4647 | |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 4648 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 4649 | #ifdef CONFIG_TRACER_MAX_TRACE |
David Sharp | 750912f | 2010-12-08 13:46:47 -0800 | [diff] [blame] | 4650 | max_tr.buffer = ring_buffer_alloc(1, rb_flags); |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 4651 | if (!max_tr.buffer) { |
| 4652 | printk(KERN_ERR "tracer: failed to allocate max ring buffer!\n"); |
| 4653 | WARN_ON(1); |
| 4654 | ring_buffer_free(global_trace.buffer); |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 4655 | goto out_free_cpumask; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 4656 | } |
KOSAKI Motohiro | ef710e1 | 2010-07-01 14:34:35 +0900 | [diff] [blame] | 4657 | max_tr.entries = 1; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 4658 | #endif |
| 4659 | |
Steven Rostedt | 4c11d7a | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 4660 | /* Allocate the first page for all buffers */ |
Steven Rostedt | ab46428 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 4661 | for_each_tracing_cpu(i) { |
jolsa@redhat.com | 566b0aa | 2009-07-16 21:44:26 +0200 | [diff] [blame] | 4662 | global_trace.data[i] = &per_cpu(global_trace_cpu, i); |
Tejun Heo | 9705f69 | 2009-10-29 22:34:13 +0900 | [diff] [blame] | 4663 | max_tr.data[i] = &per_cpu(max_tr_data, i); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4664 | } |
| 4665 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4666 | trace_init_cmdlines(); |
| 4667 | |
Frédéric Weisbecker | 43a1538 | 2008-09-21 20:16:30 +0200 | [diff] [blame] | 4668 | register_tracer(&nop_trace); |
Steven Rostedt | 79fb0768f | 2009-02-02 21:38:33 -0500 | [diff] [blame] | 4669 | current_trace = &nop_trace; |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 4670 | /* All seems OK, enable tracing */ |
| 4671 | tracing_disabled = 0; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 4672 | |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 4673 | atomic_notifier_chain_register(&panic_notifier_list, |
| 4674 | &trace_panic_notifier); |
| 4675 | |
| 4676 | register_die_notifier(&trace_die_notifier); |
Frederic Weisbecker | 2fc1dfb | 2009-03-16 01:45:03 +0100 | [diff] [blame] | 4677 | |
| 4678 | return 0; |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 4679 | |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 4680 | out_free_cpumask: |
| 4681 | free_cpumask_var(tracing_cpumask); |
| 4682 | out_free_buffer_mask: |
| 4683 | free_cpumask_var(tracing_buffer_mask); |
| 4684 | out: |
| 4685 | return ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4686 | } |
Steven Rostedt | b2821ae | 2009-02-02 21:38:32 -0500 | [diff] [blame] | 4687 | |
| 4688 | __init static int clear_boot_tracer(void) |
| 4689 | { |
| 4690 | /* |
| 4691 | * The default tracer at boot buffer is an init section. |
| 4692 | * This function is called in lateinit. If we did not |
| 4693 | * find the boot tracer, then clear it out, to prevent |
| 4694 | * later registration from accessing the buffer that is |
| 4695 | * about to be freed. |
| 4696 | */ |
| 4697 | if (!default_bootup_tracer) |
| 4698 | return 0; |
| 4699 | |
| 4700 | printk(KERN_INFO "ftrace bootup tracer '%s' not registered.\n", |
| 4701 | default_bootup_tracer); |
| 4702 | default_bootup_tracer = NULL; |
| 4703 | |
| 4704 | return 0; |
| 4705 | } |
| 4706 | |
Frédéric Weisbecker | b5ad384 | 2008-09-23 11:34:32 +0100 | [diff] [blame] | 4707 | early_initcall(tracer_alloc_buffers); |
| 4708 | fs_initcall(tracer_init_debugfs); |
Steven Rostedt | b2821ae | 2009-02-02 21:38:32 -0500 | [diff] [blame] | 4709 | late_initcall(clear_boot_tracer); |