1 // SPDX-License-Identifier: GPL-2.0
3 * preemptoff and irqoff tracepoints
5 * Copyright (C) Joel Fernandes (Google) <joel@joelfernandes.org>
8 #include <linux/kallsyms.h>
9 #include <linux/uaccess.h>
10 #include <linux/module.h>
11 #include <linux/ftrace.h>
14 #define CREATE_TRACE_POINTS
15 #include <trace/events/preemptirq.h>
17 #ifdef CONFIG_TRACE_IRQFLAGS
18 /* Per-cpu variable to prevent redundant calls when IRQs already off */
19 static DEFINE_PER_CPU(int, tracing_irq_cpu);
21 void trace_hardirqs_on(void)
23 if (this_cpu_read(tracing_irq_cpu)) {
25 trace_irq_enable_rcuidle(CALLER_ADDR0, CALLER_ADDR1);
26 tracer_hardirqs_on(CALLER_ADDR0, CALLER_ADDR1);
27 this_cpu_write(tracing_irq_cpu, 0);
30 lockdep_hardirqs_on(CALLER_ADDR0);
32 EXPORT_SYMBOL(trace_hardirqs_on);
34 void trace_hardirqs_off(void)
36 if (!this_cpu_read(tracing_irq_cpu)) {
37 this_cpu_write(tracing_irq_cpu, 1);
38 tracer_hardirqs_off(CALLER_ADDR0, CALLER_ADDR1);
40 trace_irq_disable_rcuidle(CALLER_ADDR0, CALLER_ADDR1);
43 lockdep_hardirqs_off(CALLER_ADDR0);
45 EXPORT_SYMBOL(trace_hardirqs_off);
47 __visible void trace_hardirqs_on_caller(unsigned long caller_addr)
49 if (this_cpu_read(tracing_irq_cpu)) {
51 trace_irq_enable_rcuidle(CALLER_ADDR0, caller_addr);
52 tracer_hardirqs_on(CALLER_ADDR0, caller_addr);
53 this_cpu_write(tracing_irq_cpu, 0);
56 lockdep_hardirqs_on(CALLER_ADDR0);
58 EXPORT_SYMBOL(trace_hardirqs_on_caller);
60 __visible void trace_hardirqs_off_caller(unsigned long caller_addr)
62 lockdep_hardirqs_off(CALLER_ADDR0);
64 if (!this_cpu_read(tracing_irq_cpu)) {
65 this_cpu_write(tracing_irq_cpu, 1);
66 tracer_hardirqs_off(CALLER_ADDR0, caller_addr);
68 trace_irq_disable_rcuidle(CALLER_ADDR0, caller_addr);
71 EXPORT_SYMBOL(trace_hardirqs_off_caller);
72 #endif /* CONFIG_TRACE_IRQFLAGS */
74 #ifdef CONFIG_TRACE_PREEMPT_TOGGLE
76 void trace_preempt_on(unsigned long a0, unsigned long a1)
79 trace_preempt_enable_rcuidle(a0, a1);
80 tracer_preempt_on(a0, a1);
83 void trace_preempt_off(unsigned long a0, unsigned long a1)
86 trace_preempt_disable_rcuidle(a0, a1);
87 tracer_preempt_off(a0, a1);