<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, May 3, 2017 at 9:59 AM, Juan A. Suarez Romero <span dir="ltr"><<a href="mailto:jasuarez@igalia.com" target="_blank">jasuarez@igalia.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On Wed, 2017-04-26 at 07:35 -0700, Jason Ekstrand wrote:<br>
> ---<br>
> src/intel/vulkan/anv_<wbr>allocator.c | 23 ++++++++++-------------<br>
> src/intel/vulkan/tests/block_<wbr>pool_no_free.c | 7 ++++---<br>
> 2 files changed, 14 insertions(+), 16 deletions(-)<br>
><br>
> diff --git a/src/intel/vulkan/anv_<wbr>allocator.c b/src/intel/vulkan/anv_<wbr>allocator.c<br>
> index fa7101b..e58734b 100644<br>
> --- a/src/intel/vulkan/anv_<wbr>allocator.c<br>
> +++ b/src/intel/vulkan/anv_<wbr>allocator.c<br>
> @@ -430,8 +430,7 @@ anv_block_pool_expand_range(<wbr>struct anv_block_pool *pool,<br>
> * the pool and a 4K CPU page.<br>
> */<br>
> static uint32_t<br>
> -anv_block_pool_grow(struct anv_block_pool *pool, struct anv_block_state *state,<br>
> - uint32_t block_size)<br>
> +anv_block_pool_grow(struct anv_block_pool *pool, struct anv_block_state *state)<br>
> {<br>
> uint32_t size;<br>
> VkResult result = VK_SUCCESS;<br>
> @@ -470,7 +469,7 @@ anv_block_pool_grow(struct anv_block_pool *pool, struct anv_block_state *state,<br>
><br>
> if (old_size == 0) {<br>
> /* This is the first allocation */<br>
> - size = MAX2(32 * block_size, PAGE_SIZE);<br>
> + size = 32 * PAGE_SIZE;<br>
> } else {<br>
> size = old_size * 2;<br>
> }<br>
> @@ -498,10 +497,8 @@ anv_block_pool_grow(struct anv_block_pool *pool, struct anv_block_state *state,<br>
> */<br>
> center_bo_offset = ((uint64_t)size * back_used) / total_used;<br>
><br>
> - /* Align down to a multiple of both the block size and page size */<br>
> - uint32_t granularity = MAX2(block_size, PAGE_SIZE);<br>
> - assert(util_is_power_of_two(<wbr>granularity));<br>
> - center_bo_offset &= ~(granularity - 1);<br>
> + /* Align down to a multiple of both the page size */<br>
</div></div> ^^^^<br>
[...] multiple of the page size */<span class=""><br></span></blockquote><div><br></div><div>Fixed. Thanks.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">
> + center_bo_offset &= ~(PAGE_SIZE - 1);<br>
><br>
> assert(center_bo_offset >= back_used);<br>
><br>
> @@ -514,7 +511,6 @@ anv_block_pool_grow(struct anv_block_pool *pool, struct anv_block_state *state,<br>
> center_bo_offset = size - pool->state.end;<br>
> }<br>
><br>
> - assert(center_bo_offset % block_size == 0);<br>
> assert(center_bo_offset % PAGE_SIZE == 0);<br>
><br>
> result = anv_block_pool_expand_range(<wbr>pool, center_bo_offset, size);<br>
> @@ -545,21 +541,22 @@ anv_block_pool_alloc_new(<wbr>struct anv_block_pool *pool,<br>
> {<br>
> struct anv_block_state state, old, new;<br>
><br>
> - assert(util_is_power_of_two(<wbr>block_size));<br>
<br>
</span>Aren't we interesting on restricting the blocksize to power-of-two<br>
sizes?<br></blockquote><div><br></div><div>We could restrict it, but it's not required. It does need to be a multiple of PAGE_SIZE but, other than that, we don't really have any actual restrictions. It's always been a bit arbitrary. Of course, the restriction on the sizes of states is not arbitrary because we have to be able to split them.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
In any case, Reviewed-by: Juan A. Suarez Romero <<a href="mailto:jasuarez@igalia.com">jasuarez@igalia.com</a>><br><div><div class="h5"></div></div></blockquote><div><br></div><div>Thanks!<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5">
> -<br>
> while (1) {<br>
> state.u64 = __sync_fetch_and_add(&pool_<wbr>state->u64, block_size);<br>
> - if (state.next < state.end) {<br>
> + if (state.next + block_size <= state.end) {<br>
> assert(pool->map);<br>
> return state.next;<br>
> - } else if (state.next == state.end) {<br>
> + } else if (state.next <= state.end) {<br>
> /* We allocated the first block outside the pool so we have to grow<br>
> * the pool. pool_state->next acts a mutex: threads who try to<br>
> * allocate now will get block indexes above the current limit and<br>
> * hit futex_wait below.<br>
> */<br>
> new.next = state.next + block_size;<br>
> - new.end = anv_block_pool_grow(pool, pool_state, block_size);<br>
> + do {<br>
> + new.end = anv_block_pool_grow(pool, pool_state);<br>
> + } while (new.end < new.next);<br>
> +<br>
> old.u64 = __sync_lock_test_and_set(&<wbr>pool_state->u64, new.u64);<br>
> if (old.next != state.next)<br>
> futex_wake(&pool_state->end, INT_MAX);<br>
> diff --git a/src/intel/vulkan/tests/<wbr>block_pool_no_free.c b/src/intel/vulkan/tests/<wbr>block_pool_no_free.c<br>
> index 6e6fc68..f5ace7f 100644<br>
> --- a/src/intel/vulkan/tests/<wbr>block_pool_no_free.c<br>
> +++ b/src/intel/vulkan/tests/<wbr>block_pool_no_free.c<br>
> @@ -25,7 +25,6 @@<br>
><br>
> #include "anv_private.h"<br>
><br>
> -#define BLOCK_SIZE 16<br>
> #define NUM_THREADS 16<br>
> #define BLOCKS_PER_THREAD 1024<br>
> #define NUM_RUNS 64<br>
> @@ -42,16 +41,18 @@ struct job {<br>
> static void *alloc_blocks(void *_job)<br>
> {<br>
> struct job *job = _job;<br>
> + uint32_t job_id = job - jobs;<br>
> + uint32_t block_size = 16 * ((job_id % 4) + 1);<br>
> int32_t block, *data;<br>
><br>
> for (unsigned i = 0; i < BLOCKS_PER_THREAD; i++) {<br>
> - block = anv_block_pool_alloc(job-><wbr>pool, BLOCK_SIZE);<br>
> + block = anv_block_pool_alloc(job-><wbr>pool, block_size);<br>
> data = job->pool->map + block;<br>
> *data = block;<br>
> assert(block >= 0);<br>
> job->blocks[i] = block;<br>
><br>
> - block = anv_block_pool_alloc_back(job-<wbr>>pool, BLOCK_SIZE);<br>
> + block = anv_block_pool_alloc_back(job-<wbr>>pool, block_size);<br>
> data = job->pool->map + block;<br>
> *data = block;<br>
> assert(block < 0);<br>
</div></div>______________________________<wbr>_________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev" rel="noreferrer" target="_blank">https://lists.freedesktop.org/<wbr>mailman/listinfo/mesa-dev</a><br>
</blockquote></div><br></div></div>