Commit 2835f4f3 authored by Chris Wilson's avatar Chris Wilson

drm/i915/selftests: Improve switch-to-kernel-context checking

We can reduce the switch-to-kernel-context selftest to operate as a loop
and so trivially test another state transition (that of idle->busy).
Signed-off-by: default avatarChris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: default avatarTvrtko Ursulin <tvrtko.ursulin@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20190307211947.6954-1-chris@chris-wilson.co.uk
parent b185a352
...@@ -1493,9 +1493,14 @@ static int __igt_switch_to_kernel_context(struct drm_i915_private *i915, ...@@ -1493,9 +1493,14 @@ static int __igt_switch_to_kernel_context(struct drm_i915_private *i915,
{ {
struct intel_engine_cs *engine; struct intel_engine_cs *engine;
unsigned int tmp; unsigned int tmp;
int err; int pass;
GEM_TRACE("Testing %s\n", __engine_name(i915, engines)); GEM_TRACE("Testing %s\n", __engine_name(i915, engines));
for (pass = 0; pass < 4; pass++) { /* Once busy; once idle; repeat */
bool from_idle = pass & 1;
int err;
if (!from_idle) {
for_each_engine_masked(engine, i915, engines, tmp) { for_each_engine_masked(engine, i915, engines, tmp) {
struct i915_request *rq; struct i915_request *rq;
...@@ -1505,52 +1510,39 @@ static int __igt_switch_to_kernel_context(struct drm_i915_private *i915, ...@@ -1505,52 +1510,39 @@ static int __igt_switch_to_kernel_context(struct drm_i915_private *i915,
i915_request_add(rq); i915_request_add(rq);
} }
}
err = i915_gem_switch_to_kernel_context(i915); err = i915_gem_switch_to_kernel_context(i915);
if (err) if (err)
return err; return err;
for_each_engine_masked(engine, i915, engines, tmp) { if (!from_idle) {
if (!engine_has_kernel_context_barrier(engine)) {
pr_err("kernel context not last on engine %s!\n",
engine->name);
return -EINVAL;
}
}
err = i915_gem_wait_for_idle(i915, err = i915_gem_wait_for_idle(i915,
I915_WAIT_LOCKED, I915_WAIT_LOCKED,
MAX_SCHEDULE_TIMEOUT); MAX_SCHEDULE_TIMEOUT);
if (err) if (err)
return err; return err;
GEM_BUG_ON(i915->gt.active_requests);
for_each_engine_masked(engine, i915, engines, tmp) {
if (engine->last_retired_context->gem_context != i915->kernel_context) {
pr_err("engine %s not idling in kernel context!\n",
engine->name);
return -EINVAL;
}
} }
err = i915_gem_switch_to_kernel_context(i915);
if (err)
return err;
if (i915->gt.active_requests) { if (i915->gt.active_requests) {
pr_err("switch-to-kernel-context emitted %d requests even though it should already be idling in the kernel context\n", pr_err("%d active requests remain after switching to kernel context, pass %d (%s) on %s engine%s\n",
i915->gt.active_requests); i915->gt.active_requests,
pass, from_idle ? "idle" : "busy",
__engine_name(i915, engines),
is_power_of_2(engines) ? "" : "s");
return -EINVAL; return -EINVAL;
} }
for_each_engine_masked(engine, i915, engines, tmp) { /* XXX Bonus points for proving we are the kernel context! */
if (!intel_engine_has_kernel_context(engine)) {
pr_err("kernel context not last on engine %s!\n", mutex_unlock(&i915->drm.struct_mutex);
engine->name); drain_delayed_work(&i915->gt.idle_work);
return -EINVAL; mutex_lock(&i915->drm.struct_mutex);
}
} }
if (igt_flush_test(i915, I915_WAIT_LOCKED))
return -EIO;
return 0; return 0;
} }
...@@ -1593,8 +1585,6 @@ static int igt_switch_to_kernel_context(void *arg) ...@@ -1593,8 +1585,6 @@ static int igt_switch_to_kernel_context(void *arg)
out_unlock: out_unlock:
GEM_TRACE_DUMP_ON(err); GEM_TRACE_DUMP_ON(err);
if (igt_flush_test(i915, I915_WAIT_LOCKED))
err = -EIO;
intel_runtime_pm_put(i915, wakeref); intel_runtime_pm_put(i915, wakeref);
mutex_unlock(&i915->drm.struct_mutex); mutex_unlock(&i915->drm.struct_mutex);
......
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