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