[patch] sched: add cond_resched_softirq()

From: Ingo Molnar
Date: Tue Sep 14 2004 - 04:52:45 EST



the attached patch comes after preempt-lock-need-resched.patch.

it adds cond_resched_softirq() which can be used by _process context_
softirqs-disabled codepaths to preempt if necessary. The function will
enable softirqs before scheduling. (Later patches will use this
primitive.)

Ingo

the attached patch comes after preempt-lock-need-resched.patch.

it adds cond_resched_softirq() which can be used by _process context_
softirqs-disabled codepaths to preempt if necessary. The function will
enable softirqs before scheduling. (Later patches will use this
primitive.)

Signed-off-by: Ingo Molnar <mingo@xxxxxxx>

--- linux/include/linux/sched.h.orig
+++ linux/include/linux/sched.h
@@ -955,9 +955,12 @@ static inline int need_resched(void)
* cond_resched() and cond_resched_lock(): latency reduction via
* explicit rescheduling in places that are safe. The return
* value indicates whether a reschedule was done in fact.
+ * cond_resched_lock() will drop the spinlock before scheduling,
+ * cond_resched_softirq() will enable bhs before scheduling.
*/
extern int cond_resched(void);
extern int cond_resched_lock(spinlock_t * lock);
+extern int cond_resched_softirq(void);

/*
* Does a critical section need to be broken due to another
--- linux/kernel/sched.c.orig
+++ linux/kernel/sched.c
@@ -3589,6 +3589,22 @@ int cond_resched_lock(spinlock_t * lock)

EXPORT_SYMBOL(cond_resched_lock);

+int __sched cond_resched_softirq(void)
+{
+ BUG_ON(!in_softirq());
+
+ if (need_resched()) {
+ __local_bh_enable();
+ __cond_resched();
+ local_bh_disable();
+ return 1;
+ }
+ return 0;
+}
+
+EXPORT_SYMBOL(cond_resched_softirq);
+
+
/**
* yield - yield the current processor to other threads.
*