Commit 63251685 authored by Chris Wilson's avatar Chris Wilson

drm/i915/selftests: Common live setup/teardown

We frequently, but not frequently enough!, remember to flush residual
operations and objects at the end of a live subtest. The purpose is to
cleanup after every subtest, leaving a clean slate for the next subtest,
and perform early detection of leaky state. As this should ideally be
common for all live subtests, pull the task into a common teardown
routine.
Signed-off-by: default avatarChris Wilson <chris@chris-wilson.co.uk>
Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Reviewed-by: default avatarMatthew Auld <matthew.auld@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20190703091726.11690-1-chris@chris-wilson.co.uk
parent 8e9ecb3e
...@@ -11,8 +11,8 @@ ...@@ -11,8 +11,8 @@
static int igt_client_fill(void *arg) static int igt_client_fill(void *arg)
{ {
struct intel_context *ce = arg; struct drm_i915_private *i915 = arg;
struct drm_i915_private *i915 = ce->gem_context->i915; struct intel_context *ce = i915->engine[BCS0]->kernel_context;
struct drm_i915_gem_object *obj; struct drm_i915_gem_object *obj;
struct rnd_state prng; struct rnd_state prng;
IGT_TIMEOUT(end); IGT_TIMEOUT(end);
...@@ -89,11 +89,6 @@ static int igt_client_fill(void *arg) ...@@ -89,11 +89,6 @@ static int igt_client_fill(void *arg)
err_put: err_put:
i915_gem_object_put(obj); i915_gem_object_put(obj);
err_flush: err_flush:
mutex_lock(&i915->drm.struct_mutex);
if (igt_flush_test(i915, I915_WAIT_LOCKED))
err = -EIO;
mutex_unlock(&i915->drm.struct_mutex);
if (err == -ENOMEM) if (err == -ENOMEM)
err = 0; err = 0;
...@@ -112,5 +107,5 @@ int i915_gem_client_blt_live_selftests(struct drm_i915_private *i915) ...@@ -112,5 +107,5 @@ int i915_gem_client_blt_live_selftests(struct drm_i915_private *i915)
if (!HAS_ENGINE(i915, BCS0)) if (!HAS_ENGINE(i915, BCS0))
return 0; return 0;
return i915_subtests(tests, i915->engine[BCS0]->kernel_context); return i915_live_subtests(tests, i915);
} }
...@@ -1731,5 +1731,5 @@ int i915_gem_context_live_selftests(struct drm_i915_private *dev_priv) ...@@ -1731,5 +1731,5 @@ int i915_gem_context_live_selftests(struct drm_i915_private *dev_priv)
if (i915_terminally_wedged(dev_priv)) if (i915_terminally_wedged(dev_priv))
return 0; return 0;
return i915_subtests(tests, dev_priv); return i915_live_subtests(tests, dev_priv);
} }
...@@ -11,8 +11,8 @@ ...@@ -11,8 +11,8 @@
static int igt_fill_blt(void *arg) static int igt_fill_blt(void *arg)
{ {
struct intel_context *ce = arg; struct drm_i915_private *i915 = arg;
struct drm_i915_private *i915 = ce->gem_context->i915; struct intel_context *ce = i915->engine[BCS0]->kernel_context;
struct drm_i915_gem_object *obj; struct drm_i915_gem_object *obj;
struct rnd_state prng; struct rnd_state prng;
IGT_TIMEOUT(end); IGT_TIMEOUT(end);
...@@ -83,11 +83,6 @@ static int igt_fill_blt(void *arg) ...@@ -83,11 +83,6 @@ static int igt_fill_blt(void *arg)
err_put: err_put:
i915_gem_object_put(obj); i915_gem_object_put(obj);
err_flush: err_flush:
mutex_lock(&i915->drm.struct_mutex);
if (igt_flush_test(i915, I915_WAIT_LOCKED))
err = -EIO;
mutex_unlock(&i915->drm.struct_mutex);
if (err == -ENOMEM) if (err == -ENOMEM)
err = 0; err = 0;
...@@ -106,5 +101,5 @@ int i915_gem_object_blt_live_selftests(struct drm_i915_private *i915) ...@@ -106,5 +101,5 @@ int i915_gem_object_blt_live_selftests(struct drm_i915_private *i915)
if (!HAS_ENGINE(i915, BCS0)) if (!HAS_ENGINE(i915, BCS0))
return 0; return 0;
return i915_subtests(tests, i915->engine[BCS0]->kernel_context); return i915_live_subtests(tests, i915);
} }
...@@ -1744,7 +1744,7 @@ int intel_hangcheck_live_selftests(struct drm_i915_private *i915) ...@@ -1744,7 +1744,7 @@ int intel_hangcheck_live_selftests(struct drm_i915_private *i915)
saved_hangcheck = fetch_and_zero(&i915_modparams.enable_hangcheck); saved_hangcheck = fetch_and_zero(&i915_modparams.enable_hangcheck);
drain_delayed_work(&i915->gpu_error.hangcheck_work); /* flush param */ drain_delayed_work(&i915->gpu_error.hangcheck_work); /* flush param */
err = i915_subtests(tests, i915); err = i915_live_subtests(tests, i915);
mutex_lock(&i915->drm.struct_mutex); mutex_lock(&i915->drm.struct_mutex);
igt_flush_test(i915, I915_WAIT_LOCKED); igt_flush_test(i915, I915_WAIT_LOCKED);
......
...@@ -73,7 +73,6 @@ static int live_sanitycheck(void *arg) ...@@ -73,7 +73,6 @@ static int live_sanitycheck(void *arg)
err_spin: err_spin:
igt_spinner_fini(&spin); igt_spinner_fini(&spin);
err_unlock: err_unlock:
igt_flush_test(i915, I915_WAIT_LOCKED);
intel_runtime_pm_put(&i915->runtime_pm, wakeref); intel_runtime_pm_put(&i915->runtime_pm, wakeref);
mutex_unlock(&i915->drm.struct_mutex); mutex_unlock(&i915->drm.struct_mutex);
return err; return err;
...@@ -290,8 +289,6 @@ static int live_timeslice_preempt(void *arg) ...@@ -290,8 +289,6 @@ static int live_timeslice_preempt(void *arg)
err_obj: err_obj:
i915_gem_object_put(obj); i915_gem_object_put(obj);
err_unlock: err_unlock:
if (igt_flush_test(i915, I915_WAIT_LOCKED))
err = -EIO;
intel_runtime_pm_put(&i915->runtime_pm, wakeref); intel_runtime_pm_put(&i915->runtime_pm, wakeref);
mutex_unlock(&i915->drm.struct_mutex); mutex_unlock(&i915->drm.struct_mutex);
...@@ -472,8 +469,6 @@ static int live_busywait_preempt(void *arg) ...@@ -472,8 +469,6 @@ static int live_busywait_preempt(void *arg)
err_ctx_hi: err_ctx_hi:
kernel_context_close(ctx_hi); kernel_context_close(ctx_hi);
err_unlock: err_unlock:
if (igt_flush_test(i915, I915_WAIT_LOCKED))
err = -EIO;
intel_runtime_pm_put(&i915->runtime_pm, wakeref); intel_runtime_pm_put(&i915->runtime_pm, wakeref);
mutex_unlock(&i915->drm.struct_mutex); mutex_unlock(&i915->drm.struct_mutex);
return err; return err;
...@@ -580,7 +575,6 @@ static int live_preempt(void *arg) ...@@ -580,7 +575,6 @@ static int live_preempt(void *arg)
err_spin_hi: err_spin_hi:
igt_spinner_fini(&spin_hi); igt_spinner_fini(&spin_hi);
err_unlock: err_unlock:
igt_flush_test(i915, I915_WAIT_LOCKED);
intel_runtime_pm_put(&i915->runtime_pm, wakeref); intel_runtime_pm_put(&i915->runtime_pm, wakeref);
mutex_unlock(&i915->drm.struct_mutex); mutex_unlock(&i915->drm.struct_mutex);
return err; return err;
...@@ -687,7 +681,6 @@ static int live_late_preempt(void *arg) ...@@ -687,7 +681,6 @@ static int live_late_preempt(void *arg)
err_spin_hi: err_spin_hi:
igt_spinner_fini(&spin_hi); igt_spinner_fini(&spin_hi);
err_unlock: err_unlock:
igt_flush_test(i915, I915_WAIT_LOCKED);
intel_runtime_pm_put(&i915->runtime_pm, wakeref); intel_runtime_pm_put(&i915->runtime_pm, wakeref);
mutex_unlock(&i915->drm.struct_mutex); mutex_unlock(&i915->drm.struct_mutex);
return err; return err;
...@@ -826,8 +819,6 @@ static int live_suppress_self_preempt(void *arg) ...@@ -826,8 +819,6 @@ static int live_suppress_self_preempt(void *arg)
err_client_a: err_client_a:
preempt_client_fini(&a); preempt_client_fini(&a);
err_unlock: err_unlock:
if (igt_flush_test(i915, I915_WAIT_LOCKED))
err = -EIO;
intel_runtime_pm_put(&i915->runtime_pm, wakeref); intel_runtime_pm_put(&i915->runtime_pm, wakeref);
mutex_unlock(&i915->drm.struct_mutex); mutex_unlock(&i915->drm.struct_mutex);
return err; return err;
...@@ -995,8 +986,6 @@ static int live_suppress_wait_preempt(void *arg) ...@@ -995,8 +986,6 @@ static int live_suppress_wait_preempt(void *arg)
err_client_0: err_client_0:
preempt_client_fini(&client[0]); preempt_client_fini(&client[0]);
err_unlock: err_unlock:
if (igt_flush_test(i915, I915_WAIT_LOCKED))
err = -EIO;
intel_runtime_pm_put(&i915->runtime_pm, wakeref); intel_runtime_pm_put(&i915->runtime_pm, wakeref);
mutex_unlock(&i915->drm.struct_mutex); mutex_unlock(&i915->drm.struct_mutex);
return err; return err;
...@@ -1143,8 +1132,6 @@ static int live_chain_preempt(void *arg) ...@@ -1143,8 +1132,6 @@ static int live_chain_preempt(void *arg)
err_client_hi: err_client_hi:
preempt_client_fini(&hi); preempt_client_fini(&hi);
err_unlock: err_unlock:
if (igt_flush_test(i915, I915_WAIT_LOCKED))
err = -EIO;
intel_runtime_pm_put(&i915->runtime_pm, wakeref); intel_runtime_pm_put(&i915->runtime_pm, wakeref);
mutex_unlock(&i915->drm.struct_mutex); mutex_unlock(&i915->drm.struct_mutex);
return err; return err;
...@@ -1270,7 +1257,6 @@ static int live_preempt_hang(void *arg) ...@@ -1270,7 +1257,6 @@ static int live_preempt_hang(void *arg)
err_spin_hi: err_spin_hi:
igt_spinner_fini(&spin_hi); igt_spinner_fini(&spin_hi);
err_unlock: err_unlock:
igt_flush_test(i915, I915_WAIT_LOCKED);
intel_runtime_pm_put(&i915->runtime_pm, wakeref); intel_runtime_pm_put(&i915->runtime_pm, wakeref);
mutex_unlock(&i915->drm.struct_mutex); mutex_unlock(&i915->drm.struct_mutex);
return err; return err;
...@@ -2054,5 +2040,5 @@ int intel_execlists_live_selftests(struct drm_i915_private *i915) ...@@ -2054,5 +2040,5 @@ int intel_execlists_live_selftests(struct drm_i915_private *i915)
if (i915_terminally_wedged(i915)) if (i915_terminally_wedged(i915))
return 0; return 0;
return i915_subtests(tests, i915); return i915_live_subtests(tests, i915);
} }
...@@ -821,8 +821,6 @@ static int live_hwsp_recycle(void *arg) ...@@ -821,8 +821,6 @@ static int live_hwsp_recycle(void *arg)
} }
out: out:
if (igt_flush_test(i915, I915_WAIT_LOCKED))
err = -EIO;
intel_runtime_pm_put(&i915->runtime_pm, wakeref); intel_runtime_pm_put(&i915->runtime_pm, wakeref);
mutex_unlock(&i915->drm.struct_mutex); mutex_unlock(&i915->drm.struct_mutex);
...@@ -841,5 +839,5 @@ int intel_timeline_live_selftests(struct drm_i915_private *i915) ...@@ -841,5 +839,5 @@ int intel_timeline_live_selftests(struct drm_i915_private *i915)
if (i915_terminally_wedged(i915)) if (i915_terminally_wedged(i915))
return 0; return 0;
return i915_subtests(tests, i915); return i915_live_subtests(tests, i915);
} }
...@@ -66,12 +66,28 @@ struct i915_subtest { ...@@ -66,12 +66,28 @@ struct i915_subtest {
const char *name; const char *name;
}; };
int __i915_nop_setup(void *data);
int __i915_nop_teardown(int err, void *data);
int __i915_live_setup(void *data);
int __i915_live_teardown(int err, void *data);
int __i915_subtests(const char *caller, int __i915_subtests(const char *caller,
int (*setup)(void *data),
int (*teardown)(int err, void *data),
const struct i915_subtest *st, const struct i915_subtest *st,
unsigned int count, unsigned int count,
void *data); void *data);
#define i915_subtests(T, data) \ #define i915_subtests(T, data) \
__i915_subtests(__func__, T, ARRAY_SIZE(T), data) __i915_subtests(__func__, \
__i915_nop_setup, __i915_nop_teardown, \
T, ARRAY_SIZE(T), data)
#define i915_live_subtests(T, data) ({ \
typecheck(struct drm_i915_private *, data); \
__i915_subtests(__func__, \
__i915_live_setup, __i915_live_teardown, \
T, ARRAY_SIZE(T), data); \
})
#define SUBTEST(x) { x, #x } #define SUBTEST(x) { x, #x }
......
...@@ -154,8 +154,6 @@ static int igt_gem_suspend(void *arg) ...@@ -154,8 +154,6 @@ static int igt_gem_suspend(void *arg)
mutex_lock(&i915->drm.struct_mutex); mutex_lock(&i915->drm.struct_mutex);
err = switch_to_context(i915, ctx); err = switch_to_context(i915, ctx);
if (igt_flush_test(i915, I915_WAIT_LOCKED))
err = -EIO;
mutex_unlock(&i915->drm.struct_mutex); mutex_unlock(&i915->drm.struct_mutex);
out: out:
mock_file_free(i915, file); mock_file_free(i915, file);
...@@ -195,8 +193,6 @@ static int igt_gem_hibernate(void *arg) ...@@ -195,8 +193,6 @@ static int igt_gem_hibernate(void *arg)
mutex_lock(&i915->drm.struct_mutex); mutex_lock(&i915->drm.struct_mutex);
err = switch_to_context(i915, ctx); err = switch_to_context(i915, ctx);
if (igt_flush_test(i915, I915_WAIT_LOCKED))
err = -EIO;
mutex_unlock(&i915->drm.struct_mutex); mutex_unlock(&i915->drm.struct_mutex);
out: out:
mock_file_free(i915, file); mock_file_free(i915, file);
...@@ -213,5 +209,5 @@ int i915_gem_live_selftests(struct drm_i915_private *i915) ...@@ -213,5 +209,5 @@ int i915_gem_live_selftests(struct drm_i915_private *i915)
if (i915_terminally_wedged(i915)) if (i915_terminally_wedged(i915))
return 0; return 0;
return i915_subtests(tests, i915); return i915_live_subtests(tests, i915);
} }
...@@ -26,6 +26,8 @@ ...@@ -26,6 +26,8 @@
#include "../i915_drv.h" #include "../i915_drv.h"
#include "../i915_selftest.h" #include "../i915_selftest.h"
#include "igt_flush_test.h"
struct i915_selftest i915_selftest __read_mostly = { struct i915_selftest i915_selftest __read_mostly = {
.timeout_ms = 1000, .timeout_ms = 1000,
}; };
...@@ -240,7 +242,40 @@ static bool apply_subtest_filter(const char *caller, const char *name) ...@@ -240,7 +242,40 @@ static bool apply_subtest_filter(const char *caller, const char *name)
return result; return result;
} }
int __i915_nop_setup(void *data)
{
return 0;
}
int __i915_nop_teardown(int err, void *data)
{
return err;
}
int __i915_live_setup(void *data)
{
struct drm_i915_private *i915 = data;
return i915_terminally_wedged(i915);
}
int __i915_live_teardown(int err, void *data)
{
struct drm_i915_private *i915 = data;
mutex_lock(&i915->drm.struct_mutex);
if (igt_flush_test(i915, I915_WAIT_LOCKED))
err = -EIO;
mutex_unlock(&i915->drm.struct_mutex);
i915_gem_drain_freed_objects(i915);
return err;
}
int __i915_subtests(const char *caller, int __i915_subtests(const char *caller,
int (*setup)(void *data),
int (*teardown)(int err, void *data),
const struct i915_subtest *st, const struct i915_subtest *st,
unsigned int count, unsigned int count,
void *data) void *data)
...@@ -255,10 +290,17 @@ int __i915_subtests(const char *caller, ...@@ -255,10 +290,17 @@ int __i915_subtests(const char *caller,
if (!apply_subtest_filter(caller, st->name)) if (!apply_subtest_filter(caller, st->name))
continue; continue;
err = setup(data);
if (err) {
pr_err(DRIVER_NAME "/%s: setup failed for %s\n",
caller, st->name);
return err;
}
pr_info(DRIVER_NAME ": Running %s/%s\n", caller, st->name); pr_info(DRIVER_NAME ": Running %s/%s\n", caller, st->name);
GEM_TRACE("Running %s/%s\n", caller, st->name); GEM_TRACE("Running %s/%s\n", caller, st->name);
err = st->func(data); err = teardown(st->func(data), data);
if (err && err != -EINTR) { if (err && err != -EINTR) {
pr_err(DRIVER_NAME "/%s: %s failed with error %d\n", pr_err(DRIVER_NAME "/%s: %s failed with error %d\n",
caller, st->name, err); caller, st->name, 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