[Intel-gfx] [PATCH v2 21/40] drm: kselftest for drm_mm and restricted color eviction
Chris Wilson
chris at chris-wilson.co.uk
Fri Dec 16 07:46:59 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 | 119 ++++++++++++++++++++++++++-
2 files changed, 116 insertions(+), 4 deletions(-)
diff --git a/drivers/gpu/drm/selftests/drm_mm_selftests.h b/drivers/gpu/drm/selftests/drm_mm_selftests.h
index 0a3a7e32e5f7..6a4575fdc1c0 100644
--- a/drivers/gpu/drm/selftests/drm_mm_selftests.h
+++ b/drivers/gpu/drm/selftests/drm_mm_selftests.h
@@ -20,3 +20,4 @@ selftest(evict_range, igt_evict_range)
selftest(topdown, igt_topdown)
selftest(color, igt_color)
selftest(color_evict, igt_color_evict)
+selftest(color_evict_range, igt_color_evict_range)
diff --git a/drivers/gpu/drm/selftests/test-drm_mm.c b/drivers/gpu/drm/selftests/test-drm_mm.c
index 0a051abc8f13..43575074eca5 100644
--- a/drivers/gpu/drm/selftests/test-drm_mm.c
+++ b/drivers/gpu/drm/selftests/test-drm_mm.c
@@ -1831,6 +1831,7 @@ static int igt_color(void *ignored)
}
static int evict_color(struct drm_mm *mm,
+ u64 range_start, u64 range_end,
struct evict_node *nodes,
unsigned int *order,
unsigned int count,
@@ -1844,7 +1845,9 @@ static int evict_color(struct drm_mm *mm,
struct drm_mm_node tmp;
int err;
- drm_mm_init_scan(mm, size, alignment, color);
+ drm_mm_init_scan_with_range(mm,
+ size, alignment, color,
+ range_start, range_end);
if (!evict_nodes(mm,
nodes, order, count,
&evict_list))
@@ -1862,6 +1865,12 @@ static int evict_color(struct drm_mm *mm,
return err;
}
+ if (tmp.start < range_start || tmp.start + tmp.size > range_end) {
+ pr_err("Inserted [address=%llu + %llu] did not fit into the request range [%llu, %llu]\n",
+ tmp.start, tmp.size, range_start, range_end);
+ err = -EINVAL;
+ }
+
if (colors_abutt(&tmp))
err = -EINVAL;
@@ -1933,7 +1942,7 @@ static int igt_color_evict(void *ignored)
for (mode = evict_modes; mode->name; mode++) {
for (n = 1; n <= total_size; n <<= 1) {
drm_random_reorder(order, total_size, &prng);
- err = evict_color(&mm,
+ err = evict_color(&mm, 0, U64_MAX,
nodes, order, total_size,
n, 1, color++,
mode);
@@ -1946,7 +1955,7 @@ static int igt_color_evict(void *ignored)
for (n = 1; n < total_size; n <<= 1) {
drm_random_reorder(order, total_size, &prng);
- err = evict_color(&mm,
+ err = evict_color(&mm, 0, U64_MAX,
nodes, order, total_size,
total_size/2, n, color++,
mode);
@@ -1963,7 +1972,7 @@ static int igt_color_evict(void *ignored)
DRM_MM_BUG_ON(!nsize);
drm_random_reorder(order, total_size, &prng);
- err = evict_color(&mm,
+ err = evict_color(&mm, 0, U64_MAX,
nodes, order, total_size,
nsize, n, color++,
mode);
@@ -1989,6 +1998,108 @@ static int igt_color_evict(void *ignored)
return ret;
}
+static int igt_color_evict_range(void *ignored)
+{
+ RND_STATE(prng, random_seed);
+ const unsigned int total_size = 8192;
+ const unsigned int range_size = total_size / 2;
+ const unsigned int range_start = total_size / 4;
+ const unsigned int range_end = range_start + range_size;
+ const struct insert_mode *mode;
+ unsigned long color = 0;
+ struct drm_mm mm;
+ struct evict_node *nodes;
+ struct drm_mm_node *node, *next;
+ unsigned int *order, n;
+ int ret, err;
+
+ /* Like igt_color_evict(), but limited to small portion of the full
+ * drm_mm range.
+ */
+
+ ret = -ENOMEM;
+ nodes = vzalloc(total_size * sizeof(*nodes));
+ if (!nodes)
+ goto err;
+
+ order = drm_random_order(total_size, &prng);
+ if (!order)
+ goto err_nodes;
+
+ ret = -EINVAL;
+ drm_mm_init(&mm, 0, 2*total_size - 1);
+ mm.color_adjust = separate_adjacent_colors;
+ for (n = 0; n < total_size; n++) {
+ 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 (mode = evict_modes; mode->name; mode++) {
+ for (n = 1; n <= range_size; n <<= 1) {
+ drm_random_reorder(order, range_size, &prng);
+ err = evict_color(&mm, range_start, range_end,
+ nodes, order, total_size,
+ n, 1, color++,
+ mode);
+ if (err) {
+ pr_err("%s evict_color(size=%u) failed for range [%x, %x]\n",
+ mode->name, n, range_start, range_end);
+ goto out;
+ }
+ }
+
+ for (n = 1; n < range_size; n <<= 1) {
+ drm_random_reorder(order, total_size, &prng);
+ err = evict_color(&mm, range_start, range_end,
+ nodes, order, total_size,
+ range_size/2, n, color++,
+ mode);
+ if (err) {
+ pr_err("%s evict_color(size=%u, alignment=%u) failed for range [%x, %x]\n",
+ mode->name, total_size/2, n, range_start, range_end);
+ goto out;
+ }
+ }
+
+ drm_for_each_prime(n, min(range_size, max_prime)) {
+ unsigned int nsize = (range_size - n + 1) / 2;
+
+ DRM_MM_BUG_ON(!nsize);
+
+ drm_random_reorder(order, total_size, &prng);
+ err = evict_color(&mm, range_start, range_end,
+ nodes, order, total_size,
+ nsize, n, color++,
+ mode);
+ if (err) {
+ pr_err("%s evict_color(size=%u, alignment=%u) failed for range [%x, %x]\n",
+ mode->name, nsize, n, range_start, range_end);
+ 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