Skip to contentSkip to conversation

drm/amdgpu: do not call insert_nop fn for zero count

PATCH In review Sunil Khatri 3 participants 4 messages Jul 31, 2024 – Aug 1, 2024

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

PATCH 1/2 drm/amdgpu: do not call insert_nop fn for zero count

Do not make a function call for zero size NOP as it does not add anything in the ring and is unnecessary function call.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +3 -1
index ad49cecb20b8..0d72d2cbb64b 100644
@@ -145,7 +145,9 @@ void amdgpu_ring_commit(struct amdgpu_ring *ring)
 	count = ring->funcs->align_mask + 1 -
 		(ring->wptr & ring->funcs->align_mask);
 	count %= ring->funcs->align_mask + 1;
-	ring->funcs->insert_nop(ring, count);
+
+	if (count != 0)
+		ring->funcs->insert_nop(ring, count);
 
 	mb();
 	amdgpu_ring_set_wptr(ring);
Signature · 1 line
2.34.1
#1 lore raw

PATCH 2/2 drm/amdgpu: optimize the padding for gfx11

Adding NOP packets one by one in the ring
does not use the CP efficiently.

Solution:
Use CP optimization while adding NOP packet's so PFP can discard NOP packets based on information of count from the Header instead of fetching all NOP packets one by one.

Cc Christian König <[email protected]>
Cc Pierre-Eric Pelloux-Prayer <[email protected]>
Cc Tvrtko Ursulin <[email protected]>
Cc Marek Olšák <[email protected]>
---
 drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +20 -2
index 4a9766635933..e7c160b9d0fe 100644
@@ -481,6 +481,24 @@ static void gfx_v11_0_wait_reg_mem(struct amdgpu_ring *ring, int eng_sel,
 	amdgpu_ring_write(ring, inv); /* poll interval */
 }
 
+static void gfx_v11_ring_insert_nop(struct amdgpu_ring *ring, uint32_t num_nop)
+{
+	int i;
+
+	/* Header itself is a NOP packet */
+	if (num_nop == 1) {
+		amdgpu_ring_write(ring, ring->funcs->nop);
+		return;
+	}
+
+	/* Max HW optimization till 0x3ffe, followed by remaining one NOP at a time*/
+	amdgpu_ring_write(ring, PACKET3(PACKET3_NOP, min(num_nop - 2, 0x3ffe)));
+
+	/* Header is at index 0, followed by num_nops - 1 NOP packet's */
+	for (i = 1; i < num_nop; i++)
+		amdgpu_ring_write(ring, ring->funcs->nop);
+}
+
 static int gfx_v11_0_ring_test_ring(struct amdgpu_ring *ring)
 {
 	struct amdgpu_device *adev = ring->adev;
@@ -6709,7 +6727,7 @@ static const struct amdgpu_ring_funcs gfx_v11_0_ring_funcs_gfx = {
 	.emit_hdp_flush = gfx_v11_0_ring_emit_hdp_flush,
 	.test_ring = gfx_v11_0_ring_test_ring,
 	.test_ib = gfx_v11_0_ring_test_ib,
-	.insert_nop = amdgpu_ring_insert_nop,
+	.insert_nop = gfx_v11_ring_insert_nop,
 	.pad_ib = amdgpu_ring_generic_pad_ib,
 	.emit_cntxcntl = gfx_v11_0_ring_emit_cntxcntl,
 	.emit_gfx_shadow = gfx_v11_0_ring_emit_gfx_shadow,
@@ -6751,7 +6769,7 @@ static const struct amdgpu_ring_funcs gfx_v11_0_ring_funcs_compute = {
 	.emit_hdp_flush = gfx_v11_0_ring_emit_hdp_flush,
 	.test_ring = gfx_v11_0_ring_test_ring,
 	.test_ib = gfx_v11_0_ring_test_ib,
-	.insert_nop = amdgpu_ring_insert_nop,
+	.insert_nop = gfx_v11_ring_insert_nop,
 	.pad_ib = amdgpu_ring_generic_pad_ib,
 	.emit_wreg = gfx_v11_0_ring_emit_wreg,
 	.emit_reg_wait = gfx_v11_0_ring_emit_reg_wait,
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH 2/2] drm/amdgpu: optimize the padding for gfx11

Quoted 33 lines · Sunil Khatri

Adding NOP packets one by one in the ring
does not use the CP efficiently.

Solution:
Use CP optimization while adding NOP packet's so PFP can discard NOP packets based on information of count from the Header instead of fetching all NOP packets one by one.

Cc Christian König <[email protected]>
Cc Pierre-Eric Pelloux-Prayer <[email protected]>
Cc Tvrtko Ursulin <[email protected]>
Cc Marek Olšák <[email protected]>
---
 drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +6 -0
index 4a9766635933..e7c160b9d0fe 100644
@@ -481,6 +481,24 @@ static void gfx_v11_0_wait_reg_mem(struct amdgpu_ring *ring, int eng_sel,
        amdgpu_ring_write(ring, inv); /* poll interval */
 }
 
+static void gfx_v11_ring_insert_nop(struct amdgpu_ring *ring, uint32_t num_nop)
+{
+       int i;
+
+       /* Header itself is a NOP packet */
+       if (num_nop == 1) {

drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c static void gfx_v11_0_wait_reg_mem(struct amdgpu_ring *ring, int eng_sel, · line 499

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +10 -0
+               amdgpu_ring_write(ring, ring->funcs->nop);
+               return;
+       }
+
+       /* Max HW optimization till 0x3ffe, followed by remaining one NOP at a time*/
+       amdgpu_ring_write(ring, PACKET3(PACKET3_NOP, min(num_nop - 2, 0x3ffe)));
+
+       /* Header is at index 0, followed by num_nops - 1 NOP packet's */
+       for (i = 1; i < num_nop; i++)
+               amdgpu_ring_write(ring, ring->funcs->nop);

This loop should be removed. I explained the reason in the gfx10 commit.

Marek

Quoted 26 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +4 -3
+}
+
 static int gfx_v11_0_ring_test_ring(struct amdgpu_ring *ring)
 {
        struct amdgpu_device *adev = ring->adev;
@@ -6709,7 +6727,7 @@ static const struct amdgpu_ring_funcs gfx_v11_0_ring_funcs_gfx = {
        .emit_hdp_flush = gfx_v11_0_ring_emit_hdp_flush,
        .test_ring = gfx_v11_0_ring_test_ring,
        .test_ib = gfx_v11_0_ring_test_ib,
-       .insert_nop = amdgpu_ring_insert_nop,
+       .insert_nop = gfx_v11_ring_insert_nop,
        .pad_ib = amdgpu_ring_generic_pad_ib,
        .emit_cntxcntl = gfx_v11_0_ring_emit_cntxcntl,
        .emit_gfx_shadow = gfx_v11_0_ring_emit_gfx_shadow,
@@ -6751,7 +6769,7 @@ static const struct amdgpu_ring_funcs gfx_v11_0_ring_funcs_compute = {
        .emit_hdp_flush = gfx_v11_0_ring_emit_hdp_flush,
        .test_ring = gfx_v11_0_ring_test_ring,
        .test_ib = gfx_v11_0_ring_test_ib,
-       .insert_nop = amdgpu_ring_insert_nop,
+       .insert_nop = gfx_v11_ring_insert_nop,
        .pad_ib = amdgpu_ring_generic_pad_ib,
        .emit_wreg = gfx_v11_0_ring_emit_wreg,
        .emit_reg_wait = gfx_v11_0_ring_emit_reg_wait,
--

2.34.1

maintainer
#3 lore raw
In reply to Sunil Khatri

Adding Tvrtko since he was working on a similar patch.

Am 31.07.24 um 10:12 schrieb Sunil Khatri:

Quoted 5 lines

Do not make a function call for zero size NOP as it does not add anything in the ring and is unnecessary function call.

Please double check if we have some count==0 handling in some of the NOP functions and if possible remove them.

Apart from that this patch set is Reviewed-by: Christian König <[email protected]>.

Thanks,
Christian.

Quoted 19 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +3 -1
index ad49cecb20b8..0d72d2cbb64b 100644
@@ -145,7 +145,9 @@ void amdgpu_ring_commit(struct amdgpu_ring *ring)
  	count = ring->funcs->align_mask + 1 -
  		(ring->wptr & ring->funcs->align_mask);
  	count %= ring->funcs->align_mask + 1;
-	ring->funcs->insert_nop(ring, count);
+
+	if (count != 0)
+		ring->funcs->insert_nop(ring, count);
 
  	mb();
  	amdgpu_ring_set_wptr(ring);