Re: [RFC][PATCH -v3 10/10] locking/mutex: Implement alternative HANDOFF
From: Peter Zijlstra
Date: Mon Sep 12 2016 - 11:21:07 EST
On Fri, Sep 09, 2016 at 06:32:04PM -0400, Waiman Long wrote:
> I have another way of catching the uncleared handoff flag. See the following
> code to see if you think that will work.
>
> diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c
> index 9492494..362ff83 100644
> --- a/kernel/locking/mutex.c
> +++ b/kernel/locking/mutex.c
> @@ -85,7 +85,13 @@ static inline bool __mutex_trylock(struct mutex *lock,
> const
>
> owner = atomic_long_read(&lock->owner);
> for (;;) { /* must loop, can race against a flag */
> - unsigned long old;
> + unsigned long old, flags = __owner_flags(owner);
> +
> + /*
> + * We don't need to keep the HANDOFF flag for the waiter.
> + */
> + if (handoff)
> + flags &= ~MUTEX_FLAG_HANDOFF;
>
> if (__owner_task(owner)) {
> if (handoff && unlikely(__owner_task(owner) == current))
I placed this condition below the __owner_task() branch.
> @@ -688,7 +694,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned
> * state back to RUNNING and fall through the next schedule(),
> * or we must see its unlock and acquire.
> */
> - if (__mutex_trylock(lock, true))
> + if (__mutex_trylock(lock, first))
> break;
>
> spin_lock_mutex(&lock->wait_lock, flags);
Hmm, yes. I think that works.
We (the first waiter) set the flag, we clear it on try-lock, or unlock
clears it when it hands the thing off.
Much simpler. Thanks!