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