All of lore.kernel.org
 help / color / mirror / Atom feed
From: Daniel Vetter <daniel@ffwll.ch>
To: "Christian König" <christian.koenig@amd.com>
Cc: Peter Zijlstra <peterz@infradead.org>,
	Lucas Stach <l.stach@pengutronix.de>,
	Russell King <linux+etnaviv@armlinux.org.uk>,
	Christian Gmeiner <christian.gmeiner@gmail.com>,
	Qiang Yu <yuq825@gmail.com>, "Anholt, Eric" <eric@anholt.net>,
	Thomas Hellstrom <thellstrom@vmware.com>,
	dri-devel <dri-devel@lists.freedesktop.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	The etnaviv authors <etnaviv@lists.freedesktop.org>,
	lima@lists.freedesktop.org
Subject: Re: [PATCH 3/6] drm/gem: use new ww_mutex_(un)lock_for_each macros
Date: Sat, 15 Jun 2019 15:56:25 +0200	[thread overview]
Message-ID: <CAKMK7uFzg+e315h2e5SmDTQwYTAbgAsxB_pc09ztwA1Wa-mzxw@mail.gmail.com> (raw)
In-Reply-To: <20190614203040.GE23020@phenom.ffwll.local>

On Fri, Jun 14, 2019 at 10:30 PM Daniel Vetter <daniel@ffwll.ch> wrote:
>
> On Fri, Jun 14, 2019 at 08:51:11PM +0200, Christian König wrote:
> > Am 14.06.19 um 20:24 schrieb Daniel Vetter:
> > >
> > > On Fri, Jun 14, 2019 at 8:10 PM Christian König <ckoenig.leichtzumerken@gmail.com> wrote:
> > > > [SNIP]
> > > > WW_MUTEX_LOCK_BEGIN()
> > > >
> > > > lock(lru_lock);
> > > >
> > > > while (bo = list_first(lru)) {
> > > >   if (kref_get_unless_zero(bo)) {
> > > >           unlock(lru_lock);
> > > >           WW_MUTEX_LOCK(bo->ww_mutex);
> > > >           lock(lru_lock);
> > > >   } else {
> > > >           /* bo is getting freed, steal it from the freeing process
> > > >            * or just ignore */
> > > >   }
> > > > }
> > > > unlock(lru_lock)
> > > >
> > > > WW_MUTEX_LOCK_END;
> >
> > Ah, now I know what you mean. And NO, that approach doesn't work.
> >
> > See for the correct ww_mutex dance we need to use the iterator multiple
> > times.
> >
> > Once to give us the BOs which needs to be locked and another time to give us
> > the BOs which needs to be unlocked in case of a contention.
> >
> > That won't work with the approach you suggest here.
>
> A right, drat.
>
> Maybe give up on the idea to make this work for ww_mutex in general, and
> just for drm_gem_buffer_object? I'm just about to send out a patch series
> which makes sure that a lot more drivers set gem_bo.resv correctly (it
> will alias with ttm_bo.resv for ttm drivers ofc). Then we could add a
> list_head to gem_bo (won't really matter, but not something we can do with
> ww_mutex really), so that the unlock walking doesn't need to reuse the
> same iterator. That should work I think ...
>
> Also, it would almost cover everything you want to do. For ttm we'd need
> to make ttm_bo a subclass of gem_bo (and maybe not initialize that
> embedded gem_bo for vmwgfx and shadow bo and driver internal stuff).
>
> Just some ideas, since copypasting the ww_mutex dance into all drivers is
> indeed not great.

Even better we don't need to force everyone to use drm_gem_object, the
hard work is already done with the reservation_object. We could add a
list_head there for unwinding, and then the locking helpers would look
a lot cleaner and simpler imo. reservation_unlock_all() would even be
a real function! And if we do this then I think we should also have a
reservation_acquire_ctx, to store the list_head and maybe anything
else.

Plus all the code you want to touch is dealing with
reservation_object, so that's all covered. And it mirros quite a bit
what we've done with struct drm_modeset_lock, to wrap ww_mutex is
something easier to deal with for kms.
-Daniel

> -Daniel
>
> >
> > Regards,
> > Christian.
> >
> > >
> > >
> > > Also I think if we allow this we could perhaps use this to implement the
> > > modeset macros too.
> > > -Daniel
> > >
> > >
> > >
> > >
> > > > > This is kinda what we went with for modeset locks with
> > > > > DRM_MODESET_LOCK_ALL_BEGIN/END, you can grab more locks in between the
> > > > > pair at least. But it's a lot more limited use-cases, maybe too fragile an
> > > > > idea for ww_mutex in full generality.
> > > > >
> > > > > Not going to type this out because too much w/e mode here already, but I
> > > > > can give it a stab next week.
> > > > > -Daniel
> > > > _______________________________________________
> > > > dri-devel mailing list
> > > > dri-devel@lists.freedesktop.org
> > > > https://lists.freedesktop.org/mailman/listinfo/dri-devel
> > >
> > >
> >
> > _______________________________________________
> > dri-devel mailing list
> > dri-devel@lists.freedesktop.org
> > https://lists.freedesktop.org/mailman/listinfo/dri-devel
>
> --
> Daniel Vetter
> Software Engineer, Intel Corporation
> http://blog.ffwll.ch



-- 
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch

WARNING: multiple messages have this Message-ID (diff)
From: Daniel Vetter <daniel@ffwll.ch>
To: "Christian König" <christian.koenig@amd.com>
Cc: Thomas Hellstrom <thellstrom@vmware.com>,
	lima@lists.freedesktop.org, Peter Zijlstra <peterz@infradead.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	dri-devel <dri-devel@lists.freedesktop.org>,
	The etnaviv authors <etnaviv@lists.freedesktop.org>,
	Qiang Yu <yuq825@gmail.com>,
	Russell King <linux+etnaviv@armlinux.org.uk>
Subject: Re: [PATCH 3/6] drm/gem: use new ww_mutex_(un)lock_for_each macros
Date: Sat, 15 Jun 2019 15:56:25 +0200	[thread overview]
Message-ID: <CAKMK7uFzg+e315h2e5SmDTQwYTAbgAsxB_pc09ztwA1Wa-mzxw@mail.gmail.com> (raw)
In-Reply-To: <20190614203040.GE23020@phenom.ffwll.local>

On Fri, Jun 14, 2019 at 10:30 PM Daniel Vetter <daniel@ffwll.ch> wrote:
>
> On Fri, Jun 14, 2019 at 08:51:11PM +0200, Christian König wrote:
> > Am 14.06.19 um 20:24 schrieb Daniel Vetter:
> > >
> > > On Fri, Jun 14, 2019 at 8:10 PM Christian König <ckoenig.leichtzumerken@gmail.com> wrote:
> > > > [SNIP]
> > > > WW_MUTEX_LOCK_BEGIN()
> > > >
> > > > lock(lru_lock);
> > > >
> > > > while (bo = list_first(lru)) {
> > > >   if (kref_get_unless_zero(bo)) {
> > > >           unlock(lru_lock);
> > > >           WW_MUTEX_LOCK(bo->ww_mutex);
> > > >           lock(lru_lock);
> > > >   } else {
> > > >           /* bo is getting freed, steal it from the freeing process
> > > >            * or just ignore */
> > > >   }
> > > > }
> > > > unlock(lru_lock)
> > > >
> > > > WW_MUTEX_LOCK_END;
> >
> > Ah, now I know what you mean. And NO, that approach doesn't work.
> >
> > See for the correct ww_mutex dance we need to use the iterator multiple
> > times.
> >
> > Once to give us the BOs which needs to be locked and another time to give us
> > the BOs which needs to be unlocked in case of a contention.
> >
> > That won't work with the approach you suggest here.
>
> A right, drat.
>
> Maybe give up on the idea to make this work for ww_mutex in general, and
> just for drm_gem_buffer_object? I'm just about to send out a patch series
> which makes sure that a lot more drivers set gem_bo.resv correctly (it
> will alias with ttm_bo.resv for ttm drivers ofc). Then we could add a
> list_head to gem_bo (won't really matter, but not something we can do with
> ww_mutex really), so that the unlock walking doesn't need to reuse the
> same iterator. That should work I think ...
>
> Also, it would almost cover everything you want to do. For ttm we'd need
> to make ttm_bo a subclass of gem_bo (and maybe not initialize that
> embedded gem_bo for vmwgfx and shadow bo and driver internal stuff).
>
> Just some ideas, since copypasting the ww_mutex dance into all drivers is
> indeed not great.

Even better we don't need to force everyone to use drm_gem_object, the
hard work is already done with the reservation_object. We could add a
list_head there for unwinding, and then the locking helpers would look
a lot cleaner and simpler imo. reservation_unlock_all() would even be
a real function! And if we do this then I think we should also have a
reservation_acquire_ctx, to store the list_head and maybe anything
else.

Plus all the code you want to touch is dealing with
reservation_object, so that's all covered. And it mirros quite a bit
what we've done with struct drm_modeset_lock, to wrap ww_mutex is
something easier to deal with for kms.
-Daniel

> -Daniel
>
> >
> > Regards,
> > Christian.
> >
> > >
> > >
> > > Also I think if we allow this we could perhaps use this to implement the
> > > modeset macros too.
> > > -Daniel
> > >
> > >
> > >
> > >
> > > > > This is kinda what we went with for modeset locks with
> > > > > DRM_MODESET_LOCK_ALL_BEGIN/END, you can grab more locks in between the
> > > > > pair at least. But it's a lot more limited use-cases, maybe too fragile an
> > > > > idea for ww_mutex in full generality.
> > > > >
> > > > > Not going to type this out because too much w/e mode here already, but I
> > > > > can give it a stab next week.
> > > > > -Daniel
> > > > _______________________________________________
> > > > dri-devel mailing list
> > > > dri-devel@lists.freedesktop.org
> > > > https://lists.freedesktop.org/mailman/listinfo/dri-devel
> > >
> > >
> >
> > _______________________________________________
> > dri-devel mailing list
> > dri-devel@lists.freedesktop.org
> > https://lists.freedesktop.org/mailman/listinfo/dri-devel
>
> --
> Daniel Vetter
> Software Engineer, Intel Corporation
> http://blog.ffwll.ch



-- 
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

  reply	other threads:[~2019-06-15 13:57 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-14 12:41 ww_mutex deadlock handling cleanup Christian König
2019-06-14 12:41 ` [PATCH 1/6] locking: add ww_mutex_(un)lock_for_each helpers Christian König
2019-06-14 12:56   ` Peter Zijlstra
2019-06-14 12:56     ` Peter Zijlstra
2019-06-14 13:04     ` Christian König
2019-06-14 12:41 ` [PATCH 2/6] drm/ttm: use new ww_mutex_(un)lock_for_each macros Christian König
2019-06-14 12:41 ` [PATCH 3/6] drm/gem: " Christian König
2019-06-14 12:41   ` Christian König
2019-06-14 12:59   ` Peter Zijlstra
2019-06-14 12:59     ` Peter Zijlstra
2019-06-14 13:06     ` Christian König
2019-06-14 13:21       ` Peter Zijlstra
2019-06-14 13:19   ` Peter Zijlstra
2019-06-14 15:22     ` Daniel Vetter
2019-06-14 18:10       ` Christian König
2019-06-14 18:24         ` Daniel Vetter
2019-06-14 18:24           ` Daniel Vetter
2019-06-14 18:51           ` Christian König
2019-06-14 20:30             ` Daniel Vetter
2019-06-14 20:30               ` Daniel Vetter
2019-06-15 13:56               ` Daniel Vetter [this message]
2019-06-15 13:56                 ` Daniel Vetter
2019-06-17  9:30                 ` Christian König
2019-06-14 12:41 ` [PATCH 4/6] drm/etnaviv: " Christian König
2019-06-14 12:41   ` Christian König
2019-06-14 12:41 ` [PATCH 5/6] drm/lima: " Christian König
2019-06-14 12:41   ` Christian König
2019-06-14 12:41 ` [PATCH 6/6] drm/vc4: " Christian König

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=CAKMK7uFzg+e315h2e5SmDTQwYTAbgAsxB_pc09ztwA1Wa-mzxw@mail.gmail.com \
    --to=daniel@ffwll.ch \
    --cc=christian.gmeiner@gmail.com \
    --cc=christian.koenig@amd.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=eric@anholt.net \
    --cc=etnaviv@lists.freedesktop.org \
    --cc=l.stach@pengutronix.de \
    --cc=lima@lists.freedesktop.org \
    --cc=linux+etnaviv@armlinux.org.uk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peterz@infradead.org \
    --cc=thellstrom@vmware.com \
    --cc=yuq825@gmail.com \
    /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.