Skip to contentSkip to conversation

drm/amdgpu:fix gfx fence allocate size

PATCH In review Monk Liu 3 participants 3 messages Jul 18, 2017 2 messages not in the archive

Subsystems (2)
lore
Share & tools
lore

Monk Liu

author
#0 lore raw

PATCH 1/1 drm/amdgpu:fix gfx fence allocate size

1, for sriov, we need 8dw for the gfx fence due to CP behaviour
2, cleanup wrong logic in wptr/rptr wb alloc and free

Change-Id Ifbfed17a4621dae57244942ffac7de1743de0294
---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h        |  2 ++
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 32 ++++++++++++++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c   | 26 ++++++++++++++++--------
 3 files changed, 52 insertions(+), 8 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +2 -0
index f6345b9..fe96236 100644
@@ -1191,7 +1191,9 @@ struct amdgpu_wb {
 int amdgpu_wb_get(struct amdgpu_device *adev, u32 *wb);
 void amdgpu_wb_free(struct amdgpu_device *adev, u32 wb);
 int amdgpu_wb_get_64bit(struct amdgpu_device *adev, u32 *wb);
+int amdgpu_wb_get_256Bit(struct amdgpu_device *adev, u32 *wb);
 void amdgpu_wb_free_64bit(struct amdgpu_device *adev, u32 wb);
+void amdgpu_wb_free_256bit(struct amdgpu_device *adev, u32 wb);
 
 void amdgpu_get_pcie_info(struct amdgpu_device *adev);
 
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +32 -0
index 7e11190..6050804 100644
@@ -603,6 +603,21 @@ int amdgpu_wb_get_64bit(struct amdgpu_device *adev, u32 *wb)
 	}
 }
 
+int amdgpu_wb_get_256Bit(struct amdgpu_device *adev, u32 *wb)
+{
+	int i = 0;
+	unsigned long offset = bitmap_find_next_zero_area_off(adev->wb.used,
+				adev->wb.num_wb, 0, 8, 63, 0);
+	if ((offset + 7) < adev->wb.num_wb) {
+		for (i = 0; i < 8; i++)
+			__set_bit(offset + i, adev->wb.used);
+		*wb = offset;
+		return 0;
+	} else {
+		return -EINVAL;
+	}
+}
+
 /**
  * amdgpu_wb_free - Free a wb entry
  *
@@ -634,6 +649,23 @@ void amdgpu_wb_free_64bit(struct amdgpu_device *adev, u32 wb)
 }
 
 /**
+ * amdgpu_wb_free_256bit - Free a wb entry
+ *
+ * @adev: amdgpu_device pointer
+ * @wb: wb index
+ *
+ * Free a wb slot allocated for use by the driver (all asics)
+ */
+void amdgpu_wb_free_256bit(struct amdgpu_device *adev, u32 wb)
+{
+	int i = 0;
+
+	if ((wb + 7) < adev->wb.num_wb)
+		for (i = 0; i < 8; i++)
+			__clear_bit(wb + i, adev->wb.used);
+}
+
+/**
  * amdgpu_vram_location - try to find VRAM location
  * @adev: amdgpu device structure holding all necessary informations
  * @mc: memory controller structure holding memory informations
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +18 -8
index 75165e0..eea17ae 100644
@@ -212,10 +212,19 @@ int amdgpu_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring,
 
 	}
 
-	r = amdgpu_wb_get(adev, &ring->fence_offs);
-	if (r) {
-		dev_err(adev->dev, "(%d) ring fence_offs wb alloc failed\n", r);
-		return r;
+	if (amdgpu_sriov_vf(adev) && ring->funcs->type == AMDGPU_RING_TYPE_GFX) {
+		r = amdgpu_wb_get_256Bit(adev, &ring->fence_offs);
+		if (r) {
+			dev_err(adev->dev, "(%d) ring fence_offs wb alloc failed\n", r);
+			return r;
+		}
+
+	} else {
+		r = amdgpu_wb_get(adev, &ring->fence_offs);
+		if (r) {
+			dev_err(adev->dev, "(%d) ring fence_offs wb alloc failed\n", r);
+			return r;
+		}
 	}
 
 	r = amdgpu_wb_get(adev, &ring->cond_exe_offs);
@@ -278,17 +287,18 @@ void amdgpu_ring_fini(struct amdgpu_ring *ring)
 	ring->ready = false;
 
 	if (ring->funcs->support_64bit_ptrs) {
-		amdgpu_wb_free_64bit(ring->adev, ring->cond_exe_offs);
-		amdgpu_wb_free_64bit(ring->adev, ring->fence_offs);
 		amdgpu_wb_free_64bit(ring->adev, ring->rptr_offs);
 		amdgpu_wb_free_64bit(ring->adev, ring->wptr_offs);
 	} else {
-		amdgpu_wb_free(ring->adev, ring->cond_exe_offs);
-		amdgpu_wb_free(ring->adev, ring->fence_offs);
 		amdgpu_wb_free(ring->adev, ring->rptr_offs);
 		amdgpu_wb_free(ring->adev, ring->wptr_offs);
 	}
 
+	amdgpu_wb_free(ring->adev, ring->cond_exe_offs);
+	if (amdgpu_sriov_vf(ring->adev) && ring->funcs->type == AMDGPU_RING_TYPE_GFX)
+		amdgpu_wb_free_256bit(ring->adev, ring->fence_offs);
+	else
+		amdgpu_wb_free(ring->adev, ring->cond_exe_offs);
 
 	amdgpu_bo_free_kernel(&ring->ring_obj,
 			      &ring->gpu_addr,
Signature · 6 lines
2.7.4

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 1500352822-29824-1-git-send-email-Monk.Liu-5C7GfCeVMHo@public.gmane.org

Reviewed-by Alex Deucher
#2 lore raw
Quoted 44 lines

-----Original Message-----
From: amd-gfx [mailto:[email protected]] On Behalf Of Monk Liu
Sent: Tuesday, July 18, 2017 12:40 AM
To: [email protected]
Cc: Yu, Xiangliang; Liu, Monk
Subject: [PATCH] drm/amdgpu:fix gfx fence allocate size

1, for sriov, we need 8dw for the gfx fence due to CP behaviour
2, cleanup wrong logic in wptr/rptr wb alloc and free

Change-Id Ifbfed17a4621dae57244942ffac7de1743de0294
---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h        |  2 ++
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 32
++++++++++++++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c   | 26 ++++++++++++++++---
-----
 3 files changed, 52 insertions(+), 8 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +2 -0
index f6345b9..fe96236 100644
@@ -1191,7 +1191,9 @@ struct amdgpu_wb {
 int amdgpu_wb_get(struct amdgpu_device *adev, u32 *wb);
 void amdgpu_wb_free(struct amdgpu_device *adev, u32 wb);
 int amdgpu_wb_get_64bit(struct amdgpu_device *adev, u32 *wb);
+int amdgpu_wb_get_256Bit(struct amdgpu_device *adev, u32 *wb);
 void amdgpu_wb_free_64bit(struct amdgpu_device *adev, u32 wb);
+void amdgpu_wb_free_256bit(struct amdgpu_device *adev, u32 wb);
 
 void amdgpu_get_pcie_info(struct amdgpu_device *adev);
 
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
index 7e11190..6050804 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c int amdgpu_wb_get_64bit(struct amdgpu_device · line 607

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1 -0
@@ -603,6 +603,21 @@ int amdgpu_wb_get_64bit(struct amdgpu_device
 *adev, u32 *wb)
 	}
 }
 
+int amdgpu_wb_get_256Bit(struct amdgpu_device *adev, u32 *wb)

For consistency with the free function and the rest of the code, make this 256bit (lower case b). Then, split this patch in two, one patch to add the new wb interface, and one to fix the fence code for sr-iov. With those changes:

Alex

Quoted 104 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +14 -0
+{
+	int i = 0;
+	unsigned long offset = bitmap_find_next_zero_area_off(adev-
 >wb.used,
+				adev->wb.num_wb, 0, 8, 63, 0);
+	if ((offset + 7) < adev->wb.num_wb) {
+		for (i = 0; i < 8; i++)
+			__set_bit(offset + i, adev->wb.used);
+		*wb = offset;
+		return 0;
+	} else {
+		return -EINVAL;
+	}
+}
+
 /**

* amdgpu_wb_free - Free a wb entry
*

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +17 -0
@@ -634,6 +649,23 @@ void amdgpu_wb_free_64bit(struct amdgpu_device
 *adev, u32 wb)
 }
 
 /**
+ * amdgpu_wb_free_256bit - Free a wb entry
+ *
+ * @adev: amdgpu_device pointer
+ * @wb: wb index
+ *
+ * Free a wb slot allocated for use by the driver (all asics)
+ */
+void amdgpu_wb_free_256bit(struct amdgpu_device *adev, u32 wb)
+{
+	int i = 0;
+
+	if ((wb + 7) < adev->wb.num_wb)
+		for (i = 0; i < 8; i++)
+			__clear_bit(wb + i, adev->wb.used);
+}
+
+/**
  * amdgpu_vram_location - try to find VRAM location
  * @adev: amdgpu device structure holding all necessary informations

* @mc: memory controller structure holding memory informations

drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +4 -4
index 75165e0..eea17ae 100644
@@ -212,10 +212,19 @@ int amdgpu_ring_init(struct amdgpu_device *adev,
 struct amdgpu_ring *ring,
 
 	}
 
-	r = amdgpu_wb_get(adev, &ring->fence_offs);
-	if (r) {
-		dev_err(adev->dev, "(%d) ring fence_offs wb alloc failed\n",
 r);
-		return r;
+	if (amdgpu_sriov_vf(adev) && ring->funcs->type ==
 AMDGPU_RING_TYPE_GFX) {
+		r = amdgpu_wb_get_256Bit(adev, &ring->fence_offs);
+		if (r) {
+			dev_err(adev->dev, "(%d) ring fence_offs wb alloc

failed\n", r);

drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +7 -0
+			return r;
+		}
+
+	} else {
+		r = amdgpu_wb_get(adev, &ring->fence_offs);
+		if (r) {
+			dev_err(adev->dev, "(%d) ring fence_offs wb alloc

failed\n", r);

drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +7 -4
+			return r;
+		}
 	}
 
 	r = amdgpu_wb_get(adev, &ring->cond_exe_offs);
@@ -278,17 +287,18 @@ void amdgpu_ring_fini(struct amdgpu_ring *ring)
 	ring->ready = false;
 
 	if (ring->funcs->support_64bit_ptrs) {
-		amdgpu_wb_free_64bit(ring->adev, ring->cond_exe_offs);
-		amdgpu_wb_free_64bit(ring->adev, ring->fence_offs);
 		amdgpu_wb_free_64bit(ring->adev, ring->rptr_offs);
 		amdgpu_wb_free_64bit(ring->adev, ring->wptr_offs);
 	} else {
-		amdgpu_wb_free(ring->adev, ring->cond_exe_offs);
-		amdgpu_wb_free(ring->adev, ring->fence_offs);
 		amdgpu_wb_free(ring->adev, ring->rptr_offs);
 		amdgpu_wb_free(ring->adev, ring->wptr_offs);
 	}
 
+	amdgpu_wb_free(ring->adev, ring->cond_exe_offs);
+	if (amdgpu_sriov_vf(ring->adev) && ring->funcs->type ==
 AMDGPU_RING_TYPE_GFX)
+		amdgpu_wb_free_256bit(ring->adev, ring->fence_offs);
+	else
+		amdgpu_wb_free(ring->adev, ring->cond_exe_offs);
 
 	amdgpu_bo_free_kernel(&ring->ring_obj,

&ring->gpu_addr,
--
2.7.4

Quoted 4 lines

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): CY4PR12MB1653075900EC7085BC14158EF7A10-rpdhrqHFk06apTa93KjAaQdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org

#4 lore raw

Am 18.07.2017 um 14:50 schrieb Deucher, Alexander:

Quoted 48 lines
Quoted 48 lines

-----Original Message-----
From: amd-gfx [mailto:[email protected]] On Behalf Of Monk Liu
Sent: Tuesday, July 18, 2017 12:40 AM
To: [email protected]
Cc: Yu, Xiangliang; Liu, Monk
Subject: [PATCH] drm/amdgpu:fix gfx fence allocate size

1, for sriov, we need 8dw for the gfx fence due to CP behaviour
2, cleanup wrong logic in wptr/rptr wb alloc and free

Change-Id Ifbfed17a4621dae57244942ffac7de1743de0294
---
  drivers/gpu/drm/amd/amdgpu/amdgpu.h        |  2 ++
  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 32
++++++++++++++++++++++++++++++
  drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c   | 26 ++++++++++++++++---
-----
  3 files changed, 52 insertions(+), 8 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +2 -0
index f6345b9..fe96236 100644
@@ -1191,7 +1191,9 @@ struct amdgpu_wb {
  int amdgpu_wb_get(struct amdgpu_device *adev, u32 *wb);
  void amdgpu_wb_free(struct amdgpu_device *adev, u32 wb);
  int amdgpu_wb_get_64bit(struct amdgpu_device *adev, u32 *wb);
+int amdgpu_wb_get_256Bit(struct amdgpu_device *adev, u32 *wb);
  void amdgpu_wb_free_64bit(struct amdgpu_device *adev, u32 wb);
+void amdgpu_wb_free_256bit(struct amdgpu_device *adev, u32 wb);
 
  void amdgpu_get_pcie_info(struct amdgpu_device *adev);
 
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
index 7e11190..6050804 100644
@@ -603,6 +603,21 @@ int amdgpu_wb_get_64bit(struct amdgpu_device
 *adev, u32 *wb)
  	}
  }
 
Quoted 3 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c int amdgpu_wb_get_64bit(struct amdgpu_device *adev, u32 *wb) · line 606

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1 -0
+int amdgpu_wb_get_256Bit(struct amdgpu_device *adev, u32 *wb)

For consistency with the free function and the rest of the code, make this 256bit (lower case b). Then, split this patch in two, one patch to add the new wb interface, and one to fix the fence code for sr-iov. With those changes:

BTW: Would it hurt us if we always allocate 256bits of writeback for each slot?

I mean the WB BO is 4K in size, so that gives us 256 slot with 16 bytes each and I think in total we use something like maybe ~40 at maximum.

This way we wouldn't need 3 different get/free functions and save us a bunch of logic spread around everywhere.

Anyway that can come later, let's fix the bug first. So with Alex suggestions the patch is Reviewed-by: Christian König <[email protected]> as well.

Christian.

Quoted 107 lines

Alex

Quoted 104 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +14 -0
+{
+	int i = 0;
+	unsigned long offset = bitmap_find_next_zero_area_off(adev-
 > wb.used,
+				adev->wb.num_wb, 0, 8, 63, 0);
+	if ((offset + 7) < adev->wb.num_wb) {
+		for (i = 0; i < 8; i++)
+			__set_bit(offset + i, adev->wb.used);
+		*wb = offset;
+		return 0;
+	} else {
+		return -EINVAL;
+	}
+}
+
  /**

* amdgpu_wb_free - Free a wb entry
*

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +17 -0
@@ -634,6 +649,23 @@ void amdgpu_wb_free_64bit(struct amdgpu_device
 *adev, u32 wb)
  }
 
  /**
+ * amdgpu_wb_free_256bit - Free a wb entry
+ *
+ * @adev: amdgpu_device pointer
+ * @wb: wb index
+ *
+ * Free a wb slot allocated for use by the driver (all asics)
+ */
+void amdgpu_wb_free_256bit(struct amdgpu_device *adev, u32 wb)
+{
+	int i = 0;
+
+	if ((wb + 7) < adev->wb.num_wb)
+		for (i = 0; i < 8; i++)
+			__clear_bit(wb + i, adev->wb.used);
+}
+
+/**
   * amdgpu_vram_location - try to find VRAM location
   * @adev: amdgpu device structure holding all necessary informations

* @mc: memory controller structure holding memory informations

drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +4 -4
index 75165e0..eea17ae 100644
@@ -212,10 +212,19 @@ int amdgpu_ring_init(struct amdgpu_device *adev,
 struct amdgpu_ring *ring,
 
  	}
 
-	r = amdgpu_wb_get(adev, &ring->fence_offs);
-	if (r) {
-		dev_err(adev->dev, "(%d) ring fence_offs wb alloc failed\n",
 r);
-		return r;
+	if (amdgpu_sriov_vf(adev) && ring->funcs->type ==
 AMDGPU_RING_TYPE_GFX) {
+		r = amdgpu_wb_get_256Bit(adev, &ring->fence_offs);
+		if (r) {
+			dev_err(adev->dev, "(%d) ring fence_offs wb alloc

failed\n", r);

drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +7 -0
+			return r;
+		}
+
+	} else {
+		r = amdgpu_wb_get(adev, &ring->fence_offs);
+		if (r) {
+			dev_err(adev->dev, "(%d) ring fence_offs wb alloc

failed\n", r);

drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +7 -4
+			return r;
+		}
  	}
 
  	r = amdgpu_wb_get(adev, &ring->cond_exe_offs);
@@ -278,17 +287,18 @@ void amdgpu_ring_fini(struct amdgpu_ring *ring)
  	ring->ready = false;
 
  	if (ring->funcs->support_64bit_ptrs) {
-		amdgpu_wb_free_64bit(ring->adev, ring->cond_exe_offs);
-		amdgpu_wb_free_64bit(ring->adev, ring->fence_offs);
  		amdgpu_wb_free_64bit(ring->adev, ring->rptr_offs);
  		amdgpu_wb_free_64bit(ring->adev, ring->wptr_offs);
  	} else {
-		amdgpu_wb_free(ring->adev, ring->cond_exe_offs);
-		amdgpu_wb_free(ring->adev, ring->fence_offs);
  		amdgpu_wb_free(ring->adev, ring->rptr_offs);
  		amdgpu_wb_free(ring->adev, ring->wptr_offs);
  	}
 
+	amdgpu_wb_free(ring->adev, ring->cond_exe_offs);
+	if (amdgpu_sriov_vf(ring->adev) && ring->funcs->type ==
 AMDGPU_RING_TYPE_GFX)
+		amdgpu_wb_free_256bit(ring->adev, ring->fence_offs);
+	else
+		amdgpu_wb_free(ring->adev, ring->cond_exe_offs);
 
  	amdgpu_bo_free_kernel(&ring->ring_obj,

&ring->gpu_addr,
--
2.7.4

Quoted 8 lines
Quoted 4 lines

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx