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 (Red Hat) | 8434dc9 | 2015-01-20 12:13:40 -0500 | [diff] [blame] | 23 | #include <linux/tracefs.h> |
Steven Rostedt | 4c11d7a | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 24 | #include <linux/pagemap.h> |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 25 | #include <linux/hardirq.h> |
| 26 | #include <linux/linkage.h> |
| 27 | #include <linux/uaccess.h> |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 28 | #include <linux/kprobes.h> |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 29 | #include <linux/ftrace.h> |
| 30 | #include <linux/module.h> |
| 31 | #include <linux/percpu.h> |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 32 | #include <linux/splice.h> |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 33 | #include <linux/kdebug.h> |
Frederic Weisbecker | 5f0c6c0 | 2009-03-27 14:22:10 +0100 | [diff] [blame] | 34 | #include <linux/string.h> |
Steven Rostedt (Red Hat) | f76180b | 2015-01-20 15:48:46 -0500 | [diff] [blame] | 35 | #include <linux/mount.h> |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 36 | #include <linux/rwsem.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 37 | #include <linux/slab.h> |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 38 | #include <linux/ctype.h> |
| 39 | #include <linux/init.h> |
Soeren Sandmann Pedersen | 2a2cc8f | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 40 | #include <linux/poll.h> |
Steven Rostedt | b892e5c | 2012-03-01 22:06:48 -0500 | [diff] [blame] | 41 | #include <linux/nmi.h> |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 42 | #include <linux/fs.h> |
Clark Williams | 8bd75c7 | 2013-02-07 09:47:07 -0600 | [diff] [blame] | 43 | #include <linux/sched/rt.h> |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 44 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 45 | #include "trace.h" |
Steven Rostedt | f0868d1 | 2008-12-23 23:24:12 -0500 | [diff] [blame] | 46 | #include "trace_output.h" |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 47 | |
Frederic Weisbecker | 8e1b82e | 2008-12-06 03:41:33 +0100 | [diff] [blame] | 48 | /* |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 49 | * On boot up, the ring buffer is set to the minimum size, so that |
| 50 | * we do not waste memory on systems that are not using tracing. |
| 51 | */ |
Steven Rostedt (Red Hat) | 55034cd | 2013-03-07 22:48:09 -0500 | [diff] [blame] | 52 | bool ring_buffer_expanded; |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 53 | |
| 54 | /* |
Frederic Weisbecker | 8e1b82e | 2008-12-06 03:41:33 +0100 | [diff] [blame] | 55 | * We need to change this state when a selftest is running. |
Frederic Weisbecker | ff32504 | 2008-12-04 23:47:35 +0100 | [diff] [blame] | 56 | * A selftest will lurk into the ring-buffer to count the |
| 57 | * entries inserted during the selftest although some concurrent |
Ingo Molnar | 5e1607a | 2009-03-05 10:24:48 +0100 | [diff] [blame] | 58 | * insertions into the ring-buffer such as trace_printk could occurred |
Frederic Weisbecker | ff32504 | 2008-12-04 23:47:35 +0100 | [diff] [blame] | 59 | * at the same time, giving false positive or negative results. |
| 60 | */ |
Frederic Weisbecker | 8e1b82e | 2008-12-06 03:41:33 +0100 | [diff] [blame] | 61 | static bool __read_mostly tracing_selftest_running; |
Frederic Weisbecker | ff32504 | 2008-12-04 23:47:35 +0100 | [diff] [blame] | 62 | |
Steven Rostedt | b2821ae | 2009-02-02 21:38:32 -0500 | [diff] [blame] | 63 | /* |
| 64 | * If a tracer is running, we do not want to run SELFTEST. |
| 65 | */ |
Li Zefan | 020e5f8 | 2009-07-01 10:47:05 +0800 | [diff] [blame] | 66 | bool __read_mostly tracing_selftest_disabled; |
Steven Rostedt | b2821ae | 2009-02-02 21:38:32 -0500 | [diff] [blame] | 67 | |
Steven Rostedt (Red Hat) | 0daa2302 | 2014-12-12 22:27:10 -0500 | [diff] [blame] | 68 | /* Pipe tracepoints to printk */ |
| 69 | struct trace_iterator *tracepoint_print_iter; |
| 70 | int tracepoint_printk; |
| 71 | |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 72 | /* For tracers that don't implement custom flags */ |
| 73 | static struct tracer_opt dummy_tracer_opt[] = { |
| 74 | { } |
| 75 | }; |
| 76 | |
| 77 | static struct tracer_flags dummy_tracer_flags = { |
| 78 | .val = 0, |
| 79 | .opts = dummy_tracer_opt |
| 80 | }; |
| 81 | |
Steven Rostedt (Red Hat) | 8c1a49a | 2014-01-10 11:13:54 -0500 | [diff] [blame] | 82 | static int |
| 83 | dummy_set_flag(struct trace_array *tr, u32 old_flags, u32 bit, int set) |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 84 | { |
| 85 | return 0; |
| 86 | } |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 87 | |
| 88 | /* |
Steven Rostedt | 7ffbd48 | 2012-10-11 12:14:25 -0400 | [diff] [blame] | 89 | * To prevent the comm cache from being overwritten when no |
| 90 | * tracing is active, only save the comm when a trace event |
| 91 | * occurred. |
| 92 | */ |
| 93 | static DEFINE_PER_CPU(bool, trace_cmdline_save); |
| 94 | |
| 95 | /* |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 96 | * Kill all tracing for good (never come back). |
| 97 | * It is initialized to 1 but will turn to zero if the initialization |
| 98 | * of the tracer is successful. But that is the only place that sets |
| 99 | * this back to zero. |
| 100 | */ |
Hannes Eder | 4fd2735 | 2009-02-10 19:44:12 +0100 | [diff] [blame] | 101 | static int tracing_disabled = 1; |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 102 | |
Christoph Lameter | 9288f99 | 2009-10-07 19:17:45 -0400 | [diff] [blame] | 103 | DEFINE_PER_CPU(int, ftrace_cpu_disabled); |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 104 | |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 105 | cpumask_var_t __read_mostly tracing_buffer_mask; |
Steven Rostedt | ab46428 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 106 | |
Steven Rostedt | 944ac42 | 2008-10-23 19:26:08 -0400 | [diff] [blame] | 107 | /* |
| 108 | * ftrace_dump_on_oops - variable to dump ftrace buffer on oops |
| 109 | * |
| 110 | * If there is an oops (or kernel panic) and the ftrace_dump_on_oops |
| 111 | * is set, then ftrace_dump is called. This will output the contents |
| 112 | * of the ftrace buffers to the console. This is very useful for |
| 113 | * capturing traces that lead to crashes and outputing it to a |
| 114 | * serial console. |
| 115 | * |
| 116 | * It is default off, but you can enable it with either specifying |
| 117 | * "ftrace_dump_on_oops" in the kernel command line, or setting |
Frederic Weisbecker | cecbca9 | 2010-04-18 19:08:41 +0200 | [diff] [blame] | 118 | * /proc/sys/kernel/ftrace_dump_on_oops |
| 119 | * Set 1 if you want to dump buffers of all CPUs |
| 120 | * 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] | 121 | */ |
Frederic Weisbecker | cecbca9 | 2010-04-18 19:08:41 +0200 | [diff] [blame] | 122 | |
| 123 | enum ftrace_dump_mode ftrace_dump_on_oops; |
Steven Rostedt | 944ac42 | 2008-10-23 19:26:08 -0400 | [diff] [blame] | 124 | |
Steven Rostedt (Red Hat) | de7edd3 | 2013-06-14 16:21:43 -0400 | [diff] [blame] | 125 | /* When set, tracing will stop when a WARN*() is hit */ |
| 126 | int __disable_trace_on_warning; |
| 127 | |
Steven Rostedt (Red Hat) | 9828413 | 2015-03-31 17:23:45 -0400 | [diff] [blame] | 128 | #ifdef CONFIG_TRACE_ENUM_MAP_FILE |
| 129 | /* Map of enums to their values, for "enum_map" file */ |
| 130 | struct trace_enum_map_head { |
| 131 | struct module *mod; |
| 132 | unsigned long length; |
| 133 | }; |
| 134 | |
| 135 | union trace_enum_map_item; |
| 136 | |
| 137 | struct trace_enum_map_tail { |
| 138 | /* |
| 139 | * "end" is first and points to NULL as it must be different |
| 140 | * than "mod" or "enum_string" |
| 141 | */ |
| 142 | union trace_enum_map_item *next; |
| 143 | const char *end; /* points to NULL */ |
| 144 | }; |
| 145 | |
| 146 | static DEFINE_MUTEX(trace_enum_mutex); |
| 147 | |
| 148 | /* |
| 149 | * The trace_enum_maps are saved in an array with two extra elements, |
| 150 | * one at the beginning, and one at the end. The beginning item contains |
| 151 | * the count of the saved maps (head.length), and the module they |
| 152 | * belong to if not built in (head.mod). The ending item contains a |
| 153 | * pointer to the next array of saved enum_map items. |
| 154 | */ |
| 155 | union trace_enum_map_item { |
| 156 | struct trace_enum_map map; |
| 157 | struct trace_enum_map_head head; |
| 158 | struct trace_enum_map_tail tail; |
| 159 | }; |
| 160 | |
| 161 | static union trace_enum_map_item *trace_enum_maps; |
| 162 | #endif /* CONFIG_TRACE_ENUM_MAP_FILE */ |
| 163 | |
Steven Rostedt (Red Hat) | 607e2ea | 2013-11-06 22:42:48 -0500 | [diff] [blame] | 164 | static int tracing_set_tracer(struct trace_array *tr, const char *buf); |
Steven Rostedt | b2821ae | 2009-02-02 21:38:32 -0500 | [diff] [blame] | 165 | |
Li Zefan | ee6c2c1 | 2009-09-18 14:06:47 +0800 | [diff] [blame] | 166 | #define MAX_TRACER_SIZE 100 |
| 167 | static char bootup_tracer_buf[MAX_TRACER_SIZE] __initdata; |
Steven Rostedt | b2821ae | 2009-02-02 21:38:32 -0500 | [diff] [blame] | 168 | static char *default_bootup_tracer; |
Peter Zijlstra | d9e5407 | 2008-11-01 19:57:37 +0100 | [diff] [blame] | 169 | |
Steven Rostedt (Red Hat) | 55034cd | 2013-03-07 22:48:09 -0500 | [diff] [blame] | 170 | static bool allocate_snapshot; |
| 171 | |
Frederic Weisbecker | 1beee96 | 2009-10-14 20:50:32 +0200 | [diff] [blame] | 172 | static int __init set_cmdline_ftrace(char *str) |
Peter Zijlstra | d9e5407 | 2008-11-01 19:57:37 +0100 | [diff] [blame] | 173 | { |
Chen Gang | 67012ab | 2013-04-08 12:06:44 +0800 | [diff] [blame] | 174 | strlcpy(bootup_tracer_buf, str, MAX_TRACER_SIZE); |
Steven Rostedt | b2821ae | 2009-02-02 21:38:32 -0500 | [diff] [blame] | 175 | default_bootup_tracer = bootup_tracer_buf; |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 176 | /* We are using ftrace early, expand it */ |
Steven Rostedt (Red Hat) | 55034cd | 2013-03-07 22:48:09 -0500 | [diff] [blame] | 177 | ring_buffer_expanded = true; |
Peter Zijlstra | d9e5407 | 2008-11-01 19:57:37 +0100 | [diff] [blame] | 178 | return 1; |
| 179 | } |
Frederic Weisbecker | 1beee96 | 2009-10-14 20:50:32 +0200 | [diff] [blame] | 180 | __setup("ftrace=", set_cmdline_ftrace); |
Peter Zijlstra | d9e5407 | 2008-11-01 19:57:37 +0100 | [diff] [blame] | 181 | |
Steven Rostedt | 944ac42 | 2008-10-23 19:26:08 -0400 | [diff] [blame] | 182 | static int __init set_ftrace_dump_on_oops(char *str) |
| 183 | { |
Frederic Weisbecker | cecbca9 | 2010-04-18 19:08:41 +0200 | [diff] [blame] | 184 | if (*str++ != '=' || !*str) { |
| 185 | ftrace_dump_on_oops = DUMP_ALL; |
| 186 | return 1; |
| 187 | } |
| 188 | |
| 189 | if (!strcmp("orig_cpu", str)) { |
| 190 | ftrace_dump_on_oops = DUMP_ORIG; |
| 191 | return 1; |
| 192 | } |
| 193 | |
| 194 | return 0; |
Steven Rostedt | 944ac42 | 2008-10-23 19:26:08 -0400 | [diff] [blame] | 195 | } |
| 196 | __setup("ftrace_dump_on_oops", set_ftrace_dump_on_oops); |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 197 | |
Steven Rostedt (Red Hat) | de7edd3 | 2013-06-14 16:21:43 -0400 | [diff] [blame] | 198 | static int __init stop_trace_on_warning(char *str) |
| 199 | { |
Luis Claudio R. Goncalves | 933ff9f | 2014-11-12 21:14:00 -0200 | [diff] [blame] | 200 | if ((strcmp(str, "=0") != 0 && strcmp(str, "=off") != 0)) |
| 201 | __disable_trace_on_warning = 1; |
Steven Rostedt (Red Hat) | de7edd3 | 2013-06-14 16:21:43 -0400 | [diff] [blame] | 202 | return 1; |
| 203 | } |
Luis Claudio R. Goncalves | 933ff9f | 2014-11-12 21:14:00 -0200 | [diff] [blame] | 204 | __setup("traceoff_on_warning", stop_trace_on_warning); |
Steven Rostedt (Red Hat) | de7edd3 | 2013-06-14 16:21:43 -0400 | [diff] [blame] | 205 | |
Steven Rostedt (Red Hat) | 3209cff | 2013-03-12 11:17:54 -0400 | [diff] [blame] | 206 | static int __init boot_alloc_snapshot(char *str) |
Steven Rostedt (Red Hat) | 55034cd | 2013-03-07 22:48:09 -0500 | [diff] [blame] | 207 | { |
| 208 | allocate_snapshot = true; |
| 209 | /* We also need the main ring buffer expanded */ |
| 210 | ring_buffer_expanded = true; |
| 211 | return 1; |
| 212 | } |
Steven Rostedt (Red Hat) | 3209cff | 2013-03-12 11:17:54 -0400 | [diff] [blame] | 213 | __setup("alloc_snapshot", boot_alloc_snapshot); |
Steven Rostedt (Red Hat) | 55034cd | 2013-03-07 22:48:09 -0500 | [diff] [blame] | 214 | |
Steven Rostedt | 7bcfaf5 | 2012-11-01 22:56:07 -0400 | [diff] [blame] | 215 | |
| 216 | static char trace_boot_options_buf[MAX_TRACER_SIZE] __initdata; |
| 217 | static char *trace_boot_options __initdata; |
| 218 | |
| 219 | static int __init set_trace_boot_options(char *str) |
| 220 | { |
Chen Gang | 67012ab | 2013-04-08 12:06:44 +0800 | [diff] [blame] | 221 | strlcpy(trace_boot_options_buf, str, MAX_TRACER_SIZE); |
Steven Rostedt | 7bcfaf5 | 2012-11-01 22:56:07 -0400 | [diff] [blame] | 222 | trace_boot_options = trace_boot_options_buf; |
| 223 | return 0; |
| 224 | } |
| 225 | __setup("trace_options=", set_trace_boot_options); |
| 226 | |
Steven Rostedt | e1e232c | 2014-02-10 23:38:46 -0500 | [diff] [blame] | 227 | static char trace_boot_clock_buf[MAX_TRACER_SIZE] __initdata; |
| 228 | static char *trace_boot_clock __initdata; |
| 229 | |
| 230 | static int __init set_trace_boot_clock(char *str) |
| 231 | { |
| 232 | strlcpy(trace_boot_clock_buf, str, MAX_TRACER_SIZE); |
| 233 | trace_boot_clock = trace_boot_clock_buf; |
| 234 | return 0; |
| 235 | } |
| 236 | __setup("trace_clock=", set_trace_boot_clock); |
| 237 | |
Steven Rostedt (Red Hat) | 0daa2302 | 2014-12-12 22:27:10 -0500 | [diff] [blame] | 238 | static int __init set_tracepoint_printk(char *str) |
| 239 | { |
| 240 | if ((strcmp(str, "=0") != 0 && strcmp(str, "=off") != 0)) |
| 241 | tracepoint_printk = 1; |
| 242 | return 1; |
| 243 | } |
| 244 | __setup("tp_printk", set_tracepoint_printk); |
Steven Rostedt (Red Hat) | de7edd3 | 2013-06-14 16:21:43 -0400 | [diff] [blame] | 245 | |
Lai Jiangshan | cf8e347 | 2009-03-30 13:48:00 +0800 | [diff] [blame] | 246 | unsigned long long ns2usecs(cycle_t nsec) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 247 | { |
| 248 | nsec += 500; |
| 249 | do_div(nsec, 1000); |
| 250 | return nsec; |
| 251 | } |
| 252 | |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 253 | /* |
| 254 | * The global_trace is the descriptor that holds the tracing |
| 255 | * buffers for the live tracing. For each CPU, it contains |
| 256 | * a link list of pages that will store trace entries. The |
| 257 | * page descriptor of the pages in the memory is used to hold |
| 258 | * the link list by linking the lru item in the page descriptor |
| 259 | * to each of the pages in the buffer per CPU. |
| 260 | * |
| 261 | * For each active CPU there is a data field that holds the |
| 262 | * pages for the buffer for that CPU. Each CPU has the same number |
| 263 | * of pages allocated for its buffer. |
| 264 | */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 265 | static struct trace_array global_trace; |
| 266 | |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 267 | LIST_HEAD(ftrace_trace_arrays); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 268 | |
Steven Rostedt (Red Hat) | ff45196 | 2013-07-01 22:50:29 -0400 | [diff] [blame] | 269 | int trace_array_get(struct trace_array *this_tr) |
| 270 | { |
| 271 | struct trace_array *tr; |
| 272 | int ret = -ENODEV; |
| 273 | |
| 274 | mutex_lock(&trace_types_lock); |
| 275 | list_for_each_entry(tr, &ftrace_trace_arrays, list) { |
| 276 | if (tr == this_tr) { |
| 277 | tr->ref++; |
| 278 | ret = 0; |
| 279 | break; |
| 280 | } |
| 281 | } |
| 282 | mutex_unlock(&trace_types_lock); |
| 283 | |
| 284 | return ret; |
| 285 | } |
| 286 | |
| 287 | static void __trace_array_put(struct trace_array *this_tr) |
| 288 | { |
| 289 | WARN_ON(!this_tr->ref); |
| 290 | this_tr->ref--; |
| 291 | } |
| 292 | |
| 293 | void trace_array_put(struct trace_array *this_tr) |
| 294 | { |
| 295 | mutex_lock(&trace_types_lock); |
| 296 | __trace_array_put(this_tr); |
| 297 | mutex_unlock(&trace_types_lock); |
| 298 | } |
| 299 | |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 300 | int filter_check_discard(struct trace_event_file *file, void *rec, |
Tom Zanussi | f306cc8 | 2013-10-24 08:34:17 -0500 | [diff] [blame] | 301 | struct ring_buffer *buffer, |
| 302 | struct ring_buffer_event *event) |
Tom Zanussi | eb02ce0 | 2009-04-08 03:15:54 -0500 | [diff] [blame] | 303 | { |
Steven Rostedt (Red Hat) | 5d6ad96 | 2015-05-13 15:12:33 -0400 | [diff] [blame] | 304 | if (unlikely(file->flags & EVENT_FILE_FL_FILTERED) && |
Tom Zanussi | f306cc8 | 2013-10-24 08:34:17 -0500 | [diff] [blame] | 305 | !filter_match_preds(file->filter, rec)) { |
| 306 | ring_buffer_discard_commit(buffer, event); |
| 307 | return 1; |
| 308 | } |
| 309 | |
| 310 | return 0; |
Tom Zanussi | eb02ce0 | 2009-04-08 03:15:54 -0500 | [diff] [blame] | 311 | } |
Tom Zanussi | f306cc8 | 2013-10-24 08:34:17 -0500 | [diff] [blame] | 312 | EXPORT_SYMBOL_GPL(filter_check_discard); |
| 313 | |
Steven Rostedt (Red Hat) | 2425bcb | 2015-05-05 11:45:27 -0400 | [diff] [blame] | 314 | int call_filter_check_discard(struct trace_event_call *call, void *rec, |
Tom Zanussi | f306cc8 | 2013-10-24 08:34:17 -0500 | [diff] [blame] | 315 | struct ring_buffer *buffer, |
| 316 | struct ring_buffer_event *event) |
| 317 | { |
| 318 | if (unlikely(call->flags & TRACE_EVENT_FL_FILTERED) && |
| 319 | !filter_match_preds(call->filter, rec)) { |
| 320 | ring_buffer_discard_commit(buffer, event); |
| 321 | return 1; |
| 322 | } |
| 323 | |
| 324 | return 0; |
| 325 | } |
| 326 | EXPORT_SYMBOL_GPL(call_filter_check_discard); |
Tom Zanussi | eb02ce0 | 2009-04-08 03:15:54 -0500 | [diff] [blame] | 327 | |
Fabian Frederick | ad1438a | 2014-04-17 21:44:42 +0200 | [diff] [blame] | 328 | static cycle_t buffer_ftrace_now(struct trace_buffer *buf, int cpu) |
Steven Rostedt | 37886f6 | 2009-03-17 17:22:06 -0400 | [diff] [blame] | 329 | { |
| 330 | u64 ts; |
| 331 | |
| 332 | /* Early boot up does not have a buffer yet */ |
Alexander Z Lam | 9457158 | 2013-08-02 18:36:16 -0700 | [diff] [blame] | 333 | if (!buf->buffer) |
Steven Rostedt | 37886f6 | 2009-03-17 17:22:06 -0400 | [diff] [blame] | 334 | return trace_clock_local(); |
| 335 | |
Alexander Z Lam | 9457158 | 2013-08-02 18:36:16 -0700 | [diff] [blame] | 336 | ts = ring_buffer_time_stamp(buf->buffer, cpu); |
| 337 | ring_buffer_normalize_time_stamp(buf->buffer, cpu, &ts); |
Steven Rostedt | 37886f6 | 2009-03-17 17:22:06 -0400 | [diff] [blame] | 338 | |
| 339 | return ts; |
| 340 | } |
| 341 | |
Alexander Z Lam | 9457158 | 2013-08-02 18:36:16 -0700 | [diff] [blame] | 342 | cycle_t ftrace_now(int cpu) |
| 343 | { |
| 344 | return buffer_ftrace_now(&global_trace.trace_buffer, cpu); |
| 345 | } |
| 346 | |
Steven Rostedt (Red Hat) | 10246fa | 2013-07-01 15:58:24 -0400 | [diff] [blame] | 347 | /** |
| 348 | * tracing_is_enabled - Show if global_trace has been disabled |
| 349 | * |
| 350 | * Shows if the global trace has been enabled or not. It uses the |
| 351 | * mirror flag "buffer_disabled" to be used in fast paths such as for |
| 352 | * the irqsoff tracer. But it may be inaccurate due to races. If you |
| 353 | * need to know the accurate state, use tracing_is_on() which is a little |
| 354 | * slower, but accurate. |
| 355 | */ |
Steven Rostedt | 9036990 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 356 | int tracing_is_enabled(void) |
| 357 | { |
Steven Rostedt (Red Hat) | 10246fa | 2013-07-01 15:58:24 -0400 | [diff] [blame] | 358 | /* |
| 359 | * For quick access (irqsoff uses this in fast path), just |
| 360 | * return the mirror variable of the state of the ring buffer. |
| 361 | * It's a little racy, but we don't really care. |
| 362 | */ |
| 363 | smp_rmb(); |
| 364 | return !global_trace.buffer_disabled; |
Steven Rostedt | 9036990 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 365 | } |
| 366 | |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 367 | /* |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 368 | * trace_buf_size is the size in bytes that is allocated |
| 369 | * for a buffer. Note, the number of bytes is always rounded |
| 370 | * to page size. |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 371 | * |
| 372 | * This number is purposely set to a low number of 16384. |
| 373 | * If the dump on oops happens, it will be much appreciated |
| 374 | * to not have to wait for all that output. Anyway this can be |
| 375 | * boot time and run time configurable. |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 376 | */ |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 377 | #define TRACE_BUF_SIZE_DEFAULT 1441792UL /* 16384 * 88 (sizeof(entry)) */ |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 378 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 379 | static unsigned long trace_buf_size = TRACE_BUF_SIZE_DEFAULT; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 380 | |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 381 | /* trace_types holds a link list of available tracers. */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 382 | static struct tracer *trace_types __read_mostly; |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 383 | |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 384 | /* |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 385 | * trace_types_lock is used to protect the trace_types list. |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 386 | */ |
Alexander Z Lam | a822741 | 2013-07-01 19:37:54 -0700 | [diff] [blame] | 387 | DEFINE_MUTEX(trace_types_lock); |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 388 | |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 389 | /* |
| 390 | * serialize the access of the ring buffer |
| 391 | * |
| 392 | * ring buffer serializes readers, but it is low level protection. |
| 393 | * The validity of the events (which returns by ring_buffer_peek() ..etc) |
| 394 | * are not protected by ring buffer. |
| 395 | * |
| 396 | * The content of events may become garbage if we allow other process consumes |
| 397 | * these events concurrently: |
| 398 | * A) the page of the consumed events may become a normal page |
| 399 | * (not reader page) in ring buffer, and this page will be rewrited |
| 400 | * by events producer. |
| 401 | * B) The page of the consumed events may become a page for splice_read, |
| 402 | * and this page will be returned to system. |
| 403 | * |
| 404 | * These primitives allow multi process access to different cpu ring buffer |
| 405 | * concurrently. |
| 406 | * |
| 407 | * These primitives don't distinguish read-only and read-consume access. |
| 408 | * Multi read-only access are also serialized. |
| 409 | */ |
| 410 | |
| 411 | #ifdef CONFIG_SMP |
| 412 | static DECLARE_RWSEM(all_cpu_access_lock); |
| 413 | static DEFINE_PER_CPU(struct mutex, cpu_access_lock); |
| 414 | |
| 415 | static inline void trace_access_lock(int cpu) |
| 416 | { |
Steven Rostedt | ae3b509 | 2013-01-23 15:22:59 -0500 | [diff] [blame] | 417 | if (cpu == RING_BUFFER_ALL_CPUS) { |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 418 | /* gain it for accessing the whole ring buffer. */ |
| 419 | down_write(&all_cpu_access_lock); |
| 420 | } else { |
| 421 | /* gain it for accessing a cpu ring buffer. */ |
| 422 | |
Steven Rostedt | ae3b509 | 2013-01-23 15:22:59 -0500 | [diff] [blame] | 423 | /* Firstly block other trace_access_lock(RING_BUFFER_ALL_CPUS). */ |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 424 | down_read(&all_cpu_access_lock); |
| 425 | |
| 426 | /* Secondly block other access to this @cpu ring buffer. */ |
| 427 | mutex_lock(&per_cpu(cpu_access_lock, cpu)); |
| 428 | } |
| 429 | } |
| 430 | |
| 431 | static inline void trace_access_unlock(int cpu) |
| 432 | { |
Steven Rostedt | ae3b509 | 2013-01-23 15:22:59 -0500 | [diff] [blame] | 433 | if (cpu == RING_BUFFER_ALL_CPUS) { |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 434 | up_write(&all_cpu_access_lock); |
| 435 | } else { |
| 436 | mutex_unlock(&per_cpu(cpu_access_lock, cpu)); |
| 437 | up_read(&all_cpu_access_lock); |
| 438 | } |
| 439 | } |
| 440 | |
| 441 | static inline void trace_access_lock_init(void) |
| 442 | { |
| 443 | int cpu; |
| 444 | |
| 445 | for_each_possible_cpu(cpu) |
| 446 | mutex_init(&per_cpu(cpu_access_lock, cpu)); |
| 447 | } |
| 448 | |
| 449 | #else |
| 450 | |
| 451 | static DEFINE_MUTEX(access_lock); |
| 452 | |
| 453 | static inline void trace_access_lock(int cpu) |
| 454 | { |
| 455 | (void)cpu; |
| 456 | mutex_lock(&access_lock); |
| 457 | } |
| 458 | |
| 459 | static inline void trace_access_unlock(int cpu) |
| 460 | { |
| 461 | (void)cpu; |
| 462 | mutex_unlock(&access_lock); |
| 463 | } |
| 464 | |
| 465 | static inline void trace_access_lock_init(void) |
| 466 | { |
| 467 | } |
| 468 | |
| 469 | #endif |
| 470 | |
Steven Rostedt (Red Hat) | d78a461 | 2015-09-25 13:30:47 -0400 | [diff] [blame^] | 471 | #ifdef CONFIG_STACKTRACE |
| 472 | static void __ftrace_trace_stack(struct ring_buffer *buffer, |
| 473 | unsigned long flags, |
| 474 | int skip, int pc, struct pt_regs *regs); |
| 475 | #else |
| 476 | static inline void __ftrace_trace_stack(struct ring_buffer *buffer, |
| 477 | unsigned long flags, |
| 478 | int skip, int pc, struct pt_regs *regs) |
| 479 | { |
| 480 | } |
| 481 | #endif |
| 482 | |
Steven Rostedt | ee6bce5 | 2008-11-12 17:52:37 -0500 | [diff] [blame] | 483 | /* trace_flags holds trace_options default values */ |
Steven Rostedt | 12ef7d4 | 2008-11-12 17:52:38 -0500 | [diff] [blame] | 484 | unsigned long trace_flags = TRACE_ITER_PRINT_PARENT | TRACE_ITER_PRINTK | |
Steven Rostedt | a2a16d6 | 2009-03-24 23:17:58 -0400 | [diff] [blame] | 485 | TRACE_ITER_ANNOTATE | TRACE_ITER_CONTEXT_INFO | TRACE_ITER_SLEEP_TIME | |
Steven Rostedt | 77271ce | 2011-11-17 09:34:33 -0500 | [diff] [blame] | 486 | TRACE_ITER_GRAPH_TIME | TRACE_ITER_RECORD_CMD | TRACE_ITER_OVERWRITE | |
Steven Rostedt (Red Hat) | 328df47 | 2013-03-14 12:10:40 -0400 | [diff] [blame] | 487 | TRACE_ITER_IRQ_INFO | TRACE_ITER_MARKERS | TRACE_ITER_FUNCTION; |
Vaibhav Nagarnaik | e7e2ee8 | 2011-05-10 13:27:21 -0700 | [diff] [blame] | 488 | |
Steven Rostedt (Red Hat) | 5280bce | 2013-07-02 19:59:57 -0400 | [diff] [blame] | 489 | static void tracer_tracing_on(struct trace_array *tr) |
Steven Rostedt (Red Hat) | 10246fa | 2013-07-01 15:58:24 -0400 | [diff] [blame] | 490 | { |
| 491 | if (tr->trace_buffer.buffer) |
| 492 | ring_buffer_record_on(tr->trace_buffer.buffer); |
| 493 | /* |
| 494 | * This flag is looked at when buffers haven't been allocated |
| 495 | * yet, or by some tracers (like irqsoff), that just want to |
| 496 | * know if the ring buffer has been disabled, but it can handle |
| 497 | * races of where it gets disabled but we still do a record. |
| 498 | * As the check is in the fast path of the tracers, it is more |
| 499 | * important to be fast than accurate. |
| 500 | */ |
| 501 | tr->buffer_disabled = 0; |
| 502 | /* Make the flag seen by readers */ |
| 503 | smp_wmb(); |
| 504 | } |
| 505 | |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 506 | /** |
Steven Rostedt | 499e547 | 2012-02-22 15:50:28 -0500 | [diff] [blame] | 507 | * tracing_on - enable tracing buffers |
| 508 | * |
| 509 | * This function enables tracing buffers that may have been |
| 510 | * disabled with tracing_off. |
| 511 | */ |
| 512 | void tracing_on(void) |
| 513 | { |
Steven Rostedt (Red Hat) | 10246fa | 2013-07-01 15:58:24 -0400 | [diff] [blame] | 514 | tracer_tracing_on(&global_trace); |
Steven Rostedt | 499e547 | 2012-02-22 15:50:28 -0500 | [diff] [blame] | 515 | } |
| 516 | EXPORT_SYMBOL_GPL(tracing_on); |
| 517 | |
| 518 | /** |
Steven Rostedt (Red Hat) | 09ae723 | 2013-03-08 21:02:34 -0500 | [diff] [blame] | 519 | * __trace_puts - write a constant string into the trace buffer. |
| 520 | * @ip: The address of the caller |
| 521 | * @str: The constant string to write |
| 522 | * @size: The size of the string. |
| 523 | */ |
| 524 | int __trace_puts(unsigned long ip, const char *str, int size) |
| 525 | { |
| 526 | struct ring_buffer_event *event; |
| 527 | struct ring_buffer *buffer; |
| 528 | struct print_entry *entry; |
| 529 | unsigned long irq_flags; |
| 530 | int alloc; |
zhangwei(Jovi) | 8abfb87 | 2013-07-18 16:31:05 +0800 | [diff] [blame] | 531 | int pc; |
| 532 | |
zhangwei(Jovi) | f0160a5 | 2013-07-18 16:31:18 +0800 | [diff] [blame] | 533 | if (!(trace_flags & TRACE_ITER_PRINTK)) |
| 534 | return 0; |
| 535 | |
zhangwei(Jovi) | 8abfb87 | 2013-07-18 16:31:05 +0800 | [diff] [blame] | 536 | pc = preempt_count(); |
Steven Rostedt (Red Hat) | 09ae723 | 2013-03-08 21:02:34 -0500 | [diff] [blame] | 537 | |
Steven Rostedt (Red Hat) | 3132e10 | 2014-01-23 12:27:59 -0500 | [diff] [blame] | 538 | if (unlikely(tracing_selftest_running || tracing_disabled)) |
| 539 | return 0; |
| 540 | |
Steven Rostedt (Red Hat) | 09ae723 | 2013-03-08 21:02:34 -0500 | [diff] [blame] | 541 | alloc = sizeof(*entry) + size + 2; /* possible \n added */ |
| 542 | |
| 543 | local_save_flags(irq_flags); |
| 544 | buffer = global_trace.trace_buffer.buffer; |
| 545 | event = trace_buffer_lock_reserve(buffer, TRACE_PRINT, alloc, |
zhangwei(Jovi) | 8abfb87 | 2013-07-18 16:31:05 +0800 | [diff] [blame] | 546 | irq_flags, pc); |
Steven Rostedt (Red Hat) | 09ae723 | 2013-03-08 21:02:34 -0500 | [diff] [blame] | 547 | if (!event) |
| 548 | return 0; |
| 549 | |
| 550 | entry = ring_buffer_event_data(event); |
| 551 | entry->ip = ip; |
| 552 | |
| 553 | memcpy(&entry->buf, str, size); |
| 554 | |
| 555 | /* Add a newline if necessary */ |
| 556 | if (entry->buf[size - 1] != '\n') { |
| 557 | entry->buf[size] = '\n'; |
| 558 | entry->buf[size + 1] = '\0'; |
| 559 | } else |
| 560 | entry->buf[size] = '\0'; |
| 561 | |
| 562 | __buffer_unlock_commit(buffer, event); |
zhangwei(Jovi) | 8abfb87 | 2013-07-18 16:31:05 +0800 | [diff] [blame] | 563 | ftrace_trace_stack(buffer, irq_flags, 4, pc); |
Steven Rostedt (Red Hat) | 09ae723 | 2013-03-08 21:02:34 -0500 | [diff] [blame] | 564 | |
| 565 | return size; |
| 566 | } |
| 567 | EXPORT_SYMBOL_GPL(__trace_puts); |
| 568 | |
| 569 | /** |
| 570 | * __trace_bputs - write the pointer to a constant string into trace buffer |
| 571 | * @ip: The address of the caller |
| 572 | * @str: The constant string to write to the buffer to |
| 573 | */ |
| 574 | int __trace_bputs(unsigned long ip, const char *str) |
| 575 | { |
| 576 | struct ring_buffer_event *event; |
| 577 | struct ring_buffer *buffer; |
| 578 | struct bputs_entry *entry; |
| 579 | unsigned long irq_flags; |
| 580 | int size = sizeof(struct bputs_entry); |
zhangwei(Jovi) | 8abfb87 | 2013-07-18 16:31:05 +0800 | [diff] [blame] | 581 | int pc; |
| 582 | |
zhangwei(Jovi) | f0160a5 | 2013-07-18 16:31:18 +0800 | [diff] [blame] | 583 | if (!(trace_flags & TRACE_ITER_PRINTK)) |
| 584 | return 0; |
| 585 | |
zhangwei(Jovi) | 8abfb87 | 2013-07-18 16:31:05 +0800 | [diff] [blame] | 586 | pc = preempt_count(); |
Steven Rostedt (Red Hat) | 09ae723 | 2013-03-08 21:02:34 -0500 | [diff] [blame] | 587 | |
Steven Rostedt (Red Hat) | 3132e10 | 2014-01-23 12:27:59 -0500 | [diff] [blame] | 588 | if (unlikely(tracing_selftest_running || tracing_disabled)) |
| 589 | return 0; |
| 590 | |
Steven Rostedt (Red Hat) | 09ae723 | 2013-03-08 21:02:34 -0500 | [diff] [blame] | 591 | local_save_flags(irq_flags); |
| 592 | buffer = global_trace.trace_buffer.buffer; |
| 593 | event = trace_buffer_lock_reserve(buffer, TRACE_BPUTS, size, |
zhangwei(Jovi) | 8abfb87 | 2013-07-18 16:31:05 +0800 | [diff] [blame] | 594 | irq_flags, pc); |
Steven Rostedt (Red Hat) | 09ae723 | 2013-03-08 21:02:34 -0500 | [diff] [blame] | 595 | if (!event) |
| 596 | return 0; |
| 597 | |
| 598 | entry = ring_buffer_event_data(event); |
| 599 | entry->ip = ip; |
| 600 | entry->str = str; |
| 601 | |
| 602 | __buffer_unlock_commit(buffer, event); |
zhangwei(Jovi) | 8abfb87 | 2013-07-18 16:31:05 +0800 | [diff] [blame] | 603 | ftrace_trace_stack(buffer, irq_flags, 4, pc); |
Steven Rostedt (Red Hat) | 09ae723 | 2013-03-08 21:02:34 -0500 | [diff] [blame] | 604 | |
| 605 | return 1; |
| 606 | } |
| 607 | EXPORT_SYMBOL_GPL(__trace_bputs); |
| 608 | |
Steven Rostedt (Red Hat) | ad909e2 | 2013-03-06 21:45:37 -0500 | [diff] [blame] | 609 | #ifdef CONFIG_TRACER_SNAPSHOT |
| 610 | /** |
| 611 | * trace_snapshot - take a snapshot of the current buffer. |
| 612 | * |
| 613 | * This causes a swap between the snapshot buffer and the current live |
| 614 | * tracing buffer. You can use this to take snapshots of the live |
| 615 | * trace when some condition is triggered, but continue to trace. |
| 616 | * |
| 617 | * Note, make sure to allocate the snapshot with either |
| 618 | * a tracing_snapshot_alloc(), or by doing it manually |
| 619 | * with: echo 1 > /sys/kernel/debug/tracing/snapshot |
| 620 | * |
| 621 | * If the snapshot buffer is not allocated, it will stop tracing. |
| 622 | * Basically making a permanent snapshot. |
| 623 | */ |
| 624 | void tracing_snapshot(void) |
| 625 | { |
| 626 | struct trace_array *tr = &global_trace; |
| 627 | struct tracer *tracer = tr->current_trace; |
| 628 | unsigned long flags; |
| 629 | |
Steven Rostedt (Red Hat) | 1b22e38 | 2013-03-09 00:56:08 -0500 | [diff] [blame] | 630 | if (in_nmi()) { |
| 631 | internal_trace_puts("*** SNAPSHOT CALLED FROM NMI CONTEXT ***\n"); |
| 632 | internal_trace_puts("*** snapshot is being ignored ***\n"); |
| 633 | return; |
| 634 | } |
| 635 | |
Steven Rostedt (Red Hat) | ad909e2 | 2013-03-06 21:45:37 -0500 | [diff] [blame] | 636 | if (!tr->allocated_snapshot) { |
Steven Rostedt (Red Hat) | ca268da | 2013-03-09 00:40:58 -0500 | [diff] [blame] | 637 | internal_trace_puts("*** SNAPSHOT NOT ALLOCATED ***\n"); |
| 638 | internal_trace_puts("*** stopping trace here! ***\n"); |
Steven Rostedt (Red Hat) | ad909e2 | 2013-03-06 21:45:37 -0500 | [diff] [blame] | 639 | tracing_off(); |
| 640 | return; |
| 641 | } |
| 642 | |
| 643 | /* Note, snapshot can not be used when the tracer uses it */ |
| 644 | if (tracer->use_max_tr) { |
Steven Rostedt (Red Hat) | ca268da | 2013-03-09 00:40:58 -0500 | [diff] [blame] | 645 | internal_trace_puts("*** LATENCY TRACER ACTIVE ***\n"); |
| 646 | internal_trace_puts("*** Can not use snapshot (sorry) ***\n"); |
Steven Rostedt (Red Hat) | ad909e2 | 2013-03-06 21:45:37 -0500 | [diff] [blame] | 647 | return; |
| 648 | } |
| 649 | |
| 650 | local_irq_save(flags); |
| 651 | update_max_tr(tr, current, smp_processor_id()); |
| 652 | local_irq_restore(flags); |
| 653 | } |
Steven Rostedt (Red Hat) | 1b22e38 | 2013-03-09 00:56:08 -0500 | [diff] [blame] | 654 | EXPORT_SYMBOL_GPL(tracing_snapshot); |
Steven Rostedt (Red Hat) | ad909e2 | 2013-03-06 21:45:37 -0500 | [diff] [blame] | 655 | |
| 656 | static int resize_buffer_duplicate_size(struct trace_buffer *trace_buf, |
| 657 | struct trace_buffer *size_buf, int cpu_id); |
Steven Rostedt (Red Hat) | 3209cff | 2013-03-12 11:17:54 -0400 | [diff] [blame] | 658 | static void set_buffer_entries(struct trace_buffer *buf, unsigned long val); |
| 659 | |
| 660 | static int alloc_snapshot(struct trace_array *tr) |
| 661 | { |
| 662 | int ret; |
| 663 | |
| 664 | if (!tr->allocated_snapshot) { |
| 665 | |
| 666 | /* allocate spare buffer */ |
| 667 | ret = resize_buffer_duplicate_size(&tr->max_buffer, |
| 668 | &tr->trace_buffer, RING_BUFFER_ALL_CPUS); |
| 669 | if (ret < 0) |
| 670 | return ret; |
| 671 | |
| 672 | tr->allocated_snapshot = true; |
| 673 | } |
| 674 | |
| 675 | return 0; |
| 676 | } |
| 677 | |
Fabian Frederick | ad1438a | 2014-04-17 21:44:42 +0200 | [diff] [blame] | 678 | static void free_snapshot(struct trace_array *tr) |
Steven Rostedt (Red Hat) | 3209cff | 2013-03-12 11:17:54 -0400 | [diff] [blame] | 679 | { |
| 680 | /* |
| 681 | * We don't free the ring buffer. instead, resize it because |
| 682 | * The max_tr ring buffer has some state (e.g. ring->clock) and |
| 683 | * we want preserve it. |
| 684 | */ |
| 685 | ring_buffer_resize(tr->max_buffer.buffer, 1, RING_BUFFER_ALL_CPUS); |
| 686 | set_buffer_entries(&tr->max_buffer, 1); |
| 687 | tracing_reset_online_cpus(&tr->max_buffer); |
| 688 | tr->allocated_snapshot = false; |
| 689 | } |
Steven Rostedt (Red Hat) | ad909e2 | 2013-03-06 21:45:37 -0500 | [diff] [blame] | 690 | |
| 691 | /** |
Tom Zanussi | 93e31ff | 2013-10-24 08:59:26 -0500 | [diff] [blame] | 692 | * tracing_alloc_snapshot - allocate snapshot buffer. |
| 693 | * |
| 694 | * This only allocates the snapshot buffer if it isn't already |
| 695 | * allocated - it doesn't also take a snapshot. |
| 696 | * |
| 697 | * This is meant to be used in cases where the snapshot buffer needs |
| 698 | * to be set up for events that can't sleep but need to be able to |
| 699 | * trigger a snapshot. |
| 700 | */ |
| 701 | int tracing_alloc_snapshot(void) |
| 702 | { |
| 703 | struct trace_array *tr = &global_trace; |
| 704 | int ret; |
| 705 | |
| 706 | ret = alloc_snapshot(tr); |
| 707 | WARN_ON(ret < 0); |
| 708 | |
| 709 | return ret; |
| 710 | } |
| 711 | EXPORT_SYMBOL_GPL(tracing_alloc_snapshot); |
| 712 | |
| 713 | /** |
Steven Rostedt (Red Hat) | ad909e2 | 2013-03-06 21:45:37 -0500 | [diff] [blame] | 714 | * trace_snapshot_alloc - allocate and take a snapshot of the current buffer. |
| 715 | * |
| 716 | * This is similar to trace_snapshot(), but it will allocate the |
| 717 | * snapshot buffer if it isn't already allocated. Use this only |
| 718 | * where it is safe to sleep, as the allocation may sleep. |
| 719 | * |
| 720 | * This causes a swap between the snapshot buffer and the current live |
| 721 | * tracing buffer. You can use this to take snapshots of the live |
| 722 | * trace when some condition is triggered, but continue to trace. |
| 723 | */ |
| 724 | void tracing_snapshot_alloc(void) |
| 725 | { |
Steven Rostedt (Red Hat) | ad909e2 | 2013-03-06 21:45:37 -0500 | [diff] [blame] | 726 | int ret; |
| 727 | |
Tom Zanussi | 93e31ff | 2013-10-24 08:59:26 -0500 | [diff] [blame] | 728 | ret = tracing_alloc_snapshot(); |
| 729 | if (ret < 0) |
Steven Rostedt (Red Hat) | 3209cff | 2013-03-12 11:17:54 -0400 | [diff] [blame] | 730 | return; |
Steven Rostedt (Red Hat) | ad909e2 | 2013-03-06 21:45:37 -0500 | [diff] [blame] | 731 | |
| 732 | tracing_snapshot(); |
| 733 | } |
Steven Rostedt (Red Hat) | 1b22e38 | 2013-03-09 00:56:08 -0500 | [diff] [blame] | 734 | EXPORT_SYMBOL_GPL(tracing_snapshot_alloc); |
Steven Rostedt (Red Hat) | ad909e2 | 2013-03-06 21:45:37 -0500 | [diff] [blame] | 735 | #else |
| 736 | void tracing_snapshot(void) |
| 737 | { |
| 738 | WARN_ONCE(1, "Snapshot feature not enabled, but internal snapshot used"); |
| 739 | } |
Steven Rostedt (Red Hat) | 1b22e38 | 2013-03-09 00:56:08 -0500 | [diff] [blame] | 740 | EXPORT_SYMBOL_GPL(tracing_snapshot); |
Tom Zanussi | 93e31ff | 2013-10-24 08:59:26 -0500 | [diff] [blame] | 741 | int tracing_alloc_snapshot(void) |
| 742 | { |
| 743 | WARN_ONCE(1, "Snapshot feature not enabled, but snapshot allocation used"); |
| 744 | return -ENODEV; |
| 745 | } |
| 746 | EXPORT_SYMBOL_GPL(tracing_alloc_snapshot); |
Steven Rostedt (Red Hat) | ad909e2 | 2013-03-06 21:45:37 -0500 | [diff] [blame] | 747 | void tracing_snapshot_alloc(void) |
| 748 | { |
| 749 | /* Give warning */ |
| 750 | tracing_snapshot(); |
| 751 | } |
Steven Rostedt (Red Hat) | 1b22e38 | 2013-03-09 00:56:08 -0500 | [diff] [blame] | 752 | EXPORT_SYMBOL_GPL(tracing_snapshot_alloc); |
Steven Rostedt (Red Hat) | ad909e2 | 2013-03-06 21:45:37 -0500 | [diff] [blame] | 753 | #endif /* CONFIG_TRACER_SNAPSHOT */ |
| 754 | |
Steven Rostedt (Red Hat) | 5280bce | 2013-07-02 19:59:57 -0400 | [diff] [blame] | 755 | static void tracer_tracing_off(struct trace_array *tr) |
Steven Rostedt (Red Hat) | 10246fa | 2013-07-01 15:58:24 -0400 | [diff] [blame] | 756 | { |
| 757 | if (tr->trace_buffer.buffer) |
| 758 | ring_buffer_record_off(tr->trace_buffer.buffer); |
| 759 | /* |
| 760 | * This flag is looked at when buffers haven't been allocated |
| 761 | * yet, or by some tracers (like irqsoff), that just want to |
| 762 | * know if the ring buffer has been disabled, but it can handle |
| 763 | * races of where it gets disabled but we still do a record. |
| 764 | * As the check is in the fast path of the tracers, it is more |
| 765 | * important to be fast than accurate. |
| 766 | */ |
| 767 | tr->buffer_disabled = 1; |
| 768 | /* Make the flag seen by readers */ |
| 769 | smp_wmb(); |
| 770 | } |
| 771 | |
Steven Rostedt | 499e547 | 2012-02-22 15:50:28 -0500 | [diff] [blame] | 772 | /** |
| 773 | * tracing_off - turn off tracing buffers |
| 774 | * |
| 775 | * This function stops the tracing buffers from recording data. |
| 776 | * It does not disable any overhead the tracers themselves may |
| 777 | * be causing. This function simply causes all recording to |
| 778 | * the ring buffers to fail. |
| 779 | */ |
| 780 | void tracing_off(void) |
| 781 | { |
Steven Rostedt (Red Hat) | 10246fa | 2013-07-01 15:58:24 -0400 | [diff] [blame] | 782 | tracer_tracing_off(&global_trace); |
Steven Rostedt | 499e547 | 2012-02-22 15:50:28 -0500 | [diff] [blame] | 783 | } |
| 784 | EXPORT_SYMBOL_GPL(tracing_off); |
| 785 | |
Steven Rostedt (Red Hat) | de7edd3 | 2013-06-14 16:21:43 -0400 | [diff] [blame] | 786 | void disable_trace_on_warning(void) |
| 787 | { |
| 788 | if (__disable_trace_on_warning) |
| 789 | tracing_off(); |
| 790 | } |
| 791 | |
Steven Rostedt | 499e547 | 2012-02-22 15:50:28 -0500 | [diff] [blame] | 792 | /** |
Steven Rostedt (Red Hat) | 10246fa | 2013-07-01 15:58:24 -0400 | [diff] [blame] | 793 | * tracer_tracing_is_on - show real state of ring buffer enabled |
| 794 | * @tr : the trace array to know if ring buffer is enabled |
| 795 | * |
| 796 | * Shows real state of the ring buffer if it is enabled or not. |
| 797 | */ |
Steven Rostedt (Red Hat) | 5280bce | 2013-07-02 19:59:57 -0400 | [diff] [blame] | 798 | static int tracer_tracing_is_on(struct trace_array *tr) |
Steven Rostedt (Red Hat) | 10246fa | 2013-07-01 15:58:24 -0400 | [diff] [blame] | 799 | { |
| 800 | if (tr->trace_buffer.buffer) |
| 801 | return ring_buffer_record_is_on(tr->trace_buffer.buffer); |
| 802 | return !tr->buffer_disabled; |
| 803 | } |
| 804 | |
Steven Rostedt | 499e547 | 2012-02-22 15:50:28 -0500 | [diff] [blame] | 805 | /** |
| 806 | * tracing_is_on - show state of ring buffers enabled |
| 807 | */ |
| 808 | int tracing_is_on(void) |
| 809 | { |
Steven Rostedt (Red Hat) | 10246fa | 2013-07-01 15:58:24 -0400 | [diff] [blame] | 810 | return tracer_tracing_is_on(&global_trace); |
Steven Rostedt | 499e547 | 2012-02-22 15:50:28 -0500 | [diff] [blame] | 811 | } |
| 812 | EXPORT_SYMBOL_GPL(tracing_is_on); |
| 813 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 814 | static int __init set_buf_size(char *str) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 815 | { |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 816 | unsigned long buf_size; |
Steven Rostedt | c6caeeb | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 817 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 818 | if (!str) |
| 819 | return 0; |
Li Zefan | 9d612be | 2009-06-24 17:33:15 +0800 | [diff] [blame] | 820 | buf_size = memparse(str, &str); |
Steven Rostedt | c6caeeb | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 821 | /* nr_entries can not be zero */ |
Li Zefan | 9d612be | 2009-06-24 17:33:15 +0800 | [diff] [blame] | 822 | if (buf_size == 0) |
Steven Rostedt | c6caeeb | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 823 | return 0; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 824 | trace_buf_size = buf_size; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 825 | return 1; |
| 826 | } |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 827 | __setup("trace_buf_size=", set_buf_size); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 828 | |
Tim Bird | 0e95017 | 2010-02-25 15:36:43 -0800 | [diff] [blame] | 829 | static int __init set_tracing_thresh(char *str) |
| 830 | { |
Wang Tianhong | 87abb3b | 2012-08-02 14:02:00 +0800 | [diff] [blame] | 831 | unsigned long threshold; |
Tim Bird | 0e95017 | 2010-02-25 15:36:43 -0800 | [diff] [blame] | 832 | int ret; |
| 833 | |
| 834 | if (!str) |
| 835 | return 0; |
Daniel Walter | bcd83ea | 2012-09-26 22:08:38 +0200 | [diff] [blame] | 836 | ret = kstrtoul(str, 0, &threshold); |
Tim Bird | 0e95017 | 2010-02-25 15:36:43 -0800 | [diff] [blame] | 837 | if (ret < 0) |
| 838 | return 0; |
Wang Tianhong | 87abb3b | 2012-08-02 14:02:00 +0800 | [diff] [blame] | 839 | tracing_thresh = threshold * 1000; |
Tim Bird | 0e95017 | 2010-02-25 15:36:43 -0800 | [diff] [blame] | 840 | return 1; |
| 841 | } |
| 842 | __setup("tracing_thresh=", set_tracing_thresh); |
| 843 | |
Steven Rostedt | 57f50be | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 844 | unsigned long nsecs_to_usecs(unsigned long nsecs) |
| 845 | { |
| 846 | return nsecs / 1000; |
| 847 | } |
| 848 | |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 849 | /* These must match the bit postions in trace_iterator_flags */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 850 | static const char *trace_options[] = { |
| 851 | "print-parent", |
| 852 | "sym-offset", |
| 853 | "sym-addr", |
| 854 | "verbose", |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 855 | "raw", |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 856 | "hex", |
Ingo Molnar | cb0f12a | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 857 | "bin", |
Soeren Sandmann Pedersen | 2a2cc8f | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 858 | "block", |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 859 | "stacktrace", |
Ingo Molnar | 5e1607a | 2009-03-05 10:24:48 +0100 | [diff] [blame] | 860 | "trace_printk", |
Steven Rostedt | b2a866f | 2008-11-03 23:15:57 -0500 | [diff] [blame] | 861 | "ftrace_preempt", |
Steven Rostedt | 9f029e8 | 2008-11-12 15:24:24 -0500 | [diff] [blame] | 862 | "branch", |
Steven Rostedt | 12ef7d4 | 2008-11-12 17:52:38 -0500 | [diff] [blame] | 863 | "annotate", |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 864 | "userstacktrace", |
Török Edwin | b54d3de | 2008-11-22 13:28:48 +0200 | [diff] [blame] | 865 | "sym-userobj", |
Frederic Weisbecker | 66896a8 | 2008-12-13 20:18:13 +0100 | [diff] [blame] | 866 | "printk-msg-only", |
Frederic Weisbecker | c4a8e8b | 2009-02-02 20:29:21 -0200 | [diff] [blame] | 867 | "context-info", |
Steven Rostedt | c032ef64 | 2009-03-04 20:34:24 -0500 | [diff] [blame] | 868 | "latency-format", |
Steven Rostedt | be6f164 | 2009-03-24 11:06:24 -0400 | [diff] [blame] | 869 | "sleep-time", |
Steven Rostedt | a2a16d6 | 2009-03-24 23:17:58 -0400 | [diff] [blame] | 870 | "graph-time", |
Li Zefan | e870e9a | 2010-07-02 11:07:32 +0800 | [diff] [blame] | 871 | "record-cmd", |
David Sharp | 750912f | 2010-12-08 13:46:47 -0800 | [diff] [blame] | 872 | "overwrite", |
Steven Rostedt | cf30cf6 | 2011-06-14 22:44:07 -0400 | [diff] [blame] | 873 | "disable_on_free", |
Steven Rostedt | 77271ce | 2011-11-17 09:34:33 -0500 | [diff] [blame] | 874 | "irq-info", |
Mandeep Singh Baines | 5224c3a | 2012-09-07 18:12:19 -0700 | [diff] [blame] | 875 | "markers", |
Steven Rostedt (Red Hat) | 328df47 | 2013-03-14 12:10:40 -0400 | [diff] [blame] | 876 | "function-trace", |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 877 | NULL |
| 878 | }; |
| 879 | |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 880 | static struct { |
| 881 | u64 (*func)(void); |
| 882 | const char *name; |
David Sharp | 8be0709 | 2012-11-13 12:18:22 -0800 | [diff] [blame] | 883 | int in_ns; /* is this clock in nanoseconds? */ |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 884 | } trace_clocks[] = { |
Thomas Gleixner | 1b3e5c0 | 2014-07-16 21:05:25 +0000 | [diff] [blame] | 885 | { trace_clock_local, "local", 1 }, |
| 886 | { trace_clock_global, "global", 1 }, |
| 887 | { trace_clock_counter, "counter", 0 }, |
Linus Torvalds | e7fda6c | 2014-08-05 17:46:42 -0700 | [diff] [blame] | 888 | { trace_clock_jiffies, "uptime", 0 }, |
Thomas Gleixner | 1b3e5c0 | 2014-07-16 21:05:25 +0000 | [diff] [blame] | 889 | { trace_clock, "perf", 1 }, |
| 890 | { ktime_get_mono_fast_ns, "mono", 1 }, |
Drew Richardson | aabfa5f | 2015-05-08 07:30:39 -0700 | [diff] [blame] | 891 | { ktime_get_raw_fast_ns, "mono_raw", 1 }, |
David Sharp | 8cbd9cc | 2012-11-13 12:18:21 -0800 | [diff] [blame] | 892 | ARCH_TRACE_CLOCKS |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 893 | }; |
| 894 | |
jolsa@redhat.com | b63f39e | 2009-09-11 17:29:27 +0200 | [diff] [blame] | 895 | /* |
| 896 | * trace_parser_get_init - gets the buffer for trace parser |
| 897 | */ |
| 898 | int trace_parser_get_init(struct trace_parser *parser, int size) |
| 899 | { |
| 900 | memset(parser, 0, sizeof(*parser)); |
| 901 | |
| 902 | parser->buffer = kmalloc(size, GFP_KERNEL); |
| 903 | if (!parser->buffer) |
| 904 | return 1; |
| 905 | |
| 906 | parser->size = size; |
| 907 | return 0; |
| 908 | } |
| 909 | |
| 910 | /* |
| 911 | * trace_parser_put - frees the buffer for trace parser |
| 912 | */ |
| 913 | void trace_parser_put(struct trace_parser *parser) |
| 914 | { |
| 915 | kfree(parser->buffer); |
| 916 | } |
| 917 | |
| 918 | /* |
| 919 | * trace_get_user - reads the user input string separated by space |
| 920 | * (matched by isspace(ch)) |
| 921 | * |
| 922 | * For each string found the 'struct trace_parser' is updated, |
| 923 | * and the function returns. |
| 924 | * |
| 925 | * Returns number of bytes read. |
| 926 | * |
| 927 | * See kernel/trace/trace.h for 'struct trace_parser' details. |
| 928 | */ |
| 929 | int trace_get_user(struct trace_parser *parser, const char __user *ubuf, |
| 930 | size_t cnt, loff_t *ppos) |
| 931 | { |
| 932 | char ch; |
| 933 | size_t read = 0; |
| 934 | ssize_t ret; |
| 935 | |
| 936 | if (!*ppos) |
| 937 | trace_parser_clear(parser); |
| 938 | |
| 939 | ret = get_user(ch, ubuf++); |
| 940 | if (ret) |
| 941 | goto out; |
| 942 | |
| 943 | read++; |
| 944 | cnt--; |
| 945 | |
| 946 | /* |
| 947 | * The parser is not finished with the last write, |
| 948 | * continue reading the user input without skipping spaces. |
| 949 | */ |
| 950 | if (!parser->cont) { |
| 951 | /* skip white space */ |
| 952 | while (cnt && isspace(ch)) { |
| 953 | ret = get_user(ch, ubuf++); |
| 954 | if (ret) |
| 955 | goto out; |
| 956 | read++; |
| 957 | cnt--; |
| 958 | } |
| 959 | |
| 960 | /* only spaces were written */ |
| 961 | if (isspace(ch)) { |
| 962 | *ppos += read; |
| 963 | ret = read; |
| 964 | goto out; |
| 965 | } |
| 966 | |
| 967 | parser->idx = 0; |
| 968 | } |
| 969 | |
| 970 | /* read the non-space input */ |
| 971 | while (cnt && !isspace(ch)) { |
Li Zefan | 3c235a3 | 2009-09-22 13:51:54 +0800 | [diff] [blame] | 972 | if (parser->idx < parser->size - 1) |
jolsa@redhat.com | b63f39e | 2009-09-11 17:29:27 +0200 | [diff] [blame] | 973 | parser->buffer[parser->idx++] = ch; |
| 974 | else { |
| 975 | ret = -EINVAL; |
| 976 | goto out; |
| 977 | } |
| 978 | ret = get_user(ch, ubuf++); |
| 979 | if (ret) |
| 980 | goto out; |
| 981 | read++; |
| 982 | cnt--; |
| 983 | } |
| 984 | |
| 985 | /* We either got finished input or we have to wait for another call. */ |
| 986 | if (isspace(ch)) { |
| 987 | parser->buffer[parser->idx] = 0; |
| 988 | parser->cont = false; |
Steven Rostedt | 057db84 | 2013-10-09 22:23:23 -0400 | [diff] [blame] | 989 | } else if (parser->idx < parser->size - 1) { |
jolsa@redhat.com | b63f39e | 2009-09-11 17:29:27 +0200 | [diff] [blame] | 990 | parser->cont = true; |
| 991 | parser->buffer[parser->idx++] = ch; |
Steven Rostedt | 057db84 | 2013-10-09 22:23:23 -0400 | [diff] [blame] | 992 | } else { |
| 993 | ret = -EINVAL; |
| 994 | goto out; |
jolsa@redhat.com | b63f39e | 2009-09-11 17:29:27 +0200 | [diff] [blame] | 995 | } |
| 996 | |
| 997 | *ppos += read; |
| 998 | ret = read; |
| 999 | |
| 1000 | out: |
| 1001 | return ret; |
| 1002 | } |
| 1003 | |
Steven Rostedt (Red Hat) | 3a161d9 | 2014-06-25 15:54:42 -0400 | [diff] [blame] | 1004 | /* TODO add a seq_buf_to_buffer() */ |
Dmitri Vorobiev | b8b9426 | 2009-03-22 19:11:11 +0200 | [diff] [blame] | 1005 | 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] | 1006 | { |
| 1007 | int len; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 1008 | |
Steven Rostedt (Red Hat) | 5ac48378 | 2014-11-14 15:49:41 -0500 | [diff] [blame] | 1009 | if (trace_seq_used(s) <= s->seq.readpos) |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 1010 | return -EBUSY; |
| 1011 | |
Steven Rostedt (Red Hat) | 5ac48378 | 2014-11-14 15:49:41 -0500 | [diff] [blame] | 1012 | len = trace_seq_used(s) - s->seq.readpos; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 1013 | if (cnt > len) |
| 1014 | cnt = len; |
Steven Rostedt (Red Hat) | 3a161d9 | 2014-06-25 15:54:42 -0400 | [diff] [blame] | 1015 | memcpy(buf, s->buffer + s->seq.readpos, cnt); |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 1016 | |
Steven Rostedt (Red Hat) | 3a161d9 | 2014-06-25 15:54:42 -0400 | [diff] [blame] | 1017 | s->seq.readpos += cnt; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 1018 | return cnt; |
| 1019 | } |
| 1020 | |
Tim Bird | 0e95017 | 2010-02-25 15:36:43 -0800 | [diff] [blame] | 1021 | unsigned long __read_mostly tracing_thresh; |
| 1022 | |
Steven Rostedt | 5d4a9db | 2009-08-27 16:52:21 -0400 | [diff] [blame] | 1023 | #ifdef CONFIG_TRACER_MAX_TRACE |
Steven Rostedt | 5d4a9db | 2009-08-27 16:52:21 -0400 | [diff] [blame] | 1024 | /* |
| 1025 | * Copy the new maximum trace into the separate maximum-trace |
| 1026 | * structure. (this way the maximum trace is permanently saved, |
| 1027 | * for later retrieval via /sys/kernel/debug/tracing/latency_trace) |
| 1028 | */ |
| 1029 | static void |
| 1030 | __update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu) |
| 1031 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1032 | struct trace_buffer *trace_buf = &tr->trace_buffer; |
| 1033 | struct trace_buffer *max_buf = &tr->max_buffer; |
| 1034 | struct trace_array_cpu *data = per_cpu_ptr(trace_buf->data, cpu); |
| 1035 | 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] | 1036 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1037 | max_buf->cpu = cpu; |
| 1038 | max_buf->time_start = data->preempt_timestamp; |
Steven Rostedt | 5d4a9db | 2009-08-27 16:52:21 -0400 | [diff] [blame] | 1039 | |
Steven Rostedt (Red Hat) | 6d9b3fa | 2014-01-14 11:28:38 -0500 | [diff] [blame] | 1040 | max_data->saved_latency = tr->max_latency; |
Steven Rostedt | 8248ac0 | 2009-09-02 12:27:41 -0400 | [diff] [blame] | 1041 | max_data->critical_start = data->critical_start; |
| 1042 | max_data->critical_end = data->critical_end; |
Steven Rostedt | 5d4a9db | 2009-08-27 16:52:21 -0400 | [diff] [blame] | 1043 | |
Arnaldo Carvalho de Melo | 1acaa1b | 2010-03-05 18:23:50 -0300 | [diff] [blame] | 1044 | memcpy(max_data->comm, tsk->comm, TASK_COMM_LEN); |
Steven Rostedt | 8248ac0 | 2009-09-02 12:27:41 -0400 | [diff] [blame] | 1045 | max_data->pid = tsk->pid; |
Steven Rostedt (Red Hat) | f17a519 | 2013-05-30 21:10:37 -0400 | [diff] [blame] | 1046 | /* |
| 1047 | * If tsk == current, then use current_uid(), as that does not use |
| 1048 | * RCU. The irq tracer can be called out of RCU scope. |
| 1049 | */ |
| 1050 | if (tsk == current) |
| 1051 | max_data->uid = current_uid(); |
| 1052 | else |
| 1053 | max_data->uid = task_uid(tsk); |
| 1054 | |
Steven Rostedt | 8248ac0 | 2009-09-02 12:27:41 -0400 | [diff] [blame] | 1055 | max_data->nice = tsk->static_prio - 20 - MAX_RT_PRIO; |
| 1056 | max_data->policy = tsk->policy; |
| 1057 | max_data->rt_priority = tsk->rt_priority; |
Steven Rostedt | 5d4a9db | 2009-08-27 16:52:21 -0400 | [diff] [blame] | 1058 | |
| 1059 | /* record this tasks comm */ |
| 1060 | tracing_record_cmdline(tsk); |
| 1061 | } |
| 1062 | |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 1063 | /** |
| 1064 | * update_max_tr - snapshot all trace buffers from global_trace to max_tr |
| 1065 | * @tr: tracer |
| 1066 | * @tsk: the task with the latency |
| 1067 | * @cpu: The cpu that initiated the trace. |
| 1068 | * |
| 1069 | * Flip the buffers between the @tr and the max_tr and record information |
| 1070 | * about which task was the cause of this latency. |
| 1071 | */ |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1072 | void |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1073 | update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu) |
| 1074 | { |
Steven Rostedt (Red Hat) | 2721e72 | 2013-03-12 11:32:32 -0400 | [diff] [blame] | 1075 | struct ring_buffer *buf; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1076 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 1077 | if (tr->stop_count) |
Steven Rostedt | b8de7bd1 | 2009-08-31 22:32:27 -0400 | [diff] [blame] | 1078 | return; |
| 1079 | |
Steven Rostedt | 4c11d7a | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1080 | WARN_ON_ONCE(!irqs_disabled()); |
Steven Rostedt | 34600f0 | 2013-01-22 13:35:11 -0500 | [diff] [blame] | 1081 | |
Steven Rostedt (Red Hat) | 45ad21c | 2013-03-05 18:25:02 -0500 | [diff] [blame] | 1082 | if (!tr->allocated_snapshot) { |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 1083 | /* Only the nop tracer should hit this when disabling */ |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 1084 | WARN_ON_ONCE(tr->current_trace != &nop_trace); |
KOSAKI Motohiro | ef710e1 | 2010-07-01 14:34:35 +0900 | [diff] [blame] | 1085 | return; |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 1086 | } |
Steven Rostedt | 34600f0 | 2013-01-22 13:35:11 -0500 | [diff] [blame] | 1087 | |
Steven Rostedt (Red Hat) | 0b9b12c | 2014-01-14 10:04:59 -0500 | [diff] [blame] | 1088 | arch_spin_lock(&tr->max_lock); |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1089 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1090 | buf = tr->trace_buffer.buffer; |
| 1091 | tr->trace_buffer.buffer = tr->max_buffer.buffer; |
| 1092 | tr->max_buffer.buffer = buf; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1093 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1094 | __update_max_tr(tr, tsk, cpu); |
Steven Rostedt (Red Hat) | 0b9b12c | 2014-01-14 10:04:59 -0500 | [diff] [blame] | 1095 | arch_spin_unlock(&tr->max_lock); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1096 | } |
| 1097 | |
| 1098 | /** |
| 1099 | * update_max_tr_single - only copy one trace over, and reset the rest |
| 1100 | * @tr - tracer |
| 1101 | * @tsk - task with the latency |
| 1102 | * @cpu - the cpu of the buffer to copy. |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 1103 | * |
| 1104 | * 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] | 1105 | */ |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1106 | void |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1107 | update_max_tr_single(struct trace_array *tr, struct task_struct *tsk, int cpu) |
| 1108 | { |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1109 | int ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1110 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 1111 | if (tr->stop_count) |
Steven Rostedt | b8de7bd1 | 2009-08-31 22:32:27 -0400 | [diff] [blame] | 1112 | return; |
| 1113 | |
Steven Rostedt | 4c11d7a | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1114 | WARN_ON_ONCE(!irqs_disabled()); |
Steven Rostedt | 6c24499 | 2013-04-29 20:08:14 -0400 | [diff] [blame] | 1115 | if (!tr->allocated_snapshot) { |
Steven Rostedt (Red Hat) | 2930e04 | 2013-03-26 17:33:00 -0400 | [diff] [blame] | 1116 | /* Only the nop tracer should hit this when disabling */ |
Linus Torvalds | 9e8529a | 2013-04-29 13:55:38 -0700 | [diff] [blame] | 1117 | WARN_ON_ONCE(tr->current_trace != &nop_trace); |
KOSAKI Motohiro | ef710e1 | 2010-07-01 14:34:35 +0900 | [diff] [blame] | 1118 | return; |
Steven Rostedt (Red Hat) | 2930e04 | 2013-03-26 17:33:00 -0400 | [diff] [blame] | 1119 | } |
KOSAKI Motohiro | ef710e1 | 2010-07-01 14:34:35 +0900 | [diff] [blame] | 1120 | |
Steven Rostedt (Red Hat) | 0b9b12c | 2014-01-14 10:04:59 -0500 | [diff] [blame] | 1121 | arch_spin_lock(&tr->max_lock); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1122 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1123 | 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] | 1124 | |
Steven Rostedt | e8165dbb | 2009-09-03 19:13:05 -0400 | [diff] [blame] | 1125 | if (ret == -EBUSY) { |
| 1126 | /* |
| 1127 | * We failed to swap the buffer due to a commit taking |
| 1128 | * place on this CPU. We fail to record, but we reset |
| 1129 | * the max trace buffer (no one writes directly to it) |
| 1130 | * and flag that it failed. |
| 1131 | */ |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1132 | trace_array_printk_buf(tr->max_buffer.buffer, _THIS_IP_, |
Steven Rostedt | e8165dbb | 2009-09-03 19:13:05 -0400 | [diff] [blame] | 1133 | "Failed to swap buffers due to commit in progress\n"); |
| 1134 | } |
| 1135 | |
Steven Rostedt | e8165dbb | 2009-09-03 19:13:05 -0400 | [diff] [blame] | 1136 | WARN_ON_ONCE(ret && ret != -EAGAIN && ret != -EBUSY); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1137 | |
| 1138 | __update_max_tr(tr, tsk, cpu); |
Steven Rostedt (Red Hat) | 0b9b12c | 2014-01-14 10:04:59 -0500 | [diff] [blame] | 1139 | arch_spin_unlock(&tr->max_lock); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1140 | } |
Steven Rostedt | 5d4a9db | 2009-08-27 16:52:21 -0400 | [diff] [blame] | 1141 | #endif /* CONFIG_TRACER_MAX_TRACE */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1142 | |
Rabin Vincent | e30f53a | 2014-11-10 19:46:34 +0100 | [diff] [blame] | 1143 | static int wait_on_pipe(struct trace_iterator *iter, bool full) |
Steven Rostedt | 0d5c6e1 | 2012-11-01 20:54:21 -0400 | [diff] [blame] | 1144 | { |
Steven Rostedt (Red Hat) | 1569345 | 2013-02-28 19:59:17 -0500 | [diff] [blame] | 1145 | /* Iterators are static, they should be filled or empty */ |
| 1146 | if (trace_buffer_iter(iter, iter->cpu_file)) |
Steven Rostedt (Red Hat) | 8b8b368 | 2014-06-10 09:46:00 -0400 | [diff] [blame] | 1147 | return 0; |
Steven Rostedt | 0d5c6e1 | 2012-11-01 20:54:21 -0400 | [diff] [blame] | 1148 | |
Rabin Vincent | e30f53a | 2014-11-10 19:46:34 +0100 | [diff] [blame] | 1149 | return ring_buffer_wait(iter->trace_buffer->buffer, iter->cpu_file, |
| 1150 | full); |
Steven Rostedt | 0d5c6e1 | 2012-11-01 20:54:21 -0400 | [diff] [blame] | 1151 | } |
| 1152 | |
Steven Rostedt (Red Hat) | f4e781c | 2013-03-07 11:10:56 -0500 | [diff] [blame] | 1153 | #ifdef CONFIG_FTRACE_STARTUP_TEST |
| 1154 | static int run_tracer_selftest(struct tracer *type) |
| 1155 | { |
| 1156 | struct trace_array *tr = &global_trace; |
| 1157 | struct tracer *saved_tracer = tr->current_trace; |
| 1158 | int ret; |
| 1159 | |
| 1160 | if (!type->selftest || tracing_selftest_disabled) |
| 1161 | return 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1162 | |
| 1163 | /* |
Steven Rostedt (Red Hat) | f4e781c | 2013-03-07 11:10:56 -0500 | [diff] [blame] | 1164 | * Run a selftest on this tracer. |
| 1165 | * Here we reset the trace buffer, and set the current |
| 1166 | * tracer to be this tracer. The tracer can then run some |
| 1167 | * internal tracing to verify that everything is in order. |
| 1168 | * If we fail, we do not register this tracer. |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 1169 | */ |
Steven Rostedt (Red Hat) | f4e781c | 2013-03-07 11:10:56 -0500 | [diff] [blame] | 1170 | tracing_reset_online_cpus(&tr->trace_buffer); |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 1171 | |
Steven Rostedt (Red Hat) | f4e781c | 2013-03-07 11:10:56 -0500 | [diff] [blame] | 1172 | tr->current_trace = type; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1173 | |
Steven Rostedt (Red Hat) | f4e781c | 2013-03-07 11:10:56 -0500 | [diff] [blame] | 1174 | #ifdef CONFIG_TRACER_MAX_TRACE |
| 1175 | if (type->use_max_tr) { |
| 1176 | /* If we expanded the buffers, make sure the max is expanded too */ |
| 1177 | if (ring_buffer_expanded) |
| 1178 | ring_buffer_resize(tr->max_buffer.buffer, trace_buf_size, |
| 1179 | RING_BUFFER_ALL_CPUS); |
| 1180 | tr->allocated_snapshot = true; |
| 1181 | } |
| 1182 | #endif |
| 1183 | |
| 1184 | /* the test is responsible for initializing and enabling */ |
| 1185 | pr_info("Testing tracer %s: ", type->name); |
| 1186 | ret = type->selftest(type, tr); |
| 1187 | /* the test is responsible for resetting too */ |
| 1188 | tr->current_trace = saved_tracer; |
| 1189 | if (ret) { |
| 1190 | printk(KERN_CONT "FAILED!\n"); |
| 1191 | /* Add the warning after printing 'FAILED' */ |
| 1192 | WARN_ON(1); |
| 1193 | return -1; |
| 1194 | } |
| 1195 | /* Only reset on passing, to avoid touching corrupted buffers */ |
| 1196 | tracing_reset_online_cpus(&tr->trace_buffer); |
| 1197 | |
| 1198 | #ifdef CONFIG_TRACER_MAX_TRACE |
| 1199 | if (type->use_max_tr) { |
| 1200 | tr->allocated_snapshot = false; |
| 1201 | |
| 1202 | /* Shrink the max buffer again */ |
| 1203 | if (ring_buffer_expanded) |
| 1204 | ring_buffer_resize(tr->max_buffer.buffer, 1, |
| 1205 | RING_BUFFER_ALL_CPUS); |
| 1206 | } |
| 1207 | #endif |
| 1208 | |
| 1209 | printk(KERN_CONT "PASSED\n"); |
| 1210 | return 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1211 | } |
Steven Rostedt (Red Hat) | f4e781c | 2013-03-07 11:10:56 -0500 | [diff] [blame] | 1212 | #else |
| 1213 | static inline int run_tracer_selftest(struct tracer *type) |
| 1214 | { |
| 1215 | return 0; |
| 1216 | } |
| 1217 | #endif /* CONFIG_FTRACE_STARTUP_TEST */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1218 | |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 1219 | /** |
| 1220 | * register_tracer - register a tracer with the ftrace system. |
| 1221 | * @type - the plugin for the tracer |
| 1222 | * |
| 1223 | * Register a new plugin tracer. |
| 1224 | */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1225 | int register_tracer(struct tracer *type) |
| 1226 | { |
| 1227 | struct tracer *t; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1228 | int ret = 0; |
| 1229 | |
| 1230 | if (!type->name) { |
| 1231 | pr_info("Tracer must have a name\n"); |
| 1232 | return -1; |
| 1233 | } |
| 1234 | |
Dan Carpenter | 24a461d | 2010-07-10 12:06:44 +0200 | [diff] [blame] | 1235 | if (strlen(type->name) >= MAX_TRACER_SIZE) { |
Li Zefan | ee6c2c1 | 2009-09-18 14:06:47 +0800 | [diff] [blame] | 1236 | pr_info("Tracer has a name longer than %d\n", MAX_TRACER_SIZE); |
| 1237 | return -1; |
| 1238 | } |
| 1239 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1240 | mutex_lock(&trace_types_lock); |
Ingo Molnar | 86fa2f6 | 2008-11-19 10:00:15 +0100 | [diff] [blame] | 1241 | |
Frederic Weisbecker | 8e1b82e | 2008-12-06 03:41:33 +0100 | [diff] [blame] | 1242 | tracing_selftest_running = true; |
| 1243 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1244 | for (t = trace_types; t; t = t->next) { |
| 1245 | if (strcmp(type->name, t->name) == 0) { |
| 1246 | /* already found */ |
Li Zefan | ee6c2c1 | 2009-09-18 14:06:47 +0800 | [diff] [blame] | 1247 | pr_info("Tracer %s already registered\n", |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1248 | type->name); |
| 1249 | ret = -1; |
| 1250 | goto out; |
| 1251 | } |
| 1252 | } |
| 1253 | |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 1254 | if (!type->set_flag) |
| 1255 | type->set_flag = &dummy_set_flag; |
| 1256 | if (!type->flags) |
| 1257 | type->flags = &dummy_tracer_flags; |
| 1258 | else |
| 1259 | if (!type->flags->opts) |
| 1260 | type->flags->opts = dummy_tracer_opt; |
Frederic Weisbecker | 6eaaa5d | 2009-02-11 02:25:00 +0100 | [diff] [blame] | 1261 | |
Steven Rostedt (Red Hat) | f4e781c | 2013-03-07 11:10:56 -0500 | [diff] [blame] | 1262 | ret = run_tracer_selftest(type); |
| 1263 | if (ret < 0) |
| 1264 | goto out; |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 1265 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1266 | type->next = trace_types; |
| 1267 | trace_types = type; |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 1268 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1269 | out: |
Frederic Weisbecker | 8e1b82e | 2008-12-06 03:41:33 +0100 | [diff] [blame] | 1270 | tracing_selftest_running = false; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1271 | mutex_unlock(&trace_types_lock); |
| 1272 | |
Steven Rostedt | dac7494 | 2009-02-05 01:13:38 -0500 | [diff] [blame] | 1273 | if (ret || !default_bootup_tracer) |
| 1274 | goto out_unlock; |
Steven Rostedt | b2821ae | 2009-02-02 21:38:32 -0500 | [diff] [blame] | 1275 | |
Li Zefan | ee6c2c1 | 2009-09-18 14:06:47 +0800 | [diff] [blame] | 1276 | if (strncmp(default_bootup_tracer, type->name, MAX_TRACER_SIZE)) |
Steven Rostedt | dac7494 | 2009-02-05 01:13:38 -0500 | [diff] [blame] | 1277 | goto out_unlock; |
| 1278 | |
| 1279 | printk(KERN_INFO "Starting tracer '%s'\n", type->name); |
| 1280 | /* Do we want this tracer to start on bootup? */ |
Steven Rostedt (Red Hat) | 607e2ea | 2013-11-06 22:42:48 -0500 | [diff] [blame] | 1281 | tracing_set_tracer(&global_trace, type->name); |
Steven Rostedt | dac7494 | 2009-02-05 01:13:38 -0500 | [diff] [blame] | 1282 | default_bootup_tracer = NULL; |
| 1283 | /* disable other selftests, since this will break it. */ |
Steven Rostedt (Red Hat) | 55034cd | 2013-03-07 22:48:09 -0500 | [diff] [blame] | 1284 | tracing_selftest_disabled = true; |
Steven Rostedt | dac7494 | 2009-02-05 01:13:38 -0500 | [diff] [blame] | 1285 | #ifdef CONFIG_FTRACE_STARTUP_TEST |
| 1286 | printk(KERN_INFO "Disabling FTRACE selftests due to running tracer '%s'\n", |
| 1287 | type->name); |
| 1288 | #endif |
| 1289 | |
| 1290 | out_unlock: |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1291 | return ret; |
| 1292 | } |
| 1293 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1294 | void tracing_reset(struct trace_buffer *buf, int cpu) |
Steven Rostedt | f633903 | 2009-09-04 12:35:16 -0400 | [diff] [blame] | 1295 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1296 | struct ring_buffer *buffer = buf->buffer; |
Steven Rostedt | f633903 | 2009-09-04 12:35:16 -0400 | [diff] [blame] | 1297 | |
Hiraku Toyooka | a541641 | 2012-12-19 16:02:34 +0900 | [diff] [blame] | 1298 | if (!buffer) |
| 1299 | return; |
| 1300 | |
Steven Rostedt | f633903 | 2009-09-04 12:35:16 -0400 | [diff] [blame] | 1301 | ring_buffer_record_disable(buffer); |
| 1302 | |
| 1303 | /* Make sure all commits have finished */ |
| 1304 | synchronize_sched(); |
Steven Rostedt | 6817968 | 2012-05-08 20:57:53 -0400 | [diff] [blame] | 1305 | ring_buffer_reset_cpu(buffer, cpu); |
Steven Rostedt | f633903 | 2009-09-04 12:35:16 -0400 | [diff] [blame] | 1306 | |
| 1307 | ring_buffer_record_enable(buffer); |
| 1308 | } |
| 1309 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1310 | void tracing_reset_online_cpus(struct trace_buffer *buf) |
Pekka J Enberg | 213cc06 | 2008-12-19 12:08:39 +0200 | [diff] [blame] | 1311 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1312 | struct ring_buffer *buffer = buf->buffer; |
Pekka J Enberg | 213cc06 | 2008-12-19 12:08:39 +0200 | [diff] [blame] | 1313 | int cpu; |
| 1314 | |
Hiraku Toyooka | a541641 | 2012-12-19 16:02:34 +0900 | [diff] [blame] | 1315 | if (!buffer) |
| 1316 | return; |
| 1317 | |
Steven Rostedt | 621968c | 2009-09-04 12:02:35 -0400 | [diff] [blame] | 1318 | ring_buffer_record_disable(buffer); |
| 1319 | |
| 1320 | /* Make sure all commits have finished */ |
| 1321 | synchronize_sched(); |
| 1322 | |
Alexander Z Lam | 9457158 | 2013-08-02 18:36:16 -0700 | [diff] [blame] | 1323 | buf->time_start = buffer_ftrace_now(buf, buf->cpu); |
Pekka J Enberg | 213cc06 | 2008-12-19 12:08:39 +0200 | [diff] [blame] | 1324 | |
| 1325 | for_each_online_cpu(cpu) |
Steven Rostedt | 6817968 | 2012-05-08 20:57:53 -0400 | [diff] [blame] | 1326 | ring_buffer_reset_cpu(buffer, cpu); |
Steven Rostedt | 621968c | 2009-09-04 12:02:35 -0400 | [diff] [blame] | 1327 | |
| 1328 | ring_buffer_record_enable(buffer); |
Pekka J Enberg | 213cc06 | 2008-12-19 12:08:39 +0200 | [diff] [blame] | 1329 | } |
| 1330 | |
Steven Rostedt (Red Hat) | 09d8091 | 2013-07-23 22:21:59 -0400 | [diff] [blame] | 1331 | /* Must have trace_types_lock held */ |
Steven Rostedt (Red Hat) | 873c642 | 2013-03-04 23:26:06 -0500 | [diff] [blame] | 1332 | void tracing_reset_all_online_cpus(void) |
Steven Rostedt | 9456f0f | 2009-05-06 21:54:09 -0400 | [diff] [blame] | 1333 | { |
Steven Rostedt (Red Hat) | 873c642 | 2013-03-04 23:26:06 -0500 | [diff] [blame] | 1334 | struct trace_array *tr; |
| 1335 | |
Steven Rostedt (Red Hat) | 873c642 | 2013-03-04 23:26:06 -0500 | [diff] [blame] | 1336 | list_for_each_entry(tr, &ftrace_trace_arrays, list) { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1337 | tracing_reset_online_cpus(&tr->trace_buffer); |
| 1338 | #ifdef CONFIG_TRACER_MAX_TRACE |
| 1339 | tracing_reset_online_cpus(&tr->max_buffer); |
| 1340 | #endif |
Steven Rostedt (Red Hat) | 873c642 | 2013-03-04 23:26:06 -0500 | [diff] [blame] | 1341 | } |
Steven Rostedt | 9456f0f | 2009-05-06 21:54:09 -0400 | [diff] [blame] | 1342 | } |
| 1343 | |
Yoshihiro YUNOMAE | 939c7a4 | 2014-06-05 10:24:27 +0900 | [diff] [blame] | 1344 | #define SAVED_CMDLINES_DEFAULT 128 |
Thomas Gleixner | 2c7eea4 | 2009-03-18 09:03:19 +0100 | [diff] [blame] | 1345 | #define NO_CMDLINE_MAP UINT_MAX |
Thomas Gleixner | edc35bd | 2009-12-03 12:38:57 +0100 | [diff] [blame] | 1346 | static arch_spinlock_t trace_cmdline_lock = __ARCH_SPIN_LOCK_UNLOCKED; |
Yoshihiro YUNOMAE | 939c7a4 | 2014-06-05 10:24:27 +0900 | [diff] [blame] | 1347 | struct saved_cmdlines_buffer { |
| 1348 | unsigned map_pid_to_cmdline[PID_MAX_DEFAULT+1]; |
| 1349 | unsigned *map_cmdline_to_pid; |
| 1350 | unsigned cmdline_num; |
| 1351 | int cmdline_idx; |
| 1352 | char *saved_cmdlines; |
| 1353 | }; |
| 1354 | static struct saved_cmdlines_buffer *savedcmd; |
Steven Rostedt | 25b0b44 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 1355 | |
Steven Rostedt | 25b0b44 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 1356 | /* temporary disable recording */ |
Hannes Eder | 4fd2735 | 2009-02-10 19:44:12 +0100 | [diff] [blame] | 1357 | static atomic_t trace_record_cmdline_disabled __read_mostly; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1358 | |
Yoshihiro YUNOMAE | 939c7a4 | 2014-06-05 10:24:27 +0900 | [diff] [blame] | 1359 | static inline char *get_saved_cmdlines(int idx) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1360 | { |
Yoshihiro YUNOMAE | 939c7a4 | 2014-06-05 10:24:27 +0900 | [diff] [blame] | 1361 | return &savedcmd->saved_cmdlines[idx * TASK_COMM_LEN]; |
| 1362 | } |
| 1363 | |
| 1364 | static inline void set_cmdline(int idx, const char *cmdline) |
| 1365 | { |
| 1366 | memcpy(get_saved_cmdlines(idx), cmdline, TASK_COMM_LEN); |
| 1367 | } |
| 1368 | |
| 1369 | static int allocate_cmdlines_buffer(unsigned int val, |
| 1370 | struct saved_cmdlines_buffer *s) |
| 1371 | { |
| 1372 | s->map_cmdline_to_pid = kmalloc(val * sizeof(*s->map_cmdline_to_pid), |
| 1373 | GFP_KERNEL); |
| 1374 | if (!s->map_cmdline_to_pid) |
| 1375 | return -ENOMEM; |
| 1376 | |
| 1377 | s->saved_cmdlines = kmalloc(val * TASK_COMM_LEN, GFP_KERNEL); |
| 1378 | if (!s->saved_cmdlines) { |
| 1379 | kfree(s->map_cmdline_to_pid); |
| 1380 | return -ENOMEM; |
| 1381 | } |
| 1382 | |
| 1383 | s->cmdline_idx = 0; |
| 1384 | s->cmdline_num = val; |
| 1385 | memset(&s->map_pid_to_cmdline, NO_CMDLINE_MAP, |
| 1386 | sizeof(s->map_pid_to_cmdline)); |
| 1387 | memset(s->map_cmdline_to_pid, NO_CMDLINE_MAP, |
| 1388 | val * sizeof(*s->map_cmdline_to_pid)); |
| 1389 | |
| 1390 | return 0; |
| 1391 | } |
| 1392 | |
| 1393 | static int trace_create_savedcmd(void) |
| 1394 | { |
| 1395 | int ret; |
| 1396 | |
Namhyung Kim | a6af8fb | 2014-06-10 16:11:35 +0900 | [diff] [blame] | 1397 | savedcmd = kmalloc(sizeof(*savedcmd), GFP_KERNEL); |
Yoshihiro YUNOMAE | 939c7a4 | 2014-06-05 10:24:27 +0900 | [diff] [blame] | 1398 | if (!savedcmd) |
| 1399 | return -ENOMEM; |
| 1400 | |
| 1401 | ret = allocate_cmdlines_buffer(SAVED_CMDLINES_DEFAULT, savedcmd); |
| 1402 | if (ret < 0) { |
| 1403 | kfree(savedcmd); |
| 1404 | savedcmd = NULL; |
| 1405 | return -ENOMEM; |
| 1406 | } |
| 1407 | |
| 1408 | return 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1409 | } |
| 1410 | |
Carsten Emde | b5130b1 | 2009-09-13 01:43:07 +0200 | [diff] [blame] | 1411 | int is_tracing_stopped(void) |
| 1412 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 1413 | return global_trace.stop_count; |
Carsten Emde | b5130b1 | 2009-09-13 01:43:07 +0200 | [diff] [blame] | 1414 | } |
| 1415 | |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1416 | /** |
| 1417 | * tracing_start - quick start of the tracer |
| 1418 | * |
| 1419 | * If tracing is enabled but was stopped by tracing_stop, |
| 1420 | * this will start the tracer back up. |
| 1421 | */ |
| 1422 | void tracing_start(void) |
| 1423 | { |
| 1424 | struct ring_buffer *buffer; |
| 1425 | unsigned long flags; |
| 1426 | |
| 1427 | if (tracing_disabled) |
| 1428 | return; |
| 1429 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 1430 | raw_spin_lock_irqsave(&global_trace.start_lock, flags); |
| 1431 | if (--global_trace.stop_count) { |
| 1432 | if (global_trace.stop_count < 0) { |
Steven Rostedt | b06a830 | 2009-01-22 14:26:15 -0500 | [diff] [blame] | 1433 | /* Someone screwed up their debugging */ |
| 1434 | WARN_ON_ONCE(1); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 1435 | global_trace.stop_count = 0; |
Steven Rostedt | b06a830 | 2009-01-22 14:26:15 -0500 | [diff] [blame] | 1436 | } |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1437 | goto out; |
| 1438 | } |
| 1439 | |
Steven Rostedt | a2f8071 | 2010-03-12 19:56:00 -0500 | [diff] [blame] | 1440 | /* Prevent the buffers from switching */ |
Steven Rostedt (Red Hat) | 0b9b12c | 2014-01-14 10:04:59 -0500 | [diff] [blame] | 1441 | arch_spin_lock(&global_trace.max_lock); |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1442 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1443 | buffer = global_trace.trace_buffer.buffer; |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1444 | if (buffer) |
| 1445 | ring_buffer_record_enable(buffer); |
| 1446 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1447 | #ifdef CONFIG_TRACER_MAX_TRACE |
| 1448 | buffer = global_trace.max_buffer.buffer; |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1449 | if (buffer) |
| 1450 | ring_buffer_record_enable(buffer); |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1451 | #endif |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1452 | |
Steven Rostedt (Red Hat) | 0b9b12c | 2014-01-14 10:04:59 -0500 | [diff] [blame] | 1453 | arch_spin_unlock(&global_trace.max_lock); |
Steven Rostedt | a2f8071 | 2010-03-12 19:56:00 -0500 | [diff] [blame] | 1454 | |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1455 | out: |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 1456 | raw_spin_unlock_irqrestore(&global_trace.start_lock, flags); |
| 1457 | } |
| 1458 | |
| 1459 | static void tracing_start_tr(struct trace_array *tr) |
| 1460 | { |
| 1461 | struct ring_buffer *buffer; |
| 1462 | unsigned long flags; |
| 1463 | |
| 1464 | if (tracing_disabled) |
| 1465 | return; |
| 1466 | |
| 1467 | /* If global, we need to also start the max tracer */ |
| 1468 | if (tr->flags & TRACE_ARRAY_FL_GLOBAL) |
| 1469 | return tracing_start(); |
| 1470 | |
| 1471 | raw_spin_lock_irqsave(&tr->start_lock, flags); |
| 1472 | |
| 1473 | if (--tr->stop_count) { |
| 1474 | if (tr->stop_count < 0) { |
| 1475 | /* Someone screwed up their debugging */ |
| 1476 | WARN_ON_ONCE(1); |
| 1477 | tr->stop_count = 0; |
| 1478 | } |
| 1479 | goto out; |
| 1480 | } |
| 1481 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1482 | buffer = tr->trace_buffer.buffer; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 1483 | if (buffer) |
| 1484 | ring_buffer_record_enable(buffer); |
| 1485 | |
| 1486 | out: |
| 1487 | raw_spin_unlock_irqrestore(&tr->start_lock, flags); |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1488 | } |
| 1489 | |
| 1490 | /** |
| 1491 | * tracing_stop - quick stop of the tracer |
| 1492 | * |
| 1493 | * Light weight way to stop tracing. Use in conjunction with |
| 1494 | * tracing_start. |
| 1495 | */ |
| 1496 | void tracing_stop(void) |
| 1497 | { |
| 1498 | struct ring_buffer *buffer; |
| 1499 | unsigned long flags; |
| 1500 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 1501 | raw_spin_lock_irqsave(&global_trace.start_lock, flags); |
| 1502 | if (global_trace.stop_count++) |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1503 | goto out; |
| 1504 | |
Steven Rostedt | a2f8071 | 2010-03-12 19:56:00 -0500 | [diff] [blame] | 1505 | /* Prevent the buffers from switching */ |
Steven Rostedt (Red Hat) | 0b9b12c | 2014-01-14 10:04:59 -0500 | [diff] [blame] | 1506 | arch_spin_lock(&global_trace.max_lock); |
Steven Rostedt | a2f8071 | 2010-03-12 19:56:00 -0500 | [diff] [blame] | 1507 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1508 | buffer = global_trace.trace_buffer.buffer; |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1509 | if (buffer) |
| 1510 | ring_buffer_record_disable(buffer); |
| 1511 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1512 | #ifdef CONFIG_TRACER_MAX_TRACE |
| 1513 | buffer = global_trace.max_buffer.buffer; |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1514 | if (buffer) |
| 1515 | ring_buffer_record_disable(buffer); |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1516 | #endif |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1517 | |
Steven Rostedt (Red Hat) | 0b9b12c | 2014-01-14 10:04:59 -0500 | [diff] [blame] | 1518 | arch_spin_unlock(&global_trace.max_lock); |
Steven Rostedt | a2f8071 | 2010-03-12 19:56:00 -0500 | [diff] [blame] | 1519 | |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1520 | out: |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 1521 | raw_spin_unlock_irqrestore(&global_trace.start_lock, flags); |
| 1522 | } |
| 1523 | |
| 1524 | static void tracing_stop_tr(struct trace_array *tr) |
| 1525 | { |
| 1526 | struct ring_buffer *buffer; |
| 1527 | unsigned long flags; |
| 1528 | |
| 1529 | /* If global, we need to also stop the max tracer */ |
| 1530 | if (tr->flags & TRACE_ARRAY_FL_GLOBAL) |
| 1531 | return tracing_stop(); |
| 1532 | |
| 1533 | raw_spin_lock_irqsave(&tr->start_lock, flags); |
| 1534 | if (tr->stop_count++) |
| 1535 | goto out; |
| 1536 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1537 | buffer = tr->trace_buffer.buffer; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 1538 | if (buffer) |
| 1539 | ring_buffer_record_disable(buffer); |
| 1540 | |
| 1541 | out: |
| 1542 | raw_spin_unlock_irqrestore(&tr->start_lock, flags); |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1543 | } |
| 1544 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1545 | void trace_stop_cmdline_recording(void); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1546 | |
Steven Rostedt (Red Hat) | 379cfda | 2014-05-30 09:42:39 -0400 | [diff] [blame] | 1547 | static int trace_save_cmdline(struct task_struct *tsk) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1548 | { |
Carsten Emde | a635cf0 | 2009-03-18 09:00:41 +0100 | [diff] [blame] | 1549 | unsigned pid, idx; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1550 | |
| 1551 | if (!tsk->pid || unlikely(tsk->pid > PID_MAX_DEFAULT)) |
Steven Rostedt (Red Hat) | 379cfda | 2014-05-30 09:42:39 -0400 | [diff] [blame] | 1552 | return 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1553 | |
| 1554 | /* |
| 1555 | * It's not the end of the world if we don't get |
| 1556 | * the lock, but we also don't want to spin |
| 1557 | * nor do we want to disable interrupts, |
| 1558 | * so if we miss here, then better luck next time. |
| 1559 | */ |
Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 1560 | if (!arch_spin_trylock(&trace_cmdline_lock)) |
Steven Rostedt (Red Hat) | 379cfda | 2014-05-30 09:42:39 -0400 | [diff] [blame] | 1561 | return 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1562 | |
Yoshihiro YUNOMAE | 939c7a4 | 2014-06-05 10:24:27 +0900 | [diff] [blame] | 1563 | idx = savedcmd->map_pid_to_cmdline[tsk->pid]; |
Thomas Gleixner | 2c7eea4 | 2009-03-18 09:03:19 +0100 | [diff] [blame] | 1564 | if (idx == NO_CMDLINE_MAP) { |
Yoshihiro YUNOMAE | 939c7a4 | 2014-06-05 10:24:27 +0900 | [diff] [blame] | 1565 | idx = (savedcmd->cmdline_idx + 1) % savedcmd->cmdline_num; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1566 | |
Carsten Emde | a635cf0 | 2009-03-18 09:00:41 +0100 | [diff] [blame] | 1567 | /* |
| 1568 | * Check whether the cmdline buffer at idx has a pid |
| 1569 | * mapped. We are going to overwrite that entry so we |
| 1570 | * need to clear the map_pid_to_cmdline. Otherwise we |
| 1571 | * would read the new comm for the old pid. |
| 1572 | */ |
Yoshihiro YUNOMAE | 939c7a4 | 2014-06-05 10:24:27 +0900 | [diff] [blame] | 1573 | pid = savedcmd->map_cmdline_to_pid[idx]; |
Carsten Emde | a635cf0 | 2009-03-18 09:00:41 +0100 | [diff] [blame] | 1574 | if (pid != NO_CMDLINE_MAP) |
Yoshihiro YUNOMAE | 939c7a4 | 2014-06-05 10:24:27 +0900 | [diff] [blame] | 1575 | savedcmd->map_pid_to_cmdline[pid] = NO_CMDLINE_MAP; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1576 | |
Yoshihiro YUNOMAE | 939c7a4 | 2014-06-05 10:24:27 +0900 | [diff] [blame] | 1577 | savedcmd->map_cmdline_to_pid[idx] = tsk->pid; |
| 1578 | savedcmd->map_pid_to_cmdline[tsk->pid] = idx; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1579 | |
Yoshihiro YUNOMAE | 939c7a4 | 2014-06-05 10:24:27 +0900 | [diff] [blame] | 1580 | savedcmd->cmdline_idx = idx; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1581 | } |
| 1582 | |
Yoshihiro YUNOMAE | 939c7a4 | 2014-06-05 10:24:27 +0900 | [diff] [blame] | 1583 | set_cmdline(idx, tsk->comm); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1584 | |
Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 1585 | arch_spin_unlock(&trace_cmdline_lock); |
Steven Rostedt (Red Hat) | 379cfda | 2014-05-30 09:42:39 -0400 | [diff] [blame] | 1586 | |
| 1587 | return 1; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1588 | } |
| 1589 | |
Steven Rostedt (Red Hat) | 4c27e75 | 2014-05-30 10:49:46 -0400 | [diff] [blame] | 1590 | static void __trace_find_cmdline(int pid, char comm[]) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1591 | { |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1592 | unsigned map; |
| 1593 | |
Steven Rostedt | 4ca53085 | 2009-03-16 19:20:15 -0400 | [diff] [blame] | 1594 | if (!pid) { |
| 1595 | strcpy(comm, "<idle>"); |
| 1596 | return; |
| 1597 | } |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1598 | |
Steven Rostedt | 74bf407 | 2010-01-25 15:11:53 -0500 | [diff] [blame] | 1599 | if (WARN_ON_ONCE(pid < 0)) { |
| 1600 | strcpy(comm, "<XXX>"); |
| 1601 | return; |
| 1602 | } |
| 1603 | |
Steven Rostedt | 4ca53085 | 2009-03-16 19:20:15 -0400 | [diff] [blame] | 1604 | if (pid > PID_MAX_DEFAULT) { |
| 1605 | strcpy(comm, "<...>"); |
| 1606 | return; |
| 1607 | } |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1608 | |
Yoshihiro YUNOMAE | 939c7a4 | 2014-06-05 10:24:27 +0900 | [diff] [blame] | 1609 | map = savedcmd->map_pid_to_cmdline[pid]; |
Thomas Gleixner | 50d8875 | 2009-03-18 08:58:44 +0100 | [diff] [blame] | 1610 | if (map != NO_CMDLINE_MAP) |
Yoshihiro YUNOMAE | 939c7a4 | 2014-06-05 10:24:27 +0900 | [diff] [blame] | 1611 | strcpy(comm, get_saved_cmdlines(map)); |
Thomas Gleixner | 50d8875 | 2009-03-18 08:58:44 +0100 | [diff] [blame] | 1612 | else |
| 1613 | strcpy(comm, "<...>"); |
Steven Rostedt (Red Hat) | 4c27e75 | 2014-05-30 10:49:46 -0400 | [diff] [blame] | 1614 | } |
| 1615 | |
| 1616 | void trace_find_cmdline(int pid, char comm[]) |
| 1617 | { |
| 1618 | preempt_disable(); |
| 1619 | arch_spin_lock(&trace_cmdline_lock); |
| 1620 | |
| 1621 | __trace_find_cmdline(pid, comm); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1622 | |
Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 1623 | arch_spin_unlock(&trace_cmdline_lock); |
Heiko Carstens | 5b6045a | 2009-05-26 17:28:02 +0200 | [diff] [blame] | 1624 | preempt_enable(); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1625 | } |
| 1626 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1627 | void tracing_record_cmdline(struct task_struct *tsk) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1628 | { |
Steven Rostedt | 0fb9656 | 2012-05-11 14:25:30 -0400 | [diff] [blame] | 1629 | if (atomic_read(&trace_record_cmdline_disabled) || !tracing_is_on()) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1630 | return; |
| 1631 | |
Steven Rostedt | 7ffbd48 | 2012-10-11 12:14:25 -0400 | [diff] [blame] | 1632 | if (!__this_cpu_read(trace_cmdline_save)) |
| 1633 | return; |
| 1634 | |
Steven Rostedt (Red Hat) | 379cfda | 2014-05-30 09:42:39 -0400 | [diff] [blame] | 1635 | if (trace_save_cmdline(tsk)) |
| 1636 | __this_cpu_write(trace_cmdline_save, false); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1637 | } |
| 1638 | |
Pekka Paalanen | 45dcd8b | 2008-09-16 21:56:41 +0300 | [diff] [blame] | 1639 | void |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 1640 | tracing_generic_entry_update(struct trace_entry *entry, unsigned long flags, |
| 1641 | int pc) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1642 | { |
| 1643 | struct task_struct *tsk = current; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1644 | |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1645 | entry->preempt_count = pc & 0xff; |
| 1646 | entry->pid = (tsk) ? tsk->pid : 0; |
| 1647 | entry->flags = |
Steven Rostedt | 9244489 | 2008-10-24 09:42:59 -0400 | [diff] [blame] | 1648 | #ifdef CONFIG_TRACE_IRQFLAGS_SUPPORT |
Steven Rostedt | 2e2ca15 | 2008-08-01 12:26:40 -0400 | [diff] [blame] | 1649 | (irqs_disabled_flags(flags) ? TRACE_FLAG_IRQS_OFF : 0) | |
Steven Rostedt | 9244489 | 2008-10-24 09:42:59 -0400 | [diff] [blame] | 1650 | #else |
| 1651 | TRACE_FLAG_IRQS_NOSUPPORT | |
| 1652 | #endif |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1653 | ((pc & HARDIRQ_MASK) ? TRACE_FLAG_HARDIRQ : 0) | |
| 1654 | ((pc & SOFTIRQ_MASK) ? TRACE_FLAG_SOFTIRQ : 0) | |
Peter Zijlstra | e5137b5 | 2013-10-04 17:28:26 +0200 | [diff] [blame] | 1655 | (tif_need_resched() ? TRACE_FLAG_NEED_RESCHED : 0) | |
| 1656 | (test_preempt_need_resched() ? TRACE_FLAG_PREEMPT_RESCHED : 0); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1657 | } |
Frederic Weisbecker | f413cdb | 2009-08-07 01:25:54 +0200 | [diff] [blame] | 1658 | EXPORT_SYMBOL_GPL(tracing_generic_entry_update); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1659 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1660 | struct ring_buffer_event * |
| 1661 | trace_buffer_lock_reserve(struct ring_buffer *buffer, |
| 1662 | int type, |
| 1663 | unsigned long len, |
| 1664 | unsigned long flags, int pc) |
Arnaldo Carvalho de Melo | 51a763d | 2009-02-05 16:14:13 -0200 | [diff] [blame] | 1665 | { |
| 1666 | struct ring_buffer_event *event; |
| 1667 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1668 | event = ring_buffer_lock_reserve(buffer, len); |
Arnaldo Carvalho de Melo | 51a763d | 2009-02-05 16:14:13 -0200 | [diff] [blame] | 1669 | if (event != NULL) { |
| 1670 | struct trace_entry *ent = ring_buffer_event_data(event); |
| 1671 | |
| 1672 | tracing_generic_entry_update(ent, flags, pc); |
| 1673 | ent->type = type; |
| 1674 | } |
| 1675 | |
| 1676 | return event; |
| 1677 | } |
Arnaldo Carvalho de Melo | 51a763d | 2009-02-05 16:14:13 -0200 | [diff] [blame] | 1678 | |
Steven Rostedt | 7ffbd48 | 2012-10-11 12:14:25 -0400 | [diff] [blame] | 1679 | void |
| 1680 | __buffer_unlock_commit(struct ring_buffer *buffer, struct ring_buffer_event *event) |
| 1681 | { |
| 1682 | __this_cpu_write(trace_cmdline_save, true); |
| 1683 | ring_buffer_unlock_commit(buffer, event); |
| 1684 | } |
| 1685 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1686 | static inline void |
| 1687 | __trace_buffer_unlock_commit(struct ring_buffer *buffer, |
| 1688 | struct ring_buffer_event *event, |
Steven Rostedt | 0d5c6e1 | 2012-11-01 20:54:21 -0400 | [diff] [blame] | 1689 | unsigned long flags, int pc) |
Arnaldo Carvalho de Melo | 51a763d | 2009-02-05 16:14:13 -0200 | [diff] [blame] | 1690 | { |
Steven Rostedt | 7ffbd48 | 2012-10-11 12:14:25 -0400 | [diff] [blame] | 1691 | __buffer_unlock_commit(buffer, event); |
Arnaldo Carvalho de Melo | 51a763d | 2009-02-05 16:14:13 -0200 | [diff] [blame] | 1692 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1693 | ftrace_trace_stack(buffer, flags, 6, pc); |
| 1694 | ftrace_trace_userstack(buffer, flags, pc); |
Frederic Weisbecker | 07edf71 | 2009-03-22 23:10:46 +0100 | [diff] [blame] | 1695 | } |
| 1696 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1697 | void trace_buffer_unlock_commit(struct ring_buffer *buffer, |
| 1698 | struct ring_buffer_event *event, |
| 1699 | unsigned long flags, int pc) |
Frederic Weisbecker | 07edf71 | 2009-03-22 23:10:46 +0100 | [diff] [blame] | 1700 | { |
Steven Rostedt | 0d5c6e1 | 2012-11-01 20:54:21 -0400 | [diff] [blame] | 1701 | __trace_buffer_unlock_commit(buffer, event, flags, pc); |
Arnaldo Carvalho de Melo | 51a763d | 2009-02-05 16:14:13 -0200 | [diff] [blame] | 1702 | } |
Steven Rostedt | 0d5c6e1 | 2012-11-01 20:54:21 -0400 | [diff] [blame] | 1703 | EXPORT_SYMBOL_GPL(trace_buffer_unlock_commit); |
Arnaldo Carvalho de Melo | 51a763d | 2009-02-05 16:14:13 -0200 | [diff] [blame] | 1704 | |
Steven Rostedt (Red Hat) | 2c4a33a | 2014-03-25 23:39:41 -0400 | [diff] [blame] | 1705 | static struct ring_buffer *temp_buffer; |
| 1706 | |
Steven Rostedt | ef5580d | 2009-02-27 19:38:04 -0500 | [diff] [blame] | 1707 | struct ring_buffer_event * |
Steven Rostedt | ccb469a | 2012-08-02 10:32:10 -0400 | [diff] [blame] | 1708 | trace_event_buffer_lock_reserve(struct ring_buffer **current_rb, |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 1709 | struct trace_event_file *trace_file, |
Steven Rostedt | ccb469a | 2012-08-02 10:32:10 -0400 | [diff] [blame] | 1710 | int type, unsigned long len, |
| 1711 | unsigned long flags, int pc) |
| 1712 | { |
Steven Rostedt (Red Hat) | 2c4a33a | 2014-03-25 23:39:41 -0400 | [diff] [blame] | 1713 | struct ring_buffer_event *entry; |
| 1714 | |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 1715 | *current_rb = trace_file->tr->trace_buffer.buffer; |
Steven Rostedt (Red Hat) | 2c4a33a | 2014-03-25 23:39:41 -0400 | [diff] [blame] | 1716 | entry = trace_buffer_lock_reserve(*current_rb, |
Steven Rostedt | ccb469a | 2012-08-02 10:32:10 -0400 | [diff] [blame] | 1717 | type, len, flags, pc); |
Steven Rostedt (Red Hat) | 2c4a33a | 2014-03-25 23:39:41 -0400 | [diff] [blame] | 1718 | /* |
| 1719 | * If tracing is off, but we have triggers enabled |
| 1720 | * we still need to look at the event data. Use the temp_buffer |
| 1721 | * to store the trace event for the tigger to use. It's recusive |
| 1722 | * safe and will not be recorded anywhere. |
| 1723 | */ |
Steven Rostedt (Red Hat) | 5d6ad96 | 2015-05-13 15:12:33 -0400 | [diff] [blame] | 1724 | if (!entry && trace_file->flags & EVENT_FILE_FL_TRIGGER_COND) { |
Steven Rostedt (Red Hat) | 2c4a33a | 2014-03-25 23:39:41 -0400 | [diff] [blame] | 1725 | *current_rb = temp_buffer; |
| 1726 | entry = trace_buffer_lock_reserve(*current_rb, |
| 1727 | type, len, flags, pc); |
| 1728 | } |
| 1729 | return entry; |
Steven Rostedt | ccb469a | 2012-08-02 10:32:10 -0400 | [diff] [blame] | 1730 | } |
| 1731 | EXPORT_SYMBOL_GPL(trace_event_buffer_lock_reserve); |
| 1732 | |
| 1733 | struct ring_buffer_event * |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1734 | trace_current_buffer_lock_reserve(struct ring_buffer **current_rb, |
| 1735 | int type, unsigned long len, |
Steven Rostedt | ef5580d | 2009-02-27 19:38:04 -0500 | [diff] [blame] | 1736 | unsigned long flags, int pc) |
| 1737 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1738 | *current_rb = global_trace.trace_buffer.buffer; |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1739 | return trace_buffer_lock_reserve(*current_rb, |
Steven Rostedt | ef5580d | 2009-02-27 19:38:04 -0500 | [diff] [blame] | 1740 | type, len, flags, pc); |
| 1741 | } |
Steven Rostedt | 94487d6 | 2009-05-05 19:22:53 -0400 | [diff] [blame] | 1742 | EXPORT_SYMBOL_GPL(trace_current_buffer_lock_reserve); |
Steven Rostedt | ef5580d | 2009-02-27 19:38:04 -0500 | [diff] [blame] | 1743 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1744 | void trace_current_buffer_unlock_commit(struct ring_buffer *buffer, |
| 1745 | struct ring_buffer_event *event, |
Steven Rostedt | ef5580d | 2009-02-27 19:38:04 -0500 | [diff] [blame] | 1746 | unsigned long flags, int pc) |
| 1747 | { |
Steven Rostedt | 0d5c6e1 | 2012-11-01 20:54:21 -0400 | [diff] [blame] | 1748 | __trace_buffer_unlock_commit(buffer, event, flags, pc); |
Frederic Weisbecker | 07edf71 | 2009-03-22 23:10:46 +0100 | [diff] [blame] | 1749 | } |
Steven Rostedt | 94487d6 | 2009-05-05 19:22:53 -0400 | [diff] [blame] | 1750 | EXPORT_SYMBOL_GPL(trace_current_buffer_unlock_commit); |
Frederic Weisbecker | 07edf71 | 2009-03-22 23:10:46 +0100 | [diff] [blame] | 1751 | |
Steven Rostedt | 0d5c6e1 | 2012-11-01 20:54:21 -0400 | [diff] [blame] | 1752 | void trace_buffer_unlock_commit_regs(struct ring_buffer *buffer, |
| 1753 | struct ring_buffer_event *event, |
| 1754 | unsigned long flags, int pc, |
| 1755 | struct pt_regs *regs) |
Masami Hiramatsu | 1fd8df2 | 2011-06-08 16:09:34 +0900 | [diff] [blame] | 1756 | { |
Steven Rostedt | 7ffbd48 | 2012-10-11 12:14:25 -0400 | [diff] [blame] | 1757 | __buffer_unlock_commit(buffer, event); |
Masami Hiramatsu | 1fd8df2 | 2011-06-08 16:09:34 +0900 | [diff] [blame] | 1758 | |
Steven Rostedt (Red Hat) | d78a461 | 2015-09-25 13:30:47 -0400 | [diff] [blame^] | 1759 | if (trace_flags & TRACE_ITER_STACKTRACE) |
| 1760 | __ftrace_trace_stack(buffer, flags, 0, pc, regs); |
Masami Hiramatsu | 1fd8df2 | 2011-06-08 16:09:34 +0900 | [diff] [blame] | 1761 | ftrace_trace_userstack(buffer, flags, pc); |
| 1762 | } |
Steven Rostedt | 0d5c6e1 | 2012-11-01 20:54:21 -0400 | [diff] [blame] | 1763 | EXPORT_SYMBOL_GPL(trace_buffer_unlock_commit_regs); |
Masami Hiramatsu | 1fd8df2 | 2011-06-08 16:09:34 +0900 | [diff] [blame] | 1764 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1765 | void trace_current_buffer_discard_commit(struct ring_buffer *buffer, |
| 1766 | struct ring_buffer_event *event) |
Steven Rostedt | 77d9f46 | 2009-04-02 01:16:59 -0400 | [diff] [blame] | 1767 | { |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1768 | ring_buffer_discard_commit(buffer, event); |
Steven Rostedt | ef5580d | 2009-02-27 19:38:04 -0500 | [diff] [blame] | 1769 | } |
Steven Rostedt | 12acd47 | 2009-04-17 16:01:56 -0400 | [diff] [blame] | 1770 | EXPORT_SYMBOL_GPL(trace_current_buffer_discard_commit); |
Steven Rostedt | ef5580d | 2009-02-27 19:38:04 -0500 | [diff] [blame] | 1771 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1772 | void |
Arnaldo Carvalho de Melo | 7be4215 | 2009-02-05 01:13:37 -0500 | [diff] [blame] | 1773 | trace_function(struct trace_array *tr, |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 1774 | unsigned long ip, unsigned long parent_ip, unsigned long flags, |
| 1775 | int pc) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1776 | { |
Steven Rostedt (Red Hat) | 2425bcb | 2015-05-05 11:45:27 -0400 | [diff] [blame] | 1777 | struct trace_event_call *call = &event_function; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1778 | struct ring_buffer *buffer = tr->trace_buffer.buffer; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1779 | struct ring_buffer_event *event; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1780 | struct ftrace_entry *entry; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1781 | |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 1782 | /* If we are reading the ring buffer, don't trace */ |
Rusty Russell | dd17c8f | 2009-10-29 22:34:15 +0900 | [diff] [blame] | 1783 | if (unlikely(__this_cpu_read(ftrace_cpu_disabled))) |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 1784 | return; |
| 1785 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1786 | event = trace_buffer_lock_reserve(buffer, TRACE_FN, sizeof(*entry), |
Arnaldo Carvalho de Melo | 51a763d | 2009-02-05 16:14:13 -0200 | [diff] [blame] | 1787 | flags, pc); |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1788 | if (!event) |
| 1789 | return; |
| 1790 | entry = ring_buffer_event_data(event); |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1791 | entry->ip = ip; |
| 1792 | entry->parent_ip = parent_ip; |
Tom Zanussi | e1112b4 | 2009-03-31 00:48:49 -0500 | [diff] [blame] | 1793 | |
Tom Zanussi | f306cc8 | 2013-10-24 08:34:17 -0500 | [diff] [blame] | 1794 | if (!call_filter_check_discard(call, entry, buffer, event)) |
Steven Rostedt | 7ffbd48 | 2012-10-11 12:14:25 -0400 | [diff] [blame] | 1795 | __buffer_unlock_commit(buffer, event); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1796 | } |
| 1797 | |
Frederic Weisbecker | c0a0d0d | 2009-07-29 17:51:13 +0200 | [diff] [blame] | 1798 | #ifdef CONFIG_STACKTRACE |
Steven Rostedt | 4a9bd3f | 2011-07-14 16:36:53 -0400 | [diff] [blame] | 1799 | |
| 1800 | #define FTRACE_STACK_MAX_ENTRIES (PAGE_SIZE / sizeof(unsigned long)) |
| 1801 | struct ftrace_stack { |
| 1802 | unsigned long calls[FTRACE_STACK_MAX_ENTRIES]; |
| 1803 | }; |
| 1804 | |
| 1805 | static DEFINE_PER_CPU(struct ftrace_stack, ftrace_stack); |
| 1806 | static DEFINE_PER_CPU(int, ftrace_stack_reserve); |
| 1807 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1808 | static void __ftrace_trace_stack(struct ring_buffer *buffer, |
Steven Rostedt | 5361499 | 2009-01-15 19:12:40 -0500 | [diff] [blame] | 1809 | unsigned long flags, |
Masami Hiramatsu | 1fd8df2 | 2011-06-08 16:09:34 +0900 | [diff] [blame] | 1810 | int skip, int pc, struct pt_regs *regs) |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1811 | { |
Steven Rostedt (Red Hat) | 2425bcb | 2015-05-05 11:45:27 -0400 | [diff] [blame] | 1812 | struct trace_event_call *call = &event_kernel_stack; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1813 | struct ring_buffer_event *event; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1814 | struct stack_entry *entry; |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1815 | struct stack_trace trace; |
Steven Rostedt | 4a9bd3f | 2011-07-14 16:36:53 -0400 | [diff] [blame] | 1816 | int use_stack; |
| 1817 | int size = FTRACE_STACK_ENTRIES; |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1818 | |
| 1819 | trace.nr_entries = 0; |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1820 | trace.skip = skip; |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1821 | |
Steven Rostedt | 4a9bd3f | 2011-07-14 16:36:53 -0400 | [diff] [blame] | 1822 | /* |
| 1823 | * Since events can happen in NMIs there's no safe way to |
| 1824 | * use the per cpu ftrace_stacks. We reserve it and if an interrupt |
| 1825 | * or NMI comes in, it will just have to use the default |
| 1826 | * FTRACE_STACK_SIZE. |
| 1827 | */ |
| 1828 | preempt_disable_notrace(); |
| 1829 | |
Shan Wei | 8214652 | 2012-11-19 13:21:01 +0800 | [diff] [blame] | 1830 | use_stack = __this_cpu_inc_return(ftrace_stack_reserve); |
Steven Rostedt | 4a9bd3f | 2011-07-14 16:36:53 -0400 | [diff] [blame] | 1831 | /* |
| 1832 | * We don't need any atomic variables, just a barrier. |
| 1833 | * If an interrupt comes in, we don't care, because it would |
| 1834 | * have exited and put the counter back to what we want. |
| 1835 | * We just need a barrier to keep gcc from moving things |
| 1836 | * around. |
| 1837 | */ |
| 1838 | barrier(); |
| 1839 | if (use_stack == 1) { |
Christoph Lameter | bdffd89 | 2014-04-29 14:17:40 -0500 | [diff] [blame] | 1840 | trace.entries = this_cpu_ptr(ftrace_stack.calls); |
Steven Rostedt | 4a9bd3f | 2011-07-14 16:36:53 -0400 | [diff] [blame] | 1841 | trace.max_entries = FTRACE_STACK_MAX_ENTRIES; |
| 1842 | |
| 1843 | if (regs) |
| 1844 | save_stack_trace_regs(regs, &trace); |
| 1845 | else |
| 1846 | save_stack_trace(&trace); |
| 1847 | |
| 1848 | if (trace.nr_entries > size) |
| 1849 | size = trace.nr_entries; |
| 1850 | } else |
| 1851 | /* From now on, use_stack is a boolean */ |
| 1852 | use_stack = 0; |
| 1853 | |
| 1854 | size *= sizeof(unsigned long); |
| 1855 | |
| 1856 | event = trace_buffer_lock_reserve(buffer, TRACE_STACK, |
| 1857 | sizeof(*entry) + size, flags, pc); |
| 1858 | if (!event) |
| 1859 | goto out; |
| 1860 | entry = ring_buffer_event_data(event); |
| 1861 | |
| 1862 | memset(&entry->caller, 0, size); |
| 1863 | |
| 1864 | if (use_stack) |
| 1865 | memcpy(&entry->caller, trace.entries, |
| 1866 | trace.nr_entries * sizeof(unsigned long)); |
| 1867 | else { |
| 1868 | trace.max_entries = FTRACE_STACK_ENTRIES; |
| 1869 | trace.entries = entry->caller; |
| 1870 | if (regs) |
| 1871 | save_stack_trace_regs(regs, &trace); |
| 1872 | else |
| 1873 | save_stack_trace(&trace); |
| 1874 | } |
| 1875 | |
| 1876 | entry->size = trace.nr_entries; |
| 1877 | |
Tom Zanussi | f306cc8 | 2013-10-24 08:34:17 -0500 | [diff] [blame] | 1878 | if (!call_filter_check_discard(call, entry, buffer, event)) |
Steven Rostedt | 7ffbd48 | 2012-10-11 12:14:25 -0400 | [diff] [blame] | 1879 | __buffer_unlock_commit(buffer, event); |
Steven Rostedt | 4a9bd3f | 2011-07-14 16:36:53 -0400 | [diff] [blame] | 1880 | |
| 1881 | out: |
| 1882 | /* Again, don't let gcc optimize things here */ |
| 1883 | barrier(); |
Shan Wei | 8214652 | 2012-11-19 13:21:01 +0800 | [diff] [blame] | 1884 | __this_cpu_dec(ftrace_stack_reserve); |
Steven Rostedt | 4a9bd3f | 2011-07-14 16:36:53 -0400 | [diff] [blame] | 1885 | preempt_enable_notrace(); |
| 1886 | |
Ingo Molnar | f0a920d | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 1887 | } |
| 1888 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1889 | void ftrace_trace_stack(struct ring_buffer *buffer, unsigned long flags, |
| 1890 | int skip, int pc) |
Steven Rostedt | 5361499 | 2009-01-15 19:12:40 -0500 | [diff] [blame] | 1891 | { |
| 1892 | if (!(trace_flags & TRACE_ITER_STACKTRACE)) |
| 1893 | return; |
| 1894 | |
Masami Hiramatsu | 1fd8df2 | 2011-06-08 16:09:34 +0900 | [diff] [blame] | 1895 | __ftrace_trace_stack(buffer, flags, skip, pc, NULL); |
Steven Rostedt | 5361499 | 2009-01-15 19:12:40 -0500 | [diff] [blame] | 1896 | } |
| 1897 | |
Frederic Weisbecker | c0a0d0d | 2009-07-29 17:51:13 +0200 | [diff] [blame] | 1898 | void __trace_stack(struct trace_array *tr, unsigned long flags, int skip, |
| 1899 | int pc) |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 1900 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1901 | __ftrace_trace_stack(tr->trace_buffer.buffer, flags, skip, pc, NULL); |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 1902 | } |
| 1903 | |
Steven Rostedt | 0388938 | 2009-12-11 09:48:22 -0500 | [diff] [blame] | 1904 | /** |
| 1905 | * trace_dump_stack - record a stack back trace in the trace buffer |
Steven Rostedt (Red Hat) | c142be8 | 2013-03-13 09:55:57 -0400 | [diff] [blame] | 1906 | * @skip: Number of functions to skip (helper handlers) |
Steven Rostedt | 0388938 | 2009-12-11 09:48:22 -0500 | [diff] [blame] | 1907 | */ |
Steven Rostedt (Red Hat) | c142be8 | 2013-03-13 09:55:57 -0400 | [diff] [blame] | 1908 | void trace_dump_stack(int skip) |
Steven Rostedt | 0388938 | 2009-12-11 09:48:22 -0500 | [diff] [blame] | 1909 | { |
| 1910 | unsigned long flags; |
| 1911 | |
| 1912 | if (tracing_disabled || tracing_selftest_running) |
Steven Rostedt | e36c545 | 2009-12-14 15:58:33 -0500 | [diff] [blame] | 1913 | return; |
Steven Rostedt | 0388938 | 2009-12-11 09:48:22 -0500 | [diff] [blame] | 1914 | |
| 1915 | local_save_flags(flags); |
| 1916 | |
Steven Rostedt (Red Hat) | c142be8 | 2013-03-13 09:55:57 -0400 | [diff] [blame] | 1917 | /* |
| 1918 | * Skip 3 more, seems to get us at the caller of |
| 1919 | * this function. |
| 1920 | */ |
| 1921 | skip += 3; |
| 1922 | __ftrace_trace_stack(global_trace.trace_buffer.buffer, |
| 1923 | flags, skip, preempt_count(), NULL); |
Steven Rostedt | 0388938 | 2009-12-11 09:48:22 -0500 | [diff] [blame] | 1924 | } |
| 1925 | |
Steven Rostedt | 91e86e5 | 2010-11-10 12:56:12 +0100 | [diff] [blame] | 1926 | static DEFINE_PER_CPU(int, user_stack_count); |
| 1927 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1928 | void |
| 1929 | 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] | 1930 | { |
Steven Rostedt (Red Hat) | 2425bcb | 2015-05-05 11:45:27 -0400 | [diff] [blame] | 1931 | struct trace_event_call *call = &event_user_stack; |
Török Edwin | 8d7c6a9 | 2008-11-23 12:39:06 +0200 | [diff] [blame] | 1932 | struct ring_buffer_event *event; |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 1933 | struct userstack_entry *entry; |
| 1934 | struct stack_trace trace; |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 1935 | |
| 1936 | if (!(trace_flags & TRACE_ITER_USERSTACKTRACE)) |
| 1937 | return; |
| 1938 | |
Steven Rostedt | b634587 | 2010-03-12 20:03:30 -0500 | [diff] [blame] | 1939 | /* |
| 1940 | * NMIs can not handle page faults, even with fix ups. |
| 1941 | * The save user stack can (and often does) fault. |
| 1942 | */ |
| 1943 | if (unlikely(in_nmi())) |
| 1944 | return; |
| 1945 | |
Steven Rostedt | 91e86e5 | 2010-11-10 12:56:12 +0100 | [diff] [blame] | 1946 | /* |
| 1947 | * prevent recursion, since the user stack tracing may |
| 1948 | * trigger other kernel events. |
| 1949 | */ |
| 1950 | preempt_disable(); |
| 1951 | if (__this_cpu_read(user_stack_count)) |
| 1952 | goto out; |
| 1953 | |
| 1954 | __this_cpu_inc(user_stack_count); |
| 1955 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1956 | event = trace_buffer_lock_reserve(buffer, TRACE_USER_STACK, |
Arnaldo Carvalho de Melo | 51a763d | 2009-02-05 16:14:13 -0200 | [diff] [blame] | 1957 | sizeof(*entry), flags, pc); |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 1958 | if (!event) |
Li Zefan | 1dbd195 | 2010-12-09 15:47:56 +0800 | [diff] [blame] | 1959 | goto out_drop_count; |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 1960 | entry = ring_buffer_event_data(event); |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 1961 | |
Steven Rostedt | 48659d3 | 2009-09-11 11:36:23 -0400 | [diff] [blame] | 1962 | entry->tgid = current->tgid; |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 1963 | memset(&entry->caller, 0, sizeof(entry->caller)); |
| 1964 | |
| 1965 | trace.nr_entries = 0; |
| 1966 | trace.max_entries = FTRACE_STACK_ENTRIES; |
| 1967 | trace.skip = 0; |
| 1968 | trace.entries = entry->caller; |
| 1969 | |
| 1970 | save_stack_trace_user(&trace); |
Tom Zanussi | f306cc8 | 2013-10-24 08:34:17 -0500 | [diff] [blame] | 1971 | if (!call_filter_check_discard(call, entry, buffer, event)) |
Steven Rostedt | 7ffbd48 | 2012-10-11 12:14:25 -0400 | [diff] [blame] | 1972 | __buffer_unlock_commit(buffer, event); |
Steven Rostedt | 91e86e5 | 2010-11-10 12:56:12 +0100 | [diff] [blame] | 1973 | |
Li Zefan | 1dbd195 | 2010-12-09 15:47:56 +0800 | [diff] [blame] | 1974 | out_drop_count: |
Steven Rostedt | 91e86e5 | 2010-11-10 12:56:12 +0100 | [diff] [blame] | 1975 | __this_cpu_dec(user_stack_count); |
Steven Rostedt | 91e86e5 | 2010-11-10 12:56:12 +0100 | [diff] [blame] | 1976 | out: |
| 1977 | preempt_enable(); |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 1978 | } |
| 1979 | |
Hannes Eder | 4fd2735 | 2009-02-10 19:44:12 +0100 | [diff] [blame] | 1980 | #ifdef UNUSED |
| 1981 | 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] | 1982 | { |
Arnaldo Carvalho de Melo | 7be4215 | 2009-02-05 01:13:37 -0500 | [diff] [blame] | 1983 | ftrace_trace_userstack(tr, flags, preempt_count()); |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 1984 | } |
Hannes Eder | 4fd2735 | 2009-02-10 19:44:12 +0100 | [diff] [blame] | 1985 | #endif /* UNUSED */ |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 1986 | |
Frederic Weisbecker | c0a0d0d | 2009-07-29 17:51:13 +0200 | [diff] [blame] | 1987 | #endif /* CONFIG_STACKTRACE */ |
| 1988 | |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 1989 | /* created for use with alloc_percpu */ |
| 1990 | struct trace_buffer_struct { |
| 1991 | char buffer[TRACE_BUF_SIZE]; |
| 1992 | }; |
| 1993 | |
| 1994 | static struct trace_buffer_struct *trace_percpu_buffer; |
| 1995 | static struct trace_buffer_struct *trace_percpu_sirq_buffer; |
| 1996 | static struct trace_buffer_struct *trace_percpu_irq_buffer; |
| 1997 | static struct trace_buffer_struct *trace_percpu_nmi_buffer; |
| 1998 | |
| 1999 | /* |
| 2000 | * The buffer used is dependent on the context. There is a per cpu |
| 2001 | * buffer for normal context, softirq contex, hard irq context and |
| 2002 | * for NMI context. Thise allows for lockless recording. |
| 2003 | * |
| 2004 | * Note, if the buffers failed to be allocated, then this returns NULL |
| 2005 | */ |
| 2006 | static char *get_trace_buf(void) |
| 2007 | { |
| 2008 | struct trace_buffer_struct *percpu_buffer; |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 2009 | |
| 2010 | /* |
| 2011 | * If we have allocated per cpu buffers, then we do not |
| 2012 | * need to do any locking. |
| 2013 | */ |
| 2014 | if (in_nmi()) |
| 2015 | percpu_buffer = trace_percpu_nmi_buffer; |
| 2016 | else if (in_irq()) |
| 2017 | percpu_buffer = trace_percpu_irq_buffer; |
| 2018 | else if (in_softirq()) |
| 2019 | percpu_buffer = trace_percpu_sirq_buffer; |
| 2020 | else |
| 2021 | percpu_buffer = trace_percpu_buffer; |
| 2022 | |
| 2023 | if (!percpu_buffer) |
| 2024 | return NULL; |
| 2025 | |
Shan Wei | d8a0349 | 2012-11-13 09:53:04 +0800 | [diff] [blame] | 2026 | return this_cpu_ptr(&percpu_buffer->buffer[0]); |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 2027 | } |
| 2028 | |
| 2029 | static int alloc_percpu_trace_buffer(void) |
| 2030 | { |
| 2031 | struct trace_buffer_struct *buffers; |
| 2032 | struct trace_buffer_struct *sirq_buffers; |
| 2033 | struct trace_buffer_struct *irq_buffers; |
| 2034 | struct trace_buffer_struct *nmi_buffers; |
| 2035 | |
| 2036 | buffers = alloc_percpu(struct trace_buffer_struct); |
| 2037 | if (!buffers) |
| 2038 | goto err_warn; |
| 2039 | |
| 2040 | sirq_buffers = alloc_percpu(struct trace_buffer_struct); |
| 2041 | if (!sirq_buffers) |
| 2042 | goto err_sirq; |
| 2043 | |
| 2044 | irq_buffers = alloc_percpu(struct trace_buffer_struct); |
| 2045 | if (!irq_buffers) |
| 2046 | goto err_irq; |
| 2047 | |
| 2048 | nmi_buffers = alloc_percpu(struct trace_buffer_struct); |
| 2049 | if (!nmi_buffers) |
| 2050 | goto err_nmi; |
| 2051 | |
| 2052 | trace_percpu_buffer = buffers; |
| 2053 | trace_percpu_sirq_buffer = sirq_buffers; |
| 2054 | trace_percpu_irq_buffer = irq_buffers; |
| 2055 | trace_percpu_nmi_buffer = nmi_buffers; |
| 2056 | |
| 2057 | return 0; |
| 2058 | |
| 2059 | err_nmi: |
| 2060 | free_percpu(irq_buffers); |
| 2061 | err_irq: |
| 2062 | free_percpu(sirq_buffers); |
| 2063 | err_sirq: |
| 2064 | free_percpu(buffers); |
| 2065 | err_warn: |
| 2066 | WARN(1, "Could not allocate percpu trace_printk buffer"); |
| 2067 | return -ENOMEM; |
| 2068 | } |
| 2069 | |
Steven Rostedt | 8169883 | 2012-10-11 10:15:05 -0400 | [diff] [blame] | 2070 | static int buffers_allocated; |
| 2071 | |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 2072 | void trace_printk_init_buffers(void) |
| 2073 | { |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 2074 | if (buffers_allocated) |
| 2075 | return; |
| 2076 | |
| 2077 | if (alloc_percpu_trace_buffer()) |
| 2078 | return; |
| 2079 | |
Steven Rostedt | 2184db4 | 2014-05-28 13:14:40 -0400 | [diff] [blame] | 2080 | /* trace_printk() is for debug use only. Don't use it in production. */ |
| 2081 | |
Borislav Petkov | 69a1c99 | 2015-01-27 17:17:20 +0100 | [diff] [blame] | 2082 | pr_warning("\n"); |
| 2083 | pr_warning("**********************************************************\n"); |
Steven Rostedt | 2184db4 | 2014-05-28 13:14:40 -0400 | [diff] [blame] | 2084 | pr_warning("** NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE **\n"); |
| 2085 | pr_warning("** **\n"); |
| 2086 | pr_warning("** trace_printk() being used. Allocating extra memory. **\n"); |
| 2087 | pr_warning("** **\n"); |
| 2088 | pr_warning("** This means that this is a DEBUG kernel and it is **\n"); |
Frans Klaver | eff264e | 2014-11-07 15:53:44 +0100 | [diff] [blame] | 2089 | pr_warning("** unsafe for production use. **\n"); |
Steven Rostedt | 2184db4 | 2014-05-28 13:14:40 -0400 | [diff] [blame] | 2090 | pr_warning("** **\n"); |
| 2091 | pr_warning("** If you see this message and you are not debugging **\n"); |
| 2092 | pr_warning("** the kernel, report this immediately to your vendor! **\n"); |
| 2093 | pr_warning("** **\n"); |
| 2094 | pr_warning("** NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE **\n"); |
| 2095 | pr_warning("**********************************************************\n"); |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 2096 | |
Steven Rostedt | b382ede6 | 2012-10-10 21:44:34 -0400 | [diff] [blame] | 2097 | /* Expand the buffers to set size */ |
| 2098 | tracing_update_buffers(); |
| 2099 | |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 2100 | buffers_allocated = 1; |
Steven Rostedt | 8169883 | 2012-10-11 10:15:05 -0400 | [diff] [blame] | 2101 | |
| 2102 | /* |
| 2103 | * trace_printk_init_buffers() can be called by modules. |
| 2104 | * If that happens, then we need to start cmdline recording |
| 2105 | * directly here. If the global_trace.buffer is already |
| 2106 | * allocated here, then this was called by module code. |
| 2107 | */ |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2108 | if (global_trace.trace_buffer.buffer) |
Steven Rostedt | 8169883 | 2012-10-11 10:15:05 -0400 | [diff] [blame] | 2109 | tracing_start_cmdline_record(); |
| 2110 | } |
| 2111 | |
| 2112 | void trace_printk_start_comm(void) |
| 2113 | { |
| 2114 | /* Start tracing comms if trace printk is set */ |
| 2115 | if (!buffers_allocated) |
| 2116 | return; |
| 2117 | tracing_start_cmdline_record(); |
| 2118 | } |
| 2119 | |
| 2120 | static void trace_printk_start_stop_comm(int enabled) |
| 2121 | { |
| 2122 | if (!buffers_allocated) |
| 2123 | return; |
| 2124 | |
| 2125 | if (enabled) |
| 2126 | tracing_start_cmdline_record(); |
| 2127 | else |
| 2128 | tracing_stop_cmdline_record(); |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 2129 | } |
| 2130 | |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 2131 | /** |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 2132 | * trace_vbprintk - write binary msg to tracing buffer |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 2133 | * |
| 2134 | */ |
Steven Rostedt | 40ce74f | 2009-03-19 14:03:53 -0400 | [diff] [blame] | 2135 | int trace_vbprintk(unsigned long ip, const char *fmt, va_list args) |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 2136 | { |
Steven Rostedt (Red Hat) | 2425bcb | 2015-05-05 11:45:27 -0400 | [diff] [blame] | 2137 | struct trace_event_call *call = &event_bprint; |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 2138 | struct ring_buffer_event *event; |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 2139 | struct ring_buffer *buffer; |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 2140 | struct trace_array *tr = &global_trace; |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 2141 | struct bprint_entry *entry; |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 2142 | unsigned long flags; |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 2143 | char *tbuffer; |
| 2144 | int len = 0, size, pc; |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 2145 | |
| 2146 | if (unlikely(tracing_selftest_running || tracing_disabled)) |
| 2147 | return 0; |
| 2148 | |
| 2149 | /* Don't pollute graph traces with trace_vprintk internals */ |
| 2150 | pause_graph_tracing(); |
| 2151 | |
| 2152 | pc = preempt_count(); |
Steven Rostedt | 5168ae5 | 2010-06-03 09:36:50 -0400 | [diff] [blame] | 2153 | preempt_disable_notrace(); |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 2154 | |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 2155 | tbuffer = get_trace_buf(); |
| 2156 | if (!tbuffer) { |
| 2157 | len = 0; |
| 2158 | goto out; |
| 2159 | } |
| 2160 | |
| 2161 | len = vbin_printf((u32 *)tbuffer, TRACE_BUF_SIZE/sizeof(int), fmt, args); |
| 2162 | |
| 2163 | if (len > TRACE_BUF_SIZE/sizeof(int) || len < 0) |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 2164 | goto out; |
| 2165 | |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 2166 | local_save_flags(flags); |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 2167 | size = sizeof(*entry) + sizeof(u32) * len; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2168 | buffer = tr->trace_buffer.buffer; |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 2169 | event = trace_buffer_lock_reserve(buffer, TRACE_BPRINT, size, |
| 2170 | flags, pc); |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 2171 | if (!event) |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 2172 | goto out; |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 2173 | entry = ring_buffer_event_data(event); |
| 2174 | entry->ip = ip; |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 2175 | entry->fmt = fmt; |
| 2176 | |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 2177 | memcpy(entry->buf, tbuffer, sizeof(u32) * len); |
Tom Zanussi | f306cc8 | 2013-10-24 08:34:17 -0500 | [diff] [blame] | 2178 | if (!call_filter_check_discard(call, entry, buffer, event)) { |
Steven Rostedt | 7ffbd48 | 2012-10-11 12:14:25 -0400 | [diff] [blame] | 2179 | __buffer_unlock_commit(buffer, event); |
Steven Rostedt | d931369 | 2010-01-06 17:27:11 -0500 | [diff] [blame] | 2180 | ftrace_trace_stack(buffer, flags, 6, pc); |
| 2181 | } |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 2182 | |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 2183 | out: |
Steven Rostedt | 5168ae5 | 2010-06-03 09:36:50 -0400 | [diff] [blame] | 2184 | preempt_enable_notrace(); |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 2185 | unpause_graph_tracing(); |
| 2186 | |
| 2187 | return len; |
| 2188 | } |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 2189 | EXPORT_SYMBOL_GPL(trace_vbprintk); |
| 2190 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2191 | static int |
| 2192 | __trace_array_vprintk(struct ring_buffer *buffer, |
| 2193 | unsigned long ip, const char *fmt, va_list args) |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 2194 | { |
Steven Rostedt (Red Hat) | 2425bcb | 2015-05-05 11:45:27 -0400 | [diff] [blame] | 2195 | struct trace_event_call *call = &event_print; |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 2196 | struct ring_buffer_event *event; |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 2197 | int len = 0, size, pc; |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 2198 | struct print_entry *entry; |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 2199 | unsigned long flags; |
| 2200 | char *tbuffer; |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 2201 | |
| 2202 | if (tracing_disabled || tracing_selftest_running) |
| 2203 | return 0; |
| 2204 | |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 2205 | /* Don't pollute graph traces with trace_vprintk internals */ |
| 2206 | pause_graph_tracing(); |
| 2207 | |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 2208 | pc = preempt_count(); |
| 2209 | preempt_disable_notrace(); |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 2210 | |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 2211 | |
| 2212 | tbuffer = get_trace_buf(); |
| 2213 | if (!tbuffer) { |
| 2214 | len = 0; |
| 2215 | goto out; |
| 2216 | } |
| 2217 | |
Dan Carpenter | 3558a5a | 2014-11-27 18:57:52 +0300 | [diff] [blame] | 2218 | len = vscnprintf(tbuffer, TRACE_BUF_SIZE, fmt, args); |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 2219 | |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 2220 | local_save_flags(flags); |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 2221 | size = sizeof(*entry) + len + 1; |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 2222 | event = trace_buffer_lock_reserve(buffer, TRACE_PRINT, size, |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 2223 | flags, pc); |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 2224 | if (!event) |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 2225 | goto out; |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 2226 | entry = ring_buffer_event_data(event); |
Carsten Emde | c13d2f7 | 2009-11-16 20:56:13 +0100 | [diff] [blame] | 2227 | entry->ip = ip; |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 2228 | |
Dan Carpenter | 3558a5a | 2014-11-27 18:57:52 +0300 | [diff] [blame] | 2229 | memcpy(&entry->buf, tbuffer, len + 1); |
Tom Zanussi | f306cc8 | 2013-10-24 08:34:17 -0500 | [diff] [blame] | 2230 | if (!call_filter_check_discard(call, entry, buffer, event)) { |
Steven Rostedt | 7ffbd48 | 2012-10-11 12:14:25 -0400 | [diff] [blame] | 2231 | __buffer_unlock_commit(buffer, event); |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 2232 | ftrace_trace_stack(buffer, flags, 6, pc); |
Steven Rostedt | d931369 | 2010-01-06 17:27:11 -0500 | [diff] [blame] | 2233 | } |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 2234 | out: |
| 2235 | preempt_enable_notrace(); |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 2236 | unpause_graph_tracing(); |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 2237 | |
| 2238 | return len; |
| 2239 | } |
Steven Rostedt | 659372d | 2009-09-03 19:11:07 -0400 | [diff] [blame] | 2240 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2241 | int trace_array_vprintk(struct trace_array *tr, |
| 2242 | unsigned long ip, const char *fmt, va_list args) |
| 2243 | { |
| 2244 | return __trace_array_vprintk(tr->trace_buffer.buffer, ip, fmt, args); |
| 2245 | } |
| 2246 | |
| 2247 | int trace_array_printk(struct trace_array *tr, |
| 2248 | unsigned long ip, const char *fmt, ...) |
| 2249 | { |
| 2250 | int ret; |
| 2251 | va_list ap; |
| 2252 | |
| 2253 | if (!(trace_flags & TRACE_ITER_PRINTK)) |
| 2254 | return 0; |
| 2255 | |
| 2256 | va_start(ap, fmt); |
| 2257 | ret = trace_array_vprintk(tr, ip, fmt, ap); |
| 2258 | va_end(ap); |
| 2259 | return ret; |
| 2260 | } |
| 2261 | |
| 2262 | int trace_array_printk_buf(struct ring_buffer *buffer, |
| 2263 | unsigned long ip, const char *fmt, ...) |
| 2264 | { |
| 2265 | int ret; |
| 2266 | va_list ap; |
| 2267 | |
| 2268 | if (!(trace_flags & TRACE_ITER_PRINTK)) |
| 2269 | return 0; |
| 2270 | |
| 2271 | va_start(ap, fmt); |
| 2272 | ret = __trace_array_vprintk(buffer, ip, fmt, ap); |
| 2273 | va_end(ap); |
| 2274 | return ret; |
| 2275 | } |
| 2276 | |
Steven Rostedt | 659372d | 2009-09-03 19:11:07 -0400 | [diff] [blame] | 2277 | int trace_vprintk(unsigned long ip, const char *fmt, va_list args) |
| 2278 | { |
Steven Rostedt | a813a15 | 2009-10-09 01:41:35 -0400 | [diff] [blame] | 2279 | return trace_array_vprintk(&global_trace, ip, fmt, args); |
Steven Rostedt | 659372d | 2009-09-03 19:11:07 -0400 | [diff] [blame] | 2280 | } |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 2281 | EXPORT_SYMBOL_GPL(trace_vprintk); |
| 2282 | |
Robert Richter | e2ac8ef | 2008-11-12 12:59:32 +0100 | [diff] [blame] | 2283 | static void trace_iterator_increment(struct trace_iterator *iter) |
Steven Rostedt | 5a90f57 | 2008-09-03 17:42:51 -0400 | [diff] [blame] | 2284 | { |
Steven Rostedt | 6d158a8 | 2012-06-27 20:46:14 -0400 | [diff] [blame] | 2285 | struct ring_buffer_iter *buf_iter = trace_buffer_iter(iter, iter->cpu); |
| 2286 | |
Steven Rostedt | 5a90f57 | 2008-09-03 17:42:51 -0400 | [diff] [blame] | 2287 | iter->idx++; |
Steven Rostedt | 6d158a8 | 2012-06-27 20:46:14 -0400 | [diff] [blame] | 2288 | if (buf_iter) |
| 2289 | ring_buffer_read(buf_iter, NULL); |
Steven Rostedt | 5a90f57 | 2008-09-03 17:42:51 -0400 | [diff] [blame] | 2290 | } |
| 2291 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 2292 | static struct trace_entry * |
Steven Rostedt | bc21b47 | 2010-03-31 19:49:26 -0400 | [diff] [blame] | 2293 | peek_next_entry(struct trace_iterator *iter, int cpu, u64 *ts, |
| 2294 | unsigned long *lost_events) |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2295 | { |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2296 | struct ring_buffer_event *event; |
Steven Rostedt | 6d158a8 | 2012-06-27 20:46:14 -0400 | [diff] [blame] | 2297 | struct ring_buffer_iter *buf_iter = trace_buffer_iter(iter, cpu); |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2298 | |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 2299 | if (buf_iter) |
| 2300 | event = ring_buffer_iter_peek(buf_iter, ts); |
| 2301 | else |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2302 | event = ring_buffer_peek(iter->trace_buffer->buffer, cpu, ts, |
Steven Rostedt | bc21b47 | 2010-03-31 19:49:26 -0400 | [diff] [blame] | 2303 | lost_events); |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 2304 | |
Steven Rostedt | 4a9bd3f | 2011-07-14 16:36:53 -0400 | [diff] [blame] | 2305 | if (event) { |
| 2306 | iter->ent_size = ring_buffer_event_length(event); |
| 2307 | return ring_buffer_event_data(event); |
| 2308 | } |
| 2309 | iter->ent_size = 0; |
| 2310 | return NULL; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2311 | } |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 2312 | |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2313 | static struct trace_entry * |
Steven Rostedt | bc21b47 | 2010-03-31 19:49:26 -0400 | [diff] [blame] | 2314 | __find_next_entry(struct trace_iterator *iter, int *ent_cpu, |
| 2315 | unsigned long *missing_events, u64 *ent_ts) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2316 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2317 | struct ring_buffer *buffer = iter->trace_buffer->buffer; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2318 | struct trace_entry *ent, *next = NULL; |
Lai Jiangshan | aa27497 | 2010-04-05 17:11:05 +0800 | [diff] [blame] | 2319 | unsigned long lost_events = 0, next_lost = 0; |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 2320 | int cpu_file = iter->cpu_file; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2321 | u64 next_ts = 0, ts; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2322 | int next_cpu = -1; |
Steven Rostedt | 12b5da3 | 2012-03-27 10:43:28 -0400 | [diff] [blame] | 2323 | int next_size = 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2324 | int cpu; |
| 2325 | |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 2326 | /* |
| 2327 | * If we are in a per_cpu trace file, don't bother by iterating over |
| 2328 | * all cpu and peek directly. |
| 2329 | */ |
Steven Rostedt | ae3b509 | 2013-01-23 15:22:59 -0500 | [diff] [blame] | 2330 | if (cpu_file > RING_BUFFER_ALL_CPUS) { |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 2331 | if (ring_buffer_empty_cpu(buffer, cpu_file)) |
| 2332 | return NULL; |
Steven Rostedt | bc21b47 | 2010-03-31 19:49:26 -0400 | [diff] [blame] | 2333 | ent = peek_next_entry(iter, cpu_file, ent_ts, missing_events); |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 2334 | if (ent_cpu) |
| 2335 | *ent_cpu = cpu_file; |
| 2336 | |
| 2337 | return ent; |
| 2338 | } |
| 2339 | |
Steven Rostedt | ab46428 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 2340 | for_each_tracing_cpu(cpu) { |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2341 | |
| 2342 | if (ring_buffer_empty_cpu(buffer, cpu)) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2343 | continue; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2344 | |
Steven Rostedt | bc21b47 | 2010-03-31 19:49:26 -0400 | [diff] [blame] | 2345 | ent = peek_next_entry(iter, cpu, &ts, &lost_events); |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2346 | |
Ingo Molnar | cdd31cd2 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2347 | /* |
| 2348 | * Pick the entry with the smallest timestamp: |
| 2349 | */ |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2350 | if (ent && (!next || ts < next_ts)) { |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2351 | next = ent; |
| 2352 | next_cpu = cpu; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2353 | next_ts = ts; |
Steven Rostedt | bc21b47 | 2010-03-31 19:49:26 -0400 | [diff] [blame] | 2354 | next_lost = lost_events; |
Steven Rostedt | 12b5da3 | 2012-03-27 10:43:28 -0400 | [diff] [blame] | 2355 | next_size = iter->ent_size; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2356 | } |
| 2357 | } |
| 2358 | |
Steven Rostedt | 12b5da3 | 2012-03-27 10:43:28 -0400 | [diff] [blame] | 2359 | iter->ent_size = next_size; |
| 2360 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2361 | if (ent_cpu) |
| 2362 | *ent_cpu = next_cpu; |
| 2363 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2364 | if (ent_ts) |
| 2365 | *ent_ts = next_ts; |
| 2366 | |
Steven Rostedt | bc21b47 | 2010-03-31 19:49:26 -0400 | [diff] [blame] | 2367 | if (missing_events) |
| 2368 | *missing_events = next_lost; |
| 2369 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2370 | return next; |
| 2371 | } |
| 2372 | |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2373 | /* Find the next real entry, without updating the iterator itself */ |
Frederic Weisbecker | c4a8e8b | 2009-02-02 20:29:21 -0200 | [diff] [blame] | 2374 | struct trace_entry *trace_find_next_entry(struct trace_iterator *iter, |
| 2375 | int *ent_cpu, u64 *ent_ts) |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2376 | { |
Steven Rostedt | bc21b47 | 2010-03-31 19:49:26 -0400 | [diff] [blame] | 2377 | return __find_next_entry(iter, ent_cpu, NULL, ent_ts); |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2378 | } |
Ingo Molnar | 8c523a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2379 | |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2380 | /* 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] | 2381 | void *trace_find_next_entry_inc(struct trace_iterator *iter) |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2382 | { |
Steven Rostedt | bc21b47 | 2010-03-31 19:49:26 -0400 | [diff] [blame] | 2383 | iter->ent = __find_next_entry(iter, &iter->cpu, |
| 2384 | &iter->lost_events, &iter->ts); |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2385 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2386 | if (iter->ent) |
Robert Richter | e2ac8ef | 2008-11-12 12:59:32 +0100 | [diff] [blame] | 2387 | trace_iterator_increment(iter); |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2388 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2389 | return iter->ent ? iter : NULL; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2390 | } |
| 2391 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 2392 | static void trace_consume(struct trace_iterator *iter) |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2393 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2394 | ring_buffer_consume(iter->trace_buffer->buffer, iter->cpu, &iter->ts, |
Steven Rostedt | bc21b47 | 2010-03-31 19:49:26 -0400 | [diff] [blame] | 2395 | &iter->lost_events); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2396 | } |
| 2397 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 2398 | 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] | 2399 | { |
| 2400 | struct trace_iterator *iter = m->private; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2401 | int i = (int)*pos; |
Ingo Molnar | 4e3c333 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 2402 | void *ent; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2403 | |
Steven Rostedt | a63ce5b | 2009-12-07 09:11:39 -0500 | [diff] [blame] | 2404 | WARN_ON_ONCE(iter->leftover); |
| 2405 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2406 | (*pos)++; |
| 2407 | |
| 2408 | /* can't go backwards */ |
| 2409 | if (iter->idx > i) |
| 2410 | return NULL; |
| 2411 | |
| 2412 | if (iter->idx < 0) |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 2413 | ent = trace_find_next_entry_inc(iter); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2414 | else |
| 2415 | ent = iter; |
| 2416 | |
| 2417 | while (ent && iter->idx < i) |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 2418 | ent = trace_find_next_entry_inc(iter); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2419 | |
| 2420 | iter->pos = *pos; |
| 2421 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2422 | return ent; |
| 2423 | } |
| 2424 | |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 2425 | void tracing_iter_reset(struct trace_iterator *iter, int cpu) |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 2426 | { |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 2427 | struct ring_buffer_event *event; |
| 2428 | struct ring_buffer_iter *buf_iter; |
| 2429 | unsigned long entries = 0; |
| 2430 | u64 ts; |
| 2431 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2432 | per_cpu_ptr(iter->trace_buffer->data, cpu)->skipped_entries = 0; |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 2433 | |
Steven Rostedt | 6d158a8 | 2012-06-27 20:46:14 -0400 | [diff] [blame] | 2434 | buf_iter = trace_buffer_iter(iter, cpu); |
| 2435 | if (!buf_iter) |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 2436 | return; |
| 2437 | |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 2438 | ring_buffer_iter_reset(buf_iter); |
| 2439 | |
| 2440 | /* |
| 2441 | * We could have the case with the max latency tracers |
| 2442 | * that a reset never took place on a cpu. This is evident |
| 2443 | * by the timestamp being before the start of the buffer. |
| 2444 | */ |
| 2445 | while ((event = ring_buffer_iter_peek(buf_iter, &ts))) { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2446 | if (ts >= iter->trace_buffer->time_start) |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 2447 | break; |
| 2448 | entries++; |
| 2449 | ring_buffer_read(buf_iter, NULL); |
| 2450 | } |
| 2451 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2452 | per_cpu_ptr(iter->trace_buffer->data, cpu)->skipped_entries = entries; |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 2453 | } |
| 2454 | |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 2455 | /* |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 2456 | * The current tracer is copied to avoid a global locking |
| 2457 | * all around. |
| 2458 | */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2459 | static void *s_start(struct seq_file *m, loff_t *pos) |
| 2460 | { |
| 2461 | struct trace_iterator *iter = m->private; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 2462 | struct trace_array *tr = iter->tr; |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 2463 | int cpu_file = iter->cpu_file; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2464 | void *p = NULL; |
| 2465 | loff_t l = 0; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2466 | int cpu; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2467 | |
Hiraku Toyooka | 2fd196e | 2012-12-26 11:52:52 +0900 | [diff] [blame] | 2468 | /* |
| 2469 | * copy the tracer to avoid using a global lock all around. |
| 2470 | * iter->trace is a copy of current_trace, the pointer to the |
| 2471 | * name may be used instead of a strcmp(), as iter->trace->name |
| 2472 | * will point to the same string as current_trace->name. |
| 2473 | */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2474 | mutex_lock(&trace_types_lock); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 2475 | if (unlikely(tr->current_trace && iter->trace->name != tr->current_trace->name)) |
| 2476 | *iter->trace = *tr->current_trace; |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 2477 | mutex_unlock(&trace_types_lock); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2478 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2479 | #ifdef CONFIG_TRACER_MAX_TRACE |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 2480 | if (iter->snapshot && iter->trace->use_max_tr) |
| 2481 | return ERR_PTR(-EBUSY); |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2482 | #endif |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 2483 | |
| 2484 | if (!iter->snapshot) |
| 2485 | atomic_inc(&trace_record_cmdline_disabled); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2486 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2487 | if (*pos != iter->pos) { |
| 2488 | iter->ent = NULL; |
| 2489 | iter->cpu = 0; |
| 2490 | iter->idx = -1; |
| 2491 | |
Steven Rostedt | ae3b509 | 2013-01-23 15:22:59 -0500 | [diff] [blame] | 2492 | if (cpu_file == RING_BUFFER_ALL_CPUS) { |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 2493 | for_each_tracing_cpu(cpu) |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 2494 | tracing_iter_reset(iter, cpu); |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 2495 | } else |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 2496 | tracing_iter_reset(iter, cpu_file); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2497 | |
Lai Jiangshan | ac91d85 | 2010-03-02 17:54:50 +0800 | [diff] [blame] | 2498 | iter->leftover = 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2499 | for (p = iter; p && l < *pos; p = s_next(m, p, &l)) |
| 2500 | ; |
| 2501 | |
| 2502 | } else { |
Steven Rostedt | a63ce5b | 2009-12-07 09:11:39 -0500 | [diff] [blame] | 2503 | /* |
| 2504 | * If we overflowed the seq_file before, then we want |
| 2505 | * to just reuse the trace_seq buffer again. |
| 2506 | */ |
| 2507 | if (iter->leftover) |
| 2508 | p = iter; |
| 2509 | else { |
| 2510 | l = *pos - 1; |
| 2511 | p = s_next(m, p, &l); |
| 2512 | } |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2513 | } |
| 2514 | |
Lai Jiangshan | 4f53596 | 2009-05-18 19:35:34 +0800 | [diff] [blame] | 2515 | trace_event_read_lock(); |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 2516 | trace_access_lock(cpu_file); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2517 | return p; |
| 2518 | } |
| 2519 | |
| 2520 | static void s_stop(struct seq_file *m, void *p) |
| 2521 | { |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 2522 | struct trace_iterator *iter = m->private; |
| 2523 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2524 | #ifdef CONFIG_TRACER_MAX_TRACE |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 2525 | if (iter->snapshot && iter->trace->use_max_tr) |
| 2526 | return; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2527 | #endif |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 2528 | |
| 2529 | if (!iter->snapshot) |
| 2530 | atomic_dec(&trace_record_cmdline_disabled); |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2531 | |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 2532 | trace_access_unlock(iter->cpu_file); |
Lai Jiangshan | 4f53596 | 2009-05-18 19:35:34 +0800 | [diff] [blame] | 2533 | trace_event_read_unlock(); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2534 | } |
| 2535 | |
Steven Rostedt | 39eaf7e | 2011-11-17 10:35:16 -0500 | [diff] [blame] | 2536 | static void |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2537 | get_total_entries(struct trace_buffer *buf, |
| 2538 | unsigned long *total, unsigned long *entries) |
Steven Rostedt | 39eaf7e | 2011-11-17 10:35:16 -0500 | [diff] [blame] | 2539 | { |
| 2540 | unsigned long count; |
| 2541 | int cpu; |
| 2542 | |
| 2543 | *total = 0; |
| 2544 | *entries = 0; |
| 2545 | |
| 2546 | for_each_tracing_cpu(cpu) { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2547 | count = ring_buffer_entries_cpu(buf->buffer, cpu); |
Steven Rostedt | 39eaf7e | 2011-11-17 10:35:16 -0500 | [diff] [blame] | 2548 | /* |
| 2549 | * If this buffer has skipped entries, then we hold all |
| 2550 | * entries for the trace and we need to ignore the |
| 2551 | * ones before the time stamp. |
| 2552 | */ |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2553 | if (per_cpu_ptr(buf->data, cpu)->skipped_entries) { |
| 2554 | count -= per_cpu_ptr(buf->data, cpu)->skipped_entries; |
Steven Rostedt | 39eaf7e | 2011-11-17 10:35:16 -0500 | [diff] [blame] | 2555 | /* total is the same as the entries */ |
| 2556 | *total += count; |
| 2557 | } else |
| 2558 | *total += count + |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2559 | ring_buffer_overrun_cpu(buf->buffer, cpu); |
Steven Rostedt | 39eaf7e | 2011-11-17 10:35:16 -0500 | [diff] [blame] | 2560 | *entries += count; |
| 2561 | } |
| 2562 | } |
| 2563 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 2564 | static void print_lat_help_header(struct seq_file *m) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2565 | { |
Rasmus Villemoes | d79ac28 | 2014-11-08 21:42:11 +0100 | [diff] [blame] | 2566 | seq_puts(m, "# _------=> CPU# \n" |
| 2567 | "# / _-----=> irqs-off \n" |
| 2568 | "# | / _----=> need-resched \n" |
| 2569 | "# || / _---=> hardirq/softirq \n" |
| 2570 | "# ||| / _--=> preempt-depth \n" |
| 2571 | "# |||| / delay \n" |
| 2572 | "# cmd pid ||||| time | caller \n" |
| 2573 | "# \\ / ||||| \\ | / \n"); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2574 | } |
| 2575 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2576 | 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] | 2577 | { |
Steven Rostedt | 39eaf7e | 2011-11-17 10:35:16 -0500 | [diff] [blame] | 2578 | unsigned long total; |
| 2579 | unsigned long entries; |
| 2580 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2581 | get_total_entries(buf, &total, &entries); |
Steven Rostedt | 39eaf7e | 2011-11-17 10:35:16 -0500 | [diff] [blame] | 2582 | seq_printf(m, "# entries-in-buffer/entries-written: %lu/%lu #P:%d\n", |
| 2583 | entries, total, num_online_cpus()); |
| 2584 | seq_puts(m, "#\n"); |
| 2585 | } |
| 2586 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2587 | 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] | 2588 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2589 | print_event_info(buf, m); |
Rasmus Villemoes | d79ac28 | 2014-11-08 21:42:11 +0100 | [diff] [blame] | 2590 | seq_puts(m, "# TASK-PID CPU# TIMESTAMP FUNCTION\n" |
| 2591 | "# | | | | |\n"); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2592 | } |
| 2593 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2594 | 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] | 2595 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2596 | print_event_info(buf, m); |
Rasmus Villemoes | d79ac28 | 2014-11-08 21:42:11 +0100 | [diff] [blame] | 2597 | seq_puts(m, "# _-----=> irqs-off\n" |
| 2598 | "# / _----=> need-resched\n" |
| 2599 | "# | / _---=> hardirq/softirq\n" |
| 2600 | "# || / _--=> preempt-depth\n" |
| 2601 | "# ||| / delay\n" |
| 2602 | "# TASK-PID CPU# |||| TIMESTAMP FUNCTION\n" |
| 2603 | "# | | | |||| | |\n"); |
Steven Rostedt | 77271ce | 2011-11-17 09:34:33 -0500 | [diff] [blame] | 2604 | } |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2605 | |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 2606 | void |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2607 | print_trace_header(struct seq_file *m, struct trace_iterator *iter) |
| 2608 | { |
| 2609 | unsigned long sym_flags = (trace_flags & TRACE_ITER_SYM_MASK); |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2610 | struct trace_buffer *buf = iter->trace_buffer; |
| 2611 | struct trace_array_cpu *data = per_cpu_ptr(buf->data, buf->cpu); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 2612 | struct tracer *type = iter->trace; |
Steven Rostedt | 39eaf7e | 2011-11-17 10:35:16 -0500 | [diff] [blame] | 2613 | unsigned long entries; |
| 2614 | unsigned long total; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2615 | const char *name = "preemption"; |
| 2616 | |
Steven Rostedt (Red Hat) | d840f71 | 2013-02-01 18:38:47 -0500 | [diff] [blame] | 2617 | name = type->name; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2618 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2619 | get_total_entries(buf, &total, &entries); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2620 | |
KOSAKI Motohiro | 888b55d | 2009-03-08 13:12:43 +0900 | [diff] [blame] | 2621 | seq_printf(m, "# %s latency trace v1.1.5 on %s\n", |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2622 | name, UTS_RELEASE); |
KOSAKI Motohiro | 888b55d | 2009-03-08 13:12:43 +0900 | [diff] [blame] | 2623 | seq_puts(m, "# -----------------------------------" |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2624 | "---------------------------------\n"); |
KOSAKI Motohiro | 888b55d | 2009-03-08 13:12:43 +0900 | [diff] [blame] | 2625 | seq_printf(m, "# latency: %lu us, #%lu/%lu, CPU#%d |" |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2626 | " (M:%s VP:%d, KP:%d, SP:%d HP:%d", |
Steven Rostedt | 57f50be | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 2627 | nsecs_to_usecs(data->saved_latency), |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2628 | entries, |
Steven Rostedt | 4c11d7a | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 2629 | total, |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2630 | buf->cpu, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2631 | #if defined(CONFIG_PREEMPT_NONE) |
| 2632 | "server", |
| 2633 | #elif defined(CONFIG_PREEMPT_VOLUNTARY) |
| 2634 | "desktop", |
Steven Rostedt | b5c21b4 | 2008-07-10 20:58:12 -0400 | [diff] [blame] | 2635 | #elif defined(CONFIG_PREEMPT) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2636 | "preempt", |
| 2637 | #else |
| 2638 | "unknown", |
| 2639 | #endif |
| 2640 | /* These are reserved for later use */ |
| 2641 | 0, 0, 0, 0); |
| 2642 | #ifdef CONFIG_SMP |
| 2643 | seq_printf(m, " #P:%d)\n", num_online_cpus()); |
| 2644 | #else |
| 2645 | seq_puts(m, ")\n"); |
| 2646 | #endif |
KOSAKI Motohiro | 888b55d | 2009-03-08 13:12:43 +0900 | [diff] [blame] | 2647 | seq_puts(m, "# -----------------\n"); |
| 2648 | seq_printf(m, "# | task: %.16s-%d " |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2649 | "(uid:%d nice:%ld policy:%ld rt_prio:%ld)\n", |
Eric W. Biederman | d20b92a | 2012-03-13 16:02:19 -0700 | [diff] [blame] | 2650 | data->comm, data->pid, |
| 2651 | from_kuid_munged(seq_user_ns(m), data->uid), data->nice, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2652 | data->policy, data->rt_priority); |
KOSAKI Motohiro | 888b55d | 2009-03-08 13:12:43 +0900 | [diff] [blame] | 2653 | seq_puts(m, "# -----------------\n"); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2654 | |
| 2655 | if (data->critical_start) { |
KOSAKI Motohiro | 888b55d | 2009-03-08 13:12:43 +0900 | [diff] [blame] | 2656 | seq_puts(m, "# => started at: "); |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2657 | seq_print_ip_sym(&iter->seq, data->critical_start, sym_flags); |
| 2658 | trace_print_seq(m, &iter->seq); |
KOSAKI Motohiro | 888b55d | 2009-03-08 13:12:43 +0900 | [diff] [blame] | 2659 | seq_puts(m, "\n# => ended at: "); |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2660 | seq_print_ip_sym(&iter->seq, data->critical_end, sym_flags); |
| 2661 | trace_print_seq(m, &iter->seq); |
Steven Rostedt | 8248ac0 | 2009-09-02 12:27:41 -0400 | [diff] [blame] | 2662 | seq_puts(m, "\n#\n"); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2663 | } |
| 2664 | |
KOSAKI Motohiro | 888b55d | 2009-03-08 13:12:43 +0900 | [diff] [blame] | 2665 | seq_puts(m, "#\n"); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2666 | } |
| 2667 | |
Steven Rostedt | a309720 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 2668 | static void test_cpu_buff_start(struct trace_iterator *iter) |
| 2669 | { |
| 2670 | struct trace_seq *s = &iter->seq; |
| 2671 | |
Steven Rostedt | 12ef7d4 | 2008-11-12 17:52:38 -0500 | [diff] [blame] | 2672 | if (!(trace_flags & TRACE_ITER_ANNOTATE)) |
| 2673 | return; |
| 2674 | |
| 2675 | if (!(iter->iter_flags & TRACE_FILE_ANNOTATE)) |
| 2676 | return; |
| 2677 | |
Rusty Russell | 4462344 | 2009-01-01 10:12:23 +1030 | [diff] [blame] | 2678 | if (cpumask_test_cpu(iter->cpu, iter->started)) |
Steven Rostedt | a309720 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 2679 | return; |
| 2680 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2681 | if (per_cpu_ptr(iter->trace_buffer->data, iter->cpu)->skipped_entries) |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 2682 | return; |
| 2683 | |
Rusty Russell | 4462344 | 2009-01-01 10:12:23 +1030 | [diff] [blame] | 2684 | cpumask_set_cpu(iter->cpu, iter->started); |
Frederic Weisbecker | b0dfa97 | 2009-04-01 22:53:08 +0200 | [diff] [blame] | 2685 | |
| 2686 | /* Don't print started cpu buffer for the first entry of the trace */ |
| 2687 | if (iter->idx > 1) |
| 2688 | trace_seq_printf(s, "##### CPU %u buffer started ####\n", |
| 2689 | iter->cpu); |
Steven Rostedt | a309720 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 2690 | } |
| 2691 | |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 2692 | static enum print_line_t print_trace_fmt(struct trace_iterator *iter) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2693 | { |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2694 | struct trace_seq *s = &iter->seq; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2695 | unsigned long sym_flags = (trace_flags & TRACE_ITER_SYM_MASK); |
Ingo Molnar | 4e3c333 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 2696 | struct trace_entry *entry; |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 2697 | struct trace_event *event; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2698 | |
Ingo Molnar | 4e3c333 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 2699 | entry = iter->ent; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2700 | |
Steven Rostedt | a309720 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 2701 | test_cpu_buff_start(iter); |
| 2702 | |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 2703 | event = ftrace_find_event(entry->type); |
Frederic Weisbecker | c4a8e8b | 2009-02-02 20:29:21 -0200 | [diff] [blame] | 2704 | |
| 2705 | if (trace_flags & TRACE_ITER_CONTEXT_INFO) { |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame] | 2706 | if (iter->iter_flags & TRACE_FILE_LAT_FMT) |
| 2707 | trace_print_lat_context(iter); |
| 2708 | else |
| 2709 | trace_print_context(iter); |
Frederic Weisbecker | c4a8e8b | 2009-02-02 20:29:21 -0200 | [diff] [blame] | 2710 | } |
| 2711 | |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame] | 2712 | if (trace_seq_has_overflowed(s)) |
| 2713 | return TRACE_TYPE_PARTIAL_LINE; |
| 2714 | |
Arnaldo Carvalho de Melo | 268ccda | 2009-02-04 20:16:39 -0200 | [diff] [blame] | 2715 | if (event) |
Steven Rostedt | a9a5776 | 2010-04-22 18:46:14 -0400 | [diff] [blame] | 2716 | return event->funcs->trace(iter, sym_flags, event); |
Arnaldo Carvalho de Melo | d9793bd | 2009-02-03 20:20:41 -0200 | [diff] [blame] | 2717 | |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame] | 2718 | trace_seq_printf(s, "Unknown type %d\n", entry->type); |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 2719 | |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame] | 2720 | return trace_handle_return(s); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2721 | } |
| 2722 | |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 2723 | static enum print_line_t print_raw_fmt(struct trace_iterator *iter) |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2724 | { |
| 2725 | struct trace_seq *s = &iter->seq; |
| 2726 | struct trace_entry *entry; |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 2727 | struct trace_event *event; |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2728 | |
| 2729 | entry = iter->ent; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2730 | |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame] | 2731 | if (trace_flags & TRACE_ITER_CONTEXT_INFO) |
| 2732 | trace_seq_printf(s, "%d %d %llu ", |
| 2733 | entry->pid, iter->cpu, iter->ts); |
| 2734 | |
| 2735 | if (trace_seq_has_overflowed(s)) |
| 2736 | return TRACE_TYPE_PARTIAL_LINE; |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2737 | |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 2738 | event = ftrace_find_event(entry->type); |
Arnaldo Carvalho de Melo | 268ccda | 2009-02-04 20:16:39 -0200 | [diff] [blame] | 2739 | if (event) |
Steven Rostedt | a9a5776 | 2010-04-22 18:46:14 -0400 | [diff] [blame] | 2740 | return event->funcs->raw(iter, 0, event); |
Arnaldo Carvalho de Melo | d9793bd | 2009-02-03 20:20:41 -0200 | [diff] [blame] | 2741 | |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame] | 2742 | trace_seq_printf(s, "%d ?\n", entry->type); |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 2743 | |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame] | 2744 | return trace_handle_return(s); |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2745 | } |
| 2746 | |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 2747 | static enum print_line_t print_hex_fmt(struct trace_iterator *iter) |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 2748 | { |
| 2749 | struct trace_seq *s = &iter->seq; |
| 2750 | unsigned char newline = '\n'; |
| 2751 | struct trace_entry *entry; |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 2752 | struct trace_event *event; |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 2753 | |
| 2754 | entry = iter->ent; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2755 | |
Frederic Weisbecker | c4a8e8b | 2009-02-02 20:29:21 -0200 | [diff] [blame] | 2756 | if (trace_flags & TRACE_ITER_CONTEXT_INFO) { |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame] | 2757 | SEQ_PUT_HEX_FIELD(s, entry->pid); |
| 2758 | SEQ_PUT_HEX_FIELD(s, iter->cpu); |
| 2759 | SEQ_PUT_HEX_FIELD(s, iter->ts); |
| 2760 | if (trace_seq_has_overflowed(s)) |
| 2761 | return TRACE_TYPE_PARTIAL_LINE; |
Frederic Weisbecker | c4a8e8b | 2009-02-02 20:29:21 -0200 | [diff] [blame] | 2762 | } |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 2763 | |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 2764 | event = ftrace_find_event(entry->type); |
Arnaldo Carvalho de Melo | 268ccda | 2009-02-04 20:16:39 -0200 | [diff] [blame] | 2765 | if (event) { |
Steven Rostedt | a9a5776 | 2010-04-22 18:46:14 -0400 | [diff] [blame] | 2766 | 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] | 2767 | if (ret != TRACE_TYPE_HANDLED) |
| 2768 | return ret; |
| 2769 | } |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 2770 | |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame] | 2771 | SEQ_PUT_FIELD(s, newline); |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 2772 | |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame] | 2773 | return trace_handle_return(s); |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 2774 | } |
| 2775 | |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 2776 | static enum print_line_t print_bin_fmt(struct trace_iterator *iter) |
Ingo Molnar | cb0f12a | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2777 | { |
| 2778 | struct trace_seq *s = &iter->seq; |
| 2779 | struct trace_entry *entry; |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 2780 | struct trace_event *event; |
Ingo Molnar | cb0f12a | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2781 | |
| 2782 | entry = iter->ent; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2783 | |
Frederic Weisbecker | c4a8e8b | 2009-02-02 20:29:21 -0200 | [diff] [blame] | 2784 | if (trace_flags & TRACE_ITER_CONTEXT_INFO) { |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame] | 2785 | SEQ_PUT_FIELD(s, entry->pid); |
| 2786 | SEQ_PUT_FIELD(s, iter->cpu); |
| 2787 | SEQ_PUT_FIELD(s, iter->ts); |
| 2788 | if (trace_seq_has_overflowed(s)) |
| 2789 | return TRACE_TYPE_PARTIAL_LINE; |
Frederic Weisbecker | c4a8e8b | 2009-02-02 20:29:21 -0200 | [diff] [blame] | 2790 | } |
Ingo Molnar | cb0f12a | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2791 | |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 2792 | event = ftrace_find_event(entry->type); |
Steven Rostedt | a9a5776 | 2010-04-22 18:46:14 -0400 | [diff] [blame] | 2793 | return event ? event->funcs->binary(iter, 0, event) : |
| 2794 | TRACE_TYPE_HANDLED; |
Ingo Molnar | cb0f12a | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2795 | } |
| 2796 | |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 2797 | int trace_empty(struct trace_iterator *iter) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2798 | { |
Steven Rostedt | 6d158a8 | 2012-06-27 20:46:14 -0400 | [diff] [blame] | 2799 | struct ring_buffer_iter *buf_iter; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2800 | int cpu; |
| 2801 | |
Steven Rostedt | 9aba60f | 2009-03-11 19:52:30 -0400 | [diff] [blame] | 2802 | /* If we are looking at one CPU buffer, only check that one */ |
Steven Rostedt | ae3b509 | 2013-01-23 15:22:59 -0500 | [diff] [blame] | 2803 | if (iter->cpu_file != RING_BUFFER_ALL_CPUS) { |
Steven Rostedt | 9aba60f | 2009-03-11 19:52:30 -0400 | [diff] [blame] | 2804 | cpu = iter->cpu_file; |
Steven Rostedt | 6d158a8 | 2012-06-27 20:46:14 -0400 | [diff] [blame] | 2805 | buf_iter = trace_buffer_iter(iter, cpu); |
| 2806 | if (buf_iter) { |
| 2807 | if (!ring_buffer_iter_empty(buf_iter)) |
Steven Rostedt | 9aba60f | 2009-03-11 19:52:30 -0400 | [diff] [blame] | 2808 | return 0; |
| 2809 | } else { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2810 | if (!ring_buffer_empty_cpu(iter->trace_buffer->buffer, cpu)) |
Steven Rostedt | 9aba60f | 2009-03-11 19:52:30 -0400 | [diff] [blame] | 2811 | return 0; |
| 2812 | } |
| 2813 | return 1; |
| 2814 | } |
| 2815 | |
Steven Rostedt | ab46428 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 2816 | for_each_tracing_cpu(cpu) { |
Steven Rostedt | 6d158a8 | 2012-06-27 20:46:14 -0400 | [diff] [blame] | 2817 | buf_iter = trace_buffer_iter(iter, cpu); |
| 2818 | if (buf_iter) { |
| 2819 | if (!ring_buffer_iter_empty(buf_iter)) |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 2820 | return 0; |
| 2821 | } else { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2822 | if (!ring_buffer_empty_cpu(iter->trace_buffer->buffer, cpu)) |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 2823 | return 0; |
| 2824 | } |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2825 | } |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 2826 | |
Frederic Weisbecker | 797d371 | 2008-09-30 18:13:45 +0200 | [diff] [blame] | 2827 | return 1; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2828 | } |
| 2829 | |
Lai Jiangshan | 4f53596 | 2009-05-18 19:35:34 +0800 | [diff] [blame] | 2830 | /* Called with trace_event_read_lock() held. */ |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 2831 | enum print_line_t print_trace_line(struct trace_iterator *iter) |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2832 | { |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 2833 | enum print_line_t ret; |
| 2834 | |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame] | 2835 | if (iter->lost_events) { |
| 2836 | trace_seq_printf(&iter->seq, "CPU:%d [LOST %lu EVENTS]\n", |
| 2837 | iter->cpu, iter->lost_events); |
| 2838 | if (trace_seq_has_overflowed(&iter->seq)) |
| 2839 | return TRACE_TYPE_PARTIAL_LINE; |
| 2840 | } |
Steven Rostedt | bc21b47 | 2010-03-31 19:49:26 -0400 | [diff] [blame] | 2841 | |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 2842 | if (iter->trace && iter->trace->print_line) { |
| 2843 | ret = iter->trace->print_line(iter); |
| 2844 | if (ret != TRACE_TYPE_UNHANDLED) |
| 2845 | return ret; |
| 2846 | } |
Thomas Gleixner | 72829bc | 2008-05-23 21:37:28 +0200 | [diff] [blame] | 2847 | |
Steven Rostedt (Red Hat) | 09ae723 | 2013-03-08 21:02:34 -0500 | [diff] [blame] | 2848 | if (iter->ent->type == TRACE_BPUTS && |
| 2849 | trace_flags & TRACE_ITER_PRINTK && |
| 2850 | trace_flags & TRACE_ITER_PRINTK_MSGONLY) |
| 2851 | return trace_print_bputs_msg_only(iter); |
| 2852 | |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 2853 | if (iter->ent->type == TRACE_BPRINT && |
| 2854 | trace_flags & TRACE_ITER_PRINTK && |
| 2855 | trace_flags & TRACE_ITER_PRINTK_MSGONLY) |
Steven Rostedt | 5ef841f | 2009-03-19 12:20:38 -0400 | [diff] [blame] | 2856 | return trace_print_bprintk_msg_only(iter); |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 2857 | |
Frederic Weisbecker | 66896a8 | 2008-12-13 20:18:13 +0100 | [diff] [blame] | 2858 | if (iter->ent->type == TRACE_PRINT && |
| 2859 | trace_flags & TRACE_ITER_PRINTK && |
| 2860 | trace_flags & TRACE_ITER_PRINTK_MSGONLY) |
Steven Rostedt | 5ef841f | 2009-03-19 12:20:38 -0400 | [diff] [blame] | 2861 | return trace_print_printk_msg_only(iter); |
Frederic Weisbecker | 66896a8 | 2008-12-13 20:18:13 +0100 | [diff] [blame] | 2862 | |
Ingo Molnar | cb0f12a | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2863 | if (trace_flags & TRACE_ITER_BIN) |
| 2864 | return print_bin_fmt(iter); |
| 2865 | |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 2866 | if (trace_flags & TRACE_ITER_HEX) |
| 2867 | return print_hex_fmt(iter); |
| 2868 | |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2869 | if (trace_flags & TRACE_ITER_RAW) |
| 2870 | return print_raw_fmt(iter); |
| 2871 | |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2872 | return print_trace_fmt(iter); |
| 2873 | } |
| 2874 | |
Jiri Olsa | 7e9a49e | 2011-11-07 16:08:49 +0100 | [diff] [blame] | 2875 | void trace_latency_header(struct seq_file *m) |
| 2876 | { |
| 2877 | struct trace_iterator *iter = m->private; |
| 2878 | |
| 2879 | /* print nothing if the buffers are empty */ |
| 2880 | if (trace_empty(iter)) |
| 2881 | return; |
| 2882 | |
| 2883 | if (iter->iter_flags & TRACE_FILE_LAT_FMT) |
| 2884 | print_trace_header(m, iter); |
| 2885 | |
| 2886 | if (!(trace_flags & TRACE_ITER_VERBOSE)) |
| 2887 | print_lat_help_header(m); |
| 2888 | } |
| 2889 | |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 2890 | void trace_default_header(struct seq_file *m) |
| 2891 | { |
| 2892 | struct trace_iterator *iter = m->private; |
| 2893 | |
Jiri Olsa | f56e7f8 | 2011-06-03 16:58:49 +0200 | [diff] [blame] | 2894 | if (!(trace_flags & TRACE_ITER_CONTEXT_INFO)) |
| 2895 | return; |
| 2896 | |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 2897 | if (iter->iter_flags & TRACE_FILE_LAT_FMT) { |
| 2898 | /* print nothing if the buffers are empty */ |
| 2899 | if (trace_empty(iter)) |
| 2900 | return; |
| 2901 | print_trace_header(m, iter); |
| 2902 | if (!(trace_flags & TRACE_ITER_VERBOSE)) |
| 2903 | print_lat_help_header(m); |
| 2904 | } else { |
Steven Rostedt | 77271ce | 2011-11-17 09:34:33 -0500 | [diff] [blame] | 2905 | if (!(trace_flags & TRACE_ITER_VERBOSE)) { |
| 2906 | if (trace_flags & TRACE_ITER_IRQ_INFO) |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2907 | print_func_help_header_irq(iter->trace_buffer, m); |
Steven Rostedt | 77271ce | 2011-11-17 09:34:33 -0500 | [diff] [blame] | 2908 | else |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2909 | print_func_help_header(iter->trace_buffer, m); |
Steven Rostedt | 77271ce | 2011-11-17 09:34:33 -0500 | [diff] [blame] | 2910 | } |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 2911 | } |
| 2912 | } |
| 2913 | |
Steven Rostedt | e0a413f | 2011-09-29 21:26:16 -0400 | [diff] [blame] | 2914 | static void test_ftrace_alive(struct seq_file *m) |
| 2915 | { |
| 2916 | if (!ftrace_is_dead()) |
| 2917 | return; |
Rasmus Villemoes | d79ac28 | 2014-11-08 21:42:11 +0100 | [diff] [blame] | 2918 | seq_puts(m, "# WARNING: FUNCTION TRACING IS CORRUPTED\n" |
| 2919 | "# MAY BE MISSING FUNCTION EVENTS\n"); |
Steven Rostedt | e0a413f | 2011-09-29 21:26:16 -0400 | [diff] [blame] | 2920 | } |
| 2921 | |
Steven Rostedt (Red Hat) | d8741e2 | 2013-03-05 10:25:16 -0500 | [diff] [blame] | 2922 | #ifdef CONFIG_TRACER_MAX_TRACE |
Steven Rostedt (Red Hat) | f1affca | 2013-03-05 14:35:11 -0500 | [diff] [blame] | 2923 | static void show_snapshot_main_help(struct seq_file *m) |
Steven Rostedt (Red Hat) | d8741e2 | 2013-03-05 10:25:16 -0500 | [diff] [blame] | 2924 | { |
Rasmus Villemoes | d79ac28 | 2014-11-08 21:42:11 +0100 | [diff] [blame] | 2925 | seq_puts(m, "# echo 0 > snapshot : Clears and frees snapshot buffer\n" |
| 2926 | "# echo 1 > snapshot : Allocates snapshot buffer, if not already allocated.\n" |
| 2927 | "# Takes a snapshot of the main buffer.\n" |
| 2928 | "# echo 2 > snapshot : Clears snapshot buffer (but does not allocate or free)\n" |
| 2929 | "# (Doesn't have to be '2' works with any number that\n" |
| 2930 | "# is not a '0' or '1')\n"); |
Steven Rostedt (Red Hat) | d8741e2 | 2013-03-05 10:25:16 -0500 | [diff] [blame] | 2931 | } |
Steven Rostedt (Red Hat) | f1affca | 2013-03-05 14:35:11 -0500 | [diff] [blame] | 2932 | |
| 2933 | static void show_snapshot_percpu_help(struct seq_file *m) |
| 2934 | { |
Rasmus Villemoes | fa6f0cc | 2014-11-08 21:42:10 +0100 | [diff] [blame] | 2935 | seq_puts(m, "# echo 0 > snapshot : Invalid for per_cpu snapshot file.\n"); |
Steven Rostedt (Red Hat) | f1affca | 2013-03-05 14:35:11 -0500 | [diff] [blame] | 2936 | #ifdef CONFIG_RING_BUFFER_ALLOW_SWAP |
Rasmus Villemoes | d79ac28 | 2014-11-08 21:42:11 +0100 | [diff] [blame] | 2937 | seq_puts(m, "# echo 1 > snapshot : Allocates snapshot buffer, if not already allocated.\n" |
| 2938 | "# Takes a snapshot of the main buffer for this cpu.\n"); |
Steven Rostedt (Red Hat) | f1affca | 2013-03-05 14:35:11 -0500 | [diff] [blame] | 2939 | #else |
Rasmus Villemoes | d79ac28 | 2014-11-08 21:42:11 +0100 | [diff] [blame] | 2940 | seq_puts(m, "# echo 1 > snapshot : Not supported with this kernel.\n" |
| 2941 | "# Must use main snapshot file to allocate.\n"); |
Steven Rostedt (Red Hat) | f1affca | 2013-03-05 14:35:11 -0500 | [diff] [blame] | 2942 | #endif |
Rasmus Villemoes | d79ac28 | 2014-11-08 21:42:11 +0100 | [diff] [blame] | 2943 | seq_puts(m, "# echo 2 > snapshot : Clears this cpu's snapshot buffer (but does not allocate)\n" |
| 2944 | "# (Doesn't have to be '2' works with any number that\n" |
| 2945 | "# is not a '0' or '1')\n"); |
Steven Rostedt (Red Hat) | f1affca | 2013-03-05 14:35:11 -0500 | [diff] [blame] | 2946 | } |
| 2947 | |
Steven Rostedt (Red Hat) | d8741e2 | 2013-03-05 10:25:16 -0500 | [diff] [blame] | 2948 | static void print_snapshot_help(struct seq_file *m, struct trace_iterator *iter) |
| 2949 | { |
Steven Rostedt (Red Hat) | 45ad21c | 2013-03-05 18:25:02 -0500 | [diff] [blame] | 2950 | if (iter->tr->allocated_snapshot) |
Rasmus Villemoes | fa6f0cc | 2014-11-08 21:42:10 +0100 | [diff] [blame] | 2951 | seq_puts(m, "#\n# * Snapshot is allocated *\n#\n"); |
Steven Rostedt (Red Hat) | d8741e2 | 2013-03-05 10:25:16 -0500 | [diff] [blame] | 2952 | else |
Rasmus Villemoes | fa6f0cc | 2014-11-08 21:42:10 +0100 | [diff] [blame] | 2953 | seq_puts(m, "#\n# * Snapshot is freed *\n#\n"); |
Steven Rostedt (Red Hat) | d8741e2 | 2013-03-05 10:25:16 -0500 | [diff] [blame] | 2954 | |
Rasmus Villemoes | fa6f0cc | 2014-11-08 21:42:10 +0100 | [diff] [blame] | 2955 | seq_puts(m, "# Snapshot commands:\n"); |
Steven Rostedt (Red Hat) | f1affca | 2013-03-05 14:35:11 -0500 | [diff] [blame] | 2956 | if (iter->cpu_file == RING_BUFFER_ALL_CPUS) |
| 2957 | show_snapshot_main_help(m); |
| 2958 | else |
| 2959 | show_snapshot_percpu_help(m); |
Steven Rostedt (Red Hat) | d8741e2 | 2013-03-05 10:25:16 -0500 | [diff] [blame] | 2960 | } |
| 2961 | #else |
| 2962 | /* Should never be called */ |
| 2963 | static inline void print_snapshot_help(struct seq_file *m, struct trace_iterator *iter) { } |
| 2964 | #endif |
| 2965 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2966 | static int s_show(struct seq_file *m, void *v) |
| 2967 | { |
| 2968 | struct trace_iterator *iter = v; |
Steven Rostedt | a63ce5b | 2009-12-07 09:11:39 -0500 | [diff] [blame] | 2969 | int ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2970 | |
| 2971 | if (iter->ent == NULL) { |
| 2972 | if (iter->tr) { |
| 2973 | seq_printf(m, "# tracer: %s\n", iter->trace->name); |
| 2974 | seq_puts(m, "#\n"); |
Steven Rostedt | e0a413f | 2011-09-29 21:26:16 -0400 | [diff] [blame] | 2975 | test_ftrace_alive(m); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2976 | } |
Steven Rostedt (Red Hat) | d8741e2 | 2013-03-05 10:25:16 -0500 | [diff] [blame] | 2977 | if (iter->snapshot && trace_empty(iter)) |
| 2978 | print_snapshot_help(m, iter); |
| 2979 | else if (iter->trace && iter->trace->print_header) |
Markus Metzger | 8bba1bf | 2008-11-25 09:12:31 +0100 | [diff] [blame] | 2980 | iter->trace->print_header(m); |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 2981 | else |
| 2982 | trace_default_header(m); |
| 2983 | |
Steven Rostedt | a63ce5b | 2009-12-07 09:11:39 -0500 | [diff] [blame] | 2984 | } else if (iter->leftover) { |
| 2985 | /* |
| 2986 | * If we filled the seq_file buffer earlier, we |
| 2987 | * want to just show it now. |
| 2988 | */ |
| 2989 | ret = trace_print_seq(m, &iter->seq); |
| 2990 | |
| 2991 | /* ret should this time be zero, but you never know */ |
| 2992 | iter->leftover = ret; |
| 2993 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2994 | } else { |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2995 | print_trace_line(iter); |
Steven Rostedt | a63ce5b | 2009-12-07 09:11:39 -0500 | [diff] [blame] | 2996 | ret = trace_print_seq(m, &iter->seq); |
| 2997 | /* |
| 2998 | * If we overflow the seq_file buffer, then it will |
| 2999 | * ask us for this data again at start up. |
| 3000 | * Use that instead. |
| 3001 | * ret is 0 if seq_file write succeeded. |
| 3002 | * -1 otherwise. |
| 3003 | */ |
| 3004 | iter->leftover = ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3005 | } |
| 3006 | |
| 3007 | return 0; |
| 3008 | } |
| 3009 | |
Oleg Nesterov | 649e9c70 | 2013-07-23 17:25:54 +0200 | [diff] [blame] | 3010 | /* |
| 3011 | * Should be used after trace_array_get(), trace_types_lock |
| 3012 | * ensures that i_cdev was already initialized. |
| 3013 | */ |
| 3014 | static inline int tracing_get_cpu(struct inode *inode) |
| 3015 | { |
| 3016 | if (inode->i_cdev) /* See trace_create_cpu_file() */ |
| 3017 | return (long)inode->i_cdev - 1; |
| 3018 | return RING_BUFFER_ALL_CPUS; |
| 3019 | } |
| 3020 | |
James Morris | 88e9d34 | 2009-09-22 16:43:43 -0700 | [diff] [blame] | 3021 | static const struct seq_operations tracer_seq_ops = { |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3022 | .start = s_start, |
| 3023 | .next = s_next, |
| 3024 | .stop = s_stop, |
| 3025 | .show = s_show, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3026 | }; |
| 3027 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 3028 | static struct trace_iterator * |
Oleg Nesterov | 6484c71 | 2013-07-23 17:26:10 +0200 | [diff] [blame] | 3029 | __tracing_open(struct inode *inode, struct file *file, bool snapshot) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3030 | { |
Oleg Nesterov | 6484c71 | 2013-07-23 17:26:10 +0200 | [diff] [blame] | 3031 | struct trace_array *tr = inode->i_private; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3032 | struct trace_iterator *iter; |
Jiri Olsa | 50e18b9 | 2012-04-25 10:23:39 +0200 | [diff] [blame] | 3033 | int cpu; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3034 | |
Steven Rostedt | 85a2f9b | 2009-02-27 00:12:38 -0500 | [diff] [blame] | 3035 | if (tracing_disabled) |
| 3036 | return ERR_PTR(-ENODEV); |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 3037 | |
Jiri Olsa | 50e18b9 | 2012-04-25 10:23:39 +0200 | [diff] [blame] | 3038 | iter = __seq_open_private(file, &tracer_seq_ops, sizeof(*iter)); |
Steven Rostedt | 85a2f9b | 2009-02-27 00:12:38 -0500 | [diff] [blame] | 3039 | if (!iter) |
| 3040 | return ERR_PTR(-ENOMEM); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3041 | |
Gil Fruchter | 7291723 | 2015-06-09 10:32:35 +0300 | [diff] [blame] | 3042 | iter->buffer_iter = kcalloc(nr_cpu_ids, sizeof(*iter->buffer_iter), |
Steven Rostedt | 6d158a8 | 2012-06-27 20:46:14 -0400 | [diff] [blame] | 3043 | GFP_KERNEL); |
Dan Carpenter | 93574fc | 2012-07-11 09:35:08 +0300 | [diff] [blame] | 3044 | if (!iter->buffer_iter) |
| 3045 | goto release; |
| 3046 | |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 3047 | /* |
| 3048 | * We make a copy of the current tracer to avoid concurrent |
| 3049 | * changes on it while we are reading. |
| 3050 | */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3051 | mutex_lock(&trace_types_lock); |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 3052 | iter->trace = kzalloc(sizeof(*iter->trace), GFP_KERNEL); |
Steven Rostedt | 85a2f9b | 2009-02-27 00:12:38 -0500 | [diff] [blame] | 3053 | if (!iter->trace) |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 3054 | goto fail; |
Steven Rostedt | 85a2f9b | 2009-02-27 00:12:38 -0500 | [diff] [blame] | 3055 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3056 | *iter->trace = *tr->current_trace; |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 3057 | |
Li Zefan | 79f5599 | 2009-06-15 14:58:26 +0800 | [diff] [blame] | 3058 | if (!zalloc_cpumask_var(&iter->started, GFP_KERNEL)) |
Frederic Weisbecker | b0dfa97 | 2009-04-01 22:53:08 +0200 | [diff] [blame] | 3059 | goto fail; |
| 3060 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3061 | iter->tr = tr; |
| 3062 | |
| 3063 | #ifdef CONFIG_TRACER_MAX_TRACE |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3064 | /* Currently only the top directory has a snapshot */ |
| 3065 | if (tr->current_trace->print_max || snapshot) |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3066 | iter->trace_buffer = &tr->max_buffer; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3067 | else |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3068 | #endif |
| 3069 | iter->trace_buffer = &tr->trace_buffer; |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 3070 | iter->snapshot = snapshot; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3071 | iter->pos = -1; |
Oleg Nesterov | 6484c71 | 2013-07-23 17:26:10 +0200 | [diff] [blame] | 3072 | iter->cpu_file = tracing_get_cpu(inode); |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 3073 | mutex_init(&iter->mutex); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3074 | |
Markus Metzger | 8bba1bf | 2008-11-25 09:12:31 +0100 | [diff] [blame] | 3075 | /* Notify the tracer early; before we stop tracing. */ |
| 3076 | if (iter->trace && iter->trace->open) |
Markus Metzger | a93751c | 2008-12-11 13:53:26 +0100 | [diff] [blame] | 3077 | iter->trace->open(iter); |
Markus Metzger | 8bba1bf | 2008-11-25 09:12:31 +0100 | [diff] [blame] | 3078 | |
Steven Rostedt | 12ef7d4 | 2008-11-12 17:52:38 -0500 | [diff] [blame] | 3079 | /* Annotate start of buffers if we had overruns */ |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3080 | if (ring_buffer_overruns(iter->trace_buffer->buffer)) |
Steven Rostedt | 12ef7d4 | 2008-11-12 17:52:38 -0500 | [diff] [blame] | 3081 | iter->iter_flags |= TRACE_FILE_ANNOTATE; |
| 3082 | |
David Sharp | 8be0709 | 2012-11-13 12:18:22 -0800 | [diff] [blame] | 3083 | /* Output in nanoseconds only if we are using a clock in nanoseconds. */ |
Yoshihiro YUNOMAE | 58e8eed | 2013-04-23 10:32:39 +0900 | [diff] [blame] | 3084 | if (trace_clocks[tr->clock_id].in_ns) |
David Sharp | 8be0709 | 2012-11-13 12:18:22 -0800 | [diff] [blame] | 3085 | iter->iter_flags |= TRACE_FILE_TIME_IN_NS; |
| 3086 | |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 3087 | /* stop the trace while dumping if we are not opening "snapshot" */ |
| 3088 | if (!iter->snapshot) |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3089 | tracing_stop_tr(tr); |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 3090 | |
Steven Rostedt | ae3b509 | 2013-01-23 15:22:59 -0500 | [diff] [blame] | 3091 | if (iter->cpu_file == RING_BUFFER_ALL_CPUS) { |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 3092 | for_each_tracing_cpu(cpu) { |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 3093 | iter->buffer_iter[cpu] = |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3094 | ring_buffer_read_prepare(iter->trace_buffer->buffer, cpu); |
David Miller | 72c9ddf | 2010-04-20 15:47:11 -0700 | [diff] [blame] | 3095 | } |
| 3096 | ring_buffer_read_prepare_sync(); |
| 3097 | for_each_tracing_cpu(cpu) { |
| 3098 | ring_buffer_read_start(iter->buffer_iter[cpu]); |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 3099 | tracing_iter_reset(iter, cpu); |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 3100 | } |
| 3101 | } else { |
| 3102 | cpu = iter->cpu_file; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 3103 | iter->buffer_iter[cpu] = |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3104 | ring_buffer_read_prepare(iter->trace_buffer->buffer, cpu); |
David Miller | 72c9ddf | 2010-04-20 15:47:11 -0700 | [diff] [blame] | 3105 | ring_buffer_read_prepare_sync(); |
| 3106 | ring_buffer_read_start(iter->buffer_iter[cpu]); |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 3107 | tracing_iter_reset(iter, cpu); |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 3108 | } |
| 3109 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3110 | mutex_unlock(&trace_types_lock); |
| 3111 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3112 | return iter; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 3113 | |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 3114 | fail: |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 3115 | mutex_unlock(&trace_types_lock); |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 3116 | kfree(iter->trace); |
Steven Rostedt | 6d158a8 | 2012-06-27 20:46:14 -0400 | [diff] [blame] | 3117 | kfree(iter->buffer_iter); |
Dan Carpenter | 93574fc | 2012-07-11 09:35:08 +0300 | [diff] [blame] | 3118 | release: |
Jiri Olsa | 50e18b9 | 2012-04-25 10:23:39 +0200 | [diff] [blame] | 3119 | seq_release_private(inode, file); |
| 3120 | return ERR_PTR(-ENOMEM); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3121 | } |
| 3122 | |
| 3123 | int tracing_open_generic(struct inode *inode, struct file *filp) |
| 3124 | { |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 3125 | if (tracing_disabled) |
| 3126 | return -ENODEV; |
| 3127 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3128 | filp->private_data = inode->i_private; |
| 3129 | return 0; |
| 3130 | } |
| 3131 | |
Geyslan G. Bem | 2e86421 | 2013-10-18 21:15:54 -0300 | [diff] [blame] | 3132 | bool tracing_is_disabled(void) |
| 3133 | { |
| 3134 | return (tracing_disabled) ? true: false; |
| 3135 | } |
| 3136 | |
Steven Rostedt (Red Hat) | 7b85af6 | 2013-07-01 23:34:22 -0400 | [diff] [blame] | 3137 | /* |
| 3138 | * Open and update trace_array ref count. |
| 3139 | * Must have the current trace_array passed to it. |
| 3140 | */ |
Steven Rostedt (Red Hat) | dcc3022 | 2013-07-02 20:30:52 -0400 | [diff] [blame] | 3141 | static int tracing_open_generic_tr(struct inode *inode, struct file *filp) |
Steven Rostedt (Red Hat) | 7b85af6 | 2013-07-01 23:34:22 -0400 | [diff] [blame] | 3142 | { |
| 3143 | struct trace_array *tr = inode->i_private; |
| 3144 | |
| 3145 | if (tracing_disabled) |
| 3146 | return -ENODEV; |
| 3147 | |
| 3148 | if (trace_array_get(tr) < 0) |
| 3149 | return -ENODEV; |
| 3150 | |
| 3151 | filp->private_data = inode->i_private; |
| 3152 | |
| 3153 | return 0; |
Steven Rostedt (Red Hat) | 7b85af6 | 2013-07-01 23:34:22 -0400 | [diff] [blame] | 3154 | } |
| 3155 | |
Hannes Eder | 4fd2735 | 2009-02-10 19:44:12 +0100 | [diff] [blame] | 3156 | static int tracing_release(struct inode *inode, struct file *file) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3157 | { |
Oleg Nesterov | 6484c71 | 2013-07-23 17:26:10 +0200 | [diff] [blame] | 3158 | struct trace_array *tr = inode->i_private; |
matt mooney | 907f278 | 2010-09-27 19:04:53 -0700 | [diff] [blame] | 3159 | struct seq_file *m = file->private_data; |
Steven Rostedt | 4acd4d0 | 2009-03-18 10:40:24 -0400 | [diff] [blame] | 3160 | struct trace_iterator *iter; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 3161 | int cpu; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3162 | |
Steven Rostedt (Red Hat) | ff45196 | 2013-07-01 22:50:29 -0400 | [diff] [blame] | 3163 | if (!(file->f_mode & FMODE_READ)) { |
Oleg Nesterov | 6484c71 | 2013-07-23 17:26:10 +0200 | [diff] [blame] | 3164 | trace_array_put(tr); |
Steven Rostedt | 4acd4d0 | 2009-03-18 10:40:24 -0400 | [diff] [blame] | 3165 | return 0; |
Steven Rostedt (Red Hat) | ff45196 | 2013-07-01 22:50:29 -0400 | [diff] [blame] | 3166 | } |
Steven Rostedt | 4acd4d0 | 2009-03-18 10:40:24 -0400 | [diff] [blame] | 3167 | |
Oleg Nesterov | 6484c71 | 2013-07-23 17:26:10 +0200 | [diff] [blame] | 3168 | /* Writes do not use seq_file */ |
Steven Rostedt | 4acd4d0 | 2009-03-18 10:40:24 -0400 | [diff] [blame] | 3169 | iter = m->private; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3170 | mutex_lock(&trace_types_lock); |
Steven Rostedt (Red Hat) | a695cb5 | 2013-03-06 15:27:24 -0500 | [diff] [blame] | 3171 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 3172 | for_each_tracing_cpu(cpu) { |
| 3173 | if (iter->buffer_iter[cpu]) |
| 3174 | ring_buffer_read_finish(iter->buffer_iter[cpu]); |
| 3175 | } |
| 3176 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3177 | if (iter->trace && iter->trace->close) |
| 3178 | iter->trace->close(iter); |
| 3179 | |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 3180 | if (!iter->snapshot) |
| 3181 | /* reenable tracing if it was previously enabled */ |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3182 | tracing_start_tr(tr); |
Alexander Z Lam | f77d09a | 2013-07-18 11:18:44 -0700 | [diff] [blame] | 3183 | |
| 3184 | __trace_array_put(tr); |
| 3185 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3186 | mutex_unlock(&trace_types_lock); |
| 3187 | |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 3188 | mutex_destroy(&iter->mutex); |
Frederic Weisbecker | b0dfa97 | 2009-04-01 22:53:08 +0200 | [diff] [blame] | 3189 | free_cpumask_var(iter->started); |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 3190 | kfree(iter->trace); |
Steven Rostedt | 6d158a8 | 2012-06-27 20:46:14 -0400 | [diff] [blame] | 3191 | kfree(iter->buffer_iter); |
Jiri Olsa | 50e18b9 | 2012-04-25 10:23:39 +0200 | [diff] [blame] | 3192 | seq_release_private(inode, file); |
Steven Rostedt (Red Hat) | ff45196 | 2013-07-01 22:50:29 -0400 | [diff] [blame] | 3193 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3194 | return 0; |
| 3195 | } |
| 3196 | |
Steven Rostedt (Red Hat) | 7b85af6 | 2013-07-01 23:34:22 -0400 | [diff] [blame] | 3197 | static int tracing_release_generic_tr(struct inode *inode, struct file *file) |
| 3198 | { |
| 3199 | struct trace_array *tr = inode->i_private; |
| 3200 | |
| 3201 | trace_array_put(tr); |
| 3202 | return 0; |
| 3203 | } |
| 3204 | |
Steven Rostedt (Red Hat) | 7b85af6 | 2013-07-01 23:34:22 -0400 | [diff] [blame] | 3205 | static int tracing_single_release_tr(struct inode *inode, struct file *file) |
| 3206 | { |
| 3207 | struct trace_array *tr = inode->i_private; |
| 3208 | |
| 3209 | trace_array_put(tr); |
| 3210 | |
| 3211 | return single_release(inode, file); |
| 3212 | } |
| 3213 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3214 | static int tracing_open(struct inode *inode, struct file *file) |
| 3215 | { |
Oleg Nesterov | 6484c71 | 2013-07-23 17:26:10 +0200 | [diff] [blame] | 3216 | struct trace_array *tr = inode->i_private; |
Steven Rostedt | 85a2f9b | 2009-02-27 00:12:38 -0500 | [diff] [blame] | 3217 | struct trace_iterator *iter; |
| 3218 | int ret = 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3219 | |
Steven Rostedt (Red Hat) | ff45196 | 2013-07-01 22:50:29 -0400 | [diff] [blame] | 3220 | if (trace_array_get(tr) < 0) |
| 3221 | return -ENODEV; |
| 3222 | |
Steven Rostedt | 4acd4d0 | 2009-03-18 10:40:24 -0400 | [diff] [blame] | 3223 | /* If this file was open for write, then erase contents */ |
Oleg Nesterov | 6484c71 | 2013-07-23 17:26:10 +0200 | [diff] [blame] | 3224 | if ((file->f_mode & FMODE_WRITE) && (file->f_flags & O_TRUNC)) { |
| 3225 | int cpu = tracing_get_cpu(inode); |
| 3226 | |
| 3227 | if (cpu == RING_BUFFER_ALL_CPUS) |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3228 | tracing_reset_online_cpus(&tr->trace_buffer); |
Steven Rostedt | 4acd4d0 | 2009-03-18 10:40:24 -0400 | [diff] [blame] | 3229 | else |
Oleg Nesterov | 6484c71 | 2013-07-23 17:26:10 +0200 | [diff] [blame] | 3230 | tracing_reset(&tr->trace_buffer, cpu); |
Steven Rostedt | 4acd4d0 | 2009-03-18 10:40:24 -0400 | [diff] [blame] | 3231 | } |
| 3232 | |
| 3233 | if (file->f_mode & FMODE_READ) { |
Oleg Nesterov | 6484c71 | 2013-07-23 17:26:10 +0200 | [diff] [blame] | 3234 | iter = __tracing_open(inode, file, false); |
Steven Rostedt | 4acd4d0 | 2009-03-18 10:40:24 -0400 | [diff] [blame] | 3235 | if (IS_ERR(iter)) |
| 3236 | ret = PTR_ERR(iter); |
| 3237 | else if (trace_flags & TRACE_ITER_LATENCY_FMT) |
| 3238 | iter->iter_flags |= TRACE_FILE_LAT_FMT; |
| 3239 | } |
Steven Rostedt (Red Hat) | ff45196 | 2013-07-01 22:50:29 -0400 | [diff] [blame] | 3240 | |
| 3241 | if (ret < 0) |
| 3242 | trace_array_put(tr); |
| 3243 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3244 | return ret; |
| 3245 | } |
| 3246 | |
Steven Rostedt (Red Hat) | 607e2ea | 2013-11-06 22:42:48 -0500 | [diff] [blame] | 3247 | /* |
| 3248 | * Some tracers are not suitable for instance buffers. |
| 3249 | * A tracer is always available for the global array (toplevel) |
| 3250 | * or if it explicitly states that it is. |
| 3251 | */ |
| 3252 | static bool |
| 3253 | trace_ok_for_array(struct tracer *t, struct trace_array *tr) |
| 3254 | { |
| 3255 | return (tr->flags & TRACE_ARRAY_FL_GLOBAL) || t->allow_instances; |
| 3256 | } |
| 3257 | |
| 3258 | /* Find the next tracer that this trace array may use */ |
| 3259 | static struct tracer * |
| 3260 | get_tracer_for_array(struct trace_array *tr, struct tracer *t) |
| 3261 | { |
| 3262 | while (t && !trace_ok_for_array(t, tr)) |
| 3263 | t = t->next; |
| 3264 | |
| 3265 | return t; |
| 3266 | } |
| 3267 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 3268 | static void * |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3269 | t_next(struct seq_file *m, void *v, loff_t *pos) |
| 3270 | { |
Steven Rostedt (Red Hat) | 607e2ea | 2013-11-06 22:42:48 -0500 | [diff] [blame] | 3271 | struct trace_array *tr = m->private; |
Li Zefan | f129e96 | 2009-06-24 09:53:44 +0800 | [diff] [blame] | 3272 | struct tracer *t = v; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3273 | |
| 3274 | (*pos)++; |
| 3275 | |
| 3276 | if (t) |
Steven Rostedt (Red Hat) | 607e2ea | 2013-11-06 22:42:48 -0500 | [diff] [blame] | 3277 | t = get_tracer_for_array(tr, t->next); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3278 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3279 | return t; |
| 3280 | } |
| 3281 | |
| 3282 | static void *t_start(struct seq_file *m, loff_t *pos) |
| 3283 | { |
Steven Rostedt (Red Hat) | 607e2ea | 2013-11-06 22:42:48 -0500 | [diff] [blame] | 3284 | struct trace_array *tr = m->private; |
Li Zefan | f129e96 | 2009-06-24 09:53:44 +0800 | [diff] [blame] | 3285 | struct tracer *t; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3286 | loff_t l = 0; |
| 3287 | |
| 3288 | mutex_lock(&trace_types_lock); |
Steven Rostedt (Red Hat) | 607e2ea | 2013-11-06 22:42:48 -0500 | [diff] [blame] | 3289 | |
| 3290 | t = get_tracer_for_array(tr, trace_types); |
| 3291 | for (; t && l < *pos; t = t_next(m, t, &l)) |
| 3292 | ; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3293 | |
| 3294 | return t; |
| 3295 | } |
| 3296 | |
| 3297 | static void t_stop(struct seq_file *m, void *p) |
| 3298 | { |
| 3299 | mutex_unlock(&trace_types_lock); |
| 3300 | } |
| 3301 | |
| 3302 | static int t_show(struct seq_file *m, void *v) |
| 3303 | { |
| 3304 | struct tracer *t = v; |
| 3305 | |
| 3306 | if (!t) |
| 3307 | return 0; |
| 3308 | |
Rasmus Villemoes | fa6f0cc | 2014-11-08 21:42:10 +0100 | [diff] [blame] | 3309 | seq_puts(m, t->name); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3310 | if (t->next) |
| 3311 | seq_putc(m, ' '); |
| 3312 | else |
| 3313 | seq_putc(m, '\n'); |
| 3314 | |
| 3315 | return 0; |
| 3316 | } |
| 3317 | |
James Morris | 88e9d34 | 2009-09-22 16:43:43 -0700 | [diff] [blame] | 3318 | static const struct seq_operations show_traces_seq_ops = { |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3319 | .start = t_start, |
| 3320 | .next = t_next, |
| 3321 | .stop = t_stop, |
| 3322 | .show = t_show, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3323 | }; |
| 3324 | |
| 3325 | static int show_traces_open(struct inode *inode, struct file *file) |
| 3326 | { |
Steven Rostedt (Red Hat) | 607e2ea | 2013-11-06 22:42:48 -0500 | [diff] [blame] | 3327 | struct trace_array *tr = inode->i_private; |
| 3328 | struct seq_file *m; |
| 3329 | int ret; |
| 3330 | |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 3331 | if (tracing_disabled) |
| 3332 | return -ENODEV; |
| 3333 | |
Steven Rostedt (Red Hat) | 607e2ea | 2013-11-06 22:42:48 -0500 | [diff] [blame] | 3334 | ret = seq_open(file, &show_traces_seq_ops); |
| 3335 | if (ret) |
| 3336 | return ret; |
| 3337 | |
| 3338 | m = file->private_data; |
| 3339 | m->private = tr; |
| 3340 | |
| 3341 | return 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3342 | } |
| 3343 | |
Steven Rostedt | 4acd4d0 | 2009-03-18 10:40:24 -0400 | [diff] [blame] | 3344 | static ssize_t |
| 3345 | tracing_write_stub(struct file *filp, const char __user *ubuf, |
| 3346 | size_t count, loff_t *ppos) |
| 3347 | { |
| 3348 | return count; |
| 3349 | } |
| 3350 | |
Steven Rostedt (Red Hat) | 098c879 | 2013-12-21 17:39:40 -0500 | [diff] [blame] | 3351 | loff_t tracing_lseek(struct file *file, loff_t offset, int whence) |
Slava Pestov | 364829b | 2010-11-24 15:13:16 -0800 | [diff] [blame] | 3352 | { |
Steven Rostedt (Red Hat) | 098c879 | 2013-12-21 17:39:40 -0500 | [diff] [blame] | 3353 | int ret; |
| 3354 | |
Slava Pestov | 364829b | 2010-11-24 15:13:16 -0800 | [diff] [blame] | 3355 | if (file->f_mode & FMODE_READ) |
Steven Rostedt (Red Hat) | 098c879 | 2013-12-21 17:39:40 -0500 | [diff] [blame] | 3356 | ret = seq_lseek(file, offset, whence); |
Slava Pestov | 364829b | 2010-11-24 15:13:16 -0800 | [diff] [blame] | 3357 | else |
Steven Rostedt (Red Hat) | 098c879 | 2013-12-21 17:39:40 -0500 | [diff] [blame] | 3358 | file->f_pos = ret = 0; |
| 3359 | |
| 3360 | return ret; |
Slava Pestov | 364829b | 2010-11-24 15:13:16 -0800 | [diff] [blame] | 3361 | } |
| 3362 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 3363 | static const struct file_operations tracing_fops = { |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3364 | .open = tracing_open, |
| 3365 | .read = seq_read, |
Steven Rostedt | 4acd4d0 | 2009-03-18 10:40:24 -0400 | [diff] [blame] | 3366 | .write = tracing_write_stub, |
Steven Rostedt (Red Hat) | 098c879 | 2013-12-21 17:39:40 -0500 | [diff] [blame] | 3367 | .llseek = tracing_lseek, |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3368 | .release = tracing_release, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3369 | }; |
| 3370 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 3371 | static const struct file_operations show_traces_fops = { |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3372 | .open = show_traces_open, |
| 3373 | .read = seq_read, |
| 3374 | .release = seq_release, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 3375 | .llseek = seq_lseek, |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3376 | }; |
| 3377 | |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3378 | /* |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3379 | * The tracer itself will not take this lock, but still we want |
| 3380 | * to provide a consistent cpumask to user-space: |
| 3381 | */ |
| 3382 | static DEFINE_MUTEX(tracing_cpumask_update_lock); |
| 3383 | |
| 3384 | /* |
| 3385 | * Temporary storage for the character representation of the |
| 3386 | * CPU bitmask (and one more byte for the newline): |
| 3387 | */ |
| 3388 | static char mask_str[NR_CPUS + 1]; |
| 3389 | |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3390 | static ssize_t |
| 3391 | tracing_cpumask_read(struct file *filp, char __user *ubuf, |
| 3392 | size_t count, loff_t *ppos) |
| 3393 | { |
Alexander Z Lam | ccfe9e4 | 2013-08-08 09:47:45 -0700 | [diff] [blame] | 3394 | struct trace_array *tr = file_inode(filp)->i_private; |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3395 | int len; |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3396 | |
| 3397 | mutex_lock(&tracing_cpumask_update_lock); |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3398 | |
Tejun Heo | 1a40243 | 2015-02-13 14:37:39 -0800 | [diff] [blame] | 3399 | len = snprintf(mask_str, count, "%*pb\n", |
| 3400 | cpumask_pr_args(tr->tracing_cpumask)); |
| 3401 | if (len >= count) { |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3402 | count = -EINVAL; |
| 3403 | goto out_err; |
| 3404 | } |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3405 | count = simple_read_from_buffer(ubuf, count, ppos, mask_str, NR_CPUS+1); |
| 3406 | |
| 3407 | out_err: |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3408 | mutex_unlock(&tracing_cpumask_update_lock); |
| 3409 | |
| 3410 | return count; |
| 3411 | } |
| 3412 | |
| 3413 | static ssize_t |
| 3414 | tracing_cpumask_write(struct file *filp, const char __user *ubuf, |
| 3415 | size_t count, loff_t *ppos) |
| 3416 | { |
Alexander Z Lam | ccfe9e4 | 2013-08-08 09:47:45 -0700 | [diff] [blame] | 3417 | struct trace_array *tr = file_inode(filp)->i_private; |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 3418 | cpumask_var_t tracing_cpumask_new; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3419 | int err, cpu; |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 3420 | |
| 3421 | if (!alloc_cpumask_var(&tracing_cpumask_new, GFP_KERNEL)) |
| 3422 | return -ENOMEM; |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3423 | |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 3424 | err = cpumask_parse_user(ubuf, count, tracing_cpumask_new); |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3425 | if (err) |
| 3426 | goto err_unlock; |
| 3427 | |
Li Zefan | 215368e | 2009-06-15 10:56:42 +0800 | [diff] [blame] | 3428 | mutex_lock(&tracing_cpumask_update_lock); |
| 3429 | |
Steven Rostedt | a5e2588 | 2008-12-02 15:34:05 -0500 | [diff] [blame] | 3430 | local_irq_disable(); |
Steven Rostedt (Red Hat) | 0b9b12c | 2014-01-14 10:04:59 -0500 | [diff] [blame] | 3431 | arch_spin_lock(&tr->max_lock); |
Steven Rostedt | ab46428 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 3432 | for_each_tracing_cpu(cpu) { |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3433 | /* |
| 3434 | * Increase/decrease the disabled counter if we are |
| 3435 | * about to flip a bit in the cpumask: |
| 3436 | */ |
Alexander Z Lam | ccfe9e4 | 2013-08-08 09:47:45 -0700 | [diff] [blame] | 3437 | if (cpumask_test_cpu(cpu, tr->tracing_cpumask) && |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 3438 | !cpumask_test_cpu(cpu, tracing_cpumask_new)) { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3439 | atomic_inc(&per_cpu_ptr(tr->trace_buffer.data, cpu)->disabled); |
| 3440 | ring_buffer_record_disable_cpu(tr->trace_buffer.buffer, cpu); |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3441 | } |
Alexander Z Lam | ccfe9e4 | 2013-08-08 09:47:45 -0700 | [diff] [blame] | 3442 | if (!cpumask_test_cpu(cpu, tr->tracing_cpumask) && |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 3443 | cpumask_test_cpu(cpu, tracing_cpumask_new)) { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3444 | atomic_dec(&per_cpu_ptr(tr->trace_buffer.data, cpu)->disabled); |
| 3445 | ring_buffer_record_enable_cpu(tr->trace_buffer.buffer, cpu); |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3446 | } |
| 3447 | } |
Steven Rostedt (Red Hat) | 0b9b12c | 2014-01-14 10:04:59 -0500 | [diff] [blame] | 3448 | arch_spin_unlock(&tr->max_lock); |
Steven Rostedt | a5e2588 | 2008-12-02 15:34:05 -0500 | [diff] [blame] | 3449 | local_irq_enable(); |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3450 | |
Alexander Z Lam | ccfe9e4 | 2013-08-08 09:47:45 -0700 | [diff] [blame] | 3451 | cpumask_copy(tr->tracing_cpumask, tracing_cpumask_new); |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3452 | |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3453 | mutex_unlock(&tracing_cpumask_update_lock); |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 3454 | free_cpumask_var(tracing_cpumask_new); |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3455 | |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3456 | return count; |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3457 | |
| 3458 | err_unlock: |
Li Zefan | 215368e | 2009-06-15 10:56:42 +0800 | [diff] [blame] | 3459 | free_cpumask_var(tracing_cpumask_new); |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3460 | |
| 3461 | return err; |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3462 | } |
| 3463 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 3464 | static const struct file_operations tracing_cpumask_fops = { |
Alexander Z Lam | ccfe9e4 | 2013-08-08 09:47:45 -0700 | [diff] [blame] | 3465 | .open = tracing_open_generic_tr, |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3466 | .read = tracing_cpumask_read, |
| 3467 | .write = tracing_cpumask_write, |
Alexander Z Lam | ccfe9e4 | 2013-08-08 09:47:45 -0700 | [diff] [blame] | 3468 | .release = tracing_release_generic_tr, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 3469 | .llseek = generic_file_llseek, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3470 | }; |
| 3471 | |
Li Zefan | fdb372e | 2009-12-08 11:15:59 +0800 | [diff] [blame] | 3472 | static int tracing_trace_options_show(struct seq_file *m, void *v) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3473 | { |
Steven Rostedt | d8e83d2 | 2009-02-26 23:55:58 -0500 | [diff] [blame] | 3474 | struct tracer_opt *trace_opts; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3475 | struct trace_array *tr = m->private; |
Steven Rostedt | d8e83d2 | 2009-02-26 23:55:58 -0500 | [diff] [blame] | 3476 | u32 tracer_flags; |
Steven Rostedt | d8e83d2 | 2009-02-26 23:55:58 -0500 | [diff] [blame] | 3477 | int i; |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 3478 | |
Steven Rostedt | d8e83d2 | 2009-02-26 23:55:58 -0500 | [diff] [blame] | 3479 | mutex_lock(&trace_types_lock); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3480 | tracer_flags = tr->current_trace->flags->val; |
| 3481 | trace_opts = tr->current_trace->flags->opts; |
Steven Rostedt | d8e83d2 | 2009-02-26 23:55:58 -0500 | [diff] [blame] | 3482 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3483 | for (i = 0; trace_options[i]; i++) { |
| 3484 | if (trace_flags & (1 << i)) |
Li Zefan | fdb372e | 2009-12-08 11:15:59 +0800 | [diff] [blame] | 3485 | seq_printf(m, "%s\n", trace_options[i]); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3486 | else |
Li Zefan | fdb372e | 2009-12-08 11:15:59 +0800 | [diff] [blame] | 3487 | seq_printf(m, "no%s\n", trace_options[i]); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3488 | } |
| 3489 | |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 3490 | for (i = 0; trace_opts[i].name; i++) { |
| 3491 | if (tracer_flags & trace_opts[i].bit) |
Li Zefan | fdb372e | 2009-12-08 11:15:59 +0800 | [diff] [blame] | 3492 | seq_printf(m, "%s\n", trace_opts[i].name); |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 3493 | else |
Li Zefan | fdb372e | 2009-12-08 11:15:59 +0800 | [diff] [blame] | 3494 | seq_printf(m, "no%s\n", trace_opts[i].name); |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 3495 | } |
Steven Rostedt | d8e83d2 | 2009-02-26 23:55:58 -0500 | [diff] [blame] | 3496 | mutex_unlock(&trace_types_lock); |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 3497 | |
Li Zefan | fdb372e | 2009-12-08 11:15:59 +0800 | [diff] [blame] | 3498 | return 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3499 | } |
| 3500 | |
Steven Rostedt (Red Hat) | 8c1a49a | 2014-01-10 11:13:54 -0500 | [diff] [blame] | 3501 | static int __set_tracer_option(struct trace_array *tr, |
Li Zefan | 8d18eaa | 2009-12-08 11:17:06 +0800 | [diff] [blame] | 3502 | struct tracer_flags *tracer_flags, |
| 3503 | struct tracer_opt *opts, int neg) |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 3504 | { |
Steven Rostedt (Red Hat) | 8c1a49a | 2014-01-10 11:13:54 -0500 | [diff] [blame] | 3505 | struct tracer *trace = tr->current_trace; |
Li Zefan | 8d18eaa | 2009-12-08 11:17:06 +0800 | [diff] [blame] | 3506 | int ret; |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 3507 | |
Steven Rostedt (Red Hat) | 8c1a49a | 2014-01-10 11:13:54 -0500 | [diff] [blame] | 3508 | ret = trace->set_flag(tr, tracer_flags->val, opts->bit, !neg); |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 3509 | if (ret) |
| 3510 | return ret; |
| 3511 | |
| 3512 | if (neg) |
Zhaolei | 7770841 | 2009-08-07 18:53:21 +0800 | [diff] [blame] | 3513 | tracer_flags->val &= ~opts->bit; |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 3514 | else |
Zhaolei | 7770841 | 2009-08-07 18:53:21 +0800 | [diff] [blame] | 3515 | tracer_flags->val |= opts->bit; |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 3516 | return 0; |
| 3517 | } |
| 3518 | |
Li Zefan | 8d18eaa | 2009-12-08 11:17:06 +0800 | [diff] [blame] | 3519 | /* Try to assign a tracer specific option */ |
Steven Rostedt (Red Hat) | 8c1a49a | 2014-01-10 11:13:54 -0500 | [diff] [blame] | 3520 | static int set_tracer_option(struct trace_array *tr, char *cmp, int neg) |
Li Zefan | 8d18eaa | 2009-12-08 11:17:06 +0800 | [diff] [blame] | 3521 | { |
Steven Rostedt (Red Hat) | 8c1a49a | 2014-01-10 11:13:54 -0500 | [diff] [blame] | 3522 | struct tracer *trace = tr->current_trace; |
Li Zefan | 8d18eaa | 2009-12-08 11:17:06 +0800 | [diff] [blame] | 3523 | struct tracer_flags *tracer_flags = trace->flags; |
| 3524 | struct tracer_opt *opts = NULL; |
| 3525 | int i; |
| 3526 | |
| 3527 | for (i = 0; tracer_flags->opts[i].name; i++) { |
| 3528 | opts = &tracer_flags->opts[i]; |
| 3529 | |
| 3530 | if (strcmp(cmp, opts->name) == 0) |
Steven Rostedt (Red Hat) | 8c1a49a | 2014-01-10 11:13:54 -0500 | [diff] [blame] | 3531 | return __set_tracer_option(tr, trace->flags, opts, neg); |
Li Zefan | 8d18eaa | 2009-12-08 11:17:06 +0800 | [diff] [blame] | 3532 | } |
| 3533 | |
| 3534 | return -EINVAL; |
| 3535 | } |
| 3536 | |
Steven Rostedt (Red Hat) | 613f04a | 2013-03-14 15:03:53 -0400 | [diff] [blame] | 3537 | /* Some tracers require overwrite to stay enabled */ |
| 3538 | int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set) |
| 3539 | { |
| 3540 | if (tracer->enabled && (mask & TRACE_ITER_OVERWRITE) && !set) |
| 3541 | return -1; |
| 3542 | |
| 3543 | return 0; |
| 3544 | } |
| 3545 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3546 | 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] | 3547 | { |
| 3548 | /* do nothing if flag is already set */ |
| 3549 | if (!!(trace_flags & mask) == !!enabled) |
Steven Rostedt (Red Hat) | 613f04a | 2013-03-14 15:03:53 -0400 | [diff] [blame] | 3550 | return 0; |
| 3551 | |
| 3552 | /* Give the tracer a chance to approve the change */ |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3553 | if (tr->current_trace->flag_changed) |
Steven Rostedt (Red Hat) | bf6065b | 2014-01-10 17:51:01 -0500 | [diff] [blame] | 3554 | if (tr->current_trace->flag_changed(tr, mask, !!enabled)) |
Steven Rostedt (Red Hat) | 613f04a | 2013-03-14 15:03:53 -0400 | [diff] [blame] | 3555 | return -EINVAL; |
Steven Rostedt | af4617b | 2009-03-17 18:09:55 -0400 | [diff] [blame] | 3556 | |
| 3557 | if (enabled) |
| 3558 | trace_flags |= mask; |
| 3559 | else |
| 3560 | trace_flags &= ~mask; |
Li Zefan | e870e9a | 2010-07-02 11:07:32 +0800 | [diff] [blame] | 3561 | |
| 3562 | if (mask == TRACE_ITER_RECORD_CMD) |
| 3563 | trace_event_enable_cmd_record(enabled); |
David Sharp | 750912f | 2010-12-08 13:46:47 -0800 | [diff] [blame] | 3564 | |
Steven Rostedt (Red Hat) | 8090282 | 2013-03-14 14:20:54 -0400 | [diff] [blame] | 3565 | if (mask == TRACE_ITER_OVERWRITE) { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3566 | ring_buffer_change_overwrite(tr->trace_buffer.buffer, enabled); |
Steven Rostedt (Red Hat) | 8090282 | 2013-03-14 14:20:54 -0400 | [diff] [blame] | 3567 | #ifdef CONFIG_TRACER_MAX_TRACE |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3568 | ring_buffer_change_overwrite(tr->max_buffer.buffer, enabled); |
Steven Rostedt (Red Hat) | 8090282 | 2013-03-14 14:20:54 -0400 | [diff] [blame] | 3569 | #endif |
| 3570 | } |
Steven Rostedt | 8169883 | 2012-10-11 10:15:05 -0400 | [diff] [blame] | 3571 | |
| 3572 | if (mask == TRACE_ITER_PRINTK) |
| 3573 | trace_printk_start_stop_comm(enabled); |
Steven Rostedt (Red Hat) | 613f04a | 2013-03-14 15:03:53 -0400 | [diff] [blame] | 3574 | |
| 3575 | return 0; |
Steven Rostedt | af4617b | 2009-03-17 18:09:55 -0400 | [diff] [blame] | 3576 | } |
| 3577 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3578 | static int trace_set_options(struct trace_array *tr, char *option) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3579 | { |
Li Zefan | 8d18eaa | 2009-12-08 11:17:06 +0800 | [diff] [blame] | 3580 | char *cmp; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3581 | int neg = 0; |
Steven Rostedt (Red Hat) | 613f04a | 2013-03-14 15:03:53 -0400 | [diff] [blame] | 3582 | int ret = -ENODEV; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3583 | int i; |
| 3584 | |
Steven Rostedt | 7bcfaf5 | 2012-11-01 22:56:07 -0400 | [diff] [blame] | 3585 | cmp = strstrip(option); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3586 | |
Li Zefan | 8d18eaa | 2009-12-08 11:17:06 +0800 | [diff] [blame] | 3587 | if (strncmp(cmp, "no", 2) == 0) { |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3588 | neg = 1; |
| 3589 | cmp += 2; |
| 3590 | } |
| 3591 | |
Steven Rostedt (Red Hat) | 69d34da | 2013-03-14 13:50:56 -0400 | [diff] [blame] | 3592 | mutex_lock(&trace_types_lock); |
| 3593 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3594 | for (i = 0; trace_options[i]; i++) { |
Li Zefan | 8d18eaa | 2009-12-08 11:17:06 +0800 | [diff] [blame] | 3595 | if (strcmp(cmp, trace_options[i]) == 0) { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3596 | ret = set_tracer_flag(tr, 1 << i, !neg); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3597 | break; |
| 3598 | } |
| 3599 | } |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 3600 | |
| 3601 | /* 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] | 3602 | if (!trace_options[i]) |
Steven Rostedt (Red Hat) | 8c1a49a | 2014-01-10 11:13:54 -0500 | [diff] [blame] | 3603 | ret = set_tracer_option(tr, cmp, neg); |
Steven Rostedt (Red Hat) | 69d34da | 2013-03-14 13:50:56 -0400 | [diff] [blame] | 3604 | |
| 3605 | mutex_unlock(&trace_types_lock); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3606 | |
Steven Rostedt | 7bcfaf5 | 2012-11-01 22:56:07 -0400 | [diff] [blame] | 3607 | return ret; |
| 3608 | } |
| 3609 | |
| 3610 | static ssize_t |
| 3611 | tracing_trace_options_write(struct file *filp, const char __user *ubuf, |
| 3612 | size_t cnt, loff_t *ppos) |
| 3613 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3614 | struct seq_file *m = filp->private_data; |
| 3615 | struct trace_array *tr = m->private; |
Steven Rostedt | 7bcfaf5 | 2012-11-01 22:56:07 -0400 | [diff] [blame] | 3616 | char buf[64]; |
Steven Rostedt (Red Hat) | 613f04a | 2013-03-14 15:03:53 -0400 | [diff] [blame] | 3617 | int ret; |
Steven Rostedt | 7bcfaf5 | 2012-11-01 22:56:07 -0400 | [diff] [blame] | 3618 | |
| 3619 | if (cnt >= sizeof(buf)) |
| 3620 | return -EINVAL; |
| 3621 | |
| 3622 | if (copy_from_user(&buf, ubuf, cnt)) |
| 3623 | return -EFAULT; |
| 3624 | |
Steven Rostedt | a8dd217 | 2013-01-09 20:54:17 -0500 | [diff] [blame] | 3625 | buf[cnt] = 0; |
| 3626 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3627 | ret = trace_set_options(tr, buf); |
Steven Rostedt (Red Hat) | 613f04a | 2013-03-14 15:03:53 -0400 | [diff] [blame] | 3628 | if (ret < 0) |
| 3629 | return ret; |
Steven Rostedt | 7bcfaf5 | 2012-11-01 22:56:07 -0400 | [diff] [blame] | 3630 | |
Jiri Olsa | cf8517c | 2009-10-23 19:36:16 -0400 | [diff] [blame] | 3631 | *ppos += cnt; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3632 | |
| 3633 | return cnt; |
| 3634 | } |
| 3635 | |
Li Zefan | fdb372e | 2009-12-08 11:15:59 +0800 | [diff] [blame] | 3636 | static int tracing_trace_options_open(struct inode *inode, struct file *file) |
| 3637 | { |
Steven Rostedt (Red Hat) | 7b85af6 | 2013-07-01 23:34:22 -0400 | [diff] [blame] | 3638 | struct trace_array *tr = inode->i_private; |
Alexander Z Lam | f77d09a | 2013-07-18 11:18:44 -0700 | [diff] [blame] | 3639 | int ret; |
Steven Rostedt (Red Hat) | 7b85af6 | 2013-07-01 23:34:22 -0400 | [diff] [blame] | 3640 | |
Li Zefan | fdb372e | 2009-12-08 11:15:59 +0800 | [diff] [blame] | 3641 | if (tracing_disabled) |
| 3642 | return -ENODEV; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3643 | |
Steven Rostedt (Red Hat) | 7b85af6 | 2013-07-01 23:34:22 -0400 | [diff] [blame] | 3644 | if (trace_array_get(tr) < 0) |
| 3645 | return -ENODEV; |
| 3646 | |
Alexander Z Lam | f77d09a | 2013-07-18 11:18:44 -0700 | [diff] [blame] | 3647 | ret = single_open(file, tracing_trace_options_show, inode->i_private); |
| 3648 | if (ret < 0) |
| 3649 | trace_array_put(tr); |
| 3650 | |
| 3651 | return ret; |
Li Zefan | fdb372e | 2009-12-08 11:15:59 +0800 | [diff] [blame] | 3652 | } |
| 3653 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 3654 | static const struct file_operations tracing_iter_fops = { |
Li Zefan | fdb372e | 2009-12-08 11:15:59 +0800 | [diff] [blame] | 3655 | .open = tracing_trace_options_open, |
| 3656 | .read = seq_read, |
| 3657 | .llseek = seq_lseek, |
Steven Rostedt (Red Hat) | 7b85af6 | 2013-07-01 23:34:22 -0400 | [diff] [blame] | 3658 | .release = tracing_single_release_tr, |
Steven Rostedt | ee6bce5 | 2008-11-12 17:52:37 -0500 | [diff] [blame] | 3659 | .write = tracing_trace_options_write, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3660 | }; |
| 3661 | |
Ingo Molnar | 7bd2f24 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 3662 | static const char readme_msg[] = |
| 3663 | "tracing mini-HOWTO:\n\n" |
Steven Rostedt (Red Hat) | 22f4564 | 2013-03-15 17:23:20 -0400 | [diff] [blame] | 3664 | "# echo 0 > tracing_on : quick way to disable tracing\n" |
| 3665 | "# echo 1 > tracing_on : quick way to re-enable tracing\n\n" |
| 3666 | " Important files:\n" |
| 3667 | " trace\t\t\t- The static contents of the buffer\n" |
| 3668 | "\t\t\t To clear the buffer write into this file: echo > trace\n" |
| 3669 | " trace_pipe\t\t- A consuming read to see the contents of the buffer\n" |
| 3670 | " current_tracer\t- function and latency tracers\n" |
| 3671 | " available_tracers\t- list of configured tracers for current_tracer\n" |
| 3672 | " buffer_size_kb\t- view and modify size of per cpu buffer\n" |
| 3673 | " buffer_total_size_kb - view total size of all cpu buffers\n\n" |
| 3674 | " trace_clock\t\t-change the clock used to order events\n" |
| 3675 | " local: Per cpu clock but may not be synced across CPUs\n" |
| 3676 | " global: Synced across CPUs but slows tracing down.\n" |
| 3677 | " counter: Not a clock, but just an increment\n" |
| 3678 | " uptime: Jiffy counter from time of boot\n" |
| 3679 | " perf: Same clock that perf events use\n" |
| 3680 | #ifdef CONFIG_X86_64 |
| 3681 | " x86-tsc: TSC cycle counter\n" |
| 3682 | #endif |
| 3683 | "\n trace_marker\t\t- Writes into this file writes into the kernel buffer\n" |
| 3684 | " tracing_cpumask\t- Limit which CPUs to trace\n" |
| 3685 | " instances\t\t- Make sub-buffers with: mkdir instances/foo\n" |
| 3686 | "\t\t\t Remove sub-buffer with rmdir\n" |
| 3687 | " trace_options\t\t- Set format or modify how tracing happens\n" |
Steven Rostedt (Red Hat) | 71485c4 | 2014-01-23 00:10:04 -0500 | [diff] [blame] | 3688 | "\t\t\t Disable an option by adding a suffix 'no' to the\n" |
| 3689 | "\t\t\t option name\n" |
Yoshihiro YUNOMAE | 939c7a4 | 2014-06-05 10:24:27 +0900 | [diff] [blame] | 3690 | " saved_cmdlines_size\t- echo command number in here to store comm-pid list\n" |
Steven Rostedt (Red Hat) | 22f4564 | 2013-03-15 17:23:20 -0400 | [diff] [blame] | 3691 | #ifdef CONFIG_DYNAMIC_FTRACE |
| 3692 | "\n available_filter_functions - list of functions that can be filtered on\n" |
Steven Rostedt (Red Hat) | 71485c4 | 2014-01-23 00:10:04 -0500 | [diff] [blame] | 3693 | " set_ftrace_filter\t- echo function name in here to only trace these\n" |
| 3694 | "\t\t\t functions\n" |
| 3695 | "\t accepts: func_full_name, *func_end, func_begin*, *func_middle*\n" |
| 3696 | "\t modules: Can select a group via module\n" |
| 3697 | "\t Format: :mod:<module-name>\n" |
| 3698 | "\t example: echo :mod:ext3 > set_ftrace_filter\n" |
| 3699 | "\t triggers: a command to perform when function is hit\n" |
| 3700 | "\t Format: <function>:<trigger>[:count]\n" |
| 3701 | "\t trigger: traceon, traceoff\n" |
| 3702 | "\t\t enable_event:<system>:<event>\n" |
| 3703 | "\t\t disable_event:<system>:<event>\n" |
Steven Rostedt (Red Hat) | 22f4564 | 2013-03-15 17:23:20 -0400 | [diff] [blame] | 3704 | #ifdef CONFIG_STACKTRACE |
Steven Rostedt (Red Hat) | 71485c4 | 2014-01-23 00:10:04 -0500 | [diff] [blame] | 3705 | "\t\t stacktrace\n" |
Steven Rostedt (Red Hat) | 22f4564 | 2013-03-15 17:23:20 -0400 | [diff] [blame] | 3706 | #endif |
| 3707 | #ifdef CONFIG_TRACER_SNAPSHOT |
Steven Rostedt (Red Hat) | 71485c4 | 2014-01-23 00:10:04 -0500 | [diff] [blame] | 3708 | "\t\t snapshot\n" |
Steven Rostedt (Red Hat) | 22f4564 | 2013-03-15 17:23:20 -0400 | [diff] [blame] | 3709 | #endif |
Steven Rostedt (Red Hat) | 17a280e | 2014-04-10 22:43:37 -0400 | [diff] [blame] | 3710 | "\t\t dump\n" |
| 3711 | "\t\t cpudump\n" |
Steven Rostedt (Red Hat) | 71485c4 | 2014-01-23 00:10:04 -0500 | [diff] [blame] | 3712 | "\t example: echo do_fault:traceoff > set_ftrace_filter\n" |
| 3713 | "\t echo do_trap:traceoff:3 > set_ftrace_filter\n" |
| 3714 | "\t The first one will disable tracing every time do_fault is hit\n" |
| 3715 | "\t The second will disable tracing at most 3 times when do_trap is hit\n" |
| 3716 | "\t The first time do trap is hit and it disables tracing, the\n" |
| 3717 | "\t counter will decrement to 2. If tracing is already disabled,\n" |
| 3718 | "\t the counter will not decrement. It only decrements when the\n" |
| 3719 | "\t trigger did work\n" |
| 3720 | "\t To remove trigger without count:\n" |
| 3721 | "\t echo '!<function>:<trigger> > set_ftrace_filter\n" |
| 3722 | "\t To remove trigger with a count:\n" |
| 3723 | "\t echo '!<function>:<trigger>:0 > set_ftrace_filter\n" |
Steven Rostedt (Red Hat) | 22f4564 | 2013-03-15 17:23:20 -0400 | [diff] [blame] | 3724 | " set_ftrace_notrace\t- echo function name in here to never trace.\n" |
Steven Rostedt (Red Hat) | 71485c4 | 2014-01-23 00:10:04 -0500 | [diff] [blame] | 3725 | "\t accepts: func_full_name, *func_end, func_begin*, *func_middle*\n" |
| 3726 | "\t modules: Can select a group via module command :mod:\n" |
| 3727 | "\t Does not accept triggers\n" |
Steven Rostedt (Red Hat) | 22f4564 | 2013-03-15 17:23:20 -0400 | [diff] [blame] | 3728 | #endif /* CONFIG_DYNAMIC_FTRACE */ |
| 3729 | #ifdef CONFIG_FUNCTION_TRACER |
Steven Rostedt (Red Hat) | 71485c4 | 2014-01-23 00:10:04 -0500 | [diff] [blame] | 3730 | " set_ftrace_pid\t- Write pid(s) to only function trace those pids\n" |
| 3731 | "\t\t (function)\n" |
Steven Rostedt (Red Hat) | 22f4564 | 2013-03-15 17:23:20 -0400 | [diff] [blame] | 3732 | #endif |
| 3733 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER |
| 3734 | " set_graph_function\t- Trace the nested calls of a function (function_graph)\n" |
Namhyung Kim | d048a8c7 | 2014-06-13 01:23:53 +0900 | [diff] [blame] | 3735 | " set_graph_notrace\t- Do not trace the nested calls of a function (function_graph)\n" |
Steven Rostedt (Red Hat) | 22f4564 | 2013-03-15 17:23:20 -0400 | [diff] [blame] | 3736 | " max_graph_depth\t- Trace a limited depth of nested calls (0 is unlimited)\n" |
| 3737 | #endif |
| 3738 | #ifdef CONFIG_TRACER_SNAPSHOT |
Steven Rostedt (Red Hat) | 71485c4 | 2014-01-23 00:10:04 -0500 | [diff] [blame] | 3739 | "\n snapshot\t\t- Like 'trace' but shows the content of the static\n" |
| 3740 | "\t\t\t snapshot buffer. Read the contents for more\n" |
| 3741 | "\t\t\t information\n" |
Steven Rostedt (Red Hat) | 22f4564 | 2013-03-15 17:23:20 -0400 | [diff] [blame] | 3742 | #endif |
zhangwei(Jovi) | 991821c | 2013-07-15 16:32:34 +0800 | [diff] [blame] | 3743 | #ifdef CONFIG_STACK_TRACER |
Steven Rostedt (Red Hat) | 22f4564 | 2013-03-15 17:23:20 -0400 | [diff] [blame] | 3744 | " stack_trace\t\t- Shows the max stack trace when active\n" |
| 3745 | " stack_max_size\t- Shows current max stack size that was traced\n" |
Steven Rostedt (Red Hat) | 71485c4 | 2014-01-23 00:10:04 -0500 | [diff] [blame] | 3746 | "\t\t\t Write into this file to reset the max size (trigger a\n" |
| 3747 | "\t\t\t new trace)\n" |
Steven Rostedt (Red Hat) | 22f4564 | 2013-03-15 17:23:20 -0400 | [diff] [blame] | 3748 | #ifdef CONFIG_DYNAMIC_FTRACE |
Steven Rostedt (Red Hat) | 71485c4 | 2014-01-23 00:10:04 -0500 | [diff] [blame] | 3749 | " stack_trace_filter\t- Like set_ftrace_filter but limits what stack_trace\n" |
| 3750 | "\t\t\t traces\n" |
Steven Rostedt (Red Hat) | 22f4564 | 2013-03-15 17:23:20 -0400 | [diff] [blame] | 3751 | #endif |
zhangwei(Jovi) | 991821c | 2013-07-15 16:32:34 +0800 | [diff] [blame] | 3752 | #endif /* CONFIG_STACK_TRACER */ |
Tom Zanussi | 26f2556 | 2014-01-17 15:11:44 -0600 | [diff] [blame] | 3753 | " events/\t\t- Directory containing all trace event subsystems:\n" |
| 3754 | " enable\t\t- Write 0/1 to enable/disable tracing of all events\n" |
| 3755 | " events/<system>/\t- Directory containing all trace events for <system>:\n" |
Steven Rostedt (Red Hat) | 71485c4 | 2014-01-23 00:10:04 -0500 | [diff] [blame] | 3756 | " enable\t\t- Write 0/1 to enable/disable tracing of all <system>\n" |
| 3757 | "\t\t\t events\n" |
Tom Zanussi | 26f2556 | 2014-01-17 15:11:44 -0600 | [diff] [blame] | 3758 | " filter\t\t- If set, only events passing filter are traced\n" |
Steven Rostedt (Red Hat) | 71485c4 | 2014-01-23 00:10:04 -0500 | [diff] [blame] | 3759 | " events/<system>/<event>/\t- Directory containing control files for\n" |
| 3760 | "\t\t\t <event>:\n" |
Tom Zanussi | 26f2556 | 2014-01-17 15:11:44 -0600 | [diff] [blame] | 3761 | " enable\t\t- Write 0/1 to enable/disable tracing of <event>\n" |
| 3762 | " filter\t\t- If set, only events passing filter are traced\n" |
| 3763 | " trigger\t\t- If set, a command to perform when event is hit\n" |
Steven Rostedt (Red Hat) | 71485c4 | 2014-01-23 00:10:04 -0500 | [diff] [blame] | 3764 | "\t Format: <trigger>[:count][if <filter>]\n" |
| 3765 | "\t trigger: traceon, traceoff\n" |
| 3766 | "\t enable_event:<system>:<event>\n" |
| 3767 | "\t disable_event:<system>:<event>\n" |
Tom Zanussi | 26f2556 | 2014-01-17 15:11:44 -0600 | [diff] [blame] | 3768 | #ifdef CONFIG_STACKTRACE |
Steven Rostedt (Red Hat) | 71485c4 | 2014-01-23 00:10:04 -0500 | [diff] [blame] | 3769 | "\t\t stacktrace\n" |
Tom Zanussi | 26f2556 | 2014-01-17 15:11:44 -0600 | [diff] [blame] | 3770 | #endif |
| 3771 | #ifdef CONFIG_TRACER_SNAPSHOT |
Steven Rostedt (Red Hat) | 71485c4 | 2014-01-23 00:10:04 -0500 | [diff] [blame] | 3772 | "\t\t snapshot\n" |
Tom Zanussi | 26f2556 | 2014-01-17 15:11:44 -0600 | [diff] [blame] | 3773 | #endif |
Steven Rostedt (Red Hat) | 71485c4 | 2014-01-23 00:10:04 -0500 | [diff] [blame] | 3774 | "\t example: echo traceoff > events/block/block_unplug/trigger\n" |
| 3775 | "\t echo traceoff:3 > events/block/block_unplug/trigger\n" |
| 3776 | "\t echo 'enable_event:kmem:kmalloc:3 if nr_rq > 1' > \\\n" |
| 3777 | "\t events/block/block_unplug/trigger\n" |
| 3778 | "\t The first disables tracing every time block_unplug is hit.\n" |
| 3779 | "\t The second disables tracing the first 3 times block_unplug is hit.\n" |
| 3780 | "\t The third enables the kmalloc event the first 3 times block_unplug\n" |
| 3781 | "\t is hit and has value of greater than 1 for the 'nr_rq' event field.\n" |
| 3782 | "\t Like function triggers, the counter is only decremented if it\n" |
| 3783 | "\t enabled or disabled tracing.\n" |
| 3784 | "\t To remove a trigger without a count:\n" |
| 3785 | "\t echo '!<trigger> > <system>/<event>/trigger\n" |
| 3786 | "\t To remove a trigger with a count:\n" |
| 3787 | "\t echo '!<trigger>:0 > <system>/<event>/trigger\n" |
| 3788 | "\t Filters can be ignored when removing a trigger.\n" |
Ingo Molnar | 7bd2f24 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 3789 | ; |
| 3790 | |
| 3791 | static ssize_t |
| 3792 | tracing_readme_read(struct file *filp, char __user *ubuf, |
| 3793 | size_t cnt, loff_t *ppos) |
| 3794 | { |
| 3795 | return simple_read_from_buffer(ubuf, cnt, ppos, |
| 3796 | readme_msg, strlen(readme_msg)); |
| 3797 | } |
| 3798 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 3799 | static const struct file_operations tracing_readme_fops = { |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3800 | .open = tracing_open_generic, |
| 3801 | .read = tracing_readme_read, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 3802 | .llseek = generic_file_llseek, |
Ingo Molnar | 7bd2f24 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 3803 | }; |
| 3804 | |
Yoshihiro YUNOMAE | 42584c8 | 2014-02-20 17:44:31 +0900 | [diff] [blame] | 3805 | static void *saved_cmdlines_next(struct seq_file *m, void *v, loff_t *pos) |
Avadh Patel | 69abe6a | 2009-04-10 16:04:48 -0400 | [diff] [blame] | 3806 | { |
Yoshihiro YUNOMAE | 42584c8 | 2014-02-20 17:44:31 +0900 | [diff] [blame] | 3807 | unsigned int *ptr = v; |
Avadh Patel | 69abe6a | 2009-04-10 16:04:48 -0400 | [diff] [blame] | 3808 | |
Yoshihiro YUNOMAE | 42584c8 | 2014-02-20 17:44:31 +0900 | [diff] [blame] | 3809 | if (*pos || m->count) |
| 3810 | ptr++; |
Avadh Patel | 69abe6a | 2009-04-10 16:04:48 -0400 | [diff] [blame] | 3811 | |
Yoshihiro YUNOMAE | 42584c8 | 2014-02-20 17:44:31 +0900 | [diff] [blame] | 3812 | (*pos)++; |
Avadh Patel | 69abe6a | 2009-04-10 16:04:48 -0400 | [diff] [blame] | 3813 | |
Yoshihiro YUNOMAE | 939c7a4 | 2014-06-05 10:24:27 +0900 | [diff] [blame] | 3814 | for (; ptr < &savedcmd->map_cmdline_to_pid[savedcmd->cmdline_num]; |
| 3815 | ptr++) { |
Yoshihiro YUNOMAE | 42584c8 | 2014-02-20 17:44:31 +0900 | [diff] [blame] | 3816 | if (*ptr == -1 || *ptr == NO_CMDLINE_MAP) |
Avadh Patel | 69abe6a | 2009-04-10 16:04:48 -0400 | [diff] [blame] | 3817 | continue; |
| 3818 | |
Yoshihiro YUNOMAE | 42584c8 | 2014-02-20 17:44:31 +0900 | [diff] [blame] | 3819 | return ptr; |
Avadh Patel | 69abe6a | 2009-04-10 16:04:48 -0400 | [diff] [blame] | 3820 | } |
| 3821 | |
Yoshihiro YUNOMAE | 42584c8 | 2014-02-20 17:44:31 +0900 | [diff] [blame] | 3822 | return NULL; |
| 3823 | } |
Avadh Patel | 69abe6a | 2009-04-10 16:04:48 -0400 | [diff] [blame] | 3824 | |
Yoshihiro YUNOMAE | 42584c8 | 2014-02-20 17:44:31 +0900 | [diff] [blame] | 3825 | static void *saved_cmdlines_start(struct seq_file *m, loff_t *pos) |
| 3826 | { |
| 3827 | void *v; |
| 3828 | loff_t l = 0; |
Avadh Patel | 69abe6a | 2009-04-10 16:04:48 -0400 | [diff] [blame] | 3829 | |
Steven Rostedt (Red Hat) | 4c27e75 | 2014-05-30 10:49:46 -0400 | [diff] [blame] | 3830 | preempt_disable(); |
| 3831 | arch_spin_lock(&trace_cmdline_lock); |
| 3832 | |
Yoshihiro YUNOMAE | 939c7a4 | 2014-06-05 10:24:27 +0900 | [diff] [blame] | 3833 | v = &savedcmd->map_cmdline_to_pid[0]; |
Yoshihiro YUNOMAE | 42584c8 | 2014-02-20 17:44:31 +0900 | [diff] [blame] | 3834 | while (l <= *pos) { |
| 3835 | v = saved_cmdlines_next(m, v, &l); |
| 3836 | if (!v) |
| 3837 | return NULL; |
| 3838 | } |
| 3839 | |
| 3840 | return v; |
| 3841 | } |
| 3842 | |
| 3843 | static void saved_cmdlines_stop(struct seq_file *m, void *v) |
| 3844 | { |
Steven Rostedt (Red Hat) | 4c27e75 | 2014-05-30 10:49:46 -0400 | [diff] [blame] | 3845 | arch_spin_unlock(&trace_cmdline_lock); |
| 3846 | preempt_enable(); |
Yoshihiro YUNOMAE | 42584c8 | 2014-02-20 17:44:31 +0900 | [diff] [blame] | 3847 | } |
| 3848 | |
| 3849 | static int saved_cmdlines_show(struct seq_file *m, void *v) |
| 3850 | { |
| 3851 | char buf[TASK_COMM_LEN]; |
| 3852 | unsigned int *pid = v; |
| 3853 | |
Steven Rostedt (Red Hat) | 4c27e75 | 2014-05-30 10:49:46 -0400 | [diff] [blame] | 3854 | __trace_find_cmdline(*pid, buf); |
Yoshihiro YUNOMAE | 42584c8 | 2014-02-20 17:44:31 +0900 | [diff] [blame] | 3855 | seq_printf(m, "%d %s\n", *pid, buf); |
| 3856 | return 0; |
| 3857 | } |
| 3858 | |
| 3859 | static const struct seq_operations tracing_saved_cmdlines_seq_ops = { |
| 3860 | .start = saved_cmdlines_start, |
| 3861 | .next = saved_cmdlines_next, |
| 3862 | .stop = saved_cmdlines_stop, |
| 3863 | .show = saved_cmdlines_show, |
| 3864 | }; |
| 3865 | |
| 3866 | static int tracing_saved_cmdlines_open(struct inode *inode, struct file *filp) |
| 3867 | { |
| 3868 | if (tracing_disabled) |
| 3869 | return -ENODEV; |
| 3870 | |
| 3871 | return seq_open(filp, &tracing_saved_cmdlines_seq_ops); |
Avadh Patel | 69abe6a | 2009-04-10 16:04:48 -0400 | [diff] [blame] | 3872 | } |
| 3873 | |
| 3874 | static const struct file_operations tracing_saved_cmdlines_fops = { |
Yoshihiro YUNOMAE | 42584c8 | 2014-02-20 17:44:31 +0900 | [diff] [blame] | 3875 | .open = tracing_saved_cmdlines_open, |
| 3876 | .read = seq_read, |
| 3877 | .llseek = seq_lseek, |
| 3878 | .release = seq_release, |
Avadh Patel | 69abe6a | 2009-04-10 16:04:48 -0400 | [diff] [blame] | 3879 | }; |
| 3880 | |
| 3881 | static ssize_t |
Yoshihiro YUNOMAE | 939c7a4 | 2014-06-05 10:24:27 +0900 | [diff] [blame] | 3882 | tracing_saved_cmdlines_size_read(struct file *filp, char __user *ubuf, |
| 3883 | size_t cnt, loff_t *ppos) |
| 3884 | { |
| 3885 | char buf[64]; |
| 3886 | int r; |
| 3887 | |
| 3888 | arch_spin_lock(&trace_cmdline_lock); |
Namhyung Kim | a6af8fb | 2014-06-10 16:11:35 +0900 | [diff] [blame] | 3889 | r = scnprintf(buf, sizeof(buf), "%u\n", savedcmd->cmdline_num); |
Yoshihiro YUNOMAE | 939c7a4 | 2014-06-05 10:24:27 +0900 | [diff] [blame] | 3890 | arch_spin_unlock(&trace_cmdline_lock); |
| 3891 | |
| 3892 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, r); |
| 3893 | } |
| 3894 | |
| 3895 | static void free_saved_cmdlines_buffer(struct saved_cmdlines_buffer *s) |
| 3896 | { |
| 3897 | kfree(s->saved_cmdlines); |
| 3898 | kfree(s->map_cmdline_to_pid); |
| 3899 | kfree(s); |
| 3900 | } |
| 3901 | |
| 3902 | static int tracing_resize_saved_cmdlines(unsigned int val) |
| 3903 | { |
| 3904 | struct saved_cmdlines_buffer *s, *savedcmd_temp; |
| 3905 | |
Namhyung Kim | a6af8fb | 2014-06-10 16:11:35 +0900 | [diff] [blame] | 3906 | s = kmalloc(sizeof(*s), GFP_KERNEL); |
Yoshihiro YUNOMAE | 939c7a4 | 2014-06-05 10:24:27 +0900 | [diff] [blame] | 3907 | if (!s) |
| 3908 | return -ENOMEM; |
| 3909 | |
| 3910 | if (allocate_cmdlines_buffer(val, s) < 0) { |
| 3911 | kfree(s); |
| 3912 | return -ENOMEM; |
| 3913 | } |
| 3914 | |
| 3915 | arch_spin_lock(&trace_cmdline_lock); |
| 3916 | savedcmd_temp = savedcmd; |
| 3917 | savedcmd = s; |
| 3918 | arch_spin_unlock(&trace_cmdline_lock); |
| 3919 | free_saved_cmdlines_buffer(savedcmd_temp); |
| 3920 | |
| 3921 | return 0; |
| 3922 | } |
| 3923 | |
| 3924 | static ssize_t |
| 3925 | tracing_saved_cmdlines_size_write(struct file *filp, const char __user *ubuf, |
| 3926 | size_t cnt, loff_t *ppos) |
| 3927 | { |
| 3928 | unsigned long val; |
| 3929 | int ret; |
| 3930 | |
| 3931 | ret = kstrtoul_from_user(ubuf, cnt, 10, &val); |
| 3932 | if (ret) |
| 3933 | return ret; |
| 3934 | |
| 3935 | /* must have at least 1 entry or less than PID_MAX_DEFAULT */ |
| 3936 | if (!val || val > PID_MAX_DEFAULT) |
| 3937 | return -EINVAL; |
| 3938 | |
| 3939 | ret = tracing_resize_saved_cmdlines((unsigned int)val); |
| 3940 | if (ret < 0) |
| 3941 | return ret; |
| 3942 | |
| 3943 | *ppos += cnt; |
| 3944 | |
| 3945 | return cnt; |
| 3946 | } |
| 3947 | |
| 3948 | static const struct file_operations tracing_saved_cmdlines_size_fops = { |
| 3949 | .open = tracing_open_generic, |
| 3950 | .read = tracing_saved_cmdlines_size_read, |
| 3951 | .write = tracing_saved_cmdlines_size_write, |
| 3952 | }; |
| 3953 | |
Steven Rostedt (Red Hat) | 9828413 | 2015-03-31 17:23:45 -0400 | [diff] [blame] | 3954 | #ifdef CONFIG_TRACE_ENUM_MAP_FILE |
| 3955 | static union trace_enum_map_item * |
| 3956 | update_enum_map(union trace_enum_map_item *ptr) |
| 3957 | { |
| 3958 | if (!ptr->map.enum_string) { |
| 3959 | if (ptr->tail.next) { |
| 3960 | ptr = ptr->tail.next; |
| 3961 | /* Set ptr to the next real item (skip head) */ |
| 3962 | ptr++; |
| 3963 | } else |
| 3964 | return NULL; |
| 3965 | } |
| 3966 | return ptr; |
| 3967 | } |
| 3968 | |
| 3969 | static void *enum_map_next(struct seq_file *m, void *v, loff_t *pos) |
| 3970 | { |
| 3971 | union trace_enum_map_item *ptr = v; |
| 3972 | |
| 3973 | /* |
| 3974 | * Paranoid! If ptr points to end, we don't want to increment past it. |
| 3975 | * This really should never happen. |
| 3976 | */ |
| 3977 | ptr = update_enum_map(ptr); |
| 3978 | if (WARN_ON_ONCE(!ptr)) |
| 3979 | return NULL; |
| 3980 | |
| 3981 | ptr++; |
| 3982 | |
| 3983 | (*pos)++; |
| 3984 | |
| 3985 | ptr = update_enum_map(ptr); |
| 3986 | |
| 3987 | return ptr; |
| 3988 | } |
| 3989 | |
| 3990 | static void *enum_map_start(struct seq_file *m, loff_t *pos) |
| 3991 | { |
| 3992 | union trace_enum_map_item *v; |
| 3993 | loff_t l = 0; |
| 3994 | |
| 3995 | mutex_lock(&trace_enum_mutex); |
| 3996 | |
| 3997 | v = trace_enum_maps; |
| 3998 | if (v) |
| 3999 | v++; |
| 4000 | |
| 4001 | while (v && l < *pos) { |
| 4002 | v = enum_map_next(m, v, &l); |
| 4003 | } |
| 4004 | |
| 4005 | return v; |
| 4006 | } |
| 4007 | |
| 4008 | static void enum_map_stop(struct seq_file *m, void *v) |
| 4009 | { |
| 4010 | mutex_unlock(&trace_enum_mutex); |
| 4011 | } |
| 4012 | |
| 4013 | static int enum_map_show(struct seq_file *m, void *v) |
| 4014 | { |
| 4015 | union trace_enum_map_item *ptr = v; |
| 4016 | |
| 4017 | seq_printf(m, "%s %ld (%s)\n", |
| 4018 | ptr->map.enum_string, ptr->map.enum_value, |
| 4019 | ptr->map.system); |
| 4020 | |
| 4021 | return 0; |
| 4022 | } |
| 4023 | |
| 4024 | static const struct seq_operations tracing_enum_map_seq_ops = { |
| 4025 | .start = enum_map_start, |
| 4026 | .next = enum_map_next, |
| 4027 | .stop = enum_map_stop, |
| 4028 | .show = enum_map_show, |
| 4029 | }; |
| 4030 | |
| 4031 | static int tracing_enum_map_open(struct inode *inode, struct file *filp) |
| 4032 | { |
| 4033 | if (tracing_disabled) |
| 4034 | return -ENODEV; |
| 4035 | |
| 4036 | return seq_open(filp, &tracing_enum_map_seq_ops); |
| 4037 | } |
| 4038 | |
| 4039 | static const struct file_operations tracing_enum_map_fops = { |
| 4040 | .open = tracing_enum_map_open, |
| 4041 | .read = seq_read, |
| 4042 | .llseek = seq_lseek, |
| 4043 | .release = seq_release, |
| 4044 | }; |
| 4045 | |
| 4046 | static inline union trace_enum_map_item * |
| 4047 | trace_enum_jmp_to_tail(union trace_enum_map_item *ptr) |
| 4048 | { |
| 4049 | /* Return tail of array given the head */ |
| 4050 | return ptr + ptr->head.length + 1; |
| 4051 | } |
| 4052 | |
| 4053 | static void |
| 4054 | trace_insert_enum_map_file(struct module *mod, struct trace_enum_map **start, |
| 4055 | int len) |
| 4056 | { |
| 4057 | struct trace_enum_map **stop; |
| 4058 | struct trace_enum_map **map; |
| 4059 | union trace_enum_map_item *map_array; |
| 4060 | union trace_enum_map_item *ptr; |
| 4061 | |
| 4062 | stop = start + len; |
| 4063 | |
| 4064 | /* |
| 4065 | * The trace_enum_maps contains the map plus a head and tail item, |
| 4066 | * where the head holds the module and length of array, and the |
| 4067 | * tail holds a pointer to the next list. |
| 4068 | */ |
| 4069 | map_array = kmalloc(sizeof(*map_array) * (len + 2), GFP_KERNEL); |
| 4070 | if (!map_array) { |
| 4071 | pr_warning("Unable to allocate trace enum mapping\n"); |
| 4072 | return; |
| 4073 | } |
| 4074 | |
| 4075 | mutex_lock(&trace_enum_mutex); |
| 4076 | |
| 4077 | if (!trace_enum_maps) |
| 4078 | trace_enum_maps = map_array; |
| 4079 | else { |
| 4080 | ptr = trace_enum_maps; |
| 4081 | for (;;) { |
| 4082 | ptr = trace_enum_jmp_to_tail(ptr); |
| 4083 | if (!ptr->tail.next) |
| 4084 | break; |
| 4085 | ptr = ptr->tail.next; |
| 4086 | |
| 4087 | } |
| 4088 | ptr->tail.next = map_array; |
| 4089 | } |
| 4090 | map_array->head.mod = mod; |
| 4091 | map_array->head.length = len; |
| 4092 | map_array++; |
| 4093 | |
| 4094 | for (map = start; (unsigned long)map < (unsigned long)stop; map++) { |
| 4095 | map_array->map = **map; |
| 4096 | map_array++; |
| 4097 | } |
| 4098 | memset(map_array, 0, sizeof(*map_array)); |
| 4099 | |
| 4100 | mutex_unlock(&trace_enum_mutex); |
| 4101 | } |
| 4102 | |
| 4103 | static void trace_create_enum_file(struct dentry *d_tracer) |
| 4104 | { |
| 4105 | trace_create_file("enum_map", 0444, d_tracer, |
| 4106 | NULL, &tracing_enum_map_fops); |
| 4107 | } |
| 4108 | |
| 4109 | #else /* CONFIG_TRACE_ENUM_MAP_FILE */ |
| 4110 | static inline void trace_create_enum_file(struct dentry *d_tracer) { } |
| 4111 | static inline void trace_insert_enum_map_file(struct module *mod, |
| 4112 | struct trace_enum_map **start, int len) { } |
| 4113 | #endif /* !CONFIG_TRACE_ENUM_MAP_FILE */ |
| 4114 | |
| 4115 | static void trace_insert_enum_map(struct module *mod, |
| 4116 | struct trace_enum_map **start, int len) |
Steven Rostedt (Red Hat) | 0c564a5 | 2015-03-24 17:58:09 -0400 | [diff] [blame] | 4117 | { |
| 4118 | struct trace_enum_map **map; |
Steven Rostedt (Red Hat) | 0c564a5 | 2015-03-24 17:58:09 -0400 | [diff] [blame] | 4119 | |
| 4120 | if (len <= 0) |
| 4121 | return; |
| 4122 | |
| 4123 | map = start; |
| 4124 | |
| 4125 | trace_event_enum_update(map, len); |
Steven Rostedt (Red Hat) | 9828413 | 2015-03-31 17:23:45 -0400 | [diff] [blame] | 4126 | |
| 4127 | trace_insert_enum_map_file(mod, start, len); |
Steven Rostedt (Red Hat) | 0c564a5 | 2015-03-24 17:58:09 -0400 | [diff] [blame] | 4128 | } |
| 4129 | |
Yoshihiro YUNOMAE | 939c7a4 | 2014-06-05 10:24:27 +0900 | [diff] [blame] | 4130 | static ssize_t |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4131 | tracing_set_trace_read(struct file *filp, char __user *ubuf, |
| 4132 | size_t cnt, loff_t *ppos) |
| 4133 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4134 | struct trace_array *tr = filp->private_data; |
Li Zefan | ee6c2c1 | 2009-09-18 14:06:47 +0800 | [diff] [blame] | 4135 | char buf[MAX_TRACER_SIZE+2]; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4136 | int r; |
| 4137 | |
| 4138 | mutex_lock(&trace_types_lock); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4139 | r = sprintf(buf, "%s\n", tr->current_trace->name); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4140 | mutex_unlock(&trace_types_lock); |
| 4141 | |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4142 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, r); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4143 | } |
| 4144 | |
Arnaldo Carvalho de Melo | b6f11df | 2009-02-05 18:02:00 -0200 | [diff] [blame] | 4145 | int tracer_init(struct tracer *t, struct trace_array *tr) |
| 4146 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4147 | tracing_reset_online_cpus(&tr->trace_buffer); |
Arnaldo Carvalho de Melo | b6f11df | 2009-02-05 18:02:00 -0200 | [diff] [blame] | 4148 | return t->init(tr); |
| 4149 | } |
| 4150 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4151 | static void set_buffer_entries(struct trace_buffer *buf, unsigned long val) |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 4152 | { |
| 4153 | int cpu; |
Steven Rostedt (Red Hat) | 737223f | 2013-03-05 21:13:47 -0500 | [diff] [blame] | 4154 | |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 4155 | for_each_tracing_cpu(cpu) |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4156 | per_cpu_ptr(buf->data, cpu)->entries = val; |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 4157 | } |
| 4158 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4159 | #ifdef CONFIG_TRACER_MAX_TRACE |
Hiraku Toyooka | d60da50 | 2012-10-17 11:56:16 +0900 | [diff] [blame] | 4160 | /* 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] | 4161 | static int resize_buffer_duplicate_size(struct trace_buffer *trace_buf, |
| 4162 | struct trace_buffer *size_buf, int cpu_id) |
Hiraku Toyooka | d60da50 | 2012-10-17 11:56:16 +0900 | [diff] [blame] | 4163 | { |
| 4164 | int cpu, ret = 0; |
| 4165 | |
| 4166 | if (cpu_id == RING_BUFFER_ALL_CPUS) { |
| 4167 | for_each_tracing_cpu(cpu) { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4168 | ret = ring_buffer_resize(trace_buf->buffer, |
| 4169 | per_cpu_ptr(size_buf->data, cpu)->entries, cpu); |
Hiraku Toyooka | d60da50 | 2012-10-17 11:56:16 +0900 | [diff] [blame] | 4170 | if (ret < 0) |
| 4171 | break; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4172 | per_cpu_ptr(trace_buf->data, cpu)->entries = |
| 4173 | per_cpu_ptr(size_buf->data, cpu)->entries; |
Hiraku Toyooka | d60da50 | 2012-10-17 11:56:16 +0900 | [diff] [blame] | 4174 | } |
| 4175 | } else { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4176 | ret = ring_buffer_resize(trace_buf->buffer, |
| 4177 | per_cpu_ptr(size_buf->data, cpu_id)->entries, cpu_id); |
Hiraku Toyooka | d60da50 | 2012-10-17 11:56:16 +0900 | [diff] [blame] | 4178 | if (ret == 0) |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4179 | per_cpu_ptr(trace_buf->data, cpu_id)->entries = |
| 4180 | per_cpu_ptr(size_buf->data, cpu_id)->entries; |
Hiraku Toyooka | d60da50 | 2012-10-17 11:56:16 +0900 | [diff] [blame] | 4181 | } |
| 4182 | |
| 4183 | return ret; |
| 4184 | } |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4185 | #endif /* CONFIG_TRACER_MAX_TRACE */ |
Hiraku Toyooka | d60da50 | 2012-10-17 11:56:16 +0900 | [diff] [blame] | 4186 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4187 | static int __tracing_resize_ring_buffer(struct trace_array *tr, |
| 4188 | unsigned long size, int cpu) |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 4189 | { |
| 4190 | int ret; |
| 4191 | |
| 4192 | /* |
| 4193 | * If kernel or user changes the size of the ring buffer |
Steven Rostedt | a123c52 | 2009-03-12 11:21:08 -0400 | [diff] [blame] | 4194 | * we use the size that was given, and we can forget about |
| 4195 | * expanding it later. |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 4196 | */ |
Steven Rostedt (Red Hat) | 55034cd | 2013-03-07 22:48:09 -0500 | [diff] [blame] | 4197 | ring_buffer_expanded = true; |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 4198 | |
Steven Rostedt | b382ede6 | 2012-10-10 21:44:34 -0400 | [diff] [blame] | 4199 | /* May be called before buffers are initialized */ |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4200 | if (!tr->trace_buffer.buffer) |
Steven Rostedt | b382ede6 | 2012-10-10 21:44:34 -0400 | [diff] [blame] | 4201 | return 0; |
| 4202 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4203 | ret = ring_buffer_resize(tr->trace_buffer.buffer, size, cpu); |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 4204 | if (ret < 0) |
| 4205 | return ret; |
| 4206 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4207 | #ifdef CONFIG_TRACER_MAX_TRACE |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4208 | if (!(tr->flags & TRACE_ARRAY_FL_GLOBAL) || |
| 4209 | !tr->current_trace->use_max_tr) |
KOSAKI Motohiro | ef710e1 | 2010-07-01 14:34:35 +0900 | [diff] [blame] | 4210 | goto out; |
| 4211 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4212 | ret = ring_buffer_resize(tr->max_buffer.buffer, size, cpu); |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 4213 | if (ret < 0) { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4214 | int r = resize_buffer_duplicate_size(&tr->trace_buffer, |
| 4215 | &tr->trace_buffer, cpu); |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 4216 | if (r < 0) { |
Steven Rostedt | a123c52 | 2009-03-12 11:21:08 -0400 | [diff] [blame] | 4217 | /* |
| 4218 | * AARGH! We are left with different |
| 4219 | * size max buffer!!!! |
| 4220 | * The max buffer is our "snapshot" buffer. |
| 4221 | * When a tracer needs a snapshot (one of the |
| 4222 | * latency tracers), it swaps the max buffer |
| 4223 | * with the saved snap shot. We succeeded to |
| 4224 | * update the size of the main buffer, but failed to |
| 4225 | * update the size of the max buffer. But when we tried |
| 4226 | * to reset the main buffer to the original size, we |
| 4227 | * failed there too. This is very unlikely to |
| 4228 | * happen, but if it does, warn and kill all |
| 4229 | * tracing. |
| 4230 | */ |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 4231 | WARN_ON(1); |
| 4232 | tracing_disabled = 1; |
| 4233 | } |
| 4234 | return ret; |
| 4235 | } |
| 4236 | |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 4237 | if (cpu == RING_BUFFER_ALL_CPUS) |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4238 | set_buffer_entries(&tr->max_buffer, size); |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 4239 | else |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4240 | per_cpu_ptr(tr->max_buffer.data, cpu)->entries = size; |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 4241 | |
KOSAKI Motohiro | ef710e1 | 2010-07-01 14:34:35 +0900 | [diff] [blame] | 4242 | out: |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4243 | #endif /* CONFIG_TRACER_MAX_TRACE */ |
| 4244 | |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 4245 | if (cpu == RING_BUFFER_ALL_CPUS) |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4246 | set_buffer_entries(&tr->trace_buffer, size); |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 4247 | else |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4248 | per_cpu_ptr(tr->trace_buffer.data, cpu)->entries = size; |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 4249 | |
| 4250 | return ret; |
| 4251 | } |
| 4252 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4253 | static ssize_t tracing_resize_ring_buffer(struct trace_array *tr, |
| 4254 | unsigned long size, int cpu_id) |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 4255 | { |
Vaibhav Nagarnaik | 83f4031 | 2012-05-03 18:59:50 -0700 | [diff] [blame] | 4256 | int ret = size; |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 4257 | |
| 4258 | mutex_lock(&trace_types_lock); |
| 4259 | |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 4260 | if (cpu_id != RING_BUFFER_ALL_CPUS) { |
| 4261 | /* make sure, this cpu is enabled in the mask */ |
| 4262 | if (!cpumask_test_cpu(cpu_id, tracing_buffer_mask)) { |
| 4263 | ret = -EINVAL; |
| 4264 | goto out; |
| 4265 | } |
| 4266 | } |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 4267 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4268 | ret = __tracing_resize_ring_buffer(tr, size, cpu_id); |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 4269 | if (ret < 0) |
| 4270 | ret = -ENOMEM; |
| 4271 | |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 4272 | out: |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 4273 | mutex_unlock(&trace_types_lock); |
| 4274 | |
| 4275 | return ret; |
| 4276 | } |
| 4277 | |
KOSAKI Motohiro | ef710e1 | 2010-07-01 14:34:35 +0900 | [diff] [blame] | 4278 | |
Steven Rostedt | 1852fcc | 2009-03-11 14:33:00 -0400 | [diff] [blame] | 4279 | /** |
| 4280 | * tracing_update_buffers - used by tracing facility to expand ring buffers |
| 4281 | * |
| 4282 | * To save on memory when the tracing is never used on a system with it |
| 4283 | * configured in. The ring buffers are set to a minimum size. But once |
| 4284 | * a user starts to use the tracing facility, then they need to grow |
| 4285 | * to their default size. |
| 4286 | * |
| 4287 | * This function is to be called when a tracer is about to be used. |
| 4288 | */ |
| 4289 | int tracing_update_buffers(void) |
| 4290 | { |
| 4291 | int ret = 0; |
| 4292 | |
Steven Rostedt | 1027fcb | 2009-03-12 11:33:20 -0400 | [diff] [blame] | 4293 | mutex_lock(&trace_types_lock); |
Steven Rostedt | 1852fcc | 2009-03-11 14:33:00 -0400 | [diff] [blame] | 4294 | if (!ring_buffer_expanded) |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4295 | ret = __tracing_resize_ring_buffer(&global_trace, trace_buf_size, |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 4296 | RING_BUFFER_ALL_CPUS); |
Steven Rostedt | 1027fcb | 2009-03-12 11:33:20 -0400 | [diff] [blame] | 4297 | mutex_unlock(&trace_types_lock); |
Steven Rostedt | 1852fcc | 2009-03-11 14:33:00 -0400 | [diff] [blame] | 4298 | |
| 4299 | return ret; |
| 4300 | } |
| 4301 | |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 4302 | struct trace_option_dentry; |
| 4303 | |
| 4304 | static struct trace_option_dentry * |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4305 | create_trace_option_files(struct trace_array *tr, struct tracer *tracer); |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 4306 | |
| 4307 | static void |
| 4308 | destroy_trace_option_files(struct trace_option_dentry *topts); |
| 4309 | |
Steven Rostedt (Red Hat) | 6b450d2 | 2014-01-14 08:43:01 -0500 | [diff] [blame] | 4310 | /* |
| 4311 | * Used to clear out the tracer before deletion of an instance. |
| 4312 | * Must have trace_types_lock held. |
| 4313 | */ |
| 4314 | static void tracing_set_nop(struct trace_array *tr) |
| 4315 | { |
| 4316 | if (tr->current_trace == &nop_trace) |
| 4317 | return; |
| 4318 | |
Steven Rostedt (Red Hat) | 50512ab | 2014-01-14 08:52:35 -0500 | [diff] [blame] | 4319 | tr->current_trace->enabled--; |
Steven Rostedt (Red Hat) | 6b450d2 | 2014-01-14 08:43:01 -0500 | [diff] [blame] | 4320 | |
| 4321 | if (tr->current_trace->reset) |
| 4322 | tr->current_trace->reset(tr); |
| 4323 | |
| 4324 | tr->current_trace = &nop_trace; |
| 4325 | } |
| 4326 | |
Steven Rostedt (Red Hat) | 09d23a1 | 2015-02-03 12:45:53 -0500 | [diff] [blame] | 4327 | static void update_tracer_options(struct trace_array *tr, struct tracer *t) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4328 | { |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 4329 | static struct trace_option_dentry *topts; |
Steven Rostedt (Red Hat) | 09d23a1 | 2015-02-03 12:45:53 -0500 | [diff] [blame] | 4330 | |
| 4331 | /* Only enable if the directory has been created already. */ |
| 4332 | if (!tr->dir) |
| 4333 | return; |
| 4334 | |
| 4335 | /* Currently, only the top instance has options */ |
| 4336 | if (!(tr->flags & TRACE_ARRAY_FL_GLOBAL)) |
| 4337 | return; |
| 4338 | |
| 4339 | destroy_trace_option_files(topts); |
| 4340 | topts = create_trace_option_files(tr, t); |
| 4341 | } |
| 4342 | |
| 4343 | static int tracing_set_tracer(struct trace_array *tr, const char *buf) |
| 4344 | { |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4345 | struct tracer *t; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4346 | #ifdef CONFIG_TRACER_MAX_TRACE |
Steven Rostedt | 34600f0 | 2013-01-22 13:35:11 -0500 | [diff] [blame] | 4347 | bool had_max_tr; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4348 | #endif |
Peter Zijlstra | d9e5407 | 2008-11-01 19:57:37 +0100 | [diff] [blame] | 4349 | int ret = 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4350 | |
Steven Rostedt | 1027fcb | 2009-03-12 11:33:20 -0400 | [diff] [blame] | 4351 | mutex_lock(&trace_types_lock); |
| 4352 | |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 4353 | if (!ring_buffer_expanded) { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4354 | ret = __tracing_resize_ring_buffer(tr, trace_buf_size, |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 4355 | RING_BUFFER_ALL_CPUS); |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 4356 | if (ret < 0) |
Frederic Weisbecker | 59f586d | 2009-03-15 22:10:39 +0100 | [diff] [blame] | 4357 | goto out; |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 4358 | ret = 0; |
| 4359 | } |
| 4360 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4361 | for (t = trace_types; t; t = t->next) { |
| 4362 | if (strcmp(t->name, buf) == 0) |
| 4363 | break; |
| 4364 | } |
Frederic Weisbecker | c2931e0 | 2008-10-04 22:04:44 +0200 | [diff] [blame] | 4365 | if (!t) { |
| 4366 | ret = -EINVAL; |
| 4367 | goto out; |
| 4368 | } |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4369 | if (t == tr->current_trace) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4370 | goto out; |
| 4371 | |
Steven Rostedt (Red Hat) | 607e2ea | 2013-11-06 22:42:48 -0500 | [diff] [blame] | 4372 | /* Some tracers are only allowed for the top level buffer */ |
| 4373 | if (!trace_ok_for_array(t, tr)) { |
| 4374 | ret = -EINVAL; |
| 4375 | goto out; |
| 4376 | } |
| 4377 | |
Steven Rostedt (Red Hat) | cf6ab6d | 2014-12-15 20:13:31 -0500 | [diff] [blame] | 4378 | /* If trace pipe files are being read, we can't change the tracer */ |
| 4379 | if (tr->current_trace->ref) { |
| 4380 | ret = -EBUSY; |
| 4381 | goto out; |
| 4382 | } |
| 4383 | |
Steven Rostedt | 9f029e8 | 2008-11-12 15:24:24 -0500 | [diff] [blame] | 4384 | trace_branch_disable(); |
Steven Rostedt (Red Hat) | 613f04a | 2013-03-14 15:03:53 -0400 | [diff] [blame] | 4385 | |
Steven Rostedt (Red Hat) | 50512ab | 2014-01-14 08:52:35 -0500 | [diff] [blame] | 4386 | tr->current_trace->enabled--; |
Steven Rostedt (Red Hat) | 613f04a | 2013-03-14 15:03:53 -0400 | [diff] [blame] | 4387 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4388 | if (tr->current_trace->reset) |
| 4389 | tr->current_trace->reset(tr); |
Steven Rostedt | 34600f0 | 2013-01-22 13:35:11 -0500 | [diff] [blame] | 4390 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4391 | /* Current trace needs to be nop_trace before synchronize_sched */ |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4392 | tr->current_trace = &nop_trace; |
Steven Rostedt | 34600f0 | 2013-01-22 13:35:11 -0500 | [diff] [blame] | 4393 | |
Steven Rostedt (Red Hat) | 45ad21c | 2013-03-05 18:25:02 -0500 | [diff] [blame] | 4394 | #ifdef CONFIG_TRACER_MAX_TRACE |
| 4395 | had_max_tr = tr->allocated_snapshot; |
Steven Rostedt | 34600f0 | 2013-01-22 13:35:11 -0500 | [diff] [blame] | 4396 | |
| 4397 | if (had_max_tr && !t->use_max_tr) { |
| 4398 | /* |
| 4399 | * We need to make sure that the update_max_tr sees that |
| 4400 | * current_trace changed to nop_trace to keep it from |
| 4401 | * swapping the buffers after we resize it. |
| 4402 | * The update_max_tr is called from interrupts disabled |
| 4403 | * so a synchronized_sched() is sufficient. |
| 4404 | */ |
| 4405 | synchronize_sched(); |
Steven Rostedt (Red Hat) | 3209cff | 2013-03-12 11:17:54 -0400 | [diff] [blame] | 4406 | free_snapshot(tr); |
KOSAKI Motohiro | ef710e1 | 2010-07-01 14:34:35 +0900 | [diff] [blame] | 4407 | } |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4408 | #endif |
Steven Rostedt (Red Hat) | 09d23a1 | 2015-02-03 12:45:53 -0500 | [diff] [blame] | 4409 | update_tracer_options(tr, t); |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4410 | |
| 4411 | #ifdef CONFIG_TRACER_MAX_TRACE |
Steven Rostedt | 34600f0 | 2013-01-22 13:35:11 -0500 | [diff] [blame] | 4412 | if (t->use_max_tr && !had_max_tr) { |
Steven Rostedt (Red Hat) | 3209cff | 2013-03-12 11:17:54 -0400 | [diff] [blame] | 4413 | ret = alloc_snapshot(tr); |
Hiraku Toyooka | d60da50 | 2012-10-17 11:56:16 +0900 | [diff] [blame] | 4414 | if (ret < 0) |
| 4415 | goto out; |
KOSAKI Motohiro | ef710e1 | 2010-07-01 14:34:35 +0900 | [diff] [blame] | 4416 | } |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4417 | #endif |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 4418 | |
Frederic Weisbecker | 1c80025 | 2008-11-16 05:57:26 +0100 | [diff] [blame] | 4419 | if (t->init) { |
Arnaldo Carvalho de Melo | b6f11df | 2009-02-05 18:02:00 -0200 | [diff] [blame] | 4420 | ret = tracer_init(t, tr); |
Frederic Weisbecker | 1c80025 | 2008-11-16 05:57:26 +0100 | [diff] [blame] | 4421 | if (ret) |
| 4422 | goto out; |
| 4423 | } |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4424 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4425 | tr->current_trace = t; |
Steven Rostedt (Red Hat) | 50512ab | 2014-01-14 08:52:35 -0500 | [diff] [blame] | 4426 | tr->current_trace->enabled++; |
Steven Rostedt | 9f029e8 | 2008-11-12 15:24:24 -0500 | [diff] [blame] | 4427 | trace_branch_enable(tr); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4428 | out: |
| 4429 | mutex_unlock(&trace_types_lock); |
| 4430 | |
Peter Zijlstra | d9e5407 | 2008-11-01 19:57:37 +0100 | [diff] [blame] | 4431 | return ret; |
| 4432 | } |
| 4433 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4434 | static ssize_t |
| 4435 | tracing_set_trace_write(struct file *filp, const char __user *ubuf, |
| 4436 | size_t cnt, loff_t *ppos) |
| 4437 | { |
Steven Rostedt (Red Hat) | 607e2ea | 2013-11-06 22:42:48 -0500 | [diff] [blame] | 4438 | struct trace_array *tr = filp->private_data; |
Li Zefan | ee6c2c1 | 2009-09-18 14:06:47 +0800 | [diff] [blame] | 4439 | char buf[MAX_TRACER_SIZE+1]; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4440 | int i; |
| 4441 | size_t ret; |
Frederic Weisbecker | e6e7a65 | 2008-11-16 05:53:19 +0100 | [diff] [blame] | 4442 | int err; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4443 | |
Steven Rostedt | 60063a6 | 2008-10-28 10:44:24 -0400 | [diff] [blame] | 4444 | ret = cnt; |
| 4445 | |
Li Zefan | ee6c2c1 | 2009-09-18 14:06:47 +0800 | [diff] [blame] | 4446 | if (cnt > MAX_TRACER_SIZE) |
| 4447 | cnt = MAX_TRACER_SIZE; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4448 | |
| 4449 | if (copy_from_user(&buf, ubuf, cnt)) |
| 4450 | return -EFAULT; |
| 4451 | |
| 4452 | buf[cnt] = 0; |
| 4453 | |
| 4454 | /* strip ending whitespace. */ |
| 4455 | for (i = cnt - 1; i > 0 && isspace(buf[i]); i--) |
| 4456 | buf[i] = 0; |
| 4457 | |
Steven Rostedt (Red Hat) | 607e2ea | 2013-11-06 22:42:48 -0500 | [diff] [blame] | 4458 | err = tracing_set_tracer(tr, buf); |
Frederic Weisbecker | e6e7a65 | 2008-11-16 05:53:19 +0100 | [diff] [blame] | 4459 | if (err) |
| 4460 | return err; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4461 | |
Jiri Olsa | cf8517c | 2009-10-23 19:36:16 -0400 | [diff] [blame] | 4462 | *ppos += ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4463 | |
Frederic Weisbecker | c2931e0 | 2008-10-04 22:04:44 +0200 | [diff] [blame] | 4464 | return ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4465 | } |
| 4466 | |
| 4467 | static ssize_t |
Stanislav Fomichev | 6508fa7 | 2014-07-18 15:17:27 +0400 | [diff] [blame] | 4468 | tracing_nsecs_read(unsigned long *ptr, char __user *ubuf, |
| 4469 | size_t cnt, loff_t *ppos) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4470 | { |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4471 | char buf[64]; |
| 4472 | int r; |
| 4473 | |
Steven Rostedt | cffae43 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 4474 | r = snprintf(buf, sizeof(buf), "%ld\n", |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4475 | *ptr == (unsigned long)-1 ? -1 : nsecs_to_usecs(*ptr)); |
Steven Rostedt | cffae43 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 4476 | if (r > sizeof(buf)) |
| 4477 | r = sizeof(buf); |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4478 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, r); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4479 | } |
| 4480 | |
| 4481 | static ssize_t |
Stanislav Fomichev | 6508fa7 | 2014-07-18 15:17:27 +0400 | [diff] [blame] | 4482 | tracing_nsecs_write(unsigned long *ptr, const char __user *ubuf, |
| 4483 | size_t cnt, loff_t *ppos) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4484 | { |
Hannes Eder | 5e39841 | 2009-02-10 19:44:34 +0100 | [diff] [blame] | 4485 | unsigned long val; |
Steven Rostedt | c6caeeb | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 4486 | int ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4487 | |
Peter Huewe | 22fe9b5 | 2011-06-07 21:58:27 +0200 | [diff] [blame] | 4488 | ret = kstrtoul_from_user(ubuf, cnt, 10, &val); |
| 4489 | if (ret) |
Steven Rostedt | c6caeeb | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 4490 | return ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4491 | |
| 4492 | *ptr = val * 1000; |
| 4493 | |
| 4494 | return cnt; |
| 4495 | } |
| 4496 | |
Stanislav Fomichev | 6508fa7 | 2014-07-18 15:17:27 +0400 | [diff] [blame] | 4497 | static ssize_t |
| 4498 | tracing_thresh_read(struct file *filp, char __user *ubuf, |
| 4499 | size_t cnt, loff_t *ppos) |
| 4500 | { |
| 4501 | return tracing_nsecs_read(&tracing_thresh, ubuf, cnt, ppos); |
| 4502 | } |
| 4503 | |
| 4504 | static ssize_t |
| 4505 | tracing_thresh_write(struct file *filp, const char __user *ubuf, |
| 4506 | size_t cnt, loff_t *ppos) |
| 4507 | { |
| 4508 | struct trace_array *tr = filp->private_data; |
| 4509 | int ret; |
| 4510 | |
| 4511 | mutex_lock(&trace_types_lock); |
| 4512 | ret = tracing_nsecs_write(&tracing_thresh, ubuf, cnt, ppos); |
| 4513 | if (ret < 0) |
| 4514 | goto out; |
| 4515 | |
| 4516 | if (tr->current_trace->update_thresh) { |
| 4517 | ret = tr->current_trace->update_thresh(tr); |
| 4518 | if (ret < 0) |
| 4519 | goto out; |
| 4520 | } |
| 4521 | |
| 4522 | ret = cnt; |
| 4523 | out: |
| 4524 | mutex_unlock(&trace_types_lock); |
| 4525 | |
| 4526 | return ret; |
| 4527 | } |
| 4528 | |
| 4529 | static ssize_t |
| 4530 | tracing_max_lat_read(struct file *filp, char __user *ubuf, |
| 4531 | size_t cnt, loff_t *ppos) |
| 4532 | { |
| 4533 | return tracing_nsecs_read(filp->private_data, ubuf, cnt, ppos); |
| 4534 | } |
| 4535 | |
| 4536 | static ssize_t |
| 4537 | tracing_max_lat_write(struct file *filp, const char __user *ubuf, |
| 4538 | size_t cnt, loff_t *ppos) |
| 4539 | { |
| 4540 | return tracing_nsecs_write(filp->private_data, ubuf, cnt, ppos); |
| 4541 | } |
| 4542 | |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4543 | static int tracing_open_pipe(struct inode *inode, struct file *filp) |
| 4544 | { |
Oleg Nesterov | 1554420 | 2013-07-23 17:25:57 +0200 | [diff] [blame] | 4545 | struct trace_array *tr = inode->i_private; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4546 | struct trace_iterator *iter; |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 4547 | int ret = 0; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4548 | |
| 4549 | if (tracing_disabled) |
| 4550 | return -ENODEV; |
| 4551 | |
Steven Rostedt (Red Hat) | 7b85af6 | 2013-07-01 23:34:22 -0400 | [diff] [blame] | 4552 | if (trace_array_get(tr) < 0) |
| 4553 | return -ENODEV; |
| 4554 | |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 4555 | mutex_lock(&trace_types_lock); |
| 4556 | |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4557 | /* create a buffer to store the information to pass to userspace */ |
| 4558 | iter = kzalloc(sizeof(*iter), GFP_KERNEL); |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 4559 | if (!iter) { |
| 4560 | ret = -ENOMEM; |
Alexander Z Lam | f77d09a | 2013-07-18 11:18:44 -0700 | [diff] [blame] | 4561 | __trace_array_put(tr); |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 4562 | goto out; |
| 4563 | } |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4564 | |
Steven Rostedt (Red Hat) | 3a161d9 | 2014-06-25 15:54:42 -0400 | [diff] [blame] | 4565 | trace_seq_init(&iter->seq); |
Steven Rostedt (Red Hat) | d716ff7 | 2014-12-15 22:31:07 -0500 | [diff] [blame] | 4566 | iter->trace = tr->current_trace; |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 4567 | |
| 4568 | if (!alloc_cpumask_var(&iter->started, GFP_KERNEL)) { |
| 4569 | ret = -ENOMEM; |
| 4570 | goto fail; |
Rusty Russell | 4462344 | 2009-01-01 10:12:23 +1030 | [diff] [blame] | 4571 | } |
| 4572 | |
Steven Rostedt | a309720 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 4573 | /* trace pipe does not show start of buffer */ |
Rusty Russell | 4462344 | 2009-01-01 10:12:23 +1030 | [diff] [blame] | 4574 | cpumask_setall(iter->started); |
Steven Rostedt | a309720 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 4575 | |
Steven Rostedt | 112f38a7 | 2009-06-01 15:16:05 -0400 | [diff] [blame] | 4576 | if (trace_flags & TRACE_ITER_LATENCY_FMT) |
| 4577 | iter->iter_flags |= TRACE_FILE_LAT_FMT; |
| 4578 | |
David Sharp | 8be0709 | 2012-11-13 12:18:22 -0800 | [diff] [blame] | 4579 | /* Output in nanoseconds only if we are using a clock in nanoseconds. */ |
Yoshihiro YUNOMAE | 58e8eed | 2013-04-23 10:32:39 +0900 | [diff] [blame] | 4580 | if (trace_clocks[tr->clock_id].in_ns) |
David Sharp | 8be0709 | 2012-11-13 12:18:22 -0800 | [diff] [blame] | 4581 | iter->iter_flags |= TRACE_FILE_TIME_IN_NS; |
| 4582 | |
Oleg Nesterov | 1554420 | 2013-07-23 17:25:57 +0200 | [diff] [blame] | 4583 | iter->tr = tr; |
| 4584 | iter->trace_buffer = &tr->trace_buffer; |
| 4585 | iter->cpu_file = tracing_get_cpu(inode); |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 4586 | mutex_init(&iter->mutex); |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4587 | filp->private_data = iter; |
| 4588 | |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 4589 | if (iter->trace->pipe_open) |
| 4590 | iter->trace->pipe_open(iter); |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 4591 | |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 4592 | nonseekable_open(inode, filp); |
Steven Rostedt (Red Hat) | cf6ab6d | 2014-12-15 20:13:31 -0500 | [diff] [blame] | 4593 | |
| 4594 | tr->current_trace->ref++; |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 4595 | out: |
| 4596 | mutex_unlock(&trace_types_lock); |
| 4597 | return ret; |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 4598 | |
| 4599 | fail: |
| 4600 | kfree(iter->trace); |
| 4601 | kfree(iter); |
Steven Rostedt (Red Hat) | 7b85af6 | 2013-07-01 23:34:22 -0400 | [diff] [blame] | 4602 | __trace_array_put(tr); |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 4603 | mutex_unlock(&trace_types_lock); |
| 4604 | return ret; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4605 | } |
| 4606 | |
| 4607 | static int tracing_release_pipe(struct inode *inode, struct file *file) |
| 4608 | { |
| 4609 | struct trace_iterator *iter = file->private_data; |
Oleg Nesterov | 1554420 | 2013-07-23 17:25:57 +0200 | [diff] [blame] | 4610 | struct trace_array *tr = inode->i_private; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4611 | |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 4612 | mutex_lock(&trace_types_lock); |
| 4613 | |
Steven Rostedt (Red Hat) | cf6ab6d | 2014-12-15 20:13:31 -0500 | [diff] [blame] | 4614 | tr->current_trace->ref--; |
| 4615 | |
Steven Rostedt | 29bf4a5 | 2009-12-09 12:37:43 -0500 | [diff] [blame] | 4616 | if (iter->trace->pipe_close) |
Steven Rostedt | c521efd | 2009-12-07 09:06:24 -0500 | [diff] [blame] | 4617 | iter->trace->pipe_close(iter); |
| 4618 | |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 4619 | mutex_unlock(&trace_types_lock); |
| 4620 | |
Rusty Russell | 4462344 | 2009-01-01 10:12:23 +1030 | [diff] [blame] | 4621 | free_cpumask_var(iter->started); |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 4622 | mutex_destroy(&iter->mutex); |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4623 | kfree(iter); |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4624 | |
Steven Rostedt (Red Hat) | 7b85af6 | 2013-07-01 23:34:22 -0400 | [diff] [blame] | 4625 | trace_array_put(tr); |
| 4626 | |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4627 | return 0; |
| 4628 | } |
| 4629 | |
Soeren Sandmann Pedersen | 2a2cc8f | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 4630 | static unsigned int |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 4631 | 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] | 4632 | { |
Steven Rostedt (Red Hat) | 1569345 | 2013-02-28 19:59:17 -0500 | [diff] [blame] | 4633 | /* Iterators are static, they should be filled or empty */ |
| 4634 | if (trace_buffer_iter(iter, iter->cpu_file)) |
| 4635 | return POLLIN | POLLRDNORM; |
Soeren Sandmann Pedersen | 2a2cc8f | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 4636 | |
Steven Rostedt (Red Hat) | 1569345 | 2013-02-28 19:59:17 -0500 | [diff] [blame] | 4637 | if (trace_flags & TRACE_ITER_BLOCK) |
Soeren Sandmann Pedersen | 2a2cc8f | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 4638 | /* |
| 4639 | * Always select as readable when in blocking mode |
| 4640 | */ |
| 4641 | return POLLIN | POLLRDNORM; |
Steven Rostedt (Red Hat) | 1569345 | 2013-02-28 19:59:17 -0500 | [diff] [blame] | 4642 | else |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4643 | 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] | 4644 | filp, poll_table); |
Soeren Sandmann Pedersen | 2a2cc8f | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 4645 | } |
Soeren Sandmann Pedersen | 2a2cc8f | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 4646 | |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 4647 | static unsigned int |
| 4648 | tracing_poll_pipe(struct file *filp, poll_table *poll_table) |
| 4649 | { |
| 4650 | struct trace_iterator *iter = filp->private_data; |
| 4651 | |
| 4652 | return trace_poll(iter, filp, poll_table); |
Soeren Sandmann Pedersen | 2a2cc8f | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 4653 | } |
| 4654 | |
Steven Rostedt (Red Hat) | d716ff7 | 2014-12-15 22:31:07 -0500 | [diff] [blame] | 4655 | /* Must be called with iter->mutex held. */ |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 4656 | static int tracing_wait_pipe(struct file *filp) |
| 4657 | { |
| 4658 | struct trace_iterator *iter = filp->private_data; |
Steven Rostedt (Red Hat) | 8b8b368 | 2014-06-10 09:46:00 -0400 | [diff] [blame] | 4659 | int ret; |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 4660 | |
| 4661 | while (trace_empty(iter)) { |
| 4662 | |
| 4663 | if ((filp->f_flags & O_NONBLOCK)) { |
| 4664 | return -EAGAIN; |
| 4665 | } |
| 4666 | |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 4667 | /* |
Liu Bo | 250bfd3 | 2013-01-14 10:54:11 +0800 | [diff] [blame] | 4668 | * We block until we read something and tracing is disabled. |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 4669 | * We still block if tracing is disabled, but we have never |
| 4670 | * read anything. This allows a user to cat this file, and |
| 4671 | * then enable tracing. But after we have read something, |
| 4672 | * we give an EOF when tracing is again disabled. |
| 4673 | * |
| 4674 | * iter->pos will be 0 if we haven't read anything. |
| 4675 | */ |
Steven Rostedt (Red Hat) | 10246fa | 2013-07-01 15:58:24 -0400 | [diff] [blame] | 4676 | if (!tracing_is_on() && iter->pos) |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 4677 | break; |
Steven Rostedt (Red Hat) | f487426 | 2014-04-29 16:07:28 -0400 | [diff] [blame] | 4678 | |
| 4679 | mutex_unlock(&iter->mutex); |
| 4680 | |
Rabin Vincent | e30f53a | 2014-11-10 19:46:34 +0100 | [diff] [blame] | 4681 | ret = wait_on_pipe(iter, false); |
Steven Rostedt (Red Hat) | f487426 | 2014-04-29 16:07:28 -0400 | [diff] [blame] | 4682 | |
| 4683 | mutex_lock(&iter->mutex); |
| 4684 | |
Steven Rostedt (Red Hat) | 8b8b368 | 2014-06-10 09:46:00 -0400 | [diff] [blame] | 4685 | if (ret) |
| 4686 | return ret; |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 4687 | } |
| 4688 | |
| 4689 | return 1; |
| 4690 | } |
| 4691 | |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4692 | /* |
| 4693 | * Consumer reader. |
| 4694 | */ |
| 4695 | static ssize_t |
| 4696 | tracing_read_pipe(struct file *filp, char __user *ubuf, |
| 4697 | size_t cnt, loff_t *ppos) |
| 4698 | { |
| 4699 | struct trace_iterator *iter = filp->private_data; |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 4700 | ssize_t sret; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4701 | |
| 4702 | /* return any leftover data */ |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 4703 | sret = trace_seq_to_user(&iter->seq, ubuf, cnt); |
| 4704 | if (sret != -EBUSY) |
| 4705 | return sret; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4706 | |
Steven Rostedt | f952075 | 2009-03-02 14:04:40 -0500 | [diff] [blame] | 4707 | trace_seq_init(&iter->seq); |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4708 | |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 4709 | /* |
| 4710 | * Avoid more than one consumer on a single file descriptor |
| 4711 | * This is just a matter of traces coherency, the ring buffer itself |
| 4712 | * is protected. |
| 4713 | */ |
| 4714 | mutex_lock(&iter->mutex); |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 4715 | if (iter->trace->read) { |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 4716 | sret = iter->trace->read(iter, filp, ubuf, cnt, ppos); |
| 4717 | if (sret) |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 4718 | goto out; |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 4719 | } |
| 4720 | |
Pekka Paalanen | 9ff4b97 | 2008-09-29 20:23:48 +0200 | [diff] [blame] | 4721 | waitagain: |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 4722 | sret = tracing_wait_pipe(filp); |
| 4723 | if (sret <= 0) |
| 4724 | goto out; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4725 | |
| 4726 | /* stop when tracing is finished */ |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 4727 | if (trace_empty(iter)) { |
| 4728 | sret = 0; |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 4729 | goto out; |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 4730 | } |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4731 | |
| 4732 | if (cnt >= PAGE_SIZE) |
| 4733 | cnt = PAGE_SIZE - 1; |
| 4734 | |
Steven Rostedt | 53d0aa7 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 4735 | /* reset all but tr, trace, and overruns */ |
Steven Rostedt | 53d0aa7 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 4736 | memset(&iter->seq, 0, |
| 4737 | sizeof(struct trace_iterator) - |
| 4738 | offsetof(struct trace_iterator, seq)); |
Andrew Vagin | ed5467d | 2013-08-02 21:16:43 +0400 | [diff] [blame] | 4739 | cpumask_clear(iter->started); |
Steven Rostedt | 4823ed7 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 4740 | iter->pos = -1; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4741 | |
Lai Jiangshan | 4f53596 | 2009-05-18 19:35:34 +0800 | [diff] [blame] | 4742 | trace_event_read_lock(); |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 4743 | trace_access_lock(iter->cpu_file); |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 4744 | while (trace_find_next_entry_inc(iter) != NULL) { |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 4745 | enum print_line_t ret; |
Steven Rostedt (Red Hat) | 5ac48378 | 2014-11-14 15:49:41 -0500 | [diff] [blame] | 4746 | int save_len = iter->seq.seq.len; |
Steven Rostedt | 088b1e42 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 4747 | |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 4748 | ret = print_trace_line(iter); |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 4749 | if (ret == TRACE_TYPE_PARTIAL_LINE) { |
Steven Rostedt | 088b1e42 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 4750 | /* don't print partial lines */ |
Steven Rostedt (Red Hat) | 5ac48378 | 2014-11-14 15:49:41 -0500 | [diff] [blame] | 4751 | iter->seq.seq.len = save_len; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4752 | break; |
Steven Rostedt | 088b1e42 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 4753 | } |
Frederic Weisbecker | b91facc | 2009-02-06 18:30:44 +0100 | [diff] [blame] | 4754 | if (ret != TRACE_TYPE_NO_CONSUME) |
| 4755 | trace_consume(iter); |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4756 | |
Steven Rostedt (Red Hat) | 5ac48378 | 2014-11-14 15:49:41 -0500 | [diff] [blame] | 4757 | if (trace_seq_used(&iter->seq) >= cnt) |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4758 | break; |
Jiri Olsa | ee5e51f | 2011-03-25 12:05:18 +0100 | [diff] [blame] | 4759 | |
| 4760 | /* |
| 4761 | * Setting the full flag means we reached the trace_seq buffer |
| 4762 | * size and we should leave by partial output condition above. |
| 4763 | * One of the trace_seq_* functions is not used properly. |
| 4764 | */ |
| 4765 | WARN_ONCE(iter->seq.full, "full flag set for trace type %d", |
| 4766 | iter->ent->type); |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4767 | } |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 4768 | trace_access_unlock(iter->cpu_file); |
Lai Jiangshan | 4f53596 | 2009-05-18 19:35:34 +0800 | [diff] [blame] | 4769 | trace_event_read_unlock(); |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4770 | |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4771 | /* Now copy what we have to the user */ |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 4772 | sret = trace_seq_to_user(&iter->seq, ubuf, cnt); |
Steven Rostedt (Red Hat) | 5ac48378 | 2014-11-14 15:49:41 -0500 | [diff] [blame] | 4773 | if (iter->seq.seq.readpos >= trace_seq_used(&iter->seq)) |
Steven Rostedt | f952075 | 2009-03-02 14:04:40 -0500 | [diff] [blame] | 4774 | trace_seq_init(&iter->seq); |
Pekka Paalanen | 9ff4b97 | 2008-09-29 20:23:48 +0200 | [diff] [blame] | 4775 | |
| 4776 | /* |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 4777 | * 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] | 4778 | * entries, go back to wait for more entries. |
| 4779 | */ |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 4780 | if (sret == -EBUSY) |
Pekka Paalanen | 9ff4b97 | 2008-09-29 20:23:48 +0200 | [diff] [blame] | 4781 | goto waitagain; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4782 | |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 4783 | out: |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 4784 | mutex_unlock(&iter->mutex); |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 4785 | |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 4786 | return sret; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4787 | } |
| 4788 | |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4789 | static void tracing_spd_release_pipe(struct splice_pipe_desc *spd, |
| 4790 | unsigned int idx) |
| 4791 | { |
| 4792 | __free_page(spd->pages[idx]); |
| 4793 | } |
| 4794 | |
Alexey Dobriyan | 28dfef8 | 2009-12-15 16:46:48 -0800 | [diff] [blame] | 4795 | static const struct pipe_buf_operations tracing_pipe_buf_ops = { |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 4796 | .can_merge = 0, |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 4797 | .confirm = generic_pipe_buf_confirm, |
Al Viro | 92fdd98 | 2014-01-17 07:53:39 -0500 | [diff] [blame] | 4798 | .release = generic_pipe_buf_release, |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 4799 | .steal = generic_pipe_buf_steal, |
| 4800 | .get = generic_pipe_buf_get, |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4801 | }; |
| 4802 | |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 4803 | static size_t |
Frederic Weisbecker | fa7c7f6 | 2009-02-11 02:51:30 +0100 | [diff] [blame] | 4804 | tracing_fill_pipe_page(size_t rem, struct trace_iterator *iter) |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 4805 | { |
| 4806 | size_t count; |
Steven Rostedt (Red Hat) | 74f06bb | 2014-11-17 13:12:22 -0500 | [diff] [blame] | 4807 | int save_len; |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 4808 | int ret; |
| 4809 | |
| 4810 | /* Seq buffer is page-sized, exactly what we need. */ |
| 4811 | for (;;) { |
Steven Rostedt (Red Hat) | 74f06bb | 2014-11-17 13:12:22 -0500 | [diff] [blame] | 4812 | save_len = iter->seq.seq.len; |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 4813 | ret = print_trace_line(iter); |
Steven Rostedt (Red Hat) | 74f06bb | 2014-11-17 13:12:22 -0500 | [diff] [blame] | 4814 | |
| 4815 | if (trace_seq_has_overflowed(&iter->seq)) { |
| 4816 | iter->seq.seq.len = save_len; |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 4817 | break; |
| 4818 | } |
Steven Rostedt (Red Hat) | 74f06bb | 2014-11-17 13:12:22 -0500 | [diff] [blame] | 4819 | |
| 4820 | /* |
| 4821 | * This should not be hit, because it should only |
| 4822 | * be set if the iter->seq overflowed. But check it |
| 4823 | * anyway to be safe. |
| 4824 | */ |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 4825 | if (ret == TRACE_TYPE_PARTIAL_LINE) { |
Steven Rostedt (Red Hat) | 74f06bb | 2014-11-17 13:12:22 -0500 | [diff] [blame] | 4826 | iter->seq.seq.len = save_len; |
| 4827 | break; |
| 4828 | } |
| 4829 | |
Steven Rostedt (Red Hat) | 5ac48378 | 2014-11-14 15:49:41 -0500 | [diff] [blame] | 4830 | count = trace_seq_used(&iter->seq) - save_len; |
Steven Rostedt (Red Hat) | 74f06bb | 2014-11-17 13:12:22 -0500 | [diff] [blame] | 4831 | if (rem < count) { |
| 4832 | rem = 0; |
| 4833 | iter->seq.seq.len = save_len; |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 4834 | break; |
| 4835 | } |
| 4836 | |
Lai Jiangshan | 74e7ff8 | 2009-07-28 20:17:22 +0800 | [diff] [blame] | 4837 | if (ret != TRACE_TYPE_NO_CONSUME) |
| 4838 | trace_consume(iter); |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 4839 | rem -= count; |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 4840 | if (!trace_find_next_entry_inc(iter)) { |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 4841 | rem = 0; |
| 4842 | iter->ent = NULL; |
| 4843 | break; |
| 4844 | } |
| 4845 | } |
| 4846 | |
| 4847 | return rem; |
| 4848 | } |
| 4849 | |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4850 | static ssize_t tracing_splice_read_pipe(struct file *filp, |
| 4851 | loff_t *ppos, |
| 4852 | struct pipe_inode_info *pipe, |
| 4853 | size_t len, |
| 4854 | unsigned int flags) |
| 4855 | { |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 4856 | struct page *pages_def[PIPE_DEF_BUFFERS]; |
| 4857 | struct partial_page partial_def[PIPE_DEF_BUFFERS]; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4858 | struct trace_iterator *iter = filp->private_data; |
| 4859 | struct splice_pipe_desc spd = { |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 4860 | .pages = pages_def, |
| 4861 | .partial = partial_def, |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 4862 | .nr_pages = 0, /* This gets updated below. */ |
Eric Dumazet | 047fe36 | 2012-06-12 15:24:40 +0200 | [diff] [blame] | 4863 | .nr_pages_max = PIPE_DEF_BUFFERS, |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 4864 | .flags = flags, |
| 4865 | .ops = &tracing_pipe_buf_ops, |
| 4866 | .spd_release = tracing_spd_release_pipe, |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4867 | }; |
| 4868 | ssize_t ret; |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 4869 | size_t rem; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4870 | unsigned int i; |
| 4871 | |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 4872 | if (splice_grow_spd(pipe, &spd)) |
| 4873 | return -ENOMEM; |
| 4874 | |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 4875 | mutex_lock(&iter->mutex); |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4876 | |
| 4877 | if (iter->trace->splice_read) { |
| 4878 | ret = iter->trace->splice_read(iter, filp, |
| 4879 | ppos, pipe, len, flags); |
| 4880 | if (ret) |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 4881 | goto out_err; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4882 | } |
| 4883 | |
| 4884 | ret = tracing_wait_pipe(filp); |
| 4885 | if (ret <= 0) |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 4886 | goto out_err; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4887 | |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 4888 | if (!iter->ent && !trace_find_next_entry_inc(iter)) { |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4889 | ret = -EFAULT; |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 4890 | goto out_err; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4891 | } |
| 4892 | |
Lai Jiangshan | 4f53596 | 2009-05-18 19:35:34 +0800 | [diff] [blame] | 4893 | trace_event_read_lock(); |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 4894 | trace_access_lock(iter->cpu_file); |
Lai Jiangshan | 4f53596 | 2009-05-18 19:35:34 +0800 | [diff] [blame] | 4895 | |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4896 | /* Fill as many pages as possible. */ |
Al Viro | a786c06 | 2014-04-11 12:01:03 -0400 | [diff] [blame] | 4897 | for (i = 0, rem = len; i < spd.nr_pages_max && rem; i++) { |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 4898 | spd.pages[i] = alloc_page(GFP_KERNEL); |
| 4899 | if (!spd.pages[i]) |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 4900 | break; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4901 | |
Frederic Weisbecker | fa7c7f6 | 2009-02-11 02:51:30 +0100 | [diff] [blame] | 4902 | rem = tracing_fill_pipe_page(rem, iter); |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4903 | |
| 4904 | /* Copy the data into the page, so we can start over. */ |
| 4905 | ret = trace_seq_to_buffer(&iter->seq, |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 4906 | page_address(spd.pages[i]), |
Steven Rostedt (Red Hat) | 5ac48378 | 2014-11-14 15:49:41 -0500 | [diff] [blame] | 4907 | trace_seq_used(&iter->seq)); |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4908 | if (ret < 0) { |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 4909 | __free_page(spd.pages[i]); |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4910 | break; |
| 4911 | } |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 4912 | spd.partial[i].offset = 0; |
Steven Rostedt (Red Hat) | 5ac48378 | 2014-11-14 15:49:41 -0500 | [diff] [blame] | 4913 | spd.partial[i].len = trace_seq_used(&iter->seq); |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4914 | |
Steven Rostedt | f952075 | 2009-03-02 14:04:40 -0500 | [diff] [blame] | 4915 | trace_seq_init(&iter->seq); |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4916 | } |
| 4917 | |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 4918 | trace_access_unlock(iter->cpu_file); |
Lai Jiangshan | 4f53596 | 2009-05-18 19:35:34 +0800 | [diff] [blame] | 4919 | trace_event_read_unlock(); |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 4920 | mutex_unlock(&iter->mutex); |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4921 | |
| 4922 | spd.nr_pages = i; |
| 4923 | |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 4924 | ret = splice_to_pipe(pipe, &spd); |
| 4925 | out: |
Eric Dumazet | 047fe36 | 2012-06-12 15:24:40 +0200 | [diff] [blame] | 4926 | splice_shrink_spd(&spd); |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 4927 | return ret; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4928 | |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 4929 | out_err: |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 4930 | mutex_unlock(&iter->mutex); |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 4931 | goto out; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4932 | } |
| 4933 | |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 4934 | static ssize_t |
| 4935 | tracing_entries_read(struct file *filp, char __user *ubuf, |
| 4936 | size_t cnt, loff_t *ppos) |
| 4937 | { |
Oleg Nesterov | 0bc392e | 2013-07-23 17:26:06 +0200 | [diff] [blame] | 4938 | struct inode *inode = file_inode(filp); |
| 4939 | struct trace_array *tr = inode->i_private; |
| 4940 | int cpu = tracing_get_cpu(inode); |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 4941 | char buf[64]; |
| 4942 | int r = 0; |
| 4943 | ssize_t ret; |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 4944 | |
Steven Rostedt | db526ca | 2009-03-12 13:53:25 -0400 | [diff] [blame] | 4945 | mutex_lock(&trace_types_lock); |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 4946 | |
Oleg Nesterov | 0bc392e | 2013-07-23 17:26:06 +0200 | [diff] [blame] | 4947 | if (cpu == RING_BUFFER_ALL_CPUS) { |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 4948 | int cpu, buf_size_same; |
| 4949 | unsigned long size; |
| 4950 | |
| 4951 | size = 0; |
| 4952 | buf_size_same = 1; |
| 4953 | /* check if all cpu sizes are same */ |
| 4954 | for_each_tracing_cpu(cpu) { |
| 4955 | /* fill in the size from first enabled cpu */ |
| 4956 | if (size == 0) |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4957 | size = per_cpu_ptr(tr->trace_buffer.data, cpu)->entries; |
| 4958 | if (size != per_cpu_ptr(tr->trace_buffer.data, cpu)->entries) { |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 4959 | buf_size_same = 0; |
| 4960 | break; |
| 4961 | } |
| 4962 | } |
| 4963 | |
| 4964 | if (buf_size_same) { |
| 4965 | if (!ring_buffer_expanded) |
| 4966 | r = sprintf(buf, "%lu (expanded: %lu)\n", |
| 4967 | size >> 10, |
| 4968 | trace_buf_size >> 10); |
| 4969 | else |
| 4970 | r = sprintf(buf, "%lu\n", size >> 10); |
| 4971 | } else |
| 4972 | r = sprintf(buf, "X\n"); |
| 4973 | } else |
Oleg Nesterov | 0bc392e | 2013-07-23 17:26:06 +0200 | [diff] [blame] | 4974 | r = sprintf(buf, "%lu\n", per_cpu_ptr(tr->trace_buffer.data, cpu)->entries >> 10); |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 4975 | |
Steven Rostedt | db526ca | 2009-03-12 13:53:25 -0400 | [diff] [blame] | 4976 | mutex_unlock(&trace_types_lock); |
| 4977 | |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 4978 | ret = simple_read_from_buffer(ubuf, cnt, ppos, buf, r); |
| 4979 | return ret; |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 4980 | } |
| 4981 | |
| 4982 | static ssize_t |
| 4983 | tracing_entries_write(struct file *filp, const char __user *ubuf, |
| 4984 | size_t cnt, loff_t *ppos) |
| 4985 | { |
Oleg Nesterov | 0bc392e | 2013-07-23 17:26:06 +0200 | [diff] [blame] | 4986 | struct inode *inode = file_inode(filp); |
| 4987 | struct trace_array *tr = inode->i_private; |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 4988 | unsigned long val; |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 4989 | int ret; |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 4990 | |
Peter Huewe | 22fe9b5 | 2011-06-07 21:58:27 +0200 | [diff] [blame] | 4991 | ret = kstrtoul_from_user(ubuf, cnt, 10, &val); |
| 4992 | if (ret) |
Steven Rostedt | c6caeeb | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 4993 | return ret; |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 4994 | |
| 4995 | /* must have at least 1 entry */ |
| 4996 | if (!val) |
| 4997 | return -EINVAL; |
| 4998 | |
Steven Rostedt | 1696b2b | 2008-11-13 00:09:35 -0500 | [diff] [blame] | 4999 | /* value is in KB */ |
| 5000 | val <<= 10; |
Oleg Nesterov | 0bc392e | 2013-07-23 17:26:06 +0200 | [diff] [blame] | 5001 | ret = tracing_resize_ring_buffer(tr, val, tracing_get_cpu(inode)); |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 5002 | if (ret < 0) |
| 5003 | return ret; |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 5004 | |
Jiri Olsa | cf8517c | 2009-10-23 19:36:16 -0400 | [diff] [blame] | 5005 | *ppos += cnt; |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 5006 | |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 5007 | return cnt; |
| 5008 | } |
Steven Rostedt | bf5e651 | 2008-11-10 21:46:00 -0500 | [diff] [blame] | 5009 | |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 5010 | static ssize_t |
Vaibhav Nagarnaik | f81ab07 | 2011-08-16 14:46:15 -0700 | [diff] [blame] | 5011 | tracing_total_entries_read(struct file *filp, char __user *ubuf, |
| 5012 | size_t cnt, loff_t *ppos) |
| 5013 | { |
| 5014 | struct trace_array *tr = filp->private_data; |
| 5015 | char buf[64]; |
| 5016 | int r, cpu; |
| 5017 | unsigned long size = 0, expanded_size = 0; |
| 5018 | |
| 5019 | mutex_lock(&trace_types_lock); |
| 5020 | for_each_tracing_cpu(cpu) { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5021 | size += per_cpu_ptr(tr->trace_buffer.data, cpu)->entries >> 10; |
Vaibhav Nagarnaik | f81ab07 | 2011-08-16 14:46:15 -0700 | [diff] [blame] | 5022 | if (!ring_buffer_expanded) |
| 5023 | expanded_size += trace_buf_size >> 10; |
| 5024 | } |
| 5025 | if (ring_buffer_expanded) |
| 5026 | r = sprintf(buf, "%lu\n", size); |
| 5027 | else |
| 5028 | r = sprintf(buf, "%lu (expanded: %lu)\n", size, expanded_size); |
| 5029 | mutex_unlock(&trace_types_lock); |
| 5030 | |
| 5031 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, r); |
| 5032 | } |
| 5033 | |
| 5034 | static ssize_t |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 5035 | tracing_free_buffer_write(struct file *filp, const char __user *ubuf, |
| 5036 | size_t cnt, loff_t *ppos) |
| 5037 | { |
| 5038 | /* |
| 5039 | * There is no need to read what the user has written, this function |
| 5040 | * is just to make sure that there is no error when "echo" is used |
| 5041 | */ |
| 5042 | |
| 5043 | *ppos += cnt; |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 5044 | |
| 5045 | return cnt; |
| 5046 | } |
| 5047 | |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 5048 | static int |
| 5049 | tracing_free_buffer_release(struct inode *inode, struct file *filp) |
| 5050 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5051 | struct trace_array *tr = inode->i_private; |
| 5052 | |
Steven Rostedt | cf30cf6 | 2011-06-14 22:44:07 -0400 | [diff] [blame] | 5053 | /* disable tracing ? */ |
| 5054 | if (trace_flags & TRACE_ITER_STOP_ON_FREE) |
Alexander Z Lam | 711e124 | 2013-08-02 18:36:15 -0700 | [diff] [blame] | 5055 | tracer_tracing_off(tr); |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 5056 | /* resize the ring buffer to 0 */ |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5057 | tracing_resize_ring_buffer(tr, 0, RING_BUFFER_ALL_CPUS); |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 5058 | |
Steven Rostedt (Red Hat) | 7b85af6 | 2013-07-01 23:34:22 -0400 | [diff] [blame] | 5059 | trace_array_put(tr); |
| 5060 | |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 5061 | return 0; |
| 5062 | } |
| 5063 | |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 5064 | static ssize_t |
| 5065 | tracing_mark_write(struct file *filp, const char __user *ubuf, |
| 5066 | size_t cnt, loff_t *fpos) |
| 5067 | { |
Steven Rostedt | d696b58 | 2011-09-22 11:50:27 -0400 | [diff] [blame] | 5068 | unsigned long addr = (unsigned long)ubuf; |
Alexander Z Lam | 2d71619 | 2013-07-01 15:31:24 -0700 | [diff] [blame] | 5069 | struct trace_array *tr = filp->private_data; |
Steven Rostedt | d696b58 | 2011-09-22 11:50:27 -0400 | [diff] [blame] | 5070 | struct ring_buffer_event *event; |
| 5071 | struct ring_buffer *buffer; |
| 5072 | struct print_entry *entry; |
| 5073 | unsigned long irq_flags; |
| 5074 | struct page *pages[2]; |
Steven Rostedt | 6edb2a8 | 2012-05-11 23:28:49 -0400 | [diff] [blame] | 5075 | void *map_page[2]; |
Steven Rostedt | d696b58 | 2011-09-22 11:50:27 -0400 | [diff] [blame] | 5076 | int nr_pages = 1; |
| 5077 | ssize_t written; |
Steven Rostedt | d696b58 | 2011-09-22 11:50:27 -0400 | [diff] [blame] | 5078 | int offset; |
| 5079 | int size; |
| 5080 | int len; |
| 5081 | int ret; |
Steven Rostedt | 6edb2a8 | 2012-05-11 23:28:49 -0400 | [diff] [blame] | 5082 | int i; |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 5083 | |
Steven Rostedt | c76f069 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 5084 | if (tracing_disabled) |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 5085 | return -EINVAL; |
| 5086 | |
Mandeep Singh Baines | 5224c3a | 2012-09-07 18:12:19 -0700 | [diff] [blame] | 5087 | if (!(trace_flags & TRACE_ITER_MARKERS)) |
| 5088 | return -EINVAL; |
| 5089 | |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 5090 | if (cnt > TRACE_BUF_SIZE) |
| 5091 | cnt = TRACE_BUF_SIZE; |
| 5092 | |
Steven Rostedt | d696b58 | 2011-09-22 11:50:27 -0400 | [diff] [blame] | 5093 | /* |
| 5094 | * Userspace is injecting traces into the kernel trace buffer. |
| 5095 | * We want to be as non intrusive as possible. |
| 5096 | * To do so, we do not want to allocate any special buffers |
| 5097 | * or take any locks, but instead write the userspace data |
| 5098 | * straight into the ring buffer. |
| 5099 | * |
| 5100 | * First we need to pin the userspace buffer into memory, |
| 5101 | * which, most likely it is, because it just referenced it. |
| 5102 | * But there's no guarantee that it is. By using get_user_pages_fast() |
| 5103 | * and kmap_atomic/kunmap_atomic() we can get access to the |
| 5104 | * pages directly. We then write the data directly into the |
| 5105 | * ring buffer. |
| 5106 | */ |
| 5107 | BUILD_BUG_ON(TRACE_BUF_SIZE >= PAGE_SIZE); |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 5108 | |
Steven Rostedt | d696b58 | 2011-09-22 11:50:27 -0400 | [diff] [blame] | 5109 | /* check if we cross pages */ |
| 5110 | if ((addr & PAGE_MASK) != ((addr + cnt) & PAGE_MASK)) |
| 5111 | nr_pages = 2; |
| 5112 | |
| 5113 | offset = addr & (PAGE_SIZE - 1); |
| 5114 | addr &= PAGE_MASK; |
| 5115 | |
| 5116 | ret = get_user_pages_fast(addr, nr_pages, 0, pages); |
| 5117 | if (ret < nr_pages) { |
| 5118 | while (--ret >= 0) |
| 5119 | put_page(pages[ret]); |
| 5120 | written = -EFAULT; |
| 5121 | goto out; |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 5122 | } |
| 5123 | |
Steven Rostedt | 6edb2a8 | 2012-05-11 23:28:49 -0400 | [diff] [blame] | 5124 | for (i = 0; i < nr_pages; i++) |
| 5125 | map_page[i] = kmap_atomic(pages[i]); |
Steven Rostedt | d696b58 | 2011-09-22 11:50:27 -0400 | [diff] [blame] | 5126 | |
| 5127 | local_save_flags(irq_flags); |
| 5128 | size = sizeof(*entry) + cnt + 2; /* possible \n added */ |
Alexander Z Lam | 2d71619 | 2013-07-01 15:31:24 -0700 | [diff] [blame] | 5129 | buffer = tr->trace_buffer.buffer; |
Steven Rostedt | d696b58 | 2011-09-22 11:50:27 -0400 | [diff] [blame] | 5130 | event = trace_buffer_lock_reserve(buffer, TRACE_PRINT, size, |
| 5131 | irq_flags, preempt_count()); |
| 5132 | if (!event) { |
| 5133 | /* Ring buffer disabled, return as if not open for write */ |
| 5134 | written = -EBADF; |
| 5135 | goto out_unlock; |
| 5136 | } |
| 5137 | |
| 5138 | entry = ring_buffer_event_data(event); |
| 5139 | entry->ip = _THIS_IP_; |
| 5140 | |
| 5141 | if (nr_pages == 2) { |
| 5142 | len = PAGE_SIZE - offset; |
Steven Rostedt | 6edb2a8 | 2012-05-11 23:28:49 -0400 | [diff] [blame] | 5143 | memcpy(&entry->buf, map_page[0] + offset, len); |
| 5144 | memcpy(&entry->buf[len], map_page[1], cnt - len); |
Steven Rostedt | d696b58 | 2011-09-22 11:50:27 -0400 | [diff] [blame] | 5145 | } else |
Steven Rostedt | 6edb2a8 | 2012-05-11 23:28:49 -0400 | [diff] [blame] | 5146 | memcpy(&entry->buf, map_page[0] + offset, cnt); |
Steven Rostedt | d696b58 | 2011-09-22 11:50:27 -0400 | [diff] [blame] | 5147 | |
| 5148 | if (entry->buf[cnt - 1] != '\n') { |
| 5149 | entry->buf[cnt] = '\n'; |
| 5150 | entry->buf[cnt + 1] = '\0'; |
| 5151 | } else |
| 5152 | entry->buf[cnt] = '\0'; |
| 5153 | |
Steven Rostedt | 7ffbd48 | 2012-10-11 12:14:25 -0400 | [diff] [blame] | 5154 | __buffer_unlock_commit(buffer, event); |
Steven Rostedt | d696b58 | 2011-09-22 11:50:27 -0400 | [diff] [blame] | 5155 | |
| 5156 | written = cnt; |
| 5157 | |
Marcin Slusarz | 1aa54bc | 2010-07-28 01:18:01 +0200 | [diff] [blame] | 5158 | *fpos += written; |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 5159 | |
Steven Rostedt | d696b58 | 2011-09-22 11:50:27 -0400 | [diff] [blame] | 5160 | out_unlock: |
Vikram Mulukutla | 7215853 | 2014-12-17 18:50:56 -0800 | [diff] [blame] | 5161 | for (i = nr_pages - 1; i >= 0; i--) { |
Steven Rostedt | 6edb2a8 | 2012-05-11 23:28:49 -0400 | [diff] [blame] | 5162 | kunmap_atomic(map_page[i]); |
| 5163 | put_page(pages[i]); |
| 5164 | } |
Steven Rostedt | d696b58 | 2011-09-22 11:50:27 -0400 | [diff] [blame] | 5165 | out: |
Marcin Slusarz | 1aa54bc | 2010-07-28 01:18:01 +0200 | [diff] [blame] | 5166 | return written; |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 5167 | } |
| 5168 | |
Li Zefan | 13f16d2 | 2009-12-08 11:16:11 +0800 | [diff] [blame] | 5169 | static int tracing_clock_show(struct seq_file *m, void *v) |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 5170 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5171 | struct trace_array *tr = m->private; |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 5172 | int i; |
| 5173 | |
| 5174 | for (i = 0; i < ARRAY_SIZE(trace_clocks); i++) |
Li Zefan | 13f16d2 | 2009-12-08 11:16:11 +0800 | [diff] [blame] | 5175 | seq_printf(m, |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 5176 | "%s%s%s%s", i ? " " : "", |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5177 | i == tr->clock_id ? "[" : "", trace_clocks[i].name, |
| 5178 | i == tr->clock_id ? "]" : ""); |
Li Zefan | 13f16d2 | 2009-12-08 11:16:11 +0800 | [diff] [blame] | 5179 | seq_putc(m, '\n'); |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 5180 | |
Li Zefan | 13f16d2 | 2009-12-08 11:16:11 +0800 | [diff] [blame] | 5181 | return 0; |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 5182 | } |
| 5183 | |
Steven Rostedt | e1e232c | 2014-02-10 23:38:46 -0500 | [diff] [blame] | 5184 | static int tracing_set_clock(struct trace_array *tr, const char *clockstr) |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 5185 | { |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 5186 | int i; |
| 5187 | |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 5188 | for (i = 0; i < ARRAY_SIZE(trace_clocks); i++) { |
| 5189 | if (strcmp(trace_clocks[i].name, clockstr) == 0) |
| 5190 | break; |
| 5191 | } |
| 5192 | if (i == ARRAY_SIZE(trace_clocks)) |
| 5193 | return -EINVAL; |
| 5194 | |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 5195 | mutex_lock(&trace_types_lock); |
| 5196 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5197 | tr->clock_id = i; |
| 5198 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5199 | ring_buffer_set_clock(tr->trace_buffer.buffer, trace_clocks[i].func); |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 5200 | |
David Sharp | 60303ed | 2012-10-11 16:27:52 -0700 | [diff] [blame] | 5201 | /* |
| 5202 | * New clock may not be consistent with the previous clock. |
| 5203 | * Reset the buffer so that it doesn't have incomparable timestamps. |
| 5204 | */ |
Alexander Z Lam | 9457158 | 2013-08-02 18:36:16 -0700 | [diff] [blame] | 5205 | tracing_reset_online_cpus(&tr->trace_buffer); |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5206 | |
| 5207 | #ifdef CONFIG_TRACER_MAX_TRACE |
| 5208 | if (tr->flags & TRACE_ARRAY_FL_GLOBAL && tr->max_buffer.buffer) |
| 5209 | ring_buffer_set_clock(tr->max_buffer.buffer, trace_clocks[i].func); |
Alexander Z Lam | 9457158 | 2013-08-02 18:36:16 -0700 | [diff] [blame] | 5210 | tracing_reset_online_cpus(&tr->max_buffer); |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5211 | #endif |
David Sharp | 60303ed | 2012-10-11 16:27:52 -0700 | [diff] [blame] | 5212 | |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 5213 | mutex_unlock(&trace_types_lock); |
| 5214 | |
Steven Rostedt | e1e232c | 2014-02-10 23:38:46 -0500 | [diff] [blame] | 5215 | return 0; |
| 5216 | } |
| 5217 | |
| 5218 | static ssize_t tracing_clock_write(struct file *filp, const char __user *ubuf, |
| 5219 | size_t cnt, loff_t *fpos) |
| 5220 | { |
| 5221 | struct seq_file *m = filp->private_data; |
| 5222 | struct trace_array *tr = m->private; |
| 5223 | char buf[64]; |
| 5224 | const char *clockstr; |
| 5225 | int ret; |
| 5226 | |
| 5227 | if (cnt >= sizeof(buf)) |
| 5228 | return -EINVAL; |
| 5229 | |
| 5230 | if (copy_from_user(&buf, ubuf, cnt)) |
| 5231 | return -EFAULT; |
| 5232 | |
| 5233 | buf[cnt] = 0; |
| 5234 | |
| 5235 | clockstr = strstrip(buf); |
| 5236 | |
| 5237 | ret = tracing_set_clock(tr, clockstr); |
| 5238 | if (ret) |
| 5239 | return ret; |
| 5240 | |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 5241 | *fpos += cnt; |
| 5242 | |
| 5243 | return cnt; |
| 5244 | } |
| 5245 | |
Li Zefan | 13f16d2 | 2009-12-08 11:16:11 +0800 | [diff] [blame] | 5246 | static int tracing_clock_open(struct inode *inode, struct file *file) |
| 5247 | { |
Steven Rostedt (Red Hat) | 7b85af6 | 2013-07-01 23:34:22 -0400 | [diff] [blame] | 5248 | struct trace_array *tr = inode->i_private; |
| 5249 | int ret; |
| 5250 | |
Li Zefan | 13f16d2 | 2009-12-08 11:16:11 +0800 | [diff] [blame] | 5251 | if (tracing_disabled) |
| 5252 | return -ENODEV; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5253 | |
Steven Rostedt (Red Hat) | 7b85af6 | 2013-07-01 23:34:22 -0400 | [diff] [blame] | 5254 | if (trace_array_get(tr)) |
| 5255 | return -ENODEV; |
| 5256 | |
| 5257 | ret = single_open(file, tracing_clock_show, inode->i_private); |
| 5258 | if (ret < 0) |
| 5259 | trace_array_put(tr); |
| 5260 | |
| 5261 | return ret; |
Li Zefan | 13f16d2 | 2009-12-08 11:16:11 +0800 | [diff] [blame] | 5262 | } |
| 5263 | |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 5264 | struct ftrace_buffer_info { |
| 5265 | struct trace_iterator iter; |
| 5266 | void *spare; |
| 5267 | unsigned int read; |
| 5268 | }; |
| 5269 | |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 5270 | #ifdef CONFIG_TRACER_SNAPSHOT |
| 5271 | static int tracing_snapshot_open(struct inode *inode, struct file *file) |
| 5272 | { |
Oleg Nesterov | 6484c71 | 2013-07-23 17:26:10 +0200 | [diff] [blame] | 5273 | struct trace_array *tr = inode->i_private; |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 5274 | struct trace_iterator *iter; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5275 | struct seq_file *m; |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 5276 | int ret = 0; |
| 5277 | |
Steven Rostedt (Red Hat) | ff45196 | 2013-07-01 22:50:29 -0400 | [diff] [blame] | 5278 | if (trace_array_get(tr) < 0) |
| 5279 | return -ENODEV; |
| 5280 | |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 5281 | if (file->f_mode & FMODE_READ) { |
Oleg Nesterov | 6484c71 | 2013-07-23 17:26:10 +0200 | [diff] [blame] | 5282 | iter = __tracing_open(inode, file, true); |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 5283 | if (IS_ERR(iter)) |
| 5284 | ret = PTR_ERR(iter); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5285 | } else { |
| 5286 | /* Writes still need the seq_file to hold the private data */ |
Alexander Z Lam | f77d09a | 2013-07-18 11:18:44 -0700 | [diff] [blame] | 5287 | ret = -ENOMEM; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5288 | m = kzalloc(sizeof(*m), GFP_KERNEL); |
| 5289 | if (!m) |
Alexander Z Lam | f77d09a | 2013-07-18 11:18:44 -0700 | [diff] [blame] | 5290 | goto out; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5291 | iter = kzalloc(sizeof(*iter), GFP_KERNEL); |
| 5292 | if (!iter) { |
| 5293 | kfree(m); |
Alexander Z Lam | f77d09a | 2013-07-18 11:18:44 -0700 | [diff] [blame] | 5294 | goto out; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5295 | } |
Alexander Z Lam | f77d09a | 2013-07-18 11:18:44 -0700 | [diff] [blame] | 5296 | ret = 0; |
| 5297 | |
Steven Rostedt (Red Hat) | ff45196 | 2013-07-01 22:50:29 -0400 | [diff] [blame] | 5298 | iter->tr = tr; |
Oleg Nesterov | 6484c71 | 2013-07-23 17:26:10 +0200 | [diff] [blame] | 5299 | iter->trace_buffer = &tr->max_buffer; |
| 5300 | iter->cpu_file = tracing_get_cpu(inode); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5301 | m->private = iter; |
| 5302 | file->private_data = m; |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 5303 | } |
Alexander Z Lam | f77d09a | 2013-07-18 11:18:44 -0700 | [diff] [blame] | 5304 | out: |
Steven Rostedt (Red Hat) | ff45196 | 2013-07-01 22:50:29 -0400 | [diff] [blame] | 5305 | if (ret < 0) |
| 5306 | trace_array_put(tr); |
| 5307 | |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 5308 | return ret; |
| 5309 | } |
| 5310 | |
| 5311 | static ssize_t |
| 5312 | tracing_snapshot_write(struct file *filp, const char __user *ubuf, size_t cnt, |
| 5313 | loff_t *ppos) |
| 5314 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5315 | struct seq_file *m = filp->private_data; |
| 5316 | struct trace_iterator *iter = m->private; |
| 5317 | struct trace_array *tr = iter->tr; |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 5318 | unsigned long val; |
| 5319 | int ret; |
| 5320 | |
| 5321 | ret = tracing_update_buffers(); |
| 5322 | if (ret < 0) |
| 5323 | return ret; |
| 5324 | |
| 5325 | ret = kstrtoul_from_user(ubuf, cnt, 10, &val); |
| 5326 | if (ret) |
| 5327 | return ret; |
| 5328 | |
| 5329 | mutex_lock(&trace_types_lock); |
| 5330 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5331 | if (tr->current_trace->use_max_tr) { |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 5332 | ret = -EBUSY; |
| 5333 | goto out; |
| 5334 | } |
| 5335 | |
| 5336 | switch (val) { |
| 5337 | case 0: |
Steven Rostedt (Red Hat) | f1affca | 2013-03-05 14:35:11 -0500 | [diff] [blame] | 5338 | if (iter->cpu_file != RING_BUFFER_ALL_CPUS) { |
| 5339 | ret = -EINVAL; |
| 5340 | break; |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 5341 | } |
Steven Rostedt (Red Hat) | 3209cff | 2013-03-12 11:17:54 -0400 | [diff] [blame] | 5342 | if (tr->allocated_snapshot) |
| 5343 | free_snapshot(tr); |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 5344 | break; |
| 5345 | case 1: |
Steven Rostedt (Red Hat) | f1affca | 2013-03-05 14:35:11 -0500 | [diff] [blame] | 5346 | /* Only allow per-cpu swap if the ring buffer supports it */ |
| 5347 | #ifndef CONFIG_RING_BUFFER_ALLOW_SWAP |
| 5348 | if (iter->cpu_file != RING_BUFFER_ALL_CPUS) { |
| 5349 | ret = -EINVAL; |
| 5350 | break; |
| 5351 | } |
| 5352 | #endif |
Steven Rostedt (Red Hat) | 45ad21c | 2013-03-05 18:25:02 -0500 | [diff] [blame] | 5353 | if (!tr->allocated_snapshot) { |
Steven Rostedt (Red Hat) | 3209cff | 2013-03-12 11:17:54 -0400 | [diff] [blame] | 5354 | ret = alloc_snapshot(tr); |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 5355 | if (ret < 0) |
| 5356 | break; |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 5357 | } |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 5358 | local_irq_disable(); |
| 5359 | /* Now, we're going to swap */ |
Steven Rostedt (Red Hat) | f1affca | 2013-03-05 14:35:11 -0500 | [diff] [blame] | 5360 | if (iter->cpu_file == RING_BUFFER_ALL_CPUS) |
Steven Rostedt (Red Hat) | ce9bae5 | 2013-03-05 21:23:55 -0500 | [diff] [blame] | 5361 | update_max_tr(tr, current, smp_processor_id()); |
Steven Rostedt (Red Hat) | f1affca | 2013-03-05 14:35:11 -0500 | [diff] [blame] | 5362 | else |
Steven Rostedt (Red Hat) | ce9bae5 | 2013-03-05 21:23:55 -0500 | [diff] [blame] | 5363 | update_max_tr_single(tr, current, iter->cpu_file); |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 5364 | local_irq_enable(); |
| 5365 | break; |
| 5366 | default: |
Steven Rostedt (Red Hat) | 45ad21c | 2013-03-05 18:25:02 -0500 | [diff] [blame] | 5367 | if (tr->allocated_snapshot) { |
Steven Rostedt (Red Hat) | f1affca | 2013-03-05 14:35:11 -0500 | [diff] [blame] | 5368 | if (iter->cpu_file == RING_BUFFER_ALL_CPUS) |
| 5369 | tracing_reset_online_cpus(&tr->max_buffer); |
| 5370 | else |
| 5371 | tracing_reset(&tr->max_buffer, iter->cpu_file); |
| 5372 | } |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 5373 | break; |
| 5374 | } |
| 5375 | |
| 5376 | if (ret >= 0) { |
| 5377 | *ppos += cnt; |
| 5378 | ret = cnt; |
| 5379 | } |
| 5380 | out: |
| 5381 | mutex_unlock(&trace_types_lock); |
| 5382 | return ret; |
| 5383 | } |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5384 | |
| 5385 | static int tracing_snapshot_release(struct inode *inode, struct file *file) |
| 5386 | { |
| 5387 | struct seq_file *m = file->private_data; |
Steven Rostedt (Red Hat) | ff45196 | 2013-07-01 22:50:29 -0400 | [diff] [blame] | 5388 | int ret; |
| 5389 | |
| 5390 | ret = tracing_release(inode, file); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5391 | |
| 5392 | if (file->f_mode & FMODE_READ) |
Steven Rostedt (Red Hat) | ff45196 | 2013-07-01 22:50:29 -0400 | [diff] [blame] | 5393 | return ret; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5394 | |
| 5395 | /* If write only, the seq_file is just a stub */ |
| 5396 | if (m) |
| 5397 | kfree(m->private); |
| 5398 | kfree(m); |
| 5399 | |
| 5400 | return 0; |
| 5401 | } |
| 5402 | |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 5403 | static int tracing_buffers_open(struct inode *inode, struct file *filp); |
| 5404 | static ssize_t tracing_buffers_read(struct file *filp, char __user *ubuf, |
| 5405 | size_t count, loff_t *ppos); |
| 5406 | static int tracing_buffers_release(struct inode *inode, struct file *file); |
| 5407 | static ssize_t tracing_buffers_splice_read(struct file *file, loff_t *ppos, |
| 5408 | struct pipe_inode_info *pipe, size_t len, unsigned int flags); |
| 5409 | |
| 5410 | static int snapshot_raw_open(struct inode *inode, struct file *filp) |
| 5411 | { |
| 5412 | struct ftrace_buffer_info *info; |
| 5413 | int ret; |
| 5414 | |
| 5415 | ret = tracing_buffers_open(inode, filp); |
| 5416 | if (ret < 0) |
| 5417 | return ret; |
| 5418 | |
| 5419 | info = filp->private_data; |
| 5420 | |
| 5421 | if (info->iter.trace->use_max_tr) { |
| 5422 | tracing_buffers_release(inode, filp); |
| 5423 | return -EBUSY; |
| 5424 | } |
| 5425 | |
| 5426 | info->iter.snapshot = true; |
| 5427 | info->iter.trace_buffer = &info->iter.tr->max_buffer; |
| 5428 | |
| 5429 | return ret; |
| 5430 | } |
| 5431 | |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 5432 | #endif /* CONFIG_TRACER_SNAPSHOT */ |
| 5433 | |
| 5434 | |
Stanislav Fomichev | 6508fa7 | 2014-07-18 15:17:27 +0400 | [diff] [blame] | 5435 | static const struct file_operations tracing_thresh_fops = { |
| 5436 | .open = tracing_open_generic, |
| 5437 | .read = tracing_thresh_read, |
| 5438 | .write = tracing_thresh_write, |
| 5439 | .llseek = generic_file_llseek, |
| 5440 | }; |
| 5441 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 5442 | static const struct file_operations tracing_max_lat_fops = { |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 5443 | .open = tracing_open_generic, |
| 5444 | .read = tracing_max_lat_read, |
| 5445 | .write = tracing_max_lat_write, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 5446 | .llseek = generic_file_llseek, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5447 | }; |
| 5448 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 5449 | static const struct file_operations set_tracer_fops = { |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 5450 | .open = tracing_open_generic, |
| 5451 | .read = tracing_set_trace_read, |
| 5452 | .write = tracing_set_trace_write, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 5453 | .llseek = generic_file_llseek, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5454 | }; |
| 5455 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 5456 | static const struct file_operations tracing_pipe_fops = { |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 5457 | .open = tracing_open_pipe, |
Soeren Sandmann Pedersen | 2a2cc8f | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 5458 | .poll = tracing_poll_pipe, |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 5459 | .read = tracing_read_pipe, |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 5460 | .splice_read = tracing_splice_read_pipe, |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 5461 | .release = tracing_release_pipe, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 5462 | .llseek = no_llseek, |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 5463 | }; |
| 5464 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 5465 | static const struct file_operations tracing_entries_fops = { |
Oleg Nesterov | 0bc392e | 2013-07-23 17:26:06 +0200 | [diff] [blame] | 5466 | .open = tracing_open_generic_tr, |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 5467 | .read = tracing_entries_read, |
| 5468 | .write = tracing_entries_write, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 5469 | .llseek = generic_file_llseek, |
Oleg Nesterov | 0bc392e | 2013-07-23 17:26:06 +0200 | [diff] [blame] | 5470 | .release = tracing_release_generic_tr, |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 5471 | }; |
| 5472 | |
Vaibhav Nagarnaik | f81ab07 | 2011-08-16 14:46:15 -0700 | [diff] [blame] | 5473 | static const struct file_operations tracing_total_entries_fops = { |
Steven Rostedt (Red Hat) | 7b85af6 | 2013-07-01 23:34:22 -0400 | [diff] [blame] | 5474 | .open = tracing_open_generic_tr, |
Vaibhav Nagarnaik | f81ab07 | 2011-08-16 14:46:15 -0700 | [diff] [blame] | 5475 | .read = tracing_total_entries_read, |
| 5476 | .llseek = generic_file_llseek, |
Steven Rostedt (Red Hat) | 7b85af6 | 2013-07-01 23:34:22 -0400 | [diff] [blame] | 5477 | .release = tracing_release_generic_tr, |
Vaibhav Nagarnaik | f81ab07 | 2011-08-16 14:46:15 -0700 | [diff] [blame] | 5478 | }; |
| 5479 | |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 5480 | static const struct file_operations tracing_free_buffer_fops = { |
Steven Rostedt (Red Hat) | 7b85af6 | 2013-07-01 23:34:22 -0400 | [diff] [blame] | 5481 | .open = tracing_open_generic_tr, |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 5482 | .write = tracing_free_buffer_write, |
| 5483 | .release = tracing_free_buffer_release, |
| 5484 | }; |
| 5485 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 5486 | static const struct file_operations tracing_mark_fops = { |
Steven Rostedt (Red Hat) | 7b85af6 | 2013-07-01 23:34:22 -0400 | [diff] [blame] | 5487 | .open = tracing_open_generic_tr, |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 5488 | .write = tracing_mark_write, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 5489 | .llseek = generic_file_llseek, |
Steven Rostedt (Red Hat) | 7b85af6 | 2013-07-01 23:34:22 -0400 | [diff] [blame] | 5490 | .release = tracing_release_generic_tr, |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 5491 | }; |
| 5492 | |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 5493 | static const struct file_operations trace_clock_fops = { |
Li Zefan | 13f16d2 | 2009-12-08 11:16:11 +0800 | [diff] [blame] | 5494 | .open = tracing_clock_open, |
| 5495 | .read = seq_read, |
| 5496 | .llseek = seq_lseek, |
Steven Rostedt (Red Hat) | 7b85af6 | 2013-07-01 23:34:22 -0400 | [diff] [blame] | 5497 | .release = tracing_single_release_tr, |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 5498 | .write = tracing_clock_write, |
| 5499 | }; |
| 5500 | |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 5501 | #ifdef CONFIG_TRACER_SNAPSHOT |
| 5502 | static const struct file_operations snapshot_fops = { |
| 5503 | .open = tracing_snapshot_open, |
| 5504 | .read = seq_read, |
| 5505 | .write = tracing_snapshot_write, |
Steven Rostedt (Red Hat) | 098c879 | 2013-12-21 17:39:40 -0500 | [diff] [blame] | 5506 | .llseek = tracing_lseek, |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5507 | .release = tracing_snapshot_release, |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 5508 | }; |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 5509 | |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 5510 | static const struct file_operations snapshot_raw_fops = { |
| 5511 | .open = snapshot_raw_open, |
| 5512 | .read = tracing_buffers_read, |
| 5513 | .release = tracing_buffers_release, |
| 5514 | .splice_read = tracing_buffers_splice_read, |
| 5515 | .llseek = no_llseek, |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5516 | }; |
| 5517 | |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 5518 | #endif /* CONFIG_TRACER_SNAPSHOT */ |
| 5519 | |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5520 | static int tracing_buffers_open(struct inode *inode, struct file *filp) |
| 5521 | { |
Oleg Nesterov | 46ef2be | 2013-07-23 17:26:00 +0200 | [diff] [blame] | 5522 | struct trace_array *tr = inode->i_private; |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5523 | struct ftrace_buffer_info *info; |
Steven Rostedt (Red Hat) | 7b85af6 | 2013-07-01 23:34:22 -0400 | [diff] [blame] | 5524 | int ret; |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5525 | |
| 5526 | if (tracing_disabled) |
| 5527 | return -ENODEV; |
| 5528 | |
Steven Rostedt (Red Hat) | 7b85af6 | 2013-07-01 23:34:22 -0400 | [diff] [blame] | 5529 | if (trace_array_get(tr) < 0) |
| 5530 | return -ENODEV; |
| 5531 | |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5532 | info = kzalloc(sizeof(*info), GFP_KERNEL); |
Steven Rostedt (Red Hat) | 7b85af6 | 2013-07-01 23:34:22 -0400 | [diff] [blame] | 5533 | if (!info) { |
| 5534 | trace_array_put(tr); |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5535 | return -ENOMEM; |
Steven Rostedt (Red Hat) | 7b85af6 | 2013-07-01 23:34:22 -0400 | [diff] [blame] | 5536 | } |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5537 | |
Steven Rostedt (Red Hat) | a695cb5 | 2013-03-06 15:27:24 -0500 | [diff] [blame] | 5538 | mutex_lock(&trace_types_lock); |
| 5539 | |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 5540 | info->iter.tr = tr; |
Oleg Nesterov | 46ef2be | 2013-07-23 17:26:00 +0200 | [diff] [blame] | 5541 | info->iter.cpu_file = tracing_get_cpu(inode); |
Steven Rostedt | b627344 | 2013-02-28 13:44:11 -0500 | [diff] [blame] | 5542 | info->iter.trace = tr->current_trace; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5543 | info->iter.trace_buffer = &tr->trace_buffer; |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 5544 | info->spare = NULL; |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5545 | /* Force reading ring buffer for first read */ |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 5546 | info->read = (unsigned int)-1; |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5547 | |
| 5548 | filp->private_data = info; |
| 5549 | |
Steven Rostedt (Red Hat) | cf6ab6d | 2014-12-15 20:13:31 -0500 | [diff] [blame] | 5550 | tr->current_trace->ref++; |
| 5551 | |
Steven Rostedt (Red Hat) | a695cb5 | 2013-03-06 15:27:24 -0500 | [diff] [blame] | 5552 | mutex_unlock(&trace_types_lock); |
| 5553 | |
Steven Rostedt (Red Hat) | 7b85af6 | 2013-07-01 23:34:22 -0400 | [diff] [blame] | 5554 | ret = nonseekable_open(inode, filp); |
| 5555 | if (ret < 0) |
| 5556 | trace_array_put(tr); |
| 5557 | |
| 5558 | return ret; |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5559 | } |
| 5560 | |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 5561 | static unsigned int |
| 5562 | tracing_buffers_poll(struct file *filp, poll_table *poll_table) |
| 5563 | { |
| 5564 | struct ftrace_buffer_info *info = filp->private_data; |
| 5565 | struct trace_iterator *iter = &info->iter; |
| 5566 | |
| 5567 | return trace_poll(iter, filp, poll_table); |
| 5568 | } |
| 5569 | |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5570 | static ssize_t |
| 5571 | tracing_buffers_read(struct file *filp, char __user *ubuf, |
| 5572 | size_t count, loff_t *ppos) |
| 5573 | { |
| 5574 | struct ftrace_buffer_info *info = filp->private_data; |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 5575 | struct trace_iterator *iter = &info->iter; |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5576 | ssize_t ret; |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 5577 | ssize_t size; |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5578 | |
Steven Rostedt | 2dc5d12 | 2009-03-04 19:10:05 -0500 | [diff] [blame] | 5579 | if (!count) |
| 5580 | return 0; |
| 5581 | |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 5582 | #ifdef CONFIG_TRACER_MAX_TRACE |
Steven Rostedt (Red Hat) | d716ff7 | 2014-12-15 22:31:07 -0500 | [diff] [blame] | 5583 | if (iter->snapshot && iter->tr->current_trace->use_max_tr) |
| 5584 | return -EBUSY; |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 5585 | #endif |
| 5586 | |
Lai Jiangshan | ddd538f | 2009-04-02 15:16:59 +0800 | [diff] [blame] | 5587 | if (!info->spare) |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5588 | info->spare = ring_buffer_alloc_read_page(iter->trace_buffer->buffer, |
| 5589 | iter->cpu_file); |
Lai Jiangshan | ddd538f | 2009-04-02 15:16:59 +0800 | [diff] [blame] | 5590 | if (!info->spare) |
Steven Rostedt (Red Hat) | d716ff7 | 2014-12-15 22:31:07 -0500 | [diff] [blame] | 5591 | return -ENOMEM; |
Lai Jiangshan | ddd538f | 2009-04-02 15:16:59 +0800 | [diff] [blame] | 5592 | |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5593 | /* Do we have previous read data to read? */ |
| 5594 | if (info->read < PAGE_SIZE) |
| 5595 | goto read; |
| 5596 | |
Steven Rostedt | b627344 | 2013-02-28 13:44:11 -0500 | [diff] [blame] | 5597 | again: |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 5598 | trace_access_lock(iter->cpu_file); |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5599 | ret = ring_buffer_read_page(iter->trace_buffer->buffer, |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5600 | &info->spare, |
| 5601 | count, |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 5602 | iter->cpu_file, 0); |
| 5603 | trace_access_unlock(iter->cpu_file); |
Steven Rostedt | b627344 | 2013-02-28 13:44:11 -0500 | [diff] [blame] | 5604 | |
| 5605 | if (ret < 0) { |
| 5606 | if (trace_empty(iter)) { |
Steven Rostedt (Red Hat) | d716ff7 | 2014-12-15 22:31:07 -0500 | [diff] [blame] | 5607 | if ((filp->f_flags & O_NONBLOCK)) |
| 5608 | return -EAGAIN; |
| 5609 | |
Rabin Vincent | e30f53a | 2014-11-10 19:46:34 +0100 | [diff] [blame] | 5610 | ret = wait_on_pipe(iter, false); |
Steven Rostedt (Red Hat) | d716ff7 | 2014-12-15 22:31:07 -0500 | [diff] [blame] | 5611 | if (ret) |
| 5612 | return ret; |
| 5613 | |
Steven Rostedt | b627344 | 2013-02-28 13:44:11 -0500 | [diff] [blame] | 5614 | goto again; |
| 5615 | } |
Steven Rostedt (Red Hat) | d716ff7 | 2014-12-15 22:31:07 -0500 | [diff] [blame] | 5616 | return 0; |
Steven Rostedt | b627344 | 2013-02-28 13:44:11 -0500 | [diff] [blame] | 5617 | } |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5618 | |
Steven Rostedt | 436fc28 | 2011-10-14 10:44:25 -0400 | [diff] [blame] | 5619 | info->read = 0; |
Steven Rostedt | b627344 | 2013-02-28 13:44:11 -0500 | [diff] [blame] | 5620 | read: |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5621 | size = PAGE_SIZE - info->read; |
| 5622 | if (size > count) |
| 5623 | size = count; |
| 5624 | |
| 5625 | ret = copy_to_user(ubuf, info->spare + info->read, size); |
Steven Rostedt (Red Hat) | d716ff7 | 2014-12-15 22:31:07 -0500 | [diff] [blame] | 5626 | if (ret == size) |
| 5627 | return -EFAULT; |
| 5628 | |
Steven Rostedt | 2dc5d12 | 2009-03-04 19:10:05 -0500 | [diff] [blame] | 5629 | size -= ret; |
| 5630 | |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5631 | *ppos += size; |
| 5632 | info->read += size; |
| 5633 | |
| 5634 | return size; |
| 5635 | } |
| 5636 | |
| 5637 | static int tracing_buffers_release(struct inode *inode, struct file *file) |
| 5638 | { |
| 5639 | struct ftrace_buffer_info *info = file->private_data; |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 5640 | struct trace_iterator *iter = &info->iter; |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5641 | |
Steven Rostedt (Red Hat) | a695cb5 | 2013-03-06 15:27:24 -0500 | [diff] [blame] | 5642 | mutex_lock(&trace_types_lock); |
| 5643 | |
Steven Rostedt (Red Hat) | cf6ab6d | 2014-12-15 20:13:31 -0500 | [diff] [blame] | 5644 | iter->tr->current_trace->ref--; |
| 5645 | |
Steven Rostedt (Red Hat) | ff45196 | 2013-07-01 22:50:29 -0400 | [diff] [blame] | 5646 | __trace_array_put(iter->tr); |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5647 | |
Lai Jiangshan | ddd538f | 2009-04-02 15:16:59 +0800 | [diff] [blame] | 5648 | if (info->spare) |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5649 | ring_buffer_free_read_page(iter->trace_buffer->buffer, info->spare); |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5650 | kfree(info); |
| 5651 | |
Steven Rostedt (Red Hat) | a695cb5 | 2013-03-06 15:27:24 -0500 | [diff] [blame] | 5652 | mutex_unlock(&trace_types_lock); |
| 5653 | |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5654 | return 0; |
| 5655 | } |
| 5656 | |
| 5657 | struct buffer_ref { |
| 5658 | struct ring_buffer *buffer; |
| 5659 | void *page; |
| 5660 | int ref; |
| 5661 | }; |
| 5662 | |
| 5663 | static void buffer_pipe_buf_release(struct pipe_inode_info *pipe, |
| 5664 | struct pipe_buffer *buf) |
| 5665 | { |
| 5666 | struct buffer_ref *ref = (struct buffer_ref *)buf->private; |
| 5667 | |
| 5668 | if (--ref->ref) |
| 5669 | return; |
| 5670 | |
| 5671 | ring_buffer_free_read_page(ref->buffer, ref->page); |
| 5672 | kfree(ref); |
| 5673 | buf->private = 0; |
| 5674 | } |
| 5675 | |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5676 | static void buffer_pipe_buf_get(struct pipe_inode_info *pipe, |
| 5677 | struct pipe_buffer *buf) |
| 5678 | { |
| 5679 | struct buffer_ref *ref = (struct buffer_ref *)buf->private; |
| 5680 | |
| 5681 | ref->ref++; |
| 5682 | } |
| 5683 | |
| 5684 | /* Pipe buffer operations for a buffer. */ |
Alexey Dobriyan | 28dfef8 | 2009-12-15 16:46:48 -0800 | [diff] [blame] | 5685 | static const struct pipe_buf_operations buffer_pipe_buf_ops = { |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5686 | .can_merge = 0, |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5687 | .confirm = generic_pipe_buf_confirm, |
| 5688 | .release = buffer_pipe_buf_release, |
Masami Hiramatsu | d55cb6c | 2012-08-09 21:31:10 +0900 | [diff] [blame] | 5689 | .steal = generic_pipe_buf_steal, |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5690 | .get = buffer_pipe_buf_get, |
| 5691 | }; |
| 5692 | |
| 5693 | /* |
| 5694 | * Callback from splice_to_pipe(), if we need to release some pages |
| 5695 | * at the end of the spd in case we error'ed out in filling the pipe. |
| 5696 | */ |
| 5697 | static void buffer_spd_release(struct splice_pipe_desc *spd, unsigned int i) |
| 5698 | { |
| 5699 | struct buffer_ref *ref = |
| 5700 | (struct buffer_ref *)spd->partial[i].private; |
| 5701 | |
| 5702 | if (--ref->ref) |
| 5703 | return; |
| 5704 | |
| 5705 | ring_buffer_free_read_page(ref->buffer, ref->page); |
| 5706 | kfree(ref); |
| 5707 | spd->partial[i].private = 0; |
| 5708 | } |
| 5709 | |
| 5710 | static ssize_t |
| 5711 | tracing_buffers_splice_read(struct file *file, loff_t *ppos, |
| 5712 | struct pipe_inode_info *pipe, size_t len, |
| 5713 | unsigned int flags) |
| 5714 | { |
| 5715 | struct ftrace_buffer_info *info = file->private_data; |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 5716 | struct trace_iterator *iter = &info->iter; |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 5717 | struct partial_page partial_def[PIPE_DEF_BUFFERS]; |
| 5718 | struct page *pages_def[PIPE_DEF_BUFFERS]; |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5719 | struct splice_pipe_desc spd = { |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 5720 | .pages = pages_def, |
| 5721 | .partial = partial_def, |
Eric Dumazet | 047fe36 | 2012-06-12 15:24:40 +0200 | [diff] [blame] | 5722 | .nr_pages_max = PIPE_DEF_BUFFERS, |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5723 | .flags = flags, |
| 5724 | .ops = &buffer_pipe_buf_ops, |
| 5725 | .spd_release = buffer_spd_release, |
| 5726 | }; |
| 5727 | struct buffer_ref *ref; |
Steven Rostedt | 93459c6 | 2009-04-29 00:23:13 -0400 | [diff] [blame] | 5728 | int entries, size, i; |
Rabin Vincent | 07906da | 2014-11-06 22:26:07 +0100 | [diff] [blame] | 5729 | ssize_t ret = 0; |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5730 | |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 5731 | #ifdef CONFIG_TRACER_MAX_TRACE |
Steven Rostedt (Red Hat) | d716ff7 | 2014-12-15 22:31:07 -0500 | [diff] [blame] | 5732 | if (iter->snapshot && iter->tr->current_trace->use_max_tr) |
| 5733 | return -EBUSY; |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 5734 | #endif |
| 5735 | |
Steven Rostedt (Red Hat) | d716ff7 | 2014-12-15 22:31:07 -0500 | [diff] [blame] | 5736 | if (splice_grow_spd(pipe, &spd)) |
| 5737 | return -ENOMEM; |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 5738 | |
Steven Rostedt (Red Hat) | d716ff7 | 2014-12-15 22:31:07 -0500 | [diff] [blame] | 5739 | if (*ppos & (PAGE_SIZE - 1)) |
| 5740 | return -EINVAL; |
Lai Jiangshan | 93cfb3c | 2009-04-02 15:17:08 +0800 | [diff] [blame] | 5741 | |
| 5742 | if (len & (PAGE_SIZE - 1)) { |
Steven Rostedt (Red Hat) | d716ff7 | 2014-12-15 22:31:07 -0500 | [diff] [blame] | 5743 | if (len < PAGE_SIZE) |
| 5744 | return -EINVAL; |
Lai Jiangshan | 93cfb3c | 2009-04-02 15:17:08 +0800 | [diff] [blame] | 5745 | len &= PAGE_MASK; |
| 5746 | } |
| 5747 | |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 5748 | again: |
| 5749 | trace_access_lock(iter->cpu_file); |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5750 | entries = ring_buffer_entries_cpu(iter->trace_buffer->buffer, iter->cpu_file); |
Steven Rostedt | 93459c6 | 2009-04-29 00:23:13 -0400 | [diff] [blame] | 5751 | |
Al Viro | a786c06 | 2014-04-11 12:01:03 -0400 | [diff] [blame] | 5752 | for (i = 0; i < spd.nr_pages_max && len && entries; i++, len -= PAGE_SIZE) { |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5753 | struct page *page; |
| 5754 | int r; |
| 5755 | |
| 5756 | ref = kzalloc(sizeof(*ref), GFP_KERNEL); |
Rabin Vincent | 07906da | 2014-11-06 22:26:07 +0100 | [diff] [blame] | 5757 | if (!ref) { |
| 5758 | ret = -ENOMEM; |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5759 | break; |
Rabin Vincent | 07906da | 2014-11-06 22:26:07 +0100 | [diff] [blame] | 5760 | } |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5761 | |
Steven Rostedt | 7267fa6 | 2009-04-29 00:16:21 -0400 | [diff] [blame] | 5762 | ref->ref = 1; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5763 | ref->buffer = iter->trace_buffer->buffer; |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 5764 | ref->page = ring_buffer_alloc_read_page(ref->buffer, iter->cpu_file); |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5765 | if (!ref->page) { |
Rabin Vincent | 07906da | 2014-11-06 22:26:07 +0100 | [diff] [blame] | 5766 | ret = -ENOMEM; |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5767 | kfree(ref); |
| 5768 | break; |
| 5769 | } |
| 5770 | |
| 5771 | r = ring_buffer_read_page(ref->buffer, &ref->page, |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 5772 | len, iter->cpu_file, 1); |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5773 | if (r < 0) { |
Vaibhav Nagarnaik | 7ea5906 | 2011-05-03 17:56:42 -0700 | [diff] [blame] | 5774 | ring_buffer_free_read_page(ref->buffer, ref->page); |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5775 | kfree(ref); |
| 5776 | break; |
| 5777 | } |
| 5778 | |
| 5779 | /* |
| 5780 | * zero out any left over data, this is going to |
| 5781 | * user land. |
| 5782 | */ |
| 5783 | size = ring_buffer_page_len(ref->page); |
| 5784 | if (size < PAGE_SIZE) |
| 5785 | memset(ref->page + size, 0, PAGE_SIZE - size); |
| 5786 | |
| 5787 | page = virt_to_page(ref->page); |
| 5788 | |
| 5789 | spd.pages[i] = page; |
| 5790 | spd.partial[i].len = PAGE_SIZE; |
| 5791 | spd.partial[i].offset = 0; |
| 5792 | spd.partial[i].private = (unsigned long)ref; |
| 5793 | spd.nr_pages++; |
Lai Jiangshan | 93cfb3c | 2009-04-02 15:17:08 +0800 | [diff] [blame] | 5794 | *ppos += PAGE_SIZE; |
Steven Rostedt | 93459c6 | 2009-04-29 00:23:13 -0400 | [diff] [blame] | 5795 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5796 | entries = ring_buffer_entries_cpu(iter->trace_buffer->buffer, iter->cpu_file); |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5797 | } |
| 5798 | |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 5799 | trace_access_unlock(iter->cpu_file); |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5800 | spd.nr_pages = i; |
| 5801 | |
| 5802 | /* did we read anything? */ |
| 5803 | if (!spd.nr_pages) { |
Rabin Vincent | 07906da | 2014-11-06 22:26:07 +0100 | [diff] [blame] | 5804 | if (ret) |
Steven Rostedt (Red Hat) | d716ff7 | 2014-12-15 22:31:07 -0500 | [diff] [blame] | 5805 | return ret; |
Rabin Vincent | 07906da | 2014-11-06 22:26:07 +0100 | [diff] [blame] | 5806 | |
Steven Rostedt (Red Hat) | d716ff7 | 2014-12-15 22:31:07 -0500 | [diff] [blame] | 5807 | if ((file->f_flags & O_NONBLOCK) || (flags & SPLICE_F_NONBLOCK)) |
| 5808 | return -EAGAIN; |
| 5809 | |
Rabin Vincent | e30f53a | 2014-11-10 19:46:34 +0100 | [diff] [blame] | 5810 | ret = wait_on_pipe(iter, true); |
Steven Rostedt (Red Hat) | 8b8b368 | 2014-06-10 09:46:00 -0400 | [diff] [blame] | 5811 | if (ret) |
Steven Rostedt (Red Hat) | d716ff7 | 2014-12-15 22:31:07 -0500 | [diff] [blame] | 5812 | return ret; |
Rabin Vincent | e30f53a | 2014-11-10 19:46:34 +0100 | [diff] [blame] | 5813 | |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 5814 | goto again; |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5815 | } |
| 5816 | |
| 5817 | ret = splice_to_pipe(pipe, &spd); |
Eric Dumazet | 047fe36 | 2012-06-12 15:24:40 +0200 | [diff] [blame] | 5818 | splice_shrink_spd(&spd); |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 5819 | |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5820 | return ret; |
| 5821 | } |
| 5822 | |
| 5823 | static const struct file_operations tracing_buffers_fops = { |
| 5824 | .open = tracing_buffers_open, |
| 5825 | .read = tracing_buffers_read, |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 5826 | .poll = tracing_buffers_poll, |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5827 | .release = tracing_buffers_release, |
| 5828 | .splice_read = tracing_buffers_splice_read, |
| 5829 | .llseek = no_llseek, |
| 5830 | }; |
| 5831 | |
Steven Rostedt | c8d7718 | 2009-04-29 18:03:45 -0400 | [diff] [blame] | 5832 | static ssize_t |
| 5833 | tracing_stats_read(struct file *filp, char __user *ubuf, |
| 5834 | size_t count, loff_t *ppos) |
| 5835 | { |
Oleg Nesterov | 4d3435b | 2013-07-23 17:26:03 +0200 | [diff] [blame] | 5836 | struct inode *inode = file_inode(filp); |
| 5837 | struct trace_array *tr = inode->i_private; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5838 | struct trace_buffer *trace_buf = &tr->trace_buffer; |
Oleg Nesterov | 4d3435b | 2013-07-23 17:26:03 +0200 | [diff] [blame] | 5839 | int cpu = tracing_get_cpu(inode); |
Steven Rostedt | c8d7718 | 2009-04-29 18:03:45 -0400 | [diff] [blame] | 5840 | struct trace_seq *s; |
| 5841 | unsigned long cnt; |
Vaibhav Nagarnaik | c64e148 | 2011-08-16 14:46:16 -0700 | [diff] [blame] | 5842 | unsigned long long t; |
| 5843 | unsigned long usec_rem; |
Steven Rostedt | c8d7718 | 2009-04-29 18:03:45 -0400 | [diff] [blame] | 5844 | |
Li Zefan | e4f2d10 | 2009-06-15 10:57:28 +0800 | [diff] [blame] | 5845 | s = kmalloc(sizeof(*s), GFP_KERNEL); |
Steven Rostedt | c8d7718 | 2009-04-29 18:03:45 -0400 | [diff] [blame] | 5846 | if (!s) |
Roel Kluin | a646365 | 2009-11-11 22:26:35 +0100 | [diff] [blame] | 5847 | return -ENOMEM; |
Steven Rostedt | c8d7718 | 2009-04-29 18:03:45 -0400 | [diff] [blame] | 5848 | |
| 5849 | trace_seq_init(s); |
| 5850 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5851 | cnt = ring_buffer_entries_cpu(trace_buf->buffer, cpu); |
Steven Rostedt | c8d7718 | 2009-04-29 18:03:45 -0400 | [diff] [blame] | 5852 | trace_seq_printf(s, "entries: %ld\n", cnt); |
| 5853 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5854 | cnt = ring_buffer_overrun_cpu(trace_buf->buffer, cpu); |
Steven Rostedt | c8d7718 | 2009-04-29 18:03:45 -0400 | [diff] [blame] | 5855 | trace_seq_printf(s, "overrun: %ld\n", cnt); |
| 5856 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5857 | cnt = ring_buffer_commit_overrun_cpu(trace_buf->buffer, cpu); |
Steven Rostedt | c8d7718 | 2009-04-29 18:03:45 -0400 | [diff] [blame] | 5858 | trace_seq_printf(s, "commit overrun: %ld\n", cnt); |
| 5859 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5860 | cnt = ring_buffer_bytes_cpu(trace_buf->buffer, cpu); |
Vaibhav Nagarnaik | c64e148 | 2011-08-16 14:46:16 -0700 | [diff] [blame] | 5861 | trace_seq_printf(s, "bytes: %ld\n", cnt); |
| 5862 | |
Yoshihiro YUNOMAE | 58e8eed | 2013-04-23 10:32:39 +0900 | [diff] [blame] | 5863 | if (trace_clocks[tr->clock_id].in_ns) { |
Yoshihiro YUNOMAE | 11043d8b | 2012-11-13 12:18:23 -0800 | [diff] [blame] | 5864 | /* local or global for trace_clock */ |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5865 | t = ns2usecs(ring_buffer_oldest_event_ts(trace_buf->buffer, cpu)); |
Yoshihiro YUNOMAE | 11043d8b | 2012-11-13 12:18:23 -0800 | [diff] [blame] | 5866 | usec_rem = do_div(t, USEC_PER_SEC); |
| 5867 | trace_seq_printf(s, "oldest event ts: %5llu.%06lu\n", |
| 5868 | t, usec_rem); |
Vaibhav Nagarnaik | c64e148 | 2011-08-16 14:46:16 -0700 | [diff] [blame] | 5869 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5870 | t = ns2usecs(ring_buffer_time_stamp(trace_buf->buffer, cpu)); |
Yoshihiro YUNOMAE | 11043d8b | 2012-11-13 12:18:23 -0800 | [diff] [blame] | 5871 | usec_rem = do_div(t, USEC_PER_SEC); |
| 5872 | trace_seq_printf(s, "now ts: %5llu.%06lu\n", t, usec_rem); |
| 5873 | } else { |
| 5874 | /* counter or tsc mode for trace_clock */ |
| 5875 | trace_seq_printf(s, "oldest event ts: %llu\n", |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5876 | ring_buffer_oldest_event_ts(trace_buf->buffer, cpu)); |
Yoshihiro YUNOMAE | 11043d8b | 2012-11-13 12:18:23 -0800 | [diff] [blame] | 5877 | |
| 5878 | trace_seq_printf(s, "now ts: %llu\n", |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5879 | ring_buffer_time_stamp(trace_buf->buffer, cpu)); |
Yoshihiro YUNOMAE | 11043d8b | 2012-11-13 12:18:23 -0800 | [diff] [blame] | 5880 | } |
Vaibhav Nagarnaik | c64e148 | 2011-08-16 14:46:16 -0700 | [diff] [blame] | 5881 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5882 | cnt = ring_buffer_dropped_events_cpu(trace_buf->buffer, cpu); |
Slava Pestov | 884bfe8 | 2011-07-15 14:23:58 -0700 | [diff] [blame] | 5883 | trace_seq_printf(s, "dropped events: %ld\n", cnt); |
| 5884 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5885 | cnt = ring_buffer_read_events_cpu(trace_buf->buffer, cpu); |
Steven Rostedt (Red Hat) | ad96470 | 2013-01-29 17:45:49 -0500 | [diff] [blame] | 5886 | trace_seq_printf(s, "read events: %ld\n", cnt); |
| 5887 | |
Steven Rostedt (Red Hat) | 5ac48378 | 2014-11-14 15:49:41 -0500 | [diff] [blame] | 5888 | count = simple_read_from_buffer(ubuf, count, ppos, |
| 5889 | s->buffer, trace_seq_used(s)); |
Steven Rostedt | c8d7718 | 2009-04-29 18:03:45 -0400 | [diff] [blame] | 5890 | |
| 5891 | kfree(s); |
| 5892 | |
| 5893 | return count; |
| 5894 | } |
| 5895 | |
| 5896 | static const struct file_operations tracing_stats_fops = { |
Oleg Nesterov | 4d3435b | 2013-07-23 17:26:03 +0200 | [diff] [blame] | 5897 | .open = tracing_open_generic_tr, |
Steven Rostedt | c8d7718 | 2009-04-29 18:03:45 -0400 | [diff] [blame] | 5898 | .read = tracing_stats_read, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 5899 | .llseek = generic_file_llseek, |
Oleg Nesterov | 4d3435b | 2013-07-23 17:26:03 +0200 | [diff] [blame] | 5900 | .release = tracing_release_generic_tr, |
Steven Rostedt | c8d7718 | 2009-04-29 18:03:45 -0400 | [diff] [blame] | 5901 | }; |
| 5902 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5903 | #ifdef CONFIG_DYNAMIC_FTRACE |
| 5904 | |
Steven Rostedt | b807c3d | 2008-10-30 16:08:33 -0400 | [diff] [blame] | 5905 | int __weak ftrace_arch_read_dyn_info(char *buf, int size) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5906 | { |
Steven Rostedt | b807c3d | 2008-10-30 16:08:33 -0400 | [diff] [blame] | 5907 | return 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5908 | } |
| 5909 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5910 | static ssize_t |
Steven Rostedt | b807c3d | 2008-10-30 16:08:33 -0400 | [diff] [blame] | 5911 | tracing_read_dyn_info(struct file *filp, char __user *ubuf, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5912 | size_t cnt, loff_t *ppos) |
| 5913 | { |
Steven Rostedt | a26a2a2 | 2008-10-31 00:03:22 -0400 | [diff] [blame] | 5914 | static char ftrace_dyn_info_buffer[1024]; |
| 5915 | static DEFINE_MUTEX(dyn_info_mutex); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5916 | unsigned long *p = filp->private_data; |
Steven Rostedt | b807c3d | 2008-10-30 16:08:33 -0400 | [diff] [blame] | 5917 | char *buf = ftrace_dyn_info_buffer; |
Steven Rostedt | a26a2a2 | 2008-10-31 00:03:22 -0400 | [diff] [blame] | 5918 | int size = ARRAY_SIZE(ftrace_dyn_info_buffer); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5919 | int r; |
| 5920 | |
Steven Rostedt | b807c3d | 2008-10-30 16:08:33 -0400 | [diff] [blame] | 5921 | mutex_lock(&dyn_info_mutex); |
| 5922 | r = sprintf(buf, "%ld ", *p); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5923 | |
Steven Rostedt | a26a2a2 | 2008-10-31 00:03:22 -0400 | [diff] [blame] | 5924 | r += ftrace_arch_read_dyn_info(buf+r, (size-1)-r); |
Steven Rostedt | b807c3d | 2008-10-30 16:08:33 -0400 | [diff] [blame] | 5925 | buf[r++] = '\n'; |
| 5926 | |
| 5927 | r = simple_read_from_buffer(ubuf, cnt, ppos, buf, r); |
| 5928 | |
| 5929 | mutex_unlock(&dyn_info_mutex); |
| 5930 | |
| 5931 | return r; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5932 | } |
| 5933 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 5934 | static const struct file_operations tracing_dyn_info_fops = { |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 5935 | .open = tracing_open_generic, |
Steven Rostedt | b807c3d | 2008-10-30 16:08:33 -0400 | [diff] [blame] | 5936 | .read = tracing_read_dyn_info, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 5937 | .llseek = generic_file_llseek, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5938 | }; |
Steven Rostedt (Red Hat) | 77fd5c1 | 2013-03-12 11:49:18 -0400 | [diff] [blame] | 5939 | #endif /* CONFIG_DYNAMIC_FTRACE */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5940 | |
Steven Rostedt (Red Hat) | 77fd5c1 | 2013-03-12 11:49:18 -0400 | [diff] [blame] | 5941 | #if defined(CONFIG_TRACER_SNAPSHOT) && defined(CONFIG_DYNAMIC_FTRACE) |
| 5942 | static void |
| 5943 | ftrace_snapshot(unsigned long ip, unsigned long parent_ip, void **data) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5944 | { |
Steven Rostedt (Red Hat) | 77fd5c1 | 2013-03-12 11:49:18 -0400 | [diff] [blame] | 5945 | tracing_snapshot(); |
| 5946 | } |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5947 | |
Steven Rostedt (Red Hat) | 77fd5c1 | 2013-03-12 11:49:18 -0400 | [diff] [blame] | 5948 | static void |
| 5949 | ftrace_count_snapshot(unsigned long ip, unsigned long parent_ip, void **data) |
| 5950 | { |
| 5951 | unsigned long *count = (long *)data; |
| 5952 | |
| 5953 | if (!*count) |
| 5954 | return; |
| 5955 | |
| 5956 | if (*count != -1) |
| 5957 | (*count)--; |
| 5958 | |
| 5959 | tracing_snapshot(); |
| 5960 | } |
| 5961 | |
| 5962 | static int |
| 5963 | ftrace_snapshot_print(struct seq_file *m, unsigned long ip, |
| 5964 | struct ftrace_probe_ops *ops, void *data) |
| 5965 | { |
| 5966 | long count = (long)data; |
| 5967 | |
| 5968 | seq_printf(m, "%ps:", (void *)ip); |
| 5969 | |
Rasmus Villemoes | fa6f0cc | 2014-11-08 21:42:10 +0100 | [diff] [blame] | 5970 | seq_puts(m, "snapshot"); |
Steven Rostedt (Red Hat) | 77fd5c1 | 2013-03-12 11:49:18 -0400 | [diff] [blame] | 5971 | |
| 5972 | if (count == -1) |
Rasmus Villemoes | fa6f0cc | 2014-11-08 21:42:10 +0100 | [diff] [blame] | 5973 | seq_puts(m, ":unlimited\n"); |
Steven Rostedt (Red Hat) | 77fd5c1 | 2013-03-12 11:49:18 -0400 | [diff] [blame] | 5974 | else |
| 5975 | seq_printf(m, ":count=%ld\n", count); |
| 5976 | |
| 5977 | return 0; |
| 5978 | } |
| 5979 | |
| 5980 | static struct ftrace_probe_ops snapshot_probe_ops = { |
| 5981 | .func = ftrace_snapshot, |
| 5982 | .print = ftrace_snapshot_print, |
| 5983 | }; |
| 5984 | |
| 5985 | static struct ftrace_probe_ops snapshot_count_probe_ops = { |
| 5986 | .func = ftrace_count_snapshot, |
| 5987 | .print = ftrace_snapshot_print, |
| 5988 | }; |
| 5989 | |
| 5990 | static int |
| 5991 | ftrace_trace_snapshot_callback(struct ftrace_hash *hash, |
| 5992 | char *glob, char *cmd, char *param, int enable) |
| 5993 | { |
| 5994 | struct ftrace_probe_ops *ops; |
| 5995 | void *count = (void *)-1; |
| 5996 | char *number; |
| 5997 | int ret; |
| 5998 | |
| 5999 | /* hash funcs only work with set_ftrace_filter */ |
| 6000 | if (!enable) |
| 6001 | return -EINVAL; |
| 6002 | |
| 6003 | ops = param ? &snapshot_count_probe_ops : &snapshot_probe_ops; |
| 6004 | |
| 6005 | if (glob[0] == '!') { |
| 6006 | unregister_ftrace_function_probe_func(glob+1, ops); |
| 6007 | return 0; |
| 6008 | } |
| 6009 | |
| 6010 | if (!param) |
| 6011 | goto out_reg; |
| 6012 | |
| 6013 | number = strsep(¶m, ":"); |
| 6014 | |
| 6015 | if (!strlen(number)) |
| 6016 | goto out_reg; |
| 6017 | |
| 6018 | /* |
| 6019 | * We use the callback data field (which is a pointer) |
| 6020 | * as our counter. |
| 6021 | */ |
| 6022 | ret = kstrtoul(number, 0, (unsigned long *)&count); |
| 6023 | if (ret) |
| 6024 | return ret; |
| 6025 | |
| 6026 | out_reg: |
| 6027 | ret = register_ftrace_function_probe(glob, ops, count); |
| 6028 | |
| 6029 | if (ret >= 0) |
| 6030 | alloc_snapshot(&global_trace); |
| 6031 | |
| 6032 | return ret < 0 ? ret : 0; |
| 6033 | } |
| 6034 | |
| 6035 | static struct ftrace_func_command ftrace_snapshot_cmd = { |
| 6036 | .name = "snapshot", |
| 6037 | .func = ftrace_trace_snapshot_callback, |
| 6038 | }; |
| 6039 | |
Tom Zanussi | 38de93a | 2013-10-24 08:34:18 -0500 | [diff] [blame] | 6040 | static __init int register_snapshot_cmd(void) |
Steven Rostedt (Red Hat) | 77fd5c1 | 2013-03-12 11:49:18 -0400 | [diff] [blame] | 6041 | { |
| 6042 | return register_ftrace_command(&ftrace_snapshot_cmd); |
| 6043 | } |
| 6044 | #else |
Tom Zanussi | 38de93a | 2013-10-24 08:34:18 -0500 | [diff] [blame] | 6045 | static inline __init int register_snapshot_cmd(void) { return 0; } |
Steven Rostedt (Red Hat) | 77fd5c1 | 2013-03-12 11:49:18 -0400 | [diff] [blame] | 6046 | #endif /* defined(CONFIG_TRACER_SNAPSHOT) && defined(CONFIG_DYNAMIC_FTRACE) */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 6047 | |
Steven Rostedt (Red Hat) | 7eeafbc | 2015-01-26 21:00:48 -0500 | [diff] [blame] | 6048 | static struct dentry *tracing_get_dentry(struct trace_array *tr) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 6049 | { |
Steven Rostedt (Red Hat) | 8434dc9 | 2015-01-20 12:13:40 -0500 | [diff] [blame] | 6050 | if (WARN_ON(!tr->dir)) |
| 6051 | return ERR_PTR(-ENODEV); |
| 6052 | |
| 6053 | /* Top directory uses NULL as the parent */ |
| 6054 | if (tr->flags & TRACE_ARRAY_FL_GLOBAL) |
| 6055 | return NULL; |
| 6056 | |
| 6057 | /* All sub buffers have a descriptor */ |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6058 | return tr->dir; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 6059 | } |
| 6060 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6061 | static struct dentry *tracing_dentry_percpu(struct trace_array *tr, int cpu) |
| 6062 | { |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 6063 | struct dentry *d_tracer; |
| 6064 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6065 | if (tr->percpu_dir) |
| 6066 | return tr->percpu_dir; |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 6067 | |
Steven Rostedt (Red Hat) | 7eeafbc | 2015-01-26 21:00:48 -0500 | [diff] [blame] | 6068 | d_tracer = tracing_get_dentry(tr); |
Steven Rostedt (Red Hat) | 14a5ae4 | 2015-01-20 11:14:16 -0500 | [diff] [blame] | 6069 | if (IS_ERR(d_tracer)) |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 6070 | return NULL; |
| 6071 | |
Steven Rostedt (Red Hat) | 8434dc9 | 2015-01-20 12:13:40 -0500 | [diff] [blame] | 6072 | tr->percpu_dir = tracefs_create_dir("per_cpu", d_tracer); |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 6073 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6074 | WARN_ONCE(!tr->percpu_dir, |
Steven Rostedt (Red Hat) | 8434dc9 | 2015-01-20 12:13:40 -0500 | [diff] [blame] | 6075 | "Could not create tracefs directory 'per_cpu/%d'\n", cpu); |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 6076 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6077 | return tr->percpu_dir; |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 6078 | } |
| 6079 | |
Oleg Nesterov | 649e9c70 | 2013-07-23 17:25:54 +0200 | [diff] [blame] | 6080 | static struct dentry * |
| 6081 | trace_create_cpu_file(const char *name, umode_t mode, struct dentry *parent, |
| 6082 | void *data, long cpu, const struct file_operations *fops) |
| 6083 | { |
| 6084 | struct dentry *ret = trace_create_file(name, mode, parent, data, fops); |
| 6085 | |
| 6086 | if (ret) /* See tracing_get_cpu() */ |
David Howells | 7682c91 | 2015-03-17 22:26:16 +0000 | [diff] [blame] | 6087 | d_inode(ret)->i_cdev = (void *)(cpu + 1); |
Oleg Nesterov | 649e9c70 | 2013-07-23 17:25:54 +0200 | [diff] [blame] | 6088 | return ret; |
| 6089 | } |
| 6090 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6091 | static void |
Steven Rostedt (Red Hat) | 8434dc9 | 2015-01-20 12:13:40 -0500 | [diff] [blame] | 6092 | tracing_init_tracefs_percpu(struct trace_array *tr, long cpu) |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 6093 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6094 | struct dentry *d_percpu = tracing_dentry_percpu(tr, cpu); |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 6095 | struct dentry *d_cpu; |
Steven Rostedt | dd49a38 | 2010-10-20 21:51:26 -0400 | [diff] [blame] | 6096 | char cpu_dir[30]; /* 30 characters should be more than enough */ |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 6097 | |
Namhyung Kim | 0a3d7ce | 2012-04-23 10:11:57 +0900 | [diff] [blame] | 6098 | if (!d_percpu) |
| 6099 | return; |
| 6100 | |
Steven Rostedt | dd49a38 | 2010-10-20 21:51:26 -0400 | [diff] [blame] | 6101 | snprintf(cpu_dir, 30, "cpu%ld", cpu); |
Steven Rostedt (Red Hat) | 8434dc9 | 2015-01-20 12:13:40 -0500 | [diff] [blame] | 6102 | d_cpu = tracefs_create_dir(cpu_dir, d_percpu); |
Frederic Weisbecker | 8656e7a | 2009-02-26 00:41:38 +0100 | [diff] [blame] | 6103 | if (!d_cpu) { |
Steven Rostedt (Red Hat) | 8434dc9 | 2015-01-20 12:13:40 -0500 | [diff] [blame] | 6104 | pr_warning("Could not create tracefs '%s' entry\n", cpu_dir); |
Frederic Weisbecker | 8656e7a | 2009-02-26 00:41:38 +0100 | [diff] [blame] | 6105 | return; |
| 6106 | } |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 6107 | |
Frederic Weisbecker | 8656e7a | 2009-02-26 00:41:38 +0100 | [diff] [blame] | 6108 | /* per cpu trace_pipe */ |
Oleg Nesterov | 649e9c70 | 2013-07-23 17:25:54 +0200 | [diff] [blame] | 6109 | trace_create_cpu_file("trace_pipe", 0444, d_cpu, |
Oleg Nesterov | 1554420 | 2013-07-23 17:25:57 +0200 | [diff] [blame] | 6110 | tr, cpu, &tracing_pipe_fops); |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 6111 | |
| 6112 | /* per cpu trace */ |
Oleg Nesterov | 649e9c70 | 2013-07-23 17:25:54 +0200 | [diff] [blame] | 6113 | trace_create_cpu_file("trace", 0644, d_cpu, |
Oleg Nesterov | 6484c71 | 2013-07-23 17:26:10 +0200 | [diff] [blame] | 6114 | tr, cpu, &tracing_fops); |
Steven Rostedt | 7f96f93 | 2009-03-13 00:37:42 -0400 | [diff] [blame] | 6115 | |
Oleg Nesterov | 649e9c70 | 2013-07-23 17:25:54 +0200 | [diff] [blame] | 6116 | trace_create_cpu_file("trace_pipe_raw", 0444, d_cpu, |
Oleg Nesterov | 46ef2be | 2013-07-23 17:26:00 +0200 | [diff] [blame] | 6117 | tr, cpu, &tracing_buffers_fops); |
Steven Rostedt | c8d7718 | 2009-04-29 18:03:45 -0400 | [diff] [blame] | 6118 | |
Oleg Nesterov | 649e9c70 | 2013-07-23 17:25:54 +0200 | [diff] [blame] | 6119 | trace_create_cpu_file("stats", 0444, d_cpu, |
Oleg Nesterov | 4d3435b | 2013-07-23 17:26:03 +0200 | [diff] [blame] | 6120 | tr, cpu, &tracing_stats_fops); |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 6121 | |
Oleg Nesterov | 649e9c70 | 2013-07-23 17:25:54 +0200 | [diff] [blame] | 6122 | trace_create_cpu_file("buffer_size_kb", 0444, d_cpu, |
Oleg Nesterov | 0bc392e | 2013-07-23 17:26:06 +0200 | [diff] [blame] | 6123 | tr, cpu, &tracing_entries_fops); |
Steven Rostedt (Red Hat) | f1affca | 2013-03-05 14:35:11 -0500 | [diff] [blame] | 6124 | |
| 6125 | #ifdef CONFIG_TRACER_SNAPSHOT |
Oleg Nesterov | 649e9c70 | 2013-07-23 17:25:54 +0200 | [diff] [blame] | 6126 | trace_create_cpu_file("snapshot", 0644, d_cpu, |
Oleg Nesterov | 6484c71 | 2013-07-23 17:26:10 +0200 | [diff] [blame] | 6127 | tr, cpu, &snapshot_fops); |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 6128 | |
Oleg Nesterov | 649e9c70 | 2013-07-23 17:25:54 +0200 | [diff] [blame] | 6129 | trace_create_cpu_file("snapshot_raw", 0444, d_cpu, |
Oleg Nesterov | 46ef2be | 2013-07-23 17:26:00 +0200 | [diff] [blame] | 6130 | tr, cpu, &snapshot_raw_fops); |
Steven Rostedt (Red Hat) | f1affca | 2013-03-05 14:35:11 -0500 | [diff] [blame] | 6131 | #endif |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 6132 | } |
| 6133 | |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 6134 | #ifdef CONFIG_FTRACE_SELFTEST |
| 6135 | /* Let selftest have access to static functions in this file */ |
| 6136 | #include "trace_selftest.c" |
| 6137 | #endif |
| 6138 | |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 6139 | struct trace_option_dentry { |
| 6140 | struct tracer_opt *opt; |
| 6141 | struct tracer_flags *flags; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6142 | struct trace_array *tr; |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 6143 | struct dentry *entry; |
| 6144 | }; |
| 6145 | |
| 6146 | static ssize_t |
| 6147 | trace_options_read(struct file *filp, char __user *ubuf, size_t cnt, |
| 6148 | loff_t *ppos) |
| 6149 | { |
| 6150 | struct trace_option_dentry *topt = filp->private_data; |
| 6151 | char *buf; |
| 6152 | |
| 6153 | if (topt->flags->val & topt->opt->bit) |
| 6154 | buf = "1\n"; |
| 6155 | else |
| 6156 | buf = "0\n"; |
| 6157 | |
| 6158 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, 2); |
| 6159 | } |
| 6160 | |
| 6161 | static ssize_t |
| 6162 | trace_options_write(struct file *filp, const char __user *ubuf, size_t cnt, |
| 6163 | loff_t *ppos) |
| 6164 | { |
| 6165 | struct trace_option_dentry *topt = filp->private_data; |
| 6166 | unsigned long val; |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 6167 | int ret; |
| 6168 | |
Peter Huewe | 22fe9b5 | 2011-06-07 21:58:27 +0200 | [diff] [blame] | 6169 | ret = kstrtoul_from_user(ubuf, cnt, 10, &val); |
| 6170 | if (ret) |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 6171 | return ret; |
| 6172 | |
Li Zefan | 8d18eaa | 2009-12-08 11:17:06 +0800 | [diff] [blame] | 6173 | if (val != 0 && val != 1) |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 6174 | return -EINVAL; |
Li Zefan | 8d18eaa | 2009-12-08 11:17:06 +0800 | [diff] [blame] | 6175 | |
| 6176 | if (!!(topt->flags->val & topt->opt->bit) != val) { |
| 6177 | mutex_lock(&trace_types_lock); |
Steven Rostedt (Red Hat) | 8c1a49a | 2014-01-10 11:13:54 -0500 | [diff] [blame] | 6178 | ret = __set_tracer_option(topt->tr, topt->flags, |
Steven Rostedt | c757bea | 2009-12-21 22:35:16 -0500 | [diff] [blame] | 6179 | topt->opt, !val); |
Li Zefan | 8d18eaa | 2009-12-08 11:17:06 +0800 | [diff] [blame] | 6180 | mutex_unlock(&trace_types_lock); |
| 6181 | if (ret) |
| 6182 | return ret; |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 6183 | } |
| 6184 | |
| 6185 | *ppos += cnt; |
| 6186 | |
| 6187 | return cnt; |
| 6188 | } |
| 6189 | |
| 6190 | |
| 6191 | static const struct file_operations trace_options_fops = { |
| 6192 | .open = tracing_open_generic, |
| 6193 | .read = trace_options_read, |
| 6194 | .write = trace_options_write, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 6195 | .llseek = generic_file_llseek, |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 6196 | }; |
| 6197 | |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 6198 | static ssize_t |
| 6199 | trace_options_core_read(struct file *filp, char __user *ubuf, size_t cnt, |
| 6200 | loff_t *ppos) |
| 6201 | { |
| 6202 | long index = (long)filp->private_data; |
| 6203 | char *buf; |
| 6204 | |
| 6205 | if (trace_flags & (1 << index)) |
| 6206 | buf = "1\n"; |
| 6207 | else |
| 6208 | buf = "0\n"; |
| 6209 | |
| 6210 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, 2); |
| 6211 | } |
| 6212 | |
| 6213 | static ssize_t |
| 6214 | trace_options_core_write(struct file *filp, const char __user *ubuf, size_t cnt, |
| 6215 | loff_t *ppos) |
| 6216 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6217 | struct trace_array *tr = &global_trace; |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 6218 | long index = (long)filp->private_data; |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 6219 | unsigned long val; |
| 6220 | int ret; |
| 6221 | |
Peter Huewe | 22fe9b5 | 2011-06-07 21:58:27 +0200 | [diff] [blame] | 6222 | ret = kstrtoul_from_user(ubuf, cnt, 10, &val); |
| 6223 | if (ret) |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 6224 | return ret; |
| 6225 | |
Zhaolei | f2d84b6 | 2009-08-07 18:55:48 +0800 | [diff] [blame] | 6226 | if (val != 0 && val != 1) |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 6227 | return -EINVAL; |
Steven Rostedt (Red Hat) | 69d34da | 2013-03-14 13:50:56 -0400 | [diff] [blame] | 6228 | |
| 6229 | mutex_lock(&trace_types_lock); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6230 | ret = set_tracer_flag(tr, 1 << index, val); |
Steven Rostedt (Red Hat) | 69d34da | 2013-03-14 13:50:56 -0400 | [diff] [blame] | 6231 | mutex_unlock(&trace_types_lock); |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 6232 | |
Steven Rostedt (Red Hat) | 613f04a | 2013-03-14 15:03:53 -0400 | [diff] [blame] | 6233 | if (ret < 0) |
| 6234 | return ret; |
| 6235 | |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 6236 | *ppos += cnt; |
| 6237 | |
| 6238 | return cnt; |
| 6239 | } |
| 6240 | |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 6241 | static const struct file_operations trace_options_core_fops = { |
| 6242 | .open = tracing_open_generic, |
| 6243 | .read = trace_options_core_read, |
| 6244 | .write = trace_options_core_write, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 6245 | .llseek = generic_file_llseek, |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 6246 | }; |
| 6247 | |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 6248 | struct dentry *trace_create_file(const char *name, |
Al Viro | f4ae40a6 | 2011-07-24 04:33:43 -0400 | [diff] [blame] | 6249 | umode_t mode, |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 6250 | struct dentry *parent, |
| 6251 | void *data, |
| 6252 | const struct file_operations *fops) |
| 6253 | { |
| 6254 | struct dentry *ret; |
| 6255 | |
Steven Rostedt (Red Hat) | 8434dc9 | 2015-01-20 12:13:40 -0500 | [diff] [blame] | 6256 | ret = tracefs_create_file(name, mode, parent, data, fops); |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 6257 | if (!ret) |
Steven Rostedt (Red Hat) | 8434dc9 | 2015-01-20 12:13:40 -0500 | [diff] [blame] | 6258 | pr_warning("Could not create tracefs '%s' entry\n", name); |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 6259 | |
| 6260 | return ret; |
| 6261 | } |
| 6262 | |
| 6263 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6264 | static struct dentry *trace_options_init_dentry(struct trace_array *tr) |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 6265 | { |
| 6266 | struct dentry *d_tracer; |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 6267 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6268 | if (tr->options) |
| 6269 | return tr->options; |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 6270 | |
Steven Rostedt (Red Hat) | 7eeafbc | 2015-01-26 21:00:48 -0500 | [diff] [blame] | 6271 | d_tracer = tracing_get_dentry(tr); |
Steven Rostedt (Red Hat) | 14a5ae4 | 2015-01-20 11:14:16 -0500 | [diff] [blame] | 6272 | if (IS_ERR(d_tracer)) |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 6273 | return NULL; |
| 6274 | |
Steven Rostedt (Red Hat) | 8434dc9 | 2015-01-20 12:13:40 -0500 | [diff] [blame] | 6275 | tr->options = tracefs_create_dir("options", d_tracer); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6276 | if (!tr->options) { |
Steven Rostedt (Red Hat) | 8434dc9 | 2015-01-20 12:13:40 -0500 | [diff] [blame] | 6277 | pr_warning("Could not create tracefs directory 'options'\n"); |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 6278 | return NULL; |
| 6279 | } |
| 6280 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6281 | return tr->options; |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 6282 | } |
| 6283 | |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 6284 | static void |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6285 | create_trace_option_file(struct trace_array *tr, |
| 6286 | struct trace_option_dentry *topt, |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 6287 | struct tracer_flags *flags, |
| 6288 | struct tracer_opt *opt) |
| 6289 | { |
| 6290 | struct dentry *t_options; |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 6291 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6292 | t_options = trace_options_init_dentry(tr); |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 6293 | if (!t_options) |
| 6294 | return; |
| 6295 | |
| 6296 | topt->flags = flags; |
| 6297 | topt->opt = opt; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6298 | topt->tr = tr; |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 6299 | |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 6300 | topt->entry = trace_create_file(opt->name, 0644, t_options, topt, |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 6301 | &trace_options_fops); |
| 6302 | |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 6303 | } |
| 6304 | |
| 6305 | static struct trace_option_dentry * |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6306 | create_trace_option_files(struct trace_array *tr, struct tracer *tracer) |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 6307 | { |
| 6308 | struct trace_option_dentry *topts; |
| 6309 | struct tracer_flags *flags; |
| 6310 | struct tracer_opt *opts; |
| 6311 | int cnt; |
| 6312 | |
| 6313 | if (!tracer) |
| 6314 | return NULL; |
| 6315 | |
| 6316 | flags = tracer->flags; |
| 6317 | |
| 6318 | if (!flags || !flags->opts) |
| 6319 | return NULL; |
| 6320 | |
| 6321 | opts = flags->opts; |
| 6322 | |
| 6323 | for (cnt = 0; opts[cnt].name; cnt++) |
| 6324 | ; |
| 6325 | |
Steven Rostedt | 0cfe824 | 2009-02-27 10:51:10 -0500 | [diff] [blame] | 6326 | topts = kcalloc(cnt + 1, sizeof(*topts), GFP_KERNEL); |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 6327 | if (!topts) |
| 6328 | return NULL; |
| 6329 | |
| 6330 | for (cnt = 0; opts[cnt].name; cnt++) |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6331 | create_trace_option_file(tr, &topts[cnt], flags, |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 6332 | &opts[cnt]); |
| 6333 | |
| 6334 | return topts; |
| 6335 | } |
| 6336 | |
| 6337 | static void |
| 6338 | destroy_trace_option_files(struct trace_option_dentry *topts) |
| 6339 | { |
| 6340 | int cnt; |
| 6341 | |
| 6342 | if (!topts) |
| 6343 | return; |
| 6344 | |
Fabian Frederick | 3f4d8f7 | 2014-06-26 19:14:31 +0200 | [diff] [blame] | 6345 | for (cnt = 0; topts[cnt].opt; cnt++) |
Steven Rostedt (Red Hat) | 8434dc9 | 2015-01-20 12:13:40 -0500 | [diff] [blame] | 6346 | tracefs_remove(topts[cnt].entry); |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 6347 | |
| 6348 | kfree(topts); |
| 6349 | } |
| 6350 | |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 6351 | static struct dentry * |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6352 | create_trace_option_core_file(struct trace_array *tr, |
| 6353 | const char *option, long index) |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 6354 | { |
| 6355 | struct dentry *t_options; |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 6356 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6357 | t_options = trace_options_init_dentry(tr); |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 6358 | if (!t_options) |
| 6359 | return NULL; |
| 6360 | |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 6361 | return trace_create_file(option, 0644, t_options, (void *)index, |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 6362 | &trace_options_core_fops); |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 6363 | } |
| 6364 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6365 | static __init void create_trace_options_dir(struct trace_array *tr) |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 6366 | { |
| 6367 | struct dentry *t_options; |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 6368 | int i; |
| 6369 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6370 | t_options = trace_options_init_dentry(tr); |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 6371 | if (!t_options) |
| 6372 | return; |
| 6373 | |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 6374 | for (i = 0; trace_options[i]; i++) |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6375 | create_trace_option_core_file(tr, trace_options[i], i); |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 6376 | } |
| 6377 | |
Steven Rostedt | 499e547 | 2012-02-22 15:50:28 -0500 | [diff] [blame] | 6378 | static ssize_t |
| 6379 | rb_simple_read(struct file *filp, char __user *ubuf, |
| 6380 | size_t cnt, loff_t *ppos) |
| 6381 | { |
Steven Rostedt | 348f0fc | 2012-04-16 15:41:28 -0400 | [diff] [blame] | 6382 | struct trace_array *tr = filp->private_data; |
Steven Rostedt | 499e547 | 2012-02-22 15:50:28 -0500 | [diff] [blame] | 6383 | char buf[64]; |
| 6384 | int r; |
| 6385 | |
Steven Rostedt (Red Hat) | 10246fa | 2013-07-01 15:58:24 -0400 | [diff] [blame] | 6386 | r = tracer_tracing_is_on(tr); |
Steven Rostedt | 499e547 | 2012-02-22 15:50:28 -0500 | [diff] [blame] | 6387 | r = sprintf(buf, "%d\n", r); |
| 6388 | |
| 6389 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, r); |
| 6390 | } |
| 6391 | |
| 6392 | static ssize_t |
| 6393 | rb_simple_write(struct file *filp, const char __user *ubuf, |
| 6394 | size_t cnt, loff_t *ppos) |
| 6395 | { |
Steven Rostedt | 348f0fc | 2012-04-16 15:41:28 -0400 | [diff] [blame] | 6396 | struct trace_array *tr = filp->private_data; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 6397 | struct ring_buffer *buffer = tr->trace_buffer.buffer; |
Steven Rostedt | 499e547 | 2012-02-22 15:50:28 -0500 | [diff] [blame] | 6398 | unsigned long val; |
| 6399 | int ret; |
| 6400 | |
| 6401 | ret = kstrtoul_from_user(ubuf, cnt, 10, &val); |
| 6402 | if (ret) |
| 6403 | return ret; |
| 6404 | |
| 6405 | if (buffer) { |
Steven Rostedt | 2df8f8a | 2013-01-11 16:14:10 -0500 | [diff] [blame] | 6406 | mutex_lock(&trace_types_lock); |
| 6407 | if (val) { |
Steven Rostedt (Red Hat) | 10246fa | 2013-07-01 15:58:24 -0400 | [diff] [blame] | 6408 | tracer_tracing_on(tr); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6409 | if (tr->current_trace->start) |
| 6410 | tr->current_trace->start(tr); |
Steven Rostedt | 2df8f8a | 2013-01-11 16:14:10 -0500 | [diff] [blame] | 6411 | } else { |
Steven Rostedt (Red Hat) | 10246fa | 2013-07-01 15:58:24 -0400 | [diff] [blame] | 6412 | tracer_tracing_off(tr); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6413 | if (tr->current_trace->stop) |
| 6414 | tr->current_trace->stop(tr); |
Steven Rostedt | 2df8f8a | 2013-01-11 16:14:10 -0500 | [diff] [blame] | 6415 | } |
| 6416 | mutex_unlock(&trace_types_lock); |
Steven Rostedt | 499e547 | 2012-02-22 15:50:28 -0500 | [diff] [blame] | 6417 | } |
| 6418 | |
| 6419 | (*ppos)++; |
| 6420 | |
| 6421 | return cnt; |
| 6422 | } |
| 6423 | |
| 6424 | static const struct file_operations rb_simple_fops = { |
Steven Rostedt (Red Hat) | 7b85af6 | 2013-07-01 23:34:22 -0400 | [diff] [blame] | 6425 | .open = tracing_open_generic_tr, |
Steven Rostedt | 499e547 | 2012-02-22 15:50:28 -0500 | [diff] [blame] | 6426 | .read = rb_simple_read, |
| 6427 | .write = rb_simple_write, |
Steven Rostedt (Red Hat) | 7b85af6 | 2013-07-01 23:34:22 -0400 | [diff] [blame] | 6428 | .release = tracing_release_generic_tr, |
Steven Rostedt | 499e547 | 2012-02-22 15:50:28 -0500 | [diff] [blame] | 6429 | .llseek = default_llseek, |
| 6430 | }; |
| 6431 | |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 6432 | struct dentry *trace_instance_dir; |
| 6433 | |
| 6434 | static void |
Steven Rostedt (Red Hat) | 8434dc9 | 2015-01-20 12:13:40 -0500 | [diff] [blame] | 6435 | init_tracer_tracefs(struct trace_array *tr, struct dentry *d_tracer); |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 6436 | |
Steven Rostedt (Red Hat) | 55034cd | 2013-03-07 22:48:09 -0500 | [diff] [blame] | 6437 | static int |
| 6438 | 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] | 6439 | { |
| 6440 | enum ring_buffer_flags rb_flags; |
Steven Rostedt (Red Hat) | 737223f | 2013-03-05 21:13:47 -0500 | [diff] [blame] | 6441 | |
| 6442 | rb_flags = trace_flags & TRACE_ITER_OVERWRITE ? RB_FL_OVERWRITE : 0; |
| 6443 | |
Steven Rostedt (Red Hat) | dced341 | 2014-01-14 10:19:46 -0500 | [diff] [blame] | 6444 | buf->tr = tr; |
| 6445 | |
Steven Rostedt (Red Hat) | 55034cd | 2013-03-07 22:48:09 -0500 | [diff] [blame] | 6446 | buf->buffer = ring_buffer_alloc(size, rb_flags); |
| 6447 | if (!buf->buffer) |
| 6448 | return -ENOMEM; |
Steven Rostedt (Red Hat) | 737223f | 2013-03-05 21:13:47 -0500 | [diff] [blame] | 6449 | |
Steven Rostedt (Red Hat) | 55034cd | 2013-03-07 22:48:09 -0500 | [diff] [blame] | 6450 | buf->data = alloc_percpu(struct trace_array_cpu); |
| 6451 | if (!buf->data) { |
| 6452 | ring_buffer_free(buf->buffer); |
| 6453 | return -ENOMEM; |
| 6454 | } |
Steven Rostedt (Red Hat) | 737223f | 2013-03-05 21:13:47 -0500 | [diff] [blame] | 6455 | |
Steven Rostedt (Red Hat) | 737223f | 2013-03-05 21:13:47 -0500 | [diff] [blame] | 6456 | /* Allocate the first page for all buffers */ |
| 6457 | set_buffer_entries(&tr->trace_buffer, |
| 6458 | ring_buffer_size(tr->trace_buffer.buffer, 0)); |
| 6459 | |
Steven Rostedt (Red Hat) | 55034cd | 2013-03-07 22:48:09 -0500 | [diff] [blame] | 6460 | return 0; |
| 6461 | } |
| 6462 | |
| 6463 | static int allocate_trace_buffers(struct trace_array *tr, int size) |
| 6464 | { |
| 6465 | int ret; |
| 6466 | |
| 6467 | ret = allocate_trace_buffer(tr, &tr->trace_buffer, size); |
| 6468 | if (ret) |
| 6469 | return ret; |
| 6470 | |
Steven Rostedt (Red Hat) | 737223f | 2013-03-05 21:13:47 -0500 | [diff] [blame] | 6471 | #ifdef CONFIG_TRACER_MAX_TRACE |
Steven Rostedt (Red Hat) | 55034cd | 2013-03-07 22:48:09 -0500 | [diff] [blame] | 6472 | ret = allocate_trace_buffer(tr, &tr->max_buffer, |
| 6473 | allocate_snapshot ? size : 1); |
| 6474 | if (WARN_ON(ret)) { |
| 6475 | ring_buffer_free(tr->trace_buffer.buffer); |
| 6476 | free_percpu(tr->trace_buffer.data); |
| 6477 | return -ENOMEM; |
| 6478 | } |
| 6479 | tr->allocated_snapshot = allocate_snapshot; |
Steven Rostedt (Red Hat) | 737223f | 2013-03-05 21:13:47 -0500 | [diff] [blame] | 6480 | |
Steven Rostedt (Red Hat) | 55034cd | 2013-03-07 22:48:09 -0500 | [diff] [blame] | 6481 | /* |
| 6482 | * Only the top level trace array gets its snapshot allocated |
| 6483 | * from the kernel command line. |
| 6484 | */ |
| 6485 | allocate_snapshot = false; |
Steven Rostedt (Red Hat) | 737223f | 2013-03-05 21:13:47 -0500 | [diff] [blame] | 6486 | #endif |
| 6487 | return 0; |
Steven Rostedt (Red Hat) | 737223f | 2013-03-05 21:13:47 -0500 | [diff] [blame] | 6488 | } |
| 6489 | |
Steven Rostedt (Red Hat) | f0b70cc | 2014-06-10 12:06:30 -0400 | [diff] [blame] | 6490 | static void free_trace_buffer(struct trace_buffer *buf) |
| 6491 | { |
| 6492 | if (buf->buffer) { |
| 6493 | ring_buffer_free(buf->buffer); |
| 6494 | buf->buffer = NULL; |
| 6495 | free_percpu(buf->data); |
| 6496 | buf->data = NULL; |
| 6497 | } |
| 6498 | } |
| 6499 | |
Steven Rostedt (Red Hat) | 23aaa3c | 2014-06-06 00:01:46 -0400 | [diff] [blame] | 6500 | static void free_trace_buffers(struct trace_array *tr) |
| 6501 | { |
| 6502 | if (!tr) |
| 6503 | return; |
| 6504 | |
Steven Rostedt (Red Hat) | f0b70cc | 2014-06-10 12:06:30 -0400 | [diff] [blame] | 6505 | free_trace_buffer(&tr->trace_buffer); |
Steven Rostedt (Red Hat) | 23aaa3c | 2014-06-06 00:01:46 -0400 | [diff] [blame] | 6506 | |
| 6507 | #ifdef CONFIG_TRACER_MAX_TRACE |
Steven Rostedt (Red Hat) | f0b70cc | 2014-06-10 12:06:30 -0400 | [diff] [blame] | 6508 | free_trace_buffer(&tr->max_buffer); |
Steven Rostedt (Red Hat) | 23aaa3c | 2014-06-06 00:01:46 -0400 | [diff] [blame] | 6509 | #endif |
| 6510 | } |
| 6511 | |
Steven Rostedt (Red Hat) | eae4735 | 2015-01-21 10:01:39 -0500 | [diff] [blame] | 6512 | static int instance_mkdir(const char *name) |
Steven Rostedt (Red Hat) | 737223f | 2013-03-05 21:13:47 -0500 | [diff] [blame] | 6513 | { |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 6514 | struct trace_array *tr; |
| 6515 | int ret; |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 6516 | |
| 6517 | mutex_lock(&trace_types_lock); |
| 6518 | |
| 6519 | ret = -EEXIST; |
| 6520 | list_for_each_entry(tr, &ftrace_trace_arrays, list) { |
| 6521 | if (tr->name && strcmp(tr->name, name) == 0) |
| 6522 | goto out_unlock; |
| 6523 | } |
| 6524 | |
| 6525 | ret = -ENOMEM; |
| 6526 | tr = kzalloc(sizeof(*tr), GFP_KERNEL); |
| 6527 | if (!tr) |
| 6528 | goto out_unlock; |
| 6529 | |
| 6530 | tr->name = kstrdup(name, GFP_KERNEL); |
| 6531 | if (!tr->name) |
| 6532 | goto out_free_tr; |
| 6533 | |
Alexander Z Lam | ccfe9e4 | 2013-08-08 09:47:45 -0700 | [diff] [blame] | 6534 | if (!alloc_cpumask_var(&tr->tracing_cpumask, GFP_KERNEL)) |
| 6535 | goto out_free_tr; |
| 6536 | |
| 6537 | cpumask_copy(tr->tracing_cpumask, cpu_all_mask); |
| 6538 | |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 6539 | raw_spin_lock_init(&tr->start_lock); |
| 6540 | |
Steven Rostedt (Red Hat) | 0b9b12c | 2014-01-14 10:04:59 -0500 | [diff] [blame] | 6541 | tr->max_lock = (arch_spinlock_t)__ARCH_SPIN_LOCK_UNLOCKED; |
| 6542 | |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 6543 | tr->current_trace = &nop_trace; |
| 6544 | |
| 6545 | INIT_LIST_HEAD(&tr->systems); |
| 6546 | INIT_LIST_HEAD(&tr->events); |
| 6547 | |
Steven Rostedt (Red Hat) | 737223f | 2013-03-05 21:13:47 -0500 | [diff] [blame] | 6548 | if (allocate_trace_buffers(tr, trace_buf_size) < 0) |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 6549 | goto out_free_tr; |
| 6550 | |
Steven Rostedt (Red Hat) | 8434dc9 | 2015-01-20 12:13:40 -0500 | [diff] [blame] | 6551 | tr->dir = tracefs_create_dir(name, trace_instance_dir); |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 6552 | if (!tr->dir) |
| 6553 | goto out_free_tr; |
| 6554 | |
| 6555 | ret = event_trace_add_tracer(tr->dir, tr); |
Alexander Z Lam | 609e85a | 2013-07-10 17:34:34 -0700 | [diff] [blame] | 6556 | if (ret) { |
Steven Rostedt (Red Hat) | 8434dc9 | 2015-01-20 12:13:40 -0500 | [diff] [blame] | 6557 | tracefs_remove_recursive(tr->dir); |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 6558 | goto out_free_tr; |
Alexander Z Lam | 609e85a | 2013-07-10 17:34:34 -0700 | [diff] [blame] | 6559 | } |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 6560 | |
Steven Rostedt (Red Hat) | 8434dc9 | 2015-01-20 12:13:40 -0500 | [diff] [blame] | 6561 | init_tracer_tracefs(tr, tr->dir); |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 6562 | |
| 6563 | list_add(&tr->list, &ftrace_trace_arrays); |
| 6564 | |
| 6565 | mutex_unlock(&trace_types_lock); |
| 6566 | |
| 6567 | return 0; |
| 6568 | |
| 6569 | out_free_tr: |
Steven Rostedt (Red Hat) | 23aaa3c | 2014-06-06 00:01:46 -0400 | [diff] [blame] | 6570 | free_trace_buffers(tr); |
Alexander Z Lam | ccfe9e4 | 2013-08-08 09:47:45 -0700 | [diff] [blame] | 6571 | free_cpumask_var(tr->tracing_cpumask); |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 6572 | kfree(tr->name); |
| 6573 | kfree(tr); |
| 6574 | |
| 6575 | out_unlock: |
| 6576 | mutex_unlock(&trace_types_lock); |
| 6577 | |
| 6578 | return ret; |
| 6579 | |
| 6580 | } |
| 6581 | |
Steven Rostedt (Red Hat) | eae4735 | 2015-01-21 10:01:39 -0500 | [diff] [blame] | 6582 | static int instance_rmdir(const char *name) |
Steven Rostedt | 0c8916c | 2012-08-07 16:14:16 -0400 | [diff] [blame] | 6583 | { |
| 6584 | struct trace_array *tr; |
| 6585 | int found = 0; |
| 6586 | int ret; |
| 6587 | |
| 6588 | mutex_lock(&trace_types_lock); |
| 6589 | |
| 6590 | ret = -ENODEV; |
| 6591 | list_for_each_entry(tr, &ftrace_trace_arrays, list) { |
| 6592 | if (tr->name && strcmp(tr->name, name) == 0) { |
| 6593 | found = 1; |
| 6594 | break; |
| 6595 | } |
| 6596 | } |
| 6597 | if (!found) |
| 6598 | goto out_unlock; |
| 6599 | |
Steven Rostedt (Red Hat) | a695cb5 | 2013-03-06 15:27:24 -0500 | [diff] [blame] | 6600 | ret = -EBUSY; |
Steven Rostedt (Red Hat) | cf6ab6d | 2014-12-15 20:13:31 -0500 | [diff] [blame] | 6601 | if (tr->ref || (tr->current_trace && tr->current_trace->ref)) |
Steven Rostedt (Red Hat) | a695cb5 | 2013-03-06 15:27:24 -0500 | [diff] [blame] | 6602 | goto out_unlock; |
| 6603 | |
Steven Rostedt | 0c8916c | 2012-08-07 16:14:16 -0400 | [diff] [blame] | 6604 | list_del(&tr->list); |
| 6605 | |
Steven Rostedt (Red Hat) | 6b450d2 | 2014-01-14 08:43:01 -0500 | [diff] [blame] | 6606 | tracing_set_nop(tr); |
Steven Rostedt | 0c8916c | 2012-08-07 16:14:16 -0400 | [diff] [blame] | 6607 | event_trace_del_tracer(tr); |
Steven Rostedt (Red Hat) | 591dffd | 2014-01-10 16:17:45 -0500 | [diff] [blame] | 6608 | ftrace_destroy_function_files(tr); |
Steven Rostedt | 0c8916c | 2012-08-07 16:14:16 -0400 | [diff] [blame] | 6609 | debugfs_remove_recursive(tr->dir); |
Steven Rostedt (Red Hat) | a9fcaaa | 2014-06-06 23:17:28 -0400 | [diff] [blame] | 6610 | free_trace_buffers(tr); |
Steven Rostedt | 0c8916c | 2012-08-07 16:14:16 -0400 | [diff] [blame] | 6611 | |
| 6612 | kfree(tr->name); |
| 6613 | kfree(tr); |
| 6614 | |
| 6615 | ret = 0; |
| 6616 | |
| 6617 | out_unlock: |
| 6618 | mutex_unlock(&trace_types_lock); |
| 6619 | |
| 6620 | return ret; |
| 6621 | } |
| 6622 | |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 6623 | static __init void create_trace_instances(struct dentry *d_tracer) |
| 6624 | { |
Steven Rostedt (Red Hat) | eae4735 | 2015-01-21 10:01:39 -0500 | [diff] [blame] | 6625 | trace_instance_dir = tracefs_create_instance_dir("instances", d_tracer, |
| 6626 | instance_mkdir, |
| 6627 | instance_rmdir); |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 6628 | if (WARN_ON(!trace_instance_dir)) |
| 6629 | return; |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 6630 | } |
| 6631 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6632 | static void |
Steven Rostedt (Red Hat) | 8434dc9 | 2015-01-20 12:13:40 -0500 | [diff] [blame] | 6633 | init_tracer_tracefs(struct trace_array *tr, struct dentry *d_tracer) |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6634 | { |
Steven Rostedt (Red Hat) | 121aaee | 2013-03-05 21:52:25 -0500 | [diff] [blame] | 6635 | int cpu; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6636 | |
Steven Rostedt (Red Hat) | 607e2ea | 2013-11-06 22:42:48 -0500 | [diff] [blame] | 6637 | trace_create_file("available_tracers", 0444, d_tracer, |
| 6638 | tr, &show_traces_fops); |
| 6639 | |
| 6640 | trace_create_file("current_tracer", 0644, d_tracer, |
| 6641 | tr, &set_tracer_fops); |
| 6642 | |
Alexander Z Lam | ccfe9e4 | 2013-08-08 09:47:45 -0700 | [diff] [blame] | 6643 | trace_create_file("tracing_cpumask", 0644, d_tracer, |
| 6644 | tr, &tracing_cpumask_fops); |
| 6645 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6646 | trace_create_file("trace_options", 0644, d_tracer, |
| 6647 | tr, &tracing_iter_fops); |
| 6648 | |
| 6649 | trace_create_file("trace", 0644, d_tracer, |
Oleg Nesterov | 6484c71 | 2013-07-23 17:26:10 +0200 | [diff] [blame] | 6650 | tr, &tracing_fops); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6651 | |
| 6652 | trace_create_file("trace_pipe", 0444, d_tracer, |
Oleg Nesterov | 1554420 | 2013-07-23 17:25:57 +0200 | [diff] [blame] | 6653 | tr, &tracing_pipe_fops); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6654 | |
| 6655 | trace_create_file("buffer_size_kb", 0644, d_tracer, |
Oleg Nesterov | 0bc392e | 2013-07-23 17:26:06 +0200 | [diff] [blame] | 6656 | tr, &tracing_entries_fops); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6657 | |
| 6658 | trace_create_file("buffer_total_size_kb", 0444, d_tracer, |
| 6659 | tr, &tracing_total_entries_fops); |
| 6660 | |
Wang YanQing | 238ae93 | 2013-05-26 16:52:01 +0800 | [diff] [blame] | 6661 | trace_create_file("free_buffer", 0200, d_tracer, |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6662 | tr, &tracing_free_buffer_fops); |
| 6663 | |
| 6664 | trace_create_file("trace_marker", 0220, d_tracer, |
| 6665 | tr, &tracing_mark_fops); |
| 6666 | |
| 6667 | trace_create_file("trace_clock", 0644, d_tracer, tr, |
| 6668 | &trace_clock_fops); |
| 6669 | |
| 6670 | trace_create_file("tracing_on", 0644, d_tracer, |
Oleg Nesterov | 6484c71 | 2013-07-23 17:26:10 +0200 | [diff] [blame] | 6671 | tr, &rb_simple_fops); |
Steven Rostedt (Red Hat) | ce9bae5 | 2013-03-05 21:23:55 -0500 | [diff] [blame] | 6672 | |
Steven Rostedt (Red Hat) | 6d9b3fa | 2014-01-14 11:28:38 -0500 | [diff] [blame] | 6673 | #ifdef CONFIG_TRACER_MAX_TRACE |
| 6674 | trace_create_file("tracing_max_latency", 0644, d_tracer, |
| 6675 | &tr->max_latency, &tracing_max_lat_fops); |
| 6676 | #endif |
| 6677 | |
Steven Rostedt (Red Hat) | 591dffd | 2014-01-10 16:17:45 -0500 | [diff] [blame] | 6678 | if (ftrace_create_function_files(tr, d_tracer)) |
| 6679 | WARN(1, "Could not allocate function filter files"); |
| 6680 | |
Steven Rostedt (Red Hat) | ce9bae5 | 2013-03-05 21:23:55 -0500 | [diff] [blame] | 6681 | #ifdef CONFIG_TRACER_SNAPSHOT |
| 6682 | trace_create_file("snapshot", 0644, d_tracer, |
Oleg Nesterov | 6484c71 | 2013-07-23 17:26:10 +0200 | [diff] [blame] | 6683 | tr, &snapshot_fops); |
Steven Rostedt (Red Hat) | ce9bae5 | 2013-03-05 21:23:55 -0500 | [diff] [blame] | 6684 | #endif |
Steven Rostedt (Red Hat) | 121aaee | 2013-03-05 21:52:25 -0500 | [diff] [blame] | 6685 | |
| 6686 | for_each_tracing_cpu(cpu) |
Steven Rostedt (Red Hat) | 8434dc9 | 2015-01-20 12:13:40 -0500 | [diff] [blame] | 6687 | tracing_init_tracefs_percpu(tr, cpu); |
Steven Rostedt (Red Hat) | 121aaee | 2013-03-05 21:52:25 -0500 | [diff] [blame] | 6688 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6689 | } |
| 6690 | |
Steven Rostedt (Red Hat) | f76180b | 2015-01-20 15:48:46 -0500 | [diff] [blame] | 6691 | static struct vfsmount *trace_automount(void *ingore) |
| 6692 | { |
| 6693 | struct vfsmount *mnt; |
| 6694 | struct file_system_type *type; |
| 6695 | |
| 6696 | /* |
| 6697 | * To maintain backward compatibility for tools that mount |
| 6698 | * debugfs to get to the tracing facility, tracefs is automatically |
| 6699 | * mounted to the debugfs/tracing directory. |
| 6700 | */ |
| 6701 | type = get_fs_type("tracefs"); |
| 6702 | if (!type) |
| 6703 | return NULL; |
| 6704 | mnt = vfs_kern_mount(type, 0, "tracefs", NULL); |
| 6705 | put_filesystem(type); |
| 6706 | if (IS_ERR(mnt)) |
| 6707 | return NULL; |
| 6708 | mntget(mnt); |
| 6709 | |
| 6710 | return mnt; |
| 6711 | } |
| 6712 | |
Steven Rostedt (Red Hat) | 7eeafbc | 2015-01-26 21:00:48 -0500 | [diff] [blame] | 6713 | /** |
| 6714 | * tracing_init_dentry - initialize top level trace array |
| 6715 | * |
| 6716 | * This is called when creating files or directories in the tracing |
| 6717 | * directory. It is called via fs_initcall() by any of the boot up code |
| 6718 | * and expects to return the dentry of the top level tracing directory. |
| 6719 | */ |
| 6720 | struct dentry *tracing_init_dentry(void) |
| 6721 | { |
| 6722 | struct trace_array *tr = &global_trace; |
| 6723 | |
Steven Rostedt (Red Hat) | f76180b | 2015-01-20 15:48:46 -0500 | [diff] [blame] | 6724 | /* The top level trace array uses NULL as parent */ |
Steven Rostedt (Red Hat) | 7eeafbc | 2015-01-26 21:00:48 -0500 | [diff] [blame] | 6725 | if (tr->dir) |
Steven Rostedt (Red Hat) | f76180b | 2015-01-20 15:48:46 -0500 | [diff] [blame] | 6726 | return NULL; |
Steven Rostedt (Red Hat) | 7eeafbc | 2015-01-26 21:00:48 -0500 | [diff] [blame] | 6727 | |
| 6728 | if (WARN_ON(!debugfs_initialized())) |
| 6729 | return ERR_PTR(-ENODEV); |
| 6730 | |
Steven Rostedt (Red Hat) | f76180b | 2015-01-20 15:48:46 -0500 | [diff] [blame] | 6731 | /* |
| 6732 | * As there may still be users that expect the tracing |
| 6733 | * files to exist in debugfs/tracing, we must automount |
| 6734 | * the tracefs file system there, so older tools still |
| 6735 | * work with the newer kerenl. |
| 6736 | */ |
| 6737 | tr->dir = debugfs_create_automount("tracing", NULL, |
| 6738 | trace_automount, NULL); |
Steven Rostedt (Red Hat) | 7eeafbc | 2015-01-26 21:00:48 -0500 | [diff] [blame] | 6739 | if (!tr->dir) { |
| 6740 | pr_warn_once("Could not create debugfs directory 'tracing'\n"); |
| 6741 | return ERR_PTR(-ENOMEM); |
| 6742 | } |
| 6743 | |
Steven Rostedt (Red Hat) | 8434dc9 | 2015-01-20 12:13:40 -0500 | [diff] [blame] | 6744 | return NULL; |
Steven Rostedt (Red Hat) | 7eeafbc | 2015-01-26 21:00:48 -0500 | [diff] [blame] | 6745 | } |
| 6746 | |
Steven Rostedt (Red Hat) | 0c564a5 | 2015-03-24 17:58:09 -0400 | [diff] [blame] | 6747 | extern struct trace_enum_map *__start_ftrace_enum_maps[]; |
| 6748 | extern struct trace_enum_map *__stop_ftrace_enum_maps[]; |
| 6749 | |
| 6750 | static void __init trace_enum_init(void) |
| 6751 | { |
Steven Rostedt (Red Hat) | 3673b8e | 2015-03-25 15:44:21 -0400 | [diff] [blame] | 6752 | int len; |
| 6753 | |
| 6754 | len = __stop_ftrace_enum_maps - __start_ftrace_enum_maps; |
Steven Rostedt (Red Hat) | 9828413 | 2015-03-31 17:23:45 -0400 | [diff] [blame] | 6755 | trace_insert_enum_map(NULL, __start_ftrace_enum_maps, len); |
Steven Rostedt (Red Hat) | 0c564a5 | 2015-03-24 17:58:09 -0400 | [diff] [blame] | 6756 | } |
| 6757 | |
Steven Rostedt (Red Hat) | 3673b8e | 2015-03-25 15:44:21 -0400 | [diff] [blame] | 6758 | #ifdef CONFIG_MODULES |
| 6759 | static void trace_module_add_enums(struct module *mod) |
| 6760 | { |
| 6761 | if (!mod->num_trace_enums) |
| 6762 | return; |
| 6763 | |
| 6764 | /* |
| 6765 | * Modules with bad taint do not have events created, do |
| 6766 | * not bother with enums either. |
| 6767 | */ |
| 6768 | if (trace_module_has_bad_taint(mod)) |
| 6769 | return; |
| 6770 | |
Steven Rostedt (Red Hat) | 9828413 | 2015-03-31 17:23:45 -0400 | [diff] [blame] | 6771 | trace_insert_enum_map(mod, mod->trace_enums, mod->num_trace_enums); |
Steven Rostedt (Red Hat) | 3673b8e | 2015-03-25 15:44:21 -0400 | [diff] [blame] | 6772 | } |
| 6773 | |
Steven Rostedt (Red Hat) | 9828413 | 2015-03-31 17:23:45 -0400 | [diff] [blame] | 6774 | #ifdef CONFIG_TRACE_ENUM_MAP_FILE |
| 6775 | static void trace_module_remove_enums(struct module *mod) |
| 6776 | { |
| 6777 | union trace_enum_map_item *map; |
| 6778 | union trace_enum_map_item **last = &trace_enum_maps; |
| 6779 | |
| 6780 | if (!mod->num_trace_enums) |
| 6781 | return; |
| 6782 | |
| 6783 | mutex_lock(&trace_enum_mutex); |
| 6784 | |
| 6785 | map = trace_enum_maps; |
| 6786 | |
| 6787 | while (map) { |
| 6788 | if (map->head.mod == mod) |
| 6789 | break; |
| 6790 | map = trace_enum_jmp_to_tail(map); |
| 6791 | last = &map->tail.next; |
| 6792 | map = map->tail.next; |
| 6793 | } |
| 6794 | if (!map) |
| 6795 | goto out; |
| 6796 | |
| 6797 | *last = trace_enum_jmp_to_tail(map)->tail.next; |
| 6798 | kfree(map); |
| 6799 | out: |
| 6800 | mutex_unlock(&trace_enum_mutex); |
| 6801 | } |
| 6802 | #else |
| 6803 | static inline void trace_module_remove_enums(struct module *mod) { } |
| 6804 | #endif /* CONFIG_TRACE_ENUM_MAP_FILE */ |
| 6805 | |
Steven Rostedt (Red Hat) | 3673b8e | 2015-03-25 15:44:21 -0400 | [diff] [blame] | 6806 | static int trace_module_notify(struct notifier_block *self, |
| 6807 | unsigned long val, void *data) |
| 6808 | { |
| 6809 | struct module *mod = data; |
| 6810 | |
| 6811 | switch (val) { |
| 6812 | case MODULE_STATE_COMING: |
| 6813 | trace_module_add_enums(mod); |
| 6814 | break; |
Steven Rostedt (Red Hat) | 9828413 | 2015-03-31 17:23:45 -0400 | [diff] [blame] | 6815 | case MODULE_STATE_GOING: |
| 6816 | trace_module_remove_enums(mod); |
| 6817 | break; |
Steven Rostedt (Red Hat) | 3673b8e | 2015-03-25 15:44:21 -0400 | [diff] [blame] | 6818 | } |
| 6819 | |
| 6820 | return 0; |
| 6821 | } |
| 6822 | |
| 6823 | static struct notifier_block trace_module_nb = { |
| 6824 | .notifier_call = trace_module_notify, |
| 6825 | .priority = 0, |
| 6826 | }; |
Steven Rostedt (Red Hat) | 9828413 | 2015-03-31 17:23:45 -0400 | [diff] [blame] | 6827 | #endif /* CONFIG_MODULES */ |
Steven Rostedt (Red Hat) | 3673b8e | 2015-03-25 15:44:21 -0400 | [diff] [blame] | 6828 | |
Steven Rostedt (Red Hat) | 8434dc9 | 2015-01-20 12:13:40 -0500 | [diff] [blame] | 6829 | static __init int tracer_init_tracefs(void) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 6830 | { |
| 6831 | struct dentry *d_tracer; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 6832 | |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 6833 | trace_access_lock_init(); |
| 6834 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 6835 | d_tracer = tracing_init_dentry(); |
Steven Rostedt (Red Hat) | 14a5ae4 | 2015-01-20 11:14:16 -0500 | [diff] [blame] | 6836 | if (IS_ERR(d_tracer)) |
Namhyung Kim | ed6f1c9 | 2013-04-10 09:18:12 +0900 | [diff] [blame] | 6837 | return 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 6838 | |
Steven Rostedt (Red Hat) | 8434dc9 | 2015-01-20 12:13:40 -0500 | [diff] [blame] | 6839 | init_tracer_tracefs(&global_trace, d_tracer); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 6840 | |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 6841 | trace_create_file("tracing_thresh", 0644, d_tracer, |
Stanislav Fomichev | 6508fa7 | 2014-07-18 15:17:27 +0400 | [diff] [blame] | 6842 | &global_trace, &tracing_thresh_fops); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 6843 | |
Li Zefan | 339ae5d | 2009-04-17 10:34:30 +0800 | [diff] [blame] | 6844 | trace_create_file("README", 0444, d_tracer, |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 6845 | NULL, &tracing_readme_fops); |
Ingo Molnar | 7bd2f24 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 6846 | |
Avadh Patel | 69abe6a | 2009-04-10 16:04:48 -0400 | [diff] [blame] | 6847 | trace_create_file("saved_cmdlines", 0444, d_tracer, |
| 6848 | NULL, &tracing_saved_cmdlines_fops); |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 6849 | |
Yoshihiro YUNOMAE | 939c7a4 | 2014-06-05 10:24:27 +0900 | [diff] [blame] | 6850 | trace_create_file("saved_cmdlines_size", 0644, d_tracer, |
| 6851 | NULL, &tracing_saved_cmdlines_size_fops); |
| 6852 | |
Steven Rostedt (Red Hat) | 0c564a5 | 2015-03-24 17:58:09 -0400 | [diff] [blame] | 6853 | trace_enum_init(); |
| 6854 | |
Steven Rostedt (Red Hat) | 9828413 | 2015-03-31 17:23:45 -0400 | [diff] [blame] | 6855 | trace_create_enum_file(d_tracer); |
| 6856 | |
Steven Rostedt (Red Hat) | 3673b8e | 2015-03-25 15:44:21 -0400 | [diff] [blame] | 6857 | #ifdef CONFIG_MODULES |
| 6858 | register_module_notifier(&trace_module_nb); |
| 6859 | #endif |
| 6860 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 6861 | #ifdef CONFIG_DYNAMIC_FTRACE |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 6862 | trace_create_file("dyn_ftrace_total_info", 0444, d_tracer, |
| 6863 | &ftrace_update_tot_cnt, &tracing_dyn_info_fops); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 6864 | #endif |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 6865 | |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 6866 | create_trace_instances(d_tracer); |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 6867 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6868 | create_trace_options_dir(&global_trace); |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 6869 | |
Steven Rostedt (Red Hat) | 09d23a1 | 2015-02-03 12:45:53 -0500 | [diff] [blame] | 6870 | /* If the tracer was started via cmdline, create options for it here */ |
| 6871 | if (global_trace.current_trace != &nop_trace) |
| 6872 | update_tracer_options(&global_trace, global_trace.current_trace); |
| 6873 | |
Frédéric Weisbecker | b5ad384 | 2008-09-23 11:34:32 +0100 | [diff] [blame] | 6874 | return 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 6875 | } |
| 6876 | |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 6877 | static int trace_panic_handler(struct notifier_block *this, |
| 6878 | unsigned long event, void *unused) |
| 6879 | { |
Steven Rostedt | 944ac42 | 2008-10-23 19:26:08 -0400 | [diff] [blame] | 6880 | if (ftrace_dump_on_oops) |
Frederic Weisbecker | cecbca9 | 2010-04-18 19:08:41 +0200 | [diff] [blame] | 6881 | ftrace_dump(ftrace_dump_on_oops); |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 6882 | return NOTIFY_OK; |
| 6883 | } |
| 6884 | |
| 6885 | static struct notifier_block trace_panic_notifier = { |
| 6886 | .notifier_call = trace_panic_handler, |
| 6887 | .next = NULL, |
| 6888 | .priority = 150 /* priority: INT_MAX >= x >= 0 */ |
| 6889 | }; |
| 6890 | |
| 6891 | static int trace_die_handler(struct notifier_block *self, |
| 6892 | unsigned long val, |
| 6893 | void *data) |
| 6894 | { |
| 6895 | switch (val) { |
| 6896 | case DIE_OOPS: |
Steven Rostedt | 944ac42 | 2008-10-23 19:26:08 -0400 | [diff] [blame] | 6897 | if (ftrace_dump_on_oops) |
Frederic Weisbecker | cecbca9 | 2010-04-18 19:08:41 +0200 | [diff] [blame] | 6898 | ftrace_dump(ftrace_dump_on_oops); |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 6899 | break; |
| 6900 | default: |
| 6901 | break; |
| 6902 | } |
| 6903 | return NOTIFY_OK; |
| 6904 | } |
| 6905 | |
| 6906 | static struct notifier_block trace_die_notifier = { |
| 6907 | .notifier_call = trace_die_handler, |
| 6908 | .priority = 200 |
| 6909 | }; |
| 6910 | |
| 6911 | /* |
| 6912 | * printk is set to max of 1024, we really don't need it that big. |
| 6913 | * Nothing should be printing 1000 characters anyway. |
| 6914 | */ |
| 6915 | #define TRACE_MAX_PRINT 1000 |
| 6916 | |
| 6917 | /* |
| 6918 | * Define here KERN_TRACE so that we have one place to modify |
| 6919 | * it if we decide to change what log level the ftrace dump |
| 6920 | * should be at. |
| 6921 | */ |
Steven Rostedt | 428aee1 | 2009-01-14 12:24:42 -0500 | [diff] [blame] | 6922 | #define KERN_TRACE KERN_EMERG |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 6923 | |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 6924 | void |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 6925 | trace_printk_seq(struct trace_seq *s) |
| 6926 | { |
| 6927 | /* Probably should print a warning here. */ |
Steven Rostedt (Red Hat) | 3a161d9 | 2014-06-25 15:54:42 -0400 | [diff] [blame] | 6928 | if (s->seq.len >= TRACE_MAX_PRINT) |
| 6929 | s->seq.len = TRACE_MAX_PRINT; |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 6930 | |
Steven Rostedt (Red Hat) | 820b75f | 2014-11-19 10:56:41 -0500 | [diff] [blame] | 6931 | /* |
| 6932 | * More paranoid code. Although the buffer size is set to |
| 6933 | * PAGE_SIZE, and TRACE_MAX_PRINT is 1000, this is just |
| 6934 | * an extra layer of protection. |
| 6935 | */ |
| 6936 | if (WARN_ON_ONCE(s->seq.len >= s->seq.size)) |
| 6937 | s->seq.len = s->seq.size - 1; |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 6938 | |
| 6939 | /* should be zero ended, but we are paranoid. */ |
Steven Rostedt (Red Hat) | 3a161d9 | 2014-06-25 15:54:42 -0400 | [diff] [blame] | 6940 | s->buffer[s->seq.len] = 0; |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 6941 | |
| 6942 | printk(KERN_TRACE "%s", s->buffer); |
| 6943 | |
Steven Rostedt | f952075 | 2009-03-02 14:04:40 -0500 | [diff] [blame] | 6944 | trace_seq_init(s); |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 6945 | } |
| 6946 | |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 6947 | void trace_init_global_iter(struct trace_iterator *iter) |
| 6948 | { |
| 6949 | iter->tr = &global_trace; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6950 | iter->trace = iter->tr->current_trace; |
Steven Rostedt | ae3b509 | 2013-01-23 15:22:59 -0500 | [diff] [blame] | 6951 | iter->cpu_file = RING_BUFFER_ALL_CPUS; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 6952 | iter->trace_buffer = &global_trace.trace_buffer; |
Cody P Schafer | b2f974d | 2013-10-23 11:49:57 -0700 | [diff] [blame] | 6953 | |
| 6954 | if (iter->trace && iter->trace->open) |
| 6955 | iter->trace->open(iter); |
| 6956 | |
| 6957 | /* Annotate start of buffers if we had overruns */ |
| 6958 | if (ring_buffer_overruns(iter->trace_buffer->buffer)) |
| 6959 | iter->iter_flags |= TRACE_FILE_ANNOTATE; |
| 6960 | |
| 6961 | /* Output in nanoseconds only if we are using a clock in nanoseconds. */ |
| 6962 | if (trace_clocks[iter->tr->clock_id].in_ns) |
| 6963 | iter->iter_flags |= TRACE_FILE_TIME_IN_NS; |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 6964 | } |
| 6965 | |
Steven Rostedt (Red Hat) | 7fe70b5 | 2013-03-15 13:10:35 -0400 | [diff] [blame] | 6966 | void ftrace_dump(enum ftrace_dump_mode oops_dump_mode) |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 6967 | { |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 6968 | /* use static because iter can be a bit big for the stack */ |
| 6969 | static struct trace_iterator iter; |
Steven Rostedt (Red Hat) | 7fe70b5 | 2013-03-15 13:10:35 -0400 | [diff] [blame] | 6970 | static atomic_t dump_running; |
Frederic Weisbecker | cf586b6 | 2009-03-22 05:04:35 +0100 | [diff] [blame] | 6971 | unsigned int old_userobj; |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 6972 | unsigned long flags; |
| 6973 | int cnt = 0, cpu; |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 6974 | |
Steven Rostedt (Red Hat) | 7fe70b5 | 2013-03-15 13:10:35 -0400 | [diff] [blame] | 6975 | /* Only allow one dump user at a time. */ |
| 6976 | if (atomic_inc_return(&dump_running) != 1) { |
| 6977 | atomic_dec(&dump_running); |
| 6978 | return; |
Steven Rostedt | e0a413f | 2011-09-29 21:26:16 -0400 | [diff] [blame] | 6979 | } |
| 6980 | |
Steven Rostedt (Red Hat) | 7fe70b5 | 2013-03-15 13:10:35 -0400 | [diff] [blame] | 6981 | /* |
| 6982 | * Always turn off tracing when we dump. |
| 6983 | * We don't need to show trace output of what happens |
| 6984 | * between multiple crashes. |
| 6985 | * |
| 6986 | * If the user does a sysrq-z, then they can re-enable |
| 6987 | * tracing with echo 1 > tracing_on. |
| 6988 | */ |
| 6989 | tracing_off(); |
| 6990 | |
| 6991 | local_irq_save(flags); |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 6992 | |
Jovi Zhang | 38dbe0b | 2013-01-25 18:03:07 +0800 | [diff] [blame] | 6993 | /* Simulate the iterator */ |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 6994 | trace_init_global_iter(&iter); |
| 6995 | |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 6996 | for_each_tracing_cpu(cpu) { |
Umesh Tiwari | 5e2d5ef | 2015-06-22 16:55:06 +0530 | [diff] [blame] | 6997 | atomic_inc(&per_cpu_ptr(iter.trace_buffer->data, cpu)->disabled); |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 6998 | } |
| 6999 | |
Frederic Weisbecker | cf586b6 | 2009-03-22 05:04:35 +0100 | [diff] [blame] | 7000 | old_userobj = trace_flags & TRACE_ITER_SYM_USEROBJ; |
| 7001 | |
Török Edwin | b54d3de | 2008-11-22 13:28:48 +0200 | [diff] [blame] | 7002 | /* don't look at user memory in panic mode */ |
| 7003 | trace_flags &= ~TRACE_ITER_SYM_USEROBJ; |
| 7004 | |
Frederic Weisbecker | cecbca9 | 2010-04-18 19:08:41 +0200 | [diff] [blame] | 7005 | switch (oops_dump_mode) { |
| 7006 | case DUMP_ALL: |
Steven Rostedt | ae3b509 | 2013-01-23 15:22:59 -0500 | [diff] [blame] | 7007 | iter.cpu_file = RING_BUFFER_ALL_CPUS; |
Frederic Weisbecker | cecbca9 | 2010-04-18 19:08:41 +0200 | [diff] [blame] | 7008 | break; |
| 7009 | case DUMP_ORIG: |
| 7010 | iter.cpu_file = raw_smp_processor_id(); |
| 7011 | break; |
| 7012 | case DUMP_NONE: |
| 7013 | goto out_enable; |
| 7014 | default: |
| 7015 | printk(KERN_TRACE "Bad dumping mode, switching to all CPUs dump\n"); |
Steven Rostedt | ae3b509 | 2013-01-23 15:22:59 -0500 | [diff] [blame] | 7016 | iter.cpu_file = RING_BUFFER_ALL_CPUS; |
Frederic Weisbecker | cecbca9 | 2010-04-18 19:08:41 +0200 | [diff] [blame] | 7017 | } |
| 7018 | |
| 7019 | printk(KERN_TRACE "Dumping ftrace buffer:\n"); |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 7020 | |
Steven Rostedt (Red Hat) | 7fe70b5 | 2013-03-15 13:10:35 -0400 | [diff] [blame] | 7021 | /* Did function tracer already get disabled? */ |
| 7022 | if (ftrace_is_dead()) { |
| 7023 | printk("# WARNING: FUNCTION TRACING IS CORRUPTED\n"); |
| 7024 | printk("# MAY BE MISSING FUNCTION EVENTS\n"); |
| 7025 | } |
| 7026 | |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 7027 | /* |
| 7028 | * We need to stop all tracing on all CPUS to read the |
| 7029 | * the next buffer. This is a bit expensive, but is |
| 7030 | * not done often. We fill all what we can read, |
| 7031 | * and then release the locks again. |
| 7032 | */ |
| 7033 | |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 7034 | while (!trace_empty(&iter)) { |
| 7035 | |
| 7036 | if (!cnt) |
| 7037 | printk(KERN_TRACE "---------------------------------\n"); |
| 7038 | |
| 7039 | cnt++; |
| 7040 | |
| 7041 | /* reset all but tr, trace, and overruns */ |
| 7042 | memset(&iter.seq, 0, |
| 7043 | sizeof(struct trace_iterator) - |
| 7044 | offsetof(struct trace_iterator, seq)); |
| 7045 | iter.iter_flags |= TRACE_FILE_LAT_FMT; |
| 7046 | iter.pos = -1; |
| 7047 | |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 7048 | if (trace_find_next_entry_inc(&iter) != NULL) { |
Lai Jiangshan | 74e7ff8 | 2009-07-28 20:17:22 +0800 | [diff] [blame] | 7049 | int ret; |
| 7050 | |
| 7051 | ret = print_trace_line(&iter); |
| 7052 | if (ret != TRACE_TYPE_NO_CONSUME) |
| 7053 | trace_consume(&iter); |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 7054 | } |
Steven Rostedt | b892e5c | 2012-03-01 22:06:48 -0500 | [diff] [blame] | 7055 | touch_nmi_watchdog(); |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 7056 | |
| 7057 | trace_printk_seq(&iter.seq); |
| 7058 | } |
| 7059 | |
| 7060 | if (!cnt) |
| 7061 | printk(KERN_TRACE " (ftrace buffer empty)\n"); |
| 7062 | else |
| 7063 | printk(KERN_TRACE "---------------------------------\n"); |
| 7064 | |
Frederic Weisbecker | cecbca9 | 2010-04-18 19:08:41 +0200 | [diff] [blame] | 7065 | out_enable: |
Steven Rostedt (Red Hat) | 7fe70b5 | 2013-03-15 13:10:35 -0400 | [diff] [blame] | 7066 | trace_flags |= old_userobj; |
Frederic Weisbecker | cf586b6 | 2009-03-22 05:04:35 +0100 | [diff] [blame] | 7067 | |
Steven Rostedt (Red Hat) | 7fe70b5 | 2013-03-15 13:10:35 -0400 | [diff] [blame] | 7068 | for_each_tracing_cpu(cpu) { |
| 7069 | atomic_dec(&per_cpu_ptr(iter.trace_buffer->data, cpu)->disabled); |
Frederic Weisbecker | cf586b6 | 2009-03-22 05:04:35 +0100 | [diff] [blame] | 7070 | } |
Steven Rostedt (Red Hat) | 7fe70b5 | 2013-03-15 13:10:35 -0400 | [diff] [blame] | 7071 | atomic_dec(&dump_running); |
Steven Rostedt | cd891ae | 2009-04-28 11:39:34 -0400 | [diff] [blame] | 7072 | local_irq_restore(flags); |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 7073 | } |
Paul E. McKenney | a8eecf2 | 2011-10-02 11:01:15 -0700 | [diff] [blame] | 7074 | EXPORT_SYMBOL_GPL(ftrace_dump); |
Frederic Weisbecker | cf586b6 | 2009-03-22 05:04:35 +0100 | [diff] [blame] | 7075 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 7076 | __init static int tracer_alloc_buffers(void) |
| 7077 | { |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 7078 | int ring_buf_size; |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 7079 | int ret = -ENOMEM; |
| 7080 | |
| 7081 | if (!alloc_cpumask_var(&tracing_buffer_mask, GFP_KERNEL)) |
| 7082 | goto out; |
| 7083 | |
Alexander Z Lam | ccfe9e4 | 2013-08-08 09:47:45 -0700 | [diff] [blame] | 7084 | if (!alloc_cpumask_var(&global_trace.tracing_cpumask, GFP_KERNEL)) |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 7085 | goto out_free_buffer_mask; |
| 7086 | |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 7087 | /* Only allocate trace_printk buffers if a trace_printk exists */ |
| 7088 | if (__stop___trace_bprintk_fmt != __start___trace_bprintk_fmt) |
Steven Rostedt | 8169883 | 2012-10-11 10:15:05 -0400 | [diff] [blame] | 7089 | /* Must be called before global_trace.buffer is allocated */ |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 7090 | trace_printk_init_buffers(); |
| 7091 | |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 7092 | /* To save memory, keep the ring buffer size to its minimum */ |
| 7093 | if (ring_buffer_expanded) |
| 7094 | ring_buf_size = trace_buf_size; |
| 7095 | else |
| 7096 | ring_buf_size = 1; |
| 7097 | |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 7098 | cpumask_copy(tracing_buffer_mask, cpu_possible_mask); |
Alexander Z Lam | ccfe9e4 | 2013-08-08 09:47:45 -0700 | [diff] [blame] | 7099 | cpumask_copy(global_trace.tracing_cpumask, cpu_all_mask); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 7100 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 7101 | raw_spin_lock_init(&global_trace.start_lock); |
| 7102 | |
Steven Rostedt (Red Hat) | 2c4a33a | 2014-03-25 23:39:41 -0400 | [diff] [blame] | 7103 | /* Used for event triggers */ |
| 7104 | temp_buffer = ring_buffer_alloc(PAGE_SIZE, RB_FL_OVERWRITE); |
| 7105 | if (!temp_buffer) |
| 7106 | goto out_free_cpumask; |
| 7107 | |
Yoshihiro YUNOMAE | 939c7a4 | 2014-06-05 10:24:27 +0900 | [diff] [blame] | 7108 | if (trace_create_savedcmd() < 0) |
| 7109 | goto out_free_temp_buffer; |
| 7110 | |
Steven Rostedt | ab46428 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 7111 | /* TODO: make the number of buffers hot pluggable with CPUS */ |
Steven Rostedt (Red Hat) | 737223f | 2013-03-05 21:13:47 -0500 | [diff] [blame] | 7112 | if (allocate_trace_buffers(&global_trace, ring_buf_size) < 0) { |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 7113 | printk(KERN_ERR "tracer: failed to allocate ring buffer!\n"); |
| 7114 | WARN_ON(1); |
Yoshihiro YUNOMAE | 939c7a4 | 2014-06-05 10:24:27 +0900 | [diff] [blame] | 7115 | goto out_free_savedcmd; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 7116 | } |
Steven Rostedt | a7603ff | 2012-08-06 16:24:11 -0400 | [diff] [blame] | 7117 | |
Steven Rostedt | 499e547 | 2012-02-22 15:50:28 -0500 | [diff] [blame] | 7118 | if (global_trace.buffer_disabled) |
| 7119 | tracing_off(); |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 7120 | |
Steven Rostedt | e1e232c | 2014-02-10 23:38:46 -0500 | [diff] [blame] | 7121 | if (trace_boot_clock) { |
| 7122 | ret = tracing_set_clock(&global_trace, trace_boot_clock); |
| 7123 | if (ret < 0) |
| 7124 | pr_warning("Trace clock %s not defined, going back to default\n", |
| 7125 | trace_boot_clock); |
| 7126 | } |
| 7127 | |
Steven Rostedt (Red Hat) | ca16431 | 2013-05-23 11:51:10 -0400 | [diff] [blame] | 7128 | /* |
| 7129 | * register_tracer() might reference current_trace, so it |
| 7130 | * needs to be set before we register anything. This is |
| 7131 | * just a bootstrap of current_trace anyway. |
| 7132 | */ |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 7133 | global_trace.current_trace = &nop_trace; |
| 7134 | |
Steven Rostedt (Red Hat) | 0b9b12c | 2014-01-14 10:04:59 -0500 | [diff] [blame] | 7135 | global_trace.max_lock = (arch_spinlock_t)__ARCH_SPIN_LOCK_UNLOCKED; |
| 7136 | |
Steven Rostedt (Red Hat) | 4104d32 | 2014-01-10 17:01:58 -0500 | [diff] [blame] | 7137 | ftrace_init_global_array_ops(&global_trace); |
| 7138 | |
Steven Rostedt (Red Hat) | ca16431 | 2013-05-23 11:51:10 -0400 | [diff] [blame] | 7139 | register_tracer(&nop_trace); |
| 7140 | |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 7141 | /* All seems OK, enable tracing */ |
| 7142 | tracing_disabled = 0; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 7143 | |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 7144 | atomic_notifier_chain_register(&panic_notifier_list, |
| 7145 | &trace_panic_notifier); |
| 7146 | |
| 7147 | register_die_notifier(&trace_die_notifier); |
Frederic Weisbecker | 2fc1dfb | 2009-03-16 01:45:03 +0100 | [diff] [blame] | 7148 | |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 7149 | global_trace.flags = TRACE_ARRAY_FL_GLOBAL; |
| 7150 | |
| 7151 | INIT_LIST_HEAD(&global_trace.systems); |
| 7152 | INIT_LIST_HEAD(&global_trace.events); |
| 7153 | list_add(&global_trace.list, &ftrace_trace_arrays); |
| 7154 | |
Steven Rostedt | 7bcfaf5 | 2012-11-01 22:56:07 -0400 | [diff] [blame] | 7155 | while (trace_boot_options) { |
| 7156 | char *option; |
| 7157 | |
| 7158 | option = strsep(&trace_boot_options, ","); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 7159 | trace_set_options(&global_trace, option); |
Steven Rostedt | 7bcfaf5 | 2012-11-01 22:56:07 -0400 | [diff] [blame] | 7160 | } |
| 7161 | |
Steven Rostedt (Red Hat) | 77fd5c1 | 2013-03-12 11:49:18 -0400 | [diff] [blame] | 7162 | register_snapshot_cmd(); |
| 7163 | |
Frederic Weisbecker | 2fc1dfb | 2009-03-16 01:45:03 +0100 | [diff] [blame] | 7164 | return 0; |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 7165 | |
Yoshihiro YUNOMAE | 939c7a4 | 2014-06-05 10:24:27 +0900 | [diff] [blame] | 7166 | out_free_savedcmd: |
| 7167 | free_saved_cmdlines_buffer(savedcmd); |
Steven Rostedt (Red Hat) | 2c4a33a | 2014-03-25 23:39:41 -0400 | [diff] [blame] | 7168 | out_free_temp_buffer: |
| 7169 | ring_buffer_free(temp_buffer); |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 7170 | out_free_cpumask: |
Alexander Z Lam | ccfe9e4 | 2013-08-08 09:47:45 -0700 | [diff] [blame] | 7171 | free_cpumask_var(global_trace.tracing_cpumask); |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 7172 | out_free_buffer_mask: |
| 7173 | free_cpumask_var(tracing_buffer_mask); |
| 7174 | out: |
| 7175 | return ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 7176 | } |
Steven Rostedt | b2821ae | 2009-02-02 21:38:32 -0500 | [diff] [blame] | 7177 | |
Steven Rostedt (Red Hat) | 5f893b2 | 2014-12-12 20:05:10 -0500 | [diff] [blame] | 7178 | void __init trace_init(void) |
| 7179 | { |
Steven Rostedt (Red Hat) | 0daa2302 | 2014-12-12 22:27:10 -0500 | [diff] [blame] | 7180 | if (tracepoint_printk) { |
| 7181 | tracepoint_print_iter = |
| 7182 | kmalloc(sizeof(*tracepoint_print_iter), GFP_KERNEL); |
| 7183 | if (WARN_ON(!tracepoint_print_iter)) |
| 7184 | tracepoint_printk = 0; |
| 7185 | } |
Steven Rostedt (Red Hat) | 5f893b2 | 2014-12-12 20:05:10 -0500 | [diff] [blame] | 7186 | tracer_alloc_buffers(); |
Steven Rostedt (Red Hat) | 0c564a5 | 2015-03-24 17:58:09 -0400 | [diff] [blame] | 7187 | trace_event_init(); |
Steven Rostedt (Red Hat) | 5f893b2 | 2014-12-12 20:05:10 -0500 | [diff] [blame] | 7188 | } |
| 7189 | |
Steven Rostedt | b2821ae | 2009-02-02 21:38:32 -0500 | [diff] [blame] | 7190 | __init static int clear_boot_tracer(void) |
| 7191 | { |
| 7192 | /* |
| 7193 | * The default tracer at boot buffer is an init section. |
| 7194 | * This function is called in lateinit. If we did not |
| 7195 | * find the boot tracer, then clear it out, to prevent |
| 7196 | * later registration from accessing the buffer that is |
| 7197 | * about to be freed. |
| 7198 | */ |
| 7199 | if (!default_bootup_tracer) |
| 7200 | return 0; |
| 7201 | |
| 7202 | printk(KERN_INFO "ftrace bootup tracer '%s' not registered.\n", |
| 7203 | default_bootup_tracer); |
| 7204 | default_bootup_tracer = NULL; |
| 7205 | |
| 7206 | return 0; |
| 7207 | } |
| 7208 | |
Steven Rostedt (Red Hat) | 8434dc9 | 2015-01-20 12:13:40 -0500 | [diff] [blame] | 7209 | fs_initcall(tracer_init_tracefs); |
Steven Rostedt | b2821ae | 2009-02-02 21:38:32 -0500 | [diff] [blame] | 7210 | late_initcall(clear_boot_tracer); |