From 3e122014cf37faf7f7c76db4ebc2ba993c805ec8 Mon Sep 17 00:00:00 2001 From: Yiwei Zhang Date: Wed, 8 Nov 2023 22:48:24 -0800 Subject: [PATCH] venus: relax ring mutex Now we are able to break up the original lock to allow shmem alloc to be outside the ring mutex, as long as the reply shmem set is still coupled with ring submission. Add and expose vn_instance_reply_shmem_alloc helper which will be used by rings separately later. Signed-off-by: Yiwei Zhang Part-of: --- src/virtio/vulkan/vn_instance.c | 45 ++++++++++++--------------------- src/virtio/vulkan/vn_instance.h | 9 +++++++ 2 files changed, 25 insertions(+), 29 deletions(-) diff --git a/src/virtio/vulkan/vn_instance.c b/src/virtio/vulkan/vn_instance.c index 2012e565ac8..351337010d9 100644 --- a/src/virtio/vulkan/vn_instance.c +++ b/src/virtio/vulkan/vn_instance.c @@ -490,20 +490,12 @@ vn_instance_ring_submit(struct vn_instance *instance, return result; } -static struct vn_renderer_shmem * -vn_instance_get_reply_shmem_locked(struct vn_instance *instance, - size_t size, - void **out_ptr) +static inline void +vn_instance_set_reply_shmem_locked(struct vn_instance *instance, + struct vn_renderer_shmem *shmem, + size_t offset, + size_t size) { - VN_TRACE_FUNC(); - - struct vn_renderer_shmem_pool *pool = &instance->reply_shmem_pool; - - size_t offset; - struct vn_renderer_shmem *shmem = - vn_renderer_shmem_pool_alloc(instance->renderer, pool, size, &offset); - if (!shmem) - return NULL; uint32_t set_reply_command_stream_data[16]; struct vn_cs_encoder local_enc = VN_CS_ENCODER_INITIALIZER_LOCAL( @@ -516,10 +508,6 @@ vn_instance_get_reply_shmem_locked(struct vn_instance *instance, vn_encode_vkSetReplyCommandStreamMESA(&local_enc, 0, &stream); vn_cs_encoder_commit(&local_enc); vn_instance_ring_submit_locked(instance, &local_enc, NULL, NULL); - - *out_ptr = shmem->mmap_ptr + offset; - - return shmem; } void @@ -528,33 +516,32 @@ vn_instance_submit_command(struct vn_instance *instance, { assert(!vn_cs_encoder_is_empty(&submit->command)); - void *reply_ptr = NULL; - submit->reply_shmem = NULL; - - mtx_lock(&instance->ring.mutex); - vn_cs_encoder_commit(&submit->command); + size_t reply_offset = 0; + submit->reply_shmem = NULL; if (submit->reply_size) { - submit->reply_shmem = vn_instance_get_reply_shmem_locked( - instance, submit->reply_size, &reply_ptr); - if (!submit->reply_shmem) { - mtx_unlock(&instance->ring.mutex); + submit->reply_shmem = vn_instance_reply_shmem_alloc( + instance, submit->reply_size, &reply_offset); + if (!submit->reply_shmem) return; - } } + mtx_lock(&instance->ring.mutex); + if (submit->reply_size) { + vn_instance_set_reply_shmem_locked(instance, submit->reply_shmem, + reply_offset, submit->reply_size); + } submit->ring_seqno_valid = VK_SUCCESS == vn_instance_ring_submit_locked(instance, &submit->command, submit->reply_shmem, &submit->ring_seqno); - mtx_unlock(&instance->ring.mutex); if (submit->reply_size) { + void *reply_ptr = submit->reply_shmem->mmap_ptr + reply_offset; submit->reply = VN_CS_DECODER_INITIALIZER(reply_ptr, submit->reply_size); - if (submit->ring_seqno_valid) vn_ring_wait_seqno(&instance->ring.ring, submit->ring_seqno); } diff --git a/src/virtio/vulkan/vn_instance.h b/src/virtio/vulkan/vn_instance.h index bcdb99ed0d4..c512a5fcf88 100644 --- a/src/virtio/vulkan/vn_instance.h +++ b/src/virtio/vulkan/vn_instance.h @@ -169,6 +169,15 @@ vn_instance_cs_shmem_alloc(struct vn_instance *instance, instance->renderer, &instance->cs_shmem_pool, size, out_offset); } +static inline struct vn_renderer_shmem * +vn_instance_reply_shmem_alloc(struct vn_instance *instance, + size_t size, + size_t *out_offset) +{ + return vn_renderer_shmem_pool_alloc( + instance->renderer, &instance->reply_shmem_pool, size, out_offset); +} + static inline int vn_instance_acquire_ring_idx(struct vn_instance *instance) {