blob: b02a3f1d46a0595788b86220bcbee174171ad78c [file] [log] [blame]
Ingo Molnarde30a2b2006-07-03 00:24:42 -07001/*
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 Rostedt3f3078912008-07-25 01:45:25 -070014#include <linux/typecheck.h>
15
Ingo Molnarde30a2b2006-07-03 00:24:42 -070016#ifdef CONFIG_TRACE_IRQFLAGS
Ingo Molnarde30a2b2006-07-03 00:24:42 -070017 extern void trace_softirqs_on(unsigned long ip);
18 extern void trace_softirqs_off(unsigned long ip);
Steven Rostedt81d68a92008-05-12 21:20:42 +020019 extern void trace_hardirqs_on(void);
20 extern void trace_hardirqs_off(void);
Ingo Molnarde30a2b2006-07-03 00:24:42 -070021# define trace_hardirq_context(p) ((p)->hardirq_context)
22# define trace_softirq_context(p) ((p)->softirq_context)
23# define trace_hardirqs_enabled(p) ((p)->hardirqs_enabled)
24# define trace_softirqs_enabled(p) ((p)->softirqs_enabled)
25# define trace_hardirq_enter() do { current->hardirq_context++; } while (0)
26# define trace_hardirq_exit() do { current->hardirq_context--; } while (0)
Ingo Molnard820ac42009-03-13 01:30:40 +010027# define lockdep_softirq_enter() do { current->softirq_context++; } while (0)
28# define lockdep_softirq_exit() do { current->softirq_context--; } while (0)
Ingo Molnarde30a2b2006-07-03 00:24:42 -070029# define INIT_TRACE_IRQFLAGS .softirqs_enabled = 1,
30#else
31# define trace_hardirqs_on() do { } while (0)
32# define trace_hardirqs_off() do { } while (0)
33# define trace_softirqs_on(ip) do { } while (0)
34# define trace_softirqs_off(ip) do { } while (0)
35# define trace_hardirq_context(p) 0
36# define trace_softirq_context(p) 0
37# define trace_hardirqs_enabled(p) 0
38# define trace_softirqs_enabled(p) 0
39# define trace_hardirq_enter() do { } while (0)
40# define trace_hardirq_exit() do { } while (0)
Ingo Molnard820ac42009-03-13 01:30:40 +010041# define lockdep_softirq_enter() do { } while (0)
42# define lockdep_softirq_exit() do { } while (0)
Ingo Molnarde30a2b2006-07-03 00:24:42 -070043# define INIT_TRACE_IRQFLAGS
44#endif
45
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +020046#if defined(CONFIG_IRQSOFF_TRACER) || \
47 defined(CONFIG_PREEMPT_TRACER)
Steven Rostedt81d68a92008-05-12 21:20:42 +020048 extern void stop_critical_timings(void);
49 extern void start_critical_timings(void);
50#else
51# define stop_critical_timings() do { } while (0)
52# define start_critical_timings() do { } while (0)
53#endif
54
Ingo Molnarde30a2b2006-07-03 00:24:42 -070055#ifdef CONFIG_TRACE_IRQFLAGS_SUPPORT
56
57#include <asm/irqflags.h>
58
59#define local_irq_enable() \
60 do { trace_hardirqs_on(); raw_local_irq_enable(); } while (0)
61#define local_irq_disable() \
62 do { raw_local_irq_disable(); trace_hardirqs_off(); } while (0)
Steven Rostedt3f3078912008-07-25 01:45:25 -070063#define local_irq_save(flags) \
64 do { \
65 typecheck(unsigned long, flags); \
66 raw_local_irq_save(flags); \
67 trace_hardirqs_off(); \
68 } while (0)
Ingo Molnarde30a2b2006-07-03 00:24:42 -070069
Steven Rostedt3f3078912008-07-25 01:45:25 -070070
71#define local_irq_restore(flags) \
72 do { \
73 typecheck(unsigned long, flags); \
74 if (raw_irqs_disabled_flags(flags)) { \
75 raw_local_irq_restore(flags); \
76 trace_hardirqs_off(); \
77 } else { \
78 trace_hardirqs_on(); \
79 raw_local_irq_restore(flags); \
80 } \
Ingo Molnarde30a2b2006-07-03 00:24:42 -070081 } while (0)
82#else /* !CONFIG_TRACE_IRQFLAGS_SUPPORT */
83/*
84 * The local_irq_*() APIs are equal to the raw_local_irq*()
85 * if !TRACE_IRQFLAGS.
86 */
87# define raw_local_irq_disable() local_irq_disable()
88# define raw_local_irq_enable() local_irq_enable()
Steven Rostedt3f3078912008-07-25 01:45:25 -070089# define raw_local_irq_save(flags) \
90 do { \
91 typecheck(unsigned long, flags); \
92 local_irq_save(flags); \
93 } while (0)
94# define raw_local_irq_restore(flags) \
95 do { \
96 typecheck(unsigned long, flags); \
97 local_irq_restore(flags); \
98 } while (0)
Ingo Molnarde30a2b2006-07-03 00:24:42 -070099#endif /* CONFIG_TRACE_IRQFLAGS_SUPPORT */
100
101#ifdef CONFIG_TRACE_IRQFLAGS_SUPPORT
102#define safe_halt() \
103 do { \
104 trace_hardirqs_on(); \
105 raw_safe_halt(); \
106 } while (0)
107
Steven Rostedt3f3078912008-07-25 01:45:25 -0700108#define local_save_flags(flags) \
109 do { \
110 typecheck(unsigned long, flags); \
111 raw_local_save_flags(flags); \
112 } while (0)
Ingo Molnarde30a2b2006-07-03 00:24:42 -0700113
114#define irqs_disabled() \
115({ \
Harvey Harrisona7d5ac82008-03-04 22:05:27 -0800116 unsigned long _flags; \
Ingo Molnarde30a2b2006-07-03 00:24:42 -0700117 \
Harvey Harrisona7d5ac82008-03-04 22:05:27 -0800118 raw_local_save_flags(_flags); \
119 raw_irqs_disabled_flags(_flags); \
Ingo Molnarde30a2b2006-07-03 00:24:42 -0700120})
121
Steven Rostedt3f3078912008-07-25 01:45:25 -0700122#define irqs_disabled_flags(flags) \
123({ \
124 typecheck(unsigned long, flags); \
125 raw_irqs_disabled_flags(flags); \
126})
Ingo Molnarde30a2b2006-07-03 00:24:42 -0700127#endif /* CONFIG_X86 */
128
129#endif