iris: Don't mark protected bo as reusable
authorJosé Roberto de Souza <jose.souza@intel.com>
Thu, 9 Mar 2023 19:00:10 +0000 (11:00 -0800)
committerMarge Bot <emma+marge@anholt.net>
Fri, 10 Mar 2023 18:59:59 +0000 (18:59 +0000)
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 <jose.souza@intel.com>
Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21824>

src/gallium/drivers/iris/iris_bufmgr.c

index 17dc704..fd4277c 100644 (file)
@@ -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