[Mesa-dev] [PATCH 08/21] anv/allocator: Add a BO cache

Chad Versace chadversary at chromium.org
Thu Apr 27 23:31:51 UTC 2017


On Fri 14 Apr 2017, Jason Ekstrand wrote:
> This cache allows us to easily ensure that we have a unique anv_bo for
> each gem handle.  We'll need this in order to support multiple-import of
> memory objects and semaphores.
> 
> v2 (Jason Ekstrand):
>  - Reject BO imports if the size doesn't match the prime fd size as
>    reported by lseek().
> ---
>  src/intel/vulkan/anv_allocator.c                   | 257 +++++++++++++++++++++
>  src/intel/vulkan/anv_private.h                     |  21 ++


>  .../drivers/dri/i965/brw_nir_trig_workarounds.c    | 191 +++++++++++++++

Hmm... nir trig workarounds. That's cool :)

>  3 files changed, 469 insertions(+)
>  create mode 100644 src/mesa/drivers/dri/i965/brw_nir_trig_workarounds.c



> +VkResult
> +anv_bo_cache_init(struct anv_bo_cache *cache)
> +{
> +   cache->bo_map = _mesa_hash_table_create(NULL, _mesa_hash_pointer,
> +                                           _mesa_key_pointer_equal);
> +   if (!cache->bo_map)
> +      return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
> +
> +   if (pthread_mutex_init(&cache->mutex, NULL)) {
> +      _mesa_hash_table_destroy(cache->bo_map, NULL);
> +      return vk_errorf(VK_ERROR_OUT_OF_HOST_MEMORY,
> +                       "pthread_mutex_inti failed: %m");

Typo s/inti/init/

> +   }


> +static struct anv_bo *
> +anv_bo_cache_lookup(struct anv_bo_cache *cache, uint32_t gem_handle)
> +{
> +   pthread_mutex_lock(&cache->mutex);
> +
> +   struct anv_cached_bo *bo = anv_bo_cache_lookup_locked(cache, gem_handle);
> +
> +   pthread_mutex_unlock(&cache->mutex);
> +
> +   return &bo->bo;

This correctly returns NULL when the lookup fails, but only by luck
because offset(struct anv_cache_bo, bo) == 0. It should really be
rewritten to avoid the dereference after lookup failures.

> +}

Fix those three issues, and this patch will be
Reviewed-by: Chad Versace <chadversary at chromium.org>



More information about the mesa-dev mailing list