Skip to contentSkip to conversation

drm/amdgpu: clean up the count calculation for nop

PATCH In review Sunil Khatri 2 participants 2 messages Jul 31, 2024

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

PATCH 1/1 drm/amdgpu: clean up the count calculation for nop

clean up the calculation for nops count before
commit in the ring.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +2 -3
index 0d72d2cbb64b..2c8218332c65 100644
@@ -142,9 +142,8 @@ void amdgpu_ring_commit(struct amdgpu_ring *ring)
 	uint32_t count;
 
 	/* We pad to match fetch size */
-	count = ring->funcs->align_mask + 1 -
-		(ring->wptr & ring->funcs->align_mask);
-	count %= ring->funcs->align_mask + 1;
+	count = ring->funcs->align_mask -
+		((ring->wptr + ring->funcs->align_mask) & ring->funcs->align_mask);
 
 	if (count != 0)
 		ring->funcs->insert_nop(ring, count);
Signature · 1 line
2.34.1
maintainer
#1 lore raw

Am 31.07.24 um 11:35 schrieb Sunil Khatri:

Quoted 13 lines

clean up the calculation for nops count before
commit in the ring.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c | 5 ++---
  1 file changed, 2 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +0 -0
index 0d72d2cbb64b..2c8218332c65 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c void amdgpu_ring_commit(struct amdgpu_ring *ring) · line 146

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +2 -3
@@ -142,9 +142,8 @@ void amdgpu_ring_commit(struct amdgpu_ring *ring)
  	uint32_t count;
 
  	/* We pad to match fetch size */
-	count = ring->funcs->align_mask + 1 -
-		(ring->wptr & ring->funcs->align_mask);
-	count %= ring->funcs->align_mask + 1;
+	count = ring->funcs->align_mask -
+		((ring->wptr + ring->funcs->align_mask) & ring->funcs->align_mask);

I just realized that the old handling was potentially better since it only required a constant addition instead of two with the align_mask.

E.g. "ring->funcs->align_mask + 1 -" looks a bit odd but might be less instructions.

Maybe just review and commit the version from Tvrtko which just replaces the % with an & operation.

Regards,
Christian.

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +0 -0
  	if (count != 0)
  		ring->funcs->insert_nop(ring, count);