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/thread_info.h>
10 #include <linux/linkage.h>
11 #include <linux/list.h>
13 #if defined(CONFIG_DEBUG_PREEMPT) || defined(CONFIG_PREEMPT_TRACER)
14 extern void add_preempt_count(int val
);
15 extern void sub_preempt_count(int val
);
17 # define add_preempt_count(val) do { preempt_count() += (val); } while (0)
18 # define sub_preempt_count(val) do { preempt_count() -= (val); } while (0)
21 #define inc_preempt_count() add_preempt_count(1)
22 #define dec_preempt_count() sub_preempt_count(1)
24 #define preempt_count() (current_thread_info()->preempt_count)
28 asmlinkage
void preempt_schedule(void);
30 #define preempt_check_resched() \
32 if (unlikely(test_thread_flag(TIF_NEED_RESCHED))) \
36 #ifdef CONFIG_CONTEXT_TRACKING
38 void preempt_schedule_context(void);
40 #define preempt_check_resched_context() \
42 if (unlikely(test_thread_flag(TIF_NEED_RESCHED))) \
43 preempt_schedule_context(); \
47 #define preempt_check_resched_context() preempt_check_resched()
49 #endif /* CONFIG_CONTEXT_TRACKING */
51 #else /* !CONFIG_PREEMPT */
53 #define preempt_check_resched() do { } while (0)
54 #define preempt_check_resched_context() do { } while (0)
56 #endif /* CONFIG_PREEMPT */
59 #ifdef CONFIG_PREEMPT_COUNT
61 #define preempt_disable() \
63 inc_preempt_count(); \
67 #define sched_preempt_enable_no_resched() \
70 dec_preempt_count(); \
73 #define preempt_enable_no_resched() sched_preempt_enable_no_resched()
75 #define preempt_enable() \
77 preempt_enable_no_resched(); \
79 preempt_check_resched(); \
82 /* For debugging and tracer internals only! */
83 #define add_preempt_count_notrace(val) \
84 do { preempt_count() += (val); } while (0)
85 #define sub_preempt_count_notrace(val) \
86 do { preempt_count() -= (val); } while (0)
87 #define inc_preempt_count_notrace() add_preempt_count_notrace(1)
88 #define dec_preempt_count_notrace() sub_preempt_count_notrace(1)
90 #define preempt_disable_notrace() \
92 inc_preempt_count_notrace(); \
96 #define preempt_enable_no_resched_notrace() \
99 dec_preempt_count_notrace(); \
102 /* preempt_check_resched is OK to trace */
103 #define preempt_enable_notrace() \
105 preempt_enable_no_resched_notrace(); \
107 preempt_check_resched_context(); \
110 #else /* !CONFIG_PREEMPT_COUNT */
113 * Even if we don't have any preemption, we need preempt disable/enable
114 * to be barriers, so that we don't have things like get_user/put_user
115 * that can cause faults and scheduling migrate into our preempt-protected
118 #define preempt_disable() barrier()
119 #define sched_preempt_enable_no_resched() barrier()
120 #define preempt_enable_no_resched() barrier()
121 #define preempt_enable() barrier()
123 #define preempt_disable_notrace() barrier()
124 #define preempt_enable_no_resched_notrace() barrier()
125 #define preempt_enable_notrace() barrier()
127 #endif /* CONFIG_PREEMPT_COUNT */
129 #ifdef CONFIG_PREEMPT_NOTIFIERS
131 struct preempt_notifier
;
134 * preempt_ops - notifiers called when a task is preempted and rescheduled
135 * @sched_in: we're about to be rescheduled:
136 * notifier: struct preempt_notifier for the task being scheduled
137 * cpu: cpu we're scheduled on
138 * @sched_out: we've just been preempted
139 * notifier: struct preempt_notifier for the task being preempted
140 * next: the task that's kicking us out
142 * Please note that sched_in and out are called under different
143 * contexts. sched_out is called with rq lock held and irq disabled
144 * while sched_in is called without rq lock and irq enabled. This
145 * difference is intentional and depended upon by its users.
148 void (*sched_in
)(struct preempt_notifier
*notifier
, int cpu
);
149 void (*sched_out
)(struct preempt_notifier
*notifier
,
150 struct task_struct
*next
);
154 * preempt_notifier - key for installing preemption notifiers
155 * @link: internal use
156 * @ops: defines the notifier functions to be called
158 * Usually used in conjunction with container_of().
160 struct preempt_notifier
{
161 struct hlist_node link
;
162 struct preempt_ops
*ops
;
165 void preempt_notifier_register(struct preempt_notifier
*notifier
);
166 void preempt_notifier_unregister(struct preempt_notifier
*notifier
);
168 static inline void preempt_notifier_init(struct preempt_notifier
*notifier
,
169 struct preempt_ops
*ops
)
171 INIT_HLIST_NODE(¬ifier
->link
);
177 #endif /* __LINUX_PREEMPT_H */
This page took 0.034787 seconds and 6 git commands to generate.