Skip to contentSkip to conversation

drm/amdgpu: Increase KIQ invalidate_tlbs timeout

PATCH In review Jay Cornwall 3 participants 4 messages Mar 31, 2025 – Apr 2, 2025

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

PATCH v3 1/1 drm/amdgpu: Increase KIQ invalidate_tlbs timeout

KIQ invalidate_tlbs request has been seen to marginally exceed the configured 100 ms timeout on systems under load.

All other KIQ requests in the driver use a 10 second timeout. Use a similar timeout implementation on the invalidate_tlbs path.

v2: Poll once before msleep
v3: Fix return value

---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h     |  1 -
 drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 19 ++++++++++++++-----
 2 files changed, 14 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +0 -1
index ffca74a476da..3cdb5f8325aa 100644
@@ -356,7 +356,6 @@ enum amdgpu_kiq_irq {
 	AMDGPU_CP_KIQ_IRQ_DRIVER0 = 0,
 	AMDGPU_CP_KIQ_IRQ_LAST
 };
-#define SRIOV_USEC_TIMEOUT  1200000 /* wait 12 * 100ms for SRIOV */
 #define MAX_KIQ_REG_WAIT       5000 /* in usecs, 5ms */
 #define MAX_KIQ_REG_BAILOUT_INTERVAL   5 /* in msecs, 5ms */
 #define MAX_KIQ_REG_TRY 1000
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +14 -5
index 464625282872..ecb74ccf1d90 100644
@@ -699,12 +699,10 @@ int amdgpu_gmc_flush_gpu_tlb_pasid(struct amdgpu_device *adev, uint16_t pasid,
 				   uint32_t flush_type, bool all_hub,
 				   uint32_t inst)
 {
-	u32 usec_timeout = amdgpu_sriov_vf(adev) ? SRIOV_USEC_TIMEOUT :
-		adev->usec_timeout;
 	struct amdgpu_ring *ring = &adev->gfx.kiq[inst].ring;
 	struct amdgpu_kiq *kiq = &adev->gfx.kiq[inst];
 	unsigned int ndw;
-	int r;
+	int r, cnt = 0;
 	uint32_t seq;
 
 	/*
@@ -761,10 +759,21 @@ int amdgpu_gmc_flush_gpu_tlb_pasid(struct amdgpu_device *adev, uint16_t pasid,
 
 		amdgpu_ring_commit(ring);
 		spin_unlock(&adev->gfx.kiq[inst].ring_lock);
-		if (amdgpu_fence_wait_polling(ring, seq, usec_timeout) < 1) {
+
+		r = amdgpu_fence_wait_polling(ring, seq, MAX_KIQ_REG_WAIT);
+
+		might_sleep();
+		while (r < 1 && cnt++ < MAX_KIQ_REG_TRY &&
+		       !amdgpu_reset_pending(adev->reset_domain)) {
+			msleep(MAX_KIQ_REG_BAILOUT_INTERVAL);
+			r = amdgpu_fence_wait_polling(ring, seq, MAX_KIQ_REG_WAIT);
+		}
+
+		if (cnt > MAX_KIQ_REG_TRY) {
 			dev_err(adev->dev, "timeout waiting for kiq fence\n");
 			r = -ETIME;
-		}
+		} else
+			r = 0;
 	}
 
 error_unlock_reset:
Signature · 1 line
2.34.1
Reviewed-by on v3 1/1
#1 lore raw

[AMD Official Use Only - AMD Internal Distribution Only]

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Jay Cornwall
Sent: Monday, March 31, 2025 11:45 AM
To: [email protected]
Cc: Cornwall, Jay <[email protected]>; Russell, Kent <[email protected]>
Subject: [PATCH v3] drm/amdgpu: Increase KIQ invalidate_tlbs timeout

KIQ invalidate_tlbs request has been seen to marginally exceed the configured 100 ms timeout on systems under load.

All other KIQ requests in the driver use a 10 second timeout. Use a similar timeout implementation on the invalidate_tlbs path.

v2: Poll once before msleep
v3: Fix return value

---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h     |  1 -
 drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 19 ++++++++++++++-----
 2 files changed, 14 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +0 -1
index ffca74a476da..3cdb5f8325aa 100644
@@ -356,7 +356,6 @@ enum amdgpu_kiq_irq {
        AMDGPU_CP_KIQ_IRQ_DRIVER0 = 0,
        AMDGPU_CP_KIQ_IRQ_LAST
 };
-#define SRIOV_USEC_TIMEOUT  1200000 /* wait 12 * 100ms for SRIOV */
 #define MAX_KIQ_REG_WAIT       5000 /* in usecs, 5ms */
 #define MAX_KIQ_REG_BAILOUT_INTERVAL   5 /* in msecs, 5ms */
 #define MAX_KIQ_REG_TRY 1000
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +14 -5
index 464625282872..ecb74ccf1d90 100644
@@ -699,12 +699,10 @@ int amdgpu_gmc_flush_gpu_tlb_pasid(struct amdgpu_device *adev, uint16_t pasid,
                                   uint32_t flush_type, bool all_hub,
                                   uint32_t inst)
 {
-       u32 usec_timeout = amdgpu_sriov_vf(adev) ? SRIOV_USEC_TIMEOUT :
-               adev->usec_timeout;
        struct amdgpu_ring *ring = &adev->gfx.kiq[inst].ring;
        struct amdgpu_kiq *kiq = &adev->gfx.kiq[inst];
        unsigned int ndw;
-       int r;
+       int r, cnt = 0;
        uint32_t seq;
 
        /*
@@ -761,10 +759,21 @@ int amdgpu_gmc_flush_gpu_tlb_pasid(struct amdgpu_device *adev, uint16_t pasid,
 
                amdgpu_ring_commit(ring);
                spin_unlock(&adev->gfx.kiq[inst].ring_lock);
-               if (amdgpu_fence_wait_polling(ring, seq, usec_timeout) < 1) {
+
+               r = amdgpu_fence_wait_polling(ring, seq, MAX_KIQ_REG_WAIT);
+
+               might_sleep();
+               while (r < 1 && cnt++ < MAX_KIQ_REG_TRY &&
+                      !amdgpu_reset_pending(adev->reset_domain)) {
+                       msleep(MAX_KIQ_REG_BAILOUT_INTERVAL);
+                       r = amdgpu_fence_wait_polling(ring, seq, MAX_KIQ_REG_WAIT);
+               }
+
+               if (cnt > MAX_KIQ_REG_TRY) {
                        dev_err(adev->dev, "timeout waiting for kiq fence\n");
                        r = -ETIME;
-               }
+               } else
+                       r = 0;
        }
 
 error_unlock_reset:

--
2.34.1

#2 lore raw
In reply to Jay Cornwall

Am 31.03.25 um 17:44 schrieb Jay Cornwall:

Quoted 21 lines

KIQ invalidate_tlbs request has been seen to marginally exceed the configured 100 ms timeout on systems under load.

All other KIQ requests in the driver use a 10 second timeout. Use a similar timeout implementation on the invalidate_tlbs path.

v2: Poll once before msleep
v3: Fix return value

---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h     |  1 -
 drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 19 ++++++++++++++-----
 2 files changed, 14 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +0 -0
index ffca74a476da..3cdb5f8325aa 100644

drivers/gpu/drm/amd/amdgpu/amdgpu.h enum amdgpu_kiq_irq { · line 361

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +0 -1
@@ -356,7 +356,6 @@ enum amdgpu_kiq_irq {
 	AMDGPU_CP_KIQ_IRQ_DRIVER0 = 0,
 	AMDGPU_CP_KIQ_IRQ_LAST
 };
-#define SRIOV_USEC_TIMEOUT  1200000 /* wait 12 * 100ms for SRIOV */
 #define MAX_KIQ_REG_WAIT       5000 /* in usecs, 5ms */
 #define MAX_KIQ_REG_BAILOUT_INTERVAL   5 /* in msecs, 5ms */
 #define MAX_KIQ_REG_TRY 1000

Unrelated to this patch here, but defines like those *must* have an AMDGPU_ prefix.

Please fix in a follow up patch.

Regards,
Christian.

Quoted 42 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +14 -5
index 464625282872..ecb74ccf1d90 100644
@@ -699,12 +699,10 @@ int amdgpu_gmc_flush_gpu_tlb_pasid(struct amdgpu_device *adev, uint16_t pasid,
 				   uint32_t flush_type, bool all_hub,
 				   uint32_t inst)
 {
-	u32 usec_timeout = amdgpu_sriov_vf(adev) ? SRIOV_USEC_TIMEOUT :
-		adev->usec_timeout;
 	struct amdgpu_ring *ring = &adev->gfx.kiq[inst].ring;
 	struct amdgpu_kiq *kiq = &adev->gfx.kiq[inst];
 	unsigned int ndw;
-	int r;
+	int r, cnt = 0;
 	uint32_t seq;
 
 	/*
@@ -761,10 +759,21 @@ int amdgpu_gmc_flush_gpu_tlb_pasid(struct amdgpu_device *adev, uint16_t pasid,
 
 		amdgpu_ring_commit(ring);
 		spin_unlock(&adev->gfx.kiq[inst].ring_lock);
-		if (amdgpu_fence_wait_polling(ring, seq, usec_timeout) < 1) {
+
+		r = amdgpu_fence_wait_polling(ring, seq, MAX_KIQ_REG_WAIT);
+
+		might_sleep();
+		while (r < 1 && cnt++ < MAX_KIQ_REG_TRY &&
+		       !amdgpu_reset_pending(adev->reset_domain)) {
+			msleep(MAX_KIQ_REG_BAILOUT_INTERVAL);
+			r = amdgpu_fence_wait_polling(ring, seq, MAX_KIQ_REG_WAIT);
+		}
+
+		if (cnt > MAX_KIQ_REG_TRY) {
 			dev_err(adev->dev, "timeout waiting for kiq fence\n");
 			r = -ETIME;
-		}
+		} else
+			r = 0;
 	}
 
 error_unlock_reset:
#3 lore raw
Quoted 15 lines · Christian König

drivers/gpu/drm/amd/amdgpu/amdgpu.h enum amdgpu_kiq_irq { · line 361

Quoted 12 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +0 -1
index ffca74a476da..3cdb5f8325aa 100644
@@ -356,7 +356,6 @@ enum amdgpu_kiq_irq {
  	AMDGPU_CP_KIQ_IRQ_DRIVER0 = 0,
  	AMDGPU_CP_KIQ_IRQ_LAST
  };
-#define SRIOV_USEC_TIMEOUT  1200000 /* wait 12 * 100ms for SRIOV */
  #define MAX_KIQ_REG_WAIT       5000 /* in usecs, 5ms */
  #define MAX_KIQ_REG_BAILOUT_INTERVAL   5 /* in msecs, 5ms */
  #define MAX_KIQ_REG_TRY 1000

Unrelated to this patch here, but defines like those *must* have an AMDGPU_ prefix.

Quoted 1 line

Please fix in a follow up patch.

Sure. A deeper problem which has led to these macros is the duplication of polling logic across several different files.

We could instead move this code into amdgpu_fence_wait_polling. All clients would then abort early on in_reset or in_interrupt. There are a couple of users with different timeouts (adev->usec_timeout and a hard-coded 2100ms) which could be unified or retained with a fixed 5ms polling interval.

adev->usec_timeout is too low for this particular system under load.