[PATCH 9/9] drm: kselftest for drm_mm and color adjustment
Chris Wilson
chris at chris-wilson.co.uk
Fri Dec 9 13:08:25 UTC 2016
Check that after applying the driver's color adjustment, fitting of the
node and its alignment are still correct.
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 | 178 +++++++++++++++++++++++++++++++++++++
2 files changed, 179 insertions(+)
diff --git a/drivers/gpu/drm/drm_mm_selftests.h b/drivers/gpu/drm/drm_mm_selftests.h
index 6bbdbb929714..30b4f2134248 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(color, igt_color)
selftest(topdown_align, igt_topdown_align)
selftest(topdown, igt_topdown)
selftest(evict, igt_evict)
diff --git a/drivers/gpu/drm/test-drm_mm.c b/drivers/gpu/drm/test-drm_mm.c
index 7699e7e2c698..f320ded75cab 100644
--- a/drivers/gpu/drm/test-drm_mm.c
+++ b/drivers/gpu/drm/test-drm_mm.c
@@ -1130,6 +1130,184 @@ static int igt_topdown_align(void *ignored)
return ret;
}
+static void no_color_touching(struct drm_mm_node *node,
+ unsigned long color,
+ u64 *start,
+ u64 *end)
+{
+ if (node->allocated && node->color != color)
+ ++*start;
+
+ node = list_next_entry(node, node_list);
+ if (node->allocated && node->color != color)
+ --*end;
+}
+
+static int igt_color(void *ignored)
+{
+ const int count = 4096;
+ struct drm_mm mm;
+ struct drm_mm_node *node, *nn;
+ const struct modes {
+ const char *name;
+ unsigned int search;
+ unsigned int create;
+ } modes[] = {
+ { "default", DRM_MM_SEARCH_DEFAULT, DRM_MM_CREATE_DEFAULT },
+ { "best", DRM_MM_SEARCH_BEST, DRM_MM_CREATE_DEFAULT },
+ { "top-down", DRM_MM_SEARCH_BELOW, DRM_MM_CREATE_TOP },
+ };
+ int ret = -EINVAL;
+ int n, m;
+
+ drm_mm_init(&mm, 0, ~0ull);
+
+ for (n = 1; n <= count; n++) {
+ int err;
+
+ node = kzalloc(sizeof(*node), GFP_KERNEL);
+ if (!node) {
+ ret = -ENOMEM;
+ goto out;
+ }
+
+ err = drm_mm_insert_node_generic(&mm, node, n, 0, n,
+ DRM_MM_SEARCH_DEFAULT,
+ DRM_MM_CREATE_DEFAULT);
+ if (err) {
+ pr_err("insert failed, step %d\n", n);
+ kfree(node);
+ ret = err;
+ goto out;
+ }
+ }
+
+ list_for_each_entry_safe(node, nn, &mm.head_node.node_list, node_list) {
+ if (node->color != node->size) {
+ pr_err("invalid color stored: expected %lld, found %ld\n",
+ node->size, node->color);
+
+ goto out;
+ }
+
+ drm_mm_remove_node(node);
+ kfree(node);
+ }
+
+ /* Now, let's start experimenting with applying a color callback */
+ mm.color_adjust = no_color_touching;
+ for (m = 0; m < ARRAY_SIZE(modes); m++) {
+ u64 last;
+ int err;
+
+ node = kzalloc(sizeof(*node), GFP_KERNEL);
+ if (!node) {
+ ret = -ENOMEM;
+ goto out;
+ }
+
+ node->size = 1 + 2*count;
+ node->color = node->size;
+
+ err = drm_mm_reserve_node(&mm, node);
+ if (err) {
+ pr_err("intial reserve failed!\n");
+ goto out;
+ }
+
+ last = node->start + node->size;
+
+ for (n = 1; n <= count; n++) {
+ int rem;
+
+ node = kzalloc(sizeof(*node), GFP_KERNEL);
+ if (!node) {
+ ret = -ENOMEM;
+ goto out;
+ }
+
+ node->start = last;
+ node->size = n + count;
+ node->color = node->size;
+
+ err = drm_mm_reserve_node(&mm, node);
+ if (err != -ENOSPC) {
+ pr_err("reserve %d did not report color overlap! err=%d\n",
+ n, err);
+ goto out;
+ }
+
+ node->start += n + 1;
+ rem = node->start;
+ rem %= n + count;
+ node->start += n + count - rem;
+
+ err = drm_mm_reserve_node(&mm, node);
+ if (err) {
+ pr_err("reserve %d failed, err=%d\n", n, err);
+ goto out;
+ }
+
+ last = node->start + node->size;
+ }
+
+ for (n = 1; n <= count; n++) {
+ node = kzalloc(sizeof(*node), GFP_KERNEL);
+ if (!node) {
+ ret = -ENOMEM;
+ goto out;
+ }
+
+ err = drm_mm_insert_node_generic(&mm, node, n, n, n,
+ modes[m].search,
+ modes[m].create);
+ if (err) {
+ pr_err("%s insert failed, step %d, err=%d\n",
+ modes[m].name, n, err);
+ kfree(node);
+ ret = err;
+ goto out;
+ }
+ }
+
+ list_for_each_entry_safe(node, nn,
+ &mm.head_node.node_list, node_list) {
+ u64 rem;
+
+ if (node->color != node->size) {
+ pr_err("%s invalid color stored: expected %lld, found %ld\n",
+ modes[m].name, node->size, node->color);
+
+ goto out;
+ }
+
+ if (!node->hole_follows) {
+ pr_err("%s colors abutt!\n", modes[m].name);
+ goto out;
+ }
+
+ div64_u64_rem(node->start, node->size, &rem);
+ if (rem) {
+ pr_err("%s colored node misaligned, start=%llx expected alignment=%lld [rem=%lld]\n",
+ modes[m].name, node->start, node->size, rem);
+ goto out;
+ }
+
+ drm_mm_remove_node(node);
+ kfree(node);
+ }
+ }
+
+ ret = 0;
+out:
+ list_for_each_entry_safe(node, nn, &mm.head_node.node_list, node_list) {
+ drm_mm_remove_node(node);
+ kfree(node);
+ }
+ drm_mm_takedown(&mm);
+ return ret;
+}
+
#include "drm_selftest.c"
static int __init test_drm_mm_init(void)
--
2.11.0
More information about the dri-devel
mailing list