Check that if we request bottom-up allocation from drm_mm_insert_node() we receive the next available hole from the bottom. Signed-off-by: Chris Wilson <chris@xxxxxxxxxxxxxxxxxx> --- drivers/gpu/drm/selftests/drm_mm_selftests.h | 1 + drivers/gpu/drm/selftests/test-drm_mm.c | 89 ++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+) diff --git a/drivers/gpu/drm/selftests/drm_mm_selftests.h b/drivers/gpu/drm/selftests/drm_mm_selftests.h index fb9d704e7943..bf0cd64264c8 100644 --- a/drivers/gpu/drm/selftests/drm_mm_selftests.h +++ b/drivers/gpu/drm/selftests/drm_mm_selftests.h @@ -9,6 +9,7 @@ selftest(color_evict_range, igt_color_evict_range) selftest(color_evict, igt_color_evict) selftest(color, igt_color) selftest(topdown_align, igt_topdown_align) +selftest(bottomup, igt_bottomup) 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 f2f802c60e4c..30d04dd9daef 100644 --- a/drivers/gpu/drm/selftests/test-drm_mm.c +++ b/drivers/gpu/drm/selftests/test-drm_mm.c @@ -1304,6 +1304,95 @@ static int igt_topdown(void *ignored) return ret; } +static int igt_bottomup(void *ignored) +{ + u32 lcg_state = random_seed; + 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 = drm_random_order(size, &lcg_state); + 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_INSERT_LOW); + if (err) { + pr_err("bottomup insert failed, step %d\n", n); + ret = err; + goto out; + } + + if (nodes[n].hole_size) { + pr_err("hole after bottomup insert %d, start=%llx\n", + n, nodes[n].start); + goto out; + } + } + + drm_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_INSERT_LOW); + if (err) { + pr_err("insert failed, step %d/%d\n", m, n); + ret = err; + goto out; + } + + last = find_first_bit(bitmap, size); + if (node->start != last) { + pr_err("node %d/%d not inserted into bottom hole, expected %d, found %lld\n", + m, n, last, node->start); + goto out; + } + __clear_bit(last, bitmap); + } + + o += n; + } + + ret = 0; +out: + drm_mm_for_each_node_safe(node, next, &mm) + drm_mm_remove_node(node); + drm_mm_takedown(&mm); + kfree(order); +err_bitmap: + kfree(bitmap); +err_nodes: + vfree(nodes); +err: + return ret; +} + static int igt_topdown_align(void *ignored) { struct drm_mm mm; -- 2.11.0 _______________________________________________ Intel-gfx mailing list Intel-gfx@xxxxxxxxxxxxxxxxxxxxx https://lists.freedesktop.org/mailman/listinfo/intel-gfx