irqflags.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. #include <linux/typecheck.h>
  15. #include <asm/irqflags.h>
  16. /* Currently trace_softirqs_on/off is used only by lockdep */
  17. #ifdef CONFIG_PROVE_LOCKING
  18. extern void trace_softirqs_on(unsigned long ip);
  19. extern void trace_softirqs_off(unsigned long ip);
  20. #else
  21. # define trace_softirqs_on(ip) do { } while (0)
  22. # define trace_softirqs_off(ip) do { } while (0)
  23. #endif
  24. #ifdef CONFIG_TRACE_IRQFLAGS
  25. extern void trace_hardirqs_on(void);
  26. extern void trace_hardirqs_off(void);
  27. # define trace_hardirq_context(p) ((p)->hardirq_context)
  28. # define trace_softirq_context(p) ((p)->softirq_context)
  29. # define trace_hardirqs_enabled(p) ((p)->hardirqs_enabled)
  30. # define trace_softirqs_enabled(p) ((p)->softirqs_enabled)
  31. # define trace_hardirq_enter() \
  32. do { \
  33. current->hardirq_context++; \
  34. } while (0)
  35. # define trace_hardirq_exit() \
  36. do { \
  37. current->hardirq_context--; \
  38. } while (0)
  39. # define lockdep_softirq_enter() \
  40. do { \
  41. current->softirq_context++; \
  42. } while (0)
  43. # define lockdep_softirq_exit() \
  44. do { \
  45. current->softirq_context--; \
  46. } while (0)
  47. #else
  48. # define trace_hardirqs_on() do { } while (0)
  49. # define trace_hardirqs_off() do { } while (0)
  50. # define trace_hardirq_context(p) 0
  51. # define trace_softirq_context(p) 0
  52. # define trace_hardirqs_enabled(p) 0
  53. # define trace_softirqs_enabled(p) 0
  54. # define trace_hardirq_enter() do { } while (0)
  55. # define trace_hardirq_exit() do { } while (0)
  56. # define lockdep_softirq_enter() do { } while (0)
  57. # define lockdep_softirq_exit() do { } while (0)
  58. #endif
  59. #if defined(CONFIG_IRQSOFF_TRACER) || \
  60. defined(CONFIG_PREEMPT_TRACER)
  61. extern void stop_critical_timings(void);
  62. extern void start_critical_timings(void);
  63. #else
  64. # define stop_critical_timings() do { } while (0)
  65. # define start_critical_timings() do { } while (0)
  66. #endif
  67. /*
  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. * The local_irq_*() APIs are equal to the raw_local_irq*()
  96. * if !TRACE_IRQFLAGS.
  97. */
  98. #ifdef CONFIG_TRACE_IRQFLAGS
  99. #define local_irq_enable() \
  100. do { trace_hardirqs_on(); raw_local_irq_enable(); } while (0)
  101. #define local_irq_disable() \
  102. do { raw_local_irq_disable(); trace_hardirqs_off(); } while (0)
  103. #define local_irq_save(flags) \
  104. do { \
  105. raw_local_irq_save(flags); \
  106. trace_hardirqs_off(); \
  107. } while (0)
  108. #define local_irq_restore(flags) \
  109. do { \
  110. if (raw_irqs_disabled_flags(flags)) { \
  111. raw_local_irq_restore(flags); \
  112. trace_hardirqs_off(); \
  113. } else { \
  114. trace_hardirqs_on(); \
  115. raw_local_irq_restore(flags); \
  116. } \
  117. } while (0)
  118. #define safe_halt() \
  119. do { \
  120. trace_hardirqs_on(); \
  121. raw_safe_halt(); \
  122. } while (0)
  123. #else /* !CONFIG_TRACE_IRQFLAGS */
  124. #define local_irq_enable() do { raw_local_irq_enable(); } while (0)
  125. #define local_irq_disable() do { raw_local_irq_disable(); } while (0)
  126. #define local_irq_save(flags) \
  127. do { \
  128. raw_local_irq_save(flags); \
  129. } while (0)
  130. #define local_irq_restore(flags) do { raw_local_irq_restore(flags); } while (0)
  131. #define safe_halt() do { raw_safe_halt(); } while (0)
  132. #endif /* CONFIG_TRACE_IRQFLAGS */
  133. #define local_save_flags(flags) raw_local_save_flags(flags)
  134. /*
  135. * Some architectures don't define arch_irqs_disabled(), so even if either
  136. * definition would be fine we need to use different ones for the time being
  137. * to avoid build issues.
  138. */
  139. #ifdef CONFIG_TRACE_IRQFLAGS_SUPPORT
  140. #define irqs_disabled() \
  141. ({ \
  142. unsigned long _flags; \
  143. raw_local_save_flags(_flags); \
  144. raw_irqs_disabled_flags(_flags); \
  145. })
  146. #else /* !CONFIG_TRACE_IRQFLAGS_SUPPORT */
  147. #define irqs_disabled() raw_irqs_disabled()
  148. #endif /* CONFIG_TRACE_IRQFLAGS_SUPPORT */
  149. #define irqs_disabled_flags(flags) raw_irqs_disabled_flags(flags)
  150. #endif