freedreno: Avoid taking screen lock
authorRob Clark <robdclark@chromium.org>
Sat, 11 Feb 2023 16:08:24 +0000 (08:08 -0800)
committerMarge Bot <emma+marge@anholt.net>
Thu, 16 Feb 2023 19:57:13 +0000 (19:57 +0000)
Avoid taking screen unlock for batch unref.  Instead just split the
destroy fxn into locked and unlocked variants.  That way we only end
up taking the screen lock on final unref but avoid it in the common
case.

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

src/gallium/drivers/freedreno/freedreno_batch.c
src/gallium/drivers/freedreno/freedreno_batch.h

index f716517..06b5b95 100644 (file)
@@ -291,7 +291,7 @@ fd_batch_reset(struct fd_batch *batch)
 }
 
 void
-__fd_batch_destroy(struct fd_batch *batch)
+__fd_batch_destroy_locked(struct fd_batch *batch)
 {
    struct fd_context *ctx = batch->ctx;
 
@@ -320,6 +320,15 @@ __fd_batch_destroy(struct fd_batch *batch)
 }
 
 void
+__fd_batch_destroy(struct fd_batch *batch)
+{
+   struct fd_screen *screen = batch->ctx->screen;
+   fd_screen_lock(screen);
+   __fd_batch_destroy_locked(batch);
+   fd_screen_unlock(screen);
+}
+
+void
 __fd_batch_describe(char *buf, const struct fd_batch *batch)
 {
    sprintf(buf, "fd_batch<%u>", batch->seqno);
index 81e02b4..ecb4833 100644 (file)
@@ -285,6 +285,7 @@ struct fd_batch_key *fd_batch_key_clone(void *mem_ctx,
 
 /* not called directly: */
 void __fd_batch_describe(char *buf, const struct fd_batch *batch) assert_dt;
+void __fd_batch_destroy_locked(struct fd_batch *batch);
 void __fd_batch_destroy(struct fd_batch *batch);
 
 /*
@@ -314,7 +315,7 @@ fd_batch_reference_locked(struct fd_batch **ptr, struct fd_batch *batch)
    if (pipe_reference_described(
           &(*ptr)->reference, &batch->reference,
           (debug_reference_descriptor)__fd_batch_describe))
-      __fd_batch_destroy(old_batch);
+      __fd_batch_destroy_locked(old_batch);
 
    *ptr = batch;
 }
@@ -323,15 +324,13 @@ static inline void
 fd_batch_reference(struct fd_batch **ptr, struct fd_batch *batch)
 {
    struct fd_batch *old_batch = *ptr;
-   struct fd_context *ctx = old_batch ? old_batch->ctx : NULL;
-
-   if (ctx)
-      fd_screen_lock(ctx->screen);
 
-   fd_batch_reference_locked(ptr, batch);
+   if (pipe_reference_described(
+          &(*ptr)->reference, &batch->reference,
+          (debug_reference_descriptor)__fd_batch_describe))
+      __fd_batch_destroy(old_batch);
 
-   if (ctx)
-      fd_screen_unlock(ctx->screen);
+   *ptr = batch;
 }
 
 static inline void