public inbox for intel-gfx@lists.freedesktop.org
 help / color / mirror / Atom feed
From: Daniel Vetter <daniel@ffwll.ch>
To: Ben Widawsky <ben@bwidawsk.net>
Cc: intel-gfx@lists.freedesktop.org
Subject: Re: [PATCH 09/12] drm/i915: timeout parameter for seqno wait
Date: Fri, 27 Apr 2012 17:00:20 +0200	[thread overview]
Message-ID: <20120427150020.GH5147@phenom.ffwll.local> (raw)
In-Reply-To: <1335481389-7232-10-git-send-email-ben@bwidawsk.net>

On Thu, Apr 26, 2012 at 04:03:06PM -0700, Ben Widawsky wrote:
> 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.
> 
> Signed-off-by: Ben Widawsky <ben@bwidawsk.net>

I have to admit, I'm a bit unhappy with this swiss-army-tool wait_seqno
and what it looks like. What about copy&pasting __wait_seqno_timeout,
which is always interruptible?
-Daniel

> ---
>  drivers/gpu/drm/i915/i915_gem.c |   58 +++++++++++++++++++++++++++++++--------
>  1 file changed, 46 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
> index 0ae1a73..f054439 100644
> --- a/drivers/gpu/drm/i915/i915_gem.c
> +++ b/drivers/gpu/drm/i915/i915_gem.c
> @@ -1820,10 +1820,23 @@ i915_gem_retire_work_handler(struct work_struct *work)
>  }
>  
>  static int __wait_seqno(struct intel_ring_buffer *ring, u32 seqno,
> -			bool interruptible)
> +			bool interruptible, long *usecs)
>  {
>  	drm_i915_private_t *dev_priv = ring->dev->dev_private;
> -	int ret = 0;
> +	bool wait_forever = false;
> +	long timeout, end;
> +
> +	if (usecs == NULL || ((*usecs) < 0)) {
> +		wait_forever = true;
> +		timeout = msecs_to_jiffies(100);
> +	} else
> +		timeout = usecs_to_jiffies(*usecs);
> +
> +	if (i915_seqno_passed(ring->get_seqno(ring), seqno))
> +		return 0;
> +
> +	if (WARN_ON(!ring->irq_get(ring)))
> +		return -ENODEV;
>  
>  	if (i915_seqno_passed(ring->get_seqno(ring), seqno))
>  		return 0;
> @@ -1836,17 +1849,40 @@ static int __wait_seqno(struct intel_ring_buffer *ring, u32 seqno,
>  	(i915_seqno_passed(ring->get_seqno(ring), seqno) || \
>  	atomic_read(&dev_priv->mm.wedged))
>  
> +	trace_i915_gem_request_wait_begin(ring, seqno);
> +again:
>  	if (interruptible)
> -		ret = wait_event_interruptible(ring->irq_queue,
> -					       EXIT_COND);
> +		end = wait_event_interruptible_timeout(ring->irq_queue,
> +						       EXIT_COND,
> +						       timeout);
>  	else
> -		wait_event(ring->irq_queue, EXIT_COND);
> +		end = wait_event_timeout(ring->irq_queue, EXIT_COND, timeout);
> +#undef EXIT_COND
> +
> +	if (atomic_read(&dev_priv->mm.wedged))
> +		end = -EAGAIN;
> +
> +	if (end == 0 && wait_forever)
> +		goto again;
>  
> -	ring->irq_put(ring);
>  	trace_i915_gem_request_wait_end(ring, seqno);
> -#undef EXIT_COND
> +	ring->irq_put(ring);
>  
> -	return ret;
> +	if (!wait_forever) {
> +		BUG_ON(end == 0);
> +		*usecs = jiffies_to_usecs(timeout - end);
> +	}
> +
> +	switch (end) {
> +	case -EAGAIN: /* Wedged */
> +	case -ERESTARTSYS: /* Signal */
> +		return (int)end;
> +	case 0: /* Tiemout */
> +		return -ETIME;
> +	default: /* Completed */
> +		WARN_ON(end < 0); /* We're not aware of other errors */
> +		return 0;
> +	}
>  }
>  
>  /**
> @@ -1891,9 +1927,7 @@ i915_wait_request(struct intel_ring_buffer *ring,
>  		seqno = request->seqno;
>  	}
>  
> -	ret = __wait_seqno(ring, seqno, dev_priv->mm.interruptible);
> -	if (atomic_read(&dev_priv->mm.wedged))
> -		ret = -EAGAIN;
> +	ret = __wait_seqno(ring, seqno, dev_priv->mm.interruptible, NULL);
>  
>  	return ret;
>  }
> @@ -2981,7 +3015,7 @@ i915_gem_ring_throttle(struct drm_device *dev, struct drm_file *file)
>  	if (seqno == 0)
>  		return 0;
>  
> -	ret = __wait_seqno(ring, seqno, true);
> +	ret = __wait_seqno(ring, seqno, true, NULL);
>  	if (ret == 0)
>  		queue_delayed_work(dev_priv->wq, &dev_priv->mm.retire_work, 0);
>  
> -- 
> 1.7.10
> 
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/intel-gfx

-- 
Daniel Vetter
Mail: daniel@ffwll.ch
Mobile: +41 (0)79 365 57 48

  parent reply	other threads:[~2012-04-27 14:59 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-26 23:02 [PATCH 00/12 v2] wait for BO with timeout Ben Widawsky
2012-04-26 23:02 ` [PATCH 01/12 v2] drm/i915: remove do_retire from i915_wait_request Ben Widawsky
2012-04-27 14:25   ` Daniel Vetter
2012-04-26 23:02 ` [PATCH 02/12] drm/i915: remove some extra retiring Ben Widawsky
2012-04-27 14:21   ` Daniel Vetter
2012-04-26 23:03 ` [PATCH 03/12 v2] drm/i915: move vbetool invoked ier stuff Ben Widawsky
2012-04-27 14:28   ` Daniel Vetter
2012-05-04 19:40   ` Jesse Barnes
2012-04-26 23:03 ` [PATCH 04/12 v2] drm/i915: kill waiting_seqno Ben Widawsky
2012-04-27 14:45   ` Daniel Vetter
2012-04-26 23:03 ` [PATCH 05/12 v2] drm/i915: drop polled waits from i915_wait_request Ben Widawsky
2012-04-27 14:46   ` Daniel Vetter
2012-04-26 23:03 ` [PATCH 06/12 v2] drm/i915: extract __wait_seqno " Ben Widawsky
2012-04-26 23:03 ` [PATCH 07/12] drm/i915: remove polled wait from throttle Ben Widawsky
2012-04-26 23:03 ` [PATCH 08/12 v2] drm/i915: use __wait_seqno for ring throttle Ben Widawsky
2012-04-27 14:50   ` Daniel Vetter
2012-04-26 23:03 ` [PATCH 09/12] drm/i915: timeout parameter for seqno wait Ben Widawsky
2012-04-27 14:14   ` Chris Wilson
2012-04-28 19:34     ` Ben Widawsky
2012-04-27 15:00   ` Daniel Vetter [this message]
2012-04-28  4:28     ` Ben Widawsky
2012-04-26 23:03 ` [PATCH 10/12] drm/i915: extract some common olr+wedge code Ben Widawsky
2012-04-27  8:46   ` Chris Wilson
2012-04-28 22:06     ` Ben Widawsky
2012-04-26 23:03 ` [PATCH 11/12 v2] drm/i915: wait render timeout ioctl Ben Widawsky
2012-04-27  8:44   ` Chris Wilson
2012-04-28 22:18     ` Ben Widawsky
2012-04-27 15:24   ` Chris Wilson
2012-04-29  2:11     ` Ben Widawsky
2012-04-29  2:33       ` Ben Widawsky
2012-04-29  9:27       ` Chris Wilson
2012-04-26 23:03 ` [PATCH 12/12] drm/i915: s/i915_wait_reqest/i915_wait_seqno/g Ben Widawsky

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20120427150020.GH5147@phenom.ffwll.local \
    --to=daniel@ffwll.ch \
    --cc=ben@bwidawsk.net \
    --cc=intel-gfx@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox