[PATCH 2/6] drm: add drm_gem_object_is_shared_for_memory_stats() helper
Hamza Mahfooz
hamza.mahfooz at amd.com
Tue Jan 30 17:11:08 UTC 2024
On 1/30/24 11:12, Alex Deucher wrote:
> Add a helper so that drm drivers can consistently report
> shared status via the fdinfo shared memory stats interface.
>
> In addition to handle count, show buffers as shared if they
> are shared via dma-buf as well (e.g., shared with v4l or some
> other subsystem).
>
> Link: https://lore.kernel.org/all/20231207180225.439482-1-alexander.deucher@amd.com/
> Signed-off-by: Alex Deucher <alexander.deucher at amd.com>
> ---
> drivers/gpu/drm/drm_gem.c | 16 ++++++++++++++++
> include/drm/drm_gem.h | 1 +
> 2 files changed, 17 insertions(+)
>
> diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c
> index 44a948b80ee1..71b5f628d828 100644
> --- a/drivers/gpu/drm/drm_gem.c
> +++ b/drivers/gpu/drm/drm_gem.c
> @@ -1506,3 +1506,19 @@ int drm_gem_evict(struct drm_gem_object *obj)
> return 0;
> }
> EXPORT_SYMBOL(drm_gem_evict);
> +
> +/**
> + * drm_gem_object_is_shared_for_memory_stats - helper for shared memory stats
> + *
> + * This helper should only be used for fdinfo shared memory stats to determine
> + * if a GEM object is shared.
> + *
> + * @obj: obj in question
> + */
> +bool drm_gem_object_is_shared_for_memory_stats(struct drm_gem_object *obj)
> +{
> + if ((obj->handle_count > 1) || obj->dma_buf)
> + return true;
> + return false;
nit: you can simplify this to:
return (obj->handle_count > 1) || obj->dma_buf;
(It maybe worth just inlining this to drm_gem.h).
> +}
> +EXPORT_SYMBOL(drm_gem_object_is_shared_for_memory_stats);
> diff --git a/include/drm/drm_gem.h b/include/drm/drm_gem.h
> index 369505447acd..86a9c696f038 100644
> --- a/include/drm/drm_gem.h
> +++ b/include/drm/drm_gem.h
> @@ -552,6 +552,7 @@ unsigned long drm_gem_lru_scan(struct drm_gem_lru *lru,
> bool (*shrink)(struct drm_gem_object *obj));
>
> int drm_gem_evict(struct drm_gem_object *obj);
> +bool drm_gem_object_is_shared_for_memory_stats(struct drm_gem_object *obj);
>
> #ifdef CONFIG_LOCKDEP
> /**
--
Hamza
More information about the dri-devel
mailing list