Skip to content

Commit 2a10f0b

Browse files
alexdeucherSasha Levin
authored andcommitted
drm/amdgpu: add shared fdinfo stats
[ Upstream commit ba1a58d ] 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> Reviewed-by: Christian König <christian.keonig@amd.com> Signed-off-by: Christian König <christian.koenig@amd.com> Stable-dep-of: a6ff969 ("drm/amdgpu: fix visible VRAM handling during faults") Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 73436e9 commit 2a10f0b

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

drivers/gpu/drm/amd/amdgpu/amdgpu_fdinfo.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ void amdgpu_show_fdinfo(struct drm_printer *p, struct drm_file *file)
9797
stats.requested_visible_vram/1024UL);
9898
drm_printf(p, "amd-requested-gtt:\t%llu KiB\n",
9999
stats.requested_gtt/1024UL);
100+
drm_printf(p, "drm-shared-vram:\t%llu KiB\n", stats.vram_shared/1024UL);
101+
drm_printf(p, "drm-shared-gtt:\t%llu KiB\n", stats.gtt_shared/1024UL);
102+
drm_printf(p, "drm-shared-cpu:\t%llu KiB\n", stats.cpu_shared/1024UL);
103+
100104
for (hw_ip = 0; hw_ip < AMDGPU_HW_IP_NUM; ++hw_ip) {
101105
if (!usage[hw_ip])
102106
continue;

drivers/gpu/drm/amd/amdgpu/amdgpu_object.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1276,25 +1276,36 @@ void amdgpu_bo_get_memory(struct amdgpu_bo *bo,
12761276
struct amdgpu_mem_stats *stats)
12771277
{
12781278
uint64_t size = amdgpu_bo_size(bo);
1279+
struct drm_gem_object *obj;
12791280
unsigned int domain;
1281+
bool shared;
12801282

12811283
/* Abort if the BO doesn't currently have a backing store */
12821284
if (!bo->tbo.resource)
12831285
return;
12841286

1287+
obj = &bo->tbo.base;
1288+
shared = drm_gem_object_is_shared_for_memory_stats(obj);
1289+
12851290
domain = amdgpu_mem_type_to_domain(bo->tbo.resource->mem_type);
12861291
switch (domain) {
12871292
case AMDGPU_GEM_DOMAIN_VRAM:
12881293
stats->vram += size;
12891294
if (amdgpu_bo_in_cpu_visible_vram(bo))
12901295
stats->visible_vram += size;
1296+
if (shared)
1297+
stats->vram_shared += size;
12911298
break;
12921299
case AMDGPU_GEM_DOMAIN_GTT:
12931300
stats->gtt += size;
1301+
if (shared)
1302+
stats->gtt_shared += size;
12941303
break;
12951304
case AMDGPU_GEM_DOMAIN_CPU:
12961305
default:
12971306
stats->cpu += size;
1307+
if (shared)
1308+
stats->cpu_shared += size;
12981309
break;
12991310
}
13001311

drivers/gpu/drm/amd/amdgpu/amdgpu_object.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,18 @@ struct amdgpu_bo_vm {
138138
struct amdgpu_mem_stats {
139139
/* current VRAM usage, includes visible VRAM */
140140
uint64_t vram;
141+
/* current shared VRAM usage, includes visible VRAM */
142+
uint64_t vram_shared;
141143
/* current visible VRAM usage */
142144
uint64_t visible_vram;
143145
/* current GTT usage */
144146
uint64_t gtt;
147+
/* current shared GTT usage */
148+
uint64_t gtt_shared;
145149
/* current system memory usage */
146150
uint64_t cpu;
151+
/* current shared system memory usage */
152+
uint64_t cpu_shared;
147153
/* sum of evicted buffers, includes visible VRAM */
148154
uint64_t evicted_vram;
149155
/* sum of evicted buffers due to CPU access */

0 commit comments

Comments
 (0)