From be5bb3146a47dd76e87a79c1ec1965d2450240ca Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Mon, 5 Jul 2021 05:11:26 +1000 Subject: [PATCH] crocus: optimise bo_unref path a little. This just splits it into the atomic/non-atomic paths Part-of: --- src/gallium/drivers/crocus/crocus_bufmgr.c | 37 ++++++---------------- src/gallium/drivers/crocus/crocus_bufmgr.h | 24 +++++++++++++- 2 files changed, 33 insertions(+), 28 deletions(-) diff --git a/src/gallium/drivers/crocus/crocus_bufmgr.c b/src/gallium/drivers/crocus/crocus_bufmgr.c index fa80b2a1155..5efa47289ab 100644 --- a/src/gallium/drivers/crocus/crocus_bufmgr.c +++ b/src/gallium/drivers/crocus/crocus_bufmgr.c @@ -115,16 +115,6 @@ get_time(void) #define FILE_DEBUG_FLAG DEBUG_BUFMGR -static inline int -atomic_add_unless(int *v, int add, int unless) -{ - int c, old; - c = p_atomic_read(v); - while (c != unless && (old = p_atomic_cmpxchg(v, c, c + add)) != c) - c = old; - return c == unless; -} - struct bo_cache_bucket { /** List of cached BOs. */ struct list_head head; @@ -720,28 +710,21 @@ bo_unreference_final(struct crocus_bo *bo, time_t time) } void -crocus_bo_unreference(struct crocus_bo *bo) +__crocus_bo_unreference(struct crocus_bo *bo) { - if (bo == NULL) - return; + struct crocus_bufmgr *bufmgr = bo->bufmgr; + struct timespec time; - assert(p_atomic_read(&bo->refcount) > 0); + clock_gettime(CLOCK_MONOTONIC, &time); - if (atomic_add_unless(&bo->refcount, -1, 1)) { - struct crocus_bufmgr *bufmgr = bo->bufmgr; - struct timespec time; + mtx_lock(&bufmgr->lock); - clock_gettime(CLOCK_MONOTONIC, &time); - - mtx_lock(&bufmgr->lock); - - if (p_atomic_dec_zero(&bo->refcount)) { - bo_unreference_final(bo, time.tv_sec); - cleanup_bo_cache(bufmgr, time.tv_sec); - } - - mtx_unlock(&bufmgr->lock); + if (p_atomic_dec_zero(&bo->refcount)) { + bo_unreference_final(bo, time.tv_sec); + cleanup_bo_cache(bufmgr, time.tv_sec); } + + mtx_unlock(&bufmgr->lock); } static void diff --git a/src/gallium/drivers/crocus/crocus_bufmgr.h b/src/gallium/drivers/crocus/crocus_bufmgr.h index 0ec2af5bc69..0f3408c1233 100644 --- a/src/gallium/drivers/crocus/crocus_bufmgr.h +++ b/src/gallium/drivers/crocus/crocus_bufmgr.h @@ -186,11 +186,33 @@ crocus_bo_reference(struct crocus_bo *bo) p_atomic_inc(&bo->refcount); } +static inline int +atomic_add_unless(int *v, int add, int unless) +{ + int c, old; + c = p_atomic_read(v); + while (c != unless && (old = p_atomic_cmpxchg(v, c, c + add)) != c) + c = old; + return c == unless; +} + +void __crocus_bo_unreference(struct crocus_bo *bo); + /** * Releases a reference on a buffer object, freeing the data if * no references remain. */ -void crocus_bo_unreference(struct crocus_bo *bo); +static inline void crocus_bo_unreference(struct crocus_bo *bo) +{ + if (bo == NULL) + return; + + assert(p_atomic_read(&bo->refcount) > 0); + + if (atomic_add_unless(&bo->refcount, -1, 1)) { + __crocus_bo_unreference(bo); + } +} #define MAP_READ PIPE_MAP_READ #define MAP_WRITE PIPE_MAP_WRITE