blob: f23f540e0ebbad9b8a352865345bdaf5de53d2cb [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Ingo Molnarde30a2b2006-07-03 00:24:42 -07002/*
3 * include/linux/irqflags.h
4 *
5 * IRQ flags tracing: follow the state of the hardirq and softirq flags and
6 * provide callbacks for transitions between ON and OFF states.
7 *
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.
11 */
12#ifndef _LINUX_TRACE_IRQFLAGS_H
13#define _LINUX_TRACE_IRQFLAGS_H
14
Steven Rostedt3f3078912008-07-25 01:45:25 -070015#include <linux/typecheck.h>
David Howellsdf9ee292010-10-07 14:08:55 +010016#include <asm/irqflags.h>
Steven Rostedt3f3078912008-07-25 01:45:25 -070017
Joel Fernandes (Google)c3bc8fd2018-07-30 15:24:23 -070018/* Currently trace_softirqs_on/off is used only by lockdep */
19#ifdef CONFIG_PROVE_LOCKING
Ingo Molnarde30a2b2006-07-03 00:24:42 -070020 extern void trace_softirqs_on(unsigned long ip);
21 extern void trace_softirqs_off(unsigned long ip);
Steven Rostedt (VMware)bff1b202018-08-06 15:50:58 -040022 extern void lockdep_hardirqs_on(unsigned long ip);
23 extern void lockdep_hardirqs_off(unsigned long ip);
Joel Fernandes (Google)c3bc8fd2018-07-30 15:24:23 -070024#else
Steven Rostedt (VMware)bff1b202018-08-06 15:50:58 -040025 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) { }
Joel Fernandes (Google)c3bc8fd2018-07-30 15:24:23 -070029#endif
30
31#ifdef CONFIG_TRACE_IRQFLAGS
Steven Rostedt81d68a92008-05-12 21:20:42 +020032 extern void trace_hardirqs_on(void);
33 extern void trace_hardirqs_off(void);
Ingo Molnarde30a2b2006-07-03 00:24:42 -070034# 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)
Byungchul Parkb09be672017-08-07 16:12:52 +090038# define trace_hardirq_enter() \
39do { \
Peter Zijlstrade8f5e42020-03-21 12:26:01 +010040 if (!current->hardirq_context++) \
41 current->hardirq_threaded = 0; \
42} while (0)
43# define trace_hardirq_threaded() \
44do { \
45 current->hardirq_threaded = 1; \
Byungchul Parkb09be672017-08-07 16:12:52 +090046} while (0)
47# define trace_hardirq_exit() \
48do { \
49 current->hardirq_context--; \
Byungchul Parkb09be672017-08-07 16:12:52 +090050} while (0)
51# define lockdep_softirq_enter() \
52do { \
53 current->softirq_context++; \
Byungchul Parkb09be672017-08-07 16:12:52 +090054} while (0)
55# define lockdep_softirq_exit() \
56do { \
57 current->softirq_context--; \
Byungchul Parkb09be672017-08-07 16:12:52 +090058} while (0)
Sebastian Andrzej Siewior40db1732020-03-21 12:26:02 +010059
60# define lockdep_hrtimer_enter(__hrtimer) \
61 do { \
62 if (!__hrtimer->is_hard) \
63 current->irq_config = 1; \
64 } while (0)
65
66# define lockdep_hrtimer_exit(__hrtimer) \
67 do { \
68 if (!__hrtimer->is_hard) \
69 current->irq_config = 0; \
70 } while (0)
71
Sebastian Andrzej Siewior49915ac2020-03-21 12:26:03 +010072# define lockdep_irq_work_enter(__work) \
73 do { \
74 if (!(atomic_read(&__work->flags) & IRQ_WORK_HARD_IRQ))\
75 current->irq_config = 1; \
76 } while (0)
77# define lockdep_irq_work_exit(__work) \
78 do { \
79 if (!(atomic_read(&__work->flags) & IRQ_WORK_HARD_IRQ))\
80 current->irq_config = 0; \
81 } while (0)
82
Ingo Molnarde30a2b2006-07-03 00:24:42 -070083#else
84# define trace_hardirqs_on() do { } while (0)
85# define trace_hardirqs_off() do { } while (0)
Ingo Molnarde30a2b2006-07-03 00:24:42 -070086# define trace_hardirq_context(p) 0
87# define trace_softirq_context(p) 0
88# define trace_hardirqs_enabled(p) 0
89# define trace_softirqs_enabled(p) 0
90# define trace_hardirq_enter() do { } while (0)
Peter Zijlstrade8f5e42020-03-21 12:26:01 +010091# define trace_hardirq_threaded() do { } while (0)
Ingo Molnarde30a2b2006-07-03 00:24:42 -070092# define trace_hardirq_exit() do { } while (0)
Ingo Molnard820ac42009-03-13 01:30:40 +010093# define lockdep_softirq_enter() do { } while (0)
94# define lockdep_softirq_exit() do { } while (0)
Sebastian Andrzej Siewior40db1732020-03-21 12:26:02 +010095# define lockdep_hrtimer_enter(__hrtimer) do { } while (0)
96# define lockdep_hrtimer_exit(__hrtimer) do { } while (0)
Sebastian Andrzej Siewior49915ac2020-03-21 12:26:03 +010097# define lockdep_irq_work_enter(__work) do { } while (0)
98# define lockdep_irq_work_exit(__work) do { } while (0)
Ingo Molnarde30a2b2006-07-03 00:24:42 -070099#endif
100
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +0200101#if defined(CONFIG_IRQSOFF_TRACER) || \
102 defined(CONFIG_PREEMPT_TRACER)
Steven Rostedt81d68a92008-05-12 21:20:42 +0200103 extern void stop_critical_timings(void);
104 extern void start_critical_timings(void);
105#else
106# define stop_critical_timings() do { } while (0)
107# define start_critical_timings() do { } while (0)
108#endif
109
David Howellsdf9ee292010-10-07 14:08:55 +0100110/*
111 * Wrap the arch provided IRQ routines to provide appropriate checks.
112 */
113#define raw_local_irq_disable() arch_local_irq_disable()
114#define raw_local_irq_enable() arch_local_irq_enable()
115#define raw_local_irq_save(flags) \
116 do { \
117 typecheck(unsigned long, flags); \
118 flags = arch_local_irq_save(); \
119 } while (0)
120#define raw_local_irq_restore(flags) \
121 do { \
122 typecheck(unsigned long, flags); \
123 arch_local_irq_restore(flags); \
124 } while (0)
125#define raw_local_save_flags(flags) \
126 do { \
127 typecheck(unsigned long, flags); \
128 flags = arch_local_save_flags(); \
129 } while (0)
130#define raw_irqs_disabled_flags(flags) \
131 ({ \
132 typecheck(unsigned long, flags); \
133 arch_irqs_disabled_flags(flags); \
134 })
135#define raw_irqs_disabled() (arch_irqs_disabled())
136#define raw_safe_halt() arch_safe_halt()
137
138/*
139 * The local_irq_*() APIs are equal to the raw_local_irq*()
140 * if !TRACE_IRQFLAGS.
141 */
Jan Beulichdb2dcb42015-01-20 13:00:46 +0000142#ifdef CONFIG_TRACE_IRQFLAGS
Ingo Molnarde30a2b2006-07-03 00:24:42 -0700143#define local_irq_enable() \
144 do { trace_hardirqs_on(); raw_local_irq_enable(); } while (0)
145#define local_irq_disable() \
146 do { raw_local_irq_disable(); trace_hardirqs_off(); } while (0)
Steven Rostedt3f3078912008-07-25 01:45:25 -0700147#define local_irq_save(flags) \
148 do { \
Steven Rostedt3f3078912008-07-25 01:45:25 -0700149 raw_local_irq_save(flags); \
150 trace_hardirqs_off(); \
151 } while (0)
Ingo Molnarde30a2b2006-07-03 00:24:42 -0700152
Steven Rostedt3f3078912008-07-25 01:45:25 -0700153
154#define local_irq_restore(flags) \
155 do { \
Steven Rostedt3f3078912008-07-25 01:45:25 -0700156 if (raw_irqs_disabled_flags(flags)) { \
157 raw_local_irq_restore(flags); \
158 trace_hardirqs_off(); \
159 } else { \
160 trace_hardirqs_on(); \
161 raw_local_irq_restore(flags); \
162 } \
Ingo Molnarde30a2b2006-07-03 00:24:42 -0700163 } while (0)
David Howellsdf9ee292010-10-07 14:08:55 +0100164
165#define safe_halt() \
166 do { \
167 trace_hardirqs_on(); \
168 raw_safe_halt(); \
169 } while (0)
170
171
Jan Beulichdb2dcb42015-01-20 13:00:46 +0000172#else /* !CONFIG_TRACE_IRQFLAGS */
David Howellsdf9ee292010-10-07 14:08:55 +0100173
174#define local_irq_enable() do { raw_local_irq_enable(); } while (0)
175#define local_irq_disable() do { raw_local_irq_disable(); } while (0)
176#define local_irq_save(flags) \
177 do { \
178 raw_local_irq_save(flags); \
179 } while (0)
180#define local_irq_restore(flags) do { raw_local_irq_restore(flags); } while (0)
David Howellsdf9ee292010-10-07 14:08:55 +0100181#define safe_halt() do { raw_safe_halt(); } while (0)
182
Jan Beulichdb2dcb42015-01-20 13:00:46 +0000183#endif /* CONFIG_TRACE_IRQFLAGS */
184
185#define local_save_flags(flags) raw_local_save_flags(flags)
186
187/*
188 * Some architectures don't define arch_irqs_disabled(), so even if either
189 * definition would be fine we need to use different ones for the time being
190 * to avoid build issues.
191 */
192#ifdef CONFIG_TRACE_IRQFLAGS_SUPPORT
193#define irqs_disabled() \
194 ({ \
195 unsigned long _flags; \
196 raw_local_save_flags(_flags); \
197 raw_irqs_disabled_flags(_flags); \
198 })
199#else /* !CONFIG_TRACE_IRQFLAGS_SUPPORT */
200#define irqs_disabled() raw_irqs_disabled()
Michael Neuling40b1f4e2009-10-22 14:39:28 +1100201#endif /* CONFIG_TRACE_IRQFLAGS_SUPPORT */
Ingo Molnarde30a2b2006-07-03 00:24:42 -0700202
Jan Beulichdb2dcb42015-01-20 13:00:46 +0000203#define irqs_disabled_flags(flags) raw_irqs_disabled_flags(flags)
204
Ingo Molnarde30a2b2006-07-03 00:24:42 -0700205#endif