All of lore.kernel.org
 help / color / mirror / Atom feed
From: Daniel Vetter <daniel@ffwll.ch>
To: ankitprasad.r.sharma@intel.com
Cc: intel-gfx@lists.freedesktop.org, akash.goel@intel.com
Subject: Re: [PATCH 3/3] drm/i915: Use insert_page for pwrite_fast
Date: Wed, 18 Nov 2015 10:59:25 +0100	[thread overview]
Message-ID: <20151118095925.GG20799@phenom.ffwll.local> (raw)
In-Reply-To: <1446723959-25580-4-git-send-email-ankitprasad.r.sharma@intel.com>

On Thu, Nov 05, 2015 at 05:15:59PM +0530, ankitprasad.r.sharma@intel.com wrote:
> From: Ankitprasad Sharma <ankitprasad.r.sharma@intel.com>
> 
> In pwrite_fast, map an object page by page if obj_ggtt_pin fails. First,
> we try a nonblocking pin for the whole object (since that is fastest if
> reused), then failing that we try to grab one page in the mappable
> aperture. It also allows us to handle objects larger than the mappable
> aperture (e.g. if we need to pwrite with vGPU restricting the aperture
> to a measely 8MiB or something like that).

We already have a fallback to the shmem pwrite. Why do we need this?
-Daniel

> 
> Signed-off-by: Ankitprasad Sharma <ankitprasad.r.sharma@intel.com>
> ---
>  drivers/gpu/drm/i915/i915_gem.c | 92 ++++++++++++++++++++++++++++++-----------
>  1 file changed, 69 insertions(+), 23 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
> index bf5ef7a..9132240 100644
> --- a/drivers/gpu/drm/i915/i915_gem.c
> +++ b/drivers/gpu/drm/i915/i915_gem.c
> @@ -766,14 +766,26 @@ i915_gem_gtt_pwrite_fast(struct drm_device *dev,
>  			 struct drm_file *file)
>  {
>  	struct drm_i915_private *dev_priv = dev->dev_private;
> +	struct drm_mm_node node;
>  	ssize_t remain;
>  	loff_t offset, page_base;
>  	char __user *user_data;
> -	int page_offset, page_length, ret;
> +	int page_offset, page_length, ret, i;
> +	bool pinned = true;
>  
>  	ret = i915_gem_obj_ggtt_pin(obj, 0, PIN_MAPPABLE | PIN_NONBLOCK);
> -	if (ret)
> -		goto out;
> +	if (ret) {
> +		pinned = false;
> +		memset(&node, 0, sizeof(node));
> +		ret = drm_mm_insert_node_in_range_generic(&dev_priv->gtt.base.mm,
> +							  &node, 4096, 0,
> +							  I915_CACHE_NONE, 0,
> +							  dev_priv->gtt.mappable_end,
> +							  DRM_MM_SEARCH_DEFAULT,
> +							  DRM_MM_CREATE_DEFAULT);
> +		if (ret)
> +			goto out;
> +	}
>  
>  	ret = i915_gem_object_set_to_gtt_domain(obj, true);
>  	if (ret)
> @@ -786,42 +798,76 @@ i915_gem_gtt_pwrite_fast(struct drm_device *dev,
>  	user_data = to_user_ptr(args->data_ptr);
>  	remain = args->size;
>  
> -	offset = i915_gem_obj_ggtt_offset(obj) + args->offset;
> -
>  	intel_fb_obj_invalidate(obj, ORIGIN_GTT);
>  
> -	while (remain > 0) {
> -		/* Operation in this page
> +	if (likely(pinned)) {
> +		offset = i915_gem_obj_ggtt_offset(obj) + args->offset;
> +		/* Operation in the page
>  		 *
>  		 * page_base = page offset within aperture
>  		 * page_offset = offset within page
> -		 * page_length = bytes to copy for this page
> +		 * page_length = bytes to copy for the page
>  		 */
>  		page_base = offset & PAGE_MASK;
>  		page_offset = offset_in_page(offset);
> -		page_length = remain;
> -		if ((page_offset + remain) > PAGE_SIZE)
> -			page_length = PAGE_SIZE - page_offset;
> +		while (remain > 0) {
> +			page_length = remain;
> +			if ((page_offset + remain) > PAGE_SIZE)
> +				page_length = PAGE_SIZE - page_offset;
> +
> +			/* If we get a fault while copying data, then (presumably) our
> +			 * source page isn't available.  Return the error and we'll
> +			 * retry in the slow path.
> +			 */
> +			if (fast_user_write(dev_priv->gtt.mappable, page_base,
> +						page_offset, user_data, page_length)) {
> +				ret = -EFAULT;
> +				goto out_flush;
> +			}
>  
> -		/* If we get a fault while copying data, then (presumably) our
> -		 * source page isn't available.  Return the error and we'll
> -		 * retry in the slow path.
> -		 */
> -		if (fast_user_write(dev_priv->gtt.mappable, page_base,
> -				    page_offset, user_data, page_length)) {
> -			ret = -EFAULT;
> -			goto out_flush;
> +			remain -= page_length;
> +			user_data += page_length;
> +			page_offset = 0;
>  		}
> +	} else {
> +		i = args->offset / PAGE_SIZE;
> +		page_offset = offset_in_page(args->offset);
> +		while (remain > 0) {
> +			page_length = remain;
> +			if ((page_offset + remain) > PAGE_SIZE)
> +				page_length = PAGE_SIZE - page_offset;
> +
> +			wmb();
> +			dev_priv->gtt.base.insert_page(&dev_priv->gtt.base,
> +					i915_gem_object_get_dma_address(obj, i),
> +					node.start,
> +					I915_CACHE_NONE,
> +					0);
> +			wmb();
> +
> +			if (fast_user_write(dev_priv->gtt.mappable, node.start,
> +						page_offset, user_data, page_length)) {
> +				ret = -EFAULT;
> +				goto out_flush;
> +			}
>  
> -		remain -= page_length;
> -		user_data += page_length;
> -		offset += page_length;
> +			remain -= page_length;
> +			user_data += page_length;
> +			page_offset = 0;
> +			i++;
> +		}
> +		wmb();
> +		dev_priv->gtt.base.clear_range(&dev_priv->gtt.base,
> +				node.start, node.size,
> +				true);
> +		drm_mm_remove_node(&node);
>  	}
>  
>  out_flush:
>  	intel_fb_obj_flush(obj, false, ORIGIN_GTT);
>  out_unpin:
> -	i915_gem_object_ggtt_unpin(obj);
> +	if (pinned)
> +		i915_gem_object_ggtt_unpin(obj);
>  out:
>  	return ret;
>  }
> -- 
> 1.9.1
> 
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/intel-gfx

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

  parent reply	other threads:[~2015-11-18  9:59 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-05 11:45 [PATCH 0/3] Support for mapping an object page by page ankitprasad.r.sharma
2015-11-05 11:45 ` [PATCH 1/3] drm/i915: Add support " ankitprasad.r.sharma
2015-11-05 11:45 ` [PATCH 2/3] drm/i915: Introduce i915_gem_object_get_dma_address() ankitprasad.r.sharma
2015-11-05 11:45 ` [PATCH 3/3] drm/i915: Use insert_page for pwrite_fast ankitprasad.r.sharma
2015-11-05 12:34   ` Chris Wilson
2015-11-06  6:15     ` Ankitprasad Sharma
2015-11-05 12:37   ` Tvrtko Ursulin
2015-11-05 12:42     ` Chris Wilson
2015-11-05 12:53       ` Tvrtko Ursulin
2015-11-05 12:58         ` Chris Wilson
2015-11-05 14:38           ` Tvrtko Ursulin
2015-11-07 10:13             ` Chris Wilson
2015-11-18  9:59   ` Daniel Vetter [this message]
2015-11-20  9:37     ` Ankitprasad Sharma
2015-11-20 10:06       ` Chris Wilson
2015-11-24 12:22         ` Daniel Vetter
2015-12-14  8:19           ` Ankitprasad Sharma
  -- strict thread matches above, loose matches on Subject: below --
2015-11-07  8:02 [PATCH v2 0/3] Support for mapping an object page by page ankitprasad.r.sharma
2015-11-07  8:02 ` [PATCH 3/3] drm/i915: Use insert_page for pwrite_fast ankitprasad.r.sharma
2015-11-07 10:07   ` Chris Wilson
2015-11-09 10:56 [PATCH v3 0/3] Support for mapping an object page by page ankitprasad.r.sharma
2015-11-09 10:56 ` [PATCH 3/3] drm/i915: Use insert_page for pwrite_fast ankitprasad.r.sharma
2015-11-09 12:20   ` kbuild test robot
2015-11-10  7:55   ` Mika Kuoppala
2015-11-10  8:05     ` Ankitprasad Sharma
2015-11-10  8:44     ` Chris Wilson
2015-11-10 11:51       ` Chris Wilson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20151118095925.GG20799@phenom.ffwll.local \
    --to=daniel@ffwll.ch \
    --cc=akash.goel@intel.com \
    --cc=ankitprasad.r.sharma@intel.com \
    --cc=intel-gfx@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.