All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Christian König" <christian.koenig@amd.com>
To: Yunxiang Li <Yunxiang.Li@amd.com>,
	amd-gfx@lists.freedesktop.org, tvrtko.ursulin@igalia.com
Cc: Alexander.Deucher@amd.com, dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v10 4/6] drm: consider GEM object shared when it is exported
Date: Wed, 11 Dec 2024 09:15:56 +0100	[thread overview]
Message-ID: <674b6d62-2274-4b0d-8d27-382faad5de88@amd.com> (raw)
In-Reply-To: <20241210175939.2498-5-Yunxiang.Li@amd.com>

Am 10.12.24 um 18:59 schrieb Yunxiang Li:
> Tracking the state of a GEM object for shared stats is quite difficult
> since the handle_count is managed behind driver's back. So instead
> considers GEM object shared the moment it is exported with flink ioctl.
> This makes it work the same to the dma_buf case. Add a callback for
> drivers to get notified when GEM object is being shared.

First of all GEM flink is pretty much deprecated, we only have it for 
compatibility reasons. So please don't change anything here.

Then flink is not the only way to create multiple handles for a GEM 
object. So this here won't handle all cases.

And finally we already have the .open and .close callbacks, which are 
called whenever a handle for a GEM object is created/destroyed. So it 
shouldn't be necessary in the first place.

Regards,
Christian.

>
> Signed-off-by: Yunxiang Li <Yunxiang.Li@amd.com>
>
> CC: dri-devel@lists.freedesktop.org
> ---
>   drivers/gpu/drm/drm_gem.c   |  3 +++
>   drivers/gpu/drm/drm_prime.c |  3 +++
>   include/drm/drm_gem.h       | 12 +++++++++++-
>   3 files changed, 17 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c
> index d4bbc5d109c8b..1ead11de31f6b 100644
> --- a/drivers/gpu/drm/drm_gem.c
> +++ b/drivers/gpu/drm/drm_gem.c
> @@ -854,6 +854,9 @@ drm_gem_flink_ioctl(struct drm_device *dev, void *data,
>   			goto err;
>   
>   		obj->name = ret;
> +
> +		if (obj->funcs->shared)
> +			obj->funcs->shared(obj);
>   	}
>   
>   	args->name = (uint64_t) obj->name;
> diff --git a/drivers/gpu/drm/drm_prime.c b/drivers/gpu/drm/drm_prime.c
> index 0e3f8adf162f6..336d982d69807 100644
> --- a/drivers/gpu/drm/drm_prime.c
> +++ b/drivers/gpu/drm/drm_prime.c
> @@ -406,6 +406,9 @@ static struct dma_buf *export_and_register_object(struct drm_device *dev,
>   	obj->dma_buf = dmabuf;
>   	get_dma_buf(obj->dma_buf);
>   
> +	if (obj->funcs->shared)
> +		obj->funcs->shared(obj);
> +
>   	return dmabuf;
>   }
>   
> diff --git a/include/drm/drm_gem.h b/include/drm/drm_gem.h
> index da11c16e212aa..8c5ffcd485752 100644
> --- a/include/drm/drm_gem.h
> +++ b/include/drm/drm_gem.h
> @@ -122,6 +122,16 @@ struct drm_gem_object_funcs {
>   	 */
>   	struct dma_buf *(*export)(struct drm_gem_object *obj, int flags);
>   
> +	/**
> +	 * @shared:
> +	 *
> +	 * Callback when GEM object becomes shared, see also
> +	 * drm_gem_object_is_shared_for_memory_stats
> +	 *
> +	 * This callback is optional.
> +	 */
> +	void (*shared)(struct drm_gem_object *obj);
> +
>   	/**
>   	 * @pin:
>   	 *
> @@ -568,7 +578,7 @@ int drm_gem_evict(struct drm_gem_object *obj);
>    */
>   static inline bool drm_gem_object_is_shared_for_memory_stats(struct drm_gem_object *obj)
>   {
> -	return (obj->handle_count > 1) || obj->dma_buf;
> +	return obj->name || obj->dma_buf;
>   }
>   
>   #ifdef CONFIG_LOCKDEP


  reply	other threads:[~2024-12-11  8:16 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-10 17:59 [PATCH v10 0/6] rework bo mem stats tracking Yunxiang Li
2024-12-10 17:59 ` [PATCH v10 1/6] drm: add drm_memory_stats_is_zero Yunxiang Li
2024-12-10 17:59 ` [PATCH v10 2/6] drm: make drm-active- stats optional Yunxiang Li
2024-12-10 17:59 ` [PATCH v10 3/6] Documentation/gpu: Clarify drm memory stats definition Yunxiang Li
2024-12-10 17:59 ` [PATCH v10 4/6] drm: consider GEM object shared when it is exported Yunxiang Li
2024-12-11  8:15   ` Christian König [this message]
2024-12-11 14:02     ` Li, Yunxiang (Teddy)
2024-12-11 15:02       ` Christian König
2024-12-11 16:14         ` Li, Yunxiang (Teddy)
2024-12-12  9:25           ` Christian König
2024-12-12 14:04             ` Li, Yunxiang (Teddy)
2024-12-12 14:08               ` Christian König
2024-12-10 17:59 ` [PATCH v10 5/6] drm/amdgpu: remove unused function parameter Yunxiang Li
2024-12-10 17:59 ` [PATCH v10 6/6] drm/amdgpu: track bo memory stats at runtime Yunxiang Li

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=674b6d62-2274-4b0d-8d27-382faad5de88@amd.com \
    --to=christian.koenig@amd.com \
    --cc=Alexander.Deucher@amd.com \
    --cc=Yunxiang.Li@amd.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=tvrtko.ursulin@igalia.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.