[Intel-gfx] [PATCH 27/49] drm/i915: Use a separate slab for requests

Daniel Vetter daniel at ffwll.ch
Fri Mar 27 07:20:08 PDT 2015


On Fri, Mar 27, 2015 at 11:01:59AM +0000, Chris Wilson wrote:
> requests are even more frequently allocated than objects and equally
> benefit from having a dedicated slab.
> 
> Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>

vmas, while we're at it?
-Daniel

> ---
>  drivers/gpu/drm/i915/i915_dma.c         | 12 ++++++++----
>  drivers/gpu/drm/i915/i915_drv.h         |  5 ++++-
>  drivers/gpu/drm/i915/i915_gem.c         | 26 ++++++++++++++++++++++----
>  drivers/gpu/drm/i915/intel_lrc.c        | 11 +++++------
>  drivers/gpu/drm/i915/intel_ringbuffer.c |  9 ++++-----
>  5 files changed, 43 insertions(+), 20 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
> index 8f5428b46a27..180b5d92b279 100644
> --- a/drivers/gpu/drm/i915/i915_dma.c
> +++ b/drivers/gpu/drm/i915/i915_dma.c
> @@ -1006,8 +1006,10 @@ out_regs:
>  put_bridge:
>  	pci_dev_put(dev_priv->bridge_dev);
>  free_priv:
> -	if (dev_priv->slab)
> -		kmem_cache_destroy(dev_priv->slab);
> +	if (dev_priv->requests)
> +		kmem_cache_destroy(dev_priv->requests);
> +	if (dev_priv->objects)
> +		kmem_cache_destroy(dev_priv->objects);
>  	kfree(dev_priv);
>  	return ret;
>  }
> @@ -1090,8 +1092,10 @@ int i915_driver_unload(struct drm_device *dev)
>  	if (dev_priv->regs != NULL)
>  		pci_iounmap(dev->pdev, dev_priv->regs);
>  
> -	if (dev_priv->slab)
> -		kmem_cache_destroy(dev_priv->slab);
> +	if (dev_priv->requests)
> +		kmem_cache_destroy(dev_priv->requests);
> +	if (dev_priv->objects)
> +		kmem_cache_destroy(dev_priv->objects);
>  
>  	pci_dev_put(dev_priv->bridge_dev);
>  	kfree(dev_priv);
> diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
> index ee51540e169a..b728250d6550 100644
> --- a/drivers/gpu/drm/i915/i915_drv.h
> +++ b/drivers/gpu/drm/i915/i915_drv.h
> @@ -1556,7 +1556,8 @@ struct i915_virtual_gpu {
>  
>  struct drm_i915_private {
>  	struct drm_device *dev;
> -	struct kmem_cache *slab;
> +	struct kmem_cache *objects;
> +	struct kmem_cache *requests;
>  
>  	const struct intel_device_info info;
>  
> @@ -2052,6 +2053,7 @@ struct drm_i915_gem_request {
>  	struct kref ref;
>  
>  	/** On Which ring this request was generated */
> +	struct drm_i915_private *i915;
>  	struct intel_engine_cs *ring;
>  
>  	/** GEM sequence number associated with this request. */
> @@ -2118,6 +2120,7 @@ struct drm_i915_gem_request {
>  	struct list_head execlist_link;
>  };
>  
> +struct drm_i915_gem_request *i915_gem_request_alloc(struct drm_i915_private *i915);
>  void i915_gem_request_free(struct kref *req_ref);
>  
>  static inline uint32_t
> diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
> index 5366162e4983..900cbe17c49a 100644
> --- a/drivers/gpu/drm/i915/i915_gem.c
> +++ b/drivers/gpu/drm/i915/i915_gem.c
> @@ -381,13 +381,13 @@ out:
>  void *i915_gem_object_alloc(struct drm_device *dev)
>  {
>  	struct drm_i915_private *dev_priv = dev->dev_private;
> -	return kmem_cache_zalloc(dev_priv->slab, GFP_KERNEL);
> +	return kmem_cache_zalloc(dev_priv->objects, GFP_KERNEL);
>  }
>  
>  void i915_gem_object_free(struct drm_i915_gem_object *obj)
>  {
>  	struct drm_i915_private *dev_priv = obj->base.dev->dev_private;
> -	kmem_cache_free(dev_priv->slab, obj);
> +	kmem_cache_free(dev_priv->objects, obj);
>  }
>  
>  static int
> @@ -2567,6 +2567,19 @@ static void i915_set_reset_status(struct drm_i915_private *dev_priv,
>  	}
>  }
>  
> +struct drm_i915_gem_request *i915_gem_request_alloc(struct drm_i915_private *i915)
> +{
> +	struct drm_i915_gem_request *rq;
> +
> +	rq = kmem_cache_zalloc(i915->requests, GFP_KERNEL);
> +	if (rq == NULL)
> +		return ERR_PTR(-ENOMEM);
> +
> +	kref_init(&rq->ref);
> +	rq->i915 = i915;
> +	return rq;
> +}
> +
>  void i915_gem_request_free(struct kref *req_ref)
>  {
>  	struct drm_i915_gem_request *req = container_of(req_ref,
> @@ -2577,7 +2590,7 @@ void i915_gem_request_free(struct kref *req_ref)
>  		i915_gem_context_unreference(ctx);
>  	}
>  
> -	kfree(req);
> +	kmem_cache_free(req->i915->requests, req);
>  }
>  
>  struct drm_i915_gem_request *
> @@ -5110,11 +5123,16 @@ i915_gem_load(struct drm_device *dev)
>  	struct drm_i915_private *dev_priv = dev->dev_private;
>  	int i;
>  
> -	dev_priv->slab =
> +	dev_priv->objects =
>  		kmem_cache_create("i915_gem_object",
>  				  sizeof(struct drm_i915_gem_object), 0,
>  				  SLAB_HWCACHE_ALIGN,
>  				  NULL);
> +	dev_priv->requests =
> +		kmem_cache_create("i915_gem_request",
> +				  sizeof(struct drm_i915_gem_request), 0,
> +				  SLAB_HWCACHE_ALIGN,
> +				  NULL);
>  
>  	INIT_LIST_HEAD(&dev_priv->vm_list);
>  	i915_init_vm(dev_priv, &dev_priv->gtt.base);
> diff --git a/drivers/gpu/drm/i915/intel_lrc.c b/drivers/gpu/drm/i915/intel_lrc.c
> index a013239f5e26..5e51ed5232e8 100644
> --- a/drivers/gpu/drm/i915/intel_lrc.c
> +++ b/drivers/gpu/drm/i915/intel_lrc.c
> @@ -742,24 +742,23 @@ static int logical_ring_alloc_request(struct intel_engine_cs *ring,
>  	if (ring->outstanding_lazy_request)
>  		return 0;
>  
> -	request = kzalloc(sizeof(*request), GFP_KERNEL);
> -	if (request == NULL)
> -		return -ENOMEM;
> +	request = i915_gem_request_alloc(dev_private);
> +	if (IS_ERR(request))
> +		return PTR_ERR(request);
>  
>  	ret = intel_lr_context_pin(ring, ctx);
>  	if (ret) {
> -		kfree(request);
> +		i915_gem_request_free(&request->ref);
>  		return ret;
>  	}
>  
> -	kref_init(&request->ref);
>  	request->ring = ring;
>  	request->uniq = dev_private->request_uniq++;
>  
>  	ret = i915_gem_get_seqno(ring->dev, &request->seqno);
>  	if (ret) {
>  		intel_lr_context_unpin(ring, ctx);
> -		kfree(request);
> +		i915_gem_request_free(&request->ref);
>  		return ret;
>  	}
>  
> diff --git a/drivers/gpu/drm/i915/intel_ringbuffer.c b/drivers/gpu/drm/i915/intel_ringbuffer.c
> index 2e5c39123d24..f7097a80dea3 100644
> --- a/drivers/gpu/drm/i915/intel_ringbuffer.c
> +++ b/drivers/gpu/drm/i915/intel_ringbuffer.c
> @@ -2179,18 +2179,17 @@ intel_ring_alloc_request(struct intel_engine_cs *ring)
>  	if (ring->outstanding_lazy_request)
>  		return 0;
>  
> -	request = kzalloc(sizeof(*request), GFP_KERNEL);
> -	if (request == NULL)
> -		return -ENOMEM;
> +	request = i915_gem_request_alloc(dev_private);
> +	if (IS_ERR(request))
> +		return PTR_ERR(request);
>  
> -	kref_init(&request->ref);
>  	request->ring = ring;
>  	request->ringbuf = ring->buffer;
>  	request->uniq = dev_private->request_uniq++;
>  
>  	ret = i915_gem_get_seqno(ring->dev, &request->seqno);
>  	if (ret) {
> -		kfree(request);
> +		i915_gem_request_free(&request->ref);
>  		return ret;
>  	}
>  
> -- 
> 2.1.4
> 
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/intel-gfx

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch


More information about the Intel-gfx mailing list