Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add new 'cond_resched_bkl()' helper function

It acts exactly like a regular 'cond_resched()', but will not get
optimized away when CONFIG_PREEMPT is set.

Normal kernel code is already preemptable in the presense of
CONFIG_PREEMPT, so cond_resched() is optimized away (see commit
02b67cc3ba36bdba351d6c3a00593f4ec550d9d3 "sched: do not do
cond_resched() when CONFIG_PREEMPT").

But when wanting to conditionally reschedule while holding a lock, you
need to use "cond_sched_lock(lock)", and the new function is the BKL
equivalent of that.

Also make fs/locks.c use it.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

+6 -4
+1 -1
fs/locks.c
··· 773 773 * give it the opportunity to lock the file. 774 774 */ 775 775 if (found) 776 - cond_resched(); 776 + cond_resched_bkl(); 777 777 778 778 find_conflict: 779 779 for_each_lock(inode, before) {
+5 -1
include/linux/sched.h
··· 2037 2037 * cond_resched_lock() will drop the spinlock before scheduling, 2038 2038 * cond_resched_softirq() will enable bhs before scheduling. 2039 2039 */ 2040 + extern int _cond_resched(void); 2040 2041 #ifdef CONFIG_PREEMPT 2041 2042 static inline int cond_resched(void) 2042 2043 { 2043 2044 return 0; 2044 2045 } 2045 2046 #else 2046 - extern int _cond_resched(void); 2047 2047 static inline int cond_resched(void) 2048 2048 { 2049 2049 return _cond_resched(); ··· 2051 2051 #endif 2052 2052 extern int cond_resched_lock(spinlock_t * lock); 2053 2053 extern int cond_resched_softirq(void); 2054 + static inline int cond_resched_bkl(void) 2055 + { 2056 + return _cond_resched(); 2057 + } 2054 2058 2055 2059 /* 2056 2060 * Does a critical section need to be broken due to another
-2
kernel/sched.c
··· 5525 5525 } while (need_resched()); 5526 5526 } 5527 5527 5528 - #if !defined(CONFIG_PREEMPT) || defined(CONFIG_PREEMPT_VOLUNTARY) 5529 5528 int __sched _cond_resched(void) 5530 5529 { 5531 5530 if (need_resched() && !(preempt_count() & PREEMPT_ACTIVE) && ··· 5535 5536 return 0; 5536 5537 } 5537 5538 EXPORT_SYMBOL(_cond_resched); 5538 - #endif 5539 5539 5540 5540 /* 5541 5541 * cond_resched_lock() - if a reschedule is pending, drop the given lock,