All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>
To: Chris Wilson <chris@chris-wilson.co.uk>, intel-gfx@lists.freedesktop.org
Cc: matthew.auld@intel.com
Subject: Re: [PATCH 06/43] drm/i915: Reduce presumption of request ordering for barriers
Date: Thu, 7 Mar 2019 17:26:49 +0000	[thread overview]
Message-ID: <819751d2-2b21-23c0-bf72-b47a80244e47@linux.intel.com> (raw)
In-Reply-To: <20190306142517.22558-7-chris@chris-wilson.co.uk>


On 06/03/2019 14:24, Chris Wilson wrote:
> Currently we assume that we know the order in which requests run and so
> can determine if we need to reissue a switch-to-kernel-context prior to
> idling. That assumption does not hold for the future, so instead of
> tracking which barriers have been used, simply determine if we have ever
> switched away from the kernel context by using the engine and before
> idling ensure that all engines that have been used since the last idle
> are synchronously switched back to the kernel context for safety (and
> else of shrinking memory while idle).
> 
> Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
> ---
>   drivers/gpu/drm/i915/i915_drv.h               |  1 +
>   drivers/gpu/drm/i915/i915_gem.c               | 13 ++--
>   drivers/gpu/drm/i915/i915_gem_context.c       | 66 +------------------
>   drivers/gpu/drm/i915/i915_gem_context.h       |  3 +-
>   drivers/gpu/drm/i915/i915_gem_evict.c         |  2 +-
>   drivers/gpu/drm/i915/i915_request.c           |  1 +
>   drivers/gpu/drm/i915/intel_engine_cs.c        |  5 ++
>   .../gpu/drm/i915/selftests/i915_gem_context.c |  3 +-
>   .../gpu/drm/i915/selftests/igt_flush_test.c   |  2 +-
>   .../gpu/drm/i915/selftests/mock_gem_device.c  |  4 ++
>   10 files changed, 28 insertions(+), 72 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
> index de142a268371..59d041eb72d7 100644
> --- a/drivers/gpu/drm/i915/i915_drv.h
> +++ b/drivers/gpu/drm/i915/i915_drv.h
> @@ -1994,6 +1994,7 @@ struct drm_i915_private {
>   
>   		struct list_head active_rings;
>   		struct list_head closed_vma;
> +		unsigned long active_engines;

Can use intel_engine_mask_t.

>   		u32 active_requests;
>   
>   		/**
> diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
> index d4800e7d6f2c..ed7695fd444a 100644
> --- a/drivers/gpu/drm/i915/i915_gem.c
> +++ b/drivers/gpu/drm/i915/i915_gem.c
> @@ -2845,9 +2845,10 @@ static void assert_kernel_context_is_current(struct drm_i915_private *i915)
>   	}
>   }
>   
> -static bool switch_to_kernel_context_sync(struct drm_i915_private *i915)
> +static bool switch_to_kernel_context_sync(struct drm_i915_private *i915,
> +					  unsigned long mask)
>   {
> -	if (i915_gem_switch_to_kernel_context(i915))
> +	if (i915_gem_switch_to_kernel_context(i915, mask))
>   		return false;
>   
>   	if (i915_gem_wait_for_idle(i915,
> @@ -2862,7 +2863,8 @@ static bool switch_to_kernel_context_sync(struct drm_i915_private *i915)
>   
>   static bool load_power_context(struct drm_i915_private *i915)
>   {
> -	if (!switch_to_kernel_context_sync(i915))
> +	/* Force loading the kernel context on all engines */
> +	if (!switch_to_kernel_context_sync(i915, -1))

ALL_ENGINES for self-documenting readability?

>   		return false;
>   
>   	/*
> @@ -2910,7 +2912,8 @@ i915_gem_idle_work_handler(struct work_struct *work)
>   	if (!gt->active_requests && !work_pending(&gt->idle_work.work)) {
>   		++gt->active_requests; /* don't requeue idle */
>   
> -		if (!switch_to_kernel_context_sync(i915)) {
> +		if (!switch_to_kernel_context_sync(i915,
> +						   i915->gt.active_engines)) {
>   			dev_err(i915->drm.dev,
>   				"Failed to idle engines, declaring wedged!\n");
>   			GEM_TRACE_DUMP();
> @@ -4369,7 +4372,7 @@ void i915_gem_suspend(struct drm_i915_private *i915)
>   	 * state. Fortunately, the kernel_context is disposable and we do
>   	 * not rely on its state.
>   	 */
> -	if (!switch_to_kernel_context_sync(i915)) {
> +	if (!switch_to_kernel_context_sync(i915, i915->gt.active_engines)) {
>   		/* Forcibly cancel outstanding work and leave the gpu quiet. */
>   		i915_gem_set_wedged(i915);
>   	}
> diff --git a/drivers/gpu/drm/i915/i915_gem_context.c b/drivers/gpu/drm/i915/i915_gem_context.c
> index 9a3eb4f66d85..486203e9d205 100644
> --- a/drivers/gpu/drm/i915/i915_gem_context.c
> +++ b/drivers/gpu/drm/i915/i915_gem_context.c
> @@ -704,63 +704,10 @@ last_request_on_engine(struct i915_timeline *timeline,
>   	return NULL;
>   }
>   
> -static bool engine_has_kernel_context_barrier(struct intel_engine_cs *engine)
> -{
> -	struct drm_i915_private *i915 = engine->i915;
> -	const struct intel_context * const ce =
> -		to_intel_context(i915->kernel_context, engine);
> -	struct i915_timeline *barrier = ce->ring->timeline;
> -	struct intel_ring *ring;
> -	bool any_active = false;
> -
> -	lockdep_assert_held(&i915->drm.struct_mutex);
> -	list_for_each_entry(ring, &i915->gt.active_rings, active_link) {
> -		struct i915_request *rq;
> -
> -		rq = last_request_on_engine(ring->timeline, engine);
> -		if (!rq)
> -			continue;
> -
> -		any_active = true;
> -
> -		if (rq->hw_context == ce)
> -			continue;
> -
> -		/*
> -		 * Was this request submitted after the previous
> -		 * switch-to-kernel-context?
> -		 */
> -		if (!i915_timeline_sync_is_later(barrier, &rq->fence)) {
> -			GEM_TRACE("%s needs barrier for %llx:%lld\n",
> -				  ring->timeline->name,
> -				  rq->fence.context,
> -				  rq->fence.seqno);
> -			return false;
> -		}
> -
> -		GEM_TRACE("%s has barrier after %llx:%lld\n",
> -			  ring->timeline->name,
> -			  rq->fence.context,
> -			  rq->fence.seqno);
> -	}
> -
> -	/*
> -	 * If any other timeline was still active and behind the last barrier,
> -	 * then our last switch-to-kernel-context must still be queued and
> -	 * will run last (leaving the engine in the kernel context when it
> -	 * eventually idles).
> -	 */
> -	if (any_active)
> -		return true;
> -
> -	/* The engine is idle; check that it is idling in the kernel context. */
> -	return engine->last_retired_context == ce;
> -}
> -
> -int i915_gem_switch_to_kernel_context(struct drm_i915_private *i915)
> +int i915_gem_switch_to_kernel_context(struct drm_i915_private *i915,
> +				      unsigned long mask)
>   {
>   	struct intel_engine_cs *engine;
> -	enum intel_engine_id id;
>   
>   	GEM_TRACE("awake?=%s\n", yesno(i915->gt.awake));
>   
> @@ -771,17 +718,11 @@ int i915_gem_switch_to_kernel_context(struct drm_i915_private *i915)
>   	if (i915_terminally_wedged(i915))
>   		return 0;
>   
> -	i915_retire_requests(i915);
> -
> -	for_each_engine(engine, i915, id) {
> +	for_each_engine_masked(engine, i915, mask, mask) {
>   		struct intel_ring *ring;
>   		struct i915_request *rq;
>   
>   		GEM_BUG_ON(!to_intel_context(i915->kernel_context, engine));
> -		if (engine_has_kernel_context_barrier(engine))
> -			continue;
> -
> -		GEM_TRACE("emit barrier on %s\n", engine->name);
>   
>   		rq = i915_request_alloc(engine, i915->kernel_context);
>   		if (IS_ERR(rq))
> @@ -805,7 +746,6 @@ int i915_gem_switch_to_kernel_context(struct drm_i915_private *i915)
>   			i915_sw_fence_await_sw_fence_gfp(&rq->submit,
>   							 &prev->submit,
>   							 I915_FENCE_GFP);
> -			i915_timeline_sync_set(rq->timeline, &prev->fence);
>   		}
>   
>   		i915_request_add(rq);
> diff --git a/drivers/gpu/drm/i915/i915_gem_context.h b/drivers/gpu/drm/i915/i915_gem_context.h
> index 2f9ef333acaa..e1188d77a23d 100644
> --- a/drivers/gpu/drm/i915/i915_gem_context.h
> +++ b/drivers/gpu/drm/i915/i915_gem_context.h
> @@ -372,7 +372,8 @@ int i915_gem_context_open(struct drm_i915_private *i915,
>   void i915_gem_context_close(struct drm_file *file);
>   
>   int i915_switch_context(struct i915_request *rq);
> -int i915_gem_switch_to_kernel_context(struct drm_i915_private *dev_priv);
> +int i915_gem_switch_to_kernel_context(struct drm_i915_private *i915,
> +				      unsigned long engine_mask);
>   
>   void i915_gem_context_release(struct kref *ctx_ref);
>   struct i915_gem_context *
> diff --git a/drivers/gpu/drm/i915/i915_gem_evict.c b/drivers/gpu/drm/i915/i915_gem_evict.c
> index 68d74c50ac39..7d8e90dfca84 100644
> --- a/drivers/gpu/drm/i915/i915_gem_evict.c
> +++ b/drivers/gpu/drm/i915/i915_gem_evict.c
> @@ -62,7 +62,7 @@ static int ggtt_flush(struct drm_i915_private *i915)
>   	 * the hopes that we can then remove contexts and the like only
>   	 * bound by their active reference.
>   	 */
> -	err = i915_gem_switch_to_kernel_context(i915);
> +	err = i915_gem_switch_to_kernel_context(i915, i915->gt.active_engines);
>   	if (err)
>   		return err;
>   
> diff --git a/drivers/gpu/drm/i915/i915_request.c b/drivers/gpu/drm/i915/i915_request.c
> index f8a63495114c..9533a85cb0b3 100644
> --- a/drivers/gpu/drm/i915/i915_request.c
> +++ b/drivers/gpu/drm/i915/i915_request.c
> @@ -1068,6 +1068,7 @@ void i915_request_add(struct i915_request *request)
>   		GEM_TRACE("marking %s as active\n", ring->timeline->name);
>   		list_add(&ring->active_link, &request->i915->gt.active_rings);
>   	}
> +	request->i915->gt.active_engines |= request->engine->mask;
>   	request->emitted_jiffies = jiffies;
>   
>   	/*
> diff --git a/drivers/gpu/drm/i915/intel_engine_cs.c b/drivers/gpu/drm/i915/intel_engine_cs.c
> index 555a4590fa23..18174f808fd8 100644
> --- a/drivers/gpu/drm/i915/intel_engine_cs.c
> +++ b/drivers/gpu/drm/i915/intel_engine_cs.c
> @@ -1106,6 +1106,9 @@ bool intel_engine_has_kernel_context(const struct intel_engine_cs *engine)
>   
>   	lockdep_assert_held(&engine->i915->drm.struct_mutex);
>   
> +	if (!engine->context_size)
> +		return true;
> +
>   	/*
>   	 * Check the last context seen by the engine. If active, it will be
>   	 * the last request that remains in the timeline. When idle, it is
> @@ -1205,6 +1208,8 @@ void intel_engines_park(struct drm_i915_private *i915)
>   		i915_gem_batch_pool_fini(&engine->batch_pool);
>   		engine->execlists.no_priolist = false;
>   	}
> +
> +	i915->gt.active_engines = 0;
>   }
>   
>   /**
> diff --git a/drivers/gpu/drm/i915/selftests/i915_gem_context.c b/drivers/gpu/drm/i915/selftests/i915_gem_context.c
> index cb3d77c95ddf..00ac34007582 100644
> --- a/drivers/gpu/drm/i915/selftests/i915_gem_context.c
> +++ b/drivers/gpu/drm/i915/selftests/i915_gem_context.c
> @@ -1514,7 +1514,8 @@ static int __igt_switch_to_kernel_context(struct drm_i915_private *i915,
>   			}
>   		}
>   
> -		err = i915_gem_switch_to_kernel_context(i915);
> +		err = i915_gem_switch_to_kernel_context(i915,
> +							i915->gt.active_engines);
>   		if (err)
>   			return err;
>   
> diff --git a/drivers/gpu/drm/i915/selftests/igt_flush_test.c b/drivers/gpu/drm/i915/selftests/igt_flush_test.c
> index e0d3122fd35a..94aee4071a66 100644
> --- a/drivers/gpu/drm/i915/selftests/igt_flush_test.c
> +++ b/drivers/gpu/drm/i915/selftests/igt_flush_test.c
> @@ -14,7 +14,7 @@ int igt_flush_test(struct drm_i915_private *i915, unsigned int flags)
>   	cond_resched();
>   
>   	if (flags & I915_WAIT_LOCKED &&
> -	    i915_gem_switch_to_kernel_context(i915)) {
> +	    i915_gem_switch_to_kernel_context(i915, i915->gt.active_engines)) {
>   		pr_err("Failed to switch back to kernel context; declaring wedged\n");
>   		i915_gem_set_wedged(i915);
>   	}
> diff --git a/drivers/gpu/drm/i915/selftests/mock_gem_device.c b/drivers/gpu/drm/i915/selftests/mock_gem_device.c
> index b2c7808e0595..54cfb611c0aa 100644
> --- a/drivers/gpu/drm/i915/selftests/mock_gem_device.c
> +++ b/drivers/gpu/drm/i915/selftests/mock_gem_device.c
> @@ -109,6 +109,10 @@ static void mock_retire_work_handler(struct work_struct *work)
>   
>   static void mock_idle_work_handler(struct work_struct *work)
>   {
> +	struct drm_i915_private *i915 =
> +		container_of(work, typeof(*i915), gt.idle_work.work);
> +
> +	i915->gt.active_engines = 0;
>   }
>   
>   static int pm_domain_resume(struct device *dev)
> 

Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>

Regards,

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

  reply	other threads:[~2019-03-07 17:26 UTC|newest]

Thread overview: 78+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-06 14:24 RFC Breaking up GEM struct_mutex for async-pages Chris Wilson
2019-03-06 14:24 ` [PATCH 01/43] drm/i915/selftests: Canonicalise gen8 addresses Chris Wilson
2019-03-06 14:24 ` [PATCH 02/43] drm/i915: Force GPU idle on suspend Chris Wilson
2019-03-07  9:38   ` Tvrtko Ursulin
2019-03-06 14:24 ` [PATCH 03/43] drm/i915/selftests: Improve switch-to-kernel-context checking Chris Wilson
2019-03-07 12:40   ` Tvrtko Ursulin
2019-03-07 13:17     ` Chris Wilson
2019-03-07 13:21       ` Tvrtko Ursulin
2019-03-06 14:24 ` [PATCH 04/43] drm/i915: Do a synchronous switch-to-kernel-context on idling Chris Wilson
2019-03-07 13:07   ` Tvrtko Ursulin
2019-03-07 13:29     ` Chris Wilson
2019-03-07 17:06       ` Tvrtko Ursulin
2019-03-07 22:24         ` Chris Wilson
2019-03-08  6:46           ` Tvrtko Ursulin
2019-03-08  8:59             ` Chris Wilson
2019-03-06 14:24 ` [PATCH 05/43] drm/i915: Refactor common code to load initial power context Chris Wilson
2019-03-07 13:19   ` Tvrtko Ursulin
2019-03-07 22:26     ` Chris Wilson
2019-03-08  6:48       ` Tvrtko Ursulin
2019-03-06 14:24 ` [PATCH 06/43] drm/i915: Reduce presumption of request ordering for barriers Chris Wilson
2019-03-07 17:26   ` Tvrtko Ursulin [this message]
2019-03-06 14:24 ` [PATCH 07/43] drm/i915: Remove has-kernel-context Chris Wilson
2019-03-07 17:29   ` Tvrtko Ursulin
2019-03-06 14:24 ` [PATCH 08/43] drm/i915: Introduce the i915_user_extension_method Chris Wilson
2019-03-06 14:24 ` [PATCH 09/43] drm/i915: Track active engines within a context Chris Wilson
2019-03-06 14:24 ` [PATCH 10/43] drm/i915: Introduce a context barrier callback Chris Wilson
2019-03-06 14:24 ` [PATCH 11/43] drm/i915: Create/destroy VM (ppGTT) for use with contexts Chris Wilson
2019-03-06 14:24 ` [PATCH 12/43] drm/i915: Extend CONTEXT_CREATE to set parameters upon construction Chris Wilson
2019-03-06 14:24 ` [PATCH 13/43] drm/i915: Allow contexts to share a single timeline across all engines Chris Wilson
2019-03-06 14:24 ` [PATCH 14/43] drm/i915: Allow userspace to clone contexts on creation Chris Wilson
2019-03-06 14:24 ` [PATCH 15/43] drm/i915: Allow a context to define its set of engines Chris Wilson
2019-03-06 14:24 ` [PATCH 16/43] drm/i915: Extend I915_CONTEXT_PARAM_SSEU to support local ctx->engine[] Chris Wilson
2019-03-06 14:24 ` [PATCH 17/43] drm/i915: Split struct intel_context definition to its own header Chris Wilson
2019-03-06 14:24 ` [PATCH 18/43] drm/i915: Store the intel_context_ops in the intel_engine_cs Chris Wilson
2019-03-06 14:39   ` Tvrtko Ursulin
2019-03-06 14:24 ` [PATCH 19/43] drm/i915: Move over to intel_context_lookup() Chris Wilson
2019-03-06 14:40   ` Tvrtko Ursulin
2019-03-06 14:24 ` [PATCH 20/43] drm/i915: Make context pinning part of intel_context_ops Chris Wilson
2019-03-06 14:24 ` [PATCH 21/43] drm/i915: Track the pinned kernel contexts on each engine Chris Wilson
2019-03-08  9:26   ` Tvrtko Ursulin
2019-03-06 14:24 ` [PATCH 22/43] drm/i915: Introduce intel_context.pin_mutex for pin management Chris Wilson
2019-03-06 14:43   ` Tvrtko Ursulin
2019-03-06 14:51     ` Chris Wilson
2019-03-06 15:46       ` Tvrtko Ursulin
2019-03-06 14:24 ` [PATCH 23/43] drm/i915: Load balancing across a virtual engine Chris Wilson
2019-03-06 14:24 ` [PATCH 24/43] drm/i915: Extend execution fence to support a callback Chris Wilson
2019-03-06 14:24 ` [PATCH 25/43] drm/i915/execlists: Virtual engine bonding Chris Wilson
2019-03-06 14:25 ` [PATCH 26/43] drm/i915: Allow specification of parallel execbuf Chris Wilson
2019-03-06 14:25 ` [PATCH 27/43] drm/i915/selftests: Check preemption support on each engine Chris Wilson
2019-03-08  9:31   ` Tvrtko Ursulin
2019-03-06 14:25 ` [PATCH 28/43] drm/i915/execlists: Skip direct submission if only lite-restore Chris Wilson
2019-03-06 14:25 ` [PATCH 29/43] drm/i915: Split GEM object type definition to its own header Chris Wilson
2019-03-06 15:46   ` Matthew Auld
2019-03-06 14:25 ` [PATCH 30/43] drm/i915: Pull GEM ioctls interface to its own file Chris Wilson
2019-03-06 15:48   ` Matthew Auld
2019-03-06 14:25 ` [PATCH 31/43] drm/i915: Move object->pages API to i915_gem_object.[ch] Chris Wilson
2019-03-06 16:23   ` Matthew Auld
2019-03-06 16:29     ` Chris Wilson
2019-03-06 14:25 ` [PATCH 32/43] drm/i915: Move shmem object setup to its own file Chris Wilson
2019-03-06 17:05   ` Matthew Auld
2019-03-06 17:24     ` Chris Wilson
2019-03-06 14:25 ` [PATCH 33/43] drm/i915: Move phys objects " Chris Wilson
2019-03-07 12:31   ` Matthew Auld
2019-03-06 14:25 ` [PATCH 34/43] drm/i915: Move mmap and friends " Chris Wilson
2019-03-07 12:42   ` Matthew Auld
2019-03-06 14:25 ` [PATCH 35/43] drm/i915: Move GEM domain management " Chris Wilson
2019-03-07 13:00   ` Matthew Auld
2019-03-06 14:25 ` [PATCH 36/43] drm/i915: Move more GEM objects under gem/ Chris Wilson
2019-03-06 14:25 ` [PATCH 37/43] drm/i915: Pull scatterlist utils out of i915_gem.h Chris Wilson
2019-03-06 14:25 ` [PATCH 38/43] drm/i915: Move GEM object domain management from struct_mutex to local Chris Wilson
2019-03-06 14:25 ` [PATCH 39/43] drm/i915: Move GEM object waiting to its own file Chris Wilson
2019-03-06 14:25 ` [PATCH 40/43] drm/i915: Move GEM object busy checking " Chris Wilson
2019-03-06 14:25 ` [PATCH 41/43] drm/i915: Move GEM client throttling " Chris Wilson
2019-03-06 14:25 ` [PATCH 42/43] drm/i915: Drop the deferred active reference Chris Wilson
2019-03-06 14:25 ` [PATCH 43/43] drm/i915: Move object close under its own lock Chris Wilson
2019-03-06 15:08 ` ✗ Fi.CI.CHECKPATCH: warning for series starting with [01/43] drm/i915/selftests: Canonicalise gen8 addresses Patchwork
2019-03-06 15:25 ` ✗ Fi.CI.SPARSE: " Patchwork
2019-03-06 16:19 ` ✗ Fi.CI.BAT: failure " Patchwork

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=819751d2-2b21-23c0-bf72-b47a80244e47@linux.intel.com \
    --to=tvrtko.ursulin@linux.intel.com \
    --cc=chris@chris-wilson.co.uk \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=matthew.auld@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 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.