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