Re: [PATCH -v4 2/8] locking/mutex: Rework mutex::owner

From: Davidlohr Bueso
Date: Wed Oct 12 2016 - 14:34:37 EST


On Fri, 07 Oct 2016, Peter Zijlstra wrote:
+/*
+ * Optimistic trylock that only works in the uncontended case. Make sure to
+ * follow with a __mutex_trylock() before failing.
+ */
+static __always_inline bool __mutex_trylock_fast(struct mutex *lock)
+{
+ unsigned long curr = (unsigned long)current;
+
+ if (!atomic_long_cmpxchg_acquire(&lock->owner, 0UL, curr))
+ return true;

Do we want to do a ccas check for !lock->owner? Although I can see a possible
case of 'optimizing for the contended' reasons for nay.

Thanks,
Davidlohr