On Tue, Sep 22, 2015 at 04:50:43PM -0400, Waiman Long wrote:
+gotlock:This i need to think about a wee bit; its almost the same...
/*
+ * We now have the lock. We need to either clear the tail code or
+ * notify the next one in queue as the new queue head.
*/
+ old = atomic_read(&lock->val);
+ while ((old& _Q_TAIL_MASK) == tail) {
+ int val;
+ int new = old& ~_Q_TAIL_MASK;
+
+ /*
+ * We are the only one in the queue, so clear the tail code
+ * and return.
+ */
+ val = atomic_cmpxchg(&lock->val, old, new);
+ if (old == val)
+ goto done;
+ old = val;
+ }
+
So the below is exactly duplicated from the normal slowpath, so why
don't you keep that there?
It would get you something like:
if (pv_wait_head_or_steal(..))
goto stolen;
stolen:
+ /*release:
+ * contended path; wait for next, release.
+ */
+ while (!(next = READ_ONCE(node->next)))
+ cpu_relax();
+
+ arch_mcs_spin_unlock_contended(&next->locked);
+ pv_kick_node(lock, next);
...