All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alex Deucher <alexander.deucher@amd.com>
To: <amd-gfx@lists.freedesktop.org>,
	<dri-devel@lists.freedesktop.org>,
	<intel-gfx@lists.freedesktop.org>,
	<intel-xe@lists.freedesktop.org>,
	<tvrtko.ursulin@linux.intel.com>, <daniel@ffwll.ch>
Cc: Alex Deucher <alexander.deucher@amd.com>,
	Rob Clark <robdclark@gmail.com>
Subject: [PATCH 4/6] drm/amdgpu: add shared fdinfo stats
Date: Mon, 12 Feb 2024 16:04:26 -0500	[thread overview]
Message-ID: <20240212210428.851952-5-alexander.deucher@amd.com> (raw)
In-Reply-To: <20240212210428.851952-1-alexander.deucher@amd.com>

Add shared stats.  Useful for seeing shared memory.

v2: take dma-buf into account as well
v3: use the new gem helper

Link: https://lore.kernel.org/all/20231207180225.439482-1-alexander.deucher@amd.com/
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Cc: Rob Clark <robdclark@gmail.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_fdinfo.c |  4 ++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 11 +++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.h |  6 ++++++
 3 files changed, 21 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_fdinfo.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_fdinfo.c
index 5706b282a0c7..c7df7fa3459f 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_fdinfo.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_fdinfo.c
@@ -97,6 +97,10 @@ void amdgpu_show_fdinfo(struct drm_printer *p, struct drm_file *file)
 		   stats.requested_visible_vram/1024UL);
 	drm_printf(p, "amd-requested-gtt:\t%llu KiB\n",
 		   stats.requested_gtt/1024UL);
+	drm_printf(p, "drm-shared-vram:\t%llu KiB\n", stats.vram_shared/1024UL);
+	drm_printf(p, "drm-shared-gtt:\t%llu KiB\n", stats.gtt_shared/1024UL);
+	drm_printf(p, "drm-shared-cpu:\t%llu KiB\n", stats.cpu_shared/1024UL);
+
 	for (hw_ip = 0; hw_ip < AMDGPU_HW_IP_NUM; ++hw_ip) {
 		if (!usage[hw_ip])
 			continue;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
index 425cebcc5cbf..e6f69fce539b 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
@@ -1276,25 +1276,36 @@ void amdgpu_bo_get_memory(struct amdgpu_bo *bo,
 			  struct amdgpu_mem_stats *stats)
 {
 	uint64_t size = amdgpu_bo_size(bo);
+	struct drm_gem_object *obj;
 	unsigned int domain;
+	bool shared;
 
 	/* Abort if the BO doesn't currently have a backing store */
 	if (!bo->tbo.resource)
 		return;
 
+	obj = &bo->tbo.base;
+	shared = drm_gem_object_is_shared_for_memory_stats(obj);
+
 	domain = amdgpu_mem_type_to_domain(bo->tbo.resource->mem_type);
 	switch (domain) {
 	case AMDGPU_GEM_DOMAIN_VRAM:
 		stats->vram += size;
 		if (amdgpu_bo_in_cpu_visible_vram(bo))
 			stats->visible_vram += size;
+		if (shared)
+			stats->vram_shared += size;
 		break;
 	case AMDGPU_GEM_DOMAIN_GTT:
 		stats->gtt += size;
+		if (shared)
+			stats->gtt_shared += size;
 		break;
 	case AMDGPU_GEM_DOMAIN_CPU:
 	default:
 		stats->cpu += size;
+		if (shared)
+			stats->cpu_shared += size;
 		break;
 	}
 
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
index a3ea8a82db23..be679c42b0b8 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
@@ -138,12 +138,18 @@ struct amdgpu_bo_vm {
 struct amdgpu_mem_stats {
 	/* current VRAM usage, includes visible VRAM */
 	uint64_t vram;
+	/* current shared VRAM usage, includes visible VRAM */
+	uint64_t vram_shared;
 	/* current visible VRAM usage */
 	uint64_t visible_vram;
 	/* current GTT usage */
 	uint64_t gtt;
+	/* current shared GTT usage */
+	uint64_t gtt_shared;
 	/* current system memory usage */
 	uint64_t cpu;
+	/* current shared system memory usage */
+	uint64_t cpu_shared;
 	/* sum of evicted buffers, includes visible VRAM */
 	uint64_t evicted_vram;
 	/* sum of evicted buffers due to CPU access */
-- 
2.42.0


  parent reply	other threads:[~2024-02-12 21:05 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-12 21:04 [PATCH 0/6 V4] fdinfo shared stats Alex Deucher
2024-02-12 21:04 ` [PATCH 1/6] Documentation/gpu: Update documentation on drm-shared-* Alex Deucher
2024-02-12 21:04 ` [PATCH 2/6] drm: add drm_gem_object_is_shared_for_memory_stats() helper Alex Deucher
2024-02-12 21:04 ` [PATCH 3/6] drm: update drm_show_memory_stats() for dma-bufs Alex Deucher
2024-02-12 21:04 ` Alex Deucher [this message]
2024-02-12 21:04 ` [PATCH 5/6] drm/i915: Update shared stats to use the new gem helper Alex Deucher
2024-02-12 21:04 ` [PATCH 6/6] drm/xe: " Alex Deucher
2024-02-12 23:57 ` ✗ Fi.CI.CHECKPATCH: warning for fdinfo shared stats (rev3) Patchwork
2024-02-12 23:57 ` ✗ Fi.CI.SPARSE: " Patchwork
2024-02-13  0:15 ` ✓ Fi.CI.BAT: success " Patchwork
2024-02-13  3:52 ` ✗ Fi.CI.IGT: failure " Patchwork
2024-02-13  5:29 ` ✓ CI.Patch_applied: success " Patchwork
2024-02-13  5:29 ` ✗ CI.checkpatch: warning " Patchwork
2024-02-13  5:30 ` ✓ CI.KUnit: success " Patchwork
2024-02-13  5:40 ` ✓ CI.Build: " Patchwork
2024-02-13  5:41 ` ✓ CI.Hooks: " Patchwork
2024-02-13  5:42 ` ✗ CI.checksparse: warning " Patchwork
2024-02-13  6:18 ` ✓ CI.BAT: success " Patchwork
2024-02-15 14:12 ` [PATCH 0/6 V4] fdinfo shared stats Christian König
2024-02-15 14:20   ` Alex Deucher
2024-02-16 12:45     ` Christian König
  -- strict thread matches above, loose matches on Subject: below --
2024-01-30 16:12 [PATCH 0/6 V3] " Alex Deucher
2024-01-30 16:12 ` [PATCH 4/6] drm/amdgpu: add shared fdinfo stats Alex Deucher
2024-01-30 16:12   ` Alex Deucher

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240212210428.851952-5-alexander.deucher@amd.com \
    --to=alexander.deucher@amd.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=robdclark@gmail.com \
    --cc=tvrtko.ursulin@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.