[Intel-gfx] [PATCH v2 1/5] drm/i915: Implement a framework for batch buffer pools

Chris Wilson chris at chris-wilson.co.uk
Wed Jul 9 09:32:13 CEST 2014


On Tue, Jul 08, 2014 at 03:26:36PM -0700, bradley.d.volkin at intel.com wrote:
> +void i915_gem_batch_pool_fini(struct i915_gem_batch_pool *pool)
> +{
> +	struct drm_i915_gem_object *obj, *next;
> +
> +	WARN_ON(!mutex_is_locked(&pool->dev->struct_mutex));
> +	WARN_ON(!list_empty(&pool->active_list));
> +
> +	list_for_each_entry_safe(obj, next,
> +				 &pool->inactive_list, batch_pool_list) {
> +		list_del(&obj->batch_pool_list);
> +		drm_gem_object_unreference(&obj->base);
> +	}

Cleanup loops are idiomatically: while (!list_empty()) { }

> +struct drm_i915_gem_object *
> +i915_gem_batch_pool_get(struct i915_gem_batch_pool *pool,
> +			size_t size)
> +{
> +	struct drm_i915_gem_object *obj = NULL;
> +	struct drm_i915_gem_object *tmp;
> +
> +	WARN_ON(!mutex_is_locked(&pool->dev->struct_mutex));
> +
> +	list_for_each_entry(tmp, &pool->inactive_list, batch_pool_list) {
> +		if (tmp->base.size >= size) {

A general rule-of-thumb we use elsewhere is not to hand back an object
that is greater than 2x the request. If you want to be generic, you
could change size to min_size, max_size.
-Chris

-- 
Chris Wilson, Intel Open Source Technology Centre



More information about the Intel-gfx mailing list