panfrost: Make pool slab size configurable
authorAlyssa Rosenzweig <alyssa@collabora.com>
Wed, 12 May 2021 22:47:25 +0000 (18:47 -0400)
committerMarge Bot <eric+marge@anholt.net>
Tue, 18 May 2021 19:19:01 +0000 (19:19 +0000)
Different pools have different expected sizes.

Signed-off-by: Alyssa Rosenzweig <alyssa@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10866>

src/gallium/drivers/panfrost/pan_job.c
src/panfrost/lib/pan_blitter.c
src/panfrost/lib/pan_device.h
src/panfrost/lib/pan_indirect_draw.c
src/panfrost/lib/pan_pool.c
src/panfrost/lib/pan_pool.h

index 225d602..cabc772 100644 (file)
@@ -85,13 +85,13 @@ panfrost_batch_init(struct panfrost_context *ctx,
 
         /* Preallocate the main pool, since every batch has at least one job
          * structure so it will be used */
-        panfrost_pool_init(&batch->pool, NULL, dev, 0, "Batch pool", true, true);
+        panfrost_pool_init(&batch->pool, NULL, dev, 0, 65536, "Batch pool", true, true);
 
         /* Don't preallocate the invisible pool, since not every batch will use
          * the pre-allocation, particularly if the varyings are larger than the
          * preallocation and a reallocation is needed after anyway. */
         panfrost_pool_init(&batch->invisible_pool, NULL, dev,
-                        PAN_BO_INVISIBLE, "Varyings", false, true);
+                        PAN_BO_INVISIBLE, 65536, "Varyings", false, true);
 
         panfrost_batch_add_fbo_bos(batch);
 }
index fe7b991..9ca47a4 100644 (file)
@@ -1348,7 +1348,7 @@ pan_blit_ctx_init(struct panfrost_device *dev,
                   struct pan_blit_context *ctx)
 {
         memset(ctx, 0, sizeof(*ctx));
-        panfrost_pool_init(&ctx->pool, NULL, dev, 0, "Blitter pool", false, true);
+        panfrost_pool_init(&ctx->pool, NULL, dev, 0, 65536, "Blitter pool", false, true);
 
         ctx->z_scale = (float)(info->dst.end.z - info->dst.start.z + 1) /
                        (info->src.end.z - info->src.start.z + 1);
@@ -1599,11 +1599,11 @@ pan_blitter_init(struct panfrost_device *dev)
                 _mesa_hash_table_create(NULL, pan_blit_blend_shader_key_hash,
                                         pan_blit_blend_shader_key_equal);
         panfrost_pool_init(&dev->blitter.shaders.pool, NULL, dev,
-                           PAN_BO_EXECUTE, "Blitter shaders", false, true);
+                           PAN_BO_EXECUTE, 65536, "Blitter shaders", false, true);
         pthread_mutex_init(&dev->blitter.shaders.lock, NULL);
         pan_blitter_prefill_blit_shader_cache(dev);
 
-        panfrost_pool_init(&dev->blitter.rsds.pool, NULL, dev, 0, "Blitter RSDs", false, true);
+        panfrost_pool_init(&dev->blitter.rsds.pool, NULL, dev, 0, 65536, "Blitter RSDs", false, true);
         dev->blitter.rsds.rsds =
                 _mesa_hash_table_create(NULL, pan_blit_rsd_key_hash,
                                         pan_blit_rsd_key_equal);
index a6b40d4..ae1d90e 100644 (file)
@@ -49,22 +49,6 @@ extern "C" {
 /* Driver limits */
 #define PAN_MAX_CONST_BUFFERS 16
 
-/* Transient slab size. This is a balance between fragmentation against cache
- * locality and ease of bookkeeping */
-
-#define TRANSIENT_SLAB_PAGES (16) /* 64kb */
-#define TRANSIENT_SLAB_SIZE (4096 * TRANSIENT_SLAB_PAGES)
-
-/* Maximum number of transient slabs so we don't need dynamic arrays. Most
- * interesting Mali boards are 4GB RAM max, so if the entire RAM was filled
- * with transient slabs, you could never exceed (4GB / TRANSIENT_SLAB_SIZE)
- * allocations anyway. By capping, we can use a fixed-size bitset for tracking
- * free slabs, eliminating quite a bit of complexity. We can pack the free
- * state of 8 slabs into a single byte, so for 128kb transient slabs the bitset
- * occupies a cheap 4kb of memory */
-
-#define MAX_TRANSIENT_SLABS (1024*1024 / TRANSIENT_SLAB_PAGES)
-
 /* How many power-of-two levels in the BO cache do we want? 2^12
  * minimum chosen as it is the page size that all allocations are
  * rounded to */
index 6156038..c34259a 100644 (file)
@@ -1372,7 +1372,7 @@ panfrost_init_indirect_draw_shaders(struct panfrost_device *dev)
          */
         pthread_mutex_init(&dev->indirect_draw_shaders.lock, NULL);
         panfrost_pool_init(&dev->indirect_draw_shaders.bin_pool, NULL, dev,
-                           PAN_BO_EXECUTE, "Indirect draw shaders", false, true);
+                           PAN_BO_EXECUTE, 65536, "Indirect draw shaders", false, true);
 }
 
 void
index b2044d3..530d2f0 100644 (file)
@@ -67,7 +67,7 @@ panfrost_pool_alloc_backing(struct pan_pool *pool, size_t bo_sz)
 void
 panfrost_pool_init(struct pan_pool *pool, void *memctx,
                    struct panfrost_device *dev,
-                   unsigned create_flags, const char *label,
+                   unsigned create_flags, size_t slab_size, const char *label,
                    bool prealloc, bool owned)
 {
         memset(pool, 0, sizeof(*pool));
@@ -75,12 +75,13 @@ panfrost_pool_init(struct pan_pool *pool, void *memctx,
         pool->create_flags = create_flags;
         pool->owned = owned;
         pool->label = label;
+        pool->slab_size = slab_size;
 
         if (owned)
                 util_dynarray_init(&pool->bos, memctx);
 
         if (prealloc)
-                panfrost_pool_alloc_backing(pool, TRANSIENT_SLAB_SIZE);
+                panfrost_pool_alloc_backing(pool, pool->slab_size);
 }
 
 void
@@ -128,9 +129,9 @@ panfrost_pool_alloc_aligned(struct pan_pool *pool, size_t sz, unsigned alignment
         unsigned offset = ALIGN_POT(pool->transient_offset, alignment);
 
         /* If we don't fit, allocate a new backing */
-        if (unlikely(bo == NULL || (offset + sz) >= TRANSIENT_SLAB_SIZE)) {
+        if (unlikely(bo == NULL || (offset + sz) >= pool->slab_size)) {
                 bo = panfrost_pool_alloc_backing(pool,
-                                ALIGN_POT(MAX2(TRANSIENT_SLAB_SIZE, sz), 4096));
+                                ALIGN_POT(MAX2(pool->slab_size, sz), 4096));
                 offset = 0;
         }
 
index f0b639a..48e6a69 100644 (file)
@@ -53,6 +53,9 @@ struct pan_pool {
         /* BO flags to use in the pool */
         unsigned create_flags;
 
+        /* Minimum size for allocated BOs. */
+        size_t slab_size;
+
         /* Mode of the pool. BO management is in the pool for owned mode, but
          * the consumed for unowned mode. */
         bool owned;
@@ -61,7 +64,8 @@ struct pan_pool {
 void
 panfrost_pool_init(struct pan_pool *pool, void *memctx,
                    struct panfrost_device *dev, unsigned create_flags,
-                   const char *label, bool prealloc, bool owned);
+                   size_t slab_size, const char *label, bool prealloc, bool
+                   owned);
 
 void
 panfrost_pool_cleanup(struct pan_pool *pool);