[Intel-gfx] [PATCH 6/9] drm: kselftest for drm_mm and eviction
Chris Wilson
chris at chris-wilson.co.uk
Fri Dec 9 13:08:22 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/drm_mm_selftests.h | 1 +
drivers/gpu/drm/test-drm_mm.c | 167 +++++++++++++++++++++++++++++++++++++
2 files changed, 168 insertions(+)
diff --git a/drivers/gpu/drm/drm_mm_selftests.h b/drivers/gpu/drm/drm_mm_selftests.h
index 591d34aa233a..a3ee623b5f59 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(evict, igt_evict)
selftest(align64, igt_align64)
selftest(align32, igt_align32)
selftest(align, igt_align)
diff --git a/drivers/gpu/drm/test-drm_mm.c b/drivers/gpu/drm/test-drm_mm.c
index 8cdcde580da3..ab9ddfba5cf5 100644
--- a/drivers/gpu/drm/test-drm_mm.c
+++ b/drivers/gpu/drm/test-drm_mm.c
@@ -775,6 +775,173 @@ static int igt_align64(void *ignored)
return igt_align_pot(64);
}
+static int igt_evict(void *ignored)
+{
+ 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 = random_order(size);
+ 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;
+ }
+ }
+
+ 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;
+ bool found = false;
+ int err;
+
+ drm_mm_init_scan(&mm, nsize, n, 0);
+ for (m = 0; m < size; m++) {
+ e = &nodes[order[m]];
+ list_add(&e->link, &evict_list);
+ if (drm_mm_scan_add_block(&e->node)) {
+ found = true;
+ break;
+ }
+ }
+ if (!found) {
+ pr_err("Failed to fail eviction: size=%d, align=%d\n",
+ nsize, n);
+ goto out;
+ }
+
+ list_for_each_entry_safe(e, en, &evict_list, link) {
+ if (!drm_mm_scan_remove_block(&e->node))
+ list_del(&e->link);
+ }
+
+ 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);
+ goto out;
+ }
+
+ if (tmp.start % n || tmp.size != nsize || tmp.hole_follows) {
+ pr_err("Inserted did not fill the eviction hole: size=%lld [%d], align=%d, start=%llx, hole-follows?=%d\n",
+ tmp.size, nsize, 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;
+ }
+ }
+ }
+
+ 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;
+ bool found = false;
+ int err;
+
+ drm_mm_init_scan(&mm, nsize, n, 0);
+ for (m = 0; m < size; m++) {
+ e = &nodes[order[m]];
+ list_add(&e->link, &evict_list);
+ if (drm_mm_scan_add_block(&e->node)) {
+ found = true;
+ break;
+ }
+ }
+ if (!found) {
+ pr_err("Failed to fail eviction: size=%d, align=%d\n",
+ nsize, n);
+ goto out;
+ }
+
+ list_for_each_entry_safe(e, en, &evict_list, link) {
+ if (!drm_mm_scan_remove_block(&e->node))
+ list_del(&e->link);
+ }
+
+ 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);
+ goto out;
+ }
+
+ if (tmp.start % n || tmp.size != nsize || tmp.hole_follows) {
+ pr_err("Inserted did not fill the eviction hole: size=%lld [%d], align=%d, start=%llx, hole-follows?=%d\n",
+ tmp.size, nsize, 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:
+ 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_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