Re: [RFC PATCH 3/3] locking/mutex: Optimize mutex trylock slowpath

Davidlohr Bueso
2014-06-04T20:28:40Z

On Wed, 2014-06-04 at 12:08 -0700, Jason Low wrote:
> In __mutex_trylock_slowpath(), we 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 we the mutex is already locked, then there may not be
^^ leave that out.

> much point in attempting the above operations.

Isn't this redundant? I mean, if we enter the slowpath its because
__mutex_fastpath_trylock() already failed so we already know that the
lock is taken.

What kind of testing has this change been put through? Any advantages?
(ie: how many cycles are we saving here?), the trylock mechanism is
already pretty darn fast.

Thanks,
Davidlohr