locking/mutexes: Optimize mutex trylock slowpath
locking/mutexes: Optimize mutex trylock slowpath

The mutex_trylock() function calls into __mutex_trylock_fastpath() when
trying to obtain the mutex. On 32 bit x86, in the !__HAVE_ARCH_CMPXCHG
case, __mutex_trylock_fastpath() calls directly into __mutex_trylock_slowpath()
regardless of whether or not the mutex is locked.

In __mutex_trylock_slowpath(), we then acquire the wait_lock spinlock, xchg()
lock->count with -1, then set lock->count back to 0 if there are no waiters,
and return true if the prev lock count was 1.

However, if the mutex is already locked, then there isn't much point
in attempting all of the above expensive operations. In this patch, we only
attempt the above trylock operations if the mutex is unlocked.

Signed-off-by: Jason Low <09ebf12aa4fd61769490ade56a7655bcf429b765@hp.com>
Reviewed-by: Davidlohr Bueso <4aa5652442886f3c4e77d3a743dc27e129c1613f@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: a123fdd9fb50e93f03393cfddab9c182b4164439@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-5-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