[Intel-gfx] [PATCH 05/11] drm/i915: extract fence stealing code

Eric Anholt eric at anholt.net
Wed Feb 17 01:09:57 CET 2010


On Mon,  1 Feb 2010 13:59:20 +0100, Daniel Vetter <daniel.vetter at ffwll.ch> wrote:
> The spaghetti logic in there tripped up my brain's code parser for a
> few secs. Prevent this from happening again by extracting the fence
> stealing code into a seperate functions. IMHO this slightly clears up
> the code flow.
> 
> v2: Beautified according to ickle's comments.
> 
> v3: ickle forgot to flush his comment queue ... Now there's also a
> we-are-paranoid BUG_ON in there.
> 
> v4: I've forgotten to switch on my brain when doing v3. Now the BUG_ON
> actually checks something useful.
> 
> Signed-off-by: Daniel Vetter <daniel.vetter at ffwll.ch>
> Reviewed-by: Chris Wilson <chris at chris-wilson.co.uk>
> ---
>  drivers/gpu/drm/i915/i915_gem.c |  107 ++++++++++++++++++++++-----------------
>  1 files changed, 60 insertions(+), 47 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
> index 66d326e..a5ae3b8 100644
> --- a/drivers/gpu/drm/i915/i915_gem.c
> +++ b/drivers/gpu/drm/i915/i915_gem.c
> @@ -2370,6 +2370,58 @@ static void i830_write_fence_reg(struct drm_i915_fence_reg *reg)
>  	I915_WRITE(FENCE_REG_830_0 + (regnum * 4), val);
>  }
>  
> +static int i915_find_fence_reg(struct drm_device *dev)
> +{
> +	struct drm_i915_fence_reg *reg = NULL;
> +	struct drm_i915_gem_object *obj_priv = NULL;
> +	struct drm_i915_private *dev_priv = dev->dev_private;
> +	struct drm_gem_object *obj = NULL;
> +	int i, avail, ret;
> +
> +	/* First try to find a free reg */
> +	avail = 0;
> +	for (i = dev_priv->fence_reg_start; i < dev_priv->num_fence_regs; i++) {
> +		reg = &dev_priv->fence_regs[i];
> +		if (!reg->obj)
> +			return i;
> +
> +		obj_priv = reg->obj->driver_private;
> +		if (!obj_priv->pin_count)
> +		    avail++;
> +	}
> +
> +	if (avail == 0)
> +		return -ENOSPC;
> +
> +	/* None available, try to steal one or wait for a user to finish */
> +	i = I915_FENCE_REG_NONE;
> +	list_for_each_entry(obj_priv, &dev_priv->mm.fence_list,
> +			    fence_list) {
> +		obj = obj_priv->obj;
> +
> +		if (obj_priv->pin_count)
> +			continue;
> +
> +		/* found one! */
> +		i = obj_priv->fence_reg;
> +		break;
> +	}
> +
> +	BUG_ON(i == I915_FENCE_REG_NONE);
> +
> +	/* Take a reference, as otherwise the wait_rendering
> +	 * below may cause the object to get freed out from
> +	 * under us.
> +	 */
> +	drm_gem_object_reference(obj);
> +	ret = i915_gem_object_put_fence_reg(obj);
> +	drm_gem_object_unreference(obj);
> +	if (ret != 0)
> +		return ret;
> +
> +	return i;

This comment appears to be bogus now.  Does it mean a wait_rendering
inside of put_fence_reg?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/intel-gfx/attachments/20100216/8d9cc912/attachment.sig>


More information about the Intel-gfx mailing list