From a4b949fe61bd5d2ceccd739fff30e309a7ba996a Mon Sep 17 00:00:00 2001 From: Rob Clark Date: Sat, 11 Feb 2023 08:08:24 -0800 Subject: [PATCH] freedreno: Avoid taking screen lock 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 Part-of: --- src/gallium/drivers/freedreno/freedreno_batch.c | 11 ++++++++++- src/gallium/drivers/freedreno/freedreno_batch.h | 15 +++++++-------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/gallium/drivers/freedreno/freedreno_batch.c b/src/gallium/drivers/freedreno/freedreno_batch.c index f716517bdd4..06b5b9561d4 100644 --- a/src/gallium/drivers/freedreno/freedreno_batch.c +++ b/src/gallium/drivers/freedreno/freedreno_batch.c @@ -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; @@ -319,6 +319,15 @@ __fd_batch_destroy(struct fd_batch *batch) fd_screen_lock(ctx->screen); } +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) { diff --git a/src/gallium/drivers/freedreno/freedreno_batch.h b/src/gallium/drivers/freedreno/freedreno_batch.h index 81e02b4249c..ecb4833b7aa 100644 --- a/src/gallium/drivers/freedreno/freedreno_batch.h +++ b/src/gallium/drivers/freedreno/freedreno_batch.h @@ -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); + if (pipe_reference_described( + &(*ptr)->reference, &batch->reference, + (debug_reference_descriptor)__fd_batch_describe)) + __fd_batch_destroy(old_batch); - fd_batch_reference_locked(ptr, batch); - - if (ctx) - fd_screen_unlock(ctx->screen); + *ptr = batch; } static inline void