Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Ingo Molnar | de30a2b | 2006-07-03 00:24:42 -0700 | [diff] [blame] | 2 | /* |
| 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 Rostedt | 3f307891 | 2008-07-25 01:45:25 -0700 | [diff] [blame] | 15 | #include <linux/typecheck.h> |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 16 | #include <asm/irqflags.h> |
Steven Rostedt | 3f307891 | 2008-07-25 01:45:25 -0700 | [diff] [blame] | 17 | |
Joel Fernandes (Google) | c3bc8fd | 2018-07-30 15:24:23 -0700 | [diff] [blame] | 18 | /* Currently trace_softirqs_on/off is used only by lockdep */ |
| 19 | #ifdef CONFIG_PROVE_LOCKING |
Ingo Molnar | de30a2b | 2006-07-03 00:24:42 -0700 | [diff] [blame] | 20 | extern void trace_softirqs_on(unsigned long ip); |
| 21 | extern void trace_softirqs_off(unsigned long ip); |
Steven Rostedt (VMware) | bff1b20 | 2018-08-06 15:50:58 -0400 | [diff] [blame] | 22 | extern void lockdep_hardirqs_on(unsigned long ip); |
| 23 | extern void lockdep_hardirqs_off(unsigned long ip); |
Joel Fernandes (Google) | c3bc8fd | 2018-07-30 15:24:23 -0700 | [diff] [blame] | 24 | #else |
Steven Rostedt (VMware) | bff1b20 | 2018-08-06 15:50:58 -0400 | [diff] [blame] | 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) { } |
Joel Fernandes (Google) | c3bc8fd | 2018-07-30 15:24:23 -0700 | [diff] [blame] | 29 | #endif |
| 30 | |
| 31 | #ifdef CONFIG_TRACE_IRQFLAGS |
Steven Rostedt | 81d68a9 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 32 | extern void trace_hardirqs_on(void); |
| 33 | extern void trace_hardirqs_off(void); |
Ingo Molnar | de30a2b | 2006-07-03 00:24:42 -0700 | [diff] [blame] | 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) |
Byungchul Park | b09be67 | 2017-08-07 16:12:52 +0900 | [diff] [blame] | 38 | # define trace_hardirq_enter() \ |
| 39 | do { \ |
| 40 | current->hardirq_context++; \ |
Byungchul Park | b09be67 | 2017-08-07 16:12:52 +0900 | [diff] [blame] | 41 | } while (0) |
| 42 | # define trace_hardirq_exit() \ |
| 43 | do { \ |
| 44 | current->hardirq_context--; \ |
Byungchul Park | b09be67 | 2017-08-07 16:12:52 +0900 | [diff] [blame] | 45 | } while (0) |
| 46 | # define lockdep_softirq_enter() \ |
| 47 | do { \ |
| 48 | current->softirq_context++; \ |
Byungchul Park | b09be67 | 2017-08-07 16:12:52 +0900 | [diff] [blame] | 49 | } while (0) |
| 50 | # define lockdep_softirq_exit() \ |
| 51 | do { \ |
| 52 | current->softirq_context--; \ |
Byungchul Park | b09be67 | 2017-08-07 16:12:52 +0900 | [diff] [blame] | 53 | } while (0) |
Ingo Molnar | de30a2b | 2006-07-03 00:24:42 -0700 | [diff] [blame] | 54 | #else |
| 55 | # define trace_hardirqs_on() do { } while (0) |
| 56 | # define trace_hardirqs_off() do { } while (0) |
Ingo Molnar | de30a2b | 2006-07-03 00:24:42 -0700 | [diff] [blame] | 57 | # define trace_hardirq_context(p) 0 |
| 58 | # define trace_softirq_context(p) 0 |
| 59 | # define trace_hardirqs_enabled(p) 0 |
| 60 | # define trace_softirqs_enabled(p) 0 |
| 61 | # define trace_hardirq_enter() do { } while (0) |
| 62 | # define trace_hardirq_exit() do { } while (0) |
Ingo Molnar | d820ac4 | 2009-03-13 01:30:40 +0100 | [diff] [blame] | 63 | # define lockdep_softirq_enter() do { } while (0) |
| 64 | # define lockdep_softirq_exit() do { } while (0) |
Ingo Molnar | de30a2b | 2006-07-03 00:24:42 -0700 | [diff] [blame] | 65 | #endif |
| 66 | |
Steven Rostedt | 6cd8a4b | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 67 | #if defined(CONFIG_IRQSOFF_TRACER) || \ |
| 68 | defined(CONFIG_PREEMPT_TRACER) |
Steven Rostedt | 81d68a9 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 69 | extern void stop_critical_timings(void); |
| 70 | extern void start_critical_timings(void); |
| 71 | #else |
| 72 | # define stop_critical_timings() do { } while (0) |
| 73 | # define start_critical_timings() do { } while (0) |
| 74 | #endif |
| 75 | |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 76 | /* |
| 77 | * Wrap the arch provided IRQ routines to provide appropriate checks. |
| 78 | */ |
| 79 | #define raw_local_irq_disable() arch_local_irq_disable() |
| 80 | #define raw_local_irq_enable() arch_local_irq_enable() |
| 81 | #define raw_local_irq_save(flags) \ |
| 82 | do { \ |
| 83 | typecheck(unsigned long, flags); \ |
| 84 | flags = arch_local_irq_save(); \ |
| 85 | } while (0) |
| 86 | #define raw_local_irq_restore(flags) \ |
| 87 | do { \ |
| 88 | typecheck(unsigned long, flags); \ |
| 89 | arch_local_irq_restore(flags); \ |
| 90 | } while (0) |
| 91 | #define raw_local_save_flags(flags) \ |
| 92 | do { \ |
| 93 | typecheck(unsigned long, flags); \ |
| 94 | flags = arch_local_save_flags(); \ |
| 95 | } while (0) |
| 96 | #define raw_irqs_disabled_flags(flags) \ |
| 97 | ({ \ |
| 98 | typecheck(unsigned long, flags); \ |
| 99 | arch_irqs_disabled_flags(flags); \ |
| 100 | }) |
| 101 | #define raw_irqs_disabled() (arch_irqs_disabled()) |
| 102 | #define raw_safe_halt() arch_safe_halt() |
| 103 | |
| 104 | /* |
| 105 | * The local_irq_*() APIs are equal to the raw_local_irq*() |
| 106 | * if !TRACE_IRQFLAGS. |
| 107 | */ |
Jan Beulich | db2dcb4 | 2015-01-20 13:00:46 +0000 | [diff] [blame] | 108 | #ifdef CONFIG_TRACE_IRQFLAGS |
Ingo Molnar | de30a2b | 2006-07-03 00:24:42 -0700 | [diff] [blame] | 109 | #define local_irq_enable() \ |
| 110 | do { trace_hardirqs_on(); raw_local_irq_enable(); } while (0) |
| 111 | #define local_irq_disable() \ |
| 112 | do { raw_local_irq_disable(); trace_hardirqs_off(); } while (0) |
Steven Rostedt | 3f307891 | 2008-07-25 01:45:25 -0700 | [diff] [blame] | 113 | #define local_irq_save(flags) \ |
| 114 | do { \ |
Steven Rostedt | 3f307891 | 2008-07-25 01:45:25 -0700 | [diff] [blame] | 115 | raw_local_irq_save(flags); \ |
| 116 | trace_hardirqs_off(); \ |
| 117 | } while (0) |
Ingo Molnar | de30a2b | 2006-07-03 00:24:42 -0700 | [diff] [blame] | 118 | |
Steven Rostedt | 3f307891 | 2008-07-25 01:45:25 -0700 | [diff] [blame] | 119 | |
| 120 | #define local_irq_restore(flags) \ |
| 121 | do { \ |
Steven Rostedt | 3f307891 | 2008-07-25 01:45:25 -0700 | [diff] [blame] | 122 | if (raw_irqs_disabled_flags(flags)) { \ |
| 123 | raw_local_irq_restore(flags); \ |
| 124 | trace_hardirqs_off(); \ |
| 125 | } else { \ |
| 126 | trace_hardirqs_on(); \ |
| 127 | raw_local_irq_restore(flags); \ |
| 128 | } \ |
Ingo Molnar | de30a2b | 2006-07-03 00:24:42 -0700 | [diff] [blame] | 129 | } while (0) |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 130 | |
| 131 | #define safe_halt() \ |
| 132 | do { \ |
| 133 | trace_hardirqs_on(); \ |
| 134 | raw_safe_halt(); \ |
| 135 | } while (0) |
| 136 | |
| 137 | |
Jan Beulich | db2dcb4 | 2015-01-20 13:00:46 +0000 | [diff] [blame] | 138 | #else /* !CONFIG_TRACE_IRQFLAGS */ |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 139 | |
| 140 | #define local_irq_enable() do { raw_local_irq_enable(); } while (0) |
| 141 | #define local_irq_disable() do { raw_local_irq_disable(); } while (0) |
| 142 | #define local_irq_save(flags) \ |
| 143 | do { \ |
| 144 | raw_local_irq_save(flags); \ |
| 145 | } while (0) |
| 146 | #define local_irq_restore(flags) do { raw_local_irq_restore(flags); } while (0) |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 147 | #define safe_halt() do { raw_safe_halt(); } while (0) |
| 148 | |
Jan Beulich | db2dcb4 | 2015-01-20 13:00:46 +0000 | [diff] [blame] | 149 | #endif /* CONFIG_TRACE_IRQFLAGS */ |
| 150 | |
| 151 | #define local_save_flags(flags) raw_local_save_flags(flags) |
| 152 | |
| 153 | /* |
| 154 | * Some architectures don't define arch_irqs_disabled(), so even if either |
| 155 | * definition would be fine we need to use different ones for the time being |
| 156 | * to avoid build issues. |
| 157 | */ |
| 158 | #ifdef CONFIG_TRACE_IRQFLAGS_SUPPORT |
| 159 | #define irqs_disabled() \ |
| 160 | ({ \ |
| 161 | unsigned long _flags; \ |
| 162 | raw_local_save_flags(_flags); \ |
| 163 | raw_irqs_disabled_flags(_flags); \ |
| 164 | }) |
| 165 | #else /* !CONFIG_TRACE_IRQFLAGS_SUPPORT */ |
| 166 | #define irqs_disabled() raw_irqs_disabled() |
Michael Neuling | 40b1f4e | 2009-10-22 14:39:28 +1100 | [diff] [blame] | 167 | #endif /* CONFIG_TRACE_IRQFLAGS_SUPPORT */ |
Ingo Molnar | de30a2b | 2006-07-03 00:24:42 -0700 | [diff] [blame] | 168 | |
Jan Beulich | db2dcb4 | 2015-01-20 13:00:46 +0000 | [diff] [blame] | 169 | #define irqs_disabled_flags(flags) raw_irqs_disabled_flags(flags) |
| 170 | |
Ingo Molnar | de30a2b | 2006-07-03 00:24:42 -0700 | [diff] [blame] | 171 | #endif |