Module: Mesa Branch: main Commit: cc3c97d8c9492c2860c50ddab162212499a98786 URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=cc3c97d8c9492c2860c50ddab162212499a98786
Author: Juston Li <[email protected]> Date: Thu Feb 16 14:32:26 2023 -0800 venus: Add VkBuffer cache statistics for debug Signed-off-by: Juston Li <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21324> --- src/virtio/vulkan/vn_buffer.c | 18 ++++++++++++++++++ src/virtio/vulkan/vn_buffer.h | 6 ++++++ 2 files changed, 24 insertions(+) diff --git a/src/virtio/vulkan/vn_buffer.c b/src/virtio/vulkan/vn_buffer.c index 6d536f70e16..5046ff2baac 100644 --- a/src/virtio/vulkan/vn_buffer.c +++ b/src/virtio/vulkan/vn_buffer.c @@ -105,11 +105,23 @@ vn_buffer_cache_init(struct vn_device *dev) return VK_SUCCESS; } +static void +vn_buffer_cache_debug_dump(struct vn_buffer_cache *cache) +{ + vn_log(NULL, "dumping buffer cache statistics"); + vn_log(NULL, " cache hit: %d", cache->debug.cache_hit_count); + vn_log(NULL, " cache miss: %d", cache->debug.cache_miss_count); + vn_log(NULL, " cache skip: %d", cache->debug.cache_skip_count); +} + void vn_buffer_cache_fini(struct vn_device *dev) { util_sparse_array_finish(&dev->buffer_cache.entries); simple_mtx_destroy(&dev->buffer_cache.mutex); + + if (VN_DEBUG(CACHE)) + vn_buffer_cache_debug_dump(&dev->buffer_cache); } static struct vn_buffer_cache_entry * @@ -146,11 +158,17 @@ vn_buffer_get_cached_memory_requirements( */ out->memory.memoryRequirements.size = align64( create_info->size, out->memory.memoryRequirements.alignment); + + p_atomic_inc(&cache->debug.cache_hit_count); + } else { + p_atomic_inc(&cache->debug.cache_miss_count); } return entry; } + p_atomic_inc(&cache->debug.cache_skip_count); + return NULL; } diff --git a/src/virtio/vulkan/vn_buffer.h b/src/virtio/vulkan/vn_buffer.h index 63a0f1e546e..82f70be439b 100644 --- a/src/virtio/vulkan/vn_buffer.h +++ b/src/virtio/vulkan/vn_buffer.h @@ -32,6 +32,12 @@ struct vn_buffer_cache { /* lazily cache memory requirements for native buffer infos */ struct util_sparse_array entries; simple_mtx_t mutex; + + struct { + uint32_t cache_skip_count; + uint32_t cache_hit_count; + uint32_t cache_miss_count; + } debug; }; struct vn_buffer {
