etnaviv/drm: convert to simple_mtx
authorChristian Gmeiner <christian.gmeiner@gmail.com>
Mon, 30 Nov 2020 08:39:35 +0000 (09:39 +0100)
committerMarge Bot <eric+marge@anholt.net>
Tue, 1 Dec 2020 12:20:45 +0000 (12:20 +0000)
We do not need a full blown pthread mutex.

Signed-off-by: Christian Gmeiner <christian.gmeiner@gmail.com>
Reviewed-by: Lucas Stach <l.stach@pengutronix.de>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7832>

src/etnaviv/drm/etnaviv_bo.c
src/etnaviv/drm/etnaviv_bo_cache.c
src/etnaviv/drm/etnaviv_cmd_stream.c
src/etnaviv/drm/etnaviv_device.c
src/etnaviv/drm/etnaviv_priv.h

index 7fde304..8c258f2 100644 (file)
@@ -30,7 +30,7 @@
 #include "etnaviv_priv.h"
 #include "etnaviv_drmif.h"
 
-pthread_mutex_t etna_drm_table_lock = PTHREAD_MUTEX_INITIALIZER;
+simple_mtx_t etna_drm_table_lock = _SIMPLE_MTX_INITIALIZER_NP;
 void _etna_bo_del(struct etna_bo *bo);
 
 /* set buffer name, and add to table, call w/ etna_drm_table_lock held: */
@@ -135,10 +135,10 @@ struct etna_bo *etna_bo_new(struct etna_device *dev, uint32_t size,
        if (ret)
                return NULL;
 
-       pthread_mutex_lock(&etna_drm_table_lock);
+       simple_mtx_lock(&etna_drm_table_lock);
        bo = bo_from_handle(dev, size, req.handle, flags);
        bo->reuse = 1;
-       pthread_mutex_unlock(&etna_drm_table_lock);
+       simple_mtx_unlock(&etna_drm_table_lock);
 
        VG_BO_ALLOC(bo);
 
@@ -181,7 +181,7 @@ struct etna_bo *etna_bo_from_name(struct etna_device *dev,
                .name = name,
        };
 
-       pthread_mutex_lock(&etna_drm_table_lock);
+       simple_mtx_lock(&etna_drm_table_lock);
 
        /* check name table first, to see if bo is already open: */
        bo = lookup_bo(dev->name_table, name);
@@ -204,7 +204,7 @@ struct etna_bo *etna_bo_from_name(struct etna_device *dev,
        }
 
 out_unlock:
-       pthread_mutex_unlock(&etna_drm_table_lock);
+       simple_mtx_unlock(&etna_drm_table_lock);
 
        return bo;
 }
@@ -223,11 +223,11 @@ struct etna_bo *etna_bo_from_dmabuf(struct etna_device *dev, int fd)
         * racing against etna_bo_del, which might invalidate the
         * returned handle.
         */
-       pthread_mutex_lock(&etna_drm_table_lock);
+       simple_mtx_lock(&etna_drm_table_lock);
 
        ret = drmPrimeFDToHandle(dev->fd, fd, &handle);
        if (ret) {
-               pthread_mutex_unlock(&etna_drm_table_lock);
+               simple_mtx_unlock(&etna_drm_table_lock);
                return NULL;
        }
 
@@ -244,7 +244,7 @@ struct etna_bo *etna_bo_from_dmabuf(struct etna_device *dev, int fd)
        VG_BO_ALLOC(bo);
 
 out_unlock:
-       pthread_mutex_unlock(&etna_drm_table_lock);
+       simple_mtx_unlock(&etna_drm_table_lock);
 
        return bo;
 }
@@ -257,7 +257,7 @@ void etna_bo_del(struct etna_bo *bo)
 
        struct etna_device *dev = bo->dev;
 
-       pthread_mutex_lock(&etna_drm_table_lock);
+       simple_mtx_lock(&etna_drm_table_lock);
 
        /* Must test under table lock to avoid racing with the from_dmabuf/name
         * paths, which rely on the BO refcount to be stable over the lookup, so
@@ -272,7 +272,7 @@ void etna_bo_del(struct etna_bo *bo)
        _etna_bo_del(bo);
        etna_device_del_locked(dev);
 out:
-       pthread_mutex_unlock(&etna_drm_table_lock);
+       simple_mtx_unlock(&etna_drm_table_lock);
 }
 
 /* get the global flink/DRI2 buffer name */
@@ -289,9 +289,9 @@ int etna_bo_get_name(struct etna_bo *bo, uint32_t *name)
                        return ret;
                }
 
-               pthread_mutex_lock(&etna_drm_table_lock);
+               simple_mtx_lock(&etna_drm_table_lock);
                set_name(bo, req.name);
-               pthread_mutex_unlock(&etna_drm_table_lock);
+               simple_mtx_unlock(&etna_drm_table_lock);
                bo->reuse = 0;
        }
 
index 185ae52..e99cf46 100644 (file)
@@ -122,7 +122,7 @@ static struct etna_bo *find_in_bucket(struct etna_bo_bucket *bucket, uint32_t fl
 {
        struct etna_bo *bo = NULL, *tmp;
 
-       pthread_mutex_lock(&etna_drm_table_lock);
+       simple_mtx_lock(&etna_drm_table_lock);
 
        if (list_is_empty(&bucket->list))
                goto out_unlock;
@@ -146,7 +146,7 @@ static struct etna_bo *find_in_bucket(struct etna_bo_bucket *bucket, uint32_t fl
        bo = NULL;
 
 out_unlock:
-       pthread_mutex_unlock(&etna_drm_table_lock);
+       simple_mtx_unlock(&etna_drm_table_lock);
 
        return bo;
 }
index 0c12bfe..5555efb 100644 (file)
@@ -30,7 +30,7 @@
 #include "etnaviv_drmif.h"
 #include "etnaviv_priv.h"
 
-static pthread_mutex_t idx_lock = PTHREAD_MUTEX_INITIALIZER;
+static simple_mtx_t idx_lock = _SIMPLE_MTX_INITIALIZER_NP;
 
 static void *grow(void *ptr, uint32_t nr, uint32_t *max, uint32_t sz)
 {
@@ -173,7 +173,7 @@ static uint32_t bo2idx(struct etna_cmd_stream *stream, struct etna_bo *bo,
        struct etna_cmd_stream_priv *priv = etna_cmd_stream_priv(stream);
        uint32_t idx;
 
-       pthread_mutex_lock(&idx_lock);
+       simple_mtx_lock(&idx_lock);
 
        if (bo->current_stream == stream) {
                idx = bo->idx;
@@ -195,7 +195,7 @@ static uint32_t bo2idx(struct etna_cmd_stream *stream, struct etna_bo *bo,
                bo->current_stream = stream;
                bo->idx = idx;
        }
-       pthread_mutex_unlock(&idx_lock);
+       simple_mtx_unlock(&idx_lock);
 
        if (flags & ETNA_RELOC_READ)
                priv->submit.bos[idx].flags |= ETNA_SUBMIT_BO_READ;
index e53fa18..2f2f921 100644 (file)
@@ -109,9 +109,9 @@ void etna_device_del(struct etna_device *dev)
        if (!p_atomic_dec_zero(&dev->refcnt))
                return;
 
-       pthread_mutex_lock(&etna_drm_table_lock);
+       simple_mtx_lock(&etna_drm_table_lock);
        etna_device_del_impl(dev);
-       pthread_mutex_unlock(&etna_drm_table_lock);
+       simple_mtx_unlock(&etna_drm_table_lock);
 }
 
 int etna_device_fd(struct etna_device *dev)
index bec01ae..e3a857b 100644 (file)
@@ -34,7 +34,6 @@
 #include <errno.h>
 #include <fcntl.h>
 #include <sys/ioctl.h>
-#include <pthread.h>
 #include <stdio.h>
 #include <assert.h>
 
@@ -42,6 +41,7 @@
 
 #include "util/list.h"
 #include "util/macros.h"
+#include "util/simple_mtx.h"
 #include "util/timespec.h"
 #include "util/u_atomic.h"
 #include "util/u_debug.h"
@@ -50,7 +50,7 @@
 #include "etnaviv_drmif.h"
 #include "drm-uapi/etnaviv_drm.h"
 
-extern pthread_mutex_t etna_drm_table_lock;
+extern simple_mtx_t etna_drm_table_lock;
 
 struct etna_bo_bucket {
        uint32_t size;