From 7941d705c3a346a08ca30d1eb355642f9d43bd9b Mon Sep 17 00:00:00 2001 From: Yiwei Zhang Date: Tue, 27 Aug 2024 11:57:11 -0700 Subject: [PATCH] venus: workaround cacheline overflush issue on Intel JSL We observed that Venus on ANV on JSL platform has some cacheline flush issue. The overflush shows up as: 1. There're 2 threads venus bliting the feedback buffers suballocated from the same backing device memory, back to back. 2. On thread A, flushing the feedback buffer for cpu read is placed behind flushing a shader storage buffer for cpu read. 3. On thread B, flushing a different feedback buffer with the same backing device memory (different offset bound to) can kick the feedback buffer flush in (2) earlier than it should be flushed. 4. As a result, CPU polling thread for thread B results would see venus feedback buffer update earlier than shader storage buffer results being updated, breaking Venus sync primitives optimization. During investigation, a solid workaround for JSL platform is to force Venus to align up to 128 bytes for feedback buffer suballocation while the default is at 64 bytes. Cc: mesa-stable Signed-off-by: Yiwei Zhang Part-of: --- src/virtio/vulkan/vn_feedback.c | 8 +++++--- src/virtio/vulkan/vn_physical_device.c | 2 ++ src/virtio/vulkan/vn_physical_device.h | 5 +++++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/virtio/vulkan/vn_feedback.c b/src/virtio/vulkan/vn_feedback.c index 9069533c3f9..d85340455d2 100644 --- a/src/virtio/vulkan/vn_feedback.c +++ b/src/virtio/vulkan/vn_feedback.c @@ -134,10 +134,12 @@ vn_feedback_buffer_destroy(struct vn_device *dev, } static inline uint32_t -vn_get_feedback_buffer_alignment(struct vn_feedback_buffer *fb_buf) +vn_get_feedback_buffer_alignment(struct vn_device *dev, + struct vn_feedback_buffer *fb_buf) { struct vn_buffer *buf = vn_buffer_from_handle(fb_buf->buf_handle); - return buf->requirements.memory.memoryRequirements.alignment; + return align(buf->requirements.memory.memoryRequirements.alignment, + dev->physical_device->wa_min_fb_align); } static VkResult @@ -153,7 +155,7 @@ vn_feedback_pool_grow_locked(struct vn_feedback_pool *pool) return result; pool->used = 0; - pool->alignment = vn_get_feedback_buffer_alignment(fb_buf); + pool->alignment = vn_get_feedback_buffer_alignment(pool->dev, fb_buf); list_add(&fb_buf->head, &pool->fb_bufs); diff --git a/src/virtio/vulkan/vn_physical_device.c b/src/virtio/vulkan/vn_physical_device.c index e72663201f4..3022a79e7c0 100644 --- a/src/virtio/vulkan/vn_physical_device.c +++ b/src/virtio/vulkan/vn_physical_device.c @@ -417,6 +417,8 @@ vn_physical_device_sanitize_properties(struct vn_physical_device *physical_dev) if (!forward_driver_version) props->driverVersion = vk_get_driver_version(); + physical_dev->wa_min_fb_align = strstr(props->deviceName, "JSL") ? 128 : 1; + char device_name[VK_MAX_PHYSICAL_DEVICE_NAME_SIZE]; int device_name_len = snprintf(device_name, sizeof(device_name), "Virtio-GPU Venus (%s)", props->deviceName); diff --git a/src/virtio/vulkan/vn_physical_device.h b/src/virtio/vulkan/vn_physical_device.h index cc9dbb219d3..5e12acd5c52 100644 --- a/src/virtio/vulkan/vn_physical_device.h +++ b/src/virtio/vulkan/vn_physical_device.h @@ -73,6 +73,11 @@ struct vn_physical_device { struct vk_device_extension_table renderer_extensions; uint32_t *extension_spec_versions; + /* Venus feedback encounters cacheline overflush issue on Intel JSL, and + * has to workaround by further aligning up the feedback buffer alignment. + */ + uint32_t wa_min_fb_align; + enum VkDriverId renderer_driver_id; VkQueueFamilyProperties2 *queue_family_properties;