diff mbox series

drm/v3d: Expose memory stats through fdinfo

Message ID 20240711142736.783816-1-mcanal@igalia.com (mailing list archive)
State New, archived
Headers show
Series drm/v3d: Expose memory stats through fdinfo | expand

Commit Message

Maíra Canal July 11, 2024, 2:25 p.m. UTC
Use the common DRM function `drm_show_memory_stats()` to expose standard
fdinfo memory stats.

V3D exposes global GPU memory stats through debugfs. Those stats will be
preserved while the DRM subsystem doesn't have a standard solution to
expose global GPU stats.

Signed-off-by: Maíra Canal <mcanal@igalia.com>
---

* Example fdinfo output:

$ cat /proc/10100/fdinfo/19
pos:    0
flags:  02400002
mnt_id: 25
ino:    521
drm-driver:     v3d
drm-client-id:  81
drm-engine-bin:         4916187 ns
v3d-jobs-bin:   98 jobs
drm-engine-render:      154563573 ns
v3d-jobs-render:        98 jobs
drm-engine-tfu:         10574 ns
v3d-jobs-tfu:   1 jobs
drm-engine-csd:         0 ns
v3d-jobs-csd:   0 jobs
drm-engine-cache_clean:         0 ns
v3d-jobs-cache_clean:   0 jobs
drm-engine-cpu:         0 ns
v3d-jobs-cpu:   0 jobs
drm-total-memory:       15168 KiB
drm-shared-memory:      9336 KiB
drm-active-memory:      0

* Example gputop output:

DRM minor 128
  PID      MEM      RSS       bin          render           tfu            csd        cache_clean        cpu       NAME
10257      19M      19M |  3.6% ▎     || 43.2% ██▋   ||  0.0%       ||  0.0%       ||  0.0%       ||  0.0%       | glmark2
 9963       3M       3M |  0.3% ▏     ||  2.6% ▎     ||  0.0%       ||  0.0%       ||  0.0%       ||  0.0%       | glxgears
 9965      10M      10M |  0.0%       ||  0.0%       ||  0.0%       ||  0.0%       ||  0.0%       ||  0.0%       | Xwayland
10100      14M      14M |  0.0%       ||  0.0%       ||  0.0%       ||  0.0%       ||  0.0%       ||  0.0%       | chromium-browse

Best Regards,
- Maíra

 drivers/gpu/drm/v3d/v3d_bo.c  | 12 ++++++++++++
 drivers/gpu/drm/v3d/v3d_drv.c |  2 ++
 2 files changed, 14 insertions(+)

Comments

Tvrtko Ursulin July 11, 2024, 5:34 p.m. UTC | #1
On 11/07/2024 15:25, Maíra Canal wrote:
> Use the common DRM function `drm_show_memory_stats()` to expose standard
> fdinfo memory stats.
> 
> V3D exposes global GPU memory stats through debugfs. Those stats will be
> preserved while the DRM subsystem doesn't have a standard solution to
> expose global GPU stats.
> 
> Signed-off-by: Maíra Canal <mcanal@igalia.com>
> ---
> 
> * Example fdinfo output:
> 
> $ cat /proc/10100/fdinfo/19
> pos:    0
> flags:  02400002
> mnt_id: 25
> ino:    521
> drm-driver:     v3d
> drm-client-id:  81
> drm-engine-bin:         4916187 ns
> v3d-jobs-bin:   98 jobs
> drm-engine-render:      154563573 ns
> v3d-jobs-render:        98 jobs
> drm-engine-tfu:         10574 ns
> v3d-jobs-tfu:   1 jobs
> drm-engine-csd:         0 ns
> v3d-jobs-csd:   0 jobs
> drm-engine-cache_clean:         0 ns
> v3d-jobs-cache_clean:   0 jobs
> drm-engine-cpu:         0 ns
> v3d-jobs-cpu:   0 jobs
> drm-total-memory:       15168 KiB
> drm-shared-memory:      9336 KiB
> drm-active-memory:      0
> 
> * Example gputop output:
> 
> DRM minor 128
>    PID      MEM      RSS       bin          render           tfu            csd        cache_clean        cpu       NAME
> 10257      19M      19M |  3.6% ▎     || 43.2% ██▋   ||  0.0%       ||  0.0%       ||  0.0%       ||  0.0%       | glmark2
>   9963       3M       3M |  0.3% ▏     ||  2.6% ▎     ||  0.0%       ||  0.0%       ||  0.0%       ||  0.0%       | glxgears
>   9965      10M      10M |  0.0%       ||  0.0%       ||  0.0%       ||  0.0%       ||  0.0%       ||  0.0%       | Xwayland
> 10100      14M      14M |  0.0%       ||  0.0%       ||  0.0%       ||  0.0%       ||  0.0%       ||  0.0%       | chromium-browse
> 
> Best Regards,
> - Maíra
> 
>   drivers/gpu/drm/v3d/v3d_bo.c  | 12 ++++++++++++
>   drivers/gpu/drm/v3d/v3d_drv.c |  2 ++
>   2 files changed, 14 insertions(+)
> 
> diff --git a/drivers/gpu/drm/v3d/v3d_bo.c b/drivers/gpu/drm/v3d/v3d_bo.c
> index a165cbcdd27b..ecb80fd75b1a 100644
> --- a/drivers/gpu/drm/v3d/v3d_bo.c
> +++ b/drivers/gpu/drm/v3d/v3d_bo.c
> @@ -26,6 +26,17 @@
>   #include "v3d_drv.h"
>   #include "uapi/drm/v3d_drm.h"
>   
> +static enum drm_gem_object_status v3d_gem_status(struct drm_gem_object *obj)
> +{
> +	struct v3d_bo *bo = to_v3d_bo(obj);
> +	enum drm_gem_object_status res = 0;
> +
> +	if (bo->base.pages)
> +		res |= DRM_GEM_OBJECT_RESIDENT;

To check my understanding of v3d - pages are actually always there for 
the lifetime of the object? If so this could be just "return 
DRM_GEM_OBJECT_RESIDENT", although granted, like you have it is more 
future proof.

Either way:

Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@igalia.com>

Regards,

Tvrtko

> +
> +	return res;
> +}
> +
>   /* Called DRM core on the last userspace/kernel unreference of the
>    * BO.
>    */
> @@ -63,6 +74,7 @@ static const struct drm_gem_object_funcs v3d_gem_funcs = {
>   	.vmap = drm_gem_shmem_object_vmap,
>   	.vunmap = drm_gem_shmem_object_vunmap,
>   	.mmap = drm_gem_shmem_object_mmap,
> +	.status = v3d_gem_status,
>   	.vm_ops = &drm_gem_shmem_vm_ops,
>   };
>   
> diff --git a/drivers/gpu/drm/v3d/v3d_drv.c b/drivers/gpu/drm/v3d/v3d_drv.c
> index a47f00b443d3..e883f405f26a 100644
> --- a/drivers/gpu/drm/v3d/v3d_drv.c
> +++ b/drivers/gpu/drm/v3d/v3d_drv.c
> @@ -184,6 +184,8 @@ static void v3d_show_fdinfo(struct drm_printer *p, struct drm_file *file)
>   		drm_printf(p, "v3d-jobs-%s: \t%llu jobs\n",
>   			   v3d_queue_to_string(queue), jobs_completed);
>   	}
> +
> +	drm_show_memory_stats(p, file);
>   }
>   
>   static const struct file_operations v3d_drm_fops = {
Maíra Canal July 13, 2024, 2:57 p.m. UTC | #2
On 7/11/24 11:25, Maíra Canal wrote:
> Use the common DRM function `drm_show_memory_stats()` to expose standard
> fdinfo memory stats.
> 
> V3D exposes global GPU memory stats through debugfs. Those stats will be
> preserved while the DRM subsystem doesn't have a standard solution to
> expose global GPU stats.
> 
> Signed-off-by: Maíra Canal <mcanal@igalia.com>

Applied to drm-misc/drm-misc-next!

Best Regards,
- Maíra

> ---
> 
> * Example fdinfo output:
> 
> $ cat /proc/10100/fdinfo/19
> pos:    0
> flags:  02400002
> mnt_id: 25
> ino:    521
> drm-driver:     v3d
> drm-client-id:  81
> drm-engine-bin:         4916187 ns
> v3d-jobs-bin:   98 jobs
> drm-engine-render:      154563573 ns
> v3d-jobs-render:        98 jobs
> drm-engine-tfu:         10574 ns
> v3d-jobs-tfu:   1 jobs
> drm-engine-csd:         0 ns
> v3d-jobs-csd:   0 jobs
> drm-engine-cache_clean:         0 ns
> v3d-jobs-cache_clean:   0 jobs
> drm-engine-cpu:         0 ns
> v3d-jobs-cpu:   0 jobs
> drm-total-memory:       15168 KiB
> drm-shared-memory:      9336 KiB
> drm-active-memory:      0
> 
> * Example gputop output:
> 
> DRM minor 128
>    PID      MEM      RSS       bin          render           tfu            csd        cache_clean        cpu       NAME
> 10257      19M      19M |  3.6% ▎     || 43.2% ██▋   ||  0.0%       ||  0.0%       ||  0.0%       ||  0.0%       | glmark2
>   9963       3M       3M |  0.3% ▏     ||  2.6% ▎     ||  0.0%       ||  0.0%       ||  0.0%       ||  0.0%       | glxgears
>   9965      10M      10M |  0.0%       ||  0.0%       ||  0.0%       ||  0.0%       ||  0.0%       ||  0.0%       | Xwayland
> 10100      14M      14M |  0.0%       ||  0.0%       ||  0.0%       ||  0.0%       ||  0.0%       ||  0.0%       | chromium-browse
> 
> Best Regards,
> - Maíra
> 
>   drivers/gpu/drm/v3d/v3d_bo.c  | 12 ++++++++++++
>   drivers/gpu/drm/v3d/v3d_drv.c |  2 ++
>   2 files changed, 14 insertions(+)
> 
> diff --git a/drivers/gpu/drm/v3d/v3d_bo.c b/drivers/gpu/drm/v3d/v3d_bo.c
> index a165cbcdd27b..ecb80fd75b1a 100644
> --- a/drivers/gpu/drm/v3d/v3d_bo.c
> +++ b/drivers/gpu/drm/v3d/v3d_bo.c
> @@ -26,6 +26,17 @@
>   #include "v3d_drv.h"
>   #include "uapi/drm/v3d_drm.h"
>   
> +static enum drm_gem_object_status v3d_gem_status(struct drm_gem_object *obj)
> +{
> +	struct v3d_bo *bo = to_v3d_bo(obj);
> +	enum drm_gem_object_status res = 0;
> +
> +	if (bo->base.pages)
> +		res |= DRM_GEM_OBJECT_RESIDENT;
> +
> +	return res;
> +}
> +
>   /* Called DRM core on the last userspace/kernel unreference of the
>    * BO.
>    */
> @@ -63,6 +74,7 @@ static const struct drm_gem_object_funcs v3d_gem_funcs = {
>   	.vmap = drm_gem_shmem_object_vmap,
>   	.vunmap = drm_gem_shmem_object_vunmap,
>   	.mmap = drm_gem_shmem_object_mmap,
> +	.status = v3d_gem_status,
>   	.vm_ops = &drm_gem_shmem_vm_ops,
>   };
>   
> diff --git a/drivers/gpu/drm/v3d/v3d_drv.c b/drivers/gpu/drm/v3d/v3d_drv.c
> index a47f00b443d3..e883f405f26a 100644
> --- a/drivers/gpu/drm/v3d/v3d_drv.c
> +++ b/drivers/gpu/drm/v3d/v3d_drv.c
> @@ -184,6 +184,8 @@ static void v3d_show_fdinfo(struct drm_printer *p, struct drm_file *file)
>   		drm_printf(p, "v3d-jobs-%s: \t%llu jobs\n",
>   			   v3d_queue_to_string(queue), jobs_completed);
>   	}
> +
> +	drm_show_memory_stats(p, file);
>   }
>   
>   static const struct file_operations v3d_drm_fops = {
diff mbox series

Patch

diff --git a/drivers/gpu/drm/v3d/v3d_bo.c b/drivers/gpu/drm/v3d/v3d_bo.c
index a165cbcdd27b..ecb80fd75b1a 100644
--- a/drivers/gpu/drm/v3d/v3d_bo.c
+++ b/drivers/gpu/drm/v3d/v3d_bo.c
@@ -26,6 +26,17 @@ 
 #include "v3d_drv.h"
 #include "uapi/drm/v3d_drm.h"
 
+static enum drm_gem_object_status v3d_gem_status(struct drm_gem_object *obj)
+{
+	struct v3d_bo *bo = to_v3d_bo(obj);
+	enum drm_gem_object_status res = 0;
+
+	if (bo->base.pages)
+		res |= DRM_GEM_OBJECT_RESIDENT;
+
+	return res;
+}
+
 /* Called DRM core on the last userspace/kernel unreference of the
  * BO.
  */
@@ -63,6 +74,7 @@  static const struct drm_gem_object_funcs v3d_gem_funcs = {
 	.vmap = drm_gem_shmem_object_vmap,
 	.vunmap = drm_gem_shmem_object_vunmap,
 	.mmap = drm_gem_shmem_object_mmap,
+	.status = v3d_gem_status,
 	.vm_ops = &drm_gem_shmem_vm_ops,
 };
 
diff --git a/drivers/gpu/drm/v3d/v3d_drv.c b/drivers/gpu/drm/v3d/v3d_drv.c
index a47f00b443d3..e883f405f26a 100644
--- a/drivers/gpu/drm/v3d/v3d_drv.c
+++ b/drivers/gpu/drm/v3d/v3d_drv.c
@@ -184,6 +184,8 @@  static void v3d_show_fdinfo(struct drm_printer *p, struct drm_file *file)
 		drm_printf(p, "v3d-jobs-%s: \t%llu jobs\n",
 			   v3d_queue_to_string(queue), jobs_completed);
 	}
+
+	drm_show_memory_stats(p, file);
 }
 
 static const struct file_operations v3d_drm_fops = {