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 (Red Hat) | 983f938 | 2015-09-30 09:42:05 -0400 | [diff] [blame] | 253 | /* trace_flags holds trace_options default values */ |
| 254 | #define TRACE_DEFAULT_FLAGS \ |
| 255 | (FUNCTION_DEFAULT_FLAGS | \ |
| 256 | TRACE_ITER_PRINT_PARENT | TRACE_ITER_PRINTK | \ |
| 257 | TRACE_ITER_ANNOTATE | TRACE_ITER_CONTEXT_INFO | \ |
| 258 | TRACE_ITER_RECORD_CMD | TRACE_ITER_OVERWRITE | \ |
| 259 | TRACE_ITER_IRQ_INFO | TRACE_ITER_MARKERS) |
| 260 | |
Steven Rostedt (Red Hat) | 1627014 | 2015-09-30 12:30:06 -0400 | [diff] [blame] | 261 | /* trace_options that are only supported by global_trace */ |
| 262 | #define TOP_LEVEL_TRACE_FLAGS (TRACE_ITER_PRINTK | \ |
| 263 | TRACE_ITER_PRINTK_MSGONLY | TRACE_ITER_RECORD_CMD) |
| 264 | |
| 265 | |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 266 | /* |
| 267 | * The global_trace is the descriptor that holds the tracing |
| 268 | * buffers for the live tracing. For each CPU, it contains |
| 269 | * a link list of pages that will store trace entries. The |
| 270 | * page descriptor of the pages in the memory is used to hold |
| 271 | * the link list by linking the lru item in the page descriptor |
| 272 | * to each of the pages in the buffer per CPU. |
| 273 | * |
| 274 | * For each active CPU there is a data field that holds the |
| 275 | * pages for the buffer for that CPU. Each CPU has the same number |
| 276 | * of pages allocated for its buffer. |
| 277 | */ |
Steven Rostedt (Red Hat) | 983f938 | 2015-09-30 09:42:05 -0400 | [diff] [blame] | 278 | static struct trace_array global_trace = { |
| 279 | .trace_flags = TRACE_DEFAULT_FLAGS, |
| 280 | }; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 281 | |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 282 | LIST_HEAD(ftrace_trace_arrays); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 283 | |
Steven Rostedt (Red Hat) | ff45196 | 2013-07-01 22:50:29 -0400 | [diff] [blame] | 284 | int trace_array_get(struct trace_array *this_tr) |
| 285 | { |
| 286 | struct trace_array *tr; |
| 287 | int ret = -ENODEV; |
| 288 | |
| 289 | mutex_lock(&trace_types_lock); |
| 290 | list_for_each_entry(tr, &ftrace_trace_arrays, list) { |
| 291 | if (tr == this_tr) { |
| 292 | tr->ref++; |
| 293 | ret = 0; |
| 294 | break; |
| 295 | } |
| 296 | } |
| 297 | mutex_unlock(&trace_types_lock); |
| 298 | |
| 299 | return ret; |
| 300 | } |
| 301 | |
| 302 | static void __trace_array_put(struct trace_array *this_tr) |
| 303 | { |
| 304 | WARN_ON(!this_tr->ref); |
| 305 | this_tr->ref--; |
| 306 | } |
| 307 | |
| 308 | void trace_array_put(struct trace_array *this_tr) |
| 309 | { |
| 310 | mutex_lock(&trace_types_lock); |
| 311 | __trace_array_put(this_tr); |
| 312 | mutex_unlock(&trace_types_lock); |
| 313 | } |
| 314 | |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 315 | int filter_check_discard(struct trace_event_file *file, void *rec, |
Tom Zanussi | f306cc8 | 2013-10-24 08:34:17 -0500 | [diff] [blame] | 316 | struct ring_buffer *buffer, |
| 317 | struct ring_buffer_event *event) |
Tom Zanussi | eb02ce0 | 2009-04-08 03:15:54 -0500 | [diff] [blame] | 318 | { |
Steven Rostedt (Red Hat) | 5d6ad96 | 2015-05-13 15:12:33 -0400 | [diff] [blame] | 319 | if (unlikely(file->flags & EVENT_FILE_FL_FILTERED) && |
Tom Zanussi | f306cc8 | 2013-10-24 08:34:17 -0500 | [diff] [blame] | 320 | !filter_match_preds(file->filter, rec)) { |
| 321 | ring_buffer_discard_commit(buffer, event); |
| 322 | return 1; |
| 323 | } |
| 324 | |
| 325 | return 0; |
Tom Zanussi | eb02ce0 | 2009-04-08 03:15:54 -0500 | [diff] [blame] | 326 | } |
Tom Zanussi | f306cc8 | 2013-10-24 08:34:17 -0500 | [diff] [blame] | 327 | EXPORT_SYMBOL_GPL(filter_check_discard); |
| 328 | |
Steven Rostedt (Red Hat) | 2425bcb | 2015-05-05 11:45:27 -0400 | [diff] [blame] | 329 | int call_filter_check_discard(struct trace_event_call *call, void *rec, |
Tom Zanussi | f306cc8 | 2013-10-24 08:34:17 -0500 | [diff] [blame] | 330 | struct ring_buffer *buffer, |
| 331 | struct ring_buffer_event *event) |
| 332 | { |
| 333 | if (unlikely(call->flags & TRACE_EVENT_FL_FILTERED) && |
| 334 | !filter_match_preds(call->filter, rec)) { |
| 335 | ring_buffer_discard_commit(buffer, event); |
| 336 | return 1; |
| 337 | } |
| 338 | |
| 339 | return 0; |
| 340 | } |
| 341 | EXPORT_SYMBOL_GPL(call_filter_check_discard); |
Tom Zanussi | eb02ce0 | 2009-04-08 03:15:54 -0500 | [diff] [blame] | 342 | |
Fabian Frederick | ad1438a | 2014-04-17 21:44:42 +0200 | [diff] [blame] | 343 | static cycle_t buffer_ftrace_now(struct trace_buffer *buf, int cpu) |
Steven Rostedt | 37886f6 | 2009-03-17 17:22:06 -0400 | [diff] [blame] | 344 | { |
| 345 | u64 ts; |
| 346 | |
| 347 | /* Early boot up does not have a buffer yet */ |
Alexander Z Lam | 9457158 | 2013-08-02 18:36:16 -0700 | [diff] [blame] | 348 | if (!buf->buffer) |
Steven Rostedt | 37886f6 | 2009-03-17 17:22:06 -0400 | [diff] [blame] | 349 | return trace_clock_local(); |
| 350 | |
Alexander Z Lam | 9457158 | 2013-08-02 18:36:16 -0700 | [diff] [blame] | 351 | ts = ring_buffer_time_stamp(buf->buffer, cpu); |
| 352 | ring_buffer_normalize_time_stamp(buf->buffer, cpu, &ts); |
Steven Rostedt | 37886f6 | 2009-03-17 17:22:06 -0400 | [diff] [blame] | 353 | |
| 354 | return ts; |
| 355 | } |
| 356 | |
Alexander Z Lam | 9457158 | 2013-08-02 18:36:16 -0700 | [diff] [blame] | 357 | cycle_t ftrace_now(int cpu) |
| 358 | { |
| 359 | return buffer_ftrace_now(&global_trace.trace_buffer, cpu); |
| 360 | } |
| 361 | |
Steven Rostedt (Red Hat) | 10246fa | 2013-07-01 15:58:24 -0400 | [diff] [blame] | 362 | /** |
| 363 | * tracing_is_enabled - Show if global_trace has been disabled |
| 364 | * |
| 365 | * Shows if the global trace has been enabled or not. It uses the |
| 366 | * mirror flag "buffer_disabled" to be used in fast paths such as for |
| 367 | * the irqsoff tracer. But it may be inaccurate due to races. If you |
| 368 | * need to know the accurate state, use tracing_is_on() which is a little |
| 369 | * slower, but accurate. |
| 370 | */ |
Steven Rostedt | 9036990 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 371 | int tracing_is_enabled(void) |
| 372 | { |
Steven Rostedt (Red Hat) | 10246fa | 2013-07-01 15:58:24 -0400 | [diff] [blame] | 373 | /* |
| 374 | * For quick access (irqsoff uses this in fast path), just |
| 375 | * return the mirror variable of the state of the ring buffer. |
| 376 | * It's a little racy, but we don't really care. |
| 377 | */ |
| 378 | smp_rmb(); |
| 379 | return !global_trace.buffer_disabled; |
Steven Rostedt | 9036990 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 380 | } |
| 381 | |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 382 | /* |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 383 | * trace_buf_size is the size in bytes that is allocated |
| 384 | * for a buffer. Note, the number of bytes is always rounded |
| 385 | * to page size. |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 386 | * |
| 387 | * This number is purposely set to a low number of 16384. |
| 388 | * If the dump on oops happens, it will be much appreciated |
| 389 | * to not have to wait for all that output. Anyway this can be |
| 390 | * boot time and run time configurable. |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 391 | */ |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 392 | #define TRACE_BUF_SIZE_DEFAULT 1441792UL /* 16384 * 88 (sizeof(entry)) */ |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 393 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 394 | static unsigned long trace_buf_size = TRACE_BUF_SIZE_DEFAULT; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 395 | |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 396 | /* trace_types holds a link list of available tracers. */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 397 | static struct tracer *trace_types __read_mostly; |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 398 | |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 399 | /* |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 400 | * trace_types_lock is used to protect the trace_types list. |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 401 | */ |
Alexander Z Lam | a822741 | 2013-07-01 19:37:54 -0700 | [diff] [blame] | 402 | DEFINE_MUTEX(trace_types_lock); |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 403 | |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 404 | /* |
| 405 | * serialize the access of the ring buffer |
| 406 | * |
| 407 | * ring buffer serializes readers, but it is low level protection. |
| 408 | * The validity of the events (which returns by ring_buffer_peek() ..etc) |
| 409 | * are not protected by ring buffer. |
| 410 | * |
| 411 | * The content of events may become garbage if we allow other process consumes |
| 412 | * these events concurrently: |
| 413 | * A) the page of the consumed events may become a normal page |
| 414 | * (not reader page) in ring buffer, and this page will be rewrited |
| 415 | * by events producer. |
| 416 | * B) The page of the consumed events may become a page for splice_read, |
| 417 | * and this page will be returned to system. |
| 418 | * |
| 419 | * These primitives allow multi process access to different cpu ring buffer |
| 420 | * concurrently. |
| 421 | * |
| 422 | * These primitives don't distinguish read-only and read-consume access. |
| 423 | * Multi read-only access are also serialized. |
| 424 | */ |
| 425 | |
| 426 | #ifdef CONFIG_SMP |
| 427 | static DECLARE_RWSEM(all_cpu_access_lock); |
| 428 | static DEFINE_PER_CPU(struct mutex, cpu_access_lock); |
| 429 | |
| 430 | static inline void trace_access_lock(int cpu) |
| 431 | { |
Steven Rostedt | ae3b509 | 2013-01-23 15:22:59 -0500 | [diff] [blame] | 432 | if (cpu == RING_BUFFER_ALL_CPUS) { |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 433 | /* gain it for accessing the whole ring buffer. */ |
| 434 | down_write(&all_cpu_access_lock); |
| 435 | } else { |
| 436 | /* gain it for accessing a cpu ring buffer. */ |
| 437 | |
Steven Rostedt | ae3b509 | 2013-01-23 15:22:59 -0500 | [diff] [blame] | 438 | /* Firstly block other trace_access_lock(RING_BUFFER_ALL_CPUS). */ |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 439 | down_read(&all_cpu_access_lock); |
| 440 | |
| 441 | /* Secondly block other access to this @cpu ring buffer. */ |
| 442 | mutex_lock(&per_cpu(cpu_access_lock, cpu)); |
| 443 | } |
| 444 | } |
| 445 | |
| 446 | static inline void trace_access_unlock(int cpu) |
| 447 | { |
Steven Rostedt | ae3b509 | 2013-01-23 15:22:59 -0500 | [diff] [blame] | 448 | if (cpu == RING_BUFFER_ALL_CPUS) { |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 449 | up_write(&all_cpu_access_lock); |
| 450 | } else { |
| 451 | mutex_unlock(&per_cpu(cpu_access_lock, cpu)); |
| 452 | up_read(&all_cpu_access_lock); |
| 453 | } |
| 454 | } |
| 455 | |
| 456 | static inline void trace_access_lock_init(void) |
| 457 | { |
| 458 | int cpu; |
| 459 | |
| 460 | for_each_possible_cpu(cpu) |
| 461 | mutex_init(&per_cpu(cpu_access_lock, cpu)); |
| 462 | } |
| 463 | |
| 464 | #else |
| 465 | |
| 466 | static DEFINE_MUTEX(access_lock); |
| 467 | |
| 468 | static inline void trace_access_lock(int cpu) |
| 469 | { |
| 470 | (void)cpu; |
| 471 | mutex_lock(&access_lock); |
| 472 | } |
| 473 | |
| 474 | static inline void trace_access_unlock(int cpu) |
| 475 | { |
| 476 | (void)cpu; |
| 477 | mutex_unlock(&access_lock); |
| 478 | } |
| 479 | |
| 480 | static inline void trace_access_lock_init(void) |
| 481 | { |
| 482 | } |
| 483 | |
| 484 | #endif |
| 485 | |
Steven Rostedt (Red Hat) | d78a461 | 2015-09-25 13:30:47 -0400 | [diff] [blame] | 486 | #ifdef CONFIG_STACKTRACE |
| 487 | static void __ftrace_trace_stack(struct ring_buffer *buffer, |
| 488 | unsigned long flags, |
| 489 | int skip, int pc, struct pt_regs *regs); |
Steven Rostedt (Red Hat) | 2d34f48 | 2015-09-30 11:45:22 -0400 | [diff] [blame] | 490 | static inline void ftrace_trace_stack(struct trace_array *tr, |
| 491 | struct ring_buffer *buffer, |
Steven Rostedt (Red Hat) | 73dddbb | 2015-09-29 15:38:55 -0400 | [diff] [blame] | 492 | unsigned long flags, |
| 493 | int skip, int pc, struct pt_regs *regs); |
Steven Rostedt (Red Hat) | ca475e8 | 2015-09-28 09:41:11 -0400 | [diff] [blame] | 494 | |
Steven Rostedt (Red Hat) | d78a461 | 2015-09-25 13:30:47 -0400 | [diff] [blame] | 495 | #else |
| 496 | static inline void __ftrace_trace_stack(struct ring_buffer *buffer, |
| 497 | unsigned long flags, |
| 498 | int skip, int pc, struct pt_regs *regs) |
| 499 | { |
| 500 | } |
Steven Rostedt (Red Hat) | 2d34f48 | 2015-09-30 11:45:22 -0400 | [diff] [blame] | 501 | static inline void ftrace_trace_stack(struct trace_array *tr, |
| 502 | struct ring_buffer *buffer, |
Steven Rostedt (Red Hat) | 73dddbb | 2015-09-29 15:38:55 -0400 | [diff] [blame] | 503 | unsigned long flags, |
| 504 | int skip, int pc, struct pt_regs *regs) |
Steven Rostedt (Red Hat) | ca475e8 | 2015-09-28 09:41:11 -0400 | [diff] [blame] | 505 | { |
| 506 | } |
| 507 | |
Steven Rostedt (Red Hat) | d78a461 | 2015-09-25 13:30:47 -0400 | [diff] [blame] | 508 | #endif |
| 509 | |
Steven Rostedt (Red Hat) | 5280bce | 2013-07-02 19:59:57 -0400 | [diff] [blame] | 510 | static void tracer_tracing_on(struct trace_array *tr) |
Steven Rostedt (Red Hat) | 10246fa | 2013-07-01 15:58:24 -0400 | [diff] [blame] | 511 | { |
| 512 | if (tr->trace_buffer.buffer) |
| 513 | ring_buffer_record_on(tr->trace_buffer.buffer); |
| 514 | /* |
| 515 | * This flag is looked at when buffers haven't been allocated |
| 516 | * yet, or by some tracers (like irqsoff), that just want to |
| 517 | * know if the ring buffer has been disabled, but it can handle |
| 518 | * races of where it gets disabled but we still do a record. |
| 519 | * As the check is in the fast path of the tracers, it is more |
| 520 | * important to be fast than accurate. |
| 521 | */ |
| 522 | tr->buffer_disabled = 0; |
| 523 | /* Make the flag seen by readers */ |
| 524 | smp_wmb(); |
| 525 | } |
| 526 | |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 527 | /** |
Steven Rostedt | 499e547 | 2012-02-22 15:50:28 -0500 | [diff] [blame] | 528 | * tracing_on - enable tracing buffers |
| 529 | * |
| 530 | * This function enables tracing buffers that may have been |
| 531 | * disabled with tracing_off. |
| 532 | */ |
| 533 | void tracing_on(void) |
| 534 | { |
Steven Rostedt (Red Hat) | 10246fa | 2013-07-01 15:58:24 -0400 | [diff] [blame] | 535 | tracer_tracing_on(&global_trace); |
Steven Rostedt | 499e547 | 2012-02-22 15:50:28 -0500 | [diff] [blame] | 536 | } |
| 537 | EXPORT_SYMBOL_GPL(tracing_on); |
| 538 | |
| 539 | /** |
Steven Rostedt (Red Hat) | 09ae723 | 2013-03-08 21:02:34 -0500 | [diff] [blame] | 540 | * __trace_puts - write a constant string into the trace buffer. |
| 541 | * @ip: The address of the caller |
| 542 | * @str: The constant string to write |
| 543 | * @size: The size of the string. |
| 544 | */ |
| 545 | int __trace_puts(unsigned long ip, const char *str, int size) |
| 546 | { |
| 547 | struct ring_buffer_event *event; |
| 548 | struct ring_buffer *buffer; |
| 549 | struct print_entry *entry; |
| 550 | unsigned long irq_flags; |
| 551 | int alloc; |
zhangwei(Jovi) | 8abfb87 | 2013-07-18 16:31:05 +0800 | [diff] [blame] | 552 | int pc; |
| 553 | |
Steven Rostedt (Red Hat) | 983f938 | 2015-09-30 09:42:05 -0400 | [diff] [blame] | 554 | if (!(global_trace.trace_flags & TRACE_ITER_PRINTK)) |
zhangwei(Jovi) | f0160a5 | 2013-07-18 16:31:18 +0800 | [diff] [blame] | 555 | return 0; |
| 556 | |
zhangwei(Jovi) | 8abfb87 | 2013-07-18 16:31:05 +0800 | [diff] [blame] | 557 | pc = preempt_count(); |
Steven Rostedt (Red Hat) | 09ae723 | 2013-03-08 21:02:34 -0500 | [diff] [blame] | 558 | |
Steven Rostedt (Red Hat) | 3132e10 | 2014-01-23 12:27:59 -0500 | [diff] [blame] | 559 | if (unlikely(tracing_selftest_running || tracing_disabled)) |
| 560 | return 0; |
| 561 | |
Steven Rostedt (Red Hat) | 09ae723 | 2013-03-08 21:02:34 -0500 | [diff] [blame] | 562 | alloc = sizeof(*entry) + size + 2; /* possible \n added */ |
| 563 | |
| 564 | local_save_flags(irq_flags); |
| 565 | buffer = global_trace.trace_buffer.buffer; |
| 566 | event = trace_buffer_lock_reserve(buffer, TRACE_PRINT, alloc, |
zhangwei(Jovi) | 8abfb87 | 2013-07-18 16:31:05 +0800 | [diff] [blame] | 567 | irq_flags, pc); |
Steven Rostedt (Red Hat) | 09ae723 | 2013-03-08 21:02:34 -0500 | [diff] [blame] | 568 | if (!event) |
| 569 | return 0; |
| 570 | |
| 571 | entry = ring_buffer_event_data(event); |
| 572 | entry->ip = ip; |
| 573 | |
| 574 | memcpy(&entry->buf, str, size); |
| 575 | |
| 576 | /* Add a newline if necessary */ |
| 577 | if (entry->buf[size - 1] != '\n') { |
| 578 | entry->buf[size] = '\n'; |
| 579 | entry->buf[size + 1] = '\0'; |
| 580 | } else |
| 581 | entry->buf[size] = '\0'; |
| 582 | |
| 583 | __buffer_unlock_commit(buffer, event); |
Steven Rostedt (Red Hat) | 2d34f48 | 2015-09-30 11:45:22 -0400 | [diff] [blame] | 584 | ftrace_trace_stack(&global_trace, buffer, irq_flags, 4, pc, NULL); |
Steven Rostedt (Red Hat) | 09ae723 | 2013-03-08 21:02:34 -0500 | [diff] [blame] | 585 | |
| 586 | return size; |
| 587 | } |
| 588 | EXPORT_SYMBOL_GPL(__trace_puts); |
| 589 | |
| 590 | /** |
| 591 | * __trace_bputs - write the pointer to a constant string into trace buffer |
| 592 | * @ip: The address of the caller |
| 593 | * @str: The constant string to write to the buffer to |
| 594 | */ |
| 595 | int __trace_bputs(unsigned long ip, const char *str) |
| 596 | { |
| 597 | struct ring_buffer_event *event; |
| 598 | struct ring_buffer *buffer; |
| 599 | struct bputs_entry *entry; |
| 600 | unsigned long irq_flags; |
| 601 | int size = sizeof(struct bputs_entry); |
zhangwei(Jovi) | 8abfb87 | 2013-07-18 16:31:05 +0800 | [diff] [blame] | 602 | int pc; |
| 603 | |
Steven Rostedt (Red Hat) | 983f938 | 2015-09-30 09:42:05 -0400 | [diff] [blame] | 604 | if (!(global_trace.trace_flags & TRACE_ITER_PRINTK)) |
zhangwei(Jovi) | f0160a5 | 2013-07-18 16:31:18 +0800 | [diff] [blame] | 605 | return 0; |
| 606 | |
zhangwei(Jovi) | 8abfb87 | 2013-07-18 16:31:05 +0800 | [diff] [blame] | 607 | pc = preempt_count(); |
Steven Rostedt (Red Hat) | 09ae723 | 2013-03-08 21:02:34 -0500 | [diff] [blame] | 608 | |
Steven Rostedt (Red Hat) | 3132e10 | 2014-01-23 12:27:59 -0500 | [diff] [blame] | 609 | if (unlikely(tracing_selftest_running || tracing_disabled)) |
| 610 | return 0; |
| 611 | |
Steven Rostedt (Red Hat) | 09ae723 | 2013-03-08 21:02:34 -0500 | [diff] [blame] | 612 | local_save_flags(irq_flags); |
| 613 | buffer = global_trace.trace_buffer.buffer; |
| 614 | event = trace_buffer_lock_reserve(buffer, TRACE_BPUTS, size, |
zhangwei(Jovi) | 8abfb87 | 2013-07-18 16:31:05 +0800 | [diff] [blame] | 615 | irq_flags, pc); |
Steven Rostedt (Red Hat) | 09ae723 | 2013-03-08 21:02:34 -0500 | [diff] [blame] | 616 | if (!event) |
| 617 | return 0; |
| 618 | |
| 619 | entry = ring_buffer_event_data(event); |
| 620 | entry->ip = ip; |
| 621 | entry->str = str; |
| 622 | |
| 623 | __buffer_unlock_commit(buffer, event); |
Steven Rostedt (Red Hat) | 2d34f48 | 2015-09-30 11:45:22 -0400 | [diff] [blame] | 624 | ftrace_trace_stack(&global_trace, buffer, irq_flags, 4, pc, NULL); |
Steven Rostedt (Red Hat) | 09ae723 | 2013-03-08 21:02:34 -0500 | [diff] [blame] | 625 | |
| 626 | return 1; |
| 627 | } |
| 628 | EXPORT_SYMBOL_GPL(__trace_bputs); |
| 629 | |
Steven Rostedt (Red Hat) | ad909e2 | 2013-03-06 21:45:37 -0500 | [diff] [blame] | 630 | #ifdef CONFIG_TRACER_SNAPSHOT |
| 631 | /** |
| 632 | * trace_snapshot - take a snapshot of the current buffer. |
| 633 | * |
| 634 | * This causes a swap between the snapshot buffer and the current live |
| 635 | * tracing buffer. You can use this to take snapshots of the live |
| 636 | * trace when some condition is triggered, but continue to trace. |
| 637 | * |
| 638 | * Note, make sure to allocate the snapshot with either |
| 639 | * a tracing_snapshot_alloc(), or by doing it manually |
| 640 | * with: echo 1 > /sys/kernel/debug/tracing/snapshot |
| 641 | * |
| 642 | * If the snapshot buffer is not allocated, it will stop tracing. |
| 643 | * Basically making a permanent snapshot. |
| 644 | */ |
| 645 | void tracing_snapshot(void) |
| 646 | { |
| 647 | struct trace_array *tr = &global_trace; |
| 648 | struct tracer *tracer = tr->current_trace; |
| 649 | unsigned long flags; |
| 650 | |
Steven Rostedt (Red Hat) | 1b22e38 | 2013-03-09 00:56:08 -0500 | [diff] [blame] | 651 | if (in_nmi()) { |
| 652 | internal_trace_puts("*** SNAPSHOT CALLED FROM NMI CONTEXT ***\n"); |
| 653 | internal_trace_puts("*** snapshot is being ignored ***\n"); |
| 654 | return; |
| 655 | } |
| 656 | |
Steven Rostedt (Red Hat) | ad909e2 | 2013-03-06 21:45:37 -0500 | [diff] [blame] | 657 | if (!tr->allocated_snapshot) { |
Steven Rostedt (Red Hat) | ca268da | 2013-03-09 00:40:58 -0500 | [diff] [blame] | 658 | internal_trace_puts("*** SNAPSHOT NOT ALLOCATED ***\n"); |
| 659 | internal_trace_puts("*** stopping trace here! ***\n"); |
Steven Rostedt (Red Hat) | ad909e2 | 2013-03-06 21:45:37 -0500 | [diff] [blame] | 660 | tracing_off(); |
| 661 | return; |
| 662 | } |
| 663 | |
| 664 | /* Note, snapshot can not be used when the tracer uses it */ |
| 665 | if (tracer->use_max_tr) { |
Steven Rostedt (Red Hat) | ca268da | 2013-03-09 00:40:58 -0500 | [diff] [blame] | 666 | internal_trace_puts("*** LATENCY TRACER ACTIVE ***\n"); |
| 667 | internal_trace_puts("*** Can not use snapshot (sorry) ***\n"); |
Steven Rostedt (Red Hat) | ad909e2 | 2013-03-06 21:45:37 -0500 | [diff] [blame] | 668 | return; |
| 669 | } |
| 670 | |
| 671 | local_irq_save(flags); |
| 672 | update_max_tr(tr, current, smp_processor_id()); |
| 673 | local_irq_restore(flags); |
| 674 | } |
Steven Rostedt (Red Hat) | 1b22e38 | 2013-03-09 00:56:08 -0500 | [diff] [blame] | 675 | EXPORT_SYMBOL_GPL(tracing_snapshot); |
Steven Rostedt (Red Hat) | ad909e2 | 2013-03-06 21:45:37 -0500 | [diff] [blame] | 676 | |
| 677 | static int resize_buffer_duplicate_size(struct trace_buffer *trace_buf, |
| 678 | struct trace_buffer *size_buf, int cpu_id); |
Steven Rostedt (Red Hat) | 3209cff | 2013-03-12 11:17:54 -0400 | [diff] [blame] | 679 | static void set_buffer_entries(struct trace_buffer *buf, unsigned long val); |
| 680 | |
| 681 | static int alloc_snapshot(struct trace_array *tr) |
| 682 | { |
| 683 | int ret; |
| 684 | |
| 685 | if (!tr->allocated_snapshot) { |
| 686 | |
| 687 | /* allocate spare buffer */ |
| 688 | ret = resize_buffer_duplicate_size(&tr->max_buffer, |
| 689 | &tr->trace_buffer, RING_BUFFER_ALL_CPUS); |
| 690 | if (ret < 0) |
| 691 | return ret; |
| 692 | |
| 693 | tr->allocated_snapshot = true; |
| 694 | } |
| 695 | |
| 696 | return 0; |
| 697 | } |
| 698 | |
Fabian Frederick | ad1438a | 2014-04-17 21:44:42 +0200 | [diff] [blame] | 699 | static void free_snapshot(struct trace_array *tr) |
Steven Rostedt (Red Hat) | 3209cff | 2013-03-12 11:17:54 -0400 | [diff] [blame] | 700 | { |
| 701 | /* |
| 702 | * We don't free the ring buffer. instead, resize it because |
| 703 | * The max_tr ring buffer has some state (e.g. ring->clock) and |
| 704 | * we want preserve it. |
| 705 | */ |
| 706 | ring_buffer_resize(tr->max_buffer.buffer, 1, RING_BUFFER_ALL_CPUS); |
| 707 | set_buffer_entries(&tr->max_buffer, 1); |
| 708 | tracing_reset_online_cpus(&tr->max_buffer); |
| 709 | tr->allocated_snapshot = false; |
| 710 | } |
Steven Rostedt (Red Hat) | ad909e2 | 2013-03-06 21:45:37 -0500 | [diff] [blame] | 711 | |
| 712 | /** |
Tom Zanussi | 93e31ff | 2013-10-24 08:59:26 -0500 | [diff] [blame] | 713 | * tracing_alloc_snapshot - allocate snapshot buffer. |
| 714 | * |
| 715 | * This only allocates the snapshot buffer if it isn't already |
| 716 | * allocated - it doesn't also take a snapshot. |
| 717 | * |
| 718 | * This is meant to be used in cases where the snapshot buffer needs |
| 719 | * to be set up for events that can't sleep but need to be able to |
| 720 | * trigger a snapshot. |
| 721 | */ |
| 722 | int tracing_alloc_snapshot(void) |
| 723 | { |
| 724 | struct trace_array *tr = &global_trace; |
| 725 | int ret; |
| 726 | |
| 727 | ret = alloc_snapshot(tr); |
| 728 | WARN_ON(ret < 0); |
| 729 | |
| 730 | return ret; |
| 731 | } |
| 732 | EXPORT_SYMBOL_GPL(tracing_alloc_snapshot); |
| 733 | |
| 734 | /** |
Steven Rostedt (Red Hat) | ad909e2 | 2013-03-06 21:45:37 -0500 | [diff] [blame] | 735 | * trace_snapshot_alloc - allocate and take a snapshot of the current buffer. |
| 736 | * |
| 737 | * This is similar to trace_snapshot(), but it will allocate the |
| 738 | * snapshot buffer if it isn't already allocated. Use this only |
| 739 | * where it is safe to sleep, as the allocation may sleep. |
| 740 | * |
| 741 | * This causes a swap between the snapshot buffer and the current live |
| 742 | * tracing buffer. You can use this to take snapshots of the live |
| 743 | * trace when some condition is triggered, but continue to trace. |
| 744 | */ |
| 745 | void tracing_snapshot_alloc(void) |
| 746 | { |
Steven Rostedt (Red Hat) | ad909e2 | 2013-03-06 21:45:37 -0500 | [diff] [blame] | 747 | int ret; |
| 748 | |
Tom Zanussi | 93e31ff | 2013-10-24 08:59:26 -0500 | [diff] [blame] | 749 | ret = tracing_alloc_snapshot(); |
| 750 | if (ret < 0) |
Steven Rostedt (Red Hat) | 3209cff | 2013-03-12 11:17:54 -0400 | [diff] [blame] | 751 | return; |
Steven Rostedt (Red Hat) | ad909e2 | 2013-03-06 21:45:37 -0500 | [diff] [blame] | 752 | |
| 753 | tracing_snapshot(); |
| 754 | } |
Steven Rostedt (Red Hat) | 1b22e38 | 2013-03-09 00:56:08 -0500 | [diff] [blame] | 755 | EXPORT_SYMBOL_GPL(tracing_snapshot_alloc); |
Steven Rostedt (Red Hat) | ad909e2 | 2013-03-06 21:45:37 -0500 | [diff] [blame] | 756 | #else |
| 757 | void tracing_snapshot(void) |
| 758 | { |
| 759 | WARN_ONCE(1, "Snapshot feature not enabled, but internal snapshot used"); |
| 760 | } |
Steven Rostedt (Red Hat) | 1b22e38 | 2013-03-09 00:56:08 -0500 | [diff] [blame] | 761 | EXPORT_SYMBOL_GPL(tracing_snapshot); |
Tom Zanussi | 93e31ff | 2013-10-24 08:59:26 -0500 | [diff] [blame] | 762 | int tracing_alloc_snapshot(void) |
| 763 | { |
| 764 | WARN_ONCE(1, "Snapshot feature not enabled, but snapshot allocation used"); |
| 765 | return -ENODEV; |
| 766 | } |
| 767 | EXPORT_SYMBOL_GPL(tracing_alloc_snapshot); |
Steven Rostedt (Red Hat) | ad909e2 | 2013-03-06 21:45:37 -0500 | [diff] [blame] | 768 | void tracing_snapshot_alloc(void) |
| 769 | { |
| 770 | /* Give warning */ |
| 771 | tracing_snapshot(); |
| 772 | } |
Steven Rostedt (Red Hat) | 1b22e38 | 2013-03-09 00:56:08 -0500 | [diff] [blame] | 773 | EXPORT_SYMBOL_GPL(tracing_snapshot_alloc); |
Steven Rostedt (Red Hat) | ad909e2 | 2013-03-06 21:45:37 -0500 | [diff] [blame] | 774 | #endif /* CONFIG_TRACER_SNAPSHOT */ |
| 775 | |
Steven Rostedt (Red Hat) | 5280bce | 2013-07-02 19:59:57 -0400 | [diff] [blame] | 776 | static void tracer_tracing_off(struct trace_array *tr) |
Steven Rostedt (Red Hat) | 10246fa | 2013-07-01 15:58:24 -0400 | [diff] [blame] | 777 | { |
| 778 | if (tr->trace_buffer.buffer) |
| 779 | ring_buffer_record_off(tr->trace_buffer.buffer); |
| 780 | /* |
| 781 | * This flag is looked at when buffers haven't been allocated |
| 782 | * yet, or by some tracers (like irqsoff), that just want to |
| 783 | * know if the ring buffer has been disabled, but it can handle |
| 784 | * races of where it gets disabled but we still do a record. |
| 785 | * As the check is in the fast path of the tracers, it is more |
| 786 | * important to be fast than accurate. |
| 787 | */ |
| 788 | tr->buffer_disabled = 1; |
| 789 | /* Make the flag seen by readers */ |
| 790 | smp_wmb(); |
| 791 | } |
| 792 | |
Steven Rostedt | 499e547 | 2012-02-22 15:50:28 -0500 | [diff] [blame] | 793 | /** |
| 794 | * tracing_off - turn off tracing buffers |
| 795 | * |
| 796 | * This function stops the tracing buffers from recording data. |
| 797 | * It does not disable any overhead the tracers themselves may |
| 798 | * be causing. This function simply causes all recording to |
| 799 | * the ring buffers to fail. |
| 800 | */ |
| 801 | void tracing_off(void) |
| 802 | { |
Steven Rostedt (Red Hat) | 10246fa | 2013-07-01 15:58:24 -0400 | [diff] [blame] | 803 | tracer_tracing_off(&global_trace); |
Steven Rostedt | 499e547 | 2012-02-22 15:50:28 -0500 | [diff] [blame] | 804 | } |
| 805 | EXPORT_SYMBOL_GPL(tracing_off); |
| 806 | |
Steven Rostedt (Red Hat) | de7edd3 | 2013-06-14 16:21:43 -0400 | [diff] [blame] | 807 | void disable_trace_on_warning(void) |
| 808 | { |
| 809 | if (__disable_trace_on_warning) |
| 810 | tracing_off(); |
| 811 | } |
| 812 | |
Steven Rostedt | 499e547 | 2012-02-22 15:50:28 -0500 | [diff] [blame] | 813 | /** |
Steven Rostedt (Red Hat) | 10246fa | 2013-07-01 15:58:24 -0400 | [diff] [blame] | 814 | * tracer_tracing_is_on - show real state of ring buffer enabled |
| 815 | * @tr : the trace array to know if ring buffer is enabled |
| 816 | * |
| 817 | * Shows real state of the ring buffer if it is enabled or not. |
| 818 | */ |
Steven Rostedt (Red Hat) | 5280bce | 2013-07-02 19:59:57 -0400 | [diff] [blame] | 819 | static int tracer_tracing_is_on(struct trace_array *tr) |
Steven Rostedt (Red Hat) | 10246fa | 2013-07-01 15:58:24 -0400 | [diff] [blame] | 820 | { |
| 821 | if (tr->trace_buffer.buffer) |
| 822 | return ring_buffer_record_is_on(tr->trace_buffer.buffer); |
| 823 | return !tr->buffer_disabled; |
| 824 | } |
| 825 | |
Steven Rostedt | 499e547 | 2012-02-22 15:50:28 -0500 | [diff] [blame] | 826 | /** |
| 827 | * tracing_is_on - show state of ring buffers enabled |
| 828 | */ |
| 829 | int tracing_is_on(void) |
| 830 | { |
Steven Rostedt (Red Hat) | 10246fa | 2013-07-01 15:58:24 -0400 | [diff] [blame] | 831 | return tracer_tracing_is_on(&global_trace); |
Steven Rostedt | 499e547 | 2012-02-22 15:50:28 -0500 | [diff] [blame] | 832 | } |
| 833 | EXPORT_SYMBOL_GPL(tracing_is_on); |
| 834 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 835 | static int __init set_buf_size(char *str) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 836 | { |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 837 | unsigned long buf_size; |
Steven Rostedt | c6caeeb | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 838 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 839 | if (!str) |
| 840 | return 0; |
Li Zefan | 9d612be | 2009-06-24 17:33:15 +0800 | [diff] [blame] | 841 | buf_size = memparse(str, &str); |
Steven Rostedt | c6caeeb | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 842 | /* nr_entries can not be zero */ |
Li Zefan | 9d612be | 2009-06-24 17:33:15 +0800 | [diff] [blame] | 843 | if (buf_size == 0) |
Steven Rostedt | c6caeeb | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 844 | return 0; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 845 | trace_buf_size = buf_size; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 846 | return 1; |
| 847 | } |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 848 | __setup("trace_buf_size=", set_buf_size); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 849 | |
Tim Bird | 0e95017 | 2010-02-25 15:36:43 -0800 | [diff] [blame] | 850 | static int __init set_tracing_thresh(char *str) |
| 851 | { |
Wang Tianhong | 87abb3b | 2012-08-02 14:02:00 +0800 | [diff] [blame] | 852 | unsigned long threshold; |
Tim Bird | 0e95017 | 2010-02-25 15:36:43 -0800 | [diff] [blame] | 853 | int ret; |
| 854 | |
| 855 | if (!str) |
| 856 | return 0; |
Daniel Walter | bcd83ea | 2012-09-26 22:08:38 +0200 | [diff] [blame] | 857 | ret = kstrtoul(str, 0, &threshold); |
Tim Bird | 0e95017 | 2010-02-25 15:36:43 -0800 | [diff] [blame] | 858 | if (ret < 0) |
| 859 | return 0; |
Wang Tianhong | 87abb3b | 2012-08-02 14:02:00 +0800 | [diff] [blame] | 860 | tracing_thresh = threshold * 1000; |
Tim Bird | 0e95017 | 2010-02-25 15:36:43 -0800 | [diff] [blame] | 861 | return 1; |
| 862 | } |
| 863 | __setup("tracing_thresh=", set_tracing_thresh); |
| 864 | |
Steven Rostedt | 57f50be | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 865 | unsigned long nsecs_to_usecs(unsigned long nsecs) |
| 866 | { |
| 867 | return nsecs / 1000; |
| 868 | } |
| 869 | |
Steven Rostedt (Red Hat) | a3418a3 | 2015-09-29 09:43:30 -0400 | [diff] [blame] | 870 | /* |
| 871 | * TRACE_FLAGS is defined as a tuple matching bit masks with strings. |
| 872 | * It uses C(a, b) where 'a' is the enum name and 'b' is the string that |
| 873 | * matches it. By defining "C(a, b) b", TRACE_FLAGS becomes a list |
| 874 | * of strings in the order that the enums were defined. |
| 875 | */ |
| 876 | #undef C |
| 877 | #define C(a, b) b |
| 878 | |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 879 | /* These must match the bit postions in trace_iterator_flags */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 880 | static const char *trace_options[] = { |
Steven Rostedt (Red Hat) | a3418a3 | 2015-09-29 09:43:30 -0400 | [diff] [blame] | 881 | TRACE_FLAGS |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 882 | NULL |
| 883 | }; |
| 884 | |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 885 | static struct { |
| 886 | u64 (*func)(void); |
| 887 | const char *name; |
David Sharp | 8be0709 | 2012-11-13 12:18:22 -0800 | [diff] [blame] | 888 | int in_ns; /* is this clock in nanoseconds? */ |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 889 | } trace_clocks[] = { |
Thomas Gleixner | 1b3e5c0 | 2014-07-16 21:05:25 +0000 | [diff] [blame] | 890 | { trace_clock_local, "local", 1 }, |
| 891 | { trace_clock_global, "global", 1 }, |
| 892 | { trace_clock_counter, "counter", 0 }, |
Linus Torvalds | e7fda6c | 2014-08-05 17:46:42 -0700 | [diff] [blame] | 893 | { trace_clock_jiffies, "uptime", 0 }, |
Thomas Gleixner | 1b3e5c0 | 2014-07-16 21:05:25 +0000 | [diff] [blame] | 894 | { trace_clock, "perf", 1 }, |
| 895 | { ktime_get_mono_fast_ns, "mono", 1 }, |
Drew Richardson | aabfa5f | 2015-05-08 07:30:39 -0700 | [diff] [blame] | 896 | { ktime_get_raw_fast_ns, "mono_raw", 1 }, |
David Sharp | 8cbd9cc | 2012-11-13 12:18:21 -0800 | [diff] [blame] | 897 | ARCH_TRACE_CLOCKS |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 898 | }; |
| 899 | |
jolsa@redhat.com | b63f39e | 2009-09-11 17:29:27 +0200 | [diff] [blame] | 900 | /* |
| 901 | * trace_parser_get_init - gets the buffer for trace parser |
| 902 | */ |
| 903 | int trace_parser_get_init(struct trace_parser *parser, int size) |
| 904 | { |
| 905 | memset(parser, 0, sizeof(*parser)); |
| 906 | |
| 907 | parser->buffer = kmalloc(size, GFP_KERNEL); |
| 908 | if (!parser->buffer) |
| 909 | return 1; |
| 910 | |
| 911 | parser->size = size; |
| 912 | return 0; |
| 913 | } |
| 914 | |
| 915 | /* |
| 916 | * trace_parser_put - frees the buffer for trace parser |
| 917 | */ |
| 918 | void trace_parser_put(struct trace_parser *parser) |
| 919 | { |
| 920 | kfree(parser->buffer); |
| 921 | } |
| 922 | |
| 923 | /* |
| 924 | * trace_get_user - reads the user input string separated by space |
| 925 | * (matched by isspace(ch)) |
| 926 | * |
| 927 | * For each string found the 'struct trace_parser' is updated, |
| 928 | * and the function returns. |
| 929 | * |
| 930 | * Returns number of bytes read. |
| 931 | * |
| 932 | * See kernel/trace/trace.h for 'struct trace_parser' details. |
| 933 | */ |
| 934 | int trace_get_user(struct trace_parser *parser, const char __user *ubuf, |
| 935 | size_t cnt, loff_t *ppos) |
| 936 | { |
| 937 | char ch; |
| 938 | size_t read = 0; |
| 939 | ssize_t ret; |
| 940 | |
| 941 | if (!*ppos) |
| 942 | trace_parser_clear(parser); |
| 943 | |
| 944 | ret = get_user(ch, ubuf++); |
| 945 | if (ret) |
| 946 | goto out; |
| 947 | |
| 948 | read++; |
| 949 | cnt--; |
| 950 | |
| 951 | /* |
| 952 | * The parser is not finished with the last write, |
| 953 | * continue reading the user input without skipping spaces. |
| 954 | */ |
| 955 | if (!parser->cont) { |
| 956 | /* skip white space */ |
| 957 | while (cnt && isspace(ch)) { |
| 958 | ret = get_user(ch, ubuf++); |
| 959 | if (ret) |
| 960 | goto out; |
| 961 | read++; |
| 962 | cnt--; |
| 963 | } |
| 964 | |
| 965 | /* only spaces were written */ |
| 966 | if (isspace(ch)) { |
| 967 | *ppos += read; |
| 968 | ret = read; |
| 969 | goto out; |
| 970 | } |
| 971 | |
| 972 | parser->idx = 0; |
| 973 | } |
| 974 | |
| 975 | /* read the non-space input */ |
| 976 | while (cnt && !isspace(ch)) { |
Li Zefan | 3c235a3 | 2009-09-22 13:51:54 +0800 | [diff] [blame] | 977 | if (parser->idx < parser->size - 1) |
jolsa@redhat.com | b63f39e | 2009-09-11 17:29:27 +0200 | [diff] [blame] | 978 | parser->buffer[parser->idx++] = ch; |
| 979 | else { |
| 980 | ret = -EINVAL; |
| 981 | goto out; |
| 982 | } |
| 983 | ret = get_user(ch, ubuf++); |
| 984 | if (ret) |
| 985 | goto out; |
| 986 | read++; |
| 987 | cnt--; |
| 988 | } |
| 989 | |
| 990 | /* We either got finished input or we have to wait for another call. */ |
| 991 | if (isspace(ch)) { |
| 992 | parser->buffer[parser->idx] = 0; |
| 993 | parser->cont = false; |
Steven Rostedt | 057db84 | 2013-10-09 22:23:23 -0400 | [diff] [blame] | 994 | } else if (parser->idx < parser->size - 1) { |
jolsa@redhat.com | b63f39e | 2009-09-11 17:29:27 +0200 | [diff] [blame] | 995 | parser->cont = true; |
| 996 | parser->buffer[parser->idx++] = ch; |
Steven Rostedt | 057db84 | 2013-10-09 22:23:23 -0400 | [diff] [blame] | 997 | } else { |
| 998 | ret = -EINVAL; |
| 999 | goto out; |
jolsa@redhat.com | b63f39e | 2009-09-11 17:29:27 +0200 | [diff] [blame] | 1000 | } |
| 1001 | |
| 1002 | *ppos += read; |
| 1003 | ret = read; |
| 1004 | |
| 1005 | out: |
| 1006 | return ret; |
| 1007 | } |
| 1008 | |
Steven Rostedt (Red Hat) | 3a161d9 | 2014-06-25 15:54:42 -0400 | [diff] [blame] | 1009 | /* TODO add a seq_buf_to_buffer() */ |
Dmitri Vorobiev | b8b9426 | 2009-03-22 19:11:11 +0200 | [diff] [blame] | 1010 | 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] | 1011 | { |
| 1012 | int len; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 1013 | |
Steven Rostedt (Red Hat) | 5ac48378 | 2014-11-14 15:49:41 -0500 | [diff] [blame] | 1014 | if (trace_seq_used(s) <= s->seq.readpos) |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 1015 | return -EBUSY; |
| 1016 | |
Steven Rostedt (Red Hat) | 5ac48378 | 2014-11-14 15:49:41 -0500 | [diff] [blame] | 1017 | len = trace_seq_used(s) - s->seq.readpos; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 1018 | if (cnt > len) |
| 1019 | cnt = len; |
Steven Rostedt (Red Hat) | 3a161d9 | 2014-06-25 15:54:42 -0400 | [diff] [blame] | 1020 | memcpy(buf, s->buffer + s->seq.readpos, cnt); |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 1021 | |
Steven Rostedt (Red Hat) | 3a161d9 | 2014-06-25 15:54:42 -0400 | [diff] [blame] | 1022 | s->seq.readpos += cnt; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 1023 | return cnt; |
| 1024 | } |
| 1025 | |
Tim Bird | 0e95017 | 2010-02-25 15:36:43 -0800 | [diff] [blame] | 1026 | unsigned long __read_mostly tracing_thresh; |
| 1027 | |
Steven Rostedt | 5d4a9db | 2009-08-27 16:52:21 -0400 | [diff] [blame] | 1028 | #ifdef CONFIG_TRACER_MAX_TRACE |
Steven Rostedt | 5d4a9db | 2009-08-27 16:52:21 -0400 | [diff] [blame] | 1029 | /* |
| 1030 | * Copy the new maximum trace into the separate maximum-trace |
| 1031 | * structure. (this way the maximum trace is permanently saved, |
| 1032 | * for later retrieval via /sys/kernel/debug/tracing/latency_trace) |
| 1033 | */ |
| 1034 | static void |
| 1035 | __update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu) |
| 1036 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1037 | struct trace_buffer *trace_buf = &tr->trace_buffer; |
| 1038 | struct trace_buffer *max_buf = &tr->max_buffer; |
| 1039 | struct trace_array_cpu *data = per_cpu_ptr(trace_buf->data, cpu); |
| 1040 | 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] | 1041 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1042 | max_buf->cpu = cpu; |
| 1043 | max_buf->time_start = data->preempt_timestamp; |
Steven Rostedt | 5d4a9db | 2009-08-27 16:52:21 -0400 | [diff] [blame] | 1044 | |
Steven Rostedt (Red Hat) | 6d9b3fa | 2014-01-14 11:28:38 -0500 | [diff] [blame] | 1045 | max_data->saved_latency = tr->max_latency; |
Steven Rostedt | 8248ac0 | 2009-09-02 12:27:41 -0400 | [diff] [blame] | 1046 | max_data->critical_start = data->critical_start; |
| 1047 | max_data->critical_end = data->critical_end; |
Steven Rostedt | 5d4a9db | 2009-08-27 16:52:21 -0400 | [diff] [blame] | 1048 | |
Arnaldo Carvalho de Melo | 1acaa1b | 2010-03-05 18:23:50 -0300 | [diff] [blame] | 1049 | memcpy(max_data->comm, tsk->comm, TASK_COMM_LEN); |
Steven Rostedt | 8248ac0 | 2009-09-02 12:27:41 -0400 | [diff] [blame] | 1050 | max_data->pid = tsk->pid; |
Steven Rostedt (Red Hat) | f17a519 | 2013-05-30 21:10:37 -0400 | [diff] [blame] | 1051 | /* |
| 1052 | * If tsk == current, then use current_uid(), as that does not use |
| 1053 | * RCU. The irq tracer can be called out of RCU scope. |
| 1054 | */ |
| 1055 | if (tsk == current) |
| 1056 | max_data->uid = current_uid(); |
| 1057 | else |
| 1058 | max_data->uid = task_uid(tsk); |
| 1059 | |
Steven Rostedt | 8248ac0 | 2009-09-02 12:27:41 -0400 | [diff] [blame] | 1060 | max_data->nice = tsk->static_prio - 20 - MAX_RT_PRIO; |
| 1061 | max_data->policy = tsk->policy; |
| 1062 | max_data->rt_priority = tsk->rt_priority; |
Steven Rostedt | 5d4a9db | 2009-08-27 16:52:21 -0400 | [diff] [blame] | 1063 | |
| 1064 | /* record this tasks comm */ |
| 1065 | tracing_record_cmdline(tsk); |
| 1066 | } |
| 1067 | |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 1068 | /** |
| 1069 | * update_max_tr - snapshot all trace buffers from global_trace to max_tr |
| 1070 | * @tr: tracer |
| 1071 | * @tsk: the task with the latency |
| 1072 | * @cpu: The cpu that initiated the trace. |
| 1073 | * |
| 1074 | * Flip the buffers between the @tr and the max_tr and record information |
| 1075 | * about which task was the cause of this latency. |
| 1076 | */ |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1077 | void |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1078 | update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu) |
| 1079 | { |
Steven Rostedt (Red Hat) | 2721e72 | 2013-03-12 11:32:32 -0400 | [diff] [blame] | 1080 | struct ring_buffer *buf; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1081 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 1082 | if (tr->stop_count) |
Steven Rostedt | b8de7bd1 | 2009-08-31 22:32:27 -0400 | [diff] [blame] | 1083 | return; |
| 1084 | |
Steven Rostedt | 4c11d7a | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1085 | WARN_ON_ONCE(!irqs_disabled()); |
Steven Rostedt | 34600f0 | 2013-01-22 13:35:11 -0500 | [diff] [blame] | 1086 | |
Steven Rostedt (Red Hat) | 45ad21c | 2013-03-05 18:25:02 -0500 | [diff] [blame] | 1087 | if (!tr->allocated_snapshot) { |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 1088 | /* Only the nop tracer should hit this when disabling */ |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 1089 | WARN_ON_ONCE(tr->current_trace != &nop_trace); |
KOSAKI Motohiro | ef710e1 | 2010-07-01 14:34:35 +0900 | [diff] [blame] | 1090 | return; |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 1091 | } |
Steven Rostedt | 34600f0 | 2013-01-22 13:35:11 -0500 | [diff] [blame] | 1092 | |
Steven Rostedt (Red Hat) | 0b9b12c | 2014-01-14 10:04:59 -0500 | [diff] [blame] | 1093 | arch_spin_lock(&tr->max_lock); |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1094 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1095 | buf = tr->trace_buffer.buffer; |
| 1096 | tr->trace_buffer.buffer = tr->max_buffer.buffer; |
| 1097 | tr->max_buffer.buffer = buf; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1098 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1099 | __update_max_tr(tr, tsk, cpu); |
Steven Rostedt (Red Hat) | 0b9b12c | 2014-01-14 10:04:59 -0500 | [diff] [blame] | 1100 | arch_spin_unlock(&tr->max_lock); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1101 | } |
| 1102 | |
| 1103 | /** |
| 1104 | * update_max_tr_single - only copy one trace over, and reset the rest |
| 1105 | * @tr - tracer |
| 1106 | * @tsk - task with the latency |
| 1107 | * @cpu - the cpu of the buffer to copy. |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 1108 | * |
| 1109 | * 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] | 1110 | */ |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1111 | void |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1112 | update_max_tr_single(struct trace_array *tr, struct task_struct *tsk, int cpu) |
| 1113 | { |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1114 | int ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1115 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 1116 | if (tr->stop_count) |
Steven Rostedt | b8de7bd1 | 2009-08-31 22:32:27 -0400 | [diff] [blame] | 1117 | return; |
| 1118 | |
Steven Rostedt | 4c11d7a | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1119 | WARN_ON_ONCE(!irqs_disabled()); |
Steven Rostedt | 6c24499 | 2013-04-29 20:08:14 -0400 | [diff] [blame] | 1120 | if (!tr->allocated_snapshot) { |
Steven Rostedt (Red Hat) | 2930e04 | 2013-03-26 17:33:00 -0400 | [diff] [blame] | 1121 | /* Only the nop tracer should hit this when disabling */ |
Linus Torvalds | 9e8529a | 2013-04-29 13:55:38 -0700 | [diff] [blame] | 1122 | WARN_ON_ONCE(tr->current_trace != &nop_trace); |
KOSAKI Motohiro | ef710e1 | 2010-07-01 14:34:35 +0900 | [diff] [blame] | 1123 | return; |
Steven Rostedt (Red Hat) | 2930e04 | 2013-03-26 17:33:00 -0400 | [diff] [blame] | 1124 | } |
KOSAKI Motohiro | ef710e1 | 2010-07-01 14:34:35 +0900 | [diff] [blame] | 1125 | |
Steven Rostedt (Red Hat) | 0b9b12c | 2014-01-14 10:04:59 -0500 | [diff] [blame] | 1126 | arch_spin_lock(&tr->max_lock); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1127 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1128 | 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] | 1129 | |
Steven Rostedt | e8165dbb | 2009-09-03 19:13:05 -0400 | [diff] [blame] | 1130 | if (ret == -EBUSY) { |
| 1131 | /* |
| 1132 | * We failed to swap the buffer due to a commit taking |
| 1133 | * place on this CPU. We fail to record, but we reset |
| 1134 | * the max trace buffer (no one writes directly to it) |
| 1135 | * and flag that it failed. |
| 1136 | */ |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1137 | trace_array_printk_buf(tr->max_buffer.buffer, _THIS_IP_, |
Steven Rostedt | e8165dbb | 2009-09-03 19:13:05 -0400 | [diff] [blame] | 1138 | "Failed to swap buffers due to commit in progress\n"); |
| 1139 | } |
| 1140 | |
Steven Rostedt | e8165dbb | 2009-09-03 19:13:05 -0400 | [diff] [blame] | 1141 | WARN_ON_ONCE(ret && ret != -EAGAIN && ret != -EBUSY); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1142 | |
| 1143 | __update_max_tr(tr, tsk, cpu); |
Steven Rostedt (Red Hat) | 0b9b12c | 2014-01-14 10:04:59 -0500 | [diff] [blame] | 1144 | arch_spin_unlock(&tr->max_lock); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1145 | } |
Steven Rostedt | 5d4a9db | 2009-08-27 16:52:21 -0400 | [diff] [blame] | 1146 | #endif /* CONFIG_TRACER_MAX_TRACE */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1147 | |
Rabin Vincent | e30f53a | 2014-11-10 19:46:34 +0100 | [diff] [blame] | 1148 | static int wait_on_pipe(struct trace_iterator *iter, bool full) |
Steven Rostedt | 0d5c6e1 | 2012-11-01 20:54:21 -0400 | [diff] [blame] | 1149 | { |
Steven Rostedt (Red Hat) | 1569345 | 2013-02-28 19:59:17 -0500 | [diff] [blame] | 1150 | /* Iterators are static, they should be filled or empty */ |
| 1151 | if (trace_buffer_iter(iter, iter->cpu_file)) |
Steven Rostedt (Red Hat) | 8b8b368 | 2014-06-10 09:46:00 -0400 | [diff] [blame] | 1152 | return 0; |
Steven Rostedt | 0d5c6e1 | 2012-11-01 20:54:21 -0400 | [diff] [blame] | 1153 | |
Rabin Vincent | e30f53a | 2014-11-10 19:46:34 +0100 | [diff] [blame] | 1154 | return ring_buffer_wait(iter->trace_buffer->buffer, iter->cpu_file, |
| 1155 | full); |
Steven Rostedt | 0d5c6e1 | 2012-11-01 20:54:21 -0400 | [diff] [blame] | 1156 | } |
| 1157 | |
Steven Rostedt (Red Hat) | f4e781c | 2013-03-07 11:10:56 -0500 | [diff] [blame] | 1158 | #ifdef CONFIG_FTRACE_STARTUP_TEST |
| 1159 | static int run_tracer_selftest(struct tracer *type) |
| 1160 | { |
| 1161 | struct trace_array *tr = &global_trace; |
| 1162 | struct tracer *saved_tracer = tr->current_trace; |
| 1163 | int ret; |
| 1164 | |
| 1165 | if (!type->selftest || tracing_selftest_disabled) |
| 1166 | return 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1167 | |
| 1168 | /* |
Steven Rostedt (Red Hat) | f4e781c | 2013-03-07 11:10:56 -0500 | [diff] [blame] | 1169 | * Run a selftest on this tracer. |
| 1170 | * Here we reset the trace buffer, and set the current |
| 1171 | * tracer to be this tracer. The tracer can then run some |
| 1172 | * internal tracing to verify that everything is in order. |
| 1173 | * If we fail, we do not register this tracer. |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 1174 | */ |
Steven Rostedt (Red Hat) | f4e781c | 2013-03-07 11:10:56 -0500 | [diff] [blame] | 1175 | tracing_reset_online_cpus(&tr->trace_buffer); |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 1176 | |
Steven Rostedt (Red Hat) | f4e781c | 2013-03-07 11:10:56 -0500 | [diff] [blame] | 1177 | tr->current_trace = type; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1178 | |
Steven Rostedt (Red Hat) | f4e781c | 2013-03-07 11:10:56 -0500 | [diff] [blame] | 1179 | #ifdef CONFIG_TRACER_MAX_TRACE |
| 1180 | if (type->use_max_tr) { |
| 1181 | /* If we expanded the buffers, make sure the max is expanded too */ |
| 1182 | if (ring_buffer_expanded) |
| 1183 | ring_buffer_resize(tr->max_buffer.buffer, trace_buf_size, |
| 1184 | RING_BUFFER_ALL_CPUS); |
| 1185 | tr->allocated_snapshot = true; |
| 1186 | } |
| 1187 | #endif |
| 1188 | |
| 1189 | /* the test is responsible for initializing and enabling */ |
| 1190 | pr_info("Testing tracer %s: ", type->name); |
| 1191 | ret = type->selftest(type, tr); |
| 1192 | /* the test is responsible for resetting too */ |
| 1193 | tr->current_trace = saved_tracer; |
| 1194 | if (ret) { |
| 1195 | printk(KERN_CONT "FAILED!\n"); |
| 1196 | /* Add the warning after printing 'FAILED' */ |
| 1197 | WARN_ON(1); |
| 1198 | return -1; |
| 1199 | } |
| 1200 | /* Only reset on passing, to avoid touching corrupted buffers */ |
| 1201 | tracing_reset_online_cpus(&tr->trace_buffer); |
| 1202 | |
| 1203 | #ifdef CONFIG_TRACER_MAX_TRACE |
| 1204 | if (type->use_max_tr) { |
| 1205 | tr->allocated_snapshot = false; |
| 1206 | |
| 1207 | /* Shrink the max buffer again */ |
| 1208 | if (ring_buffer_expanded) |
| 1209 | ring_buffer_resize(tr->max_buffer.buffer, 1, |
| 1210 | RING_BUFFER_ALL_CPUS); |
| 1211 | } |
| 1212 | #endif |
| 1213 | |
| 1214 | printk(KERN_CONT "PASSED\n"); |
| 1215 | return 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1216 | } |
Steven Rostedt (Red Hat) | f4e781c | 2013-03-07 11:10:56 -0500 | [diff] [blame] | 1217 | #else |
| 1218 | static inline int run_tracer_selftest(struct tracer *type) |
| 1219 | { |
| 1220 | return 0; |
| 1221 | } |
| 1222 | #endif /* CONFIG_FTRACE_STARTUP_TEST */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1223 | |
Steven Rostedt (Red Hat) | 41d9c0b | 2015-09-29 17:31:55 -0400 | [diff] [blame] | 1224 | static void add_tracer_options(struct trace_array *tr, struct tracer *t); |
| 1225 | |
Steven Rostedt | 4fcdae8 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 1226 | /** |
| 1227 | * register_tracer - register a tracer with the ftrace system. |
| 1228 | * @type - the plugin for the tracer |
| 1229 | * |
| 1230 | * Register a new plugin tracer. |
| 1231 | */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1232 | int register_tracer(struct tracer *type) |
| 1233 | { |
| 1234 | struct tracer *t; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1235 | int ret = 0; |
| 1236 | |
| 1237 | if (!type->name) { |
| 1238 | pr_info("Tracer must have a name\n"); |
| 1239 | return -1; |
| 1240 | } |
| 1241 | |
Dan Carpenter | 24a461d | 2010-07-10 12:06:44 +0200 | [diff] [blame] | 1242 | if (strlen(type->name) >= MAX_TRACER_SIZE) { |
Li Zefan | ee6c2c1 | 2009-09-18 14:06:47 +0800 | [diff] [blame] | 1243 | pr_info("Tracer has a name longer than %d\n", MAX_TRACER_SIZE); |
| 1244 | return -1; |
| 1245 | } |
| 1246 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1247 | mutex_lock(&trace_types_lock); |
Ingo Molnar | 86fa2f6 | 2008-11-19 10:00:15 +0100 | [diff] [blame] | 1248 | |
Frederic Weisbecker | 8e1b82e | 2008-12-06 03:41:33 +0100 | [diff] [blame] | 1249 | tracing_selftest_running = true; |
| 1250 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1251 | for (t = trace_types; t; t = t->next) { |
| 1252 | if (strcmp(type->name, t->name) == 0) { |
| 1253 | /* already found */ |
Li Zefan | ee6c2c1 | 2009-09-18 14:06:47 +0800 | [diff] [blame] | 1254 | pr_info("Tracer %s already registered\n", |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1255 | type->name); |
| 1256 | ret = -1; |
| 1257 | goto out; |
| 1258 | } |
| 1259 | } |
| 1260 | |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 1261 | if (!type->set_flag) |
| 1262 | type->set_flag = &dummy_set_flag; |
| 1263 | if (!type->flags) |
| 1264 | type->flags = &dummy_tracer_flags; |
| 1265 | else |
| 1266 | if (!type->flags->opts) |
| 1267 | type->flags->opts = dummy_tracer_opt; |
Frederic Weisbecker | 6eaaa5d | 2009-02-11 02:25:00 +0100 | [diff] [blame] | 1268 | |
Steven Rostedt (Red Hat) | f4e781c | 2013-03-07 11:10:56 -0500 | [diff] [blame] | 1269 | ret = run_tracer_selftest(type); |
| 1270 | if (ret < 0) |
| 1271 | goto out; |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 1272 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1273 | type->next = trace_types; |
| 1274 | trace_types = type; |
Steven Rostedt (Red Hat) | 41d9c0b | 2015-09-29 17:31:55 -0400 | [diff] [blame] | 1275 | add_tracer_options(&global_trace, type); |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 1276 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1277 | out: |
Frederic Weisbecker | 8e1b82e | 2008-12-06 03:41:33 +0100 | [diff] [blame] | 1278 | tracing_selftest_running = false; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1279 | mutex_unlock(&trace_types_lock); |
| 1280 | |
Steven Rostedt | dac7494 | 2009-02-05 01:13:38 -0500 | [diff] [blame] | 1281 | if (ret || !default_bootup_tracer) |
| 1282 | goto out_unlock; |
Steven Rostedt | b2821ae | 2009-02-02 21:38:32 -0500 | [diff] [blame] | 1283 | |
Li Zefan | ee6c2c1 | 2009-09-18 14:06:47 +0800 | [diff] [blame] | 1284 | if (strncmp(default_bootup_tracer, type->name, MAX_TRACER_SIZE)) |
Steven Rostedt | dac7494 | 2009-02-05 01:13:38 -0500 | [diff] [blame] | 1285 | goto out_unlock; |
| 1286 | |
| 1287 | printk(KERN_INFO "Starting tracer '%s'\n", type->name); |
| 1288 | /* Do we want this tracer to start on bootup? */ |
Steven Rostedt (Red Hat) | 607e2ea | 2013-11-06 22:42:48 -0500 | [diff] [blame] | 1289 | tracing_set_tracer(&global_trace, type->name); |
Steven Rostedt | dac7494 | 2009-02-05 01:13:38 -0500 | [diff] [blame] | 1290 | default_bootup_tracer = NULL; |
| 1291 | /* disable other selftests, since this will break it. */ |
Steven Rostedt (Red Hat) | 55034cd | 2013-03-07 22:48:09 -0500 | [diff] [blame] | 1292 | tracing_selftest_disabled = true; |
Steven Rostedt | dac7494 | 2009-02-05 01:13:38 -0500 | [diff] [blame] | 1293 | #ifdef CONFIG_FTRACE_STARTUP_TEST |
| 1294 | printk(KERN_INFO "Disabling FTRACE selftests due to running tracer '%s'\n", |
| 1295 | type->name); |
| 1296 | #endif |
| 1297 | |
| 1298 | out_unlock: |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1299 | return ret; |
| 1300 | } |
| 1301 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1302 | void tracing_reset(struct trace_buffer *buf, int cpu) |
Steven Rostedt | f633903 | 2009-09-04 12:35:16 -0400 | [diff] [blame] | 1303 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1304 | struct ring_buffer *buffer = buf->buffer; |
Steven Rostedt | f633903 | 2009-09-04 12:35:16 -0400 | [diff] [blame] | 1305 | |
Hiraku Toyooka | a541641 | 2012-12-19 16:02:34 +0900 | [diff] [blame] | 1306 | if (!buffer) |
| 1307 | return; |
| 1308 | |
Steven Rostedt | f633903 | 2009-09-04 12:35:16 -0400 | [diff] [blame] | 1309 | ring_buffer_record_disable(buffer); |
| 1310 | |
| 1311 | /* Make sure all commits have finished */ |
| 1312 | synchronize_sched(); |
Steven Rostedt | 6817968 | 2012-05-08 20:57:53 -0400 | [diff] [blame] | 1313 | ring_buffer_reset_cpu(buffer, cpu); |
Steven Rostedt | f633903 | 2009-09-04 12:35:16 -0400 | [diff] [blame] | 1314 | |
| 1315 | ring_buffer_record_enable(buffer); |
| 1316 | } |
| 1317 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1318 | void tracing_reset_online_cpus(struct trace_buffer *buf) |
Pekka J Enberg | 213cc06 | 2008-12-19 12:08:39 +0200 | [diff] [blame] | 1319 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1320 | struct ring_buffer *buffer = buf->buffer; |
Pekka J Enberg | 213cc06 | 2008-12-19 12:08:39 +0200 | [diff] [blame] | 1321 | int cpu; |
| 1322 | |
Hiraku Toyooka | a541641 | 2012-12-19 16:02:34 +0900 | [diff] [blame] | 1323 | if (!buffer) |
| 1324 | return; |
| 1325 | |
Steven Rostedt | 621968c | 2009-09-04 12:02:35 -0400 | [diff] [blame] | 1326 | ring_buffer_record_disable(buffer); |
| 1327 | |
| 1328 | /* Make sure all commits have finished */ |
| 1329 | synchronize_sched(); |
| 1330 | |
Alexander Z Lam | 9457158 | 2013-08-02 18:36:16 -0700 | [diff] [blame] | 1331 | buf->time_start = buffer_ftrace_now(buf, buf->cpu); |
Pekka J Enberg | 213cc06 | 2008-12-19 12:08:39 +0200 | [diff] [blame] | 1332 | |
| 1333 | for_each_online_cpu(cpu) |
Steven Rostedt | 6817968 | 2012-05-08 20:57:53 -0400 | [diff] [blame] | 1334 | ring_buffer_reset_cpu(buffer, cpu); |
Steven Rostedt | 621968c | 2009-09-04 12:02:35 -0400 | [diff] [blame] | 1335 | |
| 1336 | ring_buffer_record_enable(buffer); |
Pekka J Enberg | 213cc06 | 2008-12-19 12:08:39 +0200 | [diff] [blame] | 1337 | } |
| 1338 | |
Steven Rostedt (Red Hat) | 09d8091 | 2013-07-23 22:21:59 -0400 | [diff] [blame] | 1339 | /* Must have trace_types_lock held */ |
Steven Rostedt (Red Hat) | 873c642 | 2013-03-04 23:26:06 -0500 | [diff] [blame] | 1340 | void tracing_reset_all_online_cpus(void) |
Steven Rostedt | 9456f0f | 2009-05-06 21:54:09 -0400 | [diff] [blame] | 1341 | { |
Steven Rostedt (Red Hat) | 873c642 | 2013-03-04 23:26:06 -0500 | [diff] [blame] | 1342 | struct trace_array *tr; |
| 1343 | |
Steven Rostedt (Red Hat) | 873c642 | 2013-03-04 23:26:06 -0500 | [diff] [blame] | 1344 | list_for_each_entry(tr, &ftrace_trace_arrays, list) { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1345 | tracing_reset_online_cpus(&tr->trace_buffer); |
| 1346 | #ifdef CONFIG_TRACER_MAX_TRACE |
| 1347 | tracing_reset_online_cpus(&tr->max_buffer); |
| 1348 | #endif |
Steven Rostedt (Red Hat) | 873c642 | 2013-03-04 23:26:06 -0500 | [diff] [blame] | 1349 | } |
Steven Rostedt | 9456f0f | 2009-05-06 21:54:09 -0400 | [diff] [blame] | 1350 | } |
| 1351 | |
Yoshihiro YUNOMAE | 939c7a4 | 2014-06-05 10:24:27 +0900 | [diff] [blame] | 1352 | #define SAVED_CMDLINES_DEFAULT 128 |
Thomas Gleixner | 2c7eea4 | 2009-03-18 09:03:19 +0100 | [diff] [blame] | 1353 | #define NO_CMDLINE_MAP UINT_MAX |
Thomas Gleixner | edc35bd | 2009-12-03 12:38:57 +0100 | [diff] [blame] | 1354 | static arch_spinlock_t trace_cmdline_lock = __ARCH_SPIN_LOCK_UNLOCKED; |
Yoshihiro YUNOMAE | 939c7a4 | 2014-06-05 10:24:27 +0900 | [diff] [blame] | 1355 | struct saved_cmdlines_buffer { |
| 1356 | unsigned map_pid_to_cmdline[PID_MAX_DEFAULT+1]; |
| 1357 | unsigned *map_cmdline_to_pid; |
| 1358 | unsigned cmdline_num; |
| 1359 | int cmdline_idx; |
| 1360 | char *saved_cmdlines; |
| 1361 | }; |
| 1362 | static struct saved_cmdlines_buffer *savedcmd; |
Steven Rostedt | 25b0b44 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 1363 | |
Steven Rostedt | 25b0b44 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 1364 | /* temporary disable recording */ |
Hannes Eder | 4fd2735 | 2009-02-10 19:44:12 +0100 | [diff] [blame] | 1365 | static atomic_t trace_record_cmdline_disabled __read_mostly; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1366 | |
Yoshihiro YUNOMAE | 939c7a4 | 2014-06-05 10:24:27 +0900 | [diff] [blame] | 1367 | static inline char *get_saved_cmdlines(int idx) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1368 | { |
Yoshihiro YUNOMAE | 939c7a4 | 2014-06-05 10:24:27 +0900 | [diff] [blame] | 1369 | return &savedcmd->saved_cmdlines[idx * TASK_COMM_LEN]; |
| 1370 | } |
| 1371 | |
| 1372 | static inline void set_cmdline(int idx, const char *cmdline) |
| 1373 | { |
| 1374 | memcpy(get_saved_cmdlines(idx), cmdline, TASK_COMM_LEN); |
| 1375 | } |
| 1376 | |
| 1377 | static int allocate_cmdlines_buffer(unsigned int val, |
| 1378 | struct saved_cmdlines_buffer *s) |
| 1379 | { |
| 1380 | s->map_cmdline_to_pid = kmalloc(val * sizeof(*s->map_cmdline_to_pid), |
| 1381 | GFP_KERNEL); |
| 1382 | if (!s->map_cmdline_to_pid) |
| 1383 | return -ENOMEM; |
| 1384 | |
| 1385 | s->saved_cmdlines = kmalloc(val * TASK_COMM_LEN, GFP_KERNEL); |
| 1386 | if (!s->saved_cmdlines) { |
| 1387 | kfree(s->map_cmdline_to_pid); |
| 1388 | return -ENOMEM; |
| 1389 | } |
| 1390 | |
| 1391 | s->cmdline_idx = 0; |
| 1392 | s->cmdline_num = val; |
| 1393 | memset(&s->map_pid_to_cmdline, NO_CMDLINE_MAP, |
| 1394 | sizeof(s->map_pid_to_cmdline)); |
| 1395 | memset(s->map_cmdline_to_pid, NO_CMDLINE_MAP, |
| 1396 | val * sizeof(*s->map_cmdline_to_pid)); |
| 1397 | |
| 1398 | return 0; |
| 1399 | } |
| 1400 | |
| 1401 | static int trace_create_savedcmd(void) |
| 1402 | { |
| 1403 | int ret; |
| 1404 | |
Namhyung Kim | a6af8fb | 2014-06-10 16:11:35 +0900 | [diff] [blame] | 1405 | savedcmd = kmalloc(sizeof(*savedcmd), GFP_KERNEL); |
Yoshihiro YUNOMAE | 939c7a4 | 2014-06-05 10:24:27 +0900 | [diff] [blame] | 1406 | if (!savedcmd) |
| 1407 | return -ENOMEM; |
| 1408 | |
| 1409 | ret = allocate_cmdlines_buffer(SAVED_CMDLINES_DEFAULT, savedcmd); |
| 1410 | if (ret < 0) { |
| 1411 | kfree(savedcmd); |
| 1412 | savedcmd = NULL; |
| 1413 | return -ENOMEM; |
| 1414 | } |
| 1415 | |
| 1416 | return 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1417 | } |
| 1418 | |
Carsten Emde | b5130b1 | 2009-09-13 01:43:07 +0200 | [diff] [blame] | 1419 | int is_tracing_stopped(void) |
| 1420 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 1421 | return global_trace.stop_count; |
Carsten Emde | b5130b1 | 2009-09-13 01:43:07 +0200 | [diff] [blame] | 1422 | } |
| 1423 | |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1424 | /** |
| 1425 | * tracing_start - quick start of the tracer |
| 1426 | * |
| 1427 | * If tracing is enabled but was stopped by tracing_stop, |
| 1428 | * this will start the tracer back up. |
| 1429 | */ |
| 1430 | void tracing_start(void) |
| 1431 | { |
| 1432 | struct ring_buffer *buffer; |
| 1433 | unsigned long flags; |
| 1434 | |
| 1435 | if (tracing_disabled) |
| 1436 | return; |
| 1437 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 1438 | raw_spin_lock_irqsave(&global_trace.start_lock, flags); |
| 1439 | if (--global_trace.stop_count) { |
| 1440 | if (global_trace.stop_count < 0) { |
Steven Rostedt | b06a830 | 2009-01-22 14:26:15 -0500 | [diff] [blame] | 1441 | /* Someone screwed up their debugging */ |
| 1442 | WARN_ON_ONCE(1); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 1443 | global_trace.stop_count = 0; |
Steven Rostedt | b06a830 | 2009-01-22 14:26:15 -0500 | [diff] [blame] | 1444 | } |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1445 | goto out; |
| 1446 | } |
| 1447 | |
Steven Rostedt | a2f8071 | 2010-03-12 19:56:00 -0500 | [diff] [blame] | 1448 | /* Prevent the buffers from switching */ |
Steven Rostedt (Red Hat) | 0b9b12c | 2014-01-14 10:04:59 -0500 | [diff] [blame] | 1449 | arch_spin_lock(&global_trace.max_lock); |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1450 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1451 | buffer = global_trace.trace_buffer.buffer; |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1452 | if (buffer) |
| 1453 | ring_buffer_record_enable(buffer); |
| 1454 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1455 | #ifdef CONFIG_TRACER_MAX_TRACE |
| 1456 | buffer = global_trace.max_buffer.buffer; |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1457 | if (buffer) |
| 1458 | ring_buffer_record_enable(buffer); |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1459 | #endif |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1460 | |
Steven Rostedt (Red Hat) | 0b9b12c | 2014-01-14 10:04:59 -0500 | [diff] [blame] | 1461 | arch_spin_unlock(&global_trace.max_lock); |
Steven Rostedt | a2f8071 | 2010-03-12 19:56:00 -0500 | [diff] [blame] | 1462 | |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1463 | out: |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 1464 | raw_spin_unlock_irqrestore(&global_trace.start_lock, flags); |
| 1465 | } |
| 1466 | |
| 1467 | static void tracing_start_tr(struct trace_array *tr) |
| 1468 | { |
| 1469 | struct ring_buffer *buffer; |
| 1470 | unsigned long flags; |
| 1471 | |
| 1472 | if (tracing_disabled) |
| 1473 | return; |
| 1474 | |
| 1475 | /* If global, we need to also start the max tracer */ |
| 1476 | if (tr->flags & TRACE_ARRAY_FL_GLOBAL) |
| 1477 | return tracing_start(); |
| 1478 | |
| 1479 | raw_spin_lock_irqsave(&tr->start_lock, flags); |
| 1480 | |
| 1481 | if (--tr->stop_count) { |
| 1482 | if (tr->stop_count < 0) { |
| 1483 | /* Someone screwed up their debugging */ |
| 1484 | WARN_ON_ONCE(1); |
| 1485 | tr->stop_count = 0; |
| 1486 | } |
| 1487 | goto out; |
| 1488 | } |
| 1489 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1490 | buffer = tr->trace_buffer.buffer; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 1491 | if (buffer) |
| 1492 | ring_buffer_record_enable(buffer); |
| 1493 | |
| 1494 | out: |
| 1495 | raw_spin_unlock_irqrestore(&tr->start_lock, flags); |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1496 | } |
| 1497 | |
| 1498 | /** |
| 1499 | * tracing_stop - quick stop of the tracer |
| 1500 | * |
| 1501 | * Light weight way to stop tracing. Use in conjunction with |
| 1502 | * tracing_start. |
| 1503 | */ |
| 1504 | void tracing_stop(void) |
| 1505 | { |
| 1506 | struct ring_buffer *buffer; |
| 1507 | unsigned long flags; |
| 1508 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 1509 | raw_spin_lock_irqsave(&global_trace.start_lock, flags); |
| 1510 | if (global_trace.stop_count++) |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1511 | goto out; |
| 1512 | |
Steven Rostedt | a2f8071 | 2010-03-12 19:56:00 -0500 | [diff] [blame] | 1513 | /* Prevent the buffers from switching */ |
Steven Rostedt (Red Hat) | 0b9b12c | 2014-01-14 10:04:59 -0500 | [diff] [blame] | 1514 | arch_spin_lock(&global_trace.max_lock); |
Steven Rostedt | a2f8071 | 2010-03-12 19:56:00 -0500 | [diff] [blame] | 1515 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1516 | buffer = global_trace.trace_buffer.buffer; |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1517 | if (buffer) |
| 1518 | ring_buffer_record_disable(buffer); |
| 1519 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1520 | #ifdef CONFIG_TRACER_MAX_TRACE |
| 1521 | buffer = global_trace.max_buffer.buffer; |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1522 | if (buffer) |
| 1523 | ring_buffer_record_disable(buffer); |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1524 | #endif |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1525 | |
Steven Rostedt (Red Hat) | 0b9b12c | 2014-01-14 10:04:59 -0500 | [diff] [blame] | 1526 | arch_spin_unlock(&global_trace.max_lock); |
Steven Rostedt | a2f8071 | 2010-03-12 19:56:00 -0500 | [diff] [blame] | 1527 | |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1528 | out: |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 1529 | raw_spin_unlock_irqrestore(&global_trace.start_lock, flags); |
| 1530 | } |
| 1531 | |
| 1532 | static void tracing_stop_tr(struct trace_array *tr) |
| 1533 | { |
| 1534 | struct ring_buffer *buffer; |
| 1535 | unsigned long flags; |
| 1536 | |
| 1537 | /* If global, we need to also stop the max tracer */ |
| 1538 | if (tr->flags & TRACE_ARRAY_FL_GLOBAL) |
| 1539 | return tracing_stop(); |
| 1540 | |
| 1541 | raw_spin_lock_irqsave(&tr->start_lock, flags); |
| 1542 | if (tr->stop_count++) |
| 1543 | goto out; |
| 1544 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1545 | buffer = tr->trace_buffer.buffer; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 1546 | if (buffer) |
| 1547 | ring_buffer_record_disable(buffer); |
| 1548 | |
| 1549 | out: |
| 1550 | raw_spin_unlock_irqrestore(&tr->start_lock, flags); |
Steven Rostedt | 0f04870 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1551 | } |
| 1552 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1553 | void trace_stop_cmdline_recording(void); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1554 | |
Steven Rostedt (Red Hat) | 379cfda | 2014-05-30 09:42:39 -0400 | [diff] [blame] | 1555 | static int trace_save_cmdline(struct task_struct *tsk) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1556 | { |
Carsten Emde | a635cf0 | 2009-03-18 09:00:41 +0100 | [diff] [blame] | 1557 | unsigned pid, idx; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1558 | |
| 1559 | if (!tsk->pid || unlikely(tsk->pid > PID_MAX_DEFAULT)) |
Steven Rostedt (Red Hat) | 379cfda | 2014-05-30 09:42:39 -0400 | [diff] [blame] | 1560 | return 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1561 | |
| 1562 | /* |
| 1563 | * It's not the end of the world if we don't get |
| 1564 | * the lock, but we also don't want to spin |
| 1565 | * nor do we want to disable interrupts, |
| 1566 | * so if we miss here, then better luck next time. |
| 1567 | */ |
Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 1568 | if (!arch_spin_trylock(&trace_cmdline_lock)) |
Steven Rostedt (Red Hat) | 379cfda | 2014-05-30 09:42:39 -0400 | [diff] [blame] | 1569 | return 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1570 | |
Yoshihiro YUNOMAE | 939c7a4 | 2014-06-05 10:24:27 +0900 | [diff] [blame] | 1571 | idx = savedcmd->map_pid_to_cmdline[tsk->pid]; |
Thomas Gleixner | 2c7eea4 | 2009-03-18 09:03:19 +0100 | [diff] [blame] | 1572 | if (idx == NO_CMDLINE_MAP) { |
Yoshihiro YUNOMAE | 939c7a4 | 2014-06-05 10:24:27 +0900 | [diff] [blame] | 1573 | idx = (savedcmd->cmdline_idx + 1) % savedcmd->cmdline_num; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1574 | |
Carsten Emde | a635cf0 | 2009-03-18 09:00:41 +0100 | [diff] [blame] | 1575 | /* |
| 1576 | * Check whether the cmdline buffer at idx has a pid |
| 1577 | * mapped. We are going to overwrite that entry so we |
| 1578 | * need to clear the map_pid_to_cmdline. Otherwise we |
| 1579 | * would read the new comm for the old pid. |
| 1580 | */ |
Yoshihiro YUNOMAE | 939c7a4 | 2014-06-05 10:24:27 +0900 | [diff] [blame] | 1581 | pid = savedcmd->map_cmdline_to_pid[idx]; |
Carsten Emde | a635cf0 | 2009-03-18 09:00:41 +0100 | [diff] [blame] | 1582 | if (pid != NO_CMDLINE_MAP) |
Yoshihiro YUNOMAE | 939c7a4 | 2014-06-05 10:24:27 +0900 | [diff] [blame] | 1583 | savedcmd->map_pid_to_cmdline[pid] = NO_CMDLINE_MAP; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1584 | |
Yoshihiro YUNOMAE | 939c7a4 | 2014-06-05 10:24:27 +0900 | [diff] [blame] | 1585 | savedcmd->map_cmdline_to_pid[idx] = tsk->pid; |
| 1586 | savedcmd->map_pid_to_cmdline[tsk->pid] = idx; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1587 | |
Yoshihiro YUNOMAE | 939c7a4 | 2014-06-05 10:24:27 +0900 | [diff] [blame] | 1588 | savedcmd->cmdline_idx = idx; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1589 | } |
| 1590 | |
Yoshihiro YUNOMAE | 939c7a4 | 2014-06-05 10:24:27 +0900 | [diff] [blame] | 1591 | set_cmdline(idx, tsk->comm); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1592 | |
Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 1593 | arch_spin_unlock(&trace_cmdline_lock); |
Steven Rostedt (Red Hat) | 379cfda | 2014-05-30 09:42:39 -0400 | [diff] [blame] | 1594 | |
| 1595 | return 1; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1596 | } |
| 1597 | |
Steven Rostedt (Red Hat) | 4c27e75 | 2014-05-30 10:49:46 -0400 | [diff] [blame] | 1598 | static void __trace_find_cmdline(int pid, char comm[]) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1599 | { |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1600 | unsigned map; |
| 1601 | |
Steven Rostedt | 4ca53085 | 2009-03-16 19:20:15 -0400 | [diff] [blame] | 1602 | if (!pid) { |
| 1603 | strcpy(comm, "<idle>"); |
| 1604 | return; |
| 1605 | } |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1606 | |
Steven Rostedt | 74bf407 | 2010-01-25 15:11:53 -0500 | [diff] [blame] | 1607 | if (WARN_ON_ONCE(pid < 0)) { |
| 1608 | strcpy(comm, "<XXX>"); |
| 1609 | return; |
| 1610 | } |
| 1611 | |
Steven Rostedt | 4ca53085 | 2009-03-16 19:20:15 -0400 | [diff] [blame] | 1612 | if (pid > PID_MAX_DEFAULT) { |
| 1613 | strcpy(comm, "<...>"); |
| 1614 | return; |
| 1615 | } |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1616 | |
Yoshihiro YUNOMAE | 939c7a4 | 2014-06-05 10:24:27 +0900 | [diff] [blame] | 1617 | map = savedcmd->map_pid_to_cmdline[pid]; |
Thomas Gleixner | 50d8875 | 2009-03-18 08:58:44 +0100 | [diff] [blame] | 1618 | if (map != NO_CMDLINE_MAP) |
Yoshihiro YUNOMAE | 939c7a4 | 2014-06-05 10:24:27 +0900 | [diff] [blame] | 1619 | strcpy(comm, get_saved_cmdlines(map)); |
Thomas Gleixner | 50d8875 | 2009-03-18 08:58:44 +0100 | [diff] [blame] | 1620 | else |
| 1621 | strcpy(comm, "<...>"); |
Steven Rostedt (Red Hat) | 4c27e75 | 2014-05-30 10:49:46 -0400 | [diff] [blame] | 1622 | } |
| 1623 | |
| 1624 | void trace_find_cmdline(int pid, char comm[]) |
| 1625 | { |
| 1626 | preempt_disable(); |
| 1627 | arch_spin_lock(&trace_cmdline_lock); |
| 1628 | |
| 1629 | __trace_find_cmdline(pid, comm); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1630 | |
Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 1631 | arch_spin_unlock(&trace_cmdline_lock); |
Heiko Carstens | 5b6045a | 2009-05-26 17:28:02 +0200 | [diff] [blame] | 1632 | preempt_enable(); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1633 | } |
| 1634 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1635 | void tracing_record_cmdline(struct task_struct *tsk) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1636 | { |
Steven Rostedt | 0fb9656 | 2012-05-11 14:25:30 -0400 | [diff] [blame] | 1637 | if (atomic_read(&trace_record_cmdline_disabled) || !tracing_is_on()) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1638 | return; |
| 1639 | |
Steven Rostedt | 7ffbd48 | 2012-10-11 12:14:25 -0400 | [diff] [blame] | 1640 | if (!__this_cpu_read(trace_cmdline_save)) |
| 1641 | return; |
| 1642 | |
Steven Rostedt (Red Hat) | 379cfda | 2014-05-30 09:42:39 -0400 | [diff] [blame] | 1643 | if (trace_save_cmdline(tsk)) |
| 1644 | __this_cpu_write(trace_cmdline_save, false); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1645 | } |
| 1646 | |
Pekka Paalanen | 45dcd8b | 2008-09-16 21:56:41 +0300 | [diff] [blame] | 1647 | void |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 1648 | tracing_generic_entry_update(struct trace_entry *entry, unsigned long flags, |
| 1649 | int pc) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1650 | { |
| 1651 | struct task_struct *tsk = current; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1652 | |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1653 | entry->preempt_count = pc & 0xff; |
| 1654 | entry->pid = (tsk) ? tsk->pid : 0; |
| 1655 | entry->flags = |
Steven Rostedt | 9244489 | 2008-10-24 09:42:59 -0400 | [diff] [blame] | 1656 | #ifdef CONFIG_TRACE_IRQFLAGS_SUPPORT |
Steven Rostedt | 2e2ca15 | 2008-08-01 12:26:40 -0400 | [diff] [blame] | 1657 | (irqs_disabled_flags(flags) ? TRACE_FLAG_IRQS_OFF : 0) | |
Steven Rostedt | 9244489 | 2008-10-24 09:42:59 -0400 | [diff] [blame] | 1658 | #else |
| 1659 | TRACE_FLAG_IRQS_NOSUPPORT | |
| 1660 | #endif |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1661 | ((pc & HARDIRQ_MASK) ? TRACE_FLAG_HARDIRQ : 0) | |
| 1662 | ((pc & SOFTIRQ_MASK) ? TRACE_FLAG_SOFTIRQ : 0) | |
Peter Zijlstra | e5137b5 | 2013-10-04 17:28:26 +0200 | [diff] [blame] | 1663 | (tif_need_resched() ? TRACE_FLAG_NEED_RESCHED : 0) | |
| 1664 | (test_preempt_need_resched() ? TRACE_FLAG_PREEMPT_RESCHED : 0); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1665 | } |
Frederic Weisbecker | f413cdb | 2009-08-07 01:25:54 +0200 | [diff] [blame] | 1666 | EXPORT_SYMBOL_GPL(tracing_generic_entry_update); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1667 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1668 | struct ring_buffer_event * |
| 1669 | trace_buffer_lock_reserve(struct ring_buffer *buffer, |
| 1670 | int type, |
| 1671 | unsigned long len, |
| 1672 | unsigned long flags, int pc) |
Arnaldo Carvalho de Melo | 51a763d | 2009-02-05 16:14:13 -0200 | [diff] [blame] | 1673 | { |
| 1674 | struct ring_buffer_event *event; |
| 1675 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1676 | event = ring_buffer_lock_reserve(buffer, len); |
Arnaldo Carvalho de Melo | 51a763d | 2009-02-05 16:14:13 -0200 | [diff] [blame] | 1677 | if (event != NULL) { |
| 1678 | struct trace_entry *ent = ring_buffer_event_data(event); |
| 1679 | |
| 1680 | tracing_generic_entry_update(ent, flags, pc); |
| 1681 | ent->type = type; |
| 1682 | } |
| 1683 | |
| 1684 | return event; |
| 1685 | } |
Arnaldo Carvalho de Melo | 51a763d | 2009-02-05 16:14:13 -0200 | [diff] [blame] | 1686 | |
Steven Rostedt | 7ffbd48 | 2012-10-11 12:14:25 -0400 | [diff] [blame] | 1687 | void |
| 1688 | __buffer_unlock_commit(struct ring_buffer *buffer, struct ring_buffer_event *event) |
| 1689 | { |
| 1690 | __this_cpu_write(trace_cmdline_save, true); |
| 1691 | ring_buffer_unlock_commit(buffer, event); |
| 1692 | } |
| 1693 | |
Steven Rostedt (Red Hat) | b7f0c95 | 2015-09-25 17:38:44 -0400 | [diff] [blame] | 1694 | void trace_buffer_unlock_commit(struct trace_array *tr, |
| 1695 | struct ring_buffer *buffer, |
| 1696 | struct ring_buffer_event *event, |
| 1697 | unsigned long flags, int pc) |
Arnaldo Carvalho de Melo | 51a763d | 2009-02-05 16:14:13 -0200 | [diff] [blame] | 1698 | { |
Steven Rostedt | 7ffbd48 | 2012-10-11 12:14:25 -0400 | [diff] [blame] | 1699 | __buffer_unlock_commit(buffer, event); |
Arnaldo Carvalho de Melo | 51a763d | 2009-02-05 16:14:13 -0200 | [diff] [blame] | 1700 | |
Steven Rostedt (Red Hat) | 2d34f48 | 2015-09-30 11:45:22 -0400 | [diff] [blame] | 1701 | ftrace_trace_stack(tr, buffer, flags, 6, pc, NULL); |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1702 | ftrace_trace_userstack(buffer, flags, pc); |
Frederic Weisbecker | 07edf71 | 2009-03-22 23:10:46 +0100 | [diff] [blame] | 1703 | } |
Steven Rostedt | 0d5c6e1 | 2012-11-01 20:54:21 -0400 | [diff] [blame] | 1704 | EXPORT_SYMBOL_GPL(trace_buffer_unlock_commit); |
Arnaldo Carvalho de Melo | 51a763d | 2009-02-05 16:14:13 -0200 | [diff] [blame] | 1705 | |
Steven Rostedt (Red Hat) | 2c4a33a | 2014-03-25 23:39:41 -0400 | [diff] [blame] | 1706 | static struct ring_buffer *temp_buffer; |
| 1707 | |
Steven Rostedt | ef5580d | 2009-02-27 19:38:04 -0500 | [diff] [blame] | 1708 | struct ring_buffer_event * |
Steven Rostedt | ccb469a | 2012-08-02 10:32:10 -0400 | [diff] [blame] | 1709 | trace_event_buffer_lock_reserve(struct ring_buffer **current_rb, |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 1710 | struct trace_event_file *trace_file, |
Steven Rostedt | ccb469a | 2012-08-02 10:32:10 -0400 | [diff] [blame] | 1711 | int type, unsigned long len, |
| 1712 | unsigned long flags, int pc) |
| 1713 | { |
Steven Rostedt (Red Hat) | 2c4a33a | 2014-03-25 23:39:41 -0400 | [diff] [blame] | 1714 | struct ring_buffer_event *entry; |
| 1715 | |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 1716 | *current_rb = trace_file->tr->trace_buffer.buffer; |
Steven Rostedt (Red Hat) | 2c4a33a | 2014-03-25 23:39:41 -0400 | [diff] [blame] | 1717 | entry = trace_buffer_lock_reserve(*current_rb, |
Steven Rostedt | ccb469a | 2012-08-02 10:32:10 -0400 | [diff] [blame] | 1718 | type, len, flags, pc); |
Steven Rostedt (Red Hat) | 2c4a33a | 2014-03-25 23:39:41 -0400 | [diff] [blame] | 1719 | /* |
| 1720 | * If tracing is off, but we have triggers enabled |
| 1721 | * we still need to look at the event data. Use the temp_buffer |
| 1722 | * to store the trace event for the tigger to use. It's recusive |
| 1723 | * safe and will not be recorded anywhere. |
| 1724 | */ |
Steven Rostedt (Red Hat) | 5d6ad96 | 2015-05-13 15:12:33 -0400 | [diff] [blame] | 1725 | if (!entry && trace_file->flags & EVENT_FILE_FL_TRIGGER_COND) { |
Steven Rostedt (Red Hat) | 2c4a33a | 2014-03-25 23:39:41 -0400 | [diff] [blame] | 1726 | *current_rb = temp_buffer; |
| 1727 | entry = trace_buffer_lock_reserve(*current_rb, |
| 1728 | type, len, flags, pc); |
| 1729 | } |
| 1730 | return entry; |
Steven Rostedt | ccb469a | 2012-08-02 10:32:10 -0400 | [diff] [blame] | 1731 | } |
| 1732 | EXPORT_SYMBOL_GPL(trace_event_buffer_lock_reserve); |
| 1733 | |
| 1734 | struct ring_buffer_event * |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1735 | trace_current_buffer_lock_reserve(struct ring_buffer **current_rb, |
| 1736 | int type, unsigned long len, |
Steven Rostedt | ef5580d | 2009-02-27 19:38:04 -0500 | [diff] [blame] | 1737 | unsigned long flags, int pc) |
| 1738 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1739 | *current_rb = global_trace.trace_buffer.buffer; |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1740 | return trace_buffer_lock_reserve(*current_rb, |
Steven Rostedt | ef5580d | 2009-02-27 19:38:04 -0500 | [diff] [blame] | 1741 | type, len, flags, pc); |
| 1742 | } |
Steven Rostedt | 94487d6 | 2009-05-05 19:22:53 -0400 | [diff] [blame] | 1743 | EXPORT_SYMBOL_GPL(trace_current_buffer_lock_reserve); |
Steven Rostedt | ef5580d | 2009-02-27 19:38:04 -0500 | [diff] [blame] | 1744 | |
Steven Rostedt (Red Hat) | b7f0c95 | 2015-09-25 17:38:44 -0400 | [diff] [blame] | 1745 | void trace_buffer_unlock_commit_regs(struct trace_array *tr, |
| 1746 | struct ring_buffer *buffer, |
Steven Rostedt | 0d5c6e1 | 2012-11-01 20:54:21 -0400 | [diff] [blame] | 1747 | struct ring_buffer_event *event, |
| 1748 | unsigned long flags, int pc, |
| 1749 | struct pt_regs *regs) |
Masami Hiramatsu | 1fd8df2 | 2011-06-08 16:09:34 +0900 | [diff] [blame] | 1750 | { |
Steven Rostedt | 7ffbd48 | 2012-10-11 12:14:25 -0400 | [diff] [blame] | 1751 | __buffer_unlock_commit(buffer, event); |
Masami Hiramatsu | 1fd8df2 | 2011-06-08 16:09:34 +0900 | [diff] [blame] | 1752 | |
Steven Rostedt (Red Hat) | 2d34f48 | 2015-09-30 11:45:22 -0400 | [diff] [blame] | 1753 | ftrace_trace_stack(tr, buffer, flags, 6, pc, regs); |
Masami Hiramatsu | 1fd8df2 | 2011-06-08 16:09:34 +0900 | [diff] [blame] | 1754 | ftrace_trace_userstack(buffer, flags, pc); |
| 1755 | } |
Steven Rostedt | 0d5c6e1 | 2012-11-01 20:54:21 -0400 | [diff] [blame] | 1756 | EXPORT_SYMBOL_GPL(trace_buffer_unlock_commit_regs); |
Masami Hiramatsu | 1fd8df2 | 2011-06-08 16:09:34 +0900 | [diff] [blame] | 1757 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1758 | void trace_current_buffer_discard_commit(struct ring_buffer *buffer, |
| 1759 | struct ring_buffer_event *event) |
Steven Rostedt | 77d9f46 | 2009-04-02 01:16:59 -0400 | [diff] [blame] | 1760 | { |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1761 | ring_buffer_discard_commit(buffer, event); |
Steven Rostedt | ef5580d | 2009-02-27 19:38:04 -0500 | [diff] [blame] | 1762 | } |
Steven Rostedt | 12acd47 | 2009-04-17 16:01:56 -0400 | [diff] [blame] | 1763 | EXPORT_SYMBOL_GPL(trace_current_buffer_discard_commit); |
Steven Rostedt | ef5580d | 2009-02-27 19:38:04 -0500 | [diff] [blame] | 1764 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1765 | void |
Arnaldo Carvalho de Melo | 7be4215 | 2009-02-05 01:13:37 -0500 | [diff] [blame] | 1766 | trace_function(struct trace_array *tr, |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 1767 | unsigned long ip, unsigned long parent_ip, unsigned long flags, |
| 1768 | int pc) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1769 | { |
Steven Rostedt (Red Hat) | 2425bcb | 2015-05-05 11:45:27 -0400 | [diff] [blame] | 1770 | struct trace_event_call *call = &event_function; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1771 | struct ring_buffer *buffer = tr->trace_buffer.buffer; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1772 | struct ring_buffer_event *event; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1773 | struct ftrace_entry *entry; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1774 | |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 1775 | /* If we are reading the ring buffer, don't trace */ |
Rusty Russell | dd17c8f | 2009-10-29 22:34:15 +0900 | [diff] [blame] | 1776 | if (unlikely(__this_cpu_read(ftrace_cpu_disabled))) |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 1777 | return; |
| 1778 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1779 | event = trace_buffer_lock_reserve(buffer, TRACE_FN, sizeof(*entry), |
Arnaldo Carvalho de Melo | 51a763d | 2009-02-05 16:14:13 -0200 | [diff] [blame] | 1780 | flags, pc); |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1781 | if (!event) |
| 1782 | return; |
| 1783 | entry = ring_buffer_event_data(event); |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1784 | entry->ip = ip; |
| 1785 | entry->parent_ip = parent_ip; |
Tom Zanussi | e1112b4 | 2009-03-31 00:48:49 -0500 | [diff] [blame] | 1786 | |
Tom Zanussi | f306cc8 | 2013-10-24 08:34:17 -0500 | [diff] [blame] | 1787 | if (!call_filter_check_discard(call, entry, buffer, event)) |
Steven Rostedt | 7ffbd48 | 2012-10-11 12:14:25 -0400 | [diff] [blame] | 1788 | __buffer_unlock_commit(buffer, event); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1789 | } |
| 1790 | |
Frederic Weisbecker | c0a0d0d | 2009-07-29 17:51:13 +0200 | [diff] [blame] | 1791 | #ifdef CONFIG_STACKTRACE |
Steven Rostedt | 4a9bd3f | 2011-07-14 16:36:53 -0400 | [diff] [blame] | 1792 | |
| 1793 | #define FTRACE_STACK_MAX_ENTRIES (PAGE_SIZE / sizeof(unsigned long)) |
| 1794 | struct ftrace_stack { |
| 1795 | unsigned long calls[FTRACE_STACK_MAX_ENTRIES]; |
| 1796 | }; |
| 1797 | |
| 1798 | static DEFINE_PER_CPU(struct ftrace_stack, ftrace_stack); |
| 1799 | static DEFINE_PER_CPU(int, ftrace_stack_reserve); |
| 1800 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1801 | static void __ftrace_trace_stack(struct ring_buffer *buffer, |
Steven Rostedt | 5361499 | 2009-01-15 19:12:40 -0500 | [diff] [blame] | 1802 | unsigned long flags, |
Masami Hiramatsu | 1fd8df2 | 2011-06-08 16:09:34 +0900 | [diff] [blame] | 1803 | int skip, int pc, struct pt_regs *regs) |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1804 | { |
Steven Rostedt (Red Hat) | 2425bcb | 2015-05-05 11:45:27 -0400 | [diff] [blame] | 1805 | struct trace_event_call *call = &event_kernel_stack; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 1806 | struct ring_buffer_event *event; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 1807 | struct stack_entry *entry; |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1808 | struct stack_trace trace; |
Steven Rostedt | 4a9bd3f | 2011-07-14 16:36:53 -0400 | [diff] [blame] | 1809 | int use_stack; |
| 1810 | int size = FTRACE_STACK_ENTRIES; |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1811 | |
| 1812 | trace.nr_entries = 0; |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1813 | trace.skip = skip; |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1814 | |
Steven Rostedt | 4a9bd3f | 2011-07-14 16:36:53 -0400 | [diff] [blame] | 1815 | /* |
| 1816 | * Since events can happen in NMIs there's no safe way to |
| 1817 | * use the per cpu ftrace_stacks. We reserve it and if an interrupt |
| 1818 | * or NMI comes in, it will just have to use the default |
| 1819 | * FTRACE_STACK_SIZE. |
| 1820 | */ |
| 1821 | preempt_disable_notrace(); |
| 1822 | |
Shan Wei | 8214652 | 2012-11-19 13:21:01 +0800 | [diff] [blame] | 1823 | use_stack = __this_cpu_inc_return(ftrace_stack_reserve); |
Steven Rostedt | 4a9bd3f | 2011-07-14 16:36:53 -0400 | [diff] [blame] | 1824 | /* |
| 1825 | * We don't need any atomic variables, just a barrier. |
| 1826 | * If an interrupt comes in, we don't care, because it would |
| 1827 | * have exited and put the counter back to what we want. |
| 1828 | * We just need a barrier to keep gcc from moving things |
| 1829 | * around. |
| 1830 | */ |
| 1831 | barrier(); |
| 1832 | if (use_stack == 1) { |
Christoph Lameter | bdffd89 | 2014-04-29 14:17:40 -0500 | [diff] [blame] | 1833 | trace.entries = this_cpu_ptr(ftrace_stack.calls); |
Steven Rostedt | 4a9bd3f | 2011-07-14 16:36:53 -0400 | [diff] [blame] | 1834 | trace.max_entries = FTRACE_STACK_MAX_ENTRIES; |
| 1835 | |
| 1836 | if (regs) |
| 1837 | save_stack_trace_regs(regs, &trace); |
| 1838 | else |
| 1839 | save_stack_trace(&trace); |
| 1840 | |
| 1841 | if (trace.nr_entries > size) |
| 1842 | size = trace.nr_entries; |
| 1843 | } else |
| 1844 | /* From now on, use_stack is a boolean */ |
| 1845 | use_stack = 0; |
| 1846 | |
| 1847 | size *= sizeof(unsigned long); |
| 1848 | |
| 1849 | event = trace_buffer_lock_reserve(buffer, TRACE_STACK, |
| 1850 | sizeof(*entry) + size, flags, pc); |
| 1851 | if (!event) |
| 1852 | goto out; |
| 1853 | entry = ring_buffer_event_data(event); |
| 1854 | |
| 1855 | memset(&entry->caller, 0, size); |
| 1856 | |
| 1857 | if (use_stack) |
| 1858 | memcpy(&entry->caller, trace.entries, |
| 1859 | trace.nr_entries * sizeof(unsigned long)); |
| 1860 | else { |
| 1861 | trace.max_entries = FTRACE_STACK_ENTRIES; |
| 1862 | trace.entries = entry->caller; |
| 1863 | if (regs) |
| 1864 | save_stack_trace_regs(regs, &trace); |
| 1865 | else |
| 1866 | save_stack_trace(&trace); |
| 1867 | } |
| 1868 | |
| 1869 | entry->size = trace.nr_entries; |
| 1870 | |
Tom Zanussi | f306cc8 | 2013-10-24 08:34:17 -0500 | [diff] [blame] | 1871 | if (!call_filter_check_discard(call, entry, buffer, event)) |
Steven Rostedt | 7ffbd48 | 2012-10-11 12:14:25 -0400 | [diff] [blame] | 1872 | __buffer_unlock_commit(buffer, event); |
Steven Rostedt | 4a9bd3f | 2011-07-14 16:36:53 -0400 | [diff] [blame] | 1873 | |
| 1874 | out: |
| 1875 | /* Again, don't let gcc optimize things here */ |
| 1876 | barrier(); |
Shan Wei | 8214652 | 2012-11-19 13:21:01 +0800 | [diff] [blame] | 1877 | __this_cpu_dec(ftrace_stack_reserve); |
Steven Rostedt | 4a9bd3f | 2011-07-14 16:36:53 -0400 | [diff] [blame] | 1878 | preempt_enable_notrace(); |
| 1879 | |
Ingo Molnar | f0a920d | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 1880 | } |
| 1881 | |
Steven Rostedt (Red Hat) | 2d34f48 | 2015-09-30 11:45:22 -0400 | [diff] [blame] | 1882 | static inline void ftrace_trace_stack(struct trace_array *tr, |
| 1883 | struct ring_buffer *buffer, |
Steven Rostedt (Red Hat) | 73dddbb | 2015-09-29 15:38:55 -0400 | [diff] [blame] | 1884 | unsigned long flags, |
| 1885 | int skip, int pc, struct pt_regs *regs) |
Steven Rostedt | 5361499 | 2009-01-15 19:12:40 -0500 | [diff] [blame] | 1886 | { |
Steven Rostedt (Red Hat) | 2d34f48 | 2015-09-30 11:45:22 -0400 | [diff] [blame] | 1887 | if (!(tr->trace_flags & TRACE_ITER_STACKTRACE)) |
Steven Rostedt | 5361499 | 2009-01-15 19:12:40 -0500 | [diff] [blame] | 1888 | return; |
| 1889 | |
Steven Rostedt (Red Hat) | 73dddbb | 2015-09-29 15:38:55 -0400 | [diff] [blame] | 1890 | __ftrace_trace_stack(buffer, flags, skip, pc, regs); |
Steven Rostedt | 5361499 | 2009-01-15 19:12:40 -0500 | [diff] [blame] | 1891 | } |
| 1892 | |
Frederic Weisbecker | c0a0d0d | 2009-07-29 17:51:13 +0200 | [diff] [blame] | 1893 | void __trace_stack(struct trace_array *tr, unsigned long flags, int skip, |
| 1894 | int pc) |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 1895 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 1896 | __ftrace_trace_stack(tr->trace_buffer.buffer, flags, skip, pc, NULL); |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 1897 | } |
| 1898 | |
Steven Rostedt | 0388938 | 2009-12-11 09:48:22 -0500 | [diff] [blame] | 1899 | /** |
| 1900 | * 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] | 1901 | * @skip: Number of functions to skip (helper handlers) |
Steven Rostedt | 0388938 | 2009-12-11 09:48:22 -0500 | [diff] [blame] | 1902 | */ |
Steven Rostedt (Red Hat) | c142be8 | 2013-03-13 09:55:57 -0400 | [diff] [blame] | 1903 | void trace_dump_stack(int skip) |
Steven Rostedt | 0388938 | 2009-12-11 09:48:22 -0500 | [diff] [blame] | 1904 | { |
| 1905 | unsigned long flags; |
| 1906 | |
| 1907 | if (tracing_disabled || tracing_selftest_running) |
Steven Rostedt | e36c545 | 2009-12-14 15:58:33 -0500 | [diff] [blame] | 1908 | return; |
Steven Rostedt | 0388938 | 2009-12-11 09:48:22 -0500 | [diff] [blame] | 1909 | |
| 1910 | local_save_flags(flags); |
| 1911 | |
Steven Rostedt (Red Hat) | c142be8 | 2013-03-13 09:55:57 -0400 | [diff] [blame] | 1912 | /* |
| 1913 | * Skip 3 more, seems to get us at the caller of |
| 1914 | * this function. |
| 1915 | */ |
| 1916 | skip += 3; |
| 1917 | __ftrace_trace_stack(global_trace.trace_buffer.buffer, |
| 1918 | flags, skip, preempt_count(), NULL); |
Steven Rostedt | 0388938 | 2009-12-11 09:48:22 -0500 | [diff] [blame] | 1919 | } |
| 1920 | |
Steven Rostedt | 91e86e5 | 2010-11-10 12:56:12 +0100 | [diff] [blame] | 1921 | static DEFINE_PER_CPU(int, user_stack_count); |
| 1922 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1923 | void |
| 1924 | 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] | 1925 | { |
Steven Rostedt (Red Hat) | 2425bcb | 2015-05-05 11:45:27 -0400 | [diff] [blame] | 1926 | struct trace_event_call *call = &event_user_stack; |
Török Edwin | 8d7c6a9 | 2008-11-23 12:39:06 +0200 | [diff] [blame] | 1927 | struct ring_buffer_event *event; |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 1928 | struct userstack_entry *entry; |
| 1929 | struct stack_trace trace; |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 1930 | |
Steven Rostedt (Red Hat) | 983f938 | 2015-09-30 09:42:05 -0400 | [diff] [blame] | 1931 | if (!(global_trace.trace_flags & TRACE_ITER_USERSTACKTRACE)) |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 1932 | return; |
| 1933 | |
Steven Rostedt | b634587 | 2010-03-12 20:03:30 -0500 | [diff] [blame] | 1934 | /* |
| 1935 | * NMIs can not handle page faults, even with fix ups. |
| 1936 | * The save user stack can (and often does) fault. |
| 1937 | */ |
| 1938 | if (unlikely(in_nmi())) |
| 1939 | return; |
| 1940 | |
Steven Rostedt | 91e86e5 | 2010-11-10 12:56:12 +0100 | [diff] [blame] | 1941 | /* |
| 1942 | * prevent recursion, since the user stack tracing may |
| 1943 | * trigger other kernel events. |
| 1944 | */ |
| 1945 | preempt_disable(); |
| 1946 | if (__this_cpu_read(user_stack_count)) |
| 1947 | goto out; |
| 1948 | |
| 1949 | __this_cpu_inc(user_stack_count); |
| 1950 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1951 | event = trace_buffer_lock_reserve(buffer, TRACE_USER_STACK, |
Arnaldo Carvalho de Melo | 51a763d | 2009-02-05 16:14:13 -0200 | [diff] [blame] | 1952 | sizeof(*entry), flags, pc); |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 1953 | if (!event) |
Li Zefan | 1dbd195 | 2010-12-09 15:47:56 +0800 | [diff] [blame] | 1954 | goto out_drop_count; |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 1955 | entry = ring_buffer_event_data(event); |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 1956 | |
Steven Rostedt | 48659d3 | 2009-09-11 11:36:23 -0400 | [diff] [blame] | 1957 | entry->tgid = current->tgid; |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 1958 | memset(&entry->caller, 0, sizeof(entry->caller)); |
| 1959 | |
| 1960 | trace.nr_entries = 0; |
| 1961 | trace.max_entries = FTRACE_STACK_ENTRIES; |
| 1962 | trace.skip = 0; |
| 1963 | trace.entries = entry->caller; |
| 1964 | |
| 1965 | save_stack_trace_user(&trace); |
Tom Zanussi | f306cc8 | 2013-10-24 08:34:17 -0500 | [diff] [blame] | 1966 | if (!call_filter_check_discard(call, entry, buffer, event)) |
Steven Rostedt | 7ffbd48 | 2012-10-11 12:14:25 -0400 | [diff] [blame] | 1967 | __buffer_unlock_commit(buffer, event); |
Steven Rostedt | 91e86e5 | 2010-11-10 12:56:12 +0100 | [diff] [blame] | 1968 | |
Li Zefan | 1dbd195 | 2010-12-09 15:47:56 +0800 | [diff] [blame] | 1969 | out_drop_count: |
Steven Rostedt | 91e86e5 | 2010-11-10 12:56:12 +0100 | [diff] [blame] | 1970 | __this_cpu_dec(user_stack_count); |
Steven Rostedt | 91e86e5 | 2010-11-10 12:56:12 +0100 | [diff] [blame] | 1971 | out: |
| 1972 | preempt_enable(); |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 1973 | } |
| 1974 | |
Hannes Eder | 4fd2735 | 2009-02-10 19:44:12 +0100 | [diff] [blame] | 1975 | #ifdef UNUSED |
| 1976 | 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] | 1977 | { |
Arnaldo Carvalho de Melo | 7be4215 | 2009-02-05 01:13:37 -0500 | [diff] [blame] | 1978 | ftrace_trace_userstack(tr, flags, preempt_count()); |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 1979 | } |
Hannes Eder | 4fd2735 | 2009-02-10 19:44:12 +0100 | [diff] [blame] | 1980 | #endif /* UNUSED */ |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 1981 | |
Frederic Weisbecker | c0a0d0d | 2009-07-29 17:51:13 +0200 | [diff] [blame] | 1982 | #endif /* CONFIG_STACKTRACE */ |
| 1983 | |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 1984 | /* created for use with alloc_percpu */ |
| 1985 | struct trace_buffer_struct { |
| 1986 | char buffer[TRACE_BUF_SIZE]; |
| 1987 | }; |
| 1988 | |
| 1989 | static struct trace_buffer_struct *trace_percpu_buffer; |
| 1990 | static struct trace_buffer_struct *trace_percpu_sirq_buffer; |
| 1991 | static struct trace_buffer_struct *trace_percpu_irq_buffer; |
| 1992 | static struct trace_buffer_struct *trace_percpu_nmi_buffer; |
| 1993 | |
| 1994 | /* |
| 1995 | * The buffer used is dependent on the context. There is a per cpu |
| 1996 | * buffer for normal context, softirq contex, hard irq context and |
| 1997 | * for NMI context. Thise allows for lockless recording. |
| 1998 | * |
| 1999 | * Note, if the buffers failed to be allocated, then this returns NULL |
| 2000 | */ |
| 2001 | static char *get_trace_buf(void) |
| 2002 | { |
| 2003 | struct trace_buffer_struct *percpu_buffer; |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 2004 | |
| 2005 | /* |
| 2006 | * If we have allocated per cpu buffers, then we do not |
| 2007 | * need to do any locking. |
| 2008 | */ |
| 2009 | if (in_nmi()) |
| 2010 | percpu_buffer = trace_percpu_nmi_buffer; |
| 2011 | else if (in_irq()) |
| 2012 | percpu_buffer = trace_percpu_irq_buffer; |
| 2013 | else if (in_softirq()) |
| 2014 | percpu_buffer = trace_percpu_sirq_buffer; |
| 2015 | else |
| 2016 | percpu_buffer = trace_percpu_buffer; |
| 2017 | |
| 2018 | if (!percpu_buffer) |
| 2019 | return NULL; |
| 2020 | |
Shan Wei | d8a0349 | 2012-11-13 09:53:04 +0800 | [diff] [blame] | 2021 | return this_cpu_ptr(&percpu_buffer->buffer[0]); |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 2022 | } |
| 2023 | |
| 2024 | static int alloc_percpu_trace_buffer(void) |
| 2025 | { |
| 2026 | struct trace_buffer_struct *buffers; |
| 2027 | struct trace_buffer_struct *sirq_buffers; |
| 2028 | struct trace_buffer_struct *irq_buffers; |
| 2029 | struct trace_buffer_struct *nmi_buffers; |
| 2030 | |
| 2031 | buffers = alloc_percpu(struct trace_buffer_struct); |
| 2032 | if (!buffers) |
| 2033 | goto err_warn; |
| 2034 | |
| 2035 | sirq_buffers = alloc_percpu(struct trace_buffer_struct); |
| 2036 | if (!sirq_buffers) |
| 2037 | goto err_sirq; |
| 2038 | |
| 2039 | irq_buffers = alloc_percpu(struct trace_buffer_struct); |
| 2040 | if (!irq_buffers) |
| 2041 | goto err_irq; |
| 2042 | |
| 2043 | nmi_buffers = alloc_percpu(struct trace_buffer_struct); |
| 2044 | if (!nmi_buffers) |
| 2045 | goto err_nmi; |
| 2046 | |
| 2047 | trace_percpu_buffer = buffers; |
| 2048 | trace_percpu_sirq_buffer = sirq_buffers; |
| 2049 | trace_percpu_irq_buffer = irq_buffers; |
| 2050 | trace_percpu_nmi_buffer = nmi_buffers; |
| 2051 | |
| 2052 | return 0; |
| 2053 | |
| 2054 | err_nmi: |
| 2055 | free_percpu(irq_buffers); |
| 2056 | err_irq: |
| 2057 | free_percpu(sirq_buffers); |
| 2058 | err_sirq: |
| 2059 | free_percpu(buffers); |
| 2060 | err_warn: |
| 2061 | WARN(1, "Could not allocate percpu trace_printk buffer"); |
| 2062 | return -ENOMEM; |
| 2063 | } |
| 2064 | |
Steven Rostedt | 8169883 | 2012-10-11 10:15:05 -0400 | [diff] [blame] | 2065 | static int buffers_allocated; |
| 2066 | |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 2067 | void trace_printk_init_buffers(void) |
| 2068 | { |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 2069 | if (buffers_allocated) |
| 2070 | return; |
| 2071 | |
| 2072 | if (alloc_percpu_trace_buffer()) |
| 2073 | return; |
| 2074 | |
Steven Rostedt | 2184db4 | 2014-05-28 13:14:40 -0400 | [diff] [blame] | 2075 | /* trace_printk() is for debug use only. Don't use it in production. */ |
| 2076 | |
Borislav Petkov | 69a1c99 | 2015-01-27 17:17:20 +0100 | [diff] [blame] | 2077 | pr_warning("\n"); |
| 2078 | pr_warning("**********************************************************\n"); |
Steven Rostedt | 2184db4 | 2014-05-28 13:14:40 -0400 | [diff] [blame] | 2079 | pr_warning("** NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE **\n"); |
| 2080 | pr_warning("** **\n"); |
| 2081 | pr_warning("** trace_printk() being used. Allocating extra memory. **\n"); |
| 2082 | pr_warning("** **\n"); |
| 2083 | 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] | 2084 | pr_warning("** unsafe for production use. **\n"); |
Steven Rostedt | 2184db4 | 2014-05-28 13:14:40 -0400 | [diff] [blame] | 2085 | pr_warning("** **\n"); |
| 2086 | pr_warning("** If you see this message and you are not debugging **\n"); |
| 2087 | pr_warning("** the kernel, report this immediately to your vendor! **\n"); |
| 2088 | pr_warning("** **\n"); |
| 2089 | pr_warning("** NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE **\n"); |
| 2090 | pr_warning("**********************************************************\n"); |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 2091 | |
Steven Rostedt | b382ede6 | 2012-10-10 21:44:34 -0400 | [diff] [blame] | 2092 | /* Expand the buffers to set size */ |
| 2093 | tracing_update_buffers(); |
| 2094 | |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 2095 | buffers_allocated = 1; |
Steven Rostedt | 8169883 | 2012-10-11 10:15:05 -0400 | [diff] [blame] | 2096 | |
| 2097 | /* |
| 2098 | * trace_printk_init_buffers() can be called by modules. |
| 2099 | * If that happens, then we need to start cmdline recording |
| 2100 | * directly here. If the global_trace.buffer is already |
| 2101 | * allocated here, then this was called by module code. |
| 2102 | */ |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2103 | if (global_trace.trace_buffer.buffer) |
Steven Rostedt | 8169883 | 2012-10-11 10:15:05 -0400 | [diff] [blame] | 2104 | tracing_start_cmdline_record(); |
| 2105 | } |
| 2106 | |
| 2107 | void trace_printk_start_comm(void) |
| 2108 | { |
| 2109 | /* Start tracing comms if trace printk is set */ |
| 2110 | if (!buffers_allocated) |
| 2111 | return; |
| 2112 | tracing_start_cmdline_record(); |
| 2113 | } |
| 2114 | |
| 2115 | static void trace_printk_start_stop_comm(int enabled) |
| 2116 | { |
| 2117 | if (!buffers_allocated) |
| 2118 | return; |
| 2119 | |
| 2120 | if (enabled) |
| 2121 | tracing_start_cmdline_record(); |
| 2122 | else |
| 2123 | tracing_stop_cmdline_record(); |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 2124 | } |
| 2125 | |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 2126 | /** |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 2127 | * trace_vbprintk - write binary msg to tracing buffer |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 2128 | * |
| 2129 | */ |
Steven Rostedt | 40ce74f | 2009-03-19 14:03:53 -0400 | [diff] [blame] | 2130 | int trace_vbprintk(unsigned long ip, const char *fmt, va_list args) |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 2131 | { |
Steven Rostedt (Red Hat) | 2425bcb | 2015-05-05 11:45:27 -0400 | [diff] [blame] | 2132 | struct trace_event_call *call = &event_bprint; |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 2133 | struct ring_buffer_event *event; |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 2134 | struct ring_buffer *buffer; |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 2135 | struct trace_array *tr = &global_trace; |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 2136 | struct bprint_entry *entry; |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 2137 | unsigned long flags; |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 2138 | char *tbuffer; |
| 2139 | int len = 0, size, pc; |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 2140 | |
| 2141 | if (unlikely(tracing_selftest_running || tracing_disabled)) |
| 2142 | return 0; |
| 2143 | |
| 2144 | /* Don't pollute graph traces with trace_vprintk internals */ |
| 2145 | pause_graph_tracing(); |
| 2146 | |
| 2147 | pc = preempt_count(); |
Steven Rostedt | 5168ae5 | 2010-06-03 09:36:50 -0400 | [diff] [blame] | 2148 | preempt_disable_notrace(); |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 2149 | |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 2150 | tbuffer = get_trace_buf(); |
| 2151 | if (!tbuffer) { |
| 2152 | len = 0; |
| 2153 | goto out; |
| 2154 | } |
| 2155 | |
| 2156 | len = vbin_printf((u32 *)tbuffer, TRACE_BUF_SIZE/sizeof(int), fmt, args); |
| 2157 | |
| 2158 | if (len > TRACE_BUF_SIZE/sizeof(int) || len < 0) |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 2159 | goto out; |
| 2160 | |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 2161 | local_save_flags(flags); |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 2162 | size = sizeof(*entry) + sizeof(u32) * len; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2163 | buffer = tr->trace_buffer.buffer; |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 2164 | event = trace_buffer_lock_reserve(buffer, TRACE_BPRINT, size, |
| 2165 | flags, pc); |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 2166 | if (!event) |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 2167 | goto out; |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 2168 | entry = ring_buffer_event_data(event); |
| 2169 | entry->ip = ip; |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 2170 | entry->fmt = fmt; |
| 2171 | |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 2172 | memcpy(entry->buf, tbuffer, sizeof(u32) * len); |
Tom Zanussi | f306cc8 | 2013-10-24 08:34:17 -0500 | [diff] [blame] | 2173 | if (!call_filter_check_discard(call, entry, buffer, event)) { |
Steven Rostedt | 7ffbd48 | 2012-10-11 12:14:25 -0400 | [diff] [blame] | 2174 | __buffer_unlock_commit(buffer, event); |
Steven Rostedt (Red Hat) | 2d34f48 | 2015-09-30 11:45:22 -0400 | [diff] [blame] | 2175 | ftrace_trace_stack(tr, buffer, flags, 6, pc, NULL); |
Steven Rostedt | d931369 | 2010-01-06 17:27:11 -0500 | [diff] [blame] | 2176 | } |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 2177 | |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 2178 | out: |
Steven Rostedt | 5168ae5 | 2010-06-03 09:36:50 -0400 | [diff] [blame] | 2179 | preempt_enable_notrace(); |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 2180 | unpause_graph_tracing(); |
| 2181 | |
| 2182 | return len; |
| 2183 | } |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 2184 | EXPORT_SYMBOL_GPL(trace_vbprintk); |
| 2185 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2186 | static int |
| 2187 | __trace_array_vprintk(struct ring_buffer *buffer, |
| 2188 | unsigned long ip, const char *fmt, va_list args) |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 2189 | { |
Steven Rostedt (Red Hat) | 2425bcb | 2015-05-05 11:45:27 -0400 | [diff] [blame] | 2190 | struct trace_event_call *call = &event_print; |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 2191 | struct ring_buffer_event *event; |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 2192 | int len = 0, size, pc; |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 2193 | struct print_entry *entry; |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 2194 | unsigned long flags; |
| 2195 | char *tbuffer; |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 2196 | |
| 2197 | if (tracing_disabled || tracing_selftest_running) |
| 2198 | return 0; |
| 2199 | |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 2200 | /* Don't pollute graph traces with trace_vprintk internals */ |
| 2201 | pause_graph_tracing(); |
| 2202 | |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 2203 | pc = preempt_count(); |
| 2204 | preempt_disable_notrace(); |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 2205 | |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 2206 | |
| 2207 | tbuffer = get_trace_buf(); |
| 2208 | if (!tbuffer) { |
| 2209 | len = 0; |
| 2210 | goto out; |
| 2211 | } |
| 2212 | |
Dan Carpenter | 3558a5a | 2014-11-27 18:57:52 +0300 | [diff] [blame] | 2213 | len = vscnprintf(tbuffer, TRACE_BUF_SIZE, fmt, args); |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 2214 | |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 2215 | local_save_flags(flags); |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 2216 | size = sizeof(*entry) + len + 1; |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 2217 | event = trace_buffer_lock_reserve(buffer, TRACE_PRINT, size, |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 2218 | flags, pc); |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 2219 | if (!event) |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 2220 | goto out; |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 2221 | entry = ring_buffer_event_data(event); |
Carsten Emde | c13d2f7 | 2009-11-16 20:56:13 +0100 | [diff] [blame] | 2222 | entry->ip = ip; |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 2223 | |
Dan Carpenter | 3558a5a | 2014-11-27 18:57:52 +0300 | [diff] [blame] | 2224 | memcpy(&entry->buf, tbuffer, len + 1); |
Tom Zanussi | f306cc8 | 2013-10-24 08:34:17 -0500 | [diff] [blame] | 2225 | if (!call_filter_check_discard(call, entry, buffer, event)) { |
Steven Rostedt | 7ffbd48 | 2012-10-11 12:14:25 -0400 | [diff] [blame] | 2226 | __buffer_unlock_commit(buffer, event); |
Steven Rostedt (Red Hat) | 2d34f48 | 2015-09-30 11:45:22 -0400 | [diff] [blame] | 2227 | ftrace_trace_stack(&global_trace, buffer, flags, 6, pc, NULL); |
Steven Rostedt | d931369 | 2010-01-06 17:27:11 -0500 | [diff] [blame] | 2228 | } |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 2229 | out: |
| 2230 | preempt_enable_notrace(); |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 2231 | unpause_graph_tracing(); |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 2232 | |
| 2233 | return len; |
| 2234 | } |
Steven Rostedt | 659372d | 2009-09-03 19:11:07 -0400 | [diff] [blame] | 2235 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2236 | int trace_array_vprintk(struct trace_array *tr, |
| 2237 | unsigned long ip, const char *fmt, va_list args) |
| 2238 | { |
| 2239 | return __trace_array_vprintk(tr->trace_buffer.buffer, ip, fmt, args); |
| 2240 | } |
| 2241 | |
| 2242 | int trace_array_printk(struct trace_array *tr, |
| 2243 | unsigned long ip, const char *fmt, ...) |
| 2244 | { |
| 2245 | int ret; |
| 2246 | va_list ap; |
| 2247 | |
Steven Rostedt (Red Hat) | 983f938 | 2015-09-30 09:42:05 -0400 | [diff] [blame] | 2248 | if (!(global_trace.trace_flags & TRACE_ITER_PRINTK)) |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2249 | return 0; |
| 2250 | |
| 2251 | va_start(ap, fmt); |
| 2252 | ret = trace_array_vprintk(tr, ip, fmt, ap); |
| 2253 | va_end(ap); |
| 2254 | return ret; |
| 2255 | } |
| 2256 | |
| 2257 | int trace_array_printk_buf(struct ring_buffer *buffer, |
| 2258 | unsigned long ip, const char *fmt, ...) |
| 2259 | { |
| 2260 | int ret; |
| 2261 | va_list ap; |
| 2262 | |
Steven Rostedt (Red Hat) | 983f938 | 2015-09-30 09:42:05 -0400 | [diff] [blame] | 2263 | if (!(global_trace.trace_flags & TRACE_ITER_PRINTK)) |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2264 | return 0; |
| 2265 | |
| 2266 | va_start(ap, fmt); |
| 2267 | ret = __trace_array_vprintk(buffer, ip, fmt, ap); |
| 2268 | va_end(ap); |
| 2269 | return ret; |
| 2270 | } |
| 2271 | |
Steven Rostedt | 659372d | 2009-09-03 19:11:07 -0400 | [diff] [blame] | 2272 | int trace_vprintk(unsigned long ip, const char *fmt, va_list args) |
| 2273 | { |
Steven Rostedt | a813a15 | 2009-10-09 01:41:35 -0400 | [diff] [blame] | 2274 | return trace_array_vprintk(&global_trace, ip, fmt, args); |
Steven Rostedt | 659372d | 2009-09-03 19:11:07 -0400 | [diff] [blame] | 2275 | } |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 2276 | EXPORT_SYMBOL_GPL(trace_vprintk); |
| 2277 | |
Robert Richter | e2ac8ef | 2008-11-12 12:59:32 +0100 | [diff] [blame] | 2278 | static void trace_iterator_increment(struct trace_iterator *iter) |
Steven Rostedt | 5a90f57 | 2008-09-03 17:42:51 -0400 | [diff] [blame] | 2279 | { |
Steven Rostedt | 6d158a8 | 2012-06-27 20:46:14 -0400 | [diff] [blame] | 2280 | struct ring_buffer_iter *buf_iter = trace_buffer_iter(iter, iter->cpu); |
| 2281 | |
Steven Rostedt | 5a90f57 | 2008-09-03 17:42:51 -0400 | [diff] [blame] | 2282 | iter->idx++; |
Steven Rostedt | 6d158a8 | 2012-06-27 20:46:14 -0400 | [diff] [blame] | 2283 | if (buf_iter) |
| 2284 | ring_buffer_read(buf_iter, NULL); |
Steven Rostedt | 5a90f57 | 2008-09-03 17:42:51 -0400 | [diff] [blame] | 2285 | } |
| 2286 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 2287 | static struct trace_entry * |
Steven Rostedt | bc21b47 | 2010-03-31 19:49:26 -0400 | [diff] [blame] | 2288 | peek_next_entry(struct trace_iterator *iter, int cpu, u64 *ts, |
| 2289 | unsigned long *lost_events) |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2290 | { |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2291 | struct ring_buffer_event *event; |
Steven Rostedt | 6d158a8 | 2012-06-27 20:46:14 -0400 | [diff] [blame] | 2292 | struct ring_buffer_iter *buf_iter = trace_buffer_iter(iter, cpu); |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2293 | |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 2294 | if (buf_iter) |
| 2295 | event = ring_buffer_iter_peek(buf_iter, ts); |
| 2296 | else |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2297 | event = ring_buffer_peek(iter->trace_buffer->buffer, cpu, ts, |
Steven Rostedt | bc21b47 | 2010-03-31 19:49:26 -0400 | [diff] [blame] | 2298 | lost_events); |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 2299 | |
Steven Rostedt | 4a9bd3f | 2011-07-14 16:36:53 -0400 | [diff] [blame] | 2300 | if (event) { |
| 2301 | iter->ent_size = ring_buffer_event_length(event); |
| 2302 | return ring_buffer_event_data(event); |
| 2303 | } |
| 2304 | iter->ent_size = 0; |
| 2305 | return NULL; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2306 | } |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 2307 | |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2308 | static struct trace_entry * |
Steven Rostedt | bc21b47 | 2010-03-31 19:49:26 -0400 | [diff] [blame] | 2309 | __find_next_entry(struct trace_iterator *iter, int *ent_cpu, |
| 2310 | unsigned long *missing_events, u64 *ent_ts) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2311 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2312 | struct ring_buffer *buffer = iter->trace_buffer->buffer; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2313 | struct trace_entry *ent, *next = NULL; |
Lai Jiangshan | aa27497 | 2010-04-05 17:11:05 +0800 | [diff] [blame] | 2314 | unsigned long lost_events = 0, next_lost = 0; |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 2315 | int cpu_file = iter->cpu_file; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2316 | u64 next_ts = 0, ts; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2317 | int next_cpu = -1; |
Steven Rostedt | 12b5da3 | 2012-03-27 10:43:28 -0400 | [diff] [blame] | 2318 | int next_size = 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2319 | int cpu; |
| 2320 | |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 2321 | /* |
| 2322 | * If we are in a per_cpu trace file, don't bother by iterating over |
| 2323 | * all cpu and peek directly. |
| 2324 | */ |
Steven Rostedt | ae3b509 | 2013-01-23 15:22:59 -0500 | [diff] [blame] | 2325 | if (cpu_file > RING_BUFFER_ALL_CPUS) { |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 2326 | if (ring_buffer_empty_cpu(buffer, cpu_file)) |
| 2327 | return NULL; |
Steven Rostedt | bc21b47 | 2010-03-31 19:49:26 -0400 | [diff] [blame] | 2328 | ent = peek_next_entry(iter, cpu_file, ent_ts, missing_events); |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 2329 | if (ent_cpu) |
| 2330 | *ent_cpu = cpu_file; |
| 2331 | |
| 2332 | return ent; |
| 2333 | } |
| 2334 | |
Steven Rostedt | ab46428 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 2335 | for_each_tracing_cpu(cpu) { |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2336 | |
| 2337 | if (ring_buffer_empty_cpu(buffer, cpu)) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2338 | continue; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2339 | |
Steven Rostedt | bc21b47 | 2010-03-31 19:49:26 -0400 | [diff] [blame] | 2340 | ent = peek_next_entry(iter, cpu, &ts, &lost_events); |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2341 | |
Ingo Molnar | cdd31cd2 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2342 | /* |
| 2343 | * Pick the entry with the smallest timestamp: |
| 2344 | */ |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2345 | if (ent && (!next || ts < next_ts)) { |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2346 | next = ent; |
| 2347 | next_cpu = cpu; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2348 | next_ts = ts; |
Steven Rostedt | bc21b47 | 2010-03-31 19:49:26 -0400 | [diff] [blame] | 2349 | next_lost = lost_events; |
Steven Rostedt | 12b5da3 | 2012-03-27 10:43:28 -0400 | [diff] [blame] | 2350 | next_size = iter->ent_size; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2351 | } |
| 2352 | } |
| 2353 | |
Steven Rostedt | 12b5da3 | 2012-03-27 10:43:28 -0400 | [diff] [blame] | 2354 | iter->ent_size = next_size; |
| 2355 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2356 | if (ent_cpu) |
| 2357 | *ent_cpu = next_cpu; |
| 2358 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2359 | if (ent_ts) |
| 2360 | *ent_ts = next_ts; |
| 2361 | |
Steven Rostedt | bc21b47 | 2010-03-31 19:49:26 -0400 | [diff] [blame] | 2362 | if (missing_events) |
| 2363 | *missing_events = next_lost; |
| 2364 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2365 | return next; |
| 2366 | } |
| 2367 | |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2368 | /* Find the next real entry, without updating the iterator itself */ |
Frederic Weisbecker | c4a8e8b | 2009-02-02 20:29:21 -0200 | [diff] [blame] | 2369 | struct trace_entry *trace_find_next_entry(struct trace_iterator *iter, |
| 2370 | int *ent_cpu, u64 *ent_ts) |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2371 | { |
Steven Rostedt | bc21b47 | 2010-03-31 19:49:26 -0400 | [diff] [blame] | 2372 | return __find_next_entry(iter, ent_cpu, NULL, ent_ts); |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2373 | } |
Ingo Molnar | 8c523a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2374 | |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2375 | /* 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] | 2376 | void *trace_find_next_entry_inc(struct trace_iterator *iter) |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2377 | { |
Steven Rostedt | bc21b47 | 2010-03-31 19:49:26 -0400 | [diff] [blame] | 2378 | iter->ent = __find_next_entry(iter, &iter->cpu, |
| 2379 | &iter->lost_events, &iter->ts); |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2380 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2381 | if (iter->ent) |
Robert Richter | e2ac8ef | 2008-11-12 12:59:32 +0100 | [diff] [blame] | 2382 | trace_iterator_increment(iter); |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2383 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2384 | return iter->ent ? iter : NULL; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2385 | } |
| 2386 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 2387 | static void trace_consume(struct trace_iterator *iter) |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2388 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2389 | ring_buffer_consume(iter->trace_buffer->buffer, iter->cpu, &iter->ts, |
Steven Rostedt | bc21b47 | 2010-03-31 19:49:26 -0400 | [diff] [blame] | 2390 | &iter->lost_events); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2391 | } |
| 2392 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 2393 | 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] | 2394 | { |
| 2395 | struct trace_iterator *iter = m->private; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2396 | int i = (int)*pos; |
Ingo Molnar | 4e3c333 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 2397 | void *ent; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2398 | |
Steven Rostedt | a63ce5b | 2009-12-07 09:11:39 -0500 | [diff] [blame] | 2399 | WARN_ON_ONCE(iter->leftover); |
| 2400 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2401 | (*pos)++; |
| 2402 | |
| 2403 | /* can't go backwards */ |
| 2404 | if (iter->idx > i) |
| 2405 | return NULL; |
| 2406 | |
| 2407 | if (iter->idx < 0) |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 2408 | ent = trace_find_next_entry_inc(iter); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2409 | else |
| 2410 | ent = iter; |
| 2411 | |
| 2412 | while (ent && iter->idx < i) |
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 | |
| 2415 | iter->pos = *pos; |
| 2416 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2417 | return ent; |
| 2418 | } |
| 2419 | |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 2420 | void tracing_iter_reset(struct trace_iterator *iter, int cpu) |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 2421 | { |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 2422 | struct ring_buffer_event *event; |
| 2423 | struct ring_buffer_iter *buf_iter; |
| 2424 | unsigned long entries = 0; |
| 2425 | u64 ts; |
| 2426 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2427 | per_cpu_ptr(iter->trace_buffer->data, cpu)->skipped_entries = 0; |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 2428 | |
Steven Rostedt | 6d158a8 | 2012-06-27 20:46:14 -0400 | [diff] [blame] | 2429 | buf_iter = trace_buffer_iter(iter, cpu); |
| 2430 | if (!buf_iter) |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 2431 | return; |
| 2432 | |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 2433 | ring_buffer_iter_reset(buf_iter); |
| 2434 | |
| 2435 | /* |
| 2436 | * We could have the case with the max latency tracers |
| 2437 | * that a reset never took place on a cpu. This is evident |
| 2438 | * by the timestamp being before the start of the buffer. |
| 2439 | */ |
| 2440 | while ((event = ring_buffer_iter_peek(buf_iter, &ts))) { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2441 | if (ts >= iter->trace_buffer->time_start) |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 2442 | break; |
| 2443 | entries++; |
| 2444 | ring_buffer_read(buf_iter, NULL); |
| 2445 | } |
| 2446 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2447 | per_cpu_ptr(iter->trace_buffer->data, cpu)->skipped_entries = entries; |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 2448 | } |
| 2449 | |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 2450 | /* |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 2451 | * The current tracer is copied to avoid a global locking |
| 2452 | * all around. |
| 2453 | */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2454 | static void *s_start(struct seq_file *m, loff_t *pos) |
| 2455 | { |
| 2456 | struct trace_iterator *iter = m->private; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 2457 | struct trace_array *tr = iter->tr; |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 2458 | int cpu_file = iter->cpu_file; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2459 | void *p = NULL; |
| 2460 | loff_t l = 0; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 2461 | int cpu; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2462 | |
Hiraku Toyooka | 2fd196e | 2012-12-26 11:52:52 +0900 | [diff] [blame] | 2463 | /* |
| 2464 | * copy the tracer to avoid using a global lock all around. |
| 2465 | * iter->trace is a copy of current_trace, the pointer to the |
| 2466 | * name may be used instead of a strcmp(), as iter->trace->name |
| 2467 | * will point to the same string as current_trace->name. |
| 2468 | */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2469 | mutex_lock(&trace_types_lock); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 2470 | if (unlikely(tr->current_trace && iter->trace->name != tr->current_trace->name)) |
| 2471 | *iter->trace = *tr->current_trace; |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 2472 | mutex_unlock(&trace_types_lock); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2473 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2474 | #ifdef CONFIG_TRACER_MAX_TRACE |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 2475 | if (iter->snapshot && iter->trace->use_max_tr) |
| 2476 | return ERR_PTR(-EBUSY); |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2477 | #endif |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 2478 | |
| 2479 | if (!iter->snapshot) |
| 2480 | atomic_inc(&trace_record_cmdline_disabled); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2481 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2482 | if (*pos != iter->pos) { |
| 2483 | iter->ent = NULL; |
| 2484 | iter->cpu = 0; |
| 2485 | iter->idx = -1; |
| 2486 | |
Steven Rostedt | ae3b509 | 2013-01-23 15:22:59 -0500 | [diff] [blame] | 2487 | if (cpu_file == RING_BUFFER_ALL_CPUS) { |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 2488 | for_each_tracing_cpu(cpu) |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 2489 | tracing_iter_reset(iter, cpu); |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 2490 | } else |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 2491 | tracing_iter_reset(iter, cpu_file); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2492 | |
Lai Jiangshan | ac91d85 | 2010-03-02 17:54:50 +0800 | [diff] [blame] | 2493 | iter->leftover = 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2494 | for (p = iter; p && l < *pos; p = s_next(m, p, &l)) |
| 2495 | ; |
| 2496 | |
| 2497 | } else { |
Steven Rostedt | a63ce5b | 2009-12-07 09:11:39 -0500 | [diff] [blame] | 2498 | /* |
| 2499 | * If we overflowed the seq_file before, then we want |
| 2500 | * to just reuse the trace_seq buffer again. |
| 2501 | */ |
| 2502 | if (iter->leftover) |
| 2503 | p = iter; |
| 2504 | else { |
| 2505 | l = *pos - 1; |
| 2506 | p = s_next(m, p, &l); |
| 2507 | } |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2508 | } |
| 2509 | |
Lai Jiangshan | 4f53596 | 2009-05-18 19:35:34 +0800 | [diff] [blame] | 2510 | trace_event_read_lock(); |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 2511 | trace_access_lock(cpu_file); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2512 | return p; |
| 2513 | } |
| 2514 | |
| 2515 | static void s_stop(struct seq_file *m, void *p) |
| 2516 | { |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 2517 | struct trace_iterator *iter = m->private; |
| 2518 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2519 | #ifdef CONFIG_TRACER_MAX_TRACE |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 2520 | if (iter->snapshot && iter->trace->use_max_tr) |
| 2521 | return; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2522 | #endif |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 2523 | |
| 2524 | if (!iter->snapshot) |
| 2525 | atomic_dec(&trace_record_cmdline_disabled); |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2526 | |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 2527 | trace_access_unlock(iter->cpu_file); |
Lai Jiangshan | 4f53596 | 2009-05-18 19:35:34 +0800 | [diff] [blame] | 2528 | trace_event_read_unlock(); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2529 | } |
| 2530 | |
Steven Rostedt | 39eaf7e | 2011-11-17 10:35:16 -0500 | [diff] [blame] | 2531 | static void |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2532 | get_total_entries(struct trace_buffer *buf, |
| 2533 | unsigned long *total, unsigned long *entries) |
Steven Rostedt | 39eaf7e | 2011-11-17 10:35:16 -0500 | [diff] [blame] | 2534 | { |
| 2535 | unsigned long count; |
| 2536 | int cpu; |
| 2537 | |
| 2538 | *total = 0; |
| 2539 | *entries = 0; |
| 2540 | |
| 2541 | for_each_tracing_cpu(cpu) { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2542 | count = ring_buffer_entries_cpu(buf->buffer, cpu); |
Steven Rostedt | 39eaf7e | 2011-11-17 10:35:16 -0500 | [diff] [blame] | 2543 | /* |
| 2544 | * If this buffer has skipped entries, then we hold all |
| 2545 | * entries for the trace and we need to ignore the |
| 2546 | * ones before the time stamp. |
| 2547 | */ |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2548 | if (per_cpu_ptr(buf->data, cpu)->skipped_entries) { |
| 2549 | count -= per_cpu_ptr(buf->data, cpu)->skipped_entries; |
Steven Rostedt | 39eaf7e | 2011-11-17 10:35:16 -0500 | [diff] [blame] | 2550 | /* total is the same as the entries */ |
| 2551 | *total += count; |
| 2552 | } else |
| 2553 | *total += count + |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2554 | ring_buffer_overrun_cpu(buf->buffer, cpu); |
Steven Rostedt | 39eaf7e | 2011-11-17 10:35:16 -0500 | [diff] [blame] | 2555 | *entries += count; |
| 2556 | } |
| 2557 | } |
| 2558 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 2559 | static void print_lat_help_header(struct seq_file *m) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2560 | { |
Rasmus Villemoes | d79ac28 | 2014-11-08 21:42:11 +0100 | [diff] [blame] | 2561 | seq_puts(m, "# _------=> CPU# \n" |
| 2562 | "# / _-----=> irqs-off \n" |
| 2563 | "# | / _----=> need-resched \n" |
| 2564 | "# || / _---=> hardirq/softirq \n" |
| 2565 | "# ||| / _--=> preempt-depth \n" |
| 2566 | "# |||| / delay \n" |
| 2567 | "# cmd pid ||||| time | caller \n" |
| 2568 | "# \\ / ||||| \\ | / \n"); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2569 | } |
| 2570 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2571 | 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] | 2572 | { |
Steven Rostedt | 39eaf7e | 2011-11-17 10:35:16 -0500 | [diff] [blame] | 2573 | unsigned long total; |
| 2574 | unsigned long entries; |
| 2575 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2576 | get_total_entries(buf, &total, &entries); |
Steven Rostedt | 39eaf7e | 2011-11-17 10:35:16 -0500 | [diff] [blame] | 2577 | seq_printf(m, "# entries-in-buffer/entries-written: %lu/%lu #P:%d\n", |
| 2578 | entries, total, num_online_cpus()); |
| 2579 | seq_puts(m, "#\n"); |
| 2580 | } |
| 2581 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2582 | 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] | 2583 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2584 | print_event_info(buf, m); |
Rasmus Villemoes | d79ac28 | 2014-11-08 21:42:11 +0100 | [diff] [blame] | 2585 | seq_puts(m, "# TASK-PID CPU# TIMESTAMP FUNCTION\n" |
| 2586 | "# | | | | |\n"); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2587 | } |
| 2588 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2589 | 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] | 2590 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2591 | print_event_info(buf, m); |
Rasmus Villemoes | d79ac28 | 2014-11-08 21:42:11 +0100 | [diff] [blame] | 2592 | seq_puts(m, "# _-----=> irqs-off\n" |
| 2593 | "# / _----=> need-resched\n" |
| 2594 | "# | / _---=> hardirq/softirq\n" |
| 2595 | "# || / _--=> preempt-depth\n" |
| 2596 | "# ||| / delay\n" |
| 2597 | "# TASK-PID CPU# |||| TIMESTAMP FUNCTION\n" |
| 2598 | "# | | | |||| | |\n"); |
Steven Rostedt | 77271ce | 2011-11-17 09:34:33 -0500 | [diff] [blame] | 2599 | } |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2600 | |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 2601 | void |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2602 | print_trace_header(struct seq_file *m, struct trace_iterator *iter) |
| 2603 | { |
Steven Rostedt (Red Hat) | 983f938 | 2015-09-30 09:42:05 -0400 | [diff] [blame] | 2604 | unsigned long sym_flags = (global_trace.trace_flags & TRACE_ITER_SYM_MASK); |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2605 | struct trace_buffer *buf = iter->trace_buffer; |
| 2606 | struct trace_array_cpu *data = per_cpu_ptr(buf->data, buf->cpu); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 2607 | struct tracer *type = iter->trace; |
Steven Rostedt | 39eaf7e | 2011-11-17 10:35:16 -0500 | [diff] [blame] | 2608 | unsigned long entries; |
| 2609 | unsigned long total; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2610 | const char *name = "preemption"; |
| 2611 | |
Steven Rostedt (Red Hat) | d840f71 | 2013-02-01 18:38:47 -0500 | [diff] [blame] | 2612 | name = type->name; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2613 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2614 | get_total_entries(buf, &total, &entries); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2615 | |
KOSAKI Motohiro | 888b55d | 2009-03-08 13:12:43 +0900 | [diff] [blame] | 2616 | seq_printf(m, "# %s latency trace v1.1.5 on %s\n", |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2617 | name, UTS_RELEASE); |
KOSAKI Motohiro | 888b55d | 2009-03-08 13:12:43 +0900 | [diff] [blame] | 2618 | seq_puts(m, "# -----------------------------------" |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2619 | "---------------------------------\n"); |
KOSAKI Motohiro | 888b55d | 2009-03-08 13:12:43 +0900 | [diff] [blame] | 2620 | seq_printf(m, "# latency: %lu us, #%lu/%lu, CPU#%d |" |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2621 | " (M:%s VP:%d, KP:%d, SP:%d HP:%d", |
Steven Rostedt | 57f50be | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 2622 | nsecs_to_usecs(data->saved_latency), |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2623 | entries, |
Steven Rostedt | 4c11d7a | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 2624 | total, |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2625 | buf->cpu, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2626 | #if defined(CONFIG_PREEMPT_NONE) |
| 2627 | "server", |
| 2628 | #elif defined(CONFIG_PREEMPT_VOLUNTARY) |
| 2629 | "desktop", |
Steven Rostedt | b5c21b4 | 2008-07-10 20:58:12 -0400 | [diff] [blame] | 2630 | #elif defined(CONFIG_PREEMPT) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2631 | "preempt", |
| 2632 | #else |
| 2633 | "unknown", |
| 2634 | #endif |
| 2635 | /* These are reserved for later use */ |
| 2636 | 0, 0, 0, 0); |
| 2637 | #ifdef CONFIG_SMP |
| 2638 | seq_printf(m, " #P:%d)\n", num_online_cpus()); |
| 2639 | #else |
| 2640 | seq_puts(m, ")\n"); |
| 2641 | #endif |
KOSAKI Motohiro | 888b55d | 2009-03-08 13:12:43 +0900 | [diff] [blame] | 2642 | seq_puts(m, "# -----------------\n"); |
| 2643 | seq_printf(m, "# | task: %.16s-%d " |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2644 | "(uid:%d nice:%ld policy:%ld rt_prio:%ld)\n", |
Eric W. Biederman | d20b92a | 2012-03-13 16:02:19 -0700 | [diff] [blame] | 2645 | data->comm, data->pid, |
| 2646 | from_kuid_munged(seq_user_ns(m), data->uid), data->nice, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2647 | data->policy, data->rt_priority); |
KOSAKI Motohiro | 888b55d | 2009-03-08 13:12:43 +0900 | [diff] [blame] | 2648 | seq_puts(m, "# -----------------\n"); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2649 | |
| 2650 | if (data->critical_start) { |
KOSAKI Motohiro | 888b55d | 2009-03-08 13:12:43 +0900 | [diff] [blame] | 2651 | seq_puts(m, "# => started at: "); |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2652 | seq_print_ip_sym(&iter->seq, data->critical_start, sym_flags); |
| 2653 | trace_print_seq(m, &iter->seq); |
KOSAKI Motohiro | 888b55d | 2009-03-08 13:12:43 +0900 | [diff] [blame] | 2654 | seq_puts(m, "\n# => ended at: "); |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2655 | seq_print_ip_sym(&iter->seq, data->critical_end, sym_flags); |
| 2656 | trace_print_seq(m, &iter->seq); |
Steven Rostedt | 8248ac0 | 2009-09-02 12:27:41 -0400 | [diff] [blame] | 2657 | seq_puts(m, "\n#\n"); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2658 | } |
| 2659 | |
KOSAKI Motohiro | 888b55d | 2009-03-08 13:12:43 +0900 | [diff] [blame] | 2660 | seq_puts(m, "#\n"); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2661 | } |
| 2662 | |
Steven Rostedt | a309720 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 2663 | static void test_cpu_buff_start(struct trace_iterator *iter) |
| 2664 | { |
| 2665 | struct trace_seq *s = &iter->seq; |
Steven Rostedt (Red Hat) | 983f938 | 2015-09-30 09:42:05 -0400 | [diff] [blame] | 2666 | struct trace_array *tr = iter->tr; |
Steven Rostedt | a309720 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 2667 | |
Steven Rostedt (Red Hat) | 983f938 | 2015-09-30 09:42:05 -0400 | [diff] [blame] | 2668 | if (!(tr->trace_flags & TRACE_ITER_ANNOTATE)) |
Steven Rostedt | 12ef7d4 | 2008-11-12 17:52:38 -0500 | [diff] [blame] | 2669 | return; |
| 2670 | |
| 2671 | if (!(iter->iter_flags & TRACE_FILE_ANNOTATE)) |
| 2672 | return; |
| 2673 | |
Rusty Russell | 4462344 | 2009-01-01 10:12:23 +1030 | [diff] [blame] | 2674 | if (cpumask_test_cpu(iter->cpu, iter->started)) |
Steven Rostedt | a309720 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 2675 | return; |
| 2676 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2677 | if (per_cpu_ptr(iter->trace_buffer->data, iter->cpu)->skipped_entries) |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 2678 | return; |
| 2679 | |
Rusty Russell | 4462344 | 2009-01-01 10:12:23 +1030 | [diff] [blame] | 2680 | cpumask_set_cpu(iter->cpu, iter->started); |
Frederic Weisbecker | b0dfa97 | 2009-04-01 22:53:08 +0200 | [diff] [blame] | 2681 | |
| 2682 | /* Don't print started cpu buffer for the first entry of the trace */ |
| 2683 | if (iter->idx > 1) |
| 2684 | trace_seq_printf(s, "##### CPU %u buffer started ####\n", |
| 2685 | iter->cpu); |
Steven Rostedt | a309720 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 2686 | } |
| 2687 | |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 2688 | static enum print_line_t print_trace_fmt(struct trace_iterator *iter) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2689 | { |
Steven Rostedt (Red Hat) | 983f938 | 2015-09-30 09:42:05 -0400 | [diff] [blame] | 2690 | struct trace_array *tr = iter->tr; |
Steven Rostedt | 214023c | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 2691 | struct trace_seq *s = &iter->seq; |
Steven Rostedt (Red Hat) | 983f938 | 2015-09-30 09:42:05 -0400 | [diff] [blame] | 2692 | unsigned long sym_flags = (tr->trace_flags & TRACE_ITER_SYM_MASK); |
Ingo Molnar | 4e3c333 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 2693 | struct trace_entry *entry; |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 2694 | struct trace_event *event; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2695 | |
Ingo Molnar | 4e3c333 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 2696 | entry = iter->ent; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2697 | |
Steven Rostedt | a309720 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 2698 | test_cpu_buff_start(iter); |
| 2699 | |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 2700 | event = ftrace_find_event(entry->type); |
Frederic Weisbecker | c4a8e8b | 2009-02-02 20:29:21 -0200 | [diff] [blame] | 2701 | |
Steven Rostedt (Red Hat) | 983f938 | 2015-09-30 09:42:05 -0400 | [diff] [blame] | 2702 | if (tr->trace_flags & TRACE_ITER_CONTEXT_INFO) { |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame] | 2703 | if (iter->iter_flags & TRACE_FILE_LAT_FMT) |
| 2704 | trace_print_lat_context(iter); |
| 2705 | else |
| 2706 | trace_print_context(iter); |
Frederic Weisbecker | c4a8e8b | 2009-02-02 20:29:21 -0200 | [diff] [blame] | 2707 | } |
| 2708 | |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame] | 2709 | if (trace_seq_has_overflowed(s)) |
| 2710 | return TRACE_TYPE_PARTIAL_LINE; |
| 2711 | |
Arnaldo Carvalho de Melo | 268ccda | 2009-02-04 20:16:39 -0200 | [diff] [blame] | 2712 | if (event) |
Steven Rostedt | a9a5776 | 2010-04-22 18:46:14 -0400 | [diff] [blame] | 2713 | return event->funcs->trace(iter, sym_flags, event); |
Arnaldo Carvalho de Melo | d9793bd | 2009-02-03 20:20:41 -0200 | [diff] [blame] | 2714 | |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame] | 2715 | trace_seq_printf(s, "Unknown type %d\n", entry->type); |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 2716 | |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame] | 2717 | return trace_handle_return(s); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2718 | } |
| 2719 | |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 2720 | static enum print_line_t print_raw_fmt(struct trace_iterator *iter) |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2721 | { |
Steven Rostedt (Red Hat) | 983f938 | 2015-09-30 09:42:05 -0400 | [diff] [blame] | 2722 | struct trace_array *tr = iter->tr; |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2723 | struct trace_seq *s = &iter->seq; |
| 2724 | struct trace_entry *entry; |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 2725 | struct trace_event *event; |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2726 | |
| 2727 | entry = iter->ent; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2728 | |
Steven Rostedt (Red Hat) | 983f938 | 2015-09-30 09:42:05 -0400 | [diff] [blame] | 2729 | if (tr->trace_flags & TRACE_ITER_CONTEXT_INFO) |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame] | 2730 | trace_seq_printf(s, "%d %d %llu ", |
| 2731 | entry->pid, iter->cpu, iter->ts); |
| 2732 | |
| 2733 | if (trace_seq_has_overflowed(s)) |
| 2734 | return TRACE_TYPE_PARTIAL_LINE; |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2735 | |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 2736 | event = ftrace_find_event(entry->type); |
Arnaldo Carvalho de Melo | 268ccda | 2009-02-04 20:16:39 -0200 | [diff] [blame] | 2737 | if (event) |
Steven Rostedt | a9a5776 | 2010-04-22 18:46:14 -0400 | [diff] [blame] | 2738 | return event->funcs->raw(iter, 0, event); |
Arnaldo Carvalho de Melo | d9793bd | 2009-02-03 20:20:41 -0200 | [diff] [blame] | 2739 | |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame] | 2740 | trace_seq_printf(s, "%d ?\n", entry->type); |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 2741 | |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame] | 2742 | return trace_handle_return(s); |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2743 | } |
| 2744 | |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 2745 | static enum print_line_t print_hex_fmt(struct trace_iterator *iter) |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 2746 | { |
Steven Rostedt (Red Hat) | 983f938 | 2015-09-30 09:42:05 -0400 | [diff] [blame] | 2747 | struct trace_array *tr = iter->tr; |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 2748 | struct trace_seq *s = &iter->seq; |
| 2749 | unsigned char newline = '\n'; |
| 2750 | struct trace_entry *entry; |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 2751 | struct trace_event *event; |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 2752 | |
| 2753 | entry = iter->ent; |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 2754 | |
Steven Rostedt (Red Hat) | 983f938 | 2015-09-30 09:42:05 -0400 | [diff] [blame] | 2755 | if (tr->trace_flags & TRACE_ITER_CONTEXT_INFO) { |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame] | 2756 | SEQ_PUT_HEX_FIELD(s, entry->pid); |
| 2757 | SEQ_PUT_HEX_FIELD(s, iter->cpu); |
| 2758 | SEQ_PUT_HEX_FIELD(s, iter->ts); |
| 2759 | if (trace_seq_has_overflowed(s)) |
| 2760 | return TRACE_TYPE_PARTIAL_LINE; |
Frederic Weisbecker | c4a8e8b | 2009-02-02 20:29:21 -0200 | [diff] [blame] | 2761 | } |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 2762 | |
Steven Rostedt | f633cef | 2008-12-23 23:24:13 -0500 | [diff] [blame] | 2763 | event = ftrace_find_event(entry->type); |
Arnaldo Carvalho de Melo | 268ccda | 2009-02-04 20:16:39 -0200 | [diff] [blame] | 2764 | if (event) { |
Steven Rostedt | a9a5776 | 2010-04-22 18:46:14 -0400 | [diff] [blame] | 2765 | 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] | 2766 | if (ret != TRACE_TYPE_HANDLED) |
| 2767 | return ret; |
| 2768 | } |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 2769 | |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame] | 2770 | SEQ_PUT_FIELD(s, newline); |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 2771 | |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame] | 2772 | return trace_handle_return(s); |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 2773 | } |
| 2774 | |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 2775 | static enum print_line_t print_bin_fmt(struct trace_iterator *iter) |
Ingo Molnar | cb0f12a | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2776 | { |
Steven Rostedt (Red Hat) | 983f938 | 2015-09-30 09:42:05 -0400 | [diff] [blame] | 2777 | struct trace_array *tr = iter->tr; |
Ingo Molnar | cb0f12a | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 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 | |
Steven Rostedt (Red Hat) | 983f938 | 2015-09-30 09:42:05 -0400 | [diff] [blame] | 2784 | if (tr->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 | { |
Steven Rostedt (Red Hat) | 983f938 | 2015-09-30 09:42:05 -0400 | [diff] [blame] | 2833 | struct trace_array *tr = iter->tr; |
| 2834 | unsigned long trace_flags = tr->trace_flags; |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 2835 | enum print_line_t ret; |
| 2836 | |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame] | 2837 | if (iter->lost_events) { |
| 2838 | trace_seq_printf(&iter->seq, "CPU:%d [LOST %lu EVENTS]\n", |
| 2839 | iter->cpu, iter->lost_events); |
| 2840 | if (trace_seq_has_overflowed(&iter->seq)) |
| 2841 | return TRACE_TYPE_PARTIAL_LINE; |
| 2842 | } |
Steven Rostedt | bc21b47 | 2010-03-31 19:49:26 -0400 | [diff] [blame] | 2843 | |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 2844 | if (iter->trace && iter->trace->print_line) { |
| 2845 | ret = iter->trace->print_line(iter); |
| 2846 | if (ret != TRACE_TYPE_UNHANDLED) |
| 2847 | return ret; |
| 2848 | } |
Thomas Gleixner | 72829bc | 2008-05-23 21:37:28 +0200 | [diff] [blame] | 2849 | |
Steven Rostedt (Red Hat) | 09ae723 | 2013-03-08 21:02:34 -0500 | [diff] [blame] | 2850 | if (iter->ent->type == TRACE_BPUTS && |
| 2851 | trace_flags & TRACE_ITER_PRINTK && |
| 2852 | trace_flags & TRACE_ITER_PRINTK_MSGONLY) |
| 2853 | return trace_print_bputs_msg_only(iter); |
| 2854 | |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 2855 | if (iter->ent->type == TRACE_BPRINT && |
| 2856 | trace_flags & TRACE_ITER_PRINTK && |
| 2857 | trace_flags & TRACE_ITER_PRINTK_MSGONLY) |
Steven Rostedt | 5ef841f | 2009-03-19 12:20:38 -0400 | [diff] [blame] | 2858 | return trace_print_bprintk_msg_only(iter); |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 2859 | |
Frederic Weisbecker | 66896a8 | 2008-12-13 20:18:13 +0100 | [diff] [blame] | 2860 | if (iter->ent->type == TRACE_PRINT && |
| 2861 | trace_flags & TRACE_ITER_PRINTK && |
| 2862 | trace_flags & TRACE_ITER_PRINTK_MSGONLY) |
Steven Rostedt | 5ef841f | 2009-03-19 12:20:38 -0400 | [diff] [blame] | 2863 | return trace_print_printk_msg_only(iter); |
Frederic Weisbecker | 66896a8 | 2008-12-13 20:18:13 +0100 | [diff] [blame] | 2864 | |
Ingo Molnar | cb0f12a | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2865 | if (trace_flags & TRACE_ITER_BIN) |
| 2866 | return print_bin_fmt(iter); |
| 2867 | |
Ingo Molnar | 5e3ca0e | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 2868 | if (trace_flags & TRACE_ITER_HEX) |
| 2869 | return print_hex_fmt(iter); |
| 2870 | |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2871 | if (trace_flags & TRACE_ITER_RAW) |
| 2872 | return print_raw_fmt(iter); |
| 2873 | |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 2874 | return print_trace_fmt(iter); |
| 2875 | } |
| 2876 | |
Jiri Olsa | 7e9a49e | 2011-11-07 16:08:49 +0100 | [diff] [blame] | 2877 | void trace_latency_header(struct seq_file *m) |
| 2878 | { |
| 2879 | struct trace_iterator *iter = m->private; |
Steven Rostedt (Red Hat) | 983f938 | 2015-09-30 09:42:05 -0400 | [diff] [blame] | 2880 | struct trace_array *tr = iter->tr; |
Jiri Olsa | 7e9a49e | 2011-11-07 16:08:49 +0100 | [diff] [blame] | 2881 | |
| 2882 | /* print nothing if the buffers are empty */ |
| 2883 | if (trace_empty(iter)) |
| 2884 | return; |
| 2885 | |
| 2886 | if (iter->iter_flags & TRACE_FILE_LAT_FMT) |
| 2887 | print_trace_header(m, iter); |
| 2888 | |
Steven Rostedt (Red Hat) | 983f938 | 2015-09-30 09:42:05 -0400 | [diff] [blame] | 2889 | if (!(tr->trace_flags & TRACE_ITER_VERBOSE)) |
Jiri Olsa | 7e9a49e | 2011-11-07 16:08:49 +0100 | [diff] [blame] | 2890 | print_lat_help_header(m); |
| 2891 | } |
| 2892 | |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 2893 | void trace_default_header(struct seq_file *m) |
| 2894 | { |
| 2895 | struct trace_iterator *iter = m->private; |
Steven Rostedt (Red Hat) | 983f938 | 2015-09-30 09:42:05 -0400 | [diff] [blame] | 2896 | struct trace_array *tr = iter->tr; |
| 2897 | unsigned long trace_flags = tr->trace_flags; |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 2898 | |
Jiri Olsa | f56e7f8 | 2011-06-03 16:58:49 +0200 | [diff] [blame] | 2899 | if (!(trace_flags & TRACE_ITER_CONTEXT_INFO)) |
| 2900 | return; |
| 2901 | |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 2902 | if (iter->iter_flags & TRACE_FILE_LAT_FMT) { |
| 2903 | /* print nothing if the buffers are empty */ |
| 2904 | if (trace_empty(iter)) |
| 2905 | return; |
| 2906 | print_trace_header(m, iter); |
| 2907 | if (!(trace_flags & TRACE_ITER_VERBOSE)) |
| 2908 | print_lat_help_header(m); |
| 2909 | } else { |
Steven Rostedt | 77271ce | 2011-11-17 09:34:33 -0500 | [diff] [blame] | 2910 | if (!(trace_flags & TRACE_ITER_VERBOSE)) { |
| 2911 | if (trace_flags & TRACE_ITER_IRQ_INFO) |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2912 | print_func_help_header_irq(iter->trace_buffer, m); |
Steven Rostedt | 77271ce | 2011-11-17 09:34:33 -0500 | [diff] [blame] | 2913 | else |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 2914 | print_func_help_header(iter->trace_buffer, m); |
Steven Rostedt | 77271ce | 2011-11-17 09:34:33 -0500 | [diff] [blame] | 2915 | } |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 2916 | } |
| 2917 | } |
| 2918 | |
Steven Rostedt | e0a413f | 2011-09-29 21:26:16 -0400 | [diff] [blame] | 2919 | static void test_ftrace_alive(struct seq_file *m) |
| 2920 | { |
| 2921 | if (!ftrace_is_dead()) |
| 2922 | return; |
Rasmus Villemoes | d79ac28 | 2014-11-08 21:42:11 +0100 | [diff] [blame] | 2923 | seq_puts(m, "# WARNING: FUNCTION TRACING IS CORRUPTED\n" |
| 2924 | "# MAY BE MISSING FUNCTION EVENTS\n"); |
Steven Rostedt | e0a413f | 2011-09-29 21:26:16 -0400 | [diff] [blame] | 2925 | } |
| 2926 | |
Steven Rostedt (Red Hat) | d8741e2 | 2013-03-05 10:25:16 -0500 | [diff] [blame] | 2927 | #ifdef CONFIG_TRACER_MAX_TRACE |
Steven Rostedt (Red Hat) | f1affca | 2013-03-05 14:35:11 -0500 | [diff] [blame] | 2928 | static void show_snapshot_main_help(struct seq_file *m) |
Steven Rostedt (Red Hat) | d8741e2 | 2013-03-05 10:25:16 -0500 | [diff] [blame] | 2929 | { |
Rasmus Villemoes | d79ac28 | 2014-11-08 21:42:11 +0100 | [diff] [blame] | 2930 | seq_puts(m, "# echo 0 > snapshot : Clears and frees snapshot buffer\n" |
| 2931 | "# echo 1 > snapshot : Allocates snapshot buffer, if not already allocated.\n" |
| 2932 | "# Takes a snapshot of the main buffer.\n" |
| 2933 | "# echo 2 > snapshot : Clears snapshot buffer (but does not allocate or free)\n" |
| 2934 | "# (Doesn't have to be '2' works with any number that\n" |
| 2935 | "# is not a '0' or '1')\n"); |
Steven Rostedt (Red Hat) | d8741e2 | 2013-03-05 10:25:16 -0500 | [diff] [blame] | 2936 | } |
Steven Rostedt (Red Hat) | f1affca | 2013-03-05 14:35:11 -0500 | [diff] [blame] | 2937 | |
| 2938 | static void show_snapshot_percpu_help(struct seq_file *m) |
| 2939 | { |
Rasmus Villemoes | fa6f0cc | 2014-11-08 21:42:10 +0100 | [diff] [blame] | 2940 | 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] | 2941 | #ifdef CONFIG_RING_BUFFER_ALLOW_SWAP |
Rasmus Villemoes | d79ac28 | 2014-11-08 21:42:11 +0100 | [diff] [blame] | 2942 | seq_puts(m, "# echo 1 > snapshot : Allocates snapshot buffer, if not already allocated.\n" |
| 2943 | "# 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] | 2944 | #else |
Rasmus Villemoes | d79ac28 | 2014-11-08 21:42:11 +0100 | [diff] [blame] | 2945 | seq_puts(m, "# echo 1 > snapshot : Not supported with this kernel.\n" |
| 2946 | "# Must use main snapshot file to allocate.\n"); |
Steven Rostedt (Red Hat) | f1affca | 2013-03-05 14:35:11 -0500 | [diff] [blame] | 2947 | #endif |
Rasmus Villemoes | d79ac28 | 2014-11-08 21:42:11 +0100 | [diff] [blame] | 2948 | seq_puts(m, "# echo 2 > snapshot : Clears this cpu's snapshot buffer (but does not allocate)\n" |
| 2949 | "# (Doesn't have to be '2' works with any number that\n" |
| 2950 | "# is not a '0' or '1')\n"); |
Steven Rostedt (Red Hat) | f1affca | 2013-03-05 14:35:11 -0500 | [diff] [blame] | 2951 | } |
| 2952 | |
Steven Rostedt (Red Hat) | d8741e2 | 2013-03-05 10:25:16 -0500 | [diff] [blame] | 2953 | static void print_snapshot_help(struct seq_file *m, struct trace_iterator *iter) |
| 2954 | { |
Steven Rostedt (Red Hat) | 45ad21c | 2013-03-05 18:25:02 -0500 | [diff] [blame] | 2955 | if (iter->tr->allocated_snapshot) |
Rasmus Villemoes | fa6f0cc | 2014-11-08 21:42:10 +0100 | [diff] [blame] | 2956 | seq_puts(m, "#\n# * Snapshot is allocated *\n#\n"); |
Steven Rostedt (Red Hat) | d8741e2 | 2013-03-05 10:25:16 -0500 | [diff] [blame] | 2957 | else |
Rasmus Villemoes | fa6f0cc | 2014-11-08 21:42:10 +0100 | [diff] [blame] | 2958 | seq_puts(m, "#\n# * Snapshot is freed *\n#\n"); |
Steven Rostedt (Red Hat) | d8741e2 | 2013-03-05 10:25:16 -0500 | [diff] [blame] | 2959 | |
Rasmus Villemoes | fa6f0cc | 2014-11-08 21:42:10 +0100 | [diff] [blame] | 2960 | seq_puts(m, "# Snapshot commands:\n"); |
Steven Rostedt (Red Hat) | f1affca | 2013-03-05 14:35:11 -0500 | [diff] [blame] | 2961 | if (iter->cpu_file == RING_BUFFER_ALL_CPUS) |
| 2962 | show_snapshot_main_help(m); |
| 2963 | else |
| 2964 | show_snapshot_percpu_help(m); |
Steven Rostedt (Red Hat) | d8741e2 | 2013-03-05 10:25:16 -0500 | [diff] [blame] | 2965 | } |
| 2966 | #else |
| 2967 | /* Should never be called */ |
| 2968 | static inline void print_snapshot_help(struct seq_file *m, struct trace_iterator *iter) { } |
| 2969 | #endif |
| 2970 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2971 | static int s_show(struct seq_file *m, void *v) |
| 2972 | { |
| 2973 | struct trace_iterator *iter = v; |
Steven Rostedt | a63ce5b | 2009-12-07 09:11:39 -0500 | [diff] [blame] | 2974 | int ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2975 | |
| 2976 | if (iter->ent == NULL) { |
| 2977 | if (iter->tr) { |
| 2978 | seq_printf(m, "# tracer: %s\n", iter->trace->name); |
| 2979 | seq_puts(m, "#\n"); |
Steven Rostedt | e0a413f | 2011-09-29 21:26:16 -0400 | [diff] [blame] | 2980 | test_ftrace_alive(m); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2981 | } |
Steven Rostedt (Red Hat) | d8741e2 | 2013-03-05 10:25:16 -0500 | [diff] [blame] | 2982 | if (iter->snapshot && trace_empty(iter)) |
| 2983 | print_snapshot_help(m, iter); |
| 2984 | else if (iter->trace && iter->trace->print_header) |
Markus Metzger | 8bba1bf | 2008-11-25 09:12:31 +0100 | [diff] [blame] | 2985 | iter->trace->print_header(m); |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 2986 | else |
| 2987 | trace_default_header(m); |
| 2988 | |
Steven Rostedt | a63ce5b | 2009-12-07 09:11:39 -0500 | [diff] [blame] | 2989 | } else if (iter->leftover) { |
| 2990 | /* |
| 2991 | * If we filled the seq_file buffer earlier, we |
| 2992 | * want to just show it now. |
| 2993 | */ |
| 2994 | ret = trace_print_seq(m, &iter->seq); |
| 2995 | |
| 2996 | /* ret should this time be zero, but you never know */ |
| 2997 | iter->leftover = ret; |
| 2998 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2999 | } else { |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 3000 | print_trace_line(iter); |
Steven Rostedt | a63ce5b | 2009-12-07 09:11:39 -0500 | [diff] [blame] | 3001 | ret = trace_print_seq(m, &iter->seq); |
| 3002 | /* |
| 3003 | * If we overflow the seq_file buffer, then it will |
| 3004 | * ask us for this data again at start up. |
| 3005 | * Use that instead. |
| 3006 | * ret is 0 if seq_file write succeeded. |
| 3007 | * -1 otherwise. |
| 3008 | */ |
| 3009 | iter->leftover = ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3010 | } |
| 3011 | |
| 3012 | return 0; |
| 3013 | } |
| 3014 | |
Oleg Nesterov | 649e9c70 | 2013-07-23 17:25:54 +0200 | [diff] [blame] | 3015 | /* |
| 3016 | * Should be used after trace_array_get(), trace_types_lock |
| 3017 | * ensures that i_cdev was already initialized. |
| 3018 | */ |
| 3019 | static inline int tracing_get_cpu(struct inode *inode) |
| 3020 | { |
| 3021 | if (inode->i_cdev) /* See trace_create_cpu_file() */ |
| 3022 | return (long)inode->i_cdev - 1; |
| 3023 | return RING_BUFFER_ALL_CPUS; |
| 3024 | } |
| 3025 | |
James Morris | 88e9d34 | 2009-09-22 16:43:43 -0700 | [diff] [blame] | 3026 | static const struct seq_operations tracer_seq_ops = { |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3027 | .start = s_start, |
| 3028 | .next = s_next, |
| 3029 | .stop = s_stop, |
| 3030 | .show = s_show, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3031 | }; |
| 3032 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 3033 | static struct trace_iterator * |
Oleg Nesterov | 6484c71 | 2013-07-23 17:26:10 +0200 | [diff] [blame] | 3034 | __tracing_open(struct inode *inode, struct file *file, bool snapshot) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3035 | { |
Oleg Nesterov | 6484c71 | 2013-07-23 17:26:10 +0200 | [diff] [blame] | 3036 | struct trace_array *tr = inode->i_private; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3037 | struct trace_iterator *iter; |
Jiri Olsa | 50e18b9 | 2012-04-25 10:23:39 +0200 | [diff] [blame] | 3038 | int cpu; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3039 | |
Steven Rostedt | 85a2f9b | 2009-02-27 00:12:38 -0500 | [diff] [blame] | 3040 | if (tracing_disabled) |
| 3041 | return ERR_PTR(-ENODEV); |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 3042 | |
Jiri Olsa | 50e18b9 | 2012-04-25 10:23:39 +0200 | [diff] [blame] | 3043 | iter = __seq_open_private(file, &tracer_seq_ops, sizeof(*iter)); |
Steven Rostedt | 85a2f9b | 2009-02-27 00:12:38 -0500 | [diff] [blame] | 3044 | if (!iter) |
| 3045 | return ERR_PTR(-ENOMEM); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3046 | |
Gil Fruchter | 7291723 | 2015-06-09 10:32:35 +0300 | [diff] [blame] | 3047 | iter->buffer_iter = kcalloc(nr_cpu_ids, sizeof(*iter->buffer_iter), |
Steven Rostedt | 6d158a8 | 2012-06-27 20:46:14 -0400 | [diff] [blame] | 3048 | GFP_KERNEL); |
Dan Carpenter | 93574fc | 2012-07-11 09:35:08 +0300 | [diff] [blame] | 3049 | if (!iter->buffer_iter) |
| 3050 | goto release; |
| 3051 | |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 3052 | /* |
| 3053 | * We make a copy of the current tracer to avoid concurrent |
| 3054 | * changes on it while we are reading. |
| 3055 | */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3056 | mutex_lock(&trace_types_lock); |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 3057 | iter->trace = kzalloc(sizeof(*iter->trace), GFP_KERNEL); |
Steven Rostedt | 85a2f9b | 2009-02-27 00:12:38 -0500 | [diff] [blame] | 3058 | if (!iter->trace) |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 3059 | goto fail; |
Steven Rostedt | 85a2f9b | 2009-02-27 00:12:38 -0500 | [diff] [blame] | 3060 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3061 | *iter->trace = *tr->current_trace; |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 3062 | |
Li Zefan | 79f5599 | 2009-06-15 14:58:26 +0800 | [diff] [blame] | 3063 | if (!zalloc_cpumask_var(&iter->started, GFP_KERNEL)) |
Frederic Weisbecker | b0dfa97 | 2009-04-01 22:53:08 +0200 | [diff] [blame] | 3064 | goto fail; |
| 3065 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3066 | iter->tr = tr; |
| 3067 | |
| 3068 | #ifdef CONFIG_TRACER_MAX_TRACE |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3069 | /* Currently only the top directory has a snapshot */ |
| 3070 | if (tr->current_trace->print_max || snapshot) |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3071 | iter->trace_buffer = &tr->max_buffer; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3072 | else |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3073 | #endif |
| 3074 | iter->trace_buffer = &tr->trace_buffer; |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 3075 | iter->snapshot = snapshot; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3076 | iter->pos = -1; |
Oleg Nesterov | 6484c71 | 2013-07-23 17:26:10 +0200 | [diff] [blame] | 3077 | iter->cpu_file = tracing_get_cpu(inode); |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 3078 | mutex_init(&iter->mutex); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3079 | |
Markus Metzger | 8bba1bf | 2008-11-25 09:12:31 +0100 | [diff] [blame] | 3080 | /* Notify the tracer early; before we stop tracing. */ |
| 3081 | if (iter->trace && iter->trace->open) |
Markus Metzger | a93751c | 2008-12-11 13:53:26 +0100 | [diff] [blame] | 3082 | iter->trace->open(iter); |
Markus Metzger | 8bba1bf | 2008-11-25 09:12:31 +0100 | [diff] [blame] | 3083 | |
Steven Rostedt | 12ef7d4 | 2008-11-12 17:52:38 -0500 | [diff] [blame] | 3084 | /* Annotate start of buffers if we had overruns */ |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3085 | if (ring_buffer_overruns(iter->trace_buffer->buffer)) |
Steven Rostedt | 12ef7d4 | 2008-11-12 17:52:38 -0500 | [diff] [blame] | 3086 | iter->iter_flags |= TRACE_FILE_ANNOTATE; |
| 3087 | |
David Sharp | 8be0709 | 2012-11-13 12:18:22 -0800 | [diff] [blame] | 3088 | /* Output in nanoseconds only if we are using a clock in nanoseconds. */ |
Yoshihiro YUNOMAE | 58e8eed | 2013-04-23 10:32:39 +0900 | [diff] [blame] | 3089 | if (trace_clocks[tr->clock_id].in_ns) |
David Sharp | 8be0709 | 2012-11-13 12:18:22 -0800 | [diff] [blame] | 3090 | iter->iter_flags |= TRACE_FILE_TIME_IN_NS; |
| 3091 | |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 3092 | /* stop the trace while dumping if we are not opening "snapshot" */ |
| 3093 | if (!iter->snapshot) |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3094 | tracing_stop_tr(tr); |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 3095 | |
Steven Rostedt | ae3b509 | 2013-01-23 15:22:59 -0500 | [diff] [blame] | 3096 | if (iter->cpu_file == RING_BUFFER_ALL_CPUS) { |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 3097 | for_each_tracing_cpu(cpu) { |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 3098 | iter->buffer_iter[cpu] = |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3099 | ring_buffer_read_prepare(iter->trace_buffer->buffer, cpu); |
David Miller | 72c9ddf | 2010-04-20 15:47:11 -0700 | [diff] [blame] | 3100 | } |
| 3101 | ring_buffer_read_prepare_sync(); |
| 3102 | for_each_tracing_cpu(cpu) { |
| 3103 | ring_buffer_read_start(iter->buffer_iter[cpu]); |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 3104 | tracing_iter_reset(iter, cpu); |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 3105 | } |
| 3106 | } else { |
| 3107 | cpu = iter->cpu_file; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 3108 | iter->buffer_iter[cpu] = |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3109 | ring_buffer_read_prepare(iter->trace_buffer->buffer, cpu); |
David Miller | 72c9ddf | 2010-04-20 15:47:11 -0700 | [diff] [blame] | 3110 | ring_buffer_read_prepare_sync(); |
| 3111 | ring_buffer_read_start(iter->buffer_iter[cpu]); |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 3112 | tracing_iter_reset(iter, cpu); |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 3113 | } |
| 3114 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3115 | mutex_unlock(&trace_types_lock); |
| 3116 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3117 | return iter; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 3118 | |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 3119 | fail: |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 3120 | mutex_unlock(&trace_types_lock); |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 3121 | kfree(iter->trace); |
Steven Rostedt | 6d158a8 | 2012-06-27 20:46:14 -0400 | [diff] [blame] | 3122 | kfree(iter->buffer_iter); |
Dan Carpenter | 93574fc | 2012-07-11 09:35:08 +0300 | [diff] [blame] | 3123 | release: |
Jiri Olsa | 50e18b9 | 2012-04-25 10:23:39 +0200 | [diff] [blame] | 3124 | seq_release_private(inode, file); |
| 3125 | return ERR_PTR(-ENOMEM); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3126 | } |
| 3127 | |
| 3128 | int tracing_open_generic(struct inode *inode, struct file *filp) |
| 3129 | { |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 3130 | if (tracing_disabled) |
| 3131 | return -ENODEV; |
| 3132 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3133 | filp->private_data = inode->i_private; |
| 3134 | return 0; |
| 3135 | } |
| 3136 | |
Geyslan G. Bem | 2e86421 | 2013-10-18 21:15:54 -0300 | [diff] [blame] | 3137 | bool tracing_is_disabled(void) |
| 3138 | { |
| 3139 | return (tracing_disabled) ? true: false; |
| 3140 | } |
| 3141 | |
Steven Rostedt (Red Hat) | 7b85af6 | 2013-07-01 23:34:22 -0400 | [diff] [blame] | 3142 | /* |
| 3143 | * Open and update trace_array ref count. |
| 3144 | * Must have the current trace_array passed to it. |
| 3145 | */ |
Steven Rostedt (Red Hat) | dcc3022 | 2013-07-02 20:30:52 -0400 | [diff] [blame] | 3146 | 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] | 3147 | { |
| 3148 | struct trace_array *tr = inode->i_private; |
| 3149 | |
| 3150 | if (tracing_disabled) |
| 3151 | return -ENODEV; |
| 3152 | |
| 3153 | if (trace_array_get(tr) < 0) |
| 3154 | return -ENODEV; |
| 3155 | |
| 3156 | filp->private_data = inode->i_private; |
| 3157 | |
| 3158 | return 0; |
Steven Rostedt (Red Hat) | 7b85af6 | 2013-07-01 23:34:22 -0400 | [diff] [blame] | 3159 | } |
| 3160 | |
Hannes Eder | 4fd2735 | 2009-02-10 19:44:12 +0100 | [diff] [blame] | 3161 | static int tracing_release(struct inode *inode, struct file *file) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3162 | { |
Oleg Nesterov | 6484c71 | 2013-07-23 17:26:10 +0200 | [diff] [blame] | 3163 | struct trace_array *tr = inode->i_private; |
matt mooney | 907f278 | 2010-09-27 19:04:53 -0700 | [diff] [blame] | 3164 | struct seq_file *m = file->private_data; |
Steven Rostedt | 4acd4d0 | 2009-03-18 10:40:24 -0400 | [diff] [blame] | 3165 | struct trace_iterator *iter; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 3166 | int cpu; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3167 | |
Steven Rostedt (Red Hat) | ff45196 | 2013-07-01 22:50:29 -0400 | [diff] [blame] | 3168 | if (!(file->f_mode & FMODE_READ)) { |
Oleg Nesterov | 6484c71 | 2013-07-23 17:26:10 +0200 | [diff] [blame] | 3169 | trace_array_put(tr); |
Steven Rostedt | 4acd4d0 | 2009-03-18 10:40:24 -0400 | [diff] [blame] | 3170 | return 0; |
Steven Rostedt (Red Hat) | ff45196 | 2013-07-01 22:50:29 -0400 | [diff] [blame] | 3171 | } |
Steven Rostedt | 4acd4d0 | 2009-03-18 10:40:24 -0400 | [diff] [blame] | 3172 | |
Oleg Nesterov | 6484c71 | 2013-07-23 17:26:10 +0200 | [diff] [blame] | 3173 | /* Writes do not use seq_file */ |
Steven Rostedt | 4acd4d0 | 2009-03-18 10:40:24 -0400 | [diff] [blame] | 3174 | iter = m->private; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3175 | mutex_lock(&trace_types_lock); |
Steven Rostedt (Red Hat) | a695cb5 | 2013-03-06 15:27:24 -0500 | [diff] [blame] | 3176 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 3177 | for_each_tracing_cpu(cpu) { |
| 3178 | if (iter->buffer_iter[cpu]) |
| 3179 | ring_buffer_read_finish(iter->buffer_iter[cpu]); |
| 3180 | } |
| 3181 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3182 | if (iter->trace && iter->trace->close) |
| 3183 | iter->trace->close(iter); |
| 3184 | |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 3185 | if (!iter->snapshot) |
| 3186 | /* reenable tracing if it was previously enabled */ |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3187 | tracing_start_tr(tr); |
Alexander Z Lam | f77d09a | 2013-07-18 11:18:44 -0700 | [diff] [blame] | 3188 | |
| 3189 | __trace_array_put(tr); |
| 3190 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3191 | mutex_unlock(&trace_types_lock); |
| 3192 | |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 3193 | mutex_destroy(&iter->mutex); |
Frederic Weisbecker | b0dfa97 | 2009-04-01 22:53:08 +0200 | [diff] [blame] | 3194 | free_cpumask_var(iter->started); |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 3195 | kfree(iter->trace); |
Steven Rostedt | 6d158a8 | 2012-06-27 20:46:14 -0400 | [diff] [blame] | 3196 | kfree(iter->buffer_iter); |
Jiri Olsa | 50e18b9 | 2012-04-25 10:23:39 +0200 | [diff] [blame] | 3197 | seq_release_private(inode, file); |
Steven Rostedt (Red Hat) | ff45196 | 2013-07-01 22:50:29 -0400 | [diff] [blame] | 3198 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3199 | return 0; |
| 3200 | } |
| 3201 | |
Steven Rostedt (Red Hat) | 7b85af6 | 2013-07-01 23:34:22 -0400 | [diff] [blame] | 3202 | static int tracing_release_generic_tr(struct inode *inode, struct file *file) |
| 3203 | { |
| 3204 | struct trace_array *tr = inode->i_private; |
| 3205 | |
| 3206 | trace_array_put(tr); |
| 3207 | return 0; |
| 3208 | } |
| 3209 | |
Steven Rostedt (Red Hat) | 7b85af6 | 2013-07-01 23:34:22 -0400 | [diff] [blame] | 3210 | static int tracing_single_release_tr(struct inode *inode, struct file *file) |
| 3211 | { |
| 3212 | struct trace_array *tr = inode->i_private; |
| 3213 | |
| 3214 | trace_array_put(tr); |
| 3215 | |
| 3216 | return single_release(inode, file); |
| 3217 | } |
| 3218 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3219 | static int tracing_open(struct inode *inode, struct file *file) |
| 3220 | { |
Oleg Nesterov | 6484c71 | 2013-07-23 17:26:10 +0200 | [diff] [blame] | 3221 | struct trace_array *tr = inode->i_private; |
Steven Rostedt | 85a2f9b | 2009-02-27 00:12:38 -0500 | [diff] [blame] | 3222 | struct trace_iterator *iter; |
| 3223 | int ret = 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3224 | |
Steven Rostedt (Red Hat) | ff45196 | 2013-07-01 22:50:29 -0400 | [diff] [blame] | 3225 | if (trace_array_get(tr) < 0) |
| 3226 | return -ENODEV; |
| 3227 | |
Steven Rostedt | 4acd4d0 | 2009-03-18 10:40:24 -0400 | [diff] [blame] | 3228 | /* If this file was open for write, then erase contents */ |
Oleg Nesterov | 6484c71 | 2013-07-23 17:26:10 +0200 | [diff] [blame] | 3229 | if ((file->f_mode & FMODE_WRITE) && (file->f_flags & O_TRUNC)) { |
| 3230 | int cpu = tracing_get_cpu(inode); |
| 3231 | |
| 3232 | if (cpu == RING_BUFFER_ALL_CPUS) |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3233 | tracing_reset_online_cpus(&tr->trace_buffer); |
Steven Rostedt | 4acd4d0 | 2009-03-18 10:40:24 -0400 | [diff] [blame] | 3234 | else |
Oleg Nesterov | 6484c71 | 2013-07-23 17:26:10 +0200 | [diff] [blame] | 3235 | tracing_reset(&tr->trace_buffer, cpu); |
Steven Rostedt | 4acd4d0 | 2009-03-18 10:40:24 -0400 | [diff] [blame] | 3236 | } |
| 3237 | |
| 3238 | if (file->f_mode & FMODE_READ) { |
Oleg Nesterov | 6484c71 | 2013-07-23 17:26:10 +0200 | [diff] [blame] | 3239 | iter = __tracing_open(inode, file, false); |
Steven Rostedt | 4acd4d0 | 2009-03-18 10:40:24 -0400 | [diff] [blame] | 3240 | if (IS_ERR(iter)) |
| 3241 | ret = PTR_ERR(iter); |
Steven Rostedt (Red Hat) | 983f938 | 2015-09-30 09:42:05 -0400 | [diff] [blame] | 3242 | else if (tr->trace_flags & TRACE_ITER_LATENCY_FMT) |
Steven Rostedt | 4acd4d0 | 2009-03-18 10:40:24 -0400 | [diff] [blame] | 3243 | iter->iter_flags |= TRACE_FILE_LAT_FMT; |
| 3244 | } |
Steven Rostedt (Red Hat) | ff45196 | 2013-07-01 22:50:29 -0400 | [diff] [blame] | 3245 | |
| 3246 | if (ret < 0) |
| 3247 | trace_array_put(tr); |
| 3248 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3249 | return ret; |
| 3250 | } |
| 3251 | |
Steven Rostedt (Red Hat) | 607e2ea | 2013-11-06 22:42:48 -0500 | [diff] [blame] | 3252 | /* |
| 3253 | * Some tracers are not suitable for instance buffers. |
| 3254 | * A tracer is always available for the global array (toplevel) |
| 3255 | * or if it explicitly states that it is. |
| 3256 | */ |
| 3257 | static bool |
| 3258 | trace_ok_for_array(struct tracer *t, struct trace_array *tr) |
| 3259 | { |
| 3260 | return (tr->flags & TRACE_ARRAY_FL_GLOBAL) || t->allow_instances; |
| 3261 | } |
| 3262 | |
| 3263 | /* Find the next tracer that this trace array may use */ |
| 3264 | static struct tracer * |
| 3265 | get_tracer_for_array(struct trace_array *tr, struct tracer *t) |
| 3266 | { |
| 3267 | while (t && !trace_ok_for_array(t, tr)) |
| 3268 | t = t->next; |
| 3269 | |
| 3270 | return t; |
| 3271 | } |
| 3272 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 3273 | static void * |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3274 | t_next(struct seq_file *m, void *v, loff_t *pos) |
| 3275 | { |
Steven Rostedt (Red Hat) | 607e2ea | 2013-11-06 22:42:48 -0500 | [diff] [blame] | 3276 | struct trace_array *tr = m->private; |
Li Zefan | f129e96 | 2009-06-24 09:53:44 +0800 | [diff] [blame] | 3277 | struct tracer *t = v; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3278 | |
| 3279 | (*pos)++; |
| 3280 | |
| 3281 | if (t) |
Steven Rostedt (Red Hat) | 607e2ea | 2013-11-06 22:42:48 -0500 | [diff] [blame] | 3282 | t = get_tracer_for_array(tr, t->next); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3283 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3284 | return t; |
| 3285 | } |
| 3286 | |
| 3287 | static void *t_start(struct seq_file *m, loff_t *pos) |
| 3288 | { |
Steven Rostedt (Red Hat) | 607e2ea | 2013-11-06 22:42:48 -0500 | [diff] [blame] | 3289 | struct trace_array *tr = m->private; |
Li Zefan | f129e96 | 2009-06-24 09:53:44 +0800 | [diff] [blame] | 3290 | struct tracer *t; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3291 | loff_t l = 0; |
| 3292 | |
| 3293 | mutex_lock(&trace_types_lock); |
Steven Rostedt (Red Hat) | 607e2ea | 2013-11-06 22:42:48 -0500 | [diff] [blame] | 3294 | |
| 3295 | t = get_tracer_for_array(tr, trace_types); |
| 3296 | for (; t && l < *pos; t = t_next(m, t, &l)) |
| 3297 | ; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3298 | |
| 3299 | return t; |
| 3300 | } |
| 3301 | |
| 3302 | static void t_stop(struct seq_file *m, void *p) |
| 3303 | { |
| 3304 | mutex_unlock(&trace_types_lock); |
| 3305 | } |
| 3306 | |
| 3307 | static int t_show(struct seq_file *m, void *v) |
| 3308 | { |
| 3309 | struct tracer *t = v; |
| 3310 | |
| 3311 | if (!t) |
| 3312 | return 0; |
| 3313 | |
Rasmus Villemoes | fa6f0cc | 2014-11-08 21:42:10 +0100 | [diff] [blame] | 3314 | seq_puts(m, t->name); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3315 | if (t->next) |
| 3316 | seq_putc(m, ' '); |
| 3317 | else |
| 3318 | seq_putc(m, '\n'); |
| 3319 | |
| 3320 | return 0; |
| 3321 | } |
| 3322 | |
James Morris | 88e9d34 | 2009-09-22 16:43:43 -0700 | [diff] [blame] | 3323 | static const struct seq_operations show_traces_seq_ops = { |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3324 | .start = t_start, |
| 3325 | .next = t_next, |
| 3326 | .stop = t_stop, |
| 3327 | .show = t_show, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3328 | }; |
| 3329 | |
| 3330 | static int show_traces_open(struct inode *inode, struct file *file) |
| 3331 | { |
Steven Rostedt (Red Hat) | 607e2ea | 2013-11-06 22:42:48 -0500 | [diff] [blame] | 3332 | struct trace_array *tr = inode->i_private; |
| 3333 | struct seq_file *m; |
| 3334 | int ret; |
| 3335 | |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 3336 | if (tracing_disabled) |
| 3337 | return -ENODEV; |
| 3338 | |
Steven Rostedt (Red Hat) | 607e2ea | 2013-11-06 22:42:48 -0500 | [diff] [blame] | 3339 | ret = seq_open(file, &show_traces_seq_ops); |
| 3340 | if (ret) |
| 3341 | return ret; |
| 3342 | |
| 3343 | m = file->private_data; |
| 3344 | m->private = tr; |
| 3345 | |
| 3346 | return 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3347 | } |
| 3348 | |
Steven Rostedt | 4acd4d0 | 2009-03-18 10:40:24 -0400 | [diff] [blame] | 3349 | static ssize_t |
| 3350 | tracing_write_stub(struct file *filp, const char __user *ubuf, |
| 3351 | size_t count, loff_t *ppos) |
| 3352 | { |
| 3353 | return count; |
| 3354 | } |
| 3355 | |
Steven Rostedt (Red Hat) | 098c879 | 2013-12-21 17:39:40 -0500 | [diff] [blame] | 3356 | loff_t tracing_lseek(struct file *file, loff_t offset, int whence) |
Slava Pestov | 364829b | 2010-11-24 15:13:16 -0800 | [diff] [blame] | 3357 | { |
Steven Rostedt (Red Hat) | 098c879 | 2013-12-21 17:39:40 -0500 | [diff] [blame] | 3358 | int ret; |
| 3359 | |
Slava Pestov | 364829b | 2010-11-24 15:13:16 -0800 | [diff] [blame] | 3360 | if (file->f_mode & FMODE_READ) |
Steven Rostedt (Red Hat) | 098c879 | 2013-12-21 17:39:40 -0500 | [diff] [blame] | 3361 | ret = seq_lseek(file, offset, whence); |
Slava Pestov | 364829b | 2010-11-24 15:13:16 -0800 | [diff] [blame] | 3362 | else |
Steven Rostedt (Red Hat) | 098c879 | 2013-12-21 17:39:40 -0500 | [diff] [blame] | 3363 | file->f_pos = ret = 0; |
| 3364 | |
| 3365 | return ret; |
Slava Pestov | 364829b | 2010-11-24 15:13:16 -0800 | [diff] [blame] | 3366 | } |
| 3367 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 3368 | static const struct file_operations tracing_fops = { |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3369 | .open = tracing_open, |
| 3370 | .read = seq_read, |
Steven Rostedt | 4acd4d0 | 2009-03-18 10:40:24 -0400 | [diff] [blame] | 3371 | .write = tracing_write_stub, |
Steven Rostedt (Red Hat) | 098c879 | 2013-12-21 17:39:40 -0500 | [diff] [blame] | 3372 | .llseek = tracing_lseek, |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 3373 | .release = tracing_release, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3374 | }; |
| 3375 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 3376 | static const struct file_operations show_traces_fops = { |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3377 | .open = show_traces_open, |
| 3378 | .read = seq_read, |
| 3379 | .release = seq_release, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 3380 | .llseek = seq_lseek, |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3381 | }; |
| 3382 | |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3383 | /* |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3384 | * The tracer itself will not take this lock, but still we want |
| 3385 | * to provide a consistent cpumask to user-space: |
| 3386 | */ |
| 3387 | static DEFINE_MUTEX(tracing_cpumask_update_lock); |
| 3388 | |
| 3389 | /* |
| 3390 | * Temporary storage for the character representation of the |
| 3391 | * CPU bitmask (and one more byte for the newline): |
| 3392 | */ |
| 3393 | static char mask_str[NR_CPUS + 1]; |
| 3394 | |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3395 | static ssize_t |
| 3396 | tracing_cpumask_read(struct file *filp, char __user *ubuf, |
| 3397 | size_t count, loff_t *ppos) |
| 3398 | { |
Alexander Z Lam | ccfe9e4 | 2013-08-08 09:47:45 -0700 | [diff] [blame] | 3399 | struct trace_array *tr = file_inode(filp)->i_private; |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3400 | int len; |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3401 | |
| 3402 | mutex_lock(&tracing_cpumask_update_lock); |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3403 | |
Tejun Heo | 1a40243 | 2015-02-13 14:37:39 -0800 | [diff] [blame] | 3404 | len = snprintf(mask_str, count, "%*pb\n", |
| 3405 | cpumask_pr_args(tr->tracing_cpumask)); |
| 3406 | if (len >= count) { |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3407 | count = -EINVAL; |
| 3408 | goto out_err; |
| 3409 | } |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3410 | count = simple_read_from_buffer(ubuf, count, ppos, mask_str, NR_CPUS+1); |
| 3411 | |
| 3412 | out_err: |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3413 | mutex_unlock(&tracing_cpumask_update_lock); |
| 3414 | |
| 3415 | return count; |
| 3416 | } |
| 3417 | |
| 3418 | static ssize_t |
| 3419 | tracing_cpumask_write(struct file *filp, const char __user *ubuf, |
| 3420 | size_t count, loff_t *ppos) |
| 3421 | { |
Alexander Z Lam | ccfe9e4 | 2013-08-08 09:47:45 -0700 | [diff] [blame] | 3422 | struct trace_array *tr = file_inode(filp)->i_private; |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 3423 | cpumask_var_t tracing_cpumask_new; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3424 | int err, cpu; |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 3425 | |
| 3426 | if (!alloc_cpumask_var(&tracing_cpumask_new, GFP_KERNEL)) |
| 3427 | return -ENOMEM; |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3428 | |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 3429 | err = cpumask_parse_user(ubuf, count, tracing_cpumask_new); |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3430 | if (err) |
| 3431 | goto err_unlock; |
| 3432 | |
Li Zefan | 215368e | 2009-06-15 10:56:42 +0800 | [diff] [blame] | 3433 | mutex_lock(&tracing_cpumask_update_lock); |
| 3434 | |
Steven Rostedt | a5e2588 | 2008-12-02 15:34:05 -0500 | [diff] [blame] | 3435 | local_irq_disable(); |
Steven Rostedt (Red Hat) | 0b9b12c | 2014-01-14 10:04:59 -0500 | [diff] [blame] | 3436 | arch_spin_lock(&tr->max_lock); |
Steven Rostedt | ab46428 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 3437 | for_each_tracing_cpu(cpu) { |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3438 | /* |
| 3439 | * Increase/decrease the disabled counter if we are |
| 3440 | * about to flip a bit in the cpumask: |
| 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_inc(&per_cpu_ptr(tr->trace_buffer.data, cpu)->disabled); |
| 3445 | ring_buffer_record_disable_cpu(tr->trace_buffer.buffer, cpu); |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3446 | } |
Alexander Z Lam | ccfe9e4 | 2013-08-08 09:47:45 -0700 | [diff] [blame] | 3447 | if (!cpumask_test_cpu(cpu, tr->tracing_cpumask) && |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 3448 | cpumask_test_cpu(cpu, tracing_cpumask_new)) { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3449 | atomic_dec(&per_cpu_ptr(tr->trace_buffer.data, cpu)->disabled); |
| 3450 | ring_buffer_record_enable_cpu(tr->trace_buffer.buffer, cpu); |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3451 | } |
| 3452 | } |
Steven Rostedt (Red Hat) | 0b9b12c | 2014-01-14 10:04:59 -0500 | [diff] [blame] | 3453 | arch_spin_unlock(&tr->max_lock); |
Steven Rostedt | a5e2588 | 2008-12-02 15:34:05 -0500 | [diff] [blame] | 3454 | local_irq_enable(); |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3455 | |
Alexander Z Lam | ccfe9e4 | 2013-08-08 09:47:45 -0700 | [diff] [blame] | 3456 | cpumask_copy(tr->tracing_cpumask, tracing_cpumask_new); |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3457 | |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3458 | mutex_unlock(&tracing_cpumask_update_lock); |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 3459 | free_cpumask_var(tracing_cpumask_new); |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3460 | |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3461 | return count; |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3462 | |
| 3463 | err_unlock: |
Li Zefan | 215368e | 2009-06-15 10:56:42 +0800 | [diff] [blame] | 3464 | free_cpumask_var(tracing_cpumask_new); |
Ingo Molnar | 36dfe92 | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3465 | |
| 3466 | return err; |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3467 | } |
| 3468 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 3469 | static const struct file_operations tracing_cpumask_fops = { |
Alexander Z Lam | ccfe9e4 | 2013-08-08 09:47:45 -0700 | [diff] [blame] | 3470 | .open = tracing_open_generic_tr, |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3471 | .read = tracing_cpumask_read, |
| 3472 | .write = tracing_cpumask_write, |
Alexander Z Lam | ccfe9e4 | 2013-08-08 09:47:45 -0700 | [diff] [blame] | 3473 | .release = tracing_release_generic_tr, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 3474 | .llseek = generic_file_llseek, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3475 | }; |
| 3476 | |
Li Zefan | fdb372e | 2009-12-08 11:15:59 +0800 | [diff] [blame] | 3477 | static int tracing_trace_options_show(struct seq_file *m, void *v) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3478 | { |
Steven Rostedt | d8e83d2 | 2009-02-26 23:55:58 -0500 | [diff] [blame] | 3479 | struct tracer_opt *trace_opts; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3480 | struct trace_array *tr = m->private; |
Steven Rostedt | d8e83d2 | 2009-02-26 23:55:58 -0500 | [diff] [blame] | 3481 | u32 tracer_flags; |
Steven Rostedt | d8e83d2 | 2009-02-26 23:55:58 -0500 | [diff] [blame] | 3482 | int i; |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 3483 | |
Steven Rostedt | d8e83d2 | 2009-02-26 23:55:58 -0500 | [diff] [blame] | 3484 | mutex_lock(&trace_types_lock); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3485 | tracer_flags = tr->current_trace->flags->val; |
| 3486 | trace_opts = tr->current_trace->flags->opts; |
Steven Rostedt | d8e83d2 | 2009-02-26 23:55:58 -0500 | [diff] [blame] | 3487 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3488 | for (i = 0; trace_options[i]; i++) { |
Steven Rostedt (Red Hat) | 983f938 | 2015-09-30 09:42:05 -0400 | [diff] [blame] | 3489 | if (tr->trace_flags & (1 << i)) |
Li Zefan | fdb372e | 2009-12-08 11:15:59 +0800 | [diff] [blame] | 3490 | seq_printf(m, "%s\n", trace_options[i]); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3491 | else |
Li Zefan | fdb372e | 2009-12-08 11:15:59 +0800 | [diff] [blame] | 3492 | seq_printf(m, "no%s\n", trace_options[i]); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3493 | } |
| 3494 | |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 3495 | for (i = 0; trace_opts[i].name; i++) { |
| 3496 | if (tracer_flags & trace_opts[i].bit) |
Li Zefan | fdb372e | 2009-12-08 11:15:59 +0800 | [diff] [blame] | 3497 | seq_printf(m, "%s\n", trace_opts[i].name); |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 3498 | else |
Li Zefan | fdb372e | 2009-12-08 11:15:59 +0800 | [diff] [blame] | 3499 | seq_printf(m, "no%s\n", trace_opts[i].name); |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 3500 | } |
Steven Rostedt | d8e83d2 | 2009-02-26 23:55:58 -0500 | [diff] [blame] | 3501 | mutex_unlock(&trace_types_lock); |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 3502 | |
Li Zefan | fdb372e | 2009-12-08 11:15:59 +0800 | [diff] [blame] | 3503 | return 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3504 | } |
| 3505 | |
Steven Rostedt (Red Hat) | 8c1a49a | 2014-01-10 11:13:54 -0500 | [diff] [blame] | 3506 | static int __set_tracer_option(struct trace_array *tr, |
Li Zefan | 8d18eaa | 2009-12-08 11:17:06 +0800 | [diff] [blame] | 3507 | struct tracer_flags *tracer_flags, |
| 3508 | struct tracer_opt *opts, int neg) |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 3509 | { |
Steven Rostedt (Red Hat) | 8c1a49a | 2014-01-10 11:13:54 -0500 | [diff] [blame] | 3510 | struct tracer *trace = tr->current_trace; |
Li Zefan | 8d18eaa | 2009-12-08 11:17:06 +0800 | [diff] [blame] | 3511 | int ret; |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 3512 | |
Steven Rostedt (Red Hat) | 8c1a49a | 2014-01-10 11:13:54 -0500 | [diff] [blame] | 3513 | ret = trace->set_flag(tr, tracer_flags->val, opts->bit, !neg); |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 3514 | if (ret) |
| 3515 | return ret; |
| 3516 | |
| 3517 | if (neg) |
Zhaolei | 7770841 | 2009-08-07 18:53:21 +0800 | [diff] [blame] | 3518 | tracer_flags->val &= ~opts->bit; |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 3519 | else |
Zhaolei | 7770841 | 2009-08-07 18:53:21 +0800 | [diff] [blame] | 3520 | tracer_flags->val |= opts->bit; |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 3521 | return 0; |
| 3522 | } |
| 3523 | |
Li Zefan | 8d18eaa | 2009-12-08 11:17:06 +0800 | [diff] [blame] | 3524 | /* Try to assign a tracer specific option */ |
Steven Rostedt (Red Hat) | 8c1a49a | 2014-01-10 11:13:54 -0500 | [diff] [blame] | 3525 | 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] | 3526 | { |
Steven Rostedt (Red Hat) | 8c1a49a | 2014-01-10 11:13:54 -0500 | [diff] [blame] | 3527 | struct tracer *trace = tr->current_trace; |
Li Zefan | 8d18eaa | 2009-12-08 11:17:06 +0800 | [diff] [blame] | 3528 | struct tracer_flags *tracer_flags = trace->flags; |
| 3529 | struct tracer_opt *opts = NULL; |
| 3530 | int i; |
| 3531 | |
| 3532 | for (i = 0; tracer_flags->opts[i].name; i++) { |
| 3533 | opts = &tracer_flags->opts[i]; |
| 3534 | |
| 3535 | if (strcmp(cmp, opts->name) == 0) |
Steven Rostedt (Red Hat) | 8c1a49a | 2014-01-10 11:13:54 -0500 | [diff] [blame] | 3536 | return __set_tracer_option(tr, trace->flags, opts, neg); |
Li Zefan | 8d18eaa | 2009-12-08 11:17:06 +0800 | [diff] [blame] | 3537 | } |
| 3538 | |
| 3539 | return -EINVAL; |
| 3540 | } |
| 3541 | |
Steven Rostedt (Red Hat) | 613f04a | 2013-03-14 15:03:53 -0400 | [diff] [blame] | 3542 | /* Some tracers require overwrite to stay enabled */ |
| 3543 | int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set) |
| 3544 | { |
| 3545 | if (tracer->enabled && (mask & TRACE_ITER_OVERWRITE) && !set) |
| 3546 | return -1; |
| 3547 | |
| 3548 | return 0; |
| 3549 | } |
| 3550 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3551 | 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] | 3552 | { |
| 3553 | /* do nothing if flag is already set */ |
Steven Rostedt (Red Hat) | 983f938 | 2015-09-30 09:42:05 -0400 | [diff] [blame] | 3554 | if (!!(tr->trace_flags & mask) == !!enabled) |
Steven Rostedt (Red Hat) | 613f04a | 2013-03-14 15:03:53 -0400 | [diff] [blame] | 3555 | return 0; |
| 3556 | |
| 3557 | /* Give the tracer a chance to approve the change */ |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3558 | if (tr->current_trace->flag_changed) |
Steven Rostedt (Red Hat) | bf6065b | 2014-01-10 17:51:01 -0500 | [diff] [blame] | 3559 | if (tr->current_trace->flag_changed(tr, mask, !!enabled)) |
Steven Rostedt (Red Hat) | 613f04a | 2013-03-14 15:03:53 -0400 | [diff] [blame] | 3560 | return -EINVAL; |
Steven Rostedt | af4617b | 2009-03-17 18:09:55 -0400 | [diff] [blame] | 3561 | |
| 3562 | if (enabled) |
Steven Rostedt (Red Hat) | 983f938 | 2015-09-30 09:42:05 -0400 | [diff] [blame] | 3563 | tr->trace_flags |= mask; |
Steven Rostedt | af4617b | 2009-03-17 18:09:55 -0400 | [diff] [blame] | 3564 | else |
Steven Rostedt (Red Hat) | 983f938 | 2015-09-30 09:42:05 -0400 | [diff] [blame] | 3565 | tr->trace_flags &= ~mask; |
Li Zefan | e870e9a | 2010-07-02 11:07:32 +0800 | [diff] [blame] | 3566 | |
| 3567 | if (mask == TRACE_ITER_RECORD_CMD) |
| 3568 | trace_event_enable_cmd_record(enabled); |
David Sharp | 750912f | 2010-12-08 13:46:47 -0800 | [diff] [blame] | 3569 | |
Steven Rostedt (Red Hat) | 8090282 | 2013-03-14 14:20:54 -0400 | [diff] [blame] | 3570 | if (mask == TRACE_ITER_OVERWRITE) { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3571 | ring_buffer_change_overwrite(tr->trace_buffer.buffer, enabled); |
Steven Rostedt (Red Hat) | 8090282 | 2013-03-14 14:20:54 -0400 | [diff] [blame] | 3572 | #ifdef CONFIG_TRACER_MAX_TRACE |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 3573 | ring_buffer_change_overwrite(tr->max_buffer.buffer, enabled); |
Steven Rostedt (Red Hat) | 8090282 | 2013-03-14 14:20:54 -0400 | [diff] [blame] | 3574 | #endif |
| 3575 | } |
Steven Rostedt | 8169883 | 2012-10-11 10:15:05 -0400 | [diff] [blame] | 3576 | |
Steven Rostedt (Red Hat) | b9f9108 | 2015-09-29 18:21:35 -0400 | [diff] [blame] | 3577 | if (mask == TRACE_ITER_PRINTK) { |
Steven Rostedt | 8169883 | 2012-10-11 10:15:05 -0400 | [diff] [blame] | 3578 | trace_printk_start_stop_comm(enabled); |
Steven Rostedt (Red Hat) | b9f9108 | 2015-09-29 18:21:35 -0400 | [diff] [blame] | 3579 | trace_printk_control(enabled); |
| 3580 | } |
Steven Rostedt (Red Hat) | 613f04a | 2013-03-14 15:03:53 -0400 | [diff] [blame] | 3581 | |
| 3582 | return 0; |
Steven Rostedt | af4617b | 2009-03-17 18:09:55 -0400 | [diff] [blame] | 3583 | } |
| 3584 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3585 | static int trace_set_options(struct trace_array *tr, char *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 | char *cmp; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3588 | int neg = 0; |
Steven Rostedt (Red Hat) | 613f04a | 2013-03-14 15:03:53 -0400 | [diff] [blame] | 3589 | int ret = -ENODEV; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3590 | int i; |
| 3591 | |
Steven Rostedt | 7bcfaf5 | 2012-11-01 22:56:07 -0400 | [diff] [blame] | 3592 | cmp = strstrip(option); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3593 | |
Li Zefan | 8d18eaa | 2009-12-08 11:17:06 +0800 | [diff] [blame] | 3594 | if (strncmp(cmp, "no", 2) == 0) { |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3595 | neg = 1; |
| 3596 | cmp += 2; |
| 3597 | } |
| 3598 | |
Steven Rostedt (Red Hat) | 69d34da | 2013-03-14 13:50:56 -0400 | [diff] [blame] | 3599 | mutex_lock(&trace_types_lock); |
| 3600 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3601 | for (i = 0; trace_options[i]; i++) { |
Li Zefan | 8d18eaa | 2009-12-08 11:17:06 +0800 | [diff] [blame] | 3602 | if (strcmp(cmp, trace_options[i]) == 0) { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3603 | ret = set_tracer_flag(tr, 1 << i, !neg); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3604 | break; |
| 3605 | } |
| 3606 | } |
Frederic Weisbecker | adf9f19 | 2008-11-17 19:23:42 +0100 | [diff] [blame] | 3607 | |
| 3608 | /* 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] | 3609 | if (!trace_options[i]) |
Steven Rostedt (Red Hat) | 8c1a49a | 2014-01-10 11:13:54 -0500 | [diff] [blame] | 3610 | ret = set_tracer_option(tr, cmp, neg); |
Steven Rostedt (Red Hat) | 69d34da | 2013-03-14 13:50:56 -0400 | [diff] [blame] | 3611 | |
| 3612 | mutex_unlock(&trace_types_lock); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3613 | |
Steven Rostedt | 7bcfaf5 | 2012-11-01 22:56:07 -0400 | [diff] [blame] | 3614 | return ret; |
| 3615 | } |
| 3616 | |
| 3617 | static ssize_t |
| 3618 | tracing_trace_options_write(struct file *filp, const char __user *ubuf, |
| 3619 | size_t cnt, loff_t *ppos) |
| 3620 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3621 | struct seq_file *m = filp->private_data; |
| 3622 | struct trace_array *tr = m->private; |
Steven Rostedt | 7bcfaf5 | 2012-11-01 22:56:07 -0400 | [diff] [blame] | 3623 | char buf[64]; |
Steven Rostedt (Red Hat) | 613f04a | 2013-03-14 15:03:53 -0400 | [diff] [blame] | 3624 | int ret; |
Steven Rostedt | 7bcfaf5 | 2012-11-01 22:56:07 -0400 | [diff] [blame] | 3625 | |
| 3626 | if (cnt >= sizeof(buf)) |
| 3627 | return -EINVAL; |
| 3628 | |
| 3629 | if (copy_from_user(&buf, ubuf, cnt)) |
| 3630 | return -EFAULT; |
| 3631 | |
Steven Rostedt | a8dd217 | 2013-01-09 20:54:17 -0500 | [diff] [blame] | 3632 | buf[cnt] = 0; |
| 3633 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3634 | ret = trace_set_options(tr, buf); |
Steven Rostedt (Red Hat) | 613f04a | 2013-03-14 15:03:53 -0400 | [diff] [blame] | 3635 | if (ret < 0) |
| 3636 | return ret; |
Steven Rostedt | 7bcfaf5 | 2012-11-01 22:56:07 -0400 | [diff] [blame] | 3637 | |
Jiri Olsa | cf8517c | 2009-10-23 19:36:16 -0400 | [diff] [blame] | 3638 | *ppos += cnt; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3639 | |
| 3640 | return cnt; |
| 3641 | } |
| 3642 | |
Li Zefan | fdb372e | 2009-12-08 11:15:59 +0800 | [diff] [blame] | 3643 | static int tracing_trace_options_open(struct inode *inode, struct file *file) |
| 3644 | { |
Steven Rostedt (Red Hat) | 7b85af6 | 2013-07-01 23:34:22 -0400 | [diff] [blame] | 3645 | struct trace_array *tr = inode->i_private; |
Alexander Z Lam | f77d09a | 2013-07-18 11:18:44 -0700 | [diff] [blame] | 3646 | int ret; |
Steven Rostedt (Red Hat) | 7b85af6 | 2013-07-01 23:34:22 -0400 | [diff] [blame] | 3647 | |
Li Zefan | fdb372e | 2009-12-08 11:15:59 +0800 | [diff] [blame] | 3648 | if (tracing_disabled) |
| 3649 | return -ENODEV; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 3650 | |
Steven Rostedt (Red Hat) | 7b85af6 | 2013-07-01 23:34:22 -0400 | [diff] [blame] | 3651 | if (trace_array_get(tr) < 0) |
| 3652 | return -ENODEV; |
| 3653 | |
Alexander Z Lam | f77d09a | 2013-07-18 11:18:44 -0700 | [diff] [blame] | 3654 | ret = single_open(file, tracing_trace_options_show, inode->i_private); |
| 3655 | if (ret < 0) |
| 3656 | trace_array_put(tr); |
| 3657 | |
| 3658 | return ret; |
Li Zefan | fdb372e | 2009-12-08 11:15:59 +0800 | [diff] [blame] | 3659 | } |
| 3660 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 3661 | static const struct file_operations tracing_iter_fops = { |
Li Zefan | fdb372e | 2009-12-08 11:15:59 +0800 | [diff] [blame] | 3662 | .open = tracing_trace_options_open, |
| 3663 | .read = seq_read, |
| 3664 | .llseek = seq_lseek, |
Steven Rostedt (Red Hat) | 7b85af6 | 2013-07-01 23:34:22 -0400 | [diff] [blame] | 3665 | .release = tracing_single_release_tr, |
Steven Rostedt | ee6bce5 | 2008-11-12 17:52:37 -0500 | [diff] [blame] | 3666 | .write = tracing_trace_options_write, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3667 | }; |
| 3668 | |
Ingo Molnar | 7bd2f24 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 3669 | static const char readme_msg[] = |
| 3670 | "tracing mini-HOWTO:\n\n" |
Steven Rostedt (Red Hat) | 22f4564 | 2013-03-15 17:23:20 -0400 | [diff] [blame] | 3671 | "# echo 0 > tracing_on : quick way to disable tracing\n" |
| 3672 | "# echo 1 > tracing_on : quick way to re-enable tracing\n\n" |
| 3673 | " Important files:\n" |
| 3674 | " trace\t\t\t- The static contents of the buffer\n" |
| 3675 | "\t\t\t To clear the buffer write into this file: echo > trace\n" |
| 3676 | " trace_pipe\t\t- A consuming read to see the contents of the buffer\n" |
| 3677 | " current_tracer\t- function and latency tracers\n" |
| 3678 | " available_tracers\t- list of configured tracers for current_tracer\n" |
| 3679 | " buffer_size_kb\t- view and modify size of per cpu buffer\n" |
| 3680 | " buffer_total_size_kb - view total size of all cpu buffers\n\n" |
| 3681 | " trace_clock\t\t-change the clock used to order events\n" |
| 3682 | " local: Per cpu clock but may not be synced across CPUs\n" |
| 3683 | " global: Synced across CPUs but slows tracing down.\n" |
| 3684 | " counter: Not a clock, but just an increment\n" |
| 3685 | " uptime: Jiffy counter from time of boot\n" |
| 3686 | " perf: Same clock that perf events use\n" |
| 3687 | #ifdef CONFIG_X86_64 |
| 3688 | " x86-tsc: TSC cycle counter\n" |
| 3689 | #endif |
| 3690 | "\n trace_marker\t\t- Writes into this file writes into the kernel buffer\n" |
| 3691 | " tracing_cpumask\t- Limit which CPUs to trace\n" |
| 3692 | " instances\t\t- Make sub-buffers with: mkdir instances/foo\n" |
| 3693 | "\t\t\t Remove sub-buffer with rmdir\n" |
| 3694 | " 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] | 3695 | "\t\t\t Disable an option by adding a suffix 'no' to the\n" |
| 3696 | "\t\t\t option name\n" |
Yoshihiro YUNOMAE | 939c7a4 | 2014-06-05 10:24:27 +0900 | [diff] [blame] | 3697 | " 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] | 3698 | #ifdef CONFIG_DYNAMIC_FTRACE |
| 3699 | "\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] | 3700 | " set_ftrace_filter\t- echo function name in here to only trace these\n" |
| 3701 | "\t\t\t functions\n" |
| 3702 | "\t accepts: func_full_name, *func_end, func_begin*, *func_middle*\n" |
| 3703 | "\t modules: Can select a group via module\n" |
| 3704 | "\t Format: :mod:<module-name>\n" |
| 3705 | "\t example: echo :mod:ext3 > set_ftrace_filter\n" |
| 3706 | "\t triggers: a command to perform when function is hit\n" |
| 3707 | "\t Format: <function>:<trigger>[:count]\n" |
| 3708 | "\t trigger: traceon, traceoff\n" |
| 3709 | "\t\t enable_event:<system>:<event>\n" |
| 3710 | "\t\t disable_event:<system>:<event>\n" |
Steven Rostedt (Red Hat) | 22f4564 | 2013-03-15 17:23:20 -0400 | [diff] [blame] | 3711 | #ifdef CONFIG_STACKTRACE |
Steven Rostedt (Red Hat) | 71485c4 | 2014-01-23 00:10:04 -0500 | [diff] [blame] | 3712 | "\t\t stacktrace\n" |
Steven Rostedt (Red Hat) | 22f4564 | 2013-03-15 17:23:20 -0400 | [diff] [blame] | 3713 | #endif |
| 3714 | #ifdef CONFIG_TRACER_SNAPSHOT |
Steven Rostedt (Red Hat) | 71485c4 | 2014-01-23 00:10:04 -0500 | [diff] [blame] | 3715 | "\t\t snapshot\n" |
Steven Rostedt (Red Hat) | 22f4564 | 2013-03-15 17:23:20 -0400 | [diff] [blame] | 3716 | #endif |
Steven Rostedt (Red Hat) | 17a280e | 2014-04-10 22:43:37 -0400 | [diff] [blame] | 3717 | "\t\t dump\n" |
| 3718 | "\t\t cpudump\n" |
Steven Rostedt (Red Hat) | 71485c4 | 2014-01-23 00:10:04 -0500 | [diff] [blame] | 3719 | "\t example: echo do_fault:traceoff > set_ftrace_filter\n" |
| 3720 | "\t echo do_trap:traceoff:3 > set_ftrace_filter\n" |
| 3721 | "\t The first one will disable tracing every time do_fault is hit\n" |
| 3722 | "\t The second will disable tracing at most 3 times when do_trap is hit\n" |
| 3723 | "\t The first time do trap is hit and it disables tracing, the\n" |
| 3724 | "\t counter will decrement to 2. If tracing is already disabled,\n" |
| 3725 | "\t the counter will not decrement. It only decrements when the\n" |
| 3726 | "\t trigger did work\n" |
| 3727 | "\t To remove trigger without count:\n" |
| 3728 | "\t echo '!<function>:<trigger> > set_ftrace_filter\n" |
| 3729 | "\t To remove trigger with a count:\n" |
| 3730 | "\t echo '!<function>:<trigger>:0 > set_ftrace_filter\n" |
Steven Rostedt (Red Hat) | 22f4564 | 2013-03-15 17:23:20 -0400 | [diff] [blame] | 3731 | " 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] | 3732 | "\t accepts: func_full_name, *func_end, func_begin*, *func_middle*\n" |
| 3733 | "\t modules: Can select a group via module command :mod:\n" |
| 3734 | "\t Does not accept triggers\n" |
Steven Rostedt (Red Hat) | 22f4564 | 2013-03-15 17:23:20 -0400 | [diff] [blame] | 3735 | #endif /* CONFIG_DYNAMIC_FTRACE */ |
| 3736 | #ifdef CONFIG_FUNCTION_TRACER |
Steven Rostedt (Red Hat) | 71485c4 | 2014-01-23 00:10:04 -0500 | [diff] [blame] | 3737 | " set_ftrace_pid\t- Write pid(s) to only function trace those pids\n" |
| 3738 | "\t\t (function)\n" |
Steven Rostedt (Red Hat) | 22f4564 | 2013-03-15 17:23:20 -0400 | [diff] [blame] | 3739 | #endif |
| 3740 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER |
| 3741 | " 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] | 3742 | " 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] | 3743 | " max_graph_depth\t- Trace a limited depth of nested calls (0 is unlimited)\n" |
| 3744 | #endif |
| 3745 | #ifdef CONFIG_TRACER_SNAPSHOT |
Steven Rostedt (Red Hat) | 71485c4 | 2014-01-23 00:10:04 -0500 | [diff] [blame] | 3746 | "\n snapshot\t\t- Like 'trace' but shows the content of the static\n" |
| 3747 | "\t\t\t snapshot buffer. Read the contents for more\n" |
| 3748 | "\t\t\t information\n" |
Steven Rostedt (Red Hat) | 22f4564 | 2013-03-15 17:23:20 -0400 | [diff] [blame] | 3749 | #endif |
zhangwei(Jovi) | 991821c | 2013-07-15 16:32:34 +0800 | [diff] [blame] | 3750 | #ifdef CONFIG_STACK_TRACER |
Steven Rostedt (Red Hat) | 22f4564 | 2013-03-15 17:23:20 -0400 | [diff] [blame] | 3751 | " stack_trace\t\t- Shows the max stack trace when active\n" |
| 3752 | " 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] | 3753 | "\t\t\t Write into this file to reset the max size (trigger a\n" |
| 3754 | "\t\t\t new trace)\n" |
Steven Rostedt (Red Hat) | 22f4564 | 2013-03-15 17:23:20 -0400 | [diff] [blame] | 3755 | #ifdef CONFIG_DYNAMIC_FTRACE |
Steven Rostedt (Red Hat) | 71485c4 | 2014-01-23 00:10:04 -0500 | [diff] [blame] | 3756 | " stack_trace_filter\t- Like set_ftrace_filter but limits what stack_trace\n" |
| 3757 | "\t\t\t traces\n" |
Steven Rostedt (Red Hat) | 22f4564 | 2013-03-15 17:23:20 -0400 | [diff] [blame] | 3758 | #endif |
zhangwei(Jovi) | 991821c | 2013-07-15 16:32:34 +0800 | [diff] [blame] | 3759 | #endif /* CONFIG_STACK_TRACER */ |
Tom Zanussi | 26f2556 | 2014-01-17 15:11:44 -0600 | [diff] [blame] | 3760 | " events/\t\t- Directory containing all trace event subsystems:\n" |
| 3761 | " enable\t\t- Write 0/1 to enable/disable tracing of all events\n" |
| 3762 | " 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] | 3763 | " enable\t\t- Write 0/1 to enable/disable tracing of all <system>\n" |
| 3764 | "\t\t\t events\n" |
Tom Zanussi | 26f2556 | 2014-01-17 15:11:44 -0600 | [diff] [blame] | 3765 | " 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] | 3766 | " events/<system>/<event>/\t- Directory containing control files for\n" |
| 3767 | "\t\t\t <event>:\n" |
Tom Zanussi | 26f2556 | 2014-01-17 15:11:44 -0600 | [diff] [blame] | 3768 | " enable\t\t- Write 0/1 to enable/disable tracing of <event>\n" |
| 3769 | " filter\t\t- If set, only events passing filter are traced\n" |
| 3770 | " 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] | 3771 | "\t Format: <trigger>[:count][if <filter>]\n" |
| 3772 | "\t trigger: traceon, traceoff\n" |
| 3773 | "\t enable_event:<system>:<event>\n" |
| 3774 | "\t disable_event:<system>:<event>\n" |
Tom Zanussi | 26f2556 | 2014-01-17 15:11:44 -0600 | [diff] [blame] | 3775 | #ifdef CONFIG_STACKTRACE |
Steven Rostedt (Red Hat) | 71485c4 | 2014-01-23 00:10:04 -0500 | [diff] [blame] | 3776 | "\t\t stacktrace\n" |
Tom Zanussi | 26f2556 | 2014-01-17 15:11:44 -0600 | [diff] [blame] | 3777 | #endif |
| 3778 | #ifdef CONFIG_TRACER_SNAPSHOT |
Steven Rostedt (Red Hat) | 71485c4 | 2014-01-23 00:10:04 -0500 | [diff] [blame] | 3779 | "\t\t snapshot\n" |
Tom Zanussi | 26f2556 | 2014-01-17 15:11:44 -0600 | [diff] [blame] | 3780 | #endif |
Steven Rostedt (Red Hat) | 71485c4 | 2014-01-23 00:10:04 -0500 | [diff] [blame] | 3781 | "\t example: echo traceoff > events/block/block_unplug/trigger\n" |
| 3782 | "\t echo traceoff:3 > events/block/block_unplug/trigger\n" |
| 3783 | "\t echo 'enable_event:kmem:kmalloc:3 if nr_rq > 1' > \\\n" |
| 3784 | "\t events/block/block_unplug/trigger\n" |
| 3785 | "\t The first disables tracing every time block_unplug is hit.\n" |
| 3786 | "\t The second disables tracing the first 3 times block_unplug is hit.\n" |
| 3787 | "\t The third enables the kmalloc event the first 3 times block_unplug\n" |
| 3788 | "\t is hit and has value of greater than 1 for the 'nr_rq' event field.\n" |
| 3789 | "\t Like function triggers, the counter is only decremented if it\n" |
| 3790 | "\t enabled or disabled tracing.\n" |
| 3791 | "\t To remove a trigger without a count:\n" |
| 3792 | "\t echo '!<trigger> > <system>/<event>/trigger\n" |
| 3793 | "\t To remove a trigger with a count:\n" |
| 3794 | "\t echo '!<trigger>:0 > <system>/<event>/trigger\n" |
| 3795 | "\t Filters can be ignored when removing a trigger.\n" |
Ingo Molnar | 7bd2f24 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 3796 | ; |
| 3797 | |
| 3798 | static ssize_t |
| 3799 | tracing_readme_read(struct file *filp, char __user *ubuf, |
| 3800 | size_t cnt, loff_t *ppos) |
| 3801 | { |
| 3802 | return simple_read_from_buffer(ubuf, cnt, ppos, |
| 3803 | readme_msg, strlen(readme_msg)); |
| 3804 | } |
| 3805 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 3806 | static const struct file_operations tracing_readme_fops = { |
Ingo Molnar | c7078de | 2008-05-12 21:20:52 +0200 | [diff] [blame] | 3807 | .open = tracing_open_generic, |
| 3808 | .read = tracing_readme_read, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 3809 | .llseek = generic_file_llseek, |
Ingo Molnar | 7bd2f24 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 3810 | }; |
| 3811 | |
Yoshihiro YUNOMAE | 42584c8 | 2014-02-20 17:44:31 +0900 | [diff] [blame] | 3812 | 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] | 3813 | { |
Yoshihiro YUNOMAE | 42584c8 | 2014-02-20 17:44:31 +0900 | [diff] [blame] | 3814 | unsigned int *ptr = v; |
Avadh Patel | 69abe6a | 2009-04-10 16:04:48 -0400 | [diff] [blame] | 3815 | |
Yoshihiro YUNOMAE | 42584c8 | 2014-02-20 17:44:31 +0900 | [diff] [blame] | 3816 | if (*pos || m->count) |
| 3817 | ptr++; |
Avadh Patel | 69abe6a | 2009-04-10 16:04:48 -0400 | [diff] [blame] | 3818 | |
Yoshihiro YUNOMAE | 42584c8 | 2014-02-20 17:44:31 +0900 | [diff] [blame] | 3819 | (*pos)++; |
Avadh Patel | 69abe6a | 2009-04-10 16:04:48 -0400 | [diff] [blame] | 3820 | |
Yoshihiro YUNOMAE | 939c7a4 | 2014-06-05 10:24:27 +0900 | [diff] [blame] | 3821 | for (; ptr < &savedcmd->map_cmdline_to_pid[savedcmd->cmdline_num]; |
| 3822 | ptr++) { |
Yoshihiro YUNOMAE | 42584c8 | 2014-02-20 17:44:31 +0900 | [diff] [blame] | 3823 | if (*ptr == -1 || *ptr == NO_CMDLINE_MAP) |
Avadh Patel | 69abe6a | 2009-04-10 16:04:48 -0400 | [diff] [blame] | 3824 | continue; |
| 3825 | |
Yoshihiro YUNOMAE | 42584c8 | 2014-02-20 17:44:31 +0900 | [diff] [blame] | 3826 | return ptr; |
Avadh Patel | 69abe6a | 2009-04-10 16:04:48 -0400 | [diff] [blame] | 3827 | } |
| 3828 | |
Yoshihiro YUNOMAE | 42584c8 | 2014-02-20 17:44:31 +0900 | [diff] [blame] | 3829 | return NULL; |
| 3830 | } |
Avadh Patel | 69abe6a | 2009-04-10 16:04:48 -0400 | [diff] [blame] | 3831 | |
Yoshihiro YUNOMAE | 42584c8 | 2014-02-20 17:44:31 +0900 | [diff] [blame] | 3832 | static void *saved_cmdlines_start(struct seq_file *m, loff_t *pos) |
| 3833 | { |
| 3834 | void *v; |
| 3835 | loff_t l = 0; |
Avadh Patel | 69abe6a | 2009-04-10 16:04:48 -0400 | [diff] [blame] | 3836 | |
Steven Rostedt (Red Hat) | 4c27e75 | 2014-05-30 10:49:46 -0400 | [diff] [blame] | 3837 | preempt_disable(); |
| 3838 | arch_spin_lock(&trace_cmdline_lock); |
| 3839 | |
Yoshihiro YUNOMAE | 939c7a4 | 2014-06-05 10:24:27 +0900 | [diff] [blame] | 3840 | v = &savedcmd->map_cmdline_to_pid[0]; |
Yoshihiro YUNOMAE | 42584c8 | 2014-02-20 17:44:31 +0900 | [diff] [blame] | 3841 | while (l <= *pos) { |
| 3842 | v = saved_cmdlines_next(m, v, &l); |
| 3843 | if (!v) |
| 3844 | return NULL; |
| 3845 | } |
| 3846 | |
| 3847 | return v; |
| 3848 | } |
| 3849 | |
| 3850 | static void saved_cmdlines_stop(struct seq_file *m, void *v) |
| 3851 | { |
Steven Rostedt (Red Hat) | 4c27e75 | 2014-05-30 10:49:46 -0400 | [diff] [blame] | 3852 | arch_spin_unlock(&trace_cmdline_lock); |
| 3853 | preempt_enable(); |
Yoshihiro YUNOMAE | 42584c8 | 2014-02-20 17:44:31 +0900 | [diff] [blame] | 3854 | } |
| 3855 | |
| 3856 | static int saved_cmdlines_show(struct seq_file *m, void *v) |
| 3857 | { |
| 3858 | char buf[TASK_COMM_LEN]; |
| 3859 | unsigned int *pid = v; |
| 3860 | |
Steven Rostedt (Red Hat) | 4c27e75 | 2014-05-30 10:49:46 -0400 | [diff] [blame] | 3861 | __trace_find_cmdline(*pid, buf); |
Yoshihiro YUNOMAE | 42584c8 | 2014-02-20 17:44:31 +0900 | [diff] [blame] | 3862 | seq_printf(m, "%d %s\n", *pid, buf); |
| 3863 | return 0; |
| 3864 | } |
| 3865 | |
| 3866 | static const struct seq_operations tracing_saved_cmdlines_seq_ops = { |
| 3867 | .start = saved_cmdlines_start, |
| 3868 | .next = saved_cmdlines_next, |
| 3869 | .stop = saved_cmdlines_stop, |
| 3870 | .show = saved_cmdlines_show, |
| 3871 | }; |
| 3872 | |
| 3873 | static int tracing_saved_cmdlines_open(struct inode *inode, struct file *filp) |
| 3874 | { |
| 3875 | if (tracing_disabled) |
| 3876 | return -ENODEV; |
| 3877 | |
| 3878 | return seq_open(filp, &tracing_saved_cmdlines_seq_ops); |
Avadh Patel | 69abe6a | 2009-04-10 16:04:48 -0400 | [diff] [blame] | 3879 | } |
| 3880 | |
| 3881 | static const struct file_operations tracing_saved_cmdlines_fops = { |
Yoshihiro YUNOMAE | 42584c8 | 2014-02-20 17:44:31 +0900 | [diff] [blame] | 3882 | .open = tracing_saved_cmdlines_open, |
| 3883 | .read = seq_read, |
| 3884 | .llseek = seq_lseek, |
| 3885 | .release = seq_release, |
Avadh Patel | 69abe6a | 2009-04-10 16:04:48 -0400 | [diff] [blame] | 3886 | }; |
| 3887 | |
| 3888 | static ssize_t |
Yoshihiro YUNOMAE | 939c7a4 | 2014-06-05 10:24:27 +0900 | [diff] [blame] | 3889 | tracing_saved_cmdlines_size_read(struct file *filp, char __user *ubuf, |
| 3890 | size_t cnt, loff_t *ppos) |
| 3891 | { |
| 3892 | char buf[64]; |
| 3893 | int r; |
| 3894 | |
| 3895 | arch_spin_lock(&trace_cmdline_lock); |
Namhyung Kim | a6af8fb | 2014-06-10 16:11:35 +0900 | [diff] [blame] | 3896 | r = scnprintf(buf, sizeof(buf), "%u\n", savedcmd->cmdline_num); |
Yoshihiro YUNOMAE | 939c7a4 | 2014-06-05 10:24:27 +0900 | [diff] [blame] | 3897 | arch_spin_unlock(&trace_cmdline_lock); |
| 3898 | |
| 3899 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, r); |
| 3900 | } |
| 3901 | |
| 3902 | static void free_saved_cmdlines_buffer(struct saved_cmdlines_buffer *s) |
| 3903 | { |
| 3904 | kfree(s->saved_cmdlines); |
| 3905 | kfree(s->map_cmdline_to_pid); |
| 3906 | kfree(s); |
| 3907 | } |
| 3908 | |
| 3909 | static int tracing_resize_saved_cmdlines(unsigned int val) |
| 3910 | { |
| 3911 | struct saved_cmdlines_buffer *s, *savedcmd_temp; |
| 3912 | |
Namhyung Kim | a6af8fb | 2014-06-10 16:11:35 +0900 | [diff] [blame] | 3913 | s = kmalloc(sizeof(*s), GFP_KERNEL); |
Yoshihiro YUNOMAE | 939c7a4 | 2014-06-05 10:24:27 +0900 | [diff] [blame] | 3914 | if (!s) |
| 3915 | return -ENOMEM; |
| 3916 | |
| 3917 | if (allocate_cmdlines_buffer(val, s) < 0) { |
| 3918 | kfree(s); |
| 3919 | return -ENOMEM; |
| 3920 | } |
| 3921 | |
| 3922 | arch_spin_lock(&trace_cmdline_lock); |
| 3923 | savedcmd_temp = savedcmd; |
| 3924 | savedcmd = s; |
| 3925 | arch_spin_unlock(&trace_cmdline_lock); |
| 3926 | free_saved_cmdlines_buffer(savedcmd_temp); |
| 3927 | |
| 3928 | return 0; |
| 3929 | } |
| 3930 | |
| 3931 | static ssize_t |
| 3932 | tracing_saved_cmdlines_size_write(struct file *filp, const char __user *ubuf, |
| 3933 | size_t cnt, loff_t *ppos) |
| 3934 | { |
| 3935 | unsigned long val; |
| 3936 | int ret; |
| 3937 | |
| 3938 | ret = kstrtoul_from_user(ubuf, cnt, 10, &val); |
| 3939 | if (ret) |
| 3940 | return ret; |
| 3941 | |
| 3942 | /* must have at least 1 entry or less than PID_MAX_DEFAULT */ |
| 3943 | if (!val || val > PID_MAX_DEFAULT) |
| 3944 | return -EINVAL; |
| 3945 | |
| 3946 | ret = tracing_resize_saved_cmdlines((unsigned int)val); |
| 3947 | if (ret < 0) |
| 3948 | return ret; |
| 3949 | |
| 3950 | *ppos += cnt; |
| 3951 | |
| 3952 | return cnt; |
| 3953 | } |
| 3954 | |
| 3955 | static const struct file_operations tracing_saved_cmdlines_size_fops = { |
| 3956 | .open = tracing_open_generic, |
| 3957 | .read = tracing_saved_cmdlines_size_read, |
| 3958 | .write = tracing_saved_cmdlines_size_write, |
| 3959 | }; |
| 3960 | |
Steven Rostedt (Red Hat) | 9828413 | 2015-03-31 17:23:45 -0400 | [diff] [blame] | 3961 | #ifdef CONFIG_TRACE_ENUM_MAP_FILE |
| 3962 | static union trace_enum_map_item * |
| 3963 | update_enum_map(union trace_enum_map_item *ptr) |
| 3964 | { |
| 3965 | if (!ptr->map.enum_string) { |
| 3966 | if (ptr->tail.next) { |
| 3967 | ptr = ptr->tail.next; |
| 3968 | /* Set ptr to the next real item (skip head) */ |
| 3969 | ptr++; |
| 3970 | } else |
| 3971 | return NULL; |
| 3972 | } |
| 3973 | return ptr; |
| 3974 | } |
| 3975 | |
| 3976 | static void *enum_map_next(struct seq_file *m, void *v, loff_t *pos) |
| 3977 | { |
| 3978 | union trace_enum_map_item *ptr = v; |
| 3979 | |
| 3980 | /* |
| 3981 | * Paranoid! If ptr points to end, we don't want to increment past it. |
| 3982 | * This really should never happen. |
| 3983 | */ |
| 3984 | ptr = update_enum_map(ptr); |
| 3985 | if (WARN_ON_ONCE(!ptr)) |
| 3986 | return NULL; |
| 3987 | |
| 3988 | ptr++; |
| 3989 | |
| 3990 | (*pos)++; |
| 3991 | |
| 3992 | ptr = update_enum_map(ptr); |
| 3993 | |
| 3994 | return ptr; |
| 3995 | } |
| 3996 | |
| 3997 | static void *enum_map_start(struct seq_file *m, loff_t *pos) |
| 3998 | { |
| 3999 | union trace_enum_map_item *v; |
| 4000 | loff_t l = 0; |
| 4001 | |
| 4002 | mutex_lock(&trace_enum_mutex); |
| 4003 | |
| 4004 | v = trace_enum_maps; |
| 4005 | if (v) |
| 4006 | v++; |
| 4007 | |
| 4008 | while (v && l < *pos) { |
| 4009 | v = enum_map_next(m, v, &l); |
| 4010 | } |
| 4011 | |
| 4012 | return v; |
| 4013 | } |
| 4014 | |
| 4015 | static void enum_map_stop(struct seq_file *m, void *v) |
| 4016 | { |
| 4017 | mutex_unlock(&trace_enum_mutex); |
| 4018 | } |
| 4019 | |
| 4020 | static int enum_map_show(struct seq_file *m, void *v) |
| 4021 | { |
| 4022 | union trace_enum_map_item *ptr = v; |
| 4023 | |
| 4024 | seq_printf(m, "%s %ld (%s)\n", |
| 4025 | ptr->map.enum_string, ptr->map.enum_value, |
| 4026 | ptr->map.system); |
| 4027 | |
| 4028 | return 0; |
| 4029 | } |
| 4030 | |
| 4031 | static const struct seq_operations tracing_enum_map_seq_ops = { |
| 4032 | .start = enum_map_start, |
| 4033 | .next = enum_map_next, |
| 4034 | .stop = enum_map_stop, |
| 4035 | .show = enum_map_show, |
| 4036 | }; |
| 4037 | |
| 4038 | static int tracing_enum_map_open(struct inode *inode, struct file *filp) |
| 4039 | { |
| 4040 | if (tracing_disabled) |
| 4041 | return -ENODEV; |
| 4042 | |
| 4043 | return seq_open(filp, &tracing_enum_map_seq_ops); |
| 4044 | } |
| 4045 | |
| 4046 | static const struct file_operations tracing_enum_map_fops = { |
| 4047 | .open = tracing_enum_map_open, |
| 4048 | .read = seq_read, |
| 4049 | .llseek = seq_lseek, |
| 4050 | .release = seq_release, |
| 4051 | }; |
| 4052 | |
| 4053 | static inline union trace_enum_map_item * |
| 4054 | trace_enum_jmp_to_tail(union trace_enum_map_item *ptr) |
| 4055 | { |
| 4056 | /* Return tail of array given the head */ |
| 4057 | return ptr + ptr->head.length + 1; |
| 4058 | } |
| 4059 | |
| 4060 | static void |
| 4061 | trace_insert_enum_map_file(struct module *mod, struct trace_enum_map **start, |
| 4062 | int len) |
| 4063 | { |
| 4064 | struct trace_enum_map **stop; |
| 4065 | struct trace_enum_map **map; |
| 4066 | union trace_enum_map_item *map_array; |
| 4067 | union trace_enum_map_item *ptr; |
| 4068 | |
| 4069 | stop = start + len; |
| 4070 | |
| 4071 | /* |
| 4072 | * The trace_enum_maps contains the map plus a head and tail item, |
| 4073 | * where the head holds the module and length of array, and the |
| 4074 | * tail holds a pointer to the next list. |
| 4075 | */ |
| 4076 | map_array = kmalloc(sizeof(*map_array) * (len + 2), GFP_KERNEL); |
| 4077 | if (!map_array) { |
| 4078 | pr_warning("Unable to allocate trace enum mapping\n"); |
| 4079 | return; |
| 4080 | } |
| 4081 | |
| 4082 | mutex_lock(&trace_enum_mutex); |
| 4083 | |
| 4084 | if (!trace_enum_maps) |
| 4085 | trace_enum_maps = map_array; |
| 4086 | else { |
| 4087 | ptr = trace_enum_maps; |
| 4088 | for (;;) { |
| 4089 | ptr = trace_enum_jmp_to_tail(ptr); |
| 4090 | if (!ptr->tail.next) |
| 4091 | break; |
| 4092 | ptr = ptr->tail.next; |
| 4093 | |
| 4094 | } |
| 4095 | ptr->tail.next = map_array; |
| 4096 | } |
| 4097 | map_array->head.mod = mod; |
| 4098 | map_array->head.length = len; |
| 4099 | map_array++; |
| 4100 | |
| 4101 | for (map = start; (unsigned long)map < (unsigned long)stop; map++) { |
| 4102 | map_array->map = **map; |
| 4103 | map_array++; |
| 4104 | } |
| 4105 | memset(map_array, 0, sizeof(*map_array)); |
| 4106 | |
| 4107 | mutex_unlock(&trace_enum_mutex); |
| 4108 | } |
| 4109 | |
| 4110 | static void trace_create_enum_file(struct dentry *d_tracer) |
| 4111 | { |
| 4112 | trace_create_file("enum_map", 0444, d_tracer, |
| 4113 | NULL, &tracing_enum_map_fops); |
| 4114 | } |
| 4115 | |
| 4116 | #else /* CONFIG_TRACE_ENUM_MAP_FILE */ |
| 4117 | static inline void trace_create_enum_file(struct dentry *d_tracer) { } |
| 4118 | static inline void trace_insert_enum_map_file(struct module *mod, |
| 4119 | struct trace_enum_map **start, int len) { } |
| 4120 | #endif /* !CONFIG_TRACE_ENUM_MAP_FILE */ |
| 4121 | |
| 4122 | static void trace_insert_enum_map(struct module *mod, |
| 4123 | struct trace_enum_map **start, int len) |
Steven Rostedt (Red Hat) | 0c564a5 | 2015-03-24 17:58:09 -0400 | [diff] [blame] | 4124 | { |
| 4125 | struct trace_enum_map **map; |
Steven Rostedt (Red Hat) | 0c564a5 | 2015-03-24 17:58:09 -0400 | [diff] [blame] | 4126 | |
| 4127 | if (len <= 0) |
| 4128 | return; |
| 4129 | |
| 4130 | map = start; |
| 4131 | |
| 4132 | trace_event_enum_update(map, len); |
Steven Rostedt (Red Hat) | 9828413 | 2015-03-31 17:23:45 -0400 | [diff] [blame] | 4133 | |
| 4134 | trace_insert_enum_map_file(mod, start, len); |
Steven Rostedt (Red Hat) | 0c564a5 | 2015-03-24 17:58:09 -0400 | [diff] [blame] | 4135 | } |
| 4136 | |
Yoshihiro YUNOMAE | 939c7a4 | 2014-06-05 10:24:27 +0900 | [diff] [blame] | 4137 | static ssize_t |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4138 | tracing_set_trace_read(struct file *filp, char __user *ubuf, |
| 4139 | size_t cnt, loff_t *ppos) |
| 4140 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4141 | struct trace_array *tr = filp->private_data; |
Li Zefan | ee6c2c1 | 2009-09-18 14:06:47 +0800 | [diff] [blame] | 4142 | char buf[MAX_TRACER_SIZE+2]; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4143 | int r; |
| 4144 | |
| 4145 | mutex_lock(&trace_types_lock); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4146 | r = sprintf(buf, "%s\n", tr->current_trace->name); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4147 | mutex_unlock(&trace_types_lock); |
| 4148 | |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4149 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, r); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4150 | } |
| 4151 | |
Arnaldo Carvalho de Melo | b6f11df | 2009-02-05 18:02:00 -0200 | [diff] [blame] | 4152 | int tracer_init(struct tracer *t, struct trace_array *tr) |
| 4153 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4154 | tracing_reset_online_cpus(&tr->trace_buffer); |
Arnaldo Carvalho de Melo | b6f11df | 2009-02-05 18:02:00 -0200 | [diff] [blame] | 4155 | return t->init(tr); |
| 4156 | } |
| 4157 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4158 | static void set_buffer_entries(struct trace_buffer *buf, unsigned long val) |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 4159 | { |
| 4160 | int cpu; |
Steven Rostedt (Red Hat) | 737223f | 2013-03-05 21:13:47 -0500 | [diff] [blame] | 4161 | |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 4162 | for_each_tracing_cpu(cpu) |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4163 | per_cpu_ptr(buf->data, cpu)->entries = val; |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 4164 | } |
| 4165 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4166 | #ifdef CONFIG_TRACER_MAX_TRACE |
Hiraku Toyooka | d60da50 | 2012-10-17 11:56:16 +0900 | [diff] [blame] | 4167 | /* 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] | 4168 | static int resize_buffer_duplicate_size(struct trace_buffer *trace_buf, |
| 4169 | struct trace_buffer *size_buf, int cpu_id) |
Hiraku Toyooka | d60da50 | 2012-10-17 11:56:16 +0900 | [diff] [blame] | 4170 | { |
| 4171 | int cpu, ret = 0; |
| 4172 | |
| 4173 | if (cpu_id == RING_BUFFER_ALL_CPUS) { |
| 4174 | for_each_tracing_cpu(cpu) { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4175 | ret = ring_buffer_resize(trace_buf->buffer, |
| 4176 | per_cpu_ptr(size_buf->data, cpu)->entries, cpu); |
Hiraku Toyooka | d60da50 | 2012-10-17 11:56:16 +0900 | [diff] [blame] | 4177 | if (ret < 0) |
| 4178 | break; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4179 | per_cpu_ptr(trace_buf->data, cpu)->entries = |
| 4180 | per_cpu_ptr(size_buf->data, cpu)->entries; |
Hiraku Toyooka | d60da50 | 2012-10-17 11:56:16 +0900 | [diff] [blame] | 4181 | } |
| 4182 | } else { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4183 | ret = ring_buffer_resize(trace_buf->buffer, |
| 4184 | per_cpu_ptr(size_buf->data, cpu_id)->entries, cpu_id); |
Hiraku Toyooka | d60da50 | 2012-10-17 11:56:16 +0900 | [diff] [blame] | 4185 | if (ret == 0) |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4186 | per_cpu_ptr(trace_buf->data, cpu_id)->entries = |
| 4187 | per_cpu_ptr(size_buf->data, cpu_id)->entries; |
Hiraku Toyooka | d60da50 | 2012-10-17 11:56:16 +0900 | [diff] [blame] | 4188 | } |
| 4189 | |
| 4190 | return ret; |
| 4191 | } |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4192 | #endif /* CONFIG_TRACER_MAX_TRACE */ |
Hiraku Toyooka | d60da50 | 2012-10-17 11:56:16 +0900 | [diff] [blame] | 4193 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4194 | static int __tracing_resize_ring_buffer(struct trace_array *tr, |
| 4195 | unsigned long size, int cpu) |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 4196 | { |
| 4197 | int ret; |
| 4198 | |
| 4199 | /* |
| 4200 | * If kernel or user changes the size of the ring buffer |
Steven Rostedt | a123c52 | 2009-03-12 11:21:08 -0400 | [diff] [blame] | 4201 | * we use the size that was given, and we can forget about |
| 4202 | * expanding it later. |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 4203 | */ |
Steven Rostedt (Red Hat) | 55034cd | 2013-03-07 22:48:09 -0500 | [diff] [blame] | 4204 | ring_buffer_expanded = true; |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 4205 | |
Steven Rostedt | b382ede6 | 2012-10-10 21:44:34 -0400 | [diff] [blame] | 4206 | /* May be called before buffers are initialized */ |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4207 | if (!tr->trace_buffer.buffer) |
Steven Rostedt | b382ede6 | 2012-10-10 21:44:34 -0400 | [diff] [blame] | 4208 | return 0; |
| 4209 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4210 | ret = ring_buffer_resize(tr->trace_buffer.buffer, size, cpu); |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 4211 | if (ret < 0) |
| 4212 | return ret; |
| 4213 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4214 | #ifdef CONFIG_TRACER_MAX_TRACE |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4215 | if (!(tr->flags & TRACE_ARRAY_FL_GLOBAL) || |
| 4216 | !tr->current_trace->use_max_tr) |
KOSAKI Motohiro | ef710e1 | 2010-07-01 14:34:35 +0900 | [diff] [blame] | 4217 | goto out; |
| 4218 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4219 | ret = ring_buffer_resize(tr->max_buffer.buffer, size, cpu); |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 4220 | if (ret < 0) { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4221 | int r = resize_buffer_duplicate_size(&tr->trace_buffer, |
| 4222 | &tr->trace_buffer, cpu); |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 4223 | if (r < 0) { |
Steven Rostedt | a123c52 | 2009-03-12 11:21:08 -0400 | [diff] [blame] | 4224 | /* |
| 4225 | * AARGH! We are left with different |
| 4226 | * size max buffer!!!! |
| 4227 | * The max buffer is our "snapshot" buffer. |
| 4228 | * When a tracer needs a snapshot (one of the |
| 4229 | * latency tracers), it swaps the max buffer |
| 4230 | * with the saved snap shot. We succeeded to |
| 4231 | * update the size of the main buffer, but failed to |
| 4232 | * update the size of the max buffer. But when we tried |
| 4233 | * to reset the main buffer to the original size, we |
| 4234 | * failed there too. This is very unlikely to |
| 4235 | * happen, but if it does, warn and kill all |
| 4236 | * tracing. |
| 4237 | */ |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 4238 | WARN_ON(1); |
| 4239 | tracing_disabled = 1; |
| 4240 | } |
| 4241 | return ret; |
| 4242 | } |
| 4243 | |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 4244 | if (cpu == RING_BUFFER_ALL_CPUS) |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4245 | set_buffer_entries(&tr->max_buffer, size); |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 4246 | else |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4247 | per_cpu_ptr(tr->max_buffer.data, cpu)->entries = size; |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 4248 | |
KOSAKI Motohiro | ef710e1 | 2010-07-01 14:34:35 +0900 | [diff] [blame] | 4249 | out: |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4250 | #endif /* CONFIG_TRACER_MAX_TRACE */ |
| 4251 | |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 4252 | if (cpu == RING_BUFFER_ALL_CPUS) |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4253 | set_buffer_entries(&tr->trace_buffer, size); |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 4254 | else |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4255 | per_cpu_ptr(tr->trace_buffer.data, cpu)->entries = size; |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 4256 | |
| 4257 | return ret; |
| 4258 | } |
| 4259 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4260 | static ssize_t tracing_resize_ring_buffer(struct trace_array *tr, |
| 4261 | unsigned long size, int cpu_id) |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 4262 | { |
Vaibhav Nagarnaik | 83f4031 | 2012-05-03 18:59:50 -0700 | [diff] [blame] | 4263 | int ret = size; |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 4264 | |
| 4265 | mutex_lock(&trace_types_lock); |
| 4266 | |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 4267 | if (cpu_id != RING_BUFFER_ALL_CPUS) { |
| 4268 | /* make sure, this cpu is enabled in the mask */ |
| 4269 | if (!cpumask_test_cpu(cpu_id, tracing_buffer_mask)) { |
| 4270 | ret = -EINVAL; |
| 4271 | goto out; |
| 4272 | } |
| 4273 | } |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 4274 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4275 | ret = __tracing_resize_ring_buffer(tr, size, cpu_id); |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 4276 | if (ret < 0) |
| 4277 | ret = -ENOMEM; |
| 4278 | |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 4279 | out: |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 4280 | mutex_unlock(&trace_types_lock); |
| 4281 | |
| 4282 | return ret; |
| 4283 | } |
| 4284 | |
KOSAKI Motohiro | ef710e1 | 2010-07-01 14:34:35 +0900 | [diff] [blame] | 4285 | |
Steven Rostedt | 1852fcc | 2009-03-11 14:33:00 -0400 | [diff] [blame] | 4286 | /** |
| 4287 | * tracing_update_buffers - used by tracing facility to expand ring buffers |
| 4288 | * |
| 4289 | * To save on memory when the tracing is never used on a system with it |
| 4290 | * configured in. The ring buffers are set to a minimum size. But once |
| 4291 | * a user starts to use the tracing facility, then they need to grow |
| 4292 | * to their default size. |
| 4293 | * |
| 4294 | * This function is to be called when a tracer is about to be used. |
| 4295 | */ |
| 4296 | int tracing_update_buffers(void) |
| 4297 | { |
| 4298 | int ret = 0; |
| 4299 | |
Steven Rostedt | 1027fcb | 2009-03-12 11:33:20 -0400 | [diff] [blame] | 4300 | mutex_lock(&trace_types_lock); |
Steven Rostedt | 1852fcc | 2009-03-11 14:33:00 -0400 | [diff] [blame] | 4301 | if (!ring_buffer_expanded) |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4302 | ret = __tracing_resize_ring_buffer(&global_trace, trace_buf_size, |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 4303 | RING_BUFFER_ALL_CPUS); |
Steven Rostedt | 1027fcb | 2009-03-12 11:33:20 -0400 | [diff] [blame] | 4304 | mutex_unlock(&trace_types_lock); |
Steven Rostedt | 1852fcc | 2009-03-11 14:33:00 -0400 | [diff] [blame] | 4305 | |
| 4306 | return ret; |
| 4307 | } |
| 4308 | |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 4309 | struct trace_option_dentry; |
| 4310 | |
Steven Rostedt (Red Hat) | 37aea98 | 2015-09-30 14:27:31 -0400 | [diff] [blame] | 4311 | static void |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4312 | create_trace_option_files(struct trace_array *tr, struct tracer *tracer); |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 4313 | |
Steven Rostedt (Red Hat) | 6b450d2 | 2014-01-14 08:43:01 -0500 | [diff] [blame] | 4314 | /* |
| 4315 | * Used to clear out the tracer before deletion of an instance. |
| 4316 | * Must have trace_types_lock held. |
| 4317 | */ |
| 4318 | static void tracing_set_nop(struct trace_array *tr) |
| 4319 | { |
| 4320 | if (tr->current_trace == &nop_trace) |
| 4321 | return; |
| 4322 | |
Steven Rostedt (Red Hat) | 50512ab | 2014-01-14 08:52:35 -0500 | [diff] [blame] | 4323 | tr->current_trace->enabled--; |
Steven Rostedt (Red Hat) | 6b450d2 | 2014-01-14 08:43:01 -0500 | [diff] [blame] | 4324 | |
| 4325 | if (tr->current_trace->reset) |
| 4326 | tr->current_trace->reset(tr); |
| 4327 | |
| 4328 | tr->current_trace = &nop_trace; |
| 4329 | } |
| 4330 | |
Steven Rostedt (Red Hat) | 41d9c0b | 2015-09-29 17:31:55 -0400 | [diff] [blame] | 4331 | static void add_tracer_options(struct trace_array *tr, struct tracer *t) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4332 | { |
Steven Rostedt (Red Hat) | 09d23a1 | 2015-02-03 12:45:53 -0500 | [diff] [blame] | 4333 | /* Only enable if the directory has been created already. */ |
| 4334 | if (!tr->dir) |
| 4335 | return; |
| 4336 | |
Steven Rostedt (Red Hat) | 37aea98 | 2015-09-30 14:27:31 -0400 | [diff] [blame] | 4337 | create_trace_option_files(tr, t); |
Steven Rostedt (Red Hat) | 09d23a1 | 2015-02-03 12:45:53 -0500 | [diff] [blame] | 4338 | } |
| 4339 | |
| 4340 | static int tracing_set_tracer(struct trace_array *tr, const char *buf) |
| 4341 | { |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4342 | struct tracer *t; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4343 | #ifdef CONFIG_TRACER_MAX_TRACE |
Steven Rostedt | 34600f0 | 2013-01-22 13:35:11 -0500 | [diff] [blame] | 4344 | bool had_max_tr; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4345 | #endif |
Peter Zijlstra | d9e5407 | 2008-11-01 19:57:37 +0100 | [diff] [blame] | 4346 | int ret = 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4347 | |
Steven Rostedt | 1027fcb | 2009-03-12 11:33:20 -0400 | [diff] [blame] | 4348 | mutex_lock(&trace_types_lock); |
| 4349 | |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 4350 | if (!ring_buffer_expanded) { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4351 | ret = __tracing_resize_ring_buffer(tr, trace_buf_size, |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 4352 | RING_BUFFER_ALL_CPUS); |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 4353 | if (ret < 0) |
Frederic Weisbecker | 59f586d | 2009-03-15 22:10:39 +0100 | [diff] [blame] | 4354 | goto out; |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 4355 | ret = 0; |
| 4356 | } |
| 4357 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4358 | for (t = trace_types; t; t = t->next) { |
| 4359 | if (strcmp(t->name, buf) == 0) |
| 4360 | break; |
| 4361 | } |
Frederic Weisbecker | c2931e0 | 2008-10-04 22:04:44 +0200 | [diff] [blame] | 4362 | if (!t) { |
| 4363 | ret = -EINVAL; |
| 4364 | goto out; |
| 4365 | } |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4366 | if (t == tr->current_trace) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4367 | goto out; |
| 4368 | |
Steven Rostedt (Red Hat) | 607e2ea | 2013-11-06 22:42:48 -0500 | [diff] [blame] | 4369 | /* Some tracers are only allowed for the top level buffer */ |
| 4370 | if (!trace_ok_for_array(t, tr)) { |
| 4371 | ret = -EINVAL; |
| 4372 | goto out; |
| 4373 | } |
| 4374 | |
Steven Rostedt (Red Hat) | cf6ab6d | 2014-12-15 20:13:31 -0500 | [diff] [blame] | 4375 | /* If trace pipe files are being read, we can't change the tracer */ |
| 4376 | if (tr->current_trace->ref) { |
| 4377 | ret = -EBUSY; |
| 4378 | goto out; |
| 4379 | } |
| 4380 | |
Steven Rostedt | 9f029e8 | 2008-11-12 15:24:24 -0500 | [diff] [blame] | 4381 | trace_branch_disable(); |
Steven Rostedt (Red Hat) | 613f04a | 2013-03-14 15:03:53 -0400 | [diff] [blame] | 4382 | |
Steven Rostedt (Red Hat) | 50512ab | 2014-01-14 08:52:35 -0500 | [diff] [blame] | 4383 | tr->current_trace->enabled--; |
Steven Rostedt (Red Hat) | 613f04a | 2013-03-14 15:03:53 -0400 | [diff] [blame] | 4384 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4385 | if (tr->current_trace->reset) |
| 4386 | tr->current_trace->reset(tr); |
Steven Rostedt | 34600f0 | 2013-01-22 13:35:11 -0500 | [diff] [blame] | 4387 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4388 | /* Current trace needs to be nop_trace before synchronize_sched */ |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4389 | tr->current_trace = &nop_trace; |
Steven Rostedt | 34600f0 | 2013-01-22 13:35:11 -0500 | [diff] [blame] | 4390 | |
Steven Rostedt (Red Hat) | 45ad21c | 2013-03-05 18:25:02 -0500 | [diff] [blame] | 4391 | #ifdef CONFIG_TRACER_MAX_TRACE |
| 4392 | had_max_tr = tr->allocated_snapshot; |
Steven Rostedt | 34600f0 | 2013-01-22 13:35:11 -0500 | [diff] [blame] | 4393 | |
| 4394 | if (had_max_tr && !t->use_max_tr) { |
| 4395 | /* |
| 4396 | * We need to make sure that the update_max_tr sees that |
| 4397 | * current_trace changed to nop_trace to keep it from |
| 4398 | * swapping the buffers after we resize it. |
| 4399 | * The update_max_tr is called from interrupts disabled |
| 4400 | * so a synchronized_sched() is sufficient. |
| 4401 | */ |
| 4402 | synchronize_sched(); |
Steven Rostedt (Red Hat) | 3209cff | 2013-03-12 11:17:54 -0400 | [diff] [blame] | 4403 | free_snapshot(tr); |
KOSAKI Motohiro | ef710e1 | 2010-07-01 14:34:35 +0900 | [diff] [blame] | 4404 | } |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4405 | #endif |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4406 | |
| 4407 | #ifdef CONFIG_TRACER_MAX_TRACE |
Steven Rostedt | 34600f0 | 2013-01-22 13:35:11 -0500 | [diff] [blame] | 4408 | if (t->use_max_tr && !had_max_tr) { |
Steven Rostedt (Red Hat) | 3209cff | 2013-03-12 11:17:54 -0400 | [diff] [blame] | 4409 | ret = alloc_snapshot(tr); |
Hiraku Toyooka | d60da50 | 2012-10-17 11:56:16 +0900 | [diff] [blame] | 4410 | if (ret < 0) |
| 4411 | goto out; |
KOSAKI Motohiro | ef710e1 | 2010-07-01 14:34:35 +0900 | [diff] [blame] | 4412 | } |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4413 | #endif |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 4414 | |
Frederic Weisbecker | 1c80025 | 2008-11-16 05:57:26 +0100 | [diff] [blame] | 4415 | if (t->init) { |
Arnaldo Carvalho de Melo | b6f11df | 2009-02-05 18:02:00 -0200 | [diff] [blame] | 4416 | ret = tracer_init(t, tr); |
Frederic Weisbecker | 1c80025 | 2008-11-16 05:57:26 +0100 | [diff] [blame] | 4417 | if (ret) |
| 4418 | goto out; |
| 4419 | } |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4420 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 4421 | tr->current_trace = t; |
Steven Rostedt (Red Hat) | 50512ab | 2014-01-14 08:52:35 -0500 | [diff] [blame] | 4422 | tr->current_trace->enabled++; |
Steven Rostedt | 9f029e8 | 2008-11-12 15:24:24 -0500 | [diff] [blame] | 4423 | trace_branch_enable(tr); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4424 | out: |
| 4425 | mutex_unlock(&trace_types_lock); |
| 4426 | |
Peter Zijlstra | d9e5407 | 2008-11-01 19:57:37 +0100 | [diff] [blame] | 4427 | return ret; |
| 4428 | } |
| 4429 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4430 | static ssize_t |
| 4431 | tracing_set_trace_write(struct file *filp, const char __user *ubuf, |
| 4432 | size_t cnt, loff_t *ppos) |
| 4433 | { |
Steven Rostedt (Red Hat) | 607e2ea | 2013-11-06 22:42:48 -0500 | [diff] [blame] | 4434 | struct trace_array *tr = filp->private_data; |
Li Zefan | ee6c2c1 | 2009-09-18 14:06:47 +0800 | [diff] [blame] | 4435 | char buf[MAX_TRACER_SIZE+1]; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4436 | int i; |
| 4437 | size_t ret; |
Frederic Weisbecker | e6e7a65 | 2008-11-16 05:53:19 +0100 | [diff] [blame] | 4438 | int err; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4439 | |
Steven Rostedt | 60063a6 | 2008-10-28 10:44:24 -0400 | [diff] [blame] | 4440 | ret = cnt; |
| 4441 | |
Li Zefan | ee6c2c1 | 2009-09-18 14:06:47 +0800 | [diff] [blame] | 4442 | if (cnt > MAX_TRACER_SIZE) |
| 4443 | cnt = MAX_TRACER_SIZE; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4444 | |
| 4445 | if (copy_from_user(&buf, ubuf, cnt)) |
| 4446 | return -EFAULT; |
| 4447 | |
| 4448 | buf[cnt] = 0; |
| 4449 | |
| 4450 | /* strip ending whitespace. */ |
| 4451 | for (i = cnt - 1; i > 0 && isspace(buf[i]); i--) |
| 4452 | buf[i] = 0; |
| 4453 | |
Steven Rostedt (Red Hat) | 607e2ea | 2013-11-06 22:42:48 -0500 | [diff] [blame] | 4454 | err = tracing_set_tracer(tr, buf); |
Frederic Weisbecker | e6e7a65 | 2008-11-16 05:53:19 +0100 | [diff] [blame] | 4455 | if (err) |
| 4456 | return err; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4457 | |
Jiri Olsa | cf8517c | 2009-10-23 19:36:16 -0400 | [diff] [blame] | 4458 | *ppos += ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4459 | |
Frederic Weisbecker | c2931e0 | 2008-10-04 22:04:44 +0200 | [diff] [blame] | 4460 | return ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4461 | } |
| 4462 | |
| 4463 | static ssize_t |
Stanislav Fomichev | 6508fa7 | 2014-07-18 15:17:27 +0400 | [diff] [blame] | 4464 | tracing_nsecs_read(unsigned long *ptr, char __user *ubuf, |
| 4465 | size_t cnt, loff_t *ppos) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4466 | { |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4467 | char buf[64]; |
| 4468 | int r; |
| 4469 | |
Steven Rostedt | cffae43 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 4470 | r = snprintf(buf, sizeof(buf), "%ld\n", |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4471 | *ptr == (unsigned long)-1 ? -1 : nsecs_to_usecs(*ptr)); |
Steven Rostedt | cffae43 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 4472 | if (r > sizeof(buf)) |
| 4473 | r = sizeof(buf); |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4474 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, r); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4475 | } |
| 4476 | |
| 4477 | static ssize_t |
Stanislav Fomichev | 6508fa7 | 2014-07-18 15:17:27 +0400 | [diff] [blame] | 4478 | tracing_nsecs_write(unsigned long *ptr, const char __user *ubuf, |
| 4479 | size_t cnt, loff_t *ppos) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4480 | { |
Hannes Eder | 5e39841 | 2009-02-10 19:44:34 +0100 | [diff] [blame] | 4481 | unsigned long val; |
Steven Rostedt | c6caeeb | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 4482 | int ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4483 | |
Peter Huewe | 22fe9b5 | 2011-06-07 21:58:27 +0200 | [diff] [blame] | 4484 | ret = kstrtoul_from_user(ubuf, cnt, 10, &val); |
| 4485 | if (ret) |
Steven Rostedt | c6caeeb | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 4486 | return ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4487 | |
| 4488 | *ptr = val * 1000; |
| 4489 | |
| 4490 | return cnt; |
| 4491 | } |
| 4492 | |
Stanislav Fomichev | 6508fa7 | 2014-07-18 15:17:27 +0400 | [diff] [blame] | 4493 | static ssize_t |
| 4494 | tracing_thresh_read(struct file *filp, char __user *ubuf, |
| 4495 | size_t cnt, loff_t *ppos) |
| 4496 | { |
| 4497 | return tracing_nsecs_read(&tracing_thresh, ubuf, cnt, ppos); |
| 4498 | } |
| 4499 | |
| 4500 | static ssize_t |
| 4501 | tracing_thresh_write(struct file *filp, const char __user *ubuf, |
| 4502 | size_t cnt, loff_t *ppos) |
| 4503 | { |
| 4504 | struct trace_array *tr = filp->private_data; |
| 4505 | int ret; |
| 4506 | |
| 4507 | mutex_lock(&trace_types_lock); |
| 4508 | ret = tracing_nsecs_write(&tracing_thresh, ubuf, cnt, ppos); |
| 4509 | if (ret < 0) |
| 4510 | goto out; |
| 4511 | |
| 4512 | if (tr->current_trace->update_thresh) { |
| 4513 | ret = tr->current_trace->update_thresh(tr); |
| 4514 | if (ret < 0) |
| 4515 | goto out; |
| 4516 | } |
| 4517 | |
| 4518 | ret = cnt; |
| 4519 | out: |
| 4520 | mutex_unlock(&trace_types_lock); |
| 4521 | |
| 4522 | return ret; |
| 4523 | } |
| 4524 | |
| 4525 | static ssize_t |
| 4526 | tracing_max_lat_read(struct file *filp, char __user *ubuf, |
| 4527 | size_t cnt, loff_t *ppos) |
| 4528 | { |
| 4529 | return tracing_nsecs_read(filp->private_data, ubuf, cnt, ppos); |
| 4530 | } |
| 4531 | |
| 4532 | static ssize_t |
| 4533 | tracing_max_lat_write(struct file *filp, const char __user *ubuf, |
| 4534 | size_t cnt, loff_t *ppos) |
| 4535 | { |
| 4536 | return tracing_nsecs_write(filp->private_data, ubuf, cnt, ppos); |
| 4537 | } |
| 4538 | |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4539 | static int tracing_open_pipe(struct inode *inode, struct file *filp) |
| 4540 | { |
Oleg Nesterov | 1554420 | 2013-07-23 17:25:57 +0200 | [diff] [blame] | 4541 | struct trace_array *tr = inode->i_private; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4542 | struct trace_iterator *iter; |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 4543 | int ret = 0; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4544 | |
| 4545 | if (tracing_disabled) |
| 4546 | return -ENODEV; |
| 4547 | |
Steven Rostedt (Red Hat) | 7b85af6 | 2013-07-01 23:34:22 -0400 | [diff] [blame] | 4548 | if (trace_array_get(tr) < 0) |
| 4549 | return -ENODEV; |
| 4550 | |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 4551 | mutex_lock(&trace_types_lock); |
| 4552 | |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4553 | /* create a buffer to store the information to pass to userspace */ |
| 4554 | iter = kzalloc(sizeof(*iter), GFP_KERNEL); |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 4555 | if (!iter) { |
| 4556 | ret = -ENOMEM; |
Alexander Z Lam | f77d09a | 2013-07-18 11:18:44 -0700 | [diff] [blame] | 4557 | __trace_array_put(tr); |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 4558 | goto out; |
| 4559 | } |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4560 | |
Steven Rostedt (Red Hat) | 3a161d9 | 2014-06-25 15:54:42 -0400 | [diff] [blame] | 4561 | trace_seq_init(&iter->seq); |
Steven Rostedt (Red Hat) | d716ff7 | 2014-12-15 22:31:07 -0500 | [diff] [blame] | 4562 | iter->trace = tr->current_trace; |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 4563 | |
| 4564 | if (!alloc_cpumask_var(&iter->started, GFP_KERNEL)) { |
| 4565 | ret = -ENOMEM; |
| 4566 | goto fail; |
Rusty Russell | 4462344 | 2009-01-01 10:12:23 +1030 | [diff] [blame] | 4567 | } |
| 4568 | |
Steven Rostedt | a309720 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 4569 | /* trace pipe does not show start of buffer */ |
Rusty Russell | 4462344 | 2009-01-01 10:12:23 +1030 | [diff] [blame] | 4570 | cpumask_setall(iter->started); |
Steven Rostedt | a309720 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 4571 | |
Steven Rostedt (Red Hat) | 983f938 | 2015-09-30 09:42:05 -0400 | [diff] [blame] | 4572 | if (tr->trace_flags & TRACE_ITER_LATENCY_FMT) |
Steven Rostedt | 112f38a7 | 2009-06-01 15:16:05 -0400 | [diff] [blame] | 4573 | iter->iter_flags |= TRACE_FILE_LAT_FMT; |
| 4574 | |
David Sharp | 8be0709 | 2012-11-13 12:18:22 -0800 | [diff] [blame] | 4575 | /* Output in nanoseconds only if we are using a clock in nanoseconds. */ |
Yoshihiro YUNOMAE | 58e8eed | 2013-04-23 10:32:39 +0900 | [diff] [blame] | 4576 | if (trace_clocks[tr->clock_id].in_ns) |
David Sharp | 8be0709 | 2012-11-13 12:18:22 -0800 | [diff] [blame] | 4577 | iter->iter_flags |= TRACE_FILE_TIME_IN_NS; |
| 4578 | |
Oleg Nesterov | 1554420 | 2013-07-23 17:25:57 +0200 | [diff] [blame] | 4579 | iter->tr = tr; |
| 4580 | iter->trace_buffer = &tr->trace_buffer; |
| 4581 | iter->cpu_file = tracing_get_cpu(inode); |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 4582 | mutex_init(&iter->mutex); |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4583 | filp->private_data = iter; |
| 4584 | |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 4585 | if (iter->trace->pipe_open) |
| 4586 | iter->trace->pipe_open(iter); |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 4587 | |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 4588 | nonseekable_open(inode, filp); |
Steven Rostedt (Red Hat) | cf6ab6d | 2014-12-15 20:13:31 -0500 | [diff] [blame] | 4589 | |
| 4590 | tr->current_trace->ref++; |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 4591 | out: |
| 4592 | mutex_unlock(&trace_types_lock); |
| 4593 | return ret; |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 4594 | |
| 4595 | fail: |
| 4596 | kfree(iter->trace); |
| 4597 | kfree(iter); |
Steven Rostedt (Red Hat) | 7b85af6 | 2013-07-01 23:34:22 -0400 | [diff] [blame] | 4598 | __trace_array_put(tr); |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 4599 | mutex_unlock(&trace_types_lock); |
| 4600 | return ret; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4601 | } |
| 4602 | |
| 4603 | static int tracing_release_pipe(struct inode *inode, struct file *file) |
| 4604 | { |
| 4605 | struct trace_iterator *iter = file->private_data; |
Oleg Nesterov | 1554420 | 2013-07-23 17:25:57 +0200 | [diff] [blame] | 4606 | struct trace_array *tr = inode->i_private; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4607 | |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 4608 | mutex_lock(&trace_types_lock); |
| 4609 | |
Steven Rostedt (Red Hat) | cf6ab6d | 2014-12-15 20:13:31 -0500 | [diff] [blame] | 4610 | tr->current_trace->ref--; |
| 4611 | |
Steven Rostedt | 29bf4a5 | 2009-12-09 12:37:43 -0500 | [diff] [blame] | 4612 | if (iter->trace->pipe_close) |
Steven Rostedt | c521efd | 2009-12-07 09:06:24 -0500 | [diff] [blame] | 4613 | iter->trace->pipe_close(iter); |
| 4614 | |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 4615 | mutex_unlock(&trace_types_lock); |
| 4616 | |
Rusty Russell | 4462344 | 2009-01-01 10:12:23 +1030 | [diff] [blame] | 4617 | free_cpumask_var(iter->started); |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 4618 | mutex_destroy(&iter->mutex); |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4619 | kfree(iter); |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4620 | |
Steven Rostedt (Red Hat) | 7b85af6 | 2013-07-01 23:34:22 -0400 | [diff] [blame] | 4621 | trace_array_put(tr); |
| 4622 | |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4623 | return 0; |
| 4624 | } |
| 4625 | |
Soeren Sandmann Pedersen | 2a2cc8f | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 4626 | static unsigned int |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 4627 | 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] | 4628 | { |
Steven Rostedt (Red Hat) | 983f938 | 2015-09-30 09:42:05 -0400 | [diff] [blame] | 4629 | struct trace_array *tr = iter->tr; |
| 4630 | |
Steven Rostedt (Red Hat) | 1569345 | 2013-02-28 19:59:17 -0500 | [diff] [blame] | 4631 | /* Iterators are static, they should be filled or empty */ |
| 4632 | if (trace_buffer_iter(iter, iter->cpu_file)) |
| 4633 | return POLLIN | POLLRDNORM; |
Soeren Sandmann Pedersen | 2a2cc8f | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 4634 | |
Steven Rostedt (Red Hat) | 983f938 | 2015-09-30 09:42:05 -0400 | [diff] [blame] | 4635 | if (tr->trace_flags & TRACE_ITER_BLOCK) |
Soeren Sandmann Pedersen | 2a2cc8f | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 4636 | /* |
| 4637 | * Always select as readable when in blocking mode |
| 4638 | */ |
| 4639 | return POLLIN | POLLRDNORM; |
Steven Rostedt (Red Hat) | 1569345 | 2013-02-28 19:59:17 -0500 | [diff] [blame] | 4640 | else |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4641 | 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] | 4642 | filp, poll_table); |
Soeren Sandmann Pedersen | 2a2cc8f | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 4643 | } |
Soeren Sandmann Pedersen | 2a2cc8f | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 4644 | |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 4645 | static unsigned int |
| 4646 | tracing_poll_pipe(struct file *filp, poll_table *poll_table) |
| 4647 | { |
| 4648 | struct trace_iterator *iter = filp->private_data; |
| 4649 | |
| 4650 | return trace_poll(iter, filp, poll_table); |
Soeren Sandmann Pedersen | 2a2cc8f | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 4651 | } |
| 4652 | |
Steven Rostedt (Red Hat) | d716ff7 | 2014-12-15 22:31:07 -0500 | [diff] [blame] | 4653 | /* Must be called with iter->mutex held. */ |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 4654 | static int tracing_wait_pipe(struct file *filp) |
| 4655 | { |
| 4656 | struct trace_iterator *iter = filp->private_data; |
Steven Rostedt (Red Hat) | 8b8b368 | 2014-06-10 09:46:00 -0400 | [diff] [blame] | 4657 | int ret; |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 4658 | |
| 4659 | while (trace_empty(iter)) { |
| 4660 | |
| 4661 | if ((filp->f_flags & O_NONBLOCK)) { |
| 4662 | return -EAGAIN; |
| 4663 | } |
| 4664 | |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 4665 | /* |
Liu Bo | 250bfd3 | 2013-01-14 10:54:11 +0800 | [diff] [blame] | 4666 | * We block until we read something and tracing is disabled. |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 4667 | * We still block if tracing is disabled, but we have never |
| 4668 | * read anything. This allows a user to cat this file, and |
| 4669 | * then enable tracing. But after we have read something, |
| 4670 | * we give an EOF when tracing is again disabled. |
| 4671 | * |
| 4672 | * iter->pos will be 0 if we haven't read anything. |
| 4673 | */ |
Steven Rostedt (Red Hat) | 10246fa | 2013-07-01 15:58:24 -0400 | [diff] [blame] | 4674 | if (!tracing_is_on() && iter->pos) |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 4675 | break; |
Steven Rostedt (Red Hat) | f487426 | 2014-04-29 16:07:28 -0400 | [diff] [blame] | 4676 | |
| 4677 | mutex_unlock(&iter->mutex); |
| 4678 | |
Rabin Vincent | e30f53a | 2014-11-10 19:46:34 +0100 | [diff] [blame] | 4679 | ret = wait_on_pipe(iter, false); |
Steven Rostedt (Red Hat) | f487426 | 2014-04-29 16:07:28 -0400 | [diff] [blame] | 4680 | |
| 4681 | mutex_lock(&iter->mutex); |
| 4682 | |
Steven Rostedt (Red Hat) | 8b8b368 | 2014-06-10 09:46:00 -0400 | [diff] [blame] | 4683 | if (ret) |
| 4684 | return ret; |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 4685 | } |
| 4686 | |
| 4687 | return 1; |
| 4688 | } |
| 4689 | |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4690 | /* |
| 4691 | * Consumer reader. |
| 4692 | */ |
| 4693 | static ssize_t |
| 4694 | tracing_read_pipe(struct file *filp, char __user *ubuf, |
| 4695 | size_t cnt, loff_t *ppos) |
| 4696 | { |
| 4697 | struct trace_iterator *iter = filp->private_data; |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 4698 | ssize_t sret; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4699 | |
| 4700 | /* return any leftover data */ |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 4701 | sret = trace_seq_to_user(&iter->seq, ubuf, cnt); |
| 4702 | if (sret != -EBUSY) |
| 4703 | return sret; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4704 | |
Steven Rostedt | f952075 | 2009-03-02 14:04:40 -0500 | [diff] [blame] | 4705 | trace_seq_init(&iter->seq); |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4706 | |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 4707 | /* |
| 4708 | * Avoid more than one consumer on a single file descriptor |
| 4709 | * This is just a matter of traces coherency, the ring buffer itself |
| 4710 | * is protected. |
| 4711 | */ |
| 4712 | mutex_lock(&iter->mutex); |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 4713 | if (iter->trace->read) { |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 4714 | sret = iter->trace->read(iter, filp, ubuf, cnt, ppos); |
| 4715 | if (sret) |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 4716 | goto out; |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 4717 | } |
| 4718 | |
Pekka Paalanen | 9ff4b97 | 2008-09-29 20:23:48 +0200 | [diff] [blame] | 4719 | waitagain: |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 4720 | sret = tracing_wait_pipe(filp); |
| 4721 | if (sret <= 0) |
| 4722 | goto out; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4723 | |
| 4724 | /* stop when tracing is finished */ |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 4725 | if (trace_empty(iter)) { |
| 4726 | sret = 0; |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 4727 | goto out; |
Eduard - Gabriel Munteanu | ff98781 | 2009-02-09 08:15:55 +0200 | [diff] [blame] | 4728 | } |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4729 | |
| 4730 | if (cnt >= PAGE_SIZE) |
| 4731 | cnt = PAGE_SIZE - 1; |
| 4732 | |
Steven Rostedt | 53d0aa7 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 4733 | /* reset all but tr, trace, and overruns */ |
Steven Rostedt | 53d0aa7 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 4734 | memset(&iter->seq, 0, |
| 4735 | sizeof(struct trace_iterator) - |
| 4736 | offsetof(struct trace_iterator, seq)); |
Andrew Vagin | ed5467d | 2013-08-02 21:16:43 +0400 | [diff] [blame] | 4737 | cpumask_clear(iter->started); |
Steven Rostedt | 4823ed7 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 4738 | iter->pos = -1; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4739 | |
Lai Jiangshan | 4f53596 | 2009-05-18 19:35:34 +0800 | [diff] [blame] | 4740 | trace_event_read_lock(); |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 4741 | trace_access_lock(iter->cpu_file); |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 4742 | while (trace_find_next_entry_inc(iter) != NULL) { |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 4743 | enum print_line_t ret; |
Steven Rostedt (Red Hat) | 5ac48378 | 2014-11-14 15:49:41 -0500 | [diff] [blame] | 4744 | int save_len = iter->seq.seq.len; |
Steven Rostedt | 088b1e42 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 4745 | |
Ingo Molnar | f9896bf | 2008-05-12 21:20:47 +0200 | [diff] [blame] | 4746 | ret = print_trace_line(iter); |
Frederic Weisbecker | 2c4f035 | 2008-09-29 20:18:34 +0200 | [diff] [blame] | 4747 | if (ret == TRACE_TYPE_PARTIAL_LINE) { |
Steven Rostedt | 088b1e42 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 4748 | /* don't print partial lines */ |
Steven Rostedt (Red Hat) | 5ac48378 | 2014-11-14 15:49:41 -0500 | [diff] [blame] | 4749 | iter->seq.seq.len = save_len; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4750 | break; |
Steven Rostedt | 088b1e42 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 4751 | } |
Frederic Weisbecker | b91facc | 2009-02-06 18:30:44 +0100 | [diff] [blame] | 4752 | if (ret != TRACE_TYPE_NO_CONSUME) |
| 4753 | trace_consume(iter); |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4754 | |
Steven Rostedt (Red Hat) | 5ac48378 | 2014-11-14 15:49:41 -0500 | [diff] [blame] | 4755 | if (trace_seq_used(&iter->seq) >= cnt) |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4756 | break; |
Jiri Olsa | ee5e51f | 2011-03-25 12:05:18 +0100 | [diff] [blame] | 4757 | |
| 4758 | /* |
| 4759 | * Setting the full flag means we reached the trace_seq buffer |
| 4760 | * size and we should leave by partial output condition above. |
| 4761 | * One of the trace_seq_* functions is not used properly. |
| 4762 | */ |
| 4763 | WARN_ONCE(iter->seq.full, "full flag set for trace type %d", |
| 4764 | iter->ent->type); |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4765 | } |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 4766 | trace_access_unlock(iter->cpu_file); |
Lai Jiangshan | 4f53596 | 2009-05-18 19:35:34 +0800 | [diff] [blame] | 4767 | trace_event_read_unlock(); |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4768 | |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4769 | /* Now copy what we have to the user */ |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 4770 | sret = trace_seq_to_user(&iter->seq, ubuf, cnt); |
Steven Rostedt (Red Hat) | 5ac48378 | 2014-11-14 15:49:41 -0500 | [diff] [blame] | 4771 | if (iter->seq.seq.readpos >= trace_seq_used(&iter->seq)) |
Steven Rostedt | f952075 | 2009-03-02 14:04:40 -0500 | [diff] [blame] | 4772 | trace_seq_init(&iter->seq); |
Pekka Paalanen | 9ff4b97 | 2008-09-29 20:23:48 +0200 | [diff] [blame] | 4773 | |
| 4774 | /* |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 4775 | * 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] | 4776 | * entries, go back to wait for more entries. |
| 4777 | */ |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 4778 | if (sret == -EBUSY) |
Pekka Paalanen | 9ff4b97 | 2008-09-29 20:23:48 +0200 | [diff] [blame] | 4779 | goto waitagain; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4780 | |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 4781 | out: |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 4782 | mutex_unlock(&iter->mutex); |
Steven Rostedt | 107bad8 | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 4783 | |
Pekka Paalanen | 6c6c279 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 4784 | return sret; |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 4785 | } |
| 4786 | |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4787 | static void tracing_spd_release_pipe(struct splice_pipe_desc *spd, |
| 4788 | unsigned int idx) |
| 4789 | { |
| 4790 | __free_page(spd->pages[idx]); |
| 4791 | } |
| 4792 | |
Alexey Dobriyan | 28dfef8 | 2009-12-15 16:46:48 -0800 | [diff] [blame] | 4793 | static const struct pipe_buf_operations tracing_pipe_buf_ops = { |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 4794 | .can_merge = 0, |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 4795 | .confirm = generic_pipe_buf_confirm, |
Al Viro | 92fdd98 | 2014-01-17 07:53:39 -0500 | [diff] [blame] | 4796 | .release = generic_pipe_buf_release, |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 4797 | .steal = generic_pipe_buf_steal, |
| 4798 | .get = generic_pipe_buf_get, |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4799 | }; |
| 4800 | |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 4801 | static size_t |
Frederic Weisbecker | fa7c7f6 | 2009-02-11 02:51:30 +0100 | [diff] [blame] | 4802 | tracing_fill_pipe_page(size_t rem, struct trace_iterator *iter) |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 4803 | { |
| 4804 | size_t count; |
Steven Rostedt (Red Hat) | 74f06bb | 2014-11-17 13:12:22 -0500 | [diff] [blame] | 4805 | int save_len; |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 4806 | int ret; |
| 4807 | |
| 4808 | /* Seq buffer is page-sized, exactly what we need. */ |
| 4809 | for (;;) { |
Steven Rostedt (Red Hat) | 74f06bb | 2014-11-17 13:12:22 -0500 | [diff] [blame] | 4810 | save_len = iter->seq.seq.len; |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 4811 | ret = print_trace_line(iter); |
Steven Rostedt (Red Hat) | 74f06bb | 2014-11-17 13:12:22 -0500 | [diff] [blame] | 4812 | |
| 4813 | if (trace_seq_has_overflowed(&iter->seq)) { |
| 4814 | iter->seq.seq.len = save_len; |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 4815 | break; |
| 4816 | } |
Steven Rostedt (Red Hat) | 74f06bb | 2014-11-17 13:12:22 -0500 | [diff] [blame] | 4817 | |
| 4818 | /* |
| 4819 | * This should not be hit, because it should only |
| 4820 | * be set if the iter->seq overflowed. But check it |
| 4821 | * anyway to be safe. |
| 4822 | */ |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 4823 | if (ret == TRACE_TYPE_PARTIAL_LINE) { |
Steven Rostedt (Red Hat) | 74f06bb | 2014-11-17 13:12:22 -0500 | [diff] [blame] | 4824 | iter->seq.seq.len = save_len; |
| 4825 | break; |
| 4826 | } |
| 4827 | |
Steven Rostedt (Red Hat) | 5ac48378 | 2014-11-14 15:49:41 -0500 | [diff] [blame] | 4828 | count = trace_seq_used(&iter->seq) - save_len; |
Steven Rostedt (Red Hat) | 74f06bb | 2014-11-17 13:12:22 -0500 | [diff] [blame] | 4829 | if (rem < count) { |
| 4830 | rem = 0; |
| 4831 | iter->seq.seq.len = save_len; |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 4832 | break; |
| 4833 | } |
| 4834 | |
Lai Jiangshan | 74e7ff8 | 2009-07-28 20:17:22 +0800 | [diff] [blame] | 4835 | if (ret != TRACE_TYPE_NO_CONSUME) |
| 4836 | trace_consume(iter); |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 4837 | rem -= count; |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 4838 | if (!trace_find_next_entry_inc(iter)) { |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 4839 | rem = 0; |
| 4840 | iter->ent = NULL; |
| 4841 | break; |
| 4842 | } |
| 4843 | } |
| 4844 | |
| 4845 | return rem; |
| 4846 | } |
| 4847 | |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4848 | static ssize_t tracing_splice_read_pipe(struct file *filp, |
| 4849 | loff_t *ppos, |
| 4850 | struct pipe_inode_info *pipe, |
| 4851 | size_t len, |
| 4852 | unsigned int flags) |
| 4853 | { |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 4854 | struct page *pages_def[PIPE_DEF_BUFFERS]; |
| 4855 | struct partial_page partial_def[PIPE_DEF_BUFFERS]; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4856 | struct trace_iterator *iter = filp->private_data; |
| 4857 | struct splice_pipe_desc spd = { |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 4858 | .pages = pages_def, |
| 4859 | .partial = partial_def, |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 4860 | .nr_pages = 0, /* This gets updated below. */ |
Eric Dumazet | 047fe36 | 2012-06-12 15:24:40 +0200 | [diff] [blame] | 4861 | .nr_pages_max = PIPE_DEF_BUFFERS, |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 4862 | .flags = flags, |
| 4863 | .ops = &tracing_pipe_buf_ops, |
| 4864 | .spd_release = tracing_spd_release_pipe, |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4865 | }; |
| 4866 | ssize_t ret; |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 4867 | size_t rem; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4868 | unsigned int i; |
| 4869 | |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 4870 | if (splice_grow_spd(pipe, &spd)) |
| 4871 | return -ENOMEM; |
| 4872 | |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 4873 | mutex_lock(&iter->mutex); |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4874 | |
| 4875 | if (iter->trace->splice_read) { |
| 4876 | ret = iter->trace->splice_read(iter, filp, |
| 4877 | ppos, pipe, len, flags); |
| 4878 | if (ret) |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 4879 | goto out_err; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4880 | } |
| 4881 | |
| 4882 | ret = tracing_wait_pipe(filp); |
| 4883 | if (ret <= 0) |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 4884 | goto out_err; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4885 | |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 4886 | if (!iter->ent && !trace_find_next_entry_inc(iter)) { |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4887 | ret = -EFAULT; |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 4888 | goto out_err; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4889 | } |
| 4890 | |
Lai Jiangshan | 4f53596 | 2009-05-18 19:35:34 +0800 | [diff] [blame] | 4891 | trace_event_read_lock(); |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 4892 | trace_access_lock(iter->cpu_file); |
Lai Jiangshan | 4f53596 | 2009-05-18 19:35:34 +0800 | [diff] [blame] | 4893 | |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4894 | /* Fill as many pages as possible. */ |
Al Viro | a786c06 | 2014-04-11 12:01:03 -0400 | [diff] [blame] | 4895 | for (i = 0, rem = len; i < spd.nr_pages_max && rem; i++) { |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 4896 | spd.pages[i] = alloc_page(GFP_KERNEL); |
| 4897 | if (!spd.pages[i]) |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 4898 | break; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4899 | |
Frederic Weisbecker | fa7c7f6 | 2009-02-11 02:51:30 +0100 | [diff] [blame] | 4900 | rem = tracing_fill_pipe_page(rem, iter); |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4901 | |
| 4902 | /* Copy the data into the page, so we can start over. */ |
| 4903 | ret = trace_seq_to_buffer(&iter->seq, |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 4904 | page_address(spd.pages[i]), |
Steven Rostedt (Red Hat) | 5ac48378 | 2014-11-14 15:49:41 -0500 | [diff] [blame] | 4905 | trace_seq_used(&iter->seq)); |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4906 | if (ret < 0) { |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 4907 | __free_page(spd.pages[i]); |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4908 | break; |
| 4909 | } |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 4910 | spd.partial[i].offset = 0; |
Steven Rostedt (Red Hat) | 5ac48378 | 2014-11-14 15:49:41 -0500 | [diff] [blame] | 4911 | spd.partial[i].len = trace_seq_used(&iter->seq); |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4912 | |
Steven Rostedt | f952075 | 2009-03-02 14:04:40 -0500 | [diff] [blame] | 4913 | trace_seq_init(&iter->seq); |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4914 | } |
| 4915 | |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 4916 | trace_access_unlock(iter->cpu_file); |
Lai Jiangshan | 4f53596 | 2009-05-18 19:35:34 +0800 | [diff] [blame] | 4917 | trace_event_read_unlock(); |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 4918 | mutex_unlock(&iter->mutex); |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4919 | |
| 4920 | spd.nr_pages = i; |
| 4921 | |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 4922 | ret = splice_to_pipe(pipe, &spd); |
| 4923 | out: |
Eric Dumazet | 047fe36 | 2012-06-12 15:24:40 +0200 | [diff] [blame] | 4924 | splice_shrink_spd(&spd); |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 4925 | return ret; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4926 | |
Steven Rostedt | 34cd499 | 2009-02-09 12:06:29 -0500 | [diff] [blame] | 4927 | out_err: |
Frederic Weisbecker | d7350c3f | 2009-02-25 06:13:16 +0100 | [diff] [blame] | 4928 | mutex_unlock(&iter->mutex); |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 4929 | goto out; |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 4930 | } |
| 4931 | |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 4932 | static ssize_t |
| 4933 | tracing_entries_read(struct file *filp, char __user *ubuf, |
| 4934 | size_t cnt, loff_t *ppos) |
| 4935 | { |
Oleg Nesterov | 0bc392e | 2013-07-23 17:26:06 +0200 | [diff] [blame] | 4936 | struct inode *inode = file_inode(filp); |
| 4937 | struct trace_array *tr = inode->i_private; |
| 4938 | int cpu = tracing_get_cpu(inode); |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 4939 | char buf[64]; |
| 4940 | int r = 0; |
| 4941 | ssize_t ret; |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 4942 | |
Steven Rostedt | db526ca | 2009-03-12 13:53:25 -0400 | [diff] [blame] | 4943 | mutex_lock(&trace_types_lock); |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 4944 | |
Oleg Nesterov | 0bc392e | 2013-07-23 17:26:06 +0200 | [diff] [blame] | 4945 | if (cpu == RING_BUFFER_ALL_CPUS) { |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 4946 | int cpu, buf_size_same; |
| 4947 | unsigned long size; |
| 4948 | |
| 4949 | size = 0; |
| 4950 | buf_size_same = 1; |
| 4951 | /* check if all cpu sizes are same */ |
| 4952 | for_each_tracing_cpu(cpu) { |
| 4953 | /* fill in the size from first enabled cpu */ |
| 4954 | if (size == 0) |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 4955 | size = per_cpu_ptr(tr->trace_buffer.data, cpu)->entries; |
| 4956 | if (size != per_cpu_ptr(tr->trace_buffer.data, cpu)->entries) { |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 4957 | buf_size_same = 0; |
| 4958 | break; |
| 4959 | } |
| 4960 | } |
| 4961 | |
| 4962 | if (buf_size_same) { |
| 4963 | if (!ring_buffer_expanded) |
| 4964 | r = sprintf(buf, "%lu (expanded: %lu)\n", |
| 4965 | size >> 10, |
| 4966 | trace_buf_size >> 10); |
| 4967 | else |
| 4968 | r = sprintf(buf, "%lu\n", size >> 10); |
| 4969 | } else |
| 4970 | r = sprintf(buf, "X\n"); |
| 4971 | } else |
Oleg Nesterov | 0bc392e | 2013-07-23 17:26:06 +0200 | [diff] [blame] | 4972 | 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] | 4973 | |
Steven Rostedt | db526ca | 2009-03-12 13:53:25 -0400 | [diff] [blame] | 4974 | mutex_unlock(&trace_types_lock); |
| 4975 | |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 4976 | ret = simple_read_from_buffer(ubuf, cnt, ppos, buf, r); |
| 4977 | return ret; |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 4978 | } |
| 4979 | |
| 4980 | static ssize_t |
| 4981 | tracing_entries_write(struct file *filp, const char __user *ubuf, |
| 4982 | size_t cnt, loff_t *ppos) |
| 4983 | { |
Oleg Nesterov | 0bc392e | 2013-07-23 17:26:06 +0200 | [diff] [blame] | 4984 | struct inode *inode = file_inode(filp); |
| 4985 | struct trace_array *tr = inode->i_private; |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 4986 | unsigned long val; |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 4987 | int ret; |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 4988 | |
Peter Huewe | 22fe9b5 | 2011-06-07 21:58:27 +0200 | [diff] [blame] | 4989 | ret = kstrtoul_from_user(ubuf, cnt, 10, &val); |
| 4990 | if (ret) |
Steven Rostedt | c6caeeb | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 4991 | return ret; |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 4992 | |
| 4993 | /* must have at least 1 entry */ |
| 4994 | if (!val) |
| 4995 | return -EINVAL; |
| 4996 | |
Steven Rostedt | 1696b2b | 2008-11-13 00:09:35 -0500 | [diff] [blame] | 4997 | /* value is in KB */ |
| 4998 | val <<= 10; |
Oleg Nesterov | 0bc392e | 2013-07-23 17:26:06 +0200 | [diff] [blame] | 4999 | ret = tracing_resize_ring_buffer(tr, val, tracing_get_cpu(inode)); |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 5000 | if (ret < 0) |
| 5001 | return ret; |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 5002 | |
Jiri Olsa | cf8517c | 2009-10-23 19:36:16 -0400 | [diff] [blame] | 5003 | *ppos += cnt; |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 5004 | |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 5005 | return cnt; |
| 5006 | } |
Steven Rostedt | bf5e651 | 2008-11-10 21:46:00 -0500 | [diff] [blame] | 5007 | |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 5008 | static ssize_t |
Vaibhav Nagarnaik | f81ab07 | 2011-08-16 14:46:15 -0700 | [diff] [blame] | 5009 | tracing_total_entries_read(struct file *filp, char __user *ubuf, |
| 5010 | size_t cnt, loff_t *ppos) |
| 5011 | { |
| 5012 | struct trace_array *tr = filp->private_data; |
| 5013 | char buf[64]; |
| 5014 | int r, cpu; |
| 5015 | unsigned long size = 0, expanded_size = 0; |
| 5016 | |
| 5017 | mutex_lock(&trace_types_lock); |
| 5018 | for_each_tracing_cpu(cpu) { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5019 | size += per_cpu_ptr(tr->trace_buffer.data, cpu)->entries >> 10; |
Vaibhav Nagarnaik | f81ab07 | 2011-08-16 14:46:15 -0700 | [diff] [blame] | 5020 | if (!ring_buffer_expanded) |
| 5021 | expanded_size += trace_buf_size >> 10; |
| 5022 | } |
| 5023 | if (ring_buffer_expanded) |
| 5024 | r = sprintf(buf, "%lu\n", size); |
| 5025 | else |
| 5026 | r = sprintf(buf, "%lu (expanded: %lu)\n", size, expanded_size); |
| 5027 | mutex_unlock(&trace_types_lock); |
| 5028 | |
| 5029 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, r); |
| 5030 | } |
| 5031 | |
| 5032 | static ssize_t |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 5033 | tracing_free_buffer_write(struct file *filp, const char __user *ubuf, |
| 5034 | size_t cnt, loff_t *ppos) |
| 5035 | { |
| 5036 | /* |
| 5037 | * There is no need to read what the user has written, this function |
| 5038 | * is just to make sure that there is no error when "echo" is used |
| 5039 | */ |
| 5040 | |
| 5041 | *ppos += cnt; |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 5042 | |
| 5043 | return cnt; |
| 5044 | } |
| 5045 | |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 5046 | static int |
| 5047 | tracing_free_buffer_release(struct inode *inode, struct file *filp) |
| 5048 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5049 | struct trace_array *tr = inode->i_private; |
| 5050 | |
Steven Rostedt | cf30cf6 | 2011-06-14 22:44:07 -0400 | [diff] [blame] | 5051 | /* disable tracing ? */ |
Steven Rostedt (Red Hat) | 983f938 | 2015-09-30 09:42:05 -0400 | [diff] [blame] | 5052 | if (tr->trace_flags & TRACE_ITER_STOP_ON_FREE) |
Alexander Z Lam | 711e124 | 2013-08-02 18:36:15 -0700 | [diff] [blame] | 5053 | tracer_tracing_off(tr); |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 5054 | /* resize the ring buffer to 0 */ |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5055 | tracing_resize_ring_buffer(tr, 0, RING_BUFFER_ALL_CPUS); |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 5056 | |
Steven Rostedt (Red Hat) | 7b85af6 | 2013-07-01 23:34:22 -0400 | [diff] [blame] | 5057 | trace_array_put(tr); |
| 5058 | |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 5059 | return 0; |
| 5060 | } |
| 5061 | |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 5062 | static ssize_t |
| 5063 | tracing_mark_write(struct file *filp, const char __user *ubuf, |
| 5064 | size_t cnt, loff_t *fpos) |
| 5065 | { |
Steven Rostedt | d696b58 | 2011-09-22 11:50:27 -0400 | [diff] [blame] | 5066 | unsigned long addr = (unsigned long)ubuf; |
Alexander Z Lam | 2d71619 | 2013-07-01 15:31:24 -0700 | [diff] [blame] | 5067 | struct trace_array *tr = filp->private_data; |
Steven Rostedt | d696b58 | 2011-09-22 11:50:27 -0400 | [diff] [blame] | 5068 | struct ring_buffer_event *event; |
| 5069 | struct ring_buffer *buffer; |
| 5070 | struct print_entry *entry; |
| 5071 | unsigned long irq_flags; |
| 5072 | struct page *pages[2]; |
Steven Rostedt | 6edb2a8 | 2012-05-11 23:28:49 -0400 | [diff] [blame] | 5073 | void *map_page[2]; |
Steven Rostedt | d696b58 | 2011-09-22 11:50:27 -0400 | [diff] [blame] | 5074 | int nr_pages = 1; |
| 5075 | ssize_t written; |
Steven Rostedt | d696b58 | 2011-09-22 11:50:27 -0400 | [diff] [blame] | 5076 | int offset; |
| 5077 | int size; |
| 5078 | int len; |
| 5079 | int ret; |
Steven Rostedt | 6edb2a8 | 2012-05-11 23:28:49 -0400 | [diff] [blame] | 5080 | int i; |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 5081 | |
Steven Rostedt | c76f069 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 5082 | if (tracing_disabled) |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 5083 | return -EINVAL; |
| 5084 | |
Steven Rostedt (Red Hat) | 983f938 | 2015-09-30 09:42:05 -0400 | [diff] [blame] | 5085 | if (!(tr->trace_flags & TRACE_ITER_MARKERS)) |
Mandeep Singh Baines | 5224c3a | 2012-09-07 18:12:19 -0700 | [diff] [blame] | 5086 | return -EINVAL; |
| 5087 | |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 5088 | if (cnt > TRACE_BUF_SIZE) |
| 5089 | cnt = TRACE_BUF_SIZE; |
| 5090 | |
Steven Rostedt | d696b58 | 2011-09-22 11:50:27 -0400 | [diff] [blame] | 5091 | /* |
| 5092 | * Userspace is injecting traces into the kernel trace buffer. |
| 5093 | * We want to be as non intrusive as possible. |
| 5094 | * To do so, we do not want to allocate any special buffers |
| 5095 | * or take any locks, but instead write the userspace data |
| 5096 | * straight into the ring buffer. |
| 5097 | * |
| 5098 | * First we need to pin the userspace buffer into memory, |
| 5099 | * which, most likely it is, because it just referenced it. |
| 5100 | * But there's no guarantee that it is. By using get_user_pages_fast() |
| 5101 | * and kmap_atomic/kunmap_atomic() we can get access to the |
| 5102 | * pages directly. We then write the data directly into the |
| 5103 | * ring buffer. |
| 5104 | */ |
| 5105 | BUILD_BUG_ON(TRACE_BUF_SIZE >= PAGE_SIZE); |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 5106 | |
Steven Rostedt | d696b58 | 2011-09-22 11:50:27 -0400 | [diff] [blame] | 5107 | /* check if we cross pages */ |
| 5108 | if ((addr & PAGE_MASK) != ((addr + cnt) & PAGE_MASK)) |
| 5109 | nr_pages = 2; |
| 5110 | |
| 5111 | offset = addr & (PAGE_SIZE - 1); |
| 5112 | addr &= PAGE_MASK; |
| 5113 | |
| 5114 | ret = get_user_pages_fast(addr, nr_pages, 0, pages); |
| 5115 | if (ret < nr_pages) { |
| 5116 | while (--ret >= 0) |
| 5117 | put_page(pages[ret]); |
| 5118 | written = -EFAULT; |
| 5119 | goto out; |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 5120 | } |
| 5121 | |
Steven Rostedt | 6edb2a8 | 2012-05-11 23:28:49 -0400 | [diff] [blame] | 5122 | for (i = 0; i < nr_pages; i++) |
| 5123 | map_page[i] = kmap_atomic(pages[i]); |
Steven Rostedt | d696b58 | 2011-09-22 11:50:27 -0400 | [diff] [blame] | 5124 | |
| 5125 | local_save_flags(irq_flags); |
| 5126 | size = sizeof(*entry) + cnt + 2; /* possible \n added */ |
Alexander Z Lam | 2d71619 | 2013-07-01 15:31:24 -0700 | [diff] [blame] | 5127 | buffer = tr->trace_buffer.buffer; |
Steven Rostedt | d696b58 | 2011-09-22 11:50:27 -0400 | [diff] [blame] | 5128 | event = trace_buffer_lock_reserve(buffer, TRACE_PRINT, size, |
| 5129 | irq_flags, preempt_count()); |
| 5130 | if (!event) { |
| 5131 | /* Ring buffer disabled, return as if not open for write */ |
| 5132 | written = -EBADF; |
| 5133 | goto out_unlock; |
| 5134 | } |
| 5135 | |
| 5136 | entry = ring_buffer_event_data(event); |
| 5137 | entry->ip = _THIS_IP_; |
| 5138 | |
| 5139 | if (nr_pages == 2) { |
| 5140 | len = PAGE_SIZE - offset; |
Steven Rostedt | 6edb2a8 | 2012-05-11 23:28:49 -0400 | [diff] [blame] | 5141 | memcpy(&entry->buf, map_page[0] + offset, len); |
| 5142 | memcpy(&entry->buf[len], map_page[1], cnt - len); |
Steven Rostedt | d696b58 | 2011-09-22 11:50:27 -0400 | [diff] [blame] | 5143 | } else |
Steven Rostedt | 6edb2a8 | 2012-05-11 23:28:49 -0400 | [diff] [blame] | 5144 | memcpy(&entry->buf, map_page[0] + offset, cnt); |
Steven Rostedt | d696b58 | 2011-09-22 11:50:27 -0400 | [diff] [blame] | 5145 | |
| 5146 | if (entry->buf[cnt - 1] != '\n') { |
| 5147 | entry->buf[cnt] = '\n'; |
| 5148 | entry->buf[cnt + 1] = '\0'; |
| 5149 | } else |
| 5150 | entry->buf[cnt] = '\0'; |
| 5151 | |
Steven Rostedt | 7ffbd48 | 2012-10-11 12:14:25 -0400 | [diff] [blame] | 5152 | __buffer_unlock_commit(buffer, event); |
Steven Rostedt | d696b58 | 2011-09-22 11:50:27 -0400 | [diff] [blame] | 5153 | |
| 5154 | written = cnt; |
| 5155 | |
Marcin Slusarz | 1aa54bc | 2010-07-28 01:18:01 +0200 | [diff] [blame] | 5156 | *fpos += written; |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 5157 | |
Steven Rostedt | d696b58 | 2011-09-22 11:50:27 -0400 | [diff] [blame] | 5158 | out_unlock: |
Vikram Mulukutla | 7215853 | 2014-12-17 18:50:56 -0800 | [diff] [blame] | 5159 | for (i = nr_pages - 1; i >= 0; i--) { |
Steven Rostedt | 6edb2a8 | 2012-05-11 23:28:49 -0400 | [diff] [blame] | 5160 | kunmap_atomic(map_page[i]); |
| 5161 | put_page(pages[i]); |
| 5162 | } |
Steven Rostedt | d696b58 | 2011-09-22 11:50:27 -0400 | [diff] [blame] | 5163 | out: |
Marcin Slusarz | 1aa54bc | 2010-07-28 01:18:01 +0200 | [diff] [blame] | 5164 | return written; |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 5165 | } |
| 5166 | |
Li Zefan | 13f16d2 | 2009-12-08 11:16:11 +0800 | [diff] [blame] | 5167 | static int tracing_clock_show(struct seq_file *m, void *v) |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 5168 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5169 | struct trace_array *tr = m->private; |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 5170 | int i; |
| 5171 | |
| 5172 | for (i = 0; i < ARRAY_SIZE(trace_clocks); i++) |
Li Zefan | 13f16d2 | 2009-12-08 11:16:11 +0800 | [diff] [blame] | 5173 | seq_printf(m, |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 5174 | "%s%s%s%s", i ? " " : "", |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5175 | i == tr->clock_id ? "[" : "", trace_clocks[i].name, |
| 5176 | i == tr->clock_id ? "]" : ""); |
Li Zefan | 13f16d2 | 2009-12-08 11:16:11 +0800 | [diff] [blame] | 5177 | seq_putc(m, '\n'); |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 5178 | |
Li Zefan | 13f16d2 | 2009-12-08 11:16:11 +0800 | [diff] [blame] | 5179 | return 0; |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 5180 | } |
| 5181 | |
Steven Rostedt | e1e232c | 2014-02-10 23:38:46 -0500 | [diff] [blame] | 5182 | static int tracing_set_clock(struct trace_array *tr, const char *clockstr) |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 5183 | { |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 5184 | int i; |
| 5185 | |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 5186 | for (i = 0; i < ARRAY_SIZE(trace_clocks); i++) { |
| 5187 | if (strcmp(trace_clocks[i].name, clockstr) == 0) |
| 5188 | break; |
| 5189 | } |
| 5190 | if (i == ARRAY_SIZE(trace_clocks)) |
| 5191 | return -EINVAL; |
| 5192 | |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 5193 | mutex_lock(&trace_types_lock); |
| 5194 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5195 | tr->clock_id = i; |
| 5196 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5197 | ring_buffer_set_clock(tr->trace_buffer.buffer, trace_clocks[i].func); |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 5198 | |
David Sharp | 60303ed | 2012-10-11 16:27:52 -0700 | [diff] [blame] | 5199 | /* |
| 5200 | * New clock may not be consistent with the previous clock. |
| 5201 | * Reset the buffer so that it doesn't have incomparable timestamps. |
| 5202 | */ |
Alexander Z Lam | 9457158 | 2013-08-02 18:36:16 -0700 | [diff] [blame] | 5203 | tracing_reset_online_cpus(&tr->trace_buffer); |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5204 | |
| 5205 | #ifdef CONFIG_TRACER_MAX_TRACE |
| 5206 | if (tr->flags & TRACE_ARRAY_FL_GLOBAL && tr->max_buffer.buffer) |
| 5207 | 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] | 5208 | tracing_reset_online_cpus(&tr->max_buffer); |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5209 | #endif |
David Sharp | 60303ed | 2012-10-11 16:27:52 -0700 | [diff] [blame] | 5210 | |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 5211 | mutex_unlock(&trace_types_lock); |
| 5212 | |
Steven Rostedt | e1e232c | 2014-02-10 23:38:46 -0500 | [diff] [blame] | 5213 | return 0; |
| 5214 | } |
| 5215 | |
| 5216 | static ssize_t tracing_clock_write(struct file *filp, const char __user *ubuf, |
| 5217 | size_t cnt, loff_t *fpos) |
| 5218 | { |
| 5219 | struct seq_file *m = filp->private_data; |
| 5220 | struct trace_array *tr = m->private; |
| 5221 | char buf[64]; |
| 5222 | const char *clockstr; |
| 5223 | int ret; |
| 5224 | |
| 5225 | if (cnt >= sizeof(buf)) |
| 5226 | return -EINVAL; |
| 5227 | |
| 5228 | if (copy_from_user(&buf, ubuf, cnt)) |
| 5229 | return -EFAULT; |
| 5230 | |
| 5231 | buf[cnt] = 0; |
| 5232 | |
| 5233 | clockstr = strstrip(buf); |
| 5234 | |
| 5235 | ret = tracing_set_clock(tr, clockstr); |
| 5236 | if (ret) |
| 5237 | return ret; |
| 5238 | |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 5239 | *fpos += cnt; |
| 5240 | |
| 5241 | return cnt; |
| 5242 | } |
| 5243 | |
Li Zefan | 13f16d2 | 2009-12-08 11:16:11 +0800 | [diff] [blame] | 5244 | static int tracing_clock_open(struct inode *inode, struct file *file) |
| 5245 | { |
Steven Rostedt (Red Hat) | 7b85af6 | 2013-07-01 23:34:22 -0400 | [diff] [blame] | 5246 | struct trace_array *tr = inode->i_private; |
| 5247 | int ret; |
| 5248 | |
Li Zefan | 13f16d2 | 2009-12-08 11:16:11 +0800 | [diff] [blame] | 5249 | if (tracing_disabled) |
| 5250 | return -ENODEV; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5251 | |
Steven Rostedt (Red Hat) | 7b85af6 | 2013-07-01 23:34:22 -0400 | [diff] [blame] | 5252 | if (trace_array_get(tr)) |
| 5253 | return -ENODEV; |
| 5254 | |
| 5255 | ret = single_open(file, tracing_clock_show, inode->i_private); |
| 5256 | if (ret < 0) |
| 5257 | trace_array_put(tr); |
| 5258 | |
| 5259 | return ret; |
Li Zefan | 13f16d2 | 2009-12-08 11:16:11 +0800 | [diff] [blame] | 5260 | } |
| 5261 | |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 5262 | struct ftrace_buffer_info { |
| 5263 | struct trace_iterator iter; |
| 5264 | void *spare; |
| 5265 | unsigned int read; |
| 5266 | }; |
| 5267 | |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 5268 | #ifdef CONFIG_TRACER_SNAPSHOT |
| 5269 | static int tracing_snapshot_open(struct inode *inode, struct file *file) |
| 5270 | { |
Oleg Nesterov | 6484c71 | 2013-07-23 17:26:10 +0200 | [diff] [blame] | 5271 | struct trace_array *tr = inode->i_private; |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 5272 | struct trace_iterator *iter; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5273 | struct seq_file *m; |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 5274 | int ret = 0; |
| 5275 | |
Steven Rostedt (Red Hat) | ff45196 | 2013-07-01 22:50:29 -0400 | [diff] [blame] | 5276 | if (trace_array_get(tr) < 0) |
| 5277 | return -ENODEV; |
| 5278 | |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 5279 | if (file->f_mode & FMODE_READ) { |
Oleg Nesterov | 6484c71 | 2013-07-23 17:26:10 +0200 | [diff] [blame] | 5280 | iter = __tracing_open(inode, file, true); |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 5281 | if (IS_ERR(iter)) |
| 5282 | ret = PTR_ERR(iter); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5283 | } else { |
| 5284 | /* Writes still need the seq_file to hold the private data */ |
Alexander Z Lam | f77d09a | 2013-07-18 11:18:44 -0700 | [diff] [blame] | 5285 | ret = -ENOMEM; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5286 | m = kzalloc(sizeof(*m), GFP_KERNEL); |
| 5287 | if (!m) |
Alexander Z Lam | f77d09a | 2013-07-18 11:18:44 -0700 | [diff] [blame] | 5288 | goto out; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5289 | iter = kzalloc(sizeof(*iter), GFP_KERNEL); |
| 5290 | if (!iter) { |
| 5291 | kfree(m); |
Alexander Z Lam | f77d09a | 2013-07-18 11:18:44 -0700 | [diff] [blame] | 5292 | goto out; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5293 | } |
Alexander Z Lam | f77d09a | 2013-07-18 11:18:44 -0700 | [diff] [blame] | 5294 | ret = 0; |
| 5295 | |
Steven Rostedt (Red Hat) | ff45196 | 2013-07-01 22:50:29 -0400 | [diff] [blame] | 5296 | iter->tr = tr; |
Oleg Nesterov | 6484c71 | 2013-07-23 17:26:10 +0200 | [diff] [blame] | 5297 | iter->trace_buffer = &tr->max_buffer; |
| 5298 | iter->cpu_file = tracing_get_cpu(inode); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5299 | m->private = iter; |
| 5300 | file->private_data = m; |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 5301 | } |
Alexander Z Lam | f77d09a | 2013-07-18 11:18:44 -0700 | [diff] [blame] | 5302 | out: |
Steven Rostedt (Red Hat) | ff45196 | 2013-07-01 22:50:29 -0400 | [diff] [blame] | 5303 | if (ret < 0) |
| 5304 | trace_array_put(tr); |
| 5305 | |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 5306 | return ret; |
| 5307 | } |
| 5308 | |
| 5309 | static ssize_t |
| 5310 | tracing_snapshot_write(struct file *filp, const char __user *ubuf, size_t cnt, |
| 5311 | loff_t *ppos) |
| 5312 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5313 | struct seq_file *m = filp->private_data; |
| 5314 | struct trace_iterator *iter = m->private; |
| 5315 | struct trace_array *tr = iter->tr; |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 5316 | unsigned long val; |
| 5317 | int ret; |
| 5318 | |
| 5319 | ret = tracing_update_buffers(); |
| 5320 | if (ret < 0) |
| 5321 | return ret; |
| 5322 | |
| 5323 | ret = kstrtoul_from_user(ubuf, cnt, 10, &val); |
| 5324 | if (ret) |
| 5325 | return ret; |
| 5326 | |
| 5327 | mutex_lock(&trace_types_lock); |
| 5328 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5329 | if (tr->current_trace->use_max_tr) { |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 5330 | ret = -EBUSY; |
| 5331 | goto out; |
| 5332 | } |
| 5333 | |
| 5334 | switch (val) { |
| 5335 | case 0: |
Steven Rostedt (Red Hat) | f1affca | 2013-03-05 14:35:11 -0500 | [diff] [blame] | 5336 | if (iter->cpu_file != RING_BUFFER_ALL_CPUS) { |
| 5337 | ret = -EINVAL; |
| 5338 | break; |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 5339 | } |
Steven Rostedt (Red Hat) | 3209cff | 2013-03-12 11:17:54 -0400 | [diff] [blame] | 5340 | if (tr->allocated_snapshot) |
| 5341 | free_snapshot(tr); |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 5342 | break; |
| 5343 | case 1: |
Steven Rostedt (Red Hat) | f1affca | 2013-03-05 14:35:11 -0500 | [diff] [blame] | 5344 | /* Only allow per-cpu swap if the ring buffer supports it */ |
| 5345 | #ifndef CONFIG_RING_BUFFER_ALLOW_SWAP |
| 5346 | if (iter->cpu_file != RING_BUFFER_ALL_CPUS) { |
| 5347 | ret = -EINVAL; |
| 5348 | break; |
| 5349 | } |
| 5350 | #endif |
Steven Rostedt (Red Hat) | 45ad21c | 2013-03-05 18:25:02 -0500 | [diff] [blame] | 5351 | if (!tr->allocated_snapshot) { |
Steven Rostedt (Red Hat) | 3209cff | 2013-03-12 11:17:54 -0400 | [diff] [blame] | 5352 | ret = alloc_snapshot(tr); |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 5353 | if (ret < 0) |
| 5354 | break; |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 5355 | } |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 5356 | local_irq_disable(); |
| 5357 | /* Now, we're going to swap */ |
Steven Rostedt (Red Hat) | f1affca | 2013-03-05 14:35:11 -0500 | [diff] [blame] | 5358 | if (iter->cpu_file == RING_BUFFER_ALL_CPUS) |
Steven Rostedt (Red Hat) | ce9bae5 | 2013-03-05 21:23:55 -0500 | [diff] [blame] | 5359 | update_max_tr(tr, current, smp_processor_id()); |
Steven Rostedt (Red Hat) | f1affca | 2013-03-05 14:35:11 -0500 | [diff] [blame] | 5360 | else |
Steven Rostedt (Red Hat) | ce9bae5 | 2013-03-05 21:23:55 -0500 | [diff] [blame] | 5361 | update_max_tr_single(tr, current, iter->cpu_file); |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 5362 | local_irq_enable(); |
| 5363 | break; |
| 5364 | default: |
Steven Rostedt (Red Hat) | 45ad21c | 2013-03-05 18:25:02 -0500 | [diff] [blame] | 5365 | if (tr->allocated_snapshot) { |
Steven Rostedt (Red Hat) | f1affca | 2013-03-05 14:35:11 -0500 | [diff] [blame] | 5366 | if (iter->cpu_file == RING_BUFFER_ALL_CPUS) |
| 5367 | tracing_reset_online_cpus(&tr->max_buffer); |
| 5368 | else |
| 5369 | tracing_reset(&tr->max_buffer, iter->cpu_file); |
| 5370 | } |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 5371 | break; |
| 5372 | } |
| 5373 | |
| 5374 | if (ret >= 0) { |
| 5375 | *ppos += cnt; |
| 5376 | ret = cnt; |
| 5377 | } |
| 5378 | out: |
| 5379 | mutex_unlock(&trace_types_lock); |
| 5380 | return ret; |
| 5381 | } |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5382 | |
| 5383 | static int tracing_snapshot_release(struct inode *inode, struct file *file) |
| 5384 | { |
| 5385 | struct seq_file *m = file->private_data; |
Steven Rostedt (Red Hat) | ff45196 | 2013-07-01 22:50:29 -0400 | [diff] [blame] | 5386 | int ret; |
| 5387 | |
| 5388 | ret = tracing_release(inode, file); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5389 | |
| 5390 | if (file->f_mode & FMODE_READ) |
Steven Rostedt (Red Hat) | ff45196 | 2013-07-01 22:50:29 -0400 | [diff] [blame] | 5391 | return ret; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5392 | |
| 5393 | /* If write only, the seq_file is just a stub */ |
| 5394 | if (m) |
| 5395 | kfree(m->private); |
| 5396 | kfree(m); |
| 5397 | |
| 5398 | return 0; |
| 5399 | } |
| 5400 | |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 5401 | static int tracing_buffers_open(struct inode *inode, struct file *filp); |
| 5402 | static ssize_t tracing_buffers_read(struct file *filp, char __user *ubuf, |
| 5403 | size_t count, loff_t *ppos); |
| 5404 | static int tracing_buffers_release(struct inode *inode, struct file *file); |
| 5405 | static ssize_t tracing_buffers_splice_read(struct file *file, loff_t *ppos, |
| 5406 | struct pipe_inode_info *pipe, size_t len, unsigned int flags); |
| 5407 | |
| 5408 | static int snapshot_raw_open(struct inode *inode, struct file *filp) |
| 5409 | { |
| 5410 | struct ftrace_buffer_info *info; |
| 5411 | int ret; |
| 5412 | |
| 5413 | ret = tracing_buffers_open(inode, filp); |
| 5414 | if (ret < 0) |
| 5415 | return ret; |
| 5416 | |
| 5417 | info = filp->private_data; |
| 5418 | |
| 5419 | if (info->iter.trace->use_max_tr) { |
| 5420 | tracing_buffers_release(inode, filp); |
| 5421 | return -EBUSY; |
| 5422 | } |
| 5423 | |
| 5424 | info->iter.snapshot = true; |
| 5425 | info->iter.trace_buffer = &info->iter.tr->max_buffer; |
| 5426 | |
| 5427 | return ret; |
| 5428 | } |
| 5429 | |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 5430 | #endif /* CONFIG_TRACER_SNAPSHOT */ |
| 5431 | |
| 5432 | |
Stanislav Fomichev | 6508fa7 | 2014-07-18 15:17:27 +0400 | [diff] [blame] | 5433 | static const struct file_operations tracing_thresh_fops = { |
| 5434 | .open = tracing_open_generic, |
| 5435 | .read = tracing_thresh_read, |
| 5436 | .write = tracing_thresh_write, |
| 5437 | .llseek = generic_file_llseek, |
| 5438 | }; |
| 5439 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 5440 | static const struct file_operations tracing_max_lat_fops = { |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 5441 | .open = tracing_open_generic, |
| 5442 | .read = tracing_max_lat_read, |
| 5443 | .write = tracing_max_lat_write, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 5444 | .llseek = generic_file_llseek, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5445 | }; |
| 5446 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 5447 | static const struct file_operations set_tracer_fops = { |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 5448 | .open = tracing_open_generic, |
| 5449 | .read = tracing_set_trace_read, |
| 5450 | .write = tracing_set_trace_write, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 5451 | .llseek = generic_file_llseek, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5452 | }; |
| 5453 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 5454 | static const struct file_operations tracing_pipe_fops = { |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 5455 | .open = tracing_open_pipe, |
Soeren Sandmann Pedersen | 2a2cc8f | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 5456 | .poll = tracing_poll_pipe, |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 5457 | .read = tracing_read_pipe, |
Eduard - Gabriel Munteanu | 3c56819 | 2009-02-09 08:15:56 +0200 | [diff] [blame] | 5458 | .splice_read = tracing_splice_read_pipe, |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 5459 | .release = tracing_release_pipe, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 5460 | .llseek = no_llseek, |
Steven Rostedt | b3806b4 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 5461 | }; |
| 5462 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 5463 | static const struct file_operations tracing_entries_fops = { |
Oleg Nesterov | 0bc392e | 2013-07-23 17:26:06 +0200 | [diff] [blame] | 5464 | .open = tracing_open_generic_tr, |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 5465 | .read = tracing_entries_read, |
| 5466 | .write = tracing_entries_write, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 5467 | .llseek = generic_file_llseek, |
Oleg Nesterov | 0bc392e | 2013-07-23 17:26:06 +0200 | [diff] [blame] | 5468 | .release = tracing_release_generic_tr, |
Steven Rostedt | a98a3c3 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 5469 | }; |
| 5470 | |
Vaibhav Nagarnaik | f81ab07 | 2011-08-16 14:46:15 -0700 | [diff] [blame] | 5471 | static const struct file_operations tracing_total_entries_fops = { |
Steven Rostedt (Red Hat) | 7b85af6 | 2013-07-01 23:34:22 -0400 | [diff] [blame] | 5472 | .open = tracing_open_generic_tr, |
Vaibhav Nagarnaik | f81ab07 | 2011-08-16 14:46:15 -0700 | [diff] [blame] | 5473 | .read = tracing_total_entries_read, |
| 5474 | .llseek = generic_file_llseek, |
Steven Rostedt (Red Hat) | 7b85af6 | 2013-07-01 23:34:22 -0400 | [diff] [blame] | 5475 | .release = tracing_release_generic_tr, |
Vaibhav Nagarnaik | f81ab07 | 2011-08-16 14:46:15 -0700 | [diff] [blame] | 5476 | }; |
| 5477 | |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 5478 | static const struct file_operations tracing_free_buffer_fops = { |
Steven Rostedt (Red Hat) | 7b85af6 | 2013-07-01 23:34:22 -0400 | [diff] [blame] | 5479 | .open = tracing_open_generic_tr, |
Vaibhav Nagarnaik | 4f271a2 | 2011-06-13 17:51:57 -0700 | [diff] [blame] | 5480 | .write = tracing_free_buffer_write, |
| 5481 | .release = tracing_free_buffer_release, |
| 5482 | }; |
| 5483 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 5484 | static const struct file_operations tracing_mark_fops = { |
Steven Rostedt (Red Hat) | 7b85af6 | 2013-07-01 23:34:22 -0400 | [diff] [blame] | 5485 | .open = tracing_open_generic_tr, |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 5486 | .write = tracing_mark_write, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 5487 | .llseek = generic_file_llseek, |
Steven Rostedt (Red Hat) | 7b85af6 | 2013-07-01 23:34:22 -0400 | [diff] [blame] | 5488 | .release = tracing_release_generic_tr, |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 5489 | }; |
| 5490 | |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 5491 | static const struct file_operations trace_clock_fops = { |
Li Zefan | 13f16d2 | 2009-12-08 11:16:11 +0800 | [diff] [blame] | 5492 | .open = tracing_clock_open, |
| 5493 | .read = seq_read, |
| 5494 | .llseek = seq_lseek, |
Steven Rostedt (Red Hat) | 7b85af6 | 2013-07-01 23:34:22 -0400 | [diff] [blame] | 5495 | .release = tracing_single_release_tr, |
Zhaolei | 5079f32 | 2009-08-25 16:12:56 +0800 | [diff] [blame] | 5496 | .write = tracing_clock_write, |
| 5497 | }; |
| 5498 | |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 5499 | #ifdef CONFIG_TRACER_SNAPSHOT |
| 5500 | static const struct file_operations snapshot_fops = { |
| 5501 | .open = tracing_snapshot_open, |
| 5502 | .read = seq_read, |
| 5503 | .write = tracing_snapshot_write, |
Steven Rostedt (Red Hat) | 098c879 | 2013-12-21 17:39:40 -0500 | [diff] [blame] | 5504 | .llseek = tracing_lseek, |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 5505 | .release = tracing_snapshot_release, |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 5506 | }; |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 5507 | |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 5508 | static const struct file_operations snapshot_raw_fops = { |
| 5509 | .open = snapshot_raw_open, |
| 5510 | .read = tracing_buffers_read, |
| 5511 | .release = tracing_buffers_release, |
| 5512 | .splice_read = tracing_buffers_splice_read, |
| 5513 | .llseek = no_llseek, |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5514 | }; |
| 5515 | |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 5516 | #endif /* CONFIG_TRACER_SNAPSHOT */ |
| 5517 | |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5518 | static int tracing_buffers_open(struct inode *inode, struct file *filp) |
| 5519 | { |
Oleg Nesterov | 46ef2be | 2013-07-23 17:26:00 +0200 | [diff] [blame] | 5520 | struct trace_array *tr = inode->i_private; |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5521 | struct ftrace_buffer_info *info; |
Steven Rostedt (Red Hat) | 7b85af6 | 2013-07-01 23:34:22 -0400 | [diff] [blame] | 5522 | int ret; |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5523 | |
| 5524 | if (tracing_disabled) |
| 5525 | return -ENODEV; |
| 5526 | |
Steven Rostedt (Red Hat) | 7b85af6 | 2013-07-01 23:34:22 -0400 | [diff] [blame] | 5527 | if (trace_array_get(tr) < 0) |
| 5528 | return -ENODEV; |
| 5529 | |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5530 | info = kzalloc(sizeof(*info), GFP_KERNEL); |
Steven Rostedt (Red Hat) | 7b85af6 | 2013-07-01 23:34:22 -0400 | [diff] [blame] | 5531 | if (!info) { |
| 5532 | trace_array_put(tr); |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5533 | return -ENOMEM; |
Steven Rostedt (Red Hat) | 7b85af6 | 2013-07-01 23:34:22 -0400 | [diff] [blame] | 5534 | } |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5535 | |
Steven Rostedt (Red Hat) | a695cb5 | 2013-03-06 15:27:24 -0500 | [diff] [blame] | 5536 | mutex_lock(&trace_types_lock); |
| 5537 | |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 5538 | info->iter.tr = tr; |
Oleg Nesterov | 46ef2be | 2013-07-23 17:26:00 +0200 | [diff] [blame] | 5539 | info->iter.cpu_file = tracing_get_cpu(inode); |
Steven Rostedt | b627344 | 2013-02-28 13:44:11 -0500 | [diff] [blame] | 5540 | info->iter.trace = tr->current_trace; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5541 | info->iter.trace_buffer = &tr->trace_buffer; |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 5542 | info->spare = NULL; |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5543 | /* Force reading ring buffer for first read */ |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 5544 | info->read = (unsigned int)-1; |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5545 | |
| 5546 | filp->private_data = info; |
| 5547 | |
Steven Rostedt (Red Hat) | cf6ab6d | 2014-12-15 20:13:31 -0500 | [diff] [blame] | 5548 | tr->current_trace->ref++; |
| 5549 | |
Steven Rostedt (Red Hat) | a695cb5 | 2013-03-06 15:27:24 -0500 | [diff] [blame] | 5550 | mutex_unlock(&trace_types_lock); |
| 5551 | |
Steven Rostedt (Red Hat) | 7b85af6 | 2013-07-01 23:34:22 -0400 | [diff] [blame] | 5552 | ret = nonseekable_open(inode, filp); |
| 5553 | if (ret < 0) |
| 5554 | trace_array_put(tr); |
| 5555 | |
| 5556 | return ret; |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5557 | } |
| 5558 | |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 5559 | static unsigned int |
| 5560 | tracing_buffers_poll(struct file *filp, poll_table *poll_table) |
| 5561 | { |
| 5562 | struct ftrace_buffer_info *info = filp->private_data; |
| 5563 | struct trace_iterator *iter = &info->iter; |
| 5564 | |
| 5565 | return trace_poll(iter, filp, poll_table); |
| 5566 | } |
| 5567 | |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5568 | static ssize_t |
| 5569 | tracing_buffers_read(struct file *filp, char __user *ubuf, |
| 5570 | size_t count, loff_t *ppos) |
| 5571 | { |
| 5572 | struct ftrace_buffer_info *info = filp->private_data; |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 5573 | struct trace_iterator *iter = &info->iter; |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5574 | ssize_t ret; |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 5575 | ssize_t size; |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5576 | |
Steven Rostedt | 2dc5d12 | 2009-03-04 19:10:05 -0500 | [diff] [blame] | 5577 | if (!count) |
| 5578 | return 0; |
| 5579 | |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 5580 | #ifdef CONFIG_TRACER_MAX_TRACE |
Steven Rostedt (Red Hat) | d716ff7 | 2014-12-15 22:31:07 -0500 | [diff] [blame] | 5581 | if (iter->snapshot && iter->tr->current_trace->use_max_tr) |
| 5582 | return -EBUSY; |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 5583 | #endif |
| 5584 | |
Lai Jiangshan | ddd538f | 2009-04-02 15:16:59 +0800 | [diff] [blame] | 5585 | if (!info->spare) |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5586 | info->spare = ring_buffer_alloc_read_page(iter->trace_buffer->buffer, |
| 5587 | iter->cpu_file); |
Lai Jiangshan | ddd538f | 2009-04-02 15:16:59 +0800 | [diff] [blame] | 5588 | if (!info->spare) |
Steven Rostedt (Red Hat) | d716ff7 | 2014-12-15 22:31:07 -0500 | [diff] [blame] | 5589 | return -ENOMEM; |
Lai Jiangshan | ddd538f | 2009-04-02 15:16:59 +0800 | [diff] [blame] | 5590 | |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5591 | /* Do we have previous read data to read? */ |
| 5592 | if (info->read < PAGE_SIZE) |
| 5593 | goto read; |
| 5594 | |
Steven Rostedt | b627344 | 2013-02-28 13:44:11 -0500 | [diff] [blame] | 5595 | again: |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 5596 | trace_access_lock(iter->cpu_file); |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5597 | ret = ring_buffer_read_page(iter->trace_buffer->buffer, |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5598 | &info->spare, |
| 5599 | count, |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 5600 | iter->cpu_file, 0); |
| 5601 | trace_access_unlock(iter->cpu_file); |
Steven Rostedt | b627344 | 2013-02-28 13:44:11 -0500 | [diff] [blame] | 5602 | |
| 5603 | if (ret < 0) { |
| 5604 | if (trace_empty(iter)) { |
Steven Rostedt (Red Hat) | d716ff7 | 2014-12-15 22:31:07 -0500 | [diff] [blame] | 5605 | if ((filp->f_flags & O_NONBLOCK)) |
| 5606 | return -EAGAIN; |
| 5607 | |
Rabin Vincent | e30f53a | 2014-11-10 19:46:34 +0100 | [diff] [blame] | 5608 | ret = wait_on_pipe(iter, false); |
Steven Rostedt (Red Hat) | d716ff7 | 2014-12-15 22:31:07 -0500 | [diff] [blame] | 5609 | if (ret) |
| 5610 | return ret; |
| 5611 | |
Steven Rostedt | b627344 | 2013-02-28 13:44:11 -0500 | [diff] [blame] | 5612 | goto again; |
| 5613 | } |
Steven Rostedt (Red Hat) | d716ff7 | 2014-12-15 22:31:07 -0500 | [diff] [blame] | 5614 | return 0; |
Steven Rostedt | b627344 | 2013-02-28 13:44:11 -0500 | [diff] [blame] | 5615 | } |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5616 | |
Steven Rostedt | 436fc28 | 2011-10-14 10:44:25 -0400 | [diff] [blame] | 5617 | info->read = 0; |
Steven Rostedt | b627344 | 2013-02-28 13:44:11 -0500 | [diff] [blame] | 5618 | read: |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5619 | size = PAGE_SIZE - info->read; |
| 5620 | if (size > count) |
| 5621 | size = count; |
| 5622 | |
| 5623 | ret = copy_to_user(ubuf, info->spare + info->read, size); |
Steven Rostedt (Red Hat) | d716ff7 | 2014-12-15 22:31:07 -0500 | [diff] [blame] | 5624 | if (ret == size) |
| 5625 | return -EFAULT; |
| 5626 | |
Steven Rostedt | 2dc5d12 | 2009-03-04 19:10:05 -0500 | [diff] [blame] | 5627 | size -= ret; |
| 5628 | |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5629 | *ppos += size; |
| 5630 | info->read += size; |
| 5631 | |
| 5632 | return size; |
| 5633 | } |
| 5634 | |
| 5635 | static int tracing_buffers_release(struct inode *inode, struct file *file) |
| 5636 | { |
| 5637 | struct ftrace_buffer_info *info = file->private_data; |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 5638 | struct trace_iterator *iter = &info->iter; |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5639 | |
Steven Rostedt (Red Hat) | a695cb5 | 2013-03-06 15:27:24 -0500 | [diff] [blame] | 5640 | mutex_lock(&trace_types_lock); |
| 5641 | |
Steven Rostedt (Red Hat) | cf6ab6d | 2014-12-15 20:13:31 -0500 | [diff] [blame] | 5642 | iter->tr->current_trace->ref--; |
| 5643 | |
Steven Rostedt (Red Hat) | ff45196 | 2013-07-01 22:50:29 -0400 | [diff] [blame] | 5644 | __trace_array_put(iter->tr); |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5645 | |
Lai Jiangshan | ddd538f | 2009-04-02 15:16:59 +0800 | [diff] [blame] | 5646 | if (info->spare) |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5647 | ring_buffer_free_read_page(iter->trace_buffer->buffer, info->spare); |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5648 | kfree(info); |
| 5649 | |
Steven Rostedt (Red Hat) | a695cb5 | 2013-03-06 15:27:24 -0500 | [diff] [blame] | 5650 | mutex_unlock(&trace_types_lock); |
| 5651 | |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5652 | return 0; |
| 5653 | } |
| 5654 | |
| 5655 | struct buffer_ref { |
| 5656 | struct ring_buffer *buffer; |
| 5657 | void *page; |
| 5658 | int ref; |
| 5659 | }; |
| 5660 | |
| 5661 | static void buffer_pipe_buf_release(struct pipe_inode_info *pipe, |
| 5662 | struct pipe_buffer *buf) |
| 5663 | { |
| 5664 | struct buffer_ref *ref = (struct buffer_ref *)buf->private; |
| 5665 | |
| 5666 | if (--ref->ref) |
| 5667 | return; |
| 5668 | |
| 5669 | ring_buffer_free_read_page(ref->buffer, ref->page); |
| 5670 | kfree(ref); |
| 5671 | buf->private = 0; |
| 5672 | } |
| 5673 | |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5674 | static void buffer_pipe_buf_get(struct pipe_inode_info *pipe, |
| 5675 | struct pipe_buffer *buf) |
| 5676 | { |
| 5677 | struct buffer_ref *ref = (struct buffer_ref *)buf->private; |
| 5678 | |
| 5679 | ref->ref++; |
| 5680 | } |
| 5681 | |
| 5682 | /* Pipe buffer operations for a buffer. */ |
Alexey Dobriyan | 28dfef8 | 2009-12-15 16:46:48 -0800 | [diff] [blame] | 5683 | static const struct pipe_buf_operations buffer_pipe_buf_ops = { |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5684 | .can_merge = 0, |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5685 | .confirm = generic_pipe_buf_confirm, |
| 5686 | .release = buffer_pipe_buf_release, |
Masami Hiramatsu | d55cb6c | 2012-08-09 21:31:10 +0900 | [diff] [blame] | 5687 | .steal = generic_pipe_buf_steal, |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5688 | .get = buffer_pipe_buf_get, |
| 5689 | }; |
| 5690 | |
| 5691 | /* |
| 5692 | * Callback from splice_to_pipe(), if we need to release some pages |
| 5693 | * at the end of the spd in case we error'ed out in filling the pipe. |
| 5694 | */ |
| 5695 | static void buffer_spd_release(struct splice_pipe_desc *spd, unsigned int i) |
| 5696 | { |
| 5697 | struct buffer_ref *ref = |
| 5698 | (struct buffer_ref *)spd->partial[i].private; |
| 5699 | |
| 5700 | if (--ref->ref) |
| 5701 | return; |
| 5702 | |
| 5703 | ring_buffer_free_read_page(ref->buffer, ref->page); |
| 5704 | kfree(ref); |
| 5705 | spd->partial[i].private = 0; |
| 5706 | } |
| 5707 | |
| 5708 | static ssize_t |
| 5709 | tracing_buffers_splice_read(struct file *file, loff_t *ppos, |
| 5710 | struct pipe_inode_info *pipe, size_t len, |
| 5711 | unsigned int flags) |
| 5712 | { |
| 5713 | struct ftrace_buffer_info *info = file->private_data; |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 5714 | struct trace_iterator *iter = &info->iter; |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 5715 | struct partial_page partial_def[PIPE_DEF_BUFFERS]; |
| 5716 | struct page *pages_def[PIPE_DEF_BUFFERS]; |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5717 | struct splice_pipe_desc spd = { |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 5718 | .pages = pages_def, |
| 5719 | .partial = partial_def, |
Eric Dumazet | 047fe36 | 2012-06-12 15:24:40 +0200 | [diff] [blame] | 5720 | .nr_pages_max = PIPE_DEF_BUFFERS, |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5721 | .flags = flags, |
| 5722 | .ops = &buffer_pipe_buf_ops, |
| 5723 | .spd_release = buffer_spd_release, |
| 5724 | }; |
| 5725 | struct buffer_ref *ref; |
Steven Rostedt | 93459c6 | 2009-04-29 00:23:13 -0400 | [diff] [blame] | 5726 | int entries, size, i; |
Rabin Vincent | 07906da | 2014-11-06 22:26:07 +0100 | [diff] [blame] | 5727 | ssize_t ret = 0; |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5728 | |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 5729 | #ifdef CONFIG_TRACER_MAX_TRACE |
Steven Rostedt (Red Hat) | d716ff7 | 2014-12-15 22:31:07 -0500 | [diff] [blame] | 5730 | if (iter->snapshot && iter->tr->current_trace->use_max_tr) |
| 5731 | return -EBUSY; |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 5732 | #endif |
| 5733 | |
Steven Rostedt (Red Hat) | d716ff7 | 2014-12-15 22:31:07 -0500 | [diff] [blame] | 5734 | if (splice_grow_spd(pipe, &spd)) |
| 5735 | return -ENOMEM; |
Jens Axboe | 35f3d14 | 2010-05-20 10:43:18 +0200 | [diff] [blame] | 5736 | |
Steven Rostedt (Red Hat) | d716ff7 | 2014-12-15 22:31:07 -0500 | [diff] [blame] | 5737 | if (*ppos & (PAGE_SIZE - 1)) |
| 5738 | return -EINVAL; |
Lai Jiangshan | 93cfb3c | 2009-04-02 15:17:08 +0800 | [diff] [blame] | 5739 | |
| 5740 | if (len & (PAGE_SIZE - 1)) { |
Steven Rostedt (Red Hat) | d716ff7 | 2014-12-15 22:31:07 -0500 | [diff] [blame] | 5741 | if (len < PAGE_SIZE) |
| 5742 | return -EINVAL; |
Lai Jiangshan | 93cfb3c | 2009-04-02 15:17:08 +0800 | [diff] [blame] | 5743 | len &= PAGE_MASK; |
| 5744 | } |
| 5745 | |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 5746 | again: |
| 5747 | trace_access_lock(iter->cpu_file); |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5748 | entries = ring_buffer_entries_cpu(iter->trace_buffer->buffer, iter->cpu_file); |
Steven Rostedt | 93459c6 | 2009-04-29 00:23:13 -0400 | [diff] [blame] | 5749 | |
Al Viro | a786c06 | 2014-04-11 12:01:03 -0400 | [diff] [blame] | 5750 | 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] | 5751 | struct page *page; |
| 5752 | int r; |
| 5753 | |
| 5754 | ref = kzalloc(sizeof(*ref), GFP_KERNEL); |
Rabin Vincent | 07906da | 2014-11-06 22:26:07 +0100 | [diff] [blame] | 5755 | if (!ref) { |
| 5756 | ret = -ENOMEM; |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5757 | break; |
Rabin Vincent | 07906da | 2014-11-06 22:26:07 +0100 | [diff] [blame] | 5758 | } |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5759 | |
Steven Rostedt | 7267fa6 | 2009-04-29 00:16:21 -0400 | [diff] [blame] | 5760 | ref->ref = 1; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5761 | ref->buffer = iter->trace_buffer->buffer; |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 5762 | ref->page = ring_buffer_alloc_read_page(ref->buffer, iter->cpu_file); |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5763 | if (!ref->page) { |
Rabin Vincent | 07906da | 2014-11-06 22:26:07 +0100 | [diff] [blame] | 5764 | ret = -ENOMEM; |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5765 | kfree(ref); |
| 5766 | break; |
| 5767 | } |
| 5768 | |
| 5769 | r = ring_buffer_read_page(ref->buffer, &ref->page, |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 5770 | len, iter->cpu_file, 1); |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5771 | if (r < 0) { |
Vaibhav Nagarnaik | 7ea5906 | 2011-05-03 17:56:42 -0700 | [diff] [blame] | 5772 | ring_buffer_free_read_page(ref->buffer, ref->page); |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5773 | kfree(ref); |
| 5774 | break; |
| 5775 | } |
| 5776 | |
| 5777 | /* |
| 5778 | * zero out any left over data, this is going to |
| 5779 | * user land. |
| 5780 | */ |
| 5781 | size = ring_buffer_page_len(ref->page); |
| 5782 | if (size < PAGE_SIZE) |
| 5783 | memset(ref->page + size, 0, PAGE_SIZE - size); |
| 5784 | |
| 5785 | page = virt_to_page(ref->page); |
| 5786 | |
| 5787 | spd.pages[i] = page; |
| 5788 | spd.partial[i].len = PAGE_SIZE; |
| 5789 | spd.partial[i].offset = 0; |
| 5790 | spd.partial[i].private = (unsigned long)ref; |
| 5791 | spd.nr_pages++; |
Lai Jiangshan | 93cfb3c | 2009-04-02 15:17:08 +0800 | [diff] [blame] | 5792 | *ppos += PAGE_SIZE; |
Steven Rostedt | 93459c6 | 2009-04-29 00:23:13 -0400 | [diff] [blame] | 5793 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5794 | entries = ring_buffer_entries_cpu(iter->trace_buffer->buffer, iter->cpu_file); |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5795 | } |
| 5796 | |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 5797 | trace_access_unlock(iter->cpu_file); |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5798 | spd.nr_pages = i; |
| 5799 | |
| 5800 | /* did we read anything? */ |
| 5801 | if (!spd.nr_pages) { |
Rabin Vincent | 07906da | 2014-11-06 22:26:07 +0100 | [diff] [blame] | 5802 | if (ret) |
Steven Rostedt (Red Hat) | d716ff7 | 2014-12-15 22:31:07 -0500 | [diff] [blame] | 5803 | return ret; |
Rabin Vincent | 07906da | 2014-11-06 22:26:07 +0100 | [diff] [blame] | 5804 | |
Steven Rostedt (Red Hat) | d716ff7 | 2014-12-15 22:31:07 -0500 | [diff] [blame] | 5805 | if ((file->f_flags & O_NONBLOCK) || (flags & SPLICE_F_NONBLOCK)) |
| 5806 | return -EAGAIN; |
| 5807 | |
Rabin Vincent | e30f53a | 2014-11-10 19:46:34 +0100 | [diff] [blame] | 5808 | ret = wait_on_pipe(iter, true); |
Steven Rostedt (Red Hat) | 8b8b368 | 2014-06-10 09:46:00 -0400 | [diff] [blame] | 5809 | if (ret) |
Steven Rostedt (Red Hat) | d716ff7 | 2014-12-15 22:31:07 -0500 | [diff] [blame] | 5810 | return ret; |
Rabin Vincent | e30f53a | 2014-11-10 19:46:34 +0100 | [diff] [blame] | 5811 | |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 5812 | goto again; |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5813 | } |
| 5814 | |
| 5815 | ret = splice_to_pipe(pipe, &spd); |
Eric Dumazet | 047fe36 | 2012-06-12 15:24:40 +0200 | [diff] [blame] | 5816 | splice_shrink_spd(&spd); |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 5817 | |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5818 | return ret; |
| 5819 | } |
| 5820 | |
| 5821 | static const struct file_operations tracing_buffers_fops = { |
| 5822 | .open = tracing_buffers_open, |
| 5823 | .read = tracing_buffers_read, |
Steven Rostedt | cc60cdc | 2013-02-28 09:17:16 -0500 | [diff] [blame] | 5824 | .poll = tracing_buffers_poll, |
Steven Rostedt | 2cadf91 | 2008-12-01 22:20:19 -0500 | [diff] [blame] | 5825 | .release = tracing_buffers_release, |
| 5826 | .splice_read = tracing_buffers_splice_read, |
| 5827 | .llseek = no_llseek, |
| 5828 | }; |
| 5829 | |
Steven Rostedt | c8d7718 | 2009-04-29 18:03:45 -0400 | [diff] [blame] | 5830 | static ssize_t |
| 5831 | tracing_stats_read(struct file *filp, char __user *ubuf, |
| 5832 | size_t count, loff_t *ppos) |
| 5833 | { |
Oleg Nesterov | 4d3435b | 2013-07-23 17:26:03 +0200 | [diff] [blame] | 5834 | struct inode *inode = file_inode(filp); |
| 5835 | struct trace_array *tr = inode->i_private; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5836 | struct trace_buffer *trace_buf = &tr->trace_buffer; |
Oleg Nesterov | 4d3435b | 2013-07-23 17:26:03 +0200 | [diff] [blame] | 5837 | int cpu = tracing_get_cpu(inode); |
Steven Rostedt | c8d7718 | 2009-04-29 18:03:45 -0400 | [diff] [blame] | 5838 | struct trace_seq *s; |
| 5839 | unsigned long cnt; |
Vaibhav Nagarnaik | c64e148 | 2011-08-16 14:46:16 -0700 | [diff] [blame] | 5840 | unsigned long long t; |
| 5841 | unsigned long usec_rem; |
Steven Rostedt | c8d7718 | 2009-04-29 18:03:45 -0400 | [diff] [blame] | 5842 | |
Li Zefan | e4f2d10 | 2009-06-15 10:57:28 +0800 | [diff] [blame] | 5843 | s = kmalloc(sizeof(*s), GFP_KERNEL); |
Steven Rostedt | c8d7718 | 2009-04-29 18:03:45 -0400 | [diff] [blame] | 5844 | if (!s) |
Roel Kluin | a646365 | 2009-11-11 22:26:35 +0100 | [diff] [blame] | 5845 | return -ENOMEM; |
Steven Rostedt | c8d7718 | 2009-04-29 18:03:45 -0400 | [diff] [blame] | 5846 | |
| 5847 | trace_seq_init(s); |
| 5848 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5849 | cnt = ring_buffer_entries_cpu(trace_buf->buffer, cpu); |
Steven Rostedt | c8d7718 | 2009-04-29 18:03:45 -0400 | [diff] [blame] | 5850 | trace_seq_printf(s, "entries: %ld\n", cnt); |
| 5851 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5852 | cnt = ring_buffer_overrun_cpu(trace_buf->buffer, cpu); |
Steven Rostedt | c8d7718 | 2009-04-29 18:03:45 -0400 | [diff] [blame] | 5853 | trace_seq_printf(s, "overrun: %ld\n", cnt); |
| 5854 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5855 | cnt = ring_buffer_commit_overrun_cpu(trace_buf->buffer, cpu); |
Steven Rostedt | c8d7718 | 2009-04-29 18:03:45 -0400 | [diff] [blame] | 5856 | trace_seq_printf(s, "commit overrun: %ld\n", cnt); |
| 5857 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5858 | cnt = ring_buffer_bytes_cpu(trace_buf->buffer, cpu); |
Vaibhav Nagarnaik | c64e148 | 2011-08-16 14:46:16 -0700 | [diff] [blame] | 5859 | trace_seq_printf(s, "bytes: %ld\n", cnt); |
| 5860 | |
Yoshihiro YUNOMAE | 58e8eed | 2013-04-23 10:32:39 +0900 | [diff] [blame] | 5861 | if (trace_clocks[tr->clock_id].in_ns) { |
Yoshihiro YUNOMAE | 11043d8b | 2012-11-13 12:18:23 -0800 | [diff] [blame] | 5862 | /* local or global for trace_clock */ |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5863 | t = ns2usecs(ring_buffer_oldest_event_ts(trace_buf->buffer, cpu)); |
Yoshihiro YUNOMAE | 11043d8b | 2012-11-13 12:18:23 -0800 | [diff] [blame] | 5864 | usec_rem = do_div(t, USEC_PER_SEC); |
| 5865 | trace_seq_printf(s, "oldest event ts: %5llu.%06lu\n", |
| 5866 | t, usec_rem); |
Vaibhav Nagarnaik | c64e148 | 2011-08-16 14:46:16 -0700 | [diff] [blame] | 5867 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5868 | t = ns2usecs(ring_buffer_time_stamp(trace_buf->buffer, cpu)); |
Yoshihiro YUNOMAE | 11043d8b | 2012-11-13 12:18:23 -0800 | [diff] [blame] | 5869 | usec_rem = do_div(t, USEC_PER_SEC); |
| 5870 | trace_seq_printf(s, "now ts: %5llu.%06lu\n", t, usec_rem); |
| 5871 | } else { |
| 5872 | /* counter or tsc mode for trace_clock */ |
| 5873 | trace_seq_printf(s, "oldest event ts: %llu\n", |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5874 | ring_buffer_oldest_event_ts(trace_buf->buffer, cpu)); |
Yoshihiro YUNOMAE | 11043d8b | 2012-11-13 12:18:23 -0800 | [diff] [blame] | 5875 | |
| 5876 | trace_seq_printf(s, "now ts: %llu\n", |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5877 | ring_buffer_time_stamp(trace_buf->buffer, cpu)); |
Yoshihiro YUNOMAE | 11043d8b | 2012-11-13 12:18:23 -0800 | [diff] [blame] | 5878 | } |
Vaibhav Nagarnaik | c64e148 | 2011-08-16 14:46:16 -0700 | [diff] [blame] | 5879 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5880 | cnt = ring_buffer_dropped_events_cpu(trace_buf->buffer, cpu); |
Slava Pestov | 884bfe8 | 2011-07-15 14:23:58 -0700 | [diff] [blame] | 5881 | trace_seq_printf(s, "dropped events: %ld\n", cnt); |
| 5882 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 5883 | cnt = ring_buffer_read_events_cpu(trace_buf->buffer, cpu); |
Steven Rostedt (Red Hat) | ad96470 | 2013-01-29 17:45:49 -0500 | [diff] [blame] | 5884 | trace_seq_printf(s, "read events: %ld\n", cnt); |
| 5885 | |
Steven Rostedt (Red Hat) | 5ac48378 | 2014-11-14 15:49:41 -0500 | [diff] [blame] | 5886 | count = simple_read_from_buffer(ubuf, count, ppos, |
| 5887 | s->buffer, trace_seq_used(s)); |
Steven Rostedt | c8d7718 | 2009-04-29 18:03:45 -0400 | [diff] [blame] | 5888 | |
| 5889 | kfree(s); |
| 5890 | |
| 5891 | return count; |
| 5892 | } |
| 5893 | |
| 5894 | static const struct file_operations tracing_stats_fops = { |
Oleg Nesterov | 4d3435b | 2013-07-23 17:26:03 +0200 | [diff] [blame] | 5895 | .open = tracing_open_generic_tr, |
Steven Rostedt | c8d7718 | 2009-04-29 18:03:45 -0400 | [diff] [blame] | 5896 | .read = tracing_stats_read, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 5897 | .llseek = generic_file_llseek, |
Oleg Nesterov | 4d3435b | 2013-07-23 17:26:03 +0200 | [diff] [blame] | 5898 | .release = tracing_release_generic_tr, |
Steven Rostedt | c8d7718 | 2009-04-29 18:03:45 -0400 | [diff] [blame] | 5899 | }; |
| 5900 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5901 | #ifdef CONFIG_DYNAMIC_FTRACE |
| 5902 | |
Steven Rostedt | b807c3d | 2008-10-30 16:08:33 -0400 | [diff] [blame] | 5903 | int __weak ftrace_arch_read_dyn_info(char *buf, int size) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5904 | { |
Steven Rostedt | b807c3d | 2008-10-30 16:08:33 -0400 | [diff] [blame] | 5905 | return 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5906 | } |
| 5907 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5908 | static ssize_t |
Steven Rostedt | b807c3d | 2008-10-30 16:08:33 -0400 | [diff] [blame] | 5909 | tracing_read_dyn_info(struct file *filp, char __user *ubuf, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5910 | size_t cnt, loff_t *ppos) |
| 5911 | { |
Steven Rostedt | a26a2a2 | 2008-10-31 00:03:22 -0400 | [diff] [blame] | 5912 | static char ftrace_dyn_info_buffer[1024]; |
| 5913 | static DEFINE_MUTEX(dyn_info_mutex); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5914 | unsigned long *p = filp->private_data; |
Steven Rostedt | b807c3d | 2008-10-30 16:08:33 -0400 | [diff] [blame] | 5915 | char *buf = ftrace_dyn_info_buffer; |
Steven Rostedt | a26a2a2 | 2008-10-31 00:03:22 -0400 | [diff] [blame] | 5916 | int size = ARRAY_SIZE(ftrace_dyn_info_buffer); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5917 | int r; |
| 5918 | |
Steven Rostedt | b807c3d | 2008-10-30 16:08:33 -0400 | [diff] [blame] | 5919 | mutex_lock(&dyn_info_mutex); |
| 5920 | r = sprintf(buf, "%ld ", *p); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5921 | |
Steven Rostedt | a26a2a2 | 2008-10-31 00:03:22 -0400 | [diff] [blame] | 5922 | r += ftrace_arch_read_dyn_info(buf+r, (size-1)-r); |
Steven Rostedt | b807c3d | 2008-10-30 16:08:33 -0400 | [diff] [blame] | 5923 | buf[r++] = '\n'; |
| 5924 | |
| 5925 | r = simple_read_from_buffer(ubuf, cnt, ppos, buf, r); |
| 5926 | |
| 5927 | mutex_unlock(&dyn_info_mutex); |
| 5928 | |
| 5929 | return r; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5930 | } |
| 5931 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 5932 | static const struct file_operations tracing_dyn_info_fops = { |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 5933 | .open = tracing_open_generic, |
Steven Rostedt | b807c3d | 2008-10-30 16:08:33 -0400 | [diff] [blame] | 5934 | .read = tracing_read_dyn_info, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 5935 | .llseek = generic_file_llseek, |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5936 | }; |
Steven Rostedt (Red Hat) | 77fd5c1 | 2013-03-12 11:49:18 -0400 | [diff] [blame] | 5937 | #endif /* CONFIG_DYNAMIC_FTRACE */ |
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 | #if defined(CONFIG_TRACER_SNAPSHOT) && defined(CONFIG_DYNAMIC_FTRACE) |
| 5940 | static void |
| 5941 | ftrace_snapshot(unsigned long ip, unsigned long parent_ip, void **data) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5942 | { |
Steven Rostedt (Red Hat) | 77fd5c1 | 2013-03-12 11:49:18 -0400 | [diff] [blame] | 5943 | tracing_snapshot(); |
| 5944 | } |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 5945 | |
Steven Rostedt (Red Hat) | 77fd5c1 | 2013-03-12 11:49:18 -0400 | [diff] [blame] | 5946 | static void |
| 5947 | ftrace_count_snapshot(unsigned long ip, unsigned long parent_ip, void **data) |
| 5948 | { |
| 5949 | unsigned long *count = (long *)data; |
| 5950 | |
| 5951 | if (!*count) |
| 5952 | return; |
| 5953 | |
| 5954 | if (*count != -1) |
| 5955 | (*count)--; |
| 5956 | |
| 5957 | tracing_snapshot(); |
| 5958 | } |
| 5959 | |
| 5960 | static int |
| 5961 | ftrace_snapshot_print(struct seq_file *m, unsigned long ip, |
| 5962 | struct ftrace_probe_ops *ops, void *data) |
| 5963 | { |
| 5964 | long count = (long)data; |
| 5965 | |
| 5966 | seq_printf(m, "%ps:", (void *)ip); |
| 5967 | |
Rasmus Villemoes | fa6f0cc | 2014-11-08 21:42:10 +0100 | [diff] [blame] | 5968 | seq_puts(m, "snapshot"); |
Steven Rostedt (Red Hat) | 77fd5c1 | 2013-03-12 11:49:18 -0400 | [diff] [blame] | 5969 | |
| 5970 | if (count == -1) |
Rasmus Villemoes | fa6f0cc | 2014-11-08 21:42:10 +0100 | [diff] [blame] | 5971 | seq_puts(m, ":unlimited\n"); |
Steven Rostedt (Red Hat) | 77fd5c1 | 2013-03-12 11:49:18 -0400 | [diff] [blame] | 5972 | else |
| 5973 | seq_printf(m, ":count=%ld\n", count); |
| 5974 | |
| 5975 | return 0; |
| 5976 | } |
| 5977 | |
| 5978 | static struct ftrace_probe_ops snapshot_probe_ops = { |
| 5979 | .func = ftrace_snapshot, |
| 5980 | .print = ftrace_snapshot_print, |
| 5981 | }; |
| 5982 | |
| 5983 | static struct ftrace_probe_ops snapshot_count_probe_ops = { |
| 5984 | .func = ftrace_count_snapshot, |
| 5985 | .print = ftrace_snapshot_print, |
| 5986 | }; |
| 5987 | |
| 5988 | static int |
| 5989 | ftrace_trace_snapshot_callback(struct ftrace_hash *hash, |
| 5990 | char *glob, char *cmd, char *param, int enable) |
| 5991 | { |
| 5992 | struct ftrace_probe_ops *ops; |
| 5993 | void *count = (void *)-1; |
| 5994 | char *number; |
| 5995 | int ret; |
| 5996 | |
| 5997 | /* hash funcs only work with set_ftrace_filter */ |
| 5998 | if (!enable) |
| 5999 | return -EINVAL; |
| 6000 | |
| 6001 | ops = param ? &snapshot_count_probe_ops : &snapshot_probe_ops; |
| 6002 | |
| 6003 | if (glob[0] == '!') { |
| 6004 | unregister_ftrace_function_probe_func(glob+1, ops); |
| 6005 | return 0; |
| 6006 | } |
| 6007 | |
| 6008 | if (!param) |
| 6009 | goto out_reg; |
| 6010 | |
| 6011 | number = strsep(¶m, ":"); |
| 6012 | |
| 6013 | if (!strlen(number)) |
| 6014 | goto out_reg; |
| 6015 | |
| 6016 | /* |
| 6017 | * We use the callback data field (which is a pointer) |
| 6018 | * as our counter. |
| 6019 | */ |
| 6020 | ret = kstrtoul(number, 0, (unsigned long *)&count); |
| 6021 | if (ret) |
| 6022 | return ret; |
| 6023 | |
| 6024 | out_reg: |
| 6025 | ret = register_ftrace_function_probe(glob, ops, count); |
| 6026 | |
| 6027 | if (ret >= 0) |
| 6028 | alloc_snapshot(&global_trace); |
| 6029 | |
| 6030 | return ret < 0 ? ret : 0; |
| 6031 | } |
| 6032 | |
| 6033 | static struct ftrace_func_command ftrace_snapshot_cmd = { |
| 6034 | .name = "snapshot", |
| 6035 | .func = ftrace_trace_snapshot_callback, |
| 6036 | }; |
| 6037 | |
Tom Zanussi | 38de93a | 2013-10-24 08:34:18 -0500 | [diff] [blame] | 6038 | static __init int register_snapshot_cmd(void) |
Steven Rostedt (Red Hat) | 77fd5c1 | 2013-03-12 11:49:18 -0400 | [diff] [blame] | 6039 | { |
| 6040 | return register_ftrace_command(&ftrace_snapshot_cmd); |
| 6041 | } |
| 6042 | #else |
Tom Zanussi | 38de93a | 2013-10-24 08:34:18 -0500 | [diff] [blame] | 6043 | static inline __init int register_snapshot_cmd(void) { return 0; } |
Steven Rostedt (Red Hat) | 77fd5c1 | 2013-03-12 11:49:18 -0400 | [diff] [blame] | 6044 | #endif /* defined(CONFIG_TRACER_SNAPSHOT) && defined(CONFIG_DYNAMIC_FTRACE) */ |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 6045 | |
Steven Rostedt (Red Hat) | 7eeafbc | 2015-01-26 21:00:48 -0500 | [diff] [blame] | 6046 | static struct dentry *tracing_get_dentry(struct trace_array *tr) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 6047 | { |
Steven Rostedt (Red Hat) | 8434dc9 | 2015-01-20 12:13:40 -0500 | [diff] [blame] | 6048 | if (WARN_ON(!tr->dir)) |
| 6049 | return ERR_PTR(-ENODEV); |
| 6050 | |
| 6051 | /* Top directory uses NULL as the parent */ |
| 6052 | if (tr->flags & TRACE_ARRAY_FL_GLOBAL) |
| 6053 | return NULL; |
| 6054 | |
| 6055 | /* All sub buffers have a descriptor */ |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6056 | return tr->dir; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 6057 | } |
| 6058 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6059 | static struct dentry *tracing_dentry_percpu(struct trace_array *tr, int cpu) |
| 6060 | { |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 6061 | struct dentry *d_tracer; |
| 6062 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6063 | if (tr->percpu_dir) |
| 6064 | return tr->percpu_dir; |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 6065 | |
Steven Rostedt (Red Hat) | 7eeafbc | 2015-01-26 21:00:48 -0500 | [diff] [blame] | 6066 | d_tracer = tracing_get_dentry(tr); |
Steven Rostedt (Red Hat) | 14a5ae4 | 2015-01-20 11:14:16 -0500 | [diff] [blame] | 6067 | if (IS_ERR(d_tracer)) |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 6068 | return NULL; |
| 6069 | |
Steven Rostedt (Red Hat) | 8434dc9 | 2015-01-20 12:13:40 -0500 | [diff] [blame] | 6070 | tr->percpu_dir = tracefs_create_dir("per_cpu", d_tracer); |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 6071 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6072 | WARN_ONCE(!tr->percpu_dir, |
Steven Rostedt (Red Hat) | 8434dc9 | 2015-01-20 12:13:40 -0500 | [diff] [blame] | 6073 | "Could not create tracefs directory 'per_cpu/%d'\n", cpu); |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 6074 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6075 | return tr->percpu_dir; |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 6076 | } |
| 6077 | |
Oleg Nesterov | 649e9c70 | 2013-07-23 17:25:54 +0200 | [diff] [blame] | 6078 | static struct dentry * |
| 6079 | trace_create_cpu_file(const char *name, umode_t mode, struct dentry *parent, |
| 6080 | void *data, long cpu, const struct file_operations *fops) |
| 6081 | { |
| 6082 | struct dentry *ret = trace_create_file(name, mode, parent, data, fops); |
| 6083 | |
| 6084 | if (ret) /* See tracing_get_cpu() */ |
David Howells | 7682c91 | 2015-03-17 22:26:16 +0000 | [diff] [blame] | 6085 | d_inode(ret)->i_cdev = (void *)(cpu + 1); |
Oleg Nesterov | 649e9c70 | 2013-07-23 17:25:54 +0200 | [diff] [blame] | 6086 | return ret; |
| 6087 | } |
| 6088 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6089 | static void |
Steven Rostedt (Red Hat) | 8434dc9 | 2015-01-20 12:13:40 -0500 | [diff] [blame] | 6090 | tracing_init_tracefs_percpu(struct trace_array *tr, long cpu) |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 6091 | { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6092 | struct dentry *d_percpu = tracing_dentry_percpu(tr, cpu); |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 6093 | struct dentry *d_cpu; |
Steven Rostedt | dd49a38 | 2010-10-20 21:51:26 -0400 | [diff] [blame] | 6094 | char cpu_dir[30]; /* 30 characters should be more than enough */ |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 6095 | |
Namhyung Kim | 0a3d7ce | 2012-04-23 10:11:57 +0900 | [diff] [blame] | 6096 | if (!d_percpu) |
| 6097 | return; |
| 6098 | |
Steven Rostedt | dd49a38 | 2010-10-20 21:51:26 -0400 | [diff] [blame] | 6099 | snprintf(cpu_dir, 30, "cpu%ld", cpu); |
Steven Rostedt (Red Hat) | 8434dc9 | 2015-01-20 12:13:40 -0500 | [diff] [blame] | 6100 | d_cpu = tracefs_create_dir(cpu_dir, d_percpu); |
Frederic Weisbecker | 8656e7a | 2009-02-26 00:41:38 +0100 | [diff] [blame] | 6101 | if (!d_cpu) { |
Steven Rostedt (Red Hat) | 8434dc9 | 2015-01-20 12:13:40 -0500 | [diff] [blame] | 6102 | pr_warning("Could not create tracefs '%s' entry\n", cpu_dir); |
Frederic Weisbecker | 8656e7a | 2009-02-26 00:41:38 +0100 | [diff] [blame] | 6103 | return; |
| 6104 | } |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 6105 | |
Frederic Weisbecker | 8656e7a | 2009-02-26 00:41:38 +0100 | [diff] [blame] | 6106 | /* per cpu trace_pipe */ |
Oleg Nesterov | 649e9c70 | 2013-07-23 17:25:54 +0200 | [diff] [blame] | 6107 | trace_create_cpu_file("trace_pipe", 0444, d_cpu, |
Oleg Nesterov | 1554420 | 2013-07-23 17:25:57 +0200 | [diff] [blame] | 6108 | tr, cpu, &tracing_pipe_fops); |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 6109 | |
| 6110 | /* per cpu trace */ |
Oleg Nesterov | 649e9c70 | 2013-07-23 17:25:54 +0200 | [diff] [blame] | 6111 | trace_create_cpu_file("trace", 0644, d_cpu, |
Oleg Nesterov | 6484c71 | 2013-07-23 17:26:10 +0200 | [diff] [blame] | 6112 | tr, cpu, &tracing_fops); |
Steven Rostedt | 7f96f93 | 2009-03-13 00:37:42 -0400 | [diff] [blame] | 6113 | |
Oleg Nesterov | 649e9c70 | 2013-07-23 17:25:54 +0200 | [diff] [blame] | 6114 | trace_create_cpu_file("trace_pipe_raw", 0444, d_cpu, |
Oleg Nesterov | 46ef2be | 2013-07-23 17:26:00 +0200 | [diff] [blame] | 6115 | tr, cpu, &tracing_buffers_fops); |
Steven Rostedt | c8d7718 | 2009-04-29 18:03:45 -0400 | [diff] [blame] | 6116 | |
Oleg Nesterov | 649e9c70 | 2013-07-23 17:25:54 +0200 | [diff] [blame] | 6117 | trace_create_cpu_file("stats", 0444, d_cpu, |
Oleg Nesterov | 4d3435b | 2013-07-23 17:26:03 +0200 | [diff] [blame] | 6118 | tr, cpu, &tracing_stats_fops); |
Vaibhav Nagarnaik | 438ced1 | 2012-02-02 12:00:41 -0800 | [diff] [blame] | 6119 | |
Oleg Nesterov | 649e9c70 | 2013-07-23 17:25:54 +0200 | [diff] [blame] | 6120 | trace_create_cpu_file("buffer_size_kb", 0444, d_cpu, |
Oleg Nesterov | 0bc392e | 2013-07-23 17:26:06 +0200 | [diff] [blame] | 6121 | tr, cpu, &tracing_entries_fops); |
Steven Rostedt (Red Hat) | f1affca | 2013-03-05 14:35:11 -0500 | [diff] [blame] | 6122 | |
| 6123 | #ifdef CONFIG_TRACER_SNAPSHOT |
Oleg Nesterov | 649e9c70 | 2013-07-23 17:25:54 +0200 | [diff] [blame] | 6124 | trace_create_cpu_file("snapshot", 0644, d_cpu, |
Oleg Nesterov | 6484c71 | 2013-07-23 17:26:10 +0200 | [diff] [blame] | 6125 | tr, cpu, &snapshot_fops); |
Steven Rostedt (Red Hat) | 6de58e6 | 2013-03-05 16:18:16 -0500 | [diff] [blame] | 6126 | |
Oleg Nesterov | 649e9c70 | 2013-07-23 17:25:54 +0200 | [diff] [blame] | 6127 | trace_create_cpu_file("snapshot_raw", 0444, d_cpu, |
Oleg Nesterov | 46ef2be | 2013-07-23 17:26:00 +0200 | [diff] [blame] | 6128 | tr, cpu, &snapshot_raw_fops); |
Steven Rostedt (Red Hat) | f1affca | 2013-03-05 14:35:11 -0500 | [diff] [blame] | 6129 | #endif |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 6130 | } |
| 6131 | |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 6132 | #ifdef CONFIG_FTRACE_SELFTEST |
| 6133 | /* Let selftest have access to static functions in this file */ |
| 6134 | #include "trace_selftest.c" |
| 6135 | #endif |
| 6136 | |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 6137 | static ssize_t |
| 6138 | trace_options_read(struct file *filp, char __user *ubuf, size_t cnt, |
| 6139 | loff_t *ppos) |
| 6140 | { |
| 6141 | struct trace_option_dentry *topt = filp->private_data; |
| 6142 | char *buf; |
| 6143 | |
| 6144 | if (topt->flags->val & topt->opt->bit) |
| 6145 | buf = "1\n"; |
| 6146 | else |
| 6147 | buf = "0\n"; |
| 6148 | |
| 6149 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, 2); |
| 6150 | } |
| 6151 | |
| 6152 | static ssize_t |
| 6153 | trace_options_write(struct file *filp, const char __user *ubuf, size_t cnt, |
| 6154 | loff_t *ppos) |
| 6155 | { |
| 6156 | struct trace_option_dentry *topt = filp->private_data; |
| 6157 | unsigned long val; |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 6158 | int ret; |
| 6159 | |
Peter Huewe | 22fe9b5 | 2011-06-07 21:58:27 +0200 | [diff] [blame] | 6160 | ret = kstrtoul_from_user(ubuf, cnt, 10, &val); |
| 6161 | if (ret) |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 6162 | return ret; |
| 6163 | |
Li Zefan | 8d18eaa | 2009-12-08 11:17:06 +0800 | [diff] [blame] | 6164 | if (val != 0 && val != 1) |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 6165 | return -EINVAL; |
Li Zefan | 8d18eaa | 2009-12-08 11:17:06 +0800 | [diff] [blame] | 6166 | |
| 6167 | if (!!(topt->flags->val & topt->opt->bit) != val) { |
| 6168 | mutex_lock(&trace_types_lock); |
Steven Rostedt (Red Hat) | 8c1a49a | 2014-01-10 11:13:54 -0500 | [diff] [blame] | 6169 | ret = __set_tracer_option(topt->tr, topt->flags, |
Steven Rostedt | c757bea | 2009-12-21 22:35:16 -0500 | [diff] [blame] | 6170 | topt->opt, !val); |
Li Zefan | 8d18eaa | 2009-12-08 11:17:06 +0800 | [diff] [blame] | 6171 | mutex_unlock(&trace_types_lock); |
| 6172 | if (ret) |
| 6173 | return ret; |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 6174 | } |
| 6175 | |
| 6176 | *ppos += cnt; |
| 6177 | |
| 6178 | return cnt; |
| 6179 | } |
| 6180 | |
| 6181 | |
| 6182 | static const struct file_operations trace_options_fops = { |
| 6183 | .open = tracing_open_generic, |
| 6184 | .read = trace_options_read, |
| 6185 | .write = trace_options_write, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 6186 | .llseek = generic_file_llseek, |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 6187 | }; |
| 6188 | |
Steven Rostedt (Red Hat) | 9a38a88 | 2015-09-30 11:11:15 -0400 | [diff] [blame] | 6189 | /* |
| 6190 | * In order to pass in both the trace_array descriptor as well as the index |
| 6191 | * to the flag that the trace option file represents, the trace_array |
| 6192 | * has a character array of trace_flags_index[], which holds the index |
| 6193 | * of the bit for the flag it represents. index[0] == 0, index[1] == 1, etc. |
| 6194 | * The address of this character array is passed to the flag option file |
| 6195 | * read/write callbacks. |
| 6196 | * |
| 6197 | * In order to extract both the index and the trace_array descriptor, |
| 6198 | * get_tr_index() uses the following algorithm. |
| 6199 | * |
| 6200 | * idx = *ptr; |
| 6201 | * |
| 6202 | * As the pointer itself contains the address of the index (remember |
| 6203 | * index[1] == 1). |
| 6204 | * |
| 6205 | * Then to get the trace_array descriptor, by subtracting that index |
| 6206 | * from the ptr, we get to the start of the index itself. |
| 6207 | * |
| 6208 | * ptr - idx == &index[0] |
| 6209 | * |
| 6210 | * Then a simple container_of() from that pointer gets us to the |
| 6211 | * trace_array descriptor. |
| 6212 | */ |
| 6213 | static void get_tr_index(void *data, struct trace_array **ptr, |
| 6214 | unsigned int *pindex) |
| 6215 | { |
| 6216 | *pindex = *(unsigned char *)data; |
| 6217 | |
| 6218 | *ptr = container_of(data - *pindex, struct trace_array, |
| 6219 | trace_flags_index); |
| 6220 | } |
| 6221 | |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 6222 | static ssize_t |
| 6223 | trace_options_core_read(struct file *filp, char __user *ubuf, size_t cnt, |
| 6224 | loff_t *ppos) |
| 6225 | { |
Steven Rostedt (Red Hat) | 9a38a88 | 2015-09-30 11:11:15 -0400 | [diff] [blame] | 6226 | void *tr_index = filp->private_data; |
| 6227 | struct trace_array *tr; |
| 6228 | unsigned int index; |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 6229 | char *buf; |
| 6230 | |
Steven Rostedt (Red Hat) | 9a38a88 | 2015-09-30 11:11:15 -0400 | [diff] [blame] | 6231 | get_tr_index(tr_index, &tr, &index); |
| 6232 | |
| 6233 | if (tr->trace_flags & (1 << index)) |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 6234 | buf = "1\n"; |
| 6235 | else |
| 6236 | buf = "0\n"; |
| 6237 | |
| 6238 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, 2); |
| 6239 | } |
| 6240 | |
| 6241 | static ssize_t |
| 6242 | trace_options_core_write(struct file *filp, const char __user *ubuf, size_t cnt, |
| 6243 | loff_t *ppos) |
| 6244 | { |
Steven Rostedt (Red Hat) | 9a38a88 | 2015-09-30 11:11:15 -0400 | [diff] [blame] | 6245 | void *tr_index = filp->private_data; |
| 6246 | struct trace_array *tr; |
| 6247 | unsigned int index; |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 6248 | unsigned long val; |
| 6249 | int ret; |
| 6250 | |
Steven Rostedt (Red Hat) | 9a38a88 | 2015-09-30 11:11:15 -0400 | [diff] [blame] | 6251 | get_tr_index(tr_index, &tr, &index); |
| 6252 | |
Peter Huewe | 22fe9b5 | 2011-06-07 21:58:27 +0200 | [diff] [blame] | 6253 | ret = kstrtoul_from_user(ubuf, cnt, 10, &val); |
| 6254 | if (ret) |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 6255 | return ret; |
| 6256 | |
Zhaolei | f2d84b6 | 2009-08-07 18:55:48 +0800 | [diff] [blame] | 6257 | if (val != 0 && val != 1) |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 6258 | return -EINVAL; |
Steven Rostedt (Red Hat) | 69d34da | 2013-03-14 13:50:56 -0400 | [diff] [blame] | 6259 | |
| 6260 | mutex_lock(&trace_types_lock); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6261 | ret = set_tracer_flag(tr, 1 << index, val); |
Steven Rostedt (Red Hat) | 69d34da | 2013-03-14 13:50:56 -0400 | [diff] [blame] | 6262 | mutex_unlock(&trace_types_lock); |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 6263 | |
Steven Rostedt (Red Hat) | 613f04a | 2013-03-14 15:03:53 -0400 | [diff] [blame] | 6264 | if (ret < 0) |
| 6265 | return ret; |
| 6266 | |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 6267 | *ppos += cnt; |
| 6268 | |
| 6269 | return cnt; |
| 6270 | } |
| 6271 | |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 6272 | static const struct file_operations trace_options_core_fops = { |
| 6273 | .open = tracing_open_generic, |
| 6274 | .read = trace_options_core_read, |
| 6275 | .write = trace_options_core_write, |
Arnd Bergmann | b444786 | 2010-07-07 23:40:11 +0200 | [diff] [blame] | 6276 | .llseek = generic_file_llseek, |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 6277 | }; |
| 6278 | |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 6279 | struct dentry *trace_create_file(const char *name, |
Al Viro | f4ae40a6 | 2011-07-24 04:33:43 -0400 | [diff] [blame] | 6280 | umode_t mode, |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 6281 | struct dentry *parent, |
| 6282 | void *data, |
| 6283 | const struct file_operations *fops) |
| 6284 | { |
| 6285 | struct dentry *ret; |
| 6286 | |
Steven Rostedt (Red Hat) | 8434dc9 | 2015-01-20 12:13:40 -0500 | [diff] [blame] | 6287 | ret = tracefs_create_file(name, mode, parent, data, fops); |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 6288 | if (!ret) |
Steven Rostedt (Red Hat) | 8434dc9 | 2015-01-20 12:13:40 -0500 | [diff] [blame] | 6289 | pr_warning("Could not create tracefs '%s' entry\n", name); |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 6290 | |
| 6291 | return ret; |
| 6292 | } |
| 6293 | |
| 6294 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6295 | static struct dentry *trace_options_init_dentry(struct trace_array *tr) |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 6296 | { |
| 6297 | struct dentry *d_tracer; |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 6298 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6299 | if (tr->options) |
| 6300 | return tr->options; |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 6301 | |
Steven Rostedt (Red Hat) | 7eeafbc | 2015-01-26 21:00:48 -0500 | [diff] [blame] | 6302 | d_tracer = tracing_get_dentry(tr); |
Steven Rostedt (Red Hat) | 14a5ae4 | 2015-01-20 11:14:16 -0500 | [diff] [blame] | 6303 | if (IS_ERR(d_tracer)) |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 6304 | return NULL; |
| 6305 | |
Steven Rostedt (Red Hat) | 8434dc9 | 2015-01-20 12:13:40 -0500 | [diff] [blame] | 6306 | tr->options = tracefs_create_dir("options", d_tracer); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6307 | if (!tr->options) { |
Steven Rostedt (Red Hat) | 8434dc9 | 2015-01-20 12:13:40 -0500 | [diff] [blame] | 6308 | pr_warning("Could not create tracefs directory 'options'\n"); |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 6309 | return NULL; |
| 6310 | } |
| 6311 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6312 | return tr->options; |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 6313 | } |
| 6314 | |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 6315 | static void |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6316 | create_trace_option_file(struct trace_array *tr, |
| 6317 | struct trace_option_dentry *topt, |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 6318 | struct tracer_flags *flags, |
| 6319 | struct tracer_opt *opt) |
| 6320 | { |
| 6321 | struct dentry *t_options; |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 6322 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6323 | t_options = trace_options_init_dentry(tr); |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 6324 | if (!t_options) |
| 6325 | return; |
| 6326 | |
| 6327 | topt->flags = flags; |
| 6328 | topt->opt = opt; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6329 | topt->tr = tr; |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 6330 | |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 6331 | topt->entry = trace_create_file(opt->name, 0644, t_options, topt, |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 6332 | &trace_options_fops); |
| 6333 | |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 6334 | } |
| 6335 | |
Steven Rostedt (Red Hat) | 37aea98 | 2015-09-30 14:27:31 -0400 | [diff] [blame] | 6336 | static void |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6337 | create_trace_option_files(struct trace_array *tr, struct tracer *tracer) |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 6338 | { |
| 6339 | struct trace_option_dentry *topts; |
Steven Rostedt (Red Hat) | 37aea98 | 2015-09-30 14:27:31 -0400 | [diff] [blame] | 6340 | struct trace_options *tr_topts; |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 6341 | struct tracer_flags *flags; |
| 6342 | struct tracer_opt *opts; |
| 6343 | int cnt; |
Steven Rostedt (Red Hat) | 37aea98 | 2015-09-30 14:27:31 -0400 | [diff] [blame] | 6344 | int i; |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 6345 | |
| 6346 | if (!tracer) |
Steven Rostedt (Red Hat) | 37aea98 | 2015-09-30 14:27:31 -0400 | [diff] [blame] | 6347 | return; |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 6348 | |
| 6349 | flags = tracer->flags; |
| 6350 | |
| 6351 | if (!flags || !flags->opts) |
Steven Rostedt (Red Hat) | 37aea98 | 2015-09-30 14:27:31 -0400 | [diff] [blame] | 6352 | return; |
| 6353 | |
| 6354 | /* |
| 6355 | * If this is an instance, only create flags for tracers |
| 6356 | * the instance may have. |
| 6357 | */ |
| 6358 | if (!trace_ok_for_array(tracer, tr)) |
| 6359 | return; |
| 6360 | |
| 6361 | for (i = 0; i < tr->nr_topts; i++) { |
| 6362 | /* |
| 6363 | * Check if these flags have already been added. |
| 6364 | * Some tracers share flags. |
| 6365 | */ |
| 6366 | if (tr->topts[i].tracer->flags == tracer->flags) |
| 6367 | return; |
| 6368 | } |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 6369 | |
| 6370 | opts = flags->opts; |
| 6371 | |
| 6372 | for (cnt = 0; opts[cnt].name; cnt++) |
| 6373 | ; |
| 6374 | |
Steven Rostedt | 0cfe824 | 2009-02-27 10:51:10 -0500 | [diff] [blame] | 6375 | topts = kcalloc(cnt + 1, sizeof(*topts), GFP_KERNEL); |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 6376 | if (!topts) |
Steven Rostedt (Red Hat) | 37aea98 | 2015-09-30 14:27:31 -0400 | [diff] [blame] | 6377 | return; |
| 6378 | |
| 6379 | tr_topts = krealloc(tr->topts, sizeof(*tr->topts) * (tr->nr_topts + 1), |
| 6380 | GFP_KERNEL); |
| 6381 | if (!tr_topts) { |
| 6382 | kfree(topts); |
| 6383 | return; |
| 6384 | } |
| 6385 | |
| 6386 | tr->topts = tr_topts; |
| 6387 | tr->topts[tr->nr_topts].tracer = tracer; |
| 6388 | tr->topts[tr->nr_topts].topts = topts; |
| 6389 | tr->nr_topts++; |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 6390 | |
Steven Rostedt (Red Hat) | 41d9c0b | 2015-09-29 17:31:55 -0400 | [diff] [blame] | 6391 | for (cnt = 0; opts[cnt].name; cnt++) { |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6392 | create_trace_option_file(tr, &topts[cnt], flags, |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 6393 | &opts[cnt]); |
Steven Rostedt (Red Hat) | 41d9c0b | 2015-09-29 17:31:55 -0400 | [diff] [blame] | 6394 | WARN_ONCE(topts[cnt].entry == NULL, |
| 6395 | "Failed to create trace option: %s", |
| 6396 | opts[cnt].name); |
| 6397 | } |
Steven Rostedt | 577b785 | 2009-02-26 23:43:05 -0500 | [diff] [blame] | 6398 | } |
| 6399 | |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 6400 | static struct dentry * |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6401 | create_trace_option_core_file(struct trace_array *tr, |
| 6402 | const char *option, long index) |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 6403 | { |
| 6404 | struct dentry *t_options; |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 6405 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6406 | t_options = trace_options_init_dentry(tr); |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 6407 | if (!t_options) |
| 6408 | return NULL; |
| 6409 | |
Steven Rostedt (Red Hat) | 9a38a88 | 2015-09-30 11:11:15 -0400 | [diff] [blame] | 6410 | return trace_create_file(option, 0644, t_options, |
| 6411 | (void *)&tr->trace_flags_index[index], |
| 6412 | &trace_options_core_fops); |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 6413 | } |
| 6414 | |
Steven Rostedt (Red Hat) | 1627014 | 2015-09-30 12:30:06 -0400 | [diff] [blame] | 6415 | static void create_trace_options_dir(struct trace_array *tr) |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 6416 | { |
| 6417 | struct dentry *t_options; |
Steven Rostedt (Red Hat) | 1627014 | 2015-09-30 12:30:06 -0400 | [diff] [blame] | 6418 | bool top_level = tr == &global_trace; |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 6419 | int i; |
| 6420 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6421 | t_options = trace_options_init_dentry(tr); |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 6422 | if (!t_options) |
| 6423 | return; |
| 6424 | |
Steven Rostedt (Red Hat) | 1627014 | 2015-09-30 12:30:06 -0400 | [diff] [blame] | 6425 | for (i = 0; trace_options[i]; i++) { |
| 6426 | if (top_level || |
| 6427 | !((1 << i) & TOP_LEVEL_TRACE_FLAGS)) |
| 6428 | create_trace_option_core_file(tr, trace_options[i], i); |
| 6429 | } |
Steven Rostedt | a825907 | 2009-02-26 22:19:12 -0500 | [diff] [blame] | 6430 | } |
| 6431 | |
Steven Rostedt | 499e547 | 2012-02-22 15:50:28 -0500 | [diff] [blame] | 6432 | static ssize_t |
| 6433 | rb_simple_read(struct file *filp, char __user *ubuf, |
| 6434 | size_t cnt, loff_t *ppos) |
| 6435 | { |
Steven Rostedt | 348f0fc | 2012-04-16 15:41:28 -0400 | [diff] [blame] | 6436 | struct trace_array *tr = filp->private_data; |
Steven Rostedt | 499e547 | 2012-02-22 15:50:28 -0500 | [diff] [blame] | 6437 | char buf[64]; |
| 6438 | int r; |
| 6439 | |
Steven Rostedt (Red Hat) | 10246fa | 2013-07-01 15:58:24 -0400 | [diff] [blame] | 6440 | r = tracer_tracing_is_on(tr); |
Steven Rostedt | 499e547 | 2012-02-22 15:50:28 -0500 | [diff] [blame] | 6441 | r = sprintf(buf, "%d\n", r); |
| 6442 | |
| 6443 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, r); |
| 6444 | } |
| 6445 | |
| 6446 | static ssize_t |
| 6447 | rb_simple_write(struct file *filp, const char __user *ubuf, |
| 6448 | size_t cnt, loff_t *ppos) |
| 6449 | { |
Steven Rostedt | 348f0fc | 2012-04-16 15:41:28 -0400 | [diff] [blame] | 6450 | struct trace_array *tr = filp->private_data; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 6451 | struct ring_buffer *buffer = tr->trace_buffer.buffer; |
Steven Rostedt | 499e547 | 2012-02-22 15:50:28 -0500 | [diff] [blame] | 6452 | unsigned long val; |
| 6453 | int ret; |
| 6454 | |
| 6455 | ret = kstrtoul_from_user(ubuf, cnt, 10, &val); |
| 6456 | if (ret) |
| 6457 | return ret; |
| 6458 | |
| 6459 | if (buffer) { |
Steven Rostedt | 2df8f8a | 2013-01-11 16:14:10 -0500 | [diff] [blame] | 6460 | mutex_lock(&trace_types_lock); |
| 6461 | if (val) { |
Steven Rostedt (Red Hat) | 10246fa | 2013-07-01 15:58:24 -0400 | [diff] [blame] | 6462 | tracer_tracing_on(tr); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6463 | if (tr->current_trace->start) |
| 6464 | tr->current_trace->start(tr); |
Steven Rostedt | 2df8f8a | 2013-01-11 16:14:10 -0500 | [diff] [blame] | 6465 | } else { |
Steven Rostedt (Red Hat) | 10246fa | 2013-07-01 15:58:24 -0400 | [diff] [blame] | 6466 | tracer_tracing_off(tr); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6467 | if (tr->current_trace->stop) |
| 6468 | tr->current_trace->stop(tr); |
Steven Rostedt | 2df8f8a | 2013-01-11 16:14:10 -0500 | [diff] [blame] | 6469 | } |
| 6470 | mutex_unlock(&trace_types_lock); |
Steven Rostedt | 499e547 | 2012-02-22 15:50:28 -0500 | [diff] [blame] | 6471 | } |
| 6472 | |
| 6473 | (*ppos)++; |
| 6474 | |
| 6475 | return cnt; |
| 6476 | } |
| 6477 | |
| 6478 | static const struct file_operations rb_simple_fops = { |
Steven Rostedt (Red Hat) | 7b85af6 | 2013-07-01 23:34:22 -0400 | [diff] [blame] | 6479 | .open = tracing_open_generic_tr, |
Steven Rostedt | 499e547 | 2012-02-22 15:50:28 -0500 | [diff] [blame] | 6480 | .read = rb_simple_read, |
| 6481 | .write = rb_simple_write, |
Steven Rostedt (Red Hat) | 7b85af6 | 2013-07-01 23:34:22 -0400 | [diff] [blame] | 6482 | .release = tracing_release_generic_tr, |
Steven Rostedt | 499e547 | 2012-02-22 15:50:28 -0500 | [diff] [blame] | 6483 | .llseek = default_llseek, |
| 6484 | }; |
| 6485 | |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 6486 | struct dentry *trace_instance_dir; |
| 6487 | |
| 6488 | static void |
Steven Rostedt (Red Hat) | 8434dc9 | 2015-01-20 12:13:40 -0500 | [diff] [blame] | 6489 | init_tracer_tracefs(struct trace_array *tr, struct dentry *d_tracer); |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 6490 | |
Steven Rostedt (Red Hat) | 55034cd | 2013-03-07 22:48:09 -0500 | [diff] [blame] | 6491 | static int |
| 6492 | 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] | 6493 | { |
| 6494 | enum ring_buffer_flags rb_flags; |
Steven Rostedt (Red Hat) | 737223f | 2013-03-05 21:13:47 -0500 | [diff] [blame] | 6495 | |
Steven Rostedt (Red Hat) | 983f938 | 2015-09-30 09:42:05 -0400 | [diff] [blame] | 6496 | rb_flags = tr->trace_flags & TRACE_ITER_OVERWRITE ? RB_FL_OVERWRITE : 0; |
Steven Rostedt (Red Hat) | 737223f | 2013-03-05 21:13:47 -0500 | [diff] [blame] | 6497 | |
Steven Rostedt (Red Hat) | dced341 | 2014-01-14 10:19:46 -0500 | [diff] [blame] | 6498 | buf->tr = tr; |
| 6499 | |
Steven Rostedt (Red Hat) | 55034cd | 2013-03-07 22:48:09 -0500 | [diff] [blame] | 6500 | buf->buffer = ring_buffer_alloc(size, rb_flags); |
| 6501 | if (!buf->buffer) |
| 6502 | return -ENOMEM; |
Steven Rostedt (Red Hat) | 737223f | 2013-03-05 21:13:47 -0500 | [diff] [blame] | 6503 | |
Steven Rostedt (Red Hat) | 55034cd | 2013-03-07 22:48:09 -0500 | [diff] [blame] | 6504 | buf->data = alloc_percpu(struct trace_array_cpu); |
| 6505 | if (!buf->data) { |
| 6506 | ring_buffer_free(buf->buffer); |
| 6507 | return -ENOMEM; |
| 6508 | } |
Steven Rostedt (Red Hat) | 737223f | 2013-03-05 21:13:47 -0500 | [diff] [blame] | 6509 | |
Steven Rostedt (Red Hat) | 737223f | 2013-03-05 21:13:47 -0500 | [diff] [blame] | 6510 | /* Allocate the first page for all buffers */ |
| 6511 | set_buffer_entries(&tr->trace_buffer, |
| 6512 | ring_buffer_size(tr->trace_buffer.buffer, 0)); |
| 6513 | |
Steven Rostedt (Red Hat) | 55034cd | 2013-03-07 22:48:09 -0500 | [diff] [blame] | 6514 | return 0; |
| 6515 | } |
| 6516 | |
| 6517 | static int allocate_trace_buffers(struct trace_array *tr, int size) |
| 6518 | { |
| 6519 | int ret; |
| 6520 | |
| 6521 | ret = allocate_trace_buffer(tr, &tr->trace_buffer, size); |
| 6522 | if (ret) |
| 6523 | return ret; |
| 6524 | |
Steven Rostedt (Red Hat) | 737223f | 2013-03-05 21:13:47 -0500 | [diff] [blame] | 6525 | #ifdef CONFIG_TRACER_MAX_TRACE |
Steven Rostedt (Red Hat) | 55034cd | 2013-03-07 22:48:09 -0500 | [diff] [blame] | 6526 | ret = allocate_trace_buffer(tr, &tr->max_buffer, |
| 6527 | allocate_snapshot ? size : 1); |
| 6528 | if (WARN_ON(ret)) { |
| 6529 | ring_buffer_free(tr->trace_buffer.buffer); |
| 6530 | free_percpu(tr->trace_buffer.data); |
| 6531 | return -ENOMEM; |
| 6532 | } |
| 6533 | tr->allocated_snapshot = allocate_snapshot; |
Steven Rostedt (Red Hat) | 737223f | 2013-03-05 21:13:47 -0500 | [diff] [blame] | 6534 | |
Steven Rostedt (Red Hat) | 55034cd | 2013-03-07 22:48:09 -0500 | [diff] [blame] | 6535 | /* |
| 6536 | * Only the top level trace array gets its snapshot allocated |
| 6537 | * from the kernel command line. |
| 6538 | */ |
| 6539 | allocate_snapshot = false; |
Steven Rostedt (Red Hat) | 737223f | 2013-03-05 21:13:47 -0500 | [diff] [blame] | 6540 | #endif |
| 6541 | return 0; |
Steven Rostedt (Red Hat) | 737223f | 2013-03-05 21:13:47 -0500 | [diff] [blame] | 6542 | } |
| 6543 | |
Steven Rostedt (Red Hat) | f0b70cc | 2014-06-10 12:06:30 -0400 | [diff] [blame] | 6544 | static void free_trace_buffer(struct trace_buffer *buf) |
| 6545 | { |
| 6546 | if (buf->buffer) { |
| 6547 | ring_buffer_free(buf->buffer); |
| 6548 | buf->buffer = NULL; |
| 6549 | free_percpu(buf->data); |
| 6550 | buf->data = NULL; |
| 6551 | } |
| 6552 | } |
| 6553 | |
Steven Rostedt (Red Hat) | 23aaa3c | 2014-06-06 00:01:46 -0400 | [diff] [blame] | 6554 | static void free_trace_buffers(struct trace_array *tr) |
| 6555 | { |
| 6556 | if (!tr) |
| 6557 | return; |
| 6558 | |
Steven Rostedt (Red Hat) | f0b70cc | 2014-06-10 12:06:30 -0400 | [diff] [blame] | 6559 | free_trace_buffer(&tr->trace_buffer); |
Steven Rostedt (Red Hat) | 23aaa3c | 2014-06-06 00:01:46 -0400 | [diff] [blame] | 6560 | |
| 6561 | #ifdef CONFIG_TRACER_MAX_TRACE |
Steven Rostedt (Red Hat) | f0b70cc | 2014-06-10 12:06:30 -0400 | [diff] [blame] | 6562 | free_trace_buffer(&tr->max_buffer); |
Steven Rostedt (Red Hat) | 23aaa3c | 2014-06-06 00:01:46 -0400 | [diff] [blame] | 6563 | #endif |
| 6564 | } |
| 6565 | |
Steven Rostedt (Red Hat) | 9a38a88 | 2015-09-30 11:11:15 -0400 | [diff] [blame] | 6566 | static void init_trace_flags_index(struct trace_array *tr) |
| 6567 | { |
| 6568 | int i; |
| 6569 | |
| 6570 | /* Used by the trace options files */ |
| 6571 | for (i = 0; i < TRACE_FLAGS_MAX_SIZE; i++) |
| 6572 | tr->trace_flags_index[i] = i; |
| 6573 | } |
| 6574 | |
Steven Rostedt (Red Hat) | 37aea98 | 2015-09-30 14:27:31 -0400 | [diff] [blame] | 6575 | static void __update_tracer_options(struct trace_array *tr) |
| 6576 | { |
| 6577 | struct tracer *t; |
| 6578 | |
| 6579 | for (t = trace_types; t; t = t->next) |
| 6580 | add_tracer_options(tr, t); |
| 6581 | } |
| 6582 | |
| 6583 | static void update_tracer_options(struct trace_array *tr) |
| 6584 | { |
| 6585 | mutex_lock(&trace_types_lock); |
| 6586 | __update_tracer_options(tr); |
| 6587 | mutex_unlock(&trace_types_lock); |
| 6588 | } |
| 6589 | |
Steven Rostedt (Red Hat) | eae4735 | 2015-01-21 10:01:39 -0500 | [diff] [blame] | 6590 | static int instance_mkdir(const char *name) |
Steven Rostedt (Red Hat) | 737223f | 2013-03-05 21:13:47 -0500 | [diff] [blame] | 6591 | { |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 6592 | struct trace_array *tr; |
| 6593 | int ret; |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 6594 | |
| 6595 | mutex_lock(&trace_types_lock); |
| 6596 | |
| 6597 | ret = -EEXIST; |
| 6598 | list_for_each_entry(tr, &ftrace_trace_arrays, list) { |
| 6599 | if (tr->name && strcmp(tr->name, name) == 0) |
| 6600 | goto out_unlock; |
| 6601 | } |
| 6602 | |
| 6603 | ret = -ENOMEM; |
| 6604 | tr = kzalloc(sizeof(*tr), GFP_KERNEL); |
| 6605 | if (!tr) |
| 6606 | goto out_unlock; |
| 6607 | |
| 6608 | tr->name = kstrdup(name, GFP_KERNEL); |
| 6609 | if (!tr->name) |
| 6610 | goto out_free_tr; |
| 6611 | |
Alexander Z Lam | ccfe9e4 | 2013-08-08 09:47:45 -0700 | [diff] [blame] | 6612 | if (!alloc_cpumask_var(&tr->tracing_cpumask, GFP_KERNEL)) |
| 6613 | goto out_free_tr; |
| 6614 | |
Steven Rostedt (Red Hat) | 983f938 | 2015-09-30 09:42:05 -0400 | [diff] [blame] | 6615 | tr->trace_flags = global_trace.trace_flags; |
| 6616 | |
Alexander Z Lam | ccfe9e4 | 2013-08-08 09:47:45 -0700 | [diff] [blame] | 6617 | cpumask_copy(tr->tracing_cpumask, cpu_all_mask); |
| 6618 | |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 6619 | raw_spin_lock_init(&tr->start_lock); |
| 6620 | |
Steven Rostedt (Red Hat) | 0b9b12c | 2014-01-14 10:04:59 -0500 | [diff] [blame] | 6621 | tr->max_lock = (arch_spinlock_t)__ARCH_SPIN_LOCK_UNLOCKED; |
| 6622 | |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 6623 | tr->current_trace = &nop_trace; |
| 6624 | |
| 6625 | INIT_LIST_HEAD(&tr->systems); |
| 6626 | INIT_LIST_HEAD(&tr->events); |
| 6627 | |
Steven Rostedt (Red Hat) | 737223f | 2013-03-05 21:13:47 -0500 | [diff] [blame] | 6628 | if (allocate_trace_buffers(tr, trace_buf_size) < 0) |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 6629 | goto out_free_tr; |
| 6630 | |
Steven Rostedt (Red Hat) | 8434dc9 | 2015-01-20 12:13:40 -0500 | [diff] [blame] | 6631 | tr->dir = tracefs_create_dir(name, trace_instance_dir); |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 6632 | if (!tr->dir) |
| 6633 | goto out_free_tr; |
| 6634 | |
| 6635 | ret = event_trace_add_tracer(tr->dir, tr); |
Alexander Z Lam | 609e85a | 2013-07-10 17:34:34 -0700 | [diff] [blame] | 6636 | if (ret) { |
Steven Rostedt (Red Hat) | 8434dc9 | 2015-01-20 12:13:40 -0500 | [diff] [blame] | 6637 | tracefs_remove_recursive(tr->dir); |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 6638 | goto out_free_tr; |
Alexander Z Lam | 609e85a | 2013-07-10 17:34:34 -0700 | [diff] [blame] | 6639 | } |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 6640 | |
Steven Rostedt (Red Hat) | 8434dc9 | 2015-01-20 12:13:40 -0500 | [diff] [blame] | 6641 | init_tracer_tracefs(tr, tr->dir); |
Steven Rostedt (Red Hat) | 9a38a88 | 2015-09-30 11:11:15 -0400 | [diff] [blame] | 6642 | init_trace_flags_index(tr); |
Steven Rostedt (Red Hat) | 37aea98 | 2015-09-30 14:27:31 -0400 | [diff] [blame] | 6643 | __update_tracer_options(tr); |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 6644 | |
| 6645 | list_add(&tr->list, &ftrace_trace_arrays); |
| 6646 | |
| 6647 | mutex_unlock(&trace_types_lock); |
| 6648 | |
| 6649 | return 0; |
| 6650 | |
| 6651 | out_free_tr: |
Steven Rostedt (Red Hat) | 23aaa3c | 2014-06-06 00:01:46 -0400 | [diff] [blame] | 6652 | free_trace_buffers(tr); |
Alexander Z Lam | ccfe9e4 | 2013-08-08 09:47:45 -0700 | [diff] [blame] | 6653 | free_cpumask_var(tr->tracing_cpumask); |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 6654 | kfree(tr->name); |
| 6655 | kfree(tr); |
| 6656 | |
| 6657 | out_unlock: |
| 6658 | mutex_unlock(&trace_types_lock); |
| 6659 | |
| 6660 | return ret; |
| 6661 | |
| 6662 | } |
| 6663 | |
Steven Rostedt (Red Hat) | eae4735 | 2015-01-21 10:01:39 -0500 | [diff] [blame] | 6664 | static int instance_rmdir(const char *name) |
Steven Rostedt | 0c8916c | 2012-08-07 16:14:16 -0400 | [diff] [blame] | 6665 | { |
| 6666 | struct trace_array *tr; |
| 6667 | int found = 0; |
| 6668 | int ret; |
Steven Rostedt (Red Hat) | 37aea98 | 2015-09-30 14:27:31 -0400 | [diff] [blame] | 6669 | int i; |
Steven Rostedt | 0c8916c | 2012-08-07 16:14:16 -0400 | [diff] [blame] | 6670 | |
| 6671 | mutex_lock(&trace_types_lock); |
| 6672 | |
| 6673 | ret = -ENODEV; |
| 6674 | list_for_each_entry(tr, &ftrace_trace_arrays, list) { |
| 6675 | if (tr->name && strcmp(tr->name, name) == 0) { |
| 6676 | found = 1; |
| 6677 | break; |
| 6678 | } |
| 6679 | } |
| 6680 | if (!found) |
| 6681 | goto out_unlock; |
| 6682 | |
Steven Rostedt (Red Hat) | a695cb5 | 2013-03-06 15:27:24 -0500 | [diff] [blame] | 6683 | ret = -EBUSY; |
Steven Rostedt (Red Hat) | cf6ab6d | 2014-12-15 20:13:31 -0500 | [diff] [blame] | 6684 | if (tr->ref || (tr->current_trace && tr->current_trace->ref)) |
Steven Rostedt (Red Hat) | a695cb5 | 2013-03-06 15:27:24 -0500 | [diff] [blame] | 6685 | goto out_unlock; |
| 6686 | |
Steven Rostedt | 0c8916c | 2012-08-07 16:14:16 -0400 | [diff] [blame] | 6687 | list_del(&tr->list); |
| 6688 | |
Steven Rostedt (Red Hat) | 6b450d2 | 2014-01-14 08:43:01 -0500 | [diff] [blame] | 6689 | tracing_set_nop(tr); |
Steven Rostedt | 0c8916c | 2012-08-07 16:14:16 -0400 | [diff] [blame] | 6690 | event_trace_del_tracer(tr); |
Steven Rostedt (Red Hat) | 591dffd | 2014-01-10 16:17:45 -0500 | [diff] [blame] | 6691 | ftrace_destroy_function_files(tr); |
Jiaxing Wang | 681a4a2 | 2015-10-18 19:58:08 +0800 | [diff] [blame^] | 6692 | tracefs_remove_recursive(tr->dir); |
Steven Rostedt (Red Hat) | a9fcaaa | 2014-06-06 23:17:28 -0400 | [diff] [blame] | 6693 | free_trace_buffers(tr); |
Steven Rostedt | 0c8916c | 2012-08-07 16:14:16 -0400 | [diff] [blame] | 6694 | |
Steven Rostedt (Red Hat) | 37aea98 | 2015-09-30 14:27:31 -0400 | [diff] [blame] | 6695 | for (i = 0; i < tr->nr_topts; i++) { |
| 6696 | kfree(tr->topts[i].topts); |
| 6697 | } |
| 6698 | kfree(tr->topts); |
| 6699 | |
Steven Rostedt | 0c8916c | 2012-08-07 16:14:16 -0400 | [diff] [blame] | 6700 | kfree(tr->name); |
| 6701 | kfree(tr); |
| 6702 | |
| 6703 | ret = 0; |
| 6704 | |
| 6705 | out_unlock: |
| 6706 | mutex_unlock(&trace_types_lock); |
| 6707 | |
| 6708 | return ret; |
| 6709 | } |
| 6710 | |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 6711 | static __init void create_trace_instances(struct dentry *d_tracer) |
| 6712 | { |
Steven Rostedt (Red Hat) | eae4735 | 2015-01-21 10:01:39 -0500 | [diff] [blame] | 6713 | trace_instance_dir = tracefs_create_instance_dir("instances", d_tracer, |
| 6714 | instance_mkdir, |
| 6715 | instance_rmdir); |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 6716 | if (WARN_ON(!trace_instance_dir)) |
| 6717 | return; |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 6718 | } |
| 6719 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6720 | static void |
Steven Rostedt (Red Hat) | 8434dc9 | 2015-01-20 12:13:40 -0500 | [diff] [blame] | 6721 | init_tracer_tracefs(struct trace_array *tr, struct dentry *d_tracer) |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6722 | { |
Steven Rostedt (Red Hat) | 121aaee | 2013-03-05 21:52:25 -0500 | [diff] [blame] | 6723 | int cpu; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6724 | |
Steven Rostedt (Red Hat) | 607e2ea | 2013-11-06 22:42:48 -0500 | [diff] [blame] | 6725 | trace_create_file("available_tracers", 0444, d_tracer, |
| 6726 | tr, &show_traces_fops); |
| 6727 | |
| 6728 | trace_create_file("current_tracer", 0644, d_tracer, |
| 6729 | tr, &set_tracer_fops); |
| 6730 | |
Alexander Z Lam | ccfe9e4 | 2013-08-08 09:47:45 -0700 | [diff] [blame] | 6731 | trace_create_file("tracing_cpumask", 0644, d_tracer, |
| 6732 | tr, &tracing_cpumask_fops); |
| 6733 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6734 | trace_create_file("trace_options", 0644, d_tracer, |
| 6735 | tr, &tracing_iter_fops); |
| 6736 | |
| 6737 | trace_create_file("trace", 0644, d_tracer, |
Oleg Nesterov | 6484c71 | 2013-07-23 17:26:10 +0200 | [diff] [blame] | 6738 | tr, &tracing_fops); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6739 | |
| 6740 | trace_create_file("trace_pipe", 0444, d_tracer, |
Oleg Nesterov | 1554420 | 2013-07-23 17:25:57 +0200 | [diff] [blame] | 6741 | tr, &tracing_pipe_fops); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6742 | |
| 6743 | trace_create_file("buffer_size_kb", 0644, d_tracer, |
Oleg Nesterov | 0bc392e | 2013-07-23 17:26:06 +0200 | [diff] [blame] | 6744 | tr, &tracing_entries_fops); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6745 | |
| 6746 | trace_create_file("buffer_total_size_kb", 0444, d_tracer, |
| 6747 | tr, &tracing_total_entries_fops); |
| 6748 | |
Wang YanQing | 238ae93 | 2013-05-26 16:52:01 +0800 | [diff] [blame] | 6749 | trace_create_file("free_buffer", 0200, d_tracer, |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6750 | tr, &tracing_free_buffer_fops); |
| 6751 | |
| 6752 | trace_create_file("trace_marker", 0220, d_tracer, |
| 6753 | tr, &tracing_mark_fops); |
| 6754 | |
| 6755 | trace_create_file("trace_clock", 0644, d_tracer, tr, |
| 6756 | &trace_clock_fops); |
| 6757 | |
| 6758 | trace_create_file("tracing_on", 0644, d_tracer, |
Oleg Nesterov | 6484c71 | 2013-07-23 17:26:10 +0200 | [diff] [blame] | 6759 | tr, &rb_simple_fops); |
Steven Rostedt (Red Hat) | ce9bae5 | 2013-03-05 21:23:55 -0500 | [diff] [blame] | 6760 | |
Steven Rostedt (Red Hat) | 1627014 | 2015-09-30 12:30:06 -0400 | [diff] [blame] | 6761 | create_trace_options_dir(tr); |
| 6762 | |
Steven Rostedt (Red Hat) | 6d9b3fa | 2014-01-14 11:28:38 -0500 | [diff] [blame] | 6763 | #ifdef CONFIG_TRACER_MAX_TRACE |
| 6764 | trace_create_file("tracing_max_latency", 0644, d_tracer, |
| 6765 | &tr->max_latency, &tracing_max_lat_fops); |
| 6766 | #endif |
| 6767 | |
Steven Rostedt (Red Hat) | 591dffd | 2014-01-10 16:17:45 -0500 | [diff] [blame] | 6768 | if (ftrace_create_function_files(tr, d_tracer)) |
| 6769 | WARN(1, "Could not allocate function filter files"); |
| 6770 | |
Steven Rostedt (Red Hat) | ce9bae5 | 2013-03-05 21:23:55 -0500 | [diff] [blame] | 6771 | #ifdef CONFIG_TRACER_SNAPSHOT |
| 6772 | trace_create_file("snapshot", 0644, d_tracer, |
Oleg Nesterov | 6484c71 | 2013-07-23 17:26:10 +0200 | [diff] [blame] | 6773 | tr, &snapshot_fops); |
Steven Rostedt (Red Hat) | ce9bae5 | 2013-03-05 21:23:55 -0500 | [diff] [blame] | 6774 | #endif |
Steven Rostedt (Red Hat) | 121aaee | 2013-03-05 21:52:25 -0500 | [diff] [blame] | 6775 | |
| 6776 | for_each_tracing_cpu(cpu) |
Steven Rostedt (Red Hat) | 8434dc9 | 2015-01-20 12:13:40 -0500 | [diff] [blame] | 6777 | tracing_init_tracefs_percpu(tr, cpu); |
Steven Rostedt (Red Hat) | 121aaee | 2013-03-05 21:52:25 -0500 | [diff] [blame] | 6778 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 6779 | } |
| 6780 | |
Steven Rostedt (Red Hat) | f76180b | 2015-01-20 15:48:46 -0500 | [diff] [blame] | 6781 | static struct vfsmount *trace_automount(void *ingore) |
| 6782 | { |
| 6783 | struct vfsmount *mnt; |
| 6784 | struct file_system_type *type; |
| 6785 | |
| 6786 | /* |
| 6787 | * To maintain backward compatibility for tools that mount |
| 6788 | * debugfs to get to the tracing facility, tracefs is automatically |
| 6789 | * mounted to the debugfs/tracing directory. |
| 6790 | */ |
| 6791 | type = get_fs_type("tracefs"); |
| 6792 | if (!type) |
| 6793 | return NULL; |
| 6794 | mnt = vfs_kern_mount(type, 0, "tracefs", NULL); |
| 6795 | put_filesystem(type); |
| 6796 | if (IS_ERR(mnt)) |
| 6797 | return NULL; |
| 6798 | mntget(mnt); |
| 6799 | |
| 6800 | return mnt; |
| 6801 | } |
| 6802 | |
Steven Rostedt (Red Hat) | 7eeafbc | 2015-01-26 21:00:48 -0500 | [diff] [blame] | 6803 | /** |
| 6804 | * tracing_init_dentry - initialize top level trace array |
| 6805 | * |
| 6806 | * This is called when creating files or directories in the tracing |
| 6807 | * directory. It is called via fs_initcall() by any of the boot up code |
| 6808 | * and expects to return the dentry of the top level tracing directory. |
| 6809 | */ |
| 6810 | struct dentry *tracing_init_dentry(void) |
| 6811 | { |
| 6812 | struct trace_array *tr = &global_trace; |
| 6813 | |
Steven Rostedt (Red Hat) | f76180b | 2015-01-20 15:48:46 -0500 | [diff] [blame] | 6814 | /* The top level trace array uses NULL as parent */ |
Steven Rostedt (Red Hat) | 7eeafbc | 2015-01-26 21:00:48 -0500 | [diff] [blame] | 6815 | if (tr->dir) |
Steven Rostedt (Red Hat) | f76180b | 2015-01-20 15:48:46 -0500 | [diff] [blame] | 6816 | return NULL; |
Steven Rostedt (Red Hat) | 7eeafbc | 2015-01-26 21:00:48 -0500 | [diff] [blame] | 6817 | |
| 6818 | if (WARN_ON(!debugfs_initialized())) |
| 6819 | return ERR_PTR(-ENODEV); |
| 6820 | |
Steven Rostedt (Red Hat) | f76180b | 2015-01-20 15:48:46 -0500 | [diff] [blame] | 6821 | /* |
| 6822 | * As there may still be users that expect the tracing |
| 6823 | * files to exist in debugfs/tracing, we must automount |
| 6824 | * the tracefs file system there, so older tools still |
| 6825 | * work with the newer kerenl. |
| 6826 | */ |
| 6827 | tr->dir = debugfs_create_automount("tracing", NULL, |
| 6828 | trace_automount, NULL); |
Steven Rostedt (Red Hat) | 7eeafbc | 2015-01-26 21:00:48 -0500 | [diff] [blame] | 6829 | if (!tr->dir) { |
| 6830 | pr_warn_once("Could not create debugfs directory 'tracing'\n"); |
| 6831 | return ERR_PTR(-ENOMEM); |
| 6832 | } |
| 6833 | |
Steven Rostedt (Red Hat) | 8434dc9 | 2015-01-20 12:13:40 -0500 | [diff] [blame] | 6834 | return NULL; |
Steven Rostedt (Red Hat) | 7eeafbc | 2015-01-26 21:00:48 -0500 | [diff] [blame] | 6835 | } |
| 6836 | |
Steven Rostedt (Red Hat) | 0c564a5 | 2015-03-24 17:58:09 -0400 | [diff] [blame] | 6837 | extern struct trace_enum_map *__start_ftrace_enum_maps[]; |
| 6838 | extern struct trace_enum_map *__stop_ftrace_enum_maps[]; |
| 6839 | |
| 6840 | static void __init trace_enum_init(void) |
| 6841 | { |
Steven Rostedt (Red Hat) | 3673b8e | 2015-03-25 15:44:21 -0400 | [diff] [blame] | 6842 | int len; |
| 6843 | |
| 6844 | len = __stop_ftrace_enum_maps - __start_ftrace_enum_maps; |
Steven Rostedt (Red Hat) | 9828413 | 2015-03-31 17:23:45 -0400 | [diff] [blame] | 6845 | trace_insert_enum_map(NULL, __start_ftrace_enum_maps, len); |
Steven Rostedt (Red Hat) | 0c564a5 | 2015-03-24 17:58:09 -0400 | [diff] [blame] | 6846 | } |
| 6847 | |
Steven Rostedt (Red Hat) | 3673b8e | 2015-03-25 15:44:21 -0400 | [diff] [blame] | 6848 | #ifdef CONFIG_MODULES |
| 6849 | static void trace_module_add_enums(struct module *mod) |
| 6850 | { |
| 6851 | if (!mod->num_trace_enums) |
| 6852 | return; |
| 6853 | |
| 6854 | /* |
| 6855 | * Modules with bad taint do not have events created, do |
| 6856 | * not bother with enums either. |
| 6857 | */ |
| 6858 | if (trace_module_has_bad_taint(mod)) |
| 6859 | return; |
| 6860 | |
Steven Rostedt (Red Hat) | 9828413 | 2015-03-31 17:23:45 -0400 | [diff] [blame] | 6861 | 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] | 6862 | } |
| 6863 | |
Steven Rostedt (Red Hat) | 9828413 | 2015-03-31 17:23:45 -0400 | [diff] [blame] | 6864 | #ifdef CONFIG_TRACE_ENUM_MAP_FILE |
| 6865 | static void trace_module_remove_enums(struct module *mod) |
| 6866 | { |
| 6867 | union trace_enum_map_item *map; |
| 6868 | union trace_enum_map_item **last = &trace_enum_maps; |
| 6869 | |
| 6870 | if (!mod->num_trace_enums) |
| 6871 | return; |
| 6872 | |
| 6873 | mutex_lock(&trace_enum_mutex); |
| 6874 | |
| 6875 | map = trace_enum_maps; |
| 6876 | |
| 6877 | while (map) { |
| 6878 | if (map->head.mod == mod) |
| 6879 | break; |
| 6880 | map = trace_enum_jmp_to_tail(map); |
| 6881 | last = &map->tail.next; |
| 6882 | map = map->tail.next; |
| 6883 | } |
| 6884 | if (!map) |
| 6885 | goto out; |
| 6886 | |
| 6887 | *last = trace_enum_jmp_to_tail(map)->tail.next; |
| 6888 | kfree(map); |
| 6889 | out: |
| 6890 | mutex_unlock(&trace_enum_mutex); |
| 6891 | } |
| 6892 | #else |
| 6893 | static inline void trace_module_remove_enums(struct module *mod) { } |
| 6894 | #endif /* CONFIG_TRACE_ENUM_MAP_FILE */ |
| 6895 | |
Steven Rostedt (Red Hat) | 3673b8e | 2015-03-25 15:44:21 -0400 | [diff] [blame] | 6896 | static int trace_module_notify(struct notifier_block *self, |
| 6897 | unsigned long val, void *data) |
| 6898 | { |
| 6899 | struct module *mod = data; |
| 6900 | |
| 6901 | switch (val) { |
| 6902 | case MODULE_STATE_COMING: |
| 6903 | trace_module_add_enums(mod); |
| 6904 | break; |
Steven Rostedt (Red Hat) | 9828413 | 2015-03-31 17:23:45 -0400 | [diff] [blame] | 6905 | case MODULE_STATE_GOING: |
| 6906 | trace_module_remove_enums(mod); |
| 6907 | break; |
Steven Rostedt (Red Hat) | 3673b8e | 2015-03-25 15:44:21 -0400 | [diff] [blame] | 6908 | } |
| 6909 | |
| 6910 | return 0; |
| 6911 | } |
| 6912 | |
| 6913 | static struct notifier_block trace_module_nb = { |
| 6914 | .notifier_call = trace_module_notify, |
| 6915 | .priority = 0, |
| 6916 | }; |
Steven Rostedt (Red Hat) | 9828413 | 2015-03-31 17:23:45 -0400 | [diff] [blame] | 6917 | #endif /* CONFIG_MODULES */ |
Steven Rostedt (Red Hat) | 3673b8e | 2015-03-25 15:44:21 -0400 | [diff] [blame] | 6918 | |
Steven Rostedt (Red Hat) | 8434dc9 | 2015-01-20 12:13:40 -0500 | [diff] [blame] | 6919 | static __init int tracer_init_tracefs(void) |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 6920 | { |
| 6921 | struct dentry *d_tracer; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 6922 | |
Lai Jiangshan | 7e53bd4 | 2010-01-06 20:08:50 +0800 | [diff] [blame] | 6923 | trace_access_lock_init(); |
| 6924 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 6925 | d_tracer = tracing_init_dentry(); |
Steven Rostedt (Red Hat) | 14a5ae4 | 2015-01-20 11:14:16 -0500 | [diff] [blame] | 6926 | if (IS_ERR(d_tracer)) |
Namhyung Kim | ed6f1c9 | 2013-04-10 09:18:12 +0900 | [diff] [blame] | 6927 | return 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 6928 | |
Steven Rostedt (Red Hat) | 8434dc9 | 2015-01-20 12:13:40 -0500 | [diff] [blame] | 6929 | init_tracer_tracefs(&global_trace, d_tracer); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 6930 | |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 6931 | trace_create_file("tracing_thresh", 0644, d_tracer, |
Stanislav Fomichev | 6508fa7 | 2014-07-18 15:17:27 +0400 | [diff] [blame] | 6932 | &global_trace, &tracing_thresh_fops); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 6933 | |
Li Zefan | 339ae5d | 2009-04-17 10:34:30 +0800 | [diff] [blame] | 6934 | trace_create_file("README", 0444, d_tracer, |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 6935 | NULL, &tracing_readme_fops); |
Ingo Molnar | 7bd2f24 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 6936 | |
Avadh Patel | 69abe6a | 2009-04-10 16:04:48 -0400 | [diff] [blame] | 6937 | trace_create_file("saved_cmdlines", 0444, d_tracer, |
| 6938 | NULL, &tracing_saved_cmdlines_fops); |
Pekka Paalanen | 5bf9a1e | 2008-09-16 22:06:42 +0300 | [diff] [blame] | 6939 | |
Yoshihiro YUNOMAE | 939c7a4 | 2014-06-05 10:24:27 +0900 | [diff] [blame] | 6940 | trace_create_file("saved_cmdlines_size", 0644, d_tracer, |
| 6941 | NULL, &tracing_saved_cmdlines_size_fops); |
| 6942 | |
Steven Rostedt (Red Hat) | 0c564a5 | 2015-03-24 17:58:09 -0400 | [diff] [blame] | 6943 | trace_enum_init(); |
| 6944 | |
Steven Rostedt (Red Hat) | 9828413 | 2015-03-31 17:23:45 -0400 | [diff] [blame] | 6945 | trace_create_enum_file(d_tracer); |
| 6946 | |
Steven Rostedt (Red Hat) | 3673b8e | 2015-03-25 15:44:21 -0400 | [diff] [blame] | 6947 | #ifdef CONFIG_MODULES |
| 6948 | register_module_notifier(&trace_module_nb); |
| 6949 | #endif |
| 6950 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 6951 | #ifdef CONFIG_DYNAMIC_FTRACE |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 6952 | trace_create_file("dyn_ftrace_total_info", 0444, d_tracer, |
| 6953 | &ftrace_update_tot_cnt, &tracing_dyn_info_fops); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 6954 | #endif |
Frederic Weisbecker | b04cc6b | 2009-02-25 03:22:28 +0100 | [diff] [blame] | 6955 | |
Steven Rostedt | 277ba04 | 2012-08-03 16:10:49 -0400 | [diff] [blame] | 6956 | create_trace_instances(d_tracer); |
Hiraku Toyooka | debdd57 | 2012-12-26 11:53:00 +0900 | [diff] [blame] | 6957 | |
Steven Rostedt (Red Hat) | 37aea98 | 2015-09-30 14:27:31 -0400 | [diff] [blame] | 6958 | update_tracer_options(&global_trace); |
Steven Rostedt (Red Hat) | 09d23a1 | 2015-02-03 12:45:53 -0500 | [diff] [blame] | 6959 | |
Frédéric Weisbecker | b5ad384 | 2008-09-23 11:34:32 +0100 | [diff] [blame] | 6960 | return 0; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 6961 | } |
| 6962 | |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 6963 | static int trace_panic_handler(struct notifier_block *this, |
| 6964 | unsigned long event, void *unused) |
| 6965 | { |
Steven Rostedt | 944ac42 | 2008-10-23 19:26:08 -0400 | [diff] [blame] | 6966 | if (ftrace_dump_on_oops) |
Frederic Weisbecker | cecbca9 | 2010-04-18 19:08:41 +0200 | [diff] [blame] | 6967 | ftrace_dump(ftrace_dump_on_oops); |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 6968 | return NOTIFY_OK; |
| 6969 | } |
| 6970 | |
| 6971 | static struct notifier_block trace_panic_notifier = { |
| 6972 | .notifier_call = trace_panic_handler, |
| 6973 | .next = NULL, |
| 6974 | .priority = 150 /* priority: INT_MAX >= x >= 0 */ |
| 6975 | }; |
| 6976 | |
| 6977 | static int trace_die_handler(struct notifier_block *self, |
| 6978 | unsigned long val, |
| 6979 | void *data) |
| 6980 | { |
| 6981 | switch (val) { |
| 6982 | case DIE_OOPS: |
Steven Rostedt | 944ac42 | 2008-10-23 19:26:08 -0400 | [diff] [blame] | 6983 | if (ftrace_dump_on_oops) |
Frederic Weisbecker | cecbca9 | 2010-04-18 19:08:41 +0200 | [diff] [blame] | 6984 | ftrace_dump(ftrace_dump_on_oops); |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 6985 | break; |
| 6986 | default: |
| 6987 | break; |
| 6988 | } |
| 6989 | return NOTIFY_OK; |
| 6990 | } |
| 6991 | |
| 6992 | static struct notifier_block trace_die_notifier = { |
| 6993 | .notifier_call = trace_die_handler, |
| 6994 | .priority = 200 |
| 6995 | }; |
| 6996 | |
| 6997 | /* |
| 6998 | * printk is set to max of 1024, we really don't need it that big. |
| 6999 | * Nothing should be printing 1000 characters anyway. |
| 7000 | */ |
| 7001 | #define TRACE_MAX_PRINT 1000 |
| 7002 | |
| 7003 | /* |
| 7004 | * Define here KERN_TRACE so that we have one place to modify |
| 7005 | * it if we decide to change what log level the ftrace dump |
| 7006 | * should be at. |
| 7007 | */ |
Steven Rostedt | 428aee1 | 2009-01-14 12:24:42 -0500 | [diff] [blame] | 7008 | #define KERN_TRACE KERN_EMERG |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 7009 | |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 7010 | void |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 7011 | trace_printk_seq(struct trace_seq *s) |
| 7012 | { |
| 7013 | /* Probably should print a warning here. */ |
Steven Rostedt (Red Hat) | 3a161d9 | 2014-06-25 15:54:42 -0400 | [diff] [blame] | 7014 | if (s->seq.len >= TRACE_MAX_PRINT) |
| 7015 | s->seq.len = TRACE_MAX_PRINT; |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 7016 | |
Steven Rostedt (Red Hat) | 820b75f | 2014-11-19 10:56:41 -0500 | [diff] [blame] | 7017 | /* |
| 7018 | * More paranoid code. Although the buffer size is set to |
| 7019 | * PAGE_SIZE, and TRACE_MAX_PRINT is 1000, this is just |
| 7020 | * an extra layer of protection. |
| 7021 | */ |
| 7022 | if (WARN_ON_ONCE(s->seq.len >= s->seq.size)) |
| 7023 | s->seq.len = s->seq.size - 1; |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 7024 | |
| 7025 | /* should be zero ended, but we are paranoid. */ |
Steven Rostedt (Red Hat) | 3a161d9 | 2014-06-25 15:54:42 -0400 | [diff] [blame] | 7026 | s->buffer[s->seq.len] = 0; |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 7027 | |
| 7028 | printk(KERN_TRACE "%s", s->buffer); |
| 7029 | |
Steven Rostedt | f952075 | 2009-03-02 14:04:40 -0500 | [diff] [blame] | 7030 | trace_seq_init(s); |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 7031 | } |
| 7032 | |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 7033 | void trace_init_global_iter(struct trace_iterator *iter) |
| 7034 | { |
| 7035 | iter->tr = &global_trace; |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 7036 | iter->trace = iter->tr->current_trace; |
Steven Rostedt | ae3b509 | 2013-01-23 15:22:59 -0500 | [diff] [blame] | 7037 | iter->cpu_file = RING_BUFFER_ALL_CPUS; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 7038 | iter->trace_buffer = &global_trace.trace_buffer; |
Cody P Schafer | b2f974d | 2013-10-23 11:49:57 -0700 | [diff] [blame] | 7039 | |
| 7040 | if (iter->trace && iter->trace->open) |
| 7041 | iter->trace->open(iter); |
| 7042 | |
| 7043 | /* Annotate start of buffers if we had overruns */ |
| 7044 | if (ring_buffer_overruns(iter->trace_buffer->buffer)) |
| 7045 | iter->iter_flags |= TRACE_FILE_ANNOTATE; |
| 7046 | |
| 7047 | /* Output in nanoseconds only if we are using a clock in nanoseconds. */ |
| 7048 | if (trace_clocks[iter->tr->clock_id].in_ns) |
| 7049 | iter->iter_flags |= TRACE_FILE_TIME_IN_NS; |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 7050 | } |
| 7051 | |
Steven Rostedt (Red Hat) | 7fe70b5 | 2013-03-15 13:10:35 -0400 | [diff] [blame] | 7052 | void ftrace_dump(enum ftrace_dump_mode oops_dump_mode) |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 7053 | { |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 7054 | /* use static because iter can be a bit big for the stack */ |
| 7055 | static struct trace_iterator iter; |
Steven Rostedt (Red Hat) | 7fe70b5 | 2013-03-15 13:10:35 -0400 | [diff] [blame] | 7056 | static atomic_t dump_running; |
Steven Rostedt (Red Hat) | 983f938 | 2015-09-30 09:42:05 -0400 | [diff] [blame] | 7057 | struct trace_array *tr = &global_trace; |
Frederic Weisbecker | cf586b6 | 2009-03-22 05:04:35 +0100 | [diff] [blame] | 7058 | unsigned int old_userobj; |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 7059 | unsigned long flags; |
| 7060 | int cnt = 0, cpu; |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 7061 | |
Steven Rostedt (Red Hat) | 7fe70b5 | 2013-03-15 13:10:35 -0400 | [diff] [blame] | 7062 | /* Only allow one dump user at a time. */ |
| 7063 | if (atomic_inc_return(&dump_running) != 1) { |
| 7064 | atomic_dec(&dump_running); |
| 7065 | return; |
Steven Rostedt | e0a413f | 2011-09-29 21:26:16 -0400 | [diff] [blame] | 7066 | } |
| 7067 | |
Steven Rostedt (Red Hat) | 7fe70b5 | 2013-03-15 13:10:35 -0400 | [diff] [blame] | 7068 | /* |
| 7069 | * Always turn off tracing when we dump. |
| 7070 | * We don't need to show trace output of what happens |
| 7071 | * between multiple crashes. |
| 7072 | * |
| 7073 | * If the user does a sysrq-z, then they can re-enable |
| 7074 | * tracing with echo 1 > tracing_on. |
| 7075 | */ |
| 7076 | tracing_off(); |
| 7077 | |
| 7078 | local_irq_save(flags); |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 7079 | |
Jovi Zhang | 38dbe0b | 2013-01-25 18:03:07 +0800 | [diff] [blame] | 7080 | /* Simulate the iterator */ |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 7081 | trace_init_global_iter(&iter); |
| 7082 | |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 7083 | for_each_tracing_cpu(cpu) { |
Umesh Tiwari | 5e2d5ef | 2015-06-22 16:55:06 +0530 | [diff] [blame] | 7084 | atomic_inc(&per_cpu_ptr(iter.trace_buffer->data, cpu)->disabled); |
Steven Rostedt | d769041 | 2008-10-01 00:29:53 -0400 | [diff] [blame] | 7085 | } |
| 7086 | |
Steven Rostedt (Red Hat) | 983f938 | 2015-09-30 09:42:05 -0400 | [diff] [blame] | 7087 | old_userobj = tr->trace_flags & TRACE_ITER_SYM_USEROBJ; |
Frederic Weisbecker | cf586b6 | 2009-03-22 05:04:35 +0100 | [diff] [blame] | 7088 | |
Török Edwin | b54d3de | 2008-11-22 13:28:48 +0200 | [diff] [blame] | 7089 | /* don't look at user memory in panic mode */ |
Steven Rostedt (Red Hat) | 983f938 | 2015-09-30 09:42:05 -0400 | [diff] [blame] | 7090 | tr->trace_flags &= ~TRACE_ITER_SYM_USEROBJ; |
Török Edwin | b54d3de | 2008-11-22 13:28:48 +0200 | [diff] [blame] | 7091 | |
Frederic Weisbecker | cecbca9 | 2010-04-18 19:08:41 +0200 | [diff] [blame] | 7092 | switch (oops_dump_mode) { |
| 7093 | case DUMP_ALL: |
Steven Rostedt | ae3b509 | 2013-01-23 15:22:59 -0500 | [diff] [blame] | 7094 | iter.cpu_file = RING_BUFFER_ALL_CPUS; |
Frederic Weisbecker | cecbca9 | 2010-04-18 19:08:41 +0200 | [diff] [blame] | 7095 | break; |
| 7096 | case DUMP_ORIG: |
| 7097 | iter.cpu_file = raw_smp_processor_id(); |
| 7098 | break; |
| 7099 | case DUMP_NONE: |
| 7100 | goto out_enable; |
| 7101 | default: |
| 7102 | printk(KERN_TRACE "Bad dumping mode, switching to all CPUs dump\n"); |
Steven Rostedt | ae3b509 | 2013-01-23 15:22:59 -0500 | [diff] [blame] | 7103 | iter.cpu_file = RING_BUFFER_ALL_CPUS; |
Frederic Weisbecker | cecbca9 | 2010-04-18 19:08:41 +0200 | [diff] [blame] | 7104 | } |
| 7105 | |
| 7106 | printk(KERN_TRACE "Dumping ftrace buffer:\n"); |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 7107 | |
Steven Rostedt (Red Hat) | 7fe70b5 | 2013-03-15 13:10:35 -0400 | [diff] [blame] | 7108 | /* Did function tracer already get disabled? */ |
| 7109 | if (ftrace_is_dead()) { |
| 7110 | printk("# WARNING: FUNCTION TRACING IS CORRUPTED\n"); |
| 7111 | printk("# MAY BE MISSING FUNCTION EVENTS\n"); |
| 7112 | } |
| 7113 | |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 7114 | /* |
| 7115 | * We need to stop all tracing on all CPUS to read the |
| 7116 | * the next buffer. This is a bit expensive, but is |
| 7117 | * not done often. We fill all what we can read, |
| 7118 | * and then release the locks again. |
| 7119 | */ |
| 7120 | |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 7121 | while (!trace_empty(&iter)) { |
| 7122 | |
| 7123 | if (!cnt) |
| 7124 | printk(KERN_TRACE "---------------------------------\n"); |
| 7125 | |
| 7126 | cnt++; |
| 7127 | |
| 7128 | /* reset all but tr, trace, and overruns */ |
| 7129 | memset(&iter.seq, 0, |
| 7130 | sizeof(struct trace_iterator) - |
| 7131 | offsetof(struct trace_iterator, seq)); |
| 7132 | iter.iter_flags |= TRACE_FILE_LAT_FMT; |
| 7133 | iter.pos = -1; |
| 7134 | |
Jason Wessel | 955b61e | 2010-08-05 09:22:23 -0500 | [diff] [blame] | 7135 | if (trace_find_next_entry_inc(&iter) != NULL) { |
Lai Jiangshan | 74e7ff8 | 2009-07-28 20:17:22 +0800 | [diff] [blame] | 7136 | int ret; |
| 7137 | |
| 7138 | ret = print_trace_line(&iter); |
| 7139 | if (ret != TRACE_TYPE_NO_CONSUME) |
| 7140 | trace_consume(&iter); |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 7141 | } |
Steven Rostedt | b892e5c | 2012-03-01 22:06:48 -0500 | [diff] [blame] | 7142 | touch_nmi_watchdog(); |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 7143 | |
| 7144 | trace_printk_seq(&iter.seq); |
| 7145 | } |
| 7146 | |
| 7147 | if (!cnt) |
| 7148 | printk(KERN_TRACE " (ftrace buffer empty)\n"); |
| 7149 | else |
| 7150 | printk(KERN_TRACE "---------------------------------\n"); |
| 7151 | |
Frederic Weisbecker | cecbca9 | 2010-04-18 19:08:41 +0200 | [diff] [blame] | 7152 | out_enable: |
Steven Rostedt (Red Hat) | 983f938 | 2015-09-30 09:42:05 -0400 | [diff] [blame] | 7153 | tr->trace_flags |= old_userobj; |
Frederic Weisbecker | cf586b6 | 2009-03-22 05:04:35 +0100 | [diff] [blame] | 7154 | |
Steven Rostedt (Red Hat) | 7fe70b5 | 2013-03-15 13:10:35 -0400 | [diff] [blame] | 7155 | for_each_tracing_cpu(cpu) { |
| 7156 | atomic_dec(&per_cpu_ptr(iter.trace_buffer->data, cpu)->disabled); |
Frederic Weisbecker | cf586b6 | 2009-03-22 05:04:35 +0100 | [diff] [blame] | 7157 | } |
Steven Rostedt (Red Hat) | 7fe70b5 | 2013-03-15 13:10:35 -0400 | [diff] [blame] | 7158 | atomic_dec(&dump_running); |
Steven Rostedt | cd891ae | 2009-04-28 11:39:34 -0400 | [diff] [blame] | 7159 | local_irq_restore(flags); |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 7160 | } |
Paul E. McKenney | a8eecf2 | 2011-10-02 11:01:15 -0700 | [diff] [blame] | 7161 | EXPORT_SYMBOL_GPL(ftrace_dump); |
Frederic Weisbecker | cf586b6 | 2009-03-22 05:04:35 +0100 | [diff] [blame] | 7162 | |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 7163 | __init static int tracer_alloc_buffers(void) |
| 7164 | { |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 7165 | int ring_buf_size; |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 7166 | int ret = -ENOMEM; |
| 7167 | |
Steven Rostedt (Red Hat) | b5e87c0 | 2015-09-29 18:13:33 -0400 | [diff] [blame] | 7168 | /* |
| 7169 | * Make sure we don't accidently add more trace options |
| 7170 | * than we have bits for. |
| 7171 | */ |
Steven Rostedt (Red Hat) | 9a38a88 | 2015-09-30 11:11:15 -0400 | [diff] [blame] | 7172 | BUILD_BUG_ON(TRACE_ITER_LAST_BIT > TRACE_FLAGS_MAX_SIZE); |
Steven Rostedt (Red Hat) | b5e87c0 | 2015-09-29 18:13:33 -0400 | [diff] [blame] | 7173 | |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 7174 | if (!alloc_cpumask_var(&tracing_buffer_mask, GFP_KERNEL)) |
| 7175 | goto out; |
| 7176 | |
Alexander Z Lam | ccfe9e4 | 2013-08-08 09:47:45 -0700 | [diff] [blame] | 7177 | if (!alloc_cpumask_var(&global_trace.tracing_cpumask, GFP_KERNEL)) |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 7178 | goto out_free_buffer_mask; |
| 7179 | |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 7180 | /* Only allocate trace_printk buffers if a trace_printk exists */ |
| 7181 | if (__stop___trace_bprintk_fmt != __start___trace_bprintk_fmt) |
Steven Rostedt | 8169883 | 2012-10-11 10:15:05 -0400 | [diff] [blame] | 7182 | /* Must be called before global_trace.buffer is allocated */ |
Steven Rostedt | 07d777f | 2011-09-22 14:01:55 -0400 | [diff] [blame] | 7183 | trace_printk_init_buffers(); |
| 7184 | |
Steven Rostedt | 73c5162 | 2009-03-11 13:42:01 -0400 | [diff] [blame] | 7185 | /* To save memory, keep the ring buffer size to its minimum */ |
| 7186 | if (ring_buffer_expanded) |
| 7187 | ring_buf_size = trace_buf_size; |
| 7188 | else |
| 7189 | ring_buf_size = 1; |
| 7190 | |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 7191 | cpumask_copy(tracing_buffer_mask, cpu_possible_mask); |
Alexander Z Lam | ccfe9e4 | 2013-08-08 09:47:45 -0700 | [diff] [blame] | 7192 | cpumask_copy(global_trace.tracing_cpumask, cpu_all_mask); |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 7193 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 7194 | raw_spin_lock_init(&global_trace.start_lock); |
| 7195 | |
Steven Rostedt (Red Hat) | 2c4a33a | 2014-03-25 23:39:41 -0400 | [diff] [blame] | 7196 | /* Used for event triggers */ |
| 7197 | temp_buffer = ring_buffer_alloc(PAGE_SIZE, RB_FL_OVERWRITE); |
| 7198 | if (!temp_buffer) |
| 7199 | goto out_free_cpumask; |
| 7200 | |
Yoshihiro YUNOMAE | 939c7a4 | 2014-06-05 10:24:27 +0900 | [diff] [blame] | 7201 | if (trace_create_savedcmd() < 0) |
| 7202 | goto out_free_temp_buffer; |
| 7203 | |
Steven Rostedt | ab46428 | 2008-05-12 21:21:00 +0200 | [diff] [blame] | 7204 | /* TODO: make the number of buffers hot pluggable with CPUS */ |
Steven Rostedt (Red Hat) | 737223f | 2013-03-05 21:13:47 -0500 | [diff] [blame] | 7205 | if (allocate_trace_buffers(&global_trace, ring_buf_size) < 0) { |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 7206 | printk(KERN_ERR "tracer: failed to allocate ring buffer!\n"); |
| 7207 | WARN_ON(1); |
Yoshihiro YUNOMAE | 939c7a4 | 2014-06-05 10:24:27 +0900 | [diff] [blame] | 7208 | goto out_free_savedcmd; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 7209 | } |
Steven Rostedt | a7603ff | 2012-08-06 16:24:11 -0400 | [diff] [blame] | 7210 | |
Steven Rostedt | 499e547 | 2012-02-22 15:50:28 -0500 | [diff] [blame] | 7211 | if (global_trace.buffer_disabled) |
| 7212 | tracing_off(); |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 7213 | |
Steven Rostedt | e1e232c | 2014-02-10 23:38:46 -0500 | [diff] [blame] | 7214 | if (trace_boot_clock) { |
| 7215 | ret = tracing_set_clock(&global_trace, trace_boot_clock); |
| 7216 | if (ret < 0) |
| 7217 | pr_warning("Trace clock %s not defined, going back to default\n", |
| 7218 | trace_boot_clock); |
| 7219 | } |
| 7220 | |
Steven Rostedt (Red Hat) | ca16431 | 2013-05-23 11:51:10 -0400 | [diff] [blame] | 7221 | /* |
| 7222 | * register_tracer() might reference current_trace, so it |
| 7223 | * needs to be set before we register anything. This is |
| 7224 | * just a bootstrap of current_trace anyway. |
| 7225 | */ |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 7226 | global_trace.current_trace = &nop_trace; |
| 7227 | |
Steven Rostedt (Red Hat) | 0b9b12c | 2014-01-14 10:04:59 -0500 | [diff] [blame] | 7228 | global_trace.max_lock = (arch_spinlock_t)__ARCH_SPIN_LOCK_UNLOCKED; |
| 7229 | |
Steven Rostedt (Red Hat) | 4104d32 | 2014-01-10 17:01:58 -0500 | [diff] [blame] | 7230 | ftrace_init_global_array_ops(&global_trace); |
| 7231 | |
Steven Rostedt (Red Hat) | 9a38a88 | 2015-09-30 11:11:15 -0400 | [diff] [blame] | 7232 | init_trace_flags_index(&global_trace); |
| 7233 | |
Steven Rostedt (Red Hat) | ca16431 | 2013-05-23 11:51:10 -0400 | [diff] [blame] | 7234 | register_tracer(&nop_trace); |
| 7235 | |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 7236 | /* All seems OK, enable tracing */ |
| 7237 | tracing_disabled = 0; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 7238 | |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 7239 | atomic_notifier_chain_register(&panic_notifier_list, |
| 7240 | &trace_panic_notifier); |
| 7241 | |
| 7242 | register_die_notifier(&trace_die_notifier); |
Frederic Weisbecker | 2fc1dfb | 2009-03-16 01:45:03 +0100 | [diff] [blame] | 7243 | |
Steven Rostedt | ae63b31e | 2012-05-03 23:09:03 -0400 | [diff] [blame] | 7244 | global_trace.flags = TRACE_ARRAY_FL_GLOBAL; |
| 7245 | |
| 7246 | INIT_LIST_HEAD(&global_trace.systems); |
| 7247 | INIT_LIST_HEAD(&global_trace.events); |
| 7248 | list_add(&global_trace.list, &ftrace_trace_arrays); |
| 7249 | |
Steven Rostedt | 7bcfaf5 | 2012-11-01 22:56:07 -0400 | [diff] [blame] | 7250 | while (trace_boot_options) { |
| 7251 | char *option; |
| 7252 | |
| 7253 | option = strsep(&trace_boot_options, ","); |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 7254 | trace_set_options(&global_trace, option); |
Steven Rostedt | 7bcfaf5 | 2012-11-01 22:56:07 -0400 | [diff] [blame] | 7255 | } |
| 7256 | |
Steven Rostedt (Red Hat) | 77fd5c1 | 2013-03-12 11:49:18 -0400 | [diff] [blame] | 7257 | register_snapshot_cmd(); |
| 7258 | |
Frederic Weisbecker | 2fc1dfb | 2009-03-16 01:45:03 +0100 | [diff] [blame] | 7259 | return 0; |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 7260 | |
Yoshihiro YUNOMAE | 939c7a4 | 2014-06-05 10:24:27 +0900 | [diff] [blame] | 7261 | out_free_savedcmd: |
| 7262 | free_saved_cmdlines_buffer(savedcmd); |
Steven Rostedt (Red Hat) | 2c4a33a | 2014-03-25 23:39:41 -0400 | [diff] [blame] | 7263 | out_free_temp_buffer: |
| 7264 | ring_buffer_free(temp_buffer); |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 7265 | out_free_cpumask: |
Alexander Z Lam | ccfe9e4 | 2013-08-08 09:47:45 -0700 | [diff] [blame] | 7266 | free_cpumask_var(global_trace.tracing_cpumask); |
Rusty Russell | 9e01c1b | 2009-01-01 10:12:22 +1030 | [diff] [blame] | 7267 | out_free_buffer_mask: |
| 7268 | free_cpumask_var(tracing_buffer_mask); |
| 7269 | out: |
| 7270 | return ret; |
Steven Rostedt | bc0c38d | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 7271 | } |
Steven Rostedt | b2821ae | 2009-02-02 21:38:32 -0500 | [diff] [blame] | 7272 | |
Steven Rostedt (Red Hat) | 5f893b2 | 2014-12-12 20:05:10 -0500 | [diff] [blame] | 7273 | void __init trace_init(void) |
| 7274 | { |
Steven Rostedt (Red Hat) | 0daa2302 | 2014-12-12 22:27:10 -0500 | [diff] [blame] | 7275 | if (tracepoint_printk) { |
| 7276 | tracepoint_print_iter = |
| 7277 | kmalloc(sizeof(*tracepoint_print_iter), GFP_KERNEL); |
| 7278 | if (WARN_ON(!tracepoint_print_iter)) |
| 7279 | tracepoint_printk = 0; |
| 7280 | } |
Steven Rostedt (Red Hat) | 5f893b2 | 2014-12-12 20:05:10 -0500 | [diff] [blame] | 7281 | tracer_alloc_buffers(); |
Steven Rostedt (Red Hat) | 0c564a5 | 2015-03-24 17:58:09 -0400 | [diff] [blame] | 7282 | trace_event_init(); |
Steven Rostedt (Red Hat) | 5f893b2 | 2014-12-12 20:05:10 -0500 | [diff] [blame] | 7283 | } |
| 7284 | |
Steven Rostedt | b2821ae | 2009-02-02 21:38:32 -0500 | [diff] [blame] | 7285 | __init static int clear_boot_tracer(void) |
| 7286 | { |
| 7287 | /* |
| 7288 | * The default tracer at boot buffer is an init section. |
| 7289 | * This function is called in lateinit. If we did not |
| 7290 | * find the boot tracer, then clear it out, to prevent |
| 7291 | * later registration from accessing the buffer that is |
| 7292 | * about to be freed. |
| 7293 | */ |
| 7294 | if (!default_bootup_tracer) |
| 7295 | return 0; |
| 7296 | |
| 7297 | printk(KERN_INFO "ftrace bootup tracer '%s' not registered.\n", |
| 7298 | default_bootup_tracer); |
| 7299 | default_bootup_tracer = NULL; |
| 7300 | |
| 7301 | return 0; |
| 7302 | } |
| 7303 | |
Steven Rostedt (Red Hat) | 8434dc9 | 2015-01-20 12:13:40 -0500 | [diff] [blame] | 7304 | fs_initcall(tracer_init_tracefs); |
Steven Rostedt | b2821ae | 2009-02-02 21:38:32 -0500 | [diff] [blame] | 7305 | late_initcall(clear_boot_tracer); |