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