public inbox for intel-gfx@lists.freedesktop.org
 help / color / mirror / Atom feed
From: Mika Kuoppala <mika.kuoppala@linux.intel.com>
To: Intel Graphics Development <intel-gfx@lists.freedesktop.org>
Cc: Daniel Vetter <daniel.vetter@intel.com>,
	Daniel Vetter <daniel.vetter@ffwll.ch>
Subject: Re: [PATCH] drm/i915: Fix up the vma aliasing ppgtt binding
Date: Tue, 21 Apr 2015 16:29:04 +0300	[thread overview]
Message-ID: <87383t1ufz.fsf@gaia.fi.intel.com> (raw)
In-Reply-To: <1429545845-15179-1-git-send-email-daniel.vetter@ffwll.ch>

Daniel Vetter <daniel.vetter@ffwll.ch> writes:

> Currently we have the problem that the decision whether ptes need to
> be (re)written is splattered all over the codebase. Move all that into
> i915_vma_bind. This needs a few changes:
> - Just reuse the PIN_* flags for i915_vma_bind and do the conversion
>   to vma->bound in there to avoid duplicating the conversion code all
>   over.
> - We need to make binding for EXECBUF (i.e. pick aliasing ppgtt if
>   around) explicit, add PIN_USER for that.
> - Two callers want to update ptes, give them a PIN_UPDATE for that.
>
> Of course we still want to avoid double-binding, but that should be
> taken care of:
> - A ppgtt vma will only ever see PIN_USER, so no issue with
>   double-binding.
> - A ggtt vma with aliasing ppgtt needs both types of binding, and we
>   track that properly now.
> - A ggtt vma without aliasing ppgtt could be bound twice. In the
>   lower-level ->bind_vma functions hence unconditionally set
>   GLOBAL_BIND when writing the ggtt ptes.
>
> There's still a bit room for cleanup, but that's for follow-up
> patches.
>
> v2: Fixup fumbles.
>
> v3: s/PIN_EXECBUF/PIN_USER/ for clearer meaning, suggested by Chris.
>
> Cc: Chris Wilson <chris@chris-wilson.co.uk>
> Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>

Reviewed-by: Mika Kuoppala <mika.kuoppala@intel.com>

> ---
>  drivers/gpu/drm/i915/i915_drv.h            | 11 +++--
>  drivers/gpu/drm/i915/i915_gem.c            | 11 ++---
>  drivers/gpu/drm/i915/i915_gem_execbuffer.c |  7 ++--
>  drivers/gpu/drm/i915/i915_gem_gtt.c        | 65 ++++++++++++------------------
>  4 files changed, 40 insertions(+), 54 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
> index 47be4a57e6a9..80afbe3ad669 100644
> --- a/drivers/gpu/drm/i915/i915_drv.h
> +++ b/drivers/gpu/drm/i915/i915_drv.h
> @@ -2640,10 +2640,13 @@ void i915_init_vm(struct drm_i915_private *dev_priv,
>  void i915_gem_free_object(struct drm_gem_object *obj);
>  void i915_gem_vma_destroy(struct i915_vma *vma);
>  
> -#define PIN_MAPPABLE 0x1
> -#define PIN_NONBLOCK 0x2
> -#define PIN_GLOBAL 0x4
> -#define PIN_OFFSET_BIAS 0x8
> +/* Flags used by pin/bind&friends. */
> +#define PIN_MAPPABLE	(1<<0)
> +#define PIN_NONBLOCK	(1<<1)
> +#define PIN_GLOBAL	(1<<2)
> +#define PIN_OFFSET_BIAS	(1<<3)
> +#define PIN_USER	(1<<4)
> +#define PIN_UPDATE	(1<<5)
>  #define PIN_OFFSET_MASK (~4095)
>  int __must_check
>  i915_gem_object_pin(struct drm_i915_gem_object *obj,
> diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
> index 10e873c8957f..047629b08697 100644
> --- a/drivers/gpu/drm/i915/i915_gem.c
> +++ b/drivers/gpu/drm/i915/i915_gem.c
> @@ -3557,8 +3557,7 @@ search_free:
>  		goto err_remove_node;
>  
>  	trace_i915_vma_bind(vma, flags);
> -	ret = i915_vma_bind(vma, obj->cache_level,
> -			    flags & PIN_GLOBAL ? GLOBAL_BIND : 0);
> +	ret = i915_vma_bind(vma, obj->cache_level, flags);
>  	if (ret)
>  		goto err_finish_gtt;
>  
> @@ -3784,7 +3783,7 @@ int i915_gem_object_set_cache_level(struct drm_i915_gem_object *obj,
>  		list_for_each_entry(vma, &obj->vma_list, vma_link)
>  			if (drm_mm_node_allocated(&vma->node)) {
>  				ret = i915_vma_bind(vma, cache_level,
> -						    vma->bound & GLOBAL_BIND);
> +						    PIN_UPDATE);
>  				if (ret)
>  					return ret;
>  			}
> @@ -4187,10 +4186,8 @@ i915_gem_object_do_pin(struct drm_i915_gem_object *obj,
>  						 flags);
>  		if (IS_ERR(vma))
>  			return PTR_ERR(vma);
> -	}
> -
> -	if (flags & PIN_GLOBAL && !(vma->bound & GLOBAL_BIND)) {
> -		ret = i915_vma_bind(vma, obj->cache_level, GLOBAL_BIND);
> +	} else {
> +		ret = i915_vma_bind(vma, obj->cache_level, flags);
>  		if (ret)
>  			return ret;
>  	}
> diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
> index 7f69aa820458..cfdc8c6073aa 100644
> --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
> +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
> @@ -400,10 +400,9 @@ i915_gem_execbuffer_relocate_entry(struct drm_i915_gem_object *obj,
>  	 * pipe_control writes because the gpu doesn't properly redirect them
>  	 * through the ppgtt for non_secure batchbuffers. */
>  	if (unlikely(IS_GEN6(dev) &&
> -	    reloc->write_domain == I915_GEM_DOMAIN_INSTRUCTION &&
> -	    !(target_vma->bound & GLOBAL_BIND))) {
> +	    reloc->write_domain == I915_GEM_DOMAIN_INSTRUCTION)) {
>  		ret = i915_vma_bind(target_vma, target_i915_obj->cache_level,
> -				    GLOBAL_BIND);
> +				    PIN_GLOBAL);
>  		if (WARN_ONCE(ret, "Unexpected failure to bind target VMA!"))
>  			return ret;
>  	}
> @@ -585,7 +584,7 @@ i915_gem_execbuffer_reserve_vma(struct i915_vma *vma,
>  	uint64_t flags;
>  	int ret;
>  
> -	flags = 0;
> +	flags = PIN_USER;
>  	if (entry->flags & EXEC_OBJECT_NEEDS_GTT)
>  		flags |= PIN_GLOBAL;
>  
> diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.c b/drivers/gpu/drm/i915/i915_gem_gtt.c
> index 4e2caef83772..9e06180e206f 100644
> --- a/drivers/gpu/drm/i915/i915_gem_gtt.c
> +++ b/drivers/gpu/drm/i915/i915_gem_gtt.c
> @@ -1748,15 +1748,7 @@ void i915_gem_restore_gtt_mappings(struct drm_device *dev)
>  			continue;
>  
>  		i915_gem_clflush_object(obj, obj->pin_display);
> -		/* The bind_vma code tries to be smart about tracking mappings.
> -		 * Unfortunately above, we've just wiped out the mappings
> -		 * without telling our object about it. So we need to fake it.
> -		 *
> -		 * Bind is not expected to fail since this is only called on
> -		 * resume and assumption is all requirements exist already.
> -		 */
> -		vma->bound &= ~GLOBAL_BIND;
> -		WARN_ON(i915_vma_bind(vma, obj->cache_level, GLOBAL_BIND));
> +		WARN_ON(i915_vma_bind(vma, obj->cache_level, PIN_UPDATE));
>  	}
>  
>  
> @@ -1957,7 +1949,8 @@ static void i915_ggtt_bind_vma(struct i915_vma *vma,
>  
>  	BUG_ON(!i915_is_ggtt(vma->vm));
>  	intel_gtt_insert_sg_entries(vma->ggtt_view.pages, entry, flags);
> -	vma->bound = GLOBAL_BIND;
> +
> +	vma->bound |= GLOBAL_BIND;
>  }
>  
>  static void i915_ggtt_clear_range(struct i915_address_space *vm,
> @@ -1976,7 +1969,6 @@ static void i915_ggtt_unbind_vma(struct i915_vma *vma)
>  	const unsigned int size = vma->obj->base.size >> PAGE_SHIFT;
>  
>  	BUG_ON(!i915_is_ggtt(vma->vm));
> -	vma->bound = 0;
>  	intel_gtt_clear_range(first, size);
>  }
>  
> @@ -1997,35 +1989,19 @@ static void ggtt_bind_vma(struct i915_vma *vma,
>  	if (i915_is_ggtt(vma->vm))
>  		pages = vma->ggtt_view.pages;
>  
> -	/* If there is no aliasing PPGTT, or the caller needs a global mapping,
> -	 * or we have a global mapping already but the cacheability flags have
> -	 * changed, set the global PTEs.
> -	 *
> -	 * If there is an aliasing PPGTT it is anecdotally faster, so use that
> -	 * instead if none of the above hold true.
> -	 *
> -	 * NB: A global mapping should only be needed for special regions like
> -	 * "gtt mappable", SNB errata, or if specified via special execbuf
> -	 * flags. At all other times, the GPU will use the aliasing PPGTT.
> -	 */
>  	if (!dev_priv->mm.aliasing_ppgtt || flags & GLOBAL_BIND) {
> -		if (!(vma->bound & GLOBAL_BIND) ||
> -		    (cache_level != obj->cache_level)) {
> -			vma->vm->insert_entries(vma->vm, pages,
> -						vma->node.start,
> -						cache_level, pte_flags);
> -			vma->bound |= GLOBAL_BIND;
> -		}
> +		vma->vm->insert_entries(vma->vm, pages,
> +					vma->node.start,
> +					cache_level, pte_flags);
> +
> +		vma->bound |= GLOBAL_BIND;
>  	}
>  
> -	if (dev_priv->mm.aliasing_ppgtt &&
> -	    (!(vma->bound & LOCAL_BIND) ||
> -	     (cache_level != obj->cache_level))) {
> +	if (dev_priv->mm.aliasing_ppgtt && flags & LOCAL_BIND) {
>  		struct i915_hw_ppgtt *appgtt = dev_priv->mm.aliasing_ppgtt;
>  		appgtt->base.insert_entries(&appgtt->base, pages,
>  					    vma->node.start,
>  					    cache_level, pte_flags);
> -		vma->bound |= LOCAL_BIND;
>  	}
>  }
>  
> @@ -2040,16 +2016,14 @@ static void ggtt_unbind_vma(struct i915_vma *vma)
>  				     vma->node.start,
>  				     obj->base.size,
>  				     true);
> -		vma->bound &= ~GLOBAL_BIND;
>  	}
>  
> -	if (vma->bound & LOCAL_BIND) {
> +	if (dev_priv->mm.aliasing_ppgtt && vma->bound & LOCAL_BIND) {
>  		struct i915_hw_ppgtt *appgtt = dev_priv->mm.aliasing_ppgtt;
>  		appgtt->base.clear_range(&appgtt->base,
>  					 vma->node.start,
>  					 obj->base.size,
>  					 true);
> -		vma->bound &= ~LOCAL_BIND;
>  	}
>  }
>  
> @@ -2839,6 +2813,7 @@ i915_get_ggtt_vma_pages(struct i915_vma *vma)
>  int i915_vma_bind(struct i915_vma *vma, enum i915_cache_level cache_level,
>  		  u32 flags)
>  {
> +	u32 bind_flags = 0;
>  	int ret;
>  
>  	if (vma->vm->allocate_va_range) {
> @@ -2855,12 +2830,24 @@ int i915_vma_bind(struct i915_vma *vma, enum i915_cache_level cache_level,
>  
>  	if (i915_is_ggtt(vma->vm)) {
>  		ret = i915_get_ggtt_vma_pages(vma);
> -
>  		if (ret)
> -			return ret;
> +			return 0;
>  	}
>  
> -	vma->vm->bind_vma(vma, cache_level, flags);
> +	if (flags & PIN_GLOBAL)
> +		bind_flags |= GLOBAL_BIND;
> +	if (flags & PIN_USER)
> +		bind_flags |= LOCAL_BIND;
> +
> +	if (flags & PIN_UPDATE)
> +		bind_flags |= vma->bound;
> +	else
> +		bind_flags &= ~vma->bound;
> +
> +	if (bind_flags)
> +		vma->vm->bind_vma(vma, cache_level, bind_flags);
> +
> +	vma->bound |= bind_flags;
>  
>  	return 0;
>  }
> -- 
> 1.9.3
>
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/intel-gfx
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

  reply	other threads:[~2015-04-21 13:29 UTC|newest]

Thread overview: 74+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-14 15:35 [PATCH 00/17] i915_gem_gtt.c polish Daniel Vetter
2015-04-14 15:35 ` [PATCH 01/17] drm/i915: Move gen8 clear_range vfunc setup into common code Daniel Vetter
2015-04-17 14:11   ` Mika Kuoppala
2015-04-14 15:35 ` [PATCH 02/17] drm/i915: Move vma vfuns to adddress_space Daniel Vetter
2015-04-14 16:09   ` Chris Wilson
2015-04-14 16:12     ` Chris Wilson
2015-04-14 17:08       ` Daniel Vetter
2015-04-14 17:23         ` Chris Wilson
2015-04-16  6:18     ` Mika Kuoppala
2015-04-16  7:39       ` Chris Wilson
2015-04-17 14:15   ` Mika Kuoppala
2015-04-14 15:35 ` [PATCH 03/17] drm/i915: Clean up aliasing ppgtt correctly on error paths Daniel Vetter
2015-04-17 14:34   ` Mika Kuoppala
2015-04-14 15:35 ` [PATCH 04/17] drm/i915: Unify aliasing ppgtt handling Daniel Vetter
2015-04-17 13:36   ` Mika Kuoppala
2015-04-17 16:21   ` Mika Kuoppala
2015-04-14 15:35 ` [PATCH 05/17] drm/i915: Move PTE_READ_ONLY to ->pte_encode vfunc Daniel Vetter
2015-04-17 16:22   ` Mika Kuoppala
2015-04-14 15:35 ` [PATCH 06/17] drm/i915: Dont clear PIN_GLOBAL in the execbuf pinning fallback Daniel Vetter
2015-04-14 15:53   ` Chris Wilson
2015-04-14 16:33     ` Chris Wilson
2015-04-14 17:01   ` [PATCH] " Daniel Vetter
2015-04-15 21:50     ` shuang.he
2015-04-14 15:35 ` [PATCH 07/17] drm/i915: Drop redundant GGTT rebinding Daniel Vetter
2015-04-14 16:03   ` Chris Wilson
2015-04-14 15:35 ` [PATCH 08/17] drm/i915: Don't look at pg_dirty_rings for aliasing ppgtt Daniel Vetter
2015-04-14 16:06   ` Chris Wilson
2015-04-14 17:11     ` Daniel Vetter
2015-04-14 17:53       ` Chris Wilson
2015-04-15 10:44         ` Daniel Vetter
2015-04-17 13:49           ` Mika Kuoppala
2015-04-20 16:02             ` Daniel Vetter
2015-04-20 16:08             ` Daniel Vetter
2015-04-21  8:18               ` Mika Kuoppala
2015-04-23 15:43             ` Chris Wilson
2015-04-23 18:56               ` Daniel Vetter
2015-04-23 19:52                 ` Chris Wilson
2015-04-23 21:52                 ` Chris Wilson
2015-07-31 16:26                 ` Chris Wilson
2015-07-31 17:38                   ` Chris Wilson
2015-04-14 15:35 ` [PATCH 09/17] drm/i915: Don't use atomics for pg_dirty_rings Daniel Vetter
2015-04-17 16:39   ` Mika Kuoppala
2015-04-14 15:35 ` [PATCH 10/17] drm/i915: Remove misleading comment around bind_to_vm Daniel Vetter
2015-04-17 18:09   ` Mika Kuoppala
2015-04-14 15:35 ` [PATCH 11/17] drm/i915: Fix up the vma aliasing ppgtt binding Daniel Vetter
2015-04-15 10:47   ` Chris Wilson
2015-04-16  8:01     ` Daniel Vetter
2015-04-16  8:07       ` Chris Wilson
2015-04-16  8:57         ` Daniel Vetter
2015-04-20 16:04   ` [PATCH] " Daniel Vetter
2015-04-21 13:29     ` Mika Kuoppala [this message]
2015-04-24 11:14     ` Chris Wilson
2015-04-24 11:55       ` Chris Wilson
2015-05-04  8:49         ` Daniel Vetter
2015-05-04  9:06           ` Chris Wilson
2015-05-04  9:20             ` Daniel Vetter
2015-04-14 15:35 ` [PATCH 12/17] drm/i915: Arm cmd parser with aliasng ppgtt only Daniel Vetter
2015-04-14 18:10   ` Chris Wilson
2015-04-15  9:43     ` Daniel Vetter
2015-04-15 10:07       ` Chris Wilson
2015-04-15 10:28         ` Daniel Vetter
2015-04-30 10:37           ` Jani Nikula
2015-04-24 12:57   ` Mika Kuoppala
2015-05-04  8:54     ` [PATCH] drm/i915: Simplify cmd-parser DISPATCH_SECURE check Daniel Vetter
2015-05-04  9:23       ` Daniel Vetter
2015-05-04 12:52       ` shuang.he
2015-04-14 15:35 ` [PATCH 13/17] drm/i915: move i915_gem_restore_gtt_mappings around Daniel Vetter
2015-04-14 15:35 ` [PATCH 14/17] drm/i915: Move ppgtt_bind/unbind around Daniel Vetter
2015-04-14 15:35 ` [PATCH 15/17] drm/i915: Unduplicate i915_ggtt_unbind/bind_vma Daniel Vetter
2015-04-14 15:35 ` [PATCH 16/17] drm/i915: Don't try to outsmart gcc in i915_gem_gtt.c Daniel Vetter
2015-04-14 15:35 ` [PATCH 17/17] drm/i915: Move i915_get_ggtt_vma_pages into ggtt_bind_vma Daniel Vetter
2015-04-21 13:36   ` Mika Kuoppala
2015-04-23 19:08     ` Daniel Vetter
2015-04-15 10:49 ` [PATCH 00/17] i915_gem_gtt.c polish 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=87383t1ufz.fsf@gaia.fi.intel.com \
    --to=mika.kuoppala@linux.intel.com \
    --cc=daniel.vetter@ffwll.ch \
    --cc=daniel.vetter@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox