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
Subject: Re: [PATCH 15/40] drm/i915: Apply an execution_mask to the virtual_engine
Date: Wed, 8 May 2019 11:13:32 +0100	[thread overview]
Message-ID: <295baf29-7b55-837e-d221-e54c67903a32@linux.intel.com> (raw)
In-Reply-To: <20190508080704.24223-15-chris@chris-wilson.co.uk>


On 08/05/2019 09:06, Chris Wilson wrote:
> Allow the user to direct which physical engines of the virtual engine
> they wish to execute one, as sometimes it is necessary to override the
> load balancing algorithm.
> 
> v2: Only kick the virtual engines on context-out if required
> 
> Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
> Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
> ---
>   drivers/gpu/drm/i915/gt/intel_lrc.c    |  67 +++++++++++++
>   drivers/gpu/drm/i915/gt/selftest_lrc.c | 131 +++++++++++++++++++++++++
>   drivers/gpu/drm/i915/i915_request.c    |   1 +
>   drivers/gpu/drm/i915/i915_request.h    |   3 +
>   4 files changed, 202 insertions(+)
> 
> diff --git a/drivers/gpu/drm/i915/gt/intel_lrc.c b/drivers/gpu/drm/i915/gt/intel_lrc.c
> index bc388df39802..69849ffb9c82 100644
> --- a/drivers/gpu/drm/i915/gt/intel_lrc.c
> +++ b/drivers/gpu/drm/i915/gt/intel_lrc.c
> @@ -550,6 +550,15 @@ execlists_context_schedule_in(struct i915_request *rq)
>   	rq->hw_context->active = rq->engine;
>   }
>   
> +static void kick_siblings(struct i915_request *rq)
> +{
> +	struct virtual_engine *ve = to_virtual_engine(rq->hw_context->engine);
> +	struct i915_request *next = READ_ONCE(ve->request);
> +
> +	if (next && next->execution_mask & ~rq->execution_mask)
> +		tasklet_schedule(&ve->base.execlists.tasklet);
> +}
> +
>   static inline void
>   execlists_context_schedule_out(struct i915_request *rq, unsigned long status)
>   {
> @@ -557,6 +566,18 @@ execlists_context_schedule_out(struct i915_request *rq, unsigned long status)
>   	intel_engine_context_out(rq->engine);
>   	execlists_context_status_change(rq, status);
>   	trace_i915_request_out(rq);
> +
> +	/*
> +	 * If this is part of a virtual engine, its next request may have
> +	 * been blocked waiting for access to the active context. We have
> +	 * to kick all the siblings again in case we need to switch (e.g.
> +	 * the next request is not runnable on this engine). Hopefully,
> +	 * we will already have submitted the next request before the
> +	 * tasklet runs and do not need to rebuild each virtual tree
> +	 * and kick everyone again.
> +	 */
> +	if (rq->engine != rq->hw_context->engine)
> +		kick_siblings(rq);
>   }
>   
>   static u64 execlists_update_context(struct i915_request *rq)
> @@ -787,6 +808,9 @@ static bool virtual_matches(const struct virtual_engine *ve,
>   {
>   	const struct intel_engine_cs *active;
>   
> +	if (!(rq->execution_mask & engine->mask)) /* We peeked too soon! */
> +		return false;
> +
>   	/*
>   	 * We track when the HW has completed saving the context image
>   	 * (i.e. when we have seen the final CS event switching out of
> @@ -3159,12 +3183,44 @@ static const struct intel_context_ops virtual_context_ops = {
>   	.destroy = virtual_context_destroy,
>   };
>   
> +static intel_engine_mask_t virtual_submission_mask(struct virtual_engine *ve)
> +{
> +	struct i915_request *rq;
> +	intel_engine_mask_t mask;
> +
> +	rq = READ_ONCE(ve->request);
> +	if (!rq)
> +		return 0;
> +
> +	/* The rq is ready for submission; rq->execution_mask is now stable. */
> +	mask = rq->execution_mask;
> +	if (unlikely(!mask)) {
> +		/* Invalid selection, submit to a random engine in error */
> +		i915_request_skip(rq, -ENODEV);
> +		mask = ve->siblings[0]->mask;
> +	}
> +
> +	GEM_TRACE("%s: rq=%llx:%lld, mask=%x, prio=%d\n",
> +		  ve->base.name,
> +		  rq->fence.context, rq->fence.seqno,
> +		  mask, ve->base.execlists.queue_priority_hint);
> +
> +	return mask;
> +}
> +
>   static void virtual_submission_tasklet(unsigned long data)
>   {
>   	struct virtual_engine * const ve = (struct virtual_engine *)data;
>   	const int prio = ve->base.execlists.queue_priority_hint;
> +	intel_engine_mask_t mask;
>   	unsigned int n;
>   
> +	rcu_read_lock();
> +	mask = virtual_submission_mask(ve);
> +	rcu_read_unlock();
> +	if (unlikely(!mask))
> +		return;
> +
>   	local_irq_disable();
>   	for (n = 0; READ_ONCE(ve->request) && n < ve->num_siblings; n++) {
>   		struct intel_engine_cs *sibling = ve->siblings[n];
> @@ -3172,6 +3228,17 @@ static void virtual_submission_tasklet(unsigned long data)
>   		struct rb_node **parent, *rb;
>   		bool first;
>   
> +		if (unlikely(!(mask & sibling->mask))) {
> +			if (!RB_EMPTY_NODE(&node->rb)) {
> +				spin_lock(&sibling->timeline.lock);
> +				rb_erase_cached(&node->rb,
> +						&sibling->execlists.virtual);
> +				RB_CLEAR_NODE(&node->rb);
> +				spin_unlock(&sibling->timeline.lock);
> +			}
> +			continue;
> +		}
> +
>   		spin_lock(&sibling->timeline.lock);
>   
>   		if (!RB_EMPTY_NODE(&node->rb)) {
> diff --git a/drivers/gpu/drm/i915/gt/selftest_lrc.c b/drivers/gpu/drm/i915/gt/selftest_lrc.c
> index ccc0b6350123..2ef7639ee665 100644
> --- a/drivers/gpu/drm/i915/gt/selftest_lrc.c
> +++ b/drivers/gpu/drm/i915/gt/selftest_lrc.c
> @@ -1489,6 +1489,136 @@ static int live_virtual_engine(void *arg)
>   	return err;
>   }
>   
> +static int mask_virtual_engine(struct drm_i915_private *i915,
> +			       struct intel_engine_cs **siblings,
> +			       unsigned int nsibling)
> +{
> +	struct i915_request *request[MAX_ENGINE_INSTANCE + 1];
> +	struct i915_gem_context *ctx;
> +	struct intel_context *ve;
> +	struct igt_live_test t;
> +	unsigned int n;
> +	int err;
> +
> +	/*
> +	 * Check that by setting the execution mask on a request, we can
> +	 * restrict it to our desired engine within the virtual engine.
> +	 */
> +
> +	ctx = kernel_context(i915);
> +	if (!ctx)
> +		return -ENOMEM;
> +
> +	ve = intel_execlists_create_virtual(ctx, siblings, nsibling);
> +	if (IS_ERR(ve)) {
> +		err = PTR_ERR(ve);
> +		goto out_close;
> +	}
> +
> +	err = intel_context_pin(ve);
> +	if (err)
> +		goto out_put;
> +
> +	err = igt_live_test_begin(&t, i915, __func__, ve->engine->name);
> +	if (err)
> +		goto out_unpin;
> +
> +	for (n = 0; n < nsibling; n++) {
> +		request[n] = i915_request_create(ve);
> +		if (IS_ERR(request)) {
> +			err = PTR_ERR(request);
> +			nsibling = n;
> +			goto out;
> +		}
> +
> +		/* Reverse order as it's more likely to be unnatural */
> +		request[n]->execution_mask = siblings[nsibling - n - 1]->mask;
> +
> +		i915_request_get(request[n]);
> +		i915_request_add(request[n]);
> +	}
> +
> +	for (n = 0; n < nsibling; n++) {
> +		if (i915_request_wait(request[n], I915_WAIT_LOCKED, HZ / 10) < 0) {
> +			pr_err("%s(%s): wait for %llx:%lld timed out\n",
> +			       __func__, ve->engine->name,
> +			       request[n]->fence.context,
> +			       request[n]->fence.seqno);
> +
> +			GEM_TRACE("%s(%s) failed at request %llx:%lld\n",
> +				  __func__, ve->engine->name,
> +				  request[n]->fence.context,
> +				  request[n]->fence.seqno);
> +			GEM_TRACE_DUMP();
> +			i915_gem_set_wedged(i915);
> +			err = -EIO;
> +			goto out;
> +		}
> +
> +		if (request[n]->engine != siblings[nsibling - n - 1]) {
> +			pr_err("Executed on wrong sibling '%s', expected '%s'\n",
> +			       request[n]->engine->name,
> +			       siblings[nsibling - n - 1]->name);
> +			err = -EINVAL;
> +			goto out;
> +		}
> +	}
> +
> +	err = igt_live_test_end(&t);
> +	if (err)
> +		goto out;
> +
> +out:
> +	if (igt_flush_test(i915, I915_WAIT_LOCKED))
> +		err = -EIO;
> +
> +	for (n = 0; n < nsibling; n++)
> +		i915_request_put(request[n]);
> +
> +out_unpin:
> +	intel_context_unpin(ve);
> +out_put:
> +	intel_context_put(ve);
> +out_close:
> +	kernel_context_close(ctx);
> +	return err;
> +}
> +
> +static int live_virtual_mask(void *arg)
> +{
> +	struct drm_i915_private *i915 = arg;
> +	struct intel_engine_cs *siblings[MAX_ENGINE_INSTANCE + 1];
> +	unsigned int class, inst;
> +	int err = 0;
> +
> +	if (USES_GUC_SUBMISSION(i915))
> +		return 0;
> +
> +	mutex_lock(&i915->drm.struct_mutex);
> +
> +	for (class = 0; class <= MAX_ENGINE_CLASS; class++) {
> +		unsigned int nsibling;
> +
> +		nsibling = 0;
> +		for (inst = 0; inst <= MAX_ENGINE_INSTANCE; inst++) {
> +			if (!i915->engine_class[class][inst])
> +				break;
> +
> +			siblings[nsibling++] = i915->engine_class[class][inst];
> +		}
> +		if (nsibling < 2)
> +			continue;
> +
> +		err = mask_virtual_engine(i915, siblings, nsibling);
> +		if (err)
> +			goto out_unlock;
> +	}
> +
> +out_unlock:
> +	mutex_unlock(&i915->drm.struct_mutex);
> +	return err;
> +}
> +
>   int intel_execlists_live_selftests(struct drm_i915_private *i915)
>   {
>   	static const struct i915_subtest tests[] = {
> @@ -1502,6 +1632,7 @@ int intel_execlists_live_selftests(struct drm_i915_private *i915)
>   		SUBTEST(live_preempt_hang),
>   		SUBTEST(live_preempt_smoke),
>   		SUBTEST(live_virtual_engine),
> +		SUBTEST(live_virtual_mask),
>   	};
>   
>   	if (!HAS_EXECLISTS(i915))
> diff --git a/drivers/gpu/drm/i915/i915_request.c b/drivers/gpu/drm/i915/i915_request.c
> index cbe4098cd6ec..3beced7daa15 100644
> --- a/drivers/gpu/drm/i915/i915_request.c
> +++ b/drivers/gpu/drm/i915/i915_request.c
> @@ -699,6 +699,7 @@ __i915_request_create(struct intel_context *ce, gfp_t gfp)
>   	rq->batch = NULL;
>   	rq->capture_list = NULL;
>   	rq->waitboost = false;
> +	rq->execution_mask = ALL_ENGINES;
>   
>   	INIT_LIST_HEAD(&rq->active_list);
>   	INIT_LIST_HEAD(&rq->execute_cb);
> diff --git a/drivers/gpu/drm/i915/i915_request.h b/drivers/gpu/drm/i915/i915_request.h
> index 8025a89b5999..d7f9b2194568 100644
> --- a/drivers/gpu/drm/i915/i915_request.h
> +++ b/drivers/gpu/drm/i915/i915_request.h
> @@ -28,6 +28,8 @@
>   #include <linux/dma-fence.h>
>   #include <linux/lockdep.h>
>   
> +#include "gt/intel_engine_types.h"
> +
>   #include "i915_gem.h"
>   #include "i915_scheduler.h"
>   #include "i915_selftest.h"
> @@ -156,6 +158,7 @@ struct i915_request {
>   	 */
>   	struct i915_sched_node sched;
>   	struct i915_dependency dep;
> +	intel_engine_mask_t execution_mask;
>   
>   	/*
>   	 * A convenience pointer to the current breadcrumb value stored in
> 

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-05-08 10:13 UTC|newest]

Thread overview: 71+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-08  8:06 [PATCH 01/40] drm/i915/hangcheck: Replace hangcheck.seqno with RING_HEAD Chris Wilson
2019-05-08  8:06 ` [PATCH 02/40] drm/i915: Rearrange i915_scheduler.c Chris Wilson
2019-05-08  8:06 ` [PATCH 03/40] drm/i915: Pass i915_sched_node around internally Chris Wilson
2019-05-08 10:15   ` Tvrtko Ursulin
2019-05-08  8:06 ` [PATCH 04/40] drm/i915: Check for no-op priority changes first Chris Wilson
2019-05-08 10:16   ` Tvrtko Ursulin
2019-05-08  8:06 ` [PATCH 05/40] drm/i915: Bump signaler priority on adding a waiter Chris Wilson
2019-05-08  8:06 ` [PATCH 06/40] drm/i915: Convert inconsistent static engine tables into an init error Chris Wilson
2019-05-08  8:06 ` [PATCH 07/40] drm/i915: Seal races between async GPU cancellation, retirement and signaling Chris Wilson
2019-05-08 10:21   ` Tvrtko Ursulin
2019-05-08 11:24   ` [PATCH] " Chris Wilson
2019-05-08 11:50     ` Tvrtko Ursulin
2019-05-08  8:06 ` [PATCH 08/40] dma-fence: Refactor signaling for manual invocation Chris Wilson
2019-05-08 11:25   ` [PATCH] " Chris Wilson
2019-05-08 11:52     ` Tvrtko Ursulin
2019-05-08  8:06 ` [PATCH 09/40] drm/i915: Restore control over ppgtt for context creation ABI Chris Wilson
2019-05-08 10:24   ` Tvrtko Ursulin
2019-05-08  8:06 ` [PATCH 10/40] drm/i915: Allow a context to define its set of engines Chris Wilson
2019-05-08  8:06 ` [PATCH 11/40] drm/i915: Extend I915_CONTEXT_PARAM_SSEU to support local ctx->engine[] Chris Wilson
2019-05-08 10:25   ` Tvrtko Ursulin
2019-05-08  8:06 ` [PATCH 12/40] drm/i915: Re-expose SINGLE_TIMELINE flags for context creation Chris Wilson
2019-05-08 10:26   ` Tvrtko Ursulin
2019-05-08  8:06 ` [PATCH 13/40] drm/i915: Allow userspace to clone contexts on creation Chris Wilson
2019-05-08  8:06 ` [PATCH 14/40] drm/i915: Load balancing across a virtual engine Chris Wilson
2019-05-08 10:29   ` Tvrtko Ursulin
2019-05-08 11:17     ` Chris Wilson
2019-05-08 11:36       ` Tvrtko Ursulin
2019-05-08 11:23   ` [PATCH] " Chris Wilson
2019-05-08 11:35     ` Tvrtko Ursulin
2019-05-08  8:06 ` [PATCH 15/40] drm/i915: Apply an execution_mask to the virtual_engine Chris Wilson
2019-05-08 10:13   ` Tvrtko Ursulin [this message]
2019-05-08  8:06 ` [PATCH 16/40] drm/i915: Extend execution fence to support a callback Chris Wilson
2019-05-08  8:06 ` [PATCH 17/40] drm/i915/execlists: Virtual engine bonding Chris Wilson
2019-05-08  8:06 ` [PATCH 18/40] drm/i915: Allow specification of parallel execbuf Chris Wilson
2019-05-08  8:06 ` [PATCH 19/40] drm/i915: Split GEM object type definition to its own header Chris Wilson
2019-05-08  8:06 ` [PATCH 20/40] drm/i915: Pull GEM ioctls interface to its own file Chris Wilson
2019-05-08  8:06 ` [PATCH 21/40] drm/i915: Move object->pages API to i915_gem_object.[ch] Chris Wilson
2019-05-08  8:06 ` [PATCH 22/40] drm/i915: Move shmem object setup to its own file Chris Wilson
2019-05-08  8:06 ` [PATCH 23/40] drm/i915: Move phys objects " Chris Wilson
2019-05-08  8:06 ` [PATCH 24/40] drm/i915: Move mmap and friends " Chris Wilson
2019-05-08  8:06 ` [PATCH 25/40] drm/i915: Move GEM domain management " Chris Wilson
2019-05-08  8:06 ` [PATCH 26/40] drm/i915: Move more GEM objects under gem/ Chris Wilson
2019-05-08  8:06 ` [PATCH 27/40] drm/i915: Pull scatterlist utils out of i915_gem.h Chris Wilson
2019-05-08  8:06 ` [PATCH 28/40] drm/i915: Move GEM object domain management from struct_mutex to local Chris Wilson
2019-05-08  8:06 ` [PATCH 29/40] drm/i915: Move GEM object waiting to its own file Chris Wilson
2019-05-10 14:17   ` Mika Kuoppala
2019-05-10 14:33     ` Chris Wilson
2019-05-08  8:06 ` [PATCH 30/40] drm/i915: Move GEM object busy checking " Chris Wilson
2019-05-10 14:29   ` Mika Kuoppala
2019-05-08  8:06 ` [PATCH 31/40] drm/i915: Move GEM client throttling " Chris Wilson
2019-05-10 14:37   ` Mika Kuoppala
2019-05-08  8:06 ` [PATCH 32/40] drm/i915: Drop the deferred active reference Chris Wilson
2019-05-08  8:06 ` [PATCH 33/40] drm/i915: Move object close under its own lock Chris Wilson
2019-05-08  8:06 ` [PATCH 34/40] drm/i915: Rename intel_context.active to .inflight Chris Wilson
2019-05-10 14:44   ` Mika Kuoppala
2019-05-08  8:06 ` [PATCH 35/40] drm/i915: Keep contexts pinned until after the next kernel context switch Chris Wilson
2019-05-08  8:07 ` [PATCH 36/40] drm/i915: Stop retiring along engine Chris Wilson
2019-05-08  8:07 ` [PATCH 37/40] drm/i915: Replace engine->timeline with a plain list Chris Wilson
2019-05-08  8:07 ` [PATCH 38/40] drm/i915: Flush the execution-callbacks on retiring Chris Wilson
2019-05-08  8:07 ` [PATCH 39/40] drm/i915/execlists: Preempt-to-busy Chris Wilson
2019-05-08  8:07 ` [PATCH 40/40] drm/i915/execlists: Minimalistic timeslicing Chris Wilson
2019-05-08 10:47 ` ✗ Fi.CI.CHECKPATCH: warning for series starting with [01/40] drm/i915/hangcheck: Replace hangcheck.seqno with RING_HEAD Patchwork
2019-05-08 10:59 ` ✗ Fi.CI.SPARSE: " Patchwork
2019-05-08 11:09 ` ✓ Fi.CI.BAT: success " Patchwork
2019-05-08 11:49 ` ✗ Fi.CI.CHECKPATCH: warning for series starting with [01/40] drm/i915/hangcheck: Replace hangcheck.seqno with RING_HEAD (rev4) Patchwork
2019-05-08 12:06 ` ✗ Fi.CI.SPARSE: " Patchwork
2019-05-08 12:10 ` ✗ Fi.CI.BAT: failure " Patchwork
2019-05-08 12:30 ` [PATCH 01/40] drm/i915/hangcheck: Replace hangcheck.seqno with RING_HEAD Mika Kuoppala
2019-05-08 12:40   ` Chris Wilson
2019-05-08 14:00     ` Mika Kuoppala
2019-05-08 14:10       ` 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=295baf29-7b55-837e-d221-e54c67903a32@linux.intel.com \
    --to=tvrtko.ursulin@linux.intel.com \
    --cc=chris@chris-wilson.co.uk \
    --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.