winsys/amdgpu: pack amdgpu_winsys_bo::is_shared and protect it by a mutex
authorMarek Olšák <marek.olsak@amd.com>
Wed, 3 Feb 2021 04:52:58 +0000 (23:52 -0500)
committerMarge Bot <eric+marge@anholt.net>
Sat, 6 Feb 2021 05:41:22 +0000 (05:41 +0000)
The initialization of abs_timeout fixes a warning that started appearing
with this commit.

Reviewed-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Reviewed-by: Zoltán Böszörményi <zboszor@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8849>

src/gallium/winsys/amdgpu/drm/amdgpu_bo.c
src/gallium/winsys/amdgpu/drm/amdgpu_bo.h

index 9f02292..75bfe6e 100644 (file)
@@ -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;
 }
 
index 99bedca..9bf23a6 100644 (file)
@@ -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;