[RFC PATCH 7/8] drm: trace memory import per DRM file

Gurchetan Singh gurchetansingh at chromium.org
Thu Oct 21 03:10:26 UTC 2021


- drm_gem_prime_fd_to_handle increases the per-instance imported
  memory counter

- drm_gem_remove_prime_handles decreases the per-instance imported
  memory counter on non-fake imports.

Signed-off-by: Gurchetan Singh <gurchetansingh at chromium.org>
---
 drivers/gpu/drm/drm_gem.c   | 3 +++
 drivers/gpu/drm/drm_prime.c | 2 ++
 2 files changed, 5 insertions(+)

diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c
index 7637be0ceb74..c07568ea8442 100644
--- a/drivers/gpu/drm/drm_gem.c
+++ b/drivers/gpu/drm/drm_gem.c
@@ -231,6 +231,9 @@ drm_gem_remove_prime_handles(struct drm_gem_object *obj, struct drm_file *filp)
 		drm_prime_remove_buf_handle_locked(&filp->prime,
 						   obj->dma_buf,
 						   &removed_real_import);
+		if (removed_real_import)
+			drm_gem_trace_gpu_mem_instance(dev, filp, -obj->size,
+						       true);
 	}
 	mutex_unlock(&filp->prime.lock);
 }
diff --git a/drivers/gpu/drm/drm_prime.c b/drivers/gpu/drm/drm_prime.c
index 31f033ec8549..1afcae0c4038 100644
--- a/drivers/gpu/drm/drm_prime.c
+++ b/drivers/gpu/drm/drm_prime.c
@@ -349,6 +349,8 @@ int drm_gem_prime_fd_to_handle(struct drm_device *dev,
 
 	dma_buf_put(dma_buf);
 
+	drm_gem_trace_gpu_mem_instance(dev, file_priv, obj->size, true);
+
 	return 0;
 
 fail:
-- 
2.25.1



More information about the dri-devel mailing list