summaryrefslogtreecommitdiff
path: root/src/gallium/winsys
diff options
context:
space:
mode:
authorMarek Olšák <marek.olsak@amd.com>2021-02-02 23:52:58 -0500
committerMarge Bot <eric+marge@anholt.net>2021-02-06 05:41:22 +0000
commitc3778b8fe147e7ac09cc55e3e59c0f642ce5cbc2 (patch)
tree26cfc6052a4d11688cccb725c325577968e102e5 /src/gallium/winsys
parentff311df6b54e2cab3c6afa3d00adc0a534b0eb5c (diff)
winsys/amdgpu: pack amdgpu_winsys_bo::is_shared and protect it by a mutex
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>
Diffstat (limited to 'src/gallium/winsys')
-rw-r--r--src/gallium/winsys/amdgpu/drm/amdgpu_bo.c16
-rw-r--r--src/gallium/winsys/amdgpu/drm/amdgpu_bo.h11
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;