[PATCH 05/23] drm/via: track user->memblock mapping with idr

James Simmons jsimmons at infradead.org
Wed Dec 7 08:22:25 PST 2011


> Massive indirection through a hashtable for a simple key->pointer
> look-up actually just adds bloat.
> 
> Signed-off-by: Daniel Vetter <daniel.vetter at ffwll.ch>
> ---
>  drivers/gpu/drm/via/via_drv.h |    2 +
>  drivers/gpu/drm/via/via_map.c |    1 +
>  drivers/gpu/drm/via/via_mm.c  |   61 +++++++++++++++++++++++++++++++----------
>  3 files changed, 49 insertions(+), 15 deletions(-)

Acked-by: James Simmons <jsimmons at infradead.org>
 
> diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
> index 9cf87d9..108ea71 100644
> --- a/drivers/gpu/drm/via/via_drv.h
> +++ b/drivers/gpu/drm/via/via_drv.h
> @@ -91,6 +91,8 @@ typedef struct drm_via_private {
>  	struct drm_sman sman;
>  	int vram_initialized;
>  	int agp_initialized;
> +	/** Mapping of userspace keys to mm objects */
> +	struct idr object_idr;
>  	unsigned long vram_offset;
>  	unsigned long agp_offset;
>  	drm_via_blitq_t blit_queues[VIA_NUM_BLIT_ENGINES];
> diff --git a/drivers/gpu/drm/via/via_map.c b/drivers/gpu/drm/via/via_map.c
> index 6cca9a7..b09f659 100644
> --- a/drivers/gpu/drm/via/via_map.c
> +++ b/drivers/gpu/drm/via/via_map.c
> @@ -104,6 +104,7 @@ int via_driver_load(struct drm_device *dev, unsigned long chipset)
>  
>  	dev_priv->chipset = chipset;
>  
> +	idr_init(&dev->object_name_idr);
>  	ret = drm_sman_init(&dev_priv->sman, 2, 12, 8);
>  	if (ret) {
>  		kfree(dev_priv);
> diff --git a/drivers/gpu/drm/via/via_mm.c b/drivers/gpu/drm/via/via_mm.c
> index ea3d621..af9e771 100644
> --- a/drivers/gpu/drm/via/via_mm.c
> +++ b/drivers/gpu/drm/via/via_mm.c
> @@ -118,7 +118,7 @@ int via_mem_alloc(struct drm_device *dev, void *data,
>  		  struct drm_file *file)
>  {
>  	drm_via_mem_t *mem = data;
> -	int retval = 0;
> +	int retval = 0, user_key;
>  	struct drm_memblock_item *item;
>  	drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private;
>  	struct via_file_private *file_priv = file->driver_priv;
> @@ -139,24 +139,46 @@ int via_mem_alloc(struct drm_device *dev, void *data,
>  
>  	tmpSize = (mem->size + VIA_MM_ALIGN_MASK) >> VIA_MM_ALIGN_SHIFT;
>  	item = drm_sman_alloc(&dev_priv->sman, mem->type, tmpSize, 0, 0);
> +	if (!item) {
> +		retval = -ENOMEM;
> +		goto fail_alloc;
> +	}
>  
> -	if (item) {
> -		INIT_LIST_HEAD(&item->owner_list);
> -		list_add(&item->owner_list, &file_priv->obj_list);
> -		mem->offset = ((mem->type == VIA_MEM_VIDEO) ?
> -			      dev_priv->vram_offset : dev_priv->agp_offset) +
> -		    (item->mm->
> -		     offset(item->mm, item->mm_info) << VIA_MM_ALIGN_SHIFT);
> -		mem->index = item->user_hash.key;
> -	} else {
> -		mem->offset = 0;
> -		mem->size = 0;
> -		mem->index = 0;
> -		DRM_DEBUG("Video memory allocation failed\n");
> +again:
> +	if (idr_pre_get(&dev_priv->object_idr, GFP_KERNEL) == 0) {
>  		retval = -ENOMEM;
> +		goto fail_idr;
>  	}
> +
> +	/* do the allocation under our spinlock */
> +	retval = idr_get_new_above(&dev_priv->object_idr, item, 1, &user_key);
> +	if (retval == -EAGAIN)
> +		goto again;
> +	if (retval)
> +		goto fail_idr;
> +
> +	INIT_LIST_HEAD(&item->owner_list);
> +	list_add(&item->owner_list, &file_priv->obj_list);
>  	mutex_unlock(&dev->struct_mutex);
>  
> +	mem->offset = ((mem->type == VIA_MEM_VIDEO) ?
> +		      dev_priv->vram_offset : dev_priv->agp_offset) +
> +	    (item->mm->
> +	     offset(item->mm, item->mm_info) << VIA_MM_ALIGN_SHIFT);
> +	mem->index = user_key;
> +
> +	return 0;
> +
> +fail_idr:
> +	drm_sman_free(item);
> +fail_alloc:
> +	mutex_unlock(&dev->struct_mutex);
> +
> +	mem->offset = 0;
> +	mem->size = 0;
> +	mem->index = 0;
> +	DRM_DEBUG("Video memory allocation failed\n");
> +
>  	return retval;
>  }
>  
> @@ -164,11 +186,20 @@ int via_mem_free(struct drm_device *dev, void *data, struct drm_file *file_priv)
>  {
>  	drm_via_private_t *dev_priv = dev->dev_private;
>  	drm_via_mem_t *mem = data;
> +	struct drm_memblock_item *obj;
>  	int ret;
>  
>  	mutex_lock(&dev->struct_mutex);
> -	ret = drm_sman_free_key(&dev_priv->sman, mem->index);
> +	obj = idr_find(&dev_priv->object_idr, mem->index);
> +	if (obj == NULL) {
> +		mutex_unlock(&dev->struct_mutex);
> +		return -EINVAL;
> +	}
> +
> +	idr_remove(&dev_priv->object_idr, mem->index);
> +	drm_sman_free(obj);
>  	mutex_unlock(&dev->struct_mutex);
> +
>  	DRM_DEBUG("free = 0x%lx\n", mem->index);
>  
>  	return ret;
> -- 
> 1.7.7.1
> 
> _______________________________________________
> dri-devel mailing list
> dri-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/dri-devel
> 


More information about the dri-devel mailing list