drm/amdgpu: Add timeout for sync wait
Subsystems (3)
PATCH 1/2 drm/amdgpu: Add timeout for sync wait
Issue: Dead heappen during gpu recover, the call sequence as below:
amdgpu_device_gpu_recover->amdgpu_amdkfd_pre_reset->flush_delayed_work-> amdgpu_amdkfd_gpuvm_restore_process_bos->amdgpu_sync_wait
It is because the amdgpu_sync_wait is waiting for the bad job's fence, and never return, so the recover couldn't continue.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c +9 -2
@@ -406,8 +406,15 @@ int amdgpu_sync_wait(struct amdgpu_sync *sync, bool intr)int i, r;hash_for_each_safe (sync->fences, i, tmp, e, node) { - r =dma_fence_wait (e->fence, intr); -if (r) +struct drm_sched_fence *s_fence =to_drm_sched_fence (e->fence); +long timeout =msecs_to_jiffies (10000 ); + +if (s_fence) + timeout = s_fence->sched->timeout; + +if (r ==0 ) + r = -ETIMEDOUT ; +if (r <0 )return r;amdgpu_sync_entry_free (e);
Signature · 1 line
2.36.1
PATCH 2/2 drm/amdgpu: handle the return for sync wait
--- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 9 ++++++--- drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c | 6 +++++- 2 files changed, 11 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +6 -3
@@ -2668,7 +2668,7 @@ static int validate_invalid_user_pages(struct amdkfd_process_info *process_info) unreserve_out:ttm_eu_backoff_reservation (&ticket, &resv_list); -amdgpu_sync_wait (&sync, false); + ret =amdgpu_sync_wait (&sync, false);amdgpu_sync_free (&sync); out_free:kfree (pd_bo_list_entries);
@@ -2939,8 +2939,11 @@ int amdgpu_amdkfd_gpuvm_restore_process_bos(void *info, struct dma_fence **ef) }/* Wait for validate and PT updates to finish */ -amdgpu_sync_wait (&sync_obj, false); - + ret =amdgpu_sync_wait (&sync_obj, false); +if (ret) { +pr_err ("Failed to wait for validate and PT updates to finish\n" ); + goto validate_map_fail; + }/* Release old eviction fence and create new one, because fence only * goes from unsignaled to signaled, fence cannot be reused. * Use context and mm from the old fence.
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c +5 -1
@@ -1153,7 +1153,11 @@ int amdgpu_mes_ctx_map_meta_data(struct amdgpu_device *adev, }amdgpu_sync_fence (&sync, vm->last_update); -amdgpu_sync_wait (&sync, false); + r =amdgpu_sync_wait (&sync, false); +if (r) { +DRM_ERROR ("failed to wait sync\n" ); + goto error; + }ttm_eu_backoff_reservation (&ticket, &list);amdgpu_sync_free (&sync);
Signature · 1 line
2.36.1
Re: [PATCH 2/2] drm/amdgpu: handle the return for sync wait
Am 20.10.23 um 08:13 schrieb Emily Deng:
You need a patch description and this patch here needs to come first and not second.
Christian.
Quoted 50 lines
Signed-off-by Emily Deng <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 9 ++++++--- drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c | 6 +++++- 2 files changed, 11 insertions(+), 4 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +6
-3@@ -2668,7 +2668,7 @@ static int validate_invalid_user_pages(struct amdkfd_process_info *process_info) unreserve_out:ttm_eu_backoff_reservation (&ticket, &resv_list); -amdgpu_sync_wait (&sync, false); + ret =amdgpu_sync_wait (&sync, false);amdgpu_sync_free (&sync); out_free:kfree (pd_bo_list_entries);@@ -2939,8 +2939,11 @@ int amdgpu_amdkfd_gpuvm_restore_process_bos(void *info, struct dma_fence **ef) }/* Wait for validate and PT updates to finish */ -amdgpu_sync_wait (&sync_obj, false); - + ret =amdgpu_sync_wait (&sync_obj, false); +if (ret) { +pr_err ("Failed to wait for validate and PT updates to finish\n" ); + goto validate_map_fail; + }/* Release old eviction fence and create new one, because fence only * goes from unsignaled to signaled, fence cannot be reused. * Use context and mm from the old fence. drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c +5
-1@@ -1153,7 +1153,11 @@ int amdgpu_mes_ctx_map_meta_data(struct amdgpu_device *adev, }amdgpu_sync_fence (&sync, vm->last_update); -amdgpu_sync_wait (&sync, false); + r =amdgpu_sync_wait (&sync, false); +if (r) { +DRM_ERROR ("failed to wait sync\n" ); + goto error; + }ttm_eu_backoff_reservation (&ticket, &list);amdgpu_sync_free (&sync);
RE: [PATCH 2/2] drm/amdgpu: handle the return for sync wait
[AMD Official Use Only - General]
Ok, will send this as the first.
Emily Deng
Best Wishes
Quoted 69 lines
-----Original Message-----
From: Christian König <[email protected]>
Sent: Friday, October 20, 2023 3:30 PM
To: Deng, Emily <[email protected]>; [email protected]
Subject: Re: [PATCH 2/2] drm/amdgpu: handle the return for sync waitAm 20.10.23 um 08:13 schrieb Emily Deng:
You need a patch description and this patch here needs to come first and not second.
Christian.
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c int
Quoted 22 lines
Signed-off-by Emily Deng <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 9 ++++++--- drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c | 6 +++++- 2 files changed, 11 insertions(+), 4 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +1
-1@@ -2668,7 +2668,7 @@ static int validate_invalid_user_pages(struct amdkfd_process_info *process_info) unreserve_out: ttm_eu_backoff_reservation(&ticket, &resv_list); -amdgpu_sync_wait (&sync, false); + ret =amdgpu_sync_wait (&sync, false);amdgpu_sync_free (&sync); out_free:kfree(pd_bo_list_entries);drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +0
-0@@ -2939,8 +2939,11 @@ int
amdgpu_amdkfd_gpuvm_restore_process_bos(void *info, struct dma_fence **ef)drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c int amdgpu_mes_ctx_map_meta_data(struct
Quoted 19 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +5
-2}/* Wait for validate and PT updates to finish */ -amdgpu_sync_wait (&sync_obj, false); - + ret =amdgpu_sync_wait (&sync_obj, false); +if (ret) { +pr_err ("Failed to wait for validate and PT updates to finish\n" ); + goto validate_map_fail; + }/* Release old eviction fence and create new one, because fence only * goes from unsignaled to signaled, fence cannot be reused. * Use context and mm from the old fence. drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c +0
-0@@ -1153,7 +1153,11 @@ int amdgpu_mes_ctx_map_meta_data(struct
amdgpu_device*adev,Quoted 12 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c +5
-1}amdgpu_sync_fence (&sync, vm->last_update); -amdgpu_sync_wait (&sync, false); + r =amdgpu_sync_wait (&sync, false); +if (r) { +DRM_ERROR ("failed to wait sync\n" ); + goto error; + }ttm_eu_backoff_reservation (&ticket, &list);amdgpu_sync_free (&sync);
Am 20.10.23 um 08:13 schrieb Emily Deng:
Quoted 19 lines
Issue: Dead heappen during gpu recover, the call sequence as below:
amdgpu_device_gpu_recover->amdgpu_amdkfd_pre_reset->flush_delayed_work->
amdgpu_amdkfd_gpuvm_restore_process_bos->amdgpu_sync_waitIt is because the
amdgpu_sync_waitis waiting for the bad job's fence, and never return, so the recover couldn't continue.Signed-off-by Emily Deng <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c +0
-0
drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c int amdgpu_sync_wait(struct amdgpu_sync *sync, bool intr) · line 410
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c +2
-2@@ -406,8 +406,15 @@ int amdgpu_sync_wait(struct amdgpu_sync *sync, bool intr)int i, r;hash_for_each_safe (sync->fences, i, tmp, e, node) { - r =dma_fence_wait (e->fence, intr); -if (r) +struct drm_sched_fence *s_fence =to_drm_sched_fence (e->fence); +long timeout =msecs_to_jiffies (10000 );
That handling doesn't make much sense. If you need a timeout then you need a timeout for the whole function.
Additional to that timeouts often just hide real problems which needs fixing.
So this here needs a much better justification otherwise it's a pretty clear NAK.
Regards,
Christian.
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c +7
-0+ +if (s_fence) + timeout = s_fence->sched->timeout; + +if (r ==0 ) + r = -ETIMEDOUT ; +if (r <0 )return r;amdgpu_sync_entry_free (e);
[AMD Official Use Only - General]
Hi Christian,
The issue is running a compute hang with a quark and trigger a compute job timeout. For compute, the timeout setting is 60s, but for gfx and sdma, it is 10s.
So, get the timeout from the sched is reasonable for different sched.
And if wait timeout, it will print error, so won't hint real issues. And even it has real issue, the wait forever is bad user experience, and driver couldn't work anymore.
Emily Deng
Best Wishes
Quoted 58 lines
-----Original Message-----
From: Christian König <[email protected]>
Sent: Friday, October 20, 2023 3:29 PM
To: Deng, Emily <[email protected]>; [email protected]
Subject: Re: [PATCH 1/2] drm/amdgpu: Add timeout for sync waitAm 20.10.23 um 08:13 schrieb Emily Deng:
drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c int amdgpu_sync_wait(struct amdgpu_sync *sync,
Quoted 21 lines
Issue: Dead heappen during gpu recover, the call sequence as below:
amdgpu_device_gpu_recover->amdgpu_amdkfd_pre_reset-
flush_delayed_work
->amdgpu_amdkfd_gpuvm_restore_process_bos->amdgpu_sync_waitIt is because the
amdgpu_sync_waitis waiting for the bad job's fence, and never return, so the recover couldn't continue.Signed-off-by Emily Deng <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c +0
-0@@ -406,8 +406,15 @@ int amdgpu_sync_wait(struct amdgpu_sync *sync,bool intr)
drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c int amdgpu_sync_wait(struct amdgpu_sync *sync, bool intr) · line 410
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c +2
-2int i, r;hash_for_each_safe (sync->fences, i, tmp, e, node) { - r =dma_fence_wait (e->fence, intr); -if (r) +struct drm_sched_fence *s_fence =to_drm_sched_fence (e- fence); +long timeout =msecs_to_jiffies (10000 );That handling doesn't make much sense. If you need a timeout then you need a timeout for the whole function.
Additional to that timeouts often just hide real problems which needs fixing.
So this here needs a much better justification otherwise it's a pretty clear NAK.
Regards,
Christian.Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c +7
-0+ +if (s_fence) + timeout = s_fence->sched->timeout; + +if (r ==0 ) + r = -ETIMEDOUT ; +if (r <0 )return r;amdgpu_sync_entry_free(e);
No, the wait forever is what is expected and perfectly valid user experience.
Waiting with a timeout on the other hand sounds like a really bad idea to me.
Every wait with a timeout needs a justification, e.g. for example that userspace explicitly specified it. And I absolutely don't see that here.
Regards,
Christian.
Am 20.10.23 um 10:52 schrieb Deng, Emily:
Quoted 69 lines
[AMD Official Use Only - General]
Hi Christian,
The issue is running a compute hang with a quark and trigger a compute job timeout. For compute, the timeout setting is 60s, but for gfx and sdma, it is 10s.
So, get the timeout from the sched is reasonable for different sched.
And if wait timeout, it will print error, so won't hint real issues. And even it has real issue, the wait forever is bad user experience, and driver couldn't work anymore.Emily Deng
Best WishesQuoted 57 lines
-----Original Message-----
From: Christian König <[email protected]>
Sent: Friday, October 20, 2023 3:29 PM
To: Deng, Emily <[email protected]>; [email protected]
Subject: Re: [PATCH 1/2] drm/amdgpu: Add timeout for sync waitAm 20.10.23 um 08:13 schrieb Emily Deng:
drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c int amdgpu_sync_wait(struct amdgpu_sync *sync,
Quoted 21 lines
Issue: Dead heappen during gpu recover, the call sequence as below:
amdgpu_device_gpu_recover->amdgpu_amdkfd_pre_reset-
flush_delayed_work
->amdgpu_amdkfd_gpuvm_restore_process_bos->amdgpu_sync_waitIt is because the
amdgpu_sync_waitis waiting for the bad job's fence, and never return, so the recover couldn't continue.Signed-off-by Emily Deng <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c +0
-0@@ -406,8 +406,15 @@ int amdgpu_sync_wait(struct amdgpu_sync *sync,bool intr)
drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c int amdgpu_sync_wait(struct amdgpu_sync *sync, bool intr) · line 410
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c +2
-2int i, r;hash_for_each_safe (sync->fences, i, tmp, e, node) { - r =dma_fence_wait (e->fence, intr); -if (r) +struct drm_sched_fence *s_fence =to_drm_sched_fence (e- fence); +long timeout =msecs_to_jiffies (10000 );That handling doesn't make much sense. If you need a timeout then you need a timeout for the whole function.
Additional to that timeouts often just hide real problems which needs fixing.
So this here needs a much better justification otherwise it's a pretty clear NAK.
Regards,
Christian.Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c +7
-0+ +if (s_fence) + timeout = s_fence->sched->timeout; + +if (r ==0 ) + r = -ETIMEDOUT ; +if (r <0 )return r;amdgpu_sync_entry_free(e);
Felix Kuehling
maintainerQuoted 5 lines · Christian König
No, the wait forever is what is expected and perfectly valid user experience.
Waiting with a timeout on the other hand sounds like a really bad idea to me.
Every wait with a timeout needs a justification, e.g. for example that userspace explicitly specified it. And I absolutely don't see that here.
In this case the wait is in a kernel worker thread, and the wait is not interruptible. Not having a timeout means, you can have a kernel worker stuck forever. The restore worker also has retry logic already, so it can handle a timeout perfectly well. But maybe this shouldn't be done automatically for all callers of amdgpu_sync_wait, but only for this particular caller in the restore_process_worker. So we'd need to add a timeout parameter to amdgpu_sync_wait.
Regards,
Felix
Quoted 75 lines
Regards,
Christian.Am 20.10.23 um 10:52 schrieb Deng, Emily:
Quoted 69 lines
[AMD Official Use Only - General]
Hi Christian,
The issue is running a compute hang with a quark and trigger a compute job timeout. For compute, the timeout setting is 60s, but for gfx and sdma, it is 10s. So, get the timeout from the sched is reasonable for different sched.
And if wait timeout, it will print error, so won't hint real issues. And even it has real issue, the wait forever is bad user experience, and driver couldn't work anymore.Emily Deng
Best WishesQuoted 57 lines
-----Original Message-----
From: Christian König <[email protected]>
Sent: Friday, October 20, 2023 3:29 PM
To: Deng, Emily <[email protected]>; [email protected]
Subject: Re: [PATCH 1/2] drm/amdgpu: Add timeout for sync waitAm 20.10.23 um 08:13 schrieb Emily Deng:
drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c int amdgpu_sync_wait(struct amdgpu_sync *sync,
Quoted 21 lines
Issue: Dead heappen during gpu recover, the call sequence as below:
amdgpu_device_gpu_recover->amdgpu_amdkfd_pre_reset-
flush_delayed_work
->amdgpu_amdkfd_gpuvm_restore_process_bos->amdgpu_sync_waitIt is because the
amdgpu_sync_waitis waiting for the bad job's fence, and never return, so the recover couldn't continue.Signed-off-by Emily Deng <[email protected]>---
drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c| 11 +++++++++--1 file changed, 9 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c +0
-0@@ -406,8 +406,15 @@ int amdgpu_sync_wait(struct amdgpu_sync *sync,bool intr)
drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c int amdgpu_sync_wait(struct amdgpu_sync *sync, bool intr) · line 410
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c +2
-2int i, r; hash_for_each_safe(sync->fences, i, tmp, e, node) { - r = dma_fence_wait(e->fence, intr); - if (r) + struct drm_sched_fence *s_fence = to_drm_sched_fence(e- fence); + long timeout = msecs_to_jiffies(10000);That handling doesn't make much sense. If you need a timeout then you need a timeout for the whole function.
Additional to that timeouts often just hide real problems which needs fixing.
So this here needs a much better justification otherwise it's a pretty clear NAK.
Regards,
Christian.Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c +7
-0+ + if (s_fence) + timeout = s_fence->sched->timeout; + + if (r == 0) + r = -ETIMEDOUT; + if (r < 0) return r;
amdgpu_sync_entry_free(e);
Am 20.10.23 um 21:47 schrieb Felix Kuehling:
Quoted 8 lines · Christian König
Quoted 5 lines
No, the wait forever is what is expected and perfectly valid user experience.
Waiting with a timeout on the other hand sounds like a really bad idea to me.
Every wait with a timeout needs a justification, e.g. for example that userspace explicitly specified it. And I absolutely don't see that here.
In this case the wait is in a kernel worker thread, and the wait is not interruptible. Not having a timeout means, you can have a kernel worker stuck forever. The restore worker also has retry logic already, so it can handle a timeout perfectly well. But maybe this shouldn't be done automatically for all callers of
amdgpu_sync_wait, but only for this particular caller in therestore_process_worker. So we'd need to add a timeout parameter toamdgpu_sync_wait.
Adding a parameter sounds like a good idea to me, but it's mandatory that dma_fence operations finish in a reasonable amount of time in the first place.
This is even documented by now and basically means we need timeouts in the area of 100ms for each operation and not between 10 and 60 seconds.
If upstream starts to taint the kernel for longer timeouts we will need to reduce the current values massively.
Regards,
Christian.
Quoted 80 lines
Regards,
FelixQuoted 75 lines
Regards,
Christian.Am 20.10.23 um 10:52 schrieb Deng, Emily:
Quoted 69 lines
[AMD Official Use Only - General]
Hi Christian,
The issue is running a compute hang with a quark and trigger a compute job timeout. For compute, the timeout setting is 60s, but for gfx and sdma, it is 10s. So, get the timeout from the sched is reasonable for different sched.
And if wait timeout, it will print error, so won't hint real issues. And even it has real issue, the wait forever is bad user experience, and driver couldn't work anymore.Emily Deng
Best WishesQuoted 57 lines
-----Original Message-----
From: Christian König <[email protected]>
Sent: Friday, October 20, 2023 3:29 PM
To: Deng, Emily <[email protected]>; [email protected]
Subject: Re: [PATCH 1/2] drm/amdgpu: Add timeout for sync waitAm 20.10.23 um 08:13 schrieb Emily Deng:
drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c int amdgpu_sync_wait(struct amdgpu_sync *sync,
Quoted 21 lines
Issue: Dead heappen during gpu recover, the call sequence as below:
amdgpu_device_gpu_recover->amdgpu_amdkfd_pre_reset-
flush_delayed_work
->amdgpu_amdkfd_gpuvm_restore_process_bos->amdgpu_sync_waitIt is because the
amdgpu_sync_waitis waiting for the bad job's fence, and never return, so the recover couldn't continue.Signed-off-by Emily Deng <[email protected]>---
drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c| 11 +++++++++--1 file changed, 9 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c +0
-0@@ -406,8 +406,15 @@ int amdgpu_sync_wait(struct amdgpu_sync *sync,bool intr)
drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c int amdgpu_sync_wait(struct amdgpu_sync *sync, bool intr) · line 410
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c +2
-2int i, r; hash_for_each_safe(sync->fences, i, tmp, e, node) { - r = dma_fence_wait(e->fence, intr); - if (r) + struct drm_sched_fence *s_fence = to_drm_sched_fence(e- fence); + long timeout = msecs_to_jiffies(10000);That handling doesn't make much sense. If you need a timeout then you need a timeout for the whole function.
Additional to that timeouts often just hide real problems which needs fixing.
So this here needs a much better justification otherwise it's a pretty clear NAK.
Regards,
Christian.Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c +7
-0+ + if (s_fence) + timeout = s_fence->sched->timeout; + + if (r == 0) + r = -ETIMEDOUT; + if (r < 0) return r;
amdgpu_sync_entry_free(e);