mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 00/11] locking/ww_mutex: Keep sorted wait list to avoid stampedes
@ 2016-11-28 12:20 Nicolai Hähnle
  2016-11-28 12:20 ` [PATCH 01/11] drm/vgem: Use ww_mutex_(un)lock even with a NULL context Nicolai Hähnle
                   ` (12 more replies)
  0 siblings, 13 replies; 28+ messages in thread
From: Nicolai Hähnle @ 2016-11-28 12:20 UTC (permalink / raw)
  To: linux-kernel

It turns out that the deadlock that I found last week was already implicitly
fixed during the lock->owner redesign, by checking the WAITERS bit in the
w/w lock fast path. However, since I had already started looking into
sorting the wait list, here goes.

The basic idea is to make sure that:

1. All waiters that have a ww_ctx appear in stamp order in the wait list.
Waiters without a ww_ctx are still supported and appear in FIFO order as
before.

2. At most one of the waiters can be in a state where it has to check for
back off (i.e., ww_ctx->acquire > 0). Technically, there are short time
windows in which more than one such waiter can be on the list, but all
but the first one are running. This happens when a new waiter with
ww_ctx->acquire > 0 adds itself at the front of the list and wakes up the
previous head of the list, and of course multiple such chained cases can
be in-flight simultaneously.

Then we only ever have to wake up one task at a time. This is _not_ always
the head of the wait list, since there may be waiters without a context. But
among waiters with a context, we only ever have to wake the first one.

To achieve all this, the series adds a new field to mutex_waiter which is
only used for the w/w lock case. As a consequence, calling mutex_lock
directly on w/w locks is now definitely incorrect. That was likely the
intention previously anyway, but grepping through the source I did find one
place that had slipped through.

I've included timings taken from a contention-heavy stress test to some of
the patches. The stress test performs actual GPU operations which take a
good chunk of the wall time, but even so, the series still manages to
improve the wall time quite a bit.

Cheers,
Nicolai

^ permalink raw reply	[flat|nested] 28+ messages in thread

end of thread, other threads:[~2016-11-30 19:09 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-11-28 12:20 [PATCH 00/11] locking/ww_mutex: Keep sorted wait list to avoid stampedes Nicolai Hähnle
2016-11-28 12:20 ` [PATCH 01/11] drm/vgem: Use ww_mutex_(un)lock even with a NULL context Nicolai Hähnle
2016-11-28 12:42   ` Maarten Lankhorst
2016-11-28 12:50     ` Peter Zijlstra
2016-11-28 12:58   ` Christian König
2016-11-28 12:20 ` [PATCH 02/11] locking/ww_mutex: Re-check ww->ctx in the inner optimistic spin loop Nicolai Hähnle
2016-11-28 12:20 ` [PATCH 03/11] locking/ww_mutex: Extract stamp comparison to __ww_mutex_stamp_after Nicolai Hähnle
2016-11-28 12:20 ` [PATCH 04/11] locking/ww_mutex: Set use_ww_ctx even when locking without a context Nicolai Hähnle
2016-11-28 12:20 ` [PATCH 05/11] locking/ww_mutex: Add waiters in stamp order Nicolai Hähnle
2016-11-30 14:10   ` Chris Wilson
2016-11-28 12:20 ` [PATCH 06/11] locking/ww_mutex: Notify waiters that have to back off while adding tasks to wait list Nicolai Hähnle
2016-11-28 12:20 ` [PATCH 07/11] locking/ww_mutex: Wake at most one waiter for back off when acquiring the lock Nicolai Hähnle
2016-11-28 12:20 ` [PATCH 08/11] locking/ww_mutex: Yield to other waiters from optimistic spin Nicolai Hähnle
2016-11-28 12:20 ` [PATCH 09/11] locking/mutex: Initialize mutex_waiter::ww_ctx with poison when debugging Nicolai Hähnle
2016-11-28 12:20 ` [PATCH 10/11] Documentation/locking/ww_mutex: Update the design document Nicolai Hähnle
2016-11-28 12:20 ` [PATCH 11/11] [rfc] locking/ww_mutex: Always spin optimistically for the first waiter Nicolai Hähnle
2016-11-30  0:35 ` [PATCH 1/4] locking: Begin kselftests for ww_mutex Chris Wilson
2016-11-30  0:35   ` [PATCH 2/4] locking: Add kselftests for ww_mutex AA deadlock detection Chris Wilson
2016-11-30  0:35   ` [PATCH 3/4] locking: Add kselftests for ww_mutex ABBA " Chris Wilson
2016-11-30  0:35   ` [PATCH 4/4] locking: Add kselftests for ww_mutex stress Chris Wilson
2016-11-30 12:29     ` Maarten Lankhorst
2016-11-30 12:52       ` Chris Wilson
2016-11-30  8:00   ` [PATCH 1/4] locking: Begin kselftests for ww_mutex Nicolai Hähnle
2016-11-30 19:08   ` kbuild test robot
2016-11-30  9:40 ` [PATCH 00/11] locking/ww_mutex: Keep sorted wait list to avoid stampedes Chris Wilson
2016-11-30 11:52   ` Nicolai Hähnle
2016-11-30 12:20     ` Chris Wilson
2016-11-30 13:40       ` Nicolai Hähnle

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome