drm/amdgpu: Increase KIQ invalidate_tlbs timeout
Subsystems (2)
PATCH 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.
--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 1 - drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 15 +++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +0 -1
@@ -355,7 +355,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 +11 -4
@@ -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,7 +759,16 @@ 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 ) { + +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 ; }
Signature · 1 line
2.34.1
[Public]
Do we want to actually do a fence_wait_polling before the loop begins like in all of the other functions? I know 5ms isn't a big deal, but the other ones we have are all after a single fence_wait_polling first.
Kent
Quoted 76 lines
-----Original Message-----
From: Cornwall, Jay <[email protected]>
Sent: Friday, March 21, 2025 2:27 PM
To: [email protected]
Cc: Cornwall, Jay <[email protected]>; Russell, Kent <[email protected]>
Subject: [PATCH] drm/amdgpu: Increase KIQinvalidate_tlbstimeoutKIQ
invalidate_tlbsrequest 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_tlbspath.Signed-off-by Jay Cornwall <[email protected]>Cc Kent Russell <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 1 - drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 15 +++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu.h +0
-1@@ -355,7 +355,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 1000drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +1
-3@@ -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;/*drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +10
-1@@ -761,7 +759,16 @@ 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 ) { + +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; }--
2.34.1
Quoted 1 line · Kent
Do we want to actually do a
fence_wait_pollingbefore the loop begins like in all of the other functions? I know 5ms isn't a big deal, but the other ones we have are all after a singlefence_wait_pollingfirst.
I think the intent of that is to exit early when in an interrupt context (not the case here) and to check for GPU recovery (checked every loop iteration here).
Though I don't entirely understand how exiting early from an interrupt would work. A quick KIQ request can be stuck behind slow ones and 5ms is very short.
Quoted 1 line · Kent
Do we want to actually do a
fence_wait_pollingbefore the loop begins like in all of the other functions? I know 5ms isn't a big deal, but the other ones we have are all after a singlefence_wait_pollingfirst.
Oh I see what you're saying now. This introduces an unconditional 5ms delay before the first poll. D'oh, I'll send a v2. Thanks for the catch.