drm/amdgpu: add remove all process queues support for MES v12.1
Subsystems (3)
PATCH 1/2 drm/amdgpu: add remove all process queues support for MES v12.1
MES recently added support to remove all queues of a process with a single REMOVE_QUEUE request. Use it to optimize queue removal during process eviction and termination.
Add the new fields to the MES v12 REMOVE_QUEUE packet definition and to struct mes_remove_queue_input, program them in mes_v12_1_remove_hw_queue(), and add amdgpu_mes_remove_all_process_queues_supported() so callers can check whether the running MES firmware supports it. It is supported on GC 12.1 with MES scheduler firmware version 0x87 or newer.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c | 9 +++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h | 3 +++ drivers/gpu/drm/amd/amdgpu/mes_v12_1.c | 13 +++++++++---- drivers/gpu/drm/amd/include/mes_v12_api_def.h | 10 +++++++++- 4 files changed, 30 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c +9 -0
@@ -966,6 +966,15 @@ bool amdgpu_mes_queue_reset_by_mes_supported(struct amdgpu_device *adev) ((ip_maj ==12 && ip_min ==1 ) && mes_sched >=0x7b ); } +bool amdgpu_mes_remove_all_process_queues_supported (struct amdgpu_device *adev) +{ +u32 ip_maj =IP_VERSION_MAJ (amdgpu_ip_version (adev,GC_HWIP ,0 )); +u32 ip_min =IP_VERSION_MIN (amdgpu_ip_version (adev,GC_HWIP ,0 )); +u32 mes_sched = adev->mes.sched_version &AMDGPU_MES_VERSION_MASK ; + +return ip_maj ==12 && ip_min ==1 && mes_sched >=0x87 ; +} +/* Fix me -- node_id is used to identify the correct MES instances in the future */ static int amdgpu_mes_set_enforce_isolation (struct amdgpu_device *adev,uint32_t node_id,bool enable)
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h +3 -0
@@ -333,6 +333,8 @@ struct mes_remove_queue_input {uint32_t queue_type;bool remove_queue_after_reset;uint32_t gang_context_array_index; +bool remove_all_process_queues; +uint32_t pasid; };struct mes_map_legacy_queue_input {
@@ -738,6 +740,7 @@ static inline void amdgpu_mes_unlock(struct amdgpu_mes *mes)bool amdgpu_mes_suspend_resume_all_supported (struct amdgpu_device *adev);bool amdgpu_mes_queue_reset_by_mes_supported (struct amdgpu_device *adev); +bool amdgpu_mes_remove_all_process_queues_supported (struct amdgpu_device *adev);int amdgpu_mes_update_enforce_isolation (struct amdgpu_device *adev);
drivers/gpu/drm/amd/amdgpu/mes_v12_1.c +9 -4
@@ -363,10 +363,15 @@ static int mes_v12_1_remove_hw_queue(struct amdgpu_mes *mes, mes_remove_queue_pkt.header.opcode =MES_SCH_API_REMOVE_QUEUE ; mes_remove_queue_pkt.header.dwsize =API_FRAME_SIZE_IN_DWORDS ; - mes_remove_queue_pkt.doorbell_offset = input->doorbell_offset; - mes_remove_queue_pkt.gang_context_addr = input->gang_context_addr; - mes_remove_queue_pkt.queue_type = -convert_to_mes_queue_type (input->queue_type); +if (input->remove_all_process_queues) { + mes_remove_queue_pkt.remove_all_process_queues =1 ; + mes_remove_queue_pkt.pasid = input->pasid; + }else { + mes_remove_queue_pkt.doorbell_offset = input->doorbell_offset; + mes_remove_queue_pkt.gang_context_addr = input->gang_context_addr; + mes_remove_queue_pkt.queue_type = +convert_to_mes_queue_type (input->queue_type); + } return mes_v12_1_submit_pkt_and_poll_completion(mes, xcc_id, AMDGPU_MES_SCHED_PIPE,
drivers/gpu/drm/amd/include/mes_v12_api_def.h +9 -1
@@ -411,7 +411,13 @@ union MESAPI__REMOVE_QUEUE { uint32_t preempt_legacy_gfx_queue : 1; uint32_t unmap_legacy_queue : 1; uint32_t remove_queue_after_reset : 1; - uint32_t reserved : 27; +/* +* Remove all queues of the process identified by pasid, +* doorbell_offset/gang_context_addr/gang_context_array_index +* are ignored +*/ + uint32_t remove_all_process_queues : 1; + uint32_t reserved : 26; };struct MES_API_STATUS api_status;
@@ -424,6 +430,8 @@ union MESAPI__REMOVE_QUEUE {enum MES_QUEUE_TYPE queue_type;uint64_t timestamp;uint32_t gang_context_array_index; +/* Only valid when remove_all_process_queues is set */ +uint32_t pasid; };uint32_t max_dwords_in_api[API_FRAME_SIZE_IN_DWORDS ];
Signature · 1 line
2.56.0
PATCH 2/2 drm/amdkfd: remove all queues of a process with a single MES call
On process eviction, termination and scheduler halt/stop, KFD sends one MES REMOVE_QUEUE per active queue. If MES supports it, remove all queues of a process, by PASID, with a single request instead.
remove_queue_mes() sends this request when called with a NULL queue. On failure, the same request is passed to the MES queue reset path, which sends it again if no hung queue is found.
--- .../drm/amd/amdkfd/kfd_device_queue_manager.c | 122 ++++++++++++++---- 1 file changed, 96 insertions(+), 26 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +96 -26
@@ -79,7 +79,9 @@ static struct queue *find_queue_by_doorbell_offset(struct device_queue_manager * u32 doorbell_offset);static void set_queue_as_reset (struct device_queue_manager *dqm,struct queue *q,struct qcm_process_device *qpd,bool verbose); -static int reset_queues_mes (struct device_queue_manager *dqm,struct queue *q); +static int reset_queues_mes (struct device_queue_manager *dqm, +struct kfd_process_device *pdd, +struct mes_remove_queue_input *queue_input);static inline enum KFD_MQD_TYPE get_mqd_type_from_queue_type (enum kfd_queue_type type)
@@ -299,6 +301,23 @@ static int add_queue_mes(struct device_queue_manager *dqm, struct queue *q,return r; } +/* A queue that is active and not reset is still in MES */ +static bool qpd_has_mes_queue (struct qcm_process_device *qpd) +{ +struct queue *q; + +list_for_each_entry (q, &qpd->queues_list, list) +if (q->properties.is_active && !q->properties.is_reset) +return true; + +return false; +} + +/* +* Remove queue q from MES. If q is NULL, remove all queues of the process +* with a single request, see amdgpu_mes_remove_all_process_queues_supported(). +* This must be done while the queues are still marked active. +*/ static int remove_queue_mes_on_reset_option(struct device_queue_manager *dqm, struct queue *q, struct qcm_process_device *qpd, bool is_for_reset,
@@ -308,8 +327,8 @@ static int remove_queue_mes_on_reset_option(struct device_queue_manager *dqm, stint r;struct mes_remove_queue_input queue_input; -/* queue was already removed during reset */ -if (q->properties.is_reset) +/* queue(s) already removed during reset */ +if (q ? q->properties.is_reset : !qpd_has_mes_queue (qpd))return 0 ;if (!dqm->sched_running || dqm->sched_halt)
@@ -318,12 +337,17 @@ static int remove_queue_mes_on_reset_option(struct device_queue_manager *dqm, streturn -EIO ;memset (&queue_input,0x0 ,sizeof (struct mes_remove_queue_input )); - queue_input.doorbell_offset = q->properties.doorbell_off; - queue_input.gang_context_addr = q->gang_ctx_gpu_addr; - queue_input.queue_type =convert_to_amdgpu_ring_type (q->properties.type); - queue_input.remove_queue_after_reset = flush_mes_queue; +if (q) { + queue_input.doorbell_offset = q->properties.doorbell_off; + queue_input.gang_context_addr = q->gang_ctx_gpu_addr; + queue_input.queue_type =convert_to_amdgpu_ring_type (q->properties.type); + queue_input.remove_queue_after_reset = flush_mes_queue; + queue_input.gang_context_array_index = q->gang_ctx_array_index; + }else { + queue_input.remove_all_process_queues = true; + queue_input.pasid =qpd_to_pdd (qpd)->pasid; + } queue_input.xcc_id =ffs (dqm->dev->xcc_mask) -1 ; - queue_input.gang_context_array_index = q->gang_ctx_array_index;amdgpu_mes_lock (&adev->mes); r = adev->mes.funcs->remove_hw_queue (&adev->mes, &queue_input);
@@ -335,10 +359,15 @@ static int remove_queue_mes_on_reset_option(struct device_queue_manager *dqm, streturn r;/* remove_hw_queue failure indicates a queue hang. reset the queue */ - r =reset_queues_mes (dqm, q); + queue_input.remove_queue_after_reset = false; + r =reset_queues_mes (dqm,qpd_to_pdd (qpd), &queue_input);if (r && amdgpu_gpu_recovery) { -dev_err (adev->dev,"failed to remove queue from MES, doorbell=0x%x\n" , - q->properties.doorbell_off); +if (q) +dev_err (adev->dev,"failed to remove queue from MES, doorbell=0x%x\n" , + q->properties.doorbell_off); +else +dev_err (adev->dev,"failed to remove queues of pasid 0x%x from MES\n" , + queue_input.pasid);dev_err (adev->dev,"MES might be in unrecoverable state, issue a GPU reset\n" );kfd_hws_hang (dqm); }
@@ -363,6 +392,8 @@ static int remove_queue_mes(struct device_queue_manager *dqm, struct queue *q,static int remove_all_kfd_queues_mes (struct device_queue_manager *dqm) { +struct amdgpu_device *adev = (struct amdgpu_device *)dqm->dev->adev; +bool remove_all =amdgpu_mes_remove_all_process_queues_supported (adev);struct device_process_node *cur;struct device *dev = dqm->dev->adev->dev;struct qcm_process_device *qpd;
@@ -371,6 +402,16 @@ static int remove_all_kfd_queues_mes(struct device_queue_manager *dqm)list_for_each_entry (cur, &dqm->queues, list) { qpd = cur->qpd; +if (remove_all) { + retval =remove_queue_mes (dqm,NULL , qpd); +if (retval) { +dev_err (dev,"%s: Failed to remove queues of pasid 0x%x for dev %d" , + __func__,qpd_to_pdd (qpd)->pasid, dqm->dev->id); +return retval; + } +continue ; + } +list_for_each_entry (q, &qpd->queues_list, list) {if (q->properties.is_active) { retval =remove_queue_mes (dqm, q, qpd);
@@ -452,15 +493,19 @@ int kfd_reset_queue_mes(struct device_queue_manager *dqm, int queue_type,return reset_queue_mes (dqm, q, queue_type, pipe, queue, db); } -static int reset_queues_mes (struct device_queue_manager *dqm,struct queue *q) +/* +* queue_input is the remove request for the bad queue(s). If MES doesn't +* detect a hung queue, it is sent again before the queues are resumed. +*/ +static int reset_queues_mes (struct device_queue_manager *dqm, +struct kfd_process_device *pdd, +struct mes_remove_queue_input *queue_input) {struct amdgpu_device *adev = (struct amdgpu_device *)dqm->dev->adev;struct drm_wedge_task_info *info =NULL ;struct amdgpu_task_info *ti =NULL ; -struct kfd_process_device *pdd;unsigned int num_hung =0 ;int r =0 ; -struct mes_remove_queue_input queue_input;if (!amdgpu_mes_queue_reset_by_mes_supported (adev)) { r = -ENOTRECOVERABLE ;
@@ -471,18 +516,11 @@ static int reset_queues_mes(struct device_queue_manager *dqm, struct queue *q)if (WARN_ON (dqm->detect_hang_count >0 ))return 0 ; -memset (&queue_input,0x0 ,sizeof (struct mes_remove_queue_input )); - queue_input.doorbell_offset = q->properties.doorbell_off; - queue_input.gang_context_addr = q->gang_ctx_gpu_addr; - queue_input.gang_context_array_index = q->gang_ctx_array_index; - queue_input.queue_type =convert_to_amdgpu_ring_type (q->properties.type); - queue_input.remove_queue_after_reset = false; - queue_input.xcc_id =ffs (dqm->dev->xcc_mask) -1 ;/* pass the known bad queue info to the reset function */ - r =amdgpu_gfx_reset_mes_compute (adev, dqm->dev->xcp,NULL ,NULL ,NULL , &num_hung, &queue_input); + r =amdgpu_gfx_reset_mes_compute (adev, dqm->dev->xcp,NULL ,NULL ,NULL , &num_hung, + queue_input);if (r) goto fail; - pdd =kfd_get_process_device_data (q->device, q->process);if (pdd) { ti =amdgpu_vm_get_task_info_pasid (adev, pdd->pasid);if (ti) {
@@ -1493,6 +1531,7 @@ static int evict_process_queues_cpsch(struct device_queue_manager *dqm,struct queue *q;struct device *dev = dqm->dev->adev->dev;struct kfd_process_device *pdd; +bool remove_all;int retval =0 ;dqm_lock (dqm);
@@ -1514,6 +1553,17 @@ static int evict_process_queues_cpsch(struct device_queue_manager *dqm,if (dqm->dev->kfd->shared_resources.enable_mes) pdd->last_evict_timestamp =get_jiffies_64 (); + remove_all = dqm->dev->kfd->shared_resources.enable_mes && +amdgpu_mes_remove_all_process_queues_supported (dqm->dev->adev); +if (remove_all) { + retval =remove_queue_mes (dqm,NULL , qpd); +if (retval) { +dev_err (dev,"Failed to evict queues of pasid 0x%x\n" , + pdd->pasid); + goto out; + } + } +/* Mark all queues as evicted. Deactivate all active queues on * the qpd. */
@@ -1525,7 +1575,7 @@ static int evict_process_queues_cpsch(struct device_queue_manager *dqm, q->properties.is_active = false;decrement_queue_count (dqm, qpd, q); -if (dqm->dev->kfd->shared_resources.enable_mes) { +if (dqm->dev->kfd->shared_resources.enable_mes && !remove_all) { retval =remove_queue_mes (dqm, q, qpd);if (retval) { dev_err(dev, "Failed to evict queue %d\n",
@@ -3286,6 +3336,7 @@ static int process_termination_cpsch(struct device_queue_manager *dqm,enum kfd_unmap_queues_filter filter =KFD_UNMAP_QUEUES_FILTER_DYNAMIC_QUEUES ;bool found = false; +bool remove_all;dqm_lock (dqm);
@@ -3298,6 +3349,15 @@ static int process_termination_cpsch(struct device_queue_manager *dqm, filter =KFD_UNMAP_QUEUES_FILTER_ALL_QUEUES ; } + remove_all = dqm->dev->kfd->shared_resources.enable_mes && +amdgpu_mes_remove_all_process_queues_supported (dqm->dev->adev); +if (remove_all) { + retval =remove_queue_mes (dqm,NULL , qpd); +if (retval) +dev_err (dev,"Failed to remove queues of pasid 0x%x\n" , +qpd_to_pdd (qpd)->pasid); + } +/* Clear all user mode queues */ list_for_each_entry (q, &qpd->queues_list, list) {if (q->properties.type ==KFD_QUEUE_TYPE_SDMA )
@@ -3308,7 +3368,7 @@ static int process_termination_cpsch(struct device_queue_manager *dqm,if (q->properties.is_active) {decrement_queue_count (dqm, qpd, q); -if (dqm->dev->kfd->shared_resources.enable_mes) { +if (dqm->dev->kfd->shared_resources.enable_mes && !remove_all) { retval =remove_queue_mes (dqm, q, qpd);if (retval) dev_err(dev, "Failed to remove queue %d\n",
@@ -3610,7 +3670,17 @@ int kfd_dqm_suspend_bad_queue_mes(struct kfd_node *knode, u32 pasid, u32 doorbellist_for_each_entry (q, &qpd->queues_list, list) {if (q->doorbell_id == doorbell_id && q->properties.is_active) { -if (reset_queues_mes (dqm, q)) +struct mes_remove_queue_input queue_input; + +memset (&queue_input,0x0 ,sizeof (struct mes_remove_queue_input )); + queue_input.doorbell_offset = q->properties.doorbell_off; + queue_input.gang_context_addr = q->gang_ctx_gpu_addr; + queue_input.gang_context_array_index = q->gang_ctx_array_index; + queue_input.queue_type = +convert_to_amdgpu_ring_type (q->properties.type); + queue_input.xcc_id =ffs (dqm->dev->xcc_mask) -1 ; + +if (reset_queues_mes (dqm, pdd, &queue_input))dev_dbg (knode->adev->dev,"Fail to remove bad queue. doorbell_id 0x%x\n" , q->doorbell_id); q->properties.is_evicted = true;
Signature · 1 line
2.56.0