Commit 480cd6dd authored by Chris Wilson's avatar Chris Wilson

drm/i915/selftests: Track evict objects explicitly

During review of commit 71fc448c ("drm/i915/selftests: Make evict
tolerant of foreign objects"), Matthew mentioned it would be better if
we explicitly tracked the objects we created. We have an obj->st_link
hook for this purpose, so add the corresponding list of objects and
reduce our loops to only consider our own list.

References: 71fc448c ("drm/i915/selftests: Make evict tolerant of foreign objects")
Signed-off-by: default avatarChris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: default avatarMatthew Auld <matthew.auld@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20190121222117.23305-6-chris@chris-wilson.co.uk
parent 24bf86cc
...@@ -29,25 +29,21 @@ ...@@ -29,25 +29,21 @@
#include "mock_drm.h" #include "mock_drm.h"
#include "mock_gem_device.h" #include "mock_gem_device.h"
static int populate_ggtt(struct drm_i915_private *i915) static void quirk_add(struct drm_i915_gem_object *obj,
struct list_head *objects)
{
/* quirk is only for live tiled objects, use it to declare ownership */
GEM_BUG_ON(obj->mm.quirked);
obj->mm.quirked = true;
list_add(&obj->st_link, objects);
}
static int populate_ggtt(struct drm_i915_private *i915,
struct list_head *objects)
{ {
struct drm_i915_gem_object *obj, *on;
unsigned long expected_unbound, expected_bound;
unsigned long unbound, bound, count; unsigned long unbound, bound, count;
struct drm_i915_gem_object *obj;
u64 size; u64 size;
int err;
expected_unbound = 0;
list_for_each_entry(obj, &i915->mm.unbound_list, mm.link) {
i915_gem_object_get(obj);
expected_unbound++;
}
expected_bound = 0;
list_for_each_entry(obj, &i915->mm.bound_list, mm.link) {
i915_gem_object_get(obj);
expected_bound++;
}
count = 0; count = 0;
for (size = 0; for (size = 0;
...@@ -56,38 +52,36 @@ static int populate_ggtt(struct drm_i915_private *i915) ...@@ -56,38 +52,36 @@ static int populate_ggtt(struct drm_i915_private *i915)
struct i915_vma *vma; struct i915_vma *vma;
obj = i915_gem_object_create_internal(i915, I915_GTT_PAGE_SIZE); obj = i915_gem_object_create_internal(i915, I915_GTT_PAGE_SIZE);
if (IS_ERR(obj)) { if (IS_ERR(obj))
err = PTR_ERR(obj); return PTR_ERR(obj);
goto cleanup;
} quirk_add(obj, objects);
vma = i915_gem_object_ggtt_pin(obj, NULL, 0, 0, 0); vma = i915_gem_object_ggtt_pin(obj, NULL, 0, 0, 0);
if (IS_ERR(vma)) { if (IS_ERR(vma))
err = PTR_ERR(vma); return PTR_ERR(vma);
goto cleanup;
}
count++; count++;
} }
unbound = 0; unbound = 0;
list_for_each_entry(obj, &i915->mm.unbound_list, mm.link) list_for_each_entry(obj, &i915->mm.unbound_list, mm.link)
unbound++; if (obj->mm.quirked)
if (unbound != expected_unbound) { unbound++;
pr_err("%s: Found %lu objects unbound, expected %lu!\n", if (unbound) {
__func__, unbound, expected_unbound); pr_err("%s: Found %lu objects unbound, expected %u!\n",
err = -EINVAL; __func__, unbound, 0);
goto cleanup; return -EINVAL;
} }
bound = 0; bound = 0;
list_for_each_entry(obj, &i915->mm.bound_list, mm.link) list_for_each_entry(obj, &i915->mm.bound_list, mm.link)
bound++; if (obj->mm.quirked)
if (bound != expected_bound + count) { bound++;
if (bound != count) {
pr_err("%s: Found %lu objects bound, expected %lu!\n", pr_err("%s: Found %lu objects bound, expected %lu!\n",
__func__, bound, expected_bound + count); __func__, bound, count);
err = -EINVAL; return -EINVAL;
goto cleanup;
} }
if (list_empty(&i915->ggtt.vm.inactive_list)) { if (list_empty(&i915->ggtt.vm.inactive_list)) {
...@@ -96,15 +90,6 @@ static int populate_ggtt(struct drm_i915_private *i915) ...@@ -96,15 +90,6 @@ static int populate_ggtt(struct drm_i915_private *i915)
} }
return 0; return 0;
cleanup:
list_for_each_entry_safe(obj, on, &i915->mm.unbound_list, mm.link)
i915_gem_object_put(obj);
list_for_each_entry_safe(obj, on, &i915->mm.bound_list, mm.link)
i915_gem_object_put(obj);
return err;
} }
static void unpin_ggtt(struct drm_i915_private *i915) static void unpin_ggtt(struct drm_i915_private *i915)
...@@ -112,18 +97,20 @@ static void unpin_ggtt(struct drm_i915_private *i915) ...@@ -112,18 +97,20 @@ static void unpin_ggtt(struct drm_i915_private *i915)
struct i915_vma *vma; struct i915_vma *vma;
list_for_each_entry(vma, &i915->ggtt.vm.inactive_list, vm_link) list_for_each_entry(vma, &i915->ggtt.vm.inactive_list, vm_link)
i915_vma_unpin(vma); if (vma->obj->mm.quirked)
i915_vma_unpin(vma);
} }
static void cleanup_objects(struct drm_i915_private *i915) static void cleanup_objects(struct drm_i915_private *i915,
struct list_head *list)
{ {
struct drm_i915_gem_object *obj, *on; struct drm_i915_gem_object *obj, *on;
list_for_each_entry_safe(obj, on, &i915->mm.unbound_list, mm.link) list_for_each_entry_safe(obj, on, list, st_link) {
i915_gem_object_put(obj); GEM_BUG_ON(!obj->mm.quirked);
obj->mm.quirked = false;
list_for_each_entry_safe(obj, on, &i915->mm.bound_list, mm.link)
i915_gem_object_put(obj); i915_gem_object_put(obj);
}
mutex_unlock(&i915->drm.struct_mutex); mutex_unlock(&i915->drm.struct_mutex);
...@@ -136,11 +123,12 @@ static int igt_evict_something(void *arg) ...@@ -136,11 +123,12 @@ static int igt_evict_something(void *arg)
{ {
struct drm_i915_private *i915 = arg; struct drm_i915_private *i915 = arg;
struct i915_ggtt *ggtt = &i915->ggtt; struct i915_ggtt *ggtt = &i915->ggtt;
LIST_HEAD(objects);
int err; int err;
/* Fill the GGTT with pinned objects and try to evict one. */ /* Fill the GGTT with pinned objects and try to evict one. */
err = populate_ggtt(i915); err = populate_ggtt(i915, &objects);
if (err) if (err)
goto cleanup; goto cleanup;
...@@ -169,7 +157,7 @@ static int igt_evict_something(void *arg) ...@@ -169,7 +157,7 @@ static int igt_evict_something(void *arg)
} }
cleanup: cleanup:
cleanup_objects(i915); cleanup_objects(i915, &objects);
return err; return err;
} }
...@@ -178,13 +166,14 @@ static int igt_overcommit(void *arg) ...@@ -178,13 +166,14 @@ static int igt_overcommit(void *arg)
struct drm_i915_private *i915 = arg; struct drm_i915_private *i915 = arg;
struct drm_i915_gem_object *obj; struct drm_i915_gem_object *obj;
struct i915_vma *vma; struct i915_vma *vma;
LIST_HEAD(objects);
int err; int err;
/* Fill the GGTT with pinned objects and then try to pin one more. /* Fill the GGTT with pinned objects and then try to pin one more.
* We expect it to fail. * We expect it to fail.
*/ */
err = populate_ggtt(i915); err = populate_ggtt(i915, &objects);
if (err) if (err)
goto cleanup; goto cleanup;
...@@ -194,6 +183,8 @@ static int igt_overcommit(void *arg) ...@@ -194,6 +183,8 @@ static int igt_overcommit(void *arg)
goto cleanup; goto cleanup;
} }
quirk_add(obj, &objects);
vma = i915_gem_object_ggtt_pin(obj, NULL, 0, 0, 0); vma = i915_gem_object_ggtt_pin(obj, NULL, 0, 0, 0);
if (!IS_ERR(vma) || PTR_ERR(vma) != -ENOSPC) { if (!IS_ERR(vma) || PTR_ERR(vma) != -ENOSPC) {
pr_err("Failed to evict+insert, i915_gem_object_ggtt_pin returned err=%d\n", (int)PTR_ERR(vma)); pr_err("Failed to evict+insert, i915_gem_object_ggtt_pin returned err=%d\n", (int)PTR_ERR(vma));
...@@ -202,7 +193,7 @@ static int igt_overcommit(void *arg) ...@@ -202,7 +193,7 @@ static int igt_overcommit(void *arg)
} }
cleanup: cleanup:
cleanup_objects(i915); cleanup_objects(i915, &objects);
return err; return err;
} }
...@@ -214,11 +205,12 @@ static int igt_evict_for_vma(void *arg) ...@@ -214,11 +205,12 @@ static int igt_evict_for_vma(void *arg)
.start = 0, .start = 0,
.size = 4096, .size = 4096,
}; };
LIST_HEAD(objects);
int err; int err;
/* Fill the GGTT with pinned objects and try to evict a range. */ /* Fill the GGTT with pinned objects and try to evict a range. */
err = populate_ggtt(i915); err = populate_ggtt(i915, &objects);
if (err) if (err)
goto cleanup; goto cleanup;
...@@ -241,7 +233,7 @@ static int igt_evict_for_vma(void *arg) ...@@ -241,7 +233,7 @@ static int igt_evict_for_vma(void *arg)
} }
cleanup: cleanup:
cleanup_objects(i915); cleanup_objects(i915, &objects);
return err; return err;
} }
...@@ -264,6 +256,7 @@ static int igt_evict_for_cache_color(void *arg) ...@@ -264,6 +256,7 @@ static int igt_evict_for_cache_color(void *arg)
}; };
struct drm_i915_gem_object *obj; struct drm_i915_gem_object *obj;
struct i915_vma *vma; struct i915_vma *vma;
LIST_HEAD(objects);
int err; int err;
/* Currently the use of color_adjust is limited to cache domains within /* Currently the use of color_adjust is limited to cache domains within
...@@ -279,6 +272,7 @@ static int igt_evict_for_cache_color(void *arg) ...@@ -279,6 +272,7 @@ static int igt_evict_for_cache_color(void *arg)
goto cleanup; goto cleanup;
} }
i915_gem_object_set_cache_level(obj, I915_CACHE_LLC); i915_gem_object_set_cache_level(obj, I915_CACHE_LLC);
quirk_add(obj, &objects);
vma = i915_gem_object_ggtt_pin(obj, NULL, 0, 0, vma = i915_gem_object_ggtt_pin(obj, NULL, 0, 0,
I915_GTT_PAGE_SIZE | flags); I915_GTT_PAGE_SIZE | flags);
...@@ -294,6 +288,7 @@ static int igt_evict_for_cache_color(void *arg) ...@@ -294,6 +288,7 @@ static int igt_evict_for_cache_color(void *arg)
goto cleanup; goto cleanup;
} }
i915_gem_object_set_cache_level(obj, I915_CACHE_LLC); i915_gem_object_set_cache_level(obj, I915_CACHE_LLC);
quirk_add(obj, &objects);
/* Neighbouring; same colour - should fit */ /* Neighbouring; same colour - should fit */
vma = i915_gem_object_ggtt_pin(obj, NULL, 0, 0, vma = i915_gem_object_ggtt_pin(obj, NULL, 0, 0,
...@@ -329,7 +324,7 @@ static int igt_evict_for_cache_color(void *arg) ...@@ -329,7 +324,7 @@ static int igt_evict_for_cache_color(void *arg)
cleanup: cleanup:
unpin_ggtt(i915); unpin_ggtt(i915);
cleanup_objects(i915); cleanup_objects(i915, &objects);
ggtt->vm.mm.color_adjust = NULL; ggtt->vm.mm.color_adjust = NULL;
return err; return err;
} }
...@@ -338,11 +333,12 @@ static int igt_evict_vm(void *arg) ...@@ -338,11 +333,12 @@ static int igt_evict_vm(void *arg)
{ {
struct drm_i915_private *i915 = arg; struct drm_i915_private *i915 = arg;
struct i915_ggtt *ggtt = &i915->ggtt; struct i915_ggtt *ggtt = &i915->ggtt;
LIST_HEAD(objects);
int err; int err;
/* Fill the GGTT with pinned objects and try to evict everything. */ /* Fill the GGTT with pinned objects and try to evict everything. */
err = populate_ggtt(i915); err = populate_ggtt(i915, &objects);
if (err) if (err)
goto cleanup; goto cleanup;
...@@ -364,7 +360,7 @@ static int igt_evict_vm(void *arg) ...@@ -364,7 +360,7 @@ static int igt_evict_vm(void *arg)
} }
cleanup: cleanup:
cleanup_objects(i915); cleanup_objects(i915, &objects);
return err; return err;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment