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