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 | } | |
606576ce | 154 | #endif /* CONFIG_FUNCTION_TRACER */ |
81d68a96 | 155 | |
62b915f1 | 156 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER |
8c1a49ae SRRH |
157 | static int |
158 | irqsoff_set_flag(struct trace_array *tr, u32 old_flags, u32 bit, int set) | |
62b915f1 JO |
159 | { |
160 | int cpu; | |
161 | ||
162 | if (!(bit & TRACE_DISPLAY_GRAPH)) | |
163 | return -EINVAL; | |
164 | ||
165 | if (!(is_graph() ^ set)) | |
166 | return 0; | |
167 | ||
168 | stop_irqsoff_tracer(irqsoff_trace, !set); | |
169 | ||
170 | for_each_possible_cpu(cpu) | |
171 | per_cpu(tracing_cpu, cpu) = 0; | |
172 | ||
6d9b3fa5 | 173 | tr->max_latency = 0; |
12883efb | 174 | tracing_reset_online_cpus(&irqsoff_trace->trace_buffer); |
62b915f1 JO |
175 | |
176 | return start_irqsoff_tracer(irqsoff_trace, set); | |
177 | } | |
178 | ||
179 | static int irqsoff_graph_entry(struct ftrace_graph_ent *trace) | |
180 | { | |
181 | struct trace_array *tr = irqsoff_trace; | |
182 | struct trace_array_cpu *data; | |
183 | unsigned long flags; | |
62b915f1 | 184 | int ret; |
62b915f1 JO |
185 | int pc; |
186 | ||
5e6d2b9c | 187 | if (!func_prolog_dec(tr, &data, &flags)) |
62b915f1 JO |
188 | return 0; |
189 | ||
5e6d2b9c SR |
190 | pc = preempt_count(); |
191 | ret = __trace_graph_entry(tr, trace, flags, pc); | |
62b915f1 | 192 | atomic_dec(&data->disabled); |
5e6d2b9c | 193 | |
62b915f1 JO |
194 | return ret; |
195 | } | |
196 | ||
197 | static void irqsoff_graph_return(struct ftrace_graph_ret *trace) | |
198 | { | |
199 | struct trace_array *tr = irqsoff_trace; | |
200 | struct trace_array_cpu *data; | |
201 | unsigned long flags; | |
62b915f1 JO |
202 | int pc; |
203 | ||
5e6d2b9c | 204 | if (!func_prolog_dec(tr, &data, &flags)) |
62b915f1 JO |
205 | return; |
206 | ||
5e6d2b9c SR |
207 | pc = preempt_count(); |
208 | __trace_graph_return(tr, trace, flags, pc); | |
62b915f1 JO |
209 | atomic_dec(&data->disabled); |
210 | } | |
211 | ||
212 | static void irqsoff_trace_open(struct trace_iterator *iter) | |
213 | { | |
214 | if (is_graph()) | |
215 | graph_trace_open(iter); | |
216 | ||
217 | } | |
218 | ||
219 | static void irqsoff_trace_close(struct trace_iterator *iter) | |
220 | { | |
221 | if (iter->private) | |
222 | graph_trace_close(iter); | |
223 | } | |
224 | ||
225 | #define GRAPH_TRACER_FLAGS (TRACE_GRAPH_PRINT_CPU | \ | |
321e68b0 JO |
226 | TRACE_GRAPH_PRINT_PROC | \ |
227 | TRACE_GRAPH_PRINT_ABS_TIME | \ | |
228 | TRACE_GRAPH_PRINT_DURATION) | |
62b915f1 JO |
229 | |
230 | static enum print_line_t irqsoff_print_line(struct trace_iterator *iter) | |
231 | { | |
62b915f1 JO |
232 | /* |
233 | * In graph mode call the graph tracer output function, | |
234 | * otherwise go with the TRACE_FN event handler | |
235 | */ | |
236 | if (is_graph()) | |
0a772620 | 237 | return print_graph_function_flags(iter, GRAPH_TRACER_FLAGS); |
62b915f1 JO |
238 | |
239 | return TRACE_TYPE_UNHANDLED; | |
240 | } | |
241 | ||
242 | static void irqsoff_print_header(struct seq_file *s) | |
243 | { | |
0a772620 JO |
244 | if (is_graph()) |
245 | print_graph_headers_flags(s, GRAPH_TRACER_FLAGS); | |
246 | else | |
62b915f1 JO |
247 | trace_default_header(s); |
248 | } | |
249 | ||
62b915f1 JO |
250 | static void |
251 | __trace_function(struct trace_array *tr, | |
252 | unsigned long ip, unsigned long parent_ip, | |
253 | unsigned long flags, int pc) | |
254 | { | |
0a772620 JO |
255 | if (is_graph()) |
256 | trace_graph_function(tr, ip, parent_ip, flags, pc); | |
257 | else | |
62b915f1 | 258 | trace_function(tr, ip, parent_ip, flags, pc); |
62b915f1 JO |
259 | } |
260 | ||
261 | #else | |
262 | #define __trace_function trace_function | |
263 | ||
8c1a49ae SRRH |
264 | static int |
265 | irqsoff_set_flag(struct trace_array *tr, u32 old_flags, u32 bit, int set) | |
62b915f1 JO |
266 | { |
267 | return -EINVAL; | |
268 | } | |
269 | ||
270 | static int irqsoff_graph_entry(struct ftrace_graph_ent *trace) | |
271 | { | |
272 | return -1; | |
273 | } | |
274 | ||
275 | static enum print_line_t irqsoff_print_line(struct trace_iterator *iter) | |
276 | { | |
277 | return TRACE_TYPE_UNHANDLED; | |
278 | } | |
279 | ||
280 | static void irqsoff_graph_return(struct ftrace_graph_ret *trace) { } | |
62b915f1 JO |
281 | static void irqsoff_trace_open(struct trace_iterator *iter) { } |
282 | static void irqsoff_trace_close(struct trace_iterator *iter) { } | |
7e9a49ef JO |
283 | |
284 | #ifdef CONFIG_FUNCTION_TRACER | |
285 | static void irqsoff_print_header(struct seq_file *s) | |
286 | { | |
287 | trace_default_header(s); | |
288 | } | |
289 | #else | |
290 | static void irqsoff_print_header(struct seq_file *s) | |
291 | { | |
292 | trace_latency_header(s); | |
293 | } | |
294 | #endif /* CONFIG_FUNCTION_TRACER */ | |
62b915f1 JO |
295 | #endif /* CONFIG_FUNCTION_GRAPH_TRACER */ |
296 | ||
81d68a96 SR |
297 | /* |
298 | * Should this new latency be reported/recorded? | |
299 | */ | |
6d9b3fa5 | 300 | static int report_latency(struct trace_array *tr, cycle_t delta) |
81d68a96 SR |
301 | { |
302 | if (tracing_thresh) { | |
303 | if (delta < tracing_thresh) | |
304 | return 0; | |
305 | } else { | |
6d9b3fa5 | 306 | if (delta <= tr->max_latency) |
81d68a96 SR |
307 | return 0; |
308 | } | |
309 | return 1; | |
310 | } | |
311 | ||
e309b41d | 312 | static void |
81d68a96 SR |
313 | check_critical_timing(struct trace_array *tr, |
314 | struct trace_array_cpu *data, | |
315 | unsigned long parent_ip, | |
316 | int cpu) | |
317 | { | |
89b2f978 | 318 | cycle_t T0, T1, delta; |
81d68a96 | 319 | unsigned long flags; |
38697053 | 320 | int pc; |
81d68a96 | 321 | |
81d68a96 | 322 | T0 = data->preempt_timestamp; |
750ed1a4 | 323 | T1 = ftrace_now(cpu); |
81d68a96 SR |
324 | delta = T1-T0; |
325 | ||
326 | local_save_flags(flags); | |
327 | ||
6450c1d3 SR |
328 | pc = preempt_count(); |
329 | ||
6d9b3fa5 | 330 | if (!report_latency(tr, delta)) |
81d68a96 SR |
331 | goto out; |
332 | ||
5389f6fa | 333 | raw_spin_lock_irqsave(&max_trace_lock, flags); |
81d68a96 | 334 | |
89b2f978 | 335 | /* check if we are still the max latency */ |
6d9b3fa5 | 336 | if (!report_latency(tr, delta)) |
89b2f978 SR |
337 | goto out_unlock; |
338 | ||
62b915f1 | 339 | __trace_function(tr, CALLER_ADDR0, parent_ip, flags, pc); |
cc51a0fc SR |
340 | /* Skip 5 functions to get to the irq/preempt enable function */ |
341 | __trace_stack(tr, flags, 5, pc); | |
81d68a96 | 342 | |
81d68a96 | 343 | if (data->critical_sequence != max_sequence) |
89b2f978 | 344 | goto out_unlock; |
81d68a96 | 345 | |
81d68a96 SR |
346 | data->critical_end = parent_ip; |
347 | ||
b5130b1e | 348 | if (likely(!is_tracing_stopped())) { |
6d9b3fa5 | 349 | tr->max_latency = delta; |
b5130b1e CE |
350 | update_max_tr_single(tr, current, cpu); |
351 | } | |
81d68a96 | 352 | |
81d68a96 SR |
353 | max_sequence++; |
354 | ||
89b2f978 | 355 | out_unlock: |
5389f6fa | 356 | raw_spin_unlock_irqrestore(&max_trace_lock, flags); |
89b2f978 | 357 | |
81d68a96 SR |
358 | out: |
359 | data->critical_sequence = max_sequence; | |
750ed1a4 | 360 | data->preempt_timestamp = ftrace_now(cpu); |
62b915f1 | 361 | __trace_function(tr, CALLER_ADDR0, parent_ip, flags, pc); |
81d68a96 SR |
362 | } |
363 | ||
e309b41d | 364 | static inline void |
81d68a96 SR |
365 | start_critical_timing(unsigned long ip, unsigned long parent_ip) |
366 | { | |
367 | int cpu; | |
368 | struct trace_array *tr = irqsoff_trace; | |
369 | struct trace_array_cpu *data; | |
370 | unsigned long flags; | |
371 | ||
10246fa3 | 372 | if (!tracer_enabled || !tracing_is_enabled()) |
81d68a96 SR |
373 | return; |
374 | ||
c5f888ca SR |
375 | cpu = raw_smp_processor_id(); |
376 | ||
377 | if (per_cpu(tracing_cpu, cpu)) | |
6cd8a4bb SR |
378 | return; |
379 | ||
12883efb | 380 | data = per_cpu_ptr(tr->trace_buffer.data, cpu); |
81d68a96 | 381 | |
c5f888ca | 382 | if (unlikely(!data) || atomic_read(&data->disabled)) |
81d68a96 SR |
383 | return; |
384 | ||
385 | atomic_inc(&data->disabled); | |
386 | ||
387 | data->critical_sequence = max_sequence; | |
750ed1a4 | 388 | data->preempt_timestamp = ftrace_now(cpu); |
6cd8a4bb | 389 | data->critical_start = parent_ip ? : ip; |
81d68a96 SR |
390 | |
391 | local_save_flags(flags); | |
6cd8a4bb | 392 | |
62b915f1 | 393 | __trace_function(tr, ip, parent_ip, flags, preempt_count()); |
81d68a96 | 394 | |
c5f888ca | 395 | per_cpu(tracing_cpu, cpu) = 1; |
6cd8a4bb | 396 | |
81d68a96 SR |
397 | atomic_dec(&data->disabled); |
398 | } | |
399 | ||
e309b41d | 400 | static inline void |
81d68a96 SR |
401 | stop_critical_timing(unsigned long ip, unsigned long parent_ip) |
402 | { | |
403 | int cpu; | |
404 | struct trace_array *tr = irqsoff_trace; | |
405 | struct trace_array_cpu *data; | |
406 | unsigned long flags; | |
407 | ||
c5f888ca | 408 | cpu = raw_smp_processor_id(); |
6cd8a4bb | 409 | /* Always clear the tracing cpu on stopping the trace */ |
c5f888ca SR |
410 | if (unlikely(per_cpu(tracing_cpu, cpu))) |
411 | per_cpu(tracing_cpu, cpu) = 0; | |
6cd8a4bb SR |
412 | else |
413 | return; | |
414 | ||
10246fa3 | 415 | if (!tracer_enabled || !tracing_is_enabled()) |
81d68a96 SR |
416 | return; |
417 | ||
12883efb | 418 | data = per_cpu_ptr(tr->trace_buffer.data, cpu); |
81d68a96 | 419 | |
3928a8a2 | 420 | if (unlikely(!data) || |
81d68a96 SR |
421 | !data->critical_start || atomic_read(&data->disabled)) |
422 | return; | |
423 | ||
424 | atomic_inc(&data->disabled); | |
c5f888ca | 425 | |
81d68a96 | 426 | local_save_flags(flags); |
62b915f1 | 427 | __trace_function(tr, ip, parent_ip, flags, preempt_count()); |
6cd8a4bb | 428 | check_critical_timing(tr, data, parent_ip ? : ip, cpu); |
81d68a96 SR |
429 | data->critical_start = 0; |
430 | atomic_dec(&data->disabled); | |
431 | } | |
432 | ||
6cd8a4bb | 433 | /* start and stop critical timings used to for stoppage (in idle) */ |
e309b41d | 434 | void start_critical_timings(void) |
81d68a96 | 435 | { |
6cd8a4bb | 436 | if (preempt_trace() || irq_trace()) |
81d68a96 SR |
437 | start_critical_timing(CALLER_ADDR0, CALLER_ADDR1); |
438 | } | |
1fe37104 | 439 | EXPORT_SYMBOL_GPL(start_critical_timings); |
81d68a96 | 440 | |
e309b41d | 441 | void stop_critical_timings(void) |
81d68a96 | 442 | { |
6cd8a4bb | 443 | if (preempt_trace() || irq_trace()) |
81d68a96 SR |
444 | stop_critical_timing(CALLER_ADDR0, CALLER_ADDR1); |
445 | } | |
1fe37104 | 446 | EXPORT_SYMBOL_GPL(stop_critical_timings); |
81d68a96 | 447 | |
6cd8a4bb | 448 | #ifdef CONFIG_IRQSOFF_TRACER |
81d68a96 | 449 | #ifdef CONFIG_PROVE_LOCKING |
e309b41d | 450 | void time_hardirqs_on(unsigned long a0, unsigned long a1) |
81d68a96 | 451 | { |
6cd8a4bb | 452 | if (!preempt_trace() && irq_trace()) |
81d68a96 SR |
453 | stop_critical_timing(a0, a1); |
454 | } | |
455 | ||
e309b41d | 456 | void time_hardirqs_off(unsigned long a0, unsigned long a1) |
81d68a96 | 457 | { |
6cd8a4bb | 458 | if (!preempt_trace() && irq_trace()) |
81d68a96 SR |
459 | start_critical_timing(a0, a1); |
460 | } | |
461 | ||
462 | #else /* !CONFIG_PROVE_LOCKING */ | |
463 | ||
464 | /* | |
465 | * Stubs: | |
466 | */ | |
467 | ||
81d68a96 SR |
468 | void trace_softirqs_on(unsigned long ip) |
469 | { | |
470 | } | |
471 | ||
472 | void trace_softirqs_off(unsigned long ip) | |
473 | { | |
474 | } | |
475 | ||
e309b41d | 476 | inline void print_irqtrace_events(struct task_struct *curr) |
81d68a96 SR |
477 | { |
478 | } | |
479 | ||
480 | /* | |
481 | * We are only interested in hardirq on/off events: | |
482 | */ | |
e309b41d | 483 | void trace_hardirqs_on(void) |
81d68a96 | 484 | { |
6cd8a4bb | 485 | if (!preempt_trace() && irq_trace()) |
81d68a96 SR |
486 | stop_critical_timing(CALLER_ADDR0, CALLER_ADDR1); |
487 | } | |
488 | EXPORT_SYMBOL(trace_hardirqs_on); | |
489 | ||
e309b41d | 490 | void trace_hardirqs_off(void) |
81d68a96 | 491 | { |
6cd8a4bb | 492 | if (!preempt_trace() && irq_trace()) |
81d68a96 SR |
493 | start_critical_timing(CALLER_ADDR0, CALLER_ADDR1); |
494 | } | |
495 | EXPORT_SYMBOL(trace_hardirqs_off); | |
496 | ||
285c00ad | 497 | __visible void trace_hardirqs_on_caller(unsigned long caller_addr) |
81d68a96 | 498 | { |
6cd8a4bb | 499 | if (!preempt_trace() && irq_trace()) |
81d68a96 SR |
500 | stop_critical_timing(CALLER_ADDR0, caller_addr); |
501 | } | |
502 | EXPORT_SYMBOL(trace_hardirqs_on_caller); | |
503 | ||
285c00ad | 504 | __visible void trace_hardirqs_off_caller(unsigned long caller_addr) |
81d68a96 | 505 | { |
6cd8a4bb | 506 | if (!preempt_trace() && irq_trace()) |
81d68a96 SR |
507 | start_critical_timing(CALLER_ADDR0, caller_addr); |
508 | } | |
509 | EXPORT_SYMBOL(trace_hardirqs_off_caller); | |
510 | ||
511 | #endif /* CONFIG_PROVE_LOCKING */ | |
6cd8a4bb SR |
512 | #endif /* CONFIG_IRQSOFF_TRACER */ |
513 | ||
514 | #ifdef CONFIG_PREEMPT_TRACER | |
e309b41d | 515 | void trace_preempt_on(unsigned long a0, unsigned long a1) |
6cd8a4bb | 516 | { |
e36de1de | 517 | if (preempt_trace() && !irq_trace()) |
1e01cb0c | 518 | stop_critical_timing(a0, a1); |
6cd8a4bb SR |
519 | } |
520 | ||
e309b41d | 521 | void trace_preempt_off(unsigned long a0, unsigned long a1) |
6cd8a4bb | 522 | { |
e36de1de | 523 | if (preempt_trace() && !irq_trace()) |
1e01cb0c | 524 | start_critical_timing(a0, a1); |
6cd8a4bb SR |
525 | } |
526 | #endif /* CONFIG_PREEMPT_TRACER */ | |
81d68a96 | 527 | |
4104d326 | 528 | static int register_irqsoff_function(struct trace_array *tr, int graph, int set) |
81d68a96 | 529 | { |
328df475 | 530 | int ret; |
62b915f1 | 531 | |
328df475 SRRH |
532 | /* 'set' is set if TRACE_ITER_FUNCTION is about to be set */ |
533 | if (function_enabled || (!set && !(trace_flags & TRACE_ITER_FUNCTION))) | |
534 | return 0; | |
535 | ||
536 | if (graph) | |
62b915f1 JO |
537 | ret = register_ftrace_graph(&irqsoff_graph_return, |
538 | &irqsoff_graph_entry); | |
328df475 | 539 | else |
4104d326 | 540 | ret = register_ftrace_function(tr->ops); |
328df475 SRRH |
541 | |
542 | if (!ret) | |
543 | function_enabled = true; | |
544 | ||
545 | return ret; | |
546 | } | |
547 | ||
4104d326 | 548 | static void unregister_irqsoff_function(struct trace_array *tr, int graph) |
328df475 SRRH |
549 | { |
550 | if (!function_enabled) | |
551 | return; | |
552 | ||
553 | if (graph) | |
554 | unregister_ftrace_graph(); | |
555 | else | |
4104d326 | 556 | unregister_ftrace_function(tr->ops); |
328df475 SRRH |
557 | |
558 | function_enabled = false; | |
559 | } | |
560 | ||
4104d326 | 561 | static void irqsoff_function_set(struct trace_array *tr, int set) |
328df475 SRRH |
562 | { |
563 | if (set) | |
4104d326 | 564 | register_irqsoff_function(tr, is_graph(), 1); |
328df475 | 565 | else |
4104d326 | 566 | unregister_irqsoff_function(tr, is_graph()); |
328df475 SRRH |
567 | } |
568 | ||
bf6065b5 | 569 | static int irqsoff_flag_changed(struct trace_array *tr, u32 mask, int set) |
328df475 | 570 | { |
bf6065b5 SRRH |
571 | struct tracer *tracer = tr->current_trace; |
572 | ||
328df475 | 573 | if (mask & TRACE_ITER_FUNCTION) |
4104d326 | 574 | irqsoff_function_set(tr, set); |
328df475 SRRH |
575 | |
576 | return trace_keep_overwrite(tracer, mask, set); | |
577 | } | |
578 | ||
579 | static int start_irqsoff_tracer(struct trace_array *tr, int graph) | |
580 | { | |
581 | int ret; | |
582 | ||
4104d326 | 583 | ret = register_irqsoff_function(tr, graph, 0); |
62b915f1 JO |
584 | |
585 | if (!ret && tracing_is_enabled()) | |
9036990d | 586 | tracer_enabled = 1; |
94523e81 | 587 | else |
9036990d | 588 | tracer_enabled = 0; |
62b915f1 JO |
589 | |
590 | return ret; | |
81d68a96 SR |
591 | } |
592 | ||
62b915f1 | 593 | static void stop_irqsoff_tracer(struct trace_array *tr, int graph) |
81d68a96 | 594 | { |
81d68a96 | 595 | tracer_enabled = 0; |
62b915f1 | 596 | |
4104d326 | 597 | unregister_irqsoff_function(tr, graph); |
81d68a96 SR |
598 | } |
599 | ||
6cd8a4bb | 600 | static void __irqsoff_tracer_init(struct trace_array *tr) |
81d68a96 | 601 | { |
613f04a0 SRRH |
602 | save_flags = trace_flags; |
603 | ||
604 | /* non overwrite screws up the latency tracers */ | |
2b6080f2 SR |
605 | set_tracer_flag(tr, TRACE_ITER_OVERWRITE, 1); |
606 | set_tracer_flag(tr, TRACE_ITER_LATENCY_FMT, 1); | |
e9d25fe6 | 607 | |
6d9b3fa5 | 608 | tr->max_latency = 0; |
81d68a96 | 609 | irqsoff_trace = tr; |
c5f888ca | 610 | /* make sure that the tracer is visible */ |
81d68a96 | 611 | smp_wmb(); |
12883efb | 612 | tracing_reset_online_cpus(&tr->trace_buffer); |
62b915f1 | 613 | |
4104d326 SRRH |
614 | ftrace_init_array_ops(tr, irqsoff_tracer_call); |
615 | ||
616 | /* Only toplevel instance supports graph tracing */ | |
617 | if (start_irqsoff_tracer(tr, (tr->flags & TRACE_ARRAY_FL_GLOBAL && | |
618 | is_graph()))) | |
62b915f1 | 619 | printk(KERN_ERR "failed to start irqsoff tracer\n"); |
81d68a96 SR |
620 | } |
621 | ||
622 | static void irqsoff_tracer_reset(struct trace_array *tr) | |
623 | { | |
613f04a0 SRRH |
624 | int lat_flag = save_flags & TRACE_ITER_LATENCY_FMT; |
625 | int overwrite_flag = save_flags & TRACE_ITER_OVERWRITE; | |
626 | ||
62b915f1 | 627 | stop_irqsoff_tracer(tr, is_graph()); |
e9d25fe6 | 628 | |
2b6080f2 SR |
629 | set_tracer_flag(tr, TRACE_ITER_LATENCY_FMT, lat_flag); |
630 | set_tracer_flag(tr, TRACE_ITER_OVERWRITE, overwrite_flag); | |
4104d326 | 631 | ftrace_reset_array_ops(tr); |
81d68a96 SR |
632 | } |
633 | ||
9036990d SR |
634 | static void irqsoff_tracer_start(struct trace_array *tr) |
635 | { | |
9036990d | 636 | tracer_enabled = 1; |
9036990d SR |
637 | } |
638 | ||
639 | static void irqsoff_tracer_stop(struct trace_array *tr) | |
640 | { | |
641 | tracer_enabled = 0; | |
81d68a96 SR |
642 | } |
643 | ||
6cd8a4bb | 644 | #ifdef CONFIG_IRQSOFF_TRACER |
1c80025a | 645 | static int irqsoff_tracer_init(struct trace_array *tr) |
6cd8a4bb SR |
646 | { |
647 | trace_type = TRACER_IRQS_OFF; | |
648 | ||
649 | __irqsoff_tracer_init(tr); | |
1c80025a | 650 | return 0; |
6cd8a4bb | 651 | } |
81d68a96 SR |
652 | static struct tracer irqsoff_tracer __read_mostly = |
653 | { | |
654 | .name = "irqsoff", | |
655 | .init = irqsoff_tracer_init, | |
656 | .reset = irqsoff_tracer_reset, | |
9036990d SR |
657 | .start = irqsoff_tracer_start, |
658 | .stop = irqsoff_tracer_stop, | |
f43c738b | 659 | .print_max = true, |
62b915f1 JO |
660 | .print_header = irqsoff_print_header, |
661 | .print_line = irqsoff_print_line, | |
662 | .flags = &tracer_flags, | |
663 | .set_flag = irqsoff_set_flag, | |
328df475 | 664 | .flag_changed = irqsoff_flag_changed, |
60a11774 SR |
665 | #ifdef CONFIG_FTRACE_SELFTEST |
666 | .selftest = trace_selftest_startup_irqsoff, | |
667 | #endif | |
62b915f1 JO |
668 | .open = irqsoff_trace_open, |
669 | .close = irqsoff_trace_close, | |
f43c738b | 670 | .use_max_tr = true, |
81d68a96 | 671 | }; |
6cd8a4bb SR |
672 | # define register_irqsoff(trace) register_tracer(&trace) |
673 | #else | |
674 | # define register_irqsoff(trace) do { } while (0) | |
675 | #endif | |
676 | ||
677 | #ifdef CONFIG_PREEMPT_TRACER | |
1c80025a | 678 | static int preemptoff_tracer_init(struct trace_array *tr) |
6cd8a4bb SR |
679 | { |
680 | trace_type = TRACER_PREEMPT_OFF; | |
681 | ||
682 | __irqsoff_tracer_init(tr); | |
1c80025a | 683 | return 0; |
6cd8a4bb SR |
684 | } |
685 | ||
686 | static struct tracer preemptoff_tracer __read_mostly = | |
687 | { | |
688 | .name = "preemptoff", | |
689 | .init = preemptoff_tracer_init, | |
690 | .reset = irqsoff_tracer_reset, | |
9036990d SR |
691 | .start = irqsoff_tracer_start, |
692 | .stop = irqsoff_tracer_stop, | |
f43c738b | 693 | .print_max = true, |
62b915f1 JO |
694 | .print_header = irqsoff_print_header, |
695 | .print_line = irqsoff_print_line, | |
696 | .flags = &tracer_flags, | |
697 | .set_flag = irqsoff_set_flag, | |
328df475 | 698 | .flag_changed = irqsoff_flag_changed, |
60a11774 SR |
699 | #ifdef CONFIG_FTRACE_SELFTEST |
700 | .selftest = trace_selftest_startup_preemptoff, | |
701 | #endif | |
62b915f1 JO |
702 | .open = irqsoff_trace_open, |
703 | .close = irqsoff_trace_close, | |
f43c738b | 704 | .use_max_tr = true, |
6cd8a4bb SR |
705 | }; |
706 | # define register_preemptoff(trace) register_tracer(&trace) | |
707 | #else | |
708 | # define register_preemptoff(trace) do { } while (0) | |
709 | #endif | |
710 | ||
711 | #if defined(CONFIG_IRQSOFF_TRACER) && \ | |
712 | defined(CONFIG_PREEMPT_TRACER) | |
713 | ||
1c80025a | 714 | static int preemptirqsoff_tracer_init(struct trace_array *tr) |
6cd8a4bb SR |
715 | { |
716 | trace_type = TRACER_IRQS_OFF | TRACER_PREEMPT_OFF; | |
717 | ||
718 | __irqsoff_tracer_init(tr); | |
1c80025a | 719 | return 0; |
6cd8a4bb SR |
720 | } |
721 | ||
722 | static struct tracer preemptirqsoff_tracer __read_mostly = | |
723 | { | |
724 | .name = "preemptirqsoff", | |
725 | .init = preemptirqsoff_tracer_init, | |
726 | .reset = irqsoff_tracer_reset, | |
9036990d SR |
727 | .start = irqsoff_tracer_start, |
728 | .stop = irqsoff_tracer_stop, | |
f43c738b | 729 | .print_max = true, |
62b915f1 JO |
730 | .print_header = irqsoff_print_header, |
731 | .print_line = irqsoff_print_line, | |
732 | .flags = &tracer_flags, | |
733 | .set_flag = irqsoff_set_flag, | |
328df475 | 734 | .flag_changed = irqsoff_flag_changed, |
60a11774 SR |
735 | #ifdef CONFIG_FTRACE_SELFTEST |
736 | .selftest = trace_selftest_startup_preemptirqsoff, | |
737 | #endif | |
62b915f1 JO |
738 | .open = irqsoff_trace_open, |
739 | .close = irqsoff_trace_close, | |
f43c738b | 740 | .use_max_tr = true, |
6cd8a4bb SR |
741 | }; |
742 | ||
743 | # define register_preemptirqsoff(trace) register_tracer(&trace) | |
744 | #else | |
745 | # define register_preemptirqsoff(trace) do { } while (0) | |
746 | #endif | |
81d68a96 SR |
747 | |
748 | __init static int init_irqsoff_tracer(void) | |
749 | { | |
6cd8a4bb SR |
750 | register_irqsoff(irqsoff_tracer); |
751 | register_preemptoff(preemptoff_tracer); | |
752 | register_preemptirqsoff(preemptirqsoff_tracer); | |
81d68a96 SR |
753 | |
754 | return 0; | |
755 | } | |
6f415672 | 756 | core_initcall(init_irqsoff_tracer); |