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