Skip to contentSkip to conversation

sched: Fix cond_resched_lock() in !CONFIG_PREEMPT

PATCH In review Frederic Weisbecker 1 participant 2 messages Jul 24, 2009 – Aug 2, 2009 Scheduler

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sched: Fix cond_resched_lock() in !CONFIG_PREEMPT

The might_sleep() test inside cond_resched_lock() assumes the spinlock is held and then preemption is disabled. This is true with CONFIG_PREEMPT but the preempt_count() doesn't change otherwise.

Check by starting from the appropriate preempt offset depending on the config.

---
 include/linux/sched.h |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)
include/linux/sched.h +7 -1
index cb070dc..2c35bc2 100644
@@ -2294,8 +2294,14 @@ extern int _cond_resched(void);
 
 extern int __cond_resched_lock(spinlock_t *lock);
 
+#ifdef CONFIG_PREEMPT
+#define PREEMPT_LOCK_OFFSET	PREEMPT_OFFSET
+#else
+#define PREEMPT_LOCK_OFFSET	0
+#endif
+
 #define cond_resched_lock(lock) ({				\
-	__might_sleep(__FILE__, __LINE__, PREEMPT_OFFSET);	\
+	__might_sleep(__FILE__, __LINE__, PREEMPT_LOCK_OFFSET);	\
 	__cond_resched_lock(lock);				\
 })
 
Signature · 1 line
1.6.2.3
#1 lore raw
Commit-ID:  716a42348cdaf04534b15fbdc9c83e25baebfed5
Gitweb:     http://git.kernel.org/tip/716a42348cdaf04534b15fbdc9c83e25baebfed5
Author:     Frederic Weisbecker <[email protected]>
AuthorDate: Fri, 24 Jul 2009 20:05:23 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Sun, 2 Aug 2009 14:03:57 +0200

sched: Fix cond_resched_lock() in !CONFIG_PREEMPT

The might_sleep() test inside cond_resched_lock() assumes the spinlock is held and then preemption is disabled. This is true with CONFIG_PREEMPT but the preempt_count() doesn't change otherwise.

Check by starting from the appropriate preempt offset depending on the config.

LKML-Reference: <[email protected]>

---
 include/linux/sched.h |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)
include/linux/sched.h +7 -1
index cbbfca6..c472414 100644
@@ -2293,8 +2293,14 @@ extern int _cond_resched(void);
 
 extern int __cond_resched_lock(spinlock_t *lock);
 
+#ifdef CONFIG_PREEMPT
+#define PREEMPT_LOCK_OFFSET	PREEMPT_OFFSET
+#else
+#define PREEMPT_LOCK_OFFSET	0
+#endif
+
 #define cond_resched_lock(lock) ({				\
-	__might_sleep(__FILE__, __LINE__, PREEMPT_OFFSET);	\
+	__might_sleep(__FILE__, __LINE__, PREEMPT_LOCK_OFFSET);	\
 	__cond_resched_lock(lock);				\
 })