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