[Mesa-dev] [PATCH 06/18] anv/allocator: Roll fixed_size_state_pool into state_pool

Jason Ekstrand jason at jlekstrand.net
Wed Apr 26 14:35:05 UTC 2017


The helper functions aren't really gaining us as much as they claim and
are actually about to be in the way.
---
 src/intel/vulkan/anv_allocator.c | 85 +++++++++++++++++-----------------------
 1 file changed, 35 insertions(+), 50 deletions(-)

diff --git a/src/intel/vulkan/anv_allocator.c b/src/intel/vulkan/anv_allocator.c
index 7091fd4..a168af5 100644
--- a/src/intel/vulkan/anv_allocator.c
+++ b/src/intel/vulkan/anv_allocator.c
@@ -611,33 +611,33 @@ anv_block_pool_free(struct anv_block_pool *pool, int32_t offset)
    }
 }
 
-static void
-anv_fixed_size_state_pool_init(struct anv_fixed_size_state_pool *pool)
+void
+anv_state_pool_init(struct anv_state_pool *pool,
+                    struct anv_block_pool *block_pool)
 {
-   /* At least a cache line and must divide the block size. */
-   pool->free_list = ANV_FREE_LIST_EMPTY;
-   pool->block.next = 0;
-   pool->block.end = 0;
+   pool->block_pool = block_pool;
+   for (unsigned i = 0; i < ANV_STATE_BUCKETS; i++) {
+      pool->buckets[i].free_list = ANV_FREE_LIST_EMPTY;
+      pool->buckets[i].block.next = 0;
+      pool->buckets[i].block.end = 0;
+   }
+   VG(VALGRIND_CREATE_MEMPOOL(pool, 0, false));
 }
 
-static uint32_t
-anv_fixed_size_state_pool_alloc(struct anv_fixed_size_state_pool *pool,
-                                struct anv_block_pool *block_pool,
-                                uint32_t state_size)
+void
+anv_state_pool_finish(struct anv_state_pool *pool)
 {
-   assert(state_size >= 64 && util_is_power_of_two(state_size));
+   VG(VALGRIND_DESTROY_MEMPOOL(pool));
+}
 
-   int32_t offset;
+static uint32_t
+anv_fixed_size_state_pool_alloc_new(struct anv_fixed_size_state_pool *pool,
+                                    struct anv_block_pool *block_pool,
+                                    uint32_t state_size)
+{
    struct anv_block_state block, old, new;
+   uint32_t offset;
 
-   /* Try free list first. */
-   if (anv_free_list_pop(&pool->free_list, &block_pool->map, &offset)) {
-      assert(offset >= 0);
-      return offset;
-   }
-
-   /* If free list was empty (or somebody raced us and took the items) we
-    * allocate a new item from the end of the block */
  restart:
    block.u64 = __sync_fetch_and_add(&pool->block.u64, state_size);
 
@@ -657,31 +657,6 @@ anv_fixed_size_state_pool_alloc(struct anv_fixed_size_state_pool *pool,
    }
 }
 
-static void
-anv_fixed_size_state_pool_free(struct anv_fixed_size_state_pool *pool,
-                               struct anv_block_pool *block_pool,
-                               uint32_t offset)
-{
-   anv_free_list_push(&pool->free_list, block_pool->map, offset);
-}
-
-void
-anv_state_pool_init(struct anv_state_pool *pool,
-                    struct anv_block_pool *block_pool)
-{
-   pool->block_pool = block_pool;
-   for (unsigned i = 0; i < ANV_STATE_BUCKETS; i++) {
-      anv_fixed_size_state_pool_init(&pool->buckets[i]);
-   }
-   VG(VALGRIND_CREATE_MEMPOOL(pool, 0, false));
-}
-
-void
-anv_state_pool_finish(struct anv_state_pool *pool)
-{
-   VG(VALGRIND_DESTROY_MEMPOOL(pool));
-}
-
 static struct anv_state
 anv_state_pool_alloc_no_vg(struct anv_state_pool *pool,
                            uint32_t size, uint32_t align)
@@ -694,9 +669,19 @@ anv_state_pool_alloc_no_vg(struct anv_state_pool *pool,
 
    struct anv_state state;
    state.alloc_size = 1 << size_log2;
-   state.offset = anv_fixed_size_state_pool_alloc(&pool->buckets[bucket],
-                                                  pool->block_pool,
-                                                  state.alloc_size);
+
+   /* Try free list first. */
+   if (anv_free_list_pop(&pool->buckets[bucket].free_list,
+                         &pool->block_pool->map, &state.offset)) {
+      assert(state.offset >= 0);
+      goto done;
+   }
+
+   state.offset = anv_fixed_size_state_pool_alloc_new(&pool->buckets[bucket],
+                                                      pool->block_pool,
+                                                      state.alloc_size);
+
+done:
    state.map = pool->block_pool->map + state.offset;
    return state;
 }
@@ -721,8 +706,8 @@ anv_state_pool_free_no_vg(struct anv_state_pool *pool, struct anv_state state)
           size_log2 <= ANV_MAX_STATE_SIZE_LOG2);
    unsigned bucket = size_log2 - ANV_MIN_STATE_SIZE_LOG2;
 
-   anv_fixed_size_state_pool_free(&pool->buckets[bucket],
-                                  pool->block_pool, state.offset);
+   anv_free_list_push(&pool->buckets[bucket].free_list,
+                      pool->block_pool->map, state.offset);
 }
 
 void
-- 
2.5.0.400.gff86faf



More information about the mesa-dev mailing list