Skip to contentSkip to conversation

drm/v3d: Expose memory stats through fdinfo

PATCH Applied Maíra Canal 2 participants 3 messages Jul 11, 2024 – Jul 13, 2024

Subsystems (3)
lore
Share & tools
lore

Maíra Canal

author maintainer
#0 lore raw

PATCH 1/1 drm/v3d: Expose memory stats through fdinfo

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.

---

* 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(+)
drivers/gpu/drm/v3d/v3d_bo.c +12 -0
index a165cbcdd27b..ecb80fd75b1a 100644
@@ -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,
 };
 
drivers/gpu/drm/v3d/v3d_drv.c +2 -0
index a47f00b443d3..e883f405f26a 100644
@@ -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 = {
Signature · 1 line
2.45.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 56 lines · Maíra Canal

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.

---

* 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(+)
drivers/gpu/drm/v3d/v3d_bo.c +0 -0
index a165cbcdd27b..ecb80fd75b1a 100644

drivers/gpu/drm/v3d/v3d_bo.c line 35

Quoted 10 lines
drivers/gpu/drm/v3d/v3d_bo.c +7 -0
@@ -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:

Regards,

Tvrtko

Quoted 28 lines
drivers/gpu/drm/v3d/v3d_bo.c +5 -0
+
+	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,
  };
 
drivers/gpu/drm/v3d/v3d_drv.c +2 -0
index a47f00b443d3..e883f405f26a 100644
@@ -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 = {
author maintainer Applied
#2 lore raw
In reply to Maíra Canal
Quoted 8 lines · Maíra Canal

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.

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

Best Regards,
- Maíra

Quoted 86 lines

---

* 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(+)
drivers/gpu/drm/v3d/v3d_bo.c +12 -0
index a165cbcdd27b..ecb80fd75b1a 100644
@@ -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,
  };
 
drivers/gpu/drm/v3d/v3d_drv.c +2 -0
index a47f00b443d3..e883f405f26a 100644
@@ -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 = {