[Intel-gfx] [PATCH 5/9] drm: kselftest for drm_mm and alignment
Chris Wilson
chris at chris-wilson.co.uk
Fri Dec 9 13:08:21 UTC 2016
Check that we can request alignment to any power-of-two or prime using a
plain drm_mm_node_insert().
Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
---
drivers/gpu/drm/drm_mm_selftests.h | 3 +
drivers/gpu/drm/test-drm_mm.c | 113 +++++++++++++++++++++++++++++++++++++
2 files changed, 116 insertions(+)
diff --git a/drivers/gpu/drm/drm_mm_selftests.h b/drivers/gpu/drm/drm_mm_selftests.h
index 4070123daffc..591d34aa233a 100644
--- a/drivers/gpu/drm/drm_mm_selftests.h
+++ b/drivers/gpu/drm/drm_mm_selftests.h
@@ -5,6 +5,9 @@
*
* Tests are executed in reverse order by igt/drm_mm
*/
+selftest(align64, igt_align64)
+selftest(align32, igt_align32)
+selftest(align, igt_align)
selftest(insert_range, igt_insert_range)
selftest(insert, igt_insert)
selftest(reserve, igt_reserve)
diff --git a/drivers/gpu/drm/test-drm_mm.c b/drivers/gpu/drm/test-drm_mm.c
index 494a470e08f3..8cdcde580da3 100644
--- a/drivers/gpu/drm/test-drm_mm.c
+++ b/drivers/gpu/drm/test-drm_mm.c
@@ -662,6 +662,119 @@ static int igt_insert_range(void *ignored)
return 0;
}
+static int igt_align(void *ignored)
+{
+ struct drm_mm mm;
+ struct drm_mm_node *node, *next;
+ int ret = -EINVAL;
+ int n;
+
+ drm_mm_init(&mm, 1, -2);
+ if (!drm_mm_clean(&mm)) {
+ pr_err("mm not empty on creation\n");
+ goto out;
+ }
+
+ for_each_prime(n, 8192) {
+ int err;
+
+ node = kzalloc(sizeof(*node), GFP_KERNEL);
+ if (!node) {
+ ret = -ENOMEM;
+ goto out;
+ }
+
+ err = drm_mm_insert_node_generic(&mm, node,
+ next_prime_number(n),/* size */
+ n, /* alignment */
+ 0,
+ DRM_MM_SEARCH_DEFAULT,
+ DRM_MM_CREATE_DEFAULT);
+ if (err) {
+ pr_err("insert failed with alignment=%d", n);
+ ret = err;
+ goto out;
+ }
+
+ if (node->start % n) {
+ pr_err("node inserted into wrong location %llx, expected alignment to %d\n",
+ node->start, n);
+ goto out;
+ }
+ }
+
+ ret = 0;
+out:
+ list_for_each_entry_safe(node, next,
+ &mm.head_node.node_list, node_list) {
+ drm_mm_remove_node(node);
+ kfree(node);
+ }
+ drm_mm_takedown(&mm);
+ return ret;
+}
+
+static int igt_align_pot(int max)
+{
+ struct drm_mm mm;
+ struct drm_mm_node *node, *next;
+ int bit;
+ int ret = -EINVAL;
+
+ drm_mm_init(&mm, 1, -2);
+ if (!drm_mm_clean(&mm)) {
+ pr_err("mm not empty on creation\n");
+ goto out;
+ }
+
+ for (bit = max - 1; bit; bit--) {
+ int err;
+
+ node = kzalloc(sizeof(*node), GFP_KERNEL);
+ if (!node) {
+ ret = -ENOMEM;
+ goto out;
+ }
+
+ err = drm_mm_insert_node_generic(&mm, node, 1,
+ BIT_ULL(bit), bit,
+ DRM_MM_SEARCH_DEFAULT,
+ DRM_MM_CREATE_DEFAULT);
+ if (err) {
+ pr_err("insert failed with alignment=%llx [%d]",
+ BIT_ULL(bit), bit);
+ ret = err;
+ goto out;
+ }
+
+ if (node->start & (BIT_ULL(bit) - 1)) {
+ pr_err("node inserted into wrong location %llx, expected alignment to %llx [%d]\n",
+ node->start, BIT_ULL(bit), bit);
+ goto out;
+ }
+ }
+
+ ret = 0;
+out:
+ list_for_each_entry_safe(node, next,
+ &mm.head_node.node_list, node_list) {
+ drm_mm_remove_node(node);
+ kfree(node);
+ }
+ drm_mm_takedown(&mm);
+ return ret;
+}
+
+static int igt_align32(void *ignored)
+{
+ return igt_align_pot(32);
+}
+
+static int igt_align64(void *ignored)
+{
+ return igt_align_pot(64);
+}
+
#include "drm_selftest.c"
static int __init test_drm_mm_init(void)
--
2.11.0
More information about the Intel-gfx
mailing list