Skip to contentSkip to conversation

drm/i915: Do not unmap object unless no other VMAs reference it

PATCH In review [email protected] 2 participants 11 messages Jul 11, 2014

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/i915: Do not unmap object unless no other VMAs reference it

From: Armin Reese <[email protected]>

---
 drivers/gpu/drm/i915/i915_gem.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/i915/i915_gem.c +3 -3
index 87d0aac..676e5f4 100644
@@ -2922,8 +2922,6 @@ int i915_vma_unbind(struct i915_vma *vma)
 
 	vma->unbind_vma(vma);
 
-	i915_gem_gtt_finish_object(obj);
-
 	list_del_init(&vma->mm_list);
 	/* Avoid an unnecessary call to unbind on rebind. */
 	if (i915_is_ggtt(vma->vm))
@@ -2934,8 +2932,10 @@ int i915_vma_unbind(struct i915_vma *vma)
 
 	/* Since the unbound list is global, only move to that list if
 	 * no more VMAs exist. */
-	if (list_empty(&obj->vma_list))
+	if (list_empty(&obj->vma_list)) {
+		i915_gem_gtt_finish_object(obj);
 		list_move_tail(&obj->global_list, &dev_priv->mm.unbound_list);
+	}
 
 	/* And finally now the object is completely decoupled from this vma,
 	 * we can drop its hold on the backing storage and allow it to be
Signature · 1 line
1.9.1
#1 lore raw

PATCH 1/1 drm/i915: Optimize the i915_gem_gtt_finish_object function

From: Armin Reese <[email protected]>

---
 drivers/gpu/drm/i915/i915_gem_gtt.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
drivers/gpu/drm/i915/i915_gem_gtt.c +6 -7
index afd4eef..7e2190e 100644
@@ -1624,18 +1624,17 @@ static void ggtt_unbind_vma(struct i915_vma *vma)
 
 void i915_gem_gtt_finish_object(struct drm_i915_gem_object *obj)
 {
-	struct drm_device *dev = obj->base.dev;
-	struct drm_i915_private *dev_priv = dev->dev_private;
-	bool interruptible;
-
-	interruptible = do_idling(dev_priv);
+	if (!obj->has_dma_mapping) {
+		struct drm_device *dev = obj->base.dev;
+		struct drm_i915_private *dev_priv = dev->dev_private;
+		bool interruptible = do_idling(dev_priv);
 
-	if (!obj->has_dma_mapping)
 		dma_unmap_sg(&dev->pdev->dev,
 			     obj->pages->sgl, obj->pages->nents,
 			     PCI_DMA_BIDIRECTIONAL);
 
-	undo_idling(dev_priv, interruptible);
+		undo_idling(dev_priv, interruptible);
+	}
 }
 
 static void i915_gtt_color_adjust(struct drm_mm_node *node,
Signature · 1 line
1.9.1
#2 lore raw

Re: [PATCH] drm/i915: Optimize the i915_gem_gtt_finish_object function

Quoted 23 lines · On Fri, Jul 11, 2014 at 10:15:36AM -0700, [email protected] wrote:

From: Armin Reese <[email protected]>

---
 drivers/gpu/drm/i915/i915_gem_gtt.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
drivers/gpu/drm/i915/i915_gem_gtt.c +3 -5
index afd4eef..7e2190e 100644
@@ -1624,18 +1624,17 @@ static void ggtt_unbind_vma(struct i915_vma *vma)
 
 void i915_gem_gtt_finish_object(struct drm_i915_gem_object *obj)
 {
-	struct drm_device *dev = obj->base.dev;
-	struct drm_i915_private *dev_priv = dev->dev_private;
-	bool interruptible;
-
-	interruptible = do_idling(dev_priv);
+	if (!obj->has_dma_mapping) {
+		struct drm_device *dev = obj->base.dev;
+		struct drm_i915_private *dev_priv = dev->dev_private;

drivers/gpu/drm/i915/i915_gem_gtt.c static void ggtt_unbind_vma(struct i915_vma *vma) · line 1637

Quoted 10 lines
drivers/gpu/drm/i915/i915_gem_gtt.c +3 -2
+		bool interruptible = do_idling(dev_priv);
 
-	if (!obj->has_dma_mapping)
 		dma_unmap_sg(&dev->pdev->dev,
 			     obj->pages->sgl, obj->pages->nents,
 			     PCI_DMA_BIDIRECTIONAL);
 
-	undo_idling(dev_priv, interruptible);
+		undo_idling(dev_priv, interruptible);
+	}

Are you really beating the compiler here?
-Chris

Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
#3 lore raw

Re: [PATCH] drm/i915: Optimize the i915_gem_gtt_finish_object function

Originally, the function always executes do_idling() followed by undo_idling() regardless of whether obj->has_dma_mapping is TRUE or not. This change idles the GPU only if needed.

However, if the intention of the function is to ALWAYS idle the GPU, then my change is a mistake.
- Armin

-----Original Message-----
From: Chris Wilson [mailto:[email protected]]
Sent: Friday, July 11, 2014 10:20 AM
To: Reese, Armin C
Cc: [email protected]
Subject: Re: [Intel-gfx] [PATCH] drm/i915: Optimize the i915_gem_gtt_finish_object function

Quoted 24 lines · On Fri, Jul 11, 2014 at 10:15:36AM -0700, [email protected] wrote:

From: Armin Reese <[email protected]>

---
 drivers/gpu/drm/i915/i915_gem_gtt.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
drivers/gpu/drm/i915/i915_gem_gtt.c +3 -5
index afd4eef..7e2190e 100644
@@ -1624,18 +1624,17 @@ static void ggtt_unbind_vma(struct i915_vma 
 *vma)
 
 void i915_gem_gtt_finish_object(struct drm_i915_gem_object *obj)  {
-	struct drm_device *dev = obj->base.dev;
-	struct drm_i915_private *dev_priv = dev->dev_private;
-	bool interruptible;
-
-	interruptible = do_idling(dev_priv);
+	if (!obj->has_dma_mapping) {
+		struct drm_device *dev = obj->base.dev;
+		struct drm_i915_private *dev_priv = dev->dev_private;

drivers/gpu/drm/i915/i915_gem_gtt.c static void ggtt_unbind_vma(struct i915_vma · line 1637

Quoted 10 lines
drivers/gpu/drm/i915/i915_gem_gtt.c +3 -2
+		bool interruptible = do_idling(dev_priv);
 
-	if (!obj->has_dma_mapping)
 		dma_unmap_sg(&dev->pdev->dev,
 			     obj->pages->sgl, obj->pages->nents,
 			     PCI_DMA_BIDIRECTIONAL);
 
-	undo_idling(dev_priv, interruptible);
+		undo_idling(dev_priv, interruptible);
+	}

Are you really beating the compiler here?
-Chris

--
Chris Wilson, Intel Open Source Technology Centre

#4 lore raw

Re: [PATCH] drm/i915: Optimize the i915_gem_gtt_finish_object function

Quoted 1 line · Armin C

Originally, the function always executes do_idling() followed by undo_idling() regardless of whether obj->has_dma_mapping is TRUE or not. This change idles the GPU only if needed.

But those functions will be inlined by the compiler, and if it is doing its job corectly will see more opportunity for optimising the branching. -Chris

Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
#5 lore raw

Re: [PATCH] drm/i915: Optimize the i915_gem_gtt_finish_object function

In reply to Reese, Armin C
Quoted 3 lines · Armin C

Originally, the function always executes do_idling() followed by undo_idling() regardless of whether obj->has_dma_mapping is TRUE or not. This change idles the GPU only if needed.

However, if the intention of the function is to ALWAYS idle the GPU, then my change is a mistake.

Ah yes. It is unclear whether the workaround also needs to be applied for stolen objects, but it is best to presume that it is. -Chris

Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
#6 lore raw

Re: [PATCH] drm/i915: Optimize the i915_gem_gtt_finish_object function

So the code should stay the way it is originally and assume GPU idling is always needed?
- Armin

-----Original Message-----
From: Chris Wilson [mailto:[email protected]]
Sent: Friday, July 11, 2014 10:37 AM
To: Reese, Armin C
Cc: [email protected]
Subject: Re: [Intel-gfx] [PATCH] drm/i915: Optimize the i915_gem_gtt_finish_object function

Quoted 3 lines · Armin C

Originally, the function always executes do_idling() followed by undo_idling() regardless of whether obj->has_dma_mapping is TRUE or not. This change idles the GPU only if needed.

However, if the intention of the function is to ALWAYS idle the GPU, then my change is a mistake.

Ah yes. It is unclear whether the workaround also needs to be applied for stolen objects, but it is best to presume that it is. -Chris

--
Chris Wilson, Intel Open Source Technology Centre

#7 lore raw

Re: [PATCH] drm/i915: Optimize the i915_gem_gtt_finish_object function

Quoted 1 line · Armin C

So the code should stay the way it is originally and assume GPU idling is always needed?

Yes, it also cover dmabuf imports as well. Definitely likely that we need to keep the wa for those.
-Chris

Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
#8 lore raw

Re: [PATCH] drm/i915: Optimize the i915_gem_gtt_finish_object function

OK, sounds like it's best to ignore this patch then.
- Armin

-----Original Message-----
From: Chris Wilson [mailto:[email protected]]
Sent: Friday, July 11, 2014 10:49 AM
To: Reese, Armin C
Cc: [email protected]
Subject: Re: [Intel-gfx] [PATCH] drm/i915: Optimize the i915_gem_gtt_finish_object function

Quoted 1 line · Armin C

So the code should stay the way it is originally and assume GPU idling is always needed?

Yes, it also cover dmabuf imports as well. Definitely likely that we need to keep the wa for those. -Chris

--
Chris Wilson, Intel Open Source Technology Centre

#10 lore raw

No bugs have been reported so far ...
Daniel caught this by inspection of the Full PPGTT patch set and wanted me to fix it.
- Armin

-----Original Message-----
From: Chris Wilson [mailto:[email protected]]
Sent: Friday, July 11, 2014 10:21 AM
To: Reese, Armin C
Cc: [email protected]
Subject: Re: [Intel-gfx] [PATCH] drm/i915: Do not unmap object unless no other VMAs reference it

Quoted 1 line · On Fri, Jul 11, 2014 at 10:15:35AM -0700, [email protected] wrote:

From: Armin Reese <[email protected]>

If you can a description of how to trigger the bug and the user impact would be great. And Daniel is about to ask for a test case in 3 seconds... -Chris

--
Chris Wilson, Intel Open Source Technology Centre