Skip to contentSkip to conversation

More compact IB emission

PATCH Applied Tvrtko Ursulin 2 participants 27 messages Sep 11, 2025 – Oct 31, 2025

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

cover More compact IB emission

In short, this series mostly does a lot of replacing of this pattern:

       ib->ptr[ib->length_dw++] = SDMA_PKT_HEADER_OP(SDMA_OP_WRITE) |
               SDMA_PKT_HEADER_SUB_OP(SDMA_SUBOP_WRITE_LINEAR);
       ib->ptr[ib->length_dw++] = lower_32_bits(pe);
       ib->ptr[ib->length_dw++] = upper_32_bits(pe);
       ib->ptr[ib->length_dw++] = ndw - 1;
       for (; ndw > 0; ndw -= 2) {
              ib->ptr[ib->length_dw++] = lower_32_bits(value);
              ib->ptr[ib->length_dw++] = upper_32_bits(value);
               value += incr;
       }

With this one:

       u32 *ptr = &ib->ptr[ib->length_dw];

       *ptr++ = SDMA_PKT_HEADER_OP(SDMA_OP_WRITE) |
                SDMA_PKT_HEADER_SUB_OP(SDMA_SUBOP_WRITE_LINEAR);
       *ptr++ = lower_32_bits(pe);
       *ptr++ = upper_32_bits(pe);
       *ptr++ = ndw - 1;
       for (; ndw > 0; ndw -= 2) {
               *ptr++ = lower_32_bits(value);
               *ptr++ = upper_32_bits(value);
                value += incr;
        }

       ib->length_dw = ptr - ib->ptr;

Latter avoids register reloads and length updates on every dword written, and on the overall makes the IB emission much more compact:

add/remove: 0/1 grow/shrink: 10/58 up/down: 260/-6598 (-6338)

Function                                     old     new   delta
sdma_v7_0_ring_pad_ib                         99     127     +28
sdma_v6_0_ring_pad_ib                         99     127     +28
sdma_v5_2_ring_pad_ib                         99     127     +28
sdma_v5_0_ring_pad_ib                         99     127     +28
sdma_v4_4_2_ring_pad_ib                       99     127     +28
sdma_v4_0_ring_pad_ib                         99     127     +28
sdma_v3_0_ring_pad_ib                         99     127     +28
sdma_v2_4_ring_pad_ib                         99     127     +28
cik_sdma_ring_pad_ib                          99     127     +28
si_dma_ring_pad_ib                            36      44      +8
amdgpu_ring_generic_pad_ib                    56      52      -4
si_dma_emit_fill_buffer                      108      71     -37
si_dma_vm_write_pte                          158     115     -43
amdgpu_vcn_dec_sw_send_msg                   810     767     -43
si_dma_vm_copy_pte                           137      87     -50
si_dma_emit_copy_buffer                      134      84     -50
sdma_v3_0_vm_write_pte                       163     102     -61
sdma_v2_4_vm_write_pte                       163     102     -61
cik_sdma_vm_write_pte                        163     102     -61
sdma_v7_0_vm_write_pte                       168     105     -63
sdma_v7_0_emit_fill_buffer                   119      56     -63
sdma_v6_0_vm_write_pte                       168     105     -63
sdma_v6_0_emit_fill_buffer                   119      56     -63
sdma_v5_2_vm_write_pte                       168     105     -63
sdma_v5_2_emit_fill_buffer                   119      56     -63
sdma_v5_0_vm_write_pte                       168     105     -63
sdma_v5_0_emit_fill_buffer                   119      56     -63
sdma_v4_4_2_vm_write_pte                     168     105     -63
sdma_v4_4_2_emit_fill_buffer                 119      56     -63
sdma_v4_0_vm_write_pte                       168     105     -63
sdma_v4_0_emit_fill_buffer                   119      56     -63
sdma_v3_0_emit_fill_buffer                   116      53     -63
sdma_v2_4_emit_fill_buffer                   116      53     -63
cik_sdma_emit_fill_buffer                    116      53     -63
sdma_v6_0_emit_copy_buffer                   169      76     -93
sdma_v5_2_emit_copy_buffer                   169      76     -93
sdma_v5_0_emit_copy_buffer                   169      76     -93
sdma_v4_4_2_emit_copy_buffer                 169      76     -93
sdma_v4_0_emit_copy_buffer                   169      76     -93
sdma_v3_0_vm_copy_pte                        158      64     -94
sdma_v3_0_emit_copy_buffer                   155      61     -94
sdma_v2_4_vm_copy_pte                        158      64     -94
sdma_v2_4_emit_copy_buffer                   155      61     -94
cik_sdma_vm_copy_pte                         158      64     -94
cik_sdma_emit_copy_buffer                    155      61     -94
sdma_v6_0_vm_copy_pte                        163      68     -95
sdma_v5_2_vm_copy_pte                        163      68     -95
sdma_v5_0_vm_copy_pte                        163      68     -95
sdma_v4_4_2_vm_copy_pte                      163      68     -95
sdma_v4_0_vm_copy_pte                        163      68     -95
sdma_v7_0_vm_copy_pte                        183      75    -108
sdma_v7_0_emit_copy_buffer                   317     202    -115
si_dma_vm_set_pte_pde                        338     214    -124
amdgpu_vce_get_destroy_msg                   784     652    -132
sdma_v7_0_vm_set_pte_pde                     218      72    -146
sdma_v6_0_vm_set_pte_pde                     218      72    -146
sdma_v5_2_vm_set_pte_pde                     218      72    -146
sdma_v5_0_vm_set_pte_pde                     218      72    -146
sdma_v4_4_2_vm_set_pte_pde                   218      72    -146
sdma_v4_0_vm_set_pte_pde                     218      72    -146
sdma_v3_0_vm_set_pte_pde                     215      69    -146
sdma_v2_4_vm_set_pte_pde                     215      69    -146
cik_sdma_vm_set_pte_pde                      215      69    -146
amdgpu_vcn_unified_ring_ib_header            172       -    -172
gfx_v9_4_2_run_shader.constprop              739     532    -207
uvd_v6_0_enc_ring_test_ib                   1464    1162    -302
uvd_v7_0_enc_ring_test_ib                   1464    1138    -326
amdgpu_vce_ring_test_ib                     1357     936    -421
amdgpu_vcn_enc_ring_test_ib                 2042    1524    -518

Total: Before=9262623, After=9256285, chg -0.07%

* Notice how _pad_ib functions have grown. I think the compiler used the opportunity to unroll the loops.

** Series was only smoke tested on the Steam Deck.

Tvrtko Ursulin (16):
drm/amdgpu: Use memset32 for IB padding
drm/amdgpu: More compact VCE IB emission
drm/amdgpu: More compact VCN IB emission
drm/amdgpu: More compact UVD 6 IB emission
drm/amdgpu: More compact UVD 7 IB emission
drm/amdgpu: More compact SI SDMA emission
drm/amdgpu: More compact CIK SDMA IB emission
drm/amdgpu: More compact GFX 9.4.2 IB emission
drm/amdgpu: More compact SDMA 2.4 IB emission
drm/amdgpu: More compact SDMA 3.0 IB emission
drm/amdgpu: More compact SDMA 4.0 IB emission
drm/amdgpu: More compact SDMA 4.4.2 IB emission
drm/amdgpu: More compact SDMA 5.0 IB emission
drm/amdgpu: More compact SDMA 5.2 IB emission
drm/amdgpu: More compact SDMA 6.0 IB emission
drm/amdgpu: More compact SDMA 7.0 IB emission

 drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c |  12 ++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c  |  90 +++++++++--------
 drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c  | 101 ++++++++++---------
 drivers/gpu/drm/amd/amdgpu/cik_sdma.c    | 105 ++++++++++++--------
 drivers/gpu/drm/amd/amdgpu/gfx_v9_4_2.c  |  46 ++++-----
 drivers/gpu/drm/amd/amdgpu/sdma_v2_4.c   | 108 ++++++++++++--------
 drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c   | 108 ++++++++++++--------
 drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c   | 109 ++++++++++++---------
 drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c | 108 ++++++++++++--------
 drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c   | 106 ++++++++++++--------
 drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c   | 110 ++++++++++++---------
 drivers/gpu/drm/amd/amdgpu/sdma_v6_0.c   | 110 ++++++++++++---------
 drivers/gpu/drm/amd/amdgpu/sdma_v7_0.c   | 119 +++++++++++++----------
 drivers/gpu/drm/amd/amdgpu/si_dma.c      |  84 +++++++++-------
 drivers/gpu/drm/amd/amdgpu/uvd_v6_0.c    |  66 +++++++------
 drivers/gpu/drm/amd/amdgpu/uvd_v7_0.c    |  66 +++++++------
 16 files changed, 849 insertions(+), 599 deletions(-)
Signature · 1 line
2.48.0
#1 lore raw

PATCH 1/16 drm/amdgpu: Use memset32 for IB padding

Use memset32 instead of open coding it, just because it is that bit nicer.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +10 -2
index 6379bb25bf5c..0918d832da94 100644
@@ -159,8 +159,16 @@ void amdgpu_ring_insert_nop(struct amdgpu_ring *ring, uint32_t count)
  */
 void amdgpu_ring_generic_pad_ib(struct amdgpu_ring *ring, struct amdgpu_ib *ib)
 {
-	while (ib->length_dw & ring->funcs->align_mask)
-		ib->ptr[ib->length_dw++] = ring->funcs->nop;
+	u32 align_mask = ring->funcs->align_mask;
+	u32 count = ib->length_dw & align_mask;
+
+	if (count) {
+		count = align_mask + 1 - count;
+
+		memset32(&ib->ptr[ib->length_dw], ring->funcs->nop, count);
+
+		ib->length_dw += count;
+	}
 }
 
 /**
Signature · 1 line
2.48.0
#2 lore raw

PATCH 2/16 drm/amdgpu: More compact VCE IB emission

In reply to Tvrtko Ursulin

Avoid constant register reloads while emitting IBs by using a local write pointer and only updating the size at the end of each helper.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c | 90 +++++++++++++------------
 1 file changed, 48 insertions(+), 42 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c +48 -42
index ce318f5de047..4bde057e56d6 100644
@@ -444,6 +444,7 @@ static int amdgpu_vce_get_create_msg(struct amdgpu_ring *ring, uint32_t handle,
 	struct amdgpu_ib ib_msg;
 	struct dma_fence *f = NULL;
 	uint64_t addr;
+	u32 *ptr;
 	int i, r;
 
 	r = amdgpu_job_alloc_with_ib(ring->adev, &ring->adev->vce.entity,
@@ -462,45 +463,47 @@ static int amdgpu_vce_get_create_msg(struct amdgpu_ring *ring, uint32_t handle,
 		goto err;
 
 	ib = &job->ibs[0];
+	ptr = ib->ptr;
 	/* let addr point to page boundary */
 	addr = AMDGPU_GPU_PAGE_ALIGN(ib_msg.gpu_addr);
 
 	/* stitch together an VCE create msg */
-	ib->length_dw = 0;
-	ib->ptr[ib->length_dw++] = 0x0000000c; /* len */
-	ib->ptr[ib->length_dw++] = 0x00000001; /* session cmd */
-	ib->ptr[ib->length_dw++] = handle;
+	*ptr++ = 0x0000000c; /* len */
+	*ptr++ = 0x00000001; /* session cmd */
+	*ptr++ = handle;
 
 	if ((ring->adev->vce.fw_version >> 24) >= 52)
-		ib->ptr[ib->length_dw++] = 0x00000040; /* len */
+		*ptr++ = 0x00000040; /* len */
 	else
-		ib->ptr[ib->length_dw++] = 0x00000030; /* len */
-	ib->ptr[ib->length_dw++] = 0x01000001; /* create cmd */
-	ib->ptr[ib->length_dw++] = 0x00000000;
-	ib->ptr[ib->length_dw++] = 0x00000042;
-	ib->ptr[ib->length_dw++] = 0x0000000a;
-	ib->ptr[ib->length_dw++] = 0x00000001;
-	ib->ptr[ib->length_dw++] = 0x00000080;
-	ib->ptr[ib->length_dw++] = 0x00000060;
-	ib->ptr[ib->length_dw++] = 0x00000100;
-	ib->ptr[ib->length_dw++] = 0x00000100;
-	ib->ptr[ib->length_dw++] = 0x0000000c;
-	ib->ptr[ib->length_dw++] = 0x00000000;
+		*ptr++ = 0x00000030; /* len */
+	*ptr++ = 0x01000001; /* create cmd */
+	*ptr++ = 0x00000000;
+	*ptr++ = 0x00000042;
+	*ptr++ = 0x0000000a;
+	*ptr++ = 0x00000001;
+	*ptr++ = 0x00000080;
+	*ptr++ = 0x00000060;
+	*ptr++ = 0x00000100;
+	*ptr++ = 0x00000100;
+	*ptr++ = 0x0000000c;
+	*ptr++ = 0x00000000;
 	if ((ring->adev->vce.fw_version >> 24) >= 52) {
-		ib->ptr[ib->length_dw++] = 0x00000000;
-		ib->ptr[ib->length_dw++] = 0x00000000;
-		ib->ptr[ib->length_dw++] = 0x00000000;
-		ib->ptr[ib->length_dw++] = 0x00000000;
+		*ptr++ = 0x00000000;
+		*ptr++ = 0x00000000;
+		*ptr++ = 0x00000000;
+		*ptr++ = 0x00000000;
 	}
 
-	ib->ptr[ib->length_dw++] = 0x00000014; /* len */
-	ib->ptr[ib->length_dw++] = 0x05000005; /* feedback buffer */
-	ib->ptr[ib->length_dw++] = upper_32_bits(addr);
-	ib->ptr[ib->length_dw++] = addr;
-	ib->ptr[ib->length_dw++] = 0x00000001;
+	*ptr++ = 0x00000014; /* len */
+	*ptr++ = 0x05000005; /* feedback buffer */
+	*ptr++ = upper_32_bits(addr);
+	*ptr++ = addr;
+	*ptr++ = 0x00000001;
+
+	ib->length_dw = ptr - ib->ptr;
 
 	for (i = ib->length_dw; i < ib_size_dw; ++i)
-		ib->ptr[i] = 0x0;
+		*ptr++ = 0x0;
 
 	r = amdgpu_job_submit_direct(job, ring, &f);
 	amdgpu_ib_free(&ib_msg, f);
@@ -534,6 +537,7 @@ static int amdgpu_vce_get_destroy_msg(struct amdgpu_ring *ring, uint32_t handle,
 	struct amdgpu_job *job;
 	struct amdgpu_ib *ib;
 	struct dma_fence *f = NULL;
+	u32 *ptr;
 	int i, r;
 
 	r = amdgpu_job_alloc_with_ib(ring->adev, &ring->adev->vce.entity,
@@ -546,27 +550,29 @@ static int amdgpu_vce_get_destroy_msg(struct amdgpu_ring *ring, uint32_t handle,
 		return r;
 
 	ib = &job->ibs[0];
+	ptr = ib->ptr;
 
 	/* stitch together an VCE destroy msg */
-	ib->length_dw = 0;
-	ib->ptr[ib->length_dw++] = 0x0000000c; /* len */
-	ib->ptr[ib->length_dw++] = 0x00000001; /* session cmd */
-	ib->ptr[ib->length_dw++] = handle;
+	*ptr++ = 0x0000000c; /* len */
+	*ptr++ = 0x00000001; /* session cmd */
+	*ptr++ = handle;
 
-	ib->ptr[ib->length_dw++] = 0x00000020; /* len */
-	ib->ptr[ib->length_dw++] = 0x00000002; /* task info */
-	ib->ptr[ib->length_dw++] = 0xffffffff; /* next task info, set to 0xffffffff if no */
-	ib->ptr[ib->length_dw++] = 0x00000001; /* destroy session */
-	ib->ptr[ib->length_dw++] = 0x00000000;
-	ib->ptr[ib->length_dw++] = 0x00000000;
-	ib->ptr[ib->length_dw++] = 0xffffffff; /* feedback is not needed, set to 0xffffffff and firmware will not output feedback */
-	ib->ptr[ib->length_dw++] = 0x00000000;
+	*ptr++ = 0x00000020; /* len */
+	*ptr++ = 0x00000002; /* task info */
+	*ptr++ = 0xffffffff; /* next task info, set to 0xffffffff if no */
+	*ptr++ = 0x00000001; /* destroy session */
+	*ptr++ = 0x00000000;
+	*ptr++ = 0x00000000;
+	*ptr++ = 0xffffffff; /* feedback is not needed, set to 0xffffffff and firmware will not output feedback */
+	*ptr++ = 0x00000000;
 
-	ib->ptr[ib->length_dw++] = 0x00000008; /* len */
-	ib->ptr[ib->length_dw++] = 0x02000001; /* destroy cmd */
+	*ptr++ = 0x00000008; /* len */
+	*ptr++ = 0x02000001; /* destroy cmd */
+
+	ib->length_dw = ptr - ib->ptr;
 
 	for (i = ib->length_dw; i < ib_size_dw; ++i)
-		ib->ptr[i] = 0x0;
+		*ptr++ = 0x0;
 
 	if (direct)
 		r = amdgpu_job_submit_direct(job, ring, &f);
Signature · 1 line
2.48.0
#3 lore raw

PATCH 3/16 drm/amdgpu: More compact VCN IB emission

In reply to Tvrtko Ursulin

Avoid constant register reloads while emitting IBs by using a local write pointer and only updating the size at the end of each helper.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c | 101 +++++++++++++-----------
 1 file changed, 55 insertions(+), 46 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +55 -46
index 595f0df17bcc..3b30bdff76d5 100644
@@ -762,16 +762,19 @@ static uint32_t *amdgpu_vcn_unified_ring_ib_header(struct amdgpu_ib *ib,
 						uint32_t ib_pack_in_dw, bool enc)
 {
 	uint32_t *ib_checksum;
+	u32 *ptr = &ib->ptr[ib->length_dw];
 
-	ib->ptr[ib->length_dw++] = 0x00000010; /* single queue checksum */
-	ib->ptr[ib->length_dw++] = 0x30000002;
-	ib_checksum = &ib->ptr[ib->length_dw++];
-	ib->ptr[ib->length_dw++] = ib_pack_in_dw;
+	*ptr++ = 0x00000010; /* single queue checksum */
+	*ptr++ = 0x30000002;
+	ib_checksum = ptr++;
+	*ptr++ = ib_pack_in_dw;
 
-	ib->ptr[ib->length_dw++] = 0x00000010; /* engine info */
-	ib->ptr[ib->length_dw++] = 0x30000001;
-	ib->ptr[ib->length_dw++] = enc ? 0x2 : 0x3;
-	ib->ptr[ib->length_dw++] = ib_pack_in_dw * sizeof(uint32_t);
+	*ptr++ = 0x00000010; /* engine info */
+	*ptr++ = 0x30000001;
+	*ptr++ = enc ? 0x2 : 0x3;
+	*ptr++ = ib_pack_in_dw * sizeof(uint32_t);
+
+	ib->length_dw = ptr - ib->ptr;
 
 	return ib_checksum;
 }
@@ -801,6 +804,7 @@ static int amdgpu_vcn_dec_sw_send_msg(struct amdgpu_ring *ring,
 	uint64_t addr = AMDGPU_GPU_PAGE_ALIGN(ib_msg->gpu_addr);
 	uint32_t *ib_checksum;
 	uint32_t ib_pack_in_dw;
+	u32 *ptr;
 	int i, r;
 
 	if (adev->vcn.inst[ring->me].using_unified_queue)
@@ -813,7 +817,7 @@ static int amdgpu_vcn_dec_sw_send_msg(struct amdgpu_ring *ring,
 		goto err;
 
 	ib = &job->ibs[0];
-	ib->length_dw = 0;
+	ptr = ib->ptr;
 
 	/* single queue headers */
 	if (adev->vcn.inst[ring->me].using_unified_queue) {
@@ -822,10 +826,11 @@ static int amdgpu_vcn_dec_sw_send_msg(struct amdgpu_ring *ring,
 		ib_checksum = amdgpu_vcn_unified_ring_ib_header(ib, ib_pack_in_dw, false);
 	}
 
-	ib->ptr[ib->length_dw++] = sizeof(struct amdgpu_vcn_decode_buffer) + 8;
-	ib->ptr[ib->length_dw++] = cpu_to_le32(AMDGPU_VCN_IB_FLAG_DECODE_BUFFER);
-	decode_buffer = (struct amdgpu_vcn_decode_buffer *)&(ib->ptr[ib->length_dw]);
-	ib->length_dw += sizeof(struct amdgpu_vcn_decode_buffer) / 4;
+	*ptr++ = sizeof(struct amdgpu_vcn_decode_buffer) + 8;
+	*ptr++ = cpu_to_le32(AMDGPU_VCN_IB_FLAG_DECODE_BUFFER);
+	decode_buffer = (struct amdgpu_vcn_decode_buffer *)ptr;
+	ib->length_dw = ptr - ib->ptr +
+			sizeof(struct amdgpu_vcn_decode_buffer) / 4;
 	memset(decode_buffer, 0, sizeof(struct amdgpu_vcn_decode_buffer));
 
 	decode_buffer->valid_buf_flag |= cpu_to_le32(AMDGPU_VCN_CMD_FLAG_MSG_BUFFER);
@@ -833,7 +838,7 @@ static int amdgpu_vcn_dec_sw_send_msg(struct amdgpu_ring *ring,
 	decode_buffer->msg_buffer_address_lo = cpu_to_le32(addr);
 
 	for (i = ib->length_dw; i < ib_size_dw; ++i)
-		ib->ptr[i] = 0x0;
+		*ptr++ = 0x0;
 
 	if (adev->vcn.inst[ring->me].using_unified_queue)
 		amdgpu_vcn_unified_ring_ib_checksum(&ib_checksum, ib_pack_in_dw);
@@ -931,6 +936,7 @@ static int amdgpu_vcn_enc_get_create_msg(struct amdgpu_ring *ring, uint32_t hand
 	struct dma_fence *f = NULL;
 	uint32_t *ib_checksum = NULL;
 	uint64_t addr;
+	u32 *ptr;
 	int i, r;
 
 	if (adev->vcn.inst[ring->me].using_unified_queue)
@@ -943,31 +949,32 @@ static int amdgpu_vcn_enc_get_create_msg(struct amdgpu_ring *ring, uint32_t hand
 		return r;
 
 	ib = &job->ibs[0];
+	ptr = ib->ptr;
 	addr = AMDGPU_GPU_PAGE_ALIGN(ib_msg->gpu_addr);
 
-	ib->length_dw = 0;
-
 	if (adev->vcn.inst[ring->me].using_unified_queue)
 		ib_checksum = amdgpu_vcn_unified_ring_ib_header(ib, 0x11, true);
 
-	ib->ptr[ib->length_dw++] = 0x00000018;
-	ib->ptr[ib->length_dw++] = 0x00000001; /* session info */
-	ib->ptr[ib->length_dw++] = handle;
-	ib->ptr[ib->length_dw++] = upper_32_bits(addr);
-	ib->ptr[ib->length_dw++] = addr;
-	ib->ptr[ib->length_dw++] = 0x00000000;
+	*ptr++ = 0x00000018;
+	*ptr++ = 0x00000001; /* session info */
+	*ptr++ = handle;
+	*ptr++ = upper_32_bits(addr);
+	*ptr++ = addr;
+	*ptr++ = 0x00000000;
 
-	ib->ptr[ib->length_dw++] = 0x00000014;
-	ib->ptr[ib->length_dw++] = 0x00000002; /* task info */
-	ib->ptr[ib->length_dw++] = 0x0000001c;
-	ib->ptr[ib->length_dw++] = 0x00000000;
-	ib->ptr[ib->length_dw++] = 0x00000000;
+	*ptr++ = 0x00000014;
+	*ptr++ = 0x00000002; /* task info */
+	*ptr++ = 0x0000001c;
+	*ptr++ = 0x00000000;
+	*ptr++ = 0x00000000;
 
-	ib->ptr[ib->length_dw++] = 0x00000008;
-	ib->ptr[ib->length_dw++] = 0x08000001; /* op initialize */
+	*ptr++ = 0x00000008;
+	*ptr++ = 0x08000001; /* op initialize */
+
+	ib->length_dw = ptr - ib->ptr;
 
 	for (i = ib->length_dw; i < ib_size_dw; ++i)
-		ib->ptr[i] = 0x0;
+		*ptr++ = 0x0;
 
 	if (adev->vcn.inst[ring->me].using_unified_queue)
 		amdgpu_vcn_unified_ring_ib_checksum(&ib_checksum, 0x11);
@@ -998,6 +1005,7 @@ static int amdgpu_vcn_enc_get_destroy_msg(struct amdgpu_ring *ring, uint32_t han
 	struct dma_fence *f = NULL;
 	uint32_t *ib_checksum = NULL;
 	uint64_t addr;
+	u32 *ptr;
 	int i, r;
 
 	if (adev->vcn.inst[ring->me].using_unified_queue)
@@ -1010,31 +1018,32 @@ static int amdgpu_vcn_enc_get_destroy_msg(struct amdgpu_ring *ring, uint32_t han
 		return r;
 
 	ib = &job->ibs[0];
+	ptr = ib->ptr;
 	addr = AMDGPU_GPU_PAGE_ALIGN(ib_msg->gpu_addr);
 
-	ib->length_dw = 0;
-
 	if (adev->vcn.inst[ring->me].using_unified_queue)
 		ib_checksum = amdgpu_vcn_unified_ring_ib_header(ib, 0x11, true);
 
-	ib->ptr[ib->length_dw++] = 0x00000018;
-	ib->ptr[ib->length_dw++] = 0x00000001;
-	ib->ptr[ib->length_dw++] = handle;
-	ib->ptr[ib->length_dw++] = upper_32_bits(addr);
-	ib->ptr[ib->length_dw++] = addr;
-	ib->ptr[ib->length_dw++] = 0x00000000;
+	*ptr++ = 0x00000018;
+	*ptr++ = 0x00000001;
+	*ptr++ = handle;
+	*ptr++ = upper_32_bits(addr);
+	*ptr++ = addr;
+	*ptr++ = 0x00000000;
 
-	ib->ptr[ib->length_dw++] = 0x00000014;
-	ib->ptr[ib->length_dw++] = 0x00000002;
-	ib->ptr[ib->length_dw++] = 0x0000001c;
-	ib->ptr[ib->length_dw++] = 0x00000000;
-	ib->ptr[ib->length_dw++] = 0x00000000;
+	*ptr++ = 0x00000014;
+	*ptr++ = 0x00000002;
+	*ptr++ = 0x0000001c;
+	*ptr++ = 0x00000000;
+	*ptr++ = 0x00000000;
 
-	ib->ptr[ib->length_dw++] = 0x00000008;
-	ib->ptr[ib->length_dw++] = 0x08000002; /* op close session */
+	*ptr++ = 0x00000008;
+	*ptr++ = 0x08000002; /* op close session */
+
+	ib->length_dw = ptr - ib->ptr;
 
 	for (i = ib->length_dw; i < ib_size_dw; ++i)
-		ib->ptr[i] = 0x0;
+		*ptr++ = 0x0;
 
 	if (adev->vcn.inst[ring->me].using_unified_queue)
 		amdgpu_vcn_unified_ring_ib_checksum(&ib_checksum, 0x11);
Signature · 1 line
2.48.0
#4 lore raw

PATCH 4/16 drm/amdgpu: More compact UVD 6 IB emission

In reply to Tvrtko Ursulin

Avoid constant register reloads while emitting IBs by using a local write pointer and only updating the size at the end of each helper.uvd 6

---
 drivers/gpu/drm/amd/amdgpu/uvd_v6_0.c | 66 +++++++++++++++------------
 1 file changed, 36 insertions(+), 30 deletions(-)
drivers/gpu/drm/amd/amdgpu/uvd_v6_0.c +36 -30
index ceb94bbb03a4..815952ccccf0 100644
@@ -214,6 +214,7 @@ static int uvd_v6_0_enc_get_create_msg(struct amdgpu_ring *ring, uint32_t handle
 	struct amdgpu_ib *ib;
 	struct dma_fence *f = NULL;
 	uint64_t addr;
+	u32 *ptr;
 	int i, r;
 
 	r = amdgpu_job_alloc_with_ib(ring->adev, NULL, NULL, ib_size_dw * 4,
@@ -223,27 +224,29 @@ static int uvd_v6_0_enc_get_create_msg(struct amdgpu_ring *ring, uint32_t handle
 		return r;
 
 	ib = &job->ibs[0];
+	ptr = ib->ptr;
 	addr = amdgpu_bo_gpu_offset(bo);
 
-	ib->length_dw = 0;
-	ib->ptr[ib->length_dw++] = 0x00000018;
-	ib->ptr[ib->length_dw++] = 0x00000001; /* session info */
-	ib->ptr[ib->length_dw++] = handle;
-	ib->ptr[ib->length_dw++] = 0x00010000;
-	ib->ptr[ib->length_dw++] = upper_32_bits(addr);
-	ib->ptr[ib->length_dw++] = addr;
+	*ptr++ = 0x00000018;
+	*ptr++ = 0x00000001; /* session info */
+	*ptr++ = handle;
+	*ptr++ = 0x00010000;
+	*ptr++ = upper_32_bits(addr);
+	*ptr++ = addr;
 
-	ib->ptr[ib->length_dw++] = 0x00000014;
-	ib->ptr[ib->length_dw++] = 0x00000002; /* task info */
-	ib->ptr[ib->length_dw++] = 0x0000001c;
-	ib->ptr[ib->length_dw++] = 0x00000001;
-	ib->ptr[ib->length_dw++] = 0x00000000;
+	*ptr++ = 0x00000014;
+	*ptr++ = 0x00000002; /* task info */
+	*ptr++ = 0x0000001c;
+	*ptr++ = 0x00000001;
+	*ptr++ = 0x00000000;
 
-	ib->ptr[ib->length_dw++] = 0x00000008;
-	ib->ptr[ib->length_dw++] = 0x08000001; /* op initialize */
+	*ptr++ = 0x00000008;
+	*ptr++ = 0x08000001; /* op initialize */
+
+	ib->length_dw = ptr - ib->ptr;
 
 	for (i = ib->length_dw; i < ib_size_dw; ++i)
-		ib->ptr[i] = 0x0;
+		*ptr++ = 0x0;
 
 	r = amdgpu_job_submit_direct(job, ring, &f);
 	if (r)
@@ -279,6 +282,7 @@ static int uvd_v6_0_enc_get_destroy_msg(struct amdgpu_ring *ring,
 	struct amdgpu_ib *ib;
 	struct dma_fence *f = NULL;
 	uint64_t addr;
+	u32 *ptr;
 	int i, r;
 
 	r = amdgpu_job_alloc_with_ib(ring->adev, NULL, NULL, ib_size_dw * 4,
@@ -288,27 +292,29 @@ static int uvd_v6_0_enc_get_destroy_msg(struct amdgpu_ring *ring,
 		return r;
 
 	ib = &job->ibs[0];
+	ptr = ib->ptr;
 	addr = amdgpu_bo_gpu_offset(bo);
 
-	ib->length_dw = 0;
-	ib->ptr[ib->length_dw++] = 0x00000018;
-	ib->ptr[ib->length_dw++] = 0x00000001; /* session info */
-	ib->ptr[ib->length_dw++] = handle;
-	ib->ptr[ib->length_dw++] = 0x00010000;
-	ib->ptr[ib->length_dw++] = upper_32_bits(addr);
-	ib->ptr[ib->length_dw++] = addr;
+	*ptr++ = 0x00000018;
+	*ptr++ = 0x00000001; /* session info */
+	*ptr++ = handle;
+	*ptr++ = 0x00010000;
+	*ptr++ = upper_32_bits(addr);
+	*ptr++ = addr;
 
-	ib->ptr[ib->length_dw++] = 0x00000014;
-	ib->ptr[ib->length_dw++] = 0x00000002; /* task info */
-	ib->ptr[ib->length_dw++] = 0x0000001c;
-	ib->ptr[ib->length_dw++] = 0x00000001;
-	ib->ptr[ib->length_dw++] = 0x00000000;
+	*ptr++ = 0x00000014;
+	*ptr++ = 0x00000002; /* task info */
+	*ptr++ = 0x0000001c;
+	*ptr++ = 0x00000001;
+	*ptr++ = 0x00000000;
 
-	ib->ptr[ib->length_dw++] = 0x00000008;
-	ib->ptr[ib->length_dw++] = 0x08000002; /* op close session */
+	*ptr++ = 0x00000008;
+	*ptr++ = 0x08000002; /* op close session */
+
+	ib->length_dw = ptr - ib->ptr;
 
 	for (i = ib->length_dw; i < ib_size_dw; ++i)
-		ib->ptr[i] = 0x0;
+		*ptr++ = 0x0;
 
 	r = amdgpu_job_submit_direct(job, ring, &f);
 	if (r)
Signature · 1 line
2.48.0
#5 lore raw

PATCH 5/16 drm/amdgpu: More compact UVD 7 IB emission

In reply to Tvrtko Ursulin

Avoid constant register reloads while emitting IBs by using a local write pointer and only updating the size at the end of each helper.

---
 drivers/gpu/drm/amd/amdgpu/uvd_v7_0.c | 66 +++++++++++++++------------
 1 file changed, 36 insertions(+), 30 deletions(-)
drivers/gpu/drm/amd/amdgpu/uvd_v7_0.c +36 -30
index 1f8866f3f63c..cd3a20671963 100644
@@ -222,6 +222,7 @@ static int uvd_v7_0_enc_get_create_msg(struct amdgpu_ring *ring, u32 handle,
 	struct amdgpu_ib *ib;
 	struct dma_fence *f = NULL;
 	uint64_t addr;
+	u32 *ptr;
 	int i, r;
 
 	r = amdgpu_job_alloc_with_ib(ring->adev, NULL, NULL, ib_size_dw * 4,
@@ -231,27 +232,29 @@ static int uvd_v7_0_enc_get_create_msg(struct amdgpu_ring *ring, u32 handle,
 		return r;
 
 	ib = &job->ibs[0];
+	ptr = ib->ptr;
 	addr = amdgpu_bo_gpu_offset(bo);
 
-	ib->length_dw = 0;
-	ib->ptr[ib->length_dw++] = 0x00000018;
-	ib->ptr[ib->length_dw++] = 0x00000001; /* session info */
-	ib->ptr[ib->length_dw++] = handle;
-	ib->ptr[ib->length_dw++] = 0x00000000;
-	ib->ptr[ib->length_dw++] = upper_32_bits(addr);
-	ib->ptr[ib->length_dw++] = addr;
+	*ptr++ = 0x00000018;
+	*ptr++ = 0x00000001; /* session info */
+	*ptr++ = handle;
+	*ptr++ = 0x00000000;
+	*ptr++ = upper_32_bits(addr);
+	*ptr++ = addr;
 
-	ib->ptr[ib->length_dw++] = 0x00000014;
-	ib->ptr[ib->length_dw++] = 0x00000002; /* task info */
-	ib->ptr[ib->length_dw++] = 0x0000001c;
-	ib->ptr[ib->length_dw++] = 0x00000000;
-	ib->ptr[ib->length_dw++] = 0x00000000;
+	*ptr++ = 0x00000014;
+	*ptr++ = 0x00000002; /* task info */
+	*ptr++ = 0x0000001c;
+	*ptr++ = 0x00000000;
+	*ptr++ = 0x00000000;
 
-	ib->ptr[ib->length_dw++] = 0x00000008;
-	ib->ptr[ib->length_dw++] = 0x08000001; /* op initialize */
+	*ptr++ = 0x00000008;
+	*ptr++ = 0x08000001; /* op initialize */
+
+	ib->length_dw = ptr - ib->ptr;
 
 	for (i = ib->length_dw; i < ib_size_dw; ++i)
-		ib->ptr[i] = 0x0;
+		*ptr++ = 0x0;
 
 	r = amdgpu_job_submit_direct(job, ring, &f);
 	if (r)
@@ -286,6 +289,7 @@ static int uvd_v7_0_enc_get_destroy_msg(struct amdgpu_ring *ring, u32 handle,
 	struct amdgpu_ib *ib;
 	struct dma_fence *f = NULL;
 	uint64_t addr;
+	u32 *ptr;
 	int i, r;
 
 	r = amdgpu_job_alloc_with_ib(ring->adev, NULL, NULL, ib_size_dw * 4,
@@ -295,27 +299,29 @@ static int uvd_v7_0_enc_get_destroy_msg(struct amdgpu_ring *ring, u32 handle,
 		return r;
 
 	ib = &job->ibs[0];
+	ptr = ib->ptr;
 	addr = amdgpu_bo_gpu_offset(bo);
 
-	ib->length_dw = 0;
-	ib->ptr[ib->length_dw++] = 0x00000018;
-	ib->ptr[ib->length_dw++] = 0x00000001;
-	ib->ptr[ib->length_dw++] = handle;
-	ib->ptr[ib->length_dw++] = 0x00000000;
-	ib->ptr[ib->length_dw++] = upper_32_bits(addr);
-	ib->ptr[ib->length_dw++] = addr;
+	*ptr++ = 0x00000018;
+	*ptr++ = 0x00000001;
+	*ptr++ = handle;
+	*ptr++ = 0x00000000;
+	*ptr++ = upper_32_bits(addr);
+	*ptr++ = addr;
 
-	ib->ptr[ib->length_dw++] = 0x00000014;
-	ib->ptr[ib->length_dw++] = 0x00000002;
-	ib->ptr[ib->length_dw++] = 0x0000001c;
-	ib->ptr[ib->length_dw++] = 0x00000000;
-	ib->ptr[ib->length_dw++] = 0x00000000;
+	*ptr++ = 0x00000014;
+	*ptr++ = 0x00000002;
+	*ptr++ = 0x0000001c;
+	*ptr++ = 0x00000000;
+	*ptr++ = 0x00000000;
 
-	ib->ptr[ib->length_dw++] = 0x00000008;
-	ib->ptr[ib->length_dw++] = 0x08000002; /* op close session */
+	*ptr++ = 0x00000008;
+	*ptr++ = 0x08000002; /* op close session */
+
+	ib->length_dw = ptr - ib->ptr;
 
 	for (i = ib->length_dw; i < ib_size_dw; ++i)
-		ib->ptr[i] = 0x0;
+		*ptr++ = 0x0;
 
 	r = amdgpu_job_submit_direct(job, ring, &f);
 	if (r)
Signature · 1 line
2.48.0
#6 lore raw

PATCH 6/16 drm/amdgpu: More compact SI SDMA emission

In reply to Tvrtko Ursulin

Avoid constant register reloads while emitting IBs by using a local write pointer and only updating the size at the end of each helper.

---
 drivers/gpu/drm/amd/amdgpu/si_dma.c | 84 +++++++++++++++++------------
 1 file changed, 51 insertions(+), 33 deletions(-)
drivers/gpu/drm/amd/amdgpu/si_dma.c +51 -33
index 7f18e4875287..9e26c7598d74 100644
@@ -323,14 +323,16 @@ static void si_dma_vm_copy_pte(struct amdgpu_ib *ib,
 			       uint64_t pe, uint64_t src,
 			       unsigned count)
 {
+	u32 *ptr = &ib->ptr[ib->length_dw];
 	unsigned bytes = count * 8;
 
-	ib->ptr[ib->length_dw++] = DMA_PACKET(DMA_PACKET_COPY,
-					      1, 0, 0, bytes);
-	ib->ptr[ib->length_dw++] = lower_32_bits(pe);
-	ib->ptr[ib->length_dw++] = lower_32_bits(src);
-	ib->ptr[ib->length_dw++] = upper_32_bits(pe) & 0xff;
-	ib->ptr[ib->length_dw++] = upper_32_bits(src) & 0xff;
+	*ptr++ = DMA_PACKET(DMA_PACKET_COPY, 1, 0, 0, bytes);
+	*ptr++ = lower_32_bits(pe);
+	*ptr++ = lower_32_bits(src);
+	*ptr++ = upper_32_bits(pe) & 0xff;
+	*ptr++ = upper_32_bits(src) & 0xff;
+
+	ib->length_dw = ptr - ib->ptr;
 }
 
 /**
@@ -348,16 +350,19 @@ static void si_dma_vm_write_pte(struct amdgpu_ib *ib, uint64_t pe,
 				uint64_t value, unsigned count,
 				uint32_t incr)
 {
+	u32 *ptr = &ib->ptr[ib->length_dw];
 	unsigned ndw = count * 2;
 
-	ib->ptr[ib->length_dw++] = DMA_PACKET(DMA_PACKET_WRITE, 0, 0, 0, ndw);
-	ib->ptr[ib->length_dw++] = lower_32_bits(pe);
-	ib->ptr[ib->length_dw++] = upper_32_bits(pe);
+	*ptr++ = DMA_PACKET(DMA_PACKET_WRITE, 0, 0, 0, ndw);
+	*ptr++ = lower_32_bits(pe);
+	*ptr++ = upper_32_bits(pe);
 	for (; ndw > 0; ndw -= 2) {
-		ib->ptr[ib->length_dw++] = lower_32_bits(value);
-		ib->ptr[ib->length_dw++] = upper_32_bits(value);
+		*ptr++ = lower_32_bits(value);
+		*ptr++ = upper_32_bits(value);
 		value += incr;
 	}
+
+	ib->length_dw = ptr - ib->ptr;
 }
 
 /**
@@ -377,6 +382,7 @@ static void si_dma_vm_set_pte_pde(struct amdgpu_ib *ib,
 				     uint64_t addr, unsigned count,
 				     uint32_t incr, uint64_t flags)
 {
+	u32 *ptr = &ib->ptr[ib->length_dw];
 	uint64_t value;
 	unsigned ndw;
 
@@ -391,19 +397,21 @@ static void si_dma_vm_set_pte_pde(struct amdgpu_ib *ib,
 			value = 0;
 
 		/* for physically contiguous pages (vram) */
-		ib->ptr[ib->length_dw++] = DMA_PTE_PDE_PACKET(ndw);
-		ib->ptr[ib->length_dw++] = pe; /* dst addr */
-		ib->ptr[ib->length_dw++] = upper_32_bits(pe) & 0xff;
-		ib->ptr[ib->length_dw++] = lower_32_bits(flags); /* mask */
-		ib->ptr[ib->length_dw++] = upper_32_bits(flags);
-		ib->ptr[ib->length_dw++] = value; /* value */
-		ib->ptr[ib->length_dw++] = upper_32_bits(value);
-		ib->ptr[ib->length_dw++] = incr; /* increment size */
-		ib->ptr[ib->length_dw++] = 0;
+		*ptr++ = DMA_PTE_PDE_PACKET(ndw);
+		*ptr++ = pe; /* dst addr */
+		*ptr++ = upper_32_bits(pe) & 0xff;
+		*ptr++ = lower_32_bits(flags); /* mask */
+		*ptr++ = upper_32_bits(flags);
+		*ptr++ = value; /* value */
+		*ptr++ = upper_32_bits(value);
+		*ptr++ = incr; /* increment size */
+		*ptr++ = 0;
 		pe += ndw * 4;
 		addr += (ndw / 2) * incr;
 		count -= ndw / 2;
 	}
+
+	ib->length_dw = ptr - ib->ptr;
 }
 
 /**
@@ -415,8 +423,12 @@ static void si_dma_vm_set_pte_pde(struct amdgpu_ib *ib,
  */
 static void si_dma_ring_pad_ib(struct amdgpu_ring *ring, struct amdgpu_ib *ib)
 {
-	while (ib->length_dw & 0x7)
-		ib->ptr[ib->length_dw++] = DMA_PACKET(DMA_PACKET_NOP, 0, 0, 0, 0);
+	int pad = 8 - (ib->length_dw & 0x7);
+
+	if (pad && pad < 8) {
+		memset32(ib->ptr, DMA_PACKET(DMA_PACKET_NOP, 0, 0, 0, 0), pad);
+		ib->length_dw += pad;
+	}
 }
 
 /**
@@ -783,12 +795,15 @@ static void si_dma_emit_copy_buffer(struct amdgpu_ib *ib,
 				       uint32_t byte_count,
 				       uint32_t copy_flags)
 {
-	ib->ptr[ib->length_dw++] = DMA_PACKET(DMA_PACKET_COPY,
-					      1, 0, 0, byte_count);
-	ib->ptr[ib->length_dw++] = lower_32_bits(dst_offset);
-	ib->ptr[ib->length_dw++] = lower_32_bits(src_offset);
-	ib->ptr[ib->length_dw++] = upper_32_bits(dst_offset) & 0xff;
-	ib->ptr[ib->length_dw++] = upper_32_bits(src_offset) & 0xff;
+	u32 *ptr = &ib->ptr[ib->length_dw];
+
+	*ptr++ = DMA_PACKET(DMA_PACKET_COPY, 1, 0, 0, byte_count);
+	*ptr++ = lower_32_bits(dst_offset);
+	*ptr++ = lower_32_bits(src_offset);
+	*ptr++ = upper_32_bits(dst_offset) & 0xff;
+	*ptr++ = upper_32_bits(src_offset) & 0xff;
+
+	ib->length_dw = ptr - ib->ptr;
 }
 
 /**
@@ -806,11 +821,14 @@ static void si_dma_emit_fill_buffer(struct amdgpu_ib *ib,
 				       uint64_t dst_offset,
 				       uint32_t byte_count)
 {
-	ib->ptr[ib->length_dw++] = DMA_PACKET(DMA_PACKET_CONSTANT_FILL,
-					      0, 0, 0, byte_count / 4);
-	ib->ptr[ib->length_dw++] = lower_32_bits(dst_offset);
-	ib->ptr[ib->length_dw++] = src_data;
-	ib->ptr[ib->length_dw++] = upper_32_bits(dst_offset) << 16;
+	u32 *ptr = &ib->ptr[ib->length_dw];
+
+	*ptr++ = DMA_PACKET(DMA_PACKET_CONSTANT_FILL, 0, 0, 0, byte_count / 4);
+	*ptr++ = lower_32_bits(dst_offset);
+	*ptr++ = src_data;
+	*ptr++ = upper_32_bits(dst_offset) << 16;
+
+	ib->length_dw = ptr - ib->ptr;
 }
 
 
Signature · 1 line
2.48.0
#7 lore raw

PATCH 7/16 drm/amdgpu: More compact CIK SDMA IB emission

In reply to Tvrtko Ursulin

Avoid constant register reloads while emitting IBs by using a local write pointer and only updating the size at the end of each helper.

---
 drivers/gpu/drm/amd/amdgpu/cik_sdma.c | 105 +++++++++++++++-----------
 1 file changed, 63 insertions(+), 42 deletions(-)
drivers/gpu/drm/amd/amdgpu/cik_sdma.c +63 -42
index 9e8715b4739d..bf3049200fcd 100644
@@ -718,16 +718,18 @@ static void cik_sdma_vm_copy_pte(struct amdgpu_ib *ib,
 				 uint64_t pe, uint64_t src,
 				 unsigned count)
 {
+	u32 *ptr = &ib->ptr[ib->length_dw];
 	unsigned bytes = count * 8;
 
-	ib->ptr[ib->length_dw++] = SDMA_PACKET(SDMA_OPCODE_COPY,
-		SDMA_WRITE_SUB_OPCODE_LINEAR, 0);
-	ib->ptr[ib->length_dw++] = bytes;
-	ib->ptr[ib->length_dw++] = 0; /* src/dst endian swap */
-	ib->ptr[ib->length_dw++] = lower_32_bits(src);
-	ib->ptr[ib->length_dw++] = upper_32_bits(src);
-	ib->ptr[ib->length_dw++] = lower_32_bits(pe);
-	ib->ptr[ib->length_dw++] = upper_32_bits(pe);
+	*ptr++ = SDMA_PACKET(SDMA_OPCODE_COPY, SDMA_WRITE_SUB_OPCODE_LINEAR, 0);
+	*ptr++ = bytes;
+	*ptr++ = 0; /* src/dst endian swap */
+	*ptr++ = lower_32_bits(src);
+	*ptr++ = upper_32_bits(src);
+	*ptr++ = lower_32_bits(pe);
+	*ptr++ = upper_32_bits(pe);
+
+	ib->length_dw = ptr - ib->ptr;
 }
 
 /**
@@ -745,18 +747,21 @@ static void cik_sdma_vm_write_pte(struct amdgpu_ib *ib, uint64_t pe,
 				  uint64_t value, unsigned count,
 				  uint32_t incr)
 {
+	u32 *ptr = &ib->ptr[ib->length_dw];
 	unsigned ndw = count * 2;
 
-	ib->ptr[ib->length_dw++] = SDMA_PACKET(SDMA_OPCODE_WRITE,
-		SDMA_WRITE_SUB_OPCODE_LINEAR, 0);
-	ib->ptr[ib->length_dw++] = lower_32_bits(pe);
-	ib->ptr[ib->length_dw++] = upper_32_bits(pe);
-	ib->ptr[ib->length_dw++] = ndw;
+	*ptr++ = SDMA_PACKET(SDMA_OPCODE_WRITE,
+			     SDMA_WRITE_SUB_OPCODE_LINEAR, 0);
+	*ptr++ = lower_32_bits(pe);
+	*ptr++ = upper_32_bits(pe);
+	*ptr++ = ndw;
 	for (; ndw > 0; ndw -= 2) {
-		ib->ptr[ib->length_dw++] = lower_32_bits(value);
-		ib->ptr[ib->length_dw++] = upper_32_bits(value);
+		*ptr++ = lower_32_bits(value);
+		*ptr++ = upper_32_bits(value);
 		value += incr;
 	}
+
+	ib->length_dw = ptr - ib->ptr;
 }
 
 /**
@@ -775,17 +780,21 @@ static void cik_sdma_vm_set_pte_pde(struct amdgpu_ib *ib, uint64_t pe,
 				    uint64_t addr, unsigned count,
 				    uint32_t incr, uint64_t flags)
 {
+	u32 *ptr = &ib->ptr[ib->length_dw];
+
 	/* for physically contiguous pages (vram) */
-	ib->ptr[ib->length_dw++] = SDMA_PACKET(SDMA_OPCODE_GENERATE_PTE_PDE, 0, 0);
-	ib->ptr[ib->length_dw++] = lower_32_bits(pe); /* dst addr */
-	ib->ptr[ib->length_dw++] = upper_32_bits(pe);
-	ib->ptr[ib->length_dw++] = lower_32_bits(flags); /* mask */
-	ib->ptr[ib->length_dw++] = upper_32_bits(flags);
-	ib->ptr[ib->length_dw++] = lower_32_bits(addr); /* value */
-	ib->ptr[ib->length_dw++] = upper_32_bits(addr);
-	ib->ptr[ib->length_dw++] = incr; /* increment size */
-	ib->ptr[ib->length_dw++] = 0;
-	ib->ptr[ib->length_dw++] = count; /* number of entries */
+	*ptr++ = SDMA_PACKET(SDMA_OPCODE_GENERATE_PTE_PDE, 0, 0);
+	*ptr++ = lower_32_bits(pe); /* dst addr */
+	*ptr++ = upper_32_bits(pe);
+	*ptr++ = lower_32_bits(flags); /* mask */
+	*ptr++ = upper_32_bits(flags);
+	*ptr++ = lower_32_bits(addr); /* value */
+	*ptr++ = upper_32_bits(addr);
+	*ptr++ = incr; /* increment size */
+	*ptr++ = 0;
+	*ptr++ = count; /* number of entries */
+
+	ib->length_dw = ptr - ib->ptr;
 }
 
 /**
@@ -798,18 +807,22 @@ static void cik_sdma_vm_set_pte_pde(struct amdgpu_ib *ib, uint64_t pe,
 static void cik_sdma_ring_pad_ib(struct amdgpu_ring *ring, struct amdgpu_ib *ib)
 {
 	struct amdgpu_sdma_instance *sdma = amdgpu_sdma_get_instance_from_ring(ring);
+	u32 *ptr = &ib->ptr[ib->length_dw];
 	u32 pad_count;
 	int i;
 
 	pad_count = (-ib->length_dw) & 7;
+	if (!pad_count)
+		return;
+
 	for (i = 0; i < pad_count; i++)
 		if (sdma && sdma->burst_nop && (i == 0))
-			ib->ptr[ib->length_dw++] =
-					SDMA_PACKET(SDMA_OPCODE_NOP, 0, 0) |
-					SDMA_NOP_COUNT(pad_count - 1);
+			*ptr++ = SDMA_PACKET(SDMA_OPCODE_NOP, 0, 0) |
+				 SDMA_NOP_COUNT(pad_count - 1);
 		else
-			ib->ptr[ib->length_dw++] =
-					SDMA_PACKET(SDMA_OPCODE_NOP, 0, 0);
+			*ptr++ = SDMA_PACKET(SDMA_OPCODE_NOP, 0, 0);
+
+	ib->length_dw += pad_count;
 }
 
 /**
@@ -1290,13 +1303,17 @@ static void cik_sdma_emit_copy_buffer(struct amdgpu_ib *ib,
 				      uint32_t byte_count,
 				      uint32_t copy_flags)
 {
-	ib->ptr[ib->length_dw++] = SDMA_PACKET(SDMA_OPCODE_COPY, SDMA_COPY_SUB_OPCODE_LINEAR, 0);
-	ib->ptr[ib->length_dw++] = byte_count;
-	ib->ptr[ib->length_dw++] = 0; /* src/dst endian swap */
-	ib->ptr[ib->length_dw++] = lower_32_bits(src_offset);
-	ib->ptr[ib->length_dw++] = upper_32_bits(src_offset);
-	ib->ptr[ib->length_dw++] = lower_32_bits(dst_offset);
-	ib->ptr[ib->length_dw++] = upper_32_bits(dst_offset);
+	u32 *ptr = &ib->ptr[ib->length_dw];
+
+	*ptr++ = SDMA_PACKET(SDMA_OPCODE_COPY, SDMA_COPY_SUB_OPCODE_LINEAR, 0);
+	*ptr++ = byte_count;
+	*ptr++ = 0; /* src/dst endian swap */
+	*ptr++ = lower_32_bits(src_offset);
+	*ptr++ = upper_32_bits(src_offset);
+	*ptr++ = lower_32_bits(dst_offset);
+	*ptr++ = upper_32_bits(dst_offset);
+
+	ib->length_dw = ptr - ib->ptr;
 }
 
 /**
@@ -1314,11 +1331,15 @@ static void cik_sdma_emit_fill_buffer(struct amdgpu_ib *ib,
 				      uint64_t dst_offset,
 				      uint32_t byte_count)
 {
-	ib->ptr[ib->length_dw++] = SDMA_PACKET(SDMA_OPCODE_CONSTANT_FILL, 0, 0);
-	ib->ptr[ib->length_dw++] = lower_32_bits(dst_offset);
-	ib->ptr[ib->length_dw++] = upper_32_bits(dst_offset);
-	ib->ptr[ib->length_dw++] = src_data;
-	ib->ptr[ib->length_dw++] = byte_count;
+	u32 *ptr = &ib->ptr[ib->length_dw];
+
+	*ptr++ = SDMA_PACKET(SDMA_OPCODE_CONSTANT_FILL, 0, 0);
+	*ptr++ = lower_32_bits(dst_offset);
+	*ptr++ = upper_32_bits(dst_offset);
+	*ptr++ = src_data;
+	*ptr++ = byte_count;
+
+	ib->length_dw = ptr - ib->ptr;
 }
 
 static const struct amdgpu_buffer_funcs cik_sdma_buffer_funcs = {
Signature · 1 line
2.48.0
#8 lore raw

PATCH 8/16 drm/amdgpu: More compact GFX 9.4.2 IB emission

In reply to Tvrtko Ursulin

Avoid constant register reloads while emitting IBs by using a local write pointer and only updating the size at the end of each helper.

---
 drivers/gpu/drm/amd/amdgpu/gfx_v9_4_2.c | 46 +++++++++++++------------
 1 file changed, 24 insertions(+), 22 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v9_4_2.c +24 -22
index 8058ea91ecaf..830887964645 100644
@@ -354,6 +354,7 @@ static int gfx_v9_4_2_run_shader(struct amdgpu_device *adev,
 	int r, i;
 	uint32_t total_size, shader_offset;
 	u64 gpu_addr;
+	u32 *ptr;
 
 	total_size = (regs_size * 3 + 4 + 5 + 5) * 4;
 	total_size = ALIGN(total_size, 256);
@@ -373,40 +374,41 @@ static int gfx_v9_4_2_run_shader(struct amdgpu_device *adev,
 	for (i = 0; i < shader_size/sizeof(u32); i++)
 		ib->ptr[i + (shader_offset / 4)] = shader_ptr[i];
 
-	/* init the ib length to 0 */
-	ib->length_dw = 0;
+	ptr = ib->ptr;
 
 	/* write the register state for the compute dispatch */
 	for (i = 0; i < regs_size; i++) {
-		ib->ptr[ib->length_dw++] = PACKET3(PACKET3_SET_SH_REG, 1);
-		ib->ptr[ib->length_dw++] = SOC15_REG_ENTRY_OFFSET(init_regs[i])
-								- PACKET3_SET_SH_REG_START;
-		ib->ptr[ib->length_dw++] = init_regs[i].reg_value;
+		*ptr++ = PACKET3(PACKET3_SET_SH_REG, 1);
+		*ptr++ = SOC15_REG_ENTRY_OFFSET(init_regs[i]) -
+			 PACKET3_SET_SH_REG_START;
+		*ptr++ = init_regs[i].reg_value;
 	}
 
 	/* write the shader start address: mmCOMPUTE_PGM_LO, mmCOMPUTE_PGM_HI */
 	gpu_addr = (ib->gpu_addr + (u64)shader_offset) >> 8;
-	ib->ptr[ib->length_dw++] = PACKET3(PACKET3_SET_SH_REG, 2);
-	ib->ptr[ib->length_dw++] = SOC15_REG_OFFSET(GC, 0, regCOMPUTE_PGM_LO)
+	*ptr++ = PACKET3(PACKET3_SET_SH_REG, 2);
+	*ptr++ = SOC15_REG_OFFSET(GC, 0, regCOMPUTE_PGM_LO)
 							- PACKET3_SET_SH_REG_START;
-	ib->ptr[ib->length_dw++] = lower_32_bits(gpu_addr);
-	ib->ptr[ib->length_dw++] = upper_32_bits(gpu_addr);
+	*ptr++ = lower_32_bits(gpu_addr);
+	*ptr++ = upper_32_bits(gpu_addr);
 
 	/* write the wb buffer address */
-	ib->ptr[ib->length_dw++] = PACKET3(PACKET3_SET_SH_REG, 3);
-	ib->ptr[ib->length_dw++] = SOC15_REG_OFFSET(GC, 0, regCOMPUTE_USER_DATA_0)
-							- PACKET3_SET_SH_REG_START;
-	ib->ptr[ib->length_dw++] = lower_32_bits(wb_gpu_addr);
-	ib->ptr[ib->length_dw++] = upper_32_bits(wb_gpu_addr);
-	ib->ptr[ib->length_dw++] = pattern;
+	*ptr++ = PACKET3(PACKET3_SET_SH_REG, 3);
+	*ptr++ = SOC15_REG_OFFSET(GC, 0, regCOMPUTE_USER_DATA_0) -
+		 PACKET3_SET_SH_REG_START;
+	*ptr++ = lower_32_bits(wb_gpu_addr);
+	*ptr++ = upper_32_bits(wb_gpu_addr);
+	*ptr++ = pattern;
 
 	/* write dispatch packet */
-	ib->ptr[ib->length_dw++] = PACKET3(PACKET3_DISPATCH_DIRECT, 3);
-	ib->ptr[ib->length_dw++] = compute_dim_x; /* x */
-	ib->ptr[ib->length_dw++] = 1; /* y */
-	ib->ptr[ib->length_dw++] = 1; /* z */
-	ib->ptr[ib->length_dw++] =
-		REG_SET_FIELD(0, COMPUTE_DISPATCH_INITIATOR, COMPUTE_SHADER_EN, 1);
+	*ptr++ = PACKET3(PACKET3_DISPATCH_DIRECT, 3);
+	*ptr++ = compute_dim_x; /* x */
+	*ptr++ = 1; /* y */
+	*ptr++ = 1; /* z */
+	*ptr++ = REG_SET_FIELD(0, COMPUTE_DISPATCH_INITIATOR, COMPUTE_SHADER_EN,
+			       1);
+
+	ib->length_dw = ptr - ib->ptr;
 
 	/* shedule the ib on the ring */
 	r = amdgpu_ib_schedule(ring, 1, ib, NULL, fence_ptr);
Signature · 1 line
2.48.0
#9 lore raw

PATCH 9/16 drm/amdgpu: More compact SDMA 2.4 IB emission

In reply to Tvrtko Ursulin

Avoid constant register reloads while emitting IBs by using a local write pointer and only updating the size at the end of each helper.

---
 drivers/gpu/drm/amd/amdgpu/sdma_v2_4.c | 108 +++++++++++++++----------
 1 file changed, 65 insertions(+), 43 deletions(-)
drivers/gpu/drm/amd/amdgpu/sdma_v2_4.c +65 -43
index 92ce580647cd..53083c53a435 100644
@@ -654,16 +654,19 @@ static void sdma_v2_4_vm_copy_pte(struct amdgpu_ib *ib,
 				  uint64_t pe, uint64_t src,
 				  unsigned count)
 {
+	u32 *ptr = &ib->ptr[ib->length_dw];
 	unsigned bytes = count * 8;
 
-	ib->ptr[ib->length_dw++] = SDMA_PKT_HEADER_OP(SDMA_OP_COPY) |
-		SDMA_PKT_HEADER_SUB_OP(SDMA_SUBOP_COPY_LINEAR);
-	ib->ptr[ib->length_dw++] = bytes;
-	ib->ptr[ib->length_dw++] = 0; /* src/dst endian swap */
-	ib->ptr[ib->length_dw++] = lower_32_bits(src);
-	ib->ptr[ib->length_dw++] = upper_32_bits(src);
-	ib->ptr[ib->length_dw++] = lower_32_bits(pe);
-	ib->ptr[ib->length_dw++] = upper_32_bits(pe);
+	*ptr++ = SDMA_PKT_HEADER_OP(SDMA_OP_COPY) |
+		 SDMA_PKT_HEADER_SUB_OP(SDMA_SUBOP_COPY_LINEAR);
+	*ptr++ = bytes;
+	*ptr++ = 0; /* src/dst endian swap */
+	*ptr++ = lower_32_bits(src);
+	*ptr++ = upper_32_bits(src);
+	*ptr++ = lower_32_bits(pe);
+	*ptr++ = upper_32_bits(pe);
+
+	ib->length_dw = ptr - ib->ptr;
 }
 
 /**
@@ -681,18 +684,21 @@ static void sdma_v2_4_vm_write_pte(struct amdgpu_ib *ib, uint64_t pe,
 				   uint64_t value, unsigned count,
 				   uint32_t incr)
 {
+	u32 *ptr = &ib->ptr[ib->length_dw];
 	unsigned ndw = count * 2;
 
-	ib->ptr[ib->length_dw++] = SDMA_PKT_HEADER_OP(SDMA_OP_WRITE) |
-		SDMA_PKT_HEADER_SUB_OP(SDMA_SUBOP_WRITE_LINEAR);
-	ib->ptr[ib->length_dw++] = pe;
-	ib->ptr[ib->length_dw++] = upper_32_bits(pe);
-	ib->ptr[ib->length_dw++] = ndw;
+	*ptr++ = SDMA_PKT_HEADER_OP(SDMA_OP_WRITE) |
+		 SDMA_PKT_HEADER_SUB_OP(SDMA_SUBOP_WRITE_LINEAR);
+	*ptr++ = pe;
+	*ptr++ = upper_32_bits(pe);
+	*ptr++ = ndw;
 	for (; ndw > 0; ndw -= 2) {
-		ib->ptr[ib->length_dw++] = lower_32_bits(value);
-		ib->ptr[ib->length_dw++] = upper_32_bits(value);
+		*ptr++ = lower_32_bits(value);
+		*ptr++ = upper_32_bits(value);
 		value += incr;
 	}
+
+	ib->length_dw = ptr - ib->ptr;
 }
 
 /**
@@ -711,17 +717,21 @@ static void sdma_v2_4_vm_set_pte_pde(struct amdgpu_ib *ib, uint64_t pe,
 				     uint64_t addr, unsigned count,
 				     uint32_t incr, uint64_t flags)
 {
+	u32 *ptr = &ib->ptr[ib->length_dw];
+
 	/* for physically contiguous pages (vram) */
-	ib->ptr[ib->length_dw++] = SDMA_PKT_HEADER_OP(SDMA_OP_GEN_PTEPDE);
-	ib->ptr[ib->length_dw++] = lower_32_bits(pe); /* dst addr */
-	ib->ptr[ib->length_dw++] = upper_32_bits(pe);
-	ib->ptr[ib->length_dw++] = lower_32_bits(flags); /* mask */
-	ib->ptr[ib->length_dw++] = upper_32_bits(flags);
-	ib->ptr[ib->length_dw++] = lower_32_bits(addr); /* value */
-	ib->ptr[ib->length_dw++] = upper_32_bits(addr);
-	ib->ptr[ib->length_dw++] = incr; /* increment size */
-	ib->ptr[ib->length_dw++] = 0;
-	ib->ptr[ib->length_dw++] = count; /* number of entries */
+	*ptr++ = SDMA_PKT_HEADER_OP(SDMA_OP_GEN_PTEPDE);
+	*ptr++ = lower_32_bits(pe); /* dst addr */
+	*ptr++ = upper_32_bits(pe);
+	*ptr++ = lower_32_bits(flags); /* mask */
+	*ptr++ = upper_32_bits(flags);
+	*ptr++ = lower_32_bits(addr); /* value */
+	*ptr++ = upper_32_bits(addr);
+	*ptr++ = incr; /* increment size */
+	*ptr++ = 0;
+	*ptr++ = count; /* number of entries */
+
+	ib->length_dw = ptr - ib->ptr;
 }
 
 /**
@@ -734,18 +744,22 @@ static void sdma_v2_4_vm_set_pte_pde(struct amdgpu_ib *ib, uint64_t pe,
 static void sdma_v2_4_ring_pad_ib(struct amdgpu_ring *ring, struct amdgpu_ib *ib)
 {
 	struct amdgpu_sdma_instance *sdma = amdgpu_sdma_get_instance_from_ring(ring);
+	u32 *ptr = &ib->ptr[ib->length_dw];
 	u32 pad_count;
 	int i;
 
 	pad_count = (-ib->length_dw) & 7;
+	if (!pad_count)
+		return;
+
 	for (i = 0; i < pad_count; i++)
 		if (sdma && sdma->burst_nop && (i == 0))
-			ib->ptr[ib->length_dw++] =
-				SDMA_PKT_HEADER_OP(SDMA_OP_NOP) |
-				SDMA_PKT_NOP_HEADER_COUNT(pad_count - 1);
+			*ptr++ = SDMA_PKT_HEADER_OP(SDMA_OP_NOP) |
+				 SDMA_PKT_NOP_HEADER_COUNT(pad_count - 1);
 		else
-			ib->ptr[ib->length_dw++] =
-				SDMA_PKT_HEADER_OP(SDMA_OP_NOP);
+			*ptr++ = SDMA_PKT_HEADER_OP(SDMA_OP_NOP);
+
+	ib->length_dw += pad_count;
 }
 
 /**
@@ -1184,14 +1198,18 @@ static void sdma_v2_4_emit_copy_buffer(struct amdgpu_ib *ib,
 				       uint32_t byte_count,
 				       uint32_t copy_flags)
 {
-	ib->ptr[ib->length_dw++] = SDMA_PKT_HEADER_OP(SDMA_OP_COPY) |
-		SDMA_PKT_HEADER_SUB_OP(SDMA_SUBOP_COPY_LINEAR);
-	ib->ptr[ib->length_dw++] = byte_count;
-	ib->ptr[ib->length_dw++] = 0; /* src/dst endian swap */
-	ib->ptr[ib->length_dw++] = lower_32_bits(src_offset);
-	ib->ptr[ib->length_dw++] = upper_32_bits(src_offset);
-	ib->ptr[ib->length_dw++] = lower_32_bits(dst_offset);
-	ib->ptr[ib->length_dw++] = upper_32_bits(dst_offset);
+	u32 *ptr = &ib->ptr[ib->length_dw];
+
+	*ptr++ = SDMA_PKT_HEADER_OP(SDMA_OP_COPY) |
+		 SDMA_PKT_HEADER_SUB_OP(SDMA_SUBOP_COPY_LINEAR);
+	*ptr++ = byte_count;
+	*ptr++ = 0; /* src/dst endian swap */
+	*ptr++ = lower_32_bits(src_offset);
+	*ptr++ = upper_32_bits(src_offset);
+	*ptr++ = lower_32_bits(dst_offset);
+	*ptr++ = upper_32_bits(dst_offset);
+
+	ib->length_dw = ptr - ib->ptr;
 }
 
 /**
@@ -1209,11 +1227,15 @@ static void sdma_v2_4_emit_fill_buffer(struct amdgpu_ib *ib,
 				       uint64_t dst_offset,
 				       uint32_t byte_count)
 {
-	ib->ptr[ib->length_dw++] = SDMA_PKT_HEADER_OP(SDMA_OP_CONST_FILL);
-	ib->ptr[ib->length_dw++] = lower_32_bits(dst_offset);
-	ib->ptr[ib->length_dw++] = upper_32_bits(dst_offset);
-	ib->ptr[ib->length_dw++] = src_data;
-	ib->ptr[ib->length_dw++] = byte_count;
+	u32 *ptr = &ib->ptr[ib->length_dw];
+
+	*ptr++ = SDMA_PKT_HEADER_OP(SDMA_OP_CONST_FILL);
+	*ptr++ = lower_32_bits(dst_offset);
+	*ptr++ = upper_32_bits(dst_offset);
+	*ptr++ = src_data;
+	*ptr++ = byte_count;
+
+	ib->length_dw = ptr - ib->ptr;
 }
 
 static const struct amdgpu_buffer_funcs sdma_v2_4_buffer_funcs = {
Signature · 1 line
2.48.0
#10 lore raw

PATCH 10/16 drm/amdgpu: More compact SDMA 3.0 IB emission

In reply to Tvrtko Ursulin

Avoid constant register reloads while emitting IBs by using a local write pointer and only updating the size at the end of each helper.

---
 drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c | 108 +++++++++++++++----------
 1 file changed, 65 insertions(+), 43 deletions(-)
drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c +65 -43
index 1c076bd1cf73..01b95d1c7419 100644
@@ -927,16 +927,19 @@ static void sdma_v3_0_vm_copy_pte(struct amdgpu_ib *ib,
 				  uint64_t pe, uint64_t src,
 				  unsigned count)
 {
+	u32 *ptr = &ib->ptr[ib->length_dw];
 	unsigned bytes = count * 8;
 
-	ib->ptr[ib->length_dw++] = SDMA_PKT_HEADER_OP(SDMA_OP_COPY) |
-		SDMA_PKT_HEADER_SUB_OP(SDMA_SUBOP_COPY_LINEAR);
-	ib->ptr[ib->length_dw++] = bytes;
-	ib->ptr[ib->length_dw++] = 0; /* src/dst endian swap */
-	ib->ptr[ib->length_dw++] = lower_32_bits(src);
-	ib->ptr[ib->length_dw++] = upper_32_bits(src);
-	ib->ptr[ib->length_dw++] = lower_32_bits(pe);
-	ib->ptr[ib->length_dw++] = upper_32_bits(pe);
+	*ptr++ = SDMA_PKT_HEADER_OP(SDMA_OP_COPY) |
+		 SDMA_PKT_HEADER_SUB_OP(SDMA_SUBOP_COPY_LINEAR);
+	*ptr++ = bytes;
+	*ptr++ = 0; /* src/dst endian swap */
+	*ptr++ = lower_32_bits(src);
+	*ptr++ = upper_32_bits(src);
+	*ptr++ = lower_32_bits(pe);
+	*ptr++ = upper_32_bits(pe);
+
+	ib->length_dw = ptr - ib->ptr;
 }
 
 /**
@@ -954,18 +957,21 @@ static void sdma_v3_0_vm_write_pte(struct amdgpu_ib *ib, uint64_t pe,
 				   uint64_t value, unsigned count,
 				   uint32_t incr)
 {
+	u32 *ptr = &ib->ptr[ib->length_dw];
 	unsigned ndw = count * 2;
 
-	ib->ptr[ib->length_dw++] = SDMA_PKT_HEADER_OP(SDMA_OP_WRITE) |
-		SDMA_PKT_HEADER_SUB_OP(SDMA_SUBOP_WRITE_LINEAR);
-	ib->ptr[ib->length_dw++] = lower_32_bits(pe);
-	ib->ptr[ib->length_dw++] = upper_32_bits(pe);
-	ib->ptr[ib->length_dw++] = ndw;
+	*ptr++ = SDMA_PKT_HEADER_OP(SDMA_OP_WRITE) |
+		 SDMA_PKT_HEADER_SUB_OP(SDMA_SUBOP_WRITE_LINEAR);
+	*ptr++ = lower_32_bits(pe);
+	*ptr++ = upper_32_bits(pe);
+	*ptr++ = ndw;
 	for (; ndw > 0; ndw -= 2) {
-		ib->ptr[ib->length_dw++] = lower_32_bits(value);
-		ib->ptr[ib->length_dw++] = upper_32_bits(value);
+		*ptr++ = lower_32_bits(value);
+		*ptr++ = upper_32_bits(value);
 		value += incr;
 	}
+
+	ib->length_dw = ptr - ib->ptr;
 }
 
 /**
@@ -984,17 +990,21 @@ static void sdma_v3_0_vm_set_pte_pde(struct amdgpu_ib *ib, uint64_t pe,
 				     uint64_t addr, unsigned count,
 				     uint32_t incr, uint64_t flags)
 {
+	u32 *ptr = &ib->ptr[ib->length_dw];
+
 	/* for physically contiguous pages (vram) */
-	ib->ptr[ib->length_dw++] = SDMA_PKT_HEADER_OP(SDMA_OP_GEN_PTEPDE);
-	ib->ptr[ib->length_dw++] = lower_32_bits(pe); /* dst addr */
-	ib->ptr[ib->length_dw++] = upper_32_bits(pe);
-	ib->ptr[ib->length_dw++] = lower_32_bits(flags); /* mask */
-	ib->ptr[ib->length_dw++] = upper_32_bits(flags);
-	ib->ptr[ib->length_dw++] = lower_32_bits(addr); /* value */
-	ib->ptr[ib->length_dw++] = upper_32_bits(addr);
-	ib->ptr[ib->length_dw++] = incr; /* increment size */
-	ib->ptr[ib->length_dw++] = 0;
-	ib->ptr[ib->length_dw++] = count; /* number of entries */
+	*ptr++ = SDMA_PKT_HEADER_OP(SDMA_OP_GEN_PTEPDE);
+	*ptr++ = lower_32_bits(pe); /* dst addr */
+	*ptr++ = upper_32_bits(pe);
+	*ptr++ = lower_32_bits(flags); /* mask */
+	*ptr++ = upper_32_bits(flags);
+	*ptr++ = lower_32_bits(addr); /* value */
+	*ptr++ = upper_32_bits(addr);
+	*ptr++ = incr; /* increment size */
+	*ptr++ = 0;
+	*ptr++ = count; /* number of entries */
+
+	ib->length_dw = ptr - ib->ptr;
 }
 
 /**
@@ -1007,18 +1017,22 @@ static void sdma_v3_0_vm_set_pte_pde(struct amdgpu_ib *ib, uint64_t pe,
 static void sdma_v3_0_ring_pad_ib(struct amdgpu_ring *ring, struct amdgpu_ib *ib)
 {
 	struct amdgpu_sdma_instance *sdma = amdgpu_sdma_get_instance_from_ring(ring);
+	u32 *ptr = &ib->ptr[ib->length_dw];
 	u32 pad_count;
 	int i;
 
 	pad_count = (-ib->length_dw) & 7;
+	if (!pad_count)
+		return;
+
 	for (i = 0; i < pad_count; i++)
 		if (sdma && sdma->burst_nop && (i == 0))
-			ib->ptr[ib->length_dw++] =
-				SDMA_PKT_HEADER_OP(SDMA_OP_NOP) |
-				SDMA_PKT_NOP_HEADER_COUNT(pad_count - 1);
+			*ptr++ = SDMA_PKT_HEADER_OP(SDMA_OP_NOP) |
+				 SDMA_PKT_NOP_HEADER_COUNT(pad_count - 1);
 		else
-			ib->ptr[ib->length_dw++] =
-				SDMA_PKT_HEADER_OP(SDMA_OP_NOP);
+			*ptr++ = SDMA_PKT_HEADER_OP(SDMA_OP_NOP);
+
+	ib->length_dw = pad_count;
 }
 
 /**
@@ -1626,14 +1640,18 @@ static void sdma_v3_0_emit_copy_buffer(struct amdgpu_ib *ib,
 				       uint32_t byte_count,
 				       uint32_t copy_flags)
 {
-	ib->ptr[ib->length_dw++] = SDMA_PKT_HEADER_OP(SDMA_OP_COPY) |
-		SDMA_PKT_HEADER_SUB_OP(SDMA_SUBOP_COPY_LINEAR);
-	ib->ptr[ib->length_dw++] = byte_count;
-	ib->ptr[ib->length_dw++] = 0; /* src/dst endian swap */
-	ib->ptr[ib->length_dw++] = lower_32_bits(src_offset);
-	ib->ptr[ib->length_dw++] = upper_32_bits(src_offset);
-	ib->ptr[ib->length_dw++] = lower_32_bits(dst_offset);
-	ib->ptr[ib->length_dw++] = upper_32_bits(dst_offset);
+	u32 *ptr = &ib->ptr[ib->length_dw];
+
+	*ptr++ = SDMA_PKT_HEADER_OP(SDMA_OP_COPY) |
+		 SDMA_PKT_HEADER_SUB_OP(SDMA_SUBOP_COPY_LINEAR);
+	*ptr++ = byte_count;
+	*ptr++ = 0; /* src/dst endian swap */
+	*ptr++ = lower_32_bits(src_offset);
+	*ptr++ = upper_32_bits(src_offset);
+	*ptr++ = lower_32_bits(dst_offset);
+	*ptr++ = upper_32_bits(dst_offset);
+
+	ib->length_dw = ptr - ib->ptr;
 }
 
 /**
@@ -1651,11 +1669,15 @@ static void sdma_v3_0_emit_fill_buffer(struct amdgpu_ib *ib,
 				       uint64_t dst_offset,
 				       uint32_t byte_count)
 {
-	ib->ptr[ib->length_dw++] = SDMA_PKT_HEADER_OP(SDMA_OP_CONST_FILL);
-	ib->ptr[ib->length_dw++] = lower_32_bits(dst_offset);
-	ib->ptr[ib->length_dw++] = upper_32_bits(dst_offset);
-	ib->ptr[ib->length_dw++] = src_data;
-	ib->ptr[ib->length_dw++] = byte_count;
+	u32 *ptr = &ib->ptr[ib->length_dw];
+
+	*ptr++ = SDMA_PKT_HEADER_OP(SDMA_OP_CONST_FILL);
+	*ptr++ = lower_32_bits(dst_offset);
+	*ptr++ = upper_32_bits(dst_offset);
+	*ptr++ = src_data;
+	*ptr++ = byte_count;
+
+	ib->length_dw = ptr - ib->ptr;
 }
 
 static const struct amdgpu_buffer_funcs sdma_v3_0_buffer_funcs = {
Signature · 1 line
2.48.0
#11 lore raw

PATCH 11/16 drm/amdgpu: More compact SDMA 4.0 IB emission

In reply to Tvrtko Ursulin

Avoid constant register reloads while emitting IBs by using a local write pointer and only updating the size at the end of each helper.

---
 drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c | 109 +++++++++++++++----------
 1 file changed, 65 insertions(+), 44 deletions(-)
drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c +65 -44
index f38004e6064e..0308ff694c74 100644
@@ -1587,17 +1587,19 @@ static void sdma_v4_0_vm_copy_pte(struct amdgpu_ib *ib,
 				  uint64_t pe, uint64_t src,
 				  unsigned count)
 {
+	u32 *ptr = &ib->ptr[ib->length_dw];
 	unsigned bytes = count * 8;
 
-	ib->ptr[ib->length_dw++] = SDMA_PKT_HEADER_OP(SDMA_OP_COPY) |
-		SDMA_PKT_HEADER_SUB_OP(SDMA_SUBOP_COPY_LINEAR);
-	ib->ptr[ib->length_dw++] = bytes - 1;
-	ib->ptr[ib->length_dw++] = 0; /* src/dst endian swap */
-	ib->ptr[ib->length_dw++] = lower_32_bits(src);
-	ib->ptr[ib->length_dw++] = upper_32_bits(src);
-	ib->ptr[ib->length_dw++] = lower_32_bits(pe);
-	ib->ptr[ib->length_dw++] = upper_32_bits(pe);
+	*ptr++ = SDMA_PKT_HEADER_OP(SDMA_OP_COPY) |
+		 SDMA_PKT_HEADER_SUB_OP(SDMA_SUBOP_COPY_LINEAR);
+	*ptr++ = bytes - 1;
+	*ptr++ = 0; /* src/dst endian swap */
+	*ptr++ = lower_32_bits(src);
+	*ptr++ = upper_32_bits(src);
+	*ptr++ = lower_32_bits(pe);
+	*ptr++ = upper_32_bits(pe);
 
+	ib->length_dw = ptr - ib->ptr;
 }
 
 /**
@@ -1615,18 +1617,21 @@ static void sdma_v4_0_vm_write_pte(struct amdgpu_ib *ib, uint64_t pe,
 				   uint64_t value, unsigned count,
 				   uint32_t incr)
 {
+	u32 *ptr = &ib->ptr[ib->length_dw];
 	unsigned ndw = count * 2;
 
-	ib->ptr[ib->length_dw++] = SDMA_PKT_HEADER_OP(SDMA_OP_WRITE) |
-		SDMA_PKT_HEADER_SUB_OP(SDMA_SUBOP_WRITE_LINEAR);
-	ib->ptr[ib->length_dw++] = lower_32_bits(pe);
-	ib->ptr[ib->length_dw++] = upper_32_bits(pe);
-	ib->ptr[ib->length_dw++] = ndw - 1;
+	*ptr++ = SDMA_PKT_HEADER_OP(SDMA_OP_WRITE) |
+		 SDMA_PKT_HEADER_SUB_OP(SDMA_SUBOP_WRITE_LINEAR);
+	*ptr++ = lower_32_bits(pe);
+	*ptr++ = upper_32_bits(pe);
+	*ptr++ = ndw - 1;
 	for (; ndw > 0; ndw -= 2) {
-		ib->ptr[ib->length_dw++] = lower_32_bits(value);
-		ib->ptr[ib->length_dw++] = upper_32_bits(value);
+		*ptr++ = lower_32_bits(value);
+		*ptr++ = upper_32_bits(value);
 		value += incr;
 	}
+
+	ib->length_dw = ptr - ib->ptr;
 }
 
 /**
@@ -1646,17 +1651,21 @@ static void sdma_v4_0_vm_set_pte_pde(struct amdgpu_ib *ib,
 				     uint64_t addr, unsigned count,
 				     uint32_t incr, uint64_t flags)
 {
+	u32 *ptr = &ib->ptr[ib->length_dw];
+
 	/* for physically contiguous pages (vram) */
-	ib->ptr[ib->length_dw++] = SDMA_PKT_HEADER_OP(SDMA_OP_PTEPDE);
-	ib->ptr[ib->length_dw++] = lower_32_bits(pe); /* dst addr */
-	ib->ptr[ib->length_dw++] = upper_32_bits(pe);
-	ib->ptr[ib->length_dw++] = lower_32_bits(flags); /* mask */
-	ib->ptr[ib->length_dw++] = upper_32_bits(flags);
-	ib->ptr[ib->length_dw++] = lower_32_bits(addr); /* value */
-	ib->ptr[ib->length_dw++] = upper_32_bits(addr);
-	ib->ptr[ib->length_dw++] = incr; /* increment size */
-	ib->ptr[ib->length_dw++] = 0;
-	ib->ptr[ib->length_dw++] = count - 1; /* number of entries */
+	*ptr++ = SDMA_PKT_HEADER_OP(SDMA_OP_PTEPDE);
+	*ptr++ = lower_32_bits(pe); /* dst addr */
+	*ptr++ = upper_32_bits(pe);
+	*ptr++ = lower_32_bits(flags); /* mask */
+	*ptr++ = upper_32_bits(flags);
+	*ptr++ = lower_32_bits(addr); /* value */
+	*ptr++ = upper_32_bits(addr);
+	*ptr++ = incr; /* increment size */
+	*ptr++ = 0;
+	*ptr++ = count - 1; /* number of entries */
+
+	ib->length_dw = ptr - ib->ptr;
 }
 
 /**
@@ -1668,18 +1677,22 @@ static void sdma_v4_0_vm_set_pte_pde(struct amdgpu_ib *ib,
 static void sdma_v4_0_ring_pad_ib(struct amdgpu_ring *ring, struct amdgpu_ib *ib)
 {
 	struct amdgpu_sdma_instance *sdma = amdgpu_sdma_get_instance_from_ring(ring);
+	u32 *ptr = &ib->ptr[ib->length_dw];
 	u32 pad_count;
 	int i;
 
 	pad_count = (-ib->length_dw) & 7;
+	if (!pad_count)
+		return;
+
 	for (i = 0; i < pad_count; i++)
 		if (sdma && sdma->burst_nop && (i == 0))
-			ib->ptr[ib->length_dw++] =
-				SDMA_PKT_HEADER_OP(SDMA_OP_NOP) |
-				SDMA_PKT_NOP_HEADER_COUNT(pad_count - 1);
+			*ptr++ = SDMA_PKT_HEADER_OP(SDMA_OP_NOP) |
+				 SDMA_PKT_NOP_HEADER_COUNT(pad_count - 1);
 		else
-			ib->ptr[ib->length_dw++] =
-				SDMA_PKT_HEADER_OP(SDMA_OP_NOP);
+			*ptr++ = SDMA_PKT_HEADER_OP(SDMA_OP_NOP);
+
+	ib->length_dw += pad_count;
 }
 
 
@@ -2563,15 +2576,19 @@ static void sdma_v4_0_emit_copy_buffer(struct amdgpu_ib *ib,
 				       uint32_t byte_count,
 				       uint32_t copy_flags)
 {
-	ib->ptr[ib->length_dw++] = SDMA_PKT_HEADER_OP(SDMA_OP_COPY) |
-		SDMA_PKT_HEADER_SUB_OP(SDMA_SUBOP_COPY_LINEAR) |
-		SDMA_PKT_COPY_LINEAR_HEADER_TMZ((copy_flags & AMDGPU_COPY_FLAGS_TMZ) ? 1 : 0);
-	ib->ptr[ib->length_dw++] = byte_count - 1;
-	ib->ptr[ib->length_dw++] = 0; /* src/dst endian swap */
-	ib->ptr[ib->length_dw++] = lower_32_bits(src_offset);
-	ib->ptr[ib->length_dw++] = upper_32_bits(src_offset);
-	ib->ptr[ib->length_dw++] = lower_32_bits(dst_offset);
-	ib->ptr[ib->length_dw++] = upper_32_bits(dst_offset);
+	u32 *ptr = &ib->ptr[ib->length_dw];
+
+	*ptr++ = SDMA_PKT_HEADER_OP(SDMA_OP_COPY) |
+		 SDMA_PKT_HEADER_SUB_OP(SDMA_SUBOP_COPY_LINEAR) |
+		 SDMA_PKT_COPY_LINEAR_HEADER_TMZ((copy_flags & AMDGPU_COPY_FLAGS_TMZ) ? 1 : 0);
+	*ptr++ = byte_count - 1;
+	*ptr++ = 0; /* src/dst endian swap */
+	*ptr++ = lower_32_bits(src_offset);
+	*ptr++ = upper_32_bits(src_offset);
+	*ptr++ = lower_32_bits(dst_offset);
+	*ptr++ = upper_32_bits(dst_offset);
+
+	ib->length_dw = ptr - ib->ptr;
 }
 
 /**
@@ -2589,11 +2606,15 @@ static void sdma_v4_0_emit_fill_buffer(struct amdgpu_ib *ib,
 				       uint64_t dst_offset,
 				       uint32_t byte_count)
 {
-	ib->ptr[ib->length_dw++] = SDMA_PKT_HEADER_OP(SDMA_OP_CONST_FILL);
-	ib->ptr[ib->length_dw++] = lower_32_bits(dst_offset);
-	ib->ptr[ib->length_dw++] = upper_32_bits(dst_offset);
-	ib->ptr[ib->length_dw++] = src_data;
-	ib->ptr[ib->length_dw++] = byte_count - 1;
+	u32 *ptr = &ib->ptr[ib->length_dw];
+
+	*ptr++ = SDMA_PKT_HEADER_OP(SDMA_OP_CONST_FILL);
+	*ptr++ = lower_32_bits(dst_offset);
+	*ptr++ = upper_32_bits(dst_offset);
+	*ptr++ = src_data;
+	*ptr++ = byte_count - 1;
+
+	ib->length_dw = ptr - ib->ptr;
 }
 
 static const struct amdgpu_buffer_funcs sdma_v4_0_buffer_funcs = {
Signature · 1 line
2.48.0
#12 lore raw

PATCH 12/16 drm/amdgpu: More compact SDMA 4.4.2 IB emission

In reply to Tvrtko Ursulin

Avoid constant register reloads while emitting IBs by using a local write pointer and only updating the size at the end of each helper.

---
 drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c | 108 ++++++++++++++---------
 1 file changed, 65 insertions(+), 43 deletions(-)
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +65 -43
index 36b1ca73c2ed..59d85c71f9bb 100644
@@ -1183,16 +1183,19 @@ static void sdma_v4_4_2_vm_copy_pte(struct amdgpu_ib *ib,
 				  uint64_t pe, uint64_t src,
 				  unsigned count)
 {
+	u32 *ptr = &ib->ptr[ib->length_dw];
 	unsigned bytes = count * 8;
 
-	ib->ptr[ib->length_dw++] = SDMA_PKT_HEADER_OP(SDMA_OP_COPY) |
-		SDMA_PKT_HEADER_SUB_OP(SDMA_SUBOP_COPY_LINEAR);
-	ib->ptr[ib->length_dw++] = bytes - 1;
-	ib->ptr[ib->length_dw++] = 0; /* src/dst endian swap */
-	ib->ptr[ib->length_dw++] = lower_32_bits(src);
-	ib->ptr[ib->length_dw++] = upper_32_bits(src);
-	ib->ptr[ib->length_dw++] = lower_32_bits(pe);
-	ib->ptr[ib->length_dw++] = upper_32_bits(pe);
+	*ptr++ = SDMA_PKT_HEADER_OP(SDMA_OP_COPY) |
+		 SDMA_PKT_HEADER_SUB_OP(SDMA_SUBOP_COPY_LINEAR);
+	*ptr++ = bytes - 1;
+	*ptr++ = 0; /* src/dst endian swap */
+	*ptr++ = lower_32_bits(src);
+	*ptr++ = upper_32_bits(src);
+	*ptr++ = lower_32_bits(pe);
+	*ptr++ = upper_32_bits(pe);
+
+	ib->length_dw = ptr - ib->ptr;
 
 }
 
@@ -1211,18 +1214,21 @@ static void sdma_v4_4_2_vm_write_pte(struct amdgpu_ib *ib, uint64_t pe,
 				   uint64_t value, unsigned count,
 				   uint32_t incr)
 {
+	u32 *ptr = &ib->ptr[ib->length_dw];
 	unsigned ndw = count * 2;
 
-	ib->ptr[ib->length_dw++] = SDMA_PKT_HEADER_OP(SDMA_OP_WRITE) |
+	*ptr++ = SDMA_PKT_HEADER_OP(SDMA_OP_WRITE) |
 		SDMA_PKT_HEADER_SUB_OP(SDMA_SUBOP_WRITE_LINEAR);
-	ib->ptr[ib->length_dw++] = lower_32_bits(pe);
-	ib->ptr[ib->length_dw++] = upper_32_bits(pe);
-	ib->ptr[ib->length_dw++] = ndw - 1;
+	*ptr++ = lower_32_bits(pe);
+	*ptr++ = upper_32_bits(pe);
+	*ptr++ = ndw - 1;
 	for (; ndw > 0; ndw -= 2) {
-		ib->ptr[ib->length_dw++] = lower_32_bits(value);
-		ib->ptr[ib->length_dw++] = upper_32_bits(value);
+		*ptr++ = lower_32_bits(value);
+		*ptr++ = upper_32_bits(value);
 		value += incr;
 	}
+
+	ib->length_dw = ptr - ib->ptr;
 }
 
 /**
@@ -1242,17 +1248,21 @@ static void sdma_v4_4_2_vm_set_pte_pde(struct amdgpu_ib *ib,
 				     uint64_t addr, unsigned count,
 				     uint32_t incr, uint64_t flags)
 {
+	u32 *ptr = &ib->ptr[ib->length_dw];
+
 	/* for physically contiguous pages (vram) */
-	ib->ptr[ib->length_dw++] = SDMA_PKT_HEADER_OP(SDMA_OP_PTEPDE);
-	ib->ptr[ib->length_dw++] = lower_32_bits(pe); /* dst addr */
-	ib->ptr[ib->length_dw++] = upper_32_bits(pe);
-	ib->ptr[ib->length_dw++] = lower_32_bits(flags); /* mask */
-	ib->ptr[ib->length_dw++] = upper_32_bits(flags);
-	ib->ptr[ib->length_dw++] = lower_32_bits(addr); /* value */
-	ib->ptr[ib->length_dw++] = upper_32_bits(addr);
-	ib->ptr[ib->length_dw++] = incr; /* increment size */
-	ib->ptr[ib->length_dw++] = 0;
-	ib->ptr[ib->length_dw++] = count - 1; /* number of entries */
+	*ptr++ = SDMA_PKT_HEADER_OP(SDMA_OP_PTEPDE);
+	*ptr++ = lower_32_bits(pe); /* dst addr */
+	*ptr++ = upper_32_bits(pe);
+	*ptr++ = lower_32_bits(flags); /* mask */
+	*ptr++ = upper_32_bits(flags);
+	*ptr++ = lower_32_bits(addr); /* value */
+	*ptr++ = upper_32_bits(addr);
+	*ptr++ = incr; /* increment size */
+	*ptr++ = 0;
+	*ptr++ = count - 1; /* number of entries */
+
+	ib->length_dw = ptr - ib->ptr;
 }
 
 /**
@@ -1264,18 +1274,22 @@ static void sdma_v4_4_2_vm_set_pte_pde(struct amdgpu_ib *ib,
 static void sdma_v4_4_2_ring_pad_ib(struct amdgpu_ring *ring, struct amdgpu_ib *ib)
 {
 	struct amdgpu_sdma_instance *sdma = amdgpu_sdma_get_instance_from_ring(ring);
+	u32 *ptr = &ib->ptr[ib->length_dw];
 	u32 pad_count;
 	int i;
 
 	pad_count = (-ib->length_dw) & 7;
+	if (!pad_count)
+		return;
+
 	for (i = 0; i < pad_count; i++)
 		if (sdma && sdma->burst_nop && (i == 0))
-			ib->ptr[ib->length_dw++] =
-				SDMA_PKT_HEADER_OP(SDMA_OP_NOP) |
-				SDMA_PKT_NOP_HEADER_COUNT(pad_count - 1);
+			*ptr++ = SDMA_PKT_HEADER_OP(SDMA_OP_NOP) |
+				 SDMA_PKT_NOP_HEADER_COUNT(pad_count - 1);
 		else
-			ib->ptr[ib->length_dw++] =
-				SDMA_PKT_HEADER_OP(SDMA_OP_NOP);
+			*ptr++ = SDMA_PKT_HEADER_OP(SDMA_OP_NOP);
+
+	ib->length_dw += pad_count;
 }
 
 
@@ -2264,15 +2278,19 @@ static void sdma_v4_4_2_emit_copy_buffer(struct amdgpu_ib *ib,
 				       uint32_t byte_count,
 				       uint32_t copy_flags)
 {
-	ib->ptr[ib->length_dw++] = SDMA_PKT_HEADER_OP(SDMA_OP_COPY) |
-		SDMA_PKT_HEADER_SUB_OP(SDMA_SUBOP_COPY_LINEAR) |
-		SDMA_PKT_COPY_LINEAR_HEADER_TMZ((copy_flags & AMDGPU_COPY_FLAGS_TMZ) ? 1 : 0);
-	ib->ptr[ib->length_dw++] = byte_count - 1;
-	ib->ptr[ib->length_dw++] = 0; /* src/dst endian swap */
-	ib->ptr[ib->length_dw++] = lower_32_bits(src_offset);
-	ib->ptr[ib->length_dw++] = upper_32_bits(src_offset);
-	ib->ptr[ib->length_dw++] = lower_32_bits(dst_offset);
-	ib->ptr[ib->length_dw++] = upper_32_bits(dst_offset);
+	u32 *ptr = &ib->ptr[ib->length_dw];
+
+	*ptr++ = SDMA_PKT_HEADER_OP(SDMA_OP_COPY) |
+		 SDMA_PKT_HEADER_SUB_OP(SDMA_SUBOP_COPY_LINEAR) |
+		 SDMA_PKT_COPY_LINEAR_HEADER_TMZ((copy_flags & AMDGPU_COPY_FLAGS_TMZ) ? 1 : 0);
+	*ptr++ = byte_count - 1;
+	*ptr++ = 0; /* src/dst endian swap */
+	*ptr++ = lower_32_bits(src_offset);
+	*ptr++ = upper_32_bits(src_offset);
+	*ptr++ = lower_32_bits(dst_offset);
+	*ptr++ = upper_32_bits(dst_offset);
+
+	ib->length_dw = ptr - ib->ptr;
 }
 
 /**
@@ -2290,11 +2308,15 @@ static void sdma_v4_4_2_emit_fill_buffer(struct amdgpu_ib *ib,
 				       uint64_t dst_offset,
 				       uint32_t byte_count)
 {
-	ib->ptr[ib->length_dw++] = SDMA_PKT_HEADER_OP(SDMA_OP_CONST_FILL);
-	ib->ptr[ib->length_dw++] = lower_32_bits(dst_offset);
-	ib->ptr[ib->length_dw++] = upper_32_bits(dst_offset);
-	ib->ptr[ib->length_dw++] = src_data;
-	ib->ptr[ib->length_dw++] = byte_count - 1;
+	u32 *ptr = &ib->ptr[ib->length_dw];
+
+	*ptr++ = SDMA_PKT_HEADER_OP(SDMA_OP_CONST_FILL);
+	*ptr++ = lower_32_bits(dst_offset);
+	*ptr++ = upper_32_bits(dst_offset);
+	*ptr++ = src_data;
+	*ptr++ = byte_count - 1;
+
+	ib->length_dw = ptr - ib->ptr;
 }
 
 static const struct amdgpu_buffer_funcs sdma_v4_4_2_buffer_funcs = {
Signature · 1 line
2.48.0
#13 lore raw

PATCH 13/16 drm/amdgpu: More compact SDMA 5.0 IB emission

In reply to Tvrtko Ursulin

Avoid constant register reloads while emitting IBs by using a local write pointer and only updating the size at the end of each helper.

---
 drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c | 106 +++++++++++++++----------
 1 file changed, 64 insertions(+), 42 deletions(-)
drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c +64 -42
index 7dc67a22a7a0..ab012592a276 100644
@@ -1155,16 +1155,19 @@ static void sdma_v5_0_vm_copy_pte(struct amdgpu_ib *ib,
 				  uint64_t pe, uint64_t src,
 				  unsigned count)
 {
+	u32 *ptr = &ib->ptr[ib->length_dw];
 	unsigned bytes = count * 8;
 
-	ib->ptr[ib->length_dw++] = SDMA_PKT_HEADER_OP(SDMA_OP_COPY) |
-		SDMA_PKT_HEADER_SUB_OP(SDMA_SUBOP_COPY_LINEAR);
-	ib->ptr[ib->length_dw++] = bytes - 1;
-	ib->ptr[ib->length_dw++] = 0; /* src/dst endian swap */
-	ib->ptr[ib->length_dw++] = lower_32_bits(src);
-	ib->ptr[ib->length_dw++] = upper_32_bits(src);
-	ib->ptr[ib->length_dw++] = lower_32_bits(pe);
-	ib->ptr[ib->length_dw++] = upper_32_bits(pe);
+	*ptr++ = SDMA_PKT_HEADER_OP(SDMA_OP_COPY) |
+		 SDMA_PKT_HEADER_SUB_OP(SDMA_SUBOP_COPY_LINEAR);
+	*ptr++ = bytes - 1;
+	*ptr++ = 0; /* src/dst endian swap */
+	*ptr++ = lower_32_bits(src);
+	*ptr++ = upper_32_bits(src);
+	*ptr++ = lower_32_bits(pe);
+	*ptr++ = upper_32_bits(pe);
+
+	ib->length_dw = ptr - ib->ptr;
 
 }
 
@@ -1183,18 +1186,21 @@ static void sdma_v5_0_vm_write_pte(struct amdgpu_ib *ib, uint64_t pe,
 				   uint64_t value, unsigned count,
 				   uint32_t incr)
 {
+	u32 *ptr = &ib->ptr[ib->length_dw];
 	unsigned ndw = count * 2;
 
-	ib->ptr[ib->length_dw++] = SDMA_PKT_HEADER_OP(SDMA_OP_WRITE) |
-		SDMA_PKT_HEADER_SUB_OP(SDMA_SUBOP_WRITE_LINEAR);
-	ib->ptr[ib->length_dw++] = lower_32_bits(pe);
-	ib->ptr[ib->length_dw++] = upper_32_bits(pe);
-	ib->ptr[ib->length_dw++] = ndw - 1;
+	*ptr++ = SDMA_PKT_HEADER_OP(SDMA_OP_WRITE) |
+		 SDMA_PKT_HEADER_SUB_OP(SDMA_SUBOP_WRITE_LINEAR);
+	*ptr++ = lower_32_bits(pe);
+	*ptr++ = upper_32_bits(pe);
+	*ptr++ = ndw - 1;
 	for (; ndw > 0; ndw -= 2) {
-		ib->ptr[ib->length_dw++] = lower_32_bits(value);
-		ib->ptr[ib->length_dw++] = upper_32_bits(value);
+		*ptr++ = lower_32_bits(value);
+		*ptr++ = upper_32_bits(value);
 		value += incr;
 	}
+
+	ib->length_dw = ptr - ib->ptr;
 }
 
 /**
@@ -1214,17 +1220,21 @@ static void sdma_v5_0_vm_set_pte_pde(struct amdgpu_ib *ib,
 				     uint64_t addr, unsigned count,
 				     uint32_t incr, uint64_t flags)
 {
+	u32 *ptr = &ib->ptr[ib->length_dw];
+
 	/* for physically contiguous pages (vram) */
-	ib->ptr[ib->length_dw++] = SDMA_PKT_HEADER_OP(SDMA_OP_PTEPDE);
-	ib->ptr[ib->length_dw++] = lower_32_bits(pe); /* dst addr */
-	ib->ptr[ib->length_dw++] = upper_32_bits(pe);
-	ib->ptr[ib->length_dw++] = lower_32_bits(flags); /* mask */
-	ib->ptr[ib->length_dw++] = upper_32_bits(flags);
-	ib->ptr[ib->length_dw++] = lower_32_bits(addr); /* value */
-	ib->ptr[ib->length_dw++] = upper_32_bits(addr);
-	ib->ptr[ib->length_dw++] = incr; /* increment size */
-	ib->ptr[ib->length_dw++] = 0;
-	ib->ptr[ib->length_dw++] = count - 1; /* number of entries */
+	*ptr++ = SDMA_PKT_HEADER_OP(SDMA_OP_PTEPDE);
+	*ptr++ = lower_32_bits(pe); /* dst addr */
+	*ptr++ = upper_32_bits(pe);
+	*ptr++ = lower_32_bits(flags); /* mask */
+	*ptr++ = upper_32_bits(flags);
+	*ptr++ = lower_32_bits(addr); /* value */
+	*ptr++ = upper_32_bits(addr);
+	*ptr++ = incr; /* increment size */
+	*ptr++ = 0;
+	*ptr++ = count - 1; /* number of entries */
+
+	ib->length_dw = ptr - ib->ptr;
 }
 
 /**
@@ -1237,18 +1247,22 @@ static void sdma_v5_0_vm_set_pte_pde(struct amdgpu_ib *ib,
 static void sdma_v5_0_ring_pad_ib(struct amdgpu_ring *ring, struct amdgpu_ib *ib)
 {
 	struct amdgpu_sdma_instance *sdma = amdgpu_sdma_get_instance_from_ring(ring);
+	u32 *ptr = &ib->ptr[ib->length_dw];
 	u32 pad_count;
 	int i;
 
 	pad_count = (-ib->length_dw) & 0x7;
+	if (!pad_count)
+		return;
+
 	for (i = 0; i < pad_count; i++)
 		if (sdma && sdma->burst_nop && (i == 0))
-			ib->ptr[ib->length_dw++] =
-				SDMA_PKT_HEADER_OP(SDMA_OP_NOP) |
-				SDMA_PKT_NOP_HEADER_COUNT(pad_count - 1);
+			*ptr++ = SDMA_PKT_HEADER_OP(SDMA_OP_NOP) |
+				 SDMA_PKT_NOP_HEADER_COUNT(pad_count - 1);
 		else
-			ib->ptr[ib->length_dw++] =
-				SDMA_PKT_HEADER_OP(SDMA_OP_NOP);
+			*ptr++ = SDMA_PKT_HEADER_OP(SDMA_OP_NOP);
+
+	ib->length_dw += pad_count;
 }
 
 
@@ -2021,15 +2035,19 @@ static void sdma_v5_0_emit_copy_buffer(struct amdgpu_ib *ib,
 				       uint32_t byte_count,
 				       uint32_t copy_flags)
 {
-	ib->ptr[ib->length_dw++] = SDMA_PKT_HEADER_OP(SDMA_OP_COPY) |
+	u32 *ptr = &ib->ptr[ib->length_dw];
+
+	*ptr++ = SDMA_PKT_HEADER_OP(SDMA_OP_COPY) |
 		SDMA_PKT_HEADER_SUB_OP(SDMA_SUBOP_COPY_LINEAR) |
 		SDMA_PKT_COPY_LINEAR_HEADER_TMZ((copy_flags & AMDGPU_COPY_FLAGS_TMZ) ? 1 : 0);
-	ib->ptr[ib->length_dw++] = byte_count - 1;
-	ib->ptr[ib->length_dw++] = 0; /* src/dst endian swap */
-	ib->ptr[ib->length_dw++] = lower_32_bits(src_offset);
-	ib->ptr[ib->length_dw++] = upper_32_bits(src_offset);
-	ib->ptr[ib->length_dw++] = lower_32_bits(dst_offset);
-	ib->ptr[ib->length_dw++] = upper_32_bits(dst_offset);
+	*ptr++ = byte_count - 1;
+	*ptr++ = 0; /* src/dst endian swap */
+	*ptr++ = lower_32_bits(src_offset);
+	*ptr++ = upper_32_bits(src_offset);
+	*ptr++ = lower_32_bits(dst_offset);
+	*ptr++ = upper_32_bits(dst_offset);
+
+	ib->length_dw = ptr - ib->ptr;
 }
 
 /**
@@ -2047,11 +2065,15 @@ static void sdma_v5_0_emit_fill_buffer(struct amdgpu_ib *ib,
 				       uint64_t dst_offset,
 				       uint32_t byte_count)
 {
-	ib->ptr[ib->length_dw++] = SDMA_PKT_HEADER_OP(SDMA_OP_CONST_FILL);
-	ib->ptr[ib->length_dw++] = lower_32_bits(dst_offset);
-	ib->ptr[ib->length_dw++] = upper_32_bits(dst_offset);
-	ib->ptr[ib->length_dw++] = src_data;
-	ib->ptr[ib->length_dw++] = byte_count - 1;
+	u32 *ptr = &ib->ptr[ib->length_dw];
+
+	*ptr++ = SDMA_PKT_HEADER_OP(SDMA_OP_CONST_FILL);
+	*ptr++ = lower_32_bits(dst_offset);
+	*ptr++ = upper_32_bits(dst_offset);
+	*ptr++ = src_data;
+	*ptr++ = byte_count - 1;
+
+	ib->length_dw = ptr - ib->ptr;
 }
 
 static const struct amdgpu_buffer_funcs sdma_v5_0_buffer_funcs = {
Signature · 1 line
2.48.0
#14 lore raw

PATCH 14/16 drm/amdgpu: More compact SDMA 5.2 IB emission

In reply to Tvrtko Ursulin

Avoid constant register reloads while emitting IBs by using a local write pointer and only updating the size at the end of each helper.

---
 drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c | 110 +++++++++++++++----------
 1 file changed, 66 insertions(+), 44 deletions(-)
drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c +66 -44
index 3bd44c24f692..75d87f20bc67 100644
@@ -1055,15 +1055,18 @@ static void sdma_v5_2_vm_copy_pte(struct amdgpu_ib *ib,
 				  unsigned count)
 {
 	unsigned bytes = count * 8;
+	u32 *ptr = &ib->ptr[ib->length_dw];
 
-	ib->ptr[ib->length_dw++] = SDMA_PKT_HEADER_OP(SDMA_OP_COPY) |
-		SDMA_PKT_HEADER_SUB_OP(SDMA_SUBOP_COPY_LINEAR);
-	ib->ptr[ib->length_dw++] = bytes - 1;
-	ib->ptr[ib->length_dw++] = 0; /* src/dst endian swap */
-	ib->ptr[ib->length_dw++] = lower_32_bits(src);
-	ib->ptr[ib->length_dw++] = upper_32_bits(src);
-	ib->ptr[ib->length_dw++] = lower_32_bits(pe);
-	ib->ptr[ib->length_dw++] = upper_32_bits(pe);
+	*ptr++ = SDMA_PKT_HEADER_OP(SDMA_OP_COPY) |
+		 SDMA_PKT_HEADER_SUB_OP(SDMA_SUBOP_COPY_LINEAR);
+	*ptr++ = bytes - 1;
+	*ptr++ = 0; /* src/dst endian swap */
+	*ptr++ = lower_32_bits(src);
+	*ptr++ = upper_32_bits(src);
+	*ptr++ = lower_32_bits(pe);
+	*ptr++ = upper_32_bits(pe);
+
+	ib->length_dw = ptr - ib->ptr;
 
 }
 
@@ -1083,17 +1086,20 @@ static void sdma_v5_2_vm_write_pte(struct amdgpu_ib *ib, uint64_t pe,
 				   uint32_t incr)
 {
 	unsigned ndw = count * 2;
+	u32 *ptr = &ib->ptr[ib->length_dw];
 
-	ib->ptr[ib->length_dw++] = SDMA_PKT_HEADER_OP(SDMA_OP_WRITE) |
-		SDMA_PKT_HEADER_SUB_OP(SDMA_SUBOP_WRITE_LINEAR);
-	ib->ptr[ib->length_dw++] = lower_32_bits(pe);
-	ib->ptr[ib->length_dw++] = upper_32_bits(pe);
-	ib->ptr[ib->length_dw++] = ndw - 1;
+	*ptr++ = SDMA_PKT_HEADER_OP(SDMA_OP_WRITE) |
+		 SDMA_PKT_HEADER_SUB_OP(SDMA_SUBOP_WRITE_LINEAR);
+	*ptr++ = lower_32_bits(pe);
+	*ptr++ = upper_32_bits(pe);
+	*ptr++ = ndw - 1;
 	for (; ndw > 0; ndw -= 2) {
-		ib->ptr[ib->length_dw++] = lower_32_bits(value);
-		ib->ptr[ib->length_dw++] = upper_32_bits(value);
+		*ptr++ = lower_32_bits(value);
+		*ptr++ = upper_32_bits(value);
 		value += incr;
 	}
+
+	ib->length_dw = ptr - ib->ptr;
 }
 
 /**
@@ -1113,17 +1119,21 @@ static void sdma_v5_2_vm_set_pte_pde(struct amdgpu_ib *ib,
 				     uint64_t addr, unsigned count,
 				     uint32_t incr, uint64_t flags)
 {
+	u32 *ptr = &ib->ptr[ib->length_dw];
+
 	/* for physically contiguous pages (vram) */
-	ib->ptr[ib->length_dw++] = SDMA_PKT_HEADER_OP(SDMA_OP_PTEPDE);
-	ib->ptr[ib->length_dw++] = lower_32_bits(pe); /* dst addr */
-	ib->ptr[ib->length_dw++] = upper_32_bits(pe);
-	ib->ptr[ib->length_dw++] = lower_32_bits(flags); /* mask */
-	ib->ptr[ib->length_dw++] = upper_32_bits(flags);
-	ib->ptr[ib->length_dw++] = lower_32_bits(addr); /* value */
-	ib->ptr[ib->length_dw++] = upper_32_bits(addr);
-	ib->ptr[ib->length_dw++] = incr; /* increment size */
-	ib->ptr[ib->length_dw++] = 0;
-	ib->ptr[ib->length_dw++] = count - 1; /* number of entries */
+	*ptr++ = SDMA_PKT_HEADER_OP(SDMA_OP_PTEPDE);
+	*ptr++ = lower_32_bits(pe); /* dst addr */
+	*ptr++ = upper_32_bits(pe);
+	*ptr++ = lower_32_bits(flags); /* mask */
+	*ptr++ = upper_32_bits(flags);
+	*ptr++ = lower_32_bits(addr); /* value */
+	*ptr++ = upper_32_bits(addr);
+	*ptr++ = incr; /* increment size */
+	*ptr++ = 0;
+	*ptr++ = count - 1; /* number of entries */
+
+	ib->length_dw = ptr - ib->ptr;
 }
 
 /**
@@ -1137,18 +1147,22 @@ static void sdma_v5_2_vm_set_pte_pde(struct amdgpu_ib *ib,
 static void sdma_v5_2_ring_pad_ib(struct amdgpu_ring *ring, struct amdgpu_ib *ib)
 {
 	struct amdgpu_sdma_instance *sdma = amdgpu_sdma_get_instance_from_ring(ring);
+	u32 *ptr = &ib->ptr[ib->length_dw];
 	u32 pad_count;
 	int i;
 
 	pad_count = (-ib->length_dw) & 0x7;
+	if (!pad_count)
+		return;
+
 	for (i = 0; i < pad_count; i++)
 		if (sdma && sdma->burst_nop && (i == 0))
-			ib->ptr[ib->length_dw++] =
-				SDMA_PKT_HEADER_OP(SDMA_OP_NOP) |
-				SDMA_PKT_NOP_HEADER_COUNT(pad_count - 1);
+			*ptr++ = SDMA_PKT_HEADER_OP(SDMA_OP_NOP) |
+				 SDMA_PKT_NOP_HEADER_COUNT(pad_count - 1);
 		else
-			ib->ptr[ib->length_dw++] =
-				SDMA_PKT_HEADER_OP(SDMA_OP_NOP);
+			*ptr++ = SDMA_PKT_HEADER_OP(SDMA_OP_NOP);
+
+	ib->length_dw += pad_count;
 }
 
 
@@ -2031,15 +2045,19 @@ static void sdma_v5_2_emit_copy_buffer(struct amdgpu_ib *ib,
 				       uint32_t byte_count,
 				       uint32_t copy_flags)
 {
-	ib->ptr[ib->length_dw++] = SDMA_PKT_HEADER_OP(SDMA_OP_COPY) |
-		SDMA_PKT_HEADER_SUB_OP(SDMA_SUBOP_COPY_LINEAR) |
-		SDMA_PKT_COPY_LINEAR_HEADER_TMZ((copy_flags & AMDGPU_COPY_FLAGS_TMZ) ? 1 : 0);
-	ib->ptr[ib->length_dw++] = byte_count - 1;
-	ib->ptr[ib->length_dw++] = 0; /* src/dst endian swap */
-	ib->ptr[ib->length_dw++] = lower_32_bits(src_offset);
-	ib->ptr[ib->length_dw++] = upper_32_bits(src_offset);
-	ib->ptr[ib->length_dw++] = lower_32_bits(dst_offset);
-	ib->ptr[ib->length_dw++] = upper_32_bits(dst_offset);
+	u32 *ptr = &ib->ptr[ib->length_dw];
+
+	*ptr++ = SDMA_PKT_HEADER_OP(SDMA_OP_COPY) |
+		 SDMA_PKT_HEADER_SUB_OP(SDMA_SUBOP_COPY_LINEAR) |
+		 SDMA_PKT_COPY_LINEAR_HEADER_TMZ((copy_flags & AMDGPU_COPY_FLAGS_TMZ) ? 1 : 0);
+	*ptr++ = byte_count - 1;
+	*ptr++ = 0; /* src/dst endian swap */
+	*ptr++ = lower_32_bits(src_offset);
+	*ptr++ = upper_32_bits(src_offset);
+	*ptr++ = lower_32_bits(dst_offset);
+	*ptr++ = upper_32_bits(dst_offset);
+
+	ib->length_dw = ptr - ib->ptr;
 }
 
 /**
@@ -2057,11 +2075,15 @@ static void sdma_v5_2_emit_fill_buffer(struct amdgpu_ib *ib,
 				       uint64_t dst_offset,
 				       uint32_t byte_count)
 {
-	ib->ptr[ib->length_dw++] = SDMA_PKT_HEADER_OP(SDMA_OP_CONST_FILL);
-	ib->ptr[ib->length_dw++] = lower_32_bits(dst_offset);
-	ib->ptr[ib->length_dw++] = upper_32_bits(dst_offset);
-	ib->ptr[ib->length_dw++] = src_data;
-	ib->ptr[ib->length_dw++] = byte_count - 1;
+	u32 *ptr = &ib->ptr[ib->length_dw];
+
+	*ptr++ = SDMA_PKT_HEADER_OP(SDMA_OP_CONST_FILL);
+	*ptr++ = lower_32_bits(dst_offset);
+	*ptr++ = upper_32_bits(dst_offset);
+	*ptr++ = src_data;
+	*ptr++ = byte_count - 1;
+
+	ib->length_dw = ptr - ib->ptr;
 }
 
 static const struct amdgpu_buffer_funcs sdma_v5_2_buffer_funcs = {
Signature · 1 line
2.48.0
#15 lore raw

PATCH 15/16 drm/amdgpu: More compact SDMA 6.0 IB emission

In reply to Tvrtko Ursulin

Avoid constant register reloads while emitting IBs by using a local write pointer and only updating the size at the end of each helper.

---
 drivers/gpu/drm/amd/amdgpu/sdma_v6_0.c | 110 +++++++++++++++----------
 1 file changed, 66 insertions(+), 44 deletions(-)
drivers/gpu/drm/amd/amdgpu/sdma_v6_0.c +66 -44
index db6e41967f12..94062354c40f 100644
@@ -1060,16 +1060,19 @@ static void sdma_v6_0_vm_copy_pte(struct amdgpu_ib *ib,
 				  uint64_t pe, uint64_t src,
 				  unsigned count)
 {
+	u32 *ptr = &ib->ptr[ib->length_dw];
 	unsigned bytes = count * 8;
 
-	ib->ptr[ib->length_dw++] = SDMA_PKT_COPY_LINEAR_HEADER_OP(SDMA_OP_COPY) |
-		SDMA_PKT_COPY_LINEAR_HEADER_SUB_OP(SDMA_SUBOP_COPY_LINEAR);
-	ib->ptr[ib->length_dw++] = bytes - 1;
-	ib->ptr[ib->length_dw++] = 0; /* src/dst endian swap */
-	ib->ptr[ib->length_dw++] = lower_32_bits(src);
-	ib->ptr[ib->length_dw++] = upper_32_bits(src);
-	ib->ptr[ib->length_dw++] = lower_32_bits(pe);
-	ib->ptr[ib->length_dw++] = upper_32_bits(pe);
+	*ptr++ = SDMA_PKT_COPY_LINEAR_HEADER_OP(SDMA_OP_COPY) |
+		 SDMA_PKT_COPY_LINEAR_HEADER_SUB_OP(SDMA_SUBOP_COPY_LINEAR);
+	*ptr++ = bytes - 1;
+	*ptr++ = 0; /* src/dst endian swap */
+	*ptr++ = lower_32_bits(src);
+	*ptr++ = upper_32_bits(src);
+	*ptr++ = lower_32_bits(pe);
+	*ptr++ = upper_32_bits(pe);
+
+	ib->length_dw = ptr - ib->ptr;
 
 }
 
@@ -1088,18 +1091,21 @@ static void sdma_v6_0_vm_write_pte(struct amdgpu_ib *ib, uint64_t pe,
 				   uint64_t value, unsigned count,
 				   uint32_t incr)
 {
+	u32 *ptr = &ib->ptr[ib->length_dw];
 	unsigned ndw = count * 2;
 
-	ib->ptr[ib->length_dw++] = SDMA_PKT_COPY_LINEAR_HEADER_OP(SDMA_OP_WRITE) |
-		SDMA_PKT_COPY_LINEAR_HEADER_SUB_OP(SDMA_SUBOP_WRITE_LINEAR);
-	ib->ptr[ib->length_dw++] = lower_32_bits(pe);
-	ib->ptr[ib->length_dw++] = upper_32_bits(pe);
-	ib->ptr[ib->length_dw++] = ndw - 1;
+	*ptr++ = SDMA_PKT_COPY_LINEAR_HEADER_OP(SDMA_OP_WRITE) |
+		 SDMA_PKT_COPY_LINEAR_HEADER_SUB_OP(SDMA_SUBOP_WRITE_LINEAR);
+	*ptr++ = lower_32_bits(pe);
+	*ptr++ = upper_32_bits(pe);
+	*ptr++ = ndw - 1;
 	for (; ndw > 0; ndw -= 2) {
-		ib->ptr[ib->length_dw++] = lower_32_bits(value);
-		ib->ptr[ib->length_dw++] = upper_32_bits(value);
+		*ptr++ = lower_32_bits(value);
+		*ptr++ = upper_32_bits(value);
 		value += incr;
 	}
+
+	ib->length_dw = ptr - ib->ptr;
 }
 
 /**
@@ -1119,17 +1125,21 @@ static void sdma_v6_0_vm_set_pte_pde(struct amdgpu_ib *ib,
 				     uint64_t addr, unsigned count,
 				     uint32_t incr, uint64_t flags)
 {
+	u32 *ptr = &ib->ptr[ib->length_dw];
+
 	/* for physically contiguous pages (vram) */
-	ib->ptr[ib->length_dw++] = SDMA_PKT_COPY_LINEAR_HEADER_OP(SDMA_OP_PTEPDE);
-	ib->ptr[ib->length_dw++] = lower_32_bits(pe); /* dst addr */
-	ib->ptr[ib->length_dw++] = upper_32_bits(pe);
-	ib->ptr[ib->length_dw++] = lower_32_bits(flags); /* mask */
-	ib->ptr[ib->length_dw++] = upper_32_bits(flags);
-	ib->ptr[ib->length_dw++] = lower_32_bits(addr); /* value */
-	ib->ptr[ib->length_dw++] = upper_32_bits(addr);
-	ib->ptr[ib->length_dw++] = incr; /* increment size */
-	ib->ptr[ib->length_dw++] = 0;
-	ib->ptr[ib->length_dw++] = count - 1; /* number of entries */
+	*ptr++ = SDMA_PKT_COPY_LINEAR_HEADER_OP(SDMA_OP_PTEPDE);
+	*ptr++ = lower_32_bits(pe); /* dst addr */
+	*ptr++ = upper_32_bits(pe);
+	*ptr++ = lower_32_bits(flags); /* mask */
+	*ptr++ = upper_32_bits(flags);
+	*ptr++ = lower_32_bits(addr); /* value */
+	*ptr++ = upper_32_bits(addr);
+	*ptr++ = incr; /* increment size */
+	*ptr++ = 0;
+	*ptr++ = count - 1; /* number of entries */
+
+	ib->length_dw = ptr - ib->ptr;
 }
 
 /*
@@ -1142,18 +1152,22 @@ static void sdma_v6_0_vm_set_pte_pde(struct amdgpu_ib *ib,
 static void sdma_v6_0_ring_pad_ib(struct amdgpu_ring *ring, struct amdgpu_ib *ib)
 {
 	struct amdgpu_sdma_instance *sdma = amdgpu_sdma_get_instance_from_ring(ring);
+	u32 *ptr = &ib->ptr[ib->length_dw];
 	u32 pad_count;
 	int i;
 
 	pad_count = (-ib->length_dw) & 0x7;
+	if (!pad_count)
+		return;
+
 	for (i = 0; i < pad_count; i++)
 		if (sdma && sdma->burst_nop && (i == 0))
-			ib->ptr[ib->length_dw++] =
-				SDMA_PKT_COPY_LINEAR_HEADER_OP(SDMA_OP_NOP) |
-				SDMA_PKT_NOP_HEADER_COUNT(pad_count - 1);
+			*ptr++ = SDMA_PKT_COPY_LINEAR_HEADER_OP(SDMA_OP_NOP) |
+				 SDMA_PKT_NOP_HEADER_COUNT(pad_count - 1);
 		else
-			ib->ptr[ib->length_dw++] =
-				SDMA_PKT_COPY_LINEAR_HEADER_OP(SDMA_OP_NOP);
+			*ptr++ = SDMA_PKT_COPY_LINEAR_HEADER_OP(SDMA_OP_NOP);
+
+	ib->length_dw += pad_count;
 }
 
 /**
@@ -1839,15 +1853,19 @@ static void sdma_v6_0_emit_copy_buffer(struct amdgpu_ib *ib,
 				       uint32_t byte_count,
 				       uint32_t copy_flags)
 {
-	ib->ptr[ib->length_dw++] = SDMA_PKT_COPY_LINEAR_HEADER_OP(SDMA_OP_COPY) |
-		SDMA_PKT_COPY_LINEAR_HEADER_SUB_OP(SDMA_SUBOP_COPY_LINEAR) |
-		SDMA_PKT_COPY_LINEAR_HEADER_TMZ((copy_flags & AMDGPU_COPY_FLAGS_TMZ) ? 1 : 0);
-	ib->ptr[ib->length_dw++] = byte_count - 1;
-	ib->ptr[ib->length_dw++] = 0; /* src/dst endian swap */
-	ib->ptr[ib->length_dw++] = lower_32_bits(src_offset);
-	ib->ptr[ib->length_dw++] = upper_32_bits(src_offset);
-	ib->ptr[ib->length_dw++] = lower_32_bits(dst_offset);
-	ib->ptr[ib->length_dw++] = upper_32_bits(dst_offset);
+	u32 *ptr = &ib->ptr[ib->length_dw];
+
+	*ptr++ = SDMA_PKT_COPY_LINEAR_HEADER_OP(SDMA_OP_COPY) |
+		 SDMA_PKT_COPY_LINEAR_HEADER_SUB_OP(SDMA_SUBOP_COPY_LINEAR) |
+		 SDMA_PKT_COPY_LINEAR_HEADER_TMZ((copy_flags & AMDGPU_COPY_FLAGS_TMZ) ? 1 : 0);
+	*ptr++ = byte_count - 1;
+	*ptr++ = 0; /* src/dst endian swap */
+	*ptr++ = lower_32_bits(src_offset);
+	*ptr++ = upper_32_bits(src_offset);
+	*ptr++ = lower_32_bits(dst_offset);
+	*ptr++ = upper_32_bits(dst_offset);
+
+	ib->length_dw = ptr - ib->ptr;
 }
 
 /**
@@ -1865,11 +1883,15 @@ static void sdma_v6_0_emit_fill_buffer(struct amdgpu_ib *ib,
 				       uint64_t dst_offset,
 				       uint32_t byte_count)
 {
-	ib->ptr[ib->length_dw++] = SDMA_PKT_CONSTANT_FILL_HEADER_OP(SDMA_OP_CONST_FILL);
-	ib->ptr[ib->length_dw++] = lower_32_bits(dst_offset);
-	ib->ptr[ib->length_dw++] = upper_32_bits(dst_offset);
-	ib->ptr[ib->length_dw++] = src_data;
-	ib->ptr[ib->length_dw++] = byte_count - 1;
+	u32 *ptr = &ib->ptr[ib->length_dw];
+
+	*ptr++ = SDMA_PKT_CONSTANT_FILL_HEADER_OP(SDMA_OP_CONST_FILL);
+	*ptr++ = lower_32_bits(dst_offset);
+	*ptr++ = upper_32_bits(dst_offset);
+	*ptr++ = src_data;
+	*ptr++ = byte_count - 1;
+
+	ib->length_dw = ptr - ib->ptr;
 }
 
 static const struct amdgpu_buffer_funcs sdma_v6_0_buffer_funcs = {
Signature · 1 line
2.48.0
#16 lore raw

PATCH 16/16 drm/amdgpu: More compact SDMA 7.0 IB emission

In reply to Tvrtko Ursulin

Avoid constant register reloads while emitting IBs by using a local write pointer and only updating the size at the end of each helper.

---
 drivers/gpu/drm/amd/amdgpu/sdma_v7_0.c | 119 +++++++++++++++----------
 1 file changed, 70 insertions(+), 49 deletions(-)
drivers/gpu/drm/amd/amdgpu/sdma_v7_0.c +70 -49
index 326ecc8d37d2..f8e1e5a7835f 100644
@@ -1077,19 +1077,22 @@ static void sdma_v7_0_vm_copy_pte(struct amdgpu_ib *ib,
 				  uint64_t pe, uint64_t src,
 				  unsigned count)
 {
+	u32 *ptr = &ib->ptr[ib->length_dw];
 	unsigned bytes = count * 8;
 
-	ib->ptr[ib->length_dw++] = SDMA_PKT_COPY_LINEAR_HEADER_OP(SDMA_OP_COPY) |
-		SDMA_PKT_COPY_LINEAR_HEADER_SUB_OP(SDMA_SUBOP_COPY_LINEAR) |
-		SDMA_PKT_COPY_LINEAR_HEADER_CPV(1);
+	*ptr++ = SDMA_PKT_COPY_LINEAR_HEADER_OP(SDMA_OP_COPY) |
+		 SDMA_PKT_COPY_LINEAR_HEADER_SUB_OP(SDMA_SUBOP_COPY_LINEAR) |
+		 SDMA_PKT_COPY_LINEAR_HEADER_CPV(1);
 
-	ib->ptr[ib->length_dw++] = bytes - 1;
-	ib->ptr[ib->length_dw++] = 0; /* src/dst endian swap */
-	ib->ptr[ib->length_dw++] = lower_32_bits(src);
-	ib->ptr[ib->length_dw++] = upper_32_bits(src);
-	ib->ptr[ib->length_dw++] = lower_32_bits(pe);
-	ib->ptr[ib->length_dw++] = upper_32_bits(pe);
-	ib->ptr[ib->length_dw++] = 0;
+	*ptr++ = bytes - 1;
+	*ptr++ = 0; /* src/dst endian swap */
+	*ptr++ = lower_32_bits(src);
+	*ptr++ = upper_32_bits(src);
+	*ptr++ = lower_32_bits(pe);
+	*ptr++ = upper_32_bits(pe);
+	*ptr++ = 0;
+
+	ib->length_dw = ptr - ib->ptr;
 
 }
 
@@ -1108,18 +1111,21 @@ static void sdma_v7_0_vm_write_pte(struct amdgpu_ib *ib, uint64_t pe,
 				   uint64_t value, unsigned count,
 				   uint32_t incr)
 {
+	u32 *ptr = &ib->ptr[ib->length_dw];
 	unsigned ndw = count * 2;
 
-	ib->ptr[ib->length_dw++] = SDMA_PKT_COPY_LINEAR_HEADER_OP(SDMA_OP_WRITE) |
-		SDMA_PKT_COPY_LINEAR_HEADER_SUB_OP(SDMA_SUBOP_WRITE_LINEAR);
-	ib->ptr[ib->length_dw++] = lower_32_bits(pe);
-	ib->ptr[ib->length_dw++] = upper_32_bits(pe);
-	ib->ptr[ib->length_dw++] = ndw - 1;
+	*ptr++ = SDMA_PKT_COPY_LINEAR_HEADER_OP(SDMA_OP_WRITE) |
+		 SDMA_PKT_COPY_LINEAR_HEADER_SUB_OP(SDMA_SUBOP_WRITE_LINEAR);
+	*ptr++ = lower_32_bits(pe);
+	*ptr++ = upper_32_bits(pe);
+	*ptr++ = ndw - 1;
 	for (; ndw > 0; ndw -= 2) {
-		ib->ptr[ib->length_dw++] = lower_32_bits(value);
-		ib->ptr[ib->length_dw++] = upper_32_bits(value);
+		*ptr++ = lower_32_bits(value);
+		*ptr++ = upper_32_bits(value);
 		value += incr;
 	}
+
+	ib->length_dw = ptr - ib->ptr;
 }
 
 /**
@@ -1139,17 +1145,21 @@ static void sdma_v7_0_vm_set_pte_pde(struct amdgpu_ib *ib,
 				     uint64_t addr, unsigned count,
 				     uint32_t incr, uint64_t flags)
 {
+	u32 *ptr = &ib->ptr[ib->length_dw];
+
 	/* for physically contiguous pages (vram) */
-	ib->ptr[ib->length_dw++] = SDMA_PKT_COPY_LINEAR_HEADER_OP(SDMA_OP_PTEPDE);
-	ib->ptr[ib->length_dw++] = lower_32_bits(pe); /* dst addr */
-	ib->ptr[ib->length_dw++] = upper_32_bits(pe);
-	ib->ptr[ib->length_dw++] = lower_32_bits(flags); /* mask */
-	ib->ptr[ib->length_dw++] = upper_32_bits(flags);
-	ib->ptr[ib->length_dw++] = lower_32_bits(addr); /* value */
-	ib->ptr[ib->length_dw++] = upper_32_bits(addr);
-	ib->ptr[ib->length_dw++] = incr; /* increment size */
-	ib->ptr[ib->length_dw++] = 0;
-	ib->ptr[ib->length_dw++] = count - 1; /* number of entries */
+	*ptr++ = SDMA_PKT_COPY_LINEAR_HEADER_OP(SDMA_OP_PTEPDE);
+	*ptr++ = lower_32_bits(pe); /* dst addr */
+	*ptr++ = upper_32_bits(pe);
+	*ptr++ = lower_32_bits(flags); /* mask */
+	*ptr++ = upper_32_bits(flags);
+	*ptr++ = lower_32_bits(addr); /* value */
+	*ptr++ = upper_32_bits(addr);
+	*ptr++ = incr; /* increment size */
+	*ptr++ = 0;
+	*ptr++ = count - 1; /* number of entries */
+
+	ib->length_dw = ptr - ib->ptr;
 }
 
 /**
@@ -1163,18 +1173,22 @@ static void sdma_v7_0_vm_set_pte_pde(struct amdgpu_ib *ib,
 static void sdma_v7_0_ring_pad_ib(struct amdgpu_ring *ring, struct amdgpu_ib *ib)
 {
 	struct amdgpu_sdma_instance *sdma = amdgpu_sdma_get_instance_from_ring(ring);
+	u32 *ptr = &ib->ptr[ib->length_dw];
 	u32 pad_count;
 	int i;
 
 	pad_count = (-ib->length_dw) & 0x7;
+	if (!pad_count)
+		return;
+
 	for (i = 0; i < pad_count; i++)
 		if (sdma && sdma->burst_nop && (i == 0))
-			ib->ptr[ib->length_dw++] =
-				SDMA_PKT_COPY_LINEAR_HEADER_OP(SDMA_OP_NOP) |
+			*ptr++= SDMA_PKT_COPY_LINEAR_HEADER_OP(SDMA_OP_NOP) |
 				SDMA_PKT_NOP_HEADER_COUNT(pad_count - 1);
 		else
-			ib->ptr[ib->length_dw++] =
-				SDMA_PKT_COPY_LINEAR_HEADER_OP(SDMA_OP_NOP);
+			*ptr++ = SDMA_PKT_COPY_LINEAR_HEADER_OP(SDMA_OP_NOP);
+
+	ib->length_dw += pad_count;
 }
 
 /**
@@ -1765,31 +1779,34 @@ static void sdma_v7_0_emit_copy_buffer(struct amdgpu_ib *ib,
 				       uint32_t copy_flags)
 {
 	uint32_t num_type, data_format, max_com, write_cm;
+	u32 *ptr = &ib->ptr[ib->length_dw];
 
 	max_com = AMDGPU_COPY_FLAGS_GET(copy_flags, MAX_COMPRESSED);
 	data_format = AMDGPU_COPY_FLAGS_GET(copy_flags, DATA_FORMAT);
 	num_type = AMDGPU_COPY_FLAGS_GET(copy_flags, NUMBER_TYPE);
 	write_cm = AMDGPU_COPY_FLAGS_GET(copy_flags, WRITE_COMPRESS_DISABLE) ? 2 : 1;
 
-	ib->ptr[ib->length_dw++] = SDMA_PKT_COPY_LINEAR_HEADER_OP(SDMA_OP_COPY) |
-		SDMA_PKT_COPY_LINEAR_HEADER_SUB_OP(SDMA_SUBOP_COPY_LINEAR) |
-		SDMA_PKT_COPY_LINEAR_HEADER_TMZ((copy_flags & AMDGPU_COPY_FLAGS_TMZ) ? 1 : 0) |
-		SDMA_PKT_COPY_LINEAR_HEADER_CPV(1);
+	*ptr++ = SDMA_PKT_COPY_LINEAR_HEADER_OP(SDMA_OP_COPY) |
+		 SDMA_PKT_COPY_LINEAR_HEADER_SUB_OP(SDMA_SUBOP_COPY_LINEAR) |
+		 SDMA_PKT_COPY_LINEAR_HEADER_TMZ((copy_flags & AMDGPU_COPY_FLAGS_TMZ) ? 1 : 0) |
+		 SDMA_PKT_COPY_LINEAR_HEADER_CPV(1);
 
-	ib->ptr[ib->length_dw++] = byte_count - 1;
-	ib->ptr[ib->length_dw++] = 0; /* src/dst endian swap */
-	ib->ptr[ib->length_dw++] = lower_32_bits(src_offset);
-	ib->ptr[ib->length_dw++] = upper_32_bits(src_offset);
-	ib->ptr[ib->length_dw++] = lower_32_bits(dst_offset);
-	ib->ptr[ib->length_dw++] = upper_32_bits(dst_offset);
+	*ptr++ = byte_count - 1;
+	*ptr++ = 0; /* src/dst endian swap */
+	*ptr++ = lower_32_bits(src_offset);
+	*ptr++ = upper_32_bits(src_offset);
+	*ptr++ = lower_32_bits(dst_offset);
+	*ptr++ = upper_32_bits(dst_offset);
 
 	if ((copy_flags & (AMDGPU_COPY_FLAGS_READ_DECOMPRESSED | AMDGPU_COPY_FLAGS_WRITE_COMPRESSED)))
-		ib->ptr[ib->length_dw++] = SDMA_DCC_DATA_FORMAT(data_format) | SDMA_DCC_NUM_TYPE(num_type) |
+		*ptr++ = SDMA_DCC_DATA_FORMAT(data_format) | SDMA_DCC_NUM_TYPE(num_type) |
 			((copy_flags & AMDGPU_COPY_FLAGS_READ_DECOMPRESSED) ? SDMA_DCC_READ_CM(2) : 0) |
 			((copy_flags & AMDGPU_COPY_FLAGS_WRITE_COMPRESSED) ? SDMA_DCC_WRITE_CM(write_cm) : 0) |
 			SDMA_DCC_MAX_COM(max_com) | SDMA_DCC_MAX_UCOM(1);
 	else
-		ib->ptr[ib->length_dw++] = 0;
+		*ptr++ = 0;
+
+	ib->length_dw = ptr - ib->ptr;
 }
 
 /**
@@ -1807,12 +1824,16 @@ static void sdma_v7_0_emit_fill_buffer(struct amdgpu_ib *ib,
 				       uint64_t dst_offset,
 				       uint32_t byte_count)
 {
-	ib->ptr[ib->length_dw++] = SDMA_PKT_CONSTANT_FILL_HEADER_OP(SDMA_OP_CONST_FILL) |
-		SDMA_PKT_CONSTANT_FILL_HEADER_COMPRESS(1);
-	ib->ptr[ib->length_dw++] = lower_32_bits(dst_offset);
-	ib->ptr[ib->length_dw++] = upper_32_bits(dst_offset);
-	ib->ptr[ib->length_dw++] = src_data;
-	ib->ptr[ib->length_dw++] = byte_count - 1;
+	u32 *ptr = &ib->ptr[ib->length_dw];
+
+	*ptr++ = SDMA_PKT_CONSTANT_FILL_HEADER_OP(SDMA_OP_CONST_FILL) |
+		 SDMA_PKT_CONSTANT_FILL_HEADER_COMPRESS(1);
+	*ptr++ = lower_32_bits(dst_offset);
+	*ptr++ = upper_32_bits(dst_offset);
+	*ptr++ = src_data;
+	*ptr++ = byte_count - 1;
+
+	ib->length_dw = ptr - ib->ptr;
 }
 
 static const struct amdgpu_buffer_funcs sdma_v7_0_buffer_funcs = {
Signature · 1 line
2.48.0
Applied
#17 lore raw
In reply to Tvrtko Ursulin

Applied the series. Thanks!

Alex

Quoted 151 lines · Tvrtko Ursulin

In short, this series mostly does a lot of replacing of this pattern:

       ib->ptr[ib->length_dw++] = SDMA_PKT_HEADER_OP(SDMA_OP_WRITE) |
               SDMA_PKT_HEADER_SUB_OP(SDMA_SUBOP_WRITE_LINEAR);
       ib->ptr[ib->length_dw++] = lower_32_bits(pe);
       ib->ptr[ib->length_dw++] = upper_32_bits(pe);
       ib->ptr[ib->length_dw++] = ndw - 1;
       for (; ndw > 0; ndw -= 2) {
              ib->ptr[ib->length_dw++] = lower_32_bits(value);
              ib->ptr[ib->length_dw++] = upper_32_bits(value);
               value += incr;
       }

With this one:

       u32 *ptr = &ib->ptr[ib->length_dw];

       *ptr++ = SDMA_PKT_HEADER_OP(SDMA_OP_WRITE) |
                SDMA_PKT_HEADER_SUB_OP(SDMA_SUBOP_WRITE_LINEAR);
       *ptr++ = lower_32_bits(pe);
       *ptr++ = upper_32_bits(pe);
       *ptr++ = ndw - 1;
       for (; ndw > 0; ndw -= 2) {
               *ptr++ = lower_32_bits(value);
               *ptr++ = upper_32_bits(value);
                value += incr;
        }

       ib->length_dw = ptr - ib->ptr;

Latter avoids register reloads and length updates on every dword written, and on the overall makes the IB emission much more compact:

add/remove: 0/1 grow/shrink: 10/58 up/down: 260/-6598 (-6338)

Function                                     old     new   delta
sdma_v7_0_ring_pad_ib                         99     127     +28
sdma_v6_0_ring_pad_ib                         99     127     +28
sdma_v5_2_ring_pad_ib                         99     127     +28
sdma_v5_0_ring_pad_ib                         99     127     +28
sdma_v4_4_2_ring_pad_ib                       99     127     +28
sdma_v4_0_ring_pad_ib                         99     127     +28
sdma_v3_0_ring_pad_ib                         99     127     +28
sdma_v2_4_ring_pad_ib                         99     127     +28
cik_sdma_ring_pad_ib                          99     127     +28
si_dma_ring_pad_ib                            36      44      +8
amdgpu_ring_generic_pad_ib                    56      52      -4
si_dma_emit_fill_buffer                      108      71     -37
si_dma_vm_write_pte                          158     115     -43
amdgpu_vcn_dec_sw_send_msg                   810     767     -43
si_dma_vm_copy_pte                           137      87     -50
si_dma_emit_copy_buffer                      134      84     -50
sdma_v3_0_vm_write_pte                       163     102     -61
sdma_v2_4_vm_write_pte                       163     102     -61
cik_sdma_vm_write_pte                        163     102     -61
sdma_v7_0_vm_write_pte                       168     105     -63
sdma_v7_0_emit_fill_buffer                   119      56     -63
sdma_v6_0_vm_write_pte                       168     105     -63
sdma_v6_0_emit_fill_buffer                   119      56     -63
sdma_v5_2_vm_write_pte                       168     105     -63
sdma_v5_2_emit_fill_buffer                   119      56     -63
sdma_v5_0_vm_write_pte                       168     105     -63
sdma_v5_0_emit_fill_buffer                   119      56     -63
sdma_v4_4_2_vm_write_pte                     168     105     -63
sdma_v4_4_2_emit_fill_buffer                 119      56     -63
sdma_v4_0_vm_write_pte                       168     105     -63
sdma_v4_0_emit_fill_buffer                   119      56     -63
sdma_v3_0_emit_fill_buffer                   116      53     -63
sdma_v2_4_emit_fill_buffer                   116      53     -63
cik_sdma_emit_fill_buffer                    116      53     -63
sdma_v6_0_emit_copy_buffer                   169      76     -93
sdma_v5_2_emit_copy_buffer                   169      76     -93
sdma_v5_0_emit_copy_buffer                   169      76     -93
sdma_v4_4_2_emit_copy_buffer                 169      76     -93
sdma_v4_0_emit_copy_buffer                   169      76     -93
sdma_v3_0_vm_copy_pte                        158      64     -94
sdma_v3_0_emit_copy_buffer                   155      61     -94
sdma_v2_4_vm_copy_pte                        158      64     -94
sdma_v2_4_emit_copy_buffer                   155      61     -94
cik_sdma_vm_copy_pte                         158      64     -94
cik_sdma_emit_copy_buffer                    155      61     -94
sdma_v6_0_vm_copy_pte                        163      68     -95
sdma_v5_2_vm_copy_pte                        163      68     -95
sdma_v5_0_vm_copy_pte                        163      68     -95
sdma_v4_4_2_vm_copy_pte                      163      68     -95
sdma_v4_0_vm_copy_pte                        163      68     -95
sdma_v7_0_vm_copy_pte                        183      75    -108
sdma_v7_0_emit_copy_buffer                   317     202    -115
si_dma_vm_set_pte_pde                        338     214    -124
amdgpu_vce_get_destroy_msg                   784     652    -132
sdma_v7_0_vm_set_pte_pde                     218      72    -146
sdma_v6_0_vm_set_pte_pde                     218      72    -146
sdma_v5_2_vm_set_pte_pde                     218      72    -146
sdma_v5_0_vm_set_pte_pde                     218      72    -146
sdma_v4_4_2_vm_set_pte_pde                   218      72    -146
sdma_v4_0_vm_set_pte_pde                     218      72    -146
sdma_v3_0_vm_set_pte_pde                     215      69    -146
sdma_v2_4_vm_set_pte_pde                     215      69    -146
cik_sdma_vm_set_pte_pde                      215      69    -146
amdgpu_vcn_unified_ring_ib_header            172       -    -172
gfx_v9_4_2_run_shader.constprop              739     532    -207
uvd_v6_0_enc_ring_test_ib                   1464    1162    -302
uvd_v7_0_enc_ring_test_ib                   1464    1138    -326
amdgpu_vce_ring_test_ib                     1357     936    -421
amdgpu_vcn_enc_ring_test_ib                 2042    1524    -518

Total: Before=9262623, After=9256285, chg -0.07%

* Notice how _pad_ib functions have grown. I think the compiler used the opportunity to unroll the loops.

** Series was only smoke tested on the Steam Deck.

Tvrtko Ursulin (16):
drm/amdgpu: Use memset32 for IB padding
drm/amdgpu: More compact VCE IB emission
drm/amdgpu: More compact VCN IB emission
drm/amdgpu: More compact UVD 6 IB emission
drm/amdgpu: More compact UVD 7 IB emission
drm/amdgpu: More compact SI SDMA emission
drm/amdgpu: More compact CIK SDMA IB emission
drm/amdgpu: More compact GFX 9.4.2 IB emission
drm/amdgpu: More compact SDMA 2.4 IB emission
drm/amdgpu: More compact SDMA 3.0 IB emission
drm/amdgpu: More compact SDMA 4.0 IB emission
drm/amdgpu: More compact SDMA 4.4.2 IB emission
drm/amdgpu: More compact SDMA 5.0 IB emission
drm/amdgpu: More compact SDMA 5.2 IB emission
drm/amdgpu: More compact SDMA 6.0 IB emission
drm/amdgpu: More compact SDMA 7.0 IB emission

 drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c |  12 ++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c  |  90 +++++++++--------
 drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c  | 101 ++++++++++---------
 drivers/gpu/drm/amd/amdgpu/cik_sdma.c    | 105 ++++++++++++--------
 drivers/gpu/drm/amd/amdgpu/gfx_v9_4_2.c  |  46 ++++-----
 drivers/gpu/drm/amd/amdgpu/sdma_v2_4.c   | 108 ++++++++++++--------
 drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c   | 108 ++++++++++++--------
 drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c   | 109 ++++++++++++---------
 drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c | 108 ++++++++++++--------
 drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c   | 106 ++++++++++++--------
 drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c   | 110 ++++++++++++---------
 drivers/gpu/drm/amd/amdgpu/sdma_v6_0.c   | 110 ++++++++++++---------
 drivers/gpu/drm/amd/amdgpu/sdma_v7_0.c   | 119 +++++++++++++----------
 drivers/gpu/drm/amd/amdgpu/si_dma.c      |  84 +++++++++-------
 drivers/gpu/drm/amd/amdgpu/uvd_v6_0.c    |  66 +++++++------
 drivers/gpu/drm/amd/amdgpu/uvd_v7_0.c    |  66 +++++++------
 16 files changed, 849 insertions(+), 599 deletions(-)

--
2.48.0

#18 lore raw
Quoted 1 line · Alex Deucher

Applied the series. Thanks!

Thank you and fingers crossed I did not fat finger anything that your CI wouldn't find!

I wish something similar could be done for amdgpu_ring_write too, but that one is waiting on Christian to, AFAIR, become idle enough to untangle some ptr masking issues.

Regards,

Tvrtko

Quoted 153 lines
Quoted 151 lines · Tvrtko Ursulin

In short, this series mostly does a lot of replacing of this pattern:

        ib->ptr[ib->length_dw++] = SDMA_PKT_HEADER_OP(SDMA_OP_WRITE) |
                SDMA_PKT_HEADER_SUB_OP(SDMA_SUBOP_WRITE_LINEAR);
        ib->ptr[ib->length_dw++] = lower_32_bits(pe);
        ib->ptr[ib->length_dw++] = upper_32_bits(pe);
        ib->ptr[ib->length_dw++] = ndw - 1;
        for (; ndw > 0; ndw -= 2) {
               ib->ptr[ib->length_dw++] = lower_32_bits(value);
               ib->ptr[ib->length_dw++] = upper_32_bits(value);
                value += incr;
        }

With this one:

        u32 *ptr = &ib->ptr[ib->length_dw];

        *ptr++ = SDMA_PKT_HEADER_OP(SDMA_OP_WRITE) |
                 SDMA_PKT_HEADER_SUB_OP(SDMA_SUBOP_WRITE_LINEAR);
        *ptr++ = lower_32_bits(pe);
        *ptr++ = upper_32_bits(pe);
        *ptr++ = ndw - 1;
        for (; ndw > 0; ndw -= 2) {
                *ptr++ = lower_32_bits(value);
                *ptr++ = upper_32_bits(value);
                 value += incr;
         }

        ib->length_dw = ptr - ib->ptr;

Latter avoids register reloads and length updates on every dword written, and on the overall makes the IB emission much more compact:

add/remove: 0/1 grow/shrink: 10/58 up/down: 260/-6598 (-6338)

Function                                     old     new   delta
sdma_v7_0_ring_pad_ib                         99     127     +28
sdma_v6_0_ring_pad_ib                         99     127     +28
sdma_v5_2_ring_pad_ib                         99     127     +28
sdma_v5_0_ring_pad_ib                         99     127     +28
sdma_v4_4_2_ring_pad_ib                       99     127     +28
sdma_v4_0_ring_pad_ib                         99     127     +28
sdma_v3_0_ring_pad_ib                         99     127     +28
sdma_v2_4_ring_pad_ib                         99     127     +28
cik_sdma_ring_pad_ib                          99     127     +28
si_dma_ring_pad_ib                            36      44      +8
amdgpu_ring_generic_pad_ib                    56      52      -4
si_dma_emit_fill_buffer                      108      71     -37
si_dma_vm_write_pte                          158     115     -43
amdgpu_vcn_dec_sw_send_msg                   810     767     -43
si_dma_vm_copy_pte                           137      87     -50
si_dma_emit_copy_buffer                      134      84     -50
sdma_v3_0_vm_write_pte                       163     102     -61
sdma_v2_4_vm_write_pte                       163     102     -61
cik_sdma_vm_write_pte                        163     102     -61
sdma_v7_0_vm_write_pte                       168     105     -63
sdma_v7_0_emit_fill_buffer                   119      56     -63
sdma_v6_0_vm_write_pte                       168     105     -63
sdma_v6_0_emit_fill_buffer                   119      56     -63
sdma_v5_2_vm_write_pte                       168     105     -63
sdma_v5_2_emit_fill_buffer                   119      56     -63
sdma_v5_0_vm_write_pte                       168     105     -63
sdma_v5_0_emit_fill_buffer                   119      56     -63
sdma_v4_4_2_vm_write_pte                     168     105     -63
sdma_v4_4_2_emit_fill_buffer                 119      56     -63
sdma_v4_0_vm_write_pte                       168     105     -63
sdma_v4_0_emit_fill_buffer                   119      56     -63
sdma_v3_0_emit_fill_buffer                   116      53     -63
sdma_v2_4_emit_fill_buffer                   116      53     -63
cik_sdma_emit_fill_buffer                    116      53     -63
sdma_v6_0_emit_copy_buffer                   169      76     -93
sdma_v5_2_emit_copy_buffer                   169      76     -93
sdma_v5_0_emit_copy_buffer                   169      76     -93
sdma_v4_4_2_emit_copy_buffer                 169      76     -93
sdma_v4_0_emit_copy_buffer                   169      76     -93
sdma_v3_0_vm_copy_pte                        158      64     -94
sdma_v3_0_emit_copy_buffer                   155      61     -94
sdma_v2_4_vm_copy_pte                        158      64     -94
sdma_v2_4_emit_copy_buffer                   155      61     -94
cik_sdma_vm_copy_pte                         158      64     -94
cik_sdma_emit_copy_buffer                    155      61     -94
sdma_v6_0_vm_copy_pte                        163      68     -95
sdma_v5_2_vm_copy_pte                        163      68     -95
sdma_v5_0_vm_copy_pte                        163      68     -95
sdma_v4_4_2_vm_copy_pte                      163      68     -95
sdma_v4_0_vm_copy_pte                        163      68     -95
sdma_v7_0_vm_copy_pte                        183      75    -108
sdma_v7_0_emit_copy_buffer                   317     202    -115
si_dma_vm_set_pte_pde                        338     214    -124
amdgpu_vce_get_destroy_msg                   784     652    -132
sdma_v7_0_vm_set_pte_pde                     218      72    -146
sdma_v6_0_vm_set_pte_pde                     218      72    -146
sdma_v5_2_vm_set_pte_pde                     218      72    -146
sdma_v5_0_vm_set_pte_pde                     218      72    -146
sdma_v4_4_2_vm_set_pte_pde                   218      72    -146
sdma_v4_0_vm_set_pte_pde                     218      72    -146
sdma_v3_0_vm_set_pte_pde                     215      69    -146
sdma_v2_4_vm_set_pte_pde                     215      69    -146
cik_sdma_vm_set_pte_pde                      215      69    -146
amdgpu_vcn_unified_ring_ib_header            172       -    -172
gfx_v9_4_2_run_shader.constprop              739     532    -207
uvd_v6_0_enc_ring_test_ib                   1464    1162    -302
uvd_v7_0_enc_ring_test_ib                   1464    1138    -326
amdgpu_vce_ring_test_ib                     1357     936    -421
amdgpu_vcn_enc_ring_test_ib                 2042    1524    -518

Total: Before=9262623, After=9256285, chg -0.07%

* Notice how _pad_ib functions have grown. I think the compiler used the opportunity to unroll the loops.

** Series was only smoke tested on the Steam Deck.

Tvrtko Ursulin (16):
drm/amdgpu: Use memset32 for IB padding drm/amdgpu: More compact VCE IB emission drm/amdgpu: More compact VCN IB emission drm/amdgpu: More compact UVD 6 IB emission drm/amdgpu: More compact UVD 7 IB emission drm/amdgpu: More compact SI SDMA emission drm/amdgpu: More compact CIK SDMA IB emission drm/amdgpu: More compact GFX 9.4.2 IB emission drm/amdgpu: More compact SDMA 2.4 IB emission drm/amdgpu: More compact SDMA 3.0 IB emission drm/amdgpu: More compact SDMA 4.0 IB emission drm/amdgpu: More compact SDMA 4.4.2 IB emission drm/amdgpu: More compact SDMA 5.0 IB emission drm/amdgpu: More compact SDMA 5.2 IB emission drm/amdgpu: More compact SDMA 6.0 IB emission drm/amdgpu: More compact SDMA 7.0 IB emission

  drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c |  12 ++-
  drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c  |  90 +++++++++--------
  drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c  | 101 ++++++++++---------
  drivers/gpu/drm/amd/amdgpu/cik_sdma.c    | 105 ++++++++++++--------
  drivers/gpu/drm/amd/amdgpu/gfx_v9_4_2.c  |  46 ++++-----
  drivers/gpu/drm/amd/amdgpu/sdma_v2_4.c   | 108 ++++++++++++--------
  drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c   | 108 ++++++++++++--------
  drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c   | 109 ++++++++++++---------
  drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c | 108 ++++++++++++--------
  drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c   | 106 ++++++++++++--------
  drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c   | 110 ++++++++++++---------
  drivers/gpu/drm/amd/amdgpu/sdma_v6_0.c   | 110 ++++++++++++---------
  drivers/gpu/drm/amd/amdgpu/sdma_v7_0.c   | 119 +++++++++++++----------
  drivers/gpu/drm/amd/amdgpu/si_dma.c      |  84 +++++++++-------
  drivers/gpu/drm/amd/amdgpu/uvd_v6_0.c    |  66 +++++++------
  drivers/gpu/drm/amd/amdgpu/uvd_v7_0.c    |  66 +++++++------
  16 files changed, 849 insertions(+), 599 deletions(-)

--
2.48.0

#19 lore raw
Quoted 7 lines · Tvrtko Ursulin
Quoted 1 line · Alex Deucher

Applied the series. Thanks!

Thank you and fingers crossed I did not fat finger anything that your CI wouldn't find!

Sorry for the late reply. This series broke the VCN IB tests on at least navi4x. The issue is a GPUVM page fault caused by VCN when running the IB tests.
I don't see any obvious problems with the patches, but I haven't had a chance to dig too much further.

Alex

Quoted 163 lines

I wish something similar could be done for amdgpu_ring_write too, but that one is waiting on Christian to, AFAIR, become idle enough to untangle some ptr masking issues.

Regards,

Tvrtko

Quoted 153 lines
Quoted 151 lines · Tvrtko Ursulin

In short, this series mostly does a lot of replacing of this pattern:

        ib->ptr[ib->length_dw++] = SDMA_PKT_HEADER_OP(SDMA_OP_WRITE) |
                SDMA_PKT_HEADER_SUB_OP(SDMA_SUBOP_WRITE_LINEAR);
        ib->ptr[ib->length_dw++] = lower_32_bits(pe);
        ib->ptr[ib->length_dw++] = upper_32_bits(pe);
        ib->ptr[ib->length_dw++] = ndw - 1;
        for (; ndw > 0; ndw -= 2) {
               ib->ptr[ib->length_dw++] = lower_32_bits(value);
               ib->ptr[ib->length_dw++] = upper_32_bits(value);
                value += incr;
        }

With this one:

        u32 *ptr = &ib->ptr[ib->length_dw];

        *ptr++ = SDMA_PKT_HEADER_OP(SDMA_OP_WRITE) |
                 SDMA_PKT_HEADER_SUB_OP(SDMA_SUBOP_WRITE_LINEAR);
        *ptr++ = lower_32_bits(pe);
        *ptr++ = upper_32_bits(pe);
        *ptr++ = ndw - 1;
        for (; ndw > 0; ndw -= 2) {
                *ptr++ = lower_32_bits(value);
                *ptr++ = upper_32_bits(value);
                 value += incr;
         }

        ib->length_dw = ptr - ib->ptr;

Latter avoids register reloads and length updates on every dword written, and on the overall makes the IB emission much more compact:

add/remove: 0/1 grow/shrink: 10/58 up/down: 260/-6598 (-6338)

Function                                     old     new   delta
sdma_v7_0_ring_pad_ib                         99     127     +28
sdma_v6_0_ring_pad_ib                         99     127     +28
sdma_v5_2_ring_pad_ib                         99     127     +28
sdma_v5_0_ring_pad_ib                         99     127     +28
sdma_v4_4_2_ring_pad_ib                       99     127     +28
sdma_v4_0_ring_pad_ib                         99     127     +28
sdma_v3_0_ring_pad_ib                         99     127     +28
sdma_v2_4_ring_pad_ib                         99     127     +28
cik_sdma_ring_pad_ib                          99     127     +28
si_dma_ring_pad_ib                            36      44      +8
amdgpu_ring_generic_pad_ib                    56      52      -4
si_dma_emit_fill_buffer                      108      71     -37
si_dma_vm_write_pte                          158     115     -43
amdgpu_vcn_dec_sw_send_msg                   810     767     -43
si_dma_vm_copy_pte                           137      87     -50
si_dma_emit_copy_buffer                      134      84     -50
sdma_v3_0_vm_write_pte                       163     102     -61
sdma_v2_4_vm_write_pte                       163     102     -61
cik_sdma_vm_write_pte                        163     102     -61
sdma_v7_0_vm_write_pte                       168     105     -63
sdma_v7_0_emit_fill_buffer                   119      56     -63
sdma_v6_0_vm_write_pte                       168     105     -63
sdma_v6_0_emit_fill_buffer                   119      56     -63
sdma_v5_2_vm_write_pte                       168     105     -63
sdma_v5_2_emit_fill_buffer                   119      56     -63
sdma_v5_0_vm_write_pte                       168     105     -63
sdma_v5_0_emit_fill_buffer                   119      56     -63
sdma_v4_4_2_vm_write_pte                     168     105     -63
sdma_v4_4_2_emit_fill_buffer                 119      56     -63
sdma_v4_0_vm_write_pte                       168     105     -63
sdma_v4_0_emit_fill_buffer                   119      56     -63
sdma_v3_0_emit_fill_buffer                   116      53     -63
sdma_v2_4_emit_fill_buffer                   116      53     -63
cik_sdma_emit_fill_buffer                    116      53     -63
sdma_v6_0_emit_copy_buffer                   169      76     -93
sdma_v5_2_emit_copy_buffer                   169      76     -93
sdma_v5_0_emit_copy_buffer                   169      76     -93
sdma_v4_4_2_emit_copy_buffer                 169      76     -93
sdma_v4_0_emit_copy_buffer                   169      76     -93
sdma_v3_0_vm_copy_pte                        158      64     -94
sdma_v3_0_emit_copy_buffer                   155      61     -94
sdma_v2_4_vm_copy_pte                        158      64     -94
sdma_v2_4_emit_copy_buffer                   155      61     -94
cik_sdma_vm_copy_pte                         158      64     -94
cik_sdma_emit_copy_buffer                    155      61     -94
sdma_v6_0_vm_copy_pte                        163      68     -95
sdma_v5_2_vm_copy_pte                        163      68     -95
sdma_v5_0_vm_copy_pte                        163      68     -95
sdma_v4_4_2_vm_copy_pte                      163      68     -95
sdma_v4_0_vm_copy_pte                        163      68     -95
sdma_v7_0_vm_copy_pte                        183      75    -108
sdma_v7_0_emit_copy_buffer                   317     202    -115
si_dma_vm_set_pte_pde                        338     214    -124
amdgpu_vce_get_destroy_msg                   784     652    -132
sdma_v7_0_vm_set_pte_pde                     218      72    -146
sdma_v6_0_vm_set_pte_pde                     218      72    -146
sdma_v5_2_vm_set_pte_pde                     218      72    -146
sdma_v5_0_vm_set_pte_pde                     218      72    -146
sdma_v4_4_2_vm_set_pte_pde                   218      72    -146
sdma_v4_0_vm_set_pte_pde                     218      72    -146
sdma_v3_0_vm_set_pte_pde                     215      69    -146
sdma_v2_4_vm_set_pte_pde                     215      69    -146
cik_sdma_vm_set_pte_pde                      215      69    -146
amdgpu_vcn_unified_ring_ib_header            172       -    -172
gfx_v9_4_2_run_shader.constprop              739     532    -207
uvd_v6_0_enc_ring_test_ib                   1464    1162    -302
uvd_v7_0_enc_ring_test_ib                   1464    1138    -326
amdgpu_vce_ring_test_ib                     1357     936    -421
amdgpu_vcn_enc_ring_test_ib                 2042    1524    -518

Total: Before=9262623, After=9256285, chg -0.07%

* Notice how _pad_ib functions have grown. I think the compiler used the opportunity to unroll the loops.

** Series was only smoke tested on the Steam Deck.

Tvrtko Ursulin (16):
drm/amdgpu: Use memset32 for IB padding drm/amdgpu: More compact VCE IB emission drm/amdgpu: More compact VCN IB emission drm/amdgpu: More compact UVD 6 IB emission drm/amdgpu: More compact UVD 7 IB emission drm/amdgpu: More compact SI SDMA emission drm/amdgpu: More compact CIK SDMA IB emission drm/amdgpu: More compact GFX 9.4.2 IB emission drm/amdgpu: More compact SDMA 2.4 IB emission drm/amdgpu: More compact SDMA 3.0 IB emission drm/amdgpu: More compact SDMA 4.0 IB emission drm/amdgpu: More compact SDMA 4.4.2 IB emission drm/amdgpu: More compact SDMA 5.0 IB emission drm/amdgpu: More compact SDMA 5.2 IB emission drm/amdgpu: More compact SDMA 6.0 IB emission drm/amdgpu: More compact SDMA 7.0 IB emission

  drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c |  12 ++-
  drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c  |  90 +++++++++--------
  drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c  | 101 ++++++++++---------
  drivers/gpu/drm/amd/amdgpu/cik_sdma.c    | 105 ++++++++++++--------
  drivers/gpu/drm/amd/amdgpu/gfx_v9_4_2.c  |  46 ++++-----
  drivers/gpu/drm/amd/amdgpu/sdma_v2_4.c   | 108 ++++++++++++--------
  drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c   | 108 ++++++++++++--------
  drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c   | 109 ++++++++++++---------
  drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c | 108 ++++++++++++--------
  drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c   | 106 ++++++++++++--------
  drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c   | 110 ++++++++++++---------
  drivers/gpu/drm/amd/amdgpu/sdma_v6_0.c   | 110 ++++++++++++---------
  drivers/gpu/drm/amd/amdgpu/sdma_v7_0.c   | 119 +++++++++++++----------
  drivers/gpu/drm/amd/amdgpu/si_dma.c      |  84 +++++++++-------
  drivers/gpu/drm/amd/amdgpu/uvd_v6_0.c    |  66 +++++++------
  drivers/gpu/drm/amd/amdgpu/uvd_v7_0.c    |  66 +++++++------
  16 files changed, 849 insertions(+), 599 deletions(-)

--
2.48.0

#20 lore raw
Quoted 7 lines · Alex Deucher
Quoted 5 lines · Tvrtko Ursulin
Quoted 1 line · Alex Deucher

Applied the series. Thanks!

Quoted 8 lines
Quoted 2 lines

Thank you and fingers crossed I did not fat finger anything that your CI wouldn't find!

Sorry for the late reply. This series broke the VCN IB tests on at least navi4x. The issue is a GPUVM page fault caused by VCN when running the IB tests.
I don't see any obvious problems with the patches, but I haven't had a chance to dig too much further.

Oh I see the problem.. sorry about that.

I missed the fact that after amdgpu_vcn_unified_ring_ib_header() I need to update the pointer.

Good news is that only VCN has this pattern.

Okay to send a fix next week? Would you need a fixup or a replacement patch in case you want to revert it in the meantime?

Regards,

Tvrtko

Quoted 162 lines
Quoted 162 lines

I wish something similar could be done for amdgpu_ring_write too, but that one is waiting on Christian to, AFAIR, become idle enough to untangle some ptr masking issues.

Regards,

Tvrtko

Quoted 153 lines
Quoted 151 lines · Tvrtko Ursulin

In short, this series mostly does a lot of replacing of this pattern:

         ib->ptr[ib->length_dw++] = SDMA_PKT_HEADER_OP(SDMA_OP_WRITE) |
                 SDMA_PKT_HEADER_SUB_OP(SDMA_SUBOP_WRITE_LINEAR);
         ib->ptr[ib->length_dw++] = lower_32_bits(pe);
         ib->ptr[ib->length_dw++] = upper_32_bits(pe);
         ib->ptr[ib->length_dw++] = ndw - 1;
         for (; ndw > 0; ndw -= 2) {
                ib->ptr[ib->length_dw++] = lower_32_bits(value);
                ib->ptr[ib->length_dw++] = upper_32_bits(value);
                 value += incr;
         }

With this one:

         u32 *ptr = &ib->ptr[ib->length_dw];

         *ptr++ = SDMA_PKT_HEADER_OP(SDMA_OP_WRITE) |
                  SDMA_PKT_HEADER_SUB_OP(SDMA_SUBOP_WRITE_LINEAR);
         *ptr++ = lower_32_bits(pe);
         *ptr++ = upper_32_bits(pe);
         *ptr++ = ndw - 1;
         for (; ndw > 0; ndw -= 2) {
                 *ptr++ = lower_32_bits(value);
                 *ptr++ = upper_32_bits(value);
                  value += incr;
          }

         ib->length_dw = ptr - ib->ptr;

Latter avoids register reloads and length updates on every dword written, and on the overall makes the IB emission much more compact:

add/remove: 0/1 grow/shrink: 10/58 up/down: 260/-6598 (-6338)

Function                                     old     new   delta
sdma_v7_0_ring_pad_ib                         99     127     +28
sdma_v6_0_ring_pad_ib                         99     127     +28
sdma_v5_2_ring_pad_ib                         99     127     +28
sdma_v5_0_ring_pad_ib                         99     127     +28
sdma_v4_4_2_ring_pad_ib                       99     127     +28
sdma_v4_0_ring_pad_ib                         99     127     +28
sdma_v3_0_ring_pad_ib                         99     127     +28
sdma_v2_4_ring_pad_ib                         99     127     +28
cik_sdma_ring_pad_ib                          99     127     +28
si_dma_ring_pad_ib                            36      44      +8
amdgpu_ring_generic_pad_ib                    56      52      -4
si_dma_emit_fill_buffer                      108      71     -37
si_dma_vm_write_pte                          158     115     -43
amdgpu_vcn_dec_sw_send_msg                   810     767     -43
si_dma_vm_copy_pte                           137      87     -50
si_dma_emit_copy_buffer                      134      84     -50
sdma_v3_0_vm_write_pte                       163     102     -61
sdma_v2_4_vm_write_pte                       163     102     -61
cik_sdma_vm_write_pte                        163     102     -61
sdma_v7_0_vm_write_pte                       168     105     -63
sdma_v7_0_emit_fill_buffer                   119      56     -63
sdma_v6_0_vm_write_pte                       168     105     -63
sdma_v6_0_emit_fill_buffer                   119      56     -63
sdma_v5_2_vm_write_pte                       168     105     -63
sdma_v5_2_emit_fill_buffer                   119      56     -63
sdma_v5_0_vm_write_pte                       168     105     -63
sdma_v5_0_emit_fill_buffer                   119      56     -63
sdma_v4_4_2_vm_write_pte                     168     105     -63
sdma_v4_4_2_emit_fill_buffer                 119      56     -63
sdma_v4_0_vm_write_pte                       168     105     -63
sdma_v4_0_emit_fill_buffer                   119      56     -63
sdma_v3_0_emit_fill_buffer                   116      53     -63
sdma_v2_4_emit_fill_buffer                   116      53     -63
cik_sdma_emit_fill_buffer                    116      53     -63
sdma_v6_0_emit_copy_buffer                   169      76     -93
sdma_v5_2_emit_copy_buffer                   169      76     -93
sdma_v5_0_emit_copy_buffer                   169      76     -93
sdma_v4_4_2_emit_copy_buffer                 169      76     -93
sdma_v4_0_emit_copy_buffer                   169      76     -93
sdma_v3_0_vm_copy_pte                        158      64     -94
sdma_v3_0_emit_copy_buffer                   155      61     -94
sdma_v2_4_vm_copy_pte                        158      64     -94
sdma_v2_4_emit_copy_buffer                   155      61     -94
cik_sdma_vm_copy_pte                         158      64     -94
cik_sdma_emit_copy_buffer                    155      61     -94
sdma_v6_0_vm_copy_pte                        163      68     -95
sdma_v5_2_vm_copy_pte                        163      68     -95
sdma_v5_0_vm_copy_pte                        163      68     -95
sdma_v4_4_2_vm_copy_pte                      163      68     -95
sdma_v4_0_vm_copy_pte                        163      68     -95
sdma_v7_0_vm_copy_pte                        183      75    -108
sdma_v7_0_emit_copy_buffer                   317     202    -115
si_dma_vm_set_pte_pde                        338     214    -124
amdgpu_vce_get_destroy_msg                   784     652    -132
sdma_v7_0_vm_set_pte_pde                     218      72    -146
sdma_v6_0_vm_set_pte_pde                     218      72    -146
sdma_v5_2_vm_set_pte_pde                     218      72    -146
sdma_v5_0_vm_set_pte_pde                     218      72    -146
sdma_v4_4_2_vm_set_pte_pde                   218      72    -146
sdma_v4_0_vm_set_pte_pde                     218      72    -146
sdma_v3_0_vm_set_pte_pde                     215      69    -146
sdma_v2_4_vm_set_pte_pde                     215      69    -146
cik_sdma_vm_set_pte_pde                      215      69    -146
amdgpu_vcn_unified_ring_ib_header            172       -    -172
gfx_v9_4_2_run_shader.constprop              739     532    -207
uvd_v6_0_enc_ring_test_ib                   1464    1162    -302
uvd_v7_0_enc_ring_test_ib                   1464    1138    -326
amdgpu_vce_ring_test_ib                     1357     936    -421
amdgpu_vcn_enc_ring_test_ib                 2042    1524    -518

Total: Before=9262623, After=9256285, chg -0.07%

* Notice how _pad_ib functions have grown. I think the compiler used the opportunity to unroll the loops.

** Series was only smoke tested on the Steam Deck.

Tvrtko Ursulin (16):
drm/amdgpu: Use memset32 for IB padding drm/amdgpu: More compact VCE IB emission drm/amdgpu: More compact VCN IB emission drm/amdgpu: More compact UVD 6 IB emission drm/amdgpu: More compact UVD 7 IB emission drm/amdgpu: More compact SI SDMA emission drm/amdgpu: More compact CIK SDMA IB emission drm/amdgpu: More compact GFX 9.4.2 IB emission drm/amdgpu: More compact SDMA 2.4 IB emission drm/amdgpu: More compact SDMA 3.0 IB emission drm/amdgpu: More compact SDMA 4.0 IB emission drm/amdgpu: More compact SDMA 4.4.2 IB emission drm/amdgpu: More compact SDMA 5.0 IB emission drm/amdgpu: More compact SDMA 5.2 IB emission drm/amdgpu: More compact SDMA 6.0 IB emission drm/amdgpu: More compact SDMA 7.0 IB emission

   drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c |  12 ++-
   drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c  |  90 +++++++++--------
   drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c  | 101 ++++++++++---------
   drivers/gpu/drm/amd/amdgpu/cik_sdma.c    | 105 ++++++++++++--------
   drivers/gpu/drm/amd/amdgpu/gfx_v9_4_2.c  |  46 ++++-----
   drivers/gpu/drm/amd/amdgpu/sdma_v2_4.c   | 108 ++++++++++++--------
   drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c   | 108 ++++++++++++--------
   drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c   | 109 ++++++++++++---------
   drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c | 108 ++++++++++++--------
   drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c   | 106 ++++++++++++--------
   drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c   | 110 ++++++++++++---------
   drivers/gpu/drm/amd/amdgpu/sdma_v6_0.c   | 110 ++++++++++++---------
   drivers/gpu/drm/amd/amdgpu/sdma_v7_0.c   | 119 +++++++++++++----------
   drivers/gpu/drm/amd/amdgpu/si_dma.c      |  84 +++++++++-------
   drivers/gpu/drm/amd/amdgpu/uvd_v6_0.c    |  66 +++++++------
   drivers/gpu/drm/amd/amdgpu/uvd_v7_0.c    |  66 +++++++------
   16 files changed, 849 insertions(+), 599 deletions(-)

--
2.48.0

#21 lore raw
Quoted 21 lines · Tvrtko Ursulin
Quoted 7 lines · Alex Deucher
Quoted 5 lines · Tvrtko Ursulin
Quoted 1 line · Alex Deucher

Applied the series. Thanks!

Quoted 8 lines
Quoted 2 lines

Thank you and fingers crossed I did not fat finger anything that your CI wouldn't find!

Sorry for the late reply. This series broke the VCN IB tests on at least navi4x. The issue is a GPUVM page fault caused by VCN when running the IB tests.
I don't see any obvious problems with the patches, but I haven't had a chance to dig too much further.

Oh I see the problem.. sorry about that.

Quoted 7 lines

I missed the fact that after amdgpu_vcn_unified_ring_ib_header() I need to update the pointer.

Good news is that only VCN has this pattern.

Okay to send a fix next week? Would you need a fixup or a replacement patch in case you want to revert it in the meantime?

Fixup is fine. I'll squash it into the original VCN patch and give it a test next week.

Thanks!

Alex

Quoted 168 lines

Regards,

Tvrtko

Quoted 162 lines
Quoted 162 lines

I wish something similar could be done for amdgpu_ring_write too, but that one is waiting on Christian to, AFAIR, become idle enough to untangle some ptr masking issues.

Regards,

Tvrtko

Quoted 153 lines
Quoted 151 lines · Tvrtko Ursulin

In short, this series mostly does a lot of replacing of this pattern:

         ib->ptr[ib->length_dw++] = SDMA_PKT_HEADER_OP(SDMA_OP_WRITE) |
                 SDMA_PKT_HEADER_SUB_OP(SDMA_SUBOP_WRITE_LINEAR);
         ib->ptr[ib->length_dw++] = lower_32_bits(pe);
         ib->ptr[ib->length_dw++] = upper_32_bits(pe);
         ib->ptr[ib->length_dw++] = ndw - 1;
         for (; ndw > 0; ndw -= 2) {
                ib->ptr[ib->length_dw++] = lower_32_bits(value);
                ib->ptr[ib->length_dw++] = upper_32_bits(value);
                 value += incr;
         }

With this one:

         u32 *ptr = &ib->ptr[ib->length_dw];

         *ptr++ = SDMA_PKT_HEADER_OP(SDMA_OP_WRITE) |
                  SDMA_PKT_HEADER_SUB_OP(SDMA_SUBOP_WRITE_LINEAR);
         *ptr++ = lower_32_bits(pe);
         *ptr++ = upper_32_bits(pe);
         *ptr++ = ndw - 1;
         for (; ndw > 0; ndw -= 2) {
                 *ptr++ = lower_32_bits(value);
                 *ptr++ = upper_32_bits(value);
                  value += incr;
          }

         ib->length_dw = ptr - ib->ptr;

Latter avoids register reloads and length updates on every dword written, and on the overall makes the IB emission much more compact:

add/remove: 0/1 grow/shrink: 10/58 up/down: 260/-6598 (-6338)

Function                                     old     new   delta
sdma_v7_0_ring_pad_ib                         99     127     +28
sdma_v6_0_ring_pad_ib                         99     127     +28
sdma_v5_2_ring_pad_ib                         99     127     +28
sdma_v5_0_ring_pad_ib                         99     127     +28
sdma_v4_4_2_ring_pad_ib                       99     127     +28
sdma_v4_0_ring_pad_ib                         99     127     +28
sdma_v3_0_ring_pad_ib                         99     127     +28
sdma_v2_4_ring_pad_ib                         99     127     +28
cik_sdma_ring_pad_ib                          99     127     +28
si_dma_ring_pad_ib                            36      44      +8
amdgpu_ring_generic_pad_ib                    56      52      -4
si_dma_emit_fill_buffer                      108      71     -37
si_dma_vm_write_pte                          158     115     -43
amdgpu_vcn_dec_sw_send_msg                   810     767     -43
si_dma_vm_copy_pte                           137      87     -50
si_dma_emit_copy_buffer                      134      84     -50
sdma_v3_0_vm_write_pte                       163     102     -61
sdma_v2_4_vm_write_pte                       163     102     -61
cik_sdma_vm_write_pte                        163     102     -61
sdma_v7_0_vm_write_pte                       168     105     -63
sdma_v7_0_emit_fill_buffer                   119      56     -63
sdma_v6_0_vm_write_pte                       168     105     -63
sdma_v6_0_emit_fill_buffer                   119      56     -63
sdma_v5_2_vm_write_pte                       168     105     -63
sdma_v5_2_emit_fill_buffer                   119      56     -63
sdma_v5_0_vm_write_pte                       168     105     -63
sdma_v5_0_emit_fill_buffer                   119      56     -63
sdma_v4_4_2_vm_write_pte                     168     105     -63
sdma_v4_4_2_emit_fill_buffer                 119      56     -63
sdma_v4_0_vm_write_pte                       168     105     -63
sdma_v4_0_emit_fill_buffer                   119      56     -63
sdma_v3_0_emit_fill_buffer                   116      53     -63
sdma_v2_4_emit_fill_buffer                   116      53     -63
cik_sdma_emit_fill_buffer                    116      53     -63
sdma_v6_0_emit_copy_buffer                   169      76     -93
sdma_v5_2_emit_copy_buffer                   169      76     -93
sdma_v5_0_emit_copy_buffer                   169      76     -93
sdma_v4_4_2_emit_copy_buffer                 169      76     -93
sdma_v4_0_emit_copy_buffer                   169      76     -93
sdma_v3_0_vm_copy_pte                        158      64     -94
sdma_v3_0_emit_copy_buffer                   155      61     -94
sdma_v2_4_vm_copy_pte                        158      64     -94
sdma_v2_4_emit_copy_buffer                   155      61     -94
cik_sdma_vm_copy_pte                         158      64     -94
cik_sdma_emit_copy_buffer                    155      61     -94
sdma_v6_0_vm_copy_pte                        163      68     -95
sdma_v5_2_vm_copy_pte                        163      68     -95
sdma_v5_0_vm_copy_pte                        163      68     -95
sdma_v4_4_2_vm_copy_pte                      163      68     -95
sdma_v4_0_vm_copy_pte                        163      68     -95
sdma_v7_0_vm_copy_pte                        183      75    -108
sdma_v7_0_emit_copy_buffer                   317     202    -115
si_dma_vm_set_pte_pde                        338     214    -124
amdgpu_vce_get_destroy_msg                   784     652    -132
sdma_v7_0_vm_set_pte_pde                     218      72    -146
sdma_v6_0_vm_set_pte_pde                     218      72    -146
sdma_v5_2_vm_set_pte_pde                     218      72    -146
sdma_v5_0_vm_set_pte_pde                     218      72    -146
sdma_v4_4_2_vm_set_pte_pde                   218      72    -146
sdma_v4_0_vm_set_pte_pde                     218      72    -146
sdma_v3_0_vm_set_pte_pde                     215      69    -146
sdma_v2_4_vm_set_pte_pde                     215      69    -146
cik_sdma_vm_set_pte_pde                      215      69    -146
amdgpu_vcn_unified_ring_ib_header            172       -    -172
gfx_v9_4_2_run_shader.constprop              739     532    -207
uvd_v6_0_enc_ring_test_ib                   1464    1162    -302
uvd_v7_0_enc_ring_test_ib                   1464    1138    -326
amdgpu_vce_ring_test_ib                     1357     936    -421
amdgpu_vcn_enc_ring_test_ib                 2042    1524    -518

Total: Before=9262623, After=9256285, chg -0.07%

* Notice how _pad_ib functions have grown. I think the compiler used the opportunity to unroll the loops.

** Series was only smoke tested on the Steam Deck.

Tvrtko Ursulin (16):
drm/amdgpu: Use memset32 for IB padding drm/amdgpu: More compact VCE IB emission drm/amdgpu: More compact VCN IB emission drm/amdgpu: More compact UVD 6 IB emission drm/amdgpu: More compact UVD 7 IB emission drm/amdgpu: More compact SI SDMA emission drm/amdgpu: More compact CIK SDMA IB emission drm/amdgpu: More compact GFX 9.4.2 IB emission drm/amdgpu: More compact SDMA 2.4 IB emission drm/amdgpu: More compact SDMA 3.0 IB emission drm/amdgpu: More compact SDMA 4.0 IB emission drm/amdgpu: More compact SDMA 4.4.2 IB emission drm/amdgpu: More compact SDMA 5.0 IB emission drm/amdgpu: More compact SDMA 5.2 IB emission drm/amdgpu: More compact SDMA 6.0 IB emission drm/amdgpu: More compact SDMA 7.0 IB emission

   drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c |  12 ++-
   drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c  |  90 +++++++++--------
   drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c  | 101 ++++++++++---------
   drivers/gpu/drm/amd/amdgpu/cik_sdma.c    | 105 ++++++++++++--------
   drivers/gpu/drm/amd/amdgpu/gfx_v9_4_2.c  |  46 ++++-----
   drivers/gpu/drm/amd/amdgpu/sdma_v2_4.c   | 108 ++++++++++++--------
   drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c   | 108 ++++++++++++--------
   drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c   | 109 ++++++++++++---------
   drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c | 108 ++++++++++++--------
   drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c   | 106 ++++++++++++--------
   drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c   | 110 ++++++++++++---------
   drivers/gpu/drm/amd/amdgpu/sdma_v6_0.c   | 110 ++++++++++++---------
   drivers/gpu/drm/amd/amdgpu/sdma_v7_0.c   | 119 +++++++++++++----------
   drivers/gpu/drm/amd/amdgpu/si_dma.c      |  84 +++++++++-------
   drivers/gpu/drm/amd/amdgpu/uvd_v6_0.c    |  66 +++++++------
   drivers/gpu/drm/amd/amdgpu/uvd_v7_0.c    |  66 +++++++------
   16 files changed, 849 insertions(+), 599 deletions(-)

--
2.48.0

#22 lore raw
Quoted 26 lines · Alex Deucher
Quoted 24 lines · Tvrtko Ursulin
Quoted 7 lines · Alex Deucher
Quoted 5 lines · Tvrtko Ursulin
Quoted 1 line · Alex Deucher

Applied the series. Thanks!

Quoted 8 lines
Quoted 2 lines

Thank you and fingers crossed I did not fat finger anything that your CI wouldn't find!

Sorry for the late reply. This series broke the VCN IB tests on at least navi4x. The issue is a GPUVM page fault caused by VCN when running the IB tests.
I don't see any obvious problems with the patches, but I haven't had a chance to dig too much further.

Oh I see the problem.. sorry about that.

I missed the fact that after amdgpu_vcn_unified_ring_ib_header() I need to update the pointer.

Quoted 7 lines
Quoted 4 lines

Good news is that only VCN has this pattern.

Okay to send a fix next week? Would you need a fixup or a replacement patch in case you want to revert it in the meantime?

Fixup is fine. I'll squash it into the original VCN patch and give it a test next week.

How did it go? I noticed amd-staging-drm-next currently has the original buggy version.

Given other patches from the series are also missing perhaps you are testing it in stages?

Regards,

Tvrtko

Quoted 163 lines
Quoted 163 lines
Quoted 162 lines
Quoted 162 lines

I wish something similar could be done for amdgpu_ring_write too, but that one is waiting on Christian to, AFAIR, become idle enough to untangle some ptr masking issues.

Regards,

Tvrtko

Quoted 153 lines
Quoted 151 lines · Tvrtko Ursulin

In short, this series mostly does a lot of replacing of this pattern:

          ib->ptr[ib->length_dw++] = SDMA_PKT_HEADER_OP(SDMA_OP_WRITE) |
                  SDMA_PKT_HEADER_SUB_OP(SDMA_SUBOP_WRITE_LINEAR);
          ib->ptr[ib->length_dw++] = lower_32_bits(pe);
          ib->ptr[ib->length_dw++] = upper_32_bits(pe);
          ib->ptr[ib->length_dw++] = ndw - 1;
          for (; ndw > 0; ndw -= 2) {
                 ib->ptr[ib->length_dw++] = lower_32_bits(value);
                 ib->ptr[ib->length_dw++] = upper_32_bits(value);
                  value += incr;
          }

With this one:

          u32 *ptr = &ib->ptr[ib->length_dw];

          *ptr++ = SDMA_PKT_HEADER_OP(SDMA_OP_WRITE) |
                   SDMA_PKT_HEADER_SUB_OP(SDMA_SUBOP_WRITE_LINEAR);
          *ptr++ = lower_32_bits(pe);
          *ptr++ = upper_32_bits(pe);
          *ptr++ = ndw - 1;
          for (; ndw > 0; ndw -= 2) {
                  *ptr++ = lower_32_bits(value);
                  *ptr++ = upper_32_bits(value);
                   value += incr;
           }

          ib->length_dw = ptr - ib->ptr;

Latter avoids register reloads and length updates on every dword written, and on the overall makes the IB emission much more compact:

add/remove: 0/1 grow/shrink: 10/58 up/down: 260/-6598 (-6338)

Function                                     old     new   delta
sdma_v7_0_ring_pad_ib                         99     127     +28
sdma_v6_0_ring_pad_ib                         99     127     +28
sdma_v5_2_ring_pad_ib                         99     127     +28
sdma_v5_0_ring_pad_ib                         99     127     +28
sdma_v4_4_2_ring_pad_ib                       99     127     +28
sdma_v4_0_ring_pad_ib                         99     127     +28
sdma_v3_0_ring_pad_ib                         99     127     +28
sdma_v2_4_ring_pad_ib                         99     127     +28
cik_sdma_ring_pad_ib                          99     127     +28
si_dma_ring_pad_ib                            36      44      +8
amdgpu_ring_generic_pad_ib                    56      52      -4
si_dma_emit_fill_buffer                      108      71     -37
si_dma_vm_write_pte                          158     115     -43
amdgpu_vcn_dec_sw_send_msg                   810     767     -43
si_dma_vm_copy_pte                           137      87     -50
si_dma_emit_copy_buffer                      134      84     -50
sdma_v3_0_vm_write_pte                       163     102     -61
sdma_v2_4_vm_write_pte                       163     102     -61
cik_sdma_vm_write_pte                        163     102     -61
sdma_v7_0_vm_write_pte                       168     105     -63
sdma_v7_0_emit_fill_buffer                   119      56     -63
sdma_v6_0_vm_write_pte                       168     105     -63
sdma_v6_0_emit_fill_buffer                   119      56     -63
sdma_v5_2_vm_write_pte                       168     105     -63
sdma_v5_2_emit_fill_buffer                   119      56     -63
sdma_v5_0_vm_write_pte                       168     105     -63
sdma_v5_0_emit_fill_buffer                   119      56     -63
sdma_v4_4_2_vm_write_pte                     168     105     -63
sdma_v4_4_2_emit_fill_buffer                 119      56     -63
sdma_v4_0_vm_write_pte                       168     105     -63
sdma_v4_0_emit_fill_buffer                   119      56     -63
sdma_v3_0_emit_fill_buffer                   116      53     -63
sdma_v2_4_emit_fill_buffer                   116      53     -63
cik_sdma_emit_fill_buffer                    116      53     -63
sdma_v6_0_emit_copy_buffer                   169      76     -93
sdma_v5_2_emit_copy_buffer                   169      76     -93
sdma_v5_0_emit_copy_buffer                   169      76     -93
sdma_v4_4_2_emit_copy_buffer                 169      76     -93
sdma_v4_0_emit_copy_buffer                   169      76     -93
sdma_v3_0_vm_copy_pte                        158      64     -94
sdma_v3_0_emit_copy_buffer                   155      61     -94
sdma_v2_4_vm_copy_pte                        158      64     -94
sdma_v2_4_emit_copy_buffer                   155      61     -94
cik_sdma_vm_copy_pte                         158      64     -94
cik_sdma_emit_copy_buffer                    155      61     -94
sdma_v6_0_vm_copy_pte                        163      68     -95
sdma_v5_2_vm_copy_pte                        163      68     -95
sdma_v5_0_vm_copy_pte                        163      68     -95
sdma_v4_4_2_vm_copy_pte                      163      68     -95
sdma_v4_0_vm_copy_pte                        163      68     -95
sdma_v7_0_vm_copy_pte                        183      75    -108
sdma_v7_0_emit_copy_buffer                   317     202    -115
si_dma_vm_set_pte_pde                        338     214    -124
amdgpu_vce_get_destroy_msg                   784     652    -132
sdma_v7_0_vm_set_pte_pde                     218      72    -146
sdma_v6_0_vm_set_pte_pde                     218      72    -146
sdma_v5_2_vm_set_pte_pde                     218      72    -146
sdma_v5_0_vm_set_pte_pde                     218      72    -146
sdma_v4_4_2_vm_set_pte_pde                   218      72    -146
sdma_v4_0_vm_set_pte_pde                     218      72    -146
sdma_v3_0_vm_set_pte_pde                     215      69    -146
sdma_v2_4_vm_set_pte_pde                     215      69    -146
cik_sdma_vm_set_pte_pde                      215      69    -146
amdgpu_vcn_unified_ring_ib_header            172       -    -172
gfx_v9_4_2_run_shader.constprop              739     532    -207
uvd_v6_0_enc_ring_test_ib                   1464    1162    -302
uvd_v7_0_enc_ring_test_ib                   1464    1138    -326
amdgpu_vce_ring_test_ib                     1357     936    -421
amdgpu_vcn_enc_ring_test_ib                 2042    1524    -518

Total: Before=9262623, After=9256285, chg -0.07%

* Notice how _pad_ib functions have grown. I think the compiler used the opportunity to unroll the loops.

** Series was only smoke tested on the Steam Deck.

Tvrtko Ursulin (16):

     drm/amdgpu: Use memset32 for IB padding
     drm/amdgpu: More compact VCE IB emission
     drm/amdgpu: More compact VCN IB emission
     drm/amdgpu: More compact UVD 6 IB emission
     drm/amdgpu: More compact UVD 7 IB emission
     drm/amdgpu: More compact SI SDMA emission
     drm/amdgpu: More compact CIK SDMA IB emission
     drm/amdgpu: More compact GFX 9.4.2 IB emission
     drm/amdgpu: More compact SDMA 2.4 IB emission
     drm/amdgpu: More compact SDMA 3.0 IB emission
     drm/amdgpu: More compact SDMA 4.0 IB emission
     drm/amdgpu: More compact SDMA 4.4.2 IB emission
     drm/amdgpu: More compact SDMA 5.0 IB emission
     drm/amdgpu: More compact SDMA 5.2 IB emission
     drm/amdgpu: More compact SDMA 6.0 IB emission
     drm/amdgpu: More compact SDMA 7.0 IB emission

    drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c |  12 ++-
    drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c  |  90 +++++++++--------
    drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c  | 101 ++++++++++---------
    drivers/gpu/drm/amd/amdgpu/cik_sdma.c    | 105 ++++++++++++--------
    drivers/gpu/drm/amd/amdgpu/gfx_v9_4_2.c  |  46 ++++-----
    drivers/gpu/drm/amd/amdgpu/sdma_v2_4.c   | 108 ++++++++++++--------
    drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c   | 108 ++++++++++++--------
    drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c   | 109 ++++++++++++---------
    drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c | 108 ++++++++++++--------
    drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c   | 106 ++++++++++++--------
    drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c   | 110 ++++++++++++---------
    drivers/gpu/drm/amd/amdgpu/sdma_v6_0.c   | 110 ++++++++++++---------
    drivers/gpu/drm/amd/amdgpu/sdma_v7_0.c   | 119 +++++++++++++----------
    drivers/gpu/drm/amd/amdgpu/si_dma.c      |  84 +++++++++-------
    drivers/gpu/drm/amd/amdgpu/uvd_v6_0.c    |  66 +++++++------
    drivers/gpu/drm/amd/amdgpu/uvd_v7_0.c    |  66 +++++++------
    16 files changed, 849 insertions(+), 599 deletions(-)

--
2.48.0

#23 lore raw
Quoted 31 lines · Tvrtko Ursulin
Quoted 28 lines · Alex Deucher
Quoted 26 lines · Tvrtko Ursulin
Quoted 7 lines · Alex Deucher
Quoted 5 lines · Tvrtko Ursulin
Quoted 1 line · Alex Deucher

Applied the series. Thanks!

Quoted 8 lines
Quoted 2 lines

Thank you and fingers crossed I did not fat finger anything that your CI wouldn't find!

Sorry for the late reply. This series broke the VCN IB tests on at least navi4x. The issue is a GPUVM page fault caused by VCN when running the IB tests.
I don't see any obvious problems with the patches, but I haven't had a chance to dig too much further.

Oh I see the problem.. sorry about that.

I missed the fact that after amdgpu_vcn_unified_ring_ib_header() I need to update the pointer.

Good news is that only VCN has this pattern.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Okay to send a fix next week? Would you need a fixup or a replacement patch in case you want to revert it in the meantime?

Fixup is fine. I'll squash it into the original VCN patch and give it a test next week.

How did it go? I noticed amd-staging-drm-next currently has the original buggy version.

Those were reverted.

Quoted 3 lines

Given other patches from the series are also missing perhaps you are testing it in stages?

I was running it through CI again and noticed that polaris seems to regress with these changes, so likely related to the VCE or UVD v6 changes.

Alex

Quoted 169 lines

Regards,

Tvrtko

Quoted 163 lines
Quoted 163 lines
Quoted 162 lines
Quoted 162 lines

I wish something similar could be done for amdgpu_ring_write too, but that one is waiting on Christian to, AFAIR, become idle enough to untangle some ptr masking issues.

Regards,

Tvrtko

Quoted 153 lines
Quoted 151 lines · Tvrtko Ursulin

In short, this series mostly does a lot of replacing of this pattern:

          ib->ptr[ib->length_dw++] = SDMA_PKT_HEADER_OP(SDMA_OP_WRITE) |
                  SDMA_PKT_HEADER_SUB_OP(SDMA_SUBOP_WRITE_LINEAR);
          ib->ptr[ib->length_dw++] = lower_32_bits(pe);
          ib->ptr[ib->length_dw++] = upper_32_bits(pe);
          ib->ptr[ib->length_dw++] = ndw - 1;
          for (; ndw > 0; ndw -= 2) {
                 ib->ptr[ib->length_dw++] = lower_32_bits(value);
                 ib->ptr[ib->length_dw++] = upper_32_bits(value);
                  value += incr;
          }

With this one:

          u32 *ptr = &ib->ptr[ib->length_dw];

          *ptr++ = SDMA_PKT_HEADER_OP(SDMA_OP_WRITE) |
                   SDMA_PKT_HEADER_SUB_OP(SDMA_SUBOP_WRITE_LINEAR);
          *ptr++ = lower_32_bits(pe);
          *ptr++ = upper_32_bits(pe);
          *ptr++ = ndw - 1;
          for (; ndw > 0; ndw -= 2) {
                  *ptr++ = lower_32_bits(value);
                  *ptr++ = upper_32_bits(value);
                   value += incr;
           }

          ib->length_dw = ptr - ib->ptr;

Latter avoids register reloads and length updates on every dword written, and on the overall makes the IB emission much more compact:

add/remove: 0/1 grow/shrink: 10/58 up/down: 260/-6598 (-6338)

Function                                     old     new   delta
sdma_v7_0_ring_pad_ib                         99     127     +28
sdma_v6_0_ring_pad_ib                         99     127     +28
sdma_v5_2_ring_pad_ib                         99     127     +28
sdma_v5_0_ring_pad_ib                         99     127     +28
sdma_v4_4_2_ring_pad_ib                       99     127     +28
sdma_v4_0_ring_pad_ib                         99     127     +28
sdma_v3_0_ring_pad_ib                         99     127     +28
sdma_v2_4_ring_pad_ib                         99     127     +28
cik_sdma_ring_pad_ib                          99     127     +28
si_dma_ring_pad_ib                            36      44      +8
amdgpu_ring_generic_pad_ib                    56      52      -4
si_dma_emit_fill_buffer                      108      71     -37
si_dma_vm_write_pte                          158     115     -43
amdgpu_vcn_dec_sw_send_msg                   810     767     -43
si_dma_vm_copy_pte                           137      87     -50
si_dma_emit_copy_buffer                      134      84     -50
sdma_v3_0_vm_write_pte                       163     102     -61
sdma_v2_4_vm_write_pte                       163     102     -61
cik_sdma_vm_write_pte                        163     102     -61
sdma_v7_0_vm_write_pte                       168     105     -63
sdma_v7_0_emit_fill_buffer                   119      56     -63
sdma_v6_0_vm_write_pte                       168     105     -63
sdma_v6_0_emit_fill_buffer                   119      56     -63
sdma_v5_2_vm_write_pte                       168     105     -63
sdma_v5_2_emit_fill_buffer                   119      56     -63
sdma_v5_0_vm_write_pte                       168     105     -63
sdma_v5_0_emit_fill_buffer                   119      56     -63
sdma_v4_4_2_vm_write_pte                     168     105     -63
sdma_v4_4_2_emit_fill_buffer                 119      56     -63
sdma_v4_0_vm_write_pte                       168     105     -63
sdma_v4_0_emit_fill_buffer                   119      56     -63
sdma_v3_0_emit_fill_buffer                   116      53     -63
sdma_v2_4_emit_fill_buffer                   116      53     -63
cik_sdma_emit_fill_buffer                    116      53     -63
sdma_v6_0_emit_copy_buffer                   169      76     -93
sdma_v5_2_emit_copy_buffer                   169      76     -93
sdma_v5_0_emit_copy_buffer                   169      76     -93
sdma_v4_4_2_emit_copy_buffer                 169      76     -93
sdma_v4_0_emit_copy_buffer                   169      76     -93
sdma_v3_0_vm_copy_pte                        158      64     -94
sdma_v3_0_emit_copy_buffer                   155      61     -94
sdma_v2_4_vm_copy_pte                        158      64     -94
sdma_v2_4_emit_copy_buffer                   155      61     -94
cik_sdma_vm_copy_pte                         158      64     -94
cik_sdma_emit_copy_buffer                    155      61     -94
sdma_v6_0_vm_copy_pte                        163      68     -95
sdma_v5_2_vm_copy_pte                        163      68     -95
sdma_v5_0_vm_copy_pte                        163      68     -95
sdma_v4_4_2_vm_copy_pte                      163      68     -95
sdma_v4_0_vm_copy_pte                        163      68     -95
sdma_v7_0_vm_copy_pte                        183      75    -108
sdma_v7_0_emit_copy_buffer                   317     202    -115
si_dma_vm_set_pte_pde                        338     214    -124
amdgpu_vce_get_destroy_msg                   784     652    -132
sdma_v7_0_vm_set_pte_pde                     218      72    -146
sdma_v6_0_vm_set_pte_pde                     218      72    -146
sdma_v5_2_vm_set_pte_pde                     218      72    -146
sdma_v5_0_vm_set_pte_pde                     218      72    -146
sdma_v4_4_2_vm_set_pte_pde                   218      72    -146
sdma_v4_0_vm_set_pte_pde                     218      72    -146
sdma_v3_0_vm_set_pte_pde                     215      69    -146
sdma_v2_4_vm_set_pte_pde                     215      69    -146
cik_sdma_vm_set_pte_pde                      215      69    -146
amdgpu_vcn_unified_ring_ib_header            172       -    -172
gfx_v9_4_2_run_shader.constprop              739     532    -207
uvd_v6_0_enc_ring_test_ib                   1464    1162    -302
uvd_v7_0_enc_ring_test_ib                   1464    1138    -326
amdgpu_vce_ring_test_ib                     1357     936    -421
amdgpu_vcn_enc_ring_test_ib                 2042    1524    -518

Total: Before=9262623, After=9256285, chg -0.07%

* Notice how _pad_ib functions have grown. I think the compiler used the opportunity to unroll the loops.

** Series was only smoke tested on the Steam Deck.

Tvrtko Ursulin (16):

     drm/amdgpu: Use memset32 for IB padding
     drm/amdgpu: More compact VCE IB emission
     drm/amdgpu: More compact VCN IB emission
     drm/amdgpu: More compact UVD 6 IB emission
     drm/amdgpu: More compact UVD 7 IB emission
     drm/amdgpu: More compact SI SDMA emission
     drm/amdgpu: More compact CIK SDMA IB emission
     drm/amdgpu: More compact GFX 9.4.2 IB emission
     drm/amdgpu: More compact SDMA 2.4 IB emission
     drm/amdgpu: More compact SDMA 3.0 IB emission
     drm/amdgpu: More compact SDMA 4.0 IB emission
     drm/amdgpu: More compact SDMA 4.4.2 IB emission
     drm/amdgpu: More compact SDMA 5.0 IB emission
     drm/amdgpu: More compact SDMA 5.2 IB emission
     drm/amdgpu: More compact SDMA 6.0 IB emission
     drm/amdgpu: More compact SDMA 7.0 IB emission

    drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c |  12 ++-
    drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c  |  90 +++++++++--------
    drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c  | 101 ++++++++++---------
    drivers/gpu/drm/amd/amdgpu/cik_sdma.c    | 105 ++++++++++++--------
    drivers/gpu/drm/amd/amdgpu/gfx_v9_4_2.c  |  46 ++++-----
    drivers/gpu/drm/amd/amdgpu/sdma_v2_4.c   | 108 ++++++++++++--------
    drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c   | 108 ++++++++++++--------
    drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c   | 109 ++++++++++++---------
    drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c | 108 ++++++++++++--------
    drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c   | 106 ++++++++++++--------
    drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c   | 110 ++++++++++++---------
    drivers/gpu/drm/amd/amdgpu/sdma_v6_0.c   | 110 ++++++++++++---------
    drivers/gpu/drm/amd/amdgpu/sdma_v7_0.c   | 119 +++++++++++++----------
    drivers/gpu/drm/amd/amdgpu/si_dma.c      |  84 +++++++++-------
    drivers/gpu/drm/amd/amdgpu/uvd_v6_0.c    |  66 +++++++------
    drivers/gpu/drm/amd/amdgpu/uvd_v7_0.c    |  66 +++++++------
    16 files changed, 849 insertions(+), 599 deletions(-)

--
2.48.0

#24 lore raw
Quoted 45 lines · Alex Deucher
Quoted 31 lines · Tvrtko Ursulin
Quoted 28 lines · Alex Deucher
Quoted 26 lines · Tvrtko Ursulin
Quoted 7 lines · Alex Deucher
Quoted 5 lines · Tvrtko Ursulin
Quoted 1 line · Alex Deucher

Applied the series. Thanks!

Quoted 8 lines
Quoted 2 lines

Thank you and fingers crossed I did not fat finger anything that your CI wouldn't find!

Sorry for the late reply. This series broke the VCN IB tests on at least navi4x. The issue is a GPUVM page fault caused by VCN when running the IB tests.
I don't see any obvious problems with the patches, but I haven't had a chance to dig too much further.

Oh I see the problem.. sorry about that.

I missed the fact that after amdgpu_vcn_unified_ring_ib_header() I need to update the pointer.

Good news is that only VCN has this pattern.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Okay to send a fix next week? Would you need a fixup or a replacement patch in case you want to revert it in the meantime?

Fixup is fine. I'll squash it into the original VCN patch and give it a test next week.

How did it go? I noticed amd-staging-drm-next currently has the original buggy version.

Those were reverted.

Quoted 1 line
Quoted 6 lines
Quoted 2 lines

Given other patches from the series are also missing perhaps you are testing it in stages?

I was running it through CI again and noticed that polaris seems to regress with these changes, so likely related to the VCE or UVD v6 changes.

Not sure I follow and sorry if there is still some confusion.

I did not spot anything obviously wrong in VCE and UVD v6.

But currently a broken version of "drm/amdgpu: More compact VCN IB emission" is in the staging branch. It needs to be squashed with "drm/amdgpu: Fixup VCN IB emission".

Regards,

Tvrtko

Quoted 171 lines

Alex

Quoted 169 lines

Regards,

Tvrtko

Quoted 163 lines
Quoted 163 lines
Quoted 162 lines
Quoted 162 lines

I wish something similar could be done for amdgpu_ring_write too, but that one is waiting on Christian to, AFAIR, become idle enough to untangle some ptr masking issues.

Regards,

Tvrtko

Quoted 153 lines
Quoted 151 lines · Tvrtko Ursulin

In short, this series mostly does a lot of replacing of this pattern:

           ib->ptr[ib->length_dw++] = SDMA_PKT_HEADER_OP(SDMA_OP_WRITE) |
                   SDMA_PKT_HEADER_SUB_OP(SDMA_SUBOP_WRITE_LINEAR);
           ib->ptr[ib->length_dw++] = lower_32_bits(pe);
           ib->ptr[ib->length_dw++] = upper_32_bits(pe);
           ib->ptr[ib->length_dw++] = ndw - 1;
           for (; ndw > 0; ndw -= 2) {
                  ib->ptr[ib->length_dw++] = lower_32_bits(value);
                  ib->ptr[ib->length_dw++] = upper_32_bits(value);
                   value += incr;
           }

With this one:

           u32 *ptr = &ib->ptr[ib->length_dw];

           *ptr++ = SDMA_PKT_HEADER_OP(SDMA_OP_WRITE) |
                    SDMA_PKT_HEADER_SUB_OP(SDMA_SUBOP_WRITE_LINEAR);
           *ptr++ = lower_32_bits(pe);
           *ptr++ = upper_32_bits(pe);
           *ptr++ = ndw - 1;
           for (; ndw > 0; ndw -= 2) {
                   *ptr++ = lower_32_bits(value);
                   *ptr++ = upper_32_bits(value);
                    value += incr;
            }

           ib->length_dw = ptr - ib->ptr;

Latter avoids register reloads and length updates on every dword written, and on the overall makes the IB emission much more compact:

add/remove: 0/1 grow/shrink: 10/58 up/down: 260/-6598 (-6338)

Function                                     old     new   delta
sdma_v7_0_ring_pad_ib                         99     127     +28
sdma_v6_0_ring_pad_ib                         99     127     +28
sdma_v5_2_ring_pad_ib                         99     127     +28
sdma_v5_0_ring_pad_ib                         99     127     +28
sdma_v4_4_2_ring_pad_ib                       99     127     +28
sdma_v4_0_ring_pad_ib                         99     127     +28
sdma_v3_0_ring_pad_ib                         99     127     +28
sdma_v2_4_ring_pad_ib                         99     127     +28
cik_sdma_ring_pad_ib                          99     127     +28
si_dma_ring_pad_ib                            36      44      +8
amdgpu_ring_generic_pad_ib                    56      52      -4
si_dma_emit_fill_buffer                      108      71     -37
si_dma_vm_write_pte                          158     115     -43
amdgpu_vcn_dec_sw_send_msg                   810     767     -43
si_dma_vm_copy_pte                           137      87     -50
si_dma_emit_copy_buffer                      134      84     -50
sdma_v3_0_vm_write_pte                       163     102     -61
sdma_v2_4_vm_write_pte                       163     102     -61
cik_sdma_vm_write_pte                        163     102     -61
sdma_v7_0_vm_write_pte                       168     105     -63
sdma_v7_0_emit_fill_buffer                   119      56     -63
sdma_v6_0_vm_write_pte                       168     105     -63
sdma_v6_0_emit_fill_buffer                   119      56     -63
sdma_v5_2_vm_write_pte                       168     105     -63
sdma_v5_2_emit_fill_buffer                   119      56     -63
sdma_v5_0_vm_write_pte                       168     105     -63
sdma_v5_0_emit_fill_buffer                   119      56     -63
sdma_v4_4_2_vm_write_pte                     168     105     -63
sdma_v4_4_2_emit_fill_buffer                 119      56     -63
sdma_v4_0_vm_write_pte                       168     105     -63
sdma_v4_0_emit_fill_buffer                   119      56     -63
sdma_v3_0_emit_fill_buffer                   116      53     -63
sdma_v2_4_emit_fill_buffer                   116      53     -63
cik_sdma_emit_fill_buffer                    116      53     -63
sdma_v6_0_emit_copy_buffer                   169      76     -93
sdma_v5_2_emit_copy_buffer                   169      76     -93
sdma_v5_0_emit_copy_buffer                   169      76     -93
sdma_v4_4_2_emit_copy_buffer                 169      76     -93
sdma_v4_0_emit_copy_buffer                   169      76     -93
sdma_v3_0_vm_copy_pte                        158      64     -94
sdma_v3_0_emit_copy_buffer                   155      61     -94
sdma_v2_4_vm_copy_pte                        158      64     -94
sdma_v2_4_emit_copy_buffer                   155      61     -94
cik_sdma_vm_copy_pte                         158      64     -94
cik_sdma_emit_copy_buffer                    155      61     -94
sdma_v6_0_vm_copy_pte                        163      68     -95
sdma_v5_2_vm_copy_pte                        163      68     -95
sdma_v5_0_vm_copy_pte                        163      68     -95
sdma_v4_4_2_vm_copy_pte                      163      68     -95
sdma_v4_0_vm_copy_pte                        163      68     -95
sdma_v7_0_vm_copy_pte                        183      75    -108
sdma_v7_0_emit_copy_buffer                   317     202    -115
si_dma_vm_set_pte_pde                        338     214    -124
amdgpu_vce_get_destroy_msg                   784     652    -132
sdma_v7_0_vm_set_pte_pde                     218      72    -146
sdma_v6_0_vm_set_pte_pde                     218      72    -146
sdma_v5_2_vm_set_pte_pde                     218      72    -146
sdma_v5_0_vm_set_pte_pde                     218      72    -146
sdma_v4_4_2_vm_set_pte_pde                   218      72    -146
sdma_v4_0_vm_set_pte_pde                     218      72    -146
sdma_v3_0_vm_set_pte_pde                     215      69    -146
sdma_v2_4_vm_set_pte_pde                     215      69    -146
cik_sdma_vm_set_pte_pde                      215      69    -146
amdgpu_vcn_unified_ring_ib_header            172       -    -172
gfx_v9_4_2_run_shader.constprop              739     532    -207
uvd_v6_0_enc_ring_test_ib                   1464    1162    -302
uvd_v7_0_enc_ring_test_ib                   1464    1138    -326
amdgpu_vce_ring_test_ib                     1357     936    -421
amdgpu_vcn_enc_ring_test_ib                 2042    1524    -518

Total: Before=9262623, After=9256285, chg -0.07%

* Notice how _pad_ib functions have grown. I think the compiler used the opportunity to unroll the loops.

** Series was only smoke tested on the Steam Deck.

Tvrtko Ursulin (16):

      drm/amdgpu: Use memset32 for IB padding
      drm/amdgpu: More compact VCE IB emission
      drm/amdgpu: More compact VCN IB emission
      drm/amdgpu: More compact UVD 6 IB emission
      drm/amdgpu: More compact UVD 7 IB emission
      drm/amdgpu: More compact SI SDMA emission
      drm/amdgpu: More compact CIK SDMA IB emission
      drm/amdgpu: More compact GFX 9.4.2 IB emission
      drm/amdgpu: More compact SDMA 2.4 IB emission
      drm/amdgpu: More compact SDMA 3.0 IB emission
      drm/amdgpu: More compact SDMA 4.0 IB emission
      drm/amdgpu: More compact SDMA 4.4.2 IB emission
      drm/amdgpu: More compact SDMA 5.0 IB emission
      drm/amdgpu: More compact SDMA 5.2 IB emission
      drm/amdgpu: More compact SDMA 6.0 IB emission
      drm/amdgpu: More compact SDMA 7.0 IB emission

     drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c |  12 ++-
     drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c  |  90 +++++++++--------
     drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c  | 101 ++++++++++---------
     drivers/gpu/drm/amd/amdgpu/cik_sdma.c    | 105 ++++++++++++--------
     drivers/gpu/drm/amd/amdgpu/gfx_v9_4_2.c  |  46 ++++-----
     drivers/gpu/drm/amd/amdgpu/sdma_v2_4.c   | 108 ++++++++++++--------
     drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c   | 108 ++++++++++++--------
     drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c   | 109 ++++++++++++---------
     drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c | 108 ++++++++++++--------
     drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c   | 106 ++++++++++++--------
     drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c   | 110 ++++++++++++---------
     drivers/gpu/drm/amd/amdgpu/sdma_v6_0.c   | 110 ++++++++++++---------
     drivers/gpu/drm/amd/amdgpu/sdma_v7_0.c   | 119 +++++++++++++----------
     drivers/gpu/drm/amd/amdgpu/si_dma.c      |  84 +++++++++-------
     drivers/gpu/drm/amd/amdgpu/uvd_v6_0.c    |  66 +++++++------
     drivers/gpu/drm/amd/amdgpu/uvd_v7_0.c    |  66 +++++++------
     16 files changed, 849 insertions(+), 599 deletions(-)

--
2.48.0

#25 lore raw
Quoted 55 lines · Tvrtko Ursulin
Quoted 45 lines · Alex Deucher
Quoted 31 lines · Tvrtko Ursulin
Quoted 28 lines · Alex Deucher
Quoted 26 lines · Tvrtko Ursulin
Quoted 7 lines · Alex Deucher
Quoted 5 lines · Tvrtko Ursulin
Quoted 1 line · Alex Deucher

Applied the series. Thanks!

Quoted 8 lines
Quoted 2 lines

Thank you and fingers crossed I did not fat finger anything that your CI wouldn't find!

Sorry for the late reply. This series broke the VCN IB tests on at least navi4x. The issue is a GPUVM page fault caused by VCN when running the IB tests.
I don't see any obvious problems with the patches, but I haven't had a chance to dig too much further.

Oh I see the problem.. sorry about that.

I missed the fact that after amdgpu_vcn_unified_ring_ib_header() I need to update the pointer.

Good news is that only VCN has this pattern.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Okay to send a fix next week? Would you need a fixup or a replacement patch in case you want to revert it in the meantime?

Fixup is fine. I'll squash it into the original VCN patch and give it a test next week.

How did it go? I noticed amd-staging-drm-next currently has the original buggy version.

Those were reverted.

Quoted 1 line
Quoted 6 lines
Quoted 2 lines

Given other patches from the series are also missing perhaps you are testing it in stages?

I was running it through CI again and noticed that polaris seems to regress with these changes, so likely related to the VCE or UVD v6 changes.

Quoted 7 lines

Not sure I follow and sorry if there is still some confusion.

I did not spot anything obviously wrong in VCE and UVD v6.

But currently a broken version of "drm/amdgpu: More compact VCN IB emission" is in the staging branch. It needs to be squashed with "drm/amdgpu: Fixup VCN IB emission".

It's already been reverted:
https://gitlab.freedesktop.org/agd5f/linux/-/commit/bdb17ea8a391885c884d4e8dfb27a1e22d3d03ce

I was planning to land the whole series along with the VCN fix squashed into the original, but the CI for polaris keeps failing with this set. I haven't had time to dig further yet.

Alex

Quoted 178 lines

Regards,

Tvrtko

Quoted 171 lines

Alex

Quoted 169 lines

Regards,

Tvrtko

Quoted 163 lines
Quoted 163 lines
Quoted 162 lines
Quoted 162 lines

I wish something similar could be done for amdgpu_ring_write too, but that one is waiting on Christian to, AFAIR, become idle enough to untangle some ptr masking issues.

Regards,

Tvrtko

Quoted 153 lines
Quoted 151 lines · Tvrtko Ursulin

In short, this series mostly does a lot of replacing of this pattern:

           ib->ptr[ib->length_dw++] = SDMA_PKT_HEADER_OP(SDMA_OP_WRITE) |
                   SDMA_PKT_HEADER_SUB_OP(SDMA_SUBOP_WRITE_LINEAR);
           ib->ptr[ib->length_dw++] = lower_32_bits(pe);
           ib->ptr[ib->length_dw++] = upper_32_bits(pe);
           ib->ptr[ib->length_dw++] = ndw - 1;
           for (; ndw > 0; ndw -= 2) {
                  ib->ptr[ib->length_dw++] = lower_32_bits(value);
                  ib->ptr[ib->length_dw++] = upper_32_bits(value);
                   value += incr;
           }

With this one:

           u32 *ptr = &ib->ptr[ib->length_dw];

           *ptr++ = SDMA_PKT_HEADER_OP(SDMA_OP_WRITE) |
                    SDMA_PKT_HEADER_SUB_OP(SDMA_SUBOP_WRITE_LINEAR);
           *ptr++ = lower_32_bits(pe);
           *ptr++ = upper_32_bits(pe);
           *ptr++ = ndw - 1;
           for (; ndw > 0; ndw -= 2) {
                   *ptr++ = lower_32_bits(value);
                   *ptr++ = upper_32_bits(value);
                    value += incr;
            }

           ib->length_dw = ptr - ib->ptr;

Latter avoids register reloads and length updates on every dword written, and on the overall makes the IB emission much more compact:

add/remove: 0/1 grow/shrink: 10/58 up/down: 260/-6598 (-6338)

Function                                     old     new   delta
sdma_v7_0_ring_pad_ib                         99     127     +28
sdma_v6_0_ring_pad_ib                         99     127     +28
sdma_v5_2_ring_pad_ib                         99     127     +28
sdma_v5_0_ring_pad_ib                         99     127     +28
sdma_v4_4_2_ring_pad_ib                       99     127     +28
sdma_v4_0_ring_pad_ib                         99     127     +28
sdma_v3_0_ring_pad_ib                         99     127     +28
sdma_v2_4_ring_pad_ib                         99     127     +28
cik_sdma_ring_pad_ib                          99     127     +28
si_dma_ring_pad_ib                            36      44      +8
amdgpu_ring_generic_pad_ib                    56      52      -4
si_dma_emit_fill_buffer                      108      71     -37
si_dma_vm_write_pte                          158     115     -43
amdgpu_vcn_dec_sw_send_msg                   810     767     -43
si_dma_vm_copy_pte                           137      87     -50
si_dma_emit_copy_buffer                      134      84     -50
sdma_v3_0_vm_write_pte                       163     102     -61
sdma_v2_4_vm_write_pte                       163     102     -61
cik_sdma_vm_write_pte                        163     102     -61
sdma_v7_0_vm_write_pte                       168     105     -63
sdma_v7_0_emit_fill_buffer                   119      56     -63
sdma_v6_0_vm_write_pte                       168     105     -63
sdma_v6_0_emit_fill_buffer                   119      56     -63
sdma_v5_2_vm_write_pte                       168     105     -63
sdma_v5_2_emit_fill_buffer                   119      56     -63
sdma_v5_0_vm_write_pte                       168     105     -63
sdma_v5_0_emit_fill_buffer                   119      56     -63
sdma_v4_4_2_vm_write_pte                     168     105     -63
sdma_v4_4_2_emit_fill_buffer                 119      56     -63
sdma_v4_0_vm_write_pte                       168     105     -63
sdma_v4_0_emit_fill_buffer                   119      56     -63
sdma_v3_0_emit_fill_buffer                   116      53     -63
sdma_v2_4_emit_fill_buffer                   116      53     -63
cik_sdma_emit_fill_buffer                    116      53     -63
sdma_v6_0_emit_copy_buffer                   169      76     -93
sdma_v5_2_emit_copy_buffer                   169      76     -93
sdma_v5_0_emit_copy_buffer                   169      76     -93
sdma_v4_4_2_emit_copy_buffer                 169      76     -93
sdma_v4_0_emit_copy_buffer                   169      76     -93
sdma_v3_0_vm_copy_pte                        158      64     -94
sdma_v3_0_emit_copy_buffer                   155      61     -94
sdma_v2_4_vm_copy_pte                        158      64     -94
sdma_v2_4_emit_copy_buffer                   155      61     -94
cik_sdma_vm_copy_pte                         158      64     -94
cik_sdma_emit_copy_buffer                    155      61     -94
sdma_v6_0_vm_copy_pte                        163      68     -95
sdma_v5_2_vm_copy_pte                        163      68     -95
sdma_v5_0_vm_copy_pte                        163      68     -95
sdma_v4_4_2_vm_copy_pte                      163      68     -95
sdma_v4_0_vm_copy_pte                        163      68     -95
sdma_v7_0_vm_copy_pte                        183      75    -108
sdma_v7_0_emit_copy_buffer                   317     202    -115
si_dma_vm_set_pte_pde                        338     214    -124
amdgpu_vce_get_destroy_msg                   784     652    -132
sdma_v7_0_vm_set_pte_pde                     218      72    -146
sdma_v6_0_vm_set_pte_pde                     218      72    -146
sdma_v5_2_vm_set_pte_pde                     218      72    -146
sdma_v5_0_vm_set_pte_pde                     218      72    -146
sdma_v4_4_2_vm_set_pte_pde                   218      72    -146
sdma_v4_0_vm_set_pte_pde                     218      72    -146
sdma_v3_0_vm_set_pte_pde                     215      69    -146
sdma_v2_4_vm_set_pte_pde                     215      69    -146
cik_sdma_vm_set_pte_pde                      215      69    -146
amdgpu_vcn_unified_ring_ib_header            172       -    -172
gfx_v9_4_2_run_shader.constprop              739     532    -207
uvd_v6_0_enc_ring_test_ib                   1464    1162    -302
uvd_v7_0_enc_ring_test_ib                   1464    1138    -326
amdgpu_vce_ring_test_ib                     1357     936    -421
amdgpu_vcn_enc_ring_test_ib                 2042    1524    -518

Total: Before=9262623, After=9256285, chg -0.07%

* Notice how _pad_ib functions have grown. I think the compiler used the opportunity to unroll the loops.

** Series was only smoke tested on the Steam Deck.

Tvrtko Ursulin (16):

      drm/amdgpu: Use memset32 for IB padding
      drm/amdgpu: More compact VCE IB emission
      drm/amdgpu: More compact VCN IB emission
      drm/amdgpu: More compact UVD 6 IB emission
      drm/amdgpu: More compact UVD 7 IB emission
      drm/amdgpu: More compact SI SDMA emission
      drm/amdgpu: More compact CIK SDMA IB emission
      drm/amdgpu: More compact GFX 9.4.2 IB emission
      drm/amdgpu: More compact SDMA 2.4 IB emission
      drm/amdgpu: More compact SDMA 3.0 IB emission
      drm/amdgpu: More compact SDMA 4.0 IB emission
      drm/amdgpu: More compact SDMA 4.4.2 IB emission
      drm/amdgpu: More compact SDMA 5.0 IB emission
      drm/amdgpu: More compact SDMA 5.2 IB emission
      drm/amdgpu: More compact SDMA 6.0 IB emission
      drm/amdgpu: More compact SDMA 7.0 IB emission

     drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c |  12 ++-
     drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c  |  90 +++++++++--------
     drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c  | 101 ++++++++++---------
     drivers/gpu/drm/amd/amdgpu/cik_sdma.c    | 105 ++++++++++++--------
     drivers/gpu/drm/amd/amdgpu/gfx_v9_4_2.c  |  46 ++++-----
     drivers/gpu/drm/amd/amdgpu/sdma_v2_4.c   | 108 ++++++++++++--------
     drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c   | 108 ++++++++++++--------
     drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c   | 109 ++++++++++++---------
     drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c | 108 ++++++++++++--------
     drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c   | 106 ++++++++++++--------
     drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c   | 110 ++++++++++++---------
     drivers/gpu/drm/amd/amdgpu/sdma_v6_0.c   | 110 ++++++++++++---------
     drivers/gpu/drm/amd/amdgpu/sdma_v7_0.c   | 119 +++++++++++++----------
     drivers/gpu/drm/amd/amdgpu/si_dma.c      |  84 +++++++++-------
     drivers/gpu/drm/amd/amdgpu/uvd_v6_0.c    |  66 +++++++------
     drivers/gpu/drm/amd/amdgpu/uvd_v7_0.c    |  66 +++++++------
     16 files changed, 849 insertions(+), 599 deletions(-)

--
2.48.0

#26 lore raw
Quoted 65 lines · Alex Deucher
Quoted 55 lines · Tvrtko Ursulin
Quoted 45 lines · Alex Deucher
Quoted 31 lines · Tvrtko Ursulin
Quoted 28 lines · Alex Deucher
Quoted 26 lines · Tvrtko Ursulin
Quoted 7 lines · Alex Deucher
Quoted 5 lines · Tvrtko Ursulin
Quoted 1 line · Alex Deucher

Applied the series. Thanks!

Quoted 8 lines
Quoted 2 lines

Thank you and fingers crossed I did not fat finger anything that your CI wouldn't find!

Sorry for the late reply. This series broke the VCN IB tests on at least navi4x. The issue is a GPUVM page fault caused by VCN when running the IB tests.
I don't see any obvious problems with the patches, but I haven't had a chance to dig too much further.

Oh I see the problem.. sorry about that.

I missed the fact that after amdgpu_vcn_unified_ring_ib_header() I need to update the pointer.

Good news is that only VCN has this pattern.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Okay to send a fix next week? Would you need a fixup or a replacement patch in case you want to revert it in the meantime?

Fixup is fine. I'll squash it into the original VCN patch and give it a test next week.

How did it go? I noticed amd-staging-drm-next currently has the original buggy version.

Those were reverted.

Quoted 1 line
Quoted 6 lines
Quoted 2 lines

Given other patches from the series are also missing perhaps you are testing it in stages?

I was running it through CI again and noticed that polaris seems to regress with these changes, so likely related to the VCE or UVD v6 changes.

Quoted 7 lines

Not sure I follow and sorry if there is still some confusion.

I did not spot anything obviously wrong in VCE and UVD v6.

But currently a broken version of "drm/amdgpu: More compact VCN IB emission" is in the staging branch. It needs to be squashed with "drm/amdgpu: Fixup VCN IB emission".

Quoted 6 lines

It's already been reverted:
https://gitlab.freedesktop.org/agd5f/linux/-/commit/bdb17ea8a391885c884d4e8dfb27a1e22d3d03ce

I was planning to land the whole series along with the VCN fix squashed into the original, but the CI for polaris keeps failing with this set. I haven't had time to dig further yet.

Ah you probably mean VCN is not relevant for Polaris? What do you recommend for sort of a code name to IP block version decoding? If something like that exists in the public domain.

Regards,

Tvrtko

Quoted 165 lines
Quoted 165 lines
Quoted 164 lines
Quoted 164 lines
Quoted 163 lines
Quoted 163 lines
Quoted 162 lines
Quoted 162 lines

I wish something similar could be done for amdgpu_ring_write too, but that one is waiting on Christian to, AFAIR, become idle enough to untangle some ptr masking issues.

Regards,

Tvrtko

Quoted 153 lines
Quoted 151 lines · Tvrtko Ursulin

In short, this series mostly does a lot of replacing of this pattern:

            ib->ptr[ib->length_dw++] = SDMA_PKT_HEADER_OP(SDMA_OP_WRITE) |
                    SDMA_PKT_HEADER_SUB_OP(SDMA_SUBOP_WRITE_LINEAR);
            ib->ptr[ib->length_dw++] = lower_32_bits(pe);
            ib->ptr[ib->length_dw++] = upper_32_bits(pe);
            ib->ptr[ib->length_dw++] = ndw - 1;
            for (; ndw > 0; ndw -= 2) {
                   ib->ptr[ib->length_dw++] = lower_32_bits(value);
                   ib->ptr[ib->length_dw++] = upper_32_bits(value);
                    value += incr;
            }

With this one:

            u32 *ptr = &ib->ptr[ib->length_dw];

            *ptr++ = SDMA_PKT_HEADER_OP(SDMA_OP_WRITE) |
                     SDMA_PKT_HEADER_SUB_OP(SDMA_SUBOP_WRITE_LINEAR);
            *ptr++ = lower_32_bits(pe);
            *ptr++ = upper_32_bits(pe);
            *ptr++ = ndw - 1;
            for (; ndw > 0; ndw -= 2) {
                    *ptr++ = lower_32_bits(value);
                    *ptr++ = upper_32_bits(value);
                     value += incr;
             }

            ib->length_dw = ptr - ib->ptr;

Latter avoids register reloads and length updates on every dword written, and on the overall makes the IB emission much more compact:

add/remove: 0/1 grow/shrink: 10/58 up/down: 260/-6598 (-6338)

Function                                     old     new   delta
sdma_v7_0_ring_pad_ib                         99     127     +28
sdma_v6_0_ring_pad_ib                         99     127     +28
sdma_v5_2_ring_pad_ib                         99     127     +28
sdma_v5_0_ring_pad_ib                         99     127     +28
sdma_v4_4_2_ring_pad_ib                       99     127     +28
sdma_v4_0_ring_pad_ib                         99     127     +28
sdma_v3_0_ring_pad_ib                         99     127     +28
sdma_v2_4_ring_pad_ib                         99     127     +28
cik_sdma_ring_pad_ib                          99     127     +28
si_dma_ring_pad_ib                            36      44      +8
amdgpu_ring_generic_pad_ib                    56      52      -4
si_dma_emit_fill_buffer                      108      71     -37
si_dma_vm_write_pte                          158     115     -43
amdgpu_vcn_dec_sw_send_msg                   810     767     -43
si_dma_vm_copy_pte                           137      87     -50
si_dma_emit_copy_buffer                      134      84     -50
sdma_v3_0_vm_write_pte                       163     102     -61
sdma_v2_4_vm_write_pte                       163     102     -61
cik_sdma_vm_write_pte                        163     102     -61
sdma_v7_0_vm_write_pte                       168     105     -63
sdma_v7_0_emit_fill_buffer                   119      56     -63
sdma_v6_0_vm_write_pte                       168     105     -63
sdma_v6_0_emit_fill_buffer                   119      56     -63
sdma_v5_2_vm_write_pte                       168     105     -63
sdma_v5_2_emit_fill_buffer                   119      56     -63
sdma_v5_0_vm_write_pte                       168     105     -63
sdma_v5_0_emit_fill_buffer                   119      56     -63
sdma_v4_4_2_vm_write_pte                     168     105     -63
sdma_v4_4_2_emit_fill_buffer                 119      56     -63
sdma_v4_0_vm_write_pte                       168     105     -63
sdma_v4_0_emit_fill_buffer                   119      56     -63
sdma_v3_0_emit_fill_buffer                   116      53     -63
sdma_v2_4_emit_fill_buffer                   116      53     -63
cik_sdma_emit_fill_buffer                    116      53     -63
sdma_v6_0_emit_copy_buffer                   169      76     -93
sdma_v5_2_emit_copy_buffer                   169      76     -93
sdma_v5_0_emit_copy_buffer                   169      76     -93
sdma_v4_4_2_emit_copy_buffer                 169      76     -93
sdma_v4_0_emit_copy_buffer                   169      76     -93
sdma_v3_0_vm_copy_pte                        158      64     -94
sdma_v3_0_emit_copy_buffer                   155      61     -94
sdma_v2_4_vm_copy_pte                        158      64     -94
sdma_v2_4_emit_copy_buffer                   155      61     -94
cik_sdma_vm_copy_pte                         158      64     -94
cik_sdma_emit_copy_buffer                    155      61     -94
sdma_v6_0_vm_copy_pte                        163      68     -95
sdma_v5_2_vm_copy_pte                        163      68     -95
sdma_v5_0_vm_copy_pte                        163      68     -95
sdma_v4_4_2_vm_copy_pte                      163      68     -95
sdma_v4_0_vm_copy_pte                        163      68     -95
sdma_v7_0_vm_copy_pte                        183      75    -108
sdma_v7_0_emit_copy_buffer                   317     202    -115
si_dma_vm_set_pte_pde                        338     214    -124
amdgpu_vce_get_destroy_msg                   784     652    -132
sdma_v7_0_vm_set_pte_pde                     218      72    -146
sdma_v6_0_vm_set_pte_pde                     218      72    -146
sdma_v5_2_vm_set_pte_pde                     218      72    -146
sdma_v5_0_vm_set_pte_pde                     218      72    -146
sdma_v4_4_2_vm_set_pte_pde                   218      72    -146
sdma_v4_0_vm_set_pte_pde                     218      72    -146
sdma_v3_0_vm_set_pte_pde                     215      69    -146
sdma_v2_4_vm_set_pte_pde                     215      69    -146
cik_sdma_vm_set_pte_pde                      215      69    -146
amdgpu_vcn_unified_ring_ib_header            172       -    -172
gfx_v9_4_2_run_shader.constprop              739     532    -207
uvd_v6_0_enc_ring_test_ib                   1464    1162    -302
uvd_v7_0_enc_ring_test_ib                   1464    1138    -326
amdgpu_vce_ring_test_ib                     1357     936    -421
amdgpu_vcn_enc_ring_test_ib                 2042    1524    -518

Total: Before=9262623, After=9256285, chg -0.07%

* Notice how _pad_ib functions have grown. I think the compiler used the opportunity to unroll the loops.

** Series was only smoke tested on the Steam Deck.

Tvrtko Ursulin (16):

       drm/amdgpu: Use memset32 for IB padding
       drm/amdgpu: More compact VCE IB emission
       drm/amdgpu: More compact VCN IB emission
       drm/amdgpu: More compact UVD 6 IB emission
       drm/amdgpu: More compact UVD 7 IB emission
       drm/amdgpu: More compact SI SDMA emission
       drm/amdgpu: More compact CIK SDMA IB emission
       drm/amdgpu: More compact GFX 9.4.2 IB emission
       drm/amdgpu: More compact SDMA 2.4 IB emission
       drm/amdgpu: More compact SDMA 3.0 IB emission
       drm/amdgpu: More compact SDMA 4.0 IB emission
       drm/amdgpu: More compact SDMA 4.4.2 IB emission
       drm/amdgpu: More compact SDMA 5.0 IB emission
       drm/amdgpu: More compact SDMA 5.2 IB emission
       drm/amdgpu: More compact SDMA 6.0 IB emission
       drm/amdgpu: More compact SDMA 7.0 IB emission

      drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c |  12 ++-
      drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c  |  90 +++++++++--------
      drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c  | 101 ++++++++++---------
      drivers/gpu/drm/amd/amdgpu/cik_sdma.c    | 105 ++++++++++++--------
      drivers/gpu/drm/amd/amdgpu/gfx_v9_4_2.c  |  46 ++++-----
      drivers/gpu/drm/amd/amdgpu/sdma_v2_4.c   | 108 ++++++++++++--------
      drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c   | 108 ++++++++++++--------
      drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c   | 109 ++++++++++++---------
      drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c | 108 ++++++++++++--------
      drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c   | 106 ++++++++++++--------
      drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c   | 110 ++++++++++++---------
      drivers/gpu/drm/amd/amdgpu/sdma_v6_0.c   | 110 ++++++++++++---------
      drivers/gpu/drm/amd/amdgpu/sdma_v7_0.c   | 119 +++++++++++++----------
      drivers/gpu/drm/amd/amdgpu/si_dma.c      |  84 +++++++++-------
      drivers/gpu/drm/amd/amdgpu/uvd_v6_0.c    |  66 +++++++------
      drivers/gpu/drm/amd/amdgpu/uvd_v7_0.c    |  66 +++++++------
      16 files changed, 849 insertions(+), 599 deletions(-)

--
2.48.0