Skip to contentSkip to conversation

ppgtt: just the VMA

PATCH Superseded Ben Widawsky 3 participants 50 messages Jul 9, 2013 – Jul 16, 2013 Page 2 of 2

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#23 lore raw

Re: [PATCH 06/11] drm/i915: plumb VM into object operations

In reply to Daniel Vetter
Quoted 86 lines · Daniel Vetter
Quoted 2 lines · Ben Widawsky
Quoted 1 line · Daniel Vetter

On Mon, Jul 08, 2013 at 11:08:37PM -0700, Ben Widawsky wrote:

[snip]

Quoted 43 lines
Quoted 43 lines
Quoted 30 lines

index 058ad44..21015cd 100644

drivers/gpu/drm/i915/i915_gem.c +7 -5
@@ -38,10 +38,12 @@
 
 static void i915_gem_object_flush_gtt_write_domain(struct drm_i915_gem_object *obj);
 static void i915_gem_object_flush_cpu_write_domain(struct drm_i915_gem_object *obj);
-static __must_check int i915_gem_object_bind_to_gtt(struct drm_i915_gem_object *obj,
-						    unsigned alignment,
-						    bool map_and_fenceable,
-						    bool nonblocking);
+static __must_check int
+i915_gem_object_bind_to_gtt(struct drm_i915_gem_object *obj,
+			    struct i915_address_space *vm,
+			    unsigned alignment,
+			    bool map_and_fenceable,
+			    bool nonblocking);
 static int i915_gem_phys_pwrite(struct drm_device *dev,
 				struct drm_i915_gem_object *obj,
 				struct drm_i915_gem_pwrite *args,
@@ -135,7 +137,7 @@ int i915_mutex_lock_interruptible(struct drm_device *dev)
 static inline bool
 i915_gem_object_is_inactive(struct drm_i915_gem_object *obj)
 {
-	return i915_gem_obj_ggtt_bound(obj) && !obj->active;
+	return i915_gem_obj_bound_any(obj) && !obj->active;
 }
 
 int

drivers/gpu/drm/i915/i915_gem.c i915_gem_shmem_pread(struct drm_device *dev, · line 428

Quoted 6 lines
drivers/gpu/drm/i915/i915_gem.c +1 -1
@@ -422,7 +424,7 @@ i915_gem_shmem_pread(struct drm_device *dev,
 		 * anyway again before the next pread happens. */
 		if (obj->cache_level == I915_CACHE_NONE)
 			needs_clflush = 1;
-		if (i915_gem_obj_ggtt_bound(obj)) {
+		if (i915_gem_obj_bound_any(obj)) {
 			ret = i915_gem_object_set_to_gtt_domain(obj, false);

This is essentially a very convoluted version of "if there's gpu rendering outstanding, please wait for it". Maybe we should switch this to

	if (obj->active)
		wait_rendering(obj, true);
Quoted 8 lines
Quoted 4 lines

Same for the shmem_pwrite case below. Would be a separate patch to prep things though. Can I volunteer you for that? The ugly part is to review whether any of the lru list updating that set_domain does in addition to wait_rendering is required, but on a quick read that's not the case.

Just reading the comment above it says we need the clflush. I don't actually understand why we do that even after reading the comment, but meh. You tell me, I don't mind doing this as a prep first.

The comment right above is just for the needs_clflush = 1 assignment, the set_to_gtt_domain call afterwards is just to sync up with the gpu. The code is confusing and tricky and the lack of a white line in between the two things plus a comment explaining that we only care about the wait_rendering side-effect of set_to_gtt_domain doesn't help. If you do the proposed conversion (and add a white line) that should help a lot in unconfusing readers.

[snip]

Quoted 18 lines
Quoted 18 lines
Quoted 4 lines
drivers/gpu/drm/i915/i915_gem.c +0 -0
@@ -3333,12 +3376,15 @@ int i915_gem_object_set_cache_level(struct drm_i915_gem_object *obj,
 	}
 
 	if (!i915_gem_valid_gtt_space(dev, &vma->node, cache_level)) {

drivers/gpu/drm/i915/i915_gem.c int i915_gem_object_set_cache_level(struct drm_i915_gem_object *obj, · line 3386

Quoted 10 lines
drivers/gpu/drm/i915/i915_gem.c +4 -2
-		ret = i915_gem_object_unbind(obj);
+		ret = i915_gem_object_unbind(obj, vm);
 		if (ret)
 			return ret;
 	}
 
-	if (i915_gem_obj_ggtt_bound(obj)) {
+	list_for_each_entry(vm, &dev_priv->vm_list, global_link) {
+		if (!i915_gem_obj_bound(obj, vm))
+			continue;

Hm, shouldn't we have a per-object list of vmas? Or will that follow later on?

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

Self-correction: It exists already ... why can't we use this here?

Yes. That should work, I'll fix it and test it. It looks slightly worse IMO in terms of code clarity, but I don't mind the change.

Actually I think it'd gain in clarity, doing pte updatest (which set_cache_level does) on the vma instead of the (obj, vm) pair feels more natural. And we'd be able to drop lots of (obj, vm) -> vma lookups here.

That sounds good to me. Would you mind a patch on top?

Quoted 83 lines
Quoted 83 lines
Quoted 82 lines
Quoted 72 lines
drivers/gpu/drm/i915/i915_gem.c +11 -4
+
 		ret = i915_gem_object_finish_gpu(obj);
 		if (ret)
 			return ret;
@@ -3361,7 +3407,7 @@ int i915_gem_object_set_cache_level(struct drm_i915_gem_object *obj,
 			i915_ppgtt_bind_object(dev_priv->mm.aliasing_ppgtt,
 					       obj, cache_level);
 
-		i915_gem_obj_ggtt_set_color(obj, cache_level);
+		i915_gem_obj_set_color(obj, vm, cache_level);
 	}
 
 	if (cache_level == I915_CACHE_NONE) {
@@ -3421,6 +3467,7 @@ int i915_gem_set_caching_ioctl(struct drm_device *dev, void *data,
 			       struct drm_file *file)
 {
 	struct drm_i915_gem_caching *args = data;
+	struct drm_i915_private *dev_priv;
 	struct drm_i915_gem_object *obj;
 	enum i915_cache_level level;
 	int ret;
@@ -3445,8 +3492,10 @@ int i915_gem_set_caching_ioctl(struct drm_device *dev, void *data,
 		ret = -ENOENT;
 		goto unlock;
 	}
+	dev_priv = obj->base.dev->dev_private;
 
-	ret = i915_gem_object_set_cache_level(obj, level);
+	/* FIXME: Add interface for specific VM? */
+	ret = i915_gem_object_set_cache_level(obj, &dev_priv->gtt.base, level);
 
 	drm_gem_object_unreference(&obj->base);
 unlock:
@@ -3464,6 +3513,7 @@ i915_gem_object_pin_to_display_plane(struct drm_i915_gem_object *obj,
 				     u32 alignment,
 				     struct intel_ring_buffer *pipelined)
 {
+	struct drm_i915_private *dev_priv = obj->base.dev->dev_private;
 	u32 old_read_domains, old_write_domain;
 	int ret;
 
@@ -3482,7 +3532,8 @@ i915_gem_object_pin_to_display_plane(struct drm_i915_gem_object *obj,
 	 * of uncaching, which would allow us to flush all the LLC-cached data
 	 * with that bit in the PTE to main memory with just one PIPE_CONTROL.
 	 */
-	ret = i915_gem_object_set_cache_level(obj, I915_CACHE_NONE);
+	ret = i915_gem_object_set_cache_level(obj, &dev_priv->gtt.base,
+					      I915_CACHE_NONE);
 	if (ret)
 		return ret;
 
@@ -3490,7 +3541,7 @@ i915_gem_object_pin_to_display_plane(struct drm_i915_gem_object *obj,
 	 * (e.g. libkms for the bootup splash), we have to ensure that we
 	 * always use map_and_fenceable for all scanout buffers.
 	 */
-	ret = i915_gem_object_pin(obj, alignment, true, false);
+	ret = i915_gem_ggtt_pin(obj, alignment, true, false);
 	if (ret)
 		return ret;
 
@@ -3633,6 +3684,7 @@ i915_gem_ring_throttle(struct drm_device *dev, struct drm_file *file)
 
 int
 i915_gem_object_pin(struct drm_i915_gem_object *obj,
+		    struct i915_address_space *vm,
 		    uint32_t alignment,
 		    bool map_and_fenceable,
 		    bool nonblocking)

drivers/gpu/drm/i915/i915_gem.c i915_gem_object_pin(struct drm_i915_gem_object *obj, · line 3697

Quoted 6 lines
drivers/gpu/drm/i915/i915_gem.c +1 -2
@@ -3642,26 +3694,29 @@ i915_gem_object_pin(struct drm_i915_gem_object *obj,
 	if (WARN_ON(obj->pin_count == DRM_I915_GEM_OBJECT_MAX_PIN_COUNT))
 		return -EBUSY;
 
-	if (i915_gem_obj_ggtt_bound(obj)) {
-		if ((alignment && i915_gem_obj_ggtt_offset(obj) & (alignment - 1)) ||
+	BUG_ON(map_and_fenceable && !i915_is_ggtt(vm));

WARN_ON, since presumably we can keep on going if we get this wrong (albeit with slightly corrupted state, so render corruptions might follow).

Quoted 5 lines
Quoted 2 lines

Can we make a deal, can we leave this as BUG_ON with a FIXME to convert it at the end of merging?

Adding a FIXME right above it will cause equal amounts of conflicts, so I don't see the point that much ...

I'm just really fearful that in doing the reworks I will end up with this condition, and I am afraid I will miss them if it's a WARN_ON. Definitely it's more likely to miss than a BUG.

Also, and we've disagreed on this a few times by now, this is an internal interface which I think should carry such a fatal error for this level of mistake.

In any case I've made the change locally. Will yell at you later if I was right.

Quoted 154 lines
Quoted 154 lines
Quoted 153 lines
Quoted 137 lines
drivers/gpu/drm/i915/i915_gem.c +39 -16
+
+	if (i915_gem_obj_bound(obj, vm)) {
+		if ((alignment &&
+		     i915_gem_obj_offset(obj, vm) & (alignment - 1)) ||
 		    (map_and_fenceable && !obj->map_and_fenceable)) {
 			WARN(obj->pin_count,
 			     "bo is already pinned with incorrect alignment:"
 			     " offset=%lx, req.alignment=%x, req.map_and_fenceable=%d,"
 			     " obj->map_and_fenceable=%d\n",
-			     i915_gem_obj_ggtt_offset(obj), alignment,
+			     i915_gem_obj_offset(obj, vm), alignment,
 			     map_and_fenceable,
 			     obj->map_and_fenceable);
-			ret = i915_gem_object_unbind(obj);
+			ret = i915_gem_object_unbind(obj, vm);
 			if (ret)
 				return ret;
 		}
 	}
 
-	if (!i915_gem_obj_ggtt_bound(obj)) {
+	if (!i915_gem_obj_bound(obj, vm)) {
 		struct drm_i915_private *dev_priv = obj->base.dev->dev_private;
 
-		ret = i915_gem_object_bind_to_gtt(obj, alignment,
+		ret = i915_gem_object_bind_to_gtt(obj, vm, alignment,
 						  map_and_fenceable,
 						  nonblocking);
 		if (ret)
@@ -3684,7 +3739,7 @@ void
 i915_gem_object_unpin(struct drm_i915_gem_object *obj)
 {
 	BUG_ON(obj->pin_count == 0);
-	BUG_ON(!i915_gem_obj_ggtt_bound(obj));
+	BUG_ON(!i915_gem_obj_bound_any(obj));
 
 	if (--obj->pin_count == 0)
 		obj->pin_mappable = false;
@@ -3722,7 +3777,7 @@ i915_gem_pin_ioctl(struct drm_device *dev, void *data,
 	}
 
 	if (obj->user_pin_count == 0) {
-		ret = i915_gem_object_pin(obj, args->alignment, true, false);
+		ret = i915_gem_ggtt_pin(obj, args->alignment, true, false);
 		if (ret)
 			goto out;
 	}
@@ -3957,6 +4012,7 @@ void i915_gem_free_object(struct drm_gem_object *gem_obj)
 	struct drm_i915_gem_object *obj = to_intel_bo(gem_obj);
 	struct drm_device *dev = obj->base.dev;
 	drm_i915_private_t *dev_priv = dev->dev_private;
+	struct i915_vma *vma, *next;
 
 	trace_i915_gem_object_destroy(obj);
 
@@ -3964,15 +4020,21 @@ void i915_gem_free_object(struct drm_gem_object *gem_obj)
 		i915_gem_detach_phys_object(dev, obj);
 
 	obj->pin_count = 0;
-	if (WARN_ON(i915_gem_object_unbind(obj) == -ERESTARTSYS)) {
-		bool was_interruptible;
+	/* NB: 0 or 1 elements */
+	WARN_ON(!list_empty(&obj->vma_list) &&
+		!list_is_singular(&obj->vma_list));
+	list_for_each_entry_safe(vma, next, &obj->vma_list, vma_link) {
+		int ret = i915_gem_object_unbind(obj, vma->vm);
+		if (WARN_ON(ret == -ERESTARTSYS)) {
+			bool was_interruptible;
 
-		was_interruptible = dev_priv->mm.interruptible;
-		dev_priv->mm.interruptible = false;
+			was_interruptible = dev_priv->mm.interruptible;
+			dev_priv->mm.interruptible = false;
 
-		WARN_ON(i915_gem_object_unbind(obj));
+			WARN_ON(i915_gem_object_unbind(obj, vma->vm));
 
-		dev_priv->mm.interruptible = was_interruptible;
+			dev_priv->mm.interruptible = was_interruptible;
+		}
 	}
 
 	/* Stolen objects don't hold a ref, but do hold pin count. Fix that up
@@ -4332,6 +4394,16 @@ init_ring_lists(struct intel_ring_buffer *ring)
 	INIT_LIST_HEAD(&ring->request_list);
 }
 
+static void i915_init_vm(struct drm_i915_private *dev_priv,
+			 struct i915_address_space *vm)
+{
+	vm->dev = dev_priv->dev;
+	INIT_LIST_HEAD(&vm->active_list);
+	INIT_LIST_HEAD(&vm->inactive_list);
+	INIT_LIST_HEAD(&vm->global_link);
+	list_add(&vm->global_link, &dev_priv->vm_list);
+}
+
 void
 i915_gem_load(struct drm_device *dev)
 {
@@ -4344,8 +4416,9 @@ i915_gem_load(struct drm_device *dev)
 				  SLAB_HWCACHE_ALIGN,
 				  NULL);
 
-	INIT_LIST_HEAD(&dev_priv->gtt.base.active_list);
-	INIT_LIST_HEAD(&dev_priv->gtt.base.inactive_list);
+	INIT_LIST_HEAD(&dev_priv->vm_list);
+	i915_init_vm(dev_priv, &dev_priv->gtt.base);
+
 	INIT_LIST_HEAD(&dev_priv->mm.unbound_list);
 	INIT_LIST_HEAD(&dev_priv->mm.bound_list);
 	INIT_LIST_HEAD(&dev_priv->mm.fence_list);
@@ -4616,9 +4689,9 @@ i915_gem_inactive_shrink(struct shrinker *shrinker, struct shrink_control *sc)
 			     struct drm_i915_private,
 			     mm.inactive_shrinker);
 	struct drm_device *dev = dev_priv->dev;
-	struct i915_address_space *vm = &dev_priv->gtt.base;
+	struct i915_address_space *vm;
 	struct drm_i915_gem_object *obj;
-	int nr_to_scan = sc->nr_to_scan;
+	int nr_to_scan;
 	bool unlock = true;
 	int cnt;
 
@@ -4632,6 +4705,7 @@ i915_gem_inactive_shrink(struct shrinker *shrinker, struct shrink_control *sc)
 		unlock = false;
 	}
 
+	nr_to_scan = sc->nr_to_scan;
 	if (nr_to_scan) {
 		nr_to_scan -= i915_gem_purge(dev_priv, nr_to_scan);
 		if (nr_to_scan > 0)
@@ -4645,11 +4719,93 @@ i915_gem_inactive_shrink(struct shrinker *shrinker, struct shrink_control *sc)
 	list_for_each_entry(obj, &dev_priv->mm.unbound_list, global_list)

drivers/gpu/drm/i915/i915_gem.c i915_gem_inactive_shrink(struct shrinker *shrinker, struct shrink_control *sc) · line 4726

Quoted 10 lines
drivers/gpu/drm/i915/i915_gem.c +5 -3
 		if (obj->pages_pin_count == 0)
 			cnt += obj->base.size >> PAGE_SHIFT;
-	list_for_each_entry(obj, &vm->inactive_list, mm_list)
-		if (obj->pin_count == 0 && obj->pages_pin_count == 0)
-			cnt += obj->base.size >> PAGE_SHIFT;
+
+	list_for_each_entry(vm, &dev_priv->vm_list, global_link)
+		list_for_each_entry(obj, &vm->inactive_list, global_list)
+			if (obj->pin_count == 0 && obj->pages_pin_count == 0)
+				cnt += obj->base.size >> PAGE_SHIFT;

Isn't this now double-counting objects? In the shrinker we only care about how much physical RAM an object occupies, not how much virtual space it occupies. So just walking the bound list of objects here should be good enough ...

Quoted 8 lines
Quoted 4 lines

Maybe I've misunderstood you. My code is wrong, but I think you're idea requires a prep patch because it changes functionality, right?

So let me know if I've understood you.

Don't we have both the bound and unbound list? So we could just switch over to counting the bound objects here ... Otherwise yes, we need a prep patch to create the bound list first.

Of course there is a bound list.

The old code automatically added the size of unbound objects with unpinned pages, and unpinned inactive objects with unpinned pages.

The latter check for inactive, needs to be checked for all VMAs. That was my point.

Quoted 35 lines
Quoted 29 lines
Quoted 25 lines
Quoted 10 lines
drivers/gpu/drm/i915/i915_gem.c +3 -0
 	if (unlock)
 		mutex_unlock(&dev->struct_mutex);
 	return cnt;
 }
+
+/* All the new VM stuff */
+unsigned long i915_gem_obj_offset(struct drm_i915_gem_object *o,

drivers/gpu/drm/i915/i915_gem.c i915_gem_inactive_shrink(struct shrinker *shrinker, struct shrink_control *sc) · line 4744

Quoted 10 lines
drivers/gpu/drm/i915/i915_gem.c +10 -0
+				  struct i915_address_space *vm)
+{
+	struct drm_i915_private *dev_priv = o->base.dev->dev_private;
+	struct i915_vma *vma;
+
+	if (vm == &dev_priv->mm.aliasing_ppgtt->base)
+		vm = &dev_priv->gtt.base;
+
+	BUG_ON(list_empty(&o->vma_list));
+	list_for_each_entry(vma, &o->vma_list, vma_link) {

Imo the vma list walking here and in the other helpers below indicates that we should deal more often in vmas instead of (object, vm) pairs. Or is this again something that'll get fixed later on?

Quoted 3 lines

I just want to avoid diff churn, and it also makes reviewing easier if the foreshadowing is correct ;-) So generally I'd vote for more liberal sprinkling of obj_to_vma in callers.

Quoted 5 lines

It's not something I fixed in the whole series. I think it makes sense conceptually, to keep some things as <obj,vm> and others as direct vma.

If you want me to change something, you need to be more specific since no action specifically comes to mind at this point in the series.

Quoted 9 lines

It's just that the (obj, vm) -> vma lookup is a list-walk, so imo we should try to avoid it whenever possible. Since the vma has both and obj and a vm pointer the vma is imo strictly better than the (obj, vm) pair. And the look-up should be pushed down the callchain as much as possible.

So I think generally we want to pass the vma around to functions everywhere, and the (obj, vm) pair would be the exception (which needs special justification).

Without actually coding it, I am not sure. I think there are probably a decent number of reasonable exceptions where we want the object (ie. it's not really that much of a special case). In any case, I think we'll find you have to do this list walk at some point in the call chain anyway, but I can try to start changing around the code as a patch on top of this. I really want to leave as much as this patch in place as is, since it's decently tested (pre-rebase at least).

Quoted 225 lines
Quoted 225 lines
Quoted 208 lines
Quoted 208 lines
drivers/gpu/drm/i915/i915_gem.c +67 -0
+		if (vma->vm == vm)
+			return vma->node.start;
+
+	}
+	return -1;
+}
+
+bool i915_gem_obj_bound_any(struct drm_i915_gem_object *o)
+{
+	return !list_empty(&o->vma_list);
+}
+
+bool i915_gem_obj_bound(struct drm_i915_gem_object *o,
+			struct i915_address_space *vm)
+{
+	struct i915_vma *vma;
+
+	list_for_each_entry(vma, &o->vma_list, vma_link) {
+		if (vma->vm == vm)
+			return true;
+	}
+	return false;
+}
+
+unsigned long i915_gem_obj_size(struct drm_i915_gem_object *o,
+				struct i915_address_space *vm)
+{
+	struct drm_i915_private *dev_priv = o->base.dev->dev_private;
+	struct i915_vma *vma;
+
+	if (vm == &dev_priv->mm.aliasing_ppgtt->base)
+		vm = &dev_priv->gtt.base;
+	BUG_ON(list_empty(&o->vma_list));
+	list_for_each_entry(vma, &o->vma_list, vma_link) {
+		if (vma->vm == vm)
+			return vma->node.size;
+	}
+
+	return 0;
+}
+
+void i915_gem_obj_set_color(struct drm_i915_gem_object *o,
+			    struct i915_address_space *vm,
+			    enum i915_cache_level color)
+{
+	struct i915_vma *vma;
+	BUG_ON(list_empty(&o->vma_list));
+	list_for_each_entry(vma, &o->vma_list, vma_link) {
+		if (vma->vm == vm) {
+			vma->node.color = color;
+			return;
+		}
+	}
+
+	WARN(1, "Couldn't set color for VM %p\n", vm);
+}
+
+struct i915_vma *i915_gem_obj_to_vma(struct drm_i915_gem_object *obj,
+				     struct i915_address_space *vm)
+{
+	struct i915_vma *vma;
+	list_for_each_entry(vma, &obj->vma_list, vma_link)
+		if (vma->vm == vm)
+			return vma;
+
+	return NULL;
+}
drivers/gpu/drm/i915/i915_gem_context.c +6 -3
index 2074544..c92fd81 100644
@@ -155,6 +155,7 @@ create_hw_context(struct drm_device *dev,
 
 	if (INTEL_INFO(dev)->gen >= 7) {
 		ret = i915_gem_object_set_cache_level(ctx->obj,
+						      &dev_priv->gtt.base,
 						      I915_CACHE_LLC_MLC);
 		/* Failure shouldn't ever happen this early */
 		if (WARN_ON(ret))
@@ -214,7 +215,7 @@ static int create_default_context(struct drm_i915_private *dev_priv)
 	 * default context.
 	 */
 	dev_priv->ring[RCS].default_context = ctx;
-	ret = i915_gem_object_pin(ctx->obj, CONTEXT_ALIGN, false, false);
+	ret = i915_gem_ggtt_pin(ctx->obj, CONTEXT_ALIGN, false, false);
 	if (ret) {
 		DRM_DEBUG_DRIVER("Couldn't pin %d\n", ret);
 		goto err_destroy;
@@ -398,6 +399,7 @@ mi_set_context(struct intel_ring_buffer *ring,
 static int do_switch(struct i915_hw_context *to)
 {
 	struct intel_ring_buffer *ring = to->ring;
+	struct drm_i915_private *dev_priv = ring->dev->dev_private;
 	struct i915_hw_context *from = ring->last_context;
 	u32 hw_flags = 0;
 	int ret;
@@ -407,7 +409,7 @@ static int do_switch(struct i915_hw_context *to)
 	if (from == to)
 		return 0;
 
-	ret = i915_gem_object_pin(to->obj, CONTEXT_ALIGN, false, false);
+	ret = i915_gem_ggtt_pin(to->obj, CONTEXT_ALIGN, false, false);
 	if (ret)
 		return ret;
 
@@ -444,7 +446,8 @@ static int do_switch(struct i915_hw_context *to)
 	 */
 	if (from != NULL) {
 		from->obj->base.read_domains = I915_GEM_DOMAIN_INSTRUCTION;
-		i915_gem_object_move_to_active(from->obj, ring);
+		i915_gem_object_move_to_active(from->obj, &dev_priv->gtt.base,
+					       ring);
 		/* As long as MI_SET_CONTEXT is serializing, ie. it flushes the
 		 * whole damn pipeline, we don't need to explicitly mark the
 		 * object dirty. The only exception is that the context must be
drivers/gpu/drm/i915/i915_gem_evict.c +15 -15
index df61f33..32efdc0 100644
@@ -32,24 +32,21 @@
 #include "i915_trace.h"
 
 static bool
-mark_free(struct drm_i915_gem_object *obj, struct list_head *unwind)
+mark_free(struct i915_vma *vma, struct list_head *unwind)
 {
-	struct i915_vma *vma = __i915_gem_obj_to_vma(obj);
-
-	if (obj->pin_count)
+	if (vma->obj->pin_count)
 		return false;
 
-	list_add(&obj->exec_list, unwind);
+	list_add(&vma->obj->exec_list, unwind);
 	return drm_mm_scan_add_block(&vma->node);
 }
 
 int
-i915_gem_evict_something(struct drm_device *dev, int min_size,
-			 unsigned alignment, unsigned cache_level,
+i915_gem_evict_something(struct drm_device *dev, struct i915_address_space *vm,
+			 int min_size, unsigned alignment, unsigned cache_level,
 			 bool mappable, bool nonblocking)
 {
 	drm_i915_private_t *dev_priv = dev->dev_private;
-	struct i915_address_space *vm = &dev_priv->gtt.base;
 	struct list_head eviction_list, unwind_list;
 	struct i915_vma *vma;
 	struct drm_i915_gem_object *obj;
@@ -81,16 +78,18 @@ i915_gem_evict_something(struct drm_device *dev, int min_size,
 	 */
 
 	INIT_LIST_HEAD(&unwind_list);
-	if (mappable)
+	if (mappable) {
+		BUG_ON(!i915_is_ggtt(vm));
 		drm_mm_init_scan_with_range(&vm->mm, min_size,
 					    alignment, cache_level, 0,
 					    dev_priv->gtt.mappable_end);
-	else
+	} else
 		drm_mm_init_scan(&vm->mm, min_size, alignment, cache_level);
 
 	/* First see if there is a large enough contiguous idle region... */
 	list_for_each_entry(obj, &vm->inactive_list, mm_list) {
-		if (mark_free(obj, &unwind_list))
+		struct i915_vma *vma = i915_gem_obj_to_vma(obj, vm);
+		if (mark_free(vma, &unwind_list))
 			goto found;
 	}
 
@@ -99,7 +98,8 @@ i915_gem_evict_something(struct drm_device *dev, int min_size,
 
 	/* Now merge in the soon-to-be-expired objects... */
 	list_for_each_entry(obj, &vm->active_list, mm_list) {
-		if (mark_free(obj, &unwind_list))
+		struct i915_vma *vma = i915_gem_obj_to_vma(obj, vm);
+		if (mark_free(vma, &unwind_list))
 			goto found;
 	}
 
@@ -109,7 +109,7 @@ none:
 		obj = list_first_entry(&unwind_list,
 				       struct drm_i915_gem_object,
 				       exec_list);
-		vma = __i915_gem_obj_to_vma(obj);
+		vma = i915_gem_obj_to_vma(obj, vm);
 		ret = drm_mm_scan_remove_block(&vma->node);
 		BUG_ON(ret);
 
@@ -130,7 +130,7 @@ found:
 		obj = list_first_entry(&unwind_list,
 				       struct drm_i915_gem_object,
 				       exec_list);
-		vma = __i915_gem_obj_to_vma(obj);
+		vma = i915_gem_obj_to_vma(obj, vm);
 		if (drm_mm_scan_remove_block(&vma->node)) {
 			list_move(&obj->exec_list, &eviction_list);
 			drm_gem_object_reference(&obj->base);
@@ -145,7 +145,7 @@ found:
 				       struct drm_i915_gem_object,
 				       exec_list);
 		if (ret == 0)
-			ret = i915_gem_object_unbind(obj);
+			ret = i915_gem_object_unbind(obj, vm);
 
Quoted 12 lines

drivers/gpu/drm/i915/i915_gem_evict.c int · line 158

Quoted 4 lines
drivers/gpu/drm/i915/i915_gem_evict.c +0 -0
 		list_del_init(&obj->exec_list);
 		drm_gem_object_unreference(&obj->base);
@@ -158,13 +158,18 @@ int
 i915_gem_evict_everything(struct drm_device *dev)

I suspect evict_everything eventually wants a address_space *vm argument for those cases where we only want to evict everything in a given vm. Atm we have two use-cases of this:
- Called from the shrinker as a last-ditch effort. For that it should move _every_ object onto the unbound list.
- Called from execbuf for badly-fragmented address spaces to clean up the mess. For that case we only care about one address space.

The current thing is more or less a result of Chris' suggestions. A non-posted iteration did plumb the vm, and after reworking to the suggestion made by Chris, the vm didn't make much sense anymore.

Quoted 6 lines
Quoted 2 lines

For point #1, it requires VM prioritization I think. I don't really see any other way to fairly manage it.

The shrinker will rip out objects in lru order by walking first unbound and then bound objects. That's imo as fair as it gets, we don't need priorities between vms.

If you pass in a vm, the semantics would be, evict everything for the vm, right?

Quoted 9 lines
Quoted 3 lines

For point #2, that I agree it might be useful, but we can easily create a new function, and not call it "shrinker" to do it.

Well my point was that this function is called i915_gem_evict_everything(dev, vm) and for the first use case we simply pass in vm = NULL. But essentially thrashing the vm should be rare enough that for now we don't need to care.

IIRC, this is exactly how my original patch worked pre-Chris.

Quoted 187 lines
Quoted 182 lines
Quoted 172 lines
Quoted 172 lines
drivers/gpu/drm/i915/i915_gem_evict.c +14 -7
 {
 	drm_i915_private_t *dev_priv = dev->dev_private;
-	struct i915_address_space *vm = &dev_priv->gtt.base;
+	struct i915_address_space *vm;
 	struct drm_i915_gem_object *obj, *next;
-	bool lists_empty;
+	bool lists_empty = true;
 	int ret;
 
-	lists_empty = (list_empty(&vm->inactive_list) &&
-		       list_empty(&vm->active_list));
+	list_for_each_entry(vm, &dev_priv->vm_list, global_link) {
+		lists_empty = (list_empty(&vm->inactive_list) &&
+			       list_empty(&vm->active_list));
+		if (!lists_empty)
+			lists_empty = false;
+	}
+
 	if (lists_empty)
 		return -ENOSPC;
 
@@ -181,9 +186,11 @@ i915_gem_evict_everything(struct drm_device *dev)
 	i915_gem_retire_requests(dev);
 
 	/* Having flushed everything, unbind() should never raise an error */
-	list_for_each_entry_safe(obj, next, &vm->inactive_list, mm_list)
-		if (obj->pin_count == 0)
-			WARN_ON(i915_gem_object_unbind(obj));
+	list_for_each_entry(vm, &dev_priv->vm_list, global_link) {
+		list_for_each_entry_safe(obj, next, &vm->inactive_list, mm_list)
+			if (obj->pin_count == 0)
+				WARN_ON(i915_gem_object_unbind(obj, vm));
+	}
 
 	return 0;
 }
drivers/gpu/drm/i915/i915_gem_execbuffer.c +22 -12
index 5aeb447..e90182d 100644
@@ -150,7 +150,7 @@ eb_get_object(struct eb_objects *eb, unsigned long handle)
 }
 
 static void
-eb_destroy(struct eb_objects *eb)
+eb_destroy(struct eb_objects *eb, struct i915_address_space *vm)
 {
 	while (!list_empty(&eb->objects)) {
 		struct drm_i915_gem_object *obj;
@@ -174,7 +174,8 @@ static inline int use_cpu_reloc(struct drm_i915_gem_object *obj)
 static int
 i915_gem_execbuffer_relocate_entry(struct drm_i915_gem_object *obj,
 				   struct eb_objects *eb,
-				   struct drm_i915_gem_relocation_entry *reloc)
+				   struct drm_i915_gem_relocation_entry *reloc,
+				   struct i915_address_space *vm)
 {
 	struct drm_device *dev = obj->base.dev;
 	struct drm_gem_object *target_obj;
@@ -297,7 +298,8 @@ i915_gem_execbuffer_relocate_entry(struct drm_i915_gem_object *obj,
 
 static int
 i915_gem_execbuffer_relocate_object(struct drm_i915_gem_object *obj,
-				    struct eb_objects *eb)
+				    struct eb_objects *eb,
+				    struct i915_address_space *vm)
 {
 #define N_RELOC(x) ((x) / sizeof(struct drm_i915_gem_relocation_entry))
 	struct drm_i915_gem_relocation_entry stack_reloc[N_RELOC(512)];
@@ -321,7 +323,8 @@ i915_gem_execbuffer_relocate_object(struct drm_i915_gem_object *obj,
 		do {
 			u64 offset = r->presumed_offset;
 
-			ret = i915_gem_execbuffer_relocate_entry(obj, eb, r);
+			ret = i915_gem_execbuffer_relocate_entry(obj, eb, r,
+								 vm);
 			if (ret)
 				return ret;
 
@@ -344,13 +347,15 @@ i915_gem_execbuffer_relocate_object(struct drm_i915_gem_object *obj,
 static int
 i915_gem_execbuffer_relocate_object_slow(struct drm_i915_gem_object *obj,
 					 struct eb_objects *eb,
-					 struct drm_i915_gem_relocation_entry *relocs)
+					 struct drm_i915_gem_relocation_entry *relocs,
+					 struct i915_address_space *vm)
 {
 	const struct drm_i915_gem_exec_object2 *entry = obj->exec_entry;
 	int i, ret;
 
 	for (i = 0; i < entry->relocation_count; i++) {
-		ret = i915_gem_execbuffer_relocate_entry(obj, eb, &relocs[i]);
+		ret = i915_gem_execbuffer_relocate_entry(obj, eb, &relocs[i],
+							 vm);
 		if (ret)
 			return ret;
 	}
@@ -359,7 +364,8 @@ i915_gem_execbuffer_relocate_object_slow(struct drm_i915_gem_object *obj,
 }
 
 static int
-i915_gem_execbuffer_relocate(struct eb_objects *eb)
+i915_gem_execbuffer_relocate(struct eb_objects *eb,
+			     struct i915_address_space *vm)
 {
 	struct drm_i915_gem_object *obj;
 	int ret = 0;
@@ -373,7 +379,7 @@ i915_gem_execbuffer_relocate(struct eb_objects *eb)
 	 */
 	pagefault_disable();
 	list_for_each_entry(obj, &eb->objects, exec_list) {
-		ret = i915_gem_execbuffer_relocate_object(obj, eb);
+		ret = i915_gem_execbuffer_relocate_object(obj, eb, vm);
 		if (ret)
 			break;
 	}
@@ -395,6 +401,7 @@ need_reloc_mappable(struct drm_i915_gem_object *obj)
 static int
 i915_gem_execbuffer_reserve_object(struct drm_i915_gem_object *obj,
 				   struct intel_ring_buffer *ring,
+				   struct i915_address_space *vm,
 				   bool *need_reloc)
 {
 	struct drm_i915_private *dev_priv = obj->base.dev->dev_private;
@@ -409,7 +416,8 @@ i915_gem_execbuffer_reserve_object(struct drm_i915_gem_object *obj,
 		obj->tiling_mode != I915_TILING_NONE;
 	need_mappable = need_fence || need_reloc_mappable(obj);
 
-	ret = i915_gem_object_pin(obj, entry->alignment, need_mappable, false);
+	ret = i915_gem_object_pin(obj, vm, entry->alignment, need_mappable,
+				  false);
 	if (ret)
 		return ret;
 
@@ -436,8 +444,8 @@ i915_gem_execbuffer_reserve_object(struct drm_i915_gem_object *obj,
 		obj->has_aliasing_ppgtt_mapping = 1;
 	}
 
-	if (entry->offset != i915_gem_obj_ggtt_offset(obj)) {
-		entry->offset = i915_gem_obj_ggtt_offset(obj);
+	if (entry->offset != i915_gem_obj_offset(obj, vm)) {
+		entry->offset = i915_gem_obj_offset(obj, vm);
 		*need_reloc = true;
 	}
 
@@ -458,7 +466,7 @@ i915_gem_execbuffer_unreserve_object(struct drm_i915_gem_object *obj)
 {
 	struct drm_i915_gem_exec_object2 *entry;
 
-	if (!i915_gem_obj_ggtt_bound(obj))
+	if (!i915_gem_obj_bound_any(obj))
 		return;
 
 	entry = obj->exec_entry;
@@ -475,6 +483,7 @@ i915_gem_execbuffer_unreserve_object(struct drm_i915_gem_object *obj)
 static int
 i915_gem_execbuffer_reserve(struct intel_ring_buffer *ring,
 			    struct list_head *objects,
+			    struct i915_address_space *vm,
 			    bool *need_relocs)
 {
 	struct drm_i915_gem_object *obj;
@@ -529,32 +538,37 @@ i915_gem_execbuffer_reserve(struct intel_ring_buffer *ring,
 		list_for_each_entry(obj, objects, exec_list) {
 			struct drm_i915_gem_exec_object2 *entry = obj->exec_entry;
 			bool need_fence, need_mappable;
+			u32 obj_offset;
 
Quoted 9 lines

drivers/gpu/drm/i915/i915_gem_execbuffer.c i915_gem_execbuffer_reserve(struct intel_ring_buffer *ring, · line 544

Quoted 3 lines
drivers/gpu/drm/i915/i915_gem_execbuffer.c +1 -1
-			if (!i915_gem_obj_ggtt_bound(obj))
+			if (!i915_gem_obj_bound(obj, vm))
 				continue;

I wonder a bit how we could avoid the multipler (obj, vm) -> vma lookups here ... Maybe we should cache them in some pointer somewhere (either in the eb object or by adding a new pointer to the object struct, e.g. obj->eb_vma, similar to obj->eb_list).

Quoted 4 lines

I agree, and even did this at one unposted patch too. However, I think it's a premature optimization which risks code correctness. So I think somewhere a FIXME needs to happen to address that issue. (Or if Chris complains bitterly about some perf hit).

Quoted 4 lines

If you bring up code correctness I'd vote strongly in favour of using vmas everywhere - vma has the (obj, vm) pair locked down, doing the lookup all the thing risks us mixing them up eventually and creating a hella lot of confusion ;-)

I think this is addressed with the previous comments.

Quoted 312 lines
Quoted 312 lines
Quoted 299 lines
Quoted 299 lines
drivers/gpu/drm/i915/i915_gem_execbuffer.c +31 -18
+			obj_offset = i915_gem_obj_offset(obj, vm);
 			need_fence =
 				has_fenced_gpu_access &&
 				entry->flags & EXEC_OBJECT_NEEDS_FENCE &&
 				obj->tiling_mode != I915_TILING_NONE;
 			need_mappable = need_fence || need_reloc_mappable(obj);
 
+			BUG_ON((need_mappable || need_fence) &&
+			       !i915_is_ggtt(vm));
+
 			if ((entry->alignment &&
-			     i915_gem_obj_ggtt_offset(obj) & (entry->alignment - 1)) ||
+			     obj_offset & (entry->alignment - 1)) ||
 			    (need_mappable && !obj->map_and_fenceable))
-				ret = i915_gem_object_unbind(obj);
+				ret = i915_gem_object_unbind(obj, vm);
 			else
-				ret = i915_gem_execbuffer_reserve_object(obj, ring, need_relocs);
+				ret = i915_gem_execbuffer_reserve_object(obj, ring, vm, need_relocs);
 			if (ret)
 				goto err;
 		}
 
 		/* Bind fresh objects */
 		list_for_each_entry(obj, objects, exec_list) {
-			if (i915_gem_obj_ggtt_bound(obj))
+			if (i915_gem_obj_bound(obj, vm))
 				continue;
 
-			ret = i915_gem_execbuffer_reserve_object(obj, ring, need_relocs);
+			ret = i915_gem_execbuffer_reserve_object(obj, ring, vm, need_relocs);
 			if (ret)
 				goto err;
 		}
@@ -578,7 +592,8 @@ i915_gem_execbuffer_relocate_slow(struct drm_device *dev,
 				  struct drm_file *file,
 				  struct intel_ring_buffer *ring,
 				  struct eb_objects *eb,
-				  struct drm_i915_gem_exec_object2 *exec)
+				  struct drm_i915_gem_exec_object2 *exec,
+				  struct i915_address_space *vm)
 {
 	struct drm_i915_gem_relocation_entry *reloc;
 	struct drm_i915_gem_object *obj;
@@ -662,14 +677,15 @@ i915_gem_execbuffer_relocate_slow(struct drm_device *dev,
 		goto err;
 
 	need_relocs = (args->flags & I915_EXEC_NO_RELOC) == 0;
-	ret = i915_gem_execbuffer_reserve(ring, &eb->objects, &need_relocs);
+	ret = i915_gem_execbuffer_reserve(ring, &eb->objects, vm, &need_relocs);
 	if (ret)
 		goto err;
 
 	list_for_each_entry(obj, &eb->objects, exec_list) {
 		int offset = obj->exec_entry - exec;
 		ret = i915_gem_execbuffer_relocate_object_slow(obj, eb,
-							       reloc + reloc_offset[offset]);
+							       reloc + reloc_offset[offset],
+							       vm);
 		if (ret)
 			goto err;
 	}
@@ -768,6 +784,7 @@ validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
 
 static void
 i915_gem_execbuffer_move_to_active(struct list_head *objects,
+				   struct i915_address_space *vm,
 				   struct intel_ring_buffer *ring)
 {
 	struct drm_i915_gem_object *obj;
@@ -782,7 +799,7 @@ i915_gem_execbuffer_move_to_active(struct list_head *objects,
 		obj->base.read_domains = obj->base.pending_read_domains;
 		obj->fenced_gpu_access = obj->pending_fenced_gpu_access;
 
-		i915_gem_object_move_to_active(obj, ring);
+		i915_gem_object_move_to_active(obj, vm, ring);
 		if (obj->base.write_domain) {
 			obj->dirty = 1;
 			obj->last_write_seqno = intel_ring_get_seqno(ring);
@@ -836,7 +853,8 @@ static int
 i915_gem_do_execbuffer(struct drm_device *dev, void *data,
 		       struct drm_file *file,
 		       struct drm_i915_gem_execbuffer2 *args,
-		       struct drm_i915_gem_exec_object2 *exec)
+		       struct drm_i915_gem_exec_object2 *exec,
+		       struct i915_address_space *vm)
 {
 	drm_i915_private_t *dev_priv = dev->dev_private;
 	struct eb_objects *eb;
@@ -998,17 +1016,17 @@ i915_gem_do_execbuffer(struct drm_device *dev, void *data,
 
 	/* Move the objects en-masse into the GTT, evicting if necessary. */
 	need_relocs = (args->flags & I915_EXEC_NO_RELOC) == 0;
-	ret = i915_gem_execbuffer_reserve(ring, &eb->objects, &need_relocs);
+	ret = i915_gem_execbuffer_reserve(ring, &eb->objects, vm, &need_relocs);
 	if (ret)
 		goto err;
 
 	/* The objects are in their final locations, apply the relocations. */
 	if (need_relocs)
-		ret = i915_gem_execbuffer_relocate(eb);
+		ret = i915_gem_execbuffer_relocate(eb, vm);
 	if (ret) {
 		if (ret == -EFAULT) {
 			ret = i915_gem_execbuffer_relocate_slow(dev, args, file, ring,
-								eb, exec);
+								eb, exec, vm);
 			BUG_ON(!mutex_is_locked(&dev->struct_mutex));
 		}
 		if (ret)
@@ -1059,7 +1077,8 @@ i915_gem_do_execbuffer(struct drm_device *dev, void *data,
 			goto err;
 	}
 
-	exec_start = i915_gem_obj_ggtt_offset(batch_obj) + args->batch_start_offset;
+	exec_start = i915_gem_obj_offset(batch_obj, vm) +
+		args->batch_start_offset;
 	exec_len = args->batch_len;
 	if (cliprects) {
 		for (i = 0; i < args->num_cliprects; i++) {
@@ -1084,11 +1103,11 @@ i915_gem_do_execbuffer(struct drm_device *dev, void *data,
 
 	trace_i915_gem_ring_dispatch(ring, intel_ring_get_seqno(ring), flags);
 
-	i915_gem_execbuffer_move_to_active(&eb->objects, ring);
+	i915_gem_execbuffer_move_to_active(&eb->objects, vm, ring);
 	i915_gem_execbuffer_retire_commands(dev, file, ring, batch_obj);
 
 err:
-	eb_destroy(eb);
+	eb_destroy(eb, vm);
 
 	mutex_unlock(&dev->struct_mutex);
 
@@ -1105,6 +1124,7 @@ int
 i915_gem_execbuffer(struct drm_device *dev, void *data,
 		    struct drm_file *file)
 {
+	struct drm_i915_private *dev_priv = dev->dev_private;
 	struct drm_i915_gem_execbuffer *args = data;
 	struct drm_i915_gem_execbuffer2 exec2;
 	struct drm_i915_gem_exec_object *exec_list = NULL;
@@ -1160,7 +1180,8 @@ i915_gem_execbuffer(struct drm_device *dev, void *data,
 	exec2.flags = I915_EXEC_RENDER;
 	i915_execbuffer2_set_context_id(exec2, 0);
 
-	ret = i915_gem_do_execbuffer(dev, data, file, &exec2, exec2_list);
+	ret = i915_gem_do_execbuffer(dev, data, file, &exec2, exec2_list,
+				     &dev_priv->gtt.base);
 	if (!ret) {
 		/* Copy the new buffer offsets back to the user's exec list. */
 		for (i = 0; i < args->buffer_count; i++)
@@ -1186,6 +1207,7 @@ int
 i915_gem_execbuffer2(struct drm_device *dev, void *data,
 		     struct drm_file *file)
 {
+	struct drm_i915_private *dev_priv = dev->dev_private;
 	struct drm_i915_gem_execbuffer2 *args = data;
 	struct drm_i915_gem_exec_object2 *exec2_list = NULL;
 	int ret;
@@ -1216,7 +1238,8 @@ i915_gem_execbuffer2(struct drm_device *dev, void *data,
 		return -EFAULT;
 	}
 
-	ret = i915_gem_do_execbuffer(dev, data, file, args, exec2_list);
+	ret = i915_gem_do_execbuffer(dev, data, file, args, exec2_list,
+				     &dev_priv->gtt.base);
 	if (!ret) {
 		/* Copy the new buffer offsets back to the user's exec list. */
 		ret = copy_to_user(to_user_ptr(args->buffers_ptr),
drivers/gpu/drm/i915/i915_gem_gtt.c +24 -17
index 298fc42..70ce2f6 100644
@@ -367,6 +367,8 @@ static int i915_gem_init_aliasing_ppgtt(struct drm_device *dev)
 			    ppgtt->base.total);
 	}
 
+	/* i915_init_vm(dev_priv, &ppgtt->base) */
+
 	return ret;
 }
 
@@ -386,17 +388,22 @@ void i915_ppgtt_bind_object(struct i915_hw_ppgtt *ppgtt,
 			    struct drm_i915_gem_object *obj,
 			    enum i915_cache_level cache_level)
 {
-	ppgtt->base.insert_entries(&ppgtt->base, obj->pages,
-				   i915_gem_obj_ggtt_offset(obj) >> PAGE_SHIFT,
-				   cache_level);
+	struct i915_address_space *vm = &ppgtt->base;
+	unsigned long obj_offset = i915_gem_obj_offset(obj, vm);
+
+	vm->insert_entries(vm, obj->pages,
+			   obj_offset >> PAGE_SHIFT,
+			   cache_level);
 }
 
 void i915_ppgtt_unbind_object(struct i915_hw_ppgtt *ppgtt,
 			      struct drm_i915_gem_object *obj)
 {
-	ppgtt->base.clear_range(&ppgtt->base,
-				i915_gem_obj_ggtt_offset(obj) >> PAGE_SHIFT,
-				obj->base.size >> PAGE_SHIFT);
+	struct i915_address_space *vm = &ppgtt->base;
+	unsigned long obj_offset = i915_gem_obj_offset(obj, vm);
+
+	vm->clear_range(vm, obj_offset >> PAGE_SHIFT,
+			obj->base.size >> PAGE_SHIFT);
 }
 
 extern int intel_iommu_gfx_mapped;
@@ -447,6 +454,9 @@ void i915_gem_restore_gtt_mappings(struct drm_device *dev)
 				       dev_priv->gtt.base.start / PAGE_SIZE,
 				       dev_priv->gtt.base.total / PAGE_SIZE);
 
+	if (dev_priv->mm.aliasing_ppgtt)
+		gen6_write_pdes(dev_priv->mm.aliasing_ppgtt);
+
 	list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
 		i915_gem_clflush_object(obj);
 		i915_gem_gtt_bind_object(obj, obj->cache_level);
@@ -625,7 +635,8 @@ void i915_gem_setup_global_gtt(struct drm_device *dev,
 	 * aperture.  One page should be enough to keep any prefetching inside
 	 * of the aperture.
 	 */
-	drm_i915_private_t *dev_priv = dev->dev_private;
+	struct drm_i915_private *dev_priv = dev->dev_private;
+	struct i915_address_space *ggtt_vm = &dev_priv->gtt.base;
 	struct drm_mm_node *entry;
 	struct drm_i915_gem_object *obj;
 	unsigned long hole_start, hole_end;
@@ -633,19 +644,19 @@ void i915_gem_setup_global_gtt(struct drm_device *dev,
 	BUG_ON(mappable_end > end);
 
 	/* Subtract the guard page ... */
-	drm_mm_init(&dev_priv->gtt.base.mm, start, end - start - PAGE_SIZE);
+	drm_mm_init(&ggtt_vm->mm, start, end - start - PAGE_SIZE);
 	if (!HAS_LLC(dev))
 		dev_priv->gtt.base.mm.color_adjust = i915_gtt_color_adjust;
 
 	/* Mark any preallocated objects as occupied */
 	list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
-		struct i915_vma *vma = __i915_gem_obj_to_vma(obj);
+		struct i915_vma *vma = i915_gem_obj_to_vma(obj, ggtt_vm);
 		int ret;
 		DRM_DEBUG_KMS("reserving preallocated space: %lx + %zx\n",
 			      i915_gem_obj_ggtt_offset(obj), obj->base.size);
 
 		WARN_ON(i915_gem_obj_ggtt_bound(obj));
-		ret = drm_mm_reserve_node(&dev_priv->gtt.base.mm, &vma->node);
+		ret = drm_mm_reserve_node(&ggtt_vm->mm, &vma->node);
 		if (ret)
 			DRM_DEBUG_KMS("Reservation failed\n");
 		obj->has_global_gtt_mapping = 1;
@@ -656,19 +667,15 @@ void i915_gem_setup_global_gtt(struct drm_device *dev,
 	dev_priv->gtt.base.total = end - start;
 
 	/* Clear any non-preallocated blocks */
-	drm_mm_for_each_hole(entry, &dev_priv->gtt.base.mm,
-			     hole_start, hole_end) {
+	drm_mm_for_each_hole(entry, &ggtt_vm->mm, hole_start, hole_end) {
 		const unsigned long count = (hole_end - hole_start) / PAGE_SIZE;
 		DRM_DEBUG_KMS("clearing unused GTT space: [%lx, %lx]\n",
 			      hole_start, hole_end);
-		dev_priv->gtt.base.clear_range(&dev_priv->gtt.base,
-					       hole_start / PAGE_SIZE,
-					       count);
+		ggtt_vm->clear_range(ggtt_vm, hole_start / PAGE_SIZE, count);
 	}
 
 	/* And finally clear the reserved guard page */
-	dev_priv->gtt.base.clear_range(&dev_priv->gtt.base,
-				       end / PAGE_SIZE - 1, 1);
+	ggtt_vm->clear_range(ggtt_vm, end / PAGE_SIZE - 1, 1);
 }
 
 static bool
drivers/gpu/drm/i915/i915_gem_stolen.c +1 -2
index 245eb1d..bfe61fa 100644
@@ -391,7 +391,7 @@ i915_gem_object_create_stolen_for_preallocated(struct drm_device *dev,
 	if (gtt_offset == I915_GTT_OFFSET_NONE)
 		return obj;
 
-	vma = i915_gem_vma_create(obj, &dev_priv->gtt.base);
+	vma = i915_gem_vma_create(obj, vm);
 	if (!vma) {
 		drm_gem_object_unreference(&obj->base);
 		return NULL;
@@ -404,8 +404,8 @@ i915_gem_object_create_stolen_for_preallocated(struct drm_device *dev,
 	 */
 	vma->node.start = gtt_offset;
 	vma->node.size = size;
-	if (drm_mm_initialized(&dev_priv->gtt.base.mm)) {
Quoted 8 lines

drivers/gpu/drm/i915/i915_gem_stolen.c i915_gem_object_create_stolen_for_preallocated(struct drm_device *dev, · line 408

Quoted 3 lines
drivers/gpu/drm/i915/i915_gem_stolen.c +2 -1
-		ret = drm_mm_reserve_node(&dev_priv->gtt.base.mm, &vma->node);
+	if (drm_mm_initialized(&vm->mm)) {
+		ret = drm_mm_reserve_node(&vm->mm, &vma->node);

These two hunks here for stolen look fishy - we only ever use the stolen preallocated stuff for objects with mappings in the global gtt. So keeping that explicit is imo the better approach. And tbh I'm confused where the local variable vm is from ...

If we don't create a vma for it, we potentially have to special case a bunch of places, I think. I'm not actually sure of this, but the overhead to do it is quite small.

Quoted 7 lines
Quoted 1 line

Anyway, I'll look this over again nd see what I think.

I'm not against the vma, I've just wonedered why you do the /dev_priv->gtt.base/vm/ replacement here since
- it's never gonna be used with another vm than ggtt
- this patch doesn't add the vm variable, so I'm even more confused where this started ;-)

It started from the rebase. In the original series, I did that "deferred_offset" thing, and having a vm variable made that code pass the checkpatch.pl. There wasn't a particular reason for naming it vm other than I had done it all over the place.

I've fixed this locally, leaving the vma, and renamed the local variable ggtt. It still has 3 uses in this function, so it's a bit less typing.

Quoted 6 lines

Cheers, Daniel

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
Signature · 1 line
Ben Widawsky, Intel Open Source Technology Center
#24 lore raw

Re: [PATCH 06/11] drm/i915: plumb VM into object operations

Quoted 4 lines · Ben Widawsky
Quoted 3 lines · Daniel Vetter
Quoted 2 lines · Ben Widawsky
Quoted 1 line · Daniel Vetter

On Mon, Jul 08, 2013 at 11:08:37PM -0700, Ben Widawsky wrote:

[snip]

Quoted 20 lines
Quoted 20 lines
Quoted 20 lines
Quoted 19 lines
Quoted 4 lines
drivers/gpu/drm/i915/i915_gem.c +0 -0
@@ -3333,12 +3376,15 @@ int i915_gem_object_set_cache_level(struct drm_i915_gem_object *obj,
 	}
 
 	if (!i915_gem_valid_gtt_space(dev, &vma->node, cache_level)) {

drivers/gpu/drm/i915/i915_gem.c int i915_gem_object_set_cache_level(struct drm_i915_gem_object *obj, · line 3386

Quoted 10 lines
drivers/gpu/drm/i915/i915_gem.c +4 -2
-		ret = i915_gem_object_unbind(obj);
+		ret = i915_gem_object_unbind(obj, vm);
 		if (ret)
 			return ret;
 	}
 
-	if (i915_gem_obj_ggtt_bound(obj)) {
+	list_for_each_entry(vm, &dev_priv->vm_list, global_link) {
+		if (!i915_gem_obj_bound(obj, vm))
+			continue;

Hm, shouldn't we have a per-object list of vmas? Or will that follow later on?

Self-correction: It exists already ... why can't we use this here?

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

Yes. That should work, I'll fix it and test it. It looks slightly worse IMO in terms of code clarity, but I don't mind the change.

Actually I think it'd gain in clarity, doing pte updatest (which set_cache_level does) on the vma instead of the (obj, vm) pair feels more natural. And we'd be able to drop lots of (obj, vm) -> vma lookups here.

That sounds good to me. Would you mind a patch on top?

If you want I guess we can refactor this after everything has settled. Has the upside that assessing whether using vma or (obj, vm) is much easier. So fine with me.

Quoted 90 lines
Quoted 84 lines
Quoted 84 lines
Quoted 83 lines
Quoted 73 lines
drivers/gpu/drm/i915/i915_gem.c +11 -4
+
 		ret = i915_gem_object_finish_gpu(obj);
 		if (ret)
 			return ret;
@@ -3361,7 +3407,7 @@ int i915_gem_object_set_cache_level(struct drm_i915_gem_object *obj,
 			i915_ppgtt_bind_object(dev_priv->mm.aliasing_ppgtt,
 					       obj, cache_level);
 
-		i915_gem_obj_ggtt_set_color(obj, cache_level);
+		i915_gem_obj_set_color(obj, vm, cache_level);
 	}
 
 	if (cache_level == I915_CACHE_NONE) {
@@ -3421,6 +3467,7 @@ int i915_gem_set_caching_ioctl(struct drm_device *dev, void *data,
 			       struct drm_file *file)
 {
 	struct drm_i915_gem_caching *args = data;
+	struct drm_i915_private *dev_priv;
 	struct drm_i915_gem_object *obj;
 	enum i915_cache_level level;
 	int ret;
@@ -3445,8 +3492,10 @@ int i915_gem_set_caching_ioctl(struct drm_device *dev, void *data,
 		ret = -ENOENT;
 		goto unlock;
 	}
+	dev_priv = obj->base.dev->dev_private;
 
-	ret = i915_gem_object_set_cache_level(obj, level);
+	/* FIXME: Add interface for specific VM? */
+	ret = i915_gem_object_set_cache_level(obj, &dev_priv->gtt.base, level);
 
 	drm_gem_object_unreference(&obj->base);
 unlock:
@@ -3464,6 +3513,7 @@ i915_gem_object_pin_to_display_plane(struct drm_i915_gem_object *obj,
 				     u32 alignment,
 				     struct intel_ring_buffer *pipelined)
 {
+	struct drm_i915_private *dev_priv = obj->base.dev->dev_private;
 	u32 old_read_domains, old_write_domain;
 	int ret;
 
@@ -3482,7 +3532,8 @@ i915_gem_object_pin_to_display_plane(struct drm_i915_gem_object *obj,
 	 * of uncaching, which would allow us to flush all the LLC-cached data
 	 * with that bit in the PTE to main memory with just one PIPE_CONTROL.
 	 */
-	ret = i915_gem_object_set_cache_level(obj, I915_CACHE_NONE);
+	ret = i915_gem_object_set_cache_level(obj, &dev_priv->gtt.base,
+					      I915_CACHE_NONE);
 	if (ret)
 		return ret;
 
@@ -3490,7 +3541,7 @@ i915_gem_object_pin_to_display_plane(struct drm_i915_gem_object *obj,
 	 * (e.g. libkms for the bootup splash), we have to ensure that we
 	 * always use map_and_fenceable for all scanout buffers.
 	 */
-	ret = i915_gem_object_pin(obj, alignment, true, false);
+	ret = i915_gem_ggtt_pin(obj, alignment, true, false);
 	if (ret)
 		return ret;
 
@@ -3633,6 +3684,7 @@ i915_gem_ring_throttle(struct drm_device *dev, struct drm_file *file)
 
 int
 i915_gem_object_pin(struct drm_i915_gem_object *obj,
+		    struct i915_address_space *vm,
 		    uint32_t alignment,
 		    bool map_and_fenceable,
 		    bool nonblocking)

drivers/gpu/drm/i915/i915_gem.c i915_gem_object_pin(struct drm_i915_gem_object *obj, · line 3697

Quoted 6 lines
drivers/gpu/drm/i915/i915_gem.c +1 -2
@@ -3642,26 +3694,29 @@ i915_gem_object_pin(struct drm_i915_gem_object *obj,
 	if (WARN_ON(obj->pin_count == DRM_I915_GEM_OBJECT_MAX_PIN_COUNT))
 		return -EBUSY;
 
-	if (i915_gem_obj_ggtt_bound(obj)) {
-		if ((alignment && i915_gem_obj_ggtt_offset(obj) & (alignment - 1)) ||
+	BUG_ON(map_and_fenceable && !i915_is_ggtt(vm));

WARN_ON, since presumably we can keep on going if we get this wrong (albeit with slightly corrupted state, so render corruptions might follow).

Quoted 5 lines
Quoted 2 lines

Can we make a deal, can we leave this as BUG_ON with a FIXME to convert it at the end of merging?

Adding a FIXME right above it will cause equal amounts of conflicts, so I don't see the point that much ...

Quoted 7 lines

I'm just really fearful that in doing the reworks I will end up with this condition, and I am afraid I will miss them if it's a WARN_ON. Definitely it's more likely to miss than a BUG.

Also, and we've disagreed on this a few times by now, this is an internal interface which I think should carry such a fatal error for this level of mistake.

Ime every time I argue this with myself and state your case it ends up biting me horribly because I'm regularly too incompetent and hit my very on BUG_ONs ;-) Hence why I insist so much on using WARN_ON wherever possible. Of course if people don't check they're logs that's a different matter (*cough* Jesse *cough*) ...

Quoted 2 lines

In any case I've made the change locally. Will yell at you later if I was right.

Getting yelled at is part of my job, so bring it on ;-)

[snip]

Quoted 28 lines
Quoted 19 lines
Quoted 19 lines
Quoted 18 lines

drivers/gpu/drm/i915/i915_gem.c i915_gem_inactive_shrink(struct shrinker *shrinker, struct shrink_control *sc) · line 4726

Quoted 12 lines
drivers/gpu/drm/i915/i915_gem.c +5 -3
@@ -4645,11 +4719,93 @@ i915_gem_inactive_shrink(struct shrinker *shrinker, struct shrink_control *sc)
 	list_for_each_entry(obj, &dev_priv->mm.unbound_list, global_list)
 		if (obj->pages_pin_count == 0)
 			cnt += obj->base.size >> PAGE_SHIFT;
-	list_for_each_entry(obj, &vm->inactive_list, mm_list)
-		if (obj->pin_count == 0 && obj->pages_pin_count == 0)
-			cnt += obj->base.size >> PAGE_SHIFT;
+
+	list_for_each_entry(vm, &dev_priv->vm_list, global_link)
+		list_for_each_entry(obj, &vm->inactive_list, global_list)
+			if (obj->pin_count == 0 && obj->pages_pin_count == 0)
+				cnt += obj->base.size >> PAGE_SHIFT;

Isn't this now double-counting objects? In the shrinker we only care about how much physical RAM an object occupies, not how much virtual space it occupies. So just walking the bound list of objects here should be good enough ...

Quoted 8 lines
Quoted 4 lines

Maybe I've misunderstood you. My code is wrong, but I think you're idea requires a prep patch because it changes functionality, right?

So let me know if I've understood you.

Don't we have both the bound and unbound list? So we could just switch over to counting the bound objects here ... Otherwise yes, we need a prep patch to create the bound list first.

Quoted 7 lines

Of course there is a bound list.

The old code automatically added the size of unbound objects with unpinned pages, and unpinned inactive objects with unpinned pages.

The latter check for inactive, needs to be checked for all VMAs. That was my point.

Oh right. The thing is that technically there's no reason to not also scan the active objects, i.e. just the unbound list. So yeah, sounds like we need a prep patch to switch to the unbound list here first. My apologies for being dense and not fully grasphing this right away.

Quoted 46 lines
Quoted 36 lines
Quoted 30 lines
Quoted 26 lines
Quoted 11 lines
drivers/gpu/drm/i915/i915_gem.c +3 -0
 	if (unlock)
 		mutex_unlock(&dev->struct_mutex);
 	return cnt;
 }
+
+/* All the new VM stuff */
+unsigned long i915_gem_obj_offset(struct drm_i915_gem_object *o,

drivers/gpu/drm/i915/i915_gem.c i915_gem_inactive_shrink(struct shrinker *shrinker, struct shrink_control *sc) · line 4744

Quoted 10 lines
drivers/gpu/drm/i915/i915_gem.c +10 -0
+				  struct i915_address_space *vm)
+{
+	struct drm_i915_private *dev_priv = o->base.dev->dev_private;
+	struct i915_vma *vma;
+
+	if (vm == &dev_priv->mm.aliasing_ppgtt->base)
+		vm = &dev_priv->gtt.base;
+
+	BUG_ON(list_empty(&o->vma_list));
+	list_for_each_entry(vma, &o->vma_list, vma_link) {

Imo the vma list walking here and in the other helpers below indicates that we should deal more often in vmas instead of (object, vm) pairs. Or is this again something that'll get fixed later on?

Quoted 3 lines

I just want to avoid diff churn, and it also makes reviewing easier if the foreshadowing is correct ;-) So generally I'd vote for more liberal sprinkling of obj_to_vma in callers.

Quoted 5 lines

It's not something I fixed in the whole series. I think it makes sense conceptually, to keep some things as <obj,vm> and others as direct vma.

If you want me to change something, you need to be more specific since no action specifically comes to mind at this point in the series.

Quoted 9 lines

It's just that the (obj, vm) -> vma lookup is a list-walk, so imo we should try to avoid it whenever possible. Since the vma has both and obj and a vm pointer the vma is imo strictly better than the (obj, vm) pair. And the look-up should be pushed down the callchain as much as possible.

So I think generally we want to pass the vma around to functions everywhere, and the (obj, vm) pair would be the exception (which needs special justification).

Quoted 7 lines

Without actually coding it, I am not sure. I think there are probably a decent number of reasonable exceptions where we want the object (ie. it's not really that much of a special case). In any case, I think we'll find you have to do this list walk at some point in the call chain anyway, but I can try to start changing around the code as a patch on top of this. I really want to leave as much as this patch in place as is, since it's decently tested (pre-rebase at least).

Ok, I can life with this if we clean things up afterwards. But imo vma->obj isn't worse for readability than just obj, and passing pairs of (obj,vm) around all the time just feels wrong conceptually. In C we have structs for this, and since we already have a suitable one created we might as well use it.

Aside: I know that we have the (ring, seqno) pair splattered all over the code. It's been on my todo to fix that ever since I've proposed to add a i915_gpu_sync_cookie with the original multi-ring enabling. As you can see I've been ignored, but I hope we can finally fix this with the dma_buf fence rework.

And we did just recently discover a bug where such a (ring, seqno) pair got mixed up, so imo not using vma is fraught with unecessary peril.

[snip]

Quoted 18 lines
Quoted 18 lines
Quoted 17 lines
Quoted 10 lines

drivers/gpu/drm/i915/i915_gem_evict.c int · line 158

Quoted 2 lines
drivers/gpu/drm/i915/i915_gem_evict.c +0 -0
@@ -158,13 +158,18 @@ int
 i915_gem_evict_everything(struct drm_device *dev)

I suspect evict_everything eventually wants a address_space *vm argument for those cases where we only want to evict everything in a given vm. Atm we have two use-cases of this:
- Called from the shrinker as a last-ditch effort. For that it should move _every_ object onto the unbound list.
- Called from execbuf for badly-fragmented address spaces to clean up the mess. For that case we only care about one address space.

The current thing is more or less a result of Chris' suggestions. A non-posted iteration did plumb the vm, and after reworking to the suggestion made by Chris, the vm didn't make much sense anymore.

For point #1, it requires VM prioritization I think. I don't really see any other way to fairly manage it.

Quoted 6 lines
Quoted 3 lines

The shrinker will rip out objects in lru order by walking first unbound and then bound objects. That's imo as fair as it gets, we don't need priorities between vms.

If you pass in a vm, the semantics would be, evict everything for the vm, right?

Yes.

Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

For point #2, that I agree it might be useful, but we can easily create a new function, and not call it "shrinker" to do it.

Quoted 7 lines
Quoted 5 lines

Well my point was that this function is called i915_gem_evict_everything(dev, vm) and for the first use case we simply pass in vm = NULL. But essentially thrashing the vm should be rare enough that for now we don't need to care.

IIRC, this is exactly how my original patch worked pre-Chris.

Oops. Do you or Chris still now the argument for changing things? Maybe I just don't see another facet of the issue at hand ...

[snip]

Quoted 29 lines
Quoted 29 lines
Quoted 28 lines
Quoted 14 lines
Quoted 14 lines
drivers/gpu/drm/i915/i915_gem_execbuffer.c +2 -0
@@ -475,6 +483,7 @@ i915_gem_execbuffer_unreserve_object(struct drm_i915_gem_object *obj)
 static int
 i915_gem_execbuffer_reserve(struct intel_ring_buffer *ring,
 			    struct list_head *objects,
+			    struct i915_address_space *vm,
 			    bool *need_relocs)
 {
 	struct drm_i915_gem_object *obj;
@@ -529,32 +538,37 @@ i915_gem_execbuffer_reserve(struct intel_ring_buffer *ring,
 		list_for_each_entry(obj, objects, exec_list) {
 			struct drm_i915_gem_exec_object2 *entry = obj->exec_entry;
 			bool need_fence, need_mappable;
+			u32 obj_offset;
 
Quoted 9 lines

drivers/gpu/drm/i915/i915_gem_execbuffer.c i915_gem_execbuffer_reserve(struct intel_ring_buffer *ring, · line 544

Quoted 3 lines
drivers/gpu/drm/i915/i915_gem_execbuffer.c +1 -1
-			if (!i915_gem_obj_ggtt_bound(obj))
+			if (!i915_gem_obj_bound(obj, vm))
 				continue;

I wonder a bit how we could avoid the multipler (obj, vm) -> vma lookups here ... Maybe we should cache them in some pointer somewhere (either in the eb object or by adding a new pointer to the object struct, e.g. obj->eb_vma, similar to obj->eb_list).

I agree, and even did this at one unposted patch too. However, I think it's a premature optimization which risks code correctness. So I think somewhere a FIXME needs to happen to address that issue. (Or if Chris complains bitterly about some perf hit).

Quoted 6 lines
Quoted 4 lines

If you bring up code correctness I'd vote strongly in favour of using vmas everywhere - vma has the (obj, vm) pair locked down, doing the lookup all the thing risks us mixing them up eventually and creating a hella lot of confusion ;-)

I think this is addressed with the previous comments.

See my example for (ring, seqno). I really strongly believe passing pairs is the wrong thing and passing structs is the right thing. Especially if we have one at hand. But I'm ok if you want to clean this up afterwards.

Ofc if the cleanup afterwards doesn't happend I'll be a bit pissed ;-)

[snip]

Quoted 39 lines
Quoted 31 lines
Quoted 31 lines
Quoted 18 lines
Quoted 18 lines
drivers/gpu/drm/i915/i915_gem_stolen.c +1 -2
index 245eb1d..bfe61fa 100644
@@ -391,7 +391,7 @@ i915_gem_object_create_stolen_for_preallocated(struct drm_device *dev,
 	if (gtt_offset == I915_GTT_OFFSET_NONE)
 		return obj;
 
-	vma = i915_gem_vma_create(obj, &dev_priv->gtt.base);
+	vma = i915_gem_vma_create(obj, vm);
 	if (!vma) {
 		drm_gem_object_unreference(&obj->base);
 		return NULL;
@@ -404,8 +404,8 @@ i915_gem_object_create_stolen_for_preallocated(struct drm_device *dev,
 	 */
 	vma->node.start = gtt_offset;
 	vma->node.size = size;
-	if (drm_mm_initialized(&dev_priv->gtt.base.mm)) {
Quoted 8 lines

drivers/gpu/drm/i915/i915_gem_stolen.c i915_gem_object_create_stolen_for_preallocated(struct drm_device *dev, · line 408

Quoted 3 lines
drivers/gpu/drm/i915/i915_gem_stolen.c +2 -1
-		ret = drm_mm_reserve_node(&dev_priv->gtt.base.mm, &vma->node);
+	if (drm_mm_initialized(&vm->mm)) {
+		ret = drm_mm_reserve_node(&vm->mm, &vma->node);

These two hunks here for stolen look fishy - we only ever use the stolen preallocated stuff for objects with mappings in the global gtt. So keeping that explicit is imo the better approach. And tbh I'm confused where the local variable vm is from ...

If we don't create a vma for it, we potentially have to special case a bunch of places, I think. I'm not actually sure of this, but the overhead to do it is quite small.

Quoted 7 lines
Quoted 1 line

Anyway, I'll look this over again nd see what I think.

I'm not against the vma, I've just wonedered why you do the /dev_priv->gtt.base/vm/ replacement here since
- it's never gonna be used with another vm than ggtt
- this patch doesn't add the vm variable, so I'm even more confused where this started ;-)

Quoted 7 lines

It started from the rebase. In the original series, I did that "deferred_offset" thing, and having a vm variable made that code pass the checkpatch.pl. There wasn't a particular reason for naming it vm other than I had done it all over the place.

I've fixed this locally, leaving the vma, and renamed the local variable ggtt. It still has 3 uses in this function, so it's a bit less typing.

Yeah, make sense to keep it then.

Cheers, Daniel

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
#25 lore raw

Re: [PATCH 06/11] drm/i915: plumb VM into object operations

Quoted 35 lines · Daniel Vetter
Quoted 4 lines · Ben Widawsky
Quoted 3 lines · Daniel Vetter
Quoted 2 lines · Ben Widawsky
Quoted 1 line · Daniel Vetter

On Mon, Jul 08, 2013 at 11:08:37PM -0700, Ben Widawsky wrote:

[snip]

Quoted 27 lines
Quoted 26 lines
Quoted 18 lines
Quoted 18 lines
Quoted 4 lines
drivers/gpu/drm/i915/i915_gem.c +0 -0
@@ -3333,12 +3376,15 @@ int i915_gem_object_set_cache_level(struct drm_i915_gem_object *obj,
 	}
 
 	if (!i915_gem_valid_gtt_space(dev, &vma->node, cache_level)) {

drivers/gpu/drm/i915/i915_gem.c int i915_gem_object_set_cache_level(struct drm_i915_gem_object *obj, · line 3386

Quoted 10 lines
drivers/gpu/drm/i915/i915_gem.c +4 -2
-		ret = i915_gem_object_unbind(obj);
+		ret = i915_gem_object_unbind(obj, vm);
 		if (ret)
 			return ret;
 	}
 
-	if (i915_gem_obj_ggtt_bound(obj)) {
+	list_for_each_entry(vm, &dev_priv->vm_list, global_link) {
+		if (!i915_gem_obj_bound(obj, vm))
+			continue;

Hm, shouldn't we have a per-object list of vmas? Or will that follow later on?

Quoted 4 lines
Quoted 1 line

Self-correction: It exists already ... why can't we use this here?

Yes. That should work, I'll fix it and test it. It looks slightly worse IMO in terms of code clarity, but I don't mind the change.

Actually I think it'd gain in clarity, doing pte updatest (which set_cache_level does) on the vma instead of the (obj, vm) pair feels more natural. And we'd be able to drop lots of (obj, vm) -> vma lookups here.

Quoted 5 lines
Quoted 1 line

That sounds good to me. Would you mind a patch on top?

If you want I guess we can refactor this after everything has settled. Has the upside that assessing whether using vma or (obj, vm) is much easier. So fine with me.

I think our time to get these merged in is quickly evaporating. I am sure you know this - just reminding you.

Quoted 219 lines
Quoted 91 lines
Quoted 85 lines
Quoted 85 lines
Quoted 84 lines
Quoted 74 lines
drivers/gpu/drm/i915/i915_gem.c +11 -4
+
 		ret = i915_gem_object_finish_gpu(obj);
 		if (ret)
 			return ret;
@@ -3361,7 +3407,7 @@ int i915_gem_object_set_cache_level(struct drm_i915_gem_object *obj,
 			i915_ppgtt_bind_object(dev_priv->mm.aliasing_ppgtt,
 					       obj, cache_level);
 
-		i915_gem_obj_ggtt_set_color(obj, cache_level);
+		i915_gem_obj_set_color(obj, vm, cache_level);
 	}
 
 	if (cache_level == I915_CACHE_NONE) {
@@ -3421,6 +3467,7 @@ int i915_gem_set_caching_ioctl(struct drm_device *dev, void *data,
 			       struct drm_file *file)
 {
 	struct drm_i915_gem_caching *args = data;
+	struct drm_i915_private *dev_priv;
 	struct drm_i915_gem_object *obj;
 	enum i915_cache_level level;
 	int ret;
@@ -3445,8 +3492,10 @@ int i915_gem_set_caching_ioctl(struct drm_device *dev, void *data,
 		ret = -ENOENT;
 		goto unlock;
 	}
+	dev_priv = obj->base.dev->dev_private;
 
-	ret = i915_gem_object_set_cache_level(obj, level);
+	/* FIXME: Add interface for specific VM? */
+	ret = i915_gem_object_set_cache_level(obj, &dev_priv->gtt.base, level);
 
 	drm_gem_object_unreference(&obj->base);
 unlock:
@@ -3464,6 +3513,7 @@ i915_gem_object_pin_to_display_plane(struct drm_i915_gem_object *obj,
 				     u32 alignment,
 				     struct intel_ring_buffer *pipelined)
 {
+	struct drm_i915_private *dev_priv = obj->base.dev->dev_private;
 	u32 old_read_domains, old_write_domain;
 	int ret;
 
@@ -3482,7 +3532,8 @@ i915_gem_object_pin_to_display_plane(struct drm_i915_gem_object *obj,
 	 * of uncaching, which would allow us to flush all the LLC-cached data
 	 * with that bit in the PTE to main memory with just one PIPE_CONTROL.
 	 */
-	ret = i915_gem_object_set_cache_level(obj, I915_CACHE_NONE);
+	ret = i915_gem_object_set_cache_level(obj, &dev_priv->gtt.base,
+					      I915_CACHE_NONE);
 	if (ret)
 		return ret;
 
@@ -3490,7 +3541,7 @@ i915_gem_object_pin_to_display_plane(struct drm_i915_gem_object *obj,
 	 * (e.g. libkms for the bootup splash), we have to ensure that we
 	 * always use map_and_fenceable for all scanout buffers.
 	 */
-	ret = i915_gem_object_pin(obj, alignment, true, false);
+	ret = i915_gem_ggtt_pin(obj, alignment, true, false);
 	if (ret)
 		return ret;
 
@@ -3633,6 +3684,7 @@ i915_gem_ring_throttle(struct drm_device *dev, struct drm_file *file)
 
 int
 i915_gem_object_pin(struct drm_i915_gem_object *obj,
+		    struct i915_address_space *vm,
 		    uint32_t alignment,
 		    bool map_and_fenceable,
 		    bool nonblocking)

drivers/gpu/drm/i915/i915_gem.c i915_gem_object_pin(struct drm_i915_gem_object *obj, · line 3697

Quoted 6 lines
drivers/gpu/drm/i915/i915_gem.c +1 -2
@@ -3642,26 +3694,29 @@ i915_gem_object_pin(struct drm_i915_gem_object *obj,
 	if (WARN_ON(obj->pin_count == DRM_I915_GEM_OBJECT_MAX_PIN_COUNT))
 		return -EBUSY;
 
-	if (i915_gem_obj_ggtt_bound(obj)) {
-		if ((alignment && i915_gem_obj_ggtt_offset(obj) & (alignment - 1)) ||
+	BUG_ON(map_and_fenceable && !i915_is_ggtt(vm));

WARN_ON, since presumably we can keep on going if we get this wrong (albeit with slightly corrupted state, so render corruptions might follow).

Quoted 5 lines
Quoted 2 lines

Can we make a deal, can we leave this as BUG_ON with a FIXME to convert it at the end of merging?

Adding a FIXME right above it will cause equal amounts of conflicts, so I don't see the point that much ...

Quoted 7 lines

I'm just really fearful that in doing the reworks I will end up with this condition, and I am afraid I will miss them if it's a WARN_ON. Definitely it's more likely to miss than a BUG.

Also, and we've disagreed on this a few times by now, this is an internal interface which I think should carry such a fatal error for this level of mistake.

Ime every time I argue this with myself and state your case it ends up biting me horribly because I'm regularly too incompetent and hit my very on BUG_ONs ;-) Hence why I insist so much on using WARN_ON wherever possible. Of course if people don't check they're logs that's a different matter (*cough* Jesse *cough*) ...

Quoted 2 lines

In any case I've made the change locally. Will yell at you later if I was right.

Getting yelled at is part of my job, so bring it on ;-)

[snip]

Quoted 28 lines
Quoted 19 lines
Quoted 19 lines
Quoted 18 lines

drivers/gpu/drm/i915/i915_gem.c i915_gem_inactive_shrink(struct shrinker *shrinker, struct shrink_control *sc) · line 4726

Quoted 12 lines
drivers/gpu/drm/i915/i915_gem.c +5 -3
@@ -4645,11 +4719,93 @@ i915_gem_inactive_shrink(struct shrinker *shrinker, struct shrink_control *sc)
 	list_for_each_entry(obj, &dev_priv->mm.unbound_list, global_list)
 		if (obj->pages_pin_count == 0)
 			cnt += obj->base.size >> PAGE_SHIFT;
-	list_for_each_entry(obj, &vm->inactive_list, mm_list)
-		if (obj->pin_count == 0 && obj->pages_pin_count == 0)
-			cnt += obj->base.size >> PAGE_SHIFT;
+
+	list_for_each_entry(vm, &dev_priv->vm_list, global_link)
+		list_for_each_entry(obj, &vm->inactive_list, global_list)
+			if (obj->pin_count == 0 && obj->pages_pin_count == 0)
+				cnt += obj->base.size >> PAGE_SHIFT;

Isn't this now double-counting objects? In the shrinker we only care about how much physical RAM an object occupies, not how much virtual space it occupies. So just walking the bound list of objects here should be good enough ...

Quoted 8 lines
Quoted 4 lines

Maybe I've misunderstood you. My code is wrong, but I think you're idea requires a prep patch because it changes functionality, right?

So let me know if I've understood you.

Don't we have both the bound and unbound list? So we could just switch over to counting the bound objects here ... Otherwise yes, we need a prep patch to create the bound list first.

Quoted 7 lines

Of course there is a bound list.

The old code automatically added the size of unbound objects with unpinned pages, and unpinned inactive objects with unpinned pages.

The latter check for inactive, needs to be checked for all VMAs. That was my point.

Oh right. The thing is that technically there's no reason to not also scan the active objects, i.e. just the unbound list. So yeah, sounds like we need a prep patch to switch to the unbound list here first. My apologies for being dense and not fully grasphing this right away.

Quoted 46 lines
Quoted 36 lines
Quoted 30 lines
Quoted 26 lines
Quoted 11 lines
drivers/gpu/drm/i915/i915_gem.c +3 -0
 	if (unlock)
 		mutex_unlock(&dev->struct_mutex);
 	return cnt;
 }
+
+/* All the new VM stuff */
+unsigned long i915_gem_obj_offset(struct drm_i915_gem_object *o,

drivers/gpu/drm/i915/i915_gem.c i915_gem_inactive_shrink(struct shrinker *shrinker, struct shrink_control *sc) · line 4744

Quoted 10 lines
drivers/gpu/drm/i915/i915_gem.c +10 -0
+				  struct i915_address_space *vm)
+{
+	struct drm_i915_private *dev_priv = o->base.dev->dev_private;
+	struct i915_vma *vma;
+
+	if (vm == &dev_priv->mm.aliasing_ppgtt->base)
+		vm = &dev_priv->gtt.base;
+
+	BUG_ON(list_empty(&o->vma_list));
+	list_for_each_entry(vma, &o->vma_list, vma_link) {

Imo the vma list walking here and in the other helpers below indicates that we should deal more often in vmas instead of (object, vm) pairs. Or is this again something that'll get fixed later on?

Quoted 3 lines

I just want to avoid diff churn, and it also makes reviewing easier if the foreshadowing is correct ;-) So generally I'd vote for more liberal sprinkling of obj_to_vma in callers.

Quoted 5 lines

It's not something I fixed in the whole series. I think it makes sense conceptually, to keep some things as <obj,vm> and others as direct vma.

If you want me to change something, you need to be more specific since no action specifically comes to mind at this point in the series.

Quoted 9 lines

It's just that the (obj, vm) -> vma lookup is a list-walk, so imo we should try to avoid it whenever possible. Since the vma has both and obj and a vm pointer the vma is imo strictly better than the (obj, vm) pair. And the look-up should be pushed down the callchain as much as possible.

So I think generally we want to pass the vma around to functions everywhere, and the (obj, vm) pair would be the exception (which needs special justification).

Quoted 7 lines

Without actually coding it, I am not sure. I think there are probably a decent number of reasonable exceptions where we want the object (ie. it's not really that much of a special case). In any case, I think we'll find you have to do this list walk at some point in the call chain anyway, but I can try to start changing around the code as a patch on top of this. I really want to leave as much as this patch in place as is, since it's decently tested (pre-rebase at least).

Ok, I can life with this if we clean things up afterwards. But imo vma->obj isn't worse for readability than just obj, and passing pairs of (obj,vm) around all the time just feels wrong conceptually. In C we have structs for this, and since we already have a suitable one created we might as well use it.

Aside: I know that we have the (ring, seqno) pair splattered all over the code. It's been on my todo to fix that ever since I've proposed to add a i915_gpu_sync_cookie with the original multi-ring enabling. As you can see I've been ignored, but I hope we can finally fix this with the dma_buf fence rework.

Quoted 4 lines

And we did just recently discover a bug where such a (ring, seqno) pair got mixed up, so imo not using vma is fraught with unecessary peril.

[snip]

As I wrote this code, I would say things as, "do this operation on that object, in so and so address space." That's more or less why I kept everything as obj, vm pairs. Since GEM is about BOs, at some fundamental level we're always talking about objects, and you need to translate an <obj,VM> pair into a VMA. The other motivation was of course to make the diffs more manageable and easier to write. It's way easier to add a new VM argument, than it is to do even more plumbing. As stated now in several places, I agree it very well might make sense to convert many functions in the call chain to VMAs, and do the lookup at the entry point from userspace, or whenever it's logical; and indeed in the long run I think it will lead to less buggy code.

Quoted 82 lines
Quoted 19 lines
Quoted 19 lines
Quoted 18 lines
Quoted 11 lines

drivers/gpu/drm/i915/i915_gem_evict.c int · line 158

Quoted 3 lines
drivers/gpu/drm/i915/i915_gem_evict.c +0 -0
@@ -158,13 +158,18 @@ int
 i915_gem_evict_everything(struct drm_device *dev)

I suspect evict_everything eventually wants a address_space *vm argument for those cases where we only want to evict everything in a given vm. Atm we have two use-cases of this:
- Called from the shrinker as a last-ditch effort. For that it should move _every_ object onto the unbound list.
- Called from execbuf for badly-fragmented address spaces to clean up the mess. For that case we only care about one address space.

The current thing is more or less a result of Chris' suggestions. A non-posted iteration did plumb the vm, and after reworking to the suggestion made by Chris, the vm didn't make much sense anymore.

For point #1, it requires VM prioritization I think. I don't really see any other way to fairly manage it.

Quoted 6 lines
Quoted 3 lines

The shrinker will rip out objects in lru order by walking first unbound and then bound objects. That's imo as fair as it gets, we don't need priorities between vms.

If you pass in a vm, the semantics would be, evict everything for the vm, right?

Yes.

Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

For point #2, that I agree it might be useful, but we can easily create a new function, and not call it "shrinker" to do it.

Quoted 7 lines
Quoted 5 lines

Well my point was that this function is called i915_gem_evict_everything(dev, vm) and for the first use case we simply pass in vm = NULL. But essentially thrashing the vm should be rare enough that for now we don't need to care.

IIRC, this is exactly how my original patch worked pre-Chris.

Oops. Do you or Chris still now the argument for changing things? Maybe I just don't see another facet of the issue at hand ...

[snip]

Quoted 29 lines
Quoted 29 lines
Quoted 28 lines
Quoted 14 lines
Quoted 14 lines
drivers/gpu/drm/i915/i915_gem_execbuffer.c +2 -0
@@ -475,6 +483,7 @@ i915_gem_execbuffer_unreserve_object(struct drm_i915_gem_object *obj)
 static int
 i915_gem_execbuffer_reserve(struct intel_ring_buffer *ring,
 			    struct list_head *objects,
+			    struct i915_address_space *vm,
 			    bool *need_relocs)
 {
 	struct drm_i915_gem_object *obj;
@@ -529,32 +538,37 @@ i915_gem_execbuffer_reserve(struct intel_ring_buffer *ring,
 		list_for_each_entry(obj, objects, exec_list) {
 			struct drm_i915_gem_exec_object2 *entry = obj->exec_entry;
 			bool need_fence, need_mappable;
+			u32 obj_offset;
 
Quoted 9 lines

drivers/gpu/drm/i915/i915_gem_execbuffer.c i915_gem_execbuffer_reserve(struct intel_ring_buffer *ring, · line 544

Quoted 3 lines
drivers/gpu/drm/i915/i915_gem_execbuffer.c +1 -1
-			if (!i915_gem_obj_ggtt_bound(obj))
+			if (!i915_gem_obj_bound(obj, vm))
 				continue;

I wonder a bit how we could avoid the multipler (obj, vm) -> vma lookups here ... Maybe we should cache them in some pointer somewhere (either in the eb object or by adding a new pointer to the object struct, e.g. obj->eb_vma, similar to obj->eb_list).

I agree, and even did this at one unposted patch too. However, I think it's a premature optimization which risks code correctness. So I think somewhere a FIXME needs to happen to address that issue. (Or if Chris complains bitterly about some perf hit).

Quoted 6 lines
Quoted 4 lines

If you bring up code correctness I'd vote strongly in favour of using vmas everywhere - vma has the (obj, vm) pair locked down, doing the lookup all the thing risks us mixing them up eventually and creating a hella lot of confusion ;-)

I think this is addressed with the previous comments.

Quoted 7 lines

See my example for (ring, seqno). I really strongly believe passing pairs is the wrong thing and passing structs is the right thing. Especially if we have one at hand. But I'm ok if you want to clean this up afterwards.

Ofc if the cleanup afterwards doesn't happend I'll be a bit pissed ;-)

[snip]

I think it's fair to not merge anything until I do it. I'm just asking that you let me do it as a patch on top of the series as opposed to doing a bunch of rebasing which I've shown historically time and again to screw up. Whether or not I should be better at rebasing isn't up for debate.

Quoted 45 lines
Quoted 45 lines
Quoted 32 lines
Quoted 32 lines
Quoted 19 lines
Quoted 19 lines
drivers/gpu/drm/i915/i915_gem_stolen.c +1 -2
index 245eb1d..bfe61fa 100644
@@ -391,7 +391,7 @@ i915_gem_object_create_stolen_for_preallocated(struct drm_device *dev,
 	if (gtt_offset == I915_GTT_OFFSET_NONE)
 		return obj;
 
-	vma = i915_gem_vma_create(obj, &dev_priv->gtt.base);
+	vma = i915_gem_vma_create(obj, vm);
 	if (!vma) {
 		drm_gem_object_unreference(&obj->base);
 		return NULL;
@@ -404,8 +404,8 @@ i915_gem_object_create_stolen_for_preallocated(struct drm_device *dev,
 	 */
 	vma->node.start = gtt_offset;
 	vma->node.size = size;
-	if (drm_mm_initialized(&dev_priv->gtt.base.mm)) {
Quoted 8 lines

drivers/gpu/drm/i915/i915_gem_stolen.c i915_gem_object_create_stolen_for_preallocated(struct drm_device *dev, · line 408

Quoted 3 lines
drivers/gpu/drm/i915/i915_gem_stolen.c +2 -1
-		ret = drm_mm_reserve_node(&dev_priv->gtt.base.mm, &vma->node);
+	if (drm_mm_initialized(&vm->mm)) {
+		ret = drm_mm_reserve_node(&vm->mm, &vma->node);

These two hunks here for stolen look fishy - we only ever use the stolen preallocated stuff for objects with mappings in the global gtt. So keeping that explicit is imo the better approach. And tbh I'm confused where the local variable vm is from ...

If we don't create a vma for it, we potentially have to special case a bunch of places, I think. I'm not actually sure of this, but the overhead to do it is quite small.

Quoted 7 lines
Quoted 1 line

Anyway, I'll look this over again nd see what I think.

I'm not against the vma, I've just wonedered why you do the /dev_priv->gtt.base/vm/ replacement here since
- it's never gonna be used with another vm than ggtt
- this patch doesn't add the vm variable, so I'm even more confused where this started ;-)

It started from the rebase. In the original series, I did that "deferred_offset" thing, and having a vm variable made that code pass the checkpatch.pl. There wasn't a particular reason for naming it vm other than I had done it all over the place.

Quoted 6 lines
Quoted 2 lines

I've fixed this locally, leaving the vma, and renamed the local variable ggtt. It still has 3 uses in this function, so it's a bit less typing.

Yeah, make sense to keep it then.

Cheers, Daniel

So here is the plan summing up from this mail thread and the other one...

I'm calling the series done until we get feedback from Chris on the eviction/shrinker code. Basically whatever he signs off on, I am willing to implement (assuming you agree). I am confident enough in my rebase abilities to at least fix that up when we get to it.

On top of this series, I am going smash the 3 patches which introduce bind/unbind function pointers. I am doing this because all this code already exists, plays nicely together, and has been tested.

Finally on top of this, I am going to have a [fairly large] patch to squash <obj,vm> pair into <vma> where I feel its appropriate. My plan for this is to basically look at a squashed version of all the patches where I introduce both arguments in one call, think about if it makes sense to me to think about the operation in terms of an object, or a vma, and then change as appropriate.

So the feedback I need from you:
1. Does that sound reasonable? If you want to call it weird, that's fine, but I think the diff churn is acceptable, and the series should be quite bisectable.
2. Are you aware of anything else I missed in other patch review which I haven't mentioned. I cannot find anything, and I think except for this patch I had updated everything locally.

You can see the 14 patches (11 here + 3 from the others series):
http://cgit.freedesktop.org/~bwidawsk/drm-intel/log/?h=ppgtt2

Hopefully this was all taken in good humor. I am not upset or anything, we just need to figure out how we can make some progress on this soon without making total crap, and without taking all my time (since I have a few other things to work on). I know you warned me about the latter a few weeks ago, but well, reality.

Signature · 1 line
Ben Widawsky, Intel Open Source Technology Center
#26 lore raw

Re: [PATCH 06/11] drm/i915: plumb VM into object operations

Quoted 7 lines · Ben Widawsky

So here is the plan summing up from this mail thread and the other one...

I'm calling the series done until we get feedback from Chris on the eviction/shrinker code. Basically whatever he signs off on, I am willing to implement (assuming you agree). I am confident enough in my rebase abilities to at least fix that up when we get to it.

I guess we could shovel this around after merging, shrinker gets frobbed around once a while for anyway ;-)

Quoted 11 lines

On top of this series, I am going smash the 3 patches which introduce bind/unbind function pointers. I am doing this because all this code already exists, plays nicely together, and has been tested.

Finally on top of this, I am going to have a [fairly large] patch to squash <obj,vm> pair into <vma> where I feel its appropriate. My plan for this is to basically look at a squashed version of all the patches where I introduce both arguments in one call, think about if it makes sense to me to think about the operation in terms of an object, or a vma, and then change as appropriate.

Quoted 4 lines

So the feedback I need from you:
1. Does that sound reasonable? If you want to call it weird, that's fine, but I think the diff churn is acceptable, and the series should be quite bisectable.

I guess I'll live ;-)

Quoted 3 lines

2. Are you aware of anything else I missed in other patch review which I haven't mentioned. I cannot find anything, and I think except for this patch I had updated everything locally.

Imo my review on the semantics of ->bind/unbind is fairly important, at least for discussion. Atm you just add some new abstraction (and kill some old one for which we've established some good use) without putting it to real use imo. Haven't read any responses yet though, it's early.

Quoted 8 lines

You can see the 14 patches (11 here + 3 from the others series):
http://cgit.freedesktop.org/~bwidawsk/drm-intel/log/?h=ppgtt2

Hopefully this was all taken in good humor. I am not upset or anything, we just need to figure out how we can make some progress on this soon without making total crap, and without taking all my time (since I have a few other things to work on). I know you warned me about the latter a few weeks ago, but well, reality.

Imo the first five patches should get the small reviews addressed and then merged. Atm that's what I'm kinda stalling on ... Then we can tackle the next little bit of this major work.
-Daniel

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
#27 lore raw

PATCH 7/11 drm/i915: Fix up map and fenceable for VMA

In reply to Ben Widawsky

formerly: "drm/i915: Create VMAs (part 3.5) - map and fenceable tracking"

The map_and_fenceable tracking is per object. GTT mapping, and fences only apply to global GTT. As such, object operations which are not performed on the global GTT should not effect mappable or fenceable characteristics.

Functionally, this commit could very well be squashed in to the previous patch which updated object operations to take a VM argument. This commit is split out because it's a bit tricky (or at least it was for me).

---
 drivers/gpu/drm/i915/i915_gem.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/gpu/drm/i915/i915_gem.c +6 -3
index 21015cd..501c590 100644
@@ -2635,7 +2635,7 @@ i915_gem_object_unbind(struct drm_i915_gem_object *obj,
 
 	trace_i915_gem_object_unbind(obj, vm);
 
-	if (obj->has_global_gtt_mapping)
+	if (obj->has_global_gtt_mapping && i915_is_ggtt(vm))
 		i915_gem_gtt_unbind_object(obj);
 	if (obj->has_aliasing_ppgtt_mapping) {
 		i915_ppgtt_unbind_object(dev_priv->mm.aliasing_ppgtt, obj);
@@ -2646,7 +2646,8 @@ i915_gem_object_unbind(struct drm_i915_gem_object *obj,
 
 	list_del(&obj->mm_list);
 	/* Avoid an unnecessary call to unbind on rebind. */
-	obj->map_and_fenceable = true;
+	if (i915_is_ggtt(vm))
+		obj->map_and_fenceable = true;
 
 	vma = i915_gem_obj_to_vma(obj, vm);
 	list_del(&vma->vma_link);
@@ -3213,7 +3214,9 @@ search_free:
 		i915_is_ggtt(vm) &&
 		vma->node.start + obj->base.size <= dev_priv->gtt.mappable_end;
 
-	obj->map_and_fenceable = mappable && fenceable;
+	/* Map and fenceable only changes if the VM is the global GGTT */
+	if (i915_is_ggtt(vm))
+		obj->map_and_fenceable = mappable && fenceable;
 
 	trace_i915_gem_object_bind(obj, vm, map_and_fenceable);
 	i915_gem_verify_gtt(dev);
Signature · 1 line
1.8.3.2
#28 lore raw

Re: [PATCH 07/11] drm/i915: Fix up map and fenceable for VMA

Quoted 22 lines · Ben Widawsky

formerly: "drm/i915: Create VMAs (part 3.5) - map and fenceable tracking"

The map_and_fenceable tracking is per object. GTT mapping, and fences only apply to global GTT. As such, object operations which are not performed on the global GTT should not effect mappable or fenceable characteristics.

Functionally, this commit could very well be squashed in to the previous patch which updated object operations to take a VM argument. This commit is split out because it's a bit tricky (or at least it was for me).

---
 drivers/gpu/drm/i915/i915_gem.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/gpu/drm/i915/i915_gem.c +0 -0
index 21015cd..501c590 100644

drivers/gpu/drm/i915/i915_gem.c i915_gem_object_unbind(struct drm_i915_gem_object *obj, · line 2639

Quoted 6 lines
drivers/gpu/drm/i915/i915_gem.c +1 -1
@@ -2635,7 +2635,7 @@ i915_gem_object_unbind(struct drm_i915_gem_object *obj,
 
 	trace_i915_gem_object_unbind(obj, vm);
 
-	if (obj->has_global_gtt_mapping)
+	if (obj->has_global_gtt_mapping && i915_is_ggtt(vm))
 		i915_gem_gtt_unbind_object(obj);

Wont this part be done as part of the global gtt clear_range callback?

drivers/gpu/drm/i915/i915_gem.c i915_gem_object_unbind(struct drm_i915_gem_object *obj, · line 2641

Quoted 2 lines
drivers/gpu/drm/i915/i915_gem.c +0 -0
 	if (obj->has_aliasing_ppgtt_mapping) {
 		i915_ppgtt_unbind_object(dev_priv->mm.aliasing_ppgtt, obj);

And I have a hunch that we should shovel the aliasing ppgtt clearing into the ggtt write_ptes/clear_range callbacks, too. Once all this has settled at least.

Quoted 28 lines
drivers/gpu/drm/i915/i915_gem.c +5 -2
@@ -2646,7 +2646,8 @@ i915_gem_object_unbind(struct drm_i915_gem_object *obj,
 
 	list_del(&obj->mm_list);
 	/* Avoid an unnecessary call to unbind on rebind. */
-	obj->map_and_fenceable = true;
+	if (i915_is_ggtt(vm))
+		obj->map_and_fenceable = true;
 
 	vma = i915_gem_obj_to_vma(obj, vm);
 	list_del(&vma->vma_link);
@@ -3213,7 +3214,9 @@ search_free:
 		i915_is_ggtt(vm) &&
 		vma->node.start + obj->base.size <= dev_priv->gtt.mappable_end;
 
-	obj->map_and_fenceable = mappable && fenceable;
+	/* Map and fenceable only changes if the VM is the global GGTT */
+	if (i915_is_ggtt(vm))
+		obj->map_and_fenceable = mappable && fenceable;
 
 	trace_i915_gem_object_bind(obj, vm, map_and_fenceable);
 	i915_gem_verify_gtt(dev);
Signature · 6 lines
1.8.3.2

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
#29 lore raw

Re: [PATCH 07/11] drm/i915: Fix up map and fenceable for VMA

Quoted 32 lines · Daniel Vetter
Quoted 22 lines · Ben Widawsky

formerly: "drm/i915: Create VMAs (part 3.5) - map and fenceable tracking"

The map_and_fenceable tracking is per object. GTT mapping, and fences only apply to global GTT. As such, object operations which are not performed on the global GTT should not effect mappable or fenceable characteristics.

Functionally, this commit could very well be squashed in to the previous patch which updated object operations to take a VM argument. This commit is split out because it's a bit tricky (or at least it was for me).

---
 drivers/gpu/drm/i915/i915_gem.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/gpu/drm/i915/i915_gem.c +0 -0
index 21015cd..501c590 100644

drivers/gpu/drm/i915/i915_gem.c i915_gem_object_unbind(struct drm_i915_gem_object *obj, · line 2639

Quoted 6 lines
drivers/gpu/drm/i915/i915_gem.c +1 -1
@@ -2635,7 +2635,7 @@ i915_gem_object_unbind(struct drm_i915_gem_object *obj,
 
 	trace_i915_gem_object_unbind(obj, vm);
 
-	if (obj->has_global_gtt_mapping)
+	if (obj->has_global_gtt_mapping && i915_is_ggtt(vm))
 		i915_gem_gtt_unbind_object(obj);

Wont this part be done as part of the global gtt clear_range callback?

Quoted 7 lines

drivers/gpu/drm/i915/i915_gem.c i915_gem_object_unbind(struct drm_i915_gem_object *obj, · line 2641

Quoted 2 lines
drivers/gpu/drm/i915/i915_gem.c +0 -0
 	if (obj->has_aliasing_ppgtt_mapping) {
 		i915_ppgtt_unbind_object(dev_priv->mm.aliasing_ppgtt, obj);

And I have a hunch that we should shovel the aliasing ppgtt clearing into the ggtt write_ptes/clear_range callbacks, too. Once all this has settled at least.

Addressing both comments at once:

First, this is a rebase mistake AFAICT because this hunk doesn't really belong in this patch anyway.

Eventually, I'd want to kill i915_gem_gtt_unbind_object, and i915_ppgtt_unbind_object. In the 66 patch series, I killed the latter, but decided to leave the former to make it clear that is a special case.

In the original 66 patch series, I did not move clear_range which is probably why this was left like this. I believe bind was fixed to just be vm->bleh()

If you're good with the idea, I'll add a new patch to remove those and use the i915_address_space. I'll do the same in other applicable places. It's easiest if I do that as a patch 12, I think, if you don't mind?

I do think this hunk belongs in another patch though until I do the above. I'm not really sure where to put that.

Quoted 33 lines
Quoted 28 lines
drivers/gpu/drm/i915/i915_gem.c +5 -2
@@ -2646,7 +2646,8 @@ i915_gem_object_unbind(struct drm_i915_gem_object *obj,
 
 	list_del(&obj->mm_list);
 	/* Avoid an unnecessary call to unbind on rebind. */
-	obj->map_and_fenceable = true;
+	if (i915_is_ggtt(vm))
+		obj->map_and_fenceable = true;
 
 	vma = i915_gem_obj_to_vma(obj, vm);
 	list_del(&vma->vma_link);
@@ -3213,7 +3214,9 @@ search_free:
 		i915_is_ggtt(vm) &&
 		vma->node.start + obj->base.size <= dev_priv->gtt.mappable_end;
 
-	obj->map_and_fenceable = mappable && fenceable;
+	/* Map and fenceable only changes if the VM is the global GGTT */
+	if (i915_is_ggtt(vm))
+		obj->map_and_fenceable = mappable && fenceable;
 
 	trace_i915_gem_object_bind(obj, vm, map_and_fenceable);
 	i915_gem_verify_gtt(dev);
Signature · 6 lines
1.8.3.2

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
Signature · 1 line
Ben Widawsky, Intel Open Source Technology Center
#30 lore raw

Re: [PATCH 07/11] drm/i915: Fix up map and fenceable for VMA

Quoted 50 lines · Ben Widawsky
Quoted 32 lines · Daniel Vetter
Quoted 22 lines · Ben Widawsky

formerly: "drm/i915: Create VMAs (part 3.5) - map and fenceable tracking"

The map_and_fenceable tracking is per object. GTT mapping, and fences only apply to global GTT. As such, object operations which are not performed on the global GTT should not effect mappable or fenceable characteristics.

Functionally, this commit could very well be squashed in to the previous patch which updated object operations to take a VM argument. This commit is split out because it's a bit tricky (or at least it was for me).

---
 drivers/gpu/drm/i915/i915_gem.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/gpu/drm/i915/i915_gem.c +0 -0
index 21015cd..501c590 100644

drivers/gpu/drm/i915/i915_gem.c i915_gem_object_unbind(struct drm_i915_gem_object *obj, · line 2639

Quoted 6 lines
drivers/gpu/drm/i915/i915_gem.c +1 -1
@@ -2635,7 +2635,7 @@ i915_gem_object_unbind(struct drm_i915_gem_object *obj,
 
 	trace_i915_gem_object_unbind(obj, vm);
 
-	if (obj->has_global_gtt_mapping)
+	if (obj->has_global_gtt_mapping && i915_is_ggtt(vm))
 		i915_gem_gtt_unbind_object(obj);

Wont this part be done as part of the global gtt clear_range callback?

Quoted 7 lines

drivers/gpu/drm/i915/i915_gem.c i915_gem_object_unbind(struct drm_i915_gem_object *obj, · line 2641

Quoted 2 lines
drivers/gpu/drm/i915/i915_gem.c +0 -0
 	if (obj->has_aliasing_ppgtt_mapping) {
 		i915_ppgtt_unbind_object(dev_priv->mm.aliasing_ppgtt, obj);

And I have a hunch that we should shovel the aliasing ppgtt clearing into the ggtt write_ptes/clear_range callbacks, too. Once all this has settled at least.

Addressing both comments at once:

First, this is a rebase mistake AFAICT because this hunk doesn't really belong in this patch anyway.

Eventually, I'd want to kill i915_gem_gtt_unbind_object, and i915_ppgtt_unbind_object. In the 66 patch series, I killed the latter, but decided to leave the former to make it clear that is a special case.

Quoted 7 lines

In the original 66 patch series, I did not move clear_range which is probably why this was left like this. I believe bind was fixed to just be vm->bleh()

If you're good with the idea, I'll add a new patch to remove those and use the i915_address_space. I'll do the same in other applicable places. It's easiest if I do that as a patch 12, I think, if you don't mind?

Yeah, I'm ok with that, since the above hunk that started my thinking will go away anyway.

Quoted 2 lines

I do think this hunk belongs in another patch though until I do the above. I'm not really sure where to put that.

If you want to keep it, please add a comment explaining why and how exactly it will get fixed up. In case of doubt just create a new patch to highlight the special case imo.
-Daniel

Quoted 38 lines
Quoted 35 lines
Quoted 30 lines
drivers/gpu/drm/i915/i915_gem.c +5 -2
@@ -2646,7 +2646,8 @@ i915_gem_object_unbind(struct drm_i915_gem_object *obj,
 
 	list_del(&obj->mm_list);
 	/* Avoid an unnecessary call to unbind on rebind. */
-	obj->map_and_fenceable = true;
+	if (i915_is_ggtt(vm))
+		obj->map_and_fenceable = true;
 
 	vma = i915_gem_obj_to_vma(obj, vm);
 	list_del(&vma->vma_link);
@@ -3213,7 +3214,9 @@ search_free:
 		i915_is_ggtt(vm) &&
 		vma->node.start + obj->base.size <= dev_priv->gtt.mappable_end;
 
-	obj->map_and_fenceable = mappable && fenceable;
+	/* Map and fenceable only changes if the VM is the global GGTT */
+	if (i915_is_ggtt(vm))
+		obj->map_and_fenceable = mappable && fenceable;
 
 	trace_i915_gem_object_bind(obj, vm, map_and_fenceable);
 	i915_gem_verify_gtt(dev);
Signature · 6 lines
1.8.3.2

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
Signature · 1 line
Ben Widawsky, Intel Open Source Technology Center
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
#31 lore raw

PATCH 8/11 drm/i915: mm_list is per VMA

In reply to Ben Widawsky

formerly: "drm/i915: Create VMAs (part 5) - move mm_list"

The mm_list is used for the active/inactive LRUs. Since those LRUs are per address space, the link should be per VMx .

Because we'll only ever have 1 VMA before this point, it's not incorrect to defer this change until this point in the patch series, and doing it here makes the change much easier to understand.

v2: only bump GGTT LRU in i915_gem_object_set_to_gtt_domain (Chris)

v3: Moved earlier in the series

---
 drivers/gpu/drm/i915/i915_debugfs.c    | 53 ++++++++++++++++++++++------------
 drivers/gpu/drm/i915/i915_drv.h        |  5 ++--
 drivers/gpu/drm/i915/i915_gem.c        | 34 ++++++++++++++--------
 drivers/gpu/drm/i915/i915_gem_evict.c  | 14 ++++-----
 drivers/gpu/drm/i915/i915_gem_stolen.c |  2 +-
 drivers/gpu/drm/i915/i915_irq.c        | 37 ++++++++++++++----------
 6 files changed, 87 insertions(+), 58 deletions(-)
drivers/gpu/drm/i915/i915_debugfs.c +34 -19
index 867ed07..163ca6b 100644
@@ -157,7 +157,7 @@ static int i915_gem_object_list_info(struct seq_file *m, void *data)
 	struct drm_device *dev = node->minor->dev;
 	struct drm_i915_private *dev_priv = dev->dev_private;
 	struct i915_address_space *vm = &dev_priv->gtt.base;
-	struct drm_i915_gem_object *obj;
+	struct i915_vma *vma;
 	size_t total_obj_size, total_gtt_size;
 	int count, ret;
 
@@ -165,6 +165,7 @@ static int i915_gem_object_list_info(struct seq_file *m, void *data)
 	if (ret)
 		return ret;
 
+	/* FIXME: the user of this interface might want more than just GGTT */
 	switch (list) {
 	case ACTIVE_LIST:
 		seq_puts(m, "Active:\n");
@@ -180,12 +181,12 @@ static int i915_gem_object_list_info(struct seq_file *m, void *data)
 	}
 
 	total_obj_size = total_gtt_size = count = 0;
-	list_for_each_entry(obj, head, mm_list) {
-		seq_puts(m, "   ");
-		describe_obj(m, obj);
-		seq_putc(m, '\n');
-		total_obj_size += obj->base.size;
-		total_gtt_size += i915_gem_obj_ggtt_size(obj);
+	list_for_each_entry(vma, head, mm_list) {
+		seq_printf(m, "   ");
+		describe_obj(m, vma->obj);
+		seq_printf(m, "\n");
+		total_obj_size += vma->obj->base.size;
+		total_gtt_size += i915_gem_obj_size(vma->obj, vma->vm);
 		count++;
 	}
 	mutex_unlock(&dev->struct_mutex);
@@ -233,7 +234,18 @@ static int per_file_stats(int id, void *ptr, void *data)
 	return 0;
 }
 
-static int i915_gem_object_info(struct seq_file *m, void *data)
+#define count_vmas(list, member) do { \
+	list_for_each_entry(vma, list, member) { \
+		size += i915_gem_obj_ggtt_size(vma->obj); \
+		++count; \
+		if (vma->obj->map_and_fenceable) { \
+			mappable_size += i915_gem_obj_ggtt_size(vma->obj); \
+			++mappable_count; \
+		} \
+	} \
+} while (0)
+
+static int i915_gem_object_info(struct seq_file *m, void* data)
 {
 	struct drm_info_node *node = (struct drm_info_node *) m->private;
 	struct drm_device *dev = node->minor->dev;
@@ -243,6 +255,7 @@ static int i915_gem_object_info(struct seq_file *m, void *data)
 	struct drm_i915_gem_object *obj;
 	struct i915_address_space *vm = &dev_priv->gtt.base;
 	struct drm_file *file;
+	struct i915_vma *vma;
 	int ret;
 
 	ret = mutex_lock_interruptible(&dev->struct_mutex);
@@ -259,12 +272,12 @@ static int i915_gem_object_info(struct seq_file *m, void *data)
 		   count, mappable_count, size, mappable_size);
 
 	size = count = mappable_size = mappable_count = 0;
-	count_objects(&vm->active_list, mm_list);
+	count_vmas(&vm->active_list, mm_list);
 	seq_printf(m, "  %u [%u] active objects, %zu [%zu] bytes\n",
 		   count, mappable_count, size, mappable_size);
 
 	size = count = mappable_size = mappable_count = 0;
-	count_objects(&vm->inactive_list, mm_list);
+	count_vmas(&vm->inactive_list, mm_list);
 	seq_printf(m, "  %u [%u] inactive objects, %zu [%zu] bytes\n",
 		   count, mappable_count, size, mappable_size);
 
@@ -2037,7 +2050,8 @@ i915_drop_caches_set(void *data, u64 val)
 	struct drm_device *dev = data;
 	struct drm_i915_private *dev_priv = dev->dev_private;
 	struct drm_i915_gem_object *obj, *next;
-	struct i915_address_space *vm = &dev_priv->gtt.base;
+	struct i915_address_space *vm;
+	struct i915_vma *vma, *x;
 	int ret;
 
 	DRM_DEBUG_DRIVER("Dropping caches: 0x%08llx\n", val);
@@ -2058,14 +2072,15 @@ i915_drop_caches_set(void *data, u64 val)
 		i915_gem_retire_requests(dev);
 
 	if (val & DROP_BOUND) {
-		list_for_each_entry_safe(obj, next, &vm->inactive_list,
-					 mm_list) {
-			if (obj->pin_count)
-				continue;
-
-			ret = i915_gem_object_unbind(obj, &dev_priv->gtt.base);
-			if (ret)
-				goto unlock;
+		list_for_each_entry(vm, &dev_priv->vm_list, global_link) {
+			list_for_each_entry_safe(vma, x, &vm->inactive_list,
+						 mm_list)
+				if (vma->obj->pin_count == 0) {
+					ret = i915_gem_object_unbind(vma->obj,
+								     vm);
+					if (ret)
+						goto unlock;
+				}
 		}
 	}
 
drivers/gpu/drm/i915/i915_drv.h +3 -2
index 48baccc..48105f8 100644
@@ -541,6 +541,9 @@ struct i915_vma {
 	struct drm_i915_gem_object *obj;
 	struct i915_address_space *vm;
 
+	/** This object's place on the active/inactive lists */
+	struct list_head mm_list;
+
 	struct list_head vma_link; /* Link in the object's VMA list */
 };
 
@@ -1242,9 +1245,7 @@ struct drm_i915_gem_object {
 	struct drm_mm_node *stolen;
 	struct list_head global_list;
 
-	/** This object's place on the active/inactive lists */
 	struct list_head ring_list;
-	struct list_head mm_list;
 	/** This object's place in the batchbuffer or on the eviction list */
 	struct list_head exec_list;
 
drivers/gpu/drm/i915/i915_gem.c +22 -12
index 501c590..9a58363 100644
@@ -1888,6 +1888,7 @@ i915_gem_object_move_to_active(struct drm_i915_gem_object *obj,
 	struct drm_device *dev = obj->base.dev;
 	struct drm_i915_private *dev_priv = dev->dev_private;
 	u32 seqno = intel_ring_get_seqno(ring);
+	struct i915_vma *vma;
 
 	BUG_ON(ring == NULL);
 	obj->ring = ring;
@@ -1899,7 +1900,8 @@ i915_gem_object_move_to_active(struct drm_i915_gem_object *obj,
 	}
 
 	/* Move from whatever list we were on to the tail of execution. */
-	list_move_tail(&obj->mm_list, &vm->active_list);
+	vma = i915_gem_obj_to_vma(obj, vm);
+	list_move_tail(&vma->mm_list, &vm->active_list);
 	list_move_tail(&obj->ring_list, &ring->active_list);
 
 	obj->last_read_seqno = seqno;
@@ -1922,10 +1924,13 @@ static void
 i915_gem_object_move_to_inactive(struct drm_i915_gem_object *obj,
 				 struct i915_address_space *vm)
 {
+	struct i915_vma *vma;
+
 	BUG_ON(obj->base.write_domain & ~I915_GEM_GPU_DOMAINS);
 	BUG_ON(!obj->active);
 
-	list_move_tail(&obj->mm_list, &vm->inactive_list);
+	vma = i915_gem_obj_to_vma(obj, vm);
+	list_move_tail(&vma->mm_list, &vm->inactive_list);
 
 	list_del_init(&obj->ring_list);
 	obj->ring = NULL;
@@ -2287,9 +2292,9 @@ void i915_gem_restore_fences(struct drm_device *dev)
 void i915_gem_reset(struct drm_device *dev)
 {
 	struct drm_i915_private *dev_priv = dev->dev_private;
-	struct i915_address_space *vm;
-	struct drm_i915_gem_object *obj;
 	struct intel_ring_buffer *ring;
+	struct i915_address_space *vm;
+	struct i915_vma *vma;
 	int i;
 
 	for_each_ring(ring, dev_priv, i)
@@ -2299,8 +2304,8 @@ void i915_gem_reset(struct drm_device *dev)
 	 * necessary invalidation upon reuse.
 	 */
 	list_for_each_entry(vm, &dev_priv->vm_list, global_link)
-		list_for_each_entry(obj, &vm->inactive_list, mm_list)
-			obj->base.read_domains &= ~I915_GEM_GPU_DOMAINS;
+		list_for_each_entry(vma, &vm->inactive_list, mm_list)
+			vma->obj->base.read_domains &= ~I915_GEM_GPU_DOMAINS;
 
 	i915_gem_restore_fences(dev);
 }
@@ -2644,12 +2649,12 @@ i915_gem_object_unbind(struct drm_i915_gem_object *obj,
 	i915_gem_gtt_finish_object(obj);
 	i915_gem_object_unpin_pages(obj);
 
-	list_del(&obj->mm_list);
 	/* Avoid an unnecessary call to unbind on rebind. */
 	if (i915_is_ggtt(vm))
 		obj->map_and_fenceable = true;
 
 	vma = i915_gem_obj_to_vma(obj, vm);
+	list_del(&vma->mm_list);
 	list_del(&vma->vma_link);
 	drm_mm_remove_node(&vma->node);
 	i915_gem_vma_destroy(vma);
@@ -3197,7 +3202,7 @@ search_free:
 	}
 
 	list_move_tail(&obj->global_list, &dev_priv->mm.bound_list);
-	list_add_tail(&obj->mm_list, &vm->inactive_list);
+	list_add_tail(&vma->mm_list, &vm->inactive_list);
 
 	/* Keep GGTT vmas first to make debug easier */
 	if (i915_is_ggtt(vm))
@@ -3354,9 +3359,14 @@ i915_gem_object_set_to_gtt_domain(struct drm_i915_gem_object *obj, bool write)
 					    old_write_domain);
 
 	/* And bump the LRU for this access */
-	if (i915_gem_object_is_inactive(obj))
-		list_move_tail(&obj->mm_list,
-			       &dev_priv->gtt.base.inactive_list);
+	if (i915_gem_object_is_inactive(obj)) {
+		struct i915_vma *vma = i915_gem_obj_to_vma(obj,
+							   &dev_priv->gtt.base);
+		if (vma)
+			list_move_tail(&vma->mm_list,
+				       &dev_priv->gtt.base.inactive_list);
+
+	}
 
 	return 0;
 }
@@ -3931,7 +3941,6 @@ unlock:
 void i915_gem_object_init(struct drm_i915_gem_object *obj,
 			  const struct drm_i915_gem_object_ops *ops)
 {
-	INIT_LIST_HEAD(&obj->mm_list);
 	INIT_LIST_HEAD(&obj->global_list);
 	INIT_LIST_HEAD(&obj->ring_list);
 	INIT_LIST_HEAD(&obj->exec_list);
@@ -4071,6 +4080,7 @@ struct i915_vma *i915_gem_vma_create(struct drm_i915_gem_object *obj,
 		return ERR_PTR(-ENOMEM);
 
 	INIT_LIST_HEAD(&vma->vma_link);
+	INIT_LIST_HEAD(&vma->mm_list);
 	vma->vm = vm;
 	vma->obj = obj;
 
drivers/gpu/drm/i915/i915_gem_evict.c +6 -8
index 32efdc0..18a44a9 100644
@@ -87,8 +87,7 @@ i915_gem_evict_something(struct drm_device *dev, struct i915_address_space *vm,
 		drm_mm_init_scan(&vm->mm, min_size, alignment, cache_level);
 
 	/* First see if there is a large enough contiguous idle region... */
-	list_for_each_entry(obj, &vm->inactive_list, mm_list) {
-		struct i915_vma *vma = i915_gem_obj_to_vma(obj, vm);
+	list_for_each_entry(vma, &vm->inactive_list, mm_list) {
 		if (mark_free(vma, &unwind_list))
 			goto found;
 	}
@@ -97,8 +96,7 @@ i915_gem_evict_something(struct drm_device *dev, struct i915_address_space *vm,
 		goto none;
 
 	/* Now merge in the soon-to-be-expired objects... */
-	list_for_each_entry(obj, &vm->active_list, mm_list) {
-		struct i915_vma *vma = i915_gem_obj_to_vma(obj, vm);
+	list_for_each_entry(vma, &vm->active_list, mm_list) {
 		if (mark_free(vma, &unwind_list))
 			goto found;
 	}
@@ -159,7 +157,7 @@ i915_gem_evict_everything(struct drm_device *dev)
 {
 	drm_i915_private_t *dev_priv = dev->dev_private;
 	struct i915_address_space *vm;
-	struct drm_i915_gem_object *obj, *next;
+	struct i915_vma *vma, *next;
 	bool lists_empty = true;
 	int ret;
 
@@ -187,9 +185,9 @@ i915_gem_evict_everything(struct drm_device *dev)
 
 	/* Having flushed everything, unbind() should never raise an error */
 	list_for_each_entry(vm, &dev_priv->vm_list, global_link) {
-		list_for_each_entry_safe(obj, next, &vm->inactive_list, mm_list)
-			if (obj->pin_count == 0)
-				WARN_ON(i915_gem_object_unbind(obj, vm));
+		list_for_each_entry_safe(vma, next, &vm->inactive_list, mm_list)
+			if (vma->obj->pin_count == 0)
+				WARN_ON(i915_gem_object_unbind(vma->obj, vm));
 	}
 
 	return 0;
drivers/gpu/drm/i915/i915_gem_stolen.c +1 -1
index bfe61fa..58b2613 100644
@@ -415,7 +415,7 @@ i915_gem_object_create_stolen_for_preallocated(struct drm_device *dev,
 	obj->has_global_gtt_mapping = 1;
 
 	list_add_tail(&obj->global_list, &dev_priv->mm.bound_list);
-	list_add_tail(&obj->mm_list, &vm->inactive_list);
+	list_add_tail(&vma->mm_list, &dev_priv->gtt.base.inactive_list);
 
 	return obj;
 
drivers/gpu/drm/i915/i915_irq.c +21 -16
index 28fa0ff..e065232 100644
@@ -1640,11 +1640,11 @@ static void capture_bo(struct drm_i915_error_buffer *err,
 static u32 capture_active_bo(struct drm_i915_error_buffer *err,
 			     int count, struct list_head *head)
 {
-	struct drm_i915_gem_object *obj;
+	struct i915_vma *vma;
 	int i = 0;
 
-	list_for_each_entry(obj, head, mm_list) {
-		capture_bo(err++, obj);
+	list_for_each_entry(vma, head, mm_list) {
+		capture_bo(err++, vma->obj);
 		if (++i == count)
 			break;
 	}
@@ -1706,8 +1706,9 @@ static struct drm_i915_error_object *
 i915_error_first_batchbuffer(struct drm_i915_private *dev_priv,
 			     struct intel_ring_buffer *ring)
 {
+	struct i915_address_space *vm;
+	struct i915_vma *vma;
 	struct drm_i915_gem_object *obj;
-	struct i915_address_space *vm = &dev_priv->gtt.base;
 	u32 seqno;
 
 	if (!ring->get_seqno)
@@ -1729,20 +1730,23 @@ i915_error_first_batchbuffer(struct drm_i915_private *dev_priv,
 	}
 
 	seqno = ring->get_seqno(ring, false);
-	list_for_each_entry(obj, &vm->active_list, mm_list) {
-		if (obj->ring != ring)
-			continue;
+	list_for_each_entry(vm, &dev_priv->vm_list, global_link) {
+		list_for_each_entry(vma, &vm->active_list, mm_list) {
+			obj = vma->obj;
+			if (obj->ring != ring)
+				continue;
 
-		if (i915_seqno_passed(seqno, obj->last_read_seqno))
-			continue;
+			if (i915_seqno_passed(seqno, obj->last_read_seqno))
+				continue;
 
-		if ((obj->base.read_domains & I915_GEM_DOMAIN_COMMAND) == 0)
-			continue;
+			if ((obj->base.read_domains & I915_GEM_DOMAIN_COMMAND) == 0)
+				continue;
 
-		/* We need to copy these to an anonymous buffer as the simplest
-		 * method to avoid being overwritten by userspace.
-		 */
-		return i915_error_object_create(dev_priv, obj);
+			/* We need to copy these to an anonymous buffer as the simplest
+			 * method to avoid being overwritten by userspace.
+			 */
+			return i915_error_object_create(dev_priv, obj);
+		}
 	}
 
 	return NULL;
@@ -1863,11 +1867,12 @@ static void i915_gem_capture_buffers(struct drm_i915_private *dev_priv,
 				     struct drm_i915_error_state *error)
 {
 	struct drm_i915_gem_object *obj;
+	struct i915_vma *vma;
 	struct i915_address_space *vm = &dev_priv->gtt.base;
 	int i;
 
 	i = 0;
-	list_for_each_entry(obj, &vm->active_list, mm_list)
+	list_for_each_entry(vma, &vm->active_list, mm_list)
 		i++;
 	error->active_bo_count = i;
 	list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list)
Signature · 1 line
1.8.3.2
#32 lore raw

Re: [PATCH 08/11] drm/i915: mm_list is per VMA

Quoted 9 lines · Ben Widawsky

formerly: "drm/i915: Create VMAs (part 5) - move mm_list"

The mm_list is used for the active/inactive LRUs. Since those LRUs are per address space, the link should be per VMx .

Because we'll only ever have 1 VMA before this point, it's not incorrect to defer this change until this point in the patch series, and doing it here makes the change much easier to understand.

Quoted 5 lines

v2: only bump GGTT LRU in i915_gem_object_set_to_gtt_domain (Chris)

v3: Moved earlier in the series

The commit message seems to miss the explanation (that I've written for you) why we move only some of the dev_priv->mm lrus, not all of them ...

Quoted 412 lines
---
 drivers/gpu/drm/i915/i915_debugfs.c    | 53 ++++++++++++++++++++++------------
 drivers/gpu/drm/i915/i915_drv.h        |  5 ++--
 drivers/gpu/drm/i915/i915_gem.c        | 34 ++++++++++++++--------
 drivers/gpu/drm/i915/i915_gem_evict.c  | 14 ++++-----
 drivers/gpu/drm/i915/i915_gem_stolen.c |  2 +-
 drivers/gpu/drm/i915/i915_irq.c        | 37 ++++++++++++++----------
 6 files changed, 87 insertions(+), 58 deletions(-)
drivers/gpu/drm/i915/i915_debugfs.c +34 -19
index 867ed07..163ca6b 100644
@@ -157,7 +157,7 @@ static int i915_gem_object_list_info(struct seq_file *m, void *data)
 	struct drm_device *dev = node->minor->dev;
 	struct drm_i915_private *dev_priv = dev->dev_private;
 	struct i915_address_space *vm = &dev_priv->gtt.base;
-	struct drm_i915_gem_object *obj;
+	struct i915_vma *vma;
 	size_t total_obj_size, total_gtt_size;
 	int count, ret;
 
@@ -165,6 +165,7 @@ static int i915_gem_object_list_info(struct seq_file *m, void *data)
 	if (ret)
 		return ret;
 
+	/* FIXME: the user of this interface might want more than just GGTT */
 	switch (list) {
 	case ACTIVE_LIST:
 		seq_puts(m, "Active:\n");
@@ -180,12 +181,12 @@ static int i915_gem_object_list_info(struct seq_file *m, void *data)
 	}
 
 	total_obj_size = total_gtt_size = count = 0;
-	list_for_each_entry(obj, head, mm_list) {
-		seq_puts(m, "   ");
-		describe_obj(m, obj);
-		seq_putc(m, '\n');
-		total_obj_size += obj->base.size;
-		total_gtt_size += i915_gem_obj_ggtt_size(obj);
+	list_for_each_entry(vma, head, mm_list) {
+		seq_printf(m, "   ");
+		describe_obj(m, vma->obj);
+		seq_printf(m, "\n");
+		total_obj_size += vma->obj->base.size;
+		total_gtt_size += i915_gem_obj_size(vma->obj, vma->vm);
 		count++;
 	}
 	mutex_unlock(&dev->struct_mutex);
@@ -233,7 +234,18 @@ static int per_file_stats(int id, void *ptr, void *data)
 	return 0;
 }
 
-static int i915_gem_object_info(struct seq_file *m, void *data)
+#define count_vmas(list, member) do { \
+	list_for_each_entry(vma, list, member) { \
+		size += i915_gem_obj_ggtt_size(vma->obj); \
+		++count; \
+		if (vma->obj->map_and_fenceable) { \
+			mappable_size += i915_gem_obj_ggtt_size(vma->obj); \
+			++mappable_count; \
+		} \
+	} \
+} while (0)
+
+static int i915_gem_object_info(struct seq_file *m, void* data)
 {
 	struct drm_info_node *node = (struct drm_info_node *) m->private;
 	struct drm_device *dev = node->minor->dev;
@@ -243,6 +255,7 @@ static int i915_gem_object_info(struct seq_file *m, void *data)
 	struct drm_i915_gem_object *obj;
 	struct i915_address_space *vm = &dev_priv->gtt.base;
 	struct drm_file *file;
+	struct i915_vma *vma;
 	int ret;
 
 	ret = mutex_lock_interruptible(&dev->struct_mutex);
@@ -259,12 +272,12 @@ static int i915_gem_object_info(struct seq_file *m, void *data)
 		   count, mappable_count, size, mappable_size);
 
 	size = count = mappable_size = mappable_count = 0;
-	count_objects(&vm->active_list, mm_list);
+	count_vmas(&vm->active_list, mm_list);
 	seq_printf(m, "  %u [%u] active objects, %zu [%zu] bytes\n",
 		   count, mappable_count, size, mappable_size);
 
 	size = count = mappable_size = mappable_count = 0;
-	count_objects(&vm->inactive_list, mm_list);
+	count_vmas(&vm->inactive_list, mm_list);
 	seq_printf(m, "  %u [%u] inactive objects, %zu [%zu] bytes\n",
 		   count, mappable_count, size, mappable_size);
 
@@ -2037,7 +2050,8 @@ i915_drop_caches_set(void *data, u64 val)
 	struct drm_device *dev = data;
 	struct drm_i915_private *dev_priv = dev->dev_private;
 	struct drm_i915_gem_object *obj, *next;
-	struct i915_address_space *vm = &dev_priv->gtt.base;
+	struct i915_address_space *vm;
+	struct i915_vma *vma, *x;
 	int ret;
 
 	DRM_DEBUG_DRIVER("Dropping caches: 0x%08llx\n", val);
@@ -2058,14 +2072,15 @@ i915_drop_caches_set(void *data, u64 val)
 		i915_gem_retire_requests(dev);
 
 	if (val & DROP_BOUND) {
-		list_for_each_entry_safe(obj, next, &vm->inactive_list,
-					 mm_list) {
-			if (obj->pin_count)
-				continue;
-
-			ret = i915_gem_object_unbind(obj, &dev_priv->gtt.base);
-			if (ret)
-				goto unlock;
+		list_for_each_entry(vm, &dev_priv->vm_list, global_link) {
+			list_for_each_entry_safe(vma, x, &vm->inactive_list,
+						 mm_list)
+				if (vma->obj->pin_count == 0) {
+					ret = i915_gem_object_unbind(vma->obj,
+								     vm);
+					if (ret)
+						goto unlock;
+				}
 		}
 	}
 
drivers/gpu/drm/i915/i915_drv.h +3 -2
index 48baccc..48105f8 100644
@@ -541,6 +541,9 @@ struct i915_vma {
 	struct drm_i915_gem_object *obj;
 	struct i915_address_space *vm;
 
+	/** This object's place on the active/inactive lists */
+	struct list_head mm_list;
+
 	struct list_head vma_link; /* Link in the object's VMA list */
 };
 
@@ -1242,9 +1245,7 @@ struct drm_i915_gem_object {
 	struct drm_mm_node *stolen;
 	struct list_head global_list;
 
-	/** This object's place on the active/inactive lists */
 	struct list_head ring_list;
-	struct list_head mm_list;
 	/** This object's place in the batchbuffer or on the eviction list */
 	struct list_head exec_list;
 
drivers/gpu/drm/i915/i915_gem.c +22 -12
index 501c590..9a58363 100644
@@ -1888,6 +1888,7 @@ i915_gem_object_move_to_active(struct drm_i915_gem_object *obj,
 	struct drm_device *dev = obj->base.dev;
 	struct drm_i915_private *dev_priv = dev->dev_private;
 	u32 seqno = intel_ring_get_seqno(ring);
+	struct i915_vma *vma;
 
 	BUG_ON(ring == NULL);
 	obj->ring = ring;
@@ -1899,7 +1900,8 @@ i915_gem_object_move_to_active(struct drm_i915_gem_object *obj,
 	}
 
 	/* Move from whatever list we were on to the tail of execution. */
-	list_move_tail(&obj->mm_list, &vm->active_list);
+	vma = i915_gem_obj_to_vma(obj, vm);
+	list_move_tail(&vma->mm_list, &vm->active_list);
 	list_move_tail(&obj->ring_list, &ring->active_list);
 
 	obj->last_read_seqno = seqno;
@@ -1922,10 +1924,13 @@ static void
 i915_gem_object_move_to_inactive(struct drm_i915_gem_object *obj,
 				 struct i915_address_space *vm)
 {
+	struct i915_vma *vma;
+
 	BUG_ON(obj->base.write_domain & ~I915_GEM_GPU_DOMAINS);
 	BUG_ON(!obj->active);
 
-	list_move_tail(&obj->mm_list, &vm->inactive_list);
+	vma = i915_gem_obj_to_vma(obj, vm);
+	list_move_tail(&vma->mm_list, &vm->inactive_list);
 
 	list_del_init(&obj->ring_list);
 	obj->ring = NULL;
@@ -2287,9 +2292,9 @@ void i915_gem_restore_fences(struct drm_device *dev)
 void i915_gem_reset(struct drm_device *dev)
 {
 	struct drm_i915_private *dev_priv = dev->dev_private;
-	struct i915_address_space *vm;
-	struct drm_i915_gem_object *obj;
 	struct intel_ring_buffer *ring;
+	struct i915_address_space *vm;
+	struct i915_vma *vma;
 	int i;
 
 	for_each_ring(ring, dev_priv, i)
@@ -2299,8 +2304,8 @@ void i915_gem_reset(struct drm_device *dev)
 	 * necessary invalidation upon reuse.
 	 */
 	list_for_each_entry(vm, &dev_priv->vm_list, global_link)
-		list_for_each_entry(obj, &vm->inactive_list, mm_list)
-			obj->base.read_domains &= ~I915_GEM_GPU_DOMAINS;
+		list_for_each_entry(vma, &vm->inactive_list, mm_list)
+			vma->obj->base.read_domains &= ~I915_GEM_GPU_DOMAINS;
 
 	i915_gem_restore_fences(dev);
 }
@@ -2644,12 +2649,12 @@ i915_gem_object_unbind(struct drm_i915_gem_object *obj,
 	i915_gem_gtt_finish_object(obj);
 	i915_gem_object_unpin_pages(obj);
 
-	list_del(&obj->mm_list);
 	/* Avoid an unnecessary call to unbind on rebind. */
 	if (i915_is_ggtt(vm))
 		obj->map_and_fenceable = true;
 
 	vma = i915_gem_obj_to_vma(obj, vm);
+	list_del(&vma->mm_list);
 	list_del(&vma->vma_link);
 	drm_mm_remove_node(&vma->node);
 	i915_gem_vma_destroy(vma);
@@ -3197,7 +3202,7 @@ search_free:
 	}
 
 	list_move_tail(&obj->global_list, &dev_priv->mm.bound_list);
-	list_add_tail(&obj->mm_list, &vm->inactive_list);
+	list_add_tail(&vma->mm_list, &vm->inactive_list);
 
 	/* Keep GGTT vmas first to make debug easier */
 	if (i915_is_ggtt(vm))
@@ -3354,9 +3359,14 @@ i915_gem_object_set_to_gtt_domain(struct drm_i915_gem_object *obj, bool write)
 					    old_write_domain);
 
 	/* And bump the LRU for this access */
-	if (i915_gem_object_is_inactive(obj))
-		list_move_tail(&obj->mm_list,
-			       &dev_priv->gtt.base.inactive_list);
+	if (i915_gem_object_is_inactive(obj)) {
+		struct i915_vma *vma = i915_gem_obj_to_vma(obj,
+							   &dev_priv->gtt.base);
+		if (vma)
+			list_move_tail(&vma->mm_list,
+				       &dev_priv->gtt.base.inactive_list);
+
+	}
 
 	return 0;
 }
@@ -3931,7 +3941,6 @@ unlock:
 void i915_gem_object_init(struct drm_i915_gem_object *obj,
 			  const struct drm_i915_gem_object_ops *ops)
 {
-	INIT_LIST_HEAD(&obj->mm_list);
 	INIT_LIST_HEAD(&obj->global_list);
 	INIT_LIST_HEAD(&obj->ring_list);
 	INIT_LIST_HEAD(&obj->exec_list);
@@ -4071,6 +4080,7 @@ struct i915_vma *i915_gem_vma_create(struct drm_i915_gem_object *obj,
 		return ERR_PTR(-ENOMEM);
 
 	INIT_LIST_HEAD(&vma->vma_link);
+	INIT_LIST_HEAD(&vma->mm_list);
 	vma->vm = vm;
 	vma->obj = obj;
 
drivers/gpu/drm/i915/i915_gem_evict.c +6 -8
index 32efdc0..18a44a9 100644
@@ -87,8 +87,7 @@ i915_gem_evict_something(struct drm_device *dev, struct i915_address_space *vm,
 		drm_mm_init_scan(&vm->mm, min_size, alignment, cache_level);
 
 	/* First see if there is a large enough contiguous idle region... */
-	list_for_each_entry(obj, &vm->inactive_list, mm_list) {
-		struct i915_vma *vma = i915_gem_obj_to_vma(obj, vm);
+	list_for_each_entry(vma, &vm->inactive_list, mm_list) {
 		if (mark_free(vma, &unwind_list))
 			goto found;
 	}
@@ -97,8 +96,7 @@ i915_gem_evict_something(struct drm_device *dev, struct i915_address_space *vm,
 		goto none;
 
 	/* Now merge in the soon-to-be-expired objects... */
-	list_for_each_entry(obj, &vm->active_list, mm_list) {
-		struct i915_vma *vma = i915_gem_obj_to_vma(obj, vm);
+	list_for_each_entry(vma, &vm->active_list, mm_list) {
 		if (mark_free(vma, &unwind_list))
 			goto found;
 	}
@@ -159,7 +157,7 @@ i915_gem_evict_everything(struct drm_device *dev)
 {
 	drm_i915_private_t *dev_priv = dev->dev_private;
 	struct i915_address_space *vm;
-	struct drm_i915_gem_object *obj, *next;
+	struct i915_vma *vma, *next;
 	bool lists_empty = true;
 	int ret;
 
@@ -187,9 +185,9 @@ i915_gem_evict_everything(struct drm_device *dev)
 
 	/* Having flushed everything, unbind() should never raise an error */
 	list_for_each_entry(vm, &dev_priv->vm_list, global_link) {
-		list_for_each_entry_safe(obj, next, &vm->inactive_list, mm_list)
-			if (obj->pin_count == 0)
-				WARN_ON(i915_gem_object_unbind(obj, vm));
+		list_for_each_entry_safe(vma, next, &vm->inactive_list, mm_list)
+			if (vma->obj->pin_count == 0)
+				WARN_ON(i915_gem_object_unbind(vma->obj, vm));
 	}
 
 	return 0;
drivers/gpu/drm/i915/i915_gem_stolen.c +1 -1
index bfe61fa..58b2613 100644
@@ -415,7 +415,7 @@ i915_gem_object_create_stolen_for_preallocated(struct drm_device *dev,
 	obj->has_global_gtt_mapping = 1;
 
 	list_add_tail(&obj->global_list, &dev_priv->mm.bound_list);
-	list_add_tail(&obj->mm_list, &vm->inactive_list);
+	list_add_tail(&vma->mm_list, &dev_priv->gtt.base.inactive_list);
 
 	return obj;
 
drivers/gpu/drm/i915/i915_irq.c +21 -16
index 28fa0ff..e065232 100644
@@ -1640,11 +1640,11 @@ static void capture_bo(struct drm_i915_error_buffer *err,
 static u32 capture_active_bo(struct drm_i915_error_buffer *err,
 			     int count, struct list_head *head)
 {
-	struct drm_i915_gem_object *obj;
+	struct i915_vma *vma;
 	int i = 0;
 
-	list_for_each_entry(obj, head, mm_list) {
-		capture_bo(err++, obj);
+	list_for_each_entry(vma, head, mm_list) {
+		capture_bo(err++, vma->obj);
 		if (++i == count)
 			break;
 	}
@@ -1706,8 +1706,9 @@ static struct drm_i915_error_object *
 i915_error_first_batchbuffer(struct drm_i915_private *dev_priv,
 			     struct intel_ring_buffer *ring)
 {
+	struct i915_address_space *vm;
+	struct i915_vma *vma;
 	struct drm_i915_gem_object *obj;
-	struct i915_address_space *vm = &dev_priv->gtt.base;
 	u32 seqno;
 
 	if (!ring->get_seqno)
@@ -1729,20 +1730,23 @@ i915_error_first_batchbuffer(struct drm_i915_private *dev_priv,
 	}
 
 	seqno = ring->get_seqno(ring, false);
-	list_for_each_entry(obj, &vm->active_list, mm_list) {
-		if (obj->ring != ring)
-			continue;
+	list_for_each_entry(vm, &dev_priv->vm_list, global_link) {
+		list_for_each_entry(vma, &vm->active_list, mm_list) {
+			obj = vma->obj;
+			if (obj->ring != ring)
+				continue;
 
-		if (i915_seqno_passed(seqno, obj->last_read_seqno))
-			continue;
+			if (i915_seqno_passed(seqno, obj->last_read_seqno))
+				continue;
 
-		if ((obj->base.read_domains & I915_GEM_DOMAIN_COMMAND) == 0)
-			continue;
+			if ((obj->base.read_domains & I915_GEM_DOMAIN_COMMAND) == 0)
+				continue;
 
-		/* We need to copy these to an anonymous buffer as the simplest
-		 * method to avoid being overwritten by userspace.
-		 */
-		return i915_error_object_create(dev_priv, obj);
+			/* We need to copy these to an anonymous buffer as the simplest
+			 * method to avoid being overwritten by userspace.
+			 */
+			return i915_error_object_create(dev_priv, obj);
+		}
 	}
 
 	return NULL;
@@ -1863,11 +1867,12 @@ static void i915_gem_capture_buffers(struct drm_i915_private *dev_priv,
 				     struct drm_i915_error_state *error)
 {
 	struct drm_i915_gem_object *obj;
+	struct i915_vma *vma;
 	struct i915_address_space *vm = &dev_priv->gtt.base;
 	int i;
 
 	i = 0;
-	list_for_each_entry(obj, &vm->active_list, mm_list)
+	list_for_each_entry(vma, &vm->active_list, mm_list)
 		i++;
 	error->active_bo_count = i;
 	list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list)
Signature · 6 lines
1.8.3.2

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
#33 lore raw

Re: [PATCH 08/11] drm/i915: mm_list is per VMA

Quoted 10 lines · Daniel Vetter
Quoted 9 lines · Ben Widawsky

formerly: "drm/i915: Create VMAs (part 5) - move mm_list"

The mm_list is used for the active/inactive LRUs. Since those LRUs are per address space, the link should be per VMx .

Because we'll only ever have 1 VMA before this point, it's not incorrect to defer this change until this point in the patch series, and doing it here makes the change much easier to understand.

Quoted 8 lines
Quoted 5 lines

v2: only bump GGTT LRU in i915_gem_object_set_to_gtt_domain (Chris)

v3: Moved earlier in the series

The commit message seems to miss the explanation (that I've written for you) why we move only some of the dev_priv->mm lrus, not all of them ...

Yes. This is a mistake. I had copied into a commit message with "Shamelessly manipulated out of Daniel:" I'm not sure where it went. After I address the other issues, I'll decide if I resubmit the whole series or just this fixed.

Sorry about that, it wasn't ignorance, just incompetence.

Quoted 417 lines
Quoted 412 lines
---
 drivers/gpu/drm/i915/i915_debugfs.c    | 53 ++++++++++++++++++++++------------
 drivers/gpu/drm/i915/i915_drv.h        |  5 ++--
 drivers/gpu/drm/i915/i915_gem.c        | 34 ++++++++++++++--------
 drivers/gpu/drm/i915/i915_gem_evict.c  | 14 ++++-----
 drivers/gpu/drm/i915/i915_gem_stolen.c |  2 +-
 drivers/gpu/drm/i915/i915_irq.c        | 37 ++++++++++++++----------
 6 files changed, 87 insertions(+), 58 deletions(-)
drivers/gpu/drm/i915/i915_debugfs.c +34 -19
index 867ed07..163ca6b 100644
@@ -157,7 +157,7 @@ static int i915_gem_object_list_info(struct seq_file *m, void *data)
 	struct drm_device *dev = node->minor->dev;
 	struct drm_i915_private *dev_priv = dev->dev_private;
 	struct i915_address_space *vm = &dev_priv->gtt.base;
-	struct drm_i915_gem_object *obj;
+	struct i915_vma *vma;
 	size_t total_obj_size, total_gtt_size;
 	int count, ret;
 
@@ -165,6 +165,7 @@ static int i915_gem_object_list_info(struct seq_file *m, void *data)
 	if (ret)
 		return ret;
 
+	/* FIXME: the user of this interface might want more than just GGTT */
 	switch (list) {
 	case ACTIVE_LIST:
 		seq_puts(m, "Active:\n");
@@ -180,12 +181,12 @@ static int i915_gem_object_list_info(struct seq_file *m, void *data)
 	}
 
 	total_obj_size = total_gtt_size = count = 0;
-	list_for_each_entry(obj, head, mm_list) {
-		seq_puts(m, "   ");
-		describe_obj(m, obj);
-		seq_putc(m, '\n');
-		total_obj_size += obj->base.size;
-		total_gtt_size += i915_gem_obj_ggtt_size(obj);
+	list_for_each_entry(vma, head, mm_list) {
+		seq_printf(m, "   ");
+		describe_obj(m, vma->obj);
+		seq_printf(m, "\n");
+		total_obj_size += vma->obj->base.size;
+		total_gtt_size += i915_gem_obj_size(vma->obj, vma->vm);
 		count++;
 	}
 	mutex_unlock(&dev->struct_mutex);
@@ -233,7 +234,18 @@ static int per_file_stats(int id, void *ptr, void *data)
 	return 0;
 }
 
-static int i915_gem_object_info(struct seq_file *m, void *data)
+#define count_vmas(list, member) do { \
+	list_for_each_entry(vma, list, member) { \
+		size += i915_gem_obj_ggtt_size(vma->obj); \
+		++count; \
+		if (vma->obj->map_and_fenceable) { \
+			mappable_size += i915_gem_obj_ggtt_size(vma->obj); \
+			++mappable_count; \
+		} \
+	} \
+} while (0)
+
+static int i915_gem_object_info(struct seq_file *m, void* data)
 {
 	struct drm_info_node *node = (struct drm_info_node *) m->private;
 	struct drm_device *dev = node->minor->dev;
@@ -243,6 +255,7 @@ static int i915_gem_object_info(struct seq_file *m, void *data)
 	struct drm_i915_gem_object *obj;
 	struct i915_address_space *vm = &dev_priv->gtt.base;
 	struct drm_file *file;
+	struct i915_vma *vma;
 	int ret;
 
 	ret = mutex_lock_interruptible(&dev->struct_mutex);
@@ -259,12 +272,12 @@ static int i915_gem_object_info(struct seq_file *m, void *data)
 		   count, mappable_count, size, mappable_size);
 
 	size = count = mappable_size = mappable_count = 0;
-	count_objects(&vm->active_list, mm_list);
+	count_vmas(&vm->active_list, mm_list);
 	seq_printf(m, "  %u [%u] active objects, %zu [%zu] bytes\n",
 		   count, mappable_count, size, mappable_size);
 
 	size = count = mappable_size = mappable_count = 0;
-	count_objects(&vm->inactive_list, mm_list);
+	count_vmas(&vm->inactive_list, mm_list);
 	seq_printf(m, "  %u [%u] inactive objects, %zu [%zu] bytes\n",
 		   count, mappable_count, size, mappable_size);
 
@@ -2037,7 +2050,8 @@ i915_drop_caches_set(void *data, u64 val)
 	struct drm_device *dev = data;
 	struct drm_i915_private *dev_priv = dev->dev_private;
 	struct drm_i915_gem_object *obj, *next;
-	struct i915_address_space *vm = &dev_priv->gtt.base;
+	struct i915_address_space *vm;
+	struct i915_vma *vma, *x;
 	int ret;
 
 	DRM_DEBUG_DRIVER("Dropping caches: 0x%08llx\n", val);
@@ -2058,14 +2072,15 @@ i915_drop_caches_set(void *data, u64 val)
 		i915_gem_retire_requests(dev);
 
 	if (val & DROP_BOUND) {
-		list_for_each_entry_safe(obj, next, &vm->inactive_list,
-					 mm_list) {
-			if (obj->pin_count)
-				continue;
-
-			ret = i915_gem_object_unbind(obj, &dev_priv->gtt.base);
-			if (ret)
-				goto unlock;
+		list_for_each_entry(vm, &dev_priv->vm_list, global_link) {
+			list_for_each_entry_safe(vma, x, &vm->inactive_list,
+						 mm_list)
+				if (vma->obj->pin_count == 0) {
+					ret = i915_gem_object_unbind(vma->obj,
+								     vm);
+					if (ret)
+						goto unlock;
+				}
 		}
 	}
 
drivers/gpu/drm/i915/i915_drv.h +3 -2
index 48baccc..48105f8 100644
@@ -541,6 +541,9 @@ struct i915_vma {
 	struct drm_i915_gem_object *obj;
 	struct i915_address_space *vm;
 
+	/** This object's place on the active/inactive lists */
+	struct list_head mm_list;
+
 	struct list_head vma_link; /* Link in the object's VMA list */
 };
 
@@ -1242,9 +1245,7 @@ struct drm_i915_gem_object {
 	struct drm_mm_node *stolen;
 	struct list_head global_list;
 
-	/** This object's place on the active/inactive lists */
 	struct list_head ring_list;
-	struct list_head mm_list;
 	/** This object's place in the batchbuffer or on the eviction list */
 	struct list_head exec_list;
 
drivers/gpu/drm/i915/i915_gem.c +22 -12
index 501c590..9a58363 100644
@@ -1888,6 +1888,7 @@ i915_gem_object_move_to_active(struct drm_i915_gem_object *obj,
 	struct drm_device *dev = obj->base.dev;
 	struct drm_i915_private *dev_priv = dev->dev_private;
 	u32 seqno = intel_ring_get_seqno(ring);
+	struct i915_vma *vma;
 
 	BUG_ON(ring == NULL);
 	obj->ring = ring;
@@ -1899,7 +1900,8 @@ i915_gem_object_move_to_active(struct drm_i915_gem_object *obj,
 	}
 
 	/* Move from whatever list we were on to the tail of execution. */
-	list_move_tail(&obj->mm_list, &vm->active_list);
+	vma = i915_gem_obj_to_vma(obj, vm);
+	list_move_tail(&vma->mm_list, &vm->active_list);
 	list_move_tail(&obj->ring_list, &ring->active_list);
 
 	obj->last_read_seqno = seqno;
@@ -1922,10 +1924,13 @@ static void
 i915_gem_object_move_to_inactive(struct drm_i915_gem_object *obj,
 				 struct i915_address_space *vm)
 {
+	struct i915_vma *vma;
+
 	BUG_ON(obj->base.write_domain & ~I915_GEM_GPU_DOMAINS);
 	BUG_ON(!obj->active);
 
-	list_move_tail(&obj->mm_list, &vm->inactive_list);
+	vma = i915_gem_obj_to_vma(obj, vm);
+	list_move_tail(&vma->mm_list, &vm->inactive_list);
 
 	list_del_init(&obj->ring_list);
 	obj->ring = NULL;
@@ -2287,9 +2292,9 @@ void i915_gem_restore_fences(struct drm_device *dev)
 void i915_gem_reset(struct drm_device *dev)
 {
 	struct drm_i915_private *dev_priv = dev->dev_private;
-	struct i915_address_space *vm;
-	struct drm_i915_gem_object *obj;
 	struct intel_ring_buffer *ring;
+	struct i915_address_space *vm;
+	struct i915_vma *vma;
 	int i;
 
 	for_each_ring(ring, dev_priv, i)
@@ -2299,8 +2304,8 @@ void i915_gem_reset(struct drm_device *dev)
 	 * necessary invalidation upon reuse.
 	 */
 	list_for_each_entry(vm, &dev_priv->vm_list, global_link)
-		list_for_each_entry(obj, &vm->inactive_list, mm_list)
-			obj->base.read_domains &= ~I915_GEM_GPU_DOMAINS;
+		list_for_each_entry(vma, &vm->inactive_list, mm_list)
+			vma->obj->base.read_domains &= ~I915_GEM_GPU_DOMAINS;
 
 	i915_gem_restore_fences(dev);
 }
@@ -2644,12 +2649,12 @@ i915_gem_object_unbind(struct drm_i915_gem_object *obj,
 	i915_gem_gtt_finish_object(obj);
 	i915_gem_object_unpin_pages(obj);
 
-	list_del(&obj->mm_list);
 	/* Avoid an unnecessary call to unbind on rebind. */
 	if (i915_is_ggtt(vm))
 		obj->map_and_fenceable = true;
 
 	vma = i915_gem_obj_to_vma(obj, vm);
+	list_del(&vma->mm_list);
 	list_del(&vma->vma_link);
 	drm_mm_remove_node(&vma->node);
 	i915_gem_vma_destroy(vma);
@@ -3197,7 +3202,7 @@ search_free:
 	}
 
 	list_move_tail(&obj->global_list, &dev_priv->mm.bound_list);
-	list_add_tail(&obj->mm_list, &vm->inactive_list);
+	list_add_tail(&vma->mm_list, &vm->inactive_list);
 
 	/* Keep GGTT vmas first to make debug easier */
 	if (i915_is_ggtt(vm))
@@ -3354,9 +3359,14 @@ i915_gem_object_set_to_gtt_domain(struct drm_i915_gem_object *obj, bool write)
 					    old_write_domain);
 
 	/* And bump the LRU for this access */
-	if (i915_gem_object_is_inactive(obj))
-		list_move_tail(&obj->mm_list,
-			       &dev_priv->gtt.base.inactive_list);
+	if (i915_gem_object_is_inactive(obj)) {
+		struct i915_vma *vma = i915_gem_obj_to_vma(obj,
+							   &dev_priv->gtt.base);
+		if (vma)
+			list_move_tail(&vma->mm_list,
+				       &dev_priv->gtt.base.inactive_list);
+
+	}
 
 	return 0;
 }
@@ -3931,7 +3941,6 @@ unlock:
 void i915_gem_object_init(struct drm_i915_gem_object *obj,
 			  const struct drm_i915_gem_object_ops *ops)
 {
-	INIT_LIST_HEAD(&obj->mm_list);
 	INIT_LIST_HEAD(&obj->global_list);
 	INIT_LIST_HEAD(&obj->ring_list);
 	INIT_LIST_HEAD(&obj->exec_list);
@@ -4071,6 +4080,7 @@ struct i915_vma *i915_gem_vma_create(struct drm_i915_gem_object *obj,
 		return ERR_PTR(-ENOMEM);
 
 	INIT_LIST_HEAD(&vma->vma_link);
+	INIT_LIST_HEAD(&vma->mm_list);
 	vma->vm = vm;
 	vma->obj = obj;
 
drivers/gpu/drm/i915/i915_gem_evict.c +6 -8
index 32efdc0..18a44a9 100644
@@ -87,8 +87,7 @@ i915_gem_evict_something(struct drm_device *dev, struct i915_address_space *vm,
 		drm_mm_init_scan(&vm->mm, min_size, alignment, cache_level);
 
 	/* First see if there is a large enough contiguous idle region... */
-	list_for_each_entry(obj, &vm->inactive_list, mm_list) {
-		struct i915_vma *vma = i915_gem_obj_to_vma(obj, vm);
+	list_for_each_entry(vma, &vm->inactive_list, mm_list) {
 		if (mark_free(vma, &unwind_list))
 			goto found;
 	}
@@ -97,8 +96,7 @@ i915_gem_evict_something(struct drm_device *dev, struct i915_address_space *vm,
 		goto none;
 
 	/* Now merge in the soon-to-be-expired objects... */
-	list_for_each_entry(obj, &vm->active_list, mm_list) {
-		struct i915_vma *vma = i915_gem_obj_to_vma(obj, vm);
+	list_for_each_entry(vma, &vm->active_list, mm_list) {
 		if (mark_free(vma, &unwind_list))
 			goto found;
 	}
@@ -159,7 +157,7 @@ i915_gem_evict_everything(struct drm_device *dev)
 {
 	drm_i915_private_t *dev_priv = dev->dev_private;
 	struct i915_address_space *vm;
-	struct drm_i915_gem_object *obj, *next;
+	struct i915_vma *vma, *next;
 	bool lists_empty = true;
 	int ret;
 
@@ -187,9 +185,9 @@ i915_gem_evict_everything(struct drm_device *dev)
 
 	/* Having flushed everything, unbind() should never raise an error */
 	list_for_each_entry(vm, &dev_priv->vm_list, global_link) {
-		list_for_each_entry_safe(obj, next, &vm->inactive_list, mm_list)
-			if (obj->pin_count == 0)
-				WARN_ON(i915_gem_object_unbind(obj, vm));
+		list_for_each_entry_safe(vma, next, &vm->inactive_list, mm_list)
+			if (vma->obj->pin_count == 0)
+				WARN_ON(i915_gem_object_unbind(vma->obj, vm));
 	}
 
 	return 0;
drivers/gpu/drm/i915/i915_gem_stolen.c +1 -1
index bfe61fa..58b2613 100644
@@ -415,7 +415,7 @@ i915_gem_object_create_stolen_for_preallocated(struct drm_device *dev,
 	obj->has_global_gtt_mapping = 1;
 
 	list_add_tail(&obj->global_list, &dev_priv->mm.bound_list);
-	list_add_tail(&obj->mm_list, &vm->inactive_list);
+	list_add_tail(&vma->mm_list, &dev_priv->gtt.base.inactive_list);
 
 	return obj;
 
drivers/gpu/drm/i915/i915_irq.c +21 -16
index 28fa0ff..e065232 100644
@@ -1640,11 +1640,11 @@ static void capture_bo(struct drm_i915_error_buffer *err,
 static u32 capture_active_bo(struct drm_i915_error_buffer *err,
 			     int count, struct list_head *head)
 {
-	struct drm_i915_gem_object *obj;
+	struct i915_vma *vma;
 	int i = 0;
 
-	list_for_each_entry(obj, head, mm_list) {
-		capture_bo(err++, obj);
+	list_for_each_entry(vma, head, mm_list) {
+		capture_bo(err++, vma->obj);
 		if (++i == count)
 			break;
 	}
@@ -1706,8 +1706,9 @@ static struct drm_i915_error_object *
 i915_error_first_batchbuffer(struct drm_i915_private *dev_priv,
 			     struct intel_ring_buffer *ring)
 {
+	struct i915_address_space *vm;
+	struct i915_vma *vma;
 	struct drm_i915_gem_object *obj;
-	struct i915_address_space *vm = &dev_priv->gtt.base;
 	u32 seqno;
 
 	if (!ring->get_seqno)
@@ -1729,20 +1730,23 @@ i915_error_first_batchbuffer(struct drm_i915_private *dev_priv,
 	}
 
 	seqno = ring->get_seqno(ring, false);
-	list_for_each_entry(obj, &vm->active_list, mm_list) {
-		if (obj->ring != ring)
-			continue;
+	list_for_each_entry(vm, &dev_priv->vm_list, global_link) {
+		list_for_each_entry(vma, &vm->active_list, mm_list) {
+			obj = vma->obj;
+			if (obj->ring != ring)
+				continue;
 
-		if (i915_seqno_passed(seqno, obj->last_read_seqno))
-			continue;
+			if (i915_seqno_passed(seqno, obj->last_read_seqno))
+				continue;
 
-		if ((obj->base.read_domains & I915_GEM_DOMAIN_COMMAND) == 0)
-			continue;
+			if ((obj->base.read_domains & I915_GEM_DOMAIN_COMMAND) == 0)
+				continue;
 
-		/* We need to copy these to an anonymous buffer as the simplest
-		 * method to avoid being overwritten by userspace.
-		 */
-		return i915_error_object_create(dev_priv, obj);
+			/* We need to copy these to an anonymous buffer as the simplest
+			 * method to avoid being overwritten by userspace.
+			 */
+			return i915_error_object_create(dev_priv, obj);
+		}
 	}
 
 	return NULL;
@@ -1863,11 +1867,12 @@ static void i915_gem_capture_buffers(struct drm_i915_private *dev_priv,
 				     struct drm_i915_error_state *error)
 {
 	struct drm_i915_gem_object *obj;
+	struct i915_vma *vma;
 	struct i915_address_space *vm = &dev_priv->gtt.base;
 	int i;
 
 	i = 0;
-	list_for_each_entry(obj, &vm->active_list, mm_list)
+	list_for_each_entry(vma, &vm->active_list, mm_list)
 		i++;
 	error->active_bo_count = i;
 	list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list)
Signature · 6 lines
1.8.3.2

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
Signature · 1 line
Ben Widawsky, Intel Open Source Technology Center
#34 lore raw

PATCH 9/11 drm/i915: Update error capture for VMs

In reply to Ben Widawsky

formerly: "drm/i915: Create VMAs (part 4) - Error capture"

Since the active/inactive lists are per VM, we need to modify the error capture code to be aware of this, and also extend it to capture the buffers from all the VMs. For now all the code assumes only 1 VM, but it will become more generic over the next few patches.

NOTE: If the number of VMs in a real world system grows significantly we'll have to focus on only capturing the guilty VM, or else it's likely there won't be enough space for error capture.

v2: Squashed in the "part 6" which had dependencies on the mm_list change. Since I've moved the mm_list change to an earlier point in the series, we were able to accomplish it here and now.

---
 drivers/gpu/drm/i915/i915_debugfs.c |   8 +--
 drivers/gpu/drm/i915/i915_drv.h     |   4 +-
 drivers/gpu/drm/i915/i915_irq.c     | 115 ++++++++++++++++++++++++++----------
 3 files changed, 91 insertions(+), 36 deletions(-)
drivers/gpu/drm/i915/i915_debugfs.c +4 -4
index 163ca6b..9a4acc2 100644
@@ -902,13 +902,13 @@ int i915_error_state_to_str(struct drm_i915_error_state_buf *m,
 
 	if (error->active_bo)
 		print_error_buffers(m, "Active",
-				    error->active_bo,
-				    error->active_bo_count);
+				    error->active_bo[0],
+				    error->active_bo_count[0]);
 
 	if (error->pinned_bo)
 		print_error_buffers(m, "Pinned",
-				    error->pinned_bo,
-				    error->pinned_bo_count);
+				    error->pinned_bo[0],
+				    error->pinned_bo_count[0]);
 
 	for (i = 0; i < ARRAY_SIZE(error->ring); i++) {
 		struct drm_i915_error_object *obj;
drivers/gpu/drm/i915/i915_drv.h +2 -2
index 48105f8..b98ad82 100644
@@ -323,8 +323,8 @@ struct drm_i915_error_state {
 		u32 purgeable:1;
 		s32 ring:4;
 		u32 cache_level:2;
-	} *active_bo, *pinned_bo;
-	u32 active_bo_count, pinned_bo_count;
+	} **active_bo, **pinned_bo;
+	u32 *active_bo_count, *pinned_bo_count;
 	struct intel_overlay_error_state *overlay;
 	struct intel_display_error_state *display;
 };
drivers/gpu/drm/i915/i915_irq.c +85 -30

233 lines not on this page · raw message

Signature · 1 line
1.8.3.2
#35 lore raw

PATCH 10/11 drm/i915: create an object_is_active()

In reply to Ben Widawsky

This is simply obj->active for now, but will serve a purpose when we track activity per vma.

---
 drivers/gpu/drm/i915/i915_drv.h            |  1 +
 drivers/gpu/drm/i915/i915_gem.c            | 18 ++++++++++++------
 drivers/gpu/drm/i915/i915_gem_execbuffer.c |  2 +-
 3 files changed, 14 insertions(+), 7 deletions(-)
drivers/gpu/drm/i915/i915_drv.h +1 -0
index b98ad82..38d07f2 100644
@@ -1716,6 +1716,7 @@ static inline void i915_gem_object_unpin_pages(struct drm_i915_gem_object *obj)
 int __must_check i915_mutex_lock_interruptible(struct drm_device *dev);
 int i915_gem_object_sync(struct drm_i915_gem_object *obj,
 			 struct intel_ring_buffer *to);
+bool i915_gem_object_is_active(struct drm_i915_gem_object *obj);
 void i915_gem_object_move_to_active(struct drm_i915_gem_object *obj,
 				    struct i915_address_space *vm,
 				    struct intel_ring_buffer *ring);
drivers/gpu/drm/i915/i915_gem.c +12 -6
index 9a58363..c2ecb78 100644
@@ -134,10 +134,16 @@ int i915_mutex_lock_interruptible(struct drm_device *dev)
 	return 0;
 }
 
+/* NB: Not the same as !i915_gem_object_is_inactive */
+bool i915_gem_object_is_active(struct drm_i915_gem_object *obj)
+{
+	return obj->active;
+}
+
 static inline bool
 i915_gem_object_is_inactive(struct drm_i915_gem_object *obj)
 {
-	return i915_gem_obj_bound_any(obj) && !obj->active;
+	return i915_gem_obj_bound_any(obj) && !i915_gem_object_is_active(obj);
 }
 
 int
@@ -1894,7 +1900,7 @@ i915_gem_object_move_to_active(struct drm_i915_gem_object *obj,
 	obj->ring = ring;
 
 	/* Add a reference if we're newly entering the active list. */
-	if (!obj->active) {
+	if (!i915_gem_object_is_active(obj)) {
 		drm_gem_object_reference(&obj->base);
 		obj->active = 1;
 	}
@@ -1927,7 +1933,7 @@ i915_gem_object_move_to_inactive(struct drm_i915_gem_object *obj,
 	struct i915_vma *vma;
 
 	BUG_ON(obj->base.write_domain & ~I915_GEM_GPU_DOMAINS);
-	BUG_ON(!obj->active);
+	BUG_ON(!i915_gem_object_is_active(obj));
 
 	vma = i915_gem_obj_to_vma(obj, vm);
 	list_move_tail(&vma->mm_list, &vm->inactive_list);
@@ -2437,7 +2443,7 @@ i915_gem_object_flush_active(struct drm_i915_gem_object *obj)
 {
 	int ret;
 
-	if (obj->active) {
+	if (i915_gem_object_is_active(obj)) {
 		ret = i915_gem_check_olr(obj->ring, obj->last_read_seqno);
 		if (ret)
 			return ret;
@@ -2502,7 +2508,7 @@ i915_gem_wait_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
 	if (ret)
 		goto out;
 
-	if (obj->active) {
+	if (i915_gem_object_is_active(obj)) {
 		seqno = obj->last_read_seqno;
 		ring = obj->ring;
 	}
@@ -3872,7 +3878,7 @@ i915_gem_busy_ioctl(struct drm_device *dev, void *data,
 	 */
 	ret = i915_gem_object_flush_active(obj);
 
-	args->busy = obj->active;
+	args->busy = i915_gem_object_is_active(obj);
 	if (obj->ring) {
 		BUILD_BUG_ON(I915_NUM_RINGS > 16);
 		args->busy |= intel_ring_flag(obj->ring) << 16;
drivers/gpu/drm/i915/i915_gem_execbuffer.c +1 -1
index e90182d..725dd7f 100644
@@ -251,7 +251,7 @@ i915_gem_execbuffer_relocate_entry(struct drm_i915_gem_object *obj,
 	}
 
 	/* We can't wait for rendering with pagefaults disabled */
-	if (obj->active && in_atomic())
+	if (i915_gem_object_is_active(obj) && in_atomic())
 		return -EFAULT;
 
 	reloc->delta += target_offset;
Signature · 1 line
1.8.3.2
#36 lore raw

PATCH 11/11 drm/i915: Move active to vma

In reply to Ben Widawsky

Probably need to squash whole thing, or just the inactive part, tbd...

---
 drivers/gpu/drm/i915/i915_drv.h | 14 ++++++------
 drivers/gpu/drm/i915/i915_gem.c | 47 ++++++++++++++++++++++++-----------------
 2 files changed, 35 insertions(+), 26 deletions(-)
drivers/gpu/drm/i915/i915_drv.h +7 -7
index 38d07f2..e6694ae 100644
@@ -541,6 +541,13 @@ struct i915_vma {
 	struct drm_i915_gem_object *obj;
 	struct i915_address_space *vm;
 
+	/**
+	 * This is set if the object is on the active lists (has pending
+	 * rendering and so a non-zero seqno), and is not set if it i s on
+	 * inactive (ready to be unbound) list.
+	 */
+	unsigned int active:1;
+
 	/** This object's place on the active/inactive lists */
 	struct list_head mm_list;
 
@@ -1250,13 +1257,6 @@ struct drm_i915_gem_object {
 	struct list_head exec_list;
 
 	/**
-	 * This is set if the object is on the active lists (has pending
-	 * rendering and so a non-zero seqno), and is not set if it i s on
-	 * inactive (ready to be unbound) list.
-	 */
-	unsigned int active:1;
-
-	/**
 	 * This is set if the object has been written to since last bound
 	 * to the GTT
 	 */
drivers/gpu/drm/i915/i915_gem.c +28 -19

104 lines not on this page · raw message

Signature · 1 line
1.8.3.2
#37 lore raw

Re: [PATCH 11/11] drm/i915: Move active to vma

Quoted 3 lines · Ben Widawsky

Probably need to squash whole thing, or just the inactive part, tbd...

I agree that we need vma->active, but I'm not sold on removing obj->active. Atm we have to use-cases for checking obj->active:
- In the evict/unbind code to check whether the gpu is still using this specific mapping. This use-case nicely fits into checking vma->active.
- In the shrinker code and everywhere we want to do cpu access we only care about whether the gpu is accessing the object, not at all through which mapping precisely. There a vma-independant obj->active sounds much saner.

Note though that just keeping track of vma->active isn't too useful, since if some other vma is keeping the object busy we'll still stall on that one for eviction. So we'd need a vma->ring and vma->last_rendering_seqno, too.

At that point I wonder a bit whether all this complexity is worth it ...

I need to ponder this some more.
-Daniel

Quoted 85 lines
---
 drivers/gpu/drm/i915/i915_drv.h | 14 ++++++------
 drivers/gpu/drm/i915/i915_gem.c | 47 ++++++++++++++++++++++++-----------------
 2 files changed, 35 insertions(+), 26 deletions(-)
drivers/gpu/drm/i915/i915_drv.h +7 -7
index 38d07f2..e6694ae 100644
@@ -541,6 +541,13 @@ struct i915_vma {
 	struct drm_i915_gem_object *obj;
 	struct i915_address_space *vm;
 
+	/**
+	 * This is set if the object is on the active lists (has pending
+	 * rendering and so a non-zero seqno), and is not set if it i s on
+	 * inactive (ready to be unbound) list.
+	 */
+	unsigned int active:1;
+
 	/** This object's place on the active/inactive lists */
 	struct list_head mm_list;
 
@@ -1250,13 +1257,6 @@ struct drm_i915_gem_object {
 	struct list_head exec_list;
 
 	/**
-	 * This is set if the object is on the active lists (has pending
-	 * rendering and so a non-zero seqno), and is not set if it i s on
-	 * inactive (ready to be unbound) list.
-	 */
-	unsigned int active:1;
-
-	/**
 	 * This is set if the object has been written to since last bound
 	 * to the GTT
 	 */
drivers/gpu/drm/i915/i915_gem.c +14 -7
index c2ecb78..b87073b 100644
@@ -137,7 +137,13 @@ int i915_mutex_lock_interruptible(struct drm_device *dev)
 /* NB: Not the same as !i915_gem_object_is_inactive */
 bool i915_gem_object_is_active(struct drm_i915_gem_object *obj)
 {
-	return obj->active;
+	struct i915_vma *vma;
+
+	list_for_each_entry(vma, &obj->vma_list, vma_link)
+		if (vma->active)
+			return true;
+
+	return false;
 }
 
 static inline bool
@@ -1899,14 +1905,14 @@ i915_gem_object_move_to_active(struct drm_i915_gem_object *obj,
 	BUG_ON(ring == NULL);
 	obj->ring = ring;
 
+	/* Move from whatever list we were on to the tail of execution. */
+	vma = i915_gem_obj_to_vma(obj, vm);
 	/* Add a reference if we're newly entering the active list. */
-	if (!i915_gem_object_is_active(obj)) {
+	if (!vma->active) {
 		drm_gem_object_reference(&obj->base);
-		obj->active = 1;
+		vma->active = 1;
 	}
 
-	/* Move from whatever list we were on to the tail of execution. */
-	vma = i915_gem_obj_to_vma(obj, vm);
 	list_move_tail(&vma->mm_list, &vm->active_list);
 	list_move_tail(&obj->ring_list, &ring->active_list);
 
@@ -1927,16 +1933,23 @@ i915_gem_object_move_to_active(struct drm_i915_gem_object *obj,
 }
 
 static void
-i915_gem_object_move_to_inactive(struct drm_i915_gem_object *obj,
-				 struct i915_address_space *vm)
+i915_gem_object_move_to_inactive(struct drm_i915_gem_object *obj)
 {
+	struct drm_i915_private *dev_priv = obj->base.dev->dev_private;
+	struct i915_address_space *vm;

drivers/gpu/drm/i915/i915_gem.c i915_gem_object_move_to_active(struct drm_i915_gem_object *obj, · line 1946

Quoted 10 lines
drivers/gpu/drm/i915/i915_gem.c +3 -3
 	struct i915_vma *vma;
+	int i = 0;
 
 	BUG_ON(obj->base.write_domain & ~I915_GEM_GPU_DOMAINS);
-	BUG_ON(!i915_gem_object_is_active(obj));
 
-	vma = i915_gem_obj_to_vma(obj, vm);
-	list_move_tail(&vma->mm_list, &vm->inactive_list);
+	list_for_each_entry(vm, &dev_priv->vm_list, global_link) {
+		vma = i915_gem_obj_to_vma(obj, vm);

For paranoia we might want to track the vm used to run a batch in it request struct, then we

Quoted 64 lines
drivers/gpu/drm/i915/i915_gem.c +11 -9
+		if (!vma || !vma->active)
+			continue;
+		list_move_tail(&vma->mm_list, &vm->inactive_list);
+		vma->active = 0;
+		i++;
+	}
 
 	list_del_init(&obj->ring_list);
 	obj->ring = NULL;
@@ -1948,8 +1961,8 @@ i915_gem_object_move_to_inactive(struct drm_i915_gem_object *obj,
 	obj->last_fenced_seqno = 0;
 	obj->fenced_gpu_access = false;
 
-	obj->active = 0;
-	drm_gem_object_unreference(&obj->base);
+	while (i--)
+		drm_gem_object_unreference(&obj->base);
 
 	WARN_ON(i915_verify_lists(dev));
 }
@@ -2272,15 +2285,13 @@ static void i915_gem_reset_ring_lists(struct drm_i915_private *dev_priv,
 	}
 
 	while (!list_empty(&ring->active_list)) {
-		struct i915_address_space *vm;
 		struct drm_i915_gem_object *obj;
 
 		obj = list_first_entry(&ring->active_list,
 				       struct drm_i915_gem_object,
 				       ring_list);
 
-		list_for_each_entry(vm, &dev_priv->vm_list, global_link)
-			i915_gem_object_move_to_inactive(obj, vm);
+		i915_gem_object_move_to_inactive(obj);
 	}
 }
 
@@ -2356,8 +2367,6 @@ i915_gem_retire_requests_ring(struct intel_ring_buffer *ring)
 	 * by the ringbuffer to the flushing/inactive lists as appropriate.
 	 */
 	while (!list_empty(&ring->active_list)) {
-		struct drm_i915_private *dev_priv = ring->dev->dev_private;
-		struct i915_address_space *vm;
 		struct drm_i915_gem_object *obj;
 
 		obj = list_first_entry(&ring->active_list,
@@ -2367,8 +2376,8 @@ i915_gem_retire_requests_ring(struct intel_ring_buffer *ring)
 		if (!i915_seqno_passed(seqno, obj->last_read_seqno))
 			break;
 
-		list_for_each_entry(vm, &dev_priv->vm_list, global_link)
-			i915_gem_object_move_to_inactive(obj, vm);
+		BUG_ON(!i915_gem_object_is_active(obj));
+		i915_gem_object_move_to_inactive(obj);
 	}
 
 	if (unlikely(ring->trace_irq_seqno &&
Signature · 6 lines
1.8.3.2

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
#38 lore raw

Re: [PATCH 11/11] drm/i915: Move active to vma

Quoted 14 lines · Daniel Vetter
Quoted 3 lines · Ben Widawsky

Probably need to squash whole thing, or just the inactive part, tbd...

I agree that we need vma->active, but I'm not sold on removing obj->active. Atm we have to use-cases for checking obj->active:
- In the evict/unbind code to check whether the gpu is still using this specific mapping. This use-case nicely fits into checking vma->active.
- In the shrinker code and everywhere we want to do cpu access we only care about whether the gpu is accessing the object, not at all through which mapping precisely. There a vma-independant obj->active sounds much saner.

Quoted 8 lines

Note though that just keeping track of vma->active isn't too useful, since if some other vma is keeping the object busy we'll still stall on that one for eviction. So we'd need a vma->ring and vma->last_rendering_seqno, too.

At that point I wonder a bit whether all this complexity is worth it ...

I need to ponder this some more.
-Daniel

I think eventually the complexity might prove worthwhile, it might not.

In the meanwhile, I see vma->active as just a bookkeeping thing, and not really useful in determining what we actually care about. As you mention obj->active is really what we care about, and I used the getter i915_gem_object_is_active() as a way to avoid the confusion of having two active members.

I think we're in the same state of mind on this, and I've picked what I consider to be a less offensive solution which is easy to clean up later.

Let me know when you make a decision.

Quoted 168 lines
Quoted 86 lines
---
 drivers/gpu/drm/i915/i915_drv.h | 14 ++++++------
 drivers/gpu/drm/i915/i915_gem.c | 47 ++++++++++++++++++++++++-----------------
 2 files changed, 35 insertions(+), 26 deletions(-)
drivers/gpu/drm/i915/i915_drv.h +7 -7
index 38d07f2..e6694ae 100644
@@ -541,6 +541,13 @@ struct i915_vma {
 	struct drm_i915_gem_object *obj;
 	struct i915_address_space *vm;
 
+	/**
+	 * This is set if the object is on the active lists (has pending
+	 * rendering and so a non-zero seqno), and is not set if it i s on
+	 * inactive (ready to be unbound) list.
+	 */
+	unsigned int active:1;
+
 	/** This object's place on the active/inactive lists */
 	struct list_head mm_list;
 
@@ -1250,13 +1257,6 @@ struct drm_i915_gem_object {
 	struct list_head exec_list;
 
 	/**
-	 * This is set if the object is on the active lists (has pending
-	 * rendering and so a non-zero seqno), and is not set if it i s on
-	 * inactive (ready to be unbound) list.
-	 */
-	unsigned int active:1;
-
-	/**
 	 * This is set if the object has been written to since last bound
 	 * to the GTT
 	 */
drivers/gpu/drm/i915/i915_gem.c +14 -7
index c2ecb78..b87073b 100644
@@ -137,7 +137,13 @@ int i915_mutex_lock_interruptible(struct drm_device *dev)
 /* NB: Not the same as !i915_gem_object_is_inactive */
 bool i915_gem_object_is_active(struct drm_i915_gem_object *obj)
 {
-	return obj->active;
+	struct i915_vma *vma;
+
+	list_for_each_entry(vma, &obj->vma_list, vma_link)
+		if (vma->active)
+			return true;
+
+	return false;
 }
 
 static inline bool
@@ -1899,14 +1905,14 @@ i915_gem_object_move_to_active(struct drm_i915_gem_object *obj,
 	BUG_ON(ring == NULL);
 	obj->ring = ring;
 
+	/* Move from whatever list we were on to the tail of execution. */
+	vma = i915_gem_obj_to_vma(obj, vm);
 	/* Add a reference if we're newly entering the active list. */
-	if (!i915_gem_object_is_active(obj)) {
+	if (!vma->active) {
 		drm_gem_object_reference(&obj->base);
-		obj->active = 1;
+		vma->active = 1;
 	}
 
-	/* Move from whatever list we were on to the tail of execution. */
-	vma = i915_gem_obj_to_vma(obj, vm);
 	list_move_tail(&vma->mm_list, &vm->active_list);
 	list_move_tail(&obj->ring_list, &ring->active_list);
 
@@ -1927,16 +1933,23 @@ i915_gem_object_move_to_active(struct drm_i915_gem_object *obj,
 }
 
 static void
-i915_gem_object_move_to_inactive(struct drm_i915_gem_object *obj,
-				 struct i915_address_space *vm)
+i915_gem_object_move_to_inactive(struct drm_i915_gem_object *obj)
 {
+	struct drm_i915_private *dev_priv = obj->base.dev->dev_private;
+	struct i915_address_space *vm;

drivers/gpu/drm/i915/i915_gem.c i915_gem_object_move_to_active(struct drm_i915_gem_object *obj, · line 1946

Quoted 10 lines
drivers/gpu/drm/i915/i915_gem.c +3 -3
 	struct i915_vma *vma;
+	int i = 0;
 
 	BUG_ON(obj->base.write_domain & ~I915_GEM_GPU_DOMAINS);
-	BUG_ON(!i915_gem_object_is_active(obj));
 
-	vma = i915_gem_obj_to_vma(obj, vm);
-	list_move_tail(&vma->mm_list, &vm->inactive_list);
+	list_for_each_entry(vm, &dev_priv->vm_list, global_link) {
+		vma = i915_gem_obj_to_vma(obj, vm);

For paranoia we might want to track the vm used to run a batch in it request struct, then we

Quoted 64 lines
drivers/gpu/drm/i915/i915_gem.c +11 -9
+		if (!vma || !vma->active)
+			continue;
+		list_move_tail(&vma->mm_list, &vm->inactive_list);
+		vma->active = 0;
+		i++;
+	}
 
 	list_del_init(&obj->ring_list);
 	obj->ring = NULL;
@@ -1948,8 +1961,8 @@ i915_gem_object_move_to_inactive(struct drm_i915_gem_object *obj,
 	obj->last_fenced_seqno = 0;
 	obj->fenced_gpu_access = false;
 
-	obj->active = 0;
-	drm_gem_object_unreference(&obj->base);
+	while (i--)
+		drm_gem_object_unreference(&obj->base);
 
 	WARN_ON(i915_verify_lists(dev));
 }
@@ -2272,15 +2285,13 @@ static void i915_gem_reset_ring_lists(struct drm_i915_private *dev_priv,
 	}
 
 	while (!list_empty(&ring->active_list)) {
-		struct i915_address_space *vm;
 		struct drm_i915_gem_object *obj;
 
 		obj = list_first_entry(&ring->active_list,
 				       struct drm_i915_gem_object,
 				       ring_list);
 
-		list_for_each_entry(vm, &dev_priv->vm_list, global_link)
-			i915_gem_object_move_to_inactive(obj, vm);
+		i915_gem_object_move_to_inactive(obj);
 	}
 }
 
@@ -2356,8 +2367,6 @@ i915_gem_retire_requests_ring(struct intel_ring_buffer *ring)
 	 * by the ringbuffer to the flushing/inactive lists as appropriate.
 	 */
 	while (!list_empty(&ring->active_list)) {
-		struct drm_i915_private *dev_priv = ring->dev->dev_private;
-		struct i915_address_space *vm;
 		struct drm_i915_gem_object *obj;
 
 		obj = list_first_entry(&ring->active_list,
@@ -2367,8 +2376,8 @@ i915_gem_retire_requests_ring(struct intel_ring_buffer *ring)
 		if (!i915_seqno_passed(seqno, obj->last_read_seqno))
 			break;
 
-		list_for_each_entry(vm, &dev_priv->vm_list, global_link)
-			i915_gem_object_move_to_inactive(obj, vm);
+		BUG_ON(!i915_gem_object_is_active(obj));
+		i915_gem_object_move_to_inactive(obj);
 	}
 
 	if (unlikely(ring->trace_irq_seqno &&
Signature · 6 lines
1.8.3.2

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
Signature · 1 line
Ben Widawsky, Intel Open Source Technology Center
#39 lore raw

Re: [PATCH 11/11] drm/i915: Move active to vma

Quoted 32 lines · Ben Widawsky
Quoted 14 lines · Daniel Vetter
Quoted 3 lines · Ben Widawsky

Probably need to squash whole thing, or just the inactive part, tbd...

I agree that we need vma->active, but I'm not sold on removing obj->active. Atm we have to use-cases for checking obj->active:
- In the evict/unbind code to check whether the gpu is still using this specific mapping. This use-case nicely fits into checking vma->active.
- In the shrinker code and everywhere we want to do cpu access we only care about whether the gpu is accessing the object, not at all through which mapping precisely. There a vma-independant obj->active sounds much saner.

Quoted 8 lines

Note though that just keeping track of vma->active isn't too useful, since if some other vma is keeping the object busy we'll still stall on that one for eviction. So we'd need a vma->ring and vma->last_rendering_seqno, too.

At that point I wonder a bit whether all this complexity is worth it ...

I need to ponder this some more.
-Daniel

I think eventually the complexity might prove worthwhile, it might not.

In the meanwhile, I see vma->active as just a bookkeeping thing, and not really useful in determining what we actually care about. As you mention obj->active is really what we care about, and I used the getter i915_gem_object_is_active() as a way to avoid the confusion of having two active members.

Quoted 5 lines

I think we're in the same state of mind on this, and I've picked what I consider to be a less offensive solution which is easy to clean up later.

Let me know when you make a decision.

Since you don't seem to be too keen on defending it for now I'd say let's keep it in obj->active. This way obj->active still reflects accurately whether the object is active on a ring or not.

That leaves us with updating the vm->active list. I'm leaning somewhat towards simply merging the inactive and active vm list since in the only place we care about those list (eviction) we treat them essentially as one big lru. That would cut down on complexity in retire_request to keep all the vmas on the rigth per-vm active/inactive list, too.

Optional cleanup after-the-fact imo (or upfront if it makes request retiring much simpler). Whatever suits you.
-Daniel

Quoted 172 lines
Quoted 169 lines
Quoted 87 lines

---
 drivers/gpu/drm/i915/i915_drv.h | 14 ++++++------
 drivers/gpu/drm/i915/i915_gem.c | 47 ++++++++++++++++++++++++-----------------
 2 files changed, 35 insertions(+), 26 deletions(-)
drivers/gpu/drm/i915/i915_drv.h +7 -7
index 38d07f2..e6694ae 100644
@@ -541,6 +541,13 @@ struct i915_vma {
 	struct drm_i915_gem_object *obj;
 	struct i915_address_space *vm;
 
+	/**
+	 * This is set if the object is on the active lists (has pending
+	 * rendering and so a non-zero seqno), and is not set if it i s on
+	 * inactive (ready to be unbound) list.
+	 */
+	unsigned int active:1;
+
 	/** This object's place on the active/inactive lists */
 	struct list_head mm_list;
 
@@ -1250,13 +1257,6 @@ struct drm_i915_gem_object {
 	struct list_head exec_list;
 
 	/**
-	 * This is set if the object is on the active lists (has pending
-	 * rendering and so a non-zero seqno), and is not set if it i s on
-	 * inactive (ready to be unbound) list.
-	 */
-	unsigned int active:1;
-
-	/**
 	 * This is set if the object has been written to since last bound
 	 * to the GTT
 	 */
drivers/gpu/drm/i915/i915_gem.c +14 -7
index c2ecb78..b87073b 100644
@@ -137,7 +137,13 @@ int i915_mutex_lock_interruptible(struct drm_device *dev)
 /* NB: Not the same as !i915_gem_object_is_inactive */
 bool i915_gem_object_is_active(struct drm_i915_gem_object *obj)
 {
-	return obj->active;
+	struct i915_vma *vma;
+
+	list_for_each_entry(vma, &obj->vma_list, vma_link)
+		if (vma->active)
+			return true;
+
+	return false;
 }
 
 static inline bool
@@ -1899,14 +1905,14 @@ i915_gem_object_move_to_active(struct drm_i915_gem_object *obj,
 	BUG_ON(ring == NULL);
 	obj->ring = ring;
 
+	/* Move from whatever list we were on to the tail of execution. */
+	vma = i915_gem_obj_to_vma(obj, vm);
 	/* Add a reference if we're newly entering the active list. */
-	if (!i915_gem_object_is_active(obj)) {
+	if (!vma->active) {
 		drm_gem_object_reference(&obj->base);
-		obj->active = 1;
+		vma->active = 1;
 	}
 
-	/* Move from whatever list we were on to the tail of execution. */
-	vma = i915_gem_obj_to_vma(obj, vm);
 	list_move_tail(&vma->mm_list, &vm->active_list);
 	list_move_tail(&obj->ring_list, &ring->active_list);
 
@@ -1927,16 +1933,23 @@ i915_gem_object_move_to_active(struct drm_i915_gem_object *obj,
 }
 
 static void
-i915_gem_object_move_to_inactive(struct drm_i915_gem_object *obj,
-				 struct i915_address_space *vm)
+i915_gem_object_move_to_inactive(struct drm_i915_gem_object *obj)
 {
+	struct drm_i915_private *dev_priv = obj->base.dev->dev_private;
+	struct i915_address_space *vm;

drivers/gpu/drm/i915/i915_gem.c i915_gem_object_move_to_active(struct drm_i915_gem_object *obj, · line 1946

Quoted 10 lines
drivers/gpu/drm/i915/i915_gem.c +3 -3
 	struct i915_vma *vma;
+	int i = 0;
 
 	BUG_ON(obj->base.write_domain & ~I915_GEM_GPU_DOMAINS);
-	BUG_ON(!i915_gem_object_is_active(obj));
 
-	vma = i915_gem_obj_to_vma(obj, vm);
-	list_move_tail(&vma->mm_list, &vm->inactive_list);
+	list_for_each_entry(vm, &dev_priv->vm_list, global_link) {
+		vma = i915_gem_obj_to_vma(obj, vm);

For paranoia we might want to track the vm used to run a batch in it request struct, then we

Quoted 64 lines
drivers/gpu/drm/i915/i915_gem.c +11 -9
+		if (!vma || !vma->active)
+			continue;
+		list_move_tail(&vma->mm_list, &vm->inactive_list);
+		vma->active = 0;
+		i++;
+	}
 
 	list_del_init(&obj->ring_list);
 	obj->ring = NULL;
@@ -1948,8 +1961,8 @@ i915_gem_object_move_to_inactive(struct drm_i915_gem_object *obj,
 	obj->last_fenced_seqno = 0;
 	obj->fenced_gpu_access = false;
 
-	obj->active = 0;
-	drm_gem_object_unreference(&obj->base);
+	while (i--)
+		drm_gem_object_unreference(&obj->base);
 
 	WARN_ON(i915_verify_lists(dev));
 }
@@ -2272,15 +2285,13 @@ static void i915_gem_reset_ring_lists(struct drm_i915_private *dev_priv,
 	}
 
 	while (!list_empty(&ring->active_list)) {
-		struct i915_address_space *vm;
 		struct drm_i915_gem_object *obj;
 
 		obj = list_first_entry(&ring->active_list,
 				       struct drm_i915_gem_object,
 				       ring_list);
 
-		list_for_each_entry(vm, &dev_priv->vm_list, global_link)
-			i915_gem_object_move_to_inactive(obj, vm);
+		i915_gem_object_move_to_inactive(obj);
 	}
 }
 
@@ -2356,8 +2367,6 @@ i915_gem_retire_requests_ring(struct intel_ring_buffer *ring)
 	 * by the ringbuffer to the flushing/inactive lists as appropriate.
 	 */
 	while (!list_empty(&ring->active_list)) {
-		struct drm_i915_private *dev_priv = ring->dev->dev_private;
-		struct i915_address_space *vm;
 		struct drm_i915_gem_object *obj;
 
 		obj = list_first_entry(&ring->active_list,
@@ -2367,8 +2376,8 @@ i915_gem_retire_requests_ring(struct intel_ring_buffer *ring)
 		if (!i915_seqno_passed(seqno, obj->last_read_seqno))
 			break;
 
-		list_for_each_entry(vm, &dev_priv->vm_list, global_link)
-			i915_gem_object_move_to_inactive(obj, vm);
+		BUG_ON(!i915_gem_object_is_active(obj));
+		i915_gem_object_move_to_inactive(obj);
 	}
 
 	if (unlikely(ring->trace_irq_seqno &&
Signature · 6 lines
1.8.3.2

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
Signature · 1 line
Ben Widawsky, Intel Open Source Technology Center
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
#40 lore raw
In reply to Ben Widawsky
Quoted 5 lines · Ben Widawsky

By Daniel's request, to make the PPGTT merging more manageable, here are the patches associated with the VM/VMA infrastructure. They are not as well tested as the previous series, although I would hope that without actually changing address space, most of this series is just massaging code.

Quoted 8 lines

Even though these patches were all cherry picked from the original, working series, the amount of rework was not insignificant ie. there may be a lot of bugs present, or changes needed.

There should be little to no effect on the code, since there will only ever be one VM until the rest of the PPGTT series is merged.

Finally, Daniel, is this more or less what you wanted first?

Yeah, looks good. I think up to patch 5 I can merge it (only 2 tiny bikesheds), but I'll volunteer someone to do an in-depth review. Later patches I think need a bit more discussion and maybe split-out of prep work. I've dropped my questions on them.
-Daniel

Quoted 43 lines

References:
http://lists.freedesktop.org/archives/intel-gfx/2013-June/029408.html

Ben Widawsky (11):
drm/i915: Move gtt and ppgtt under address space umbrella drm/i915: Put the mm in the parent address space drm/i915: Create a global list of vms
drm/i915: Move active/inactive lists to new mm drm/i915: Create VMAs
drm/i915: plumb VM into object operations drm/i915: Fix up map and fenceable for VMA drm/i915: mm_list is per VMA
drm/i915: Update error capture for VMs
drm/i915: create an object_is_active()
drm/i915: Move active to vma

 drivers/gpu/drm/i915/i915_debugfs.c        |  88 ++++--
 drivers/gpu/drm/i915/i915_dma.c            |   9 +-
 drivers/gpu/drm/i915/i915_drv.h            | 243 +++++++++-------
 drivers/gpu/drm/i915/i915_gem.c            | 432 ++++++++++++++++++++++-------
 drivers/gpu/drm/i915/i915_gem_context.c    |   9 +-
 drivers/gpu/drm/i915/i915_gem_debug.c      |   2 +-
 drivers/gpu/drm/i915/i915_gem_evict.c      |  67 +++--
 drivers/gpu/drm/i915/i915_gem_execbuffer.c |  87 +++---
 drivers/gpu/drm/i915/i915_gem_gtt.c        | 193 +++++++------
 drivers/gpu/drm/i915/i915_gem_stolen.c     |  19 +-
 drivers/gpu/drm/i915/i915_gem_tiling.c     |  10 +-
 drivers/gpu/drm/i915/i915_irq.c            | 158 ++++++++---
 drivers/gpu/drm/i915/i915_trace.h          |  20 +-
 drivers/gpu/drm/i915/intel_fb.c            |   1 -
 drivers/gpu/drm/i915/intel_overlay.c       |   2 +-
 drivers/gpu/drm/i915/intel_pm.c            |   2 +-
 drivers/gpu/drm/i915/intel_ringbuffer.c    |  16 +-
 17 files changed, 902 insertions(+), 456 deletions(-)
Signature · 6 lines
1.8.3.2

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
#41 lore raw

RFC PATCH 12/15 create vm->bind,unbind

In reply to Ben Widawsky

In response to some of Daniel's requests on patch 6, I tried to clean up some of our code via bind/unbind. I haven't done terribly thorough testing so far - but basic tests are passing on IVB, and the code is a lot cleaner IMO. This could be squashed in to patch 6, but I would prefer to leave it as this small series on top of the bunch.

I have tried a lesser version of this before in my earlier gtt/agp cleanups. Daniel rejected it then in favor of his own version. I am trying again because I think the latest PPGTT work provide an even greater case for it.

References:
http://lists.freedesktop.org/archives/intel-gfx/2013-January/023920.html

Ben Widawsky (3):
drm/i915: Add bind/unbind object functions to VM drm/i915: Use the new vm [un]bind functions drm/i915: eliminate vm->insert_entries()

 drivers/gpu/drm/i915/i915_drv.h            |  23 +++---
 drivers/gpu/drm/i915/i915_gem.c            |  36 +++++-----
 drivers/gpu/drm/i915/i915_gem_context.c    |   6 +-
 drivers/gpu/drm/i915/i915_gem_execbuffer.c |  19 ++---
 drivers/gpu/drm/i915/i915_gem_gtt.c        | 109 ++++++++++++++++++-----------
 5 files changed, 109 insertions(+), 84 deletions(-)
Signature · 1 line
1.8.3.2
#42 lore raw

PATCH 1/3 drm/i915: Add bind/unbind object functions to VM

As we plumb the code with more VM information, it has become more obvious that the easiest way to deal with bind and unbind is to simply put the function pointers in the vm, and let those choose the correct way to handle the page table updates. This change allows many places in the code to simply be vm->bind, and not have to worry about distinguishing PPGTT vs GGTT.

NOTE: At some point in the future, brining back insert_entries may in fact be desirable in order to use 1 bind/unbind for multiple generations of PPGTT. For now however, it's just not necessary.

---
 drivers/gpu/drm/i915/i915_drv.h     |  9 +++++
 drivers/gpu/drm/i915/i915_gem_gtt.c | 72 +++++++++++++++++++++++++++++++++++++
 2 files changed, 81 insertions(+)
drivers/gpu/drm/i915/i915_drv.h +9 -0
index e6694ae..c2a9c98 100644
@@ -484,9 +484,18 @@ struct i915_address_space {
 	/* FIXME: Need a more generic return type */
 	gen6_gtt_pte_t (*pte_encode)(dma_addr_t addr,
 				     enum i915_cache_level level);
+
+	/** Unmap an object from an address space. This usually consists of
+	 * setting the valid PTE entries to a reserved scratch page. */
+	void (*unbind_object)(struct i915_address_space *vm,
+			      struct drm_i915_gem_object *obj);
 	void (*clear_range)(struct i915_address_space *vm,
 			    unsigned int first_entry,
 			    unsigned int num_entries);
+	/* Map an object into an address space with the given cache flags. */
+	void (*bind_object)(struct i915_address_space *vm,
+			    struct drm_i915_gem_object *obj,
+			    enum i915_cache_level cache_level);
 	void (*insert_entries)(struct i915_address_space *vm,
 			       struct sg_table *st,
 			       unsigned int first_entry,
drivers/gpu/drm/i915/i915_gem_gtt.c +72 -0

129 lines not on this page · raw message

Signature · 1 line
1.8.3.2
#43 lore raw

Re: [PATCH 1/3] drm/i915: Add bind/unbind object functions to VM

Quoted 10 lines · Ben Widawsky

As we plumb the code with more VM information, it has become more obvious that the easiest way to deal with bind and unbind is to simply put the function pointers in the vm, and let those choose the correct way to handle the page table updates. This change allows many places in the code to simply be vm->bind, and not have to worry about distinguishing PPGTT vs GGTT.

NOTE: At some point in the future, brining back insert_entries may in fact be desirable in order to use 1 bind/unbind for multiple generations of PPGTT. For now however, it's just not necessary.

I need to check the -internal tree again, but I'm rather sure that we need ->insert_entries. In that case I don't want to remove it here in the upstream tree since I have no intention to carry the re-add patch in -internal ;-)

Quoted 12 lines
---
 drivers/gpu/drm/i915/i915_drv.h     |  9 +++++
 drivers/gpu/drm/i915/i915_gem_gtt.c | 72 +++++++++++++++++++++++++++++++++++++
 2 files changed, 81 insertions(+)
drivers/gpu/drm/i915/i915_drv.h +0 -0
index e6694ae..c2a9c98 100644

drivers/gpu/drm/i915/i915_drv.h struct i915_address_space { · line 491

Quoted 8 lines
drivers/gpu/drm/i915/i915_drv.h +5 -0
@@ -484,9 +484,18 @@ struct i915_address_space {
 	/* FIXME: Need a more generic return type */
 	gen6_gtt_pte_t (*pte_encode)(dma_addr_t addr,
 				     enum i915_cache_level level);
+
+	/** Unmap an object from an address space. This usually consists of
+	 * setting the valid PTE entries to a reserved scratch page. */
+	void (*unbind_object)(struct i915_address_space *vm,
+			      struct drm_i915_gem_object *obj);
	void (*unbind_vma)(struct i915_vma *vma);
	void (*bind_vma)(struct i915_vma *vma,
			 enum i915_cache_level cache_level);

I think if you do this as a follow-up we might as well bikeshed the interface a bit. Again (I know, broken record) for me it feels semantically much cleaner to talk about binding/unbindinig a vma instead of an (obj, vm) pair ...

Quoted 40 lines
drivers/gpu/drm/i915/i915_drv.h +4 -0
 	void (*clear_range)(struct i915_address_space *vm,
 			    unsigned int first_entry,
 			    unsigned int num_entries);
+	/* Map an object into an address space with the given cache flags. */
+	void (*bind_object)(struct i915_address_space *vm,
+			    struct drm_i915_gem_object *obj,
+			    enum i915_cache_level cache_level);
 	void (*insert_entries)(struct i915_address_space *vm,
 			       struct sg_table *st,
 			       unsigned int first_entry,
drivers/gpu/drm/i915/i915_gem_gtt.c +8 -0
index c0d0223..31ff971 100644
@@ -45,6 +45,12 @@
 #define GEN6_PTE_CACHE_LLC_MLC		(3 << 1)
 #define GEN6_PTE_ADDR_ENCODE(addr)	GEN6_GTT_ADDR_ENCODE(addr)
 
+static void gen6_ppgtt_bind_object(struct i915_address_space *vm,
+				   struct drm_i915_gem_object *obj,
+				   enum i915_cache_level cache_level);
+static void gen6_ppgtt_unbind_object(struct i915_address_space *vm,
+				     struct drm_i915_gem_object *obj);
+
 static gen6_gtt_pte_t gen6_pte_encode(dma_addr_t addr,
 				      enum i915_cache_level level)
 {
@@ -285,7 +291,9 @@ static int gen6_ppgtt_init(struct i915_hw_ppgtt *ppgtt)
 	}
 	ppgtt->num_pd_entries = GEN6_PPGTT_PD_ENTRIES;
 	ppgtt->enable = gen6_ppgtt_enable;
+	ppgtt->base.unbind_object = gen6_ppgtt_unbind_object;
 	ppgtt->base.clear_range = gen6_ppgtt_clear_range;
+	ppgtt->base.bind_object = gen6_ppgtt_bind_object;
 	ppgtt->base.insert_entries = gen6_ppgtt_insert_entries;
 	ppgtt->base.cleanup = gen6_ppgtt_cleanup;
 	ppgtt->base.scratch = dev_priv->gtt.base.scratch;
@@ -397,6 +405,17 @@ void i915_ppgtt_bind_object(struct i915_hw_ppgtt *ppgtt,
 			   cache_level);
 }

drivers/gpu/drm/i915/i915_gem_gtt.c void i915_ppgtt_bind_object(struct i915_hw_ppgtt *ppgtt, · line 416

Quoted 10 lines
drivers/gpu/drm/i915/i915_gem_gtt.c +9 -0
 
+static void gen6_ppgtt_bind_object(struct i915_address_space *vm,
+				   struct drm_i915_gem_object *obj,
+				   enum i915_cache_level cache_level)
+{
+	const unsigned long entry = i915_gem_obj_offset(obj, vm);
+
+	gen6_ppgtt_insert_entries(vm, obj->pages, entry >> PAGE_SHIFT,
+				  cache_level);
+	obj->has_aliasing_ppgtt_mapping = 1;

Since this is the bind function for ppgtt the aliasing ppgtt stuff looks a bit wrong here. Either we do the ppgtt insert_entries call as part of the global gtt bind call (if vm->aliasing_ppgtt is set) or we have a special global gtt binding call for execbuf.

Thinking about this some more we might need bind flags with

#define VMA_BIND_CPU (1<<0) /* ensure ggtt mapping exists for aliasing ppgtt */ #define VMA_BIND_GPU (1<<1) /* ensure ppgtt mappings exists for aliasing ppgtt */

since otherwise we can't properly encapsulate the aliasing ppgtt binding logic into vm->bind. So in the end we'd have

void ggtt_bind_vma(vma, bind_flags, cache_level)

{
	ggtt_vm = vma->vm;
	WARN_ON(ggtt_vm != &dev_priv->gtt.base);

	if ((!ggtt_vm->aliasing_ppgtt || (bind_flags & BIND_CPU)) &&
	    !obj->has_global_gtt_mapping) {
		ggtt_vm->insert_entries(vma->obj, vma->node.start, cache_leve);
		vma->obj->has_global_gtt_mapping = true;
	}

	if ((ggtt_vm->aliasing_ppgtt && (bind_flags & BIND_GPU)) &&
	    !obj->has_ppgtt_mapping) {
		ggtt_vm->aliasing_ppgtt->insert_entries(vma->obj,
							vma->node.start,
							cache_leve);
		vma->obj->has_ppgtt_mapping = true;
	}
}

Obviously completely untested, but I hope I could get the idea accross.

Cheers, Daniel

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
#44 lore raw

Re: [PATCH 1/3] drm/i915: Add bind/unbind object functions to VM

Quoted 8 lines · Daniel Vetter
Quoted 7 lines · Ben Widawsky

As we plumb the code with more VM information, it has become more obvious that the easiest way to deal with bind and unbind is to simply put the function pointers in the vm, and let those choose the correct way to handle the page table updates. This change allows many places in the code to simply be vm->bind, and not have to worry about distinguishing PPGTT vs GGTT.

Quoted 8 lines
Quoted 3 lines

NOTE: At some point in the future, brining back insert_entries may in fact be desirable in order to use 1 bind/unbind for multiple generations of PPGTT. For now however, it's just not necessary.

I need to check the -internal tree again, but I'm rather sure that we need ->insert_entries. In that case I don't want to remove it here in the upstream tree since I have no intention to carry the re-add patch in -internal ;-)

We do use it for i915_ppgtt_bind_object(), however it should be easily fixable since the mini-series is exactly about removing i915_ppgtt_bind_object, and making into vm->bind_object. I think it's fair if you ask me to fix this up on -internal as well, before merging it, but with that one exception - I still believe this is the right direction to go in.

Quoted 26 lines
Quoted 13 lines
---
 drivers/gpu/drm/i915/i915_drv.h     |  9 +++++
 drivers/gpu/drm/i915/i915_gem_gtt.c | 72 +++++++++++++++++++++++++++++++++++++
 2 files changed, 81 insertions(+)
drivers/gpu/drm/i915/i915_drv.h +0 -0
index e6694ae..c2a9c98 100644

drivers/gpu/drm/i915/i915_drv.h struct i915_address_space { · line 491

Quoted 8 lines
drivers/gpu/drm/i915/i915_drv.h +5 -0
@@ -484,9 +484,18 @@ struct i915_address_space {
 	/* FIXME: Need a more generic return type */
 	gen6_gtt_pte_t (*pte_encode)(dma_addr_t addr,
 				     enum i915_cache_level level);
+
+	/** Unmap an object from an address space. This usually consists of
+	 * setting the valid PTE entries to a reserved scratch page. */
+	void (*unbind_object)(struct i915_address_space *vm,
+			      struct drm_i915_gem_object *obj);
	void (*unbind_vma)(struct i915_vma *vma);
	void (*bind_vma)(struct i915_vma *vma,
			 enum i915_cache_level cache_level);
Quoted 5 lines

I think if you do this as a follow-up we might as well bikeshed the interface a bit. Again (I know, broken record) for me it feels semantically much cleaner to talk about binding/unbindinig a vma instead of an (obj, vm) pair ...

So as mentioned (and I haven't yet responded to the other email, but I'll be broken record there also) - I don't disagree with you. My argument is the performance difference should be negligible, and the code as is, is decently tested. Changing this requires changing so much, I'd rather do the conversion on top. See the other mail thread for more...

Quoted 84 lines
Quoted 40 lines
drivers/gpu/drm/i915/i915_drv.h +4 -0
 	void (*clear_range)(struct i915_address_space *vm,
 			    unsigned int first_entry,
 			    unsigned int num_entries);
+	/* Map an object into an address space with the given cache flags. */
+	void (*bind_object)(struct i915_address_space *vm,
+			    struct drm_i915_gem_object *obj,
+			    enum i915_cache_level cache_level);
 	void (*insert_entries)(struct i915_address_space *vm,
 			       struct sg_table *st,
 			       unsigned int first_entry,
drivers/gpu/drm/i915/i915_gem_gtt.c +8 -0
index c0d0223..31ff971 100644
@@ -45,6 +45,12 @@
 #define GEN6_PTE_CACHE_LLC_MLC		(3 << 1)
 #define GEN6_PTE_ADDR_ENCODE(addr)	GEN6_GTT_ADDR_ENCODE(addr)
 
+static void gen6_ppgtt_bind_object(struct i915_address_space *vm,
+				   struct drm_i915_gem_object *obj,
+				   enum i915_cache_level cache_level);
+static void gen6_ppgtt_unbind_object(struct i915_address_space *vm,
+				     struct drm_i915_gem_object *obj);
+
 static gen6_gtt_pte_t gen6_pte_encode(dma_addr_t addr,
 				      enum i915_cache_level level)
 {
@@ -285,7 +291,9 @@ static int gen6_ppgtt_init(struct i915_hw_ppgtt *ppgtt)
 	}
 	ppgtt->num_pd_entries = GEN6_PPGTT_PD_ENTRIES;
 	ppgtt->enable = gen6_ppgtt_enable;
+	ppgtt->base.unbind_object = gen6_ppgtt_unbind_object;
 	ppgtt->base.clear_range = gen6_ppgtt_clear_range;
+	ppgtt->base.bind_object = gen6_ppgtt_bind_object;
 	ppgtt->base.insert_entries = gen6_ppgtt_insert_entries;
 	ppgtt->base.cleanup = gen6_ppgtt_cleanup;
 	ppgtt->base.scratch = dev_priv->gtt.base.scratch;
@@ -397,6 +405,17 @@ void i915_ppgtt_bind_object(struct i915_hw_ppgtt *ppgtt,
 			   cache_level);
 }

drivers/gpu/drm/i915/i915_gem_gtt.c void i915_ppgtt_bind_object(struct i915_hw_ppgtt *ppgtt, · line 416

Quoted 10 lines
drivers/gpu/drm/i915/i915_gem_gtt.c +9 -0
 
+static void gen6_ppgtt_bind_object(struct i915_address_space *vm,
+				   struct drm_i915_gem_object *obj,
+				   enum i915_cache_level cache_level)
+{
+	const unsigned long entry = i915_gem_obj_offset(obj, vm);
+
+	gen6_ppgtt_insert_entries(vm, obj->pages, entry >> PAGE_SHIFT,
+				  cache_level);
+	obj->has_aliasing_ppgtt_mapping = 1;

Since this is the bind function for ppgtt the aliasing ppgtt stuff looks a bit wrong here. Either we do the ppgtt insert_entries call as part of the global gtt bind call (if vm->aliasing_ppgtt is set) or we have a special global gtt binding call for execbuf.

Thinking about this some more we might need bind flags with

#define VMA_BIND_CPU (1<<0) /* ensure ggtt mapping exists for aliasing ppgtt */ #define VMA_BIND_GPU (1<<1) /* ensure ppgtt mappings exists for aliasing ppgtt */

since otherwise we can't properly encapsulate the aliasing ppgtt binding logic into vm->bind. So in the end we'd have

void ggtt_bind_vma(vma, bind_flags, cache_level)

{
	ggtt_vm = vma->vm;
	WARN_ON(ggtt_vm != &dev_priv->gtt.base);

	if ((!ggtt_vm->aliasing_ppgtt || (bind_flags & BIND_CPU)) &&
	    !obj->has_global_gtt_mapping) {
		ggtt_vm->insert_entries(vma->obj, vma->node.start, cache_leve);
		vma->obj->has_global_gtt_mapping = true;
	}

	if ((ggtt_vm->aliasing_ppgtt && (bind_flags & BIND_GPU)) &&
	    !obj->has_ppgtt_mapping) {
		ggtt_vm->aliasing_ppgtt->insert_entries(vma->obj,
							vma->node.start,
							cache_leve);
		vma->obj->has_ppgtt_mapping = true;
	}
}
Quoted 3 lines

Obviously completely untested, but I hope I could get the idea accross.

Cheers, Daniel

To me, aliasing ppgtt is just a wart that doesn't fit well with anything. As such, my plan was to hide as much of it as possible in ggtt functions. Using some kind of flag on ggtt_bind() we can determine if the user actually wants ggtt, and if so bind to both, else just use aliasing ppgtt. None of that code appears here because I want to make the diff churn as small as possible, and hadn't completely thought it all through.

Now after typing that (and this really did happen), I just looked at your function, and it seems to be more or less exactly what I just typed. Cool! The GPU/CPU naming scheme seems off to me, and I think you really just want one flag which specifies "bind it in the global gtt, sucka"

Now having just typed /that/, it was indeed my plan. So as long as nothing really bothers you with the bind/unbind() stuff, I can move forward with a patch on top to fix it.

Signature · 1 line
Ben Widawsky, Intel Open Source Technology Center
#45 lore raw

Re: [PATCH 1/3] drm/i915: Add bind/unbind object functions to VM

Quoted 165 lines · Ben Widawsky
Quoted 8 lines · Daniel Vetter
Quoted 7 lines · Ben Widawsky

As we plumb the code with more VM information, it has become more obvious that the easiest way to deal with bind and unbind is to simply put the function pointers in the vm, and let those choose the correct way to handle the page table updates. This change allows many places in the code to simply be vm->bind, and not have to worry about distinguishing PPGTT vs GGTT.

Quoted 8 lines
Quoted 3 lines

NOTE: At some point in the future, brining back insert_entries may in fact be desirable in order to use 1 bind/unbind for multiple generations of PPGTT. For now however, it's just not necessary.

I need to check the -internal tree again, but I'm rather sure that we need ->insert_entries. In that case I don't want to remove it here in the upstream tree since I have no intention to carry the re-add patch in -internal ;-)

We do use it for i915_ppgtt_bind_object(), however it should be easily fixable since the mini-series is exactly about removing i915_ppgtt_bind_object, and making into vm->bind_object. I think it's fair if you ask me to fix this up on -internal as well, before merging it, but with that one exception - I still believe this is the right direction to go in.

Quoted 26 lines
Quoted 13 lines
---
 drivers/gpu/drm/i915/i915_drv.h     |  9 +++++
 drivers/gpu/drm/i915/i915_gem_gtt.c | 72 +++++++++++++++++++++++++++++++++++++
 2 files changed, 81 insertions(+)
drivers/gpu/drm/i915/i915_drv.h +0 -0
index e6694ae..c2a9c98 100644

drivers/gpu/drm/i915/i915_drv.h struct i915_address_space { · line 491

Quoted 8 lines
drivers/gpu/drm/i915/i915_drv.h +5 -0
@@ -484,9 +484,18 @@ struct i915_address_space {
 	/* FIXME: Need a more generic return type */
 	gen6_gtt_pte_t (*pte_encode)(dma_addr_t addr,
 				     enum i915_cache_level level);
+
+	/** Unmap an object from an address space. This usually consists of
+	 * setting the valid PTE entries to a reserved scratch page. */
+	void (*unbind_object)(struct i915_address_space *vm,
+			      struct drm_i915_gem_object *obj);
	void (*unbind_vma)(struct i915_vma *vma);
	void (*bind_vma)(struct i915_vma *vma,
			 enum i915_cache_level cache_level);
Quoted 5 lines

I think if you do this as a follow-up we might as well bikeshed the interface a bit. Again (I know, broken record) for me it feels semantically much cleaner to talk about binding/unbindinig a vma instead of an (obj, vm) pair ...

So as mentioned (and I haven't yet responded to the other email, but I'll be broken record there also) - I don't disagree with you. My argument is the performance difference should be negligible, and the code as is, is decently tested. Changing this requires changing so much, I'd rather do the conversion on top. See the other mail thread for more...

Quoted 84 lines
Quoted 40 lines
drivers/gpu/drm/i915/i915_drv.h +4 -0
 	void (*clear_range)(struct i915_address_space *vm,
 			    unsigned int first_entry,
 			    unsigned int num_entries);
+	/* Map an object into an address space with the given cache flags. */
+	void (*bind_object)(struct i915_address_space *vm,
+			    struct drm_i915_gem_object *obj,
+			    enum i915_cache_level cache_level);
 	void (*insert_entries)(struct i915_address_space *vm,
 			       struct sg_table *st,
 			       unsigned int first_entry,
drivers/gpu/drm/i915/i915_gem_gtt.c +8 -0
index c0d0223..31ff971 100644
@@ -45,6 +45,12 @@
 #define GEN6_PTE_CACHE_LLC_MLC		(3 << 1)
 #define GEN6_PTE_ADDR_ENCODE(addr)	GEN6_GTT_ADDR_ENCODE(addr)
 
+static void gen6_ppgtt_bind_object(struct i915_address_space *vm,
+				   struct drm_i915_gem_object *obj,
+				   enum i915_cache_level cache_level);
+static void gen6_ppgtt_unbind_object(struct i915_address_space *vm,
+				     struct drm_i915_gem_object *obj);
+
 static gen6_gtt_pte_t gen6_pte_encode(dma_addr_t addr,
 				      enum i915_cache_level level)
 {
@@ -285,7 +291,9 @@ static int gen6_ppgtt_init(struct i915_hw_ppgtt *ppgtt)
 	}
 	ppgtt->num_pd_entries = GEN6_PPGTT_PD_ENTRIES;
 	ppgtt->enable = gen6_ppgtt_enable;
+	ppgtt->base.unbind_object = gen6_ppgtt_unbind_object;
 	ppgtt->base.clear_range = gen6_ppgtt_clear_range;
+	ppgtt->base.bind_object = gen6_ppgtt_bind_object;
 	ppgtt->base.insert_entries = gen6_ppgtt_insert_entries;
 	ppgtt->base.cleanup = gen6_ppgtt_cleanup;
 	ppgtt->base.scratch = dev_priv->gtt.base.scratch;
@@ -397,6 +405,17 @@ void i915_ppgtt_bind_object(struct i915_hw_ppgtt *ppgtt,
 			   cache_level);
 }

drivers/gpu/drm/i915/i915_gem_gtt.c void i915_ppgtt_bind_object(struct i915_hw_ppgtt *ppgtt, · line 416

Quoted 10 lines
drivers/gpu/drm/i915/i915_gem_gtt.c +9 -0
 
+static void gen6_ppgtt_bind_object(struct i915_address_space *vm,
+				   struct drm_i915_gem_object *obj,
+				   enum i915_cache_level cache_level)
+{
+	const unsigned long entry = i915_gem_obj_offset(obj, vm);
+
+	gen6_ppgtt_insert_entries(vm, obj->pages, entry >> PAGE_SHIFT,
+				  cache_level);
+	obj->has_aliasing_ppgtt_mapping = 1;

Since this is the bind function for ppgtt the aliasing ppgtt stuff looks a bit wrong here. Either we do the ppgtt insert_entries call as part of the global gtt bind call (if vm->aliasing_ppgtt is set) or we have a special global gtt binding call for execbuf.

Thinking about this some more we might need bind flags with

#define VMA_BIND_CPU (1<<0) /* ensure ggtt mapping exists for aliasing ppgtt */ #define VMA_BIND_GPU (1<<1) /* ensure ppgtt mappings exists for aliasing ppgtt */

since otherwise we can't properly encapsulate the aliasing ppgtt binding logic into vm->bind. So in the end we'd have

void ggtt_bind_vma(vma, bind_flags, cache_level)

{
	ggtt_vm = vma->vm;
	WARN_ON(ggtt_vm != &dev_priv->gtt.base);

	if ((!ggtt_vm->aliasing_ppgtt || (bind_flags & BIND_CPU)) &&
	    !obj->has_global_gtt_mapping) {
		ggtt_vm->insert_entries(vma->obj, vma->node.start, cache_leve);
		vma->obj->has_global_gtt_mapping = true;
	}

	if ((ggtt_vm->aliasing_ppgtt && (bind_flags & BIND_GPU)) &&
	    !obj->has_ppgtt_mapping) {
		ggtt_vm->aliasing_ppgtt->insert_entries(vma->obj,
							vma->node.start,
							cache_leve);
		vma->obj->has_ppgtt_mapping = true;
	}
}
Quoted 3 lines

Obviously completely untested, but I hope I could get the idea accross.

Cheers, Daniel

To me, aliasing ppgtt is just a wart that doesn't fit well with anything. As such, my plan was to hide as much of it as possible in ggtt functions. Using some kind of flag on ggtt_bind() we can determine if the user actually wants ggtt, and if so bind to both, else just use aliasing ppgtt. None of that code appears here because I want to make the diff churn as small as possible, and hadn't completely thought it all through.

Now after typing that (and this really did happen), I just looked at your function, and it seems to be more or less exactly what I just typed. Cool! The GPU/CPU naming scheme seems off to me, and I think you really just want one flag which specifies "bind it in the global gtt, sucka"

Quoted 4 lines

Now having just typed /that/, it was indeed my plan. So as long as nothing really bothers you with the bind/unbind() stuff, I can move forward with a patch on top to fix it.

I changed my mind already. A patch on top doesn't make sense. I'll try to fix this one up as is.

Signature · 1 line
Ben Widawsky, Intel Open Source Technology Center
#46 lore raw

Re: [PATCH 1/3] drm/i915: Add bind/unbind object functions to VM

Quoted 9 lines · Ben Widawsky
Quoted 8 lines · Ben Widawsky

To me, aliasing ppgtt is just a wart that doesn't fit well with anything. As such, my plan was to hide as much of it as possible in ggtt functions. Using some kind of flag on ggtt_bind() we can determine if the user actually wants ggtt, and if so bind to both, else just use aliasing ppgtt. None of that code appears here because I want to make the diff churn as small as possible, and hadn't completely thought it all through.

Quoted 5 lines
Quoted 5 lines

Now after typing that (and this really did happen), I just looked at your function, and it seems to be more or less exactly what I just typed. Cool! The GPU/CPU naming scheme seems off to me, and I think you really just want one flag which specifies "bind it in the global gtt, sucka"

Feel free to bikeshed the names, I tend to not be really good at that ;-) I guess a flag to switch between binding to ppgtt or ggtt would also work, I just slowly started to dislike make bool arguments and favour explicitly named flags/enums more. Better self-documenting code ...

Quoted 7 lines
Quoted 4 lines

Now having just typed /that/, it was indeed my plan. So as long as nothing really bothers you with the bind/unbind() stuff, I can move forward with a patch on top to fix it.

I changed my mind already. A patch on top doesn't make sense. I'll try to fix this one up as is.

Yeah, overall the thing that irks me is that you've added ppgtt bind functions despite that we don't yet bind anything into any real ppgtt address space. I'd recommend to just implement the ggtt bind functions (with the aliasing crap added) and then add the ppgtt bind functions once we get nearer to actually using them for real.
-Daniel

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
#47 lore raw

Re: [PATCH 1/3] drm/i915: Add bind/unbind object functions to VM

In reply to Ben Widawsky
Quoted 18 lines · Ben Widawsky
Quoted 8 lines · Daniel Vetter
Quoted 7 lines · Ben Widawsky

As we plumb the code with more VM information, it has become more obvious that the easiest way to deal with bind and unbind is to simply put the function pointers in the vm, and let those choose the correct way to handle the page table updates. This change allows many places in the code to simply be vm->bind, and not have to worry about distinguishing PPGTT vs GGTT.

Quoted 8 lines
Quoted 3 lines

NOTE: At some point in the future, brining back insert_entries may in fact be desirable in order to use 1 bind/unbind for multiple generations of PPGTT. For now however, it's just not necessary.

I need to check the -internal tree again, but I'm rather sure that we need ->insert_entries. In that case I don't want to remove it here in the upstream tree since I have no intention to carry the re-add patch in -internal ;-)

Quoted 6 lines

We do use it for i915_ppgtt_bind_object(), however it should be easily fixable since the mini-series is exactly about removing i915_ppgtt_bind_object, and making into vm->bind_object. I think it's fair if you ask me to fix this up on -internal as well, before merging it, but with that one exception - I still believe this is the right direction to go in.

My idea behind ->bind was that we could us this to hide the aliasing ppgtt stuff a bit, and otherwise keep things exactly as-is. I haven't actually looked at -internal to check whether it's as ugly as I expect ;-)

So if you promise to fix up -internal if I come screaming around due to rebase breakage I'm ok with either option.

Quoted 31 lines
Quoted 25 lines
Quoted 12 lines
---
 drivers/gpu/drm/i915/i915_drv.h     |  9 +++++
 drivers/gpu/drm/i915/i915_gem_gtt.c | 72 +++++++++++++++++++++++++++++++++++++
 2 files changed, 81 insertions(+)
drivers/gpu/drm/i915/i915_drv.h +0 -0
index e6694ae..c2a9c98 100644

drivers/gpu/drm/i915/i915_drv.h struct i915_address_space { · line 491

Quoted 8 lines
drivers/gpu/drm/i915/i915_drv.h +5 -0
@@ -484,9 +484,18 @@ struct i915_address_space {
 	/* FIXME: Need a more generic return type */
 	gen6_gtt_pte_t (*pte_encode)(dma_addr_t addr,
 				     enum i915_cache_level level);
+
+	/** Unmap an object from an address space. This usually consists of
+	 * setting the valid PTE entries to a reserved scratch page. */
+	void (*unbind_object)(struct i915_address_space *vm,
+			      struct drm_i915_gem_object *obj);
	void (*unbind_vma)(struct i915_vma *vma);
	void (*bind_vma)(struct i915_vma *vma,
			 enum i915_cache_level cache_level);
Quoted 5 lines

I think if you do this as a follow-up we might as well bikeshed the interface a bit. Again (I know, broken record) for me it feels semantically much cleaner to talk about binding/unbindinig a vma instead of an (obj, vm) pair ...

Quoted 5 lines

So as mentioned (and I haven't yet responded to the other email, but I'll be broken record there also) - I don't disagree with you. My argument is the performance difference should be negligible, and the code as is, is decently tested. Changing this requires changing so much, I'd rather do the conversion on top. See the other mail thread for more...

Yeah, I agree with the testing argument, sometimes I just want the Perfect Patch a bit too much ;-)
-Daniel

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
#48 lore raw

PATCH 2/3 drm/i915: Use the new vm [un]bind functions

In reply to Ben Widawsky

Building on the last patch which created the new function pointers in the VM for bind/unbind, here we actually put those new function pointers to use.

Split out as a separate patch to aid in review. I'm fine with squashing into the previous patch if people request it.

---
 drivers/gpu/drm/i915/i915_drv.h            | 10 -----
 drivers/gpu/drm/i915/i915_gem.c            | 36 +++++++--------
 drivers/gpu/drm/i915/i915_gem_context.c    |  6 ++-
 drivers/gpu/drm/i915/i915_gem_execbuffer.c | 19 ++++----
 drivers/gpu/drm/i915/i915_gem_gtt.c        | 70 +++++++++---------------------
 5 files changed, 52 insertions(+), 89 deletions(-)
drivers/gpu/drm/i915/i915_drv.h +0 -10
index c2a9c98..8f9569b 100644
@@ -1923,18 +1923,8 @@ int i915_gem_context_destroy_ioctl(struct drm_device *dev, void *data,
 
 /* i915_gem_gtt.c */
 void i915_gem_cleanup_aliasing_ppgtt(struct drm_device *dev);
-void i915_ppgtt_bind_object(struct i915_hw_ppgtt *ppgtt,
-			    struct drm_i915_gem_object *obj,
-			    enum i915_cache_level cache_level);
-void i915_ppgtt_unbind_object(struct i915_hw_ppgtt *ppgtt,
-			      struct drm_i915_gem_object *obj);
-
 void i915_gem_restore_gtt_mappings(struct drm_device *dev);
 int __must_check i915_gem_gtt_prepare_object(struct drm_i915_gem_object *obj);
-/* FIXME: this is never okay with full PPGTT */
-void i915_gem_gtt_bind_object(struct drm_i915_gem_object *obj,
-				enum i915_cache_level cache_level);
-void i915_gem_gtt_unbind_object(struct drm_i915_gem_object *obj);
 void i915_gem_gtt_finish_object(struct drm_i915_gem_object *obj);
 void i915_gem_init_global_gtt(struct drm_device *dev);
 void i915_gem_setup_global_gtt(struct drm_device *dev, unsigned long start,
drivers/gpu/drm/i915/i915_gem.c +16 -20
index 90d49fb..8e7a12d 100644
@@ -2655,12 +2655,9 @@ i915_gem_object_unbind(struct drm_i915_gem_object *obj,
 
 	trace_i915_gem_object_unbind(obj, vm);
 
-	if (obj->has_global_gtt_mapping && i915_is_ggtt(vm))
-		i915_gem_gtt_unbind_object(obj);
-	if (obj->has_aliasing_ppgtt_mapping) {
-		i915_ppgtt_unbind_object(dev_priv->mm.aliasing_ppgtt, obj);
-		obj->has_aliasing_ppgtt_mapping = 0;
-	}
+
+	vm->unbind_object(vm, obj);
+
 	i915_gem_gtt_finish_object(obj);
 	i915_gem_object_unpin_pages(obj);
 
@@ -3393,7 +3390,6 @@ int i915_gem_object_set_cache_level(struct drm_i915_gem_object *obj,
 				    enum i915_cache_level cache_level)
 {
 	struct drm_device *dev = obj->base.dev;
-	drm_i915_private_t *dev_priv = dev->dev_private;
 	struct i915_vma *vma = i915_gem_obj_to_vma(obj, vm);
 	int ret;
 
@@ -3428,13 +3424,8 @@ int i915_gem_object_set_cache_level(struct drm_i915_gem_object *obj,
 				return ret;
 		}
 
-		if (obj->has_global_gtt_mapping)
-			i915_gem_gtt_bind_object(obj, cache_level);
-		if (obj->has_aliasing_ppgtt_mapping)
-			i915_ppgtt_bind_object(dev_priv->mm.aliasing_ppgtt,
-					       obj, cache_level);
-
-		i915_gem_obj_set_color(obj, vma->vm, cache_level);
+		vm->bind_object(vm, obj, cache_level);
+		i915_gem_obj_set_color(obj, vm, cache_level);
 	}
 
 	if (cache_level == I915_CACHE_NONE) {
@@ -3716,6 +3707,7 @@ i915_gem_object_pin(struct drm_i915_gem_object *obj,
 		    bool map_and_fenceable,
 		    bool nonblocking)
 {
+	struct drm_i915_private *dev_priv = obj->base.dev->dev_private;
 	int ret;
 
 	if (WARN_ON(obj->pin_count == DRM_I915_GEM_OBJECT_MAX_PIN_COUNT))
@@ -3741,20 +3733,24 @@ i915_gem_object_pin(struct drm_i915_gem_object *obj,
 	}
 
 	if (!i915_gem_obj_bound(obj, vm)) {
-		struct drm_i915_private *dev_priv = obj->base.dev->dev_private;
-
 		ret = i915_gem_object_bind_to_gtt(obj, vm, alignment,
 						  map_and_fenceable,
 						  nonblocking);
 		if (ret)
 			return ret;
 
-		if (!dev_priv->mm.aliasing_ppgtt)
-			i915_gem_gtt_bind_object(obj, obj->cache_level);
+		if (!dev_priv->mm.aliasing_ppgtt) {
+			dev_priv->gtt.base.bind_object(&dev_priv->gtt.base,
+						       obj,
+						       obj->cache_level);
+		}
 	}
 
-	if (!obj->has_global_gtt_mapping && map_and_fenceable)
-		i915_gem_gtt_bind_object(obj, obj->cache_level);
+	if (!obj->has_global_gtt_mapping && map_and_fenceable) {
+		dev_priv->gtt.base.bind_object(&dev_priv->gtt.base,
+					       obj,
+					       obj->cache_level);
+	}
 
 	obj->pin_count++;
 	obj->pin_mappable |= map_and_fenceable;
drivers/gpu/drm/i915/i915_gem_context.c +4 -2
index c92fd81..177e42c 100644
@@ -424,8 +424,10 @@ static int do_switch(struct i915_hw_context *to)
 		return ret;
 	}
 
-	if (!to->obj->has_global_gtt_mapping)
-		i915_gem_gtt_bind_object(to->obj, to->obj->cache_level);
+	if (!to->obj->has_global_gtt_mapping) {
+		dev_priv->gtt.base.bind_object(&dev_priv->gtt.base,
+					       to->obj, to->obj->cache_level);
+	}
 
 	if (!to->is_initialized || is_default_context(to))
 		hw_flags |= MI_RESTORE_INHIBIT;
drivers/gpu/drm/i915/i915_gem_execbuffer.c +11 -8
index 725dd7f..9e9d955 100644
@@ -197,8 +197,10 @@ i915_gem_execbuffer_relocate_entry(struct drm_i915_gem_object *obj,
 	if (unlikely(IS_GEN6(dev) &&
 	    reloc->write_domain == I915_GEM_DOMAIN_INSTRUCTION &&
 	    !target_i915_obj->has_global_gtt_mapping)) {
-		i915_gem_gtt_bind_object(target_i915_obj,
-					 target_i915_obj->cache_level);
+		struct drm_i915_private *dev_priv = dev->dev_private;
+		dev_priv->gtt.base.bind_object(&dev_priv->gtt.base,
+					       target_i915_obj,
+					       target_i915_obj->cache_level);
 	}
 
 	/* Validate that the target is in a valid r/w GPU domain */
@@ -438,10 +440,9 @@ i915_gem_execbuffer_reserve_object(struct drm_i915_gem_object *obj,
 
 	/* Ensure ppgtt mapping exists if needed */
 	if (dev_priv->mm.aliasing_ppgtt && !obj->has_aliasing_ppgtt_mapping) {
-		i915_ppgtt_bind_object(dev_priv->mm.aliasing_ppgtt,
-				       obj, obj->cache_level);
-
-		obj->has_aliasing_ppgtt_mapping = 1;
+		struct i915_address_space *appgtt;
+		appgtt = &dev_priv->mm.aliasing_ppgtt->base;
+		appgtt->bind_object(appgtt, obj, obj->cache_level);
 	}
 
 	if (entry->offset != i915_gem_obj_offset(obj, vm)) {
@@ -456,7 +457,8 @@ i915_gem_execbuffer_reserve_object(struct drm_i915_gem_object *obj,
 
 	if (entry->flags & EXEC_OBJECT_NEEDS_GTT &&
 	    !obj->has_global_gtt_mapping)
-		i915_gem_gtt_bind_object(obj, obj->cache_level);
+		dev_priv->gtt.base.bind_object(&dev_priv->gtt.base,
+					       obj, obj->cache_level);
 
 	return 0;
 }
@@ -1046,7 +1048,8 @@ i915_gem_do_execbuffer(struct drm_device *dev, void *data,
 	 * hsw should have this fixed, but let's be paranoid and do it
 	 * unconditionally for now. */
 	if (flags & I915_DISPATCH_SECURE && !batch_obj->has_global_gtt_mapping)
-		i915_gem_gtt_bind_object(batch_obj, batch_obj->cache_level);
+		dev_priv->gtt.base.bind_object(&dev_priv->gtt.base, batch_obj,
+					       batch_obj->cache_level);
 
 	ret = i915_gem_execbuffer_move_to_gpu(ring, &eb->objects);
 	if (ret)
drivers/gpu/drm/i915/i915_gem_gtt.c +21 -49

101 lines not on this page · raw message

Signature · 1 line
1.8.3.2
#49 lore raw

PATCH 3/3 drm/i915: eliminate vm->insert_entries()

In reply to Ben Widawsky

With bind/unbind function pointers in place, we no longer need insert_entries. We could, and want, to remove clear_range, however it's not totally easy at this point. Since it's used in a couple of place still that don't only deal in objects: setup, ppgtt init, and restore gtt mappings.

---
 drivers/gpu/drm/i915/i915_drv.h     |  4 ----
 drivers/gpu/drm/i915/i915_gem_gtt.c | 15 ---------------
 2 files changed, 19 deletions(-)
drivers/gpu/drm/i915/i915_drv.h +0 -4
index 8f9569b..eb13399 100644
@@ -496,10 +496,6 @@ struct i915_address_space {
 	void (*bind_object)(struct i915_address_space *vm,
 			    struct drm_i915_gem_object *obj,
 			    enum i915_cache_level cache_level);
-	void (*insert_entries)(struct i915_address_space *vm,
-			       struct sg_table *st,
-			       unsigned int first_entry,
-			       enum i915_cache_level cache_level);
 	void (*cleanup)(struct i915_address_space *vm);
 };
 
drivers/gpu/drm/i915/i915_gem_gtt.c +0 -15
index 31bffb9..dd3d5e5 100644
@@ -294,7 +294,6 @@ static int gen6_ppgtt_init(struct i915_hw_ppgtt *ppgtt)
 	ppgtt->base.unbind_object = gen6_ppgtt_unbind_object;
 	ppgtt->base.clear_range = gen6_ppgtt_clear_range;
 	ppgtt->base.bind_object = gen6_ppgtt_bind_object;
-	ppgtt->base.insert_entries = gen6_ppgtt_insert_entries;
 	ppgtt->base.cleanup = gen6_ppgtt_cleanup;
 	ppgtt->base.scratch = dev_priv->gtt.base.scratch;
 	ppgtt->pt_pages = kzalloc(sizeof(struct page *)*ppgtt->num_pd_entries,
@@ -551,18 +550,6 @@ static void gen6_ggtt_clear_range(struct i915_address_space *vm,
 }
 
 
-static void i915_ggtt_insert_entries(struct i915_address_space *vm,
-				     struct sg_table *st,
-				     unsigned int pg_start,
-				     enum i915_cache_level cache_level)
-{
-	unsigned int flags = (cache_level == I915_CACHE_NONE) ?
-		AGP_USER_MEMORY : AGP_USER_CACHED_MEMORY;
-
-	intel_gtt_insert_sg_entries(st, pg_start, flags);
-
-}
-
 static void i915_ggtt_bind_object(struct i915_address_space *vm,
 				  struct drm_i915_gem_object *obj,
 				  enum i915_cache_level cache_level)
@@ -864,7 +851,6 @@ static int gen6_gmch_probe(struct drm_device *dev,
 
 	dev_priv->gtt.base.clear_range = gen6_ggtt_clear_range;
 	dev_priv->gtt.base.unbind_object = gen6_ggtt_unbind_object;
-	dev_priv->gtt.base.insert_entries = gen6_ggtt_insert_entries;
 	dev_priv->gtt.base.bind_object = gen6_ggtt_bind_object;
 
 	return ret;
@@ -898,7 +884,6 @@ static int i915_gmch_probe(struct drm_device *dev,
 	dev_priv->gtt.do_idle_maps = needs_idle_maps(dev_priv->dev);
 	dev_priv->gtt.base.clear_range = i915_ggtt_clear_range;
 	dev_priv->gtt.base.unbind_object = i915_ggtt_unbind_object;
-	dev_priv->gtt.base.insert_entries = i915_ggtt_insert_entries;
 	dev_priv->gtt.base.bind_object = i915_ggtt_bind_object;
 
 	return 0;
Signature · 1 line
1.8.3.2