]> bbs.cooldavid.org Git - net-next-2.6.git/blame - include/linux/hardirq.h
"Tree RCU": scalable classic RCU implementation
[net-next-2.6.git] / include / linux / hardirq.h
CommitLineData
1da177e4
LT
1#ifndef LINUX_HARDIRQ_H
2#define LINUX_HARDIRQ_H
3
67bc4eb0 4#include <linux/preempt.h>
1da177e4 5#include <linux/smp_lock.h>
fbb9ce95 6#include <linux/lockdep.h>
1da177e4
LT
7#include <asm/hardirq.h>
8#include <asm/system.h>
9
10/*
11 * We put the hardirq and softirq counter into the preemption
12 * counter. The bitmask has the following meaning:
13 *
14 * - bits 0-7 are the preemption count (max preemption depth: 256)
15 * - bits 8-15 are the softirq count (max # of softirqs: 256)
16 *
17 * The hardirq count can be overridden per architecture, the default is:
18 *
19 * - bits 16-27 are the hardirq count (max # of hardirqs: 4096)
20 * - ( bit 28 is the PREEMPT_ACTIVE flag. )
21 *
22 * PREEMPT_MASK: 0x000000ff
23 * SOFTIRQ_MASK: 0x0000ff00
24 * HARDIRQ_MASK: 0x0fff0000
25 */
26#define PREEMPT_BITS 8
27#define SOFTIRQ_BITS 8
28
29#ifndef HARDIRQ_BITS
30#define HARDIRQ_BITS 12
23d0b8b0
EB
31
32#ifndef MAX_HARDIRQS_PER_CPU
33#define MAX_HARDIRQS_PER_CPU NR_IRQS
34#endif
35
1da177e4
LT
36/*
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.
39 */
23d0b8b0 40#if (1 << HARDIRQ_BITS) < MAX_HARDIRQS_PER_CPU
1da177e4
LT
41# error HARDIRQ_BITS is too low!
42#endif
43#endif
44
45#define PREEMPT_SHIFT 0
46#define SOFTIRQ_SHIFT (PREEMPT_SHIFT + PREEMPT_BITS)
47#define HARDIRQ_SHIFT (SOFTIRQ_SHIFT + SOFTIRQ_BITS)
48
49#define __IRQ_MASK(x) ((1UL << (x))-1)
50
51#define PREEMPT_MASK (__IRQ_MASK(PREEMPT_BITS) << PREEMPT_SHIFT)
1da177e4 52#define SOFTIRQ_MASK (__IRQ_MASK(SOFTIRQ_BITS) << SOFTIRQ_SHIFT)
8f28e8fa 53#define HARDIRQ_MASK (__IRQ_MASK(HARDIRQ_BITS) << HARDIRQ_SHIFT)
1da177e4
LT
54
55#define PREEMPT_OFFSET (1UL << PREEMPT_SHIFT)
56#define SOFTIRQ_OFFSET (1UL << SOFTIRQ_SHIFT)
57#define HARDIRQ_OFFSET (1UL << HARDIRQ_SHIFT)
58
8f28e8fa
PBG
59#if PREEMPT_ACTIVE < (1 << (HARDIRQ_SHIFT + HARDIRQ_BITS))
60#error PREEMPT_ACTIVE is too low!
61#endif
62
1da177e4
LT
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))
66
67/*
68 * Are we doing bottom half or hardware interrupt processing?
69 * Are we in a softirq context? Interrupt context?
70 */
71#define in_irq() (hardirq_count())
72#define in_softirq() (softirq_count())
73#define in_interrupt() (irq_count())
74
8e3e076c
LT
75#if defined(CONFIG_PREEMPT)
76# define PREEMPT_INATOMIC_BASE kernel_locked()
77# define PREEMPT_CHECK_OFFSET 1
78#else
79# define PREEMPT_INATOMIC_BASE 0
80# define PREEMPT_CHECK_OFFSET 0
81#endif
82
8c703d35
JC
83/*
84 * Are we running in atomic context? WARNING: this macro cannot
85 * always detect atomic context; in particular, it cannot know about
86 * held spinlocks in non-preemptible kernels. Thus it should not be
87 * used in the general case to determine whether sleeping is possible.
88 * Do not use in_atomic() in driver code.
89 */
8e3e076c 90#define in_atomic() ((preempt_count() & ~PREEMPT_ACTIVE) != PREEMPT_INATOMIC_BASE)
4da1ce6d
IM
91
92/*
93 * Check whether we were atomic before we did preempt_disable():
8e3e076c 94 * (used by the scheduler, *after* releasing the kernel lock)
4da1ce6d
IM
95 */
96#define in_atomic_preempt_off() \
97 ((preempt_count() & ~PREEMPT_ACTIVE) != PREEMPT_CHECK_OFFSET)
98
1da177e4
LT
99#ifdef CONFIG_PREEMPT
100# define preemptible() (preempt_count() == 0 && !irqs_disabled())
101# define IRQ_EXIT_OFFSET (HARDIRQ_OFFSET-1)
102#else
103# define preemptible() 0
104# define IRQ_EXIT_OFFSET HARDIRQ_OFFSET
105#endif
106
107#ifdef CONFIG_SMP
108extern void synchronize_irq(unsigned int irq);
109#else
110# define synchronize_irq(irq) barrier()
111#endif
112
f037360f
AV
113struct task_struct;
114
1da177e4 115#ifndef CONFIG_VIRT_CPU_ACCOUNTING
1da177e4
LT
116static inline void account_system_vtime(struct task_struct *tsk)
117{
118}
119#endif
120
64db4cff 121#if defined(CONFIG_NO_HZ) && !defined(CONFIG_CLASSIC_RCU)
2232c2d8
SR
122extern void rcu_irq_enter(void);
123extern void rcu_irq_exit(void);
64db4cff
PM
124extern void rcu_nmi_enter(void);
125extern void rcu_nmi_exit(void);
2232c2d8
SR
126#else
127# define rcu_irq_enter() do { } while (0)
128# define rcu_irq_exit() do { } while (0)
64db4cff
PM
129# define rcu_nmi_enter() do { } while (0)
130# define rcu_nmi_exit() do { } while (0)
131#endif /* #if defined(CONFIG_NO_HZ) && !defined(CONFIG_CLASSIC_RCU) */
2232c2d8 132
de30a2b3
IM
133/*
134 * It is safe to do non-atomic ops on ->hardirq_context,
135 * because NMI handlers may not preempt and the ops are
136 * always balanced, so the interrupted value of ->hardirq_context
137 * will always be restored.
138 */
79bf2bb3
TG
139#define __irq_enter() \
140 do { \
141 account_system_vtime(current); \
142 add_preempt_count(HARDIRQ_OFFSET); \
143 trace_hardirq_enter(); \
144 } while (0)
145
146/*
147 * Enter irq context (on NO_HZ, update jiffies):
148 */
dde4b2b5 149extern void irq_enter(void);
de30a2b3
IM
150
151/*
152 * Exit irq context without processing softirqs:
153 */
154#define __irq_exit() \
155 do { \
156 trace_hardirq_exit(); \
157 account_system_vtime(current); \
158 sub_preempt_count(HARDIRQ_OFFSET); \
1da177e4
LT
159 } while (0)
160
de30a2b3
IM
161/*
162 * Exit irq context and process softirqs if needed:
163 */
1da177e4
LT
164extern void irq_exit(void);
165
64db4cff
PM
166#define nmi_enter() do { lockdep_off(); rcu_nmi_enter(); __irq_enter(); } while (0)
167#define nmi_exit() do { __irq_exit(); rcu_nmi_exit(); lockdep_on(); } while (0)
de30a2b3 168
1da177e4 169#endif /* LINUX_HARDIRQ_H */