From f8f4f466f7150d0dcc9be235511c0076f304740c Mon Sep 17 00:00:00 2001 From: Asahi Lina Date: Sat, 22 Jul 2023 18:34:11 +0900 Subject: [PATCH] asahi: Fix race in BO stats accounting These counters are accessed without locking, so they need to be atomic. Should be cosmetic only. Signed-off-by: Asahi Lina Part-of: --- src/asahi/lib/agx_bo.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/asahi/lib/agx_bo.c b/src/asahi/lib/agx_bo.c index 2d455cd..44b77c4 100644 --- a/src/asahi/lib/agx_bo.c +++ b/src/asahi/lib/agx_bo.c @@ -127,8 +127,9 @@ agx_bo_cache_put_locked(struct agx_bo *bo) printf("BO cache: %zu KiB (+%zu KiB from %s, hit/miss %" PRIu64 "/%" PRIu64 ")\n", DIV_ROUND_UP(dev->bo_cache.size, 1024), - DIV_ROUND_UP(bo->size, 1024), bo->label, dev->bo_cache.hits, - dev->bo_cache.misses); + DIV_ROUND_UP(bo->size, 1024), bo->label, + p_atomic_read(&dev->bo_cache.hits), + p_atomic_read(&dev->bo_cache.misses)); } /* Update label for debug */ @@ -224,9 +225,9 @@ agx_bo_create(struct agx_device *dev, unsigned size, enum agx_bo_flags flags, /* Update stats based on the first attempt to fetch */ if (bo != NULL) - dev->bo_cache.hits++; + p_atomic_inc(&dev->bo_cache.hits); else - dev->bo_cache.misses++; + p_atomic_inc(&dev->bo_cache.misses); /* Otherwise, allocate a fresh BO. If allocation fails, we can try waiting * for something in the cache. But if there's no nothing suitable, we should -- 2.7.4