Skip to contentSkip to conversation

drm/amdgpu: move error log from ring write to commit

PATCH In review Sunil Khatri 2 participants 4 messages Oct 3, 2024 – Oct 7, 2024

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

PATCH v2 1/2 drm/amdgpu: move error log from ring write to commit

Move the error message from ring write as an optimization to avoid printing that message on every write instead print once during commit if it exceeds write the allocated size i.e ring->count_dw.

Also we do not want to log the error message in between a ring write and complete the write as its mostly not harmful as it will overwrite stale data only as GPU read from ring is faster than CPU write to ring.

This reduces the size of amdgpu.ko module by around 600 Kb as write is very often used function and hence the print.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c | 3 +++
 drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h | 2 --
 2 files changed, 3 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +3 -0
index 690976665cf6..05b3480ecec7 100644
@@ -141,6 +141,9 @@ void amdgpu_ring_commit(struct amdgpu_ring *ring)
 {
 	uint32_t count;
 
+	if (ring->count_dw <= 0)
+		DRM_ERROR("amdgpu: writing more dwords to the ring than expected!\n");
+
 	/* We pad to match fetch size */
 	count = ring->funcs->align_mask + 1 -
 		(ring->wptr & ring->funcs->align_mask);
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h +0 -2
index f93f51002201..af8824e8da49 100644
@@ -377,8 +377,6 @@ static inline void amdgpu_ring_clear_ring(struct amdgpu_ring *ring)
 
 static inline void amdgpu_ring_write(struct amdgpu_ring *ring, uint32_t v)
 {
-	if (ring->count_dw <= 0)
-		DRM_ERROR("amdgpu: writing more dwords to the ring than expected!\n");
 	ring->ring[ring->wptr++ & ring->buf_mask] = v;
 	ring->wptr &= ring->ptr_mask;
 	ring->count_dw--;
Signature · 1 line
2.34.1
#1 lore raw

PATCH v2 2/2 drm/amdgpu: no need to log error in multi ring write

No need to log error in multi ring write as its taken care during ring commit.

This is inline with change done in amdgpu_ring_write.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h | 3 ---
 1 file changed, 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h +0 -3
index af8824e8da49..574336d6714a 100644
@@ -388,9 +388,6 @@ static inline void amdgpu_ring_write_multiple(struct amdgpu_ring *ring,
 	unsigned occupied, chunk1, chunk2;
 	void *dst;
 
-	if (unlikely(ring->count_dw < count_dw))
-		DRM_ERROR("amdgpu: writing more dwords to the ring than expected!\n");
-
 	occupied = ring->wptr & ring->buf_mask;
 	dst = (void *)&ring->ring[occupied];
 	chunk1 = ring->buf_mask + 1 - occupied;
Signature · 1 line
2.34.1
maintainer
#2 lore raw
In reply to Sunil Khatri

Am 03.10.24 um 10:28 schrieb Sunil Khatri:

Quoted 26 lines

Move the error message from ring write as an optimization to avoid printing that message on every write instead print once during commit if it exceeds write the allocated size i.e ring->count_dw.

Also we do not want to log the error message in between a ring write and complete the write as its mostly not harmful as it will overwrite stale data only as GPU read from ring is faster than CPU write to ring.

This reduces the size of amdgpu.ko module by around 600 Kb as write is very often used function and hence the print.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c | 3 +++
  drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h | 2 --
  2 files changed, 3 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +0 -0
index 690976665cf6..05b3480ecec7 100644

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

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +3 -0
@@ -141,6 +141,9 @@ void amdgpu_ring_commit(struct amdgpu_ring *ring)
  {
  	uint32_t count;
 
+	if (ring->count_dw <= 0)
+		DRM_ERROR("amdgpu: writing more dwords to the ring than expected!\n");
+

Oh, I missed this on the first review a count_dw of 0 is actually ok since that means we have written exactly as much dw as estimated.

Regards,
Christian.

Quoted 16 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +0 -0
  	/* We pad to match fetch size */
  	count = ring->funcs->align_mask + 1 -
  		(ring->wptr & ring->funcs->align_mask);
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h +0 -2
index f93f51002201..af8824e8da49 100644
@@ -377,8 +377,6 @@ static inline void amdgpu_ring_clear_ring(struct amdgpu_ring *ring)
 
  static inline void amdgpu_ring_write(struct amdgpu_ring *ring, uint32_t v)
  {
-	if (ring->count_dw <= 0)
-		DRM_ERROR("amdgpu: writing more dwords to the ring than expected!\n");
  	ring->ring[ring->wptr++ & ring->buf_mask] = v;
  	ring->wptr &= ring->ptr_mask;
  	ring->count_dw--;
#3 lore raw
Quoted 22 lines · Christian König

Am 03.10.24 um 10:28 schrieb Sunil Khatri:

Quoted 21 lines

Move the error message from ring write as an optimization to avoid printing that message on every write instead print once during commit if it exceeds write the allocated size i.e ring->count_dw.

Also we do not want to log the error message in between a ring write and complete the write as its mostly not harmful as it will overwrite stale data only as GPU read from ring is faster than CPU write to ring.

This reduces the size of amdgpu.ko module by around 600 Kb as write is very often used function and hence the print.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c | 3 +++ drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h | 2 --

  2 files changed, 3 insertions(+), 2 deletions(-)
Quoted 13 lines

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

Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +2 -0
index 690976665cf6..05b3480ecec7 100644
@@ -141,6 +141,9 @@ void amdgpu_ring_commit(struct amdgpu_ring *ring)
   {
       uint32_t count;
   +    if (ring->count_dw <= 0)
+        DRM_ERROR("amdgpu: writing more dwords to the ring than 
 expected!\n");
+

Oh, I missed this on the first review a count_dw of 0 is actually ok since that means we have written exactly as much dw as estimated.

Sure i will replace it with below code

 if (ring->count_dw < 0)

Regards
Sunil khatri

Quoted 22 lines

Regards,
Christian.

Quoted 17 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +0 -0
       /* We pad to match fetch size */

      count = ring->funcs->align_mask + 1 - (ring->wptr & ring->funcs->align_mask);

drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h +0 -2
index f93f51002201..af8824e8da49 100644
@@ -377,8 +377,6 @@ static inline void amdgpu_ring_clear_ring(struct 
 amdgpu_ring *ring)
     static inline void amdgpu_ring_write(struct amdgpu_ring *ring, uint32_t v)
   {
-    if (ring->count_dw <= 0)
-        DRM_ERROR("amdgpu: writing more dwords to the ring than 
 expected!\n");
       ring->ring[ring->wptr++ & ring->buf_mask] = v;
       ring->wptr &= ring->ptr_mask;

      ring->count_dw--;