From: Daniel Vetter <daniel-/w4YWyX8dFk@public.gmane.org>
To: Rob Herring <robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
Cc: Sean Paul <sean-p7yTbzM4H96eqtR555YLDQ@public.gmane.org>,
Rob Clark <robdclark-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
Maxime Ripard
<maxime.ripard-LDxbnhwyfcJBDgjK7y7TUQ@public.gmane.org>,
David Airlie <airlied-cv59FeDIM0c@public.gmane.org>,
linux-arm-msm-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
Maarten Lankhorst
<maarten.lankhorst-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>,
etnaviv-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org,
dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org,
Eric Anholt <eric-WhKQ6XTQaPysTnJN9+BGXg@public.gmane.org>,
Christian Gmeiner
<christian.gmeiner-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
Daniel Vetter <daniel-/w4YWyX8dFk@public.gmane.org>,
Russell King
<linux+etnaviv-I+IVW8TIWO2tmTQ+vhA3Yw@public.gmane.org>,
freedreno-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org,
Lucas Stach <l.stach-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
Subject: Re: [PATCH 1/5] drm: Add reservation_object to drm_gem_object
Date: Fri, 1 Feb 2019 18:21:31 +0100 [thread overview]
Message-ID: <20190201172131.GD3271@phenom.ffwll.local> (raw)
In-Reply-To: <20190201005057.13648-2-robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
On Thu, Jan 31, 2019 at 06:50:53PM -0600, Rob Herring wrote:
> Many users of drm_gem_object embed a struct reservation_object into
> their subclassed struct, so let's add one to struct drm_gem_object.
> This will allow removing the reservation object from the subclasses
> and removing the ->gem_prime_res_obj callback.
>
> With the addition, add a drm_gem_reservation_object_wait() helper
> function for drivers to use in wait ioctls.
>
> Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
> Cc: Maxime Ripard <maxime.ripard@bootlin.com>
> Cc: Sean Paul <sean@poorly.run>
> Cc: David Airlie <airlied@linux.ie>
> Cc: Daniel Vetter <daniel@ffwll.ch>
> Signed-off-by: Rob Herring <robh@kernel.org>
> ---
> Documentation/gpu/todo.rst | 9 ---------
> drivers/gpu/drm/drm_gem.c | 39 +++++++++++++++++++++++++++++++++++++
> drivers/gpu/drm/drm_prime.c | 1 +
> include/drm/drm_gem.h | 7 +++++++
> 4 files changed, 47 insertions(+), 9 deletions(-)
>
> diff --git a/Documentation/gpu/todo.rst b/Documentation/gpu/todo.rst
> index 14191b64446d..6e0a37d0bf6d 100644
> --- a/Documentation/gpu/todo.rst
> +++ b/Documentation/gpu/todo.rst
> @@ -209,15 +209,6 @@ Would be great to refactor this all into a set of small common helpers.
>
> Contact: Daniel Vetter
>
> -Put a reservation_object into drm_gem_object
> ---------------------------------------------
> -
> -This would remove the need for the ->gem_prime_res_obj callback. It would also
> -allow us to implement generic helpers for waiting for a bo, allowing for quite a
> -bit of refactoring in the various wait ioctl implementations.
> -
> -Contact: Daniel Vetter
> -
> idr_init_base()
> ---------------
>
> diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c
> index 8b55ece97967..91dd06c1b3a8 100644
> --- a/drivers/gpu/drm/drm_gem.c
> +++ b/drivers/gpu/drm/drm_gem.c
> @@ -170,6 +170,10 @@ void drm_gem_private_object_init(struct drm_device *dev,
> kref_init(&obj->refcount);
> obj->handle_count = 0;
> obj->size = size;
> + if (!obj->resv) {
> + obj->resv = &obj->_resv;
> + reservation_object_init(obj->resv);
You _fini unconditionally, but don't _init unconditionally. I think
simplest to just always init (and only assign the pointer if nothing's
been assigned to it yet).
> + }
> drm_vma_node_reset(&obj->vma_node);
> }
> EXPORT_SYMBOL(drm_gem_private_object_init);
> @@ -657,6 +661,40 @@ drm_gem_object_lookup(struct drm_file *filp, u32 handle)
> }
> EXPORT_SYMBOL(drm_gem_object_lookup);
>
> +/**
> + * drm_gem_object_lookup - Wait on GEM object's reservation's objects
> + * shared and/or exclusive fences.
> + * @filp: DRM file private date
> + * @handle: userspace handle
> + * @wait_all: if true, wait on all fences, else wait on just exclusive fence
> + * @timeout: timeout value in jiffies or zero to return immediately
> + *
> + * Returns:
> + *
> + * Returns -ERESTARTSYS if interrupted, 0 if the wait timed out, or
> + * greater than 0 on success.
> + */
> +long drm_gem_reservation_object_wait(struct drm_file *filep, u32 handle,
> + bool wait_all, unsigned long timeout)
> +{
> + long ret;
> + struct drm_gem_object *obj;
> +
> + obj = drm_gem_object_lookup(filep, handle);
> + if (!obj) {
> + DRM_DEBUG("Failed to look up GEM BO %d\n", handle);
> + return -EINVAL;
> + }
> +
> + ret = reservation_object_wait_timeout_rcu(obj->resv, wait_all,
> + true, timeout);
> +
> + drm_gem_object_put_unlocked(obj);
> +
> + return ret;
> +}
> +EXPORT_SYMBOL(drm_gem_reservation_object_wait);
> +
> /**
> * drm_gem_close_ioctl - implementation of the GEM_CLOSE ioctl
> * @dev: drm_device
> @@ -821,6 +859,7 @@ drm_gem_object_release(struct drm_gem_object *obj)
> if (obj->filp)
> fput(obj->filp);
>
> + reservation_object_fini(&obj->_resv);
> drm_gem_free_mmap_offset(obj);
> }
> EXPORT_SYMBOL(drm_gem_object_release);
> diff --git a/drivers/gpu/drm/drm_prime.c b/drivers/gpu/drm/drm_prime.c
> index 231e3f6d5f41..dc079efb3b0f 100644
> --- a/drivers/gpu/drm/drm_prime.c
> +++ b/drivers/gpu/drm/drm_prime.c
> @@ -504,6 +504,7 @@ struct dma_buf *drm_gem_prime_export(struct drm_device *dev,
> .size = obj->size,
> .flags = flags,
> .priv = obj,
> + .resv = obj->resv,
> };
>
> if (dev->driver->gem_prime_res_obj)
> diff --git a/include/drm/drm_gem.h b/include/drm/drm_gem.h
> index c95727425284..f450a5b6038e 100644
> --- a/include/drm/drm_gem.h
> +++ b/include/drm/drm_gem.h
> @@ -35,6 +35,7 @@
> */
>
> #include <linux/kref.h>
> +#include <linux/reservation.h>
>
> #include <drm/drm_vma_manager.h>
>
> @@ -262,6 +263,10 @@ struct drm_gem_object {
> */
> struct dma_buf_attachment *import_attach;
>
> + /* normally (resv == &_resv) except for imported bo's */
> + struct reservation_object *resv;
> + struct reservation_object _resv;
Some kerneldoc here would be neat too.
Otherwise looks good to me..
-Daniel
> +
> /**
> * @funcs:
> *
> @@ -363,6 +368,8 @@ void drm_gem_put_pages(struct drm_gem_object *obj, struct page **pages,
> bool dirty, bool accessed);
>
> struct drm_gem_object *drm_gem_object_lookup(struct drm_file *filp, u32 handle);
> +long drm_gem_reservation_object_wait(struct drm_file *filep, u32 handle,
> + bool wait_all, unsigned long timeout);
> int drm_gem_dumb_map_offset(struct drm_file *file, struct drm_device *dev,
> u32 handle, u64 *offset);
> int drm_gem_dumb_destroy(struct drm_file *file,
> --
> 2.19.1
>
--
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
Freedreno mailing list
Freedreno@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/freedreno
next prev parent reply other threads:[~2019-02-01 17:21 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-01 0:50 [PATCH 0/5] Add reservation_object to drm_gem_object Rob Herring
2019-02-01 0:50 ` [PATCH 1/5] drm: " Rob Herring
2019-02-01 12:39 ` kbuild test robot
[not found] ` <20190201005057.13648-2-robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2019-02-01 17:21 ` Daniel Vetter [this message]
[not found] ` <20190201005057.13648-1-robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2019-02-01 0:50 ` [PATCH 2/5] drm: etnaviv: Switch to use drm_gem_object reservation_object Rob Herring
2019-02-01 0:50 ` [PATCH 3/5] drm: msm: " Rob Herring
2019-02-01 0:50 ` [PATCH 4/5] drm: v3d: " Rob Herring
[not found] ` <20190201005057.13648-5-robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2019-02-01 17:12 ` Eric Anholt
2019-02-01 17:38 ` Rob Herring
2019-02-01 17:23 ` [PATCH 0/5] Add reservation_object to drm_gem_object Daniel Vetter
2019-02-01 0:50 ` [PATCH 5/5] drm: vc4: Switch to use drm_gem_object reservation_object Rob Herring
[not found] ` <20190201005057.13648-6-robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2019-02-01 17:13 ` Eric Anholt
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=20190201172131.GD3271@phenom.ffwll.local \
--to=daniel-/w4ywyx8dfk@public.gmane.org \
--cc=airlied-cv59FeDIM0c@public.gmane.org \
--cc=christian.gmeiner-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
--cc=dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org \
--cc=eric-WhKQ6XTQaPysTnJN9+BGXg@public.gmane.org \
--cc=etnaviv-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org \
--cc=freedreno-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org \
--cc=l.stach-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org \
--cc=linux+etnaviv-I+IVW8TIWO2tmTQ+vhA3Yw@public.gmane.org \
--cc=linux-arm-msm-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=maarten.lankhorst-VuQAYsv1563Yd54FQh9/CA@public.gmane.org \
--cc=maxime.ripard-LDxbnhwyfcJBDgjK7y7TUQ@public.gmane.org \
--cc=robdclark-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
--cc=robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
--cc=sean-p7yTbzM4H96eqtR555YLDQ@public.gmane.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.