From f100c77d0e24044c152153aa9e9b7dbf2bdb1cae Mon Sep 17 00:00:00 2001 From: Iago Toral Quiroga Date: Fri, 11 Nov 2022 12:58:10 +0100 Subject: [PATCH] v3dv: ignore imported BOs when tracking BO memory usage MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Imported BOs are not allocated by the device so we don't update BO stats when they are imported. Therefore, we should not be updating them when they are freed either. Reviewed-by: Alejandro Piñeiro Part-of: (cherry picked from commit f14e2ca099cbc1c732020b6e1c30aaff4f652d1b) --- .pick_status.json | 2 +- src/broadcom/vulkan/v3dv_bo.c | 32 +++++++++++++++++++++++--------- src/broadcom/vulkan/v3dv_bo.h | 4 ++++ src/broadcom/vulkan/v3dv_device.c | 2 +- 4 files changed, 29 insertions(+), 11 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index cc936aa..9de3695 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -2398,7 +2398,7 @@ "description": "v3dv: ignore imported BOs when tracking BO memory usage", "nominated": false, "nomination_type": null, - "resolution": 4, + "resolution": 1, "main_sha": null, "because_sha": null }, diff --git a/src/broadcom/vulkan/v3dv_bo.c b/src/broadcom/vulkan/v3dv_bo.c index f3c819f..c51b192 100644 --- a/src/broadcom/vulkan/v3dv_bo.c +++ b/src/broadcom/vulkan/v3dv_bo.c @@ -142,15 +142,17 @@ bo_free(struct v3dv_device *device, if (ret != 0) fprintf(stderr, "close object %d: %s\n", bo->handle, strerror(errno)); - device->bo_count--; - device->bo_size -= bo->size; - - if (dump_stats) { - fprintf(stderr, "Freed %s%s%dkb:\n", - bo->name ? bo->name : "", - bo->name ? " " : "", - bo->size / 1024); - bo_dump_stats(device); + if (!bo->is_import) { + device->bo_count--; + device->bo_size -= bo->size; + + if (dump_stats) { + fprintf(stderr, "Freed %s%s%dkb:\n", + bo->name ? bo->name : "", + bo->name ? " " : "", + bo->size / 1024); + bo_dump_stats(device); + } } /* Our BO structs are stored in a sparse array in the physical device, @@ -198,9 +200,21 @@ v3dv_bo_init(struct v3dv_bo *bo, bo->name = name; bo->private = private; bo->dumb_handle = -1; + bo->is_import = false; list_inithead(&bo->list_link); } +void +v3dv_bo_init_import(struct v3dv_bo *bo, + uint32_t handle, + uint32_t size, + uint32_t offset, + bool private) +{ + v3dv_bo_init(bo, handle, size, offset, "import", private); + bo->is_import = true; +} + struct v3dv_bo * v3dv_bo_alloc(struct v3dv_device *device, uint32_t size, diff --git a/src/broadcom/vulkan/v3dv_bo.h b/src/broadcom/vulkan/v3dv_bo.h index 191c087..d7a4823 100644 --- a/src/broadcom/vulkan/v3dv_bo.h +++ b/src/broadcom/vulkan/v3dv_bo.h @@ -52,6 +52,9 @@ struct v3dv_bo { */ bool private; + /** If this BO has been imported */ + bool is_import; + /** * If this BO was allocated for a swapchain on the display device, the * handle of the dumb BO on that device. @@ -62,6 +65,7 @@ struct v3dv_bo { }; void v3dv_bo_init(struct v3dv_bo *bo, uint32_t handle, uint32_t size, uint32_t offset, const char *name, bool private); +void v3dv_bo_init_import(struct v3dv_bo *bo, uint32_t handle, uint32_t size, uint32_t offset, bool private); struct v3dv_bo *v3dv_bo_alloc(struct v3dv_device *device, uint32_t size, const char *name, bool private); diff --git a/src/broadcom/vulkan/v3dv_device.c b/src/broadcom/vulkan/v3dv_device.c index a72c577..679b2eb 100644 --- a/src/broadcom/vulkan/v3dv_device.c +++ b/src/broadcom/vulkan/v3dv_device.c @@ -2278,7 +2278,7 @@ device_import_bo(struct v3dv_device *device, assert(*bo); if ((*bo)->refcnt == 0) - v3dv_bo_init(*bo, handle, size, get_offset.offset, "import", false); + v3dv_bo_init_import(*bo, handle, size, get_offset.offset, false); else p_atomic_inc(&(*bo)->refcnt); -- 2.7.4