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 v4 12/16] drm/i915: Exercise request cancellation using a mock selftest
Date: Thu, 23 Feb 2017 12:21:02 +0000	[thread overview]
Message-ID: <e01cb421-1cfb-71d1-20b3-5e9fcba2b363@linux.intel.com> (raw)
In-Reply-To: <20170223074422.4125-13-chris@chris-wilson.co.uk>


On 23/02/2017 07:44, Chris Wilson wrote:
> Add a mock selftest to preempt a request and check that we cancel it,
> requeue the request and then complete its execution.
>
> v2: Error leaks no more.
>
> Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
> ---
>  drivers/gpu/drm/i915/selftests/i915_gem_request.c | 64 +++++++++++++++++++++++
>  drivers/gpu/drm/i915/selftests/mock_request.c     | 19 +++++++
>  drivers/gpu/drm/i915/selftests/mock_request.h     |  2 +
>  3 files changed, 85 insertions(+)
>
> diff --git a/drivers/gpu/drm/i915/selftests/i915_gem_request.c b/drivers/gpu/drm/i915/selftests/i915_gem_request.c
> index 9d056a86723d..42bdeac93324 100644
> --- a/drivers/gpu/drm/i915/selftests/i915_gem_request.c
> +++ b/drivers/gpu/drm/i915/selftests/i915_gem_request.c
> @@ -26,6 +26,7 @@
>
>  #include "../i915_selftest.h"
>
> +#include "mock_context.h"
>  #include "mock_gem_device.h"
>
>  static int igt_add_request(void *arg)
> @@ -181,12 +182,75 @@ static int igt_fence_wait(void *arg)
>  	return err;
>  }
>
> +static int igt_request_rewind(void *arg)
> +{
> +	struct drm_i915_private *i915 = arg;
> +	struct drm_i915_gem_request *request, *vip;
> +	struct i915_gem_context *ctx[2];
> +	int err = -EINVAL;
> +
> +	mutex_lock(&i915->drm.struct_mutex);
> +	ctx[0] = mock_context(i915, "A");
> +	request = mock_request(i915->engine[RCS], ctx[0], 2 * HZ);
> +	if (!request) {
> +		err = -ENOMEM;
> +		goto err_context_0;
> +	}
> +
> +	i915_gem_request_get(request);
> +	i915_add_request(request);
> +
> +	ctx[1] = mock_context(i915, "B");
> +	vip = mock_request(i915->engine[RCS], ctx[1], 0);
> +	if (!vip) {
> +		err = -ENOMEM;
> +		goto err_context_1;
> +	}
> +
> +	/* Simulate preemption by manual reordering */
> +	if (!mock_cancel_request(request)) {
> +		pr_err("failed to cancel request (already executed)!\n");
> +		i915_add_request(vip);
> +		goto err_context_1;
> +	}
> +	i915_gem_request_get(vip);
> +	i915_add_request(vip);
> +	request->engine->submit_request(request);
> +
> +	mutex_unlock(&i915->drm.struct_mutex);
> +
> +	if (i915_wait_request(vip, 0, HZ) == -ETIME) {
> +		pr_err("timed out waiting for high priority request, vip.seqno=%d, current seqno=%d\n",
> +		       vip->global_seqno, intel_engine_get_seqno(i915->engine[RCS]));
> +		goto err;
> +	}
> +
> +	if (i915_gem_request_completed(request)) {
> +		pr_err("low priority request already completed\n");
> +		goto err;
> +	}
> +
> +	err = 0;
> +err:
> +	i915_gem_request_put(vip);
> +	mutex_lock(&i915->drm.struct_mutex);
> +err_context_1:
> +	mock_context_close(ctx[1]);
> +	i915_gem_request_put(request);
> +err_context_0:
> +	mock_context_close(ctx[0]);
> +	mock_device_flush(i915);
> +	mutex_unlock(&i915->drm.struct_mutex);
> +	return err;
> +}
> +
>  int i915_gem_request_mock_selftests(void)
>  {
>  	static const struct i915_subtest tests[] = {
>  		SUBTEST(igt_add_request),
>  		SUBTEST(igt_wait_request),
>  		SUBTEST(igt_fence_wait),
> +		SUBTEST(igt_request_rewind),
>  	};
>  	struct drm_i915_private *i915;
>  	int err;
> diff --git a/drivers/gpu/drm/i915/selftests/mock_request.c b/drivers/gpu/drm/i915/selftests/mock_request.c
> index e23242d1b88a..0e8d2e7f8c70 100644
> --- a/drivers/gpu/drm/i915/selftests/mock_request.c
> +++ b/drivers/gpu/drm/i915/selftests/mock_request.c
> @@ -22,6 +22,7 @@
>   *
>   */
>
> +#include "mock_engine.h"
>  #include "mock_request.h"
>
>  struct drm_i915_gem_request *
> @@ -42,3 +43,21 @@ mock_request(struct intel_engine_cs *engine,
>
>  	return &mock->base;
>  }
> +
> +bool mock_cancel_request(struct drm_i915_gem_request *request)
> +{
> +	struct mock_request *mock = container_of(request, typeof(*mock), base);
> +	struct mock_engine *engine =
> +		container_of(request->engine, typeof(*engine), base);
> +	bool was_queued;
> +
> +	spin_lock_irq(&engine->hw_lock);
> +	was_queued = !list_empty(&mock->link);
> +	list_del_init(&mock->link);
> +	spin_unlock_irq(&engine->hw_lock);
> +
> +	if (was_queued)
> +		i915_gem_request_unsubmit(request);
> +
> +	return was_queued;
> +}
> diff --git a/drivers/gpu/drm/i915/selftests/mock_request.h b/drivers/gpu/drm/i915/selftests/mock_request.h
> index cc76d4f4eb4e..4dea74c8e96d 100644
> --- a/drivers/gpu/drm/i915/selftests/mock_request.h
> +++ b/drivers/gpu/drm/i915/selftests/mock_request.h
> @@ -41,4 +41,6 @@ mock_request(struct intel_engine_cs *engine,
>  	     struct i915_gem_context *context,
>  	     unsigned long delay);
>
> +bool mock_cancel_request(struct drm_i915_gem_request *request);
> +
>  #endif /* !__MOCK_REQUEST__ */
>

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:[~2017-02-23 12:21 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-23  7:44 Preemption preparation pass phaw Chris Wilson
2017-02-23  7:44 ` [PATCH v4 01/16] drm/i915: Check against the signaled bit for fences/requests Chris Wilson
2017-02-23  7:44 ` [PATCH v4 02/16] drm/i915: Keep a global seqno per-engine Chris Wilson
2017-02-23  7:44 ` [PATCH v4 03/16] drm/i915: Move reserve_seqno() next to unreserve_seqno() Chris Wilson
2017-02-23  7:44 ` [PATCH v4 04/16] drm/i915: Use a local to shorten req->i915->gpu_error.wait_queue Chris Wilson
2017-02-23  7:44 ` [PATCH v4 05/16] drm/i915: Add ourselves to the gpu error waitqueue for the entire wait Chris Wilson
2017-02-23  7:44 ` [PATCH v4 06/16] drm/i915: Inline __i915_gem_request_wait_for_execute() Chris Wilson
2017-02-23  7:44 ` [PATCH v4 07/16] drm/i915: Deconstruct execute fence Chris Wilson
2017-02-23  7:44 ` [PATCH v4 08/16] drm/i915: Protect the request->global_seqno with the engine->timeline lock Chris Wilson
2017-02-23  7:44 ` [PATCH v4 09/16] drm/i915: Take a reference whilst processing the signaler request Chris Wilson
2017-02-23  7:44 ` [PATCH v4 10/16] drm/i915: Allow a request to be cancelled Chris Wilson
2017-02-23  7:44 ` [PATCH v4 11/16] drm/i915: Remove the preempted request from the execution queue Chris Wilson
2017-02-23 12:11   ` Tvrtko Ursulin
2017-02-23  7:44 ` [PATCH v4 12/16] drm/i915: Exercise request cancellation using a mock selftest Chris Wilson
2017-02-23 12:21   ` Tvrtko Ursulin [this message]
2017-02-23  7:44 ` [PATCH v4 13/16] drm/i915: Replace reset_wait_queue with default_wake_function Chris Wilson
2017-02-23  7:44 ` [PATCH v4 14/16] drm/i915: Refactor direct GPU reset from request waiters Chris Wilson
2017-02-23 12:23   ` Tvrtko Ursulin
2017-02-23  7:44 ` [PATCH v4 15/16] drm/i915: Immediately process a reset before starting waiting Chris Wilson
2017-02-23 12:35   ` Tvrtko Ursulin
2017-02-23 12:41     ` Chris Wilson
2017-02-23 12:45       ` Tvrtko Ursulin
2017-02-23  7:44 ` [PATCH v4 16/16] drm/i915: Remove one level of indention from wait-for-execute Chris Wilson
2017-02-23  8:18 ` ✓ Fi.CI.BAT: success for series starting with [v4,01/16] drm/i915: Check against the signaled bit for fences/requests Patchwork
2017-02-23 15:21   ` 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=e01cb421-1cfb-71d1-20b3-5e9fcba2b363@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.