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 majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Reply via email to