[Mesa-dev] [PATCH 01/18] anv/allocator: Add no-valgrind versions of state_pool_alloc/free

Jason Ekstrand jason at jlekstrand.net
Fri Apr 28 03:34:00 UTC 2017


On Thu, Apr 27, 2017 at 9:20 AM, Juan A. Suarez Romero <jasuarez at igalia.com>
wrote:

> On Wed, 2017-04-26 at 07:35 -0700, Jason Ekstrand wrote:
> > ---
> >  src/intel/vulkan/anv_allocator.c | 24 +++++++++++++++++++-----
> >  1 file changed, 19 insertions(+), 5 deletions(-)
> >
> > diff --git a/src/intel/vulkan/anv_allocator.c b/src/intel/vulkan/anv_
> allocator.c
> > index 784191e..594cf49 100644
> > --- a/src/intel/vulkan/anv_allocator.c
> > +++ b/src/intel/vulkan/anv_allocator.c
> > @@ -684,8 +684,9 @@ anv_state_pool_finish(struct anv_state_pool *pool)
> >     VG(VALGRIND_DESTROY_MEMPOOL(pool));
> >  }
> >
> > -struct anv_state
> > -anv_state_pool_alloc(struct anv_state_pool *pool, size_t size, size_t
> align)
> > +static struct anv_state
> > +anv_state_pool_alloc_no_vg(struct anv_state_pool *pool,
> > +                           size_t size, size_t align)
> >  {
> >     unsigned size_log2 = ilog2_round_up(size < align ? align : size);
> >     assert(size_log2 <= ANV_MAX_STATE_SIZE_LOG2);
> > @@ -698,12 +699,19 @@ anv_state_pool_alloc(struct anv_state_pool *pool,
> size_t size, size_t align)
> >     state.offset = anv_fixed_size_state_pool_
> alloc(&pool->buckets[bucket],
> >                                                    pool->block_pool);
> >     state.map = pool->block_pool->map + state.offset;
> > +   return state;
> > +}
> > +
> > +struct anv_state
> > +anv_state_pool_alloc(struct anv_state_pool *pool, size_t size, size_t
> align)
> > +{
> > +   struct anv_state state = anv_state_pool_alloc_no_vg(pool, size,
> align);
> >     VG(VALGRIND_MEMPOOL_ALLOC(pool, state.map, size));
> >     return state;
> >  }
> >
>
>
> Is it really worth to have a different function? I would understand if
> the valgrind and no-valgrind where totally different.
>

The valgrind step has to be done at the last possible moment before we hand
the pointer back to the "user".  With the state stream pulling from the
state pool, this means that, for anything allocated by the stream, it needs
to be done by the stream and not the pool.  These helpers let us skip the
valgrind alloc/free markers when we're pulling through the stream until
state_stream_alloc/free.

--Jason


> >
> > -void
> > -anv_state_pool_free(struct anv_state_pool *pool, struct anv_state state)
> > +static void
> > +anv_state_pool_free_no_vg(struct anv_state_pool *pool, struct
> anv_state state)
> >  {
> >     assert(util_is_power_of_two(state.alloc_size));
> >     unsigned size_log2 = ilog2_round_up(state.alloc_size);
> > @@ -711,11 +719,17 @@ anv_state_pool_free(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;
> >
> > -   VG(VALGRIND_MEMPOOL_FREE(pool, state.map));
> >     anv_fixed_size_state_pool_free(&pool->buckets[bucket],
> >                                    pool->block_pool, state.offset);
> >  }
> >
> > +void
> > +anv_state_pool_free(struct anv_state_pool *pool, struct anv_state state)
> > +{
> > +   VG(VALGRIND_MEMPOOL_FREE(pool, state.map));
> > +   anv_state_pool_free_no_vg(pool, state);
> > +}
> > +
> >  #define NULL_BLOCK 1
> >  struct anv_state_stream_block {
> >     /* The next block */
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20170427/1fd5c9ef/attachment.html>


More information about the mesa-dev mailing list