Skip to contentSkip to conversation

drm/amdgpu: improve wait logic at fence polling

PATCH In review Alex Sierra 3 participants 3 messages Apr 26, 2023 – May 12, 2023

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

PATCH 1/1 drm/amdgpu: improve wait logic at fence polling

Accomplish this by reading the seq number right away instead of sleep for 5us. There are certain cases where the fence is ready almost immediately. Sleep number granularity was also reduced as the majority of the kiq tlb flush takes between 2us to 6us.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +4 -7
index a7627cc0118d..9192896239e9 100644
@@ -377,14 +377,11 @@ signed long amdgpu_fence_wait_polling(struct amdgpu_ring *ring,
 				      uint32_t wait_seq,
 				      signed long timeout)
 {
-	uint32_t seq;
-
-	do {
-		seq = amdgpu_fence_read(ring);
-		udelay(5);
-		timeout -= 5;
-	} while ((int32_t)(wait_seq - seq) > 0 && timeout > 0);
 
+	while ((int32_t)(wait_seq - amdgpu_fence_read(ring)) > 0 && timeout > 0) {
+		udelay(2);
+		timeout -= 2;
+	}
 	return timeout > 0 ? timeout : 0;
 }
 /**
Signature · 1 line
2.32.0
Acked-by on v1 1/1
#1 lore raw

Am 2023-04-26 um 12:15 schrieb Alex Sierra:

Quoted 6 lines

Accomplish this by reading the seq number right away instead of sleep for 5us. There are certain cases where the fence is ready almost immediately. Sleep number granularity was also reduced as the majority of the kiq tlb flush takes between 2us to 6us.

I'm not sure I have authority to give an R-b for this. But the change and the explanation sound reasonable to me. Doing the first check before waiting is a no-brainer. Reducing the delay can increase CPU usage or bus traffic and may be more controversial.

FWIW, this patch is

Quoted 27 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c | 11 ++++-------
  1 file changed, 4 insertions(+), 7 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +4 -7
index a7627cc0118d..9192896239e9 100644
@@ -377,14 +377,11 @@ signed long amdgpu_fence_wait_polling(struct amdgpu_ring *ring,
  				      uint32_t wait_seq,
  				      signed long timeout)
  {
-	uint32_t seq;
-
-	do {
-		seq = amdgpu_fence_read(ring);
-		udelay(5);
-		timeout -= 5;
-	} while ((int32_t)(wait_seq - seq) > 0 && timeout > 0);
 
+	while ((int32_t)(wait_seq - amdgpu_fence_read(ring)) > 0 && timeout > 0) {
+		udelay(2);
+		timeout -= 2;
+	}
  	return timeout > 0 ? timeout : 0;
  }
  /**
Reviewed-by
#2 lore raw
Quoted 7 lines · Felix Kuehling

Am 2023-04-26 um 12:15 schrieb Alex Sierra:

Quoted 5 lines

Accomplish this by reading the seq number right away instead of sleep for 5us. There are certain cases where the fence is ready almost immediately. Sleep number granularity was also reduced as the majority of the kiq tlb flush takes between 2us to 6us.

Quoted 7 lines
Quoted 1 line

I'm not sure I have authority to give an R-b for this. But the change and the explanation sound reasonable to me. Doing the first check before waiting is a no-brainer. Reducing the delay can increase CPU usage or bus traffic and may be more controversial.

The fences should be in system memory, so it shouldn't affect bus traffic, but there could be more CPU usage. The change seems fine to me.

Quoted 32 lines

FWIW, this patch is

Quoted 27 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c | 11 ++++-------
  1 file changed, 4 insertions(+), 7 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +4 -7
index a7627cc0118d..9192896239e9 100644
@@ -377,14 +377,11 @@ signed long amdgpu_fence_wait_polling(struct amdgpu_ring *ring,
                                    uint32_t wait_seq,
                                    signed long timeout)
  {
-     uint32_t seq;
-
-     do {
-             seq = amdgpu_fence_read(ring);
-             udelay(5);
-             timeout -= 5;
-     } while ((int32_t)(wait_seq - seq) > 0 && timeout > 0);
 
+     while ((int32_t)(wait_seq - amdgpu_fence_read(ring)) > 0 && timeout > 0) {
+             udelay(2);
+             timeout -= 2;
+     }
      return timeout > 0 ? timeout : 0;
  }
  /**