hardirq.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #ifndef LINUX_HARDIRQ_H
  2. #define LINUX_HARDIRQ_H
  3. #include <linux/config.h>
  4. #include <linux/smp_lock.h>
  5. #include <asm/hardirq.h>
  6. #include <asm/system.h>
  7. /*
  8. * We put the hardirq and softirq counter into the preemption
  9. * counter. The bitmask has the following meaning:
  10. *
  11. * - bits 0-7 are the preemption count (max preemption depth: 256)
  12. * - bits 8-15 are the softirq count (max # of softirqs: 256)
  13. *
  14. * The hardirq count can be overridden per architecture, the default is:
  15. *
  16. * - bits 16-27 are the hardirq count (max # of hardirqs: 4096)
  17. * - ( bit 28 is the PREEMPT_ACTIVE flag. )
  18. *
  19. * PREEMPT_MASK: 0x000000ff
  20. * SOFTIRQ_MASK: 0x0000ff00
  21. * HARDIRQ_MASK: 0x0fff0000
  22. */
  23. #define PREEMPT_BITS 8
  24. #define SOFTIRQ_BITS 8
  25. #ifndef HARDIRQ_BITS
  26. #define HARDIRQ_BITS 12
  27. /*
  28. * The hardirq mask has to be large enough to have space for potentially
  29. * all IRQ sources in the system nesting on a single CPU.
  30. */
  31. #if (1 << HARDIRQ_BITS) < NR_IRQS
  32. # error HARDIRQ_BITS is too low!
  33. #endif
  34. #endif
  35. #define PREEMPT_SHIFT 0
  36. #define SOFTIRQ_SHIFT (PREEMPT_SHIFT + PREEMPT_BITS)
  37. #define HARDIRQ_SHIFT (SOFTIRQ_SHIFT + SOFTIRQ_BITS)
  38. #define __IRQ_MASK(x) ((1UL << (x))-1)
  39. #define PREEMPT_MASK (__IRQ_MASK(PREEMPT_BITS) << PREEMPT_SHIFT)
  40. #define SOFTIRQ_MASK (__IRQ_MASK(SOFTIRQ_BITS) << SOFTIRQ_SHIFT)
  41. #define HARDIRQ_MASK (__IRQ_MASK(HARDIRQ_BITS) << HARDIRQ_SHIFT)
  42. #define PREEMPT_OFFSET (1UL << PREEMPT_SHIFT)
  43. #define SOFTIRQ_OFFSET (1UL << SOFTIRQ_SHIFT)
  44. #define HARDIRQ_OFFSET (1UL << HARDIRQ_SHIFT)
  45. #if PREEMPT_ACTIVE < (1 << (HARDIRQ_SHIFT + HARDIRQ_BITS))
  46. #error PREEMPT_ACTIVE is too low!
  47. #endif
  48. #define hardirq_count() (preempt_count() & HARDIRQ_MASK)
  49. #define softirq_count() (preempt_count() & SOFTIRQ_MASK)
  50. #define irq_count() (preempt_count() & (HARDIRQ_MASK | SOFTIRQ_MASK))
  51. /*
  52. * Are we doing bottom half or hardware interrupt processing?
  53. * Are we in a softirq context? Interrupt context?
  54. */
  55. #define in_irq() (hardirq_count())
  56. #define in_softirq() (softirq_count())
  57. #define in_interrupt() (irq_count())
  58. #if defined(CONFIG_PREEMPT) && !defined(CONFIG_PREEMPT_BKL)
  59. # define in_atomic() ((preempt_count() & ~PREEMPT_ACTIVE) != kernel_locked())
  60. #else
  61. # define in_atomic() ((preempt_count() & ~PREEMPT_ACTIVE) != 0)
  62. #endif
  63. #ifdef CONFIG_PREEMPT
  64. # define preemptible() (preempt_count() == 0 && !irqs_disabled())
  65. # define IRQ_EXIT_OFFSET (HARDIRQ_OFFSET-1)
  66. #else
  67. # define preemptible() 0
  68. # define IRQ_EXIT_OFFSET HARDIRQ_OFFSET
  69. #endif
  70. #ifdef CONFIG_SMP
  71. extern void synchronize_irq(unsigned int irq);
  72. #else
  73. # define synchronize_irq(irq) barrier()
  74. #endif
  75. #define nmi_enter() irq_enter()
  76. #define nmi_exit() sub_preempt_count(HARDIRQ_OFFSET)
  77. #ifndef CONFIG_VIRT_CPU_ACCOUNTING
  78. static inline void account_user_vtime(struct task_struct *tsk)
  79. {
  80. }
  81. static inline void account_system_vtime(struct task_struct *tsk)
  82. {
  83. }
  84. #endif
  85. #define irq_enter() \
  86. do { \
  87. account_system_vtime(current); \
  88. add_preempt_count(HARDIRQ_OFFSET); \
  89. } while (0)
  90. extern void irq_exit(void);
  91. #endif /* LINUX_HARDIRQ_H */