blob: b923d13e2fad9793dba42bfa05b582a36f306800 [file] [log] [blame]
Steven Rostedt81d68a92008-05-12 21:20:42 +02001/*
Wenji Huang73d8b8b2009-02-17 01:10:02 -05002 * trace irqs off critical timings
Steven Rostedt81d68a92008-05-12 21:20:42 +02003 *
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
Steven Rostedte9d25fe2009-03-04 22:15:30 -050035static int save_lat_flag;
36
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +020037#ifdef CONFIG_PREEMPT_TRACER
Ingo Molnare309b412008-05-12 21:20:51 +020038static inline int
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +020039preempt_trace(void)
40{
41 return ((trace_type & TRACER_PREEMPT_OFF) && preempt_count());
42}
43#else
44# define preempt_trace() (0)
45#endif
46
47#ifdef CONFIG_IRQSOFF_TRACER
Ingo Molnare309b412008-05-12 21:20:51 +020048static inline int
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +020049irq_trace(void)
50{
51 return ((trace_type & TRACER_IRQS_OFF) &&
52 irqs_disabled());
53}
54#else
55# define irq_trace() (0)
56#endif
57
Steven Rostedt81d68a92008-05-12 21:20:42 +020058/*
59 * Sequence count - we record it when starting a measurement and
60 * skip the latency if the sequence has changed - some other section
61 * did a maximum and could disturb our measurement with serial console
62 * printouts, etc. Truly coinciding maximum latencies should be rare
63 * and what happens together happens separately as well, so this doesnt
64 * decrease the validity of the maximum found:
65 */
66static __cacheline_aligned_in_smp unsigned long max_sequence;
67
Steven Rostedt606576c2008-10-06 19:06:12 -040068#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedt81d68a92008-05-12 21:20:42 +020069/*
70 * irqsoff uses its own tracer function to keep the overhead down:
71 */
Ingo Molnare309b412008-05-12 21:20:51 +020072static void
Steven Rostedt81d68a92008-05-12 21:20:42 +020073irqsoff_tracer_call(unsigned long ip, unsigned long parent_ip)
74{
75 struct trace_array *tr = irqsoff_trace;
76 struct trace_array_cpu *data;
77 unsigned long flags;
78 long disabled;
79 int cpu;
80
Steven Rostedt361943a2008-05-12 21:20:44 +020081 /*
82 * Does not matter if we preempt. We test the flags
83 * afterward, to see if irqs are disabled or not.
84 * If we preempt and get a false positive, the flags
85 * test will fail.
86 */
87 cpu = raw_smp_processor_id();
88 if (likely(!per_cpu(tracing_cpu, cpu)))
Steven Rostedt81d68a92008-05-12 21:20:42 +020089 return;
90
91 local_save_flags(flags);
Steven Rostedt361943a2008-05-12 21:20:44 +020092 /* slight chance to get a false positive on tracing_cpu */
93 if (!irqs_disabled_flags(flags))
94 return;
Steven Rostedt81d68a92008-05-12 21:20:42 +020095
Steven Rostedt81d68a92008-05-12 21:20:42 +020096 data = tr->data[cpu];
97 disabled = atomic_inc_return(&data->disabled);
98
99 if (likely(disabled == 1))
Arnaldo Carvalho de Melo7be42152009-02-05 01:13:37 -0500100 trace_function(tr, ip, parent_ip, flags, preempt_count());
Steven Rostedt81d68a92008-05-12 21:20:42 +0200101
102 atomic_dec(&data->disabled);
103}
104
105static struct ftrace_ops trace_ops __read_mostly =
106{
107 .func = irqsoff_tracer_call,
108};
Steven Rostedt606576c2008-10-06 19:06:12 -0400109#endif /* CONFIG_FUNCTION_TRACER */
Steven Rostedt81d68a92008-05-12 21:20:42 +0200110
111/*
112 * Should this new latency be reported/recorded?
113 */
Ingo Molnare309b412008-05-12 21:20:51 +0200114static int report_latency(cycle_t delta)
Steven Rostedt81d68a92008-05-12 21:20:42 +0200115{
116 if (tracing_thresh) {
117 if (delta < tracing_thresh)
118 return 0;
119 } else {
120 if (delta <= tracing_max_latency)
121 return 0;
122 }
123 return 1;
124}
125
Ingo Molnare309b412008-05-12 21:20:51 +0200126static void
Steven Rostedt81d68a92008-05-12 21:20:42 +0200127check_critical_timing(struct trace_array *tr,
128 struct trace_array_cpu *data,
129 unsigned long parent_ip,
130 int cpu)
131{
132 unsigned long latency, t0, t1;
Steven Rostedt89b2f972008-05-12 21:20:44 +0200133 cycle_t T0, T1, delta;
Steven Rostedt81d68a92008-05-12 21:20:42 +0200134 unsigned long flags;
Steven Rostedt38697052008-10-01 13:14:09 -0400135 int pc;
Steven Rostedt81d68a92008-05-12 21:20:42 +0200136
137 /*
138 * usecs conversion is slow so we try to delay the conversion
139 * as long as possible:
140 */
141 T0 = data->preempt_timestamp;
Ingo Molnar750ed1a2008-05-12 21:20:46 +0200142 T1 = ftrace_now(cpu);
Steven Rostedt81d68a92008-05-12 21:20:42 +0200143 delta = T1-T0;
144
145 local_save_flags(flags);
146
Steven Rostedt6450c1d2008-10-02 19:23:04 -0400147 pc = preempt_count();
148
Steven Rostedt81d68a92008-05-12 21:20:42 +0200149 if (!report_latency(delta))
150 goto out;
151
Ingo Molnarc7aafc52008-05-12 21:20:45 +0200152 spin_lock_irqsave(&max_trace_lock, flags);
Steven Rostedt81d68a92008-05-12 21:20:42 +0200153
Steven Rostedt89b2f972008-05-12 21:20:44 +0200154 /* check if we are still the max latency */
155 if (!report_latency(delta))
156 goto out_unlock;
157
Arnaldo Carvalho de Melo7be42152009-02-05 01:13:37 -0500158 trace_function(tr, CALLER_ADDR0, parent_ip, flags, pc);
Steven Rostedt81d68a92008-05-12 21:20:42 +0200159
160 latency = nsecs_to_usecs(delta);
161
162 if (data->critical_sequence != max_sequence)
Steven Rostedt89b2f972008-05-12 21:20:44 +0200163 goto out_unlock;
Steven Rostedt81d68a92008-05-12 21:20:42 +0200164
165 tracing_max_latency = delta;
166 t0 = nsecs_to_usecs(T0);
167 t1 = nsecs_to_usecs(T1);
168
169 data->critical_end = parent_ip;
170
171 update_max_tr_single(tr, current, cpu);
172
Steven Rostedt81d68a92008-05-12 21:20:42 +0200173 max_sequence++;
174
Steven Rostedt89b2f972008-05-12 21:20:44 +0200175out_unlock:
Ingo Molnarc7aafc52008-05-12 21:20:45 +0200176 spin_unlock_irqrestore(&max_trace_lock, flags);
Steven Rostedt89b2f972008-05-12 21:20:44 +0200177
Steven Rostedt81d68a92008-05-12 21:20:42 +0200178out:
179 data->critical_sequence = max_sequence;
Ingo Molnar750ed1a2008-05-12 21:20:46 +0200180 data->preempt_timestamp = ftrace_now(cpu);
Steven Rostedt3928a8a2008-09-29 23:02:41 -0400181 tracing_reset(tr, cpu);
Arnaldo Carvalho de Melo7be42152009-02-05 01:13:37 -0500182 trace_function(tr, CALLER_ADDR0, parent_ip, flags, pc);
Steven Rostedt81d68a92008-05-12 21:20:42 +0200183}
184
Ingo Molnare309b412008-05-12 21:20:51 +0200185static inline void
Steven Rostedt81d68a92008-05-12 21:20:42 +0200186start_critical_timing(unsigned long ip, unsigned long parent_ip)
187{
188 int cpu;
189 struct trace_array *tr = irqsoff_trace;
190 struct trace_array_cpu *data;
191 unsigned long flags;
192
193 if (likely(!tracer_enabled))
194 return;
195
Steven Rostedtc5f888c2008-05-12 21:20:55 +0200196 cpu = raw_smp_processor_id();
197
198 if (per_cpu(tracing_cpu, cpu))
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +0200199 return;
200
Steven Rostedt81d68a92008-05-12 21:20:42 +0200201 data = tr->data[cpu];
202
Steven Rostedtc5f888c2008-05-12 21:20:55 +0200203 if (unlikely(!data) || atomic_read(&data->disabled))
Steven Rostedt81d68a92008-05-12 21:20:42 +0200204 return;
205
206 atomic_inc(&data->disabled);
207
208 data->critical_sequence = max_sequence;
Ingo Molnar750ed1a2008-05-12 21:20:46 +0200209 data->preempt_timestamp = ftrace_now(cpu);
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +0200210 data->critical_start = parent_ip ? : ip;
Steven Rostedt3928a8a2008-09-29 23:02:41 -0400211 tracing_reset(tr, cpu);
Steven Rostedt81d68a92008-05-12 21:20:42 +0200212
213 local_save_flags(flags);
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +0200214
Arnaldo Carvalho de Melo7be42152009-02-05 01:13:37 -0500215 trace_function(tr, ip, parent_ip, flags, preempt_count());
Steven Rostedt81d68a92008-05-12 21:20:42 +0200216
Steven Rostedtc5f888c2008-05-12 21:20:55 +0200217 per_cpu(tracing_cpu, cpu) = 1;
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +0200218
Steven Rostedt81d68a92008-05-12 21:20:42 +0200219 atomic_dec(&data->disabled);
220}
221
Ingo Molnare309b412008-05-12 21:20:51 +0200222static inline void
Steven Rostedt81d68a92008-05-12 21:20:42 +0200223stop_critical_timing(unsigned long ip, unsigned long parent_ip)
224{
225 int cpu;
226 struct trace_array *tr = irqsoff_trace;
227 struct trace_array_cpu *data;
228 unsigned long flags;
229
Steven Rostedtc5f888c2008-05-12 21:20:55 +0200230 cpu = raw_smp_processor_id();
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +0200231 /* Always clear the tracing cpu on stopping the trace */
Steven Rostedtc5f888c2008-05-12 21:20:55 +0200232 if (unlikely(per_cpu(tracing_cpu, cpu)))
233 per_cpu(tracing_cpu, cpu) = 0;
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +0200234 else
235 return;
236
237 if (!tracer_enabled)
Steven Rostedt81d68a92008-05-12 21:20:42 +0200238 return;
239
Steven Rostedt81d68a92008-05-12 21:20:42 +0200240 data = tr->data[cpu];
241
Steven Rostedt3928a8a2008-09-29 23:02:41 -0400242 if (unlikely(!data) ||
Steven Rostedt81d68a92008-05-12 21:20:42 +0200243 !data->critical_start || atomic_read(&data->disabled))
244 return;
245
246 atomic_inc(&data->disabled);
Steven Rostedtc5f888c2008-05-12 21:20:55 +0200247
Steven Rostedt81d68a92008-05-12 21:20:42 +0200248 local_save_flags(flags);
Arnaldo Carvalho de Melo7be42152009-02-05 01:13:37 -0500249 trace_function(tr, ip, parent_ip, flags, preempt_count());
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +0200250 check_critical_timing(tr, data, parent_ip ? : ip, cpu);
Steven Rostedt81d68a92008-05-12 21:20:42 +0200251 data->critical_start = 0;
252 atomic_dec(&data->disabled);
253}
254
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +0200255/* start and stop critical timings used to for stoppage (in idle) */
Ingo Molnare309b412008-05-12 21:20:51 +0200256void start_critical_timings(void)
Steven Rostedt81d68a92008-05-12 21:20:42 +0200257{
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +0200258 if (preempt_trace() || irq_trace())
Steven Rostedt81d68a92008-05-12 21:20:42 +0200259 start_critical_timing(CALLER_ADDR0, CALLER_ADDR1);
260}
Ingo Molnar1fe37102008-07-26 15:09:47 +0200261EXPORT_SYMBOL_GPL(start_critical_timings);
Steven Rostedt81d68a92008-05-12 21:20:42 +0200262
Ingo Molnare309b412008-05-12 21:20:51 +0200263void stop_critical_timings(void)
Steven Rostedt81d68a92008-05-12 21:20:42 +0200264{
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +0200265 if (preempt_trace() || irq_trace())
Steven Rostedt81d68a92008-05-12 21:20:42 +0200266 stop_critical_timing(CALLER_ADDR0, CALLER_ADDR1);
267}
Ingo Molnar1fe37102008-07-26 15:09:47 +0200268EXPORT_SYMBOL_GPL(stop_critical_timings);
Steven Rostedt81d68a92008-05-12 21:20:42 +0200269
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +0200270#ifdef CONFIG_IRQSOFF_TRACER
Steven Rostedt81d68a92008-05-12 21:20:42 +0200271#ifdef CONFIG_PROVE_LOCKING
Ingo Molnare309b412008-05-12 21:20:51 +0200272void time_hardirqs_on(unsigned long a0, unsigned long a1)
Steven Rostedt81d68a92008-05-12 21:20:42 +0200273{
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +0200274 if (!preempt_trace() && irq_trace())
Steven Rostedt81d68a92008-05-12 21:20:42 +0200275 stop_critical_timing(a0, a1);
276}
277
Ingo Molnare309b412008-05-12 21:20:51 +0200278void time_hardirqs_off(unsigned long a0, unsigned long a1)
Steven Rostedt81d68a92008-05-12 21:20:42 +0200279{
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +0200280 if (!preempt_trace() && irq_trace())
Steven Rostedt81d68a92008-05-12 21:20:42 +0200281 start_critical_timing(a0, a1);
282}
283
284#else /* !CONFIG_PROVE_LOCKING */
285
286/*
287 * Stubs:
288 */
289
290void early_boot_irqs_off(void)
291{
292}
293
294void early_boot_irqs_on(void)
295{
296}
297
298void trace_softirqs_on(unsigned long ip)
299{
300}
301
302void trace_softirqs_off(unsigned long ip)
303{
304}
305
Ingo Molnare309b412008-05-12 21:20:51 +0200306inline void print_irqtrace_events(struct task_struct *curr)
Steven Rostedt81d68a92008-05-12 21:20:42 +0200307{
308}
309
310/*
311 * We are only interested in hardirq on/off events:
312 */
Ingo Molnare309b412008-05-12 21:20:51 +0200313void trace_hardirqs_on(void)
Steven Rostedt81d68a92008-05-12 21:20:42 +0200314{
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +0200315 if (!preempt_trace() && irq_trace())
Steven Rostedt81d68a92008-05-12 21:20:42 +0200316 stop_critical_timing(CALLER_ADDR0, CALLER_ADDR1);
317}
318EXPORT_SYMBOL(trace_hardirqs_on);
319
Ingo Molnare309b412008-05-12 21:20:51 +0200320void trace_hardirqs_off(void)
Steven Rostedt81d68a92008-05-12 21:20:42 +0200321{
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +0200322 if (!preempt_trace() && irq_trace())
Steven Rostedt81d68a92008-05-12 21:20:42 +0200323 start_critical_timing(CALLER_ADDR0, CALLER_ADDR1);
324}
325EXPORT_SYMBOL(trace_hardirqs_off);
326
Ingo Molnare309b412008-05-12 21:20:51 +0200327void trace_hardirqs_on_caller(unsigned long caller_addr)
Steven Rostedt81d68a92008-05-12 21:20:42 +0200328{
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +0200329 if (!preempt_trace() && irq_trace())
Steven Rostedt81d68a92008-05-12 21:20:42 +0200330 stop_critical_timing(CALLER_ADDR0, caller_addr);
331}
332EXPORT_SYMBOL(trace_hardirqs_on_caller);
333
Ingo Molnare309b412008-05-12 21:20:51 +0200334void trace_hardirqs_off_caller(unsigned long caller_addr)
Steven Rostedt81d68a92008-05-12 21:20:42 +0200335{
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +0200336 if (!preempt_trace() && irq_trace())
Steven Rostedt81d68a92008-05-12 21:20:42 +0200337 start_critical_timing(CALLER_ADDR0, caller_addr);
338}
339EXPORT_SYMBOL(trace_hardirqs_off_caller);
340
341#endif /* CONFIG_PROVE_LOCKING */
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +0200342#endif /* CONFIG_IRQSOFF_TRACER */
343
344#ifdef CONFIG_PREEMPT_TRACER
Ingo Molnare309b412008-05-12 21:20:51 +0200345void trace_preempt_on(unsigned long a0, unsigned long a1)
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +0200346{
Steven Rostedt1e01cb02008-07-15 09:53:37 -0400347 if (preempt_trace())
348 stop_critical_timing(a0, a1);
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +0200349}
350
Ingo Molnare309b412008-05-12 21:20:51 +0200351void trace_preempt_off(unsigned long a0, unsigned long a1)
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +0200352{
Steven Rostedt1e01cb02008-07-15 09:53:37 -0400353 if (preempt_trace())
354 start_critical_timing(a0, a1);
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +0200355}
356#endif /* CONFIG_PREEMPT_TRACER */
Steven Rostedt81d68a92008-05-12 21:20:42 +0200357
358static void start_irqsoff_tracer(struct trace_array *tr)
359{
Steven Rostedt81d68a92008-05-12 21:20:42 +0200360 register_ftrace_function(&trace_ops);
Steven Rostedt94523e82009-01-22 11:18:06 -0500361 if (tracing_is_enabled())
Steven Rostedt90369902008-11-05 16:05:44 -0500362 tracer_enabled = 1;
Steven Rostedt94523e82009-01-22 11:18:06 -0500363 else
Steven Rostedt90369902008-11-05 16:05:44 -0500364 tracer_enabled = 0;
Steven Rostedt81d68a92008-05-12 21:20:42 +0200365}
366
367static void stop_irqsoff_tracer(struct trace_array *tr)
368{
Steven Rostedt81d68a92008-05-12 21:20:42 +0200369 tracer_enabled = 0;
Steven Rostedt89b2f972008-05-12 21:20:44 +0200370 unregister_ftrace_function(&trace_ops);
Steven Rostedt81d68a92008-05-12 21:20:42 +0200371}
372
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +0200373static void __irqsoff_tracer_init(struct trace_array *tr)
Steven Rostedt81d68a92008-05-12 21:20:42 +0200374{
Steven Rostedte9d25fe2009-03-04 22:15:30 -0500375 save_lat_flag = trace_flags & TRACE_ITER_LATENCY_FMT;
376 trace_flags |= TRACE_ITER_LATENCY_FMT;
377
Steven Rostedt745b1622009-01-15 23:40:11 -0500378 tracing_max_latency = 0;
Steven Rostedt81d68a92008-05-12 21:20:42 +0200379 irqsoff_trace = tr;
Steven Rostedtc5f888c2008-05-12 21:20:55 +0200380 /* make sure that the tracer is visible */
Steven Rostedt81d68a92008-05-12 21:20:42 +0200381 smp_wmb();
Steven Rostedtc76f0692008-11-07 22:36:02 -0500382 start_irqsoff_tracer(tr);
Steven Rostedt81d68a92008-05-12 21:20:42 +0200383}
384
385static void irqsoff_tracer_reset(struct trace_array *tr)
386{
Steven Rostedtc76f0692008-11-07 22:36:02 -0500387 stop_irqsoff_tracer(tr);
Steven Rostedte9d25fe2009-03-04 22:15:30 -0500388
389 if (!save_lat_flag)
390 trace_flags &= ~TRACE_ITER_LATENCY_FMT;
Steven Rostedt81d68a92008-05-12 21:20:42 +0200391}
392
Steven Rostedt90369902008-11-05 16:05:44 -0500393static void irqsoff_tracer_start(struct trace_array *tr)
394{
Steven Rostedt90369902008-11-05 16:05:44 -0500395 tracer_enabled = 1;
Steven Rostedt90369902008-11-05 16:05:44 -0500396}
397
398static void irqsoff_tracer_stop(struct trace_array *tr)
399{
400 tracer_enabled = 0;
Steven Rostedt81d68a92008-05-12 21:20:42 +0200401}
402
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +0200403#ifdef CONFIG_IRQSOFF_TRACER
Frederic Weisbecker1c800252008-11-16 05:57:26 +0100404static int irqsoff_tracer_init(struct trace_array *tr)
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +0200405{
406 trace_type = TRACER_IRQS_OFF;
407
408 __irqsoff_tracer_init(tr);
Frederic Weisbecker1c800252008-11-16 05:57:26 +0100409 return 0;
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +0200410}
Steven Rostedt81d68a92008-05-12 21:20:42 +0200411static struct tracer irqsoff_tracer __read_mostly =
412{
413 .name = "irqsoff",
414 .init = irqsoff_tracer_init,
415 .reset = irqsoff_tracer_reset,
Steven Rostedt90369902008-11-05 16:05:44 -0500416 .start = irqsoff_tracer_start,
417 .stop = irqsoff_tracer_stop,
Steven Rostedt81d68a92008-05-12 21:20:42 +0200418 .print_max = 1,
Steven Rostedt60a11772008-05-12 21:20:44 +0200419#ifdef CONFIG_FTRACE_SELFTEST
420 .selftest = trace_selftest_startup_irqsoff,
421#endif
Steven Rostedt81d68a92008-05-12 21:20:42 +0200422};
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +0200423# define register_irqsoff(trace) register_tracer(&trace)
424#else
425# define register_irqsoff(trace) do { } while (0)
426#endif
427
428#ifdef CONFIG_PREEMPT_TRACER
Frederic Weisbecker1c800252008-11-16 05:57:26 +0100429static int preemptoff_tracer_init(struct trace_array *tr)
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +0200430{
431 trace_type = TRACER_PREEMPT_OFF;
432
433 __irqsoff_tracer_init(tr);
Frederic Weisbecker1c800252008-11-16 05:57:26 +0100434 return 0;
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +0200435}
436
437static struct tracer preemptoff_tracer __read_mostly =
438{
439 .name = "preemptoff",
440 .init = preemptoff_tracer_init,
441 .reset = irqsoff_tracer_reset,
Steven Rostedt90369902008-11-05 16:05:44 -0500442 .start = irqsoff_tracer_start,
443 .stop = irqsoff_tracer_stop,
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +0200444 .print_max = 1,
Steven Rostedt60a11772008-05-12 21:20:44 +0200445#ifdef CONFIG_FTRACE_SELFTEST
446 .selftest = trace_selftest_startup_preemptoff,
447#endif
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +0200448};
449# define register_preemptoff(trace) register_tracer(&trace)
450#else
451# define register_preemptoff(trace) do { } while (0)
452#endif
453
454#if defined(CONFIG_IRQSOFF_TRACER) && \
455 defined(CONFIG_PREEMPT_TRACER)
456
Frederic Weisbecker1c800252008-11-16 05:57:26 +0100457static int preemptirqsoff_tracer_init(struct trace_array *tr)
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +0200458{
459 trace_type = TRACER_IRQS_OFF | TRACER_PREEMPT_OFF;
460
461 __irqsoff_tracer_init(tr);
Frederic Weisbecker1c800252008-11-16 05:57:26 +0100462 return 0;
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +0200463}
464
465static struct tracer preemptirqsoff_tracer __read_mostly =
466{
467 .name = "preemptirqsoff",
468 .init = preemptirqsoff_tracer_init,
469 .reset = irqsoff_tracer_reset,
Steven Rostedt90369902008-11-05 16:05:44 -0500470 .start = irqsoff_tracer_start,
471 .stop = irqsoff_tracer_stop,
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +0200472 .print_max = 1,
Steven Rostedt60a11772008-05-12 21:20:44 +0200473#ifdef CONFIG_FTRACE_SELFTEST
474 .selftest = trace_selftest_startup_preemptirqsoff,
475#endif
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +0200476};
477
478# define register_preemptirqsoff(trace) register_tracer(&trace)
479#else
480# define register_preemptirqsoff(trace) do { } while (0)
481#endif
Steven Rostedt81d68a92008-05-12 21:20:42 +0200482
483__init static int init_irqsoff_tracer(void)
484{
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +0200485 register_irqsoff(irqsoff_tracer);
486 register_preemptoff(preemptoff_tracer);
487 register_preemptirqsoff(preemptirqsoff_tracer);
Steven Rostedt81d68a92008-05-12 21:20:42 +0200488
489 return 0;
490}
491device_initcall(init_irqsoff_tracer);