drm/amdgpu/userq: rename suspend/resume callbacks
Subsystems (2)
Alex Deucher
maintainerPATCH 1/10 drm/amdgpu/userq: rename suspend/resume callbacks
Rename to map and umap to better align with what is happening at the firmware level and remove the extra level of indirection in the MES userq code.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 10 ++-- drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.h | 8 ++-- drivers/gpu/drm/amd/amdgpu/mes_userqueue.c | 46 ++++++------------- 3 files changed, 23 insertions(+), 41 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +5 -5
@@ -432,11 +432,11 @@ amdgpu_userqueue_resume_all(struct amdgpu_userq_mgr *uq_mgr)/* Resume all the queues for this process */ idr_for_each_entry (&uq_mgr->userq_idr, queue, queue_id) { userq_funcs = adev->userq_funcs[queue->queue_type]; - ret = userq_funcs->resume (uq_mgr, queue); + ret = userq_funcs->map (uq_mgr, queue); }if (ret) -DRM_ERROR ("Failed to resume all the queue\n" ); +DRM_ERROR ("Failed to map all the queues\n" );return ret; }
@@ -587,14 +587,14 @@ amdgpu_userqueue_suspend_all(struct amdgpu_userq_mgr *uq_mgr)int queue_id;int ret =0 ; -/* Try to suspend all the queues in this process ctx */ +/* Try to unmap all the queues in this process ctx */ idr_for_each_entry (&uq_mgr->userq_idr, queue, queue_id) { userq_funcs = adev->userq_funcs[queue->queue_type]; - ret += userq_funcs->suspend (uq_mgr, queue); + ret += userq_funcs->unmap (uq_mgr, queue); }if (ret) -DRM_ERROR ("Couldn't suspend all the queues\n" ); +DRM_ERROR ("Couldn't unmap all the queues\n" );return ret; }
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.h +4 -4
@@ -64,10 +64,10 @@ struct amdgpu_userq_funcs { struct amdgpu_usermode_queue *queue);void (*mqd_destroy)(struct amdgpu_userq_mgr *uq_mgr,struct amdgpu_usermode_queue *uq); -int (*suspend)(struct amdgpu_userq_mgr *uq_mgr, -struct amdgpu_usermode_queue *queue); -int (*resume)(struct amdgpu_userq_mgr *uq_mgr, -struct amdgpu_usermode_queue *queue); +int (*unmap)(struct amdgpu_userq_mgr *uq_mgr, +struct amdgpu_usermode_queue *queue); +int (*map)(struct amdgpu_userq_mgr *uq_mgr, +struct amdgpu_usermode_queue *queue); };/* Usermode queues for gfx */
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +14 -32
89 lines not on this page · raw message
Signature · 1 line
2.49.0
Alex Deucher
maintainerPATCH 2/10 drm/amdgpu/userq: rework front end call sequence
Split out the queue map from the mqd create call and split out the queue unmap from the mqd destroy call. This splits the queue setup and teardown with the actual enablement in the firmware.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 17 +++++++++++++++-- drivers/gpu/drm/amd/amdgpu/mes_userqueue.c | 10 ---------- 2 files changed, 15 insertions(+), 12 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +15 -2
@@ -263,7 +263,10 @@ amdgpu_userqueue_destroy(struct drm_file *filp, int queue_id) {struct amdgpu_fpriv *fpriv = filp->driver_priv;struct amdgpu_userq_mgr *uq_mgr = &fpriv->userq_mgr; +struct amdgpu_device *adev = uq_mgr->adev; +const struct amdgpu_userq_funcs *uq_funcs;struct amdgpu_usermode_queue *queue; +int r;cancel_delayed_work (&uq_mgr->resume_work);mutex_lock (&uq_mgr->userq_mutex);
@@ -274,12 +277,13 @@ amdgpu_userqueue_destroy(struct drm_file *filp, int queue_id)mutex_unlock (&uq_mgr->userq_mutex);return -EINVAL ; } - + uq_funcs = adev->userq_funcs[queue->queue_type]; + r = uq_funcs->unmap (uq_mgr, queue);amdgpu_bo_unpin (queue->db_obj.obj);amdgpu_bo_unref (&queue->db_obj.obj);amdgpu_userqueue_cleanup (uq_mgr, queue, queue_id);mutex_unlock (&uq_mgr->userq_mutex); -return 0 ; +return r; } static int
@@ -364,6 +368,15 @@ amdgpu_userqueue_create(struct drm_file *filp, union drm_amdgpu_userq *args) r = -ENOMEM ; goto unlock; } + + r = uq_funcs->map (uq_mgr, queue); +if (r) { +DRM_ERROR ("Failed to map Queue\n" ); + uq_funcs->mqd_destroy (uq_mgr, queue); +kfree (queue); + goto unlock; + } + args->out.queue_id = qid; unlock:
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +0 -10
@@ -320,13 +320,6 @@ static int mes_userq_mqd_create(struct amdgpu_userq_mgr *uq_mgr, goto free_ctx; } -/* Map userqueue into FW using MES */ - r =mes_userq_map (uq_mgr, queue); -if (r) { -DRM_ERROR ("Failed to init MQD\n" ); - goto free_ctx; - } -return 0 ; free_ctx:
@@ -350,9 +343,6 @@ mes_userq_mqd_destroy(struct amdgpu_userq_mgr *uq_mgr, {struct amdgpu_device *adev = uq_mgr->adev; -if (queue->queue_active) -mes_userq_unmap (uq_mgr, queue); -amdgpu_userqueue_destroy_object (uq_mgr, &queue->fw_obj);kfree (queue->userq_prop);amdgpu_userqueue_destroy_object (uq_mgr, &queue->mqd);
Signature · 1 line
2.49.0
Alex Deucher
maintainerPATCH 3/10 drm/amdgpu/userq: move some code around
In reply to Alex DeucherMove some userq fence handling code into amdgpu_userq_fence.c. This matches the other code in that file.
--- .../gpu/drm/amd/amdgpu/amdgpu_userq_fence.c | 26 +++++++++++++++++++ .../gpu/drm/amd/amdgpu/amdgpu_userq_fence.h | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 26 ------------------- 3 files changed, 27 insertions(+), 26 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +26 -0
@@ -120,6 +120,32 @@ int amdgpu_userq_fence_driver_alloc(struct amdgpu_device *adev,return r; } +static void amdgpu_userq_walk_and_drop_fence_drv (struct xarray *xa) +{ +struct amdgpu_userq_fence_driver *fence_drv; +unsigned long index; + +if (xa_empty (xa)) +return ; + +xa_lock (xa); +xa_for_each (xa, index, fence_drv) { +__xa_erase (xa, index); +amdgpu_userq_fence_driver_put (fence_drv); + } + +xa_unlock (xa); +} + +void +amdgpu_userq_fence_driver_free (struct amdgpu_usermode_queue *userq) +{ +amdgpu_userq_walk_and_drop_fence_drv (&userq->fence_drv_xa); +xa_destroy (&userq->fence_drv_xa); +/* Drop the fence_drv reference held by user queue */ +amdgpu_userq_fence_driver_put (userq->fence_drv); +} +void amdgpu_userq_fence_driver_process (struct amdgpu_userq_fence_driver *fence_drv) {struct amdgpu_userq_fence *userq_fence, *tmp;
drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.h +1 -0
@@ -66,6 +66,7 @@ void amdgpu_userq_fence_driver_get(struct amdgpu_userq_fence_driver *fence_drv);void amdgpu_userq_fence_driver_put (struct amdgpu_userq_fence_driver *fence_drv);int amdgpu_userq_fence_driver_alloc (struct amdgpu_device *adev,struct amdgpu_usermode_queue *userq); +void amdgpu_userq_fence_driver_free (struct amdgpu_usermode_queue *userq);void amdgpu_userq_fence_driver_process (struct amdgpu_userq_fence_driver *fence_drv);void amdgpu_userq_fence_driver_destroy (struct kref *ref); int amdgpu_userq_signal_ioctl(struct drm_device *dev, void *data,
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +0 -26
@@ -28,32 +28,6 @@#include "amdgpu_userqueue.h" #include "amdgpu_userq_fence.h" -static void amdgpu_userq_walk_and_drop_fence_drv (struct xarray *xa) -{ -struct amdgpu_userq_fence_driver *fence_drv; -unsigned long index; - -if (xa_empty (xa)) -return ; - -xa_lock (xa); -xa_for_each (xa, index, fence_drv) { -__xa_erase (xa, index); -amdgpu_userq_fence_driver_put (fence_drv); - } - -xa_unlock (xa); -} - -static void -amdgpu_userq_fence_driver_free (struct amdgpu_usermode_queue *userq) -{ -amdgpu_userq_walk_and_drop_fence_drv (&userq->fence_drv_xa); -xa_destroy (&userq->fence_drv_xa); -/* Drop the fence_drv reference held by user queue */ -amdgpu_userq_fence_driver_put (userq->fence_drv); -} - static void amdgpu_userqueue_cleanup(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermode_queue *queue,
Signature · 1 line
2.49.0
Alex Deucher
maintainerPATCH 4/10 drm/amdgpu/userq: properly clean up userq fence driver on failure
In reply to Alex DeucherIf userq creation fails, we need to properly unwind and free the user queue fence driver.
v2: free idr as well (Sunil)
--- drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +4 -0
@@ -330,6 +330,7 @@ amdgpu_userqueue_create(struct drm_file *filp, union drm_amdgpu_userq *args) r = uq_funcs->mqd_create (uq_mgr, &args->in, queue);if (r) {DRM_ERROR ("Failed to create Queue\n" ); +amdgpu_userq_fence_driver_free (queue);kfree (queue); goto unlock; }
@@ -337,6 +338,7 @@ amdgpu_userqueue_create(struct drm_file *filp, union drm_amdgpu_userq *args) qid =idr_alloc (&uq_mgr->userq_idr, queue,1 ,AMDGPU_MAX_USERQ_COUNT ,GFP_KERNEL );if (qid <0 ) {DRM_ERROR ("Failed to allocate a queue id\n" ); +amdgpu_userq_fence_driver_free (queue); uq_funcs->mqd_destroy (uq_mgr, queue);kfree (queue); r = -ENOMEM ;
@@ -346,6 +348,8 @@ amdgpu_userqueue_create(struct drm_file *filp, union drm_amdgpu_userq *args) r = uq_funcs->map (uq_mgr, queue);if (r) {DRM_ERROR ("Failed to map Queue\n" ); +idr_remove (&uq_mgr->userq_idr, qid); +amdgpu_userq_fence_driver_free (queue); uq_funcs->mqd_destroy (uq_mgr, queue);kfree (queue); goto unlock;
Signature · 1 line
2.49.0
Alex Deucher
maintainerPATCH 5/10 drm/amdgpu/userq: add suspend and resume helpers
In reply to Alex DeucherAdd helpers to unmap and map user queues on suspend and resume.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 39 +++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.h | 3 ++ 2 files changed, 42 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +39 -0
@@ -681,3 +681,42 @@ void amdgpu_userq_mgr_fini(struct amdgpu_userq_mgr *userq_mgr)mutex_unlock (&userq_mgr->userq_mutex);mutex_destroy (&userq_mgr->userq_mutex); } + +int amdgpu_userq_suspend (struct amdgpu_device *adev) +{ +const struct amdgpu_userq_funcs *userq_funcs; +struct amdgpu_usermode_queue *queue; +struct amdgpu_userq_mgr *uqm, *tmp; +int queue_id; +int ret =0 ; + +mutex_lock (&adev->userq_mutex); +list_for_each_entry_safe (uqm, tmp, &adev->userq_mgr_list, list) { +cancel_delayed_work_sync (&uqm->resume_work); +idr_for_each_entry (&uqm->userq_idr, queue, queue_id) { + userq_funcs = adev->userq_funcs[queue->queue_type]; + ret |= userq_funcs->unmap (uqm, queue); + } + } +mutex_unlock (&adev->userq_mutex); +return ret; +} + +int amdgpu_userq_resume (struct amdgpu_device *adev) +{ +const struct amdgpu_userq_funcs *userq_funcs; +struct amdgpu_usermode_queue *queue; +struct amdgpu_userq_mgr *uqm, *tmp; +int queue_id; +int ret =0 ; + +mutex_lock (&adev->userq_mutex); +list_for_each_entry_safe (uqm, tmp, &adev->userq_mgr_list, list) { +idr_for_each_entry (&uqm->userq_idr, queue, queue_id) { + userq_funcs = adev->userq_funcs[queue->queue_type]; + ret |= userq_funcs->map (uqm, queue); + } + } +mutex_unlock (&adev->userq_mutex); +return ret; +}
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.h +3 -0
@@ -111,4 +111,7 @@ uint64_t amdgpu_userqueue_get_doorbell_index(struct amdgpu_userq_mgr *uq_mgr,struct amdgpu_db_info *db_info, struct drm_file *filp); +int amdgpu_userq_suspend (struct amdgpu_device *adev); +int amdgpu_userq_resume (struct amdgpu_device *adev); +#endif
Signature · 1 line
2.49.0
Alex Deucher
maintainerPATCH 6/10 drm/amdgpu/userq: handle system suspend and resume
In reply to Alex DeucherUnmap user queues on suspend and map them on resume.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +13 -1
@@ -3507,6 +3507,9 @@ static int amdgpu_device_ip_fini_early(struct amdgpu_device *adev)amdgpu_device_set_cg_state (adev,AMD_CG_STATE_UNGATE );amdgpu_amdkfd_suspend (adev, false); +#ifdef CONFIG_DRM_AMDGPU_NAVI3X_USERQ +amdgpu_userq_suspend (adev); +#endif /* Workaround for ASICs need to disable SMC first */ amdgpu_device_smu_fini_early (adev);
@@ -5075,8 +5078,12 @@ int amdgpu_device_suspend(struct drm_device *dev, bool notify_clients)amdgpu_device_ip_suspend_phase1 (adev); -if (!adev->in_s0ix) +if (!adev->in_s0ix) {amdgpu_amdkfd_suspend (adev, adev->in_runpm); +#ifdef CONFIG_DRM_AMDGPU_NAVI3X_USERQ +amdgpu_userq_suspend (adev); +#endif + } r =amdgpu_device_evict_resources (adev);if (r)
@@ -5143,6 +5150,11 @@ int amdgpu_device_resume(struct drm_device *dev, bool notify_clients) r =amdgpu_amdkfd_resume (adev, adev->in_runpm);if (r) goto exit; +#ifdef CONFIG_DRM_AMDGPU_NAVI3X_USERQ + r =amdgpu_userq_resume (adev); +if (r) + goto exit; +#endif } r =amdgpu_device_ip_late_init (adev);
Signature · 1 line
2.49.0
Alex Deucher
maintainerPATCH 7/10 drm/amdgpu: don't swallow errors in amdgpu_userqueue_resume_all()
In reply to Alex Deuchersince we loop through the queues |= the errors.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +1 -1
@@ -423,7 +423,7 @@ amdgpu_userqueue_resume_all(struct amdgpu_userq_mgr *uq_mgr)/* Resume all the queues for this process */ idr_for_each_entry (&uq_mgr->userq_idr, queue, queue_id) { userq_funcs = adev->userq_funcs[queue->queue_type]; - ret = userq_funcs->map (uq_mgr, queue); + ret |= userq_funcs->map (uq_mgr, queue); }if (ret)
Signature · 1 line
2.49.0
Alex Deucher
maintainerPATCH 8/10 drm/amdgpu/userq: track the xcp_id associated with the queue
In reply to Alex DeucherTrack this to align with KFD for enforce isolation handling.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.h | 1 + 1 file changed, 1 insertion(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.h +1 -0
@@ -56,6 +56,7 @@ struct amdgpu_usermode_queue {struct xarray fence_drv_xa;struct amdgpu_userq_fence_driver *fence_drv;struct dma_fence *last_fence; +u32 xcp_id; };struct amdgpu_userq_funcs {
Signature · 1 line
2.49.0
Re: [PATCH 08/10] drm/amdgpu/userq: track the xcp_id associated with the queue
Quoted 20 lines · Alex Deucher
Track this to align with KFD for enforce isolation handling.
Signed-off-by Alex Deucher <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.h | 1 + 1 file changed, 1 insertion(+)drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.h +1
-0@@ -56,6 +56,7 @@ struct amdgpu_usermode_queue {struct xarray fence_drv_xa;struct amdgpu_userq_fence_driver *fence_drv;struct dma_fence *last_fence; +u32 xcp_id; };struct amdgpu_userq_funcs {
Alex Deucher
maintainerPATCH v2 9/10 drm/amdgpu/userq: add helpers to start/stop scheduling
In reply to Alex DeucherThis will be used to stop/start user queue scheduling for example when switching between kernel and user queues when enforce isolation is enabled.
v2: use idx
--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 72 ++++++++++++++++--- drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.h | 3 + 3 files changed, 68 insertions(+), 8 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1 -0
@@ -1249,6 +1249,7 @@ struct amdgpu_device {struct list_head userq_mgr_list;struct mutex userq_mutex; +bool userq_halt; }; static inline uint32_t amdgpu_ip_version(const struct amdgpu_device *adev,
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +64 -8
88 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.h +3 -0
@@ -115,4 +115,7 @@ uint64_t amdgpu_userqueue_get_doorbell_index(struct amdgpu_userq_mgr *uq_mgr,int amdgpu_userq_suspend (struct amdgpu_device *adev);int amdgpu_userq_resume (struct amdgpu_device *adev); +int amdgpu_userq_stop_sched (struct amdgpu_device *adev,u32 idx); +int amdgpu_userq_start_sched (struct amdgpu_device *adev,u32 idx); +#endif
Signature · 1 line
2.49.0
Re: [PATCH V2 09/10] drm/amdgpu/userq: add helpers to start/stop scheduling
Quoted 132 lines · Alex Deucher
This will be used to stop/start user queue scheduling for example when switching between kernel and user queues when enforce isolation is enabled.
v2: use idx
Signed-off-by Alex Deucher <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 72 ++++++++++++++++--- drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.h | 3 + 3 files changed, 68 insertions(+), 8 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu.h +1
-0@@ -1249,6 +1249,7 @@ struct amdgpu_device {struct list_head userq_mgr_list;struct mutex userq_mutex; +bool userq_halt; }; static inline uint32_t amdgpu_ip_version(const struct amdgpu_device *adev,drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +64
-8@@ -335,6 +335,7 @@ amdgpu_userqueue_create(struct drm_file *filp, union drm_amdgpu_userq *args) goto unlock; } + qid =idr_alloc (&uq_mgr->userq_idr, queue,1 ,AMDGPU_MAX_USERQ_COUNT ,GFP_KERNEL );if (qid <0 ) {DRM_ERROR ("Failed to allocate a queue id\n" );@@ -345,15 +346,21 @@ amdgpu_userqueue_create(struct drm_file *filp, union drm_amdgpu_userq *args) goto unlock; } - r = uq_funcs->map (uq_mgr, queue); -if (r) { -DRM_ERROR ("Failed to map Queue\n" ); -idr_remove (&uq_mgr->userq_idr, qid); -amdgpu_userq_fence_driver_free (queue); - uq_funcs->mqd_destroy (uq_mgr, queue); -kfree (queue); - goto unlock; +/* don't map the queue if scheduling is halted */ +mutex_lock (&adev->userq_mutex); +if (!adev->userq_halt) { + r = uq_funcs->map (uq_mgr, queue); +if (r) { +DRM_ERROR ("Failed to map Queue\n" ); +mutex_unlock (&adev->userq_mutex); +idr_remove (&uq_mgr->userq_idr, qid); +amdgpu_userq_fence_driver_free (queue); + uq_funcs->mqd_destroy (uq_mgr, queue); +kfree (queue); + goto unlock; + } } +mutex_unlock (&adev->userq_mutex); args->out.queue_id = qid;@@ -720,3 +727,52 @@ int amdgpu_userq_resume(struct amdgpu_device *adev)mutex_unlock (&adev->userq_mutex);return ret; } + +int amdgpu_userq_stop_sched (struct amdgpu_device *adev,u32 idx) +{ +const struct amdgpu_userq_funcs *userq_funcs; +struct amdgpu_usermode_queue *queue; +struct amdgpu_userq_mgr *uqm, *tmp; +int queue_id; +int ret =0 ; + +mutex_lock (&adev->userq_mutex); +if (adev->userq_halt) +dev_warn (adev->dev,"userq scheduling already stopped!\n" ); + adev->userq_halt = true; +list_for_each_entry_safe (uqm, tmp, &adev->userq_mgr_list, list) { +cancel_delayed_work_sync (&uqm->resume_work); +idr_for_each_entry (&uqm->userq_idr, queue, queue_id) { +if (queue->xcp_id == idx) { + userq_funcs = adev->userq_funcs[queue->queue_type]; + ret |= userq_funcs->unmap (uqm, queue); + } + } + } +mutex_unlock (&adev->userq_mutex); +return ret; +} + +int amdgpu_userq_start_sched (struct amdgpu_device *adev,u32 idx) +{ +const struct amdgpu_userq_funcs *userq_funcs; +struct amdgpu_usermode_queue *queue; +struct amdgpu_userq_mgr *uqm, *tmp; +int queue_id; +int ret =0 ; + +mutex_lock (&adev->userq_mutex); +if (!adev->userq_halt) +dev_warn (adev->dev,"userq scheduling already started!\n" ); + adev->userq_halt = false; +list_for_each_entry_safe (uqm, tmp, &adev->userq_mgr_list, list) { +idr_for_each_entry (&uqm->userq_idr, queue, queue_id) { +if (queue->xcp_id == idx) { + userq_funcs = adev->userq_funcs[queue->queue_type]; + ret |= userq_funcs->map (uqm, queue); + } + } + } +mutex_unlock (&adev->userq_mutex); +return ret; +}drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.h +3
-0@@ -115,4 +115,7 @@ uint64_t amdgpu_userqueue_get_doorbell_index(struct amdgpu_userq_mgr *uq_mgr,int amdgpu_userq_suspend (struct amdgpu_device *adev);int amdgpu_userq_resume (struct amdgpu_device *adev); +int amdgpu_userq_stop_sched (struct amdgpu_device *adev,u32 idx); +int amdgpu_userq_start_sched (struct amdgpu_device *adev,u32 idx); +#endif
Alex Deucher
maintainerPATCH 10/10 drm/amdgpu/userq: integrate with enforce isolation
In reply to Alex DeucherEnforce isolation serializes access to the GFX IP. User queues are isolated in the MES scheduler, but we still need to serialize between kernel queues and user queues. For enforce isolation, group KGD user queues with KFD user queues.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 34 ++++++++++++---------- drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h | 6 ++-- 3 files changed, 22 insertions(+), 20 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1 -1
@@ -4362,7 +4362,7 @@ int amdgpu_device_init(struct amdgpu_device *adev,amdgpu_sync_create (&adev->isolation[i].active);amdgpu_sync_create (&adev->isolation[i].prev); } -mutex_init (&adev->gfx.kfd_sch_mutex); +mutex_init (&adev->gfx.userq_sch_mutex);mutex_init (&adev->gfx.workload_profile_mutex);mutex_init (&adev->vcn.workload_profile_mutex);mutex_init (&adev->userq_mutex);
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +18 -16
@@ -1947,39 +1947,41 @@ void amdgpu_gfx_cleaner_shader_init(struct amdgpu_device *adev,static void amdgpu_gfx_kfd_sch_ctrl (struct amdgpu_device *adev,u32 idx,bool enable) { -mutex_lock (&adev->gfx.kfd_sch_mutex); +mutex_lock (&adev->gfx.userq_sch_mutex);if (enable) {/* If the count is already 0, it means there's an imbalance bug somewhere. * Note that the bug may be in a different caller than the one which triggers the * WARN_ON_ONCE. */ -if (WARN_ON_ONCE (adev->gfx.kfd_sch_req_count[idx] ==0 )) { +if (WARN_ON_ONCE (adev->gfx.userq_sch_req_count[idx] ==0 )) {dev_err (adev->dev,"Attempted to enable KFD scheduler when reference count is already zero\n" ); goto unlock; } - adev->gfx.kfd_sch_req_count[idx]--; + adev->gfx.userq_sch_req_count[idx]--; -if (adev->gfx.kfd_sch_req_count[idx] ==0 && - adev->gfx.kfd_sch_inactive[idx]) { +if (adev->gfx.userq_sch_req_count[idx] ==0 && + adev->gfx.userq_sch_inactive[idx]) {schedule_delayed_work (&adev->gfx.enforce_isolation[idx].work,msecs_to_jiffies (adev->gfx.enforce_isolation_time[idx])); } }else { -if (adev->gfx.kfd_sch_req_count[idx] ==0 ) { +if (adev->gfx.userq_sch_req_count[idx] ==0 ) {cancel_delayed_work_sync (&adev->gfx.enforce_isolation[idx].work); -if (!adev->gfx.kfd_sch_inactive[idx]) { -amdgpu_amdkfd_stop_sched (adev, idx); - adev->gfx.kfd_sch_inactive[idx] = true; +if (!adev->gfx.userq_sch_inactive[idx]) { +amdgpu_userq_stop_sched (adev, idx); +if (adev->kfd.init_complete) +amdgpu_amdkfd_stop_sched (adev, idx); + adev->gfx.userq_sch_inactive[idx] = true; } } - adev->gfx.kfd_sch_req_count[idx]++; + adev->gfx.userq_sch_req_count[idx]++; } unlock: -mutex_unlock (&adev->gfx.kfd_sch_mutex); +mutex_unlock (&adev->gfx.userq_sch_mutex); }/**
@@ -2024,12 +2026,12 @@ void amdgpu_gfx_enforce_isolation_handler(struct work_struct *work) msecs_to_jiffies(1)); }else {/* Tell KFD to resume the runqueue */ -if (adev->kfd.init_complete) { -WARN_ON_ONCE (!adev->gfx.kfd_sch_inactive[idx]); -WARN_ON_ONCE (adev->gfx.kfd_sch_req_count[idx]); +WARN_ON_ONCE (!adev->gfx.userq_sch_inactive[idx]); +WARN_ON_ONCE (adev->gfx.userq_sch_req_count[idx]); +amdgpu_userq_start_sched (adev, idx); +if (adev->kfd.init_complete)amdgpu_amdkfd_start_sched (adev, idx); - adev->gfx.kfd_sch_inactive[idx] = false; - } + adev->gfx.userq_sch_inactive[idx] = false; }mutex_unlock (&adev->enforce_isolation_mutex); }
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +3 -3
@@ -475,9 +475,9 @@ struct amdgpu_gfx {bool enable_cleaner_shader;struct amdgpu_isolation_work enforce_isolation[MAX_XCP ];/* Mutex for synchronizing KFD scheduler operations */ -struct mutex kfd_sch_mutex; -u64 kfd_sch_req_count[MAX_XCP ]; -bool kfd_sch_inactive[MAX_XCP ]; +struct mutex userq_sch_mutex; +u64 userq_sch_req_count[MAX_XCP ]; +bool userq_sch_inactive[MAX_XCP ];unsigned long enforce_isolation_jiffies[MAX_XCP ];unsigned long enforce_isolation_time[MAX_XCP ];
Signature · 1 line
2.49.0
Re: [PATCH 10/10] drm/amdgpu/userq: integrate with enforce isolation
Quoted 118 lines · Alex Deucher
Enforce isolation serializes access to the GFX IP. User queues are isolated in the MES scheduler, but we still need to serialize between kernel queues and user queues. For enforce isolation, group KGD user queues with KFD user queues.
Signed-off-by Alex Deucher<[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 34 ++++++++++++---------- drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h | 6 ++-- 3 files changed, 22 insertions(+), 20 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1
-1@@ -4362,7 +4362,7 @@ int amdgpu_device_init(struct amdgpu_device *adev,amdgpu_sync_create (&adev->isolation[i].active);amdgpu_sync_create (&adev->isolation[i].prev); } -mutex_init (&adev->gfx.kfd_sch_mutex); +mutex_init (&adev->gfx.userq_sch_mutex);mutex_init (&adev->gfx.workload_profile_mutex);mutex_init (&adev->vcn.workload_profile_mutex);mutex_init (&adev->userq_mutex);drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +18
-16@@ -1947,39 +1947,41 @@ void amdgpu_gfx_cleaner_shader_init(struct amdgpu_device *adev,static void amdgpu_gfx_kfd_sch_ctrl (struct amdgpu_device *adev,u32 idx,bool enable) { -mutex_lock (&adev->gfx.kfd_sch_mutex); +mutex_lock (&adev->gfx.userq_sch_mutex);if (enable) {/* If the count is already 0, it means there's an imbalance bug somewhere. * Note that the bug may be in a different caller than the one which triggers the * WARN_ON_ONCE. */ -if (WARN_ON_ONCE (adev->gfx.kfd_sch_req_count[idx] ==0 )) { +if (WARN_ON_ONCE (adev->gfx.userq_sch_req_count[idx] ==0 )) {dev_err (adev->dev,"Attempted to enable KFD scheduler when reference count is already zero\n" ); goto unlock; } - adev->gfx.kfd_sch_req_count[idx]--; + adev->gfx.userq_sch_req_count[idx]--; -if (adev->gfx.kfd_sch_req_count[idx] ==0 && - adev->gfx.kfd_sch_inactive[idx]) { +if (adev->gfx.userq_sch_req_count[idx] ==0 && + adev->gfx.userq_sch_inactive[idx]) {schedule_delayed_work (&adev->gfx.enforce_isolation[idx].work,msecs_to_jiffies (adev->gfx.enforce_isolation_time[idx])); } }else { -if (adev->gfx.kfd_sch_req_count[idx] ==0 ) { +if (adev->gfx.userq_sch_req_count[idx] ==0 ) {cancel_delayed_work_sync (&adev->gfx.enforce_isolation[idx].work); -if (!adev->gfx.kfd_sch_inactive[idx]) { -amdgpu_amdkfd_stop_sched (adev, idx); - adev->gfx.kfd_sch_inactive[idx] = true; +if (!adev->gfx.userq_sch_inactive[idx]) { +amdgpu_userq_stop_sched (adev, idx); +if (adev->kfd.init_complete) +amdgpu_amdkfd_stop_sched (adev, idx); + adev->gfx.userq_sch_inactive[idx] = true; } } - adev->gfx.kfd_sch_req_count[idx]++; + adev->gfx.userq_sch_req_count[idx]++; } unlock: -mutex_unlock (&adev->gfx.kfd_sch_mutex); +mutex_unlock (&adev->gfx.userq_sch_mutex); }/** @@ -2024,12 +2026,12 @@ void amdgpu_gfx_enforce_isolation_handler(struct work_struct *work) msecs_to_jiffies(1)); }else {/* Tell KFD to resume the runqueue */ -if (adev->kfd.init_complete) { -WARN_ON_ONCE (!adev->gfx.kfd_sch_inactive[idx]); -WARN_ON_ONCE (adev->gfx.kfd_sch_req_count[idx]); +WARN_ON_ONCE (!adev->gfx.userq_sch_inactive[idx]); +WARN_ON_ONCE (adev->gfx.userq_sch_req_count[idx]); +amdgpu_userq_start_sched (adev, idx); +if (adev->kfd.init_complete)amdgpu_amdkfd_start_sched (adev, idx); - adev->gfx.kfd_sch_inactive[idx] = false; - } + adev->gfx.userq_sch_inactive[idx] = false; }mutex_unlock (&adev->enforce_isolation_mutex); }drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +3
-3@@ -475,9 +475,9 @@ struct amdgpu_gfx {bool enable_cleaner_shader;struct amdgpu_isolation_work enforce_isolation[MAX_XCP ];/* Mutex for synchronizing KFD scheduler operations */ -struct mutex kfd_sch_mutex; -u64 kfd_sch_req_count[MAX_XCP ]; -bool kfd_sch_inactive[MAX_XCP ]; +struct mutex userq_sch_mutex; +u64 userq_sch_req_count[MAX_XCP ]; +bool userq_sch_inactive[MAX_XCP ];unsigned long enforce_isolation_jiffies[MAX_XCP ];unsigned long enforce_isolation_time[MAX_XCP ];