File: /Users/paulross/dev/linux/linux-3.13/include/linux/preempt_mask.h

Green shading in the line number column means the source is part of the translation unit, red means it is conditionally excluded. Highlighted line numbers link to the translation unit page. Highlighted macros link to the macro page.

       1: #ifndef LINUX_PREEMPT_MASK_H
       2: #define LINUX_PREEMPT_MASK_H
       3: 
       4: #include <linux/preempt.h>
       5: #include <asm/hardirq.h>
       6: 
       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 could in theory be the same as the number of
      15:  * interrupts in the system, but we run all interrupt handlers with
      16:  * interrupts disabled, so we cannot have nesting interrupts. Though
      17:  * there are a few palaeontologic drivers which reenable interrupts in
      18:  * the handler, so we need more than one bit here.
      19:  *
      20:  * PREEMPT_MASK:    0x000000ff
      21:  * SOFTIRQ_MASK:    0x0000ff00
      22:  * HARDIRQ_MASK:    0x000f0000
      23:  *     NMI_MASK:    0x00100000
      24:  * PREEMPT_ACTIVE:    0x00200000
      25:  */
      26: #define PREEMPT_BITS    8
      27: #define SOFTIRQ_BITS    8
      28: #define HARDIRQ_BITS    4
      29: #define NMI_BITS    1
      30: 
      31: #define PREEMPT_SHIFT    0
      32: #define SOFTIRQ_SHIFT    (PREEMPT_SHIFT + PREEMPT_BITS)
      33: #define HARDIRQ_SHIFT    (SOFTIRQ_SHIFT + SOFTIRQ_BITS)
      34: #define NMI_SHIFT    (HARDIRQ_SHIFT + HARDIRQ_BITS)
      35: 
      36: #define __IRQ_MASK(x)    ((1UL << (x))-1)
      37: 
      38: #define PREEMPT_MASK    (__IRQ_MASK(PREEMPT_BITS) << PREEMPT_SHIFT)
      39: #define SOFTIRQ_MASK    (__IRQ_MASK(SOFTIRQ_BITS) << SOFTIRQ_SHIFT)
      40: #define HARDIRQ_MASK    (__IRQ_MASK(HARDIRQ_BITS) << HARDIRQ_SHIFT)
      41: #define NMI_MASK    (__IRQ_MASK(NMI_BITS)     << NMI_SHIFT)
      42: 
      43: #define PREEMPT_OFFSET    (1UL << PREEMPT_SHIFT)
      44: #define SOFTIRQ_OFFSET    (1UL << SOFTIRQ_SHIFT)
      45: #define HARDIRQ_OFFSET    (1UL << HARDIRQ_SHIFT)
      46: #define NMI_OFFSET    (1UL << NMI_SHIFT)
      47: 
      48: #define SOFTIRQ_DISABLE_OFFSET    (2 * SOFTIRQ_OFFSET)
      49: 
      50: #define PREEMPT_ACTIVE_BITS    1
      51: #define PREEMPT_ACTIVE_SHIFT    (NMI_SHIFT + NMI_BITS)
      52: #define PREEMPT_ACTIVE    (__IRQ_MASK(PREEMPT_ACTIVE_BITS) << PREEMPT_ACTIVE_SHIFT)
      53: 
      54: #define hardirq_count()    (preempt_count() & HARDIRQ_MASK)
      55: #define softirq_count()    (preempt_count() & SOFTIRQ_MASK)
      56: #define irq_count()    (preempt_count() & (HARDIRQ_MASK | SOFTIRQ_MASK \
      57:                  | NMI_MASK))
      58: 
      59: /*
      60:  * Are we doing bottom half or hardware interrupt processing?
      61:  * Are we in a softirq context? Interrupt context?
      62:  * in_softirq - Are we currently processing softirq or have bh disabled?
      63:  * in_serving_softirq - Are we currently processing softirq?
      64:  */
      65: #define in_irq()        (hardirq_count())
      66: #define in_softirq()        (softirq_count())
      67: #define in_interrupt()        (irq_count())
      68: #define in_serving_softirq()    (softirq_count() & SOFTIRQ_OFFSET)
      69: 
      70: /*
      71:  * Are we in NMI context?
      72:  */
      73: #define in_nmi()    (preempt_count() & NMI_MASK)
      74: 
      75: #if defined(CONFIG_PREEMPT_COUNT)
      76: # define PREEMPT_CHECK_OFFSET 1
      77: #else
      78: # define PREEMPT_CHECK_OFFSET 0
      79: #endif
      80: 
      81: /*
      82:  * Are we running in atomic context?  WARNING: this macro cannot
      83:  * always detect atomic context; in particular, it cannot know about
      84:  * held spinlocks in non-preemptible kernels.  Thus it should not be
      85:  * used in the general case to determine whether sleeping is possible.
      86:  * Do not use in_atomic() in driver code.
      87:  */
      88: #define in_atomic()    ((preempt_count() & ~PREEMPT_ACTIVE) != 0)
      89: 
      90: /*
      91:  * Check whether we were atomic before we did preempt_disable():
      92:  * (used by the scheduler, *after* releasing the kernel lock)
      93:  */
      94: #define in_atomic_preempt_off() \
      95:         ((preempt_count() & ~PREEMPT_ACTIVE) != PREEMPT_CHECK_OFFSET)
      96: 
      97: #ifdef CONFIG_PREEMPT_COUNT
      98: # define preemptible()    (preempt_count() == 0 && !irqs_disabled())
      99: #else
     100: # define preemptible()    0
     101: #endif
     102: 
     103: #endif /* LINUX_PREEMPT_MASK_H */
     104: