Skip to contentSkip to conversation

fdinfo fixes

PATCH Applied Tvrtko Ursulin 3 participants 7 messages Oct 24, 2024 – Oct 29, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover fdinfo fixes

From: Tvrtko Ursulin <[email protected]>

I included two Teddy's patches which have been reviewed and acked and IMO makes sense to pull them in straight away.

Then patch three does what Christian suggested - stops reporting GWS, GDS, OA and DOORBELL TTM regions as 'CPU' memory.

Last patch is RFC in case there is value to expose the above mentioned as their own memory regions. Looks questionable since I only see all zeros so not much value for a lot of new text to parse?

$ cat /proc/1967/fdinfo/4
pos:  0
flags:  02100002
mnt_id: 24
ino:  1181
drm-driver: amdgpu
drm-client-id:  30
drm-pdev: 0000:04:00.0
pasid:  32785
drm-total-cpu:  0
drm-shared-cpu: 0
drm-active-cpu: 0
drm-resident-cpu: 0
drm-purgeable-cpu:  0
drm-total-gtt:  20 MiB
drm-shared-gtt: 0
drm-active-gtt: 0
drm-resident-gtt: 20 MiB
drm-purgeable-gtt:  0
drm-total-vram: 155068 KiB
drm-shared-vram:  13584 KiB
drm-active-vram:  0
drm-resident-vram:  155068 KiB
drm-purgeable-vram: 0
drm-total-gds:  0
drm-shared-gds: 0
drm-active-gds: 0
drm-resident-gds: 0
drm-purgeable-gds:  0
drm-total-gws:  0
drm-shared-gws: 0
drm-active-gws: 0
drm-resident-gws: 0
drm-purgeable-gws:  0
drm-total-oa: 0
drm-shared-oa:  0
drm-active-oa:  0
drm-resident-oa:  0
drm-purgeable-oa: 0
drm-total-doorbell: 0
drm-shared-doorbell:  0
drm-active-doorbell:  0
drm-resident-doorbell:  0
drm-purgeable-doorbell: 0
drm-memory-vram:  155068 KiB
drm-memory-gtt:   20480 KiB
drm-memory-cpu:   0 KiB
amd-evicted-vram: 0 KiB
amd-requested-vram: 155068 KiB
amd-requested-gtt:  20480 KiB
drm-engine-gfx: 19291217545 ns
Cc Christian König <[email protected]>
Cc Yunxiang Li <[email protected]>
Cc Alex Deucher <[email protected]>

Tvrtko Ursulin (2):
drm/amdgpu: Stop reporting special chip memory pools as CPU memory in
fdinfo
drm/amdgpu: Expose special on chip memory pools in fdinfo

Yunxiang Li (2):
drm/amdgpu: make drm-memory-* report resident memory drm/amdgpu: stop tracking visible memory stats

 drivers/gpu/drm/amd/amdgpu/amdgpu_fdinfo.c | 23 ++++++++++++---------
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 24 ++--------------------
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | 11 ----------
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h     | 11 +++++++++-
 4 files changed, 25 insertions(+), 44 deletions(-)
Signature · 1 line
2.46.0
#1 lore raw

PATCH 1/4 drm/amdgpu: make drm-memory-* report resident memory

From: Yunxiang Li <[email protected]>

The old behavior reports the resident memory usage for this key and the documentation say so as well. However this was accidentally changed to include buffers that was evicted.

Fixes a2529f67e2ed ("drm/amdgpu: Use drm_print_memory_stats helper from fdinfo")
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_fdinfo.c | 7 ++++---
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 1 -
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | 1 -
 3 files changed, 4 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_fdinfo.c +4 -3
index 00a4ab082459..8281dd45faaa 100644
@@ -33,6 +33,7 @@
 #include <drm/amdgpu_drm.h>
 #include <drm/drm_debugfs.h>
 #include <drm/drm_drv.h>
+#include <drm/drm_file.h>
 
 #include "amdgpu.h"
 #include "amdgpu_vm.h"
@@ -95,11 +96,11 @@ void amdgpu_show_fdinfo(struct drm_printer *p, struct drm_file *file)
 
 	/* Legacy amdgpu keys, alias to drm-resident-memory-: */
 	drm_printf(p, "drm-memory-vram:\t%llu KiB\n",
-		   stats[TTM_PL_VRAM].total/1024UL);
+		   stats[TTM_PL_VRAM].drm.resident/1024UL);
 	drm_printf(p, "drm-memory-gtt: \t%llu KiB\n",
-		   stats[TTM_PL_TT].total/1024UL);
+		   stats[TTM_PL_TT].drm.resident/1024UL);
 	drm_printf(p, "drm-memory-cpu: \t%llu KiB\n",
-		   stats[TTM_PL_SYSTEM].total/1024UL);
+		   stats[TTM_PL_SYSTEM].drm.resident/1024UL);
 
 	/* Amdgpu specific memory accounting keys: */
 	drm_printf(p, "amd-memory-visible-vram:\t%llu KiB\n",
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +0 -1
index 1e6a044e3143..d41686a8e5ec 100644
@@ -1224,7 +1224,6 @@ void amdgpu_bo_get_memory(struct amdgpu_bo *bo,
 
 	/* DRM stats common fields: */
 
-	stats[type].total += size;
 	if (drm_gem_object_is_shared_for_memory_stats(obj))
 		stats[type].drm.shared += size;
 	else
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +0 -1
index 7260349917ef..a5653f474f85 100644
@@ -142,7 +142,6 @@ struct amdgpu_bo_vm {
 struct amdgpu_mem_stats {
 	struct drm_memory_stats drm;
 
-	uint64_t total;
 	uint64_t visible;
 	uint64_t evicted;
 	uint64_t evicted_visible;
Signature · 1 line
2.46.0
#2 lore raw

PATCH 2/4 drm/amdgpu: stop tracking visible memory stats

In reply to Tvrtko Ursulin

From: Yunxiang Li <[email protected]>

Since on modern systems all of vram can be made visible anyways, to simplify the new implementation, drops tracking how much memory is visible for now. If this is really needed we can add it back on top of the new implementation, or just report all the BOs as visible.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_fdinfo.c |  6 ------
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 12 ++----------
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | 10 ----------
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h     | 11 ++++++++++-
 4 files changed, 12 insertions(+), 27 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_fdinfo.c +0 -6
index 8281dd45faaa..7a9573958d87 100644
@@ -103,16 +103,10 @@ void amdgpu_show_fdinfo(struct drm_printer *p, struct drm_file *file)
 		   stats[TTM_PL_SYSTEM].drm.resident/1024UL);
 
 	/* Amdgpu specific memory accounting keys: */
-	drm_printf(p, "amd-memory-visible-vram:\t%llu KiB\n",
-		   stats[TTM_PL_VRAM].visible/1024UL);
 	drm_printf(p, "amd-evicted-vram:\t%llu KiB\n",
 		   stats[TTM_PL_VRAM].evicted/1024UL);
-	drm_printf(p, "amd-evicted-visible-vram:\t%llu KiB\n",
-		   stats[TTM_PL_VRAM].evicted_visible/1024UL);
 	drm_printf(p, "amd-requested-vram:\t%llu KiB\n",
 		   stats[TTM_PL_VRAM].requested/1024UL);
-	drm_printf(p, "amd-requested-visible-vram:\t%llu KiB\n",
-		   stats[TTM_PL_VRAM].requested_visible/1024UL);
 	drm_printf(p, "amd-requested-gtt:\t%llu KiB\n",
 		   stats[TTM_PL_TT].requested/1024UL);
 
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +2 -10
index d41686a8e5ec..0d3fb6b4212e 100644
@@ -40,6 +40,7 @@
 #include "amdgpu_trace.h"
 #include "amdgpu_amdkfd.h"
 #include "amdgpu_vram_mgr.h"
+#include "amdgpu_vm.h"
 
 /**
  * DOC: amdgpu_object
@@ -1236,23 +1237,14 @@ void amdgpu_bo_get_memory(struct amdgpu_bo *bo,
 			stats[type].drm.active += size;
 		else if (bo->flags & AMDGPU_GEM_CREATE_DISCARDABLE)
 			stats[type].drm.purgeable += size;
-
-		if (type == TTM_PL_VRAM && amdgpu_res_cpu_visible(adev, res))
-			stats[type].visible += size;
 	}
 
 	/* amdgpu specific stats: */
 
 	if (bo->preferred_domains & AMDGPU_GEM_DOMAIN_VRAM) {
 		stats[TTM_PL_VRAM].requested += size;
-		if (bo->flags & AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED)
-			stats[TTM_PL_VRAM].requested_visible += size;
-
-		if (type != TTM_PL_VRAM) {
+		if (type != TTM_PL_VRAM)
 			stats[TTM_PL_VRAM].evicted += size;
-			if (bo->flags & AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED)
-				stats[TTM_PL_VRAM].evicted_visible += size;
-		}
 	} else if (bo->preferred_domains & AMDGPU_GEM_DOMAIN_GTT) {
 		stats[TTM_PL_TT].requested += size;
 	}
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +0 -10
index a5653f474f85..be6769852ece 100644
@@ -139,16 +139,6 @@ struct amdgpu_bo_vm {
 	struct amdgpu_vm_bo_base        entries[];
 };
 
-struct amdgpu_mem_stats {
-	struct drm_memory_stats drm;
-
-	uint64_t visible;
-	uint64_t evicted;
-	uint64_t evicted_visible;
-	uint64_t requested;
-	uint64_t requested_visible;
-};
-
 static inline struct amdgpu_bo *ttm_to_amdgpu_bo(struct ttm_buffer_object *tbo)
 {
 	return container_of(tbo, struct amdgpu_bo, tbo);
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +10 -1
index c5b41e3ed14f..5d119ac26c4f 100644
@@ -42,7 +42,6 @@ struct amdgpu_bo_va;
 struct amdgpu_job;
 struct amdgpu_bo_list_entry;
 struct amdgpu_bo_vm;
-struct amdgpu_mem_stats;
 
 /*
  * GPUVM handling
@@ -322,6 +321,16 @@ struct amdgpu_vm_fault_info {
 	unsigned int	vmhub;
 };
 
+struct amdgpu_mem_stats {
+	struct drm_memory_stats drm;
+
+	/* buffers that requested this placement */
+	uint64_t requested;
+	/* buffers that requested this placement
+	 * but are currently evicted */
+	uint64_t evicted;
+};
+
 struct amdgpu_vm {
 	/* tree of virtual addresses mapped */
 	struct rb_root_cached	va;
Signature · 1 line
2.46.0
#3 lore raw

PATCH 3/4 drm/amdgpu: Stop reporting special chip memory pools as CPU memory in fdinfo

In reply to Tvrtko Ursulin

From: Tvrtko Ursulin <[email protected]>

So far these specialized on chip memory pools were reported as system memory (aka 'cpu') which is not correct and misleading. Lets remove that and consider later making them visible as their own thing.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 11 -----------
 1 file changed, 11 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +0 -11
index 0d3fb6b4212e..b5f65ef1efcd 100644
@@ -1209,17 +1209,6 @@ void amdgpu_bo_get_memory(struct amdgpu_bo *bo,
 		type = res->mem_type;
 	}
 
-	/* Squash some into 'cpu' to keep the legacy userspace view. */
-	switch (type) {
-	case TTM_PL_VRAM:
-	case TTM_PL_TT:
-	case TTM_PL_SYSTEM:
-		break;
-	default:
-		type = TTM_PL_SYSTEM;
-		break;
-	}
-
 	if (drm_WARN_ON_ONCE(&adev->ddev, type >= sz))
 		return;
 
Signature · 1 line
2.46.0
#4 lore raw

RFC 4/4 drm/amdgpu: Expose special on chip memory pools in fdinfo

In reply to Tvrtko Ursulin

From: Tvrtko Ursulin <[email protected]>

In the past these specialized on chip memory pools were reported as system memory (aka 'cpu') which was not correct and misleading. That has since been removed so lets make them visible as their own respective memory regions.

Cc Christian König <[email protected]>
Cc Yunxiang Li <[email protected]>
Cc Alex Deucher <[email protected]>

---
It is easy to do but is it worth it I leave to AMD experts to decide.

I gave it a quick spin and have only seen all zeros when running a Steam game.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_fdinfo.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_fdinfo.c +9 -1
index 7a9573958d87..df2cf5c33925 100644
@@ -66,6 +66,10 @@ void amdgpu_show_fdinfo(struct drm_printer *p, struct drm_file *file)
 		[TTM_PL_VRAM] = "vram",
 		[TTM_PL_TT] = "gtt",
 		[TTM_PL_SYSTEM] = "cpu",
+		[AMDGPU_PL_GDS] = "gds",
+		[AMDGPU_PL_GWS] = "gws",
+		[AMDGPU_PL_OA] = "oa",
+		[AMDGPU_PL_DOORBELL] = "doorbell",
 	};
 	unsigned int hw_ip, i;
 	int ret;
@@ -87,12 +91,16 @@ void amdgpu_show_fdinfo(struct drm_printer *p, struct drm_file *file)
 
 	drm_printf(p, "pasid:\t%u\n", fpriv->vm.pasid);
 
-	for (i = 0; i < TTM_PL_PRIV; i++)
+	for (i = 0; i < ARRAY_SIZE(pl_name); i++) {
+		if (!pl_name[i])
+			continue;
+
 		drm_print_memory_stats(p,
 				       &stats[i].drm,
 				       DRM_GEM_OBJECT_RESIDENT |
 				       DRM_GEM_OBJECT_PURGEABLE,
 				       pl_name[i]);
+	}
 
 	/* Legacy amdgpu keys, alias to drm-resident-memory-: */
 	drm_printf(p, "drm-memory-vram:\t%llu KiB\n",
Signature · 1 line
2.46.0
maintainer
#5 lore raw

Re: [RFC 4/4] drm/amdgpu: Expose special on chip memory pools in fdinfo

Am 24.10.24 um 11:23 schrieb Tvrtko Ursulin:

Quoted 11 lines

From: Tvrtko Ursulin <[email protected]>

In the past these specialized on chip memory pools were reported as system memory (aka 'cpu') which was not correct and misleading. That has since been removed so lets make them visible as their own respective memory regions.

Cc Christian König <[email protected]>
Cc Yunxiang Li <[email protected]>
Cc Alex Deucher <[email protected]>

Of hand looks correct to me, feel free to add my Reviewed-by: Christian König <[email protected]>

Quoted 5 lines

---
It is easy to do but is it worth it I leave to AMD experts to decide.

I gave it a quick spin and have only seen all zeros when running a Steam game.

Usage depends on HW generation and use case. IIRC GDS is the most used, but only in some rare use cases.

The upcoming HW generations will depend quite a bit on doorbells.

Regards,
Christian.

Quoted 37 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_fdinfo.c | 10 +++++++++-
  1 file changed, 9 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_fdinfo.c +9 -1
index 7a9573958d87..df2cf5c33925 100644
@@ -66,6 +66,10 @@ void amdgpu_show_fdinfo(struct drm_printer *p, struct drm_file *file)
  		[TTM_PL_VRAM] = "vram",
  		[TTM_PL_TT] = "gtt",
  		[TTM_PL_SYSTEM] = "cpu",
+		[AMDGPU_PL_GDS] = "gds",
+		[AMDGPU_PL_GWS] = "gws",
+		[AMDGPU_PL_OA] = "oa",
+		[AMDGPU_PL_DOORBELL] = "doorbell",
  	};
  	unsigned int hw_ip, i;
  	int ret;
@@ -87,12 +91,16 @@ void amdgpu_show_fdinfo(struct drm_printer *p, struct drm_file *file)
 
  	drm_printf(p, "pasid:\t%u\n", fpriv->vm.pasid);
 
-	for (i = 0; i < TTM_PL_PRIV; i++)
+	for (i = 0; i < ARRAY_SIZE(pl_name); i++) {
+		if (!pl_name[i])
+			continue;
+
  		drm_print_memory_stats(p,
  				       &stats[i].drm,
  				       DRM_GEM_OBJECT_RESIDENT |
  				       DRM_GEM_OBJECT_PURGEABLE,
  				       pl_name[i]);
+	}
 
  	/* Legacy amdgpu keys, alias to drm-resident-memory-: */
  	drm_printf(p, "drm-memory-vram:\t%llu KiB\n",
Applied
#6 lore raw

Re: [RFC 4/4] drm/amdgpu: Expose special on chip memory pools in fdinfo

Applied the series. Thanks!

Alex

Quoted 69 lines · Christian König

Am 24.10.24 um 11:23 schrieb Tvrtko Ursulin:

Quoted 11 lines

From: Tvrtko Ursulin <[email protected]>

In the past these specialized on chip memory pools were reported as system memory (aka 'cpu') which was not correct and misleading. That has since been removed so lets make them visible as their own respective memory regions.

Cc Christian König <[email protected]>
Cc Yunxiang Li <[email protected]>
Cc Alex Deucher <[email protected]>

Of hand looks correct to me, feel free to add my Reviewed-by: Christian König <[email protected]>

Quoted 5 lines

---
It is easy to do but is it worth it I leave to AMD experts to decide.

I gave it a quick spin and have only seen all zeros when running a Steam game.

Usage depends on HW generation and use case. IIRC GDS is the most used, but only in some rare use cases.

The upcoming HW generations will depend quite a bit on doorbells.

Regards,
Christian.

Quoted 37 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_fdinfo.c | 10 +++++++++-
  1 file changed, 9 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_fdinfo.c +9 -1
index 7a9573958d87..df2cf5c33925 100644
@@ -66,6 +66,10 @@ void amdgpu_show_fdinfo(struct drm_printer *p, struct drm_file *file)
              [TTM_PL_VRAM] = "vram",
              [TTM_PL_TT] = "gtt",
              [TTM_PL_SYSTEM] = "cpu",
+             [AMDGPU_PL_GDS] = "gds",
+             [AMDGPU_PL_GWS] = "gws",
+             [AMDGPU_PL_OA] = "oa",
+             [AMDGPU_PL_DOORBELL] = "doorbell",
      };
      unsigned int hw_ip, i;
      int ret;
@@ -87,12 +91,16 @@ void amdgpu_show_fdinfo(struct drm_printer *p, struct drm_file *file)
 
      drm_printf(p, "pasid:\t%u\n", fpriv->vm.pasid);
 
-     for (i = 0; i < TTM_PL_PRIV; i++)
+     for (i = 0; i < ARRAY_SIZE(pl_name); i++) {
+             if (!pl_name[i])
+                     continue;
+
              drm_print_memory_stats(p,
                                     &stats[i].drm,
                                     DRM_GEM_OBJECT_RESIDENT |
                                     DRM_GEM_OBJECT_PURGEABLE,
                                     pl_name[i]);
+     }
 
      /* Legacy amdgpu keys, alias to drm-resident-memory-: */
      drm_printf(p, "drm-memory-vram:\t%llu KiB\n",