irqflags.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. #ifdef CONFIG_TRACE_IRQFLAGS
  17. extern void trace_softirqs_on(unsigned long ip);
  18. extern void trace_softirqs_off(unsigned long ip);
  19. extern void trace_hardirqs_on(void);
  20. extern void trace_hardirqs_off(void);
  21. # 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() \
  26. do { \
  27. current->hardirq_context++; \
  28. } while (0)
  29. # define trace_hardirq_exit() \
  30. do { \
  31. current->hardirq_context--; \
  32. } while (0)
  33. # define lockdep_softirq_enter() \
  34. do { \
  35. current->softirq_context++; \
  36. } while (0)
  37. # define lockdep_softirq_exit() \
  38. do { \
  39. current->softirq_context--; \
  40. } while (0)
  41. # define INIT_TRACE_IRQFLAGS .softirqs_enabled = 1,
  42. #else
  43. # define trace_hardirqs_on() do { } while (0)
  44. # define trace_hardirqs_off() do { } while (0)
  45. # define trace_softirqs_on(ip) do { } while (0)
  46. # define trace_softirqs_off(ip) do { } while (0)
  47. # define trace_hardirq_context(p) 0
  48. # define trace_softirq_context(p) 0
  49. # define trace_hardirqs_enabled(p) 0
  50. # define trace_softirqs_enabled(p) 0
  51. # define trace_hardirq_enter() do { } while (0)
  52. # define trace_hardirq_exit() do { } while (0)
  53. # define lockdep_softirq_enter() do { } while (0)
  54. # define lockdep_softirq_exit() do { } while (0)
  55. # define INIT_TRACE_IRQFLAGS
  56. #endif
  57. #if defined(CONFIG_IRQSOFF_TRACER) || \
  58. defined(CONFIG_PREEMPT_TRACER)
  59. extern void stop_critical_timings(void);
  60. extern void start_critical_timings(void);
  61. #else
  62. # define stop_critical_timings() do { } while (0)
  63. # define start_critical_timings() do { } while (0)
  64. #endif
  65. /*
  66. * Wrap the arch provided IRQ routines to provide appropriate checks.
  67. */
  68. #define raw_local_irq_disable() arch_local_irq_disable()
  69. #define raw_local_irq_enable() arch_local_irq_enable()
  70. #define raw_local_irq_save(flags) \
  71. do { \
  72. typecheck(unsigned long, flags); \
  73. flags = arch_local_irq_save(); \
  74. } while (0)
  75. #define raw_local_irq_restore(flags) \
  76. do { \
  77. typecheck(unsigned long, flags); \
  78. arch_local_irq_restore(flags); \
  79. } while (0)
  80. #define raw_local_save_flags(flags) \
  81. do { \
  82. typecheck(unsigned long, flags); \
  83. flags = arch_local_save_flags(); \
  84. } while (0)
  85. #define raw_irqs_disabled_flags(flags) \
  86. ({ \
  87. typecheck(unsigned long, flags); \
  88. arch_irqs_disabled_flags(flags); \
  89. })
  90. #define raw_irqs_disabled() (arch_irqs_disabled())
  91. #define raw_safe_halt() arch_safe_halt()
  92. /*
  93. * The local_irq_*() APIs are equal to the raw_local_irq*()
  94. * if !TRACE_IRQFLAGS.
  95. */
  96. #ifdef CONFIG_TRACE_IRQFLAGS
  97. #define local_irq_enable() \
  98. do { trace_hardirqs_on(); raw_local_irq_enable(); } while (0)
  99. #define local_irq_disable() \
  100. do { raw_local_irq_disable(); trace_hardirqs_off(); } while (0)
  101. #define local_irq_save(flags) \
  102. do { \
  103. raw_local_irq_save(flags); \
  104. trace_hardirqs_off(); \
  105. } while (0)
  106. #define local_irq_restore(flags) \
  107. do { \
  108. if (raw_irqs_disabled_flags(flags)) { \
  109. raw_local_irq_restore(flags); \
  110. trace_hardirqs_off(); \
  111. } else { \
  112. trace_hardirqs_on(); \
  113. raw_local_irq_restore(flags); \
  114. } \
  115. } while (0)
  116. #define safe_halt() \
  117. do { \
  118. trace_hardirqs_on(); \
  119. raw_safe_halt(); \
  120. } while (0)
  121. #else /* !CONFIG_TRACE_IRQFLAGS */
  122. #define local_irq_enable() do { raw_local_irq_enable(); } while (0)
  123. #define local_irq_disable() do { raw_local_irq_disable(); } while (0)
  124. #define local_irq_save(flags) \
  125. do { \
  126. raw_local_irq_save(flags); \
  127. } while (0)
  128. #define local_irq_restore(flags) do { raw_local_irq_restore(flags); } while (0)
  129. #define safe_halt() do { raw_safe_halt(); } while (0)
  130. #endif /* CONFIG_TRACE_IRQFLAGS */
  131. #define local_save_flags(flags) raw_local_save_flags(flags)
  132. /*
  133. * Some architectures don't define arch_irqs_disabled(), so even if either
  134. * definition would be fine we need to use different ones for the time being
  135. * to avoid build issues.
  136. */
  137. #ifdef CONFIG_TRACE_IRQFLAGS_SUPPORT
  138. #define irqs_disabled() \
  139. ({ \
  140. unsigned long _flags; \
  141. raw_local_save_flags(_flags); \
  142. raw_irqs_disabled_flags(_flags); \
  143. })
  144. #else /* !CONFIG_TRACE_IRQFLAGS_SUPPORT */
  145. #define irqs_disabled() raw_irqs_disabled()
  146. #endif /* CONFIG_TRACE_IRQFLAGS_SUPPORT */
  147. #define irqs_disabled_flags(flags) raw_irqs_disabled_flags(flags)
  148. #endif