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 | */ |
| 14 | #include <linux/utsrelease.h> |
| 15 | #include <linux/kallsyms.h> |
| 16 | #include <linux/seq_file.h> |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 17 | #include <linux/notifier.h> |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 18 | #include <linux/debugfs.h> |
Steven Rostedt | 4c11d7a | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 19 | #include <linux/pagemap.h> |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 20 | #include <linux/hardirq.h> |
| 21 | #include <linux/linkage.h> |
| 22 | #include <linux/uaccess.h> |
| 23 | #include <linux/ftrace.h> |
| 24 | #include <linux/module.h> |
| 25 | #include <linux/percpu.h> |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 26 | #include <linux/kdebug.h> |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 27 | #include <linux/ctype.h> |
| 28 | #include <linux/init.h> |
Soeren Sandmann Pedersen | 2a2cc8f | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 29 | #include <linux/poll.h> |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 30 | #include <linux/gfp.h> |
| 31 | #include <linux/fs.h> |
Abhishek Sagar | 76094a2 | 2008-05-28 00:03:18 +0530 | [diff] [blame] | 32 | #include <linux/kprobes.h> |
Steven Rostedt | 3eefae9 | 2008-05-12 21:21:04 +0200 | [diff] [blame] | 33 | #include <linux/writeback.h> |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 34 | |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 35 | #include <linux/stacktrace.h> |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 36 | #include <linux/ring_buffer.h> |
Frederic Weisbecker | 21798a8 | 2008-10-28 09:43:26 +0100 | [diff] [blame] | 37 | #include <linux/irqflags.h> |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 38 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 39 | #include "trace.h" |
| 40 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 41 | #define TRACE_BUFFER_FLAGS (RB_FL_OVERWRITE) |
| 42 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 43 | unsigned long __read_mostly tracing_max_latency = (cycle_t)ULONG_MAX; |
| 44 | unsigned long __read_mostly tracing_thresh; |
| 45 | |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 46 | |
| 47 | /* |
| 48 | * Kill all tracing for good (never come back). |
| 49 | * It is initialized to 1 but will turn to zero if the initialization |
| 50 | * of the tracer is successful. But that is the only place that sets |
| 51 | * this back to zero. |
| 52 | */ |
| 53 | int tracing_disabled = 1; |
| 54 | |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 55 | static DEFINE_PER_CPU(local_t, ftrace_cpu_disabled); |
| 56 | |
| 57 | static inline void ftrace_disable_cpu(void) |
| 58 | { |
| 59 | preempt_disable(); |
| 60 | local_inc(&__get_cpu_var(ftrace_cpu_disabled)); |
| 61 | } |
| 62 | |
| 63 | static inline void ftrace_enable_cpu(void) |
| 64 | { |
| 65 | local_dec(&__get_cpu_var(ftrace_cpu_disabled)); |
| 66 | preempt_enable(); |
| 67 | } |
| 68 | |
Steven Rostedt | ab46428 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 69 | static cpumask_t __read_mostly tracing_buffer_mask; |
| 70 | |
| 71 | #define for_each_tracing_cpu(cpu) \ |
| 72 | for_each_cpu_mask(cpu, tracing_buffer_mask) |
| 73 | |
Steven Rostedt | 944ac42 | 2008-10-23 19:26:08 -0400 | [diff] [blame] | 74 | /* |
| 75 | * ftrace_dump_on_oops - variable to dump ftrace buffer on oops |
| 76 | * |
| 77 | * If there is an oops (or kernel panic) and the ftrace_dump_on_oops |
| 78 | * is set, then ftrace_dump is called. This will output the contents |
| 79 | * of the ftrace buffers to the console. This is very useful for |
| 80 | * capturing traces that lead to crashes and outputing it to a |
| 81 | * serial console. |
| 82 | * |
| 83 | * It is default off, but you can enable it with either specifying |
| 84 | * "ftrace_dump_on_oops" in the kernel command line, or setting |
| 85 | * /proc/sys/kernel/ftrace_dump_on_oops to true. |
| 86 | */ |
| 87 | int ftrace_dump_on_oops; |
| 88 | |
Peter Zijlstra | d9e5407 | 2008-11-01 19:57:37 +0100 | [diff] [blame] | 89 | static int tracing_set_tracer(char *buf); |
| 90 | |
| 91 | static int __init set_ftrace(char *str) |
| 92 | { |
| 93 | tracing_set_tracer(str); |
| 94 | return 1; |
| 95 | } |
| 96 | __setup("ftrace", set_ftrace); |
| 97 | |
Steven Rostedt | 944ac42 | 2008-10-23 19:26:08 -0400 | [diff] [blame] | 98 | static int __init set_ftrace_dump_on_oops(char *str) |
| 99 | { |
| 100 | ftrace_dump_on_oops = 1; |
| 101 | return 1; |
| 102 | } |
| 103 | __setup("ftrace_dump_on_oops", set_ftrace_dump_on_oops); |
| 104 | |
Thomas Gleixner | 72829bc | 2008-05-23 21:37:28 +0200 | [diff] [blame] | 105 | long |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 106 | ns2usecs(cycle_t nsec) |
| 107 | { |
| 108 | nsec += 500; |
| 109 | do_div(nsec, 1000); |
| 110 | return nsec; |
| 111 | } |
| 112 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 113 | cycle_t ftrace_now(int cpu) |
Ingo Molnar | 750ed1a | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 114 | { |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 115 | u64 ts = ring_buffer_time_stamp(cpu); |
| 116 | ring_buffer_normalize_time_stamp(cpu, &ts); |
| 117 | return ts; |
Ingo Molnar | 750ed1a | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 118 | } |
| 119 | |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 120 | /* |
| 121 | * The global_trace is the descriptor that holds the tracing |
| 122 | * buffers for the live tracing. For each CPU, it contains |
| 123 | * a link list of pages that will store trace entries. The |
| 124 | * page descriptor of the pages in the memory is used to hold |
| 125 | * the link list by linking the lru item in the page descriptor |
| 126 | * to each of the pages in the buffer per CPU. |
| 127 | * |
| 128 | * For each active CPU there is a data field that holds the |
| 129 | * pages for the buffer for that CPU. Each CPU has the same number |
| 130 | * of pages allocated for its buffer. |
| 131 | */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 132 | static struct trace_array global_trace; |
| 133 | |
| 134 | static DEFINE_PER_CPU(struct trace_array_cpu, global_trace_cpu); |
| 135 | |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 136 | /* |
| 137 | * The max_tr is used to snapshot the global_trace when a maximum |
| 138 | * latency is reached. Some tracers will use this to store a maximum |
| 139 | * trace while it continues examining live traces. |
| 140 | * |
| 141 | * The buffers for the max_tr are set up the same as the global_trace. |
| 142 | * When a snapshot is taken, the link list of the max_tr is swapped |
| 143 | * with the link list of the global_trace and the buffers are reset for |
| 144 | * the global_trace so the tracing can continue. |
| 145 | */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 146 | static struct trace_array max_tr; |
| 147 | |
| 148 | static DEFINE_PER_CPU(struct trace_array_cpu, max_data); |
| 149 | |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 150 | /* tracer_enabled is used to toggle activation of a tracer */ |
Steven Rostedt | 26994ea | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 151 | static int tracer_enabled = 1; |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 152 | |
Steven Rostedt | 9036990 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 153 | /** |
| 154 | * tracing_is_enabled - return tracer_enabled status |
| 155 | * |
| 156 | * This function is used by other tracers to know the status |
| 157 | * of the tracer_enabled flag. Tracers may use this function |
| 158 | * to know if it should enable their features when starting |
| 159 | * up. See irqsoff tracer for an example (start_irqsoff_tracer). |
| 160 | */ |
| 161 | int tracing_is_enabled(void) |
| 162 | { |
| 163 | return tracer_enabled; |
| 164 | } |
| 165 | |
Steven Rostedt | 60bc080 | 2008-07-10 20:58:16 -0400 | [diff] [blame] | 166 | /* function tracing enabled */ |
| 167 | int ftrace_function_enabled; |
| 168 | |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 169 | /* |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 170 | * trace_buf_size is the size in bytes that is allocated |
| 171 | * for a buffer. Note, the number of bytes is always rounded |
| 172 | * to page size. |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 173 | * |
| 174 | * This number is purposely set to a low number of 16384. |
| 175 | * If the dump on oops happens, it will be much appreciated |
| 176 | * to not have to wait for all that output. Anyway this can be |
| 177 | * boot time and run time configurable. |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 178 | */ |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 179 | #define TRACE_BUF_SIZE_DEFAULT 1441792UL /* 16384 * 88 (sizeof(entry)) */ |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 180 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 181 | static unsigned long trace_buf_size = TRACE_BUF_SIZE_DEFAULT; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 182 | |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 183 | /* trace_types holds a link list of available tracers. */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 184 | static struct tracer *trace_types __read_mostly; |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 185 | |
| 186 | /* current_trace points to the tracer that is currently active */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 187 | static struct tracer *current_trace __read_mostly; |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 188 | |
| 189 | /* |
| 190 | * max_tracer_type_len is used to simplify the allocating of |
| 191 | * buffers to read userspace tracer names. We keep track of |
| 192 | * the longest tracer name registered. |
| 193 | */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 194 | static int max_tracer_type_len; |
| 195 | |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 196 | /* |
| 197 | * trace_types_lock is used to protect the trace_types list. |
| 198 | * This lock is also used to keep user access serialized. |
| 199 | * Accesses from userspace will grab this lock while userspace |
| 200 | * activities happen inside the kernel. |
| 201 | */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 202 | static DEFINE_MUTEX(trace_types_lock); |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 203 | |
| 204 | /* trace_wait is a waitqueue for tasks blocked on trace_poll */ |
Ingo Molnar | 4e65551 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 205 | static DECLARE_WAIT_QUEUE_HEAD(trace_wait); |
| 206 | |
Steven Rostedt | ee6bce5 | 2008-11-12 17:52:37 -0500 | [diff] [blame] | 207 | /* trace_flags holds trace_options default values */ |
Steven Rostedt | 12ef7d4 | 2008-11-12 17:52:38 -0500 | [diff] [blame] | 208 | unsigned long trace_flags = TRACE_ITER_PRINT_PARENT | TRACE_ITER_PRINTK | |
| 209 | TRACE_ITER_ANNOTATE; |
Ingo Molnar | 4e65551 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 210 | |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 211 | /** |
| 212 | * trace_wake_up - wake up tasks waiting for trace input |
| 213 | * |
| 214 | * Simply wakes up any task that is blocked on the trace_wait |
| 215 | * queue. These is used with trace_poll for tasks polling the trace. |
| 216 | */ |
Ingo Molnar | 4e65551 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 217 | void trace_wake_up(void) |
| 218 | { |
Ingo Molnar | 017730c | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 219 | /* |
| 220 | * The runqueue_is_locked() can fail, but this is the best we |
| 221 | * have for now: |
| 222 | */ |
| 223 | if (!(trace_flags & TRACE_ITER_BLOCK) && !runqueue_is_locked()) |
Ingo Molnar | 4e65551 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 224 | wake_up(&trace_wait); |
| 225 | } |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 226 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 227 | static int __init set_buf_size(char *str) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 228 | { |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 229 | unsigned long buf_size; |
Steven Rostedt | c6caeeb | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 230 | int ret; |
| 231 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 232 | if (!str) |
| 233 | return 0; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 234 | ret = strict_strtoul(str, 0, &buf_size); |
Steven Rostedt | c6caeeb | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 235 | /* nr_entries can not be zero */ |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 236 | if (ret < 0 || buf_size == 0) |
Steven Rostedt | c6caeeb | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 237 | return 0; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 238 | trace_buf_size = buf_size; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 239 | return 1; |
| 240 | } |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 241 | __setup("trace_buf_size=", set_buf_size); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 242 | |
Steven Rostedt | 57f50be | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 243 | unsigned long nsecs_to_usecs(unsigned long nsecs) |
| 244 | { |
| 245 | return nsecs / 1000; |
| 246 | } |
| 247 | |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 248 | /* These must match the bit postions in trace_iterator_flags */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 249 | static const char *trace_options[] = { |
| 250 | "print-parent", |
| 251 | "sym-offset", |
| 252 | "sym-addr", |
| 253 | "verbose", |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 254 | "raw", |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 255 | "hex", |
Ingo Molnar | cb0f12a | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 256 | "bin", |
Soeren Sandmann Pedersen | 2a2cc8f | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 257 | "block", |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 258 | "stacktrace", |
Ingo Molnar | 4ac3ba4 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 259 | "sched-tree", |
Peter Zijlstra | f09ce57 | 2008-09-04 10:24:14 +0200 | [diff] [blame] | 260 | "ftrace_printk", |
Steven Rostedt | b2a866f | 2008-11-03 23:15:57 -0500 | [diff] [blame] | 261 | "ftrace_preempt", |
Steven Rostedt | 2ed84ee | 2008-11-12 15:24:24 -0500 | [diff] [blame] | 262 | #ifdef CONFIG_BRANCH_TRACER |
Steven Rostedt | 9f029e8 | 2008-11-12 15:24:24 -0500 | [diff] [blame] | 263 | "branch", |
Steven Rostedt | 52f232c | 2008-11-12 00:14:40 -0500 | [diff] [blame] | 264 | #endif |
Steven Rostedt | 12ef7d4 | 2008-11-12 17:52:38 -0500 | [diff] [blame] | 265 | "annotate", |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 266 | NULL |
| 267 | }; |
| 268 | |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 269 | /* |
| 270 | * ftrace_max_lock is used to protect the swapping of buffers |
| 271 | * when taking a max snapshot. The buffers themselves are |
| 272 | * protected by per_cpu spinlocks. But the action of the swap |
| 273 | * needs its own lock. |
| 274 | * |
| 275 | * This is defined as a raw_spinlock_t in order to help |
| 276 | * with performance when lockdep debugging is enabled. |
| 277 | */ |
Steven Rostedt | 92205c2 | 2008-05-12 21:20:55 +0200 | [diff] [blame] | 278 | static raw_spinlock_t ftrace_max_lock = |
| 279 | (raw_spinlock_t)__RAW_SPIN_LOCK_UNLOCKED; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 280 | |
| 281 | /* |
| 282 | * Copy the new maximum trace into the separate maximum-trace |
| 283 | * structure. (this way the maximum trace is permanently saved, |
| 284 | * for later retrieval via /debugfs/tracing/latency_trace) |
| 285 | */ |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 286 | static void |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 287 | __update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu) |
| 288 | { |
| 289 | struct trace_array_cpu *data = tr->data[cpu]; |
| 290 | |
| 291 | max_tr.cpu = cpu; |
| 292 | max_tr.time_start = data->preempt_timestamp; |
| 293 | |
| 294 | data = max_tr.data[cpu]; |
| 295 | data->saved_latency = tracing_max_latency; |
| 296 | |
| 297 | memcpy(data->comm, tsk->comm, TASK_COMM_LEN); |
| 298 | data->pid = tsk->pid; |
| 299 | data->uid = tsk->uid; |
| 300 | data->nice = tsk->static_prio - 20 - MAX_RT_PRIO; |
| 301 | data->policy = tsk->policy; |
| 302 | data->rt_priority = tsk->rt_priority; |
| 303 | |
| 304 | /* record this tasks comm */ |
| 305 | tracing_record_cmdline(current); |
| 306 | } |
| 307 | |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 308 | /** |
| 309 | * trace_seq_printf - sequence printing of trace information |
| 310 | * @s: trace sequence descriptor |
| 311 | * @fmt: printf format string |
| 312 | * |
| 313 | * The tracer may use either sequence operations or its own |
| 314 | * copy to user routines. To simplify formating of a trace |
| 315 | * trace_seq_printf is used to store strings into a special |
| 316 | * buffer (@s). Then the output may be either used by |
| 317 | * the sequencer or pulled into another buffer. |
| 318 | */ |
Thomas Gleixner | 72829bc | 2008-05-23 21:37:28 +0200 | [diff] [blame] | 319 | int |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 320 | trace_seq_printf(struct trace_seq *s, const char *fmt, ...) |
| 321 | { |
| 322 | int len = (PAGE_SIZE - 1) - s->len; |
| 323 | va_list ap; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 324 | int ret; |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 325 | |
| 326 | if (!len) |
| 327 | return 0; |
| 328 | |
| 329 | va_start(ap, fmt); |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 330 | ret = vsnprintf(s->buffer + s->len, len, fmt, ap); |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 331 | va_end(ap); |
| 332 | |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 333 | /* If we can't write it all, don't bother writing anything */ |
Thomas Gleixner | 72829bc | 2008-05-23 21:37:28 +0200 | [diff] [blame] | 334 | if (ret >= len) |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 335 | return 0; |
| 336 | |
| 337 | s->len += ret; |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 338 | |
| 339 | return len; |
| 340 | } |
| 341 | |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 342 | /** |
| 343 | * trace_seq_puts - trace sequence printing of simple string |
| 344 | * @s: trace sequence descriptor |
| 345 | * @str: simple string to record |
| 346 | * |
| 347 | * The tracer may use either the sequence operations or its own |
| 348 | * copy to user routines. This function records a simple string |
| 349 | * into a special buffer (@s) for later retrieval by a sequencer |
| 350 | * or other mechanism. |
| 351 | */ |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 352 | static int |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 353 | trace_seq_puts(struct trace_seq *s, const char *str) |
| 354 | { |
| 355 | int len = strlen(str); |
| 356 | |
| 357 | if (len > ((PAGE_SIZE - 1) - s->len)) |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 358 | return 0; |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 359 | |
| 360 | memcpy(s->buffer + s->len, str, len); |
| 361 | s->len += len; |
| 362 | |
| 363 | return len; |
| 364 | } |
| 365 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 366 | static int |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 367 | trace_seq_putc(struct trace_seq *s, unsigned char c) |
| 368 | { |
| 369 | if (s->len >= (PAGE_SIZE - 1)) |
| 370 | return 0; |
| 371 | |
| 372 | s->buffer[s->len++] = c; |
| 373 | |
| 374 | return 1; |
| 375 | } |
| 376 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 377 | static int |
Ingo Molnar | cb0f12a | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 378 | trace_seq_putmem(struct trace_seq *s, void *mem, size_t len) |
| 379 | { |
| 380 | if (len > ((PAGE_SIZE - 1) - s->len)) |
| 381 | return 0; |
| 382 | |
| 383 | memcpy(s->buffer + s->len, mem, len); |
| 384 | s->len += len; |
| 385 | |
| 386 | return len; |
| 387 | } |
| 388 | |
Harvey Harrison | ad0a3b6 | 2008-10-08 17:44:55 -0700 | [diff] [blame] | 389 | #define MAX_MEMHEX_BYTES 8 |
| 390 | #define HEX_CHARS (MAX_MEMHEX_BYTES*2 + 1) |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 391 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 392 | static int |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 393 | trace_seq_putmem_hex(struct trace_seq *s, void *mem, size_t len) |
| 394 | { |
| 395 | unsigned char hex[HEX_CHARS]; |
Thomas Gleixner | 93dcc6e | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 396 | unsigned char *data = mem; |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 397 | int i, j; |
| 398 | |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 399 | #ifdef __BIG_ENDIAN |
| 400 | for (i = 0, j = 0; i < len; i++) { |
| 401 | #else |
| 402 | for (i = len-1, j = 0; i >= 0; i--) { |
| 403 | #endif |
Harvey Harrison | 2fbc474 | 2008-10-08 16:51:49 -0700 | [diff] [blame] | 404 | hex[j++] = hex_asc_hi(data[i]); |
| 405 | hex[j++] = hex_asc_lo(data[i]); |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 406 | } |
Thomas Gleixner | 93dcc6e | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 407 | hex[j++] = ' '; |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 408 | |
| 409 | return trace_seq_putmem(s, hex, j); |
| 410 | } |
| 411 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 412 | static void |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 413 | trace_seq_reset(struct trace_seq *s) |
| 414 | { |
| 415 | s->len = 0; |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 416 | s->readpos = 0; |
| 417 | } |
| 418 | |
| 419 | ssize_t trace_seq_to_user(struct trace_seq *s, char __user *ubuf, size_t cnt) |
| 420 | { |
| 421 | int len; |
| 422 | int ret; |
| 423 | |
| 424 | if (s->len <= s->readpos) |
| 425 | return -EBUSY; |
| 426 | |
| 427 | len = s->len - s->readpos; |
| 428 | if (cnt > len) |
| 429 | cnt = len; |
| 430 | ret = copy_to_user(ubuf, s->buffer + s->readpos, cnt); |
| 431 | if (ret) |
| 432 | return -EFAULT; |
| 433 | |
| 434 | s->readpos += len; |
| 435 | return cnt; |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 436 | } |
| 437 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 438 | static void |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 439 | trace_print_seq(struct seq_file *m, struct trace_seq *s) |
| 440 | { |
| 441 | int len = s->len >= PAGE_SIZE ? PAGE_SIZE - 1 : s->len; |
| 442 | |
| 443 | s->buffer[len] = 0; |
| 444 | seq_puts(m, s->buffer); |
| 445 | |
| 446 | trace_seq_reset(s); |
| 447 | } |
| 448 | |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 449 | /** |
| 450 | * update_max_tr - snapshot all trace buffers from global_trace to max_tr |
| 451 | * @tr: tracer |
| 452 | * @tsk: the task with the latency |
| 453 | * @cpu: The cpu that initiated the trace. |
| 454 | * |
| 455 | * Flip the buffers between the @tr and the max_tr and record information |
| 456 | * about which task was the cause of this latency. |
| 457 | */ |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 458 | void |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 459 | update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu) |
| 460 | { |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 461 | struct ring_buffer *buf = tr->buffer; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 462 | |
Steven Rostedt | 4c11d7a | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 463 | WARN_ON_ONCE(!irqs_disabled()); |
Steven Rostedt | 92205c2 | 2008-05-12 21:20:55 +0200 | [diff] [blame] | 464 | __raw_spin_lock(&ftrace_max_lock); |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 465 | |
| 466 | tr->buffer = max_tr.buffer; |
| 467 | max_tr.buffer = buf; |
| 468 | |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 469 | ftrace_disable_cpu(); |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 470 | ring_buffer_reset(tr->buffer); |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 471 | ftrace_enable_cpu(); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 472 | |
| 473 | __update_max_tr(tr, tsk, cpu); |
Steven Rostedt | 92205c2 | 2008-05-12 21:20:55 +0200 | [diff] [blame] | 474 | __raw_spin_unlock(&ftrace_max_lock); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 475 | } |
| 476 | |
| 477 | /** |
| 478 | * update_max_tr_single - only copy one trace over, and reset the rest |
| 479 | * @tr - tracer |
| 480 | * @tsk - task with the latency |
| 481 | * @cpu - the cpu of the buffer to copy. |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 482 | * |
| 483 | * 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] | 484 | */ |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 485 | void |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 486 | update_max_tr_single(struct trace_array *tr, struct task_struct *tsk, int cpu) |
| 487 | { |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 488 | int ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 489 | |
Steven Rostedt | 4c11d7a | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 490 | WARN_ON_ONCE(!irqs_disabled()); |
Steven Rostedt | 92205c2 | 2008-05-12 21:20:55 +0200 | [diff] [blame] | 491 | __raw_spin_lock(&ftrace_max_lock); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 492 | |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 493 | ftrace_disable_cpu(); |
| 494 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 495 | ring_buffer_reset(max_tr.buffer); |
| 496 | ret = ring_buffer_swap_cpu(max_tr.buffer, tr->buffer, cpu); |
| 497 | |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 498 | ftrace_enable_cpu(); |
| 499 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 500 | WARN_ON_ONCE(ret); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 501 | |
| 502 | __update_max_tr(tr, tsk, cpu); |
Steven Rostedt | 92205c2 | 2008-05-12 21:20:55 +0200 | [diff] [blame] | 503 | __raw_spin_unlock(&ftrace_max_lock); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 504 | } |
| 505 | |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 506 | /** |
| 507 | * register_tracer - register a tracer with the ftrace system. |
| 508 | * @type - the plugin for the tracer |
| 509 | * |
| 510 | * Register a new plugin tracer. |
| 511 | */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 512 | int register_tracer(struct tracer *type) |
| 513 | { |
| 514 | struct tracer *t; |
| 515 | int len; |
| 516 | int ret = 0; |
| 517 | |
| 518 | if (!type->name) { |
| 519 | pr_info("Tracer must have a name\n"); |
| 520 | return -1; |
| 521 | } |
| 522 | |
Ingo Molnar | 86fa2f6 | 2008-11-19 10:00:15 +0100 | [diff] [blame^] | 523 | /* |
| 524 | * When this gets called we hold the BKL which means that |
| 525 | * preemption is disabled. Various trace selftests however |
| 526 | * need to disable and enable preemption for successful tests. |
| 527 | * So we drop the BKL here and grab it after the tests again. |
| 528 | */ |
| 529 | unlock_kernel(); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 530 | mutex_lock(&trace_types_lock); |
Ingo Molnar | 86fa2f6 | 2008-11-19 10:00:15 +0100 | [diff] [blame^] | 531 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 532 | for (t = trace_types; t; t = t->next) { |
| 533 | if (strcmp(type->name, t->name) == 0) { |
| 534 | /* already found */ |
| 535 | pr_info("Trace %s already registered\n", |
| 536 | type->name); |
| 537 | ret = -1; |
| 538 | goto out; |
| 539 | } |
| 540 | } |
| 541 | |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 542 | #ifdef CONFIG_FTRACE_STARTUP_TEST |
| 543 | if (type->selftest) { |
| 544 | struct tracer *saved_tracer = current_trace; |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 545 | struct trace_array *tr = &global_trace; |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 546 | int i; |
| 547 | /* |
| 548 | * Run a selftest on this tracer. |
| 549 | * Here we reset the trace buffer, and set the current |
| 550 | * tracer to be this tracer. The tracer can then run some |
| 551 | * internal tracing to verify that everything is in order. |
| 552 | * If we fail, we do not register this tracer. |
| 553 | */ |
Ingo Molnar | 86fa2f6 | 2008-11-19 10:00:15 +0100 | [diff] [blame^] | 554 | for_each_tracing_cpu(i) |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 555 | tracing_reset(tr, i); |
Ingo Molnar | 86fa2f6 | 2008-11-19 10:00:15 +0100 | [diff] [blame^] | 556 | |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 557 | current_trace = type; |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 558 | /* the test is responsible for initializing and enabling */ |
| 559 | pr_info("Testing tracer %s: ", type->name); |
| 560 | ret = type->selftest(type, tr); |
| 561 | /* the test is responsible for resetting too */ |
| 562 | current_trace = saved_tracer; |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 563 | if (ret) { |
| 564 | printk(KERN_CONT "FAILED!\n"); |
| 565 | goto out; |
| 566 | } |
Steven Rostedt | 1d4db00 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 567 | /* Only reset on passing, to avoid touching corrupted buffers */ |
Ingo Molnar | 86fa2f6 | 2008-11-19 10:00:15 +0100 | [diff] [blame^] | 568 | for_each_tracing_cpu(i) |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 569 | tracing_reset(tr, i); |
Ingo Molnar | 86fa2f6 | 2008-11-19 10:00:15 +0100 | [diff] [blame^] | 570 | |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 571 | printk(KERN_CONT "PASSED\n"); |
| 572 | } |
| 573 | #endif |
| 574 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 575 | type->next = trace_types; |
| 576 | trace_types = type; |
| 577 | len = strlen(type->name); |
| 578 | if (len > max_tracer_type_len) |
| 579 | max_tracer_type_len = len; |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 580 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 581 | out: |
| 582 | mutex_unlock(&trace_types_lock); |
Ingo Molnar | 86fa2f6 | 2008-11-19 10:00:15 +0100 | [diff] [blame^] | 583 | lock_kernel(); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 584 | |
| 585 | return ret; |
| 586 | } |
| 587 | |
| 588 | void unregister_tracer(struct tracer *type) |
| 589 | { |
| 590 | struct tracer **t; |
| 591 | int len; |
| 592 | |
| 593 | mutex_lock(&trace_types_lock); |
| 594 | for (t = &trace_types; *t; t = &(*t)->next) { |
| 595 | if (*t == type) |
| 596 | goto found; |
| 597 | } |
| 598 | pr_info("Trace %s not registered\n", type->name); |
| 599 | goto out; |
| 600 | |
| 601 | found: |
| 602 | *t = (*t)->next; |
| 603 | if (strlen(type->name) != max_tracer_type_len) |
| 604 | goto out; |
| 605 | |
| 606 | max_tracer_type_len = 0; |
| 607 | for (t = &trace_types; *t; t = &(*t)->next) { |
| 608 | len = strlen((*t)->name); |
| 609 | if (len > max_tracer_type_len) |
| 610 | max_tracer_type_len = len; |
| 611 | } |
| 612 | out: |
| 613 | mutex_unlock(&trace_types_lock); |
| 614 | } |
| 615 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 616 | void tracing_reset(struct trace_array *tr, int cpu) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 617 | { |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 618 | ftrace_disable_cpu(); |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 619 | ring_buffer_reset_cpu(tr->buffer, cpu); |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 620 | ftrace_enable_cpu(); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 621 | } |
| 622 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 623 | #define SAVED_CMDLINES 128 |
| 624 | static unsigned map_pid_to_cmdline[PID_MAX_DEFAULT+1]; |
| 625 | static unsigned map_cmdline_to_pid[SAVED_CMDLINES]; |
| 626 | static char saved_cmdlines[SAVED_CMDLINES][TASK_COMM_LEN]; |
| 627 | static int cmdline_idx; |
| 628 | static DEFINE_SPINLOCK(trace_cmdline_lock); |
Steven Rostedt | 25b0b44 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 629 | |
Steven Rostedt | 25b0b44 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 630 | /* temporary disable recording */ |
| 631 | atomic_t trace_record_cmdline_disabled __read_mostly; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 632 | |
| 633 | static void trace_init_cmdlines(void) |
| 634 | { |
| 635 | memset(&map_pid_to_cmdline, -1, sizeof(map_pid_to_cmdline)); |
| 636 | memset(&map_cmdline_to_pid, -1, sizeof(map_cmdline_to_pid)); |
| 637 | cmdline_idx = 0; |
| 638 | } |
| 639 | |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 640 | static int trace_stop_count; |
| 641 | static DEFINE_SPINLOCK(tracing_start_lock); |
| 642 | |
| 643 | /** |
| 644 | * tracing_start - quick start of the tracer |
| 645 | * |
| 646 | * If tracing is enabled but was stopped by tracing_stop, |
| 647 | * this will start the tracer back up. |
| 648 | */ |
| 649 | void tracing_start(void) |
| 650 | { |
| 651 | struct ring_buffer *buffer; |
| 652 | unsigned long flags; |
| 653 | |
| 654 | if (tracing_disabled) |
| 655 | return; |
| 656 | |
| 657 | spin_lock_irqsave(&tracing_start_lock, flags); |
| 658 | if (--trace_stop_count) |
| 659 | goto out; |
| 660 | |
| 661 | if (trace_stop_count < 0) { |
| 662 | /* Someone screwed up their debugging */ |
| 663 | WARN_ON_ONCE(1); |
| 664 | trace_stop_count = 0; |
| 665 | goto out; |
| 666 | } |
| 667 | |
| 668 | |
| 669 | buffer = global_trace.buffer; |
| 670 | if (buffer) |
| 671 | ring_buffer_record_enable(buffer); |
| 672 | |
| 673 | buffer = max_tr.buffer; |
| 674 | if (buffer) |
| 675 | ring_buffer_record_enable(buffer); |
| 676 | |
| 677 | ftrace_start(); |
| 678 | out: |
| 679 | spin_unlock_irqrestore(&tracing_start_lock, flags); |
| 680 | } |
| 681 | |
| 682 | /** |
| 683 | * tracing_stop - quick stop of the tracer |
| 684 | * |
| 685 | * Light weight way to stop tracing. Use in conjunction with |
| 686 | * tracing_start. |
| 687 | */ |
| 688 | void tracing_stop(void) |
| 689 | { |
| 690 | struct ring_buffer *buffer; |
| 691 | unsigned long flags; |
| 692 | |
| 693 | ftrace_stop(); |
| 694 | spin_lock_irqsave(&tracing_start_lock, flags); |
| 695 | if (trace_stop_count++) |
| 696 | goto out; |
| 697 | |
| 698 | buffer = global_trace.buffer; |
| 699 | if (buffer) |
| 700 | ring_buffer_record_disable(buffer); |
| 701 | |
| 702 | buffer = max_tr.buffer; |
| 703 | if (buffer) |
| 704 | ring_buffer_record_disable(buffer); |
| 705 | |
| 706 | out: |
| 707 | spin_unlock_irqrestore(&tracing_start_lock, flags); |
| 708 | } |
| 709 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 710 | void trace_stop_cmdline_recording(void); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 711 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 712 | static void trace_save_cmdline(struct task_struct *tsk) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 713 | { |
| 714 | unsigned map; |
| 715 | unsigned idx; |
| 716 | |
| 717 | if (!tsk->pid || unlikely(tsk->pid > PID_MAX_DEFAULT)) |
| 718 | return; |
| 719 | |
| 720 | /* |
| 721 | * It's not the end of the world if we don't get |
| 722 | * the lock, but we also don't want to spin |
| 723 | * nor do we want to disable interrupts, |
| 724 | * so if we miss here, then better luck next time. |
| 725 | */ |
| 726 | if (!spin_trylock(&trace_cmdline_lock)) |
| 727 | return; |
| 728 | |
| 729 | idx = map_pid_to_cmdline[tsk->pid]; |
| 730 | if (idx >= SAVED_CMDLINES) { |
| 731 | idx = (cmdline_idx + 1) % SAVED_CMDLINES; |
| 732 | |
| 733 | map = map_cmdline_to_pid[idx]; |
| 734 | if (map <= PID_MAX_DEFAULT) |
| 735 | map_pid_to_cmdline[map] = (unsigned)-1; |
| 736 | |
| 737 | map_pid_to_cmdline[tsk->pid] = idx; |
| 738 | |
| 739 | cmdline_idx = idx; |
| 740 | } |
| 741 | |
| 742 | memcpy(&saved_cmdlines[idx], tsk->comm, TASK_COMM_LEN); |
| 743 | |
| 744 | spin_unlock(&trace_cmdline_lock); |
| 745 | } |
| 746 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 747 | static char *trace_find_cmdline(int pid) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 748 | { |
| 749 | char *cmdline = "<...>"; |
| 750 | unsigned map; |
| 751 | |
| 752 | if (!pid) |
| 753 | return "<idle>"; |
| 754 | |
| 755 | if (pid > PID_MAX_DEFAULT) |
| 756 | goto out; |
| 757 | |
| 758 | map = map_pid_to_cmdline[pid]; |
| 759 | if (map >= SAVED_CMDLINES) |
| 760 | goto out; |
| 761 | |
| 762 | cmdline = saved_cmdlines[map]; |
| 763 | |
| 764 | out: |
| 765 | return cmdline; |
| 766 | } |
| 767 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 768 | void tracing_record_cmdline(struct task_struct *tsk) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 769 | { |
| 770 | if (atomic_read(&trace_record_cmdline_disabled)) |
| 771 | return; |
| 772 | |
| 773 | trace_save_cmdline(tsk); |
| 774 | } |
| 775 | |
Pekka Paalanen | 45dcd8b | 2008-09-16 21:56:41 +0300 | [diff] [blame] | 776 | void |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 777 | tracing_generic_entry_update(struct trace_entry *entry, unsigned long flags, |
| 778 | int pc) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 779 | { |
| 780 | struct task_struct *tsk = current; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 781 | |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 782 | entry->preempt_count = pc & 0xff; |
| 783 | entry->pid = (tsk) ? tsk->pid : 0; |
| 784 | entry->flags = |
Steven Rostedt | 9244489 | 2008-10-24 09:42:59 -0400 | [diff] [blame] | 785 | #ifdef CONFIG_TRACE_IRQFLAGS_SUPPORT |
Steven Rostedt | 2e2ca15 | 2008-08-01 12:26:40 -0400 | [diff] [blame] | 786 | (irqs_disabled_flags(flags) ? TRACE_FLAG_IRQS_OFF : 0) | |
Steven Rostedt | 9244489 | 2008-10-24 09:42:59 -0400 | [diff] [blame] | 787 | #else |
| 788 | TRACE_FLAG_IRQS_NOSUPPORT | |
| 789 | #endif |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 790 | ((pc & HARDIRQ_MASK) ? TRACE_FLAG_HARDIRQ : 0) | |
| 791 | ((pc & SOFTIRQ_MASK) ? TRACE_FLAG_SOFTIRQ : 0) | |
| 792 | (need_resched() ? TRACE_FLAG_NEED_RESCHED : 0); |
| 793 | } |
| 794 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 795 | void |
Steven Rostedt | 6fb44b7 | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 796 | trace_function(struct trace_array *tr, struct trace_array_cpu *data, |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 797 | unsigned long ip, unsigned long parent_ip, unsigned long flags, |
| 798 | int pc) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 799 | { |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 800 | struct ring_buffer_event *event; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 801 | struct ftrace_entry *entry; |
Ingo Molnar | dcb6308 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 802 | unsigned long irq_flags; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 803 | |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 804 | /* If we are reading the ring buffer, don't trace */ |
| 805 | if (unlikely(local_read(&__get_cpu_var(ftrace_cpu_disabled)))) |
| 806 | return; |
| 807 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 808 | event = ring_buffer_lock_reserve(tr->buffer, sizeof(*entry), |
| 809 | &irq_flags); |
| 810 | if (!event) |
| 811 | return; |
| 812 | entry = ring_buffer_event_data(event); |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 813 | tracing_generic_entry_update(&entry->ent, flags, pc); |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 814 | entry->ent.type = TRACE_FN; |
| 815 | entry->ip = ip; |
| 816 | entry->parent_ip = parent_ip; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 817 | ring_buffer_unlock_commit(tr->buffer, event, irq_flags); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 818 | } |
| 819 | |
Frederic Weisbecker | 15e6cb3 | 2008-11-11 07:14:25 +0100 | [diff] [blame] | 820 | #ifdef CONFIG_FUNCTION_RET_TRACER |
| 821 | static void __trace_function_return(struct trace_array *tr, |
| 822 | struct trace_array_cpu *data, |
| 823 | struct ftrace_retfunc *trace, |
| 824 | unsigned long flags, |
| 825 | int pc) |
| 826 | { |
| 827 | struct ring_buffer_event *event; |
| 828 | struct ftrace_ret_entry *entry; |
| 829 | unsigned long irq_flags; |
| 830 | |
| 831 | if (unlikely(local_read(&__get_cpu_var(ftrace_cpu_disabled)))) |
| 832 | return; |
| 833 | |
| 834 | event = ring_buffer_lock_reserve(global_trace.buffer, sizeof(*entry), |
| 835 | &irq_flags); |
| 836 | if (!event) |
| 837 | return; |
| 838 | entry = ring_buffer_event_data(event); |
| 839 | tracing_generic_entry_update(&entry->ent, flags, pc); |
| 840 | entry->ent.type = TRACE_FN_RET; |
| 841 | entry->ip = trace->func; |
| 842 | entry->parent_ip = trace->ret; |
| 843 | entry->rettime = trace->rettime; |
| 844 | entry->calltime = trace->calltime; |
| 845 | ring_buffer_unlock_commit(global_trace.buffer, event, irq_flags); |
| 846 | } |
| 847 | #endif |
| 848 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 849 | void |
Ingo Molnar | 2e0f576 | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 850 | ftrace(struct trace_array *tr, struct trace_array_cpu *data, |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 851 | unsigned long ip, unsigned long parent_ip, unsigned long flags, |
| 852 | int pc) |
Ingo Molnar | 2e0f576 | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 853 | { |
| 854 | if (likely(!atomic_read(&data->disabled))) |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 855 | trace_function(tr, data, ip, parent_ip, flags, pc); |
Ingo Molnar | 2e0f576 | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 856 | } |
| 857 | |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 858 | static void ftrace_trace_stack(struct trace_array *tr, |
| 859 | struct trace_array_cpu *data, |
| 860 | unsigned long flags, |
| 861 | int skip, int pc) |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 862 | { |
Al Viro | c2c8052 | 2008-10-31 19:50:41 +0000 | [diff] [blame] | 863 | #ifdef CONFIG_STACKTRACE |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 864 | struct ring_buffer_event *event; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 865 | struct stack_entry *entry; |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 866 | struct stack_trace trace; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 867 | unsigned long irq_flags; |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 868 | |
| 869 | if (!(trace_flags & TRACE_ITER_STACKTRACE)) |
| 870 | return; |
| 871 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 872 | event = ring_buffer_lock_reserve(tr->buffer, sizeof(*entry), |
| 873 | &irq_flags); |
| 874 | if (!event) |
| 875 | return; |
| 876 | entry = ring_buffer_event_data(event); |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 877 | tracing_generic_entry_update(&entry->ent, flags, pc); |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 878 | entry->ent.type = TRACE_STACK; |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 879 | |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 880 | memset(&entry->caller, 0, sizeof(entry->caller)); |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 881 | |
| 882 | trace.nr_entries = 0; |
| 883 | trace.max_entries = FTRACE_STACK_ENTRIES; |
| 884 | trace.skip = skip; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 885 | trace.entries = entry->caller; |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 886 | |
| 887 | save_stack_trace(&trace); |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 888 | ring_buffer_unlock_commit(tr->buffer, event, irq_flags); |
Al Viro | c2c8052 | 2008-10-31 19:50:41 +0000 | [diff] [blame] | 889 | #endif |
Ingo Molnar | f0a920d | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 890 | } |
| 891 | |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 892 | void __trace_stack(struct trace_array *tr, |
| 893 | struct trace_array_cpu *data, |
| 894 | unsigned long flags, |
| 895 | int skip) |
| 896 | { |
| 897 | ftrace_trace_stack(tr, data, flags, skip, preempt_count()); |
| 898 | } |
| 899 | |
| 900 | static void |
| 901 | ftrace_trace_special(void *__tr, void *__data, |
| 902 | unsigned long arg1, unsigned long arg2, unsigned long arg3, |
| 903 | int pc) |
Ingo Molnar | a4feb834 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 904 | { |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 905 | struct ring_buffer_event *event; |
Ingo Molnar | a4feb834 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 906 | struct trace_array_cpu *data = __data; |
| 907 | struct trace_array *tr = __tr; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 908 | struct special_entry *entry; |
Ingo Molnar | a4feb834 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 909 | unsigned long irq_flags; |
| 910 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 911 | event = ring_buffer_lock_reserve(tr->buffer, sizeof(*entry), |
| 912 | &irq_flags); |
| 913 | if (!event) |
| 914 | return; |
| 915 | entry = ring_buffer_event_data(event); |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 916 | tracing_generic_entry_update(&entry->ent, 0, pc); |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 917 | entry->ent.type = TRACE_SPECIAL; |
| 918 | entry->arg1 = arg1; |
| 919 | entry->arg2 = arg2; |
| 920 | entry->arg3 = arg3; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 921 | ring_buffer_unlock_commit(tr->buffer, event, irq_flags); |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 922 | ftrace_trace_stack(tr, data, irq_flags, 4, pc); |
Ingo Molnar | a4feb834 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 923 | |
| 924 | trace_wake_up(); |
| 925 | } |
| 926 | |
| 927 | void |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 928 | __trace_special(void *__tr, void *__data, |
| 929 | unsigned long arg1, unsigned long arg2, unsigned long arg3) |
| 930 | { |
| 931 | ftrace_trace_special(__tr, __data, arg1, arg2, arg3, preempt_count()); |
| 932 | } |
| 933 | |
| 934 | void |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 935 | tracing_sched_switch_trace(struct trace_array *tr, |
| 936 | struct trace_array_cpu *data, |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 937 | struct task_struct *prev, |
| 938 | struct task_struct *next, |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 939 | unsigned long flags, int pc) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 940 | { |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 941 | struct ring_buffer_event *event; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 942 | struct ctx_switch_entry *entry; |
Ingo Molnar | dcb6308 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 943 | unsigned long irq_flags; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 944 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 945 | event = ring_buffer_lock_reserve(tr->buffer, sizeof(*entry), |
| 946 | &irq_flags); |
| 947 | if (!event) |
| 948 | return; |
| 949 | entry = ring_buffer_event_data(event); |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 950 | tracing_generic_entry_update(&entry->ent, flags, pc); |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 951 | entry->ent.type = TRACE_CTX; |
| 952 | entry->prev_pid = prev->pid; |
| 953 | entry->prev_prio = prev->prio; |
| 954 | entry->prev_state = prev->state; |
| 955 | entry->next_pid = next->pid; |
| 956 | entry->next_prio = next->prio; |
| 957 | entry->next_state = next->state; |
| 958 | entry->next_cpu = task_cpu(next); |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 959 | ring_buffer_unlock_commit(tr->buffer, event, irq_flags); |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 960 | ftrace_trace_stack(tr, data, flags, 5, pc); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 961 | } |
| 962 | |
Ingo Molnar | 5742279 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 963 | void |
| 964 | tracing_sched_wakeup_trace(struct trace_array *tr, |
| 965 | struct trace_array_cpu *data, |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 966 | struct task_struct *wakee, |
| 967 | struct task_struct *curr, |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 968 | unsigned long flags, int pc) |
Ingo Molnar | 5742279 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 969 | { |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 970 | struct ring_buffer_event *event; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 971 | struct ctx_switch_entry *entry; |
Ingo Molnar | 5742279 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 972 | unsigned long irq_flags; |
| 973 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 974 | event = ring_buffer_lock_reserve(tr->buffer, sizeof(*entry), |
| 975 | &irq_flags); |
| 976 | if (!event) |
| 977 | return; |
| 978 | entry = ring_buffer_event_data(event); |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 979 | tracing_generic_entry_update(&entry->ent, flags, pc); |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 980 | entry->ent.type = TRACE_WAKE; |
| 981 | entry->prev_pid = curr->pid; |
| 982 | entry->prev_prio = curr->prio; |
| 983 | entry->prev_state = curr->state; |
| 984 | entry->next_pid = wakee->pid; |
| 985 | entry->next_prio = wakee->prio; |
| 986 | entry->next_state = wakee->state; |
| 987 | entry->next_cpu = task_cpu(wakee); |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 988 | ring_buffer_unlock_commit(tr->buffer, event, irq_flags); |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 989 | ftrace_trace_stack(tr, data, flags, 6, pc); |
Ingo Molnar | 017730c | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 990 | |
| 991 | trace_wake_up(); |
Ingo Molnar | 5742279 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 992 | } |
| 993 | |
Steven Rostedt | 4902f88 | 2008-05-22 00:22:18 -0400 | [diff] [blame] | 994 | void |
| 995 | ftrace_special(unsigned long arg1, unsigned long arg2, unsigned long arg3) |
| 996 | { |
| 997 | struct trace_array *tr = &global_trace; |
| 998 | struct trace_array_cpu *data; |
Steven Rostedt | 5aa1ba6 | 2008-11-10 23:07:30 -0500 | [diff] [blame] | 999 | unsigned long flags; |
Steven Rostedt | 4902f88 | 2008-05-22 00:22:18 -0400 | [diff] [blame] | 1000 | int cpu; |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 1001 | int pc; |
Steven Rostedt | 4902f88 | 2008-05-22 00:22:18 -0400 | [diff] [blame] | 1002 | |
Steven Rostedt | c76f069 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 1003 | if (tracing_disabled) |
Steven Rostedt | 4902f88 | 2008-05-22 00:22:18 -0400 | [diff] [blame] | 1004 | return; |
| 1005 | |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 1006 | pc = preempt_count(); |
Steven Rostedt | 5aa1ba6 | 2008-11-10 23:07:30 -0500 | [diff] [blame] | 1007 | local_irq_save(flags); |
Steven Rostedt | 4902f88 | 2008-05-22 00:22:18 -0400 | [diff] [blame] | 1008 | cpu = raw_smp_processor_id(); |
| 1009 | data = tr->data[cpu]; |
Steven Rostedt | 4902f88 | 2008-05-22 00:22:18 -0400 | [diff] [blame] | 1010 | |
Steven Rostedt | 5aa1ba6 | 2008-11-10 23:07:30 -0500 | [diff] [blame] | 1011 | if (likely(atomic_inc_return(&data->disabled) == 1)) |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 1012 | ftrace_trace_special(tr, data, arg1, arg2, arg3, pc); |
Steven Rostedt | 4902f88 | 2008-05-22 00:22:18 -0400 | [diff] [blame] | 1013 | |
Steven Rostedt | 5aa1ba6 | 2008-11-10 23:07:30 -0500 | [diff] [blame] | 1014 | atomic_dec(&data->disabled); |
| 1015 | local_irq_restore(flags); |
Steven Rostedt | 4902f88 | 2008-05-22 00:22:18 -0400 | [diff] [blame] | 1016 | } |
| 1017 | |
Steven Rostedt | 606576c | 2008-10-06 19:06:12 -0400 | [diff] [blame] | 1018 | #ifdef CONFIG_FUNCTION_TRACER |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1019 | static void |
Steven Rostedt | b2a866f | 2008-11-03 23:15:57 -0500 | [diff] [blame] | 1020 | function_trace_call_preempt_only(unsigned long ip, unsigned long parent_ip) |
Ingo Molnar | 2e0f576 | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 1021 | { |
| 1022 | struct trace_array *tr = &global_trace; |
| 1023 | struct trace_array_cpu *data; |
| 1024 | unsigned long flags; |
| 1025 | long disabled; |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 1026 | int cpu, resched; |
| 1027 | int pc; |
Ingo Molnar | 2e0f576 | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 1028 | |
Steven Rostedt | 60bc080 | 2008-07-10 20:58:16 -0400 | [diff] [blame] | 1029 | if (unlikely(!ftrace_function_enabled)) |
Ingo Molnar | 2e0f576 | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 1030 | return; |
| 1031 | |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 1032 | pc = preempt_count(); |
Steven Rostedt | 182e9f5 | 2008-11-03 23:15:56 -0500 | [diff] [blame] | 1033 | resched = ftrace_preempt_disable(); |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 1034 | local_save_flags(flags); |
Ingo Molnar | 2e0f576 | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 1035 | cpu = raw_smp_processor_id(); |
| 1036 | data = tr->data[cpu]; |
| 1037 | disabled = atomic_inc_return(&data->disabled); |
| 1038 | |
| 1039 | if (likely(disabled == 1)) |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 1040 | trace_function(tr, data, ip, parent_ip, flags, pc); |
Ingo Molnar | 2e0f576 | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 1041 | |
| 1042 | atomic_dec(&data->disabled); |
Steven Rostedt | 182e9f5 | 2008-11-03 23:15:56 -0500 | [diff] [blame] | 1043 | ftrace_preempt_enable(resched); |
Ingo Molnar | 2e0f576 | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 1044 | } |
| 1045 | |
Steven Rostedt | b2a866f | 2008-11-03 23:15:57 -0500 | [diff] [blame] | 1046 | static void |
| 1047 | function_trace_call(unsigned long ip, unsigned long parent_ip) |
| 1048 | { |
| 1049 | struct trace_array *tr = &global_trace; |
| 1050 | struct trace_array_cpu *data; |
| 1051 | unsigned long flags; |
| 1052 | long disabled; |
| 1053 | int cpu; |
| 1054 | int pc; |
| 1055 | |
| 1056 | if (unlikely(!ftrace_function_enabled)) |
| 1057 | return; |
| 1058 | |
| 1059 | /* |
| 1060 | * Need to use raw, since this must be called before the |
| 1061 | * recursive protection is performed. |
| 1062 | */ |
Steven Rostedt | d51ad7a | 2008-11-15 15:48:29 -0500 | [diff] [blame] | 1063 | local_irq_save(flags); |
Steven Rostedt | b2a866f | 2008-11-03 23:15:57 -0500 | [diff] [blame] | 1064 | cpu = raw_smp_processor_id(); |
| 1065 | data = tr->data[cpu]; |
| 1066 | disabled = atomic_inc_return(&data->disabled); |
| 1067 | |
| 1068 | if (likely(disabled == 1)) { |
| 1069 | pc = preempt_count(); |
| 1070 | trace_function(tr, data, ip, parent_ip, flags, pc); |
| 1071 | } |
| 1072 | |
| 1073 | atomic_dec(&data->disabled); |
Steven Rostedt | d51ad7a | 2008-11-15 15:48:29 -0500 | [diff] [blame] | 1074 | local_irq_restore(flags); |
Steven Rostedt | b2a866f | 2008-11-03 23:15:57 -0500 | [diff] [blame] | 1075 | } |
| 1076 | |
Frederic Weisbecker | 15e6cb3 | 2008-11-11 07:14:25 +0100 | [diff] [blame] | 1077 | #ifdef CONFIG_FUNCTION_RET_TRACER |
| 1078 | void trace_function_return(struct ftrace_retfunc *trace) |
| 1079 | { |
| 1080 | struct trace_array *tr = &global_trace; |
| 1081 | struct trace_array_cpu *data; |
| 1082 | unsigned long flags; |
| 1083 | long disabled; |
| 1084 | int cpu; |
| 1085 | int pc; |
| 1086 | |
| 1087 | raw_local_irq_save(flags); |
| 1088 | cpu = raw_smp_processor_id(); |
| 1089 | data = tr->data[cpu]; |
| 1090 | disabled = atomic_inc_return(&data->disabled); |
| 1091 | if (likely(disabled == 1)) { |
| 1092 | pc = preempt_count(); |
| 1093 | __trace_function_return(tr, data, trace, flags, pc); |
| 1094 | } |
| 1095 | atomic_dec(&data->disabled); |
| 1096 | raw_local_irq_restore(flags); |
| 1097 | } |
| 1098 | #endif /* CONFIG_FUNCTION_RET_TRACER */ |
| 1099 | |
Ingo Molnar | 2e0f576 | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 1100 | static struct ftrace_ops trace_ops __read_mostly = |
| 1101 | { |
| 1102 | .func = function_trace_call, |
| 1103 | }; |
| 1104 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1105 | void tracing_start_function_trace(void) |
Ingo Molnar | 2e0f576 | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 1106 | { |
Steven Rostedt | 60bc080 | 2008-07-10 20:58:16 -0400 | [diff] [blame] | 1107 | ftrace_function_enabled = 0; |
Steven Rostedt | b2a866f | 2008-11-03 23:15:57 -0500 | [diff] [blame] | 1108 | |
| 1109 | if (trace_flags & TRACE_ITER_PREEMPTONLY) |
| 1110 | trace_ops.func = function_trace_call_preempt_only; |
| 1111 | else |
| 1112 | trace_ops.func = function_trace_call; |
| 1113 | |
Ingo Molnar | 2e0f576 | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 1114 | register_ftrace_function(&trace_ops); |
Steven Rostedt | 9036990 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1115 | ftrace_function_enabled = 1; |
Ingo Molnar | 2e0f576 | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 1116 | } |
| 1117 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1118 | void tracing_stop_function_trace(void) |
Ingo Molnar | 2e0f576 | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 1119 | { |
Steven Rostedt | 60bc080 | 2008-07-10 20:58:16 -0400 | [diff] [blame] | 1120 | ftrace_function_enabled = 0; |
Ingo Molnar | 2e0f576 | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 1121 | unregister_ftrace_function(&trace_ops); |
| 1122 | } |
| 1123 | #endif |
| 1124 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1125 | enum trace_file_type { |
| 1126 | TRACE_FILE_LAT_FMT = 1, |
Steven Rostedt | 12ef7d4 | 2008-11-12 17:52:38 -0500 | [diff] [blame] | 1127 | TRACE_FILE_ANNOTATE = 2, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1128 | }; |
| 1129 | |
Steven Rostedt | 5a90f57 | 2008-09-03 17:42:51 -0400 | [diff] [blame] | 1130 | static void trace_iterator_increment(struct trace_iterator *iter, int cpu) |
| 1131 | { |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 1132 | /* Don't allow ftrace to trace into the ring buffers */ |
| 1133 | ftrace_disable_cpu(); |
| 1134 | |
Steven Rostedt | 5a90f57 | 2008-09-03 17:42:51 -0400 | [diff] [blame] | 1135 | iter->idx++; |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 1136 | if (iter->buffer_iter[iter->cpu]) |
| 1137 | ring_buffer_read(iter->buffer_iter[iter->cpu], NULL); |
| 1138 | |
| 1139 | ftrace_enable_cpu(); |
Steven Rostedt | 5a90f57 | 2008-09-03 17:42:51 -0400 | [diff] [blame] | 1140 | } |
| 1141 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1142 | static struct trace_entry * |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1143 | peek_next_entry(struct trace_iterator *iter, int cpu, u64 *ts) |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1144 | { |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1145 | struct ring_buffer_event *event; |
| 1146 | struct ring_buffer_iter *buf_iter = iter->buffer_iter[cpu]; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1147 | |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 1148 | /* Don't allow ftrace to trace into the ring buffers */ |
| 1149 | ftrace_disable_cpu(); |
| 1150 | |
| 1151 | if (buf_iter) |
| 1152 | event = ring_buffer_iter_peek(buf_iter, ts); |
| 1153 | else |
| 1154 | event = ring_buffer_peek(iter->tr->buffer, cpu, ts); |
| 1155 | |
| 1156 | ftrace_enable_cpu(); |
| 1157 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1158 | return event ? ring_buffer_event_data(event) : NULL; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1159 | } |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 1160 | |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1161 | static struct trace_entry * |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1162 | __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] | 1163 | { |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1164 | struct ring_buffer *buffer = iter->tr->buffer; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1165 | struct trace_entry *ent, *next = NULL; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1166 | u64 next_ts = 0, ts; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1167 | int next_cpu = -1; |
| 1168 | int cpu; |
| 1169 | |
Steven Rostedt | ab46428 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 1170 | for_each_tracing_cpu(cpu) { |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1171 | |
| 1172 | if (ring_buffer_empty_cpu(buffer, cpu)) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1173 | continue; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1174 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1175 | ent = peek_next_entry(iter, cpu, &ts); |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1176 | |
Ingo Molnar | cdd31cd2 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1177 | /* |
| 1178 | * Pick the entry with the smallest timestamp: |
| 1179 | */ |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1180 | if (ent && (!next || ts < next_ts)) { |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1181 | next = ent; |
| 1182 | next_cpu = cpu; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1183 | next_ts = ts; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1184 | } |
| 1185 | } |
| 1186 | |
| 1187 | if (ent_cpu) |
| 1188 | *ent_cpu = next_cpu; |
| 1189 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1190 | if (ent_ts) |
| 1191 | *ent_ts = next_ts; |
| 1192 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1193 | return next; |
| 1194 | } |
| 1195 | |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1196 | /* Find the next real entry, without updating the iterator itself */ |
| 1197 | static struct trace_entry * |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1198 | find_next_entry(struct trace_iterator *iter, int *ent_cpu, u64 *ent_ts) |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1199 | { |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1200 | return __find_next_entry(iter, ent_cpu, ent_ts); |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1201 | } |
Ingo Molnar | 8c523a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1202 | |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1203 | /* Find the next real entry, and increment the iterator to the next entry */ |
| 1204 | static void *find_next_entry_inc(struct trace_iterator *iter) |
| 1205 | { |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1206 | iter->ent = __find_next_entry(iter, &iter->cpu, &iter->ts); |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1207 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1208 | if (iter->ent) |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1209 | trace_iterator_increment(iter, iter->cpu); |
| 1210 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1211 | return iter->ent ? iter : NULL; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1212 | } |
| 1213 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1214 | static void trace_consume(struct trace_iterator *iter) |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1215 | { |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 1216 | /* Don't allow ftrace to trace into the ring buffers */ |
| 1217 | ftrace_disable_cpu(); |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1218 | ring_buffer_consume(iter->tr->buffer, iter->cpu, &iter->ts); |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 1219 | ftrace_enable_cpu(); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1220 | } |
| 1221 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1222 | 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] | 1223 | { |
| 1224 | struct trace_iterator *iter = m->private; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1225 | int i = (int)*pos; |
Ingo Molnar | 4e3c333 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 1226 | void *ent; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1227 | |
| 1228 | (*pos)++; |
| 1229 | |
| 1230 | /* can't go backwards */ |
| 1231 | if (iter->idx > i) |
| 1232 | return NULL; |
| 1233 | |
| 1234 | if (iter->idx < 0) |
| 1235 | ent = find_next_entry_inc(iter); |
| 1236 | else |
| 1237 | ent = iter; |
| 1238 | |
| 1239 | while (ent && iter->idx < i) |
| 1240 | ent = find_next_entry_inc(iter); |
| 1241 | |
| 1242 | iter->pos = *pos; |
| 1243 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1244 | return ent; |
| 1245 | } |
| 1246 | |
| 1247 | static void *s_start(struct seq_file *m, loff_t *pos) |
| 1248 | { |
| 1249 | struct trace_iterator *iter = m->private; |
| 1250 | void *p = NULL; |
| 1251 | loff_t l = 0; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1252 | int cpu; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1253 | |
| 1254 | mutex_lock(&trace_types_lock); |
| 1255 | |
Steven Rostedt | d15f57f | 2008-05-12 21:20:56 +0200 | [diff] [blame] | 1256 | if (!current_trace || current_trace != iter->trace) { |
| 1257 | mutex_unlock(&trace_types_lock); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1258 | return NULL; |
Steven Rostedt | d15f57f | 2008-05-12 21:20:56 +0200 | [diff] [blame] | 1259 | } |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1260 | |
| 1261 | atomic_inc(&trace_record_cmdline_disabled); |
| 1262 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1263 | if (*pos != iter->pos) { |
| 1264 | iter->ent = NULL; |
| 1265 | iter->cpu = 0; |
| 1266 | iter->idx = -1; |
| 1267 | |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 1268 | ftrace_disable_cpu(); |
| 1269 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1270 | for_each_tracing_cpu(cpu) { |
| 1271 | ring_buffer_iter_reset(iter->buffer_iter[cpu]); |
Steven Rostedt | 4c11d7a | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1272 | } |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1273 | |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 1274 | ftrace_enable_cpu(); |
| 1275 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1276 | for (p = iter; p && l < *pos; p = s_next(m, p, &l)) |
| 1277 | ; |
| 1278 | |
| 1279 | } else { |
Steven Rostedt | 4c11d7a | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1280 | l = *pos - 1; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1281 | p = s_next(m, p, &l); |
| 1282 | } |
| 1283 | |
| 1284 | return p; |
| 1285 | } |
| 1286 | |
| 1287 | static void s_stop(struct seq_file *m, void *p) |
| 1288 | { |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1289 | atomic_dec(&trace_record_cmdline_disabled); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1290 | mutex_unlock(&trace_types_lock); |
| 1291 | } |
| 1292 | |
Abhishek Sagar | 76094a2 | 2008-05-28 00:03:18 +0530 | [diff] [blame] | 1293 | #ifdef CONFIG_KRETPROBES |
Steven Rostedt | b3aa557 | 2008-10-31 15:44:07 -0400 | [diff] [blame] | 1294 | static inline const char *kretprobed(const char *name) |
Abhishek Sagar | 76094a2 | 2008-05-28 00:03:18 +0530 | [diff] [blame] | 1295 | { |
Steven Rostedt | b3aa557 | 2008-10-31 15:44:07 -0400 | [diff] [blame] | 1296 | static const char tramp_name[] = "kretprobe_trampoline"; |
| 1297 | int size = sizeof(tramp_name); |
| 1298 | |
| 1299 | if (strncmp(tramp_name, name, size) == 0) |
| 1300 | return "[unknown/kretprobe'd]"; |
| 1301 | return name; |
Abhishek Sagar | 76094a2 | 2008-05-28 00:03:18 +0530 | [diff] [blame] | 1302 | } |
| 1303 | #else |
Steven Rostedt | b3aa557 | 2008-10-31 15:44:07 -0400 | [diff] [blame] | 1304 | static inline const char *kretprobed(const char *name) |
Abhishek Sagar | 76094a2 | 2008-05-28 00:03:18 +0530 | [diff] [blame] | 1305 | { |
Steven Rostedt | b3aa557 | 2008-10-31 15:44:07 -0400 | [diff] [blame] | 1306 | return name; |
Abhishek Sagar | 76094a2 | 2008-05-28 00:03:18 +0530 | [diff] [blame] | 1307 | } |
| 1308 | #endif /* CONFIG_KRETPROBES */ |
| 1309 | |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1310 | static int |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1311 | seq_print_sym_short(struct trace_seq *s, const char *fmt, unsigned long address) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1312 | { |
| 1313 | #ifdef CONFIG_KALLSYMS |
| 1314 | char str[KSYM_SYMBOL_LEN]; |
Steven Rostedt | b3aa557 | 2008-10-31 15:44:07 -0400 | [diff] [blame] | 1315 | const char *name; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1316 | |
| 1317 | kallsyms_lookup(address, NULL, NULL, NULL, str); |
| 1318 | |
Steven Rostedt | b3aa557 | 2008-10-31 15:44:07 -0400 | [diff] [blame] | 1319 | name = kretprobed(str); |
| 1320 | |
| 1321 | return trace_seq_printf(s, fmt, name); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1322 | #endif |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1323 | return 1; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1324 | } |
| 1325 | |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1326 | static int |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1327 | seq_print_sym_offset(struct trace_seq *s, const char *fmt, |
| 1328 | unsigned long address) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1329 | { |
| 1330 | #ifdef CONFIG_KALLSYMS |
| 1331 | char str[KSYM_SYMBOL_LEN]; |
Steven Rostedt | b3aa557 | 2008-10-31 15:44:07 -0400 | [diff] [blame] | 1332 | const char *name; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1333 | |
| 1334 | sprint_symbol(str, address); |
Steven Rostedt | b3aa557 | 2008-10-31 15:44:07 -0400 | [diff] [blame] | 1335 | name = kretprobed(str); |
| 1336 | |
| 1337 | return trace_seq_printf(s, fmt, name); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1338 | #endif |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1339 | return 1; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1340 | } |
| 1341 | |
| 1342 | #ifndef CONFIG_64BIT |
| 1343 | # define IP_FMT "%08lx" |
| 1344 | #else |
| 1345 | # define IP_FMT "%016lx" |
| 1346 | #endif |
| 1347 | |
Frederic Weisbecker | 15e6cb3 | 2008-11-11 07:14:25 +0100 | [diff] [blame] | 1348 | int |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1349 | seq_print_ip_sym(struct trace_seq *s, unsigned long ip, unsigned long sym_flags) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1350 | { |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1351 | int ret; |
| 1352 | |
| 1353 | if (!ip) |
| 1354 | return trace_seq_printf(s, "0"); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1355 | |
| 1356 | if (sym_flags & TRACE_ITER_SYM_OFFSET) |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1357 | ret = seq_print_sym_offset(s, "%s", ip); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1358 | else |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1359 | ret = seq_print_sym_short(s, "%s", ip); |
| 1360 | |
| 1361 | if (!ret) |
| 1362 | return 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1363 | |
| 1364 | if (sym_flags & TRACE_ITER_SYM_ADDR) |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1365 | ret = trace_seq_printf(s, " <" IP_FMT ">", ip); |
| 1366 | return ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1367 | } |
| 1368 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1369 | static void print_lat_help_header(struct seq_file *m) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1370 | { |
Michael Ellerman | a616835 | 2008-08-20 16:36:11 -0700 | [diff] [blame] | 1371 | seq_puts(m, "# _------=> CPU# \n"); |
| 1372 | seq_puts(m, "# / _-----=> irqs-off \n"); |
| 1373 | seq_puts(m, "# | / _----=> need-resched \n"); |
| 1374 | seq_puts(m, "# || / _---=> hardirq/softirq \n"); |
| 1375 | seq_puts(m, "# ||| / _--=> preempt-depth \n"); |
| 1376 | seq_puts(m, "# |||| / \n"); |
| 1377 | seq_puts(m, "# ||||| delay \n"); |
| 1378 | seq_puts(m, "# cmd pid ||||| time | caller \n"); |
| 1379 | seq_puts(m, "# \\ / ||||| \\ | / \n"); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1380 | } |
| 1381 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1382 | static void print_func_help_header(struct seq_file *m) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1383 | { |
Michael Ellerman | a616835 | 2008-08-20 16:36:11 -0700 | [diff] [blame] | 1384 | seq_puts(m, "# TASK-PID CPU# TIMESTAMP FUNCTION\n"); |
| 1385 | seq_puts(m, "# | | | | |\n"); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1386 | } |
| 1387 | |
| 1388 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1389 | static void |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1390 | print_trace_header(struct seq_file *m, struct trace_iterator *iter) |
| 1391 | { |
| 1392 | unsigned long sym_flags = (trace_flags & TRACE_ITER_SYM_MASK); |
| 1393 | struct trace_array *tr = iter->tr; |
| 1394 | struct trace_array_cpu *data = tr->data[tr->cpu]; |
| 1395 | struct tracer *type = current_trace; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1396 | unsigned long total; |
| 1397 | unsigned long entries; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1398 | const char *name = "preemption"; |
| 1399 | |
| 1400 | if (type) |
| 1401 | name = type->name; |
| 1402 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1403 | entries = ring_buffer_entries(iter->tr->buffer); |
| 1404 | total = entries + |
| 1405 | ring_buffer_overruns(iter->tr->buffer); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1406 | |
| 1407 | seq_printf(m, "%s latency trace v1.1.5 on %s\n", |
| 1408 | name, UTS_RELEASE); |
| 1409 | seq_puts(m, "-----------------------------------" |
| 1410 | "---------------------------------\n"); |
| 1411 | seq_printf(m, " latency: %lu us, #%lu/%lu, CPU#%d |" |
| 1412 | " (M:%s VP:%d, KP:%d, SP:%d HP:%d", |
Steven Rostedt | 57f50be | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 1413 | nsecs_to_usecs(data->saved_latency), |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1414 | entries, |
Steven Rostedt | 4c11d7a | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1415 | total, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1416 | tr->cpu, |
| 1417 | #if defined(CONFIG_PREEMPT_NONE) |
| 1418 | "server", |
| 1419 | #elif defined(CONFIG_PREEMPT_VOLUNTARY) |
| 1420 | "desktop", |
Steven Rostedt | b5c21b4 | 2008-07-10 20:58:12 -0400 | [diff] [blame] | 1421 | #elif defined(CONFIG_PREEMPT) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1422 | "preempt", |
| 1423 | #else |
| 1424 | "unknown", |
| 1425 | #endif |
| 1426 | /* These are reserved for later use */ |
| 1427 | 0, 0, 0, 0); |
| 1428 | #ifdef CONFIG_SMP |
| 1429 | seq_printf(m, " #P:%d)\n", num_online_cpus()); |
| 1430 | #else |
| 1431 | seq_puts(m, ")\n"); |
| 1432 | #endif |
| 1433 | seq_puts(m, " -----------------\n"); |
| 1434 | seq_printf(m, " | task: %.16s-%d " |
| 1435 | "(uid:%d nice:%ld policy:%ld rt_prio:%ld)\n", |
| 1436 | data->comm, data->pid, data->uid, data->nice, |
| 1437 | data->policy, data->rt_priority); |
| 1438 | seq_puts(m, " -----------------\n"); |
| 1439 | |
| 1440 | if (data->critical_start) { |
| 1441 | seq_puts(m, " => started at: "); |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1442 | seq_print_ip_sym(&iter->seq, data->critical_start, sym_flags); |
| 1443 | trace_print_seq(m, &iter->seq); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1444 | seq_puts(m, "\n => ended at: "); |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1445 | seq_print_ip_sym(&iter->seq, data->critical_end, sym_flags); |
| 1446 | trace_print_seq(m, &iter->seq); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1447 | seq_puts(m, "\n"); |
| 1448 | } |
| 1449 | |
| 1450 | seq_puts(m, "\n"); |
| 1451 | } |
| 1452 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1453 | static void |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1454 | lat_print_generic(struct trace_seq *s, struct trace_entry *entry, int cpu) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1455 | { |
| 1456 | int hardirq, softirq; |
| 1457 | char *comm; |
| 1458 | |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1459 | comm = trace_find_cmdline(entry->pid); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1460 | |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1461 | trace_seq_printf(s, "%8.8s-%-5d ", comm, entry->pid); |
Michael Ellerman | a616835 | 2008-08-20 16:36:11 -0700 | [diff] [blame] | 1462 | trace_seq_printf(s, "%3d", cpu); |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1463 | trace_seq_printf(s, "%c%c", |
Steven Rostedt | 9244489 | 2008-10-24 09:42:59 -0400 | [diff] [blame] | 1464 | (entry->flags & TRACE_FLAG_IRQS_OFF) ? 'd' : |
| 1465 | (entry->flags & TRACE_FLAG_IRQS_NOSUPPORT) ? 'X' : '.', |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1466 | ((entry->flags & TRACE_FLAG_NEED_RESCHED) ? 'N' : '.')); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1467 | |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1468 | hardirq = entry->flags & TRACE_FLAG_HARDIRQ; |
| 1469 | softirq = entry->flags & TRACE_FLAG_SOFTIRQ; |
Ingo Molnar | afc2abc | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 1470 | if (hardirq && softirq) { |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1471 | trace_seq_putc(s, 'H'); |
Ingo Molnar | afc2abc | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 1472 | } else { |
| 1473 | if (hardirq) { |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1474 | trace_seq_putc(s, 'h'); |
Ingo Molnar | afc2abc | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 1475 | } else { |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1476 | if (softirq) |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1477 | trace_seq_putc(s, 's'); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1478 | else |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1479 | trace_seq_putc(s, '.'); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1480 | } |
| 1481 | } |
| 1482 | |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1483 | if (entry->preempt_count) |
| 1484 | trace_seq_printf(s, "%x", entry->preempt_count); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1485 | else |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1486 | trace_seq_puts(s, "."); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1487 | } |
| 1488 | |
| 1489 | unsigned long preempt_mark_thresh = 100; |
| 1490 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1491 | static void |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1492 | lat_print_timestamp(struct trace_seq *s, u64 abs_usecs, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1493 | unsigned long rel_usecs) |
| 1494 | { |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1495 | trace_seq_printf(s, " %4lldus", abs_usecs); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1496 | if (rel_usecs > preempt_mark_thresh) |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1497 | trace_seq_puts(s, "!: "); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1498 | else if (rel_usecs > 1) |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1499 | trace_seq_puts(s, "+: "); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1500 | else |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1501 | trace_seq_puts(s, " : "); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1502 | } |
| 1503 | |
| 1504 | static const char state_to_char[] = TASK_STATE_TO_CHAR_STR; |
| 1505 | |
Pekka Paalanen | fc5e27a | 2008-09-16 22:02:27 +0300 | [diff] [blame] | 1506 | /* |
| 1507 | * The message is supposed to contain an ending newline. |
| 1508 | * If the printing stops prematurely, try to add a newline of our own. |
| 1509 | */ |
| 1510 | void trace_seq_print_cont(struct trace_seq *s, struct trace_iterator *iter) |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1511 | { |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1512 | struct trace_entry *ent; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1513 | struct trace_field_cont *cont; |
Pekka Paalanen | fc5e27a | 2008-09-16 22:02:27 +0300 | [diff] [blame] | 1514 | bool ok = true; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1515 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1516 | ent = peek_next_entry(iter, iter->cpu, NULL); |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1517 | if (!ent || ent->type != TRACE_CONT) { |
| 1518 | trace_seq_putc(s, '\n'); |
| 1519 | return; |
| 1520 | } |
| 1521 | |
| 1522 | do { |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1523 | cont = (struct trace_field_cont *)ent; |
Pekka Paalanen | fc5e27a | 2008-09-16 22:02:27 +0300 | [diff] [blame] | 1524 | if (ok) |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1525 | ok = (trace_seq_printf(s, "%s", cont->buf) > 0); |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 1526 | |
| 1527 | ftrace_disable_cpu(); |
| 1528 | |
| 1529 | if (iter->buffer_iter[iter->cpu]) |
| 1530 | ring_buffer_read(iter->buffer_iter[iter->cpu], NULL); |
| 1531 | else |
| 1532 | ring_buffer_consume(iter->tr->buffer, iter->cpu, NULL); |
| 1533 | |
| 1534 | ftrace_enable_cpu(); |
| 1535 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1536 | ent = peek_next_entry(iter, iter->cpu, NULL); |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1537 | } while (ent && ent->type == TRACE_CONT); |
Pekka Paalanen | fc5e27a | 2008-09-16 22:02:27 +0300 | [diff] [blame] | 1538 | |
| 1539 | if (!ok) |
| 1540 | trace_seq_putc(s, '\n'); |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1541 | } |
| 1542 | |
Steven Rostedt | a309720 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 1543 | static void test_cpu_buff_start(struct trace_iterator *iter) |
| 1544 | { |
| 1545 | struct trace_seq *s = &iter->seq; |
| 1546 | |
Steven Rostedt | 12ef7d4 | 2008-11-12 17:52:38 -0500 | [diff] [blame] | 1547 | if (!(trace_flags & TRACE_ITER_ANNOTATE)) |
| 1548 | return; |
| 1549 | |
| 1550 | if (!(iter->iter_flags & TRACE_FILE_ANNOTATE)) |
| 1551 | return; |
| 1552 | |
Steven Rostedt | a309720 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 1553 | if (cpu_isset(iter->cpu, iter->started)) |
| 1554 | return; |
| 1555 | |
| 1556 | cpu_set(iter->cpu, iter->started); |
| 1557 | trace_seq_printf(s, "##### CPU %u buffer started ####\n", iter->cpu); |
| 1558 | } |
| 1559 | |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 1560 | static enum print_line_t |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1561 | print_lat_fmt(struct trace_iterator *iter, unsigned int trace_idx, int cpu) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1562 | { |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1563 | struct trace_seq *s = &iter->seq; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1564 | unsigned long sym_flags = (trace_flags & TRACE_ITER_SYM_MASK); |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1565 | struct trace_entry *next_entry; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1566 | unsigned long verbose = (trace_flags & TRACE_ITER_VERBOSE); |
| 1567 | struct trace_entry *entry = iter->ent; |
| 1568 | unsigned long abs_usecs; |
| 1569 | unsigned long rel_usecs; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1570 | u64 next_ts; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1571 | char *comm; |
Peter Zijlstra | bac524d | 2008-05-12 21:20:53 +0200 | [diff] [blame] | 1572 | int S, T; |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1573 | int i; |
Ankita Garg | d17d969 | 2008-05-12 21:20:58 +0200 | [diff] [blame] | 1574 | unsigned state; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1575 | |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1576 | if (entry->type == TRACE_CONT) |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 1577 | return TRACE_TYPE_HANDLED; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1578 | |
Steven Rostedt | a309720 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 1579 | test_cpu_buff_start(iter); |
| 1580 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1581 | next_entry = find_next_entry(iter, NULL, &next_ts); |
| 1582 | if (!next_entry) |
| 1583 | next_ts = iter->ts; |
| 1584 | rel_usecs = ns2usecs(next_ts - iter->ts); |
| 1585 | abs_usecs = ns2usecs(iter->ts - iter->tr->time_start); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1586 | |
| 1587 | if (verbose) { |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1588 | comm = trace_find_cmdline(entry->pid); |
Michael Ellerman | a616835 | 2008-08-20 16:36:11 -0700 | [diff] [blame] | 1589 | trace_seq_printf(s, "%16s %5d %3d %d %08x %08x [%08lx]" |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1590 | " %ld.%03ldms (+%ld.%03ldms): ", |
| 1591 | comm, |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1592 | entry->pid, cpu, entry->flags, |
| 1593 | entry->preempt_count, trace_idx, |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1594 | ns2usecs(iter->ts), |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1595 | abs_usecs/1000, |
| 1596 | abs_usecs % 1000, rel_usecs/1000, |
| 1597 | rel_usecs % 1000); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1598 | } else { |
Ingo Molnar | f29c73f | 2008-05-12 21:20:53 +0200 | [diff] [blame] | 1599 | lat_print_generic(s, entry, cpu); |
| 1600 | lat_print_timestamp(s, abs_usecs, rel_usecs); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1601 | } |
| 1602 | switch (entry->type) { |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1603 | case TRACE_FN: { |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 1604 | struct ftrace_entry *field; |
| 1605 | |
| 1606 | trace_assign_type(field, entry); |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1607 | |
| 1608 | seq_print_ip_sym(s, field->ip, sym_flags); |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1609 | trace_seq_puts(s, " ("); |
Steven Rostedt | b3aa557 | 2008-10-31 15:44:07 -0400 | [diff] [blame] | 1610 | seq_print_ip_sym(s, field->parent_ip, sym_flags); |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1611 | trace_seq_puts(s, ")\n"); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1612 | break; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1613 | } |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1614 | case TRACE_CTX: |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1615 | case TRACE_WAKE: { |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 1616 | struct ctx_switch_entry *field; |
| 1617 | |
| 1618 | trace_assign_type(field, entry); |
Peter Zijlstra | bac524d | 2008-05-12 21:20:53 +0200 | [diff] [blame] | 1619 | |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1620 | T = field->next_state < sizeof(state_to_char) ? |
| 1621 | state_to_char[field->next_state] : 'X'; |
| 1622 | |
| 1623 | state = field->prev_state ? |
| 1624 | __ffs(field->prev_state) + 1 : 0; |
Ankita Garg | d17d969 | 2008-05-12 21:20:58 +0200 | [diff] [blame] | 1625 | S = state < sizeof(state_to_char) - 1 ? state_to_char[state] : 'X'; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1626 | comm = trace_find_cmdline(field->next_pid); |
Peter Zijlstra | 80b5e94 | 2008-09-04 10:24:16 +0200 | [diff] [blame] | 1627 | trace_seq_printf(s, " %5d:%3d:%c %s [%03d] %5d:%3d:%c %s\n", |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1628 | field->prev_pid, |
| 1629 | field->prev_prio, |
Ingo Molnar | 5742279 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1630 | S, entry->type == TRACE_CTX ? "==>" : " +", |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1631 | field->next_cpu, |
| 1632 | field->next_pid, |
| 1633 | field->next_prio, |
Peter Zijlstra | bac524d | 2008-05-12 21:20:53 +0200 | [diff] [blame] | 1634 | T, comm); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1635 | break; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1636 | } |
| 1637 | case TRACE_SPECIAL: { |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 1638 | struct special_entry *field; |
| 1639 | |
| 1640 | trace_assign_type(field, entry); |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1641 | |
Ingo Molnar | 88a4216 | 2008-05-12 21:20:53 +0200 | [diff] [blame] | 1642 | trace_seq_printf(s, "# %ld %ld %ld\n", |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1643 | field->arg1, |
| 1644 | field->arg2, |
| 1645 | field->arg3); |
Ingo Molnar | f0a920d | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 1646 | break; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1647 | } |
| 1648 | case TRACE_STACK: { |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 1649 | struct stack_entry *field; |
| 1650 | |
| 1651 | trace_assign_type(field, entry); |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1652 | |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1653 | for (i = 0; i < FTRACE_STACK_ENTRIES; i++) { |
| 1654 | if (i) |
| 1655 | trace_seq_puts(s, " <= "); |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1656 | seq_print_ip_sym(s, field->caller[i], sym_flags); |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1657 | } |
| 1658 | trace_seq_puts(s, "\n"); |
| 1659 | break; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1660 | } |
| 1661 | case TRACE_PRINT: { |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 1662 | struct print_entry *field; |
| 1663 | |
| 1664 | trace_assign_type(field, entry); |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1665 | |
| 1666 | seq_print_ip_sym(s, field->ip, sym_flags); |
| 1667 | trace_seq_printf(s, ": %s", field->buf); |
| 1668 | if (entry->flags & TRACE_FLAG_CONT) |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1669 | trace_seq_print_cont(s, iter); |
| 1670 | break; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1671 | } |
Steven Rostedt | 9f029e8 | 2008-11-12 15:24:24 -0500 | [diff] [blame] | 1672 | case TRACE_BRANCH: { |
| 1673 | struct trace_branch *field; |
Steven Rostedt | 52f232c | 2008-11-12 00:14:40 -0500 | [diff] [blame] | 1674 | |
| 1675 | trace_assign_type(field, entry); |
| 1676 | |
| 1677 | trace_seq_printf(s, "[%s] %s:%s:%d\n", |
Ingo Molnar | 68d119f | 2008-11-12 14:09:30 +0100 | [diff] [blame] | 1678 | field->correct ? " ok " : " MISS ", |
Steven Rostedt | 52f232c | 2008-11-12 00:14:40 -0500 | [diff] [blame] | 1679 | field->func, |
| 1680 | field->file, |
| 1681 | field->line); |
| 1682 | break; |
| 1683 | } |
Steven Rostedt | 89b2f97 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 1684 | default: |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1685 | trace_seq_printf(s, "Unknown type %d\n", entry->type); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1686 | } |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 1687 | return TRACE_TYPE_HANDLED; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1688 | } |
| 1689 | |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 1690 | static enum print_line_t print_trace_fmt(struct trace_iterator *iter) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1691 | { |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1692 | struct trace_seq *s = &iter->seq; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1693 | unsigned long sym_flags = (trace_flags & TRACE_ITER_SYM_MASK); |
Ingo Molnar | 4e3c333 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 1694 | struct trace_entry *entry; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1695 | unsigned long usec_rem; |
| 1696 | unsigned long long t; |
| 1697 | unsigned long secs; |
| 1698 | char *comm; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1699 | int ret; |
Peter Zijlstra | bac524d | 2008-05-12 21:20:53 +0200 | [diff] [blame] | 1700 | int S, T; |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1701 | int i; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1702 | |
Ingo Molnar | 4e3c333 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 1703 | entry = iter->ent; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1704 | |
| 1705 | if (entry->type == TRACE_CONT) |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 1706 | return TRACE_TYPE_HANDLED; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1707 | |
Steven Rostedt | a309720 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 1708 | test_cpu_buff_start(iter); |
| 1709 | |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1710 | comm = trace_find_cmdline(iter->ent->pid); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1711 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1712 | t = ns2usecs(iter->ts); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1713 | usec_rem = do_div(t, 1000000ULL); |
| 1714 | secs = (unsigned long)t; |
| 1715 | |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1716 | ret = trace_seq_printf(s, "%16s-%-5d ", comm, entry->pid); |
Ingo Molnar | f29c73f | 2008-05-12 21:20:53 +0200 | [diff] [blame] | 1717 | if (!ret) |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 1718 | return TRACE_TYPE_PARTIAL_LINE; |
Michael Ellerman | a616835 | 2008-08-20 16:36:11 -0700 | [diff] [blame] | 1719 | ret = trace_seq_printf(s, "[%03d] ", iter->cpu); |
Ingo Molnar | f29c73f | 2008-05-12 21:20:53 +0200 | [diff] [blame] | 1720 | if (!ret) |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 1721 | return TRACE_TYPE_PARTIAL_LINE; |
Ingo Molnar | f29c73f | 2008-05-12 21:20:53 +0200 | [diff] [blame] | 1722 | ret = trace_seq_printf(s, "%5lu.%06lu: ", secs, usec_rem); |
| 1723 | if (!ret) |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 1724 | return TRACE_TYPE_PARTIAL_LINE; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1725 | |
| 1726 | switch (entry->type) { |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1727 | case TRACE_FN: { |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 1728 | struct ftrace_entry *field; |
| 1729 | |
| 1730 | trace_assign_type(field, entry); |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1731 | |
| 1732 | ret = seq_print_ip_sym(s, field->ip, sym_flags); |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1733 | if (!ret) |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 1734 | return TRACE_TYPE_PARTIAL_LINE; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1735 | if ((sym_flags & TRACE_ITER_PRINT_PARENT) && |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1736 | field->parent_ip) { |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1737 | ret = trace_seq_printf(s, " <-"); |
| 1738 | if (!ret) |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 1739 | return TRACE_TYPE_PARTIAL_LINE; |
Steven Rostedt | b3aa557 | 2008-10-31 15:44:07 -0400 | [diff] [blame] | 1740 | ret = seq_print_ip_sym(s, |
| 1741 | field->parent_ip, |
| 1742 | sym_flags); |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1743 | if (!ret) |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 1744 | return TRACE_TYPE_PARTIAL_LINE; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1745 | } |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1746 | ret = trace_seq_printf(s, "\n"); |
| 1747 | if (!ret) |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 1748 | return TRACE_TYPE_PARTIAL_LINE; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1749 | break; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1750 | } |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1751 | case TRACE_CTX: |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1752 | case TRACE_WAKE: { |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 1753 | struct ctx_switch_entry *field; |
| 1754 | |
| 1755 | trace_assign_type(field, entry); |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1756 | |
| 1757 | S = field->prev_state < sizeof(state_to_char) ? |
| 1758 | state_to_char[field->prev_state] : 'X'; |
| 1759 | T = field->next_state < sizeof(state_to_char) ? |
| 1760 | state_to_char[field->next_state] : 'X'; |
Peter Zijlstra | 80b5e94 | 2008-09-04 10:24:16 +0200 | [diff] [blame] | 1761 | ret = trace_seq_printf(s, " %5d:%3d:%c %s [%03d] %5d:%3d:%c\n", |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1762 | field->prev_pid, |
| 1763 | field->prev_prio, |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1764 | S, |
Ingo Molnar | 5742279 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1765 | entry->type == TRACE_CTX ? "==>" : " +", |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1766 | field->next_cpu, |
| 1767 | field->next_pid, |
| 1768 | field->next_prio, |
Peter Zijlstra | bac524d | 2008-05-12 21:20:53 +0200 | [diff] [blame] | 1769 | T); |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1770 | if (!ret) |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 1771 | return TRACE_TYPE_PARTIAL_LINE; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1772 | break; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1773 | } |
| 1774 | case TRACE_SPECIAL: { |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 1775 | struct special_entry *field; |
| 1776 | |
| 1777 | trace_assign_type(field, entry); |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1778 | |
Ingo Molnar | 88a4216 | 2008-05-12 21:20:53 +0200 | [diff] [blame] | 1779 | ret = trace_seq_printf(s, "# %ld %ld %ld\n", |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1780 | field->arg1, |
| 1781 | field->arg2, |
| 1782 | field->arg3); |
Ingo Molnar | f0a920d | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 1783 | if (!ret) |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 1784 | return TRACE_TYPE_PARTIAL_LINE; |
Ingo Molnar | f0a920d | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 1785 | break; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1786 | } |
| 1787 | case TRACE_STACK: { |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 1788 | struct stack_entry *field; |
| 1789 | |
| 1790 | trace_assign_type(field, entry); |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1791 | |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1792 | for (i = 0; i < FTRACE_STACK_ENTRIES; i++) { |
| 1793 | if (i) { |
| 1794 | ret = trace_seq_puts(s, " <= "); |
| 1795 | if (!ret) |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 1796 | return TRACE_TYPE_PARTIAL_LINE; |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1797 | } |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1798 | ret = seq_print_ip_sym(s, field->caller[i], |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1799 | sym_flags); |
| 1800 | if (!ret) |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 1801 | return TRACE_TYPE_PARTIAL_LINE; |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1802 | } |
| 1803 | ret = trace_seq_puts(s, "\n"); |
| 1804 | if (!ret) |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 1805 | return TRACE_TYPE_PARTIAL_LINE; |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1806 | break; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1807 | } |
| 1808 | case TRACE_PRINT: { |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 1809 | struct print_entry *field; |
| 1810 | |
| 1811 | trace_assign_type(field, entry); |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1812 | |
| 1813 | seq_print_ip_sym(s, field->ip, sym_flags); |
| 1814 | trace_seq_printf(s, ": %s", field->buf); |
| 1815 | if (entry->flags & TRACE_FLAG_CONT) |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1816 | trace_seq_print_cont(s, iter); |
| 1817 | break; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1818 | } |
Frederic Weisbecker | 15e6cb3 | 2008-11-11 07:14:25 +0100 | [diff] [blame] | 1819 | case TRACE_FN_RET: { |
| 1820 | return print_return_function(iter); |
| 1821 | break; |
| 1822 | } |
Steven Rostedt | 9f029e8 | 2008-11-12 15:24:24 -0500 | [diff] [blame] | 1823 | case TRACE_BRANCH: { |
| 1824 | struct trace_branch *field; |
Steven Rostedt | 52f232c | 2008-11-12 00:14:40 -0500 | [diff] [blame] | 1825 | |
| 1826 | trace_assign_type(field, entry); |
| 1827 | |
| 1828 | trace_seq_printf(s, "[%s] %s:%s:%d\n", |
Ingo Molnar | 68d119f | 2008-11-12 14:09:30 +0100 | [diff] [blame] | 1829 | field->correct ? " ok " : " MISS ", |
Steven Rostedt | 52f232c | 2008-11-12 00:14:40 -0500 | [diff] [blame] | 1830 | field->func, |
| 1831 | field->file, |
| 1832 | field->line); |
| 1833 | break; |
| 1834 | } |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1835 | } |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 1836 | return TRACE_TYPE_HANDLED; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1837 | } |
| 1838 | |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 1839 | static enum print_line_t print_raw_fmt(struct trace_iterator *iter) |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 1840 | { |
| 1841 | struct trace_seq *s = &iter->seq; |
| 1842 | struct trace_entry *entry; |
| 1843 | int ret; |
Peter Zijlstra | bac524d | 2008-05-12 21:20:53 +0200 | [diff] [blame] | 1844 | int S, T; |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 1845 | |
| 1846 | entry = iter->ent; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1847 | |
| 1848 | if (entry->type == TRACE_CONT) |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 1849 | return TRACE_TYPE_HANDLED; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1850 | |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 1851 | ret = trace_seq_printf(s, "%d %d %llu ", |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1852 | entry->pid, iter->cpu, iter->ts); |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 1853 | if (!ret) |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 1854 | return TRACE_TYPE_PARTIAL_LINE; |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 1855 | |
| 1856 | switch (entry->type) { |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1857 | case TRACE_FN: { |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 1858 | struct ftrace_entry *field; |
| 1859 | |
| 1860 | trace_assign_type(field, entry); |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1861 | |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 1862 | ret = trace_seq_printf(s, "%x %x\n", |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1863 | field->ip, |
| 1864 | field->parent_ip); |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 1865 | if (!ret) |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 1866 | return TRACE_TYPE_PARTIAL_LINE; |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 1867 | break; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1868 | } |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 1869 | case TRACE_CTX: |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1870 | case TRACE_WAKE: { |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 1871 | struct ctx_switch_entry *field; |
| 1872 | |
| 1873 | trace_assign_type(field, entry); |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1874 | |
| 1875 | S = field->prev_state < sizeof(state_to_char) ? |
| 1876 | state_to_char[field->prev_state] : 'X'; |
| 1877 | T = field->next_state < sizeof(state_to_char) ? |
| 1878 | state_to_char[field->next_state] : 'X'; |
Ingo Molnar | 5742279 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1879 | if (entry->type == TRACE_WAKE) |
| 1880 | S = '+'; |
Peter Zijlstra | 80b5e94 | 2008-09-04 10:24:16 +0200 | [diff] [blame] | 1881 | ret = trace_seq_printf(s, "%d %d %c %d %d %d %c\n", |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1882 | field->prev_pid, |
| 1883 | field->prev_prio, |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 1884 | S, |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1885 | field->next_cpu, |
| 1886 | field->next_pid, |
| 1887 | field->next_prio, |
Peter Zijlstra | bac524d | 2008-05-12 21:20:53 +0200 | [diff] [blame] | 1888 | T); |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 1889 | if (!ret) |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 1890 | return TRACE_TYPE_PARTIAL_LINE; |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 1891 | break; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1892 | } |
Ingo Molnar | f0a920d | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 1893 | case TRACE_SPECIAL: |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1894 | case TRACE_STACK: { |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 1895 | struct special_entry *field; |
| 1896 | |
| 1897 | trace_assign_type(field, entry); |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1898 | |
Ingo Molnar | 88a4216 | 2008-05-12 21:20:53 +0200 | [diff] [blame] | 1899 | ret = trace_seq_printf(s, "# %ld %ld %ld\n", |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1900 | field->arg1, |
| 1901 | field->arg2, |
| 1902 | field->arg3); |
Ingo Molnar | f0a920d | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 1903 | if (!ret) |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 1904 | return TRACE_TYPE_PARTIAL_LINE; |
Ingo Molnar | f0a920d | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 1905 | break; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1906 | } |
| 1907 | case TRACE_PRINT: { |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 1908 | struct print_entry *field; |
| 1909 | |
| 1910 | trace_assign_type(field, entry); |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1911 | |
| 1912 | trace_seq_printf(s, "# %lx %s", field->ip, field->buf); |
| 1913 | if (entry->flags & TRACE_FLAG_CONT) |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1914 | trace_seq_print_cont(s, iter); |
| 1915 | break; |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 1916 | } |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1917 | } |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 1918 | return TRACE_TYPE_HANDLED; |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 1919 | } |
| 1920 | |
Ingo Molnar | cb0f12a | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 1921 | #define SEQ_PUT_FIELD_RET(s, x) \ |
| 1922 | do { \ |
| 1923 | if (!trace_seq_putmem(s, &(x), sizeof(x))) \ |
| 1924 | return 0; \ |
| 1925 | } while (0) |
| 1926 | |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 1927 | #define SEQ_PUT_HEX_FIELD_RET(s, x) \ |
| 1928 | do { \ |
Harvey Harrison | ad0a3b6 | 2008-10-08 17:44:55 -0700 | [diff] [blame] | 1929 | BUILD_BUG_ON(sizeof(x) > MAX_MEMHEX_BYTES); \ |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 1930 | if (!trace_seq_putmem_hex(s, &(x), sizeof(x))) \ |
| 1931 | return 0; \ |
| 1932 | } while (0) |
| 1933 | |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 1934 | static enum print_line_t print_hex_fmt(struct trace_iterator *iter) |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 1935 | { |
| 1936 | struct trace_seq *s = &iter->seq; |
| 1937 | unsigned char newline = '\n'; |
| 1938 | struct trace_entry *entry; |
Peter Zijlstra | bac524d | 2008-05-12 21:20:53 +0200 | [diff] [blame] | 1939 | int S, T; |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 1940 | |
| 1941 | entry = iter->ent; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1942 | |
| 1943 | if (entry->type == TRACE_CONT) |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 1944 | return TRACE_TYPE_HANDLED; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1945 | |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1946 | SEQ_PUT_HEX_FIELD_RET(s, entry->pid); |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 1947 | SEQ_PUT_HEX_FIELD_RET(s, iter->cpu); |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1948 | SEQ_PUT_HEX_FIELD_RET(s, iter->ts); |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 1949 | |
| 1950 | switch (entry->type) { |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1951 | case TRACE_FN: { |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 1952 | struct ftrace_entry *field; |
| 1953 | |
| 1954 | trace_assign_type(field, entry); |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1955 | |
| 1956 | SEQ_PUT_HEX_FIELD_RET(s, field->ip); |
| 1957 | SEQ_PUT_HEX_FIELD_RET(s, field->parent_ip); |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 1958 | break; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1959 | } |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 1960 | case TRACE_CTX: |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1961 | case TRACE_WAKE: { |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 1962 | struct ctx_switch_entry *field; |
| 1963 | |
| 1964 | trace_assign_type(field, entry); |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1965 | |
| 1966 | S = field->prev_state < sizeof(state_to_char) ? |
| 1967 | state_to_char[field->prev_state] : 'X'; |
| 1968 | T = field->next_state < sizeof(state_to_char) ? |
| 1969 | state_to_char[field->next_state] : 'X'; |
Ingo Molnar | 5742279 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1970 | if (entry->type == TRACE_WAKE) |
| 1971 | S = '+'; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1972 | SEQ_PUT_HEX_FIELD_RET(s, field->prev_pid); |
| 1973 | SEQ_PUT_HEX_FIELD_RET(s, field->prev_prio); |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 1974 | SEQ_PUT_HEX_FIELD_RET(s, S); |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1975 | SEQ_PUT_HEX_FIELD_RET(s, field->next_cpu); |
| 1976 | SEQ_PUT_HEX_FIELD_RET(s, field->next_pid); |
| 1977 | SEQ_PUT_HEX_FIELD_RET(s, field->next_prio); |
Peter Zijlstra | bac524d | 2008-05-12 21:20:53 +0200 | [diff] [blame] | 1978 | SEQ_PUT_HEX_FIELD_RET(s, T); |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 1979 | break; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1980 | } |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 1981 | case TRACE_SPECIAL: |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1982 | case TRACE_STACK: { |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 1983 | struct special_entry *field; |
| 1984 | |
| 1985 | trace_assign_type(field, entry); |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1986 | |
| 1987 | SEQ_PUT_HEX_FIELD_RET(s, field->arg1); |
| 1988 | SEQ_PUT_HEX_FIELD_RET(s, field->arg2); |
| 1989 | SEQ_PUT_HEX_FIELD_RET(s, field->arg3); |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 1990 | break; |
| 1991 | } |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1992 | } |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 1993 | SEQ_PUT_FIELD_RET(s, newline); |
| 1994 | |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 1995 | return TRACE_TYPE_HANDLED; |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 1996 | } |
| 1997 | |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 1998 | static enum print_line_t print_bin_fmt(struct trace_iterator *iter) |
Ingo Molnar | cb0f12a | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 1999 | { |
| 2000 | struct trace_seq *s = &iter->seq; |
| 2001 | struct trace_entry *entry; |
| 2002 | |
| 2003 | entry = iter->ent; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2004 | |
| 2005 | if (entry->type == TRACE_CONT) |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 2006 | return TRACE_TYPE_HANDLED; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2007 | |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 2008 | SEQ_PUT_FIELD_RET(s, entry->pid); |
Eric Anholt | 072ba49 | 2008-10-26 15:26:57 -0700 | [diff] [blame] | 2009 | SEQ_PUT_FIELD_RET(s, entry->cpu); |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2010 | SEQ_PUT_FIELD_RET(s, iter->ts); |
Ingo Molnar | cb0f12a | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2011 | |
| 2012 | switch (entry->type) { |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 2013 | case TRACE_FN: { |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 2014 | struct ftrace_entry *field; |
| 2015 | |
| 2016 | trace_assign_type(field, entry); |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 2017 | |
| 2018 | SEQ_PUT_FIELD_RET(s, field->ip); |
| 2019 | SEQ_PUT_FIELD_RET(s, field->parent_ip); |
Ingo Molnar | cb0f12a | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2020 | break; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 2021 | } |
| 2022 | case TRACE_CTX: { |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 2023 | struct ctx_switch_entry *field; |
| 2024 | |
| 2025 | trace_assign_type(field, entry); |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 2026 | |
| 2027 | SEQ_PUT_FIELD_RET(s, field->prev_pid); |
| 2028 | SEQ_PUT_FIELD_RET(s, field->prev_prio); |
| 2029 | SEQ_PUT_FIELD_RET(s, field->prev_state); |
| 2030 | SEQ_PUT_FIELD_RET(s, field->next_pid); |
| 2031 | SEQ_PUT_FIELD_RET(s, field->next_prio); |
| 2032 | SEQ_PUT_FIELD_RET(s, field->next_state); |
Ingo Molnar | cb0f12a | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2033 | break; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 2034 | } |
Ingo Molnar | f0a920d | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2035 | case TRACE_SPECIAL: |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 2036 | case TRACE_STACK: { |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 2037 | struct special_entry *field; |
| 2038 | |
| 2039 | trace_assign_type(field, entry); |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 2040 | |
| 2041 | SEQ_PUT_FIELD_RET(s, field->arg1); |
| 2042 | SEQ_PUT_FIELD_RET(s, field->arg2); |
| 2043 | SEQ_PUT_FIELD_RET(s, field->arg3); |
Ingo Molnar | f0a920d | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2044 | break; |
Ingo Molnar | cb0f12a | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2045 | } |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 2046 | } |
Ingo Molnar | cb0f12a | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2047 | return 1; |
| 2048 | } |
| 2049 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2050 | static int trace_empty(struct trace_iterator *iter) |
| 2051 | { |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2052 | int cpu; |
| 2053 | |
Steven Rostedt | ab46428 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 2054 | for_each_tracing_cpu(cpu) { |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 2055 | if (iter->buffer_iter[cpu]) { |
| 2056 | if (!ring_buffer_iter_empty(iter->buffer_iter[cpu])) |
| 2057 | return 0; |
| 2058 | } else { |
| 2059 | if (!ring_buffer_empty_cpu(iter->tr->buffer, cpu)) |
| 2060 | return 0; |
| 2061 | } |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2062 | } |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 2063 | |
Frederic Weisbecker | 797d371 | 2008-09-30 18:13:45 +0200 | [diff] [blame] | 2064 | return 1; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2065 | } |
| 2066 | |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 2067 | static enum print_line_t print_trace_line(struct trace_iterator *iter) |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2068 | { |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 2069 | enum print_line_t ret; |
| 2070 | |
| 2071 | if (iter->trace && iter->trace->print_line) { |
| 2072 | ret = iter->trace->print_line(iter); |
| 2073 | if (ret != TRACE_TYPE_UNHANDLED) |
| 2074 | return ret; |
| 2075 | } |
Thomas Gleixner | 72829bc | 2008-05-23 21:37:28 +0200 | [diff] [blame] | 2076 | |
Ingo Molnar | cb0f12a | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2077 | if (trace_flags & TRACE_ITER_BIN) |
| 2078 | return print_bin_fmt(iter); |
| 2079 | |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 2080 | if (trace_flags & TRACE_ITER_HEX) |
| 2081 | return print_hex_fmt(iter); |
| 2082 | |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2083 | if (trace_flags & TRACE_ITER_RAW) |
| 2084 | return print_raw_fmt(iter); |
| 2085 | |
| 2086 | if (iter->iter_flags & TRACE_FILE_LAT_FMT) |
| 2087 | return print_lat_fmt(iter, iter->idx, iter->cpu); |
| 2088 | |
| 2089 | return print_trace_fmt(iter); |
| 2090 | } |
| 2091 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2092 | static int s_show(struct seq_file *m, void *v) |
| 2093 | { |
| 2094 | struct trace_iterator *iter = v; |
| 2095 | |
| 2096 | if (iter->ent == NULL) { |
| 2097 | if (iter->tr) { |
| 2098 | seq_printf(m, "# tracer: %s\n", iter->trace->name); |
| 2099 | seq_puts(m, "#\n"); |
| 2100 | } |
| 2101 | if (iter->iter_flags & TRACE_FILE_LAT_FMT) { |
| 2102 | /* print nothing if the buffers are empty */ |
| 2103 | if (trace_empty(iter)) |
| 2104 | return 0; |
| 2105 | print_trace_header(m, iter); |
| 2106 | if (!(trace_flags & TRACE_ITER_VERBOSE)) |
| 2107 | print_lat_help_header(m); |
| 2108 | } else { |
| 2109 | if (!(trace_flags & TRACE_ITER_VERBOSE)) |
| 2110 | print_func_help_header(m); |
| 2111 | } |
| 2112 | } else { |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2113 | print_trace_line(iter); |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2114 | trace_print_seq(m, &iter->seq); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2115 | } |
| 2116 | |
| 2117 | return 0; |
| 2118 | } |
| 2119 | |
| 2120 | static struct seq_operations tracer_seq_ops = { |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2121 | .start = s_start, |
| 2122 | .next = s_next, |
| 2123 | .stop = s_stop, |
| 2124 | .show = s_show, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2125 | }; |
| 2126 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 2127 | static struct trace_iterator * |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2128 | __tracing_open(struct inode *inode, struct file *file, int *ret) |
| 2129 | { |
| 2130 | struct trace_iterator *iter; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2131 | struct seq_file *m; |
| 2132 | int cpu; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2133 | |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 2134 | if (tracing_disabled) { |
| 2135 | *ret = -ENODEV; |
| 2136 | return NULL; |
| 2137 | } |
| 2138 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2139 | iter = kzalloc(sizeof(*iter), GFP_KERNEL); |
| 2140 | if (!iter) { |
| 2141 | *ret = -ENOMEM; |
| 2142 | goto out; |
| 2143 | } |
| 2144 | |
| 2145 | mutex_lock(&trace_types_lock); |
| 2146 | if (current_trace && current_trace->print_max) |
| 2147 | iter->tr = &max_tr; |
| 2148 | else |
| 2149 | iter->tr = inode->i_private; |
| 2150 | iter->trace = current_trace; |
| 2151 | iter->pos = -1; |
| 2152 | |
Steven Rostedt | 12ef7d4 | 2008-11-12 17:52:38 -0500 | [diff] [blame] | 2153 | /* Annotate start of buffers if we had overruns */ |
| 2154 | if (ring_buffer_overruns(iter->tr->buffer)) |
| 2155 | iter->iter_flags |= TRACE_FILE_ANNOTATE; |
| 2156 | |
| 2157 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2158 | for_each_tracing_cpu(cpu) { |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 2159 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2160 | iter->buffer_iter[cpu] = |
| 2161 | ring_buffer_read_start(iter->tr->buffer, cpu); |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 2162 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2163 | if (!iter->buffer_iter[cpu]) |
| 2164 | goto fail_buffer; |
| 2165 | } |
| 2166 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2167 | /* TODO stop tracer */ |
| 2168 | *ret = seq_open(file, &tracer_seq_ops); |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2169 | if (*ret) |
| 2170 | goto fail_buffer; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2171 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2172 | m = file->private_data; |
| 2173 | m->private = iter; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2174 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2175 | /* stop the trace while dumping */ |
Steven Rostedt | 9036990 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 2176 | tracing_stop(); |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2177 | |
| 2178 | if (iter->trace && iter->trace->open) |
| 2179 | iter->trace->open(iter); |
| 2180 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2181 | mutex_unlock(&trace_types_lock); |
| 2182 | |
| 2183 | out: |
| 2184 | return iter; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2185 | |
| 2186 | fail_buffer: |
| 2187 | for_each_tracing_cpu(cpu) { |
| 2188 | if (iter->buffer_iter[cpu]) |
| 2189 | ring_buffer_read_finish(iter->buffer_iter[cpu]); |
| 2190 | } |
| 2191 | mutex_unlock(&trace_types_lock); |
| 2192 | |
| 2193 | return ERR_PTR(-ENOMEM); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2194 | } |
| 2195 | |
| 2196 | int tracing_open_generic(struct inode *inode, struct file *filp) |
| 2197 | { |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 2198 | if (tracing_disabled) |
| 2199 | return -ENODEV; |
| 2200 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2201 | filp->private_data = inode->i_private; |
| 2202 | return 0; |
| 2203 | } |
| 2204 | |
| 2205 | int tracing_release(struct inode *inode, struct file *file) |
| 2206 | { |
| 2207 | struct seq_file *m = (struct seq_file *)file->private_data; |
| 2208 | struct trace_iterator *iter = m->private; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2209 | int cpu; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2210 | |
| 2211 | mutex_lock(&trace_types_lock); |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2212 | for_each_tracing_cpu(cpu) { |
| 2213 | if (iter->buffer_iter[cpu]) |
| 2214 | ring_buffer_read_finish(iter->buffer_iter[cpu]); |
| 2215 | } |
| 2216 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2217 | if (iter->trace && iter->trace->close) |
| 2218 | iter->trace->close(iter); |
| 2219 | |
| 2220 | /* reenable tracing if it was previously enabled */ |
Steven Rostedt | 9036990 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 2221 | tracing_start(); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2222 | mutex_unlock(&trace_types_lock); |
| 2223 | |
| 2224 | seq_release(inode, file); |
| 2225 | kfree(iter); |
| 2226 | return 0; |
| 2227 | } |
| 2228 | |
| 2229 | static int tracing_open(struct inode *inode, struct file *file) |
| 2230 | { |
| 2231 | int ret; |
| 2232 | |
| 2233 | __tracing_open(inode, file, &ret); |
| 2234 | |
| 2235 | return ret; |
| 2236 | } |
| 2237 | |
| 2238 | static int tracing_lt_open(struct inode *inode, struct file *file) |
| 2239 | { |
| 2240 | struct trace_iterator *iter; |
| 2241 | int ret; |
| 2242 | |
| 2243 | iter = __tracing_open(inode, file, &ret); |
| 2244 | |
| 2245 | if (!ret) |
| 2246 | iter->iter_flags |= TRACE_FILE_LAT_FMT; |
| 2247 | |
| 2248 | return ret; |
| 2249 | } |
| 2250 | |
| 2251 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 2252 | static void * |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2253 | t_next(struct seq_file *m, void *v, loff_t *pos) |
| 2254 | { |
| 2255 | struct tracer *t = m->private; |
| 2256 | |
| 2257 | (*pos)++; |
| 2258 | |
| 2259 | if (t) |
| 2260 | t = t->next; |
| 2261 | |
| 2262 | m->private = t; |
| 2263 | |
| 2264 | return t; |
| 2265 | } |
| 2266 | |
| 2267 | static void *t_start(struct seq_file *m, loff_t *pos) |
| 2268 | { |
| 2269 | struct tracer *t = m->private; |
| 2270 | loff_t l = 0; |
| 2271 | |
| 2272 | mutex_lock(&trace_types_lock); |
| 2273 | for (; t && l < *pos; t = t_next(m, t, &l)) |
| 2274 | ; |
| 2275 | |
| 2276 | return t; |
| 2277 | } |
| 2278 | |
| 2279 | static void t_stop(struct seq_file *m, void *p) |
| 2280 | { |
| 2281 | mutex_unlock(&trace_types_lock); |
| 2282 | } |
| 2283 | |
| 2284 | static int t_show(struct seq_file *m, void *v) |
| 2285 | { |
| 2286 | struct tracer *t = v; |
| 2287 | |
| 2288 | if (!t) |
| 2289 | return 0; |
| 2290 | |
| 2291 | seq_printf(m, "%s", t->name); |
| 2292 | if (t->next) |
| 2293 | seq_putc(m, ' '); |
| 2294 | else |
| 2295 | seq_putc(m, '\n'); |
| 2296 | |
| 2297 | return 0; |
| 2298 | } |
| 2299 | |
| 2300 | static struct seq_operations show_traces_seq_ops = { |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2301 | .start = t_start, |
| 2302 | .next = t_next, |
| 2303 | .stop = t_stop, |
| 2304 | .show = t_show, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2305 | }; |
| 2306 | |
| 2307 | static int show_traces_open(struct inode *inode, struct file *file) |
| 2308 | { |
| 2309 | int ret; |
| 2310 | |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 2311 | if (tracing_disabled) |
| 2312 | return -ENODEV; |
| 2313 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2314 | ret = seq_open(file, &show_traces_seq_ops); |
| 2315 | if (!ret) { |
| 2316 | struct seq_file *m = file->private_data; |
| 2317 | m->private = trace_types; |
| 2318 | } |
| 2319 | |
| 2320 | return ret; |
| 2321 | } |
| 2322 | |
| 2323 | static struct file_operations tracing_fops = { |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2324 | .open = tracing_open, |
| 2325 | .read = seq_read, |
| 2326 | .llseek = seq_lseek, |
| 2327 | .release = tracing_release, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2328 | }; |
| 2329 | |
| 2330 | static struct file_operations tracing_lt_fops = { |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2331 | .open = tracing_lt_open, |
| 2332 | .read = seq_read, |
| 2333 | .llseek = seq_lseek, |
| 2334 | .release = tracing_release, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2335 | }; |
| 2336 | |
| 2337 | static struct file_operations show_traces_fops = { |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2338 | .open = show_traces_open, |
| 2339 | .read = seq_read, |
| 2340 | .release = seq_release, |
| 2341 | }; |
| 2342 | |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2343 | /* |
| 2344 | * Only trace on a CPU if the bitmask is set: |
| 2345 | */ |
| 2346 | static cpumask_t tracing_cpumask = CPU_MASK_ALL; |
| 2347 | |
| 2348 | /* |
| 2349 | * When tracing/tracing_cpu_mask is modified then this holds |
| 2350 | * the new bitmask we are about to install: |
| 2351 | */ |
| 2352 | static cpumask_t tracing_cpumask_new; |
| 2353 | |
| 2354 | /* |
| 2355 | * The tracer itself will not take this lock, but still we want |
| 2356 | * to provide a consistent cpumask to user-space: |
| 2357 | */ |
| 2358 | static DEFINE_MUTEX(tracing_cpumask_update_lock); |
| 2359 | |
| 2360 | /* |
| 2361 | * Temporary storage for the character representation of the |
| 2362 | * CPU bitmask (and one more byte for the newline): |
| 2363 | */ |
| 2364 | static char mask_str[NR_CPUS + 1]; |
| 2365 | |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2366 | static ssize_t |
| 2367 | tracing_cpumask_read(struct file *filp, char __user *ubuf, |
| 2368 | size_t count, loff_t *ppos) |
| 2369 | { |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2370 | int len; |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2371 | |
| 2372 | mutex_lock(&tracing_cpumask_update_lock); |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2373 | |
| 2374 | len = cpumask_scnprintf(mask_str, count, tracing_cpumask); |
| 2375 | if (count - len < 2) { |
| 2376 | count = -EINVAL; |
| 2377 | goto out_err; |
| 2378 | } |
| 2379 | len += sprintf(mask_str + len, "\n"); |
| 2380 | count = simple_read_from_buffer(ubuf, count, ppos, mask_str, NR_CPUS+1); |
| 2381 | |
| 2382 | out_err: |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2383 | mutex_unlock(&tracing_cpumask_update_lock); |
| 2384 | |
| 2385 | return count; |
| 2386 | } |
| 2387 | |
| 2388 | static ssize_t |
| 2389 | tracing_cpumask_write(struct file *filp, const char __user *ubuf, |
| 2390 | size_t count, loff_t *ppos) |
| 2391 | { |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2392 | int err, cpu; |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2393 | |
| 2394 | mutex_lock(&tracing_cpumask_update_lock); |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2395 | err = cpumask_parse_user(ubuf, count, tracing_cpumask_new); |
| 2396 | if (err) |
| 2397 | goto err_unlock; |
| 2398 | |
Steven Rostedt | 92205c2 | 2008-05-12 21:20:55 +0200 | [diff] [blame] | 2399 | raw_local_irq_disable(); |
| 2400 | __raw_spin_lock(&ftrace_max_lock); |
Steven Rostedt | ab46428 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 2401 | for_each_tracing_cpu(cpu) { |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2402 | /* |
| 2403 | * Increase/decrease the disabled counter if we are |
| 2404 | * about to flip a bit in the cpumask: |
| 2405 | */ |
| 2406 | if (cpu_isset(cpu, tracing_cpumask) && |
| 2407 | !cpu_isset(cpu, tracing_cpumask_new)) { |
| 2408 | atomic_inc(&global_trace.data[cpu]->disabled); |
| 2409 | } |
| 2410 | if (!cpu_isset(cpu, tracing_cpumask) && |
| 2411 | cpu_isset(cpu, tracing_cpumask_new)) { |
| 2412 | atomic_dec(&global_trace.data[cpu]->disabled); |
| 2413 | } |
| 2414 | } |
Steven Rostedt | 92205c2 | 2008-05-12 21:20:55 +0200 | [diff] [blame] | 2415 | __raw_spin_unlock(&ftrace_max_lock); |
| 2416 | raw_local_irq_enable(); |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2417 | |
| 2418 | tracing_cpumask = tracing_cpumask_new; |
| 2419 | |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2420 | mutex_unlock(&tracing_cpumask_update_lock); |
| 2421 | |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2422 | return count; |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2423 | |
| 2424 | err_unlock: |
| 2425 | mutex_unlock(&tracing_cpumask_update_lock); |
| 2426 | |
| 2427 | return err; |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2428 | } |
| 2429 | |
| 2430 | static struct file_operations tracing_cpumask_fops = { |
| 2431 | .open = tracing_open_generic, |
| 2432 | .read = tracing_cpumask_read, |
| 2433 | .write = tracing_cpumask_write, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2434 | }; |
| 2435 | |
| 2436 | static ssize_t |
Steven Rostedt | ee6bce5 | 2008-11-12 17:52:37 -0500 | [diff] [blame] | 2437 | tracing_trace_options_read(struct file *filp, char __user *ubuf, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2438 | size_t cnt, loff_t *ppos) |
| 2439 | { |
| 2440 | char *buf; |
| 2441 | int r = 0; |
| 2442 | int len = 0; |
| 2443 | int i; |
| 2444 | |
| 2445 | /* calulate max size */ |
| 2446 | for (i = 0; trace_options[i]; i++) { |
| 2447 | len += strlen(trace_options[i]); |
| 2448 | len += 3; /* "no" and space */ |
| 2449 | } |
| 2450 | |
| 2451 | /* +2 for \n and \0 */ |
| 2452 | buf = kmalloc(len + 2, GFP_KERNEL); |
| 2453 | if (!buf) |
| 2454 | return -ENOMEM; |
| 2455 | |
| 2456 | for (i = 0; trace_options[i]; i++) { |
| 2457 | if (trace_flags & (1 << i)) |
| 2458 | r += sprintf(buf + r, "%s ", trace_options[i]); |
| 2459 | else |
| 2460 | r += sprintf(buf + r, "no%s ", trace_options[i]); |
| 2461 | } |
| 2462 | |
| 2463 | r += sprintf(buf + r, "\n"); |
| 2464 | WARN_ON(r >= len + 2); |
| 2465 | |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2466 | r = simple_read_from_buffer(ubuf, cnt, ppos, buf, r); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2467 | |
| 2468 | kfree(buf); |
| 2469 | |
| 2470 | return r; |
| 2471 | } |
| 2472 | |
| 2473 | static ssize_t |
Steven Rostedt | ee6bce5 | 2008-11-12 17:52:37 -0500 | [diff] [blame] | 2474 | tracing_trace_options_write(struct file *filp, const char __user *ubuf, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2475 | size_t cnt, loff_t *ppos) |
| 2476 | { |
| 2477 | char buf[64]; |
| 2478 | char *cmp = buf; |
| 2479 | int neg = 0; |
| 2480 | int i; |
| 2481 | |
Steven Rostedt | cffae43 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 2482 | if (cnt >= sizeof(buf)) |
| 2483 | return -EINVAL; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2484 | |
| 2485 | if (copy_from_user(&buf, ubuf, cnt)) |
| 2486 | return -EFAULT; |
| 2487 | |
| 2488 | buf[cnt] = 0; |
| 2489 | |
| 2490 | if (strncmp(buf, "no", 2) == 0) { |
| 2491 | neg = 1; |
| 2492 | cmp += 2; |
| 2493 | } |
| 2494 | |
| 2495 | for (i = 0; trace_options[i]; i++) { |
| 2496 | int len = strlen(trace_options[i]); |
| 2497 | |
| 2498 | if (strncmp(cmp, trace_options[i], len) == 0) { |
| 2499 | if (neg) |
| 2500 | trace_flags &= ~(1 << i); |
| 2501 | else |
| 2502 | trace_flags |= (1 << i); |
| 2503 | break; |
| 2504 | } |
| 2505 | } |
Ingo Molnar | 442e544 | 2008-05-12 21:20:53 +0200 | [diff] [blame] | 2506 | /* |
| 2507 | * If no option could be set, return an error: |
| 2508 | */ |
| 2509 | if (!trace_options[i]) |
| 2510 | return -EINVAL; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2511 | |
| 2512 | filp->f_pos += cnt; |
| 2513 | |
| 2514 | return cnt; |
| 2515 | } |
| 2516 | |
| 2517 | static struct file_operations tracing_iter_fops = { |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2518 | .open = tracing_open_generic, |
Steven Rostedt | ee6bce5 | 2008-11-12 17:52:37 -0500 | [diff] [blame] | 2519 | .read = tracing_trace_options_read, |
| 2520 | .write = tracing_trace_options_write, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2521 | }; |
| 2522 | |
Ingo Molnar | 7bd2f24 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 2523 | static const char readme_msg[] = |
| 2524 | "tracing mini-HOWTO:\n\n" |
| 2525 | "# mkdir /debug\n" |
| 2526 | "# mount -t debugfs nodev /debug\n\n" |
| 2527 | "# cat /debug/tracing/available_tracers\n" |
| 2528 | "wakeup preemptirqsoff preemptoff irqsoff ftrace sched_switch none\n\n" |
| 2529 | "# cat /debug/tracing/current_tracer\n" |
| 2530 | "none\n" |
| 2531 | "# echo sched_switch > /debug/tracing/current_tracer\n" |
| 2532 | "# cat /debug/tracing/current_tracer\n" |
| 2533 | "sched_switch\n" |
Steven Rostedt | ee6bce5 | 2008-11-12 17:52:37 -0500 | [diff] [blame] | 2534 | "# cat /debug/tracing/trace_options\n" |
Ingo Molnar | 7bd2f24 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 2535 | "noprint-parent nosym-offset nosym-addr noverbose\n" |
Steven Rostedt | ee6bce5 | 2008-11-12 17:52:37 -0500 | [diff] [blame] | 2536 | "# echo print-parent > /debug/tracing/trace_options\n" |
Ingo Molnar | 7bd2f24 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 2537 | "# echo 1 > /debug/tracing/tracing_enabled\n" |
| 2538 | "# cat /debug/tracing/trace > /tmp/trace.txt\n" |
| 2539 | "echo 0 > /debug/tracing/tracing_enabled\n" |
| 2540 | ; |
| 2541 | |
| 2542 | static ssize_t |
| 2543 | tracing_readme_read(struct file *filp, char __user *ubuf, |
| 2544 | size_t cnt, loff_t *ppos) |
| 2545 | { |
| 2546 | return simple_read_from_buffer(ubuf, cnt, ppos, |
| 2547 | readme_msg, strlen(readme_msg)); |
| 2548 | } |
| 2549 | |
| 2550 | static struct file_operations tracing_readme_fops = { |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2551 | .open = tracing_open_generic, |
| 2552 | .read = tracing_readme_read, |
Ingo Molnar | 7bd2f24 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 2553 | }; |
| 2554 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2555 | static ssize_t |
| 2556 | tracing_ctrl_read(struct file *filp, char __user *ubuf, |
| 2557 | size_t cnt, loff_t *ppos) |
| 2558 | { |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2559 | char buf[64]; |
| 2560 | int r; |
| 2561 | |
Steven Rostedt | 9036990 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 2562 | r = sprintf(buf, "%u\n", tracer_enabled); |
Ingo Molnar | 4e3c333 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 2563 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, r); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2564 | } |
| 2565 | |
| 2566 | static ssize_t |
| 2567 | tracing_ctrl_write(struct file *filp, const char __user *ubuf, |
| 2568 | size_t cnt, loff_t *ppos) |
| 2569 | { |
| 2570 | struct trace_array *tr = filp->private_data; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2571 | char buf[64]; |
Steven Rostedt | c6caeeb | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 2572 | long val; |
| 2573 | int ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2574 | |
Steven Rostedt | cffae43 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 2575 | if (cnt >= sizeof(buf)) |
| 2576 | return -EINVAL; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2577 | |
| 2578 | if (copy_from_user(&buf, ubuf, cnt)) |
| 2579 | return -EFAULT; |
| 2580 | |
| 2581 | buf[cnt] = 0; |
| 2582 | |
Steven Rostedt | c6caeeb | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 2583 | ret = strict_strtoul(buf, 10, &val); |
| 2584 | if (ret < 0) |
| 2585 | return ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2586 | |
| 2587 | val = !!val; |
| 2588 | |
| 2589 | mutex_lock(&trace_types_lock); |
Steven Rostedt | 9036990 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 2590 | if (tracer_enabled ^ val) { |
| 2591 | if (val) { |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2592 | tracer_enabled = 1; |
Steven Rostedt | 9036990 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 2593 | if (current_trace->start) |
| 2594 | current_trace->start(tr); |
| 2595 | tracing_start(); |
| 2596 | } else { |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2597 | tracer_enabled = 0; |
Steven Rostedt | 9036990 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 2598 | tracing_stop(); |
| 2599 | if (current_trace->stop) |
| 2600 | current_trace->stop(tr); |
| 2601 | } |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2602 | } |
| 2603 | mutex_unlock(&trace_types_lock); |
| 2604 | |
| 2605 | filp->f_pos += cnt; |
| 2606 | |
| 2607 | return cnt; |
| 2608 | } |
| 2609 | |
| 2610 | static ssize_t |
| 2611 | tracing_set_trace_read(struct file *filp, char __user *ubuf, |
| 2612 | size_t cnt, loff_t *ppos) |
| 2613 | { |
| 2614 | char buf[max_tracer_type_len+2]; |
| 2615 | int r; |
| 2616 | |
| 2617 | mutex_lock(&trace_types_lock); |
| 2618 | if (current_trace) |
| 2619 | r = sprintf(buf, "%s\n", current_trace->name); |
| 2620 | else |
| 2621 | r = sprintf(buf, "\n"); |
| 2622 | mutex_unlock(&trace_types_lock); |
| 2623 | |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2624 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, r); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2625 | } |
| 2626 | |
Peter Zijlstra | d9e5407 | 2008-11-01 19:57:37 +0100 | [diff] [blame] | 2627 | static int tracing_set_tracer(char *buf) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2628 | { |
| 2629 | struct trace_array *tr = &global_trace; |
| 2630 | struct tracer *t; |
Peter Zijlstra | d9e5407 | 2008-11-01 19:57:37 +0100 | [diff] [blame] | 2631 | int ret = 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2632 | |
| 2633 | mutex_lock(&trace_types_lock); |
| 2634 | for (t = trace_types; t; t = t->next) { |
| 2635 | if (strcmp(t->name, buf) == 0) |
| 2636 | break; |
| 2637 | } |
Frederic Weisbecker | c2931e0 | 2008-10-04 22:04:44 +0200 | [diff] [blame] | 2638 | if (!t) { |
| 2639 | ret = -EINVAL; |
| 2640 | goto out; |
| 2641 | } |
| 2642 | if (t == current_trace) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2643 | goto out; |
| 2644 | |
Steven Rostedt | 9f029e8 | 2008-11-12 15:24:24 -0500 | [diff] [blame] | 2645 | trace_branch_disable(); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2646 | if (current_trace && current_trace->reset) |
| 2647 | current_trace->reset(tr); |
| 2648 | |
| 2649 | current_trace = t; |
Frederic Weisbecker | 1c80025 | 2008-11-16 05:57:26 +0100 | [diff] [blame] | 2650 | if (t->init) { |
| 2651 | ret = t->init(tr); |
| 2652 | if (ret) |
| 2653 | goto out; |
| 2654 | } |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2655 | |
Steven Rostedt | 9f029e8 | 2008-11-12 15:24:24 -0500 | [diff] [blame] | 2656 | trace_branch_enable(tr); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2657 | out: |
| 2658 | mutex_unlock(&trace_types_lock); |
| 2659 | |
Peter Zijlstra | d9e5407 | 2008-11-01 19:57:37 +0100 | [diff] [blame] | 2660 | return ret; |
| 2661 | } |
| 2662 | |
| 2663 | static ssize_t |
| 2664 | tracing_set_trace_write(struct file *filp, const char __user *ubuf, |
| 2665 | size_t cnt, loff_t *ppos) |
| 2666 | { |
| 2667 | char buf[max_tracer_type_len+1]; |
| 2668 | int i; |
| 2669 | size_t ret; |
Frederic Weisbecker | e6e7a65 | 2008-11-16 05:53:19 +0100 | [diff] [blame] | 2670 | int err; |
| 2671 | |
| 2672 | ret = cnt; |
Peter Zijlstra | d9e5407 | 2008-11-01 19:57:37 +0100 | [diff] [blame] | 2673 | |
| 2674 | if (cnt > max_tracer_type_len) |
| 2675 | cnt = max_tracer_type_len; |
| 2676 | |
| 2677 | if (copy_from_user(&buf, ubuf, cnt)) |
| 2678 | return -EFAULT; |
| 2679 | |
| 2680 | buf[cnt] = 0; |
| 2681 | |
| 2682 | /* strip ending whitespace. */ |
| 2683 | for (i = cnt - 1; i > 0 && isspace(buf[i]); i--) |
| 2684 | buf[i] = 0; |
| 2685 | |
Frederic Weisbecker | e6e7a65 | 2008-11-16 05:53:19 +0100 | [diff] [blame] | 2686 | err = tracing_set_tracer(buf); |
| 2687 | if (err) |
| 2688 | return err; |
Peter Zijlstra | d9e5407 | 2008-11-01 19:57:37 +0100 | [diff] [blame] | 2689 | |
Frederic Weisbecker | e6e7a65 | 2008-11-16 05:53:19 +0100 | [diff] [blame] | 2690 | filp->f_pos += ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2691 | |
Frederic Weisbecker | c2931e0 | 2008-10-04 22:04:44 +0200 | [diff] [blame] | 2692 | return ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2693 | } |
| 2694 | |
| 2695 | static ssize_t |
| 2696 | tracing_max_lat_read(struct file *filp, char __user *ubuf, |
| 2697 | size_t cnt, loff_t *ppos) |
| 2698 | { |
| 2699 | unsigned long *ptr = filp->private_data; |
| 2700 | char buf[64]; |
| 2701 | int r; |
| 2702 | |
Steven Rostedt | cffae43 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 2703 | r = snprintf(buf, sizeof(buf), "%ld\n", |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2704 | *ptr == (unsigned long)-1 ? -1 : nsecs_to_usecs(*ptr)); |
Steven Rostedt | cffae43 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 2705 | if (r > sizeof(buf)) |
| 2706 | r = sizeof(buf); |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2707 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, r); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2708 | } |
| 2709 | |
| 2710 | static ssize_t |
| 2711 | tracing_max_lat_write(struct file *filp, const char __user *ubuf, |
| 2712 | size_t cnt, loff_t *ppos) |
| 2713 | { |
| 2714 | long *ptr = filp->private_data; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2715 | char buf[64]; |
Steven Rostedt | c6caeeb | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 2716 | long val; |
| 2717 | int ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2718 | |
Steven Rostedt | cffae43 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 2719 | if (cnt >= sizeof(buf)) |
| 2720 | return -EINVAL; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2721 | |
| 2722 | if (copy_from_user(&buf, ubuf, cnt)) |
| 2723 | return -EFAULT; |
| 2724 | |
| 2725 | buf[cnt] = 0; |
| 2726 | |
Steven Rostedt | c6caeeb | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 2727 | ret = strict_strtoul(buf, 10, &val); |
| 2728 | if (ret < 0) |
| 2729 | return ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2730 | |
| 2731 | *ptr = val * 1000; |
| 2732 | |
| 2733 | return cnt; |
| 2734 | } |
| 2735 | |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2736 | static atomic_t tracing_reader; |
| 2737 | |
| 2738 | static int tracing_open_pipe(struct inode *inode, struct file *filp) |
| 2739 | { |
| 2740 | struct trace_iterator *iter; |
| 2741 | |
| 2742 | if (tracing_disabled) |
| 2743 | return -ENODEV; |
| 2744 | |
| 2745 | /* We only allow for reader of the pipe */ |
| 2746 | if (atomic_inc_return(&tracing_reader) != 1) { |
| 2747 | atomic_dec(&tracing_reader); |
| 2748 | return -EBUSY; |
| 2749 | } |
| 2750 | |
| 2751 | /* create a buffer to store the information to pass to userspace */ |
| 2752 | iter = kzalloc(sizeof(*iter), GFP_KERNEL); |
| 2753 | if (!iter) |
| 2754 | return -ENOMEM; |
| 2755 | |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 2756 | mutex_lock(&trace_types_lock); |
Steven Rostedt | a309720 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 2757 | |
| 2758 | /* trace pipe does not show start of buffer */ |
| 2759 | cpus_setall(iter->started); |
| 2760 | |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2761 | iter->tr = &global_trace; |
Thomas Gleixner | 72829bc | 2008-05-23 21:37:28 +0200 | [diff] [blame] | 2762 | iter->trace = current_trace; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2763 | filp->private_data = iter; |
| 2764 | |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 2765 | if (iter->trace->pipe_open) |
| 2766 | iter->trace->pipe_open(iter); |
| 2767 | mutex_unlock(&trace_types_lock); |
| 2768 | |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2769 | return 0; |
| 2770 | } |
| 2771 | |
| 2772 | static int tracing_release_pipe(struct inode *inode, struct file *file) |
| 2773 | { |
| 2774 | struct trace_iterator *iter = file->private_data; |
| 2775 | |
| 2776 | kfree(iter); |
| 2777 | atomic_dec(&tracing_reader); |
| 2778 | |
| 2779 | return 0; |
| 2780 | } |
| 2781 | |
Soeren Sandmann Pedersen | 2a2cc8f | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 2782 | static unsigned int |
| 2783 | tracing_poll_pipe(struct file *filp, poll_table *poll_table) |
| 2784 | { |
| 2785 | struct trace_iterator *iter = filp->private_data; |
| 2786 | |
| 2787 | if (trace_flags & TRACE_ITER_BLOCK) { |
| 2788 | /* |
| 2789 | * Always select as readable when in blocking mode |
| 2790 | */ |
| 2791 | return POLLIN | POLLRDNORM; |
Ingo Molnar | afc2abc | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 2792 | } else { |
Soeren Sandmann Pedersen | 2a2cc8f | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 2793 | if (!trace_empty(iter)) |
| 2794 | return POLLIN | POLLRDNORM; |
| 2795 | poll_wait(filp, &trace_wait, poll_table); |
| 2796 | if (!trace_empty(iter)) |
| 2797 | return POLLIN | POLLRDNORM; |
| 2798 | |
| 2799 | return 0; |
| 2800 | } |
| 2801 | } |
| 2802 | |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2803 | /* |
| 2804 | * Consumer reader. |
| 2805 | */ |
| 2806 | static ssize_t |
| 2807 | tracing_read_pipe(struct file *filp, char __user *ubuf, |
| 2808 | size_t cnt, loff_t *ppos) |
| 2809 | { |
| 2810 | struct trace_iterator *iter = filp->private_data; |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 2811 | ssize_t sret; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2812 | |
| 2813 | /* return any leftover data */ |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 2814 | sret = trace_seq_to_user(&iter->seq, ubuf, cnt); |
| 2815 | if (sret != -EBUSY) |
| 2816 | return sret; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2817 | |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 2818 | trace_seq_reset(&iter->seq); |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2819 | |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 2820 | mutex_lock(&trace_types_lock); |
| 2821 | if (iter->trace->read) { |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 2822 | sret = iter->trace->read(iter, filp, ubuf, cnt, ppos); |
| 2823 | if (sret) |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 2824 | goto out; |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 2825 | } |
| 2826 | |
Pekka Paalanen | 9ff4b97 | 2008-09-29 20:23:48 +0200 | [diff] [blame] | 2827 | waitagain: |
| 2828 | sret = 0; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2829 | while (trace_empty(iter)) { |
Steven Rostedt | 2dc8f09 | 2008-05-12 21:20:58 +0200 | [diff] [blame] | 2830 | |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 2831 | if ((filp->f_flags & O_NONBLOCK)) { |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 2832 | sret = -EAGAIN; |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 2833 | goto out; |
| 2834 | } |
Steven Rostedt | 2dc8f09 | 2008-05-12 21:20:58 +0200 | [diff] [blame] | 2835 | |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2836 | /* |
| 2837 | * This is a make-shift waitqueue. The reason we don't use |
| 2838 | * an actual wait queue is because: |
| 2839 | * 1) we only ever have one waiter |
| 2840 | * 2) the tracing, traces all functions, we don't want |
| 2841 | * the overhead of calling wake_up and friends |
| 2842 | * (and tracing them too) |
| 2843 | * Anyway, this is really very primitive wakeup. |
| 2844 | */ |
| 2845 | set_current_state(TASK_INTERRUPTIBLE); |
| 2846 | iter->tr->waiter = current; |
| 2847 | |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 2848 | mutex_unlock(&trace_types_lock); |
| 2849 | |
Ingo Molnar | 9fe068e | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 2850 | /* sleep for 100 msecs, and try again. */ |
| 2851 | schedule_timeout(HZ/10); |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2852 | |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 2853 | mutex_lock(&trace_types_lock); |
| 2854 | |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2855 | iter->tr->waiter = NULL; |
| 2856 | |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 2857 | if (signal_pending(current)) { |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 2858 | sret = -EINTR; |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 2859 | goto out; |
| 2860 | } |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2861 | |
Steven Rostedt | 8452799 | 2008-05-12 21:20:58 +0200 | [diff] [blame] | 2862 | if (iter->trace != current_trace) |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 2863 | goto out; |
Steven Rostedt | 8452799 | 2008-05-12 21:20:58 +0200 | [diff] [blame] | 2864 | |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2865 | /* |
| 2866 | * We block until we read something and tracing is disabled. |
| 2867 | * We still block if tracing is disabled, but we have never |
| 2868 | * read anything. This allows a user to cat this file, and |
| 2869 | * then enable tracing. But after we have read something, |
| 2870 | * we give an EOF when tracing is again disabled. |
| 2871 | * |
| 2872 | * iter->pos will be 0 if we haven't read anything. |
| 2873 | */ |
| 2874 | if (!tracer_enabled && iter->pos) |
| 2875 | break; |
| 2876 | |
| 2877 | continue; |
| 2878 | } |
| 2879 | |
| 2880 | /* stop when tracing is finished */ |
| 2881 | if (trace_empty(iter)) |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 2882 | goto out; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2883 | |
| 2884 | if (cnt >= PAGE_SIZE) |
| 2885 | cnt = PAGE_SIZE - 1; |
| 2886 | |
Steven Rostedt | 53d0aa7 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 2887 | /* reset all but tr, trace, and overruns */ |
Steven Rostedt | 53d0aa7 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 2888 | memset(&iter->seq, 0, |
| 2889 | sizeof(struct trace_iterator) - |
| 2890 | offsetof(struct trace_iterator, seq)); |
Steven Rostedt | 4823ed7 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 2891 | iter->pos = -1; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2892 | |
Steven Rostedt | 088b1e42 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 2893 | while (find_next_entry_inc(iter) != NULL) { |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 2894 | enum print_line_t ret; |
Steven Rostedt | 088b1e42 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 2895 | int len = iter->seq.len; |
| 2896 | |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2897 | ret = print_trace_line(iter); |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 2898 | if (ret == TRACE_TYPE_PARTIAL_LINE) { |
Steven Rostedt | 088b1e42 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 2899 | /* don't print partial lines */ |
| 2900 | iter->seq.len = len; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2901 | break; |
Steven Rostedt | 088b1e42 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 2902 | } |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2903 | |
| 2904 | trace_consume(iter); |
| 2905 | |
| 2906 | if (iter->seq.len >= cnt) |
| 2907 | break; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2908 | } |
| 2909 | |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2910 | /* Now copy what we have to the user */ |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 2911 | sret = trace_seq_to_user(&iter->seq, ubuf, cnt); |
| 2912 | if (iter->seq.readpos >= iter->seq.len) |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2913 | trace_seq_reset(&iter->seq); |
Pekka Paalanen | 9ff4b97 | 2008-09-29 20:23:48 +0200 | [diff] [blame] | 2914 | |
| 2915 | /* |
| 2916 | * If there was nothing to send to user, inspite of consuming trace |
| 2917 | * entries, go back to wait for more entries. |
| 2918 | */ |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 2919 | if (sret == -EBUSY) |
Pekka Paalanen | 9ff4b97 | 2008-09-29 20:23:48 +0200 | [diff] [blame] | 2920 | goto waitagain; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2921 | |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 2922 | out: |
| 2923 | mutex_unlock(&trace_types_lock); |
| 2924 | |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 2925 | return sret; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2926 | } |
| 2927 | |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 2928 | static ssize_t |
| 2929 | tracing_entries_read(struct file *filp, char __user *ubuf, |
| 2930 | size_t cnt, loff_t *ppos) |
| 2931 | { |
| 2932 | struct trace_array *tr = filp->private_data; |
| 2933 | char buf[64]; |
| 2934 | int r; |
| 2935 | |
Steven Rostedt | 1696b2b | 2008-11-13 00:09:35 -0500 | [diff] [blame] | 2936 | r = sprintf(buf, "%lu\n", tr->entries >> 10); |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 2937 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, r); |
| 2938 | } |
| 2939 | |
| 2940 | static ssize_t |
| 2941 | tracing_entries_write(struct file *filp, const char __user *ubuf, |
| 2942 | size_t cnt, loff_t *ppos) |
| 2943 | { |
| 2944 | unsigned long val; |
| 2945 | char buf[64]; |
Steven Rostedt | bf5e651 | 2008-11-10 21:46:00 -0500 | [diff] [blame] | 2946 | int ret, cpu; |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 2947 | |
Steven Rostedt | cffae43 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 2948 | if (cnt >= sizeof(buf)) |
| 2949 | return -EINVAL; |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 2950 | |
| 2951 | if (copy_from_user(&buf, ubuf, cnt)) |
| 2952 | return -EFAULT; |
| 2953 | |
| 2954 | buf[cnt] = 0; |
| 2955 | |
Steven Rostedt | c6caeeb | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 2956 | ret = strict_strtoul(buf, 10, &val); |
| 2957 | if (ret < 0) |
| 2958 | return ret; |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 2959 | |
| 2960 | /* must have at least 1 entry */ |
| 2961 | if (!val) |
| 2962 | return -EINVAL; |
| 2963 | |
| 2964 | mutex_lock(&trace_types_lock); |
| 2965 | |
Steven Rostedt | c76f069 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 2966 | tracing_stop(); |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 2967 | |
Steven Rostedt | bf5e651 | 2008-11-10 21:46:00 -0500 | [diff] [blame] | 2968 | /* disable all cpu buffers */ |
| 2969 | for_each_tracing_cpu(cpu) { |
| 2970 | if (global_trace.data[cpu]) |
| 2971 | atomic_inc(&global_trace.data[cpu]->disabled); |
| 2972 | if (max_tr.data[cpu]) |
| 2973 | atomic_inc(&max_tr.data[cpu]->disabled); |
| 2974 | } |
| 2975 | |
Steven Rostedt | 1696b2b | 2008-11-13 00:09:35 -0500 | [diff] [blame] | 2976 | /* value is in KB */ |
| 2977 | val <<= 10; |
| 2978 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2979 | if (val != global_trace.entries) { |
| 2980 | ret = ring_buffer_resize(global_trace.buffer, val); |
| 2981 | if (ret < 0) { |
| 2982 | cnt = ret; |
Steven Rostedt | 3eefae9 | 2008-05-12 21:21:04 +0200 | [diff] [blame] | 2983 | goto out; |
| 2984 | } |
| 2985 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2986 | ret = ring_buffer_resize(max_tr.buffer, val); |
| 2987 | if (ret < 0) { |
| 2988 | int r; |
| 2989 | cnt = ret; |
| 2990 | r = ring_buffer_resize(global_trace.buffer, |
| 2991 | global_trace.entries); |
| 2992 | if (r < 0) { |
| 2993 | /* AARGH! We are left with different |
| 2994 | * size max buffer!!!! */ |
| 2995 | WARN_ON(1); |
| 2996 | tracing_disabled = 1; |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 2997 | } |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2998 | goto out; |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 2999 | } |
Steven Rostedt | 3eefae9 | 2008-05-12 21:21:04 +0200 | [diff] [blame] | 3000 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 3001 | global_trace.entries = val; |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 3002 | } |
| 3003 | |
| 3004 | filp->f_pos += cnt; |
| 3005 | |
Steven Rostedt | 19384c0 | 2008-05-22 00:22:16 -0400 | [diff] [blame] | 3006 | /* If check pages failed, return ENOMEM */ |
| 3007 | if (tracing_disabled) |
| 3008 | cnt = -ENOMEM; |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 3009 | out: |
Steven Rostedt | bf5e651 | 2008-11-10 21:46:00 -0500 | [diff] [blame] | 3010 | for_each_tracing_cpu(cpu) { |
| 3011 | if (global_trace.data[cpu]) |
| 3012 | atomic_dec(&global_trace.data[cpu]->disabled); |
| 3013 | if (max_tr.data[cpu]) |
| 3014 | atomic_dec(&max_tr.data[cpu]->disabled); |
| 3015 | } |
| 3016 | |
Steven Rostedt | c76f069 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 3017 | tracing_start(); |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 3018 | max_tr.entries = global_trace.entries; |
| 3019 | mutex_unlock(&trace_types_lock); |
| 3020 | |
| 3021 | return cnt; |
| 3022 | } |
| 3023 | |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 3024 | static int mark_printk(const char *fmt, ...) |
| 3025 | { |
| 3026 | int ret; |
| 3027 | va_list args; |
| 3028 | va_start(args, fmt); |
| 3029 | ret = trace_vprintk(0, fmt, args); |
| 3030 | va_end(args); |
| 3031 | return ret; |
| 3032 | } |
| 3033 | |
| 3034 | static ssize_t |
| 3035 | tracing_mark_write(struct file *filp, const char __user *ubuf, |
| 3036 | size_t cnt, loff_t *fpos) |
| 3037 | { |
| 3038 | char *buf; |
| 3039 | char *end; |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 3040 | |
Steven Rostedt | c76f069 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 3041 | if (tracing_disabled) |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 3042 | return -EINVAL; |
| 3043 | |
| 3044 | if (cnt > TRACE_BUF_SIZE) |
| 3045 | cnt = TRACE_BUF_SIZE; |
| 3046 | |
| 3047 | buf = kmalloc(cnt + 1, GFP_KERNEL); |
| 3048 | if (buf == NULL) |
| 3049 | return -ENOMEM; |
| 3050 | |
| 3051 | if (copy_from_user(buf, ubuf, cnt)) { |
| 3052 | kfree(buf); |
| 3053 | return -EFAULT; |
| 3054 | } |
| 3055 | |
| 3056 | /* Cut from the first nil or newline. */ |
| 3057 | buf[cnt] = '\0'; |
| 3058 | end = strchr(buf, '\n'); |
| 3059 | if (end) |
| 3060 | *end = '\0'; |
| 3061 | |
| 3062 | cnt = mark_printk("%s\n", buf); |
| 3063 | kfree(buf); |
| 3064 | *fpos += cnt; |
| 3065 | |
| 3066 | return cnt; |
| 3067 | } |
| 3068 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3069 | static struct file_operations tracing_max_lat_fops = { |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3070 | .open = tracing_open_generic, |
| 3071 | .read = tracing_max_lat_read, |
| 3072 | .write = tracing_max_lat_write, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3073 | }; |
| 3074 | |
| 3075 | static struct file_operations tracing_ctrl_fops = { |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3076 | .open = tracing_open_generic, |
| 3077 | .read = tracing_ctrl_read, |
| 3078 | .write = tracing_ctrl_write, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3079 | }; |
| 3080 | |
| 3081 | static struct file_operations set_tracer_fops = { |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3082 | .open = tracing_open_generic, |
| 3083 | .read = tracing_set_trace_read, |
| 3084 | .write = tracing_set_trace_write, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3085 | }; |
| 3086 | |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3087 | static struct file_operations tracing_pipe_fops = { |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3088 | .open = tracing_open_pipe, |
Soeren Sandmann Pedersen | 2a2cc8f | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 3089 | .poll = tracing_poll_pipe, |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3090 | .read = tracing_read_pipe, |
| 3091 | .release = tracing_release_pipe, |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3092 | }; |
| 3093 | |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 3094 | static struct file_operations tracing_entries_fops = { |
| 3095 | .open = tracing_open_generic, |
| 3096 | .read = tracing_entries_read, |
| 3097 | .write = tracing_entries_write, |
| 3098 | }; |
| 3099 | |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 3100 | static struct file_operations tracing_mark_fops = { |
Frédéric Weisbecker | 43a1538 | 2008-09-21 20:16:30 +0200 | [diff] [blame] | 3101 | .open = tracing_open_generic, |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 3102 | .write = tracing_mark_write, |
| 3103 | }; |
| 3104 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3105 | #ifdef CONFIG_DYNAMIC_FTRACE |
| 3106 | |
Steven Rostedt | b807c3d | 2008-10-30 16:08:33 -0400 | [diff] [blame] | 3107 | int __weak ftrace_arch_read_dyn_info(char *buf, int size) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3108 | { |
Steven Rostedt | b807c3d | 2008-10-30 16:08:33 -0400 | [diff] [blame] | 3109 | return 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3110 | } |
| 3111 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3112 | static ssize_t |
Steven Rostedt | b807c3d | 2008-10-30 16:08:33 -0400 | [diff] [blame] | 3113 | tracing_read_dyn_info(struct file *filp, char __user *ubuf, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3114 | size_t cnt, loff_t *ppos) |
| 3115 | { |
Steven Rostedt | a26a2a2 | 2008-10-31 00:03:22 -0400 | [diff] [blame] | 3116 | static char ftrace_dyn_info_buffer[1024]; |
| 3117 | static DEFINE_MUTEX(dyn_info_mutex); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3118 | unsigned long *p = filp->private_data; |
Steven Rostedt | b807c3d | 2008-10-30 16:08:33 -0400 | [diff] [blame] | 3119 | char *buf = ftrace_dyn_info_buffer; |
Steven Rostedt | a26a2a2 | 2008-10-31 00:03:22 -0400 | [diff] [blame] | 3120 | int size = ARRAY_SIZE(ftrace_dyn_info_buffer); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3121 | int r; |
| 3122 | |
Steven Rostedt | b807c3d | 2008-10-30 16:08:33 -0400 | [diff] [blame] | 3123 | mutex_lock(&dyn_info_mutex); |
| 3124 | r = sprintf(buf, "%ld ", *p); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3125 | |
Steven Rostedt | a26a2a2 | 2008-10-31 00:03:22 -0400 | [diff] [blame] | 3126 | r += ftrace_arch_read_dyn_info(buf+r, (size-1)-r); |
Steven Rostedt | b807c3d | 2008-10-30 16:08:33 -0400 | [diff] [blame] | 3127 | buf[r++] = '\n'; |
| 3128 | |
| 3129 | r = simple_read_from_buffer(ubuf, cnt, ppos, buf, r); |
| 3130 | |
| 3131 | mutex_unlock(&dyn_info_mutex); |
| 3132 | |
| 3133 | return r; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3134 | } |
| 3135 | |
Steven Rostedt | b807c3d | 2008-10-30 16:08:33 -0400 | [diff] [blame] | 3136 | static struct file_operations tracing_dyn_info_fops = { |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3137 | .open = tracing_open_generic, |
Steven Rostedt | b807c3d | 2008-10-30 16:08:33 -0400 | [diff] [blame] | 3138 | .read = tracing_read_dyn_info, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3139 | }; |
| 3140 | #endif |
| 3141 | |
| 3142 | static struct dentry *d_tracer; |
| 3143 | |
| 3144 | struct dentry *tracing_init_dentry(void) |
| 3145 | { |
| 3146 | static int once; |
| 3147 | |
| 3148 | if (d_tracer) |
| 3149 | return d_tracer; |
| 3150 | |
| 3151 | d_tracer = debugfs_create_dir("tracing", NULL); |
| 3152 | |
| 3153 | if (!d_tracer && !once) { |
| 3154 | once = 1; |
| 3155 | pr_warning("Could not create debugfs directory 'tracing'\n"); |
| 3156 | return NULL; |
| 3157 | } |
| 3158 | |
| 3159 | return d_tracer; |
| 3160 | } |
| 3161 | |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 3162 | #ifdef CONFIG_FTRACE_SELFTEST |
| 3163 | /* Let selftest have access to static functions in this file */ |
| 3164 | #include "trace_selftest.c" |
| 3165 | #endif |
| 3166 | |
Frédéric Weisbecker | b5ad384 | 2008-09-23 11:34:32 +0100 | [diff] [blame] | 3167 | static __init int tracer_init_debugfs(void) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3168 | { |
| 3169 | struct dentry *d_tracer; |
| 3170 | struct dentry *entry; |
| 3171 | |
| 3172 | d_tracer = tracing_init_dentry(); |
| 3173 | |
| 3174 | entry = debugfs_create_file("tracing_enabled", 0644, d_tracer, |
| 3175 | &global_trace, &tracing_ctrl_fops); |
| 3176 | if (!entry) |
| 3177 | pr_warning("Could not create debugfs 'tracing_enabled' entry\n"); |
| 3178 | |
Steven Rostedt | ee6bce5 | 2008-11-12 17:52:37 -0500 | [diff] [blame] | 3179 | entry = debugfs_create_file("trace_options", 0644, d_tracer, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3180 | NULL, &tracing_iter_fops); |
| 3181 | if (!entry) |
Steven Rostedt | ee6bce5 | 2008-11-12 17:52:37 -0500 | [diff] [blame] | 3182 | pr_warning("Could not create debugfs 'trace_options' entry\n"); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3183 | |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3184 | entry = debugfs_create_file("tracing_cpumask", 0644, d_tracer, |
| 3185 | NULL, &tracing_cpumask_fops); |
| 3186 | if (!entry) |
| 3187 | pr_warning("Could not create debugfs 'tracing_cpumask' entry\n"); |
| 3188 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3189 | entry = debugfs_create_file("latency_trace", 0444, d_tracer, |
| 3190 | &global_trace, &tracing_lt_fops); |
| 3191 | if (!entry) |
| 3192 | pr_warning("Could not create debugfs 'latency_trace' entry\n"); |
| 3193 | |
| 3194 | entry = debugfs_create_file("trace", 0444, d_tracer, |
| 3195 | &global_trace, &tracing_fops); |
| 3196 | if (!entry) |
| 3197 | pr_warning("Could not create debugfs 'trace' entry\n"); |
| 3198 | |
| 3199 | entry = debugfs_create_file("available_tracers", 0444, d_tracer, |
| 3200 | &global_trace, &show_traces_fops); |
| 3201 | if (!entry) |
Frédéric Weisbecker | 98a983a | 2008-08-15 21:08:22 +0200 | [diff] [blame] | 3202 | pr_warning("Could not create debugfs 'available_tracers' entry\n"); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3203 | |
| 3204 | entry = debugfs_create_file("current_tracer", 0444, d_tracer, |
| 3205 | &global_trace, &set_tracer_fops); |
| 3206 | if (!entry) |
Frédéric Weisbecker | 98a983a | 2008-08-15 21:08:22 +0200 | [diff] [blame] | 3207 | pr_warning("Could not create debugfs 'current_tracer' entry\n"); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3208 | |
| 3209 | entry = debugfs_create_file("tracing_max_latency", 0644, d_tracer, |
| 3210 | &tracing_max_latency, |
| 3211 | &tracing_max_lat_fops); |
| 3212 | if (!entry) |
| 3213 | pr_warning("Could not create debugfs " |
| 3214 | "'tracing_max_latency' entry\n"); |
| 3215 | |
| 3216 | entry = debugfs_create_file("tracing_thresh", 0644, d_tracer, |
| 3217 | &tracing_thresh, &tracing_max_lat_fops); |
| 3218 | if (!entry) |
| 3219 | pr_warning("Could not create debugfs " |
Frédéric Weisbecker | 98a983a | 2008-08-15 21:08:22 +0200 | [diff] [blame] | 3220 | "'tracing_thresh' entry\n"); |
Ingo Molnar | 7bd2f24 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 3221 | entry = debugfs_create_file("README", 0644, d_tracer, |
| 3222 | NULL, &tracing_readme_fops); |
| 3223 | if (!entry) |
| 3224 | pr_warning("Could not create debugfs 'README' entry\n"); |
| 3225 | |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3226 | entry = debugfs_create_file("trace_pipe", 0644, d_tracer, |
| 3227 | NULL, &tracing_pipe_fops); |
| 3228 | if (!entry) |
| 3229 | pr_warning("Could not create debugfs " |
Frédéric Weisbecker | 98a983a | 2008-08-15 21:08:22 +0200 | [diff] [blame] | 3230 | "'trace_pipe' entry\n"); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3231 | |
Steven Rostedt | a94c80e | 2008-11-12 17:52:36 -0500 | [diff] [blame] | 3232 | entry = debugfs_create_file("buffer_size_kb", 0644, d_tracer, |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 3233 | &global_trace, &tracing_entries_fops); |
| 3234 | if (!entry) |
| 3235 | pr_warning("Could not create debugfs " |
Steven Rostedt | a94c80e | 2008-11-12 17:52:36 -0500 | [diff] [blame] | 3236 | "'buffer_size_kb' entry\n"); |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 3237 | |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 3238 | entry = debugfs_create_file("trace_marker", 0220, d_tracer, |
| 3239 | NULL, &tracing_mark_fops); |
| 3240 | if (!entry) |
| 3241 | pr_warning("Could not create debugfs " |
| 3242 | "'trace_marker' entry\n"); |
| 3243 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3244 | #ifdef CONFIG_DYNAMIC_FTRACE |
| 3245 | entry = debugfs_create_file("dyn_ftrace_total_info", 0444, d_tracer, |
| 3246 | &ftrace_update_tot_cnt, |
Steven Rostedt | b807c3d | 2008-10-30 16:08:33 -0400 | [diff] [blame] | 3247 | &tracing_dyn_info_fops); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3248 | if (!entry) |
| 3249 | pr_warning("Could not create debugfs " |
| 3250 | "'dyn_ftrace_total_info' entry\n"); |
| 3251 | #endif |
Ingo Molnar | d618b3e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 3252 | #ifdef CONFIG_SYSPROF_TRACER |
| 3253 | init_tracer_sysprof_debugfs(d_tracer); |
| 3254 | #endif |
Frédéric Weisbecker | b5ad384 | 2008-09-23 11:34:32 +0100 | [diff] [blame] | 3255 | return 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3256 | } |
| 3257 | |
Pekka Paalanen | 801fe40 | 2008-09-16 21:58:24 +0300 | [diff] [blame] | 3258 | int trace_vprintk(unsigned long ip, const char *fmt, va_list args) |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 3259 | { |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 3260 | static DEFINE_SPINLOCK(trace_buf_lock); |
| 3261 | static char trace_buf[TRACE_BUF_SIZE]; |
Peter Zijlstra | f09ce57 | 2008-09-04 10:24:14 +0200 | [diff] [blame] | 3262 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 3263 | struct ring_buffer_event *event; |
Peter Zijlstra | f09ce57 | 2008-09-04 10:24:14 +0200 | [diff] [blame] | 3264 | struct trace_array *tr = &global_trace; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 3265 | struct trace_array_cpu *data; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 3266 | struct print_entry *entry; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 3267 | unsigned long flags, irq_flags; |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 3268 | int cpu, len = 0, size, pc; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 3269 | |
Steven Rostedt | c76f069 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 3270 | if (tracing_disabled) |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 3271 | return 0; |
| 3272 | |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 3273 | pc = preempt_count(); |
| 3274 | preempt_disable_notrace(); |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 3275 | cpu = raw_smp_processor_id(); |
| 3276 | data = tr->data[cpu]; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 3277 | |
Steven Rostedt | 3ea2e6d | 2008-10-04 02:01:00 -0400 | [diff] [blame] | 3278 | if (unlikely(atomic_read(&data->disabled))) |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 3279 | goto out; |
| 3280 | |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 3281 | spin_lock_irqsave(&trace_buf_lock, flags); |
Pekka Paalanen | 801fe40 | 2008-09-16 21:58:24 +0300 | [diff] [blame] | 3282 | len = vsnprintf(trace_buf, TRACE_BUF_SIZE, fmt, args); |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 3283 | |
| 3284 | len = min(len, TRACE_BUF_SIZE-1); |
| 3285 | trace_buf[len] = 0; |
| 3286 | |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 3287 | size = sizeof(*entry) + len + 1; |
| 3288 | event = ring_buffer_lock_reserve(tr->buffer, size, &irq_flags); |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 3289 | if (!event) |
| 3290 | goto out_unlock; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 3291 | entry = ring_buffer_event_data(event); |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 3292 | tracing_generic_entry_update(&entry->ent, flags, pc); |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 3293 | entry->ent.type = TRACE_PRINT; |
| 3294 | entry->ip = ip; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 3295 | |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 3296 | memcpy(&entry->buf, trace_buf, len); |
| 3297 | entry->buf[len] = 0; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 3298 | ring_buffer_unlock_commit(tr->buffer, event, irq_flags); |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 3299 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 3300 | out_unlock: |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 3301 | spin_unlock_irqrestore(&trace_buf_lock, flags); |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 3302 | |
| 3303 | out: |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 3304 | preempt_enable_notrace(); |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 3305 | |
| 3306 | return len; |
| 3307 | } |
Pekka Paalanen | 801fe40 | 2008-09-16 21:58:24 +0300 | [diff] [blame] | 3308 | EXPORT_SYMBOL_GPL(trace_vprintk); |
| 3309 | |
| 3310 | int __ftrace_printk(unsigned long ip, const char *fmt, ...) |
| 3311 | { |
| 3312 | int ret; |
| 3313 | va_list ap; |
| 3314 | |
| 3315 | if (!(trace_flags & TRACE_ITER_PRINTK)) |
| 3316 | return 0; |
| 3317 | |
| 3318 | va_start(ap, fmt); |
| 3319 | ret = trace_vprintk(ip, fmt, ap); |
| 3320 | va_end(ap); |
| 3321 | return ret; |
| 3322 | } |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 3323 | EXPORT_SYMBOL_GPL(__ftrace_printk); |
| 3324 | |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 3325 | static int trace_panic_handler(struct notifier_block *this, |
| 3326 | unsigned long event, void *unused) |
| 3327 | { |
Steven Rostedt | 944ac42 | 2008-10-23 19:26:08 -0400 | [diff] [blame] | 3328 | if (ftrace_dump_on_oops) |
| 3329 | ftrace_dump(); |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 3330 | return NOTIFY_OK; |
| 3331 | } |
| 3332 | |
| 3333 | static struct notifier_block trace_panic_notifier = { |
| 3334 | .notifier_call = trace_panic_handler, |
| 3335 | .next = NULL, |
| 3336 | .priority = 150 /* priority: INT_MAX >= x >= 0 */ |
| 3337 | }; |
| 3338 | |
| 3339 | static int trace_die_handler(struct notifier_block *self, |
| 3340 | unsigned long val, |
| 3341 | void *data) |
| 3342 | { |
| 3343 | switch (val) { |
| 3344 | case DIE_OOPS: |
Steven Rostedt | 944ac42 | 2008-10-23 19:26:08 -0400 | [diff] [blame] | 3345 | if (ftrace_dump_on_oops) |
| 3346 | ftrace_dump(); |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 3347 | break; |
| 3348 | default: |
| 3349 | break; |
| 3350 | } |
| 3351 | return NOTIFY_OK; |
| 3352 | } |
| 3353 | |
| 3354 | static struct notifier_block trace_die_notifier = { |
| 3355 | .notifier_call = trace_die_handler, |
| 3356 | .priority = 200 |
| 3357 | }; |
| 3358 | |
| 3359 | /* |
| 3360 | * printk is set to max of 1024, we really don't need it that big. |
| 3361 | * Nothing should be printing 1000 characters anyway. |
| 3362 | */ |
| 3363 | #define TRACE_MAX_PRINT 1000 |
| 3364 | |
| 3365 | /* |
| 3366 | * Define here KERN_TRACE so that we have one place to modify |
| 3367 | * it if we decide to change what log level the ftrace dump |
| 3368 | * should be at. |
| 3369 | */ |
| 3370 | #define KERN_TRACE KERN_INFO |
| 3371 | |
| 3372 | static void |
| 3373 | trace_printk_seq(struct trace_seq *s) |
| 3374 | { |
| 3375 | /* Probably should print a warning here. */ |
| 3376 | if (s->len >= 1000) |
| 3377 | s->len = 1000; |
| 3378 | |
| 3379 | /* should be zero ended, but we are paranoid. */ |
| 3380 | s->buffer[s->len] = 0; |
| 3381 | |
| 3382 | printk(KERN_TRACE "%s", s->buffer); |
| 3383 | |
| 3384 | trace_seq_reset(s); |
| 3385 | } |
| 3386 | |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 3387 | void ftrace_dump(void) |
| 3388 | { |
| 3389 | static DEFINE_SPINLOCK(ftrace_dump_lock); |
| 3390 | /* use static because iter can be a bit big for the stack */ |
| 3391 | static struct trace_iterator iter; |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 3392 | static cpumask_t mask; |
| 3393 | static int dump_ran; |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 3394 | unsigned long flags; |
| 3395 | int cnt = 0, cpu; |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 3396 | |
| 3397 | /* only one dump */ |
| 3398 | spin_lock_irqsave(&ftrace_dump_lock, flags); |
| 3399 | if (dump_ran) |
| 3400 | goto out; |
| 3401 | |
| 3402 | dump_ran = 1; |
| 3403 | |
| 3404 | /* No turning back! */ |
Steven Rostedt | 81adbdc | 2008-10-23 09:33:02 -0400 | [diff] [blame] | 3405 | ftrace_kill(); |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 3406 | |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 3407 | for_each_tracing_cpu(cpu) { |
| 3408 | atomic_inc(&global_trace.data[cpu]->disabled); |
| 3409 | } |
| 3410 | |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 3411 | printk(KERN_TRACE "Dumping ftrace buffer:\n"); |
| 3412 | |
| 3413 | iter.tr = &global_trace; |
| 3414 | iter.trace = current_trace; |
| 3415 | |
| 3416 | /* |
| 3417 | * We need to stop all tracing on all CPUS to read the |
| 3418 | * the next buffer. This is a bit expensive, but is |
| 3419 | * not done often. We fill all what we can read, |
| 3420 | * and then release the locks again. |
| 3421 | */ |
| 3422 | |
| 3423 | cpus_clear(mask); |
| 3424 | |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 3425 | while (!trace_empty(&iter)) { |
| 3426 | |
| 3427 | if (!cnt) |
| 3428 | printk(KERN_TRACE "---------------------------------\n"); |
| 3429 | |
| 3430 | cnt++; |
| 3431 | |
| 3432 | /* reset all but tr, trace, and overruns */ |
| 3433 | memset(&iter.seq, 0, |
| 3434 | sizeof(struct trace_iterator) - |
| 3435 | offsetof(struct trace_iterator, seq)); |
| 3436 | iter.iter_flags |= TRACE_FILE_LAT_FMT; |
| 3437 | iter.pos = -1; |
| 3438 | |
| 3439 | if (find_next_entry_inc(&iter) != NULL) { |
| 3440 | print_trace_line(&iter); |
| 3441 | trace_consume(&iter); |
| 3442 | } |
| 3443 | |
| 3444 | trace_printk_seq(&iter.seq); |
| 3445 | } |
| 3446 | |
| 3447 | if (!cnt) |
| 3448 | printk(KERN_TRACE " (ftrace buffer empty)\n"); |
| 3449 | else |
| 3450 | printk(KERN_TRACE "---------------------------------\n"); |
| 3451 | |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 3452 | out: |
| 3453 | spin_unlock_irqrestore(&ftrace_dump_lock, flags); |
| 3454 | } |
| 3455 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3456 | __init static int tracer_alloc_buffers(void) |
| 3457 | { |
Steven Rostedt | 4c11d7a | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 3458 | struct trace_array_cpu *data; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3459 | int i; |
| 3460 | |
Steven Rostedt | ab46428 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 3461 | /* TODO: make the number of buffers hot pluggable with CPUS */ |
Steven Rostedt | ab46428 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 3462 | tracing_buffer_mask = cpu_possible_map; |
| 3463 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 3464 | global_trace.buffer = ring_buffer_alloc(trace_buf_size, |
| 3465 | TRACE_BUFFER_FLAGS); |
| 3466 | if (!global_trace.buffer) { |
| 3467 | printk(KERN_ERR "tracer: failed to allocate ring buffer!\n"); |
| 3468 | WARN_ON(1); |
| 3469 | return 0; |
| 3470 | } |
| 3471 | global_trace.entries = ring_buffer_size(global_trace.buffer); |
| 3472 | |
| 3473 | #ifdef CONFIG_TRACER_MAX_TRACE |
| 3474 | max_tr.buffer = ring_buffer_alloc(trace_buf_size, |
| 3475 | TRACE_BUFFER_FLAGS); |
| 3476 | if (!max_tr.buffer) { |
| 3477 | printk(KERN_ERR "tracer: failed to allocate max ring buffer!\n"); |
| 3478 | WARN_ON(1); |
| 3479 | ring_buffer_free(global_trace.buffer); |
| 3480 | return 0; |
| 3481 | } |
| 3482 | max_tr.entries = ring_buffer_size(max_tr.buffer); |
| 3483 | WARN_ON(max_tr.entries != global_trace.entries); |
| 3484 | #endif |
| 3485 | |
Steven Rostedt | 4c11d7a | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 3486 | /* Allocate the first page for all buffers */ |
Steven Rostedt | ab46428 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 3487 | for_each_tracing_cpu(i) { |
Steven Rostedt | 4c11d7a | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 3488 | data = global_trace.data[i] = &per_cpu(global_trace_cpu, i); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3489 | max_tr.data[i] = &per_cpu(max_data, i); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3490 | } |
| 3491 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3492 | trace_init_cmdlines(); |
| 3493 | |
Frédéric Weisbecker | 43a1538 | 2008-09-21 20:16:30 +0200 | [diff] [blame] | 3494 | register_tracer(&nop_trace); |
Frédéric Weisbecker | b5ad384 | 2008-09-23 11:34:32 +0100 | [diff] [blame] | 3495 | #ifdef CONFIG_BOOT_TRACER |
| 3496 | register_tracer(&boot_tracer); |
| 3497 | current_trace = &boot_tracer; |
| 3498 | current_trace->init(&global_trace); |
| 3499 | #else |
Frédéric Weisbecker | 43a1538 | 2008-09-21 20:16:30 +0200 | [diff] [blame] | 3500 | current_trace = &nop_trace; |
Frédéric Weisbecker | b5ad384 | 2008-09-23 11:34:32 +0100 | [diff] [blame] | 3501 | #endif |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3502 | |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 3503 | /* All seems OK, enable tracing */ |
| 3504 | tracing_disabled = 0; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 3505 | |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 3506 | atomic_notifier_chain_register(&panic_notifier_list, |
| 3507 | &trace_panic_notifier); |
| 3508 | |
| 3509 | register_die_notifier(&trace_die_notifier); |
| 3510 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3511 | return 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3512 | } |
Frédéric Weisbecker | b5ad384 | 2008-09-23 11:34:32 +0100 | [diff] [blame] | 3513 | early_initcall(tracer_alloc_buffers); |
| 3514 | fs_initcall(tracer_init_debugfs); |