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