From 266d961fdc91514d6425e33d43fc1bd4e571bd35 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Roberto=20de=20Souza?= Date: Thu, 9 Mar 2023 11:00:10 -0800 Subject: [PATCH] iris: Don't mark protected bo as reusable MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The check in alloc_bo_from_cache() was skiping any try to get a bo from cache but after use a protected bo was still being put in some cache bucket and could be used for cases that don't require a protected bo. Using a protected bo in cases that don't require it can have performance implications. So here returning NULL when trying to get a cache bucket for a protected bo, this will cause bo->real.reusable to be set to false avoiding the bo to be reused. Fixes: 9402ac8023a0 ("iris: handle protected BO creation") Signed-off-by: José Roberto de Souza Reviewed-by: Lionel Landwerlin Part-of: --- src/gallium/drivers/iris/iris_bufmgr.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/gallium/drivers/iris/iris_bufmgr.c b/src/gallium/drivers/iris/iris_bufmgr.c index 17dc704..fd4277c 100644 --- a/src/gallium/drivers/iris/iris_bufmgr.c +++ b/src/gallium/drivers/iris/iris_bufmgr.c @@ -311,8 +311,12 @@ bucket_info_for_heap(struct iris_bufmgr *bufmgr, enum iris_heap heap, */ static struct bo_cache_bucket * bucket_for_size(struct iris_bufmgr *bufmgr, uint64_t size, - enum iris_heap heap) + enum iris_heap heap, unsigned flags) { + /* Protected bo needs special handling during allocation */ + if (flags & BO_ALLOC_PROTECTED) + return NULL; + /* Calculating the pages and rounding up to the page size. */ const unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE; @@ -872,8 +876,7 @@ alloc_bo_from_cache(struct iris_bufmgr *bufmgr, unsigned flags, bool match_zone) { - /* Don't put anything protected in the BO cache. */ - if (!bucket || (flags & BO_ALLOC_PROTECTED)) + if (!bucket) return NULL; struct iris_bo *bo = NULL; @@ -1039,7 +1042,7 @@ iris_bo_alloc(struct iris_bufmgr *bufmgr, unsigned int page_size = getpagesize(); enum iris_heap heap = flags_to_heap(bufmgr, flags); bool local = heap != IRIS_HEAP_SYSTEM_MEMORY; - struct bo_cache_bucket *bucket = bucket_for_size(bufmgr, size, heap); + struct bo_cache_bucket *bucket = bucket_for_size(bufmgr, size, heap, flags); if (memzone != IRIS_MEMZONE_OTHER || (flags & BO_ALLOC_COHERENT)) flags |= BO_ALLOC_NO_SUBALLOC; @@ -1431,7 +1434,7 @@ bo_unreference_final(struct iris_bo *bo, time_t time) bucket = NULL; if (bo->real.reusable) - bucket = bucket_for_size(bufmgr, bo->size, bo->real.heap); + bucket = bucket_for_size(bufmgr, bo->size, bo->real.heap, 0); /* Put the buffer into our internal cache for reuse if we can. */ if (bucket && iris_bo_madvise(bo, IRIS_MADVICE_DONT_NEED)) { bo->real.free_time = time; @@ -2075,9 +2078,9 @@ add_bucket(struct iris_bufmgr *bufmgr, int size, enum iris_heap heap) list_inithead(&buckets[i].head); buckets[i].size = size; - assert(bucket_for_size(bufmgr, size, heap) == &buckets[i]); - assert(bucket_for_size(bufmgr, size - 2048, heap) == &buckets[i]); - assert(bucket_for_size(bufmgr, size + 1, heap) != &buckets[i]); + assert(bucket_for_size(bufmgr, size, heap, 0) == &buckets[i]); + assert(bucket_for_size(bufmgr, size - 2048, heap, 0) == &buckets[i]); + assert(bucket_for_size(bufmgr, size + 1, heap, 0) != &buckets[i]); } static void -- 2.7.4