From 1e04483c22e372aac8a664fe2b272b10aa774eea Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Fri, 5 Aug 2016 01:28:17 +0200 Subject: [PATCH] winsys/amdgpu: track the amount of mapped memory MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Reviewed-by: Nicolai Hähnle --- src/gallium/drivers/radeon/radeon_winsys.h | 2 ++ src/gallium/winsys/amdgpu/drm/amdgpu_bo.c | 18 +++++++++++++++++- src/gallium/winsys/amdgpu/drm/amdgpu_bo.h | 1 + src/gallium/winsys/amdgpu/drm/amdgpu_winsys.c | 4 ++++ src/gallium/winsys/amdgpu/drm/amdgpu_winsys.h | 2 ++ 5 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/gallium/drivers/radeon/radeon_winsys.h b/src/gallium/drivers/radeon/radeon_winsys.h index cc79d5492d1..72ba830fd35 100644 --- a/src/gallium/drivers/radeon/radeon_winsys.h +++ b/src/gallium/drivers/radeon/radeon_winsys.h @@ -154,6 +154,8 @@ enum ring_type { enum radeon_value_id { RADEON_REQUESTED_VRAM_MEMORY, RADEON_REQUESTED_GTT_MEMORY, + RADEON_MAPPED_VRAM, + RADEON_MAPPED_GTT, RADEON_BUFFER_WAIT_TIME_NS, RADEON_TIMESTAMP, RADEON_NUM_CS_FLUSHES, diff --git a/src/gallium/winsys/amdgpu/drm/amdgpu_bo.c b/src/gallium/winsys/amdgpu/drm/amdgpu_bo.c index db2c77fec0d..a4bc474634b 100644 --- a/src/gallium/winsys/amdgpu/drm/amdgpu_bo.c +++ b/src/gallium/winsys/amdgpu/drm/amdgpu_bo.c @@ -256,8 +256,17 @@ static void *amdgpu_bo_map(struct pb_buffer *buf, /* Clear the cache and try again. */ pb_cache_release_all_buffers(&bo->ws->bo_cache); r = amdgpu_bo_cpu_map(bo->bo, &cpu); + if (r) + return NULL; + } + + if (p_atomic_inc_return(&bo->map_count) == 1) { + if (bo->initial_domain & RADEON_DOMAIN_VRAM) + bo->ws->mapped_vram += bo->base.size; + else + bo->ws->mapped_gtt += bo->base.size; } - return r ? NULL : cpu; + return cpu; } static void amdgpu_bo_unmap(struct pb_buffer *buf) @@ -267,6 +276,13 @@ static void amdgpu_bo_unmap(struct pb_buffer *buf) if (bo->user_ptr) return; + if (p_atomic_dec_zero(&bo->map_count)) { + if (bo->initial_domain & RADEON_DOMAIN_VRAM) + bo->ws->mapped_vram -= bo->base.size; + else + bo->ws->mapped_gtt -= bo->base.size; + } + amdgpu_bo_cpu_unmap(bo->bo); } diff --git a/src/gallium/winsys/amdgpu/drm/amdgpu_bo.h b/src/gallium/winsys/amdgpu/drm/amdgpu_bo.h index a76877130d4..e2ee049b642 100644 --- a/src/gallium/winsys/amdgpu/drm/amdgpu_bo.h +++ b/src/gallium/winsys/amdgpu/drm/amdgpu_bo.h @@ -44,6 +44,7 @@ struct amdgpu_winsys_bo { void *user_ptr; /* from buffer_from_ptr */ amdgpu_bo_handle bo; + int map_count; uint32_t unique_id; amdgpu_va_handle va_handle; uint64_t va; diff --git a/src/gallium/winsys/amdgpu/drm/amdgpu_winsys.c b/src/gallium/winsys/amdgpu/drm/amdgpu_winsys.c index 1f24fcdd701..95567776bee 100644 --- a/src/gallium/winsys/amdgpu/drm/amdgpu_winsys.c +++ b/src/gallium/winsys/amdgpu/drm/amdgpu_winsys.c @@ -379,6 +379,10 @@ static uint64_t amdgpu_query_value(struct radeon_winsys *rws, return ws->allocated_vram; case RADEON_REQUESTED_GTT_MEMORY: return ws->allocated_gtt; + case RADEON_MAPPED_VRAM: + return ws->mapped_vram; + case RADEON_MAPPED_GTT: + return ws->mapped_gtt; case RADEON_BUFFER_WAIT_TIME_NS: return ws->buffer_wait_time; case RADEON_TIMESTAMP: diff --git a/src/gallium/winsys/amdgpu/drm/amdgpu_winsys.h b/src/gallium/winsys/amdgpu/drm/amdgpu_winsys.h index 848953048d1..96d4e6d0567 100644 --- a/src/gallium/winsys/amdgpu/drm/amdgpu_winsys.h +++ b/src/gallium/winsys/amdgpu/drm/amdgpu_winsys.h @@ -53,6 +53,8 @@ struct amdgpu_winsys { uint32_t next_bo_unique_id; uint64_t allocated_vram; uint64_t allocated_gtt; + uint64_t mapped_vram; + uint64_t mapped_gtt; uint64_t buffer_wait_time; /* time spent in buffer_wait in ns */ uint64_t num_cs_flushes; -- 2.30.2