drm/amdgpu: simplify padding calculations
Subsystems (2)
PATCH 1/1 drm/amdgpu: simplify padding calculations
Simplify padding calculations.
--- drivers/gpu/drm/amd/amdgpu/cik_sdma.c | 4 ++-- drivers/gpu/drm/amd/amdgpu/sdma_v2_4.c | 4 ++-- drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c | 4 ++-- drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c | 4 ++-- drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c | 14 +++++++++----- 5 files changed, 17 insertions(+), 13 deletions(-)
drivers/gpu/drm/amd/amdgpu/cik_sdma.c +2 -2
@@ -228,7 +228,7 @@ static void cik_sdma_ring_emit_ib(struct amdgpu_ring *ring,u32 extra_bits = vmid &0xf ;/* IB packet must end on a 8 DW boundary */ -cik_sdma_ring_insert_nop (ring, (12 - (lower_32_bits (ring->wptr) &7 )) %8 ); +cik_sdma_ring_insert_nop (ring, (4 -lower_32_bits (ring->wptr)) &7 );amdgpu_ring_write (ring,SDMA_PACKET (SDMA_OPCODE_INDIRECT_BUFFER ,0 , extra_bits));amdgpu_ring_write (ring, ib->gpu_addr &0xffffffe0 );/* base must be 32 byte aligned */
@@ -811,7 +811,7 @@ static void cik_sdma_ring_pad_ib(struct amdgpu_ring *ring, struct amdgpu_ib *ib)u32 pad_count;int i; - pad_count = (8 - (ib->length_dw &0x7 )) %8 ; + pad_count = (-ib->length_dw) &7 ;for (i =0 ; i < pad_count; i++)if (sdma && sdma->burst_nop && (i ==0 )) ib->ptr[ib->length_dw++] =
drivers/gpu/drm/amd/amdgpu/sdma_v2_4.c +2 -2
@@ -255,7 +255,7 @@ static void sdma_v2_4_ring_emit_ib(struct amdgpu_ring *ring,unsigned vmid =AMDGPU_JOB_GET_VMID (job);/* IB packet must end on a 8 DW boundary */ -sdma_v2_4_ring_insert_nop (ring, (10 - (lower_32_bits (ring->wptr) &7 )) %8 ); +sdma_v2_4_ring_insert_nop (ring, (2 -lower_32_bits (ring->wptr)) &7 );amdgpu_ring_write (ring,SDMA_PKT_HEADER_OP (SDMA_OP_INDIRECT ) |SDMA_PKT_INDIRECT_HEADER_VMID (vmid &0xf ));
@@ -750,7 +750,7 @@ static void sdma_v2_4_ring_pad_ib(struct amdgpu_ring *ring, struct amdgpu_ib *ibu32 pad_count;int i; - pad_count = (8 - (ib->length_dw &0x7 )) %8 ; + pad_count = (-ib->length_dw) &7 ;for (i =0 ; i < pad_count; i++)if (sdma && sdma->burst_nop && (i ==0 )) ib->ptr[ib->length_dw++] =
drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c +2 -2
@@ -429,7 +429,7 @@ static void sdma_v3_0_ring_emit_ib(struct amdgpu_ring *ring,unsigned vmid =AMDGPU_JOB_GET_VMID (job);/* IB packet must end on a 8 DW boundary */ -sdma_v3_0_ring_insert_nop (ring, (10 - (lower_32_bits (ring->wptr) &7 )) %8 ); +sdma_v3_0_ring_insert_nop (ring, (2 -lower_32_bits (ring->wptr)) &7 );amdgpu_ring_write (ring,SDMA_PKT_HEADER_OP (SDMA_OP_INDIRECT ) |SDMA_PKT_INDIRECT_HEADER_VMID (vmid &0xf ));
@@ -1021,7 +1021,7 @@ static void sdma_v3_0_ring_pad_ib(struct amdgpu_ring *ring, struct amdgpu_ib *ibu32 pad_count;int i; - pad_count = (8 - (ib->length_dw &0x7 )) %8 ; + pad_count = (-ib->length_dw) &7 ;for (i =0 ; i < pad_count; i++)if (sdma && sdma->burst_nop && (i ==0 )) ib->ptr[ib->length_dw++] =
drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c +2 -2
@@ -698,7 +698,7 @@ static void sdma_v4_0_ring_emit_ib(struct amdgpu_ring *ring,unsigned vmid =AMDGPU_JOB_GET_VMID (job);/* IB packet must end on a 8 DW boundary */ -sdma_v4_0_ring_insert_nop (ring, (10 - (lower_32_bits (ring->wptr) &7 )) %8 ); +sdma_v4_0_ring_insert_nop (ring, (2 -lower_32_bits (ring->wptr)) &7 );amdgpu_ring_write (ring,SDMA_PKT_HEADER_OP (SDMA_OP_INDIRECT ) |SDMA_PKT_INDIRECT_HEADER_VMID (vmid &0xf ));
@@ -1580,7 +1580,7 @@ static void sdma_v4_0_ring_pad_ib(struct amdgpu_ring *ring, struct amdgpu_ib *ibu32 pad_count;int i; - pad_count = (8 - (ib->length_dw &0x7 )) %8 ; + pad_count = (-ib->length_dw) &7 ;for (i =0 ; i < pad_count; i++)if (sdma && sdma->burst_nop && (i ==0 )) ib->ptr[ib->length_dw++] =
drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c +9 -5
@@ -382,8 +382,12 @@ static void sdma_v5_0_ring_emit_ib(struct amdgpu_ring *ring,unsigned vmid =AMDGPU_JOB_GET_VMID (job);uint64_t csa_mc_addr =amdgpu_sdma_get_csa_mc_addr (ring, vmid); -/* IB packet must end on a 8 DW boundary */ -sdma_v5_0_ring_insert_nop (ring, (10 - (lower_32_bits (ring->wptr) &7 )) %8 ); +/* An IB packet must end on a 8 DW boundary--the next dword must +* be on a 8-dword boundary. Our IB below is 6 dwords long, +* thus add x number of NOPs, such that +* wptr + 6 + x = 8k, k >= 0. +*/ +sdma_v5_0_ring_insert_nop (ring, (2 -lower_32_bits (ring->wptr)) &7 );amdgpu_ring_write (ring,SDMA_PKT_HEADER_OP (SDMA_OP_INDIRECT ) |SDMA_PKT_INDIRECT_HEADER_VMID (vmid &0xf ));
@@ -1086,10 +1090,10 @@ static void sdma_v5_0_vm_set_pte_pde(struct amdgpu_ib *ib, }/** -* sdma_v5_0_ring_pad_ib - pad the IB to the required number of dw -* +* sdma_v5_0_ring_pad_ib - pad the IB * @ib: indirect buffer to fill with padding * +* Pad the IB with NOPs to a boundary multiple of 8. */ static void sdma_v5_0_ring_pad_ib (struct amdgpu_ring *ring,struct amdgpu_ib *ib) {
@@ -1097,7 +1101,7 @@ static void sdma_v5_0_ring_pad_ib(struct amdgpu_ring *ring, struct amdgpu_ib *ibu32 pad_count;int i; - pad_count = (8 - (ib->length_dw &0x7 )) %8 ; + pad_count = (-ib->length_dw) &0x7 ;for (i =0 ; i < pad_count; i++)if (sdma && sdma->burst_nop && (i ==0 )) ib->ptr[ib->length_dw++] =
Signature · 6 lines
2.23.0.385.gbc12974a89 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): [email protected]
Am 25.10.19 um 01:44 schrieb Tuikov, Luben:
Quoted 104 lines
Simplify padding calculations.
Signed-off-by Luben Tuikov <[email protected]>--- drivers/gpu/drm/amd/amdgpu/cik_sdma.c | 4 ++-- drivers/gpu/drm/amd/amdgpu/sdma_v2_4.c | 4 ++-- drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c | 4 ++-- drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c | 4 ++-- drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c | 14 +++++++++----- 5 files changed, 17 insertions(+), 13 deletions(-)drivers/gpu/drm/amd/amdgpu/cik_sdma.c +2
-2@@ -228,7 +228,7 @@ static void cik_sdma_ring_emit_ib(struct amdgpu_ring *ring,u32 extra_bits = vmid &0xf ;/* IB packet must end on a 8 DW boundary */ -cik_sdma_ring_insert_nop (ring, (12 - (lower_32_bits (ring->wptr) &7 )) %8 ); +cik_sdma_ring_insert_nop (ring, (4 -lower_32_bits (ring->wptr)) &7 );amdgpu_ring_write (ring,SDMA_PACKET (SDMA_OPCODE_INDIRECT_BUFFER ,0 , extra_bits));amdgpu_ring_write (ring, ib->gpu_addr &0xffffffe0 );/* base must be 32 byte aligned */ @@ -811,7 +811,7 @@ static void cik_sdma_ring_pad_ib(struct amdgpu_ring *ring, struct amdgpu_ib *ib)u32 pad_count;int i; - pad_count = (8 - (ib->length_dw &0x7 )) %8 ; + pad_count = (-ib->length_dw) &7 ;for (i =0 ; i < pad_count; i++)if (sdma && sdma->burst_nop && (i ==0 )) ib->ptr[ib->length_dw++] =drivers/gpu/drm/amd/amdgpu/sdma_v2_4.c +2
-2@@ -255,7 +255,7 @@ static void sdma_v2_4_ring_emit_ib(struct amdgpu_ring *ring,unsigned vmid =AMDGPU_JOB_GET_VMID (job);/* IB packet must end on a 8 DW boundary */ -sdma_v2_4_ring_insert_nop (ring, (10 - (lower_32_bits (ring->wptr) &7 )) %8 ); +sdma_v2_4_ring_insert_nop (ring, (2 -lower_32_bits (ring->wptr)) &7 );amdgpu_ring_write (ring,SDMA_PKT_HEADER_OP (SDMA_OP_INDIRECT ) |SDMA_PKT_INDIRECT_HEADER_VMID (vmid &0xf ));@@ -750,7 +750,7 @@ static void sdma_v2_4_ring_pad_ib(struct amdgpu_ring *ring, struct amdgpu_ib *ibu32 pad_count;int i; - pad_count = (8 - (ib->length_dw &0x7 )) %8 ; + pad_count = (-ib->length_dw) &7 ;for (i =0 ; i < pad_count; i++)if (sdma && sdma->burst_nop && (i ==0 )) ib->ptr[ib->length_dw++] =drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c +2
-2@@ -429,7 +429,7 @@ static void sdma_v3_0_ring_emit_ib(struct amdgpu_ring *ring,unsigned vmid =AMDGPU_JOB_GET_VMID (job);/* IB packet must end on a 8 DW boundary */ -sdma_v3_0_ring_insert_nop (ring, (10 - (lower_32_bits (ring->wptr) &7 )) %8 ); +sdma_v3_0_ring_insert_nop (ring, (2 -lower_32_bits (ring->wptr)) &7 );amdgpu_ring_write (ring,SDMA_PKT_HEADER_OP (SDMA_OP_INDIRECT ) |SDMA_PKT_INDIRECT_HEADER_VMID (vmid &0xf ));@@ -1021,7 +1021,7 @@ static void sdma_v3_0_ring_pad_ib(struct amdgpu_ring *ring, struct amdgpu_ib *ibu32 pad_count;int i; - pad_count = (8 - (ib->length_dw &0x7 )) %8 ; + pad_count = (-ib->length_dw) &7 ;for (i =0 ; i < pad_count; i++)if (sdma && sdma->burst_nop && (i ==0 )) ib->ptr[ib->length_dw++] =drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c +2
-2@@ -698,7 +698,7 @@ static void sdma_v4_0_ring_emit_ib(struct amdgpu_ring *ring,unsigned vmid =AMDGPU_JOB_GET_VMID (job);/* IB packet must end on a 8 DW boundary */ -sdma_v4_0_ring_insert_nop (ring, (10 - (lower_32_bits (ring->wptr) &7 )) %8 ); +sdma_v4_0_ring_insert_nop (ring, (2 -lower_32_bits (ring->wptr)) &7 );amdgpu_ring_write (ring,SDMA_PKT_HEADER_OP (SDMA_OP_INDIRECT ) |SDMA_PKT_INDIRECT_HEADER_VMID (vmid &0xf ));@@ -1580,7 +1580,7 @@ static void sdma_v4_0_ring_pad_ib(struct amdgpu_ring *ring, struct amdgpu_ib *ibu32 pad_count;int i; - pad_count = (8 - (ib->length_dw &0x7 )) %8 ; + pad_count = (-ib->length_dw) &7 ;for (i =0 ; i < pad_count; i++)if (sdma && sdma->burst_nop && (i ==0 )) ib->ptr[ib->length_dw++] =drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c +0
-0
drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c static void sdma_v5_0_ring_emit_ib(struct amdgpu_ring *ring, · line 386
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c +2
-2@@ -382,8 +382,12 @@ static void sdma_v5_0_ring_emit_ib(struct amdgpu_ring *ring,unsigned vmid =AMDGPU_JOB_GET_VMID (job);uint64_t csa_mc_addr =amdgpu_sdma_get_csa_mc_addr (ring, vmid); -/* IB packet must end on a 8 DW boundary */ -sdma_v5_0_ring_insert_nop (ring, (10 - (lower_32_bits (ring->wptr) &7 )) %8 ); +/* An IB packet must end on a 8 DW boundary--the next dword must +* be on a 8-dword boundary. Our IB below is 6 dwords long,
That should probably read "our IB command" or "our IB packet".
drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c static void sdma_v5_0_ring_emit_ib(struct amdgpu_ring *ring, · line 388
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c +2
-0+* thus add x number of NOPs, such that +* wptr + 6 + x = 8k, k >= 0.
Maybe write (wrptr + 6 + x) % 8 = 0 to make that more obvious.
drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c static void sdma_v5_0_ring_emit_ib(struct amdgpu_ring *ring, · line 390
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c +2
-0+*/ +sdma_v5_0_ring_insert_nop (ring, (2 -lower_32_bits (ring->wptr)) &7 );
Spaces between operators please.
Apart form that looks good to me,
Christian.
Quoted 17 lines
drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c +2
-2amdgpu_ring_write (ring,SDMA_PKT_HEADER_OP (SDMA_OP_INDIRECT ) |SDMA_PKT_INDIRECT_HEADER_VMID (vmid &0xf ));@@ -1086,10 +1090,10 @@ static void sdma_v5_0_vm_set_pte_pde(struct amdgpu_ib *ib, }/** -* sdma_v5_0_ring_pad_ib - pad the IB to the required number of dw -* +* sdma_v5_0_ring_pad_ib - pad the IB * @ib: indirect buffer to fill with padding * +* Pad the IB with NOPs to a boundary multiple of 8. */ static void sdma_v5_0_ring_pad_ib (struct amdgpu_ring *ring,struct amdgpu_ib *ib) {
drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c static void sdma_v5_0_ring_pad_ib(struct amdgpu_ring *ring, struct amdgpu_ib *ib · line 1107
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c +1
-1@@ -1097,7 +1101,7 @@ static void sdma_v5_0_ring_pad_ib(struct amdgpu_ring *ring, struct amdgpu_ib *ibu32 pad_count;int i; - pad_count = (8 - (ib->length_dw &0x7 )) %8 ; + pad_count = (-ib->length_dw) &0x7 ;for (i =0 ; i < pad_count; i++)if (sdma && sdma->burst_nop && (i ==0 )) ib->ptr[ib->length_dw++] =
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 45e07677-717a-2c01-369e-1dbd19ce8e74-5C7GfCeVMHo@public.gmane.org
Quoted 108 lines · Christian
Am 25.10.19 um 01:44 schrieb Tuikov, Luben:
Quoted 107 lines
Simplify padding calculations.
Signed-off-by Luben Tuikov <[email protected]>--- drivers/gpu/drm/amd/amdgpu/cik_sdma.c | 4 ++-- drivers/gpu/drm/amd/amdgpu/sdma_v2_4.c | 4 ++-- drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c | 4 ++-- drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c | 4 ++-- drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c | 14 +++++++++----- 5 files changed, 17 insertions(+), 13 deletions(-)drivers/gpu/drm/amd/amdgpu/cik_sdma.c +2
-2@@ -228,7 +228,7 @@ static void cik_sdma_ring_emit_ib(struct amdgpu_ring *ring,u32 extra_bits = vmid &0xf ;/* IB packet must end on a 8 DW boundary */ -cik_sdma_ring_insert_nop (ring, (12 - (lower_32_bits (ring->wptr) &7 )) %8 ); +cik_sdma_ring_insert_nop (ring, (4 -lower_32_bits (ring->wptr)) &7 );amdgpu_ring_write (ring,SDMA_PACKET (SDMA_OPCODE_INDIRECT_BUFFER ,0 , extra_bits));amdgpu_ring_write (ring, ib->gpu_addr &0xffffffe0 );/* base must be 32 byte aligned */ @@ -811,7 +811,7 @@ static void cik_sdma_ring_pad_ib(struct amdgpu_ring *ring, struct amdgpu_ib *ib)u32 pad_count;int i; - pad_count = (8 - (ib->length_dw &0x7 )) %8 ; + pad_count = (-ib->length_dw) &7 ;for (i =0 ; i < pad_count; i++)if (sdma && sdma->burst_nop && (i ==0 )) ib->ptr[ib->length_dw++] =drivers/gpu/drm/amd/amdgpu/sdma_v2_4.c +2
-2@@ -255,7 +255,7 @@ static void sdma_v2_4_ring_emit_ib(struct amdgpu_ring *ring,unsigned vmid =AMDGPU_JOB_GET_VMID (job);/* IB packet must end on a 8 DW boundary */ -sdma_v2_4_ring_insert_nop (ring, (10 - (lower_32_bits (ring->wptr) &7 )) %8 ); +sdma_v2_4_ring_insert_nop (ring, (2 -lower_32_bits (ring->wptr)) &7 );amdgpu_ring_write (ring,SDMA_PKT_HEADER_OP (SDMA_OP_INDIRECT ) |SDMA_PKT_INDIRECT_HEADER_VMID (vmid &0xf ));@@ -750,7 +750,7 @@ static void sdma_v2_4_ring_pad_ib(struct amdgpu_ring *ring, struct amdgpu_ib *ibu32 pad_count;int i; - pad_count = (8 - (ib->length_dw &0x7 )) %8 ; + pad_count = (-ib->length_dw) &7 ;for (i =0 ; i < pad_count; i++)if (sdma && sdma->burst_nop && (i ==0 )) ib->ptr[ib->length_dw++] =drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c +2
-2@@ -429,7 +429,7 @@ static void sdma_v3_0_ring_emit_ib(struct amdgpu_ring *ring,unsigned vmid =AMDGPU_JOB_GET_VMID (job);/* IB packet must end on a 8 DW boundary */ -sdma_v3_0_ring_insert_nop (ring, (10 - (lower_32_bits (ring->wptr) &7 )) %8 ); +sdma_v3_0_ring_insert_nop (ring, (2 -lower_32_bits (ring->wptr)) &7 );amdgpu_ring_write (ring,SDMA_PKT_HEADER_OP (SDMA_OP_INDIRECT ) |SDMA_PKT_INDIRECT_HEADER_VMID (vmid &0xf ));@@ -1021,7 +1021,7 @@ static void sdma_v3_0_ring_pad_ib(struct amdgpu_ring *ring, struct amdgpu_ib *ibu32 pad_count;int i; - pad_count = (8 - (ib->length_dw &0x7 )) %8 ; + pad_count = (-ib->length_dw) &7 ;for (i =0 ; i < pad_count; i++)if (sdma && sdma->burst_nop && (i ==0 )) ib->ptr[ib->length_dw++] =drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c +2
-2@@ -698,7 +698,7 @@ static void sdma_v4_0_ring_emit_ib(struct amdgpu_ring *ring,unsigned vmid =AMDGPU_JOB_GET_VMID (job);/* IB packet must end on a 8 DW boundary */ -sdma_v4_0_ring_insert_nop (ring, (10 - (lower_32_bits (ring->wptr) &7 )) %8 ); +sdma_v4_0_ring_insert_nop (ring, (2 -lower_32_bits (ring->wptr)) &7 );amdgpu_ring_write (ring,SDMA_PKT_HEADER_OP (SDMA_OP_INDIRECT ) |SDMA_PKT_INDIRECT_HEADER_VMID (vmid &0xf ));@@ -1580,7 +1580,7 @@ static void sdma_v4_0_ring_pad_ib(struct amdgpu_ring *ring, struct amdgpu_ib *ibu32 pad_count;int i; - pad_count = (8 - (ib->length_dw &0x7 )) %8 ; + pad_count = (-ib->length_dw) &7 ;for (i =0 ; i < pad_count; i++)if (sdma && sdma->burst_nop && (i ==0 )) ib->ptr[ib->length_dw++] =drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c +0
-0@@ -382,8 +382,12 @@ static void sdma_v5_0_ring_emit_ib(struct amdgpu_ring *ring,unsigned vmid =AMDGPU_JOB_GET_VMID (job);uint64_t csa_mc_addr =amdgpu_sdma_get_csa_mc_addr (ring, vmid);
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c static void sdma_v5_0_ring_emit_ib(struct amdgpu_ring *ring, · line 386
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c +2
-2-/* IB packet must end on a 8 DW boundary */ -sdma_v5_0_ring_insert_nop (ring, (10 - (lower_32_bits (ring->wptr) &7 )) %8 ); +/* An IB packet must end on a 8 DW boundary--the next dword must +* be on a 8-dword boundary. Our IB below is 6 dwords long, That should probably read "our IB command" or "our IB packet".
Done.
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c static void sdma_v5_0_ring_emit_ib(struct amdgpu_ring *ring, · line 388
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c +2
-0+* thus add x number of NOPs, such that +* wptr + 6 + x = 8k, k >= 0. Maybe write (wrptr + 6 + x) % 8 = 0 to make that more obvious.
That's less obvious. In my mind I always translate it to a congruence expression. It's what I used to derive the algebraic simplifications of this patch.
I'll add the highly cryptic "(wrptr + 6 + x) % 8 = 0" to make you happy, below the algebraic expression already there.
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c static void sdma_v5_0_ring_emit_ib(struct amdgpu_ring *ring, · line 390
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c +2
-0+*/ +sdma_v5_0_ring_insert_nop (ring, (2 -lower_32_bits (ring->wptr)) &7 );Spaces between operators please.
Yeah, I wanted to put an emphasis on the AND-op, but I'll add them.
Regards,
Luben
Quoted 24 lines
Apart form that looks good to me,
Christian.Quoted 20 lines
drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c +2
-2amdgpu_ring_write (ring,SDMA_PKT_HEADER_OP (SDMA_OP_INDIRECT ) |SDMA_PKT_INDIRECT_HEADER_VMID (vmid &0xf ));@@ -1086,10 +1090,10 @@ static void sdma_v5_0_vm_set_pte_pde(struct amdgpu_ib *ib, }/** -* sdma_v5_0_ring_pad_ib - pad the IB to the required number of dw -* +* sdma_v5_0_ring_pad_ib - pad the IB * @ib: indirect buffer to fill with padding * +* Pad the IB with NOPs to a boundary multiple of 8. */ static void sdma_v5_0_ring_pad_ib (struct amdgpu_ring *ring,struct amdgpu_ib *ib) {@@ -1097,7 +1101,7 @@ static void sdma_v5_0_ring_pad_ib(struct amdgpu_ring *ring, struct amdgpu_ib *ibu32 pad_count;int i;
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c static void sdma_v5_0_ring_pad_ib(struct amdgpu_ring *ring, struct amdgpu_ib *ib · line 1107
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c +1
-1- pad_count = (8 - (ib->length_dw &0x7 )) %8 ; + pad_count = (-ib->length_dw) &0x7 ;for (i =0 ; i < pad_count; i++)if (sdma && sdma->burst_nop && (i ==0 )) ib->ptr[ib->length_dw++] =
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): ed713bfe-2032-b56a-3e29-f61f48aeeb3b-5C7GfCeVMHo@public.gmane.org
PATCH 1/1 drm/amdgpu: simplify padding calculations
Simplify padding calculations.
--- drivers/gpu/drm/amd/amdgpu/cik_sdma.c | 4 ++-- drivers/gpu/drm/amd/amdgpu/sdma_v2_4.c | 4 ++-- drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c | 4 ++-- drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c | 4 ++-- drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c | 17 ++++++++++++----- 5 files changed, 20 insertions(+), 13 deletions(-)
drivers/gpu/drm/amd/amdgpu/cik_sdma.c +2 -2
@@ -228,7 +228,7 @@ static void cik_sdma_ring_emit_ib(struct amdgpu_ring *ring,u32 extra_bits = vmid &0xf ;/* IB packet must end on a 8 DW boundary */ -cik_sdma_ring_insert_nop (ring, (12 - (lower_32_bits (ring->wptr) &7 )) %8 ); +cik_sdma_ring_insert_nop (ring, (4 -lower_32_bits (ring->wptr)) &7 );amdgpu_ring_write (ring,SDMA_PACKET (SDMA_OPCODE_INDIRECT_BUFFER ,0 , extra_bits));amdgpu_ring_write (ring, ib->gpu_addr &0xffffffe0 );/* base must be 32 byte aligned */
@@ -811,7 +811,7 @@ static void cik_sdma_ring_pad_ib(struct amdgpu_ring *ring, struct amdgpu_ib *ib)u32 pad_count;int i; - pad_count = (8 - (ib->length_dw &0x7 )) %8 ; + pad_count = (-ib->length_dw) &7 ;for (i =0 ; i < pad_count; i++)if (sdma && sdma->burst_nop && (i ==0 )) ib->ptr[ib->length_dw++] =
drivers/gpu/drm/amd/amdgpu/sdma_v2_4.c +2 -2
@@ -255,7 +255,7 @@ static void sdma_v2_4_ring_emit_ib(struct amdgpu_ring *ring,unsigned vmid =AMDGPU_JOB_GET_VMID (job);/* IB packet must end on a 8 DW boundary */ -sdma_v2_4_ring_insert_nop (ring, (10 - (lower_32_bits (ring->wptr) &7 )) %8 ); +sdma_v2_4_ring_insert_nop (ring, (2 -lower_32_bits (ring->wptr)) &7 );amdgpu_ring_write (ring,SDMA_PKT_HEADER_OP (SDMA_OP_INDIRECT ) |SDMA_PKT_INDIRECT_HEADER_VMID (vmid &0xf ));
@@ -750,7 +750,7 @@ static void sdma_v2_4_ring_pad_ib(struct amdgpu_ring *ring, struct amdgpu_ib *ibu32 pad_count;int i; - pad_count = (8 - (ib->length_dw &0x7 )) %8 ; + pad_count = (-ib->length_dw) &7 ;for (i =0 ; i < pad_count; i++)if (sdma && sdma->burst_nop && (i ==0 )) ib->ptr[ib->length_dw++] =
drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c +2 -2
@@ -429,7 +429,7 @@ static void sdma_v3_0_ring_emit_ib(struct amdgpu_ring *ring,unsigned vmid =AMDGPU_JOB_GET_VMID (job);/* IB packet must end on a 8 DW boundary */ -sdma_v3_0_ring_insert_nop (ring, (10 - (lower_32_bits (ring->wptr) &7 )) %8 ); +sdma_v3_0_ring_insert_nop (ring, (2 -lower_32_bits (ring->wptr)) &7 );amdgpu_ring_write (ring,SDMA_PKT_HEADER_OP (SDMA_OP_INDIRECT ) |SDMA_PKT_INDIRECT_HEADER_VMID (vmid &0xf ));
@@ -1021,7 +1021,7 @@ static void sdma_v3_0_ring_pad_ib(struct amdgpu_ring *ring, struct amdgpu_ib *ibu32 pad_count;int i; - pad_count = (8 - (ib->length_dw &0x7 )) %8 ; + pad_count = (-ib->length_dw) &7 ;for (i =0 ; i < pad_count; i++)if (sdma && sdma->burst_nop && (i ==0 )) ib->ptr[ib->length_dw++] =
drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c +2 -2
@@ -698,7 +698,7 @@ static void sdma_v4_0_ring_emit_ib(struct amdgpu_ring *ring,unsigned vmid =AMDGPU_JOB_GET_VMID (job);/* IB packet must end on a 8 DW boundary */ -sdma_v4_0_ring_insert_nop (ring, (10 - (lower_32_bits (ring->wptr) &7 )) %8 ); +sdma_v4_0_ring_insert_nop (ring, (2 -lower_32_bits (ring->wptr)) &7 );amdgpu_ring_write (ring,SDMA_PKT_HEADER_OP (SDMA_OP_INDIRECT ) |SDMA_PKT_INDIRECT_HEADER_VMID (vmid &0xf ));
@@ -1580,7 +1580,7 @@ static void sdma_v4_0_ring_pad_ib(struct amdgpu_ring *ring, struct amdgpu_ib *ibu32 pad_count;int i; - pad_count = (8 - (ib->length_dw &0x7 )) %8 ; + pad_count = (-ib->length_dw) &7 ;for (i =0 ; i < pad_count; i++)if (sdma && sdma->burst_nop && (i ==0 )) ib->ptr[ib->length_dw++] =
drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c +12 -5
@@ -382,8 +382,15 @@ static void sdma_v5_0_ring_emit_ib(struct amdgpu_ring *ring,unsigned vmid =AMDGPU_JOB_GET_VMID (job);uint64_t csa_mc_addr =amdgpu_sdma_get_csa_mc_addr (ring, vmid); -/* IB packet must end on a 8 DW boundary */ -sdma_v5_0_ring_insert_nop (ring, (10 - (lower_32_bits (ring->wptr) &7 )) %8 ); +/* An IB packet must end on a 8 DW boundary--the next dword +* must be on a 8-dword boundary. Our IB packet below is 6 +* dwords long, thus add x number of NOPs, such that, in +* modular arithmetic, +* wptr + 6 + x = 8k, k >= 0, which in C is, +* (wptr + 6 + x) % 8 = 0. +* The expression below, is a solution of x. +*/ +sdma_v5_0_ring_insert_nop (ring, (2 -lower_32_bits (ring->wptr)) &7 );amdgpu_ring_write (ring,SDMA_PKT_HEADER_OP (SDMA_OP_INDIRECT ) |SDMA_PKT_INDIRECT_HEADER_VMID (vmid &0xf ));
@@ -1086,10 +1093,10 @@ static void sdma_v5_0_vm_set_pte_pde(struct amdgpu_ib *ib, }/** -* sdma_v5_0_ring_pad_ib - pad the IB to the required number of dw -* +* sdma_v5_0_ring_pad_ib - pad the IB * @ib: indirect buffer to fill with padding * +* Pad the IB with NOPs to a boundary multiple of 8. */ static void sdma_v5_0_ring_pad_ib (struct amdgpu_ring *ring,struct amdgpu_ib *ib) {
@@ -1097,7 +1104,7 @@ static void sdma_v5_0_ring_pad_ib(struct amdgpu_ring *ring, struct amdgpu_ib *ibu32 pad_count;int i; - pad_count = (8 - (ib->length_dw &0x7 )) %8 ; + pad_count = (-ib->length_dw) &0x7 ;for (i =0 ; i < pad_count; i++)if (sdma && sdma->burst_nop && (i ==0 )) ib->ptr[ib->length_dw++] =
Signature · 6 lines
2.23.0.385.gbc12974a89 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Am 25.10.19 um 23:51 schrieb Tuikov, Luben:
Quoted 119 lines · Christian
Quoted 108 lines
Am 25.10.19 um 01:44 schrieb Tuikov, Luben:
Quoted 107 lines
Simplify padding calculations.
Signed-off-by Luben Tuikov <[email protected]>--- drivers/gpu/drm/amd/amdgpu/cik_sdma.c | 4 ++-- drivers/gpu/drm/amd/amdgpu/sdma_v2_4.c | 4 ++-- drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c | 4 ++-- drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c | 4 ++-- drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c | 14 +++++++++----- 5 files changed, 17 insertions(+), 13 deletions(-)drivers/gpu/drm/amd/amdgpu/cik_sdma.c +2
-2@@ -228,7 +228,7 @@ static void cik_sdma_ring_emit_ib(struct amdgpu_ring *ring,u32 extra_bits = vmid &0xf ;/* IB packet must end on a 8 DW boundary */ -cik_sdma_ring_insert_nop (ring, (12 - (lower_32_bits (ring->wptr) &7 )) %8 ); +cik_sdma_ring_insert_nop (ring, (4 -lower_32_bits (ring->wptr)) &7 );amdgpu_ring_write (ring,SDMA_PACKET (SDMA_OPCODE_INDIRECT_BUFFER ,0 , extra_bits));amdgpu_ring_write (ring, ib->gpu_addr &0xffffffe0 );/* base must be 32 byte aligned */ @@ -811,7 +811,7 @@ static void cik_sdma_ring_pad_ib(struct amdgpu_ring *ring, struct amdgpu_ib *ib)u32 pad_count;int i; - pad_count = (8 - (ib->length_dw &0x7 )) %8 ; + pad_count = (-ib->length_dw) &7 ;for (i =0 ; i < pad_count; i++)if (sdma && sdma->burst_nop && (i ==0 )) ib->ptr[ib->length_dw++] =drivers/gpu/drm/amd/amdgpu/sdma_v2_4.c +2
-2@@ -255,7 +255,7 @@ static void sdma_v2_4_ring_emit_ib(struct amdgpu_ring *ring,unsigned vmid =AMDGPU_JOB_GET_VMID (job);/* IB packet must end on a 8 DW boundary */ -sdma_v2_4_ring_insert_nop (ring, (10 - (lower_32_bits (ring->wptr) &7 )) %8 ); +sdma_v2_4_ring_insert_nop (ring, (2 -lower_32_bits (ring->wptr)) &7 );amdgpu_ring_write (ring,SDMA_PKT_HEADER_OP (SDMA_OP_INDIRECT ) |SDMA_PKT_INDIRECT_HEADER_VMID (vmid &0xf ));@@ -750,7 +750,7 @@ static void sdma_v2_4_ring_pad_ib(struct amdgpu_ring *ring, struct amdgpu_ib *ibu32 pad_count;int i; - pad_count = (8 - (ib->length_dw &0x7 )) %8 ; + pad_count = (-ib->length_dw) &7 ;for (i =0 ; i < pad_count; i++)if (sdma && sdma->burst_nop && (i ==0 )) ib->ptr[ib->length_dw++] =drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c +2
-2@@ -429,7 +429,7 @@ static void sdma_v3_0_ring_emit_ib(struct amdgpu_ring *ring,unsigned vmid =AMDGPU_JOB_GET_VMID (job);/* IB packet must end on a 8 DW boundary */ -sdma_v3_0_ring_insert_nop (ring, (10 - (lower_32_bits (ring->wptr) &7 )) %8 ); +sdma_v3_0_ring_insert_nop (ring, (2 -lower_32_bits (ring->wptr)) &7 );amdgpu_ring_write (ring,SDMA_PKT_HEADER_OP (SDMA_OP_INDIRECT ) |SDMA_PKT_INDIRECT_HEADER_VMID (vmid &0xf ));@@ -1021,7 +1021,7 @@ static void sdma_v3_0_ring_pad_ib(struct amdgpu_ring *ring, struct amdgpu_ib *ibu32 pad_count;int i; - pad_count = (8 - (ib->length_dw &0x7 )) %8 ; + pad_count = (-ib->length_dw) &7 ;for (i =0 ; i < pad_count; i++)if (sdma && sdma->burst_nop && (i ==0 )) ib->ptr[ib->length_dw++] =drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c +2
-2@@ -698,7 +698,7 @@ static void sdma_v4_0_ring_emit_ib(struct amdgpu_ring *ring,unsigned vmid =AMDGPU_JOB_GET_VMID (job);/* IB packet must end on a 8 DW boundary */ -sdma_v4_0_ring_insert_nop (ring, (10 - (lower_32_bits (ring->wptr) &7 )) %8 ); +sdma_v4_0_ring_insert_nop (ring, (2 -lower_32_bits (ring->wptr)) &7 );amdgpu_ring_write (ring,SDMA_PKT_HEADER_OP (SDMA_OP_INDIRECT ) |SDMA_PKT_INDIRECT_HEADER_VMID (vmid &0xf ));@@ -1580,7 +1580,7 @@ static void sdma_v4_0_ring_pad_ib(struct amdgpu_ring *ring, struct amdgpu_ib *ibu32 pad_count;int i; - pad_count = (8 - (ib->length_dw &0x7 )) %8 ; + pad_count = (-ib->length_dw) &7 ;for (i =0 ; i < pad_count; i++)if (sdma && sdma->burst_nop && (i ==0 )) ib->ptr[ib->length_dw++] =drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c +0
-0@@ -382,8 +382,12 @@ static void sdma_v5_0_ring_emit_ib(struct amdgpu_ring *ring,unsigned vmid =AMDGPU_JOB_GET_VMID (job);uint64_t csa_mc_addr =amdgpu_sdma_get_csa_mc_addr (ring, vmid);Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c static void sdma_v5_0_ring_emit_ib(struct amdgpu_ring *ring, · line 386
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c +2
-2-/* IB packet must end on a 8 DW boundary */ -sdma_v5_0_ring_insert_nop (ring, (10 - (lower_32_bits (ring->wptr) &7 )) %8 ); +/* An IB packet must end on a 8 DW boundary--the next dword must +* be on a 8-dword boundary. Our IB below is 6 dwords long, That should probably read "our IB command" or "our IB packet".
Done.
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c static void sdma_v5_0_ring_emit_ib(struct amdgpu_ring *ring, · line 388
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c +2
-0+* thus add x number of NOPs, such that +* wptr + 6 + x = 8k, k >= 0. Maybe write (wrptr + 6 + x) % 8 = 0 to make that more obvious.
Quoted 6 lines
That's less obvious. In my mind I always translate it to a congruence expression. It's what I used to derive the algebraic simplifications of this patch.
I'll add the highly cryptic "(wrptr + 6 + x) % 8 = 0" to make you happy, below the algebraic expression already there.
The problem I see here is that people who are used to GPUs will think that k is a float and not immediately get what's meant here.
Quoted 4 lines
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c static void sdma_v5_0_ring_emit_ib(struct amdgpu_ring *ring, · line 390
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c +2
-0+*/ +sdma_v5_0_ring_insert_nop (ring, (2 -lower_32_bits (ring->wptr)) &7 );Spaces between operators please.
Yeah, I wanted to put an emphasis on the AND-op, but I'll add them.
What would be really nice to have is to keep the 10 as number of DW in the IB packet around.
Maybe add an "static inline amdgpu_ring_unalign(ring, 10, 8)" helper or something like that, the insert_nop is a ring callback anyway IIRC.
Regards,
Christian.
Quoted 28 lines
Regards,
LubenQuoted 23 lines
Apart form that looks good to me,
Christian.Quoted 20 lines
drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c +2
-2amdgpu_ring_write (ring,SDMA_PKT_HEADER_OP (SDMA_OP_INDIRECT ) |SDMA_PKT_INDIRECT_HEADER_VMID (vmid &0xf ));@@ -1086,10 +1090,10 @@ static void sdma_v5_0_vm_set_pte_pde(struct amdgpu_ib *ib, }/** -* sdma_v5_0_ring_pad_ib - pad the IB to the required number of dw -* +* sdma_v5_0_ring_pad_ib - pad the IB * @ib: indirect buffer to fill with padding * +* Pad the IB with NOPs to a boundary multiple of 8. */ static void sdma_v5_0_ring_pad_ib (struct amdgpu_ring *ring,struct amdgpu_ib *ib) {@@ -1097,7 +1101,7 @@ static void sdma_v5_0_ring_pad_ib(struct amdgpu_ring *ring, struct amdgpu_ib *ibu32 pad_count;int i;
Quoted 5 lines
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c static void sdma_v5_0_ring_pad_ib(struct amdgpu_ring *ring, struct amdgpu_ib *ib · line 1107
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c +1
-1- pad_count = (8 - (ib->length_dw &0x7 )) %8 ; + pad_count = (-ib->length_dw) &0x7 ;for (i =0 ; i < pad_count; i++)if (sdma && sdma->burst_nop && (i ==0 )) ib->ptr[ib->length_dw++] =
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): db4d6ece-2cec-a465-0639-d75142621dda-5C7GfCeVMHo@public.gmane.org
Quoted 130 lines · Christian
Am 25.10.19 um 23:51 schrieb Tuikov, Luben:
Quoted 119 lines · Christian
Quoted 108 lines
Am 25.10.19 um 01:44 schrieb Tuikov, Luben:
Quoted 107 lines
Simplify padding calculations.
Signed-off-by Luben Tuikov <[email protected]>--- drivers/gpu/drm/amd/amdgpu/cik_sdma.c | 4 ++-- drivers/gpu/drm/amd/amdgpu/sdma_v2_4.c | 4 ++-- drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c | 4 ++-- drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c | 4 ++-- drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c | 14 +++++++++----- 5 files changed, 17 insertions(+), 13 deletions(-)drivers/gpu/drm/amd/amdgpu/cik_sdma.c +2
-2@@ -228,7 +228,7 @@ static void cik_sdma_ring_emit_ib(struct amdgpu_ring *ring,u32 extra_bits = vmid &0xf ;/* IB packet must end on a 8 DW boundary */ -cik_sdma_ring_insert_nop (ring, (12 - (lower_32_bits (ring->wptr) &7 )) %8 ); +cik_sdma_ring_insert_nop (ring, (4 -lower_32_bits (ring->wptr)) &7 );amdgpu_ring_write (ring,SDMA_PACKET (SDMA_OPCODE_INDIRECT_BUFFER ,0 , extra_bits));amdgpu_ring_write (ring, ib->gpu_addr &0xffffffe0 );/* base must be 32 byte aligned */ @@ -811,7 +811,7 @@ static void cik_sdma_ring_pad_ib(struct amdgpu_ring *ring, struct amdgpu_ib *ib)u32 pad_count;int i; - pad_count = (8 - (ib->length_dw &0x7 )) %8 ; + pad_count = (-ib->length_dw) &7 ;for (i =0 ; i < pad_count; i++)if (sdma && sdma->burst_nop && (i ==0 )) ib->ptr[ib->length_dw++] =drivers/gpu/drm/amd/amdgpu/sdma_v2_4.c +2
-2@@ -255,7 +255,7 @@ static void sdma_v2_4_ring_emit_ib(struct amdgpu_ring *ring,unsigned vmid =AMDGPU_JOB_GET_VMID (job);/* IB packet must end on a 8 DW boundary */ -sdma_v2_4_ring_insert_nop (ring, (10 - (lower_32_bits (ring->wptr) &7 )) %8 ); +sdma_v2_4_ring_insert_nop (ring, (2 -lower_32_bits (ring->wptr)) &7 );amdgpu_ring_write (ring,SDMA_PKT_HEADER_OP (SDMA_OP_INDIRECT ) |SDMA_PKT_INDIRECT_HEADER_VMID (vmid &0xf ));@@ -750,7 +750,7 @@ static void sdma_v2_4_ring_pad_ib(struct amdgpu_ring *ring, struct amdgpu_ib *ibu32 pad_count;int i; - pad_count = (8 - (ib->length_dw &0x7 )) %8 ; + pad_count = (-ib->length_dw) &7 ;for (i =0 ; i < pad_count; i++)if (sdma && sdma->burst_nop && (i ==0 )) ib->ptr[ib->length_dw++] =drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c +2
-2@@ -429,7 +429,7 @@ static void sdma_v3_0_ring_emit_ib(struct amdgpu_ring *ring,unsigned vmid =AMDGPU_JOB_GET_VMID (job);/* IB packet must end on a 8 DW boundary */ -sdma_v3_0_ring_insert_nop (ring, (10 - (lower_32_bits (ring->wptr) &7 )) %8 ); +sdma_v3_0_ring_insert_nop (ring, (2 -lower_32_bits (ring->wptr)) &7 );amdgpu_ring_write (ring,SDMA_PKT_HEADER_OP (SDMA_OP_INDIRECT ) |SDMA_PKT_INDIRECT_HEADER_VMID (vmid &0xf ));@@ -1021,7 +1021,7 @@ static void sdma_v3_0_ring_pad_ib(struct amdgpu_ring *ring, struct amdgpu_ib *ibu32 pad_count;int i; - pad_count = (8 - (ib->length_dw &0x7 )) %8 ; + pad_count = (-ib->length_dw) &7 ;for (i =0 ; i < pad_count; i++)if (sdma && sdma->burst_nop && (i ==0 )) ib->ptr[ib->length_dw++] =drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c +2
-2@@ -698,7 +698,7 @@ static void sdma_v4_0_ring_emit_ib(struct amdgpu_ring *ring,unsigned vmid =AMDGPU_JOB_GET_VMID (job);/* IB packet must end on a 8 DW boundary */ -sdma_v4_0_ring_insert_nop (ring, (10 - (lower_32_bits (ring->wptr) &7 )) %8 ); +sdma_v4_0_ring_insert_nop (ring, (2 -lower_32_bits (ring->wptr)) &7 );amdgpu_ring_write (ring,SDMA_PKT_HEADER_OP (SDMA_OP_INDIRECT ) |SDMA_PKT_INDIRECT_HEADER_VMID (vmid &0xf ));@@ -1580,7 +1580,7 @@ static void sdma_v4_0_ring_pad_ib(struct amdgpu_ring *ring, struct amdgpu_ib *ibu32 pad_count;int i; - pad_count = (8 - (ib->length_dw &0x7 )) %8 ; + pad_count = (-ib->length_dw) &7 ;for (i =0 ; i < pad_count; i++)if (sdma && sdma->burst_nop && (i ==0 )) ib->ptr[ib->length_dw++] =drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c +0
-0@@ -382,8 +382,12 @@ static void sdma_v5_0_ring_emit_ib(struct amdgpu_ring *ring,unsigned vmid =AMDGPU_JOB_GET_VMID (job);uint64_t csa_mc_addr =amdgpu_sdma_get_csa_mc_addr (ring, vmid);Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c static void sdma_v5_0_ring_emit_ib(struct amdgpu_ring *ring, · line 386
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c +2
-2-/* IB packet must end on a 8 DW boundary */ -sdma_v5_0_ring_insert_nop (ring, (10 - (lower_32_bits (ring->wptr) &7 )) %8 ); +/* An IB packet must end on a 8 DW boundary--the next dword must +* be on a 8-dword boundary. Our IB below is 6 dwords long, That should probably read "our IB command" or "our IB packet".
Done.
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c static void sdma_v5_0_ring_emit_ib(struct amdgpu_ring *ring, · line 388
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c +2
-0+* thus add x number of NOPs, such that +* wptr + 6 + x = 8k, k >= 0. Maybe write (wrptr + 6 + x) % 8 = 0 to make that more obvious.
Quoted 6 lines
That's less obvious. In my mind I always translate it to a congruence expression. It's what I used to derive the algebraic simplifications of this patch.
I'll add the highly cryptic "(wrptr + 6 + x) % 8 = 0" to make you happy, below the algebraic expression already there.
The problem I see here is that people who are used to GPUs will think that k is a float and not immediately get what's meant here.
Quoted 7 lines
Quoted 4 lines
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c static void sdma_v5_0_ring_emit_ib(struct amdgpu_ring *ring, · line 390
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c +2
-0+*/ +sdma_v5_0_ring_insert_nop (ring, (2 -lower_32_bits (ring->wptr)) &7 );Spaces between operators please.
Yeah, I wanted to put an emphasis on the AND-op, but I'll add them.
What would be really nice to have is to keep the 10 as number of DW in the IB packet around.
Why? Why 10?
As far as I can see, THE IB packet is 6 dwords, we want to pad with some number of dwords, in order to make sure that the wptr + 6, ends up on a boundary multiple of 8. I.e. we want to solve exactly this, for x:
wptr + 6 + x = 8k, k >= 0.
x = -(wtpr + 6) = -6 - wptr = 2 - wptr (mod 8)
Also note that, 10 = 2 = -6 (mod 8).
I believe the patch is good as is.
Did you see v2 of the patch?
Regards,
Luben
Quoted 35 lines
Maybe add an "static inline
amdgpu_ring_unalign(ring, 10, 8)" helper or something like that, theinsert_nopis a ring callback anyway IIRC.Regards,
Christian.Quoted 28 lines
Regards,
LubenQuoted 23 lines
Apart form that looks good to me,
Christian.Quoted 20 lines
drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c +2
-2amdgpu_ring_write (ring,SDMA_PKT_HEADER_OP (SDMA_OP_INDIRECT ) |SDMA_PKT_INDIRECT_HEADER_VMID (vmid &0xf ));@@ -1086,10 +1090,10 @@ static void sdma_v5_0_vm_set_pte_pde(struct amdgpu_ib *ib, }/** -* sdma_v5_0_ring_pad_ib - pad the IB to the required number of dw -* +* sdma_v5_0_ring_pad_ib - pad the IB * @ib: indirect buffer to fill with padding * +* Pad the IB with NOPs to a boundary multiple of 8. */ static void sdma_v5_0_ring_pad_ib (struct amdgpu_ring *ring,struct amdgpu_ib *ib) {@@ -1097,7 +1101,7 @@ static void sdma_v5_0_ring_pad_ib(struct amdgpu_ring *ring, struct amdgpu_ib *ibu32 pad_count;int i;
Quoted 6 lines
Quoted 5 lines
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c static void sdma_v5_0_ring_pad_ib(struct amdgpu_ring *ring, struct amdgpu_ib *ib · line 1107
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c +1
-1- pad_count = (8 - (ib->length_dw &0x7 )) %8 ; + pad_count = (-ib->length_dw) &0x7 ;for (i =0 ; i < pad_count; i++)if (sdma && sdma->burst_nop && (i ==0 )) ib->ptr[ib->length_dw++] =
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 1/1 drm/amdgpu: simplify padding calculations (v2)
In reply to a message not in the archiveSimplify padding calculations.
v2: Comment update and spacing.
--- drivers/gpu/drm/amd/amdgpu/cik_sdma.c | 4 ++-- drivers/gpu/drm/amd/amdgpu/sdma_v2_4.c | 4 ++-- drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c | 4 ++-- drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c | 4 ++-- drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c | 17 ++++++++++++----- 5 files changed, 20 insertions(+), 13 deletions(-)
drivers/gpu/drm/amd/amdgpu/cik_sdma.c +2 -2
@@ -228,7 +228,7 @@ static void cik_sdma_ring_emit_ib(struct amdgpu_ring *ring,u32 extra_bits = vmid &0xf ;/* IB packet must end on a 8 DW boundary */ -cik_sdma_ring_insert_nop (ring, (12 - (lower_32_bits (ring->wptr) &7 )) %8 ); +cik_sdma_ring_insert_nop (ring, (4 -lower_32_bits (ring->wptr)) &7 );amdgpu_ring_write (ring,SDMA_PACKET (SDMA_OPCODE_INDIRECT_BUFFER ,0 , extra_bits));amdgpu_ring_write (ring, ib->gpu_addr &0xffffffe0 );/* base must be 32 byte aligned */
@@ -811,7 +811,7 @@ static void cik_sdma_ring_pad_ib(struct amdgpu_ring *ring, struct amdgpu_ib *ib)u32 pad_count;int i; - pad_count = (8 - (ib->length_dw &0x7 )) %8 ; + pad_count = (-ib->length_dw) &7 ;for (i =0 ; i < pad_count; i++)if (sdma && sdma->burst_nop && (i ==0 )) ib->ptr[ib->length_dw++] =
drivers/gpu/drm/amd/amdgpu/sdma_v2_4.c +2 -2
@@ -255,7 +255,7 @@ static void sdma_v2_4_ring_emit_ib(struct amdgpu_ring *ring,unsigned vmid =AMDGPU_JOB_GET_VMID (job);/* IB packet must end on a 8 DW boundary */ -sdma_v2_4_ring_insert_nop (ring, (10 - (lower_32_bits (ring->wptr) &7 )) %8 ); +sdma_v2_4_ring_insert_nop (ring, (2 -lower_32_bits (ring->wptr)) &7 );amdgpu_ring_write (ring,SDMA_PKT_HEADER_OP (SDMA_OP_INDIRECT ) |SDMA_PKT_INDIRECT_HEADER_VMID (vmid &0xf ));
@@ -750,7 +750,7 @@ static void sdma_v2_4_ring_pad_ib(struct amdgpu_ring *ring, struct amdgpu_ib *ibu32 pad_count;int i; - pad_count = (8 - (ib->length_dw &0x7 )) %8 ; + pad_count = (-ib->length_dw) &7 ;for (i =0 ; i < pad_count; i++)if (sdma && sdma->burst_nop && (i ==0 )) ib->ptr[ib->length_dw++] =
drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c +2 -2
@@ -429,7 +429,7 @@ static void sdma_v3_0_ring_emit_ib(struct amdgpu_ring *ring,unsigned vmid =AMDGPU_JOB_GET_VMID (job);/* IB packet must end on a 8 DW boundary */ -sdma_v3_0_ring_insert_nop (ring, (10 - (lower_32_bits (ring->wptr) &7 )) %8 ); +sdma_v3_0_ring_insert_nop (ring, (2 -lower_32_bits (ring->wptr)) &7 );amdgpu_ring_write (ring,SDMA_PKT_HEADER_OP (SDMA_OP_INDIRECT ) |SDMA_PKT_INDIRECT_HEADER_VMID (vmid &0xf ));
@@ -1021,7 +1021,7 @@ static void sdma_v3_0_ring_pad_ib(struct amdgpu_ring *ring, struct amdgpu_ib *ibu32 pad_count;int i; - pad_count = (8 - (ib->length_dw &0x7 )) %8 ; + pad_count = (-ib->length_dw) &7 ;for (i =0 ; i < pad_count; i++)if (sdma && sdma->burst_nop && (i ==0 )) ib->ptr[ib->length_dw++] =
drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c +2 -2
@@ -698,7 +698,7 @@ static void sdma_v4_0_ring_emit_ib(struct amdgpu_ring *ring,unsigned vmid =AMDGPU_JOB_GET_VMID (job);/* IB packet must end on a 8 DW boundary */ -sdma_v4_0_ring_insert_nop (ring, (10 - (lower_32_bits (ring->wptr) &7 )) %8 ); +sdma_v4_0_ring_insert_nop (ring, (2 -lower_32_bits (ring->wptr)) &7 );amdgpu_ring_write (ring,SDMA_PKT_HEADER_OP (SDMA_OP_INDIRECT ) |SDMA_PKT_INDIRECT_HEADER_VMID (vmid &0xf ));
@@ -1580,7 +1580,7 @@ static void sdma_v4_0_ring_pad_ib(struct amdgpu_ring *ring, struct amdgpu_ib *ibu32 pad_count;int i; - pad_count = (8 - (ib->length_dw &0x7 )) %8 ; + pad_count = (-ib->length_dw) &7 ;for (i =0 ; i < pad_count; i++)if (sdma && sdma->burst_nop && (i ==0 )) ib->ptr[ib->length_dw++] =
drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c +12 -5
@@ -382,8 +382,15 @@ static void sdma_v5_0_ring_emit_ib(struct amdgpu_ring *ring,unsigned vmid =AMDGPU_JOB_GET_VMID (job);uint64_t csa_mc_addr =amdgpu_sdma_get_csa_mc_addr (ring, vmid); -/* IB packet must end on a 8 DW boundary */ -sdma_v5_0_ring_insert_nop (ring, (10 - (lower_32_bits (ring->wptr) &7 )) %8 ); +/* An IB packet must end on a 8 DW boundary--the next dword +* must be on a 8-dword boundary. Our IB packet below is 6 +* dwords long, thus add x number of NOPs, such that, in +* modular arithmetic, +* wptr + 6 + x = 8k, k >= 0, which in C is, +* (wptr + 6 + x) % 8 = 0. +* The expression below, is a solution of x. +*/ +sdma_v5_0_ring_insert_nop (ring, (2 -lower_32_bits (ring->wptr)) &7 );amdgpu_ring_write (ring,SDMA_PKT_HEADER_OP (SDMA_OP_INDIRECT ) |SDMA_PKT_INDIRECT_HEADER_VMID (vmid &0xf ));
@@ -1086,10 +1093,10 @@ static void sdma_v5_0_vm_set_pte_pde(struct amdgpu_ib *ib, }/** -* sdma_v5_0_ring_pad_ib - pad the IB to the required number of dw -* +* sdma_v5_0_ring_pad_ib - pad the IB * @ib: indirect buffer to fill with padding * +* Pad the IB with NOPs to a boundary multiple of 8. */ static void sdma_v5_0_ring_pad_ib (struct amdgpu_ring *ring,struct amdgpu_ib *ib) {
@@ -1097,7 +1104,7 @@ static void sdma_v5_0_ring_pad_ib(struct amdgpu_ring *ring, struct amdgpu_ib *ibu32 pad_count;int i; - pad_count = (8 - (ib->length_dw &0x7 )) %8 ; + pad_count = (-ib->length_dw) &0x7 ;for (i =0 ; i < pad_count; i++)if (sdma && sdma->burst_nop && (i ==0 )) ib->ptr[ib->length_dw++] =
Signature · 6 lines
2.23.0.385.gbc12974a89 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): [email protected]
Koenig, Christian
Reviewed-by Christian KönigRe: [PATCH] drm/amdgpu: simplify padding calculations (v2)
Am 26.10.19 um 00:41 schrieb Tuikov, Luben:
Quoted 5 lines
Simplify padding calculations.
v2: Comment update and spacing.
Signed-off-by Luben Tuikov <[email protected]>
Quoted 132 lines
--- drivers/gpu/drm/amd/amdgpu/cik_sdma.c | 4 ++-- drivers/gpu/drm/amd/amdgpu/sdma_v2_4.c | 4 ++-- drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c | 4 ++-- drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c | 4 ++-- drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c | 17 ++++++++++++----- 5 files changed, 20 insertions(+), 13 deletions(-)drivers/gpu/drm/amd/amdgpu/cik_sdma.c +2
-2@@ -228,7 +228,7 @@ static void cik_sdma_ring_emit_ib(struct amdgpu_ring *ring,u32 extra_bits = vmid &0xf ;/* IB packet must end on a 8 DW boundary */ -cik_sdma_ring_insert_nop (ring, (12 - (lower_32_bits (ring->wptr) &7 )) %8 ); +cik_sdma_ring_insert_nop (ring, (4 -lower_32_bits (ring->wptr)) &7 );amdgpu_ring_write (ring,SDMA_PACKET (SDMA_OPCODE_INDIRECT_BUFFER ,0 , extra_bits));amdgpu_ring_write (ring, ib->gpu_addr &0xffffffe0 );/* base must be 32 byte aligned */ @@ -811,7 +811,7 @@ static void cik_sdma_ring_pad_ib(struct amdgpu_ring *ring, struct amdgpu_ib *ib)u32 pad_count;int i; - pad_count = (8 - (ib->length_dw &0x7 )) %8 ; + pad_count = (-ib->length_dw) &7 ;for (i =0 ; i < pad_count; i++)if (sdma && sdma->burst_nop && (i ==0 )) ib->ptr[ib->length_dw++] =drivers/gpu/drm/amd/amdgpu/sdma_v2_4.c +2
-2@@ -255,7 +255,7 @@ static void sdma_v2_4_ring_emit_ib(struct amdgpu_ring *ring,unsigned vmid =AMDGPU_JOB_GET_VMID (job);/* IB packet must end on a 8 DW boundary */ -sdma_v2_4_ring_insert_nop (ring, (10 - (lower_32_bits (ring->wptr) &7 )) %8 ); +sdma_v2_4_ring_insert_nop (ring, (2 -lower_32_bits (ring->wptr)) &7 );amdgpu_ring_write (ring,SDMA_PKT_HEADER_OP (SDMA_OP_INDIRECT ) |SDMA_PKT_INDIRECT_HEADER_VMID (vmid &0xf ));@@ -750,7 +750,7 @@ static void sdma_v2_4_ring_pad_ib(struct amdgpu_ring *ring, struct amdgpu_ib *ibu32 pad_count;int i; - pad_count = (8 - (ib->length_dw &0x7 )) %8 ; + pad_count = (-ib->length_dw) &7 ;for (i =0 ; i < pad_count; i++)if (sdma && sdma->burst_nop && (i ==0 )) ib->ptr[ib->length_dw++] =drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c +2
-2@@ -429,7 +429,7 @@ static void sdma_v3_0_ring_emit_ib(struct amdgpu_ring *ring,unsigned vmid =AMDGPU_JOB_GET_VMID (job);/* IB packet must end on a 8 DW boundary */ -sdma_v3_0_ring_insert_nop (ring, (10 - (lower_32_bits (ring->wptr) &7 )) %8 ); +sdma_v3_0_ring_insert_nop (ring, (2 -lower_32_bits (ring->wptr)) &7 );amdgpu_ring_write (ring,SDMA_PKT_HEADER_OP (SDMA_OP_INDIRECT ) |SDMA_PKT_INDIRECT_HEADER_VMID (vmid &0xf ));@@ -1021,7 +1021,7 @@ static void sdma_v3_0_ring_pad_ib(struct amdgpu_ring *ring, struct amdgpu_ib *ibu32 pad_count;int i; - pad_count = (8 - (ib->length_dw &0x7 )) %8 ; + pad_count = (-ib->length_dw) &7 ;for (i =0 ; i < pad_count; i++)if (sdma && sdma->burst_nop && (i ==0 )) ib->ptr[ib->length_dw++] =drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c +2
-2@@ -698,7 +698,7 @@ static void sdma_v4_0_ring_emit_ib(struct amdgpu_ring *ring,unsigned vmid =AMDGPU_JOB_GET_VMID (job);/* IB packet must end on a 8 DW boundary */ -sdma_v4_0_ring_insert_nop (ring, (10 - (lower_32_bits (ring->wptr) &7 )) %8 ); +sdma_v4_0_ring_insert_nop (ring, (2 -lower_32_bits (ring->wptr)) &7 );amdgpu_ring_write (ring,SDMA_PKT_HEADER_OP (SDMA_OP_INDIRECT ) |SDMA_PKT_INDIRECT_HEADER_VMID (vmid &0xf ));@@ -1580,7 +1580,7 @@ static void sdma_v4_0_ring_pad_ib(struct amdgpu_ring *ring, struct amdgpu_ib *ibu32 pad_count;int i; - pad_count = (8 - (ib->length_dw &0x7 )) %8 ; + pad_count = (-ib->length_dw) &7 ;for (i =0 ; i < pad_count; i++)if (sdma && sdma->burst_nop && (i ==0 )) ib->ptr[ib->length_dw++] =drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c +11
-4@@ -382,8 +382,15 @@ static void sdma_v5_0_ring_emit_ib(struct amdgpu_ring *ring,unsigned vmid =AMDGPU_JOB_GET_VMID (job);uint64_t csa_mc_addr =amdgpu_sdma_get_csa_mc_addr (ring, vmid); -/* IB packet must end on a 8 DW boundary */ -sdma_v5_0_ring_insert_nop (ring, (10 - (lower_32_bits (ring->wptr) &7 )) %8 ); +/* An IB packet must end on a 8 DW boundary--the next dword +* must be on a 8-dword boundary. Our IB packet below is 6 +* dwords long, thus add x number of NOPs, such that, in +* modular arithmetic, +* wptr + 6 + x = 8k, k >= 0, which in C is, +* (wptr + 6 + x) % 8 = 0. +* The expression below, is a solution of x. +*/ +sdma_v5_0_ring_insert_nop (ring, (2 -lower_32_bits (ring->wptr)) &7 );amdgpu_ring_write (ring,SDMA_PKT_HEADER_OP (SDMA_OP_INDIRECT ) |SDMA_PKT_INDIRECT_HEADER_VMID (vmid &0xf ));@@ -1086,10 +1093,10 @@ static void sdma_v5_0_vm_set_pte_pde(struct amdgpu_ib *ib, }/** -* sdma_v5_0_ring_pad_ib - pad the IB to the required number of dw -* +* sdma_v5_0_ring_pad_ib - pad the IB * @ib: indirect buffer to fill with padding * +* Pad the IB with NOPs to a boundary multiple of 8. */ static void sdma_v5_0_ring_pad_ib (struct amdgpu_ring *ring,struct amdgpu_ib *ib) {
drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c static void sdma_v5_0_ring_pad_ib(struct amdgpu_ring *ring, struct amdgpu_ib *ib · line 1110
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c +1
-1@@ -1097,7 +1104,7 @@ static void sdma_v5_0_ring_pad_ib(struct amdgpu_ring *ring, struct amdgpu_ib *ibu32 pad_count;int i; - pad_count = (8 - (ib->length_dw &0x7 )) %8 ; + pad_count = (-ib->length_dw) &0x7 ;for (i =0 ; i < pad_count; i++)if (sdma && sdma->burst_nop && (i ==0 )) ib->ptr[ib->length_dw++] =
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx