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