All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lukas Wunner <lukas@wunner.de>
To: Daniel Vetter <daniel@ffwll.ch>
Cc: Dave Airlie <airlied@redhat.com>, dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v2 00/22] Enable gpu switching on the MacBook Pro
Date: Wed, 26 Aug 2015 16:01:43 +0200	[thread overview]
Message-ID: <20150826140143.GA1990@wunner.de> (raw)
In-Reply-To: <20150825082120.GQ20434@phenom.ffwll.local>

Hi Daniel,

On Tue, Aug 25, 2015 at 10:21:20AM +0200, Daniel Vetter wrote:
> On Tue, Aug 25, 2015 at 09:36:47AM +0200, Lukas Wunner wrote:
> > I've overhauled locking once more because previously all EDID reads
> > were serialized even on machines which don't use vga_switcheroo at all.
> > Seems it's impossible to fix this with mutexes and still be race-free
> > and deadlock-free, so I've changed vgasr_mutex to an rwlock:
> > https://github.com/l1k/linux/commit/ffa4546d85244a53541eed6799f93e8eea7f29e8
> > 
> > There are a number of vga_switcheroo functions added by Takashi Iwai
> > and yourself which don't lock anything at all, I believe this was in
> > part to avoid deadlocks (vga_switcheroo_runtime_resume_hdmi_audio locks
> > vgasr_mutex, wakes up the GPU with vga_switcheroo_runtime_resume
> > which locks vgasr_mutex once again). After changing vgasr_mutex to an
> > rwlock we can safely use locking in those functions as well:
> > https://github.com/l1k/linux/commit/cdea8f5c92039329dde47cadf20b67c7d9af0d62
> > 
> > With this change, on machines which don't use vga_switcheroo, the
> > overhead in drm_get_edid() is exactly 1 read_lock + 1 read_unlock
> > and EDID reads can happen in parallel. Thierry Reding and Alex Deucher
> > are in favor of adding a separate drm_get_edid_switcheroo() and changing
> > the relevant drivers (i915, nouveau, radeon, amdgpu) to use that in lieu
> > of drm_get_edid() so that drivers which don't use vga_switcheroo avoid
> > the lock_ddc/unlock_ddc calls. Performance-wise these additional calls
> > should be negligible, so I think the motivation can only be better
> > readability/clarity. One should also keep in mind that drivers which
> > don't use vga_switcheroo currently might do so in the future, e.g.
> > if mobile GPUs use a big.LITTLE concept like ARM CPUs already do.
> 
> Just a quick aside: Switching to rwlocks to make lockdep happy is a
> fallacy - lockdep unfortunately doesn't accurately track read lock
> depencies. Which means very likely you didn't fix the locking inversions
> but just made lockdep shut up about them. [...]
> I'd highly suggest you try fixing the vga-switcheroo locking without
> resorting to rw lock primitives - that just means we need to manually
> prove the locking for many cases which is tons of work.

mutex is not the right tool for the job:

To make DDC switching bullet proof you need to block the handler from
unregistering between lock_ddc and unlock_ddc. Solution: ddc_lock grabs
a mutex, ddc_unlock releases it, unregister_handler grabs that same lock.

Downside: All EDID reads are serialized, you can't probe EDID in parallel
if you have multiple displays. Which is ugly.

One could be tempted to "solve" this for non-muxed machines by immediately
releasing the lock in lock_ddc if there's no handler, and by checking in
unlock_ddc if mutex_is_locked before releasing it. But on muxed machines
this would be racy: GPU driver A calls lock_ddc, acquires the mutex, sees
there's no handler registered, releases the mutex. Between this and the
call to unlock_ddc, a handler registers and GPU driver B calls lock_ddc.
This time the mutex is actually locked and when driver A calls unlock_ddc,
it will release it, even though the other driver had acquired it.

Of course one could come up with all sorts of ugly hacks like remembering
for which client the mutex was acquired, but this wouldn't be atomic and
100% bullet proof, unlike rwlocks.

So it seems there's no way with mutexes to achieve parallel EDID reads
and still be race-free and deadlock-free.

rwlocks have the right semantics for this use case: Registering and
unregistering requires write access to the lock, thus happens exclusively.
In lock_ddc we acquire read access to the rwlock and in unlock_ddc we
release it. So the handler can't disappear while we've switched DDC.
We use a mutex ddc_lock to lock the DDC lines but we only acquire that
lock if there's actually a handler. So on non-muxed machines, EDID reads
*can* happen in parallel, there's just the (negligible) overhead of
1 read_lock + 1 read_unlock:
https://github.com/l1k/linux/commit/d0b6f659ae8f4b8b94f4b3ded9fc80e93950d0b3

Best regards,

Lukas
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

  reply	other threads:[~2015-08-26 14:01 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-11 10:29 [PATCH v2 00/22] Enable gpu switching on the MacBook Pro Lukas Wunner
2012-09-07 15:22 ` [PATCH v2 01/22] vga_switcheroo: Add support for switching only the DDC Lukas Wunner
2012-09-07 15:22   ` [PATCH v2 02/22] vga_switcheroo: Add helper function to get the active client Lukas Wunner
2012-09-07 15:22     ` [PATCH v2 03/22] apple-gmux: Add switch_ddc support Lukas Wunner
2012-09-07 15:22       ` [PATCH v2 04/22] drm/edid: Switch DDC when reading the EDID Lukas Wunner
2012-12-22  2:52         ` [PATCH v2 05/22] vga_switcheroo: Lock/unlock DDC lines Lukas Wunner
2015-03-27 11:29           ` [PATCH v2 06/22] vga_switcheroo: Lock/unlock DDC lines harder Lukas Wunner
2015-04-21  8:39             ` [PATCH v2 07/22] Revert "vga_switcheroo: Add helper function to get the active client" Lukas Wunner
2015-08-02  9:06               ` [PATCH v2 08/22] Revert "vga_switcheroo: add reprobe hook for fbcon to recheck connected outputs." Lukas Wunner
2015-05-09 15:20                 ` [PATCH v2 09/22] drm/nouveau: Lock/unlock DDC lines on probe Lukas Wunner
2014-03-05 22:34                   ` [PATCH v2 10/22] apple-gmux: Assign apple_gmux_data before registering Lukas Wunner
2015-04-20 10:08                     ` [PATCH v2 11/22] vga_switcheroo: Generate hotplug event on handler and proxy registration Lukas Wunner
2015-07-15 11:57                       ` [PATCH v2 12/22] drm/i915: Preserve SSC earlier Lukas Wunner
2015-04-19 15:01                         ` [PATCH v2 13/22] drm/i915: Reprobe eDP and LVDS connectors on hotplug event Lukas Wunner
2015-06-30  9:06                           ` [PATCH v2 14/22 RESEND] drm/i915: Fix failure paths around initial fbdev allocation Lukas Wunner
2015-07-04  9:50                             ` [PATCH v2 15/22 RESEND] drm/i915: On fb alloc failure, unref gem object where it gets refed Lukas Wunner
2015-05-25 13:15                               ` [PATCH v2 16/22] drm: Create new fb and replace default 1024x768 fb on hotplug event Lukas Wunner
     [not found]                                 ` <afe73d5a7382f85c9bdbfc46197a52c4278c99c7.1439288957.git.lukas-JFq808J9C/izQB+pC5nmwQ@public.gmane.org>
2015-07-23 10:59                                   ` [PATCH v2 17/22] drm/nouveau/timer: Fall back to kernel timer if GPU timer read failed Lukas Wunner
2015-07-29 19:23                                     ` [PATCH v2 18/22 EXPERIMENTAL] vga_switcheroo: Allow using active client as proxy when reading DDC/AUX Lukas Wunner
2015-05-13 19:50                                       ` [PATCH v2 19/22 EXPERIMENTAL] drm: Amend struct drm_dp_aux with connector attribute Lukas Wunner
2015-05-06 12:06                                         ` [PATCH v2 20/22 EXPERIMENTAL] drm: Use vga_switcheroo active client as proxy when reading DDC/AUX Lukas Wunner
2015-07-30 11:31                                           ` [PATCH v2 21/22 EXPERIMENTAL] drm/nouveau/i2c: " Lukas Wunner
2015-06-07  9:20                                             ` [PATCH v2 22/22 EXPERIMENTAL] drm/nouveau: Use vga_switcheroo active client as proxy when probing DDC on LVDS Lukas Wunner
2015-08-31 20:23                         ` [PATCH v2 12/22] drm/i915: Preserve SSC earlier Jesse Barnes
2015-09-01  6:46                           ` Jani Nikula
2015-08-12 14:25               ` [PATCH v2 07/22] Revert "vga_switcheroo: Add helper function to get the active client" Daniel Vetter
2015-08-12 17:34                 ` Lukas Wunner
2015-08-12 21:10                   ` Daniel Vetter
2015-08-12 14:23             ` [PATCH v2 06/22] vga_switcheroo: Lock/unlock DDC lines harder Daniel Vetter
     [not found] ` <cover.1439288957.git.lukas-JFq808J9C/izQB+pC5nmwQ@public.gmane.org>
2015-08-12 14:16   ` [Intel-gfx] [PATCH v2 00/22] Enable gpu switching on the MacBook Pro Daniel Vetter
2015-08-12 23:37     ` Lukas Wunner
     [not found]       ` <20150812233711.GA6002-JFq808J9C/izQB+pC5nmwQ@public.gmane.org>
2015-08-13  6:50         ` [Intel-gfx] " Daniel Vetter
2015-08-16 19:10           ` Lukas Wunner
2015-08-25  7:36 ` Lukas Wunner
2015-08-25  8:21   ` Daniel Vetter
2015-08-26 14:01     ` Lukas Wunner [this message]
2015-08-29 14:15 ` Lukas Wunner
2015-08-31 19:15   ` Jani Nikula
2015-09-01  6:48     ` Jani Nikula
2015-09-04 14:00     ` Lukas Wunner

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=20150826140143.GA1990@wunner.de \
    --to=lukas@wunner.de \
    --cc=airlied@redhat.com \
    --cc=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.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.