Commit ec625fb9 authored by Chris Wilson's avatar Chris Wilson

drm/i915: Provide a timeout to i915_gem_wait_for_idle()

Usually we have no idea about the upper bound we need to wait to catch
up with userspace when idling the device, but in a few situations we
know the system was idle beforehand and can provide a short timeout in
order to very quickly catch a failure, long before hangcheck kicks in.

In the following patches, we will use the timeout to curtain two overly
long waits, where we know we can expect the GPU to complete within a
reasonable time or declare it broken.

In particular, with a broken GPU we expect it to fail during the initial
GPU setup where do a couple of context switches to record the defaults.
This is a task that takes a few milliseconds even on the slowest of
devices, but we may have to wait 60s for hangcheck to give in and
declare the machine inoperable. In this a case where any gpu hang is
unacceptable, both from a timeliness and practical standpoint.

The other improvement is that in selftests, we do not need to arm an
independent timer to inject a wedge, as we can just limit the timeout on
the wait directly.

v2: Include the timeout parameter in the trace.
Signed-off-by: default avatarChris Wilson <chris@chris-wilson.co.uk>
Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Cc: Mika Kuoppala <mika.kuoppala@linux.intel.com>
Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Reviewed-by: default avatarMika Kuoppala <mika.kuoppala@linux.intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20180709122044.7028-1-chris@chris-wilson.co.uk
parent e1479132
...@@ -4105,7 +4105,8 @@ fault_irq_set(struct drm_i915_private *i915, ...@@ -4105,7 +4105,8 @@ fault_irq_set(struct drm_i915_private *i915,
err = i915_gem_wait_for_idle(i915, err = i915_gem_wait_for_idle(i915,
I915_WAIT_LOCKED | I915_WAIT_LOCKED |
I915_WAIT_INTERRUPTIBLE); I915_WAIT_INTERRUPTIBLE,
MAX_SCHEDULE_TIMEOUT);
if (err) if (err)
goto err_unlock; goto err_unlock;
...@@ -4210,7 +4211,8 @@ i915_drop_caches_set(void *data, u64 val) ...@@ -4210,7 +4211,8 @@ i915_drop_caches_set(void *data, u64 val)
if (val & DROP_ACTIVE) if (val & DROP_ACTIVE)
ret = i915_gem_wait_for_idle(dev_priv, ret = i915_gem_wait_for_idle(dev_priv,
I915_WAIT_INTERRUPTIBLE | I915_WAIT_INTERRUPTIBLE |
I915_WAIT_LOCKED); I915_WAIT_LOCKED,
MAX_SCHEDULE_TIMEOUT);
if (val & DROP_RETIRE) if (val & DROP_RETIRE)
i915_retire_requests(dev_priv); i915_retire_requests(dev_priv);
......
...@@ -3157,7 +3157,7 @@ void i915_gem_init_swizzling(struct drm_i915_private *dev_priv); ...@@ -3157,7 +3157,7 @@ void i915_gem_init_swizzling(struct drm_i915_private *dev_priv);
void i915_gem_fini(struct drm_i915_private *dev_priv); void i915_gem_fini(struct drm_i915_private *dev_priv);
void i915_gem_cleanup_engines(struct drm_i915_private *dev_priv); void i915_gem_cleanup_engines(struct drm_i915_private *dev_priv);
int i915_gem_wait_for_idle(struct drm_i915_private *dev_priv, int i915_gem_wait_for_idle(struct drm_i915_private *dev_priv,
unsigned int flags); unsigned int flags, long timeout);
int __must_check i915_gem_suspend(struct drm_i915_private *dev_priv); int __must_check i915_gem_suspend(struct drm_i915_private *dev_priv);
void i915_gem_suspend_late(struct drm_i915_private *dev_priv); void i915_gem_suspend_late(struct drm_i915_private *dev_priv);
void i915_gem_resume(struct drm_i915_private *dev_priv); void i915_gem_resume(struct drm_i915_private *dev_priv);
......
...@@ -2267,7 +2267,9 @@ static int i915_gem_object_create_mmap_offset(struct drm_i915_gem_object *obj) ...@@ -2267,7 +2267,9 @@ static int i915_gem_object_create_mmap_offset(struct drm_i915_gem_object *obj)
/* Attempt to reap some mmap space from dead objects */ /* Attempt to reap some mmap space from dead objects */
do { do {
err = i915_gem_wait_for_idle(dev_priv, I915_WAIT_INTERRUPTIBLE); err = i915_gem_wait_for_idle(dev_priv,
I915_WAIT_INTERRUPTIBLE,
MAX_SCHEDULE_TIMEOUT);
if (err) if (err)
break; break;
...@@ -3742,14 +3744,14 @@ i915_gem_wait_ioctl(struct drm_device *dev, void *data, struct drm_file *file) ...@@ -3742,14 +3744,14 @@ i915_gem_wait_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
return ret; return ret;
} }
static int wait_for_timeline(struct i915_timeline *tl, unsigned int flags) static long wait_for_timeline(struct i915_timeline *tl,
unsigned int flags, long timeout)
{ {
struct i915_request *rq; struct i915_request *rq;
long ret;
rq = i915_gem_active_get_unlocked(&tl->last_request); rq = i915_gem_active_get_unlocked(&tl->last_request);
if (!rq) if (!rq)
return 0; return timeout;
/* /*
* "Race-to-idle". * "Race-to-idle".
...@@ -3763,10 +3765,10 @@ static int wait_for_timeline(struct i915_timeline *tl, unsigned int flags) ...@@ -3763,10 +3765,10 @@ static int wait_for_timeline(struct i915_timeline *tl, unsigned int flags)
if (flags & I915_WAIT_FOR_IDLE_BOOST) if (flags & I915_WAIT_FOR_IDLE_BOOST)
gen6_rps_boost(rq, NULL); gen6_rps_boost(rq, NULL);
ret = i915_request_wait(rq, flags, MAX_SCHEDULE_TIMEOUT); timeout = i915_request_wait(rq, flags, timeout);
i915_request_put(rq); i915_request_put(rq);
return ret < 0 ? ret : 0; return timeout;
} }
static int wait_for_engines(struct drm_i915_private *i915) static int wait_for_engines(struct drm_i915_private *i915)
...@@ -3782,10 +3784,12 @@ static int wait_for_engines(struct drm_i915_private *i915) ...@@ -3782,10 +3784,12 @@ static int wait_for_engines(struct drm_i915_private *i915)
return 0; return 0;
} }
int i915_gem_wait_for_idle(struct drm_i915_private *i915, unsigned int flags) int i915_gem_wait_for_idle(struct drm_i915_private *i915,
unsigned int flags, long timeout)
{ {
GEM_TRACE("flags=%x (%s)\n", GEM_TRACE("flags=%x (%s), timeout=%ld%s\n",
flags, flags & I915_WAIT_LOCKED ? "locked" : "unlocked"); flags, flags & I915_WAIT_LOCKED ? "locked" : "unlocked",
timeout, timeout == MAX_SCHEDULE_TIMEOUT ? " (forever)" : "");
/* If the device is asleep, we have no requests outstanding */ /* If the device is asleep, we have no requests outstanding */
if (!READ_ONCE(i915->gt.awake)) if (!READ_ONCE(i915->gt.awake))
...@@ -3798,9 +3802,9 @@ int i915_gem_wait_for_idle(struct drm_i915_private *i915, unsigned int flags) ...@@ -3798,9 +3802,9 @@ int i915_gem_wait_for_idle(struct drm_i915_private *i915, unsigned int flags)
lockdep_assert_held(&i915->drm.struct_mutex); lockdep_assert_held(&i915->drm.struct_mutex);
list_for_each_entry(tl, &i915->gt.timelines, link) { list_for_each_entry(tl, &i915->gt.timelines, link) {
err = wait_for_timeline(tl, flags); timeout = wait_for_timeline(tl, flags, timeout);
if (err) if (timeout < 0)
return err; return timeout;
} }
err = wait_for_engines(i915); err = wait_for_engines(i915);
...@@ -3812,12 +3816,13 @@ int i915_gem_wait_for_idle(struct drm_i915_private *i915, unsigned int flags) ...@@ -3812,12 +3816,13 @@ int i915_gem_wait_for_idle(struct drm_i915_private *i915, unsigned int flags)
} else { } else {
struct intel_engine_cs *engine; struct intel_engine_cs *engine;
enum intel_engine_id id; enum intel_engine_id id;
int err;
for_each_engine(engine, i915, id) { for_each_engine(engine, i915, id) {
err = wait_for_timeline(&engine->timeline, flags); struct i915_timeline *tl = &engine->timeline;
if (err)
return err; timeout = wait_for_timeline(tl, flags, timeout);
if (timeout < 0)
return timeout;
} }
} }
...@@ -5052,7 +5057,8 @@ int i915_gem_suspend(struct drm_i915_private *dev_priv) ...@@ -5052,7 +5057,8 @@ int i915_gem_suspend(struct drm_i915_private *dev_priv)
ret = i915_gem_wait_for_idle(dev_priv, ret = i915_gem_wait_for_idle(dev_priv,
I915_WAIT_INTERRUPTIBLE | I915_WAIT_INTERRUPTIBLE |
I915_WAIT_LOCKED | I915_WAIT_LOCKED |
I915_WAIT_FOR_IDLE_BOOST); I915_WAIT_FOR_IDLE_BOOST,
MAX_SCHEDULE_TIMEOUT);
if (ret && ret != -EIO) if (ret && ret != -EIO)
goto err_unlock; goto err_unlock;
...@@ -5356,7 +5362,9 @@ static int __intel_engines_record_defaults(struct drm_i915_private *i915) ...@@ -5356,7 +5362,9 @@ static int __intel_engines_record_defaults(struct drm_i915_private *i915)
if (err) if (err)
goto err_active; goto err_active;
err = i915_gem_wait_for_idle(i915, I915_WAIT_LOCKED); err = i915_gem_wait_for_idle(i915,
I915_WAIT_LOCKED,
MAX_SCHEDULE_TIMEOUT);
if (err) if (err)
goto err_active; goto err_active;
...@@ -5421,7 +5429,9 @@ static int __intel_engines_record_defaults(struct drm_i915_private *i915) ...@@ -5421,7 +5429,9 @@ static int __intel_engines_record_defaults(struct drm_i915_private *i915)
if (WARN_ON(i915_gem_switch_to_kernel_context(i915))) if (WARN_ON(i915_gem_switch_to_kernel_context(i915)))
goto out_ctx; goto out_ctx;
if (WARN_ON(i915_gem_wait_for_idle(i915, I915_WAIT_LOCKED))) if (WARN_ON(i915_gem_wait_for_idle(i915,
I915_WAIT_LOCKED,
MAX_SCHEDULE_TIMEOUT)))
goto out_ctx; goto out_ctx;
i915_gem_contexts_lost(i915); i915_gem_contexts_lost(i915);
......
...@@ -69,7 +69,8 @@ static int ggtt_flush(struct drm_i915_private *i915) ...@@ -69,7 +69,8 @@ static int ggtt_flush(struct drm_i915_private *i915)
err = i915_gem_wait_for_idle(i915, err = i915_gem_wait_for_idle(i915,
I915_WAIT_INTERRUPTIBLE | I915_WAIT_INTERRUPTIBLE |
I915_WAIT_LOCKED); I915_WAIT_LOCKED,
MAX_SCHEDULE_TIMEOUT);
if (err) if (err)
return err; return err;
......
...@@ -2793,7 +2793,7 @@ void i915_gem_gtt_finish_pages(struct drm_i915_gem_object *obj, ...@@ -2793,7 +2793,7 @@ void i915_gem_gtt_finish_pages(struct drm_i915_gem_object *obj,
struct i915_ggtt *ggtt = &dev_priv->ggtt; struct i915_ggtt *ggtt = &dev_priv->ggtt;
if (unlikely(ggtt->do_idle_maps)) { if (unlikely(ggtt->do_idle_maps)) {
if (i915_gem_wait_for_idle(dev_priv, 0)) { if (i915_gem_wait_for_idle(dev_priv, 0, MAX_SCHEDULE_TIMEOUT)) {
DRM_ERROR("Failed to wait for idle; VT'd may hang.\n"); DRM_ERROR("Failed to wait for idle; VT'd may hang.\n");
/* Wait a bit, in hopes it avoids the hang */ /* Wait a bit, in hopes it avoids the hang */
udelay(10); udelay(10);
......
...@@ -172,7 +172,9 @@ i915_gem_shrink(struct drm_i915_private *i915, ...@@ -172,7 +172,9 @@ i915_gem_shrink(struct drm_i915_private *i915,
* we will free as much as we can and hope to get a second chance. * we will free as much as we can and hope to get a second chance.
*/ */
if (flags & I915_SHRINK_ACTIVE) if (flags & I915_SHRINK_ACTIVE)
i915_gem_wait_for_idle(i915, I915_WAIT_LOCKED); i915_gem_wait_for_idle(i915,
I915_WAIT_LOCKED,
MAX_SCHEDULE_TIMEOUT);
trace_i915_gem_shrink(i915, target, flags); trace_i915_gem_shrink(i915, target, flags);
i915_retire_requests(i915); i915_retire_requests(i915);
...@@ -392,7 +394,8 @@ shrinker_lock_uninterruptible(struct drm_i915_private *i915, bool *unlock, ...@@ -392,7 +394,8 @@ shrinker_lock_uninterruptible(struct drm_i915_private *i915, bool *unlock,
unsigned long timeout = jiffies + msecs_to_jiffies_timeout(timeout_ms); unsigned long timeout = jiffies + msecs_to_jiffies_timeout(timeout_ms);
do { do {
if (i915_gem_wait_for_idle(i915, 0) == 0 && if (i915_gem_wait_for_idle(i915,
0, MAX_SCHEDULE_TIMEOUT) == 0 &&
shrinker_lock(i915, unlock)) shrinker_lock(i915, unlock))
break; break;
...@@ -466,7 +469,9 @@ i915_gem_shrinker_vmap(struct notifier_block *nb, unsigned long event, void *ptr ...@@ -466,7 +469,9 @@ i915_gem_shrinker_vmap(struct notifier_block *nb, unsigned long event, void *ptr
return NOTIFY_DONE; return NOTIFY_DONE;
/* Force everything onto the inactive lists */ /* Force everything onto the inactive lists */
ret = i915_gem_wait_for_idle(i915, I915_WAIT_LOCKED); ret = i915_gem_wait_for_idle(i915,
I915_WAIT_LOCKED,
MAX_SCHEDULE_TIMEOUT);
if (ret) if (ret)
goto out; goto out;
......
...@@ -1836,7 +1836,9 @@ static int gen8_configure_all_contexts(struct drm_i915_private *dev_priv, ...@@ -1836,7 +1836,9 @@ static int gen8_configure_all_contexts(struct drm_i915_private *dev_priv,
* So far the best way to work around this issue seems to be draining * So far the best way to work around this issue seems to be draining
* the GPU from any submitted work. * the GPU from any submitted work.
*/ */
ret = i915_gem_wait_for_idle(dev_priv, wait_flags); ret = i915_gem_wait_for_idle(dev_priv,
wait_flags,
MAX_SCHEDULE_TIMEOUT);
if (ret) if (ret)
goto out; goto out;
......
...@@ -206,7 +206,8 @@ static int reset_all_global_seqno(struct drm_i915_private *i915, u32 seqno) ...@@ -206,7 +206,8 @@ static int reset_all_global_seqno(struct drm_i915_private *i915, u32 seqno)
/* Carefully retire all requests without writing to the rings */ /* Carefully retire all requests without writing to the rings */
ret = i915_gem_wait_for_idle(i915, ret = i915_gem_wait_for_idle(i915,
I915_WAIT_INTERRUPTIBLE | I915_WAIT_INTERRUPTIBLE |
I915_WAIT_LOCKED); I915_WAIT_LOCKED,
MAX_SCHEDULE_TIMEOUT);
if (ret) if (ret)
return ret; return ret;
...@@ -735,7 +736,8 @@ i915_request_alloc(struct intel_engine_cs *engine, struct i915_gem_context *ctx) ...@@ -735,7 +736,8 @@ i915_request_alloc(struct intel_engine_cs *engine, struct i915_gem_context *ctx)
/* Ratelimit ourselves to prevent oom from malicious clients */ /* Ratelimit ourselves to prevent oom from malicious clients */
ret = i915_gem_wait_for_idle(i915, ret = i915_gem_wait_for_idle(i915,
I915_WAIT_LOCKED | I915_WAIT_LOCKED |
I915_WAIT_INTERRUPTIBLE); I915_WAIT_INTERRUPTIBLE,
MAX_SCHEDULE_TIMEOUT);
if (ret) if (ret)
goto err_unreserve; goto err_unreserve;
......
...@@ -478,7 +478,9 @@ static int __igt_switch_to_kernel_context(struct drm_i915_private *i915, ...@@ -478,7 +478,9 @@ static int __igt_switch_to_kernel_context(struct drm_i915_private *i915,
} }
} }
err = i915_gem_wait_for_idle(i915, I915_WAIT_LOCKED); err = i915_gem_wait_for_idle(i915,
I915_WAIT_LOCKED,
MAX_SCHEDULE_TIMEOUT);
if (err) if (err)
return err; return err;
......
...@@ -286,7 +286,9 @@ static int begin_live_test(struct live_test *t, ...@@ -286,7 +286,9 @@ static int begin_live_test(struct live_test *t,
t->func = func; t->func = func;
t->name = name; t->name = name;
err = i915_gem_wait_for_idle(i915, I915_WAIT_LOCKED); err = i915_gem_wait_for_idle(i915,
I915_WAIT_LOCKED,
MAX_SCHEDULE_TIMEOUT);
if (err) { if (err) {
pr_err("%s(%s): failed to idle before, with err=%d!", pr_err("%s(%s): failed to idle before, with err=%d!",
func, name, err); func, name, err);
......
...@@ -64,7 +64,7 @@ int igt_flush_test(struct drm_i915_private *i915, unsigned int flags) ...@@ -64,7 +64,7 @@ int igt_flush_test(struct drm_i915_private *i915, unsigned int flags)
} }
wedge_on_timeout(&w, i915, HZ) wedge_on_timeout(&w, i915, HZ)
i915_gem_wait_for_idle(i915, flags); i915_gem_wait_for_idle(i915, flags, MAX_SCHEDULE_TIMEOUT);
return i915_terminally_wedged(&i915->gpu_error) ? -EIO : 0; return i915_terminally_wedged(&i915->gpu_error) ? -EIO : 0;
} }
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