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