drm/amdgpu/userq: amdgpu_userq_vm_validate does not need userq mutex
Subsystems (2)
PATCH 1/2 drm/amdgpu/userq: amdgpu_userq_vm_validate does not need userq mutex
amdgpu_userq_vm_validate function does not need userq_mutex and exec lock is good enough to locking all bos and updating the eviction fence.
Also since we only need userq_mutex for amdgpu_userq_restore_all so move the locks in the function itself.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +5 -5
@@ -997,6 +997,7 @@ amdgpu_userq_restore_all(struct amdgpu_userq_mgr *uq_mgr)unsigned long queue_id;int ret =0 , r; +mutex_lock (&uq_mgr->userq_mutex);/* Resume all the queues for this process */ xa_for_each (&uq_mgr->userq_xa, queue_id, queue) {
@@ -1012,6 +1013,7 @@ amdgpu_userq_restore_all(struct amdgpu_userq_mgr *uq_mgr) ret = r; } +mutex_unlock (&uq_mgr->userq_mutex);if (ret)drm_file_err (uq_mgr->file,"Failed to map all the queues\n" );
@@ -1215,23 +1217,21 @@ static void amdgpu_userq_restore_worker(struct work_struct *work)struct dma_fence *ev_fence;int ret; -mutex_lock (&uq_mgr->userq_mutex); ev_fence =amdgpu_evf_mgr_get_fence (&fpriv->evf_mgr);if (!dma_fence_is_signaled (ev_fence)) - goto unlock; + goto put_fence; ret =amdgpu_userq_vm_validate (uq_mgr);if (ret) {drm_file_err (uq_mgr->file,"Failed to validate BOs to restore\n" ); - goto unlock; + goto put_fence; } ret =amdgpu_userq_restore_all (uq_mgr);if (ret)drm_file_err (uq_mgr->file,"Failed to restore all queues\n" ); -unlock: -mutex_unlock (&uq_mgr->userq_mutex); +put_fence:dma_fence_put (ev_fence); }
Signature · 1 line
2.34.1
PATCH 2/2 drm/amdgpu/userq: schedule_delayed_work should be after fence signalled
Reorganise the amdgpu_eviction_fence_suspend_worker code so schedule_delayed_work is the last thing we do after amdgpu_userq_evict is complete and the eviction fence is signalled.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c | 6 +++++- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 4 +--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h | 3 +-- 3 files changed, 7 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c +5 -1
@@ -76,7 +76,7 @@ amdgpu_eviction_fence_suspend_worker(struct work_struct *work) cookie =dma_fence_begin_signalling (); ev_fence =amdgpu_evf_mgr_get_fence (evf_mgr); -amdgpu_userq_evict (uq_mgr, !evf_mgr->shutdown); +amdgpu_userq_evict (uq_mgr);/* * Signaling the eviction fence must be done while holding the
@@ -86,6 +86,10 @@ amdgpu_eviction_fence_suspend_worker(struct work_struct *work)dma_fence_signal (ev_fence);dma_fence_end_signalling (cookie);dma_fence_put (ev_fence); + +if (!evf_mgr->shutdown) +schedule_delayed_work (&uq_mgr->resume_work,0 ); +mutex_unlock (&uq_mgr->userq_mutex); }
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +1 -3
@@ -1298,7 +1298,7 @@ amdgpu_userq_wait_for_signal(struct amdgpu_userq_mgr *uq_mgr) }void -amdgpu_userq_evict (struct amdgpu_userq_mgr *uq_mgr,bool schedule_resume) +amdgpu_userq_evict (struct amdgpu_userq_mgr *uq_mgr) {struct amdgpu_device *adev = uq_mgr->adev;int ret;
@@ -1312,8 +1312,6 @@ amdgpu_userq_evict(struct amdgpu_userq_mgr *uq_mgr, bool schedule_resume)if (ret)dev_err (adev->dev,"Failed to evict userqueue\n" ); -if (schedule_resume) -schedule_delayed_work (&uq_mgr->resume_work,0 ); } int amdgpu_userq_mgr_init(struct amdgpu_userq_mgr *userq_mgr, struct drm_file *file_priv,
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h +1 -2
@@ -133,8 +133,7 @@ int amdgpu_userq_create_object(struct amdgpu_userq_mgr *uq_mgr,void amdgpu_userq_destroy_object (struct amdgpu_userq_mgr *uq_mgr,struct amdgpu_userq_obj *userq_obj); -void amdgpu_userq_evict (struct amdgpu_userq_mgr *uq_mgr, -bool schedule_resume); +void amdgpu_userq_evict (struct amdgpu_userq_mgr *uq_mgr);void amdgpu_userq_ensure_ev_fence (struct amdgpu_userq_mgr *userq_mgr,struct amdgpu_eviction_fence_mgr *evf_mgr);
Signature · 1 line
2.34.1
Re: [PATCH v1 2/2] drm/amdgpu/userq: schedule_delayed_work should be after fence signalled
Quoted 6 lines · Sunil Khatri
Reorganise the
amdgpu_eviction_fence_suspend_workercode soschedule_delayed_workis the last thing we do afteramdgpu_userq_evictis complete and the eviction fence is signalled.Suggested-by Christian König <[email protected]>Signed-off-by Sunil Khatri <[email protected]>
But please re-order the patches, this one here should come first.
Quoted 66 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c | 6 +++++- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 4 +--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h | 3 +-- 3 files changed, 7 insertions(+), 6 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c +5
-1@@ -76,7 +76,7 @@ amdgpu_eviction_fence_suspend_worker(struct work_struct *work) cookie =dma_fence_begin_signalling (); ev_fence =amdgpu_evf_mgr_get_fence (evf_mgr); -amdgpu_userq_evict (uq_mgr, !evf_mgr->shutdown); +amdgpu_userq_evict (uq_mgr);/* * Signaling the eviction fence must be done while holding the @@ -86,6 +86,10 @@ amdgpu_eviction_fence_suspend_worker(struct work_struct *work)dma_fence_signal (ev_fence);dma_fence_end_signalling (cookie);dma_fence_put (ev_fence); + +if (!evf_mgr->shutdown) +schedule_delayed_work (&uq_mgr->resume_work,0 ); +mutex_unlock (&uq_mgr->userq_mutex); }drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +1
-3@@ -1298,7 +1298,7 @@ amdgpu_userq_wait_for_signal(struct amdgpu_userq_mgr *uq_mgr) }void -amdgpu_userq_evict (struct amdgpu_userq_mgr *uq_mgr,bool schedule_resume) +amdgpu_userq_evict (struct amdgpu_userq_mgr *uq_mgr) {struct amdgpu_device *adev = uq_mgr->adev;int ret;@@ -1312,8 +1312,6 @@ amdgpu_userq_evict(struct amdgpu_userq_mgr *uq_mgr, bool schedule_resume)if (ret)dev_err (adev->dev,"Failed to evict userqueue\n" ); -if (schedule_resume) -schedule_delayed_work (&uq_mgr->resume_work,0 ); } int amdgpu_userq_mgr_init(struct amdgpu_userq_mgr *userq_mgr, struct drm_file *file_priv,drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h +1
-2@@ -133,8 +133,7 @@ int amdgpu_userq_create_object(struct amdgpu_userq_mgr *uq_mgr,void amdgpu_userq_destroy_object (struct amdgpu_userq_mgr *uq_mgr,struct amdgpu_userq_obj *userq_obj); -void amdgpu_userq_evict (struct amdgpu_userq_mgr *uq_mgr, -bool schedule_resume); +void amdgpu_userq_evict (struct amdgpu_userq_mgr *uq_mgr);void amdgpu_userq_ensure_ev_fence (struct amdgpu_userq_mgr *userq_mgr,struct amdgpu_eviction_fence_mgr *evf_mgr);
Quoted 7 lines · Sunil Khatri
amdgpu_userq_vm_validatefunction does not needuserq_mutexand exec lock is good enough to locking all bos and updating the eviction fence.Also since we only need
userq_mutexforamdgpu_userq_restore_allso move the locks in the function itself.Signed-off-by Sunil Khatri <[email protected]>
Quoted 51 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +5
-5@@ -997,6 +997,7 @@ amdgpu_userq_restore_all(struct amdgpu_userq_mgr *uq_mgr)unsigned long queue_id;int ret =0 , r; +mutex_lock (&uq_mgr->userq_mutex);/* Resume all the queues for this process */ xa_for_each (&uq_mgr->userq_xa, queue_id, queue) {@@ -1012,6 +1013,7 @@ amdgpu_userq_restore_all(struct amdgpu_userq_mgr *uq_mgr) ret = r; } +mutex_unlock (&uq_mgr->userq_mutex);if (ret)drm_file_err (uq_mgr->file,"Failed to map all the queues\n" );@@ -1215,23 +1217,21 @@ static void amdgpu_userq_restore_worker(struct work_struct *work)struct dma_fence *ev_fence;int ret; -mutex_lock (&uq_mgr->userq_mutex); ev_fence =amdgpu_evf_mgr_get_fence (&fpriv->evf_mgr);if (!dma_fence_is_signaled (ev_fence)) - goto unlock; + goto put_fence; ret =amdgpu_userq_vm_validate (uq_mgr);if (ret) {drm_file_err (uq_mgr->file,"Failed to validate BOs to restore\n" ); - goto unlock; + goto put_fence; } ret =amdgpu_userq_restore_all (uq_mgr);if (ret)drm_file_err (uq_mgr->file,"Failed to restore all queues\n" ); -unlock: -mutex_unlock (&uq_mgr->userq_mutex); +put_fence:dma_fence_put (ev_fence); }