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) |
| 26 | # define trace_hardirq_enter() do { current->hardirq_context++; } while (0) |
| 27 | # define trace_hardirq_exit() do { current->hardirq_context--; } while (0) |
Ingo Molnar | d820ac4 | 2009-03-13 01:30:40 +0100 | [diff] [blame] | 28 | # define lockdep_softirq_enter() do { current->softirq_context++; } while (0) |
| 29 | # define lockdep_softirq_exit() do { current->softirq_context--; } while (0) |
Ingo Molnar | de30a2b | 2006-07-03 00:24:42 -0700 | [diff] [blame] | 30 | # define INIT_TRACE_IRQFLAGS .softirqs_enabled = 1, |
| 31 | #else |
| 32 | # define trace_hardirqs_on() do { } while (0) |
| 33 | # define trace_hardirqs_off() do { } while (0) |
| 34 | # define trace_softirqs_on(ip) do { } while (0) |
| 35 | # define trace_softirqs_off(ip) do { } while (0) |
| 36 | # define trace_hardirq_context(p) 0 |
| 37 | # define trace_softirq_context(p) 0 |
| 38 | # define trace_hardirqs_enabled(p) 0 |
| 39 | # define trace_softirqs_enabled(p) 0 |
| 40 | # define trace_hardirq_enter() do { } while (0) |
| 41 | # define trace_hardirq_exit() do { } while (0) |
Ingo Molnar | d820ac4 | 2009-03-13 01:30:40 +0100 | [diff] [blame] | 42 | # define lockdep_softirq_enter() do { } while (0) |
| 43 | # define lockdep_softirq_exit() do { } while (0) |
Ingo Molnar | de30a2b | 2006-07-03 00:24:42 -0700 | [diff] [blame] | 44 | # define INIT_TRACE_IRQFLAGS |
| 45 | #endif |
| 46 | |
Steven Rostedt | 6cd8a4b | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 47 | #if defined(CONFIG_IRQSOFF_TRACER) || \ |
| 48 | defined(CONFIG_PREEMPT_TRACER) |
Steven Rostedt | 81d68a9 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 49 | extern void stop_critical_timings(void); |
| 50 | extern void start_critical_timings(void); |
| 51 | #else |
| 52 | # define stop_critical_timings() do { } while (0) |
| 53 | # define start_critical_timings() do { } while (0) |
| 54 | #endif |
| 55 | |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 56 | /* |
| 57 | * Wrap the arch provided IRQ routines to provide appropriate checks. |
| 58 | */ |
| 59 | #define raw_local_irq_disable() arch_local_irq_disable() |
| 60 | #define raw_local_irq_enable() arch_local_irq_enable() |
| 61 | #define raw_local_irq_save(flags) \ |
| 62 | do { \ |
| 63 | typecheck(unsigned long, flags); \ |
| 64 | flags = arch_local_irq_save(); \ |
| 65 | } while (0) |
| 66 | #define raw_local_irq_restore(flags) \ |
| 67 | do { \ |
| 68 | typecheck(unsigned long, flags); \ |
| 69 | arch_local_irq_restore(flags); \ |
| 70 | } while (0) |
| 71 | #define raw_local_save_flags(flags) \ |
| 72 | do { \ |
| 73 | typecheck(unsigned long, flags); \ |
| 74 | flags = arch_local_save_flags(); \ |
| 75 | } while (0) |
| 76 | #define raw_irqs_disabled_flags(flags) \ |
| 77 | ({ \ |
| 78 | typecheck(unsigned long, flags); \ |
| 79 | arch_irqs_disabled_flags(flags); \ |
| 80 | }) |
| 81 | #define raw_irqs_disabled() (arch_irqs_disabled()) |
| 82 | #define raw_safe_halt() arch_safe_halt() |
| 83 | |
| 84 | /* |
| 85 | * The local_irq_*() APIs are equal to the raw_local_irq*() |
| 86 | * if !TRACE_IRQFLAGS. |
| 87 | */ |
Ingo Molnar | de30a2b | 2006-07-03 00:24:42 -0700 | [diff] [blame] | 88 | #ifdef CONFIG_TRACE_IRQFLAGS_SUPPORT |
Ingo Molnar | de30a2b | 2006-07-03 00:24:42 -0700 | [diff] [blame] | 89 | #define local_irq_enable() \ |
| 90 | do { trace_hardirqs_on(); raw_local_irq_enable(); } while (0) |
| 91 | #define local_irq_disable() \ |
| 92 | do { raw_local_irq_disable(); trace_hardirqs_off(); } while (0) |
Steven Rostedt | 3f307891 | 2008-07-25 01:45:25 -0700 | [diff] [blame] | 93 | #define local_irq_save(flags) \ |
| 94 | do { \ |
Steven Rostedt | 3f307891 | 2008-07-25 01:45:25 -0700 | [diff] [blame] | 95 | raw_local_irq_save(flags); \ |
| 96 | trace_hardirqs_off(); \ |
| 97 | } while (0) |
Ingo Molnar | de30a2b | 2006-07-03 00:24:42 -0700 | [diff] [blame] | 98 | |
Steven Rostedt | 3f307891 | 2008-07-25 01:45:25 -0700 | [diff] [blame] | 99 | |
| 100 | #define local_irq_restore(flags) \ |
| 101 | do { \ |
Steven Rostedt | 3f307891 | 2008-07-25 01:45:25 -0700 | [diff] [blame] | 102 | if (raw_irqs_disabled_flags(flags)) { \ |
| 103 | raw_local_irq_restore(flags); \ |
| 104 | trace_hardirqs_off(); \ |
| 105 | } else { \ |
| 106 | trace_hardirqs_on(); \ |
| 107 | raw_local_irq_restore(flags); \ |
| 108 | } \ |
Ingo Molnar | de30a2b | 2006-07-03 00:24:42 -0700 | [diff] [blame] | 109 | } while (0) |
Steven Rostedt | 3f307891 | 2008-07-25 01:45:25 -0700 | [diff] [blame] | 110 | #define local_save_flags(flags) \ |
| 111 | do { \ |
Steven Rostedt | 3f307891 | 2008-07-25 01:45:25 -0700 | [diff] [blame] | 112 | raw_local_save_flags(flags); \ |
| 113 | } while (0) |
Ingo Molnar | de30a2b | 2006-07-03 00:24:42 -0700 | [diff] [blame] | 114 | |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 115 | #define irqs_disabled_flags(flags) \ |
| 116 | ({ \ |
| 117 | raw_irqs_disabled_flags(flags); \ |
| 118 | }) |
Ingo Molnar | de30a2b | 2006-07-03 00:24:42 -0700 | [diff] [blame] | 119 | |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 120 | #define irqs_disabled() \ |
| 121 | ({ \ |
| 122 | unsigned long _flags; \ |
| 123 | raw_local_save_flags(_flags); \ |
| 124 | raw_irqs_disabled_flags(_flags); \ |
| 125 | }) |
| 126 | |
| 127 | #define safe_halt() \ |
| 128 | do { \ |
| 129 | trace_hardirqs_on(); \ |
| 130 | raw_safe_halt(); \ |
| 131 | } while (0) |
| 132 | |
| 133 | |
| 134 | #else /* !CONFIG_TRACE_IRQFLAGS_SUPPORT */ |
| 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) |
| 143 | #define local_save_flags(flags) do { raw_local_save_flags(flags); } while (0) |
| 144 | #define irqs_disabled() (raw_irqs_disabled()) |
| 145 | #define irqs_disabled_flags(flags) (raw_irqs_disabled_flags(flags)) |
| 146 | #define safe_halt() do { raw_safe_halt(); } while (0) |
| 147 | |
Michael Neuling | 40b1f4e | 2009-10-22 14:39:28 +1100 | [diff] [blame] | 148 | #endif /* CONFIG_TRACE_IRQFLAGS_SUPPORT */ |
Ingo Molnar | de30a2b | 2006-07-03 00:24:42 -0700 | [diff] [blame] | 149 | |
| 150 | #endif |