drm/i915/selftests: exercise cache domain eviction
authorMatthew Auld <matthew.auld@intel.com>
Mon, 6 Mar 2017 23:54:02 +0000 (23:54 +0000)
committerChris Wilson <chris@chris-wilson.co.uk>
Thu, 9 Mar 2017 08:42:39 +0000 (08:42 +0000)
Add a selftest to exercise evicting neighbouring nodes that conflict due
to page colouring in the GTT.

v2: add a peppering of comments

Signed-off-by: Matthew Auld <matthew.auld@intel.com>
Cc: Chris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
Link: http://patchwork.freedesktop.org/patch/msgid/20170306235414.23407-4-matthew.auld@intel.com
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
drivers/gpu/drm/i915/selftests/i915_gem_evict.c

index 97af353db21886235e1204dd54881a803b7f3e50..14e9c2fbc4e6b3ce43e91c8b56350406e07f8969 100644 (file)
@@ -202,6 +202,95 @@ cleanup:
        return err;
 }
 
+static void mock_color_adjust(const struct drm_mm_node *node,
+                             unsigned long color,
+                             u64 *start,
+                             u64 *end)
+{
+}
+
+static int igt_evict_for_cache_color(void *arg)
+{
+       struct drm_i915_private *i915 = arg;
+       struct i915_ggtt *ggtt = &i915->ggtt;
+       const unsigned long flags = PIN_OFFSET_FIXED;
+       struct drm_mm_node target = {
+               .start = I915_GTT_PAGE_SIZE * 2,
+               .size = I915_GTT_PAGE_SIZE,
+               .color = I915_CACHE_LLC,
+       };
+       struct drm_i915_gem_object *obj;
+       struct i915_vma *vma;
+       int err;
+
+       /* Currently the use of color_adjust is limited to cache domains within
+        * the ggtt, and so the presence of mm.color_adjust is assumed to be
+        * i915_gtt_color_adjust throughout our driver, so using a mock color
+        * adjust will work just fine for our purposes.
+        */
+       ggtt->base.mm.color_adjust = mock_color_adjust;
+
+       obj = i915_gem_object_create_internal(i915, I915_GTT_PAGE_SIZE);
+       if (IS_ERR(obj)) {
+               err = PTR_ERR(obj);
+               goto cleanup;
+       }
+       i915_gem_object_set_cache_level(obj, I915_CACHE_LLC);
+
+       vma = i915_gem_object_ggtt_pin(obj, NULL, 0, 0,
+                                      I915_GTT_PAGE_SIZE | flags);
+       if (IS_ERR(vma)) {
+               pr_err("[0]i915_gem_object_ggtt_pin failed\n");
+               err = PTR_ERR(vma);
+               goto cleanup;
+       }
+
+       obj = i915_gem_object_create_internal(i915, I915_GTT_PAGE_SIZE);
+       if (IS_ERR(obj)) {
+               err = PTR_ERR(obj);
+               goto cleanup;
+       }
+       i915_gem_object_set_cache_level(obj, I915_CACHE_LLC);
+
+       /* Neighbouring; same colour - should fit */
+       vma = i915_gem_object_ggtt_pin(obj, NULL, 0, 0,
+                                      (I915_GTT_PAGE_SIZE * 2) | flags);
+       if (IS_ERR(vma)) {
+               pr_err("[1]i915_gem_object_ggtt_pin failed\n");
+               err = PTR_ERR(vma);
+               goto cleanup;
+       }
+
+       i915_vma_unpin(vma);
+
+       /* Remove just the second vma */
+       err = i915_gem_evict_for_node(&ggtt->base, &target, 0);
+       if (err) {
+               pr_err("[0]i915_gem_evict_for_node returned err=%d\n", err);
+               goto cleanup;
+       }
+
+       /* Attempt to remove the first *pinned* vma, by removing the (empty)
+        * neighbour -- this should fail.
+        */
+       target.color = I915_CACHE_L3_LLC;
+
+       err = i915_gem_evict_for_node(&ggtt->base, &target, 0);
+       if (!err) {
+               pr_err("[1]i915_gem_evict_for_node returned err=%d\n", err);
+               err = -EINVAL;
+               goto cleanup;
+       }
+
+       err = 0;
+
+cleanup:
+       unpin_ggtt(i915);
+       cleanup_objects(i915);
+       ggtt->base.mm.color_adjust = NULL;
+       return err;
+}
+
 static int igt_evict_vm(void *arg)
 {
        struct drm_i915_private *i915 = arg;
@@ -241,6 +330,7 @@ int i915_gem_evict_mock_selftests(void)
        static const struct i915_subtest tests[] = {
                SUBTEST(igt_evict_something),
                SUBTEST(igt_evict_for_vma),
+               SUBTEST(igt_evict_for_cache_color),
                SUBTEST(igt_evict_vm),
                SUBTEST(igt_overcommit),
        };