Skip to content

Commit

Permalink
Add new 'cond_resched_bkl()' helper function
Browse files Browse the repository at this point in the history
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
02b67cc "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>
  • Loading branch information
Linus Torvalds committed May 11, 2008
1 parent 9662369 commit c3921ab
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion fs/locks.c
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@ static int flock_lock_file(struct file *filp, struct file_lock *request)
* give it the opportunity to lock the file.
*/
if (found)
cond_resched();
cond_resched_bkl();

find_conflict:
for_each_lock(inode, before) {
Expand Down
6 changes: 5 additions & 1 deletion include/linux/sched.h
Original file line number Diff line number Diff line change
Expand Up @@ -2037,20 +2037,24 @@ static inline int need_resched(void)
* cond_resched_lock() will drop the spinlock before scheduling,
* cond_resched_softirq() will enable bhs before scheduling.
*/
extern int _cond_resched(void);
#ifdef CONFIG_PREEMPT
static inline int cond_resched(void)
{
return 0;
}
#else
extern int _cond_resched(void);
static inline int cond_resched(void)
{
return _cond_resched();
}
#endif
extern int cond_resched_lock(spinlock_t * lock);
extern int cond_resched_softirq(void);
static inline int cond_resched_bkl(void)
{
return _cond_resched();
}

/*
* Does a critical section need to be broken due to another
Expand Down
2 changes: 0 additions & 2 deletions kernel/sched.c
Original file line number Diff line number Diff line change
Expand Up @@ -5525,7 +5525,6 @@ static void __cond_resched(void)
} while (need_resched());
}

#if !defined(CONFIG_PREEMPT) || defined(CONFIG_PREEMPT_VOLUNTARY)
int __sched _cond_resched(void)
{
if (need_resched() && !(preempt_count() & PREEMPT_ACTIVE) &&
Expand All @@ -5536,7 +5535,6 @@ int __sched _cond_resched(void)
return 0;
}
EXPORT_SYMBOL(_cond_resched);
#endif

/*
* cond_resched_lock() - if a reschedule is pending, drop the given lock,
Expand Down

0 comments on commit c3921ab

Please sign in to comment.