Steven Rostedt (VMware) | bcea3f9 | 2018-08-16 11:23:53 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Steven Rostedt | 81d68a9 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2 | /* |
Wenji Huang | 73d8b8b | 2009-02-17 01:10:02 -0500 | [diff] [blame] | 3 | * trace irqs off critical timings |
Steven Rostedt | 81d68a9 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4 | * |
| 5 | * Copyright (C) 2007-2008 Steven Rostedt <srostedt@redhat.com> |
| 6 | * Copyright (C) 2008 Ingo Molnar <mingo@redhat.com> |
| 7 | * |
| 8 | * From code in the latency_tracer, that is: |
| 9 | * |
| 10 | * Copyright (C) 2004-2006 Ingo Molnar |
Nadia Yvette Chambers | 6d49e35 | 2012-12-06 10:39:54 +0100 | [diff] [blame] | 11 | * Copyright (C) 2004 Nadia Yvette Chambers |
Steven Rostedt | 81d68a9 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 12 | */ |
| 13 | #include <linux/kallsyms.h> |
Steven Rostedt | 81d68a9 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 14 | #include <linux/uaccess.h> |
| 15 | #include <linux/module.h> |
| 16 | #include <linux/ftrace.h> |
Steven Rostedt | 81d68a9 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 17 | |
| 18 | #include "trace.h" |
| 19 | |
Joel Fernandes | d591581 | 2017-10-10 15:51:37 -0700 | [diff] [blame] | 20 | #include <trace/events/preemptirq.h> |
| 21 | |
Joel Fernandes | aaecaa0 | 2017-10-05 17:54:31 -0700 | [diff] [blame] | 22 | #if defined(CONFIG_IRQSOFF_TRACER) || defined(CONFIG_PREEMPT_TRACER) |
Steven Rostedt | 81d68a9 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 23 | static struct trace_array *irqsoff_trace __read_mostly; |
| 24 | static int tracer_enabled __read_mostly; |
| 25 | |
Steven Rostedt | 6cd8a4b | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 26 | static DEFINE_PER_CPU(int, tracing_cpu); |
| 27 | |
Thomas Gleixner | 5389f6f | 2009-07-25 17:13:33 +0200 | [diff] [blame] | 28 | static DEFINE_RAW_SPINLOCK(max_trace_lock); |
Steven Rostedt | 89b2f97 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 29 | |
Steven Rostedt | 6cd8a4b | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 30 | enum { |
| 31 | TRACER_IRQS_OFF = (1 << 1), |
| 32 | TRACER_PREEMPT_OFF = (1 << 2), |
| 33 | }; |
| 34 | |
| 35 | static int trace_type __read_mostly; |
| 36 | |
Steven Rostedt (Red Hat) | 613f04a | 2013-03-14 15:03:53 -0400 | [diff] [blame] | 37 | static int save_flags; |
Steven Rostedt | e9d25fe | 2009-03-04 22:15:30 -0500 | [diff] [blame] | 38 | |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 39 | static void stop_irqsoff_tracer(struct trace_array *tr, int graph); |
| 40 | static int start_irqsoff_tracer(struct trace_array *tr, int graph); |
| 41 | |
Steven Rostedt | 6cd8a4b | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 42 | #ifdef CONFIG_PREEMPT_TRACER |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 43 | static inline int |
Steven Rostedt (VMware) | f27107f | 2018-08-07 17:03:12 -0400 | [diff] [blame] | 44 | preempt_trace(int pc) |
Steven Rostedt | 6cd8a4b | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 45 | { |
Steven Rostedt (VMware) | f27107f | 2018-08-07 17:03:12 -0400 | [diff] [blame] | 46 | return ((trace_type & TRACER_PREEMPT_OFF) && pc); |
Steven Rostedt | 6cd8a4b | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 47 | } |
| 48 | #else |
Steven Rostedt (VMware) | f27107f | 2018-08-07 17:03:12 -0400 | [diff] [blame] | 49 | # define preempt_trace(pc) (0) |
Steven Rostedt | 6cd8a4b | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 50 | #endif |
| 51 | |
| 52 | #ifdef CONFIG_IRQSOFF_TRACER |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 53 | static inline int |
Steven Rostedt | 6cd8a4b | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 54 | irq_trace(void) |
| 55 | { |
| 56 | return ((trace_type & TRACER_IRQS_OFF) && |
| 57 | irqs_disabled()); |
| 58 | } |
| 59 | #else |
| 60 | # define irq_trace() (0) |
| 61 | #endif |
| 62 | |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 63 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER |
Steven Rostedt (Red Hat) | 0390558 | 2015-09-28 15:37:49 -0400 | [diff] [blame] | 64 | static int irqsoff_display_graph(struct trace_array *tr, int set); |
Steven Rostedt (Red Hat) | 983f938 | 2015-09-30 09:42:05 -0400 | [diff] [blame] | 65 | # define is_graph(tr) ((tr)->trace_flags & TRACE_ITER_DISPLAY_GRAPH) |
Steven Rostedt (Red Hat) | 0390558 | 2015-09-28 15:37:49 -0400 | [diff] [blame] | 66 | #else |
| 67 | static inline int irqsoff_display_graph(struct trace_array *tr, int set) |
| 68 | { |
| 69 | return -EINVAL; |
| 70 | } |
Steven Rostedt (Red Hat) | 983f938 | 2015-09-30 09:42:05 -0400 | [diff] [blame] | 71 | # define is_graph(tr) false |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 72 | #endif |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 73 | |
Steven Rostedt | 81d68a9 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 74 | /* |
| 75 | * Sequence count - we record it when starting a measurement and |
| 76 | * skip the latency if the sequence has changed - some other section |
| 77 | * did a maximum and could disturb our measurement with serial console |
| 78 | * printouts, etc. Truly coinciding maximum latencies should be rare |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 79 | * and what happens together happens separately as well, so this doesn't |
Steven Rostedt | 81d68a9 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 80 | * decrease the validity of the maximum found: |
| 81 | */ |
| 82 | static __cacheline_aligned_in_smp unsigned long max_sequence; |
| 83 | |
Steven Rostedt | 606576c | 2008-10-06 19:06:12 -0400 | [diff] [blame] | 84 | #ifdef CONFIG_FUNCTION_TRACER |
Steven Rostedt | 81d68a9 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 85 | /* |
Steven Rostedt | 5e6d2b9 | 2010-10-05 19:41:43 -0400 | [diff] [blame] | 86 | * Prologue for the preempt and irqs off function tracers. |
| 87 | * |
| 88 | * Returns 1 if it is OK to continue, and data->disabled is |
| 89 | * incremented. |
| 90 | * 0 if the trace is to be ignored, and data->disabled |
| 91 | * is kept the same. |
| 92 | * |
| 93 | * Note, this function is also used outside this ifdef but |
| 94 | * inside the #ifdef of the function graph tracer below. |
| 95 | * This is OK, since the function graph tracer is |
| 96 | * dependent on the function tracer. |
Steven Rostedt | 81d68a9 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 97 | */ |
Steven Rostedt | 5e6d2b9 | 2010-10-05 19:41:43 -0400 | [diff] [blame] | 98 | static int func_prolog_dec(struct trace_array *tr, |
| 99 | struct trace_array_cpu **data, |
| 100 | unsigned long *flags) |
Steven Rostedt | 81d68a9 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 101 | { |
Steven Rostedt | 81d68a9 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 102 | long disabled; |
| 103 | int cpu; |
| 104 | |
Steven Rostedt | 361943a | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 105 | /* |
| 106 | * Does not matter if we preempt. We test the flags |
| 107 | * afterward, to see if irqs are disabled or not. |
| 108 | * If we preempt and get a false positive, the flags |
| 109 | * test will fail. |
| 110 | */ |
| 111 | cpu = raw_smp_processor_id(); |
| 112 | if (likely(!per_cpu(tracing_cpu, cpu))) |
Steven Rostedt | 5e6d2b9 | 2010-10-05 19:41:43 -0400 | [diff] [blame] | 113 | return 0; |
Steven Rostedt | 81d68a9 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 114 | |
Steven Rostedt | 5e6d2b9 | 2010-10-05 19:41:43 -0400 | [diff] [blame] | 115 | local_save_flags(*flags); |
Steven Rostedt (Red Hat) | cb86e05 | 2016-03-18 12:27:43 -0400 | [diff] [blame] | 116 | /* |
| 117 | * Slight chance to get a false positive on tracing_cpu, |
| 118 | * although I'm starting to think there isn't a chance. |
| 119 | * Leave this for now just to be paranoid. |
| 120 | */ |
| 121 | if (!irqs_disabled_flags(*flags) && !preempt_count()) |
Steven Rostedt | 5e6d2b9 | 2010-10-05 19:41:43 -0400 | [diff] [blame] | 122 | return 0; |
Steven Rostedt | 81d68a9 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 123 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 124 | *data = per_cpu_ptr(tr->trace_buffer.data, cpu); |
Steven Rostedt | 5e6d2b9 | 2010-10-05 19:41:43 -0400 | [diff] [blame] | 125 | disabled = atomic_inc_return(&(*data)->disabled); |
Steven Rostedt | 81d68a9 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 126 | |
| 127 | if (likely(disabled == 1)) |
Steven Rostedt | 5e6d2b9 | 2010-10-05 19:41:43 -0400 | [diff] [blame] | 128 | return 1; |
| 129 | |
| 130 | atomic_dec(&(*data)->disabled); |
| 131 | |
| 132 | return 0; |
| 133 | } |
| 134 | |
| 135 | /* |
| 136 | * irqsoff uses its own tracer function to keep the overhead down: |
| 137 | */ |
| 138 | static void |
Steven Rostedt | 2f5f6ad | 2011-08-08 16:57:47 -0400 | [diff] [blame] | 139 | irqsoff_tracer_call(unsigned long ip, unsigned long parent_ip, |
Steven Rostedt | a1e2e31 | 2011-08-09 12:50:46 -0400 | [diff] [blame] | 140 | struct ftrace_ops *op, struct pt_regs *pt_regs) |
Steven Rostedt | 5e6d2b9 | 2010-10-05 19:41:43 -0400 | [diff] [blame] | 141 | { |
| 142 | struct trace_array *tr = irqsoff_trace; |
| 143 | struct trace_array_cpu *data; |
| 144 | unsigned long flags; |
| 145 | |
| 146 | if (!func_prolog_dec(tr, &data, &flags)) |
| 147 | return; |
| 148 | |
| 149 | trace_function(tr, ip, parent_ip, flags, preempt_count()); |
Steven Rostedt | 81d68a9 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 150 | |
| 151 | atomic_dec(&data->disabled); |
| 152 | } |
Steven Rostedt | 606576c | 2008-10-06 19:06:12 -0400 | [diff] [blame] | 153 | #endif /* CONFIG_FUNCTION_TRACER */ |
Steven Rostedt | 81d68a9 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 154 | |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 155 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER |
Steven Rostedt (Red Hat) | 0390558 | 2015-09-28 15:37:49 -0400 | [diff] [blame] | 156 | static int irqsoff_display_graph(struct trace_array *tr, int set) |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 157 | { |
| 158 | int cpu; |
| 159 | |
Steven Rostedt (Red Hat) | 983f938 | 2015-09-30 09:42:05 -0400 | [diff] [blame] | 160 | if (!(is_graph(tr) ^ set)) |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 161 | return 0; |
| 162 | |
| 163 | stop_irqsoff_tracer(irqsoff_trace, !set); |
| 164 | |
| 165 | for_each_possible_cpu(cpu) |
| 166 | per_cpu(tracing_cpu, cpu) = 0; |
| 167 | |
Steven Rostedt (Red Hat) | 6d9b3fa | 2014-01-14 11:28:38 -0500 | [diff] [blame] | 168 | tr->max_latency = 0; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 169 | tracing_reset_online_cpus(&irqsoff_trace->trace_buffer); |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 170 | |
| 171 | return start_irqsoff_tracer(irqsoff_trace, set); |
| 172 | } |
| 173 | |
| 174 | static int irqsoff_graph_entry(struct ftrace_graph_ent *trace) |
| 175 | { |
| 176 | struct trace_array *tr = irqsoff_trace; |
| 177 | struct trace_array_cpu *data; |
| 178 | unsigned long flags; |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 179 | int ret; |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 180 | int pc; |
| 181 | |
Steven Rostedt (Red Hat) | 1a41442 | 2016-12-08 19:28:28 -0500 | [diff] [blame] | 182 | if (ftrace_graph_ignore_func(trace)) |
| 183 | return 0; |
| 184 | /* |
| 185 | * Do not trace a function if it's filtered by set_graph_notrace. |
| 186 | * Make the index of ret stack negative to indicate that it should |
| 187 | * ignore further functions. But it needs its own ret stack entry |
| 188 | * to recover the original index in order to continue tracing after |
| 189 | * returning from the function. |
| 190 | */ |
| 191 | if (ftrace_graph_notrace_addr(trace->func)) |
| 192 | return 1; |
| 193 | |
Steven Rostedt | 5e6d2b9 | 2010-10-05 19:41:43 -0400 | [diff] [blame] | 194 | if (!func_prolog_dec(tr, &data, &flags)) |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 195 | return 0; |
| 196 | |
Steven Rostedt | 5e6d2b9 | 2010-10-05 19:41:43 -0400 | [diff] [blame] | 197 | pc = preempt_count(); |
| 198 | ret = __trace_graph_entry(tr, trace, flags, pc); |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 199 | atomic_dec(&data->disabled); |
Steven Rostedt | 5e6d2b9 | 2010-10-05 19:41:43 -0400 | [diff] [blame] | 200 | |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 201 | return ret; |
| 202 | } |
| 203 | |
| 204 | static void irqsoff_graph_return(struct ftrace_graph_ret *trace) |
| 205 | { |
| 206 | struct trace_array *tr = irqsoff_trace; |
| 207 | struct trace_array_cpu *data; |
| 208 | unsigned long flags; |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 209 | int pc; |
| 210 | |
Steven Rostedt (VMware) | 5cf99a0f | 2018-11-29 08:50:27 -0500 | [diff] [blame] | 211 | ftrace_graph_addr_finish(trace); |
| 212 | |
Steven Rostedt | 5e6d2b9 | 2010-10-05 19:41:43 -0400 | [diff] [blame] | 213 | if (!func_prolog_dec(tr, &data, &flags)) |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 214 | return; |
| 215 | |
Steven Rostedt | 5e6d2b9 | 2010-10-05 19:41:43 -0400 | [diff] [blame] | 216 | pc = preempt_count(); |
| 217 | __trace_graph_return(tr, trace, flags, pc); |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 218 | atomic_dec(&data->disabled); |
| 219 | } |
| 220 | |
Steven Rostedt (VMware) | 688f708 | 2018-11-15 14:06:47 -0500 | [diff] [blame^] | 221 | static struct fgraph_ops fgraph_ops = { |
| 222 | .entryfunc = &irqsoff_graph_entry, |
| 223 | .retfunc = &irqsoff_graph_return, |
| 224 | }; |
| 225 | |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 226 | static void irqsoff_trace_open(struct trace_iterator *iter) |
| 227 | { |
Steven Rostedt (Red Hat) | 983f938 | 2015-09-30 09:42:05 -0400 | [diff] [blame] | 228 | if (is_graph(iter->tr)) |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 229 | graph_trace_open(iter); |
| 230 | |
| 231 | } |
| 232 | |
| 233 | static void irqsoff_trace_close(struct trace_iterator *iter) |
| 234 | { |
| 235 | if (iter->private) |
| 236 | graph_trace_close(iter); |
| 237 | } |
| 238 | |
| 239 | #define GRAPH_TRACER_FLAGS (TRACE_GRAPH_PRINT_CPU | \ |
Jiri Olsa | 321e68b | 2011-06-03 16:58:47 +0200 | [diff] [blame] | 240 | TRACE_GRAPH_PRINT_PROC | \ |
| 241 | TRACE_GRAPH_PRINT_ABS_TIME | \ |
| 242 | TRACE_GRAPH_PRINT_DURATION) |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 243 | |
| 244 | static enum print_line_t irqsoff_print_line(struct trace_iterator *iter) |
| 245 | { |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 246 | /* |
| 247 | * In graph mode call the graph tracer output function, |
| 248 | * otherwise go with the TRACE_FN event handler |
| 249 | */ |
Steven Rostedt (Red Hat) | 983f938 | 2015-09-30 09:42:05 -0400 | [diff] [blame] | 250 | if (is_graph(iter->tr)) |
Jiri Olsa | 0a77262 | 2010-09-23 14:00:52 +0200 | [diff] [blame] | 251 | return print_graph_function_flags(iter, GRAPH_TRACER_FLAGS); |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 252 | |
| 253 | return TRACE_TYPE_UNHANDLED; |
| 254 | } |
| 255 | |
| 256 | static void irqsoff_print_header(struct seq_file *s) |
| 257 | { |
Steven Rostedt (Red Hat) | 983f938 | 2015-09-30 09:42:05 -0400 | [diff] [blame] | 258 | struct trace_array *tr = irqsoff_trace; |
| 259 | |
| 260 | if (is_graph(tr)) |
Jiri Olsa | 0a77262 | 2010-09-23 14:00:52 +0200 | [diff] [blame] | 261 | print_graph_headers_flags(s, GRAPH_TRACER_FLAGS); |
| 262 | else |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 263 | trace_default_header(s); |
| 264 | } |
| 265 | |
| 266 | static void |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 267 | __trace_function(struct trace_array *tr, |
| 268 | unsigned long ip, unsigned long parent_ip, |
| 269 | unsigned long flags, int pc) |
| 270 | { |
Steven Rostedt (Red Hat) | 983f938 | 2015-09-30 09:42:05 -0400 | [diff] [blame] | 271 | if (is_graph(tr)) |
Jiri Olsa | 0a77262 | 2010-09-23 14:00:52 +0200 | [diff] [blame] | 272 | trace_graph_function(tr, ip, parent_ip, flags, pc); |
| 273 | else |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 274 | trace_function(tr, ip, parent_ip, flags, pc); |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | #else |
| 278 | #define __trace_function trace_function |
| 279 | |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 280 | static enum print_line_t irqsoff_print_line(struct trace_iterator *iter) |
| 281 | { |
| 282 | return TRACE_TYPE_UNHANDLED; |
| 283 | } |
| 284 | |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 285 | static void irqsoff_trace_open(struct trace_iterator *iter) { } |
| 286 | static void irqsoff_trace_close(struct trace_iterator *iter) { } |
Jiri Olsa | 7e9a49e | 2011-11-07 16:08:49 +0100 | [diff] [blame] | 287 | |
| 288 | #ifdef CONFIG_FUNCTION_TRACER |
| 289 | static void irqsoff_print_header(struct seq_file *s) |
| 290 | { |
| 291 | trace_default_header(s); |
| 292 | } |
| 293 | #else |
| 294 | static void irqsoff_print_header(struct seq_file *s) |
| 295 | { |
| 296 | trace_latency_header(s); |
| 297 | } |
| 298 | #endif /* CONFIG_FUNCTION_TRACER */ |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 299 | #endif /* CONFIG_FUNCTION_GRAPH_TRACER */ |
| 300 | |
Steven Rostedt | 81d68a9 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 301 | /* |
| 302 | * Should this new latency be reported/recorded? |
| 303 | */ |
Thomas Gleixner | a5a1d1c | 2016-12-21 20:32:01 +0100 | [diff] [blame] | 304 | static bool report_latency(struct trace_array *tr, u64 delta) |
Steven Rostedt | 81d68a9 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 305 | { |
| 306 | if (tracing_thresh) { |
| 307 | if (delta < tracing_thresh) |
Yaowei Bai | 7985182 | 2015-09-29 22:43:30 +0800 | [diff] [blame] | 308 | return false; |
Steven Rostedt | 81d68a9 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 309 | } else { |
Steven Rostedt (Red Hat) | 6d9b3fa | 2014-01-14 11:28:38 -0500 | [diff] [blame] | 310 | if (delta <= tr->max_latency) |
Yaowei Bai | 7985182 | 2015-09-29 22:43:30 +0800 | [diff] [blame] | 311 | return false; |
Steven Rostedt | 81d68a9 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 312 | } |
Yaowei Bai | 7985182 | 2015-09-29 22:43:30 +0800 | [diff] [blame] | 313 | return true; |
Steven Rostedt | 81d68a9 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 314 | } |
| 315 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 316 | static void |
Steven Rostedt | 81d68a9 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 317 | check_critical_timing(struct trace_array *tr, |
| 318 | struct trace_array_cpu *data, |
| 319 | unsigned long parent_ip, |
| 320 | int cpu) |
| 321 | { |
Thomas Gleixner | a5a1d1c | 2016-12-21 20:32:01 +0100 | [diff] [blame] | 322 | u64 T0, T1, delta; |
Steven Rostedt | 81d68a9 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 323 | unsigned long flags; |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 324 | int pc; |
Steven Rostedt | 81d68a9 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 325 | |
Steven Rostedt | 81d68a9 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 326 | T0 = data->preempt_timestamp; |
Ingo Molnar | 750ed1a | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 327 | T1 = ftrace_now(cpu); |
Steven Rostedt | 81d68a9 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 328 | delta = T1-T0; |
| 329 | |
| 330 | local_save_flags(flags); |
| 331 | |
Steven Rostedt | 6450c1d | 2008-10-02 19:23:04 -0400 | [diff] [blame] | 332 | pc = preempt_count(); |
| 333 | |
Steven Rostedt (Red Hat) | 6d9b3fa | 2014-01-14 11:28:38 -0500 | [diff] [blame] | 334 | if (!report_latency(tr, delta)) |
Steven Rostedt | 81d68a9 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 335 | goto out; |
| 336 | |
Thomas Gleixner | 5389f6f | 2009-07-25 17:13:33 +0200 | [diff] [blame] | 337 | raw_spin_lock_irqsave(&max_trace_lock, flags); |
Steven Rostedt | 81d68a9 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 338 | |
Steven Rostedt | 89b2f97 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 339 | /* check if we are still the max latency */ |
Steven Rostedt (Red Hat) | 6d9b3fa | 2014-01-14 11:28:38 -0500 | [diff] [blame] | 340 | if (!report_latency(tr, delta)) |
Steven Rostedt | 89b2f97 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 341 | goto out_unlock; |
| 342 | |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 343 | __trace_function(tr, CALLER_ADDR0, parent_ip, flags, pc); |
Steven Rostedt | cc51a0f | 2009-12-11 11:54:51 -0500 | [diff] [blame] | 344 | /* Skip 5 functions to get to the irq/preempt enable function */ |
| 345 | __trace_stack(tr, flags, 5, pc); |
Steven Rostedt | 81d68a9 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 346 | |
Steven Rostedt | 81d68a9 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 347 | if (data->critical_sequence != max_sequence) |
Steven Rostedt | 89b2f97 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 348 | goto out_unlock; |
Steven Rostedt | 81d68a9 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 349 | |
Steven Rostedt | 81d68a9 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 350 | data->critical_end = parent_ip; |
| 351 | |
Carsten Emde | b5130b1 | 2009-09-13 01:43:07 +0200 | [diff] [blame] | 352 | if (likely(!is_tracing_stopped())) { |
Steven Rostedt (Red Hat) | 6d9b3fa | 2014-01-14 11:28:38 -0500 | [diff] [blame] | 353 | tr->max_latency = delta; |
Carsten Emde | b5130b1 | 2009-09-13 01:43:07 +0200 | [diff] [blame] | 354 | update_max_tr_single(tr, current, cpu); |
| 355 | } |
Steven Rostedt | 81d68a9 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 356 | |
Steven Rostedt | 81d68a9 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 357 | max_sequence++; |
| 358 | |
Steven Rostedt | 89b2f97 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 359 | out_unlock: |
Thomas Gleixner | 5389f6f | 2009-07-25 17:13:33 +0200 | [diff] [blame] | 360 | raw_spin_unlock_irqrestore(&max_trace_lock, flags); |
Steven Rostedt | 89b2f97 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 361 | |
Steven Rostedt | 81d68a9 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 362 | out: |
| 363 | data->critical_sequence = max_sequence; |
Ingo Molnar | 750ed1a | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 364 | data->preempt_timestamp = ftrace_now(cpu); |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 365 | __trace_function(tr, CALLER_ADDR0, parent_ip, flags, pc); |
Steven Rostedt | 81d68a9 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 366 | } |
| 367 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 368 | static inline void |
Steven Rostedt (VMware) | f27107f | 2018-08-07 17:03:12 -0400 | [diff] [blame] | 369 | start_critical_timing(unsigned long ip, unsigned long parent_ip, int pc) |
Steven Rostedt | 81d68a9 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 370 | { |
| 371 | int cpu; |
| 372 | struct trace_array *tr = irqsoff_trace; |
| 373 | struct trace_array_cpu *data; |
| 374 | unsigned long flags; |
| 375 | |
Steven Rostedt (Red Hat) | 10246fa | 2013-07-01 15:58:24 -0400 | [diff] [blame] | 376 | if (!tracer_enabled || !tracing_is_enabled()) |
Steven Rostedt | 81d68a9 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 377 | return; |
| 378 | |
Steven Rostedt | c5f888c | 2008-05-12 21:20:55 +0200 | [diff] [blame] | 379 | cpu = raw_smp_processor_id(); |
| 380 | |
| 381 | if (per_cpu(tracing_cpu, cpu)) |
Steven Rostedt | 6cd8a4b | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 382 | return; |
| 383 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 384 | data = per_cpu_ptr(tr->trace_buffer.data, cpu); |
Steven Rostedt | 81d68a9 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 385 | |
Steven Rostedt | c5f888c | 2008-05-12 21:20:55 +0200 | [diff] [blame] | 386 | if (unlikely(!data) || atomic_read(&data->disabled)) |
Steven Rostedt | 81d68a9 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 387 | return; |
| 388 | |
| 389 | atomic_inc(&data->disabled); |
| 390 | |
| 391 | data->critical_sequence = max_sequence; |
Ingo Molnar | 750ed1a | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 392 | data->preempt_timestamp = ftrace_now(cpu); |
Steven Rostedt | 6cd8a4b | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 393 | data->critical_start = parent_ip ? : ip; |
Steven Rostedt | 81d68a9 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 394 | |
| 395 | local_save_flags(flags); |
Steven Rostedt | 6cd8a4b | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 396 | |
Steven Rostedt (VMware) | f27107f | 2018-08-07 17:03:12 -0400 | [diff] [blame] | 397 | __trace_function(tr, ip, parent_ip, flags, pc); |
Steven Rostedt | 81d68a9 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 398 | |
Steven Rostedt | c5f888c | 2008-05-12 21:20:55 +0200 | [diff] [blame] | 399 | per_cpu(tracing_cpu, cpu) = 1; |
Steven Rostedt | 6cd8a4b | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 400 | |
Steven Rostedt | 81d68a9 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 401 | atomic_dec(&data->disabled); |
| 402 | } |
| 403 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 404 | static inline void |
Steven Rostedt (VMware) | f27107f | 2018-08-07 17:03:12 -0400 | [diff] [blame] | 405 | stop_critical_timing(unsigned long ip, unsigned long parent_ip, int pc) |
Steven Rostedt | 81d68a9 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 406 | { |
| 407 | int cpu; |
| 408 | struct trace_array *tr = irqsoff_trace; |
| 409 | struct trace_array_cpu *data; |
| 410 | unsigned long flags; |
| 411 | |
Steven Rostedt | c5f888c | 2008-05-12 21:20:55 +0200 | [diff] [blame] | 412 | cpu = raw_smp_processor_id(); |
Steven Rostedt | 6cd8a4b | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 413 | /* Always clear the tracing cpu on stopping the trace */ |
Steven Rostedt | c5f888c | 2008-05-12 21:20:55 +0200 | [diff] [blame] | 414 | if (unlikely(per_cpu(tracing_cpu, cpu))) |
| 415 | per_cpu(tracing_cpu, cpu) = 0; |
Steven Rostedt | 6cd8a4b | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 416 | else |
| 417 | return; |
| 418 | |
Steven Rostedt (Red Hat) | 10246fa | 2013-07-01 15:58:24 -0400 | [diff] [blame] | 419 | if (!tracer_enabled || !tracing_is_enabled()) |
Steven Rostedt | 81d68a9 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 420 | return; |
| 421 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 422 | data = per_cpu_ptr(tr->trace_buffer.data, cpu); |
Steven Rostedt | 81d68a9 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 423 | |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 424 | if (unlikely(!data) || |
Steven Rostedt | 81d68a9 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 425 | !data->critical_start || atomic_read(&data->disabled)) |
| 426 | return; |
| 427 | |
| 428 | atomic_inc(&data->disabled); |
Steven Rostedt | c5f888c | 2008-05-12 21:20:55 +0200 | [diff] [blame] | 429 | |
Steven Rostedt | 81d68a9 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 430 | local_save_flags(flags); |
Steven Rostedt (VMware) | f27107f | 2018-08-07 17:03:12 -0400 | [diff] [blame] | 431 | __trace_function(tr, ip, parent_ip, flags, pc); |
Steven Rostedt | 6cd8a4b | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 432 | check_critical_timing(tr, data, parent_ip ? : ip, cpu); |
Steven Rostedt | 81d68a9 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 433 | data->critical_start = 0; |
| 434 | atomic_dec(&data->disabled); |
| 435 | } |
| 436 | |
Steven Rostedt | 6cd8a4b | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 437 | /* start and stop critical timings used to for stoppage (in idle) */ |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 438 | void start_critical_timings(void) |
Steven Rostedt | 81d68a9 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 439 | { |
Steven Rostedt (VMware) | f27107f | 2018-08-07 17:03:12 -0400 | [diff] [blame] | 440 | int pc = preempt_count(); |
| 441 | |
| 442 | if (preempt_trace(pc) || irq_trace()) |
| 443 | start_critical_timing(CALLER_ADDR0, CALLER_ADDR1, pc); |
Steven Rostedt | 81d68a9 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 444 | } |
Ingo Molnar | 1fe3710 | 2008-07-26 15:09:47 +0200 | [diff] [blame] | 445 | EXPORT_SYMBOL_GPL(start_critical_timings); |
Steven Rostedt | 81d68a9 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 446 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 447 | void stop_critical_timings(void) |
Steven Rostedt | 81d68a9 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 448 | { |
Steven Rostedt (VMware) | f27107f | 2018-08-07 17:03:12 -0400 | [diff] [blame] | 449 | int pc = preempt_count(); |
| 450 | |
| 451 | if (preempt_trace(pc) || irq_trace()) |
| 452 | stop_critical_timing(CALLER_ADDR0, CALLER_ADDR1, pc); |
Steven Rostedt | 81d68a9 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 453 | } |
Ingo Molnar | 1fe3710 | 2008-07-26 15:09:47 +0200 | [diff] [blame] | 454 | EXPORT_SYMBOL_GPL(stop_critical_timings); |
Steven Rostedt | 81d68a9 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 455 | |
Steven Rostedt (Red Hat) | 8179e8a | 2015-09-29 10:24:56 -0400 | [diff] [blame] | 456 | #ifdef CONFIG_FUNCTION_TRACER |
| 457 | static bool function_enabled; |
| 458 | |
Steven Rostedt (Red Hat) | 4104d32 | 2014-01-10 17:01:58 -0500 | [diff] [blame] | 459 | static int register_irqsoff_function(struct trace_array *tr, int graph, int set) |
Steven Rostedt | 81d68a9 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 460 | { |
Steven Rostedt (Red Hat) | 328df47 | 2013-03-14 12:10:40 -0400 | [diff] [blame] | 461 | int ret; |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 462 | |
Steven Rostedt (Red Hat) | 328df47 | 2013-03-14 12:10:40 -0400 | [diff] [blame] | 463 | /* 'set' is set if TRACE_ITER_FUNCTION is about to be set */ |
Steven Rostedt (Red Hat) | 983f938 | 2015-09-30 09:42:05 -0400 | [diff] [blame] | 464 | if (function_enabled || (!set && !(tr->trace_flags & TRACE_ITER_FUNCTION))) |
Steven Rostedt (Red Hat) | 328df47 | 2013-03-14 12:10:40 -0400 | [diff] [blame] | 465 | return 0; |
| 466 | |
| 467 | if (graph) |
Steven Rostedt (VMware) | 688f708 | 2018-11-15 14:06:47 -0500 | [diff] [blame^] | 468 | ret = register_ftrace_graph(&fgraph_ops); |
Steven Rostedt (Red Hat) | 328df47 | 2013-03-14 12:10:40 -0400 | [diff] [blame] | 469 | else |
Steven Rostedt (Red Hat) | 4104d32 | 2014-01-10 17:01:58 -0500 | [diff] [blame] | 470 | ret = register_ftrace_function(tr->ops); |
Steven Rostedt (Red Hat) | 328df47 | 2013-03-14 12:10:40 -0400 | [diff] [blame] | 471 | |
| 472 | if (!ret) |
| 473 | function_enabled = true; |
| 474 | |
| 475 | return ret; |
| 476 | } |
| 477 | |
Steven Rostedt (Red Hat) | 4104d32 | 2014-01-10 17:01:58 -0500 | [diff] [blame] | 478 | static void unregister_irqsoff_function(struct trace_array *tr, int graph) |
Steven Rostedt (Red Hat) | 328df47 | 2013-03-14 12:10:40 -0400 | [diff] [blame] | 479 | { |
| 480 | if (!function_enabled) |
| 481 | return; |
| 482 | |
| 483 | if (graph) |
Steven Rostedt (VMware) | 688f708 | 2018-11-15 14:06:47 -0500 | [diff] [blame^] | 484 | unregister_ftrace_graph(&fgraph_ops); |
Steven Rostedt (Red Hat) | 328df47 | 2013-03-14 12:10:40 -0400 | [diff] [blame] | 485 | else |
Steven Rostedt (Red Hat) | 4104d32 | 2014-01-10 17:01:58 -0500 | [diff] [blame] | 486 | unregister_ftrace_function(tr->ops); |
Steven Rostedt (Red Hat) | 328df47 | 2013-03-14 12:10:40 -0400 | [diff] [blame] | 487 | |
| 488 | function_enabled = false; |
| 489 | } |
| 490 | |
Steven Rostedt (Red Hat) | 8179e8a | 2015-09-29 10:24:56 -0400 | [diff] [blame] | 491 | static int irqsoff_function_set(struct trace_array *tr, u32 mask, int set) |
Steven Rostedt (Red Hat) | 328df47 | 2013-03-14 12:10:40 -0400 | [diff] [blame] | 492 | { |
Steven Rostedt (Red Hat) | 8179e8a | 2015-09-29 10:24:56 -0400 | [diff] [blame] | 493 | if (!(mask & TRACE_ITER_FUNCTION)) |
| 494 | return 0; |
| 495 | |
Steven Rostedt (Red Hat) | 328df47 | 2013-03-14 12:10:40 -0400 | [diff] [blame] | 496 | if (set) |
Steven Rostedt (Red Hat) | 983f938 | 2015-09-30 09:42:05 -0400 | [diff] [blame] | 497 | register_irqsoff_function(tr, is_graph(tr), 1); |
Steven Rostedt (Red Hat) | 328df47 | 2013-03-14 12:10:40 -0400 | [diff] [blame] | 498 | else |
Steven Rostedt (Red Hat) | 983f938 | 2015-09-30 09:42:05 -0400 | [diff] [blame] | 499 | unregister_irqsoff_function(tr, is_graph(tr)); |
Steven Rostedt (Red Hat) | 8179e8a | 2015-09-29 10:24:56 -0400 | [diff] [blame] | 500 | return 1; |
| 501 | } |
| 502 | #else |
| 503 | static int register_irqsoff_function(struct trace_array *tr, int graph, int set) |
| 504 | { |
Steven Rostedt (Red Hat) | 0390558 | 2015-09-28 15:37:49 -0400 | [diff] [blame] | 505 | return 0; |
Steven Rostedt (Red Hat) | 328df47 | 2013-03-14 12:10:40 -0400 | [diff] [blame] | 506 | } |
Steven Rostedt (Red Hat) | 8179e8a | 2015-09-29 10:24:56 -0400 | [diff] [blame] | 507 | static void unregister_irqsoff_function(struct trace_array *tr, int graph) { } |
| 508 | static inline int irqsoff_function_set(struct trace_array *tr, u32 mask, int set) |
| 509 | { |
| 510 | return 0; |
| 511 | } |
| 512 | #endif /* CONFIG_FUNCTION_TRACER */ |
Steven Rostedt (Red Hat) | 328df47 | 2013-03-14 12:10:40 -0400 | [diff] [blame] | 513 | |
Steven Rostedt (Red Hat) | bf6065b | 2014-01-10 17:51:01 -0500 | [diff] [blame] | 514 | static int irqsoff_flag_changed(struct trace_array *tr, u32 mask, int set) |
Steven Rostedt (Red Hat) | 328df47 | 2013-03-14 12:10:40 -0400 | [diff] [blame] | 515 | { |
Steven Rostedt (Red Hat) | bf6065b | 2014-01-10 17:51:01 -0500 | [diff] [blame] | 516 | struct tracer *tracer = tr->current_trace; |
| 517 | |
Steven Rostedt (Red Hat) | 8179e8a | 2015-09-29 10:24:56 -0400 | [diff] [blame] | 518 | if (irqsoff_function_set(tr, mask, set)) |
| 519 | return 0; |
Steven Rostedt (Red Hat) | 0390558 | 2015-09-28 15:37:49 -0400 | [diff] [blame] | 520 | |
Steven Rostedt (Red Hat) | 729358d | 2015-09-29 10:15:10 -0400 | [diff] [blame] | 521 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER |
Steven Rostedt (Red Hat) | 0390558 | 2015-09-28 15:37:49 -0400 | [diff] [blame] | 522 | if (mask & TRACE_ITER_DISPLAY_GRAPH) |
| 523 | return irqsoff_display_graph(tr, set); |
Steven Rostedt (Red Hat) | 729358d | 2015-09-29 10:15:10 -0400 | [diff] [blame] | 524 | #endif |
Steven Rostedt (Red Hat) | 328df47 | 2013-03-14 12:10:40 -0400 | [diff] [blame] | 525 | |
| 526 | return trace_keep_overwrite(tracer, mask, set); |
| 527 | } |
| 528 | |
| 529 | static int start_irqsoff_tracer(struct trace_array *tr, int graph) |
| 530 | { |
| 531 | int ret; |
| 532 | |
Steven Rostedt (Red Hat) | 4104d32 | 2014-01-10 17:01:58 -0500 | [diff] [blame] | 533 | ret = register_irqsoff_function(tr, graph, 0); |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 534 | |
| 535 | if (!ret && tracing_is_enabled()) |
Steven Rostedt | 9036990 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 536 | tracer_enabled = 1; |
Steven Rostedt | 94523e8 | 2009-01-22 11:18:06 -0500 | [diff] [blame] | 537 | else |
Steven Rostedt | 9036990 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 538 | tracer_enabled = 0; |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 539 | |
| 540 | return ret; |
Steven Rostedt | 81d68a9 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 541 | } |
| 542 | |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 543 | static void stop_irqsoff_tracer(struct trace_array *tr, int graph) |
Steven Rostedt | 81d68a9 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 544 | { |
Steven Rostedt | 81d68a9 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 545 | tracer_enabled = 0; |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 546 | |
Steven Rostedt (Red Hat) | 4104d32 | 2014-01-10 17:01:58 -0500 | [diff] [blame] | 547 | unregister_irqsoff_function(tr, graph); |
Steven Rostedt | 81d68a9 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 548 | } |
| 549 | |
Steven Rostedt (Red Hat) | 02f2f76 | 2014-01-14 09:32:58 -0500 | [diff] [blame] | 550 | static bool irqsoff_busy; |
| 551 | |
| 552 | static int __irqsoff_tracer_init(struct trace_array *tr) |
Steven Rostedt | 81d68a9 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 553 | { |
Steven Rostedt (Red Hat) | 02f2f76 | 2014-01-14 09:32:58 -0500 | [diff] [blame] | 554 | if (irqsoff_busy) |
| 555 | return -EBUSY; |
| 556 | |
Steven Rostedt (Red Hat) | 983f938 | 2015-09-30 09:42:05 -0400 | [diff] [blame] | 557 | save_flags = tr->trace_flags; |
Steven Rostedt (Red Hat) | 613f04a | 2013-03-14 15:03:53 -0400 | [diff] [blame] | 558 | |
| 559 | /* non overwrite screws up the latency tracers */ |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 560 | set_tracer_flag(tr, TRACE_ITER_OVERWRITE, 1); |
| 561 | set_tracer_flag(tr, TRACE_ITER_LATENCY_FMT, 1); |
Steven Rostedt | e9d25fe | 2009-03-04 22:15:30 -0500 | [diff] [blame] | 562 | |
Steven Rostedt (Red Hat) | 6d9b3fa | 2014-01-14 11:28:38 -0500 | [diff] [blame] | 563 | tr->max_latency = 0; |
Steven Rostedt | 81d68a9 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 564 | irqsoff_trace = tr; |
Steven Rostedt | c5f888c | 2008-05-12 21:20:55 +0200 | [diff] [blame] | 565 | /* make sure that the tracer is visible */ |
Steven Rostedt | 81d68a9 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 566 | smp_wmb(); |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 567 | |
Steven Rostedt (Red Hat) | 4104d32 | 2014-01-10 17:01:58 -0500 | [diff] [blame] | 568 | ftrace_init_array_ops(tr, irqsoff_tracer_call); |
| 569 | |
| 570 | /* Only toplevel instance supports graph tracing */ |
| 571 | if (start_irqsoff_tracer(tr, (tr->flags & TRACE_ARRAY_FL_GLOBAL && |
Steven Rostedt (Red Hat) | 983f938 | 2015-09-30 09:42:05 -0400 | [diff] [blame] | 572 | is_graph(tr)))) |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 573 | printk(KERN_ERR "failed to start irqsoff tracer\n"); |
Steven Rostedt (Red Hat) | 02f2f76 | 2014-01-14 09:32:58 -0500 | [diff] [blame] | 574 | |
| 575 | irqsoff_busy = true; |
| 576 | return 0; |
Steven Rostedt | 81d68a9 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 577 | } |
| 578 | |
Joel Fernandes (Google) | 2b27ece | 2018-06-28 11:21:45 -0700 | [diff] [blame] | 579 | static void __irqsoff_tracer_reset(struct trace_array *tr) |
Steven Rostedt | 81d68a9 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 580 | { |
Steven Rostedt (Red Hat) | 613f04a | 2013-03-14 15:03:53 -0400 | [diff] [blame] | 581 | int lat_flag = save_flags & TRACE_ITER_LATENCY_FMT; |
| 582 | int overwrite_flag = save_flags & TRACE_ITER_OVERWRITE; |
| 583 | |
Steven Rostedt (Red Hat) | 983f938 | 2015-09-30 09:42:05 -0400 | [diff] [blame] | 584 | stop_irqsoff_tracer(tr, is_graph(tr)); |
Steven Rostedt | e9d25fe | 2009-03-04 22:15:30 -0500 | [diff] [blame] | 585 | |
Steven Rostedt | 2b6080f | 2012-05-11 13:29:49 -0400 | [diff] [blame] | 586 | set_tracer_flag(tr, TRACE_ITER_LATENCY_FMT, lat_flag); |
| 587 | set_tracer_flag(tr, TRACE_ITER_OVERWRITE, overwrite_flag); |
Steven Rostedt (Red Hat) | 4104d32 | 2014-01-10 17:01:58 -0500 | [diff] [blame] | 588 | ftrace_reset_array_ops(tr); |
Steven Rostedt (Red Hat) | 02f2f76 | 2014-01-14 09:32:58 -0500 | [diff] [blame] | 589 | |
| 590 | irqsoff_busy = false; |
Steven Rostedt | 81d68a9 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 591 | } |
| 592 | |
Steven Rostedt | 9036990 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 593 | static void irqsoff_tracer_start(struct trace_array *tr) |
| 594 | { |
Steven Rostedt | 9036990 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 595 | tracer_enabled = 1; |
Steven Rostedt | 9036990 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 596 | } |
| 597 | |
| 598 | static void irqsoff_tracer_stop(struct trace_array *tr) |
| 599 | { |
| 600 | tracer_enabled = 0; |
Steven Rostedt | 81d68a9 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 601 | } |
| 602 | |
Steven Rostedt | 6cd8a4b | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 603 | #ifdef CONFIG_IRQSOFF_TRACER |
Joel Fernandes (Google) | c3bc8fd | 2018-07-30 15:24:23 -0700 | [diff] [blame] | 604 | /* |
| 605 | * We are only interested in hardirq on/off events: |
| 606 | */ |
Steven Rostedt (VMware) | 3f1756d | 2018-08-08 21:28:05 -0400 | [diff] [blame] | 607 | void tracer_hardirqs_on(unsigned long a0, unsigned long a1) |
Joel Fernandes (Google) | c3bc8fd | 2018-07-30 15:24:23 -0700 | [diff] [blame] | 608 | { |
Steven Rostedt (VMware) | f27107f | 2018-08-07 17:03:12 -0400 | [diff] [blame] | 609 | unsigned int pc = preempt_count(); |
| 610 | |
Steven Rostedt (VMware) | f27107f | 2018-08-07 17:03:12 -0400 | [diff] [blame] | 611 | if (!preempt_trace(pc) && irq_trace()) |
| 612 | stop_critical_timing(a0, a1, pc); |
Joel Fernandes (Google) | c3bc8fd | 2018-07-30 15:24:23 -0700 | [diff] [blame] | 613 | } |
| 614 | |
Steven Rostedt (VMware) | 3f1756d | 2018-08-08 21:28:05 -0400 | [diff] [blame] | 615 | void tracer_hardirqs_off(unsigned long a0, unsigned long a1) |
Joel Fernandes (Google) | c3bc8fd | 2018-07-30 15:24:23 -0700 | [diff] [blame] | 616 | { |
Steven Rostedt (VMware) | f27107f | 2018-08-07 17:03:12 -0400 | [diff] [blame] | 617 | unsigned int pc = preempt_count(); |
| 618 | |
Steven Rostedt (VMware) | f27107f | 2018-08-07 17:03:12 -0400 | [diff] [blame] | 619 | if (!preempt_trace(pc) && irq_trace()) |
| 620 | start_critical_timing(a0, a1, pc); |
Joel Fernandes (Google) | c3bc8fd | 2018-07-30 15:24:23 -0700 | [diff] [blame] | 621 | } |
| 622 | |
Frederic Weisbecker | 1c80025 | 2008-11-16 05:57:26 +0100 | [diff] [blame] | 623 | static int irqsoff_tracer_init(struct trace_array *tr) |
Steven Rostedt | 6cd8a4b | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 624 | { |
| 625 | trace_type = TRACER_IRQS_OFF; |
| 626 | |
Steven Rostedt (Red Hat) | 02f2f76 | 2014-01-14 09:32:58 -0500 | [diff] [blame] | 627 | return __irqsoff_tracer_init(tr); |
Steven Rostedt | 6cd8a4b | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 628 | } |
Joel Fernandes (Google) | 2b27ece | 2018-06-28 11:21:45 -0700 | [diff] [blame] | 629 | |
| 630 | static void irqsoff_tracer_reset(struct trace_array *tr) |
| 631 | { |
| 632 | __irqsoff_tracer_reset(tr); |
| 633 | } |
| 634 | |
Steven Rostedt | 81d68a9 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 635 | static struct tracer irqsoff_tracer __read_mostly = |
| 636 | { |
| 637 | .name = "irqsoff", |
| 638 | .init = irqsoff_tracer_init, |
| 639 | .reset = irqsoff_tracer_reset, |
Steven Rostedt | 9036990 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 640 | .start = irqsoff_tracer_start, |
| 641 | .stop = irqsoff_tracer_stop, |
Hiraku Toyooka | f43c738 | 2012-10-02 17:27:10 +0900 | [diff] [blame] | 642 | .print_max = true, |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 643 | .print_header = irqsoff_print_header, |
| 644 | .print_line = irqsoff_print_line, |
Steven Rostedt (Red Hat) | 328df47 | 2013-03-14 12:10:40 -0400 | [diff] [blame] | 645 | .flag_changed = irqsoff_flag_changed, |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 646 | #ifdef CONFIG_FTRACE_SELFTEST |
| 647 | .selftest = trace_selftest_startup_irqsoff, |
| 648 | #endif |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 649 | .open = irqsoff_trace_open, |
| 650 | .close = irqsoff_trace_close, |
Steven Rostedt (Red Hat) | 02f2f76 | 2014-01-14 09:32:58 -0500 | [diff] [blame] | 651 | .allow_instances = true, |
Hiraku Toyooka | f43c738 | 2012-10-02 17:27:10 +0900 | [diff] [blame] | 652 | .use_max_tr = true, |
Steven Rostedt | 81d68a9 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 653 | }; |
Joel Fernandes (Google) | c3bc8fd | 2018-07-30 15:24:23 -0700 | [diff] [blame] | 654 | #endif /* CONFIG_IRQSOFF_TRACER */ |
Steven Rostedt | 6cd8a4b | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 655 | |
| 656 | #ifdef CONFIG_PREEMPT_TRACER |
Steven Rostedt (VMware) | 3f1756d | 2018-08-08 21:28:05 -0400 | [diff] [blame] | 657 | void tracer_preempt_on(unsigned long a0, unsigned long a1) |
Joel Fernandes (Google) | c3bc8fd | 2018-07-30 15:24:23 -0700 | [diff] [blame] | 658 | { |
Steven Rostedt (VMware) | f27107f | 2018-08-07 17:03:12 -0400 | [diff] [blame] | 659 | int pc = preempt_count(); |
| 660 | |
| 661 | if (preempt_trace(pc) && !irq_trace()) |
| 662 | stop_critical_timing(a0, a1, pc); |
Joel Fernandes (Google) | c3bc8fd | 2018-07-30 15:24:23 -0700 | [diff] [blame] | 663 | } |
| 664 | |
Steven Rostedt (VMware) | 3f1756d | 2018-08-08 21:28:05 -0400 | [diff] [blame] | 665 | void tracer_preempt_off(unsigned long a0, unsigned long a1) |
Joel Fernandes (Google) | c3bc8fd | 2018-07-30 15:24:23 -0700 | [diff] [blame] | 666 | { |
Steven Rostedt (VMware) | f27107f | 2018-08-07 17:03:12 -0400 | [diff] [blame] | 667 | int pc = preempt_count(); |
| 668 | |
| 669 | if (preempt_trace(pc) && !irq_trace()) |
| 670 | start_critical_timing(a0, a1, pc); |
Joel Fernandes (Google) | c3bc8fd | 2018-07-30 15:24:23 -0700 | [diff] [blame] | 671 | } |
| 672 | |
Frederic Weisbecker | 1c80025 | 2008-11-16 05:57:26 +0100 | [diff] [blame] | 673 | static int preemptoff_tracer_init(struct trace_array *tr) |
Steven Rostedt | 6cd8a4b | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 674 | { |
| 675 | trace_type = TRACER_PREEMPT_OFF; |
| 676 | |
Steven Rostedt (Red Hat) | 02f2f76 | 2014-01-14 09:32:58 -0500 | [diff] [blame] | 677 | return __irqsoff_tracer_init(tr); |
Steven Rostedt | 6cd8a4b | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 678 | } |
| 679 | |
Joel Fernandes (Google) | 2b27ece | 2018-06-28 11:21:45 -0700 | [diff] [blame] | 680 | static void preemptoff_tracer_reset(struct trace_array *tr) |
| 681 | { |
| 682 | __irqsoff_tracer_reset(tr); |
| 683 | } |
| 684 | |
Steven Rostedt | 6cd8a4b | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 685 | static struct tracer preemptoff_tracer __read_mostly = |
| 686 | { |
| 687 | .name = "preemptoff", |
| 688 | .init = preemptoff_tracer_init, |
Joel Fernandes (Google) | 2b27ece | 2018-06-28 11:21:45 -0700 | [diff] [blame] | 689 | .reset = preemptoff_tracer_reset, |
Steven Rostedt | 9036990 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 690 | .start = irqsoff_tracer_start, |
| 691 | .stop = irqsoff_tracer_stop, |
Hiraku Toyooka | f43c738 | 2012-10-02 17:27:10 +0900 | [diff] [blame] | 692 | .print_max = true, |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 693 | .print_header = irqsoff_print_header, |
| 694 | .print_line = irqsoff_print_line, |
Steven Rostedt (Red Hat) | 328df47 | 2013-03-14 12:10:40 -0400 | [diff] [blame] | 695 | .flag_changed = irqsoff_flag_changed, |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 696 | #ifdef CONFIG_FTRACE_SELFTEST |
| 697 | .selftest = trace_selftest_startup_preemptoff, |
| 698 | #endif |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 699 | .open = irqsoff_trace_open, |
| 700 | .close = irqsoff_trace_close, |
Steven Rostedt (Red Hat) | 02f2f76 | 2014-01-14 09:32:58 -0500 | [diff] [blame] | 701 | .allow_instances = true, |
Hiraku Toyooka | f43c738 | 2012-10-02 17:27:10 +0900 | [diff] [blame] | 702 | .use_max_tr = true, |
Steven Rostedt | 6cd8a4b | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 703 | }; |
Joel Fernandes (Google) | c3bc8fd | 2018-07-30 15:24:23 -0700 | [diff] [blame] | 704 | #endif /* CONFIG_PREEMPT_TRACER */ |
Steven Rostedt | 6cd8a4b | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 705 | |
Joel Fernandes (Google) | c3bc8fd | 2018-07-30 15:24:23 -0700 | [diff] [blame] | 706 | #if defined(CONFIG_IRQSOFF_TRACER) && defined(CONFIG_PREEMPT_TRACER) |
Steven Rostedt | 6cd8a4b | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 707 | |
Frederic Weisbecker | 1c80025 | 2008-11-16 05:57:26 +0100 | [diff] [blame] | 708 | static int preemptirqsoff_tracer_init(struct trace_array *tr) |
Steven Rostedt | 6cd8a4b | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 709 | { |
| 710 | trace_type = TRACER_IRQS_OFF | TRACER_PREEMPT_OFF; |
| 711 | |
Steven Rostedt (Red Hat) | 02f2f76 | 2014-01-14 09:32:58 -0500 | [diff] [blame] | 712 | return __irqsoff_tracer_init(tr); |
Steven Rostedt | 6cd8a4b | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 713 | } |
| 714 | |
Joel Fernandes (Google) | 2b27ece | 2018-06-28 11:21:45 -0700 | [diff] [blame] | 715 | static void preemptirqsoff_tracer_reset(struct trace_array *tr) |
| 716 | { |
| 717 | __irqsoff_tracer_reset(tr); |
| 718 | } |
| 719 | |
Steven Rostedt | 6cd8a4b | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 720 | static struct tracer preemptirqsoff_tracer __read_mostly = |
| 721 | { |
| 722 | .name = "preemptirqsoff", |
| 723 | .init = preemptirqsoff_tracer_init, |
Joel Fernandes (Google) | 2b27ece | 2018-06-28 11:21:45 -0700 | [diff] [blame] | 724 | .reset = preemptirqsoff_tracer_reset, |
Steven Rostedt | 9036990 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 725 | .start = irqsoff_tracer_start, |
| 726 | .stop = irqsoff_tracer_stop, |
Hiraku Toyooka | f43c738 | 2012-10-02 17:27:10 +0900 | [diff] [blame] | 727 | .print_max = true, |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 728 | .print_header = irqsoff_print_header, |
| 729 | .print_line = irqsoff_print_line, |
Steven Rostedt (Red Hat) | 328df47 | 2013-03-14 12:10:40 -0400 | [diff] [blame] | 730 | .flag_changed = irqsoff_flag_changed, |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 731 | #ifdef CONFIG_FTRACE_SELFTEST |
| 732 | .selftest = trace_selftest_startup_preemptirqsoff, |
| 733 | #endif |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 734 | .open = irqsoff_trace_open, |
| 735 | .close = irqsoff_trace_close, |
Steven Rostedt (Red Hat) | 02f2f76 | 2014-01-14 09:32:58 -0500 | [diff] [blame] | 736 | .allow_instances = true, |
Hiraku Toyooka | f43c738 | 2012-10-02 17:27:10 +0900 | [diff] [blame] | 737 | .use_max_tr = true, |
Steven Rostedt | 6cd8a4b | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 738 | }; |
Steven Rostedt | 6cd8a4b | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 739 | #endif |
Steven Rostedt | 81d68a9 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 740 | |
| 741 | __init static int init_irqsoff_tracer(void) |
| 742 | { |
Joel Fernandes (Google) | c3bc8fd | 2018-07-30 15:24:23 -0700 | [diff] [blame] | 743 | #ifdef CONFIG_IRQSOFF_TRACER |
| 744 | register_tracer(&irqsoff_tracer); |
| 745 | #endif |
| 746 | #ifdef CONFIG_PREEMPT_TRACER |
| 747 | register_tracer(&preemptoff_tracer); |
| 748 | #endif |
| 749 | #if defined(CONFIG_IRQSOFF_TRACER) && defined(CONFIG_PREEMPT_TRACER) |
| 750 | register_tracer(&preemptirqsoff_tracer); |
| 751 | #endif |
Steven Rostedt | 81d68a9 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 752 | |
| 753 | return 0; |
| 754 | } |
Steven Rostedt | 6f41567 | 2012-10-05 12:13:07 -0400 | [diff] [blame] | 755 | core_initcall(init_irqsoff_tracer); |
Joel Fernandes | aaecaa0 | 2017-10-05 17:54:31 -0700 | [diff] [blame] | 756 | #endif /* IRQSOFF_TRACER || PREEMPTOFF_TRACER */ |