All of lore.kernel.org
 help / color / mirror / Atom feed
From: Waiman Long <waiman.long@hpe.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Jason Low <jason.low2@hpe.com>,
	Davidlohr Bueso <dave@stgolabs.net>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	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>,
	Tim Chen <tim.c.chen@linux.intel.com>,
	"Paul E. McKenney" <paulmck@us.ibm.com>, <jason.low2@hp.com>
Subject: Re: [RFC][PATCH 0/3] locking/mutex: Rewrite basic mutex
Date: Tue, 23 Aug 2016 15:36:17 -0400	[thread overview]
Message-ID: <57BCA5B1.1010401@hpe.com> (raw)
In-Reply-To: <20160823165739.GQ10153@twins.programming.kicks-ass.net>

On 08/23/2016 12:57 PM, Peter Zijlstra wrote:
> On Tue, Aug 23, 2016 at 09:35:03AM -0700, Jason Low wrote:
>> On Tue, 2016-08-23 at 09:17 -0700, Davidlohr Bueso wrote:
>>> What's the motivation here? Is it just to unify counter and owner for
>>> the starvation issue? If so, is this really the path we wanna take for
>>> a small debug corner case?
>> And we thought our other patch was a bit invasive  :-)
> So I've wanted to do something like this for a while now, and Linus
> saying he wanted to always enable the spinning and basically reduce
> special cases made me bite the bullet and just do it to see what it
> would look like.
>
> So it not only unifies counter and owner for the starvation case, it
> does so to allow spinning and debug as well as lock handoff.
> It collapses the whole count+owner+yield_to_owner into a single
> variable.
>
> It obviously is a tad invasive, but it does make things more similar to
> rt-mutex and pi futex, both of which track the owner and pending in the
> primary 'word'.
>
> That said, I don't particularly like the new mutex_unlock() code, its
> rather more heavy than I would like, although typically the word is
> uncontended at unlock and we'd only need a single go at the
> cmpxchg-loop.
>
>

I think this is the right way to go. There isn't any big change in the 
slowpath, so the contended performance should be the same. The fastpath, 
however, will get a bit slower as a single atomic op plus a jump 
instruction (a single cacheline load) is replaced by a read-and-test and 
compxchg (potentially 2 cacheline loads) which will be somewhat slower 
than the optimized assembly code. Alternatively, you can replace the 
__mutex_trylock() in mutex_lock() by just a blind cmpxchg to optimize 
the fastpath further. A cmpxhcg will still be a tiny bit slower than 
other atomic ops, but it will be more acceptable, I think.


BTW, I got the following compilation warning when I tried your patch:

drivers/gpu/drm/i915/i915_gem_shrinker.c: In function ‘mutex_is_locked_by’:
drivers/gpu/drm/i915/i915_gem_shrinker.c:44:22: error: invalid operands 
to binary == (have ‘atomic_long_t’ and ‘struct task_struct *’)
return mutex->owner == task;
^
CC [M] drivers/gpu/drm/i915/intel_psr.o
drivers/gpu/drm/i915/i915_gem_shrinker.c:49:1: warning: control reaches 
end of non-void function [-Wreturn-type]
}
^
make[4]: *** [drivers/gpu/drm/i915/i915_gem_shrinker.o] Error 1

Apparently, you may need to look to see if there are other direct access 
of the owner field in the other code.

Cheers,
Longman

  reply	other threads:[~2016-08-23 19:36 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-23 12:46 [RFC][PATCH 0/3] locking/mutex: Rewrite basic mutex Peter Zijlstra
2016-08-23 12:46 ` [RFC][PATCH 1/3] locking/mutex: Rework mutex::owner Peter Zijlstra
2016-08-23 19:55   ` Waiman Long
2016-08-23 20:52     ` Tim Chen
2016-08-23 21:03       ` Peter Zijlstra
2016-08-23 21:09     ` Peter Zijlstra
2016-08-23 20:17   ` Waiman Long
2016-08-23 20:31     ` Peter Zijlstra
2016-08-24  9:56   ` Will Deacon
2016-08-24 15:34     ` Peter Zijlstra
2016-08-24 16:52       ` Peter Zijlstra
2016-08-24 16:54         ` Will Deacon
2016-08-23 12:46 ` [RFC][PATCH 2/3] locking/mutex: Allow MUTEX_SPIN_ON_OWNER when DEBUG_MUTEXES Peter Zijlstra
2016-08-23 12:46 ` [RFC][PATCH 3/3] locking/mutex: Add lock handoff to avoid starvation Peter Zijlstra
2016-08-23 12:56   ` Peter Zijlstra
     [not found]   ` <57BCA869.1050501@hpe.com>
2016-08-23 20:32     ` Peter Zijlstra
2016-08-24 19:50       ` Waiman Long
2016-08-25  8:11         ` Peter Zijlstra
2016-08-23 16:17 ` [RFC][PATCH 0/3] locking/mutex: Rewrite basic mutex Davidlohr Bueso
2016-08-23 16:35   ` Jason Low
2016-08-23 16:57     ` Peter Zijlstra
2016-08-23 19:36       ` Waiman Long [this message]
2016-08-23 20:41         ` Peter Zijlstra
2016-08-23 22:34           ` Waiman Long
2016-08-24  1:13     ` Jason Low
2016-08-25 12:32       ` Peter Zijlstra
2016-08-25 15:43       ` Peter Zijlstra
2016-08-25 16:33         ` Waiman Long
2016-08-25 16:35           ` Peter Zijlstra
2016-08-27 18:27             ` Ingo Molnar
2016-08-25 19:11         ` huang ying
2016-08-25 19:26           ` Peter Zijlstra
2016-08-23 18:53   ` Linus Torvalds
2016-08-23 20:34     ` 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=57BCA5B1.1010401@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=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.