hardirq.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. #ifndef LINUX_HARDIRQ_H
  2. #define LINUX_HARDIRQ_H
  3. #include <linux/preempt.h>
  4. #include <linux/smp_lock.h>
  5. #include <linux/lockdep.h>
  6. #include <asm/hardirq.h>
  7. #include <asm/system.h>
  8. /*
  9. * We put the hardirq and softirq counter into the preemption
  10. * counter. The bitmask has the following meaning:
  11. *
  12. * - bits 0-7 are the preemption count (max preemption depth: 256)
  13. * - bits 8-15 are the softirq count (max # of softirqs: 256)
  14. *
  15. * The hardirq count can be overridden per architecture, the default is:
  16. *
  17. * - bits 16-27 are the hardirq count (max # of hardirqs: 4096)
  18. * - ( bit 28 is the PREEMPT_ACTIVE flag. )
  19. *
  20. * PREEMPT_MASK: 0x000000ff
  21. * SOFTIRQ_MASK: 0x0000ff00
  22. * HARDIRQ_MASK: 0x0fff0000
  23. */
  24. #define PREEMPT_BITS 8
  25. #define SOFTIRQ_BITS 8
  26. #ifndef HARDIRQ_BITS
  27. #define HARDIRQ_BITS 12
  28. #ifndef MAX_HARDIRQS_PER_CPU
  29. #define MAX_HARDIRQS_PER_CPU NR_IRQS
  30. #endif
  31. /*
  32. * The hardirq mask has to be large enough to have space for potentially
  33. * all IRQ sources in the system nesting on a single CPU.
  34. */
  35. #if (1 << HARDIRQ_BITS) < MAX_HARDIRQS_PER_CPU
  36. # error HARDIRQ_BITS is too low!
  37. #endif
  38. #endif
  39. #define PREEMPT_SHIFT 0
  40. #define SOFTIRQ_SHIFT (PREEMPT_SHIFT + PREEMPT_BITS)
  41. #define HARDIRQ_SHIFT (SOFTIRQ_SHIFT + SOFTIRQ_BITS)
  42. #define __IRQ_MASK(x) ((1UL << (x))-1)
  43. #define PREEMPT_MASK (__IRQ_MASK(PREEMPT_BITS) << PREEMPT_SHIFT)
  44. #define SOFTIRQ_MASK (__IRQ_MASK(SOFTIRQ_BITS) << SOFTIRQ_SHIFT)
  45. #define HARDIRQ_MASK (__IRQ_MASK(HARDIRQ_BITS) << HARDIRQ_SHIFT)
  46. #define PREEMPT_OFFSET (1UL << PREEMPT_SHIFT)
  47. #define SOFTIRQ_OFFSET (1UL << SOFTIRQ_SHIFT)
  48. #define HARDIRQ_OFFSET (1UL << HARDIRQ_SHIFT)
  49. #if PREEMPT_ACTIVE < (1 << (HARDIRQ_SHIFT + HARDIRQ_BITS))
  50. #error PREEMPT_ACTIVE is too low!
  51. #endif
  52. #define hardirq_count() (preempt_count() & HARDIRQ_MASK)
  53. #define softirq_count() (preempt_count() & SOFTIRQ_MASK)
  54. #define irq_count() (preempt_count() & (HARDIRQ_MASK | SOFTIRQ_MASK))
  55. /*
  56. * Are we doing bottom half or hardware interrupt processing?
  57. * Are we in a softirq context? Interrupt context?
  58. */
  59. #define in_irq() (hardirq_count())
  60. #define in_softirq() (softirq_count())
  61. #define in_interrupt() (irq_count())
  62. #define in_atomic() ((preempt_count() & ~PREEMPT_ACTIVE) != 0)
  63. #ifdef CONFIG_PREEMPT
  64. # define PREEMPT_CHECK_OFFSET 1
  65. #else
  66. # define PREEMPT_CHECK_OFFSET 0
  67. #endif
  68. /*
  69. * Check whether we were atomic before we did preempt_disable():
  70. * (used by the scheduler)
  71. */
  72. #define in_atomic_preempt_off() \
  73. ((preempt_count() & ~PREEMPT_ACTIVE) != PREEMPT_CHECK_OFFSET)
  74. #ifdef CONFIG_PREEMPT
  75. # define preemptible() (preempt_count() == 0 && !irqs_disabled())
  76. # define IRQ_EXIT_OFFSET (HARDIRQ_OFFSET-1)
  77. #else
  78. # define preemptible() 0
  79. # define IRQ_EXIT_OFFSET HARDIRQ_OFFSET
  80. #endif
  81. #ifdef CONFIG_SMP
  82. extern void synchronize_irq(unsigned int irq);
  83. #else
  84. # define synchronize_irq(irq) barrier()
  85. #endif
  86. struct task_struct;
  87. #ifndef CONFIG_VIRT_CPU_ACCOUNTING
  88. static inline void account_system_vtime(struct task_struct *tsk)
  89. {
  90. }
  91. #endif
  92. #if defined(CONFIG_PREEMPT_RCU) && defined(CONFIG_NO_HZ)
  93. extern void rcu_irq_enter(void);
  94. extern void rcu_irq_exit(void);
  95. #else
  96. # define rcu_irq_enter() do { } while (0)
  97. # define rcu_irq_exit() do { } while (0)
  98. #endif /* CONFIG_PREEMPT_RCU */
  99. /*
  100. * It is safe to do non-atomic ops on ->hardirq_context,
  101. * because NMI handlers may not preempt and the ops are
  102. * always balanced, so the interrupted value of ->hardirq_context
  103. * will always be restored.
  104. */
  105. #define __irq_enter() \
  106. do { \
  107. rcu_irq_enter(); \
  108. account_system_vtime(current); \
  109. add_preempt_count(HARDIRQ_OFFSET); \
  110. trace_hardirq_enter(); \
  111. } while (0)
  112. /*
  113. * Enter irq context (on NO_HZ, update jiffies):
  114. */
  115. extern void irq_enter(void);
  116. /*
  117. * Exit irq context without processing softirqs:
  118. */
  119. #define __irq_exit() \
  120. do { \
  121. trace_hardirq_exit(); \
  122. account_system_vtime(current); \
  123. sub_preempt_count(HARDIRQ_OFFSET); \
  124. rcu_irq_exit(); \
  125. } while (0)
  126. /*
  127. * Exit irq context and process softirqs if needed:
  128. */
  129. extern void irq_exit(void);
  130. #define nmi_enter() do { lockdep_off(); __irq_enter(); } while (0)
  131. #define nmi_exit() do { __irq_exit(); lockdep_on(); } while (0)
  132. #endif /* LINUX_HARDIRQ_H */