All of lore.kernel.org
 help / color / mirror / Atom feed
From: Waiman Long <waiman.long@hpe.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
	Jason Low <jason.low2@hpe.com>,
	Ding Tianhong <dingtianhong@huawei.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Will Deacon <Will.Deacon@arm.com>, Ingo Molnar <mingo@redhat.com>,
	Imre Deak <imre.deak@intel.com>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Davidlohr Bueso <dave@stgolabs.net>,
	Tim Chen <tim.c.chen@linux.intel.com>,
	Terry Rudd <terry.rudd@hpe.com>,
	"Paul E. McKenney" <paulmck@us.ibm.com>,
	Jason Low <jason.low2@hp.com>
Subject: Re: [RFC][PATCH -v3 10/10] locking/mutex: Implement alternative HANDOFF
Date: Fri, 9 Sep 2016 18:32:04 -0400	[thread overview]
Message-ID: <57D33864.4060201@hpe.com> (raw)
In-Reply-To: <20160905124027.796192899@infradead.org>

On 09/05/2016 08:36 AM, Peter Zijlstra wrote:
> As mentioned in a previous patch, its possible to implement the
> handoff logic differently, avoiding the issue where we 'leak' a HADOFF
> flag.
>
> This patch does so, just to show what it looks like; I'm not at all
> convinced this is worth it.
>
> Signed-off-by: Peter Zijlstra (Intel)<peterz@infradead.org>
>

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))
@@ -107,7 +113,7 @@ static inline bool __mutex_trylock(struct mutex 
*lock, const
                 }

                 old = atomic_long_cmpxchg_acquire(&lock->owner, owner,
-                                                 curr | 
__owner_flags(owner));
+                                                 curr | flags);
                 if (old == owner)
                         return true;

@@ -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);
@@ -700,8 +706,6 @@ remove_waiter:
         mutex_remove_waiter(lock, &waiter, task);
         if (likely(list_empty(&lock->wait_list)))
                 __mutex_clear_flag(lock, MUTEX_FLAGS);
-       else if (first && (atomic_long_read(&lock->owner) & 
MUTEX_FLAG_HANDOFF))
-               __mutex_clear_flag(lock, MUTEX_FLAG_HANDOFF);

         debug_mutex_free_waiter(&waiter);


Cheers,
Longman

  reply	other threads:[~2016-09-09 22:32 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-05 12:36 [PATCH -v3 00/10] locking/mutex: Rewrite basic mutex Peter Zijlstra
2016-09-05 12:36 ` [PATCH -v3 01/10] locking/drm: Kill mutex trickery Peter Zijlstra
2016-09-05 12:36 ` [PATCH -v3 02/10] sh/atomic: Fix ATOMIC_FETCH_OP() Peter Zijlstra
2016-09-05 12:36 ` [PATCH -v3 03/10] locking/mutex: Rework mutex::owner Peter Zijlstra
2016-09-05 12:36 ` [PATCH -v3 04/10] locking/mutex: Kill arch specific code Peter Zijlstra
2016-09-05 12:36 ` [PATCH -v3 05/10] locking/mutex: Allow MUTEX_SPIN_ON_OWNER when DEBUG_MUTEXES Peter Zijlstra
2016-09-05 12:36 ` [PATCH -v3 06/10] locking/mutex: Add lock handoff to avoid starvation Peter Zijlstra
2016-09-05 12:36 ` [PATCH -v3 07/10] mutex: Restructure wait loop Peter Zijlstra
     [not found]   ` <57D31A3B.7000105@hpe.com>
     [not found]     ` <57D31C67.8010809@hpe.com>
2016-09-14 10:33       ` Peter Zijlstra
2016-09-05 12:36 ` [PATCH -v3 08/10] locking/mutex: Simplify some ww_mutex code in __mutex_lock_common() Peter Zijlstra
2016-09-05 12:36 ` [PATCH -v3 09/10] locking/mutex: Enable optimistic spinning of woken waiter Peter Zijlstra
2016-09-05 12:36 ` [RFC][PATCH -v3 10/10] locking/mutex: Implement alternative HANDOFF Peter Zijlstra
2016-09-09 22:32   ` Waiman Long [this message]
2016-09-12 15:20     ` Peter Zijlstra

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=57D33864.4060201@hpe.com \
    --to=waiman.long@hpe.com \
    --cc=Will.Deacon@arm.com \
    --cc=dave@stgolabs.net \
    --cc=dingtianhong@huawei.com \
    --cc=imre.deak@intel.com \
    --cc=jason.low2@hp.com \
    --cc=jason.low2@hpe.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=paulmck@us.ibm.com \
    --cc=peterz@infradead.org \
    --cc=terry.rudd@hpe.com \
    --cc=tglx@linutronix.de \
    --cc=tim.c.chen@linux.intel.com \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.