blob: 9700f00bbc043ff5bdfb73986eb0ee0cc5903aca [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Ingo Molnarde30a2b2006-07-03 00:24:42 -07002/*
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 Rostedt3f3078912008-07-25 01:45:25 -070015#include <linux/typecheck.h>
David Howellsdf9ee292010-10-07 14:08:55 +010016#include <asm/irqflags.h>
Steven Rostedt3f3078912008-07-25 01:45:25 -070017
Ingo Molnarde30a2b2006-07-03 00:24:42 -070018#ifdef CONFIG_TRACE_IRQFLAGS
Ingo Molnarde30a2b2006-07-03 00:24:42 -070019 extern void trace_softirqs_on(unsigned long ip);
20 extern void trace_softirqs_off(unsigned long ip);
Steven Rostedt81d68a92008-05-12 21:20:42 +020021 extern void trace_hardirqs_on(void);
22 extern void trace_hardirqs_off(void);
Ingo Molnarde30a2b2006-07-03 00:24:42 -070023# 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 Parkb09be672017-08-07 16:12:52 +090027# define trace_hardirq_enter() \
28do { \
29 current->hardirq_context++; \
Byungchul Parkb09be672017-08-07 16:12:52 +090030} while (0)
31# define trace_hardirq_exit() \
32do { \
33 current->hardirq_context--; \
Byungchul Parkb09be672017-08-07 16:12:52 +090034} while (0)
35# define lockdep_softirq_enter() \
36do { \
37 current->softirq_context++; \
Byungchul Parkb09be672017-08-07 16:12:52 +090038} while (0)
39# define lockdep_softirq_exit() \
40do { \
41 current->softirq_context--; \
Byungchul Parkb09be672017-08-07 16:12:52 +090042} while (0)
Ingo Molnarde30a2b2006-07-03 00:24:42 -070043#else
44# define trace_hardirqs_on() do { } while (0)
45# define trace_hardirqs_off() do { } while (0)
46# define trace_softirqs_on(ip) do { } while (0)
47# define trace_softirqs_off(ip) do { } while (0)
48# define trace_hardirq_context(p) 0
49# define trace_softirq_context(p) 0
50# define trace_hardirqs_enabled(p) 0
51# define trace_softirqs_enabled(p) 0
52# define trace_hardirq_enter() do { } while (0)
53# define trace_hardirq_exit() do { } while (0)
Ingo Molnard820ac42009-03-13 01:30:40 +010054# define lockdep_softirq_enter() do { } while (0)
55# define lockdep_softirq_exit() do { } while (0)
Ingo Molnarde30a2b2006-07-03 00:24:42 -070056#endif
57
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +020058#if defined(CONFIG_IRQSOFF_TRACER) || \
59 defined(CONFIG_PREEMPT_TRACER)
Steven Rostedt81d68a92008-05-12 21:20:42 +020060 extern void stop_critical_timings(void);
61 extern void start_critical_timings(void);
62#else
63# define stop_critical_timings() do { } while (0)
64# define start_critical_timings() do { } while (0)
65#endif
66
David Howellsdf9ee292010-10-07 14:08:55 +010067/*
68 * Wrap the arch provided IRQ routines to provide appropriate checks.
69 */
70#define raw_local_irq_disable() arch_local_irq_disable()
71#define raw_local_irq_enable() arch_local_irq_enable()
72#define raw_local_irq_save(flags) \
73 do { \
74 typecheck(unsigned long, flags); \
75 flags = arch_local_irq_save(); \
76 } while (0)
77#define raw_local_irq_restore(flags) \
78 do { \
79 typecheck(unsigned long, flags); \
80 arch_local_irq_restore(flags); \
81 } while (0)
82#define raw_local_save_flags(flags) \
83 do { \
84 typecheck(unsigned long, flags); \
85 flags = arch_local_save_flags(); \
86 } while (0)
87#define raw_irqs_disabled_flags(flags) \
88 ({ \
89 typecheck(unsigned long, flags); \
90 arch_irqs_disabled_flags(flags); \
91 })
92#define raw_irqs_disabled() (arch_irqs_disabled())
93#define raw_safe_halt() arch_safe_halt()
94
95/*
96 * The local_irq_*() APIs are equal to the raw_local_irq*()
97 * if !TRACE_IRQFLAGS.
98 */
Jan Beulichdb2dcb42015-01-20 13:00:46 +000099#ifdef CONFIG_TRACE_IRQFLAGS
Ingo Molnarde30a2b2006-07-03 00:24:42 -0700100#define local_irq_enable() \
101 do { trace_hardirqs_on(); raw_local_irq_enable(); } while (0)
102#define local_irq_disable() \
103 do { raw_local_irq_disable(); trace_hardirqs_off(); } while (0)
Steven Rostedt3f3078912008-07-25 01:45:25 -0700104#define local_irq_save(flags) \
105 do { \
Steven Rostedt3f3078912008-07-25 01:45:25 -0700106 raw_local_irq_save(flags); \
107 trace_hardirqs_off(); \
108 } while (0)
Ingo Molnarde30a2b2006-07-03 00:24:42 -0700109
Steven Rostedt3f3078912008-07-25 01:45:25 -0700110
111#define local_irq_restore(flags) \
112 do { \
Steven Rostedt3f3078912008-07-25 01:45:25 -0700113 if (raw_irqs_disabled_flags(flags)) { \
114 raw_local_irq_restore(flags); \
115 trace_hardirqs_off(); \
116 } else { \
117 trace_hardirqs_on(); \
118 raw_local_irq_restore(flags); \
119 } \
Ingo Molnarde30a2b2006-07-03 00:24:42 -0700120 } while (0)
David Howellsdf9ee292010-10-07 14:08:55 +0100121
122#define safe_halt() \
123 do { \
124 trace_hardirqs_on(); \
125 raw_safe_halt(); \
126 } while (0)
127
128
Jan Beulichdb2dcb42015-01-20 13:00:46 +0000129#else /* !CONFIG_TRACE_IRQFLAGS */
David Howellsdf9ee292010-10-07 14:08:55 +0100130
131#define local_irq_enable() do { raw_local_irq_enable(); } while (0)
132#define local_irq_disable() do { raw_local_irq_disable(); } while (0)
133#define local_irq_save(flags) \
134 do { \
135 raw_local_irq_save(flags); \
136 } while (0)
137#define local_irq_restore(flags) do { raw_local_irq_restore(flags); } while (0)
David Howellsdf9ee292010-10-07 14:08:55 +0100138#define safe_halt() do { raw_safe_halt(); } while (0)
139
Jan Beulichdb2dcb42015-01-20 13:00:46 +0000140#endif /* CONFIG_TRACE_IRQFLAGS */
141
142#define local_save_flags(flags) raw_local_save_flags(flags)
143
144/*
145 * Some architectures don't define arch_irqs_disabled(), so even if either
146 * definition would be fine we need to use different ones for the time being
147 * to avoid build issues.
148 */
149#ifdef CONFIG_TRACE_IRQFLAGS_SUPPORT
150#define irqs_disabled() \
151 ({ \
152 unsigned long _flags; \
153 raw_local_save_flags(_flags); \
154 raw_irqs_disabled_flags(_flags); \
155 })
156#else /* !CONFIG_TRACE_IRQFLAGS_SUPPORT */
157#define irqs_disabled() raw_irqs_disabled()
Michael Neuling40b1f4e2009-10-22 14:39:28 +1100158#endif /* CONFIG_TRACE_IRQFLAGS_SUPPORT */
Ingo Molnarde30a2b2006-07-03 00:24:42 -0700159
Jan Beulichdb2dcb42015-01-20 13:00:46 +0000160#define irqs_disabled_flags(flags) raw_irqs_disabled_flags(flags)
161
Ingo Molnarde30a2b2006-07-03 00:24:42 -0700162#endif