Commit | Line | Data |
---|---|---|
bc0c38d1 SR |
1 | /* |
2 | * ring buffer based function tracer | |
3 | * | |
2b6080f2 | 4 | * Copyright (C) 2007-2012 Steven Rostedt <srostedt@redhat.com> |
bc0c38d1 SR |
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 | |
6d49e352 | 12 | * Copyright (C) 2004 Nadia Yvette Chambers |
bc0c38d1 | 13 | */ |
2cadf913 | 14 | #include <linux/ring_buffer.h> |
273b281f | 15 | #include <generated/utsrelease.h> |
2cadf913 SR |
16 | #include <linux/stacktrace.h> |
17 | #include <linux/writeback.h> | |
bc0c38d1 SR |
18 | #include <linux/kallsyms.h> |
19 | #include <linux/seq_file.h> | |
3f5a54e3 | 20 | #include <linux/notifier.h> |
2cadf913 | 21 | #include <linux/irqflags.h> |
0d5c6e1c | 22 | #include <linux/irq_work.h> |
bc0c38d1 | 23 | #include <linux/debugfs.h> |
4c11d7ae | 24 | #include <linux/pagemap.h> |
bc0c38d1 SR |
25 | #include <linux/hardirq.h> |
26 | #include <linux/linkage.h> | |
27 | #include <linux/uaccess.h> | |
2cadf913 | 28 | #include <linux/kprobes.h> |
bc0c38d1 SR |
29 | #include <linux/ftrace.h> |
30 | #include <linux/module.h> | |
31 | #include <linux/percpu.h> | |
2cadf913 | 32 | #include <linux/splice.h> |
3f5a54e3 | 33 | #include <linux/kdebug.h> |
5f0c6c03 | 34 | #include <linux/string.h> |
7e53bd42 | 35 | #include <linux/rwsem.h> |
5a0e3ad6 | 36 | #include <linux/slab.h> |
bc0c38d1 SR |
37 | #include <linux/ctype.h> |
38 | #include <linux/init.h> | |
2a2cc8f7 | 39 | #include <linux/poll.h> |
b892e5c8 | 40 | #include <linux/nmi.h> |
bc0c38d1 | 41 | #include <linux/fs.h> |
8bd75c77 | 42 | #include <linux/sched/rt.h> |
86387f7e | 43 | |
bc0c38d1 | 44 | #include "trace.h" |
f0868d1e | 45 | #include "trace_output.h" |
bc0c38d1 | 46 | |
73c5162a SR |
47 | /* |
48 | * On boot up, the ring buffer is set to the minimum size, so that | |
49 | * we do not waste memory on systems that are not using tracing. | |
50 | */ | |
020e5f85 | 51 | int ring_buffer_expanded; |
73c5162a | 52 | |
8e1b82e0 FW |
53 | /* |
54 | * We need to change this state when a selftest is running. | |
ff32504f FW |
55 | * A selftest will lurk into the ring-buffer to count the |
56 | * entries inserted during the selftest although some concurrent | |
5e1607a0 | 57 | * insertions into the ring-buffer such as trace_printk could occurred |
ff32504f FW |
58 | * at the same time, giving false positive or negative results. |
59 | */ | |
8e1b82e0 | 60 | static bool __read_mostly tracing_selftest_running; |
ff32504f | 61 | |
b2821ae6 SR |
62 | /* |
63 | * If a tracer is running, we do not want to run SELFTEST. | |
64 | */ | |
020e5f85 | 65 | bool __read_mostly tracing_selftest_disabled; |
b2821ae6 | 66 | |
adf9f195 FW |
67 | /* For tracers that don't implement custom flags */ |
68 | static struct tracer_opt dummy_tracer_opt[] = { | |
69 | { } | |
70 | }; | |
71 | ||
72 | static struct tracer_flags dummy_tracer_flags = { | |
73 | .val = 0, | |
74 | .opts = dummy_tracer_opt | |
75 | }; | |
76 | ||
77 | static int dummy_set_flag(u32 old_flags, u32 bit, int set) | |
78 | { | |
79 | return 0; | |
80 | } | |
0f048701 | 81 | |
7ffbd48d SR |
82 | /* |
83 | * To prevent the comm cache from being overwritten when no | |
84 | * tracing is active, only save the comm when a trace event | |
85 | * occurred. | |
86 | */ | |
87 | static DEFINE_PER_CPU(bool, trace_cmdline_save); | |
88 | ||
0d5c6e1c SR |
89 | /* |
90 | * When a reader is waiting for data, then this variable is | |
91 | * set to true. | |
92 | */ | |
93 | static bool trace_wakeup_needed; | |
94 | ||
95 | static struct irq_work trace_work_wakeup; | |
96 | ||
0f048701 SR |
97 | /* |
98 | * Kill all tracing for good (never come back). | |
99 | * It is initialized to 1 but will turn to zero if the initialization | |
100 | * of the tracer is successful. But that is the only place that sets | |
101 | * this back to zero. | |
102 | */ | |
4fd27358 | 103 | static int tracing_disabled = 1; |
0f048701 | 104 | |
9288f99a | 105 | DEFINE_PER_CPU(int, ftrace_cpu_disabled); |
d769041f | 106 | |
955b61e5 | 107 | cpumask_var_t __read_mostly tracing_buffer_mask; |
ab46428c | 108 | |
944ac425 SR |
109 | /* |
110 | * ftrace_dump_on_oops - variable to dump ftrace buffer on oops | |
111 | * | |
112 | * If there is an oops (or kernel panic) and the ftrace_dump_on_oops | |
113 | * is set, then ftrace_dump is called. This will output the contents | |
114 | * of the ftrace buffers to the console. This is very useful for | |
115 | * capturing traces that lead to crashes and outputing it to a | |
116 | * serial console. | |
117 | * | |
118 | * It is default off, but you can enable it with either specifying | |
119 | * "ftrace_dump_on_oops" in the kernel command line, or setting | |
cecbca96 FW |
120 | * /proc/sys/kernel/ftrace_dump_on_oops |
121 | * Set 1 if you want to dump buffers of all CPUs | |
122 | * Set 2 if you want to dump the buffer of the CPU that triggered oops | |
944ac425 | 123 | */ |
cecbca96 FW |
124 | |
125 | enum ftrace_dump_mode ftrace_dump_on_oops; | |
944ac425 | 126 | |
b2821ae6 SR |
127 | static int tracing_set_tracer(const char *buf); |
128 | ||
ee6c2c1b LZ |
129 | #define MAX_TRACER_SIZE 100 |
130 | static char bootup_tracer_buf[MAX_TRACER_SIZE] __initdata; | |
b2821ae6 | 131 | static char *default_bootup_tracer; |
d9e54076 | 132 | |
1beee96b | 133 | static int __init set_cmdline_ftrace(char *str) |
d9e54076 | 134 | { |
ee6c2c1b | 135 | strncpy(bootup_tracer_buf, str, MAX_TRACER_SIZE); |
b2821ae6 | 136 | default_bootup_tracer = bootup_tracer_buf; |
73c5162a SR |
137 | /* We are using ftrace early, expand it */ |
138 | ring_buffer_expanded = 1; | |
d9e54076 PZ |
139 | return 1; |
140 | } | |
1beee96b | 141 | __setup("ftrace=", set_cmdline_ftrace); |
d9e54076 | 142 | |
944ac425 SR |
143 | static int __init set_ftrace_dump_on_oops(char *str) |
144 | { | |
cecbca96 FW |
145 | if (*str++ != '=' || !*str) { |
146 | ftrace_dump_on_oops = DUMP_ALL; | |
147 | return 1; | |
148 | } | |
149 | ||
150 | if (!strcmp("orig_cpu", str)) { | |
151 | ftrace_dump_on_oops = DUMP_ORIG; | |
152 | return 1; | |
153 | } | |
154 | ||
155 | return 0; | |
944ac425 SR |
156 | } |
157 | __setup("ftrace_dump_on_oops", set_ftrace_dump_on_oops); | |
60a11774 | 158 | |
7bcfaf54 SR |
159 | |
160 | static char trace_boot_options_buf[MAX_TRACER_SIZE] __initdata; | |
161 | static char *trace_boot_options __initdata; | |
162 | ||
163 | static int __init set_trace_boot_options(char *str) | |
164 | { | |
165 | strncpy(trace_boot_options_buf, str, MAX_TRACER_SIZE); | |
166 | trace_boot_options = trace_boot_options_buf; | |
167 | return 0; | |
168 | } | |
169 | __setup("trace_options=", set_trace_boot_options); | |
170 | ||
cf8e3474 | 171 | unsigned long long ns2usecs(cycle_t nsec) |
bc0c38d1 SR |
172 | { |
173 | nsec += 500; | |
174 | do_div(nsec, 1000); | |
175 | return nsec; | |
176 | } | |
177 | ||
4fcdae83 SR |
178 | /* |
179 | * The global_trace is the descriptor that holds the tracing | |
180 | * buffers for the live tracing. For each CPU, it contains | |
181 | * a link list of pages that will store trace entries. The | |
182 | * page descriptor of the pages in the memory is used to hold | |
183 | * the link list by linking the lru item in the page descriptor | |
184 | * to each of the pages in the buffer per CPU. | |
185 | * | |
186 | * For each active CPU there is a data field that holds the | |
187 | * pages for the buffer for that CPU. Each CPU has the same number | |
188 | * of pages allocated for its buffer. | |
189 | */ | |
bc0c38d1 SR |
190 | static struct trace_array global_trace; |
191 | ||
ae63b31e SR |
192 | LIST_HEAD(ftrace_trace_arrays); |
193 | ||
bc0c38d1 SR |
194 | static DEFINE_PER_CPU(struct trace_array_cpu, global_trace_cpu); |
195 | ||
e77405ad SR |
196 | int filter_current_check_discard(struct ring_buffer *buffer, |
197 | struct ftrace_event_call *call, void *rec, | |
eb02ce01 TZ |
198 | struct ring_buffer_event *event) |
199 | { | |
e77405ad | 200 | return filter_check_discard(call, rec, buffer, event); |
eb02ce01 | 201 | } |
17c873ec | 202 | EXPORT_SYMBOL_GPL(filter_current_check_discard); |
eb02ce01 | 203 | |
37886f6a SR |
204 | cycle_t ftrace_now(int cpu) |
205 | { | |
206 | u64 ts; | |
207 | ||
208 | /* Early boot up does not have a buffer yet */ | |
209 | if (!global_trace.buffer) | |
210 | return trace_clock_local(); | |
211 | ||
212 | ts = ring_buffer_time_stamp(global_trace.buffer, cpu); | |
213 | ring_buffer_normalize_time_stamp(global_trace.buffer, cpu, &ts); | |
214 | ||
215 | return ts; | |
216 | } | |
bc0c38d1 | 217 | |
4fcdae83 SR |
218 | /* |
219 | * The max_tr is used to snapshot the global_trace when a maximum | |
220 | * latency is reached. Some tracers will use this to store a maximum | |
221 | * trace while it continues examining live traces. | |
222 | * | |
223 | * The buffers for the max_tr are set up the same as the global_trace. | |
224 | * When a snapshot is taken, the link list of the max_tr is swapped | |
225 | * with the link list of the global_trace and the buffers are reset for | |
226 | * the global_trace so the tracing can continue. | |
227 | */ | |
bc0c38d1 SR |
228 | static struct trace_array max_tr; |
229 | ||
9705f69e | 230 | static DEFINE_PER_CPU(struct trace_array_cpu, max_tr_data); |
bc0c38d1 | 231 | |
9036990d SR |
232 | int tracing_is_enabled(void) |
233 | { | |
0fb9656d | 234 | return tracing_is_on(); |
9036990d SR |
235 | } |
236 | ||
4fcdae83 | 237 | /* |
3928a8a2 SR |
238 | * trace_buf_size is the size in bytes that is allocated |
239 | * for a buffer. Note, the number of bytes is always rounded | |
240 | * to page size. | |
3f5a54e3 SR |
241 | * |
242 | * This number is purposely set to a low number of 16384. | |
243 | * If the dump on oops happens, it will be much appreciated | |
244 | * to not have to wait for all that output. Anyway this can be | |
245 | * boot time and run time configurable. | |
4fcdae83 | 246 | */ |
3928a8a2 | 247 | #define TRACE_BUF_SIZE_DEFAULT 1441792UL /* 16384 * 88 (sizeof(entry)) */ |
3f5a54e3 | 248 | |
3928a8a2 | 249 | static unsigned long trace_buf_size = TRACE_BUF_SIZE_DEFAULT; |
bc0c38d1 | 250 | |
4fcdae83 | 251 | /* trace_types holds a link list of available tracers. */ |
bc0c38d1 | 252 | static struct tracer *trace_types __read_mostly; |
4fcdae83 | 253 | |
4fcdae83 SR |
254 | /* |
255 | * trace_types_lock is used to protect the trace_types list. | |
4fcdae83 | 256 | */ |
bc0c38d1 | 257 | static DEFINE_MUTEX(trace_types_lock); |
4fcdae83 | 258 | |
7e53bd42 LJ |
259 | /* |
260 | * serialize the access of the ring buffer | |
261 | * | |
262 | * ring buffer serializes readers, but it is low level protection. | |
263 | * The validity of the events (which returns by ring_buffer_peek() ..etc) | |
264 | * are not protected by ring buffer. | |
265 | * | |
266 | * The content of events may become garbage if we allow other process consumes | |
267 | * these events concurrently: | |
268 | * A) the page of the consumed events may become a normal page | |
269 | * (not reader page) in ring buffer, and this page will be rewrited | |
270 | * by events producer. | |
271 | * B) The page of the consumed events may become a page for splice_read, | |
272 | * and this page will be returned to system. | |
273 | * | |
274 | * These primitives allow multi process access to different cpu ring buffer | |
275 | * concurrently. | |
276 | * | |
277 | * These primitives don't distinguish read-only and read-consume access. | |
278 | * Multi read-only access are also serialized. | |
279 | */ | |
280 | ||
281 | #ifdef CONFIG_SMP | |
282 | static DECLARE_RWSEM(all_cpu_access_lock); | |
283 | static DEFINE_PER_CPU(struct mutex, cpu_access_lock); | |
284 | ||
285 | static inline void trace_access_lock(int cpu) | |
286 | { | |
ae3b5093 | 287 | if (cpu == RING_BUFFER_ALL_CPUS) { |
7e53bd42 LJ |
288 | /* gain it for accessing the whole ring buffer. */ |
289 | down_write(&all_cpu_access_lock); | |
290 | } else { | |
291 | /* gain it for accessing a cpu ring buffer. */ | |
292 | ||
ae3b5093 | 293 | /* Firstly block other trace_access_lock(RING_BUFFER_ALL_CPUS). */ |
7e53bd42 LJ |
294 | down_read(&all_cpu_access_lock); |
295 | ||
296 | /* Secondly block other access to this @cpu ring buffer. */ | |
297 | mutex_lock(&per_cpu(cpu_access_lock, cpu)); | |
298 | } | |
299 | } | |
300 | ||
301 | static inline void trace_access_unlock(int cpu) | |
302 | { | |
ae3b5093 | 303 | if (cpu == RING_BUFFER_ALL_CPUS) { |
7e53bd42 LJ |
304 | up_write(&all_cpu_access_lock); |
305 | } else { | |
306 | mutex_unlock(&per_cpu(cpu_access_lock, cpu)); | |
307 | up_read(&all_cpu_access_lock); | |
308 | } | |
309 | } | |
310 | ||
311 | static inline void trace_access_lock_init(void) | |
312 | { | |
313 | int cpu; | |
314 | ||
315 | for_each_possible_cpu(cpu) | |
316 | mutex_init(&per_cpu(cpu_access_lock, cpu)); | |
317 | } | |
318 | ||
319 | #else | |
320 | ||
321 | static DEFINE_MUTEX(access_lock); | |
322 | ||
323 | static inline void trace_access_lock(int cpu) | |
324 | { | |
325 | (void)cpu; | |
326 | mutex_lock(&access_lock); | |
327 | } | |
328 | ||
329 | static inline void trace_access_unlock(int cpu) | |
330 | { | |
331 | (void)cpu; | |
332 | mutex_unlock(&access_lock); | |
333 | } | |
334 | ||
335 | static inline void trace_access_lock_init(void) | |
336 | { | |
337 | } | |
338 | ||
339 | #endif | |
340 | ||
4fcdae83 | 341 | /* trace_wait is a waitqueue for tasks blocked on trace_poll */ |
4e655519 IM |
342 | static DECLARE_WAIT_QUEUE_HEAD(trace_wait); |
343 | ||
ee6bce52 | 344 | /* trace_flags holds trace_options default values */ |
12ef7d44 | 345 | unsigned long trace_flags = TRACE_ITER_PRINT_PARENT | TRACE_ITER_PRINTK | |
a2a16d6a | 346 | TRACE_ITER_ANNOTATE | TRACE_ITER_CONTEXT_INFO | TRACE_ITER_SLEEP_TIME | |
77271ce4 | 347 | TRACE_ITER_GRAPH_TIME | TRACE_ITER_RECORD_CMD | TRACE_ITER_OVERWRITE | |
5224c3a3 | 348 | TRACE_ITER_IRQ_INFO | TRACE_ITER_MARKERS; |
4e655519 | 349 | |
0d5c6e1c SR |
350 | /** |
351 | * trace_wake_up - wake up tasks waiting for trace input | |
352 | * | |
353 | * Schedules a delayed work to wake up any task that is blocked on the | |
354 | * trace_wait queue. These is used with trace_poll for tasks polling the | |
355 | * trace. | |
356 | */ | |
357 | static void trace_wake_up(struct irq_work *work) | |
e7e2ee89 | 358 | { |
0d5c6e1c | 359 | wake_up_all(&trace_wait); |
e7e2ee89 | 360 | |
0d5c6e1c | 361 | } |
e7e2ee89 | 362 | |
499e5470 SR |
363 | /** |
364 | * tracing_on - enable tracing buffers | |
365 | * | |
366 | * This function enables tracing buffers that may have been | |
367 | * disabled with tracing_off. | |
368 | */ | |
369 | void tracing_on(void) | |
370 | { | |
371 | if (global_trace.buffer) | |
372 | ring_buffer_record_on(global_trace.buffer); | |
373 | /* | |
374 | * This flag is only looked at when buffers haven't been | |
375 | * allocated yet. We don't really care about the race | |
376 | * between setting this flag and actually turning | |
377 | * on the buffer. | |
378 | */ | |
379 | global_trace.buffer_disabled = 0; | |
380 | } | |
381 | EXPORT_SYMBOL_GPL(tracing_on); | |
382 | ||
383 | /** | |
384 | * tracing_off - turn off tracing buffers | |
385 | * | |
386 | * This function stops the tracing buffers from recording data. | |
387 | * It does not disable any overhead the tracers themselves may | |
388 | * be causing. This function simply causes all recording to | |
389 | * the ring buffers to fail. | |
390 | */ | |
391 | void tracing_off(void) | |
392 | { | |
393 | if (global_trace.buffer) | |
f2bf1f6f | 394 | ring_buffer_record_off(global_trace.buffer); |
499e5470 SR |
395 | /* |
396 | * This flag is only looked at when buffers haven't been | |
397 | * allocated yet. We don't really care about the race | |
398 | * between setting this flag and actually turning | |
399 | * on the buffer. | |
400 | */ | |
401 | global_trace.buffer_disabled = 1; | |
402 | } | |
403 | EXPORT_SYMBOL_GPL(tracing_off); | |
404 | ||
405 | /** | |
406 | * tracing_is_on - show state of ring buffers enabled | |
407 | */ | |
408 | int tracing_is_on(void) | |
409 | { | |
410 | if (global_trace.buffer) | |
411 | return ring_buffer_record_is_on(global_trace.buffer); | |
412 | return !global_trace.buffer_disabled; | |
413 | } | |
414 | EXPORT_SYMBOL_GPL(tracing_is_on); | |
415 | ||
3928a8a2 | 416 | static int __init set_buf_size(char *str) |
bc0c38d1 | 417 | { |
3928a8a2 | 418 | unsigned long buf_size; |
c6caeeb1 | 419 | |
bc0c38d1 SR |
420 | if (!str) |
421 | return 0; | |
9d612bef | 422 | buf_size = memparse(str, &str); |
c6caeeb1 | 423 | /* nr_entries can not be zero */ |
9d612bef | 424 | if (buf_size == 0) |
c6caeeb1 | 425 | return 0; |
3928a8a2 | 426 | trace_buf_size = buf_size; |
bc0c38d1 SR |
427 | return 1; |
428 | } | |
3928a8a2 | 429 | __setup("trace_buf_size=", set_buf_size); |
bc0c38d1 | 430 | |
0e950173 TB |
431 | static int __init set_tracing_thresh(char *str) |
432 | { | |
87abb3b1 | 433 | unsigned long threshold; |
0e950173 TB |
434 | int ret; |
435 | ||
436 | if (!str) | |
437 | return 0; | |
bcd83ea6 | 438 | ret = kstrtoul(str, 0, &threshold); |
0e950173 TB |
439 | if (ret < 0) |
440 | return 0; | |
87abb3b1 | 441 | tracing_thresh = threshold * 1000; |
0e950173 TB |
442 | return 1; |
443 | } | |
444 | __setup("tracing_thresh=", set_tracing_thresh); | |
445 | ||
57f50be1 SR |
446 | unsigned long nsecs_to_usecs(unsigned long nsecs) |
447 | { | |
448 | return nsecs / 1000; | |
449 | } | |
450 | ||
4fcdae83 | 451 | /* These must match the bit postions in trace_iterator_flags */ |
bc0c38d1 SR |
452 | static const char *trace_options[] = { |
453 | "print-parent", | |
454 | "sym-offset", | |
455 | "sym-addr", | |
456 | "verbose", | |
f9896bf3 | 457 | "raw", |
5e3ca0ec | 458 | "hex", |
cb0f12aa | 459 | "bin", |
2a2cc8f7 | 460 | "block", |
86387f7e | 461 | "stacktrace", |
5e1607a0 | 462 | "trace_printk", |
b2a866f9 | 463 | "ftrace_preempt", |
9f029e83 | 464 | "branch", |
12ef7d44 | 465 | "annotate", |
02b67518 | 466 | "userstacktrace", |
b54d3de9 | 467 | "sym-userobj", |
66896a85 | 468 | "printk-msg-only", |
c4a8e8be | 469 | "context-info", |
c032ef64 | 470 | "latency-format", |
be6f164a | 471 | "sleep-time", |
a2a16d6a | 472 | "graph-time", |
e870e9a1 | 473 | "record-cmd", |
750912fa | 474 | "overwrite", |
cf30cf67 | 475 | "disable_on_free", |
77271ce4 | 476 | "irq-info", |
5224c3a3 | 477 | "markers", |
bc0c38d1 SR |
478 | NULL |
479 | }; | |
480 | ||
5079f326 Z |
481 | static struct { |
482 | u64 (*func)(void); | |
483 | const char *name; | |
8be0709f | 484 | int in_ns; /* is this clock in nanoseconds? */ |
5079f326 | 485 | } trace_clocks[] = { |
8be0709f DS |
486 | { trace_clock_local, "local", 1 }, |
487 | { trace_clock_global, "global", 1 }, | |
488 | { trace_clock_counter, "counter", 0 }, | |
8cbd9cc6 | 489 | ARCH_TRACE_CLOCKS |
5079f326 Z |
490 | }; |
491 | ||
492 | int trace_clock_id; | |
493 | ||
b63f39ea | 494 | /* |
495 | * trace_parser_get_init - gets the buffer for trace parser | |
496 | */ | |
497 | int trace_parser_get_init(struct trace_parser *parser, int size) | |
498 | { | |
499 | memset(parser, 0, sizeof(*parser)); | |
500 | ||
501 | parser->buffer = kmalloc(size, GFP_KERNEL); | |
502 | if (!parser->buffer) | |
503 | return 1; | |
504 | ||
505 | parser->size = size; | |
506 | return 0; | |
507 | } | |
508 | ||
509 | /* | |
510 | * trace_parser_put - frees the buffer for trace parser | |
511 | */ | |
512 | void trace_parser_put(struct trace_parser *parser) | |
513 | { | |
514 | kfree(parser->buffer); | |
515 | } | |
516 | ||
517 | /* | |
518 | * trace_get_user - reads the user input string separated by space | |
519 | * (matched by isspace(ch)) | |
520 | * | |
521 | * For each string found the 'struct trace_parser' is updated, | |
522 | * and the function returns. | |
523 | * | |
524 | * Returns number of bytes read. | |
525 | * | |
526 | * See kernel/trace/trace.h for 'struct trace_parser' details. | |
527 | */ | |
528 | int trace_get_user(struct trace_parser *parser, const char __user *ubuf, | |
529 | size_t cnt, loff_t *ppos) | |
530 | { | |
531 | char ch; | |
532 | size_t read = 0; | |
533 | ssize_t ret; | |
534 | ||
535 | if (!*ppos) | |
536 | trace_parser_clear(parser); | |
537 | ||
538 | ret = get_user(ch, ubuf++); | |
539 | if (ret) | |
540 | goto out; | |
541 | ||
542 | read++; | |
543 | cnt--; | |
544 | ||
545 | /* | |
546 | * The parser is not finished with the last write, | |
547 | * continue reading the user input without skipping spaces. | |
548 | */ | |
549 | if (!parser->cont) { | |
550 | /* skip white space */ | |
551 | while (cnt && isspace(ch)) { | |
552 | ret = get_user(ch, ubuf++); | |
553 | if (ret) | |
554 | goto out; | |
555 | read++; | |
556 | cnt--; | |
557 | } | |
558 | ||
559 | /* only spaces were written */ | |
560 | if (isspace(ch)) { | |
561 | *ppos += read; | |
562 | ret = read; | |
563 | goto out; | |
564 | } | |
565 | ||
566 | parser->idx = 0; | |
567 | } | |
568 | ||
569 | /* read the non-space input */ | |
570 | while (cnt && !isspace(ch)) { | |
3c235a33 | 571 | if (parser->idx < parser->size - 1) |
b63f39ea | 572 | parser->buffer[parser->idx++] = ch; |
573 | else { | |
574 | ret = -EINVAL; | |
575 | goto out; | |
576 | } | |
577 | ret = get_user(ch, ubuf++); | |
578 | if (ret) | |
579 | goto out; | |
580 | read++; | |
581 | cnt--; | |
582 | } | |
583 | ||
584 | /* We either got finished input or we have to wait for another call. */ | |
585 | if (isspace(ch)) { | |
586 | parser->buffer[parser->idx] = 0; | |
587 | parser->cont = false; | |
588 | } else { | |
589 | parser->cont = true; | |
590 | parser->buffer[parser->idx++] = ch; | |
591 | } | |
592 | ||
593 | *ppos += read; | |
594 | ret = read; | |
595 | ||
596 | out: | |
597 | return ret; | |
598 | } | |
599 | ||
6c6c2796 PP |
600 | ssize_t trace_seq_to_user(struct trace_seq *s, char __user *ubuf, size_t cnt) |
601 | { | |
602 | int len; | |
603 | int ret; | |
604 | ||
2dc5d12b SR |
605 | if (!cnt) |
606 | return 0; | |
607 | ||
6c6c2796 PP |
608 | if (s->len <= s->readpos) |
609 | return -EBUSY; | |
610 | ||
611 | len = s->len - s->readpos; | |
612 | if (cnt > len) | |
613 | cnt = len; | |
614 | ret = copy_to_user(ubuf, s->buffer + s->readpos, cnt); | |
2dc5d12b | 615 | if (ret == cnt) |
6c6c2796 PP |
616 | return -EFAULT; |
617 | ||
2dc5d12b SR |
618 | cnt -= ret; |
619 | ||
e74da523 | 620 | s->readpos += cnt; |
6c6c2796 | 621 | return cnt; |
214023c3 SR |
622 | } |
623 | ||
b8b94265 | 624 | static ssize_t trace_seq_to_buffer(struct trace_seq *s, void *buf, size_t cnt) |
3c56819b EGM |
625 | { |
626 | int len; | |
3c56819b EGM |
627 | |
628 | if (s->len <= s->readpos) | |
629 | return -EBUSY; | |
630 | ||
631 | len = s->len - s->readpos; | |
632 | if (cnt > len) | |
633 | cnt = len; | |
5a26c8f0 | 634 | memcpy(buf, s->buffer + s->readpos, cnt); |
3c56819b | 635 | |
e74da523 | 636 | s->readpos += cnt; |
3c56819b EGM |
637 | return cnt; |
638 | } | |
639 | ||
5d4a9dba SR |
640 | /* |
641 | * ftrace_max_lock is used to protect the swapping of buffers | |
642 | * when taking a max snapshot. The buffers themselves are | |
643 | * protected by per_cpu spinlocks. But the action of the swap | |
644 | * needs its own lock. | |
645 | * | |
445c8951 | 646 | * This is defined as a arch_spinlock_t in order to help |
5d4a9dba SR |
647 | * with performance when lockdep debugging is enabled. |
648 | * | |
649 | * It is also used in other places outside the update_max_tr | |
650 | * so it needs to be defined outside of the | |
651 | * CONFIG_TRACER_MAX_TRACE. | |
652 | */ | |
445c8951 | 653 | static arch_spinlock_t ftrace_max_lock = |
edc35bd7 | 654 | (arch_spinlock_t)__ARCH_SPIN_LOCK_UNLOCKED; |
5d4a9dba | 655 | |
0e950173 TB |
656 | unsigned long __read_mostly tracing_thresh; |
657 | ||
5d4a9dba SR |
658 | #ifdef CONFIG_TRACER_MAX_TRACE |
659 | unsigned long __read_mostly tracing_max_latency; | |
5d4a9dba SR |
660 | |
661 | /* | |
662 | * Copy the new maximum trace into the separate maximum-trace | |
663 | * structure. (this way the maximum trace is permanently saved, | |
664 | * for later retrieval via /sys/kernel/debug/tracing/latency_trace) | |
665 | */ | |
666 | static void | |
667 | __update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu) | |
668 | { | |
669 | struct trace_array_cpu *data = tr->data[cpu]; | |
1acaa1b2 | 670 | struct trace_array_cpu *max_data; |
5d4a9dba SR |
671 | |
672 | max_tr.cpu = cpu; | |
673 | max_tr.time_start = data->preempt_timestamp; | |
674 | ||
8248ac05 SR |
675 | max_data = max_tr.data[cpu]; |
676 | max_data->saved_latency = tracing_max_latency; | |
677 | max_data->critical_start = data->critical_start; | |
678 | max_data->critical_end = data->critical_end; | |
5d4a9dba | 679 | |
1acaa1b2 | 680 | memcpy(max_data->comm, tsk->comm, TASK_COMM_LEN); |
8248ac05 SR |
681 | max_data->pid = tsk->pid; |
682 | max_data->uid = task_uid(tsk); | |
683 | max_data->nice = tsk->static_prio - 20 - MAX_RT_PRIO; | |
684 | max_data->policy = tsk->policy; | |
685 | max_data->rt_priority = tsk->rt_priority; | |
5d4a9dba SR |
686 | |
687 | /* record this tasks comm */ | |
688 | tracing_record_cmdline(tsk); | |
689 | } | |
690 | ||
4fcdae83 SR |
691 | /** |
692 | * update_max_tr - snapshot all trace buffers from global_trace to max_tr | |
693 | * @tr: tracer | |
694 | * @tsk: the task with the latency | |
695 | * @cpu: The cpu that initiated the trace. | |
696 | * | |
697 | * Flip the buffers between the @tr and the max_tr and record information | |
698 | * about which task was the cause of this latency. | |
699 | */ | |
e309b41d | 700 | void |
bc0c38d1 SR |
701 | update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu) |
702 | { | |
2721e72d | 703 | struct ring_buffer *buf; |
bc0c38d1 | 704 | |
2b6080f2 | 705 | if (tr->stop_count) |
b8de7bd1 SR |
706 | return; |
707 | ||
4c11d7ae | 708 | WARN_ON_ONCE(!irqs_disabled()); |
34600f0e | 709 | |
2b6080f2 | 710 | if (!tr->current_trace->allocated_snapshot) { |
debdd57f | 711 | /* Only the nop tracer should hit this when disabling */ |
2b6080f2 | 712 | WARN_ON_ONCE(tr->current_trace != &nop_trace); |
34600f0e | 713 | return; |
debdd57f | 714 | } |
34600f0e | 715 | |
0199c4e6 | 716 | arch_spin_lock(&ftrace_max_lock); |
3928a8a2 | 717 | |
2721e72d | 718 | buf = tr->buffer; |
3928a8a2 SR |
719 | tr->buffer = max_tr.buffer; |
720 | max_tr.buffer = buf; | |
721 | ||
bc0c38d1 | 722 | __update_max_tr(tr, tsk, cpu); |
0199c4e6 | 723 | arch_spin_unlock(&ftrace_max_lock); |
bc0c38d1 SR |
724 | } |
725 | ||
726 | /** | |
727 | * update_max_tr_single - only copy one trace over, and reset the rest | |
728 | * @tr - tracer | |
729 | * @tsk - task with the latency | |
730 | * @cpu - the cpu of the buffer to copy. | |
4fcdae83 SR |
731 | * |
732 | * Flip the trace of a single CPU buffer between the @tr and the max_tr. | |
bc0c38d1 | 733 | */ |
e309b41d | 734 | void |
bc0c38d1 SR |
735 | update_max_tr_single(struct trace_array *tr, struct task_struct *tsk, int cpu) |
736 | { | |
3928a8a2 | 737 | int ret; |
bc0c38d1 | 738 | |
2b6080f2 | 739 | if (tr->stop_count) |
b8de7bd1 SR |
740 | return; |
741 | ||
4c11d7ae | 742 | WARN_ON_ONCE(!irqs_disabled()); |
2b6080f2 | 743 | if (WARN_ON_ONCE(!tr->current_trace->allocated_snapshot)) |
ef710e10 | 744 | return; |
ef710e10 | 745 | |
0199c4e6 | 746 | arch_spin_lock(&ftrace_max_lock); |
bc0c38d1 | 747 | |
3928a8a2 SR |
748 | ret = ring_buffer_swap_cpu(max_tr.buffer, tr->buffer, cpu); |
749 | ||
e8165dbb SR |
750 | if (ret == -EBUSY) { |
751 | /* | |
752 | * We failed to swap the buffer due to a commit taking | |
753 | * place on this CPU. We fail to record, but we reset | |
754 | * the max trace buffer (no one writes directly to it) | |
755 | * and flag that it failed. | |
756 | */ | |
757 | trace_array_printk(&max_tr, _THIS_IP_, | |
758 | "Failed to swap buffers due to commit in progress\n"); | |
759 | } | |
760 | ||
e8165dbb | 761 | WARN_ON_ONCE(ret && ret != -EAGAIN && ret != -EBUSY); |
bc0c38d1 SR |
762 | |
763 | __update_max_tr(tr, tsk, cpu); | |
0199c4e6 | 764 | arch_spin_unlock(&ftrace_max_lock); |
bc0c38d1 | 765 | } |
5d4a9dba | 766 | #endif /* CONFIG_TRACER_MAX_TRACE */ |
bc0c38d1 | 767 | |
0d5c6e1c SR |
768 | static void default_wait_pipe(struct trace_iterator *iter) |
769 | { | |
770 | DEFINE_WAIT(wait); | |
771 | ||
772 | prepare_to_wait(&trace_wait, &wait, TASK_INTERRUPTIBLE); | |
773 | ||
774 | /* | |
775 | * The events can happen in critical sections where | |
776 | * checking a work queue can cause deadlocks. | |
777 | * After adding a task to the queue, this flag is set | |
778 | * only to notify events to try to wake up the queue | |
779 | * using irq_work. | |
780 | * | |
781 | * We don't clear it even if the buffer is no longer | |
782 | * empty. The flag only causes the next event to run | |
783 | * irq_work to do the work queue wake up. The worse | |
784 | * that can happen if we race with !trace_empty() is that | |
785 | * an event will cause an irq_work to try to wake up | |
786 | * an empty queue. | |
787 | * | |
788 | * There's no reason to protect this flag either, as | |
789 | * the work queue and irq_work logic will do the necessary | |
790 | * synchronization for the wake ups. The only thing | |
791 | * that is necessary is that the wake up happens after | |
792 | * a task has been queued. It's OK for spurious wake ups. | |
793 | */ | |
794 | trace_wakeup_needed = true; | |
795 | ||
796 | if (trace_empty(iter)) | |
797 | schedule(); | |
798 | ||
799 | finish_wait(&trace_wait, &wait); | |
800 | } | |
801 | ||
4fcdae83 SR |
802 | /** |
803 | * register_tracer - register a tracer with the ftrace system. | |
804 | * @type - the plugin for the tracer | |
805 | * | |
806 | * Register a new plugin tracer. | |
807 | */ | |
bc0c38d1 SR |
808 | int register_tracer(struct tracer *type) |
809 | { | |
810 | struct tracer *t; | |
bc0c38d1 SR |
811 | int ret = 0; |
812 | ||
813 | if (!type->name) { | |
814 | pr_info("Tracer must have a name\n"); | |
815 | return -1; | |
816 | } | |
817 | ||
24a461d5 | 818 | if (strlen(type->name) >= MAX_TRACER_SIZE) { |
ee6c2c1b LZ |
819 | pr_info("Tracer has a name longer than %d\n", MAX_TRACER_SIZE); |
820 | return -1; | |
821 | } | |
822 | ||
bc0c38d1 | 823 | mutex_lock(&trace_types_lock); |
86fa2f60 | 824 | |
8e1b82e0 FW |
825 | tracing_selftest_running = true; |
826 | ||
bc0c38d1 SR |
827 | for (t = trace_types; t; t = t->next) { |
828 | if (strcmp(type->name, t->name) == 0) { | |
829 | /* already found */ | |
ee6c2c1b | 830 | pr_info("Tracer %s already registered\n", |
bc0c38d1 SR |
831 | type->name); |
832 | ret = -1; | |
833 | goto out; | |
834 | } | |
835 | } | |
836 | ||
adf9f195 FW |
837 | if (!type->set_flag) |
838 | type->set_flag = &dummy_set_flag; | |
839 | if (!type->flags) | |
840 | type->flags = &dummy_tracer_flags; | |
841 | else | |
842 | if (!type->flags->opts) | |
843 | type->flags->opts = dummy_tracer_opt; | |
6eaaa5d5 FW |
844 | if (!type->wait_pipe) |
845 | type->wait_pipe = default_wait_pipe; | |
846 | ||
adf9f195 | 847 | |
60a11774 | 848 | #ifdef CONFIG_FTRACE_STARTUP_TEST |
b2821ae6 | 849 | if (type->selftest && !tracing_selftest_disabled) { |
60a11774 | 850 | struct trace_array *tr = &global_trace; |
2b6080f2 | 851 | struct tracer *saved_tracer = tr->current_trace; |
ff32504f | 852 | |
60a11774 SR |
853 | /* |
854 | * Run a selftest on this tracer. | |
855 | * Here we reset the trace buffer, and set the current | |
856 | * tracer to be this tracer. The tracer can then run some | |
857 | * internal tracing to verify that everything is in order. | |
858 | * If we fail, we do not register this tracer. | |
859 | */ | |
76f0d073 | 860 | tracing_reset_online_cpus(tr); |
86fa2f60 | 861 | |
2b6080f2 | 862 | tr->current_trace = type; |
4a0b1665 | 863 | |
debdd57f HT |
864 | if (type->use_max_tr) { |
865 | /* If we expanded the buffers, make sure the max is expanded too */ | |
866 | if (ring_buffer_expanded) | |
867 | ring_buffer_resize(max_tr.buffer, trace_buf_size, | |
868 | RING_BUFFER_ALL_CPUS); | |
869 | type->allocated_snapshot = true; | |
870 | } | |
4a0b1665 | 871 | |
60a11774 SR |
872 | /* the test is responsible for initializing and enabling */ |
873 | pr_info("Testing tracer %s: ", type->name); | |
874 | ret = type->selftest(type, tr); | |
875 | /* the test is responsible for resetting too */ | |
2b6080f2 | 876 | tr->current_trace = saved_tracer; |
60a11774 SR |
877 | if (ret) { |
878 | printk(KERN_CONT "FAILED!\n"); | |
0be61ebc SR |
879 | /* Add the warning after printing 'FAILED' */ |
880 | WARN_ON(1); | |
60a11774 SR |
881 | goto out; |
882 | } | |
1d4db00a | 883 | /* Only reset on passing, to avoid touching corrupted buffers */ |
76f0d073 | 884 | tracing_reset_online_cpus(tr); |
86fa2f60 | 885 | |
debdd57f HT |
886 | if (type->use_max_tr) { |
887 | type->allocated_snapshot = false; | |
888 | ||
889 | /* Shrink the max buffer again */ | |
890 | if (ring_buffer_expanded) | |
891 | ring_buffer_resize(max_tr.buffer, 1, | |
892 | RING_BUFFER_ALL_CPUS); | |
893 | } | |
4a0b1665 | 894 | |
60a11774 SR |
895 | printk(KERN_CONT "PASSED\n"); |
896 | } | |
897 | #endif | |
898 | ||
bc0c38d1 SR |
899 | type->next = trace_types; |
900 | trace_types = type; | |
60a11774 | 901 | |
bc0c38d1 | 902 | out: |
8e1b82e0 | 903 | tracing_selftest_running = false; |
bc0c38d1 SR |
904 | mutex_unlock(&trace_types_lock); |
905 | ||
dac74940 SR |
906 | if (ret || !default_bootup_tracer) |
907 | goto out_unlock; | |
908 | ||
ee6c2c1b | 909 | if (strncmp(default_bootup_tracer, type->name, MAX_TRACER_SIZE)) |
dac74940 SR |
910 | goto out_unlock; |
911 | ||
912 | printk(KERN_INFO "Starting tracer '%s'\n", type->name); | |
913 | /* Do we want this tracer to start on bootup? */ | |
914 | tracing_set_tracer(type->name); | |
915 | default_bootup_tracer = NULL; | |
916 | /* disable other selftests, since this will break it. */ | |
917 | tracing_selftest_disabled = 1; | |
b2821ae6 | 918 | #ifdef CONFIG_FTRACE_STARTUP_TEST |
dac74940 SR |
919 | printk(KERN_INFO "Disabling FTRACE selftests due to running tracer '%s'\n", |
920 | type->name); | |
b2821ae6 | 921 | #endif |
b2821ae6 | 922 | |
dac74940 | 923 | out_unlock: |
bc0c38d1 SR |
924 | return ret; |
925 | } | |
926 | ||
f633903a SR |
927 | void tracing_reset(struct trace_array *tr, int cpu) |
928 | { | |
929 | struct ring_buffer *buffer = tr->buffer; | |
930 | ||
a5416411 HT |
931 | if (!buffer) |
932 | return; | |
933 | ||
f633903a SR |
934 | ring_buffer_record_disable(buffer); |
935 | ||
936 | /* Make sure all commits have finished */ | |
937 | synchronize_sched(); | |
68179686 | 938 | ring_buffer_reset_cpu(buffer, cpu); |
f633903a SR |
939 | |
940 | ring_buffer_record_enable(buffer); | |
941 | } | |
942 | ||
213cc060 PE |
943 | void tracing_reset_online_cpus(struct trace_array *tr) |
944 | { | |
621968cd | 945 | struct ring_buffer *buffer = tr->buffer; |
213cc060 PE |
946 | int cpu; |
947 | ||
a5416411 HT |
948 | if (!buffer) |
949 | return; | |
950 | ||
621968cd SR |
951 | ring_buffer_record_disable(buffer); |
952 | ||
953 | /* Make sure all commits have finished */ | |
954 | synchronize_sched(); | |
955 | ||
213cc060 PE |
956 | tr->time_start = ftrace_now(tr->cpu); |
957 | ||
958 | for_each_online_cpu(cpu) | |
68179686 | 959 | ring_buffer_reset_cpu(buffer, cpu); |
621968cd SR |
960 | |
961 | ring_buffer_record_enable(buffer); | |
213cc060 PE |
962 | } |
963 | ||
9456f0fa SR |
964 | void tracing_reset_current(int cpu) |
965 | { | |
966 | tracing_reset(&global_trace, cpu); | |
967 | } | |
968 | ||
969 | void tracing_reset_current_online_cpus(void) | |
970 | { | |
971 | tracing_reset_online_cpus(&global_trace); | |
972 | } | |
973 | ||
bc0c38d1 | 974 | #define SAVED_CMDLINES 128 |
2c7eea4c | 975 | #define NO_CMDLINE_MAP UINT_MAX |
bc0c38d1 SR |
976 | static unsigned map_pid_to_cmdline[PID_MAX_DEFAULT+1]; |
977 | static unsigned map_cmdline_to_pid[SAVED_CMDLINES]; | |
978 | static char saved_cmdlines[SAVED_CMDLINES][TASK_COMM_LEN]; | |
979 | static int cmdline_idx; | |
edc35bd7 | 980 | static arch_spinlock_t trace_cmdline_lock = __ARCH_SPIN_LOCK_UNLOCKED; |
25b0b44a | 981 | |
25b0b44a | 982 | /* temporary disable recording */ |
4fd27358 | 983 | static atomic_t trace_record_cmdline_disabled __read_mostly; |
bc0c38d1 SR |
984 | |
985 | static void trace_init_cmdlines(void) | |
986 | { | |
2c7eea4c TG |
987 | memset(&map_pid_to_cmdline, NO_CMDLINE_MAP, sizeof(map_pid_to_cmdline)); |
988 | memset(&map_cmdline_to_pid, NO_CMDLINE_MAP, sizeof(map_cmdline_to_pid)); | |
bc0c38d1 SR |
989 | cmdline_idx = 0; |
990 | } | |
991 | ||
b5130b1e CE |
992 | int is_tracing_stopped(void) |
993 | { | |
2b6080f2 | 994 | return global_trace.stop_count; |
b5130b1e CE |
995 | } |
996 | ||
69bb54ec SR |
997 | /** |
998 | * ftrace_off_permanent - disable all ftrace code permanently | |
999 | * | |
1000 | * This should only be called when a serious anomally has | |
1001 | * been detected. This will turn off the function tracing, | |
1002 | * ring buffers, and other tracing utilites. It takes no | |
1003 | * locks and can be called from any context. | |
1004 | */ | |
1005 | void ftrace_off_permanent(void) | |
1006 | { | |
1007 | tracing_disabled = 1; | |
1008 | ftrace_stop(); | |
1009 | tracing_off_permanent(); | |
1010 | } | |
1011 | ||
0f048701 SR |
1012 | /** |
1013 | * tracing_start - quick start of the tracer | |
1014 | * | |
1015 | * If tracing is enabled but was stopped by tracing_stop, | |
1016 | * this will start the tracer back up. | |
1017 | */ | |
1018 | void tracing_start(void) | |
1019 | { | |
1020 | struct ring_buffer *buffer; | |
1021 | unsigned long flags; | |
1022 | ||
1023 | if (tracing_disabled) | |
1024 | return; | |
1025 | ||
2b6080f2 SR |
1026 | raw_spin_lock_irqsave(&global_trace.start_lock, flags); |
1027 | if (--global_trace.stop_count) { | |
1028 | if (global_trace.stop_count < 0) { | |
b06a8301 SR |
1029 | /* Someone screwed up their debugging */ |
1030 | WARN_ON_ONCE(1); | |
2b6080f2 | 1031 | global_trace.stop_count = 0; |
b06a8301 | 1032 | } |
0f048701 SR |
1033 | goto out; |
1034 | } | |
1035 | ||
a2f80714 SR |
1036 | /* Prevent the buffers from switching */ |
1037 | arch_spin_lock(&ftrace_max_lock); | |
0f048701 SR |
1038 | |
1039 | buffer = global_trace.buffer; | |
1040 | if (buffer) | |
1041 | ring_buffer_record_enable(buffer); | |
1042 | ||
1043 | buffer = max_tr.buffer; | |
1044 | if (buffer) | |
1045 | ring_buffer_record_enable(buffer); | |
1046 | ||
a2f80714 SR |
1047 | arch_spin_unlock(&ftrace_max_lock); |
1048 | ||
0f048701 SR |
1049 | ftrace_start(); |
1050 | out: | |
2b6080f2 SR |
1051 | raw_spin_unlock_irqrestore(&global_trace.start_lock, flags); |
1052 | } | |
1053 | ||
1054 | static void tracing_start_tr(struct trace_array *tr) | |
1055 | { | |
1056 | struct ring_buffer *buffer; | |
1057 | unsigned long flags; | |
1058 | ||
1059 | if (tracing_disabled) | |
1060 | return; | |
1061 | ||
1062 | /* If global, we need to also start the max tracer */ | |
1063 | if (tr->flags & TRACE_ARRAY_FL_GLOBAL) | |
1064 | return tracing_start(); | |
1065 | ||
1066 | raw_spin_lock_irqsave(&tr->start_lock, flags); | |
1067 | ||
1068 | if (--tr->stop_count) { | |
1069 | if (tr->stop_count < 0) { | |
1070 | /* Someone screwed up their debugging */ | |
1071 | WARN_ON_ONCE(1); | |
1072 | tr->stop_count = 0; | |
1073 | } | |
1074 | goto out; | |
1075 | } | |
1076 | ||
1077 | buffer = tr->buffer; | |
1078 | if (buffer) | |
1079 | ring_buffer_record_enable(buffer); | |
1080 | ||
1081 | out: | |
1082 | raw_spin_unlock_irqrestore(&tr->start_lock, flags); | |
0f048701 SR |
1083 | } |
1084 | ||
1085 | /** | |
1086 | * tracing_stop - quick stop of the tracer | |
1087 | * | |
1088 | * Light weight way to stop tracing. Use in conjunction with | |
1089 | * tracing_start. | |
1090 | */ | |
1091 | void tracing_stop(void) | |
1092 | { | |
1093 | struct ring_buffer *buffer; | |
1094 | unsigned long flags; | |
1095 | ||
1096 | ftrace_stop(); | |
2b6080f2 SR |
1097 | raw_spin_lock_irqsave(&global_trace.start_lock, flags); |
1098 | if (global_trace.stop_count++) | |
0f048701 SR |
1099 | goto out; |
1100 | ||
a2f80714 SR |
1101 | /* Prevent the buffers from switching */ |
1102 | arch_spin_lock(&ftrace_max_lock); | |
1103 | ||
0f048701 SR |
1104 | buffer = global_trace.buffer; |
1105 | if (buffer) | |
1106 | ring_buffer_record_disable(buffer); | |
1107 | ||
1108 | buffer = max_tr.buffer; | |
1109 | if (buffer) | |
1110 | ring_buffer_record_disable(buffer); | |
1111 | ||
a2f80714 SR |
1112 | arch_spin_unlock(&ftrace_max_lock); |
1113 | ||
0f048701 | 1114 | out: |
2b6080f2 SR |
1115 | raw_spin_unlock_irqrestore(&global_trace.start_lock, flags); |
1116 | } | |
1117 | ||
1118 | static void tracing_stop_tr(struct trace_array *tr) | |
1119 | { | |
1120 | struct ring_buffer *buffer; | |
1121 | unsigned long flags; | |
1122 | ||
1123 | /* If global, we need to also stop the max tracer */ | |
1124 | if (tr->flags & TRACE_ARRAY_FL_GLOBAL) | |
1125 | return tracing_stop(); | |
1126 | ||
1127 | raw_spin_lock_irqsave(&tr->start_lock, flags); | |
1128 | if (tr->stop_count++) | |
1129 | goto out; | |
1130 | ||
1131 | buffer = tr->buffer; | |
1132 | if (buffer) | |
1133 | ring_buffer_record_disable(buffer); | |
1134 | ||
1135 | out: | |
1136 | raw_spin_unlock_irqrestore(&tr->start_lock, flags); | |
0f048701 SR |
1137 | } |
1138 | ||
e309b41d | 1139 | void trace_stop_cmdline_recording(void); |
bc0c38d1 | 1140 | |
e309b41d | 1141 | static void trace_save_cmdline(struct task_struct *tsk) |
bc0c38d1 | 1142 | { |
a635cf04 | 1143 | unsigned pid, idx; |
bc0c38d1 SR |
1144 | |
1145 | if (!tsk->pid || unlikely(tsk->pid > PID_MAX_DEFAULT)) | |
1146 | return; | |
1147 | ||
1148 | /* | |
1149 | * It's not the end of the world if we don't get | |
1150 | * the lock, but we also don't want to spin | |
1151 | * nor do we want to disable interrupts, | |
1152 | * so if we miss here, then better luck next time. | |
1153 | */ | |
0199c4e6 | 1154 | if (!arch_spin_trylock(&trace_cmdline_lock)) |
bc0c38d1 SR |
1155 | return; |
1156 | ||
1157 | idx = map_pid_to_cmdline[tsk->pid]; | |
2c7eea4c | 1158 | if (idx == NO_CMDLINE_MAP) { |
bc0c38d1 SR |
1159 | idx = (cmdline_idx + 1) % SAVED_CMDLINES; |
1160 | ||
a635cf04 CE |
1161 | /* |
1162 | * Check whether the cmdline buffer at idx has a pid | |
1163 | * mapped. We are going to overwrite that entry so we | |
1164 | * need to clear the map_pid_to_cmdline. Otherwise we | |
1165 | * would read the new comm for the old pid. | |
1166 | */ | |
1167 | pid = map_cmdline_to_pid[idx]; | |
1168 | if (pid != NO_CMDLINE_MAP) | |
1169 | map_pid_to_cmdline[pid] = NO_CMDLINE_MAP; | |
bc0c38d1 | 1170 | |
a635cf04 | 1171 | map_cmdline_to_pid[idx] = tsk->pid; |
bc0c38d1 SR |
1172 | map_pid_to_cmdline[tsk->pid] = idx; |
1173 | ||
1174 | cmdline_idx = idx; | |
1175 | } | |
1176 | ||
1177 | memcpy(&saved_cmdlines[idx], tsk->comm, TASK_COMM_LEN); | |
1178 | ||
0199c4e6 | 1179 | arch_spin_unlock(&trace_cmdline_lock); |
bc0c38d1 SR |
1180 | } |
1181 | ||
4ca53085 | 1182 | void trace_find_cmdline(int pid, char comm[]) |
bc0c38d1 | 1183 | { |
bc0c38d1 SR |
1184 | unsigned map; |
1185 | ||
4ca53085 SR |
1186 | if (!pid) { |
1187 | strcpy(comm, "<idle>"); | |
1188 | return; | |
1189 | } | |
bc0c38d1 | 1190 | |
74bf4076 SR |
1191 | if (WARN_ON_ONCE(pid < 0)) { |
1192 | strcpy(comm, "<XXX>"); | |
1193 | return; | |
1194 | } | |
1195 | ||
4ca53085 SR |
1196 | if (pid > PID_MAX_DEFAULT) { |
1197 | strcpy(comm, "<...>"); | |
1198 | return; | |
1199 | } | |
bc0c38d1 | 1200 | |
5b6045a9 | 1201 | preempt_disable(); |
0199c4e6 | 1202 | arch_spin_lock(&trace_cmdline_lock); |
bc0c38d1 | 1203 | map = map_pid_to_cmdline[pid]; |
50d88758 TG |
1204 | if (map != NO_CMDLINE_MAP) |
1205 | strcpy(comm, saved_cmdlines[map]); | |
1206 | else | |
1207 | strcpy(comm, "<...>"); | |
bc0c38d1 | 1208 | |
0199c4e6 | 1209 | arch_spin_unlock(&trace_cmdline_lock); |
5b6045a9 | 1210 | preempt_enable(); |
bc0c38d1 SR |
1211 | } |
1212 | ||
e309b41d | 1213 | void tracing_record_cmdline(struct task_struct *tsk) |
bc0c38d1 | 1214 | { |
0fb9656d | 1215 | if (atomic_read(&trace_record_cmdline_disabled) || !tracing_is_on()) |
bc0c38d1 SR |
1216 | return; |
1217 | ||
7ffbd48d SR |
1218 | if (!__this_cpu_read(trace_cmdline_save)) |
1219 | return; | |
1220 | ||
1221 | __this_cpu_write(trace_cmdline_save, false); | |
1222 | ||
bc0c38d1 SR |
1223 | trace_save_cmdline(tsk); |
1224 | } | |
1225 | ||
45dcd8b8 | 1226 | void |
38697053 SR |
1227 | tracing_generic_entry_update(struct trace_entry *entry, unsigned long flags, |
1228 | int pc) | |
bc0c38d1 SR |
1229 | { |
1230 | struct task_struct *tsk = current; | |
bc0c38d1 | 1231 | |
777e208d SR |
1232 | entry->preempt_count = pc & 0xff; |
1233 | entry->pid = (tsk) ? tsk->pid : 0; | |
1234 | entry->flags = | |
9244489a | 1235 | #ifdef CONFIG_TRACE_IRQFLAGS_SUPPORT |
2e2ca155 | 1236 | (irqs_disabled_flags(flags) ? TRACE_FLAG_IRQS_OFF : 0) | |
9244489a SR |
1237 | #else |
1238 | TRACE_FLAG_IRQS_NOSUPPORT | | |
1239 | #endif | |
bc0c38d1 SR |
1240 | ((pc & HARDIRQ_MASK) ? TRACE_FLAG_HARDIRQ : 0) | |
1241 | ((pc & SOFTIRQ_MASK) ? TRACE_FLAG_SOFTIRQ : 0) | | |
1242 | (need_resched() ? TRACE_FLAG_NEED_RESCHED : 0); | |
1243 | } | |
f413cdb8 | 1244 | EXPORT_SYMBOL_GPL(tracing_generic_entry_update); |
bc0c38d1 | 1245 | |
e77405ad SR |
1246 | struct ring_buffer_event * |
1247 | trace_buffer_lock_reserve(struct ring_buffer *buffer, | |
1248 | int type, | |
1249 | unsigned long len, | |
1250 | unsigned long flags, int pc) | |
51a763dd ACM |
1251 | { |
1252 | struct ring_buffer_event *event; | |
1253 | ||
e77405ad | 1254 | event = ring_buffer_lock_reserve(buffer, len); |
51a763dd ACM |
1255 | if (event != NULL) { |
1256 | struct trace_entry *ent = ring_buffer_event_data(event); | |
1257 | ||
1258 | tracing_generic_entry_update(ent, flags, pc); | |
1259 | ent->type = type; | |
1260 | } | |
1261 | ||
1262 | return event; | |
1263 | } | |
51a763dd | 1264 | |
7ffbd48d SR |
1265 | void |
1266 | __buffer_unlock_commit(struct ring_buffer *buffer, struct ring_buffer_event *event) | |
1267 | { | |
1268 | __this_cpu_write(trace_cmdline_save, true); | |
0d5c6e1c SR |
1269 | if (trace_wakeup_needed) { |
1270 | trace_wakeup_needed = false; | |
1271 | /* irq_work_queue() supplies it's own memory barriers */ | |
1272 | irq_work_queue(&trace_work_wakeup); | |
1273 | } | |
7ffbd48d SR |
1274 | ring_buffer_unlock_commit(buffer, event); |
1275 | } | |
1276 | ||
e77405ad SR |
1277 | static inline void |
1278 | __trace_buffer_unlock_commit(struct ring_buffer *buffer, | |
1279 | struct ring_buffer_event *event, | |
0d5c6e1c | 1280 | unsigned long flags, int pc) |
51a763dd | 1281 | { |
7ffbd48d | 1282 | __buffer_unlock_commit(buffer, event); |
51a763dd | 1283 | |
e77405ad SR |
1284 | ftrace_trace_stack(buffer, flags, 6, pc); |
1285 | ftrace_trace_userstack(buffer, flags, pc); | |
07edf712 FW |
1286 | } |
1287 | ||
e77405ad SR |
1288 | void trace_buffer_unlock_commit(struct ring_buffer *buffer, |
1289 | struct ring_buffer_event *event, | |
1290 | unsigned long flags, int pc) | |
07edf712 | 1291 | { |
0d5c6e1c | 1292 | __trace_buffer_unlock_commit(buffer, event, flags, pc); |
51a763dd | 1293 | } |
0d5c6e1c | 1294 | EXPORT_SYMBOL_GPL(trace_buffer_unlock_commit); |
51a763dd | 1295 | |
ccb469a1 SR |
1296 | struct ring_buffer_event * |
1297 | trace_event_buffer_lock_reserve(struct ring_buffer **current_rb, | |
1298 | struct ftrace_event_file *ftrace_file, | |
1299 | int type, unsigned long len, | |
1300 | unsigned long flags, int pc) | |
1301 | { | |
1302 | *current_rb = ftrace_file->tr->buffer; | |
1303 | return trace_buffer_lock_reserve(*current_rb, | |
1304 | type, len, flags, pc); | |
1305 | } | |
1306 | EXPORT_SYMBOL_GPL(trace_event_buffer_lock_reserve); | |
1307 | ||
ef5580d0 | 1308 | struct ring_buffer_event * |
e77405ad SR |
1309 | trace_current_buffer_lock_reserve(struct ring_buffer **current_rb, |
1310 | int type, unsigned long len, | |
ef5580d0 SR |
1311 | unsigned long flags, int pc) |
1312 | { | |
e77405ad SR |
1313 | *current_rb = global_trace.buffer; |
1314 | return trace_buffer_lock_reserve(*current_rb, | |
ef5580d0 SR |
1315 | type, len, flags, pc); |
1316 | } | |
94487d6d | 1317 | EXPORT_SYMBOL_GPL(trace_current_buffer_lock_reserve); |
ef5580d0 | 1318 | |
e77405ad SR |
1319 | void trace_current_buffer_unlock_commit(struct ring_buffer *buffer, |
1320 | struct ring_buffer_event *event, | |
ef5580d0 SR |
1321 | unsigned long flags, int pc) |
1322 | { | |
0d5c6e1c | 1323 | __trace_buffer_unlock_commit(buffer, event, flags, pc); |
07edf712 | 1324 | } |
94487d6d | 1325 | EXPORT_SYMBOL_GPL(trace_current_buffer_unlock_commit); |
07edf712 | 1326 | |
0d5c6e1c SR |
1327 | void trace_buffer_unlock_commit_regs(struct ring_buffer *buffer, |
1328 | struct ring_buffer_event *event, | |
1329 | unsigned long flags, int pc, | |
1330 | struct pt_regs *regs) | |
1fd8df2c | 1331 | { |
7ffbd48d | 1332 | __buffer_unlock_commit(buffer, event); |
1fd8df2c MH |
1333 | |
1334 | ftrace_trace_stack_regs(buffer, flags, 0, pc, regs); | |
1335 | ftrace_trace_userstack(buffer, flags, pc); | |
1336 | } | |
0d5c6e1c | 1337 | EXPORT_SYMBOL_GPL(trace_buffer_unlock_commit_regs); |
1fd8df2c | 1338 | |
e77405ad SR |
1339 | void trace_current_buffer_discard_commit(struct ring_buffer *buffer, |
1340 | struct ring_buffer_event *event) | |
77d9f465 | 1341 | { |
e77405ad | 1342 | ring_buffer_discard_commit(buffer, event); |
ef5580d0 | 1343 | } |
12acd473 | 1344 | EXPORT_SYMBOL_GPL(trace_current_buffer_discard_commit); |
ef5580d0 | 1345 | |
e309b41d | 1346 | void |
7be42151 | 1347 | trace_function(struct trace_array *tr, |
38697053 SR |
1348 | unsigned long ip, unsigned long parent_ip, unsigned long flags, |
1349 | int pc) | |
bc0c38d1 | 1350 | { |
e1112b4d | 1351 | struct ftrace_event_call *call = &event_function; |
e77405ad | 1352 | struct ring_buffer *buffer = tr->buffer; |
3928a8a2 | 1353 | struct ring_buffer_event *event; |
777e208d | 1354 | struct ftrace_entry *entry; |
bc0c38d1 | 1355 | |
d769041f | 1356 | /* If we are reading the ring buffer, don't trace */ |
dd17c8f7 | 1357 | if (unlikely(__this_cpu_read(ftrace_cpu_disabled))) |
d769041f SR |
1358 | return; |
1359 | ||
e77405ad | 1360 | event = trace_buffer_lock_reserve(buffer, TRACE_FN, sizeof(*entry), |
51a763dd | 1361 | flags, pc); |
3928a8a2 SR |
1362 | if (!event) |
1363 | return; | |
1364 | entry = ring_buffer_event_data(event); | |
777e208d SR |
1365 | entry->ip = ip; |
1366 | entry->parent_ip = parent_ip; | |
e1112b4d | 1367 | |
e77405ad | 1368 | if (!filter_check_discard(call, entry, buffer, event)) |
7ffbd48d | 1369 | __buffer_unlock_commit(buffer, event); |
bc0c38d1 SR |
1370 | } |
1371 | ||
e309b41d | 1372 | void |
2e0f5761 | 1373 | ftrace(struct trace_array *tr, struct trace_array_cpu *data, |
38697053 SR |
1374 | unsigned long ip, unsigned long parent_ip, unsigned long flags, |
1375 | int pc) | |
2e0f5761 IM |
1376 | { |
1377 | if (likely(!atomic_read(&data->disabled))) | |
7be42151 | 1378 | trace_function(tr, ip, parent_ip, flags, pc); |
2e0f5761 IM |
1379 | } |
1380 | ||
c0a0d0d3 | 1381 | #ifdef CONFIG_STACKTRACE |
4a9bd3f1 SR |
1382 | |
1383 | #define FTRACE_STACK_MAX_ENTRIES (PAGE_SIZE / sizeof(unsigned long)) | |
1384 | struct ftrace_stack { | |
1385 | unsigned long calls[FTRACE_STACK_MAX_ENTRIES]; | |
1386 | }; | |
1387 | ||
1388 | static DEFINE_PER_CPU(struct ftrace_stack, ftrace_stack); | |
1389 | static DEFINE_PER_CPU(int, ftrace_stack_reserve); | |
1390 | ||
e77405ad | 1391 | static void __ftrace_trace_stack(struct ring_buffer *buffer, |
53614991 | 1392 | unsigned long flags, |
1fd8df2c | 1393 | int skip, int pc, struct pt_regs *regs) |
86387f7e | 1394 | { |
e1112b4d | 1395 | struct ftrace_event_call *call = &event_kernel_stack; |
3928a8a2 | 1396 | struct ring_buffer_event *event; |
777e208d | 1397 | struct stack_entry *entry; |
86387f7e | 1398 | struct stack_trace trace; |
4a9bd3f1 SR |
1399 | int use_stack; |
1400 | int size = FTRACE_STACK_ENTRIES; | |
1401 | ||
1402 | trace.nr_entries = 0; | |
1403 | trace.skip = skip; | |
1404 | ||
1405 | /* | |
1406 | * Since events can happen in NMIs there's no safe way to | |
1407 | * use the per cpu ftrace_stacks. We reserve it and if an interrupt | |
1408 | * or NMI comes in, it will just have to use the default | |
1409 | * FTRACE_STACK_SIZE. | |
1410 | */ | |
1411 | preempt_disable_notrace(); | |
1412 | ||
82146529 | 1413 | use_stack = __this_cpu_inc_return(ftrace_stack_reserve); |
4a9bd3f1 SR |
1414 | /* |
1415 | * We don't need any atomic variables, just a barrier. | |
1416 | * If an interrupt comes in, we don't care, because it would | |
1417 | * have exited and put the counter back to what we want. | |
1418 | * We just need a barrier to keep gcc from moving things | |
1419 | * around. | |
1420 | */ | |
1421 | barrier(); | |
1422 | if (use_stack == 1) { | |
1423 | trace.entries = &__get_cpu_var(ftrace_stack).calls[0]; | |
1424 | trace.max_entries = FTRACE_STACK_MAX_ENTRIES; | |
1425 | ||
1426 | if (regs) | |
1427 | save_stack_trace_regs(regs, &trace); | |
1428 | else | |
1429 | save_stack_trace(&trace); | |
1430 | ||
1431 | if (trace.nr_entries > size) | |
1432 | size = trace.nr_entries; | |
1433 | } else | |
1434 | /* From now on, use_stack is a boolean */ | |
1435 | use_stack = 0; | |
1436 | ||
1437 | size *= sizeof(unsigned long); | |
86387f7e | 1438 | |
e77405ad | 1439 | event = trace_buffer_lock_reserve(buffer, TRACE_STACK, |
4a9bd3f1 | 1440 | sizeof(*entry) + size, flags, pc); |
3928a8a2 | 1441 | if (!event) |
4a9bd3f1 SR |
1442 | goto out; |
1443 | entry = ring_buffer_event_data(event); | |
86387f7e | 1444 | |
4a9bd3f1 SR |
1445 | memset(&entry->caller, 0, size); |
1446 | ||
1447 | if (use_stack) | |
1448 | memcpy(&entry->caller, trace.entries, | |
1449 | trace.nr_entries * sizeof(unsigned long)); | |
1450 | else { | |
1451 | trace.max_entries = FTRACE_STACK_ENTRIES; | |
1452 | trace.entries = entry->caller; | |
1453 | if (regs) | |
1454 | save_stack_trace_regs(regs, &trace); | |
1455 | else | |
1456 | save_stack_trace(&trace); | |
1457 | } | |
1458 | ||
1459 | entry->size = trace.nr_entries; | |
86387f7e | 1460 | |
e77405ad | 1461 | if (!filter_check_discard(call, entry, buffer, event)) |
7ffbd48d | 1462 | __buffer_unlock_commit(buffer, event); |
4a9bd3f1 SR |
1463 | |
1464 | out: | |
1465 | /* Again, don't let gcc optimize things here */ | |
1466 | barrier(); | |
82146529 | 1467 | __this_cpu_dec(ftrace_stack_reserve); |
4a9bd3f1 SR |
1468 | preempt_enable_notrace(); |
1469 | ||
f0a920d5 IM |
1470 | } |
1471 | ||
1fd8df2c MH |
1472 | void ftrace_trace_stack_regs(struct ring_buffer *buffer, unsigned long flags, |
1473 | int skip, int pc, struct pt_regs *regs) | |
1474 | { | |
1475 | if (!(trace_flags & TRACE_ITER_STACKTRACE)) | |
1476 | return; | |
1477 | ||
1478 | __ftrace_trace_stack(buffer, flags, skip, pc, regs); | |
1479 | } | |
1480 | ||
e77405ad SR |
1481 | void ftrace_trace_stack(struct ring_buffer *buffer, unsigned long flags, |
1482 | int skip, int pc) | |
53614991 SR |
1483 | { |
1484 | if (!(trace_flags & TRACE_ITER_STACKTRACE)) | |
1485 | return; | |
1486 | ||
1fd8df2c | 1487 | __ftrace_trace_stack(buffer, flags, skip, pc, NULL); |
53614991 SR |
1488 | } |
1489 | ||
c0a0d0d3 FW |
1490 | void __trace_stack(struct trace_array *tr, unsigned long flags, int skip, |
1491 | int pc) | |
38697053 | 1492 | { |
1fd8df2c | 1493 | __ftrace_trace_stack(tr->buffer, flags, skip, pc, NULL); |
38697053 SR |
1494 | } |
1495 | ||
03889384 SR |
1496 | /** |
1497 | * trace_dump_stack - record a stack back trace in the trace buffer | |
1498 | */ | |
1499 | void trace_dump_stack(void) | |
1500 | { | |
1501 | unsigned long flags; | |
1502 | ||
1503 | if (tracing_disabled || tracing_selftest_running) | |
e36c5458 | 1504 | return; |
03889384 SR |
1505 | |
1506 | local_save_flags(flags); | |
1507 | ||
1508 | /* skipping 3 traces, seems to get us at the caller of this function */ | |
1fd8df2c | 1509 | __ftrace_trace_stack(global_trace.buffer, flags, 3, preempt_count(), NULL); |
03889384 SR |
1510 | } |
1511 | ||
91e86e56 SR |
1512 | static DEFINE_PER_CPU(int, user_stack_count); |
1513 | ||
e77405ad SR |
1514 | void |
1515 | ftrace_trace_userstack(struct ring_buffer *buffer, unsigned long flags, int pc) | |
02b67518 | 1516 | { |
e1112b4d | 1517 | struct ftrace_event_call *call = &event_user_stack; |
8d7c6a96 | 1518 | struct ring_buffer_event *event; |
02b67518 TE |
1519 | struct userstack_entry *entry; |
1520 | struct stack_trace trace; | |
02b67518 TE |
1521 | |
1522 | if (!(trace_flags & TRACE_ITER_USERSTACKTRACE)) | |
1523 | return; | |
1524 | ||
b6345879 SR |
1525 | /* |
1526 | * NMIs can not handle page faults, even with fix ups. | |
1527 | * The save user stack can (and often does) fault. | |
1528 | */ | |
1529 | if (unlikely(in_nmi())) | |
1530 | return; | |
02b67518 | 1531 | |
91e86e56 SR |
1532 | /* |
1533 | * prevent recursion, since the user stack tracing may | |
1534 | * trigger other kernel events. | |
1535 | */ | |
1536 | preempt_disable(); | |
1537 | if (__this_cpu_read(user_stack_count)) | |
1538 | goto out; | |
1539 | ||
1540 | __this_cpu_inc(user_stack_count); | |
1541 | ||
e77405ad | 1542 | event = trace_buffer_lock_reserve(buffer, TRACE_USER_STACK, |
51a763dd | 1543 | sizeof(*entry), flags, pc); |
02b67518 | 1544 | if (!event) |
1dbd1951 | 1545 | goto out_drop_count; |
02b67518 | 1546 | entry = ring_buffer_event_data(event); |
02b67518 | 1547 | |
48659d31 | 1548 | entry->tgid = current->tgid; |
02b67518 TE |
1549 | memset(&entry->caller, 0, sizeof(entry->caller)); |
1550 | ||
1551 | trace.nr_entries = 0; | |
1552 | trace.max_entries = FTRACE_STACK_ENTRIES; | |
1553 | trace.skip = 0; | |
1554 | trace.entries = entry->caller; | |
1555 | ||
1556 | save_stack_trace_user(&trace); | |
e77405ad | 1557 | if (!filter_check_discard(call, entry, buffer, event)) |
7ffbd48d | 1558 | __buffer_unlock_commit(buffer, event); |
91e86e56 | 1559 | |
1dbd1951 | 1560 | out_drop_count: |
91e86e56 | 1561 | __this_cpu_dec(user_stack_count); |
91e86e56 SR |
1562 | out: |
1563 | preempt_enable(); | |
02b67518 TE |
1564 | } |
1565 | ||
4fd27358 HE |
1566 | #ifdef UNUSED |
1567 | static void __trace_userstack(struct trace_array *tr, unsigned long flags) | |
02b67518 | 1568 | { |
7be42151 | 1569 | ftrace_trace_userstack(tr, flags, preempt_count()); |
02b67518 | 1570 | } |
4fd27358 | 1571 | #endif /* UNUSED */ |
02b67518 | 1572 | |
c0a0d0d3 FW |
1573 | #endif /* CONFIG_STACKTRACE */ |
1574 | ||
07d777fe SR |
1575 | /* created for use with alloc_percpu */ |
1576 | struct trace_buffer_struct { | |
1577 | char buffer[TRACE_BUF_SIZE]; | |
1578 | }; | |
1579 | ||
1580 | static struct trace_buffer_struct *trace_percpu_buffer; | |
1581 | static struct trace_buffer_struct *trace_percpu_sirq_buffer; | |
1582 | static struct trace_buffer_struct *trace_percpu_irq_buffer; | |
1583 | static struct trace_buffer_struct *trace_percpu_nmi_buffer; | |
1584 | ||
1585 | /* | |
1586 | * The buffer used is dependent on the context. There is a per cpu | |
1587 | * buffer for normal context, softirq contex, hard irq context and | |
1588 | * for NMI context. Thise allows for lockless recording. | |
1589 | * | |
1590 | * Note, if the buffers failed to be allocated, then this returns NULL | |
1591 | */ | |
1592 | static char *get_trace_buf(void) | |
1593 | { | |
1594 | struct trace_buffer_struct *percpu_buffer; | |
07d777fe SR |
1595 | |
1596 | /* | |
1597 | * If we have allocated per cpu buffers, then we do not | |
1598 | * need to do any locking. | |
1599 | */ | |
1600 | if (in_nmi()) | |
1601 | percpu_buffer = trace_percpu_nmi_buffer; | |
1602 | else if (in_irq()) | |
1603 | percpu_buffer = trace_percpu_irq_buffer; | |
1604 | else if (in_softirq()) | |
1605 | percpu_buffer = trace_percpu_sirq_buffer; | |
1606 | else | |
1607 | percpu_buffer = trace_percpu_buffer; | |
1608 | ||
1609 | if (!percpu_buffer) | |
1610 | return NULL; | |
1611 | ||
d8a0349c | 1612 | return this_cpu_ptr(&percpu_buffer->buffer[0]); |
07d777fe SR |
1613 | } |
1614 | ||
1615 | static int alloc_percpu_trace_buffer(void) | |
1616 | { | |
1617 | struct trace_buffer_struct *buffers; | |
1618 | struct trace_buffer_struct *sirq_buffers; | |
1619 | struct trace_buffer_struct *irq_buffers; | |
1620 | struct trace_buffer_struct *nmi_buffers; | |
1621 | ||
1622 | buffers = alloc_percpu(struct trace_buffer_struct); | |
1623 | if (!buffers) | |
1624 | goto err_warn; | |
1625 | ||
1626 | sirq_buffers = alloc_percpu(struct trace_buffer_struct); | |
1627 | if (!sirq_buffers) | |
1628 | goto err_sirq; | |
1629 | ||
1630 | irq_buffers = alloc_percpu(struct trace_buffer_struct); | |
1631 | if (!irq_buffers) | |
1632 | goto err_irq; | |
1633 | ||
1634 | nmi_buffers = alloc_percpu(struct trace_buffer_struct); | |
1635 | if (!nmi_buffers) | |
1636 | goto err_nmi; | |
1637 | ||
1638 | trace_percpu_buffer = buffers; | |
1639 | trace_percpu_sirq_buffer = sirq_buffers; | |
1640 | trace_percpu_irq_buffer = irq_buffers; | |
1641 | trace_percpu_nmi_buffer = nmi_buffers; | |
1642 | ||
1643 | return 0; | |
1644 | ||
1645 | err_nmi: | |
1646 | free_percpu(irq_buffers); | |
1647 | err_irq: | |
1648 | free_percpu(sirq_buffers); | |
1649 | err_sirq: | |
1650 | free_percpu(buffers); | |
1651 | err_warn: | |
1652 | WARN(1, "Could not allocate percpu trace_printk buffer"); | |
1653 | return -ENOMEM; | |
1654 | } | |
1655 | ||
81698831 SR |
1656 | static int buffers_allocated; |
1657 | ||
07d777fe SR |
1658 | void trace_printk_init_buffers(void) |
1659 | { | |
07d777fe SR |
1660 | if (buffers_allocated) |
1661 | return; | |
1662 | ||
1663 | if (alloc_percpu_trace_buffer()) | |
1664 | return; | |
1665 | ||
1666 | pr_info("ftrace: Allocated trace_printk buffers\n"); | |
1667 | ||
b382ede6 SR |
1668 | /* Expand the buffers to set size */ |
1669 | tracing_update_buffers(); | |
1670 | ||
07d777fe | 1671 | buffers_allocated = 1; |
81698831 SR |
1672 | |
1673 | /* | |
1674 | * trace_printk_init_buffers() can be called by modules. | |
1675 | * If that happens, then we need to start cmdline recording | |
1676 | * directly here. If the global_trace.buffer is already | |
1677 | * allocated here, then this was called by module code. | |
1678 | */ | |
1679 | if (global_trace.buffer) | |
1680 | tracing_start_cmdline_record(); | |
1681 | } | |
1682 | ||
1683 | void trace_printk_start_comm(void) | |
1684 | { | |
1685 | /* Start tracing comms if trace printk is set */ | |
1686 | if (!buffers_allocated) | |
1687 | return; | |
1688 | tracing_start_cmdline_record(); | |
1689 | } | |
1690 | ||
1691 | static void trace_printk_start_stop_comm(int enabled) | |
1692 | { | |
1693 | if (!buffers_allocated) | |
1694 | return; | |
1695 | ||
1696 | if (enabled) | |
1697 | tracing_start_cmdline_record(); | |
1698 | else | |
1699 | tracing_stop_cmdline_record(); | |
07d777fe SR |
1700 | } |
1701 | ||
769b0441 | 1702 | /** |
48ead020 | 1703 | * trace_vbprintk - write binary msg to tracing buffer |
769b0441 FW |
1704 | * |
1705 | */ | |
40ce74f1 | 1706 | int trace_vbprintk(unsigned long ip, const char *fmt, va_list args) |
769b0441 | 1707 | { |
e1112b4d | 1708 | struct ftrace_event_call *call = &event_bprint; |
769b0441 | 1709 | struct ring_buffer_event *event; |
e77405ad | 1710 | struct ring_buffer *buffer; |
769b0441 | 1711 | struct trace_array *tr = &global_trace; |
48ead020 | 1712 | struct bprint_entry *entry; |
769b0441 | 1713 | unsigned long flags; |
07d777fe SR |
1714 | char *tbuffer; |
1715 | int len = 0, size, pc; | |
769b0441 FW |
1716 | |
1717 | if (unlikely(tracing_selftest_running || tracing_disabled)) | |
1718 | return 0; | |
1719 | ||
1720 | /* Don't pollute graph traces with trace_vprintk internals */ | |
1721 | pause_graph_tracing(); | |
1722 | ||
1723 | pc = preempt_count(); | |
5168ae50 | 1724 | preempt_disable_notrace(); |
769b0441 | 1725 | |
07d777fe SR |
1726 | tbuffer = get_trace_buf(); |
1727 | if (!tbuffer) { | |
1728 | len = 0; | |
769b0441 | 1729 | goto out; |
07d777fe | 1730 | } |
769b0441 | 1731 | |
07d777fe | 1732 | len = vbin_printf((u32 *)tbuffer, TRACE_BUF_SIZE/sizeof(int), fmt, args); |
769b0441 | 1733 | |
07d777fe SR |
1734 | if (len > TRACE_BUF_SIZE/sizeof(int) || len < 0) |
1735 | goto out; | |
769b0441 | 1736 | |
07d777fe | 1737 | local_save_flags(flags); |
769b0441 | 1738 | size = sizeof(*entry) + sizeof(u32) * len; |
e77405ad SR |
1739 | buffer = tr->buffer; |
1740 | event = trace_buffer_lock_reserve(buffer, TRACE_BPRINT, size, | |
1741 | flags, pc); | |
769b0441 | 1742 | if (!event) |
07d777fe | 1743 | goto out; |
769b0441 FW |
1744 | entry = ring_buffer_event_data(event); |
1745 | entry->ip = ip; | |
769b0441 FW |
1746 | entry->fmt = fmt; |
1747 | ||
07d777fe | 1748 | memcpy(entry->buf, tbuffer, sizeof(u32) * len); |
d931369b | 1749 | if (!filter_check_discard(call, entry, buffer, event)) { |
7ffbd48d | 1750 | __buffer_unlock_commit(buffer, event); |
d931369b SR |
1751 | ftrace_trace_stack(buffer, flags, 6, pc); |
1752 | } | |
769b0441 | 1753 | |
769b0441 | 1754 | out: |
5168ae50 | 1755 | preempt_enable_notrace(); |
769b0441 FW |
1756 | unpause_graph_tracing(); |
1757 | ||
1758 | return len; | |
1759 | } | |
48ead020 FW |
1760 | EXPORT_SYMBOL_GPL(trace_vbprintk); |
1761 | ||
659372d3 SR |
1762 | int trace_array_printk(struct trace_array *tr, |
1763 | unsigned long ip, const char *fmt, ...) | |
1764 | { | |
1765 | int ret; | |
1766 | va_list ap; | |
1767 | ||
1768 | if (!(trace_flags & TRACE_ITER_PRINTK)) | |
1769 | return 0; | |
1770 | ||
1771 | va_start(ap, fmt); | |
1772 | ret = trace_array_vprintk(tr, ip, fmt, ap); | |
1773 | va_end(ap); | |
1774 | return ret; | |
1775 | } | |
1776 | ||
1777 | int trace_array_vprintk(struct trace_array *tr, | |
1778 | unsigned long ip, const char *fmt, va_list args) | |
48ead020 | 1779 | { |
e1112b4d | 1780 | struct ftrace_event_call *call = &event_print; |
48ead020 | 1781 | struct ring_buffer_event *event; |
e77405ad | 1782 | struct ring_buffer *buffer; |
07d777fe | 1783 | int len = 0, size, pc; |
48ead020 | 1784 | struct print_entry *entry; |
07d777fe SR |
1785 | unsigned long flags; |
1786 | char *tbuffer; | |
48ead020 FW |
1787 | |
1788 | if (tracing_disabled || tracing_selftest_running) | |
1789 | return 0; | |
1790 | ||
07d777fe SR |
1791 | /* Don't pollute graph traces with trace_vprintk internals */ |
1792 | pause_graph_tracing(); | |
1793 | ||
48ead020 FW |
1794 | pc = preempt_count(); |
1795 | preempt_disable_notrace(); | |
48ead020 | 1796 | |
07d777fe SR |
1797 | |
1798 | tbuffer = get_trace_buf(); | |
1799 | if (!tbuffer) { | |
1800 | len = 0; | |
48ead020 | 1801 | goto out; |
07d777fe | 1802 | } |
48ead020 | 1803 | |
07d777fe SR |
1804 | len = vsnprintf(tbuffer, TRACE_BUF_SIZE, fmt, args); |
1805 | if (len > TRACE_BUF_SIZE) | |
1806 | goto out; | |
48ead020 | 1807 | |
07d777fe | 1808 | local_save_flags(flags); |
48ead020 | 1809 | size = sizeof(*entry) + len + 1; |
e77405ad SR |
1810 | buffer = tr->buffer; |
1811 | event = trace_buffer_lock_reserve(buffer, TRACE_PRINT, size, | |
07d777fe | 1812 | flags, pc); |
48ead020 | 1813 | if (!event) |
07d777fe | 1814 | goto out; |
48ead020 | 1815 | entry = ring_buffer_event_data(event); |
c13d2f7c | 1816 | entry->ip = ip; |
48ead020 | 1817 | |
07d777fe | 1818 | memcpy(&entry->buf, tbuffer, len); |
c13d2f7c | 1819 | entry->buf[len] = '\0'; |
d931369b | 1820 | if (!filter_check_discard(call, entry, buffer, event)) { |
7ffbd48d | 1821 | __buffer_unlock_commit(buffer, event); |
07d777fe | 1822 | ftrace_trace_stack(buffer, flags, 6, pc); |
d931369b | 1823 | } |
48ead020 FW |
1824 | out: |
1825 | preempt_enable_notrace(); | |
07d777fe | 1826 | unpause_graph_tracing(); |
48ead020 FW |
1827 | |
1828 | return len; | |
1829 | } | |
659372d3 SR |
1830 | |
1831 | int trace_vprintk(unsigned long ip, const char *fmt, va_list args) | |
1832 | { | |
a813a159 | 1833 | return trace_array_vprintk(&global_trace, ip, fmt, args); |
659372d3 | 1834 | } |
769b0441 FW |
1835 | EXPORT_SYMBOL_GPL(trace_vprintk); |
1836 | ||
e2ac8ef5 | 1837 | static void trace_iterator_increment(struct trace_iterator *iter) |
5a90f577 | 1838 | { |
6d158a81 SR |
1839 | struct ring_buffer_iter *buf_iter = trace_buffer_iter(iter, iter->cpu); |
1840 | ||
5a90f577 | 1841 | iter->idx++; |
6d158a81 SR |
1842 | if (buf_iter) |
1843 | ring_buffer_read(buf_iter, NULL); | |
5a90f577 SR |
1844 | } |
1845 | ||
e309b41d | 1846 | static struct trace_entry * |
bc21b478 SR |
1847 | peek_next_entry(struct trace_iterator *iter, int cpu, u64 *ts, |
1848 | unsigned long *lost_events) | |
dd0e545f | 1849 | { |
3928a8a2 | 1850 | struct ring_buffer_event *event; |
6d158a81 | 1851 | struct ring_buffer_iter *buf_iter = trace_buffer_iter(iter, cpu); |
dd0e545f | 1852 | |
d769041f SR |
1853 | if (buf_iter) |
1854 | event = ring_buffer_iter_peek(buf_iter, ts); | |
1855 | else | |
bc21b478 SR |
1856 | event = ring_buffer_peek(iter->tr->buffer, cpu, ts, |
1857 | lost_events); | |
d769041f | 1858 | |
4a9bd3f1 SR |
1859 | if (event) { |
1860 | iter->ent_size = ring_buffer_event_length(event); | |
1861 | return ring_buffer_event_data(event); | |
1862 | } | |
1863 | iter->ent_size = 0; | |
1864 | return NULL; | |
dd0e545f | 1865 | } |
d769041f | 1866 | |
dd0e545f | 1867 | static struct trace_entry * |
bc21b478 SR |
1868 | __find_next_entry(struct trace_iterator *iter, int *ent_cpu, |
1869 | unsigned long *missing_events, u64 *ent_ts) | |
bc0c38d1 | 1870 | { |
3928a8a2 | 1871 | struct ring_buffer *buffer = iter->tr->buffer; |
bc0c38d1 | 1872 | struct trace_entry *ent, *next = NULL; |
aa27497c | 1873 | unsigned long lost_events = 0, next_lost = 0; |
b04cc6b1 | 1874 | int cpu_file = iter->cpu_file; |
3928a8a2 | 1875 | u64 next_ts = 0, ts; |
bc0c38d1 | 1876 | int next_cpu = -1; |
12b5da34 | 1877 | int next_size = 0; |
bc0c38d1 SR |
1878 | int cpu; |
1879 | ||
b04cc6b1 FW |
1880 | /* |
1881 | * If we are in a per_cpu trace file, don't bother by iterating over | |
1882 | * all cpu and peek directly. | |
1883 | */ | |
ae3b5093 | 1884 | if (cpu_file > RING_BUFFER_ALL_CPUS) { |
b04cc6b1 FW |
1885 | if (ring_buffer_empty_cpu(buffer, cpu_file)) |
1886 | return NULL; | |
bc21b478 | 1887 | ent = peek_next_entry(iter, cpu_file, ent_ts, missing_events); |
b04cc6b1 FW |
1888 | if (ent_cpu) |
1889 | *ent_cpu = cpu_file; | |
1890 | ||
1891 | return ent; | |
1892 | } | |
1893 | ||
ab46428c | 1894 | for_each_tracing_cpu(cpu) { |
dd0e545f | 1895 | |
3928a8a2 SR |
1896 | if (ring_buffer_empty_cpu(buffer, cpu)) |
1897 | continue; | |
dd0e545f | 1898 | |
bc21b478 | 1899 | ent = peek_next_entry(iter, cpu, &ts, &lost_events); |
dd0e545f | 1900 | |
cdd31cd2 IM |
1901 | /* |
1902 | * Pick the entry with the smallest timestamp: | |
1903 | */ | |
3928a8a2 | 1904 | if (ent && (!next || ts < next_ts)) { |
bc0c38d1 SR |
1905 | next = ent; |
1906 | next_cpu = cpu; | |
3928a8a2 | 1907 | next_ts = ts; |
bc21b478 | 1908 | next_lost = lost_events; |
12b5da34 | 1909 | next_size = iter->ent_size; |
bc0c38d1 SR |
1910 | } |
1911 | } | |
1912 | ||
12b5da34 SR |
1913 | iter->ent_size = next_size; |
1914 | ||
bc0c38d1 SR |
1915 | if (ent_cpu) |
1916 | *ent_cpu = next_cpu; | |
1917 | ||
3928a8a2 SR |
1918 | if (ent_ts) |
1919 | *ent_ts = next_ts; | |
1920 | ||
bc21b478 SR |
1921 | if (missing_events) |
1922 | *missing_events = next_lost; | |
1923 | ||
bc0c38d1 SR |
1924 | return next; |
1925 | } | |
1926 | ||
dd0e545f | 1927 | /* Find the next real entry, without updating the iterator itself */ |
c4a8e8be FW |
1928 | struct trace_entry *trace_find_next_entry(struct trace_iterator *iter, |
1929 | int *ent_cpu, u64 *ent_ts) | |
bc0c38d1 | 1930 | { |
bc21b478 | 1931 | return __find_next_entry(iter, ent_cpu, NULL, ent_ts); |
dd0e545f SR |
1932 | } |
1933 | ||
1934 | /* Find the next real entry, and increment the iterator to the next entry */ | |
955b61e5 | 1935 | void *trace_find_next_entry_inc(struct trace_iterator *iter) |
dd0e545f | 1936 | { |
bc21b478 SR |
1937 | iter->ent = __find_next_entry(iter, &iter->cpu, |
1938 | &iter->lost_events, &iter->ts); | |
dd0e545f | 1939 | |
3928a8a2 | 1940 | if (iter->ent) |
e2ac8ef5 | 1941 | trace_iterator_increment(iter); |
dd0e545f | 1942 | |
3928a8a2 | 1943 | return iter->ent ? iter : NULL; |
b3806b43 | 1944 | } |
bc0c38d1 | 1945 | |
e309b41d | 1946 | static void trace_consume(struct trace_iterator *iter) |
b3806b43 | 1947 | { |
bc21b478 SR |
1948 | ring_buffer_consume(iter->tr->buffer, iter->cpu, &iter->ts, |
1949 | &iter->lost_events); | |
bc0c38d1 SR |
1950 | } |
1951 | ||
e309b41d | 1952 | static void *s_next(struct seq_file *m, void *v, loff_t *pos) |
bc0c38d1 SR |
1953 | { |
1954 | struct trace_iterator *iter = m->private; | |
bc0c38d1 | 1955 | int i = (int)*pos; |
4e3c3333 | 1956 | void *ent; |
bc0c38d1 | 1957 | |
a63ce5b3 SR |
1958 | WARN_ON_ONCE(iter->leftover); |
1959 | ||
bc0c38d1 SR |
1960 | (*pos)++; |
1961 | ||
1962 | /* can't go backwards */ | |
1963 | if (iter->idx > i) | |
1964 | return NULL; | |
1965 | ||
1966 | if (iter->idx < 0) | |
955b61e5 | 1967 | ent = trace_find_next_entry_inc(iter); |
bc0c38d1 SR |
1968 | else |
1969 | ent = iter; | |
1970 | ||
1971 | while (ent && iter->idx < i) | |
955b61e5 | 1972 | ent = trace_find_next_entry_inc(iter); |
bc0c38d1 SR |
1973 | |
1974 | iter->pos = *pos; | |
1975 | ||
bc0c38d1 SR |
1976 | return ent; |
1977 | } | |
1978 | ||
955b61e5 | 1979 | void tracing_iter_reset(struct trace_iterator *iter, int cpu) |
2f26ebd5 SR |
1980 | { |
1981 | struct trace_array *tr = iter->tr; | |
1982 | struct ring_buffer_event *event; | |
1983 | struct ring_buffer_iter *buf_iter; | |
1984 | unsigned long entries = 0; | |
1985 | u64 ts; | |
1986 | ||
1987 | tr->data[cpu]->skipped_entries = 0; | |
1988 | ||
6d158a81 SR |
1989 | buf_iter = trace_buffer_iter(iter, cpu); |
1990 | if (!buf_iter) | |
2f26ebd5 SR |
1991 | return; |
1992 | ||
2f26ebd5 SR |
1993 | ring_buffer_iter_reset(buf_iter); |
1994 | ||
1995 | /* | |
1996 | * We could have the case with the max latency tracers | |
1997 | * that a reset never took place on a cpu. This is evident | |
1998 | * by the timestamp being before the start of the buffer. | |
1999 | */ | |
2000 | while ((event = ring_buffer_iter_peek(buf_iter, &ts))) { | |
2001 | if (ts >= iter->tr->time_start) | |
2002 | break; | |
2003 | entries++; | |
2004 | ring_buffer_read(buf_iter, NULL); | |
2005 | } | |
2006 | ||
2007 | tr->data[cpu]->skipped_entries = entries; | |
2008 | } | |
2009 | ||
d7350c3f | 2010 | /* |
d7350c3f FW |
2011 | * The current tracer is copied to avoid a global locking |
2012 | * all around. | |
2013 | */ | |
bc0c38d1 SR |
2014 | static void *s_start(struct seq_file *m, loff_t *pos) |
2015 | { | |
2016 | struct trace_iterator *iter = m->private; | |
2b6080f2 | 2017 | struct trace_array *tr = iter->tr; |
b04cc6b1 | 2018 | int cpu_file = iter->cpu_file; |
bc0c38d1 SR |
2019 | void *p = NULL; |
2020 | loff_t l = 0; | |
3928a8a2 | 2021 | int cpu; |
bc0c38d1 | 2022 | |
2fd196ec HT |
2023 | /* |
2024 | * copy the tracer to avoid using a global lock all around. | |
2025 | * iter->trace is a copy of current_trace, the pointer to the | |
2026 | * name may be used instead of a strcmp(), as iter->trace->name | |
2027 | * will point to the same string as current_trace->name. | |
2028 | */ | |
bc0c38d1 | 2029 | mutex_lock(&trace_types_lock); |
2b6080f2 SR |
2030 | if (unlikely(tr->current_trace && iter->trace->name != tr->current_trace->name)) |
2031 | *iter->trace = *tr->current_trace; | |
d7350c3f | 2032 | mutex_unlock(&trace_types_lock); |
bc0c38d1 | 2033 | |
debdd57f HT |
2034 | if (iter->snapshot && iter->trace->use_max_tr) |
2035 | return ERR_PTR(-EBUSY); | |
2036 | ||
2037 | if (!iter->snapshot) | |
2038 | atomic_inc(&trace_record_cmdline_disabled); | |
bc0c38d1 | 2039 | |
bc0c38d1 SR |
2040 | if (*pos != iter->pos) { |
2041 | iter->ent = NULL; | |
2042 | iter->cpu = 0; | |
2043 | iter->idx = -1; | |
2044 | ||
ae3b5093 | 2045 | if (cpu_file == RING_BUFFER_ALL_CPUS) { |
b04cc6b1 | 2046 | for_each_tracing_cpu(cpu) |
2f26ebd5 | 2047 | tracing_iter_reset(iter, cpu); |
b04cc6b1 | 2048 | } else |
2f26ebd5 | 2049 | tracing_iter_reset(iter, cpu_file); |
bc0c38d1 | 2050 | |
ac91d854 | 2051 | iter->leftover = 0; |
bc0c38d1 SR |
2052 | for (p = iter; p && l < *pos; p = s_next(m, p, &l)) |
2053 | ; | |
2054 | ||
2055 | } else { | |
a63ce5b3 SR |
2056 | /* |
2057 | * If we overflowed the seq_file before, then we want | |
2058 | * to just reuse the trace_seq buffer again. | |
2059 | */ | |
2060 | if (iter->leftover) | |
2061 | p = iter; | |
2062 | else { | |
2063 | l = *pos - 1; | |
2064 | p = s_next(m, p, &l); | |
2065 | } | |
bc0c38d1 SR |
2066 | } |
2067 | ||
4f535968 | 2068 | trace_event_read_lock(); |
7e53bd42 | 2069 | trace_access_lock(cpu_file); |
bc0c38d1 SR |
2070 | return p; |
2071 | } | |
2072 | ||
2073 | static void s_stop(struct seq_file *m, void *p) | |
2074 | { | |
7e53bd42 LJ |
2075 | struct trace_iterator *iter = m->private; |
2076 | ||
debdd57f HT |
2077 | if (iter->snapshot && iter->trace->use_max_tr) |
2078 | return; | |
2079 | ||
2080 | if (!iter->snapshot) | |
2081 | atomic_dec(&trace_record_cmdline_disabled); | |
7e53bd42 | 2082 | trace_access_unlock(iter->cpu_file); |
4f535968 | 2083 | trace_event_read_unlock(); |
bc0c38d1 SR |
2084 | } |
2085 | ||
39eaf7ef SR |
2086 | static void |
2087 | get_total_entries(struct trace_array *tr, unsigned long *total, unsigned long *entries) | |
2088 | { | |
2089 | unsigned long count; | |
2090 | int cpu; | |
2091 | ||
2092 | *total = 0; | |
2093 | *entries = 0; | |
2094 | ||
2095 | for_each_tracing_cpu(cpu) { | |
2096 | count = ring_buffer_entries_cpu(tr->buffer, cpu); | |
2097 | /* | |
2098 | * If this buffer has skipped entries, then we hold all | |
2099 | * entries for the trace and we need to ignore the | |
2100 | * ones before the time stamp. | |
2101 | */ | |
2102 | if (tr->data[cpu]->skipped_entries) { | |
2103 | count -= tr->data[cpu]->skipped_entries; | |
2104 | /* total is the same as the entries */ | |
2105 | *total += count; | |
2106 | } else | |
2107 | *total += count + | |
2108 | ring_buffer_overrun_cpu(tr->buffer, cpu); | |
2109 | *entries += count; | |
2110 | } | |
2111 | } | |
2112 | ||
e309b41d | 2113 | static void print_lat_help_header(struct seq_file *m) |
bc0c38d1 | 2114 | { |
a6168353 ME |
2115 | seq_puts(m, "# _------=> CPU# \n"); |
2116 | seq_puts(m, "# / _-----=> irqs-off \n"); | |
2117 | seq_puts(m, "# | / _----=> need-resched \n"); | |
2118 | seq_puts(m, "# || / _---=> hardirq/softirq \n"); | |
2119 | seq_puts(m, "# ||| / _--=> preempt-depth \n"); | |
e6e1e259 SR |
2120 | seq_puts(m, "# |||| / delay \n"); |
2121 | seq_puts(m, "# cmd pid ||||| time | caller \n"); | |
2122 | seq_puts(m, "# \\ / ||||| \\ | / \n"); | |
bc0c38d1 SR |
2123 | } |
2124 | ||
39eaf7ef | 2125 | static void print_event_info(struct trace_array *tr, struct seq_file *m) |
bc0c38d1 | 2126 | { |
39eaf7ef SR |
2127 | unsigned long total; |
2128 | unsigned long entries; | |
2129 | ||
2130 | get_total_entries(tr, &total, &entries); | |
2131 | seq_printf(m, "# entries-in-buffer/entries-written: %lu/%lu #P:%d\n", | |
2132 | entries, total, num_online_cpus()); | |
2133 | seq_puts(m, "#\n"); | |
2134 | } | |
2135 | ||
2136 | static void print_func_help_header(struct trace_array *tr, struct seq_file *m) | |
2137 | { | |
2138 | print_event_info(tr, m); | |
77271ce4 | 2139 | seq_puts(m, "# TASK-PID CPU# TIMESTAMP FUNCTION\n"); |
a6168353 | 2140 | seq_puts(m, "# | | | | |\n"); |
bc0c38d1 SR |
2141 | } |
2142 | ||
39eaf7ef | 2143 | static void print_func_help_header_irq(struct trace_array *tr, struct seq_file *m) |
77271ce4 | 2144 | { |
39eaf7ef | 2145 | print_event_info(tr, m); |
77271ce4 SR |
2146 | seq_puts(m, "# _-----=> irqs-off\n"); |
2147 | seq_puts(m, "# / _----=> need-resched\n"); | |
2148 | seq_puts(m, "# | / _---=> hardirq/softirq\n"); | |
2149 | seq_puts(m, "# || / _--=> preempt-depth\n"); | |
2150 | seq_puts(m, "# ||| / delay\n"); | |
2151 | seq_puts(m, "# TASK-PID CPU# |||| TIMESTAMP FUNCTION\n"); | |
2152 | seq_puts(m, "# | | | |||| | |\n"); | |
2153 | } | |
bc0c38d1 | 2154 | |
62b915f1 | 2155 | void |
bc0c38d1 SR |
2156 | print_trace_header(struct seq_file *m, struct trace_iterator *iter) |
2157 | { | |
2158 | unsigned long sym_flags = (trace_flags & TRACE_ITER_SYM_MASK); | |
2159 | struct trace_array *tr = iter->tr; | |
2160 | struct trace_array_cpu *data = tr->data[tr->cpu]; | |
2b6080f2 | 2161 | struct tracer *type = iter->trace; |
39eaf7ef SR |
2162 | unsigned long entries; |
2163 | unsigned long total; | |
bc0c38d1 SR |
2164 | const char *name = "preemption"; |
2165 | ||
d840f718 | 2166 | name = type->name; |
bc0c38d1 | 2167 | |
39eaf7ef | 2168 | get_total_entries(tr, &total, &entries); |
bc0c38d1 | 2169 | |
888b55dc | 2170 | seq_printf(m, "# %s latency trace v1.1.5 on %s\n", |
bc0c38d1 | 2171 | name, UTS_RELEASE); |
888b55dc | 2172 | seq_puts(m, "# -----------------------------------" |
bc0c38d1 | 2173 | "---------------------------------\n"); |
888b55dc | 2174 | seq_printf(m, "# latency: %lu us, #%lu/%lu, CPU#%d |" |
bc0c38d1 | 2175 | " (M:%s VP:%d, KP:%d, SP:%d HP:%d", |
57f50be1 | 2176 | nsecs_to_usecs(data->saved_latency), |
bc0c38d1 | 2177 | entries, |
4c11d7ae | 2178 | total, |
bc0c38d1 SR |
2179 | tr->cpu, |
2180 | #if defined(CONFIG_PREEMPT_NONE) | |
2181 | "server", | |
2182 | #elif defined(CONFIG_PREEMPT_VOLUNTARY) | |
2183 | "desktop", | |
b5c21b45 | 2184 | #elif defined(CONFIG_PREEMPT) |
bc0c38d1 SR |
2185 | "preempt", |
2186 | #else | |
2187 | "unknown", | |
2188 | #endif | |
2189 | /* These are reserved for later use */ | |
2190 | 0, 0, 0, 0); | |
2191 | #ifdef CONFIG_SMP | |
2192 | seq_printf(m, " #P:%d)\n", num_online_cpus()); | |
2193 | #else | |
2194 | seq_puts(m, ")\n"); | |
2195 | #endif | |
888b55dc KM |
2196 | seq_puts(m, "# -----------------\n"); |
2197 | seq_printf(m, "# | task: %.16s-%d " | |
bc0c38d1 | 2198 | "(uid:%d nice:%ld policy:%ld rt_prio:%ld)\n", |
d20b92ab EB |
2199 | data->comm, data->pid, |
2200 | from_kuid_munged(seq_user_ns(m), data->uid), data->nice, | |
bc0c38d1 | 2201 | data->policy, data->rt_priority); |
888b55dc | 2202 | seq_puts(m, "# -----------------\n"); |
bc0c38d1 SR |
2203 | |
2204 | if (data->critical_start) { | |
888b55dc | 2205 | seq_puts(m, "# => started at: "); |
214023c3 SR |
2206 | seq_print_ip_sym(&iter->seq, data->critical_start, sym_flags); |
2207 | trace_print_seq(m, &iter->seq); | |
888b55dc | 2208 | seq_puts(m, "\n# => ended at: "); |
214023c3 SR |
2209 | seq_print_ip_sym(&iter->seq, data->critical_end, sym_flags); |
2210 | trace_print_seq(m, &iter->seq); | |
8248ac05 | 2211 | seq_puts(m, "\n#\n"); |
bc0c38d1 SR |
2212 | } |
2213 | ||
888b55dc | 2214 | seq_puts(m, "#\n"); |
bc0c38d1 SR |
2215 | } |
2216 | ||
a309720c SR |
2217 | static void test_cpu_buff_start(struct trace_iterator *iter) |
2218 | { | |
2219 | struct trace_seq *s = &iter->seq; | |
2220 | ||
12ef7d44 SR |
2221 | if (!(trace_flags & TRACE_ITER_ANNOTATE)) |
2222 | return; | |
2223 | ||
2224 | if (!(iter->iter_flags & TRACE_FILE_ANNOTATE)) | |
2225 | return; | |
2226 | ||
4462344e | 2227 | if (cpumask_test_cpu(iter->cpu, iter->started)) |
a309720c SR |
2228 | return; |
2229 | ||
2f26ebd5 SR |
2230 | if (iter->tr->data[iter->cpu]->skipped_entries) |
2231 | return; | |
2232 | ||
4462344e | 2233 | cpumask_set_cpu(iter->cpu, iter->started); |
b0dfa978 FW |
2234 | |
2235 | /* Don't print started cpu buffer for the first entry of the trace */ | |
2236 | if (iter->idx > 1) | |
2237 | trace_seq_printf(s, "##### CPU %u buffer started ####\n", | |
2238 | iter->cpu); | |
a309720c SR |
2239 | } |
2240 | ||
2c4f035f | 2241 | static enum print_line_t print_trace_fmt(struct trace_iterator *iter) |
bc0c38d1 | 2242 | { |
214023c3 | 2243 | struct trace_seq *s = &iter->seq; |
bc0c38d1 | 2244 | unsigned long sym_flags = (trace_flags & TRACE_ITER_SYM_MASK); |
4e3c3333 | 2245 | struct trace_entry *entry; |
f633cef0 | 2246 | struct trace_event *event; |
bc0c38d1 | 2247 | |
4e3c3333 | 2248 | entry = iter->ent; |
dd0e545f | 2249 | |
a309720c SR |
2250 | test_cpu_buff_start(iter); |
2251 | ||
c4a8e8be | 2252 | event = ftrace_find_event(entry->type); |
bc0c38d1 | 2253 | |
c4a8e8be | 2254 | if (trace_flags & TRACE_ITER_CONTEXT_INFO) { |
27d48be8 SR |
2255 | if (iter->iter_flags & TRACE_FILE_LAT_FMT) { |
2256 | if (!trace_print_lat_context(iter)) | |
2257 | goto partial; | |
2258 | } else { | |
2259 | if (!trace_print_context(iter)) | |
2260 | goto partial; | |
2261 | } | |
c4a8e8be | 2262 | } |
bc0c38d1 | 2263 | |
268ccda0 | 2264 | if (event) |
a9a57763 | 2265 | return event->funcs->trace(iter, sym_flags, event); |
d9793bd8 ACM |
2266 | |
2267 | if (!trace_seq_printf(s, "Unknown type %d\n", entry->type)) | |
2268 | goto partial; | |
02b67518 | 2269 | |
2c4f035f | 2270 | return TRACE_TYPE_HANDLED; |
d9793bd8 ACM |
2271 | partial: |
2272 | return TRACE_TYPE_PARTIAL_LINE; | |
bc0c38d1 SR |
2273 | } |
2274 | ||
2c4f035f | 2275 | static enum print_line_t print_raw_fmt(struct trace_iterator *iter) |
f9896bf3 IM |
2276 | { |
2277 | struct trace_seq *s = &iter->seq; | |
2278 | struct trace_entry *entry; | |
f633cef0 | 2279 | struct trace_event *event; |
f9896bf3 IM |
2280 | |
2281 | entry = iter->ent; | |
dd0e545f | 2282 | |
c4a8e8be | 2283 | if (trace_flags & TRACE_ITER_CONTEXT_INFO) { |
d9793bd8 ACM |
2284 | if (!trace_seq_printf(s, "%d %d %llu ", |
2285 | entry->pid, iter->cpu, iter->ts)) | |
2286 | goto partial; | |
c4a8e8be | 2287 | } |
f9896bf3 | 2288 | |
f633cef0 | 2289 | event = ftrace_find_event(entry->type); |
268ccda0 | 2290 | if (event) |
a9a57763 | 2291 | return event->funcs->raw(iter, 0, event); |
d9793bd8 ACM |
2292 | |
2293 | if (!trace_seq_printf(s, "%d ?\n", entry->type)) | |
2294 | goto partial; | |
777e208d | 2295 | |
2c4f035f | 2296 | return TRACE_TYPE_HANDLED; |
d9793bd8 ACM |
2297 | partial: |
2298 | return TRACE_TYPE_PARTIAL_LINE; | |
f9896bf3 IM |
2299 | } |
2300 | ||
2c4f035f | 2301 | static enum print_line_t print_hex_fmt(struct trace_iterator *iter) |
5e3ca0ec IM |
2302 | { |
2303 | struct trace_seq *s = &iter->seq; | |
2304 | unsigned char newline = '\n'; | |
2305 | struct trace_entry *entry; | |
f633cef0 | 2306 | struct trace_event *event; |
5e3ca0ec IM |
2307 | |
2308 | entry = iter->ent; | |
dd0e545f | 2309 | |
c4a8e8be FW |
2310 | if (trace_flags & TRACE_ITER_CONTEXT_INFO) { |
2311 | SEQ_PUT_HEX_FIELD_RET(s, entry->pid); | |
2312 | SEQ_PUT_HEX_FIELD_RET(s, iter->cpu); | |
2313 | SEQ_PUT_HEX_FIELD_RET(s, iter->ts); | |
2314 | } | |
5e3ca0ec | 2315 | |
f633cef0 | 2316 | event = ftrace_find_event(entry->type); |
268ccda0 | 2317 | if (event) { |
a9a57763 | 2318 | enum print_line_t ret = event->funcs->hex(iter, 0, event); |
d9793bd8 ACM |
2319 | if (ret != TRACE_TYPE_HANDLED) |
2320 | return ret; | |
2321 | } | |
7104f300 | 2322 | |
5e3ca0ec IM |
2323 | SEQ_PUT_FIELD_RET(s, newline); |
2324 | ||
2c4f035f | 2325 | return TRACE_TYPE_HANDLED; |
5e3ca0ec IM |
2326 | } |
2327 | ||
2c4f035f | 2328 | static enum print_line_t print_bin_fmt(struct trace_iterator *iter) |
cb0f12aa IM |
2329 | { |
2330 | struct trace_seq *s = &iter->seq; | |
2331 | struct trace_entry *entry; | |
f633cef0 | 2332 | struct trace_event *event; |
cb0f12aa IM |
2333 | |
2334 | entry = iter->ent; | |
dd0e545f | 2335 | |
c4a8e8be FW |
2336 | if (trace_flags & TRACE_ITER_CONTEXT_INFO) { |
2337 | SEQ_PUT_FIELD_RET(s, entry->pid); | |
1830b52d | 2338 | SEQ_PUT_FIELD_RET(s, iter->cpu); |
c4a8e8be FW |
2339 | SEQ_PUT_FIELD_RET(s, iter->ts); |
2340 | } | |
cb0f12aa | 2341 | |
f633cef0 | 2342 | event = ftrace_find_event(entry->type); |
a9a57763 SR |
2343 | return event ? event->funcs->binary(iter, 0, event) : |
2344 | TRACE_TYPE_HANDLED; | |
cb0f12aa IM |
2345 | } |
2346 | ||
62b915f1 | 2347 | int trace_empty(struct trace_iterator *iter) |
bc0c38d1 | 2348 | { |
6d158a81 | 2349 | struct ring_buffer_iter *buf_iter; |
bc0c38d1 SR |
2350 | int cpu; |
2351 | ||
9aba60fe | 2352 | /* If we are looking at one CPU buffer, only check that one */ |
ae3b5093 | 2353 | if (iter->cpu_file != RING_BUFFER_ALL_CPUS) { |
9aba60fe | 2354 | cpu = iter->cpu_file; |
6d158a81 SR |
2355 | buf_iter = trace_buffer_iter(iter, cpu); |
2356 | if (buf_iter) { | |
2357 | if (!ring_buffer_iter_empty(buf_iter)) | |
9aba60fe SR |
2358 | return 0; |
2359 | } else { | |
2360 | if (!ring_buffer_empty_cpu(iter->tr->buffer, cpu)) | |
2361 | return 0; | |
2362 | } | |
2363 | return 1; | |
2364 | } | |
2365 | ||
ab46428c | 2366 | for_each_tracing_cpu(cpu) { |
6d158a81 SR |
2367 | buf_iter = trace_buffer_iter(iter, cpu); |
2368 | if (buf_iter) { | |
2369 | if (!ring_buffer_iter_empty(buf_iter)) | |
d769041f SR |
2370 | return 0; |
2371 | } else { | |
2372 | if (!ring_buffer_empty_cpu(iter->tr->buffer, cpu)) | |
2373 | return 0; | |
2374 | } | |
bc0c38d1 | 2375 | } |
d769041f | 2376 | |
797d3712 | 2377 | return 1; |
bc0c38d1 SR |
2378 | } |
2379 | ||
4f535968 | 2380 | /* Called with trace_event_read_lock() held. */ |
955b61e5 | 2381 | enum print_line_t print_trace_line(struct trace_iterator *iter) |
f9896bf3 | 2382 | { |
2c4f035f FW |
2383 | enum print_line_t ret; |
2384 | ||
ee5e51f5 JO |
2385 | if (iter->lost_events && |
2386 | !trace_seq_printf(&iter->seq, "CPU:%d [LOST %lu EVENTS]\n", | |
2387 | iter->cpu, iter->lost_events)) | |
2388 | return TRACE_TYPE_PARTIAL_LINE; | |
bc21b478 | 2389 | |
2c4f035f FW |
2390 | if (iter->trace && iter->trace->print_line) { |
2391 | ret = iter->trace->print_line(iter); | |
2392 | if (ret != TRACE_TYPE_UNHANDLED) | |
2393 | return ret; | |
2394 | } | |
72829bc3 | 2395 | |
48ead020 FW |
2396 | if (iter->ent->type == TRACE_BPRINT && |
2397 | trace_flags & TRACE_ITER_PRINTK && | |
2398 | trace_flags & TRACE_ITER_PRINTK_MSGONLY) | |
5ef841f6 | 2399 | return trace_print_bprintk_msg_only(iter); |
48ead020 | 2400 | |
66896a85 FW |
2401 | if (iter->ent->type == TRACE_PRINT && |
2402 | trace_flags & TRACE_ITER_PRINTK && | |
2403 | trace_flags & TRACE_ITER_PRINTK_MSGONLY) | |
5ef841f6 | 2404 | return trace_print_printk_msg_only(iter); |
66896a85 | 2405 | |
cb0f12aa IM |
2406 | if (trace_flags & TRACE_ITER_BIN) |
2407 | return print_bin_fmt(iter); | |
2408 | ||
5e3ca0ec IM |
2409 | if (trace_flags & TRACE_ITER_HEX) |
2410 | return print_hex_fmt(iter); | |
2411 | ||
f9896bf3 IM |
2412 | if (trace_flags & TRACE_ITER_RAW) |
2413 | return print_raw_fmt(iter); | |
2414 | ||
f9896bf3 IM |
2415 | return print_trace_fmt(iter); |
2416 | } | |
2417 | ||
7e9a49ef JO |
2418 | void trace_latency_header(struct seq_file *m) |
2419 | { | |
2420 | struct trace_iterator *iter = m->private; | |
2421 | ||
2422 | /* print nothing if the buffers are empty */ | |
2423 | if (trace_empty(iter)) | |
2424 | return; | |
2425 | ||
2426 | if (iter->iter_flags & TRACE_FILE_LAT_FMT) | |
2427 | print_trace_header(m, iter); | |
2428 | ||
2429 | if (!(trace_flags & TRACE_ITER_VERBOSE)) | |
2430 | print_lat_help_header(m); | |
2431 | } | |
2432 | ||
62b915f1 JO |
2433 | void trace_default_header(struct seq_file *m) |
2434 | { | |
2435 | struct trace_iterator *iter = m->private; | |
2436 | ||
f56e7f8e JO |
2437 | if (!(trace_flags & TRACE_ITER_CONTEXT_INFO)) |
2438 | return; | |
2439 | ||
62b915f1 JO |
2440 | if (iter->iter_flags & TRACE_FILE_LAT_FMT) { |
2441 | /* print nothing if the buffers are empty */ | |
2442 | if (trace_empty(iter)) | |
2443 | return; | |
2444 | print_trace_header(m, iter); | |
2445 | if (!(trace_flags & TRACE_ITER_VERBOSE)) | |
2446 | print_lat_help_header(m); | |
2447 | } else { | |
77271ce4 SR |
2448 | if (!(trace_flags & TRACE_ITER_VERBOSE)) { |
2449 | if (trace_flags & TRACE_ITER_IRQ_INFO) | |
39eaf7ef | 2450 | print_func_help_header_irq(iter->tr, m); |
77271ce4 | 2451 | else |
39eaf7ef | 2452 | print_func_help_header(iter->tr, m); |
77271ce4 | 2453 | } |
62b915f1 JO |
2454 | } |
2455 | } | |
2456 | ||
e0a413f6 SR |
2457 | static void test_ftrace_alive(struct seq_file *m) |
2458 | { | |
2459 | if (!ftrace_is_dead()) | |
2460 | return; | |
2461 | seq_printf(m, "# WARNING: FUNCTION TRACING IS CORRUPTED\n"); | |
2462 | seq_printf(m, "# MAY BE MISSING FUNCTION EVENTS\n"); | |
2463 | } | |
2464 | ||
d8741e2e SRRH |
2465 | #ifdef CONFIG_TRACER_MAX_TRACE |
2466 | static void print_snapshot_help(struct seq_file *m, struct trace_iterator *iter) | |
2467 | { | |
2468 | if (iter->trace->allocated_snapshot) | |
2469 | seq_printf(m, "#\n# * Snapshot is allocated *\n#\n"); | |
2470 | else | |
2471 | seq_printf(m, "#\n# * Snapshot is freed *\n#\n"); | |
2472 | ||
2473 | seq_printf(m, "# Snapshot commands:\n"); | |
2474 | seq_printf(m, "# echo 0 > snapshot : Clears and frees snapshot buffer\n"); | |
2475 | seq_printf(m, "# echo 1 > snapshot : Allocates snapshot buffer, if not already allocated.\n"); | |
2476 | seq_printf(m, "# Takes a snapshot of the main buffer.\n"); | |
2477 | seq_printf(m, "# echo 2 > snapshot : Clears snapshot buffer (but does not allocate)\n"); | |
2478 | seq_printf(m, "# (Doesn't have to be '2' works with any number that\n"); | |
2479 | seq_printf(m, "# is not a '0' or '1')\n"); | |
2480 | } | |
2481 | #else | |
2482 | /* Should never be called */ | |
2483 | static inline void print_snapshot_help(struct seq_file *m, struct trace_iterator *iter) { } | |
2484 | #endif | |
2485 | ||
bc0c38d1 SR |
2486 | static int s_show(struct seq_file *m, void *v) |
2487 | { | |
2488 | struct trace_iterator *iter = v; | |
a63ce5b3 | 2489 | int ret; |
bc0c38d1 SR |
2490 | |
2491 | if (iter->ent == NULL) { | |
2492 | if (iter->tr) { | |
2493 | seq_printf(m, "# tracer: %s\n", iter->trace->name); | |
2494 | seq_puts(m, "#\n"); | |
e0a413f6 | 2495 | test_ftrace_alive(m); |
bc0c38d1 | 2496 | } |
d8741e2e SRRH |
2497 | if (iter->snapshot && trace_empty(iter)) |
2498 | print_snapshot_help(m, iter); | |
2499 | else if (iter->trace && iter->trace->print_header) | |
8bba1bf5 | 2500 | iter->trace->print_header(m); |
62b915f1 JO |
2501 | else |
2502 | trace_default_header(m); | |
2503 | ||
a63ce5b3 SR |
2504 | } else if (iter->leftover) { |
2505 | /* | |
2506 | * If we filled the seq_file buffer earlier, we | |
2507 | * want to just show it now. | |
2508 | */ | |
2509 | ret = trace_print_seq(m, &iter->seq); | |
2510 | ||
2511 | /* ret should this time be zero, but you never know */ | |
2512 | iter->leftover = ret; | |
2513 | ||
bc0c38d1 | 2514 | } else { |
f9896bf3 | 2515 | print_trace_line(iter); |
a63ce5b3 SR |
2516 | ret = trace_print_seq(m, &iter->seq); |
2517 | /* | |
2518 | * If we overflow the seq_file buffer, then it will | |
2519 | * ask us for this data again at start up. | |
2520 | * Use that instead. | |
2521 | * ret is 0 if seq_file write succeeded. | |
2522 | * -1 otherwise. | |
2523 | */ | |
2524 | iter->leftover = ret; | |
bc0c38d1 SR |
2525 | } |
2526 | ||
2527 | return 0; | |
2528 | } | |
2529 | ||
88e9d34c | 2530 | static const struct seq_operations tracer_seq_ops = { |
4bf39a94 IM |
2531 | .start = s_start, |
2532 | .next = s_next, | |
2533 | .stop = s_stop, | |
2534 | .show = s_show, | |
bc0c38d1 SR |
2535 | }; |
2536 | ||
e309b41d | 2537 | static struct trace_iterator * |
debdd57f | 2538 | __tracing_open(struct inode *inode, struct file *file, bool snapshot) |
bc0c38d1 | 2539 | { |
2b6080f2 SR |
2540 | struct trace_cpu *tc = inode->i_private; |
2541 | struct trace_array *tr = tc->tr; | |
bc0c38d1 | 2542 | struct trace_iterator *iter; |
50e18b94 | 2543 | int cpu; |
bc0c38d1 | 2544 | |
85a2f9b4 SR |
2545 | if (tracing_disabled) |
2546 | return ERR_PTR(-ENODEV); | |
60a11774 | 2547 | |
50e18b94 | 2548 | iter = __seq_open_private(file, &tracer_seq_ops, sizeof(*iter)); |
85a2f9b4 SR |
2549 | if (!iter) |
2550 | return ERR_PTR(-ENOMEM); | |
bc0c38d1 | 2551 | |
6d158a81 SR |
2552 | iter->buffer_iter = kzalloc(sizeof(*iter->buffer_iter) * num_possible_cpus(), |
2553 | GFP_KERNEL); | |
93574fcc DC |
2554 | if (!iter->buffer_iter) |
2555 | goto release; | |
2556 | ||
d7350c3f FW |
2557 | /* |
2558 | * We make a copy of the current tracer to avoid concurrent | |
2559 | * changes on it while we are reading. | |
2560 | */ | |
bc0c38d1 | 2561 | mutex_lock(&trace_types_lock); |
d7350c3f | 2562 | iter->trace = kzalloc(sizeof(*iter->trace), GFP_KERNEL); |
85a2f9b4 | 2563 | if (!iter->trace) |
d7350c3f | 2564 | goto fail; |
85a2f9b4 | 2565 | |
2b6080f2 | 2566 | *iter->trace = *tr->current_trace; |
d7350c3f | 2567 | |
79f55997 | 2568 | if (!zalloc_cpumask_var(&iter->started, GFP_KERNEL)) |
b0dfa978 FW |
2569 | goto fail; |
2570 | ||
2b6080f2 SR |
2571 | /* Currently only the top directory has a snapshot */ |
2572 | if (tr->current_trace->print_max || snapshot) | |
bc0c38d1 SR |
2573 | iter->tr = &max_tr; |
2574 | else | |
2b6080f2 | 2575 | iter->tr = tr; |
debdd57f | 2576 | iter->snapshot = snapshot; |
bc0c38d1 | 2577 | iter->pos = -1; |
d7350c3f | 2578 | mutex_init(&iter->mutex); |
2b6080f2 | 2579 | iter->cpu_file = tc->cpu; |
bc0c38d1 | 2580 | |
8bba1bf5 MM |
2581 | /* Notify the tracer early; before we stop tracing. */ |
2582 | if (iter->trace && iter->trace->open) | |
a93751ca | 2583 | iter->trace->open(iter); |
8bba1bf5 | 2584 | |
12ef7d44 SR |
2585 | /* Annotate start of buffers if we had overruns */ |
2586 | if (ring_buffer_overruns(iter->tr->buffer)) | |
2587 | iter->iter_flags |= TRACE_FILE_ANNOTATE; | |
2588 | ||
8be0709f DS |
2589 | /* Output in nanoseconds only if we are using a clock in nanoseconds. */ |
2590 | if (trace_clocks[trace_clock_id].in_ns) | |
2591 | iter->iter_flags |= TRACE_FILE_TIME_IN_NS; | |
2592 | ||
debdd57f HT |
2593 | /* stop the trace while dumping if we are not opening "snapshot" */ |
2594 | if (!iter->snapshot) | |
2b6080f2 | 2595 | tracing_stop_tr(tr); |
2f26ebd5 | 2596 | |
ae3b5093 | 2597 | if (iter->cpu_file == RING_BUFFER_ALL_CPUS) { |
b04cc6b1 | 2598 | for_each_tracing_cpu(cpu) { |
b04cc6b1 | 2599 | iter->buffer_iter[cpu] = |
72c9ddfd DM |
2600 | ring_buffer_read_prepare(iter->tr->buffer, cpu); |
2601 | } | |
2602 | ring_buffer_read_prepare_sync(); | |
2603 | for_each_tracing_cpu(cpu) { | |
2604 | ring_buffer_read_start(iter->buffer_iter[cpu]); | |
2f26ebd5 | 2605 | tracing_iter_reset(iter, cpu); |
b04cc6b1 FW |
2606 | } |
2607 | } else { | |
2608 | cpu = iter->cpu_file; | |
3928a8a2 | 2609 | iter->buffer_iter[cpu] = |
72c9ddfd DM |
2610 | ring_buffer_read_prepare(iter->tr->buffer, cpu); |
2611 | ring_buffer_read_prepare_sync(); | |
2612 | ring_buffer_read_start(iter->buffer_iter[cpu]); | |
2f26ebd5 | 2613 | tracing_iter_reset(iter, cpu); |
3928a8a2 SR |
2614 | } |
2615 | ||
bc0c38d1 SR |
2616 | mutex_unlock(&trace_types_lock); |
2617 | ||
bc0c38d1 | 2618 | return iter; |
3928a8a2 | 2619 | |
d7350c3f | 2620 | fail: |
3928a8a2 | 2621 | mutex_unlock(&trace_types_lock); |
d7350c3f | 2622 | kfree(iter->trace); |
6d158a81 | 2623 | kfree(iter->buffer_iter); |
93574fcc | 2624 | release: |
50e18b94 JO |
2625 | seq_release_private(inode, file); |
2626 | return ERR_PTR(-ENOMEM); | |
bc0c38d1 SR |
2627 | } |
2628 | ||
2629 | int tracing_open_generic(struct inode *inode, struct file *filp) | |
2630 | { | |
60a11774 SR |
2631 | if (tracing_disabled) |
2632 | return -ENODEV; | |
2633 | ||
bc0c38d1 SR |
2634 | filp->private_data = inode->i_private; |
2635 | return 0; | |
2636 | } | |
2637 | ||
4fd27358 | 2638 | static int tracing_release(struct inode *inode, struct file *file) |
bc0c38d1 | 2639 | { |
907f2784 | 2640 | struct seq_file *m = file->private_data; |
4acd4d00 | 2641 | struct trace_iterator *iter; |
2b6080f2 | 2642 | struct trace_array *tr; |
3928a8a2 | 2643 | int cpu; |
bc0c38d1 | 2644 | |
4acd4d00 SR |
2645 | if (!(file->f_mode & FMODE_READ)) |
2646 | return 0; | |
2647 | ||
2648 | iter = m->private; | |
2649 | ||
2b6080f2 SR |
2650 | /* Only the global tracer has a matching max_tr */ |
2651 | if (iter->tr == &max_tr) | |
2652 | tr = &global_trace; | |
2653 | else | |
2654 | tr = iter->tr; | |
2655 | ||
bc0c38d1 | 2656 | mutex_lock(&trace_types_lock); |
3928a8a2 SR |
2657 | for_each_tracing_cpu(cpu) { |
2658 | if (iter->buffer_iter[cpu]) | |
2659 | ring_buffer_read_finish(iter->buffer_iter[cpu]); | |
2660 | } | |
2661 | ||
bc0c38d1 SR |
2662 | if (iter->trace && iter->trace->close) |
2663 | iter->trace->close(iter); | |
2664 | ||
debdd57f HT |
2665 | if (!iter->snapshot) |
2666 | /* reenable tracing if it was previously enabled */ | |
2b6080f2 | 2667 | tracing_start_tr(tr); |
bc0c38d1 SR |
2668 | mutex_unlock(&trace_types_lock); |
2669 | ||
d7350c3f | 2670 | mutex_destroy(&iter->mutex); |
b0dfa978 | 2671 | free_cpumask_var(iter->started); |
d7350c3f | 2672 | kfree(iter->trace); |
6d158a81 | 2673 | kfree(iter->buffer_iter); |
50e18b94 | 2674 | seq_release_private(inode, file); |
bc0c38d1 SR |
2675 | return 0; |
2676 | } | |
2677 | ||
2678 | static int tracing_open(struct inode *inode, struct file *file) | |
2679 | { | |
85a2f9b4 SR |
2680 | struct trace_iterator *iter; |
2681 | int ret = 0; | |
bc0c38d1 | 2682 | |
4acd4d00 SR |
2683 | /* If this file was open for write, then erase contents */ |
2684 | if ((file->f_mode & FMODE_WRITE) && | |
8650ae32 | 2685 | (file->f_flags & O_TRUNC)) { |
2b6080f2 SR |
2686 | struct trace_cpu *tc = inode->i_private; |
2687 | struct trace_array *tr = tc->tr; | |
bc0c38d1 | 2688 | |
2b6080f2 SR |
2689 | if (tc->cpu == RING_BUFFER_ALL_CPUS) |
2690 | tracing_reset_online_cpus(tr); | |
4acd4d00 | 2691 | else |
2b6080f2 | 2692 | tracing_reset(tr, tc->cpu); |
4acd4d00 | 2693 | } |
bc0c38d1 | 2694 | |
4acd4d00 | 2695 | if (file->f_mode & FMODE_READ) { |
debdd57f | 2696 | iter = __tracing_open(inode, file, false); |
4acd4d00 SR |
2697 | if (IS_ERR(iter)) |
2698 | ret = PTR_ERR(iter); | |
2699 | else if (trace_flags & TRACE_ITER_LATENCY_FMT) | |
2700 | iter->iter_flags |= TRACE_FILE_LAT_FMT; | |
2701 | } | |
bc0c38d1 SR |
2702 | return ret; |
2703 | } | |
2704 | ||
e309b41d | 2705 | static void * |
bc0c38d1 SR |
2706 | t_next(struct seq_file *m, void *v, loff_t *pos) |
2707 | { | |
f129e965 | 2708 | struct tracer *t = v; |
bc0c38d1 SR |
2709 | |
2710 | (*pos)++; | |
2711 | ||
2712 | if (t) | |
2713 | t = t->next; | |
2714 | ||
bc0c38d1 SR |
2715 | return t; |
2716 | } | |
2717 | ||
2718 | static void *t_start(struct seq_file *m, loff_t *pos) | |
2719 | { | |
f129e965 | 2720 | struct tracer *t; |
bc0c38d1 SR |
2721 | loff_t l = 0; |
2722 | ||
2723 | mutex_lock(&trace_types_lock); | |
f129e965 | 2724 | for (t = trace_types; t && l < *pos; t = t_next(m, t, &l)) |
bc0c38d1 SR |
2725 | ; |
2726 | ||
2727 | return t; | |
2728 | } | |
2729 | ||
2730 | static void t_stop(struct seq_file *m, void *p) | |
2731 | { | |
2732 | mutex_unlock(&trace_types_lock); | |
2733 | } | |
2734 | ||
2735 | static int t_show(struct seq_file *m, void *v) | |
2736 | { | |
2737 | struct tracer *t = v; | |
2738 | ||
2739 | if (!t) | |
2740 | return 0; | |
2741 | ||
2742 | seq_printf(m, "%s", t->name); | |
2743 | if (t->next) | |
2744 | seq_putc(m, ' '); | |
2745 | else | |
2746 | seq_putc(m, '\n'); | |
2747 | ||
2748 | return 0; | |
2749 | } | |
2750 | ||
88e9d34c | 2751 | static const struct seq_operations show_traces_seq_ops = { |
4bf39a94 IM |
2752 | .start = t_start, |
2753 | .next = t_next, | |
2754 | .stop = t_stop, | |
2755 | .show = t_show, | |
bc0c38d1 SR |
2756 | }; |
2757 | ||
2758 | static int show_traces_open(struct inode *inode, struct file *file) | |
2759 | { | |
60a11774 SR |
2760 | if (tracing_disabled) |
2761 | return -ENODEV; | |
2762 | ||
f129e965 | 2763 | return seq_open(file, &show_traces_seq_ops); |
bc0c38d1 SR |
2764 | } |
2765 | ||
4acd4d00 SR |
2766 | static ssize_t |
2767 | tracing_write_stub(struct file *filp, const char __user *ubuf, | |
2768 | size_t count, loff_t *ppos) | |
2769 | { | |
2770 | return count; | |
2771 | } | |
2772 | ||
364829b1 SP |
2773 | static loff_t tracing_seek(struct file *file, loff_t offset, int origin) |
2774 | { | |
2775 | if (file->f_mode & FMODE_READ) | |
2776 | return seq_lseek(file, offset, origin); | |
2777 | else | |
2778 | return 0; | |
2779 | } | |
2780 | ||
5e2336a0 | 2781 | static const struct file_operations tracing_fops = { |
4bf39a94 IM |
2782 | .open = tracing_open, |
2783 | .read = seq_read, | |
4acd4d00 | 2784 | .write = tracing_write_stub, |
364829b1 | 2785 | .llseek = tracing_seek, |
4bf39a94 | 2786 | .release = tracing_release, |
bc0c38d1 SR |
2787 | }; |
2788 | ||
5e2336a0 | 2789 | static const struct file_operations show_traces_fops = { |
c7078de1 IM |
2790 | .open = show_traces_open, |
2791 | .read = seq_read, | |
2792 | .release = seq_release, | |
b444786f | 2793 | .llseek = seq_lseek, |
c7078de1 IM |
2794 | }; |
2795 | ||
36dfe925 IM |
2796 | /* |
2797 | * Only trace on a CPU if the bitmask is set: | |
2798 | */ | |
9e01c1b7 | 2799 | static cpumask_var_t tracing_cpumask; |
36dfe925 IM |
2800 | |
2801 | /* | |
2802 | * The tracer itself will not take this lock, but still we want | |
2803 | * to provide a consistent cpumask to user-space: | |
2804 | */ | |
2805 | static DEFINE_MUTEX(tracing_cpumask_update_lock); | |
2806 | ||
2807 | /* | |
2808 | * Temporary storage for the character representation of the | |
2809 | * CPU bitmask (and one more byte for the newline): | |
2810 | */ | |
2811 | static char mask_str[NR_CPUS + 1]; | |
2812 | ||
c7078de1 IM |
2813 | static ssize_t |
2814 | tracing_cpumask_read(struct file *filp, char __user *ubuf, | |
2815 | size_t count, loff_t *ppos) | |
2816 | { | |
36dfe925 | 2817 | int len; |
c7078de1 IM |
2818 | |
2819 | mutex_lock(&tracing_cpumask_update_lock); | |
36dfe925 | 2820 | |
9e01c1b7 | 2821 | len = cpumask_scnprintf(mask_str, count, tracing_cpumask); |
36dfe925 IM |
2822 | if (count - len < 2) { |
2823 | count = -EINVAL; | |
2824 | goto out_err; | |
2825 | } | |
2826 | len += sprintf(mask_str + len, "\n"); | |
2827 | count = simple_read_from_buffer(ubuf, count, ppos, mask_str, NR_CPUS+1); | |
2828 | ||
2829 | out_err: | |
c7078de1 IM |
2830 | mutex_unlock(&tracing_cpumask_update_lock); |
2831 | ||
2832 | return count; | |
2833 | } | |
2834 | ||
2835 | static ssize_t | |
2836 | tracing_cpumask_write(struct file *filp, const char __user *ubuf, | |
2837 | size_t count, loff_t *ppos) | |
2838 | { | |
2b6080f2 | 2839 | struct trace_array *tr = filp->private_data; |
9e01c1b7 | 2840 | cpumask_var_t tracing_cpumask_new; |
2b6080f2 | 2841 | int err, cpu; |
9e01c1b7 RR |
2842 | |
2843 | if (!alloc_cpumask_var(&tracing_cpumask_new, GFP_KERNEL)) | |
2844 | return -ENOMEM; | |
c7078de1 | 2845 | |
9e01c1b7 | 2846 | err = cpumask_parse_user(ubuf, count, tracing_cpumask_new); |
c7078de1 | 2847 | if (err) |
36dfe925 IM |
2848 | goto err_unlock; |
2849 | ||
215368e8 LZ |
2850 | mutex_lock(&tracing_cpumask_update_lock); |
2851 | ||
a5e25883 | 2852 | local_irq_disable(); |
0199c4e6 | 2853 | arch_spin_lock(&ftrace_max_lock); |
ab46428c | 2854 | for_each_tracing_cpu(cpu) { |
36dfe925 IM |
2855 | /* |
2856 | * Increase/decrease the disabled counter if we are | |
2857 | * about to flip a bit in the cpumask: | |
2858 | */ | |
9e01c1b7 RR |
2859 | if (cpumask_test_cpu(cpu, tracing_cpumask) && |
2860 | !cpumask_test_cpu(cpu, tracing_cpumask_new)) { | |
2b6080f2 SR |
2861 | atomic_inc(&tr->data[cpu]->disabled); |
2862 | ring_buffer_record_disable_cpu(tr->buffer, cpu); | |
36dfe925 | 2863 | } |
9e01c1b7 RR |
2864 | if (!cpumask_test_cpu(cpu, tracing_cpumask) && |
2865 | cpumask_test_cpu(cpu, tracing_cpumask_new)) { | |
2b6080f2 SR |
2866 | atomic_dec(&tr->data[cpu]->disabled); |
2867 | ring_buffer_record_enable_cpu(tr->buffer, cpu); | |
36dfe925 IM |
2868 | } |
2869 | } | |
0199c4e6 | 2870 | arch_spin_unlock(&ftrace_max_lock); |
a5e25883 | 2871 | local_irq_enable(); |
36dfe925 | 2872 | |
9e01c1b7 | 2873 | cpumask_copy(tracing_cpumask, tracing_cpumask_new); |
36dfe925 IM |
2874 | |
2875 | mutex_unlock(&tracing_cpumask_update_lock); | |
9e01c1b7 | 2876 | free_cpumask_var(tracing_cpumask_new); |
c7078de1 IM |
2877 | |
2878 | return count; | |
36dfe925 IM |
2879 | |
2880 | err_unlock: | |
215368e8 | 2881 | free_cpumask_var(tracing_cpumask_new); |
36dfe925 IM |
2882 | |
2883 | return err; | |
c7078de1 IM |
2884 | } |
2885 | ||
5e2336a0 | 2886 | static const struct file_operations tracing_cpumask_fops = { |
c7078de1 IM |
2887 | .open = tracing_open_generic, |
2888 | .read = tracing_cpumask_read, | |
2889 | .write = tracing_cpumask_write, | |
b444786f | 2890 | .llseek = generic_file_llseek, |
bc0c38d1 SR |
2891 | }; |
2892 | ||
fdb372ed | 2893 | static int tracing_trace_options_show(struct seq_file *m, void *v) |
bc0c38d1 | 2894 | { |
d8e83d26 | 2895 | struct tracer_opt *trace_opts; |
2b6080f2 | 2896 | struct trace_array *tr = m->private; |
d8e83d26 | 2897 | u32 tracer_flags; |
d8e83d26 | 2898 | int i; |
adf9f195 | 2899 | |
d8e83d26 | 2900 | mutex_lock(&trace_types_lock); |
2b6080f2 SR |
2901 | tracer_flags = tr->current_trace->flags->val; |
2902 | trace_opts = tr->current_trace->flags->opts; | |
d8e83d26 | 2903 | |
bc0c38d1 SR |
2904 | for (i = 0; trace_options[i]; i++) { |
2905 | if (trace_flags & (1 << i)) | |
fdb372ed | 2906 | seq_printf(m, "%s\n", trace_options[i]); |
bc0c38d1 | 2907 | else |
fdb372ed | 2908 | seq_printf(m, "no%s\n", trace_options[i]); |
bc0c38d1 SR |
2909 | } |
2910 | ||
adf9f195 FW |
2911 | for (i = 0; trace_opts[i].name; i++) { |
2912 | if (tracer_flags & trace_opts[i].bit) | |
fdb372ed | 2913 | seq_printf(m, "%s\n", trace_opts[i].name); |
adf9f195 | 2914 | else |
fdb372ed | 2915 | seq_printf(m, "no%s\n", trace_opts[i].name); |
adf9f195 | 2916 | } |
d8e83d26 | 2917 | mutex_unlock(&trace_types_lock); |
adf9f195 | 2918 | |
fdb372ed | 2919 | return 0; |
bc0c38d1 | 2920 | } |
bc0c38d1 | 2921 | |
8d18eaaf LZ |
2922 | static int __set_tracer_option(struct tracer *trace, |
2923 | struct tracer_flags *tracer_flags, | |
2924 | struct tracer_opt *opts, int neg) | |
2925 | { | |
2926 | int ret; | |
bc0c38d1 | 2927 | |
8d18eaaf LZ |
2928 | ret = trace->set_flag(tracer_flags->val, opts->bit, !neg); |
2929 | if (ret) | |
2930 | return ret; | |
2931 | ||
2932 | if (neg) | |
2933 | tracer_flags->val &= ~opts->bit; | |
2934 | else | |
2935 | tracer_flags->val |= opts->bit; | |
2936 | return 0; | |
bc0c38d1 SR |
2937 | } |
2938 | ||
adf9f195 FW |
2939 | /* Try to assign a tracer specific option */ |
2940 | static int set_tracer_option(struct tracer *trace, char *cmp, int neg) | |
2941 | { | |
7770841e | 2942 | struct tracer_flags *tracer_flags = trace->flags; |
adf9f195 | 2943 | struct tracer_opt *opts = NULL; |
8d18eaaf | 2944 | int i; |
adf9f195 | 2945 | |
7770841e Z |
2946 | for (i = 0; tracer_flags->opts[i].name; i++) { |
2947 | opts = &tracer_flags->opts[i]; | |
adf9f195 | 2948 | |
8d18eaaf LZ |
2949 | if (strcmp(cmp, opts->name) == 0) |
2950 | return __set_tracer_option(trace, trace->flags, | |
2951 | opts, neg); | |
adf9f195 | 2952 | } |
adf9f195 | 2953 | |
8d18eaaf | 2954 | return -EINVAL; |
adf9f195 FW |
2955 | } |
2956 | ||
613f04a0 SRRH |
2957 | /* Some tracers require overwrite to stay enabled */ |
2958 | int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set) | |
2959 | { | |
2960 | if (tracer->enabled && (mask & TRACE_ITER_OVERWRITE) && !set) | |
2961 | return -1; | |
2962 | ||
2963 | return 0; | |
2964 | } | |
2965 | ||
2b6080f2 | 2966 | int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled) |
af4617bd SR |
2967 | { |
2968 | /* do nothing if flag is already set */ | |
2969 | if (!!(trace_flags & mask) == !!enabled) | |
613f04a0 SRRH |
2970 | return 0; |
2971 | ||
2972 | /* Give the tracer a chance to approve the change */ | |
2b6080f2 SR |
2973 | if (tr->current_trace->flag_changed) |
2974 | if (tr->current_trace->flag_changed(tr->current_trace, mask, !!enabled)) | |
613f04a0 | 2975 | return -EINVAL; |
af4617bd SR |
2976 | |
2977 | if (enabled) | |
2978 | trace_flags |= mask; | |
2979 | else | |
2980 | trace_flags &= ~mask; | |
e870e9a1 LZ |
2981 | |
2982 | if (mask == TRACE_ITER_RECORD_CMD) | |
2983 | trace_event_enable_cmd_record(enabled); | |
750912fa | 2984 | |
80902822 | 2985 | if (mask == TRACE_ITER_OVERWRITE) { |
750912fa | 2986 | ring_buffer_change_overwrite(global_trace.buffer, enabled); |
80902822 SRRH |
2987 | #ifdef CONFIG_TRACER_MAX_TRACE |
2988 | ring_buffer_change_overwrite(max_tr.buffer, enabled); | |
2989 | #endif | |
2990 | } | |
81698831 SR |
2991 | |
2992 | if (mask == TRACE_ITER_PRINTK) | |
2993 | trace_printk_start_stop_comm(enabled); | |
613f04a0 SRRH |
2994 | |
2995 | return 0; | |
af4617bd SR |
2996 | } |
2997 | ||
2b6080f2 | 2998 | static int trace_set_options(struct trace_array *tr, char *option) |
bc0c38d1 | 2999 | { |
8d18eaaf | 3000 | char *cmp; |
bc0c38d1 | 3001 | int neg = 0; |
613f04a0 | 3002 | int ret = -ENODEV; |
bc0c38d1 SR |
3003 | int i; |
3004 | ||
7bcfaf54 | 3005 | cmp = strstrip(option); |
bc0c38d1 | 3006 | |
8d18eaaf | 3007 | if (strncmp(cmp, "no", 2) == 0) { |
bc0c38d1 SR |
3008 | neg = 1; |
3009 | cmp += 2; | |
3010 | } | |
3011 | ||
69d34da2 SRRH |
3012 | mutex_lock(&trace_types_lock); |
3013 | ||
bc0c38d1 | 3014 | for (i = 0; trace_options[i]; i++) { |
8d18eaaf | 3015 | if (strcmp(cmp, trace_options[i]) == 0) { |
2b6080f2 | 3016 | ret = set_tracer_flag(tr, 1 << i, !neg); |
bc0c38d1 SR |
3017 | break; |
3018 | } | |
3019 | } | |
adf9f195 FW |
3020 | |
3021 | /* If no option could be set, test the specific tracer options */ | |
69d34da2 | 3022 | if (!trace_options[i]) |
2b6080f2 | 3023 | ret = set_tracer_option(tr->current_trace, cmp, neg); |
69d34da2 SRRH |
3024 | |
3025 | mutex_unlock(&trace_types_lock); | |
bc0c38d1 | 3026 | |
7bcfaf54 SR |
3027 | return ret; |
3028 | } | |
3029 | ||
3030 | static ssize_t | |
3031 | tracing_trace_options_write(struct file *filp, const char __user *ubuf, | |
3032 | size_t cnt, loff_t *ppos) | |
3033 | { | |
2b6080f2 SR |
3034 | struct seq_file *m = filp->private_data; |
3035 | struct trace_array *tr = m->private; | |
7bcfaf54 | 3036 | char buf[64]; |
613f04a0 | 3037 | int ret; |
7bcfaf54 SR |
3038 | |
3039 | if (cnt >= sizeof(buf)) | |
3040 | return -EINVAL; | |
3041 | ||
3042 | if (copy_from_user(&buf, ubuf, cnt)) | |
3043 | return -EFAULT; | |
3044 | ||
a8dd2176 SR |
3045 | buf[cnt] = 0; |
3046 | ||
2b6080f2 | 3047 | ret = trace_set_options(tr, buf); |
613f04a0 SRRH |
3048 | if (ret < 0) |
3049 | return ret; | |
7bcfaf54 | 3050 | |
cf8517cf | 3051 | *ppos += cnt; |
bc0c38d1 SR |
3052 | |
3053 | return cnt; | |
3054 | } | |
3055 | ||
fdb372ed LZ |
3056 | static int tracing_trace_options_open(struct inode *inode, struct file *file) |
3057 | { | |
3058 | if (tracing_disabled) | |
3059 | return -ENODEV; | |
2b6080f2 SR |
3060 | |
3061 | return single_open(file, tracing_trace_options_show, inode->i_private); | |
fdb372ed LZ |
3062 | } |
3063 | ||
5e2336a0 | 3064 | static const struct file_operations tracing_iter_fops = { |
fdb372ed LZ |
3065 | .open = tracing_trace_options_open, |
3066 | .read = seq_read, | |
3067 | .llseek = seq_lseek, | |
3068 | .release = single_release, | |
ee6bce52 | 3069 | .write = tracing_trace_options_write, |
bc0c38d1 SR |
3070 | }; |
3071 | ||
7bd2f24c IM |
3072 | static const char readme_msg[] = |
3073 | "tracing mini-HOWTO:\n\n" | |
156f5a78 GL |
3074 | "# mount -t debugfs nodev /sys/kernel/debug\n\n" |
3075 | "# cat /sys/kernel/debug/tracing/available_tracers\n" | |
1e42e83f | 3076 | "wakeup wakeup_rt preemptirqsoff preemptoff irqsoff function nop\n\n" |
156f5a78 | 3077 | "# cat /sys/kernel/debug/tracing/current_tracer\n" |
bc2b6871 | 3078 | "nop\n" |
1e42e83f | 3079 | "# echo wakeup > /sys/kernel/debug/tracing/current_tracer\n" |
156f5a78 | 3080 | "# cat /sys/kernel/debug/tracing/current_tracer\n" |
1e42e83f | 3081 | "wakeup\n" |
156f5a78 | 3082 | "# cat /sys/kernel/debug/tracing/trace_options\n" |
7bd2f24c | 3083 | "noprint-parent nosym-offset nosym-addr noverbose\n" |
156f5a78 | 3084 | "# echo print-parent > /sys/kernel/debug/tracing/trace_options\n" |
9b5f8b31 | 3085 | "# echo 1 > /sys/kernel/debug/tracing/tracing_on\n" |
156f5a78 | 3086 | "# cat /sys/kernel/debug/tracing/trace > /tmp/trace.txt\n" |
9b5f8b31 | 3087 | "# echo 0 > /sys/kernel/debug/tracing/tracing_on\n" |
7bd2f24c IM |
3088 | ; |
3089 | ||
3090 | static ssize_t | |
3091 | tracing_readme_read(struct file *filp, char __user *ubuf, | |
3092 | size_t cnt, loff_t *ppos) | |
3093 | { | |
3094 | return simple_read_from_buffer(ubuf, cnt, ppos, | |
3095 | readme_msg, strlen(readme_msg)); | |
3096 | } | |
3097 | ||
5e2336a0 | 3098 | static const struct file_operations tracing_readme_fops = { |
c7078de1 IM |
3099 | .open = tracing_open_generic, |
3100 | .read = tracing_readme_read, | |
b444786f | 3101 | .llseek = generic_file_llseek, |
7bd2f24c IM |
3102 | }; |
3103 | ||
69abe6a5 AP |
3104 | static ssize_t |
3105 | tracing_saved_cmdlines_read(struct file *file, char __user *ubuf, | |
3106 | size_t cnt, loff_t *ppos) | |
3107 | { | |
3108 | char *buf_comm; | |
3109 | char *file_buf; | |
3110 | char *buf; | |
3111 | int len = 0; | |
3112 | int pid; | |
3113 | int i; | |
3114 | ||
3115 | file_buf = kmalloc(SAVED_CMDLINES*(16+TASK_COMM_LEN), GFP_KERNEL); | |
3116 | if (!file_buf) | |
3117 | return -ENOMEM; | |
3118 | ||
3119 | buf_comm = kmalloc(TASK_COMM_LEN, GFP_KERNEL); | |
3120 | if (!buf_comm) { | |
3121 | kfree(file_buf); | |
3122 | return -ENOMEM; | |
3123 | } | |
3124 | ||
3125 | buf = file_buf; | |
3126 | ||
3127 | for (i = 0; i < SAVED_CMDLINES; i++) { | |
3128 | int r; | |
3129 | ||
3130 | pid = map_cmdline_to_pid[i]; | |
3131 | if (pid == -1 || pid == NO_CMDLINE_MAP) | |
3132 | continue; | |
3133 | ||
3134 | trace_find_cmdline(pid, buf_comm); | |
3135 | r = sprintf(buf, "%d %s\n", pid, buf_comm); | |
3136 | buf += r; | |
3137 | len += r; | |
3138 | } | |
3139 | ||
3140 | len = simple_read_from_buffer(ubuf, cnt, ppos, | |
3141 | file_buf, len); | |
3142 | ||
3143 | kfree(file_buf); | |
3144 | kfree(buf_comm); | |
3145 | ||
3146 | return len; | |
3147 | } | |
3148 | ||
3149 | static const struct file_operations tracing_saved_cmdlines_fops = { | |
3150 | .open = tracing_open_generic, | |
3151 | .read = tracing_saved_cmdlines_read, | |
b444786f | 3152 | .llseek = generic_file_llseek, |
69abe6a5 AP |
3153 | }; |
3154 | ||
bc0c38d1 SR |
3155 | static ssize_t |
3156 | tracing_set_trace_read(struct file *filp, char __user *ubuf, | |
3157 | size_t cnt, loff_t *ppos) | |
3158 | { | |
2b6080f2 | 3159 | struct trace_array *tr = filp->private_data; |
ee6c2c1b | 3160 | char buf[MAX_TRACER_SIZE+2]; |
bc0c38d1 SR |
3161 | int r; |
3162 | ||
3163 | mutex_lock(&trace_types_lock); | |
2b6080f2 | 3164 | r = sprintf(buf, "%s\n", tr->current_trace->name); |
bc0c38d1 SR |
3165 | mutex_unlock(&trace_types_lock); |
3166 | ||
4bf39a94 | 3167 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, r); |
bc0c38d1 SR |
3168 | } |
3169 | ||
b6f11df2 ACM |
3170 | int tracer_init(struct tracer *t, struct trace_array *tr) |
3171 | { | |
3172 | tracing_reset_online_cpus(tr); | |
3173 | return t->init(tr); | |
3174 | } | |
3175 | ||
438ced17 VN |
3176 | static void set_buffer_entries(struct trace_array *tr, unsigned long val) |
3177 | { | |
3178 | int cpu; | |
3179 | for_each_tracing_cpu(cpu) | |
3180 | tr->data[cpu]->entries = val; | |
3181 | } | |
3182 | ||
d60da506 HT |
3183 | /* resize @tr's buffer to the size of @size_tr's entries */ |
3184 | static int resize_buffer_duplicate_size(struct trace_array *tr, | |
3185 | struct trace_array *size_tr, int cpu_id) | |
3186 | { | |
3187 | int cpu, ret = 0; | |
3188 | ||
3189 | if (cpu_id == RING_BUFFER_ALL_CPUS) { | |
3190 | for_each_tracing_cpu(cpu) { | |
3191 | ret = ring_buffer_resize(tr->buffer, | |
3192 | size_tr->data[cpu]->entries, cpu); | |
3193 | if (ret < 0) | |
3194 | break; | |
3195 | tr->data[cpu]->entries = size_tr->data[cpu]->entries; | |
3196 | } | |
3197 | } else { | |
3198 | ret = ring_buffer_resize(tr->buffer, | |
3199 | size_tr->data[cpu_id]->entries, cpu_id); | |
3200 | if (ret == 0) | |
3201 | tr->data[cpu_id]->entries = | |
3202 | size_tr->data[cpu_id]->entries; | |
3203 | } | |
3204 | ||
3205 | return ret; | |
3206 | } | |
3207 | ||
2b6080f2 SR |
3208 | static int __tracing_resize_ring_buffer(struct trace_array *tr, |
3209 | unsigned long size, int cpu) | |
73c5162a SR |
3210 | { |
3211 | int ret; | |
3212 | ||
3213 | /* | |
3214 | * If kernel or user changes the size of the ring buffer | |
a123c52b SR |
3215 | * we use the size that was given, and we can forget about |
3216 | * expanding it later. | |
73c5162a SR |
3217 | */ |
3218 | ring_buffer_expanded = 1; | |
3219 | ||
b382ede6 | 3220 | /* May be called before buffers are initialized */ |
2b6080f2 | 3221 | if (!tr->buffer) |
b382ede6 SR |
3222 | return 0; |
3223 | ||
2b6080f2 | 3224 | ret = ring_buffer_resize(tr->buffer, size, cpu); |
73c5162a SR |
3225 | if (ret < 0) |
3226 | return ret; | |
3227 | ||
2b6080f2 SR |
3228 | if (!(tr->flags & TRACE_ARRAY_FL_GLOBAL) || |
3229 | !tr->current_trace->use_max_tr) | |
ef710e10 KM |
3230 | goto out; |
3231 | ||
438ced17 | 3232 | ret = ring_buffer_resize(max_tr.buffer, size, cpu); |
73c5162a | 3233 | if (ret < 0) { |
2b6080f2 | 3234 | int r = resize_buffer_duplicate_size(tr, tr, cpu); |
73c5162a | 3235 | if (r < 0) { |
a123c52b SR |
3236 | /* |
3237 | * AARGH! We are left with different | |
3238 | * size max buffer!!!! | |
3239 | * The max buffer is our "snapshot" buffer. | |
3240 | * When a tracer needs a snapshot (one of the | |
3241 | * latency tracers), it swaps the max buffer | |
3242 | * with the saved snap shot. We succeeded to | |
3243 | * update the size of the main buffer, but failed to | |
3244 | * update the size of the max buffer. But when we tried | |
3245 | * to reset the main buffer to the original size, we | |
3246 | * failed there too. This is very unlikely to | |
3247 | * happen, but if it does, warn and kill all | |
3248 | * tracing. | |
3249 | */ | |
73c5162a SR |
3250 | WARN_ON(1); |
3251 | tracing_disabled = 1; | |
3252 | } | |
3253 | return ret; | |
3254 | } | |
3255 | ||
438ced17 VN |
3256 | if (cpu == RING_BUFFER_ALL_CPUS) |
3257 | set_buffer_entries(&max_tr, size); | |
3258 | else | |
3259 | max_tr.data[cpu]->entries = size; | |
3260 | ||
ef710e10 | 3261 | out: |
438ced17 | 3262 | if (cpu == RING_BUFFER_ALL_CPUS) |
2b6080f2 | 3263 | set_buffer_entries(tr, size); |
438ced17 | 3264 | else |
2b6080f2 | 3265 | tr->data[cpu]->entries = size; |
73c5162a SR |
3266 | |
3267 | return ret; | |
3268 | } | |
3269 | ||
2b6080f2 SR |
3270 | static ssize_t tracing_resize_ring_buffer(struct trace_array *tr, |
3271 | unsigned long size, int cpu_id) | |
4f271a2a | 3272 | { |
83f40318 | 3273 | int ret = size; |
4f271a2a VN |
3274 | |
3275 | mutex_lock(&trace_types_lock); | |
3276 | ||
438ced17 VN |
3277 | if (cpu_id != RING_BUFFER_ALL_CPUS) { |
3278 | /* make sure, this cpu is enabled in the mask */ | |
3279 | if (!cpumask_test_cpu(cpu_id, tracing_buffer_mask)) { | |
3280 | ret = -EINVAL; | |
3281 | goto out; | |
3282 | } | |
3283 | } | |
4f271a2a | 3284 | |
2b6080f2 | 3285 | ret = __tracing_resize_ring_buffer(tr, size, cpu_id); |
4f271a2a VN |
3286 | if (ret < 0) |
3287 | ret = -ENOMEM; | |
3288 | ||
438ced17 | 3289 | out: |
4f271a2a VN |
3290 | mutex_unlock(&trace_types_lock); |
3291 | ||
3292 | return ret; | |
3293 | } | |
3294 | ||
ef710e10 | 3295 | |
1852fcce SR |
3296 | /** |
3297 | * tracing_update_buffers - used by tracing facility to expand ring buffers | |
3298 | * | |
3299 | * To save on memory when the tracing is never used on a system with it | |
3300 | * configured in. The ring buffers are set to a minimum size. But once | |
3301 | * a user starts to use the tracing facility, then they need to grow | |
3302 | * to their default size. | |
3303 | * | |
3304 | * This function is to be called when a tracer is about to be used. | |
3305 | */ | |
3306 | int tracing_update_buffers(void) | |
3307 | { | |
3308 | int ret = 0; | |
3309 | ||
1027fcb2 | 3310 | mutex_lock(&trace_types_lock); |
1852fcce | 3311 | if (!ring_buffer_expanded) |
2b6080f2 | 3312 | ret = __tracing_resize_ring_buffer(&global_trace, trace_buf_size, |
438ced17 | 3313 | RING_BUFFER_ALL_CPUS); |
1027fcb2 | 3314 | mutex_unlock(&trace_types_lock); |
1852fcce SR |
3315 | |
3316 | return ret; | |
3317 | } | |
3318 | ||
577b785f SR |
3319 | struct trace_option_dentry; |
3320 | ||
3321 | static struct trace_option_dentry * | |
2b6080f2 | 3322 | create_trace_option_files(struct trace_array *tr, struct tracer *tracer); |
577b785f SR |
3323 | |
3324 | static void | |
3325 | destroy_trace_option_files(struct trace_option_dentry *topts); | |
3326 | ||
b2821ae6 | 3327 | static int tracing_set_tracer(const char *buf) |
bc0c38d1 | 3328 | { |
577b785f | 3329 | static struct trace_option_dentry *topts; |
bc0c38d1 SR |
3330 | struct trace_array *tr = &global_trace; |
3331 | struct tracer *t; | |
34600f0e | 3332 | bool had_max_tr; |
d9e54076 | 3333 | int ret = 0; |
bc0c38d1 | 3334 | |
1027fcb2 SR |
3335 | mutex_lock(&trace_types_lock); |
3336 | ||
73c5162a | 3337 | if (!ring_buffer_expanded) { |
2b6080f2 | 3338 | ret = __tracing_resize_ring_buffer(tr, trace_buf_size, |
438ced17 | 3339 | RING_BUFFER_ALL_CPUS); |
73c5162a | 3340 | if (ret < 0) |
59f586db | 3341 | goto out; |
73c5162a SR |
3342 | ret = 0; |
3343 | } | |
3344 | ||
bc0c38d1 SR |
3345 | for (t = trace_types; t; t = t->next) { |
3346 | if (strcmp(t->name, buf) == 0) | |
3347 | break; | |
3348 | } | |
c2931e05 FW |
3349 | if (!t) { |
3350 | ret = -EINVAL; | |
3351 | goto out; | |
3352 | } | |
2b6080f2 | 3353 | if (t == tr->current_trace) |
bc0c38d1 SR |
3354 | goto out; |
3355 | ||
9f029e83 | 3356 | trace_branch_disable(); |
613f04a0 | 3357 | |
2b6080f2 | 3358 | tr->current_trace->enabled = false; |
613f04a0 | 3359 | |
2b6080f2 SR |
3360 | if (tr->current_trace->reset) |
3361 | tr->current_trace->reset(tr); | |
34600f0e | 3362 | |
2b6080f2 SR |
3363 | had_max_tr = tr->current_trace->allocated_snapshot; |
3364 | tr->current_trace = &nop_trace; | |
34600f0e SR |
3365 | |
3366 | if (had_max_tr && !t->use_max_tr) { | |
3367 | /* | |
3368 | * We need to make sure that the update_max_tr sees that | |
3369 | * current_trace changed to nop_trace to keep it from | |
3370 | * swapping the buffers after we resize it. | |
3371 | * The update_max_tr is called from interrupts disabled | |
3372 | * so a synchronized_sched() is sufficient. | |
3373 | */ | |
3374 | synchronize_sched(); | |
ef710e10 KM |
3375 | /* |
3376 | * We don't free the ring buffer. instead, resize it because | |
3377 | * The max_tr ring buffer has some state (e.g. ring->clock) and | |
3378 | * we want preserve it. | |
3379 | */ | |
438ced17 VN |
3380 | ring_buffer_resize(max_tr.buffer, 1, RING_BUFFER_ALL_CPUS); |
3381 | set_buffer_entries(&max_tr, 1); | |
debdd57f | 3382 | tracing_reset_online_cpus(&max_tr); |
2b6080f2 | 3383 | tr->current_trace->allocated_snapshot = false; |
ef710e10 | 3384 | } |
577b785f SR |
3385 | destroy_trace_option_files(topts); |
3386 | ||
2b6080f2 | 3387 | topts = create_trace_option_files(tr, t); |
34600f0e | 3388 | if (t->use_max_tr && !had_max_tr) { |
438ced17 | 3389 | /* we need to make per cpu buffer sizes equivalent */ |
d60da506 HT |
3390 | ret = resize_buffer_duplicate_size(&max_tr, &global_trace, |
3391 | RING_BUFFER_ALL_CPUS); | |
3392 | if (ret < 0) | |
3393 | goto out; | |
debdd57f | 3394 | t->allocated_snapshot = true; |
ef710e10 | 3395 | } |
577b785f | 3396 | |
1c80025a | 3397 | if (t->init) { |
b6f11df2 | 3398 | ret = tracer_init(t, tr); |
1c80025a FW |
3399 | if (ret) |
3400 | goto out; | |
3401 | } | |
bc0c38d1 | 3402 | |
2b6080f2 SR |
3403 | tr->current_trace = t; |
3404 | tr->current_trace->enabled = true; | |
9f029e83 | 3405 | trace_branch_enable(tr); |
bc0c38d1 SR |
3406 | out: |
3407 | mutex_unlock(&trace_types_lock); | |
3408 | ||
d9e54076 PZ |
3409 | return ret; |
3410 | } | |
3411 | ||
3412 | static ssize_t | |
3413 | tracing_set_trace_write(struct file *filp, const char __user *ubuf, | |
3414 | size_t cnt, loff_t *ppos) | |
3415 | { | |
ee6c2c1b | 3416 | char buf[MAX_TRACER_SIZE+1]; |
d9e54076 PZ |
3417 | int i; |
3418 | size_t ret; | |
e6e7a65a FW |
3419 | int err; |
3420 | ||
3421 | ret = cnt; | |
d9e54076 | 3422 | |
ee6c2c1b LZ |
3423 | if (cnt > MAX_TRACER_SIZE) |
3424 | cnt = MAX_TRACER_SIZE; | |
d9e54076 PZ |
3425 | |
3426 | if (copy_from_user(&buf, ubuf, cnt)) | |
3427 | return -EFAULT; | |
3428 | ||
3429 | buf[cnt] = 0; | |
3430 | ||
3431 | /* strip ending whitespace. */ | |
3432 | for (i = cnt - 1; i > 0 && isspace(buf[i]); i--) | |
3433 | buf[i] = 0; | |
3434 | ||
e6e7a65a FW |
3435 | err = tracing_set_tracer(buf); |
3436 | if (err) | |
3437 | return err; | |
d9e54076 | 3438 | |
cf8517cf | 3439 | *ppos += ret; |
bc0c38d1 | 3440 | |
c2931e05 | 3441 | return ret; |
bc0c38d1 SR |
3442 | } |
3443 | ||
3444 | static ssize_t | |
3445 | tracing_max_lat_read(struct file *filp, char __user *ubuf, | |
3446 | size_t cnt, loff_t *ppos) | |
3447 | { | |
3448 | unsigned long *ptr = filp->private_data; | |
3449 | char buf[64]; | |
3450 | int r; | |
3451 | ||
cffae437 | 3452 | r = snprintf(buf, sizeof(buf), "%ld\n", |
bc0c38d1 | 3453 | *ptr == (unsigned long)-1 ? -1 : nsecs_to_usecs(*ptr)); |
cffae437 SR |
3454 | if (r > sizeof(buf)) |
3455 | r = sizeof(buf); | |
4bf39a94 | 3456 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, r); |
bc0c38d1 SR |
3457 | } |
3458 | ||
3459 | static ssize_t | |
3460 | tracing_max_lat_write(struct file *filp, const char __user *ubuf, | |
3461 | size_t cnt, loff_t *ppos) | |
3462 | { | |
5e39841c | 3463 | unsigned long *ptr = filp->private_data; |
5e39841c | 3464 | unsigned long val; |
c6caeeb1 | 3465 | int ret; |
bc0c38d1 | 3466 | |
22fe9b54 PH |
3467 | ret = kstrtoul_from_user(ubuf, cnt, 10, &val); |
3468 | if (ret) | |
c6caeeb1 | 3469 | return ret; |
bc0c38d1 SR |
3470 | |
3471 | *ptr = val * 1000; | |
3472 | ||
3473 | return cnt; | |
3474 | } | |
3475 | ||
b3806b43 SR |
3476 | static int tracing_open_pipe(struct inode *inode, struct file *filp) |
3477 | { | |
2b6080f2 SR |
3478 | struct trace_cpu *tc = inode->i_private; |
3479 | struct trace_array *tr = tc->tr; | |
b3806b43 | 3480 | struct trace_iterator *iter; |
b04cc6b1 | 3481 | int ret = 0; |
b3806b43 SR |
3482 | |
3483 | if (tracing_disabled) | |
3484 | return -ENODEV; | |
3485 | ||
b04cc6b1 FW |
3486 | mutex_lock(&trace_types_lock); |
3487 | ||
b3806b43 SR |
3488 | /* create a buffer to store the information to pass to userspace */ |
3489 | iter = kzalloc(sizeof(*iter), GFP_KERNEL); | |
b04cc6b1 FW |
3490 | if (!iter) { |
3491 | ret = -ENOMEM; | |
3492 | goto out; | |
3493 | } | |
b3806b43 | 3494 | |
d7350c3f FW |
3495 | /* |
3496 | * We make a copy of the current tracer to avoid concurrent | |
3497 | * changes on it while we are reading. | |
3498 | */ | |
3499 | iter->trace = kmalloc(sizeof(*iter->trace), GFP_KERNEL); | |
3500 | if (!iter->trace) { | |
3501 | ret = -ENOMEM; | |
3502 | goto fail; | |
3503 | } | |
2b6080f2 | 3504 | *iter->trace = *tr->current_trace; |
d7350c3f | 3505 | |
4462344e | 3506 | if (!alloc_cpumask_var(&iter->started, GFP_KERNEL)) { |
b04cc6b1 | 3507 | ret = -ENOMEM; |
d7350c3f | 3508 | goto fail; |
4462344e RR |
3509 | } |
3510 | ||
a309720c | 3511 | /* trace pipe does not show start of buffer */ |
4462344e | 3512 | cpumask_setall(iter->started); |
a309720c | 3513 | |
112f38a7 SR |
3514 | if (trace_flags & TRACE_ITER_LATENCY_FMT) |
3515 | iter->iter_flags |= TRACE_FILE_LAT_FMT; | |
3516 | ||
8be0709f DS |
3517 | /* Output in nanoseconds only if we are using a clock in nanoseconds. */ |
3518 | if (trace_clocks[trace_clock_id].in_ns) | |
3519 | iter->iter_flags |= TRACE_FILE_TIME_IN_NS; | |
3520 | ||
2b6080f2 SR |
3521 | iter->cpu_file = tc->cpu; |
3522 | iter->tr = tc->tr; | |
d7350c3f | 3523 | mutex_init(&iter->mutex); |
b3806b43 SR |
3524 | filp->private_data = iter; |
3525 | ||
107bad8b SR |
3526 | if (iter->trace->pipe_open) |
3527 | iter->trace->pipe_open(iter); | |
107bad8b | 3528 | |
b444786f | 3529 | nonseekable_open(inode, filp); |
b04cc6b1 FW |
3530 | out: |
3531 | mutex_unlock(&trace_types_lock); | |
3532 | return ret; | |
d7350c3f FW |
3533 | |
3534 | fail: | |
3535 | kfree(iter->trace); | |
3536 | kfree(iter); | |
3537 | mutex_unlock(&trace_types_lock); | |
3538 | return ret; | |
b3806b43 SR |
3539 | } |
3540 | ||
3541 | static int tracing_release_pipe(struct inode *inode, struct file *file) | |
3542 | { | |
3543 | struct trace_iterator *iter = file->private_data; | |
3544 | ||
b04cc6b1 FW |
3545 | mutex_lock(&trace_types_lock); |
3546 | ||
29bf4a5e | 3547 | if (iter->trace->pipe_close) |
c521efd1 SR |
3548 | iter->trace->pipe_close(iter); |
3549 | ||
b04cc6b1 FW |
3550 | mutex_unlock(&trace_types_lock); |
3551 | ||
4462344e | 3552 | free_cpumask_var(iter->started); |
d7350c3f FW |
3553 | mutex_destroy(&iter->mutex); |
3554 | kfree(iter->trace); | |
b3806b43 | 3555 | kfree(iter); |
b3806b43 SR |
3556 | |
3557 | return 0; | |
3558 | } | |
3559 | ||
2a2cc8f7 SSP |
3560 | static unsigned int |
3561 | tracing_poll_pipe(struct file *filp, poll_table *poll_table) | |
3562 | { | |
3563 | struct trace_iterator *iter = filp->private_data; | |
3564 | ||
3565 | if (trace_flags & TRACE_ITER_BLOCK) { | |
3566 | /* | |
3567 | * Always select as readable when in blocking mode | |
3568 | */ | |
3569 | return POLLIN | POLLRDNORM; | |
afc2abc0 | 3570 | } else { |
2a2cc8f7 SSP |
3571 | if (!trace_empty(iter)) |
3572 | return POLLIN | POLLRDNORM; | |
3573 | poll_wait(filp, &trace_wait, poll_table); | |
3574 | if (!trace_empty(iter)) | |
3575 | return POLLIN | POLLRDNORM; | |
3576 | ||
3577 | return 0; | |
3578 | } | |
3579 | } | |
3580 | ||
6eaaa5d5 FW |
3581 | /* |
3582 | * This is a make-shift waitqueue. | |
3583 | * A tracer might use this callback on some rare cases: | |
3584 | * | |
3585 | * 1) the current tracer might hold the runqueue lock when it wakes up | |
3586 | * a reader, hence a deadlock (sched, function, and function graph tracers) | |
3587 | * 2) the function tracers, trace all functions, we don't want | |
3588 | * the overhead of calling wake_up and friends | |
3589 | * (and tracing them too) | |
3590 | * | |
3591 | * Anyway, this is really very primitive wakeup. | |
3592 | */ | |
3593 | void poll_wait_pipe(struct trace_iterator *iter) | |
3594 | { | |
3595 | set_current_state(TASK_INTERRUPTIBLE); | |
3596 | /* sleep for 100 msecs, and try again. */ | |
3597 | schedule_timeout(HZ / 10); | |
3598 | } | |
3599 | ||
ff98781b EGM |
3600 | /* Must be called with trace_types_lock mutex held. */ |
3601 | static int tracing_wait_pipe(struct file *filp) | |
b3806b43 SR |
3602 | { |
3603 | struct trace_iterator *iter = filp->private_data; | |
b3806b43 | 3604 | |
b3806b43 | 3605 | while (trace_empty(iter)) { |
2dc8f095 | 3606 | |
107bad8b | 3607 | if ((filp->f_flags & O_NONBLOCK)) { |
ff98781b | 3608 | return -EAGAIN; |
107bad8b | 3609 | } |
2dc8f095 | 3610 | |
d7350c3f | 3611 | mutex_unlock(&iter->mutex); |
107bad8b | 3612 | |
6eaaa5d5 | 3613 | iter->trace->wait_pipe(iter); |
b3806b43 | 3614 | |
d7350c3f | 3615 | mutex_lock(&iter->mutex); |
107bad8b | 3616 | |
6eaaa5d5 | 3617 | if (signal_pending(current)) |
ff98781b | 3618 | return -EINTR; |
b3806b43 SR |
3619 | |
3620 | /* | |
250bfd3d | 3621 | * We block until we read something and tracing is disabled. |
b3806b43 SR |
3622 | * We still block if tracing is disabled, but we have never |
3623 | * read anything. This allows a user to cat this file, and | |
3624 | * then enable tracing. But after we have read something, | |
3625 | * we give an EOF when tracing is again disabled. | |
3626 | * | |
3627 | * iter->pos will be 0 if we haven't read anything. | |
3628 | */ | |
250bfd3d | 3629 | if (!tracing_is_enabled() && iter->pos) |
b3806b43 | 3630 | break; |
b3806b43 SR |
3631 | } |
3632 | ||
ff98781b EGM |
3633 | return 1; |
3634 | } | |
3635 | ||
3636 | /* | |
3637 | * Consumer reader. | |
3638 | */ | |
3639 | static ssize_t | |
3640 | tracing_read_pipe(struct file *filp, char __user *ubuf, | |
3641 | size_t cnt, loff_t *ppos) | |
3642 | { | |
3643 | struct trace_iterator *iter = filp->private_data; | |
2b6080f2 | 3644 | struct trace_array *tr = iter->tr; |
ff98781b EGM |
3645 | ssize_t sret; |
3646 | ||
3647 | /* return any leftover data */ | |
3648 | sret = trace_seq_to_user(&iter->seq, ubuf, cnt); | |
3649 | if (sret != -EBUSY) | |
3650 | return sret; | |
3651 | ||
f9520750 | 3652 | trace_seq_init(&iter->seq); |
ff98781b | 3653 | |
d7350c3f | 3654 | /* copy the tracer to avoid using a global lock all around */ |
ff98781b | 3655 | mutex_lock(&trace_types_lock); |
2b6080f2 SR |
3656 | if (unlikely(iter->trace->name != tr->current_trace->name)) |
3657 | *iter->trace = *tr->current_trace; | |
d7350c3f FW |
3658 | mutex_unlock(&trace_types_lock); |
3659 | ||
3660 | /* | |
3661 | * Avoid more than one consumer on a single file descriptor | |
3662 | * This is just a matter of traces coherency, the ring buffer itself | |
3663 | * is protected. | |
3664 | */ | |
3665 | mutex_lock(&iter->mutex); | |
ff98781b EGM |
3666 | if (iter->trace->read) { |
3667 | sret = iter->trace->read(iter, filp, ubuf, cnt, ppos); | |
3668 | if (sret) | |
3669 | goto out; | |
3670 | } | |
3671 | ||
3672 | waitagain: | |
3673 | sret = tracing_wait_pipe(filp); | |
3674 | if (sret <= 0) | |
3675 | goto out; | |
3676 | ||
b3806b43 | 3677 | /* stop when tracing is finished */ |
ff98781b EGM |
3678 | if (trace_empty(iter)) { |
3679 | sret = 0; | |
107bad8b | 3680 | goto out; |
ff98781b | 3681 | } |
b3806b43 SR |
3682 | |
3683 | if (cnt >= PAGE_SIZE) | |
3684 | cnt = PAGE_SIZE - 1; | |
3685 | ||
53d0aa77 | 3686 | /* reset all but tr, trace, and overruns */ |
53d0aa77 SR |
3687 | memset(&iter->seq, 0, |
3688 | sizeof(struct trace_iterator) - | |
3689 | offsetof(struct trace_iterator, seq)); | |
4823ed7e | 3690 | iter->pos = -1; |
b3806b43 | 3691 | |
4f535968 | 3692 | trace_event_read_lock(); |
7e53bd42 | 3693 | trace_access_lock(iter->cpu_file); |
955b61e5 | 3694 | while (trace_find_next_entry_inc(iter) != NULL) { |
2c4f035f | 3695 | enum print_line_t ret; |
088b1e42 SR |
3696 | int len = iter->seq.len; |
3697 | ||
f9896bf3 | 3698 | ret = print_trace_line(iter); |
2c4f035f | 3699 | if (ret == TRACE_TYPE_PARTIAL_LINE) { |
088b1e42 SR |
3700 | /* don't print partial lines */ |
3701 | iter->seq.len = len; | |
b3806b43 | 3702 | break; |
088b1e42 | 3703 | } |
b91facc3 FW |
3704 | if (ret != TRACE_TYPE_NO_CONSUME) |
3705 | trace_consume(iter); | |
b3806b43 SR |
3706 | |
3707 | if (iter->seq.len >= cnt) | |
3708 | break; | |
ee5e51f5 JO |
3709 | |
3710 | /* | |
3711 | * Setting the full flag means we reached the trace_seq buffer | |
3712 | * size and we should leave by partial output condition above. | |
3713 | * One of the trace_seq_* functions is not used properly. | |
3714 | */ | |
3715 | WARN_ONCE(iter->seq.full, "full flag set for trace type %d", | |
3716 | iter->ent->type); | |
b3806b43 | 3717 | } |
7e53bd42 | 3718 | trace_access_unlock(iter->cpu_file); |
4f535968 | 3719 | trace_event_read_unlock(); |
b3806b43 | 3720 | |
b3806b43 | 3721 | /* Now copy what we have to the user */ |
6c6c2796 PP |
3722 | sret = trace_seq_to_user(&iter->seq, ubuf, cnt); |
3723 | if (iter->seq.readpos >= iter->seq.len) | |
f9520750 | 3724 | trace_seq_init(&iter->seq); |
9ff4b974 PP |
3725 | |
3726 | /* | |
25985edc | 3727 | * If there was nothing to send to user, in spite of consuming trace |
9ff4b974 PP |
3728 | * entries, go back to wait for more entries. |
3729 | */ | |
6c6c2796 | 3730 | if (sret == -EBUSY) |
9ff4b974 | 3731 | goto waitagain; |
b3806b43 | 3732 | |
107bad8b | 3733 | out: |
d7350c3f | 3734 | mutex_unlock(&iter->mutex); |
107bad8b | 3735 | |
6c6c2796 | 3736 | return sret; |
b3806b43 SR |
3737 | } |
3738 | ||
3c56819b EGM |
3739 | static void tracing_pipe_buf_release(struct pipe_inode_info *pipe, |
3740 | struct pipe_buffer *buf) | |
3741 | { | |
3742 | __free_page(buf->page); | |
3743 | } | |
3744 | ||
3745 | static void tracing_spd_release_pipe(struct splice_pipe_desc *spd, | |
3746 | unsigned int idx) | |
3747 | { | |
3748 | __free_page(spd->pages[idx]); | |
3749 | } | |
3750 | ||
28dfef8f | 3751 | static const struct pipe_buf_operations tracing_pipe_buf_ops = { |
34cd4998 SR |
3752 | .can_merge = 0, |
3753 | .map = generic_pipe_buf_map, | |
3754 | .unmap = generic_pipe_buf_unmap, | |
3755 | .confirm = generic_pipe_buf_confirm, | |
3756 | .release = tracing_pipe_buf_release, | |
3757 | .steal = generic_pipe_buf_steal, | |
3758 | .get = generic_pipe_buf_get, | |
3c56819b EGM |
3759 | }; |
3760 | ||
34cd4998 | 3761 | static size_t |
fa7c7f6e | 3762 | tracing_fill_pipe_page(size_t rem, struct trace_iterator *iter) |
34cd4998 SR |
3763 | { |
3764 | size_t count; | |
3765 | int ret; | |
3766 | ||
3767 | /* Seq buffer is page-sized, exactly what we need. */ | |
3768 | for (;;) { | |
3769 | count = iter->seq.len; | |
3770 | ret = print_trace_line(iter); | |
3771 | count = iter->seq.len - count; | |
3772 | if (rem < count) { | |
3773 | rem = 0; | |
3774 | iter->seq.len -= count; | |
3775 | break; | |
3776 | } | |
3777 | if (ret == TRACE_TYPE_PARTIAL_LINE) { | |
3778 | iter->seq.len -= count; | |
3779 | break; | |
3780 | } | |
3781 | ||
74e7ff8c LJ |
3782 | if (ret != TRACE_TYPE_NO_CONSUME) |
3783 | trace_consume(iter); | |
34cd4998 | 3784 | rem -= count; |
955b61e5 | 3785 | if (!trace_find_next_entry_inc(iter)) { |
34cd4998 SR |
3786 | rem = 0; |
3787 | iter->ent = NULL; | |
3788 | break; | |
3789 | } | |
3790 | } | |
3791 | ||
3792 | return rem; | |
3793 | } | |
3794 | ||
3c56819b EGM |
3795 | static ssize_t tracing_splice_read_pipe(struct file *filp, |
3796 | loff_t *ppos, | |
3797 | struct pipe_inode_info *pipe, | |
3798 | size_t len, | |
3799 | unsigned int flags) | |
3800 | { | |
35f3d14d JA |
3801 | struct page *pages_def[PIPE_DEF_BUFFERS]; |
3802 | struct partial_page partial_def[PIPE_DEF_BUFFERS]; | |
3c56819b EGM |
3803 | struct trace_iterator *iter = filp->private_data; |
3804 | struct splice_pipe_desc spd = { | |
35f3d14d JA |
3805 | .pages = pages_def, |
3806 | .partial = partial_def, | |
34cd4998 | 3807 | .nr_pages = 0, /* This gets updated below. */ |
047fe360 | 3808 | .nr_pages_max = PIPE_DEF_BUFFERS, |
34cd4998 SR |
3809 | .flags = flags, |
3810 | .ops = &tracing_pipe_buf_ops, | |
3811 | .spd_release = tracing_spd_release_pipe, | |
3c56819b | 3812 | }; |
2b6080f2 | 3813 | struct trace_array *tr = iter->tr; |
3c56819b | 3814 | ssize_t ret; |
34cd4998 | 3815 | size_t rem; |
3c56819b EGM |
3816 | unsigned int i; |
3817 | ||
35f3d14d JA |
3818 | if (splice_grow_spd(pipe, &spd)) |
3819 | return -ENOMEM; | |
3820 | ||
d7350c3f | 3821 | /* copy the tracer to avoid using a global lock all around */ |
3c56819b | 3822 | mutex_lock(&trace_types_lock); |
2b6080f2 SR |
3823 | if (unlikely(iter->trace->name != tr->current_trace->name)) |
3824 | *iter->trace = *tr->current_trace; | |
d7350c3f FW |
3825 | mutex_unlock(&trace_types_lock); |
3826 | ||
3827 | mutex_lock(&iter->mutex); | |
3c56819b EGM |
3828 | |
3829 | if (iter->trace->splice_read) { | |
3830 | ret = iter->trace->splice_read(iter, filp, | |
3831 | ppos, pipe, len, flags); | |
3832 | if (ret) | |
34cd4998 | 3833 | goto out_err; |
3c56819b EGM |
3834 | } |
3835 | ||
3836 | ret = tracing_wait_pipe(filp); | |
3837 | if (ret <= 0) | |
34cd4998 | 3838 | goto out_err; |
3c56819b | 3839 | |
955b61e5 | 3840 | if (!iter->ent && !trace_find_next_entry_inc(iter)) { |
3c56819b | 3841 | ret = -EFAULT; |
34cd4998 | 3842 | goto out_err; |
3c56819b EGM |
3843 | } |
3844 | ||
4f535968 | 3845 | trace_event_read_lock(); |
7e53bd42 | 3846 | trace_access_lock(iter->cpu_file); |
4f535968 | 3847 | |
3c56819b | 3848 | /* Fill as many pages as possible. */ |
35f3d14d JA |
3849 | for (i = 0, rem = len; i < pipe->buffers && rem; i++) { |
3850 | spd.pages[i] = alloc_page(GFP_KERNEL); | |
3851 | if (!spd.pages[i]) | |
34cd4998 | 3852 | break; |
3c56819b | 3853 | |
fa7c7f6e | 3854 | rem = tracing_fill_pipe_page(rem, iter); |
3c56819b EGM |
3855 | |
3856 | /* Copy the data into the page, so we can start over. */ | |
3857 | ret = trace_seq_to_buffer(&iter->seq, | |
35f3d14d | 3858 | page_address(spd.pages[i]), |
3c56819b EGM |
3859 | iter->seq.len); |
3860 | if (ret < 0) { | |
35f3d14d | 3861 | __free_page(spd.pages[i]); |
3c56819b EGM |
3862 | break; |
3863 | } | |
35f3d14d JA |
3864 | spd.partial[i].offset = 0; |
3865 | spd.partial[i].len = iter->seq.len; | |
3c56819b | 3866 | |
f9520750 | 3867 | trace_seq_init(&iter->seq); |
3c56819b EGM |
3868 | } |
3869 | ||
7e53bd42 | 3870 | trace_access_unlock(iter->cpu_file); |
4f535968 | 3871 | trace_event_read_unlock(); |
d7350c3f | 3872 | mutex_unlock(&iter->mutex); |
3c56819b EGM |
3873 | |
3874 | spd.nr_pages = i; | |
3875 | ||
35f3d14d JA |
3876 | ret = splice_to_pipe(pipe, &spd); |
3877 | out: | |
047fe360 | 3878 | splice_shrink_spd(&spd); |
35f3d14d | 3879 | return ret; |
3c56819b | 3880 | |
34cd4998 | 3881 | out_err: |
d7350c3f | 3882 | mutex_unlock(&iter->mutex); |
35f3d14d | 3883 | goto out; |
3c56819b EGM |
3884 | } |
3885 | ||
a98a3c3f SR |
3886 | static ssize_t |
3887 | tracing_entries_read(struct file *filp, char __user *ubuf, | |
3888 | size_t cnt, loff_t *ppos) | |
3889 | { | |
2b6080f2 SR |
3890 | struct trace_cpu *tc = filp->private_data; |
3891 | struct trace_array *tr = tc->tr; | |
438ced17 VN |
3892 | char buf[64]; |
3893 | int r = 0; | |
3894 | ssize_t ret; | |
a98a3c3f | 3895 | |
db526ca3 | 3896 | mutex_lock(&trace_types_lock); |
438ced17 | 3897 | |
2b6080f2 | 3898 | if (tc->cpu == RING_BUFFER_ALL_CPUS) { |
438ced17 VN |
3899 | int cpu, buf_size_same; |
3900 | unsigned long size; | |
3901 | ||
3902 | size = 0; | |
3903 | buf_size_same = 1; | |
3904 | /* check if all cpu sizes are same */ | |
3905 | for_each_tracing_cpu(cpu) { | |
3906 | /* fill in the size from first enabled cpu */ | |
3907 | if (size == 0) | |
3908 | size = tr->data[cpu]->entries; | |
3909 | if (size != tr->data[cpu]->entries) { | |
3910 | buf_size_same = 0; | |
3911 | break; | |
3912 | } | |
3913 | } | |
3914 | ||
3915 | if (buf_size_same) { | |
3916 | if (!ring_buffer_expanded) | |
3917 | r = sprintf(buf, "%lu (expanded: %lu)\n", | |
3918 | size >> 10, | |
3919 | trace_buf_size >> 10); | |
3920 | else | |
3921 | r = sprintf(buf, "%lu\n", size >> 10); | |
3922 | } else | |
3923 | r = sprintf(buf, "X\n"); | |
3924 | } else | |
2b6080f2 | 3925 | r = sprintf(buf, "%lu\n", tr->data[tc->cpu]->entries >> 10); |
438ced17 | 3926 | |
db526ca3 SR |
3927 | mutex_unlock(&trace_types_lock); |
3928 | ||
438ced17 VN |
3929 | ret = simple_read_from_buffer(ubuf, cnt, ppos, buf, r); |
3930 | return ret; | |
a98a3c3f SR |
3931 | } |
3932 | ||
3933 | static ssize_t | |
3934 | tracing_entries_write(struct file *filp, const char __user *ubuf, | |
3935 | size_t cnt, loff_t *ppos) | |
3936 | { | |
2b6080f2 | 3937 | struct trace_cpu *tc = filp->private_data; |
a98a3c3f | 3938 | unsigned long val; |
4f271a2a | 3939 | int ret; |
a98a3c3f | 3940 | |
22fe9b54 PH |
3941 | ret = kstrtoul_from_user(ubuf, cnt, 10, &val); |
3942 | if (ret) | |
c6caeeb1 | 3943 | return ret; |
a98a3c3f SR |
3944 | |
3945 | /* must have at least 1 entry */ | |
3946 | if (!val) | |
3947 | return -EINVAL; | |
3948 | ||
1696b2b0 SR |
3949 | /* value is in KB */ |
3950 | val <<= 10; | |
3951 | ||
2b6080f2 | 3952 | ret = tracing_resize_ring_buffer(tc->tr, val, tc->cpu); |
4f271a2a VN |
3953 | if (ret < 0) |
3954 | return ret; | |
a98a3c3f | 3955 | |
cf8517cf | 3956 | *ppos += cnt; |
a98a3c3f | 3957 | |
4f271a2a VN |
3958 | return cnt; |
3959 | } | |
bf5e6519 | 3960 | |
f81ab074 VN |
3961 | static ssize_t |
3962 | tracing_total_entries_read(struct file *filp, char __user *ubuf, | |
3963 | size_t cnt, loff_t *ppos) | |
3964 | { | |
3965 | struct trace_array *tr = filp->private_data; | |
3966 | char buf[64]; | |
3967 | int r, cpu; | |
3968 | unsigned long size = 0, expanded_size = 0; | |
3969 | ||
3970 | mutex_lock(&trace_types_lock); | |
3971 | for_each_tracing_cpu(cpu) { | |
438ced17 | 3972 | size += tr->data[cpu]->entries >> 10; |
f81ab074 VN |
3973 | if (!ring_buffer_expanded) |
3974 | expanded_size += trace_buf_size >> 10; | |
3975 | } | |
3976 | if (ring_buffer_expanded) | |
3977 | r = sprintf(buf, "%lu\n", size); | |
3978 | else | |
3979 | r = sprintf(buf, "%lu (expanded: %lu)\n", size, expanded_size); | |
3980 | mutex_unlock(&trace_types_lock); | |
3981 | ||
3982 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, r); | |
3983 | } | |
3984 | ||
4f271a2a VN |
3985 | static ssize_t |
3986 | tracing_free_buffer_write(struct file *filp, const char __user *ubuf, | |
3987 | size_t cnt, loff_t *ppos) | |
3988 | { | |
3989 | /* | |
3990 | * There is no need to read what the user has written, this function | |
3991 | * is just to make sure that there is no error when "echo" is used | |
3992 | */ | |
3993 | ||
3994 | *ppos += cnt; | |
a98a3c3f SR |
3995 | |
3996 | return cnt; | |
3997 | } | |
3998 | ||
4f271a2a VN |
3999 | static int |
4000 | tracing_free_buffer_release(struct inode *inode, struct file *filp) | |
4001 | { | |
2b6080f2 SR |
4002 | struct trace_array *tr = inode->i_private; |
4003 | ||
cf30cf67 SR |
4004 | /* disable tracing ? */ |
4005 | if (trace_flags & TRACE_ITER_STOP_ON_FREE) | |
4006 | tracing_off(); | |
4f271a2a | 4007 | /* resize the ring buffer to 0 */ |
2b6080f2 | 4008 | tracing_resize_ring_buffer(tr, 0, RING_BUFFER_ALL_CPUS); |
4f271a2a VN |
4009 | |
4010 | return 0; | |
4011 | } | |
4012 | ||
5bf9a1ee PP |
4013 | static ssize_t |
4014 | tracing_mark_write(struct file *filp, const char __user *ubuf, | |
4015 | size_t cnt, loff_t *fpos) | |
4016 | { | |
d696b58c SR |
4017 | unsigned long addr = (unsigned long)ubuf; |
4018 | struct ring_buffer_event *event; | |
4019 | struct ring_buffer *buffer; | |
4020 | struct print_entry *entry; | |
4021 | unsigned long irq_flags; | |
4022 | struct page *pages[2]; | |
6edb2a8a | 4023 | void *map_page[2]; |
d696b58c SR |
4024 | int nr_pages = 1; |
4025 | ssize_t written; | |
d696b58c SR |
4026 | int offset; |
4027 | int size; | |
4028 | int len; | |
4029 | int ret; | |
6edb2a8a | 4030 | int i; |
5bf9a1ee | 4031 | |
c76f0694 | 4032 | if (tracing_disabled) |
5bf9a1ee PP |
4033 | return -EINVAL; |
4034 | ||
5224c3a3 MSB |
4035 | if (!(trace_flags & TRACE_ITER_MARKERS)) |
4036 | return -EINVAL; | |
4037 | ||
5bf9a1ee PP |
4038 | if (cnt > TRACE_BUF_SIZE) |
4039 | cnt = TRACE_BUF_SIZE; | |
4040 | ||
d696b58c SR |
4041 | /* |
4042 | * Userspace is injecting traces into the kernel trace buffer. | |
4043 | * We want to be as non intrusive as possible. | |
4044 | * To do so, we do not want to allocate any special buffers | |
4045 | * or take any locks, but instead write the userspace data | |
4046 | * straight into the ring buffer. | |
4047 | * | |
4048 | * First we need to pin the userspace buffer into memory, | |
4049 | * which, most likely it is, because it just referenced it. | |
4050 | * But there's no guarantee that it is. By using get_user_pages_fast() | |
4051 | * and kmap_atomic/kunmap_atomic() we can get access to the | |
4052 | * pages directly. We then write the data directly into the | |
4053 | * ring buffer. | |
4054 | */ | |
4055 | BUILD_BUG_ON(TRACE_BUF_SIZE >= PAGE_SIZE); | |
5bf9a1ee | 4056 | |
d696b58c SR |
4057 | /* check if we cross pages */ |
4058 | if ((addr & PAGE_MASK) != ((addr + cnt) & PAGE_MASK)) | |
4059 | nr_pages = 2; | |
4060 | ||
4061 | offset = addr & (PAGE_SIZE - 1); | |
4062 | addr &= PAGE_MASK; | |
4063 | ||
4064 | ret = get_user_pages_fast(addr, nr_pages, 0, pages); | |
4065 | if (ret < nr_pages) { | |
4066 | while (--ret >= 0) | |
4067 | put_page(pages[ret]); | |
4068 | written = -EFAULT; | |
4069 | goto out; | |
5bf9a1ee | 4070 | } |
d696b58c | 4071 | |
6edb2a8a SR |
4072 | for (i = 0; i < nr_pages; i++) |
4073 | map_page[i] = kmap_atomic(pages[i]); | |
d696b58c SR |
4074 | |
4075 | local_save_flags(irq_flags); | |
4076 | size = sizeof(*entry) + cnt + 2; /* possible \n added */ | |
4077 | buffer = global_trace.buffer; | |
4078 | event = trace_buffer_lock_reserve(buffer, TRACE_PRINT, size, | |
4079 | irq_flags, preempt_count()); | |
4080 | if (!event) { | |
4081 | /* Ring buffer disabled, return as if not open for write */ | |
4082 | written = -EBADF; | |
4083 | goto out_unlock; | |
5bf9a1ee | 4084 | } |
d696b58c SR |
4085 | |
4086 | entry = ring_buffer_event_data(event); | |
4087 | entry->ip = _THIS_IP_; | |
4088 | ||
4089 | if (nr_pages == 2) { | |
4090 | len = PAGE_SIZE - offset; | |
6edb2a8a SR |
4091 | memcpy(&entry->buf, map_page[0] + offset, len); |
4092 | memcpy(&entry->buf[len], map_page[1], cnt - len); | |
c13d2f7c | 4093 | } else |
6edb2a8a | 4094 | memcpy(&entry->buf, map_page[0] + offset, cnt); |
5bf9a1ee | 4095 | |
d696b58c SR |
4096 | if (entry->buf[cnt - 1] != '\n') { |
4097 | entry->buf[cnt] = '\n'; | |
4098 | entry->buf[cnt + 1] = '\0'; | |
4099 | } else | |
4100 | entry->buf[cnt] = '\0'; | |
4101 | ||
7ffbd48d | 4102 | __buffer_unlock_commit(buffer, event); |
5bf9a1ee | 4103 | |
d696b58c | 4104 | written = cnt; |
5bf9a1ee | 4105 | |
d696b58c | 4106 | *fpos += written; |
1aa54bca | 4107 | |
d696b58c | 4108 | out_unlock: |
6edb2a8a SR |
4109 | for (i = 0; i < nr_pages; i++){ |
4110 | kunmap_atomic(map_page[i]); | |
4111 | put_page(pages[i]); | |
4112 | } | |
d696b58c | 4113 | out: |
1aa54bca | 4114 | return written; |
5bf9a1ee PP |
4115 | } |
4116 | ||
13f16d20 | 4117 | static int tracing_clock_show(struct seq_file *m, void *v) |
5079f326 | 4118 | { |
2b6080f2 | 4119 | struct trace_array *tr = m->private; |
5079f326 Z |
4120 | int i; |
4121 | ||
4122 | for (i = 0; i < ARRAY_SIZE(trace_clocks); i++) | |
13f16d20 | 4123 | seq_printf(m, |
5079f326 | 4124 | "%s%s%s%s", i ? " " : "", |
2b6080f2 SR |
4125 | i == tr->clock_id ? "[" : "", trace_clocks[i].name, |
4126 | i == tr->clock_id ? "]" : ""); | |
13f16d20 | 4127 | seq_putc(m, '\n'); |
5079f326 | 4128 | |
13f16d20 | 4129 | return 0; |
5079f326 Z |
4130 | } |
4131 | ||
4132 | static ssize_t tracing_clock_write(struct file *filp, const char __user *ubuf, | |
4133 | size_t cnt, loff_t *fpos) | |
4134 | { | |
2b6080f2 SR |
4135 | struct seq_file *m = filp->private_data; |
4136 | struct trace_array *tr = m->private; | |
5079f326 Z |
4137 | char buf[64]; |
4138 | const char *clockstr; | |
4139 | int i; | |
4140 | ||
4141 | if (cnt >= sizeof(buf)) | |
4142 | return -EINVAL; | |
4143 | ||
4144 | if (copy_from_user(&buf, ubuf, cnt)) | |
4145 | return -EFAULT; | |
4146 | ||
4147 | buf[cnt] = 0; | |
4148 | ||
4149 | clockstr = strstrip(buf); | |
4150 | ||
4151 | for (i = 0; i < ARRAY_SIZE(trace_clocks); i++) { | |
4152 | if (strcmp(trace_clocks[i].name, clockstr) == 0) | |
4153 | break; | |
4154 | } | |
4155 | if (i == ARRAY_SIZE(trace_clocks)) | |
4156 | return -EINVAL; | |
4157 | ||
5079f326 Z |
4158 | mutex_lock(&trace_types_lock); |
4159 | ||
2b6080f2 SR |
4160 | tr->clock_id = i; |
4161 | ||
4162 | ring_buffer_set_clock(tr->buffer, trace_clocks[i].func); | |
4163 | if (tr->flags & TRACE_ARRAY_FL_GLOBAL && max_tr.buffer) | |
5079f326 Z |
4164 | ring_buffer_set_clock(max_tr.buffer, trace_clocks[i].func); |
4165 | ||
60303ed3 DS |
4166 | /* |
4167 | * New clock may not be consistent with the previous clock. | |
4168 | * Reset the buffer so that it doesn't have incomparable timestamps. | |
4169 | */ | |
4170 | tracing_reset_online_cpus(&global_trace); | |
84c6cf0d | 4171 | tracing_reset_online_cpus(&max_tr); |
60303ed3 | 4172 | |
5079f326 Z |
4173 | mutex_unlock(&trace_types_lock); |
4174 | ||
4175 | *fpos += cnt; | |
4176 | ||
4177 | return cnt; | |
4178 | } | |
4179 | ||
13f16d20 LZ |
4180 | static int tracing_clock_open(struct inode *inode, struct file *file) |
4181 | { | |
4182 | if (tracing_disabled) | |
4183 | return -ENODEV; | |
2b6080f2 SR |
4184 | |
4185 | return single_open(file, tracing_clock_show, inode->i_private); | |
13f16d20 LZ |
4186 | } |
4187 | ||
debdd57f HT |
4188 | #ifdef CONFIG_TRACER_SNAPSHOT |
4189 | static int tracing_snapshot_open(struct inode *inode, struct file *file) | |
4190 | { | |
2b6080f2 | 4191 | struct trace_cpu *tc = inode->i_private; |
debdd57f | 4192 | struct trace_iterator *iter; |
2b6080f2 | 4193 | struct seq_file *m; |
debdd57f HT |
4194 | int ret = 0; |
4195 | ||
4196 | if (file->f_mode & FMODE_READ) { | |
4197 | iter = __tracing_open(inode, file, true); | |
4198 | if (IS_ERR(iter)) | |
4199 | ret = PTR_ERR(iter); | |
2b6080f2 SR |
4200 | } else { |
4201 | /* Writes still need the seq_file to hold the private data */ | |
4202 | m = kzalloc(sizeof(*m), GFP_KERNEL); | |
4203 | if (!m) | |
4204 | return -ENOMEM; | |
4205 | iter = kzalloc(sizeof(*iter), GFP_KERNEL); | |
4206 | if (!iter) { | |
4207 | kfree(m); | |
4208 | return -ENOMEM; | |
4209 | } | |
4210 | iter->tr = tc->tr; | |
4211 | m->private = iter; | |
4212 | file->private_data = m; | |
debdd57f | 4213 | } |
2b6080f2 | 4214 | |
debdd57f HT |
4215 | return ret; |
4216 | } | |
4217 | ||
4218 | static ssize_t | |
4219 | tracing_snapshot_write(struct file *filp, const char __user *ubuf, size_t cnt, | |
4220 | loff_t *ppos) | |
4221 | { | |
2b6080f2 SR |
4222 | struct seq_file *m = filp->private_data; |
4223 | struct trace_iterator *iter = m->private; | |
4224 | struct trace_array *tr = iter->tr; | |
debdd57f HT |
4225 | unsigned long val; |
4226 | int ret; | |
4227 | ||
4228 | ret = tracing_update_buffers(); | |
4229 | if (ret < 0) | |
4230 | return ret; | |
4231 | ||
4232 | ret = kstrtoul_from_user(ubuf, cnt, 10, &val); | |
4233 | if (ret) | |
4234 | return ret; | |
4235 | ||
4236 | mutex_lock(&trace_types_lock); | |
4237 | ||
2b6080f2 | 4238 | if (tr->current_trace->use_max_tr) { |
debdd57f HT |
4239 | ret = -EBUSY; |
4240 | goto out; | |
4241 | } | |
4242 | ||
4243 | switch (val) { | |
4244 | case 0: | |
2b6080f2 | 4245 | if (tr->current_trace->allocated_snapshot) { |
debdd57f HT |
4246 | /* free spare buffer */ |
4247 | ring_buffer_resize(max_tr.buffer, 1, | |
4248 | RING_BUFFER_ALL_CPUS); | |
4249 | set_buffer_entries(&max_tr, 1); | |
4250 | tracing_reset_online_cpus(&max_tr); | |
2b6080f2 | 4251 | tr->current_trace->allocated_snapshot = false; |
debdd57f HT |
4252 | } |
4253 | break; | |
4254 | case 1: | |
2b6080f2 | 4255 | if (!tr->current_trace->allocated_snapshot) { |
debdd57f HT |
4256 | /* allocate spare buffer */ |
4257 | ret = resize_buffer_duplicate_size(&max_tr, | |
4258 | &global_trace, RING_BUFFER_ALL_CPUS); | |
4259 | if (ret < 0) | |
4260 | break; | |
2b6080f2 | 4261 | tr->current_trace->allocated_snapshot = true; |
debdd57f HT |
4262 | } |
4263 | ||
4264 | local_irq_disable(); | |
4265 | /* Now, we're going to swap */ | |
4266 | update_max_tr(&global_trace, current, smp_processor_id()); | |
4267 | local_irq_enable(); | |
4268 | break; | |
4269 | default: | |
2b6080f2 | 4270 | if (tr->current_trace->allocated_snapshot) |
debdd57f | 4271 | tracing_reset_online_cpus(&max_tr); |
debdd57f HT |
4272 | break; |
4273 | } | |
4274 | ||
4275 | if (ret >= 0) { | |
4276 | *ppos += cnt; | |
4277 | ret = cnt; | |
4278 | } | |
4279 | out: | |
4280 | mutex_unlock(&trace_types_lock); | |
4281 | return ret; | |
4282 | } | |
2b6080f2 SR |
4283 | |
4284 | static int tracing_snapshot_release(struct inode *inode, struct file *file) | |
4285 | { | |
4286 | struct seq_file *m = file->private_data; | |
4287 | ||
4288 | if (file->f_mode & FMODE_READ) | |
4289 | return tracing_release(inode, file); | |
4290 | ||
4291 | /* If write only, the seq_file is just a stub */ | |
4292 | if (m) | |
4293 | kfree(m->private); | |
4294 | kfree(m); | |
4295 | ||
4296 | return 0; | |
4297 | } | |
4298 | ||
debdd57f HT |
4299 | #endif /* CONFIG_TRACER_SNAPSHOT */ |
4300 | ||
4301 | ||
5e2336a0 | 4302 | static const struct file_operations tracing_max_lat_fops = { |
4bf39a94 IM |
4303 | .open = tracing_open_generic, |
4304 | .read = tracing_max_lat_read, | |
4305 | .write = tracing_max_lat_write, | |
b444786f | 4306 | .llseek = generic_file_llseek, |
bc0c38d1 SR |
4307 | }; |
4308 | ||
5e2336a0 | 4309 | static const struct file_operations set_tracer_fops = { |
4bf39a94 IM |
4310 | .open = tracing_open_generic, |
4311 | .read = tracing_set_trace_read, | |
4312 | .write = tracing_set_trace_write, | |
b444786f | 4313 | .llseek = generic_file_llseek, |
bc0c38d1 SR |
4314 | }; |
4315 | ||
5e2336a0 | 4316 | static const struct file_operations tracing_pipe_fops = { |
4bf39a94 | 4317 | .open = tracing_open_pipe, |
2a2cc8f7 | 4318 | .poll = tracing_poll_pipe, |
4bf39a94 | 4319 | .read = tracing_read_pipe, |
3c56819b | 4320 | .splice_read = tracing_splice_read_pipe, |
4bf39a94 | 4321 | .release = tracing_release_pipe, |
b444786f | 4322 | .llseek = no_llseek, |
b3806b43 SR |
4323 | }; |
4324 | ||
5e2336a0 | 4325 | static const struct file_operations tracing_entries_fops = { |
2b6080f2 | 4326 | .open = tracing_open_generic, |
a98a3c3f SR |
4327 | .read = tracing_entries_read, |
4328 | .write = tracing_entries_write, | |
b444786f | 4329 | .llseek = generic_file_llseek, |
a98a3c3f SR |
4330 | }; |
4331 | ||
f81ab074 VN |
4332 | static const struct file_operations tracing_total_entries_fops = { |
4333 | .open = tracing_open_generic, | |
4334 | .read = tracing_total_entries_read, | |
4335 | .llseek = generic_file_llseek, | |
4336 | }; | |
4337 | ||
4f271a2a VN |
4338 | static const struct file_operations tracing_free_buffer_fops = { |
4339 | .write = tracing_free_buffer_write, | |
4340 | .release = tracing_free_buffer_release, | |
4341 | }; | |
4342 | ||
5e2336a0 | 4343 | static const struct file_operations tracing_mark_fops = { |
43a15386 | 4344 | .open = tracing_open_generic, |
5bf9a1ee | 4345 | .write = tracing_mark_write, |
b444786f | 4346 | .llseek = generic_file_llseek, |
5bf9a1ee PP |
4347 | }; |
4348 | ||
5079f326 | 4349 | static const struct file_operations trace_clock_fops = { |
13f16d20 LZ |
4350 | .open = tracing_clock_open, |
4351 | .read = seq_read, | |
4352 | .llseek = seq_lseek, | |
4353 | .release = single_release, | |
5079f326 Z |
4354 | .write = tracing_clock_write, |
4355 | }; | |
4356 | ||
debdd57f HT |
4357 | #ifdef CONFIG_TRACER_SNAPSHOT |
4358 | static const struct file_operations snapshot_fops = { | |
4359 | .open = tracing_snapshot_open, | |
4360 | .read = seq_read, | |
4361 | .write = tracing_snapshot_write, | |
4362 | .llseek = tracing_seek, | |
2b6080f2 | 4363 | .release = tracing_snapshot_release, |
debdd57f HT |
4364 | }; |
4365 | #endif /* CONFIG_TRACER_SNAPSHOT */ | |
4366 | ||
2cadf913 SR |
4367 | struct ftrace_buffer_info { |
4368 | struct trace_array *tr; | |
4369 | void *spare; | |
4370 | int cpu; | |
4371 | unsigned int read; | |
4372 | }; | |
4373 | ||
4374 | static int tracing_buffers_open(struct inode *inode, struct file *filp) | |
4375 | { | |
2b6080f2 SR |
4376 | struct trace_cpu *tc = inode->i_private; |
4377 | struct trace_array *tr = tc->tr; | |
2cadf913 SR |
4378 | struct ftrace_buffer_info *info; |
4379 | ||
4380 | if (tracing_disabled) | |
4381 | return -ENODEV; | |
4382 | ||
4383 | info = kzalloc(sizeof(*info), GFP_KERNEL); | |
4384 | if (!info) | |
4385 | return -ENOMEM; | |
4386 | ||
2b6080f2 SR |
4387 | info->tr = tr; |
4388 | info->cpu = tc->cpu; | |
ddd538f3 | 4389 | info->spare = NULL; |
2cadf913 SR |
4390 | /* Force reading ring buffer for first read */ |
4391 | info->read = (unsigned int)-1; | |
2cadf913 SR |
4392 | |
4393 | filp->private_data = info; | |
4394 | ||
d1e7e02f | 4395 | return nonseekable_open(inode, filp); |
2cadf913 SR |
4396 | } |
4397 | ||
4398 | static ssize_t | |
4399 | tracing_buffers_read(struct file *filp, char __user *ubuf, | |
4400 | size_t count, loff_t *ppos) | |
4401 | { | |
4402 | struct ftrace_buffer_info *info = filp->private_data; | |
2cadf913 SR |
4403 | ssize_t ret; |
4404 | size_t size; | |
4405 | ||
2dc5d12b SR |
4406 | if (!count) |
4407 | return 0; | |
4408 | ||
ddd538f3 | 4409 | if (!info->spare) |
7ea59064 | 4410 | info->spare = ring_buffer_alloc_read_page(info->tr->buffer, info->cpu); |
ddd538f3 LJ |
4411 | if (!info->spare) |
4412 | return -ENOMEM; | |
4413 | ||
2cadf913 SR |
4414 | /* Do we have previous read data to read? */ |
4415 | if (info->read < PAGE_SIZE) | |
4416 | goto read; | |
4417 | ||
7e53bd42 | 4418 | trace_access_lock(info->cpu); |
2cadf913 SR |
4419 | ret = ring_buffer_read_page(info->tr->buffer, |
4420 | &info->spare, | |
4421 | count, | |
4422 | info->cpu, 0); | |
7e53bd42 | 4423 | trace_access_unlock(info->cpu); |
2cadf913 SR |
4424 | if (ret < 0) |
4425 | return 0; | |
4426 | ||
436fc280 SR |
4427 | info->read = 0; |
4428 | ||
2cadf913 SR |
4429 | read: |
4430 | size = PAGE_SIZE - info->read; | |
4431 | if (size > count) | |
4432 | size = count; | |
4433 | ||
4434 | ret = copy_to_user(ubuf, info->spare + info->read, size); | |
2dc5d12b | 4435 | if (ret == size) |
2cadf913 | 4436 | return -EFAULT; |
2dc5d12b SR |
4437 | size -= ret; |
4438 | ||
2cadf913 SR |
4439 | *ppos += size; |
4440 | info->read += size; | |
4441 | ||
4442 | return size; | |
4443 | } | |
4444 | ||
4445 | static int tracing_buffers_release(struct inode *inode, struct file *file) | |
4446 | { | |
4447 | struct ftrace_buffer_info *info = file->private_data; | |
4448 | ||
ddd538f3 LJ |
4449 | if (info->spare) |
4450 | ring_buffer_free_read_page(info->tr->buffer, info->spare); | |
2cadf913 SR |
4451 | kfree(info); |
4452 | ||
4453 | return 0; | |
4454 | } | |
4455 | ||
4456 | struct buffer_ref { | |
4457 | struct ring_buffer *buffer; | |
4458 | void *page; | |
4459 | int ref; | |
4460 | }; | |
4461 | ||
4462 | static void buffer_pipe_buf_release(struct pipe_inode_info *pipe, | |
4463 | struct pipe_buffer *buf) | |
4464 | { | |
4465 | struct buffer_ref *ref = (struct buffer_ref *)buf->private; | |
4466 | ||
4467 | if (--ref->ref) | |
4468 | return; | |
4469 | ||
4470 | ring_buffer_free_read_page(ref->buffer, ref->page); | |
4471 | kfree(ref); | |
4472 | buf->private = 0; | |
4473 | } | |
4474 | ||
2cadf913 SR |
4475 | static void buffer_pipe_buf_get(struct pipe_inode_info *pipe, |
4476 | struct pipe_buffer *buf) | |
4477 | { | |
4478 | struct buffer_ref *ref = (struct buffer_ref *)buf->private; | |
4479 | ||
4480 | ref->ref++; | |
4481 | } | |
4482 | ||
4483 | /* Pipe buffer operations for a buffer. */ | |
28dfef8f | 4484 | static const struct pipe_buf_operations buffer_pipe_buf_ops = { |
2cadf913 SR |
4485 | .can_merge = 0, |
4486 | .map = generic_pipe_buf_map, | |
4487 | .unmap = generic_pipe_buf_unmap, | |
4488 | .confirm = generic_pipe_buf_confirm, | |
4489 | .release = buffer_pipe_buf_release, | |
d55cb6cf | 4490 | .steal = generic_pipe_buf_steal, |
2cadf913 SR |
4491 | .get = buffer_pipe_buf_get, |
4492 | }; | |
4493 | ||
4494 | /* | |
4495 | * Callback from splice_to_pipe(), if we need to release some pages | |
4496 | * at the end of the spd in case we error'ed out in filling the pipe. | |
4497 | */ | |
4498 | static void buffer_spd_release(struct splice_pipe_desc *spd, unsigned int i) | |
4499 | { | |
4500 | struct buffer_ref *ref = | |
4501 | (struct buffer_ref *)spd->partial[i].private; | |
4502 | ||
4503 | if (--ref->ref) | |
4504 | return; | |
4505 | ||
4506 | ring_buffer_free_read_page(ref->buffer, ref->page); | |
4507 | kfree(ref); | |
4508 | spd->partial[i].private = 0; | |
4509 | } | |
4510 | ||
4511 | static ssize_t | |
4512 | tracing_buffers_splice_read(struct file *file, loff_t *ppos, | |
4513 | struct pipe_inode_info *pipe, size_t len, | |
4514 | unsigned int flags) | |
4515 | { | |
4516 | struct ftrace_buffer_info *info = file->private_data; | |
35f3d14d JA |
4517 | struct partial_page partial_def[PIPE_DEF_BUFFERS]; |
4518 | struct page *pages_def[PIPE_DEF_BUFFERS]; | |
2cadf913 | 4519 | struct splice_pipe_desc spd = { |
35f3d14d JA |
4520 | .pages = pages_def, |
4521 | .partial = partial_def, | |
047fe360 | 4522 | .nr_pages_max = PIPE_DEF_BUFFERS, |
2cadf913 SR |
4523 | .flags = flags, |
4524 | .ops = &buffer_pipe_buf_ops, | |
4525 | .spd_release = buffer_spd_release, | |
4526 | }; | |
4527 | struct buffer_ref *ref; | |
93459c6c | 4528 | int entries, size, i; |
2cadf913 SR |
4529 | size_t ret; |
4530 | ||
35f3d14d JA |
4531 | if (splice_grow_spd(pipe, &spd)) |
4532 | return -ENOMEM; | |
4533 | ||
93cfb3c9 | 4534 | if (*ppos & (PAGE_SIZE - 1)) { |
35f3d14d JA |
4535 | ret = -EINVAL; |
4536 | goto out; | |
93cfb3c9 LJ |
4537 | } |
4538 | ||
4539 | if (len & (PAGE_SIZE - 1)) { | |
35f3d14d JA |
4540 | if (len < PAGE_SIZE) { |
4541 | ret = -EINVAL; | |
4542 | goto out; | |
4543 | } | |
93cfb3c9 LJ |
4544 | len &= PAGE_MASK; |
4545 | } | |
4546 | ||
7e53bd42 | 4547 | trace_access_lock(info->cpu); |
93459c6c SR |
4548 | entries = ring_buffer_entries_cpu(info->tr->buffer, info->cpu); |
4549 | ||
35f3d14d | 4550 | for (i = 0; i < pipe->buffers && len && entries; i++, len -= PAGE_SIZE) { |
2cadf913 SR |
4551 | struct page *page; |
4552 | int r; | |
4553 | ||
4554 | ref = kzalloc(sizeof(*ref), GFP_KERNEL); | |
4555 | if (!ref) | |
4556 | break; | |
4557 | ||
7267fa68 | 4558 | ref->ref = 1; |
2cadf913 | 4559 | ref->buffer = info->tr->buffer; |
7ea59064 | 4560 | ref->page = ring_buffer_alloc_read_page(ref->buffer, info->cpu); |
2cadf913 SR |
4561 | if (!ref->page) { |
4562 | kfree(ref); | |
4563 | break; | |
4564 | } | |
4565 | ||
4566 | r = ring_buffer_read_page(ref->buffer, &ref->page, | |
f2957f1f | 4567 | len, info->cpu, 1); |
2cadf913 | 4568 | if (r < 0) { |
7ea59064 | 4569 | ring_buffer_free_read_page(ref->buffer, ref->page); |
2cadf913 SR |
4570 | kfree(ref); |
4571 | break; | |
4572 | } | |
4573 | ||
4574 | /* | |
4575 | * zero out any left over data, this is going to | |
4576 | * user land. | |
4577 | */ | |
4578 | size = ring_buffer_page_len(ref->page); | |
4579 | if (size < PAGE_SIZE) | |
4580 | memset(ref->page + size, 0, PAGE_SIZE - size); | |
4581 | ||
4582 | page = virt_to_page(ref->page); | |
4583 | ||
4584 | spd.pages[i] = page; | |
4585 | spd.partial[i].len = PAGE_SIZE; | |
4586 | spd.partial[i].offset = 0; | |
4587 | spd.partial[i].private = (unsigned long)ref; | |
4588 | spd.nr_pages++; | |
93cfb3c9 | 4589 | *ppos += PAGE_SIZE; |
93459c6c SR |
4590 | |
4591 | entries = ring_buffer_entries_cpu(info->tr->buffer, info->cpu); | |
2cadf913 SR |
4592 | } |
4593 | ||
7e53bd42 | 4594 | trace_access_unlock(info->cpu); |
2cadf913 SR |
4595 | spd.nr_pages = i; |
4596 | ||
4597 | /* did we read anything? */ | |
4598 | if (!spd.nr_pages) { | |
4599 | if (flags & SPLICE_F_NONBLOCK) | |
4600 | ret = -EAGAIN; | |
4601 | else | |
4602 | ret = 0; | |
4603 | /* TODO: block */ | |
35f3d14d | 4604 | goto out; |
2cadf913 SR |
4605 | } |
4606 | ||
4607 | ret = splice_to_pipe(pipe, &spd); | |
047fe360 | 4608 | splice_shrink_spd(&spd); |
35f3d14d | 4609 | out: |
2cadf913 SR |
4610 | return ret; |
4611 | } | |
4612 | ||
4613 | static const struct file_operations tracing_buffers_fops = { | |
4614 | .open = tracing_buffers_open, | |
4615 | .read = tracing_buffers_read, | |
4616 | .release = tracing_buffers_release, | |
4617 | .splice_read = tracing_buffers_splice_read, | |
4618 | .llseek = no_llseek, | |
4619 | }; | |
4620 | ||
c8d77183 SR |
4621 | static ssize_t |
4622 | tracing_stats_read(struct file *filp, char __user *ubuf, | |
4623 | size_t count, loff_t *ppos) | |
4624 | { | |
2b6080f2 SR |
4625 | struct trace_cpu *tc = filp->private_data; |
4626 | struct trace_array *tr = tc->tr; | |
c8d77183 SR |
4627 | struct trace_seq *s; |
4628 | unsigned long cnt; | |
c64e148a VN |
4629 | unsigned long long t; |
4630 | unsigned long usec_rem; | |
2b6080f2 | 4631 | int cpu = tc->cpu; |
c8d77183 | 4632 | |
e4f2d10f | 4633 | s = kmalloc(sizeof(*s), GFP_KERNEL); |
c8d77183 | 4634 | if (!s) |
a646365c | 4635 | return -ENOMEM; |
c8d77183 SR |
4636 | |
4637 | trace_seq_init(s); | |
4638 | ||
4639 | cnt = ring_buffer_entries_cpu(tr->buffer, cpu); | |
4640 | trace_seq_printf(s, "entries: %ld\n", cnt); | |
4641 | ||
4642 | cnt = ring_buffer_overrun_cpu(tr->buffer, cpu); | |
4643 | trace_seq_printf(s, "overrun: %ld\n", cnt); | |
4644 | ||
4645 | cnt = ring_buffer_commit_overrun_cpu(tr->buffer, cpu); | |
4646 | trace_seq_printf(s, "commit overrun: %ld\n", cnt); | |
4647 | ||
c64e148a VN |
4648 | cnt = ring_buffer_bytes_cpu(tr->buffer, cpu); |
4649 | trace_seq_printf(s, "bytes: %ld\n", cnt); | |
4650 | ||
11043d8b YY |
4651 | if (trace_clocks[trace_clock_id].in_ns) { |
4652 | /* local or global for trace_clock */ | |
4653 | t = ns2usecs(ring_buffer_oldest_event_ts(tr->buffer, cpu)); | |
4654 | usec_rem = do_div(t, USEC_PER_SEC); | |
4655 | trace_seq_printf(s, "oldest event ts: %5llu.%06lu\n", | |
4656 | t, usec_rem); | |
4657 | ||
4658 | t = ns2usecs(ring_buffer_time_stamp(tr->buffer, cpu)); | |
4659 | usec_rem = do_div(t, USEC_PER_SEC); | |
4660 | trace_seq_printf(s, "now ts: %5llu.%06lu\n", t, usec_rem); | |
4661 | } else { | |
4662 | /* counter or tsc mode for trace_clock */ | |
4663 | trace_seq_printf(s, "oldest event ts: %llu\n", | |
4664 | ring_buffer_oldest_event_ts(tr->buffer, cpu)); | |
c64e148a | 4665 | |
11043d8b YY |
4666 | trace_seq_printf(s, "now ts: %llu\n", |
4667 | ring_buffer_time_stamp(tr->buffer, cpu)); | |
4668 | } | |
c64e148a | 4669 | |
884bfe89 SP |
4670 | cnt = ring_buffer_dropped_events_cpu(tr->buffer, cpu); |
4671 | trace_seq_printf(s, "dropped events: %ld\n", cnt); | |
4672 | ||
ad964704 SRRH |
4673 | cnt = ring_buffer_read_events_cpu(tr->buffer, cpu); |
4674 | trace_seq_printf(s, "read events: %ld\n", cnt); | |
4675 | ||
c8d77183 SR |
4676 | count = simple_read_from_buffer(ubuf, count, ppos, s->buffer, s->len); |
4677 | ||
4678 | kfree(s); | |
4679 | ||
4680 | return count; | |
4681 | } | |
4682 | ||
4683 | static const struct file_operations tracing_stats_fops = { | |
4684 | .open = tracing_open_generic, | |
4685 | .read = tracing_stats_read, | |
b444786f | 4686 | .llseek = generic_file_llseek, |
c8d77183 SR |
4687 | }; |
4688 | ||
bc0c38d1 SR |
4689 | #ifdef CONFIG_DYNAMIC_FTRACE |
4690 | ||
b807c3d0 SR |
4691 | int __weak ftrace_arch_read_dyn_info(char *buf, int size) |
4692 | { | |
4693 | return 0; | |
4694 | } | |
4695 | ||
bc0c38d1 | 4696 | static ssize_t |
b807c3d0 | 4697 | tracing_read_dyn_info(struct file *filp, char __user *ubuf, |
bc0c38d1 SR |
4698 | size_t cnt, loff_t *ppos) |
4699 | { | |
a26a2a27 SR |
4700 | static char ftrace_dyn_info_buffer[1024]; |
4701 | static DEFINE_MUTEX(dyn_info_mutex); | |
bc0c38d1 | 4702 | unsigned long *p = filp->private_data; |
b807c3d0 | 4703 | char *buf = ftrace_dyn_info_buffer; |
a26a2a27 | 4704 | int size = ARRAY_SIZE(ftrace_dyn_info_buffer); |
bc0c38d1 SR |
4705 | int r; |
4706 | ||
b807c3d0 SR |
4707 | mutex_lock(&dyn_info_mutex); |
4708 | r = sprintf(buf, "%ld ", *p); | |
4bf39a94 | 4709 | |
a26a2a27 | 4710 | r += ftrace_arch_read_dyn_info(buf+r, (size-1)-r); |
b807c3d0 SR |
4711 | buf[r++] = '\n'; |
4712 | ||
4713 | r = simple_read_from_buffer(ubuf, cnt, ppos, buf, r); | |
4714 | ||
4715 | mutex_unlock(&dyn_info_mutex); | |
4716 | ||
4717 | return r; | |
bc0c38d1 SR |
4718 | } |
4719 | ||
5e2336a0 | 4720 | static const struct file_operations tracing_dyn_info_fops = { |
4bf39a94 | 4721 | .open = tracing_open_generic, |
b807c3d0 | 4722 | .read = tracing_read_dyn_info, |
b444786f | 4723 | .llseek = generic_file_llseek, |
bc0c38d1 SR |
4724 | }; |
4725 | #endif | |
4726 | ||
2b6080f2 | 4727 | struct dentry *tracing_init_dentry_tr(struct trace_array *tr) |
bc0c38d1 SR |
4728 | { |
4729 | static int once; | |
4730 | ||
2b6080f2 SR |
4731 | if (tr->dir) |
4732 | return tr->dir; | |
bc0c38d1 | 4733 | |
3e1f60b8 FW |
4734 | if (!debugfs_initialized()) |
4735 | return NULL; | |
4736 | ||
2b6080f2 SR |
4737 | if (tr->flags & TRACE_ARRAY_FL_GLOBAL) |
4738 | tr->dir = debugfs_create_dir("tracing", NULL); | |
bc0c38d1 | 4739 | |
2b6080f2 | 4740 | if (!tr->dir && !once) { |
bc0c38d1 SR |
4741 | once = 1; |
4742 | pr_warning("Could not create debugfs directory 'tracing'\n"); | |
4743 | return NULL; | |
4744 | } | |
4745 | ||
2b6080f2 | 4746 | return tr->dir; |
bc0c38d1 SR |
4747 | } |
4748 | ||
2b6080f2 SR |
4749 | struct dentry *tracing_init_dentry(void) |
4750 | { | |
4751 | return tracing_init_dentry_tr(&global_trace); | |
4752 | } | |
b04cc6b1 | 4753 | |
2b6080f2 | 4754 | static struct dentry *tracing_dentry_percpu(struct trace_array *tr, int cpu) |
b04cc6b1 | 4755 | { |
b04cc6b1 FW |
4756 | struct dentry *d_tracer; |
4757 | ||
2b6080f2 SR |
4758 | if (tr->percpu_dir) |
4759 | return tr->percpu_dir; | |
b04cc6b1 | 4760 | |
2b6080f2 | 4761 | d_tracer = tracing_init_dentry_tr(tr); |
b04cc6b1 FW |
4762 | if (!d_tracer) |
4763 | return NULL; | |
4764 | ||
2b6080f2 | 4765 | tr->percpu_dir = debugfs_create_dir("per_cpu", d_tracer); |
b04cc6b1 | 4766 | |
2b6080f2 SR |
4767 | WARN_ONCE(!tr->percpu_dir, |
4768 | "Could not create debugfs directory 'per_cpu/%d'\n", cpu); | |
b04cc6b1 | 4769 | |
2b6080f2 | 4770 | return tr->percpu_dir; |
b04cc6b1 FW |
4771 | } |
4772 | ||
2b6080f2 SR |
4773 | static void |
4774 | tracing_init_debugfs_percpu(struct trace_array *tr, long cpu) | |
b04cc6b1 | 4775 | { |
2b6080f2 SR |
4776 | struct trace_array_cpu *data = tr->data[cpu]; |
4777 | struct dentry *d_percpu = tracing_dentry_percpu(tr, cpu); | |
5452af66 | 4778 | struct dentry *d_cpu; |
dd49a38c | 4779 | char cpu_dir[30]; /* 30 characters should be more than enough */ |
b04cc6b1 | 4780 | |
0a3d7ce7 NK |
4781 | if (!d_percpu) |
4782 | return; | |
4783 | ||
dd49a38c | 4784 | snprintf(cpu_dir, 30, "cpu%ld", cpu); |
8656e7a2 FW |
4785 | d_cpu = debugfs_create_dir(cpu_dir, d_percpu); |
4786 | if (!d_cpu) { | |
4787 | pr_warning("Could not create debugfs '%s' entry\n", cpu_dir); | |
4788 | return; | |
4789 | } | |
b04cc6b1 | 4790 | |
8656e7a2 | 4791 | /* per cpu trace_pipe */ |
5452af66 | 4792 | trace_create_file("trace_pipe", 0444, d_cpu, |
2b6080f2 | 4793 | (void *)&data->trace_cpu, &tracing_pipe_fops); |
b04cc6b1 FW |
4794 | |
4795 | /* per cpu trace */ | |
5452af66 | 4796 | trace_create_file("trace", 0644, d_cpu, |
2b6080f2 | 4797 | (void *)&data->trace_cpu, &tracing_fops); |
7f96f93f | 4798 | |
5452af66 | 4799 | trace_create_file("trace_pipe_raw", 0444, d_cpu, |
2b6080f2 | 4800 | (void *)&data->trace_cpu, &tracing_buffers_fops); |
7f96f93f | 4801 | |
c8d77183 | 4802 | trace_create_file("stats", 0444, d_cpu, |
2b6080f2 | 4803 | (void *)&data->trace_cpu, &tracing_stats_fops); |
438ced17 VN |
4804 | |
4805 | trace_create_file("buffer_size_kb", 0444, d_cpu, | |
2b6080f2 | 4806 | (void *)&data->trace_cpu, &tracing_entries_fops); |
b04cc6b1 FW |
4807 | } |
4808 | ||
60a11774 SR |
4809 | #ifdef CONFIG_FTRACE_SELFTEST |
4810 | /* Let selftest have access to static functions in this file */ | |
4811 | #include "trace_selftest.c" | |
4812 | #endif | |
4813 | ||
577b785f SR |
4814 | struct trace_option_dentry { |
4815 | struct tracer_opt *opt; | |
4816 | struct tracer_flags *flags; | |
2b6080f2 | 4817 | struct trace_array *tr; |
577b785f SR |
4818 | struct dentry *entry; |
4819 | }; | |
4820 | ||
4821 | static ssize_t | |
4822 | trace_options_read(struct file *filp, char __user *ubuf, size_t cnt, | |
4823 | loff_t *ppos) | |
4824 | { | |
4825 | struct trace_option_dentry *topt = filp->private_data; | |
4826 | char *buf; | |
4827 | ||
4828 | if (topt->flags->val & topt->opt->bit) | |
4829 | buf = "1\n"; | |
4830 | else | |
4831 | buf = "0\n"; | |
4832 | ||
4833 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, 2); | |
4834 | } | |
4835 | ||
4836 | static ssize_t | |
4837 | trace_options_write(struct file *filp, const char __user *ubuf, size_t cnt, | |
4838 | loff_t *ppos) | |
4839 | { | |
4840 | struct trace_option_dentry *topt = filp->private_data; | |
4841 | unsigned long val; | |
577b785f SR |
4842 | int ret; |
4843 | ||
22fe9b54 PH |
4844 | ret = kstrtoul_from_user(ubuf, cnt, 10, &val); |
4845 | if (ret) | |
577b785f SR |
4846 | return ret; |
4847 | ||
8d18eaaf LZ |
4848 | if (val != 0 && val != 1) |
4849 | return -EINVAL; | |
577b785f | 4850 | |
8d18eaaf | 4851 | if (!!(topt->flags->val & topt->opt->bit) != val) { |
577b785f | 4852 | mutex_lock(&trace_types_lock); |
2b6080f2 | 4853 | ret = __set_tracer_option(topt->tr->current_trace, topt->flags, |
c757bea9 | 4854 | topt->opt, !val); |
577b785f SR |
4855 | mutex_unlock(&trace_types_lock); |
4856 | if (ret) | |
4857 | return ret; | |
577b785f SR |
4858 | } |
4859 | ||
4860 | *ppos += cnt; | |
4861 | ||
4862 | return cnt; | |
4863 | } | |
4864 | ||
4865 | ||
4866 | static const struct file_operations trace_options_fops = { | |
4867 | .open = tracing_open_generic, | |
4868 | .read = trace_options_read, | |
4869 | .write = trace_options_write, | |
b444786f | 4870 | .llseek = generic_file_llseek, |
577b785f SR |
4871 | }; |
4872 | ||
a8259075 SR |
4873 | static ssize_t |
4874 | trace_options_core_read(struct file *filp, char __user *ubuf, size_t cnt, | |
4875 | loff_t *ppos) | |
4876 | { | |
4877 | long index = (long)filp->private_data; | |
4878 | char *buf; | |
4879 | ||
4880 | if (trace_flags & (1 << index)) | |
4881 | buf = "1\n"; | |
4882 | else | |
4883 | buf = "0\n"; | |
4884 | ||
4885 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, 2); | |
4886 | } | |
4887 | ||
4888 | static ssize_t | |
4889 | trace_options_core_write(struct file *filp, const char __user *ubuf, size_t cnt, | |
4890 | loff_t *ppos) | |
4891 | { | |
2b6080f2 | 4892 | struct trace_array *tr = &global_trace; |
a8259075 | 4893 | long index = (long)filp->private_data; |
a8259075 SR |
4894 | unsigned long val; |
4895 | int ret; | |
4896 | ||
22fe9b54 PH |
4897 | ret = kstrtoul_from_user(ubuf, cnt, 10, &val); |
4898 | if (ret) | |
a8259075 SR |
4899 | return ret; |
4900 | ||
f2d84b65 | 4901 | if (val != 0 && val != 1) |
a8259075 | 4902 | return -EINVAL; |
69d34da2 SRRH |
4903 | |
4904 | mutex_lock(&trace_types_lock); | |
2b6080f2 | 4905 | ret = set_tracer_flag(tr, 1 << index, val); |
69d34da2 | 4906 | mutex_unlock(&trace_types_lock); |
a8259075 | 4907 | |
613f04a0 SRRH |
4908 | if (ret < 0) |
4909 | return ret; | |
4910 | ||
a8259075 SR |
4911 | *ppos += cnt; |
4912 | ||
4913 | return cnt; | |
4914 | } | |
4915 | ||
a8259075 SR |
4916 | static const struct file_operations trace_options_core_fops = { |
4917 | .open = tracing_open_generic, | |
4918 | .read = trace_options_core_read, | |
4919 | .write = trace_options_core_write, | |
b444786f | 4920 | .llseek = generic_file_llseek, |
a8259075 SR |
4921 | }; |
4922 | ||
5452af66 | 4923 | struct dentry *trace_create_file(const char *name, |
f4ae40a6 | 4924 | umode_t mode, |
5452af66 FW |
4925 | struct dentry *parent, |
4926 | void *data, | |
4927 | const struct file_operations *fops) | |
4928 | { | |
4929 | struct dentry *ret; | |
4930 | ||
4931 | ret = debugfs_create_file(name, mode, parent, data, fops); | |
4932 | if (!ret) | |
4933 | pr_warning("Could not create debugfs '%s' entry\n", name); | |
4934 | ||
4935 | return ret; | |
4936 | } | |
4937 | ||
4938 | ||
2b6080f2 | 4939 | static struct dentry *trace_options_init_dentry(struct trace_array *tr) |
a8259075 SR |
4940 | { |
4941 | struct dentry *d_tracer; | |
a8259075 | 4942 | |
2b6080f2 SR |
4943 | if (tr->options) |
4944 | return tr->options; | |
a8259075 | 4945 | |
2b6080f2 | 4946 | d_tracer = tracing_init_dentry_tr(tr); |
a8259075 SR |
4947 | if (!d_tracer) |
4948 | return NULL; | |
4949 | ||
2b6080f2 SR |
4950 | tr->options = debugfs_create_dir("options", d_tracer); |
4951 | if (!tr->options) { | |
a8259075 SR |
4952 | pr_warning("Could not create debugfs directory 'options'\n"); |
4953 | return NULL; | |
4954 | } | |
4955 | ||
2b6080f2 | 4956 | return tr->options; |
a8259075 SR |
4957 | } |
4958 | ||
577b785f | 4959 | static void |
2b6080f2 SR |
4960 | create_trace_option_file(struct trace_array *tr, |
4961 | struct trace_option_dentry *topt, | |
577b785f SR |
4962 | struct tracer_flags *flags, |
4963 | struct tracer_opt *opt) | |
4964 | { | |
4965 | struct dentry *t_options; | |
577b785f | 4966 | |
2b6080f2 | 4967 | t_options = trace_options_init_dentry(tr); |
577b785f SR |
4968 | if (!t_options) |
4969 | return; | |
4970 | ||
4971 | topt->flags = flags; | |
4972 | topt->opt = opt; | |
2b6080f2 | 4973 | topt->tr = tr; |
577b785f | 4974 | |
5452af66 | 4975 | topt->entry = trace_create_file(opt->name, 0644, t_options, topt, |
577b785f SR |
4976 | &trace_options_fops); |
4977 | ||
577b785f SR |
4978 | } |
4979 | ||
4980 | static struct trace_option_dentry * | |
2b6080f2 | 4981 | create_trace_option_files(struct trace_array *tr, struct tracer *tracer) |
577b785f SR |
4982 | { |
4983 | struct trace_option_dentry *topts; | |
4984 | struct tracer_flags *flags; | |
4985 | struct tracer_opt *opts; | |
4986 | int cnt; | |
4987 | ||
4988 | if (!tracer) | |
4989 | return NULL; | |
4990 | ||
4991 | flags = tracer->flags; | |
4992 | ||
4993 | if (!flags || !flags->opts) | |
4994 | return NULL; | |
4995 | ||
4996 | opts = flags->opts; | |
4997 | ||
4998 | for (cnt = 0; opts[cnt].name; cnt++) | |
4999 | ; | |
5000 | ||
0cfe8245 | 5001 | topts = kcalloc(cnt + 1, sizeof(*topts), GFP_KERNEL); |
577b785f SR |
5002 | if (!topts) |
5003 | return NULL; | |
5004 | ||
5005 | for (cnt = 0; opts[cnt].name; cnt++) | |
2b6080f2 | 5006 | create_trace_option_file(tr, &topts[cnt], flags, |
577b785f SR |
5007 | &opts[cnt]); |
5008 | ||
5009 | return topts; | |
5010 | } | |
5011 | ||
5012 | static void | |
5013 | destroy_trace_option_files(struct trace_option_dentry *topts) | |
5014 | { | |
5015 | int cnt; | |
5016 | ||
5017 | if (!topts) | |
5018 | return; | |
5019 | ||
5020 | for (cnt = 0; topts[cnt].opt; cnt++) { | |
5021 | if (topts[cnt].entry) | |
5022 | debugfs_remove(topts[cnt].entry); | |
5023 | } | |
5024 | ||
5025 | kfree(topts); | |
5026 | } | |
5027 | ||
a8259075 | 5028 | static struct dentry * |
2b6080f2 SR |
5029 | create_trace_option_core_file(struct trace_array *tr, |
5030 | const char *option, long index) | |
a8259075 SR |
5031 | { |
5032 | struct dentry *t_options; | |
a8259075 | 5033 | |
2b6080f2 | 5034 | t_options = trace_options_init_dentry(tr); |
a8259075 SR |
5035 | if (!t_options) |
5036 | return NULL; | |
5037 | ||
5452af66 | 5038 | return trace_create_file(option, 0644, t_options, (void *)index, |
a8259075 | 5039 | &trace_options_core_fops); |
a8259075 SR |
5040 | } |
5041 | ||
2b6080f2 | 5042 | static __init void create_trace_options_dir(struct trace_array *tr) |
a8259075 SR |
5043 | { |
5044 | struct dentry *t_options; | |
a8259075 SR |
5045 | int i; |
5046 | ||
2b6080f2 | 5047 | t_options = trace_options_init_dentry(tr); |
a8259075 SR |
5048 | if (!t_options) |
5049 | return; | |
5050 | ||
5452af66 | 5051 | for (i = 0; trace_options[i]; i++) |
2b6080f2 | 5052 | create_trace_option_core_file(tr, trace_options[i], i); |
a8259075 SR |
5053 | } |
5054 | ||
499e5470 SR |
5055 | static ssize_t |
5056 | rb_simple_read(struct file *filp, char __user *ubuf, | |
5057 | size_t cnt, loff_t *ppos) | |
5058 | { | |
348f0fc2 SR |
5059 | struct trace_array *tr = filp->private_data; |
5060 | struct ring_buffer *buffer = tr->buffer; | |
499e5470 SR |
5061 | char buf[64]; |
5062 | int r; | |
5063 | ||
5064 | if (buffer) | |
5065 | r = ring_buffer_record_is_on(buffer); | |
5066 | else | |
5067 | r = 0; | |
5068 | ||
5069 | r = sprintf(buf, "%d\n", r); | |
5070 | ||
5071 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, r); | |
5072 | } | |
5073 | ||
5074 | static ssize_t | |
5075 | rb_simple_write(struct file *filp, const char __user *ubuf, | |
5076 | size_t cnt, loff_t *ppos) | |
5077 | { | |
348f0fc2 SR |
5078 | struct trace_array *tr = filp->private_data; |
5079 | struct ring_buffer *buffer = tr->buffer; | |
499e5470 SR |
5080 | unsigned long val; |
5081 | int ret; | |
5082 | ||
5083 | ret = kstrtoul_from_user(ubuf, cnt, 10, &val); | |
5084 | if (ret) | |
5085 | return ret; | |
5086 | ||
5087 | if (buffer) { | |
2df8f8a6 SR |
5088 | mutex_lock(&trace_types_lock); |
5089 | if (val) { | |
499e5470 | 5090 | ring_buffer_record_on(buffer); |
2b6080f2 SR |
5091 | if (tr->current_trace->start) |
5092 | tr->current_trace->start(tr); | |
2df8f8a6 | 5093 | } else { |
499e5470 | 5094 | ring_buffer_record_off(buffer); |
2b6080f2 SR |
5095 | if (tr->current_trace->stop) |
5096 | tr->current_trace->stop(tr); | |
2df8f8a6 SR |
5097 | } |
5098 | mutex_unlock(&trace_types_lock); | |
499e5470 SR |
5099 | } |
5100 | ||
5101 | (*ppos)++; | |
5102 | ||
5103 | return cnt; | |
5104 | } | |
5105 | ||
5106 | static const struct file_operations rb_simple_fops = { | |
5107 | .open = tracing_open_generic, | |
5108 | .read = rb_simple_read, | |
5109 | .write = rb_simple_write, | |
5110 | .llseek = default_llseek, | |
5111 | }; | |
5112 | ||
2b6080f2 SR |
5113 | static void |
5114 | init_tracer_debugfs(struct trace_array *tr, struct dentry *d_tracer) | |
5115 | { | |
5116 | ||
5117 | trace_create_file("trace_options", 0644, d_tracer, | |
5118 | tr, &tracing_iter_fops); | |
5119 | ||
5120 | trace_create_file("trace", 0644, d_tracer, | |
5121 | (void *)&tr->trace_cpu, &tracing_fops); | |
5122 | ||
5123 | trace_create_file("trace_pipe", 0444, d_tracer, | |
5124 | (void *)&tr->trace_cpu, &tracing_pipe_fops); | |
5125 | ||
5126 | trace_create_file("buffer_size_kb", 0644, d_tracer, | |
5127 | (void *)&tr->trace_cpu, &tracing_entries_fops); | |
5128 | ||
5129 | trace_create_file("buffer_total_size_kb", 0444, d_tracer, | |
5130 | tr, &tracing_total_entries_fops); | |
5131 | ||
5132 | trace_create_file("free_buffer", 0644, d_tracer, | |
5133 | tr, &tracing_free_buffer_fops); | |
5134 | ||
5135 | trace_create_file("trace_marker", 0220, d_tracer, | |
5136 | tr, &tracing_mark_fops); | |
5137 | ||
5138 | trace_create_file("trace_clock", 0644, d_tracer, tr, | |
5139 | &trace_clock_fops); | |
5140 | ||
5141 | trace_create_file("tracing_on", 0644, d_tracer, | |
5142 | tr, &rb_simple_fops); | |
5143 | } | |
5144 | ||
b5ad384e | 5145 | static __init int tracer_init_debugfs(void) |
bc0c38d1 SR |
5146 | { |
5147 | struct dentry *d_tracer; | |
b04cc6b1 | 5148 | int cpu; |
bc0c38d1 | 5149 | |
7e53bd42 LJ |
5150 | trace_access_lock_init(); |
5151 | ||
bc0c38d1 SR |
5152 | d_tracer = tracing_init_dentry(); |
5153 | ||
2b6080f2 | 5154 | init_tracer_debugfs(&global_trace, d_tracer); |
bc0c38d1 | 5155 | |
5452af66 | 5156 | trace_create_file("tracing_cpumask", 0644, d_tracer, |
2b6080f2 | 5157 | &global_trace, &tracing_cpumask_fops); |
a8259075 | 5158 | |
5452af66 FW |
5159 | trace_create_file("available_tracers", 0444, d_tracer, |
5160 | &global_trace, &show_traces_fops); | |
5161 | ||
339ae5d3 | 5162 | trace_create_file("current_tracer", 0644, d_tracer, |
5452af66 FW |
5163 | &global_trace, &set_tracer_fops); |
5164 | ||
5d4a9dba | 5165 | #ifdef CONFIG_TRACER_MAX_TRACE |
5452af66 FW |
5166 | trace_create_file("tracing_max_latency", 0644, d_tracer, |
5167 | &tracing_max_latency, &tracing_max_lat_fops); | |
0e950173 | 5168 | #endif |
5452af66 FW |
5169 | |
5170 | trace_create_file("tracing_thresh", 0644, d_tracer, | |
5171 | &tracing_thresh, &tracing_max_lat_fops); | |
a8259075 | 5172 | |
339ae5d3 | 5173 | trace_create_file("README", 0444, d_tracer, |
5452af66 FW |
5174 | NULL, &tracing_readme_fops); |
5175 | ||
69abe6a5 AP |
5176 | trace_create_file("saved_cmdlines", 0444, d_tracer, |
5177 | NULL, &tracing_saved_cmdlines_fops); | |
5bf9a1ee | 5178 | |
bc0c38d1 | 5179 | #ifdef CONFIG_DYNAMIC_FTRACE |
5452af66 FW |
5180 | trace_create_file("dyn_ftrace_total_info", 0444, d_tracer, |
5181 | &ftrace_update_tot_cnt, &tracing_dyn_info_fops); | |
bc0c38d1 | 5182 | #endif |
b04cc6b1 | 5183 | |
debdd57f HT |
5184 | #ifdef CONFIG_TRACER_SNAPSHOT |
5185 | trace_create_file("snapshot", 0644, d_tracer, | |
2b6080f2 | 5186 | (void *)&global_trace.trace_cpu, &snapshot_fops); |
debdd57f HT |
5187 | #endif |
5188 | ||
2b6080f2 | 5189 | create_trace_options_dir(&global_trace); |
5452af66 | 5190 | |
b04cc6b1 | 5191 | for_each_tracing_cpu(cpu) |
2b6080f2 | 5192 | tracing_init_debugfs_percpu(&global_trace, cpu); |
b04cc6b1 | 5193 | |
b5ad384e | 5194 | return 0; |
bc0c38d1 SR |
5195 | } |
5196 | ||
3f5a54e3 SR |
5197 | static int trace_panic_handler(struct notifier_block *this, |
5198 | unsigned long event, void *unused) | |
5199 | { | |
944ac425 | 5200 | if (ftrace_dump_on_oops) |
cecbca96 | 5201 | ftrace_dump(ftrace_dump_on_oops); |
3f5a54e3 SR |
5202 | return NOTIFY_OK; |
5203 | } | |
5204 | ||
5205 | static struct notifier_block trace_panic_notifier = { | |
5206 | .notifier_call = trace_panic_handler, | |
5207 | .next = NULL, | |
5208 | .priority = 150 /* priority: INT_MAX >= x >= 0 */ | |
5209 | }; | |
5210 | ||
5211 | static int trace_die_handler(struct notifier_block *self, | |
5212 | unsigned long val, | |
5213 | void *data) | |
5214 | { | |
5215 | switch (val) { | |
5216 | case DIE_OOPS: | |
944ac425 | 5217 | if (ftrace_dump_on_oops) |
cecbca96 | 5218 | ftrace_dump(ftrace_dump_on_oops); |
3f5a54e3 SR |
5219 | break; |
5220 | default: | |
5221 | break; | |
5222 | } | |
5223 | return NOTIFY_OK; | |
5224 | } | |
5225 | ||
5226 | static struct notifier_block trace_die_notifier = { | |
5227 | .notifier_call = trace_die_handler, | |
5228 | .priority = 200 | |
5229 | }; | |
5230 | ||
5231 | /* | |
5232 | * printk is set to max of 1024, we really don't need it that big. | |
5233 | * Nothing should be printing 1000 characters anyway. | |
5234 | */ | |
5235 | #define TRACE_MAX_PRINT 1000 | |
5236 | ||
5237 | /* | |
5238 | * Define here KERN_TRACE so that we have one place to modify | |
5239 | * it if we decide to change what log level the ftrace dump | |
5240 | * should be at. | |
5241 | */ | |
428aee14 | 5242 | #define KERN_TRACE KERN_EMERG |
3f5a54e3 | 5243 | |
955b61e5 | 5244 | void |
3f5a54e3 SR |
5245 | trace_printk_seq(struct trace_seq *s) |
5246 | { | |
5247 | /* Probably should print a warning here. */ | |
5248 | if (s->len >= 1000) | |
5249 | s->len = 1000; | |
5250 | ||
5251 | /* should be zero ended, but we are paranoid. */ | |
5252 | s->buffer[s->len] = 0; | |
5253 | ||
5254 | printk(KERN_TRACE "%s", s->buffer); | |
5255 | ||
f9520750 | 5256 | trace_seq_init(s); |
3f5a54e3 SR |
5257 | } |
5258 | ||
955b61e5 JW |
5259 | void trace_init_global_iter(struct trace_iterator *iter) |
5260 | { | |
5261 | iter->tr = &global_trace; | |
2b6080f2 | 5262 | iter->trace = iter->tr->current_trace; |
ae3b5093 | 5263 | iter->cpu_file = RING_BUFFER_ALL_CPUS; |
955b61e5 JW |
5264 | } |
5265 | ||
cecbca96 FW |
5266 | static void |
5267 | __ftrace_dump(bool disable_tracing, enum ftrace_dump_mode oops_dump_mode) | |
3f5a54e3 | 5268 | { |
445c8951 | 5269 | static arch_spinlock_t ftrace_dump_lock = |
edc35bd7 | 5270 | (arch_spinlock_t)__ARCH_SPIN_LOCK_UNLOCKED; |
3f5a54e3 SR |
5271 | /* use static because iter can be a bit big for the stack */ |
5272 | static struct trace_iterator iter; | |
cf586b61 | 5273 | unsigned int old_userobj; |
3f5a54e3 | 5274 | static int dump_ran; |
d769041f SR |
5275 | unsigned long flags; |
5276 | int cnt = 0, cpu; | |
3f5a54e3 SR |
5277 | |
5278 | /* only one dump */ | |
cd891ae0 | 5279 | local_irq_save(flags); |
0199c4e6 | 5280 | arch_spin_lock(&ftrace_dump_lock); |
3f5a54e3 SR |
5281 | if (dump_ran) |
5282 | goto out; | |
5283 | ||
5284 | dump_ran = 1; | |
5285 | ||
0ee6b6cf | 5286 | tracing_off(); |
cf586b61 | 5287 | |
e0a413f6 SR |
5288 | /* Did function tracer already get disabled? */ |
5289 | if (ftrace_is_dead()) { | |
5290 | printk("# WARNING: FUNCTION TRACING IS CORRUPTED\n"); | |
5291 | printk("# MAY BE MISSING FUNCTION EVENTS\n"); | |
5292 | } | |
5293 | ||
cf586b61 FW |
5294 | if (disable_tracing) |
5295 | ftrace_kill(); | |
3f5a54e3 | 5296 | |
38dbe0b1 | 5297 | /* Simulate the iterator */ |
955b61e5 JW |
5298 | trace_init_global_iter(&iter); |
5299 | ||
d769041f | 5300 | for_each_tracing_cpu(cpu) { |
955b61e5 | 5301 | atomic_inc(&iter.tr->data[cpu]->disabled); |
d769041f SR |
5302 | } |
5303 | ||
cf586b61 FW |
5304 | old_userobj = trace_flags & TRACE_ITER_SYM_USEROBJ; |
5305 | ||
b54d3de9 TE |
5306 | /* don't look at user memory in panic mode */ |
5307 | trace_flags &= ~TRACE_ITER_SYM_USEROBJ; | |
5308 | ||
cecbca96 FW |
5309 | switch (oops_dump_mode) { |
5310 | case DUMP_ALL: | |
ae3b5093 | 5311 | iter.cpu_file = RING_BUFFER_ALL_CPUS; |
cecbca96 FW |
5312 | break; |
5313 | case DUMP_ORIG: | |
5314 | iter.cpu_file = raw_smp_processor_id(); | |
5315 | break; | |
5316 | case DUMP_NONE: | |
5317 | goto out_enable; | |
5318 | default: | |
5319 | printk(KERN_TRACE "Bad dumping mode, switching to all CPUs dump\n"); | |
ae3b5093 | 5320 | iter.cpu_file = RING_BUFFER_ALL_CPUS; |
cecbca96 FW |
5321 | } |
5322 | ||
5323 | printk(KERN_TRACE "Dumping ftrace buffer:\n"); | |
3f5a54e3 SR |
5324 | |
5325 | /* | |
5326 | * We need to stop all tracing on all CPUS to read the | |
5327 | * the next buffer. This is a bit expensive, but is | |
5328 | * not done often. We fill all what we can read, | |
5329 | * and then release the locks again. | |
5330 | */ | |
5331 | ||
3f5a54e3 SR |
5332 | while (!trace_empty(&iter)) { |
5333 | ||
5334 | if (!cnt) | |
5335 | printk(KERN_TRACE "---------------------------------\n"); | |
5336 | ||
5337 | cnt++; | |
5338 | ||
5339 | /* reset all but tr, trace, and overruns */ | |
5340 | memset(&iter.seq, 0, | |
5341 | sizeof(struct trace_iterator) - | |
5342 | offsetof(struct trace_iterator, seq)); | |
5343 | iter.iter_flags |= TRACE_FILE_LAT_FMT; | |
5344 | iter.pos = -1; | |
5345 | ||
955b61e5 | 5346 | if (trace_find_next_entry_inc(&iter) != NULL) { |
74e7ff8c LJ |
5347 | int ret; |
5348 | ||
5349 | ret = print_trace_line(&iter); | |
5350 | if (ret != TRACE_TYPE_NO_CONSUME) | |
5351 | trace_consume(&iter); | |
3f5a54e3 | 5352 | } |
b892e5c8 | 5353 | touch_nmi_watchdog(); |
3f5a54e3 SR |
5354 | |
5355 | trace_printk_seq(&iter.seq); | |
5356 | } | |
5357 | ||
5358 | if (!cnt) | |
5359 | printk(KERN_TRACE " (ftrace buffer empty)\n"); | |
5360 | else | |
5361 | printk(KERN_TRACE "---------------------------------\n"); | |
5362 | ||
cecbca96 | 5363 | out_enable: |
cf586b61 FW |
5364 | /* Re-enable tracing if requested */ |
5365 | if (!disable_tracing) { | |
5366 | trace_flags |= old_userobj; | |
5367 | ||
5368 | for_each_tracing_cpu(cpu) { | |
955b61e5 | 5369 | atomic_dec(&iter.tr->data[cpu]->disabled); |
cf586b61 FW |
5370 | } |
5371 | tracing_on(); | |
5372 | } | |
5373 | ||
3f5a54e3 | 5374 | out: |
0199c4e6 | 5375 | arch_spin_unlock(&ftrace_dump_lock); |
cd891ae0 | 5376 | local_irq_restore(flags); |
3f5a54e3 SR |
5377 | } |
5378 | ||
cf586b61 | 5379 | /* By default: disable tracing after the dump */ |
cecbca96 | 5380 | void ftrace_dump(enum ftrace_dump_mode oops_dump_mode) |
cf586b61 | 5381 | { |
cecbca96 | 5382 | __ftrace_dump(true, oops_dump_mode); |
cf586b61 | 5383 | } |
a8eecf22 | 5384 | EXPORT_SYMBOL_GPL(ftrace_dump); |
cf586b61 | 5385 | |
3928a8a2 | 5386 | __init static int tracer_alloc_buffers(void) |
bc0c38d1 | 5387 | { |
73c5162a | 5388 | int ring_buf_size; |
750912fa | 5389 | enum ring_buffer_flags rb_flags; |
4c11d7ae | 5390 | int i; |
9e01c1b7 | 5391 | int ret = -ENOMEM; |
4c11d7ae | 5392 | |
750912fa | 5393 | |
9e01c1b7 RR |
5394 | if (!alloc_cpumask_var(&tracing_buffer_mask, GFP_KERNEL)) |
5395 | goto out; | |
5396 | ||
5397 | if (!alloc_cpumask_var(&tracing_cpumask, GFP_KERNEL)) | |
5398 | goto out_free_buffer_mask; | |
4c11d7ae | 5399 | |
07d777fe SR |
5400 | /* Only allocate trace_printk buffers if a trace_printk exists */ |
5401 | if (__stop___trace_bprintk_fmt != __start___trace_bprintk_fmt) | |
81698831 | 5402 | /* Must be called before global_trace.buffer is allocated */ |
07d777fe SR |
5403 | trace_printk_init_buffers(); |
5404 | ||
73c5162a SR |
5405 | /* To save memory, keep the ring buffer size to its minimum */ |
5406 | if (ring_buffer_expanded) | |
5407 | ring_buf_size = trace_buf_size; | |
5408 | else | |
5409 | ring_buf_size = 1; | |
5410 | ||
750912fa DS |
5411 | rb_flags = trace_flags & TRACE_ITER_OVERWRITE ? RB_FL_OVERWRITE : 0; |
5412 | ||
9e01c1b7 RR |
5413 | cpumask_copy(tracing_buffer_mask, cpu_possible_mask); |
5414 | cpumask_copy(tracing_cpumask, cpu_all_mask); | |
5415 | ||
2b6080f2 SR |
5416 | raw_spin_lock_init(&global_trace.start_lock); |
5417 | ||
9e01c1b7 | 5418 | /* TODO: make the number of buffers hot pluggable with CPUS */ |
750912fa | 5419 | global_trace.buffer = ring_buffer_alloc(ring_buf_size, rb_flags); |
3928a8a2 SR |
5420 | if (!global_trace.buffer) { |
5421 | printk(KERN_ERR "tracer: failed to allocate ring buffer!\n"); | |
5422 | WARN_ON(1); | |
9e01c1b7 | 5423 | goto out_free_cpumask; |
4c11d7ae | 5424 | } |
499e5470 SR |
5425 | if (global_trace.buffer_disabled) |
5426 | tracing_off(); | |
4c11d7ae | 5427 | |
9e01c1b7 | 5428 | |
4c11d7ae | 5429 | #ifdef CONFIG_TRACER_MAX_TRACE |
750912fa | 5430 | max_tr.buffer = ring_buffer_alloc(1, rb_flags); |
2b6080f2 | 5431 | raw_spin_lock_init(&max_tr.start_lock); |
3928a8a2 SR |
5432 | if (!max_tr.buffer) { |
5433 | printk(KERN_ERR "tracer: failed to allocate max ring buffer!\n"); | |
5434 | WARN_ON(1); | |
5435 | ring_buffer_free(global_trace.buffer); | |
9e01c1b7 | 5436 | goto out_free_cpumask; |
4c11d7ae | 5437 | } |
a98a3c3f | 5438 | #endif |
ab46428c | 5439 | |
4c11d7ae | 5440 | /* Allocate the first page for all buffers */ |
ab46428c | 5441 | for_each_tracing_cpu(i) { |
566b0aaf | 5442 | global_trace.data[i] = &per_cpu(global_trace_cpu, i); |
2b6080f2 SR |
5443 | global_trace.data[i]->trace_cpu.cpu = i; |
5444 | global_trace.data[i]->trace_cpu.tr = &global_trace; | |
9705f69e | 5445 | max_tr.data[i] = &per_cpu(max_tr_data, i); |
2b6080f2 SR |
5446 | max_tr.data[i]->trace_cpu.cpu = i; |
5447 | max_tr.data[i]->trace_cpu.tr = &max_tr; | |
4c11d7ae | 5448 | } |
438ced17 | 5449 | |
a591c73f VN |
5450 | set_buffer_entries(&global_trace, |
5451 | ring_buffer_size(global_trace.buffer, 0)); | |
438ced17 VN |
5452 | #ifdef CONFIG_TRACER_MAX_TRACE |
5453 | set_buffer_entries(&max_tr, 1); | |
5454 | #endif | |
bc0c38d1 | 5455 | |
bc0c38d1 | 5456 | trace_init_cmdlines(); |
0d5c6e1c | 5457 | init_irq_work(&trace_work_wakeup, trace_wake_up); |
bc0c38d1 | 5458 | |
43a15386 | 5459 | register_tracer(&nop_trace); |
d840f718 | 5460 | |
2b6080f2 SR |
5461 | global_trace.current_trace = &nop_trace; |
5462 | ||
60a11774 SR |
5463 | /* All seems OK, enable tracing */ |
5464 | tracing_disabled = 0; | |
3928a8a2 | 5465 | |
3f5a54e3 SR |
5466 | atomic_notifier_chain_register(&panic_notifier_list, |
5467 | &trace_panic_notifier); | |
5468 | ||
5469 | register_die_notifier(&trace_die_notifier); | |
2fc1dfbe | 5470 | |
ae63b31e SR |
5471 | global_trace.flags = TRACE_ARRAY_FL_GLOBAL; |
5472 | ||
2b6080f2 SR |
5473 | /* Holder for file callbacks */ |
5474 | global_trace.trace_cpu.cpu = RING_BUFFER_ALL_CPUS; | |
5475 | global_trace.trace_cpu.tr = &global_trace; | |
5476 | ||
ae63b31e SR |
5477 | INIT_LIST_HEAD(&global_trace.systems); |
5478 | INIT_LIST_HEAD(&global_trace.events); | |
5479 | list_add(&global_trace.list, &ftrace_trace_arrays); | |
5480 | ||
7bcfaf54 SR |
5481 | while (trace_boot_options) { |
5482 | char *option; | |
5483 | ||
5484 | option = strsep(&trace_boot_options, ","); | |
2b6080f2 | 5485 | trace_set_options(&global_trace, option); |
7bcfaf54 SR |
5486 | } |
5487 | ||
2fc1dfbe | 5488 | return 0; |
3f5a54e3 | 5489 | |
9e01c1b7 RR |
5490 | out_free_cpumask: |
5491 | free_cpumask_var(tracing_cpumask); | |
5492 | out_free_buffer_mask: | |
5493 | free_cpumask_var(tracing_buffer_mask); | |
5494 | out: | |
5495 | return ret; | |
bc0c38d1 | 5496 | } |
b2821ae6 SR |
5497 | |
5498 | __init static int clear_boot_tracer(void) | |
5499 | { | |
5500 | /* | |
5501 | * The default tracer at boot buffer is an init section. | |
5502 | * This function is called in lateinit. If we did not | |
5503 | * find the boot tracer, then clear it out, to prevent | |
5504 | * later registration from accessing the buffer that is | |
5505 | * about to be freed. | |
5506 | */ | |
5507 | if (!default_bootup_tracer) | |
5508 | return 0; | |
5509 | ||
5510 | printk(KERN_INFO "ftrace bootup tracer '%s' not registered.\n", | |
5511 | default_bootup_tracer); | |
5512 | default_bootup_tracer = NULL; | |
5513 | ||
5514 | return 0; | |
5515 | } | |
5516 | ||
b5ad384e FW |
5517 | early_initcall(tracer_alloc_buffers); |
5518 | fs_initcall(tracer_init_debugfs); | |
b2821ae6 | 5519 | late_initcall(clear_boot_tracer); |