Check that if we request top-down allocation from drm_mm_insert_node() we receive the next available hole from the top. Signed-off-by: Chris Wilson <chris@xxxxxxxxxxxxxxxxxx> --- drivers/gpu/drm/drm_mm_selftests.h | 1 + drivers/gpu/drm/test-drm_mm.c | 96 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+) diff --git a/drivers/gpu/drm/drm_mm_selftests.h b/drivers/gpu/drm/drm_mm_selftests.h index a3ee623b5f59..d435234e0e86 100644 --- a/drivers/gpu/drm/drm_mm_selftests.h +++ b/drivers/gpu/drm/drm_mm_selftests.h @@ -5,6 +5,7 @@ * * Tests are executed in reverse order by igt/drm_mm */ +selftest(topdown, igt_topdown) selftest(evict, igt_evict) selftest(align64, igt_align64) selftest(align32, igt_align32) diff --git a/drivers/gpu/drm/test-drm_mm.c b/drivers/gpu/drm/test-drm_mm.c index ab9ddfba5cf5..270d0732f1ab 100644 --- a/drivers/gpu/drm/test-drm_mm.c +++ b/drivers/gpu/drm/test-drm_mm.c @@ -942,6 +942,102 @@ static int igt_evict(void *ignored) return ret; } +static int igt_topdown(void *ignored) +{ + const int size = 8192; + unsigned long *bitmap; + struct drm_mm mm; + struct drm_mm_node *nodes, *node, *next; + int *order, n, m, o = 0; + int ret; + + ret = -ENOMEM; + nodes = vzalloc(size * sizeof(*nodes)); + if (!nodes) + goto err; + + bitmap = kzalloc(size / BITS_PER_LONG * sizeof(unsigned long), + GFP_TEMPORARY); + if (!bitmap) + goto err_nodes; + + order = random_order(size); + if (!order) + goto err_bitmap; + + ret = -EINVAL; + drm_mm_init(&mm, 0, size); + for (n = 0; n < size; n++) { + int err; + + err = drm_mm_insert_node_generic(&mm, &nodes[n], 1, 0, 0, + DRM_MM_SEARCH_BELOW, + DRM_MM_CREATE_TOP); + if (err) { + pr_err("insert failed, step %d\n", n); + ret = err; + goto out; + } + + if (nodes[n].hole_follows) { + pr_err("hole after topdown insert %d, start=%llx\n", + n, nodes[n].start); + goto out; + } + } + + for_each_prime(n, size) { + for (m = 0; m < n; m++) { + node = &nodes[order[(o + m) % size]]; + drm_mm_remove_node(node); + __set_bit(node->start, bitmap); + } + + for (m = 0; m < n; m++) { + int err, last; + + node = &nodes[order[(o + m) % size]]; + err = drm_mm_insert_node_generic(&mm, node, 1, 0, 0, + DRM_MM_SEARCH_BELOW, + DRM_MM_CREATE_TOP); + if (err) { + pr_err("insert failed, step %d/%d\n", m, n); + ret = err; + goto out; + } + + if (node->hole_follows) { + pr_err("hole after topdown insert %d/%d, start=%llx\n", + m, n, node->start); + goto out; + } + + last = find_last_bit(bitmap, size); + if (node->start != last) { + pr_err("node %d/%d not inserted into upmost hole, expected %d, found %lld\n", + m, n, last, node->start); + goto out; + } + __clear_bit(last, bitmap); + } + + o += n; + } + + ret = 0; +out: + list_for_each_entry_safe(node, next, &mm.head_node.node_list, node_list) + drm_mm_remove_node(node); + drm_mm_takedown(&mm); + kfree(order); +err_bitmap: + kfree(bitmap); +err_nodes: + vfree(nodes); +err: + return ret; +} + #include "drm_selftest.c" static int __init test_drm_mm_init(void) -- 2.11.0 _______________________________________________ Intel-gfx mailing list Intel-gfx@xxxxxxxxxxxxxxxxxxxxx https://lists.freedesktop.org/mailman/listinfo/intel-gfx