diff options
Diffstat (limited to 'kernel/trace/trace.c')
-rw-r--r-- | kernel/trace/trace.c | 408 |
1 files changed, 285 insertions, 123 deletions
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index 0df1b0f2cb9e..086d36316805 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c | |||
@@ -32,10 +32,11 @@ | |||
32 | #include <linux/splice.h> | 32 | #include <linux/splice.h> |
33 | #include <linux/kdebug.h> | 33 | #include <linux/kdebug.h> |
34 | #include <linux/string.h> | 34 | #include <linux/string.h> |
35 | #include <linux/rwsem.h> | ||
36 | #include <linux/slab.h> | ||
35 | #include <linux/ctype.h> | 37 | #include <linux/ctype.h> |
36 | #include <linux/init.h> | 38 | #include <linux/init.h> |
37 | #include <linux/poll.h> | 39 | #include <linux/poll.h> |
38 | #include <linux/gfp.h> | ||
39 | #include <linux/fs.h> | 40 | #include <linux/fs.h> |
40 | 41 | ||
41 | #include "trace.h" | 42 | #include "trace.h" |
@@ -91,20 +92,17 @@ DEFINE_PER_CPU(int, ftrace_cpu_disabled); | |||
91 | static inline void ftrace_disable_cpu(void) | 92 | static inline void ftrace_disable_cpu(void) |
92 | { | 93 | { |
93 | preempt_disable(); | 94 | preempt_disable(); |
94 | __this_cpu_inc(per_cpu_var(ftrace_cpu_disabled)); | 95 | __this_cpu_inc(ftrace_cpu_disabled); |
95 | } | 96 | } |
96 | 97 | ||
97 | static inline void ftrace_enable_cpu(void) | 98 | static inline void ftrace_enable_cpu(void) |
98 | { | 99 | { |
99 | __this_cpu_dec(per_cpu_var(ftrace_cpu_disabled)); | 100 | __this_cpu_dec(ftrace_cpu_disabled); |
100 | preempt_enable(); | 101 | preempt_enable(); |
101 | } | 102 | } |
102 | 103 | ||
103 | static cpumask_var_t __read_mostly tracing_buffer_mask; | 104 | static cpumask_var_t __read_mostly tracing_buffer_mask; |
104 | 105 | ||
105 | /* Define which cpu buffers are currently read in trace_pipe */ | ||
106 | static cpumask_var_t tracing_reader_cpumask; | ||
107 | |||
108 | #define for_each_tracing_cpu(cpu) \ | 106 | #define for_each_tracing_cpu(cpu) \ |
109 | for_each_cpu(cpu, tracing_buffer_mask) | 107 | for_each_cpu(cpu, tracing_buffer_mask) |
110 | 108 | ||
@@ -119,9 +117,12 @@ static cpumask_var_t tracing_reader_cpumask; | |||
119 | * | 117 | * |
120 | * It is default off, but you can enable it with either specifying | 118 | * It is default off, but you can enable it with either specifying |
121 | * "ftrace_dump_on_oops" in the kernel command line, or setting | 119 | * "ftrace_dump_on_oops" in the kernel command line, or setting |
122 | * /proc/sys/kernel/ftrace_dump_on_oops to true. | 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 | ||
123 | */ | 123 | */ |
124 | int ftrace_dump_on_oops; | 124 | |
125 | enum ftrace_dump_mode ftrace_dump_on_oops; | ||
125 | 126 | ||
126 | static int tracing_set_tracer(const char *buf); | 127 | static int tracing_set_tracer(const char *buf); |
127 | 128 | ||
@@ -141,8 +142,17 @@ __setup("ftrace=", set_cmdline_ftrace); | |||
141 | 142 | ||
142 | static int __init set_ftrace_dump_on_oops(char *str) | 143 | static int __init set_ftrace_dump_on_oops(char *str) |
143 | { | 144 | { |
144 | ftrace_dump_on_oops = 1; | 145 | if (*str++ != '=' || !*str) { |
145 | return 1; | 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; | ||
146 | } | 156 | } |
147 | __setup("ftrace_dump_on_oops", set_ftrace_dump_on_oops); | 157 | __setup("ftrace_dump_on_oops", set_ftrace_dump_on_oops); |
148 | 158 | ||
@@ -243,12 +253,91 @@ static struct tracer *current_trace __read_mostly; | |||
243 | 253 | ||
244 | /* | 254 | /* |
245 | * trace_types_lock is used to protect the trace_types list. | 255 | * trace_types_lock is used to protect the trace_types list. |
246 | * This lock is also used to keep user access serialized. | ||
247 | * Accesses from userspace will grab this lock while userspace | ||
248 | * activities happen inside the kernel. | ||
249 | */ | 256 | */ |
250 | static DEFINE_MUTEX(trace_types_lock); | 257 | static DEFINE_MUTEX(trace_types_lock); |
251 | 258 | ||
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 | { | ||
287 | if (cpu == TRACE_PIPE_ALL_CPU) { | ||
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 | |||
293 | /* Firstly block other trace_access_lock(TRACE_PIPE_ALL_CPU). */ | ||
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 | { | ||
303 | if (cpu == TRACE_PIPE_ALL_CPU) { | ||
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 | |||
252 | /* trace_wait is a waitqueue for tasks blocked on trace_poll */ | 341 | /* trace_wait is a waitqueue for tasks blocked on trace_poll */ |
253 | static DECLARE_WAIT_QUEUE_HEAD(trace_wait); | 342 | static DECLARE_WAIT_QUEUE_HEAD(trace_wait); |
254 | 343 | ||
@@ -297,6 +386,21 @@ static int __init set_buf_size(char *str) | |||
297 | } | 386 | } |
298 | __setup("trace_buf_size=", set_buf_size); | 387 | __setup("trace_buf_size=", set_buf_size); |
299 | 388 | ||
389 | static int __init set_tracing_thresh(char *str) | ||
390 | { | ||
391 | unsigned long threshhold; | ||
392 | int ret; | ||
393 | |||
394 | if (!str) | ||
395 | return 0; | ||
396 | ret = strict_strtoul(str, 0, &threshhold); | ||
397 | if (ret < 0) | ||
398 | return 0; | ||
399 | tracing_thresh = threshhold * 1000; | ||
400 | return 1; | ||
401 | } | ||
402 | __setup("tracing_thresh=", set_tracing_thresh); | ||
403 | |||
300 | unsigned long nsecs_to_usecs(unsigned long nsecs) | 404 | unsigned long nsecs_to_usecs(unsigned long nsecs) |
301 | { | 405 | { |
302 | return nsecs / 1000; | 406 | return nsecs / 1000; |
@@ -502,9 +606,10 @@ static ssize_t trace_seq_to_buffer(struct trace_seq *s, void *buf, size_t cnt) | |||
502 | static arch_spinlock_t ftrace_max_lock = | 606 | static arch_spinlock_t ftrace_max_lock = |
503 | (arch_spinlock_t)__ARCH_SPIN_LOCK_UNLOCKED; | 607 | (arch_spinlock_t)__ARCH_SPIN_LOCK_UNLOCKED; |
504 | 608 | ||
609 | unsigned long __read_mostly tracing_thresh; | ||
610 | |||
505 | #ifdef CONFIG_TRACER_MAX_TRACE | 611 | #ifdef CONFIG_TRACER_MAX_TRACE |
506 | unsigned long __read_mostly tracing_max_latency; | 612 | unsigned long __read_mostly tracing_max_latency; |
507 | unsigned long __read_mostly tracing_thresh; | ||
508 | 613 | ||
509 | /* | 614 | /* |
510 | * Copy the new maximum trace into the separate maximum-trace | 615 | * Copy the new maximum trace into the separate maximum-trace |
@@ -515,7 +620,7 @@ static void | |||
515 | __update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu) | 620 | __update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu) |
516 | { | 621 | { |
517 | struct trace_array_cpu *data = tr->data[cpu]; | 622 | struct trace_array_cpu *data = tr->data[cpu]; |
518 | struct trace_array_cpu *max_data = tr->data[cpu]; | 623 | struct trace_array_cpu *max_data; |
519 | 624 | ||
520 | max_tr.cpu = cpu; | 625 | max_tr.cpu = cpu; |
521 | max_tr.time_start = data->preempt_timestamp; | 626 | max_tr.time_start = data->preempt_timestamp; |
@@ -525,7 +630,7 @@ __update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu) | |||
525 | max_data->critical_start = data->critical_start; | 630 | max_data->critical_start = data->critical_start; |
526 | max_data->critical_end = data->critical_end; | 631 | max_data->critical_end = data->critical_end; |
527 | 632 | ||
528 | memcpy(data->comm, tsk->comm, TASK_COMM_LEN); | 633 | memcpy(max_data->comm, tsk->comm, TASK_COMM_LEN); |
529 | max_data->pid = tsk->pid; | 634 | max_data->pid = tsk->pid; |
530 | max_data->uid = task_uid(tsk); | 635 | max_data->uid = task_uid(tsk); |
531 | max_data->nice = tsk->static_prio - 20 - MAX_RT_PRIO; | 636 | max_data->nice = tsk->static_prio - 20 - MAX_RT_PRIO; |
@@ -747,10 +852,10 @@ out: | |||
747 | mutex_unlock(&trace_types_lock); | 852 | mutex_unlock(&trace_types_lock); |
748 | } | 853 | } |
749 | 854 | ||
750 | static void __tracing_reset(struct trace_array *tr, int cpu) | 855 | static void __tracing_reset(struct ring_buffer *buffer, int cpu) |
751 | { | 856 | { |
752 | ftrace_disable_cpu(); | 857 | ftrace_disable_cpu(); |
753 | ring_buffer_reset_cpu(tr->buffer, cpu); | 858 | ring_buffer_reset_cpu(buffer, cpu); |
754 | ftrace_enable_cpu(); | 859 | ftrace_enable_cpu(); |
755 | } | 860 | } |
756 | 861 | ||
@@ -762,7 +867,7 @@ void tracing_reset(struct trace_array *tr, int cpu) | |||
762 | 867 | ||
763 | /* Make sure all commits have finished */ | 868 | /* Make sure all commits have finished */ |
764 | synchronize_sched(); | 869 | synchronize_sched(); |
765 | __tracing_reset(tr, cpu); | 870 | __tracing_reset(buffer, cpu); |
766 | 871 | ||
767 | ring_buffer_record_enable(buffer); | 872 | ring_buffer_record_enable(buffer); |
768 | } | 873 | } |
@@ -780,7 +885,7 @@ void tracing_reset_online_cpus(struct trace_array *tr) | |||
780 | tr->time_start = ftrace_now(tr->cpu); | 885 | tr->time_start = ftrace_now(tr->cpu); |
781 | 886 | ||
782 | for_each_online_cpu(cpu) | 887 | for_each_online_cpu(cpu) |
783 | __tracing_reset(tr, cpu); | 888 | __tracing_reset(buffer, cpu); |
784 | 889 | ||
785 | ring_buffer_record_enable(buffer); | 890 | ring_buffer_record_enable(buffer); |
786 | } | 891 | } |
@@ -857,6 +962,8 @@ void tracing_start(void) | |||
857 | goto out; | 962 | goto out; |
858 | } | 963 | } |
859 | 964 | ||
965 | /* Prevent the buffers from switching */ | ||
966 | arch_spin_lock(&ftrace_max_lock); | ||
860 | 967 | ||
861 | buffer = global_trace.buffer; | 968 | buffer = global_trace.buffer; |
862 | if (buffer) | 969 | if (buffer) |
@@ -866,6 +973,8 @@ void tracing_start(void) | |||
866 | if (buffer) | 973 | if (buffer) |
867 | ring_buffer_record_enable(buffer); | 974 | ring_buffer_record_enable(buffer); |
868 | 975 | ||
976 | arch_spin_unlock(&ftrace_max_lock); | ||
977 | |||
869 | ftrace_start(); | 978 | ftrace_start(); |
870 | out: | 979 | out: |
871 | spin_unlock_irqrestore(&tracing_start_lock, flags); | 980 | spin_unlock_irqrestore(&tracing_start_lock, flags); |
@@ -887,6 +996,9 @@ void tracing_stop(void) | |||
887 | if (trace_stop_count++) | 996 | if (trace_stop_count++) |
888 | goto out; | 997 | goto out; |
889 | 998 | ||
999 | /* Prevent the buffers from switching */ | ||
1000 | arch_spin_lock(&ftrace_max_lock); | ||
1001 | |||
890 | buffer = global_trace.buffer; | 1002 | buffer = global_trace.buffer; |
891 | if (buffer) | 1003 | if (buffer) |
892 | ring_buffer_record_disable(buffer); | 1004 | ring_buffer_record_disable(buffer); |
@@ -895,6 +1007,8 @@ void tracing_stop(void) | |||
895 | if (buffer) | 1007 | if (buffer) |
896 | ring_buffer_record_disable(buffer); | 1008 | ring_buffer_record_disable(buffer); |
897 | 1009 | ||
1010 | arch_spin_unlock(&ftrace_max_lock); | ||
1011 | |||
898 | out: | 1012 | out: |
899 | spin_unlock_irqrestore(&tracing_start_lock, flags); | 1013 | spin_unlock_irqrestore(&tracing_start_lock, flags); |
900 | } | 1014 | } |
@@ -951,6 +1065,11 @@ void trace_find_cmdline(int pid, char comm[]) | |||
951 | return; | 1065 | return; |
952 | } | 1066 | } |
953 | 1067 | ||
1068 | if (WARN_ON_ONCE(pid < 0)) { | ||
1069 | strcpy(comm, "<XXX>"); | ||
1070 | return; | ||
1071 | } | ||
1072 | |||
954 | if (pid > PID_MAX_DEFAULT) { | 1073 | if (pid > PID_MAX_DEFAULT) { |
955 | strcpy(comm, "<...>"); | 1074 | strcpy(comm, "<...>"); |
956 | return; | 1075 | return; |
@@ -1084,7 +1203,7 @@ trace_function(struct trace_array *tr, | |||
1084 | struct ftrace_entry *entry; | 1203 | struct ftrace_entry *entry; |
1085 | 1204 | ||
1086 | /* If we are reading the ring buffer, don't trace */ | 1205 | /* If we are reading the ring buffer, don't trace */ |
1087 | if (unlikely(__this_cpu_read(per_cpu_var(ftrace_cpu_disabled)))) | 1206 | if (unlikely(__this_cpu_read(ftrace_cpu_disabled))) |
1088 | return; | 1207 | return; |
1089 | 1208 | ||
1090 | event = trace_buffer_lock_reserve(buffer, TRACE_FN, sizeof(*entry), | 1209 | event = trace_buffer_lock_reserve(buffer, TRACE_FN, sizeof(*entry), |
@@ -1177,6 +1296,13 @@ ftrace_trace_userstack(struct ring_buffer *buffer, unsigned long flags, int pc) | |||
1177 | if (!(trace_flags & TRACE_ITER_USERSTACKTRACE)) | 1296 | if (!(trace_flags & TRACE_ITER_USERSTACKTRACE)) |
1178 | return; | 1297 | return; |
1179 | 1298 | ||
1299 | /* | ||
1300 | * NMIs can not handle page faults, even with fix ups. | ||
1301 | * The save user stack can (and often does) fault. | ||
1302 | */ | ||
1303 | if (unlikely(in_nmi())) | ||
1304 | return; | ||
1305 | |||
1180 | event = trace_buffer_lock_reserve(buffer, TRACE_USER_STACK, | 1306 | event = trace_buffer_lock_reserve(buffer, TRACE_USER_STACK, |
1181 | sizeof(*entry), flags, pc); | 1307 | sizeof(*entry), flags, pc); |
1182 | if (!event) | 1308 | if (!event) |
@@ -1315,8 +1441,10 @@ int trace_vbprintk(unsigned long ip, const char *fmt, va_list args) | |||
1315 | entry->fmt = fmt; | 1441 | entry->fmt = fmt; |
1316 | 1442 | ||
1317 | memcpy(entry->buf, trace_buf, sizeof(u32) * len); | 1443 | memcpy(entry->buf, trace_buf, sizeof(u32) * len); |
1318 | if (!filter_check_discard(call, entry, buffer, event)) | 1444 | if (!filter_check_discard(call, entry, buffer, event)) { |
1319 | ring_buffer_unlock_commit(buffer, event); | 1445 | ring_buffer_unlock_commit(buffer, event); |
1446 | ftrace_trace_stack(buffer, flags, 6, pc); | ||
1447 | } | ||
1320 | 1448 | ||
1321 | out_unlock: | 1449 | out_unlock: |
1322 | arch_spin_unlock(&trace_buf_lock); | 1450 | arch_spin_unlock(&trace_buf_lock); |
@@ -1389,8 +1517,10 @@ int trace_array_vprintk(struct trace_array *tr, | |||
1389 | 1517 | ||
1390 | memcpy(&entry->buf, trace_buf, len); | 1518 | memcpy(&entry->buf, trace_buf, len); |
1391 | entry->buf[len] = '\0'; | 1519 | entry->buf[len] = '\0'; |
1392 | if (!filter_check_discard(call, entry, buffer, event)) | 1520 | if (!filter_check_discard(call, entry, buffer, event)) { |
1393 | ring_buffer_unlock_commit(buffer, event); | 1521 | ring_buffer_unlock_commit(buffer, event); |
1522 | ftrace_trace_stack(buffer, irq_flags, 6, pc); | ||
1523 | } | ||
1394 | 1524 | ||
1395 | out_unlock: | 1525 | out_unlock: |
1396 | arch_spin_unlock(&trace_buf_lock); | 1526 | arch_spin_unlock(&trace_buf_lock); |
@@ -1427,7 +1557,8 @@ static void trace_iterator_increment(struct trace_iterator *iter) | |||
1427 | } | 1557 | } |
1428 | 1558 | ||
1429 | static struct trace_entry * | 1559 | static struct trace_entry * |
1430 | peek_next_entry(struct trace_iterator *iter, int cpu, u64 *ts) | 1560 | peek_next_entry(struct trace_iterator *iter, int cpu, u64 *ts, |
1561 | unsigned long *lost_events) | ||
1431 | { | 1562 | { |
1432 | struct ring_buffer_event *event; | 1563 | struct ring_buffer_event *event; |
1433 | struct ring_buffer_iter *buf_iter = iter->buffer_iter[cpu]; | 1564 | struct ring_buffer_iter *buf_iter = iter->buffer_iter[cpu]; |
@@ -1438,7 +1569,8 @@ peek_next_entry(struct trace_iterator *iter, int cpu, u64 *ts) | |||
1438 | if (buf_iter) | 1569 | if (buf_iter) |
1439 | event = ring_buffer_iter_peek(buf_iter, ts); | 1570 | event = ring_buffer_iter_peek(buf_iter, ts); |
1440 | else | 1571 | else |
1441 | event = ring_buffer_peek(iter->tr->buffer, cpu, ts); | 1572 | event = ring_buffer_peek(iter->tr->buffer, cpu, ts, |
1573 | lost_events); | ||
1442 | 1574 | ||
1443 | ftrace_enable_cpu(); | 1575 | ftrace_enable_cpu(); |
1444 | 1576 | ||
@@ -1446,10 +1578,12 @@ peek_next_entry(struct trace_iterator *iter, int cpu, u64 *ts) | |||
1446 | } | 1578 | } |
1447 | 1579 | ||
1448 | static struct trace_entry * | 1580 | static struct trace_entry * |
1449 | __find_next_entry(struct trace_iterator *iter, int *ent_cpu, u64 *ent_ts) | 1581 | __find_next_entry(struct trace_iterator *iter, int *ent_cpu, |
1582 | unsigned long *missing_events, u64 *ent_ts) | ||
1450 | { | 1583 | { |
1451 | struct ring_buffer *buffer = iter->tr->buffer; | 1584 | struct ring_buffer *buffer = iter->tr->buffer; |
1452 | struct trace_entry *ent, *next = NULL; | 1585 | struct trace_entry *ent, *next = NULL; |
1586 | unsigned long lost_events = 0, next_lost = 0; | ||
1453 | int cpu_file = iter->cpu_file; | 1587 | int cpu_file = iter->cpu_file; |
1454 | u64 next_ts = 0, ts; | 1588 | u64 next_ts = 0, ts; |
1455 | int next_cpu = -1; | 1589 | int next_cpu = -1; |
@@ -1462,7 +1596,7 @@ __find_next_entry(struct trace_iterator *iter, int *ent_cpu, u64 *ent_ts) | |||
1462 | if (cpu_file > TRACE_PIPE_ALL_CPU) { | 1596 | if (cpu_file > TRACE_PIPE_ALL_CPU) { |
1463 | if (ring_buffer_empty_cpu(buffer, cpu_file)) | 1597 | if (ring_buffer_empty_cpu(buffer, cpu_file)) |
1464 | return NULL; | 1598 | return NULL; |
1465 | ent = peek_next_entry(iter, cpu_file, ent_ts); | 1599 | ent = peek_next_entry(iter, cpu_file, ent_ts, missing_events); |
1466 | if (ent_cpu) | 1600 | if (ent_cpu) |
1467 | *ent_cpu = cpu_file; | 1601 | *ent_cpu = cpu_file; |
1468 | 1602 | ||
@@ -1474,7 +1608,7 @@ __find_next_entry(struct trace_iterator *iter, int *ent_cpu, u64 *ent_ts) | |||
1474 | if (ring_buffer_empty_cpu(buffer, cpu)) | 1608 | if (ring_buffer_empty_cpu(buffer, cpu)) |
1475 | continue; | 1609 | continue; |
1476 | 1610 | ||
1477 | ent = peek_next_entry(iter, cpu, &ts); | 1611 | ent = peek_next_entry(iter, cpu, &ts, &lost_events); |
1478 | 1612 | ||
1479 | /* | 1613 | /* |
1480 | * Pick the entry with the smallest timestamp: | 1614 | * Pick the entry with the smallest timestamp: |
@@ -1483,6 +1617,7 @@ __find_next_entry(struct trace_iterator *iter, int *ent_cpu, u64 *ent_ts) | |||
1483 | next = ent; | 1617 | next = ent; |
1484 | next_cpu = cpu; | 1618 | next_cpu = cpu; |
1485 | next_ts = ts; | 1619 | next_ts = ts; |
1620 | next_lost = lost_events; | ||
1486 | } | 1621 | } |
1487 | } | 1622 | } |
1488 | 1623 | ||
@@ -1492,6 +1627,9 @@ __find_next_entry(struct trace_iterator *iter, int *ent_cpu, u64 *ent_ts) | |||
1492 | if (ent_ts) | 1627 | if (ent_ts) |
1493 | *ent_ts = next_ts; | 1628 | *ent_ts = next_ts; |
1494 | 1629 | ||
1630 | if (missing_events) | ||
1631 | *missing_events = next_lost; | ||
1632 | |||
1495 | return next; | 1633 | return next; |
1496 | } | 1634 | } |
1497 | 1635 | ||
@@ -1499,13 +1637,14 @@ __find_next_entry(struct trace_iterator *iter, int *ent_cpu, u64 *ent_ts) | |||
1499 | struct trace_entry *trace_find_next_entry(struct trace_iterator *iter, | 1637 | struct trace_entry *trace_find_next_entry(struct trace_iterator *iter, |
1500 | int *ent_cpu, u64 *ent_ts) | 1638 | int *ent_cpu, u64 *ent_ts) |
1501 | { | 1639 | { |
1502 | return __find_next_entry(iter, ent_cpu, ent_ts); | 1640 | return __find_next_entry(iter, ent_cpu, NULL, ent_ts); |
1503 | } | 1641 | } |
1504 | 1642 | ||
1505 | /* Find the next real entry, and increment the iterator to the next entry */ | 1643 | /* Find the next real entry, and increment the iterator to the next entry */ |
1506 | static void *find_next_entry_inc(struct trace_iterator *iter) | 1644 | static void *find_next_entry_inc(struct trace_iterator *iter) |
1507 | { | 1645 | { |
1508 | iter->ent = __find_next_entry(iter, &iter->cpu, &iter->ts); | 1646 | iter->ent = __find_next_entry(iter, &iter->cpu, |
1647 | &iter->lost_events, &iter->ts); | ||
1509 | 1648 | ||
1510 | if (iter->ent) | 1649 | if (iter->ent) |
1511 | trace_iterator_increment(iter); | 1650 | trace_iterator_increment(iter); |
@@ -1517,7 +1656,8 @@ static void trace_consume(struct trace_iterator *iter) | |||
1517 | { | 1656 | { |
1518 | /* Don't allow ftrace to trace into the ring buffers */ | 1657 | /* Don't allow ftrace to trace into the ring buffers */ |
1519 | ftrace_disable_cpu(); | 1658 | ftrace_disable_cpu(); |
1520 | ring_buffer_consume(iter->tr->buffer, iter->cpu, &iter->ts); | 1659 | ring_buffer_consume(iter->tr->buffer, iter->cpu, &iter->ts, |
1660 | &iter->lost_events); | ||
1521 | ftrace_enable_cpu(); | 1661 | ftrace_enable_cpu(); |
1522 | } | 1662 | } |
1523 | 1663 | ||
@@ -1580,12 +1720,6 @@ static void tracing_iter_reset(struct trace_iterator *iter, int cpu) | |||
1580 | } | 1720 | } |
1581 | 1721 | ||
1582 | /* | 1722 | /* |
1583 | * No necessary locking here. The worst thing which can | ||
1584 | * happen is loosing events consumed at the same time | ||
1585 | * by a trace_pipe reader. | ||
1586 | * Other than that, we don't risk to crash the ring buffer | ||
1587 | * because it serializes the readers. | ||
1588 | * | ||
1589 | * The current tracer is copied to avoid a global locking | 1723 | * The current tracer is copied to avoid a global locking |
1590 | * all around. | 1724 | * all around. |
1591 | */ | 1725 | */ |
@@ -1623,6 +1757,7 @@ static void *s_start(struct seq_file *m, loff_t *pos) | |||
1623 | 1757 | ||
1624 | ftrace_enable_cpu(); | 1758 | ftrace_enable_cpu(); |
1625 | 1759 | ||
1760 | iter->leftover = 0; | ||
1626 | for (p = iter; p && l < *pos; p = s_next(m, p, &l)) | 1761 | for (p = iter; p && l < *pos; p = s_next(m, p, &l)) |
1627 | ; | 1762 | ; |
1628 | 1763 | ||
@@ -1640,12 +1775,16 @@ static void *s_start(struct seq_file *m, loff_t *pos) | |||
1640 | } | 1775 | } |
1641 | 1776 | ||
1642 | trace_event_read_lock(); | 1777 | trace_event_read_lock(); |
1778 | trace_access_lock(cpu_file); | ||
1643 | return p; | 1779 | return p; |
1644 | } | 1780 | } |
1645 | 1781 | ||
1646 | static void s_stop(struct seq_file *m, void *p) | 1782 | static void s_stop(struct seq_file *m, void *p) |
1647 | { | 1783 | { |
1784 | struct trace_iterator *iter = m->private; | ||
1785 | |||
1648 | atomic_dec(&trace_record_cmdline_disabled); | 1786 | atomic_dec(&trace_record_cmdline_disabled); |
1787 | trace_access_unlock(iter->cpu_file); | ||
1649 | trace_event_read_unlock(); | 1788 | trace_event_read_unlock(); |
1650 | } | 1789 | } |
1651 | 1790 | ||
@@ -1669,7 +1808,7 @@ static void print_func_help_header(struct seq_file *m) | |||
1669 | } | 1808 | } |
1670 | 1809 | ||
1671 | 1810 | ||
1672 | static void | 1811 | void |
1673 | print_trace_header(struct seq_file *m, struct trace_iterator *iter) | 1812 | print_trace_header(struct seq_file *m, struct trace_iterator *iter) |
1674 | { | 1813 | { |
1675 | unsigned long sym_flags = (trace_flags & TRACE_ITER_SYM_MASK); | 1814 | unsigned long sym_flags = (trace_flags & TRACE_ITER_SYM_MASK); |
@@ -1797,7 +1936,7 @@ static enum print_line_t print_trace_fmt(struct trace_iterator *iter) | |||
1797 | } | 1936 | } |
1798 | 1937 | ||
1799 | if (event) | 1938 | if (event) |
1800 | return event->trace(iter, sym_flags); | 1939 | return event->funcs->trace(iter, sym_flags, event); |
1801 | 1940 | ||
1802 | if (!trace_seq_printf(s, "Unknown type %d\n", entry->type)) | 1941 | if (!trace_seq_printf(s, "Unknown type %d\n", entry->type)) |
1803 | goto partial; | 1942 | goto partial; |
@@ -1823,7 +1962,7 @@ static enum print_line_t print_raw_fmt(struct trace_iterator *iter) | |||
1823 | 1962 | ||
1824 | event = ftrace_find_event(entry->type); | 1963 | event = ftrace_find_event(entry->type); |
1825 | if (event) | 1964 | if (event) |
1826 | return event->raw(iter, 0); | 1965 | return event->funcs->raw(iter, 0, event); |
1827 | 1966 | ||
1828 | if (!trace_seq_printf(s, "%d ?\n", entry->type)) | 1967 | if (!trace_seq_printf(s, "%d ?\n", entry->type)) |
1829 | goto partial; | 1968 | goto partial; |
@@ -1850,7 +1989,7 @@ static enum print_line_t print_hex_fmt(struct trace_iterator *iter) | |||
1850 | 1989 | ||
1851 | event = ftrace_find_event(entry->type); | 1990 | event = ftrace_find_event(entry->type); |
1852 | if (event) { | 1991 | if (event) { |
1853 | enum print_line_t ret = event->hex(iter, 0); | 1992 | enum print_line_t ret = event->funcs->hex(iter, 0, event); |
1854 | if (ret != TRACE_TYPE_HANDLED) | 1993 | if (ret != TRACE_TYPE_HANDLED) |
1855 | return ret; | 1994 | return ret; |
1856 | } | 1995 | } |
@@ -1875,10 +2014,11 @@ static enum print_line_t print_bin_fmt(struct trace_iterator *iter) | |||
1875 | } | 2014 | } |
1876 | 2015 | ||
1877 | event = ftrace_find_event(entry->type); | 2016 | event = ftrace_find_event(entry->type); |
1878 | return event ? event->binary(iter, 0) : TRACE_TYPE_HANDLED; | 2017 | return event ? event->funcs->binary(iter, 0, event) : |
2018 | TRACE_TYPE_HANDLED; | ||
1879 | } | 2019 | } |
1880 | 2020 | ||
1881 | static int trace_empty(struct trace_iterator *iter) | 2021 | int trace_empty(struct trace_iterator *iter) |
1882 | { | 2022 | { |
1883 | int cpu; | 2023 | int cpu; |
1884 | 2024 | ||
@@ -1913,6 +2053,10 @@ static enum print_line_t print_trace_line(struct trace_iterator *iter) | |||
1913 | { | 2053 | { |
1914 | enum print_line_t ret; | 2054 | enum print_line_t ret; |
1915 | 2055 | ||
2056 | if (iter->lost_events) | ||
2057 | trace_seq_printf(&iter->seq, "CPU:%d [LOST %lu EVENTS]\n", | ||
2058 | iter->cpu, iter->lost_events); | ||
2059 | |||
1916 | if (iter->trace && iter->trace->print_line) { | 2060 | if (iter->trace && iter->trace->print_line) { |
1917 | ret = iter->trace->print_line(iter); | 2061 | ret = iter->trace->print_line(iter); |
1918 | if (ret != TRACE_TYPE_UNHANDLED) | 2062 | if (ret != TRACE_TYPE_UNHANDLED) |
@@ -1941,6 +2085,23 @@ static enum print_line_t print_trace_line(struct trace_iterator *iter) | |||
1941 | return print_trace_fmt(iter); | 2085 | return print_trace_fmt(iter); |
1942 | } | 2086 | } |
1943 | 2087 | ||
2088 | void trace_default_header(struct seq_file *m) | ||
2089 | { | ||
2090 | struct trace_iterator *iter = m->private; | ||
2091 | |||
2092 | if (iter->iter_flags & TRACE_FILE_LAT_FMT) { | ||
2093 | /* print nothing if the buffers are empty */ | ||
2094 | if (trace_empty(iter)) | ||
2095 | return; | ||
2096 | print_trace_header(m, iter); | ||
2097 | if (!(trace_flags & TRACE_ITER_VERBOSE)) | ||
2098 | print_lat_help_header(m); | ||
2099 | } else { | ||
2100 | if (!(trace_flags & TRACE_ITER_VERBOSE)) | ||
2101 | print_func_help_header(m); | ||
2102 | } | ||
2103 | } | ||
2104 | |||
1944 | static int s_show(struct seq_file *m, void *v) | 2105 | static int s_show(struct seq_file *m, void *v) |
1945 | { | 2106 | { |
1946 | struct trace_iterator *iter = v; | 2107 | struct trace_iterator *iter = v; |
@@ -1953,17 +2114,9 @@ static int s_show(struct seq_file *m, void *v) | |||
1953 | } | 2114 | } |
1954 | if (iter->trace && iter->trace->print_header) | 2115 | if (iter->trace && iter->trace->print_header) |
1955 | iter->trace->print_header(m); | 2116 | iter->trace->print_header(m); |
1956 | else if (iter->iter_flags & TRACE_FILE_LAT_FMT) { | 2117 | else |
1957 | /* print nothing if the buffers are empty */ | 2118 | trace_default_header(m); |
1958 | if (trace_empty(iter)) | 2119 | |
1959 | return 0; | ||
1960 | print_trace_header(m, iter); | ||
1961 | if (!(trace_flags & TRACE_ITER_VERBOSE)) | ||
1962 | print_lat_help_header(m); | ||
1963 | } else { | ||
1964 | if (!(trace_flags & TRACE_ITER_VERBOSE)) | ||
1965 | print_func_help_header(m); | ||
1966 | } | ||
1967 | } else if (iter->leftover) { | 2120 | } else if (iter->leftover) { |
1968 | /* | 2121 | /* |
1969 | * If we filled the seq_file buffer earlier, we | 2122 | * If we filled the seq_file buffer earlier, we |
@@ -2049,15 +2202,20 @@ __tracing_open(struct inode *inode, struct file *file) | |||
2049 | 2202 | ||
2050 | if (iter->cpu_file == TRACE_PIPE_ALL_CPU) { | 2203 | if (iter->cpu_file == TRACE_PIPE_ALL_CPU) { |
2051 | for_each_tracing_cpu(cpu) { | 2204 | for_each_tracing_cpu(cpu) { |
2052 | |||
2053 | iter->buffer_iter[cpu] = | 2205 | iter->buffer_iter[cpu] = |
2054 | ring_buffer_read_start(iter->tr->buffer, cpu); | 2206 | ring_buffer_read_prepare(iter->tr->buffer, cpu); |
2207 | } | ||
2208 | ring_buffer_read_prepare_sync(); | ||
2209 | for_each_tracing_cpu(cpu) { | ||
2210 | ring_buffer_read_start(iter->buffer_iter[cpu]); | ||
2055 | tracing_iter_reset(iter, cpu); | 2211 | tracing_iter_reset(iter, cpu); |
2056 | } | 2212 | } |
2057 | } else { | 2213 | } else { |
2058 | cpu = iter->cpu_file; | 2214 | cpu = iter->cpu_file; |
2059 | iter->buffer_iter[cpu] = | 2215 | iter->buffer_iter[cpu] = |
2060 | ring_buffer_read_start(iter->tr->buffer, cpu); | 2216 | ring_buffer_read_prepare(iter->tr->buffer, cpu); |
2217 | ring_buffer_read_prepare_sync(); | ||
2218 | ring_buffer_read_start(iter->buffer_iter[cpu]); | ||
2061 | tracing_iter_reset(iter, cpu); | 2219 | tracing_iter_reset(iter, cpu); |
2062 | } | 2220 | } |
2063 | 2221 | ||
@@ -2836,22 +2994,6 @@ static int tracing_open_pipe(struct inode *inode, struct file *filp) | |||
2836 | 2994 | ||
2837 | mutex_lock(&trace_types_lock); | 2995 | mutex_lock(&trace_types_lock); |
2838 | 2996 | ||
2839 | /* We only allow one reader per cpu */ | ||
2840 | if (cpu_file == TRACE_PIPE_ALL_CPU) { | ||
2841 | if (!cpumask_empty(tracing_reader_cpumask)) { | ||
2842 | ret = -EBUSY; | ||
2843 | goto out; | ||
2844 | } | ||
2845 | cpumask_setall(tracing_reader_cpumask); | ||
2846 | } else { | ||
2847 | if (!cpumask_test_cpu(cpu_file, tracing_reader_cpumask)) | ||
2848 | cpumask_set_cpu(cpu_file, tracing_reader_cpumask); | ||
2849 | else { | ||
2850 | ret = -EBUSY; | ||
2851 | goto out; | ||
2852 | } | ||
2853 | } | ||
2854 | |||
2855 | /* create a buffer to store the information to pass to userspace */ | 2997 | /* create a buffer to store the information to pass to userspace */ |
2856 | iter = kzalloc(sizeof(*iter), GFP_KERNEL); | 2998 | iter = kzalloc(sizeof(*iter), GFP_KERNEL); |
2857 | if (!iter) { | 2999 | if (!iter) { |
@@ -2907,12 +3049,6 @@ static int tracing_release_pipe(struct inode *inode, struct file *file) | |||
2907 | 3049 | ||
2908 | mutex_lock(&trace_types_lock); | 3050 | mutex_lock(&trace_types_lock); |
2909 | 3051 | ||
2910 | if (iter->cpu_file == TRACE_PIPE_ALL_CPU) | ||
2911 | cpumask_clear(tracing_reader_cpumask); | ||
2912 | else | ||
2913 | cpumask_clear_cpu(iter->cpu_file, tracing_reader_cpumask); | ||
2914 | |||
2915 | |||
2916 | if (iter->trace->pipe_close) | 3052 | if (iter->trace->pipe_close) |
2917 | iter->trace->pipe_close(iter); | 3053 | iter->trace->pipe_close(iter); |
2918 | 3054 | ||
@@ -3074,6 +3210,7 @@ waitagain: | |||
3074 | iter->pos = -1; | 3210 | iter->pos = -1; |
3075 | 3211 | ||
3076 | trace_event_read_lock(); | 3212 | trace_event_read_lock(); |
3213 | trace_access_lock(iter->cpu_file); | ||
3077 | while (find_next_entry_inc(iter) != NULL) { | 3214 | while (find_next_entry_inc(iter) != NULL) { |
3078 | enum print_line_t ret; | 3215 | enum print_line_t ret; |
3079 | int len = iter->seq.len; | 3216 | int len = iter->seq.len; |
@@ -3090,6 +3227,7 @@ waitagain: | |||
3090 | if (iter->seq.len >= cnt) | 3227 | if (iter->seq.len >= cnt) |
3091 | break; | 3228 | break; |
3092 | } | 3229 | } |
3230 | trace_access_unlock(iter->cpu_file); | ||
3093 | trace_event_read_unlock(); | 3231 | trace_event_read_unlock(); |
3094 | 3232 | ||
3095 | /* Now copy what we have to the user */ | 3233 | /* Now copy what we have to the user */ |
@@ -3172,12 +3310,12 @@ static ssize_t tracing_splice_read_pipe(struct file *filp, | |||
3172 | size_t len, | 3310 | size_t len, |
3173 | unsigned int flags) | 3311 | unsigned int flags) |
3174 | { | 3312 | { |
3175 | struct page *pages[PIPE_BUFFERS]; | 3313 | struct page *pages_def[PIPE_DEF_BUFFERS]; |
3176 | struct partial_page partial[PIPE_BUFFERS]; | 3314 | struct partial_page partial_def[PIPE_DEF_BUFFERS]; |
3177 | struct trace_iterator *iter = filp->private_data; | 3315 | struct trace_iterator *iter = filp->private_data; |
3178 | struct splice_pipe_desc spd = { | 3316 | struct splice_pipe_desc spd = { |
3179 | .pages = pages, | 3317 | .pages = pages_def, |
3180 | .partial = partial, | 3318 | .partial = partial_def, |
3181 | .nr_pages = 0, /* This gets updated below. */ | 3319 | .nr_pages = 0, /* This gets updated below. */ |
3182 | .flags = flags, | 3320 | .flags = flags, |
3183 | .ops = &tracing_pipe_buf_ops, | 3321 | .ops = &tracing_pipe_buf_ops, |
@@ -3188,6 +3326,9 @@ static ssize_t tracing_splice_read_pipe(struct file *filp, | |||
3188 | size_t rem; | 3326 | size_t rem; |
3189 | unsigned int i; | 3327 | unsigned int i; |
3190 | 3328 | ||
3329 | if (splice_grow_spd(pipe, &spd)) | ||
3330 | return -ENOMEM; | ||
3331 | |||
3191 | /* copy the tracer to avoid using a global lock all around */ | 3332 | /* copy the tracer to avoid using a global lock all around */ |
3192 | mutex_lock(&trace_types_lock); | 3333 | mutex_lock(&trace_types_lock); |
3193 | if (unlikely(old_tracer != current_trace && current_trace)) { | 3334 | if (unlikely(old_tracer != current_trace && current_trace)) { |
@@ -3215,40 +3356,44 @@ static ssize_t tracing_splice_read_pipe(struct file *filp, | |||
3215 | } | 3356 | } |
3216 | 3357 | ||
3217 | trace_event_read_lock(); | 3358 | trace_event_read_lock(); |
3359 | trace_access_lock(iter->cpu_file); | ||
3218 | 3360 | ||
3219 | /* Fill as many pages as possible. */ | 3361 | /* Fill as many pages as possible. */ |
3220 | for (i = 0, rem = len; i < PIPE_BUFFERS && rem; i++) { | 3362 | for (i = 0, rem = len; i < pipe->buffers && rem; i++) { |
3221 | pages[i] = alloc_page(GFP_KERNEL); | 3363 | spd.pages[i] = alloc_page(GFP_KERNEL); |
3222 | if (!pages[i]) | 3364 | if (!spd.pages[i]) |
3223 | break; | 3365 | break; |
3224 | 3366 | ||
3225 | rem = tracing_fill_pipe_page(rem, iter); | 3367 | rem = tracing_fill_pipe_page(rem, iter); |
3226 | 3368 | ||
3227 | /* Copy the data into the page, so we can start over. */ | 3369 | /* Copy the data into the page, so we can start over. */ |
3228 | ret = trace_seq_to_buffer(&iter->seq, | 3370 | ret = trace_seq_to_buffer(&iter->seq, |
3229 | page_address(pages[i]), | 3371 | page_address(spd.pages[i]), |
3230 | iter->seq.len); | 3372 | iter->seq.len); |
3231 | if (ret < 0) { | 3373 | if (ret < 0) { |
3232 | __free_page(pages[i]); | 3374 | __free_page(spd.pages[i]); |
3233 | break; | 3375 | break; |
3234 | } | 3376 | } |
3235 | partial[i].offset = 0; | 3377 | spd.partial[i].offset = 0; |
3236 | partial[i].len = iter->seq.len; | 3378 | spd.partial[i].len = iter->seq.len; |
3237 | 3379 | ||
3238 | trace_seq_init(&iter->seq); | 3380 | trace_seq_init(&iter->seq); |
3239 | } | 3381 | } |
3240 | 3382 | ||
3383 | trace_access_unlock(iter->cpu_file); | ||
3241 | trace_event_read_unlock(); | 3384 | trace_event_read_unlock(); |
3242 | mutex_unlock(&iter->mutex); | 3385 | mutex_unlock(&iter->mutex); |
3243 | 3386 | ||
3244 | spd.nr_pages = i; | 3387 | spd.nr_pages = i; |
3245 | 3388 | ||
3246 | return splice_to_pipe(pipe, &spd); | 3389 | ret = splice_to_pipe(pipe, &spd); |
3390 | out: | ||
3391 | splice_shrink_spd(pipe, &spd); | ||
3392 | return ret; | ||
3247 | 3393 | ||
3248 | out_err: | 3394 | out_err: |
3249 | mutex_unlock(&iter->mutex); | 3395 | mutex_unlock(&iter->mutex); |
3250 | 3396 | goto out; | |
3251 | return ret; | ||
3252 | } | 3397 | } |
3253 | 3398 | ||
3254 | static ssize_t | 3399 | static ssize_t |
@@ -3521,7 +3666,6 @@ tracing_buffers_read(struct file *filp, char __user *ubuf, | |||
3521 | size_t count, loff_t *ppos) | 3666 | size_t count, loff_t *ppos) |
3522 | { | 3667 | { |
3523 | struct ftrace_buffer_info *info = filp->private_data; | 3668 | struct ftrace_buffer_info *info = filp->private_data; |
3524 | unsigned int pos; | ||
3525 | ssize_t ret; | 3669 | ssize_t ret; |
3526 | size_t size; | 3670 | size_t size; |
3527 | 3671 | ||
@@ -3539,18 +3683,15 @@ tracing_buffers_read(struct file *filp, char __user *ubuf, | |||
3539 | 3683 | ||
3540 | info->read = 0; | 3684 | info->read = 0; |
3541 | 3685 | ||
3686 | trace_access_lock(info->cpu); | ||
3542 | ret = ring_buffer_read_page(info->tr->buffer, | 3687 | ret = ring_buffer_read_page(info->tr->buffer, |
3543 | &info->spare, | 3688 | &info->spare, |
3544 | count, | 3689 | count, |
3545 | info->cpu, 0); | 3690 | info->cpu, 0); |
3691 | trace_access_unlock(info->cpu); | ||
3546 | if (ret < 0) | 3692 | if (ret < 0) |
3547 | return 0; | 3693 | return 0; |
3548 | 3694 | ||
3549 | pos = ring_buffer_page_len(info->spare); | ||
3550 | |||
3551 | if (pos < PAGE_SIZE) | ||
3552 | memset(info->spare + pos, 0, PAGE_SIZE - pos); | ||
3553 | |||
3554 | read: | 3695 | read: |
3555 | size = PAGE_SIZE - info->read; | 3696 | size = PAGE_SIZE - info->read; |
3556 | if (size > count) | 3697 | if (size > count) |
@@ -3645,11 +3786,11 @@ tracing_buffers_splice_read(struct file *file, loff_t *ppos, | |||
3645 | unsigned int flags) | 3786 | unsigned int flags) |
3646 | { | 3787 | { |
3647 | struct ftrace_buffer_info *info = file->private_data; | 3788 | struct ftrace_buffer_info *info = file->private_data; |
3648 | struct partial_page partial[PIPE_BUFFERS]; | 3789 | struct partial_page partial_def[PIPE_DEF_BUFFERS]; |
3649 | struct page *pages[PIPE_BUFFERS]; | 3790 | struct page *pages_def[PIPE_DEF_BUFFERS]; |
3650 | struct splice_pipe_desc spd = { | 3791 | struct splice_pipe_desc spd = { |
3651 | .pages = pages, | 3792 | .pages = pages_def, |
3652 | .partial = partial, | 3793 | .partial = partial_def, |
3653 | .flags = flags, | 3794 | .flags = flags, |
3654 | .ops = &buffer_pipe_buf_ops, | 3795 | .ops = &buffer_pipe_buf_ops, |
3655 | .spd_release = buffer_spd_release, | 3796 | .spd_release = buffer_spd_release, |
@@ -3658,21 +3799,28 @@ tracing_buffers_splice_read(struct file *file, loff_t *ppos, | |||
3658 | int entries, size, i; | 3799 | int entries, size, i; |
3659 | size_t ret; | 3800 | size_t ret; |
3660 | 3801 | ||
3802 | if (splice_grow_spd(pipe, &spd)) | ||
3803 | return -ENOMEM; | ||
3804 | |||
3661 | if (*ppos & (PAGE_SIZE - 1)) { | 3805 | if (*ppos & (PAGE_SIZE - 1)) { |
3662 | WARN_ONCE(1, "Ftrace: previous read must page-align\n"); | 3806 | WARN_ONCE(1, "Ftrace: previous read must page-align\n"); |
3663 | return -EINVAL; | 3807 | ret = -EINVAL; |
3808 | goto out; | ||
3664 | } | 3809 | } |
3665 | 3810 | ||
3666 | if (len & (PAGE_SIZE - 1)) { | 3811 | if (len & (PAGE_SIZE - 1)) { |
3667 | WARN_ONCE(1, "Ftrace: splice_read should page-align\n"); | 3812 | WARN_ONCE(1, "Ftrace: splice_read should page-align\n"); |
3668 | if (len < PAGE_SIZE) | 3813 | if (len < PAGE_SIZE) { |
3669 | return -EINVAL; | 3814 | ret = -EINVAL; |
3815 | goto out; | ||
3816 | } | ||
3670 | len &= PAGE_MASK; | 3817 | len &= PAGE_MASK; |
3671 | } | 3818 | } |
3672 | 3819 | ||
3820 | trace_access_lock(info->cpu); | ||
3673 | entries = ring_buffer_entries_cpu(info->tr->buffer, info->cpu); | 3821 | entries = ring_buffer_entries_cpu(info->tr->buffer, info->cpu); |
3674 | 3822 | ||
3675 | for (i = 0; i < PIPE_BUFFERS && len && entries; i++, len -= PAGE_SIZE) { | 3823 | for (i = 0; i < pipe->buffers && len && entries; i++, len -= PAGE_SIZE) { |
3676 | struct page *page; | 3824 | struct page *page; |
3677 | int r; | 3825 | int r; |
3678 | 3826 | ||
@@ -3717,6 +3865,7 @@ tracing_buffers_splice_read(struct file *file, loff_t *ppos, | |||
3717 | entries = ring_buffer_entries_cpu(info->tr->buffer, info->cpu); | 3865 | entries = ring_buffer_entries_cpu(info->tr->buffer, info->cpu); |
3718 | } | 3866 | } |
3719 | 3867 | ||
3868 | trace_access_unlock(info->cpu); | ||
3720 | spd.nr_pages = i; | 3869 | spd.nr_pages = i; |
3721 | 3870 | ||
3722 | /* did we read anything? */ | 3871 | /* did we read anything? */ |
@@ -3726,11 +3875,12 @@ tracing_buffers_splice_read(struct file *file, loff_t *ppos, | |||
3726 | else | 3875 | else |
3727 | ret = 0; | 3876 | ret = 0; |
3728 | /* TODO: block */ | 3877 | /* TODO: block */ |
3729 | return ret; | 3878 | goto out; |
3730 | } | 3879 | } |
3731 | 3880 | ||
3732 | ret = splice_to_pipe(pipe, &spd); | 3881 | ret = splice_to_pipe(pipe, &spd); |
3733 | 3882 | splice_shrink_spd(pipe, &spd); | |
3883 | out: | ||
3734 | return ret; | 3884 | return ret; |
3735 | } | 3885 | } |
3736 | 3886 | ||
@@ -4153,6 +4303,8 @@ static __init int tracer_init_debugfs(void) | |||
4153 | struct dentry *d_tracer; | 4303 | struct dentry *d_tracer; |
4154 | int cpu; | 4304 | int cpu; |
4155 | 4305 | ||
4306 | trace_access_lock_init(); | ||
4307 | |||
4156 | d_tracer = tracing_init_dentry(); | 4308 | d_tracer = tracing_init_dentry(); |
4157 | 4309 | ||
4158 | trace_create_file("tracing_enabled", 0644, d_tracer, | 4310 | trace_create_file("tracing_enabled", 0644, d_tracer, |
@@ -4176,10 +4328,10 @@ static __init int tracer_init_debugfs(void) | |||
4176 | #ifdef CONFIG_TRACER_MAX_TRACE | 4328 | #ifdef CONFIG_TRACER_MAX_TRACE |
4177 | trace_create_file("tracing_max_latency", 0644, d_tracer, | 4329 | trace_create_file("tracing_max_latency", 0644, d_tracer, |
4178 | &tracing_max_latency, &tracing_max_lat_fops); | 4330 | &tracing_max_latency, &tracing_max_lat_fops); |
4331 | #endif | ||
4179 | 4332 | ||
4180 | trace_create_file("tracing_thresh", 0644, d_tracer, | 4333 | trace_create_file("tracing_thresh", 0644, d_tracer, |
4181 | &tracing_thresh, &tracing_max_lat_fops); | 4334 | &tracing_thresh, &tracing_max_lat_fops); |
4182 | #endif | ||
4183 | 4335 | ||
4184 | trace_create_file("README", 0444, d_tracer, | 4336 | trace_create_file("README", 0444, d_tracer, |
4185 | NULL, &tracing_readme_fops); | 4337 | NULL, &tracing_readme_fops); |
@@ -4219,7 +4371,7 @@ static int trace_panic_handler(struct notifier_block *this, | |||
4219 | unsigned long event, void *unused) | 4371 | unsigned long event, void *unused) |
4220 | { | 4372 | { |
4221 | if (ftrace_dump_on_oops) | 4373 | if (ftrace_dump_on_oops) |
4222 | ftrace_dump(); | 4374 | ftrace_dump(ftrace_dump_on_oops); |
4223 | return NOTIFY_OK; | 4375 | return NOTIFY_OK; |
4224 | } | 4376 | } |
4225 | 4377 | ||
@@ -4236,7 +4388,7 @@ static int trace_die_handler(struct notifier_block *self, | |||
4236 | switch (val) { | 4388 | switch (val) { |
4237 | case DIE_OOPS: | 4389 | case DIE_OOPS: |
4238 | if (ftrace_dump_on_oops) | 4390 | if (ftrace_dump_on_oops) |
4239 | ftrace_dump(); | 4391 | ftrace_dump(ftrace_dump_on_oops); |
4240 | break; | 4392 | break; |
4241 | default: | 4393 | default: |
4242 | break; | 4394 | break; |
@@ -4277,7 +4429,8 @@ trace_printk_seq(struct trace_seq *s) | |||
4277 | trace_seq_init(s); | 4429 | trace_seq_init(s); |
4278 | } | 4430 | } |
4279 | 4431 | ||
4280 | static void __ftrace_dump(bool disable_tracing) | 4432 | static void |
4433 | __ftrace_dump(bool disable_tracing, enum ftrace_dump_mode oops_dump_mode) | ||
4281 | { | 4434 | { |
4282 | static arch_spinlock_t ftrace_dump_lock = | 4435 | static arch_spinlock_t ftrace_dump_lock = |
4283 | (arch_spinlock_t)__ARCH_SPIN_LOCK_UNLOCKED; | 4436 | (arch_spinlock_t)__ARCH_SPIN_LOCK_UNLOCKED; |
@@ -4310,12 +4463,25 @@ static void __ftrace_dump(bool disable_tracing) | |||
4310 | /* don't look at user memory in panic mode */ | 4463 | /* don't look at user memory in panic mode */ |
4311 | trace_flags &= ~TRACE_ITER_SYM_USEROBJ; | 4464 | trace_flags &= ~TRACE_ITER_SYM_USEROBJ; |
4312 | 4465 | ||
4313 | printk(KERN_TRACE "Dumping ftrace buffer:\n"); | ||
4314 | |||
4315 | /* Simulate the iterator */ | 4466 | /* Simulate the iterator */ |
4316 | iter.tr = &global_trace; | 4467 | iter.tr = &global_trace; |
4317 | iter.trace = current_trace; | 4468 | iter.trace = current_trace; |
4318 | iter.cpu_file = TRACE_PIPE_ALL_CPU; | 4469 | |
4470 | switch (oops_dump_mode) { | ||
4471 | case DUMP_ALL: | ||
4472 | iter.cpu_file = TRACE_PIPE_ALL_CPU; | ||
4473 | break; | ||
4474 | case DUMP_ORIG: | ||
4475 | iter.cpu_file = raw_smp_processor_id(); | ||
4476 | break; | ||
4477 | case DUMP_NONE: | ||
4478 | goto out_enable; | ||
4479 | default: | ||
4480 | printk(KERN_TRACE "Bad dumping mode, switching to all CPUs dump\n"); | ||
4481 | iter.cpu_file = TRACE_PIPE_ALL_CPU; | ||
4482 | } | ||
4483 | |||
4484 | printk(KERN_TRACE "Dumping ftrace buffer:\n"); | ||
4319 | 4485 | ||
4320 | /* | 4486 | /* |
4321 | * We need to stop all tracing on all CPUS to read the | 4487 | * We need to stop all tracing on all CPUS to read the |
@@ -4354,6 +4520,7 @@ static void __ftrace_dump(bool disable_tracing) | |||
4354 | else | 4520 | else |
4355 | printk(KERN_TRACE "---------------------------------\n"); | 4521 | printk(KERN_TRACE "---------------------------------\n"); |
4356 | 4522 | ||
4523 | out_enable: | ||
4357 | /* Re-enable tracing if requested */ | 4524 | /* Re-enable tracing if requested */ |
4358 | if (!disable_tracing) { | 4525 | if (!disable_tracing) { |
4359 | trace_flags |= old_userobj; | 4526 | trace_flags |= old_userobj; |
@@ -4370,9 +4537,9 @@ static void __ftrace_dump(bool disable_tracing) | |||
4370 | } | 4537 | } |
4371 | 4538 | ||
4372 | /* By default: disable tracing after the dump */ | 4539 | /* By default: disable tracing after the dump */ |
4373 | void ftrace_dump(void) | 4540 | void ftrace_dump(enum ftrace_dump_mode oops_dump_mode) |
4374 | { | 4541 | { |
4375 | __ftrace_dump(true); | 4542 | __ftrace_dump(true, oops_dump_mode); |
4376 | } | 4543 | } |
4377 | 4544 | ||
4378 | __init static int tracer_alloc_buffers(void) | 4545 | __init static int tracer_alloc_buffers(void) |
@@ -4387,9 +4554,6 @@ __init static int tracer_alloc_buffers(void) | |||
4387 | if (!alloc_cpumask_var(&tracing_cpumask, GFP_KERNEL)) | 4554 | if (!alloc_cpumask_var(&tracing_cpumask, GFP_KERNEL)) |
4388 | goto out_free_buffer_mask; | 4555 | goto out_free_buffer_mask; |
4389 | 4556 | ||
4390 | if (!zalloc_cpumask_var(&tracing_reader_cpumask, GFP_KERNEL)) | ||
4391 | goto out_free_tracing_cpumask; | ||
4392 | |||
4393 | /* To save memory, keep the ring buffer size to its minimum */ | 4557 | /* To save memory, keep the ring buffer size to its minimum */ |
4394 | if (ring_buffer_expanded) | 4558 | if (ring_buffer_expanded) |
4395 | ring_buf_size = trace_buf_size; | 4559 | ring_buf_size = trace_buf_size; |
@@ -4447,8 +4611,6 @@ __init static int tracer_alloc_buffers(void) | |||
4447 | return 0; | 4611 | return 0; |
4448 | 4612 | ||
4449 | out_free_cpumask: | 4613 | out_free_cpumask: |
4450 | free_cpumask_var(tracing_reader_cpumask); | ||
4451 | out_free_tracing_cpumask: | ||
4452 | free_cpumask_var(tracing_cpumask); | 4614 | free_cpumask_var(tracing_cpumask); |
4453 | out_free_buffer_mask: | 4615 | out_free_buffer_mask: |
4454 | free_cpumask_var(tracing_buffer_mask); | 4616 | free_cpumask_var(tracing_buffer_mask); |