[PATCH 3/6] drm/gem: use new ww_mutex_(un)lock_for_each macros
Daniel Vetter
daniel at ffwll.ch
Fri Jun 14 20:30:40 UTC 2019
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 at 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.
-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 at lists.freedesktop.org
> > > https://lists.freedesktop.org/mailman/listinfo/dri-devel
> >
> >
>
> _______________________________________________
> dri-devel mailing list
> dri-devel at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel
--
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
More information about the etnaviv
mailing list