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 | { |
Li Zefan | ee6c2c1 | 2009-09-18 14:06:47 +0800 | [diff] [blame] | 128 | strncpy(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) | 55034cd | 2013-03-07 22:48:09 -0500 | [diff] [blame] | 152 | static int __init alloc_snapshot(char *str) |
| 153 | { |
| 154 | allocate_snapshot = true; |
| 155 | /* We also need the main ring buffer expanded */ |
| 156 | ring_buffer_expanded = true; |
| 157 | return 1; |
| 158 | } |
| 159 | __setup("alloc_snapshot", alloc_snapshot); |
| 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 | { |
| 167 | strncpy(trace_boot_options_buf, str, MAX_TRACER_SIZE); |
| 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); |
| 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 | |
Mandeep Singh Baines | 5224c3a | 2012-09-07 18:12:19 -0700 | [diff] [blame] | 331 | TRACE_ITER_IRQ_INFO | TRACE_ITER_MARKERS; |
Ingo Molnar | 4e65551 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 332 | |
Steven Rostedt | 0d5c6e1 | 2012-11-01 20:54:21 -0400 | [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 | |
Steven Rostedt (Red Hat) | 09ae723 | 2013-03-08 21:02:34 -0500 | [diff] [blame^] | 353 | /** |
| 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 | |
| 445 | if (!tr->allocated_snapshot) { |
| 446 | trace_printk("*** SNAPSHOT NOT ALLOCATED ***\n"); |
| 447 | trace_printk("*** stopping trace here! ***\n"); |
| 448 | tracing_off(); |
| 449 | return; |
| 450 | } |
| 451 | |
| 452 | /* Note, snapshot can not be used when the tracer uses it */ |
| 453 | if (tracer->use_max_tr) { |
| 454 | trace_printk("*** LATENCY TRACER ACTIVE ***\n"); |
| 455 | trace_printk("*** Can not use snapshot (sorry) ***\n"); |
| 456 | return; |
| 457 | } |
| 458 | |
| 459 | local_irq_save(flags); |
| 460 | update_max_tr(tr, current, smp_processor_id()); |
| 461 | local_irq_restore(flags); |
| 462 | } |
| 463 | |
| 464 | static int resize_buffer_duplicate_size(struct trace_buffer *trace_buf, |
| 465 | struct trace_buffer *size_buf, int cpu_id); |
| 466 | |
| 467 | /** |
| 468 | * trace_snapshot_alloc - allocate and take a snapshot of the current buffer. |
| 469 | * |
| 470 | * This is similar to trace_snapshot(), but it will allocate the |
| 471 | * snapshot buffer if it isn't already allocated. Use this only |
| 472 | * where it is safe to sleep, as the allocation may sleep. |
| 473 | * |
| 474 | * This causes a swap between the snapshot buffer and the current live |
| 475 | * tracing buffer. You can use this to take snapshots of the live |
| 476 | * trace when some condition is triggered, but continue to trace. |
| 477 | */ |
| 478 | void tracing_snapshot_alloc(void) |
| 479 | { |
| 480 | struct trace_array *tr = &global_trace; |
| 481 | int ret; |
| 482 | |
| 483 | if (!tr->allocated_snapshot) { |
| 484 | |
| 485 | /* allocate spare buffer */ |
| 486 | ret = resize_buffer_duplicate_size(&tr->max_buffer, |
| 487 | &tr->trace_buffer, RING_BUFFER_ALL_CPUS); |
| 488 | if (WARN_ON(ret < 0)) |
| 489 | return; |
| 490 | |
| 491 | tr->allocated_snapshot = true; |
| 492 | } |
| 493 | |
| 494 | tracing_snapshot(); |
| 495 | } |
| 496 | #else |
| 497 | void tracing_snapshot(void) |
| 498 | { |
| 499 | WARN_ONCE(1, "Snapshot feature not enabled, but internal snapshot used"); |
| 500 | } |
| 501 | void tracing_snapshot_alloc(void) |
| 502 | { |
| 503 | /* Give warning */ |
| 504 | tracing_snapshot(); |
| 505 | } |
| 506 | #endif /* CONFIG_TRACER_SNAPSHOT */ |
| 507 | |
Steven Rostedt | 499e547 | 2012-02-22 15:50:28 -0500 | [diff] [blame] | 508 | /** |
| 509 | * tracing_off - turn off tracing buffers |
| 510 | * |
| 511 | * This function stops the tracing buffers from recording data. |
| 512 | * It does not disable any overhead the tracers themselves may |
| 513 | * be causing. This function simply causes all recording to |
| 514 | * the ring buffers to fail. |
| 515 | */ |
| 516 | void tracing_off(void) |
| 517 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 518 | if (global_trace.trace_buffer.buffer) |
| 519 | ring_buffer_record_off(global_trace.trace_buffer.buffer); |
Steven Rostedt | 499e547 | 2012-02-22 15:50:28 -0500 | [diff] [blame] | 520 | /* |
| 521 | * This flag is only looked at when buffers haven't been |
| 522 | * allocated yet. We don't really care about the race |
| 523 | * between setting this flag and actually turning |
| 524 | * on the buffer. |
| 525 | */ |
| 526 | global_trace.buffer_disabled = 1; |
| 527 | } |
| 528 | EXPORT_SYMBOL_GPL(tracing_off); |
| 529 | |
| 530 | /** |
| 531 | * tracing_is_on - show state of ring buffers enabled |
| 532 | */ |
| 533 | int tracing_is_on(void) |
| 534 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 535 | if (global_trace.trace_buffer.buffer) |
| 536 | return ring_buffer_record_is_on(global_trace.trace_buffer.buffer); |
Steven Rostedt | 499e547 | 2012-02-22 15:50:28 -0500 | [diff] [blame] | 537 | return !global_trace.buffer_disabled; |
| 538 | } |
| 539 | EXPORT_SYMBOL_GPL(tracing_is_on); |
| 540 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 541 | static int __init set_buf_size(char *str) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 542 | { |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 543 | unsigned long buf_size; |
Steven Rostedt | c6caeeb | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 544 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 545 | if (!str) |
| 546 | return 0; |
Li Zefan | 9d612be | 2009-06-24 17:33:15 +0800 | [diff] [blame] | 547 | buf_size = memparse(str, &str); |
Steven Rostedt | c6caeeb | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 548 | /* nr_entries can not be zero */ |
Li Zefan | 9d612be | 2009-06-24 17:33:15 +0800 | [diff] [blame] | 549 | if (buf_size == 0) |
Steven Rostedt | c6caeeb | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 550 | return 0; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 551 | trace_buf_size = buf_size; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 552 | return 1; |
| 553 | } |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 554 | __setup("trace_buf_size=", set_buf_size); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 555 | |
Tim Bird | 0e95017 | 2010-02-25 15:36:43 -0800 | [diff] [blame] | 556 | static int __init set_tracing_thresh(char *str) |
| 557 | { |
Wang Tianhong | 87abb3b | 2012-08-02 14:02:00 +0800 | [diff] [blame] | 558 | unsigned long threshold; |
Tim Bird | 0e95017 | 2010-02-25 15:36:43 -0800 | [diff] [blame] | 559 | int ret; |
| 560 | |
| 561 | if (!str) |
| 562 | return 0; |
Daniel Walter | bcd83ea | 2012-09-26 22:08:38 +0200 | [diff] [blame] | 563 | ret = kstrtoul(str, 0, &threshold); |
Tim Bird | 0e95017 | 2010-02-25 15:36:43 -0800 | [diff] [blame] | 564 | if (ret < 0) |
| 565 | return 0; |
Wang Tianhong | 87abb3b | 2012-08-02 14:02:00 +0800 | [diff] [blame] | 566 | tracing_thresh = threshold * 1000; |
Tim Bird | 0e95017 | 2010-02-25 15:36:43 -0800 | [diff] [blame] | 567 | return 1; |
| 568 | } |
| 569 | __setup("tracing_thresh=", set_tracing_thresh); |
| 570 | |
Steven Rostedt | 57f50be | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 571 | unsigned long nsecs_to_usecs(unsigned long nsecs) |
| 572 | { |
| 573 | return nsecs / 1000; |
| 574 | } |
| 575 | |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 576 | /* These must match the bit postions in trace_iterator_flags */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 577 | static const char *trace_options[] = { |
| 578 | "print-parent", |
| 579 | "sym-offset", |
| 580 | "sym-addr", |
| 581 | "verbose", |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 582 | "raw", |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 583 | "hex", |
Ingo Molnar | cb0f12a | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 584 | "bin", |
Soeren Sandmann Pedersen | 2a2cc8f | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 585 | "block", |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 586 | "stacktrace", |
Ingo Molnar | 5e1607a | 2009-03-05 10:24:48 +0100 | [diff] [blame] | 587 | "trace_printk", |
Steven Rostedt | b2a866f | 2008-11-03 23:15:57 -0500 | [diff] [blame] | 588 | "ftrace_preempt", |
Steven Rostedt | 9f029e8 | 2008-11-12 15:24:24 -0500 | [diff] [blame] | 589 | "branch", |
Steven Rostedt | 12ef7d4 | 2008-11-12 17:52:38 -0500 | [diff] [blame] | 590 | "annotate", |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 591 | "userstacktrace", |
Török Edwin | b54d3de | 2008-11-22 13:28:48 +0200 | [diff] [blame] | 592 | "sym-userobj", |
Frederic Weisbecker | 66896a8 | 2008-12-13 20:18:13 +0100 | [diff] [blame] | 593 | "printk-msg-only", |
Frederic Weisbecker | c4a8e8b | 2009-02-02 20:29:21 -0200 | [diff] [blame] | 594 | "context-info", |
Steven Rostedt | c032ef64 | 2009-03-04 20:34:24 -0500 | [diff] [blame] | 595 | "latency-format", |
Steven Rostedt | be6f164 | 2009-03-24 11:06:24 -0400 | [diff] [blame] | 596 | "sleep-time", |
Steven Rostedt | a2a16d6 | 2009-03-24 23:17:58 -0400 | [diff] [blame] | 597 | "graph-time", |
Li Zefan | e870e9a | 2010-07-02 11:07:32 +0800 | [diff] [blame] | 598 | "record-cmd", |
David Sharp | 750912f | 2010-12-08 13:46:47 -0800 | [diff] [blame] | 599 | "overwrite", |
Steven Rostedt | cf30cf6 | 2011-06-14 22:44:07 -0400 | [diff] [blame] | 600 | "disable_on_free", |
Steven Rostedt | 77271ce | 2011-11-17 09:34:33 -0500 | [diff] [blame] | 601 | "irq-info", |
Mandeep Singh Baines | 5224c3a | 2012-09-07 18:12:19 -0700 | [diff] [blame] | 602 | "markers", |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 603 | NULL |
| 604 | }; |
| 605 | |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 606 | static struct { |
| 607 | u64 (*func)(void); |
| 608 | const char *name; |
David Sharp | 8be0709 | 2012-11-13 12:18:22 -0800 | [diff] [blame] | 609 | int in_ns; /* is this clock in nanoseconds? */ |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 610 | } trace_clocks[] = { |
David Sharp | 8be0709 | 2012-11-13 12:18:22 -0800 | [diff] [blame] | 611 | { trace_clock_local, "local", 1 }, |
| 612 | { trace_clock_global, "global", 1 }, |
| 613 | { trace_clock_counter, "counter", 0 }, |
David Sharp | 8cbd9cc | 2012-11-13 12:18:21 -0800 | [diff] [blame] | 614 | ARCH_TRACE_CLOCKS |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 615 | }; |
| 616 | |
| 617 | int trace_clock_id; |
| 618 | |
jolsa@redhat.com | b63f39e | 2009-09-11 17:29:27 +0200 | [diff] [blame] | 619 | /* |
| 620 | * trace_parser_get_init - gets the buffer for trace parser |
| 621 | */ |
| 622 | int trace_parser_get_init(struct trace_parser *parser, int size) |
| 623 | { |
| 624 | memset(parser, 0, sizeof(*parser)); |
| 625 | |
| 626 | parser->buffer = kmalloc(size, GFP_KERNEL); |
| 627 | if (!parser->buffer) |
| 628 | return 1; |
| 629 | |
| 630 | parser->size = size; |
| 631 | return 0; |
| 632 | } |
| 633 | |
| 634 | /* |
| 635 | * trace_parser_put - frees the buffer for trace parser |
| 636 | */ |
| 637 | void trace_parser_put(struct trace_parser *parser) |
| 638 | { |
| 639 | kfree(parser->buffer); |
| 640 | } |
| 641 | |
| 642 | /* |
| 643 | * trace_get_user - reads the user input string separated by space |
| 644 | * (matched by isspace(ch)) |
| 645 | * |
| 646 | * For each string found the 'struct trace_parser' is updated, |
| 647 | * and the function returns. |
| 648 | * |
| 649 | * Returns number of bytes read. |
| 650 | * |
| 651 | * See kernel/trace/trace.h for 'struct trace_parser' details. |
| 652 | */ |
| 653 | int trace_get_user(struct trace_parser *parser, const char __user *ubuf, |
| 654 | size_t cnt, loff_t *ppos) |
| 655 | { |
| 656 | char ch; |
| 657 | size_t read = 0; |
| 658 | ssize_t ret; |
| 659 | |
| 660 | if (!*ppos) |
| 661 | trace_parser_clear(parser); |
| 662 | |
| 663 | ret = get_user(ch, ubuf++); |
| 664 | if (ret) |
| 665 | goto out; |
| 666 | |
| 667 | read++; |
| 668 | cnt--; |
| 669 | |
| 670 | /* |
| 671 | * The parser is not finished with the last write, |
| 672 | * continue reading the user input without skipping spaces. |
| 673 | */ |
| 674 | if (!parser->cont) { |
| 675 | /* skip white space */ |
| 676 | while (cnt && isspace(ch)) { |
| 677 | ret = get_user(ch, ubuf++); |
| 678 | if (ret) |
| 679 | goto out; |
| 680 | read++; |
| 681 | cnt--; |
| 682 | } |
| 683 | |
| 684 | /* only spaces were written */ |
| 685 | if (isspace(ch)) { |
| 686 | *ppos += read; |
| 687 | ret = read; |
| 688 | goto out; |
| 689 | } |
| 690 | |
| 691 | parser->idx = 0; |
| 692 | } |
| 693 | |
| 694 | /* read the non-space input */ |
| 695 | while (cnt && !isspace(ch)) { |
Li Zefan | 3c235a3 | 2009-09-22 13:51:54 +0800 | [diff] [blame] | 696 | if (parser->idx < parser->size - 1) |
jolsa@redhat.com | b63f39e | 2009-09-11 17:29:27 +0200 | [diff] [blame] | 697 | parser->buffer[parser->idx++] = ch; |
| 698 | else { |
| 699 | ret = -EINVAL; |
| 700 | goto out; |
| 701 | } |
| 702 | ret = get_user(ch, ubuf++); |
| 703 | if (ret) |
| 704 | goto out; |
| 705 | read++; |
| 706 | cnt--; |
| 707 | } |
| 708 | |
| 709 | /* We either got finished input or we have to wait for another call. */ |
| 710 | if (isspace(ch)) { |
| 711 | parser->buffer[parser->idx] = 0; |
| 712 | parser->cont = false; |
| 713 | } else { |
| 714 | parser->cont = true; |
| 715 | parser->buffer[parser->idx++] = ch; |
| 716 | } |
| 717 | |
| 718 | *ppos += read; |
| 719 | ret = read; |
| 720 | |
| 721 | out: |
| 722 | return ret; |
| 723 | } |
| 724 | |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 725 | ssize_t trace_seq_to_user(struct trace_seq *s, char __user *ubuf, size_t cnt) |
| 726 | { |
| 727 | int len; |
| 728 | int ret; |
| 729 | |
Steven Rostedt | 2dc5d12 | 2009-03-04 19:10:05 -0500 | [diff] [blame] | 730 | if (!cnt) |
| 731 | return 0; |
| 732 | |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 733 | if (s->len <= s->readpos) |
| 734 | return -EBUSY; |
| 735 | |
| 736 | len = s->len - s->readpos; |
| 737 | if (cnt > len) |
| 738 | cnt = len; |
| 739 | ret = copy_to_user(ubuf, s->buffer + s->readpos, cnt); |
Steven Rostedt | 2dc5d12 | 2009-03-04 19:10:05 -0500 | [diff] [blame] | 740 | if (ret == cnt) |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 741 | return -EFAULT; |
| 742 | |
Steven Rostedt | 2dc5d12 | 2009-03-04 19:10:05 -0500 | [diff] [blame] | 743 | cnt -= ret; |
| 744 | |
Steven Rostedt | e74da52 | 2009-03-04 20:31:11 -0500 | [diff] [blame] | 745 | s->readpos += cnt; |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 746 | return cnt; |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 747 | } |
| 748 | |
Dmitri Vorobiev | b8b9426 | 2009-03-22 19:11:11 +0200 | [diff] [blame] | 749 | 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] | 750 | { |
| 751 | int len; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 752 | |
| 753 | if (s->len <= s->readpos) |
| 754 | return -EBUSY; |
| 755 | |
| 756 | len = s->len - s->readpos; |
| 757 | if (cnt > len) |
| 758 | cnt = len; |
Dan Carpenter | 5a26c8f | 2012-04-20 09:31:45 +0300 | [diff] [blame] | 759 | memcpy(buf, s->buffer + s->readpos, cnt); |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 760 | |
Steven Rostedt | e74da52 | 2009-03-04 20:31:11 -0500 | [diff] [blame] | 761 | s->readpos += cnt; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 762 | return cnt; |
| 763 | } |
| 764 | |
Steven Rostedt | 5d4a9db | 2009-08-27 16:52:21 -0400 | [diff] [blame] | 765 | /* |
| 766 | * ftrace_max_lock is used to protect the swapping of buffers |
| 767 | * when taking a max snapshot. The buffers themselves are |
| 768 | * protected by per_cpu spinlocks. But the action of the swap |
| 769 | * needs its own lock. |
| 770 | * |
Thomas Gleixner | 445c895 | 2009-12-02 19:49:50 +0100 | [diff] [blame] | 771 | * This is defined as a arch_spinlock_t in order to help |
Steven Rostedt | 5d4a9db | 2009-08-27 16:52:21 -0400 | [diff] [blame] | 772 | * with performance when lockdep debugging is enabled. |
| 773 | * |
| 774 | * It is also used in other places outside the update_max_tr |
| 775 | * so it needs to be defined outside of the |
| 776 | * CONFIG_TRACER_MAX_TRACE. |
| 777 | */ |
Thomas Gleixner | 445c895 | 2009-12-02 19:49:50 +0100 | [diff] [blame] | 778 | static arch_spinlock_t ftrace_max_lock = |
Thomas Gleixner | edc35bd | 2009-12-03 12:38:57 +0100 | [diff] [blame] | 779 | (arch_spinlock_t)__ARCH_SPIN_LOCK_UNLOCKED; |
Steven Rostedt | 5d4a9db | 2009-08-27 16:52:21 -0400 | [diff] [blame] | 780 | |
Tim Bird | 0e95017 | 2010-02-25 15:36:43 -0800 | [diff] [blame] | 781 | unsigned long __read_mostly tracing_thresh; |
| 782 | |
Steven Rostedt | 5d4a9db | 2009-08-27 16:52:21 -0400 | [diff] [blame] | 783 | #ifdef CONFIG_TRACER_MAX_TRACE |
| 784 | unsigned long __read_mostly tracing_max_latency; |
Steven Rostedt | 5d4a9db | 2009-08-27 16:52:21 -0400 | [diff] [blame] | 785 | |
| 786 | /* |
| 787 | * Copy the new maximum trace into the separate maximum-trace |
| 788 | * structure. (this way the maximum trace is permanently saved, |
| 789 | * for later retrieval via /sys/kernel/debug/tracing/latency_trace) |
| 790 | */ |
| 791 | static void |
| 792 | __update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu) |
| 793 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 794 | struct trace_buffer *trace_buf = &tr->trace_buffer; |
| 795 | struct trace_buffer *max_buf = &tr->max_buffer; |
| 796 | struct trace_array_cpu *data = per_cpu_ptr(trace_buf->data, cpu); |
| 797 | 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] | 798 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 799 | max_buf->cpu = cpu; |
| 800 | max_buf->time_start = data->preempt_timestamp; |
Steven Rostedt | 5d4a9db | 2009-08-27 16:52:21 -0400 | [diff] [blame] | 801 | |
Steven Rostedt | 8248ac0 | 2009-09-02 12:27:41 -0400 | [diff] [blame] | 802 | max_data->saved_latency = tracing_max_latency; |
| 803 | max_data->critical_start = data->critical_start; |
| 804 | max_data->critical_end = data->critical_end; |
Steven Rostedt | 5d4a9db | 2009-08-27 16:52:21 -0400 | [diff] [blame] | 805 | |
Arnaldo Carvalho de Melo | 1acaa1b | 2010-03-05 18:23:50 -0300 | [diff] [blame] | 806 | memcpy(max_data->comm, tsk->comm, TASK_COMM_LEN); |
Steven Rostedt | 8248ac0 | 2009-09-02 12:27:41 -0400 | [diff] [blame] | 807 | max_data->pid = tsk->pid; |
| 808 | max_data->uid = task_uid(tsk); |
| 809 | max_data->nice = tsk->static_prio - 20 - MAX_RT_PRIO; |
| 810 | max_data->policy = tsk->policy; |
| 811 | max_data->rt_priority = tsk->rt_priority; |
Steven Rostedt | 5d4a9db | 2009-08-27 16:52:21 -0400 | [diff] [blame] | 812 | |
| 813 | /* record this tasks comm */ |
| 814 | tracing_record_cmdline(tsk); |
| 815 | } |
| 816 | |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 817 | /** |
| 818 | * update_max_tr - snapshot all trace buffers from global_trace to max_tr |
| 819 | * @tr: tracer |
| 820 | * @tsk: the task with the latency |
| 821 | * @cpu: The cpu that initiated the trace. |
| 822 | * |
| 823 | * Flip the buffers between the @tr and the max_tr and record information |
| 824 | * about which task was the cause of this latency. |
| 825 | */ |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 826 | void |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 827 | update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu) |
| 828 | { |
Steven Rostedt (Red Hat) | 2721e72 | 2013-03-12 11:32:32 -0400 | [diff] [blame] | 829 | struct ring_buffer *buf; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 830 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 831 | if (tr->stop_count) |
Steven Rostedt | b8de7bd1 | 2009-08-31 22:32:27 -0400 | [diff] [blame] | 832 | return; |
| 833 | |
Steven Rostedt | 4c11d7a | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 834 | WARN_ON_ONCE(!irqs_disabled()); |
Steven Rostedt | 34600f0 | 2013-01-22 13:35:11 -0500 | [diff] [blame] | 835 | |
Steven Rostedt (Red Hat) | 45ad21c | 2013-03-05 18:25:02 -0500 | [diff] [blame] | 836 | if (!tr->allocated_snapshot) { |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 837 | /* Only the nop tracer should hit this when disabling */ |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 838 | WARN_ON_ONCE(tr->current_trace != &nop_trace); |
KOSAKI Motohiro | ef710e1 | 2010-07-01 14:34:35 +0900 | [diff] [blame] | 839 | return; |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 840 | } |
Steven Rostedt | 34600f0 | 2013-01-22 13:35:11 -0500 | [diff] [blame] | 841 | |
Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 842 | arch_spin_lock(&ftrace_max_lock); |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 843 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 844 | buf = tr->trace_buffer.buffer; |
| 845 | tr->trace_buffer.buffer = tr->max_buffer.buffer; |
| 846 | tr->max_buffer.buffer = buf; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 847 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 848 | __update_max_tr(tr, tsk, cpu); |
Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 849 | arch_spin_unlock(&ftrace_max_lock); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 850 | } |
| 851 | |
| 852 | /** |
| 853 | * update_max_tr_single - only copy one trace over, and reset the rest |
| 854 | * @tr - tracer |
| 855 | * @tsk - task with the latency |
| 856 | * @cpu - the cpu of the buffer to copy. |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 857 | * |
| 858 | * 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] | 859 | */ |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 860 | void |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 861 | update_max_tr_single(struct trace_array *tr, struct task_struct *tsk, int cpu) |
| 862 | { |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 863 | int ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 864 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 865 | if (tr->stop_count) |
Steven Rostedt | b8de7bd1 | 2009-08-31 22:32:27 -0400 | [diff] [blame] | 866 | return; |
| 867 | |
Steven Rostedt | 4c11d7a | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 868 | WARN_ON_ONCE(!irqs_disabled()); |
Steven Rostedt (Red Hat) | 45ad21c | 2013-03-05 18:25:02 -0500 | [diff] [blame] | 869 | if (WARN_ON_ONCE(!tr->allocated_snapshot)) |
KOSAKI Motohiro | ef710e1 | 2010-07-01 14:34:35 +0900 | [diff] [blame] | 870 | return; |
KOSAKI Motohiro | ef710e1 | 2010-07-01 14:34:35 +0900 | [diff] [blame] | 871 | |
Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 872 | arch_spin_lock(&ftrace_max_lock); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 873 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 874 | 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] | 875 | |
Steven Rostedt | e8165dbb | 2009-09-03 19:13:05 -0400 | [diff] [blame] | 876 | if (ret == -EBUSY) { |
| 877 | /* |
| 878 | * We failed to swap the buffer due to a commit taking |
| 879 | * place on this CPU. We fail to record, but we reset |
| 880 | * the max trace buffer (no one writes directly to it) |
| 881 | * and flag that it failed. |
| 882 | */ |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 883 | trace_array_printk_buf(tr->max_buffer.buffer, _THIS_IP_, |
Steven Rostedt | e8165dbb | 2009-09-03 19:13:05 -0400 | [diff] [blame] | 884 | "Failed to swap buffers due to commit in progress\n"); |
| 885 | } |
| 886 | |
Steven Rostedt | e8165dbb | 2009-09-03 19:13:05 -0400 | [diff] [blame] | 887 | WARN_ON_ONCE(ret && ret != -EAGAIN && ret != -EBUSY); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 888 | |
| 889 | __update_max_tr(tr, tsk, cpu); |
Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 890 | arch_spin_unlock(&ftrace_max_lock); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 891 | } |
Steven Rostedt | 5d4a9db | 2009-08-27 16:52:21 -0400 | [diff] [blame] | 892 | #endif /* CONFIG_TRACER_MAX_TRACE */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 893 | |
Steven Rostedt | 0d5c6e1 | 2012-11-01 20:54:21 -0400 | [diff] [blame] | 894 | static void default_wait_pipe(struct trace_iterator *iter) |
| 895 | { |
Steven Rostedt (Red Hat) | 1569345 | 2013-02-28 19:59:17 -0500 | [diff] [blame] | 896 | /* Iterators are static, they should be filled or empty */ |
| 897 | if (trace_buffer_iter(iter, iter->cpu_file)) |
| 898 | return; |
Steven Rostedt | 0d5c6e1 | 2012-11-01 20:54:21 -0400 | [diff] [blame] | 899 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 900 | ring_buffer_wait(iter->trace_buffer->buffer, iter->cpu_file); |
Steven Rostedt | 0d5c6e1 | 2012-11-01 20:54:21 -0400 | [diff] [blame] | 901 | } |
| 902 | |
Steven Rostedt (Red Hat) | f4e781c | 2013-03-07 11:10:56 -0500 | [diff] [blame] | 903 | #ifdef CONFIG_FTRACE_STARTUP_TEST |
| 904 | static int run_tracer_selftest(struct tracer *type) |
| 905 | { |
| 906 | struct trace_array *tr = &global_trace; |
| 907 | struct tracer *saved_tracer = tr->current_trace; |
| 908 | int ret; |
| 909 | |
| 910 | if (!type->selftest || tracing_selftest_disabled) |
| 911 | return 0; |
| 912 | |
| 913 | /* |
| 914 | * Run a selftest on this tracer. |
| 915 | * Here we reset the trace buffer, and set the current |
| 916 | * tracer to be this tracer. The tracer can then run some |
| 917 | * internal tracing to verify that everything is in order. |
| 918 | * If we fail, we do not register this tracer. |
| 919 | */ |
| 920 | tracing_reset_online_cpus(&tr->trace_buffer); |
| 921 | |
| 922 | tr->current_trace = type; |
| 923 | |
| 924 | #ifdef CONFIG_TRACER_MAX_TRACE |
| 925 | if (type->use_max_tr) { |
| 926 | /* If we expanded the buffers, make sure the max is expanded too */ |
| 927 | if (ring_buffer_expanded) |
| 928 | ring_buffer_resize(tr->max_buffer.buffer, trace_buf_size, |
| 929 | RING_BUFFER_ALL_CPUS); |
| 930 | tr->allocated_snapshot = true; |
| 931 | } |
| 932 | #endif |
| 933 | |
| 934 | /* the test is responsible for initializing and enabling */ |
| 935 | pr_info("Testing tracer %s: ", type->name); |
| 936 | ret = type->selftest(type, tr); |
| 937 | /* the test is responsible for resetting too */ |
| 938 | tr->current_trace = saved_tracer; |
| 939 | if (ret) { |
| 940 | printk(KERN_CONT "FAILED!\n"); |
| 941 | /* Add the warning after printing 'FAILED' */ |
| 942 | WARN_ON(1); |
| 943 | return -1; |
| 944 | } |
| 945 | /* Only reset on passing, to avoid touching corrupted buffers */ |
| 946 | tracing_reset_online_cpus(&tr->trace_buffer); |
| 947 | |
| 948 | #ifdef CONFIG_TRACER_MAX_TRACE |
| 949 | if (type->use_max_tr) { |
| 950 | tr->allocated_snapshot = false; |
| 951 | |
| 952 | /* Shrink the max buffer again */ |
| 953 | if (ring_buffer_expanded) |
| 954 | ring_buffer_resize(tr->max_buffer.buffer, 1, |
| 955 | RING_BUFFER_ALL_CPUS); |
| 956 | } |
| 957 | #endif |
| 958 | |
| 959 | printk(KERN_CONT "PASSED\n"); |
| 960 | return 0; |
| 961 | } |
| 962 | #else |
| 963 | static inline int run_tracer_selftest(struct tracer *type) |
| 964 | { |
| 965 | return 0; |
| 966 | } |
| 967 | #endif /* CONFIG_FTRACE_STARTUP_TEST */ |
| 968 | |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 969 | /** |
| 970 | * register_tracer - register a tracer with the ftrace system. |
| 971 | * @type - the plugin for the tracer |
| 972 | * |
| 973 | * Register a new plugin tracer. |
| 974 | */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 975 | int register_tracer(struct tracer *type) |
| 976 | { |
| 977 | struct tracer *t; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 978 | int ret = 0; |
| 979 | |
| 980 | if (!type->name) { |
| 981 | pr_info("Tracer must have a name\n"); |
| 982 | return -1; |
| 983 | } |
| 984 | |
Dan Carpenter | 24a461d | 2010-07-10 12:06:44 +0200 | [diff] [blame] | 985 | if (strlen(type->name) >= MAX_TRACER_SIZE) { |
Li Zefan | ee6c2c1 | 2009-09-18 14:06:47 +0800 | [diff] [blame] | 986 | pr_info("Tracer has a name longer than %d\n", MAX_TRACER_SIZE); |
| 987 | return -1; |
| 988 | } |
| 989 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 990 | mutex_lock(&trace_types_lock); |
Ingo Molnar | 86fa2f6 | 2008-11-19 10:00:15 +0100 | [diff] [blame] | 991 | |
Frederic Weisbecker | 8e1b82e | 2008-12-06 03:41:33 +0100 | [diff] [blame] | 992 | tracing_selftest_running = true; |
| 993 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 994 | for (t = trace_types; t; t = t->next) { |
| 995 | if (strcmp(type->name, t->name) == 0) { |
| 996 | /* already found */ |
Li Zefan | ee6c2c1 | 2009-09-18 14:06:47 +0800 | [diff] [blame] | 997 | pr_info("Tracer %s already registered\n", |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 998 | type->name); |
| 999 | ret = -1; |
| 1000 | goto out; |
| 1001 | } |
| 1002 | } |
| 1003 | |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 1004 | if (!type->set_flag) |
| 1005 | type->set_flag = &dummy_set_flag; |
| 1006 | if (!type->flags) |
| 1007 | type->flags = &dummy_tracer_flags; |
| 1008 | else |
| 1009 | if (!type->flags->opts) |
| 1010 | type->flags->opts = dummy_tracer_opt; |
Frederic Weisbecker | 6eaaa5d | 2009-02-11 02:25:00 +0100 | [diff] [blame] | 1011 | if (!type->wait_pipe) |
| 1012 | type->wait_pipe = default_wait_pipe; |
| 1013 | |
Steven Rostedt (Red Hat) | f4e781c | 2013-03-07 11:10:56 -0500 | [diff] [blame] | 1014 | ret = run_tracer_selftest(type); |
| 1015 | if (ret < 0) |
| 1016 | goto out; |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 1017 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1018 | type->next = trace_types; |
| 1019 | trace_types = type; |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 1020 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1021 | out: |
Frederic Weisbecker | 8e1b82e | 2008-12-06 03:41:33 +0100 | [diff] [blame] | 1022 | tracing_selftest_running = false; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1023 | mutex_unlock(&trace_types_lock); |
| 1024 | |
Steven Rostedt | dac7494 | 2009-02-05 01:13:38 -0500 | [diff] [blame] | 1025 | if (ret || !default_bootup_tracer) |
| 1026 | goto out_unlock; |
Steven Rostedt | b2821ae | 2009-02-02 21:38:32 -0500 | [diff] [blame] | 1027 | |
Li Zefan | ee6c2c1 | 2009-09-18 14:06:47 +0800 | [diff] [blame] | 1028 | if (strncmp(default_bootup_tracer, type->name, MAX_TRACER_SIZE)) |
Steven Rostedt | dac7494 | 2009-02-05 01:13:38 -0500 | [diff] [blame] | 1029 | goto out_unlock; |
| 1030 | |
| 1031 | printk(KERN_INFO "Starting tracer '%s'\n", type->name); |
| 1032 | /* Do we want this tracer to start on bootup? */ |
| 1033 | tracing_set_tracer(type->name); |
| 1034 | default_bootup_tracer = NULL; |
| 1035 | /* disable other selftests, since this will break it. */ |
Steven Rostedt (Red Hat) | 55034cd | 2013-03-07 22:48:09 -0500 | [diff] [blame] | 1036 | tracing_selftest_disabled = true; |
Steven Rostedt | dac7494 | 2009-02-05 01:13:38 -0500 | [diff] [blame] | 1037 | #ifdef CONFIG_FTRACE_STARTUP_TEST |
| 1038 | printk(KERN_INFO "Disabling FTRACE selftests due to running tracer '%s'\n", |
| 1039 | type->name); |
| 1040 | #endif |
| 1041 | |
| 1042 | out_unlock: |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1043 | return ret; |
| 1044 | } |
| 1045 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1046 | void tracing_reset(struct trace_buffer *buf, int cpu) |
Steven Rostedt | f633903 | 2009-09-04 12:35:16 -0400 | [diff] [blame] | 1047 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1048 | struct ring_buffer *buffer = buf->buffer; |
Steven Rostedt | f633903 | 2009-09-04 12:35:16 -0400 | [diff] [blame] | 1049 | |
Hiraku Toyooka | a541641 | 2012-12-19 16:02:34 +0900 | [diff] [blame] | 1050 | if (!buffer) |
| 1051 | return; |
| 1052 | |
Steven Rostedt | f633903 | 2009-09-04 12:35:16 -0400 | [diff] [blame] | 1053 | ring_buffer_record_disable(buffer); |
| 1054 | |
| 1055 | /* Make sure all commits have finished */ |
| 1056 | synchronize_sched(); |
Steven Rostedt | 6817968 | 2012-05-08 20:57:53 -0400 | [diff] [blame] | 1057 | ring_buffer_reset_cpu(buffer, cpu); |
Steven Rostedt | f633903 | 2009-09-04 12:35:16 -0400 | [diff] [blame] | 1058 | |
| 1059 | ring_buffer_record_enable(buffer); |
| 1060 | } |
| 1061 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1062 | void tracing_reset_online_cpus(struct trace_buffer *buf) |
Pekka J Enberg | 213cc06 | 2008-12-19 12:08:39 +0200 | [diff] [blame] | 1063 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1064 | struct ring_buffer *buffer = buf->buffer; |
Pekka J Enberg | 213cc06 | 2008-12-19 12:08:39 +0200 | [diff] [blame] | 1065 | int cpu; |
| 1066 | |
Hiraku Toyooka | a541641 | 2012-12-19 16:02:34 +0900 | [diff] [blame] | 1067 | if (!buffer) |
| 1068 | return; |
| 1069 | |
Steven Rostedt | 621968c | 2009-09-04 12:02:35 -0400 | [diff] [blame] | 1070 | ring_buffer_record_disable(buffer); |
| 1071 | |
| 1072 | /* Make sure all commits have finished */ |
| 1073 | synchronize_sched(); |
| 1074 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1075 | buf->time_start = ftrace_now(buf->cpu); |
Pekka J Enberg | 213cc06 | 2008-12-19 12:08:39 +0200 | [diff] [blame] | 1076 | |
| 1077 | for_each_online_cpu(cpu) |
Steven Rostedt | 6817968 | 2012-05-08 20:57:53 -0400 | [diff] [blame] | 1078 | ring_buffer_reset_cpu(buffer, cpu); |
Steven Rostedt | 621968c | 2009-09-04 12:02:35 -0400 | [diff] [blame] | 1079 | |
| 1080 | ring_buffer_record_enable(buffer); |
Pekka J Enberg | 213cc06 | 2008-12-19 12:08:39 +0200 | [diff] [blame] | 1081 | } |
| 1082 | |
Steven Rostedt | 9456f0f | 2009-05-06 21:54:09 -0400 | [diff] [blame] | 1083 | void tracing_reset_current(int cpu) |
| 1084 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1085 | tracing_reset(&global_trace.trace_buffer, cpu); |
Steven Rostedt | 9456f0f | 2009-05-06 21:54:09 -0400 | [diff] [blame] | 1086 | } |
| 1087 | |
Steven Rostedt (Red Hat) | 873c642 | 2013-03-04 23:26:06 -0500 | [diff] [blame] | 1088 | void tracing_reset_all_online_cpus(void) |
Steven Rostedt | 9456f0f | 2009-05-06 21:54:09 -0400 | [diff] [blame] | 1089 | { |
Steven Rostedt (Red Hat) | 873c642 | 2013-03-04 23:26:06 -0500 | [diff] [blame] | 1090 | struct trace_array *tr; |
| 1091 | |
| 1092 | mutex_lock(&trace_types_lock); |
| 1093 | list_for_each_entry(tr, &ftrace_trace_arrays, list) { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1094 | tracing_reset_online_cpus(&tr->trace_buffer); |
| 1095 | #ifdef CONFIG_TRACER_MAX_TRACE |
| 1096 | tracing_reset_online_cpus(&tr->max_buffer); |
| 1097 | #endif |
Steven Rostedt (Red Hat) | 873c642 | 2013-03-04 23:26:06 -0500 | [diff] [blame] | 1098 | } |
| 1099 | mutex_unlock(&trace_types_lock); |
Steven Rostedt | 9456f0f | 2009-05-06 21:54:09 -0400 | [diff] [blame] | 1100 | } |
| 1101 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1102 | #define SAVED_CMDLINES 128 |
Thomas Gleixner | 2c7eea4 | 2009-03-18 09:03:19 +0100 | [diff] [blame] | 1103 | #define NO_CMDLINE_MAP UINT_MAX |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1104 | static unsigned map_pid_to_cmdline[PID_MAX_DEFAULT+1]; |
| 1105 | static unsigned map_cmdline_to_pid[SAVED_CMDLINES]; |
| 1106 | static char saved_cmdlines[SAVED_CMDLINES][TASK_COMM_LEN]; |
| 1107 | static int cmdline_idx; |
Thomas Gleixner | edc35bd | 2009-12-03 12:38:57 +0100 | [diff] [blame] | 1108 | static arch_spinlock_t trace_cmdline_lock = __ARCH_SPIN_LOCK_UNLOCKED; |
Steven Rostedt | 25b0b44 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 1109 | |
Steven Rostedt | 25b0b44 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 1110 | /* temporary disable recording */ |
Hannes Eder | 4fd2735 | 2009-02-10 19:44:12 +0100 | [diff] [blame] | 1111 | static atomic_t trace_record_cmdline_disabled __read_mostly; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1112 | |
| 1113 | static void trace_init_cmdlines(void) |
| 1114 | { |
Thomas Gleixner | 2c7eea4 | 2009-03-18 09:03:19 +0100 | [diff] [blame] | 1115 | memset(&map_pid_to_cmdline, NO_CMDLINE_MAP, sizeof(map_pid_to_cmdline)); |
| 1116 | 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] | 1117 | cmdline_idx = 0; |
| 1118 | } |
| 1119 | |
Carsten Emde | b5130b1 | 2009-09-13 01:43:07 +0200 | [diff] [blame] | 1120 | int is_tracing_stopped(void) |
| 1121 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 1122 | return global_trace.stop_count; |
Carsten Emde | b5130b1 | 2009-09-13 01:43:07 +0200 | [diff] [blame] | 1123 | } |
| 1124 | |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1125 | /** |
Steven Rostedt | 69bb54e | 2008-11-21 12:59:38 -0500 | [diff] [blame] | 1126 | * ftrace_off_permanent - disable all ftrace code permanently |
| 1127 | * |
| 1128 | * This should only be called when a serious anomally has |
| 1129 | * been detected. This will turn off the function tracing, |
| 1130 | * ring buffers, and other tracing utilites. It takes no |
| 1131 | * locks and can be called from any context. |
| 1132 | */ |
| 1133 | void ftrace_off_permanent(void) |
| 1134 | { |
| 1135 | tracing_disabled = 1; |
| 1136 | ftrace_stop(); |
| 1137 | tracing_off_permanent(); |
| 1138 | } |
| 1139 | |
| 1140 | /** |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1141 | * tracing_start - quick start of the tracer |
| 1142 | * |
| 1143 | * If tracing is enabled but was stopped by tracing_stop, |
| 1144 | * this will start the tracer back up. |
| 1145 | */ |
| 1146 | void tracing_start(void) |
| 1147 | { |
| 1148 | struct ring_buffer *buffer; |
| 1149 | unsigned long flags; |
| 1150 | |
| 1151 | if (tracing_disabled) |
| 1152 | return; |
| 1153 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 1154 | raw_spin_lock_irqsave(&global_trace.start_lock, flags); |
| 1155 | if (--global_trace.stop_count) { |
| 1156 | if (global_trace.stop_count < 0) { |
Steven Rostedt | b06a830 | 2009-01-22 14:26:15 -0500 | [diff] [blame] | 1157 | /* Someone screwed up their debugging */ |
| 1158 | WARN_ON_ONCE(1); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 1159 | global_trace.stop_count = 0; |
Steven Rostedt | b06a830 | 2009-01-22 14:26:15 -0500 | [diff] [blame] | 1160 | } |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1161 | goto out; |
| 1162 | } |
| 1163 | |
Steven Rostedt | a2f8071 | 2010-03-12 19:56:00 -0500 | [diff] [blame] | 1164 | /* Prevent the buffers from switching */ |
| 1165 | arch_spin_lock(&ftrace_max_lock); |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1166 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1167 | buffer = global_trace.trace_buffer.buffer; |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1168 | if (buffer) |
| 1169 | ring_buffer_record_enable(buffer); |
| 1170 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1171 | #ifdef CONFIG_TRACER_MAX_TRACE |
| 1172 | buffer = global_trace.max_buffer.buffer; |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1173 | if (buffer) |
| 1174 | ring_buffer_record_enable(buffer); |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1175 | #endif |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1176 | |
Steven Rostedt | a2f8071 | 2010-03-12 19:56:00 -0500 | [diff] [blame] | 1177 | arch_spin_unlock(&ftrace_max_lock); |
| 1178 | |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1179 | ftrace_start(); |
| 1180 | out: |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 1181 | raw_spin_unlock_irqrestore(&global_trace.start_lock, flags); |
| 1182 | } |
| 1183 | |
| 1184 | static void tracing_start_tr(struct trace_array *tr) |
| 1185 | { |
| 1186 | struct ring_buffer *buffer; |
| 1187 | unsigned long flags; |
| 1188 | |
| 1189 | if (tracing_disabled) |
| 1190 | return; |
| 1191 | |
| 1192 | /* If global, we need to also start the max tracer */ |
| 1193 | if (tr->flags & TRACE_ARRAY_FL_GLOBAL) |
| 1194 | return tracing_start(); |
| 1195 | |
| 1196 | raw_spin_lock_irqsave(&tr->start_lock, flags); |
| 1197 | |
| 1198 | if (--tr->stop_count) { |
| 1199 | if (tr->stop_count < 0) { |
| 1200 | /* Someone screwed up their debugging */ |
| 1201 | WARN_ON_ONCE(1); |
| 1202 | tr->stop_count = 0; |
| 1203 | } |
| 1204 | goto out; |
| 1205 | } |
| 1206 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1207 | buffer = tr->trace_buffer.buffer; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 1208 | if (buffer) |
| 1209 | ring_buffer_record_enable(buffer); |
| 1210 | |
| 1211 | out: |
| 1212 | raw_spin_unlock_irqrestore(&tr->start_lock, flags); |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1213 | } |
| 1214 | |
| 1215 | /** |
| 1216 | * tracing_stop - quick stop of the tracer |
| 1217 | * |
| 1218 | * Light weight way to stop tracing. Use in conjunction with |
| 1219 | * tracing_start. |
| 1220 | */ |
| 1221 | void tracing_stop(void) |
| 1222 | { |
| 1223 | struct ring_buffer *buffer; |
| 1224 | unsigned long flags; |
| 1225 | |
| 1226 | ftrace_stop(); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 1227 | raw_spin_lock_irqsave(&global_trace.start_lock, flags); |
| 1228 | if (global_trace.stop_count++) |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1229 | goto out; |
| 1230 | |
Steven Rostedt | a2f8071 | 2010-03-12 19:56:00 -0500 | [diff] [blame] | 1231 | /* Prevent the buffers from switching */ |
| 1232 | arch_spin_lock(&ftrace_max_lock); |
| 1233 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1234 | buffer = global_trace.trace_buffer.buffer; |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1235 | if (buffer) |
| 1236 | ring_buffer_record_disable(buffer); |
| 1237 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1238 | #ifdef CONFIG_TRACER_MAX_TRACE |
| 1239 | buffer = global_trace.max_buffer.buffer; |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1240 | if (buffer) |
| 1241 | ring_buffer_record_disable(buffer); |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1242 | #endif |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1243 | |
Steven Rostedt | a2f8071 | 2010-03-12 19:56:00 -0500 | [diff] [blame] | 1244 | arch_spin_unlock(&ftrace_max_lock); |
| 1245 | |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1246 | out: |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 1247 | raw_spin_unlock_irqrestore(&global_trace.start_lock, flags); |
| 1248 | } |
| 1249 | |
| 1250 | static void tracing_stop_tr(struct trace_array *tr) |
| 1251 | { |
| 1252 | struct ring_buffer *buffer; |
| 1253 | unsigned long flags; |
| 1254 | |
| 1255 | /* If global, we need to also stop the max tracer */ |
| 1256 | if (tr->flags & TRACE_ARRAY_FL_GLOBAL) |
| 1257 | return tracing_stop(); |
| 1258 | |
| 1259 | raw_spin_lock_irqsave(&tr->start_lock, flags); |
| 1260 | if (tr->stop_count++) |
| 1261 | goto out; |
| 1262 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1263 | buffer = tr->trace_buffer.buffer; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 1264 | if (buffer) |
| 1265 | ring_buffer_record_disable(buffer); |
| 1266 | |
| 1267 | out: |
| 1268 | raw_spin_unlock_irqrestore(&tr->start_lock, flags); |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1269 | } |
| 1270 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1271 | void trace_stop_cmdline_recording(void); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1272 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1273 | static void trace_save_cmdline(struct task_struct *tsk) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1274 | { |
Carsten Emde | a635cf0 | 2009-03-18 09:00:41 +0100 | [diff] [blame] | 1275 | unsigned pid, idx; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1276 | |
| 1277 | if (!tsk->pid || unlikely(tsk->pid > PID_MAX_DEFAULT)) |
| 1278 | return; |
| 1279 | |
| 1280 | /* |
| 1281 | * It's not the end of the world if we don't get |
| 1282 | * the lock, but we also don't want to spin |
| 1283 | * nor do we want to disable interrupts, |
| 1284 | * so if we miss here, then better luck next time. |
| 1285 | */ |
Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 1286 | if (!arch_spin_trylock(&trace_cmdline_lock)) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1287 | return; |
| 1288 | |
| 1289 | idx = map_pid_to_cmdline[tsk->pid]; |
Thomas Gleixner | 2c7eea4 | 2009-03-18 09:03:19 +0100 | [diff] [blame] | 1290 | if (idx == NO_CMDLINE_MAP) { |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1291 | idx = (cmdline_idx + 1) % SAVED_CMDLINES; |
| 1292 | |
Carsten Emde | a635cf0 | 2009-03-18 09:00:41 +0100 | [diff] [blame] | 1293 | /* |
| 1294 | * Check whether the cmdline buffer at idx has a pid |
| 1295 | * mapped. We are going to overwrite that entry so we |
| 1296 | * need to clear the map_pid_to_cmdline. Otherwise we |
| 1297 | * would read the new comm for the old pid. |
| 1298 | */ |
| 1299 | pid = map_cmdline_to_pid[idx]; |
| 1300 | if (pid != NO_CMDLINE_MAP) |
| 1301 | map_pid_to_cmdline[pid] = NO_CMDLINE_MAP; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1302 | |
Carsten Emde | a635cf0 | 2009-03-18 09:00:41 +0100 | [diff] [blame] | 1303 | map_cmdline_to_pid[idx] = tsk->pid; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1304 | map_pid_to_cmdline[tsk->pid] = idx; |
| 1305 | |
| 1306 | cmdline_idx = idx; |
| 1307 | } |
| 1308 | |
| 1309 | memcpy(&saved_cmdlines[idx], tsk->comm, TASK_COMM_LEN); |
| 1310 | |
Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 1311 | arch_spin_unlock(&trace_cmdline_lock); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1312 | } |
| 1313 | |
Steven Rostedt | 4ca53085 | 2009-03-16 19:20:15 -0400 | [diff] [blame] | 1314 | void trace_find_cmdline(int pid, char comm[]) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1315 | { |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1316 | unsigned map; |
| 1317 | |
Steven Rostedt | 4ca53085 | 2009-03-16 19:20:15 -0400 | [diff] [blame] | 1318 | if (!pid) { |
| 1319 | strcpy(comm, "<idle>"); |
| 1320 | return; |
| 1321 | } |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1322 | |
Steven Rostedt | 74bf407 | 2010-01-25 15:11:53 -0500 | [diff] [blame] | 1323 | if (WARN_ON_ONCE(pid < 0)) { |
| 1324 | strcpy(comm, "<XXX>"); |
| 1325 | return; |
| 1326 | } |
| 1327 | |
Steven Rostedt | 4ca53085 | 2009-03-16 19:20:15 -0400 | [diff] [blame] | 1328 | if (pid > PID_MAX_DEFAULT) { |
| 1329 | strcpy(comm, "<...>"); |
| 1330 | return; |
| 1331 | } |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1332 | |
Heiko Carstens | 5b6045a | 2009-05-26 17:28:02 +0200 | [diff] [blame] | 1333 | preempt_disable(); |
Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 1334 | arch_spin_lock(&trace_cmdline_lock); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1335 | map = map_pid_to_cmdline[pid]; |
Thomas Gleixner | 50d8875 | 2009-03-18 08:58:44 +0100 | [diff] [blame] | 1336 | if (map != NO_CMDLINE_MAP) |
| 1337 | strcpy(comm, saved_cmdlines[map]); |
| 1338 | else |
| 1339 | strcpy(comm, "<...>"); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1340 | |
Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 1341 | arch_spin_unlock(&trace_cmdline_lock); |
Heiko Carstens | 5b6045a | 2009-05-26 17:28:02 +0200 | [diff] [blame] | 1342 | preempt_enable(); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1343 | } |
| 1344 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1345 | void tracing_record_cmdline(struct task_struct *tsk) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1346 | { |
Steven Rostedt | 0fb9656 | 2012-05-11 14:25:30 -0400 | [diff] [blame] | 1347 | if (atomic_read(&trace_record_cmdline_disabled) || !tracing_is_on()) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1348 | return; |
| 1349 | |
Steven Rostedt | 7ffbd48 | 2012-10-11 12:14:25 -0400 | [diff] [blame] | 1350 | if (!__this_cpu_read(trace_cmdline_save)) |
| 1351 | return; |
| 1352 | |
| 1353 | __this_cpu_write(trace_cmdline_save, false); |
| 1354 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1355 | trace_save_cmdline(tsk); |
| 1356 | } |
| 1357 | |
Pekka Paalanen | 45dcd8b | 2008-09-16 21:56:41 +0300 | [diff] [blame] | 1358 | void |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 1359 | tracing_generic_entry_update(struct trace_entry *entry, unsigned long flags, |
| 1360 | int pc) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1361 | { |
| 1362 | struct task_struct *tsk = current; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1363 | |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1364 | entry->preempt_count = pc & 0xff; |
| 1365 | entry->pid = (tsk) ? tsk->pid : 0; |
| 1366 | entry->flags = |
Steven Rostedt | 9244489 | 2008-10-24 09:42:59 -0400 | [diff] [blame] | 1367 | #ifdef CONFIG_TRACE_IRQFLAGS_SUPPORT |
Steven Rostedt | 2e2ca15 | 2008-08-01 12:26:40 -0400 | [diff] [blame] | 1368 | (irqs_disabled_flags(flags) ? TRACE_FLAG_IRQS_OFF : 0) | |
Steven Rostedt | 9244489 | 2008-10-24 09:42:59 -0400 | [diff] [blame] | 1369 | #else |
| 1370 | TRACE_FLAG_IRQS_NOSUPPORT | |
| 1371 | #endif |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1372 | ((pc & HARDIRQ_MASK) ? TRACE_FLAG_HARDIRQ : 0) | |
| 1373 | ((pc & SOFTIRQ_MASK) ? TRACE_FLAG_SOFTIRQ : 0) | |
| 1374 | (need_resched() ? TRACE_FLAG_NEED_RESCHED : 0); |
| 1375 | } |
Frederic Weisbecker | f413cdb | 2009-08-07 01:25:54 +0200 | [diff] [blame] | 1376 | EXPORT_SYMBOL_GPL(tracing_generic_entry_update); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1377 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1378 | struct ring_buffer_event * |
| 1379 | trace_buffer_lock_reserve(struct ring_buffer *buffer, |
| 1380 | int type, |
| 1381 | unsigned long len, |
| 1382 | unsigned long flags, int pc) |
Arnaldo Carvalho de Melo | 51a763d | 2009-02-05 16:14:13 -0200 | [diff] [blame] | 1383 | { |
| 1384 | struct ring_buffer_event *event; |
| 1385 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1386 | event = ring_buffer_lock_reserve(buffer, len); |
Arnaldo Carvalho de Melo | 51a763d | 2009-02-05 16:14:13 -0200 | [diff] [blame] | 1387 | if (event != NULL) { |
| 1388 | struct trace_entry *ent = ring_buffer_event_data(event); |
| 1389 | |
| 1390 | tracing_generic_entry_update(ent, flags, pc); |
| 1391 | ent->type = type; |
| 1392 | } |
| 1393 | |
| 1394 | return event; |
| 1395 | } |
Arnaldo Carvalho de Melo | 51a763d | 2009-02-05 16:14:13 -0200 | [diff] [blame] | 1396 | |
Steven Rostedt | 7ffbd48 | 2012-10-11 12:14:25 -0400 | [diff] [blame] | 1397 | void |
| 1398 | __buffer_unlock_commit(struct ring_buffer *buffer, struct ring_buffer_event *event) |
| 1399 | { |
| 1400 | __this_cpu_write(trace_cmdline_save, true); |
| 1401 | ring_buffer_unlock_commit(buffer, event); |
| 1402 | } |
| 1403 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1404 | static inline void |
| 1405 | __trace_buffer_unlock_commit(struct ring_buffer *buffer, |
| 1406 | struct ring_buffer_event *event, |
Steven Rostedt | 0d5c6e1 | 2012-11-01 20:54:21 -0400 | [diff] [blame] | 1407 | unsigned long flags, int pc) |
Arnaldo Carvalho de Melo | 51a763d | 2009-02-05 16:14:13 -0200 | [diff] [blame] | 1408 | { |
Steven Rostedt | 7ffbd48 | 2012-10-11 12:14:25 -0400 | [diff] [blame] | 1409 | __buffer_unlock_commit(buffer, event); |
Arnaldo Carvalho de Melo | 51a763d | 2009-02-05 16:14:13 -0200 | [diff] [blame] | 1410 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1411 | ftrace_trace_stack(buffer, flags, 6, pc); |
| 1412 | ftrace_trace_userstack(buffer, flags, pc); |
Frederic Weisbecker | 07edf71 | 2009-03-22 23:10:46 +0100 | [diff] [blame] | 1413 | } |
| 1414 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1415 | void trace_buffer_unlock_commit(struct ring_buffer *buffer, |
| 1416 | struct ring_buffer_event *event, |
| 1417 | unsigned long flags, int pc) |
Frederic Weisbecker | 07edf71 | 2009-03-22 23:10:46 +0100 | [diff] [blame] | 1418 | { |
Steven Rostedt | 0d5c6e1 | 2012-11-01 20:54:21 -0400 | [diff] [blame] | 1419 | __trace_buffer_unlock_commit(buffer, event, flags, pc); |
Arnaldo Carvalho de Melo | 51a763d | 2009-02-05 16:14:13 -0200 | [diff] [blame] | 1420 | } |
Steven Rostedt | 0d5c6e1 | 2012-11-01 20:54:21 -0400 | [diff] [blame] | 1421 | EXPORT_SYMBOL_GPL(trace_buffer_unlock_commit); |
Arnaldo Carvalho de Melo | 51a763d | 2009-02-05 16:14:13 -0200 | [diff] [blame] | 1422 | |
Steven Rostedt | ef5580d | 2009-02-27 19:38:04 -0500 | [diff] [blame] | 1423 | struct ring_buffer_event * |
Steven Rostedt | ccb469a | 2012-08-02 10:32:10 -0400 | [diff] [blame] | 1424 | trace_event_buffer_lock_reserve(struct ring_buffer **current_rb, |
| 1425 | struct ftrace_event_file *ftrace_file, |
| 1426 | int type, unsigned long len, |
| 1427 | unsigned long flags, int pc) |
| 1428 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1429 | *current_rb = ftrace_file->tr->trace_buffer.buffer; |
Steven Rostedt | ccb469a | 2012-08-02 10:32:10 -0400 | [diff] [blame] | 1430 | return trace_buffer_lock_reserve(*current_rb, |
| 1431 | type, len, flags, pc); |
| 1432 | } |
| 1433 | EXPORT_SYMBOL_GPL(trace_event_buffer_lock_reserve); |
| 1434 | |
| 1435 | struct ring_buffer_event * |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1436 | trace_current_buffer_lock_reserve(struct ring_buffer **current_rb, |
| 1437 | int type, unsigned long len, |
Steven Rostedt | ef5580d | 2009-02-27 19:38:04 -0500 | [diff] [blame] | 1438 | unsigned long flags, int pc) |
| 1439 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1440 | *current_rb = global_trace.trace_buffer.buffer; |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1441 | return trace_buffer_lock_reserve(*current_rb, |
Steven Rostedt | ef5580d | 2009-02-27 19:38:04 -0500 | [diff] [blame] | 1442 | type, len, flags, pc); |
| 1443 | } |
Steven Rostedt | 94487d6 | 2009-05-05 19:22:53 -0400 | [diff] [blame] | 1444 | EXPORT_SYMBOL_GPL(trace_current_buffer_lock_reserve); |
Steven Rostedt | ef5580d | 2009-02-27 19:38:04 -0500 | [diff] [blame] | 1445 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1446 | void trace_current_buffer_unlock_commit(struct ring_buffer *buffer, |
| 1447 | struct ring_buffer_event *event, |
Steven Rostedt | ef5580d | 2009-02-27 19:38:04 -0500 | [diff] [blame] | 1448 | unsigned long flags, int pc) |
| 1449 | { |
Steven Rostedt | 0d5c6e1 | 2012-11-01 20:54:21 -0400 | [diff] [blame] | 1450 | __trace_buffer_unlock_commit(buffer, event, flags, pc); |
Frederic Weisbecker | 07edf71 | 2009-03-22 23:10:46 +0100 | [diff] [blame] | 1451 | } |
Steven Rostedt | 94487d6 | 2009-05-05 19:22:53 -0400 | [diff] [blame] | 1452 | EXPORT_SYMBOL_GPL(trace_current_buffer_unlock_commit); |
Frederic Weisbecker | 07edf71 | 2009-03-22 23:10:46 +0100 | [diff] [blame] | 1453 | |
Steven Rostedt | 0d5c6e1 | 2012-11-01 20:54:21 -0400 | [diff] [blame] | 1454 | void trace_buffer_unlock_commit_regs(struct ring_buffer *buffer, |
| 1455 | struct ring_buffer_event *event, |
| 1456 | unsigned long flags, int pc, |
| 1457 | struct pt_regs *regs) |
Masami Hiramatsu | 1fd8df2 | 2011-06-08 16:09:34 +0900 | [diff] [blame] | 1458 | { |
Steven Rostedt | 7ffbd48 | 2012-10-11 12:14:25 -0400 | [diff] [blame] | 1459 | __buffer_unlock_commit(buffer, event); |
Masami Hiramatsu | 1fd8df2 | 2011-06-08 16:09:34 +0900 | [diff] [blame] | 1460 | |
| 1461 | ftrace_trace_stack_regs(buffer, flags, 0, pc, regs); |
| 1462 | ftrace_trace_userstack(buffer, flags, pc); |
| 1463 | } |
Steven Rostedt | 0d5c6e1 | 2012-11-01 20:54:21 -0400 | [diff] [blame] | 1464 | EXPORT_SYMBOL_GPL(trace_buffer_unlock_commit_regs); |
Masami Hiramatsu | 1fd8df2 | 2011-06-08 16:09:34 +0900 | [diff] [blame] | 1465 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1466 | void trace_current_buffer_discard_commit(struct ring_buffer *buffer, |
| 1467 | struct ring_buffer_event *event) |
Steven Rostedt | 77d9f46 | 2009-04-02 01:16:59 -0400 | [diff] [blame] | 1468 | { |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1469 | ring_buffer_discard_commit(buffer, event); |
Steven Rostedt | ef5580d | 2009-02-27 19:38:04 -0500 | [diff] [blame] | 1470 | } |
Steven Rostedt | 12acd47 | 2009-04-17 16:01:56 -0400 | [diff] [blame] | 1471 | EXPORT_SYMBOL_GPL(trace_current_buffer_discard_commit); |
Steven Rostedt | ef5580d | 2009-02-27 19:38:04 -0500 | [diff] [blame] | 1472 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1473 | void |
Arnaldo Carvalho de Melo | 7be4215 | 2009-02-05 01:13:37 -0500 | [diff] [blame] | 1474 | trace_function(struct trace_array *tr, |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 1475 | unsigned long ip, unsigned long parent_ip, unsigned long flags, |
| 1476 | int pc) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1477 | { |
Tom Zanussi | e1112b4 | 2009-03-31 00:48:49 -0500 | [diff] [blame] | 1478 | struct ftrace_event_call *call = &event_function; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1479 | struct ring_buffer *buffer = tr->trace_buffer.buffer; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1480 | struct ring_buffer_event *event; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1481 | struct ftrace_entry *entry; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1482 | |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 1483 | /* If we are reading the ring buffer, don't trace */ |
Rusty Russell | dd17c8f | 2009-10-29 22:34:15 +0900 | [diff] [blame] | 1484 | if (unlikely(__this_cpu_read(ftrace_cpu_disabled))) |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 1485 | return; |
| 1486 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1487 | event = trace_buffer_lock_reserve(buffer, TRACE_FN, sizeof(*entry), |
Arnaldo Carvalho de Melo | 51a763d | 2009-02-05 16:14:13 -0200 | [diff] [blame] | 1488 | flags, pc); |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1489 | if (!event) |
| 1490 | return; |
| 1491 | entry = ring_buffer_event_data(event); |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1492 | entry->ip = ip; |
| 1493 | entry->parent_ip = parent_ip; |
Tom Zanussi | e1112b4 | 2009-03-31 00:48:49 -0500 | [diff] [blame] | 1494 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1495 | if (!filter_check_discard(call, entry, buffer, event)) |
Steven Rostedt | 7ffbd48 | 2012-10-11 12:14:25 -0400 | [diff] [blame] | 1496 | __buffer_unlock_commit(buffer, event); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1497 | } |
| 1498 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1499 | void |
Ingo Molnar | 2e0f576 | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 1500 | ftrace(struct trace_array *tr, struct trace_array_cpu *data, |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 1501 | unsigned long ip, unsigned long parent_ip, unsigned long flags, |
| 1502 | int pc) |
Ingo Molnar | 2e0f576 | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 1503 | { |
| 1504 | if (likely(!atomic_read(&data->disabled))) |
Arnaldo Carvalho de Melo | 7be4215 | 2009-02-05 01:13:37 -0500 | [diff] [blame] | 1505 | trace_function(tr, ip, parent_ip, flags, pc); |
Ingo Molnar | 2e0f576 | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 1506 | } |
| 1507 | |
Frederic Weisbecker | c0a0d0d | 2009-07-29 17:51:13 +0200 | [diff] [blame] | 1508 | #ifdef CONFIG_STACKTRACE |
Steven Rostedt | 4a9bd3f | 2011-07-14 16:36:53 -0400 | [diff] [blame] | 1509 | |
| 1510 | #define FTRACE_STACK_MAX_ENTRIES (PAGE_SIZE / sizeof(unsigned long)) |
| 1511 | struct ftrace_stack { |
| 1512 | unsigned long calls[FTRACE_STACK_MAX_ENTRIES]; |
| 1513 | }; |
| 1514 | |
| 1515 | static DEFINE_PER_CPU(struct ftrace_stack, ftrace_stack); |
| 1516 | static DEFINE_PER_CPU(int, ftrace_stack_reserve); |
| 1517 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1518 | static void __ftrace_trace_stack(struct ring_buffer *buffer, |
Steven Rostedt | 5361499 | 2009-01-15 19:12:40 -0500 | [diff] [blame] | 1519 | unsigned long flags, |
Masami Hiramatsu | 1fd8df2 | 2011-06-08 16:09:34 +0900 | [diff] [blame] | 1520 | int skip, int pc, struct pt_regs *regs) |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1521 | { |
Tom Zanussi | e1112b4 | 2009-03-31 00:48:49 -0500 | [diff] [blame] | 1522 | struct ftrace_event_call *call = &event_kernel_stack; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1523 | struct ring_buffer_event *event; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1524 | struct stack_entry *entry; |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1525 | struct stack_trace trace; |
Steven Rostedt | 4a9bd3f | 2011-07-14 16:36:53 -0400 | [diff] [blame] | 1526 | int use_stack; |
| 1527 | int size = FTRACE_STACK_ENTRIES; |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1528 | |
| 1529 | trace.nr_entries = 0; |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1530 | trace.skip = skip; |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1531 | |
Steven Rostedt | 4a9bd3f | 2011-07-14 16:36:53 -0400 | [diff] [blame] | 1532 | /* |
| 1533 | * Since events can happen in NMIs there's no safe way to |
| 1534 | * use the per cpu ftrace_stacks. We reserve it and if an interrupt |
| 1535 | * or NMI comes in, it will just have to use the default |
| 1536 | * FTRACE_STACK_SIZE. |
| 1537 | */ |
| 1538 | preempt_disable_notrace(); |
| 1539 | |
Shan Wei | 8214652 | 2012-11-19 13:21:01 +0800 | [diff] [blame] | 1540 | use_stack = __this_cpu_inc_return(ftrace_stack_reserve); |
Steven Rostedt | 4a9bd3f | 2011-07-14 16:36:53 -0400 | [diff] [blame] | 1541 | /* |
| 1542 | * We don't need any atomic variables, just a barrier. |
| 1543 | * If an interrupt comes in, we don't care, because it would |
| 1544 | * have exited and put the counter back to what we want. |
| 1545 | * We just need a barrier to keep gcc from moving things |
| 1546 | * around. |
| 1547 | */ |
| 1548 | barrier(); |
| 1549 | if (use_stack == 1) { |
| 1550 | trace.entries = &__get_cpu_var(ftrace_stack).calls[0]; |
| 1551 | trace.max_entries = FTRACE_STACK_MAX_ENTRIES; |
| 1552 | |
| 1553 | if (regs) |
| 1554 | save_stack_trace_regs(regs, &trace); |
| 1555 | else |
| 1556 | save_stack_trace(&trace); |
| 1557 | |
| 1558 | if (trace.nr_entries > size) |
| 1559 | size = trace.nr_entries; |
| 1560 | } else |
| 1561 | /* From now on, use_stack is a boolean */ |
| 1562 | use_stack = 0; |
| 1563 | |
| 1564 | size *= sizeof(unsigned long); |
| 1565 | |
| 1566 | event = trace_buffer_lock_reserve(buffer, TRACE_STACK, |
| 1567 | sizeof(*entry) + size, flags, pc); |
| 1568 | if (!event) |
| 1569 | goto out; |
| 1570 | entry = ring_buffer_event_data(event); |
| 1571 | |
| 1572 | memset(&entry->caller, 0, size); |
| 1573 | |
| 1574 | if (use_stack) |
| 1575 | memcpy(&entry->caller, trace.entries, |
| 1576 | trace.nr_entries * sizeof(unsigned long)); |
| 1577 | else { |
| 1578 | trace.max_entries = FTRACE_STACK_ENTRIES; |
| 1579 | trace.entries = entry->caller; |
| 1580 | if (regs) |
| 1581 | save_stack_trace_regs(regs, &trace); |
| 1582 | else |
| 1583 | save_stack_trace(&trace); |
| 1584 | } |
| 1585 | |
| 1586 | entry->size = trace.nr_entries; |
| 1587 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1588 | if (!filter_check_discard(call, entry, buffer, event)) |
Steven Rostedt | 7ffbd48 | 2012-10-11 12:14:25 -0400 | [diff] [blame] | 1589 | __buffer_unlock_commit(buffer, event); |
Steven Rostedt | 4a9bd3f | 2011-07-14 16:36:53 -0400 | [diff] [blame] | 1590 | |
| 1591 | out: |
| 1592 | /* Again, don't let gcc optimize things here */ |
| 1593 | barrier(); |
Shan Wei | 8214652 | 2012-11-19 13:21:01 +0800 | [diff] [blame] | 1594 | __this_cpu_dec(ftrace_stack_reserve); |
Steven Rostedt | 4a9bd3f | 2011-07-14 16:36:53 -0400 | [diff] [blame] | 1595 | preempt_enable_notrace(); |
| 1596 | |
Ingo Molnar | f0a920d | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 1597 | } |
| 1598 | |
Masami Hiramatsu | 1fd8df2 | 2011-06-08 16:09:34 +0900 | [diff] [blame] | 1599 | void ftrace_trace_stack_regs(struct ring_buffer *buffer, unsigned long flags, |
| 1600 | int skip, int pc, struct pt_regs *regs) |
| 1601 | { |
| 1602 | if (!(trace_flags & TRACE_ITER_STACKTRACE)) |
| 1603 | return; |
| 1604 | |
| 1605 | __ftrace_trace_stack(buffer, flags, skip, pc, regs); |
| 1606 | } |
| 1607 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1608 | void ftrace_trace_stack(struct ring_buffer *buffer, unsigned long flags, |
| 1609 | int skip, int pc) |
Steven Rostedt | 5361499 | 2009-01-15 19:12:40 -0500 | [diff] [blame] | 1610 | { |
| 1611 | if (!(trace_flags & TRACE_ITER_STACKTRACE)) |
| 1612 | return; |
| 1613 | |
Masami Hiramatsu | 1fd8df2 | 2011-06-08 16:09:34 +0900 | [diff] [blame] | 1614 | __ftrace_trace_stack(buffer, flags, skip, pc, NULL); |
Steven Rostedt | 5361499 | 2009-01-15 19:12:40 -0500 | [diff] [blame] | 1615 | } |
| 1616 | |
Frederic Weisbecker | c0a0d0d | 2009-07-29 17:51:13 +0200 | [diff] [blame] | 1617 | void __trace_stack(struct trace_array *tr, unsigned long flags, int skip, |
| 1618 | int pc) |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 1619 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1620 | __ftrace_trace_stack(tr->trace_buffer.buffer, flags, skip, pc, NULL); |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 1621 | } |
| 1622 | |
Steven Rostedt | 0388938 | 2009-12-11 09:48:22 -0500 | [diff] [blame] | 1623 | /** |
| 1624 | * trace_dump_stack - record a stack back trace in the trace buffer |
| 1625 | */ |
| 1626 | void trace_dump_stack(void) |
| 1627 | { |
| 1628 | unsigned long flags; |
| 1629 | |
| 1630 | if (tracing_disabled || tracing_selftest_running) |
Steven Rostedt | e36c545 | 2009-12-14 15:58:33 -0500 | [diff] [blame] | 1631 | return; |
Steven Rostedt | 0388938 | 2009-12-11 09:48:22 -0500 | [diff] [blame] | 1632 | |
| 1633 | local_save_flags(flags); |
| 1634 | |
| 1635 | /* skipping 3 traces, seems to get us at the caller of this function */ |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1636 | __ftrace_trace_stack(global_trace.trace_buffer.buffer, flags, 3, |
| 1637 | preempt_count(), NULL); |
Steven Rostedt | 0388938 | 2009-12-11 09:48:22 -0500 | [diff] [blame] | 1638 | } |
| 1639 | |
Steven Rostedt | 91e86e5 | 2010-11-10 12:56:12 +0100 | [diff] [blame] | 1640 | static DEFINE_PER_CPU(int, user_stack_count); |
| 1641 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1642 | void |
| 1643 | 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] | 1644 | { |
Tom Zanussi | e1112b4 | 2009-03-31 00:48:49 -0500 | [diff] [blame] | 1645 | struct ftrace_event_call *call = &event_user_stack; |
Török Edwin | 8d7c6a9 | 2008-11-23 12:39:06 +0200 | [diff] [blame] | 1646 | struct ring_buffer_event *event; |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 1647 | struct userstack_entry *entry; |
| 1648 | struct stack_trace trace; |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 1649 | |
| 1650 | if (!(trace_flags & TRACE_ITER_USERSTACKTRACE)) |
| 1651 | return; |
| 1652 | |
Steven Rostedt | b634587 | 2010-03-12 20:03:30 -0500 | [diff] [blame] | 1653 | /* |
| 1654 | * NMIs can not handle page faults, even with fix ups. |
| 1655 | * The save user stack can (and often does) fault. |
| 1656 | */ |
| 1657 | if (unlikely(in_nmi())) |
| 1658 | return; |
| 1659 | |
Steven Rostedt | 91e86e5 | 2010-11-10 12:56:12 +0100 | [diff] [blame] | 1660 | /* |
| 1661 | * prevent recursion, since the user stack tracing may |
| 1662 | * trigger other kernel events. |
| 1663 | */ |
| 1664 | preempt_disable(); |
| 1665 | if (__this_cpu_read(user_stack_count)) |
| 1666 | goto out; |
| 1667 | |
| 1668 | __this_cpu_inc(user_stack_count); |
| 1669 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1670 | event = trace_buffer_lock_reserve(buffer, TRACE_USER_STACK, |
Arnaldo Carvalho de Melo | 51a763d | 2009-02-05 16:14:13 -0200 | [diff] [blame] | 1671 | sizeof(*entry), flags, pc); |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 1672 | if (!event) |
Li Zefan | 1dbd195 | 2010-12-09 15:47:56 +0800 | [diff] [blame] | 1673 | goto out_drop_count; |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 1674 | entry = ring_buffer_event_data(event); |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 1675 | |
Steven Rostedt | 48659d3 | 2009-09-11 11:36:23 -0400 | [diff] [blame] | 1676 | entry->tgid = current->tgid; |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 1677 | memset(&entry->caller, 0, sizeof(entry->caller)); |
| 1678 | |
| 1679 | trace.nr_entries = 0; |
| 1680 | trace.max_entries = FTRACE_STACK_ENTRIES; |
| 1681 | trace.skip = 0; |
| 1682 | trace.entries = entry->caller; |
| 1683 | |
| 1684 | save_stack_trace_user(&trace); |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1685 | if (!filter_check_discard(call, entry, buffer, event)) |
Steven Rostedt | 7ffbd48 | 2012-10-11 12:14:25 -0400 | [diff] [blame] | 1686 | __buffer_unlock_commit(buffer, event); |
Steven Rostedt | 91e86e5 | 2010-11-10 12:56:12 +0100 | [diff] [blame] | 1687 | |
Li Zefan | 1dbd195 | 2010-12-09 15:47:56 +0800 | [diff] [blame] | 1688 | out_drop_count: |
Steven Rostedt | 91e86e5 | 2010-11-10 12:56:12 +0100 | [diff] [blame] | 1689 | __this_cpu_dec(user_stack_count); |
Steven Rostedt | 91e86e5 | 2010-11-10 12:56:12 +0100 | [diff] [blame] | 1690 | out: |
| 1691 | preempt_enable(); |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 1692 | } |
| 1693 | |
Hannes Eder | 4fd2735 | 2009-02-10 19:44:12 +0100 | [diff] [blame] | 1694 | #ifdef UNUSED |
| 1695 | 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] | 1696 | { |
Arnaldo Carvalho de Melo | 7be4215 | 2009-02-05 01:13:37 -0500 | [diff] [blame] | 1697 | ftrace_trace_userstack(tr, flags, preempt_count()); |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 1698 | } |
Hannes Eder | 4fd2735 | 2009-02-10 19:44:12 +0100 | [diff] [blame] | 1699 | #endif /* UNUSED */ |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 1700 | |
Frederic Weisbecker | c0a0d0d | 2009-07-29 17:51:13 +0200 | [diff] [blame] | 1701 | #endif /* CONFIG_STACKTRACE */ |
| 1702 | |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 1703 | /* created for use with alloc_percpu */ |
| 1704 | struct trace_buffer_struct { |
| 1705 | char buffer[TRACE_BUF_SIZE]; |
| 1706 | }; |
| 1707 | |
| 1708 | static struct trace_buffer_struct *trace_percpu_buffer; |
| 1709 | static struct trace_buffer_struct *trace_percpu_sirq_buffer; |
| 1710 | static struct trace_buffer_struct *trace_percpu_irq_buffer; |
| 1711 | static struct trace_buffer_struct *trace_percpu_nmi_buffer; |
| 1712 | |
| 1713 | /* |
| 1714 | * The buffer used is dependent on the context. There is a per cpu |
| 1715 | * buffer for normal context, softirq contex, hard irq context and |
| 1716 | * for NMI context. Thise allows for lockless recording. |
| 1717 | * |
| 1718 | * Note, if the buffers failed to be allocated, then this returns NULL |
| 1719 | */ |
| 1720 | static char *get_trace_buf(void) |
| 1721 | { |
| 1722 | struct trace_buffer_struct *percpu_buffer; |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 1723 | |
| 1724 | /* |
| 1725 | * If we have allocated per cpu buffers, then we do not |
| 1726 | * need to do any locking. |
| 1727 | */ |
| 1728 | if (in_nmi()) |
| 1729 | percpu_buffer = trace_percpu_nmi_buffer; |
| 1730 | else if (in_irq()) |
| 1731 | percpu_buffer = trace_percpu_irq_buffer; |
| 1732 | else if (in_softirq()) |
| 1733 | percpu_buffer = trace_percpu_sirq_buffer; |
| 1734 | else |
| 1735 | percpu_buffer = trace_percpu_buffer; |
| 1736 | |
| 1737 | if (!percpu_buffer) |
| 1738 | return NULL; |
| 1739 | |
Shan Wei | d8a0349 | 2012-11-13 09:53:04 +0800 | [diff] [blame] | 1740 | return this_cpu_ptr(&percpu_buffer->buffer[0]); |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 1741 | } |
| 1742 | |
| 1743 | static int alloc_percpu_trace_buffer(void) |
| 1744 | { |
| 1745 | struct trace_buffer_struct *buffers; |
| 1746 | struct trace_buffer_struct *sirq_buffers; |
| 1747 | struct trace_buffer_struct *irq_buffers; |
| 1748 | struct trace_buffer_struct *nmi_buffers; |
| 1749 | |
| 1750 | buffers = alloc_percpu(struct trace_buffer_struct); |
| 1751 | if (!buffers) |
| 1752 | goto err_warn; |
| 1753 | |
| 1754 | sirq_buffers = alloc_percpu(struct trace_buffer_struct); |
| 1755 | if (!sirq_buffers) |
| 1756 | goto err_sirq; |
| 1757 | |
| 1758 | irq_buffers = alloc_percpu(struct trace_buffer_struct); |
| 1759 | if (!irq_buffers) |
| 1760 | goto err_irq; |
| 1761 | |
| 1762 | nmi_buffers = alloc_percpu(struct trace_buffer_struct); |
| 1763 | if (!nmi_buffers) |
| 1764 | goto err_nmi; |
| 1765 | |
| 1766 | trace_percpu_buffer = buffers; |
| 1767 | trace_percpu_sirq_buffer = sirq_buffers; |
| 1768 | trace_percpu_irq_buffer = irq_buffers; |
| 1769 | trace_percpu_nmi_buffer = nmi_buffers; |
| 1770 | |
| 1771 | return 0; |
| 1772 | |
| 1773 | err_nmi: |
| 1774 | free_percpu(irq_buffers); |
| 1775 | err_irq: |
| 1776 | free_percpu(sirq_buffers); |
| 1777 | err_sirq: |
| 1778 | free_percpu(buffers); |
| 1779 | err_warn: |
| 1780 | WARN(1, "Could not allocate percpu trace_printk buffer"); |
| 1781 | return -ENOMEM; |
| 1782 | } |
| 1783 | |
Steven Rostedt | 8169883 | 2012-10-11 10:15:05 -0400 | [diff] [blame] | 1784 | static int buffers_allocated; |
| 1785 | |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 1786 | void trace_printk_init_buffers(void) |
| 1787 | { |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 1788 | if (buffers_allocated) |
| 1789 | return; |
| 1790 | |
| 1791 | if (alloc_percpu_trace_buffer()) |
| 1792 | return; |
| 1793 | |
| 1794 | pr_info("ftrace: Allocated trace_printk buffers\n"); |
| 1795 | |
Steven Rostedt | b382ede6 | 2012-10-10 21:44:34 -0400 | [diff] [blame] | 1796 | /* Expand the buffers to set size */ |
| 1797 | tracing_update_buffers(); |
| 1798 | |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 1799 | buffers_allocated = 1; |
Steven Rostedt | 8169883 | 2012-10-11 10:15:05 -0400 | [diff] [blame] | 1800 | |
| 1801 | /* |
| 1802 | * trace_printk_init_buffers() can be called by modules. |
| 1803 | * If that happens, then we need to start cmdline recording |
| 1804 | * directly here. If the global_trace.buffer is already |
| 1805 | * allocated here, then this was called by module code. |
| 1806 | */ |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1807 | if (global_trace.trace_buffer.buffer) |
Steven Rostedt | 8169883 | 2012-10-11 10:15:05 -0400 | [diff] [blame] | 1808 | tracing_start_cmdline_record(); |
| 1809 | } |
| 1810 | |
| 1811 | void trace_printk_start_comm(void) |
| 1812 | { |
| 1813 | /* Start tracing comms if trace printk is set */ |
| 1814 | if (!buffers_allocated) |
| 1815 | return; |
| 1816 | tracing_start_cmdline_record(); |
| 1817 | } |
| 1818 | |
| 1819 | static void trace_printk_start_stop_comm(int enabled) |
| 1820 | { |
| 1821 | if (!buffers_allocated) |
| 1822 | return; |
| 1823 | |
| 1824 | if (enabled) |
| 1825 | tracing_start_cmdline_record(); |
| 1826 | else |
| 1827 | tracing_stop_cmdline_record(); |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 1828 | } |
| 1829 | |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 1830 | /** |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 1831 | * trace_vbprintk - write binary msg to tracing buffer |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 1832 | * |
| 1833 | */ |
Steven Rostedt | 40ce74f | 2009-03-19 14:03:53 -0400 | [diff] [blame] | 1834 | int trace_vbprintk(unsigned long ip, const char *fmt, va_list args) |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 1835 | { |
Tom Zanussi | e1112b4 | 2009-03-31 00:48:49 -0500 | [diff] [blame] | 1836 | struct ftrace_event_call *call = &event_bprint; |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 1837 | struct ring_buffer_event *event; |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1838 | struct ring_buffer *buffer; |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 1839 | struct trace_array *tr = &global_trace; |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 1840 | struct bprint_entry *entry; |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 1841 | unsigned long flags; |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 1842 | char *tbuffer; |
| 1843 | int len = 0, size, pc; |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 1844 | |
| 1845 | if (unlikely(tracing_selftest_running || tracing_disabled)) |
| 1846 | return 0; |
| 1847 | |
| 1848 | /* Don't pollute graph traces with trace_vprintk internals */ |
| 1849 | pause_graph_tracing(); |
| 1850 | |
| 1851 | pc = preempt_count(); |
Steven Rostedt | 5168ae5 | 2010-06-03 09:36:50 -0400 | [diff] [blame] | 1852 | preempt_disable_notrace(); |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 1853 | |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 1854 | tbuffer = get_trace_buf(); |
| 1855 | if (!tbuffer) { |
| 1856 | len = 0; |
| 1857 | goto out; |
| 1858 | } |
| 1859 | |
| 1860 | len = vbin_printf((u32 *)tbuffer, TRACE_BUF_SIZE/sizeof(int), fmt, args); |
| 1861 | |
| 1862 | if (len > TRACE_BUF_SIZE/sizeof(int) || len < 0) |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 1863 | goto out; |
| 1864 | |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 1865 | local_save_flags(flags); |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 1866 | size = sizeof(*entry) + sizeof(u32) * len; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1867 | buffer = tr->trace_buffer.buffer; |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1868 | event = trace_buffer_lock_reserve(buffer, TRACE_BPRINT, size, |
| 1869 | flags, pc); |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 1870 | if (!event) |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 1871 | goto out; |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 1872 | entry = ring_buffer_event_data(event); |
| 1873 | entry->ip = ip; |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 1874 | entry->fmt = fmt; |
| 1875 | |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 1876 | memcpy(entry->buf, tbuffer, sizeof(u32) * len); |
Steven Rostedt | d931369 | 2010-01-06 17:27:11 -0500 | [diff] [blame] | 1877 | if (!filter_check_discard(call, entry, buffer, event)) { |
Steven Rostedt | 7ffbd48 | 2012-10-11 12:14:25 -0400 | [diff] [blame] | 1878 | __buffer_unlock_commit(buffer, event); |
Steven Rostedt | d931369 | 2010-01-06 17:27:11 -0500 | [diff] [blame] | 1879 | ftrace_trace_stack(buffer, flags, 6, pc); |
| 1880 | } |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 1881 | |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 1882 | out: |
Steven Rostedt | 5168ae5 | 2010-06-03 09:36:50 -0400 | [diff] [blame] | 1883 | preempt_enable_notrace(); |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 1884 | unpause_graph_tracing(); |
| 1885 | |
| 1886 | return len; |
| 1887 | } |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 1888 | EXPORT_SYMBOL_GPL(trace_vbprintk); |
| 1889 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1890 | static int |
| 1891 | __trace_array_vprintk(struct ring_buffer *buffer, |
| 1892 | unsigned long ip, const char *fmt, va_list args) |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 1893 | { |
Tom Zanussi | e1112b4 | 2009-03-31 00:48:49 -0500 | [diff] [blame] | 1894 | struct ftrace_event_call *call = &event_print; |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 1895 | struct ring_buffer_event *event; |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 1896 | int len = 0, size, pc; |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 1897 | struct print_entry *entry; |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 1898 | unsigned long flags; |
| 1899 | char *tbuffer; |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 1900 | |
| 1901 | if (tracing_disabled || tracing_selftest_running) |
| 1902 | return 0; |
| 1903 | |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 1904 | /* Don't pollute graph traces with trace_vprintk internals */ |
| 1905 | pause_graph_tracing(); |
| 1906 | |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 1907 | pc = preempt_count(); |
| 1908 | preempt_disable_notrace(); |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 1909 | |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 1910 | |
| 1911 | tbuffer = get_trace_buf(); |
| 1912 | if (!tbuffer) { |
| 1913 | len = 0; |
| 1914 | goto out; |
| 1915 | } |
| 1916 | |
| 1917 | len = vsnprintf(tbuffer, TRACE_BUF_SIZE, fmt, args); |
| 1918 | if (len > TRACE_BUF_SIZE) |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 1919 | goto out; |
| 1920 | |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 1921 | local_save_flags(flags); |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 1922 | size = sizeof(*entry) + len + 1; |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1923 | event = trace_buffer_lock_reserve(buffer, TRACE_PRINT, size, |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 1924 | flags, pc); |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 1925 | if (!event) |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 1926 | goto out; |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 1927 | entry = ring_buffer_event_data(event); |
Carsten Emde | c13d2f7 | 2009-11-16 20:56:13 +0100 | [diff] [blame] | 1928 | entry->ip = ip; |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 1929 | |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 1930 | memcpy(&entry->buf, tbuffer, len); |
Carsten Emde | c13d2f7 | 2009-11-16 20:56:13 +0100 | [diff] [blame] | 1931 | entry->buf[len] = '\0'; |
Steven Rostedt | d931369 | 2010-01-06 17:27:11 -0500 | [diff] [blame] | 1932 | if (!filter_check_discard(call, entry, buffer, event)) { |
Steven Rostedt | 7ffbd48 | 2012-10-11 12:14:25 -0400 | [diff] [blame] | 1933 | __buffer_unlock_commit(buffer, event); |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 1934 | ftrace_trace_stack(buffer, flags, 6, pc); |
Steven Rostedt | d931369 | 2010-01-06 17:27:11 -0500 | [diff] [blame] | 1935 | } |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 1936 | out: |
| 1937 | preempt_enable_notrace(); |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 1938 | unpause_graph_tracing(); |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 1939 | |
| 1940 | return len; |
| 1941 | } |
Steven Rostedt | 659372d | 2009-09-03 19:11:07 -0400 | [diff] [blame] | 1942 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1943 | int trace_array_vprintk(struct trace_array *tr, |
| 1944 | unsigned long ip, const char *fmt, va_list args) |
| 1945 | { |
| 1946 | return __trace_array_vprintk(tr->trace_buffer.buffer, ip, fmt, args); |
| 1947 | } |
| 1948 | |
| 1949 | int trace_array_printk(struct trace_array *tr, |
| 1950 | unsigned long ip, const char *fmt, ...) |
| 1951 | { |
| 1952 | int ret; |
| 1953 | va_list ap; |
| 1954 | |
| 1955 | if (!(trace_flags & TRACE_ITER_PRINTK)) |
| 1956 | return 0; |
| 1957 | |
| 1958 | va_start(ap, fmt); |
| 1959 | ret = trace_array_vprintk(tr, ip, fmt, ap); |
| 1960 | va_end(ap); |
| 1961 | return ret; |
| 1962 | } |
| 1963 | |
| 1964 | int trace_array_printk_buf(struct ring_buffer *buffer, |
| 1965 | unsigned long ip, const char *fmt, ...) |
| 1966 | { |
| 1967 | int ret; |
| 1968 | va_list ap; |
| 1969 | |
| 1970 | if (!(trace_flags & TRACE_ITER_PRINTK)) |
| 1971 | return 0; |
| 1972 | |
| 1973 | va_start(ap, fmt); |
| 1974 | ret = __trace_array_vprintk(buffer, ip, fmt, ap); |
| 1975 | va_end(ap); |
| 1976 | return ret; |
| 1977 | } |
| 1978 | |
Steven Rostedt | 659372d | 2009-09-03 19:11:07 -0400 | [diff] [blame] | 1979 | int trace_vprintk(unsigned long ip, const char *fmt, va_list args) |
| 1980 | { |
Steven Rostedt | a813a15 | 2009-10-09 01:41:35 -0400 | [diff] [blame] | 1981 | return trace_array_vprintk(&global_trace, ip, fmt, args); |
Steven Rostedt | 659372d | 2009-09-03 19:11:07 -0400 | [diff] [blame] | 1982 | } |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 1983 | EXPORT_SYMBOL_GPL(trace_vprintk); |
| 1984 | |
Robert Richter | e2ac8ef | 2008-11-12 12:59:32 +0100 | [diff] [blame] | 1985 | static void trace_iterator_increment(struct trace_iterator *iter) |
Steven Rostedt | 5a90f57 | 2008-09-03 17:42:51 -0400 | [diff] [blame] | 1986 | { |
Steven Rostedt | 6d158a8 | 2012-06-27 20:46:14 -0400 | [diff] [blame] | 1987 | struct ring_buffer_iter *buf_iter = trace_buffer_iter(iter, iter->cpu); |
| 1988 | |
Steven Rostedt | 5a90f57 | 2008-09-03 17:42:51 -0400 | [diff] [blame] | 1989 | iter->idx++; |
Steven Rostedt | 6d158a8 | 2012-06-27 20:46:14 -0400 | [diff] [blame] | 1990 | if (buf_iter) |
| 1991 | ring_buffer_read(buf_iter, NULL); |
Steven Rostedt | 5a90f57 | 2008-09-03 17:42:51 -0400 | [diff] [blame] | 1992 | } |
| 1993 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1994 | static struct trace_entry * |
Steven Rostedt | bc21b47 | 2010-03-31 19:49:26 -0400 | [diff] [blame] | 1995 | peek_next_entry(struct trace_iterator *iter, int cpu, u64 *ts, |
| 1996 | unsigned long *lost_events) |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 1997 | { |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1998 | struct ring_buffer_event *event; |
Steven Rostedt | 6d158a8 | 2012-06-27 20:46:14 -0400 | [diff] [blame] | 1999 | struct ring_buffer_iter *buf_iter = trace_buffer_iter(iter, cpu); |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2000 | |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 2001 | if (buf_iter) |
| 2002 | event = ring_buffer_iter_peek(buf_iter, ts); |
| 2003 | else |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2004 | event = ring_buffer_peek(iter->trace_buffer->buffer, cpu, ts, |
Steven Rostedt | bc21b47 | 2010-03-31 19:49:26 -0400 | [diff] [blame] | 2005 | lost_events); |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 2006 | |
Steven Rostedt | 4a9bd3f | 2011-07-14 16:36:53 -0400 | [diff] [blame] | 2007 | if (event) { |
| 2008 | iter->ent_size = ring_buffer_event_length(event); |
| 2009 | return ring_buffer_event_data(event); |
| 2010 | } |
| 2011 | iter->ent_size = 0; |
| 2012 | return NULL; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2013 | } |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 2014 | |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2015 | static struct trace_entry * |
Steven Rostedt | bc21b47 | 2010-03-31 19:49:26 -0400 | [diff] [blame] | 2016 | __find_next_entry(struct trace_iterator *iter, int *ent_cpu, |
| 2017 | unsigned long *missing_events, u64 *ent_ts) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2018 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2019 | struct ring_buffer *buffer = iter->trace_buffer->buffer; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2020 | struct trace_entry *ent, *next = NULL; |
Lai Jiangshan | aa27497 | 2010-04-05 17:11:05 +0800 | [diff] [blame] | 2021 | unsigned long lost_events = 0, next_lost = 0; |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 2022 | int cpu_file = iter->cpu_file; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2023 | u64 next_ts = 0, ts; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2024 | int next_cpu = -1; |
Steven Rostedt | 12b5da3 | 2012-03-27 10:43:28 -0400 | [diff] [blame] | 2025 | int next_size = 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2026 | int cpu; |
| 2027 | |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 2028 | /* |
| 2029 | * If we are in a per_cpu trace file, don't bother by iterating over |
| 2030 | * all cpu and peek directly. |
| 2031 | */ |
Steven Rostedt | ae3b509 | 2013-01-23 15:22:59 -0500 | [diff] [blame] | 2032 | if (cpu_file > RING_BUFFER_ALL_CPUS) { |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 2033 | if (ring_buffer_empty_cpu(buffer, cpu_file)) |
| 2034 | return NULL; |
Steven Rostedt | bc21b47 | 2010-03-31 19:49:26 -0400 | [diff] [blame] | 2035 | ent = peek_next_entry(iter, cpu_file, ent_ts, missing_events); |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 2036 | if (ent_cpu) |
| 2037 | *ent_cpu = cpu_file; |
| 2038 | |
| 2039 | return ent; |
| 2040 | } |
| 2041 | |
Steven Rostedt | ab46428 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 2042 | for_each_tracing_cpu(cpu) { |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2043 | |
| 2044 | if (ring_buffer_empty_cpu(buffer, cpu)) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2045 | continue; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2046 | |
Steven Rostedt | bc21b47 | 2010-03-31 19:49:26 -0400 | [diff] [blame] | 2047 | ent = peek_next_entry(iter, cpu, &ts, &lost_events); |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2048 | |
Ingo Molnar | cdd31cd2 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2049 | /* |
| 2050 | * Pick the entry with the smallest timestamp: |
| 2051 | */ |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2052 | if (ent && (!next || ts < next_ts)) { |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2053 | next = ent; |
| 2054 | next_cpu = cpu; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2055 | next_ts = ts; |
Steven Rostedt | bc21b47 | 2010-03-31 19:49:26 -0400 | [diff] [blame] | 2056 | next_lost = lost_events; |
Steven Rostedt | 12b5da3 | 2012-03-27 10:43:28 -0400 | [diff] [blame] | 2057 | next_size = iter->ent_size; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2058 | } |
| 2059 | } |
| 2060 | |
Steven Rostedt | 12b5da3 | 2012-03-27 10:43:28 -0400 | [diff] [blame] | 2061 | iter->ent_size = next_size; |
| 2062 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2063 | if (ent_cpu) |
| 2064 | *ent_cpu = next_cpu; |
| 2065 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2066 | if (ent_ts) |
| 2067 | *ent_ts = next_ts; |
| 2068 | |
Steven Rostedt | bc21b47 | 2010-03-31 19:49:26 -0400 | [diff] [blame] | 2069 | if (missing_events) |
| 2070 | *missing_events = next_lost; |
| 2071 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2072 | return next; |
| 2073 | } |
| 2074 | |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2075 | /* Find the next real entry, without updating the iterator itself */ |
Frederic Weisbecker | c4a8e8b | 2009-02-02 20:29:21 -0200 | [diff] [blame] | 2076 | struct trace_entry *trace_find_next_entry(struct trace_iterator *iter, |
| 2077 | int *ent_cpu, u64 *ent_ts) |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2078 | { |
Steven Rostedt | bc21b47 | 2010-03-31 19:49:26 -0400 | [diff] [blame] | 2079 | return __find_next_entry(iter, ent_cpu, NULL, ent_ts); |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2080 | } |
Ingo Molnar | 8c523a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2081 | |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2082 | /* 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] | 2083 | void *trace_find_next_entry_inc(struct trace_iterator *iter) |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2084 | { |
Steven Rostedt | bc21b47 | 2010-03-31 19:49:26 -0400 | [diff] [blame] | 2085 | iter->ent = __find_next_entry(iter, &iter->cpu, |
| 2086 | &iter->lost_events, &iter->ts); |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2087 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2088 | if (iter->ent) |
Robert Richter | e2ac8ef | 2008-11-12 12:59:32 +0100 | [diff] [blame] | 2089 | trace_iterator_increment(iter); |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2090 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2091 | return iter->ent ? iter : NULL; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2092 | } |
| 2093 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 2094 | static void trace_consume(struct trace_iterator *iter) |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2095 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2096 | ring_buffer_consume(iter->trace_buffer->buffer, iter->cpu, &iter->ts, |
Steven Rostedt | bc21b47 | 2010-03-31 19:49:26 -0400 | [diff] [blame] | 2097 | &iter->lost_events); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2098 | } |
| 2099 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 2100 | 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] | 2101 | { |
| 2102 | struct trace_iterator *iter = m->private; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2103 | int i = (int)*pos; |
Ingo Molnar | 4e3c333 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 2104 | void *ent; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2105 | |
Steven Rostedt | a63ce5b | 2009-12-07 09:11:39 -0500 | [diff] [blame] | 2106 | WARN_ON_ONCE(iter->leftover); |
| 2107 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2108 | (*pos)++; |
| 2109 | |
| 2110 | /* can't go backwards */ |
| 2111 | if (iter->idx > i) |
| 2112 | return NULL; |
| 2113 | |
| 2114 | if (iter->idx < 0) |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 2115 | ent = trace_find_next_entry_inc(iter); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2116 | else |
| 2117 | ent = iter; |
| 2118 | |
| 2119 | while (ent && iter->idx < i) |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 2120 | ent = trace_find_next_entry_inc(iter); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2121 | |
| 2122 | iter->pos = *pos; |
| 2123 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2124 | return ent; |
| 2125 | } |
| 2126 | |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 2127 | void tracing_iter_reset(struct trace_iterator *iter, int cpu) |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 2128 | { |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 2129 | struct ring_buffer_event *event; |
| 2130 | struct ring_buffer_iter *buf_iter; |
| 2131 | unsigned long entries = 0; |
| 2132 | u64 ts; |
| 2133 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2134 | per_cpu_ptr(iter->trace_buffer->data, cpu)->skipped_entries = 0; |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 2135 | |
Steven Rostedt | 6d158a8 | 2012-06-27 20:46:14 -0400 | [diff] [blame] | 2136 | buf_iter = trace_buffer_iter(iter, cpu); |
| 2137 | if (!buf_iter) |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 2138 | return; |
| 2139 | |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 2140 | ring_buffer_iter_reset(buf_iter); |
| 2141 | |
| 2142 | /* |
| 2143 | * We could have the case with the max latency tracers |
| 2144 | * that a reset never took place on a cpu. This is evident |
| 2145 | * by the timestamp being before the start of the buffer. |
| 2146 | */ |
| 2147 | while ((event = ring_buffer_iter_peek(buf_iter, &ts))) { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2148 | if (ts >= iter->trace_buffer->time_start) |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 2149 | break; |
| 2150 | entries++; |
| 2151 | ring_buffer_read(buf_iter, NULL); |
| 2152 | } |
| 2153 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2154 | per_cpu_ptr(iter->trace_buffer->data, cpu)->skipped_entries = entries; |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 2155 | } |
| 2156 | |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 2157 | /* |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 2158 | * The current tracer is copied to avoid a global locking |
| 2159 | * all around. |
| 2160 | */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2161 | static void *s_start(struct seq_file *m, loff_t *pos) |
| 2162 | { |
| 2163 | struct trace_iterator *iter = m->private; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 2164 | struct trace_array *tr = iter->tr; |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 2165 | int cpu_file = iter->cpu_file; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2166 | void *p = NULL; |
| 2167 | loff_t l = 0; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2168 | int cpu; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2169 | |
Hiraku Toyooka | 2fd196e | 2012-12-26 11:52:52 +0900 | [diff] [blame] | 2170 | /* |
| 2171 | * copy the tracer to avoid using a global lock all around. |
| 2172 | * iter->trace is a copy of current_trace, the pointer to the |
| 2173 | * name may be used instead of a strcmp(), as iter->trace->name |
| 2174 | * will point to the same string as current_trace->name. |
| 2175 | */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2176 | mutex_lock(&trace_types_lock); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 2177 | if (unlikely(tr->current_trace && iter->trace->name != tr->current_trace->name)) |
| 2178 | *iter->trace = *tr->current_trace; |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 2179 | mutex_unlock(&trace_types_lock); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2180 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2181 | #ifdef CONFIG_TRACER_MAX_TRACE |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 2182 | if (iter->snapshot && iter->trace->use_max_tr) |
| 2183 | return ERR_PTR(-EBUSY); |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2184 | #endif |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 2185 | |
| 2186 | if (!iter->snapshot) |
| 2187 | atomic_inc(&trace_record_cmdline_disabled); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2188 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2189 | if (*pos != iter->pos) { |
| 2190 | iter->ent = NULL; |
| 2191 | iter->cpu = 0; |
| 2192 | iter->idx = -1; |
| 2193 | |
Steven Rostedt | ae3b509 | 2013-01-23 15:22:59 -0500 | [diff] [blame] | 2194 | if (cpu_file == RING_BUFFER_ALL_CPUS) { |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 2195 | for_each_tracing_cpu(cpu) |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 2196 | tracing_iter_reset(iter, cpu); |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 2197 | } else |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 2198 | tracing_iter_reset(iter, cpu_file); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2199 | |
Lai Jiangshan | ac91d85 | 2010-03-02 17:54:50 +0800 | [diff] [blame] | 2200 | iter->leftover = 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2201 | for (p = iter; p && l < *pos; p = s_next(m, p, &l)) |
| 2202 | ; |
| 2203 | |
| 2204 | } else { |
Steven Rostedt | a63ce5b | 2009-12-07 09:11:39 -0500 | [diff] [blame] | 2205 | /* |
| 2206 | * If we overflowed the seq_file before, then we want |
| 2207 | * to just reuse the trace_seq buffer again. |
| 2208 | */ |
| 2209 | if (iter->leftover) |
| 2210 | p = iter; |
| 2211 | else { |
| 2212 | l = *pos - 1; |
| 2213 | p = s_next(m, p, &l); |
| 2214 | } |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2215 | } |
| 2216 | |
Lai Jiangshan | 4f53596 | 2009-05-18 19:35:34 +0800 | [diff] [blame] | 2217 | trace_event_read_lock(); |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 2218 | trace_access_lock(cpu_file); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2219 | return p; |
| 2220 | } |
| 2221 | |
| 2222 | static void s_stop(struct seq_file *m, void *p) |
| 2223 | { |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 2224 | struct trace_iterator *iter = m->private; |
| 2225 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2226 | #ifdef CONFIG_TRACER_MAX_TRACE |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 2227 | if (iter->snapshot && iter->trace->use_max_tr) |
| 2228 | return; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2229 | #endif |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 2230 | |
| 2231 | if (!iter->snapshot) |
| 2232 | atomic_dec(&trace_record_cmdline_disabled); |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2233 | |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 2234 | trace_access_unlock(iter->cpu_file); |
Lai Jiangshan | 4f53596 | 2009-05-18 19:35:34 +0800 | [diff] [blame] | 2235 | trace_event_read_unlock(); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2236 | } |
| 2237 | |
Steven Rostedt | 39eaf7e | 2011-11-17 10:35:16 -0500 | [diff] [blame] | 2238 | static void |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2239 | get_total_entries(struct trace_buffer *buf, |
| 2240 | unsigned long *total, unsigned long *entries) |
Steven Rostedt | 39eaf7e | 2011-11-17 10:35:16 -0500 | [diff] [blame] | 2241 | { |
| 2242 | unsigned long count; |
| 2243 | int cpu; |
| 2244 | |
| 2245 | *total = 0; |
| 2246 | *entries = 0; |
| 2247 | |
| 2248 | for_each_tracing_cpu(cpu) { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2249 | count = ring_buffer_entries_cpu(buf->buffer, cpu); |
Steven Rostedt | 39eaf7e | 2011-11-17 10:35:16 -0500 | [diff] [blame] | 2250 | /* |
| 2251 | * If this buffer has skipped entries, then we hold all |
| 2252 | * entries for the trace and we need to ignore the |
| 2253 | * ones before the time stamp. |
| 2254 | */ |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2255 | if (per_cpu_ptr(buf->data, cpu)->skipped_entries) { |
| 2256 | count -= per_cpu_ptr(buf->data, cpu)->skipped_entries; |
Steven Rostedt | 39eaf7e | 2011-11-17 10:35:16 -0500 | [diff] [blame] | 2257 | /* total is the same as the entries */ |
| 2258 | *total += count; |
| 2259 | } else |
| 2260 | *total += count + |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2261 | ring_buffer_overrun_cpu(buf->buffer, cpu); |
Steven Rostedt | 39eaf7e | 2011-11-17 10:35:16 -0500 | [diff] [blame] | 2262 | *entries += count; |
| 2263 | } |
| 2264 | } |
| 2265 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 2266 | static void print_lat_help_header(struct seq_file *m) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2267 | { |
Michael Ellerman | a616835 | 2008-08-20 16:36:11 -0700 | [diff] [blame] | 2268 | seq_puts(m, "# _------=> CPU# \n"); |
| 2269 | seq_puts(m, "# / _-----=> irqs-off \n"); |
| 2270 | seq_puts(m, "# | / _----=> need-resched \n"); |
| 2271 | seq_puts(m, "# || / _---=> hardirq/softirq \n"); |
| 2272 | seq_puts(m, "# ||| / _--=> preempt-depth \n"); |
Steven Rostedt | e6e1e25 | 2011-03-09 10:41:56 -0500 | [diff] [blame] | 2273 | seq_puts(m, "# |||| / delay \n"); |
| 2274 | seq_puts(m, "# cmd pid ||||| time | caller \n"); |
| 2275 | seq_puts(m, "# \\ / ||||| \\ | / \n"); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2276 | } |
| 2277 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2278 | 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] | 2279 | { |
Steven Rostedt | 39eaf7e | 2011-11-17 10:35:16 -0500 | [diff] [blame] | 2280 | unsigned long total; |
| 2281 | unsigned long entries; |
| 2282 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2283 | get_total_entries(buf, &total, &entries); |
Steven Rostedt | 39eaf7e | 2011-11-17 10:35:16 -0500 | [diff] [blame] | 2284 | seq_printf(m, "# entries-in-buffer/entries-written: %lu/%lu #P:%d\n", |
| 2285 | entries, total, num_online_cpus()); |
| 2286 | seq_puts(m, "#\n"); |
| 2287 | } |
| 2288 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2289 | 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] | 2290 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2291 | print_event_info(buf, m); |
Steven Rostedt | 77271ce | 2011-11-17 09:34:33 -0500 | [diff] [blame] | 2292 | seq_puts(m, "# TASK-PID CPU# TIMESTAMP FUNCTION\n"); |
Michael Ellerman | a616835 | 2008-08-20 16:36:11 -0700 | [diff] [blame] | 2293 | seq_puts(m, "# | | | | |\n"); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2294 | } |
| 2295 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2296 | 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] | 2297 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2298 | print_event_info(buf, m); |
Steven Rostedt | 77271ce | 2011-11-17 09:34:33 -0500 | [diff] [blame] | 2299 | seq_puts(m, "# _-----=> irqs-off\n"); |
| 2300 | seq_puts(m, "# / _----=> need-resched\n"); |
| 2301 | seq_puts(m, "# | / _---=> hardirq/softirq\n"); |
| 2302 | seq_puts(m, "# || / _--=> preempt-depth\n"); |
| 2303 | seq_puts(m, "# ||| / delay\n"); |
| 2304 | seq_puts(m, "# TASK-PID CPU# |||| TIMESTAMP FUNCTION\n"); |
| 2305 | seq_puts(m, "# | | | |||| | |\n"); |
| 2306 | } |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2307 | |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 2308 | void |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2309 | print_trace_header(struct seq_file *m, struct trace_iterator *iter) |
| 2310 | { |
| 2311 | unsigned long sym_flags = (trace_flags & TRACE_ITER_SYM_MASK); |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2312 | struct trace_buffer *buf = iter->trace_buffer; |
| 2313 | struct trace_array_cpu *data = per_cpu_ptr(buf->data, buf->cpu); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 2314 | struct tracer *type = iter->trace; |
Steven Rostedt | 39eaf7e | 2011-11-17 10:35:16 -0500 | [diff] [blame] | 2315 | unsigned long entries; |
| 2316 | unsigned long total; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2317 | const char *name = "preemption"; |
| 2318 | |
Steven Rostedt (Red Hat) | d840f71 | 2013-02-01 18:38:47 -0500 | [diff] [blame] | 2319 | name = type->name; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2320 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2321 | get_total_entries(buf, &total, &entries); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2322 | |
KOSAKI Motohiro | 888b55d | 2009-03-08 13:12:43 +0900 | [diff] [blame] | 2323 | seq_printf(m, "# %s latency trace v1.1.5 on %s\n", |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2324 | name, UTS_RELEASE); |
KOSAKI Motohiro | 888b55d | 2009-03-08 13:12:43 +0900 | [diff] [blame] | 2325 | seq_puts(m, "# -----------------------------------" |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2326 | "---------------------------------\n"); |
KOSAKI Motohiro | 888b55d | 2009-03-08 13:12:43 +0900 | [diff] [blame] | 2327 | seq_printf(m, "# latency: %lu us, #%lu/%lu, CPU#%d |" |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2328 | " (M:%s VP:%d, KP:%d, SP:%d HP:%d", |
Steven Rostedt | 57f50be | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 2329 | nsecs_to_usecs(data->saved_latency), |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2330 | entries, |
Steven Rostedt | 4c11d7a | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 2331 | total, |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2332 | buf->cpu, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2333 | #if defined(CONFIG_PREEMPT_NONE) |
| 2334 | "server", |
| 2335 | #elif defined(CONFIG_PREEMPT_VOLUNTARY) |
| 2336 | "desktop", |
Steven Rostedt | b5c21b4 | 2008-07-10 20:58:12 -0400 | [diff] [blame] | 2337 | #elif defined(CONFIG_PREEMPT) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2338 | "preempt", |
| 2339 | #else |
| 2340 | "unknown", |
| 2341 | #endif |
| 2342 | /* These are reserved for later use */ |
| 2343 | 0, 0, 0, 0); |
| 2344 | #ifdef CONFIG_SMP |
| 2345 | seq_printf(m, " #P:%d)\n", num_online_cpus()); |
| 2346 | #else |
| 2347 | seq_puts(m, ")\n"); |
| 2348 | #endif |
KOSAKI Motohiro | 888b55d | 2009-03-08 13:12:43 +0900 | [diff] [blame] | 2349 | seq_puts(m, "# -----------------\n"); |
| 2350 | seq_printf(m, "# | task: %.16s-%d " |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2351 | "(uid:%d nice:%ld policy:%ld rt_prio:%ld)\n", |
Eric W. Biederman | d20b92a | 2012-03-13 16:02:19 -0700 | [diff] [blame] | 2352 | data->comm, data->pid, |
| 2353 | from_kuid_munged(seq_user_ns(m), data->uid), data->nice, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2354 | data->policy, data->rt_priority); |
KOSAKI Motohiro | 888b55d | 2009-03-08 13:12:43 +0900 | [diff] [blame] | 2355 | seq_puts(m, "# -----------------\n"); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2356 | |
| 2357 | if (data->critical_start) { |
KOSAKI Motohiro | 888b55d | 2009-03-08 13:12:43 +0900 | [diff] [blame] | 2358 | seq_puts(m, "# => started at: "); |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2359 | seq_print_ip_sym(&iter->seq, data->critical_start, sym_flags); |
| 2360 | trace_print_seq(m, &iter->seq); |
KOSAKI Motohiro | 888b55d | 2009-03-08 13:12:43 +0900 | [diff] [blame] | 2361 | seq_puts(m, "\n# => ended at: "); |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2362 | seq_print_ip_sym(&iter->seq, data->critical_end, sym_flags); |
| 2363 | trace_print_seq(m, &iter->seq); |
Steven Rostedt | 8248ac0 | 2009-09-02 12:27:41 -0400 | [diff] [blame] | 2364 | seq_puts(m, "\n#\n"); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2365 | } |
| 2366 | |
KOSAKI Motohiro | 888b55d | 2009-03-08 13:12:43 +0900 | [diff] [blame] | 2367 | seq_puts(m, "#\n"); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2368 | } |
| 2369 | |
Steven Rostedt | a309720 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 2370 | static void test_cpu_buff_start(struct trace_iterator *iter) |
| 2371 | { |
| 2372 | struct trace_seq *s = &iter->seq; |
| 2373 | |
Steven Rostedt | 12ef7d4 | 2008-11-12 17:52:38 -0500 | [diff] [blame] | 2374 | if (!(trace_flags & TRACE_ITER_ANNOTATE)) |
| 2375 | return; |
| 2376 | |
| 2377 | if (!(iter->iter_flags & TRACE_FILE_ANNOTATE)) |
| 2378 | return; |
| 2379 | |
Rusty Russell | 4462344 | 2009-01-01 10:12:23 +1030 | [diff] [blame] | 2380 | if (cpumask_test_cpu(iter->cpu, iter->started)) |
Steven Rostedt | a309720 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 2381 | return; |
| 2382 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2383 | if (per_cpu_ptr(iter->trace_buffer->data, iter->cpu)->skipped_entries) |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 2384 | return; |
| 2385 | |
Rusty Russell | 4462344 | 2009-01-01 10:12:23 +1030 | [diff] [blame] | 2386 | cpumask_set_cpu(iter->cpu, iter->started); |
Frederic Weisbecker | b0dfa97 | 2009-04-01 22:53:08 +0200 | [diff] [blame] | 2387 | |
| 2388 | /* Don't print started cpu buffer for the first entry of the trace */ |
| 2389 | if (iter->idx > 1) |
| 2390 | trace_seq_printf(s, "##### CPU %u buffer started ####\n", |
| 2391 | iter->cpu); |
Steven Rostedt | a309720 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 2392 | } |
| 2393 | |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 2394 | static enum print_line_t print_trace_fmt(struct trace_iterator *iter) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2395 | { |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2396 | struct trace_seq *s = &iter->seq; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2397 | unsigned long sym_flags = (trace_flags & TRACE_ITER_SYM_MASK); |
Ingo Molnar | 4e3c333 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 2398 | struct trace_entry *entry; |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 2399 | struct trace_event *event; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2400 | |
Ingo Molnar | 4e3c333 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 2401 | entry = iter->ent; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2402 | |
Steven Rostedt | a309720 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 2403 | test_cpu_buff_start(iter); |
| 2404 | |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 2405 | event = ftrace_find_event(entry->type); |
Frederic Weisbecker | c4a8e8b | 2009-02-02 20:29:21 -0200 | [diff] [blame] | 2406 | |
| 2407 | if (trace_flags & TRACE_ITER_CONTEXT_INFO) { |
Steven Rostedt | 27d48be | 2009-03-04 21:57:29 -0500 | [diff] [blame] | 2408 | if (iter->iter_flags & TRACE_FILE_LAT_FMT) { |
| 2409 | if (!trace_print_lat_context(iter)) |
| 2410 | goto partial; |
| 2411 | } else { |
| 2412 | if (!trace_print_context(iter)) |
| 2413 | goto partial; |
| 2414 | } |
Frederic Weisbecker | c4a8e8b | 2009-02-02 20:29:21 -0200 | [diff] [blame] | 2415 | } |
| 2416 | |
Arnaldo Carvalho de Melo | 268ccda | 2009-02-04 20:16:39 -0200 | [diff] [blame] | 2417 | if (event) |
Steven Rostedt | a9a5776 | 2010-04-22 18:46:14 -0400 | [diff] [blame] | 2418 | return event->funcs->trace(iter, sym_flags, event); |
Arnaldo Carvalho de Melo | d9793bd | 2009-02-03 20:20:41 -0200 | [diff] [blame] | 2419 | |
| 2420 | if (!trace_seq_printf(s, "Unknown type %d\n", entry->type)) |
| 2421 | goto partial; |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 2422 | |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 2423 | return TRACE_TYPE_HANDLED; |
Arnaldo Carvalho de Melo | d9793bd | 2009-02-03 20:20:41 -0200 | [diff] [blame] | 2424 | partial: |
| 2425 | return TRACE_TYPE_PARTIAL_LINE; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2426 | } |
| 2427 | |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 2428 | static enum print_line_t print_raw_fmt(struct trace_iterator *iter) |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2429 | { |
| 2430 | struct trace_seq *s = &iter->seq; |
| 2431 | struct trace_entry *entry; |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 2432 | struct trace_event *event; |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2433 | |
| 2434 | entry = iter->ent; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2435 | |
Frederic Weisbecker | c4a8e8b | 2009-02-02 20:29:21 -0200 | [diff] [blame] | 2436 | if (trace_flags & TRACE_ITER_CONTEXT_INFO) { |
Arnaldo Carvalho de Melo | d9793bd | 2009-02-03 20:20:41 -0200 | [diff] [blame] | 2437 | if (!trace_seq_printf(s, "%d %d %llu ", |
| 2438 | entry->pid, iter->cpu, iter->ts)) |
| 2439 | goto partial; |
Frederic Weisbecker | c4a8e8b | 2009-02-02 20:29:21 -0200 | [diff] [blame] | 2440 | } |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2441 | |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 2442 | event = ftrace_find_event(entry->type); |
Arnaldo Carvalho de Melo | 268ccda | 2009-02-04 20:16:39 -0200 | [diff] [blame] | 2443 | if (event) |
Steven Rostedt | a9a5776 | 2010-04-22 18:46:14 -0400 | [diff] [blame] | 2444 | return event->funcs->raw(iter, 0, event); |
Arnaldo Carvalho de Melo | d9793bd | 2009-02-03 20:20:41 -0200 | [diff] [blame] | 2445 | |
| 2446 | if (!trace_seq_printf(s, "%d ?\n", entry->type)) |
| 2447 | goto partial; |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 2448 | |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 2449 | return TRACE_TYPE_HANDLED; |
Arnaldo Carvalho de Melo | d9793bd | 2009-02-03 20:20:41 -0200 | [diff] [blame] | 2450 | partial: |
| 2451 | return TRACE_TYPE_PARTIAL_LINE; |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2452 | } |
| 2453 | |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 2454 | static enum print_line_t print_hex_fmt(struct trace_iterator *iter) |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 2455 | { |
| 2456 | struct trace_seq *s = &iter->seq; |
| 2457 | unsigned char newline = '\n'; |
| 2458 | struct trace_entry *entry; |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 2459 | struct trace_event *event; |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 2460 | |
| 2461 | entry = iter->ent; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2462 | |
Frederic Weisbecker | c4a8e8b | 2009-02-02 20:29:21 -0200 | [diff] [blame] | 2463 | if (trace_flags & TRACE_ITER_CONTEXT_INFO) { |
| 2464 | SEQ_PUT_HEX_FIELD_RET(s, entry->pid); |
| 2465 | SEQ_PUT_HEX_FIELD_RET(s, iter->cpu); |
| 2466 | SEQ_PUT_HEX_FIELD_RET(s, iter->ts); |
| 2467 | } |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 2468 | |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 2469 | event = ftrace_find_event(entry->type); |
Arnaldo Carvalho de Melo | 268ccda | 2009-02-04 20:16:39 -0200 | [diff] [blame] | 2470 | if (event) { |
Steven Rostedt | a9a5776 | 2010-04-22 18:46:14 -0400 | [diff] [blame] | 2471 | 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] | 2472 | if (ret != TRACE_TYPE_HANDLED) |
| 2473 | return ret; |
| 2474 | } |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 2475 | |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 2476 | SEQ_PUT_FIELD_RET(s, newline); |
| 2477 | |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 2478 | return TRACE_TYPE_HANDLED; |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 2479 | } |
| 2480 | |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 2481 | static enum print_line_t print_bin_fmt(struct trace_iterator *iter) |
Ingo Molnar | cb0f12a | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2482 | { |
| 2483 | struct trace_seq *s = &iter->seq; |
| 2484 | struct trace_entry *entry; |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 2485 | struct trace_event *event; |
Ingo Molnar | cb0f12a | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2486 | |
| 2487 | entry = iter->ent; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2488 | |
Frederic Weisbecker | c4a8e8b | 2009-02-02 20:29:21 -0200 | [diff] [blame] | 2489 | if (trace_flags & TRACE_ITER_CONTEXT_INFO) { |
| 2490 | SEQ_PUT_FIELD_RET(s, entry->pid); |
Steven Rostedt | 1830b52 | 2009-02-07 19:38:43 -0500 | [diff] [blame] | 2491 | SEQ_PUT_FIELD_RET(s, iter->cpu); |
Frederic Weisbecker | c4a8e8b | 2009-02-02 20:29:21 -0200 | [diff] [blame] | 2492 | SEQ_PUT_FIELD_RET(s, iter->ts); |
| 2493 | } |
Ingo Molnar | cb0f12a | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2494 | |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 2495 | event = ftrace_find_event(entry->type); |
Steven Rostedt | a9a5776 | 2010-04-22 18:46:14 -0400 | [diff] [blame] | 2496 | return event ? event->funcs->binary(iter, 0, event) : |
| 2497 | TRACE_TYPE_HANDLED; |
Ingo Molnar | cb0f12a | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2498 | } |
| 2499 | |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 2500 | int trace_empty(struct trace_iterator *iter) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2501 | { |
Steven Rostedt | 6d158a8 | 2012-06-27 20:46:14 -0400 | [diff] [blame] | 2502 | struct ring_buffer_iter *buf_iter; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2503 | int cpu; |
| 2504 | |
Steven Rostedt | 9aba60f | 2009-03-11 19:52:30 -0400 | [diff] [blame] | 2505 | /* If we are looking at one CPU buffer, only check that one */ |
Steven Rostedt | ae3b509 | 2013-01-23 15:22:59 -0500 | [diff] [blame] | 2506 | if (iter->cpu_file != RING_BUFFER_ALL_CPUS) { |
Steven Rostedt | 9aba60f | 2009-03-11 19:52:30 -0400 | [diff] [blame] | 2507 | cpu = iter->cpu_file; |
Steven Rostedt | 6d158a8 | 2012-06-27 20:46:14 -0400 | [diff] [blame] | 2508 | buf_iter = trace_buffer_iter(iter, cpu); |
| 2509 | if (buf_iter) { |
| 2510 | if (!ring_buffer_iter_empty(buf_iter)) |
Steven Rostedt | 9aba60f | 2009-03-11 19:52:30 -0400 | [diff] [blame] | 2511 | return 0; |
| 2512 | } else { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2513 | if (!ring_buffer_empty_cpu(iter->trace_buffer->buffer, cpu)) |
Steven Rostedt | 9aba60f | 2009-03-11 19:52:30 -0400 | [diff] [blame] | 2514 | return 0; |
| 2515 | } |
| 2516 | return 1; |
| 2517 | } |
| 2518 | |
Steven Rostedt | ab46428 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 2519 | for_each_tracing_cpu(cpu) { |
Steven Rostedt | 6d158a8 | 2012-06-27 20:46:14 -0400 | [diff] [blame] | 2520 | buf_iter = trace_buffer_iter(iter, cpu); |
| 2521 | if (buf_iter) { |
| 2522 | if (!ring_buffer_iter_empty(buf_iter)) |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 2523 | return 0; |
| 2524 | } else { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2525 | if (!ring_buffer_empty_cpu(iter->trace_buffer->buffer, cpu)) |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 2526 | return 0; |
| 2527 | } |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2528 | } |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 2529 | |
Frederic Weisbecker | 797d371 | 2008-09-30 18:13:45 +0200 | [diff] [blame] | 2530 | return 1; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2531 | } |
| 2532 | |
Lai Jiangshan | 4f53596 | 2009-05-18 19:35:34 +0800 | [diff] [blame] | 2533 | /* Called with trace_event_read_lock() held. */ |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 2534 | enum print_line_t print_trace_line(struct trace_iterator *iter) |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2535 | { |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 2536 | enum print_line_t ret; |
| 2537 | |
Jiri Olsa | ee5e51f | 2011-03-25 12:05:18 +0100 | [diff] [blame] | 2538 | if (iter->lost_events && |
| 2539 | !trace_seq_printf(&iter->seq, "CPU:%d [LOST %lu EVENTS]\n", |
| 2540 | iter->cpu, iter->lost_events)) |
| 2541 | return TRACE_TYPE_PARTIAL_LINE; |
Steven Rostedt | bc21b47 | 2010-03-31 19:49:26 -0400 | [diff] [blame] | 2542 | |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 2543 | if (iter->trace && iter->trace->print_line) { |
| 2544 | ret = iter->trace->print_line(iter); |
| 2545 | if (ret != TRACE_TYPE_UNHANDLED) |
| 2546 | return ret; |
| 2547 | } |
Thomas Gleixner | 72829bc | 2008-05-23 21:37:28 +0200 | [diff] [blame] | 2548 | |
Steven Rostedt (Red Hat) | 09ae723 | 2013-03-08 21:02:34 -0500 | [diff] [blame^] | 2549 | if (iter->ent->type == TRACE_BPUTS && |
| 2550 | trace_flags & TRACE_ITER_PRINTK && |
| 2551 | trace_flags & TRACE_ITER_PRINTK_MSGONLY) |
| 2552 | return trace_print_bputs_msg_only(iter); |
| 2553 | |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 2554 | if (iter->ent->type == TRACE_BPRINT && |
| 2555 | trace_flags & TRACE_ITER_PRINTK && |
| 2556 | trace_flags & TRACE_ITER_PRINTK_MSGONLY) |
Steven Rostedt | 5ef841f | 2009-03-19 12:20:38 -0400 | [diff] [blame] | 2557 | return trace_print_bprintk_msg_only(iter); |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 2558 | |
Frederic Weisbecker | 66896a8 | 2008-12-13 20:18:13 +0100 | [diff] [blame] | 2559 | if (iter->ent->type == TRACE_PRINT && |
| 2560 | trace_flags & TRACE_ITER_PRINTK && |
| 2561 | trace_flags & TRACE_ITER_PRINTK_MSGONLY) |
Steven Rostedt | 5ef841f | 2009-03-19 12:20:38 -0400 | [diff] [blame] | 2562 | return trace_print_printk_msg_only(iter); |
Frederic Weisbecker | 66896a8 | 2008-12-13 20:18:13 +0100 | [diff] [blame] | 2563 | |
Ingo Molnar | cb0f12a | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2564 | if (trace_flags & TRACE_ITER_BIN) |
| 2565 | return print_bin_fmt(iter); |
| 2566 | |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 2567 | if (trace_flags & TRACE_ITER_HEX) |
| 2568 | return print_hex_fmt(iter); |
| 2569 | |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2570 | if (trace_flags & TRACE_ITER_RAW) |
| 2571 | return print_raw_fmt(iter); |
| 2572 | |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2573 | return print_trace_fmt(iter); |
| 2574 | } |
| 2575 | |
Jiri Olsa | 7e9a49e | 2011-11-07 16:08:49 +0100 | [diff] [blame] | 2576 | void trace_latency_header(struct seq_file *m) |
| 2577 | { |
| 2578 | struct trace_iterator *iter = m->private; |
| 2579 | |
| 2580 | /* print nothing if the buffers are empty */ |
| 2581 | if (trace_empty(iter)) |
| 2582 | return; |
| 2583 | |
| 2584 | if (iter->iter_flags & TRACE_FILE_LAT_FMT) |
| 2585 | print_trace_header(m, iter); |
| 2586 | |
| 2587 | if (!(trace_flags & TRACE_ITER_VERBOSE)) |
| 2588 | print_lat_help_header(m); |
| 2589 | } |
| 2590 | |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 2591 | void trace_default_header(struct seq_file *m) |
| 2592 | { |
| 2593 | struct trace_iterator *iter = m->private; |
| 2594 | |
Jiri Olsa | f56e7f8 | 2011-06-03 16:58:49 +0200 | [diff] [blame] | 2595 | if (!(trace_flags & TRACE_ITER_CONTEXT_INFO)) |
| 2596 | return; |
| 2597 | |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 2598 | if (iter->iter_flags & TRACE_FILE_LAT_FMT) { |
| 2599 | /* print nothing if the buffers are empty */ |
| 2600 | if (trace_empty(iter)) |
| 2601 | return; |
| 2602 | print_trace_header(m, iter); |
| 2603 | if (!(trace_flags & TRACE_ITER_VERBOSE)) |
| 2604 | print_lat_help_header(m); |
| 2605 | } else { |
Steven Rostedt | 77271ce | 2011-11-17 09:34:33 -0500 | [diff] [blame] | 2606 | if (!(trace_flags & TRACE_ITER_VERBOSE)) { |
| 2607 | if (trace_flags & TRACE_ITER_IRQ_INFO) |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2608 | print_func_help_header_irq(iter->trace_buffer, m); |
Steven Rostedt | 77271ce | 2011-11-17 09:34:33 -0500 | [diff] [blame] | 2609 | else |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2610 | print_func_help_header(iter->trace_buffer, m); |
Steven Rostedt | 77271ce | 2011-11-17 09:34:33 -0500 | [diff] [blame] | 2611 | } |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 2612 | } |
| 2613 | } |
| 2614 | |
Steven Rostedt | e0a413f | 2011-09-29 21:26:16 -0400 | [diff] [blame] | 2615 | static void test_ftrace_alive(struct seq_file *m) |
| 2616 | { |
| 2617 | if (!ftrace_is_dead()) |
| 2618 | return; |
| 2619 | seq_printf(m, "# WARNING: FUNCTION TRACING IS CORRUPTED\n"); |
| 2620 | seq_printf(m, "# MAY BE MISSING FUNCTION EVENTS\n"); |
| 2621 | } |
| 2622 | |
Steven Rostedt (Red Hat) | d8741e2 | 2013-03-05 10:25:16 -0500 | [diff] [blame] | 2623 | #ifdef CONFIG_TRACER_MAX_TRACE |
Steven Rostedt (Red Hat) | f1affca | 2013-03-05 14:35:11 -0500 | [diff] [blame] | 2624 | static void show_snapshot_main_help(struct seq_file *m) |
| 2625 | { |
| 2626 | seq_printf(m, "# echo 0 > snapshot : Clears and frees snapshot buffer\n"); |
| 2627 | seq_printf(m, "# echo 1 > snapshot : Allocates snapshot buffer, if not already allocated.\n"); |
| 2628 | seq_printf(m, "# Takes a snapshot of the main buffer.\n"); |
| 2629 | seq_printf(m, "# echo 2 > snapshot : Clears snapshot buffer (but does not allocate)\n"); |
| 2630 | seq_printf(m, "# (Doesn't have to be '2' works with any number that\n"); |
| 2631 | seq_printf(m, "# is not a '0' or '1')\n"); |
| 2632 | } |
| 2633 | |
| 2634 | static void show_snapshot_percpu_help(struct seq_file *m) |
| 2635 | { |
| 2636 | seq_printf(m, "# echo 0 > snapshot : Invalid for per_cpu snapshot file.\n"); |
| 2637 | #ifdef CONFIG_RING_BUFFER_ALLOW_SWAP |
| 2638 | seq_printf(m, "# echo 1 > snapshot : Allocates snapshot buffer, if not already allocated.\n"); |
| 2639 | seq_printf(m, "# Takes a snapshot of the main buffer for this cpu.\n"); |
| 2640 | #else |
| 2641 | seq_printf(m, "# echo 1 > snapshot : Not supported with this kernel.\n"); |
| 2642 | seq_printf(m, "# Must use main snapshot file to allocate.\n"); |
| 2643 | #endif |
| 2644 | seq_printf(m, "# echo 2 > snapshot : Clears this cpu's snapshot buffer (but does not allocate)\n"); |
| 2645 | seq_printf(m, "# (Doesn't have to be '2' works with any number that\n"); |
| 2646 | seq_printf(m, "# is not a '0' or '1')\n"); |
| 2647 | } |
| 2648 | |
Steven Rostedt (Red Hat) | d8741e2 | 2013-03-05 10:25:16 -0500 | [diff] [blame] | 2649 | static void print_snapshot_help(struct seq_file *m, struct trace_iterator *iter) |
| 2650 | { |
Steven Rostedt (Red Hat) | 45ad21c | 2013-03-05 18:25:02 -0500 | [diff] [blame] | 2651 | if (iter->tr->allocated_snapshot) |
Steven Rostedt (Red Hat) | d8741e2 | 2013-03-05 10:25:16 -0500 | [diff] [blame] | 2652 | seq_printf(m, "#\n# * Snapshot is allocated *\n#\n"); |
| 2653 | else |
| 2654 | seq_printf(m, "#\n# * Snapshot is freed *\n#\n"); |
| 2655 | |
| 2656 | seq_printf(m, "# Snapshot commands:\n"); |
Steven Rostedt (Red Hat) | f1affca | 2013-03-05 14:35:11 -0500 | [diff] [blame] | 2657 | if (iter->cpu_file == RING_BUFFER_ALL_CPUS) |
| 2658 | show_snapshot_main_help(m); |
| 2659 | else |
| 2660 | show_snapshot_percpu_help(m); |
Steven Rostedt (Red Hat) | d8741e2 | 2013-03-05 10:25:16 -0500 | [diff] [blame] | 2661 | } |
| 2662 | #else |
| 2663 | /* Should never be called */ |
| 2664 | static inline void print_snapshot_help(struct seq_file *m, struct trace_iterator *iter) { } |
| 2665 | #endif |
| 2666 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2667 | static int s_show(struct seq_file *m, void *v) |
| 2668 | { |
| 2669 | struct trace_iterator *iter = v; |
Steven Rostedt | a63ce5b | 2009-12-07 09:11:39 -0500 | [diff] [blame] | 2670 | int ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2671 | |
| 2672 | if (iter->ent == NULL) { |
| 2673 | if (iter->tr) { |
| 2674 | seq_printf(m, "# tracer: %s\n", iter->trace->name); |
| 2675 | seq_puts(m, "#\n"); |
Steven Rostedt | e0a413f | 2011-09-29 21:26:16 -0400 | [diff] [blame] | 2676 | test_ftrace_alive(m); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2677 | } |
Steven Rostedt (Red Hat) | d8741e2 | 2013-03-05 10:25:16 -0500 | [diff] [blame] | 2678 | if (iter->snapshot && trace_empty(iter)) |
| 2679 | print_snapshot_help(m, iter); |
| 2680 | else if (iter->trace && iter->trace->print_header) |
Markus Metzger | 8bba1bf | 2008-11-25 09:12:31 +0100 | [diff] [blame] | 2681 | iter->trace->print_header(m); |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 2682 | else |
| 2683 | trace_default_header(m); |
| 2684 | |
Steven Rostedt | a63ce5b | 2009-12-07 09:11:39 -0500 | [diff] [blame] | 2685 | } else if (iter->leftover) { |
| 2686 | /* |
| 2687 | * If we filled the seq_file buffer earlier, we |
| 2688 | * want to just show it now. |
| 2689 | */ |
| 2690 | ret = trace_print_seq(m, &iter->seq); |
| 2691 | |
| 2692 | /* ret should this time be zero, but you never know */ |
| 2693 | iter->leftover = ret; |
| 2694 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2695 | } else { |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2696 | print_trace_line(iter); |
Steven Rostedt | a63ce5b | 2009-12-07 09:11:39 -0500 | [diff] [blame] | 2697 | ret = trace_print_seq(m, &iter->seq); |
| 2698 | /* |
| 2699 | * If we overflow the seq_file buffer, then it will |
| 2700 | * ask us for this data again at start up. |
| 2701 | * Use that instead. |
| 2702 | * ret is 0 if seq_file write succeeded. |
| 2703 | * -1 otherwise. |
| 2704 | */ |
| 2705 | iter->leftover = ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2706 | } |
| 2707 | |
| 2708 | return 0; |
| 2709 | } |
| 2710 | |
James Morris | 88e9d34 | 2009-09-22 16:43:43 -0700 | [diff] [blame] | 2711 | static const struct seq_operations tracer_seq_ops = { |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2712 | .start = s_start, |
| 2713 | .next = s_next, |
| 2714 | .stop = s_stop, |
| 2715 | .show = s_show, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2716 | }; |
| 2717 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 2718 | static struct trace_iterator * |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 2719 | __tracing_open(struct inode *inode, struct file *file, bool snapshot) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2720 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 2721 | struct trace_cpu *tc = inode->i_private; |
| 2722 | struct trace_array *tr = tc->tr; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2723 | struct trace_iterator *iter; |
Jiri Olsa | 50e18b9 | 2012-04-25 10:23:39 +0200 | [diff] [blame] | 2724 | int cpu; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2725 | |
Steven Rostedt | 85a2f9b | 2009-02-27 00:12:38 -0500 | [diff] [blame] | 2726 | if (tracing_disabled) |
| 2727 | return ERR_PTR(-ENODEV); |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 2728 | |
Jiri Olsa | 50e18b9 | 2012-04-25 10:23:39 +0200 | [diff] [blame] | 2729 | iter = __seq_open_private(file, &tracer_seq_ops, sizeof(*iter)); |
Steven Rostedt | 85a2f9b | 2009-02-27 00:12:38 -0500 | [diff] [blame] | 2730 | if (!iter) |
| 2731 | return ERR_PTR(-ENOMEM); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2732 | |
Steven Rostedt | 6d158a8 | 2012-06-27 20:46:14 -0400 | [diff] [blame] | 2733 | iter->buffer_iter = kzalloc(sizeof(*iter->buffer_iter) * num_possible_cpus(), |
| 2734 | GFP_KERNEL); |
Dan Carpenter | 93574fc | 2012-07-11 09:35:08 +0300 | [diff] [blame] | 2735 | if (!iter->buffer_iter) |
| 2736 | goto release; |
| 2737 | |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 2738 | /* |
| 2739 | * We make a copy of the current tracer to avoid concurrent |
| 2740 | * changes on it while we are reading. |
| 2741 | */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2742 | mutex_lock(&trace_types_lock); |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 2743 | iter->trace = kzalloc(sizeof(*iter->trace), GFP_KERNEL); |
Steven Rostedt | 85a2f9b | 2009-02-27 00:12:38 -0500 | [diff] [blame] | 2744 | if (!iter->trace) |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 2745 | goto fail; |
Steven Rostedt | 85a2f9b | 2009-02-27 00:12:38 -0500 | [diff] [blame] | 2746 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 2747 | *iter->trace = *tr->current_trace; |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 2748 | |
Li Zefan | 79f5599 | 2009-06-15 14:58:26 +0800 | [diff] [blame] | 2749 | if (!zalloc_cpumask_var(&iter->started, GFP_KERNEL)) |
Frederic Weisbecker | b0dfa97 | 2009-04-01 22:53:08 +0200 | [diff] [blame] | 2750 | goto fail; |
| 2751 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2752 | iter->tr = tr; |
| 2753 | |
| 2754 | #ifdef CONFIG_TRACER_MAX_TRACE |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 2755 | /* Currently only the top directory has a snapshot */ |
| 2756 | if (tr->current_trace->print_max || snapshot) |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2757 | iter->trace_buffer = &tr->max_buffer; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2758 | else |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2759 | #endif |
| 2760 | iter->trace_buffer = &tr->trace_buffer; |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 2761 | iter->snapshot = snapshot; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2762 | iter->pos = -1; |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 2763 | mutex_init(&iter->mutex); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 2764 | iter->cpu_file = tc->cpu; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2765 | |
Markus Metzger | 8bba1bf | 2008-11-25 09:12:31 +0100 | [diff] [blame] | 2766 | /* Notify the tracer early; before we stop tracing. */ |
| 2767 | if (iter->trace && iter->trace->open) |
Markus Metzger | a93751c | 2008-12-11 13:53:26 +0100 | [diff] [blame] | 2768 | iter->trace->open(iter); |
Markus Metzger | 8bba1bf | 2008-11-25 09:12:31 +0100 | [diff] [blame] | 2769 | |
Steven Rostedt | 12ef7d4 | 2008-11-12 17:52:38 -0500 | [diff] [blame] | 2770 | /* Annotate start of buffers if we had overruns */ |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2771 | if (ring_buffer_overruns(iter->trace_buffer->buffer)) |
Steven Rostedt | 12ef7d4 | 2008-11-12 17:52:38 -0500 | [diff] [blame] | 2772 | iter->iter_flags |= TRACE_FILE_ANNOTATE; |
| 2773 | |
David Sharp | 8be0709 | 2012-11-13 12:18:22 -0800 | [diff] [blame] | 2774 | /* Output in nanoseconds only if we are using a clock in nanoseconds. */ |
| 2775 | if (trace_clocks[trace_clock_id].in_ns) |
| 2776 | iter->iter_flags |= TRACE_FILE_TIME_IN_NS; |
| 2777 | |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 2778 | /* stop the trace while dumping if we are not opening "snapshot" */ |
| 2779 | if (!iter->snapshot) |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 2780 | tracing_stop_tr(tr); |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 2781 | |
Steven Rostedt | ae3b509 | 2013-01-23 15:22:59 -0500 | [diff] [blame] | 2782 | if (iter->cpu_file == RING_BUFFER_ALL_CPUS) { |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 2783 | for_each_tracing_cpu(cpu) { |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 2784 | iter->buffer_iter[cpu] = |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2785 | ring_buffer_read_prepare(iter->trace_buffer->buffer, cpu); |
David Miller | 72c9ddf | 2010-04-20 15:47:11 -0700 | [diff] [blame] | 2786 | } |
| 2787 | ring_buffer_read_prepare_sync(); |
| 2788 | for_each_tracing_cpu(cpu) { |
| 2789 | ring_buffer_read_start(iter->buffer_iter[cpu]); |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 2790 | tracing_iter_reset(iter, cpu); |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 2791 | } |
| 2792 | } else { |
| 2793 | cpu = iter->cpu_file; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2794 | iter->buffer_iter[cpu] = |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2795 | ring_buffer_read_prepare(iter->trace_buffer->buffer, cpu); |
David Miller | 72c9ddf | 2010-04-20 15:47:11 -0700 | [diff] [blame] | 2796 | ring_buffer_read_prepare_sync(); |
| 2797 | ring_buffer_read_start(iter->buffer_iter[cpu]); |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 2798 | tracing_iter_reset(iter, cpu); |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2799 | } |
| 2800 | |
Steven Rostedt (Red Hat) | a695cb5 | 2013-03-06 15:27:24 -0500 | [diff] [blame] | 2801 | tr->ref++; |
| 2802 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2803 | mutex_unlock(&trace_types_lock); |
| 2804 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2805 | return iter; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2806 | |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 2807 | fail: |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2808 | mutex_unlock(&trace_types_lock); |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 2809 | kfree(iter->trace); |
Steven Rostedt | 6d158a8 | 2012-06-27 20:46:14 -0400 | [diff] [blame] | 2810 | kfree(iter->buffer_iter); |
Dan Carpenter | 93574fc | 2012-07-11 09:35:08 +0300 | [diff] [blame] | 2811 | release: |
Jiri Olsa | 50e18b9 | 2012-04-25 10:23:39 +0200 | [diff] [blame] | 2812 | seq_release_private(inode, file); |
| 2813 | return ERR_PTR(-ENOMEM); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2814 | } |
| 2815 | |
| 2816 | int tracing_open_generic(struct inode *inode, struct file *filp) |
| 2817 | { |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 2818 | if (tracing_disabled) |
| 2819 | return -ENODEV; |
| 2820 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2821 | filp->private_data = inode->i_private; |
| 2822 | return 0; |
| 2823 | } |
| 2824 | |
Hannes Eder | 4fd2735 | 2009-02-10 19:44:12 +0100 | [diff] [blame] | 2825 | static int tracing_release(struct inode *inode, struct file *file) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2826 | { |
matt mooney | 907f278 | 2010-09-27 19:04:53 -0700 | [diff] [blame] | 2827 | struct seq_file *m = file->private_data; |
Steven Rostedt | 4acd4d0 | 2009-03-18 10:40:24 -0400 | [diff] [blame] | 2828 | struct trace_iterator *iter; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 2829 | struct trace_array *tr; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2830 | int cpu; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2831 | |
Steven Rostedt | 4acd4d0 | 2009-03-18 10:40:24 -0400 | [diff] [blame] | 2832 | if (!(file->f_mode & FMODE_READ)) |
| 2833 | return 0; |
| 2834 | |
| 2835 | iter = m->private; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2836 | tr = iter->tr; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 2837 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2838 | mutex_lock(&trace_types_lock); |
Steven Rostedt (Red Hat) | a695cb5 | 2013-03-06 15:27:24 -0500 | [diff] [blame] | 2839 | |
| 2840 | WARN_ON(!tr->ref); |
| 2841 | tr->ref--; |
| 2842 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2843 | for_each_tracing_cpu(cpu) { |
| 2844 | if (iter->buffer_iter[cpu]) |
| 2845 | ring_buffer_read_finish(iter->buffer_iter[cpu]); |
| 2846 | } |
| 2847 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2848 | if (iter->trace && iter->trace->close) |
| 2849 | iter->trace->close(iter); |
| 2850 | |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 2851 | if (!iter->snapshot) |
| 2852 | /* reenable tracing if it was previously enabled */ |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 2853 | tracing_start_tr(tr); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2854 | mutex_unlock(&trace_types_lock); |
| 2855 | |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 2856 | mutex_destroy(&iter->mutex); |
Frederic Weisbecker | b0dfa97 | 2009-04-01 22:53:08 +0200 | [diff] [blame] | 2857 | free_cpumask_var(iter->started); |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 2858 | kfree(iter->trace); |
Steven Rostedt | 6d158a8 | 2012-06-27 20:46:14 -0400 | [diff] [blame] | 2859 | kfree(iter->buffer_iter); |
Jiri Olsa | 50e18b9 | 2012-04-25 10:23:39 +0200 | [diff] [blame] | 2860 | seq_release_private(inode, file); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2861 | return 0; |
| 2862 | } |
| 2863 | |
| 2864 | static int tracing_open(struct inode *inode, struct file *file) |
| 2865 | { |
Steven Rostedt | 85a2f9b | 2009-02-27 00:12:38 -0500 | [diff] [blame] | 2866 | struct trace_iterator *iter; |
| 2867 | int ret = 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2868 | |
Steven Rostedt | 4acd4d0 | 2009-03-18 10:40:24 -0400 | [diff] [blame] | 2869 | /* If this file was open for write, then erase contents */ |
| 2870 | if ((file->f_mode & FMODE_WRITE) && |
Steven Rostedt | 8650ae3 | 2009-07-22 23:29:30 -0400 | [diff] [blame] | 2871 | (file->f_flags & O_TRUNC)) { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 2872 | struct trace_cpu *tc = inode->i_private; |
| 2873 | struct trace_array *tr = tc->tr; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2874 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 2875 | if (tc->cpu == RING_BUFFER_ALL_CPUS) |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2876 | tracing_reset_online_cpus(&tr->trace_buffer); |
Steven Rostedt | 4acd4d0 | 2009-03-18 10:40:24 -0400 | [diff] [blame] | 2877 | else |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2878 | tracing_reset(&tr->trace_buffer, tc->cpu); |
Steven Rostedt | 4acd4d0 | 2009-03-18 10:40:24 -0400 | [diff] [blame] | 2879 | } |
| 2880 | |
| 2881 | if (file->f_mode & FMODE_READ) { |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 2882 | iter = __tracing_open(inode, file, false); |
Steven Rostedt | 4acd4d0 | 2009-03-18 10:40:24 -0400 | [diff] [blame] | 2883 | if (IS_ERR(iter)) |
| 2884 | ret = PTR_ERR(iter); |
| 2885 | else if (trace_flags & TRACE_ITER_LATENCY_FMT) |
| 2886 | iter->iter_flags |= TRACE_FILE_LAT_FMT; |
| 2887 | } |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2888 | return ret; |
| 2889 | } |
| 2890 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 2891 | static void * |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2892 | t_next(struct seq_file *m, void *v, loff_t *pos) |
| 2893 | { |
Li Zefan | f129e96 | 2009-06-24 09:53:44 +0800 | [diff] [blame] | 2894 | struct tracer *t = v; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2895 | |
| 2896 | (*pos)++; |
| 2897 | |
| 2898 | if (t) |
| 2899 | t = t->next; |
| 2900 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2901 | return t; |
| 2902 | } |
| 2903 | |
| 2904 | static void *t_start(struct seq_file *m, loff_t *pos) |
| 2905 | { |
Li Zefan | f129e96 | 2009-06-24 09:53:44 +0800 | [diff] [blame] | 2906 | struct tracer *t; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2907 | loff_t l = 0; |
| 2908 | |
| 2909 | mutex_lock(&trace_types_lock); |
Li Zefan | f129e96 | 2009-06-24 09:53:44 +0800 | [diff] [blame] | 2910 | 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] | 2911 | ; |
| 2912 | |
| 2913 | return t; |
| 2914 | } |
| 2915 | |
| 2916 | static void t_stop(struct seq_file *m, void *p) |
| 2917 | { |
| 2918 | mutex_unlock(&trace_types_lock); |
| 2919 | } |
| 2920 | |
| 2921 | static int t_show(struct seq_file *m, void *v) |
| 2922 | { |
| 2923 | struct tracer *t = v; |
| 2924 | |
| 2925 | if (!t) |
| 2926 | return 0; |
| 2927 | |
| 2928 | seq_printf(m, "%s", t->name); |
| 2929 | if (t->next) |
| 2930 | seq_putc(m, ' '); |
| 2931 | else |
| 2932 | seq_putc(m, '\n'); |
| 2933 | |
| 2934 | return 0; |
| 2935 | } |
| 2936 | |
James Morris | 88e9d34 | 2009-09-22 16:43:43 -0700 | [diff] [blame] | 2937 | static const struct seq_operations show_traces_seq_ops = { |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2938 | .start = t_start, |
| 2939 | .next = t_next, |
| 2940 | .stop = t_stop, |
| 2941 | .show = t_show, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2942 | }; |
| 2943 | |
| 2944 | static int show_traces_open(struct inode *inode, struct file *file) |
| 2945 | { |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 2946 | if (tracing_disabled) |
| 2947 | return -ENODEV; |
| 2948 | |
Li Zefan | f129e96 | 2009-06-24 09:53:44 +0800 | [diff] [blame] | 2949 | return seq_open(file, &show_traces_seq_ops); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2950 | } |
| 2951 | |
Steven Rostedt | 4acd4d0 | 2009-03-18 10:40:24 -0400 | [diff] [blame] | 2952 | static ssize_t |
| 2953 | tracing_write_stub(struct file *filp, const char __user *ubuf, |
| 2954 | size_t count, loff_t *ppos) |
| 2955 | { |
| 2956 | return count; |
| 2957 | } |
| 2958 | |
Slava Pestov | 364829b | 2010-11-24 15:13:16 -0800 | [diff] [blame] | 2959 | static loff_t tracing_seek(struct file *file, loff_t offset, int origin) |
| 2960 | { |
| 2961 | if (file->f_mode & FMODE_READ) |
| 2962 | return seq_lseek(file, offset, origin); |
| 2963 | else |
| 2964 | return 0; |
| 2965 | } |
| 2966 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 2967 | static const struct file_operations tracing_fops = { |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2968 | .open = tracing_open, |
| 2969 | .read = seq_read, |
Steven Rostedt | 4acd4d0 | 2009-03-18 10:40:24 -0400 | [diff] [blame] | 2970 | .write = tracing_write_stub, |
Slava Pestov | 364829b | 2010-11-24 15:13:16 -0800 | [diff] [blame] | 2971 | .llseek = tracing_seek, |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2972 | .release = tracing_release, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2973 | }; |
| 2974 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 2975 | static const struct file_operations show_traces_fops = { |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2976 | .open = show_traces_open, |
| 2977 | .read = seq_read, |
| 2978 | .release = seq_release, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 2979 | .llseek = seq_lseek, |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2980 | }; |
| 2981 | |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2982 | /* |
| 2983 | * Only trace on a CPU if the bitmask is set: |
| 2984 | */ |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 2985 | static cpumask_var_t tracing_cpumask; |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2986 | |
| 2987 | /* |
| 2988 | * The tracer itself will not take this lock, but still we want |
| 2989 | * to provide a consistent cpumask to user-space: |
| 2990 | */ |
| 2991 | static DEFINE_MUTEX(tracing_cpumask_update_lock); |
| 2992 | |
| 2993 | /* |
| 2994 | * Temporary storage for the character representation of the |
| 2995 | * CPU bitmask (and one more byte for the newline): |
| 2996 | */ |
| 2997 | static char mask_str[NR_CPUS + 1]; |
| 2998 | |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 2999 | static ssize_t |
| 3000 | tracing_cpumask_read(struct file *filp, char __user *ubuf, |
| 3001 | size_t count, loff_t *ppos) |
| 3002 | { |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3003 | int len; |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3004 | |
| 3005 | mutex_lock(&tracing_cpumask_update_lock); |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3006 | |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 3007 | len = cpumask_scnprintf(mask_str, count, tracing_cpumask); |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3008 | if (count - len < 2) { |
| 3009 | count = -EINVAL; |
| 3010 | goto out_err; |
| 3011 | } |
| 3012 | len += sprintf(mask_str + len, "\n"); |
| 3013 | count = simple_read_from_buffer(ubuf, count, ppos, mask_str, NR_CPUS+1); |
| 3014 | |
| 3015 | out_err: |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3016 | mutex_unlock(&tracing_cpumask_update_lock); |
| 3017 | |
| 3018 | return count; |
| 3019 | } |
| 3020 | |
| 3021 | static ssize_t |
| 3022 | tracing_cpumask_write(struct file *filp, const char __user *ubuf, |
| 3023 | size_t count, loff_t *ppos) |
| 3024 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3025 | struct trace_array *tr = filp->private_data; |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 3026 | cpumask_var_t tracing_cpumask_new; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3027 | int err, cpu; |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 3028 | |
| 3029 | if (!alloc_cpumask_var(&tracing_cpumask_new, GFP_KERNEL)) |
| 3030 | return -ENOMEM; |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3031 | |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 3032 | err = cpumask_parse_user(ubuf, count, tracing_cpumask_new); |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3033 | if (err) |
| 3034 | goto err_unlock; |
| 3035 | |
Li Zefan | 215368e | 2009-06-15 10:56:42 +0800 | [diff] [blame] | 3036 | mutex_lock(&tracing_cpumask_update_lock); |
| 3037 | |
Steven Rostedt | a5e2588 | 2008-12-02 15:34:05 -0500 | [diff] [blame] | 3038 | local_irq_disable(); |
Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 3039 | arch_spin_lock(&ftrace_max_lock); |
Steven Rostedt | ab46428 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 3040 | for_each_tracing_cpu(cpu) { |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3041 | /* |
| 3042 | * Increase/decrease the disabled counter if we are |
| 3043 | * about to flip a bit in the cpumask: |
| 3044 | */ |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 3045 | if (cpumask_test_cpu(cpu, tracing_cpumask) && |
| 3046 | !cpumask_test_cpu(cpu, tracing_cpumask_new)) { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3047 | atomic_inc(&per_cpu_ptr(tr->trace_buffer.data, cpu)->disabled); |
| 3048 | ring_buffer_record_disable_cpu(tr->trace_buffer.buffer, cpu); |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3049 | } |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 3050 | if (!cpumask_test_cpu(cpu, tracing_cpumask) && |
| 3051 | cpumask_test_cpu(cpu, tracing_cpumask_new)) { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3052 | atomic_dec(&per_cpu_ptr(tr->trace_buffer.data, cpu)->disabled); |
| 3053 | ring_buffer_record_enable_cpu(tr->trace_buffer.buffer, cpu); |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3054 | } |
| 3055 | } |
Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 3056 | arch_spin_unlock(&ftrace_max_lock); |
Steven Rostedt | a5e2588 | 2008-12-02 15:34:05 -0500 | [diff] [blame] | 3057 | local_irq_enable(); |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3058 | |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 3059 | cpumask_copy(tracing_cpumask, tracing_cpumask_new); |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3060 | |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3061 | mutex_unlock(&tracing_cpumask_update_lock); |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 3062 | free_cpumask_var(tracing_cpumask_new); |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3063 | |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3064 | return count; |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3065 | |
| 3066 | err_unlock: |
Li Zefan | 215368e | 2009-06-15 10:56:42 +0800 | [diff] [blame] | 3067 | free_cpumask_var(tracing_cpumask_new); |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3068 | |
| 3069 | return err; |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3070 | } |
| 3071 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 3072 | static const struct file_operations tracing_cpumask_fops = { |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3073 | .open = tracing_open_generic, |
| 3074 | .read = tracing_cpumask_read, |
| 3075 | .write = tracing_cpumask_write, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 3076 | .llseek = generic_file_llseek, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3077 | }; |
| 3078 | |
Li Zefan | fdb372e | 2009-12-08 11:15:59 +0800 | [diff] [blame] | 3079 | static int tracing_trace_options_show(struct seq_file *m, void *v) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3080 | { |
Steven Rostedt | d8e83d2 | 2009-02-26 23:55:58 -0500 | [diff] [blame] | 3081 | struct tracer_opt *trace_opts; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3082 | struct trace_array *tr = m->private; |
Steven Rostedt | d8e83d2 | 2009-02-26 23:55:58 -0500 | [diff] [blame] | 3083 | u32 tracer_flags; |
Steven Rostedt | d8e83d2 | 2009-02-26 23:55:58 -0500 | [diff] [blame] | 3084 | int i; |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 3085 | |
Steven Rostedt | d8e83d2 | 2009-02-26 23:55:58 -0500 | [diff] [blame] | 3086 | mutex_lock(&trace_types_lock); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3087 | tracer_flags = tr->current_trace->flags->val; |
| 3088 | trace_opts = tr->current_trace->flags->opts; |
Steven Rostedt | d8e83d2 | 2009-02-26 23:55:58 -0500 | [diff] [blame] | 3089 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3090 | for (i = 0; trace_options[i]; i++) { |
| 3091 | if (trace_flags & (1 << i)) |
Li Zefan | fdb372e | 2009-12-08 11:15:59 +0800 | [diff] [blame] | 3092 | seq_printf(m, "%s\n", trace_options[i]); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3093 | else |
Li Zefan | fdb372e | 2009-12-08 11:15:59 +0800 | [diff] [blame] | 3094 | seq_printf(m, "no%s\n", trace_options[i]); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3095 | } |
| 3096 | |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 3097 | for (i = 0; trace_opts[i].name; i++) { |
| 3098 | if (tracer_flags & trace_opts[i].bit) |
Li Zefan | fdb372e | 2009-12-08 11:15:59 +0800 | [diff] [blame] | 3099 | seq_printf(m, "%s\n", trace_opts[i].name); |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 3100 | else |
Li Zefan | fdb372e | 2009-12-08 11:15:59 +0800 | [diff] [blame] | 3101 | seq_printf(m, "no%s\n", trace_opts[i].name); |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 3102 | } |
Steven Rostedt | d8e83d2 | 2009-02-26 23:55:58 -0500 | [diff] [blame] | 3103 | mutex_unlock(&trace_types_lock); |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 3104 | |
Li Zefan | fdb372e | 2009-12-08 11:15:59 +0800 | [diff] [blame] | 3105 | return 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3106 | } |
| 3107 | |
Li Zefan | 8d18eaa | 2009-12-08 11:17:06 +0800 | [diff] [blame] | 3108 | static int __set_tracer_option(struct tracer *trace, |
| 3109 | struct tracer_flags *tracer_flags, |
| 3110 | struct tracer_opt *opts, int neg) |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 3111 | { |
Li Zefan | 8d18eaa | 2009-12-08 11:17:06 +0800 | [diff] [blame] | 3112 | int ret; |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 3113 | |
Li Zefan | 8d18eaa | 2009-12-08 11:17:06 +0800 | [diff] [blame] | 3114 | ret = trace->set_flag(tracer_flags->val, opts->bit, !neg); |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 3115 | if (ret) |
| 3116 | return ret; |
| 3117 | |
| 3118 | if (neg) |
Zhaolei | 7770841 | 2009-08-07 18:53:21 +0800 | [diff] [blame] | 3119 | tracer_flags->val &= ~opts->bit; |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 3120 | else |
Zhaolei | 7770841 | 2009-08-07 18:53:21 +0800 | [diff] [blame] | 3121 | tracer_flags->val |= opts->bit; |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 3122 | return 0; |
| 3123 | } |
| 3124 | |
Li Zefan | 8d18eaa | 2009-12-08 11:17:06 +0800 | [diff] [blame] | 3125 | /* Try to assign a tracer specific option */ |
| 3126 | static int set_tracer_option(struct tracer *trace, char *cmp, int neg) |
| 3127 | { |
| 3128 | struct tracer_flags *tracer_flags = trace->flags; |
| 3129 | struct tracer_opt *opts = NULL; |
| 3130 | int i; |
| 3131 | |
| 3132 | for (i = 0; tracer_flags->opts[i].name; i++) { |
| 3133 | opts = &tracer_flags->opts[i]; |
| 3134 | |
| 3135 | if (strcmp(cmp, opts->name) == 0) |
| 3136 | return __set_tracer_option(trace, trace->flags, |
| 3137 | opts, neg); |
| 3138 | } |
| 3139 | |
| 3140 | return -EINVAL; |
| 3141 | } |
| 3142 | |
Steven Rostedt (Red Hat) | 613f04a | 2013-03-14 15:03:53 -0400 | [diff] [blame] | 3143 | /* Some tracers require overwrite to stay enabled */ |
| 3144 | int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set) |
| 3145 | { |
| 3146 | if (tracer->enabled && (mask & TRACE_ITER_OVERWRITE) && !set) |
| 3147 | return -1; |
| 3148 | |
| 3149 | return 0; |
| 3150 | } |
| 3151 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3152 | 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] | 3153 | { |
| 3154 | /* do nothing if flag is already set */ |
| 3155 | if (!!(trace_flags & mask) == !!enabled) |
Steven Rostedt (Red Hat) | 613f04a | 2013-03-14 15:03:53 -0400 | [diff] [blame] | 3156 | return 0; |
| 3157 | |
| 3158 | /* Give the tracer a chance to approve the change */ |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3159 | if (tr->current_trace->flag_changed) |
| 3160 | 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] | 3161 | return -EINVAL; |
Steven Rostedt | af4617b | 2009-03-17 18:09:55 -0400 | [diff] [blame] | 3162 | |
| 3163 | if (enabled) |
| 3164 | trace_flags |= mask; |
| 3165 | else |
| 3166 | trace_flags &= ~mask; |
Li Zefan | e870e9a | 2010-07-02 11:07:32 +0800 | [diff] [blame] | 3167 | |
| 3168 | if (mask == TRACE_ITER_RECORD_CMD) |
| 3169 | trace_event_enable_cmd_record(enabled); |
David Sharp | 750912f | 2010-12-08 13:46:47 -0800 | [diff] [blame] | 3170 | |
Steven Rostedt (Red Hat) | 8090282 | 2013-03-14 14:20:54 -0400 | [diff] [blame] | 3171 | if (mask == TRACE_ITER_OVERWRITE) { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3172 | ring_buffer_change_overwrite(tr->trace_buffer.buffer, enabled); |
Steven Rostedt (Red Hat) | 8090282 | 2013-03-14 14:20:54 -0400 | [diff] [blame] | 3173 | #ifdef CONFIG_TRACER_MAX_TRACE |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3174 | ring_buffer_change_overwrite(tr->max_buffer.buffer, enabled); |
Steven Rostedt (Red Hat) | 8090282 | 2013-03-14 14:20:54 -0400 | [diff] [blame] | 3175 | #endif |
| 3176 | } |
Steven Rostedt | 8169883 | 2012-10-11 10:15:05 -0400 | [diff] [blame] | 3177 | |
| 3178 | if (mask == TRACE_ITER_PRINTK) |
| 3179 | trace_printk_start_stop_comm(enabled); |
Steven Rostedt (Red Hat) | 613f04a | 2013-03-14 15:03:53 -0400 | [diff] [blame] | 3180 | |
| 3181 | return 0; |
Steven Rostedt | af4617b | 2009-03-17 18:09:55 -0400 | [diff] [blame] | 3182 | } |
| 3183 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3184 | static int trace_set_options(struct trace_array *tr, char *option) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3185 | { |
Li Zefan | 8d18eaa | 2009-12-08 11:17:06 +0800 | [diff] [blame] | 3186 | char *cmp; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3187 | int neg = 0; |
Steven Rostedt (Red Hat) | 613f04a | 2013-03-14 15:03:53 -0400 | [diff] [blame] | 3188 | int ret = -ENODEV; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3189 | int i; |
| 3190 | |
Steven Rostedt | 7bcfaf5 | 2012-11-01 22:56:07 -0400 | [diff] [blame] | 3191 | cmp = strstrip(option); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3192 | |
Li Zefan | 8d18eaa | 2009-12-08 11:17:06 +0800 | [diff] [blame] | 3193 | if (strncmp(cmp, "no", 2) == 0) { |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3194 | neg = 1; |
| 3195 | cmp += 2; |
| 3196 | } |
| 3197 | |
Steven Rostedt (Red Hat) | 69d34da | 2013-03-14 13:50:56 -0400 | [diff] [blame] | 3198 | mutex_lock(&trace_types_lock); |
| 3199 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3200 | for (i = 0; trace_options[i]; i++) { |
Li Zefan | 8d18eaa | 2009-12-08 11:17:06 +0800 | [diff] [blame] | 3201 | if (strcmp(cmp, trace_options[i]) == 0) { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3202 | ret = set_tracer_flag(tr, 1 << i, !neg); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3203 | break; |
| 3204 | } |
| 3205 | } |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 3206 | |
| 3207 | /* 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] | 3208 | if (!trace_options[i]) |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3209 | ret = set_tracer_option(tr->current_trace, cmp, neg); |
Steven Rostedt (Red Hat) | 69d34da | 2013-03-14 13:50:56 -0400 | [diff] [blame] | 3210 | |
| 3211 | mutex_unlock(&trace_types_lock); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3212 | |
Steven Rostedt | 7bcfaf5 | 2012-11-01 22:56:07 -0400 | [diff] [blame] | 3213 | return ret; |
| 3214 | } |
| 3215 | |
| 3216 | static ssize_t |
| 3217 | tracing_trace_options_write(struct file *filp, const char __user *ubuf, |
| 3218 | size_t cnt, loff_t *ppos) |
| 3219 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3220 | struct seq_file *m = filp->private_data; |
| 3221 | struct trace_array *tr = m->private; |
Steven Rostedt | 7bcfaf5 | 2012-11-01 22:56:07 -0400 | [diff] [blame] | 3222 | char buf[64]; |
Steven Rostedt (Red Hat) | 613f04a | 2013-03-14 15:03:53 -0400 | [diff] [blame] | 3223 | int ret; |
Steven Rostedt | 7bcfaf5 | 2012-11-01 22:56:07 -0400 | [diff] [blame] | 3224 | |
| 3225 | if (cnt >= sizeof(buf)) |
| 3226 | return -EINVAL; |
| 3227 | |
| 3228 | if (copy_from_user(&buf, ubuf, cnt)) |
| 3229 | return -EFAULT; |
| 3230 | |
Steven Rostedt | a8dd217 | 2013-01-09 20:54:17 -0500 | [diff] [blame] | 3231 | buf[cnt] = 0; |
| 3232 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3233 | ret = trace_set_options(tr, buf); |
Steven Rostedt (Red Hat) | 613f04a | 2013-03-14 15:03:53 -0400 | [diff] [blame] | 3234 | if (ret < 0) |
| 3235 | return ret; |
Steven Rostedt | 7bcfaf5 | 2012-11-01 22:56:07 -0400 | [diff] [blame] | 3236 | |
Jiri Olsa | cf8517c | 2009-10-23 19:36:16 -0400 | [diff] [blame] | 3237 | *ppos += cnt; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3238 | |
| 3239 | return cnt; |
| 3240 | } |
| 3241 | |
Li Zefan | fdb372e | 2009-12-08 11:15:59 +0800 | [diff] [blame] | 3242 | static int tracing_trace_options_open(struct inode *inode, struct file *file) |
| 3243 | { |
| 3244 | if (tracing_disabled) |
| 3245 | return -ENODEV; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3246 | |
| 3247 | return single_open(file, tracing_trace_options_show, inode->i_private); |
Li Zefan | fdb372e | 2009-12-08 11:15:59 +0800 | [diff] [blame] | 3248 | } |
| 3249 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 3250 | static const struct file_operations tracing_iter_fops = { |
Li Zefan | fdb372e | 2009-12-08 11:15:59 +0800 | [diff] [blame] | 3251 | .open = tracing_trace_options_open, |
| 3252 | .read = seq_read, |
| 3253 | .llseek = seq_lseek, |
| 3254 | .release = single_release, |
Steven Rostedt | ee6bce5 | 2008-11-12 17:52:37 -0500 | [diff] [blame] | 3255 | .write = tracing_trace_options_write, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3256 | }; |
| 3257 | |
Ingo Molnar | 7bd2f24 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 3258 | static const char readme_msg[] = |
| 3259 | "tracing mini-HOWTO:\n\n" |
GeunSik Lim | 156f5a7 | 2009-06-02 15:01:37 +0900 | [diff] [blame] | 3260 | "# mount -t debugfs nodev /sys/kernel/debug\n\n" |
| 3261 | "# cat /sys/kernel/debug/tracing/available_tracers\n" |
Geunsik Lim | 1e42e83 | 2012-02-08 19:05:36 +0900 | [diff] [blame] | 3262 | "wakeup wakeup_rt preemptirqsoff preemptoff irqsoff function nop\n\n" |
GeunSik Lim | 156f5a7 | 2009-06-02 15:01:37 +0900 | [diff] [blame] | 3263 | "# cat /sys/kernel/debug/tracing/current_tracer\n" |
Nikanth Karthikesan | bc2b687 | 2009-03-23 11:58:31 +0530 | [diff] [blame] | 3264 | "nop\n" |
Geunsik Lim | 1e42e83 | 2012-02-08 19:05:36 +0900 | [diff] [blame] | 3265 | "# echo wakeup > /sys/kernel/debug/tracing/current_tracer\n" |
GeunSik Lim | 156f5a7 | 2009-06-02 15:01:37 +0900 | [diff] [blame] | 3266 | "# cat /sys/kernel/debug/tracing/current_tracer\n" |
Geunsik Lim | 1e42e83 | 2012-02-08 19:05:36 +0900 | [diff] [blame] | 3267 | "wakeup\n" |
GeunSik Lim | 156f5a7 | 2009-06-02 15:01:37 +0900 | [diff] [blame] | 3268 | "# cat /sys/kernel/debug/tracing/trace_options\n" |
Ingo Molnar | 7bd2f24 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 3269 | "noprint-parent nosym-offset nosym-addr noverbose\n" |
GeunSik Lim | 156f5a7 | 2009-06-02 15:01:37 +0900 | [diff] [blame] | 3270 | "# echo print-parent > /sys/kernel/debug/tracing/trace_options\n" |
Geunsik Lim | 9b5f8b3 | 2011-08-12 14:30:22 +0900 | [diff] [blame] | 3271 | "# echo 1 > /sys/kernel/debug/tracing/tracing_on\n" |
GeunSik Lim | 156f5a7 | 2009-06-02 15:01:37 +0900 | [diff] [blame] | 3272 | "# cat /sys/kernel/debug/tracing/trace > /tmp/trace.txt\n" |
Geunsik Lim | 9b5f8b3 | 2011-08-12 14:30:22 +0900 | [diff] [blame] | 3273 | "# echo 0 > /sys/kernel/debug/tracing/tracing_on\n" |
Ingo Molnar | 7bd2f24 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 3274 | ; |
| 3275 | |
| 3276 | static ssize_t |
| 3277 | tracing_readme_read(struct file *filp, char __user *ubuf, |
| 3278 | size_t cnt, loff_t *ppos) |
| 3279 | { |
| 3280 | return simple_read_from_buffer(ubuf, cnt, ppos, |
| 3281 | readme_msg, strlen(readme_msg)); |
| 3282 | } |
| 3283 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 3284 | static const struct file_operations tracing_readme_fops = { |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3285 | .open = tracing_open_generic, |
| 3286 | .read = tracing_readme_read, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 3287 | .llseek = generic_file_llseek, |
Ingo Molnar | 7bd2f24 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 3288 | }; |
| 3289 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3290 | static ssize_t |
Avadh Patel | 69abe6a | 2009-04-10 16:04:48 -0400 | [diff] [blame] | 3291 | tracing_saved_cmdlines_read(struct file *file, char __user *ubuf, |
| 3292 | size_t cnt, loff_t *ppos) |
| 3293 | { |
| 3294 | char *buf_comm; |
| 3295 | char *file_buf; |
| 3296 | char *buf; |
| 3297 | int len = 0; |
| 3298 | int pid; |
| 3299 | int i; |
| 3300 | |
| 3301 | file_buf = kmalloc(SAVED_CMDLINES*(16+TASK_COMM_LEN), GFP_KERNEL); |
| 3302 | if (!file_buf) |
| 3303 | return -ENOMEM; |
| 3304 | |
| 3305 | buf_comm = kmalloc(TASK_COMM_LEN, GFP_KERNEL); |
| 3306 | if (!buf_comm) { |
| 3307 | kfree(file_buf); |
| 3308 | return -ENOMEM; |
| 3309 | } |
| 3310 | |
| 3311 | buf = file_buf; |
| 3312 | |
| 3313 | for (i = 0; i < SAVED_CMDLINES; i++) { |
| 3314 | int r; |
| 3315 | |
| 3316 | pid = map_cmdline_to_pid[i]; |
| 3317 | if (pid == -1 || pid == NO_CMDLINE_MAP) |
| 3318 | continue; |
| 3319 | |
| 3320 | trace_find_cmdline(pid, buf_comm); |
| 3321 | r = sprintf(buf, "%d %s\n", pid, buf_comm); |
| 3322 | buf += r; |
| 3323 | len += r; |
| 3324 | } |
| 3325 | |
| 3326 | len = simple_read_from_buffer(ubuf, cnt, ppos, |
| 3327 | file_buf, len); |
| 3328 | |
| 3329 | kfree(file_buf); |
| 3330 | kfree(buf_comm); |
| 3331 | |
| 3332 | return len; |
| 3333 | } |
| 3334 | |
| 3335 | static const struct file_operations tracing_saved_cmdlines_fops = { |
| 3336 | .open = tracing_open_generic, |
| 3337 | .read = tracing_saved_cmdlines_read, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 3338 | .llseek = generic_file_llseek, |
Avadh Patel | 69abe6a | 2009-04-10 16:04:48 -0400 | [diff] [blame] | 3339 | }; |
| 3340 | |
| 3341 | static ssize_t |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3342 | tracing_set_trace_read(struct file *filp, char __user *ubuf, |
| 3343 | size_t cnt, loff_t *ppos) |
| 3344 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3345 | struct trace_array *tr = filp->private_data; |
Li Zefan | ee6c2c1 | 2009-09-18 14:06:47 +0800 | [diff] [blame] | 3346 | char buf[MAX_TRACER_SIZE+2]; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3347 | int r; |
| 3348 | |
| 3349 | mutex_lock(&trace_types_lock); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3350 | r = sprintf(buf, "%s\n", tr->current_trace->name); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3351 | mutex_unlock(&trace_types_lock); |
| 3352 | |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3353 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, r); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3354 | } |
| 3355 | |
Arnaldo Carvalho de Melo | b6f11df | 2009-02-05 18:02:00 -0200 | [diff] [blame] | 3356 | int tracer_init(struct tracer *t, struct trace_array *tr) |
| 3357 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3358 | tracing_reset_online_cpus(&tr->trace_buffer); |
Arnaldo Carvalho de Melo | b6f11df | 2009-02-05 18:02:00 -0200 | [diff] [blame] | 3359 | return t->init(tr); |
| 3360 | } |
| 3361 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3362 | static void set_buffer_entries(struct trace_buffer *buf, unsigned long val) |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 3363 | { |
| 3364 | int cpu; |
Steven Rostedt (Red Hat) | 737223f | 2013-03-05 21:13:47 -0500 | [diff] [blame] | 3365 | |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 3366 | for_each_tracing_cpu(cpu) |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3367 | per_cpu_ptr(buf->data, cpu)->entries = val; |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 3368 | } |
| 3369 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3370 | #ifdef CONFIG_TRACER_MAX_TRACE |
Hiraku Toyooka | d60da50 | 2012-10-17 11:56:16 +0900 | [diff] [blame] | 3371 | /* 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] | 3372 | static int resize_buffer_duplicate_size(struct trace_buffer *trace_buf, |
| 3373 | struct trace_buffer *size_buf, int cpu_id) |
Hiraku Toyooka | d60da50 | 2012-10-17 11:56:16 +0900 | [diff] [blame] | 3374 | { |
| 3375 | int cpu, ret = 0; |
| 3376 | |
| 3377 | if (cpu_id == RING_BUFFER_ALL_CPUS) { |
| 3378 | for_each_tracing_cpu(cpu) { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3379 | ret = ring_buffer_resize(trace_buf->buffer, |
| 3380 | per_cpu_ptr(size_buf->data, cpu)->entries, cpu); |
Hiraku Toyooka | d60da50 | 2012-10-17 11:56:16 +0900 | [diff] [blame] | 3381 | if (ret < 0) |
| 3382 | break; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3383 | per_cpu_ptr(trace_buf->data, cpu)->entries = |
| 3384 | per_cpu_ptr(size_buf->data, cpu)->entries; |
Hiraku Toyooka | d60da50 | 2012-10-17 11:56:16 +0900 | [diff] [blame] | 3385 | } |
| 3386 | } else { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3387 | ret = ring_buffer_resize(trace_buf->buffer, |
| 3388 | per_cpu_ptr(size_buf->data, cpu_id)->entries, cpu_id); |
Hiraku Toyooka | d60da50 | 2012-10-17 11:56:16 +0900 | [diff] [blame] | 3389 | if (ret == 0) |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3390 | per_cpu_ptr(trace_buf->data, cpu_id)->entries = |
| 3391 | per_cpu_ptr(size_buf->data, cpu_id)->entries; |
Hiraku Toyooka | d60da50 | 2012-10-17 11:56:16 +0900 | [diff] [blame] | 3392 | } |
| 3393 | |
| 3394 | return ret; |
| 3395 | } |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3396 | #endif /* CONFIG_TRACER_MAX_TRACE */ |
Hiraku Toyooka | d60da50 | 2012-10-17 11:56:16 +0900 | [diff] [blame] | 3397 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3398 | static int __tracing_resize_ring_buffer(struct trace_array *tr, |
| 3399 | unsigned long size, int cpu) |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 3400 | { |
| 3401 | int ret; |
| 3402 | |
| 3403 | /* |
| 3404 | * If kernel or user changes the size of the ring buffer |
Steven Rostedt | a123c52 | 2009-03-12 11:21:08 -0400 | [diff] [blame] | 3405 | * we use the size that was given, and we can forget about |
| 3406 | * expanding it later. |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 3407 | */ |
Steven Rostedt (Red Hat) | 55034cd | 2013-03-07 22:48:09 -0500 | [diff] [blame] | 3408 | ring_buffer_expanded = true; |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 3409 | |
Steven Rostedt | b382ede6 | 2012-10-10 21:44:34 -0400 | [diff] [blame] | 3410 | /* May be called before buffers are initialized */ |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3411 | if (!tr->trace_buffer.buffer) |
Steven Rostedt | b382ede6 | 2012-10-10 21:44:34 -0400 | [diff] [blame] | 3412 | return 0; |
| 3413 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3414 | ret = ring_buffer_resize(tr->trace_buffer.buffer, size, cpu); |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 3415 | if (ret < 0) |
| 3416 | return ret; |
| 3417 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3418 | #ifdef CONFIG_TRACER_MAX_TRACE |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3419 | if (!(tr->flags & TRACE_ARRAY_FL_GLOBAL) || |
| 3420 | !tr->current_trace->use_max_tr) |
KOSAKI Motohiro | ef710e1 | 2010-07-01 14:34:35 +0900 | [diff] [blame] | 3421 | goto out; |
| 3422 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3423 | ret = ring_buffer_resize(tr->max_buffer.buffer, size, cpu); |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 3424 | if (ret < 0) { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3425 | int r = resize_buffer_duplicate_size(&tr->trace_buffer, |
| 3426 | &tr->trace_buffer, cpu); |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 3427 | if (r < 0) { |
Steven Rostedt | a123c52 | 2009-03-12 11:21:08 -0400 | [diff] [blame] | 3428 | /* |
| 3429 | * AARGH! We are left with different |
| 3430 | * size max buffer!!!! |
| 3431 | * The max buffer is our "snapshot" buffer. |
| 3432 | * When a tracer needs a snapshot (one of the |
| 3433 | * latency tracers), it swaps the max buffer |
| 3434 | * with the saved snap shot. We succeeded to |
| 3435 | * update the size of the main buffer, but failed to |
| 3436 | * update the size of the max buffer. But when we tried |
| 3437 | * to reset the main buffer to the original size, we |
| 3438 | * failed there too. This is very unlikely to |
| 3439 | * happen, but if it does, warn and kill all |
| 3440 | * tracing. |
| 3441 | */ |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 3442 | WARN_ON(1); |
| 3443 | tracing_disabled = 1; |
| 3444 | } |
| 3445 | return ret; |
| 3446 | } |
| 3447 | |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 3448 | if (cpu == RING_BUFFER_ALL_CPUS) |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3449 | set_buffer_entries(&tr->max_buffer, size); |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 3450 | else |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3451 | per_cpu_ptr(tr->max_buffer.data, cpu)->entries = size; |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 3452 | |
KOSAKI Motohiro | ef710e1 | 2010-07-01 14:34:35 +0900 | [diff] [blame] | 3453 | out: |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3454 | #endif /* CONFIG_TRACER_MAX_TRACE */ |
| 3455 | |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 3456 | if (cpu == RING_BUFFER_ALL_CPUS) |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3457 | set_buffer_entries(&tr->trace_buffer, size); |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 3458 | else |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3459 | per_cpu_ptr(tr->trace_buffer.data, cpu)->entries = size; |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 3460 | |
| 3461 | return ret; |
| 3462 | } |
| 3463 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3464 | static ssize_t tracing_resize_ring_buffer(struct trace_array *tr, |
| 3465 | unsigned long size, int cpu_id) |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 3466 | { |
Vaibhav Nagarnaik | 83f4031 | 2012-05-03 18:59:50 -0700 | [diff] [blame] | 3467 | int ret = size; |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 3468 | |
| 3469 | mutex_lock(&trace_types_lock); |
| 3470 | |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 3471 | if (cpu_id != RING_BUFFER_ALL_CPUS) { |
| 3472 | /* make sure, this cpu is enabled in the mask */ |
| 3473 | if (!cpumask_test_cpu(cpu_id, tracing_buffer_mask)) { |
| 3474 | ret = -EINVAL; |
| 3475 | goto out; |
| 3476 | } |
| 3477 | } |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 3478 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3479 | ret = __tracing_resize_ring_buffer(tr, size, cpu_id); |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 3480 | if (ret < 0) |
| 3481 | ret = -ENOMEM; |
| 3482 | |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 3483 | out: |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 3484 | mutex_unlock(&trace_types_lock); |
| 3485 | |
| 3486 | return ret; |
| 3487 | } |
| 3488 | |
KOSAKI Motohiro | ef710e1 | 2010-07-01 14:34:35 +0900 | [diff] [blame] | 3489 | |
Steven Rostedt | 1852fcc | 2009-03-11 14:33:00 -0400 | [diff] [blame] | 3490 | /** |
| 3491 | * tracing_update_buffers - used by tracing facility to expand ring buffers |
| 3492 | * |
| 3493 | * To save on memory when the tracing is never used on a system with it |
| 3494 | * configured in. The ring buffers are set to a minimum size. But once |
| 3495 | * a user starts to use the tracing facility, then they need to grow |
| 3496 | * to their default size. |
| 3497 | * |
| 3498 | * This function is to be called when a tracer is about to be used. |
| 3499 | */ |
| 3500 | int tracing_update_buffers(void) |
| 3501 | { |
| 3502 | int ret = 0; |
| 3503 | |
Steven Rostedt | 1027fcb | 2009-03-12 11:33:20 -0400 | [diff] [blame] | 3504 | mutex_lock(&trace_types_lock); |
Steven Rostedt | 1852fcc | 2009-03-11 14:33:00 -0400 | [diff] [blame] | 3505 | if (!ring_buffer_expanded) |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3506 | ret = __tracing_resize_ring_buffer(&global_trace, trace_buf_size, |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 3507 | RING_BUFFER_ALL_CPUS); |
Steven Rostedt | 1027fcb | 2009-03-12 11:33:20 -0400 | [diff] [blame] | 3508 | mutex_unlock(&trace_types_lock); |
Steven Rostedt | 1852fcc | 2009-03-11 14:33:00 -0400 | [diff] [blame] | 3509 | |
| 3510 | return ret; |
| 3511 | } |
| 3512 | |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 3513 | struct trace_option_dentry; |
| 3514 | |
| 3515 | static struct trace_option_dentry * |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3516 | create_trace_option_files(struct trace_array *tr, struct tracer *tracer); |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 3517 | |
| 3518 | static void |
| 3519 | destroy_trace_option_files(struct trace_option_dentry *topts); |
| 3520 | |
Steven Rostedt | b2821ae | 2009-02-02 21:38:32 -0500 | [diff] [blame] | 3521 | static int tracing_set_tracer(const char *buf) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3522 | { |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 3523 | static struct trace_option_dentry *topts; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3524 | struct trace_array *tr = &global_trace; |
| 3525 | struct tracer *t; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3526 | #ifdef CONFIG_TRACER_MAX_TRACE |
Steven Rostedt | 34600f0 | 2013-01-22 13:35:11 -0500 | [diff] [blame] | 3527 | bool had_max_tr; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3528 | #endif |
Peter Zijlstra | d9e5407 | 2008-11-01 19:57:37 +0100 | [diff] [blame] | 3529 | int ret = 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3530 | |
Steven Rostedt | 1027fcb | 2009-03-12 11:33:20 -0400 | [diff] [blame] | 3531 | mutex_lock(&trace_types_lock); |
| 3532 | |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 3533 | if (!ring_buffer_expanded) { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3534 | ret = __tracing_resize_ring_buffer(tr, trace_buf_size, |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 3535 | RING_BUFFER_ALL_CPUS); |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 3536 | if (ret < 0) |
Frederic Weisbecker | 59f586d | 2009-03-15 22:10:39 +0100 | [diff] [blame] | 3537 | goto out; |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 3538 | ret = 0; |
| 3539 | } |
| 3540 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3541 | for (t = trace_types; t; t = t->next) { |
| 3542 | if (strcmp(t->name, buf) == 0) |
| 3543 | break; |
| 3544 | } |
Frederic Weisbecker | c2931e0 | 2008-10-04 22:04:44 +0200 | [diff] [blame] | 3545 | if (!t) { |
| 3546 | ret = -EINVAL; |
| 3547 | goto out; |
| 3548 | } |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3549 | if (t == tr->current_trace) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3550 | goto out; |
| 3551 | |
Steven Rostedt | 9f029e8 | 2008-11-12 15:24:24 -0500 | [diff] [blame] | 3552 | trace_branch_disable(); |
Steven Rostedt (Red Hat) | 613f04a | 2013-03-14 15:03:53 -0400 | [diff] [blame] | 3553 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3554 | tr->current_trace->enabled = false; |
Steven Rostedt (Red Hat) | 613f04a | 2013-03-14 15:03:53 -0400 | [diff] [blame] | 3555 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3556 | if (tr->current_trace->reset) |
| 3557 | tr->current_trace->reset(tr); |
Steven Rostedt | 34600f0 | 2013-01-22 13:35:11 -0500 | [diff] [blame] | 3558 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3559 | /* Current trace needs to be nop_trace before synchronize_sched */ |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3560 | tr->current_trace = &nop_trace; |
Steven Rostedt | 34600f0 | 2013-01-22 13:35:11 -0500 | [diff] [blame] | 3561 | |
Steven Rostedt (Red Hat) | 45ad21c | 2013-03-05 18:25:02 -0500 | [diff] [blame] | 3562 | #ifdef CONFIG_TRACER_MAX_TRACE |
| 3563 | had_max_tr = tr->allocated_snapshot; |
| 3564 | |
Steven Rostedt | 34600f0 | 2013-01-22 13:35:11 -0500 | [diff] [blame] | 3565 | if (had_max_tr && !t->use_max_tr) { |
| 3566 | /* |
| 3567 | * We need to make sure that the update_max_tr sees that |
| 3568 | * current_trace changed to nop_trace to keep it from |
| 3569 | * swapping the buffers after we resize it. |
| 3570 | * The update_max_tr is called from interrupts disabled |
| 3571 | * so a synchronized_sched() is sufficient. |
| 3572 | */ |
| 3573 | synchronize_sched(); |
KOSAKI Motohiro | ef710e1 | 2010-07-01 14:34:35 +0900 | [diff] [blame] | 3574 | /* |
| 3575 | * We don't free the ring buffer. instead, resize it because |
| 3576 | * The max_tr ring buffer has some state (e.g. ring->clock) and |
| 3577 | * we want preserve it. |
| 3578 | */ |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3579 | ring_buffer_resize(tr->max_buffer.buffer, 1, RING_BUFFER_ALL_CPUS); |
| 3580 | set_buffer_entries(&tr->max_buffer, 1); |
| 3581 | tracing_reset_online_cpus(&tr->max_buffer); |
Steven Rostedt (Red Hat) | 45ad21c | 2013-03-05 18:25:02 -0500 | [diff] [blame] | 3582 | tr->allocated_snapshot = false; |
KOSAKI Motohiro | ef710e1 | 2010-07-01 14:34:35 +0900 | [diff] [blame] | 3583 | } |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3584 | #endif |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 3585 | destroy_trace_option_files(topts); |
| 3586 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3587 | topts = create_trace_option_files(tr, t); |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3588 | |
| 3589 | #ifdef CONFIG_TRACER_MAX_TRACE |
Steven Rostedt | 34600f0 | 2013-01-22 13:35:11 -0500 | [diff] [blame] | 3590 | if (t->use_max_tr && !had_max_tr) { |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 3591 | /* we need to make per cpu buffer sizes equivalent */ |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3592 | ret = resize_buffer_duplicate_size(&tr->max_buffer, &tr->trace_buffer, |
Hiraku Toyooka | d60da50 | 2012-10-17 11:56:16 +0900 | [diff] [blame] | 3593 | RING_BUFFER_ALL_CPUS); |
| 3594 | if (ret < 0) |
| 3595 | goto out; |
Steven Rostedt (Red Hat) | 45ad21c | 2013-03-05 18:25:02 -0500 | [diff] [blame] | 3596 | tr->allocated_snapshot = true; |
KOSAKI Motohiro | ef710e1 | 2010-07-01 14:34:35 +0900 | [diff] [blame] | 3597 | } |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3598 | #endif |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 3599 | |
Frederic Weisbecker | 1c80025 | 2008-11-16 05:57:26 +0100 | [diff] [blame] | 3600 | if (t->init) { |
Arnaldo Carvalho de Melo | b6f11df | 2009-02-05 18:02:00 -0200 | [diff] [blame] | 3601 | ret = tracer_init(t, tr); |
Frederic Weisbecker | 1c80025 | 2008-11-16 05:57:26 +0100 | [diff] [blame] | 3602 | if (ret) |
| 3603 | goto out; |
| 3604 | } |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3605 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3606 | tr->current_trace = t; |
| 3607 | tr->current_trace->enabled = true; |
Steven Rostedt | 9f029e8 | 2008-11-12 15:24:24 -0500 | [diff] [blame] | 3608 | trace_branch_enable(tr); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3609 | out: |
| 3610 | mutex_unlock(&trace_types_lock); |
| 3611 | |
Peter Zijlstra | d9e5407 | 2008-11-01 19:57:37 +0100 | [diff] [blame] | 3612 | return ret; |
| 3613 | } |
| 3614 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3615 | static ssize_t |
| 3616 | tracing_set_trace_write(struct file *filp, const char __user *ubuf, |
| 3617 | size_t cnt, loff_t *ppos) |
| 3618 | { |
Li Zefan | ee6c2c1 | 2009-09-18 14:06:47 +0800 | [diff] [blame] | 3619 | char buf[MAX_TRACER_SIZE+1]; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3620 | int i; |
| 3621 | size_t ret; |
Frederic Weisbecker | e6e7a65 | 2008-11-16 05:53:19 +0100 | [diff] [blame] | 3622 | int err; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3623 | |
Steven Rostedt | 60063a6 | 2008-10-28 10:44:24 -0400 | [diff] [blame] | 3624 | ret = cnt; |
| 3625 | |
Li Zefan | ee6c2c1 | 2009-09-18 14:06:47 +0800 | [diff] [blame] | 3626 | if (cnt > MAX_TRACER_SIZE) |
| 3627 | cnt = MAX_TRACER_SIZE; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3628 | |
| 3629 | if (copy_from_user(&buf, ubuf, cnt)) |
| 3630 | return -EFAULT; |
| 3631 | |
| 3632 | buf[cnt] = 0; |
| 3633 | |
| 3634 | /* strip ending whitespace. */ |
| 3635 | for (i = cnt - 1; i > 0 && isspace(buf[i]); i--) |
| 3636 | buf[i] = 0; |
| 3637 | |
Frederic Weisbecker | e6e7a65 | 2008-11-16 05:53:19 +0100 | [diff] [blame] | 3638 | err = tracing_set_tracer(buf); |
| 3639 | if (err) |
| 3640 | return err; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3641 | |
Jiri Olsa | cf8517c | 2009-10-23 19:36:16 -0400 | [diff] [blame] | 3642 | *ppos += ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3643 | |
Frederic Weisbecker | c2931e0 | 2008-10-04 22:04:44 +0200 | [diff] [blame] | 3644 | return ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3645 | } |
| 3646 | |
| 3647 | static ssize_t |
| 3648 | tracing_max_lat_read(struct file *filp, char __user *ubuf, |
| 3649 | size_t cnt, loff_t *ppos) |
| 3650 | { |
| 3651 | unsigned long *ptr = filp->private_data; |
| 3652 | char buf[64]; |
| 3653 | int r; |
| 3654 | |
Steven Rostedt | cffae43 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 3655 | r = snprintf(buf, sizeof(buf), "%ld\n", |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3656 | *ptr == (unsigned long)-1 ? -1 : nsecs_to_usecs(*ptr)); |
Steven Rostedt | cffae43 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 3657 | if (r > sizeof(buf)) |
| 3658 | r = sizeof(buf); |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3659 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, r); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3660 | } |
| 3661 | |
| 3662 | static ssize_t |
| 3663 | tracing_max_lat_write(struct file *filp, const char __user *ubuf, |
| 3664 | size_t cnt, loff_t *ppos) |
| 3665 | { |
Hannes Eder | 5e39841 | 2009-02-10 19:44:34 +0100 | [diff] [blame] | 3666 | unsigned long *ptr = filp->private_data; |
Hannes Eder | 5e39841 | 2009-02-10 19:44:34 +0100 | [diff] [blame] | 3667 | unsigned long val; |
Steven Rostedt | c6caeeb | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 3668 | int ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3669 | |
Peter Huewe | 22fe9b5 | 2011-06-07 21:58:27 +0200 | [diff] [blame] | 3670 | ret = kstrtoul_from_user(ubuf, cnt, 10, &val); |
| 3671 | if (ret) |
Steven Rostedt | c6caeeb | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 3672 | return ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3673 | |
| 3674 | *ptr = val * 1000; |
| 3675 | |
| 3676 | return cnt; |
| 3677 | } |
| 3678 | |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3679 | static int tracing_open_pipe(struct inode *inode, struct file *filp) |
| 3680 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3681 | struct trace_cpu *tc = inode->i_private; |
| 3682 | struct trace_array *tr = tc->tr; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3683 | struct trace_iterator *iter; |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 3684 | int ret = 0; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3685 | |
| 3686 | if (tracing_disabled) |
| 3687 | return -ENODEV; |
| 3688 | |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 3689 | mutex_lock(&trace_types_lock); |
| 3690 | |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3691 | /* create a buffer to store the information to pass to userspace */ |
| 3692 | iter = kzalloc(sizeof(*iter), GFP_KERNEL); |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 3693 | if (!iter) { |
| 3694 | ret = -ENOMEM; |
| 3695 | goto out; |
| 3696 | } |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3697 | |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 3698 | /* |
| 3699 | * We make a copy of the current tracer to avoid concurrent |
| 3700 | * changes on it while we are reading. |
| 3701 | */ |
| 3702 | iter->trace = kmalloc(sizeof(*iter->trace), GFP_KERNEL); |
| 3703 | if (!iter->trace) { |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 3704 | ret = -ENOMEM; |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 3705 | goto fail; |
| 3706 | } |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3707 | *iter->trace = *tr->current_trace; |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 3708 | |
| 3709 | if (!alloc_cpumask_var(&iter->started, GFP_KERNEL)) { |
| 3710 | ret = -ENOMEM; |
| 3711 | goto fail; |
Rusty Russell | 4462344 | 2009-01-01 10:12:23 +1030 | [diff] [blame] | 3712 | } |
| 3713 | |
Steven Rostedt | a309720 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 3714 | /* trace pipe does not show start of buffer */ |
Rusty Russell | 4462344 | 2009-01-01 10:12:23 +1030 | [diff] [blame] | 3715 | cpumask_setall(iter->started); |
Steven Rostedt | a309720 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 3716 | |
Steven Rostedt | 112f38a7 | 2009-06-01 15:16:05 -0400 | [diff] [blame] | 3717 | if (trace_flags & TRACE_ITER_LATENCY_FMT) |
| 3718 | iter->iter_flags |= TRACE_FILE_LAT_FMT; |
| 3719 | |
David Sharp | 8be0709 | 2012-11-13 12:18:22 -0800 | [diff] [blame] | 3720 | /* Output in nanoseconds only if we are using a clock in nanoseconds. */ |
| 3721 | if (trace_clocks[trace_clock_id].in_ns) |
| 3722 | iter->iter_flags |= TRACE_FILE_TIME_IN_NS; |
| 3723 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3724 | iter->cpu_file = tc->cpu; |
| 3725 | iter->tr = tc->tr; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3726 | iter->trace_buffer = &tc->tr->trace_buffer; |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 3727 | mutex_init(&iter->mutex); |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3728 | filp->private_data = iter; |
| 3729 | |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 3730 | if (iter->trace->pipe_open) |
| 3731 | iter->trace->pipe_open(iter); |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 3732 | |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 3733 | nonseekable_open(inode, filp); |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 3734 | out: |
| 3735 | mutex_unlock(&trace_types_lock); |
| 3736 | return ret; |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 3737 | |
| 3738 | fail: |
| 3739 | kfree(iter->trace); |
| 3740 | kfree(iter); |
| 3741 | mutex_unlock(&trace_types_lock); |
| 3742 | return ret; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3743 | } |
| 3744 | |
| 3745 | static int tracing_release_pipe(struct inode *inode, struct file *file) |
| 3746 | { |
| 3747 | struct trace_iterator *iter = file->private_data; |
| 3748 | |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 3749 | mutex_lock(&trace_types_lock); |
| 3750 | |
Steven Rostedt | 29bf4a5 | 2009-12-09 12:37:43 -0500 | [diff] [blame] | 3751 | if (iter->trace->pipe_close) |
Steven Rostedt | c521efd | 2009-12-07 09:06:24 -0500 | [diff] [blame] | 3752 | iter->trace->pipe_close(iter); |
| 3753 | |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 3754 | mutex_unlock(&trace_types_lock); |
| 3755 | |
Rusty Russell | 4462344 | 2009-01-01 10:12:23 +1030 | [diff] [blame] | 3756 | free_cpumask_var(iter->started); |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 3757 | mutex_destroy(&iter->mutex); |
| 3758 | kfree(iter->trace); |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3759 | kfree(iter); |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3760 | |
| 3761 | return 0; |
| 3762 | } |
| 3763 | |
Soeren Sandmann Pedersen | 2a2cc8f | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 3764 | static unsigned int |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 3765 | 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] | 3766 | { |
Steven Rostedt (Red Hat) | 1569345 | 2013-02-28 19:59:17 -0500 | [diff] [blame] | 3767 | /* Iterators are static, they should be filled or empty */ |
| 3768 | if (trace_buffer_iter(iter, iter->cpu_file)) |
| 3769 | return POLLIN | POLLRDNORM; |
| 3770 | |
| 3771 | if (trace_flags & TRACE_ITER_BLOCK) |
Soeren Sandmann Pedersen | 2a2cc8f | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 3772 | /* |
| 3773 | * Always select as readable when in blocking mode |
| 3774 | */ |
| 3775 | return POLLIN | POLLRDNORM; |
Steven Rostedt (Red Hat) | 1569345 | 2013-02-28 19:59:17 -0500 | [diff] [blame] | 3776 | else |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3777 | 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] | 3778 | filp, poll_table); |
Soeren Sandmann Pedersen | 2a2cc8f | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 3779 | } |
| 3780 | |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 3781 | static unsigned int |
| 3782 | tracing_poll_pipe(struct file *filp, poll_table *poll_table) |
| 3783 | { |
| 3784 | struct trace_iterator *iter = filp->private_data; |
| 3785 | |
| 3786 | return trace_poll(iter, filp, poll_table); |
| 3787 | } |
| 3788 | |
Frederic Weisbecker | 6eaaa5d | 2009-02-11 02:25:00 +0100 | [diff] [blame] | 3789 | /* |
| 3790 | * This is a make-shift waitqueue. |
| 3791 | * A tracer might use this callback on some rare cases: |
| 3792 | * |
| 3793 | * 1) the current tracer might hold the runqueue lock when it wakes up |
| 3794 | * a reader, hence a deadlock (sched, function, and function graph tracers) |
| 3795 | * 2) the function tracers, trace all functions, we don't want |
| 3796 | * the overhead of calling wake_up and friends |
| 3797 | * (and tracing them too) |
| 3798 | * |
| 3799 | * Anyway, this is really very primitive wakeup. |
| 3800 | */ |
| 3801 | void poll_wait_pipe(struct trace_iterator *iter) |
| 3802 | { |
| 3803 | set_current_state(TASK_INTERRUPTIBLE); |
| 3804 | /* sleep for 100 msecs, and try again. */ |
| 3805 | schedule_timeout(HZ / 10); |
| 3806 | } |
| 3807 | |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 3808 | /* Must be called with trace_types_lock mutex held. */ |
| 3809 | static int tracing_wait_pipe(struct file *filp) |
| 3810 | { |
| 3811 | struct trace_iterator *iter = filp->private_data; |
| 3812 | |
| 3813 | while (trace_empty(iter)) { |
| 3814 | |
| 3815 | if ((filp->f_flags & O_NONBLOCK)) { |
| 3816 | return -EAGAIN; |
| 3817 | } |
| 3818 | |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 3819 | mutex_unlock(&iter->mutex); |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 3820 | |
Frederic Weisbecker | 6eaaa5d | 2009-02-11 02:25:00 +0100 | [diff] [blame] | 3821 | iter->trace->wait_pipe(iter); |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 3822 | |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 3823 | mutex_lock(&iter->mutex); |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 3824 | |
Frederic Weisbecker | 6eaaa5d | 2009-02-11 02:25:00 +0100 | [diff] [blame] | 3825 | if (signal_pending(current)) |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 3826 | return -EINTR; |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 3827 | |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 3828 | /* |
Liu Bo | 250bfd3 | 2013-01-14 10:54:11 +0800 | [diff] [blame] | 3829 | * We block until we read something and tracing is disabled. |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 3830 | * We still block if tracing is disabled, but we have never |
| 3831 | * read anything. This allows a user to cat this file, and |
| 3832 | * then enable tracing. But after we have read something, |
| 3833 | * we give an EOF when tracing is again disabled. |
| 3834 | * |
| 3835 | * iter->pos will be 0 if we haven't read anything. |
| 3836 | */ |
Liu Bo | 250bfd3 | 2013-01-14 10:54:11 +0800 | [diff] [blame] | 3837 | if (!tracing_is_enabled() && iter->pos) |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 3838 | break; |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 3839 | } |
| 3840 | |
| 3841 | return 1; |
| 3842 | } |
| 3843 | |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3844 | /* |
| 3845 | * Consumer reader. |
| 3846 | */ |
| 3847 | static ssize_t |
| 3848 | tracing_read_pipe(struct file *filp, char __user *ubuf, |
| 3849 | size_t cnt, loff_t *ppos) |
| 3850 | { |
| 3851 | struct trace_iterator *iter = filp->private_data; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3852 | struct trace_array *tr = iter->tr; |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 3853 | ssize_t sret; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3854 | |
| 3855 | /* return any leftover data */ |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 3856 | sret = trace_seq_to_user(&iter->seq, ubuf, cnt); |
| 3857 | if (sret != -EBUSY) |
| 3858 | return sret; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3859 | |
Steven Rostedt | f952075 | 2009-03-02 14:04:40 -0500 | [diff] [blame] | 3860 | trace_seq_init(&iter->seq); |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3861 | |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 3862 | /* copy the tracer to avoid using a global lock all around */ |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 3863 | mutex_lock(&trace_types_lock); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3864 | if (unlikely(iter->trace->name != tr->current_trace->name)) |
| 3865 | *iter->trace = *tr->current_trace; |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 3866 | mutex_unlock(&trace_types_lock); |
| 3867 | |
| 3868 | /* |
| 3869 | * Avoid more than one consumer on a single file descriptor |
| 3870 | * This is just a matter of traces coherency, the ring buffer itself |
| 3871 | * is protected. |
| 3872 | */ |
| 3873 | mutex_lock(&iter->mutex); |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 3874 | if (iter->trace->read) { |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 3875 | sret = iter->trace->read(iter, filp, ubuf, cnt, ppos); |
| 3876 | if (sret) |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 3877 | goto out; |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 3878 | } |
| 3879 | |
Pekka Paalanen | 9ff4b97 | 2008-09-29 20:23:48 +0200 | [diff] [blame] | 3880 | waitagain: |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 3881 | sret = tracing_wait_pipe(filp); |
| 3882 | if (sret <= 0) |
| 3883 | goto out; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3884 | |
| 3885 | /* stop when tracing is finished */ |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 3886 | if (trace_empty(iter)) { |
| 3887 | sret = 0; |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 3888 | goto out; |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 3889 | } |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3890 | |
| 3891 | if (cnt >= PAGE_SIZE) |
| 3892 | cnt = PAGE_SIZE - 1; |
| 3893 | |
Steven Rostedt | 53d0aa7 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 3894 | /* reset all but tr, trace, and overruns */ |
Steven Rostedt | 53d0aa7 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 3895 | memset(&iter->seq, 0, |
| 3896 | sizeof(struct trace_iterator) - |
| 3897 | offsetof(struct trace_iterator, seq)); |
Steven Rostedt | 4823ed7 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 3898 | iter->pos = -1; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3899 | |
Lai Jiangshan | 4f53596 | 2009-05-18 19:35:34 +0800 | [diff] [blame] | 3900 | trace_event_read_lock(); |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 3901 | trace_access_lock(iter->cpu_file); |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 3902 | while (trace_find_next_entry_inc(iter) != NULL) { |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 3903 | enum print_line_t ret; |
Steven Rostedt | 088b1e42 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 3904 | int len = iter->seq.len; |
| 3905 | |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 3906 | ret = print_trace_line(iter); |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 3907 | if (ret == TRACE_TYPE_PARTIAL_LINE) { |
Steven Rostedt | 088b1e42 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 3908 | /* don't print partial lines */ |
| 3909 | iter->seq.len = len; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3910 | break; |
Steven Rostedt | 088b1e42 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 3911 | } |
Frederic Weisbecker | b91facc | 2009-02-06 18:30:44 +0100 | [diff] [blame] | 3912 | if (ret != TRACE_TYPE_NO_CONSUME) |
| 3913 | trace_consume(iter); |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3914 | |
| 3915 | if (iter->seq.len >= cnt) |
| 3916 | break; |
Jiri Olsa | ee5e51f | 2011-03-25 12:05:18 +0100 | [diff] [blame] | 3917 | |
| 3918 | /* |
| 3919 | * Setting the full flag means we reached the trace_seq buffer |
| 3920 | * size and we should leave by partial output condition above. |
| 3921 | * One of the trace_seq_* functions is not used properly. |
| 3922 | */ |
| 3923 | WARN_ONCE(iter->seq.full, "full flag set for trace type %d", |
| 3924 | iter->ent->type); |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3925 | } |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 3926 | trace_access_unlock(iter->cpu_file); |
Lai Jiangshan | 4f53596 | 2009-05-18 19:35:34 +0800 | [diff] [blame] | 3927 | trace_event_read_unlock(); |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3928 | |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3929 | /* Now copy what we have to the user */ |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 3930 | sret = trace_seq_to_user(&iter->seq, ubuf, cnt); |
| 3931 | if (iter->seq.readpos >= iter->seq.len) |
Steven Rostedt | f952075 | 2009-03-02 14:04:40 -0500 | [diff] [blame] | 3932 | trace_seq_init(&iter->seq); |
Pekka Paalanen | 9ff4b97 | 2008-09-29 20:23:48 +0200 | [diff] [blame] | 3933 | |
| 3934 | /* |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 3935 | * 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] | 3936 | * entries, go back to wait for more entries. |
| 3937 | */ |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 3938 | if (sret == -EBUSY) |
Pekka Paalanen | 9ff4b97 | 2008-09-29 20:23:48 +0200 | [diff] [blame] | 3939 | goto waitagain; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3940 | |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 3941 | out: |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 3942 | mutex_unlock(&iter->mutex); |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 3943 | |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 3944 | return sret; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3945 | } |
| 3946 | |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 3947 | static void tracing_pipe_buf_release(struct pipe_inode_info *pipe, |
| 3948 | struct pipe_buffer *buf) |
| 3949 | { |
| 3950 | __free_page(buf->page); |
| 3951 | } |
| 3952 | |
| 3953 | static void tracing_spd_release_pipe(struct splice_pipe_desc *spd, |
| 3954 | unsigned int idx) |
| 3955 | { |
| 3956 | __free_page(spd->pages[idx]); |
| 3957 | } |
| 3958 | |
Alexey Dobriyan | 28dfef8 | 2009-12-15 16:46:48 -0800 | [diff] [blame] | 3959 | static const struct pipe_buf_operations tracing_pipe_buf_ops = { |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 3960 | .can_merge = 0, |
| 3961 | .map = generic_pipe_buf_map, |
| 3962 | .unmap = generic_pipe_buf_unmap, |
| 3963 | .confirm = generic_pipe_buf_confirm, |
| 3964 | .release = tracing_pipe_buf_release, |
| 3965 | .steal = generic_pipe_buf_steal, |
| 3966 | .get = generic_pipe_buf_get, |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 3967 | }; |
| 3968 | |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 3969 | static size_t |
Frederic Weisbecker | fa7c7f6 | 2009-02-11 02:51:30 +0100 | [diff] [blame] | 3970 | tracing_fill_pipe_page(size_t rem, struct trace_iterator *iter) |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 3971 | { |
| 3972 | size_t count; |
| 3973 | int ret; |
| 3974 | |
| 3975 | /* Seq buffer is page-sized, exactly what we need. */ |
| 3976 | for (;;) { |
| 3977 | count = iter->seq.len; |
| 3978 | ret = print_trace_line(iter); |
| 3979 | count = iter->seq.len - count; |
| 3980 | if (rem < count) { |
| 3981 | rem = 0; |
| 3982 | iter->seq.len -= count; |
| 3983 | break; |
| 3984 | } |
| 3985 | if (ret == TRACE_TYPE_PARTIAL_LINE) { |
| 3986 | iter->seq.len -= count; |
| 3987 | break; |
| 3988 | } |
| 3989 | |
Lai Jiangshan | 74e7ff8 | 2009-07-28 20:17:22 +0800 | [diff] [blame] | 3990 | if (ret != TRACE_TYPE_NO_CONSUME) |
| 3991 | trace_consume(iter); |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 3992 | rem -= count; |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 3993 | if (!trace_find_next_entry_inc(iter)) { |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 3994 | rem = 0; |
| 3995 | iter->ent = NULL; |
| 3996 | break; |
| 3997 | } |
| 3998 | } |
| 3999 | |
| 4000 | return rem; |
| 4001 | } |
| 4002 | |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4003 | static ssize_t tracing_splice_read_pipe(struct file *filp, |
| 4004 | loff_t *ppos, |
| 4005 | struct pipe_inode_info *pipe, |
| 4006 | size_t len, |
| 4007 | unsigned int flags) |
| 4008 | { |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 4009 | struct page *pages_def[PIPE_DEF_BUFFERS]; |
| 4010 | struct partial_page partial_def[PIPE_DEF_BUFFERS]; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4011 | struct trace_iterator *iter = filp->private_data; |
| 4012 | struct splice_pipe_desc spd = { |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 4013 | .pages = pages_def, |
| 4014 | .partial = partial_def, |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 4015 | .nr_pages = 0, /* This gets updated below. */ |
Eric Dumazet | 047fe36 | 2012-06-12 15:24:40 +0200 | [diff] [blame] | 4016 | .nr_pages_max = PIPE_DEF_BUFFERS, |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 4017 | .flags = flags, |
| 4018 | .ops = &tracing_pipe_buf_ops, |
| 4019 | .spd_release = tracing_spd_release_pipe, |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4020 | }; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4021 | struct trace_array *tr = iter->tr; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4022 | ssize_t ret; |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 4023 | size_t rem; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4024 | unsigned int i; |
| 4025 | |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 4026 | if (splice_grow_spd(pipe, &spd)) |
| 4027 | return -ENOMEM; |
| 4028 | |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 4029 | /* copy the tracer to avoid using a global lock all around */ |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4030 | mutex_lock(&trace_types_lock); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4031 | if (unlikely(iter->trace->name != tr->current_trace->name)) |
| 4032 | *iter->trace = *tr->current_trace; |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 4033 | mutex_unlock(&trace_types_lock); |
| 4034 | |
| 4035 | mutex_lock(&iter->mutex); |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4036 | |
| 4037 | if (iter->trace->splice_read) { |
| 4038 | ret = iter->trace->splice_read(iter, filp, |
| 4039 | ppos, pipe, len, flags); |
| 4040 | if (ret) |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 4041 | goto out_err; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4042 | } |
| 4043 | |
| 4044 | ret = tracing_wait_pipe(filp); |
| 4045 | if (ret <= 0) |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 4046 | goto out_err; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4047 | |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 4048 | if (!iter->ent && !trace_find_next_entry_inc(iter)) { |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4049 | ret = -EFAULT; |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 4050 | goto out_err; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4051 | } |
| 4052 | |
Lai Jiangshan | 4f53596 | 2009-05-18 19:35:34 +0800 | [diff] [blame] | 4053 | trace_event_read_lock(); |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 4054 | trace_access_lock(iter->cpu_file); |
Lai Jiangshan | 4f53596 | 2009-05-18 19:35:34 +0800 | [diff] [blame] | 4055 | |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4056 | /* Fill as many pages as possible. */ |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 4057 | for (i = 0, rem = len; i < pipe->buffers && rem; i++) { |
| 4058 | spd.pages[i] = alloc_page(GFP_KERNEL); |
| 4059 | if (!spd.pages[i]) |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 4060 | break; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4061 | |
Frederic Weisbecker | fa7c7f6 | 2009-02-11 02:51:30 +0100 | [diff] [blame] | 4062 | rem = tracing_fill_pipe_page(rem, iter); |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4063 | |
| 4064 | /* Copy the data into the page, so we can start over. */ |
| 4065 | ret = trace_seq_to_buffer(&iter->seq, |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 4066 | page_address(spd.pages[i]), |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4067 | iter->seq.len); |
| 4068 | if (ret < 0) { |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 4069 | __free_page(spd.pages[i]); |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4070 | break; |
| 4071 | } |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 4072 | spd.partial[i].offset = 0; |
| 4073 | spd.partial[i].len = iter->seq.len; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4074 | |
Steven Rostedt | f952075 | 2009-03-02 14:04:40 -0500 | [diff] [blame] | 4075 | trace_seq_init(&iter->seq); |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4076 | } |
| 4077 | |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 4078 | trace_access_unlock(iter->cpu_file); |
Lai Jiangshan | 4f53596 | 2009-05-18 19:35:34 +0800 | [diff] [blame] | 4079 | trace_event_read_unlock(); |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 4080 | mutex_unlock(&iter->mutex); |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4081 | |
| 4082 | spd.nr_pages = i; |
| 4083 | |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 4084 | ret = splice_to_pipe(pipe, &spd); |
| 4085 | out: |
Eric Dumazet | 047fe36 | 2012-06-12 15:24:40 +0200 | [diff] [blame] | 4086 | splice_shrink_spd(&spd); |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 4087 | return ret; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4088 | |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 4089 | out_err: |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 4090 | mutex_unlock(&iter->mutex); |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 4091 | goto out; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4092 | } |
| 4093 | |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 4094 | static ssize_t |
| 4095 | tracing_entries_read(struct file *filp, char __user *ubuf, |
| 4096 | size_t cnt, loff_t *ppos) |
| 4097 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4098 | struct trace_cpu *tc = filp->private_data; |
| 4099 | struct trace_array *tr = tc->tr; |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 4100 | char buf[64]; |
| 4101 | int r = 0; |
| 4102 | ssize_t ret; |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 4103 | |
Steven Rostedt | db526ca | 2009-03-12 13:53:25 -0400 | [diff] [blame] | 4104 | mutex_lock(&trace_types_lock); |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 4105 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4106 | if (tc->cpu == RING_BUFFER_ALL_CPUS) { |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 4107 | int cpu, buf_size_same; |
| 4108 | unsigned long size; |
| 4109 | |
| 4110 | size = 0; |
| 4111 | buf_size_same = 1; |
| 4112 | /* check if all cpu sizes are same */ |
| 4113 | for_each_tracing_cpu(cpu) { |
| 4114 | /* fill in the size from first enabled cpu */ |
| 4115 | if (size == 0) |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4116 | size = per_cpu_ptr(tr->trace_buffer.data, cpu)->entries; |
| 4117 | if (size != per_cpu_ptr(tr->trace_buffer.data, cpu)->entries) { |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 4118 | buf_size_same = 0; |
| 4119 | break; |
| 4120 | } |
| 4121 | } |
| 4122 | |
| 4123 | if (buf_size_same) { |
| 4124 | if (!ring_buffer_expanded) |
| 4125 | r = sprintf(buf, "%lu (expanded: %lu)\n", |
| 4126 | size >> 10, |
| 4127 | trace_buf_size >> 10); |
| 4128 | else |
| 4129 | r = sprintf(buf, "%lu\n", size >> 10); |
| 4130 | } else |
| 4131 | r = sprintf(buf, "X\n"); |
| 4132 | } else |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4133 | 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] | 4134 | |
Steven Rostedt | db526ca | 2009-03-12 13:53:25 -0400 | [diff] [blame] | 4135 | mutex_unlock(&trace_types_lock); |
| 4136 | |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 4137 | ret = simple_read_from_buffer(ubuf, cnt, ppos, buf, r); |
| 4138 | return ret; |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 4139 | } |
| 4140 | |
| 4141 | static ssize_t |
| 4142 | tracing_entries_write(struct file *filp, const char __user *ubuf, |
| 4143 | size_t cnt, loff_t *ppos) |
| 4144 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4145 | struct trace_cpu *tc = filp->private_data; |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 4146 | unsigned long val; |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 4147 | int ret; |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 4148 | |
Peter Huewe | 22fe9b5 | 2011-06-07 21:58:27 +0200 | [diff] [blame] | 4149 | ret = kstrtoul_from_user(ubuf, cnt, 10, &val); |
| 4150 | if (ret) |
Steven Rostedt | c6caeeb | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 4151 | return ret; |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 4152 | |
| 4153 | /* must have at least 1 entry */ |
| 4154 | if (!val) |
| 4155 | return -EINVAL; |
| 4156 | |
Steven Rostedt | 1696b2b | 2008-11-13 00:09:35 -0500 | [diff] [blame] | 4157 | /* value is in KB */ |
| 4158 | val <<= 10; |
| 4159 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4160 | ret = tracing_resize_ring_buffer(tc->tr, val, tc->cpu); |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 4161 | if (ret < 0) |
| 4162 | return ret; |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 4163 | |
Jiri Olsa | cf8517c | 2009-10-23 19:36:16 -0400 | [diff] [blame] | 4164 | *ppos += cnt; |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 4165 | |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 4166 | return cnt; |
| 4167 | } |
Steven Rostedt | bf5e651 | 2008-11-10 21:46:00 -0500 | [diff] [blame] | 4168 | |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 4169 | static ssize_t |
Vaibhav Nagarnaik | f81ab07 | 2011-08-16 14:46:15 -0700 | [diff] [blame] | 4170 | tracing_total_entries_read(struct file *filp, char __user *ubuf, |
| 4171 | size_t cnt, loff_t *ppos) |
| 4172 | { |
| 4173 | struct trace_array *tr = filp->private_data; |
| 4174 | char buf[64]; |
| 4175 | int r, cpu; |
| 4176 | unsigned long size = 0, expanded_size = 0; |
| 4177 | |
| 4178 | mutex_lock(&trace_types_lock); |
| 4179 | for_each_tracing_cpu(cpu) { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4180 | size += per_cpu_ptr(tr->trace_buffer.data, cpu)->entries >> 10; |
Vaibhav Nagarnaik | f81ab07 | 2011-08-16 14:46:15 -0700 | [diff] [blame] | 4181 | if (!ring_buffer_expanded) |
| 4182 | expanded_size += trace_buf_size >> 10; |
| 4183 | } |
| 4184 | if (ring_buffer_expanded) |
| 4185 | r = sprintf(buf, "%lu\n", size); |
| 4186 | else |
| 4187 | r = sprintf(buf, "%lu (expanded: %lu)\n", size, expanded_size); |
| 4188 | mutex_unlock(&trace_types_lock); |
| 4189 | |
| 4190 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, r); |
| 4191 | } |
| 4192 | |
| 4193 | static ssize_t |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 4194 | tracing_free_buffer_write(struct file *filp, const char __user *ubuf, |
| 4195 | size_t cnt, loff_t *ppos) |
| 4196 | { |
| 4197 | /* |
| 4198 | * There is no need to read what the user has written, this function |
| 4199 | * is just to make sure that there is no error when "echo" is used |
| 4200 | */ |
| 4201 | |
| 4202 | *ppos += cnt; |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 4203 | |
| 4204 | return cnt; |
| 4205 | } |
| 4206 | |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 4207 | static int |
| 4208 | tracing_free_buffer_release(struct inode *inode, struct file *filp) |
| 4209 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4210 | struct trace_array *tr = inode->i_private; |
| 4211 | |
Steven Rostedt | cf30cf6 | 2011-06-14 22:44:07 -0400 | [diff] [blame] | 4212 | /* disable tracing ? */ |
| 4213 | if (trace_flags & TRACE_ITER_STOP_ON_FREE) |
| 4214 | tracing_off(); |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 4215 | /* resize the ring buffer to 0 */ |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4216 | tracing_resize_ring_buffer(tr, 0, RING_BUFFER_ALL_CPUS); |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 4217 | |
| 4218 | return 0; |
| 4219 | } |
| 4220 | |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 4221 | static ssize_t |
| 4222 | tracing_mark_write(struct file *filp, const char __user *ubuf, |
| 4223 | size_t cnt, loff_t *fpos) |
| 4224 | { |
Steven Rostedt | d696b58 | 2011-09-22 11:50:27 -0400 | [diff] [blame] | 4225 | unsigned long addr = (unsigned long)ubuf; |
| 4226 | struct ring_buffer_event *event; |
| 4227 | struct ring_buffer *buffer; |
| 4228 | struct print_entry *entry; |
| 4229 | unsigned long irq_flags; |
| 4230 | struct page *pages[2]; |
Steven Rostedt | 6edb2a8 | 2012-05-11 23:28:49 -0400 | [diff] [blame] | 4231 | void *map_page[2]; |
Steven Rostedt | d696b58 | 2011-09-22 11:50:27 -0400 | [diff] [blame] | 4232 | int nr_pages = 1; |
| 4233 | ssize_t written; |
Steven Rostedt | d696b58 | 2011-09-22 11:50:27 -0400 | [diff] [blame] | 4234 | int offset; |
| 4235 | int size; |
| 4236 | int len; |
| 4237 | int ret; |
Steven Rostedt | 6edb2a8 | 2012-05-11 23:28:49 -0400 | [diff] [blame] | 4238 | int i; |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 4239 | |
Steven Rostedt | c76f069 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 4240 | if (tracing_disabled) |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 4241 | return -EINVAL; |
| 4242 | |
Mandeep Singh Baines | 5224c3a | 2012-09-07 18:12:19 -0700 | [diff] [blame] | 4243 | if (!(trace_flags & TRACE_ITER_MARKERS)) |
| 4244 | return -EINVAL; |
| 4245 | |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 4246 | if (cnt > TRACE_BUF_SIZE) |
| 4247 | cnt = TRACE_BUF_SIZE; |
| 4248 | |
Steven Rostedt | d696b58 | 2011-09-22 11:50:27 -0400 | [diff] [blame] | 4249 | /* |
| 4250 | * Userspace is injecting traces into the kernel trace buffer. |
| 4251 | * We want to be as non intrusive as possible. |
| 4252 | * To do so, we do not want to allocate any special buffers |
| 4253 | * or take any locks, but instead write the userspace data |
| 4254 | * straight into the ring buffer. |
| 4255 | * |
| 4256 | * First we need to pin the userspace buffer into memory, |
| 4257 | * which, most likely it is, because it just referenced it. |
| 4258 | * But there's no guarantee that it is. By using get_user_pages_fast() |
| 4259 | * and kmap_atomic/kunmap_atomic() we can get access to the |
| 4260 | * pages directly. We then write the data directly into the |
| 4261 | * ring buffer. |
| 4262 | */ |
| 4263 | BUILD_BUG_ON(TRACE_BUF_SIZE >= PAGE_SIZE); |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 4264 | |
Steven Rostedt | d696b58 | 2011-09-22 11:50:27 -0400 | [diff] [blame] | 4265 | /* check if we cross pages */ |
| 4266 | if ((addr & PAGE_MASK) != ((addr + cnt) & PAGE_MASK)) |
| 4267 | nr_pages = 2; |
| 4268 | |
| 4269 | offset = addr & (PAGE_SIZE - 1); |
| 4270 | addr &= PAGE_MASK; |
| 4271 | |
| 4272 | ret = get_user_pages_fast(addr, nr_pages, 0, pages); |
| 4273 | if (ret < nr_pages) { |
| 4274 | while (--ret >= 0) |
| 4275 | put_page(pages[ret]); |
| 4276 | written = -EFAULT; |
| 4277 | goto out; |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 4278 | } |
| 4279 | |
Steven Rostedt | 6edb2a8 | 2012-05-11 23:28:49 -0400 | [diff] [blame] | 4280 | for (i = 0; i < nr_pages; i++) |
| 4281 | map_page[i] = kmap_atomic(pages[i]); |
Steven Rostedt | d696b58 | 2011-09-22 11:50:27 -0400 | [diff] [blame] | 4282 | |
| 4283 | local_save_flags(irq_flags); |
| 4284 | size = sizeof(*entry) + cnt + 2; /* possible \n added */ |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4285 | buffer = global_trace.trace_buffer.buffer; |
Steven Rostedt | d696b58 | 2011-09-22 11:50:27 -0400 | [diff] [blame] | 4286 | event = trace_buffer_lock_reserve(buffer, TRACE_PRINT, size, |
| 4287 | irq_flags, preempt_count()); |
| 4288 | if (!event) { |
| 4289 | /* Ring buffer disabled, return as if not open for write */ |
| 4290 | written = -EBADF; |
| 4291 | goto out_unlock; |
| 4292 | } |
| 4293 | |
| 4294 | entry = ring_buffer_event_data(event); |
| 4295 | entry->ip = _THIS_IP_; |
| 4296 | |
| 4297 | if (nr_pages == 2) { |
| 4298 | len = PAGE_SIZE - offset; |
Steven Rostedt | 6edb2a8 | 2012-05-11 23:28:49 -0400 | [diff] [blame] | 4299 | memcpy(&entry->buf, map_page[0] + offset, len); |
| 4300 | memcpy(&entry->buf[len], map_page[1], cnt - len); |
Steven Rostedt | d696b58 | 2011-09-22 11:50:27 -0400 | [diff] [blame] | 4301 | } else |
Steven Rostedt | 6edb2a8 | 2012-05-11 23:28:49 -0400 | [diff] [blame] | 4302 | memcpy(&entry->buf, map_page[0] + offset, cnt); |
Steven Rostedt | d696b58 | 2011-09-22 11:50:27 -0400 | [diff] [blame] | 4303 | |
| 4304 | if (entry->buf[cnt - 1] != '\n') { |
| 4305 | entry->buf[cnt] = '\n'; |
| 4306 | entry->buf[cnt + 1] = '\0'; |
| 4307 | } else |
| 4308 | entry->buf[cnt] = '\0'; |
| 4309 | |
Steven Rostedt | 7ffbd48 | 2012-10-11 12:14:25 -0400 | [diff] [blame] | 4310 | __buffer_unlock_commit(buffer, event); |
Steven Rostedt | d696b58 | 2011-09-22 11:50:27 -0400 | [diff] [blame] | 4311 | |
| 4312 | written = cnt; |
| 4313 | |
Marcin Slusarz | 1aa54bc | 2010-07-28 01:18:01 +0200 | [diff] [blame] | 4314 | *fpos += written; |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 4315 | |
Steven Rostedt | d696b58 | 2011-09-22 11:50:27 -0400 | [diff] [blame] | 4316 | out_unlock: |
Steven Rostedt | 6edb2a8 | 2012-05-11 23:28:49 -0400 | [diff] [blame] | 4317 | for (i = 0; i < nr_pages; i++){ |
| 4318 | kunmap_atomic(map_page[i]); |
| 4319 | put_page(pages[i]); |
| 4320 | } |
Steven Rostedt | d696b58 | 2011-09-22 11:50:27 -0400 | [diff] [blame] | 4321 | out: |
Marcin Slusarz | 1aa54bc | 2010-07-28 01:18:01 +0200 | [diff] [blame] | 4322 | return written; |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 4323 | } |
| 4324 | |
Li Zefan | 13f16d2 | 2009-12-08 11:16:11 +0800 | [diff] [blame] | 4325 | static int tracing_clock_show(struct seq_file *m, void *v) |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 4326 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4327 | struct trace_array *tr = m->private; |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 4328 | int i; |
| 4329 | |
| 4330 | for (i = 0; i < ARRAY_SIZE(trace_clocks); i++) |
Li Zefan | 13f16d2 | 2009-12-08 11:16:11 +0800 | [diff] [blame] | 4331 | seq_printf(m, |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 4332 | "%s%s%s%s", i ? " " : "", |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4333 | i == tr->clock_id ? "[" : "", trace_clocks[i].name, |
| 4334 | i == tr->clock_id ? "]" : ""); |
Li Zefan | 13f16d2 | 2009-12-08 11:16:11 +0800 | [diff] [blame] | 4335 | seq_putc(m, '\n'); |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 4336 | |
Li Zefan | 13f16d2 | 2009-12-08 11:16:11 +0800 | [diff] [blame] | 4337 | return 0; |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 4338 | } |
| 4339 | |
| 4340 | static ssize_t tracing_clock_write(struct file *filp, const char __user *ubuf, |
| 4341 | size_t cnt, loff_t *fpos) |
| 4342 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4343 | struct seq_file *m = filp->private_data; |
| 4344 | struct trace_array *tr = m->private; |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 4345 | char buf[64]; |
| 4346 | const char *clockstr; |
| 4347 | int i; |
| 4348 | |
| 4349 | if (cnt >= sizeof(buf)) |
| 4350 | return -EINVAL; |
| 4351 | |
| 4352 | if (copy_from_user(&buf, ubuf, cnt)) |
| 4353 | return -EFAULT; |
| 4354 | |
| 4355 | buf[cnt] = 0; |
| 4356 | |
| 4357 | clockstr = strstrip(buf); |
| 4358 | |
| 4359 | for (i = 0; i < ARRAY_SIZE(trace_clocks); i++) { |
| 4360 | if (strcmp(trace_clocks[i].name, clockstr) == 0) |
| 4361 | break; |
| 4362 | } |
| 4363 | if (i == ARRAY_SIZE(trace_clocks)) |
| 4364 | return -EINVAL; |
| 4365 | |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 4366 | mutex_lock(&trace_types_lock); |
| 4367 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4368 | tr->clock_id = i; |
| 4369 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4370 | ring_buffer_set_clock(tr->trace_buffer.buffer, trace_clocks[i].func); |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 4371 | |
David Sharp | 60303ed | 2012-10-11 16:27:52 -0700 | [diff] [blame] | 4372 | /* |
| 4373 | * New clock may not be consistent with the previous clock. |
| 4374 | * Reset the buffer so that it doesn't have incomparable timestamps. |
| 4375 | */ |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4376 | tracing_reset_online_cpus(&global_trace.trace_buffer); |
| 4377 | |
| 4378 | #ifdef CONFIG_TRACER_MAX_TRACE |
| 4379 | if (tr->flags & TRACE_ARRAY_FL_GLOBAL && tr->max_buffer.buffer) |
| 4380 | ring_buffer_set_clock(tr->max_buffer.buffer, trace_clocks[i].func); |
| 4381 | tracing_reset_online_cpus(&global_trace.max_buffer); |
| 4382 | #endif |
David Sharp | 60303ed | 2012-10-11 16:27:52 -0700 | [diff] [blame] | 4383 | |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 4384 | mutex_unlock(&trace_types_lock); |
| 4385 | |
| 4386 | *fpos += cnt; |
| 4387 | |
| 4388 | return cnt; |
| 4389 | } |
| 4390 | |
Li Zefan | 13f16d2 | 2009-12-08 11:16:11 +0800 | [diff] [blame] | 4391 | static int tracing_clock_open(struct inode *inode, struct file *file) |
| 4392 | { |
| 4393 | if (tracing_disabled) |
| 4394 | return -ENODEV; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4395 | |
| 4396 | return single_open(file, tracing_clock_show, inode->i_private); |
Li Zefan | 13f16d2 | 2009-12-08 11:16:11 +0800 | [diff] [blame] | 4397 | } |
| 4398 | |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 4399 | struct ftrace_buffer_info { |
| 4400 | struct trace_iterator iter; |
| 4401 | void *spare; |
| 4402 | unsigned int read; |
| 4403 | }; |
| 4404 | |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4405 | #ifdef CONFIG_TRACER_SNAPSHOT |
| 4406 | static int tracing_snapshot_open(struct inode *inode, struct file *file) |
| 4407 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4408 | struct trace_cpu *tc = inode->i_private; |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4409 | struct trace_iterator *iter; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4410 | struct seq_file *m; |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4411 | int ret = 0; |
| 4412 | |
| 4413 | if (file->f_mode & FMODE_READ) { |
| 4414 | iter = __tracing_open(inode, file, true); |
| 4415 | if (IS_ERR(iter)) |
| 4416 | ret = PTR_ERR(iter); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4417 | } else { |
| 4418 | /* Writes still need the seq_file to hold the private data */ |
| 4419 | m = kzalloc(sizeof(*m), GFP_KERNEL); |
| 4420 | if (!m) |
| 4421 | return -ENOMEM; |
| 4422 | iter = kzalloc(sizeof(*iter), GFP_KERNEL); |
| 4423 | if (!iter) { |
| 4424 | kfree(m); |
| 4425 | return -ENOMEM; |
| 4426 | } |
| 4427 | iter->tr = tc->tr; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4428 | iter->trace_buffer = &tc->tr->max_buffer; |
Steven Rostedt (Red Hat) | f1affca | 2013-03-05 14:35:11 -0500 | [diff] [blame] | 4429 | iter->cpu_file = tc->cpu; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4430 | m->private = iter; |
| 4431 | file->private_data = m; |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4432 | } |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4433 | |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4434 | return ret; |
| 4435 | } |
| 4436 | |
| 4437 | static ssize_t |
| 4438 | tracing_snapshot_write(struct file *filp, const char __user *ubuf, size_t cnt, |
| 4439 | loff_t *ppos) |
| 4440 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4441 | struct seq_file *m = filp->private_data; |
| 4442 | struct trace_iterator *iter = m->private; |
| 4443 | struct trace_array *tr = iter->tr; |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4444 | unsigned long val; |
| 4445 | int ret; |
| 4446 | |
| 4447 | ret = tracing_update_buffers(); |
| 4448 | if (ret < 0) |
| 4449 | return ret; |
| 4450 | |
| 4451 | ret = kstrtoul_from_user(ubuf, cnt, 10, &val); |
| 4452 | if (ret) |
| 4453 | return ret; |
| 4454 | |
| 4455 | mutex_lock(&trace_types_lock); |
| 4456 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4457 | if (tr->current_trace->use_max_tr) { |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4458 | ret = -EBUSY; |
| 4459 | goto out; |
| 4460 | } |
| 4461 | |
| 4462 | switch (val) { |
| 4463 | case 0: |
Steven Rostedt (Red Hat) | f1affca | 2013-03-05 14:35:11 -0500 | [diff] [blame] | 4464 | if (iter->cpu_file != RING_BUFFER_ALL_CPUS) { |
| 4465 | ret = -EINVAL; |
| 4466 | break; |
| 4467 | } |
Steven Rostedt (Red Hat) | 45ad21c | 2013-03-05 18:25:02 -0500 | [diff] [blame] | 4468 | if (tr->allocated_snapshot) { |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4469 | /* free spare buffer */ |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4470 | ring_buffer_resize(tr->max_buffer.buffer, 1, |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4471 | RING_BUFFER_ALL_CPUS); |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4472 | set_buffer_entries(&tr->max_buffer, 1); |
| 4473 | tracing_reset_online_cpus(&tr->max_buffer); |
Steven Rostedt (Red Hat) | 45ad21c | 2013-03-05 18:25:02 -0500 | [diff] [blame] | 4474 | tr->allocated_snapshot = false; |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4475 | } |
| 4476 | break; |
| 4477 | case 1: |
Steven Rostedt (Red Hat) | f1affca | 2013-03-05 14:35:11 -0500 | [diff] [blame] | 4478 | /* Only allow per-cpu swap if the ring buffer supports it */ |
| 4479 | #ifndef CONFIG_RING_BUFFER_ALLOW_SWAP |
| 4480 | if (iter->cpu_file != RING_BUFFER_ALL_CPUS) { |
| 4481 | ret = -EINVAL; |
| 4482 | break; |
| 4483 | } |
| 4484 | #endif |
Steven Rostedt (Red Hat) | 45ad21c | 2013-03-05 18:25:02 -0500 | [diff] [blame] | 4485 | if (!tr->allocated_snapshot) { |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4486 | /* allocate spare buffer */ |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4487 | ret = resize_buffer_duplicate_size(&tr->max_buffer, |
| 4488 | &tr->trace_buffer, RING_BUFFER_ALL_CPUS); |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4489 | if (ret < 0) |
| 4490 | break; |
Steven Rostedt (Red Hat) | 45ad21c | 2013-03-05 18:25:02 -0500 | [diff] [blame] | 4491 | tr->allocated_snapshot = true; |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4492 | } |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4493 | local_irq_disable(); |
| 4494 | /* Now, we're going to swap */ |
Steven Rostedt (Red Hat) | f1affca | 2013-03-05 14:35:11 -0500 | [diff] [blame] | 4495 | if (iter->cpu_file == RING_BUFFER_ALL_CPUS) |
Steven Rostedt (Red Hat) | ce9bae5 | 2013-03-05 21:23:55 -0500 | [diff] [blame] | 4496 | update_max_tr(tr, current, smp_processor_id()); |
Steven Rostedt (Red Hat) | f1affca | 2013-03-05 14:35:11 -0500 | [diff] [blame] | 4497 | else |
Steven Rostedt (Red Hat) | ce9bae5 | 2013-03-05 21:23:55 -0500 | [diff] [blame] | 4498 | update_max_tr_single(tr, current, iter->cpu_file); |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4499 | local_irq_enable(); |
| 4500 | break; |
| 4501 | default: |
Steven Rostedt (Red Hat) | 45ad21c | 2013-03-05 18:25:02 -0500 | [diff] [blame] | 4502 | if (tr->allocated_snapshot) { |
Steven Rostedt (Red Hat) | f1affca | 2013-03-05 14:35:11 -0500 | [diff] [blame] | 4503 | if (iter->cpu_file == RING_BUFFER_ALL_CPUS) |
| 4504 | tracing_reset_online_cpus(&tr->max_buffer); |
| 4505 | else |
| 4506 | tracing_reset(&tr->max_buffer, iter->cpu_file); |
| 4507 | } |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4508 | break; |
| 4509 | } |
| 4510 | |
| 4511 | if (ret >= 0) { |
| 4512 | *ppos += cnt; |
| 4513 | ret = cnt; |
| 4514 | } |
| 4515 | out: |
| 4516 | mutex_unlock(&trace_types_lock); |
| 4517 | return ret; |
| 4518 | } |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4519 | |
| 4520 | static int tracing_snapshot_release(struct inode *inode, struct file *file) |
| 4521 | { |
| 4522 | struct seq_file *m = file->private_data; |
| 4523 | |
| 4524 | if (file->f_mode & FMODE_READ) |
| 4525 | return tracing_release(inode, file); |
| 4526 | |
| 4527 | /* If write only, the seq_file is just a stub */ |
| 4528 | if (m) |
| 4529 | kfree(m->private); |
| 4530 | kfree(m); |
| 4531 | |
| 4532 | return 0; |
| 4533 | } |
| 4534 | |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 4535 | static int tracing_buffers_open(struct inode *inode, struct file *filp); |
| 4536 | static ssize_t tracing_buffers_read(struct file *filp, char __user *ubuf, |
| 4537 | size_t count, loff_t *ppos); |
| 4538 | static int tracing_buffers_release(struct inode *inode, struct file *file); |
| 4539 | static ssize_t tracing_buffers_splice_read(struct file *file, loff_t *ppos, |
| 4540 | struct pipe_inode_info *pipe, size_t len, unsigned int flags); |
| 4541 | |
| 4542 | static int snapshot_raw_open(struct inode *inode, struct file *filp) |
| 4543 | { |
| 4544 | struct ftrace_buffer_info *info; |
| 4545 | int ret; |
| 4546 | |
| 4547 | ret = tracing_buffers_open(inode, filp); |
| 4548 | if (ret < 0) |
| 4549 | return ret; |
| 4550 | |
| 4551 | info = filp->private_data; |
| 4552 | |
| 4553 | if (info->iter.trace->use_max_tr) { |
| 4554 | tracing_buffers_release(inode, filp); |
| 4555 | return -EBUSY; |
| 4556 | } |
| 4557 | |
| 4558 | info->iter.snapshot = true; |
| 4559 | info->iter.trace_buffer = &info->iter.tr->max_buffer; |
| 4560 | |
| 4561 | return ret; |
| 4562 | } |
| 4563 | |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4564 | #endif /* CONFIG_TRACER_SNAPSHOT */ |
| 4565 | |
| 4566 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 4567 | static const struct file_operations tracing_max_lat_fops = { |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4568 | .open = tracing_open_generic, |
| 4569 | .read = tracing_max_lat_read, |
| 4570 | .write = tracing_max_lat_write, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 4571 | .llseek = generic_file_llseek, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4572 | }; |
| 4573 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 4574 | static const struct file_operations set_tracer_fops = { |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4575 | .open = tracing_open_generic, |
| 4576 | .read = tracing_set_trace_read, |
| 4577 | .write = tracing_set_trace_write, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 4578 | .llseek = generic_file_llseek, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4579 | }; |
| 4580 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 4581 | static const struct file_operations tracing_pipe_fops = { |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4582 | .open = tracing_open_pipe, |
Soeren Sandmann Pedersen | 2a2cc8f | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 4583 | .poll = tracing_poll_pipe, |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4584 | .read = tracing_read_pipe, |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4585 | .splice_read = tracing_splice_read_pipe, |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4586 | .release = tracing_release_pipe, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 4587 | .llseek = no_llseek, |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4588 | }; |
| 4589 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 4590 | static const struct file_operations tracing_entries_fops = { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4591 | .open = tracing_open_generic, |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 4592 | .read = tracing_entries_read, |
| 4593 | .write = tracing_entries_write, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 4594 | .llseek = generic_file_llseek, |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 4595 | }; |
| 4596 | |
Vaibhav Nagarnaik | f81ab07 | 2011-08-16 14:46:15 -0700 | [diff] [blame] | 4597 | static const struct file_operations tracing_total_entries_fops = { |
| 4598 | .open = tracing_open_generic, |
| 4599 | .read = tracing_total_entries_read, |
| 4600 | .llseek = generic_file_llseek, |
| 4601 | }; |
| 4602 | |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 4603 | static const struct file_operations tracing_free_buffer_fops = { |
| 4604 | .write = tracing_free_buffer_write, |
| 4605 | .release = tracing_free_buffer_release, |
| 4606 | }; |
| 4607 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 4608 | static const struct file_operations tracing_mark_fops = { |
Frédéric Weisbecker | 43a1538 | 2008-09-21 20:16:30 +0200 | [diff] [blame] | 4609 | .open = tracing_open_generic, |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 4610 | .write = tracing_mark_write, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 4611 | .llseek = generic_file_llseek, |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 4612 | }; |
| 4613 | |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 4614 | static const struct file_operations trace_clock_fops = { |
Li Zefan | 13f16d2 | 2009-12-08 11:16:11 +0800 | [diff] [blame] | 4615 | .open = tracing_clock_open, |
| 4616 | .read = seq_read, |
| 4617 | .llseek = seq_lseek, |
| 4618 | .release = single_release, |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 4619 | .write = tracing_clock_write, |
| 4620 | }; |
| 4621 | |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4622 | #ifdef CONFIG_TRACER_SNAPSHOT |
| 4623 | static const struct file_operations snapshot_fops = { |
| 4624 | .open = tracing_snapshot_open, |
| 4625 | .read = seq_read, |
| 4626 | .write = tracing_snapshot_write, |
| 4627 | .llseek = tracing_seek, |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4628 | .release = tracing_snapshot_release, |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4629 | }; |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 4630 | |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 4631 | static const struct file_operations snapshot_raw_fops = { |
| 4632 | .open = snapshot_raw_open, |
| 4633 | .read = tracing_buffers_read, |
| 4634 | .release = tracing_buffers_release, |
| 4635 | .splice_read = tracing_buffers_splice_read, |
| 4636 | .llseek = no_llseek, |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4637 | }; |
| 4638 | |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 4639 | #endif /* CONFIG_TRACER_SNAPSHOT */ |
| 4640 | |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4641 | static int tracing_buffers_open(struct inode *inode, struct file *filp) |
| 4642 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4643 | struct trace_cpu *tc = inode->i_private; |
| 4644 | struct trace_array *tr = tc->tr; |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4645 | struct ftrace_buffer_info *info; |
| 4646 | |
| 4647 | if (tracing_disabled) |
| 4648 | return -ENODEV; |
| 4649 | |
| 4650 | info = kzalloc(sizeof(*info), GFP_KERNEL); |
| 4651 | if (!info) |
| 4652 | return -ENOMEM; |
| 4653 | |
Steven Rostedt (Red Hat) | a695cb5 | 2013-03-06 15:27:24 -0500 | [diff] [blame] | 4654 | mutex_lock(&trace_types_lock); |
| 4655 | |
| 4656 | tr->ref++; |
| 4657 | |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 4658 | info->iter.tr = tr; |
| 4659 | info->iter.cpu_file = tc->cpu; |
Steven Rostedt | b627344 | 2013-02-28 13:44:11 -0500 | [diff] [blame] | 4660 | info->iter.trace = tr->current_trace; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4661 | info->iter.trace_buffer = &tr->trace_buffer; |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 4662 | info->spare = NULL; |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4663 | /* Force reading ring buffer for first read */ |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 4664 | info->read = (unsigned int)-1; |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4665 | |
| 4666 | filp->private_data = info; |
| 4667 | |
Steven Rostedt (Red Hat) | a695cb5 | 2013-03-06 15:27:24 -0500 | [diff] [blame] | 4668 | mutex_unlock(&trace_types_lock); |
| 4669 | |
Lai Jiangshan | d1e7e02 | 2009-04-02 15:16:56 +0800 | [diff] [blame] | 4670 | return nonseekable_open(inode, filp); |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4671 | } |
| 4672 | |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 4673 | static unsigned int |
| 4674 | tracing_buffers_poll(struct file *filp, poll_table *poll_table) |
| 4675 | { |
| 4676 | struct ftrace_buffer_info *info = filp->private_data; |
| 4677 | struct trace_iterator *iter = &info->iter; |
| 4678 | |
| 4679 | return trace_poll(iter, filp, poll_table); |
| 4680 | } |
| 4681 | |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4682 | static ssize_t |
| 4683 | tracing_buffers_read(struct file *filp, char __user *ubuf, |
| 4684 | size_t count, loff_t *ppos) |
| 4685 | { |
| 4686 | struct ftrace_buffer_info *info = filp->private_data; |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 4687 | struct trace_iterator *iter = &info->iter; |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4688 | ssize_t ret; |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 4689 | ssize_t size; |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4690 | |
Steven Rostedt | 2dc5d12 | 2009-03-04 19:10:05 -0500 | [diff] [blame] | 4691 | if (!count) |
| 4692 | return 0; |
| 4693 | |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 4694 | mutex_lock(&trace_types_lock); |
| 4695 | |
| 4696 | #ifdef CONFIG_TRACER_MAX_TRACE |
| 4697 | if (iter->snapshot && iter->tr->current_trace->use_max_tr) { |
| 4698 | size = -EBUSY; |
| 4699 | goto out_unlock; |
| 4700 | } |
| 4701 | #endif |
| 4702 | |
Lai Jiangshan | ddd538f | 2009-04-02 15:16:59 +0800 | [diff] [blame] | 4703 | if (!info->spare) |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4704 | info->spare = ring_buffer_alloc_read_page(iter->trace_buffer->buffer, |
| 4705 | iter->cpu_file); |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 4706 | size = -ENOMEM; |
Lai Jiangshan | ddd538f | 2009-04-02 15:16:59 +0800 | [diff] [blame] | 4707 | if (!info->spare) |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 4708 | goto out_unlock; |
Lai Jiangshan | ddd538f | 2009-04-02 15:16:59 +0800 | [diff] [blame] | 4709 | |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4710 | /* Do we have previous read data to read? */ |
| 4711 | if (info->read < PAGE_SIZE) |
| 4712 | goto read; |
| 4713 | |
Steven Rostedt | b627344 | 2013-02-28 13:44:11 -0500 | [diff] [blame] | 4714 | again: |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 4715 | trace_access_lock(iter->cpu_file); |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4716 | ret = ring_buffer_read_page(iter->trace_buffer->buffer, |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4717 | &info->spare, |
| 4718 | count, |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 4719 | iter->cpu_file, 0); |
| 4720 | trace_access_unlock(iter->cpu_file); |
Steven Rostedt | b627344 | 2013-02-28 13:44:11 -0500 | [diff] [blame] | 4721 | |
| 4722 | if (ret < 0) { |
| 4723 | if (trace_empty(iter)) { |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 4724 | if ((filp->f_flags & O_NONBLOCK)) { |
| 4725 | size = -EAGAIN; |
| 4726 | goto out_unlock; |
| 4727 | } |
| 4728 | mutex_unlock(&trace_types_lock); |
Steven Rostedt | b627344 | 2013-02-28 13:44:11 -0500 | [diff] [blame] | 4729 | iter->trace->wait_pipe(iter); |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 4730 | mutex_lock(&trace_types_lock); |
| 4731 | if (signal_pending(current)) { |
| 4732 | size = -EINTR; |
| 4733 | goto out_unlock; |
| 4734 | } |
Steven Rostedt | b627344 | 2013-02-28 13:44:11 -0500 | [diff] [blame] | 4735 | goto again; |
| 4736 | } |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 4737 | size = 0; |
| 4738 | goto out_unlock; |
Steven Rostedt | b627344 | 2013-02-28 13:44:11 -0500 | [diff] [blame] | 4739 | } |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4740 | |
Steven Rostedt | 436fc28 | 2011-10-14 10:44:25 -0400 | [diff] [blame] | 4741 | info->read = 0; |
Steven Rostedt | b627344 | 2013-02-28 13:44:11 -0500 | [diff] [blame] | 4742 | read: |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4743 | size = PAGE_SIZE - info->read; |
| 4744 | if (size > count) |
| 4745 | size = count; |
| 4746 | |
| 4747 | ret = copy_to_user(ubuf, info->spare + info->read, size); |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 4748 | if (ret == size) { |
| 4749 | size = -EFAULT; |
| 4750 | goto out_unlock; |
| 4751 | } |
Steven Rostedt | 2dc5d12 | 2009-03-04 19:10:05 -0500 | [diff] [blame] | 4752 | size -= ret; |
| 4753 | |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4754 | *ppos += size; |
| 4755 | info->read += size; |
| 4756 | |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 4757 | out_unlock: |
| 4758 | mutex_unlock(&trace_types_lock); |
| 4759 | |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4760 | return size; |
| 4761 | } |
| 4762 | |
| 4763 | static int tracing_buffers_release(struct inode *inode, struct file *file) |
| 4764 | { |
| 4765 | struct ftrace_buffer_info *info = file->private_data; |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 4766 | struct trace_iterator *iter = &info->iter; |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4767 | |
Steven Rostedt (Red Hat) | a695cb5 | 2013-03-06 15:27:24 -0500 | [diff] [blame] | 4768 | mutex_lock(&trace_types_lock); |
| 4769 | |
| 4770 | WARN_ON(!iter->tr->ref); |
| 4771 | iter->tr->ref--; |
| 4772 | |
Lai Jiangshan | ddd538f | 2009-04-02 15:16:59 +0800 | [diff] [blame] | 4773 | if (info->spare) |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4774 | ring_buffer_free_read_page(iter->trace_buffer->buffer, info->spare); |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4775 | kfree(info); |
| 4776 | |
Steven Rostedt (Red Hat) | a695cb5 | 2013-03-06 15:27:24 -0500 | [diff] [blame] | 4777 | mutex_unlock(&trace_types_lock); |
| 4778 | |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4779 | return 0; |
| 4780 | } |
| 4781 | |
| 4782 | struct buffer_ref { |
| 4783 | struct ring_buffer *buffer; |
| 4784 | void *page; |
| 4785 | int ref; |
| 4786 | }; |
| 4787 | |
| 4788 | static void buffer_pipe_buf_release(struct pipe_inode_info *pipe, |
| 4789 | struct pipe_buffer *buf) |
| 4790 | { |
| 4791 | struct buffer_ref *ref = (struct buffer_ref *)buf->private; |
| 4792 | |
| 4793 | if (--ref->ref) |
| 4794 | return; |
| 4795 | |
| 4796 | ring_buffer_free_read_page(ref->buffer, ref->page); |
| 4797 | kfree(ref); |
| 4798 | buf->private = 0; |
| 4799 | } |
| 4800 | |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4801 | static void buffer_pipe_buf_get(struct pipe_inode_info *pipe, |
| 4802 | struct pipe_buffer *buf) |
| 4803 | { |
| 4804 | struct buffer_ref *ref = (struct buffer_ref *)buf->private; |
| 4805 | |
| 4806 | ref->ref++; |
| 4807 | } |
| 4808 | |
| 4809 | /* Pipe buffer operations for a buffer. */ |
Alexey Dobriyan | 28dfef8 | 2009-12-15 16:46:48 -0800 | [diff] [blame] | 4810 | static const struct pipe_buf_operations buffer_pipe_buf_ops = { |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4811 | .can_merge = 0, |
| 4812 | .map = generic_pipe_buf_map, |
| 4813 | .unmap = generic_pipe_buf_unmap, |
| 4814 | .confirm = generic_pipe_buf_confirm, |
| 4815 | .release = buffer_pipe_buf_release, |
Masami Hiramatsu | d55cb6c | 2012-08-09 21:31:10 +0900 | [diff] [blame] | 4816 | .steal = generic_pipe_buf_steal, |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4817 | .get = buffer_pipe_buf_get, |
| 4818 | }; |
| 4819 | |
| 4820 | /* |
| 4821 | * Callback from splice_to_pipe(), if we need to release some pages |
| 4822 | * at the end of the spd in case we error'ed out in filling the pipe. |
| 4823 | */ |
| 4824 | static void buffer_spd_release(struct splice_pipe_desc *spd, unsigned int i) |
| 4825 | { |
| 4826 | struct buffer_ref *ref = |
| 4827 | (struct buffer_ref *)spd->partial[i].private; |
| 4828 | |
| 4829 | if (--ref->ref) |
| 4830 | return; |
| 4831 | |
| 4832 | ring_buffer_free_read_page(ref->buffer, ref->page); |
| 4833 | kfree(ref); |
| 4834 | spd->partial[i].private = 0; |
| 4835 | } |
| 4836 | |
| 4837 | static ssize_t |
| 4838 | tracing_buffers_splice_read(struct file *file, loff_t *ppos, |
| 4839 | struct pipe_inode_info *pipe, size_t len, |
| 4840 | unsigned int flags) |
| 4841 | { |
| 4842 | struct ftrace_buffer_info *info = file->private_data; |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 4843 | struct trace_iterator *iter = &info->iter; |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 4844 | struct partial_page partial_def[PIPE_DEF_BUFFERS]; |
| 4845 | struct page *pages_def[PIPE_DEF_BUFFERS]; |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4846 | struct splice_pipe_desc spd = { |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 4847 | .pages = pages_def, |
| 4848 | .partial = partial_def, |
Eric Dumazet | 047fe36 | 2012-06-12 15:24:40 +0200 | [diff] [blame] | 4849 | .nr_pages_max = PIPE_DEF_BUFFERS, |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4850 | .flags = flags, |
| 4851 | .ops = &buffer_pipe_buf_ops, |
| 4852 | .spd_release = buffer_spd_release, |
| 4853 | }; |
| 4854 | struct buffer_ref *ref; |
Steven Rostedt | 93459c6 | 2009-04-29 00:23:13 -0400 | [diff] [blame] | 4855 | int entries, size, i; |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 4856 | ssize_t ret; |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4857 | |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 4858 | mutex_lock(&trace_types_lock); |
| 4859 | |
| 4860 | #ifdef CONFIG_TRACER_MAX_TRACE |
| 4861 | if (iter->snapshot && iter->tr->current_trace->use_max_tr) { |
| 4862 | ret = -EBUSY; |
| 4863 | goto out; |
| 4864 | } |
| 4865 | #endif |
| 4866 | |
| 4867 | if (splice_grow_spd(pipe, &spd)) { |
| 4868 | ret = -ENOMEM; |
| 4869 | goto out; |
| 4870 | } |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 4871 | |
Lai Jiangshan | 93cfb3c | 2009-04-02 15:17:08 +0800 | [diff] [blame] | 4872 | if (*ppos & (PAGE_SIZE - 1)) { |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 4873 | ret = -EINVAL; |
| 4874 | goto out; |
Lai Jiangshan | 93cfb3c | 2009-04-02 15:17:08 +0800 | [diff] [blame] | 4875 | } |
| 4876 | |
| 4877 | if (len & (PAGE_SIZE - 1)) { |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 4878 | if (len < PAGE_SIZE) { |
| 4879 | ret = -EINVAL; |
| 4880 | goto out; |
| 4881 | } |
Lai Jiangshan | 93cfb3c | 2009-04-02 15:17:08 +0800 | [diff] [blame] | 4882 | len &= PAGE_MASK; |
| 4883 | } |
| 4884 | |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 4885 | again: |
| 4886 | trace_access_lock(iter->cpu_file); |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4887 | entries = ring_buffer_entries_cpu(iter->trace_buffer->buffer, iter->cpu_file); |
Steven Rostedt | 93459c6 | 2009-04-29 00:23:13 -0400 | [diff] [blame] | 4888 | |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 4889 | for (i = 0; i < pipe->buffers && len && entries; i++, len -= PAGE_SIZE) { |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4890 | struct page *page; |
| 4891 | int r; |
| 4892 | |
| 4893 | ref = kzalloc(sizeof(*ref), GFP_KERNEL); |
| 4894 | if (!ref) |
| 4895 | break; |
| 4896 | |
Steven Rostedt | 7267fa6 | 2009-04-29 00:16:21 -0400 | [diff] [blame] | 4897 | ref->ref = 1; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4898 | ref->buffer = iter->trace_buffer->buffer; |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 4899 | ref->page = ring_buffer_alloc_read_page(ref->buffer, iter->cpu_file); |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4900 | if (!ref->page) { |
| 4901 | kfree(ref); |
| 4902 | break; |
| 4903 | } |
| 4904 | |
| 4905 | r = ring_buffer_read_page(ref->buffer, &ref->page, |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 4906 | len, iter->cpu_file, 1); |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4907 | if (r < 0) { |
Vaibhav Nagarnaik | 7ea5906 | 2011-05-03 17:56:42 -0700 | [diff] [blame] | 4908 | ring_buffer_free_read_page(ref->buffer, ref->page); |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4909 | kfree(ref); |
| 4910 | break; |
| 4911 | } |
| 4912 | |
| 4913 | /* |
| 4914 | * zero out any left over data, this is going to |
| 4915 | * user land. |
| 4916 | */ |
| 4917 | size = ring_buffer_page_len(ref->page); |
| 4918 | if (size < PAGE_SIZE) |
| 4919 | memset(ref->page + size, 0, PAGE_SIZE - size); |
| 4920 | |
| 4921 | page = virt_to_page(ref->page); |
| 4922 | |
| 4923 | spd.pages[i] = page; |
| 4924 | spd.partial[i].len = PAGE_SIZE; |
| 4925 | spd.partial[i].offset = 0; |
| 4926 | spd.partial[i].private = (unsigned long)ref; |
| 4927 | spd.nr_pages++; |
Lai Jiangshan | 93cfb3c | 2009-04-02 15:17:08 +0800 | [diff] [blame] | 4928 | *ppos += PAGE_SIZE; |
Steven Rostedt | 93459c6 | 2009-04-29 00:23:13 -0400 | [diff] [blame] | 4929 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4930 | entries = ring_buffer_entries_cpu(iter->trace_buffer->buffer, iter->cpu_file); |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4931 | } |
| 4932 | |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 4933 | trace_access_unlock(iter->cpu_file); |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4934 | spd.nr_pages = i; |
| 4935 | |
| 4936 | /* did we read anything? */ |
| 4937 | if (!spd.nr_pages) { |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 4938 | if ((file->f_flags & O_NONBLOCK) || (flags & SPLICE_F_NONBLOCK)) { |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4939 | ret = -EAGAIN; |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 4940 | goto out; |
| 4941 | } |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 4942 | mutex_unlock(&trace_types_lock); |
Steven Rostedt | b627344 | 2013-02-28 13:44:11 -0500 | [diff] [blame] | 4943 | iter->trace->wait_pipe(iter); |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 4944 | mutex_lock(&trace_types_lock); |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 4945 | if (signal_pending(current)) { |
| 4946 | ret = -EINTR; |
| 4947 | goto out; |
| 4948 | } |
| 4949 | goto again; |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4950 | } |
| 4951 | |
| 4952 | ret = splice_to_pipe(pipe, &spd); |
Eric Dumazet | 047fe36 | 2012-06-12 15:24:40 +0200 | [diff] [blame] | 4953 | splice_shrink_spd(&spd); |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 4954 | out: |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 4955 | mutex_unlock(&trace_types_lock); |
| 4956 | |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4957 | return ret; |
| 4958 | } |
| 4959 | |
| 4960 | static const struct file_operations tracing_buffers_fops = { |
| 4961 | .open = tracing_buffers_open, |
| 4962 | .read = tracing_buffers_read, |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 4963 | .poll = tracing_buffers_poll, |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 4964 | .release = tracing_buffers_release, |
| 4965 | .splice_read = tracing_buffers_splice_read, |
| 4966 | .llseek = no_llseek, |
| 4967 | }; |
| 4968 | |
Steven Rostedt | c8d7718 | 2009-04-29 18:03:45 -0400 | [diff] [blame] | 4969 | static ssize_t |
| 4970 | tracing_stats_read(struct file *filp, char __user *ubuf, |
| 4971 | size_t count, loff_t *ppos) |
| 4972 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4973 | struct trace_cpu *tc = filp->private_data; |
| 4974 | struct trace_array *tr = tc->tr; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4975 | struct trace_buffer *trace_buf = &tr->trace_buffer; |
Steven Rostedt | c8d7718 | 2009-04-29 18:03:45 -0400 | [diff] [blame] | 4976 | struct trace_seq *s; |
| 4977 | unsigned long cnt; |
Vaibhav Nagarnaik | c64e148 | 2011-08-16 14:46:16 -0700 | [diff] [blame] | 4978 | unsigned long long t; |
| 4979 | unsigned long usec_rem; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4980 | int cpu = tc->cpu; |
Steven Rostedt | c8d7718 | 2009-04-29 18:03:45 -0400 | [diff] [blame] | 4981 | |
Li Zefan | e4f2d10 | 2009-06-15 10:57:28 +0800 | [diff] [blame] | 4982 | s = kmalloc(sizeof(*s), GFP_KERNEL); |
Steven Rostedt | c8d7718 | 2009-04-29 18:03:45 -0400 | [diff] [blame] | 4983 | if (!s) |
Roel Kluin | a646365 | 2009-11-11 22:26:35 +0100 | [diff] [blame] | 4984 | return -ENOMEM; |
Steven Rostedt | c8d7718 | 2009-04-29 18:03:45 -0400 | [diff] [blame] | 4985 | |
| 4986 | trace_seq_init(s); |
| 4987 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4988 | cnt = ring_buffer_entries_cpu(trace_buf->buffer, cpu); |
Steven Rostedt | c8d7718 | 2009-04-29 18:03:45 -0400 | [diff] [blame] | 4989 | trace_seq_printf(s, "entries: %ld\n", cnt); |
| 4990 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4991 | cnt = ring_buffer_overrun_cpu(trace_buf->buffer, cpu); |
Steven Rostedt | c8d7718 | 2009-04-29 18:03:45 -0400 | [diff] [blame] | 4992 | trace_seq_printf(s, "overrun: %ld\n", cnt); |
| 4993 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4994 | cnt = ring_buffer_commit_overrun_cpu(trace_buf->buffer, cpu); |
Steven Rostedt | c8d7718 | 2009-04-29 18:03:45 -0400 | [diff] [blame] | 4995 | trace_seq_printf(s, "commit overrun: %ld\n", cnt); |
| 4996 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4997 | cnt = ring_buffer_bytes_cpu(trace_buf->buffer, cpu); |
Vaibhav Nagarnaik | c64e148 | 2011-08-16 14:46:16 -0700 | [diff] [blame] | 4998 | trace_seq_printf(s, "bytes: %ld\n", cnt); |
| 4999 | |
Yoshihiro YUNOMAE | 11043d8b | 2012-11-13 12:18:23 -0800 | [diff] [blame] | 5000 | if (trace_clocks[trace_clock_id].in_ns) { |
| 5001 | /* local or global for trace_clock */ |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5002 | t = ns2usecs(ring_buffer_oldest_event_ts(trace_buf->buffer, cpu)); |
Yoshihiro YUNOMAE | 11043d8b | 2012-11-13 12:18:23 -0800 | [diff] [blame] | 5003 | usec_rem = do_div(t, USEC_PER_SEC); |
| 5004 | trace_seq_printf(s, "oldest event ts: %5llu.%06lu\n", |
| 5005 | t, usec_rem); |
Vaibhav Nagarnaik | c64e148 | 2011-08-16 14:46:16 -0700 | [diff] [blame] | 5006 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5007 | t = ns2usecs(ring_buffer_time_stamp(trace_buf->buffer, cpu)); |
Yoshihiro YUNOMAE | 11043d8b | 2012-11-13 12:18:23 -0800 | [diff] [blame] | 5008 | usec_rem = do_div(t, USEC_PER_SEC); |
| 5009 | trace_seq_printf(s, "now ts: %5llu.%06lu\n", t, usec_rem); |
| 5010 | } else { |
| 5011 | /* counter or tsc mode for trace_clock */ |
| 5012 | trace_seq_printf(s, "oldest event ts: %llu\n", |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5013 | ring_buffer_oldest_event_ts(trace_buf->buffer, cpu)); |
Yoshihiro YUNOMAE | 11043d8b | 2012-11-13 12:18:23 -0800 | [diff] [blame] | 5014 | |
| 5015 | trace_seq_printf(s, "now ts: %llu\n", |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5016 | ring_buffer_time_stamp(trace_buf->buffer, cpu)); |
Yoshihiro YUNOMAE | 11043d8b | 2012-11-13 12:18:23 -0800 | [diff] [blame] | 5017 | } |
Vaibhav Nagarnaik | c64e148 | 2011-08-16 14:46:16 -0700 | [diff] [blame] | 5018 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5019 | cnt = ring_buffer_dropped_events_cpu(trace_buf->buffer, cpu); |
Slava Pestov | 884bfe8 | 2011-07-15 14:23:58 -0700 | [diff] [blame] | 5020 | trace_seq_printf(s, "dropped events: %ld\n", cnt); |
| 5021 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5022 | cnt = ring_buffer_read_events_cpu(trace_buf->buffer, cpu); |
Steven Rostedt (Red Hat) | ad96470 | 2013-01-29 17:45:49 -0500 | [diff] [blame] | 5023 | trace_seq_printf(s, "read events: %ld\n", cnt); |
| 5024 | |
Steven Rostedt | c8d7718 | 2009-04-29 18:03:45 -0400 | [diff] [blame] | 5025 | count = simple_read_from_buffer(ubuf, count, ppos, s->buffer, s->len); |
| 5026 | |
| 5027 | kfree(s); |
| 5028 | |
| 5029 | return count; |
| 5030 | } |
| 5031 | |
| 5032 | static const struct file_operations tracing_stats_fops = { |
| 5033 | .open = tracing_open_generic, |
| 5034 | .read = tracing_stats_read, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 5035 | .llseek = generic_file_llseek, |
Steven Rostedt | c8d7718 | 2009-04-29 18:03:45 -0400 | [diff] [blame] | 5036 | }; |
| 5037 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5038 | #ifdef CONFIG_DYNAMIC_FTRACE |
| 5039 | |
Steven Rostedt | b807c3d | 2008-10-30 16:08:33 -0400 | [diff] [blame] | 5040 | int __weak ftrace_arch_read_dyn_info(char *buf, int size) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5041 | { |
Steven Rostedt | b807c3d | 2008-10-30 16:08:33 -0400 | [diff] [blame] | 5042 | return 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5043 | } |
| 5044 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5045 | static ssize_t |
Steven Rostedt | b807c3d | 2008-10-30 16:08:33 -0400 | [diff] [blame] | 5046 | tracing_read_dyn_info(struct file *filp, char __user *ubuf, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5047 | size_t cnt, loff_t *ppos) |
| 5048 | { |
Steven Rostedt | a26a2a2 | 2008-10-31 00:03:22 -0400 | [diff] [blame] | 5049 | static char ftrace_dyn_info_buffer[1024]; |
| 5050 | static DEFINE_MUTEX(dyn_info_mutex); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5051 | unsigned long *p = filp->private_data; |
Steven Rostedt | b807c3d | 2008-10-30 16:08:33 -0400 | [diff] [blame] | 5052 | char *buf = ftrace_dyn_info_buffer; |
Steven Rostedt | a26a2a2 | 2008-10-31 00:03:22 -0400 | [diff] [blame] | 5053 | int size = ARRAY_SIZE(ftrace_dyn_info_buffer); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5054 | int r; |
| 5055 | |
Steven Rostedt | b807c3d | 2008-10-30 16:08:33 -0400 | [diff] [blame] | 5056 | mutex_lock(&dyn_info_mutex); |
| 5057 | r = sprintf(buf, "%ld ", *p); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5058 | |
Steven Rostedt | a26a2a2 | 2008-10-31 00:03:22 -0400 | [diff] [blame] | 5059 | r += ftrace_arch_read_dyn_info(buf+r, (size-1)-r); |
Steven Rostedt | b807c3d | 2008-10-30 16:08:33 -0400 | [diff] [blame] | 5060 | buf[r++] = '\n'; |
| 5061 | |
| 5062 | r = simple_read_from_buffer(ubuf, cnt, ppos, buf, r); |
| 5063 | |
| 5064 | mutex_unlock(&dyn_info_mutex); |
| 5065 | |
| 5066 | return r; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5067 | } |
| 5068 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 5069 | static const struct file_operations tracing_dyn_info_fops = { |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 5070 | .open = tracing_open_generic, |
Steven Rostedt | b807c3d | 2008-10-30 16:08:33 -0400 | [diff] [blame] | 5071 | .read = tracing_read_dyn_info, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 5072 | .llseek = generic_file_llseek, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5073 | }; |
| 5074 | #endif |
| 5075 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5076 | struct dentry *tracing_init_dentry_tr(struct trace_array *tr) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5077 | { |
| 5078 | static int once; |
| 5079 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5080 | if (tr->dir) |
| 5081 | return tr->dir; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5082 | |
Frederic Weisbecker | 3e1f60b | 2009-03-22 23:10:45 +0100 | [diff] [blame] | 5083 | if (!debugfs_initialized()) |
| 5084 | return NULL; |
| 5085 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5086 | if (tr->flags & TRACE_ARRAY_FL_GLOBAL) |
| 5087 | tr->dir = debugfs_create_dir("tracing", NULL); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5088 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5089 | if (!tr->dir && !once) { |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5090 | once = 1; |
| 5091 | pr_warning("Could not create debugfs directory 'tracing'\n"); |
| 5092 | return NULL; |
| 5093 | } |
| 5094 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5095 | return tr->dir; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5096 | } |
| 5097 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5098 | struct dentry *tracing_init_dentry(void) |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 5099 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5100 | return tracing_init_dentry_tr(&global_trace); |
| 5101 | } |
| 5102 | |
| 5103 | static struct dentry *tracing_dentry_percpu(struct trace_array *tr, int cpu) |
| 5104 | { |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 5105 | struct dentry *d_tracer; |
| 5106 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5107 | if (tr->percpu_dir) |
| 5108 | return tr->percpu_dir; |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 5109 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5110 | d_tracer = tracing_init_dentry_tr(tr); |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 5111 | if (!d_tracer) |
| 5112 | return NULL; |
| 5113 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5114 | tr->percpu_dir = debugfs_create_dir("per_cpu", d_tracer); |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 5115 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5116 | WARN_ONCE(!tr->percpu_dir, |
| 5117 | "Could not create debugfs directory 'per_cpu/%d'\n", cpu); |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 5118 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5119 | return tr->percpu_dir; |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 5120 | } |
| 5121 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5122 | static void |
| 5123 | tracing_init_debugfs_percpu(struct trace_array *tr, long cpu) |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 5124 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5125 | 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] | 5126 | struct dentry *d_percpu = tracing_dentry_percpu(tr, cpu); |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 5127 | struct dentry *d_cpu; |
Steven Rostedt | dd49a38 | 2010-10-20 21:51:26 -0400 | [diff] [blame] | 5128 | char cpu_dir[30]; /* 30 characters should be more than enough */ |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 5129 | |
Namhyung Kim | 0a3d7ce | 2012-04-23 10:11:57 +0900 | [diff] [blame] | 5130 | if (!d_percpu) |
| 5131 | return; |
| 5132 | |
Steven Rostedt | dd49a38 | 2010-10-20 21:51:26 -0400 | [diff] [blame] | 5133 | snprintf(cpu_dir, 30, "cpu%ld", cpu); |
Frederic Weisbecker | 8656e7a | 2009-02-26 00:41:38 +0100 | [diff] [blame] | 5134 | d_cpu = debugfs_create_dir(cpu_dir, d_percpu); |
| 5135 | if (!d_cpu) { |
| 5136 | pr_warning("Could not create debugfs '%s' entry\n", cpu_dir); |
| 5137 | return; |
| 5138 | } |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 5139 | |
Frederic Weisbecker | 8656e7a | 2009-02-26 00:41:38 +0100 | [diff] [blame] | 5140 | /* per cpu trace_pipe */ |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 5141 | trace_create_file("trace_pipe", 0444, d_cpu, |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5142 | (void *)&data->trace_cpu, &tracing_pipe_fops); |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 5143 | |
| 5144 | /* per cpu trace */ |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 5145 | trace_create_file("trace", 0644, d_cpu, |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5146 | (void *)&data->trace_cpu, &tracing_fops); |
Steven Rostedt | 7f96f93 | 2009-03-13 00:37:42 -0400 | [diff] [blame] | 5147 | |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 5148 | trace_create_file("trace_pipe_raw", 0444, d_cpu, |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5149 | (void *)&data->trace_cpu, &tracing_buffers_fops); |
Steven Rostedt | c8d7718 | 2009-04-29 18:03:45 -0400 | [diff] [blame] | 5150 | |
| 5151 | trace_create_file("stats", 0444, d_cpu, |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5152 | (void *)&data->trace_cpu, &tracing_stats_fops); |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 5153 | |
| 5154 | trace_create_file("buffer_size_kb", 0444, d_cpu, |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5155 | (void *)&data->trace_cpu, &tracing_entries_fops); |
Steven Rostedt (Red Hat) | f1affca | 2013-03-05 14:35:11 -0500 | [diff] [blame] | 5156 | |
| 5157 | #ifdef CONFIG_TRACER_SNAPSHOT |
| 5158 | trace_create_file("snapshot", 0644, d_cpu, |
| 5159 | (void *)&data->trace_cpu, &snapshot_fops); |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 5160 | |
| 5161 | trace_create_file("snapshot_raw", 0444, d_cpu, |
| 5162 | (void *)&data->trace_cpu, &snapshot_raw_fops); |
Steven Rostedt (Red Hat) | f1affca | 2013-03-05 14:35:11 -0500 | [diff] [blame] | 5163 | #endif |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 5164 | } |
| 5165 | |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 5166 | #ifdef CONFIG_FTRACE_SELFTEST |
| 5167 | /* Let selftest have access to static functions in this file */ |
| 5168 | #include "trace_selftest.c" |
| 5169 | #endif |
| 5170 | |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 5171 | struct trace_option_dentry { |
| 5172 | struct tracer_opt *opt; |
| 5173 | struct tracer_flags *flags; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5174 | struct trace_array *tr; |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 5175 | struct dentry *entry; |
| 5176 | }; |
| 5177 | |
| 5178 | static ssize_t |
| 5179 | trace_options_read(struct file *filp, char __user *ubuf, size_t cnt, |
| 5180 | loff_t *ppos) |
| 5181 | { |
| 5182 | struct trace_option_dentry *topt = filp->private_data; |
| 5183 | char *buf; |
| 5184 | |
| 5185 | if (topt->flags->val & topt->opt->bit) |
| 5186 | buf = "1\n"; |
| 5187 | else |
| 5188 | buf = "0\n"; |
| 5189 | |
| 5190 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, 2); |
| 5191 | } |
| 5192 | |
| 5193 | static ssize_t |
| 5194 | trace_options_write(struct file *filp, const char __user *ubuf, size_t cnt, |
| 5195 | loff_t *ppos) |
| 5196 | { |
| 5197 | struct trace_option_dentry *topt = filp->private_data; |
| 5198 | unsigned long val; |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 5199 | int ret; |
| 5200 | |
Peter Huewe | 22fe9b5 | 2011-06-07 21:58:27 +0200 | [diff] [blame] | 5201 | ret = kstrtoul_from_user(ubuf, cnt, 10, &val); |
| 5202 | if (ret) |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 5203 | return ret; |
| 5204 | |
Li Zefan | 8d18eaa | 2009-12-08 11:17:06 +0800 | [diff] [blame] | 5205 | if (val != 0 && val != 1) |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 5206 | return -EINVAL; |
Li Zefan | 8d18eaa | 2009-12-08 11:17:06 +0800 | [diff] [blame] | 5207 | |
| 5208 | if (!!(topt->flags->val & topt->opt->bit) != val) { |
| 5209 | mutex_lock(&trace_types_lock); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5210 | ret = __set_tracer_option(topt->tr->current_trace, topt->flags, |
Steven Rostedt | c757bea | 2009-12-21 22:35:16 -0500 | [diff] [blame] | 5211 | topt->opt, !val); |
Li Zefan | 8d18eaa | 2009-12-08 11:17:06 +0800 | [diff] [blame] | 5212 | mutex_unlock(&trace_types_lock); |
| 5213 | if (ret) |
| 5214 | return ret; |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 5215 | } |
| 5216 | |
| 5217 | *ppos += cnt; |
| 5218 | |
| 5219 | return cnt; |
| 5220 | } |
| 5221 | |
| 5222 | |
| 5223 | static const struct file_operations trace_options_fops = { |
| 5224 | .open = tracing_open_generic, |
| 5225 | .read = trace_options_read, |
| 5226 | .write = trace_options_write, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 5227 | .llseek = generic_file_llseek, |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 5228 | }; |
| 5229 | |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5230 | static ssize_t |
| 5231 | trace_options_core_read(struct file *filp, char __user *ubuf, size_t cnt, |
| 5232 | loff_t *ppos) |
| 5233 | { |
| 5234 | long index = (long)filp->private_data; |
| 5235 | char *buf; |
| 5236 | |
| 5237 | if (trace_flags & (1 << index)) |
| 5238 | buf = "1\n"; |
| 5239 | else |
| 5240 | buf = "0\n"; |
| 5241 | |
| 5242 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, 2); |
| 5243 | } |
| 5244 | |
| 5245 | static ssize_t |
| 5246 | trace_options_core_write(struct file *filp, const char __user *ubuf, size_t cnt, |
| 5247 | loff_t *ppos) |
| 5248 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5249 | struct trace_array *tr = &global_trace; |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5250 | long index = (long)filp->private_data; |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5251 | unsigned long val; |
| 5252 | int ret; |
| 5253 | |
Peter Huewe | 22fe9b5 | 2011-06-07 21:58:27 +0200 | [diff] [blame] | 5254 | ret = kstrtoul_from_user(ubuf, cnt, 10, &val); |
| 5255 | if (ret) |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5256 | return ret; |
| 5257 | |
Zhaolei | f2d84b6 | 2009-08-07 18:55:48 +0800 | [diff] [blame] | 5258 | if (val != 0 && val != 1) |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5259 | return -EINVAL; |
Steven Rostedt (Red Hat) | 69d34da | 2013-03-14 13:50:56 -0400 | [diff] [blame] | 5260 | |
| 5261 | mutex_lock(&trace_types_lock); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5262 | ret = set_tracer_flag(tr, 1 << index, val); |
Steven Rostedt (Red Hat) | 69d34da | 2013-03-14 13:50:56 -0400 | [diff] [blame] | 5263 | mutex_unlock(&trace_types_lock); |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5264 | |
Steven Rostedt (Red Hat) | 613f04a | 2013-03-14 15:03:53 -0400 | [diff] [blame] | 5265 | if (ret < 0) |
| 5266 | return ret; |
| 5267 | |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5268 | *ppos += cnt; |
| 5269 | |
| 5270 | return cnt; |
| 5271 | } |
| 5272 | |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5273 | static const struct file_operations trace_options_core_fops = { |
| 5274 | .open = tracing_open_generic, |
| 5275 | .read = trace_options_core_read, |
| 5276 | .write = trace_options_core_write, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 5277 | .llseek = generic_file_llseek, |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5278 | }; |
| 5279 | |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 5280 | struct dentry *trace_create_file(const char *name, |
Al Viro | f4ae40a6 | 2011-07-24 04:33:43 -0400 | [diff] [blame] | 5281 | umode_t mode, |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 5282 | struct dentry *parent, |
| 5283 | void *data, |
| 5284 | const struct file_operations *fops) |
| 5285 | { |
| 5286 | struct dentry *ret; |
| 5287 | |
| 5288 | ret = debugfs_create_file(name, mode, parent, data, fops); |
| 5289 | if (!ret) |
| 5290 | pr_warning("Could not create debugfs '%s' entry\n", name); |
| 5291 | |
| 5292 | return ret; |
| 5293 | } |
| 5294 | |
| 5295 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5296 | static struct dentry *trace_options_init_dentry(struct trace_array *tr) |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5297 | { |
| 5298 | struct dentry *d_tracer; |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5299 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5300 | if (tr->options) |
| 5301 | return tr->options; |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5302 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5303 | d_tracer = tracing_init_dentry_tr(tr); |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5304 | if (!d_tracer) |
| 5305 | return NULL; |
| 5306 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5307 | tr->options = debugfs_create_dir("options", d_tracer); |
| 5308 | if (!tr->options) { |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5309 | pr_warning("Could not create debugfs directory 'options'\n"); |
| 5310 | return NULL; |
| 5311 | } |
| 5312 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5313 | return tr->options; |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5314 | } |
| 5315 | |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 5316 | static void |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5317 | create_trace_option_file(struct trace_array *tr, |
| 5318 | struct trace_option_dentry *topt, |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 5319 | struct tracer_flags *flags, |
| 5320 | struct tracer_opt *opt) |
| 5321 | { |
| 5322 | struct dentry *t_options; |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 5323 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5324 | t_options = trace_options_init_dentry(tr); |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 5325 | if (!t_options) |
| 5326 | return; |
| 5327 | |
| 5328 | topt->flags = flags; |
| 5329 | topt->opt = opt; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5330 | topt->tr = tr; |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 5331 | |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 5332 | topt->entry = trace_create_file(opt->name, 0644, t_options, topt, |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 5333 | &trace_options_fops); |
| 5334 | |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 5335 | } |
| 5336 | |
| 5337 | static struct trace_option_dentry * |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5338 | create_trace_option_files(struct trace_array *tr, struct tracer *tracer) |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 5339 | { |
| 5340 | struct trace_option_dentry *topts; |
| 5341 | struct tracer_flags *flags; |
| 5342 | struct tracer_opt *opts; |
| 5343 | int cnt; |
| 5344 | |
| 5345 | if (!tracer) |
| 5346 | return NULL; |
| 5347 | |
| 5348 | flags = tracer->flags; |
| 5349 | |
| 5350 | if (!flags || !flags->opts) |
| 5351 | return NULL; |
| 5352 | |
| 5353 | opts = flags->opts; |
| 5354 | |
| 5355 | for (cnt = 0; opts[cnt].name; cnt++) |
| 5356 | ; |
| 5357 | |
Steven Rostedt | 0cfe824 | 2009-02-27 10:51:10 -0500 | [diff] [blame] | 5358 | topts = kcalloc(cnt + 1, sizeof(*topts), GFP_KERNEL); |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 5359 | if (!topts) |
| 5360 | return NULL; |
| 5361 | |
| 5362 | for (cnt = 0; opts[cnt].name; cnt++) |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5363 | create_trace_option_file(tr, &topts[cnt], flags, |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 5364 | &opts[cnt]); |
| 5365 | |
| 5366 | return topts; |
| 5367 | } |
| 5368 | |
| 5369 | static void |
| 5370 | destroy_trace_option_files(struct trace_option_dentry *topts) |
| 5371 | { |
| 5372 | int cnt; |
| 5373 | |
| 5374 | if (!topts) |
| 5375 | return; |
| 5376 | |
| 5377 | for (cnt = 0; topts[cnt].opt; cnt++) { |
| 5378 | if (topts[cnt].entry) |
| 5379 | debugfs_remove(topts[cnt].entry); |
| 5380 | } |
| 5381 | |
| 5382 | kfree(topts); |
| 5383 | } |
| 5384 | |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5385 | static struct dentry * |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5386 | create_trace_option_core_file(struct trace_array *tr, |
| 5387 | const char *option, long index) |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5388 | { |
| 5389 | struct dentry *t_options; |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5390 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5391 | t_options = trace_options_init_dentry(tr); |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5392 | if (!t_options) |
| 5393 | return NULL; |
| 5394 | |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 5395 | return trace_create_file(option, 0644, t_options, (void *)index, |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5396 | &trace_options_core_fops); |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5397 | } |
| 5398 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5399 | static __init void create_trace_options_dir(struct trace_array *tr) |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5400 | { |
| 5401 | struct dentry *t_options; |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5402 | int i; |
| 5403 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5404 | t_options = trace_options_init_dentry(tr); |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5405 | if (!t_options) |
| 5406 | return; |
| 5407 | |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 5408 | for (i = 0; trace_options[i]; i++) |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5409 | create_trace_option_core_file(tr, trace_options[i], i); |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 5410 | } |
| 5411 | |
Steven Rostedt | 499e547 | 2012-02-22 15:50:28 -0500 | [diff] [blame] | 5412 | static ssize_t |
| 5413 | rb_simple_read(struct file *filp, char __user *ubuf, |
| 5414 | size_t cnt, loff_t *ppos) |
| 5415 | { |
Steven Rostedt | 348f0fc | 2012-04-16 15:41:28 -0400 | [diff] [blame] | 5416 | struct trace_array *tr = filp->private_data; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5417 | struct ring_buffer *buffer = tr->trace_buffer.buffer; |
Steven Rostedt | 499e547 | 2012-02-22 15:50:28 -0500 | [diff] [blame] | 5418 | char buf[64]; |
| 5419 | int r; |
| 5420 | |
| 5421 | if (buffer) |
| 5422 | r = ring_buffer_record_is_on(buffer); |
| 5423 | else |
| 5424 | r = 0; |
| 5425 | |
| 5426 | r = sprintf(buf, "%d\n", r); |
| 5427 | |
| 5428 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, r); |
| 5429 | } |
| 5430 | |
| 5431 | static ssize_t |
| 5432 | rb_simple_write(struct file *filp, const char __user *ubuf, |
| 5433 | size_t cnt, loff_t *ppos) |
| 5434 | { |
Steven Rostedt | 348f0fc | 2012-04-16 15:41:28 -0400 | [diff] [blame] | 5435 | struct trace_array *tr = filp->private_data; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5436 | struct ring_buffer *buffer = tr->trace_buffer.buffer; |
Steven Rostedt | 499e547 | 2012-02-22 15:50:28 -0500 | [diff] [blame] | 5437 | unsigned long val; |
| 5438 | int ret; |
| 5439 | |
| 5440 | ret = kstrtoul_from_user(ubuf, cnt, 10, &val); |
| 5441 | if (ret) |
| 5442 | return ret; |
| 5443 | |
| 5444 | if (buffer) { |
Steven Rostedt | 2df8f8a | 2013-01-11 16:14:10 -0500 | [diff] [blame] | 5445 | mutex_lock(&trace_types_lock); |
| 5446 | if (val) { |
Steven Rostedt | 499e547 | 2012-02-22 15:50:28 -0500 | [diff] [blame] | 5447 | ring_buffer_record_on(buffer); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5448 | if (tr->current_trace->start) |
| 5449 | tr->current_trace->start(tr); |
Steven Rostedt | 2df8f8a | 2013-01-11 16:14:10 -0500 | [diff] [blame] | 5450 | } else { |
Steven Rostedt | 499e547 | 2012-02-22 15:50:28 -0500 | [diff] [blame] | 5451 | ring_buffer_record_off(buffer); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5452 | if (tr->current_trace->stop) |
| 5453 | tr->current_trace->stop(tr); |
Steven Rostedt | 2df8f8a | 2013-01-11 16:14:10 -0500 | [diff] [blame] | 5454 | } |
| 5455 | mutex_unlock(&trace_types_lock); |
Steven Rostedt | 499e547 | 2012-02-22 15:50:28 -0500 | [diff] [blame] | 5456 | } |
| 5457 | |
| 5458 | (*ppos)++; |
| 5459 | |
| 5460 | return cnt; |
| 5461 | } |
| 5462 | |
| 5463 | static const struct file_operations rb_simple_fops = { |
| 5464 | .open = tracing_open_generic, |
| 5465 | .read = rb_simple_read, |
| 5466 | .write = rb_simple_write, |
| 5467 | .llseek = default_llseek, |
| 5468 | }; |
| 5469 | |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 5470 | struct dentry *trace_instance_dir; |
| 5471 | |
| 5472 | static void |
| 5473 | init_tracer_debugfs(struct trace_array *tr, struct dentry *d_tracer); |
| 5474 | |
Steven Rostedt (Red Hat) | 737223f | 2013-03-05 21:13:47 -0500 | [diff] [blame] | 5475 | static void init_trace_buffers(struct trace_array *tr, struct trace_buffer *buf) |
| 5476 | { |
| 5477 | int cpu; |
| 5478 | |
| 5479 | for_each_tracing_cpu(cpu) { |
| 5480 | memset(per_cpu_ptr(buf->data, cpu), 0, sizeof(struct trace_array_cpu)); |
| 5481 | per_cpu_ptr(buf->data, cpu)->trace_cpu.cpu = cpu; |
| 5482 | per_cpu_ptr(buf->data, cpu)->trace_cpu.tr = tr; |
| 5483 | } |
| 5484 | } |
| 5485 | |
Steven Rostedt (Red Hat) | 55034cd | 2013-03-07 22:48:09 -0500 | [diff] [blame] | 5486 | static int |
| 5487 | 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] | 5488 | { |
| 5489 | enum ring_buffer_flags rb_flags; |
Steven Rostedt (Red Hat) | 737223f | 2013-03-05 21:13:47 -0500 | [diff] [blame] | 5490 | |
| 5491 | rb_flags = trace_flags & TRACE_ITER_OVERWRITE ? RB_FL_OVERWRITE : 0; |
| 5492 | |
Steven Rostedt (Red Hat) | 55034cd | 2013-03-07 22:48:09 -0500 | [diff] [blame] | 5493 | buf->buffer = ring_buffer_alloc(size, rb_flags); |
| 5494 | if (!buf->buffer) |
| 5495 | return -ENOMEM; |
Steven Rostedt (Red Hat) | 737223f | 2013-03-05 21:13:47 -0500 | [diff] [blame] | 5496 | |
Steven Rostedt (Red Hat) | 55034cd | 2013-03-07 22:48:09 -0500 | [diff] [blame] | 5497 | buf->data = alloc_percpu(struct trace_array_cpu); |
| 5498 | if (!buf->data) { |
| 5499 | ring_buffer_free(buf->buffer); |
| 5500 | return -ENOMEM; |
| 5501 | } |
Steven Rostedt (Red Hat) | 737223f | 2013-03-05 21:13:47 -0500 | [diff] [blame] | 5502 | |
Steven Rostedt (Red Hat) | 55034cd | 2013-03-07 22:48:09 -0500 | [diff] [blame] | 5503 | init_trace_buffers(tr, buf); |
Steven Rostedt (Red Hat) | 737223f | 2013-03-05 21:13:47 -0500 | [diff] [blame] | 5504 | |
| 5505 | /* Allocate the first page for all buffers */ |
| 5506 | set_buffer_entries(&tr->trace_buffer, |
| 5507 | ring_buffer_size(tr->trace_buffer.buffer, 0)); |
| 5508 | |
Steven Rostedt (Red Hat) | 55034cd | 2013-03-07 22:48:09 -0500 | [diff] [blame] | 5509 | return 0; |
| 5510 | } |
| 5511 | |
| 5512 | static int allocate_trace_buffers(struct trace_array *tr, int size) |
| 5513 | { |
| 5514 | int ret; |
| 5515 | |
| 5516 | ret = allocate_trace_buffer(tr, &tr->trace_buffer, size); |
| 5517 | if (ret) |
| 5518 | return ret; |
| 5519 | |
Steven Rostedt (Red Hat) | 737223f | 2013-03-05 21:13:47 -0500 | [diff] [blame] | 5520 | #ifdef CONFIG_TRACER_MAX_TRACE |
Steven Rostedt (Red Hat) | 55034cd | 2013-03-07 22:48:09 -0500 | [diff] [blame] | 5521 | ret = allocate_trace_buffer(tr, &tr->max_buffer, |
| 5522 | allocate_snapshot ? size : 1); |
| 5523 | if (WARN_ON(ret)) { |
| 5524 | ring_buffer_free(tr->trace_buffer.buffer); |
| 5525 | free_percpu(tr->trace_buffer.data); |
| 5526 | return -ENOMEM; |
| 5527 | } |
| 5528 | tr->allocated_snapshot = allocate_snapshot; |
Steven Rostedt (Red Hat) | 737223f | 2013-03-05 21:13:47 -0500 | [diff] [blame] | 5529 | |
Steven Rostedt (Red Hat) | 55034cd | 2013-03-07 22:48:09 -0500 | [diff] [blame] | 5530 | /* |
| 5531 | * Only the top level trace array gets its snapshot allocated |
| 5532 | * from the kernel command line. |
| 5533 | */ |
| 5534 | allocate_snapshot = false; |
Steven Rostedt (Red Hat) | 737223f | 2013-03-05 21:13:47 -0500 | [diff] [blame] | 5535 | #endif |
| 5536 | return 0; |
Steven Rostedt (Red Hat) | 737223f | 2013-03-05 21:13:47 -0500 | [diff] [blame] | 5537 | } |
| 5538 | |
| 5539 | static int new_instance_create(const char *name) |
| 5540 | { |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 5541 | struct trace_array *tr; |
| 5542 | int ret; |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 5543 | |
| 5544 | mutex_lock(&trace_types_lock); |
| 5545 | |
| 5546 | ret = -EEXIST; |
| 5547 | list_for_each_entry(tr, &ftrace_trace_arrays, list) { |
| 5548 | if (tr->name && strcmp(tr->name, name) == 0) |
| 5549 | goto out_unlock; |
| 5550 | } |
| 5551 | |
| 5552 | ret = -ENOMEM; |
| 5553 | tr = kzalloc(sizeof(*tr), GFP_KERNEL); |
| 5554 | if (!tr) |
| 5555 | goto out_unlock; |
| 5556 | |
| 5557 | tr->name = kstrdup(name, GFP_KERNEL); |
| 5558 | if (!tr->name) |
| 5559 | goto out_free_tr; |
| 5560 | |
| 5561 | raw_spin_lock_init(&tr->start_lock); |
| 5562 | |
| 5563 | tr->current_trace = &nop_trace; |
| 5564 | |
| 5565 | INIT_LIST_HEAD(&tr->systems); |
| 5566 | INIT_LIST_HEAD(&tr->events); |
| 5567 | |
Steven Rostedt (Red Hat) | 737223f | 2013-03-05 21:13:47 -0500 | [diff] [blame] | 5568 | if (allocate_trace_buffers(tr, trace_buf_size) < 0) |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 5569 | goto out_free_tr; |
| 5570 | |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 5571 | /* Holder for file callbacks */ |
| 5572 | tr->trace_cpu.cpu = RING_BUFFER_ALL_CPUS; |
| 5573 | tr->trace_cpu.tr = tr; |
| 5574 | |
| 5575 | tr->dir = debugfs_create_dir(name, trace_instance_dir); |
| 5576 | if (!tr->dir) |
| 5577 | goto out_free_tr; |
| 5578 | |
| 5579 | ret = event_trace_add_tracer(tr->dir, tr); |
| 5580 | if (ret) |
| 5581 | goto out_free_tr; |
| 5582 | |
| 5583 | init_tracer_debugfs(tr, tr->dir); |
| 5584 | |
| 5585 | list_add(&tr->list, &ftrace_trace_arrays); |
| 5586 | |
| 5587 | mutex_unlock(&trace_types_lock); |
| 5588 | |
| 5589 | return 0; |
| 5590 | |
| 5591 | out_free_tr: |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5592 | if (tr->trace_buffer.buffer) |
| 5593 | ring_buffer_free(tr->trace_buffer.buffer); |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 5594 | kfree(tr->name); |
| 5595 | kfree(tr); |
| 5596 | |
| 5597 | out_unlock: |
| 5598 | mutex_unlock(&trace_types_lock); |
| 5599 | |
| 5600 | return ret; |
| 5601 | |
| 5602 | } |
| 5603 | |
Steven Rostedt | 0c8916c | 2012-08-07 16:14:16 -0400 | [diff] [blame] | 5604 | static int instance_delete(const char *name) |
| 5605 | { |
| 5606 | struct trace_array *tr; |
| 5607 | int found = 0; |
| 5608 | int ret; |
| 5609 | |
| 5610 | mutex_lock(&trace_types_lock); |
| 5611 | |
| 5612 | ret = -ENODEV; |
| 5613 | list_for_each_entry(tr, &ftrace_trace_arrays, list) { |
| 5614 | if (tr->name && strcmp(tr->name, name) == 0) { |
| 5615 | found = 1; |
| 5616 | break; |
| 5617 | } |
| 5618 | } |
| 5619 | if (!found) |
| 5620 | goto out_unlock; |
| 5621 | |
Steven Rostedt (Red Hat) | a695cb5 | 2013-03-06 15:27:24 -0500 | [diff] [blame] | 5622 | ret = -EBUSY; |
| 5623 | if (tr->ref) |
| 5624 | goto out_unlock; |
| 5625 | |
Steven Rostedt | 0c8916c | 2012-08-07 16:14:16 -0400 | [diff] [blame] | 5626 | list_del(&tr->list); |
| 5627 | |
| 5628 | event_trace_del_tracer(tr); |
| 5629 | debugfs_remove_recursive(tr->dir); |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5630 | free_percpu(tr->trace_buffer.data); |
| 5631 | ring_buffer_free(tr->trace_buffer.buffer); |
Steven Rostedt | 0c8916c | 2012-08-07 16:14:16 -0400 | [diff] [blame] | 5632 | |
| 5633 | kfree(tr->name); |
| 5634 | kfree(tr); |
| 5635 | |
| 5636 | ret = 0; |
| 5637 | |
| 5638 | out_unlock: |
| 5639 | mutex_unlock(&trace_types_lock); |
| 5640 | |
| 5641 | return ret; |
| 5642 | } |
| 5643 | |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 5644 | static int instance_mkdir (struct inode *inode, struct dentry *dentry, umode_t mode) |
| 5645 | { |
| 5646 | struct dentry *parent; |
| 5647 | int ret; |
| 5648 | |
| 5649 | /* Paranoid: Make sure the parent is the "instances" directory */ |
| 5650 | parent = hlist_entry(inode->i_dentry.first, struct dentry, d_alias); |
| 5651 | if (WARN_ON_ONCE(parent != trace_instance_dir)) |
| 5652 | return -ENOENT; |
| 5653 | |
| 5654 | /* |
| 5655 | * The inode mutex is locked, but debugfs_create_dir() will also |
| 5656 | * take the mutex. As the instances directory can not be destroyed |
| 5657 | * or changed in any other way, it is safe to unlock it, and |
| 5658 | * let the dentry try. If two users try to make the same dir at |
| 5659 | * the same time, then the new_instance_create() will determine the |
| 5660 | * winner. |
| 5661 | */ |
| 5662 | mutex_unlock(&inode->i_mutex); |
| 5663 | |
| 5664 | ret = new_instance_create(dentry->d_iname); |
| 5665 | |
| 5666 | mutex_lock(&inode->i_mutex); |
| 5667 | |
| 5668 | return ret; |
| 5669 | } |
| 5670 | |
Steven Rostedt | 0c8916c | 2012-08-07 16:14:16 -0400 | [diff] [blame] | 5671 | static int instance_rmdir(struct inode *inode, struct dentry *dentry) |
| 5672 | { |
| 5673 | struct dentry *parent; |
| 5674 | int ret; |
| 5675 | |
| 5676 | /* Paranoid: Make sure the parent is the "instances" directory */ |
| 5677 | parent = hlist_entry(inode->i_dentry.first, struct dentry, d_alias); |
| 5678 | if (WARN_ON_ONCE(parent != trace_instance_dir)) |
| 5679 | return -ENOENT; |
| 5680 | |
| 5681 | /* The caller did a dget() on dentry */ |
| 5682 | mutex_unlock(&dentry->d_inode->i_mutex); |
| 5683 | |
| 5684 | /* |
| 5685 | * The inode mutex is locked, but debugfs_create_dir() will also |
| 5686 | * take the mutex. As the instances directory can not be destroyed |
| 5687 | * or changed in any other way, it is safe to unlock it, and |
| 5688 | * let the dentry try. If two users try to make the same dir at |
| 5689 | * the same time, then the instance_delete() will determine the |
| 5690 | * winner. |
| 5691 | */ |
| 5692 | mutex_unlock(&inode->i_mutex); |
| 5693 | |
| 5694 | ret = instance_delete(dentry->d_iname); |
| 5695 | |
| 5696 | mutex_lock_nested(&inode->i_mutex, I_MUTEX_PARENT); |
| 5697 | mutex_lock(&dentry->d_inode->i_mutex); |
| 5698 | |
| 5699 | return ret; |
| 5700 | } |
| 5701 | |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 5702 | static const struct inode_operations instance_dir_inode_operations = { |
| 5703 | .lookup = simple_lookup, |
| 5704 | .mkdir = instance_mkdir, |
Steven Rostedt | 0c8916c | 2012-08-07 16:14:16 -0400 | [diff] [blame] | 5705 | .rmdir = instance_rmdir, |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 5706 | }; |
| 5707 | |
| 5708 | static __init void create_trace_instances(struct dentry *d_tracer) |
| 5709 | { |
| 5710 | trace_instance_dir = debugfs_create_dir("instances", d_tracer); |
| 5711 | if (WARN_ON(!trace_instance_dir)) |
| 5712 | return; |
| 5713 | |
| 5714 | /* Hijack the dir inode operations, to allow mkdir */ |
| 5715 | trace_instance_dir->d_inode->i_op = &instance_dir_inode_operations; |
| 5716 | } |
| 5717 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5718 | static void |
| 5719 | init_tracer_debugfs(struct trace_array *tr, struct dentry *d_tracer) |
| 5720 | { |
Steven Rostedt (Red Hat) | 121aaee | 2013-03-05 21:52:25 -0500 | [diff] [blame] | 5721 | int cpu; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5722 | |
| 5723 | trace_create_file("trace_options", 0644, d_tracer, |
| 5724 | tr, &tracing_iter_fops); |
| 5725 | |
| 5726 | trace_create_file("trace", 0644, d_tracer, |
| 5727 | (void *)&tr->trace_cpu, &tracing_fops); |
| 5728 | |
| 5729 | trace_create_file("trace_pipe", 0444, d_tracer, |
| 5730 | (void *)&tr->trace_cpu, &tracing_pipe_fops); |
| 5731 | |
| 5732 | trace_create_file("buffer_size_kb", 0644, d_tracer, |
| 5733 | (void *)&tr->trace_cpu, &tracing_entries_fops); |
| 5734 | |
| 5735 | trace_create_file("buffer_total_size_kb", 0444, d_tracer, |
| 5736 | tr, &tracing_total_entries_fops); |
| 5737 | |
| 5738 | trace_create_file("free_buffer", 0644, d_tracer, |
| 5739 | tr, &tracing_free_buffer_fops); |
| 5740 | |
| 5741 | trace_create_file("trace_marker", 0220, d_tracer, |
| 5742 | tr, &tracing_mark_fops); |
| 5743 | |
| 5744 | trace_create_file("trace_clock", 0644, d_tracer, tr, |
| 5745 | &trace_clock_fops); |
| 5746 | |
| 5747 | trace_create_file("tracing_on", 0644, d_tracer, |
| 5748 | tr, &rb_simple_fops); |
Steven Rostedt (Red Hat) | ce9bae5 | 2013-03-05 21:23:55 -0500 | [diff] [blame] | 5749 | |
| 5750 | #ifdef CONFIG_TRACER_SNAPSHOT |
| 5751 | trace_create_file("snapshot", 0644, d_tracer, |
| 5752 | (void *)&tr->trace_cpu, &snapshot_fops); |
| 5753 | #endif |
Steven Rostedt (Red Hat) | 121aaee | 2013-03-05 21:52:25 -0500 | [diff] [blame] | 5754 | |
| 5755 | for_each_tracing_cpu(cpu) |
| 5756 | tracing_init_debugfs_percpu(tr, cpu); |
| 5757 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5758 | } |
| 5759 | |
Frédéric Weisbecker | b5ad384 | 2008-09-23 11:34:32 +0100 | [diff] [blame] | 5760 | static __init int tracer_init_debugfs(void) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5761 | { |
| 5762 | struct dentry *d_tracer; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5763 | |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 5764 | trace_access_lock_init(); |
| 5765 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5766 | d_tracer = tracing_init_dentry(); |
| 5767 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5768 | init_tracer_debugfs(&global_trace, d_tracer); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5769 | |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 5770 | trace_create_file("tracing_cpumask", 0644, d_tracer, |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5771 | &global_trace, &tracing_cpumask_fops); |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 5772 | |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 5773 | trace_create_file("available_tracers", 0444, d_tracer, |
| 5774 | &global_trace, &show_traces_fops); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5775 | |
Li Zefan | 339ae5d | 2009-04-17 10:34:30 +0800 | [diff] [blame] | 5776 | trace_create_file("current_tracer", 0644, d_tracer, |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 5777 | &global_trace, &set_tracer_fops); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5778 | |
Steven Rostedt | 5d4a9db | 2009-08-27 16:52:21 -0400 | [diff] [blame] | 5779 | #ifdef CONFIG_TRACER_MAX_TRACE |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 5780 | trace_create_file("tracing_max_latency", 0644, d_tracer, |
| 5781 | &tracing_max_latency, &tracing_max_lat_fops); |
Tim Bird | 0e95017 | 2010-02-25 15:36:43 -0800 | [diff] [blame] | 5782 | #endif |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5783 | |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 5784 | trace_create_file("tracing_thresh", 0644, d_tracer, |
| 5785 | &tracing_thresh, &tracing_max_lat_fops); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5786 | |
Li Zefan | 339ae5d | 2009-04-17 10:34:30 +0800 | [diff] [blame] | 5787 | trace_create_file("README", 0444, d_tracer, |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 5788 | NULL, &tracing_readme_fops); |
Ingo Molnar | 7bd2f24 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 5789 | |
Avadh Patel | 69abe6a | 2009-04-10 16:04:48 -0400 | [diff] [blame] | 5790 | trace_create_file("saved_cmdlines", 0444, d_tracer, |
| 5791 | NULL, &tracing_saved_cmdlines_fops); |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 5792 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5793 | #ifdef CONFIG_DYNAMIC_FTRACE |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 5794 | trace_create_file("dyn_ftrace_total_info", 0444, d_tracer, |
| 5795 | &ftrace_update_tot_cnt, &tracing_dyn_info_fops); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5796 | #endif |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 5797 | |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 5798 | create_trace_instances(d_tracer); |
| 5799 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5800 | create_trace_options_dir(&global_trace); |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 5801 | |
Frédéric Weisbecker | b5ad384 | 2008-09-23 11:34:32 +0100 | [diff] [blame] | 5802 | return 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5803 | } |
| 5804 | |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 5805 | static int trace_panic_handler(struct notifier_block *this, |
| 5806 | unsigned long event, void *unused) |
| 5807 | { |
Steven Rostedt | 944ac42 | 2008-10-23 19:26:08 -0400 | [diff] [blame] | 5808 | if (ftrace_dump_on_oops) |
Frederic Weisbecker | cecbca9 | 2010-04-18 19:08:41 +0200 | [diff] [blame] | 5809 | ftrace_dump(ftrace_dump_on_oops); |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 5810 | return NOTIFY_OK; |
| 5811 | } |
| 5812 | |
| 5813 | static struct notifier_block trace_panic_notifier = { |
| 5814 | .notifier_call = trace_panic_handler, |
| 5815 | .next = NULL, |
| 5816 | .priority = 150 /* priority: INT_MAX >= x >= 0 */ |
| 5817 | }; |
| 5818 | |
| 5819 | static int trace_die_handler(struct notifier_block *self, |
| 5820 | unsigned long val, |
| 5821 | void *data) |
| 5822 | { |
| 5823 | switch (val) { |
| 5824 | case DIE_OOPS: |
Steven Rostedt | 944ac42 | 2008-10-23 19:26:08 -0400 | [diff] [blame] | 5825 | if (ftrace_dump_on_oops) |
Frederic Weisbecker | cecbca9 | 2010-04-18 19:08:41 +0200 | [diff] [blame] | 5826 | ftrace_dump(ftrace_dump_on_oops); |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 5827 | break; |
| 5828 | default: |
| 5829 | break; |
| 5830 | } |
| 5831 | return NOTIFY_OK; |
| 5832 | } |
| 5833 | |
| 5834 | static struct notifier_block trace_die_notifier = { |
| 5835 | .notifier_call = trace_die_handler, |
| 5836 | .priority = 200 |
| 5837 | }; |
| 5838 | |
| 5839 | /* |
| 5840 | * printk is set to max of 1024, we really don't need it that big. |
| 5841 | * Nothing should be printing 1000 characters anyway. |
| 5842 | */ |
| 5843 | #define TRACE_MAX_PRINT 1000 |
| 5844 | |
| 5845 | /* |
| 5846 | * Define here KERN_TRACE so that we have one place to modify |
| 5847 | * it if we decide to change what log level the ftrace dump |
| 5848 | * should be at. |
| 5849 | */ |
Steven Rostedt | 428aee1 | 2009-01-14 12:24:42 -0500 | [diff] [blame] | 5850 | #define KERN_TRACE KERN_EMERG |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 5851 | |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 5852 | void |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 5853 | trace_printk_seq(struct trace_seq *s) |
| 5854 | { |
| 5855 | /* Probably should print a warning here. */ |
| 5856 | if (s->len >= 1000) |
| 5857 | s->len = 1000; |
| 5858 | |
| 5859 | /* should be zero ended, but we are paranoid. */ |
| 5860 | s->buffer[s->len] = 0; |
| 5861 | |
| 5862 | printk(KERN_TRACE "%s", s->buffer); |
| 5863 | |
Steven Rostedt | f952075 | 2009-03-02 14:04:40 -0500 | [diff] [blame] | 5864 | trace_seq_init(s); |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 5865 | } |
| 5866 | |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 5867 | void trace_init_global_iter(struct trace_iterator *iter) |
| 5868 | { |
| 5869 | iter->tr = &global_trace; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5870 | iter->trace = iter->tr->current_trace; |
Steven Rostedt | ae3b509 | 2013-01-23 15:22:59 -0500 | [diff] [blame] | 5871 | iter->cpu_file = RING_BUFFER_ALL_CPUS; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5872 | iter->trace_buffer = &global_trace.trace_buffer; |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 5873 | } |
| 5874 | |
Frederic Weisbecker | cecbca9 | 2010-04-18 19:08:41 +0200 | [diff] [blame] | 5875 | static void |
| 5876 | __ftrace_dump(bool disable_tracing, enum ftrace_dump_mode oops_dump_mode) |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 5877 | { |
Thomas Gleixner | 445c895 | 2009-12-02 19:49:50 +0100 | [diff] [blame] | 5878 | static arch_spinlock_t ftrace_dump_lock = |
Thomas Gleixner | edc35bd | 2009-12-03 12:38:57 +0100 | [diff] [blame] | 5879 | (arch_spinlock_t)__ARCH_SPIN_LOCK_UNLOCKED; |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 5880 | /* use static because iter can be a bit big for the stack */ |
| 5881 | static struct trace_iterator iter; |
Frederic Weisbecker | cf586b6 | 2009-03-22 05:04:35 +0100 | [diff] [blame] | 5882 | unsigned int old_userobj; |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 5883 | static int dump_ran; |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 5884 | unsigned long flags; |
| 5885 | int cnt = 0, cpu; |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 5886 | |
| 5887 | /* only one dump */ |
Steven Rostedt | cd891ae | 2009-04-28 11:39:34 -0400 | [diff] [blame] | 5888 | local_irq_save(flags); |
Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 5889 | arch_spin_lock(&ftrace_dump_lock); |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 5890 | if (dump_ran) |
| 5891 | goto out; |
| 5892 | |
| 5893 | dump_ran = 1; |
| 5894 | |
Steven Rostedt | 0ee6b6c | 2009-01-14 14:50:19 -0500 | [diff] [blame] | 5895 | tracing_off(); |
Frederic Weisbecker | cf586b6 | 2009-03-22 05:04:35 +0100 | [diff] [blame] | 5896 | |
Steven Rostedt | e0a413f | 2011-09-29 21:26:16 -0400 | [diff] [blame] | 5897 | /* Did function tracer already get disabled? */ |
| 5898 | if (ftrace_is_dead()) { |
| 5899 | printk("# WARNING: FUNCTION TRACING IS CORRUPTED\n"); |
| 5900 | printk("# MAY BE MISSING FUNCTION EVENTS\n"); |
| 5901 | } |
| 5902 | |
Frederic Weisbecker | cf586b6 | 2009-03-22 05:04:35 +0100 | [diff] [blame] | 5903 | if (disable_tracing) |
| 5904 | ftrace_kill(); |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 5905 | |
Jovi Zhang | 38dbe0b | 2013-01-25 18:03:07 +0800 | [diff] [blame] | 5906 | /* Simulate the iterator */ |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 5907 | trace_init_global_iter(&iter); |
| 5908 | |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 5909 | for_each_tracing_cpu(cpu) { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5910 | atomic_inc(&per_cpu_ptr(iter.tr->trace_buffer.data, cpu)->disabled); |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 5911 | } |
| 5912 | |
Frederic Weisbecker | cf586b6 | 2009-03-22 05:04:35 +0100 | [diff] [blame] | 5913 | old_userobj = trace_flags & TRACE_ITER_SYM_USEROBJ; |
| 5914 | |
Török Edwin | b54d3de | 2008-11-22 13:28:48 +0200 | [diff] [blame] | 5915 | /* don't look at user memory in panic mode */ |
| 5916 | trace_flags &= ~TRACE_ITER_SYM_USEROBJ; |
| 5917 | |
Frederic Weisbecker | cecbca9 | 2010-04-18 19:08:41 +0200 | [diff] [blame] | 5918 | switch (oops_dump_mode) { |
| 5919 | case DUMP_ALL: |
Steven Rostedt | ae3b509 | 2013-01-23 15:22:59 -0500 | [diff] [blame] | 5920 | iter.cpu_file = RING_BUFFER_ALL_CPUS; |
Frederic Weisbecker | cecbca9 | 2010-04-18 19:08:41 +0200 | [diff] [blame] | 5921 | break; |
| 5922 | case DUMP_ORIG: |
| 5923 | iter.cpu_file = raw_smp_processor_id(); |
| 5924 | break; |
| 5925 | case DUMP_NONE: |
| 5926 | goto out_enable; |
| 5927 | default: |
| 5928 | printk(KERN_TRACE "Bad dumping mode, switching to all CPUs dump\n"); |
Steven Rostedt | ae3b509 | 2013-01-23 15:22:59 -0500 | [diff] [blame] | 5929 | iter.cpu_file = RING_BUFFER_ALL_CPUS; |
Frederic Weisbecker | cecbca9 | 2010-04-18 19:08:41 +0200 | [diff] [blame] | 5930 | } |
| 5931 | |
| 5932 | printk(KERN_TRACE "Dumping ftrace buffer:\n"); |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 5933 | |
| 5934 | /* |
| 5935 | * We need to stop all tracing on all CPUS to read the |
| 5936 | * the next buffer. This is a bit expensive, but is |
| 5937 | * not done often. We fill all what we can read, |
| 5938 | * and then release the locks again. |
| 5939 | */ |
| 5940 | |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 5941 | while (!trace_empty(&iter)) { |
| 5942 | |
| 5943 | if (!cnt) |
| 5944 | printk(KERN_TRACE "---------------------------------\n"); |
| 5945 | |
| 5946 | cnt++; |
| 5947 | |
| 5948 | /* reset all but tr, trace, and overruns */ |
| 5949 | memset(&iter.seq, 0, |
| 5950 | sizeof(struct trace_iterator) - |
| 5951 | offsetof(struct trace_iterator, seq)); |
| 5952 | iter.iter_flags |= TRACE_FILE_LAT_FMT; |
| 5953 | iter.pos = -1; |
| 5954 | |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 5955 | if (trace_find_next_entry_inc(&iter) != NULL) { |
Lai Jiangshan | 74e7ff8 | 2009-07-28 20:17:22 +0800 | [diff] [blame] | 5956 | int ret; |
| 5957 | |
| 5958 | ret = print_trace_line(&iter); |
| 5959 | if (ret != TRACE_TYPE_NO_CONSUME) |
| 5960 | trace_consume(&iter); |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 5961 | } |
Steven Rostedt | b892e5c | 2012-03-01 22:06:48 -0500 | [diff] [blame] | 5962 | touch_nmi_watchdog(); |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 5963 | |
| 5964 | trace_printk_seq(&iter.seq); |
| 5965 | } |
| 5966 | |
| 5967 | if (!cnt) |
| 5968 | printk(KERN_TRACE " (ftrace buffer empty)\n"); |
| 5969 | else |
| 5970 | printk(KERN_TRACE "---------------------------------\n"); |
| 5971 | |
Frederic Weisbecker | cecbca9 | 2010-04-18 19:08:41 +0200 | [diff] [blame] | 5972 | out_enable: |
Frederic Weisbecker | cf586b6 | 2009-03-22 05:04:35 +0100 | [diff] [blame] | 5973 | /* Re-enable tracing if requested */ |
| 5974 | if (!disable_tracing) { |
| 5975 | trace_flags |= old_userobj; |
| 5976 | |
| 5977 | for_each_tracing_cpu(cpu) { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5978 | atomic_dec(&per_cpu_ptr(iter.trace_buffer->data, cpu)->disabled); |
Frederic Weisbecker | cf586b6 | 2009-03-22 05:04:35 +0100 | [diff] [blame] | 5979 | } |
| 5980 | tracing_on(); |
| 5981 | } |
| 5982 | |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 5983 | out: |
Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 5984 | arch_spin_unlock(&ftrace_dump_lock); |
Steven Rostedt | cd891ae | 2009-04-28 11:39:34 -0400 | [diff] [blame] | 5985 | local_irq_restore(flags); |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 5986 | } |
| 5987 | |
Frederic Weisbecker | cf586b6 | 2009-03-22 05:04:35 +0100 | [diff] [blame] | 5988 | /* By default: disable tracing after the dump */ |
Frederic Weisbecker | cecbca9 | 2010-04-18 19:08:41 +0200 | [diff] [blame] | 5989 | void ftrace_dump(enum ftrace_dump_mode oops_dump_mode) |
Frederic Weisbecker | cf586b6 | 2009-03-22 05:04:35 +0100 | [diff] [blame] | 5990 | { |
Frederic Weisbecker | cecbca9 | 2010-04-18 19:08:41 +0200 | [diff] [blame] | 5991 | __ftrace_dump(true, oops_dump_mode); |
Frederic Weisbecker | cf586b6 | 2009-03-22 05:04:35 +0100 | [diff] [blame] | 5992 | } |
Paul E. McKenney | a8eecf2 | 2011-10-02 11:01:15 -0700 | [diff] [blame] | 5993 | EXPORT_SYMBOL_GPL(ftrace_dump); |
Frederic Weisbecker | cf586b6 | 2009-03-22 05:04:35 +0100 | [diff] [blame] | 5994 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5995 | __init static int tracer_alloc_buffers(void) |
| 5996 | { |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 5997 | int ring_buf_size; |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 5998 | int ret = -ENOMEM; |
| 5999 | |
David Sharp | 750912f | 2010-12-08 13:46:47 -0800 | [diff] [blame] | 6000 | |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 6001 | if (!alloc_cpumask_var(&tracing_buffer_mask, GFP_KERNEL)) |
| 6002 | goto out; |
| 6003 | |
| 6004 | if (!alloc_cpumask_var(&tracing_cpumask, GFP_KERNEL)) |
| 6005 | goto out_free_buffer_mask; |
| 6006 | |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 6007 | /* Only allocate trace_printk buffers if a trace_printk exists */ |
| 6008 | if (__stop___trace_bprintk_fmt != __start___trace_bprintk_fmt) |
Steven Rostedt | 8169883 | 2012-10-11 10:15:05 -0400 | [diff] [blame] | 6009 | /* Must be called before global_trace.buffer is allocated */ |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 6010 | trace_printk_init_buffers(); |
| 6011 | |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 6012 | /* To save memory, keep the ring buffer size to its minimum */ |
| 6013 | if (ring_buffer_expanded) |
| 6014 | ring_buf_size = trace_buf_size; |
| 6015 | else |
| 6016 | ring_buf_size = 1; |
| 6017 | |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 6018 | cpumask_copy(tracing_buffer_mask, cpu_possible_mask); |
| 6019 | cpumask_copy(tracing_cpumask, cpu_all_mask); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 6020 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6021 | raw_spin_lock_init(&global_trace.start_lock); |
| 6022 | |
Steven Rostedt | ab46428 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 6023 | /* TODO: make the number of buffers hot pluggable with CPUS */ |
Steven Rostedt (Red Hat) | 737223f | 2013-03-05 21:13:47 -0500 | [diff] [blame] | 6024 | if (allocate_trace_buffers(&global_trace, ring_buf_size) < 0) { |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 6025 | printk(KERN_ERR "tracer: failed to allocate ring buffer!\n"); |
| 6026 | WARN_ON(1); |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 6027 | goto out_free_cpumask; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 6028 | } |
Steven Rostedt | a7603ff | 2012-08-06 16:24:11 -0400 | [diff] [blame] | 6029 | |
Steven Rostedt | 499e547 | 2012-02-22 15:50:28 -0500 | [diff] [blame] | 6030 | if (global_trace.buffer_disabled) |
| 6031 | tracing_off(); |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 6032 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 6033 | trace_init_cmdlines(); |
| 6034 | |
Frédéric Weisbecker | 43a1538 | 2008-09-21 20:16:30 +0200 | [diff] [blame] | 6035 | register_tracer(&nop_trace); |
Steven Rostedt (Red Hat) | d840f71 | 2013-02-01 18:38:47 -0500 | [diff] [blame] | 6036 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6037 | global_trace.current_trace = &nop_trace; |
| 6038 | |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 6039 | /* All seems OK, enable tracing */ |
| 6040 | tracing_disabled = 0; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 6041 | |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 6042 | atomic_notifier_chain_register(&panic_notifier_list, |
| 6043 | &trace_panic_notifier); |
| 6044 | |
| 6045 | register_die_notifier(&trace_die_notifier); |
Frederic Weisbecker | 2fc1dfb | 2009-03-16 01:45:03 +0100 | [diff] [blame] | 6046 | |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 6047 | global_trace.flags = TRACE_ARRAY_FL_GLOBAL; |
| 6048 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6049 | /* Holder for file callbacks */ |
| 6050 | global_trace.trace_cpu.cpu = RING_BUFFER_ALL_CPUS; |
| 6051 | global_trace.trace_cpu.tr = &global_trace; |
| 6052 | |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 6053 | INIT_LIST_HEAD(&global_trace.systems); |
| 6054 | INIT_LIST_HEAD(&global_trace.events); |
| 6055 | list_add(&global_trace.list, &ftrace_trace_arrays); |
| 6056 | |
Steven Rostedt | 7bcfaf5 | 2012-11-01 22:56:07 -0400 | [diff] [blame] | 6057 | while (trace_boot_options) { |
| 6058 | char *option; |
| 6059 | |
| 6060 | option = strsep(&trace_boot_options, ","); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6061 | trace_set_options(&global_trace, option); |
Steven Rostedt | 7bcfaf5 | 2012-11-01 22:56:07 -0400 | [diff] [blame] | 6062 | } |
| 6063 | |
Frederic Weisbecker | 2fc1dfb | 2009-03-16 01:45:03 +0100 | [diff] [blame] | 6064 | return 0; |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 6065 | |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 6066 | out_free_cpumask: |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 6067 | free_percpu(global_trace.trace_buffer.data); |
| 6068 | #ifdef CONFIG_TRACER_MAX_TRACE |
| 6069 | free_percpu(global_trace.max_buffer.data); |
| 6070 | #endif |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 6071 | free_cpumask_var(tracing_cpumask); |
| 6072 | out_free_buffer_mask: |
| 6073 | free_cpumask_var(tracing_buffer_mask); |
| 6074 | out: |
| 6075 | return ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 6076 | } |
Steven Rostedt | b2821ae | 2009-02-02 21:38:32 -0500 | [diff] [blame] | 6077 | |
| 6078 | __init static int clear_boot_tracer(void) |
| 6079 | { |
| 6080 | /* |
| 6081 | * The default tracer at boot buffer is an init section. |
| 6082 | * This function is called in lateinit. If we did not |
| 6083 | * find the boot tracer, then clear it out, to prevent |
| 6084 | * later registration from accessing the buffer that is |
| 6085 | * about to be freed. |
| 6086 | */ |
| 6087 | if (!default_bootup_tracer) |
| 6088 | return 0; |
| 6089 | |
| 6090 | printk(KERN_INFO "ftrace bootup tracer '%s' not registered.\n", |
| 6091 | default_bootup_tracer); |
| 6092 | default_bootup_tracer = NULL; |
| 6093 | |
| 6094 | return 0; |
| 6095 | } |
| 6096 | |
Frédéric Weisbecker | b5ad384 | 2008-09-23 11:34:32 +0100 | [diff] [blame] | 6097 | early_initcall(tracer_alloc_buffers); |
| 6098 | fs_initcall(tracer_init_debugfs); |
Steven Rostedt | b2821ae | 2009-02-02 21:38:32 -0500 | [diff] [blame] | 6099 | late_initcall(clear_boot_tracer); |