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