All of lore.kernel.org
 help / color / mirror / Atom feed
From: Qiang Yu <yuq825@gmail.com>
To: "Christian König" <christian.koenig@amd.com>
Cc: Simon Shields <simon@lineageos.org>,
	devicetree@vger.kernel.org, Connor Abbott <cwabbott0@gmail.com>,
	Marek Vasut <marex@denx.de>,
	Neil Armstrong <narmstrong@baylibre.com>,
	Andrei Paulau <7134956@gmail.com>,
	dri-devel <dri-devel@lists.freedesktop.org>,
	Vasily Khoruzhick <anarsoul@gmail.com>,
	Erico Nunes <nunes.erico@gmail.com>
Subject: Re: [PATCH RFC 05/24] Revert "drm: Nerf the preclose callback for modern drivers"
Date: Thu, 24 May 2018 09:38:38 +0800	[thread overview]
Message-ID: <CAKGbVbv10zGLe34J1BXdKHg1Kg0=7A3jUy_8pnjVjNs1T=r8mw@mail.gmail.com> (raw)
In-Reply-To: <c958599c-b0df-8b85-4123-daeed0fb07ac@amd.com>

On Wed, May 23, 2018 at 9:41 PM, Christian König
<christian.koenig@amd.com> wrote:
> Am 23.05.2018 um 15:13 schrieb Qiang Yu:
>>
>> On Wed, May 23, 2018 at 5:35 PM, Christian König
>> <ckoenig.leichtzumerken@gmail.com> wrote:
>>>
>>> Well NAK, that brings back a callback we worked quite hard on getting rid
>>> of.
>>>
>>> It looks like the problem isn't that you need the preclose callback, but
>>> you
>>> rather seem to misunderstood how TTM works.
>>>
>>> All you need to do is to cleanup your command submission path so that the
>>> caller of lima_sched_context_queue_task() adds the resulting scheduler
>>> fence
>>> to TTMs buffer objects.
>>
>> You mean adding the finished dma fence to the buffer's reservation object
>> then
>> waiting it before unmap the buffer from GPU VM in the drm_release()'s
>> buffer
>> close callback?
>
>
> That is one possibility, but also not necessary.
>
> TTM has a destroy callback which is called from a workqueue when all fences
> on that BOs have signaled.
>
> Depending on your VM management you can use it to delay unmapping the buffer
> until it is actually not used any more.
>
>> Adding fence is done already, and I did wait it before unmap. But then
>> I see when
>> the buffer is shared between processes, the "perfect wait" is just
>> wait the fence
>> from this process's task, so it's better to also distinguish fences.
>> If so, I just think
>> why we don't just wait tasks from this process in the preclose before
>> unmap/free
>> buffer in the drm_release()?
>
>
> Well it depends on your VM management. When userspace expects that the VM
> space the BO used is reusable immediately than the TTM callback won't work.
>
> On the other hand you can just grab the list of fences on a BO and filter
> out the ones from your current process and wait for those. See
> amdgpu_sync_resv() as an example how to do that.

In current lima implementation, user space driver is responsible not unmap/free
buffer before task is complete. And VM map/unmap is not differed.

This works simple and fine except the case that user press Ctrl+C to terminate
the application which will force to close drm fd.

I'd more prefer to wait buffer fence before vm unmap and filter like
amdgpu_sync_resv() compared to implement refcount in kernel task.
But these two ways are all not as simple as preclose.

So I still don't understand why you don't want to get preclose back even
have to introduce other complicated mechanism to cover the case free/unmap
buffer before this process's task is done?

Regards,
Qiang

>
> Christian.
>
>
>>
>> Regards,
>> Qiang
>>
>>>
>>> Am 18.05.2018 um 11:27 schrieb Qiang Yu:
>>>>
>>>> This reverts commit 45c3d213a400c952ab7119f394c5293bb6877e6b.
>>>>
>>>> lima driver need preclose to wait all task in the context
>>>> created within closing file to finish before free all the
>>>> buffer object. Otherwise pending tesk may fail and get
>>>> noisy MMU fault message.
>>>>
>>>> Move this wait to each buffer object free function can
>>>> achieve the same result but some buffer object is shared
>>>> with other file context, but we only want to wait the
>>>> closing file context's tasks. So the implementation is
>>>> not that straight forword compared to the preclose one.
>>>>
>>>> Signed-off-by: Qiang Yu <yuq825@gmail.com>
>>>> ---
>>>>    drivers/gpu/drm/drm_file.c |  8 ++++----
>>>>    include/drm/drm_drv.h      | 23 +++++++++++++++++++++--
>>>>    2 files changed, 25 insertions(+), 6 deletions(-)
>>>>
>>>> diff --git a/drivers/gpu/drm/drm_file.c b/drivers/gpu/drm/drm_file.c
>>>> index e394799979a6..0a43107396b9 100644
>>>> --- a/drivers/gpu/drm/drm_file.c
>>>> +++ b/drivers/gpu/drm/drm_file.c
>>>> @@ -361,8 +361,9 @@ void drm_lastclose(struct drm_device * dev)
>>>>     *
>>>>     * This function must be used by drivers as their
>>>> &file_operations.release
>>>>     * method. It frees any resources associated with the open file, and
>>>> calls the
>>>> - * &drm_driver.postclose driver callback. If this is the last open file
>>>> for the
>>>> - * DRM device also proceeds to call the &drm_driver.lastclose driver
>>>> callback.
>>>> + * &drm_driver.preclose and &drm_driver.lastclose driver callbacks. If
>>>> this is
>>>> + * the last open file for the DRM device also proceeds to call the
>>>> + * &drm_driver.lastclose driver callback.
>>>>     *
>>>>     * RETURNS:
>>>>     *
>>>> @@ -382,8 +383,7 @@ int drm_release(struct inode *inode, struct file
>>>> *filp)
>>>>          list_del(&file_priv->lhead);
>>>>          mutex_unlock(&dev->filelist_mutex);
>>>>    -     if (drm_core_check_feature(dev, DRIVER_LEGACY) &&
>>>> -           dev->driver->preclose)
>>>> +       if (dev->driver->preclose)
>>>>                  dev->driver->preclose(dev, file_priv);
>>>>          /* ========================================================
>>>> diff --git a/include/drm/drm_drv.h b/include/drm/drm_drv.h
>>>> index d23dcdd1bd95..8d6080f97ed4 100644
>>>> --- a/include/drm/drm_drv.h
>>>> +++ b/include/drm/drm_drv.h
>>>> @@ -107,6 +107,23 @@ struct drm_driver {
>>>>           */
>>>>          int (*open) (struct drm_device *, struct drm_file *);
>>>>    +     /**
>>>> +        * @preclose:
>>>> +        *
>>>> +        * One of the driver callbacks when a new &struct drm_file is
>>>> closed.
>>>> +        * Useful for tearing down driver-private data structures
>>>> allocated in
>>>> +        * @open like buffer allocators, execution contexts or similar
>>>> things.
>>>> +        *
>>>> +        * Since the display/modeset side of DRM can only be owned by
>>>> exactly
>>>> +        * one &struct drm_file (see &drm_file.is_master and
>>>> &drm_device.master)
>>>> +        * there should never be a need to tear down any modeset related
>>>> +        * resources in this callback. Doing so would be a driver design
>>>> bug.
>>>> +        *
>>>> +        * FIXME: It is not really clear why there's both @preclose and
>>>> +        * @postclose. Without a really good reason, use @postclose
>>>> only.
>>>> +        */
>>>> +       void (*preclose) (struct drm_device *, struct drm_file
>>>> *file_priv);
>>>> +
>>>>          /**
>>>>           * @postclose:
>>>>           *
>>>> @@ -118,6 +135,9 @@ struct drm_driver {
>>>>           * one &struct drm_file (see &drm_file.is_master and
>>>> &drm_device.master)
>>>>           * there should never be a need to tear down any modeset
>>>> related
>>>>           * resources in this callback. Doing so would be a driver
>>>> design
>>>> bug.
>>>> +        *
>>>> +        * FIXME: It is not really clear why there's both @preclose and
>>>> +        * @postclose. Without a really good reason, use @postclose
>>>> only.
>>>>           */
>>>>          void (*postclose) (struct drm_device *, struct drm_file *);
>>>>    @@ -134,7 +154,7 @@ struct drm_driver {
>>>>           * state changes, e.g. in conjunction with the
>>>> :ref:`vga_switcheroo`
>>>>           * infrastructure.
>>>>           *
>>>> -        * This is called after @postclose hook has been called.
>>>> +        * This is called after @preclose and @postclose have been
>>>> called.
>>>>           *
>>>>           * NOTE:
>>>>           *
>>>> @@ -601,7 +621,6 @@ struct drm_driver {
>>>>          /* List of devices hanging off this driver with stealth attach.
>>>> */
>>>>          struct list_head legacy_dev_list;
>>>>          int (*firstopen) (struct drm_device *);
>>>> -       void (*preclose) (struct drm_device *, struct drm_file
>>>> *file_priv);
>>>>          int (*dma_ioctl) (struct drm_device *dev, void *data, struct
>>>> drm_file *file_priv);
>>>>          int (*dma_quiescent) (struct drm_device *);
>>>>          int (*context_dtor) (struct drm_device *dev, int context);
>>>
>>>
>
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

  reply	other threads:[~2018-05-24  1:38 UTC|newest]

Thread overview: 89+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-18  9:27 [PATCH RFC 00/24] Lima DRM driver Qiang Yu
2018-05-18  9:27 ` [PATCH RFC 01/24] ARM: dts: add gpu node to exynos4 Qiang Yu
2018-05-23 17:06   ` Rob Herring
2018-05-18  9:27 ` [PATCH RFC 02/24] dt-bindings: add switch-delay property for mali-utgard Qiang Yu
2018-05-23 17:04   ` Rob Herring
2018-05-24  1:52     ` Qiang Yu
2018-05-18  9:27 ` [PATCH RFC 03/24] arm64/dts: add switch-delay for meson mali Qiang Yu
2018-05-21 14:16   ` Neil Armstrong
2018-05-21 14:16     ` Neil Armstrong
2018-05-22  0:48     ` Qiang Yu
2018-05-22  0:48       ` Qiang Yu
2018-05-18  9:27 ` [PATCH RFC 04/24] " Qiang Yu
2018-05-21 14:16   ` Neil Armstrong
2018-05-21 14:16     ` Neil Armstrong
2018-05-18  9:27 ` [PATCH RFC 05/24] Revert "drm: Nerf the preclose callback for modern drivers" Qiang Yu
2018-05-23  9:35   ` Christian König
2018-05-23 13:13     ` Qiang Yu
2018-05-23 13:41       ` Christian König
2018-05-24  1:38         ` Qiang Yu [this message]
2018-05-24  6:46           ` Christian König
2018-05-24  9:24             ` Qiang Yu
2018-05-24  9:41               ` Christian König
2018-05-24 12:54                 ` Qiang Yu
2018-05-18  9:27 ` [PATCH RFC 06/24] drm/lima: add lima uapi header Qiang Yu
2018-05-18  9:33   ` Marek Vasut
2018-05-20  7:22     ` Qiang Yu
2018-05-20  9:52       ` Marek Vasut
2018-05-20  7:25     ` Qiang Yu
2018-05-18  9:27 ` [PATCH RFC 07/24] drm/lima: add mali 4xx GPU hardware regs Qiang Yu
2018-05-23 17:24   ` Rob Herring
2018-05-23 17:31     ` Vasily Khoruzhick
2018-05-24  0:58     ` Qiang Yu
2018-05-24 14:31       ` Rob Herring
2018-05-18  9:27 ` [PATCH RFC 08/24] drm/lima: add lima core driver Qiang Yu
2018-05-18  9:28 ` [PATCH RFC 09/24] drm/lima: add GPU device functions Qiang Yu
2018-05-18  9:28 ` [PATCH RFC 10/24] drm/lima: add PMU related functions Qiang Yu
2018-05-18  9:28 ` [PATCH RFC 11/24] drm/lima: add L2 cache functions Qiang Yu
2018-05-18  9:28 ` [PATCH RFC 12/24] drm/lima: add GP related functions Qiang Yu
2018-05-23 17:12   ` Marek Vasut
2018-05-24  0:38     ` Qiang Yu
2018-05-18  9:28 ` [PATCH RFC 13/24] drm/lima: add PP " Qiang Yu
2018-05-18  9:28 ` [PATCH RFC 14/24] drm/lima: add MMU " Qiang Yu
2018-05-18  9:28 ` [PATCH RFC 15/24] drm/lima: add BCAST related function Qiang Yu
2018-05-18  9:28 ` [PATCH RFC 16/24] drm/lima: add DLBU related functions Qiang Yu
2018-05-18  9:28 ` [PATCH RFC 17/24] drm/lima: add GPU virtual memory space handing Qiang Yu
2018-05-18  9:28 ` [PATCH RFC 18/24] drm/lima: add TTM subsystem functions Qiang Yu
2018-05-18  9:28 ` [PATCH RFC 19/24] drm/lima: add buffer object functions Qiang Yu
2018-05-18  9:28 ` [PATCH RFC 20/24] drm/lima: add GEM related functions Qiang Yu
2018-05-18  9:28 ` [PATCH RFC 21/24] drm/lima: add GEM Prime " Qiang Yu
2018-05-18  9:28 ` [PATCH RFC 22/24] drm/lima: add GPU schedule using DRM_SCHED Qiang Yu
2018-05-18  9:28 ` [PATCH RFC 23/24] drm/lima: add context related functions Qiang Yu
2018-05-18  9:28 ` [PATCH RFC 24/24] drm/lima: add makefile and kconfig Qiang Yu
2018-05-23 17:16   ` Marek Vasut
2018-05-23 17:26     ` Rob Herring
2018-05-24  0:49       ` Qiang Yu
2018-06-15 17:23     ` Andre Przywara
2018-07-14  1:14       ` Qiang Yu
2018-07-14 12:06         ` André Przywara
2018-07-14 14:18           ` Qiang Yu
2018-07-14 19:15             ` André Przywara
2018-07-15  2:23               ` Qiang Yu
2018-05-23  9:02 ` [PATCH RFC 00/24] Lima DRM driver Daniel Vetter
2018-05-23 13:24   ` Qiang Yu
2018-05-23  9:29 ` Christian König
2018-05-23 13:52   ` Qiang Yu
2018-05-23 13:59     ` Christian König
2018-05-23 14:13       ` Qiang Yu
2018-05-23 14:19         ` Christian König
2018-05-23 14:27           ` Qiang Yu
2018-05-23 15:44     ` Daniel Vetter
2018-05-24  0:31       ` Qiang Yu
2018-05-24  6:27         ` Christian König
2018-05-24  7:25           ` Daniel Vetter
2018-05-24  9:53             ` Christian König
2018-05-19  6:52 Qiang Yu
2018-05-19  6:52 ` [PATCH RFC 05/24] Revert "drm: Nerf the preclose callback for modern drivers" Qiang Yu
2018-05-21 19:37   ` Eric Anholt
2018-05-22  1:04     ` Qiang Yu
2018-05-23  9:04       ` Daniel Vetter
2018-05-23 12:59         ` Qiang Yu
2018-05-23 20:31           ` Daniel Vetter
2018-05-24  1:18             ` Qiang Yu
2018-05-24  7:51               ` Daniel Vetter
2018-05-24  8:55                 ` Qiang Yu
2018-05-30 18:13                   ` Eric Anholt
2018-05-31 14:04                     ` Qiang Yu
2018-05-31 17:51                       ` Eric Anholt
2018-05-31 18:04                         ` Keith Packard
2018-06-01  2:03                           ` Qiang Yu
2018-06-01  1:58                         ` Qiang Yu

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='CAKGbVbv10zGLe34J1BXdKHg1Kg0=7A3jUy_8pnjVjNs1T=r8mw@mail.gmail.com' \
    --to=yuq825@gmail.com \
    --cc=7134956@gmail.com \
    --cc=anarsoul@gmail.com \
    --cc=christian.koenig@amd.com \
    --cc=cwabbott0@gmail.com \
    --cc=devicetree@vger.kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=marex@denx.de \
    --cc=narmstrong@baylibre.com \
    --cc=nunes.erico@gmail.com \
    --cc=simon@lineageos.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.