Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1 | /* |
| 2 | * ring buffer based function tracer |
| 3 | * |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4 | * Copyright (C) 2007-2012 Steven Rostedt <srostedt@redhat.com> |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 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 |
Nadia Yvette Chambers | 6d49e35 | 2012-12-06 10:39:54 +0100 | [diff] [blame] | 12 | * Copyright (C) 2004 Nadia Yvette Chambers |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 13 | */ |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 14 | #include <linux/ring_buffer.h> |
Sam Ravnborg | 273b281 | 2009-10-18 00:52:28 +0200 | [diff] [blame] | 15 | #include <generated/utsrelease.h> |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 16 | #include <linux/stacktrace.h> |
| 17 | #include <linux/writeback.h> |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 18 | #include <linux/kallsyms.h> |
| 19 | #include <linux/seq_file.h> |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 20 | #include <linux/notifier.h> |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 21 | #include <linux/irqflags.h> |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 22 | #include <linux/debugfs.h> |
Steven Rostedt | 4c11d7a | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 23 | #include <linux/pagemap.h> |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 24 | #include <linux/hardirq.h> |
| 25 | #include <linux/linkage.h> |
| 26 | #include <linux/uaccess.h> |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 27 | #include <linux/kprobes.h> |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 28 | #include <linux/ftrace.h> |
| 29 | #include <linux/module.h> |
| 30 | #include <linux/percpu.h> |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 31 | #include <linux/splice.h> |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 32 | #include <linux/kdebug.h> |
Frederic Weisbecker | 5f0c6c0 | 2009-03-27 14:22:10 +0100 | [diff] [blame] | 33 | #include <linux/string.h> |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 34 | #include <linux/rwsem.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 35 | #include <linux/slab.h> |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 36 | #include <linux/ctype.h> |
| 37 | #include <linux/init.h> |
Soeren Sandmann Pedersen | 2a2cc8f | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 38 | #include <linux/poll.h> |
Steven Rostedt | b892e5c | 2012-03-01 22:06:48 -0500 | [diff] [blame] | 39 | #include <linux/nmi.h> |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 40 | #include <linux/fs.h> |
Clark Williams | 8bd75c7 | 2013-02-07 09:47:07 -0600 | [diff] [blame] | 41 | #include <linux/sched/rt.h> |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 42 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 43 | #include "trace.h" |
Steven Rostedt | f0868d1 | 2008-12-23 23:24:12 -0500 | [diff] [blame] | 44 | #include "trace_output.h" |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 45 | |
Frederic Weisbecker | 8e1b82e | 2008-12-06 03:41:33 +0100 | [diff] [blame] | 46 | /* |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 47 | * On boot up, the ring buffer is set to the minimum size, so that |
| 48 | * we do not waste memory on systems that are not using tracing. |
| 49 | */ |
Steven Rostedt (Red Hat) | 55034cd | 2013-03-07 22:48:09 -0500 | [diff] [blame] | 50 | bool ring_buffer_expanded; |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 51 | |
| 52 | /* |
Frederic Weisbecker | 8e1b82e | 2008-12-06 03:41:33 +0100 | [diff] [blame] | 53 | * We need to change this state when a selftest is running. |
Frederic Weisbecker | ff32504 | 2008-12-04 23:47:35 +0100 | [diff] [blame] | 54 | * A selftest will lurk into the ring-buffer to count the |
| 55 | * entries inserted during the selftest although some concurrent |
Ingo Molnar | 5e1607a | 2009-03-05 10:24:48 +0100 | [diff] [blame] | 56 | * insertions into the ring-buffer such as trace_printk could occurred |
Frederic Weisbecker | ff32504 | 2008-12-04 23:47:35 +0100 | [diff] [blame] | 57 | * at the same time, giving false positive or negative results. |
| 58 | */ |
Frederic Weisbecker | 8e1b82e | 2008-12-06 03:41:33 +0100 | [diff] [blame] | 59 | static bool __read_mostly tracing_selftest_running; |
Frederic Weisbecker | ff32504 | 2008-12-04 23:47:35 +0100 | [diff] [blame] | 60 | |
Steven Rostedt | b2821ae | 2009-02-02 21:38:32 -0500 | [diff] [blame] | 61 | /* |
| 62 | * If a tracer is running, we do not want to run SELFTEST. |
| 63 | */ |
Li Zefan | 020e5f8 | 2009-07-01 10:47:05 +0800 | [diff] [blame] | 64 | bool __read_mostly tracing_selftest_disabled; |
Steven Rostedt | b2821ae | 2009-02-02 21:38:32 -0500 | [diff] [blame] | 65 | |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 66 | /* For tracers that don't implement custom flags */ |
| 67 | static struct tracer_opt dummy_tracer_opt[] = { |
| 68 | { } |
| 69 | }; |
| 70 | |
| 71 | static struct tracer_flags dummy_tracer_flags = { |
| 72 | .val = 0, |
| 73 | .opts = dummy_tracer_opt |
| 74 | }; |
| 75 | |
| 76 | static int dummy_set_flag(u32 old_flags, u32 bit, int set) |
| 77 | { |
| 78 | return 0; |
| 79 | } |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 80 | |
| 81 | /* |
Steven Rostedt | 7ffbd48 | 2012-10-11 12:14:25 -0400 | [diff] [blame] | 82 | * To prevent the comm cache from being overwritten when no |
| 83 | * tracing is active, only save the comm when a trace event |
| 84 | * occurred. |
| 85 | */ |
| 86 | static DEFINE_PER_CPU(bool, trace_cmdline_save); |
| 87 | |
| 88 | /* |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 89 | * Kill all tracing for good (never come back). |
| 90 | * It is initialized to 1 but will turn to zero if the initialization |
| 91 | * of the tracer is successful. But that is the only place that sets |
| 92 | * this back to zero. |
| 93 | */ |
Hannes Eder | 4fd2735 | 2009-02-10 19:44:12 +0100 | [diff] [blame] | 94 | static int tracing_disabled = 1; |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 95 | |
Christoph Lameter | 9288f99 | 2009-10-07 19:17:45 -0400 | [diff] [blame] | 96 | DEFINE_PER_CPU(int, ftrace_cpu_disabled); |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 97 | |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 98 | cpumask_var_t __read_mostly tracing_buffer_mask; |
Steven Rostedt | ab46428 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 99 | |
Steven Rostedt | 944ac42 | 2008-10-23 19:26:08 -0400 | [diff] [blame] | 100 | /* |
| 101 | * ftrace_dump_on_oops - variable to dump ftrace buffer on oops |
| 102 | * |
| 103 | * If there is an oops (or kernel panic) and the ftrace_dump_on_oops |
| 104 | * is set, then ftrace_dump is called. This will output the contents |
| 105 | * of the ftrace buffers to the console. This is very useful for |
| 106 | * capturing traces that lead to crashes and outputing it to a |
| 107 | * serial console. |
| 108 | * |
| 109 | * It is default off, but you can enable it with either specifying |
| 110 | * "ftrace_dump_on_oops" in the kernel command line, or setting |
Frederic Weisbecker | cecbca9 | 2010-04-18 19:08:41 +0200 | [diff] [blame] | 111 | * /proc/sys/kernel/ftrace_dump_on_oops |
| 112 | * Set 1 if you want to dump buffers of all CPUs |
| 113 | * Set 2 if you want to dump the buffer of the CPU that triggered oops |
Steven Rostedt | 944ac42 | 2008-10-23 19:26:08 -0400 | [diff] [blame] | 114 | */ |
Frederic Weisbecker | cecbca9 | 2010-04-18 19:08:41 +0200 | [diff] [blame] | 115 | |
| 116 | enum ftrace_dump_mode ftrace_dump_on_oops; |
Steven Rostedt | 944ac42 | 2008-10-23 19:26:08 -0400 | [diff] [blame] | 117 | |
Steven Rostedt | b2821ae | 2009-02-02 21:38:32 -0500 | [diff] [blame] | 118 | static int tracing_set_tracer(const char *buf); |
| 119 | |
Li Zefan | ee6c2c1 | 2009-09-18 14:06:47 +0800 | [diff] [blame] | 120 | #define MAX_TRACER_SIZE 100 |
| 121 | static char bootup_tracer_buf[MAX_TRACER_SIZE] __initdata; |
Steven Rostedt | b2821ae | 2009-02-02 21:38:32 -0500 | [diff] [blame] | 122 | static char *default_bootup_tracer; |
Peter Zijlstra | d9e5407 | 2008-11-01 19:57:37 +0100 | [diff] [blame] | 123 | |
Steven Rostedt (Red Hat) | 55034cd | 2013-03-07 22:48:09 -0500 | [diff] [blame] | 124 | static bool allocate_snapshot; |
| 125 | |
Frederic Weisbecker | 1beee96 | 2009-10-14 20:50:32 +0200 | [diff] [blame] | 126 | static int __init set_cmdline_ftrace(char *str) |
Peter Zijlstra | d9e5407 | 2008-11-01 19:57:37 +0100 | [diff] [blame] | 127 | { |
Chen Gang | 67012ab | 2013-04-08 12:06:44 +0800 | [diff] [blame] | 128 | strlcpy(bootup_tracer_buf, str, MAX_TRACER_SIZE); |
Steven Rostedt | b2821ae | 2009-02-02 21:38:32 -0500 | [diff] [blame] | 129 | default_bootup_tracer = bootup_tracer_buf; |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 130 | /* We are using ftrace early, expand it */ |
Steven Rostedt (Red Hat) | 55034cd | 2013-03-07 22:48:09 -0500 | [diff] [blame] | 131 | ring_buffer_expanded = true; |
Peter Zijlstra | d9e5407 | 2008-11-01 19:57:37 +0100 | [diff] [blame] | 132 | return 1; |
| 133 | } |
Frederic Weisbecker | 1beee96 | 2009-10-14 20:50:32 +0200 | [diff] [blame] | 134 | __setup("ftrace=", set_cmdline_ftrace); |
Peter Zijlstra | d9e5407 | 2008-11-01 19:57:37 +0100 | [diff] [blame] | 135 | |
Steven Rostedt | 944ac42 | 2008-10-23 19:26:08 -0400 | [diff] [blame] | 136 | static int __init set_ftrace_dump_on_oops(char *str) |
| 137 | { |
Frederic Weisbecker | cecbca9 | 2010-04-18 19:08:41 +0200 | [diff] [blame] | 138 | if (*str++ != '=' || !*str) { |
| 139 | ftrace_dump_on_oops = DUMP_ALL; |
| 140 | return 1; |
| 141 | } |
| 142 | |
| 143 | if (!strcmp("orig_cpu", str)) { |
| 144 | ftrace_dump_on_oops = DUMP_ORIG; |
| 145 | return 1; |
| 146 | } |
| 147 | |
| 148 | return 0; |
Steven Rostedt | 944ac42 | 2008-10-23 19:26:08 -0400 | [diff] [blame] | 149 | } |
| 150 | __setup("ftrace_dump_on_oops", set_ftrace_dump_on_oops); |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 151 | |
Steven Rostedt (Red Hat) | 3209cff | 2013-03-12 11:17:54 -0400 | [diff] [blame] | 152 | static int __init boot_alloc_snapshot(char *str) |
Steven Rostedt (Red Hat) | 55034cd | 2013-03-07 22:48:09 -0500 | [diff] [blame] | 153 | { |
| 154 | allocate_snapshot = true; |
| 155 | /* We also need the main ring buffer expanded */ |
| 156 | ring_buffer_expanded = true; |
| 157 | return 1; |
| 158 | } |
Steven Rostedt (Red Hat) | 3209cff | 2013-03-12 11:17:54 -0400 | [diff] [blame] | 159 | __setup("alloc_snapshot", boot_alloc_snapshot); |
Steven Rostedt (Red Hat) | 55034cd | 2013-03-07 22:48:09 -0500 | [diff] [blame] | 160 | |
Steven Rostedt | 7bcfaf5 | 2012-11-01 22:56:07 -0400 | [diff] [blame] | 161 | |
| 162 | static char trace_boot_options_buf[MAX_TRACER_SIZE] __initdata; |
| 163 | static char *trace_boot_options __initdata; |
| 164 | |
| 165 | static int __init set_trace_boot_options(char *str) |
| 166 | { |
Chen Gang | 67012ab | 2013-04-08 12:06:44 +0800 | [diff] [blame] | 167 | strlcpy(trace_boot_options_buf, str, MAX_TRACER_SIZE); |
Steven Rostedt | 7bcfaf5 | 2012-11-01 22:56:07 -0400 | [diff] [blame] | 168 | trace_boot_options = trace_boot_options_buf; |
| 169 | return 0; |
| 170 | } |
| 171 | __setup("trace_options=", set_trace_boot_options); |
| 172 | |
Lai Jiangshan | cf8e347 | 2009-03-30 13:48:00 +0800 | [diff] [blame] | 173 | unsigned long long ns2usecs(cycle_t nsec) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 174 | { |
| 175 | nsec += 500; |
| 176 | do_div(nsec, 1000); |
| 177 | return nsec; |
| 178 | } |
| 179 | |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 180 | /* |
| 181 | * The global_trace is the descriptor that holds the tracing |
| 182 | * buffers for the live tracing. For each CPU, it contains |
| 183 | * a link list of pages that will store trace entries. The |
| 184 | * page descriptor of the pages in the memory is used to hold |
| 185 | * the link list by linking the lru item in the page descriptor |
| 186 | * to each of the pages in the buffer per CPU. |
| 187 | * |
| 188 | * For each active CPU there is a data field that holds the |
| 189 | * pages for the buffer for that CPU. Each CPU has the same number |
| 190 | * of pages allocated for its buffer. |
| 191 | */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 192 | static struct trace_array global_trace; |
| 193 | |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 194 | LIST_HEAD(ftrace_trace_arrays); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 195 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 196 | int filter_current_check_discard(struct ring_buffer *buffer, |
| 197 | struct ftrace_event_call *call, void *rec, |
Tom Zanussi | eb02ce0 | 2009-04-08 03:15:54 -0500 | [diff] [blame] | 198 | struct ring_buffer_event *event) |
| 199 | { |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 200 | return filter_check_discard(call, rec, buffer, event); |
Tom Zanussi | eb02ce0 | 2009-04-08 03:15:54 -0500 | [diff] [blame] | 201 | } |
Steven Rostedt | 17c873e | 2009-04-10 18:12:50 -0400 | [diff] [blame] | 202 | EXPORT_SYMBOL_GPL(filter_current_check_discard); |
Tom Zanussi | eb02ce0 | 2009-04-08 03:15:54 -0500 | [diff] [blame] | 203 | |
Steven Rostedt | 37886f6 | 2009-03-17 17:22:06 -0400 | [diff] [blame] | 204 | cycle_t ftrace_now(int cpu) |
| 205 | { |
| 206 | u64 ts; |
| 207 | |
| 208 | /* Early boot up does not have a buffer yet */ |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 209 | if (!global_trace.trace_buffer.buffer) |
Steven Rostedt | 37886f6 | 2009-03-17 17:22:06 -0400 | [diff] [blame] | 210 | return trace_clock_local(); |
| 211 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 212 | ts = ring_buffer_time_stamp(global_trace.trace_buffer.buffer, cpu); |
| 213 | ring_buffer_normalize_time_stamp(global_trace.trace_buffer.buffer, cpu, &ts); |
Steven Rostedt | 37886f6 | 2009-03-17 17:22:06 -0400 | [diff] [blame] | 214 | |
| 215 | return ts; |
| 216 | } |
| 217 | |
Steven Rostedt | 9036990 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 218 | int tracing_is_enabled(void) |
| 219 | { |
Steven Rostedt | 0fb9656 | 2012-05-11 14:25:30 -0400 | [diff] [blame] | 220 | return tracing_is_on(); |
Steven Rostedt | 9036990 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 221 | } |
| 222 | |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 223 | /* |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 224 | * trace_buf_size is the size in bytes that is allocated |
| 225 | * for a buffer. Note, the number of bytes is always rounded |
| 226 | * to page size. |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 227 | * |
| 228 | * This number is purposely set to a low number of 16384. |
| 229 | * If the dump on oops happens, it will be much appreciated |
| 230 | * to not have to wait for all that output. Anyway this can be |
| 231 | * boot time and run time configurable. |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 232 | */ |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 233 | #define TRACE_BUF_SIZE_DEFAULT 1441792UL /* 16384 * 88 (sizeof(entry)) */ |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 234 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 235 | static unsigned long trace_buf_size = TRACE_BUF_SIZE_DEFAULT; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 236 | |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 237 | /* trace_types holds a link list of available tracers. */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 238 | static struct tracer *trace_types __read_mostly; |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 239 | |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 240 | /* |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 241 | * trace_types_lock is used to protect the trace_types list. |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 242 | */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 243 | static DEFINE_MUTEX(trace_types_lock); |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 244 | |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 245 | /* |
| 246 | * serialize the access of the ring buffer |
| 247 | * |
| 248 | * ring buffer serializes readers, but it is low level protection. |
| 249 | * The validity of the events (which returns by ring_buffer_peek() ..etc) |
| 250 | * are not protected by ring buffer. |
| 251 | * |
| 252 | * The content of events may become garbage if we allow other process consumes |
| 253 | * these events concurrently: |
| 254 | * A) the page of the consumed events may become a normal page |
| 255 | * (not reader page) in ring buffer, and this page will be rewrited |
| 256 | * by events producer. |
| 257 | * B) The page of the consumed events may become a page for splice_read, |
| 258 | * and this page will be returned to system. |
| 259 | * |
| 260 | * These primitives allow multi process access to different cpu ring buffer |
| 261 | * concurrently. |
| 262 | * |
| 263 | * These primitives don't distinguish read-only and read-consume access. |
| 264 | * Multi read-only access are also serialized. |
| 265 | */ |
| 266 | |
| 267 | #ifdef CONFIG_SMP |
| 268 | static DECLARE_RWSEM(all_cpu_access_lock); |
| 269 | static DEFINE_PER_CPU(struct mutex, cpu_access_lock); |
| 270 | |
| 271 | static inline void trace_access_lock(int cpu) |
| 272 | { |
Steven Rostedt | ae3b509 | 2013-01-23 15:22:59 -0500 | [diff] [blame] | 273 | if (cpu == RING_BUFFER_ALL_CPUS) { |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 274 | /* gain it for accessing the whole ring buffer. */ |
| 275 | down_write(&all_cpu_access_lock); |
| 276 | } else { |
| 277 | /* gain it for accessing a cpu ring buffer. */ |
| 278 | |
Steven Rostedt | ae3b509 | 2013-01-23 15:22:59 -0500 | [diff] [blame] | 279 | /* Firstly block other trace_access_lock(RING_BUFFER_ALL_CPUS). */ |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 280 | down_read(&all_cpu_access_lock); |
| 281 | |
| 282 | /* Secondly block other access to this @cpu ring buffer. */ |
| 283 | mutex_lock(&per_cpu(cpu_access_lock, cpu)); |
| 284 | } |
| 285 | } |
| 286 | |
| 287 | static inline void trace_access_unlock(int cpu) |
| 288 | { |
Steven Rostedt | ae3b509 | 2013-01-23 15:22:59 -0500 | [diff] [blame] | 289 | if (cpu == RING_BUFFER_ALL_CPUS) { |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 290 | up_write(&all_cpu_access_lock); |
| 291 | } else { |
| 292 | mutex_unlock(&per_cpu(cpu_access_lock, cpu)); |
| 293 | up_read(&all_cpu_access_lock); |
| 294 | } |
| 295 | } |
| 296 | |
| 297 | static inline void trace_access_lock_init(void) |
| 298 | { |
| 299 | int cpu; |
| 300 | |
| 301 | for_each_possible_cpu(cpu) |
| 302 | mutex_init(&per_cpu(cpu_access_lock, cpu)); |
| 303 | } |
| 304 | |
| 305 | #else |
| 306 | |
| 307 | static DEFINE_MUTEX(access_lock); |
| 308 | |
| 309 | static inline void trace_access_lock(int cpu) |
| 310 | { |
| 311 | (void)cpu; |
| 312 | mutex_lock(&access_lock); |
| 313 | } |
| 314 | |
| 315 | static inline void trace_access_unlock(int cpu) |
| 316 | { |
| 317 | (void)cpu; |
| 318 | mutex_unlock(&access_lock); |
| 319 | } |
| 320 | |
| 321 | static inline void trace_access_lock_init(void) |
| 322 | { |
| 323 | } |
| 324 | |
| 325 | #endif |
| 326 | |
Steven Rostedt | ee6bce5 | 2008-11-12 17:52:37 -0500 | [diff] [blame] | 327 | /* trace_flags holds trace_options default values */ |
Steven Rostedt | 12ef7d4 | 2008-11-12 17:52:38 -0500 | [diff] [blame] | 328 | unsigned long trace_flags = TRACE_ITER_PRINT_PARENT | TRACE_ITER_PRINTK | |
Steven Rostedt | a2a16d6 | 2009-03-24 23:17:58 -0400 | [diff] [blame] | 329 | TRACE_ITER_ANNOTATE | TRACE_ITER_CONTEXT_INFO | TRACE_ITER_SLEEP_TIME | |
Steven Rostedt | 77271ce | 2011-11-17 09:34:33 -0500 | [diff] [blame] | 330 | TRACE_ITER_GRAPH_TIME | TRACE_ITER_RECORD_CMD | TRACE_ITER_OVERWRITE | |
Steven Rostedt (Red Hat) | 328df47 | 2013-03-14 12:10:40 -0400 | [diff] [blame] | 331 | TRACE_ITER_IRQ_INFO | TRACE_ITER_MARKERS | TRACE_ITER_FUNCTION; |
Vaibhav Nagarnaik | e7e2ee8 | 2011-05-10 13:27:21 -0700 | [diff] [blame] | 332 | |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 333 | /** |
Steven Rostedt | 499e547 | 2012-02-22 15:50:28 -0500 | [diff] [blame] | 334 | * tracing_on - enable tracing buffers |
| 335 | * |
| 336 | * This function enables tracing buffers that may have been |
| 337 | * disabled with tracing_off. |
| 338 | */ |
| 339 | void tracing_on(void) |
| 340 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 341 | if (global_trace.trace_buffer.buffer) |
| 342 | ring_buffer_record_on(global_trace.trace_buffer.buffer); |
Steven Rostedt | 499e547 | 2012-02-22 15:50:28 -0500 | [diff] [blame] | 343 | /* |
| 344 | * This flag is only looked at when buffers haven't been |
| 345 | * allocated yet. We don't really care about the race |
| 346 | * between setting this flag and actually turning |
| 347 | * on the buffer. |
| 348 | */ |
| 349 | global_trace.buffer_disabled = 0; |
| 350 | } |
| 351 | EXPORT_SYMBOL_GPL(tracing_on); |
| 352 | |
| 353 | /** |
Steven Rostedt (Red Hat) | 09ae723 | 2013-03-08 21:02:34 -0500 | [diff] [blame] | 354 | * __trace_puts - write a constant string into the trace buffer. |
| 355 | * @ip: The address of the caller |
| 356 | * @str: The constant string to write |
| 357 | * @size: The size of the string. |
| 358 | */ |
| 359 | int __trace_puts(unsigned long ip, const char *str, int size) |
| 360 | { |
| 361 | struct ring_buffer_event *event; |
| 362 | struct ring_buffer *buffer; |
| 363 | struct print_entry *entry; |
| 364 | unsigned long irq_flags; |
| 365 | int alloc; |
| 366 | |
| 367 | alloc = sizeof(*entry) + size + 2; /* possible \n added */ |
| 368 | |
| 369 | local_save_flags(irq_flags); |
| 370 | buffer = global_trace.trace_buffer.buffer; |
| 371 | event = trace_buffer_lock_reserve(buffer, TRACE_PRINT, alloc, |
| 372 | irq_flags, preempt_count()); |
| 373 | if (!event) |
| 374 | return 0; |
| 375 | |
| 376 | entry = ring_buffer_event_data(event); |
| 377 | entry->ip = ip; |
| 378 | |
| 379 | memcpy(&entry->buf, str, size); |
| 380 | |
| 381 | /* Add a newline if necessary */ |
| 382 | if (entry->buf[size - 1] != '\n') { |
| 383 | entry->buf[size] = '\n'; |
| 384 | entry->buf[size + 1] = '\0'; |
| 385 | } else |
| 386 | entry->buf[size] = '\0'; |
| 387 | |
| 388 | __buffer_unlock_commit(buffer, event); |
| 389 | |
| 390 | return size; |
| 391 | } |
| 392 | EXPORT_SYMBOL_GPL(__trace_puts); |
| 393 | |
| 394 | /** |
| 395 | * __trace_bputs - write the pointer to a constant string into trace buffer |
| 396 | * @ip: The address of the caller |
| 397 | * @str: The constant string to write to the buffer to |
| 398 | */ |
| 399 | int __trace_bputs(unsigned long ip, const char *str) |
| 400 | { |
| 401 | struct ring_buffer_event *event; |
| 402 | struct ring_buffer *buffer; |
| 403 | struct bputs_entry *entry; |
| 404 | unsigned long irq_flags; |
| 405 | int size = sizeof(struct bputs_entry); |
| 406 | |
| 407 | local_save_flags(irq_flags); |
| 408 | buffer = global_trace.trace_buffer.buffer; |
| 409 | event = trace_buffer_lock_reserve(buffer, TRACE_BPUTS, size, |
| 410 | irq_flags, preempt_count()); |
| 411 | if (!event) |
| 412 | return 0; |
| 413 | |
| 414 | entry = ring_buffer_event_data(event); |
| 415 | entry->ip = ip; |
| 416 | entry->str = str; |
| 417 | |
| 418 | __buffer_unlock_commit(buffer, event); |
| 419 | |
| 420 | return 1; |
| 421 | } |
| 422 | EXPORT_SYMBOL_GPL(__trace_bputs); |
| 423 | |
Steven Rostedt (Red Hat) | ad909e2 | 2013-03-06 21:45:37 -0500 | [diff] [blame] | 424 | #ifdef CONFIG_TRACER_SNAPSHOT |
| 425 | /** |
| 426 | * trace_snapshot - take a snapshot of the current buffer. |
| 427 | * |
| 428 | * This causes a swap between the snapshot buffer and the current live |
| 429 | * tracing buffer. You can use this to take snapshots of the live |
| 430 | * trace when some condition is triggered, but continue to trace. |
| 431 | * |
| 432 | * Note, make sure to allocate the snapshot with either |
| 433 | * a tracing_snapshot_alloc(), or by doing it manually |
| 434 | * with: echo 1 > /sys/kernel/debug/tracing/snapshot |
| 435 | * |
| 436 | * If the snapshot buffer is not allocated, it will stop tracing. |
| 437 | * Basically making a permanent snapshot. |
| 438 | */ |
| 439 | void tracing_snapshot(void) |
| 440 | { |
| 441 | struct trace_array *tr = &global_trace; |
| 442 | struct tracer *tracer = tr->current_trace; |
| 443 | unsigned long flags; |
| 444 | |
Steven Rostedt (Red Hat) | 1b22e38 | 2013-03-09 00:56:08 -0500 | [diff] [blame] | 445 | if (in_nmi()) { |
| 446 | internal_trace_puts("*** SNAPSHOT CALLED FROM NMI CONTEXT ***\n"); |
| 447 | internal_trace_puts("*** snapshot is being ignored ***\n"); |
| 448 | return; |
| 449 | } |
| 450 | |
Steven Rostedt (Red Hat) | ad909e2 | 2013-03-06 21:45:37 -0500 | [diff] [blame] | 451 | if (!tr->allocated_snapshot) { |
Steven Rostedt (Red Hat) | ca268da | 2013-03-09 00:40:58 -0500 | [diff] [blame] | 452 | internal_trace_puts("*** SNAPSHOT NOT ALLOCATED ***\n"); |
| 453 | internal_trace_puts("*** stopping trace here! ***\n"); |
Steven Rostedt (Red Hat) | ad909e2 | 2013-03-06 21:45:37 -0500 | [diff] [blame] | 454 | tracing_off(); |
| 455 | return; |
| 456 | } |
| 457 | |
| 458 | /* Note, snapshot can not be used when the tracer uses it */ |
| 459 | if (tracer->use_max_tr) { |
Steven Rostedt (Red Hat) | ca268da | 2013-03-09 00:40:58 -0500 | [diff] [blame] | 460 | internal_trace_puts("*** LATENCY TRACER ACTIVE ***\n"); |
| 461 | internal_trace_puts("*** Can not use snapshot (sorry) ***\n"); |
Steven Rostedt (Red Hat) | ad909e2 | 2013-03-06 21:45:37 -0500 | [diff] [blame] | 462 | return; |
| 463 | } |
| 464 | |
| 465 | local_irq_save(flags); |
| 466 | update_max_tr(tr, current, smp_processor_id()); |
| 467 | local_irq_restore(flags); |
| 468 | } |
Steven Rostedt (Red Hat) | 1b22e38 | 2013-03-09 00:56:08 -0500 | [diff] [blame] | 469 | EXPORT_SYMBOL_GPL(tracing_snapshot); |
Steven Rostedt (Red Hat) | ad909e2 | 2013-03-06 21:45:37 -0500 | [diff] [blame] | 470 | |
| 471 | static int resize_buffer_duplicate_size(struct trace_buffer *trace_buf, |
| 472 | struct trace_buffer *size_buf, int cpu_id); |
Steven Rostedt (Red Hat) | 3209cff | 2013-03-12 11:17:54 -0400 | [diff] [blame] | 473 | static void set_buffer_entries(struct trace_buffer *buf, unsigned long val); |
| 474 | |
| 475 | static int alloc_snapshot(struct trace_array *tr) |
| 476 | { |
| 477 | int ret; |
| 478 | |
| 479 | if (!tr->allocated_snapshot) { |
| 480 | |
| 481 | /* allocate spare buffer */ |
| 482 | ret = resize_buffer_duplicate_size(&tr->max_buffer, |
| 483 | &tr->trace_buffer, RING_BUFFER_ALL_CPUS); |
| 484 | if (ret < 0) |
| 485 | return ret; |
| 486 | |
| 487 | tr->allocated_snapshot = true; |
| 488 | } |
| 489 | |
| 490 | return 0; |
| 491 | } |
| 492 | |
| 493 | void free_snapshot(struct trace_array *tr) |
| 494 | { |
| 495 | /* |
| 496 | * We don't free the ring buffer. instead, resize it because |
| 497 | * The max_tr ring buffer has some state (e.g. ring->clock) and |
| 498 | * we want preserve it. |
| 499 | */ |
| 500 | ring_buffer_resize(tr->max_buffer.buffer, 1, RING_BUFFER_ALL_CPUS); |
| 501 | set_buffer_entries(&tr->max_buffer, 1); |
| 502 | tracing_reset_online_cpus(&tr->max_buffer); |
| 503 | tr->allocated_snapshot = false; |
| 504 | } |
Steven Rostedt (Red Hat) | ad909e2 | 2013-03-06 21:45:37 -0500 | [diff] [blame] | 505 | |
| 506 | /** |
| 507 | * trace_snapshot_alloc - allocate and take a snapshot of the current buffer. |
| 508 | * |
| 509 | * This is similar to trace_snapshot(), but it will allocate the |
| 510 | * snapshot buffer if it isn't already allocated. Use this only |
| 511 | * where it is safe to sleep, as the allocation may sleep. |
| 512 | * |
| 513 | * This causes a swap between the snapshot buffer and the current live |
| 514 | * tracing buffer. You can use this to take snapshots of the live |
| 515 | * trace when some condition is triggered, but continue to trace. |
| 516 | */ |
| 517 | void tracing_snapshot_alloc(void) |
| 518 | { |
| 519 | struct trace_array *tr = &global_trace; |
| 520 | int ret; |
| 521 | |
Steven Rostedt (Red Hat) | 3209cff | 2013-03-12 11:17:54 -0400 | [diff] [blame] | 522 | ret = alloc_snapshot(tr); |
| 523 | if (WARN_ON(ret < 0)) |
| 524 | return; |
Steven Rostedt (Red Hat) | ad909e2 | 2013-03-06 21:45:37 -0500 | [diff] [blame] | 525 | |
| 526 | tracing_snapshot(); |
| 527 | } |
Steven Rostedt (Red Hat) | 1b22e38 | 2013-03-09 00:56:08 -0500 | [diff] [blame] | 528 | EXPORT_SYMBOL_GPL(tracing_snapshot_alloc); |
Steven Rostedt (Red Hat) | ad909e2 | 2013-03-06 21:45:37 -0500 | [diff] [blame] | 529 | #else |
| 530 | void tracing_snapshot(void) |
| 531 | { |
| 532 | WARN_ONCE(1, "Snapshot feature not enabled, but internal snapshot used"); |
| 533 | } |
Steven Rostedt (Red Hat) | 1b22e38 | 2013-03-09 00:56:08 -0500 | [diff] [blame] | 534 | EXPORT_SYMBOL_GPL(tracing_snapshot); |
Steven Rostedt (Red Hat) | ad909e2 | 2013-03-06 21:45:37 -0500 | [diff] [blame] | 535 | void tracing_snapshot_alloc(void) |
| 536 | { |
| 537 | /* Give warning */ |
| 538 | tracing_snapshot(); |
| 539 | } |
Steven Rostedt (Red Hat) | 1b22e38 | 2013-03-09 00:56:08 -0500 | [diff] [blame] | 540 | EXPORT_SYMBOL_GPL(tracing_snapshot_alloc); |
Steven Rostedt (Red Hat) | ad909e2 | 2013-03-06 21:45:37 -0500 | [diff] [blame] | 541 | #endif /* CONFIG_TRACER_SNAPSHOT */ |
| 542 | |
Steven Rostedt | 499e547 | 2012-02-22 15:50:28 -0500 | [diff] [blame] | 543 | /** |
| 544 | * tracing_off - turn off tracing buffers |
| 545 | * |
| 546 | * This function stops the tracing buffers from recording data. |
| 547 | * It does not disable any overhead the tracers themselves may |
| 548 | * be causing. This function simply causes all recording to |
| 549 | * the ring buffers to fail. |
| 550 | */ |
| 551 | void tracing_off(void) |
| 552 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 553 | if (global_trace.trace_buffer.buffer) |
| 554 | ring_buffer_record_off(global_trace.trace_buffer.buffer); |
Steven Rostedt | 499e547 | 2012-02-22 15:50:28 -0500 | [diff] [blame] | 555 | /* |
| 556 | * This flag is only looked at when buffers haven't been |
| 557 | * allocated yet. We don't really care about the race |
| 558 | * between setting this flag and actually turning |
| 559 | * on the buffer. |
| 560 | */ |
| 561 | global_trace.buffer_disabled = 1; |
| 562 | } |
| 563 | EXPORT_SYMBOL_GPL(tracing_off); |
| 564 | |
| 565 | /** |
| 566 | * tracing_is_on - show state of ring buffers enabled |
| 567 | */ |
| 568 | int tracing_is_on(void) |
| 569 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 570 | if (global_trace.trace_buffer.buffer) |
| 571 | return ring_buffer_record_is_on(global_trace.trace_buffer.buffer); |
Steven Rostedt | 499e547 | 2012-02-22 15:50:28 -0500 | [diff] [blame] | 572 | return !global_trace.buffer_disabled; |
| 573 | } |
| 574 | EXPORT_SYMBOL_GPL(tracing_is_on); |
| 575 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 576 | static int __init set_buf_size(char *str) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 577 | { |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 578 | unsigned long buf_size; |
Steven Rostedt | c6caeeb | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 579 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 580 | if (!str) |
| 581 | return 0; |
Li Zefan | 9d612be | 2009-06-24 17:33:15 +0800 | [diff] [blame] | 582 | buf_size = memparse(str, &str); |
Steven Rostedt | c6caeeb | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 583 | /* nr_entries can not be zero */ |
Li Zefan | 9d612be | 2009-06-24 17:33:15 +0800 | [diff] [blame] | 584 | if (buf_size == 0) |
Steven Rostedt | c6caeeb | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 585 | return 0; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 586 | trace_buf_size = buf_size; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 587 | return 1; |
| 588 | } |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 589 | __setup("trace_buf_size=", set_buf_size); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 590 | |
Tim Bird | 0e95017 | 2010-02-25 15:36:43 -0800 | [diff] [blame] | 591 | static int __init set_tracing_thresh(char *str) |
| 592 | { |
Wang Tianhong | 87abb3b | 2012-08-02 14:02:00 +0800 | [diff] [blame] | 593 | unsigned long threshold; |
Tim Bird | 0e95017 | 2010-02-25 15:36:43 -0800 | [diff] [blame] | 594 | int ret; |
| 595 | |
| 596 | if (!str) |
| 597 | return 0; |
Daniel Walter | bcd83ea | 2012-09-26 22:08:38 +0200 | [diff] [blame] | 598 | ret = kstrtoul(str, 0, &threshold); |
Tim Bird | 0e95017 | 2010-02-25 15:36:43 -0800 | [diff] [blame] | 599 | if (ret < 0) |
| 600 | return 0; |
Wang Tianhong | 87abb3b | 2012-08-02 14:02:00 +0800 | [diff] [blame] | 601 | tracing_thresh = threshold * 1000; |
Tim Bird | 0e95017 | 2010-02-25 15:36:43 -0800 | [diff] [blame] | 602 | return 1; |
| 603 | } |
| 604 | __setup("tracing_thresh=", set_tracing_thresh); |
| 605 | |
Steven Rostedt | 57f50be | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 606 | unsigned long nsecs_to_usecs(unsigned long nsecs) |
| 607 | { |
| 608 | return nsecs / 1000; |
| 609 | } |
| 610 | |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 611 | /* These must match the bit postions in trace_iterator_flags */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 612 | static const char *trace_options[] = { |
| 613 | "print-parent", |
| 614 | "sym-offset", |
| 615 | "sym-addr", |
| 616 | "verbose", |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 617 | "raw", |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 618 | "hex", |
Ingo Molnar | cb0f12a | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 619 | "bin", |
Soeren Sandmann Pedersen | 2a2cc8f | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 620 | "block", |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 621 | "stacktrace", |
Ingo Molnar | 5e1607a | 2009-03-05 10:24:48 +0100 | [diff] [blame] | 622 | "trace_printk", |
Steven Rostedt | b2a866f | 2008-11-03 23:15:57 -0500 | [diff] [blame] | 623 | "ftrace_preempt", |
Steven Rostedt | 9f029e8 | 2008-11-12 15:24:24 -0500 | [diff] [blame] | 624 | "branch", |
Steven Rostedt | 12ef7d4 | 2008-11-12 17:52:38 -0500 | [diff] [blame] | 625 | "annotate", |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 626 | "userstacktrace", |
Török Edwin | b54d3de | 2008-11-22 13:28:48 +0200 | [diff] [blame] | 627 | "sym-userobj", |
Frederic Weisbecker | 66896a8 | 2008-12-13 20:18:13 +0100 | [diff] [blame] | 628 | "printk-msg-only", |
Frederic Weisbecker | c4a8e8b | 2009-02-02 20:29:21 -0200 | [diff] [blame] | 629 | "context-info", |
Steven Rostedt | c032ef64 | 2009-03-04 20:34:24 -0500 | [diff] [blame] | 630 | "latency-format", |
Steven Rostedt | be6f164 | 2009-03-24 11:06:24 -0400 | [diff] [blame] | 631 | "sleep-time", |
Steven Rostedt | a2a16d6 | 2009-03-24 23:17:58 -0400 | [diff] [blame] | 632 | "graph-time", |
Li Zefan | e870e9a | 2010-07-02 11:07:32 +0800 | [diff] [blame] | 633 | "record-cmd", |
David Sharp | 750912f | 2010-12-08 13:46:47 -0800 | [diff] [blame] | 634 | "overwrite", |
Steven Rostedt | cf30cf6 | 2011-06-14 22:44:07 -0400 | [diff] [blame] | 635 | "disable_on_free", |
Steven Rostedt | 77271ce | 2011-11-17 09:34:33 -0500 | [diff] [blame] | 636 | "irq-info", |
Mandeep Singh Baines | 5224c3a | 2012-09-07 18:12:19 -0700 | [diff] [blame] | 637 | "markers", |
Steven Rostedt (Red Hat) | 328df47 | 2013-03-14 12:10:40 -0400 | [diff] [blame] | 638 | "function-trace", |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 639 | NULL |
| 640 | }; |
| 641 | |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 642 | static struct { |
| 643 | u64 (*func)(void); |
| 644 | const char *name; |
David Sharp | 8be0709 | 2012-11-13 12:18:22 -0800 | [diff] [blame] | 645 | int in_ns; /* is this clock in nanoseconds? */ |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 646 | } trace_clocks[] = { |
David Sharp | 8be0709 | 2012-11-13 12:18:22 -0800 | [diff] [blame] | 647 | { trace_clock_local, "local", 1 }, |
| 648 | { trace_clock_global, "global", 1 }, |
| 649 | { trace_clock_counter, "counter", 0 }, |
Steven Rostedt (Red Hat) | 8aacf01 | 2013-03-14 13:13:45 -0400 | [diff] [blame] | 650 | { trace_clock_jiffies, "uptime", 1 }, |
Steven Rostedt (Red Hat) | 76f1191 | 2013-03-14 17:53:25 -0400 | [diff] [blame] | 651 | { trace_clock, "perf", 1 }, |
David Sharp | 8cbd9cc | 2012-11-13 12:18:21 -0800 | [diff] [blame] | 652 | ARCH_TRACE_CLOCKS |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 653 | }; |
| 654 | |
| 655 | int trace_clock_id; |
| 656 | |
jolsa@redhat.com | b63f39e | 2009-09-11 17:29:27 +0200 | [diff] [blame] | 657 | /* |
| 658 | * trace_parser_get_init - gets the buffer for trace parser |
| 659 | */ |
| 660 | int trace_parser_get_init(struct trace_parser *parser, int size) |
| 661 | { |
| 662 | memset(parser, 0, sizeof(*parser)); |
| 663 | |
| 664 | parser->buffer = kmalloc(size, GFP_KERNEL); |
| 665 | if (!parser->buffer) |
| 666 | return 1; |
| 667 | |
| 668 | parser->size = size; |
| 669 | return 0; |
| 670 | } |
| 671 | |
| 672 | /* |
| 673 | * trace_parser_put - frees the buffer for trace parser |
| 674 | */ |
| 675 | void trace_parser_put(struct trace_parser *parser) |
| 676 | { |
| 677 | kfree(parser->buffer); |
| 678 | } |
| 679 | |
| 680 | /* |
| 681 | * trace_get_user - reads the user input string separated by space |
| 682 | * (matched by isspace(ch)) |
| 683 | * |
| 684 | * For each string found the 'struct trace_parser' is updated, |
| 685 | * and the function returns. |
| 686 | * |
| 687 | * Returns number of bytes read. |
| 688 | * |
| 689 | * See kernel/trace/trace.h for 'struct trace_parser' details. |
| 690 | */ |
| 691 | int trace_get_user(struct trace_parser *parser, const char __user *ubuf, |
| 692 | size_t cnt, loff_t *ppos) |
| 693 | { |
| 694 | char ch; |
| 695 | size_t read = 0; |
| 696 | ssize_t ret; |
| 697 | |
| 698 | if (!*ppos) |
| 699 | trace_parser_clear(parser); |
| 700 | |
| 701 | ret = get_user(ch, ubuf++); |
| 702 | if (ret) |
| 703 | goto out; |
| 704 | |
| 705 | read++; |
| 706 | cnt--; |
| 707 | |
| 708 | /* |
| 709 | * The parser is not finished with the last write, |
| 710 | * continue reading the user input without skipping spaces. |
| 711 | */ |
| 712 | if (!parser->cont) { |
| 713 | /* skip white space */ |
| 714 | while (cnt && isspace(ch)) { |
| 715 | ret = get_user(ch, ubuf++); |
| 716 | if (ret) |
| 717 | goto out; |
| 718 | read++; |
| 719 | cnt--; |
| 720 | } |
| 721 | |
| 722 | /* only spaces were written */ |
| 723 | if (isspace(ch)) { |
| 724 | *ppos += read; |
| 725 | ret = read; |
| 726 | goto out; |
| 727 | } |
| 728 | |
| 729 | parser->idx = 0; |
| 730 | } |
| 731 | |
| 732 | /* read the non-space input */ |
| 733 | while (cnt && !isspace(ch)) { |
Li Zefan | 3c235a3 | 2009-09-22 13:51:54 +0800 | [diff] [blame] | 734 | if (parser->idx < parser->size - 1) |
jolsa@redhat.com | b63f39e | 2009-09-11 17:29:27 +0200 | [diff] [blame] | 735 | parser->buffer[parser->idx++] = ch; |
| 736 | else { |
| 737 | ret = -EINVAL; |
| 738 | goto out; |
| 739 | } |
| 740 | ret = get_user(ch, ubuf++); |
| 741 | if (ret) |
| 742 | goto out; |
| 743 | read++; |
| 744 | cnt--; |
| 745 | } |
| 746 | |
| 747 | /* We either got finished input or we have to wait for another call. */ |
| 748 | if (isspace(ch)) { |
| 749 | parser->buffer[parser->idx] = 0; |
| 750 | parser->cont = false; |
| 751 | } else { |
| 752 | parser->cont = true; |
| 753 | parser->buffer[parser->idx++] = ch; |
| 754 | } |
| 755 | |
| 756 | *ppos += read; |
| 757 | ret = read; |
| 758 | |
| 759 | out: |
| 760 | return ret; |
| 761 | } |
| 762 | |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 763 | ssize_t trace_seq_to_user(struct trace_seq *s, char __user *ubuf, size_t cnt) |
| 764 | { |
| 765 | int len; |
| 766 | int ret; |
| 767 | |
Steven Rostedt | 2dc5d12 | 2009-03-04 19:10:05 -0500 | [diff] [blame] | 768 | if (!cnt) |
| 769 | return 0; |
| 770 | |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 771 | if (s->len <= s->readpos) |
| 772 | return -EBUSY; |
| 773 | |
| 774 | len = s->len - s->readpos; |
| 775 | if (cnt > len) |
| 776 | cnt = len; |
| 777 | ret = copy_to_user(ubuf, s->buffer + s->readpos, cnt); |
Steven Rostedt | 2dc5d12 | 2009-03-04 19:10:05 -0500 | [diff] [blame] | 778 | if (ret == cnt) |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 779 | return -EFAULT; |
| 780 | |
Steven Rostedt | 2dc5d12 | 2009-03-04 19:10:05 -0500 | [diff] [blame] | 781 | cnt -= ret; |
| 782 | |
Steven Rostedt | e74da52 | 2009-03-04 20:31:11 -0500 | [diff] [blame] | 783 | s->readpos += cnt; |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 784 | return cnt; |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 785 | } |
| 786 | |
Dmitri Vorobiev | b8b9426 | 2009-03-22 19:11:11 +0200 | [diff] [blame] | 787 | static ssize_t trace_seq_to_buffer(struct trace_seq *s, void *buf, size_t cnt) |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 788 | { |
| 789 | int len; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 790 | |
| 791 | if (s->len <= s->readpos) |
| 792 | return -EBUSY; |
| 793 | |
| 794 | len = s->len - s->readpos; |
| 795 | if (cnt > len) |
| 796 | cnt = len; |
Dan Carpenter | 5a26c8f | 2012-04-20 09:31:45 +0300 | [diff] [blame] | 797 | memcpy(buf, s->buffer + s->readpos, cnt); |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 798 | |
Steven Rostedt | e74da52 | 2009-03-04 20:31:11 -0500 | [diff] [blame] | 799 | s->readpos += cnt; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 800 | return cnt; |
| 801 | } |
| 802 | |
Steven Rostedt | 5d4a9db | 2009-08-27 16:52:21 -0400 | [diff] [blame] | 803 | /* |
| 804 | * ftrace_max_lock is used to protect the swapping of buffers |
| 805 | * when taking a max snapshot. The buffers themselves are |
| 806 | * protected by per_cpu spinlocks. But the action of the swap |
| 807 | * needs its own lock. |
| 808 | * |
Thomas Gleixner | 445c895 | 2009-12-02 19:49:50 +0100 | [diff] [blame] | 809 | * This is defined as a arch_spinlock_t in order to help |
Steven Rostedt | 5d4a9db | 2009-08-27 16:52:21 -0400 | [diff] [blame] | 810 | * with performance when lockdep debugging is enabled. |
| 811 | * |
| 812 | * It is also used in other places outside the update_max_tr |
| 813 | * so it needs to be defined outside of the |
| 814 | * CONFIG_TRACER_MAX_TRACE. |
| 815 | */ |
Thomas Gleixner | 445c895 | 2009-12-02 19:49:50 +0100 | [diff] [blame] | 816 | static arch_spinlock_t ftrace_max_lock = |
Thomas Gleixner | edc35bd | 2009-12-03 12:38:57 +0100 | [diff] [blame] | 817 | (arch_spinlock_t)__ARCH_SPIN_LOCK_UNLOCKED; |
Steven Rostedt | 5d4a9db | 2009-08-27 16:52:21 -0400 | [diff] [blame] | 818 | |
Tim Bird | 0e95017 | 2010-02-25 15:36:43 -0800 | [diff] [blame] | 819 | unsigned long __read_mostly tracing_thresh; |
| 820 | |
Steven Rostedt | 5d4a9db | 2009-08-27 16:52:21 -0400 | [diff] [blame] | 821 | #ifdef CONFIG_TRACER_MAX_TRACE |
| 822 | unsigned long __read_mostly tracing_max_latency; |
Steven Rostedt | 5d4a9db | 2009-08-27 16:52:21 -0400 | [diff] [blame] | 823 | |
| 824 | /* |
| 825 | * Copy the new maximum trace into the separate maximum-trace |
| 826 | * structure. (this way the maximum trace is permanently saved, |
| 827 | * for later retrieval via /sys/kernel/debug/tracing/latency_trace) |
| 828 | */ |
| 829 | static void |
| 830 | __update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu) |
| 831 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 832 | struct trace_buffer *trace_buf = &tr->trace_buffer; |
| 833 | struct trace_buffer *max_buf = &tr->max_buffer; |
| 834 | struct trace_array_cpu *data = per_cpu_ptr(trace_buf->data, cpu); |
| 835 | struct trace_array_cpu *max_data = per_cpu_ptr(max_buf->data, cpu); |
Steven Rostedt | 5d4a9db | 2009-08-27 16:52:21 -0400 | [diff] [blame] | 836 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 837 | max_buf->cpu = cpu; |
| 838 | max_buf->time_start = data->preempt_timestamp; |
Steven Rostedt | 5d4a9db | 2009-08-27 16:52:21 -0400 | [diff] [blame] | 839 | |
Steven Rostedt | 8248ac0 | 2009-09-02 12:27:41 -0400 | [diff] [blame] | 840 | max_data->saved_latency = tracing_max_latency; |
| 841 | max_data->critical_start = data->critical_start; |
| 842 | max_data->critical_end = data->critical_end; |
Steven Rostedt | 5d4a9db | 2009-08-27 16:52:21 -0400 | [diff] [blame] | 843 | |
Arnaldo Carvalho de Melo | 1acaa1b | 2010-03-05 18:23:50 -0300 | [diff] [blame] | 844 | memcpy(max_data->comm, tsk->comm, TASK_COMM_LEN); |
Steven Rostedt | 8248ac0 | 2009-09-02 12:27:41 -0400 | [diff] [blame] | 845 | max_data->pid = tsk->pid; |
Steven Rostedt (Red Hat) | f17a519 | 2013-05-30 21:10:37 -0400 | [diff] [blame^] | 846 | /* |
| 847 | * If tsk == current, then use current_uid(), as that does not use |
| 848 | * RCU. The irq tracer can be called out of RCU scope. |
| 849 | */ |
| 850 | if (tsk == current) |
| 851 | max_data->uid = current_uid(); |
| 852 | else |
| 853 | max_data->uid = task_uid(tsk); |
| 854 | |
Steven Rostedt | 8248ac0 | 2009-09-02 12:27:41 -0400 | [diff] [blame] | 855 | max_data->nice = tsk->static_prio - 20 - MAX_RT_PRIO; |
| 856 | max_data->policy = tsk->policy; |
| 857 | max_data->rt_priority = tsk->rt_priority; |
Steven Rostedt | 5d4a9db | 2009-08-27 16:52:21 -0400 | [diff] [blame] | 858 | |
| 859 | /* record this tasks comm */ |
| 860 | tracing_record_cmdline(tsk); |
| 861 | } |
| 862 | |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 863 | /** |
| 864 | * update_max_tr - snapshot all trace buffers from global_trace to max_tr |
| 865 | * @tr: tracer |
| 866 | * @tsk: the task with the latency |
| 867 | * @cpu: The cpu that initiated the trace. |
| 868 | * |
| 869 | * Flip the buffers between the @tr and the max_tr and record information |
| 870 | * about which task was the cause of this latency. |
| 871 | */ |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 872 | void |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 873 | update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu) |
| 874 | { |
Steven Rostedt (Red Hat) | 2721e72 | 2013-03-12 11:32:32 -0400 | [diff] [blame] | 875 | struct ring_buffer *buf; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 876 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 877 | if (tr->stop_count) |
Steven Rostedt | b8de7bd1 | 2009-08-31 22:32:27 -0400 | [diff] [blame] | 878 | return; |
| 879 | |
Steven Rostedt | 4c11d7a | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 880 | WARN_ON_ONCE(!irqs_disabled()); |
Steven Rostedt | 34600f0 | 2013-01-22 13:35:11 -0500 | [diff] [blame] | 881 | |
Steven Rostedt (Red Hat) | 45ad21c | 2013-03-05 18:25:02 -0500 | [diff] [blame] | 882 | if (!tr->allocated_snapshot) { |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 883 | /* Only the nop tracer should hit this when disabling */ |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 884 | WARN_ON_ONCE(tr->current_trace != &nop_trace); |
KOSAKI Motohiro | ef710e1 | 2010-07-01 14:34:35 +0900 | [diff] [blame] | 885 | return; |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 886 | } |
Steven Rostedt | 34600f0 | 2013-01-22 13:35:11 -0500 | [diff] [blame] | 887 | |
Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 888 | arch_spin_lock(&ftrace_max_lock); |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 889 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 890 | buf = tr->trace_buffer.buffer; |
| 891 | tr->trace_buffer.buffer = tr->max_buffer.buffer; |
| 892 | tr->max_buffer.buffer = buf; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 893 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 894 | __update_max_tr(tr, tsk, cpu); |
Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 895 | arch_spin_unlock(&ftrace_max_lock); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 896 | } |
| 897 | |
| 898 | /** |
| 899 | * update_max_tr_single - only copy one trace over, and reset the rest |
| 900 | * @tr - tracer |
| 901 | * @tsk - task with the latency |
| 902 | * @cpu - the cpu of the buffer to copy. |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 903 | * |
| 904 | * Flip the trace of a single CPU buffer between the @tr and the max_tr. |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 905 | */ |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 906 | void |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 907 | update_max_tr_single(struct trace_array *tr, struct task_struct *tsk, int cpu) |
| 908 | { |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 909 | int ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 910 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 911 | if (tr->stop_count) |
Steven Rostedt | b8de7bd1 | 2009-08-31 22:32:27 -0400 | [diff] [blame] | 912 | return; |
| 913 | |
Steven Rostedt | 4c11d7a | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 914 | WARN_ON_ONCE(!irqs_disabled()); |
Steven Rostedt | 6c24499 | 2013-04-29 20:08:14 -0400 | [diff] [blame] | 915 | if (!tr->allocated_snapshot) { |
Steven Rostedt (Red Hat) | 2930e04 | 2013-03-26 17:33:00 -0400 | [diff] [blame] | 916 | /* Only the nop tracer should hit this when disabling */ |
Linus Torvalds | 9e8529a | 2013-04-29 13:55:38 -0700 | [diff] [blame] | 917 | WARN_ON_ONCE(tr->current_trace != &nop_trace); |
KOSAKI Motohiro | ef710e1 | 2010-07-01 14:34:35 +0900 | [diff] [blame] | 918 | return; |
Steven Rostedt (Red Hat) | 2930e04 | 2013-03-26 17:33:00 -0400 | [diff] [blame] | 919 | } |
KOSAKI Motohiro | ef710e1 | 2010-07-01 14:34:35 +0900 | [diff] [blame] | 920 | |
Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 921 | arch_spin_lock(&ftrace_max_lock); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 922 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 923 | ret = ring_buffer_swap_cpu(tr->max_buffer.buffer, tr->trace_buffer.buffer, cpu); |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 924 | |
Steven Rostedt | e8165dbb | 2009-09-03 19:13:05 -0400 | [diff] [blame] | 925 | if (ret == -EBUSY) { |
| 926 | /* |
| 927 | * We failed to swap the buffer due to a commit taking |
| 928 | * place on this CPU. We fail to record, but we reset |
| 929 | * the max trace buffer (no one writes directly to it) |
| 930 | * and flag that it failed. |
| 931 | */ |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 932 | trace_array_printk_buf(tr->max_buffer.buffer, _THIS_IP_, |
Steven Rostedt | e8165dbb | 2009-09-03 19:13:05 -0400 | [diff] [blame] | 933 | "Failed to swap buffers due to commit in progress\n"); |
| 934 | } |
| 935 | |
Steven Rostedt | e8165dbb | 2009-09-03 19:13:05 -0400 | [diff] [blame] | 936 | WARN_ON_ONCE(ret && ret != -EAGAIN && ret != -EBUSY); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 937 | |
| 938 | __update_max_tr(tr, tsk, cpu); |
Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 939 | arch_spin_unlock(&ftrace_max_lock); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 940 | } |
Steven Rostedt | 5d4a9db | 2009-08-27 16:52:21 -0400 | [diff] [blame] | 941 | #endif /* CONFIG_TRACER_MAX_TRACE */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 942 | |
Steven Rostedt | 0d5c6e1 | 2012-11-01 20:54:21 -0400 | [diff] [blame] | 943 | static void default_wait_pipe(struct trace_iterator *iter) |
| 944 | { |
Steven Rostedt (Red Hat) | 1569345 | 2013-02-28 19:59:17 -0500 | [diff] [blame] | 945 | /* Iterators are static, they should be filled or empty */ |
| 946 | if (trace_buffer_iter(iter, iter->cpu_file)) |
| 947 | return; |
Steven Rostedt | 0d5c6e1 | 2012-11-01 20:54:21 -0400 | [diff] [blame] | 948 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 949 | ring_buffer_wait(iter->trace_buffer->buffer, iter->cpu_file); |
Steven Rostedt | 0d5c6e1 | 2012-11-01 20:54:21 -0400 | [diff] [blame] | 950 | } |
| 951 | |
Steven Rostedt (Red Hat) | f4e781c | 2013-03-07 11:10:56 -0500 | [diff] [blame] | 952 | #ifdef CONFIG_FTRACE_STARTUP_TEST |
| 953 | static int run_tracer_selftest(struct tracer *type) |
| 954 | { |
| 955 | struct trace_array *tr = &global_trace; |
| 956 | struct tracer *saved_tracer = tr->current_trace; |
| 957 | int ret; |
| 958 | |
| 959 | if (!type->selftest || tracing_selftest_disabled) |
| 960 | return 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 961 | |
| 962 | /* |
Steven Rostedt (Red Hat) | f4e781c | 2013-03-07 11:10:56 -0500 | [diff] [blame] | 963 | * Run a selftest on this tracer. |
| 964 | * Here we reset the trace buffer, and set the current |
| 965 | * tracer to be this tracer. The tracer can then run some |
| 966 | * internal tracing to verify that everything is in order. |
| 967 | * If we fail, we do not register this tracer. |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 968 | */ |
Steven Rostedt (Red Hat) | f4e781c | 2013-03-07 11:10:56 -0500 | [diff] [blame] | 969 | tracing_reset_online_cpus(&tr->trace_buffer); |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 970 | |
Steven Rostedt (Red Hat) | f4e781c | 2013-03-07 11:10:56 -0500 | [diff] [blame] | 971 | tr->current_trace = type; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 972 | |
Steven Rostedt (Red Hat) | f4e781c | 2013-03-07 11:10:56 -0500 | [diff] [blame] | 973 | #ifdef CONFIG_TRACER_MAX_TRACE |
| 974 | if (type->use_max_tr) { |
| 975 | /* If we expanded the buffers, make sure the max is expanded too */ |
| 976 | if (ring_buffer_expanded) |
| 977 | ring_buffer_resize(tr->max_buffer.buffer, trace_buf_size, |
| 978 | RING_BUFFER_ALL_CPUS); |
| 979 | tr->allocated_snapshot = true; |
| 980 | } |
| 981 | #endif |
| 982 | |
| 983 | /* the test is responsible for initializing and enabling */ |
| 984 | pr_info("Testing tracer %s: ", type->name); |
| 985 | ret = type->selftest(type, tr); |
| 986 | /* the test is responsible for resetting too */ |
| 987 | tr->current_trace = saved_tracer; |
| 988 | if (ret) { |
| 989 | printk(KERN_CONT "FAILED!\n"); |
| 990 | /* Add the warning after printing 'FAILED' */ |
| 991 | WARN_ON(1); |
| 992 | return -1; |
| 993 | } |
| 994 | /* Only reset on passing, to avoid touching corrupted buffers */ |
| 995 | tracing_reset_online_cpus(&tr->trace_buffer); |
| 996 | |
| 997 | #ifdef CONFIG_TRACER_MAX_TRACE |
| 998 | if (type->use_max_tr) { |
| 999 | tr->allocated_snapshot = false; |
| 1000 | |
| 1001 | /* Shrink the max buffer again */ |
| 1002 | if (ring_buffer_expanded) |
| 1003 | ring_buffer_resize(tr->max_buffer.buffer, 1, |
| 1004 | RING_BUFFER_ALL_CPUS); |
| 1005 | } |
| 1006 | #endif |
| 1007 | |
| 1008 | printk(KERN_CONT "PASSED\n"); |
| 1009 | return 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1010 | } |
Steven Rostedt (Red Hat) | f4e781c | 2013-03-07 11:10:56 -0500 | [diff] [blame] | 1011 | #else |
| 1012 | static inline int run_tracer_selftest(struct tracer *type) |
| 1013 | { |
| 1014 | return 0; |
| 1015 | } |
| 1016 | #endif /* CONFIG_FTRACE_STARTUP_TEST */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1017 | |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 1018 | /** |
| 1019 | * register_tracer - register a tracer with the ftrace system. |
| 1020 | * @type - the plugin for the tracer |
| 1021 | * |
| 1022 | * Register a new plugin tracer. |
| 1023 | */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1024 | int register_tracer(struct tracer *type) |
| 1025 | { |
| 1026 | struct tracer *t; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1027 | int ret = 0; |
| 1028 | |
| 1029 | if (!type->name) { |
| 1030 | pr_info("Tracer must have a name\n"); |
| 1031 | return -1; |
| 1032 | } |
| 1033 | |
Dan Carpenter | 24a461d | 2010-07-10 12:06:44 +0200 | [diff] [blame] | 1034 | if (strlen(type->name) >= MAX_TRACER_SIZE) { |
Li Zefan | ee6c2c1 | 2009-09-18 14:06:47 +0800 | [diff] [blame] | 1035 | pr_info("Tracer has a name longer than %d\n", MAX_TRACER_SIZE); |
| 1036 | return -1; |
| 1037 | } |
| 1038 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1039 | mutex_lock(&trace_types_lock); |
Ingo Molnar | 86fa2f6 | 2008-11-19 10:00:15 +0100 | [diff] [blame] | 1040 | |
Frederic Weisbecker | 8e1b82e | 2008-12-06 03:41:33 +0100 | [diff] [blame] | 1041 | tracing_selftest_running = true; |
| 1042 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1043 | for (t = trace_types; t; t = t->next) { |
| 1044 | if (strcmp(type->name, t->name) == 0) { |
| 1045 | /* already found */ |
Li Zefan | ee6c2c1 | 2009-09-18 14:06:47 +0800 | [diff] [blame] | 1046 | pr_info("Tracer %s already registered\n", |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1047 | type->name); |
| 1048 | ret = -1; |
| 1049 | goto out; |
| 1050 | } |
| 1051 | } |
| 1052 | |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 1053 | if (!type->set_flag) |
| 1054 | type->set_flag = &dummy_set_flag; |
| 1055 | if (!type->flags) |
| 1056 | type->flags = &dummy_tracer_flags; |
| 1057 | else |
| 1058 | if (!type->flags->opts) |
| 1059 | type->flags->opts = dummy_tracer_opt; |
Frederic Weisbecker | 6eaaa5d | 2009-02-11 02:25:00 +0100 | [diff] [blame] | 1060 | if (!type->wait_pipe) |
| 1061 | type->wait_pipe = default_wait_pipe; |
| 1062 | |
Steven Rostedt (Red Hat) | f4e781c | 2013-03-07 11:10:56 -0500 | [diff] [blame] | 1063 | ret = run_tracer_selftest(type); |
| 1064 | if (ret < 0) |
| 1065 | goto out; |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 1066 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1067 | type->next = trace_types; |
| 1068 | trace_types = type; |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 1069 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1070 | out: |
Frederic Weisbecker | 8e1b82e | 2008-12-06 03:41:33 +0100 | [diff] [blame] | 1071 | tracing_selftest_running = false; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1072 | mutex_unlock(&trace_types_lock); |
| 1073 | |
Steven Rostedt | dac7494 | 2009-02-05 01:13:38 -0500 | [diff] [blame] | 1074 | if (ret || !default_bootup_tracer) |
| 1075 | goto out_unlock; |
Steven Rostedt | b2821ae | 2009-02-02 21:38:32 -0500 | [diff] [blame] | 1076 | |
Li Zefan | ee6c2c1 | 2009-09-18 14:06:47 +0800 | [diff] [blame] | 1077 | if (strncmp(default_bootup_tracer, type->name, MAX_TRACER_SIZE)) |
Steven Rostedt | dac7494 | 2009-02-05 01:13:38 -0500 | [diff] [blame] | 1078 | goto out_unlock; |
| 1079 | |
| 1080 | printk(KERN_INFO "Starting tracer '%s'\n", type->name); |
| 1081 | /* Do we want this tracer to start on bootup? */ |
| 1082 | tracing_set_tracer(type->name); |
| 1083 | default_bootup_tracer = NULL; |
| 1084 | /* disable other selftests, since this will break it. */ |
Steven Rostedt (Red Hat) | 55034cd | 2013-03-07 22:48:09 -0500 | [diff] [blame] | 1085 | tracing_selftest_disabled = true; |
Steven Rostedt | dac7494 | 2009-02-05 01:13:38 -0500 | [diff] [blame] | 1086 | #ifdef CONFIG_FTRACE_STARTUP_TEST |
| 1087 | printk(KERN_INFO "Disabling FTRACE selftests due to running tracer '%s'\n", |
| 1088 | type->name); |
| 1089 | #endif |
| 1090 | |
| 1091 | out_unlock: |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1092 | return ret; |
| 1093 | } |
| 1094 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1095 | void tracing_reset(struct trace_buffer *buf, int cpu) |
Steven Rostedt | f633903 | 2009-09-04 12:35:16 -0400 | [diff] [blame] | 1096 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1097 | struct ring_buffer *buffer = buf->buffer; |
Steven Rostedt | f633903 | 2009-09-04 12:35:16 -0400 | [diff] [blame] | 1098 | |
Hiraku Toyooka | a541641 | 2012-12-19 16:02:34 +0900 | [diff] [blame] | 1099 | if (!buffer) |
| 1100 | return; |
| 1101 | |
Steven Rostedt | f633903 | 2009-09-04 12:35:16 -0400 | [diff] [blame] | 1102 | ring_buffer_record_disable(buffer); |
| 1103 | |
| 1104 | /* Make sure all commits have finished */ |
| 1105 | synchronize_sched(); |
Steven Rostedt | 6817968 | 2012-05-08 20:57:53 -0400 | [diff] [blame] | 1106 | ring_buffer_reset_cpu(buffer, cpu); |
Steven Rostedt | f633903 | 2009-09-04 12:35:16 -0400 | [diff] [blame] | 1107 | |
| 1108 | ring_buffer_record_enable(buffer); |
| 1109 | } |
| 1110 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1111 | void tracing_reset_online_cpus(struct trace_buffer *buf) |
Pekka J Enberg | 213cc06 | 2008-12-19 12:08:39 +0200 | [diff] [blame] | 1112 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1113 | struct ring_buffer *buffer = buf->buffer; |
Pekka J Enberg | 213cc06 | 2008-12-19 12:08:39 +0200 | [diff] [blame] | 1114 | int cpu; |
| 1115 | |
Hiraku Toyooka | a541641 | 2012-12-19 16:02:34 +0900 | [diff] [blame] | 1116 | if (!buffer) |
| 1117 | return; |
| 1118 | |
Steven Rostedt | 621968c | 2009-09-04 12:02:35 -0400 | [diff] [blame] | 1119 | ring_buffer_record_disable(buffer); |
| 1120 | |
| 1121 | /* Make sure all commits have finished */ |
| 1122 | synchronize_sched(); |
| 1123 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1124 | buf->time_start = ftrace_now(buf->cpu); |
Pekka J Enberg | 213cc06 | 2008-12-19 12:08:39 +0200 | [diff] [blame] | 1125 | |
| 1126 | for_each_online_cpu(cpu) |
Steven Rostedt | 6817968 | 2012-05-08 20:57:53 -0400 | [diff] [blame] | 1127 | ring_buffer_reset_cpu(buffer, cpu); |
Steven Rostedt | 621968c | 2009-09-04 12:02:35 -0400 | [diff] [blame] | 1128 | |
| 1129 | ring_buffer_record_enable(buffer); |
Pekka J Enberg | 213cc06 | 2008-12-19 12:08:39 +0200 | [diff] [blame] | 1130 | } |
| 1131 | |
Steven Rostedt | 9456f0f | 2009-05-06 21:54:09 -0400 | [diff] [blame] | 1132 | void tracing_reset_current(int cpu) |
| 1133 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1134 | tracing_reset(&global_trace.trace_buffer, cpu); |
Steven Rostedt | 9456f0f | 2009-05-06 21:54:09 -0400 | [diff] [blame] | 1135 | } |
| 1136 | |
Steven Rostedt (Red Hat) | 873c642 | 2013-03-04 23:26:06 -0500 | [diff] [blame] | 1137 | void tracing_reset_all_online_cpus(void) |
Steven Rostedt | 9456f0f | 2009-05-06 21:54:09 -0400 | [diff] [blame] | 1138 | { |
Steven Rostedt (Red Hat) | 873c642 | 2013-03-04 23:26:06 -0500 | [diff] [blame] | 1139 | struct trace_array *tr; |
| 1140 | |
| 1141 | mutex_lock(&trace_types_lock); |
| 1142 | list_for_each_entry(tr, &ftrace_trace_arrays, list) { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1143 | tracing_reset_online_cpus(&tr->trace_buffer); |
| 1144 | #ifdef CONFIG_TRACER_MAX_TRACE |
| 1145 | tracing_reset_online_cpus(&tr->max_buffer); |
| 1146 | #endif |
Steven Rostedt (Red Hat) | 873c642 | 2013-03-04 23:26:06 -0500 | [diff] [blame] | 1147 | } |
| 1148 | mutex_unlock(&trace_types_lock); |
Steven Rostedt | 9456f0f | 2009-05-06 21:54:09 -0400 | [diff] [blame] | 1149 | } |
| 1150 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1151 | #define SAVED_CMDLINES 128 |
Thomas Gleixner | 2c7eea4 | 2009-03-18 09:03:19 +0100 | [diff] [blame] | 1152 | #define NO_CMDLINE_MAP UINT_MAX |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1153 | static unsigned map_pid_to_cmdline[PID_MAX_DEFAULT+1]; |
| 1154 | static unsigned map_cmdline_to_pid[SAVED_CMDLINES]; |
| 1155 | static char saved_cmdlines[SAVED_CMDLINES][TASK_COMM_LEN]; |
| 1156 | static int cmdline_idx; |
Thomas Gleixner | edc35bd | 2009-12-03 12:38:57 +0100 | [diff] [blame] | 1157 | static arch_spinlock_t trace_cmdline_lock = __ARCH_SPIN_LOCK_UNLOCKED; |
Steven Rostedt | 25b0b44 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 1158 | |
Steven Rostedt | 25b0b44 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 1159 | /* temporary disable recording */ |
Hannes Eder | 4fd2735 | 2009-02-10 19:44:12 +0100 | [diff] [blame] | 1160 | static atomic_t trace_record_cmdline_disabled __read_mostly; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1161 | |
| 1162 | static void trace_init_cmdlines(void) |
| 1163 | { |
Thomas Gleixner | 2c7eea4 | 2009-03-18 09:03:19 +0100 | [diff] [blame] | 1164 | memset(&map_pid_to_cmdline, NO_CMDLINE_MAP, sizeof(map_pid_to_cmdline)); |
| 1165 | memset(&map_cmdline_to_pid, NO_CMDLINE_MAP, sizeof(map_cmdline_to_pid)); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1166 | cmdline_idx = 0; |
| 1167 | } |
| 1168 | |
Carsten Emde | b5130b1 | 2009-09-13 01:43:07 +0200 | [diff] [blame] | 1169 | int is_tracing_stopped(void) |
| 1170 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 1171 | return global_trace.stop_count; |
Carsten Emde | b5130b1 | 2009-09-13 01:43:07 +0200 | [diff] [blame] | 1172 | } |
| 1173 | |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1174 | /** |
Steven Rostedt | 69bb54e | 2008-11-21 12:59:38 -0500 | [diff] [blame] | 1175 | * ftrace_off_permanent - disable all ftrace code permanently |
| 1176 | * |
| 1177 | * This should only be called when a serious anomally has |
| 1178 | * been detected. This will turn off the function tracing, |
| 1179 | * ring buffers, and other tracing utilites. It takes no |
| 1180 | * locks and can be called from any context. |
| 1181 | */ |
| 1182 | void ftrace_off_permanent(void) |
| 1183 | { |
| 1184 | tracing_disabled = 1; |
| 1185 | ftrace_stop(); |
| 1186 | tracing_off_permanent(); |
| 1187 | } |
| 1188 | |
| 1189 | /** |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1190 | * tracing_start - quick start of the tracer |
| 1191 | * |
| 1192 | * If tracing is enabled but was stopped by tracing_stop, |
| 1193 | * this will start the tracer back up. |
| 1194 | */ |
| 1195 | void tracing_start(void) |
| 1196 | { |
| 1197 | struct ring_buffer *buffer; |
| 1198 | unsigned long flags; |
| 1199 | |
| 1200 | if (tracing_disabled) |
| 1201 | return; |
| 1202 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 1203 | raw_spin_lock_irqsave(&global_trace.start_lock, flags); |
| 1204 | if (--global_trace.stop_count) { |
| 1205 | if (global_trace.stop_count < 0) { |
Steven Rostedt | b06a830 | 2009-01-22 14:26:15 -0500 | [diff] [blame] | 1206 | /* Someone screwed up their debugging */ |
| 1207 | WARN_ON_ONCE(1); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 1208 | global_trace.stop_count = 0; |
Steven Rostedt | b06a830 | 2009-01-22 14:26:15 -0500 | [diff] [blame] | 1209 | } |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1210 | goto out; |
| 1211 | } |
| 1212 | |
Steven Rostedt | a2f8071 | 2010-03-12 19:56:00 -0500 | [diff] [blame] | 1213 | /* Prevent the buffers from switching */ |
| 1214 | arch_spin_lock(&ftrace_max_lock); |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1215 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1216 | buffer = global_trace.trace_buffer.buffer; |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1217 | if (buffer) |
| 1218 | ring_buffer_record_enable(buffer); |
| 1219 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1220 | #ifdef CONFIG_TRACER_MAX_TRACE |
| 1221 | buffer = global_trace.max_buffer.buffer; |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1222 | if (buffer) |
| 1223 | ring_buffer_record_enable(buffer); |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1224 | #endif |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1225 | |
Steven Rostedt | a2f8071 | 2010-03-12 19:56:00 -0500 | [diff] [blame] | 1226 | arch_spin_unlock(&ftrace_max_lock); |
| 1227 | |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1228 | ftrace_start(); |
| 1229 | out: |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 1230 | raw_spin_unlock_irqrestore(&global_trace.start_lock, flags); |
| 1231 | } |
| 1232 | |
| 1233 | static void tracing_start_tr(struct trace_array *tr) |
| 1234 | { |
| 1235 | struct ring_buffer *buffer; |
| 1236 | unsigned long flags; |
| 1237 | |
| 1238 | if (tracing_disabled) |
| 1239 | return; |
| 1240 | |
| 1241 | /* If global, we need to also start the max tracer */ |
| 1242 | if (tr->flags & TRACE_ARRAY_FL_GLOBAL) |
| 1243 | return tracing_start(); |
| 1244 | |
| 1245 | raw_spin_lock_irqsave(&tr->start_lock, flags); |
| 1246 | |
| 1247 | if (--tr->stop_count) { |
| 1248 | if (tr->stop_count < 0) { |
| 1249 | /* Someone screwed up their debugging */ |
| 1250 | WARN_ON_ONCE(1); |
| 1251 | tr->stop_count = 0; |
| 1252 | } |
| 1253 | goto out; |
| 1254 | } |
| 1255 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1256 | buffer = tr->trace_buffer.buffer; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 1257 | if (buffer) |
| 1258 | ring_buffer_record_enable(buffer); |
| 1259 | |
| 1260 | out: |
| 1261 | raw_spin_unlock_irqrestore(&tr->start_lock, flags); |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1262 | } |
| 1263 | |
| 1264 | /** |
| 1265 | * tracing_stop - quick stop of the tracer |
| 1266 | * |
| 1267 | * Light weight way to stop tracing. Use in conjunction with |
| 1268 | * tracing_start. |
| 1269 | */ |
| 1270 | void tracing_stop(void) |
| 1271 | { |
| 1272 | struct ring_buffer *buffer; |
| 1273 | unsigned long flags; |
| 1274 | |
| 1275 | ftrace_stop(); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 1276 | raw_spin_lock_irqsave(&global_trace.start_lock, flags); |
| 1277 | if (global_trace.stop_count++) |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1278 | goto out; |
| 1279 | |
Steven Rostedt | a2f8071 | 2010-03-12 19:56:00 -0500 | [diff] [blame] | 1280 | /* Prevent the buffers from switching */ |
| 1281 | arch_spin_lock(&ftrace_max_lock); |
| 1282 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1283 | buffer = global_trace.trace_buffer.buffer; |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1284 | if (buffer) |
| 1285 | ring_buffer_record_disable(buffer); |
| 1286 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1287 | #ifdef CONFIG_TRACER_MAX_TRACE |
| 1288 | buffer = global_trace.max_buffer.buffer; |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1289 | if (buffer) |
| 1290 | ring_buffer_record_disable(buffer); |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1291 | #endif |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1292 | |
Steven Rostedt | a2f8071 | 2010-03-12 19:56:00 -0500 | [diff] [blame] | 1293 | arch_spin_unlock(&ftrace_max_lock); |
| 1294 | |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1295 | out: |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 1296 | raw_spin_unlock_irqrestore(&global_trace.start_lock, flags); |
| 1297 | } |
| 1298 | |
| 1299 | static void tracing_stop_tr(struct trace_array *tr) |
| 1300 | { |
| 1301 | struct ring_buffer *buffer; |
| 1302 | unsigned long flags; |
| 1303 | |
| 1304 | /* If global, we need to also stop the max tracer */ |
| 1305 | if (tr->flags & TRACE_ARRAY_FL_GLOBAL) |
| 1306 | return tracing_stop(); |
| 1307 | |
| 1308 | raw_spin_lock_irqsave(&tr->start_lock, flags); |
| 1309 | if (tr->stop_count++) |
| 1310 | goto out; |
| 1311 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1312 | buffer = tr->trace_buffer.buffer; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 1313 | if (buffer) |
| 1314 | ring_buffer_record_disable(buffer); |
| 1315 | |
| 1316 | out: |
| 1317 | raw_spin_unlock_irqrestore(&tr->start_lock, flags); |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1318 | } |
| 1319 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1320 | void trace_stop_cmdline_recording(void); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1321 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1322 | static void trace_save_cmdline(struct task_struct *tsk) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1323 | { |
Carsten Emde | a635cf0 | 2009-03-18 09:00:41 +0100 | [diff] [blame] | 1324 | unsigned pid, idx; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1325 | |
| 1326 | if (!tsk->pid || unlikely(tsk->pid > PID_MAX_DEFAULT)) |
| 1327 | return; |
| 1328 | |
| 1329 | /* |
| 1330 | * It's not the end of the world if we don't get |
| 1331 | * the lock, but we also don't want to spin |
| 1332 | * nor do we want to disable interrupts, |
| 1333 | * so if we miss here, then better luck next time. |
| 1334 | */ |
Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 1335 | if (!arch_spin_trylock(&trace_cmdline_lock)) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1336 | return; |
| 1337 | |
| 1338 | idx = map_pid_to_cmdline[tsk->pid]; |
Thomas Gleixner | 2c7eea4 | 2009-03-18 09:03:19 +0100 | [diff] [blame] | 1339 | if (idx == NO_CMDLINE_MAP) { |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1340 | idx = (cmdline_idx + 1) % SAVED_CMDLINES; |
| 1341 | |
Carsten Emde | a635cf0 | 2009-03-18 09:00:41 +0100 | [diff] [blame] | 1342 | /* |
| 1343 | * Check whether the cmdline buffer at idx has a pid |
| 1344 | * mapped. We are going to overwrite that entry so we |
| 1345 | * need to clear the map_pid_to_cmdline. Otherwise we |
| 1346 | * would read the new comm for the old pid. |
| 1347 | */ |
| 1348 | pid = map_cmdline_to_pid[idx]; |
| 1349 | if (pid != NO_CMDLINE_MAP) |
| 1350 | map_pid_to_cmdline[pid] = NO_CMDLINE_MAP; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1351 | |
Carsten Emde | a635cf0 | 2009-03-18 09:00:41 +0100 | [diff] [blame] | 1352 | map_cmdline_to_pid[idx] = tsk->pid; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1353 | map_pid_to_cmdline[tsk->pid] = idx; |
| 1354 | |
| 1355 | cmdline_idx = idx; |
| 1356 | } |
| 1357 | |
| 1358 | memcpy(&saved_cmdlines[idx], tsk->comm, TASK_COMM_LEN); |
| 1359 | |
Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 1360 | arch_spin_unlock(&trace_cmdline_lock); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1361 | } |
| 1362 | |
Steven Rostedt | 4ca53085 | 2009-03-16 19:20:15 -0400 | [diff] [blame] | 1363 | void trace_find_cmdline(int pid, char comm[]) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1364 | { |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1365 | unsigned map; |
| 1366 | |
Steven Rostedt | 4ca53085 | 2009-03-16 19:20:15 -0400 | [diff] [blame] | 1367 | if (!pid) { |
| 1368 | strcpy(comm, "<idle>"); |
| 1369 | return; |
| 1370 | } |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1371 | |
Steven Rostedt | 74bf407 | 2010-01-25 15:11:53 -0500 | [diff] [blame] | 1372 | if (WARN_ON_ONCE(pid < 0)) { |
| 1373 | strcpy(comm, "<XXX>"); |
| 1374 | return; |
| 1375 | } |
| 1376 | |
Steven Rostedt | 4ca53085 | 2009-03-16 19:20:15 -0400 | [diff] [blame] | 1377 | if (pid > PID_MAX_DEFAULT) { |
| 1378 | strcpy(comm, "<...>"); |
| 1379 | return; |
| 1380 | } |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1381 | |
Heiko Carstens | 5b6045a | 2009-05-26 17:28:02 +0200 | [diff] [blame] | 1382 | preempt_disable(); |
Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 1383 | arch_spin_lock(&trace_cmdline_lock); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1384 | map = map_pid_to_cmdline[pid]; |
Thomas Gleixner | 50d8875 | 2009-03-18 08:58:44 +0100 | [diff] [blame] | 1385 | if (map != NO_CMDLINE_MAP) |
| 1386 | strcpy(comm, saved_cmdlines[map]); |
| 1387 | else |
| 1388 | strcpy(comm, "<...>"); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1389 | |
Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 1390 | arch_spin_unlock(&trace_cmdline_lock); |
Heiko Carstens | 5b6045a | 2009-05-26 17:28:02 +0200 | [diff] [blame] | 1391 | preempt_enable(); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1392 | } |
| 1393 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1394 | void tracing_record_cmdline(struct task_struct *tsk) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1395 | { |
Steven Rostedt | 0fb9656 | 2012-05-11 14:25:30 -0400 | [diff] [blame] | 1396 | if (atomic_read(&trace_record_cmdline_disabled) || !tracing_is_on()) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1397 | return; |
| 1398 | |
Steven Rostedt | 7ffbd48 | 2012-10-11 12:14:25 -0400 | [diff] [blame] | 1399 | if (!__this_cpu_read(trace_cmdline_save)) |
| 1400 | return; |
| 1401 | |
| 1402 | __this_cpu_write(trace_cmdline_save, false); |
| 1403 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1404 | trace_save_cmdline(tsk); |
| 1405 | } |
| 1406 | |
Pekka Paalanen | 45dcd8b | 2008-09-16 21:56:41 +0300 | [diff] [blame] | 1407 | void |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 1408 | tracing_generic_entry_update(struct trace_entry *entry, unsigned long flags, |
| 1409 | int pc) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1410 | { |
| 1411 | struct task_struct *tsk = current; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1412 | |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1413 | entry->preempt_count = pc & 0xff; |
| 1414 | entry->pid = (tsk) ? tsk->pid : 0; |
| 1415 | entry->flags = |
Steven Rostedt | 9244489 | 2008-10-24 09:42:59 -0400 | [diff] [blame] | 1416 | #ifdef CONFIG_TRACE_IRQFLAGS_SUPPORT |
Steven Rostedt | 2e2ca15 | 2008-08-01 12:26:40 -0400 | [diff] [blame] | 1417 | (irqs_disabled_flags(flags) ? TRACE_FLAG_IRQS_OFF : 0) | |
Steven Rostedt | 9244489 | 2008-10-24 09:42:59 -0400 | [diff] [blame] | 1418 | #else |
| 1419 | TRACE_FLAG_IRQS_NOSUPPORT | |
| 1420 | #endif |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1421 | ((pc & HARDIRQ_MASK) ? TRACE_FLAG_HARDIRQ : 0) | |
| 1422 | ((pc & SOFTIRQ_MASK) ? TRACE_FLAG_SOFTIRQ : 0) | |
| 1423 | (need_resched() ? TRACE_FLAG_NEED_RESCHED : 0); |
| 1424 | } |
Frederic Weisbecker | f413cdb | 2009-08-07 01:25:54 +0200 | [diff] [blame] | 1425 | EXPORT_SYMBOL_GPL(tracing_generic_entry_update); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1426 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1427 | struct ring_buffer_event * |
| 1428 | trace_buffer_lock_reserve(struct ring_buffer *buffer, |
| 1429 | int type, |
| 1430 | unsigned long len, |
| 1431 | unsigned long flags, int pc) |
Arnaldo Carvalho de Melo | 51a763d | 2009-02-05 16:14:13 -0200 | [diff] [blame] | 1432 | { |
| 1433 | struct ring_buffer_event *event; |
| 1434 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1435 | event = ring_buffer_lock_reserve(buffer, len); |
Arnaldo Carvalho de Melo | 51a763d | 2009-02-05 16:14:13 -0200 | [diff] [blame] | 1436 | if (event != NULL) { |
| 1437 | struct trace_entry *ent = ring_buffer_event_data(event); |
| 1438 | |
| 1439 | tracing_generic_entry_update(ent, flags, pc); |
| 1440 | ent->type = type; |
| 1441 | } |
| 1442 | |
| 1443 | return event; |
| 1444 | } |
Arnaldo Carvalho de Melo | 51a763d | 2009-02-05 16:14:13 -0200 | [diff] [blame] | 1445 | |
Steven Rostedt | 7ffbd48 | 2012-10-11 12:14:25 -0400 | [diff] [blame] | 1446 | void |
| 1447 | __buffer_unlock_commit(struct ring_buffer *buffer, struct ring_buffer_event *event) |
| 1448 | { |
| 1449 | __this_cpu_write(trace_cmdline_save, true); |
| 1450 | ring_buffer_unlock_commit(buffer, event); |
| 1451 | } |
| 1452 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1453 | static inline void |
| 1454 | __trace_buffer_unlock_commit(struct ring_buffer *buffer, |
| 1455 | struct ring_buffer_event *event, |
Steven Rostedt | 0d5c6e1 | 2012-11-01 20:54:21 -0400 | [diff] [blame] | 1456 | unsigned long flags, int pc) |
Arnaldo Carvalho de Melo | 51a763d | 2009-02-05 16:14:13 -0200 | [diff] [blame] | 1457 | { |
Steven Rostedt | 7ffbd48 | 2012-10-11 12:14:25 -0400 | [diff] [blame] | 1458 | __buffer_unlock_commit(buffer, event); |
Arnaldo Carvalho de Melo | 51a763d | 2009-02-05 16:14:13 -0200 | [diff] [blame] | 1459 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1460 | ftrace_trace_stack(buffer, flags, 6, pc); |
| 1461 | ftrace_trace_userstack(buffer, flags, pc); |
Frederic Weisbecker | 07edf71 | 2009-03-22 23:10:46 +0100 | [diff] [blame] | 1462 | } |
| 1463 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1464 | void trace_buffer_unlock_commit(struct ring_buffer *buffer, |
| 1465 | struct ring_buffer_event *event, |
| 1466 | unsigned long flags, int pc) |
Frederic Weisbecker | 07edf71 | 2009-03-22 23:10:46 +0100 | [diff] [blame] | 1467 | { |
Steven Rostedt | 0d5c6e1 | 2012-11-01 20:54:21 -0400 | [diff] [blame] | 1468 | __trace_buffer_unlock_commit(buffer, event, flags, pc); |
Arnaldo Carvalho de Melo | 51a763d | 2009-02-05 16:14:13 -0200 | [diff] [blame] | 1469 | } |
Steven Rostedt | 0d5c6e1 | 2012-11-01 20:54:21 -0400 | [diff] [blame] | 1470 | EXPORT_SYMBOL_GPL(trace_buffer_unlock_commit); |
Arnaldo Carvalho de Melo | 51a763d | 2009-02-05 16:14:13 -0200 | [diff] [blame] | 1471 | |
Steven Rostedt | ef5580d | 2009-02-27 19:38:04 -0500 | [diff] [blame] | 1472 | struct ring_buffer_event * |
Steven Rostedt | ccb469a | 2012-08-02 10:32:10 -0400 | [diff] [blame] | 1473 | trace_event_buffer_lock_reserve(struct ring_buffer **current_rb, |
| 1474 | struct ftrace_event_file *ftrace_file, |
| 1475 | int type, unsigned long len, |
| 1476 | unsigned long flags, int pc) |
| 1477 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1478 | *current_rb = ftrace_file->tr->trace_buffer.buffer; |
Steven Rostedt | ccb469a | 2012-08-02 10:32:10 -0400 | [diff] [blame] | 1479 | return trace_buffer_lock_reserve(*current_rb, |
| 1480 | type, len, flags, pc); |
| 1481 | } |
| 1482 | EXPORT_SYMBOL_GPL(trace_event_buffer_lock_reserve); |
| 1483 | |
| 1484 | struct ring_buffer_event * |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1485 | trace_current_buffer_lock_reserve(struct ring_buffer **current_rb, |
| 1486 | int type, unsigned long len, |
Steven Rostedt | ef5580d | 2009-02-27 19:38:04 -0500 | [diff] [blame] | 1487 | unsigned long flags, int pc) |
| 1488 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1489 | *current_rb = global_trace.trace_buffer.buffer; |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1490 | return trace_buffer_lock_reserve(*current_rb, |
Steven Rostedt | ef5580d | 2009-02-27 19:38:04 -0500 | [diff] [blame] | 1491 | type, len, flags, pc); |
| 1492 | } |
Steven Rostedt | 94487d6 | 2009-05-05 19:22:53 -0400 | [diff] [blame] | 1493 | EXPORT_SYMBOL_GPL(trace_current_buffer_lock_reserve); |
Steven Rostedt | ef5580d | 2009-02-27 19:38:04 -0500 | [diff] [blame] | 1494 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1495 | void trace_current_buffer_unlock_commit(struct ring_buffer *buffer, |
| 1496 | struct ring_buffer_event *event, |
Steven Rostedt | ef5580d | 2009-02-27 19:38:04 -0500 | [diff] [blame] | 1497 | unsigned long flags, int pc) |
| 1498 | { |
Steven Rostedt | 0d5c6e1 | 2012-11-01 20:54:21 -0400 | [diff] [blame] | 1499 | __trace_buffer_unlock_commit(buffer, event, flags, pc); |
Frederic Weisbecker | 07edf71 | 2009-03-22 23:10:46 +0100 | [diff] [blame] | 1500 | } |
Steven Rostedt | 94487d6 | 2009-05-05 19:22:53 -0400 | [diff] [blame] | 1501 | EXPORT_SYMBOL_GPL(trace_current_buffer_unlock_commit); |
Frederic Weisbecker | 07edf71 | 2009-03-22 23:10:46 +0100 | [diff] [blame] | 1502 | |
Steven Rostedt | 0d5c6e1 | 2012-11-01 20:54:21 -0400 | [diff] [blame] | 1503 | void trace_buffer_unlock_commit_regs(struct ring_buffer *buffer, |
| 1504 | struct ring_buffer_event *event, |
| 1505 | unsigned long flags, int pc, |
| 1506 | struct pt_regs *regs) |
Masami Hiramatsu | 1fd8df2 | 2011-06-08 16:09:34 +0900 | [diff] [blame] | 1507 | { |
Steven Rostedt | 7ffbd48 | 2012-10-11 12:14:25 -0400 | [diff] [blame] | 1508 | __buffer_unlock_commit(buffer, event); |
Masami Hiramatsu | 1fd8df2 | 2011-06-08 16:09:34 +0900 | [diff] [blame] | 1509 | |
| 1510 | ftrace_trace_stack_regs(buffer, flags, 0, pc, regs); |
| 1511 | ftrace_trace_userstack(buffer, flags, pc); |
| 1512 | } |
Steven Rostedt | 0d5c6e1 | 2012-11-01 20:54:21 -0400 | [diff] [blame] | 1513 | EXPORT_SYMBOL_GPL(trace_buffer_unlock_commit_regs); |
Masami Hiramatsu | 1fd8df2 | 2011-06-08 16:09:34 +0900 | [diff] [blame] | 1514 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1515 | void trace_current_buffer_discard_commit(struct ring_buffer *buffer, |
| 1516 | struct ring_buffer_event *event) |
Steven Rostedt | 77d9f46 | 2009-04-02 01:16:59 -0400 | [diff] [blame] | 1517 | { |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1518 | ring_buffer_discard_commit(buffer, event); |
Steven Rostedt | ef5580d | 2009-02-27 19:38:04 -0500 | [diff] [blame] | 1519 | } |
Steven Rostedt | 12acd47 | 2009-04-17 16:01:56 -0400 | [diff] [blame] | 1520 | EXPORT_SYMBOL_GPL(trace_current_buffer_discard_commit); |
Steven Rostedt | ef5580d | 2009-02-27 19:38:04 -0500 | [diff] [blame] | 1521 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1522 | void |
Arnaldo Carvalho de Melo | 7be4215 | 2009-02-05 01:13:37 -0500 | [diff] [blame] | 1523 | trace_function(struct trace_array *tr, |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 1524 | unsigned long ip, unsigned long parent_ip, unsigned long flags, |
| 1525 | int pc) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1526 | { |
Tom Zanussi | e1112b4 | 2009-03-31 00:48:49 -0500 | [diff] [blame] | 1527 | struct ftrace_event_call *call = &event_function; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1528 | struct ring_buffer *buffer = tr->trace_buffer.buffer; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1529 | struct ring_buffer_event *event; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1530 | struct ftrace_entry *entry; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1531 | |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 1532 | /* If we are reading the ring buffer, don't trace */ |
Rusty Russell | dd17c8f | 2009-10-29 22:34:15 +0900 | [diff] [blame] | 1533 | if (unlikely(__this_cpu_read(ftrace_cpu_disabled))) |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 1534 | return; |
| 1535 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1536 | event = trace_buffer_lock_reserve(buffer, TRACE_FN, sizeof(*entry), |
Arnaldo Carvalho de Melo | 51a763d | 2009-02-05 16:14:13 -0200 | [diff] [blame] | 1537 | flags, pc); |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1538 | if (!event) |
| 1539 | return; |
| 1540 | entry = ring_buffer_event_data(event); |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1541 | entry->ip = ip; |
| 1542 | entry->parent_ip = parent_ip; |
Tom Zanussi | e1112b4 | 2009-03-31 00:48:49 -0500 | [diff] [blame] | 1543 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1544 | if (!filter_check_discard(call, entry, buffer, event)) |
Steven Rostedt | 7ffbd48 | 2012-10-11 12:14:25 -0400 | [diff] [blame] | 1545 | __buffer_unlock_commit(buffer, event); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1546 | } |
| 1547 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1548 | void |
Ingo Molnar | 2e0f576 | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 1549 | ftrace(struct trace_array *tr, struct trace_array_cpu *data, |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 1550 | unsigned long ip, unsigned long parent_ip, unsigned long flags, |
| 1551 | int pc) |
Ingo Molnar | 2e0f576 | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 1552 | { |
| 1553 | if (likely(!atomic_read(&data->disabled))) |
Arnaldo Carvalho de Melo | 7be4215 | 2009-02-05 01:13:37 -0500 | [diff] [blame] | 1554 | trace_function(tr, ip, parent_ip, flags, pc); |
Ingo Molnar | 2e0f576 | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 1555 | } |
| 1556 | |
Frederic Weisbecker | c0a0d0d | 2009-07-29 17:51:13 +0200 | [diff] [blame] | 1557 | #ifdef CONFIG_STACKTRACE |
Steven Rostedt | 4a9bd3f | 2011-07-14 16:36:53 -0400 | [diff] [blame] | 1558 | |
| 1559 | #define FTRACE_STACK_MAX_ENTRIES (PAGE_SIZE / sizeof(unsigned long)) |
| 1560 | struct ftrace_stack { |
| 1561 | unsigned long calls[FTRACE_STACK_MAX_ENTRIES]; |
| 1562 | }; |
| 1563 | |
| 1564 | static DEFINE_PER_CPU(struct ftrace_stack, ftrace_stack); |
| 1565 | static DEFINE_PER_CPU(int, ftrace_stack_reserve); |
| 1566 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1567 | static void __ftrace_trace_stack(struct ring_buffer *buffer, |
Steven Rostedt | 5361499 | 2009-01-15 19:12:40 -0500 | [diff] [blame] | 1568 | unsigned long flags, |
Masami Hiramatsu | 1fd8df2 | 2011-06-08 16:09:34 +0900 | [diff] [blame] | 1569 | int skip, int pc, struct pt_regs *regs) |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1570 | { |
Tom Zanussi | e1112b4 | 2009-03-31 00:48:49 -0500 | [diff] [blame] | 1571 | struct ftrace_event_call *call = &event_kernel_stack; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1572 | struct ring_buffer_event *event; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1573 | struct stack_entry *entry; |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1574 | struct stack_trace trace; |
Steven Rostedt | 4a9bd3f | 2011-07-14 16:36:53 -0400 | [diff] [blame] | 1575 | int use_stack; |
| 1576 | int size = FTRACE_STACK_ENTRIES; |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1577 | |
| 1578 | trace.nr_entries = 0; |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1579 | trace.skip = skip; |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1580 | |
Steven Rostedt | 4a9bd3f | 2011-07-14 16:36:53 -0400 | [diff] [blame] | 1581 | /* |
| 1582 | * Since events can happen in NMIs there's no safe way to |
| 1583 | * use the per cpu ftrace_stacks. We reserve it and if an interrupt |
| 1584 | * or NMI comes in, it will just have to use the default |
| 1585 | * FTRACE_STACK_SIZE. |
| 1586 | */ |
| 1587 | preempt_disable_notrace(); |
| 1588 | |
Shan Wei | 8214652 | 2012-11-19 13:21:01 +0800 | [diff] [blame] | 1589 | use_stack = __this_cpu_inc_return(ftrace_stack_reserve); |
Steven Rostedt | 4a9bd3f | 2011-07-14 16:36:53 -0400 | [diff] [blame] | 1590 | /* |
| 1591 | * We don't need any atomic variables, just a barrier. |
| 1592 | * If an interrupt comes in, we don't care, because it would |
| 1593 | * have exited and put the counter back to what we want. |
| 1594 | * We just need a barrier to keep gcc from moving things |
| 1595 | * around. |
| 1596 | */ |
| 1597 | barrier(); |
| 1598 | if (use_stack == 1) { |
| 1599 | trace.entries = &__get_cpu_var(ftrace_stack).calls[0]; |
| 1600 | trace.max_entries = FTRACE_STACK_MAX_ENTRIES; |
| 1601 | |
| 1602 | if (regs) |
| 1603 | save_stack_trace_regs(regs, &trace); |
| 1604 | else |
| 1605 | save_stack_trace(&trace); |
| 1606 | |
| 1607 | if (trace.nr_entries > size) |
| 1608 | size = trace.nr_entries; |
| 1609 | } else |
| 1610 | /* From now on, use_stack is a boolean */ |
| 1611 | use_stack = 0; |
| 1612 | |
| 1613 | size *= sizeof(unsigned long); |
| 1614 | |
| 1615 | event = trace_buffer_lock_reserve(buffer, TRACE_STACK, |
| 1616 | sizeof(*entry) + size, flags, pc); |
| 1617 | if (!event) |
| 1618 | goto out; |
| 1619 | entry = ring_buffer_event_data(event); |
| 1620 | |
| 1621 | memset(&entry->caller, 0, size); |
| 1622 | |
| 1623 | if (use_stack) |
| 1624 | memcpy(&entry->caller, trace.entries, |
| 1625 | trace.nr_entries * sizeof(unsigned long)); |
| 1626 | else { |
| 1627 | trace.max_entries = FTRACE_STACK_ENTRIES; |
| 1628 | trace.entries = entry->caller; |
| 1629 | if (regs) |
| 1630 | save_stack_trace_regs(regs, &trace); |
| 1631 | else |
| 1632 | save_stack_trace(&trace); |
| 1633 | } |
| 1634 | |
| 1635 | entry->size = trace.nr_entries; |
| 1636 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1637 | if (!filter_check_discard(call, entry, buffer, event)) |
Steven Rostedt | 7ffbd48 | 2012-10-11 12:14:25 -0400 | [diff] [blame] | 1638 | __buffer_unlock_commit(buffer, event); |
Steven Rostedt | 4a9bd3f | 2011-07-14 16:36:53 -0400 | [diff] [blame] | 1639 | |
| 1640 | out: |
| 1641 | /* Again, don't let gcc optimize things here */ |
| 1642 | barrier(); |
Shan Wei | 8214652 | 2012-11-19 13:21:01 +0800 | [diff] [blame] | 1643 | __this_cpu_dec(ftrace_stack_reserve); |
Steven Rostedt | 4a9bd3f | 2011-07-14 16:36:53 -0400 | [diff] [blame] | 1644 | preempt_enable_notrace(); |
| 1645 | |
Ingo Molnar | f0a920d | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 1646 | } |
| 1647 | |
Masami Hiramatsu | 1fd8df2 | 2011-06-08 16:09:34 +0900 | [diff] [blame] | 1648 | void ftrace_trace_stack_regs(struct ring_buffer *buffer, unsigned long flags, |
| 1649 | int skip, int pc, struct pt_regs *regs) |
| 1650 | { |
| 1651 | if (!(trace_flags & TRACE_ITER_STACKTRACE)) |
| 1652 | return; |
| 1653 | |
| 1654 | __ftrace_trace_stack(buffer, flags, skip, pc, regs); |
| 1655 | } |
| 1656 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1657 | void ftrace_trace_stack(struct ring_buffer *buffer, unsigned long flags, |
| 1658 | int skip, int pc) |
Steven Rostedt | 5361499 | 2009-01-15 19:12:40 -0500 | [diff] [blame] | 1659 | { |
| 1660 | if (!(trace_flags & TRACE_ITER_STACKTRACE)) |
| 1661 | return; |
| 1662 | |
Masami Hiramatsu | 1fd8df2 | 2011-06-08 16:09:34 +0900 | [diff] [blame] | 1663 | __ftrace_trace_stack(buffer, flags, skip, pc, NULL); |
Steven Rostedt | 5361499 | 2009-01-15 19:12:40 -0500 | [diff] [blame] | 1664 | } |
| 1665 | |
Frederic Weisbecker | c0a0d0d | 2009-07-29 17:51:13 +0200 | [diff] [blame] | 1666 | void __trace_stack(struct trace_array *tr, unsigned long flags, int skip, |
| 1667 | int pc) |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 1668 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1669 | __ftrace_trace_stack(tr->trace_buffer.buffer, flags, skip, pc, NULL); |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 1670 | } |
| 1671 | |
Steven Rostedt | 0388938 | 2009-12-11 09:48:22 -0500 | [diff] [blame] | 1672 | /** |
| 1673 | * trace_dump_stack - record a stack back trace in the trace buffer |
Steven Rostedt (Red Hat) | c142be8 | 2013-03-13 09:55:57 -0400 | [diff] [blame] | 1674 | * @skip: Number of functions to skip (helper handlers) |
Steven Rostedt | 0388938 | 2009-12-11 09:48:22 -0500 | [diff] [blame] | 1675 | */ |
Steven Rostedt (Red Hat) | c142be8 | 2013-03-13 09:55:57 -0400 | [diff] [blame] | 1676 | void trace_dump_stack(int skip) |
Steven Rostedt | 0388938 | 2009-12-11 09:48:22 -0500 | [diff] [blame] | 1677 | { |
| 1678 | unsigned long flags; |
| 1679 | |
| 1680 | if (tracing_disabled || tracing_selftest_running) |
Steven Rostedt | e36c545 | 2009-12-14 15:58:33 -0500 | [diff] [blame] | 1681 | return; |
Steven Rostedt | 0388938 | 2009-12-11 09:48:22 -0500 | [diff] [blame] | 1682 | |
| 1683 | local_save_flags(flags); |
| 1684 | |
Steven Rostedt (Red Hat) | c142be8 | 2013-03-13 09:55:57 -0400 | [diff] [blame] | 1685 | /* |
| 1686 | * Skip 3 more, seems to get us at the caller of |
| 1687 | * this function. |
| 1688 | */ |
| 1689 | skip += 3; |
| 1690 | __ftrace_trace_stack(global_trace.trace_buffer.buffer, |
| 1691 | flags, skip, preempt_count(), NULL); |
Steven Rostedt | 0388938 | 2009-12-11 09:48:22 -0500 | [diff] [blame] | 1692 | } |
| 1693 | |
Steven Rostedt | 91e86e5 | 2010-11-10 12:56:12 +0100 | [diff] [blame] | 1694 | static DEFINE_PER_CPU(int, user_stack_count); |
| 1695 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1696 | void |
| 1697 | ftrace_trace_userstack(struct ring_buffer *buffer, unsigned long flags, int pc) |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 1698 | { |
Tom Zanussi | e1112b4 | 2009-03-31 00:48:49 -0500 | [diff] [blame] | 1699 | struct ftrace_event_call *call = &event_user_stack; |
Török Edwin | 8d7c6a9 | 2008-11-23 12:39:06 +0200 | [diff] [blame] | 1700 | struct ring_buffer_event *event; |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 1701 | struct userstack_entry *entry; |
| 1702 | struct stack_trace trace; |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 1703 | |
| 1704 | if (!(trace_flags & TRACE_ITER_USERSTACKTRACE)) |
| 1705 | return; |
| 1706 | |
Steven Rostedt | b634587 | 2010-03-12 20:03:30 -0500 | [diff] [blame] | 1707 | /* |
| 1708 | * NMIs can not handle page faults, even with fix ups. |
| 1709 | * The save user stack can (and often does) fault. |
| 1710 | */ |
| 1711 | if (unlikely(in_nmi())) |
| 1712 | return; |
| 1713 | |
Steven Rostedt | 91e86e5 | 2010-11-10 12:56:12 +0100 | [diff] [blame] | 1714 | /* |
| 1715 | * prevent recursion, since the user stack tracing may |
| 1716 | * trigger other kernel events. |
| 1717 | */ |
| 1718 | preempt_disable(); |
| 1719 | if (__this_cpu_read(user_stack_count)) |
| 1720 | goto out; |
| 1721 | |
| 1722 | __this_cpu_inc(user_stack_count); |
| 1723 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1724 | event = trace_buffer_lock_reserve(buffer, TRACE_USER_STACK, |
Arnaldo Carvalho de Melo | 51a763d | 2009-02-05 16:14:13 -0200 | [diff] [blame] | 1725 | sizeof(*entry), flags, pc); |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 1726 | if (!event) |
Li Zefan | 1dbd195 | 2010-12-09 15:47:56 +0800 | [diff] [blame] | 1727 | goto out_drop_count; |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 1728 | entry = ring_buffer_event_data(event); |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 1729 | |
Steven Rostedt | 48659d3 | 2009-09-11 11:36:23 -0400 | [diff] [blame] | 1730 | entry->tgid = current->tgid; |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 1731 | memset(&entry->caller, 0, sizeof(entry->caller)); |
| 1732 | |
| 1733 | trace.nr_entries = 0; |
| 1734 | trace.max_entries = FTRACE_STACK_ENTRIES; |
| 1735 | trace.skip = 0; |
| 1736 | trace.entries = entry->caller; |
| 1737 | |
| 1738 | save_stack_trace_user(&trace); |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1739 | if (!filter_check_discard(call, entry, buffer, event)) |
Steven Rostedt | 7ffbd48 | 2012-10-11 12:14:25 -0400 | [diff] [blame] | 1740 | __buffer_unlock_commit(buffer, event); |
Steven Rostedt | 91e86e5 | 2010-11-10 12:56:12 +0100 | [diff] [blame] | 1741 | |
Li Zefan | 1dbd195 | 2010-12-09 15:47:56 +0800 | [diff] [blame] | 1742 | out_drop_count: |
Steven Rostedt | 91e86e5 | 2010-11-10 12:56:12 +0100 | [diff] [blame] | 1743 | __this_cpu_dec(user_stack_count); |
Steven Rostedt | 91e86e5 | 2010-11-10 12:56:12 +0100 | [diff] [blame] | 1744 | out: |
| 1745 | preempt_enable(); |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 1746 | } |
| 1747 | |
Hannes Eder | 4fd2735 | 2009-02-10 19:44:12 +0100 | [diff] [blame] | 1748 | #ifdef UNUSED |
| 1749 | static void __trace_userstack(struct trace_array *tr, unsigned long flags) |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 1750 | { |
Arnaldo Carvalho de Melo | 7be4215 | 2009-02-05 01:13:37 -0500 | [diff] [blame] | 1751 | ftrace_trace_userstack(tr, flags, preempt_count()); |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 1752 | } |
Hannes Eder | 4fd2735 | 2009-02-10 19:44:12 +0100 | [diff] [blame] | 1753 | #endif /* UNUSED */ |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 1754 | |
Frederic Weisbecker | c0a0d0d | 2009-07-29 17:51:13 +0200 | [diff] [blame] | 1755 | #endif /* CONFIG_STACKTRACE */ |
| 1756 | |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 1757 | /* created for use with alloc_percpu */ |
| 1758 | struct trace_buffer_struct { |
| 1759 | char buffer[TRACE_BUF_SIZE]; |
| 1760 | }; |
| 1761 | |
| 1762 | static struct trace_buffer_struct *trace_percpu_buffer; |
| 1763 | static struct trace_buffer_struct *trace_percpu_sirq_buffer; |
| 1764 | static struct trace_buffer_struct *trace_percpu_irq_buffer; |
| 1765 | static struct trace_buffer_struct *trace_percpu_nmi_buffer; |
| 1766 | |
| 1767 | /* |
| 1768 | * The buffer used is dependent on the context. There is a per cpu |
| 1769 | * buffer for normal context, softirq contex, hard irq context and |
| 1770 | * for NMI context. Thise allows for lockless recording. |
| 1771 | * |
| 1772 | * Note, if the buffers failed to be allocated, then this returns NULL |
| 1773 | */ |
| 1774 | static char *get_trace_buf(void) |
| 1775 | { |
| 1776 | struct trace_buffer_struct *percpu_buffer; |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 1777 | |
| 1778 | /* |
| 1779 | * If we have allocated per cpu buffers, then we do not |
| 1780 | * need to do any locking. |
| 1781 | */ |
| 1782 | if (in_nmi()) |
| 1783 | percpu_buffer = trace_percpu_nmi_buffer; |
| 1784 | else if (in_irq()) |
| 1785 | percpu_buffer = trace_percpu_irq_buffer; |
| 1786 | else if (in_softirq()) |
| 1787 | percpu_buffer = trace_percpu_sirq_buffer; |
| 1788 | else |
| 1789 | percpu_buffer = trace_percpu_buffer; |
| 1790 | |
| 1791 | if (!percpu_buffer) |
| 1792 | return NULL; |
| 1793 | |
Shan Wei | d8a0349 | 2012-11-13 09:53:04 +0800 | [diff] [blame] | 1794 | return this_cpu_ptr(&percpu_buffer->buffer[0]); |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 1795 | } |
| 1796 | |
| 1797 | static int alloc_percpu_trace_buffer(void) |
| 1798 | { |
| 1799 | struct trace_buffer_struct *buffers; |
| 1800 | struct trace_buffer_struct *sirq_buffers; |
| 1801 | struct trace_buffer_struct *irq_buffers; |
| 1802 | struct trace_buffer_struct *nmi_buffers; |
| 1803 | |
| 1804 | buffers = alloc_percpu(struct trace_buffer_struct); |
| 1805 | if (!buffers) |
| 1806 | goto err_warn; |
| 1807 | |
| 1808 | sirq_buffers = alloc_percpu(struct trace_buffer_struct); |
| 1809 | if (!sirq_buffers) |
| 1810 | goto err_sirq; |
| 1811 | |
| 1812 | irq_buffers = alloc_percpu(struct trace_buffer_struct); |
| 1813 | if (!irq_buffers) |
| 1814 | goto err_irq; |
| 1815 | |
| 1816 | nmi_buffers = alloc_percpu(struct trace_buffer_struct); |
| 1817 | if (!nmi_buffers) |
| 1818 | goto err_nmi; |
| 1819 | |
| 1820 | trace_percpu_buffer = buffers; |
| 1821 | trace_percpu_sirq_buffer = sirq_buffers; |
| 1822 | trace_percpu_irq_buffer = irq_buffers; |
| 1823 | trace_percpu_nmi_buffer = nmi_buffers; |
| 1824 | |
| 1825 | return 0; |
| 1826 | |
| 1827 | err_nmi: |
| 1828 | free_percpu(irq_buffers); |
| 1829 | err_irq: |
| 1830 | free_percpu(sirq_buffers); |
| 1831 | err_sirq: |
| 1832 | free_percpu(buffers); |
| 1833 | err_warn: |
| 1834 | WARN(1, "Could not allocate percpu trace_printk buffer"); |
| 1835 | return -ENOMEM; |
| 1836 | } |
| 1837 | |
Steven Rostedt | 8169883 | 2012-10-11 10:15:05 -0400 | [diff] [blame] | 1838 | static int buffers_allocated; |
| 1839 | |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 1840 | void trace_printk_init_buffers(void) |
| 1841 | { |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 1842 | if (buffers_allocated) |
| 1843 | return; |
| 1844 | |
| 1845 | if (alloc_percpu_trace_buffer()) |
| 1846 | return; |
| 1847 | |
| 1848 | pr_info("ftrace: Allocated trace_printk buffers\n"); |
| 1849 | |
Steven Rostedt | b382ede6 | 2012-10-10 21:44:34 -0400 | [diff] [blame] | 1850 | /* Expand the buffers to set size */ |
| 1851 | tracing_update_buffers(); |
| 1852 | |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 1853 | buffers_allocated = 1; |
Steven Rostedt | 8169883 | 2012-10-11 10:15:05 -0400 | [diff] [blame] | 1854 | |
| 1855 | /* |
| 1856 | * trace_printk_init_buffers() can be called by modules. |
| 1857 | * If that happens, then we need to start cmdline recording |
| 1858 | * directly here. If the global_trace.buffer is already |
| 1859 | * allocated here, then this was called by module code. |
| 1860 | */ |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1861 | if (global_trace.trace_buffer.buffer) |
Steven Rostedt | 8169883 | 2012-10-11 10:15:05 -0400 | [diff] [blame] | 1862 | tracing_start_cmdline_record(); |
| 1863 | } |
| 1864 | |
| 1865 | void trace_printk_start_comm(void) |
| 1866 | { |
| 1867 | /* Start tracing comms if trace printk is set */ |
| 1868 | if (!buffers_allocated) |
| 1869 | return; |
| 1870 | tracing_start_cmdline_record(); |
| 1871 | } |
| 1872 | |
| 1873 | static void trace_printk_start_stop_comm(int enabled) |
| 1874 | { |
| 1875 | if (!buffers_allocated) |
| 1876 | return; |
| 1877 | |
| 1878 | if (enabled) |
| 1879 | tracing_start_cmdline_record(); |
| 1880 | else |
| 1881 | tracing_stop_cmdline_record(); |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 1882 | } |
| 1883 | |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 1884 | /** |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 1885 | * trace_vbprintk - write binary msg to tracing buffer |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 1886 | * |
| 1887 | */ |
Steven Rostedt | 40ce74f | 2009-03-19 14:03:53 -0400 | [diff] [blame] | 1888 | int trace_vbprintk(unsigned long ip, const char *fmt, va_list args) |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 1889 | { |
Tom Zanussi | e1112b4 | 2009-03-31 00:48:49 -0500 | [diff] [blame] | 1890 | struct ftrace_event_call *call = &event_bprint; |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 1891 | struct ring_buffer_event *event; |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1892 | struct ring_buffer *buffer; |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 1893 | struct trace_array *tr = &global_trace; |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 1894 | struct bprint_entry *entry; |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 1895 | unsigned long flags; |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 1896 | char *tbuffer; |
| 1897 | int len = 0, size, pc; |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 1898 | |
| 1899 | if (unlikely(tracing_selftest_running || tracing_disabled)) |
| 1900 | return 0; |
| 1901 | |
| 1902 | /* Don't pollute graph traces with trace_vprintk internals */ |
| 1903 | pause_graph_tracing(); |
| 1904 | |
| 1905 | pc = preempt_count(); |
Steven Rostedt | 5168ae5 | 2010-06-03 09:36:50 -0400 | [diff] [blame] | 1906 | preempt_disable_notrace(); |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 1907 | |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 1908 | tbuffer = get_trace_buf(); |
| 1909 | if (!tbuffer) { |
| 1910 | len = 0; |
| 1911 | goto out; |
| 1912 | } |
| 1913 | |
| 1914 | len = vbin_printf((u32 *)tbuffer, TRACE_BUF_SIZE/sizeof(int), fmt, args); |
| 1915 | |
| 1916 | if (len > TRACE_BUF_SIZE/sizeof(int) || len < 0) |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 1917 | goto out; |
| 1918 | |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 1919 | local_save_flags(flags); |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 1920 | size = sizeof(*entry) + sizeof(u32) * len; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1921 | buffer = tr->trace_buffer.buffer; |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1922 | event = trace_buffer_lock_reserve(buffer, TRACE_BPRINT, size, |
| 1923 | flags, pc); |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 1924 | if (!event) |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 1925 | goto out; |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 1926 | entry = ring_buffer_event_data(event); |
| 1927 | entry->ip = ip; |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 1928 | entry->fmt = fmt; |
| 1929 | |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 1930 | memcpy(entry->buf, tbuffer, sizeof(u32) * len); |
Steven Rostedt | d931369 | 2010-01-06 17:27:11 -0500 | [diff] [blame] | 1931 | if (!filter_check_discard(call, entry, buffer, event)) { |
Steven Rostedt | 7ffbd48 | 2012-10-11 12:14:25 -0400 | [diff] [blame] | 1932 | __buffer_unlock_commit(buffer, event); |
Steven Rostedt | d931369 | 2010-01-06 17:27:11 -0500 | [diff] [blame] | 1933 | ftrace_trace_stack(buffer, flags, 6, pc); |
| 1934 | } |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 1935 | |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 1936 | out: |
Steven Rostedt | 5168ae5 | 2010-06-03 09:36:50 -0400 | [diff] [blame] | 1937 | preempt_enable_notrace(); |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 1938 | unpause_graph_tracing(); |
| 1939 | |
| 1940 | return len; |
| 1941 | } |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 1942 | EXPORT_SYMBOL_GPL(trace_vbprintk); |
| 1943 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1944 | static int |
| 1945 | __trace_array_vprintk(struct ring_buffer *buffer, |
| 1946 | unsigned long ip, const char *fmt, va_list args) |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 1947 | { |
Tom Zanussi | e1112b4 | 2009-03-31 00:48:49 -0500 | [diff] [blame] | 1948 | struct ftrace_event_call *call = &event_print; |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 1949 | struct ring_buffer_event *event; |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 1950 | int len = 0, size, pc; |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 1951 | struct print_entry *entry; |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 1952 | unsigned long flags; |
| 1953 | char *tbuffer; |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 1954 | |
| 1955 | if (tracing_disabled || tracing_selftest_running) |
| 1956 | return 0; |
| 1957 | |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 1958 | /* Don't pollute graph traces with trace_vprintk internals */ |
| 1959 | pause_graph_tracing(); |
| 1960 | |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 1961 | pc = preempt_count(); |
| 1962 | preempt_disable_notrace(); |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 1963 | |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 1964 | |
| 1965 | tbuffer = get_trace_buf(); |
| 1966 | if (!tbuffer) { |
| 1967 | len = 0; |
| 1968 | goto out; |
| 1969 | } |
| 1970 | |
| 1971 | len = vsnprintf(tbuffer, TRACE_BUF_SIZE, fmt, args); |
| 1972 | if (len > TRACE_BUF_SIZE) |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 1973 | goto out; |
| 1974 | |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 1975 | local_save_flags(flags); |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 1976 | size = sizeof(*entry) + len + 1; |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1977 | event = trace_buffer_lock_reserve(buffer, TRACE_PRINT, size, |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 1978 | flags, pc); |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 1979 | if (!event) |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 1980 | goto out; |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 1981 | entry = ring_buffer_event_data(event); |
Carsten Emde | c13d2f7 | 2009-11-16 20:56:13 +0100 | [diff] [blame] | 1982 | entry->ip = ip; |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 1983 | |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 1984 | memcpy(&entry->buf, tbuffer, len); |
Carsten Emde | c13d2f7 | 2009-11-16 20:56:13 +0100 | [diff] [blame] | 1985 | entry->buf[len] = '\0'; |
Steven Rostedt | d931369 | 2010-01-06 17:27:11 -0500 | [diff] [blame] | 1986 | if (!filter_check_discard(call, entry, buffer, event)) { |
Steven Rostedt | 7ffbd48 | 2012-10-11 12:14:25 -0400 | [diff] [blame] | 1987 | __buffer_unlock_commit(buffer, event); |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 1988 | ftrace_trace_stack(buffer, flags, 6, pc); |
Steven Rostedt | d931369 | 2010-01-06 17:27:11 -0500 | [diff] [blame] | 1989 | } |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 1990 | out: |
| 1991 | preempt_enable_notrace(); |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 1992 | unpause_graph_tracing(); |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 1993 | |
| 1994 | return len; |
| 1995 | } |
Steven Rostedt | 659372d | 2009-09-03 19:11:07 -0400 | [diff] [blame] | 1996 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1997 | int trace_array_vprintk(struct trace_array *tr, |
| 1998 | unsigned long ip, const char *fmt, va_list args) |
| 1999 | { |
| 2000 | return __trace_array_vprintk(tr->trace_buffer.buffer, ip, fmt, args); |
| 2001 | } |
| 2002 | |
| 2003 | int trace_array_printk(struct trace_array *tr, |
| 2004 | unsigned long ip, const char *fmt, ...) |
| 2005 | { |
| 2006 | int ret; |
| 2007 | va_list ap; |
| 2008 | |
| 2009 | if (!(trace_flags & TRACE_ITER_PRINTK)) |
| 2010 | return 0; |
| 2011 | |
| 2012 | va_start(ap, fmt); |
| 2013 | ret = trace_array_vprintk(tr, ip, fmt, ap); |
| 2014 | va_end(ap); |
| 2015 | return ret; |
| 2016 | } |
| 2017 | |
| 2018 | int trace_array_printk_buf(struct ring_buffer *buffer, |
| 2019 | unsigned long ip, const char *fmt, ...) |
| 2020 | { |
| 2021 | int ret; |
| 2022 | va_list ap; |
| 2023 | |
| 2024 | if (!(trace_flags & TRACE_ITER_PRINTK)) |
| 2025 | return 0; |
| 2026 | |
| 2027 | va_start(ap, fmt); |
| 2028 | ret = __trace_array_vprintk(buffer, ip, fmt, ap); |
| 2029 | va_end(ap); |
| 2030 | return ret; |
| 2031 | } |
| 2032 | |
Steven Rostedt | 659372d | 2009-09-03 19:11:07 -0400 | [diff] [blame] | 2033 | int trace_vprintk(unsigned long ip, const char *fmt, va_list args) |
| 2034 | { |
Steven Rostedt | a813a15 | 2009-10-09 01:41:35 -0400 | [diff] [blame] | 2035 | return trace_array_vprintk(&global_trace, ip, fmt, args); |
Steven Rostedt | 659372d | 2009-09-03 19:11:07 -0400 | [diff] [blame] | 2036 | } |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 2037 | EXPORT_SYMBOL_GPL(trace_vprintk); |
| 2038 | |
Robert Richter | e2ac8ef | 2008-11-12 12:59:32 +0100 | [diff] [blame] | 2039 | static void trace_iterator_increment(struct trace_iterator *iter) |
Steven Rostedt | 5a90f57 | 2008-09-03 17:42:51 -0400 | [diff] [blame] | 2040 | { |
Steven Rostedt | 6d158a8 | 2012-06-27 20:46:14 -0400 | [diff] [blame] | 2041 | struct ring_buffer_iter *buf_iter = trace_buffer_iter(iter, iter->cpu); |
| 2042 | |
Steven Rostedt | 5a90f57 | 2008-09-03 17:42:51 -0400 | [diff] [blame] | 2043 | iter->idx++; |
Steven Rostedt | 6d158a8 | 2012-06-27 20:46:14 -0400 | [diff] [blame] | 2044 | if (buf_iter) |
| 2045 | ring_buffer_read(buf_iter, NULL); |
Steven Rostedt | 5a90f57 | 2008-09-03 17:42:51 -0400 | [diff] [blame] | 2046 | } |
| 2047 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 2048 | static struct trace_entry * |
Steven Rostedt | bc21b47 | 2010-03-31 19:49:26 -0400 | [diff] [blame] | 2049 | peek_next_entry(struct trace_iterator *iter, int cpu, u64 *ts, |
| 2050 | unsigned long *lost_events) |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2051 | { |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2052 | struct ring_buffer_event *event; |
Steven Rostedt | 6d158a8 | 2012-06-27 20:46:14 -0400 | [diff] [blame] | 2053 | struct ring_buffer_iter *buf_iter = trace_buffer_iter(iter, cpu); |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2054 | |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 2055 | if (buf_iter) |
| 2056 | event = ring_buffer_iter_peek(buf_iter, ts); |
| 2057 | else |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2058 | event = ring_buffer_peek(iter->trace_buffer->buffer, cpu, ts, |
Steven Rostedt | bc21b47 | 2010-03-31 19:49:26 -0400 | [diff] [blame] | 2059 | lost_events); |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 2060 | |
Steven Rostedt | 4a9bd3f | 2011-07-14 16:36:53 -0400 | [diff] [blame] | 2061 | if (event) { |
| 2062 | iter->ent_size = ring_buffer_event_length(event); |
| 2063 | return ring_buffer_event_data(event); |
| 2064 | } |
| 2065 | iter->ent_size = 0; |
| 2066 | return NULL; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2067 | } |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 2068 | |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2069 | static struct trace_entry * |
Steven Rostedt | bc21b47 | 2010-03-31 19:49:26 -0400 | [diff] [blame] | 2070 | __find_next_entry(struct trace_iterator *iter, int *ent_cpu, |
| 2071 | unsigned long *missing_events, u64 *ent_ts) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2072 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2073 | struct ring_buffer *buffer = iter->trace_buffer->buffer; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2074 | struct trace_entry *ent, *next = NULL; |
Lai Jiangshan | aa27497 | 2010-04-05 17:11:05 +0800 | [diff] [blame] | 2075 | unsigned long lost_events = 0, next_lost = 0; |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 2076 | int cpu_file = iter->cpu_file; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2077 | u64 next_ts = 0, ts; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2078 | int next_cpu = -1; |
Steven Rostedt | 12b5da3 | 2012-03-27 10:43:28 -0400 | [diff] [blame] | 2079 | int next_size = 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2080 | int cpu; |
| 2081 | |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 2082 | /* |
| 2083 | * If we are in a per_cpu trace file, don't bother by iterating over |
| 2084 | * all cpu and peek directly. |
| 2085 | */ |
Steven Rostedt | ae3b509 | 2013-01-23 15:22:59 -0500 | [diff] [blame] | 2086 | if (cpu_file > RING_BUFFER_ALL_CPUS) { |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 2087 | if (ring_buffer_empty_cpu(buffer, cpu_file)) |
| 2088 | return NULL; |
Steven Rostedt | bc21b47 | 2010-03-31 19:49:26 -0400 | [diff] [blame] | 2089 | ent = peek_next_entry(iter, cpu_file, ent_ts, missing_events); |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 2090 | if (ent_cpu) |
| 2091 | *ent_cpu = cpu_file; |
| 2092 | |
| 2093 | return ent; |
| 2094 | } |
| 2095 | |
Steven Rostedt | ab46428 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 2096 | for_each_tracing_cpu(cpu) { |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2097 | |
| 2098 | if (ring_buffer_empty_cpu(buffer, cpu)) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2099 | continue; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2100 | |
Steven Rostedt | bc21b47 | 2010-03-31 19:49:26 -0400 | [diff] [blame] | 2101 | ent = peek_next_entry(iter, cpu, &ts, &lost_events); |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2102 | |
Ingo Molnar | cdd31cd2 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2103 | /* |
| 2104 | * Pick the entry with the smallest timestamp: |
| 2105 | */ |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2106 | if (ent && (!next || ts < next_ts)) { |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2107 | next = ent; |
| 2108 | next_cpu = cpu; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2109 | next_ts = ts; |
Steven Rostedt | bc21b47 | 2010-03-31 19:49:26 -0400 | [diff] [blame] | 2110 | next_lost = lost_events; |
Steven Rostedt | 12b5da3 | 2012-03-27 10:43:28 -0400 | [diff] [blame] | 2111 | next_size = iter->ent_size; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2112 | } |
| 2113 | } |
| 2114 | |
Steven Rostedt | 12b5da3 | 2012-03-27 10:43:28 -0400 | [diff] [blame] | 2115 | iter->ent_size = next_size; |
| 2116 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2117 | if (ent_cpu) |
| 2118 | *ent_cpu = next_cpu; |
| 2119 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2120 | if (ent_ts) |
| 2121 | *ent_ts = next_ts; |
| 2122 | |
Steven Rostedt | bc21b47 | 2010-03-31 19:49:26 -0400 | [diff] [blame] | 2123 | if (missing_events) |
| 2124 | *missing_events = next_lost; |
| 2125 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2126 | return next; |
| 2127 | } |
| 2128 | |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2129 | /* Find the next real entry, without updating the iterator itself */ |
Frederic Weisbecker | c4a8e8b | 2009-02-02 20:29:21 -0200 | [diff] [blame] | 2130 | struct trace_entry *trace_find_next_entry(struct trace_iterator *iter, |
| 2131 | int *ent_cpu, u64 *ent_ts) |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2132 | { |
Steven Rostedt | bc21b47 | 2010-03-31 19:49:26 -0400 | [diff] [blame] | 2133 | return __find_next_entry(iter, ent_cpu, NULL, ent_ts); |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2134 | } |
Ingo Molnar | 8c523a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2135 | |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2136 | /* Find the next real entry, and increment the iterator to the next entry */ |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 2137 | void *trace_find_next_entry_inc(struct trace_iterator *iter) |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2138 | { |
Steven Rostedt | bc21b47 | 2010-03-31 19:49:26 -0400 | [diff] [blame] | 2139 | iter->ent = __find_next_entry(iter, &iter->cpu, |
| 2140 | &iter->lost_events, &iter->ts); |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2141 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2142 | if (iter->ent) |
Robert Richter | e2ac8ef | 2008-11-12 12:59:32 +0100 | [diff] [blame] | 2143 | trace_iterator_increment(iter); |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2144 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2145 | return iter->ent ? iter : NULL; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2146 | } |
| 2147 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 2148 | static void trace_consume(struct trace_iterator *iter) |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2149 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2150 | ring_buffer_consume(iter->trace_buffer->buffer, iter->cpu, &iter->ts, |
Steven Rostedt | bc21b47 | 2010-03-31 19:49:26 -0400 | [diff] [blame] | 2151 | &iter->lost_events); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2152 | } |
| 2153 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 2154 | static void *s_next(struct seq_file *m, void *v, loff_t *pos) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2155 | { |
| 2156 | struct trace_iterator *iter = m->private; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2157 | int i = (int)*pos; |
Ingo Molnar | 4e3c333 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 2158 | void *ent; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2159 | |
Steven Rostedt | a63ce5b | 2009-12-07 09:11:39 -0500 | [diff] [blame] | 2160 | WARN_ON_ONCE(iter->leftover); |
| 2161 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2162 | (*pos)++; |
| 2163 | |
| 2164 | /* can't go backwards */ |
| 2165 | if (iter->idx > i) |
| 2166 | return NULL; |
| 2167 | |
| 2168 | if (iter->idx < 0) |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 2169 | ent = trace_find_next_entry_inc(iter); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2170 | else |
| 2171 | ent = iter; |
| 2172 | |
| 2173 | while (ent && iter->idx < i) |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 2174 | ent = trace_find_next_entry_inc(iter); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2175 | |
| 2176 | iter->pos = *pos; |
| 2177 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2178 | return ent; |
| 2179 | } |
| 2180 | |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 2181 | void tracing_iter_reset(struct trace_iterator *iter, int cpu) |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 2182 | { |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 2183 | struct ring_buffer_event *event; |
| 2184 | struct ring_buffer_iter *buf_iter; |
| 2185 | unsigned long entries = 0; |
| 2186 | u64 ts; |
| 2187 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2188 | per_cpu_ptr(iter->trace_buffer->data, cpu)->skipped_entries = 0; |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 2189 | |
Steven Rostedt | 6d158a8 | 2012-06-27 20:46:14 -0400 | [diff] [blame] | 2190 | buf_iter = trace_buffer_iter(iter, cpu); |
| 2191 | if (!buf_iter) |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 2192 | return; |
| 2193 | |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 2194 | ring_buffer_iter_reset(buf_iter); |
| 2195 | |
| 2196 | /* |
| 2197 | * We could have the case with the max latency tracers |
| 2198 | * that a reset never took place on a cpu. This is evident |
| 2199 | * by the timestamp being before the start of the buffer. |
| 2200 | */ |
| 2201 | while ((event = ring_buffer_iter_peek(buf_iter, &ts))) { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2202 | if (ts >= iter->trace_buffer->time_start) |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 2203 | break; |
| 2204 | entries++; |
| 2205 | ring_buffer_read(buf_iter, NULL); |
| 2206 | } |
| 2207 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2208 | per_cpu_ptr(iter->trace_buffer->data, cpu)->skipped_entries = entries; |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 2209 | } |
| 2210 | |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 2211 | /* |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 2212 | * The current tracer is copied to avoid a global locking |
| 2213 | * all around. |
| 2214 | */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2215 | static void *s_start(struct seq_file *m, loff_t *pos) |
| 2216 | { |
| 2217 | struct trace_iterator *iter = m->private; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 2218 | struct trace_array *tr = iter->tr; |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 2219 | int cpu_file = iter->cpu_file; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2220 | void *p = NULL; |
| 2221 | loff_t l = 0; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2222 | int cpu; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2223 | |
Hiraku Toyooka | 2fd196e | 2012-12-26 11:52:52 +0900 | [diff] [blame] | 2224 | /* |
| 2225 | * copy the tracer to avoid using a global lock all around. |
| 2226 | * iter->trace is a copy of current_trace, the pointer to the |
| 2227 | * name may be used instead of a strcmp(), as iter->trace->name |
| 2228 | * will point to the same string as current_trace->name. |
| 2229 | */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2230 | mutex_lock(&trace_types_lock); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 2231 | if (unlikely(tr->current_trace && iter->trace->name != tr->current_trace->name)) |
| 2232 | *iter->trace = *tr->current_trace; |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 2233 | mutex_unlock(&trace_types_lock); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2234 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2235 | #ifdef CONFIG_TRACER_MAX_TRACE |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 2236 | if (iter->snapshot && iter->trace->use_max_tr) |
| 2237 | return ERR_PTR(-EBUSY); |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2238 | #endif |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 2239 | |
| 2240 | if (!iter->snapshot) |
| 2241 | atomic_inc(&trace_record_cmdline_disabled); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2242 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2243 | if (*pos != iter->pos) { |
| 2244 | iter->ent = NULL; |
| 2245 | iter->cpu = 0; |
| 2246 | iter->idx = -1; |
| 2247 | |
Steven Rostedt | ae3b509 | 2013-01-23 15:22:59 -0500 | [diff] [blame] | 2248 | if (cpu_file == RING_BUFFER_ALL_CPUS) { |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 2249 | for_each_tracing_cpu(cpu) |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 2250 | tracing_iter_reset(iter, cpu); |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 2251 | } else |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 2252 | tracing_iter_reset(iter, cpu_file); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2253 | |
Lai Jiangshan | ac91d85 | 2010-03-02 17:54:50 +0800 | [diff] [blame] | 2254 | iter->leftover = 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2255 | for (p = iter; p && l < *pos; p = s_next(m, p, &l)) |
| 2256 | ; |
| 2257 | |
| 2258 | } else { |
Steven Rostedt | a63ce5b | 2009-12-07 09:11:39 -0500 | [diff] [blame] | 2259 | /* |
| 2260 | * If we overflowed the seq_file before, then we want |
| 2261 | * to just reuse the trace_seq buffer again. |
| 2262 | */ |
| 2263 | if (iter->leftover) |
| 2264 | p = iter; |
| 2265 | else { |
| 2266 | l = *pos - 1; |
| 2267 | p = s_next(m, p, &l); |
| 2268 | } |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2269 | } |
| 2270 | |
Lai Jiangshan | 4f53596 | 2009-05-18 19:35:34 +0800 | [diff] [blame] | 2271 | trace_event_read_lock(); |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 2272 | trace_access_lock(cpu_file); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2273 | return p; |
| 2274 | } |
| 2275 | |
| 2276 | static void s_stop(struct seq_file *m, void *p) |
| 2277 | { |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 2278 | struct trace_iterator *iter = m->private; |
| 2279 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2280 | #ifdef CONFIG_TRACER_MAX_TRACE |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 2281 | if (iter->snapshot && iter->trace->use_max_tr) |
| 2282 | return; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2283 | #endif |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 2284 | |
| 2285 | if (!iter->snapshot) |
| 2286 | atomic_dec(&trace_record_cmdline_disabled); |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2287 | |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 2288 | trace_access_unlock(iter->cpu_file); |
Lai Jiangshan | 4f53596 | 2009-05-18 19:35:34 +0800 | [diff] [blame] | 2289 | trace_event_read_unlock(); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2290 | } |
| 2291 | |
Steven Rostedt | 39eaf7e | 2011-11-17 10:35:16 -0500 | [diff] [blame] | 2292 | static void |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2293 | get_total_entries(struct trace_buffer *buf, |
| 2294 | unsigned long *total, unsigned long *entries) |
Steven Rostedt | 39eaf7e | 2011-11-17 10:35:16 -0500 | [diff] [blame] | 2295 | { |
| 2296 | unsigned long count; |
| 2297 | int cpu; |
| 2298 | |
| 2299 | *total = 0; |
| 2300 | *entries = 0; |
| 2301 | |
| 2302 | for_each_tracing_cpu(cpu) { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2303 | count = ring_buffer_entries_cpu(buf->buffer, cpu); |
Steven Rostedt | 39eaf7e | 2011-11-17 10:35:16 -0500 | [diff] [blame] | 2304 | /* |
| 2305 | * If this buffer has skipped entries, then we hold all |
| 2306 | * entries for the trace and we need to ignore the |
| 2307 | * ones before the time stamp. |
| 2308 | */ |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2309 | if (per_cpu_ptr(buf->data, cpu)->skipped_entries) { |
| 2310 | count -= per_cpu_ptr(buf->data, cpu)->skipped_entries; |
Steven Rostedt | 39eaf7e | 2011-11-17 10:35:16 -0500 | [diff] [blame] | 2311 | /* total is the same as the entries */ |
| 2312 | *total += count; |
| 2313 | } else |
| 2314 | *total += count + |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2315 | ring_buffer_overrun_cpu(buf->buffer, cpu); |
Steven Rostedt | 39eaf7e | 2011-11-17 10:35:16 -0500 | [diff] [blame] | 2316 | *entries += count; |
| 2317 | } |
| 2318 | } |
| 2319 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 2320 | static void print_lat_help_header(struct seq_file *m) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2321 | { |
Michael Ellerman | a616835 | 2008-08-20 16:36:11 -0700 | [diff] [blame] | 2322 | seq_puts(m, "# _------=> CPU# \n"); |
| 2323 | seq_puts(m, "# / _-----=> irqs-off \n"); |
| 2324 | seq_puts(m, "# | / _----=> need-resched \n"); |
| 2325 | seq_puts(m, "# || / _---=> hardirq/softirq \n"); |
| 2326 | seq_puts(m, "# ||| / _--=> preempt-depth \n"); |
Steven Rostedt | e6e1e25 | 2011-03-09 10:41:56 -0500 | [diff] [blame] | 2327 | seq_puts(m, "# |||| / delay \n"); |
| 2328 | seq_puts(m, "# cmd pid ||||| time | caller \n"); |
| 2329 | seq_puts(m, "# \\ / ||||| \\ | / \n"); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2330 | } |
| 2331 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2332 | static void print_event_info(struct trace_buffer *buf, struct seq_file *m) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2333 | { |
Steven Rostedt | 39eaf7e | 2011-11-17 10:35:16 -0500 | [diff] [blame] | 2334 | unsigned long total; |
| 2335 | unsigned long entries; |
| 2336 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2337 | get_total_entries(buf, &total, &entries); |
Steven Rostedt | 39eaf7e | 2011-11-17 10:35:16 -0500 | [diff] [blame] | 2338 | seq_printf(m, "# entries-in-buffer/entries-written: %lu/%lu #P:%d\n", |
| 2339 | entries, total, num_online_cpus()); |
| 2340 | seq_puts(m, "#\n"); |
| 2341 | } |
| 2342 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2343 | static void print_func_help_header(struct trace_buffer *buf, struct seq_file *m) |
Steven Rostedt | 39eaf7e | 2011-11-17 10:35:16 -0500 | [diff] [blame] | 2344 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2345 | print_event_info(buf, m); |
Steven Rostedt | 77271ce | 2011-11-17 09:34:33 -0500 | [diff] [blame] | 2346 | seq_puts(m, "# TASK-PID CPU# TIMESTAMP FUNCTION\n"); |
Michael Ellerman | a616835 | 2008-08-20 16:36:11 -0700 | [diff] [blame] | 2347 | seq_puts(m, "# | | | | |\n"); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2348 | } |
| 2349 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2350 | static void print_func_help_header_irq(struct trace_buffer *buf, struct seq_file *m) |
Steven Rostedt | 77271ce | 2011-11-17 09:34:33 -0500 | [diff] [blame] | 2351 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2352 | print_event_info(buf, m); |
Steven Rostedt | 77271ce | 2011-11-17 09:34:33 -0500 | [diff] [blame] | 2353 | seq_puts(m, "# _-----=> irqs-off\n"); |
| 2354 | seq_puts(m, "# / _----=> need-resched\n"); |
| 2355 | seq_puts(m, "# | / _---=> hardirq/softirq\n"); |
| 2356 | seq_puts(m, "# || / _--=> preempt-depth\n"); |
| 2357 | seq_puts(m, "# ||| / delay\n"); |
| 2358 | seq_puts(m, "# TASK-PID CPU# |||| TIMESTAMP FUNCTION\n"); |
| 2359 | seq_puts(m, "# | | | |||| | |\n"); |
| 2360 | } |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2361 | |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 2362 | void |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2363 | print_trace_header(struct seq_file *m, struct trace_iterator *iter) |
| 2364 | { |
| 2365 | unsigned long sym_flags = (trace_flags & TRACE_ITER_SYM_MASK); |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2366 | struct trace_buffer *buf = iter->trace_buffer; |
| 2367 | struct trace_array_cpu *data = per_cpu_ptr(buf->data, buf->cpu); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 2368 | struct tracer *type = iter->trace; |
Steven Rostedt | 39eaf7e | 2011-11-17 10:35:16 -0500 | [diff] [blame] | 2369 | unsigned long entries; |
| 2370 | unsigned long total; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2371 | const char *name = "preemption"; |
| 2372 | |
Steven Rostedt (Red Hat) | d840f71 | 2013-02-01 18:38:47 -0500 | [diff] [blame] | 2373 | name = type->name; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2374 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2375 | get_total_entries(buf, &total, &entries); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2376 | |
KOSAKI Motohiro | 888b55d | 2009-03-08 13:12:43 +0900 | [diff] [blame] | 2377 | seq_printf(m, "# %s latency trace v1.1.5 on %s\n", |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2378 | name, UTS_RELEASE); |
KOSAKI Motohiro | 888b55d | 2009-03-08 13:12:43 +0900 | [diff] [blame] | 2379 | seq_puts(m, "# -----------------------------------" |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2380 | "---------------------------------\n"); |
KOSAKI Motohiro | 888b55d | 2009-03-08 13:12:43 +0900 | [diff] [blame] | 2381 | seq_printf(m, "# latency: %lu us, #%lu/%lu, CPU#%d |" |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2382 | " (M:%s VP:%d, KP:%d, SP:%d HP:%d", |
Steven Rostedt | 57f50be | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 2383 | nsecs_to_usecs(data->saved_latency), |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2384 | entries, |
Steven Rostedt | 4c11d7a | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 2385 | total, |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2386 | buf->cpu, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2387 | #if defined(CONFIG_PREEMPT_NONE) |
| 2388 | "server", |
| 2389 | #elif defined(CONFIG_PREEMPT_VOLUNTARY) |
| 2390 | "desktop", |
Steven Rostedt | b5c21b4 | 2008-07-10 20:58:12 -0400 | [diff] [blame] | 2391 | #elif defined(CONFIG_PREEMPT) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2392 | "preempt", |
| 2393 | #else |
| 2394 | "unknown", |
| 2395 | #endif |
| 2396 | /* These are reserved for later use */ |
| 2397 | 0, 0, 0, 0); |
| 2398 | #ifdef CONFIG_SMP |
| 2399 | seq_printf(m, " #P:%d)\n", num_online_cpus()); |
| 2400 | #else |
| 2401 | seq_puts(m, ")\n"); |
| 2402 | #endif |
KOSAKI Motohiro | 888b55d | 2009-03-08 13:12:43 +0900 | [diff] [blame] | 2403 | seq_puts(m, "# -----------------\n"); |
| 2404 | seq_printf(m, "# | task: %.16s-%d " |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2405 | "(uid:%d nice:%ld policy:%ld rt_prio:%ld)\n", |
Eric W. Biederman | d20b92a | 2012-03-13 16:02:19 -0700 | [diff] [blame] | 2406 | data->comm, data->pid, |
| 2407 | from_kuid_munged(seq_user_ns(m), data->uid), data->nice, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2408 | data->policy, data->rt_priority); |
KOSAKI Motohiro | 888b55d | 2009-03-08 13:12:43 +0900 | [diff] [blame] | 2409 | seq_puts(m, "# -----------------\n"); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2410 | |
| 2411 | if (data->critical_start) { |
KOSAKI Motohiro | 888b55d | 2009-03-08 13:12:43 +0900 | [diff] [blame] | 2412 | seq_puts(m, "# => started at: "); |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2413 | seq_print_ip_sym(&iter->seq, data->critical_start, sym_flags); |
| 2414 | trace_print_seq(m, &iter->seq); |
KOSAKI Motohiro | 888b55d | 2009-03-08 13:12:43 +0900 | [diff] [blame] | 2415 | seq_puts(m, "\n# => ended at: "); |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2416 | seq_print_ip_sym(&iter->seq, data->critical_end, sym_flags); |
| 2417 | trace_print_seq(m, &iter->seq); |
Steven Rostedt | 8248ac0 | 2009-09-02 12:27:41 -0400 | [diff] [blame] | 2418 | seq_puts(m, "\n#\n"); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2419 | } |
| 2420 | |
KOSAKI Motohiro | 888b55d | 2009-03-08 13:12:43 +0900 | [diff] [blame] | 2421 | seq_puts(m, "#\n"); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2422 | } |
| 2423 | |
Steven Rostedt | a309720 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 2424 | static void test_cpu_buff_start(struct trace_iterator *iter) |
| 2425 | { |
| 2426 | struct trace_seq *s = &iter->seq; |
| 2427 | |
Steven Rostedt | 12ef7d4 | 2008-11-12 17:52:38 -0500 | [diff] [blame] | 2428 | if (!(trace_flags & TRACE_ITER_ANNOTATE)) |
| 2429 | return; |
| 2430 | |
| 2431 | if (!(iter->iter_flags & TRACE_FILE_ANNOTATE)) |
| 2432 | return; |
| 2433 | |
Rusty Russell | 4462344 | 2009-01-01 10:12:23 +1030 | [diff] [blame] | 2434 | if (cpumask_test_cpu(iter->cpu, iter->started)) |
Steven Rostedt | a309720 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 2435 | return; |
| 2436 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2437 | if (per_cpu_ptr(iter->trace_buffer->data, iter->cpu)->skipped_entries) |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 2438 | return; |
| 2439 | |
Rusty Russell | 4462344 | 2009-01-01 10:12:23 +1030 | [diff] [blame] | 2440 | cpumask_set_cpu(iter->cpu, iter->started); |
Frederic Weisbecker | b0dfa97 | 2009-04-01 22:53:08 +0200 | [diff] [blame] | 2441 | |
| 2442 | /* Don't print started cpu buffer for the first entry of the trace */ |
| 2443 | if (iter->idx > 1) |
| 2444 | trace_seq_printf(s, "##### CPU %u buffer started ####\n", |
| 2445 | iter->cpu); |
Steven Rostedt | a309720 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 2446 | } |
| 2447 | |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 2448 | static enum print_line_t print_trace_fmt(struct trace_iterator *iter) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2449 | { |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2450 | struct trace_seq *s = &iter->seq; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2451 | unsigned long sym_flags = (trace_flags & TRACE_ITER_SYM_MASK); |
Ingo Molnar | 4e3c333 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 2452 | struct trace_entry *entry; |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 2453 | struct trace_event *event; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2454 | |
Ingo Molnar | 4e3c333 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 2455 | entry = iter->ent; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2456 | |
Steven Rostedt | a309720 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 2457 | test_cpu_buff_start(iter); |
| 2458 | |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 2459 | event = ftrace_find_event(entry->type); |
Frederic Weisbecker | c4a8e8b | 2009-02-02 20:29:21 -0200 | [diff] [blame] | 2460 | |
| 2461 | if (trace_flags & TRACE_ITER_CONTEXT_INFO) { |
Steven Rostedt | 27d48be | 2009-03-04 21:57:29 -0500 | [diff] [blame] | 2462 | if (iter->iter_flags & TRACE_FILE_LAT_FMT) { |
| 2463 | if (!trace_print_lat_context(iter)) |
| 2464 | goto partial; |
| 2465 | } else { |
| 2466 | if (!trace_print_context(iter)) |
| 2467 | goto partial; |
| 2468 | } |
Frederic Weisbecker | c4a8e8b | 2009-02-02 20:29:21 -0200 | [diff] [blame] | 2469 | } |
| 2470 | |
Arnaldo Carvalho de Melo | 268ccda | 2009-02-04 20:16:39 -0200 | [diff] [blame] | 2471 | if (event) |
Steven Rostedt | a9a5776 | 2010-04-22 18:46:14 -0400 | [diff] [blame] | 2472 | return event->funcs->trace(iter, sym_flags, event); |
Arnaldo Carvalho de Melo | d9793bd | 2009-02-03 20:20:41 -0200 | [diff] [blame] | 2473 | |
| 2474 | if (!trace_seq_printf(s, "Unknown type %d\n", entry->type)) |
| 2475 | goto partial; |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 2476 | |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 2477 | return TRACE_TYPE_HANDLED; |
Arnaldo Carvalho de Melo | d9793bd | 2009-02-03 20:20:41 -0200 | [diff] [blame] | 2478 | partial: |
| 2479 | return TRACE_TYPE_PARTIAL_LINE; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2480 | } |
| 2481 | |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 2482 | static enum print_line_t print_raw_fmt(struct trace_iterator *iter) |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2483 | { |
| 2484 | struct trace_seq *s = &iter->seq; |
| 2485 | struct trace_entry *entry; |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 2486 | struct trace_event *event; |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2487 | |
| 2488 | entry = iter->ent; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2489 | |
Frederic Weisbecker | c4a8e8b | 2009-02-02 20:29:21 -0200 | [diff] [blame] | 2490 | if (trace_flags & TRACE_ITER_CONTEXT_INFO) { |
Arnaldo Carvalho de Melo | d9793bd | 2009-02-03 20:20:41 -0200 | [diff] [blame] | 2491 | if (!trace_seq_printf(s, "%d %d %llu ", |
| 2492 | entry->pid, iter->cpu, iter->ts)) |
| 2493 | goto partial; |
Frederic Weisbecker | c4a8e8b | 2009-02-02 20:29:21 -0200 | [diff] [blame] | 2494 | } |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2495 | |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 2496 | event = ftrace_find_event(entry->type); |
Arnaldo Carvalho de Melo | 268ccda | 2009-02-04 20:16:39 -0200 | [diff] [blame] | 2497 | if (event) |
Steven Rostedt | a9a5776 | 2010-04-22 18:46:14 -0400 | [diff] [blame] | 2498 | return event->funcs->raw(iter, 0, event); |
Arnaldo Carvalho de Melo | d9793bd | 2009-02-03 20:20:41 -0200 | [diff] [blame] | 2499 | |
| 2500 | if (!trace_seq_printf(s, "%d ?\n", entry->type)) |
| 2501 | goto partial; |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 2502 | |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 2503 | return TRACE_TYPE_HANDLED; |
Arnaldo Carvalho de Melo | d9793bd | 2009-02-03 20:20:41 -0200 | [diff] [blame] | 2504 | partial: |
| 2505 | return TRACE_TYPE_PARTIAL_LINE; |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2506 | } |
| 2507 | |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 2508 | static enum print_line_t print_hex_fmt(struct trace_iterator *iter) |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 2509 | { |
| 2510 | struct trace_seq *s = &iter->seq; |
| 2511 | unsigned char newline = '\n'; |
| 2512 | struct trace_entry *entry; |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 2513 | struct trace_event *event; |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 2514 | |
| 2515 | entry = iter->ent; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2516 | |
Frederic Weisbecker | c4a8e8b | 2009-02-02 20:29:21 -0200 | [diff] [blame] | 2517 | if (trace_flags & TRACE_ITER_CONTEXT_INFO) { |
| 2518 | SEQ_PUT_HEX_FIELD_RET(s, entry->pid); |
| 2519 | SEQ_PUT_HEX_FIELD_RET(s, iter->cpu); |
| 2520 | SEQ_PUT_HEX_FIELD_RET(s, iter->ts); |
| 2521 | } |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 2522 | |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 2523 | event = ftrace_find_event(entry->type); |
Arnaldo Carvalho de Melo | 268ccda | 2009-02-04 20:16:39 -0200 | [diff] [blame] | 2524 | if (event) { |
Steven Rostedt | a9a5776 | 2010-04-22 18:46:14 -0400 | [diff] [blame] | 2525 | enum print_line_t ret = event->funcs->hex(iter, 0, event); |
Arnaldo Carvalho de Melo | d9793bd | 2009-02-03 20:20:41 -0200 | [diff] [blame] | 2526 | if (ret != TRACE_TYPE_HANDLED) |
| 2527 | return ret; |
| 2528 | } |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 2529 | |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 2530 | SEQ_PUT_FIELD_RET(s, newline); |
| 2531 | |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 2532 | return TRACE_TYPE_HANDLED; |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 2533 | } |
| 2534 | |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 2535 | static enum print_line_t print_bin_fmt(struct trace_iterator *iter) |
Ingo Molnar | cb0f12a | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2536 | { |
| 2537 | struct trace_seq *s = &iter->seq; |
| 2538 | struct trace_entry *entry; |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 2539 | struct trace_event *event; |
Ingo Molnar | cb0f12a | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2540 | |
| 2541 | entry = iter->ent; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2542 | |
Frederic Weisbecker | c4a8e8b | 2009-02-02 20:29:21 -0200 | [diff] [blame] | 2543 | if (trace_flags & TRACE_ITER_CONTEXT_INFO) { |
| 2544 | SEQ_PUT_FIELD_RET(s, entry->pid); |
Steven Rostedt | 1830b52 | 2009-02-07 19:38:43 -0500 | [diff] [blame] | 2545 | SEQ_PUT_FIELD_RET(s, iter->cpu); |
Frederic Weisbecker | c4a8e8b | 2009-02-02 20:29:21 -0200 | [diff] [blame] | 2546 | SEQ_PUT_FIELD_RET(s, iter->ts); |
| 2547 | } |
Ingo Molnar | cb0f12a | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2548 | |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 2549 | event = ftrace_find_event(entry->type); |
Steven Rostedt | a9a5776 | 2010-04-22 18:46:14 -0400 | [diff] [blame] | 2550 | return event ? event->funcs->binary(iter, 0, event) : |
| 2551 | TRACE_TYPE_HANDLED; |
Ingo Molnar | cb0f12a | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2552 | } |
| 2553 | |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 2554 | int trace_empty(struct trace_iterator *iter) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2555 | { |
Steven Rostedt | 6d158a8 | 2012-06-27 20:46:14 -0400 | [diff] [blame] | 2556 | struct ring_buffer_iter *buf_iter; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2557 | int cpu; |
| 2558 | |
Steven Rostedt | 9aba60f | 2009-03-11 19:52:30 -0400 | [diff] [blame] | 2559 | /* If we are looking at one CPU buffer, only check that one */ |
Steven Rostedt | ae3b509 | 2013-01-23 15:22:59 -0500 | [diff] [blame] | 2560 | if (iter->cpu_file != RING_BUFFER_ALL_CPUS) { |
Steven Rostedt | 9aba60f | 2009-03-11 19:52:30 -0400 | [diff] [blame] | 2561 | cpu = iter->cpu_file; |
Steven Rostedt | 6d158a8 | 2012-06-27 20:46:14 -0400 | [diff] [blame] | 2562 | buf_iter = trace_buffer_iter(iter, cpu); |
| 2563 | if (buf_iter) { |
| 2564 | if (!ring_buffer_iter_empty(buf_iter)) |
Steven Rostedt | 9aba60f | 2009-03-11 19:52:30 -0400 | [diff] [blame] | 2565 | return 0; |
| 2566 | } else { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2567 | if (!ring_buffer_empty_cpu(iter->trace_buffer->buffer, cpu)) |
Steven Rostedt | 9aba60f | 2009-03-11 19:52:30 -0400 | [diff] [blame] | 2568 | return 0; |
| 2569 | } |
| 2570 | return 1; |
| 2571 | } |
| 2572 | |
Steven Rostedt | ab46428 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 2573 | for_each_tracing_cpu(cpu) { |
Steven Rostedt | 6d158a8 | 2012-06-27 20:46:14 -0400 | [diff] [blame] | 2574 | buf_iter = trace_buffer_iter(iter, cpu); |
| 2575 | if (buf_iter) { |
| 2576 | if (!ring_buffer_iter_empty(buf_iter)) |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 2577 | return 0; |
| 2578 | } else { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2579 | if (!ring_buffer_empty_cpu(iter->trace_buffer->buffer, cpu)) |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 2580 | return 0; |
| 2581 | } |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2582 | } |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 2583 | |
Frederic Weisbecker | 797d371 | 2008-09-30 18:13:45 +0200 | [diff] [blame] | 2584 | return 1; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2585 | } |
| 2586 | |
Lai Jiangshan | 4f53596 | 2009-05-18 19:35:34 +0800 | [diff] [blame] | 2587 | /* Called with trace_event_read_lock() held. */ |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 2588 | enum print_line_t print_trace_line(struct trace_iterator *iter) |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2589 | { |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 2590 | enum print_line_t ret; |
| 2591 | |
Jiri Olsa | ee5e51f | 2011-03-25 12:05:18 +0100 | [diff] [blame] | 2592 | if (iter->lost_events && |
| 2593 | !trace_seq_printf(&iter->seq, "CPU:%d [LOST %lu EVENTS]\n", |
| 2594 | iter->cpu, iter->lost_events)) |
| 2595 | return TRACE_TYPE_PARTIAL_LINE; |
Steven Rostedt | bc21b47 | 2010-03-31 19:49:26 -0400 | [diff] [blame] | 2596 | |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 2597 | if (iter->trace && iter->trace->print_line) { |
| 2598 | ret = iter->trace->print_line(iter); |
| 2599 | if (ret != TRACE_TYPE_UNHANDLED) |
| 2600 | return ret; |
| 2601 | } |
Thomas Gleixner | 72829bc | 2008-05-23 21:37:28 +0200 | [diff] [blame] | 2602 | |
Steven Rostedt (Red Hat) | 09ae723 | 2013-03-08 21:02:34 -0500 | [diff] [blame] | 2603 | if (iter->ent->type == TRACE_BPUTS && |
| 2604 | trace_flags & TRACE_ITER_PRINTK && |
| 2605 | trace_flags & TRACE_ITER_PRINTK_MSGONLY) |
| 2606 | return trace_print_bputs_msg_only(iter); |
| 2607 | |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 2608 | if (iter->ent->type == TRACE_BPRINT && |
| 2609 | trace_flags & TRACE_ITER_PRINTK && |
| 2610 | trace_flags & TRACE_ITER_PRINTK_MSGONLY) |
Steven Rostedt | 5ef841f | 2009-03-19 12:20:38 -0400 | [diff] [blame] | 2611 | return trace_print_bprintk_msg_only(iter); |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 2612 | |
Frederic Weisbecker | 66896a8 | 2008-12-13 20:18:13 +0100 | [diff] [blame] | 2613 | if (iter->ent->type == TRACE_PRINT && |
| 2614 | trace_flags & TRACE_ITER_PRINTK && |
| 2615 | trace_flags & TRACE_ITER_PRINTK_MSGONLY) |
Steven Rostedt | 5ef841f | 2009-03-19 12:20:38 -0400 | [diff] [blame] | 2616 | return trace_print_printk_msg_only(iter); |
Frederic Weisbecker | 66896a8 | 2008-12-13 20:18:13 +0100 | [diff] [blame] | 2617 | |
Ingo Molnar | cb0f12a | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2618 | if (trace_flags & TRACE_ITER_BIN) |
| 2619 | return print_bin_fmt(iter); |
| 2620 | |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 2621 | if (trace_flags & TRACE_ITER_HEX) |
| 2622 | return print_hex_fmt(iter); |
| 2623 | |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2624 | if (trace_flags & TRACE_ITER_RAW) |
| 2625 | return print_raw_fmt(iter); |
| 2626 | |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2627 | return print_trace_fmt(iter); |
| 2628 | } |
| 2629 | |
Jiri Olsa | 7e9a49e | 2011-11-07 16:08:49 +0100 | [diff] [blame] | 2630 | void trace_latency_header(struct seq_file *m) |
| 2631 | { |
| 2632 | struct trace_iterator *iter = m->private; |
| 2633 | |
| 2634 | /* print nothing if the buffers are empty */ |
| 2635 | if (trace_empty(iter)) |
| 2636 | return; |
| 2637 | |
| 2638 | if (iter->iter_flags & TRACE_FILE_LAT_FMT) |
| 2639 | print_trace_header(m, iter); |
| 2640 | |
| 2641 | if (!(trace_flags & TRACE_ITER_VERBOSE)) |
| 2642 | print_lat_help_header(m); |
| 2643 | } |
| 2644 | |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 2645 | void trace_default_header(struct seq_file *m) |
| 2646 | { |
| 2647 | struct trace_iterator *iter = m->private; |
| 2648 | |
Jiri Olsa | f56e7f8 | 2011-06-03 16:58:49 +0200 | [diff] [blame] | 2649 | if (!(trace_flags & TRACE_ITER_CONTEXT_INFO)) |
| 2650 | return; |
| 2651 | |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 2652 | if (iter->iter_flags & TRACE_FILE_LAT_FMT) { |
| 2653 | /* print nothing if the buffers are empty */ |
| 2654 | if (trace_empty(iter)) |
| 2655 | return; |
| 2656 | print_trace_header(m, iter); |
| 2657 | if (!(trace_flags & TRACE_ITER_VERBOSE)) |
| 2658 | print_lat_help_header(m); |
| 2659 | } else { |
Steven Rostedt | 77271ce | 2011-11-17 09:34:33 -0500 | [diff] [blame] | 2660 | if (!(trace_flags & TRACE_ITER_VERBOSE)) { |
| 2661 | if (trace_flags & TRACE_ITER_IRQ_INFO) |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2662 | print_func_help_header_irq(iter->trace_buffer, m); |
Steven Rostedt | 77271ce | 2011-11-17 09:34:33 -0500 | [diff] [blame] | 2663 | else |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2664 | print_func_help_header(iter->trace_buffer, m); |
Steven Rostedt | 77271ce | 2011-11-17 09:34:33 -0500 | [diff] [blame] | 2665 | } |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 2666 | } |
| 2667 | } |
| 2668 | |
Steven Rostedt | e0a413f | 2011-09-29 21:26:16 -0400 | [diff] [blame] | 2669 | static void test_ftrace_alive(struct seq_file *m) |
| 2670 | { |
| 2671 | if (!ftrace_is_dead()) |
| 2672 | return; |
| 2673 | seq_printf(m, "# WARNING: FUNCTION TRACING IS CORRUPTED\n"); |
| 2674 | seq_printf(m, "# MAY BE MISSING FUNCTION EVENTS\n"); |
| 2675 | } |
| 2676 | |
Steven Rostedt (Red Hat) | d8741e2 | 2013-03-05 10:25:16 -0500 | [diff] [blame] | 2677 | #ifdef CONFIG_TRACER_MAX_TRACE |
Steven Rostedt (Red Hat) | f1affca | 2013-03-05 14:35:11 -0500 | [diff] [blame] | 2678 | static void show_snapshot_main_help(struct seq_file *m) |
Steven Rostedt (Red Hat) | d8741e2 | 2013-03-05 10:25:16 -0500 | [diff] [blame] | 2679 | { |
Steven Rostedt (Red Hat) | d8741e2 | 2013-03-05 10:25:16 -0500 | [diff] [blame] | 2680 | seq_printf(m, "# echo 0 > snapshot : Clears and frees snapshot buffer\n"); |
| 2681 | seq_printf(m, "# echo 1 > snapshot : Allocates snapshot buffer, if not already allocated.\n"); |
| 2682 | seq_printf(m, "# Takes a snapshot of the main buffer.\n"); |
| 2683 | seq_printf(m, "# echo 2 > snapshot : Clears snapshot buffer (but does not allocate)\n"); |
| 2684 | seq_printf(m, "# (Doesn't have to be '2' works with any number that\n"); |
| 2685 | seq_printf(m, "# is not a '0' or '1')\n"); |
| 2686 | } |
Steven Rostedt (Red Hat) | f1affca | 2013-03-05 14:35:11 -0500 | [diff] [blame] | 2687 | |
| 2688 | static void show_snapshot_percpu_help(struct seq_file *m) |
| 2689 | { |
| 2690 | seq_printf(m, "# echo 0 > snapshot : Invalid for per_cpu snapshot file.\n"); |
| 2691 | #ifdef CONFIG_RING_BUFFER_ALLOW_SWAP |
| 2692 | seq_printf(m, "# echo 1 > snapshot : Allocates snapshot buffer, if not already allocated.\n"); |
| 2693 | seq_printf(m, "# Takes a snapshot of the main buffer for this cpu.\n"); |
| 2694 | #else |
| 2695 | seq_printf(m, "# echo 1 > snapshot : Not supported with this kernel.\n"); |
| 2696 | seq_printf(m, "# Must use main snapshot file to allocate.\n"); |
| 2697 | #endif |
| 2698 | seq_printf(m, "# echo 2 > snapshot : Clears this cpu's snapshot buffer (but does not allocate)\n"); |
| 2699 | seq_printf(m, "# (Doesn't have to be '2' works with any number that\n"); |
| 2700 | seq_printf(m, "# is not a '0' or '1')\n"); |
| 2701 | } |
| 2702 | |
Steven Rostedt (Red Hat) | d8741e2 | 2013-03-05 10:25:16 -0500 | [diff] [blame] | 2703 | static void print_snapshot_help(struct seq_file *m, struct trace_iterator *iter) |
| 2704 | { |
Steven Rostedt (Red Hat) | 45ad21c | 2013-03-05 18:25:02 -0500 | [diff] [blame] | 2705 | if (iter->tr->allocated_snapshot) |
Steven Rostedt (Red Hat) | d8741e2 | 2013-03-05 10:25:16 -0500 | [diff] [blame] | 2706 | seq_printf(m, "#\n# * Snapshot is allocated *\n#\n"); |
| 2707 | else |
| 2708 | seq_printf(m, "#\n# * Snapshot is freed *\n#\n"); |
| 2709 | |
| 2710 | seq_printf(m, "# Snapshot commands:\n"); |
Steven Rostedt (Red Hat) | f1affca | 2013-03-05 14:35:11 -0500 | [diff] [blame] | 2711 | if (iter->cpu_file == RING_BUFFER_ALL_CPUS) |
| 2712 | show_snapshot_main_help(m); |
| 2713 | else |
| 2714 | show_snapshot_percpu_help(m); |
Steven Rostedt (Red Hat) | d8741e2 | 2013-03-05 10:25:16 -0500 | [diff] [blame] | 2715 | } |
| 2716 | #else |
| 2717 | /* Should never be called */ |
| 2718 | static inline void print_snapshot_help(struct seq_file *m, struct trace_iterator *iter) { } |
| 2719 | #endif |
| 2720 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2721 | static int s_show(struct seq_file *m, void *v) |
| 2722 | { |
| 2723 | struct trace_iterator *iter = v; |
Steven Rostedt | a63ce5b | 2009-12-07 09:11:39 -0500 | [diff] [blame] | 2724 | int ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2725 | |
| 2726 | if (iter->ent == NULL) { |
| 2727 | if (iter->tr) { |
| 2728 | seq_printf(m, "# tracer: %s\n", iter->trace->name); |
| 2729 | seq_puts(m, "#\n"); |
Steven Rostedt | e0a413f | 2011-09-29 21:26:16 -0400 | [diff] [blame] | 2730 | test_ftrace_alive(m); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2731 | } |
Steven Rostedt (Red Hat) | d8741e2 | 2013-03-05 10:25:16 -0500 | [diff] [blame] | 2732 | if (iter->snapshot && trace_empty(iter)) |
| 2733 | print_snapshot_help(m, iter); |
| 2734 | else if (iter->trace && iter->trace->print_header) |
Markus Metzger | 8bba1bf | 2008-11-25 09:12:31 +0100 | [diff] [blame] | 2735 | iter->trace->print_header(m); |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 2736 | else |
| 2737 | trace_default_header(m); |
| 2738 | |
Steven Rostedt | a63ce5b | 2009-12-07 09:11:39 -0500 | [diff] [blame] | 2739 | } else if (iter->leftover) { |
| 2740 | /* |
| 2741 | * If we filled the seq_file buffer earlier, we |
| 2742 | * want to just show it now. |
| 2743 | */ |
| 2744 | ret = trace_print_seq(m, &iter->seq); |
| 2745 | |
| 2746 | /* ret should this time be zero, but you never know */ |
| 2747 | iter->leftover = ret; |
| 2748 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2749 | } else { |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2750 | print_trace_line(iter); |
Steven Rostedt | a63ce5b | 2009-12-07 09:11:39 -0500 | [diff] [blame] | 2751 | ret = trace_print_seq(m, &iter->seq); |
| 2752 | /* |
| 2753 | * If we overflow the seq_file buffer, then it will |
| 2754 | * ask us for this data again at start up. |
| 2755 | * Use that instead. |
| 2756 | * ret is 0 if seq_file write succeeded. |
| 2757 | * -1 otherwise. |
| 2758 | */ |
| 2759 | iter->leftover = ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2760 | } |
| 2761 | |
| 2762 | return 0; |
| 2763 | } |
| 2764 | |
James Morris | 88e9d34 | 2009-09-22 16:43:43 -0700 | [diff] [blame] | 2765 | static const struct seq_operations tracer_seq_ops = { |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2766 | .start = s_start, |
| 2767 | .next = s_next, |
| 2768 | .stop = s_stop, |
| 2769 | .show = s_show, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2770 | }; |
| 2771 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 2772 | static struct trace_iterator * |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 2773 | __tracing_open(struct inode *inode, struct file *file, bool snapshot) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2774 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 2775 | struct trace_cpu *tc = inode->i_private; |
| 2776 | struct trace_array *tr = tc->tr; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2777 | struct trace_iterator *iter; |
Jiri Olsa | 50e18b9 | 2012-04-25 10:23:39 +0200 | [diff] [blame] | 2778 | int cpu; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2779 | |
Steven Rostedt | 85a2f9b | 2009-02-27 00:12:38 -0500 | [diff] [blame] | 2780 | if (tracing_disabled) |
| 2781 | return ERR_PTR(-ENODEV); |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 2782 | |
Jiri Olsa | 50e18b9 | 2012-04-25 10:23:39 +0200 | [diff] [blame] | 2783 | iter = __seq_open_private(file, &tracer_seq_ops, sizeof(*iter)); |
Steven Rostedt | 85a2f9b | 2009-02-27 00:12:38 -0500 | [diff] [blame] | 2784 | if (!iter) |
| 2785 | return ERR_PTR(-ENOMEM); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2786 | |
Steven Rostedt | 6d158a8 | 2012-06-27 20:46:14 -0400 | [diff] [blame] | 2787 | iter->buffer_iter = kzalloc(sizeof(*iter->buffer_iter) * num_possible_cpus(), |
| 2788 | GFP_KERNEL); |
Dan Carpenter | 93574fc | 2012-07-11 09:35:08 +0300 | [diff] [blame] | 2789 | if (!iter->buffer_iter) |
| 2790 | goto release; |
| 2791 | |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 2792 | /* |
| 2793 | * We make a copy of the current tracer to avoid concurrent |
| 2794 | * changes on it while we are reading. |
| 2795 | */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2796 | mutex_lock(&trace_types_lock); |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 2797 | iter->trace = kzalloc(sizeof(*iter->trace), GFP_KERNEL); |
Steven Rostedt | 85a2f9b | 2009-02-27 00:12:38 -0500 | [diff] [blame] | 2798 | if (!iter->trace) |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 2799 | goto fail; |
Steven Rostedt | 85a2f9b | 2009-02-27 00:12:38 -0500 | [diff] [blame] | 2800 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 2801 | *iter->trace = *tr->current_trace; |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 2802 | |
Li Zefan | 79f5599 | 2009-06-15 14:58:26 +0800 | [diff] [blame] | 2803 | if (!zalloc_cpumask_var(&iter->started, GFP_KERNEL)) |
Frederic Weisbecker | b0dfa97 | 2009-04-01 22:53:08 +0200 | [diff] [blame] | 2804 | goto fail; |
| 2805 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2806 | iter->tr = tr; |
| 2807 | |
| 2808 | #ifdef CONFIG_TRACER_MAX_TRACE |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 2809 | /* Currently only the top directory has a snapshot */ |
| 2810 | if (tr->current_trace->print_max || snapshot) |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2811 | iter->trace_buffer = &tr->max_buffer; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2812 | else |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2813 | #endif |
| 2814 | iter->trace_buffer = &tr->trace_buffer; |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 2815 | iter->snapshot = snapshot; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2816 | iter->pos = -1; |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 2817 | mutex_init(&iter->mutex); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 2818 | iter->cpu_file = tc->cpu; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2819 | |
Markus Metzger | 8bba1bf | 2008-11-25 09:12:31 +0100 | [diff] [blame] | 2820 | /* Notify the tracer early; before we stop tracing. */ |
| 2821 | if (iter->trace && iter->trace->open) |
Markus Metzger | a93751c | 2008-12-11 13:53:26 +0100 | [diff] [blame] | 2822 | iter->trace->open(iter); |
Markus Metzger | 8bba1bf | 2008-11-25 09:12:31 +0100 | [diff] [blame] | 2823 | |
Steven Rostedt | 12ef7d4 | 2008-11-12 17:52:38 -0500 | [diff] [blame] | 2824 | /* Annotate start of buffers if we had overruns */ |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2825 | if (ring_buffer_overruns(iter->trace_buffer->buffer)) |
Steven Rostedt | 12ef7d4 | 2008-11-12 17:52:38 -0500 | [diff] [blame] | 2826 | iter->iter_flags |= TRACE_FILE_ANNOTATE; |
| 2827 | |
David Sharp | 8be0709 | 2012-11-13 12:18:22 -0800 | [diff] [blame] | 2828 | /* Output in nanoseconds only if we are using a clock in nanoseconds. */ |
| 2829 | if (trace_clocks[trace_clock_id].in_ns) |
| 2830 | iter->iter_flags |= TRACE_FILE_TIME_IN_NS; |
| 2831 | |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 2832 | /* stop the trace while dumping if we are not opening "snapshot" */ |
| 2833 | if (!iter->snapshot) |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 2834 | tracing_stop_tr(tr); |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 2835 | |
Steven Rostedt | ae3b509 | 2013-01-23 15:22:59 -0500 | [diff] [blame] | 2836 | if (iter->cpu_file == RING_BUFFER_ALL_CPUS) { |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 2837 | for_each_tracing_cpu(cpu) { |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 2838 | iter->buffer_iter[cpu] = |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2839 | ring_buffer_read_prepare(iter->trace_buffer->buffer, cpu); |
David Miller | 72c9ddf | 2010-04-20 15:47:11 -0700 | [diff] [blame] | 2840 | } |
| 2841 | ring_buffer_read_prepare_sync(); |
| 2842 | for_each_tracing_cpu(cpu) { |
| 2843 | ring_buffer_read_start(iter->buffer_iter[cpu]); |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 2844 | tracing_iter_reset(iter, cpu); |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 2845 | } |
| 2846 | } else { |
| 2847 | cpu = iter->cpu_file; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2848 | iter->buffer_iter[cpu] = |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2849 | ring_buffer_read_prepare(iter->trace_buffer->buffer, cpu); |
David Miller | 72c9ddf | 2010-04-20 15:47:11 -0700 | [diff] [blame] | 2850 | ring_buffer_read_prepare_sync(); |
| 2851 | ring_buffer_read_start(iter->buffer_iter[cpu]); |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 2852 | tracing_iter_reset(iter, cpu); |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2853 | } |
| 2854 | |
Steven Rostedt (Red Hat) | a695cb5 | 2013-03-06 15:27:24 -0500 | [diff] [blame] | 2855 | tr->ref++; |
| 2856 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2857 | mutex_unlock(&trace_types_lock); |
| 2858 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2859 | return iter; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2860 | |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 2861 | fail: |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2862 | mutex_unlock(&trace_types_lock); |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 2863 | kfree(iter->trace); |
Steven Rostedt | 6d158a8 | 2012-06-27 20:46:14 -0400 | [diff] [blame] | 2864 | kfree(iter->buffer_iter); |
Dan Carpenter | 93574fc | 2012-07-11 09:35:08 +0300 | [diff] [blame] | 2865 | release: |
Jiri Olsa | 50e18b9 | 2012-04-25 10:23:39 +0200 | [diff] [blame] | 2866 | seq_release_private(inode, file); |
| 2867 | return ERR_PTR(-ENOMEM); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2868 | } |
| 2869 | |
| 2870 | int tracing_open_generic(struct inode *inode, struct file *filp) |
| 2871 | { |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 2872 | if (tracing_disabled) |
| 2873 | return -ENODEV; |
| 2874 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2875 | filp->private_data = inode->i_private; |
| 2876 | return 0; |
| 2877 | } |
| 2878 | |
Hannes Eder | 4fd2735 | 2009-02-10 19:44:12 +0100 | [diff] [blame] | 2879 | static int tracing_release(struct inode *inode, struct file *file) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2880 | { |
matt mooney | 907f278 | 2010-09-27 19:04:53 -0700 | [diff] [blame] | 2881 | struct seq_file *m = file->private_data; |
Steven Rostedt | 4acd4d0 | 2009-03-18 10:40:24 -0400 | [diff] [blame] | 2882 | struct trace_iterator *iter; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 2883 | struct trace_array *tr; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2884 | int cpu; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2885 | |
Steven Rostedt | 4acd4d0 | 2009-03-18 10:40:24 -0400 | [diff] [blame] | 2886 | if (!(file->f_mode & FMODE_READ)) |
| 2887 | return 0; |
| 2888 | |
| 2889 | iter = m->private; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2890 | tr = iter->tr; |
Steven Rostedt | 4acd4d0 | 2009-03-18 10:40:24 -0400 | [diff] [blame] | 2891 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2892 | mutex_lock(&trace_types_lock); |
Steven Rostedt (Red Hat) | a695cb5 | 2013-03-06 15:27:24 -0500 | [diff] [blame] | 2893 | |
| 2894 | WARN_ON(!tr->ref); |
| 2895 | tr->ref--; |
| 2896 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2897 | for_each_tracing_cpu(cpu) { |
| 2898 | if (iter->buffer_iter[cpu]) |
| 2899 | ring_buffer_read_finish(iter->buffer_iter[cpu]); |
| 2900 | } |
| 2901 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2902 | if (iter->trace && iter->trace->close) |
| 2903 | iter->trace->close(iter); |
| 2904 | |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 2905 | if (!iter->snapshot) |
| 2906 | /* reenable tracing if it was previously enabled */ |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 2907 | tracing_start_tr(tr); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2908 | mutex_unlock(&trace_types_lock); |
| 2909 | |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 2910 | mutex_destroy(&iter->mutex); |
Frederic Weisbecker | b0dfa97 | 2009-04-01 22:53:08 +0200 | [diff] [blame] | 2911 | free_cpumask_var(iter->started); |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 2912 | kfree(iter->trace); |
Steven Rostedt | 6d158a8 | 2012-06-27 20:46:14 -0400 | [diff] [blame] | 2913 | kfree(iter->buffer_iter); |
Jiri Olsa | 50e18b9 | 2012-04-25 10:23:39 +0200 | [diff] [blame] | 2914 | seq_release_private(inode, file); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2915 | return 0; |
| 2916 | } |
| 2917 | |
| 2918 | static int tracing_open(struct inode *inode, struct file *file) |
| 2919 | { |
Steven Rostedt | 85a2f9b | 2009-02-27 00:12:38 -0500 | [diff] [blame] | 2920 | struct trace_iterator *iter; |
| 2921 | int ret = 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2922 | |
Steven Rostedt | 4acd4d0 | 2009-03-18 10:40:24 -0400 | [diff] [blame] | 2923 | /* If this file was open for write, then erase contents */ |
| 2924 | if ((file->f_mode & FMODE_WRITE) && |
Steven Rostedt | 8650ae3 | 2009-07-22 23:29:30 -0400 | [diff] [blame] | 2925 | (file->f_flags & O_TRUNC)) { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 2926 | struct trace_cpu *tc = inode->i_private; |
| 2927 | struct trace_array *tr = tc->tr; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2928 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 2929 | if (tc->cpu == RING_BUFFER_ALL_CPUS) |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2930 | tracing_reset_online_cpus(&tr->trace_buffer); |
Steven Rostedt | 4acd4d0 | 2009-03-18 10:40:24 -0400 | [diff] [blame] | 2931 | else |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2932 | tracing_reset(&tr->trace_buffer, tc->cpu); |
Steven Rostedt | 4acd4d0 | 2009-03-18 10:40:24 -0400 | [diff] [blame] | 2933 | } |
| 2934 | |
| 2935 | if (file->f_mode & FMODE_READ) { |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 2936 | iter = __tracing_open(inode, file, false); |
Steven Rostedt | 4acd4d0 | 2009-03-18 10:40:24 -0400 | [diff] [blame] | 2937 | if (IS_ERR(iter)) |
| 2938 | ret = PTR_ERR(iter); |
| 2939 | else if (trace_flags & TRACE_ITER_LATENCY_FMT) |
| 2940 | iter->iter_flags |= TRACE_FILE_LAT_FMT; |
| 2941 | } |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2942 | return ret; |
| 2943 | } |
| 2944 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 2945 | static void * |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2946 | t_next(struct seq_file *m, void *v, loff_t *pos) |
| 2947 | { |
Li Zefan | f129e96 | 2009-06-24 09:53:44 +0800 | [diff] [blame] | 2948 | struct tracer *t = v; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2949 | |
| 2950 | (*pos)++; |
| 2951 | |
| 2952 | if (t) |
| 2953 | t = t->next; |
| 2954 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2955 | return t; |
| 2956 | } |
| 2957 | |
| 2958 | static void *t_start(struct seq_file *m, loff_t *pos) |
| 2959 | { |
Li Zefan | f129e96 | 2009-06-24 09:53:44 +0800 | [diff] [blame] | 2960 | struct tracer *t; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2961 | loff_t l = 0; |
| 2962 | |
| 2963 | mutex_lock(&trace_types_lock); |
Li Zefan | f129e96 | 2009-06-24 09:53:44 +0800 | [diff] [blame] | 2964 | for (t = trace_types; t && l < *pos; t = t_next(m, t, &l)) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2965 | ; |
| 2966 | |
| 2967 | return t; |
| 2968 | } |
| 2969 | |
| 2970 | static void t_stop(struct seq_file *m, void *p) |
| 2971 | { |
| 2972 | mutex_unlock(&trace_types_lock); |
| 2973 | } |
| 2974 | |
| 2975 | static int t_show(struct seq_file *m, void *v) |
| 2976 | { |
| 2977 | struct tracer *t = v; |
| 2978 | |
| 2979 | if (!t) |
| 2980 | return 0; |
| 2981 | |
| 2982 | seq_printf(m, "%s", t->name); |
| 2983 | if (t->next) |
| 2984 | seq_putc(m, ' '); |
| 2985 | else |
| 2986 | seq_putc(m, '\n'); |
| 2987 | |
| 2988 | return 0; |
| 2989 | } |
| 2990 | |
James Morris | 88e9d34 | 2009-09-22 16:43:43 -0700 | [diff] [blame] | 2991 | static const struct seq_operations show_traces_seq_ops = { |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2992 | .start = t_start, |
| 2993 | .next = t_next, |
| 2994 | .stop = t_stop, |
| 2995 | .show = t_show, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2996 | }; |
| 2997 | |
| 2998 | static int show_traces_open(struct inode *inode, struct file *file) |
| 2999 | { |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 3000 | if (tracing_disabled) |
| 3001 | return -ENODEV; |
| 3002 | |
Li Zefan | f129e96 | 2009-06-24 09:53:44 +0800 | [diff] [blame] | 3003 | return seq_open(file, &show_traces_seq_ops); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3004 | } |
| 3005 | |
Steven Rostedt | 4acd4d0 | 2009-03-18 10:40:24 -0400 | [diff] [blame] | 3006 | static ssize_t |
| 3007 | tracing_write_stub(struct file *filp, const char __user *ubuf, |
| 3008 | size_t count, loff_t *ppos) |
| 3009 | { |
| 3010 | return count; |
| 3011 | } |
| 3012 | |
Slava Pestov | 364829b | 2010-11-24 15:13:16 -0800 | [diff] [blame] | 3013 | static loff_t tracing_seek(struct file *file, loff_t offset, int origin) |
| 3014 | { |
| 3015 | if (file->f_mode & FMODE_READ) |
| 3016 | return seq_lseek(file, offset, origin); |
| 3017 | else |
| 3018 | return 0; |
| 3019 | } |
| 3020 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 3021 | static const struct file_operations tracing_fops = { |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3022 | .open = tracing_open, |
| 3023 | .read = seq_read, |
Steven Rostedt | 4acd4d0 | 2009-03-18 10:40:24 -0400 | [diff] [blame] | 3024 | .write = tracing_write_stub, |
Slava Pestov | 364829b | 2010-11-24 15:13:16 -0800 | [diff] [blame] | 3025 | .llseek = tracing_seek, |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3026 | .release = tracing_release, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3027 | }; |
| 3028 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 3029 | static const struct file_operations show_traces_fops = { |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3030 | .open = show_traces_open, |
| 3031 | .read = seq_read, |
| 3032 | .release = seq_release, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 3033 | .llseek = seq_lseek, |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3034 | }; |
| 3035 | |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3036 | /* |
| 3037 | * Only trace on a CPU if the bitmask is set: |
| 3038 | */ |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 3039 | static cpumask_var_t tracing_cpumask; |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3040 | |
| 3041 | /* |
| 3042 | * The tracer itself will not take this lock, but still we want |
| 3043 | * to provide a consistent cpumask to user-space: |
| 3044 | */ |
| 3045 | static DEFINE_MUTEX(tracing_cpumask_update_lock); |
| 3046 | |
| 3047 | /* |
| 3048 | * Temporary storage for the character representation of the |
| 3049 | * CPU bitmask (and one more byte for the newline): |
| 3050 | */ |
| 3051 | static char mask_str[NR_CPUS + 1]; |
| 3052 | |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3053 | static ssize_t |
| 3054 | tracing_cpumask_read(struct file *filp, char __user *ubuf, |
| 3055 | size_t count, loff_t *ppos) |
| 3056 | { |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3057 | int len; |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3058 | |
| 3059 | mutex_lock(&tracing_cpumask_update_lock); |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3060 | |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 3061 | len = cpumask_scnprintf(mask_str, count, tracing_cpumask); |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3062 | if (count - len < 2) { |
| 3063 | count = -EINVAL; |
| 3064 | goto out_err; |
| 3065 | } |
| 3066 | len += sprintf(mask_str + len, "\n"); |
| 3067 | count = simple_read_from_buffer(ubuf, count, ppos, mask_str, NR_CPUS+1); |
| 3068 | |
| 3069 | out_err: |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3070 | mutex_unlock(&tracing_cpumask_update_lock); |
| 3071 | |
| 3072 | return count; |
| 3073 | } |
| 3074 | |
| 3075 | static ssize_t |
| 3076 | tracing_cpumask_write(struct file *filp, const char __user *ubuf, |
| 3077 | size_t count, loff_t *ppos) |
| 3078 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3079 | struct trace_array *tr = filp->private_data; |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 3080 | cpumask_var_t tracing_cpumask_new; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3081 | int err, cpu; |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 3082 | |
| 3083 | if (!alloc_cpumask_var(&tracing_cpumask_new, GFP_KERNEL)) |
| 3084 | return -ENOMEM; |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3085 | |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 3086 | err = cpumask_parse_user(ubuf, count, tracing_cpumask_new); |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3087 | if (err) |
| 3088 | goto err_unlock; |
| 3089 | |
Li Zefan | 215368e | 2009-06-15 10:56:42 +0800 | [diff] [blame] | 3090 | mutex_lock(&tracing_cpumask_update_lock); |
| 3091 | |
Steven Rostedt | a5e2588 | 2008-12-02 15:34:05 -0500 | [diff] [blame] | 3092 | local_irq_disable(); |
Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 3093 | arch_spin_lock(&ftrace_max_lock); |
Steven Rostedt | ab46428 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 3094 | for_each_tracing_cpu(cpu) { |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3095 | /* |
| 3096 | * Increase/decrease the disabled counter if we are |
| 3097 | * about to flip a bit in the cpumask: |
| 3098 | */ |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 3099 | if (cpumask_test_cpu(cpu, tracing_cpumask) && |
| 3100 | !cpumask_test_cpu(cpu, tracing_cpumask_new)) { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3101 | atomic_inc(&per_cpu_ptr(tr->trace_buffer.data, cpu)->disabled); |
| 3102 | ring_buffer_record_disable_cpu(tr->trace_buffer.buffer, cpu); |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3103 | } |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 3104 | if (!cpumask_test_cpu(cpu, tracing_cpumask) && |
| 3105 | cpumask_test_cpu(cpu, tracing_cpumask_new)) { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3106 | atomic_dec(&per_cpu_ptr(tr->trace_buffer.data, cpu)->disabled); |
| 3107 | ring_buffer_record_enable_cpu(tr->trace_buffer.buffer, cpu); |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3108 | } |
| 3109 | } |
Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 3110 | arch_spin_unlock(&ftrace_max_lock); |
Steven Rostedt | a5e2588 | 2008-12-02 15:34:05 -0500 | [diff] [blame] | 3111 | local_irq_enable(); |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3112 | |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 3113 | cpumask_copy(tracing_cpumask, tracing_cpumask_new); |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3114 | |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3115 | mutex_unlock(&tracing_cpumask_update_lock); |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 3116 | free_cpumask_var(tracing_cpumask_new); |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3117 | |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3118 | return count; |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3119 | |
| 3120 | err_unlock: |
Li Zefan | 215368e | 2009-06-15 10:56:42 +0800 | [diff] [blame] | 3121 | free_cpumask_var(tracing_cpumask_new); |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3122 | |
| 3123 | return err; |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3124 | } |
| 3125 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 3126 | static const struct file_operations tracing_cpumask_fops = { |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3127 | .open = tracing_open_generic, |
| 3128 | .read = tracing_cpumask_read, |
| 3129 | .write = tracing_cpumask_write, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 3130 | .llseek = generic_file_llseek, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3131 | }; |
| 3132 | |
Li Zefan | fdb372e | 2009-12-08 11:15:59 +0800 | [diff] [blame] | 3133 | static int tracing_trace_options_show(struct seq_file *m, void *v) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3134 | { |
Steven Rostedt | d8e83d2 | 2009-02-26 23:55:58 -0500 | [diff] [blame] | 3135 | struct tracer_opt *trace_opts; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3136 | struct trace_array *tr = m->private; |
Steven Rostedt | d8e83d2 | 2009-02-26 23:55:58 -0500 | [diff] [blame] | 3137 | u32 tracer_flags; |
Steven Rostedt | d8e83d2 | 2009-02-26 23:55:58 -0500 | [diff] [blame] | 3138 | int i; |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 3139 | |
Steven Rostedt | d8e83d2 | 2009-02-26 23:55:58 -0500 | [diff] [blame] | 3140 | mutex_lock(&trace_types_lock); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3141 | tracer_flags = tr->current_trace->flags->val; |
| 3142 | trace_opts = tr->current_trace->flags->opts; |
Steven Rostedt | d8e83d2 | 2009-02-26 23:55:58 -0500 | [diff] [blame] | 3143 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3144 | for (i = 0; trace_options[i]; i++) { |
| 3145 | if (trace_flags & (1 << i)) |
Li Zefan | fdb372e | 2009-12-08 11:15:59 +0800 | [diff] [blame] | 3146 | seq_printf(m, "%s\n", trace_options[i]); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3147 | else |
Li Zefan | fdb372e | 2009-12-08 11:15:59 +0800 | [diff] [blame] | 3148 | seq_printf(m, "no%s\n", trace_options[i]); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3149 | } |
| 3150 | |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 3151 | for (i = 0; trace_opts[i].name; i++) { |
| 3152 | if (tracer_flags & trace_opts[i].bit) |
Li Zefan | fdb372e | 2009-12-08 11:15:59 +0800 | [diff] [blame] | 3153 | seq_printf(m, "%s\n", trace_opts[i].name); |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 3154 | else |
Li Zefan | fdb372e | 2009-12-08 11:15:59 +0800 | [diff] [blame] | 3155 | seq_printf(m, "no%s\n", trace_opts[i].name); |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 3156 | } |
Steven Rostedt | d8e83d2 | 2009-02-26 23:55:58 -0500 | [diff] [blame] | 3157 | mutex_unlock(&trace_types_lock); |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 3158 | |
Li Zefan | fdb372e | 2009-12-08 11:15:59 +0800 | [diff] [blame] | 3159 | return 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3160 | } |
| 3161 | |
Li Zefan | 8d18eaa | 2009-12-08 11:17:06 +0800 | [diff] [blame] | 3162 | static int __set_tracer_option(struct tracer *trace, |
| 3163 | struct tracer_flags *tracer_flags, |
| 3164 | struct tracer_opt *opts, int neg) |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 3165 | { |
Li Zefan | 8d18eaa | 2009-12-08 11:17:06 +0800 | [diff] [blame] | 3166 | int ret; |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 3167 | |
Li Zefan | 8d18eaa | 2009-12-08 11:17:06 +0800 | [diff] [blame] | 3168 | ret = trace->set_flag(tracer_flags->val, opts->bit, !neg); |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 3169 | if (ret) |
| 3170 | return ret; |
| 3171 | |
| 3172 | if (neg) |
Zhaolei | 7770841 | 2009-08-07 18:53:21 +0800 | [diff] [blame] | 3173 | tracer_flags->val &= ~opts->bit; |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 3174 | else |
Zhaolei | 7770841 | 2009-08-07 18:53:21 +0800 | [diff] [blame] | 3175 | tracer_flags->val |= opts->bit; |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 3176 | return 0; |
| 3177 | } |
| 3178 | |
Li Zefan | 8d18eaa | 2009-12-08 11:17:06 +0800 | [diff] [blame] | 3179 | /* Try to assign a tracer specific option */ |
| 3180 | static int set_tracer_option(struct tracer *trace, char *cmp, int neg) |
| 3181 | { |
| 3182 | struct tracer_flags *tracer_flags = trace->flags; |
| 3183 | struct tracer_opt *opts = NULL; |
| 3184 | int i; |
| 3185 | |
| 3186 | for (i = 0; tracer_flags->opts[i].name; i++) { |
| 3187 | opts = &tracer_flags->opts[i]; |
| 3188 | |
| 3189 | if (strcmp(cmp, opts->name) == 0) |
| 3190 | return __set_tracer_option(trace, trace->flags, |
| 3191 | opts, neg); |
| 3192 | } |
| 3193 | |
| 3194 | return -EINVAL; |
| 3195 | } |
| 3196 | |
Steven Rostedt (Red Hat) | 613f04a | 2013-03-14 15:03:53 -0400 | [diff] [blame] | 3197 | /* Some tracers require overwrite to stay enabled */ |
| 3198 | int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set) |
| 3199 | { |
| 3200 | if (tracer->enabled && (mask & TRACE_ITER_OVERWRITE) && !set) |
| 3201 | return -1; |
| 3202 | |
| 3203 | return 0; |
| 3204 | } |
| 3205 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3206 | int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled) |
Steven Rostedt | af4617b | 2009-03-17 18:09:55 -0400 | [diff] [blame] | 3207 | { |
| 3208 | /* do nothing if flag is already set */ |
| 3209 | if (!!(trace_flags & mask) == !!enabled) |
Steven Rostedt (Red Hat) | 613f04a | 2013-03-14 15:03:53 -0400 | [diff] [blame] | 3210 | return 0; |
| 3211 | |
| 3212 | /* Give the tracer a chance to approve the change */ |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3213 | if (tr->current_trace->flag_changed) |
| 3214 | if (tr->current_trace->flag_changed(tr->current_trace, mask, !!enabled)) |
Steven Rostedt (Red Hat) | 613f04a | 2013-03-14 15:03:53 -0400 | [diff] [blame] | 3215 | return -EINVAL; |
Steven Rostedt | af4617b | 2009-03-17 18:09:55 -0400 | [diff] [blame] | 3216 | |
| 3217 | if (enabled) |
| 3218 | trace_flags |= mask; |
| 3219 | else |
| 3220 | trace_flags &= ~mask; |
Li Zefan | e870e9a | 2010-07-02 11:07:32 +0800 | [diff] [blame] | 3221 | |
| 3222 | if (mask == TRACE_ITER_RECORD_CMD) |
| 3223 | trace_event_enable_cmd_record(enabled); |
David Sharp | 750912f | 2010-12-08 13:46:47 -0800 | [diff] [blame] | 3224 | |
Steven Rostedt (Red Hat) | 8090282 | 2013-03-14 14:20:54 -0400 | [diff] [blame] | 3225 | if (mask == TRACE_ITER_OVERWRITE) { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3226 | ring_buffer_change_overwrite(tr->trace_buffer.buffer, enabled); |
Steven Rostedt (Red Hat) | 8090282 | 2013-03-14 14:20:54 -0400 | [diff] [blame] | 3227 | #ifdef CONFIG_TRACER_MAX_TRACE |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3228 | ring_buffer_change_overwrite(tr->max_buffer.buffer, enabled); |
Steven Rostedt (Red Hat) | 8090282 | 2013-03-14 14:20:54 -0400 | [diff] [blame] | 3229 | #endif |
| 3230 | } |
Steven Rostedt | 8169883 | 2012-10-11 10:15:05 -0400 | [diff] [blame] | 3231 | |
| 3232 | if (mask == TRACE_ITER_PRINTK) |
| 3233 | trace_printk_start_stop_comm(enabled); |
Steven Rostedt (Red Hat) | 613f04a | 2013-03-14 15:03:53 -0400 | [diff] [blame] | 3234 | |
| 3235 | return 0; |
Steven Rostedt | af4617b | 2009-03-17 18:09:55 -0400 | [diff] [blame] | 3236 | } |
| 3237 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3238 | static int trace_set_options(struct trace_array *tr, char *option) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3239 | { |
Li Zefan | 8d18eaa | 2009-12-08 11:17:06 +0800 | [diff] [blame] | 3240 | char *cmp; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3241 | int neg = 0; |
Steven Rostedt (Red Hat) | 613f04a | 2013-03-14 15:03:53 -0400 | [diff] [blame] | 3242 | int ret = -ENODEV; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3243 | int i; |
| 3244 | |
Steven Rostedt | 7bcfaf5 | 2012-11-01 22:56:07 -0400 | [diff] [blame] | 3245 | cmp = strstrip(option); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3246 | |
Li Zefan | 8d18eaa | 2009-12-08 11:17:06 +0800 | [diff] [blame] | 3247 | if (strncmp(cmp, "no", 2) == 0) { |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3248 | neg = 1; |
| 3249 | cmp += 2; |
| 3250 | } |
| 3251 | |
Steven Rostedt (Red Hat) | 69d34da | 2013-03-14 13:50:56 -0400 | [diff] [blame] | 3252 | mutex_lock(&trace_types_lock); |
| 3253 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3254 | for (i = 0; trace_options[i]; i++) { |
Li Zefan | 8d18eaa | 2009-12-08 11:17:06 +0800 | [diff] [blame] | 3255 | if (strcmp(cmp, trace_options[i]) == 0) { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3256 | ret = set_tracer_flag(tr, 1 << i, !neg); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3257 | break; |
| 3258 | } |
| 3259 | } |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 3260 | |
| 3261 | /* If no option could be set, test the specific tracer options */ |
Steven Rostedt (Red Hat) | 69d34da | 2013-03-14 13:50:56 -0400 | [diff] [blame] | 3262 | if (!trace_options[i]) |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3263 | ret = set_tracer_option(tr->current_trace, cmp, neg); |
Steven Rostedt (Red Hat) | 69d34da | 2013-03-14 13:50:56 -0400 | [diff] [blame] | 3264 | |
| 3265 | mutex_unlock(&trace_types_lock); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3266 | |
Steven Rostedt | 7bcfaf5 | 2012-11-01 22:56:07 -0400 | [diff] [blame] | 3267 | return ret; |
| 3268 | } |
| 3269 | |
| 3270 | static ssize_t |
| 3271 | tracing_trace_options_write(struct file *filp, const char __user *ubuf, |
| 3272 | size_t cnt, loff_t *ppos) |
| 3273 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3274 | struct seq_file *m = filp->private_data; |
| 3275 | struct trace_array *tr = m->private; |
Steven Rostedt | 7bcfaf5 | 2012-11-01 22:56:07 -0400 | [diff] [blame] | 3276 | char buf[64]; |
Steven Rostedt (Red Hat) | 613f04a | 2013-03-14 15:03:53 -0400 | [diff] [blame] | 3277 | int ret; |
Steven Rostedt | 7bcfaf5 | 2012-11-01 22:56:07 -0400 | [diff] [blame] | 3278 | |
| 3279 | if (cnt >= sizeof(buf)) |
| 3280 | return -EINVAL; |
| 3281 | |
| 3282 | if (copy_from_user(&buf, ubuf, cnt)) |
| 3283 | return -EFAULT; |
| 3284 | |
Steven Rostedt | a8dd217 | 2013-01-09 20:54:17 -0500 | [diff] [blame] | 3285 | buf[cnt] = 0; |
| 3286 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3287 | ret = trace_set_options(tr, buf); |
Steven Rostedt (Red Hat) | 613f04a | 2013-03-14 15:03:53 -0400 | [diff] [blame] | 3288 | if (ret < 0) |
| 3289 | return ret; |
Steven Rostedt | 7bcfaf5 | 2012-11-01 22:56:07 -0400 | [diff] [blame] | 3290 | |
Jiri Olsa | cf8517c | 2009-10-23 19:36:16 -0400 | [diff] [blame] | 3291 | *ppos += cnt; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3292 | |
| 3293 | return cnt; |
| 3294 | } |
| 3295 | |
Li Zefan | fdb372e | 2009-12-08 11:15:59 +0800 | [diff] [blame] | 3296 | static int tracing_trace_options_open(struct inode *inode, struct file *file) |
| 3297 | { |
| 3298 | if (tracing_disabled) |
| 3299 | return -ENODEV; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3300 | |
| 3301 | return single_open(file, tracing_trace_options_show, inode->i_private); |
Li Zefan | fdb372e | 2009-12-08 11:15:59 +0800 | [diff] [blame] | 3302 | } |
| 3303 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 3304 | static const struct file_operations tracing_iter_fops = { |
Li Zefan | fdb372e | 2009-12-08 11:15:59 +0800 | [diff] [blame] | 3305 | .open = tracing_trace_options_open, |
| 3306 | .read = seq_read, |
| 3307 | .llseek = seq_lseek, |
| 3308 | .release = single_release, |
Steven Rostedt | ee6bce5 | 2008-11-12 17:52:37 -0500 | [diff] [blame] | 3309 | .write = tracing_trace_options_write, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3310 | }; |
| 3311 | |
Ingo Molnar | 7bd2f24 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 3312 | static const char readme_msg[] = |
| 3313 | "tracing mini-HOWTO:\n\n" |
Steven Rostedt (Red Hat) | 22f4564 | 2013-03-15 17:23:20 -0400 | [diff] [blame] | 3314 | "# echo 0 > tracing_on : quick way to disable tracing\n" |
| 3315 | "# echo 1 > tracing_on : quick way to re-enable tracing\n\n" |
| 3316 | " Important files:\n" |
| 3317 | " trace\t\t\t- The static contents of the buffer\n" |
| 3318 | "\t\t\t To clear the buffer write into this file: echo > trace\n" |
| 3319 | " trace_pipe\t\t- A consuming read to see the contents of the buffer\n" |
| 3320 | " current_tracer\t- function and latency tracers\n" |
| 3321 | " available_tracers\t- list of configured tracers for current_tracer\n" |
| 3322 | " buffer_size_kb\t- view and modify size of per cpu buffer\n" |
| 3323 | " buffer_total_size_kb - view total size of all cpu buffers\n\n" |
| 3324 | " trace_clock\t\t-change the clock used to order events\n" |
| 3325 | " local: Per cpu clock but may not be synced across CPUs\n" |
| 3326 | " global: Synced across CPUs but slows tracing down.\n" |
| 3327 | " counter: Not a clock, but just an increment\n" |
| 3328 | " uptime: Jiffy counter from time of boot\n" |
| 3329 | " perf: Same clock that perf events use\n" |
| 3330 | #ifdef CONFIG_X86_64 |
| 3331 | " x86-tsc: TSC cycle counter\n" |
| 3332 | #endif |
| 3333 | "\n trace_marker\t\t- Writes into this file writes into the kernel buffer\n" |
| 3334 | " tracing_cpumask\t- Limit which CPUs to trace\n" |
| 3335 | " instances\t\t- Make sub-buffers with: mkdir instances/foo\n" |
| 3336 | "\t\t\t Remove sub-buffer with rmdir\n" |
| 3337 | " trace_options\t\t- Set format or modify how tracing happens\n" |
| 3338 | "\t\t\t Disable an option by adding a suffix 'no' to the option name\n" |
| 3339 | #ifdef CONFIG_DYNAMIC_FTRACE |
| 3340 | "\n available_filter_functions - list of functions that can be filtered on\n" |
| 3341 | " set_ftrace_filter\t- echo function name in here to only trace these functions\n" |
| 3342 | " accepts: func_full_name, *func_end, func_begin*, *func_middle*\n" |
| 3343 | " modules: Can select a group via module\n" |
| 3344 | " Format: :mod:<module-name>\n" |
| 3345 | " example: echo :mod:ext3 > set_ftrace_filter\n" |
| 3346 | " triggers: a command to perform when function is hit\n" |
| 3347 | " Format: <function>:<trigger>[:count]\n" |
| 3348 | " trigger: traceon, traceoff\n" |
| 3349 | " enable_event:<system>:<event>\n" |
| 3350 | " disable_event:<system>:<event>\n" |
| 3351 | #ifdef CONFIG_STACKTRACE |
| 3352 | " stacktrace\n" |
| 3353 | #endif |
| 3354 | #ifdef CONFIG_TRACER_SNAPSHOT |
| 3355 | " snapshot\n" |
| 3356 | #endif |
| 3357 | " example: echo do_fault:traceoff > set_ftrace_filter\n" |
| 3358 | " echo do_trap:traceoff:3 > set_ftrace_filter\n" |
| 3359 | " The first one will disable tracing every time do_fault is hit\n" |
| 3360 | " The second will disable tracing at most 3 times when do_trap is hit\n" |
| 3361 | " The first time do trap is hit and it disables tracing, the counter\n" |
| 3362 | " will decrement to 2. If tracing is already disabled, the counter\n" |
| 3363 | " will not decrement. It only decrements when the trigger did work\n" |
| 3364 | " To remove trigger without count:\n" |
| 3365 | " echo '!<function>:<trigger> > set_ftrace_filter\n" |
| 3366 | " To remove trigger with a count:\n" |
| 3367 | " echo '!<function>:<trigger>:0 > set_ftrace_filter\n" |
| 3368 | " set_ftrace_notrace\t- echo function name in here to never trace.\n" |
| 3369 | " accepts: func_full_name, *func_end, func_begin*, *func_middle*\n" |
| 3370 | " modules: Can select a group via module command :mod:\n" |
| 3371 | " Does not accept triggers\n" |
| 3372 | #endif /* CONFIG_DYNAMIC_FTRACE */ |
| 3373 | #ifdef CONFIG_FUNCTION_TRACER |
| 3374 | " set_ftrace_pid\t- Write pid(s) to only function trace those pids (function)\n" |
| 3375 | #endif |
| 3376 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER |
| 3377 | " set_graph_function\t- Trace the nested calls of a function (function_graph)\n" |
| 3378 | " max_graph_depth\t- Trace a limited depth of nested calls (0 is unlimited)\n" |
| 3379 | #endif |
| 3380 | #ifdef CONFIG_TRACER_SNAPSHOT |
| 3381 | "\n snapshot\t\t- Like 'trace' but shows the content of the static snapshot buffer\n" |
| 3382 | "\t\t\t Read the contents for more information\n" |
| 3383 | #endif |
| 3384 | #ifdef CONFIG_STACKTRACE |
| 3385 | " stack_trace\t\t- Shows the max stack trace when active\n" |
| 3386 | " stack_max_size\t- Shows current max stack size that was traced\n" |
| 3387 | "\t\t\t Write into this file to reset the max size (trigger a new trace)\n" |
| 3388 | #ifdef CONFIG_DYNAMIC_FTRACE |
| 3389 | " stack_trace_filter\t- Like set_ftrace_filter but limits what stack_trace traces\n" |
| 3390 | #endif |
| 3391 | #endif /* CONFIG_STACKTRACE */ |
Ingo Molnar | 7bd2f24 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 3392 | ; |
| 3393 | |
| 3394 | static ssize_t |
| 3395 | tracing_readme_read(struct file *filp, char __user *ubuf, |
| 3396 | size_t cnt, loff_t *ppos) |
| 3397 | { |
| 3398 | return simple_read_from_buffer(ubuf, cnt, ppos, |
| 3399 | readme_msg, strlen(readme_msg)); |
| 3400 | } |
| 3401 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 3402 | static const struct file_operations tracing_readme_fops = { |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3403 | .open = tracing_open_generic, |
| 3404 | .read = tracing_readme_read, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 3405 | .llseek = generic_file_llseek, |
Ingo Molnar | 7bd2f24 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 3406 | }; |
| 3407 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3408 | static ssize_t |
Avadh Patel | 69abe6a | 2009-04-10 16:04:48 -0400 | [diff] [blame] | 3409 | tracing_saved_cmdlines_read(struct file *file, char __user *ubuf, |
| 3410 | size_t cnt, loff_t *ppos) |
| 3411 | { |
| 3412 | char *buf_comm; |
| 3413 | char *file_buf; |
| 3414 | char *buf; |
| 3415 | int len = 0; |
| 3416 | int pid; |
| 3417 | int i; |
| 3418 | |
| 3419 | file_buf = kmalloc(SAVED_CMDLINES*(16+TASK_COMM_LEN), GFP_KERNEL); |
| 3420 | if (!file_buf) |
| 3421 | return -ENOMEM; |
| 3422 | |
| 3423 | buf_comm = kmalloc(TASK_COMM_LEN, GFP_KERNEL); |
| 3424 | if (!buf_comm) { |
| 3425 | kfree(file_buf); |
| 3426 | return -ENOMEM; |
| 3427 | } |
| 3428 | |
| 3429 | buf = file_buf; |
| 3430 | |
| 3431 | for (i = 0; i < SAVED_CMDLINES; i++) { |
| 3432 | int r; |
| 3433 | |
| 3434 | pid = map_cmdline_to_pid[i]; |
| 3435 | if (pid == -1 || pid == NO_CMDLINE_MAP) |
| 3436 | continue; |
| 3437 | |
| 3438 | trace_find_cmdline(pid, buf_comm); |
| 3439 | r = sprintf(buf, "%d %s\n", pid, buf_comm); |
| 3440 | buf += r; |
| 3441 | len += r; |
| 3442 | } |
| 3443 | |
| 3444 | len = simple_read_from_buffer(ubuf, cnt, ppos, |
| 3445 | file_buf, len); |
| 3446 | |
| 3447 | kfree(file_buf); |
| 3448 | kfree(buf_comm); |
| 3449 | |
| 3450 | return len; |
| 3451 | } |
| 3452 | |
| 3453 | static const struct file_operations tracing_saved_cmdlines_fops = { |
| 3454 | .open = tracing_open_generic, |
| 3455 | .read = tracing_saved_cmdlines_read, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 3456 | .llseek = generic_file_llseek, |
Avadh Patel | 69abe6a | 2009-04-10 16:04:48 -0400 | [diff] [blame] | 3457 | }; |
| 3458 | |
| 3459 | static ssize_t |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3460 | tracing_set_trace_read(struct file *filp, char __user *ubuf, |
| 3461 | size_t cnt, loff_t *ppos) |
| 3462 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3463 | struct trace_array *tr = filp->private_data; |
Li Zefan | ee6c2c1 | 2009-09-18 14:06:47 +0800 | [diff] [blame] | 3464 | char buf[MAX_TRACER_SIZE+2]; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3465 | int r; |
| 3466 | |
| 3467 | mutex_lock(&trace_types_lock); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3468 | r = sprintf(buf, "%s\n", tr->current_trace->name); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3469 | mutex_unlock(&trace_types_lock); |
| 3470 | |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3471 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, r); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3472 | } |
| 3473 | |
Arnaldo Carvalho de Melo | b6f11df | 2009-02-05 18:02:00 -0200 | [diff] [blame] | 3474 | int tracer_init(struct tracer *t, struct trace_array *tr) |
| 3475 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3476 | tracing_reset_online_cpus(&tr->trace_buffer); |
Arnaldo Carvalho de Melo | b6f11df | 2009-02-05 18:02:00 -0200 | [diff] [blame] | 3477 | return t->init(tr); |
| 3478 | } |
| 3479 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3480 | static void set_buffer_entries(struct trace_buffer *buf, unsigned long val) |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 3481 | { |
| 3482 | int cpu; |
Steven Rostedt (Red Hat) | 737223f | 2013-03-05 21:13:47 -0500 | [diff] [blame] | 3483 | |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 3484 | for_each_tracing_cpu(cpu) |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3485 | per_cpu_ptr(buf->data, cpu)->entries = val; |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 3486 | } |
| 3487 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3488 | #ifdef CONFIG_TRACER_MAX_TRACE |
Hiraku Toyooka | d60da50 | 2012-10-17 11:56:16 +0900 | [diff] [blame] | 3489 | /* resize @tr's buffer to the size of @size_tr's entries */ |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3490 | static int resize_buffer_duplicate_size(struct trace_buffer *trace_buf, |
| 3491 | struct trace_buffer *size_buf, int cpu_id) |
Hiraku Toyooka | d60da50 | 2012-10-17 11:56:16 +0900 | [diff] [blame] | 3492 | { |
| 3493 | int cpu, ret = 0; |
| 3494 | |
| 3495 | if (cpu_id == RING_BUFFER_ALL_CPUS) { |
| 3496 | for_each_tracing_cpu(cpu) { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3497 | ret = ring_buffer_resize(trace_buf->buffer, |
| 3498 | per_cpu_ptr(size_buf->data, cpu)->entries, cpu); |
Hiraku Toyooka | d60da50 | 2012-10-17 11:56:16 +0900 | [diff] [blame] | 3499 | if (ret < 0) |
| 3500 | break; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3501 | per_cpu_ptr(trace_buf->data, cpu)->entries = |
| 3502 | per_cpu_ptr(size_buf->data, cpu)->entries; |
Hiraku Toyooka | d60da50 | 2012-10-17 11:56:16 +0900 | [diff] [blame] | 3503 | } |
| 3504 | } else { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3505 | ret = ring_buffer_resize(trace_buf->buffer, |
| 3506 | per_cpu_ptr(size_buf->data, cpu_id)->entries, cpu_id); |
Hiraku Toyooka | d60da50 | 2012-10-17 11:56:16 +0900 | [diff] [blame] | 3507 | if (ret == 0) |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3508 | per_cpu_ptr(trace_buf->data, cpu_id)->entries = |
| 3509 | per_cpu_ptr(size_buf->data, cpu_id)->entries; |
Hiraku Toyooka | d60da50 | 2012-10-17 11:56:16 +0900 | [diff] [blame] | 3510 | } |
| 3511 | |
| 3512 | return ret; |
| 3513 | } |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3514 | #endif /* CONFIG_TRACER_MAX_TRACE */ |
Hiraku Toyooka | d60da50 | 2012-10-17 11:56:16 +0900 | [diff] [blame] | 3515 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3516 | static int __tracing_resize_ring_buffer(struct trace_array *tr, |
| 3517 | unsigned long size, int cpu) |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 3518 | { |
| 3519 | int ret; |
| 3520 | |
| 3521 | /* |
| 3522 | * If kernel or user changes the size of the ring buffer |
Steven Rostedt | a123c52 | 2009-03-12 11:21:08 -0400 | [diff] [blame] | 3523 | * we use the size that was given, and we can forget about |
| 3524 | * expanding it later. |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 3525 | */ |
Steven Rostedt (Red Hat) | 55034cd | 2013-03-07 22:48:09 -0500 | [diff] [blame] | 3526 | ring_buffer_expanded = true; |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 3527 | |
Steven Rostedt | b382ede6 | 2012-10-10 21:44:34 -0400 | [diff] [blame] | 3528 | /* May be called before buffers are initialized */ |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3529 | if (!tr->trace_buffer.buffer) |
Steven Rostedt | b382ede6 | 2012-10-10 21:44:34 -0400 | [diff] [blame] | 3530 | return 0; |
| 3531 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3532 | ret = ring_buffer_resize(tr->trace_buffer.buffer, size, cpu); |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 3533 | if (ret < 0) |
| 3534 | return ret; |
| 3535 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3536 | #ifdef CONFIG_TRACER_MAX_TRACE |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3537 | if (!(tr->flags & TRACE_ARRAY_FL_GLOBAL) || |
| 3538 | !tr->current_trace->use_max_tr) |
KOSAKI Motohiro | ef710e1 | 2010-07-01 14:34:35 +0900 | [diff] [blame] | 3539 | goto out; |
| 3540 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3541 | ret = ring_buffer_resize(tr->max_buffer.buffer, size, cpu); |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 3542 | if (ret < 0) { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3543 | int r = resize_buffer_duplicate_size(&tr->trace_buffer, |
| 3544 | &tr->trace_buffer, cpu); |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 3545 | if (r < 0) { |
Steven Rostedt | a123c52 | 2009-03-12 11:21:08 -0400 | [diff] [blame] | 3546 | /* |
| 3547 | * AARGH! We are left with different |
| 3548 | * size max buffer!!!! |
| 3549 | * The max buffer is our "snapshot" buffer. |
| 3550 | * When a tracer needs a snapshot (one of the |
| 3551 | * latency tracers), it swaps the max buffer |
| 3552 | * with the saved snap shot. We succeeded to |
| 3553 | * update the size of the main buffer, but failed to |
| 3554 | * update the size of the max buffer. But when we tried |
| 3555 | * to reset the main buffer to the original size, we |
| 3556 | * failed there too. This is very unlikely to |
| 3557 | * happen, but if it does, warn and kill all |
| 3558 | * tracing. |
| 3559 | */ |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 3560 | WARN_ON(1); |
| 3561 | tracing_disabled = 1; |
| 3562 | } |
| 3563 | return ret; |
| 3564 | } |
| 3565 | |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 3566 | if (cpu == RING_BUFFER_ALL_CPUS) |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3567 | set_buffer_entries(&tr->max_buffer, size); |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 3568 | else |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3569 | per_cpu_ptr(tr->max_buffer.data, cpu)->entries = size; |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 3570 | |
KOSAKI Motohiro | ef710e1 | 2010-07-01 14:34:35 +0900 | [diff] [blame] | 3571 | out: |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3572 | #endif /* CONFIG_TRACER_MAX_TRACE */ |
| 3573 | |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 3574 | if (cpu == RING_BUFFER_ALL_CPUS) |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3575 | set_buffer_entries(&tr->trace_buffer, size); |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 3576 | else |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3577 | per_cpu_ptr(tr->trace_buffer.data, cpu)->entries = size; |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 3578 | |
| 3579 | return ret; |
| 3580 | } |
| 3581 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3582 | static ssize_t tracing_resize_ring_buffer(struct trace_array *tr, |
| 3583 | unsigned long size, int cpu_id) |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 3584 | { |
Vaibhav Nagarnaik | 83f4031 | 2012-05-03 18:59:50 -0700 | [diff] [blame] | 3585 | int ret = size; |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 3586 | |
| 3587 | mutex_lock(&trace_types_lock); |
| 3588 | |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 3589 | if (cpu_id != RING_BUFFER_ALL_CPUS) { |
| 3590 | /* make sure, this cpu is enabled in the mask */ |
| 3591 | if (!cpumask_test_cpu(cpu_id, tracing_buffer_mask)) { |
| 3592 | ret = -EINVAL; |
| 3593 | goto out; |
| 3594 | } |
| 3595 | } |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 3596 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3597 | ret = __tracing_resize_ring_buffer(tr, size, cpu_id); |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 3598 | if (ret < 0) |
| 3599 | ret = -ENOMEM; |
| 3600 | |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 3601 | out: |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 3602 | mutex_unlock(&trace_types_lock); |
| 3603 | |
| 3604 | return ret; |
| 3605 | } |
| 3606 | |
KOSAKI Motohiro | ef710e1 | 2010-07-01 14:34:35 +0900 | [diff] [blame] | 3607 | |
Steven Rostedt | 1852fcc | 2009-03-11 14:33:00 -0400 | [diff] [blame] | 3608 | /** |
| 3609 | * tracing_update_buffers - used by tracing facility to expand ring buffers |
| 3610 | * |
| 3611 | * To save on memory when the tracing is never used on a system with it |
| 3612 | * configured in. The ring buffers are set to a minimum size. But once |
| 3613 | * a user starts to use the tracing facility, then they need to grow |
| 3614 | * to their default size. |
| 3615 | * |
| 3616 | * This function is to be called when a tracer is about to be used. |
| 3617 | */ |
| 3618 | int tracing_update_buffers(void) |
| 3619 | { |
| 3620 | int ret = 0; |
| 3621 | |
Steven Rostedt | 1027fcb | 2009-03-12 11:33:20 -0400 | [diff] [blame] | 3622 | mutex_lock(&trace_types_lock); |
Steven Rostedt | 1852fcc | 2009-03-11 14:33:00 -0400 | [diff] [blame] | 3623 | if (!ring_buffer_expanded) |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3624 | ret = __tracing_resize_ring_buffer(&global_trace, trace_buf_size, |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 3625 | RING_BUFFER_ALL_CPUS); |
Steven Rostedt | 1027fcb | 2009-03-12 11:33:20 -0400 | [diff] [blame] | 3626 | mutex_unlock(&trace_types_lock); |
Steven Rostedt | 1852fcc | 2009-03-11 14:33:00 -0400 | [diff] [blame] | 3627 | |
| 3628 | return ret; |
| 3629 | } |
| 3630 | |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 3631 | struct trace_option_dentry; |
| 3632 | |
| 3633 | static struct trace_option_dentry * |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3634 | create_trace_option_files(struct trace_array *tr, struct tracer *tracer); |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 3635 | |
| 3636 | static void |
| 3637 | destroy_trace_option_files(struct trace_option_dentry *topts); |
| 3638 | |
Steven Rostedt | b2821ae | 2009-02-02 21:38:32 -0500 | [diff] [blame] | 3639 | static int tracing_set_tracer(const char *buf) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3640 | { |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 3641 | static struct trace_option_dentry *topts; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3642 | struct trace_array *tr = &global_trace; |
| 3643 | struct tracer *t; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3644 | #ifdef CONFIG_TRACER_MAX_TRACE |
Steven Rostedt | 34600f0 | 2013-01-22 13:35:11 -0500 | [diff] [blame] | 3645 | bool had_max_tr; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3646 | #endif |
Peter Zijlstra | d9e5407 | 2008-11-01 19:57:37 +0100 | [diff] [blame] | 3647 | int ret = 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3648 | |
Steven Rostedt | 1027fcb | 2009-03-12 11:33:20 -0400 | [diff] [blame] | 3649 | mutex_lock(&trace_types_lock); |
| 3650 | |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 3651 | if (!ring_buffer_expanded) { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3652 | ret = __tracing_resize_ring_buffer(tr, trace_buf_size, |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 3653 | RING_BUFFER_ALL_CPUS); |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 3654 | if (ret < 0) |
Frederic Weisbecker | 59f586d | 2009-03-15 22:10:39 +0100 | [diff] [blame] | 3655 | goto out; |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 3656 | ret = 0; |
| 3657 | } |
| 3658 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3659 | for (t = trace_types; t; t = t->next) { |
| 3660 | if (strcmp(t->name, buf) == 0) |
| 3661 | break; |
| 3662 | } |
Frederic Weisbecker | c2931e0 | 2008-10-04 22:04:44 +0200 | [diff] [blame] | 3663 | if (!t) { |
| 3664 | ret = -EINVAL; |
| 3665 | goto out; |
| 3666 | } |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3667 | if (t == tr->current_trace) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3668 | goto out; |
| 3669 | |
Steven Rostedt | 9f029e8 | 2008-11-12 15:24:24 -0500 | [diff] [blame] | 3670 | trace_branch_disable(); |
Steven Rostedt (Red Hat) | 613f04a | 2013-03-14 15:03:53 -0400 | [diff] [blame] | 3671 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3672 | tr->current_trace->enabled = false; |
Steven Rostedt (Red Hat) | 613f04a | 2013-03-14 15:03:53 -0400 | [diff] [blame] | 3673 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3674 | if (tr->current_trace->reset) |
| 3675 | tr->current_trace->reset(tr); |
Steven Rostedt | 34600f0 | 2013-01-22 13:35:11 -0500 | [diff] [blame] | 3676 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3677 | /* Current trace needs to be nop_trace before synchronize_sched */ |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3678 | tr->current_trace = &nop_trace; |
Steven Rostedt | 34600f0 | 2013-01-22 13:35:11 -0500 | [diff] [blame] | 3679 | |
Steven Rostedt (Red Hat) | 45ad21c | 2013-03-05 18:25:02 -0500 | [diff] [blame] | 3680 | #ifdef CONFIG_TRACER_MAX_TRACE |
| 3681 | had_max_tr = tr->allocated_snapshot; |
Steven Rostedt | 34600f0 | 2013-01-22 13:35:11 -0500 | [diff] [blame] | 3682 | |
| 3683 | if (had_max_tr && !t->use_max_tr) { |
| 3684 | /* |
| 3685 | * We need to make sure that the update_max_tr sees that |
| 3686 | * current_trace changed to nop_trace to keep it from |
| 3687 | * swapping the buffers after we resize it. |
| 3688 | * The update_max_tr is called from interrupts disabled |
| 3689 | * so a synchronized_sched() is sufficient. |
| 3690 | */ |
| 3691 | synchronize_sched(); |
Steven Rostedt (Red Hat) | 3209cff | 2013-03-12 11:17:54 -0400 | [diff] [blame] | 3692 | free_snapshot(tr); |
KOSAKI Motohiro | ef710e1 | 2010-07-01 14:34:35 +0900 | [diff] [blame] | 3693 | } |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3694 | #endif |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 3695 | destroy_trace_option_files(topts); |
| 3696 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3697 | topts = create_trace_option_files(tr, t); |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3698 | |
| 3699 | #ifdef CONFIG_TRACER_MAX_TRACE |
Steven Rostedt | 34600f0 | 2013-01-22 13:35:11 -0500 | [diff] [blame] | 3700 | if (t->use_max_tr && !had_max_tr) { |
Steven Rostedt (Red Hat) | 3209cff | 2013-03-12 11:17:54 -0400 | [diff] [blame] | 3701 | ret = alloc_snapshot(tr); |
Hiraku Toyooka | d60da50 | 2012-10-17 11:56:16 +0900 | [diff] [blame] | 3702 | if (ret < 0) |
| 3703 | goto out; |
KOSAKI Motohiro | ef710e1 | 2010-07-01 14:34:35 +0900 | [diff] [blame] | 3704 | } |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3705 | #endif |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 3706 | |
Frederic Weisbecker | 1c80025 | 2008-11-16 05:57:26 +0100 | [diff] [blame] | 3707 | if (t->init) { |
Arnaldo Carvalho de Melo | b6f11df | 2009-02-05 18:02:00 -0200 | [diff] [blame] | 3708 | ret = tracer_init(t, tr); |
Frederic Weisbecker | 1c80025 | 2008-11-16 05:57:26 +0100 | [diff] [blame] | 3709 | if (ret) |
| 3710 | goto out; |
| 3711 | } |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3712 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3713 | tr->current_trace = t; |
| 3714 | tr->current_trace->enabled = true; |
Steven Rostedt | 9f029e8 | 2008-11-12 15:24:24 -0500 | [diff] [blame] | 3715 | trace_branch_enable(tr); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3716 | out: |
| 3717 | mutex_unlock(&trace_types_lock); |
| 3718 | |
Peter Zijlstra | d9e5407 | 2008-11-01 19:57:37 +0100 | [diff] [blame] | 3719 | return ret; |
| 3720 | } |
| 3721 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3722 | static ssize_t |
| 3723 | tracing_set_trace_write(struct file *filp, const char __user *ubuf, |
| 3724 | size_t cnt, loff_t *ppos) |
| 3725 | { |
Li Zefan | ee6c2c1 | 2009-09-18 14:06:47 +0800 | [diff] [blame] | 3726 | char buf[MAX_TRACER_SIZE+1]; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3727 | int i; |
| 3728 | size_t ret; |
Frederic Weisbecker | e6e7a65 | 2008-11-16 05:53:19 +0100 | [diff] [blame] | 3729 | int err; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3730 | |
Steven Rostedt | 60063a6 | 2008-10-28 10:44:24 -0400 | [diff] [blame] | 3731 | ret = cnt; |
| 3732 | |
Li Zefan | ee6c2c1 | 2009-09-18 14:06:47 +0800 | [diff] [blame] | 3733 | if (cnt > MAX_TRACER_SIZE) |
| 3734 | cnt = MAX_TRACER_SIZE; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3735 | |
| 3736 | if (copy_from_user(&buf, ubuf, cnt)) |
| 3737 | return -EFAULT; |
| 3738 | |
| 3739 | buf[cnt] = 0; |
| 3740 | |
| 3741 | /* strip ending whitespace. */ |
| 3742 | for (i = cnt - 1; i > 0 && isspace(buf[i]); i--) |
| 3743 | buf[i] = 0; |
| 3744 | |
Frederic Weisbecker | e6e7a65 | 2008-11-16 05:53:19 +0100 | [diff] [blame] | 3745 | err = tracing_set_tracer(buf); |
| 3746 | if (err) |
| 3747 | return err; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3748 | |
Jiri Olsa | cf8517c | 2009-10-23 19:36:16 -0400 | [diff] [blame] | 3749 | *ppos += ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3750 | |
Frederic Weisbecker | c2931e0 | 2008-10-04 22:04:44 +0200 | [diff] [blame] | 3751 | return ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3752 | } |
| 3753 | |
| 3754 | static ssize_t |
| 3755 | tracing_max_lat_read(struct file *filp, char __user *ubuf, |
| 3756 | size_t cnt, loff_t *ppos) |
| 3757 | { |
| 3758 | unsigned long *ptr = filp->private_data; |
| 3759 | char buf[64]; |
| 3760 | int r; |
| 3761 | |
Steven Rostedt | cffae43 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 3762 | r = snprintf(buf, sizeof(buf), "%ld\n", |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3763 | *ptr == (unsigned long)-1 ? -1 : nsecs_to_usecs(*ptr)); |
Steven Rostedt | cffae43 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 3764 | if (r > sizeof(buf)) |
| 3765 | r = sizeof(buf); |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3766 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, r); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3767 | } |
| 3768 | |
| 3769 | static ssize_t |
| 3770 | tracing_max_lat_write(struct file *filp, const char __user *ubuf, |
| 3771 | size_t cnt, loff_t *ppos) |
| 3772 | { |
Hannes Eder | 5e39841 | 2009-02-10 19:44:34 +0100 | [diff] [blame] | 3773 | unsigned long *ptr = filp->private_data; |
Hannes Eder | 5e39841 | 2009-02-10 19:44:34 +0100 | [diff] [blame] | 3774 | unsigned long val; |
Steven Rostedt | c6caeeb | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 3775 | int ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3776 | |
Peter Huewe | 22fe9b5 | 2011-06-07 21:58:27 +0200 | [diff] [blame] | 3777 | ret = kstrtoul_from_user(ubuf, cnt, 10, &val); |
| 3778 | if (ret) |
Steven Rostedt | c6caeeb | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 3779 | return ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3780 | |
| 3781 | *ptr = val * 1000; |
| 3782 | |
| 3783 | return cnt; |
| 3784 | } |
| 3785 | |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3786 | static int tracing_open_pipe(struct inode *inode, struct file *filp) |
| 3787 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3788 | struct trace_cpu *tc = inode->i_private; |
| 3789 | struct trace_array *tr = tc->tr; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3790 | struct trace_iterator *iter; |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 3791 | int ret = 0; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3792 | |
| 3793 | if (tracing_disabled) |
| 3794 | return -ENODEV; |
| 3795 | |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 3796 | mutex_lock(&trace_types_lock); |
| 3797 | |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3798 | /* create a buffer to store the information to pass to userspace */ |
| 3799 | iter = kzalloc(sizeof(*iter), GFP_KERNEL); |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 3800 | if (!iter) { |
| 3801 | ret = -ENOMEM; |
| 3802 | goto out; |
| 3803 | } |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3804 | |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 3805 | /* |
| 3806 | * We make a copy of the current tracer to avoid concurrent |
| 3807 | * changes on it while we are reading. |
| 3808 | */ |
| 3809 | iter->trace = kmalloc(sizeof(*iter->trace), GFP_KERNEL); |
| 3810 | if (!iter->trace) { |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 3811 | ret = -ENOMEM; |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 3812 | goto fail; |
| 3813 | } |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3814 | *iter->trace = *tr->current_trace; |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 3815 | |
| 3816 | if (!alloc_cpumask_var(&iter->started, GFP_KERNEL)) { |
| 3817 | ret = -ENOMEM; |
| 3818 | goto fail; |
Rusty Russell | 4462344 | 2009-01-01 10:12:23 +1030 | [diff] [blame] | 3819 | } |
| 3820 | |
Steven Rostedt | a309720 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 3821 | /* trace pipe does not show start of buffer */ |
Rusty Russell | 4462344 | 2009-01-01 10:12:23 +1030 | [diff] [blame] | 3822 | cpumask_setall(iter->started); |
Steven Rostedt | a309720 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 3823 | |
Steven Rostedt | 112f38a7 | 2009-06-01 15:16:05 -0400 | [diff] [blame] | 3824 | if (trace_flags & TRACE_ITER_LATENCY_FMT) |
| 3825 | iter->iter_flags |= TRACE_FILE_LAT_FMT; |
| 3826 | |
David Sharp | 8be0709 | 2012-11-13 12:18:22 -0800 | [diff] [blame] | 3827 | /* Output in nanoseconds only if we are using a clock in nanoseconds. */ |
| 3828 | if (trace_clocks[trace_clock_id].in_ns) |
| 3829 | iter->iter_flags |= TRACE_FILE_TIME_IN_NS; |
| 3830 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3831 | iter->cpu_file = tc->cpu; |
| 3832 | iter->tr = tc->tr; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3833 | iter->trace_buffer = &tc->tr->trace_buffer; |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 3834 | mutex_init(&iter->mutex); |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3835 | filp->private_data = iter; |
| 3836 | |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 3837 | if (iter->trace->pipe_open) |
| 3838 | iter->trace->pipe_open(iter); |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 3839 | |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 3840 | nonseekable_open(inode, filp); |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 3841 | out: |
| 3842 | mutex_unlock(&trace_types_lock); |
| 3843 | return ret; |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 3844 | |
| 3845 | fail: |
| 3846 | kfree(iter->trace); |
| 3847 | kfree(iter); |
| 3848 | mutex_unlock(&trace_types_lock); |
| 3849 | return ret; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3850 | } |
| 3851 | |
| 3852 | static int tracing_release_pipe(struct inode *inode, struct file *file) |
| 3853 | { |
| 3854 | struct trace_iterator *iter = file->private_data; |
| 3855 | |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 3856 | mutex_lock(&trace_types_lock); |
| 3857 | |
Steven Rostedt | 29bf4a5 | 2009-12-09 12:37:43 -0500 | [diff] [blame] | 3858 | if (iter->trace->pipe_close) |
Steven Rostedt | c521efd | 2009-12-07 09:06:24 -0500 | [diff] [blame] | 3859 | iter->trace->pipe_close(iter); |
| 3860 | |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 3861 | mutex_unlock(&trace_types_lock); |
| 3862 | |
Rusty Russell | 4462344 | 2009-01-01 10:12:23 +1030 | [diff] [blame] | 3863 | free_cpumask_var(iter->started); |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 3864 | mutex_destroy(&iter->mutex); |
| 3865 | kfree(iter->trace); |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3866 | kfree(iter); |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3867 | |
| 3868 | return 0; |
| 3869 | } |
| 3870 | |
Soeren Sandmann Pedersen | 2a2cc8f | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 3871 | static unsigned int |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 3872 | trace_poll(struct trace_iterator *iter, struct file *filp, poll_table *poll_table) |
Soeren Sandmann Pedersen | 2a2cc8f | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 3873 | { |
Steven Rostedt (Red Hat) | 1569345 | 2013-02-28 19:59:17 -0500 | [diff] [blame] | 3874 | /* Iterators are static, they should be filled or empty */ |
| 3875 | if (trace_buffer_iter(iter, iter->cpu_file)) |
| 3876 | return POLLIN | POLLRDNORM; |
Soeren Sandmann Pedersen | 2a2cc8f | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 3877 | |
Steven Rostedt (Red Hat) | 1569345 | 2013-02-28 19:59:17 -0500 | [diff] [blame] | 3878 | if (trace_flags & TRACE_ITER_BLOCK) |
Soeren Sandmann Pedersen | 2a2cc8f | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 3879 | /* |
| 3880 | * Always select as readable when in blocking mode |
| 3881 | */ |
| 3882 | return POLLIN | POLLRDNORM; |
Steven Rostedt (Red Hat) | 1569345 | 2013-02-28 19:59:17 -0500 | [diff] [blame] | 3883 | else |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3884 | return ring_buffer_poll_wait(iter->trace_buffer->buffer, iter->cpu_file, |
Steven Rostedt (Red Hat) | 1569345 | 2013-02-28 19:59:17 -0500 | [diff] [blame] | 3885 | filp, poll_table); |
Soeren Sandmann Pedersen | 2a2cc8f | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 3886 | } |
Soeren Sandmann Pedersen | 2a2cc8f | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 3887 | |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 3888 | static unsigned int |
| 3889 | tracing_poll_pipe(struct file *filp, poll_table *poll_table) |
| 3890 | { |
| 3891 | struct trace_iterator *iter = filp->private_data; |
| 3892 | |
| 3893 | return trace_poll(iter, filp, poll_table); |
Soeren Sandmann Pedersen | 2a2cc8f | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 3894 | } |
| 3895 | |
Frederic Weisbecker | 6eaaa5d | 2009-02-11 02:25:00 +0100 | [diff] [blame] | 3896 | /* |
| 3897 | * This is a make-shift waitqueue. |
| 3898 | * A tracer might use this callback on some rare cases: |
| 3899 | * |
| 3900 | * 1) the current tracer might hold the runqueue lock when it wakes up |
| 3901 | * a reader, hence a deadlock (sched, function, and function graph tracers) |
| 3902 | * 2) the function tracers, trace all functions, we don't want |
| 3903 | * the overhead of calling wake_up and friends |
| 3904 | * (and tracing them too) |
| 3905 | * |
| 3906 | * Anyway, this is really very primitive wakeup. |
| 3907 | */ |
| 3908 | void poll_wait_pipe(struct trace_iterator *iter) |
| 3909 | { |
| 3910 | set_current_state(TASK_INTERRUPTIBLE); |
| 3911 | /* sleep for 100 msecs, and try again. */ |
| 3912 | schedule_timeout(HZ / 10); |
| 3913 | } |
| 3914 | |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 3915 | /* Must be called with trace_types_lock mutex held. */ |
| 3916 | static int tracing_wait_pipe(struct file *filp) |
| 3917 | { |
| 3918 | struct trace_iterator *iter = filp->private_data; |
| 3919 | |
| 3920 | while (trace_empty(iter)) { |
| 3921 | |
| 3922 | if ((filp->f_flags & O_NONBLOCK)) { |
| 3923 | return -EAGAIN; |
| 3924 | } |
| 3925 | |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 3926 | mutex_unlock(&iter->mutex); |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 3927 | |
Frederic Weisbecker | 6eaaa5d | 2009-02-11 02:25:00 +0100 | [diff] [blame] | 3928 | iter->trace->wait_pipe(iter); |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 3929 | |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 3930 | mutex_lock(&iter->mutex); |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 3931 | |
Frederic Weisbecker | 6eaaa5d | 2009-02-11 02:25:00 +0100 | [diff] [blame] | 3932 | if (signal_pending(current)) |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 3933 | return -EINTR; |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 3934 | |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 3935 | /* |
Liu Bo | 250bfd3 | 2013-01-14 10:54:11 +0800 | [diff] [blame] | 3936 | * We block until we read something and tracing is disabled. |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 3937 | * We still block if tracing is disabled, but we have never |
| 3938 | * read anything. This allows a user to cat this file, and |
| 3939 | * then enable tracing. But after we have read something, |
| 3940 | * we give an EOF when tracing is again disabled. |
| 3941 | * |
| 3942 | * iter->pos will be 0 if we haven't read anything. |
| 3943 | */ |
Liu Bo | 250bfd3 | 2013-01-14 10:54:11 +0800 | [diff] [blame] | 3944 | if (!tracing_is_enabled() && iter->pos) |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 3945 | break; |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 3946 | } |
| 3947 | |
| 3948 | return 1; |
| 3949 | } |
| 3950 | |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3951 | /* |
| 3952 | * Consumer reader. |
| 3953 | */ |
| 3954 | static ssize_t |
| 3955 | tracing_read_pipe(struct file *filp, char __user *ubuf, |
| 3956 | size_t cnt, loff_t *ppos) |
| 3957 | { |
| 3958 | struct trace_iterator *iter = filp->private_data; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3959 | struct trace_array *tr = iter->tr; |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 3960 | ssize_t sret; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3961 | |
| 3962 | /* return any leftover data */ |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 3963 | sret = trace_seq_to_user(&iter->seq, ubuf, cnt); |
| 3964 | if (sret != -EBUSY) |
| 3965 | return sret; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3966 | |
Steven Rostedt | f952075 | 2009-03-02 14:04:40 -0500 | [diff] [blame] | 3967 | trace_seq_init(&iter->seq); |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3968 | |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 3969 | /* copy the tracer to avoid using a global lock all around */ |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 3970 | mutex_lock(&trace_types_lock); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3971 | if (unlikely(iter->trace->name != tr->current_trace->name)) |
| 3972 | *iter->trace = *tr->current_trace; |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 3973 | mutex_unlock(&trace_types_lock); |
| 3974 | |
| 3975 | /* |
| 3976 | * Avoid more than one consumer on a single file descriptor |
| 3977 | * This is just a matter of traces coherency, the ring buffer itself |
| 3978 | * is protected. |
| 3979 | */ |
| 3980 | mutex_lock(&iter->mutex); |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 3981 | if (iter->trace->read) { |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 3982 | sret = iter->trace->read(iter, filp, ubuf, cnt, ppos); |
| 3983 | if (sret) |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 3984 | goto out; |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 3985 | } |
| 3986 | |
Pekka Paalanen | 9ff4b97 | 2008-09-29 20:23:48 +0200 | [diff] [blame] | 3987 | waitagain: |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 3988 | sret = tracing_wait_pipe(filp); |
| 3989 | if (sret <= 0) |
| 3990 | goto out; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3991 | |
| 3992 | /* stop when tracing is finished */ |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 3993 | if (trace_empty(iter)) { |
| 3994 | sret = 0; |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 3995 | goto out; |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 3996 | } |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3997 | |
| 3998 | if (cnt >= PAGE_SIZE) |
| 3999 | cnt = PAGE_SIZE - 1; |
| 4000 | |
Steven Rostedt | 53d0aa7 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 4001 | /* reset all but tr, trace, and overruns */ |
Steven Rostedt | 53d0aa7 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 4002 | memset(&iter->seq, 0, |
| 4003 | sizeof(struct trace_iterator) - |
| 4004 | offsetof(struct trace_iterator, seq)); |
Steven Rostedt | 4823ed7 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 4005 | iter->pos = -1; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4006 | |
Lai Jiangshan | 4f53596 | 2009-05-18 19:35:34 +0800 | [diff] [blame] | 4007 | trace_event_read_lock(); |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 4008 | trace_access_lock(iter->cpu_file); |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 4009 | while (trace_find_next_entry_inc(iter) != NULL) { |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 4010 | enum print_line_t ret; |
Steven Rostedt | 088b1e42 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 4011 | int len = iter->seq.len; |
| 4012 | |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 4013 | ret = print_trace_line(iter); |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 4014 | if (ret == TRACE_TYPE_PARTIAL_LINE) { |
Steven Rostedt | 088b1e42 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 4015 | /* don't print partial lines */ |
| 4016 | iter->seq.len = len; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4017 | break; |
Steven Rostedt | 088b1e42 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 4018 | } |
Frederic Weisbecker | b91facc | 2009-02-06 18:30:44 +0100 | [diff] [blame] | 4019 | if (ret != TRACE_TYPE_NO_CONSUME) |
| 4020 | trace_consume(iter); |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4021 | |
| 4022 | if (iter->seq.len >= cnt) |
| 4023 | break; |
Jiri Olsa | ee5e51f | 2011-03-25 12:05:18 +0100 | [diff] [blame] | 4024 | |
| 4025 | /* |
| 4026 | * Setting the full flag means we reached the trace_seq buffer |
| 4027 | * size and we should leave by partial output condition above. |
| 4028 | * One of the trace_seq_* functions is not used properly. |
| 4029 | */ |
| 4030 | WARN_ONCE(iter->seq.full, "full flag set for trace type %d", |
| 4031 | iter->ent->type); |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4032 | } |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 4033 | trace_access_unlock(iter->cpu_file); |
Lai Jiangshan | 4f53596 | 2009-05-18 19:35:34 +0800 | [diff] [blame] | 4034 | trace_event_read_unlock(); |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4035 | |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4036 | /* Now copy what we have to the user */ |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 4037 | sret = trace_seq_to_user(&iter->seq, ubuf, cnt); |
| 4038 | if (iter->seq.readpos >= iter->seq.len) |
Steven Rostedt | f952075 | 2009-03-02 14:04:40 -0500 | [diff] [blame] | 4039 | trace_seq_init(&iter->seq); |
Pekka Paalanen | 9ff4b97 | 2008-09-29 20:23:48 +0200 | [diff] [blame] | 4040 | |
| 4041 | /* |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 4042 | * If there was nothing to send to user, in spite of consuming trace |
Pekka Paalanen | 9ff4b97 | 2008-09-29 20:23:48 +0200 | [diff] [blame] | 4043 | * entries, go back to wait for more entries. |
| 4044 | */ |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 4045 | if (sret == -EBUSY) |
Pekka Paalanen | 9ff4b97 | 2008-09-29 20:23:48 +0200 | [diff] [blame] | 4046 | goto waitagain; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4047 | |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 4048 | out: |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 4049 | mutex_unlock(&iter->mutex); |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 4050 | |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 4051 | return sret; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4052 | } |
| 4053 | |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4054 | static void tracing_pipe_buf_release(struct pipe_inode_info *pipe, |
| 4055 | struct pipe_buffer *buf) |
| 4056 | { |
| 4057 | __free_page(buf->page); |
| 4058 | } |
| 4059 | |
| 4060 | static void tracing_spd_release_pipe(struct splice_pipe_desc *spd, |
| 4061 | unsigned int idx) |
| 4062 | { |
| 4063 | __free_page(spd->pages[idx]); |
| 4064 | } |
| 4065 | |
Alexey Dobriyan | 28dfef8 | 2009-12-15 16:46:48 -0800 | [diff] [blame] | 4066 | static const struct pipe_buf_operations tracing_pipe_buf_ops = { |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 4067 | .can_merge = 0, |
| 4068 | .map = generic_pipe_buf_map, |
| 4069 | .unmap = generic_pipe_buf_unmap, |
| 4070 | .confirm = generic_pipe_buf_confirm, |
| 4071 | .release = tracing_pipe_buf_release, |
| 4072 | .steal = generic_pipe_buf_steal, |
| 4073 | .get = generic_pipe_buf_get, |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4074 | }; |
| 4075 | |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 4076 | static size_t |
Frederic Weisbecker | fa7c7f6 | 2009-02-11 02:51:30 +0100 | [diff] [blame] | 4077 | tracing_fill_pipe_page(size_t rem, struct trace_iterator *iter) |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 4078 | { |
| 4079 | size_t count; |
| 4080 | int ret; |
| 4081 | |
| 4082 | /* Seq buffer is page-sized, exactly what we need. */ |
| 4083 | for (;;) { |
| 4084 | count = iter->seq.len; |
| 4085 | ret = print_trace_line(iter); |
| 4086 | count = iter->seq.len - count; |
| 4087 | if (rem < count) { |
| 4088 | rem = 0; |
| 4089 | iter->seq.len -= count; |
| 4090 | break; |
| 4091 | } |
| 4092 | if (ret == TRACE_TYPE_PARTIAL_LINE) { |
| 4093 | iter->seq.len -= count; |
| 4094 | break; |
| 4095 | } |
| 4096 | |
Lai Jiangshan | 74e7ff8 | 2009-07-28 20:17:22 +0800 | [diff] [blame] | 4097 | if (ret != TRACE_TYPE_NO_CONSUME) |
| 4098 | trace_consume(iter); |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 4099 | rem -= count; |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 4100 | if (!trace_find_next_entry_inc(iter)) { |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 4101 | rem = 0; |
| 4102 | iter->ent = NULL; |
| 4103 | break; |
| 4104 | } |
| 4105 | } |
| 4106 | |
| 4107 | return rem; |
| 4108 | } |
| 4109 | |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4110 | static ssize_t tracing_splice_read_pipe(struct file *filp, |
| 4111 | loff_t *ppos, |
| 4112 | struct pipe_inode_info *pipe, |
| 4113 | size_t len, |
| 4114 | unsigned int flags) |
| 4115 | { |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 4116 | struct page *pages_def[PIPE_DEF_BUFFERS]; |
| 4117 | struct partial_page partial_def[PIPE_DEF_BUFFERS]; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4118 | struct trace_iterator *iter = filp->private_data; |
| 4119 | struct splice_pipe_desc spd = { |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 4120 | .pages = pages_def, |
| 4121 | .partial = partial_def, |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 4122 | .nr_pages = 0, /* This gets updated below. */ |
Eric Dumazet | 047fe36 | 2012-06-12 15:24:40 +0200 | [diff] [blame] | 4123 | .nr_pages_max = PIPE_DEF_BUFFERS, |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 4124 | .flags = flags, |
| 4125 | .ops = &tracing_pipe_buf_ops, |
| 4126 | .spd_release = tracing_spd_release_pipe, |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4127 | }; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4128 | struct trace_array *tr = iter->tr; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4129 | ssize_t ret; |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 4130 | size_t rem; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4131 | unsigned int i; |
| 4132 | |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 4133 | if (splice_grow_spd(pipe, &spd)) |
| 4134 | return -ENOMEM; |
| 4135 | |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 4136 | /* copy the tracer to avoid using a global lock all around */ |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4137 | mutex_lock(&trace_types_lock); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4138 | if (unlikely(iter->trace->name != tr->current_trace->name)) |
| 4139 | *iter->trace = *tr->current_trace; |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 4140 | mutex_unlock(&trace_types_lock); |
| 4141 | |
| 4142 | mutex_lock(&iter->mutex); |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4143 | |
| 4144 | if (iter->trace->splice_read) { |
| 4145 | ret = iter->trace->splice_read(iter, filp, |
| 4146 | ppos, pipe, len, flags); |
| 4147 | if (ret) |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 4148 | goto out_err; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4149 | } |
| 4150 | |
| 4151 | ret = tracing_wait_pipe(filp); |
| 4152 | if (ret <= 0) |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 4153 | goto out_err; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4154 | |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 4155 | if (!iter->ent && !trace_find_next_entry_inc(iter)) { |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4156 | ret = -EFAULT; |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 4157 | goto out_err; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4158 | } |
| 4159 | |
Lai Jiangshan | 4f53596 | 2009-05-18 19:35:34 +0800 | [diff] [blame] | 4160 | trace_event_read_lock(); |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 4161 | trace_access_lock(iter->cpu_file); |
Lai Jiangshan | 4f53596 | 2009-05-18 19:35:34 +0800 | [diff] [blame] | 4162 | |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4163 | /* Fill as many pages as possible. */ |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 4164 | for (i = 0, rem = len; i < pipe->buffers && rem; i++) { |
| 4165 | spd.pages[i] = alloc_page(GFP_KERNEL); |
| 4166 | if (!spd.pages[i]) |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 4167 | break; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4168 | |
Frederic Weisbecker | fa7c7f6 | 2009-02-11 02:51:30 +0100 | [diff] [blame] | 4169 | rem = tracing_fill_pipe_page(rem, iter); |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4170 | |
| 4171 | /* Copy the data into the page, so we can start over. */ |
| 4172 | ret = trace_seq_to_buffer(&iter->seq, |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 4173 | page_address(spd.pages[i]), |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4174 | iter->seq.len); |
| 4175 | if (ret < 0) { |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 4176 | __free_page(spd.pages[i]); |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4177 | break; |
| 4178 | } |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 4179 | spd.partial[i].offset = 0; |
| 4180 | spd.partial[i].len = iter->seq.len; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4181 | |
Steven Rostedt | f952075 | 2009-03-02 14:04:40 -0500 | [diff] [blame] | 4182 | trace_seq_init(&iter->seq); |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4183 | } |
| 4184 | |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 4185 | trace_access_unlock(iter->cpu_file); |
Lai Jiangshan | 4f53596 | 2009-05-18 19:35:34 +0800 | [diff] [blame] | 4186 | trace_event_read_unlock(); |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 4187 | mutex_unlock(&iter->mutex); |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4188 | |
| 4189 | spd.nr_pages = i; |
| 4190 | |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 4191 | ret = splice_to_pipe(pipe, &spd); |
| 4192 | out: |
Eric Dumazet | 047fe36 | 2012-06-12 15:24:40 +0200 | [diff] [blame] | 4193 | splice_shrink_spd(&spd); |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 4194 | return ret; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4195 | |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 4196 | out_err: |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 4197 | mutex_unlock(&iter->mutex); |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 4198 | goto out; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4199 | } |
| 4200 | |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 4201 | static ssize_t |
| 4202 | tracing_entries_read(struct file *filp, char __user *ubuf, |
| 4203 | size_t cnt, loff_t *ppos) |
| 4204 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4205 | struct trace_cpu *tc = filp->private_data; |
| 4206 | struct trace_array *tr = tc->tr; |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 4207 | char buf[64]; |
| 4208 | int r = 0; |
| 4209 | ssize_t ret; |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 4210 | |
Steven Rostedt | db526ca | 2009-03-12 13:53:25 -0400 | [diff] [blame] | 4211 | mutex_lock(&trace_types_lock); |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 4212 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4213 | if (tc->cpu == RING_BUFFER_ALL_CPUS) { |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 4214 | int cpu, buf_size_same; |
| 4215 | unsigned long size; |
| 4216 | |
| 4217 | size = 0; |
| 4218 | buf_size_same = 1; |
| 4219 | /* check if all cpu sizes are same */ |
| 4220 | for_each_tracing_cpu(cpu) { |
| 4221 | /* fill in the size from first enabled cpu */ |
| 4222 | if (size == 0) |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4223 | size = per_cpu_ptr(tr->trace_buffer.data, cpu)->entries; |
| 4224 | if (size != per_cpu_ptr(tr->trace_buffer.data, cpu)->entries) { |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 4225 | buf_size_same = 0; |
| 4226 | break; |
| 4227 | } |
| 4228 | } |
| 4229 | |
| 4230 | if (buf_size_same) { |
| 4231 | if (!ring_buffer_expanded) |
| 4232 | r = sprintf(buf, "%lu (expanded: %lu)\n", |
| 4233 | size >> 10, |
| 4234 | trace_buf_size >> 10); |
| 4235 | else |
| 4236 | r = sprintf(buf, "%lu\n", size >> 10); |
| 4237 | } else |
| 4238 | r = sprintf(buf, "X\n"); |
| 4239 | } else |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4240 | r = sprintf(buf, "%lu\n", per_cpu_ptr(tr->trace_buffer.data, tc->cpu)->entries >> 10); |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 4241 | |
Steven Rostedt | db526ca | 2009-03-12 13:53:25 -0400 | [diff] [blame] | 4242 | mutex_unlock(&trace_types_lock); |
| 4243 | |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 4244 | ret = simple_read_from_buffer(ubuf, cnt, ppos, buf, r); |
| 4245 | return ret; |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 4246 | } |
| 4247 | |
| 4248 | static ssize_t |
| 4249 | tracing_entries_write(struct file *filp, const char __user *ubuf, |
| 4250 | size_t cnt, loff_t *ppos) |
| 4251 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4252 | struct trace_cpu *tc = filp->private_data; |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 4253 | unsigned long val; |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 4254 | int ret; |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 4255 | |
Peter Huewe | 22fe9b5 | 2011-06-07 21:58:27 +0200 | [diff] [blame] | 4256 | ret = kstrtoul_from_user(ubuf, cnt, 10, &val); |
| 4257 | if (ret) |
Steven Rostedt | c6caeeb | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 4258 | return ret; |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 4259 | |
| 4260 | /* must have at least 1 entry */ |
| 4261 | if (!val) |
| 4262 | return -EINVAL; |
| 4263 | |
Steven Rostedt | 1696b2b | 2008-11-13 00:09:35 -0500 | [diff] [blame] | 4264 | /* value is in KB */ |
| 4265 | val <<= 10; |
| 4266 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4267 | ret = tracing_resize_ring_buffer(tc->tr, val, tc->cpu); |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 4268 | if (ret < 0) |
| 4269 | return ret; |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 4270 | |
Jiri Olsa | cf8517c | 2009-10-23 19:36:16 -0400 | [diff] [blame] | 4271 | *ppos += cnt; |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 4272 | |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 4273 | return cnt; |
| 4274 | } |
Steven Rostedt | bf5e651 | 2008-11-10 21:46:00 -0500 | [diff] [blame] | 4275 | |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 4276 | static ssize_t |
Vaibhav Nagarnaik | f81ab07 | 2011-08-16 14:46:15 -0700 | [diff] [blame] | 4277 | tracing_total_entries_read(struct file *filp, char __user *ubuf, |
| 4278 | size_t cnt, loff_t *ppos) |
| 4279 | { |
| 4280 | struct trace_array *tr = filp->private_data; |
| 4281 | char buf[64]; |
| 4282 | int r, cpu; |
| 4283 | unsigned long size = 0, expanded_size = 0; |
| 4284 | |
| 4285 | mutex_lock(&trace_types_lock); |
| 4286 | for_each_tracing_cpu(cpu) { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4287 | size += per_cpu_ptr(tr->trace_buffer.data, cpu)->entries >> 10; |
Vaibhav Nagarnaik | f81ab07 | 2011-08-16 14:46:15 -0700 | [diff] [blame] | 4288 | if (!ring_buffer_expanded) |
| 4289 | expanded_size += trace_buf_size >> 10; |
| 4290 | } |
| 4291 | if (ring_buffer_expanded) |
| 4292 | r = sprintf(buf, "%lu\n", size); |
| 4293 | else |
| 4294 | r = sprintf(buf, "%lu (expanded: %lu)\n", size, expanded_size); |
| 4295 | mutex_unlock(&trace_types_lock); |
| 4296 | |
| 4297 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, r); |
| 4298 | } |
| 4299 | |
| 4300 | static ssize_t |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 4301 | tracing_free_buffer_write(struct file *filp, const char __user *ubuf, |
| 4302 | size_t cnt, loff_t *ppos) |
| 4303 | { |
| 4304 | /* |
| 4305 | * There is no need to read what the user has written, this function |
| 4306 | * is just to make sure that there is no error when "echo" is used |
| 4307 | */ |
| 4308 | |
| 4309 | *ppos += cnt; |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 4310 | |
| 4311 | return cnt; |
| 4312 | } |
| 4313 | |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 4314 | static int |
| 4315 | tracing_free_buffer_release(struct inode *inode, struct file *filp) |
| 4316 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4317 | struct trace_array *tr = inode->i_private; |
| 4318 | |
Steven Rostedt | cf30cf6 | 2011-06-14 22:44:07 -0400 | [diff] [blame] | 4319 | /* disable tracing ? */ |
| 4320 | if (trace_flags & TRACE_ITER_STOP_ON_FREE) |
| 4321 | tracing_off(); |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 4322 | /* resize the ring buffer to 0 */ |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4323 | tracing_resize_ring_buffer(tr, 0, RING_BUFFER_ALL_CPUS); |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 4324 | |
| 4325 | return 0; |
| 4326 | } |
| 4327 | |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 4328 | static ssize_t |
| 4329 | tracing_mark_write(struct file *filp, const char __user *ubuf, |
| 4330 | size_t cnt, loff_t *fpos) |
| 4331 | { |
Steven Rostedt | d696b58 | 2011-09-22 11:50:27 -0400 | [diff] [blame] | 4332 | unsigned long addr = (unsigned long)ubuf; |
| 4333 | struct ring_buffer_event *event; |
| 4334 | struct ring_buffer *buffer; |
| 4335 | struct print_entry *entry; |
| 4336 | unsigned long irq_flags; |
| 4337 | struct page *pages[2]; |
Steven Rostedt | 6edb2a8 | 2012-05-11 23:28:49 -0400 | [diff] [blame] | 4338 | void *map_page[2]; |
Steven Rostedt | d696b58 | 2011-09-22 11:50:27 -0400 | [diff] [blame] | 4339 | int nr_pages = 1; |
| 4340 | ssize_t written; |
Steven Rostedt | d696b58 | 2011-09-22 11:50:27 -0400 | [diff] [blame] | 4341 | int offset; |
| 4342 | int size; |
| 4343 | int len; |
| 4344 | int ret; |
Steven Rostedt | 6edb2a8 | 2012-05-11 23:28:49 -0400 | [diff] [blame] | 4345 | int i; |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 4346 | |
Steven Rostedt | c76f069 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 4347 | if (tracing_disabled) |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 4348 | return -EINVAL; |
| 4349 | |
Mandeep Singh Baines | 5224c3a | 2012-09-07 18:12:19 -0700 | [diff] [blame] | 4350 | if (!(trace_flags & TRACE_ITER_MARKERS)) |
| 4351 | return -EINVAL; |
| 4352 | |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 4353 | if (cnt > TRACE_BUF_SIZE) |
| 4354 | cnt = TRACE_BUF_SIZE; |
| 4355 | |
Steven Rostedt | d696b58 | 2011-09-22 11:50:27 -0400 | [diff] [blame] | 4356 | /* |
| 4357 | * Userspace is injecting traces into the kernel trace buffer. |
| 4358 | * We want to be as non intrusive as possible. |
| 4359 | * To do so, we do not want to allocate any special buffers |
| 4360 | * or take any locks, but instead write the userspace data |
| 4361 | * straight into the ring buffer. |
| 4362 | * |
| 4363 | * First we need to pin the userspace buffer into memory, |
| 4364 | * which, most likely it is, because it just referenced it. |
| 4365 | * But there's no guarantee that it is. By using get_user_pages_fast() |
| 4366 | * and kmap_atomic/kunmap_atomic() we can get access to the |
| 4367 | * pages directly. We then write the data directly into the |
| 4368 | * ring buffer. |
| 4369 | */ |
| 4370 | BUILD_BUG_ON(TRACE_BUF_SIZE >= PAGE_SIZE); |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 4371 | |
Steven Rostedt | d696b58 | 2011-09-22 11:50:27 -0400 | [diff] [blame] | 4372 | /* check if we cross pages */ |
| 4373 | if ((addr & PAGE_MASK) != ((addr + cnt) & PAGE_MASK)) |
| 4374 | nr_pages = 2; |
| 4375 | |
| 4376 | offset = addr & (PAGE_SIZE - 1); |
| 4377 | addr &= PAGE_MASK; |
| 4378 | |
| 4379 | ret = get_user_pages_fast(addr, nr_pages, 0, pages); |
| 4380 | if (ret < nr_pages) { |
| 4381 | while (--ret >= 0) |
| 4382 | put_page(pages[ret]); |
| 4383 | written = -EFAULT; |
| 4384 | goto out; |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 4385 | } |
| 4386 | |
Steven Rostedt | 6edb2a8 | 2012-05-11 23:28:49 -0400 | [diff] [blame] | 4387 | for (i = 0; i < nr_pages; i++) |
| 4388 | map_page[i] = kmap_atomic(pages[i]); |
Steven Rostedt | d696b58 | 2011-09-22 11:50:27 -0400 | [diff] [blame] | 4389 | |
| 4390 | local_save_flags(irq_flags); |
| 4391 | size = sizeof(*entry) + cnt + 2; /* possible \n added */ |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4392 | buffer = global_trace.trace_buffer.buffer; |
Steven Rostedt | d696b58 | 2011-09-22 11:50:27 -0400 | [diff] [blame] | 4393 | event = trace_buffer_lock_reserve(buffer, TRACE_PRINT, size, |
| 4394 | irq_flags, preempt_count()); |
| 4395 | if (!event) { |
| 4396 | /* Ring buffer disabled, return as if not open for write */ |
| 4397 | written = -EBADF; |
| 4398 | goto out_unlock; |
| 4399 | } |
| 4400 | |
| 4401 | entry = ring_buffer_event_data(event); |
| 4402 | entry->ip = _THIS_IP_; |
| 4403 | |
| 4404 | if (nr_pages == 2) { |
| 4405 | len = PAGE_SIZE - offset; |
Steven Rostedt | 6edb2a8 | 2012-05-11 23:28:49 -0400 | [diff] [blame] | 4406 | memcpy(&entry->buf, map_page[0] + offset, len); |
| 4407 | memcpy(&entry->buf[len], map_page[1], cnt - len); |
Steven Rostedt | d696b58 | 2011-09-22 11:50:27 -0400 | [diff] [blame] | 4408 | } else |
Steven Rostedt | 6edb2a8 | 2012-05-11 23:28:49 -0400 | [diff] [blame] | 4409 | memcpy(&entry->buf, map_page[0] + offset, cnt); |
Steven Rostedt | d696b58 | 2011-09-22 11:50:27 -0400 | [diff] [blame] | 4410 | |
| 4411 | if (entry->buf[cnt - 1] != '\n') { |
| 4412 | entry->buf[cnt] = '\n'; |
| 4413 | entry->buf[cnt + 1] = '\0'; |
| 4414 | } else |
| 4415 | entry->buf[cnt] = '\0'; |
| 4416 | |
Steven Rostedt | 7ffbd48 | 2012-10-11 12:14:25 -0400 | [diff] [blame] | 4417 | __buffer_unlock_commit(buffer, event); |
Steven Rostedt | d696b58 | 2011-09-22 11:50:27 -0400 | [diff] [blame] | 4418 | |
| 4419 | written = cnt; |
| 4420 | |
Marcin Slusarz | 1aa54bc | 2010-07-28 01:18:01 +0200 | [diff] [blame] | 4421 | *fpos += written; |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 4422 | |
Steven Rostedt | d696b58 | 2011-09-22 11:50:27 -0400 | [diff] [blame] | 4423 | out_unlock: |
Steven Rostedt | 6edb2a8 | 2012-05-11 23:28:49 -0400 | [diff] [blame] | 4424 | for (i = 0; i < nr_pages; i++){ |
| 4425 | kunmap_atomic(map_page[i]); |
| 4426 | put_page(pages[i]); |
| 4427 | } |
Steven Rostedt | d696b58 | 2011-09-22 11:50:27 -0400 | [diff] [blame] | 4428 | out: |
Marcin Slusarz | 1aa54bc | 2010-07-28 01:18:01 +0200 | [diff] [blame] | 4429 | return written; |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 4430 | } |
| 4431 | |
Li Zefan | 13f16d2 | 2009-12-08 11:16:11 +0800 | [diff] [blame] | 4432 | static int tracing_clock_show(struct seq_file *m, void *v) |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 4433 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4434 | struct trace_array *tr = m->private; |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 4435 | int i; |
| 4436 | |
| 4437 | for (i = 0; i < ARRAY_SIZE(trace_clocks); i++) |
Li Zefan | 13f16d2 | 2009-12-08 11:16:11 +0800 | [diff] [blame] | 4438 | seq_printf(m, |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 4439 | "%s%s%s%s", i ? " " : "", |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4440 | i == tr->clock_id ? "[" : "", trace_clocks[i].name, |
| 4441 | i == tr->clock_id ? "]" : ""); |
Li Zefan | 13f16d2 | 2009-12-08 11:16:11 +0800 | [diff] [blame] | 4442 | seq_putc(m, '\n'); |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 4443 | |
Li Zefan | 13f16d2 | 2009-12-08 11:16:11 +0800 | [diff] [blame] | 4444 | return 0; |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 4445 | } |
| 4446 | |
| 4447 | static ssize_t tracing_clock_write(struct file *filp, const char __user *ubuf, |
| 4448 | size_t cnt, loff_t *fpos) |
| 4449 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4450 | struct seq_file *m = filp->private_data; |
| 4451 | struct trace_array *tr = m->private; |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 4452 | char buf[64]; |
| 4453 | const char *clockstr; |
| 4454 | int i; |
| 4455 | |
| 4456 | if (cnt >= sizeof(buf)) |
| 4457 | return -EINVAL; |
| 4458 | |
| 4459 | if (copy_from_user(&buf, ubuf, cnt)) |
| 4460 | return -EFAULT; |
| 4461 | |
| 4462 | buf[cnt] = 0; |
| 4463 | |
| 4464 | clockstr = strstrip(buf); |
| 4465 | |
| 4466 | for (i = 0; i < ARRAY_SIZE(trace_clocks); i++) { |
| 4467 | if (strcmp(trace_clocks[i].name, clockstr) == 0) |
| 4468 | break; |
| 4469 | } |
| 4470 | if (i == ARRAY_SIZE(trace_clocks)) |
| 4471 | return -EINVAL; |
| 4472 | |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 4473 | mutex_lock(&trace_types_lock); |
| 4474 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4475 | tr->clock_id = i; |
| 4476 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4477 | ring_buffer_set_clock(tr->trace_buffer.buffer, trace_clocks[i].func); |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 4478 | |
David Sharp | 60303ed | 2012-10-11 16:27:52 -0700 | [diff] [blame] | 4479 | /* |
| 4480 | * New clock may not be consistent with the previous clock. |
| 4481 | * Reset the buffer so that it doesn't have incomparable timestamps. |
| 4482 | */ |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4483 | tracing_reset_online_cpus(&global_trace.trace_buffer); |
| 4484 | |
| 4485 | #ifdef CONFIG_TRACER_MAX_TRACE |
| 4486 | if (tr->flags & TRACE_ARRAY_FL_GLOBAL && tr->max_buffer.buffer) |
| 4487 | ring_buffer_set_clock(tr->max_buffer.buffer, trace_clocks[i].func); |
| 4488 | tracing_reset_online_cpus(&global_trace.max_buffer); |
| 4489 | #endif |
David Sharp | 60303ed | 2012-10-11 16:27:52 -0700 | [diff] [blame] | 4490 | |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 4491 | mutex_unlock(&trace_types_lock); |
| 4492 | |
| 4493 | *fpos += cnt; |
| 4494 | |
| 4495 | return cnt; |
| 4496 | } |
| 4497 | |
Li Zefan | 13f16d2 | 2009-12-08 11:16:11 +0800 | [diff] [blame] | 4498 | static int tracing_clock_open(struct inode *inode, struct file *file) |
| 4499 | { |
| 4500 | if (tracing_disabled) |
| 4501 | return -ENODEV; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4502 | |
| 4503 | return single_open(file, tracing_clock_show, inode->i_private); |
Li Zefan | 13f16d2 | 2009-12-08 11:16:11 +0800 | [diff] [blame] | 4504 | } |
| 4505 | |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 4506 | struct ftrace_buffer_info { |
| 4507 | struct trace_iterator iter; |
| 4508 | void *spare; |
| 4509 | unsigned int read; |
| 4510 | }; |
| 4511 | |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4512 | #ifdef CONFIG_TRACER_SNAPSHOT |
| 4513 | static int tracing_snapshot_open(struct inode *inode, struct file *file) |
| 4514 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4515 | struct trace_cpu *tc = inode->i_private; |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4516 | struct trace_iterator *iter; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4517 | struct seq_file *m; |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4518 | int ret = 0; |
| 4519 | |
| 4520 | if (file->f_mode & FMODE_READ) { |
| 4521 | iter = __tracing_open(inode, file, true); |
| 4522 | if (IS_ERR(iter)) |
| 4523 | ret = PTR_ERR(iter); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4524 | } else { |
| 4525 | /* Writes still need the seq_file to hold the private data */ |
| 4526 | m = kzalloc(sizeof(*m), GFP_KERNEL); |
| 4527 | if (!m) |
| 4528 | return -ENOMEM; |
| 4529 | iter = kzalloc(sizeof(*iter), GFP_KERNEL); |
| 4530 | if (!iter) { |
| 4531 | kfree(m); |
| 4532 | return -ENOMEM; |
| 4533 | } |
| 4534 | iter->tr = tc->tr; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4535 | iter->trace_buffer = &tc->tr->max_buffer; |
Steven Rostedt (Red Hat) | f1affca | 2013-03-05 14:35:11 -0500 | [diff] [blame] | 4536 | iter->cpu_file = tc->cpu; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4537 | m->private = iter; |
| 4538 | file->private_data = m; |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4539 | } |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4540 | |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4541 | return ret; |
| 4542 | } |
| 4543 | |
| 4544 | static ssize_t |
| 4545 | tracing_snapshot_write(struct file *filp, const char __user *ubuf, size_t cnt, |
| 4546 | loff_t *ppos) |
| 4547 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4548 | struct seq_file *m = filp->private_data; |
| 4549 | struct trace_iterator *iter = m->private; |
| 4550 | struct trace_array *tr = iter->tr; |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4551 | unsigned long val; |
| 4552 | int ret; |
| 4553 | |
| 4554 | ret = tracing_update_buffers(); |
| 4555 | if (ret < 0) |
| 4556 | return ret; |
| 4557 | |
| 4558 | ret = kstrtoul_from_user(ubuf, cnt, 10, &val); |
| 4559 | if (ret) |
| 4560 | return ret; |
| 4561 | |
| 4562 | mutex_lock(&trace_types_lock); |
| 4563 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4564 | if (tr->current_trace->use_max_tr) { |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4565 | ret = -EBUSY; |
| 4566 | goto out; |
| 4567 | } |
| 4568 | |
| 4569 | switch (val) { |
| 4570 | case 0: |
Steven Rostedt (Red Hat) | f1affca | 2013-03-05 14:35:11 -0500 | [diff] [blame] | 4571 | if (iter->cpu_file != RING_BUFFER_ALL_CPUS) { |
| 4572 | ret = -EINVAL; |
| 4573 | break; |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4574 | } |
Steven Rostedt (Red Hat) | 3209cff | 2013-03-12 11:17:54 -0400 | [diff] [blame] | 4575 | if (tr->allocated_snapshot) |
| 4576 | free_snapshot(tr); |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4577 | break; |
| 4578 | case 1: |
Steven Rostedt (Red Hat) | f1affca | 2013-03-05 14:35:11 -0500 | [diff] [blame] | 4579 | /* Only allow per-cpu swap if the ring buffer supports it */ |
| 4580 | #ifndef CONFIG_RING_BUFFER_ALLOW_SWAP |
| 4581 | if (iter->cpu_file != RING_BUFFER_ALL_CPUS) { |
| 4582 | ret = -EINVAL; |
| 4583 | break; |
| 4584 | } |
| 4585 | #endif |
Steven Rostedt (Red Hat) | 45ad21c | 2013-03-05 18:25:02 -0500 | [diff] [blame] | 4586 | if (!tr->allocated_snapshot) { |
Steven Rostedt (Red Hat) | 3209cff | 2013-03-12 11:17:54 -0400 | [diff] [blame] | 4587 | ret = alloc_snapshot(tr); |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4588 | if (ret < 0) |
| 4589 | break; |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4590 | } |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4591 | local_irq_disable(); |
| 4592 | /* Now, we're going to swap */ |
Steven Rostedt (Red Hat) | f1affca | 2013-03-05 14:35:11 -0500 | [diff] [blame] | 4593 | if (iter->cpu_file == RING_BUFFER_ALL_CPUS) |
Steven Rostedt (Red Hat) | ce9bae5 | 2013-03-05 21:23:55 -0500 | [diff] [blame] | 4594 | update_max_tr(tr, current, smp_processor_id()); |
Steven Rostedt (Red Hat) | f1affca | 2013-03-05 14:35:11 -0500 | [diff] [blame] | 4595 | else |
Steven Rostedt (Red Hat) | ce9bae5 | 2013-03-05 21:23:55 -0500 | [diff] [blame] | 4596 | update_max_tr_single(tr, current, iter->cpu_file); |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4597 | local_irq_enable(); |
| 4598 | break; |
| 4599 | default: |
Steven Rostedt (Red Hat) | 45ad21c | 2013-03-05 18:25:02 -0500 | [diff] [blame] | 4600 | if (tr->allocated_snapshot) { |
Steven Rostedt (Red Hat) | f1affca | 2013-03-05 14:35:11 -0500 | [diff] [blame] | 4601 | if (iter->cpu_file == RING_BUFFER_ALL_CPUS) |
| 4602 | tracing_reset_online_cpus(&tr->max_buffer); |
| 4603 | else |
| 4604 | tracing_reset(&tr->max_buffer, iter->cpu_file); |
| 4605 | } |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4606 | break; |
| 4607 | } |
| 4608 | |
| 4609 | if (ret >= 0) { |
| 4610 | *ppos += cnt; |
| 4611 | ret = cnt; |
| 4612 | } |
| 4613 | out: |
| 4614 | mutex_unlock(&trace_types_lock); |
| 4615 | return ret; |
| 4616 | } |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4617 | |
| 4618 | static int tracing_snapshot_release(struct inode *inode, struct file *file) |
| 4619 | { |
| 4620 | struct seq_file *m = file->private_data; |
| 4621 | |
| 4622 | if (file->f_mode & FMODE_READ) |
| 4623 | return tracing_release(inode, file); |
| 4624 | |
| 4625 | /* If write only, the seq_file is just a stub */ |
| 4626 | if (m) |
| 4627 | kfree(m->private); |
| 4628 | kfree(m); |
| 4629 | |
| 4630 | return 0; |
| 4631 | } |
| 4632 | |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 4633 | static int tracing_buffers_open(struct inode *inode, struct file *filp); |
| 4634 | static ssize_t tracing_buffers_read(struct file *filp, char __user *ubuf, |
| 4635 | size_t count, loff_t *ppos); |
| 4636 | static int tracing_buffers_release(struct inode *inode, struct file *file); |
| 4637 | static ssize_t tracing_buffers_splice_read(struct file *file, loff_t *ppos, |
| 4638 | struct pipe_inode_info *pipe, size_t len, unsigned int flags); |
| 4639 | |
| 4640 | static int snapshot_raw_open(struct inode *inode, struct file *filp) |
| 4641 | { |
| 4642 | struct ftrace_buffer_info *info; |
| 4643 | int ret; |
| 4644 | |
| 4645 | ret = tracing_buffers_open(inode, filp); |
| 4646 | if (ret < 0) |
| 4647 | return ret; |
| 4648 | |
| 4649 | info = filp->private_data; |
| 4650 | |
| 4651 | if (info->iter.trace->use_max_tr) { |
| 4652 | tracing_buffers_release(inode, filp); |
| 4653 | return -EBUSY; |
| 4654 | } |
| 4655 | |
| 4656 | info->iter.snapshot = true; |
| 4657 | info->iter.trace_buffer = &info->iter.tr->max_buffer; |
| 4658 | |
| 4659 | return ret; |
| 4660 | } |
| 4661 | |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4662 | #endif /* CONFIG_TRACER_SNAPSHOT */ |
| 4663 | |
| 4664 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 4665 | static const struct file_operations tracing_max_lat_fops = { |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4666 | .open = tracing_open_generic, |
| 4667 | .read = tracing_max_lat_read, |
| 4668 | .write = tracing_max_lat_write, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 4669 | .llseek = generic_file_llseek, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4670 | }; |
| 4671 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 4672 | static const struct file_operations set_tracer_fops = { |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4673 | .open = tracing_open_generic, |
| 4674 | .read = tracing_set_trace_read, |
| 4675 | .write = tracing_set_trace_write, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 4676 | .llseek = generic_file_llseek, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4677 | }; |
| 4678 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 4679 | static const struct file_operations tracing_pipe_fops = { |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4680 | .open = tracing_open_pipe, |
Soeren Sandmann Pedersen | 2a2cc8f | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 4681 | .poll = tracing_poll_pipe, |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4682 | .read = tracing_read_pipe, |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4683 | .splice_read = tracing_splice_read_pipe, |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4684 | .release = tracing_release_pipe, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 4685 | .llseek = no_llseek, |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4686 | }; |
| 4687 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 4688 | static const struct file_operations tracing_entries_fops = { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4689 | .open = tracing_open_generic, |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 4690 | .read = tracing_entries_read, |
| 4691 | .write = tracing_entries_write, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 4692 | .llseek = generic_file_llseek, |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 4693 | }; |
| 4694 | |
Vaibhav Nagarnaik | f81ab07 | 2011-08-16 14:46:15 -0700 | [diff] [blame] | 4695 | static const struct file_operations tracing_total_entries_fops = { |
| 4696 | .open = tracing_open_generic, |
| 4697 | .read = tracing_total_entries_read, |
| 4698 | .llseek = generic_file_llseek, |
| 4699 | }; |
| 4700 | |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 4701 | static const struct file_operations tracing_free_buffer_fops = { |
| 4702 | .write = tracing_free_buffer_write, |
| 4703 | .release = tracing_free_buffer_release, |
| 4704 | }; |
| 4705 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 4706 | static const struct file_operations tracing_mark_fops = { |
Frédéric Weisbecker | 43a1538 | 2008-09-21 20:16:30 +0200 | [diff] [blame] | 4707 | .open = tracing_open_generic, |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 4708 | .write = tracing_mark_write, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 4709 | .llseek = generic_file_llseek, |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 4710 | }; |
| 4711 | |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 4712 | static const struct file_operations trace_clock_fops = { |
Li Zefan | 13f16d2 | 2009-12-08 11:16:11 +0800 | [diff] [blame] | 4713 | .open = tracing_clock_open, |
| 4714 | .read = seq_read, |
| 4715 | .llseek = seq_lseek, |
| 4716 | .release = single_release, |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 4717 | .write = tracing_clock_write, |
| 4718 | }; |
| 4719 | |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4720 | #ifdef CONFIG_TRACER_SNAPSHOT |
| 4721 | static const struct file_operations snapshot_fops = { |
| 4722 | .open = tracing_snapshot_open, |
| 4723 | .read = seq_read, |
| 4724 | .write = tracing_snapshot_write, |
| 4725 | .llseek = tracing_seek, |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4726 | .release = tracing_snapshot_release, |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4727 | }; |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4728 | |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 4729 | static const struct file_operations snapshot_raw_fops = { |
| 4730 | .open = snapshot_raw_open, |
| 4731 | .read = tracing_buffers_read, |
| 4732 | .release = tracing_buffers_release, |
| 4733 | .splice_read = tracing_buffers_splice_read, |
| 4734 | .llseek = no_llseek, |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4735 | }; |
| 4736 | |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 4737 | #endif /* CONFIG_TRACER_SNAPSHOT */ |
| 4738 | |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4739 | static int tracing_buffers_open(struct inode *inode, struct file *filp) |
| 4740 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4741 | struct trace_cpu *tc = inode->i_private; |
| 4742 | struct trace_array *tr = tc->tr; |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4743 | struct ftrace_buffer_info *info; |
| 4744 | |
| 4745 | if (tracing_disabled) |
| 4746 | return -ENODEV; |
| 4747 | |
| 4748 | info = kzalloc(sizeof(*info), GFP_KERNEL); |
| 4749 | if (!info) |
| 4750 | return -ENOMEM; |
| 4751 | |
Steven Rostedt (Red Hat) | a695cb5 | 2013-03-06 15:27:24 -0500 | [diff] [blame] | 4752 | mutex_lock(&trace_types_lock); |
| 4753 | |
| 4754 | tr->ref++; |
| 4755 | |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 4756 | info->iter.tr = tr; |
| 4757 | info->iter.cpu_file = tc->cpu; |
Steven Rostedt | b627344 | 2013-02-28 13:44:11 -0500 | [diff] [blame] | 4758 | info->iter.trace = tr->current_trace; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4759 | info->iter.trace_buffer = &tr->trace_buffer; |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 4760 | info->spare = NULL; |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4761 | /* Force reading ring buffer for first read */ |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 4762 | info->read = (unsigned int)-1; |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4763 | |
| 4764 | filp->private_data = info; |
| 4765 | |
Steven Rostedt (Red Hat) | a695cb5 | 2013-03-06 15:27:24 -0500 | [diff] [blame] | 4766 | mutex_unlock(&trace_types_lock); |
| 4767 | |
Lai Jiangshan | d1e7e02 | 2009-04-02 15:16:56 +0800 | [diff] [blame] | 4768 | return nonseekable_open(inode, filp); |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4769 | } |
| 4770 | |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 4771 | static unsigned int |
| 4772 | tracing_buffers_poll(struct file *filp, poll_table *poll_table) |
| 4773 | { |
| 4774 | struct ftrace_buffer_info *info = filp->private_data; |
| 4775 | struct trace_iterator *iter = &info->iter; |
| 4776 | |
| 4777 | return trace_poll(iter, filp, poll_table); |
| 4778 | } |
| 4779 | |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4780 | static ssize_t |
| 4781 | tracing_buffers_read(struct file *filp, char __user *ubuf, |
| 4782 | size_t count, loff_t *ppos) |
| 4783 | { |
| 4784 | struct ftrace_buffer_info *info = filp->private_data; |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 4785 | struct trace_iterator *iter = &info->iter; |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4786 | ssize_t ret; |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 4787 | ssize_t size; |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4788 | |
Steven Rostedt | 2dc5d12 | 2009-03-04 19:10:05 -0500 | [diff] [blame] | 4789 | if (!count) |
| 4790 | return 0; |
| 4791 | |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 4792 | mutex_lock(&trace_types_lock); |
| 4793 | |
| 4794 | #ifdef CONFIG_TRACER_MAX_TRACE |
| 4795 | if (iter->snapshot && iter->tr->current_trace->use_max_tr) { |
| 4796 | size = -EBUSY; |
| 4797 | goto out_unlock; |
| 4798 | } |
| 4799 | #endif |
| 4800 | |
Lai Jiangshan | ddd538f | 2009-04-02 15:16:59 +0800 | [diff] [blame] | 4801 | if (!info->spare) |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4802 | info->spare = ring_buffer_alloc_read_page(iter->trace_buffer->buffer, |
| 4803 | iter->cpu_file); |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 4804 | size = -ENOMEM; |
Lai Jiangshan | ddd538f | 2009-04-02 15:16:59 +0800 | [diff] [blame] | 4805 | if (!info->spare) |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 4806 | goto out_unlock; |
Lai Jiangshan | ddd538f | 2009-04-02 15:16:59 +0800 | [diff] [blame] | 4807 | |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4808 | /* Do we have previous read data to read? */ |
| 4809 | if (info->read < PAGE_SIZE) |
| 4810 | goto read; |
| 4811 | |
Steven Rostedt | b627344 | 2013-02-28 13:44:11 -0500 | [diff] [blame] | 4812 | again: |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 4813 | trace_access_lock(iter->cpu_file); |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4814 | ret = ring_buffer_read_page(iter->trace_buffer->buffer, |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4815 | &info->spare, |
| 4816 | count, |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 4817 | iter->cpu_file, 0); |
| 4818 | trace_access_unlock(iter->cpu_file); |
Steven Rostedt | b627344 | 2013-02-28 13:44:11 -0500 | [diff] [blame] | 4819 | |
| 4820 | if (ret < 0) { |
| 4821 | if (trace_empty(iter)) { |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 4822 | if ((filp->f_flags & O_NONBLOCK)) { |
| 4823 | size = -EAGAIN; |
| 4824 | goto out_unlock; |
| 4825 | } |
| 4826 | mutex_unlock(&trace_types_lock); |
Steven Rostedt | b627344 | 2013-02-28 13:44:11 -0500 | [diff] [blame] | 4827 | iter->trace->wait_pipe(iter); |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 4828 | mutex_lock(&trace_types_lock); |
| 4829 | if (signal_pending(current)) { |
| 4830 | size = -EINTR; |
| 4831 | goto out_unlock; |
| 4832 | } |
Steven Rostedt | b627344 | 2013-02-28 13:44:11 -0500 | [diff] [blame] | 4833 | goto again; |
| 4834 | } |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 4835 | size = 0; |
| 4836 | goto out_unlock; |
Steven Rostedt | b627344 | 2013-02-28 13:44:11 -0500 | [diff] [blame] | 4837 | } |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4838 | |
Steven Rostedt | 436fc28 | 2011-10-14 10:44:25 -0400 | [diff] [blame] | 4839 | info->read = 0; |
Steven Rostedt | b627344 | 2013-02-28 13:44:11 -0500 | [diff] [blame] | 4840 | read: |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4841 | size = PAGE_SIZE - info->read; |
| 4842 | if (size > count) |
| 4843 | size = count; |
| 4844 | |
| 4845 | ret = copy_to_user(ubuf, info->spare + info->read, size); |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 4846 | if (ret == size) { |
| 4847 | size = -EFAULT; |
| 4848 | goto out_unlock; |
| 4849 | } |
Steven Rostedt | 2dc5d12 | 2009-03-04 19:10:05 -0500 | [diff] [blame] | 4850 | size -= ret; |
| 4851 | |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4852 | *ppos += size; |
| 4853 | info->read += size; |
| 4854 | |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 4855 | out_unlock: |
| 4856 | mutex_unlock(&trace_types_lock); |
| 4857 | |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4858 | return size; |
| 4859 | } |
| 4860 | |
| 4861 | static int tracing_buffers_release(struct inode *inode, struct file *file) |
| 4862 | { |
| 4863 | struct ftrace_buffer_info *info = file->private_data; |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 4864 | struct trace_iterator *iter = &info->iter; |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4865 | |
Steven Rostedt (Red Hat) | a695cb5 | 2013-03-06 15:27:24 -0500 | [diff] [blame] | 4866 | mutex_lock(&trace_types_lock); |
| 4867 | |
| 4868 | WARN_ON(!iter->tr->ref); |
| 4869 | iter->tr->ref--; |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4870 | |
Lai Jiangshan | ddd538f | 2009-04-02 15:16:59 +0800 | [diff] [blame] | 4871 | if (info->spare) |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4872 | ring_buffer_free_read_page(iter->trace_buffer->buffer, info->spare); |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4873 | kfree(info); |
| 4874 | |
Steven Rostedt (Red Hat) | a695cb5 | 2013-03-06 15:27:24 -0500 | [diff] [blame] | 4875 | mutex_unlock(&trace_types_lock); |
| 4876 | |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4877 | return 0; |
| 4878 | } |
| 4879 | |
| 4880 | struct buffer_ref { |
| 4881 | struct ring_buffer *buffer; |
| 4882 | void *page; |
| 4883 | int ref; |
| 4884 | }; |
| 4885 | |
| 4886 | static void buffer_pipe_buf_release(struct pipe_inode_info *pipe, |
| 4887 | struct pipe_buffer *buf) |
| 4888 | { |
| 4889 | struct buffer_ref *ref = (struct buffer_ref *)buf->private; |
| 4890 | |
| 4891 | if (--ref->ref) |
| 4892 | return; |
| 4893 | |
| 4894 | ring_buffer_free_read_page(ref->buffer, ref->page); |
| 4895 | kfree(ref); |
| 4896 | buf->private = 0; |
| 4897 | } |
| 4898 | |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4899 | static void buffer_pipe_buf_get(struct pipe_inode_info *pipe, |
| 4900 | struct pipe_buffer *buf) |
| 4901 | { |
| 4902 | struct buffer_ref *ref = (struct buffer_ref *)buf->private; |
| 4903 | |
| 4904 | ref->ref++; |
| 4905 | } |
| 4906 | |
| 4907 | /* Pipe buffer operations for a buffer. */ |
Alexey Dobriyan | 28dfef8 | 2009-12-15 16:46:48 -0800 | [diff] [blame] | 4908 | static const struct pipe_buf_operations buffer_pipe_buf_ops = { |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4909 | .can_merge = 0, |
| 4910 | .map = generic_pipe_buf_map, |
| 4911 | .unmap = generic_pipe_buf_unmap, |
| 4912 | .confirm = generic_pipe_buf_confirm, |
| 4913 | .release = buffer_pipe_buf_release, |
Masami Hiramatsu | d55cb6c | 2012-08-09 21:31:10 +0900 | [diff] [blame] | 4914 | .steal = generic_pipe_buf_steal, |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4915 | .get = buffer_pipe_buf_get, |
| 4916 | }; |
| 4917 | |
| 4918 | /* |
| 4919 | * Callback from splice_to_pipe(), if we need to release some pages |
| 4920 | * at the end of the spd in case we error'ed out in filling the pipe. |
| 4921 | */ |
| 4922 | static void buffer_spd_release(struct splice_pipe_desc *spd, unsigned int i) |
| 4923 | { |
| 4924 | struct buffer_ref *ref = |
| 4925 | (struct buffer_ref *)spd->partial[i].private; |
| 4926 | |
| 4927 | if (--ref->ref) |
| 4928 | return; |
| 4929 | |
| 4930 | ring_buffer_free_read_page(ref->buffer, ref->page); |
| 4931 | kfree(ref); |
| 4932 | spd->partial[i].private = 0; |
| 4933 | } |
| 4934 | |
| 4935 | static ssize_t |
| 4936 | tracing_buffers_splice_read(struct file *file, loff_t *ppos, |
| 4937 | struct pipe_inode_info *pipe, size_t len, |
| 4938 | unsigned int flags) |
| 4939 | { |
| 4940 | struct ftrace_buffer_info *info = file->private_data; |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 4941 | struct trace_iterator *iter = &info->iter; |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 4942 | struct partial_page partial_def[PIPE_DEF_BUFFERS]; |
| 4943 | struct page *pages_def[PIPE_DEF_BUFFERS]; |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4944 | struct splice_pipe_desc spd = { |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 4945 | .pages = pages_def, |
| 4946 | .partial = partial_def, |
Eric Dumazet | 047fe36 | 2012-06-12 15:24:40 +0200 | [diff] [blame] | 4947 | .nr_pages_max = PIPE_DEF_BUFFERS, |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4948 | .flags = flags, |
| 4949 | .ops = &buffer_pipe_buf_ops, |
| 4950 | .spd_release = buffer_spd_release, |
| 4951 | }; |
| 4952 | struct buffer_ref *ref; |
Steven Rostedt | 93459c6 | 2009-04-29 00:23:13 -0400 | [diff] [blame] | 4953 | int entries, size, i; |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 4954 | ssize_t ret; |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4955 | |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 4956 | mutex_lock(&trace_types_lock); |
| 4957 | |
| 4958 | #ifdef CONFIG_TRACER_MAX_TRACE |
| 4959 | if (iter->snapshot && iter->tr->current_trace->use_max_tr) { |
| 4960 | ret = -EBUSY; |
| 4961 | goto out; |
| 4962 | } |
| 4963 | #endif |
| 4964 | |
| 4965 | if (splice_grow_spd(pipe, &spd)) { |
| 4966 | ret = -ENOMEM; |
| 4967 | goto out; |
| 4968 | } |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 4969 | |
Lai Jiangshan | 93cfb3c | 2009-04-02 15:17:08 +0800 | [diff] [blame] | 4970 | if (*ppos & (PAGE_SIZE - 1)) { |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 4971 | ret = -EINVAL; |
| 4972 | goto out; |
Lai Jiangshan | 93cfb3c | 2009-04-02 15:17:08 +0800 | [diff] [blame] | 4973 | } |
| 4974 | |
| 4975 | if (len & (PAGE_SIZE - 1)) { |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 4976 | if (len < PAGE_SIZE) { |
| 4977 | ret = -EINVAL; |
| 4978 | goto out; |
| 4979 | } |
Lai Jiangshan | 93cfb3c | 2009-04-02 15:17:08 +0800 | [diff] [blame] | 4980 | len &= PAGE_MASK; |
| 4981 | } |
| 4982 | |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 4983 | again: |
| 4984 | trace_access_lock(iter->cpu_file); |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4985 | entries = ring_buffer_entries_cpu(iter->trace_buffer->buffer, iter->cpu_file); |
Steven Rostedt | 93459c6 | 2009-04-29 00:23:13 -0400 | [diff] [blame] | 4986 | |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 4987 | for (i = 0; i < pipe->buffers && len && entries; i++, len -= PAGE_SIZE) { |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4988 | struct page *page; |
| 4989 | int r; |
| 4990 | |
| 4991 | ref = kzalloc(sizeof(*ref), GFP_KERNEL); |
| 4992 | if (!ref) |
| 4993 | break; |
| 4994 | |
Steven Rostedt | 7267fa6 | 2009-04-29 00:16:21 -0400 | [diff] [blame] | 4995 | ref->ref = 1; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4996 | ref->buffer = iter->trace_buffer->buffer; |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 4997 | ref->page = ring_buffer_alloc_read_page(ref->buffer, iter->cpu_file); |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4998 | if (!ref->page) { |
| 4999 | kfree(ref); |
| 5000 | break; |
| 5001 | } |
| 5002 | |
| 5003 | r = ring_buffer_read_page(ref->buffer, &ref->page, |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 5004 | len, iter->cpu_file, 1); |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5005 | if (r < 0) { |
Vaibhav Nagarnaik | 7ea5906 | 2011-05-03 17:56:42 -0700 | [diff] [blame] | 5006 | ring_buffer_free_read_page(ref->buffer, ref->page); |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5007 | kfree(ref); |
| 5008 | break; |
| 5009 | } |
| 5010 | |
| 5011 | /* |
| 5012 | * zero out any left over data, this is going to |
| 5013 | * user land. |
| 5014 | */ |
| 5015 | size = ring_buffer_page_len(ref->page); |
| 5016 | if (size < PAGE_SIZE) |
| 5017 | memset(ref->page + size, 0, PAGE_SIZE - size); |
| 5018 | |
| 5019 | page = virt_to_page(ref->page); |
| 5020 | |
| 5021 | spd.pages[i] = page; |
| 5022 | spd.partial[i].len = PAGE_SIZE; |
| 5023 | spd.partial[i].offset = 0; |
| 5024 | spd.partial[i].private = (unsigned long)ref; |
| 5025 | spd.nr_pages++; |
Lai Jiangshan | 93cfb3c | 2009-04-02 15:17:08 +0800 | [diff] [blame] | 5026 | *ppos += PAGE_SIZE; |
Steven Rostedt | 93459c6 | 2009-04-29 00:23:13 -0400 | [diff] [blame] | 5027 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5028 | entries = ring_buffer_entries_cpu(iter->trace_buffer->buffer, iter->cpu_file); |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5029 | } |
| 5030 | |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 5031 | trace_access_unlock(iter->cpu_file); |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5032 | spd.nr_pages = i; |
| 5033 | |
| 5034 | /* did we read anything? */ |
| 5035 | if (!spd.nr_pages) { |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 5036 | if ((file->f_flags & O_NONBLOCK) || (flags & SPLICE_F_NONBLOCK)) { |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5037 | ret = -EAGAIN; |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 5038 | goto out; |
| 5039 | } |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 5040 | mutex_unlock(&trace_types_lock); |
Steven Rostedt | b627344 | 2013-02-28 13:44:11 -0500 | [diff] [blame] | 5041 | iter->trace->wait_pipe(iter); |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 5042 | mutex_lock(&trace_types_lock); |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 5043 | if (signal_pending(current)) { |
| 5044 | ret = -EINTR; |
| 5045 | goto out; |
| 5046 | } |
| 5047 | goto again; |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5048 | } |
| 5049 | |
| 5050 | ret = splice_to_pipe(pipe, &spd); |
Eric Dumazet | 047fe36 | 2012-06-12 15:24:40 +0200 | [diff] [blame] | 5051 | splice_shrink_spd(&spd); |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 5052 | out: |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 5053 | mutex_unlock(&trace_types_lock); |
| 5054 | |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5055 | return ret; |
| 5056 | } |
| 5057 | |
| 5058 | static const struct file_operations tracing_buffers_fops = { |
| 5059 | .open = tracing_buffers_open, |
| 5060 | .read = tracing_buffers_read, |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 5061 | .poll = tracing_buffers_poll, |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5062 | .release = tracing_buffers_release, |
| 5063 | .splice_read = tracing_buffers_splice_read, |
| 5064 | .llseek = no_llseek, |
| 5065 | }; |
| 5066 | |
Steven Rostedt | c8d7718 | 2009-04-29 18:03:45 -0400 | [diff] [blame] | 5067 | static ssize_t |
| 5068 | tracing_stats_read(struct file *filp, char __user *ubuf, |
| 5069 | size_t count, loff_t *ppos) |
| 5070 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5071 | struct trace_cpu *tc = filp->private_data; |
| 5072 | struct trace_array *tr = tc->tr; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5073 | struct trace_buffer *trace_buf = &tr->trace_buffer; |
Steven Rostedt | c8d7718 | 2009-04-29 18:03:45 -0400 | [diff] [blame] | 5074 | struct trace_seq *s; |
| 5075 | unsigned long cnt; |
Vaibhav Nagarnaik | c64e148 | 2011-08-16 14:46:16 -0700 | [diff] [blame] | 5076 | unsigned long long t; |
| 5077 | unsigned long usec_rem; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5078 | int cpu = tc->cpu; |
Steven Rostedt | c8d7718 | 2009-04-29 18:03:45 -0400 | [diff] [blame] | 5079 | |
Li Zefan | e4f2d10 | 2009-06-15 10:57:28 +0800 | [diff] [blame] | 5080 | s = kmalloc(sizeof(*s), GFP_KERNEL); |
Steven Rostedt | c8d7718 | 2009-04-29 18:03:45 -0400 | [diff] [blame] | 5081 | if (!s) |
Roel Kluin | a646365 | 2009-11-11 22:26:35 +0100 | [diff] [blame] | 5082 | return -ENOMEM; |
Steven Rostedt | c8d7718 | 2009-04-29 18:03:45 -0400 | [diff] [blame] | 5083 | |
| 5084 | trace_seq_init(s); |
| 5085 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5086 | cnt = ring_buffer_entries_cpu(trace_buf->buffer, cpu); |
Steven Rostedt | c8d7718 | 2009-04-29 18:03:45 -0400 | [diff] [blame] | 5087 | trace_seq_printf(s, "entries: %ld\n", cnt); |
| 5088 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5089 | cnt = ring_buffer_overrun_cpu(trace_buf->buffer, cpu); |
Steven Rostedt | c8d7718 | 2009-04-29 18:03:45 -0400 | [diff] [blame] | 5090 | trace_seq_printf(s, "overrun: %ld\n", cnt); |
| 5091 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5092 | cnt = ring_buffer_commit_overrun_cpu(trace_buf->buffer, cpu); |
Steven Rostedt | c8d7718 | 2009-04-29 18:03:45 -0400 | [diff] [blame] | 5093 | trace_seq_printf(s, "commit overrun: %ld\n", cnt); |
| 5094 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5095 | cnt = ring_buffer_bytes_cpu(trace_buf->buffer, cpu); |
Vaibhav Nagarnaik | c64e148 | 2011-08-16 14:46:16 -0700 | [diff] [blame] | 5096 | trace_seq_printf(s, "bytes: %ld\n", cnt); |
| 5097 | |
Yoshihiro YUNOMAE | 11043d8b | 2012-11-13 12:18:23 -0800 | [diff] [blame] | 5098 | if (trace_clocks[trace_clock_id].in_ns) { |
| 5099 | /* local or global for trace_clock */ |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5100 | t = ns2usecs(ring_buffer_oldest_event_ts(trace_buf->buffer, cpu)); |
Yoshihiro YUNOMAE | 11043d8b | 2012-11-13 12:18:23 -0800 | [diff] [blame] | 5101 | usec_rem = do_div(t, USEC_PER_SEC); |
| 5102 | trace_seq_printf(s, "oldest event ts: %5llu.%06lu\n", |
| 5103 | t, usec_rem); |
Vaibhav Nagarnaik | c64e148 | 2011-08-16 14:46:16 -0700 | [diff] [blame] | 5104 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5105 | t = ns2usecs(ring_buffer_time_stamp(trace_buf->buffer, cpu)); |
Yoshihiro YUNOMAE | 11043d8b | 2012-11-13 12:18:23 -0800 | [diff] [blame] | 5106 | usec_rem = do_div(t, USEC_PER_SEC); |
| 5107 | trace_seq_printf(s, "now ts: %5llu.%06lu\n", t, usec_rem); |
| 5108 | } else { |
| 5109 | /* counter or tsc mode for trace_clock */ |
| 5110 | trace_seq_printf(s, "oldest event ts: %llu\n", |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5111 | ring_buffer_oldest_event_ts(trace_buf->buffer, cpu)); |
Yoshihiro YUNOMAE | 11043d8b | 2012-11-13 12:18:23 -0800 | [diff] [blame] | 5112 | |
| 5113 | trace_seq_printf(s, "now ts: %llu\n", |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5114 | ring_buffer_time_stamp(trace_buf->buffer, cpu)); |
Yoshihiro YUNOMAE | 11043d8b | 2012-11-13 12:18:23 -0800 | [diff] [blame] | 5115 | } |
Vaibhav Nagarnaik | c64e148 | 2011-08-16 14:46:16 -0700 | [diff] [blame] | 5116 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5117 | cnt = ring_buffer_dropped_events_cpu(trace_buf->buffer, cpu); |
Slava Pestov | 884bfe8 | 2011-07-15 14:23:58 -0700 | [diff] [blame] | 5118 | trace_seq_printf(s, "dropped events: %ld\n", cnt); |
| 5119 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5120 | cnt = ring_buffer_read_events_cpu(trace_buf->buffer, cpu); |
Steven Rostedt (Red Hat) | ad96470 | 2013-01-29 17:45:49 -0500 | [diff] [blame] | 5121 | trace_seq_printf(s, "read events: %ld\n", cnt); |
| 5122 | |
Steven Rostedt | c8d7718 | 2009-04-29 18:03:45 -0400 | [diff] [blame] | 5123 | count = simple_read_from_buffer(ubuf, count, ppos, s->buffer, s->len); |
| 5124 | |
| 5125 | kfree(s); |
| 5126 | |
| 5127 | return count; |
| 5128 | } |
| 5129 | |
| 5130 | static const struct file_operations tracing_stats_fops = { |
| 5131 | .open = tracing_open_generic, |
| 5132 | .read = tracing_stats_read, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 5133 | .llseek = generic_file_llseek, |
Steven Rostedt | c8d7718 | 2009-04-29 18:03:45 -0400 | [diff] [blame] | 5134 | }; |
| 5135 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5136 | #ifdef CONFIG_DYNAMIC_FTRACE |
| 5137 | |
Steven Rostedt | b807c3d | 2008-10-30 16:08:33 -0400 | [diff] [blame] | 5138 | int __weak ftrace_arch_read_dyn_info(char *buf, int size) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5139 | { |
Steven Rostedt | b807c3d | 2008-10-30 16:08:33 -0400 | [diff] [blame] | 5140 | return 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5141 | } |
| 5142 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5143 | static ssize_t |
Steven Rostedt | b807c3d | 2008-10-30 16:08:33 -0400 | [diff] [blame] | 5144 | tracing_read_dyn_info(struct file *filp, char __user *ubuf, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5145 | size_t cnt, loff_t *ppos) |
| 5146 | { |
Steven Rostedt | a26a2a2 | 2008-10-31 00:03:22 -0400 | [diff] [blame] | 5147 | static char ftrace_dyn_info_buffer[1024]; |
| 5148 | static DEFINE_MUTEX(dyn_info_mutex); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5149 | unsigned long *p = filp->private_data; |
Steven Rostedt | b807c3d | 2008-10-30 16:08:33 -0400 | [diff] [blame] | 5150 | char *buf = ftrace_dyn_info_buffer; |
Steven Rostedt | a26a2a2 | 2008-10-31 00:03:22 -0400 | [diff] [blame] | 5151 | int size = ARRAY_SIZE(ftrace_dyn_info_buffer); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5152 | int r; |
| 5153 | |
Steven Rostedt | b807c3d | 2008-10-30 16:08:33 -0400 | [diff] [blame] | 5154 | mutex_lock(&dyn_info_mutex); |
| 5155 | r = sprintf(buf, "%ld ", *p); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5156 | |
Steven Rostedt | a26a2a2 | 2008-10-31 00:03:22 -0400 | [diff] [blame] | 5157 | r += ftrace_arch_read_dyn_info(buf+r, (size-1)-r); |
Steven Rostedt | b807c3d | 2008-10-30 16:08:33 -0400 | [diff] [blame] | 5158 | buf[r++] = '\n'; |
| 5159 | |
| 5160 | r = simple_read_from_buffer(ubuf, cnt, ppos, buf, r); |
| 5161 | |
| 5162 | mutex_unlock(&dyn_info_mutex); |
| 5163 | |
| 5164 | return r; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5165 | } |
| 5166 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 5167 | static const struct file_operations tracing_dyn_info_fops = { |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 5168 | .open = tracing_open_generic, |
Steven Rostedt | b807c3d | 2008-10-30 16:08:33 -0400 | [diff] [blame] | 5169 | .read = tracing_read_dyn_info, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 5170 | .llseek = generic_file_llseek, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5171 | }; |
Steven Rostedt (Red Hat) | 77fd5c1 | 2013-03-12 11:49:18 -0400 | [diff] [blame] | 5172 | #endif /* CONFIG_DYNAMIC_FTRACE */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5173 | |
Steven Rostedt (Red Hat) | 77fd5c1 | 2013-03-12 11:49:18 -0400 | [diff] [blame] | 5174 | #if defined(CONFIG_TRACER_SNAPSHOT) && defined(CONFIG_DYNAMIC_FTRACE) |
| 5175 | static void |
| 5176 | ftrace_snapshot(unsigned long ip, unsigned long parent_ip, void **data) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5177 | { |
Steven Rostedt (Red Hat) | 77fd5c1 | 2013-03-12 11:49:18 -0400 | [diff] [blame] | 5178 | tracing_snapshot(); |
| 5179 | } |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5180 | |
Steven Rostedt (Red Hat) | 77fd5c1 | 2013-03-12 11:49:18 -0400 | [diff] [blame] | 5181 | static void |
| 5182 | ftrace_count_snapshot(unsigned long ip, unsigned long parent_ip, void **data) |
| 5183 | { |
| 5184 | unsigned long *count = (long *)data; |
| 5185 | |
| 5186 | if (!*count) |
| 5187 | return; |
| 5188 | |
| 5189 | if (*count != -1) |
| 5190 | (*count)--; |
| 5191 | |
| 5192 | tracing_snapshot(); |
| 5193 | } |
| 5194 | |
| 5195 | static int |
| 5196 | ftrace_snapshot_print(struct seq_file *m, unsigned long ip, |
| 5197 | struct ftrace_probe_ops *ops, void *data) |
| 5198 | { |
| 5199 | long count = (long)data; |
| 5200 | |
| 5201 | seq_printf(m, "%ps:", (void *)ip); |
| 5202 | |
| 5203 | seq_printf(m, "snapshot"); |
| 5204 | |
| 5205 | if (count == -1) |
| 5206 | seq_printf(m, ":unlimited\n"); |
| 5207 | else |
| 5208 | seq_printf(m, ":count=%ld\n", count); |
| 5209 | |
| 5210 | return 0; |
| 5211 | } |
| 5212 | |
| 5213 | static struct ftrace_probe_ops snapshot_probe_ops = { |
| 5214 | .func = ftrace_snapshot, |
| 5215 | .print = ftrace_snapshot_print, |
| 5216 | }; |
| 5217 | |
| 5218 | static struct ftrace_probe_ops snapshot_count_probe_ops = { |
| 5219 | .func = ftrace_count_snapshot, |
| 5220 | .print = ftrace_snapshot_print, |
| 5221 | }; |
| 5222 | |
| 5223 | static int |
| 5224 | ftrace_trace_snapshot_callback(struct ftrace_hash *hash, |
| 5225 | char *glob, char *cmd, char *param, int enable) |
| 5226 | { |
| 5227 | struct ftrace_probe_ops *ops; |
| 5228 | void *count = (void *)-1; |
| 5229 | char *number; |
| 5230 | int ret; |
| 5231 | |
| 5232 | /* hash funcs only work with set_ftrace_filter */ |
| 5233 | if (!enable) |
| 5234 | return -EINVAL; |
| 5235 | |
| 5236 | ops = param ? &snapshot_count_probe_ops : &snapshot_probe_ops; |
| 5237 | |
| 5238 | if (glob[0] == '!') { |
| 5239 | unregister_ftrace_function_probe_func(glob+1, ops); |
| 5240 | return 0; |
| 5241 | } |
| 5242 | |
| 5243 | if (!param) |
| 5244 | goto out_reg; |
| 5245 | |
| 5246 | number = strsep(¶m, ":"); |
| 5247 | |
| 5248 | if (!strlen(number)) |
| 5249 | goto out_reg; |
| 5250 | |
| 5251 | /* |
| 5252 | * We use the callback data field (which is a pointer) |
| 5253 | * as our counter. |
| 5254 | */ |
| 5255 | ret = kstrtoul(number, 0, (unsigned long *)&count); |
| 5256 | if (ret) |
| 5257 | return ret; |
| 5258 | |
| 5259 | out_reg: |
| 5260 | ret = register_ftrace_function_probe(glob, ops, count); |
| 5261 | |
| 5262 | if (ret >= 0) |
| 5263 | alloc_snapshot(&global_trace); |
| 5264 | |
| 5265 | return ret < 0 ? ret : 0; |
| 5266 | } |
| 5267 | |
| 5268 | static struct ftrace_func_command ftrace_snapshot_cmd = { |
| 5269 | .name = "snapshot", |
| 5270 | .func = ftrace_trace_snapshot_callback, |
| 5271 | }; |
| 5272 | |
| 5273 | static int register_snapshot_cmd(void) |
| 5274 | { |
| 5275 | return register_ftrace_command(&ftrace_snapshot_cmd); |
| 5276 | } |
| 5277 | #else |
| 5278 | static inline int register_snapshot_cmd(void) { return 0; } |
| 5279 | #endif /* defined(CONFIG_TRACER_SNAPSHOT) && defined(CONFIG_DYNAMIC_FTRACE) */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5280 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5281 | struct dentry *tracing_init_dentry_tr(struct trace_array *tr) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5282 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5283 | if (tr->dir) |
| 5284 | return tr->dir; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5285 | |
Frederic Weisbecker | 3e1f60b | 2009-03-22 23:10:45 +0100 | [diff] [blame] | 5286 | if (!debugfs_initialized()) |
| 5287 | return NULL; |
| 5288 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5289 | if (tr->flags & TRACE_ARRAY_FL_GLOBAL) |
| 5290 | tr->dir = debugfs_create_dir("tracing", NULL); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5291 | |
zhangwei(Jovi) | 687c878 | 2013-03-11 15:13:29 +0800 | [diff] [blame] | 5292 | if (!tr->dir) |
| 5293 | pr_warn_once("Could not create debugfs directory 'tracing'\n"); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5294 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5295 | return tr->dir; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5296 | } |
| 5297 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5298 | struct dentry *tracing_init_dentry(void) |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 5299 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5300 | return tracing_init_dentry_tr(&global_trace); |
| 5301 | } |
| 5302 | |
| 5303 | static struct dentry *tracing_dentry_percpu(struct trace_array *tr, int cpu) |
| 5304 | { |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 5305 | struct dentry *d_tracer; |
| 5306 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5307 | if (tr->percpu_dir) |
| 5308 | return tr->percpu_dir; |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 5309 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5310 | d_tracer = tracing_init_dentry_tr(tr); |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 5311 | if (!d_tracer) |
| 5312 | return NULL; |
| 5313 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5314 | tr->percpu_dir = debugfs_create_dir("per_cpu", d_tracer); |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 5315 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5316 | WARN_ONCE(!tr->percpu_dir, |
| 5317 | "Could not create debugfs directory 'per_cpu/%d'\n", cpu); |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 5318 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5319 | return tr->percpu_dir; |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 5320 | } |
| 5321 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5322 | static void |
| 5323 | tracing_init_debugfs_percpu(struct trace_array *tr, long cpu) |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 5324 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5325 | struct trace_array_cpu *data = per_cpu_ptr(tr->trace_buffer.data, cpu); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5326 | struct dentry *d_percpu = tracing_dentry_percpu(tr, cpu); |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 5327 | struct dentry *d_cpu; |
Steven Rostedt | dd49a38 | 2010-10-20 21:51:26 -0400 | [diff] [blame] | 5328 | char cpu_dir[30]; /* 30 characters should be more than enough */ |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 5329 | |
Namhyung Kim | 0a3d7ce | 2012-04-23 10:11:57 +0900 | [diff] [blame] | 5330 | if (!d_percpu) |
| 5331 | return; |
| 5332 | |
Steven Rostedt | dd49a38 | 2010-10-20 21:51:26 -0400 | [diff] [blame] | 5333 | snprintf(cpu_dir, 30, "cpu%ld", cpu); |
Frederic Weisbecker | 8656e7a | 2009-02-26 00:41:38 +0100 | [diff] [blame] | 5334 | d_cpu = debugfs_create_dir(cpu_dir, d_percpu); |
| 5335 | if (!d_cpu) { |
| 5336 | pr_warning("Could not create debugfs '%s' entry\n", cpu_dir); |
| 5337 | return; |
| 5338 | } |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 5339 | |
Frederic Weisbecker | 8656e7a | 2009-02-26 00:41:38 +0100 | [diff] [blame] | 5340 | /* per cpu trace_pipe */ |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 5341 | trace_create_file("trace_pipe", 0444, d_cpu, |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5342 | (void *)&data->trace_cpu, &tracing_pipe_fops); |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 5343 | |
| 5344 | /* per cpu trace */ |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 5345 | trace_create_file("trace", 0644, d_cpu, |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5346 | (void *)&data->trace_cpu, &tracing_fops); |
Steven Rostedt | 7f96f93 | 2009-03-13 00:37:42 -0400 | [diff] [blame] | 5347 | |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 5348 | trace_create_file("trace_pipe_raw", 0444, d_cpu, |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5349 | (void *)&data->trace_cpu, &tracing_buffers_fops); |
Steven Rostedt | c8d7718 | 2009-04-29 18:03:45 -0400 | [diff] [blame] | 5350 | |
| 5351 | trace_create_file("stats", 0444, d_cpu, |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5352 | (void *)&data->trace_cpu, &tracing_stats_fops); |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 5353 | |
| 5354 | trace_create_file("buffer_size_kb", 0444, d_cpu, |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5355 | (void *)&data->trace_cpu, &tracing_entries_fops); |
Steven Rostedt (Red Hat) | f1affca | 2013-03-05 14:35:11 -0500 | [diff] [blame] | 5356 | |
| 5357 | #ifdef CONFIG_TRACER_SNAPSHOT |
| 5358 | trace_create_file("snapshot", 0644, d_cpu, |
| 5359 | (void *)&data->trace_cpu, &snapshot_fops); |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 5360 | |
| 5361 | trace_create_file("snapshot_raw", 0444, d_cpu, |
| 5362 | (void *)&data->trace_cpu, &snapshot_raw_fops); |
Steven Rostedt (Red Hat) | f1affca | 2013-03-05 14:35:11 -0500 | [diff] [blame] | 5363 | #endif |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 5364 | } |
| 5365 | |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 5366 | #ifdef CONFIG_FTRACE_SELFTEST |
| 5367 | /* Let selftest have access to static functions in this file */ |
| 5368 | #include "trace_selftest.c" |
| 5369 | #endif |
| 5370 | |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 5371 | struct trace_option_dentry { |
| 5372 | struct tracer_opt *opt; |
| 5373 | struct tracer_flags *flags; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5374 | struct trace_array *tr; |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 5375 | struct dentry *entry; |
| 5376 | }; |
| 5377 | |
| 5378 | static ssize_t |
| 5379 | trace_options_read(struct file *filp, char __user *ubuf, size_t cnt, |
| 5380 | loff_t *ppos) |
| 5381 | { |
| 5382 | struct trace_option_dentry *topt = filp->private_data; |
| 5383 | char *buf; |
| 5384 | |
| 5385 | if (topt->flags->val & topt->opt->bit) |
| 5386 | buf = "1\n"; |
| 5387 | else |
| 5388 | buf = "0\n"; |
| 5389 | |
| 5390 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, 2); |
| 5391 | } |
| 5392 | |
| 5393 | static ssize_t |
| 5394 | trace_options_write(struct file *filp, const char __user *ubuf, size_t cnt, |
| 5395 | loff_t *ppos) |
| 5396 | { |
| 5397 | struct trace_option_dentry *topt = filp->private_data; |
| 5398 | unsigned long val; |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 5399 | int ret; |
| 5400 | |
Peter Huewe | 22fe9b5 | 2011-06-07 21:58:27 +0200 | [diff] [blame] | 5401 | ret = kstrtoul_from_user(ubuf, cnt, 10, &val); |
| 5402 | if (ret) |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 5403 | return ret; |
| 5404 | |
Li Zefan | 8d18eaa | 2009-12-08 11:17:06 +0800 | [diff] [blame] | 5405 | if (val != 0 && val != 1) |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 5406 | return -EINVAL; |
Li Zefan | 8d18eaa | 2009-12-08 11:17:06 +0800 | [diff] [blame] | 5407 | |
| 5408 | if (!!(topt->flags->val & topt->opt->bit) != val) { |
| 5409 | mutex_lock(&trace_types_lock); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5410 | ret = __set_tracer_option(topt->tr->current_trace, topt->flags, |
Steven Rostedt | c757bea | 2009-12-21 22:35:16 -0500 | [diff] [blame] | 5411 | topt->opt, !val); |
Li Zefan | 8d18eaa | 2009-12-08 11:17:06 +0800 | [diff] [blame] | 5412 | mutex_unlock(&trace_types_lock); |
| 5413 | if (ret) |
| 5414 | return ret; |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 5415 | } |
| 5416 | |
| 5417 | *ppos += cnt; |
| 5418 | |
| 5419 | return cnt; |
| 5420 | } |
| 5421 | |
| 5422 | |
| 5423 | static const struct file_operations trace_options_fops = { |
| 5424 | .open = tracing_open_generic, |
| 5425 | .read = trace_options_read, |
| 5426 | .write = trace_options_write, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 5427 | .llseek = generic_file_llseek, |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 5428 | }; |
| 5429 | |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5430 | static ssize_t |
| 5431 | trace_options_core_read(struct file *filp, char __user *ubuf, size_t cnt, |
| 5432 | loff_t *ppos) |
| 5433 | { |
| 5434 | long index = (long)filp->private_data; |
| 5435 | char *buf; |
| 5436 | |
| 5437 | if (trace_flags & (1 << index)) |
| 5438 | buf = "1\n"; |
| 5439 | else |
| 5440 | buf = "0\n"; |
| 5441 | |
| 5442 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, 2); |
| 5443 | } |
| 5444 | |
| 5445 | static ssize_t |
| 5446 | trace_options_core_write(struct file *filp, const char __user *ubuf, size_t cnt, |
| 5447 | loff_t *ppos) |
| 5448 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5449 | struct trace_array *tr = &global_trace; |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5450 | long index = (long)filp->private_data; |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5451 | unsigned long val; |
| 5452 | int ret; |
| 5453 | |
Peter Huewe | 22fe9b5 | 2011-06-07 21:58:27 +0200 | [diff] [blame] | 5454 | ret = kstrtoul_from_user(ubuf, cnt, 10, &val); |
| 5455 | if (ret) |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5456 | return ret; |
| 5457 | |
Zhaolei | f2d84b6 | 2009-08-07 18:55:48 +0800 | [diff] [blame] | 5458 | if (val != 0 && val != 1) |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5459 | return -EINVAL; |
Steven Rostedt (Red Hat) | 69d34da | 2013-03-14 13:50:56 -0400 | [diff] [blame] | 5460 | |
| 5461 | mutex_lock(&trace_types_lock); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5462 | ret = set_tracer_flag(tr, 1 << index, val); |
Steven Rostedt (Red Hat) | 69d34da | 2013-03-14 13:50:56 -0400 | [diff] [blame] | 5463 | mutex_unlock(&trace_types_lock); |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5464 | |
Steven Rostedt (Red Hat) | 613f04a | 2013-03-14 15:03:53 -0400 | [diff] [blame] | 5465 | if (ret < 0) |
| 5466 | return ret; |
| 5467 | |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5468 | *ppos += cnt; |
| 5469 | |
| 5470 | return cnt; |
| 5471 | } |
| 5472 | |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5473 | static const struct file_operations trace_options_core_fops = { |
| 5474 | .open = tracing_open_generic, |
| 5475 | .read = trace_options_core_read, |
| 5476 | .write = trace_options_core_write, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 5477 | .llseek = generic_file_llseek, |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5478 | }; |
| 5479 | |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 5480 | struct dentry *trace_create_file(const char *name, |
Al Viro | f4ae40a6 | 2011-07-24 04:33:43 -0400 | [diff] [blame] | 5481 | umode_t mode, |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 5482 | struct dentry *parent, |
| 5483 | void *data, |
| 5484 | const struct file_operations *fops) |
| 5485 | { |
| 5486 | struct dentry *ret; |
| 5487 | |
| 5488 | ret = debugfs_create_file(name, mode, parent, data, fops); |
| 5489 | if (!ret) |
| 5490 | pr_warning("Could not create debugfs '%s' entry\n", name); |
| 5491 | |
| 5492 | return ret; |
| 5493 | } |
| 5494 | |
| 5495 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5496 | static struct dentry *trace_options_init_dentry(struct trace_array *tr) |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5497 | { |
| 5498 | struct dentry *d_tracer; |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5499 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5500 | if (tr->options) |
| 5501 | return tr->options; |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5502 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5503 | d_tracer = tracing_init_dentry_tr(tr); |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5504 | if (!d_tracer) |
| 5505 | return NULL; |
| 5506 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5507 | tr->options = debugfs_create_dir("options", d_tracer); |
| 5508 | if (!tr->options) { |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5509 | pr_warning("Could not create debugfs directory 'options'\n"); |
| 5510 | return NULL; |
| 5511 | } |
| 5512 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5513 | return tr->options; |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5514 | } |
| 5515 | |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 5516 | static void |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5517 | create_trace_option_file(struct trace_array *tr, |
| 5518 | struct trace_option_dentry *topt, |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 5519 | struct tracer_flags *flags, |
| 5520 | struct tracer_opt *opt) |
| 5521 | { |
| 5522 | struct dentry *t_options; |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 5523 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5524 | t_options = trace_options_init_dentry(tr); |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 5525 | if (!t_options) |
| 5526 | return; |
| 5527 | |
| 5528 | topt->flags = flags; |
| 5529 | topt->opt = opt; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5530 | topt->tr = tr; |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 5531 | |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 5532 | topt->entry = trace_create_file(opt->name, 0644, t_options, topt, |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 5533 | &trace_options_fops); |
| 5534 | |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 5535 | } |
| 5536 | |
| 5537 | static struct trace_option_dentry * |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5538 | create_trace_option_files(struct trace_array *tr, struct tracer *tracer) |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 5539 | { |
| 5540 | struct trace_option_dentry *topts; |
| 5541 | struct tracer_flags *flags; |
| 5542 | struct tracer_opt *opts; |
| 5543 | int cnt; |
| 5544 | |
| 5545 | if (!tracer) |
| 5546 | return NULL; |
| 5547 | |
| 5548 | flags = tracer->flags; |
| 5549 | |
| 5550 | if (!flags || !flags->opts) |
| 5551 | return NULL; |
| 5552 | |
| 5553 | opts = flags->opts; |
| 5554 | |
| 5555 | for (cnt = 0; opts[cnt].name; cnt++) |
| 5556 | ; |
| 5557 | |
Steven Rostedt | 0cfe824 | 2009-02-27 10:51:10 -0500 | [diff] [blame] | 5558 | topts = kcalloc(cnt + 1, sizeof(*topts), GFP_KERNEL); |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 5559 | if (!topts) |
| 5560 | return NULL; |
| 5561 | |
| 5562 | for (cnt = 0; opts[cnt].name; cnt++) |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5563 | create_trace_option_file(tr, &topts[cnt], flags, |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 5564 | &opts[cnt]); |
| 5565 | |
| 5566 | return topts; |
| 5567 | } |
| 5568 | |
| 5569 | static void |
| 5570 | destroy_trace_option_files(struct trace_option_dentry *topts) |
| 5571 | { |
| 5572 | int cnt; |
| 5573 | |
| 5574 | if (!topts) |
| 5575 | return; |
| 5576 | |
| 5577 | for (cnt = 0; topts[cnt].opt; cnt++) { |
| 5578 | if (topts[cnt].entry) |
| 5579 | debugfs_remove(topts[cnt].entry); |
| 5580 | } |
| 5581 | |
| 5582 | kfree(topts); |
| 5583 | } |
| 5584 | |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5585 | static struct dentry * |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5586 | create_trace_option_core_file(struct trace_array *tr, |
| 5587 | const char *option, long index) |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5588 | { |
| 5589 | struct dentry *t_options; |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5590 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5591 | t_options = trace_options_init_dentry(tr); |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5592 | if (!t_options) |
| 5593 | return NULL; |
| 5594 | |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 5595 | return trace_create_file(option, 0644, t_options, (void *)index, |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5596 | &trace_options_core_fops); |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5597 | } |
| 5598 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5599 | static __init void create_trace_options_dir(struct trace_array *tr) |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5600 | { |
| 5601 | struct dentry *t_options; |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5602 | int i; |
| 5603 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5604 | t_options = trace_options_init_dentry(tr); |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5605 | if (!t_options) |
| 5606 | return; |
| 5607 | |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 5608 | for (i = 0; trace_options[i]; i++) |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5609 | create_trace_option_core_file(tr, trace_options[i], i); |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5610 | } |
| 5611 | |
Steven Rostedt | 499e547 | 2012-02-22 15:50:28 -0500 | [diff] [blame] | 5612 | static ssize_t |
| 5613 | rb_simple_read(struct file *filp, char __user *ubuf, |
| 5614 | size_t cnt, loff_t *ppos) |
| 5615 | { |
Steven Rostedt | 348f0fc | 2012-04-16 15:41:28 -0400 | [diff] [blame] | 5616 | struct trace_array *tr = filp->private_data; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5617 | struct ring_buffer *buffer = tr->trace_buffer.buffer; |
Steven Rostedt | 499e547 | 2012-02-22 15:50:28 -0500 | [diff] [blame] | 5618 | char buf[64]; |
| 5619 | int r; |
| 5620 | |
| 5621 | if (buffer) |
| 5622 | r = ring_buffer_record_is_on(buffer); |
| 5623 | else |
| 5624 | r = 0; |
| 5625 | |
| 5626 | r = sprintf(buf, "%d\n", r); |
| 5627 | |
| 5628 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, r); |
| 5629 | } |
| 5630 | |
| 5631 | static ssize_t |
| 5632 | rb_simple_write(struct file *filp, const char __user *ubuf, |
| 5633 | size_t cnt, loff_t *ppos) |
| 5634 | { |
Steven Rostedt | 348f0fc | 2012-04-16 15:41:28 -0400 | [diff] [blame] | 5635 | struct trace_array *tr = filp->private_data; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5636 | struct ring_buffer *buffer = tr->trace_buffer.buffer; |
Steven Rostedt | 499e547 | 2012-02-22 15:50:28 -0500 | [diff] [blame] | 5637 | unsigned long val; |
| 5638 | int ret; |
| 5639 | |
| 5640 | ret = kstrtoul_from_user(ubuf, cnt, 10, &val); |
| 5641 | if (ret) |
| 5642 | return ret; |
| 5643 | |
| 5644 | if (buffer) { |
Steven Rostedt | 2df8f8a | 2013-01-11 16:14:10 -0500 | [diff] [blame] | 5645 | mutex_lock(&trace_types_lock); |
| 5646 | if (val) { |
Steven Rostedt | 499e547 | 2012-02-22 15:50:28 -0500 | [diff] [blame] | 5647 | ring_buffer_record_on(buffer); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5648 | if (tr->current_trace->start) |
| 5649 | tr->current_trace->start(tr); |
Steven Rostedt | 2df8f8a | 2013-01-11 16:14:10 -0500 | [diff] [blame] | 5650 | } else { |
Steven Rostedt | 499e547 | 2012-02-22 15:50:28 -0500 | [diff] [blame] | 5651 | ring_buffer_record_off(buffer); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5652 | if (tr->current_trace->stop) |
| 5653 | tr->current_trace->stop(tr); |
Steven Rostedt | 2df8f8a | 2013-01-11 16:14:10 -0500 | [diff] [blame] | 5654 | } |
| 5655 | mutex_unlock(&trace_types_lock); |
Steven Rostedt | 499e547 | 2012-02-22 15:50:28 -0500 | [diff] [blame] | 5656 | } |
| 5657 | |
| 5658 | (*ppos)++; |
| 5659 | |
| 5660 | return cnt; |
| 5661 | } |
| 5662 | |
| 5663 | static const struct file_operations rb_simple_fops = { |
| 5664 | .open = tracing_open_generic, |
| 5665 | .read = rb_simple_read, |
| 5666 | .write = rb_simple_write, |
| 5667 | .llseek = default_llseek, |
| 5668 | }; |
| 5669 | |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 5670 | struct dentry *trace_instance_dir; |
| 5671 | |
| 5672 | static void |
| 5673 | init_tracer_debugfs(struct trace_array *tr, struct dentry *d_tracer); |
| 5674 | |
Steven Rostedt (Red Hat) | 737223f | 2013-03-05 21:13:47 -0500 | [diff] [blame] | 5675 | static void init_trace_buffers(struct trace_array *tr, struct trace_buffer *buf) |
| 5676 | { |
| 5677 | int cpu; |
| 5678 | |
| 5679 | for_each_tracing_cpu(cpu) { |
| 5680 | memset(per_cpu_ptr(buf->data, cpu), 0, sizeof(struct trace_array_cpu)); |
| 5681 | per_cpu_ptr(buf->data, cpu)->trace_cpu.cpu = cpu; |
| 5682 | per_cpu_ptr(buf->data, cpu)->trace_cpu.tr = tr; |
| 5683 | } |
| 5684 | } |
| 5685 | |
Steven Rostedt (Red Hat) | 55034cd | 2013-03-07 22:48:09 -0500 | [diff] [blame] | 5686 | static int |
| 5687 | allocate_trace_buffer(struct trace_array *tr, struct trace_buffer *buf, int size) |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 5688 | { |
| 5689 | enum ring_buffer_flags rb_flags; |
Steven Rostedt (Red Hat) | 737223f | 2013-03-05 21:13:47 -0500 | [diff] [blame] | 5690 | |
| 5691 | rb_flags = trace_flags & TRACE_ITER_OVERWRITE ? RB_FL_OVERWRITE : 0; |
| 5692 | |
Steven Rostedt (Red Hat) | 55034cd | 2013-03-07 22:48:09 -0500 | [diff] [blame] | 5693 | buf->buffer = ring_buffer_alloc(size, rb_flags); |
| 5694 | if (!buf->buffer) |
| 5695 | return -ENOMEM; |
Steven Rostedt (Red Hat) | 737223f | 2013-03-05 21:13:47 -0500 | [diff] [blame] | 5696 | |
Steven Rostedt (Red Hat) | 55034cd | 2013-03-07 22:48:09 -0500 | [diff] [blame] | 5697 | buf->data = alloc_percpu(struct trace_array_cpu); |
| 5698 | if (!buf->data) { |
| 5699 | ring_buffer_free(buf->buffer); |
| 5700 | return -ENOMEM; |
| 5701 | } |
Steven Rostedt (Red Hat) | 737223f | 2013-03-05 21:13:47 -0500 | [diff] [blame] | 5702 | |
Steven Rostedt (Red Hat) | 55034cd | 2013-03-07 22:48:09 -0500 | [diff] [blame] | 5703 | init_trace_buffers(tr, buf); |
Steven Rostedt (Red Hat) | 737223f | 2013-03-05 21:13:47 -0500 | [diff] [blame] | 5704 | |
| 5705 | /* Allocate the first page for all buffers */ |
| 5706 | set_buffer_entries(&tr->trace_buffer, |
| 5707 | ring_buffer_size(tr->trace_buffer.buffer, 0)); |
| 5708 | |
Steven Rostedt (Red Hat) | 55034cd | 2013-03-07 22:48:09 -0500 | [diff] [blame] | 5709 | return 0; |
| 5710 | } |
| 5711 | |
| 5712 | static int allocate_trace_buffers(struct trace_array *tr, int size) |
| 5713 | { |
| 5714 | int ret; |
| 5715 | |
| 5716 | ret = allocate_trace_buffer(tr, &tr->trace_buffer, size); |
| 5717 | if (ret) |
| 5718 | return ret; |
| 5719 | |
Steven Rostedt (Red Hat) | 737223f | 2013-03-05 21:13:47 -0500 | [diff] [blame] | 5720 | #ifdef CONFIG_TRACER_MAX_TRACE |
Steven Rostedt (Red Hat) | 55034cd | 2013-03-07 22:48:09 -0500 | [diff] [blame] | 5721 | ret = allocate_trace_buffer(tr, &tr->max_buffer, |
| 5722 | allocate_snapshot ? size : 1); |
| 5723 | if (WARN_ON(ret)) { |
| 5724 | ring_buffer_free(tr->trace_buffer.buffer); |
| 5725 | free_percpu(tr->trace_buffer.data); |
| 5726 | return -ENOMEM; |
| 5727 | } |
| 5728 | tr->allocated_snapshot = allocate_snapshot; |
Steven Rostedt (Red Hat) | 737223f | 2013-03-05 21:13:47 -0500 | [diff] [blame] | 5729 | |
Steven Rostedt (Red Hat) | 55034cd | 2013-03-07 22:48:09 -0500 | [diff] [blame] | 5730 | /* |
| 5731 | * Only the top level trace array gets its snapshot allocated |
| 5732 | * from the kernel command line. |
| 5733 | */ |
| 5734 | allocate_snapshot = false; |
Steven Rostedt (Red Hat) | 737223f | 2013-03-05 21:13:47 -0500 | [diff] [blame] | 5735 | #endif |
| 5736 | return 0; |
Steven Rostedt (Red Hat) | 737223f | 2013-03-05 21:13:47 -0500 | [diff] [blame] | 5737 | } |
| 5738 | |
| 5739 | static int new_instance_create(const char *name) |
| 5740 | { |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 5741 | struct trace_array *tr; |
| 5742 | int ret; |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 5743 | |
| 5744 | mutex_lock(&trace_types_lock); |
| 5745 | |
| 5746 | ret = -EEXIST; |
| 5747 | list_for_each_entry(tr, &ftrace_trace_arrays, list) { |
| 5748 | if (tr->name && strcmp(tr->name, name) == 0) |
| 5749 | goto out_unlock; |
| 5750 | } |
| 5751 | |
| 5752 | ret = -ENOMEM; |
| 5753 | tr = kzalloc(sizeof(*tr), GFP_KERNEL); |
| 5754 | if (!tr) |
| 5755 | goto out_unlock; |
| 5756 | |
| 5757 | tr->name = kstrdup(name, GFP_KERNEL); |
| 5758 | if (!tr->name) |
| 5759 | goto out_free_tr; |
| 5760 | |
| 5761 | raw_spin_lock_init(&tr->start_lock); |
| 5762 | |
| 5763 | tr->current_trace = &nop_trace; |
| 5764 | |
| 5765 | INIT_LIST_HEAD(&tr->systems); |
| 5766 | INIT_LIST_HEAD(&tr->events); |
| 5767 | |
Steven Rostedt (Red Hat) | 737223f | 2013-03-05 21:13:47 -0500 | [diff] [blame] | 5768 | if (allocate_trace_buffers(tr, trace_buf_size) < 0) |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 5769 | goto out_free_tr; |
| 5770 | |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 5771 | /* Holder for file callbacks */ |
| 5772 | tr->trace_cpu.cpu = RING_BUFFER_ALL_CPUS; |
| 5773 | tr->trace_cpu.tr = tr; |
| 5774 | |
| 5775 | tr->dir = debugfs_create_dir(name, trace_instance_dir); |
| 5776 | if (!tr->dir) |
| 5777 | goto out_free_tr; |
| 5778 | |
| 5779 | ret = event_trace_add_tracer(tr->dir, tr); |
| 5780 | if (ret) |
| 5781 | goto out_free_tr; |
| 5782 | |
| 5783 | init_tracer_debugfs(tr, tr->dir); |
| 5784 | |
| 5785 | list_add(&tr->list, &ftrace_trace_arrays); |
| 5786 | |
| 5787 | mutex_unlock(&trace_types_lock); |
| 5788 | |
| 5789 | return 0; |
| 5790 | |
| 5791 | out_free_tr: |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5792 | if (tr->trace_buffer.buffer) |
| 5793 | ring_buffer_free(tr->trace_buffer.buffer); |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 5794 | kfree(tr->name); |
| 5795 | kfree(tr); |
| 5796 | |
| 5797 | out_unlock: |
| 5798 | mutex_unlock(&trace_types_lock); |
| 5799 | |
| 5800 | return ret; |
| 5801 | |
| 5802 | } |
| 5803 | |
Steven Rostedt | 0c8916c | 2012-08-07 16:14:16 -0400 | [diff] [blame] | 5804 | static int instance_delete(const char *name) |
| 5805 | { |
| 5806 | struct trace_array *tr; |
| 5807 | int found = 0; |
| 5808 | int ret; |
| 5809 | |
| 5810 | mutex_lock(&trace_types_lock); |
| 5811 | |
| 5812 | ret = -ENODEV; |
| 5813 | list_for_each_entry(tr, &ftrace_trace_arrays, list) { |
| 5814 | if (tr->name && strcmp(tr->name, name) == 0) { |
| 5815 | found = 1; |
| 5816 | break; |
| 5817 | } |
| 5818 | } |
| 5819 | if (!found) |
| 5820 | goto out_unlock; |
| 5821 | |
Steven Rostedt (Red Hat) | a695cb5 | 2013-03-06 15:27:24 -0500 | [diff] [blame] | 5822 | ret = -EBUSY; |
| 5823 | if (tr->ref) |
| 5824 | goto out_unlock; |
| 5825 | |
Steven Rostedt | 0c8916c | 2012-08-07 16:14:16 -0400 | [diff] [blame] | 5826 | list_del(&tr->list); |
| 5827 | |
| 5828 | event_trace_del_tracer(tr); |
| 5829 | debugfs_remove_recursive(tr->dir); |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5830 | free_percpu(tr->trace_buffer.data); |
| 5831 | ring_buffer_free(tr->trace_buffer.buffer); |
Steven Rostedt | 0c8916c | 2012-08-07 16:14:16 -0400 | [diff] [blame] | 5832 | |
| 5833 | kfree(tr->name); |
| 5834 | kfree(tr); |
| 5835 | |
| 5836 | ret = 0; |
| 5837 | |
| 5838 | out_unlock: |
| 5839 | mutex_unlock(&trace_types_lock); |
| 5840 | |
| 5841 | return ret; |
| 5842 | } |
| 5843 | |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 5844 | static int instance_mkdir (struct inode *inode, struct dentry *dentry, umode_t mode) |
| 5845 | { |
| 5846 | struct dentry *parent; |
| 5847 | int ret; |
| 5848 | |
| 5849 | /* Paranoid: Make sure the parent is the "instances" directory */ |
| 5850 | parent = hlist_entry(inode->i_dentry.first, struct dentry, d_alias); |
| 5851 | if (WARN_ON_ONCE(parent != trace_instance_dir)) |
| 5852 | return -ENOENT; |
| 5853 | |
| 5854 | /* |
| 5855 | * The inode mutex is locked, but debugfs_create_dir() will also |
| 5856 | * take the mutex. As the instances directory can not be destroyed |
| 5857 | * or changed in any other way, it is safe to unlock it, and |
| 5858 | * let the dentry try. If two users try to make the same dir at |
| 5859 | * the same time, then the new_instance_create() will determine the |
| 5860 | * winner. |
| 5861 | */ |
| 5862 | mutex_unlock(&inode->i_mutex); |
| 5863 | |
| 5864 | ret = new_instance_create(dentry->d_iname); |
| 5865 | |
| 5866 | mutex_lock(&inode->i_mutex); |
| 5867 | |
| 5868 | return ret; |
| 5869 | } |
| 5870 | |
Steven Rostedt | 0c8916c | 2012-08-07 16:14:16 -0400 | [diff] [blame] | 5871 | static int instance_rmdir(struct inode *inode, struct dentry *dentry) |
| 5872 | { |
| 5873 | struct dentry *parent; |
| 5874 | int ret; |
| 5875 | |
| 5876 | /* Paranoid: Make sure the parent is the "instances" directory */ |
| 5877 | parent = hlist_entry(inode->i_dentry.first, struct dentry, d_alias); |
| 5878 | if (WARN_ON_ONCE(parent != trace_instance_dir)) |
| 5879 | return -ENOENT; |
| 5880 | |
| 5881 | /* The caller did a dget() on dentry */ |
| 5882 | mutex_unlock(&dentry->d_inode->i_mutex); |
| 5883 | |
| 5884 | /* |
| 5885 | * The inode mutex is locked, but debugfs_create_dir() will also |
| 5886 | * take the mutex. As the instances directory can not be destroyed |
| 5887 | * or changed in any other way, it is safe to unlock it, and |
| 5888 | * let the dentry try. If two users try to make the same dir at |
| 5889 | * the same time, then the instance_delete() will determine the |
| 5890 | * winner. |
| 5891 | */ |
| 5892 | mutex_unlock(&inode->i_mutex); |
| 5893 | |
| 5894 | ret = instance_delete(dentry->d_iname); |
| 5895 | |
| 5896 | mutex_lock_nested(&inode->i_mutex, I_MUTEX_PARENT); |
| 5897 | mutex_lock(&dentry->d_inode->i_mutex); |
| 5898 | |
| 5899 | return ret; |
| 5900 | } |
| 5901 | |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 5902 | static const struct inode_operations instance_dir_inode_operations = { |
| 5903 | .lookup = simple_lookup, |
| 5904 | .mkdir = instance_mkdir, |
Steven Rostedt | 0c8916c | 2012-08-07 16:14:16 -0400 | [diff] [blame] | 5905 | .rmdir = instance_rmdir, |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 5906 | }; |
| 5907 | |
| 5908 | static __init void create_trace_instances(struct dentry *d_tracer) |
| 5909 | { |
| 5910 | trace_instance_dir = debugfs_create_dir("instances", d_tracer); |
| 5911 | if (WARN_ON(!trace_instance_dir)) |
| 5912 | return; |
| 5913 | |
| 5914 | /* Hijack the dir inode operations, to allow mkdir */ |
| 5915 | trace_instance_dir->d_inode->i_op = &instance_dir_inode_operations; |
| 5916 | } |
| 5917 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5918 | static void |
| 5919 | init_tracer_debugfs(struct trace_array *tr, struct dentry *d_tracer) |
| 5920 | { |
Steven Rostedt (Red Hat) | 121aaee | 2013-03-05 21:52:25 -0500 | [diff] [blame] | 5921 | int cpu; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5922 | |
| 5923 | trace_create_file("trace_options", 0644, d_tracer, |
| 5924 | tr, &tracing_iter_fops); |
| 5925 | |
| 5926 | trace_create_file("trace", 0644, d_tracer, |
| 5927 | (void *)&tr->trace_cpu, &tracing_fops); |
| 5928 | |
| 5929 | trace_create_file("trace_pipe", 0444, d_tracer, |
| 5930 | (void *)&tr->trace_cpu, &tracing_pipe_fops); |
| 5931 | |
| 5932 | trace_create_file("buffer_size_kb", 0644, d_tracer, |
| 5933 | (void *)&tr->trace_cpu, &tracing_entries_fops); |
| 5934 | |
| 5935 | trace_create_file("buffer_total_size_kb", 0444, d_tracer, |
| 5936 | tr, &tracing_total_entries_fops); |
| 5937 | |
| 5938 | trace_create_file("free_buffer", 0644, d_tracer, |
| 5939 | tr, &tracing_free_buffer_fops); |
| 5940 | |
| 5941 | trace_create_file("trace_marker", 0220, d_tracer, |
| 5942 | tr, &tracing_mark_fops); |
| 5943 | |
| 5944 | trace_create_file("trace_clock", 0644, d_tracer, tr, |
| 5945 | &trace_clock_fops); |
| 5946 | |
| 5947 | trace_create_file("tracing_on", 0644, d_tracer, |
| 5948 | tr, &rb_simple_fops); |
Steven Rostedt (Red Hat) | ce9bae5 | 2013-03-05 21:23:55 -0500 | [diff] [blame] | 5949 | |
| 5950 | #ifdef CONFIG_TRACER_SNAPSHOT |
| 5951 | trace_create_file("snapshot", 0644, d_tracer, |
| 5952 | (void *)&tr->trace_cpu, &snapshot_fops); |
| 5953 | #endif |
Steven Rostedt (Red Hat) | 121aaee | 2013-03-05 21:52:25 -0500 | [diff] [blame] | 5954 | |
| 5955 | for_each_tracing_cpu(cpu) |
| 5956 | tracing_init_debugfs_percpu(tr, cpu); |
| 5957 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5958 | } |
| 5959 | |
Frédéric Weisbecker | b5ad384 | 2008-09-23 11:34:32 +0100 | [diff] [blame] | 5960 | static __init int tracer_init_debugfs(void) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5961 | { |
| 5962 | struct dentry *d_tracer; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5963 | |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 5964 | trace_access_lock_init(); |
| 5965 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5966 | d_tracer = tracing_init_dentry(); |
Namhyung Kim | ed6f1c9 | 2013-04-10 09:18:12 +0900 | [diff] [blame] | 5967 | if (!d_tracer) |
| 5968 | return 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5969 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5970 | init_tracer_debugfs(&global_trace, d_tracer); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5971 | |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 5972 | trace_create_file("tracing_cpumask", 0644, d_tracer, |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5973 | &global_trace, &tracing_cpumask_fops); |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 5974 | |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 5975 | trace_create_file("available_tracers", 0444, d_tracer, |
| 5976 | &global_trace, &show_traces_fops); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5977 | |
Li Zefan | 339ae5d | 2009-04-17 10:34:30 +0800 | [diff] [blame] | 5978 | trace_create_file("current_tracer", 0644, d_tracer, |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 5979 | &global_trace, &set_tracer_fops); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5980 | |
Steven Rostedt | 5d4a9db | 2009-08-27 16:52:21 -0400 | [diff] [blame] | 5981 | #ifdef CONFIG_TRACER_MAX_TRACE |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 5982 | trace_create_file("tracing_max_latency", 0644, d_tracer, |
| 5983 | &tracing_max_latency, &tracing_max_lat_fops); |
Tim Bird | 0e95017 | 2010-02-25 15:36:43 -0800 | [diff] [blame] | 5984 | #endif |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5985 | |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 5986 | trace_create_file("tracing_thresh", 0644, d_tracer, |
| 5987 | &tracing_thresh, &tracing_max_lat_fops); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5988 | |
Li Zefan | 339ae5d | 2009-04-17 10:34:30 +0800 | [diff] [blame] | 5989 | trace_create_file("README", 0444, d_tracer, |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 5990 | NULL, &tracing_readme_fops); |
Ingo Molnar | 7bd2f24 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 5991 | |
Avadh Patel | 69abe6a | 2009-04-10 16:04:48 -0400 | [diff] [blame] | 5992 | trace_create_file("saved_cmdlines", 0444, d_tracer, |
| 5993 | NULL, &tracing_saved_cmdlines_fops); |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 5994 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5995 | #ifdef CONFIG_DYNAMIC_FTRACE |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 5996 | trace_create_file("dyn_ftrace_total_info", 0444, d_tracer, |
| 5997 | &ftrace_update_tot_cnt, &tracing_dyn_info_fops); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5998 | #endif |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 5999 | |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 6000 | create_trace_instances(d_tracer); |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 6001 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6002 | create_trace_options_dir(&global_trace); |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 6003 | |
Frédéric Weisbecker | b5ad384 | 2008-09-23 11:34:32 +0100 | [diff] [blame] | 6004 | return 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 6005 | } |
| 6006 | |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 6007 | static int trace_panic_handler(struct notifier_block *this, |
| 6008 | unsigned long event, void *unused) |
| 6009 | { |
Steven Rostedt | 944ac42 | 2008-10-23 19:26:08 -0400 | [diff] [blame] | 6010 | if (ftrace_dump_on_oops) |
Frederic Weisbecker | cecbca9 | 2010-04-18 19:08:41 +0200 | [diff] [blame] | 6011 | ftrace_dump(ftrace_dump_on_oops); |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 6012 | return NOTIFY_OK; |
| 6013 | } |
| 6014 | |
| 6015 | static struct notifier_block trace_panic_notifier = { |
| 6016 | .notifier_call = trace_panic_handler, |
| 6017 | .next = NULL, |
| 6018 | .priority = 150 /* priority: INT_MAX >= x >= 0 */ |
| 6019 | }; |
| 6020 | |
| 6021 | static int trace_die_handler(struct notifier_block *self, |
| 6022 | unsigned long val, |
| 6023 | void *data) |
| 6024 | { |
| 6025 | switch (val) { |
| 6026 | case DIE_OOPS: |
Steven Rostedt | 944ac42 | 2008-10-23 19:26:08 -0400 | [diff] [blame] | 6027 | if (ftrace_dump_on_oops) |
Frederic Weisbecker | cecbca9 | 2010-04-18 19:08:41 +0200 | [diff] [blame] | 6028 | ftrace_dump(ftrace_dump_on_oops); |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 6029 | break; |
| 6030 | default: |
| 6031 | break; |
| 6032 | } |
| 6033 | return NOTIFY_OK; |
| 6034 | } |
| 6035 | |
| 6036 | static struct notifier_block trace_die_notifier = { |
| 6037 | .notifier_call = trace_die_handler, |
| 6038 | .priority = 200 |
| 6039 | }; |
| 6040 | |
| 6041 | /* |
| 6042 | * printk is set to max of 1024, we really don't need it that big. |
| 6043 | * Nothing should be printing 1000 characters anyway. |
| 6044 | */ |
| 6045 | #define TRACE_MAX_PRINT 1000 |
| 6046 | |
| 6047 | /* |
| 6048 | * Define here KERN_TRACE so that we have one place to modify |
| 6049 | * it if we decide to change what log level the ftrace dump |
| 6050 | * should be at. |
| 6051 | */ |
Steven Rostedt | 428aee1 | 2009-01-14 12:24:42 -0500 | [diff] [blame] | 6052 | #define KERN_TRACE KERN_EMERG |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 6053 | |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 6054 | void |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 6055 | trace_printk_seq(struct trace_seq *s) |
| 6056 | { |
| 6057 | /* Probably should print a warning here. */ |
zhangwei(Jovi) | bd6df18 | 2013-03-11 15:13:37 +0800 | [diff] [blame] | 6058 | if (s->len >= TRACE_MAX_PRINT) |
| 6059 | s->len = TRACE_MAX_PRINT; |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 6060 | |
| 6061 | /* should be zero ended, but we are paranoid. */ |
| 6062 | s->buffer[s->len] = 0; |
| 6063 | |
| 6064 | printk(KERN_TRACE "%s", s->buffer); |
| 6065 | |
Steven Rostedt | f952075 | 2009-03-02 14:04:40 -0500 | [diff] [blame] | 6066 | trace_seq_init(s); |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 6067 | } |
| 6068 | |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 6069 | void trace_init_global_iter(struct trace_iterator *iter) |
| 6070 | { |
| 6071 | iter->tr = &global_trace; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6072 | iter->trace = iter->tr->current_trace; |
Steven Rostedt | ae3b509 | 2013-01-23 15:22:59 -0500 | [diff] [blame] | 6073 | iter->cpu_file = RING_BUFFER_ALL_CPUS; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 6074 | iter->trace_buffer = &global_trace.trace_buffer; |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 6075 | } |
| 6076 | |
Steven Rostedt (Red Hat) | 7fe70b5 | 2013-03-15 13:10:35 -0400 | [diff] [blame] | 6077 | void ftrace_dump(enum ftrace_dump_mode oops_dump_mode) |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 6078 | { |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 6079 | /* use static because iter can be a bit big for the stack */ |
| 6080 | static struct trace_iterator iter; |
Steven Rostedt (Red Hat) | 7fe70b5 | 2013-03-15 13:10:35 -0400 | [diff] [blame] | 6081 | static atomic_t dump_running; |
Frederic Weisbecker | cf586b6 | 2009-03-22 05:04:35 +0100 | [diff] [blame] | 6082 | unsigned int old_userobj; |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 6083 | unsigned long flags; |
| 6084 | int cnt = 0, cpu; |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 6085 | |
Steven Rostedt (Red Hat) | 7fe70b5 | 2013-03-15 13:10:35 -0400 | [diff] [blame] | 6086 | /* Only allow one dump user at a time. */ |
| 6087 | if (atomic_inc_return(&dump_running) != 1) { |
| 6088 | atomic_dec(&dump_running); |
| 6089 | return; |
Steven Rostedt | e0a413f | 2011-09-29 21:26:16 -0400 | [diff] [blame] | 6090 | } |
| 6091 | |
Steven Rostedt (Red Hat) | 7fe70b5 | 2013-03-15 13:10:35 -0400 | [diff] [blame] | 6092 | /* |
| 6093 | * Always turn off tracing when we dump. |
| 6094 | * We don't need to show trace output of what happens |
| 6095 | * between multiple crashes. |
| 6096 | * |
| 6097 | * If the user does a sysrq-z, then they can re-enable |
| 6098 | * tracing with echo 1 > tracing_on. |
| 6099 | */ |
| 6100 | tracing_off(); |
| 6101 | |
| 6102 | local_irq_save(flags); |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 6103 | |
Jovi Zhang | 38dbe0b | 2013-01-25 18:03:07 +0800 | [diff] [blame] | 6104 | /* Simulate the iterator */ |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 6105 | trace_init_global_iter(&iter); |
| 6106 | |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 6107 | for_each_tracing_cpu(cpu) { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 6108 | atomic_inc(&per_cpu_ptr(iter.tr->trace_buffer.data, cpu)->disabled); |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 6109 | } |
| 6110 | |
Frederic Weisbecker | cf586b6 | 2009-03-22 05:04:35 +0100 | [diff] [blame] | 6111 | old_userobj = trace_flags & TRACE_ITER_SYM_USEROBJ; |
| 6112 | |
Török Edwin | b54d3de | 2008-11-22 13:28:48 +0200 | [diff] [blame] | 6113 | /* don't look at user memory in panic mode */ |
| 6114 | trace_flags &= ~TRACE_ITER_SYM_USEROBJ; |
| 6115 | |
Frederic Weisbecker | cecbca9 | 2010-04-18 19:08:41 +0200 | [diff] [blame] | 6116 | switch (oops_dump_mode) { |
| 6117 | case DUMP_ALL: |
Steven Rostedt | ae3b509 | 2013-01-23 15:22:59 -0500 | [diff] [blame] | 6118 | iter.cpu_file = RING_BUFFER_ALL_CPUS; |
Frederic Weisbecker | cecbca9 | 2010-04-18 19:08:41 +0200 | [diff] [blame] | 6119 | break; |
| 6120 | case DUMP_ORIG: |
| 6121 | iter.cpu_file = raw_smp_processor_id(); |
| 6122 | break; |
| 6123 | case DUMP_NONE: |
| 6124 | goto out_enable; |
| 6125 | default: |
| 6126 | printk(KERN_TRACE "Bad dumping mode, switching to all CPUs dump\n"); |
Steven Rostedt | ae3b509 | 2013-01-23 15:22:59 -0500 | [diff] [blame] | 6127 | iter.cpu_file = RING_BUFFER_ALL_CPUS; |
Frederic Weisbecker | cecbca9 | 2010-04-18 19:08:41 +0200 | [diff] [blame] | 6128 | } |
| 6129 | |
| 6130 | printk(KERN_TRACE "Dumping ftrace buffer:\n"); |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 6131 | |
Steven Rostedt (Red Hat) | 7fe70b5 | 2013-03-15 13:10:35 -0400 | [diff] [blame] | 6132 | /* Did function tracer already get disabled? */ |
| 6133 | if (ftrace_is_dead()) { |
| 6134 | printk("# WARNING: FUNCTION TRACING IS CORRUPTED\n"); |
| 6135 | printk("# MAY BE MISSING FUNCTION EVENTS\n"); |
| 6136 | } |
| 6137 | |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 6138 | /* |
| 6139 | * We need to stop all tracing on all CPUS to read the |
| 6140 | * the next buffer. This is a bit expensive, but is |
| 6141 | * not done often. We fill all what we can read, |
| 6142 | * and then release the locks again. |
| 6143 | */ |
| 6144 | |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 6145 | while (!trace_empty(&iter)) { |
| 6146 | |
| 6147 | if (!cnt) |
| 6148 | printk(KERN_TRACE "---------------------------------\n"); |
| 6149 | |
| 6150 | cnt++; |
| 6151 | |
| 6152 | /* reset all but tr, trace, and overruns */ |
| 6153 | memset(&iter.seq, 0, |
| 6154 | sizeof(struct trace_iterator) - |
| 6155 | offsetof(struct trace_iterator, seq)); |
| 6156 | iter.iter_flags |= TRACE_FILE_LAT_FMT; |
| 6157 | iter.pos = -1; |
| 6158 | |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 6159 | if (trace_find_next_entry_inc(&iter) != NULL) { |
Lai Jiangshan | 74e7ff8 | 2009-07-28 20:17:22 +0800 | [diff] [blame] | 6160 | int ret; |
| 6161 | |
| 6162 | ret = print_trace_line(&iter); |
| 6163 | if (ret != TRACE_TYPE_NO_CONSUME) |
| 6164 | trace_consume(&iter); |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 6165 | } |
Steven Rostedt | b892e5c | 2012-03-01 22:06:48 -0500 | [diff] [blame] | 6166 | touch_nmi_watchdog(); |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 6167 | |
| 6168 | trace_printk_seq(&iter.seq); |
| 6169 | } |
| 6170 | |
| 6171 | if (!cnt) |
| 6172 | printk(KERN_TRACE " (ftrace buffer empty)\n"); |
| 6173 | else |
| 6174 | printk(KERN_TRACE "---------------------------------\n"); |
| 6175 | |
Frederic Weisbecker | cecbca9 | 2010-04-18 19:08:41 +0200 | [diff] [blame] | 6176 | out_enable: |
Steven Rostedt (Red Hat) | 7fe70b5 | 2013-03-15 13:10:35 -0400 | [diff] [blame] | 6177 | trace_flags |= old_userobj; |
Frederic Weisbecker | cf586b6 | 2009-03-22 05:04:35 +0100 | [diff] [blame] | 6178 | |
Steven Rostedt (Red Hat) | 7fe70b5 | 2013-03-15 13:10:35 -0400 | [diff] [blame] | 6179 | for_each_tracing_cpu(cpu) { |
| 6180 | atomic_dec(&per_cpu_ptr(iter.trace_buffer->data, cpu)->disabled); |
Frederic Weisbecker | cf586b6 | 2009-03-22 05:04:35 +0100 | [diff] [blame] | 6181 | } |
Steven Rostedt (Red Hat) | 7fe70b5 | 2013-03-15 13:10:35 -0400 | [diff] [blame] | 6182 | atomic_dec(&dump_running); |
Steven Rostedt | cd891ae | 2009-04-28 11:39:34 -0400 | [diff] [blame] | 6183 | local_irq_restore(flags); |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 6184 | } |
Paul E. McKenney | a8eecf2 | 2011-10-02 11:01:15 -0700 | [diff] [blame] | 6185 | EXPORT_SYMBOL_GPL(ftrace_dump); |
Frederic Weisbecker | cf586b6 | 2009-03-22 05:04:35 +0100 | [diff] [blame] | 6186 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 6187 | __init static int tracer_alloc_buffers(void) |
| 6188 | { |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 6189 | int ring_buf_size; |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 6190 | int ret = -ENOMEM; |
| 6191 | |
David Sharp | 750912f | 2010-12-08 13:46:47 -0800 | [diff] [blame] | 6192 | |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 6193 | if (!alloc_cpumask_var(&tracing_buffer_mask, GFP_KERNEL)) |
| 6194 | goto out; |
| 6195 | |
| 6196 | if (!alloc_cpumask_var(&tracing_cpumask, GFP_KERNEL)) |
| 6197 | goto out_free_buffer_mask; |
| 6198 | |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 6199 | /* Only allocate trace_printk buffers if a trace_printk exists */ |
| 6200 | if (__stop___trace_bprintk_fmt != __start___trace_bprintk_fmt) |
Steven Rostedt | 8169883 | 2012-10-11 10:15:05 -0400 | [diff] [blame] | 6201 | /* Must be called before global_trace.buffer is allocated */ |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 6202 | trace_printk_init_buffers(); |
| 6203 | |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 6204 | /* To save memory, keep the ring buffer size to its minimum */ |
| 6205 | if (ring_buffer_expanded) |
| 6206 | ring_buf_size = trace_buf_size; |
| 6207 | else |
| 6208 | ring_buf_size = 1; |
| 6209 | |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 6210 | cpumask_copy(tracing_buffer_mask, cpu_possible_mask); |
| 6211 | cpumask_copy(tracing_cpumask, cpu_all_mask); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 6212 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6213 | raw_spin_lock_init(&global_trace.start_lock); |
| 6214 | |
Steven Rostedt | ab46428 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 6215 | /* TODO: make the number of buffers hot pluggable with CPUS */ |
Steven Rostedt (Red Hat) | 737223f | 2013-03-05 21:13:47 -0500 | [diff] [blame] | 6216 | if (allocate_trace_buffers(&global_trace, ring_buf_size) < 0) { |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 6217 | printk(KERN_ERR "tracer: failed to allocate ring buffer!\n"); |
| 6218 | WARN_ON(1); |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 6219 | goto out_free_cpumask; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 6220 | } |
Steven Rostedt | a7603ff | 2012-08-06 16:24:11 -0400 | [diff] [blame] | 6221 | |
Steven Rostedt | 499e547 | 2012-02-22 15:50:28 -0500 | [diff] [blame] | 6222 | if (global_trace.buffer_disabled) |
| 6223 | tracing_off(); |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 6224 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 6225 | trace_init_cmdlines(); |
| 6226 | |
Steven Rostedt (Red Hat) | ca16431 | 2013-05-23 11:51:10 -0400 | [diff] [blame] | 6227 | /* |
| 6228 | * register_tracer() might reference current_trace, so it |
| 6229 | * needs to be set before we register anything. This is |
| 6230 | * just a bootstrap of current_trace anyway. |
| 6231 | */ |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6232 | global_trace.current_trace = &nop_trace; |
| 6233 | |
Steven Rostedt (Red Hat) | ca16431 | 2013-05-23 11:51:10 -0400 | [diff] [blame] | 6234 | register_tracer(&nop_trace); |
| 6235 | |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 6236 | /* All seems OK, enable tracing */ |
| 6237 | tracing_disabled = 0; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 6238 | |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 6239 | atomic_notifier_chain_register(&panic_notifier_list, |
| 6240 | &trace_panic_notifier); |
| 6241 | |
| 6242 | register_die_notifier(&trace_die_notifier); |
Frederic Weisbecker | 2fc1dfb | 2009-03-16 01:45:03 +0100 | [diff] [blame] | 6243 | |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 6244 | global_trace.flags = TRACE_ARRAY_FL_GLOBAL; |
| 6245 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6246 | /* Holder for file callbacks */ |
| 6247 | global_trace.trace_cpu.cpu = RING_BUFFER_ALL_CPUS; |
| 6248 | global_trace.trace_cpu.tr = &global_trace; |
| 6249 | |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 6250 | INIT_LIST_HEAD(&global_trace.systems); |
| 6251 | INIT_LIST_HEAD(&global_trace.events); |
| 6252 | list_add(&global_trace.list, &ftrace_trace_arrays); |
| 6253 | |
Steven Rostedt | 7bcfaf5 | 2012-11-01 22:56:07 -0400 | [diff] [blame] | 6254 | while (trace_boot_options) { |
| 6255 | char *option; |
| 6256 | |
| 6257 | option = strsep(&trace_boot_options, ","); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6258 | trace_set_options(&global_trace, option); |
Steven Rostedt | 7bcfaf5 | 2012-11-01 22:56:07 -0400 | [diff] [blame] | 6259 | } |
| 6260 | |
Steven Rostedt (Red Hat) | 77fd5c1 | 2013-03-12 11:49:18 -0400 | [diff] [blame] | 6261 | register_snapshot_cmd(); |
| 6262 | |
Frederic Weisbecker | 2fc1dfb | 2009-03-16 01:45:03 +0100 | [diff] [blame] | 6263 | return 0; |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 6264 | |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 6265 | out_free_cpumask: |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 6266 | free_percpu(global_trace.trace_buffer.data); |
| 6267 | #ifdef CONFIG_TRACER_MAX_TRACE |
| 6268 | free_percpu(global_trace.max_buffer.data); |
| 6269 | #endif |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 6270 | free_cpumask_var(tracing_cpumask); |
| 6271 | out_free_buffer_mask: |
| 6272 | free_cpumask_var(tracing_buffer_mask); |
| 6273 | out: |
| 6274 | return ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 6275 | } |
Steven Rostedt | b2821ae | 2009-02-02 21:38:32 -0500 | [diff] [blame] | 6276 | |
| 6277 | __init static int clear_boot_tracer(void) |
| 6278 | { |
| 6279 | /* |
| 6280 | * The default tracer at boot buffer is an init section. |
| 6281 | * This function is called in lateinit. If we did not |
| 6282 | * find the boot tracer, then clear it out, to prevent |
| 6283 | * later registration from accessing the buffer that is |
| 6284 | * about to be freed. |
| 6285 | */ |
| 6286 | if (!default_bootup_tracer) |
| 6287 | return 0; |
| 6288 | |
| 6289 | printk(KERN_INFO "ftrace bootup tracer '%s' not registered.\n", |
| 6290 | default_bootup_tracer); |
| 6291 | default_bootup_tracer = NULL; |
| 6292 | |
| 6293 | return 0; |
| 6294 | } |
| 6295 | |
Frédéric Weisbecker | b5ad384 | 2008-09-23 11:34:32 +0100 | [diff] [blame] | 6296 | early_initcall(tracer_alloc_buffers); |
| 6297 | fs_initcall(tracer_init_debugfs); |
Steven Rostedt | b2821ae | 2009-02-02 21:38:32 -0500 | [diff] [blame] | 6298 | late_initcall(clear_boot_tracer); |