locking/mutexes: Add extra reschedule point
authorPeter Zijlstra <peterz@infradead.org>
Mon, 3 Feb 2014 15:21:09 +0000 (16:21 +0100)
committerIngo Molnar <mingo@kernel.org>
Tue, 11 Mar 2014 11:14:59 +0000 (12:14 +0100)
Add in an extra reschedule in an attempt to avoid getting reschedule
the moment we've acquired the lock.

Signed-off-by: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/n/tip-zah5eyn9gu7qlgwh9r6n2anc@git.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
kernel/locking/mutex.c

index 2670b84067d60c3c60f24dab61894c187bc19ca0..02c61a9c89066fc8560eff0dcb4da3ff246e23a8 100644 (file)
@@ -468,6 +468,13 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
        }
        osq_unlock(&lock->osq);
 slowpath:
+       /*
+        * If we fell out of the spin path because of need_resched(),
+        * reschedule now, before we try-lock the mutex. This avoids getting
+        * scheduled out right after we obtained the mutex.
+        */
+       if (need_resched())
+               schedule_preempt_disabled();
 #endif
        spin_lock_mutex(&lock->wait_lock, flags);