trace_irqsoff.c 17.3 KB
Newer Older
1
/*
2
 * trace irqs off critical timings
3 4 5 6 7 8 9
 *
 * Copyright (C) 2007-2008 Steven Rostedt <srostedt@redhat.com>
 * Copyright (C) 2008 Ingo Molnar <mingo@redhat.com>
 *
 * From code in the latency_tracer, that is:
 *
 *  Copyright (C) 2004-2006 Ingo Molnar
10
 *  Copyright (C) 2004 Nadia Yvette Chambers
11 12 13 14 15 16 17 18 19 20 21
 */
#include <linux/kallsyms.h>
#include <linux/uaccess.h>
#include <linux/module.h>
#include <linux/ftrace.h>

#include "trace.h"

static struct trace_array		*irqsoff_trace __read_mostly;
static int				tracer_enabled __read_mostly;

22 23
static DEFINE_PER_CPU(int, tracing_cpu);

24
static DEFINE_RAW_SPINLOCK(max_trace_lock);
25

26 27 28 29 30 31 32
enum {
	TRACER_IRQS_OFF		= (1 << 1),
	TRACER_PREEMPT_OFF	= (1 << 2),
};

static int trace_type __read_mostly;

33
static int save_flags;
34
static bool function_enabled;
35

36 37 38
static void stop_irqsoff_tracer(struct trace_array *tr, int graph);
static int start_irqsoff_tracer(struct trace_array *tr, int graph);

39
#ifdef CONFIG_PREEMPT_TRACER
I
Ingo Molnar 已提交
40
static inline int
41 42 43 44 45 46 47 48 49
preempt_trace(void)
{
	return ((trace_type & TRACER_PREEMPT_OFF) && preempt_count());
}
#else
# define preempt_trace() (0)
#endif

#ifdef CONFIG_IRQSOFF_TRACER
I
Ingo Molnar 已提交
50
static inline int
51 52 53 54 55 56 57 58 59
irq_trace(void)
{
	return ((trace_type & TRACER_IRQS_OFF) &&
		irqs_disabled());
}
#else
# define irq_trace() (0)
#endif

60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
#define TRACE_DISPLAY_GRAPH	1

static struct tracer_opt trace_opts[] = {
#ifdef CONFIG_FUNCTION_GRAPH_TRACER
	/* display latency trace as call graph */
	{ TRACER_OPT(display-graph, TRACE_DISPLAY_GRAPH) },
#endif
	{ } /* Empty entry */
};

static struct tracer_flags tracer_flags = {
	.val  = 0,
	.opts = trace_opts,
};

#define is_graph() (tracer_flags.val & TRACE_DISPLAY_GRAPH)

77 78 79 80 81
/*
 * Sequence count - we record it when starting a measurement and
 * skip the latency if the sequence has changed - some other section
 * did a maximum and could disturb our measurement with serial console
 * printouts, etc. Truly coinciding maximum latencies should be rare
L
Lucas De Marchi 已提交
82
 * and what happens together happens separately as well, so this doesn't
83 84 85 86
 * decrease the validity of the maximum found:
 */
static __cacheline_aligned_in_smp	unsigned long max_sequence;

87
#ifdef CONFIG_FUNCTION_TRACER
88
/*
89 90 91 92 93 94 95 96 97 98 99
 * Prologue for the preempt and irqs off function tracers.
 *
 * Returns 1 if it is OK to continue, and data->disabled is
 *            incremented.
 *         0 if the trace is to be ignored, and data->disabled
 *            is kept the same.
 *
 * Note, this function is also used outside this ifdef but
 *  inside the #ifdef of the function graph tracer below.
 *  This is OK, since the function graph tracer is
 *  dependent on the function tracer.
100
 */
101 102 103
static int func_prolog_dec(struct trace_array *tr,
			   struct trace_array_cpu **data,
			   unsigned long *flags)
104 105 106 107
{
	long disabled;
	int cpu;

108 109 110 111 112 113 114 115
	/*
	 * Does not matter if we preempt. We test the flags
	 * afterward, to see if irqs are disabled or not.
	 * If we preempt and get a false positive, the flags
	 * test will fail.
	 */
	cpu = raw_smp_processor_id();
	if (likely(!per_cpu(tracing_cpu, cpu)))
116
		return 0;
117

118
	local_save_flags(*flags);
119
	/* slight chance to get a false positive on tracing_cpu */
120 121
	if (!irqs_disabled_flags(*flags))
		return 0;
122

123
	*data = per_cpu_ptr(tr->trace_buffer.data, cpu);
124
	disabled = atomic_inc_return(&(*data)->disabled);
125 126

	if (likely(disabled == 1))
127 128 129 130 131 132 133 134 135 136 137
		return 1;

	atomic_dec(&(*data)->disabled);

	return 0;
}

/*
 * irqsoff uses its own tracer function to keep the overhead down:
 */
static void
138
irqsoff_tracer_call(unsigned long ip, unsigned long parent_ip,
139
		    struct ftrace_ops *op, struct pt_regs *pt_regs)
140 141 142 143 144 145 146 147 148
{
	struct trace_array *tr = irqsoff_trace;
	struct trace_array_cpu *data;
	unsigned long flags;

	if (!func_prolog_dec(tr, &data, &flags))
		return;

	trace_function(tr, ip, parent_ip, flags, preempt_count());
149 150 151

	atomic_dec(&data->disabled);
}
152
#endif /* CONFIG_FUNCTION_TRACER */
153

154
#ifdef CONFIG_FUNCTION_GRAPH_TRACER
155 156
static int
irqsoff_set_flag(struct trace_array *tr, u32 old_flags, u32 bit, int set)
157 158 159 160 161 162 163 164 165 166 167 168 169 170
{
	int cpu;

	if (!(bit & TRACE_DISPLAY_GRAPH))
		return -EINVAL;

	if (!(is_graph() ^ set))
		return 0;

	stop_irqsoff_tracer(irqsoff_trace, !set);

	for_each_possible_cpu(cpu)
		per_cpu(tracing_cpu, cpu) = 0;

171
	tr->max_latency = 0;
172
	tracing_reset_online_cpus(&irqsoff_trace->trace_buffer);
173 174 175 176 177 178 179 180 181 182 183 184

	return start_irqsoff_tracer(irqsoff_trace, set);
}

static int irqsoff_graph_entry(struct ftrace_graph_ent *trace)
{
	struct trace_array *tr = irqsoff_trace;
	struct trace_array_cpu *data;
	unsigned long flags;
	int ret;
	int pc;

185
	if (!func_prolog_dec(tr, &data, &flags))
186 187
		return 0;

188 189
	pc = preempt_count();
	ret = __trace_graph_entry(tr, trace, flags, pc);
190
	atomic_dec(&data->disabled);
191

192 193 194 195 196 197 198 199 200 201
	return ret;
}

static void irqsoff_graph_return(struct ftrace_graph_ret *trace)
{
	struct trace_array *tr = irqsoff_trace;
	struct trace_array_cpu *data;
	unsigned long flags;
	int pc;

202
	if (!func_prolog_dec(tr, &data, &flags))
203 204
		return;

205 206
	pc = preempt_count();
	__trace_graph_return(tr, trace, flags, pc);
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
	atomic_dec(&data->disabled);
}

static void irqsoff_trace_open(struct trace_iterator *iter)
{
	if (is_graph())
		graph_trace_open(iter);

}

static void irqsoff_trace_close(struct trace_iterator *iter)
{
	if (iter->private)
		graph_trace_close(iter);
}

#define GRAPH_TRACER_FLAGS (TRACE_GRAPH_PRINT_CPU | \
224 225 226
			    TRACE_GRAPH_PRINT_PROC | \
			    TRACE_GRAPH_PRINT_ABS_TIME | \
			    TRACE_GRAPH_PRINT_DURATION)
227 228 229 230 231 232 233 234

static enum print_line_t irqsoff_print_line(struct trace_iterator *iter)
{
	/*
	 * In graph mode call the graph tracer output function,
	 * otherwise go with the TRACE_FN event handler
	 */
	if (is_graph())
235
		return print_graph_function_flags(iter, GRAPH_TRACER_FLAGS);
236 237 238 239 240 241

	return TRACE_TYPE_UNHANDLED;
}

static void irqsoff_print_header(struct seq_file *s)
{
242 243 244
	if (is_graph())
		print_graph_headers_flags(s, GRAPH_TRACER_FLAGS);
	else
245 246 247 248 249 250 251 252
		trace_default_header(s);
}

static void
__trace_function(struct trace_array *tr,
		 unsigned long ip, unsigned long parent_ip,
		 unsigned long flags, int pc)
{
253 254 255
	if (is_graph())
		trace_graph_function(tr, ip, parent_ip, flags, pc);
	else
256 257 258 259 260 261
		trace_function(tr, ip, parent_ip, flags, pc);
}

#else
#define __trace_function trace_function

262 263
static int
irqsoff_set_flag(struct trace_array *tr, u32 old_flags, u32 bit, int set)
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280
{
	return -EINVAL;
}

static int irqsoff_graph_entry(struct ftrace_graph_ent *trace)
{
	return -1;
}

static enum print_line_t irqsoff_print_line(struct trace_iterator *iter)
{
	return TRACE_TYPE_UNHANDLED;
}

static void irqsoff_graph_return(struct ftrace_graph_ret *trace) { }
static void irqsoff_trace_open(struct trace_iterator *iter) { }
static void irqsoff_trace_close(struct trace_iterator *iter) { }
281 282 283 284 285 286 287 288 289 290 291 292

#ifdef CONFIG_FUNCTION_TRACER
static void irqsoff_print_header(struct seq_file *s)
{
	trace_default_header(s);
}
#else
static void irqsoff_print_header(struct seq_file *s)
{
	trace_latency_header(s);
}
#endif /* CONFIG_FUNCTION_TRACER */
293 294
#endif /* CONFIG_FUNCTION_GRAPH_TRACER */

295 296 297
/*
 * Should this new latency be reported/recorded?
 */
298
static int report_latency(struct trace_array *tr, cycle_t delta)
299 300 301 302 303
{
	if (tracing_thresh) {
		if (delta < tracing_thresh)
			return 0;
	} else {
304
		if (delta <= tr->max_latency)
305 306 307 308 309
			return 0;
	}
	return 1;
}

I
Ingo Molnar 已提交
310
static void
311 312 313 314 315
check_critical_timing(struct trace_array *tr,
		      struct trace_array_cpu *data,
		      unsigned long parent_ip,
		      int cpu)
{
316
	cycle_t T0, T1, delta;
317
	unsigned long flags;
318
	int pc;
319 320

	T0 = data->preempt_timestamp;
I
Ingo Molnar 已提交
321
	T1 = ftrace_now(cpu);
322 323 324 325
	delta = T1-T0;

	local_save_flags(flags);

326 327
	pc = preempt_count();

328
	if (!report_latency(tr, delta))
329 330
		goto out;

331
	raw_spin_lock_irqsave(&max_trace_lock, flags);
332

333
	/* check if we are still the max latency */
334
	if (!report_latency(tr, delta))
335 336
		goto out_unlock;

337
	__trace_function(tr, CALLER_ADDR0, parent_ip, flags, pc);
338 339
	/* Skip 5 functions to get to the irq/preempt enable function */
	__trace_stack(tr, flags, 5, pc);
340 341

	if (data->critical_sequence != max_sequence)
342
		goto out_unlock;
343 344 345

	data->critical_end = parent_ip;

346
	if (likely(!is_tracing_stopped())) {
347
		tr->max_latency = delta;
348 349
		update_max_tr_single(tr, current, cpu);
	}
350 351 352

	max_sequence++;

353
out_unlock:
354
	raw_spin_unlock_irqrestore(&max_trace_lock, flags);
355

356 357
out:
	data->critical_sequence = max_sequence;
I
Ingo Molnar 已提交
358
	data->preempt_timestamp = ftrace_now(cpu);
359
	__trace_function(tr, CALLER_ADDR0, parent_ip, flags, pc);
360 361
}

I
Ingo Molnar 已提交
362
static inline void
363 364 365 366 367 368 369
start_critical_timing(unsigned long ip, unsigned long parent_ip)
{
	int cpu;
	struct trace_array *tr = irqsoff_trace;
	struct trace_array_cpu *data;
	unsigned long flags;

370
	if (!tracer_enabled || !tracing_is_enabled())
371 372
		return;

373 374 375
	cpu = raw_smp_processor_id();

	if (per_cpu(tracing_cpu, cpu))
376 377
		return;

378
	data = per_cpu_ptr(tr->trace_buffer.data, cpu);
379

380
	if (unlikely(!data) || atomic_read(&data->disabled))
381 382 383 384 385
		return;

	atomic_inc(&data->disabled);

	data->critical_sequence = max_sequence;
I
Ingo Molnar 已提交
386
	data->preempt_timestamp = ftrace_now(cpu);
387
	data->critical_start = parent_ip ? : ip;
388 389

	local_save_flags(flags);
390

391
	__trace_function(tr, ip, parent_ip, flags, preempt_count());
392

393
	per_cpu(tracing_cpu, cpu) = 1;
394

395 396 397
	atomic_dec(&data->disabled);
}

I
Ingo Molnar 已提交
398
static inline void
399 400 401 402 403 404 405
stop_critical_timing(unsigned long ip, unsigned long parent_ip)
{
	int cpu;
	struct trace_array *tr = irqsoff_trace;
	struct trace_array_cpu *data;
	unsigned long flags;

406
	cpu = raw_smp_processor_id();
407
	/* Always clear the tracing cpu on stopping the trace */
408 409
	if (unlikely(per_cpu(tracing_cpu, cpu)))
		per_cpu(tracing_cpu, cpu) = 0;
410 411 412
	else
		return;

413
	if (!tracer_enabled || !tracing_is_enabled())
414 415
		return;

416
	data = per_cpu_ptr(tr->trace_buffer.data, cpu);
417

418
	if (unlikely(!data) ||
419 420 421 422
	    !data->critical_start || atomic_read(&data->disabled))
		return;

	atomic_inc(&data->disabled);
423

424
	local_save_flags(flags);
425
	__trace_function(tr, ip, parent_ip, flags, preempt_count());
426
	check_critical_timing(tr, data, parent_ip ? : ip, cpu);
427 428 429 430
	data->critical_start = 0;
	atomic_dec(&data->disabled);
}

431
/* start and stop critical timings used to for stoppage (in idle) */
I
Ingo Molnar 已提交
432
void start_critical_timings(void)
433
{
434
	if (preempt_trace() || irq_trace())
435 436
		start_critical_timing(CALLER_ADDR0, CALLER_ADDR1);
}
I
Ingo Molnar 已提交
437
EXPORT_SYMBOL_GPL(start_critical_timings);
438

I
Ingo Molnar 已提交
439
void stop_critical_timings(void)
440
{
441
	if (preempt_trace() || irq_trace())
442 443
		stop_critical_timing(CALLER_ADDR0, CALLER_ADDR1);
}
I
Ingo Molnar 已提交
444
EXPORT_SYMBOL_GPL(stop_critical_timings);
445

446
#ifdef CONFIG_IRQSOFF_TRACER
447
#ifdef CONFIG_PROVE_LOCKING
I
Ingo Molnar 已提交
448
void time_hardirqs_on(unsigned long a0, unsigned long a1)
449
{
450
	if (!preempt_trace() && irq_trace())
451 452 453
		stop_critical_timing(a0, a1);
}

I
Ingo Molnar 已提交
454
void time_hardirqs_off(unsigned long a0, unsigned long a1)
455
{
456
	if (!preempt_trace() && irq_trace())
457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473
		start_critical_timing(a0, a1);
}

#else /* !CONFIG_PROVE_LOCKING */

/*
 * Stubs:
 */

void trace_softirqs_on(unsigned long ip)
{
}

void trace_softirqs_off(unsigned long ip)
{
}

I
Ingo Molnar 已提交
474
inline void print_irqtrace_events(struct task_struct *curr)
475 476 477 478 479 480
{
}

/*
 * We are only interested in hardirq on/off events:
 */
I
Ingo Molnar 已提交
481
void trace_hardirqs_on(void)
482
{
483
	if (!preempt_trace() && irq_trace())
484 485 486 487
		stop_critical_timing(CALLER_ADDR0, CALLER_ADDR1);
}
EXPORT_SYMBOL(trace_hardirqs_on);

I
Ingo Molnar 已提交
488
void trace_hardirqs_off(void)
489
{
490
	if (!preempt_trace() && irq_trace())
491 492 493 494
		start_critical_timing(CALLER_ADDR0, CALLER_ADDR1);
}
EXPORT_SYMBOL(trace_hardirqs_off);

495
__visible void trace_hardirqs_on_caller(unsigned long caller_addr)
496
{
497
	if (!preempt_trace() && irq_trace())
498 499 500 501
		stop_critical_timing(CALLER_ADDR0, caller_addr);
}
EXPORT_SYMBOL(trace_hardirqs_on_caller);

502
__visible void trace_hardirqs_off_caller(unsigned long caller_addr)
503
{
504
	if (!preempt_trace() && irq_trace())
505 506 507 508 509
		start_critical_timing(CALLER_ADDR0, caller_addr);
}
EXPORT_SYMBOL(trace_hardirqs_off_caller);

#endif /* CONFIG_PROVE_LOCKING */
510 511 512
#endif /*  CONFIG_IRQSOFF_TRACER */

#ifdef CONFIG_PREEMPT_TRACER
I
Ingo Molnar 已提交
513
void trace_preempt_on(unsigned long a0, unsigned long a1)
514
{
515
	if (preempt_trace() && !irq_trace())
516
		stop_critical_timing(a0, a1);
517 518
}

I
Ingo Molnar 已提交
519
void trace_preempt_off(unsigned long a0, unsigned long a1)
520
{
521
	if (preempt_trace() && !irq_trace())
522
		start_critical_timing(a0, a1);
523 524
}
#endif /* CONFIG_PREEMPT_TRACER */
525

526
static int register_irqsoff_function(struct trace_array *tr, int graph, int set)
527
{
528
	int ret;
529

530 531 532 533 534
	/* 'set' is set if TRACE_ITER_FUNCTION is about to be set */
	if (function_enabled || (!set && !(trace_flags & TRACE_ITER_FUNCTION)))
		return 0;

	if (graph)
535 536
		ret = register_ftrace_graph(&irqsoff_graph_return,
					    &irqsoff_graph_entry);
537
	else
538
		ret = register_ftrace_function(tr->ops);
539 540 541 542 543 544 545

	if (!ret)
		function_enabled = true;

	return ret;
}

546
static void unregister_irqsoff_function(struct trace_array *tr, int graph)
547 548 549 550 551 552 553
{
	if (!function_enabled)
		return;

	if (graph)
		unregister_ftrace_graph();
	else
554
		unregister_ftrace_function(tr->ops);
555 556 557 558

	function_enabled = false;
}

559
static void irqsoff_function_set(struct trace_array *tr, int set)
560 561
{
	if (set)
562
		register_irqsoff_function(tr, is_graph(), 1);
563
	else
564
		unregister_irqsoff_function(tr, is_graph());
565 566
}

567
static int irqsoff_flag_changed(struct trace_array *tr, u32 mask, int set)
568
{
569 570
	struct tracer *tracer = tr->current_trace;

571
	if (mask & TRACE_ITER_FUNCTION)
572
		irqsoff_function_set(tr, set);
573 574 575 576 577 578 579 580

	return trace_keep_overwrite(tracer, mask, set);
}

static int start_irqsoff_tracer(struct trace_array *tr, int graph)
{
	int ret;

581
	ret = register_irqsoff_function(tr, graph, 0);
582 583

	if (!ret && tracing_is_enabled())
584
		tracer_enabled = 1;
585
	else
586
		tracer_enabled = 0;
587 588

	return ret;
589 590
}

591
static void stop_irqsoff_tracer(struct trace_array *tr, int graph)
592 593
{
	tracer_enabled = 0;
594

595
	unregister_irqsoff_function(tr, graph);
596 597
}

598 599 600
static bool irqsoff_busy;

static int __irqsoff_tracer_init(struct trace_array *tr)
601
{
602 603 604
	if (irqsoff_busy)
		return -EBUSY;

605 606 607
	save_flags = trace_flags;

	/* non overwrite screws up the latency tracers */
608 609
	set_tracer_flag(tr, TRACE_ITER_OVERWRITE, 1);
	set_tracer_flag(tr, TRACE_ITER_LATENCY_FMT, 1);
610

611
	tr->max_latency = 0;
612
	irqsoff_trace = tr;
613
	/* make sure that the tracer is visible */
614
	smp_wmb();
615
	tracing_reset_online_cpus(&tr->trace_buffer);
616

617 618 619 620 621
	ftrace_init_array_ops(tr, irqsoff_tracer_call);

	/* Only toplevel instance supports graph tracing */
	if (start_irqsoff_tracer(tr, (tr->flags & TRACE_ARRAY_FL_GLOBAL &&
				      is_graph())))
622
		printk(KERN_ERR "failed to start irqsoff tracer\n");
623 624 625

	irqsoff_busy = true;
	return 0;
626 627 628 629
}

static void irqsoff_tracer_reset(struct trace_array *tr)
{
630 631 632
	int lat_flag = save_flags & TRACE_ITER_LATENCY_FMT;
	int overwrite_flag = save_flags & TRACE_ITER_OVERWRITE;

633
	stop_irqsoff_tracer(tr, is_graph());
634

635 636
	set_tracer_flag(tr, TRACE_ITER_LATENCY_FMT, lat_flag);
	set_tracer_flag(tr, TRACE_ITER_OVERWRITE, overwrite_flag);
637
	ftrace_reset_array_ops(tr);
638 639

	irqsoff_busy = false;
640 641
}

642 643 644 645 646 647 648 649
static void irqsoff_tracer_start(struct trace_array *tr)
{
	tracer_enabled = 1;
}

static void irqsoff_tracer_stop(struct trace_array *tr)
{
	tracer_enabled = 0;
650 651
}

652
#ifdef CONFIG_IRQSOFF_TRACER
653
static int irqsoff_tracer_init(struct trace_array *tr)
654 655 656
{
	trace_type = TRACER_IRQS_OFF;

657
	return __irqsoff_tracer_init(tr);
658
}
659 660 661 662 663
static struct tracer irqsoff_tracer __read_mostly =
{
	.name		= "irqsoff",
	.init		= irqsoff_tracer_init,
	.reset		= irqsoff_tracer_reset,
664 665
	.start		= irqsoff_tracer_start,
	.stop		= irqsoff_tracer_stop,
666
	.print_max	= true,
667 668 669 670
	.print_header   = irqsoff_print_header,
	.print_line     = irqsoff_print_line,
	.flags		= &tracer_flags,
	.set_flag	= irqsoff_set_flag,
671
	.flag_changed	= irqsoff_flag_changed,
S
Steven Rostedt 已提交
672 673 674
#ifdef CONFIG_FTRACE_SELFTEST
	.selftest    = trace_selftest_startup_irqsoff,
#endif
675 676
	.open           = irqsoff_trace_open,
	.close          = irqsoff_trace_close,
677
	.allow_instances = true,
678
	.use_max_tr	= true,
679
};
680 681 682 683 684 685
# define register_irqsoff(trace) register_tracer(&trace)
#else
# define register_irqsoff(trace) do { } while (0)
#endif

#ifdef CONFIG_PREEMPT_TRACER
686
static int preemptoff_tracer_init(struct trace_array *tr)
687 688 689
{
	trace_type = TRACER_PREEMPT_OFF;

690
	return __irqsoff_tracer_init(tr);
691 692 693 694 695 696 697
}

static struct tracer preemptoff_tracer __read_mostly =
{
	.name		= "preemptoff",
	.init		= preemptoff_tracer_init,
	.reset		= irqsoff_tracer_reset,
698 699
	.start		= irqsoff_tracer_start,
	.stop		= irqsoff_tracer_stop,
700
	.print_max	= true,
701 702 703 704
	.print_header   = irqsoff_print_header,
	.print_line     = irqsoff_print_line,
	.flags		= &tracer_flags,
	.set_flag	= irqsoff_set_flag,
705
	.flag_changed	= irqsoff_flag_changed,
S
Steven Rostedt 已提交
706 707 708
#ifdef CONFIG_FTRACE_SELFTEST
	.selftest    = trace_selftest_startup_preemptoff,
#endif
709 710
	.open		= irqsoff_trace_open,
	.close		= irqsoff_trace_close,
711
	.allow_instances = true,
712
	.use_max_tr	= true,
713 714 715 716 717 718 719 720 721
};
# define register_preemptoff(trace) register_tracer(&trace)
#else
# define register_preemptoff(trace) do { } while (0)
#endif

#if defined(CONFIG_IRQSOFF_TRACER) && \
	defined(CONFIG_PREEMPT_TRACER)

722
static int preemptirqsoff_tracer_init(struct trace_array *tr)
723 724 725
{
	trace_type = TRACER_IRQS_OFF | TRACER_PREEMPT_OFF;

726
	return __irqsoff_tracer_init(tr);
727 728 729 730 731 732 733
}

static struct tracer preemptirqsoff_tracer __read_mostly =
{
	.name		= "preemptirqsoff",
	.init		= preemptirqsoff_tracer_init,
	.reset		= irqsoff_tracer_reset,
734 735
	.start		= irqsoff_tracer_start,
	.stop		= irqsoff_tracer_stop,
736
	.print_max	= true,
737 738 739 740
	.print_header   = irqsoff_print_header,
	.print_line     = irqsoff_print_line,
	.flags		= &tracer_flags,
	.set_flag	= irqsoff_set_flag,
741
	.flag_changed	= irqsoff_flag_changed,
S
Steven Rostedt 已提交
742 743 744
#ifdef CONFIG_FTRACE_SELFTEST
	.selftest    = trace_selftest_startup_preemptirqsoff,
#endif
745 746
	.open		= irqsoff_trace_open,
	.close		= irqsoff_trace_close,
747
	.allow_instances = true,
748
	.use_max_tr	= true,
749 750 751 752 753 754
};

# define register_preemptirqsoff(trace) register_tracer(&trace)
#else
# define register_preemptirqsoff(trace) do { } while (0)
#endif
755 756 757

__init static int init_irqsoff_tracer(void)
{
758 759 760
	register_irqsoff(irqsoff_tracer);
	register_preemptoff(preemptoff_tracer);
	register_preemptirqsoff(preemptirqsoff_tracer);
761 762 763

	return 0;
}
764
core_initcall(init_irqsoff_tracer);