Bunch of patches to do trivial clean up and
Subsystems (2)
v2 cover Bunch of patches to do trivial clean up and
v2: add more fixes as suggested by christian and update some logging.
Sunil Khatri (4):
drm/amdgpu/userq: no need to use local variable ret drm/amdgpu/userq: no need to use local variable here for return drm/amdgpu/userq: no need to use local variable here for return drm/amdgpu/userq: Fix the code alignment for readability
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 31 +++++++++-------------- 1 file changed, 12 insertions(+), 19 deletions(-)
Signature · 1 line
2.34.1
PATCH v2 1/3 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 | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +6 -12
@@ -1258,7 +1258,7 @@ 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 queue, eviction failed\n" );return ret; }
@@ -1289,10 +1289,10 @@ 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_timeout (f, false,MAX_SCHEDULE_TIMEOUT );if (ret <=0 ) {drm_file_err (uq_mgr->file,"Timed out waiting for fence=%llu:%llu\n" , f->context, f->seqno);
@@ -1308,17 +1308,11 @@ 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 v2 1/3] drm/amdgpu/userq: dont check return value in amdgpu_userq_evict
Quoted 20 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 | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +0
-0
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c amdgpu_userq_evict_all(struct amdgpu_userq_mgr *uq_mgr) · line 1261
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +1
-1@@ -1258,7 +1258,7 @@ 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 queue, eviction failed\n" );
I think it would be good to include ret in the error message.
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c amdgpu_userq_wait_for_signal(struct amdgpu_userq_mgr *uq_mgr) · line 1295
Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +2
-2return ret; }@@ -1289,10 +1289,10 @@ 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_timeout (f, false,MAX_SCHEDULE_TIMEOUT );
With those parameters dma_fence_wait_timeout() can't fail any more, so you don't really need to handle the return value.
There is also the dma_fence_wait() function as shortcut for that.
Regards,
Christian.
Quoted 24 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +3
-9if (ret <=0 ) {drm_file_err (uq_mgr->file,"Timed out waiting for fence=%llu:%llu\n" , f->context, f->seqno);@@ -1308,17 +1308,11 @@ 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 v2 2/3 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 | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +3 -5
@@ -1023,7 +1023,7 @@ 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 +1230,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
Re: [Patch v2 2/3] drm/amdgpu/userq: add the return code too in error condition
Quoted 6 lines · Sunil Khatri
In 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.Signed-off-by Sunil Khatri <[email protected]>
Quoted 33 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +3
-5@@ -1023,7 +1023,7 @@ 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 +1230,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);
PATCH v2 3/3 drm/amdgpu/userq: dont check and call dma_resv_wait_timeout
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, 3 insertions(+), 12 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +2 -9
@@ -1477,7 +1477,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 ;
@@ -1491,14 +1490,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 +1 -3
@@ -1978,7 +1978,6 @@ int amdgpu_vm_bo_unmap(struct amdgpu_device *adev,struct amdgpu_bo_va_mapping *mapping;struct amdgpu_vm *vm = bo_va->base.vm;bool valid = true; -int r; saddr /=AMDGPU_GPU_PAGE_SIZE ;
@@ -2004,8 +2003,7 @@ int amdgpu_vm_bo_unmap(struct amdgpu_device *adev,* 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 )) +if (amdgpu_userq_gem_va_unmap_validate (adev, mapping, saddr))dev_warn_once (adev->dev,"Attempt to unmap an active userq buffer\n" ); }
Signature · 1 line
2.34.1
Christian König
maintainerRe: [Patch v2 3/3] drm/amdgpu/userq: dont check and call dma_resv_wait_timeout
Quoted 51 lines · Sunil Khatri
In function
amdgpu_userq_gem_va_unmap_validatecalldma_resv_wait_timeoutdirectly.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, 3 insertions(+), 12 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +2
-9@@ -1477,7 +1477,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 ;@@ -1491,14 +1490,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 +0
-1@@ -1978,7 +1978,6 @@ int amdgpu_vm_bo_unmap(struct amdgpu_device *adev,struct amdgpu_bo_va_mapping *mapping;struct amdgpu_vm *vm = bo_va->base.vm;bool valid = true; -int r; saddr /=AMDGPU_GPU_PAGE_SIZE ;
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c int amdgpu_vm_bo_unmap(struct amdgpu_device *adev, · line 2006
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1
-2@@ -2004,8 +2003,7 @@ int amdgpu_vm_bo_unmap(struct amdgpu_device *adev,* 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 )) +if (amdgpu_userq_gem_va_unmap_validate (adev, mapping, saddr))
That is actually broken. dma_resv_wait_timeout() can return -ERESTARTSYS when interrupted and in that moment you should not print an error.
Regards,
Christian.
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0
-0dev_warn_once (adev->dev,"Attempt to unmap an active userq buffer\n" ); }