]> Git Repo - J-linux.git/commitdiff
sched: Avoid double preemption in __cond_resched_*lock*()
authorPeter Zijlstra <[email protected]>
Sat, 25 Dec 2021 00:04:57 +0000 (01:04 +0100)
committerPeter Zijlstra <[email protected]>
Tue, 18 Jan 2022 11:09:59 +0000 (12:09 +0100)
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]
kernel/sched/core.c

index 0d2ab2a2f9feb8213b5613144a63463fd79fcb07..56b428c8ea964df3707a755c72bf3e4b69a59573 100644 (file)
@@ -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);
@@ -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);
@@ -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);
This page took 0.062761 seconds and 4 git commands to generate.