From c3778b8fe147e7ac09cc55e3e59c0f642ce5cbc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Tue, 2 Feb 2021 23:52:58 -0500 Subject: [PATCH] winsys/amdgpu: pack amdgpu_winsys_bo::is_shared and protect it by a mutex MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The initialization of abs_timeout fixes a warning that started appearing with this commit. Reviewed-by: Pierre-Eric Pelloux-Prayer Reviewed-by: Zoltán Böszörményi Part-of: --- src/gallium/winsys/amdgpu/drm/amdgpu_bo.c | 16 +++++++++++++--- src/gallium/winsys/amdgpu/drm/amdgpu_bo.h | 11 ++++++----- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/gallium/winsys/amdgpu/drm/amdgpu_bo.c b/src/gallium/winsys/amdgpu/drm/amdgpu_bo.c index 9f022927212..75bfe6e2aff 100644 --- a/src/gallium/winsys/amdgpu/drm/amdgpu_bo.c +++ b/src/gallium/winsys/amdgpu/drm/amdgpu_bo.c @@ -52,7 +52,7 @@ static bool amdgpu_bo_wait(struct pb_buffer *_buf, uint64_t timeout, { struct amdgpu_winsys_bo *bo = amdgpu_winsys_bo(_buf); struct amdgpu_winsys *ws = bo->ws; - int64_t abs_timeout; + int64_t abs_timeout = 0; if (timeout == 0) { if (p_atomic_read(&bo->num_active_ioctls)) @@ -66,7 +66,11 @@ static bool amdgpu_bo_wait(struct pb_buffer *_buf, uint64_t timeout, return false; } - if (bo->is_shared) { + simple_mtx_lock(&bo->lock); + bool is_shared = bo->is_shared; + simple_mtx_unlock(&bo->lock); + + if (is_shared) { /* We can't use user fences for shared buffers, because user fences * are local to this process only. If we want to wait for all buffer * uses in all processes, we have to use amdgpu_bo_wait_for_idle. @@ -1631,7 +1635,11 @@ static bool amdgpu_bo_get_handle(struct radeon_winsys *rws, if (sws->fd == ws->fd) { whandle->handle = bo->u.real.kms_handle; - if (bo->is_shared) + simple_mtx_lock(&bo->lock); + bool is_shared = bo->is_shared; + simple_mtx_unlock(&bo->lock); + + if (is_shared) return true; goto hash_table_set; @@ -1677,7 +1685,9 @@ static bool amdgpu_bo_get_handle(struct radeon_winsys *rws, _mesa_hash_table_insert(ws->bo_export_table, bo->bo, bo); simple_mtx_unlock(&ws->bo_export_table_lock); + simple_mtx_lock(&bo->lock); bo->is_shared = true; + simple_mtx_unlock(&bo->lock); return true; } diff --git a/src/gallium/winsys/amdgpu/drm/amdgpu_bo.h b/src/gallium/winsys/amdgpu/drm/amdgpu_bo.h index 99bedcadf82..9bf23a6f88a 100644 --- a/src/gallium/winsys/amdgpu/drm/amdgpu_bo.h +++ b/src/gallium/winsys/amdgpu/drm/amdgpu_bo.h @@ -89,6 +89,12 @@ struct amdgpu_winsys_bo { amdgpu_bo_handle bo; /* NULL for slab entries and sparse buffers */ bool is_user_ptr; bool use_reusable_pool; + + /* Whether buffer_get_handle or buffer_from_handle has been called, + * it can only transition from false to true. Protected by lock. + */ + bool is_shared; + uint32_t unique_id; uint64_t va; simple_mtx_t lock; @@ -97,11 +103,6 @@ struct amdgpu_winsys_bo { * thread, is this bo referenced in? */ volatile int num_active_ioctls; - /* whether buffer_get_handle or buffer_from_handle was called, - * it can only transition from false to true - */ - volatile int is_shared; /* bool (int for atomicity) */ - /* Fences for buffer synchronization. */ unsigned num_fences; unsigned max_fences;