locking/mutexes: Try to acquire mutex only if it is unlocked
locking/mutexes: Try to acquire mutex only if it is unlocked

Upon entering the slowpath in __mutex_lock_common(), we try once more to
acquire the mutex. We only try to acquire if (lock->count >= 0). However,
what we actually want here is to try to acquire if the mutex is unlocked
(lock->count == 1).

This patch changes it so that we only try-acquire the mutex upon entering
the slowpath if it is unlocked, rather than if the lock count is non-negative.
This helps further reduce unnecessary atomic xchg() operations.

Furthermore, this patch uses !mutex_is_locked(lock) to do the initial
checks for if the lock is free rather than directly calling atomic_read()
on the lock->count, in order to improve readability.

Signed-off-by: Jason Low <09ebf12aa4fd61769490ade56a7655bcf429b765@hp.com>
Acked-by: Waiman Long <a123fdd9fb50e93f03393cfddab9c182b4164439@hp.com>
Signed-off-by: Peter Zijlstra <3fddac958924aef220f202ca567388ddab3f14a8@infradead.org>
Cc: 5c1e68b099950c134891f0b6e179498a8ebe9cf9@linux-foundation.org
Cc: 695db642e8bc2a781029b5690bc796db9446cc2f@linux.intel.com
Cc: 1e0ce936bb9b355d257bf5790d2513c3f28be22b@linux.vnet.ibm.com
Cc: 43232e92d70cc7aa53504ad0397085ee47bad87f@goodmis.org
Cc: 4aa5652442886f3c4e77d3a743dc27e129c1613f@hp.com
Cc: 49115ac805b6db5f3b6f48b0e88b39699dd1bea1@hp.com
Cc: bfa14955daca93db2acc6116543d4fa46c7a22b5@hp.com
Cc: Linus Torvalds <69652caca27c8b940640ad396ab71f93cacec34f@linux-foundation.org>
Link: http://lkml.kernel.org/r/1402511843-4721-4-git-send-email-09ebf12aa4fd61769490ade56a7655bcf429b765@hp.com
Signed-off-by: Ingo Molnar <9dbbbf0688fedc85ad4da37637f1a64b8c718ee2@kernel.org>

KristFoundation/Programs,KristFoundation/Programs,KristFoundation/Programs,KristFoundation/Programs,KristFoundation/Programs,KristFoundation/Programs