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