diff mbox

[16/34] drm: kselftest for drm_mm and top-down alignment

Message ID 20161212115350.780-17-chris@chris-wilson.co.uk (mailing list archive)
State New, archived
Headers show

Commit Message

Chris Wilson Dec. 12, 2016, 11:53 a.m. UTC
Check that if we request top-down allocation with a particular alignment
from drm_mm_insert_node() that the start of the node matches our
request.

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      | 92 ++++++++++++++++++++++++++++
 2 files changed, 93 insertions(+)

Comments

Joonas Lahtinen Dec. 14, 2016, 11:51 a.m. UTC | #1
On ma, 2016-12-12 at 11:53 +0000, Chris Wilson wrote:
> Check that if we request top-down allocation with a particular alignment
> from drm_mm_insert_node() that the start of the node matches our
> request.
> 
> Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>

Assuming magic numbers be gone in next iteration.

> +static int igt_topdown_align(void *ignored)
> +{
> +	struct drm_mm mm;
> +	struct drm_mm_node tmp, resv;
> +	int ret = -EINVAL;
> +	int n, m, err;
> +
> +	drm_mm_init(&mm, 0, ~0ull);
> +	memset(&tmp, 0, sizeof(tmp));
> +	memset(&resv, 0, sizeof(resv));
> +
> +	for (m = 0; m < 32; m++) {
> +		u64 end = ~0ull;
> +
> +		if (m) {
> +			resv.size = BIT_ULL(m);
> +			end -= resv.size;
> +			resv.start = end;
> +
> +			err = drm_mm_reserve_node(&mm, &resv);
> +			if (err) {
> +				pr_err("reservation of sentinel node failed\n");
> +				ret = err;
> +				goto out;
> +			}
> +		}
> +
> +		for (n = 0; n < 63 - m; n++) {
> +			u64 align = BIT_ULL(n);

DRM_MM_BUG_ON(end % align); to protect somebody from modifying? (or end
& (align - 1))

> +
> +			err = drm_mm_insert_node_generic(&mm, &tmp, 1, align, 0,
> +							 DRM_MM_SEARCH_BELOW,
> +							 DRM_MM_CREATE_TOP);
> +			drm_mm_remove_node(&tmp);

Could move this after if (err) again and in the rest of the code, too.

Reviewed-by: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>

Regards, Joonas
diff mbox

Patch

diff --git a/drivers/gpu/drm/selftests/drm_mm_selftests.h b/drivers/gpu/drm/selftests/drm_mm_selftests.h
index 357fe430e36e..a7cceeb21356 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(topdown_align, igt_topdown_align)
 selftest(topdown, igt_topdown)
 selftest(evict_range, igt_evict_range)
 selftest(evict, igt_evict)
diff --git a/drivers/gpu/drm/selftests/test-drm_mm.c b/drivers/gpu/drm/selftests/test-drm_mm.c
index 22e7904cdaea..078511c76efb 100644
--- a/drivers/gpu/drm/selftests/test-drm_mm.c
+++ b/drivers/gpu/drm/selftests/test-drm_mm.c
@@ -1311,6 +1311,98 @@  static int igt_topdown(void *ignored)
 	return ret;
 }
 
+static int igt_topdown_align(void *ignored)
+{
+	struct drm_mm mm;
+	struct drm_mm_node tmp, resv;
+	int ret = -EINVAL;
+	int n, m, err;
+
+	drm_mm_init(&mm, 0, ~0ull);
+	memset(&tmp, 0, sizeof(tmp));
+	memset(&resv, 0, sizeof(resv));
+
+	for (m = 0; m < 32; m++) {
+		u64 end = ~0ull;
+
+		if (m) {
+			resv.size = BIT_ULL(m);
+			end -= resv.size;
+			resv.start = end;
+
+			err = drm_mm_reserve_node(&mm, &resv);
+			if (err) {
+				pr_err("reservation of sentinel node failed\n");
+				ret = err;
+				goto out;
+			}
+		}
+
+		for (n = 0; n < 63 - m; n++) {
+			u64 align = BIT_ULL(n);
+
+			err = drm_mm_insert_node_generic(&mm, &tmp, 1, align, 0,
+							 DRM_MM_SEARCH_BELOW,
+							 DRM_MM_CREATE_TOP);
+			drm_mm_remove_node(&tmp);
+			if (err) {
+				pr_err("insert failed, ret=%d\n", err);
+				ret = err;
+				goto out;
+			}
+
+			if (tmp.start & (align - 1)) {
+				pr_err("insert alignment failed, aligment=%llx, start=%llx\n",
+				       align, tmp.start);
+				goto out;
+			}
+
+			if (tmp.start < end - align) {
+				pr_err("topdown insert failed, start=%llx, align=%llx, end=%llx\n",
+				       tmp.start, align, end);
+				goto out;
+			}
+		}
+
+		drm_for_each_prime(n, min(8192ull, end - 1)) {
+			u64 rem;
+
+			err = drm_mm_insert_node_generic(&mm, &tmp, 1, n, 0,
+							 DRM_MM_SEARCH_BELOW,
+							 DRM_MM_CREATE_TOP);
+			drm_mm_remove_node(&tmp);
+			if (err) {
+				pr_err("insert failed, ret=%d\n", err);
+				ret = err;
+				goto out;
+			}
+
+			div64_u64_rem(tmp.start, n, &rem);
+			if (rem) {
+				pr_err("insert alignment failed, aligment=%d, start=%llx (offset %d)\n",
+				       n, tmp.start, (int)rem);
+				goto out;
+			}
+
+			if (tmp.start < end - n) {
+				pr_err("topdown insert failed, start=%llx, align=%d, end=%llx\n",
+				       tmp.start, n, end);
+				goto out;
+			}
+		}
+
+		if (resv.allocated)
+			drm_mm_remove_node(&resv);
+	}
+
+	ret = 0;
+out:
+	if (resv.allocated)
+		drm_mm_remove_node(&resv);
+	drm_mm_takedown(&mm);
+	return ret;
+}
+
 #include "drm_selftest.c"
 
 static int __init test_drm_mm_init(void)