irqflags.h 4.7 KB

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