Mesa (master): freedreno/drm: Make ring refcnt atomic again

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Nov 10 18:27:28 UTC 2020


Module: Mesa
Branch: master
Commit: b2f4bf010574c501f93697d90f182a9bc6c83356
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=b2f4bf010574c501f93697d90f182a9bc6c83356

Author: Rob Clark <robdclark at chromium.org>
Date:   Sat Oct 24 12:20:57 2020 -0700

freedreno/drm: Make ring refcnt atomic again

In general, rings are not shared across contexts/threads.  But this
can happen with texture stateobjs, which can be invalidated by other
contexts.

And while we're here, lets convert the rest of freedreno/drm to
u_atomic

Signed-off-by: Rob Clark <robdclark at chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7342>

---

 src/freedreno/drm/freedreno_bo.c         | 2 +-
 src/freedreno/drm/freedreno_device.c     | 4 ++--
 src/freedreno/drm/freedreno_pipe.c       | 2 +-
 src/freedreno/drm/freedreno_priv.h       | 2 --
 src/freedreno/drm/freedreno_ringbuffer.h | 5 +++--
 5 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/src/freedreno/drm/freedreno_bo.c b/src/freedreno/drm/freedreno_bo.c
index 1ea514ceae3..315a3bbc361 100644
--- a/src/freedreno/drm/freedreno_bo.c
+++ b/src/freedreno/drm/freedreno_bo.c
@@ -251,7 +251,7 @@ void fd_bo_del(struct fd_bo *bo)
 {
 	struct fd_device *dev = bo->dev;
 
-	if (!atomic_dec_and_test(&bo->refcnt))
+	if (!p_atomic_dec_zero(&bo->refcnt))
 		return;
 
 	simple_mtx_lock(&table_lock);
diff --git a/src/freedreno/drm/freedreno_device.c b/src/freedreno/drm/freedreno_device.c
index e64640c2e2b..2accf5ce67f 100644
--- a/src/freedreno/drm/freedreno_device.c
+++ b/src/freedreno/drm/freedreno_device.c
@@ -121,14 +121,14 @@ static void fd_device_del_impl(struct fd_device *dev)
 
 void fd_device_del_locked(struct fd_device *dev)
 {
-	if (!atomic_dec_and_test(&dev->refcnt))
+	if (!p_atomic_dec_zero(&dev->refcnt))
 		return;
 	fd_device_del_impl(dev);
 }
 
 void fd_device_del(struct fd_device *dev)
 {
-	if (!atomic_dec_and_test(&dev->refcnt))
+	if (!p_atomic_dec_zero(&dev->refcnt))
 		return;
 	simple_mtx_lock(&table_lock);
 	fd_device_del_impl(dev);
diff --git a/src/freedreno/drm/freedreno_pipe.c b/src/freedreno/drm/freedreno_pipe.c
index a4fd856bea6..e09ffe4be8c 100644
--- a/src/freedreno/drm/freedreno_pipe.c
+++ b/src/freedreno/drm/freedreno_pipe.c
@@ -77,7 +77,7 @@ struct fd_pipe * fd_pipe_ref(struct fd_pipe *pipe)
 
 void fd_pipe_del(struct fd_pipe *pipe)
 {
-	if (!atomic_dec_and_test(&pipe->refcnt))
+	if (!p_atomic_dec_zero(&pipe->refcnt))
 		return;
 	pipe->funcs->destroy(pipe);
 }
diff --git a/src/freedreno/drm/freedreno_priv.h b/src/freedreno/drm/freedreno_priv.h
index ee2cc02ced1..0c7915f761c 100644
--- a/src/freedreno/drm/freedreno_priv.h
+++ b/src/freedreno/drm/freedreno_priv.h
@@ -51,8 +51,6 @@
 #include "freedreno_drmif.h"
 #include "freedreno_ringbuffer.h"
 
-#define atomic_dec_and_test(x) (__sync_add_and_fetch (x, -1) == 0)
-
 struct fd_device_funcs {
 	int (*bo_new_handle)(struct fd_device *dev, uint32_t size,
 			uint32_t flags, uint32_t *handle);
diff --git a/src/freedreno/drm/freedreno_ringbuffer.h b/src/freedreno/drm/freedreno_ringbuffer.h
index 3456c7df73c..f634781a324 100644
--- a/src/freedreno/drm/freedreno_ringbuffer.h
+++ b/src/freedreno/drm/freedreno_ringbuffer.h
@@ -28,6 +28,7 @@
 #define FREEDRENO_RINGBUFFER_H_
 
 #include <stdio.h>
+#include "util/u_atomic.h"
 #include "util/u_debug.h"
 #include "util/u_dynarray.h"
 
@@ -127,7 +128,7 @@ struct fd_ringbuffer * fd_ringbuffer_new_object(struct fd_pipe *pipe,
 static inline void
 fd_ringbuffer_del(struct fd_ringbuffer *ring)
 {
-	if (--ring->refcnt > 0)
+	if (!p_atomic_dec_zero(&ring->refcnt))
 		return;
 
 	ring->funcs->destroy(ring);
@@ -137,7 +138,7 @@ static inline
 struct fd_ringbuffer *
 fd_ringbuffer_ref(struct fd_ringbuffer *ring)
 {
-	ring->refcnt++;
+	p_atomic_inc(&ring->refcnt);
 	return ring;
 }
 



More information about the mesa-commit mailing list