All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Nicolai Hähnle" <nhaehnle@gmail.com>
To: "Peter Zijlstra" <peterz@infradead.org>,
	"Nicolai Hähnle" <nhaehnle@gmail.com>
Cc: linux-kernel@vger.kernel.org, Ingo Molnar <mingo@redhat.com>,
	Maarten Lankhorst <dev@mblankhorst.nl>,
	Daniel Vetter <daniel@ffwll.ch>,
	Chris Wilson <chris@chris-wilson.co.uk>,
	dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v2 05/11] locking/ww_mutex: Add waiters in stamp order
Date: Fri, 16 Dec 2016 23:35:12 +0100	[thread overview]
Message-ID: <e4b21023-d916-ef8c-eec0-00726d412e10@gmail.com> (raw)
In-Reply-To: <20161216200023.GH3124@twins.programming.kicks-ass.net>

On 16.12.2016 21:00, Peter Zijlstra wrote:
> On Fri, Dec 16, 2016 at 07:11:41PM +0100, Nicolai Hähnle wrote:
>> mutex_optimistic_spin() already calls __mutex_trylock, and for the no-spin
>> case, __mutex_unlock_slowpath() only calls wake_up_q() after releasing the
>> wait_lock.
>
> mutex_optimistic_spin() is a no-op when !CONFIG_MUTEX_SPIN_ON_OWNER

Does this change the conclusion in a meaningful way? I did mention the 
no-spin case in the very part you quoted...

Again, AFAIU we're talking about the part of my proposal that turns what 
is effectively

	__mutex_trylock(lock, ...);
	spin_lock_mutex(&lock->wait_lock, flags);

(independent of whether the trylock succeeds or not!) into

	spin_lock_mutex(&lock->wait_lock, flags);
	__mutex_trylock(lock, ...);

in an effort to streamline the code overall.

Also AFAIU, you're concerned that spin_lock_mutex(...) has to wait for 
an unlock from mutex_unlock(), but when does that actually happen with 
relevant probability?

When we spin optimistically, that could happen -- except that 
__mutex_trylock is already called in mutex_optimistic_spin, so it 
doesn't matter. When we don't spin -- whether due to .config or !first 
-- then the chance of overlap with mutex_unlock is exceedingly small.

Even if we do overlap, we'll have to wait for mutex_unlock to release 
the wait_lock anyway! So what good does acquiring the lock first really do?

Anyway, this is really more of an argument about whether there's really 
a good reason to calling __mutex_trylock twice in that loop. I don't 
think there is, your arguments certainly haven't been convincing, but 
the issue can be side-stepped for this patch by keeping the trylock 
calls as they are and just setting first = true unconditionally for 
ww_ctx != NULL (but keep the logic for when to set the HANDOFF flag 
as-is). Should probably rename the variable s/first/handoff/ then.

Nicolai

  reply	other threads:[~2016-12-16 22:35 UTC|newest]

Thread overview: 70+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-01 14:06 [PATCH v2 00/11] locking/ww_mutex: Keep sorted wait list to avoid stampedes Nicolai Hähnle
2016-12-01 14:06 ` [PATCH v2 01/11] drm/vgem: Use ww_mutex_(un)lock even with a NULL context Nicolai Hähnle
2016-12-01 14:06   ` Nicolai Hähnle
2016-12-01 14:18   ` Chris Wilson
2016-12-01 14:18     ` Chris Wilson
2016-12-01 15:14     ` Daniel Vetter
2016-12-01 16:24   ` Peter Zijlstra
2016-12-01 16:24     ` Peter Zijlstra
2016-12-01 14:06 ` [PATCH v2 02/11] locking/ww_mutex: Re-check ww->ctx in the inner optimistic spin loop Nicolai Hähnle
2016-12-01 14:06   ` Nicolai Hähnle
2016-12-01 14:36   ` Chris Wilson
2016-12-01 14:36     ` Chris Wilson
2016-12-06 15:06   ` Peter Zijlstra
2016-12-06 15:06     ` Peter Zijlstra
2016-12-06 16:03     ` Waiman Long
2016-12-06 18:29       ` Peter Zijlstra
2016-12-06 18:29         ` Peter Zijlstra
2016-12-06 18:46         ` Waiman Long
2016-12-01 14:06 ` [PATCH v2 03/11] locking/ww_mutex: Extract stamp comparison to __ww_mutex_stamp_after Nicolai Hähnle
2016-12-01 14:06   ` Nicolai Hähnle
2016-12-01 14:42   ` Chris Wilson
2016-12-01 14:42     ` Chris Wilson
2016-12-01 14:06 ` [PATCH v2 04/11] locking/ww_mutex: Set use_ww_ctx even when locking without a context Nicolai Hähnle
2016-12-01 14:06   ` Nicolai Hähnle
2016-12-06 15:14   ` Peter Zijlstra
2016-12-06 15:14     ` Peter Zijlstra
2016-12-06 15:25   ` Peter Zijlstra
2016-12-06 15:25     ` Peter Zijlstra
2016-12-16 13:17     ` Nicolai Hähnle
2016-12-16 13:17       ` Nicolai Hähnle
2016-12-17  7:53       ` Maarten Lankhorst
2016-12-17  7:53         ` Maarten Lankhorst
2016-12-17 13:49       ` Peter Zijlstra
2016-12-17 13:49         ` Peter Zijlstra
2016-12-01 14:06 ` [PATCH v2 05/11] locking/ww_mutex: Add waiters in stamp order Nicolai Hähnle
2016-12-01 15:59   ` Chris Wilson
2016-12-01 15:59     ` Chris Wilson
2016-12-16 14:21     ` Nicolai Hähnle
2016-12-16 14:21       ` Nicolai Hähnle
2016-12-06 15:36   ` Peter Zijlstra
2016-12-06 15:36     ` Peter Zijlstra
2016-12-16 13:34     ` Nicolai Hähnle
2016-12-16 13:34       ` Nicolai Hähnle
2016-12-06 16:55   ` Peter Zijlstra
2016-12-06 16:55     ` Peter Zijlstra
2016-12-16 14:19     ` Nicolai Hähnle
2016-12-16 14:19       ` Nicolai Hähnle
2016-12-16 14:46       ` Peter Zijlstra
2016-12-16 14:46         ` Peter Zijlstra
2016-12-16 17:15       ` Peter Zijlstra
2016-12-16 17:15         ` Peter Zijlstra
2016-12-16 18:11         ` Nicolai Hähnle
2016-12-16 20:00           ` Peter Zijlstra
2016-12-16 20:00             ` Peter Zijlstra
2016-12-16 22:35             ` Nicolai Hähnle [this message]
2016-12-16 17:20       ` Peter Zijlstra
2016-12-16 17:20         ` Peter Zijlstra
2016-12-16 18:12         ` Nicolai Hähnle
2016-12-16 18:12           ` Nicolai Hähnle
2016-12-01 14:06 ` [PATCH v2 06/11] locking/ww_mutex: Notify waiters that have to back off while adding tasks to wait list Nicolai Hähnle
2016-12-01 14:06   ` Nicolai Hähnle
2016-12-01 14:06 ` [PATCH v2 07/11] locking/ww_mutex: Wake at most one waiter for back off when acquiring the lock Nicolai Hähnle
2016-12-01 14:06   ` Nicolai Hähnle
2016-12-01 14:06 ` [PATCH v2 08/11] locking/ww_mutex: Yield to other waiters from optimistic spin Nicolai Hähnle
2016-12-01 14:06 ` [PATCH v2 09/11] locking/mutex: Initialize mutex_waiter::ww_ctx with poison when debugging Nicolai Hähnle
2016-12-01 14:06   ` Nicolai Hähnle
2016-12-01 14:06 ` [PATCH v2 10/11] Documentation/locking/ww_mutex: Update the design document Nicolai Hähnle
2016-12-01 14:06   ` Nicolai Hähnle
2016-12-01 14:06 ` [PATCH v2 11/11] [rfc] locking/ww_mutex: Always spin optimistically for the first waiter Nicolai Hähnle
2016-12-01 14:06   ` Nicolai Hähnle

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=e4b21023-d916-ef8c-eec0-00726d412e10@gmail.com \
    --to=nhaehnle@gmail.com \
    --cc=chris@chris-wilson.co.uk \
    --cc=daniel@ffwll.ch \
    --cc=dev@mblankhorst.nl \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.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.