Commit 5c81fe85 authored by Ben Widawsky's avatar Ben Widawsky Committed by Daniel Vetter

drm/i915: timeout parameter for seqno wait

Insert a wait parameter in the code so we can possibly timeout on a
seqno wait if need be. The code should be functionally the same as
before because all the callers will continue to retry if an arbitrary
timeout elapses.

We'd like to have nanosecond granularity, but the only way to do this is
with hrtimer, and that doesn't fit well with the needs of this code.

v2: Fix rebase error (Chris)
Return proper time even in wedged + signal case (Chris + Ben)
Use timespec constructs (Ben)
Didn't take Daniel's advice regarding the Frankenstein-ness of the
  function. I did try his advice, but in the end I liked the way the
  original code looked, better.

v3: Make wakeups far less frequent for infinite waits (Chris)

v4: Remove dummy_wait variable (Daniel)
Use raw monotonic time instead of jiffies (made the code a bit cleaner) (Ben)
Added a couple of warnings (Ben)

v5: Remove warnings (Daniel)
Use more accurate time diff for default case (Daniel)
Bikeshed for setting the return timespec in timeout case (Daniel)
s/jiffies/time in one of the comments
Signed-off-by: default avatarBen Widawsky <ben@bwidawsk.net>
Reviewed-by: default avatarEugeni Dodonov <eugeni.dodonov@intel.com>
Signed-off-by: default avatarDaniel Vetter <daniel.vetter@ffwll.ch>
parent c8d4bb54
...@@ -1869,34 +1869,82 @@ i915_gem_check_olr(struct intel_ring_buffer *ring, u32 seqno) ...@@ -1869,34 +1869,82 @@ i915_gem_check_olr(struct intel_ring_buffer *ring, u32 seqno)
return ret; return ret;
} }
/**
* __wait_seqno - wait until execution of seqno has finished
* @ring: the ring expected to report seqno
* @seqno: duh!
* @interruptible: do an interruptible wait (normally yes)
* @timeout: in - how long to wait (NULL forever); out - how much time remaining
*
* Returns 0 if the seqno was found within the alloted time. Else returns the
* errno with remaining time filled in timeout argument.
*/
static int __wait_seqno(struct intel_ring_buffer *ring, u32 seqno, static int __wait_seqno(struct intel_ring_buffer *ring, u32 seqno,
bool interruptible) bool interruptible, struct timespec *timeout)
{ {
drm_i915_private_t *dev_priv = ring->dev->dev_private; drm_i915_private_t *dev_priv = ring->dev->dev_private;
int ret = 0; struct timespec before, now, wait_time={1,0};
unsigned long timeout_jiffies;
long end;
bool wait_forever = true;
if (i915_seqno_passed(ring->get_seqno(ring), seqno)) if (i915_seqno_passed(ring->get_seqno(ring), seqno))
return 0; return 0;
trace_i915_gem_request_wait_begin(ring, seqno); trace_i915_gem_request_wait_begin(ring, seqno);
if (timeout != NULL) {
wait_time = *timeout;
wait_forever = false;
}
timeout_jiffies = timespec_to_jiffies(&wait_time);
if (WARN_ON(!ring->irq_get(ring))) if (WARN_ON(!ring->irq_get(ring)))
return -ENODEV; return -ENODEV;
/* Record current time in case interrupted by signal, or wedged * */
getrawmonotonic(&before);
#define EXIT_COND \ #define EXIT_COND \
(i915_seqno_passed(ring->get_seqno(ring), seqno) || \ (i915_seqno_passed(ring->get_seqno(ring), seqno) || \
atomic_read(&dev_priv->mm.wedged)) atomic_read(&dev_priv->mm.wedged))
do {
if (interruptible) if (interruptible)
ret = wait_event_interruptible(ring->irq_queue, end = wait_event_interruptible_timeout(ring->irq_queue,
EXIT_COND); EXIT_COND,
timeout_jiffies);
else else
wait_event(ring->irq_queue, EXIT_COND); end = wait_event_timeout(ring->irq_queue, EXIT_COND,
timeout_jiffies);
if (atomic_read(&dev_priv->mm.wedged))
end = -EAGAIN;
} while (end == 0 && wait_forever);
getrawmonotonic(&now);
ring->irq_put(ring); ring->irq_put(ring);
trace_i915_gem_request_wait_end(ring, seqno); trace_i915_gem_request_wait_end(ring, seqno);
#undef EXIT_COND #undef EXIT_COND
return ret; if (timeout) {
struct timespec sleep_time = timespec_sub(now, before);
*timeout = timespec_sub(*timeout, sleep_time);
}
switch (end) {
case -EAGAIN: /* Wedged */
case -ERESTARTSYS: /* Signal */
return (int)end;
case 0: /* Timeout */
if (timeout)
set_normalized_timespec(timeout, 0, 0);
return -ETIME;
default: /* Completed */
WARN_ON(end < 0); /* We're not aware of other errors */
return 0;
}
} }
/** /**
...@@ -1920,9 +1968,7 @@ i915_wait_request(struct intel_ring_buffer *ring, ...@@ -1920,9 +1968,7 @@ i915_wait_request(struct intel_ring_buffer *ring,
if (ret) if (ret)
return ret; return ret;
ret = __wait_seqno(ring, seqno, dev_priv->mm.interruptible); ret = __wait_seqno(ring, seqno, dev_priv->mm.interruptible, NULL);
if (atomic_read(&dev_priv->mm.wedged))
ret = -EAGAIN;
return ret; return ret;
} }
...@@ -3002,7 +3048,7 @@ i915_gem_ring_throttle(struct drm_device *dev, struct drm_file *file) ...@@ -3002,7 +3048,7 @@ i915_gem_ring_throttle(struct drm_device *dev, struct drm_file *file)
if (seqno == 0) if (seqno == 0)
return 0; return 0;
ret = __wait_seqno(ring, seqno, true); ret = __wait_seqno(ring, seqno, true, NULL);
if (ret == 0) if (ret == 0)
queue_delayed_work(dev_priv->wq, &dev_priv->mm.retire_work, 0); queue_delayed_work(dev_priv->wq, &dev_priv->mm.retire_work, 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