[Intel-gfx] [PATCH 1/2] [RFC] drm/i915: Restore LRU evict order, with a twist!

Eric Anholt eric at anholt.net
Thu Jul 1 21:49:33 CEST 2010


On Thu,  1 Jul 2010 17:53:44 +0100, Chris Wilson <chris at chris-wilson.co.uk> wrote:
> When we need to clear some space in the GTT in order to pin a new
> buffer, scan through the inactive list amalgamating objects in LRU order
> until we find a large enough contiguous space to fit the new buffer.
> 
> Doing throughput testing on a PineView machine with cairo-perf-trace
> indicates that there is very little difference with the new LRU scan,
> perhaps a small improvement.
> 
> Reference:
> 
>   Bug 15911 - Intermittent X crash (freeze)
>   https://bugzilla.kernel.org/show_bug.cgi?id=15911
> 
>   Bug 20152 - cannot view JPG in firefox when running UXA
>   https://bugs.freedesktop.org/show_bug.cgi?id=20152
> 
>   Bug 24369 - Hang when scrolling firefox page with window in front
>   https://bugs.freedesktop.org/show_bug.cgi?id=24369
> 
>   Bug 28478 - Intermittent graphics lockups due to overflow/loop
>   https://bugs.freedesktop.org/show_bug.cgi?id=28478
> 
> v2: Process active and flushing lists using roster.
> v3: Update to apply LRU across the render and bsd rings.

> diff --git a/drivers/gpu/drm/i915/i915_gem_evict.c b/drivers/gpu/drm/i915/i915_gem_evict.c
> new file mode 100644
> index 0000000..d2e8f04
> --- /dev/null
> +++ b/drivers/gpu/drm/i915/i915_gem_evict.c
> @@ -0,0 +1,489 @@
> +/*
> + * Copyright © 2008-2010 Intel Corporation
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a
> + * copy of this software and associated documentation files (the "Software"),
> + * to deal in the Software without restriction, including without limitation
> + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
> + * and/or sell copies of the Software, and to permit persons to whom the
> + * Software is furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice (including the next
> + * paragraph) shall be included in all copies or substantial portions of the
> + * Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
> + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
> + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
> + * IN THE SOFTWARE.
> + *
> + * Authors:
> + *    Eric Anholt <eric at anholt.net>
> + *    Chris Wilson <chris at chris-wilson.co.uk>
> + *
> + */
> +
> +#include "drmP.h"
> +#include "drm.h"
> +#include "i915_drm.h"
> +#include "i915_drv.h"
> +
> +struct i915_gem_eviction_entry {
> +	struct list_head link;
> +	unsigned long start, end, size;
> +	struct i915_gem_eviction_objects {
> +		struct drm_i915_gem_object *obj_priv[16];
> +		unsigned num_obj;
> +		struct list_head link;
> +	} objects;
> +};
> +
> +struct i915_gem_eviction_roster {
> +	struct list_head list;
> +	struct list_head objects_free_list;
> +};
> +
> +static int
> +i915_gem_eviction_roster_add(struct i915_gem_eviction_roster *roster,
> +			     struct drm_i915_gem_object *obj_priv)
> +{

This function could stand a brief comment of what it does.  But frankly,
a lot of this file looks like a rewrite of drm_mm.c -- is there a reason
not to reuse that for free space tracking?  Only downside seems to be
doing another lookup to figure out which objects take up the space when
we decide on which block to free, since the merging of blocks wouldn't
be aware of our list of objects we want to attach.

(but then, if we're going to talk about cpu efficiency, it seems like we
could do a lot better than this implementation of _search that we call
over and over to try to find the a block with the same size/align
parameters each time)

> +	struct i915_gem_eviction_entry *before, *after, *entry = NULL;
> +	long start = obj_priv->gtt_offset;
> +	long end = start + obj_priv->base.size;
> +	int i, ret;
> +
> +	list_for_each_entry(before, &roster->list, link) {
> +		if (before->end == start) {
> +			i915_gem_eviction_roster_entry_add(roster, before, obj_priv);
> +			entry = before;
> +			entry->end = end;
> +			break;
> +		}
> +	}
> +
> +	list_for_each_entry(after, &roster->list, link) {
> +		if (after->start == end) {
> +			if (entry) {
> +				struct i915_gem_eviction_objects *objects;
> +
> +				entry->end = after->end;
> +				for (i = 0; i < after->objects.num_obj; i++) {
> +					ret = i915_gem_eviction_roster_entry_add(roster, entry, obj_priv);
> +					if (ret)
> +						return ret;
> +				}
> +
> +				list_for_each_entry(objects, &after->objects.link, link) {
> +					for (i = 0; i < objects->num_obj; i++) {
> +						ret = i915_gem_eviction_roster_entry_add(roster, entry, obj_priv);
> +						if (ret)
> +							return ret;
> +					}
> +				}
> +				i915_gem_eviction_roster_entry_free(roster, entry);
> +			} else {
> +				ret = i915_gem_eviction_roster_entry_add(roster, after, obj_priv);
> +				if (ret)
> +					return ret;
> +
> +				entry = after;
> +				entry->start = start;
> +			}
> +			entry->size = entry->end - entry->start;
> +			break;
> +		}
> +	}
> +
> +	if (entry == NULL) {
> +		entry = kmalloc(sizeof (*entry), GFP_KERNEL);
> +		if (entry == NULL)
> +			return -ENOMEM;
> +
> +		entry->start = start;
> +		entry->end = end;
> +		entry->size = obj_priv->base.size;
> +		entry->objects.num_obj = 0;
> +		INIT_LIST_HEAD(&entry->objects.link);
> +
> +		list_add(&entry->link, &roster->list);
> +
> +		ret = i915_gem_eviction_roster_entry_add(roster, entry, obj_priv);
> +		if (ret)
> +			return ret;
> +	}
> +
> +	return 0;
> +}

> +static struct drm_i915_gem_object *
> +i915_gem_next_active_object(struct drm_device *dev,
> +			    struct list_head **render_iter,
> +			    struct list_head **bsd_iter)
> +{
> +	drm_i915_private_t *dev_priv = dev->dev_private;
> +	struct drm_i915_gem_object *render_obj, *bsd_obj;
> +
> +	if (*render_iter != &dev_priv->render_ring.active_list)
> +		render_obj = list_entry(*render_iter,
> +					struct drm_i915_gem_object,
> +					list);
> +
> +	if (HAS_BSD(dev)) {
> +		if (*bsd_iter != &dev_priv->bsd_ring.active_list)
> +			bsd_obj = list_entry(*bsd_iter,
> +					     struct drm_i915_gem_object,
> +					     list);
> +
> +		/* XXX can we handle seqno wrapping? */
> +		if (render_obj->last_rendering_seqno < bsd_obj->last_rendering_seqno) {
> +			*render_iter = (*render_iter)->next;
> +			return render_obj;
> +		} else {
> +			*bsd_iter = (*bsd_iter)->next;
> +			return bsd_obj;
> +		}
> +	} else {
> +		*render_iter = (*render_iter)->next;
> +		return render_obj;
> +	}
> +}

This looks like it will do some uninitialized value derefs when we run
out of objects in one of the lists.
-------------- 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/20100701/f2aa8d24/attachment.sig>


More information about the Intel-gfx mailing list