From 0767f91c8acf61bee4c64c2a3905321a19837cff Mon Sep 17 00:00:00 2001 From: Yiwei Zhang Date: Wed, 4 Sep 2024 23:09:04 -0700 Subject: [PATCH] venus: avoid over-caching sfb cmds For most runtime usages, e.g. apitrace via zink on venus, the sfb cmds normally don't exceed 3. So a limit of 5 cmds would be enough. This would avoid that dEQP-VK.synchronization.basic.timeline_semaphore.chain can easily leave 700+ free cmds in the cache. Signed-off-by: Yiwei Zhang Part-of: --- src/virtio/vulkan/vn_queue.c | 13 +++++++++++-- src/virtio/vulkan/vn_queue.h | 1 + 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/virtio/vulkan/vn_queue.c b/src/virtio/vulkan/vn_queue.c index b48af030db6..77453335723 100644 --- a/src/virtio/vulkan/vn_queue.c +++ b/src/virtio/vulkan/vn_queue.c @@ -1931,6 +1931,7 @@ vn_semaphore_get_feedback_cmd(struct vn_device *dev, struct vn_semaphore *sem) sfb_cmd = list_first_entry(&sem->feedback.free_cmds, struct vn_semaphore_feedback_cmd, head); list_move_to(&sfb_cmd->head, &sem->feedback.pending_cmds); + sem->feedback.free_cmd_count--; } simple_mtx_unlock(&sem->feedback.cmd_mtx); @@ -2132,8 +2133,16 @@ vn_GetSemaphoreCounterValue(VkDevice device, simple_mtx_lock(&sem->feedback.cmd_mtx); list_for_each_entry_safe(struct vn_semaphore_feedback_cmd, sfb_cmd, &sem->feedback.pending_cmds, head) { - if (counter >= vn_feedback_get_counter(sfb_cmd->src_slot)) - list_move_to(&sfb_cmd->head, &sem->feedback.free_cmds); + if (counter >= vn_feedback_get_counter(sfb_cmd->src_slot)) { + /* avoid over-caching more than normal runtime usage */ + if (sem->feedback.free_cmd_count > 5) { + list_del(&sfb_cmd->head); + vn_semaphore_feedback_cmd_free(dev, sfb_cmd); + } else { + list_move_to(&sfb_cmd->head, &sem->feedback.free_cmds); + sem->feedback.free_cmd_count++; + } + } } simple_mtx_unlock(&sem->feedback.cmd_mtx); diff --git a/src/virtio/vulkan/vn_queue.h b/src/virtio/vulkan/vn_queue.h index 26488e95f27..f1570609f81 100644 --- a/src/virtio/vulkan/vn_queue.h +++ b/src/virtio/vulkan/vn_queue.h @@ -112,6 +112,7 @@ struct vn_semaphore { */ struct list_head pending_cmds; struct list_head free_cmds; + uint32_t free_cmd_count; /* Lock for accessing free/pending sfb cmds */ simple_mtx_t cmd_mtx;