Bunch of patches to fix fence timeout cleanup
Subsystems (2)
v4 cover Bunch of patches to fix fence timeout cleanup
v2: add more fixes as suggested by christian and update some logging.
v3: patch no 4 in amdgpu_userq_wait_for_last_fence to remove signalled check.
v4: update dma_fence_wait_timeout to dma_fence_wait since its infinite wait.
Sunil Khatri (4):
drm/amdgpu/userq: dont check return value in amdgpu_userq_evict drm/amdgpu/userq: add the return code too in error condition drm/amdgpu/userq: call dma_resv_wait_timeout without test for
signalled
drm/amdgpu/userq: use dma_fence_wait_timeout without test for
signalled
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 63 +++++++++-------------- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 4 +- 2 files changed, 27 insertions(+), 40 deletions(-)
Signature · 1 line
2.34.1
PATCH v4 1/4 drm/amdgpu/userq: dont check return value in amdgpu_userq_evict
In function amdgpu_userq_evict we do not need to check for return values and print errors as we are already print error in all the functions of amdgpu_userq_evict.
a. amdgpu_userq_wait_for_signal: Could timeout and we print
error message in the function already
b. amdgpu_userq_evict_all: We unmap all the queues here and
in case of unmap failure we already print unmap error.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 26 +++++++++-------------- 1 file changed, 10 insertions(+), 16 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +10 -16
@@ -1258,7 +1258,8 @@ amdgpu_userq_evict_all(struct amdgpu_userq_mgr *uq_mgr) }if (ret) -drm_file_err (uq_mgr->file,"Couldn't unmap all the queues\n" ); +drm_file_err (uq_mgr->file, +"Couldn't unmap all the queues, eviction failed ret=%d\n" , ret);return ret; }
@@ -1289,13 +1290,14 @@ amdgpu_userq_wait_for_signal(struct amdgpu_userq_mgr *uq_mgr)xa_for_each (&uq_mgr->userq_xa, queue_id, queue) {struct dma_fence *f = queue->last_fence; -if (!f ||dma_fence_is_signaled (f)) +if (!f)continue ; - ret =dma_fence_wait_timeout (f, true,msecs_to_jiffies (100 )); + ret =dma_fence_wait (f, false);if (ret <=0 ) { -drm_file_err (uq_mgr->file,"Timed out waiting for fence=%llu:%llu\n" , - f->context, f->seqno); +drm_file_err (uq_mgr->file, +"Timed out in wait_for_signal fence=%llu:%llu ret=%d\n" , + f->context, f->seqno, ret);return -ETIMEDOUT ; }
@@ -1307,18 +1309,10 @@ amdgpu_userq_wait_for_signal(struct amdgpu_userq_mgr *uq_mgr)void amdgpu_userq_evict (struct amdgpu_userq_mgr *uq_mgr) { -struct amdgpu_device *adev = uq_mgr->adev; -int ret; -/* Wait for any pending userqueue fence work to finish */ - ret =amdgpu_userq_wait_for_signal (uq_mgr); -if (ret) -dev_err (adev->dev,"Not evicting userqueue, timeout waiting for work\n" ); - - ret =amdgpu_userq_evict_all (uq_mgr); -if (ret) -dev_err (adev->dev,"Failed to evict userqueue\n" ); - +amdgpu_userq_wait_for_signal (uq_mgr); +/* unmaps all the queues */ +amdgpu_userq_evict_all (uq_mgr); } int amdgpu_userq_mgr_init(struct amdgpu_userq_mgr *userq_mgr, struct drm_file *file_priv,
Signature · 1 line
2.34.1
Christian König
maintainerRe: [Patch v4 1/4] drm/amdgpu/userq: dont check return value in amdgpu_userq_evict
Quoted 48 lines · Sunil Khatri
In function
amdgpu_userq_evictwe do not need to check for return values and print errors as we are already print error in all the functions ofamdgpu_userq_evict.a.
amdgpu_userq_wait_for_signal: Could timeout and we print
error message in the function already
b.amdgpu_userq_evict_all: We unmap all the queues here and
in case of unmap failure we already print unmap error.Suggested-by Christian König <[email protected]>Signed-off-by Sunil Khatri <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 26 +++++++++-------------- 1 file changed, 10 insertions(+), 16 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +7
-5@@ -1258,7 +1258,8 @@ amdgpu_userq_evict_all(struct amdgpu_userq_mgr *uq_mgr) }if (ret) -drm_file_err (uq_mgr->file,"Couldn't unmap all the queues\n" ); +drm_file_err (uq_mgr->file, +"Couldn't unmap all the queues, eviction failed ret=%d\n" , ret);return ret; }@@ -1289,13 +1290,14 @@ amdgpu_userq_wait_for_signal(struct amdgpu_userq_mgr *uq_mgr)xa_for_each (&uq_mgr->userq_xa, queue_id, queue) {struct dma_fence *f = queue->last_fence; -if (!f ||dma_fence_is_signaled (f)) +if (!f)continue ; - ret =dma_fence_wait_timeout (f, true,msecs_to_jiffies (100 )); + ret =dma_fence_wait (f, false);if (ret <=0 ) { -drm_file_err (uq_mgr->file,"Timed out waiting for fence=%llu:%llu\n" , - f->context, f->seqno); +drm_file_err (uq_mgr->file, +"Timed out in wait_for_signal fence=%llu:%llu ret=%d\n" , + f->context, f->seqno, ret);return -ETIMEDOUT ;
Quoted 1 line
}
You can completely drop this. dma_fence_wait() will never return any error when used like this.
Apart from that the patch looks correct to me.
Regards,
Christian.
Quoted 22 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +3
-11@@ -1307,18 +1309,10 @@ amdgpu_userq_wait_for_signal(struct amdgpu_userq_mgr *uq_mgr)void amdgpu_userq_evict (struct amdgpu_userq_mgr *uq_mgr) { -struct amdgpu_device *adev = uq_mgr->adev; -int ret; -/* Wait for any pending userqueue fence work to finish */ - ret =amdgpu_userq_wait_for_signal (uq_mgr); -if (ret) -dev_err (adev->dev,"Not evicting userqueue, timeout waiting for work\n" ); - - ret =amdgpu_userq_evict_all (uq_mgr); -if (ret) -dev_err (adev->dev,"Failed to evict userqueue\n" ); - +amdgpu_userq_wait_for_signal (uq_mgr); +/* unmaps all the queues */ +amdgpu_userq_evict_all (uq_mgr); } int amdgpu_userq_mgr_init(struct amdgpu_userq_mgr *userq_mgr, struct drm_file *file_priv,
Re: [Patch v4 1/4] drm/amdgpu/userq: dont check return value in amdgpu_userq_evict
Quoted 48 lines · Christian König
Quoted 46 lines · Sunil Khatri
In function
amdgpu_userq_evictwe do not need to check for return values and print errors as we are already print error in all the functions ofamdgpu_userq_evict.a.
amdgpu_userq_wait_for_signal: Could timeout and we print
error message in the function already
b.amdgpu_userq_evict_all: We unmap all the queues here and
in case of unmap failure we already print unmap error.Suggested-by Christian König <[email protected]>Signed-off-by Sunil Khatri <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 26 +++++++++-------------- 1 file changed, 10 insertions(+), 16 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +7
-5@@ -1258,7 +1258,8 @@ amdgpu_userq_evict_all(struct amdgpu_userq_mgr *uq_mgr) }if (ret) -drm_file_err (uq_mgr->file,"Couldn't unmap all the queues\n" ); +drm_file_err (uq_mgr->file, +"Couldn't unmap all the queues, eviction failed ret=%d\n" , ret);return ret; }@@ -1289,13 +1290,14 @@ amdgpu_userq_wait_for_signal(struct amdgpu_userq_mgr *uq_mgr)xa_for_each (&uq_mgr->userq_xa, queue_id, queue) {struct dma_fence *f = queue->last_fence; -if (!f ||dma_fence_is_signaled (f)) +if (!f)continue ; - ret =dma_fence_wait_timeout (f, true,msecs_to_jiffies (100 )); + ret =dma_fence_wait (f, false);if (ret <=0 ) { -drm_file_err (uq_mgr->file,"Timed out waiting for fence=%llu:%llu\n" , - f->context, f->seqno); +drm_file_err (uq_mgr->file, +"Timed out in wait_for_signal fence=%llu:%llu ret=%d\n" , + f->context, f->seqno, ret);
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c amdgpu_userq_wait_for_signal(struct amdgpu_userq_mgr *uq_mgr) · line 1303
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +0
-0return -ETIMEDOUT ; }You can completely drop this.
dma_fence_wait()will never return any error when used like this.Apart from that the patch looks correct to me.
Got it
Regards
Sunil
Quoted 27 lines
Regards,
Christian.Quoted 22 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +3
-11@@ -1307,18 +1309,10 @@ amdgpu_userq_wait_for_signal(struct amdgpu_userq_mgr *uq_mgr)void amdgpu_userq_evict (struct amdgpu_userq_mgr *uq_mgr) { -struct amdgpu_device *adev = uq_mgr->adev; -int ret; -/* Wait for any pending userqueue fence work to finish */ - ret =amdgpu_userq_wait_for_signal (uq_mgr); -if (ret) -dev_err (adev->dev,"Not evicting userqueue, timeout waiting for work\n" ); - - ret =amdgpu_userq_evict_all (uq_mgr); -if (ret) -dev_err (adev->dev,"Failed to evict userqueue\n" ); - +amdgpu_userq_wait_for_signal (uq_mgr); +/* unmaps all the queues */ +amdgpu_userq_evict_all (uq_mgr); } int amdgpu_userq_mgr_init(struct amdgpu_userq_mgr *userq_mgr, struct drm_file *file_priv,
PATCH v4 2/4 drm/amdgpu/userq: add the return code too in error condition
In reply to Sunil KhatriIn function amdgpu_userq_restore
a. amdgpu_userq_vm_validate: add return code in error condition b. amdgpu_userq_restore_all: It already prints the error log, just
update the erorr log in the function and remove it from caller.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +4 -5
@@ -1023,7 +1023,8 @@ amdgpu_userq_restore_all(struct amdgpu_userq_mgr *uq_mgr)mutex_unlock (&uq_mgr->userq_mutex);if (ret) -drm_file_err (uq_mgr->file,"Failed to map all the queues\n" ); +drm_file_err (uq_mgr->file, +"Failed to map all the queues, restore failed ret=%d\n" , ret);return ret; }
@@ -1230,13 +1231,11 @@ static void amdgpu_userq_restore_worker(struct work_struct *work) ret =amdgpu_userq_vm_validate (uq_mgr);if (ret) { -drm_file_err (uq_mgr->file,"Failed to validate BOs to restore\n" ); +drm_file_err (uq_mgr->file,"Failed to validate BOs to restore ret=%d\n" , ret); goto put_fence; } - ret =amdgpu_userq_restore_all (uq_mgr); -if (ret) -drm_file_err (uq_mgr->file,"Failed to restore all queues\n" ); +amdgpu_userq_restore_all (uq_mgr); put_fence:dma_fence_put (ev_fence);
Signature · 1 line
2.34.1
PATCH v4 3/4 drm/amdgpu/userq: call dma_resv_wait_timeout without test for signalled
In reply to Sunil KhatriIn function amdgpu_userq_gem_va_unmap_validate call dma_resv_wait_timeout directly.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 11 ++--------- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 4 ++-- 2 files changed, 4 insertions(+), 11 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +2 -9
@@ -1480,7 +1480,6 @@ int amdgpu_userq_gem_va_unmap_validate(struct amdgpu_device *adev,u32 ip_mask =amdgpu_userq_get_supported_ip_mask (adev);struct amdgpu_bo_va *bo_va = mapping->bo_va;struct dma_resv *resv = bo_va->base.bo->tbo.base.resv; -int ret =0 ;if (!ip_mask)return 0 ;
@@ -1494,14 +1493,8 @@ int amdgpu_userq_gem_va_unmap_validate(struct amdgpu_device *adev,* unmap is only for one kind of userq VAs, so at this point suppose * the eviction fence is always unsignaled. */ -if (!dma_resv_test_signaled (resv,DMA_RESV_USAGE_BOOKKEEP )) { - ret =dma_resv_wait_timeout (resv,DMA_RESV_USAGE_BOOKKEEP , true, -MAX_SCHEDULE_TIMEOUT ); -if (ret <=0 ) -return -EBUSY ; - } - -return 0 ; +return dma_resv_wait_timeout (resv,DMA_RESV_USAGE_BOOKKEEP , + true,MAX_SCHEDULE_TIMEOUT ); }void amdgpu_userq_pre_reset (struct amdgpu_device *adev)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2 -2
@@ -2005,9 +2005,9 @@ int amdgpu_vm_bo_unmap(struct amdgpu_device *adev,*/ if (unlikely (atomic_read (&bo_va->userq_va_mapped) >0 )) { r =amdgpu_userq_gem_va_unmap_validate (adev, mapping, saddr); -if (unlikely (r == -EBUSY )) +if (r <=0 && r != -ERESTARTSYS )dev_warn_once (adev->dev, -"Attempt to unmap an active userq buffer\n" ); +"Attempt to unmap an active userq buffer ret=%d\n" , r); }list_del (&mapping->list);
Signature · 1 line
2.34.1
Christian König
maintainerRe: [Patch v4 3/4] drm/amdgpu/userq: call dma_resv_wait_timeout without test for signalled
Quoted 26 lines · Sunil Khatri
In function
amdgpu_userq_gem_va_unmap_validatecalldma_resv_wait_timeoutdirectly.Suggested-by Christian König <[email protected]>Signed-off-by Sunil Khatri <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 11 ++--------- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 4 ++-- 2 files changed, 4 insertions(+), 11 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +0
-1@@ -1480,7 +1480,6 @@ int amdgpu_userq_gem_va_unmap_validate(struct amdgpu_device *adev,u32 ip_mask =amdgpu_userq_get_supported_ip_mask (adev);struct amdgpu_bo_va *bo_va = mapping->bo_va;struct dma_resv *resv = bo_va->base.bo->tbo.base.resv; -int ret =0 ;if (!ip_mask)return 0 ;@@ -1494,14 +1493,8 @@ int amdgpu_userq_gem_va_unmap_validate(struct amdgpu_device *adev,* unmap is only for one kind of userq VAs, so at this point suppose * the eviction fence is always unsignaled. */
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c int amdgpu_userq_gem_va_unmap_validate(struct amdgpu_device *adev, · line 1497
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +2
-8-if (!dma_resv_test_signaled (resv,DMA_RESV_USAGE_BOOKKEEP )) { - ret =dma_resv_wait_timeout (resv,DMA_RESV_USAGE_BOOKKEEP , true, -MAX_SCHEDULE_TIMEOUT ); -if (ret <=0 ) -return -EBUSY ; - } - -return 0 ; +return dma_resv_wait_timeout (resv,DMA_RESV_USAGE_BOOKKEEP , + true,MAX_SCHEDULE_TIMEOUT );
That wait can never fail and so never return an error.
Just return 0 here or even better drop the return value.
Regards,
Christian.
Quoted 19 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +0
-0}void amdgpu_userq_pre_reset (struct amdgpu_device *adev)drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2
-2@@ -2005,9 +2005,9 @@ int amdgpu_vm_bo_unmap(struct amdgpu_device *adev,*/ if (unlikely (atomic_read (&bo_va->userq_va_mapped) >0 )) { r =amdgpu_userq_gem_va_unmap_validate (adev, mapping, saddr); -if (unlikely (r == -EBUSY )) +if (r <=0 && r != -ERESTARTSYS )dev_warn_once (adev->dev, -"Attempt to unmap an active userq buffer\n" ); +"Attempt to unmap an active userq buffer ret=%d\n" , r); }list_del (&mapping->list);
Re: [Patch v4 3/4] drm/amdgpu/userq: call dma_resv_wait_timeout without test for signalled
Quoted 39 lines · Christian König
Quoted 26 lines · Sunil Khatri
In function
amdgpu_userq_gem_va_unmap_validatecalldma_resv_wait_timeoutdirectly.Suggested-by Christian König<[email protected]>Signed-off-by Sunil Khatri<[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 11 ++--------- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 4 ++-- 2 files changed, 4 insertions(+), 11 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +0
-1@@ -1480,7 +1480,6 @@ int amdgpu_userq_gem_va_unmap_validate(struct amdgpu_device *adev,u32 ip_mask =amdgpu_userq_get_supported_ip_mask (adev);struct amdgpu_bo_va *bo_va = mapping->bo_va;struct dma_resv *resv = bo_va->base.bo->tbo.base.resv; -int ret =0 ;if (!ip_mask)return 0 ;@@ -1494,14 +1493,8 @@ int amdgpu_userq_gem_va_unmap_validate(struct amdgpu_device *adev,* unmap is only for one kind of userq VAs, so at this point suppose * the eviction fence is always unsignaled. */ drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c int amdgpu_userq_gem_va_unmap_validate(struct amdgpu_device *adev, · line 1497
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +2
-8-if (!dma_resv_test_signaled (resv,DMA_RESV_USAGE_BOOKKEEP )) { - ret =dma_resv_wait_timeout (resv,DMA_RESV_USAGE_BOOKKEEP , true, -MAX_SCHEDULE_TIMEOUT ); -if (ret <=0 ) -return -EBUSY ; - } - -return 0 ; +return dma_resv_wait_timeout (resv,DMA_RESV_USAGE_BOOKKEEP , + true,MAX_SCHEDULE_TIMEOUT );That wait can never fail and so never return an error.
Quoted 1 line
Just return 0 here or even better drop the return value.
Do we want to return and check in caller for -ERESTARTSYS ?
Regards
Sunil Khatri
Quoted 23 lines
Regards,
Christian.Quoted 19 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +0
-0}void amdgpu_userq_pre_reset (struct amdgpu_device *adev)drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2
-2@@ -2005,9 +2005,9 @@ int amdgpu_vm_bo_unmap(struct amdgpu_device *adev,*/ if (unlikely (atomic_read (&bo_va->userq_va_mapped) >0 )) { r =amdgpu_userq_gem_va_unmap_validate (adev, mapping, saddr); -if (unlikely (r == -EBUSY )) +if (r <=0 && r != -ERESTARTSYS )dev_warn_once (adev->dev, -"Attempt to unmap an active userq buffer\n" ); +"Attempt to unmap an active userq buffer ret=%d\n" , r); }list_del (&mapping->list);
PATCH v4 4/4 drm/amdgpu/userq: use dma_fence_wait_timeout without test for signalled
In reply to Sunil KhatriIn function amdgpu_userq_wait_for_last_fence use dma_fence_wait_timeout directly instead of checking for signalled fence first.
Return dma_fence_wait_timeout return value. Also update the fence timeout log to differentiate where fence timedout.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +10 -8
@@ -433,14 +433,16 @@ static int amdgpu_userq_wait_for_last_fence(struct amdgpu_usermode_queue *queue)struct dma_fence *f = queue->last_fence;int ret =0 ; -if (f && !dma_fence_is_signaled (f)) { - ret =dma_fence_wait_timeout (f, true,MAX_SCHEDULE_TIMEOUT ); -if (ret <=0 ) { -drm_file_err (uq_mgr->file,"Timed out waiting for fence=%llu:%llu\n" , - f->context, f->seqno); - queue->state =AMDGPU_USERQ_STATE_HUNG ; -return -ETIME ; - } +if (!f) +return 0 ; + + ret =dma_fence_wait (f, true); +if (ret <=0 ) { +drm_file_err (uq_mgr->file, +"Timed out in wait_for_last_fence fence=%llu:%llu\n" , + f->context, f->seqno); + queue->state =AMDGPU_USERQ_STATE_HUNG ; +return -ETIMEDOUT ; }return ret;
Signature · 1 line
2.34.1