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 09/46] drm/i915: Add unit tests for the breadcrumb rbtree, wakeups
Date: Thu, 2 Feb 2017 12:49:58 +0000	[thread overview]
Message-ID: <67e5b886-f968-871a-e838-69a6a2ff54fc@linux.intel.com> (raw)
In-Reply-To: <20170202090905.29028-10-chris@chris-wilson.co.uk>


On 02/02/2017 09:08, Chris Wilson wrote:
> Third retroactive test, make sure that the seqno waiters are woken.
>
> v2: Smattering of comments, rearrange code

v3: Fix assert.

> Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
> ---
>  drivers/gpu/drm/i915/selftests/intel_breadcrumbs.c | 201 +++++++++++++++++++++
>  1 file changed, 201 insertions(+)
>
> diff --git a/drivers/gpu/drm/i915/selftests/intel_breadcrumbs.c b/drivers/gpu/drm/i915/selftests/intel_breadcrumbs.c
> index 32a27e56c353..fb368eb37660 100644
> --- a/drivers/gpu/drm/i915/selftests/intel_breadcrumbs.c
> +++ b/drivers/gpu/drm/i915/selftests/intel_breadcrumbs.c
> @@ -259,11 +259,212 @@ static int igt_insert_complete(void *arg)
>  	return err;
>  }
>
> +struct igt_wakeup {
> +	struct task_struct *tsk;
> +	atomic_t *ready, *set, *done;
> +	struct intel_engine_cs *engine;
> +	unsigned long flags;
> +#define STOP 0
> +#define IDLE 1
> +	wait_queue_head_t *wq;
> +	u32 seqno;
> +};
> +
> +static int wait_atomic(atomic_t *p)
> +{
> +	schedule();
> +	return 0;
> +}
> +
> +static int wait_atomic_timeout(atomic_t *p)
> +{
> +	return schedule_timeout(10 * HZ) ? 0 : -ETIMEDOUT;
> +}
> +
> +static bool wait_for_ready(struct igt_wakeup *w)
> +{
> +	DEFINE_WAIT(ready);
> +
> +	if (atomic_dec_and_test(w->done))
> +		wake_up_atomic_t(w->done);
> +
> +	if (test_bit(STOP, &w->flags))
> +		goto out;
> +
> +	set_bit(IDLE, &w->flags);

I think this needs to be before atomic_dec_and_test(w->done), to avoid 
that same assert racing with the threads. Because immediately after the 
wake_up_atomic above the main loop starts asserting the IDLE bit which 
is not guaranteed to be set yet.

Regards,

Tvrtko

> +	for (;;) {
> +		prepare_to_wait(w->wq, &ready, TASK_INTERRUPTIBLE);
> +		if (atomic_read(w->ready) == 0)
> +			break;
> +
> +		schedule();
> +	}
> +	finish_wait(w->wq, &ready);
> +	clear_bit(IDLE, &w->flags);
> +
> +out:
> +	if (atomic_dec_and_test(w->set))
> +		wake_up_atomic_t(w->set);
> +
> +	return !test_bit(STOP, &w->flags);
> +}
> +
> +static int igt_wakeup_thread(void *arg)
> +{
> +	struct igt_wakeup *w = arg;
> +	struct intel_wait wait;
> +
> +	while (wait_for_ready(w)) {
> +		GEM_BUG_ON(kthread_should_stop());
> +
> +		intel_wait_init(&wait, w->seqno);
> +		intel_engine_add_wait(w->engine, &wait);
> +		for (;;) {
> +			set_current_state(TASK_UNINTERRUPTIBLE);
> +			if (i915_seqno_passed(intel_engine_get_seqno(w->engine),
> +					      w->seqno))
> +				break;
> +
> +			if (test_bit(STOP, &w->flags)) /* emergency escape */
> +				break;
> +
> +			schedule();
> +		}
> +		intel_engine_remove_wait(w->engine, &wait);
> +		__set_current_state(TASK_RUNNING);
> +	}
> +
> +	return 0;
> +}
> +
> +static void igt_wake_all_sync(atomic_t *ready,
> +			      atomic_t *set,
> +			      atomic_t *done,
> +			      wait_queue_head_t *wq,
> +			      int count)
> +{
> +	atomic_set(set, count);
> +	atomic_set(ready, 0);
> +	wake_up_all(wq);
> +
> +	wait_on_atomic_t(set, wait_atomic, TASK_UNINTERRUPTIBLE);
> +	atomic_set(ready, count);
> +	atomic_set(done, count);
> +}
> +
> +static int igt_wakeup(void *arg)
> +{
> +	I915_RND_STATE(prng);
> +	const int state = TASK_UNINTERRUPTIBLE;
> +	struct intel_engine_cs *engine = arg;
> +	struct igt_wakeup *waiters;
> +	DECLARE_WAIT_QUEUE_HEAD_ONSTACK(wq);
> +	const int count = 4096;
> +	const u32 max_seqno = count / 4;
> +	atomic_t ready, set, done;
> +	int err = -ENOMEM;
> +	int n, step;
> +
> +	mock_engine_reset(engine);
> +
> +	waiters = drm_malloc_gfp(count, sizeof(*waiters), GFP_TEMPORARY);
> +	if (!waiters)
> +		goto out_engines;
> +
> +	/* Create a large number of threads, each waiting on a random seqno.
> +	 * Multiple waiters will be waiting for the same seqno.
> +	 */
> +	atomic_set(&ready, count);
> +	for (n = 0; n < count; n++) {
> +		waiters[n].wq = &wq;
> +		waiters[n].ready = &ready;
> +		waiters[n].set = &set;
> +		waiters[n].done = &done;
> +		waiters[n].engine = engine;
> +		waiters[n].flags = BIT(IDLE);
> +
> +		waiters[n].tsk = kthread_run(igt_wakeup_thread, &waiters[n],
> +					     "i915/igt:%d", n);
> +		if (IS_ERR(waiters[n].tsk))
> +			goto out_waiters;
> +
> +		get_task_struct(waiters[n].tsk);
> +	}
> +
> +	for (step = 1; step <= max_seqno; step <<= 1) {
> +		u32 seqno;
> +
> +		/* The waiter threads start paused as we assign them a random
> +		 * seqno and reset the engine. Once the engine is reset,
> +		 * we signal that the threads may begin their wait upon their
> +		 * seqno.
> +		 */
> +		for (n = 0; n < count; n++) {
> +			GEM_BUG_ON(!test_bit(IDLE, &waiters[n].flags));
> +			waiters[n].seqno =
> +				1 + prandom_u32_state(&prng) % max_seqno;
> +		}
> +		mock_seqno_advance(engine, 0);
> +		igt_wake_all_sync(&ready, &set, &done, &wq, count);
> +
> +		/* Simulate the GPU doing chunks of work, with one or more
> +		 * seqno appearing to finish at the same time. A random number
> +		 * of threads will be waiting upon the update and hopefully be
> +		 * woken.
> +		 */
> +		for (seqno = 1; seqno <= max_seqno + step; seqno += step) {
> +			usleep_range(50, 500);
> +			mock_seqno_advance(engine, seqno);
> +		}
> +		GEM_BUG_ON(intel_engine_get_seqno(engine) < 1 + max_seqno);
> +
> +		/* With the seqno now beyond any of the waiting threads, they
> +		 * should all be woken, see that they are complete and signal
> +		 * that they are ready for the next test. We wait until all
> +		 * threads are complete and waiting for us (i.e. not a seqno).
> +		 */
> +		err = wait_on_atomic_t(&done, wait_atomic_timeout, state);
> +		if (err) {
> +			pr_err("Timed out waiting for %d remaining waiters\n",
> +			       atomic_read(&done));
> +			break;
> +		}
> +
> +		err = check_rbtree_empty(engine);
> +		if (err)
> +			break;
> +	}
> +
> +out_waiters:
> +	for (n = 0; n < count; n++) {
> +		if (IS_ERR(waiters[n].tsk))
> +			break;
> +
> +		set_bit(STOP, &waiters[n].flags);
> +	}
> +	mock_seqno_advance(engine, INT_MAX); /* wakeup any broken waiters */
> +	igt_wake_all_sync(&ready, &set, &done, &wq, n);
> +
> +	for (n = 0; n < count; n++) {
> +		if (IS_ERR(waiters[n].tsk))
> +			break;
> +
> +		kthread_stop(waiters[n].tsk);
> +		put_task_struct(waiters[n].tsk);
> +	}
> +
> +	drm_free_large(waiters);
> +out_engines:
> +	mock_engine_flush(engine);
> +	return err;
> +}
> +
>  int intel_breadcrumbs_mock_selftests(void)
>  {
>  	static const struct i915_subtest tests[] = {
>  		SUBTEST(igt_random_insert_remove),
>  		SUBTEST(igt_insert_complete),
> +		SUBTEST(igt_wakeup),
>  	};
>  	struct intel_engine_cs *engine;
>  	int err;
>
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

  reply	other threads:[~2017-02-02 12:50 UTC|newest]

Thread overview: 81+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-02  9:08 Moah selftests Chris Wilson
2017-02-02  9:08 ` [PATCH 01/46] drm: Provide a driver hook for drm_dev_release() Chris Wilson
2017-02-02  9:24   ` Laurent Pinchart
2017-02-02  9:36   ` [PATCH v6] " Chris Wilson
2017-02-02  9:44     ` Daniel Vetter
2017-02-02  9:08 ` [PATCH 02/46] drm/i915: Split device release from unload Chris Wilson
2017-02-08 13:41   ` Joonas Lahtinen
2017-02-02  9:08 ` [PATCH 03/46] drm/i915: Unbind any residual objects/vma from the Global GTT on shutdown Chris Wilson
2017-02-08 13:36   ` Joonas Lahtinen
2017-02-02  9:08 ` [PATCH 04/46] drm/i915: Flush the freed object queue on device release Chris Wilson
2017-02-08 13:38   ` Joonas Lahtinen
2017-02-02  9:08 ` [PATCH 05/46] drm/i915: Provide a hook for selftests Chris Wilson
2017-02-02  9:11   ` Chris Wilson
2017-02-10 10:19   ` Tvrtko Ursulin
2017-02-10 10:36     ` Chris Wilson
2017-02-02  9:08 ` [PATCH 06/46] drm/i915: Add some selftests for sg_table manipulation Chris Wilson
2017-02-10 10:24   ` Tvrtko Ursulin
2017-02-10 10:43     ` Chris Wilson
2017-02-10 12:01       ` Tvrtko Ursulin
2017-02-02  9:08 ` [PATCH 07/46] drm/i915: Add unit tests for the breadcrumb rbtree, insert/remove Chris Wilson
2017-02-02  9:08 ` [PATCH 08/46] drm/i915: Add unit tests for the breadcrumb rbtree, completion Chris Wilson
2017-02-02  9:08 ` [PATCH 09/46] drm/i915: Add unit tests for the breadcrumb rbtree, wakeups Chris Wilson
2017-02-02 12:49   ` Tvrtko Ursulin [this message]
2017-02-02 13:02     ` Chris Wilson
2017-02-02  9:08 ` [PATCH 10/46] drm/i915: Mock the GEM device for self-testing Chris Wilson
2017-02-02  9:08 ` [PATCH 11/46] drm/i915: Mock a GGTT " Chris Wilson
2017-02-02  9:08 ` [PATCH 12/46] drm/i915: Mock infrastructure for request emission Chris Wilson
2017-02-02  9:08 ` [PATCH 13/46] drm/i915: Create a fake object for testing huge allocations Chris Wilson
2017-02-02  9:08 ` [PATCH 14/46] drm/i915: Add selftests for i915_gem_request Chris Wilson
2017-02-02  9:08 ` [PATCH 15/46] drm/i915: Add a simple request selftest for waiting Chris Wilson
2017-02-02  9:08 ` [PATCH 16/46] drm/i915: Add a simple fence selftest to i915_gem_request Chris Wilson
2017-02-02  9:08 ` [PATCH 17/46] drm/i915: Simple selftest to exercise live requests Chris Wilson
2017-02-02  9:08 ` [PATCH 18/46] drm/i915: Test simultaneously submitting requests to all engines Chris Wilson
2017-02-02  9:08 ` [PATCH 19/46] drm/i915: Test request ordering between engines Chris Wilson
2017-02-09 10:20   ` Joonas Lahtinen
2017-02-02  9:08 ` [PATCH 20/46] drm/i915: Live testing of empty requests Chris Wilson
2017-02-09 10:30   ` Joonas Lahtinen
2017-02-02  9:08 ` [PATCH 21/46] drm/i915: Add selftests for object allocation, phys Chris Wilson
2017-02-02 13:10   ` Matthew Auld
2017-02-02 13:20     ` Chris Wilson
2017-02-02  9:08 ` [PATCH 22/46] drm/i915: Add a live seftest for GEM objects Chris Wilson
2017-02-02  9:08 ` [PATCH 23/46] drm/i915: Test partial mappings Chris Wilson
2017-02-02  9:08 ` [PATCH 24/46] drm/i915: Test exhaustion of the mmap space Chris Wilson
2017-02-02  9:08 ` [PATCH 25/46] drm/i915: Test coherency of and barriers between cache domains Chris Wilson
2017-02-02  9:08 ` [PATCH 26/46] drm/i915: Move uncore selfchecks to live selftest infrastructure Chris Wilson
2017-02-02  9:08 ` [PATCH 27/46] drm/i915: Test all fw tables during mock selftests Chris Wilson
2017-02-02  9:08 ` [PATCH 28/46] drm/i915: Sanity check all registers for matching fw domains Chris Wilson
2017-02-02  9:08 ` [PATCH 29/46] drm/i915: Add some mock tests for dmabuf interop Chris Wilson
2017-02-02  9:08 ` [PATCH 30/46] drm/i915: Add a live dmabuf selftest Chris Wilson
2017-02-09 10:59   ` Joonas Lahtinen
2017-02-02  9:08 ` [PATCH 31/46] drm/i915: Add initial selftests for i915_gem_gtt Chris Wilson
2017-02-02  9:08 ` [PATCH 32/46] drm/i915: Exercise filling the top/bottom portions of the ppgtt Chris Wilson
2017-02-09 10:49   ` Joonas Lahtinen
2017-02-02  9:08 ` [PATCH 33/46] drm/i915: Exercise filling the top/bottom portions of the global GTT Chris Wilson
2017-02-02  9:08 ` [PATCH 34/46] drm/i915: Fill different pages of the GTT Chris Wilson
2017-02-02  9:08 ` [PATCH 35/46] drm/i915: Exercise filling and removing random ranges from the live GTT Chris Wilson
2017-02-02  9:08 ` [PATCH 36/46] drm/i915: Test creation of VMA Chris Wilson
2017-02-02  9:08 ` [PATCH 37/46] drm/i915: Exercise i915_vma_pin/i915_vma_insert Chris Wilson
2017-02-02  9:08 ` [PATCH 38/46] drm/i915: Verify page layout for rotated VMA Chris Wilson
2017-02-02 13:01   ` Tvrtko Ursulin
2017-02-02  9:08 ` [PATCH 39/46] drm/i915: Test creation of partial VMA Chris Wilson
2017-02-02  9:08 ` [PATCH 40/46] drm/i915: Live testing for context execution Chris Wilson
2017-02-02  9:09 ` [PATCH 41/46] drm/i915: Initial selftests for exercising eviction Chris Wilson
2017-02-02  9:09 ` [PATCH 42/46] drm/i915: Add mock exercise for i915_gem_gtt_reserve Chris Wilson
2017-02-02  9:09 ` [PATCH 43/46] drm/i915: Add mock exercise for i915_gem_gtt_insert Chris Wilson
2017-02-02  9:09 ` [PATCH 44/46] drm/i915: Add mock tests for GTT/VMA handling Chris Wilson
2017-02-08 12:12   ` Matthew Auld
2017-02-09 10:53   ` Joonas Lahtinen
2017-02-02  9:09 ` [PATCH 45/46] drm/i915: Exercise manipulate of single pages in the GGTT Chris Wilson
2017-02-08 12:25   ` Matthew Auld
2017-02-08 12:33     ` Chris Wilson
2017-02-02  9:09 ` [PATCH 46/46] drm/i915: Add initial selftests for hang detection and resets Chris Wilson
2017-02-02 13:28   ` Mika Kuoppala
2017-02-02  9:18 ` [PATCH igt] intel-ci: Add all driver selftests to BAT Chris Wilson
2017-02-02 13:30   ` Maarten Lankhorst
2017-02-02 13:44     ` Chris Wilson
2017-02-02 14:11       ` Maarten Lankhorst
2017-02-02 15:42       ` Saarinen, Jani
2017-02-17 11:50   ` Petri Latvala
2017-02-17 11:57     ` Chris Wilson
2017-02-02 11:32 ` ✗ Fi.CI.BAT: failure for series starting with [v6] drm: Provide a driver hook for drm_dev_release() (rev2) 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=67e5b886-f968-871a-e838-69a6a2ff54fc@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.