Skip to content

Commit a63f8c5

Browse files
alexdeucherMa Wupeng
authored andcommitted
drm/amdgpu: add shared fdinfo stats
stable inclusion from stable-v6.6.30 commit f85a55fb87c2ee58e957b9c828aa70306a759d8d bugzilla: https://gitee.com/openeuler/kernel/issues/I9MPZ8 Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=f85a55fb87c2ee58e957b9c828aa70306a759d8d -------------------------------- [ Upstream commit ba1a58d5b907bdf1814f8f57434aebc86233430f ] 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: a6ff969fe9cb ("drm/amdgpu: fix visible VRAM handling during faults") Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: ZhangPeng <zhangpeng362@huawei.com>
1 parent 543e93a commit a63f8c5

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
@@ -105,6 +105,10 @@ void amdgpu_show_fdinfo(struct drm_printer *p, struct drm_file *file)
105105
stats.requested_visible_vram/1024UL);
106106
drm_printf(p, "amd-requested-gtt:\t%llu KiB\n",
107107
stats.requested_gtt/1024UL);
108+
drm_printf(p, "drm-shared-vram:\t%llu KiB\n", stats.vram_shared/1024UL);
109+
drm_printf(p, "drm-shared-gtt:\t%llu KiB\n", stats.gtt_shared/1024UL);
110+
drm_printf(p, "drm-shared-cpu:\t%llu KiB\n", stats.cpu_shared/1024UL);
111+
108112
for (hw_ip = 0; hw_ip < AMDGPU_HW_IP_NUM; ++hw_ip) {
109113
if (!usage[hw_ip])
110114
continue;

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1281,25 +1281,36 @@ void amdgpu_bo_get_memory(struct amdgpu_bo *bo,
12811281
struct amdgpu_mem_stats *stats)
12821282
{
12831283
uint64_t size = amdgpu_bo_size(bo);
1284+
struct drm_gem_object *obj;
12841285
unsigned int domain;
1286+
bool shared;
12851287

12861288
/* Abort if the BO doesn't currently have a backing store */
12871289
if (!bo->tbo.resource)
12881290
return;
12891291

1292+
obj = &bo->tbo.base;
1293+
shared = drm_gem_object_is_shared_for_memory_stats(obj);
1294+
12901295
domain = amdgpu_mem_type_to_domain(bo->tbo.resource->mem_type);
12911296
switch (domain) {
12921297
case AMDGPU_GEM_DOMAIN_VRAM:
12931298
stats->vram += size;
12941299
if (amdgpu_bo_in_cpu_visible_vram(bo))
12951300
stats->visible_vram += size;
1301+
if (shared)
1302+
stats->vram_shared += size;
12961303
break;
12971304
case AMDGPU_GEM_DOMAIN_GTT:
12981305
stats->gtt += size;
1306+
if (shared)
1307+
stats->gtt_shared += size;
12991308
break;
13001309
case AMDGPU_GEM_DOMAIN_CPU:
13011310
default:
13021311
stats->cpu += size;
1312+
if (shared)
1313+
stats->cpu_shared += size;
13031314
break;
13041315
}
13051316

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)