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