[patch] sched: add cond_resched_softirq()

Ingo Molnar
2004-09-14T09:49:59Z

[-- Attachment #1: Type: text/plain, Size: 290 bytes --]

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

[-- Attachment #2: sched-add-cond_resched_softirq.patch --]
[-- Type: text/plain, Size: 1431 bytes --]

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@elte.hu>

--- 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.
*