Skip to content

Commit

Permalink
sched: Avoid double preemption in __cond_resched_*lock*()
Browse files Browse the repository at this point in the history
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 <xuhaifeng@oppo.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/YcGnvDEYBwOiV0cR@hirez.programming.kicks-ass.net
  • Loading branch information
Peter Zijlstra committed Jan 18, 2022
1 parent a315da5 commit 7e406d1
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions kernel/sched/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -8218,9 +8218,7 @@ int __cond_resched_lock(spinlock_t *lock)

if (spin_needbreak(lock) || resched) {
spin_unlock(lock);
if (resched)
preempt_schedule_common();
else
if (!_cond_resched())
cpu_relax();
ret = 1;
spin_lock(lock);
Expand All @@ -8238,9 +8236,7 @@ int __cond_resched_rwlock_read(rwlock_t *lock)

if (rwlock_needbreak(lock) || resched) {
read_unlock(lock);
if (resched)
preempt_schedule_common();
else
if (!_cond_resched())
cpu_relax();
ret = 1;
read_lock(lock);
Expand All @@ -8258,9 +8254,7 @@ int __cond_resched_rwlock_write(rwlock_t *lock)

if (rwlock_needbreak(lock) || resched) {
write_unlock(lock);
if (resched)
preempt_schedule_common();
else
if (!_cond_resched())
cpu_relax();
ret = 1;
write_lock(lock);
Expand Down

0 comments on commit 7e406d1

Please sign in to comment.