Commit ba1a58d5 authored by Alex Deucher's avatar Alex Deucher Committed by Christian König

drm/amdgpu: add shared fdinfo stats

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: default avatarAlex Deucher <alexander.deucher@amd.com>
Cc: Rob Clark <robdclark@gmail.com>
Reviewed-by: default avatarChristian König <christian.keonig@amd.com>
Signed-off-by: default avatarChristian König <christian.koenig@amd.com>
parent d50ea100
...@@ -97,6 +97,10 @@ void amdgpu_show_fdinfo(struct drm_printer *p, struct drm_file *file) ...@@ -97,6 +97,10 @@ void amdgpu_show_fdinfo(struct drm_printer *p, struct drm_file *file)
stats.requested_visible_vram/1024UL); stats.requested_visible_vram/1024UL);
drm_printf(p, "amd-requested-gtt:\t%llu KiB\n", drm_printf(p, "amd-requested-gtt:\t%llu KiB\n",
stats.requested_gtt/1024UL); 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) { for (hw_ip = 0; hw_ip < AMDGPU_HW_IP_NUM; ++hw_ip) {
if (!usage[hw_ip]) if (!usage[hw_ip])
continue; continue;
......
...@@ -1273,25 +1273,36 @@ void amdgpu_bo_get_memory(struct amdgpu_bo *bo, ...@@ -1273,25 +1273,36 @@ void amdgpu_bo_get_memory(struct amdgpu_bo *bo,
struct amdgpu_mem_stats *stats) struct amdgpu_mem_stats *stats)
{ {
uint64_t size = amdgpu_bo_size(bo); uint64_t size = amdgpu_bo_size(bo);
struct drm_gem_object *obj;
unsigned int domain; unsigned int domain;
bool shared;
/* Abort if the BO doesn't currently have a backing store */ /* Abort if the BO doesn't currently have a backing store */
if (!bo->tbo.resource) if (!bo->tbo.resource)
return; 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); domain = amdgpu_mem_type_to_domain(bo->tbo.resource->mem_type);
switch (domain) { switch (domain) {
case AMDGPU_GEM_DOMAIN_VRAM: case AMDGPU_GEM_DOMAIN_VRAM:
stats->vram += size; stats->vram += size;
if (amdgpu_bo_in_cpu_visible_vram(bo)) if (amdgpu_bo_in_cpu_visible_vram(bo))
stats->visible_vram += size; stats->visible_vram += size;
if (shared)
stats->vram_shared += size;
break; break;
case AMDGPU_GEM_DOMAIN_GTT: case AMDGPU_GEM_DOMAIN_GTT:
stats->gtt += size; stats->gtt += size;
if (shared)
stats->gtt_shared += size;
break; break;
case AMDGPU_GEM_DOMAIN_CPU: case AMDGPU_GEM_DOMAIN_CPU:
default: default:
stats->cpu += size; stats->cpu += size;
if (shared)
stats->cpu_shared += size;
break; break;
} }
......
...@@ -138,12 +138,18 @@ struct amdgpu_bo_vm { ...@@ -138,12 +138,18 @@ struct amdgpu_bo_vm {
struct amdgpu_mem_stats { struct amdgpu_mem_stats {
/* current VRAM usage, includes visible VRAM */ /* current VRAM usage, includes visible VRAM */
uint64_t vram; uint64_t vram;
/* current shared VRAM usage, includes visible VRAM */
uint64_t vram_shared;
/* current visible VRAM usage */ /* current visible VRAM usage */
uint64_t visible_vram; uint64_t visible_vram;
/* current GTT usage */ /* current GTT usage */
uint64_t gtt; uint64_t gtt;
/* current shared GTT usage */
uint64_t gtt_shared;
/* current system memory usage */ /* current system memory usage */
uint64_t cpu; uint64_t cpu;
/* current shared system memory usage */
uint64_t cpu_shared;
/* sum of evicted buffers, includes visible VRAM */ /* sum of evicted buffers, includes visible VRAM */
uint64_t evicted_vram; uint64_t evicted_vram;
/* sum of evicted buffers due to CPU access */ /* sum of evicted buffers due to CPU access */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment