[PATCH v10 4/6] drm: consider GEM object shared when it is exported
Yunxiang Li
Yunxiang.Li at amd.com
Tue Dec 10 17:59:37 UTC 2024
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.
Signed-off-by: Yunxiang Li <Yunxiang.Li at amd.com>
CC: dri-devel at 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
--
2.34.1
More information about the amd-gfx
mailing list