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 03/37] drm/i915: Add some selftests for sg_table manipulation
Date: Thu, 12 Jan 2017 10:56:42 +0000	[thread overview]
Message-ID: <c65c9224-cb97-9fcc-06f2-36abac6fdc4e@linux.intel.com> (raw)
In-Reply-To: <20170111210937.29252-4-chris@chris-wilson.co.uk>


On 11/01/2017 21:09, Chris Wilson wrote:
> Start exercising the scattergather lists, especially looking at
> iteration after coalescing.
>
> Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
> Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
> ---
>  drivers/gpu/drm/i915/i915_gem.c                    |  11 +-
>  .../gpu/drm/i915/selftests/i915_mock_selftests.h   |   1 +
>  drivers/gpu/drm/i915/selftests/scatterlist.c       | 255 +++++++++++++++++++++
>  3 files changed, 264 insertions(+), 3 deletions(-)
>  create mode 100644 drivers/gpu/drm/i915/selftests/scatterlist.c
>
> diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
> index 4c6d40e28cf5..e88541b5b72b 100644
> --- a/drivers/gpu/drm/i915/i915_gem.c
> +++ b/drivers/gpu/drm/i915/i915_gem.c
> @@ -2219,17 +2219,17 @@ void __i915_gem_object_put_pages(struct drm_i915_gem_object *obj,
>  	mutex_unlock(&obj->mm.lock);
>  }
>
> -static void i915_sg_trim(struct sg_table *orig_st)
> +static bool i915_sg_trim(struct sg_table *orig_st)
>  {
>  	struct sg_table new_st;
>  	struct scatterlist *sg, *new_sg;
>  	unsigned int i;
>
>  	if (orig_st->nents == orig_st->orig_nents)
> -		return;
> +		return false;
>
>  	if (sg_alloc_table(&new_st, orig_st->nents, GFP_KERNEL | __GFP_NOWARN))
> -		return;
> +		return false;
>
>  	new_sg = new_st.sgl;
>  	for_each_sg(orig_st->sgl, sg, orig_st->nents, i) {
> @@ -2242,6 +2242,7 @@ static void i915_sg_trim(struct sg_table *orig_st)
>  	sg_free_table(orig_st);
>
>  	*orig_st = new_st;
> +	return true;
>  }
>
>  static struct sg_table *
> @@ -4892,3 +4893,7 @@ i915_gem_object_get_dma_address(struct drm_i915_gem_object *obj,
>  	sg = i915_gem_object_get_sg(obj, n, &offset);
>  	return sg_dma_address(sg) + (offset << PAGE_SHIFT);
>  }
> +
> +#if IS_ENABLED(CONFIG_DRM_I915_SELFTEST)
> +#include "selftests/scatterlist.c"
> +#endif
> diff --git a/drivers/gpu/drm/i915/selftests/i915_mock_selftests.h b/drivers/gpu/drm/i915/selftests/i915_mock_selftests.h
> index 69e97a2ba4a6..5f0bdda42ed8 100644
> --- a/drivers/gpu/drm/i915/selftests/i915_mock_selftests.h
> +++ b/drivers/gpu/drm/i915/selftests/i915_mock_selftests.h
> @@ -9,3 +9,4 @@
>   * Tests are executed in order by igt/drv_selftest
>   */
>  selftest(sanitycheck, i915_mock_sanitycheck) /* keep first (igt selfcheck) */
> +selftest(scatterlist, scatterlist_mock_selftests)
> diff --git a/drivers/gpu/drm/i915/selftests/scatterlist.c b/drivers/gpu/drm/i915/selftests/scatterlist.c
> new file mode 100644
> index 000000000000..1573be8961bf
> --- /dev/null
> +++ b/drivers/gpu/drm/i915/selftests/scatterlist.c
> @@ -0,0 +1,255 @@
> +/*
> + * Copyright © 2016 Intel Corporation
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a
> + * copy of this software and associated documentation files (the "Software"),
> + * to deal in the Software without restriction, including without limitation
> + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
> + * and/or sell copies of the Software, and to permit persons to whom the
> + * Software is furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice (including the next
> + * paragraph) shall be included in all copies or substantial portions of the
> + * Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
> + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
> + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
> + * IN THE SOFTWARE.
> + */
> +
> +#include <linux/prime_numbers.h>
> +
> +#include "i915_selftest.h"
> +
> +#define PFN_BIAS (1 << 10)
> +
> +struct pfn_table {
> +	struct sg_table st;
> +	unsigned long start, end;
> +};
> +
> +static noinline int expect_pfn_sg(struct pfn_table *pt, const char *who)
> +{
> +	struct scatterlist *sg;
> +	unsigned long pfn, n;
> +
> +	pfn = pt->start;
> +	for_each_sg(pt->st.sgl, sg, pt->st.nents, n) {
> +		struct page *page = sg_page(sg);
> +
> +		if (page_to_pfn(page) != pfn) {
> +			pr_err("%s left pages out of order, expected pfn %lu, found pfn %lu (using for_each_sg)\n",
> +			       who, pfn, page_to_pfn(page));
> +			return -EINVAL;
> +		}
> +
> +		if (sg->length != (n + 1) * PAGE_SIZE) {
> +			pr_err("%s: %s copied wrong sg length, expected size %lu, found %u (using for_each_sg)\n",
> +			       __func__, who, (n + 1) * PAGE_SIZE, sg->length);
> +			return -EINVAL;
> +		}
> +
> +		cond_resched();
> +		if (signal_pending(current))
> +			return -EINTR;
> +
> +		pfn += n + 1;
> +	}
> +	if (pfn != pt->end) {
> +		pr_err("%s: %s finished on wrong pfn, expected %lu, found %lu\n",
> +		       __func__, who, pt->end, pfn);
> +		return -EINVAL;
> +	}
> +
> +	return 0;
> +}
> +
> +static noinline int expect_pfn_sg_page_iter(struct pfn_table *pt, const char *who)
> +{
> +	struct sg_page_iter sgiter;
> +	unsigned long pfn;
> +
> +	pfn = pt->start;
> +	for_each_sg_page(pt->st.sgl, &sgiter, pt->st.nents, 0) {
> +		struct page *page = sg_page_iter_page(&sgiter);
> +
> +		if (page != pfn_to_page(pfn)) {
> +			pr_err("%s: %s left pages out of order, expected pfn %lu, found pfn %lu (using for_each_sg_page)\n",
> +			       __func__, who, pfn, page_to_pfn(page));
> +			return -EINVAL;
> +		}
> +
> +		cond_resched();
> +		if (signal_pending(current))
> +			return -EINTR;
> +
> +		pfn++;
> +	}
> +	if (pfn != pt->end) {
> +		pr_err("%s: %s finished on wrong pfn, expected %lu, found %lu\n",
> +		       __func__, who, pt->end, pfn);
> +		return -EINVAL;
> +	}
> +
> +	return 0;
> +}
> +
> +static noinline int expect_pfn_sgtiter(struct pfn_table *pt, const char *who)
> +{
> +	struct sgt_iter sgt;
> +	struct page *page;
> +	unsigned long pfn;
> +
> +	pfn = pt->start;
> +	for_each_sgt_page(page, sgt, &pt->st) {
> +		if (page != pfn_to_page(pfn)) {
> +			pr_err("%s: %s left pages out of order, expected pfn %lu, found pfn %lu (using for_each_sgt_page)\n",
> +			       __func__, who, pfn, page_to_pfn(page));
> +			return -EINVAL;
> +		}
> +
> +		cond_resched();
> +		if (signal_pending(current))
> +			return -EINTR;
> +
> +		pfn++;
> +	}
> +	if (pfn != pt->end) {
> +		pr_err("%s: %s finished on wrong pfn, expected %lu, found %lu\n",
> +		       __func__, who, pt->end, pfn);
> +		return -EINVAL;
> +	}
> +
> +	return 0;
> +}
> +
> +static int expect_pfn_sgtable(struct pfn_table *pt, const char *who)
> +{
> +	int err;
> +
> +	err = expect_pfn_sg(pt, who);
> +	if (err)
> +		return err;
> +
> +	err = expect_pfn_sg_page_iter(pt, who);
> +	if (err)
> +		return err;
> +
> +	err = expect_pfn_sgtiter(pt, who);
> +	if (err)
> +		return err;
> +
> +	return 0;
> +}
> +
> +static bool alloc_table(struct pfn_table *pt,
> +			unsigned long count,
> +			unsigned long max)
> +{
> +	struct scatterlist *sg;
> +	unsigned long n, pfn;
> +
> +	if (sg_alloc_table(&pt->st, max,
> +			   GFP_KERNEL | __GFP_NORETRY | __GFP_NOWARN))
> +		return false;
> +
> +	pt->start = PFN_BIAS;
> +	pfn = pt->start;
> +	sg = pt->st.sgl;
> +	for (n = 0; n < count; n++) {
> +		if (n)
> +			sg = sg_next(sg);
> +		sg_set_page(sg, pfn_to_page(pfn), (n + 1)*PAGE_SIZE, 0);

For count = BIT(max_order) (== 1M) the last sg entry will have a size of 
4GiB which would overflow sg->length, no? Especially with size + offset 
below. Unless for_each_prime_number stops below max_order. But where?

> +		pfn += n + 1;

Please describe what kind of table and why you are building with a 
comment. If tests have no comments and do, on the first look, not fully 
obvious things, then it is a lot of effort in the future to work on 
fixes and/or maintain the code.

> +	}
> +	sg_mark_end(sg);
> +	pt->st.nents = n;
> +	pt->end = pfn;
> +
> +	return true;
> +}
> +
> +static int igt_sg_alloc(void *ignored)
> +{
> +	I915_SELFTEST_TIMEOUT(end_time);
> +	const unsigned long max_order = 20; /* approximating a 4GiB object */
> +	unsigned long prime;
> +
> +	for_each_prime_number(prime, max_order) {
> +		unsigned long size = BIT(prime);
> +		int offset;
> +
> +		for (offset = -1; offset <= 1; offset++) {
> +			struct pfn_table pt;
> +			int err;
> +
> +			if (!alloc_table(&pt, size + offset, size + offset))
> +				return 0; /* out of memory, give up */
> +
> +			err = expect_pfn_sgtable(&pt, "sg_alloc_table");
> +			sg_free_table(&pt.st);
> +			if (err)
> +				return err;
> +
> +			if (time_after(jiffies, end_time)) {
> +				pr_warn("%s timed out: last table size %lu\n",
> +					__func__, size + offset);
> +				return 0;
> +			}

Maybe a fmt+vaarg timeout helper since I expect there'll be a lot of 
this. Like:

if (i915_selftest_timeout(end_time, "fmt %s", arg))
	return 0;

It is slightly tidier.

> +		}
> +	}
> +
> +	return 0;
> +}
> +
> +static int igt_sg_trim(void *ignored)
> +{
> +	I915_SELFTEST_TIMEOUT(end_time);
> +	const unsigned long max = PAGE_SIZE; /* not prime! */
> +	struct pfn_table pt;
> +	unsigned long prime;
> +
> +	for_each_prime_number(prime, max) {
> +		int err;
> +
> +		if (!alloc_table(&pt, prime, max))
> +			return 0; /* out of memory, give up */
> +
> +		err = 0;
> +		if (i915_sg_trim(&pt.st)) {
> +			if (pt.st.orig_nents != prime ||
> +			    pt.st.nents != prime) {
> +				pr_err("i915_sg_trim failed (nents %u, orig_nents %u), expected %lu\n",
> +				       pt.st.nents, pt.st.orig_nents, prime);
> +				err = -EINVAL;
> +			} else {
> +				err = expect_pfn_sgtable(&pt, "i915_sg_trim");
> +			}
> +		}
> +		sg_free_table(&pt.st);
> +		if (err)
> +			return err;
> +
> +		if (time_after(jiffies, end_time)) {
> +			pr_warn("%s timed out: last trim size %lu/%lu\n",
> +				__func__, prime, max);
> +			return 0;
> +		}
> +	}
> +
> +	return 0;
> +}
> +
> +int scatterlist_mock_selftests(void)
> +{
> +	static const struct i915_subtest tests[] = {
> +		SUBTEST(igt_sg_alloc),
> +		SUBTEST(igt_sg_trim),
> +	};
> +
> +	return i915_subtests(tests, NULL);
> +}
>

Regards,

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

  reply	other threads:[~2017-01-12 10:56 UTC|newest]

Thread overview: 81+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-11 21:09 Selftests Chris Wilson
2017-01-11 21:09 ` [PATCH 01/37] drm: Provide a driver hook for drm_dev_release() Chris Wilson
2017-01-11 21:09 ` [PATCH 02/37] drm/i915: Provide a hook for selftests Chris Wilson
2017-01-12  7:29   ` Tvrtko Ursulin
2017-01-12  7:40     ` Chris Wilson
2017-01-13  8:31   ` Chris Wilson
2017-01-13 10:12     ` Tvrtko Ursulin
2017-01-13 10:22       ` Chris Wilson
2017-01-13 10:42         ` Tvrtko Ursulin
2017-01-11 21:09 ` [PATCH 03/37] drm/i915: Add some selftests for sg_table manipulation Chris Wilson
2017-01-12 10:56   ` Tvrtko Ursulin [this message]
2017-01-12 11:14     ` Chris Wilson
2017-01-11 21:09 ` [PATCH 04/37] drm/i915: Add unit tests for the breadcrumb rbtree, insert/remove Chris Wilson
2017-01-11 21:09 ` [PATCH 05/37] drm/i915: Add unit tests for the breadcrumb rbtree, completion Chris Wilson
2017-01-11 21:09 ` [PATCH 06/37] drm/i915: Add unit tests for the breadcrumb rbtree, wakeups Chris Wilson
2017-01-12 11:11   ` Tvrtko Ursulin
2017-01-12 14:37     ` Chris Wilson
2017-01-11 21:09 ` [PATCH 07/37] drm/i915: Mock the GEM device for self-testing Chris Wilson
2017-01-11 21:09 ` [PATCH 08/37] drm/i915: Mock a GGTT " Chris Wilson
2017-01-11 21:09 ` [PATCH 09/37] drm/i915: Mock infrastructure for request emission Chris Wilson
2017-01-12 13:11   ` Tvrtko Ursulin
2017-01-12 13:27     ` Chris Wilson
2017-01-11 21:09 ` [PATCH 10/37] drm/i915: Create a fake object for testing huge allocations Chris Wilson
2017-01-12 10:56   ` Matthew Auld
2017-01-11 21:09 ` [PATCH 11/37] drm/i915: Add selftests for i915_gem_request Chris Wilson
2017-01-12 11:20   ` Tvrtko Ursulin
2017-01-12 11:32     ` Chris Wilson
2017-01-11 21:09 ` [PATCH 12/37] drm/i915: Add a simple request selftest for waiting Chris Wilson
2017-01-12 11:25   ` Tvrtko Ursulin
2017-01-11 21:09 ` [PATCH 13/37] drm/i915: Add a simple fence selftest to i915_gem_request Chris Wilson
2017-01-11 21:09 ` [PATCH 14/37] drm/i915: Simple selftest to exercise live requests Chris Wilson
2017-01-12 12:10   ` Tvrtko Ursulin
2017-01-12 12:20     ` Chris Wilson
2017-01-11 21:09 ` [PATCH 15/37] drm/i915: Add selftests for object allocation, phys Chris Wilson
2017-01-11 21:09 ` [PATCH 16/37] drm/i915: Add a live seftest for GEM objects Chris Wilson
2017-01-12 11:17   ` Matthew Auld
2017-01-11 21:09 ` [PATCH 17/37] drm/i915: Test partial mappings Chris Wilson
2017-01-16 22:05   ` Matthew Auld
2017-01-16 22:25     ` Chris Wilson
2017-01-17 12:12   ` Matthew Auld
2017-01-17 12:29     ` Chris Wilson
2017-01-11 21:09 ` [PATCH 18/37] drm/i915: Test exhaustion of the mmap space Chris Wilson
2017-01-12 17:29   ` Matthew Auld
2017-01-11 21:09 ` [PATCH 19/37] drm/i915: Test coherency of and barriers between cache domains Chris Wilson
2017-01-13 11:44   ` Matthew Auld
2017-01-13 14:13     ` Chris Wilson
2017-01-11 21:09 ` [PATCH 20/37] drm/i915: Move uncore selfchecks to live selftest infrastructure Chris Wilson
2017-01-11 21:09 ` [PATCH 21/37] drm/i915: Test all fw tables during mock selftests Chris Wilson
2017-01-11 21:09 ` [PATCH 22/37] drm/i915: Sanity check all registers for matching fw domains Chris Wilson
2017-01-11 21:09 ` [PATCH 23/37] drm/i915: Add some mock tests for dmabuf interop Chris Wilson
2017-01-11 21:09 ` [PATCH 24/37] drm/i915: Add initial selftests for i915_gem_gtt Chris Wilson
2017-01-11 21:09 ` [PATCH 25/37] drm/i915: Move i915_ppgtt_close() into i915_gem_gtt.c Chris Wilson
2017-01-12 12:43   ` Joonas Lahtinen
2017-01-11 21:09 ` [PATCH 26/37] drm/i915: Assert that we have allocated the drm_mm_node upon pinning Chris Wilson
2017-01-12 12:45   ` Joonas Lahtinen
2017-01-11 21:09 ` [PATCH 27/37] drm/i915: Exercising filling the top/bottom portions of the ppgtt Chris Wilson
2017-01-12 13:32   ` Joonas Lahtinen
2017-01-11 21:09 ` [PATCH 28/37] drm/i915: Exercising filling the top/bottom portions of the global GTT Chris Wilson
2017-01-12 14:05   ` Joonas Lahtinen
2017-01-11 21:09 ` [PATCH 29/37] drm/i915: Fill different pages of the GTT Chris Wilson
2017-01-13  7:47   ` Joonas Lahtinen
2017-01-13 20:45     ` Chris Wilson
2017-01-11 21:09 ` [PATCH 30/37] drm/i915: Exercise filling and removing random ranges from the live GTT Chris Wilson
2017-01-13  8:59   ` Joonas Lahtinen
2017-01-13  9:08     ` Chris Wilson
2017-01-11 21:09 ` [PATCH 31/37] drm/i915: Test creation of VMA Chris Wilson
2017-01-13 12:28   ` Joonas Lahtinen
2017-01-13 12:50     ` Chris Wilson
2017-01-11 21:09 ` [PATCH 32/37] drm/i915: Exercise i915_vma_pin/i915_vma_insert Chris Wilson
2017-01-13 12:49   ` Joonas Lahtinen
2017-01-13 12:57     ` Chris Wilson
2017-01-11 21:09 ` [PATCH 33/37] drm/i915: Verify page layout for rotated VMA Chris Wilson
2017-01-12 17:41   ` Tvrtko Ursulin
2017-01-11 21:09 ` [PATCH 34/37] drm/i915: Test creation of partial VMA Chris Wilson
2017-01-13 13:10   ` Joonas Lahtinen
2017-01-11 21:09 ` [PATCH 35/37] drm/i915: Live testing for context execution Chris Wilson
2017-01-13 14:28   ` Joonas Lahtinen
2017-01-13 18:35     ` Chris Wilson
2017-01-11 21:09 ` [PATCH 36/37] drm/i915: Initial selftests for exercising eviction Chris Wilson
2017-01-11 21:09 ` [PATCH 37/37] drm/i915: Add initial selftests for hang detection and resets Chris Wilson
2017-01-11 22:23 ` ✓ Fi.CI.BAT: success for series starting with [01/37] drm: Provide a driver hook for drm_dev_release() 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=c65c9224-cb97-9fcc-06f2-36abac6fdc4e@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.