1 #ifndef __LINUX_PREEMPT_H
2 #define __LINUX_PREEMPT_H
5 * include/linux/preempt.h - macros for accessing and manipulating
6 * preempt_count (used for kernel preemption, interrupt count, etc.)
9 #include <linux/linkage.h>
10 #include <linux/list.h>
13 * We use the MSB mostly because its available; see <linux/preempt_mask.h> for
14 * the other bits -- can't include that header due to inclusion hell.
16 #define PREEMPT_NEED_RESCHED 0x80000000
18 #include <asm/preempt.h>
20 #if defined(CONFIG_DEBUG_PREEMPT) || defined(CONFIG_PREEMPT_TRACER)
21 extern void preempt_count_add(int val);
22 extern void preempt_count_sub(int val);
23 #define preempt_count_dec_and_test() ({ preempt_count_sub(1); should_resched(); })
25 #define preempt_count_add(val) __preempt_count_add(val)
26 #define preempt_count_sub(val) __preempt_count_sub(val)
27 #define preempt_count_dec_and_test() __preempt_count_dec_and_test()
30 #define __preempt_count_inc() __preempt_count_add(1)
31 #define __preempt_count_dec() __preempt_count_sub(1)
33 #define preempt_count_inc() preempt_count_add(1)
34 #define preempt_count_dec() preempt_count_sub(1)
36 #ifdef CONFIG_PREEMPT_COUNT
38 #define preempt_disable() \
40 preempt_count_inc(); \
44 #define sched_preempt_enable_no_resched() \
47 preempt_count_dec(); \
50 #define preempt_enable_no_resched() sched_preempt_enable_no_resched()
53 asmlinkage void preempt_schedule(void);
54 #define preempt_enable() \
57 if (unlikely(preempt_count_dec_and_test())) \
61 #define preempt_check_resched() \
63 if (should_resched()) \
68 #define preempt_enable() preempt_enable_no_resched()
69 #define preempt_check_resched() do { } while (0)
72 #define preempt_disable_notrace() \
74 __preempt_count_inc(); \
78 #define preempt_enable_no_resched_notrace() \
81 __preempt_count_dec(); \
86 #ifdef CONFIG_CONTEXT_TRACKING
87 asmlinkage void preempt_schedule_context(void);
89 #define preempt_schedule_context() preempt_schedule()
92 #define preempt_enable_notrace() \
95 if (unlikely(__preempt_count_dec_and_test())) \
96 preempt_schedule_context(); \
99 #define preempt_enable_notrace() preempt_enable_no_resched_notrace()
102 #else /* !CONFIG_PREEMPT_COUNT */
105 * Even if we don't have any preemption, we need preempt disable/enable
106 * to be barriers, so that we don't have things like get_user/put_user
107 * that can cause faults and scheduling migrate into our preempt-protected
110 #define preempt_disable() barrier()
111 #define sched_preempt_enable_no_resched() barrier()
112 #define preempt_enable_no_resched() barrier()
113 #define preempt_enable() barrier()
114 #define preempt_check_resched() do { } while (0)
116 #define preempt_disable_notrace() barrier()
117 #define preempt_enable_no_resched_notrace() barrier()
118 #define preempt_enable_notrace() barrier()
120 #endif /* CONFIG_PREEMPT_COUNT */
122 #ifdef CONFIG_PREEMPT_NOTIFIERS
124 struct preempt_notifier;
127 * preempt_ops - notifiers called when a task is preempted and rescheduled
128 * @sched_in: we're about to be rescheduled:
129 * notifier: struct preempt_notifier for the task being scheduled
130 * cpu: cpu we're scheduled on
131 * @sched_out: we've just been preempted
132 * notifier: struct preempt_notifier for the task being preempted
133 * next: the task that's kicking us out
135 * Please note that sched_in and out are called under different
136 * contexts. sched_out is called with rq lock held and irq disabled
137 * while sched_in is called without rq lock and irq enabled. This
138 * difference is intentional and depended upon by its users.
141 void (*sched_in)(struct preempt_notifier *notifier, int cpu);
142 void (*sched_out)(struct preempt_notifier *notifier,
143 struct task_struct *next);
147 * preempt_notifier - key for installing preemption notifiers
148 * @link: internal use
149 * @ops: defines the notifier functions to be called
151 * Usually used in conjunction with container_of().
153 struct preempt_notifier {
154 struct hlist_node link;
155 struct preempt_ops *ops;
158 void preempt_notifier_register(struct preempt_notifier *notifier);
159 void preempt_notifier_unregister(struct preempt_notifier *notifier);
161 static inline void preempt_notifier_init(struct preempt_notifier *notifier,
162 struct preempt_ops *ops)
164 INIT_HLIST_NODE(¬ifier->link);
170 #endif /* __LINUX_PREEMPT_H */