1 /* SPDX-License-Identifier: GPL-2.0 */
3 * include/linux/irqflags.h
5 * IRQ flags tracing: follow the state of the hardirq and softirq flags and
6 * provide callbacks for transitions between ON and OFF states.
8 * This file gets included from lowlevel asm headers too, to provide
9 * wrapped versions of the local_irq_*() APIs, based on the
10 * raw_local_irq_*() macros from the lowlevel headers.
12 #ifndef _LINUX_TRACE_IRQFLAGS_H
13 #define _LINUX_TRACE_IRQFLAGS_H
15 #include <linux/typecheck.h>
16 #include <asm/irqflags.h>
18 /* Currently trace_softirqs_on/off is used only by lockdep */
19 #ifdef CONFIG_PROVE_LOCKING
20 extern void trace_softirqs_on(unsigned long ip);
21 extern void trace_softirqs_off(unsigned long ip);
22 extern void lockdep_hardirqs_on(unsigned long ip);
23 extern void lockdep_hardirqs_off(unsigned long ip);
25 static inline void trace_softirqs_on(unsigned long ip) { }
26 static inline void trace_softirqs_off(unsigned long ip) { }
27 static inline void lockdep_hardirqs_on(unsigned long ip) { }
28 static inline void lockdep_hardirqs_off(unsigned long ip) { }
31 #ifdef CONFIG_TRACE_IRQFLAGS
32 extern void trace_hardirqs_on(void);
33 extern void trace_hardirqs_off(void);
34 # define trace_hardirq_context(p) ((p)->hardirq_context)
35 # define trace_softirq_context(p) ((p)->softirq_context)
36 # define trace_hardirqs_enabled(p) ((p)->hardirqs_enabled)
37 # define trace_softirqs_enabled(p) ((p)->softirqs_enabled)
38 # define trace_hardirq_enter() \
40 if (!current->hardirq_context++) \
41 current->hardirq_threaded = 0; \
43 # define trace_hardirq_threaded() \
45 current->hardirq_threaded = 1; \
47 # define trace_hardirq_exit() \
49 current->hardirq_context--; \
51 # define lockdep_softirq_enter() \
53 current->softirq_context++; \
55 # define lockdep_softirq_exit() \
57 current->softirq_context--; \
60 # define lockdep_hrtimer_enter(__hrtimer) \
62 if (!__hrtimer->is_hard) \
63 current->irq_config = 1; \
66 # define lockdep_hrtimer_exit(__hrtimer) \
68 if (!__hrtimer->is_hard) \
69 current->irq_config = 0; \
73 # define trace_hardirqs_on() do { } while (0)
74 # define trace_hardirqs_off() do { } while (0)
75 # define trace_hardirq_context(p) 0
76 # define trace_softirq_context(p) 0
77 # define trace_hardirqs_enabled(p) 0
78 # define trace_softirqs_enabled(p) 0
79 # define trace_hardirq_enter() do { } while (0)
80 # define trace_hardirq_threaded() do { } while (0)
81 # define trace_hardirq_exit() do { } while (0)
82 # define lockdep_softirq_enter() do { } while (0)
83 # define lockdep_softirq_exit() do { } while (0)
84 # define lockdep_hrtimer_enter(__hrtimer) do { } while (0)
85 # define lockdep_hrtimer_exit(__hrtimer) do { } while (0)
88 #if defined(CONFIG_IRQSOFF_TRACER) || \
89 defined(CONFIG_PREEMPT_TRACER)
90 extern void stop_critical_timings(void);
91 extern void start_critical_timings(void);
93 # define stop_critical_timings() do { } while (0)
94 # define start_critical_timings() do { } while (0)
98 * Wrap the arch provided IRQ routines to provide appropriate checks.
100 #define raw_local_irq_disable() arch_local_irq_disable()
101 #define raw_local_irq_enable() arch_local_irq_enable()
102 #define raw_local_irq_save(flags) \
104 typecheck(unsigned long, flags); \
105 flags = arch_local_irq_save(); \
107 #define raw_local_irq_restore(flags) \
109 typecheck(unsigned long, flags); \
110 arch_local_irq_restore(flags); \
112 #define raw_local_save_flags(flags) \
114 typecheck(unsigned long, flags); \
115 flags = arch_local_save_flags(); \
117 #define raw_irqs_disabled_flags(flags) \
119 typecheck(unsigned long, flags); \
120 arch_irqs_disabled_flags(flags); \
122 #define raw_irqs_disabled() (arch_irqs_disabled())
123 #define raw_safe_halt() arch_safe_halt()
126 * The local_irq_*() APIs are equal to the raw_local_irq*()
127 * if !TRACE_IRQFLAGS.
129 #ifdef CONFIG_TRACE_IRQFLAGS
130 #define local_irq_enable() \
131 do { trace_hardirqs_on(); raw_local_irq_enable(); } while (0)
132 #define local_irq_disable() \
133 do { raw_local_irq_disable(); trace_hardirqs_off(); } while (0)
134 #define local_irq_save(flags) \
136 raw_local_irq_save(flags); \
137 trace_hardirqs_off(); \
141 #define local_irq_restore(flags) \
143 if (raw_irqs_disabled_flags(flags)) { \
144 raw_local_irq_restore(flags); \
145 trace_hardirqs_off(); \
147 trace_hardirqs_on(); \
148 raw_local_irq_restore(flags); \
152 #define safe_halt() \
154 trace_hardirqs_on(); \
159 #else /* !CONFIG_TRACE_IRQFLAGS */
161 #define local_irq_enable() do { raw_local_irq_enable(); } while (0)
162 #define local_irq_disable() do { raw_local_irq_disable(); } while (0)
163 #define local_irq_save(flags) \
165 raw_local_irq_save(flags); \
167 #define local_irq_restore(flags) do { raw_local_irq_restore(flags); } while (0)
168 #define safe_halt() do { raw_safe_halt(); } while (0)
170 #endif /* CONFIG_TRACE_IRQFLAGS */
172 #define local_save_flags(flags) raw_local_save_flags(flags)
175 * Some architectures don't define arch_irqs_disabled(), so even if either
176 * definition would be fine we need to use different ones for the time being
177 * to avoid build issues.
179 #ifdef CONFIG_TRACE_IRQFLAGS_SUPPORT
180 #define irqs_disabled() \
182 unsigned long _flags; \
183 raw_local_save_flags(_flags); \
184 raw_irqs_disabled_flags(_flags); \
186 #else /* !CONFIG_TRACE_IRQFLAGS_SUPPORT */
187 #define irqs_disabled() raw_irqs_disabled()
188 #endif /* CONFIG_TRACE_IRQFLAGS_SUPPORT */
190 #define irqs_disabled_flags(flags) raw_irqs_disabled_flags(flags)