[Intel-gfx] [PATCH 19/34] drm: kselftest for drm_mm and restricted color eviction

Chris Wilson chris at chris-wilson.co.uk
Mon Dec 12 11:53:35 UTC 2016


Check that after applying the driver's color adjustment, restricted
eviction scanning find a suitable hole.

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

diff --git a/drivers/gpu/drm/selftests/drm_mm_selftests.h b/drivers/gpu/drm/selftests/drm_mm_selftests.h
index cdb7c72ecadf..fb9d704e7943 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(color_evict_range, igt_color_evict_range)
 selftest(color_evict, igt_color_evict)
 selftest(color, igt_color)
 selftest(topdown_align, igt_topdown_align)
diff --git a/drivers/gpu/drm/selftests/test-drm_mm.c b/drivers/gpu/drm/selftests/test-drm_mm.c
index 663db5408b3a..02f10d9d1396 100644
--- a/drivers/gpu/drm/selftests/test-drm_mm.c
+++ b/drivers/gpu/drm/selftests/test-drm_mm.c
@@ -1784,6 +1784,211 @@ static int igt_color_evict(void *ignored)
 	return ret;
 }
 
+static int igt_color_evict_range(void *ignored)
+{
+	u32 lcg_state = random_seed;
+	const int total_size = 8192;
+	const int range_size = total_size / 2;
+	const int range_start = total_size / 4;
+	const int range_end = range_start + range_size;
+	unsigned long color = 0;
+	struct drm_mm mm;
+	struct evict_node {
+		struct drm_mm_node node;
+		struct list_head link;
+	} *nodes;
+	struct drm_mm_node *node, *next;
+	int *order, n, m;
+	int ret;
+
+	ret = -ENOMEM;
+	nodes = vzalloc(total_size * sizeof(*nodes));
+	if (!nodes)
+		goto err;
+
+	order = drm_random_order(total_size, &lcg_state);
+	if (!order)
+		goto err_nodes;
+
+	ret = -EINVAL;
+	drm_mm_init(&mm, 0, 2*total_size - 1);
+	mm.color_adjust = no_color_touching;
+	for (n = 0; n < total_size; n++) {
+		int err;
+
+		err = drm_mm_insert_node_generic(&mm, &nodes[n].node,
+						 1, 0, color++,
+						 DRM_MM_SEARCH_DEFAULT,
+						 DRM_MM_CREATE_DEFAULT);
+		if (err) {
+			pr_err("insert failed, step %d\n", n);
+			ret = err;
+			goto out;
+		}
+	}
+
+	for (n = 1; n <= range_size; n <<= 1) {
+		const int nsize = range_size / 2;
+		unsigned int c = color++;
+		LIST_HEAD(evict_list);
+		struct evict_node *e, *en;
+		struct drm_mm_node tmp;
+		int err;
+
+		drm_mm_init_scan_with_range(&mm, nsize, n, c,
+					    range_start, range_end);
+		drm_random_reorder(order, total_size, &lcg_state);
+		for (m = 0; m < total_size; m++) {
+			e = &nodes[order[m]];
+			list_add(&e->link, &evict_list);
+			if (drm_mm_scan_add_block(&e->node))
+				break;
+		}
+		list_for_each_entry_safe(e, en, &evict_list, link) {
+			if (!drm_mm_scan_remove_block(&e->node))
+				list_del(&e->link);
+		}
+		if (list_empty(&evict_list)) {
+			pr_err("Failed to find eviction: size=%d, align=%d, color=%d\n",
+			       nsize, n, c);
+			goto out;
+		}
+
+		list_for_each_entry(e, &evict_list, link)
+			drm_mm_remove_node(&e->node);
+
+		memset(&tmp, 0, sizeof(tmp));
+		err = drm_mm_insert_node_in_range_generic(&mm, &tmp, nsize, n, c,
+							  range_start, range_end,
+							  DRM_MM_SEARCH_DEFAULT,
+							  DRM_MM_CREATE_DEFAULT);
+		if (err) {
+			pr_err("Failed to insert into eviction hole: size=%d, align=%d, color=%d, err=%d\n",
+			       nsize, n, c, err);
+			show_scan(&mm);
+			show_holes(&mm, 3);
+			ret = err;
+			goto out;
+		}
+
+		if ((int)tmp.start % n || tmp.size != nsize) {
+			pr_err("Inserted did not fit the eviction hole: size=%lld [%d], align=%d [rem=%d], start=%llx\n",
+			       tmp.size, nsize, n, (int)tmp.start % n, tmp.start);
+
+			drm_mm_remove_node(&tmp);
+			goto out;
+		}
+
+		if (!tmp.hole_follows &&
+		    list_next_entry(&tmp, node_list)->allocated) {
+			pr_err("colors abutt; %ld [%llx + %llx] is next to %ld [%llx + %llx]!\n",
+			       tmp.color, tmp.start, tmp.size,
+			       list_next_entry(&tmp, node_list)->color,
+			       list_next_entry(&tmp, node_list)->start,
+			       list_next_entry(&tmp, node_list)->size);
+			goto out;
+		}
+
+		drm_mm_remove_node(&tmp);
+		list_for_each_entry(e, &evict_list, link) {
+			err = drm_mm_reserve_node(&mm, &e->node);
+			if (err) {
+				pr_err("Failed to reinsert node after eviction: start=%llx\n",
+				       e->node.start);
+				ret = err;
+				goto out;
+			}
+		}
+	}
+
+	drm_for_each_prime(n, range_size) {
+		LIST_HEAD(evict_list);
+		unsigned int c = color++;
+		struct evict_node *e, *en;
+		struct drm_mm_node tmp;
+		int nsize = (range_size - n + 1) / 2;
+		int err;
+
+		drm_mm_init_scan_with_range(&mm, nsize, n, c,
+					    range_start, range_end);
+		drm_random_reorder(order, total_size, &lcg_state);
+		for (m = 0; m < total_size; m++) {
+			e = &nodes[order[m]];
+			list_add(&e->link, &evict_list);
+			if (drm_mm_scan_add_block(&e->node))
+				break;
+		}
+		list_for_each_entry_safe(e, en, &evict_list, link) {
+			if (!drm_mm_scan_remove_block(&e->node))
+				list_del(&e->link);
+		}
+		if (list_empty(&evict_list)) {
+			pr_err("Failed to find eviction: size=%d, align=%d (prime), color=%d\n",
+			       nsize, n, c);
+			goto out;
+		}
+
+		list_for_each_entry(e, &evict_list, link)
+			drm_mm_remove_node(&e->node);
+
+		memset(&tmp, 0, sizeof(tmp));
+		err = drm_mm_insert_node_in_range_generic(&mm, &tmp, nsize, n, c,
+							  range_start, range_end,
+							  DRM_MM_SEARCH_DEFAULT,
+							  DRM_MM_CREATE_DEFAULT);
+		if (err) {
+			pr_err("Failed to insert into eviction hole: size=%d, align=%d (prime), color=%d, err=%d\n",
+			       nsize, n, c, err);
+			show_scan(&mm);
+			show_holes(&mm, 3);
+			ret = err;
+			goto out;
+		}
+
+		if ((int)tmp.start % n || tmp.size != nsize) {
+			pr_err("Inserted did not fit the eviction hole: size=%lld [%d], align=%d [rem=%d] (prime), start=%llx\n",
+			       tmp.size, nsize, n, (int)tmp.start % n, tmp.start);
+
+			drm_mm_remove_node(&tmp);
+			goto out;
+		}
+
+		if (!tmp.hole_follows &&
+		    list_next_entry(&tmp, node_list)->allocated) {
+			pr_err("colors abutt; %ld [%llx + %llx] is next to %ld [%llx + %llx]!\n",
+			       tmp.color, tmp.start, tmp.size,
+			       list_next_entry(&tmp, node_list)->color,
+			       list_next_entry(&tmp, node_list)->start,
+			       list_next_entry(&tmp, node_list)->size);
+			goto out;
+		}
+
+		drm_mm_remove_node(&tmp);
+		list_for_each_entry(e, &evict_list, link) {
+			err = drm_mm_reserve_node(&mm, &e->node);
+			if (err) {
+				pr_err("Failed to reinsert node after eviction: start=%llx\n",
+				       e->node.start);
+				ret = err;
+				goto out;
+			}
+		}
+	}
+
+	ret = 0;
+out:
+	if (ret)
+		drm_mm_debug_table(&mm, __func__);
+	drm_mm_for_each_node_safe(node, next, &mm)
+		drm_mm_remove_node(node);
+	drm_mm_takedown(&mm);
+	kfree(order);
+err_nodes:
+	vfree(nodes);
+err:
+	return ret;
+}
+
 #include "drm_selftest.c"
 
 static int __init test_drm_mm_init(void)
-- 
2.11.0



More information about the Intel-gfx mailing list