intel-gfx.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
From: Chris Wilson <chris@chris-wilson.co.uk>
To: dri-devel@lists.freedesktop.org
Cc: intel-gfx@lists.freedesktop.org, joonas.lahtinen@linux.intel.com
Subject: [PATCH 08/34] drm: kselftest for drm_mm_reserve_node()
Date: Mon, 12 Dec 2016 11:53:24 +0000	[thread overview]
Message-ID: <20161212115350.780-9-chris@chris-wilson.co.uk> (raw)
In-Reply-To: <20161212115350.780-1-chris@chris-wilson.co.uk>

Exercise drm_mm_reserve_node(), check that we can't reserve an already
occupied range and that the lists are correct after reserving/removing.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
---
 drivers/gpu/drm/selftests/drm_mm_selftests.h |   1 +
 drivers/gpu/drm/selftests/test-drm_mm.c      | 132 +++++++++++++++++++++++++++
 2 files changed, 133 insertions(+)

diff --git a/drivers/gpu/drm/selftests/drm_mm_selftests.h b/drivers/gpu/drm/selftests/drm_mm_selftests.h
index fddf2c01c97f..639913a69101 100644
--- a/drivers/gpu/drm/selftests/drm_mm_selftests.h
+++ b/drivers/gpu/drm/selftests/drm_mm_selftests.h
@@ -5,6 +5,7 @@
  *
  * Tests are executed in reverse order by igt/drm_mm
  */
+selftest(reserve, igt_reserve)
 selftest(debug, igt_debug)
 selftest(init, igt_init)
 selftest(sanitycheck, igt_sanitycheck) /* keep last */
diff --git a/drivers/gpu/drm/selftests/test-drm_mm.c b/drivers/gpu/drm/selftests/test-drm_mm.c
index 1fe104cc05d5..13b2cfdb4d44 100644
--- a/drivers/gpu/drm/selftests/test-drm_mm.c
+++ b/drivers/gpu/drm/selftests/test-drm_mm.c
@@ -11,6 +11,9 @@
 
 #include <drm/drm_mm.h>
 
+#include "../lib/drm_rand.h"
+#include "../lib/drm_prime_numbers.h"
+
 #define TESTS "drm_mm_selftests.h"
 #include "drm_selftest.h"
 
@@ -105,6 +108,135 @@ static int igt_debug(void *ignored)
 	return 0;
 }
 
+static int __igt_reserve(int count, u64 size)
+{
+	u32 lcg_state = random_seed;
+	struct drm_mm mm;
+	struct drm_mm_node *node, *next;
+	int *order, n;
+	int ret;
+
+	/* Fill a range with lots of nodes, check it doesn't fail too early */
+
+	ret = -ENOMEM;
+	order = drm_random_order(count, &lcg_state);
+	if (!order)
+		goto err;
+
+	ret = -EINVAL;
+	drm_mm_init(&mm, 0, count * size);
+	if (!drm_mm_clean(&mm)) {
+		pr_err("mm not empty on creation\n");
+		goto out;
+	}
+
+	for (n = 0; n < count; n++) {
+		int err;
+
+		node = kzalloc(sizeof(*node), GFP_KERNEL);
+		if (!node) {
+			ret = -ENOMEM;
+			goto out;
+		}
+
+		node->start = order[n] * size;
+		node->size = size;
+
+		err = drm_mm_reserve_node(&mm, node);
+		if (err) {
+			pr_err("reserve failed, step %d, start %llu\n",
+			       n, node->start);
+			ret = err;
+			goto out;
+		}
+
+		if (!drm_mm_node_allocated(node)) {
+			pr_err("reserved node not allocated! step %d, start %llu\n",
+			       n, node->start);
+			goto out;
+		}
+	}
+
+	/* Repeated use should then fail */
+	drm_random_reorder(order, count, &lcg_state);
+	for (n = 0; n < count; n++) {
+		struct drm_mm_node tmp = {
+			.start = order[n] * size,
+			.size = 1
+		};
+
+		if (!drm_mm_reserve_node(&mm, &tmp)) {
+			drm_mm_remove_node(&tmp);
+			pr_err("impossible reserve succeeded, step %d, start %llu\n",
+			       n, tmp.start);
+			goto out;
+		}
+	}
+
+	/* Overlapping use should then fail */
+	for (n = 0; n < count; n++) {
+		struct drm_mm_node tmp = {
+			.start = 0,
+			.size = size * count,
+		};
+
+		if (!drm_mm_reserve_node(&mm, &tmp)) {
+			drm_mm_remove_node(&tmp);
+			pr_err("impossible reserve succeeded, step %d, start %llu\n",
+			       n, tmp.start);
+			goto out;
+		}
+	}
+	for (n = 0; n < count; n++) {
+		struct drm_mm_node tmp = {
+			.start = size * n,
+			.size = size * (count - n),
+		};
+
+		if (!drm_mm_reserve_node(&mm, &tmp)) {
+			drm_mm_remove_node(&tmp);
+			pr_err("impossible reserve succeeded, step %d, start %llu\n",
+			       n, tmp.start);
+			goto out;
+		}
+	}
+
+	ret = 0;
+out:
+	drm_mm_for_each_node_safe(node, next, &mm) {
+		drm_mm_remove_node(node);
+		kfree(node);
+	}
+	drm_mm_takedown(&mm);
+	kfree(order);
+err:
+	return ret;
+}
+
+static int igt_reserve(void *ignored)
+{
+	const unsigned int count = BIT(10);
+	int n, ret;
+
+	drm_for_each_prime(n, 54) {
+		u64 size = BIT_ULL(n);
+
+		ret = __igt_reserve(count, size - 1);
+		if (ret)
+			return ret;
+
+		ret = __igt_reserve(count, size);
+		if (ret)
+			return ret;
+
+		ret = __igt_reserve(count, size + 1);
+		if (ret)
+			return ret;
+	}
+
+	return 0;
+}
+
 #include "drm_selftest.c"
 
 static int __init test_drm_mm_init(void)
-- 
2.11.0

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

  parent reply	other threads:[~2016-12-12 11:53 UTC|newest]

Thread overview: 81+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-12 11:53 struct drm_mm fixes Chris Wilson
2016-12-12 11:53 ` [PATCH 01/34] drm/i915: Use the MRU stack search after evicting Chris Wilson
2016-12-13  9:29   ` Joonas Lahtinen
2016-12-12 11:53 ` [PATCH 02/34] drm/i915: Simplify i915_gtt_color_adjust() Chris Wilson
2016-12-13  9:32   ` Joonas Lahtinen
2016-12-12 11:53 ` [PATCH 03/34] drm: Add drm_mm_for_each_node_safe() Chris Wilson
2016-12-13  9:35   ` Joonas Lahtinen
2016-12-14 11:39     ` Chris Wilson
2016-12-14 12:03       ` Joonas Lahtinen
2016-12-12 11:53 ` [PATCH 04/34] drm: Add some kselftests for the DRM range manager (struct drm_mm) Chris Wilson
2016-12-13  9:58   ` Joonas Lahtinen
2016-12-13 10:21     ` Chris Wilson
2016-12-13 15:03       ` Joonas Lahtinen
2016-12-12 11:53 ` [PATCH 05/34] drm: kselftest for drm_mm_init() Chris Wilson
2016-12-13 10:16   ` Joonas Lahtinen
2016-12-12 11:53 ` [PATCH 06/34] drm: Add a simple linear congruent generator PRNG Chris Wilson
2016-12-13 10:44   ` Joonas Lahtinen
2016-12-13 15:16   ` David Herrmann
2016-12-13 15:18     ` David Herrmann
2016-12-13 15:40       ` Chris Wilson
2016-12-13 16:21         ` David Herrmann
2016-12-13 15:26     ` Chris Wilson
2016-12-13 19:39     ` Laurent Pinchart
2016-12-13 20:50       ` Chris Wilson
2016-12-12 11:53 ` [PATCH 07/34] drm: Add a simple prime number generator Chris Wilson
2016-12-12 11:53 ` Chris Wilson [this message]
2016-12-14  9:55   ` [PATCH 08/34] drm: kselftest for drm_mm_reserve_node() Joonas Lahtinen
2016-12-12 11:53 ` [PATCH 09/34] drm: kselftest for drm_mm_insert_node() Chris Wilson
2016-12-14 12:26   ` Joonas Lahtinen
2016-12-14 12:51     ` Chris Wilson
2016-12-12 11:53 ` [PATCH 10/34] drm: kselftest for drm_mm_replace_node() Chris Wilson
2016-12-14 12:01   ` Joonas Lahtinen
2016-12-12 11:53 ` [PATCH 11/34] drm: kselftest for drm_mm_insert_node_in_range() Chris Wilson
2016-12-15  8:43   ` Joonas Lahtinen
2016-12-12 11:53 ` [PATCH 12/34] drm: kselftest for drm_mm and alignment Chris Wilson
2016-12-15  8:59   ` Joonas Lahtinen
2016-12-15  9:21     ` Chris Wilson
2016-12-12 11:53 ` [PATCH 13/34] drm: kselftest for drm_mm and eviction Chris Wilson
2016-12-15  9:29   ` Joonas Lahtinen
2016-12-12 11:53 ` [PATCH 14/34] drm: kselftest for drm_mm and range restricted eviction Chris Wilson
2016-12-15  9:50   ` Joonas Lahtinen
2016-12-12 11:53 ` [PATCH 15/34] drm: kselftest for drm_mm and top-down allocation Chris Wilson
2016-12-14 11:33   ` Joonas Lahtinen
2016-12-12 11:53 ` [PATCH 16/34] drm: kselftest for drm_mm and top-down alignment Chris Wilson
2016-12-14 11:51   ` Joonas Lahtinen
2016-12-12 11:53 ` [PATCH 17/34] drm: kselftest for drm_mm and color adjustment Chris Wilson
2016-12-15 11:04   ` Joonas Lahtinen
2016-12-12 11:53 ` [PATCH 18/34] drm: kselftest for drm_mm and color eviction Chris Wilson
2016-12-12 11:53 ` [PATCH 19/34] drm: kselftest for drm_mm and restricted " Chris Wilson
2016-12-12 11:53 ` [PATCH 20/34] drm/i915: Build DRM range manager selftests for CI Chris Wilson
2016-12-15 12:31   ` Joonas Lahtinen
2016-12-12 11:53 ` [PATCH 21/34] drm: Promote drm_mm alignment to u64 Chris Wilson
2016-12-12 12:39   ` Christian König
2016-12-12 11:53 ` [PATCH 22/34] drm: Constify the drm_mm API Chris Wilson
2016-12-12 11:53 ` [PATCH 23/34] drm: Simplify drm_mm_clean() Chris Wilson
2016-12-13 12:30   ` Joonas Lahtinen
2016-12-12 11:53 ` [PATCH 24/34] drm: Compile time enabling for asserts in drm_mm Chris Wilson
2016-12-13 15:04   ` Joonas Lahtinen
2016-12-12 11:53 ` [PATCH 25/34] drm: Extract struct drm_mm_scan from struct drm_mm Chris Wilson
2016-12-13 15:17   ` Joonas Lahtinen
2016-12-12 11:53 ` [PATCH 26/34] drm: Rename prev_node to hole in drm_mm_scan_add_block() Chris Wilson
2016-12-13 15:23   ` Joonas Lahtinen
2016-12-13 22:28     ` Chris Wilson
2016-12-12 11:53 ` [PATCH 27/34] drm: Unconditionally do the range check " Chris Wilson
2016-12-13 15:28   ` Joonas Lahtinen
2016-12-12 11:53 ` [PATCH 28/34] drm: Fix application of color vs range restriction when scanning drm_mm Chris Wilson
2016-12-12 14:57   ` Joonas Lahtinen
2016-12-12 11:53 ` [PATCH 29/34] drm: Compute tight evictions for drm_mm_scan Chris Wilson
2016-12-13 15:48   ` Joonas Lahtinen
2016-12-12 11:53 ` [PATCH 30/34] drm: Optimise power-of-two alignments in drm_mm_scan_add_block() Chris Wilson
2016-12-13 15:55   ` Joonas Lahtinen
2016-12-12 11:53 ` [PATCH 31/34] drm: Simplify drm_mm scan-list manipulation Chris Wilson
2016-12-14  8:27   ` Joonas Lahtinen
2016-12-12 11:53 ` [PATCH 32/34] drm: Apply tight eviction scanning to color_adjust Chris Wilson
2016-12-13 16:03   ` Joonas Lahtinen
2016-12-12 11:53 ` [PATCH 33/34] drm: Fix drm_mm search and insertion Chris Wilson
2016-12-15 12:28   ` Joonas Lahtinen
2016-12-15 12:57     ` Chris Wilson
2016-12-12 11:53 ` [PATCH 34/34] drm: kselftest for drm_mm and bottom-up allocation Chris Wilson
2016-12-14  9:10   ` Joonas Lahtinen
2016-12-12 12:15 ` ✓ Fi.CI.BAT: success for series starting with [01/34] drm/i915: Use the MRU stack search after evicting 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=20161212115350.780-9-chris@chris-wilson.co.uk \
    --to=chris@chris-wilson.co.uk \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=joonas.lahtinen@linux.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).