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