Bunch of patches for fence timeout cleanup
Subsystems (2)
v5 cover Bunch of patches for 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.
v5: use dma_fence_wait and dont check for errors.
split patch 1 into two to better suit the purpose of each patch.
Sunil Khatri (5):
drm/amdgpu/userq: fence wait for max time in
amdgpu_userq_wait_for_signal
drm/amdgpu/userq: dont need check for return values 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 | 71 ++++++----------------- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 8 +-- 3 files changed, 22 insertions(+), 59 deletions(-)
Signature · 1 line
2.34.1
PATCH v5 1/5 drm/amdgpu/userq: fence wait for max time in amdgpu_userq_wait_for_signal
wait for infinite time for fences in function amdgpu_userq_wait_for_signal and for that use dma_fence_wait(f, false);
--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +3 -12
@@ -1279,29 +1279,20 @@ void amdgpu_userq_reset_work(struct work_struct *work)amdgpu_device_gpu_recover (adev,NULL , &reset_context); } -static int +static void amdgpu_userq_wait_for_signal (struct amdgpu_userq_mgr *uq_mgr) {struct amdgpu_usermode_queue *queue;unsigned long queue_id; -int ret;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 )); -if (ret <=0 ) { -drm_file_err (uq_mgr->file,"Timed out waiting for fence=%llu:%llu\n" , - f->context, f->seqno); - -return -ETIMEDOUT ; - } +dma_fence_wait (f, false); } - -return 0 ; }void
Signature · 1 line
2.34.1
Christian König
maintainerRe: [Patch v5 1/5] drm/amdgpu/userq: fence wait for max time in amdgpu_userq_wait_for_signal
Quoted 5 lines · Sunil Khatri
wait for infinite time for fences in function
amdgpu_userq_wait_for_signaland for that usedma_fence_wait(f, false);Suggested-by Christian König <[email protected]>Signed-off-by Sunil Khatri <[email protected]>
Assuming that compile fine even as stand alone patch: Reviewed-by: Christian König <[email protected]>
Quoted 41 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +3
-12@@ -1279,29 +1279,20 @@ void amdgpu_userq_reset_work(struct work_struct *work)amdgpu_device_gpu_recover (adev,NULL , &reset_context); } -static int +static void amdgpu_userq_wait_for_signal (struct amdgpu_userq_mgr *uq_mgr) {struct amdgpu_usermode_queue *queue;unsigned long queue_id; -int ret;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 )); -if (ret <=0 ) { -drm_file_err (uq_mgr->file,"Timed out waiting for fence=%llu:%llu\n" , - f->context, f->seqno); - -return -ETIMEDOUT ; - } +dma_fence_wait (f, false); } - -return 0 ; }void
PATCH v5 2/5 drm/amdgpu/userq: dont need check for return values in amdgpu_userq_evict
In reply to Sunil KhatriFunction of amdgpu_userq_evict function do not need to check for return values as we dont use them and no need to log errors as we are already logging in called functions.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +4 -12
@@ -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; }
@@ -1298,18 +1299,9 @@ 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); +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 v5 2/5] drm/amdgpu/userq: dont need check for return values in amdgpu_userq_evict
Quoted 24 lines · Sunil Khatri
Function of
amdgpu_userq_evictfunction do not need to check for return values as we dont use them and no need to log errors as we are already logging in called functions.Signed-off-by Sunil Khatri <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +2
-1@@ -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; }
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c amdgpu_userq_wait_for_signal(struct amdgpu_userq_mgr *uq_mgr) · line 1305
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +0
-4@@ -1298,18 +1299,9 @@ 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);
That confirms my suspicion that patch #1 would cause build failures when applied alone.
Please re-order the patch before pushing them so that this one here comes first.
With that done Reviewed-by: Christian König <[email protected]>
Regards,
Christian.
Quoted 12 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +2
-7-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); +amdgpu_userq_evict_all (uq_mgr); } int amdgpu_userq_mgr_init(struct amdgpu_userq_mgr *userq_mgr, struct drm_file *file_priv,
Re: [Patch v5 2/5] drm/amdgpu/userq: dont need check for return values in amdgpu_userq_evict
Quoted 36 lines · Christian König
Quoted 24 lines · Sunil Khatri
Function of
amdgpu_userq_evictfunction do not need to check for return values as we dont use them and no need to log errors as we are already logging in called functions.Signed-off-by Sunil Khatri <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +2
-1@@ -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; }drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c amdgpu_userq_wait_for_signal(struct amdgpu_userq_mgr *uq_mgr) · line 1305
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +0
-4@@ -1298,18 +1299,9 @@ 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);That confirms my suspicion that patch #1 would cause build failures when applied alone.
Quoted 1 line
Please re-order the patch before pushing them so that this one here comes first.
Sure Christian.
Thanks Sunil
Quoted 18 lines
With that done Reviewed-by: Christian König <[email protected]>
Regards,
Christian.Quoted 12 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +2
-7-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); +amdgpu_userq_evict_all (uq_mgr); } int amdgpu_userq_mgr_init(struct amdgpu_userq_mgr *userq_mgr, struct drm_file *file_priv,
PATCH v5 3/5 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 v5 4/5 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. Also since we are waiting forever we should not be having any return value and hence no handling needed.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 15 ++++----------- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 8 ++------ 3 files changed, 7 insertions(+), 18 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +4 -11
@@ -1462,17 +1462,16 @@ int amdgpu_userq_start_sched_for_enforce_isolation(struct amdgpu_device *adev,return ret; } -int amdgpu_userq_gem_va_unmap_validate (struct amdgpu_device *adev, +void amdgpu_userq_gem_va_unmap_validate (struct amdgpu_device *adev,struct amdgpu_bo_va_mapping *mapping,uint64_t saddr) {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 ; +return ;dev_warn_once (adev->dev,"now unmapping a vital queue va:%llx\n" , saddr);/**
@@ -1483,14 +1482,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 ; +dma_resv_wait_timeout (resv,DMA_RESV_USAGE_BOOKKEEP , + false,MAX_SCHEDULE_TIMEOUT ); }void amdgpu_userq_pre_reset (struct amdgpu_device *adev)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h +1 -1
@@ -160,7 +160,7 @@ void amdgpu_userq_start_hang_detect_work(struct amdgpu_usermode_queue *queue);int amdgpu_userq_input_va_validate (struct amdgpu_device *adev,struct amdgpu_usermode_queue *queue,u64 addr,u64 expected_size); -int amdgpu_userq_gem_va_unmap_validate (struct amdgpu_device *adev, +void amdgpu_userq_gem_va_unmap_validate (struct amdgpu_device *adev,struct amdgpu_bo_va_mapping *mapping,uint64_t saddr);#endif
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2 -6
@@ -2003,12 +2003,8 @@ int amdgpu_vm_bo_unmap(struct amdgpu_device *adev,* during user requests GEM unmap IOCTL except for forcing the unmap * from user space. */ -if (unlikely (atomic_read (&bo_va->userq_va_mapped) >0 )) { - r =amdgpu_userq_gem_va_unmap_validate (adev, mapping, saddr); -if (unlikely (r == -EBUSY )) -dev_warn_once (adev->dev, -"Attempt to unmap an active userq buffer\n" ); - } +if (unlikely (atomic_read (&bo_va->userq_va_mapped) >0 )) +amdgpu_userq_gem_va_unmap_validate (adev, mapping, saddr);list_del (&mapping->list);amdgpu_vm_it_remove (mapping, &vm->va);
Signature · 1 line
2.34.1
Re: [Patch v5 4/5] drm/amdgpu/userq: call dma_resv_wait_timeout without test for signalled
Quoted 7 lines · Sunil Khatri
In function
amdgpu_userq_gem_va_unmap_validatecalldma_resv_wait_timeoutdirectly. Also since we are waiting forever we should not be having any return value and hence no handling needed.Suggested-by Christian König <[email protected]>Signed-off-by Sunil Khatri <[email protected]>
Quoted 79 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 15 ++++----------- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 8 ++------ 3 files changed, 7 insertions(+), 18 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +4
-11@@ -1462,17 +1462,16 @@ int amdgpu_userq_start_sched_for_enforce_isolation(struct amdgpu_device *adev,return ret; } -int amdgpu_userq_gem_va_unmap_validate (struct amdgpu_device *adev, +void amdgpu_userq_gem_va_unmap_validate (struct amdgpu_device *adev,struct amdgpu_bo_va_mapping *mapping,uint64_t saddr) {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 ; +return ;dev_warn_once (adev->dev,"now unmapping a vital queue va:%llx\n" , saddr);/** @@ -1483,14 +1482,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 ; +dma_resv_wait_timeout (resv,DMA_RESV_USAGE_BOOKKEEP , + false,MAX_SCHEDULE_TIMEOUT ); }void amdgpu_userq_pre_reset (struct amdgpu_device *adev)drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h +1
-1@@ -160,7 +160,7 @@ void amdgpu_userq_start_hang_detect_work(struct amdgpu_usermode_queue *queue);int amdgpu_userq_input_va_validate (struct amdgpu_device *adev,struct amdgpu_usermode_queue *queue,u64 addr,u64 expected_size); -int amdgpu_userq_gem_va_unmap_validate (struct amdgpu_device *adev, +void amdgpu_userq_gem_va_unmap_validate (struct amdgpu_device *adev,struct amdgpu_bo_va_mapping *mapping,uint64_t saddr);#endif drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2
-6@@ -2003,12 +2003,8 @@ int amdgpu_vm_bo_unmap(struct amdgpu_device *adev,* during user requests GEM unmap IOCTL except for forcing the unmap * from user space. */ -if (unlikely (atomic_read (&bo_va->userq_va_mapped) >0 )) { - r =amdgpu_userq_gem_va_unmap_validate (adev, mapping, saddr); -if (unlikely (r == -EBUSY )) -dev_warn_once (adev->dev, -"Attempt to unmap an active userq buffer\n" ); - } +if (unlikely (atomic_read (&bo_va->userq_va_mapped) >0 )) +amdgpu_userq_gem_va_unmap_validate (adev, mapping, saddr);list_del (&mapping->list);amdgpu_vm_it_remove (mapping, &vm->va);
PATCH v5 5/5 drm/amdgpu/userq: use dma_fence_wait_timeout without test for signalled
In reply to Sunil KhatriIn function amdgpu_userq_wait_for_last_fence usedma_fence_wait to wait infinitely.
Also there is no need to print error as we wont be timing out anymore.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +4 -12
@@ -427,23 +427,15 @@ static int amdgpu_userq_map_helper(struct amdgpu_usermode_queue *queue)return r; } -static int amdgpu_userq_wait_for_last_fence (struct amdgpu_usermode_queue *queue) +static void amdgpu_userq_wait_for_last_fence (struct amdgpu_usermode_queue *queue) {struct amdgpu_userq_mgr *uq_mgr = queue->userq_mgr;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 ; -return ret; +dma_fence_wait (f, false); }static void amdgpu_userq_cleanup (struct amdgpu_usermode_queue *queue)
Signature · 1 line
2.34.1
Re: [Patch v5 5/5] drm/amdgpu/userq: use dma_fence_wait_timeout without test for signalled
Quoted 7 lines · Sunil Khatri
In function
amdgpu_userq_wait_for_last_fenceusedma_fence_waitto wait infinitely.Also there is no need to print error as we wont be timing out anymore.
Signed-off-by Sunil Khatri <[email protected]>
Quoted 36 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +4
-12@@ -427,23 +427,15 @@ static int amdgpu_userq_map_helper(struct amdgpu_usermode_queue *queue)return r; } -static int amdgpu_userq_wait_for_last_fence (struct amdgpu_usermode_queue *queue) +static void amdgpu_userq_wait_for_last_fence (struct amdgpu_usermode_queue *queue) {struct amdgpu_userq_mgr *uq_mgr = queue->userq_mgr;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 ; -return ret; +dma_fence_wait (f, false); }static void amdgpu_userq_cleanup (struct amdgpu_usermode_queue *queue)