Commit 2271a223 authored by Tvrtko Ursulin's avatar Tvrtko Ursulin Committed by Chris Wilson

drm/i915/selftests: Convert eviction selftests to gt/ggtt

Convert the test code to work directly on what it needs rather than
going through the top-level i915.

This enables another natural usage for for_each_engine(.., gt, ..).
Signed-off-by: default avatarTvrtko Ursulin <tvrtko.ursulin@intel.com>
Reviewed-by: default avatarChris Wilson <chris@chris-wilson.co.uk>
Signed-off-by: default avatarChris Wilson <chris@chris-wilson.co.uk>
Link: https://patchwork.freedesktop.org/patch/msgid/20191022094726.3001-9-tvrtko.ursulin@linux.intel.com
parent 8726a2a4
...@@ -43,8 +43,7 @@ static void quirk_add(struct drm_i915_gem_object *obj, ...@@ -43,8 +43,7 @@ static void quirk_add(struct drm_i915_gem_object *obj,
list_add(&obj->st_link, objects); list_add(&obj->st_link, objects);
} }
static int populate_ggtt(struct drm_i915_private *i915, static int populate_ggtt(struct i915_ggtt *ggtt, struct list_head *objects)
struct list_head *objects)
{ {
unsigned long unbound, bound, count; unsigned long unbound, bound, count;
struct drm_i915_gem_object *obj; struct drm_i915_gem_object *obj;
...@@ -53,7 +52,8 @@ static int populate_ggtt(struct drm_i915_private *i915, ...@@ -53,7 +52,8 @@ static int populate_ggtt(struct drm_i915_private *i915,
do { do {
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(ggtt->vm.i915,
I915_GTT_PAGE_SIZE);
if (IS_ERR(obj)) if (IS_ERR(obj))
return PTR_ERR(obj); return PTR_ERR(obj);
...@@ -70,7 +70,7 @@ static int populate_ggtt(struct drm_i915_private *i915, ...@@ -70,7 +70,7 @@ static int populate_ggtt(struct drm_i915_private *i915,
count++; count++;
} while (1); } while (1);
pr_debug("Filled GGTT with %lu pages [%llu total]\n", pr_debug("Filled GGTT with %lu pages [%llu total]\n",
count, i915->ggtt.vm.total / PAGE_SIZE); count, ggtt->vm.total / PAGE_SIZE);
bound = 0; bound = 0;
unbound = 0; unbound = 0;
...@@ -96,7 +96,7 @@ static int populate_ggtt(struct drm_i915_private *i915, ...@@ -96,7 +96,7 @@ static int populate_ggtt(struct drm_i915_private *i915,
return -EINVAL; return -EINVAL;
} }
if (list_empty(&i915->ggtt.vm.bound_list)) { if (list_empty(&ggtt->vm.bound_list)) {
pr_err("No objects on the GGTT inactive list!\n"); pr_err("No objects on the GGTT inactive list!\n");
return -EINVAL; return -EINVAL;
} }
...@@ -104,17 +104,16 @@ static int populate_ggtt(struct drm_i915_private *i915, ...@@ -104,17 +104,16 @@ static int populate_ggtt(struct drm_i915_private *i915,
return 0; return 0;
} }
static void unpin_ggtt(struct drm_i915_private *i915) static void unpin_ggtt(struct i915_ggtt *ggtt)
{ {
struct i915_vma *vma; struct i915_vma *vma;
list_for_each_entry(vma, &i915->ggtt.vm.bound_list, vm_link) list_for_each_entry(vma, &ggtt->vm.bound_list, vm_link)
if (vma->obj->mm.quirked) if (vma->obj->mm.quirked)
i915_vma_unpin(vma); i915_vma_unpin(vma);
} }
static void cleanup_objects(struct drm_i915_private *i915, static void cleanup_objects(struct i915_ggtt *ggtt, struct list_head *list)
struct list_head *list)
{ {
struct drm_i915_gem_object *obj, *on; struct drm_i915_gem_object *obj, *on;
...@@ -124,19 +123,19 @@ static void cleanup_objects(struct drm_i915_private *i915, ...@@ -124,19 +123,19 @@ static void cleanup_objects(struct drm_i915_private *i915,
i915_gem_object_put(obj); i915_gem_object_put(obj);
} }
i915_gem_drain_freed_objects(i915); i915_gem_drain_freed_objects(ggtt->vm.i915);
} }
static int igt_evict_something(void *arg) static int igt_evict_something(void *arg)
{ {
struct drm_i915_private *i915 = arg; struct intel_gt *gt = arg;
struct i915_ggtt *ggtt = &i915->ggtt; struct i915_ggtt *ggtt = gt->ggtt;
LIST_HEAD(objects); 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, &objects); err = populate_ggtt(ggtt, &objects);
if (err) if (err)
goto cleanup; goto cleanup;
...@@ -153,7 +152,7 @@ static int igt_evict_something(void *arg) ...@@ -153,7 +152,7 @@ static int igt_evict_something(void *arg)
goto cleanup; goto cleanup;
} }
unpin_ggtt(i915); unpin_ggtt(ggtt);
/* Everything is unpinned, we should be able to evict something */ /* Everything is unpinned, we should be able to evict something */
mutex_lock(&ggtt->vm.mutex); mutex_lock(&ggtt->vm.mutex);
...@@ -169,13 +168,14 @@ static int igt_evict_something(void *arg) ...@@ -169,13 +168,14 @@ static int igt_evict_something(void *arg)
} }
cleanup: cleanup:
cleanup_objects(i915, &objects); cleanup_objects(ggtt, &objects);
return err; return err;
} }
static int igt_overcommit(void *arg) static int igt_overcommit(void *arg)
{ {
struct drm_i915_private *i915 = arg; struct intel_gt *gt = arg;
struct i915_ggtt *ggtt = gt->ggtt;
struct drm_i915_gem_object *obj; struct drm_i915_gem_object *obj;
struct i915_vma *vma; struct i915_vma *vma;
LIST_HEAD(objects); LIST_HEAD(objects);
...@@ -185,11 +185,11 @@ static int igt_overcommit(void *arg) ...@@ -185,11 +185,11 @@ static int igt_overcommit(void *arg)
* We expect it to fail. * We expect it to fail.
*/ */
err = populate_ggtt(i915, &objects); err = populate_ggtt(ggtt, &objects);
if (err) if (err)
goto cleanup; goto cleanup;
obj = i915_gem_object_create_internal(i915, I915_GTT_PAGE_SIZE); obj = i915_gem_object_create_internal(gt->i915, I915_GTT_PAGE_SIZE);
if (IS_ERR(obj)) { if (IS_ERR(obj)) {
err = PTR_ERR(obj); err = PTR_ERR(obj);
goto cleanup; goto cleanup;
...@@ -205,14 +205,14 @@ static int igt_overcommit(void *arg) ...@@ -205,14 +205,14 @@ static int igt_overcommit(void *arg)
} }
cleanup: cleanup:
cleanup_objects(i915, &objects); cleanup_objects(ggtt, &objects);
return err; return err;
} }
static int igt_evict_for_vma(void *arg) static int igt_evict_for_vma(void *arg)
{ {
struct drm_i915_private *i915 = arg; struct intel_gt *gt = arg;
struct i915_ggtt *ggtt = &i915->ggtt; struct i915_ggtt *ggtt = gt->ggtt;
struct drm_mm_node target = { struct drm_mm_node target = {
.start = 0, .start = 0,
.size = 4096, .size = 4096,
...@@ -222,7 +222,7 @@ static int igt_evict_for_vma(void *arg) ...@@ -222,7 +222,7 @@ static int igt_evict_for_vma(void *arg)
/* 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, &objects); err = populate_ggtt(ggtt, &objects);
if (err) if (err)
goto cleanup; goto cleanup;
...@@ -236,7 +236,7 @@ static int igt_evict_for_vma(void *arg) ...@@ -236,7 +236,7 @@ static int igt_evict_for_vma(void *arg)
goto cleanup; goto cleanup;
} }
unpin_ggtt(i915); unpin_ggtt(ggtt);
/* Everything is unpinned, we should be able to evict the node */ /* Everything is unpinned, we should be able to evict the node */
mutex_lock(&ggtt->vm.mutex); mutex_lock(&ggtt->vm.mutex);
...@@ -249,7 +249,7 @@ static int igt_evict_for_vma(void *arg) ...@@ -249,7 +249,7 @@ static int igt_evict_for_vma(void *arg)
} }
cleanup: cleanup:
cleanup_objects(i915, &objects); cleanup_objects(ggtt, &objects);
return err; return err;
} }
...@@ -262,8 +262,8 @@ static void mock_color_adjust(const struct drm_mm_node *node, ...@@ -262,8 +262,8 @@ static void mock_color_adjust(const struct drm_mm_node *node,
static int igt_evict_for_cache_color(void *arg) static int igt_evict_for_cache_color(void *arg)
{ {
struct drm_i915_private *i915 = arg; struct intel_gt *gt = arg;
struct i915_ggtt *ggtt = &i915->ggtt; struct i915_ggtt *ggtt = gt->ggtt;
const unsigned long flags = PIN_OFFSET_FIXED; const unsigned long flags = PIN_OFFSET_FIXED;
struct drm_mm_node target = { struct drm_mm_node target = {
.start = I915_GTT_PAGE_SIZE * 2, .start = I915_GTT_PAGE_SIZE * 2,
...@@ -284,7 +284,7 @@ static int igt_evict_for_cache_color(void *arg) ...@@ -284,7 +284,7 @@ static int igt_evict_for_cache_color(void *arg)
ggtt->vm.mm.color_adjust = mock_color_adjust; ggtt->vm.mm.color_adjust = mock_color_adjust;
GEM_BUG_ON(!i915_vm_has_cache_coloring(&ggtt->vm)); GEM_BUG_ON(!i915_vm_has_cache_coloring(&ggtt->vm));
obj = i915_gem_object_create_internal(i915, I915_GTT_PAGE_SIZE); obj = i915_gem_object_create_internal(gt->i915, I915_GTT_PAGE_SIZE);
if (IS_ERR(obj)) { if (IS_ERR(obj)) {
err = PTR_ERR(obj); err = PTR_ERR(obj);
goto cleanup; goto cleanup;
...@@ -300,7 +300,7 @@ static int igt_evict_for_cache_color(void *arg) ...@@ -300,7 +300,7 @@ static int igt_evict_for_cache_color(void *arg)
goto cleanup; goto cleanup;
} }
obj = i915_gem_object_create_internal(i915, I915_GTT_PAGE_SIZE); obj = i915_gem_object_create_internal(gt->i915, I915_GTT_PAGE_SIZE);
if (IS_ERR(obj)) { if (IS_ERR(obj)) {
err = PTR_ERR(obj); err = PTR_ERR(obj);
goto cleanup; goto cleanup;
...@@ -345,22 +345,22 @@ static int igt_evict_for_cache_color(void *arg) ...@@ -345,22 +345,22 @@ static int igt_evict_for_cache_color(void *arg)
err = 0; err = 0;
cleanup: cleanup:
unpin_ggtt(i915); unpin_ggtt(ggtt);
cleanup_objects(i915, &objects); cleanup_objects(ggtt, &objects);
ggtt->vm.mm.color_adjust = NULL; ggtt->vm.mm.color_adjust = NULL;
return err; return err;
} }
static int igt_evict_vm(void *arg) static int igt_evict_vm(void *arg)
{ {
struct drm_i915_private *i915 = arg; struct intel_gt *gt = arg;
struct i915_ggtt *ggtt = &i915->ggtt; struct i915_ggtt *ggtt = gt->ggtt;
LIST_HEAD(objects); 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, &objects); err = populate_ggtt(ggtt, &objects);
if (err) if (err)
goto cleanup; goto cleanup;
...@@ -374,7 +374,7 @@ static int igt_evict_vm(void *arg) ...@@ -374,7 +374,7 @@ static int igt_evict_vm(void *arg)
goto cleanup; goto cleanup;
} }
unpin_ggtt(i915); unpin_ggtt(ggtt);
mutex_lock(&ggtt->vm.mutex); mutex_lock(&ggtt->vm.mutex);
err = i915_gem_evict_vm(&ggtt->vm); err = i915_gem_evict_vm(&ggtt->vm);
...@@ -386,14 +386,16 @@ static int igt_evict_vm(void *arg) ...@@ -386,14 +386,16 @@ static int igt_evict_vm(void *arg)
} }
cleanup: cleanup:
cleanup_objects(i915, &objects); cleanup_objects(ggtt, &objects);
return err; return err;
} }
static int igt_evict_contexts(void *arg) static int igt_evict_contexts(void *arg)
{ {
const u64 PRETEND_GGTT_SIZE = 16ull << 20; const u64 PRETEND_GGTT_SIZE = 16ull << 20;
struct drm_i915_private *i915 = arg; struct intel_gt *gt = arg;
struct i915_ggtt *ggtt = gt->ggtt;
struct drm_i915_private *i915 = gt->i915;
struct intel_engine_cs *engine; struct intel_engine_cs *engine;
enum intel_engine_id id; enum intel_engine_id id;
struct reserved { struct reserved {
...@@ -423,10 +425,10 @@ static int igt_evict_contexts(void *arg) ...@@ -423,10 +425,10 @@ static int igt_evict_contexts(void *arg)
/* Reserve a block so that we know we have enough to fit a few rq */ /* Reserve a block so that we know we have enough to fit a few rq */
memset(&hole, 0, sizeof(hole)); memset(&hole, 0, sizeof(hole));
mutex_lock(&i915->ggtt.vm.mutex); mutex_lock(&ggtt->vm.mutex);
err = i915_gem_gtt_insert(&i915->ggtt.vm, &hole, err = i915_gem_gtt_insert(&ggtt->vm, &hole,
PRETEND_GGTT_SIZE, 0, I915_COLOR_UNEVICTABLE, PRETEND_GGTT_SIZE, 0, I915_COLOR_UNEVICTABLE,
0, i915->ggtt.vm.total, 0, ggtt->vm.total,
PIN_NOEVICT); PIN_NOEVICT);
if (err) if (err)
goto out_locked; goto out_locked;
...@@ -436,17 +438,17 @@ static int igt_evict_contexts(void *arg) ...@@ -436,17 +438,17 @@ static int igt_evict_contexts(void *arg)
do { do {
struct reserved *r; struct reserved *r;
mutex_unlock(&i915->ggtt.vm.mutex); mutex_unlock(&ggtt->vm.mutex);
r = kcalloc(1, sizeof(*r), GFP_KERNEL); r = kcalloc(1, sizeof(*r), GFP_KERNEL);
mutex_lock(&i915->ggtt.vm.mutex); mutex_lock(&ggtt->vm.mutex);
if (!r) { if (!r) {
err = -ENOMEM; err = -ENOMEM;
goto out_locked; goto out_locked;
} }
if (i915_gem_gtt_insert(&i915->ggtt.vm, &r->node, if (i915_gem_gtt_insert(&ggtt->vm, &r->node,
1ul << 20, 0, I915_COLOR_UNEVICTABLE, 1ul << 20, 0, I915_COLOR_UNEVICTABLE,
0, i915->ggtt.vm.total, 0, ggtt->vm.total,
PIN_NOEVICT)) { PIN_NOEVICT)) {
kfree(r); kfree(r);
break; break;
...@@ -458,11 +460,11 @@ static int igt_evict_contexts(void *arg) ...@@ -458,11 +460,11 @@ static int igt_evict_contexts(void *arg)
count++; count++;
} while (1); } while (1);
drm_mm_remove_node(&hole); drm_mm_remove_node(&hole);
mutex_unlock(&i915->ggtt.vm.mutex); mutex_unlock(&ggtt->vm.mutex);
pr_info("Filled GGTT with %lu 1MiB nodes\n", count); pr_info("Filled GGTT with %lu 1MiB nodes\n", count);
/* Overfill the GGTT with context objects and so try to evict one. */ /* Overfill the GGTT with context objects and so try to evict one. */
for_each_engine(engine, i915, id) { for_each_engine(engine, gt, id) {
struct i915_sw_fence fence; struct i915_sw_fence fence;
struct drm_file *file; struct drm_file *file;
...@@ -518,7 +520,7 @@ static int igt_evict_contexts(void *arg) ...@@ -518,7 +520,7 @@ static int igt_evict_contexts(void *arg)
break; break;
} }
mutex_lock(&i915->ggtt.vm.mutex); mutex_lock(&ggtt->vm.mutex);
out_locked: out_locked:
if (igt_flush_test(i915)) if (igt_flush_test(i915))
err = -EIO; err = -EIO;
...@@ -532,7 +534,7 @@ static int igt_evict_contexts(void *arg) ...@@ -532,7 +534,7 @@ static int igt_evict_contexts(void *arg)
} }
if (drm_mm_node_allocated(&hole)) if (drm_mm_node_allocated(&hole))
drm_mm_remove_node(&hole); drm_mm_remove_node(&hole);
mutex_unlock(&i915->ggtt.vm.mutex); mutex_unlock(&ggtt->vm.mutex);
intel_runtime_pm_put(&i915->runtime_pm, wakeref); intel_runtime_pm_put(&i915->runtime_pm, wakeref);
return err; return err;
...@@ -556,7 +558,7 @@ int i915_gem_evict_mock_selftests(void) ...@@ -556,7 +558,7 @@ int i915_gem_evict_mock_selftests(void)
return -ENOMEM; return -ENOMEM;
with_intel_runtime_pm(&i915->runtime_pm, wakeref) with_intel_runtime_pm(&i915->runtime_pm, wakeref)
err = i915_subtests(tests, i915); err = i915_subtests(tests, &i915->gt);
drm_dev_put(&i915->drm); drm_dev_put(&i915->drm);
return err; return err;
...@@ -571,5 +573,5 @@ int i915_gem_evict_live_selftests(struct drm_i915_private *i915) ...@@ -571,5 +573,5 @@ int i915_gem_evict_live_selftests(struct drm_i915_private *i915)
if (intel_gt_is_wedged(&i915->gt)) if (intel_gt_is_wedged(&i915->gt))
return 0; return 0;
return i915_subtests(tests, i915); return intel_gt_live_subtests(tests, &i915->gt);
} }
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