intel-gfx.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
From: Ankitprasad Sharma <ankitprasad.r.sharma@intel.com>
To: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>
Cc: intel-gfx@lists.freedesktop.org, akash.goel@intel.com,
	shashidhar.hiremath@intel.com
Subject: Re: [PATCH 08/10] drm/i915: Support for pread/pwrite from/to non shmem backed objects
Date: Fri, 19 Feb 2016 11:24:11 +0530	[thread overview]
Message-ID: <1455861251.2500.17.camel@ankitprasad-desktop> (raw)
In-Reply-To: <56BC731A.1060904@linux.intel.com>

Hi,
On Thu, 2016-02-11 at 11:40 +0000, Tvrtko Ursulin wrote:

> > +
> > +	mutex_unlock(&dev->struct_mutex);
> > +	if (likely(!i915.prefault_disable)) {
> > +		ret = fault_in_multipages_writeable(user_data, remain);
> > +		if (ret) {
> > +			mutex_lock(&dev->struct_mutex);
> > +			goto out_unpin;
> > +		}
> > +	}
> > +
> > +	while (remain > 0) {
> > +		/* Operation in this page
> > +		 *
> > +		 * page_base = page offset within aperture
> > +		 * page_offset = offset within page
> > +		 * page_length = bytes to copy for this page
> > +		 */
> > +		u32 page_base = node.start;
> > +		unsigned page_offset = offset_in_page(offset);
> > +		unsigned page_length = PAGE_SIZE - page_offset;
> > +		page_length = remain < page_length ? remain : page_length;
> > +		if (node.allocated) {
> > +			wmb();
> > +			dev_priv->gtt.base.insert_page(&dev_priv->gtt.base,
> > +						       i915_gem_object_get_dma_address(obj, offset >> PAGE_SHIFT),
> > +						       node.start,
> > +						       I915_CACHE_NONE, 0);
> > +			wmb();
> > +		} else {
> > +			page_base += offset & PAGE_MASK;
> > +		}
> > +		/* This is a slow read/write as it tries to read from
> > +		 * and write to user memory which may result into page
> > +		 * faults, and so we cannot perform this under struct_mutex.
> > +		 */
> > +		if (slow_user_access(dev_priv->gtt.mappable, page_base,
> > +				     page_offset, user_data,
> > +				     page_length, false)) {
> > +			ret = -EFAULT;
> > +			break;
> > +		}
> 
> Read does not want to try the fast access first, equivalent to pwrite ?
Using fast access means we will be unable to handle faults, which are
more frequent in a pread case.
> 
> > +
> > +		remain -= page_length;
> > +		user_data += page_length;
> > +		offset += page_length;
> > +	}
> > +
> >
> > @@ -870,24 +1012,36 @@ i915_gem_gtt_pwrite_fast(struct drm_i915_private *i915,
> >   		unsigned page_length = PAGE_SIZE - page_offset;
> >   		page_length = remain < page_length ? remain : page_length;
> >   		if (node.allocated) {
> > -			wmb();
> > +			wmb(); /* flush the write before we modify the GGTT */
> >   			i915->gtt.base.insert_page(&i915->gtt.base,
> >   						   i915_gem_object_get_dma_address(obj, offset >> PAGE_SHIFT),
> >   						   node.start,
> >   						   I915_CACHE_NONE,
> >   						   0);
> > -			wmb();
> > +			wmb(); /* flush modifications to the GGTT (insert_page) */
> >   		} else {
> >   			page_base += offset & PAGE_MASK;
> >   		}
> >   		/* 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 the object is non-shmem backed, we retry again with the
> > +		 * path that handles page fault.
> >   		 */
> >   		if (fast_user_write(i915->gtt.mappable, page_base,
> >   				    page_offset, user_data, page_length)) {
> > -			ret = -EFAULT;
> > -			goto out_flush;
> > +			hit_slow_path = true;
> > +			mutex_unlock(&dev->struct_mutex);
> > +			if (slow_user_access(i915->gtt.mappable,
> > +					     page_base,
> > +					     page_offset, user_data,
> > +					     page_length, true)) {
> > +				ret = -EFAULT;
> > +				mutex_lock(&dev->struct_mutex);
> > +				goto out_flush;
> > +			}
> 
> I think the function now be called i915_gem_gtt_pwrite.
> 
> Would it also need the same pre-fault as in i915_gem_gtt_pread ?
I do not think pre-fault is needed here, as in pread we are dealing with
a read from the obj and to the user buffer (which has more chances of
faulting).
While in the pwrite case, we are optimistic that the user would have
already mapped/accessed the buffer before using it to write the buffer
contents into the object.
> 
> > +
> > +			mutex_lock(&dev->struct_mutex);
> >   		}
> >
> >   		remain -= page_length;
> > @@ -896,6 +1050,9 @@ i915_gem_gtt_pwrite_fast(struct drm_i915_private *i915,
> >   	}
> >
> >   out_flush:
> > +	if (hit_slow_path)
> > +		WARN_ON(i915_gem_object_set_to_gtt_domain(obj, true));
> 
> I suppose this is for the same reason as in pread, maybe duplicate the 
> comment here?
> 
> > +
> >   	intel_fb_obj_flush(obj, false, ORIGIN_GTT);
> >   out_unpin:
> >   	if (node.allocated) {
> > @@ -1152,14 +1309,6 @@ i915_gem_pwrite_ioctl(struct drm_device *dev, void *data,
> >   		goto out;
> >   	}
> >
> > -	/* prime objects have no backing filp to GEM pread/pwrite
> > -	 * pages from.
> > -	 */
> > -	if (!obj->base.filp) {
> > -		ret = -EINVAL;
> > -		goto out;
> > -	}
> > -
> >   	trace_i915_gem_object_pwrite(obj, args->offset, args->size);
> >
> >   	ret = -EFAULT;
> > @@ -1169,20 +1318,20 @@ i915_gem_pwrite_ioctl(struct drm_device *dev, void *data,
> >   	 * pread/pwrite currently are reading and writing from the CPU
> >   	 * perspective, requiring manual detiling by the client.
> >   	 */
> > -	if (obj->tiling_mode == I915_TILING_NONE &&
> > -	    obj->base.write_domain != I915_GEM_DOMAIN_CPU &&
> > -	    cpu_write_needs_clflush(obj)) {
> > +	if (!obj->base.filp || cpu_write_needs_clflush(obj)) {
> >   		ret = i915_gem_gtt_pwrite_fast(dev_priv, obj, args, file);
> >   		/* Note that the gtt paths might fail with non-page-backed user
> >   		 * pointers (e.g. gtt mappings when moving data between
> >   		 * textures). Fallback to the shmem path in that case. */
> >   	}
> >
> > -	if (ret == -EFAULT || ret == -ENOSPC) {
> > +	if (ret == -EFAULT) {
> >   		if (obj->phys_handle)
> >   			ret = i915_gem_phys_pwrite(obj, args, file);
> > -		else
> > +		else if (obj->base.filp)
> >   			ret = i915_gem_shmem_pwrite(dev, obj, args, file);
> > +		else
> > +			ret = -ENODEV;
> >   	}
> >
> >   out:
> > @@ -3979,9 +4128,7 @@ out:
> >   	 * object is now coherent at its new cache level (with respect
> >   	 * to the access domain).
> >   	 */
> > -	if (obj->cache_dirty &&
> > -	    obj->base.write_domain != I915_GEM_DOMAIN_CPU &&
> > -	    cpu_write_needs_clflush(obj)) {
> > +	if (obj->cache_dirty && cpu_write_needs_clflush(obj)) {
> >   		if (i915_gem_clflush_object(obj, true))
> >   			i915_gem_chipset_flush(obj->base.dev);
> >   	}
> >
> 
> Regards,
> 
> Tvrtko
> 
Thanks,
Ankit

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

  parent reply	other threads:[~2016-02-19  6:17 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-04  9:30 [PATCH v16 0/10] Support for creating/using Stolen memory backed objects ankitprasad.r.sharma
2016-02-04  9:30 ` [PATCH 01/10] drm/i915: Add support for mapping an object page by page ankitprasad.r.sharma
2016-02-11 10:50   ` Tvrtko Ursulin
2016-02-18  8:33     ` Ankitprasad Sharma
2016-02-04  9:30 ` [PATCH 02/10] drm/i915: Introduce i915_gem_object_get_dma_address() ankitprasad.r.sharma
2016-02-11 10:52   ` Tvrtko Ursulin
2016-02-04  9:30 ` [PATCH 03/10] drm/i915: Use insert_page for pwrite_fast ankitprasad.r.sharma
2016-02-04 10:49   ` kbuild test robot
2016-02-04  9:30 ` [PATCH 04/10] drm/i915: Clearing buffer objects via CPU/GTT ankitprasad.r.sharma
2016-02-04  9:30 ` [PATCH 05/10] drm/i915: Support for creating Stolen memory backed objects ankitprasad.r.sharma
2016-02-04  9:30 ` [PATCH 06/10] drm/i915: Propagating correct error codes to the userspace ankitprasad.r.sharma
2016-02-04  9:30 ` [PATCH 07/10] drm/i915: Add support for stealing purgable stolen pages ankitprasad.r.sharma
2016-02-04  9:30 ` [PATCH 08/10] drm/i915: Support for pread/pwrite from/to non shmem backed objects ankitprasad.r.sharma
2016-02-11 11:40   ` Tvrtko Ursulin
2016-02-18  8:26     ` Ankitprasad Sharma
2016-02-19  5:54     ` Ankitprasad Sharma [this message]
2016-02-04  9:30 ` [PATCH 09/10] drm/i915: Migrate stolen objects before hibernation ankitprasad.r.sharma
2016-02-04  9:30 ` [PATCH 10/10] drm/i915: Disable use of stolen area by User when Intel RST is present ankitprasad.r.sharma
2016-02-04 15:46   ` Lukas Wunner
2016-02-04 16:05     ` Chris Wilson
2016-02-04 16:43       ` Lukas Wunner
2016-02-11 19:08         ` Lukas Wunner
2016-02-11 11:54   ` Tvrtko Ursulin
  -- strict thread matches above, loose matches on Subject: below --
2016-03-18  6:22 [PATCH v19 0/10] Support for creating/using Stolen memory backed objects ankitprasad.r.sharma
2016-03-18  6:22 ` [PATCH 08/10] drm/i915: Support for pread/pwrite from/to non shmem " ankitprasad.r.sharma
2016-02-29  7:39 [PATCH v1 0/10] Support for creating/using Stolen memory " ankitprasad.r.sharma
2016-02-29  7:39 ` [PATCH 08/10] drm/i915: Support for pread/pwrite from/to non shmem " ankitprasad.r.sharma
2016-02-19  6:51 [PATCH v17 0/10] Support for creating/using Stolen memory " ankitprasad.r.sharma
2016-02-19  6:51 ` [PATCH 08/10] drm/i915: Support for pread/pwrite from/to non shmem " ankitprasad.r.sharma
2016-02-19 10:55   ` Tvrtko Ursulin
2016-01-25 19:43 [PATCH v15 0/10] Support for creating/using Stolen memory " ankitprasad.r.sharma
2016-01-25 19:43 ` [PATCH 08/10] drm/i915: Support for pread/pwrite from/to non shmem " ankitprasad.r.sharma
2016-01-26 10:49   ` 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=1455861251.2500.17.camel@ankitprasad-desktop \
    --to=ankitprasad.r.sharma@intel.com \
    --cc=akash.goel@intel.com \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=shashidhar.hiremath@intel.com \
    --cc=tvrtko.ursulin@linux.intel.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).