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_disable() \
32 inc_preempt_count(); \
36 #define preempt_enable_no_resched() \
39 dec_preempt_count(); \
42 #define preempt_check_resched() \
44 if (unlikely(test_thread_flag(TIF_NEED_RESCHED))) \
48 #define preempt_enable() \
50 preempt_enable_no_resched(); \
52 preempt_check_resched(); \
55 /* For debugging and tracer internals only! */
56 #define add_preempt_count_notrace(val) \
57 do { preempt_count() += (val); } while (0)
58 #define sub_preempt_count_notrace(val) \
59 do { preempt_count() -= (val); } while (0)
60 #define inc_preempt_count_notrace() add_preempt_count_notrace(1)
61 #define dec_preempt_count_notrace() sub_preempt_count_notrace(1)
63 #define preempt_disable_notrace() \
65 inc_preempt_count_notrace(); \
69 #define preempt_enable_no_resched_notrace() \
72 dec_preempt_count_notrace(); \
75 /* preempt_check_resched is OK to trace */
76 #define preempt_enable_notrace() \
78 preempt_enable_no_resched_notrace(); \
80 preempt_check_resched(); \
85 #define preempt_disable() do { } while (0)
86 #define preempt_enable_no_resched() do { } while (0)
87 #define preempt_enable() do { } while (0)
88 #define preempt_check_resched() do { } while (0)
90 #define preempt_disable_notrace() do { } while (0)
91 #define preempt_enable_no_resched_notrace() do { } while (0)
92 #define preempt_enable_notrace() do { } while (0)
96 #ifdef CONFIG_PREEMPT_NOTIFIERS
98 struct preempt_notifier;
101 * preempt_ops - notifiers called when a task is preempted and rescheduled
102 * @sched_in: we're about to be rescheduled:
103 * notifier: struct preempt_notifier for the task being scheduled
104 * cpu: cpu we're scheduled on
105 * @sched_out: we've just been preempted
106 * notifier: struct preempt_notifier for the task being preempted
107 * next: the task that's kicking us out
110 void (*sched_in)(struct preempt_notifier *notifier, int cpu);
111 void (*sched_out)(struct preempt_notifier *notifier,
112 struct task_struct *next);
116 * preempt_notifier - key for installing preemption notifiers
117 * @link: internal use
118 * @ops: defines the notifier functions to be called
120 * Usually used in conjunction with container_of().
122 struct preempt_notifier {
123 struct hlist_node link;
124 struct preempt_ops *ops;
127 void preempt_notifier_register(struct preempt_notifier *notifier);
128 void preempt_notifier_unregister(struct preempt_notifier *notifier);
130 static inline void preempt_notifier_init(struct preempt_notifier *notifier,
131 struct preempt_ops *ops)
133 INIT_HLIST_NODE(¬ifier->link);
139 #endif /* __LINUX_PREEMPT_H */