Linux Audio

Check our new training course

Linux debugging, profiling, tracing and performance analysis training

Apr 14-17, 2025
Register
Loading...
v5.9
  1/* SPDX-License-Identifier: GPL-2.0 */
  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
 15#include <linux/typecheck.h>
 16#include <asm/irqflags.h>
 17#include <asm/percpu.h>
 18
 19/* Currently lockdep_softirqs_on/off is used only by lockdep */
 20#ifdef CONFIG_PROVE_LOCKING
 21  extern void lockdep_softirqs_on(unsigned long ip);
 22  extern void lockdep_softirqs_off(unsigned long ip);
 23  extern void lockdep_hardirqs_on_prepare(unsigned long ip);
 24  extern void lockdep_hardirqs_on(unsigned long ip);
 25  extern void lockdep_hardirqs_off(unsigned long ip);
 26#else
 27  static inline void lockdep_softirqs_on(unsigned long ip) { }
 28  static inline void lockdep_softirqs_off(unsigned long ip) { }
 29  static inline void lockdep_hardirqs_on_prepare(unsigned long ip) { }
 30  static inline void lockdep_hardirqs_on(unsigned long ip) { }
 31  static inline void lockdep_hardirqs_off(unsigned long ip) { }
 32#endif
 33
 34#ifdef CONFIG_TRACE_IRQFLAGS
 35
 36/* Per-task IRQ trace events information. */
 37struct irqtrace_events {
 38	unsigned int	irq_events;
 39	unsigned long	hardirq_enable_ip;
 40	unsigned long	hardirq_disable_ip;
 41	unsigned int	hardirq_enable_event;
 42	unsigned int	hardirq_disable_event;
 43	unsigned long	softirq_disable_ip;
 44	unsigned long	softirq_enable_ip;
 45	unsigned int	softirq_disable_event;
 46	unsigned int	softirq_enable_event;
 47};
 48
 49DECLARE_PER_CPU(int, hardirqs_enabled);
 50DECLARE_PER_CPU(int, hardirq_context);
 51
 52extern void trace_hardirqs_on_prepare(void);
 53extern void trace_hardirqs_off_finish(void);
 54extern void trace_hardirqs_on(void);
 55extern void trace_hardirqs_off(void);
 56
 57# define lockdep_hardirq_context()	(raw_cpu_read(hardirq_context))
 58# define lockdep_softirq_context(p)	((p)->softirq_context)
 59# define lockdep_hardirqs_enabled()	(this_cpu_read(hardirqs_enabled))
 60# define lockdep_softirqs_enabled(p)	((p)->softirqs_enabled)
 61# define lockdep_hardirq_enter()			\
 62do {							\
 63	if (__this_cpu_inc_return(hardirq_context) == 1)\
 64		current->hardirq_threaded = 0;		\
 65} while (0)
 66# define lockdep_hardirq_threaded()		\
 67do {						\
 68	current->hardirq_threaded = 1;		\
 69} while (0)
 70# define lockdep_hardirq_exit()			\
 71do {						\
 72	__this_cpu_dec(hardirq_context);	\
 73} while (0)
 74# define lockdep_softirq_enter()		\
 75do {						\
 76	current->softirq_context++;		\
 77} while (0)
 78# define lockdep_softirq_exit()			\
 79do {						\
 80	current->softirq_context--;		\
 81} while (0)
 82
 83# define lockdep_hrtimer_enter(__hrtimer)		\
 84({							\
 85	bool __expires_hardirq = true;			\
 86							\
 87	if (!__hrtimer->is_hard) {			\
 88		current->irq_config = 1;		\
 89		__expires_hardirq = false;		\
 90	}						\
 91	__expires_hardirq;				\
 92})
 93
 94# define lockdep_hrtimer_exit(__expires_hardirq)	\
 95	do {						\
 96		if (!__expires_hardirq)			\
 97			current->irq_config = 0;	\
 98	} while (0)
 99
100# define lockdep_posixtimer_enter()				\
101	  do {							\
102		  current->irq_config = 1;			\
103	  } while (0)
104
105# define lockdep_posixtimer_exit()				\
106	  do {							\
107		  current->irq_config = 0;			\
108	  } while (0)
109
110# define lockdep_irq_work_enter(__work)					\
111	  do {								\
112		  if (!(atomic_read(&__work->flags) & IRQ_WORK_HARD_IRQ))\
113			current->irq_config = 1;			\
114	  } while (0)
115# define lockdep_irq_work_exit(__work)					\
116	  do {								\
117		  if (!(atomic_read(&__work->flags) & IRQ_WORK_HARD_IRQ))\
118			current->irq_config = 0;			\
119	  } while (0)
120
121#else
122# define trace_hardirqs_on_prepare()		do { } while (0)
123# define trace_hardirqs_off_finish()		do { } while (0)
124# define trace_hardirqs_on()			do { } while (0)
125# define trace_hardirqs_off()			do { } while (0)
126# define lockdep_hardirq_context()		0
127# define lockdep_softirq_context(p)		0
128# define lockdep_hardirqs_enabled()		0
129# define lockdep_softirqs_enabled(p)		0
130# define lockdep_hardirq_enter()		do { } while (0)
131# define lockdep_hardirq_threaded()		do { } while (0)
132# define lockdep_hardirq_exit()			do { } while (0)
133# define lockdep_softirq_enter()		do { } while (0)
134# define lockdep_softirq_exit()			do { } while (0)
135# define lockdep_hrtimer_enter(__hrtimer)	false
136# define lockdep_hrtimer_exit(__context)	do { } while (0)
137# define lockdep_posixtimer_enter()		do { } while (0)
138# define lockdep_posixtimer_exit()		do { } while (0)
139# define lockdep_irq_work_enter(__work)		do { } while (0)
140# define lockdep_irq_work_exit(__work)		do { } while (0)
141#endif
142
143#if defined(CONFIG_IRQSOFF_TRACER) || \
144	defined(CONFIG_PREEMPT_TRACER)
145 extern void stop_critical_timings(void);
146 extern void start_critical_timings(void);
147#else
148# define stop_critical_timings() do { } while (0)
149# define start_critical_timings() do { } while (0)
150#endif
151
152/*
153 * Wrap the arch provided IRQ routines to provide appropriate checks.
154 */
155#define raw_local_irq_disable()		arch_local_irq_disable()
156#define raw_local_irq_enable()		arch_local_irq_enable()
157#define raw_local_irq_save(flags)			\
158	do {						\
159		typecheck(unsigned long, flags);	\
160		flags = arch_local_irq_save();		\
161	} while (0)
162#define raw_local_irq_restore(flags)			\
163	do {						\
164		typecheck(unsigned long, flags);	\
165		arch_local_irq_restore(flags);		\
166	} while (0)
167#define raw_local_save_flags(flags)			\
168	do {						\
169		typecheck(unsigned long, flags);	\
170		flags = arch_local_save_flags();	\
171	} while (0)
172#define raw_irqs_disabled_flags(flags)			\
173	({						\
174		typecheck(unsigned long, flags);	\
175		arch_irqs_disabled_flags(flags);	\
176	})
177#define raw_irqs_disabled()		(arch_irqs_disabled())
178#define raw_safe_halt()			arch_safe_halt()
179
180/*
181 * The local_irq_*() APIs are equal to the raw_local_irq*()
182 * if !TRACE_IRQFLAGS.
183 */
184#ifdef CONFIG_TRACE_IRQFLAGS
185
186#define local_irq_enable()				\
187	do {						\
188		trace_hardirqs_on();			\
189		raw_local_irq_enable();			\
190	} while (0)
191
192#define local_irq_disable()				\
193	do {						\
194		bool was_disabled = raw_irqs_disabled();\
195		raw_local_irq_disable();		\
196		if (!was_disabled)			\
197			trace_hardirqs_off();		\
198	} while (0)
199
200#define local_irq_save(flags)				\
201	do {						\
202		raw_local_irq_save(flags);		\
203		if (!raw_irqs_disabled_flags(flags))	\
204			trace_hardirqs_off();		\
205	} while (0)
206
 
207#define local_irq_restore(flags)			\
208	do {						\
209		if (!raw_irqs_disabled_flags(flags))	\
 
 
 
210			trace_hardirqs_on();		\
211		raw_local_irq_restore(flags);		\
 
212	} while (0)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
213
214#define safe_halt()				\
215	do {					\
216		trace_hardirqs_on();		\
217		raw_safe_halt();		\
218	} while (0)
219
220
221#else /* !CONFIG_TRACE_IRQFLAGS */
222
223#define local_irq_enable()	do { raw_local_irq_enable(); } while (0)
224#define local_irq_disable()	do { raw_local_irq_disable(); } while (0)
225#define local_irq_save(flags)	do { raw_local_irq_save(flags); } while (0)
 
 
 
226#define local_irq_restore(flags) do { raw_local_irq_restore(flags); } while (0)
 
 
 
227#define safe_halt()		do { raw_safe_halt(); } while (0)
228
229#endif /* CONFIG_TRACE_IRQFLAGS */
230
231#define local_save_flags(flags)	raw_local_save_flags(flags)
232
233/*
234 * Some architectures don't define arch_irqs_disabled(), so even if either
235 * definition would be fine we need to use different ones for the time being
236 * to avoid build issues.
237 */
238#ifdef CONFIG_TRACE_IRQFLAGS_SUPPORT
239#define irqs_disabled()					\
240	({						\
241		unsigned long _flags;			\
242		raw_local_save_flags(_flags);		\
243		raw_irqs_disabled_flags(_flags);	\
244	})
245#else /* !CONFIG_TRACE_IRQFLAGS_SUPPORT */
246#define irqs_disabled()	raw_irqs_disabled()
247#endif /* CONFIG_TRACE_IRQFLAGS_SUPPORT */
248
249#define irqs_disabled_flags(flags) raw_irqs_disabled_flags(flags)
250
251#endif
v3.1
 
  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
 14#include <linux/typecheck.h>
 15#include <asm/irqflags.h>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 16
 17#ifdef CONFIG_TRACE_IRQFLAGS
 18  extern void trace_softirqs_on(unsigned long ip);
 19  extern void trace_softirqs_off(unsigned long ip);
 20  extern void trace_hardirqs_on(void);
 21  extern void trace_hardirqs_off(void);
 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)
 28# define lockdep_softirq_enter()	do { current->softirq_context++; } while (0)
 29# define lockdep_softirq_exit()	do { current->softirq_context--; } while (0)
 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)
 42# define lockdep_softirq_enter()	do { } while (0)
 43# define lockdep_softirq_exit()		do { } while (0)
 44# define INIT_TRACE_IRQFLAGS
 
 
 
 
 
 
 45#endif
 46
 47#if defined(CONFIG_IRQSOFF_TRACER) || \
 48	defined(CONFIG_PREEMPT_TRACER)
 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
 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 */
 88#ifdef CONFIG_TRACE_IRQFLAGS_SUPPORT
 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)
 
 
 
 
 
 
 
 
 
 
 
 93#define local_irq_save(flags)				\
 94	do {						\
 95		raw_local_irq_save(flags);		\
 96		trace_hardirqs_off();			\
 
 97	} while (0)
 98
 99
100#define local_irq_restore(flags)			\
101	do {						\
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		}					\
109	} while (0)
110#define local_save_flags(flags)				\
111	do {						\
112		raw_local_save_flags(flags);		\
113	} while (0)
114
115#define irqs_disabled_flags(flags)			\
116	({						\
117		raw_irqs_disabled_flags(flags);		\
118	})
119
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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
148#endif /* CONFIG_TRACE_IRQFLAGS_SUPPORT */
 
 
149
150#endif