Skip to content

Commit 7e406d1

Browse files
author
Peter Zijlstra
committed
sched: Avoid double preemption in __cond_resched_*lock*()
For PREEMPT/DYNAMIC_PREEMPT the *_unlock() will already trigger a preemption, no point in then calling preempt_schedule_common() *again*. Use _cond_resched() instead, since this is a NOP for the preemptible configs while it provide a preemption point for the others. Reported-by: xuhaifeng <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent a315da5 commit 7e406d1

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

kernel/sched/core.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8218,9 +8218,7 @@ int __cond_resched_lock(spinlock_t *lock)
82188218

82198219
if (spin_needbreak(lock) || resched) {
82208220
spin_unlock(lock);
8221-
if (resched)
8222-
preempt_schedule_common();
8223-
else
8221+
if (!_cond_resched())
82248222
cpu_relax();
82258223
ret = 1;
82268224
spin_lock(lock);
@@ -8238,9 +8236,7 @@ int __cond_resched_rwlock_read(rwlock_t *lock)
82388236

82398237
if (rwlock_needbreak(lock) || resched) {
82408238
read_unlock(lock);
8241-
if (resched)
8242-
preempt_schedule_common();
8243-
else
8239+
if (!_cond_resched())
82448240
cpu_relax();
82458241
ret = 1;
82468242
read_lock(lock);
@@ -8258,9 +8254,7 @@ int __cond_resched_rwlock_write(rwlock_t *lock)
82588254

82598255
if (rwlock_needbreak(lock) || resched) {
82608256
write_unlock(lock);
8261-
if (resched)
8262-
preempt_schedule_common();
8263-
else
8257+
if (!_cond_resched())
82648258
cpu_relax();
82658259
ret = 1;
82668260
write_lock(lock);

0 commit comments

Comments
 (0)