blob: 62a78d943534cd0c6b4d50d8ef5832db741c881d [file] [log] [blame]
Steven Rostedt81d68a92008-05-12 21:20:42 +02001/*
2 * trace irqs off criticall timings
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
10 * Copyright (C) 2004 William Lee Irwin III
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
21static struct trace_array *irqsoff_trace __read_mostly;
22static int tracer_enabled __read_mostly;
23
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +020024static DEFINE_PER_CPU(int, tracing_cpu);
25
Steven Rostedt89b2f972008-05-12 21:20:44 +020026static DEFINE_SPINLOCK(max_trace_lock);
27
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +020028enum {
29 TRACER_IRQS_OFF = (1 << 1),
30 TRACER_PREEMPT_OFF = (1 << 2),
31};
32
33static int trace_type __read_mostly;
34
35#ifdef CONFIG_PREEMPT_TRACER
Ingo Molnare309b412008-05-12 21:20:51 +020036static inline int
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +020037preempt_trace(void)
38{
39 return ((trace_type & TRACER_PREEMPT_OFF) && preempt_count());
40}
41#else
42# define preempt_trace() (0)
43#endif
44
45#ifdef CONFIG_IRQSOFF_TRACER
Ingo Molnare309b412008-05-12 21:20:51 +020046static inline int
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +020047irq_trace(void)
48{
49 return ((trace_type & TRACER_IRQS_OFF) &&
50 irqs_disabled());
51}
52#else
53# define irq_trace() (0)
54#endif
55
Steven Rostedt81d68a92008-05-12 21:20:42 +020056/*
57 * Sequence count - we record it when starting a measurement and
58 * skip the latency if the sequence has changed - some other section
59 * did a maximum and could disturb our measurement with serial console
60 * printouts, etc. Truly coinciding maximum latencies should be rare
61 * and what happens together happens separately as well, so this doesnt
62 * decrease the validity of the maximum found:
63 */
64static __cacheline_aligned_in_smp unsigned long max_sequence;
65
Steven Rostedt606576c2008-10-06 19:06:12 -040066#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedt81d68a92008-05-12 21:20:42 +020067/*
68 * irqsoff uses its own tracer function to keep the overhead down:
69 */
Ingo Molnare309b412008-05-12 21:20:51 +020070static void
Steven Rostedt81d68a92008-05-12 21:20:42 +020071irqsoff_tracer_call(unsigned long ip, unsigned long parent_ip)
72{
73 struct trace_array *tr = irqsoff_trace;
74 struct trace_array_cpu *data;
75 unsigned long flags;
76 long disabled;
77 int cpu;
78
Steven Rostedt361943a2008-05-12 21:20:44 +020079 /*
80 * Does not matter if we preempt. We test the flags
81 * afterward, to see if irqs are disabled or not.
82 * If we preempt and get a false positive, the flags
83 * test will fail.
84 */
85 cpu = raw_smp_processor_id();
86 if (likely(!per_cpu(tracing_cpu, cpu)))
Steven Rostedt81d68a92008-05-12 21:20:42 +020087 return;
88
89 local_save_flags(flags);
Steven Rostedt361943a2008-05-12 21:20:44 +020090 /* slight chance to get a false positive on tracing_cpu */
91 if (!irqs_disabled_flags(flags))
92 return;
Steven Rostedt81d68a92008-05-12 21:20:42 +020093
Steven Rostedt81d68a92008-05-12 21:20:42 +020094 data = tr->data[cpu];
95 disabled = atomic_inc_return(&data->disabled);
96
97 if (likely(disabled == 1))
Steven Rostedt38697052008-10-01 13:14:09 -040098 trace_function(tr, data, ip, parent_ip, flags, preempt_count());
Steven Rostedt81d68a92008-05-12 21:20:42 +020099
100 atomic_dec(&data->disabled);
101}
102
103static struct ftrace_ops trace_ops __read_mostly =
104{
105 .func = irqsoff_tracer_call,
106};
Steven Rostedt606576c2008-10-06 19:06:12 -0400107#endif /* CONFIG_FUNCTION_TRACER */
Steven Rostedt81d68a92008-05-12 21:20:42 +0200108
109/*
110 * Should this new latency be reported/recorded?
111 */
Ingo Molnare309b412008-05-12 21:20:51 +0200112static int report_latency(cycle_t delta)
Steven Rostedt81d68a92008-05-12 21:20:42 +0200113{
114 if (tracing_thresh) {
115 if (delta < tracing_thresh)
116 return 0;
117 } else {
118 if (delta <= tracing_max_latency)
119 return 0;
120 }
121 return 1;
122}
123
Ingo Molnare309b412008-05-12 21:20:51 +0200124static void
Steven Rostedt81d68a92008-05-12 21:20:42 +0200125check_critical_timing(struct trace_array *tr,
126 struct trace_array_cpu *data,
127 unsigned long parent_ip,
128 int cpu)
129{
130 unsigned long latency, t0, t1;
Steven Rostedt89b2f972008-05-12 21:20:44 +0200131 cycle_t T0, T1, delta;
Steven Rostedt81d68a92008-05-12 21:20:42 +0200132 unsigned long flags;
Steven Rostedt38697052008-10-01 13:14:09 -0400133 int pc;
Steven Rostedt81d68a92008-05-12 21:20:42 +0200134
135 /*
136 * usecs conversion is slow so we try to delay the conversion
137 * as long as possible:
138 */
139 T0 = data->preempt_timestamp;
Ingo Molnar750ed1a2008-05-12 21:20:46 +0200140 T1 = ftrace_now(cpu);
Steven Rostedt81d68a92008-05-12 21:20:42 +0200141 delta = T1-T0;
142
143 local_save_flags(flags);
144
Steven Rostedt6450c1d2008-10-02 19:23:04 -0400145 pc = preempt_count();
146
Steven Rostedt81d68a92008-05-12 21:20:42 +0200147 if (!report_latency(delta))
148 goto out;
149
Ingo Molnarc7aafc52008-05-12 21:20:45 +0200150 spin_lock_irqsave(&max_trace_lock, flags);
Steven Rostedt81d68a92008-05-12 21:20:42 +0200151
Steven Rostedt89b2f972008-05-12 21:20:44 +0200152 /* check if we are still the max latency */
153 if (!report_latency(delta))
154 goto out_unlock;
155
Steven Rostedt38697052008-10-01 13:14:09 -0400156 trace_function(tr, data, CALLER_ADDR0, parent_ip, flags, pc);
Steven Rostedt81d68a92008-05-12 21:20:42 +0200157
158 latency = nsecs_to_usecs(delta);
159
160 if (data->critical_sequence != max_sequence)
Steven Rostedt89b2f972008-05-12 21:20:44 +0200161 goto out_unlock;
Steven Rostedt81d68a92008-05-12 21:20:42 +0200162
163 tracing_max_latency = delta;
164 t0 = nsecs_to_usecs(T0);
165 t1 = nsecs_to_usecs(T1);
166
167 data->critical_end = parent_ip;
168
169 update_max_tr_single(tr, current, cpu);
170
Steven Rostedt81d68a92008-05-12 21:20:42 +0200171 max_sequence++;
172
Steven Rostedt89b2f972008-05-12 21:20:44 +0200173out_unlock:
Ingo Molnarc7aafc52008-05-12 21:20:45 +0200174 spin_unlock_irqrestore(&max_trace_lock, flags);
Steven Rostedt89b2f972008-05-12 21:20:44 +0200175
Steven Rostedt81d68a92008-05-12 21:20:42 +0200176out:
177 data->critical_sequence = max_sequence;
Ingo Molnar750ed1a2008-05-12 21:20:46 +0200178 data->preempt_timestamp = ftrace_now(cpu);
Steven Rostedt3928a8a2008-09-29 23:02:41 -0400179 tracing_reset(tr, cpu);
Steven Rostedt38697052008-10-01 13:14:09 -0400180 trace_function(tr, data, CALLER_ADDR0, parent_ip, flags, pc);
Steven Rostedt81d68a92008-05-12 21:20:42 +0200181}
182
Ingo Molnare309b412008-05-12 21:20:51 +0200183static inline void
Steven Rostedt81d68a92008-05-12 21:20:42 +0200184start_critical_timing(unsigned long ip, unsigned long parent_ip)
185{
186 int cpu;
187 struct trace_array *tr = irqsoff_trace;
188 struct trace_array_cpu *data;
189 unsigned long flags;
190
191 if (likely(!tracer_enabled))
192 return;
193
Steven Rostedtc5f888c2008-05-12 21:20:55 +0200194 cpu = raw_smp_processor_id();
195
196 if (per_cpu(tracing_cpu, cpu))
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +0200197 return;
198
Steven Rostedt81d68a92008-05-12 21:20:42 +0200199 data = tr->data[cpu];
200
Steven Rostedtc5f888c2008-05-12 21:20:55 +0200201 if (unlikely(!data) || atomic_read(&data->disabled))
Steven Rostedt81d68a92008-05-12 21:20:42 +0200202 return;
203
204 atomic_inc(&data->disabled);
205
206 data->critical_sequence = max_sequence;
Ingo Molnar750ed1a2008-05-12 21:20:46 +0200207 data->preempt_timestamp = ftrace_now(cpu);
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +0200208 data->critical_start = parent_ip ? : ip;
Steven Rostedt3928a8a2008-09-29 23:02:41 -0400209 tracing_reset(tr, cpu);
Steven Rostedt81d68a92008-05-12 21:20:42 +0200210
211 local_save_flags(flags);
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +0200212
Steven Rostedt38697052008-10-01 13:14:09 -0400213 trace_function(tr, data, ip, parent_ip, flags, preempt_count());
Steven Rostedt81d68a92008-05-12 21:20:42 +0200214
Steven Rostedtc5f888c2008-05-12 21:20:55 +0200215 per_cpu(tracing_cpu, cpu) = 1;
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +0200216
Steven Rostedt81d68a92008-05-12 21:20:42 +0200217 atomic_dec(&data->disabled);
218}
219
Ingo Molnare309b412008-05-12 21:20:51 +0200220static inline void
Steven Rostedt81d68a92008-05-12 21:20:42 +0200221stop_critical_timing(unsigned long ip, unsigned long parent_ip)
222{
223 int cpu;
224 struct trace_array *tr = irqsoff_trace;
225 struct trace_array_cpu *data;
226 unsigned long flags;
227
Steven Rostedtc5f888c2008-05-12 21:20:55 +0200228 cpu = raw_smp_processor_id();
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +0200229 /* Always clear the tracing cpu on stopping the trace */
Steven Rostedtc5f888c2008-05-12 21:20:55 +0200230 if (unlikely(per_cpu(tracing_cpu, cpu)))
231 per_cpu(tracing_cpu, cpu) = 0;
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +0200232 else
233 return;
234
235 if (!tracer_enabled)
Steven Rostedt81d68a92008-05-12 21:20:42 +0200236 return;
237
Steven Rostedt81d68a92008-05-12 21:20:42 +0200238 data = tr->data[cpu];
239
Steven Rostedt3928a8a2008-09-29 23:02:41 -0400240 if (unlikely(!data) ||
Steven Rostedt81d68a92008-05-12 21:20:42 +0200241 !data->critical_start || atomic_read(&data->disabled))
242 return;
243
244 atomic_inc(&data->disabled);
Steven Rostedtc5f888c2008-05-12 21:20:55 +0200245
Steven Rostedt81d68a92008-05-12 21:20:42 +0200246 local_save_flags(flags);
Steven Rostedt38697052008-10-01 13:14:09 -0400247 trace_function(tr, data, ip, parent_ip, flags, preempt_count());
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +0200248 check_critical_timing(tr, data, parent_ip ? : ip, cpu);
Steven Rostedt81d68a92008-05-12 21:20:42 +0200249 data->critical_start = 0;
250 atomic_dec(&data->disabled);
251}
252
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +0200253/* start and stop critical timings used to for stoppage (in idle) */
Ingo Molnare309b412008-05-12 21:20:51 +0200254void start_critical_timings(void)
Steven Rostedt81d68a92008-05-12 21:20:42 +0200255{
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +0200256 if (preempt_trace() || irq_trace())
Steven Rostedt81d68a92008-05-12 21:20:42 +0200257 start_critical_timing(CALLER_ADDR0, CALLER_ADDR1);
258}
Ingo Molnar1fe37102008-07-26 15:09:47 +0200259EXPORT_SYMBOL_GPL(start_critical_timings);
Steven Rostedt81d68a92008-05-12 21:20:42 +0200260
Ingo Molnare309b412008-05-12 21:20:51 +0200261void stop_critical_timings(void)
Steven Rostedt81d68a92008-05-12 21:20:42 +0200262{
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +0200263 if (preempt_trace() || irq_trace())
Steven Rostedt81d68a92008-05-12 21:20:42 +0200264 stop_critical_timing(CALLER_ADDR0, CALLER_ADDR1);
265}
Ingo Molnar1fe37102008-07-26 15:09:47 +0200266EXPORT_SYMBOL_GPL(stop_critical_timings);
Steven Rostedt81d68a92008-05-12 21:20:42 +0200267
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +0200268#ifdef CONFIG_IRQSOFF_TRACER
Steven Rostedt81d68a92008-05-12 21:20:42 +0200269#ifdef CONFIG_PROVE_LOCKING
Ingo Molnare309b412008-05-12 21:20:51 +0200270void time_hardirqs_on(unsigned long a0, unsigned long a1)
Steven Rostedt81d68a92008-05-12 21:20:42 +0200271{
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +0200272 if (!preempt_trace() && irq_trace())
Steven Rostedt81d68a92008-05-12 21:20:42 +0200273 stop_critical_timing(a0, a1);
274}
275
Ingo Molnare309b412008-05-12 21:20:51 +0200276void time_hardirqs_off(unsigned long a0, unsigned long a1)
Steven Rostedt81d68a92008-05-12 21:20:42 +0200277{
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +0200278 if (!preempt_trace() && irq_trace())
Steven Rostedt81d68a92008-05-12 21:20:42 +0200279 start_critical_timing(a0, a1);
280}
281
282#else /* !CONFIG_PROVE_LOCKING */
283
284/*
285 * Stubs:
286 */
287
288void early_boot_irqs_off(void)
289{
290}
291
292void early_boot_irqs_on(void)
293{
294}
295
296void trace_softirqs_on(unsigned long ip)
297{
298}
299
300void trace_softirqs_off(unsigned long ip)
301{
302}
303
Ingo Molnare309b412008-05-12 21:20:51 +0200304inline void print_irqtrace_events(struct task_struct *curr)
Steven Rostedt81d68a92008-05-12 21:20:42 +0200305{
306}
307
308/*
309 * We are only interested in hardirq on/off events:
310 */
Ingo Molnare309b412008-05-12 21:20:51 +0200311void trace_hardirqs_on(void)
Steven Rostedt81d68a92008-05-12 21:20:42 +0200312{
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +0200313 if (!preempt_trace() && irq_trace())
Steven Rostedt81d68a92008-05-12 21:20:42 +0200314 stop_critical_timing(CALLER_ADDR0, CALLER_ADDR1);
315}
316EXPORT_SYMBOL(trace_hardirqs_on);
317
Ingo Molnare309b412008-05-12 21:20:51 +0200318void trace_hardirqs_off(void)
Steven Rostedt81d68a92008-05-12 21:20:42 +0200319{
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +0200320 if (!preempt_trace() && irq_trace())
Steven Rostedt81d68a92008-05-12 21:20:42 +0200321 start_critical_timing(CALLER_ADDR0, CALLER_ADDR1);
322}
323EXPORT_SYMBOL(trace_hardirqs_off);
324
Ingo Molnare309b412008-05-12 21:20:51 +0200325void trace_hardirqs_on_caller(unsigned long caller_addr)
Steven Rostedt81d68a92008-05-12 21:20:42 +0200326{
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +0200327 if (!preempt_trace() && irq_trace())
Steven Rostedt81d68a92008-05-12 21:20:42 +0200328 stop_critical_timing(CALLER_ADDR0, caller_addr);
329}
330EXPORT_SYMBOL(trace_hardirqs_on_caller);
331
Ingo Molnare309b412008-05-12 21:20:51 +0200332void trace_hardirqs_off_caller(unsigned long caller_addr)
Steven Rostedt81d68a92008-05-12 21:20:42 +0200333{
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +0200334 if (!preempt_trace() && irq_trace())
Steven Rostedt81d68a92008-05-12 21:20:42 +0200335 start_critical_timing(CALLER_ADDR0, caller_addr);
336}
337EXPORT_SYMBOL(trace_hardirqs_off_caller);
338
339#endif /* CONFIG_PROVE_LOCKING */
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +0200340#endif /* CONFIG_IRQSOFF_TRACER */
341
342#ifdef CONFIG_PREEMPT_TRACER
Ingo Molnare309b412008-05-12 21:20:51 +0200343void trace_preempt_on(unsigned long a0, unsigned long a1)
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +0200344{
Steven Rostedt1e01cb02008-07-15 09:53:37 -0400345 if (preempt_trace())
346 stop_critical_timing(a0, a1);
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +0200347}
348
Ingo Molnare309b412008-05-12 21:20:51 +0200349void trace_preempt_off(unsigned long a0, unsigned long a1)
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +0200350{
Steven Rostedt1e01cb02008-07-15 09:53:37 -0400351 if (preempt_trace())
352 start_critical_timing(a0, a1);
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +0200353}
354#endif /* CONFIG_PREEMPT_TRACER */
Steven Rostedt81d68a92008-05-12 21:20:42 +0200355
Steven Rostedt90369902008-11-05 16:05:44 -0500356/*
357 * save_tracer_enabled is used to save the state of the tracer_enabled
358 * variable when we disable it when we open a trace output file.
359 */
360static int save_tracer_enabled;
361
Steven Rostedt81d68a92008-05-12 21:20:42 +0200362static void start_irqsoff_tracer(struct trace_array *tr)
363{
Steven Rostedt81d68a92008-05-12 21:20:42 +0200364 register_ftrace_function(&trace_ops);
Steven Rostedt90369902008-11-05 16:05:44 -0500365 if (tracing_is_enabled()) {
366 tracer_enabled = 1;
367 save_tracer_enabled = 1;
368 } else {
369 tracer_enabled = 0;
370 save_tracer_enabled = 0;
371 }
Steven Rostedt81d68a92008-05-12 21:20:42 +0200372}
373
374static void stop_irqsoff_tracer(struct trace_array *tr)
375{
Steven Rostedt81d68a92008-05-12 21:20:42 +0200376 tracer_enabled = 0;
Steven Rostedt90369902008-11-05 16:05:44 -0500377 save_tracer_enabled = 0;
Steven Rostedt89b2f972008-05-12 21:20:44 +0200378 unregister_ftrace_function(&trace_ops);
Steven Rostedt81d68a92008-05-12 21:20:42 +0200379}
380
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +0200381static void __irqsoff_tracer_init(struct trace_array *tr)
Steven Rostedt81d68a92008-05-12 21:20:42 +0200382{
Steven Rostedt745b1622009-01-15 23:40:11 -0500383 tracing_max_latency = 0;
Steven Rostedt81d68a92008-05-12 21:20:42 +0200384 irqsoff_trace = tr;
Steven Rostedtc5f888c2008-05-12 21:20:55 +0200385 /* make sure that the tracer is visible */
Steven Rostedt81d68a92008-05-12 21:20:42 +0200386 smp_wmb();
Steven Rostedtc76f0692008-11-07 22:36:02 -0500387 start_irqsoff_tracer(tr);
Steven Rostedt81d68a92008-05-12 21:20:42 +0200388}
389
390static void irqsoff_tracer_reset(struct trace_array *tr)
391{
Steven Rostedtc76f0692008-11-07 22:36:02 -0500392 stop_irqsoff_tracer(tr);
Steven Rostedt81d68a92008-05-12 21:20:42 +0200393}
394
Steven Rostedt90369902008-11-05 16:05:44 -0500395static void irqsoff_tracer_start(struct trace_array *tr)
396{
Steven Rostedt90369902008-11-05 16:05:44 -0500397 tracer_enabled = 1;
398 save_tracer_enabled = 1;
399}
400
401static void irqsoff_tracer_stop(struct trace_array *tr)
402{
403 tracer_enabled = 0;
404 save_tracer_enabled = 0;
405}
406
Ingo Molnare309b412008-05-12 21:20:51 +0200407static void irqsoff_tracer_open(struct trace_iterator *iter)
Steven Rostedt81d68a92008-05-12 21:20:42 +0200408{
409 /* stop the trace while dumping */
Steven Rostedt90369902008-11-05 16:05:44 -0500410 tracer_enabled = 0;
Steven Rostedt81d68a92008-05-12 21:20:42 +0200411}
412
Ingo Molnare309b412008-05-12 21:20:51 +0200413static void irqsoff_tracer_close(struct trace_iterator *iter)
Steven Rostedt81d68a92008-05-12 21:20:42 +0200414{
Steven Rostedt90369902008-11-05 16:05:44 -0500415 /* restart tracing */
416 tracer_enabled = save_tracer_enabled;
Steven Rostedt81d68a92008-05-12 21:20:42 +0200417}
418
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +0200419#ifdef CONFIG_IRQSOFF_TRACER
Frederic Weisbecker1c800252008-11-16 05:57:26 +0100420static int irqsoff_tracer_init(struct trace_array *tr)
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +0200421{
422 trace_type = TRACER_IRQS_OFF;
423
424 __irqsoff_tracer_init(tr);
Frederic Weisbecker1c800252008-11-16 05:57:26 +0100425 return 0;
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +0200426}
Steven Rostedt81d68a92008-05-12 21:20:42 +0200427static struct tracer irqsoff_tracer __read_mostly =
428{
429 .name = "irqsoff",
430 .init = irqsoff_tracer_init,
431 .reset = irqsoff_tracer_reset,
Steven Rostedt90369902008-11-05 16:05:44 -0500432 .start = irqsoff_tracer_start,
433 .stop = irqsoff_tracer_stop,
Steven Rostedt81d68a92008-05-12 21:20:42 +0200434 .open = irqsoff_tracer_open,
435 .close = irqsoff_tracer_close,
Steven Rostedt81d68a92008-05-12 21:20:42 +0200436 .print_max = 1,
Steven Rostedt60a11772008-05-12 21:20:44 +0200437#ifdef CONFIG_FTRACE_SELFTEST
438 .selftest = trace_selftest_startup_irqsoff,
439#endif
Steven Rostedt81d68a92008-05-12 21:20:42 +0200440};
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +0200441# define register_irqsoff(trace) register_tracer(&trace)
442#else
443# define register_irqsoff(trace) do { } while (0)
444#endif
445
446#ifdef CONFIG_PREEMPT_TRACER
Frederic Weisbecker1c800252008-11-16 05:57:26 +0100447static int preemptoff_tracer_init(struct trace_array *tr)
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +0200448{
449 trace_type = TRACER_PREEMPT_OFF;
450
451 __irqsoff_tracer_init(tr);
Frederic Weisbecker1c800252008-11-16 05:57:26 +0100452 return 0;
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +0200453}
454
455static struct tracer preemptoff_tracer __read_mostly =
456{
457 .name = "preemptoff",
458 .init = preemptoff_tracer_init,
459 .reset = irqsoff_tracer_reset,
Steven Rostedt90369902008-11-05 16:05:44 -0500460 .start = irqsoff_tracer_start,
461 .stop = irqsoff_tracer_stop,
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +0200462 .open = irqsoff_tracer_open,
463 .close = irqsoff_tracer_close,
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +0200464 .print_max = 1,
Steven Rostedt60a11772008-05-12 21:20:44 +0200465#ifdef CONFIG_FTRACE_SELFTEST
466 .selftest = trace_selftest_startup_preemptoff,
467#endif
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +0200468};
469# define register_preemptoff(trace) register_tracer(&trace)
470#else
471# define register_preemptoff(trace) do { } while (0)
472#endif
473
474#if defined(CONFIG_IRQSOFF_TRACER) && \
475 defined(CONFIG_PREEMPT_TRACER)
476
Frederic Weisbecker1c800252008-11-16 05:57:26 +0100477static int preemptirqsoff_tracer_init(struct trace_array *tr)
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +0200478{
479 trace_type = TRACER_IRQS_OFF | TRACER_PREEMPT_OFF;
480
481 __irqsoff_tracer_init(tr);
Frederic Weisbecker1c800252008-11-16 05:57:26 +0100482 return 0;
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +0200483}
484
485static struct tracer preemptirqsoff_tracer __read_mostly =
486{
487 .name = "preemptirqsoff",
488 .init = preemptirqsoff_tracer_init,
489 .reset = irqsoff_tracer_reset,
Steven Rostedt90369902008-11-05 16:05:44 -0500490 .start = irqsoff_tracer_start,
491 .stop = irqsoff_tracer_stop,
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +0200492 .open = irqsoff_tracer_open,
493 .close = irqsoff_tracer_close,
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +0200494 .print_max = 1,
Steven Rostedt60a11772008-05-12 21:20:44 +0200495#ifdef CONFIG_FTRACE_SELFTEST
496 .selftest = trace_selftest_startup_preemptirqsoff,
497#endif
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +0200498};
499
500# define register_preemptirqsoff(trace) register_tracer(&trace)
501#else
502# define register_preemptirqsoff(trace) do { } while (0)
503#endif
Steven Rostedt81d68a92008-05-12 21:20:42 +0200504
505__init static int init_irqsoff_tracer(void)
506{
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +0200507 register_irqsoff(irqsoff_tracer);
508 register_preemptoff(preemptoff_tracer);
509 register_preemptirqsoff(preemptirqsoff_tracer);
Steven Rostedt81d68a92008-05-12 21:20:42 +0200510
511 return 0;
512}
513device_initcall(init_irqsoff_tracer);