diff mbox series

[RFC,4/8] drm: start using drm_gem_trace_gpu_mem_total

Message ID 20211021031027.537-5-gurchetansingh@chromium.org (mailing list archive)
State New, archived
Headers show
Series GPU memory tracepoints | expand

Commit Message

Gurchetan Singh Oct. 21, 2021, 3:10 a.m. UTC
- drm_gem_private_object_init(..) increases the total memory
  counter.

  * All GEM objects (whether allocated or imported) seem to begin
    there.
  * If there's a better place/method, please do let
    me know.

- drm_gem_object_free(..) decreases the total memory counter.

Signed-off-by: Gurchetan Singh <gurchetansingh@chromium.org>
---
 drivers/gpu/drm/drm_gem.c | 5 +++++
 1 file changed, 5 insertions(+)

Comments

Steven Rostedt Oct. 21, 2021, 3:49 a.m. UTC | #1
On Wed, 20 Oct 2021 20:10:23 -0700
Gurchetan Singh <gurchetansingh@chromium.org> wrote:

> - drm_gem_private_object_init(..) increases the total memory
>   counter.
> 
>   * All GEM objects (whether allocated or imported) seem to begin
>     there.
>   * If there's a better place/method, please do let
>     me know.
> 
> - drm_gem_object_free(..) decreases the total memory counter.
> 
> Signed-off-by: Gurchetan Singh <gurchetansingh@chromium.org>
> ---
>  drivers/gpu/drm/drm_gem.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c
> index 24a719b79400..528d7b29dccf 100644
> --- a/drivers/gpu/drm/drm_gem.c
> +++ b/drivers/gpu/drm/drm_gem.c
> @@ -213,6 +213,7 @@ void drm_gem_private_object_init(struct drm_device *dev,
>  		obj->resv = &obj->_resv;
>  
>  	drm_vma_node_reset(&obj->vma_node);

To save yourself a function call when tracing is disabled, you can add:

	if (trace_gpu_mem_total_enabled())

here, which is a static_branch (meaning it's not a compare and branch,
but a nop when tracing is disabled, and a jmp (to the if block) when
the event is enabled).

> +	drm_gem_trace_gpu_mem_total(dev, obj->size, false);
>  }
>  EXPORT_SYMBOL(drm_gem_private_object_init);
>  
> @@ -1015,6 +1016,10 @@ drm_gem_object_free(struct kref *kref)
>  	struct drm_gem_object *obj =
>  		container_of(kref, struct drm_gem_object, refcount);
>  
> +	struct drm_device *dev = obj->dev;
> +

Same here.

-- Steve

> +	drm_gem_trace_gpu_mem_total(dev, -obj->size, false);
> +
>  	if (WARN_ON(!obj->funcs->free))
>  		return;
>
diff mbox series

Patch

diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c
index 24a719b79400..528d7b29dccf 100644
--- a/drivers/gpu/drm/drm_gem.c
+++ b/drivers/gpu/drm/drm_gem.c
@@ -213,6 +213,7 @@  void drm_gem_private_object_init(struct drm_device *dev,
 		obj->resv = &obj->_resv;
 
 	drm_vma_node_reset(&obj->vma_node);
+	drm_gem_trace_gpu_mem_total(dev, obj->size, false);
 }
 EXPORT_SYMBOL(drm_gem_private_object_init);
 
@@ -1015,6 +1016,10 @@  drm_gem_object_free(struct kref *kref)
 	struct drm_gem_object *obj =
 		container_of(kref, struct drm_gem_object, refcount);
 
+	struct drm_device *dev = obj->dev;
+
+	drm_gem_trace_gpu_mem_total(dev, -obj->size, false);
+
 	if (WARN_ON(!obj->funcs->free))
 		return;