[Intel-gfx] [PATCH 13/34] drm: kselftest for drm_mm and eviction
Chris Wilson
chris at chris-wilson.co.uk
Mon Dec 12 11:53:29 UTC 2016
Check that we add arbitrary blocks to the eviction scanner in order to
find the first minimal hole that matches our request.
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 | 252 +++++++++++++++++++++++++++
2 files changed, 253 insertions(+)
diff --git a/drivers/gpu/drm/selftests/drm_mm_selftests.h b/drivers/gpu/drm/selftests/drm_mm_selftests.h
index 9eb0c9fd9dff..7aaca10e7029 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(evict, igt_evict)
selftest(align64, igt_align64)
selftest(align32, igt_align32)
selftest(align, igt_align)
diff --git a/drivers/gpu/drm/selftests/test-drm_mm.c b/drivers/gpu/drm/selftests/test-drm_mm.c
index be47e4aeec12..f9d6a25a8006 100644
--- a/drivers/gpu/drm/selftests/test-drm_mm.c
+++ b/drivers/gpu/drm/selftests/test-drm_mm.c
@@ -773,6 +773,258 @@ static int igt_align64(void *ignored)
return igt_align_pot(64);
}
+static void show_scan(const struct drm_mm *scan)
+{
+ pr_info("scan: hit [%llx, %llx], size=%lld, align=%d, color=%ld\n",
+ scan->scan_hit_start, scan->scan_hit_end,
+ scan->scan_size, scan->scan_alignment, scan->scan_color);
+}
+
+static void show_holes(const struct drm_mm *mm, int count)
+{
+ u64 hole_start, hole_end;
+ struct drm_mm_node *hole;
+
+ drm_mm_for_each_hole(hole, mm, hole_start, hole_end) {
+ struct drm_mm_node *next = list_next_entry(hole, node_list);
+ const char *node1 = NULL, *node2 = NULL;
+
+ if (hole->allocated)
+ node1 = kasprintf(GFP_KERNEL,
+ "[%llx + %lld, color=%ld], ",
+ hole->start, hole->size, hole->color);
+
+ if (next->allocated)
+ node2 = kasprintf(GFP_KERNEL,
+ ", [%llx + %lld, color=%ld]",
+ next->start, next->size, next->color);
+
+ pr_info("%sHole [%llx - %llx, size %lld]%s\n",
+ node1,
+ hole_start, hole_end, hole_end - hole_start,
+ node2);
+
+ kfree(node2);
+ kfree(node1);
+
+ if (!--count)
+ break;
+ }
+}
+
+static int igt_evict(void *ignored)
+{
+ u32 lcg_state = random_seed;
+ const int size = 8192;
+ 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(size * sizeof(*nodes));
+ if (!nodes)
+ goto err;
+
+ order = drm_random_order(size, &lcg_state);
+ if (!order)
+ goto err_nodes;
+
+ ret = -EINVAL;
+ drm_mm_init(&mm, 0, size);
+ for (n = 0; n < size; n++) {
+ int err;
+
+ err = drm_mm_insert_node(&mm, &nodes[n].node, 1, 0,
+ DRM_MM_SEARCH_DEFAULT);
+ if (err) {
+ pr_err("insert failed, step %d\n", n);
+ ret = err;
+ goto out;
+ }
+ }
+
+ /* First check that using the scanner doesn't break the mm */
+ if (1) {
+ LIST_HEAD(evict_list);
+ struct evict_node *e;
+
+ drm_mm_init_scan(&mm, 1, 0, 0);
+ for (m = 0; m < size; m++) {
+ e = &nodes[m];
+ list_add(&e->link, &evict_list);
+ drm_mm_scan_add_block(&e->node);
+ }
+ list_for_each_entry(e, &evict_list, link)
+ drm_mm_scan_remove_block(&e->node);
+
+ for (m = 0; m < size; m++) {
+ e = &nodes[m];
+
+ if (!drm_mm_node_allocated(&e->node)) {
+ pr_err("node[%d] no longer allocated!\n", m);
+ goto out;
+ }
+
+ e->link.next = NULL;
+ }
+
+ drm_mm_for_each_node(node, &mm) {
+ e = container_of(node, typeof(*e), node);
+ e->link.next = &e->link;
+ }
+
+ for (m = 0; m < size; m++) {
+ e = &nodes[m];
+
+ if (!e->link.next) {
+ pr_err("node[%d] no longer connected!\n", m);
+ goto out;
+ }
+ }
+
+ if (!list_empty(&mm.hole_stack)) {
+ pr_err("mm now contains holes!\n");
+ goto out;
+ }
+ }
+
+ for (n = 1; n < size; n <<= 1) {
+ const int nsize = size / 2;
+ LIST_HEAD(evict_list);
+ struct evict_node *e, *en;
+ struct drm_mm_node tmp;
+ int err;
+
+ drm_mm_init_scan(&mm, nsize, n, 0);
+ drm_random_reorder(order, size, &lcg_state);
+ for (m = 0; m < 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\n",
+ nsize, n);
+ 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(&mm, &tmp, nsize, n,
+ DRM_MM_SEARCH_DEFAULT);
+ if (err) {
+ pr_err("Failed to insert into eviction hole: size=%d, align=%d\n",
+ nsize, n);
+ show_scan(&mm);
+ show_holes(&mm, 3);
+ ret = err;
+ goto out;
+ }
+
+ if ((int)tmp.start % n || tmp.size != nsize || tmp.hole_follows) {
+ pr_err("Inserted did not fill the eviction hole: size=%lld [%d], align=%d [rem=%d], start=%llx, hole-follows?=%d\n",
+ tmp.size, nsize, n, (int)tmp.start % n, tmp.start, tmp.hole_follows);
+
+ drm_mm_remove_node(&tmp);
+ 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, size) {
+ LIST_HEAD(evict_list);
+ struct evict_node *e, *en;
+ struct drm_mm_node tmp;
+ int nsize = (size - n + 1) / 2;
+ int err;
+
+ drm_mm_init_scan(&mm, nsize, n, 0);
+ drm_random_reorder(order, size, &lcg_state);
+ for (m = 0; m < 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)\n",
+ nsize, n);
+ 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(&mm, &tmp, nsize, n,
+ DRM_MM_SEARCH_DEFAULT);
+ if (err) {
+ pr_err("Failed to insert into eviction hole: size=%d, align=%d (prime)\n",
+ nsize, n);
+ show_scan(&mm);
+ show_holes(&mm, 3);
+ ret = err;
+ goto out;
+ }
+
+ if ((int)tmp.start % n || tmp.size != nsize || tmp.hole_follows) {
+ pr_err("Inserted did not fill the eviction hole: size=%lld [%d], align=%d [rem=%d] (prime), start=%llx, hole-follows?=%d\n",
+ tmp.size, nsize, n, (int)tmp.start % n, tmp.start, tmp.hole_follows);
+
+ drm_mm_remove_node(&tmp);
+ 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:
+ 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