Re: [RFC][PATCH v2 5/5] mutex: Give spinners a chance tospin_on_owner if need_resched() triggered while queued

From: Jason Low
Date: Mon Feb 03 2014 - 13:39:33 EST


On Sun, 2014-02-02 at 22:12 +0100, Peter Zijlstra wrote:
> The way I wrote that same loop in step-B, is:
>
>
> for (;;) {
> if (*lock == node && cmpxchg(lock, node, prev) == node)
> return
>
> next = xchg(&node->next, NULL); /* B -> A */
> if (next)
> break;
>
> arch_mutex_cpu_relax();
> }
>
> I suppose we can make that something like:
>
>
> if (node->next) {
> next = xchg(&node->next, NULL);
> if (next)
> break
> }
>
> To avoid the xchg on every loop.

Ah yes, we want to use xchg() on &node->next.

Since the cmpxchg() is now in a loop in the unlock function, an
additional (*lock == node) check before the cmpxchg() would also be nice
to avoid spinning on cmpxchg() there too.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/