2005-04-16 16:20:36 -06:00
|
|
|
#ifndef __LINUX_PREEMPT_H
|
|
|
|
#define __LINUX_PREEMPT_H
|
|
|
|
|
|
|
|
/*
|
|
|
|
* include/linux/preempt.h - macros for accessing and manipulating
|
|
|
|
* preempt_count (used for kernel preemption, interrupt count, etc.)
|
|
|
|
*/
|
|
|
|
|
2005-11-13 17:06:57 -07:00
|
|
|
#include <linux/thread_info.h>
|
2005-04-16 16:20:36 -06:00
|
|
|
#include <linux/linkage.h>
|
2007-07-26 05:40:43 -06:00
|
|
|
#include <linux/list.h>
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
#ifdef CONFIG_DEBUG_PREEMPT
|
2008-02-08 05:19:55 -07:00
|
|
|
extern void add_preempt_count(int val);
|
|
|
|
extern void sub_preempt_count(int val);
|
2005-04-16 16:20:36 -06:00
|
|
|
#else
|
|
|
|
# define add_preempt_count(val) do { preempt_count() += (val); } while (0)
|
|
|
|
# define sub_preempt_count(val) do { preempt_count() -= (val); } while (0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define inc_preempt_count() add_preempt_count(1)
|
|
|
|
#define dec_preempt_count() sub_preempt_count(1)
|
|
|
|
|
|
|
|
#define preempt_count() (current_thread_info()->preempt_count)
|
|
|
|
|
|
|
|
#ifdef CONFIG_PREEMPT
|
|
|
|
|
|
|
|
asmlinkage void preempt_schedule(void);
|
|
|
|
|
|
|
|
#define preempt_disable() \
|
|
|
|
do { \
|
|
|
|
inc_preempt_count(); \
|
|
|
|
barrier(); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define preempt_enable_no_resched() \
|
|
|
|
do { \
|
|
|
|
barrier(); \
|
|
|
|
dec_preempt_count(); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define preempt_check_resched() \
|
|
|
|
do { \
|
|
|
|
if (unlikely(test_thread_flag(TIF_NEED_RESCHED))) \
|
|
|
|
preempt_schedule(); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define preempt_enable() \
|
|
|
|
do { \
|
|
|
|
preempt_enable_no_resched(); \
|
[PATCH] fix race with preempt_enable()
Currently a simple
void foo(void) { preempt_enable(); }
produces the following code on ARM:
foo:
bic r3, sp, #8128
bic r3, r3, #63
ldr r2, [r3, #4]
ldr r1, [r3, #0]
sub r2, r2, #1
tst r1, #4
str r2, [r3, #4]
blne preempt_schedule
mov pc, lr
The problem is that the TIF_NEED_RESCHED flag is loaded _before_ the
preemption count is stored back, hence any interrupt coming within that
3 instruction window causing TIF_NEED_RESCHED to be set won't be
seen and scheduling won't happen as it should.
Nothing currently prevents gcc from performing that reordering. There
is already a barrier() before the decrement of the preemption count, but
another one is needed between this and the TIF_NEED_RESCHED flag test
for proper code ordering.
Signed-off-by: Nicolas Pitre <nico@cam.org>
Acked-by: Nick Piggin <nickpiggin@yahoo.com.au>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-12-21 10:26:25 -07:00
|
|
|
barrier(); \
|
2005-04-16 16:20:36 -06:00
|
|
|
preempt_check_resched(); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
#define preempt_disable() do { } while (0)
|
|
|
|
#define preempt_enable_no_resched() do { } while (0)
|
|
|
|
#define preempt_enable() do { } while (0)
|
|
|
|
#define preempt_check_resched() do { } while (0)
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2007-07-26 05:40:43 -06:00
|
|
|
#ifdef CONFIG_PREEMPT_NOTIFIERS
|
|
|
|
|
|
|
|
struct preempt_notifier;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* preempt_ops - notifiers called when a task is preempted and rescheduled
|
|
|
|
* @sched_in: we're about to be rescheduled:
|
|
|
|
* notifier: struct preempt_notifier for the task being scheduled
|
|
|
|
* cpu: cpu we're scheduled on
|
|
|
|
* @sched_out: we've just been preempted
|
|
|
|
* notifier: struct preempt_notifier for the task being preempted
|
|
|
|
* next: the task that's kicking us out
|
|
|
|
*/
|
|
|
|
struct preempt_ops {
|
|
|
|
void (*sched_in)(struct preempt_notifier *notifier, int cpu);
|
|
|
|
void (*sched_out)(struct preempt_notifier *notifier,
|
|
|
|
struct task_struct *next);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* preempt_notifier - key for installing preemption notifiers
|
|
|
|
* @link: internal use
|
|
|
|
* @ops: defines the notifier functions to be called
|
|
|
|
*
|
|
|
|
* Usually used in conjunction with container_of().
|
|
|
|
*/
|
|
|
|
struct preempt_notifier {
|
|
|
|
struct hlist_node link;
|
|
|
|
struct preempt_ops *ops;
|
|
|
|
};
|
|
|
|
|
|
|
|
void preempt_notifier_register(struct preempt_notifier *notifier);
|
|
|
|
void preempt_notifier_unregister(struct preempt_notifier *notifier);
|
|
|
|
|
|
|
|
static inline void preempt_notifier_init(struct preempt_notifier *notifier,
|
|
|
|
struct preempt_ops *ops)
|
|
|
|
{
|
|
|
|
INIT_HLIST_NODE(¬ifier->link);
|
|
|
|
notifier->ops = ops;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
#endif /* __LINUX_PREEMPT_H */
|