drm/amdkfd: always resume_all after suspend_all
Subsystems (3)
PATCH v2 1/42 drm/amdkfd: always resume_all after suspend_all
From: Alex Deucher <[email protected]>
Need to restore any good queues even if the suspend_all failed for some. Always run remove_queue as that will schedule a GPU reset is removing the queue fails.
v2: move resume_all after remove
--- .../drm/amd/amdkfd/kfd_device_queue_manager.c | 20 ++++++------------- 1 file changed, 6 insertions(+), 14 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +6 -14
@@ -3258,32 +3258,24 @@ 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) { - ret =suspend_all_queues_mes (dqm); -if (ret) { -dev_err (dev,"Suspending all queues failed" ); - goto out; - } +/* suspend all queues will save any good queues and mark the rest as bad */ +suspend_all_queues_mes (dqm); q->properties.is_evicted = true; q->properties.is_active = false;decrement_queue_count (dqm, qpd, q); +/* this will remove the bad queue and sched a GPU reset if needed */ ret =remove_queue_mes (dqm, q, qpd); -if (ret) { -dev_err (dev,"Removing bad queue failed" ); - goto out; - } - - ret =resume_all_queues_mes (dqm);if (ret) -dev_err (dev,"Resuming all queues failed" ); - +dev_err (dev,"Removing bad queue failed" ); +/* resume the good queues */ +resume_all_queues_mes (dqm);break ; } } } -out:dqm_unlock (dqm);kfd_unref_process (p);return ret;
Signature · 1 line
2.49.0
PATCH v2 2/42 drm/amdgpu: don't reemit if there is nothing to reemit
From: Alex Deucher <[email protected]>
Return early in amdgpu_ring_set_fence_errors_and_reemit() if ring_backup_entries_to_copy is 0. That means that either the ring is idle and there is nothing to reemit, or there some reason why we should reemit, so return early and signal the fences (if applicable).
--- drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +9 -0
@@ -727,6 +727,15 @@ void amdgpu_ring_set_fence_errors_and_reemit(struct amdgpu_ring *ring, last_seq =amdgpu_fence_read (ring) & ring->fence_drv.num_fences_mask; seq = ring->fence_drv.sync_seq & ring->fence_drv.num_fences_mask; +/* If there is nothing to reemit, return early and set an error on the fence +* if applicable. If all of the fences are siganlled, this will be a nop. +* if there are still fences and ring_backup_entries_to_copy is 0, then +* we are skipping it on purpose. +*/ +if (!ring->ring_backup_entries_to_copy) { +amdgpu_fence_driver_force_completion (ring, &guilty_fence->base); +return ; + } ring->reemit = true;amdgpu_ring_alloc (ring, ring->ring_backup_entries_to_copy);spin_lock_irqsave (&ring->fence_drv.lock, flags);
Signature · 1 line
2.49.0
PATCH v2 3/42 drm/amdgpu: track guilty fence for queue reset
In reply to Jesse ZhangFrom: Alex Deucher <[email protected]>
If we've already seen a fence, don't backup the ring contents since presumably either the previous reset was not successful or there was something wrong with the data.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c | 11 +++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h | 1 + 2 files changed, 12 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +11 -0
@@ -803,6 +803,17 @@ void amdgpu_ring_backup_unprocessed_commands(struct amdgpu_ring *ring, seq = ring->fence_drv.sync_seq & ring->fence_drv.num_fences_mask; ring->ring_backup_entries_to_copy =0 ; +/* if we've already seen this fence, return early. +* ring->ring_backup_entries_to_copy is set to 0 so +* the reemit helper will return early as well to +* avoid getting stuck in a reemit loop. +*/ +if (ring->guilty_fence == guilty_fence) { + ring->guilty_fence =NULL ; +return ; + } + ring->guilty_fence = guilty_fence; + do { last_seq++; last_seq &= ring->fence_drv.num_fences_mask;
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h +1 -0
@@ -314,6 +314,7 @@ struct amdgpu_ring {uint32_t *ring_backup;unsigned int ring_backup_entries_to_copy;bool reemit; +struct amdgpu_fence *guilty_fence;unsigned rptr_offs;u64 rptr_gpu_addr;u32 *rptr_cpu_addr;
Signature · 1 line
2.49.0
PATCH v2 4/42 drm/amdgpu/fence: add helper to extract the guilty fence
In reply to Jesse ZhangFrom: Alex Deucher <[email protected]>
Add a helper to extract the first amdgpu_fence which has not yet signalled and is thus guilty or at least collateral damage.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c | 31 +++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h | 2 ++ 2 files changed, 33 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +31 -0
@@ -831,6 +831,37 @@ void amdgpu_ring_backup_unprocessed_commands(struct amdgpu_ring *ring, }while (last_seq != seq); } +struct amdgpu_fence * +amdgpu_ring_find_guilty_fence (struct amdgpu_ring *ring) +{ +struct dma_fence *unprocessed; +struct dma_fence __rcu **ptr; +struct amdgpu_fence *fence; +u32 seq, last_seq; + + last_seq =amdgpu_fence_read (ring) & ring->fence_drv.num_fences_mask; + seq = ring->fence_drv.sync_seq & ring->fence_drv.num_fences_mask; + ring->ring_backup_entries_to_copy =0 ; + +do { + last_seq++; + last_seq &= ring->fence_drv.num_fences_mask; + + ptr = &ring->fence_drv.fences[last_seq]; +rcu_read_lock (); + unprocessed =rcu_dereference (*ptr); + +if (unprocessed && !dma_fence_is_signaled (unprocessed)) { + fence = container_of(unprocessed, struct amdgpu_fence, base); +rcu_read_unlock (); +return fence; + } +rcu_read_unlock (); + }while (last_seq != seq); + +return NULL ; +} +/* * Common fence implementation */
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h +2 -0
@@ -589,6 +589,8 @@ int amdgpu_ib_ring_tests(struct amdgpu_device *adev);bool amdgpu_ring_sched_ready (struct amdgpu_ring *ring);void amdgpu_ring_backup_unprocessed_commands (struct amdgpu_ring *ring,struct amdgpu_fence *guilty_fence); +struct amdgpu_fence * +amdgpu_ring_find_guilty_fence (struct amdgpu_ring *ring);void amdgpu_ring_reset_helper_begin (struct amdgpu_ring *ring,struct amdgpu_fence *guilty_fence); int amdgpu_ring_reset_helper_end(struct amdgpu_ring *ring,
Signature · 1 line
2.49.0
PATCH v2 5/42 drm/amdgpu: amdgpu_ring_set_fence_errors_and_reemit() handle NULL fence
In reply to Jesse ZhangFrom: Alex Deucher <[email protected]>
All the guilty fence parameter to be NULL. Will be needed for future functionality.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +2 -1
@@ -750,7 +750,8 @@ void amdgpu_ring_set_fence_errors_and_reemit(struct amdgpu_ring *ring,if (unprocessed && !dma_fence_is_signaled_locked (unprocessed)) { fence = container_of(unprocessed, struct amdgpu_fence, base); is_guilty_fence = fence == guilty_fence; - is_guilty_context = fence->context == guilty_fence->context; + is_guilty_context = guilty_fence ? + (fence->context == guilty_fence->context) : false;/* mark all fences from the guilty context with an error */ if (is_guilty_fence)
Signature · 1 line
2.49.0
PATCH v2 6/42 drm/amdgpu/vcn: handle pipe reset more gracefully
In reply to Jesse ZhangFrom: Alex Deucher <[email protected]>
Save any unprocessed work in the queues using the
new ring helper.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c | 64 +++++++++++++++---------- 1 file changed, 40 insertions(+), 24 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +40 -24
@@ -1485,6 +1485,37 @@ int vcn_set_powergating_state(struct amdgpu_ip_block *ip_block,return ret; } +static struct amdgpu_fence * +amdgpu_vcn_ring_reset_begin_helper (struct amdgpu_ring *ring, +struct amdgpu_ring *guilty_ring, +struct amdgpu_fence *timedout_fence) +{ +struct amdgpu_fence *fence; + +drm_sched_wqueue_stop (&ring->sched); +if (ring == guilty_ring) + fence = timedout_fence; +else + fence =amdgpu_ring_find_guilty_fence (ring); +amdgpu_ring_reset_helper_begin (ring, fence); + +return fence; +} + +static int +amdgpu_vcn_ring_reset_end_helper (struct amdgpu_ring *ring, +struct amdgpu_fence *fence) +{ +int r; + + r =amdgpu_ring_reset_helper_end (ring, fence); +if (r) +return r; + +drm_sched_wqueue_start (&ring->sched); +return 0 ; +} +/** * amdgpu_vcn_ring_reset - Reset a VCN ring * @ring: ring to reset
@@ -1502,48 +1533,33 @@ int amdgpu_vcn_ring_reset(struct amdgpu_ring *ring, {struct amdgpu_device *adev = ring->adev;struct amdgpu_vcn_inst *vinst = &adev->vcn.inst[ring->me]; +struct amdgpu_fence *dec_fence; +struct amdgpu_fence *enc_fence[AMDGPU_VCN_MAX_ENC_RINGS ];int r, i;if (adev->vcn.inst[ring->me].using_unified_queue)return -EINVAL ;mutex_lock (&vinst->engine_reset_mutex); -/* Stop the scheduler's work queue for the dec and enc rings if they are running. -* This ensures that no new tasks are submitted to the queues while -* the reset is in progress. -*/ -drm_sched_wqueue_stop (&vinst->ring_dec.sched); + dec_fence =amdgpu_vcn_ring_reset_begin_helper (&vinst->ring_dec, ring, + timedout_fence);for (i =0 ; i < vinst->num_enc_rings; i++) -drm_sched_wqueue_stop (&vinst->ring_enc[i].sched); + enc_fence[i] =amdgpu_vcn_ring_reset_begin_helper (&vinst->ring_enc[i], ring, + timedout_fence);/* Perform the VCN reset for the specified instance */ r = vinst->reset (vinst);if (r) goto unlock; - r =amdgpu_ring_test_ring (&vinst->ring_dec); + + r =amdgpu_vcn_ring_reset_end_helper (&vinst->ring_dec, dec_fence);if (r) goto unlock;for (i =0 ; i < vinst->num_enc_rings; i++) { - r =amdgpu_ring_test_ring (&vinst->ring_enc[i]); + r =amdgpu_vcn_ring_reset_end_helper (&vinst->ring_enc[i], enc_fence[i]);if (r) goto unlock; } -amdgpu_fence_driver_force_completion (&vinst->ring_dec, - (&vinst->ring_dec == ring) ? - &timedout_fence->base :NULL ); -for (i =0 ; i < vinst->num_enc_rings; i++) -amdgpu_fence_driver_force_completion (&vinst->ring_enc[i], - (&vinst->ring_enc[i] == ring) ? - &timedout_fence->base :NULL ); - -/* Restart the scheduler's work queue for the dec and enc rings -* if they were stopped by this function. This allows new tasks -* to be submitted to the queues after the reset is complete. -*/ -drm_sched_wqueue_start (&vinst->ring_dec.sched); -for (i =0 ; i < vinst->num_enc_rings; i++) -drm_sched_wqueue_start (&vinst->ring_enc[i].sched); - unlock:mutex_unlock (&vinst->engine_reset_mutex);
Signature · 1 line
2.49.0
PATCH v2 7/42 drm/amdgpu/sdma: handle pipe reset more gracefully
In reply to Jesse ZhangFrom: Alex Deucher <[email protected]>
Save any unprocessed work in the queues using the
new ring helper.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +15 -4
@@ -553,10 +553,11 @@ static int amdgpu_sdma_soft_reset(struct amdgpu_device *adev, u32 instance_id)int amdgpu_sdma_reset_engine (struct amdgpu_device *adev,uint32_t instance_id,bool caller_handles_kernel_queues) { -int ret =0 ;struct amdgpu_sdma_instance *sdma_instance = &adev->sdma.instance[instance_id];struct amdgpu_ring *gfx_ring = &sdma_instance->ring;struct amdgpu_ring *page_ring = &sdma_instance->page; +struct amdgpu_fence *gfx_fence, *page_fence; +int ret =0 ;if (amdgpu_sriov_vf (adev))return -EOPNOTSUPP ;
@@ -569,9 +570,14 @@ int amdgpu_sdma_reset_engine(struct amdgpu_device *adev, uint32_t instance_id,* the reset is in progress. */ drm_sched_wqueue_stop (&gfx_ring->sched); + gfx_fence =amdgpu_ring_find_guilty_fence (gfx_ring); +amdgpu_ring_reset_helper_begin (gfx_ring, gfx_fence); -if (adev->sdma.has_page_queue) +if (adev->sdma.has_page_queue) {drm_sched_wqueue_stop (&page_ring->sched); + page_fence =amdgpu_ring_find_guilty_fence (page_ring); +amdgpu_ring_reset_helper_begin (page_ring, page_fence); + } }if (sdma_instance->funcs->stop_kernel_queue) {
@@ -600,14 +606,19 @@ int amdgpu_sdma_reset_engine(struct amdgpu_device *adev, uint32_t instance_id,* to be submitted to the queues after the reset is complete. */ if (!ret) { -amdgpu_fence_driver_force_completion (gfx_ring,NULL ); + ret =amdgpu_ring_reset_helper_end (gfx_ring, gfx_fence); +if (ret) + goto unlock;drm_sched_wqueue_start (&gfx_ring->sched);if (adev->sdma.has_page_queue) { -amdgpu_fence_driver_force_completion (page_ring,NULL ); + ret =amdgpu_ring_reset_helper_end (page_ring, page_fence); +if (ret) + goto unlock;drm_sched_wqueue_start (&page_ring->sched); } } } +unlock:mutex_unlock (&sdma_instance->engine_reset_mutex);return ret;
Signature · 1 line
2.49.0
PATCH v2 8/42 drm/amdgpu/mes12: use proper grbm_select function
In reply to Jesse ZhangFrom: Alex Deucher <[email protected]>
s/soc21_grbm_select/soc24_grbm_select/
No functional difference as the register offsets are the same.
--- drivers/gpu/drm/amd/amdgpu/mes_v12_0.c | 34 +++++++++++++------------- 1 file changed, 17 insertions(+), 17 deletions(-)
drivers/gpu/drm/amd/amdgpu/mes_v12_0.c +17 -17
@@ -26,7 +26,7 @@#include "amdgpu.h" #include "gfx_v12_0.h" #include "soc15_common.h" -#include "soc21.h" +#include "soc24.h" #include "gc/gc_12_0_0_offset.h" #include "gc/gc_12_0_0_sh_mask.h" #include "gc/gc_11_0_0_default.h"
@@ -442,7 +442,7 @@ static int mes_v12_0_reset_queue_mmio(struct amdgpu_mes *mes, uint32_t queue_typmutex_unlock (&adev->gfx.reset_sem_mutex);mutex_lock (&adev->srbm_mutex); -soc21_grbm_select (adev, me_id, pipe_id, queue_id,0 ); +soc24_grbm_select (adev, me_id, pipe_id, queue_id,0 );/* wait till dequeue take effects */ for (i =0 ; i < adev->usec_timeout; i++) {if (!(RREG32_SOC15 (GC ,0 , regCP_GFX_HQD_ACTIVE) &1 ))
@@ -454,13 +454,13 @@ static int mes_v12_0_reset_queue_mmio(struct amdgpu_mes *mes, uint32_t queue_typ r = -ETIMEDOUT ; } -soc21_grbm_select (adev,0 ,0 ,0 ,0 ); +soc24_grbm_select (adev,0 ,0 ,0 ,0 );mutex_unlock (&adev->srbm_mutex); }else if (queue_type ==AMDGPU_RING_TYPE_COMPUTE ) {dev_info (adev->dev,"reset compute queue (%d:%d:%d)\n" , me_id, pipe_id, queue_id);mutex_lock (&adev->srbm_mutex); -soc21_grbm_select (adev, me_id, pipe_id, queue_id,0 ); +soc24_grbm_select (adev, me_id, pipe_id, queue_id,0 );WREG32_SOC15 (GC ,0 , regCP_HQD_DEQUEUE_REQUEST,0x2 );WREG32_SOC15 (GC ,0 , regSPI_COMPUTE_QUEUE_RESET,0x1 );
@@ -474,7 +474,7 @@ static int mes_v12_0_reset_queue_mmio(struct amdgpu_mes *mes, uint32_t queue_typdev_err (adev->dev,"failed to wait on hqd deactivate\n" ); r = -ETIMEDOUT ; } -soc21_grbm_select (adev,0 ,0 ,0 ,0 ); +soc24_grbm_select (adev,0 ,0 ,0 ,0 );mutex_unlock (&adev->srbm_mutex); }else if (queue_type ==AMDGPU_RING_TYPE_SDMA ) { dev_info(adev->dev, "reset sdma queue (%d:%d:%d)\n",
@@ -1092,7 +1092,7 @@ static void mes_v12_0_enable(struct amdgpu_device *adev, bool enable)if (enable) {mutex_lock (&adev->srbm_mutex);for (pipe =0 ; pipe <AMDGPU_MAX_MES_PIPES ; pipe++) { -soc21_grbm_select (adev,3 , pipe,0 ,0 ); +soc24_grbm_select (adev,3 , pipe,0 ,0 );if (amdgpu_mes_log_enable) {u32 log_size =AMDGPU_MES_LOG_BUFFER_SIZE +AMDGPU_MES_MSCRATCH_SIZE ;/* In case uni mes is not enabled, only program for pipe 0 */
@@ -1131,7 +1131,7 @@ static void mes_v12_0_enable(struct amdgpu_device *adev, bool enable)WREG32_SOC15 (GC ,0 , regCP_MES_CNTL, data); } -soc21_grbm_select (adev,0 ,0 ,0 ,0 ); +soc24_grbm_select (adev,0 ,0 ,0 ,0 );mutex_unlock (&adev->srbm_mutex);if (amdgpu_emu_mode)
@@ -1163,7 +1163,7 @@ static void mes_v12_0_set_ucode_start_addr(struct amdgpu_device *adev)mutex_lock (&adev->srbm_mutex);for (pipe =0 ; pipe <AMDGPU_MAX_MES_PIPES ; pipe++) {/* me=3, queue=0 */ -soc21_grbm_select (adev,3 , pipe,0 ,0 ); +soc24_grbm_select (adev,3 , pipe,0 ,0 );/* set ucode start address */ ucode_addr = adev->mes.uc_start_addr[pipe] >>2 ;
@@ -1172,7 +1172,7 @@ static void mes_v12_0_set_ucode_start_addr(struct amdgpu_device *adev)WREG32_SOC15 (GC ,0 , regCP_MES_PRGRM_CNTR_START_HI,upper_32_bits (ucode_addr)); -soc21_grbm_select (adev,0 ,0 ,0 ,0 ); +soc24_grbm_select (adev,0 ,0 ,0 ,0 ); }mutex_unlock (&adev->srbm_mutex); }
@@ -1201,7 +1201,7 @@ static int mes_v12_0_load_microcode(struct amdgpu_device *adev,mutex_lock (&adev->srbm_mutex);/* me=3, pipe=0, queue=0 */ -soc21_grbm_select (adev,3 , pipe,0 ,0 ); +soc24_grbm_select (adev,3 , pipe,0 ,0 );WREG32_SOC15 (GC ,0 , regCP_MES_IC_BASE_CNTL,0 );
@@ -1236,7 +1236,7 @@ static int mes_v12_0_load_microcode(struct amdgpu_device *adev,WREG32_SOC15 (GC ,0 , regCP_MES_IC_OP_CNTL, data); } -soc21_grbm_select (adev,0 ,0 ,0 ,0 ); +soc24_grbm_select (adev,0 ,0 ,0 ,0 );mutex_unlock (&adev->srbm_mutex);return 0 ;
@@ -1383,7 +1383,7 @@ static void mes_v12_0_queue_init_register(struct amdgpu_ring *ring)uint32_t data =0 ;mutex_lock (&adev->srbm_mutex); -soc21_grbm_select (adev,3 , ring->pipe,0 ,0 ); +soc24_grbm_select (adev,3 , ring->pipe,0 ,0 );/* set CP_HQD_VMID.VMID = 0. */ data =RREG32_SOC15 (GC ,0 , regCP_HQD_VMID);
@@ -1434,7 +1434,7 @@ static void mes_v12_0_queue_init_register(struct amdgpu_ring *ring)/* set CP_HQD_ACTIVE.ACTIVE=1 */ WREG32_SOC15 (GC ,0 , regCP_HQD_ACTIVE, mqd->cp_hqd_active); -soc21_grbm_select (adev,0 ,0 ,0 ,0 ); +soc24_grbm_select (adev,0 ,0 ,0 ,0 );mutex_unlock (&adev->srbm_mutex); }
@@ -1500,14 +1500,14 @@ static int mes_v12_0_queue_init(struct amdgpu_device *adev, ((pipe == AMDGPU_MES_KIQ_PIPE) && !adev->mes.kiq_version)) {/* get MES scheduler/KIQ versions */ mutex_lock (&adev->srbm_mutex); -soc21_grbm_select (adev,3 , pipe,0 ,0 ); +soc24_grbm_select (adev,3 , pipe,0 ,0 );if (pipe ==AMDGPU_MES_SCHED_PIPE ) adev->mes.sched_version =RREG32_SOC15 (GC ,0 , regCP_MES_GP3_LO);else if (pipe ==AMDGPU_MES_KIQ_PIPE && adev->enable_mes_kiq) adev->mes.kiq_version =RREG32_SOC15 (GC ,0 , regCP_MES_GP3_LO); -soc21_grbm_select (adev,0 ,0 ,0 ,0 ); +soc24_grbm_select (adev,0 ,0 ,0 ,0 );mutex_unlock (&adev->srbm_mutex); }
@@ -1695,7 +1695,7 @@ static void mes_v12_0_kiq_dequeue_sched(struct amdgpu_device *adev)int i;mutex_lock (&adev->srbm_mutex); -soc21_grbm_select (adev,3 ,AMDGPU_MES_SCHED_PIPE ,0 ,0 ); +soc24_grbm_select (adev,3 ,AMDGPU_MES_SCHED_PIPE ,0 ,0 );/* disable the queue if it's active */ if (RREG32_SOC15 (GC ,0 , regCP_HQD_ACTIVE) &1 ) {
@@ -1719,7 +1719,7 @@ static void mes_v12_0_kiq_dequeue_sched(struct amdgpu_device *adev)WREG32_SOC15 (GC ,0 , regCP_HQD_PQ_WPTR_HI,0 );WREG32_SOC15 (GC ,0 , regCP_HQD_PQ_RPTR,0 ); -soc21_grbm_select (adev,0 ,0 ,0 ,0 ); +soc24_grbm_select (adev,0 ,0 ,0 ,0 );mutex_unlock (&adev->srbm_mutex); adev->mes.ring[0 ].sched.ready = false;
Signature · 1 line
2.49.0
PATCH v2 9/42 drm/amdgpu/gfx11: only need to remap KCQs when reset via MMIO
In reply to Jesse ZhangFrom: Alex Deucher <[email protected]>
MES remaps kernels queues as part of it's reset sequence.
--- drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +13 -10
@@ -7009,11 +7009,12 @@ static int gfx_v11_0_reset_kcq(struct amdgpu_ring *ring, struct amdgpu_fence *timedout_fence) {struct amdgpu_device *adev = ring->adev; +bool use_mmio = true;int r =0 ;amdgpu_ring_reset_helper_begin (ring, timedout_fence); - r =amdgpu_mes_reset_legacy_queue (ring->adev, ring, vmid, true,0 ); + r =amdgpu_mes_reset_legacy_queue (ring->adev, ring, vmid, use_mmio,0 );if (r) {dev_warn (adev->dev,"fail(%d) to reset kcq and try pipe reset\n" , r); r =gfx_v11_0_reset_compute_pipe (ring);
@@ -7021,15 +7022,17 @@ static int gfx_v11_0_reset_kcq(struct amdgpu_ring *ring,return r; } - r =gfx_v11_0_kcq_init_queue (ring, true); -if (r) { -dev_err (adev->dev,"fail to init kcq\n" ); -return r; - } - r =amdgpu_mes_map_legacy_queue (adev, ring,0 ); -if (r) { -dev_err (adev->dev,"failed to remap kcq\n" ); -return r; +if (use_mmio) { + r =gfx_v11_0_kcq_init_queue (ring, true); +if (r) { +dev_err (adev->dev,"fail to init kcq\n" ); +return r; + } + r =amdgpu_mes_map_legacy_queue (adev, ring,0 ); +if (r) { +dev_err (adev->dev,"failed to remap kcq\n" ); +return r; + } }return amdgpu_ring_reset_helper_end (ring, timedout_fence);
Signature · 1 line
2.49.0
PATCH v2 10/42 drm/amdgpu/gfx12: only need to remap KCQs when reset via MMIO
In reply to Jesse ZhangFrom: Alex Deucher <[email protected]>
MES remaps kernels queues as part of it's reset sequence.
--- drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +13 -10
@@ -5397,11 +5397,12 @@ static int gfx_v12_0_reset_kcq(struct amdgpu_ring *ring, struct amdgpu_fence *timedout_fence) {struct amdgpu_device *adev = ring->adev; +bool use_mmio = true;int r;amdgpu_ring_reset_helper_begin (ring, timedout_fence); - r =amdgpu_mes_reset_legacy_queue (ring->adev, ring, vmid, true,0 ); + r =amdgpu_mes_reset_legacy_queue (ring->adev, ring, vmid, use_mmio,0 );if (r) {dev_warn (adev->dev,"fail(%d) to reset kcq and try pipe reset\n" , r); r =gfx_v12_0_reset_compute_pipe (ring);
@@ -5409,15 +5410,17 @@ static int gfx_v12_0_reset_kcq(struct amdgpu_ring *ring,return r; } - r =gfx_v12_0_kcq_init_queue (ring, true); -if (r) { -dev_err (adev->dev,"failed to init kcq\n" ); -return r; - } - r =amdgpu_mes_map_legacy_queue (adev, ring,0 ); -if (r) { -dev_err (adev->dev,"failed to remap kcq\n" ); -return r; +if (use_mmio) { + r =gfx_v12_0_kcq_init_queue (ring, true); +if (r) { +dev_err (adev->dev,"failed to init kcq\n" ); +return r; + } + r =amdgpu_mes_map_legacy_queue (adev, ring,0 ); +if (r) { +dev_err (adev->dev,"failed to remap kcq\n" ); +return r; + } }return amdgpu_ring_reset_helper_end (ring, timedout_fence);
Signature · 1 line
2.49.0
PATCH v2 11/42 drm/amdgpu/mes_v12_0: use mes schedule pipe for legacy queues on unified MES
In reply to Jesse Zhangwhen suspend_all_gangs is issued to pipe0 MES during system suspend or runtime PM, pipe0 can only suspend and resume queues it has tracked. KCQs registered with a non-zero pipe slot may not be correctly handled, leaving them in an inconsistent state after resume.
v3: fix the schedule pipe issue
v4: use schedule pipe for KQ resets
--- drivers/gpu/drm/amd/amdgpu/mes_v12_0.c | 27 ++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-)
drivers/gpu/drm/amd/amdgpu/mes_v12_0.c +17 -10
@@ -528,10 +528,15 @@ static int mes_v12_0_map_legacy_queue(struct amdgpu_mes *mes,convert_to_mes_queue_type (input->queue_type); mes_add_queue_pkt.map_legacy_kq =1 ; -if (mes->adev->enable_uni_mes) - pipe =AMDGPU_MES_KIQ_PIPE ; -else +if (mes->adev->enable_uni_mes) { +/* Keep scheduler queue on KIQ pipe; map all other kernel queues on sched pipe. */ +if (input->queue_type ==AMDGPU_RING_TYPE_MES ) + pipe =AMDGPU_MES_KIQ_PIPE ; +else + pipe =AMDGPU_MES_SCHED_PIPE ; + }else { pipe =AMDGPU_MES_SCHED_PIPE ; + } return mes_v12_0_submit_pkt_and_poll_completion(mes, pipe, &mes_add_queue_pkt, sizeof(mes_add_queue_pkt),
@@ -567,10 +572,15 @@ static int mes_v12_0_unmap_legacy_queue(struct amdgpu_mes *mes,convert_to_mes_queue_type (input->queue_type); } -if (mes->adev->enable_uni_mes) - pipe =AMDGPU_MES_KIQ_PIPE ; -else +if (mes->adev->enable_uni_mes) { +/* Keep scheduler queue on KIQ pipe; unmap all other kernel queues on sched pipe. */ +if (input->queue_type ==AMDGPU_RING_TYPE_MES ) + pipe =AMDGPU_MES_KIQ_PIPE ; +else + pipe =AMDGPU_MES_SCHED_PIPE ; + }else { pipe =AMDGPU_MES_SCHED_PIPE ; + } return mes_v12_0_submit_pkt_and_poll_completion(mes, pipe, &mes_remove_queue_pkt, sizeof(mes_remove_queue_pkt),
@@ -913,10 +923,7 @@ static int mes_v12_0_reset_hw_queue(struct amdgpu_mes *mes, mes_reset_queue_pkt.doorbell_offset = input->doorbell_offset; } -if (input->is_kq) - pipe =AMDGPU_MES_KIQ_PIPE ; -else - pipe =AMDGPU_MES_SCHED_PIPE ; + pipe =AMDGPU_MES_SCHED_PIPE ; return mes_v12_0_submit_pkt_and_poll_completion(mes, pipe, &mes_reset_queue_pkt, sizeof(mes_reset_queue_pkt),
Signature · 1 line
2.49.0
PATCH v2 12/42 drm/amdgpu/mes_v12_1: use mes schedule pipe for legacy queues on unified MES
In reply to Jesse Zhangwhen suspend_all_gangs is issued to pipe0 MES during system suspend or runtime PM, pipe0 can only suspend and resume queues it has tracked. KCQs registered with a non-zero pipe slot may not be correctly handled, leaving them in an inconsistent state after resume.
v3: fix the schedule pipe issue
--- drivers/gpu/drm/amd/amdgpu/mes_v12_1.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/mes_v12_1.c +16 -6
@@ -417,10 +417,15 @@ static int mes_v12_1_map_legacy_queue(struct amdgpu_mes *mes,convert_to_mes_queue_type (input->queue_type); mes_add_queue_pkt.map_legacy_kq =1 ; -if (mes->adev->enable_uni_mes) - pipe =AMDGPU_MES_KIQ_PIPE ; -else +if (mes->adev->enable_uni_mes) { +/* Keep scheduler queue on KIQ pipe; map all other kernel queues on sched pipe. */ +if (input->queue_type ==AMDGPU_RING_TYPE_MES ) + pipe =AMDGPU_MES_KIQ_PIPE ; +else + pipe =AMDGPU_MES_SCHED_PIPE ; + }else { pipe =AMDGPU_MES_SCHED_PIPE ; + } return mes_v12_1_submit_pkt_and_poll_completion(mes, input->xcc_id, pipe,
@@ -457,10 +462,15 @@ static int mes_v12_1_unmap_legacy_queue(struct amdgpu_mes *mes,convert_to_mes_queue_type (input->queue_type); } -if (mes->adev->enable_uni_mes) - pipe =AMDGPU_MES_KIQ_PIPE ; -else +if (mes->adev->enable_uni_mes) { +/* Keep scheduler queue on KIQ pipe; map all other kernel queues on sched pipe. */ +if (input->queue_type ==AMDGPU_RING_TYPE_MES ) + pipe =AMDGPU_MES_KIQ_PIPE ; +else + pipe =AMDGPU_MES_SCHED_PIPE ; + }else { pipe =AMDGPU_MES_SCHED_PIPE ; + } return mes_v12_1_submit_pkt_and_poll_completion(mes, input->xcc_id, pipe,
Signature · 1 line
2.49.0
RE: [PATCH v2 12/42] drm/amdgpu/mes_v12_1: use mes schedule pipe for legacy queues on unified MES
AMD General
Regards,
Prike
Quoted 45 lines
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Jesse Zhang
Sent: Monday, June 1, 2026 1:49 PM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Zhang, Jesse(Jie) <[email protected]>; Chen, Michael <[email protected]>; Deucher, Alexander <[email protected]>; Liu, Shaoyun <[email protected]>; Zhang, Jesse(Jie) <[email protected]>
Subject: [PATCH v2 12/42] drm/amdgpu/mes_v12_1: use mes schedule pipe for legacy queues on unified MESwhen
suspend_all_gangsis issued to pipe0 MES during system suspend or runtime PM, pipe0 can only suspend and resume queues it has tracked.
KCQs registered with a non-zero pipe slot may not be correctly handled, leaving them in an inconsistent state after resume.v3: fix the schedule pipe issue
Suggested-by Michael Chen <[email protected]>Suggested-by Alex Deucher <[email protected]>Suggested-by Shaoyun Liu <[email protected]>Signed-off-by Jesse Zhang <[email protected]>Signed-off-by Alex Deucher <[email protected]>--- drivers/gpu/drm/amd/amdgpu/mes_v12_1.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-)drivers/gpu/drm/amd/amdgpu/mes_v12_1.c +2
-3@@ -417,10 +417,15 @@ static int mes_v12_1_map_legacy_queue(struct amdgpu_mes *mes,convert_to_mes_queue_type (input->queue_type); mes_add_queue_pkt.map_legacy_kq =1 ; -if (mes->adev->enable_uni_mes) - pipe =AMDGPU_MES_KIQ_PIPE ; -else +if (mes->adev->enable_uni_mes) { +/* Keep scheduler queue on KIQ pipe; map all other kernel queues on sched pipe. */
drivers/gpu/drm/amd/amdgpu/mes_v12_1.c static int mes_v12_1_map_legacy_queue(struct amdgpu_mes *mes, · line 428
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/mes_v12_1.c +6
-0+if (input->queue_type ==AMDGPU_RING_TYPE_MES ) + pipe =AMDGPU_MES_KIQ_PIPE ; +else + pipe =AMDGPU_MES_SCHED_PIPE ; + }else { pipe =AMDGPU_MES_SCHED_PIPE ; + }
The queue scheduler pipe calculation is generic and also used in the other places like as the queue reset, so how about create a common function used for calculating the queue scheduler pipe?
Without it or not, the patch is Reviewed-by: Prike Liang <[email protected]>
Quoted 26 lines
return mes_v12_1_submit_pkt_and_poll_completion(mes, input->xcc_id, pipe,drivers/gpu/drm/amd/amdgpu/mes_v12_1.c +2
-3@@ -457,10 +462,15 @@ static int mes_v12_1_unmap_legacy_queue(struct amdgpu_mes *mes,convert_to_mes_queue_type (input->queue_type); } -if (mes->adev->enable_uni_mes) - pipe =AMDGPU_MES_KIQ_PIPE ; -else +if (mes->adev->enable_uni_mes) { +/* Keep scheduler queue on KIQ pipe; map all other kernel queues on sched pipe. */
drivers/gpu/drm/amd/amdgpu/mes_v12_1.c +6
-1+if (input->queue_type ==AMDGPU_RING_TYPE_MES ) + pipe =AMDGPU_MES_KIQ_PIPE ; +else + pipe =AMDGPU_MES_SCHED_PIPE ; + }else { pipe =AMDGPU_MES_SCHED_PIPE ; + } return mes_v12_1_submit_pkt_and_poll_completion(mes, input->xcc_id, pipe, --2.49.0
PATCH v2 13/42 drm/amdgpu/gfx11: Refactor compute pipe reset and add HQD cleanup
In reply to Jesse ZhangRefactor gfx_v11_0_reset_compute_pipe() to accept explicit me, pipe, and queue parameters instead of deriving them from the ring structure. This enables the function to be used in generic pipe reset flows.
Introduce gfx_v11_0_clear_hqds_on_mec_pipe() to properly clear CP_HQD_ACTIVE and CP_HQD_DEQUEUE_REQUEST for all queues on a given MEC pipe while the pipe reset is asserted, ensuring the HQDs are torn down correctly before deasserting reset.
Switch the KCQ reset path to use the common MEC pipe reset helper amdgpu_gfx_mec_pipe_reset_run(), which coordinates the reset sequence including KFD suspend/resume to avoid conflicts with user mode queues.
v2: just update the sequence (Alex)
v3: directly clear ACTIVE and DEQUEUE_REQUEST (Shaoyun Liu)
--- drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 166 +++++++++++++++---------- 1 file changed, 100 insertions(+), 66 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +100 -66
@@ -6874,11 +6874,39 @@ static int gfx_v11_0_reset_kgq(struct amdgpu_ring *ring,return amdgpu_ring_reset_helper_end (ring, timedout_fence); } -static int gfx_v11_0_reset_compute_pipe (struct amdgpu_ring *ring) +/* +* With MEC pipe reset asserted, clear CP_HQD_ACTIVE / CP_HQD_DEQUEUE_REQUEST for +* every queue on (me, pipe). HQDs must be torn down while pipe reset stays +* asserted; only then clear the pipe reset bit. +* Caller must hold adev->srbm_mutex. +*/ +static void gfx_v11_0_clear_hqds_on_mec_pipe (struct amdgpu_device *adev,u32 me, +u32 pipe) { +unsigned int q; +int j; -struct amdgpu_device *adev = ring->adev; -uint32_t reset_pipe =0 , clean_pipe =0 ; +for (q =0 ; q < adev->gfx.mec.num_queue_per_pipe; q++) { +soc21_grbm_select (adev, me, pipe, q,0 ); +/* Start from a clean HQD dequeue state before forcing HQD inactive. */ +WREG32_SOC15 (GC ,0 , regCP_HQD_ACTIVE,0 ); +if (RREG32_SOC15 (GC ,0 , regCP_HQD_ACTIVE) &1 ) { +WREG32_SOC15 (GC ,0 , regCP_HQD_DEQUEUE_REQUEST,1 ); +for (j =0 ; j < adev->usec_timeout; j++) { +if (!(RREG32_SOC15 (GC ,0 , regCP_HQD_ACTIVE) &1 )) +break ; +udelay (1 ); + } + } + +WREG32_SOC15 (GC ,0 , regCP_HQD_DEQUEUE_REQUEST,0 ); + } +} + +static int gfx_v11_0_reset_compute_pipe (struct amdgpu_device *adev, +u32 me,u32 pipe,u32 queue) +{ +uint32_t reset_val, clean_val;int r;if (!gfx_v11_pipe_reset_support (adev))
@@ -6886,109 +6914,115 @@ static int gfx_v11_0_reset_compute_pipe(struct amdgpu_ring *ring)gfx_v11_0_set_safe_mode (adev,0 );mutex_lock (&adev->srbm_mutex); -soc21_grbm_select (adev, ring->me, ring->pipe, ring->queue,0 ); - - reset_pipe =RREG32_SOC15 (GC ,0 , regCP_MEC_RS64_CNTL); - clean_pipe = reset_pipe; +soc21_grbm_select (adev, me, pipe, queue,0 );if (adev->gfx.rs64_enable) { + reset_val =RREG32_SOC15 (GC ,0 , regCP_MEC_RS64_CNTL); + clean_val = reset_val; -switch (ring->pipe) { +switch (pipe) {case 0 : - reset_pipe =REG_SET_FIELD (reset_pipe,CP_MEC_RS64_CNTL , -MEC_PIPE0_RESET ,1 ); - clean_pipe =REG_SET_FIELD (clean_pipe,CP_MEC_RS64_CNTL , -MEC_PIPE0_RESET ,0 ); + reset_val =REG_SET_FIELD (reset_val,CP_MEC_RS64_CNTL , +MEC_PIPE0_RESET ,1 ); + clean_val =REG_SET_FIELD (clean_val,CP_MEC_RS64_CNTL , +MEC_PIPE0_RESET ,0 );break ;case 1 : - reset_pipe =REG_SET_FIELD (reset_pipe,CP_MEC_RS64_CNTL , -MEC_PIPE1_RESET ,1 ); - clean_pipe =REG_SET_FIELD (clean_pipe,CP_MEC_RS64_CNTL , -MEC_PIPE1_RESET ,0 ); + reset_val =REG_SET_FIELD (reset_val,CP_MEC_RS64_CNTL , +MEC_PIPE1_RESET ,1 ); + clean_val =REG_SET_FIELD (clean_val,CP_MEC_RS64_CNTL , +MEC_PIPE1_RESET ,0 );break ;case 2 : - reset_pipe =REG_SET_FIELD (reset_pipe,CP_MEC_RS64_CNTL , -MEC_PIPE2_RESET ,1 ); - clean_pipe =REG_SET_FIELD (clean_pipe,CP_MEC_RS64_CNTL , -MEC_PIPE2_RESET ,0 ); + reset_val =REG_SET_FIELD (reset_val,CP_MEC_RS64_CNTL , +MEC_PIPE2_RESET ,1 ); + clean_val =REG_SET_FIELD (clean_val,CP_MEC_RS64_CNTL , +MEC_PIPE2_RESET ,0 );break ;case 3 : - reset_pipe =REG_SET_FIELD (reset_pipe,CP_MEC_RS64_CNTL , -MEC_PIPE3_RESET ,1 ); - clean_pipe =REG_SET_FIELD (clean_pipe,CP_MEC_RS64_CNTL , -MEC_PIPE3_RESET ,0 ); + reset_val =REG_SET_FIELD (reset_val,CP_MEC_RS64_CNTL , +MEC_PIPE3_RESET ,1 ); + clean_val =REG_SET_FIELD (clean_val,CP_MEC_RS64_CNTL , +MEC_PIPE3_RESET ,0 );break ;default :break ; } -WREG32_SOC15 (GC ,0 , regCP_MEC_RS64_CNTL, reset_pipe); -WREG32_SOC15 (GC ,0 , regCP_MEC_RS64_CNTL, clean_pipe); +WREG32_SOC15 (GC ,0 , regCP_MEC_RS64_CNTL, reset_val); +gfx_v11_0_clear_hqds_on_mec_pipe (adev, me, pipe); +soc21_grbm_select (adev, me, pipe, queue,0 ); +WREG32_SOC15 (GC ,0 , regCP_MEC_RS64_CNTL, clean_val); r = (RREG32_SOC15 (GC ,0 , regCP_MEC_RS64_INSTR_PNTR) <<2 ) -RS64_FW_UC_START_ADDR_LO ; }else { -if (ring->me ==1 ) { -switch (ring->pipe) { + reset_val =RREG32_SOC15 (GC ,0 , regCP_MEC_CNTL); + clean_val = reset_val; + +if (me ==1 ) { +switch (pipe) {case 0 : - reset_pipe =REG_SET_FIELD (reset_pipe,CP_MEC_CNTL , -MEC_ME1_PIPE0_RESET ,1 ); - clean_pipe =REG_SET_FIELD (clean_pipe,CP_MEC_CNTL , -MEC_ME1_PIPE0_RESET ,0 ); + reset_val =REG_SET_FIELD (reset_val,CP_MEC_CNTL , +MEC_ME1_PIPE0_RESET ,1 ); + clean_val =REG_SET_FIELD (clean_val,CP_MEC_CNTL , +MEC_ME1_PIPE0_RESET ,0 );break ;case 1 : - reset_pipe =REG_SET_FIELD (reset_pipe,CP_MEC_CNTL , -MEC_ME1_PIPE1_RESET ,1 ); - clean_pipe =REG_SET_FIELD (clean_pipe,CP_MEC_CNTL , -MEC_ME1_PIPE1_RESET ,0 ); + reset_val =REG_SET_FIELD (reset_val,CP_MEC_CNTL , +MEC_ME1_PIPE1_RESET ,1 ); + clean_val =REG_SET_FIELD (clean_val,CP_MEC_CNTL , +MEC_ME1_PIPE1_RESET ,0 );break ;case 2 : - reset_pipe =REG_SET_FIELD (reset_pipe,CP_MEC_CNTL , -MEC_ME1_PIPE2_RESET ,1 ); - clean_pipe =REG_SET_FIELD (clean_pipe,CP_MEC_CNTL , -MEC_ME1_PIPE2_RESET ,0 ); + reset_val =REG_SET_FIELD (reset_val,CP_MEC_CNTL , +MEC_ME1_PIPE2_RESET ,1 ); + clean_val =REG_SET_FIELD (clean_val,CP_MEC_CNTL , +MEC_ME1_PIPE2_RESET ,0 );break ;case 3 : - reset_pipe =REG_SET_FIELD (reset_pipe,CP_MEC_CNTL , -MEC_ME1_PIPE3_RESET ,1 ); - clean_pipe =REG_SET_FIELD (clean_pipe,CP_MEC_CNTL , -MEC_ME1_PIPE3_RESET ,0 ); + reset_val =REG_SET_FIELD (reset_val,CP_MEC_CNTL , +MEC_ME1_PIPE3_RESET ,1 ); + clean_val =REG_SET_FIELD (clean_val,CP_MEC_CNTL , +MEC_ME1_PIPE3_RESET ,0 );break ;default :break ; }/* mec1 fw pc: CP_MEC1_INSTR_PNTR */ }else { -switch (ring->pipe) { +switch (pipe) {case 0 : - reset_pipe =REG_SET_FIELD (reset_pipe,CP_MEC_CNTL , -MEC_ME2_PIPE0_RESET ,1 ); - clean_pipe =REG_SET_FIELD (clean_pipe,CP_MEC_CNTL , -MEC_ME2_PIPE0_RESET ,0 ); + reset_val =REG_SET_FIELD (reset_val,CP_MEC_CNTL , +MEC_ME2_PIPE0_RESET ,1 ); + clean_val =REG_SET_FIELD (clean_val,CP_MEC_CNTL , +MEC_ME2_PIPE0_RESET ,0 );break ;case 1 : - reset_pipe =REG_SET_FIELD (reset_pipe,CP_MEC_CNTL , -MEC_ME2_PIPE1_RESET ,1 ); - clean_pipe =REG_SET_FIELD (clean_pipe,CP_MEC_CNTL , -MEC_ME2_PIPE1_RESET ,0 ); + reset_val =REG_SET_FIELD (reset_val,CP_MEC_CNTL , +MEC_ME2_PIPE1_RESET ,1 ); + clean_val =REG_SET_FIELD (clean_val,CP_MEC_CNTL , +MEC_ME2_PIPE1_RESET ,0 );break ;case 2 : - reset_pipe =REG_SET_FIELD (reset_pipe,CP_MEC_CNTL , -MEC_ME2_PIPE2_RESET ,1 ); - clean_pipe =REG_SET_FIELD (clean_pipe,CP_MEC_CNTL , -MEC_ME2_PIPE2_RESET ,0 ); + reset_val =REG_SET_FIELD (reset_val,CP_MEC_CNTL , +MEC_ME2_PIPE2_RESET ,1 ); + clean_val =REG_SET_FIELD (clean_val,CP_MEC_CNTL , +MEC_ME2_PIPE2_RESET ,0 );break ;case 3 : - reset_pipe =REG_SET_FIELD (reset_pipe,CP_MEC_CNTL , -MEC_ME2_PIPE3_RESET ,1 ); - clean_pipe =REG_SET_FIELD (clean_pipe,CP_MEC_CNTL , -MEC_ME2_PIPE3_RESET ,0 ); + reset_val =REG_SET_FIELD (reset_val,CP_MEC_CNTL , +MEC_ME2_PIPE3_RESET ,1 ); + clean_val =REG_SET_FIELD (clean_val,CP_MEC_CNTL , +MEC_ME2_PIPE3_RESET ,0 );break ;default :break ; }/* mec2 fw pc: CP:CP_MEC2_INSTR_PNTR */ } -WREG32_SOC15 (GC ,0 , regCP_MEC_CNTL, reset_pipe); -WREG32_SOC15 (GC ,0 , regCP_MEC_CNTL, clean_pipe); +WREG32_SOC15 (GC ,0 , regCP_MEC_CNTL, reset_val); +gfx_v11_0_clear_hqds_on_mec_pipe (adev, me, pipe); +soc21_grbm_select (adev, me, pipe, queue,0 ); +WREG32_SOC15 (GC ,0 , regCP_MEC_CNTL, clean_val); r =RREG32 (SOC15_REG_OFFSET (GC ,0 , regCP_MEC1_INSTR_PNTR)); }
@@ -6996,8 +7030,8 @@ static int gfx_v11_0_reset_compute_pipe(struct amdgpu_ring *ring)mutex_unlock (&adev->srbm_mutex);gfx_v11_0_unset_safe_mode (adev,0 ); -dev_info (adev->dev,"The ring %s pipe resets to MEC FW start PC: %s\n" , ring->name, - r ==0 ?"successfully" :"failed" ); +dev_dbg (adev->dev,"MEC pipe me%u pipe%u queue%u resets to MEC FW start PC: %s\n" , + me, pipe, queue, r ==0 ?"successfully" :"failed" );/*FIXME:Sometimes driver can't cache the MEC firmware start PC correctly, so the pipe * reset status relies on the compute ring test result. */
@@ -7017,7 +7051,7 @@ static int gfx_v11_0_reset_kcq(struct amdgpu_ring *ring, r =amdgpu_mes_reset_legacy_queue (ring->adev, ring, vmid, use_mmio,0 );if (r) {dev_warn (adev->dev,"fail(%d) to reset kcq and try pipe reset\n" , r); - r =gfx_v11_0_reset_compute_pipe (ring); + r =gfx_v11_0_reset_compute_pipe (adev, ring->me, ring->pipe, ring->queue);if (r)return r; }
Signature · 1 line
2.49.0
RE: [PATCH v2 13/42] drm/amdgpu/gfx11: Refactor compute pipe reset and add HQD cleanup
AMD General
Regards,
Prike
Quoted 161 lines
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Jesse Zhang
Sent: Monday, June 1, 2026 1:49 PM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Zhang, Jesse(Jie) <[email protected]>; Rastogi, Manu <[email protected]>; Deucher, Alexander <[email protected]>; Zhang, Jesse(Jie) <[email protected]>
Subject: [PATCH v2 13/42] drm/amdgpu/gfx11: Refactor compute pipe reset and add HQD cleanupRefactor
gfx_v11_0_reset_compute_pipe()to accept explicit me, pipe, and queue parameters instead of deriving them from the ring structure. This enables the function to be used in generic pipe reset flows.Introduce
gfx_v11_0_clear_hqds_on_mec_pipe()to properly clearCP_HQD_ACTIVEandCP_HQD_DEQUEUE_REQUESTfor all queues on a given MEC pipe while the pipe reset is asserted, ensuring the HQDs are torn down correctly before deasserting reset.Switch the KCQ reset path to use the common MEC pipe reset helper
amdgpu_gfx_mec_pipe_reset_run(), which coordinates the reset sequence including KFD suspend/resume to avoid conflicts with user mode queues.v2: just update the sequence (Alex)
v3: directly clear ACTIVE andDEQUEUE_REQUEST(Shaoyun Liu)Suggested-by Manu Rastogi <[email protected]>Suggested-by Alex Deucher <[email protected]>Signed-off-by Jesse Zhang <[email protected]>Signed-off-by Alex Deucher <[email protected]>--- drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 166 +++++++++++++++---------- 1 file changed, 100 insertions(+), 66 deletions(-)drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +20
-3@@ -6874,11 +6874,39 @@ static int gfx_v11_0_reset_kgq(struct amdgpu_ring *ring, return amdgpu_ring_reset_helper_end(ring, timedout_fence); } -static int gfx_v11_0_reset_compute_pipe(struct amdgpu_ring *ring) +/* +* With MEC pipe reset asserted, clear CP_HQD_ACTIVE / +CP_HQD_DEQUEUE_REQUEST for +* every queue on (me, pipe). HQDs must be torn down while pipe reset +stays +* asserted; only then clear the pipe reset bit. +* Caller must hold adev->srbm_mutex. +*/ +static void gfx_v11_0_clear_hqds_on_mec_pipe (struct amdgpu_device *adev,u32 me, +u32 pipe) { +unsigned int q; +int j; -struct amdgpu_device *adev = ring->adev; -uint32_t reset_pipe = 0, clean_pipe = 0; +for (q =0 ; q < adev->gfx.mec.num_queue_per_pipe; q++) { +soc21_grbm_select (adev, me, pipe, q,0 ); +/* Start from a clean HQD dequeue state before forcing HQD inactive. */ +WREG32_SOC15 (GC ,0 , regCP_HQD_ACTIVE,0 ); +if (RREG32_SOC15 (GC ,0 , regCP_HQD_ACTIVE) &1 ) { +WREG32_SOC15 (GC ,0 , regCP_HQD_DEQUEUE_REQUEST,1 ); +for (j =0 ; j < adev->usec_timeout; j++) { + if (!(RREG32_SOC15(GC, 0, regCP_HQD_ACTIVE)& 1))
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +32
-21+break ; +udelay (1 ); + } + } + +WREG32_SOC15 (GC ,0 , regCP_HQD_DEQUEUE_REQUEST,0 ); + } +} + +static int gfx_v11_0_reset_compute_pipe (struct amdgpu_device *adev, +u32 me,u32 pipe,u32 queue) +{ +uint32_t reset_val, clean_val;int r;if (!gfx_v11_pipe_reset_support (adev))@@ -6886,109 +6914,115 @@ static int gfx_v11_0_reset_compute_pipe(struct amdgpu_ring *ring) gfx_v11_0_set_safe_mode(adev, 0);mutex_lock (&adev->srbm_mutex); -soc21_grbm_select (adev, ring->me, ring->pipe, ring->queue,0 ); - - reset_pipe =RREG32_SOC15 (GC ,0 , regCP_MEC_RS64_CNTL); - clean_pipe = reset_pipe; +soc21_grbm_select (adev, me, pipe, queue,0 );if (adev->gfx.rs64_enable) { + reset_val =RREG32_SOC15 (GC ,0 , regCP_MEC_RS64_CNTL); + clean_val = reset_val; -switch (ring->pipe) { +switch (pipe) {case 0 : - reset_pipe =REG_SET_FIELD (reset_pipe,CP_MEC_RS64_CNTL , -MEC_PIPE0_RESET ,1 ); - clean_pipe =REG_SET_FIELD (clean_pipe,CP_MEC_RS64_CNTL , -MEC_PIPE0_RESET ,0 ); + reset_val =REG_SET_FIELD (reset_val,CP_MEC_RS64_CNTL , +MEC_PIPE0_RESET ,1 ); + clean_val =REG_SET_FIELD (clean_val,CP_MEC_RS64_CNTL , +MEC_PIPE0_RESET ,0 );break ;case 1 : - reset_pipe =REG_SET_FIELD (reset_pipe,CP_MEC_RS64_CNTL , -MEC_PIPE1_RESET ,1 ); - clean_pipe =REG_SET_FIELD (clean_pipe,CP_MEC_RS64_CNTL , -MEC_PIPE1_RESET ,0 ); + reset_val =REG_SET_FIELD (reset_val,CP_MEC_RS64_CNTL , +MEC_PIPE1_RESET ,1 ); + clean_val =REG_SET_FIELD (clean_val,CP_MEC_RS64_CNTL , +MEC_PIPE1_RESET ,0 );break ;case 2 : - reset_pipe =REG_SET_FIELD (reset_pipe,CP_MEC_RS64_CNTL , -MEC_PIPE2_RESET ,1 ); - clean_pipe =REG_SET_FIELD (clean_pipe,CP_MEC_RS64_CNTL , -MEC_PIPE2_RESET ,0 ); + reset_val =REG_SET_FIELD (reset_val,CP_MEC_RS64_CNTL , +MEC_PIPE2_RESET ,1 ); + clean_val =REG_SET_FIELD (clean_val,CP_MEC_RS64_CNTL , +MEC_PIPE2_RESET ,0 );break ;case 3 : - reset_pipe =REG_SET_FIELD (reset_pipe,CP_MEC_RS64_CNTL , -MEC_PIPE3_RESET ,1 ); - clean_pipe =REG_SET_FIELD (clean_pipe,CP_MEC_RS64_CNTL , -MEC_PIPE3_RESET ,0 ); + reset_val =REG_SET_FIELD (reset_val,CP_MEC_RS64_CNTL , +MEC_PIPE3_RESET ,1 ); + clean_val = REG_SET_FIELD(clean_val, CP_MEC_RS64_CNTL,
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c static int gfx_v11_0_reset_compute_pipe(struct · line 6970
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +4
-2+ MEC_PIPE3_RESET, 0);break ;default :break ; } -WREG32_SOC15 (GC ,0 , regCP_MEC_RS64_CNTL, reset_pipe); -WREG32_SOC15 (GC ,0 , regCP_MEC_RS64_CNTL, clean_pipe); +WREG32_SOC15 (GC ,0 , regCP_MEC_RS64_CNTL, reset_val); +gfx_v11_0_clear_hqds_on_mec_pipe (adev, me, pipe); +soc21_grbm_select (adev, me, pipe, queue,0 );
The regCP_MEC_RS64_CNTL seems to be a global register rather than per-queue register, so here we can remove the queue select both here and some other similar places. Meanwhile, gfx_v11_0_clear_hqds_on_mec_pipe() is necessary to select the queue first, but need to unselect the queue at the end of queue setting.
With that fix, the patch is Reviewed-by: Prike Liang <[email protected]>
Quoted 205 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +1
-0+WREG32_SOC15 (GC ,0 , regCP_MEC_RS64_CNTL, clean_val); r = (RREG32_SOC15(GC, 0, regCP_MEC_RS64_INSTR_PNTR) <<2) -
RS64_FW_UC_START_ADDR_LO; } else {drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +5
-3-if (ring->me ==1 ) { -switch (ring->pipe) { + reset_val =RREG32_SOC15 (GC ,0 , regCP_MEC_CNTL); + clean_val = reset_val; + +if (me ==1 ) { +switch (pipe) {case 0 : - reset_pipe = REG_SET_FIELD(reset_pipe,
CP_MEC_CNTL,
-MEC_ME1_PIPE0_RESET,
1);
-clean_pipe= REG_SET_FIELD(clean_pipe,CP_MEC_CNTL,
-MEC_ME1_PIPE0_RESET,
0);
+reset_val= REG_SET_FIELD(reset_val,CP_MEC_CNTL,
+MEC_ME1_PIPE0_RESET,
1);
+clean_val= REG_SET_FIELD(clean_val,CP_MEC_CNTL,
+MEC_ME1_PIPE0_RESET,0); break; case 1:-
reset_pipe= REG_SET_FIELD(reset_pipe,CP_MEC_CNTL,
-MEC_ME1_PIPE1_RESET,
1);
-clean_pipe= REG_SET_FIELD(clean_pipe,CP_MEC_CNTL,
-MEC_ME1_PIPE1_RESET,
0);
+reset_val= REG_SET_FIELD(reset_val,CP_MEC_CNTL,
+MEC_ME1_PIPE1_RESET,
1);
+clean_val= REG_SET_FIELD(clean_val,CP_MEC_CNTL,
+MEC_ME1_PIPE1_RESET,0); break; case 2:-
reset_pipe= REG_SET_FIELD(reset_pipe,CP_MEC_CNTL,
-MEC_ME1_PIPE2_RESET,
1);
-clean_pipe= REG_SET_FIELD(clean_pipe,CP_MEC_CNTL,
-MEC_ME1_PIPE2_RESET,
0);
+reset_val= REG_SET_FIELD(reset_val,CP_MEC_CNTL,
+MEC_ME1_PIPE2_RESET,
1);
+clean_val= REG_SET_FIELD(clean_val,CP_MEC_CNTL,
+MEC_ME1_PIPE2_RESET,0); break; case 3:-
reset_pipe= REG_SET_FIELD(reset_pipe,CP_MEC_CNTL,
-MEC_ME1_PIPE3_RESET,
1);
-clean_pipe= REG_SET_FIELD(clean_pipe,CP_MEC_CNTL,
-MEC_ME1_PIPE3_RESET,
0);
+reset_val= REG_SET_FIELD(reset_val,CP_MEC_CNTL,
+MEC_ME1_PIPE3_RESET,
1);
+clean_val= REG_SET_FIELD(clean_val,CP_MEC_CNTL,
+MEC_ME1_PIPE3_RESET,0); break; default: break; } /* mec1 fw pc: CP_MEC1_INSTR_PNTR */ } else {drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +1
-2-switch (ring->pipe) { +switch (pipe) {case 0 : - reset_pipe = REG_SET_FIELD(reset_pipe,
CP_MEC_CNTL,
-MEC_ME2_PIPE0_RESET,
1);
-clean_pipe= REG_SET_FIELD(clean_pipe,CP_MEC_CNTL,
-MEC_ME2_PIPE0_RESET,
0);
+reset_val= REG_SET_FIELD(reset_val,CP_MEC_CNTL,
+MEC_ME2_PIPE0_RESET,
1);
+clean_val= REG_SET_FIELD(clean_val,CP_MEC_CNTL,
+MEC_ME2_PIPE0_RESET,0); break; case 1:-
reset_pipe= REG_SET_FIELD(reset_pipe,CP_MEC_CNTL,
-MEC_ME2_PIPE1_RESET,
1);
-clean_pipe= REG_SET_FIELD(clean_pipe,CP_MEC_CNTL,
-MEC_ME2_PIPE1_RESET,
0);
+reset_val= REG_SET_FIELD(reset_val,CP_MEC_CNTL,
+MEC_ME2_PIPE1_RESET,
1);
+clean_val= REG_SET_FIELD(clean_val,CP_MEC_CNTL,
+MEC_ME2_PIPE1_RESET,0); break; case 2:-
reset_pipe= REG_SET_FIELD(reset_pipe,CP_MEC_CNTL,
-MEC_ME2_PIPE2_RESET,
1);
-clean_pipe= REG_SET_FIELD(clean_pipe,CP_MEC_CNTL,
-MEC_ME2_PIPE2_RESET,
0);
+reset_val= REG_SET_FIELD(reset_val,CP_MEC_CNTL,
+MEC_ME2_PIPE2_RESET,
1);
+clean_val= REG_SET_FIELD(clean_val,CP_MEC_CNTL,
+MEC_ME2_PIPE2_RESET,0); break; case 3:-
reset_pipe= REG_SET_FIELD(reset_pipe,CP_MEC_CNTL,
-MEC_ME2_PIPE3_RESET,
1);
-clean_pipe= REG_SET_FIELD(clean_pipe,CP_MEC_CNTL,
-MEC_ME2_PIPE3_RESET,
0);
+reset_val= REG_SET_FIELD(reset_val,CP_MEC_CNTL,
+MEC_ME2_PIPE3_RESET,
1);
+clean_val= REG_SET_FIELD(clean_val,CP_MEC_CNTL,
+MEC_ME2_PIPE3_RESET,0); break; default: break; } /* mec2 fw pc: CP:CP_MEC2_INSTR_PNTR */ }drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +4
-2-WREG32_SOC15 (GC ,0 , regCP_MEC_CNTL, reset_pipe); -WREG32_SOC15 (GC ,0 , regCP_MEC_CNTL, clean_pipe); +WREG32_SOC15 (GC ,0 , regCP_MEC_CNTL, reset_val); +gfx_v11_0_clear_hqds_on_mec_pipe (adev, me, pipe); +soc21_grbm_select (adev, me, pipe, queue,0 ); +WREG32_SOC15 (GC ,0 , regCP_MEC_CNTL, clean_val); r = RREG32(SOC15_REG_OFFSET(GC, 0,regCP_MEC1_INSTR_PNTR)); }drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +2
-2@@ -6996,8 +7030,8 @@ static int gfx_v11_0_reset_compute_pipe(struct amdgpu_ring *ring) mutex_unlock(&adev->srbm_mutex);gfx_v11_0_unset_safe_mode (adev,0 ); -dev_info (adev->dev,"The ring %s pipe resets to MEC FW start PC: %s\n" , ring->name, - r ==0 ?"successfully" :"failed" ); + dev_dbg(adev->dev, "MEC pipe me%u pipe%u queue%u resets to MEC FW start PC: %s\n", + me, pipe, queue, r == 0 ? "successfully" : "failed");/*FIXME:Sometimes driver can't cache the MEC firmware start PC correctly,so the pipe
* reset status relies on the compute ring test result. */drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +2
-2@@ -7017,7 +7051,7 @@ static int gfx_v11_0_reset_kcq(struct amdgpu_ring *ring, r =amdgpu_mes_reset_legacy_queue (ring->adev, ring, vmid, use_mmio,0 );if (r) {dev_warn (adev->dev,"fail(%d) to reset kcq and try pipe reset\n" , r); - r =gfx_v11_0_reset_compute_pipe (ring); + r =gfx_v11_0_reset_compute_pipe (adev, ring->me, ring->pipe, +ring->queue);if (r)return r; } --2.49.0
PATCH v2 14/42 drm/amdgpu/gfx12: Refactor compute pipe reset and add HQD cleanup
In reply to Jesse ZhangRefactor gfx_v12_0_reset_compute_pipe() to accept explicit me, pipe, and queue parameters instead of deriving them from the ring structure. This enables the function to be used in generic pipe reset flows.
Introduce gfx_v12_0_clear_hqds_on_mec_pipe() to properly clear CP_HQD_ACTIVE and CP_HQD_DEQUEUE_REQUEST for all queues on a given MEC pipe while the pipe reset is asserted, ensuring the HQDs are torn down correctly before deasserting reset.
Switch the KCQ reset path to use the common MEC pipe reset helper amdgpu_gfx_mec_pipe_reset_run(), which coordinates the reset sequence including KFD suspend/resume to avoid conflicts with user mode queues.
v2: just update the sequence (Alex)
v3: directly clear ACTIVE and DEQUEUE_REQUEST (Shaoyun Liu)
--- drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c | 115 +++++++++++++++---------- 1 file changed, 69 insertions(+), 46 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +69 -46
@@ -5309,10 +5309,30 @@ static int gfx_v12_0_reset_kgq(struct amdgpu_ring *ring,return amdgpu_ring_reset_helper_end (ring, timedout_fence); } -static int gfx_v12_0_reset_compute_pipe (struct amdgpu_ring *ring) +/* +* With MEC pipe reset asserted, clear CP_HQD_ACTIVE / CP_HQD_DEQUEUE_REQUEST for +* every queue on (me, pipe). HQDs must be torn down while pipe reset stays +* asserted; only then clear the pipe reset bit. +* Caller must hold adev->srbm_mutex. +*/ +static void gfx_v12_0_clear_hqds_on_mec_pipe (struct amdgpu_device *adev,u32 me, +u32 pipe) { -struct amdgpu_device *adev = ring->adev; -uint32_t reset_pipe =0 , clean_pipe =0 ; +unsigned int q; +int j; + +for (q =0 ; q < adev->gfx.mec.num_queue_per_pipe; q++) { +soc24_grbm_select (adev, me, pipe, q,0 ); +/* Start from a clean HQD dequeue state before forcing HQD inactive. */ +WREG32_SOC15 (GC ,0 , regCP_HQD_ACTIVE,0 ); +WREG32_SOC15 (GC ,0 , regCP_HQD_DEQUEUE_REQUEST,0 ); + } +} + +static int gfx_v12_0_reset_compute_pipe (struct amdgpu_device *adev, +u32 me,u32 pipe,u32 queue) +{ +uint32_t reset_val, clean_val;int r =0 ;if (!gfx_v12_pipe_reset_support (adev))
@@ -5320,75 +5340,78 @@ static int gfx_v12_0_reset_compute_pipe(struct amdgpu_ring *ring)gfx_v12_0_set_safe_mode (adev,0 );mutex_lock (&adev->srbm_mutex); -soc24_grbm_select (adev, ring->me, ring->pipe, ring->queue,0 ); - - reset_pipe =RREG32_SOC15 (GC ,0 , regCP_MEC_RS64_CNTL); - clean_pipe = reset_pipe; - +soc24_grbm_select (adev, me, pipe, queue,0 );if (adev->gfx.rs64_enable) { -switch (ring->pipe) { + reset_val =RREG32_SOC15 (GC ,0 , regCP_MEC_RS64_CNTL); + clean_val = reset_val; + +switch (pipe) {case 0 : - reset_pipe =REG_SET_FIELD (reset_pipe,CP_MEC_RS64_CNTL , -MEC_PIPE0_RESET ,1 ); - clean_pipe =REG_SET_FIELD (clean_pipe,CP_MEC_RS64_CNTL , -MEC_PIPE0_RESET ,0 ); + reset_val =REG_SET_FIELD (reset_val,CP_MEC_RS64_CNTL , +MEC_PIPE0_RESET ,1 ); + clean_val =REG_SET_FIELD (clean_val,CP_MEC_RS64_CNTL , +MEC_PIPE0_RESET ,0 );break ;case 1 : - reset_pipe =REG_SET_FIELD (reset_pipe,CP_MEC_RS64_CNTL , -MEC_PIPE1_RESET ,1 ); - clean_pipe =REG_SET_FIELD (clean_pipe,CP_MEC_RS64_CNTL , -MEC_PIPE1_RESET ,0 ); + reset_val =REG_SET_FIELD (reset_val,CP_MEC_RS64_CNTL , +MEC_PIPE1_RESET ,1 ); + clean_val =REG_SET_FIELD (clean_val,CP_MEC_RS64_CNTL , +MEC_PIPE1_RESET ,0 );break ;case 2 : - reset_pipe =REG_SET_FIELD (reset_pipe,CP_MEC_RS64_CNTL , -MEC_PIPE2_RESET ,1 ); - clean_pipe =REG_SET_FIELD (clean_pipe,CP_MEC_RS64_CNTL , -MEC_PIPE2_RESET ,0 ); + reset_val =REG_SET_FIELD (reset_val,CP_MEC_RS64_CNTL , +MEC_PIPE2_RESET ,1 ); + clean_val =REG_SET_FIELD (clean_val,CP_MEC_RS64_CNTL , +MEC_PIPE2_RESET ,0 );break ;case 3 : - reset_pipe =REG_SET_FIELD (reset_pipe,CP_MEC_RS64_CNTL , -MEC_PIPE3_RESET ,1 ); - clean_pipe =REG_SET_FIELD (clean_pipe,CP_MEC_RS64_CNTL , -MEC_PIPE3_RESET ,0 ); + reset_val =REG_SET_FIELD (reset_val,CP_MEC_RS64_CNTL , +MEC_PIPE3_RESET ,1 ); + clean_val =REG_SET_FIELD (clean_val,CP_MEC_RS64_CNTL , +MEC_PIPE3_RESET ,0 );break ;default :break ; } -WREG32_SOC15 (GC ,0 , regCP_MEC_RS64_CNTL, reset_pipe); -WREG32_SOC15 (GC ,0 , regCP_MEC_RS64_CNTL, clean_pipe); +WREG32_SOC15 (GC ,0 , regCP_MEC_RS64_CNTL, reset_val); +gfx_v12_0_clear_hqds_on_mec_pipe (adev, me, pipe); +soc24_grbm_select (adev, me, pipe, queue,0 ); +WREG32_SOC15 (GC ,0 , regCP_MEC_RS64_CNTL, clean_val); r = (RREG32_SOC15 (GC ,0 , regCP_MEC_RS64_INSTR_PNTR) <<2 ) -RS64_FW_UC_START_ADDR_LO ; }else { -switch (ring->pipe) { + reset_val =RREG32_SOC15 (GC ,0 , regCP_MEC_CNTL); + clean_val = reset_val; + +switch (pipe) {case 0 : - reset_pipe =REG_SET_FIELD (reset_pipe,CP_MEC_CNTL , -MEC_ME1_PIPE0_RESET ,1 ); - clean_pipe =REG_SET_FIELD (clean_pipe,CP_MEC_CNTL , -MEC_ME1_PIPE0_RESET ,0 ); + reset_val =REG_SET_FIELD (reset_val,CP_MEC_CNTL , +MEC_ME1_PIPE0_RESET ,1 ); + clean_val =REG_SET_FIELD (clean_val,CP_MEC_CNTL , +MEC_ME1_PIPE0_RESET ,0 );break ;case 1 : - reset_pipe =REG_SET_FIELD (reset_pipe,CP_MEC_CNTL , -MEC_ME1_PIPE1_RESET ,1 ); - clean_pipe =REG_SET_FIELD (clean_pipe,CP_MEC_CNTL , -MEC_ME1_PIPE1_RESET ,0 ); + reset_val =REG_SET_FIELD (reset_val,CP_MEC_CNTL , +MEC_ME1_PIPE1_RESET ,1 ); + clean_val =REG_SET_FIELD (clean_val,CP_MEC_CNTL , +MEC_ME1_PIPE1_RESET ,0 );break ;default : -break ; +break ; } -WREG32_SOC15 (GC ,0 , regCP_MEC_CNTL, reset_pipe); -WREG32_SOC15 (GC ,0 , regCP_MEC_CNTL, clean_pipe); -/* Doesn't find the F32 MEC instruction pointer register, and suppose -* the driver won't run into the F32 mode. -*/ + +WREG32_SOC15 (GC ,0 , regCP_MEC_CNTL, reset_val); +gfx_v12_0_clear_hqds_on_mec_pipe (adev, me, pipe); +soc24_grbm_select (adev, me, pipe, queue,0 ); +WREG32_SOC15 (GC ,0 , regCP_MEC_CNTL, clean_val); }soc24_grbm_select (adev,0 ,0 ,0 ,0 );mutex_unlock (&adev->srbm_mutex);gfx_v12_0_unset_safe_mode (adev,0 ); -dev_info (adev->dev,"The ring %s pipe resets: %s\n" , ring->name, - r ==0 ?"successfully" :"failed" ); -/* Need the ring test to verify the pipe reset result.*/ +dev_dbg (adev->dev,"MEC pipe me%u pipe%u queue%u resets to MEC FW start PC: %s\n" , + me, pipe, queue, r ==0 ?"successfully" :"failed" );return 0 ; }
@@ -5405,7 +5428,7 @@ static int gfx_v12_0_reset_kcq(struct amdgpu_ring *ring, r =amdgpu_mes_reset_legacy_queue (ring->adev, ring, vmid, use_mmio,0 );if (r) {dev_warn (adev->dev,"fail(%d) to reset kcq and try pipe reset\n" , r); - r =gfx_v12_0_reset_compute_pipe (ring); + r =gfx_v12_0_reset_compute_pipe (adev, ring->me, ring->pipe, ring->queue);if (r)return r; }
Signature · 1 line
2.49.0
RE: [PATCH v2 14/42] drm/amdgpu/gfx12: Refactor compute pipe reset and add HQD cleanup
AMD General
Regards,
Prike
Quoted 149 lines
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Jesse Zhang
Sent: Monday, June 1, 2026 1:49 PM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Zhang, Jesse(Jie) <[email protected]>; Rastogi, Manu <[email protected]>; Deucher, Alexander <[email protected]>; Zhang, Jesse(Jie) <[email protected]>
Subject: [PATCH v2 14/42] drm/amdgpu/gfx12: Refactor compute pipe reset and add HQD cleanupRefactor
gfx_v12_0_reset_compute_pipe()to accept explicit me, pipe, and queue parameters instead of deriving them from the ring structure. This enables the function to be used in generic pipe reset flows.Introduce
gfx_v12_0_clear_hqds_on_mec_pipe()to properly clearCP_HQD_ACTIVEandCP_HQD_DEQUEUE_REQUESTfor all queues on a given MEC pipe while the pipe reset is asserted, ensuring the HQDs are torn down correctly before deasserting reset.Switch the KCQ reset path to use the common MEC pipe reset helper
amdgpu_gfx_mec_pipe_reset_run(), which coordinates the reset sequence including KFD suspend/resume to avoid conflicts with user mode queues.v2: just update the sequence (Alex)
v3: directly clear ACTIVE andDEQUEUE_REQUEST(Shaoyun Liu)Suggested-by Manu Rastogi <[email protected]>Suggested-by Alex Deucher <[email protected]>Signed-off-by Jesse Zhang <[email protected]>Signed-off-by Alex Deucher <[email protected]>--- drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c | 115 +++++++++++++++---------- 1 file changed, 69 insertions(+), 46 deletions(-)drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +45
-25@@ -5309,10 +5309,30 @@ static int gfx_v12_0_reset_kgq(struct amdgpu_ring *ring, return amdgpu_ring_reset_helper_end(ring, timedout_fence); } -static int gfx_v12_0_reset_compute_pipe(struct amdgpu_ring *ring) +/* +* With MEC pipe reset asserted, clear CP_HQD_ACTIVE / +CP_HQD_DEQUEUE_REQUEST for +* every queue on (me, pipe). HQDs must be torn down while pipe reset +stays +* asserted; only then clear the pipe reset bit. +* Caller must hold adev->srbm_mutex. +*/ +static void gfx_v12_0_clear_hqds_on_mec_pipe (struct amdgpu_device *adev,u32 me, +u32 pipe) { -struct amdgpu_device *adev = ring->adev; -uint32_t reset_pipe = 0, clean_pipe = 0; +unsigned int q; +int j; + +for (q =0 ; q < adev->gfx.mec.num_queue_per_pipe; q++) { +soc24_grbm_select (adev, me, pipe, q,0 ); +/* Start from a clean HQD dequeue state before forcing HQD inactive. */ +WREG32_SOC15 (GC ,0 , regCP_HQD_ACTIVE,0 ); +WREG32_SOC15 (GC ,0 , regCP_HQD_DEQUEUE_REQUEST,0 ); + } +} + +static int gfx_v12_0_reset_compute_pipe (struct amdgpu_device *adev, +u32 me,u32 pipe,u32 queue) +{ +uint32_t reset_val, clean_val;int r =0 ;if (!gfx_v12_pipe_reset_support (adev))@@ -5320,75 +5340,78 @@ static int gfx_v12_0_reset_compute_pipe(struct amdgpu_ring *ring) gfx_v12_0_set_safe_mode(adev, 0);mutex_lock (&adev->srbm_mutex); -soc24_grbm_select (adev, ring->me, ring->pipe, ring->queue,0 ); - - reset_pipe =RREG32_SOC15 (GC ,0 , regCP_MEC_RS64_CNTL); - clean_pipe = reset_pipe; - +soc24_grbm_select (adev, me, pipe, queue,0 );if (adev->gfx.rs64_enable) { -switch (ring->pipe) { + reset_val =RREG32_SOC15 (GC ,0 , regCP_MEC_RS64_CNTL); + clean_val = reset_val; + +switch (pipe) {case 0 : - reset_pipe =REG_SET_FIELD (reset_pipe,CP_MEC_RS64_CNTL , -MEC_PIPE0_RESET ,1 ); - clean_pipe =REG_SET_FIELD (clean_pipe,CP_MEC_RS64_CNTL , -MEC_PIPE0_RESET ,0 ); + reset_val =REG_SET_FIELD (reset_val,CP_MEC_RS64_CNTL , +MEC_PIPE0_RESET ,1 ); + clean_val =REG_SET_FIELD (clean_val,CP_MEC_RS64_CNTL , +MEC_PIPE0_RESET ,0 );break ;case 1 : - reset_pipe =REG_SET_FIELD (reset_pipe,CP_MEC_RS64_CNTL , -MEC_PIPE1_RESET ,1 ); - clean_pipe =REG_SET_FIELD (clean_pipe,CP_MEC_RS64_CNTL , -MEC_PIPE1_RESET ,0 ); + reset_val =REG_SET_FIELD (reset_val,CP_MEC_RS64_CNTL , +MEC_PIPE1_RESET ,1 ); + clean_val =REG_SET_FIELD (clean_val,CP_MEC_RS64_CNTL , +MEC_PIPE1_RESET ,0 );break ;case 2 : - reset_pipe =REG_SET_FIELD (reset_pipe,CP_MEC_RS64_CNTL , -MEC_PIPE2_RESET ,1 ); - clean_pipe =REG_SET_FIELD (clean_pipe,CP_MEC_RS64_CNTL , -MEC_PIPE2_RESET ,0 ); + reset_val =REG_SET_FIELD (reset_val,CP_MEC_RS64_CNTL , +MEC_PIPE2_RESET ,1 ); + clean_val =REG_SET_FIELD (clean_val,CP_MEC_RS64_CNTL , +MEC_PIPE2_RESET ,0 );break ;case 3 : - reset_pipe =REG_SET_FIELD (reset_pipe,CP_MEC_RS64_CNTL , -MEC_PIPE3_RESET ,1 ); - clean_pipe =REG_SET_FIELD (clean_pipe,CP_MEC_RS64_CNTL , -MEC_PIPE3_RESET ,0 ); + reset_val =REG_SET_FIELD (reset_val,CP_MEC_RS64_CNTL , +MEC_PIPE3_RESET ,1 ); + clean_val = REG_SET_FIELD(clean_val,
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c static int gfx_v12_0_reset_compute_pipe(struct · line 5394
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +3
-2CP_MEC_RS64_CNTL , + MEC_PIPE3_RESET, 0);break ;default :break ; } -WREG32_SOC15 (GC ,0 , regCP_MEC_RS64_CNTL, reset_pipe); -WREG32_SOC15 (GC ,0 , regCP_MEC_RS64_CNTL, clean_pipe); +WREG32_SOC15 (GC ,0 , regCP_MEC_RS64_CNTL, reset_val); +gfx_v12_0_clear_hqds_on_mec_pipe (adev, me, pipe);
Same as patch#13 which requires removing the queue selecting, other than that the patch is Reviewed-by: Prike Liang <[email protected]>
Quoted 76 lines
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +2
-0+soc24_grbm_select (adev, me, pipe, queue,0 ); +WREG32_SOC15 (GC ,0 , regCP_MEC_RS64_CNTL, clean_val); r = (RREG32_SOC15(GC, 0, regCP_MEC_RS64_INSTR_PNTR) <<2) -
RS64_FW_UC_START_ADDR_LO; } else {drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +4
-3-switch (ring->pipe) { + reset_val =RREG32_SOC15 (GC ,0 , regCP_MEC_CNTL); + clean_val = reset_val; + +switch (pipe) {case 0 : - reset_pipe = REG_SET_FIELD(reset_pipe, CP_MEC_CNTL, - MEC_ME1_PIPE0_RESET,1);
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +0
-2- clean_pipe = REG_SET_FIELD(clean_pipe, CP_MEC_CNTL, - MEC_ME1_PIPE0_RESET,0);
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +4
-2+ reset_val =REG_SET_FIELD (reset_val,CP_MEC_CNTL , +MEC_ME1_PIPE0_RESET ,1 ); + clean_val =REG_SET_FIELD (clean_val,CP_MEC_CNTL , +MEC_ME1_PIPE0_RESET ,0 );break ;case 1 : - reset_pipe = REG_SET_FIELD(reset_pipe, CP_MEC_CNTL, - MEC_ME1_PIPE1_RESET,1);
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +0
-2- clean_pipe = REG_SET_FIELD(clean_pipe, CP_MEC_CNTL, - MEC_ME1_PIPE1_RESET,0);
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +11
-9+ reset_val =REG_SET_FIELD (reset_val,CP_MEC_CNTL , +MEC_ME1_PIPE1_RESET ,1 ); + clean_val =REG_SET_FIELD (clean_val,CP_MEC_CNTL , +MEC_ME1_PIPE1_RESET ,0 );break ;default : -break ; +break ; } -WREG32_SOC15 (GC ,0 , regCP_MEC_CNTL, reset_pipe); -WREG32_SOC15 (GC ,0 , regCP_MEC_CNTL, clean_pipe); -/* Doesn't find the F32 MEC instruction pointer register, and suppose -* the driver won't run into the F32 mode. -*/ + +WREG32_SOC15 (GC ,0 , regCP_MEC_CNTL, reset_val); +gfx_v12_0_clear_hqds_on_mec_pipe (adev, me, pipe); +soc24_grbm_select (adev, me, pipe, queue,0 ); +WREG32_SOC15 (GC ,0 , regCP_MEC_CNTL, clean_val); }soc24_grbm_select (adev,0 ,0 ,0 ,0 );mutex_unlock (&adev->srbm_mutex);gfx_v12_0_unset_safe_mode (adev,0 ); -dev_info (adev->dev,"The ring %s pipe resets: %s\n" , ring->name, - r ==0 ?"successfully" :"failed" ); -/* Need the ring test to verify the pipe reset result.*/ + dev_dbg(adev->dev, "MEC pipe me%u pipe%u queue%u resets to MEC FWstart PC: %s\n",
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +3
-2+ me, pipe, queue, r == 0 ? "successfully" : "failed");return 0 ; }@@ -5405,7 +5428,7 @@ static int gfx_v12_0_reset_kcq(struct amdgpu_ring *ring, r =amdgpu_mes_reset_legacy_queue (ring->adev, ring, vmid, use_mmio,0 );if (r) {dev_warn (adev->dev,"fail(%d) to reset kcq and try pipe reset\n" , r); - r =gfx_v12_0_reset_compute_pipe (ring); + r =gfx_v12_0_reset_compute_pipe (adev, ring->me, ring->pipe, +ring->queue);if (r)return r; } --2.49.0
PATCH v2 15/42 drm/amdgpu/mes11: move pipe reset to mes use_mmio patch
In reply to Jesse ZhangFrom: Alex Deucher <[email protected]>
This makes the code flows cleaner and it's only supported on the use_mmio path.
v2: fix typo
v3: fix typo
v4: directly clear ACTIVE and DEQUEUE_REQUEST (Shaoyun Liu)
--- drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 244 +------------------------ drivers/gpu/drm/amd/amdgpu/mes_v11_0.c | 244 ++++++++++++++++++++++++- 2 files changed, 244 insertions(+), 244 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +4 -240
@@ -6775,69 +6775,6 @@ static void gfx_v11_0_emit_mem_sync(struct amdgpu_ring *ring)amdgpu_ring_write (ring, gcr_cntl);/* GCR_CNTL */ } -static bool gfx_v11_pipe_reset_support (struct amdgpu_device *adev) -{ -/* Disable the pipe reset until the CPFW fully support it.*/ -dev_warn_once (adev->dev,"The CPFW hasn't support pipe reset yet.\n" ); -return false; -} - - -static int gfx_v11_reset_gfx_pipe (struct amdgpu_ring *ring) -{ -struct amdgpu_device *adev = ring->adev; -uint32_t reset_pipe =0 , clean_pipe =0 ; -int r; - -if (!gfx_v11_pipe_reset_support (adev)) -return -EOPNOTSUPP ; - -gfx_v11_0_set_safe_mode (adev,0 ); -mutex_lock (&adev->srbm_mutex); -soc21_grbm_select (adev, ring->me, ring->pipe, ring->queue,0 ); - -switch (ring->pipe) { -case 0 : - reset_pipe =REG_SET_FIELD (reset_pipe,CP_ME_CNTL , -PFP_PIPE0_RESET ,1 ); - reset_pipe =REG_SET_FIELD (reset_pipe,CP_ME_CNTL , -ME_PIPE0_RESET ,1 ); - clean_pipe =REG_SET_FIELD (clean_pipe,CP_ME_CNTL , -PFP_PIPE0_RESET ,0 ); - clean_pipe =REG_SET_FIELD (clean_pipe,CP_ME_CNTL , -ME_PIPE0_RESET ,0 ); -break ; -case 1 : - reset_pipe =REG_SET_FIELD (reset_pipe,CP_ME_CNTL , -PFP_PIPE1_RESET ,1 ); - reset_pipe =REG_SET_FIELD (reset_pipe,CP_ME_CNTL , -ME_PIPE1_RESET ,1 ); - clean_pipe =REG_SET_FIELD (clean_pipe,CP_ME_CNTL , -PFP_PIPE1_RESET ,0 ); - clean_pipe =REG_SET_FIELD (clean_pipe,CP_ME_CNTL , -ME_PIPE1_RESET ,0 ); -break ; -default : -break ; - } - -WREG32_SOC15 (GC ,0 , regCP_ME_CNTL, reset_pipe); -WREG32_SOC15 (GC ,0 , regCP_ME_CNTL, clean_pipe); - - r = (RREG32 (SOC15_REG_OFFSET (GC ,0 , regCP_GFX_RS64_INSTR_PNTR1)) <<2 ) - -RS64_FW_UC_START_ADDR_LO ; -soc21_grbm_select (adev,0 ,0 ,0 ,0 ); -mutex_unlock (&adev->srbm_mutex); -gfx_v11_0_unset_safe_mode (adev,0 ); - -dev_info (adev->dev,"The ring %s pipe reset to the ME firmware start PC: %s\n" , ring->name, - r ==0 ?"successfully" :"failed" ); -/* FIXME: Sometimes driver can't cache the ME firmware start PC correctly, -* so the pipe reset status relies on the later gfx ring test result. -*/ -return 0 ; -} -static int gfx_v11_0_reset_kgq (struct amdgpu_ring *ring,unsigned int vmid,struct amdgpu_fence *timedout_fence)
@@ -6849,13 +6786,8 @@ static int gfx_v11_0_reset_kgq(struct amdgpu_ring *ring,amdgpu_ring_reset_helper_begin (ring, timedout_fence); r =amdgpu_mes_reset_legacy_queue (ring->adev, ring, vmid, use_mmio,0 ); -if (r) { - -dev_warn (adev->dev,"reset via MES failed and try pipe reset %d\n" , r); - r =gfx_v11_reset_gfx_pipe (ring); -if (r) -return r; - } +if (r) +return r;if (use_mmio) { r =gfx_v11_0_kgq_init_queue (ring, true);
@@ -6874,170 +6806,6 @@ static int gfx_v11_0_reset_kgq(struct amdgpu_ring *ring,return amdgpu_ring_reset_helper_end (ring, timedout_fence); } -/* -* With MEC pipe reset asserted, clear CP_HQD_ACTIVE / CP_HQD_DEQUEUE_REQUEST for -* every queue on (me, pipe). HQDs must be torn down while pipe reset stays -* asserted; only then clear the pipe reset bit. -* Caller must hold adev->srbm_mutex. -*/ -static void gfx_v11_0_clear_hqds_on_mec_pipe (struct amdgpu_device *adev,u32 me, -u32 pipe) -{ -unsigned int q; -int j; - -for (q =0 ; q < adev->gfx.mec.num_queue_per_pipe; q++) { -soc21_grbm_select (adev, me, pipe, q,0 ); -/* Start from a clean HQD dequeue state before forcing HQD inactive. */ -WREG32_SOC15 (GC ,0 , regCP_HQD_ACTIVE,0 ); -if (RREG32_SOC15 (GC ,0 , regCP_HQD_ACTIVE) &1 ) { -WREG32_SOC15 (GC ,0 , regCP_HQD_DEQUEUE_REQUEST,1 ); -for (j =0 ; j < adev->usec_timeout; j++) { -if (!(RREG32_SOC15 (GC ,0 , regCP_HQD_ACTIVE) &1 )) -break ; -udelay (1 ); - } - } - -WREG32_SOC15 (GC ,0 , regCP_HQD_DEQUEUE_REQUEST,0 ); - } -} - -static int gfx_v11_0_reset_compute_pipe (struct amdgpu_device *adev, -u32 me,u32 pipe,u32 queue) -{ -uint32_t reset_val, clean_val; -int r; - -if (!gfx_v11_pipe_reset_support (adev)) -return -EOPNOTSUPP ; - -gfx_v11_0_set_safe_mode (adev,0 ); -mutex_lock (&adev->srbm_mutex); -soc21_grbm_select (adev, me, pipe, queue,0 ); - -if (adev->gfx.rs64_enable) { - reset_val =RREG32_SOC15 (GC ,0 , regCP_MEC_RS64_CNTL); - clean_val = reset_val; - -switch (pipe) { -case 0 : - reset_val =REG_SET_FIELD (reset_val,CP_MEC_RS64_CNTL , -MEC_PIPE0_RESET ,1 ); - clean_val =REG_SET_FIELD (clean_val,CP_MEC_RS64_CNTL , -MEC_PIPE0_RESET ,0 ); -break ; -case 1 : - reset_val =REG_SET_FIELD (reset_val,CP_MEC_RS64_CNTL , -MEC_PIPE1_RESET ,1 ); - clean_val =REG_SET_FIELD (clean_val,CP_MEC_RS64_CNTL , -MEC_PIPE1_RESET ,0 ); -break ; -case 2 : - reset_val =REG_SET_FIELD (reset_val,CP_MEC_RS64_CNTL , -MEC_PIPE2_RESET ,1 ); - clean_val =REG_SET_FIELD (clean_val,CP_MEC_RS64_CNTL , -MEC_PIPE2_RESET ,0 ); -break ; -case 3 : - reset_val =REG_SET_FIELD (reset_val,CP_MEC_RS64_CNTL , -MEC_PIPE3_RESET ,1 ); - clean_val =REG_SET_FIELD (clean_val,CP_MEC_RS64_CNTL , -MEC_PIPE3_RESET ,0 ); -break ; -default : -break ; - } -WREG32_SOC15 (GC ,0 , regCP_MEC_RS64_CNTL, reset_val); -gfx_v11_0_clear_hqds_on_mec_pipe (adev, me, pipe); -soc21_grbm_select (adev, me, pipe, queue,0 ); -WREG32_SOC15 (GC ,0 , regCP_MEC_RS64_CNTL, clean_val); - r = (RREG32_SOC15 (GC ,0 , regCP_MEC_RS64_INSTR_PNTR) <<2 ) - -RS64_FW_UC_START_ADDR_LO ; - }else { - reset_val =RREG32_SOC15 (GC ,0 , regCP_MEC_CNTL); - clean_val = reset_val; - -if (me ==1 ) { -switch (pipe) { -case 0 : - reset_val =REG_SET_FIELD (reset_val,CP_MEC_CNTL , -MEC_ME1_PIPE0_RESET ,1 ); - clean_val =REG_SET_FIELD (clean_val,CP_MEC_CNTL , -MEC_ME1_PIPE0_RESET ,0 ); -break ; -case 1 : - reset_val =REG_SET_FIELD (reset_val,CP_MEC_CNTL , -MEC_ME1_PIPE1_RESET ,1 ); - clean_val =REG_SET_FIELD (clean_val,CP_MEC_CNTL , -MEC_ME1_PIPE1_RESET ,0 ); -break ; -case 2 : - reset_val =REG_SET_FIELD (reset_val,CP_MEC_CNTL , -MEC_ME1_PIPE2_RESET ,1 ); - clean_val =REG_SET_FIELD (clean_val,CP_MEC_CNTL , -MEC_ME1_PIPE2_RESET ,0 ); -break ; -case 3 : - reset_val =REG_SET_FIELD (reset_val,CP_MEC_CNTL , -MEC_ME1_PIPE3_RESET ,1 ); - clean_val =REG_SET_FIELD (clean_val,CP_MEC_CNTL , -MEC_ME1_PIPE3_RESET ,0 ); -break ; -default : -break ; - } -/* mec1 fw pc: CP_MEC1_INSTR_PNTR */ - }else { -switch (pipe) { -case 0 : - reset_val =REG_SET_FIELD (reset_val,CP_MEC_CNTL , -MEC_ME2_PIPE0_RESET ,1 ); - clean_val =REG_SET_FIELD (clean_val,CP_MEC_CNTL , -MEC_ME2_PIPE0_RESET ,0 ); -break ; -case 1 : - reset_val =REG_SET_FIELD (reset_val,CP_MEC_CNTL , -MEC_ME2_PIPE1_RESET ,1 ); - clean_val =REG_SET_FIELD (clean_val,CP_MEC_CNTL , -MEC_ME2_PIPE1_RESET ,0 ); -break ; -case 2 : - reset_val =REG_SET_FIELD (reset_val,CP_MEC_CNTL , -MEC_ME2_PIPE2_RESET ,1 ); - clean_val =REG_SET_FIELD (clean_val,CP_MEC_CNTL , -MEC_ME2_PIPE2_RESET ,0 ); -break ; -case 3 : - reset_val =REG_SET_FIELD (reset_val,CP_MEC_CNTL , -MEC_ME2_PIPE3_RESET ,1 ); - clean_val =REG_SET_FIELD (clean_val,CP_MEC_CNTL , -MEC_ME2_PIPE3_RESET ,0 ); -break ; -default : -break ; - } -/* mec2 fw pc: CP:CP_MEC2_INSTR_PNTR */ - } -WREG32_SOC15 (GC ,0 , regCP_MEC_CNTL, reset_val); -gfx_v11_0_clear_hqds_on_mec_pipe (adev, me, pipe); -soc21_grbm_select (adev, me, pipe, queue,0 ); -WREG32_SOC15 (GC ,0 , regCP_MEC_CNTL, clean_val); - r =RREG32 (SOC15_REG_OFFSET (GC ,0 , regCP_MEC1_INSTR_PNTR)); - } - -soc21_grbm_select (adev,0 ,0 ,0 ,0 ); -mutex_unlock (&adev->srbm_mutex); -gfx_v11_0_unset_safe_mode (adev,0 ); - -dev_dbg (adev->dev,"MEC pipe me%u pipe%u queue%u resets to MEC FW start PC: %s\n" , - me, pipe, queue, r ==0 ?"successfully" :"failed" ); -/*FIXME:Sometimes driver can't cache the MEC firmware start PC correctly, so the pipe -* reset status relies on the compute ring test result. -*/ -return 0 ; -} -static int gfx_v11_0_reset_kcq (struct amdgpu_ring *ring,unsigned int vmid,struct amdgpu_fence *timedout_fence)
@@ -7049,12 +6817,8 @@ static int gfx_v11_0_reset_kcq(struct amdgpu_ring *ring,amdgpu_ring_reset_helper_begin (ring, timedout_fence); r =amdgpu_mes_reset_legacy_queue (ring->adev, ring, vmid, use_mmio,0 ); -if (r) { -dev_warn (adev->dev,"fail(%d) to reset kcq and try pipe reset\n" , r); - r =gfx_v11_0_reset_compute_pipe (adev, ring->me, ring->pipe, ring->queue); -if (r) -return r; - } +if (r) +return r;if (use_mmio) { r =gfx_v11_0_kcq_init_queue (ring, true);
drivers/gpu/drm/amd/amdgpu/mes_v11_0.c +240 -4
256 lines not on this page · raw message
Signature · 1 line
2.49.0
PATCH v2 16/42 drm/amdgpu/mes12: move pipe reset to mes use_mmio patch
In reply to Jesse ZhangFrom: Alex Deucher <[email protected]>
This makes the code flows cleaner and it's only supported on the use_mmio path.
v2: fix typo
v3: fix typo
v4: directly clear ACTIVE and DEQUEUE_REQUEST (Shaoyun Liu)
--- drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c | 185 +---------------------- drivers/gpu/drm/amd/amdgpu/mes_v12_0.c | 197 ++++++++++++++++++++++++- 2 files changed, 197 insertions(+), 185 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +4 -181
@@ -5211,69 +5211,6 @@ static void gfx_v12_ip_dump(struct amdgpu_ip_block *ip_block)amdgpu_gfx_off_ctrl (adev, true); } -static bool gfx_v12_pipe_reset_support (struct amdgpu_device *adev) -{ -/* Disable the pipe reset until the CPFW fully support it.*/ -dev_warn_once (adev->dev,"The CPFW hasn't support pipe reset yet.\n" ); -return false; -} - -static int gfx_v12_reset_gfx_pipe (struct amdgpu_ring *ring) -{ -struct amdgpu_device *adev = ring->adev; -uint32_t reset_pipe =0 , clean_pipe =0 ; -int r; - -if (!gfx_v12_pipe_reset_support (adev)) -return -EOPNOTSUPP ; - -gfx_v12_0_set_safe_mode (adev,0 ); -mutex_lock (&adev->srbm_mutex); -soc24_grbm_select (adev, ring->me, ring->pipe, ring->queue,0 ); - -switch (ring->pipe) { -case 0 : - reset_pipe =REG_SET_FIELD (reset_pipe,CP_ME_CNTL , -PFP_PIPE0_RESET ,1 ); - reset_pipe =REG_SET_FIELD (reset_pipe,CP_ME_CNTL , -ME_PIPE0_RESET ,1 ); - clean_pipe =REG_SET_FIELD (clean_pipe,CP_ME_CNTL , -PFP_PIPE0_RESET ,0 ); - clean_pipe =REG_SET_FIELD (clean_pipe,CP_ME_CNTL , -ME_PIPE0_RESET ,0 ); -break ; -case 1 : - reset_pipe =REG_SET_FIELD (reset_pipe,CP_ME_CNTL , -PFP_PIPE1_RESET ,1 ); - reset_pipe =REG_SET_FIELD (reset_pipe,CP_ME_CNTL , -ME_PIPE1_RESET ,1 ); - clean_pipe =REG_SET_FIELD (clean_pipe,CP_ME_CNTL , -PFP_PIPE1_RESET ,0 ); - clean_pipe =REG_SET_FIELD (clean_pipe,CP_ME_CNTL , -ME_PIPE1_RESET ,0 ); -break ; -default : -break ; - } - -WREG32_SOC15 (GC ,0 , regCP_ME_CNTL, reset_pipe); -WREG32_SOC15 (GC ,0 , regCP_ME_CNTL, clean_pipe); - - r = (RREG32 (SOC15_REG_OFFSET (GC ,0 , regCP_GFX_RS64_INSTR_PNTR1)) <<2 ) - -RS64_FW_UC_START_ADDR_LO ; -soc24_grbm_select (adev,0 ,0 ,0 ,0 ); -mutex_unlock (&adev->srbm_mutex); -gfx_v12_0_unset_safe_mode (adev,0 ); - -dev_info (adev->dev,"The ring %s pipe reset: %s\n" , ring->name, - r ==0 ?"successfully" :"failed" ); -/* Sometimes the ME start pc counter can't cache correctly, so the -* PC check only as a reference and pipe reset result rely on the -* later ring test. -*/ -return 0 ; -} -static int gfx_v12_0_reset_kgq (struct amdgpu_ring *ring,unsigned int vmid,struct amdgpu_fence *timedout_fence)
@@ -5285,12 +5222,8 @@ static int gfx_v12_0_reset_kgq(struct amdgpu_ring *ring,amdgpu_ring_reset_helper_begin (ring, timedout_fence); r =amdgpu_mes_reset_legacy_queue (ring->adev, ring, vmid, use_mmio,0 ); -if (r) { -dev_warn (adev->dev,"reset via MES failed and try pipe reset %d\n" , r); - r =gfx_v12_reset_gfx_pipe (ring); -if (r) -return r; - } +if (r) +return r;if (use_mmio) { r =gfx_v12_0_kgq_init_queue (ring, true);
@@ -5309,112 +5242,6 @@ static int gfx_v12_0_reset_kgq(struct amdgpu_ring *ring,return amdgpu_ring_reset_helper_end (ring, timedout_fence); } -/* -* With MEC pipe reset asserted, clear CP_HQD_ACTIVE / CP_HQD_DEQUEUE_REQUEST for -* every queue on (me, pipe). HQDs must be torn down while pipe reset stays -* asserted; only then clear the pipe reset bit. -* Caller must hold adev->srbm_mutex. -*/ -static void gfx_v12_0_clear_hqds_on_mec_pipe (struct amdgpu_device *adev,u32 me, -u32 pipe) -{ -unsigned int q; -int j; - -for (q =0 ; q < adev->gfx.mec.num_queue_per_pipe; q++) { -soc24_grbm_select (adev, me, pipe, q,0 ); -/* Start from a clean HQD dequeue state before forcing HQD inactive. */ -WREG32_SOC15 (GC ,0 , regCP_HQD_ACTIVE,0 ); -WREG32_SOC15 (GC ,0 , regCP_HQD_DEQUEUE_REQUEST,0 ); - } -} - -static int gfx_v12_0_reset_compute_pipe (struct amdgpu_device *adev, -u32 me,u32 pipe,u32 queue) -{ -uint32_t reset_val, clean_val; -int r =0 ; - -if (!gfx_v12_pipe_reset_support (adev)) -return -EOPNOTSUPP ; - -gfx_v12_0_set_safe_mode (adev,0 ); -mutex_lock (&adev->srbm_mutex); -soc24_grbm_select (adev, me, pipe, queue,0 ); -if (adev->gfx.rs64_enable) { - reset_val =RREG32_SOC15 (GC ,0 , regCP_MEC_RS64_CNTL); - clean_val = reset_val; - -switch (pipe) { -case 0 : - reset_val =REG_SET_FIELD (reset_val,CP_MEC_RS64_CNTL , -MEC_PIPE0_RESET ,1 ); - clean_val =REG_SET_FIELD (clean_val,CP_MEC_RS64_CNTL , -MEC_PIPE0_RESET ,0 ); -break ; -case 1 : - reset_val =REG_SET_FIELD (reset_val,CP_MEC_RS64_CNTL , -MEC_PIPE1_RESET ,1 ); - clean_val =REG_SET_FIELD (clean_val,CP_MEC_RS64_CNTL , -MEC_PIPE1_RESET ,0 ); -break ; -case 2 : - reset_val =REG_SET_FIELD (reset_val,CP_MEC_RS64_CNTL , -MEC_PIPE2_RESET ,1 ); - clean_val =REG_SET_FIELD (clean_val,CP_MEC_RS64_CNTL , -MEC_PIPE2_RESET ,0 ); -break ; -case 3 : - reset_val =REG_SET_FIELD (reset_val,CP_MEC_RS64_CNTL , -MEC_PIPE3_RESET ,1 ); - clean_val =REG_SET_FIELD (clean_val,CP_MEC_RS64_CNTL , -MEC_PIPE3_RESET ,0 ); -break ; -default : -break ; - } -WREG32_SOC15 (GC ,0 , regCP_MEC_RS64_CNTL, reset_val); -gfx_v12_0_clear_hqds_on_mec_pipe (adev, me, pipe); -soc24_grbm_select (adev, me, pipe, queue,0 ); -WREG32_SOC15 (GC ,0 , regCP_MEC_RS64_CNTL, clean_val); - r = (RREG32_SOC15 (GC ,0 , regCP_MEC_RS64_INSTR_PNTR) <<2 ) - -RS64_FW_UC_START_ADDR_LO ; - }else { - reset_val =RREG32_SOC15 (GC ,0 , regCP_MEC_CNTL); - clean_val = reset_val; - -switch (pipe) { -case 0 : - reset_val =REG_SET_FIELD (reset_val,CP_MEC_CNTL , -MEC_ME1_PIPE0_RESET ,1 ); - clean_val =REG_SET_FIELD (clean_val,CP_MEC_CNTL , -MEC_ME1_PIPE0_RESET ,0 ); -break ; -case 1 : - reset_val =REG_SET_FIELD (reset_val,CP_MEC_CNTL , -MEC_ME1_PIPE1_RESET ,1 ); - clean_val =REG_SET_FIELD (clean_val,CP_MEC_CNTL , -MEC_ME1_PIPE1_RESET ,0 ); -break ; -default : -break ; - } - -WREG32_SOC15 (GC ,0 , regCP_MEC_CNTL, reset_val); -gfx_v12_0_clear_hqds_on_mec_pipe (adev, me, pipe); -soc24_grbm_select (adev, me, pipe, queue,0 ); -WREG32_SOC15 (GC ,0 , regCP_MEC_CNTL, clean_val); - } - -soc24_grbm_select (adev,0 ,0 ,0 ,0 ); -mutex_unlock (&adev->srbm_mutex); -gfx_v12_0_unset_safe_mode (adev,0 ); - -dev_dbg (adev->dev,"MEC pipe me%u pipe%u queue%u resets to MEC FW start PC: %s\n" , - me, pipe, queue, r ==0 ?"successfully" :"failed" ); -return 0 ; -} -static int gfx_v12_0_reset_kcq (struct amdgpu_ring *ring,unsigned int vmid,struct amdgpu_fence *timedout_fence)
@@ -5426,12 +5253,8 @@ static int gfx_v12_0_reset_kcq(struct amdgpu_ring *ring,amdgpu_ring_reset_helper_begin (ring, timedout_fence); r =amdgpu_mes_reset_legacy_queue (ring->adev, ring, vmid, use_mmio,0 ); -if (r) { -dev_warn (adev->dev,"fail(%d) to reset kcq and try pipe reset\n" , r); - r =gfx_v12_0_reset_compute_pipe (adev, ring->me, ring->pipe, ring->queue); -if (r) -return r; - } +if (r) +return r;if (use_mmio) { r =gfx_v12_0_kcq_init_queue (ring, true);
drivers/gpu/drm/amd/amdgpu/mes_v12_0.c +193 -4
215 lines not on this page · raw message
Signature · 1 line
2.49.0
PATCH v2 17/42 drm/amdgpu/mes: add userq reset helper
In reply to Jesse ZhangFrom: Alex Deucher <[email protected]>
Implement a userq reset helper using the doorbell
index.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c | 23 +++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h | 4 ++++ 2 files changed, 27 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c +23 -0
@@ -439,6 +439,29 @@ int amdgpu_mes_reset_legacy_queue(struct amdgpu_device *adev,return r; } +int amdgpu_mes_reset_user_queue (struct amdgpu_device *adev, +int queue_type, +unsigned int doorbell_index, +unsigned int xcc_id) +{ +struct mes_reset_queue_input queue_input; +int r; + +memset (&queue_input,0 ,sizeof (queue_input)); + + queue_input.xcc_id = xcc_id; + queue_input.queue_type = queue_type; + queue_input.doorbell_offset = doorbell_index; + +amdgpu_mes_lock (&adev->mes); + r = adev->mes.funcs->reset_hw_queue (&adev->mes, &queue_input); +amdgpu_mes_unlock (&adev->mes); +if (r) +dev_err (adev->dev,"failed to reset user queue\n" ); + +return r; +} +int amdgpu_mes_get_hung_queue_db_array_size (struct amdgpu_device *adev) {return adev->mes.hung_queue_db_array_size;
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h +4 -0
@@ -458,6 +458,10 @@ int amdgpu_mes_reset_legacy_queue(struct amdgpu_device *adev,unsigned int vmid, bool use_mmio, uint32_t xcc_id); +int amdgpu_mes_reset_user_queue (struct amdgpu_device *adev, +int queue_type, +unsigned int doorbell_index, +unsigned int xcc_id);int amdgpu_mes_get_hung_queue_db_array_size (struct amdgpu_device *adev); int amdgpu_mes_detect_and_reset_hung_queues(struct amdgpu_device *adev,
Signature · 1 line
2.49.0
PATCH v2 18/42 drm/amdgpu/mes: add a MMIO queue reset helper
In reply to Jesse ZhangFrom: Alex Deucher <[email protected]>
Will be used by KFD for MMIO based resets.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c | 30 +++++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h | 7 ++++++ 2 files changed, 37 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c +30 -0
@@ -439,6 +439,36 @@ int amdgpu_mes_reset_legacy_queue(struct amdgpu_device *adev,return r; } +int amdgpu_mes_reset_queue_mmio (struct amdgpu_device *adev, +int queue_type, +unsigned int vmid, +unsigned int me, +unsigned int pipe, +unsigned int queue, +uint32_t xcc_id) +{ +struct mes_reset_queue_input queue_input; +int r; + +memset (&queue_input,0 ,sizeof (queue_input)); + + queue_input.xcc_id = xcc_id; + queue_input.me_id = me; + queue_input.pipe_id = pipe; + queue_input.queue_id = queue; + queue_input.vmid = vmid; + queue_input.queue_type = queue_type; + queue_input.use_mmio = true; + +amdgpu_mes_lock (&adev->mes); + r = adev->mes.funcs->reset_hw_queue (&adev->mes, &queue_input); +amdgpu_mes_unlock (&adev->mes); +if (r) +dev_err (adev->dev,"failed to reset legacy queue\n" ); + +return r; +} + int amdgpu_mes_reset_user_queue(struct amdgpu_device *adev, int queue_type, unsigned int doorbell_index,
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h +7 -0
@@ -458,6 +458,13 @@ int amdgpu_mes_reset_legacy_queue(struct amdgpu_device *adev,unsigned int vmid, bool use_mmio, uint32_t xcc_id); +int amdgpu_mes_reset_queue_mmio (struct amdgpu_device *adev, +int queue_type, +unsigned int vmid, +unsigned int me, +unsigned int pipe, +unsigned int queue, +uint32_t xcc_id); int amdgpu_mes_reset_user_queue(struct amdgpu_device *adev, int queue_type, unsigned int doorbell_index,
Signature · 1 line
2.49.0
PATCH v2 19/42 drm/amdgpu/userq: split the queue reset from adapter reset
In reply to Jesse ZhangFrom: Alex Deucher <[email protected]>
No functional change intended. Separate the per queue reset handling from the adapter reset handling.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 57 ++++++++++++++--------- 1 file changed, 34 insertions(+), 23 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +34 -23
@@ -88,6 +88,38 @@ static void amdgpu_userq_mgr_reset_work(struct work_struct *work) container_of(work, struct amdgpu_userq_mgr, reset_work);struct amdgpu_device *adev = uq_mgr->adev; +struct amdgpu_reset_context reset_context; + +if (unlikely (adev->debug_disable_gpu_ring_reset)) { +dev_err (adev->dev,"userq reset disabled by debug mask\n" ); +return ; + } + +/* +* If GPU recovery feature is disabled system-wide, +* skip all reset detection logic +*/ +if (!amdgpu_gpu_recovery) +return ; + +memset (&reset_context,0 ,sizeof (reset_context)); + + reset_context.method =AMD_RESET_METHOD_NONE ; + reset_context.reset_req_dev = adev; + reset_context.src =AMDGPU_RESET_SRC_USERQ ; +set_bit (AMDGPU_NEED_FULL_RESET , &reset_context.flags); +/*set_bit(AMDGPU_SKIP_COREDUMP, &reset_context.flags);*/ + +amdgpu_device_gpu_recover (adev,NULL , &reset_context); +} + +static void amdgpu_userq_hang_detect_work (struct work_struct *work) +{ +struct amdgpu_usermode_queue *queue = + container_of(work, struct amdgpu_usermode_queue, + hang_detect_work.work); +struct amdgpu_userq_mgr *uq_mgr =queue->userq_mgr; +struct amdgpu_device *adev = uq_mgr->adev;const int queue_types[] = {AMDGPU_RING_TYPE_COMPUTE ,AMDGPU_RING_TYPE_GFX ,
@@ -131,33 +163,12 @@ static void amdgpu_userq_mgr_reset_work(struct work_struct *work) } } } - -if (gpu_reset) { -struct amdgpu_reset_context reset_context; - -memset (&reset_context,0 ,sizeof (reset_context)); - - reset_context.method =AMD_RESET_METHOD_NONE ; - reset_context.reset_req_dev = adev; - reset_context.src =AMDGPU_RESET_SRC_USERQ ; -set_bit (AMDGPU_NEED_FULL_RESET , &reset_context.flags); -/*set_bit(AMDGPU_SKIP_COREDUMP, &reset_context.flags);*/ - -amdgpu_device_gpu_recover (adev,NULL , &reset_context); - } -} - -static void amdgpu_userq_hang_detect_work (struct work_struct *work) -{ -struct amdgpu_usermode_queue *queue = - container_of(work, struct amdgpu_usermode_queue, - hang_detect_work.work); -/* * Don't schedule the work here! Scheduling or queue work from one reset * handler to another is illegal if you don't take extra precautions! */ -amdgpu_userq_mgr_reset_work (&queue->userq_mgr->reset_work); +if (gpu_reset) +amdgpu_userq_mgr_reset_work (&queue->userq_mgr->reset_work); }/*
Signature · 1 line
2.49.0
PATCH v2 20/42 drm/amdgpu/userq: add per queue reset callback
In reply to Jesse ZhangFrom: Alex Deucher <[email protected]>
Add a per queue reset callback.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h | 1 + 1 file changed, 1 insertion(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h +1 -0
@@ -108,6 +108,7 @@ struct amdgpu_userq_funcs {int (*restore)(struct amdgpu_usermode_queue *queue);int (*detect_and_reset)(struct amdgpu_device *adev,int queue_type); +int (*reset)(struct amdgpu_usermode_queue *queue); };/* Usermode queues for gfx */
Signature · 1 line
2.49.0
PATCH v2 21/42 drm/amdgpu/userq: add mes userq reset callback
In reply to Jesse ZhangFrom: Alex Deucher <[email protected]>
Enable per queue reset for MES managed queues.
--- drivers/gpu/drm/amd/amdgpu/mes_userqueue.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +21 -0
@@ -177,6 +177,26 @@ static int mes_userq_unmap(struct amdgpu_usermode_queue *queue)return r; } +static int mes_userq_reset (struct amdgpu_usermode_queue *queue) +{ +struct amdgpu_userq_mgr *uq_mgr = queue->userq_mgr; +struct amdgpu_device *adev = uq_mgr->adev; +struct mes_reset_queue_input queue_input; +int r; + +/* XXX: add a FW version check for SDMA per queue reset */ +memset (&queue_input,0x0 ,sizeof (struct mes_reset_queue_input )); + queue_input.doorbell_offset = queue->doorbell_index; + queue_input.queue_type = queue->queue_type; + +amdgpu_mes_lock (&adev->mes); + r = adev->mes.funcs->reset_hw_queue (&adev->mes, &queue_input); +amdgpu_mes_unlock (&adev->mes); +if (r) +return r; +return mes_userq_unmap (queue); +} +static int mes_userq_create_ctx_space (struct amdgpu_userq_mgr *uq_mgr,struct amdgpu_usermode_queue *queue,struct drm_amdgpu_userq_in *mqd_user)
@@ -528,4 +548,5 @@ const struct amdgpu_userq_funcs userq_mes_funcs = { .detect_and_reset = mes_userq_detect_and_reset, .preempt = mes_userq_preempt, .restore = mes_userq_restore, + .reset = mes_userq_reset, };
Signature · 1 line
2.49.0
PATCH v2 22/42 drm/amdgpu/userq: switch to per queue reset
In reply to Jesse ZhangFrom: Alex Deucher <[email protected]>
Switch to using the per queue reset rather than
the detect and reset interface.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 38 ++++++----------------- 1 file changed, 10 insertions(+), 28 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +10 -28
@@ -120,14 +120,9 @@ static void amdgpu_userq_hang_detect_work(struct work_struct *work) hang_detect_work.work);struct amdgpu_userq_mgr *uq_mgr =queue->userq_mgr;struct amdgpu_device *adev = uq_mgr->adev; -const int queue_types[] = { -AMDGPU_RING_TYPE_COMPUTE , -AMDGPU_RING_TYPE_GFX , -AMDGPU_RING_TYPE_SDMA - }; -const int num_queue_types =ARRAY_SIZE (queue_types); +const struct amdgpu_userq_funcs *userq_funcs = + adev->userq_funcs[queue->queue_type];bool gpu_reset = false; -int i, r;if (unlikely (adev->debug_disable_gpu_ring_reset)) {dev_err (adev->dev,"userq reset disabled by debug mask\n" );
@@ -141,28 +136,15 @@ static void amdgpu_userq_hang_detect_work(struct work_struct *work)if (!amdgpu_gpu_recovery)return ; -/* -* Iterate through all queue types to detect and reset problematic queues -* Process each queue type in the defined order -*/ -for (i =0 ; i < num_queue_types; i++) { -int ring_type = queue_types[i]; -const struct amdgpu_userq_funcs *funcs = - adev->userq_funcs[ring_type]; - -if (!amdgpu_userq_is_reset_type_supported (adev, ring_type, -AMDGPU_RESET_TYPE_PER_QUEUE )) -continue ; - -if (atomic_read (&uq_mgr->userq_count[ring_type]) >0 && - funcs && funcs->detect_and_reset) { - r = funcs->detect_and_reset (adev, ring_type); -if (r) { - gpu_reset = true; -break ; - } - } +if (amdgpu_userq_is_reset_type_supported (adev, queue->queue_type, +AMDGPU_RESET_TYPE_PER_QUEUE )) { +int r = userq_funcs->reset (queue); +if (r) + gpu_reset = true; + }else { + gpu_reset = true; } +/* * Don't schedule the work here! Scheduling or queue work from one reset * handler to another is illegal if you don't take extra precautions!
Signature · 1 line
2.49.0
PATCH v2 23/42 drm/amdgpu/userq: drop detect_and_reset callback
In reply to Jesse ZhangFrom: Alex Deucher <[email protected]>
No longer needed.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h | 2 - drivers/gpu/drm/amd/amdgpu/mes_userqueue.c | 53 ---------------------- 2 files changed, 55 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h +0 -2
@@ -106,8 +106,6 @@ struct amdgpu_userq_funcs {int (*map)(struct amdgpu_usermode_queue *queue);int (*preempt)(struct amdgpu_usermode_queue *queue);int (*restore)(struct amdgpu_usermode_queue *queue); -int (*detect_and_reset)(struct amdgpu_device *adev, -int queue_type);int (*reset)(struct amdgpu_usermode_queue *queue); };
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +0 -53
65 lines not on this page · raw message
Signature · 1 line
2.49.0
RE: [PATCH v2 23/42] drm/amdgpu/userq: drop detect_and_reset callback
AMD General
Patch 19-23 are Reviewed-by: Prike Liang <[email protected]>
Reset the user queue per queue directly rather than walk over all the queues type each time, which is also my plan to improve the reset latency and simplicity and the idea was pointed out at the Christian's fix about rework the userq reset work scheduled patch upstream period.
Regards,
Prike
Quoted 113 lines
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Jesse Zhang
Sent: Monday, June 1, 2026 1:49 PM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Deucher, Alexander <[email protected]>; Zhang, Jesse(Jie) <[email protected]>
Subject: [PATCH v2 23/42] drm/amdgpu/userq: dropdetect_and_resetcallbackFrom: Alex Deucher <[email protected]>
No longer needed.
Signed-off-by Alex Deucher <[email protected]>Reviewed-by Jesse Zhang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h | 2 - drivers/gpu/drm/amd/amdgpu/mes_userqueue.c | 53 ---------------------- 2 files changed, 55 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h +0
-2@@ -106,8 +106,6 @@ struct amdgpu_userq_funcs {int (*map)(struct amdgpu_usermode_queue *queue);int (*preempt)(struct amdgpu_usermode_queue *queue);int (*restore)(struct amdgpu_usermode_queue *queue); -int (*detect_and_reset)(struct amdgpu_device *adev, -int queue_type);int (*reset)(struct amdgpu_usermode_queue *queue); };drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +0
-38@@ -219,58 +219,6 @@ static int mes_userq_create_ctx_space(structamdgpu_userq_mgr *uq_mgr, return 0; } -static int mes_userq_detect_and_reset (struct amdgpu_device *adev, -int queue_type) -{ -int db_array_size =amdgpu_mes_get_hung_queue_db_array_size (adev); -struct mes_detect_and_reset_queue_input input; -struct amdgpu_usermode_queue *queue; -unsigned int hung_db_num =0 ; -unsigned long queue_id; -u32 db_array[8 ]; -bool found_hung_queue = false; -int r, i; - -if (db_array_size >8 ) { -dev_err (adev->dev,"DB array size (%d vs 8) too small\n" , - db_array_size); -return -EINVAL ; - } - -memset (&input,0x0 ,sizeof (struct mes_detect_and_reset_queue_input )); - - input.queue_type = queue_type; - -amdgpu_mes_lock (&adev->mes); - r =amdgpu_mes_detect_and_reset_hung_queues (adev, queue_type, false, - &hung_db_num, db_array,0 ); -amdgpu_mes_unlock (&adev->mes); -if (r) { -dev_err (adev->dev,"Failed to detect and reset queues, err (%d)\n" , r); - }else if (hung_db_num) { -xa_for_each (&adev->userq_doorbell_xa, queue_id, queue) { -if (queue->queue_type == queue_type) { -for (i =0 ; i < hung_db_num; i++) { -if (queue->doorbell_index == db_array[i]) { - queue->state =AMDGPU_USERQ_STATE_HUNG ; - found_hung_queue = true; -atomic_inc (&adev- >gpu_reset_counter); -amdgpu_userq_fence_driver_force_completion (queue); - drm_dev_wedged_event(adev_to_drm(adev),
DRM_WEDGE_RECOVERY_NONE, NULL);drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +1
-16- } - } - } - } - } - -if (found_hung_queue) { -/* Resume scheduling after hang recovery */ - r =amdgpu_mes_resume (adev, input.xcc_id); - } - -return r; -} -static int mes_userq_mqd_create (struct amdgpu_usermode_queue *queue, struct drm_amdgpu_userq_in *args_in) { @@ -545,7 +493,6 @@ const struct amdgpu_userq_funcs userq_mes_funcs = { .mqd_destroy = mes_userq_mqd_destroy, .unmap = mes_userq_unmap, .map = mes_userq_map, - .detect_and_reset = mes_userq_detect_and_reset, .preempt = mes_userq_preempt, .restore = mes_userq_restore, .reset = mes_userq_reset, --2.49.0
PATCH v2 24/42 drm/amd/amdgpu/include : update mes api header v11/v12
In reply to Jesse ZhangFrom: Shaoyun Liu <[email protected]>
Update the parameter in SET_HW_RESOURCES API 1. Align with the setting of enable_lr_compute_wa 2. Add enable_compute_pipe_reset to enable pipe reset when compute queue reset failes
v2: add driver flags to track when we enable it
--- drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h | 3 +++ drivers/gpu/drm/amd/include/mes_v11_api_def.h | 5 +++-- drivers/gpu/drm/amd/include/mes_v12_api_def.h | 5 +++-- 3 files changed, 9 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h +3 -0
@@ -168,6 +168,9 @@ struct amdgpu_mes {int master_xcc_ids[AMDGPU_MAX_MES_INST_PIPES ];struct amdgpu_bo *shared_cmd_buf_obj[AMDGPU_MAX_MES_INST_PIPES ];uint64_t shared_cmd_buf_gpu_addr[AMDGPU_MAX_MES_INST_PIPES ]; + +bool compute_pipe_reset_enabled; +bool gfx_pipe_reset_enabled; };struct amdgpu_mes_hung_queue_hqd_info {
drivers/gpu/drm/amd/include/mes_v11_api_def.h +3 -2
@@ -238,8 +238,9 @@ union MESAPI_SET_HW_RESOURCES { uint32_t enable_mes_sch_stb_log : 1; uint32_t limit_single_process : 1; uint32_t is_strix_tmz_wa_enabled :1; - uint32_t enable_lr_compute_wa : 1; - uint32_t reserved : 12; + uint32_t enable_lr_compute_wa : 2; + uint32_t enable_compute_pipe_reset : 1; + uint32_t reserved : 10; };uint32_t uint32_t_all; };
drivers/gpu/drm/amd/include/mes_v12_api_def.h +3 -2
@@ -294,8 +294,9 @@ union MESAPI_SET_HW_RESOURCES { uint32_t limit_single_process : 1; uint32_t unmapped_doorbell_handling: 2; uint32_t enable_mes_fence_int: 1; - uint32_t enable_lr_compute_wa : 1; - uint32_t reserved : 9; + uint32_t enable_lr_compute_wa : 2; + uint32_t enable_compute_pipe_reset : 1; + uint32_t reserved : 7; };uint32_t uint32_all; };
Signature · 1 line
2.49.0
PATCH v2 25/42 drm/amdgpu: Allocate enough space for hpd info on gfx11
In reply to Jesse ZhangFrom: Amber Lin <[email protected]>
MES in newer versions on gfx11 and gfx12 can support queue/pipe reset via MES.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c +1 -1
@@ -217,7 +217,7 @@ int amdgpu_mes_init(struct amdgpu_device *adev)if (r) goto error_doorbell; -if (amdgpu_ip_version (adev,GC_HWIP ,0 ) >=IP_VERSION (12 ,1 ,0 )) { +if (amdgpu_ip_version (adev,GC_HWIP ,0 ) >=IP_VERSION (11 ,0 ,0 )) {/* When queue/pipe reset is done in MES instead of in the * driver, MES passes hung queues information to the driver in * hung_queue_hqd_info. Calculate required space to store this
Signature · 1 line
2.49.0
PATCH v2 26/42 drm/amdkfd: rework MES queue reset sequence
In reply to Jesse ZhangFrom: Alex Deucher <[email protected]>
Call MES with detect only to get the list of hung queues rather than detecting an resetting. Then loop over the bad queues and reset them individually and finally remove them. Skip queues not owned by KFD.
v2: always call resume_all after queue reset
--- .../drm/amd/amdkfd/kfd_device_queue_manager.c | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +14 -7
@@ -445,7 +445,7 @@ static int reset_queues_mes(struct device_queue_manager *dqm)* Passed parameter is for targeting queues not scheduled by MES add_queue. */ r =amdgpu_mes_detect_and_reset_hung_queues (adev,AMDGPU_RING_TYPE_COMPUTE , - false, &num_hung, hung_array,ffs (dqm->dev->xcc_mask) -1 ); + true, &num_hung, hung_array,ffs (dqm->dev->xcc_mask) -1 );if (!num_hung || r) { r = -ENOTRECOVERABLE ;
@@ -467,10 +467,9 @@ static int reset_queues_mes(struct device_queue_manager *dqm) } q =find_queue_by_doorbell_offset (dqm, hung_array[i]); -if (!q) { - r = -ENOTRECOVERABLE ; - goto fail; - } +/* skip queues not owned by KFD */ +if (!q) +continue ; pdd =kfd_get_process_device_data (q->device, q->process);if (!pdd) {
@@ -480,6 +479,10 @@ static int reset_queues_mes(struct device_queue_manager *dqm)pr_warn ("Hang detected doorbell %x pipe %d queue %d type %d\n" , hung_array[i], pipe, queue, queue_type); + r =amdgpu_mes_reset_user_queue (adev, queue_type, hung_array[i], +ffs (dqm->dev->xcc_mask) -1 ); +if (r) + goto fail;/* Proceed remove_queue with reset=true */ remove_queue_mes_on_reset_option (dqm, q, &pdd->qpd, true, false);set_queue_as_reset (dqm, q, &pdd->qpd);
@@ -505,13 +508,17 @@ static int suspend_all_queues_mes(struct device_queue_manager *dqm)up_read (&adev->reset_domain->sem);if (r) { -if (!reset_queues_mes (dqm)) -return 0 ; +if (!reset_queues_mes (dqm)) { + r =0 ; + goto out; + }dev_err (adev->dev,"failed to suspend gangs from MES\n" );dev_err (adev->dev,"MES might be in unrecoverable state, issue a GPU reset\n" );kfd_hws_hang (dqm); } +out: +resume_all_queues_mes (dqm);return r; }
Signature · 1 line
2.49.0
PATCH v2 27/42 drm/amdgpu/gfx: add a helper for MQD restore
In reply to Jesse ZhangFrom: Alex Deucher <[email protected]>
The handling is common so extract it to a helper.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 24 ++++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h | 1 + 2 files changed, 25 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +24 -0
@@ -377,6 +377,30 @@ int amdgpu_gfx_kiq_init(struct amdgpu_device *adev,return 0 ; } +void amdgpu_gfx_mqd_reset_restore (struct amdgpu_ring *ring) +{ +struct amdgpu_device *adev = ring->adev; +int mqd_idx, mqd_size; + +/* restore mqd with the backup copy */ +if (ring->funcs->type ==AMDGPU_RING_TYPE_COMPUTE ) { + mqd_idx = ring - &adev->gfx.compute_ring[0 ]; + mqd_size = adev->mqds[AMDGPU_HW_IP_COMPUTE ].mqd_size; +if (adev->gfx.mec.mqd_backup[mqd_idx]) +memcpy_toio (ring->mqd_ptr, adev->gfx.mec.mqd_backup[mqd_idx], mqd_size); + }else if (ring->funcs->type ==AMDGPU_RING_TYPE_GFX ) { + mqd_size = adev->mqds[AMDGPU_HW_IP_GFX ].mqd_size; + mqd_idx = ring - &adev->gfx.gfx_ring[0 ]; + +if (adev->gfx.me.mqd_backup[mqd_idx]) +memcpy_toio (ring->mqd_ptr, adev->gfx.me.mqd_backup[mqd_idx], mqd_size); + } +/* reset the ring */ + ring->wptr =0 ; +atomic64_set ((atomic64_t *)ring->wptr_cpu_addr,0 ); +amdgpu_ring_clear_ring (ring); +} +/* create MQD for each compute/gfx queue */ int amdgpu_gfx_mqd_sw_init (struct amdgpu_device *adev,unsigned int mqd_size,int xcc_id)
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +1 -0
@@ -586,6 +586,7 @@ void amdgpu_gfx_kiq_fini(struct amdgpu_device *adev, int xcc_id);int amdgpu_gfx_kiq_init (struct amdgpu_device *adev,unsigned hpd_size,int xcc_id); +void amdgpu_gfx_mqd_reset_restore (struct amdgpu_ring *ring);int amdgpu_gfx_mqd_sw_init (struct amdgpu_device *adev,unsigned mqd_size,int xcc_id);void amdgpu_gfx_mqd_sw_fini (struct amdgpu_device *adev,int xcc_id);
Signature · 1 line
2.49.0
PATCH v2 28/42 drm/amdgpu/gfx11: use the new MQD helper for queue reset
In reply to Jesse ZhangFrom: Alex Deucher <[email protected]>
And while we are at it remove the reset parameter as it's no longer needed.
--- drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +9 -16
@@ -4212,13 +4212,13 @@ static int gfx_v11_0_gfx_mqd_init(struct amdgpu_device *adev, void *m,return 0 ; } -static int gfx_v11_0_kgq_init_queue (struct amdgpu_ring *ring,bool reset) +static int gfx_v11_0_kgq_init_queue (struct amdgpu_ring *ring) {struct amdgpu_device *adev = ring->adev;struct v11_gfx_mqd *mqd = ring->mqd_ptr;int mqd_idx = ring - &adev->gfx.gfx_ring[0 ]; -if (!reset && !amdgpu_in_reset (adev) && !adev->in_suspend) { +if (!amdgpu_in_reset (adev) && !adev->in_suspend) {memset ((void *)mqd,0 ,sizeof (*mqd));mutex_lock (&adev->srbm_mutex);soc21_grbm_select (adev, ring->me, ring->pipe, ring->queue,0 );
@@ -4245,7 +4245,7 @@ static int gfx_v11_0_cp_async_gfx_ring_resume(struct amdgpu_device *adev)int r, i;for (i =0 ; i < adev->gfx.num_gfx_rings; i++) { - r =gfx_v11_0_kgq_init_queue (&adev->gfx.gfx_ring[i], false); + r =gfx_v11_0_kgq_init_queue (&adev->gfx.gfx_ring[i]);if (r)return r; }
@@ -4582,13 +4582,13 @@ static int gfx_v11_0_kiq_init_queue(struct amdgpu_ring *ring)return 0 ; } -static int gfx_v11_0_kcq_init_queue (struct amdgpu_ring *ring,bool reset) +static int gfx_v11_0_kcq_init_queue (struct amdgpu_ring *ring) {struct amdgpu_device *adev = ring->adev;struct v11_compute_mqd *mqd = ring->mqd_ptr;int mqd_idx = ring - &adev->gfx.compute_ring[0 ]; -if (!reset && !amdgpu_in_reset (adev) && !adev->in_suspend) { +if (!amdgpu_in_reset (adev) && !adev->in_suspend) {memset ((void *)mqd,0 ,sizeof (*mqd));mutex_lock (&adev->srbm_mutex);soc21_grbm_select (adev, ring->me, ring->pipe, ring->queue,0 );
@@ -4625,7 +4625,7 @@ static int gfx_v11_0_kcq_resume(struct amdgpu_device *adev)gfx_v11_0_cp_compute_enable (adev, true);for (i =0 ; i < adev->gfx.num_compute_rings; i++) { - r =gfx_v11_0_kcq_init_queue (&adev->gfx.compute_ring[i], false); + r =gfx_v11_0_kcq_init_queue (&adev->gfx.compute_ring[i]);if (r)return r; }
@@ -6790,11 +6790,7 @@ static int gfx_v11_0_reset_kgq(struct amdgpu_ring *ring,return r;if (use_mmio) { - r =gfx_v11_0_kgq_init_queue (ring, true); -if (r) { -dev_err (adev->dev,"failed to init kgq\n" ); -return r; - } +amdgpu_gfx_mqd_reset_restore (ring); r =amdgpu_mes_map_legacy_queue (adev, ring,0 );if (r) {
@@ -6821,11 +6817,8 @@ static int gfx_v11_0_reset_kcq(struct amdgpu_ring *ring,return r;if (use_mmio) { - r =gfx_v11_0_kcq_init_queue (ring, true); -if (r) { -dev_err (adev->dev,"fail to init kcq\n" ); -return r; - } +amdgpu_gfx_mqd_reset_restore (ring); + r =amdgpu_mes_map_legacy_queue (adev, ring,0 );if (r) {dev_err (adev->dev,"failed to remap kcq\n" );
Signature · 1 line
2.49.0
PATCH v2 29/42 drm/amdgpu/gfx12: use the new MQD helper for queue reset
In reply to Jesse ZhangFrom: Alex Deucher <[email protected]>
And while we are at it remove the reset parameter as it's no longer needed.
--- drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +9 -16
@@ -3071,13 +3071,13 @@ static int gfx_v12_0_gfx_mqd_init(struct amdgpu_device *adev, void *m,return 0 ; } -static int gfx_v12_0_kgq_init_queue (struct amdgpu_ring *ring,bool reset) +static int gfx_v12_0_kgq_init_queue (struct amdgpu_ring *ring) {struct amdgpu_device *adev = ring->adev;struct v12_gfx_mqd *mqd = ring->mqd_ptr;int mqd_idx = ring - &adev->gfx.gfx_ring[0 ]; -if (!reset && !amdgpu_in_reset (adev) && !adev->in_suspend) { +if (!amdgpu_in_reset (adev) && !adev->in_suspend) {memset ((void *)mqd,0 ,sizeof (*mqd));mutex_lock (&adev->srbm_mutex);soc24_grbm_select (adev, ring->me, ring->pipe, ring->queue,0 );
@@ -3104,7 +3104,7 @@ static int gfx_v12_0_cp_async_gfx_ring_resume(struct amdgpu_device *adev)int i, r;for (i =0 ; i < adev->gfx.num_gfx_rings; i++) { - r =gfx_v12_0_kgq_init_queue (&adev->gfx.gfx_ring[i], false); + r =gfx_v12_0_kgq_init_queue (&adev->gfx.gfx_ring[i]);if (r)return r; }
@@ -3441,13 +3441,13 @@ static int gfx_v12_0_kiq_init_queue(struct amdgpu_ring *ring)return 0 ; } -static int gfx_v12_0_kcq_init_queue (struct amdgpu_ring *ring,bool reset) +static int gfx_v12_0_kcq_init_queue (struct amdgpu_ring *ring) {struct amdgpu_device *adev = ring->adev;struct v12_compute_mqd *mqd = ring->mqd_ptr;int mqd_idx = ring - &adev->gfx.compute_ring[0 ]; -if (!reset && !amdgpu_in_reset (adev) && !adev->in_suspend) { +if (!amdgpu_in_reset (adev) && !adev->in_suspend) {memset ((void *)mqd,0 ,sizeof (*mqd));mutex_lock (&adev->srbm_mutex);soc24_grbm_select (adev, ring->me, ring->pipe, ring->queue,0 );
@@ -3485,7 +3485,7 @@ static int gfx_v12_0_kcq_resume(struct amdgpu_device *adev)gfx_v12_0_cp_compute_enable (adev, true);for (i =0 ; i < adev->gfx.num_compute_rings; i++) { - r =gfx_v12_0_kcq_init_queue (&adev->gfx.compute_ring[i], false); + r =gfx_v12_0_kcq_init_queue (&adev->gfx.compute_ring[i]);if (r)return r; }
@@ -5226,11 +5226,7 @@ static int gfx_v12_0_reset_kgq(struct amdgpu_ring *ring,return r;if (use_mmio) { - r =gfx_v12_0_kgq_init_queue (ring, true); -if (r) { -dev_err (adev->dev,"failed to init kgq\n" ); -return r; - } +amdgpu_gfx_mqd_reset_restore (ring); r =amdgpu_mes_map_legacy_queue (adev, ring,0 );if (r) {
@@ -5257,11 +5253,8 @@ static int gfx_v12_0_reset_kcq(struct amdgpu_ring *ring,return r;if (use_mmio) { - r =gfx_v12_0_kcq_init_queue (ring, true); -if (r) { -dev_err (adev->dev,"failed to init kcq\n" ); -return r; - } +amdgpu_gfx_mqd_reset_restore (ring); + r =amdgpu_mes_map_legacy_queue (adev, ring,0 );if (r) {dev_err (adev->dev,"failed to remap kcq\n" );
Signature · 1 line
2.49.0
PATCH v2 30/42 drm/amdgpu/gfx11: unmap the queue via MES on reset for MMIO path
In reply to Jesse ZhangFrom: Alex Deucher <[email protected]>
To keep MES in sync.
--- drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +8 -0
@@ -6790,6 +6790,10 @@ static int gfx_v11_0_reset_kgq(struct amdgpu_ring *ring,return r;if (use_mmio) { + r =amdgpu_mes_unmap_legacy_queue (adev, ring, +RESET_QUEUES ,0 ,0 ,0 ); +if (r) +return r;amdgpu_gfx_mqd_reset_restore (ring); r =amdgpu_mes_map_legacy_queue (adev, ring,0 );
@@ -6817,6 +6821,10 @@ static int gfx_v11_0_reset_kcq(struct amdgpu_ring *ring,return r;if (use_mmio) { + r =amdgpu_mes_unmap_legacy_queue (adev, ring, +RESET_QUEUES ,0 ,0 ,0 ); +if (r) +return r;amdgpu_gfx_mqd_reset_restore (ring); r =amdgpu_mes_map_legacy_queue (adev, ring,0 );
Signature · 1 line
2.49.0
PATCH v2 31/42 drm/amdgpu/gfx12: unmap the queue via MES on reset for MMIO path
In reply to Jesse ZhangFrom: Alex Deucher <[email protected]>
To keep MES in sync.
--- drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +8 -0
@@ -5226,6 +5226,10 @@ static int gfx_v12_0_reset_kgq(struct amdgpu_ring *ring,return r;if (use_mmio) { + r =amdgpu_mes_unmap_legacy_queue (adev, ring, +RESET_QUEUES ,0 ,0 ,0 ); +if (r) +return r;amdgpu_gfx_mqd_reset_restore (ring); r =amdgpu_mes_map_legacy_queue (adev, ring,0 );
@@ -5253,6 +5257,10 @@ static int gfx_v12_0_reset_kcq(struct amdgpu_ring *ring,return r;if (use_mmio) { + r =amdgpu_mes_unmap_legacy_queue (adev, ring, +RESET_QUEUES ,0 ,0 ,0 ); +if (r) +return r;amdgpu_gfx_mqd_reset_restore (ring); r =amdgpu_mes_map_legacy_queue (adev, ring,0 );
Signature · 1 line
2.49.0
PATCH v2 32/42 drm/amdgpu: store whether to use MMIO or MES for reset
In reply to Jesse ZhangFrom: Alex Deucher <[email protected]>
Separate settings for gfx (ME) and compute (MEC).
Use this rather than explicitly specifying it.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h | 2 ++ drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 7 +++++-- drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c | 7 +++++-- 3 files changed, 12 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +2 -0
@@ -116,6 +116,7 @@ struct amdgpu_mec {u32 num_pipe_per_mec;u32 num_queue_per_pipe;void *mqd_backup[AMDGPU_MAX_COMPUTE_RINGS *AMDGPU_MAX_GC_INSTANCES ]; +bool use_mmio_for_reset; };struct amdgpu_mec_bitmap {
@@ -401,6 +402,7 @@ struct amdgpu_me {uint32_t num_pipe_per_me;uint32_t num_queue_per_pipe;void *mqd_backup[AMDGPU_MAX_GFX_RINGS ]; +bool use_mmio_for_reset;/* These are the resources for which amdgpu takes ownership */ DECLARE_BITMAP (queue_bitmap,AMDGPU_MAX_GFX_QUEUES );
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +5 -2
@@ -1905,6 +1905,9 @@ static int gfx_v11_0_sw_init(struct amdgpu_ip_block *ip_block)if (r)return r; + adev->gfx.me.use_mmio_for_reset = false; + adev->gfx.mec.use_mmio_for_reset = true; +return 0 ; }
@@ -6780,7 +6783,7 @@ static int gfx_v11_0_reset_kgq(struct amdgpu_ring *ring, struct amdgpu_fence *timedout_fence) {struct amdgpu_device *adev = ring->adev; -bool use_mmio = false; +bool use_mmio = adev->gfx.me.use_mmio_for_reset;int r;amdgpu_ring_reset_helper_begin (ring, timedout_fence);
@@ -6811,7 +6814,7 @@ static int gfx_v11_0_reset_kcq(struct amdgpu_ring *ring, struct amdgpu_fence *timedout_fence) {struct amdgpu_device *adev = ring->adev; -bool use_mmio = true; +bool use_mmio = adev->gfx.mec.use_mmio_for_reset;int r =0 ;amdgpu_ring_reset_helper_begin (ring, timedout_fence);
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +5 -2
@@ -1603,6 +1603,9 @@ static int gfx_v12_0_sw_init(struct amdgpu_ip_block *ip_block)if (r)return r; + adev->gfx.me.use_mmio_for_reset = false; + adev->gfx.mec.use_mmio_for_reset = true; +return 0 ; }
@@ -5216,7 +5219,7 @@ static int gfx_v12_0_reset_kgq(struct amdgpu_ring *ring, struct amdgpu_fence *timedout_fence) {struct amdgpu_device *adev = ring->adev; -bool use_mmio = false; +bool use_mmio = adev->gfx.me.use_mmio_for_reset;int r;amdgpu_ring_reset_helper_begin (ring, timedout_fence);
@@ -5247,7 +5250,7 @@ static int gfx_v12_0_reset_kcq(struct amdgpu_ring *ring, struct amdgpu_fence *timedout_fence) {struct amdgpu_device *adev = ring->adev; -bool use_mmio = true; +bool use_mmio = adev->gfx.mec.use_mmio_for_reset;int r;amdgpu_ring_reset_helper_begin (ring, timedout_fence);
Signature · 1 line
2.49.0
PATCH v2 33/42 drm/amdgpu: Use a common KGQ and KCQ reset helper for gfx11/12
In reply to Jesse ZhangFrom: Alex Deucher <[email protected]>
They are all the same so use a common implementation.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 33 +++++++++++++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h | 6 +++- drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 46 ++----------------------- drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c | 46 ++----------------------- 4 files changed, 41 insertions(+), 90 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +32 -1
@@ -377,7 +377,7 @@ int amdgpu_gfx_kiq_init(struct amdgpu_device *adev,return 0 ; } -void amdgpu_gfx_mqd_reset_restore (struct amdgpu_ring *ring) +static void amdgpu_gfx_mqd_reset_restore (struct amdgpu_ring *ring) {struct amdgpu_device *adev = ring->adev;int mqd_idx, mqd_size;
@@ -1970,6 +1970,37 @@ static ssize_t amdgpu_gfx_get_compute_reset_mask(struct device *dev,return amdgpu_show_reset_mask (buf, adev->gfx.compute_supported_reset); } +int amdgpu_gfx_mes_reset_queue (struct amdgpu_ring *ring, +unsigned int vmid, +struct amdgpu_fence *timedout_fence, +bool use_mmio) +{ +struct amdgpu_device *adev = ring->adev; +int r; + +amdgpu_ring_reset_helper_begin (ring, timedout_fence); + + r =amdgpu_mes_reset_legacy_queue (ring->adev, ring, vmid, use_mmio,0 ); +if (r) +return r; + +if (use_mmio) { + r =amdgpu_mes_unmap_legacy_queue (adev, ring, +RESET_QUEUES ,0 ,0 ,0 ); +if (r) +return r; +amdgpu_gfx_mqd_reset_restore (ring); + + r =amdgpu_mes_map_legacy_queue (adev, ring,0 ); +if (r) { +dev_err (adev->dev,"failed to remap kgq\n" ); +return r; + } + } + +return amdgpu_ring_reset_helper_end (ring, timedout_fence); +} + static DEVICE_ATTR(run_cleaner_shader, 0200, NULL, amdgpu_gfx_set_run_cleaner_shader);
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +5 -1
@@ -588,7 +588,6 @@ void amdgpu_gfx_kiq_fini(struct amdgpu_device *adev, int xcc_id);int amdgpu_gfx_kiq_init (struct amdgpu_device *adev,unsigned hpd_size,int xcc_id); -void amdgpu_gfx_mqd_reset_restore (struct amdgpu_ring *ring);int amdgpu_gfx_mqd_sw_init (struct amdgpu_device *adev,unsigned mqd_size,int xcc_id);void amdgpu_gfx_mqd_sw_fini (struct amdgpu_device *adev,int xcc_id);
@@ -669,6 +668,11 @@ void amdgpu_debugfs_compute_sched_mask_init(struct amdgpu_device *adev);int amdgpu_gfx_ring_preempt_ib (struct amdgpu_ring *ring); +int amdgpu_gfx_mes_reset_queue (struct amdgpu_ring *ring, +unsigned int vmid, +struct amdgpu_fence *timedout_fence, +bool use_mmio); +static inline const char *amdgpu_gfx_compute_mode_desc (int mode) {switch (mode) {
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +2 -44
60 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +2 -44
60 lines not on this page · raw message
Signature · 1 line
2.49.0
PATCH v2 34/42 drm/amdkfd: split out mes queue reset sequence into standalone function
In reply to Jesse ZhangFrom: Alex Deucher <[email protected]>
No intended functional change.
--- .../drm/amd/amdkfd/kfd_device_queue_manager.c | 48 ++++++++++++------- 1 file changed, 31 insertions(+), 17 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +31 -17
@@ -407,6 +407,32 @@ static int add_all_kfd_queues_mes(struct device_queue_manager *dqm)return retval; } +static int reset_queue_mes (struct device_queue_manager *dqm,struct queue *q, +int queue_type,int pipe,int queue,unsigned int db) +{ +struct amdgpu_device *adev = (struct amdgpu_device *)dqm->dev->adev; +struct kfd_process_device *pdd; +bool use_mmio = false; +int r; + + pdd =kfd_get_process_device_data (q->device, q->process); +if (!pdd) +return -ENODEV ; + +if (use_mmio) + r =amdgpu_mes_reset_queue_mmio (adev, queue_type,0 ,1 , pipe, queue, +ffs (dqm->dev->xcc_mask) -1 ); +else + r =amdgpu_mes_reset_user_queue (adev, queue_type, db, +ffs (dqm->dev->xcc_mask) -1 ); +if (r) +return r; +/* Proceed remove_queue with reset=true */ +remove_queue_mes_on_reset_option (dqm, q, &pdd->qpd, true, false); +set_queue_as_reset (dqm, q, &pdd->qpd); +return 0 ; +} +static int reset_queues_mes (struct device_queue_manager *dqm) {struct amdgpu_device *adev = (struct amdgpu_device *)dqm->dev->adev;
@@ -414,7 +440,6 @@ static int reset_queues_mes(struct device_queue_manager *dqm)int num_hung =0 , r =0 , i, pipe, queue, queue_type;u32 *hung_array = dqm->hung_db_array;struct amdgpu_mes_hung_queue_hqd_info *hqd_info = dqm->hqd_info; -struct kfd_process_device *pdd;struct queue *q;if (!amdgpu_mes_queue_reset_by_mes_supported (adev)) {
@@ -468,24 +493,13 @@ static int reset_queues_mes(struct device_queue_manager *dqm) q =find_queue_by_doorbell_offset (dqm, hung_array[i]);/* skip queues not owned by KFD */ -if (!q) +if (!q) {continue ; - - pdd =kfd_get_process_device_data (q->device, q->process); -if (!pdd) { - r = -ENODEV ; - goto fail; + }else { + r =reset_queue_mes (dqm, q, queue_type, pipe, queue, hung_array[i]); +if (r) + goto fail; } - -pr_warn ("Hang detected doorbell %x pipe %d queue %d type %d\n" , - hung_array[i], pipe, queue, queue_type); - r =amdgpu_mes_reset_user_queue (adev, queue_type, hung_array[i], -ffs (dqm->dev->xcc_mask) -1 ); -if (r) - goto fail; -/* Proceed remove_queue with reset=true */ -remove_queue_mes_on_reset_option (dqm, q, &pdd->qpd, true, false); -set_queue_as_reset (dqm, q, &pdd->qpd); } dqm->detect_hang_count = num_hung;
Signature · 1 line
2.49.0
PATCH v2 35/42 drm/amdkfd: plumb a helper to reset a KFD user queue
In reply to Jesse ZhangFrom: Alex Deucher <[email protected]>
Can be called from KGD.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c | 14 +++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h | 16 ++++++++++++- drivers/gpu/drm/amd/amdkfd/kfd_device.c | 24 +++++++++++++++++++ .../drm/amd/amdkfd/kfd_device_queue_manager.c | 11 +++++++++ .../drm/amd/amdkfd/kfd_device_queue_manager.h | 2 ++ 5 files changed, 66 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +14 -0
@@ -942,3 +942,17 @@ int amdgpu_amdkfd_config_sq_perfmon(struct amdgpu_device *adev, uint32_t xcp_id,return r; } + +/* Reset an MES queue */ +int amdgpu_amdkfd_reset_mes_queue (struct amdgpu_device *adev, +uint32_t node_id, +int queue_type, +int pipe,int queue, +unsigned int db) +{ +if (!adev->kfd.init_complete) +return 0 ; + +return kgd2kfd_reset_mes_queue (adev->kfd.dev, node_id, queue_type, + pipe, queue, db); +}
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +15 -1
@@ -275,7 +275,11 @@ int amdgpu_amdkfd_stop_sched(struct amdgpu_device *adev, uint32_t node_id);int amdgpu_amdkfd_config_sq_perfmon (struct amdgpu_device *adev,uint32_t xcp_id,bool core_override_enable,bool reg_override_enable,bool perfmon_override_enable);bool amdgpu_amdkfd_compute_active (struct amdgpu_device *adev,uint32_t node_id); - +int amdgpu_amdkfd_reset_mes_queue (struct amdgpu_device *adev, +uint32_t node_id, +int queue_type, +int pipe,int queue, +unsigned int db);/* Read user wptr from a specified user address space with page fault * disabled. The memory must be pinned and mapped to the hardware when
@@ -446,6 +450,9 @@ bool kgd2kfd_vmfault_fast_path(struct amdgpu_device *adev, struct amdgpu_iv_entr bool retry_fault);void kgd2kfd_lock_kfd (void );void kgd2kfd_teardown_processes (struct amdgpu_device *adev); +int kgd2kfd_reset_mes_queue (struct kfd_dev *kfd,uint32_t node_id, +int queue_type,int pipe,int queue, +unsigned int db);#else static inline int kgd2kfd_init (void )
@@ -576,5 +583,12 @@ static inline void kgd2kfd_teardown_processes(struct amdgpu_device *adev) { } +static inline int kgd2kfd_reset_mes_queue (struct kfd_dev *kfd,uint32_t node_id, +int queue_type,int pipe,int queue, +unsigned int db) +{ +return 0 ; +} +#endif #endif /* AMDGPU_AMDKFD_H_INCLUDED */
drivers/gpu/drm/amd/amdkfd/kfd_device.c +24 -0
@@ -1793,6 +1793,30 @@ void kgd2kfd_teardown_processes(struct amdgpu_device *adev)cond_resched (); } +int kgd2kfd_reset_mes_queue (struct kfd_dev *kfd,uint32_t node_id, +int queue_type,int pipe,int queue, +unsigned int db) +{ +struct kfd_node *node; +int ret; + +if (!kfd->init_complete) +return 0 ; + +if (node_id >= kfd->num_nodes) { +dev_warn (kfd->adev->dev,"Invalid node ID: %u exceeds %u\n" , + node_id, kfd->num_nodes -1 ); +return -EINVAL ; + } + node = kfd->nodes[node_id]; + + ret =kfd_reset_queue_mes (node->dqm, queue_type, pipe, queue, db); +if (ret) +dev_err (kfd_device,"Error resetting queue\n" ); + +return ret; +} +#if defined(CONFIG_DEBUG_FS )/* This function will send a package to HIQ to hang the HWS
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +11 -0
@@ -433,6 +433,17 @@ static int reset_queue_mes(struct device_queue_manager *dqm, struct queue *q,return 0 ; } +int kfd_reset_queue_mes (struct device_queue_manager *dqm,int queue_type, +int pipe,int queue,unsigned int db) +{ +struct queue *q; + + q =find_queue_by_doorbell_offset (dqm, db); +if (!q) +return 0 ; +return reset_queue_mes (dqm, q, queue_type, pipe, queue, db); +} +static int reset_queues_mes (struct device_queue_manager *dqm) {struct amdgpu_device *adev = (struct amdgpu_device *)dqm->dev->adev;
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.h +2 -0
@@ -333,6 +333,8 @@ int debug_refresh_runlist(struct device_queue_manager *dqm);bool kfd_dqm_is_queue_in_process (struct device_queue_manager *dqm,struct qcm_process_device *qpd,int doorbell_off,u32 *queue_format); +int kfd_reset_queue_mes (struct device_queue_manager *dqm,int queue_type, +int pipe,int queue,unsigned int db);static inline unsigned int get_sh_mem_bases_32 (struct kfd_process_device *pdd) {
Signature · 1 line
2.49.0
PATCH v2 36/42 drm/amdgpu/userq: add MES userq reset helper
In reply to Jesse ZhangFrom: Alex Deucher <[email protected]>
Will be used by the common compute queue reset handler.
--- drivers/gpu/drm/amd/amdgpu/mes_userqueue.c | 39 +++++++++++++++++++++- drivers/gpu/drm/amd/amdgpu/mes_userqueue.h | 9 +++++ 2 files changed, 47 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +38 -1
@@ -177,7 +177,7 @@ static int mes_userq_unmap(struct amdgpu_usermode_queue *queue)return r; } -static int mes_userq_reset (struct amdgpu_usermode_queue *queue) +int mes_userq_reset (struct amdgpu_usermode_queue *queue) {struct amdgpu_userq_mgr *uq_mgr = queue->userq_mgr;struct amdgpu_device *adev = uq_mgr->adev;
@@ -197,6 +197,43 @@ static int mes_userq_reset(struct amdgpu_usermode_queue *queue)return mes_userq_unmap (queue); } +int mes_userq_reset_queue (struct amdgpu_device *adev, +struct amdgpu_usermode_queue *guilty_uq, +int queue_type, +unsigned int pipe, +unsigned int queue, +unsigned int db) +{ +struct amdgpu_usermode_queue *uq; +bool use_mmio = false; +unsigned long uq_id; +int r; + +xa_for_each (&adev->userq_doorbell_xa, uq_id, uq) { +if (uq->queue_type == queue_type) { +if (uq == guilty_uq) +continue ; +if (uq->doorbell_index == db) { + uq->state =AMDGPU_USERQ_STATE_HUNG ; +if (use_mmio) + r =amdgpu_mes_reset_queue_mmio (adev, queue_type,0 ,1 , pipe, queue,0 ); +else + r =amdgpu_mes_reset_user_queue (adev, queue_type, db,0 ); +if (r) +return r; + r =mes_userq_unmap (uq); +if (r) +return r; +atomic_inc (&adev->gpu_reset_counter); +amdgpu_userq_fence_driver_force_completion (uq); +drm_dev_wedged_event (adev_to_drm (adev),DRM_WEDGE_RECOVERY_NONE ,NULL ); +break ; + } + } + } +return 0 ; +} +static int mes_userq_create_ctx_space (struct amdgpu_userq_mgr *uq_mgr,struct amdgpu_usermode_queue *queue,struct drm_amdgpu_userq_in *mqd_user)
drivers/gpu/drm/amd/amdgpu/mes_userqueue.h +9 -0
@@ -27,4 +27,13 @@#include "amdgpu_userq.h" extern const struct amdgpu_userq_funcs userq_mes_funcs; + +int mes_userq_reset (struct amdgpu_usermode_queue *queue); +int mes_userq_reset_queue (struct amdgpu_device *adev, +struct amdgpu_usermode_queue *guilty_uq, +int queue_type, +unsigned int pipe, +unsigned int queue, +unsigned int db); +#endif
Signature · 1 line
2.49.0
PATCH v2 37/42 drm/amdgpu/gfx: add a common helper to handle MES compute resets
In reply to Jesse ZhangFrom: Alex Deucher <[email protected]>
Add helpers to handle MES compute queue resets when multiple queues are affected. Can you be used by both KGD and KFD.
v2: sqaush in updates
v3: squash in userq updates
--- drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 140 +++++++++++++++++++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h | 9 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c | 6 + drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 2 + drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c | 2 + drivers/gpu/drm/amd/amdgpu/gfx_v12_1.c | 2 + 6 files changed, 160 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +139 -1
@@ -34,6 +34,7 @@#include "amdgpu_xcp.h" #include "amdgpu_xgmi.h" #include "amdgpu_mes.h" +#include "mes_userqueue.h" #include "nvd.h" /* delay 0.1 second to enable gfx off feature */
@@ -1976,15 +1977,25 @@ int amdgpu_gfx_mes_reset_queue(struct amdgpu_ring *ring, bool use_mmio) {struct amdgpu_device *adev = ring->adev; +bool reinit_queue;int r; +if ((ring->funcs->type ==AMDGPU_RING_TYPE_COMPUTE ) && + adev->mes.compute_pipe_reset_enabled) + reinit_queue = true; +else if ((ring->funcs->type ==AMDGPU_RING_TYPE_GFX ) && + adev->mes.gfx_pipe_reset_enabled) + reinit_queue = true; +else + reinit_queue = use_mmio; +amdgpu_ring_reset_helper_begin (ring, timedout_fence); r =amdgpu_mes_reset_legacy_queue (ring->adev, ring, vmid, use_mmio,0 );if (r)return r; -if (use_mmio) { +if (reinit_queue) { r =amdgpu_mes_unmap_legacy_queue (adev, ring,RESET_QUEUES ,0 ,0 ,0 );if (r)
@@ -2159,6 +2170,133 @@ void amdgpu_gfx_sysfs_fini(struct amdgpu_device *adev) } } +static void amdgpu_gfx_reset_start_compute_scheds (struct amdgpu_device *adev, +struct amdgpu_ring *guilty_ring) +{ +struct amdgpu_ring *ring; +int i; + +for (i =0 ; i < adev->gfx.num_compute_rings; i++) { + ring = &adev->gfx.compute_ring[i]; +if (ring == guilty_ring) +continue ; +drm_sched_wqueue_start (&ring->sched); + } +} + +static void amdgpu_gfx_reset_stop_compute_scheds (struct amdgpu_device *adev, +struct amdgpu_ring *guilty_ring) +{ +struct amdgpu_ring *ring; +int i; + +for (i =0 ; i < adev->gfx.num_compute_rings; i++) { + ring = &adev->gfx.compute_ring[i]; +if (ring == guilty_ring) +continue ; +drm_sched_wqueue_stop (&ring->sched); + } +} + +static int amdgpu_gfx_reset_mes_kcq (struct amdgpu_device *adev, +struct amdgpu_ring *guilty_ring, +unsigned int db) +{ +bool use_mmio = adev->gfx.mec.use_mmio_for_reset; +struct amdgpu_fence *fence; +struct amdgpu_ring *ring; +int i, r; + +for (i =0 ; i < adev->gfx.num_compute_rings; i++) { + ring = &adev->gfx.compute_ring[i]; +if (ring == guilty_ring) +continue ; +if (ring->doorbell_index == db) { + fence =amdgpu_ring_find_guilty_fence (ring); + r =amdgpu_gfx_mes_reset_queue (ring,0 , fence, use_mmio); +if (r) +return r; +break ; + } + } +return 0 ; +} + +int amdgpu_gfx_reset_mes_compute (struct amdgpu_device *adev, +struct amdgpu_ring *ring, +struct amdgpu_fence *guilty_fence, +struct amdgpu_usermode_queue *uq, +unsigned int *hung_queue_count) +{ +struct amdgpu_mes_hung_queue_hqd_info *hqd_info = + (struct amdgpu_mes_hung_queue_hqd_info *) + &adev->gfx.mec.mes_hung_db_array[adev->mes.hung_queue_hqd_info_offset]; +int i, r, pipe, queue, queue_type; +unsigned int num_hung =0 ; +bool use_mmio = adev->gfx.mec.use_mmio_for_reset; + +guard (mutex)(&adev->gfx.mec.reset_mutex); +/* stop the drm schedulers for all compute queues */ +amdgpu_gfx_reset_stop_compute_scheds (adev, ring); +/* suspend all will determine which queues are hung. +* reset detect will return the array of bad queue doorbells +*/ + r =amdgpu_mes_suspend (adev,0 ); +/* if suspend all success, it should no hang queue */ +if (!r) +/* always reset the KCQ/userq since we need to signal the fence +* and we could be stuck in a loop which is preemptable. +*/ + goto fence_reset; + r =amdgpu_mes_detect_and_reset_hung_queues (adev,AMDGPU_RING_TYPE_COMPUTE , + true, &num_hung, adev->gfx.mec.mes_hung_db_array,0 ); +if (r) + goto out; +if (hung_queue_count) + *hung_queue_count = num_hung; + +fence_reset: +/* reset the queue this came from if specified */ +if (ring) { + r =amdgpu_gfx_mes_reset_queue (ring,0 , guilty_fence, use_mmio); +if (r) + goto out; + } +if (uq) { + r =mes_userq_reset (uq); +if (r) + goto out; + } +for (i =0 ; i < num_hung; i++) { + pipe = hqd_info[i].pipe_index; + queue = hqd_info[i].queue_index; + queue_type = hqd_info[i].queue_type; + +/* reset any KCQs */ + r =amdgpu_gfx_reset_mes_kcq (adev, ring, + adev->gfx.mec.mes_hung_db_array[i]); +if (r) + goto out; +/* reset any KFD queues */ + r =amdgpu_amdkfd_reset_mes_queue (adev,0 , queue_type, pipe, queue, + adev->gfx.mec.mes_hung_db_array[i]); +if (r) + goto out; +/* reset KGD user queues */ + r =mes_userq_reset_queue (adev, uq, queue_type, pipe, queue, + adev->gfx.mec.mes_hung_db_array[i]); +if (r) + goto out; + } +out: +/* resume all will enable the non-hung queues */ +amdgpu_mes_resume (adev,0 ); +if (!r) +amdgpu_gfx_reset_start_compute_scheds (adev, ring); + +return r; +} +int amdgpu_gfx_cleaner_shader_sw_init (struct amdgpu_device *adev,unsigned int cleaner_shader_size) {
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +9 -0
@@ -36,6 +36,8 @@#include "amdgpu_ring_mux.h" #include "amdgpu_xcp.h" +struct amdgpu_usermode_queue ; +/* GFX current status */ #define AMDGPU_GFX_NORMAL_MODE 0x00000000L#define AMDGPU_GFX_SAFE_MODE 0x00000001L
@@ -117,6 +119,8 @@ struct amdgpu_mec {u32 num_queue_per_pipe;void *mqd_backup[AMDGPU_MAX_COMPUTE_RINGS *AMDGPU_MAX_GC_INSTANCES ];bool use_mmio_for_reset; +u32 *mes_hung_db_array; +struct mutex reset_mutex; };struct amdgpu_mec_bitmap {
@@ -642,6 +646,11 @@ int amdgpu_gfx_poison_consumption_handler(struct amdgpu_device *adev,bool amdgpu_gfx_is_master_xcc (struct amdgpu_device *adev,int xcc_id);int amdgpu_gfx_sysfs_init (struct amdgpu_device *adev);void amdgpu_gfx_sysfs_fini (struct amdgpu_device *adev); +int amdgpu_gfx_reset_mes_compute (struct amdgpu_device *adev, +struct amdgpu_ring *ring, +struct amdgpu_fence *guilty_fence, +struct amdgpu_usermode_queue *uq, +unsigned int *hung_queue_count); void amdgpu_gfx_ras_error_func(struct amdgpu_device *adev, void *ras_error_status, void (*func)(struct amdgpu_device *adev, void *ras_error_status,
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c +6 -0
@@ -252,6 +252,10 @@ int amdgpu_mes_init(struct amdgpu_device *adev) } } + adev->gfx.mec.mes_hung_db_array = +kcalloc (amdgpu_mes_get_hung_queue_db_array_size (adev), +sizeof (u32),GFP_KERNEL ); +return 0 ; error_doorbell:
@@ -279,6 +283,8 @@ void amdgpu_mes_fini(struct amdgpu_device *adev)int i;int num_xcc = adev->gfx.xcc_mask ?NUM_XCC (adev->gfx.xcc_mask) :1 ; +kfree (adev->gfx.mec.mes_hung_db_array); +amdgpu_bo_free_kernel (&adev->mes.event_log_gpu_obj, &adev->mes.event_log_gpu_addr, &adev->mes.event_log_cpu_addr);
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +2 -0
@@ -1908,6 +1908,8 @@ static int gfx_v11_0_sw_init(struct amdgpu_ip_block *ip_block) adev->gfx.me.use_mmio_for_reset = false; adev->gfx.mec.use_mmio_for_reset = true; +mutex_init (&adev->gfx.mec.reset_mutex); +return 0 ; }
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +2 -0
@@ -1606,6 +1606,8 @@ static int gfx_v12_0_sw_init(struct amdgpu_ip_block *ip_block) adev->gfx.me.use_mmio_for_reset = false; adev->gfx.mec.use_mmio_for_reset = true; +mutex_init (&adev->gfx.mec.reset_mutex); +return 0 ; }
drivers/gpu/drm/amd/amdgpu/gfx_v12_1.c +2 -0
@@ -1287,6 +1287,8 @@ static int gfx_v12_1_sw_init(struct amdgpu_ip_block *ip_block)if (r)return r; +mutex_init (&adev->gfx.mec.reset_mutex); +return 0 ; }
Signature · 1 line
2.49.0
PATCH v2 38/42 drm/amdgpu: use a single entry point for mes compute reset
In reply to Jesse ZhangFrom: Alex Deucher <[email protected]>
When we reset MES queues we need to coordinate across KGD and KFD. Use a single function to handle the queue resets across KFD and KGD.
v2: squash in fixes for userqs
--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 7 +- drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 3 +- drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c | 3 +- drivers/gpu/drm/amd/amdgpu/mes_userqueue.c | 2 +- .../drm/amd/amdkfd/kfd_device_queue_manager.c | 75 ++++--------------- 5 files changed, 22 insertions(+), 68 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +6 -1
@@ -138,7 +138,12 @@ static void amdgpu_userq_hang_detect_work(struct work_struct *work)if (amdgpu_userq_is_reset_type_supported (adev, queue->queue_type,AMDGPU_RESET_TYPE_PER_QUEUE )) { -int r = userq_funcs->reset (queue); +int r; + +if (queue->queue_type ==AMDGPU_HW_IP_COMPUTE ) + r =amdgpu_gfx_reset_mes_compute (adev,NULL ,NULL ,NULL ,NULL ); +else + r = userq_funcs->reset (queue);if (r) gpu_reset = true; }else {
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +1 -2
@@ -6795,9 +6795,8 @@ static int gfx_v11_0_reset_kcq(struct amdgpu_ring *ring, struct amdgpu_fence *timedout_fence) {struct amdgpu_device *adev = ring->adev; -bool use_mmio = adev->gfx.mec.use_mmio_for_reset; -return amdgpu_gfx_mes_reset_queue (ring, vmid, timedout_fence, use_mmio); +return amdgpu_gfx_reset_mes_compute (adev, ring, timedout_fence,NULL ,NULL ); }static void gfx_v11_ip_print (struct amdgpu_ip_block *ip_block,struct drm_printer *p)
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +1 -2
@@ -5231,9 +5231,8 @@ static int gfx_v12_0_reset_kcq(struct amdgpu_ring *ring, struct amdgpu_fence *timedout_fence) {struct amdgpu_device *adev = ring->adev; -bool use_mmio = adev->gfx.mec.use_mmio_for_reset; -return amdgpu_gfx_mes_reset_queue (ring, vmid, timedout_fence, use_mmio); +return amdgpu_gfx_reset_mes_compute (adev, ring, timedout_fence,NULL ,NULL ); }static void gfx_v12_0_ring_begin_use (struct amdgpu_ring *ring)
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +1 -1
@@ -205,7 +205,7 @@ int mes_userq_reset_queue(struct amdgpu_device *adev, unsigned int db) {struct amdgpu_usermode_queue *uq; -bool use_mmio = false; +bool use_mmio = adev->gfx.mec.use_mmio_for_reset;unsigned long uq_id;int r;
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +13 -62
104 lines not on this page · raw message
Signature · 1 line
2.49.0
PATCH v2 39/42 drm/amdgpu/mes11: enable compute MMIO pipe reset
In reply to Jesse ZhangFrom: Alex Deucher <[email protected]>
Enable MMIO pipe reset for compute pipes.
--- drivers/gpu/drm/amd/amdgpu/mes_v11_0.c | 3 --- 1 file changed, 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/mes_v11_0.c +0 -3
@@ -477,9 +477,6 @@ static int mes_v11_0_reset_compute_pipe_mmio(struct amdgpu_device *adev,uint32_t reset_val, clean_val;int r; -if (!mes_v11_0_pipe_reset_support (adev)) -return -EOPNOTSUPP ; -amdgpu_gfx_rlc_enter_safe_mode (adev,0 );mutex_lock (&adev->srbm_mutex);soc21_grbm_select (adev, me, pipe, queue,0 );
Signature · 1 line
2.49.0
PATCH v2 40/42 drm/amdgpu/mes12: enable compute MMIO pipe reset
In reply to Jesse ZhangFrom: Alex Deucher <[email protected]>
Enable MMIO pipe reset for compute pipes.
--- drivers/gpu/drm/amd/amdgpu/mes_v12_0.c | 3 --- 1 file changed, 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/mes_v12_0.c +0 -3
@@ -502,9 +502,6 @@ static int mes_v12_0_reset_compute_pipe_mmio(struct amdgpu_device *adev,uint32_t reset_val, clean_val;int r =0 ; -if (!mes_v12_0_pipe_reset_support (adev)) -return -EOPNOTSUPP ; -amdgpu_gfx_rlc_enter_safe_mode (adev,0 );mutex_lock (&adev->srbm_mutex);soc24_grbm_select (adev, me, pipe, queue,0 );
Signature · 1 line
2.49.0
PATCH v2 41/42 drm/amdkfd: Update queue reset support on KFD topology
In reply to Jesse ZhangFrom: Amber Lin <[email protected]>
Enable user compute queue reset support on KFD topology for gfx 11 and gfx 12.0
--- drivers/gpu/drm/amd/amdkfd/kfd_topology.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +2 -1
@@ -2025,10 +2025,11 @@ static void kfd_topology_set_capabilities(struct kfd_topology_device *dev) dev->node_props.capability |=HSA_CAP_TRAP_DEBUG_PRECISE_ALU_OPERATIONS_SUPPORTED ; +if (KFD_GC_VERSION (dev->gpu) >=IP_VERSION (11 ,0 ,0 )) + dev->node_props.capability |=HSA_CAP_PER_QUEUE_RESET_SUPPORTED ;if (KFD_GC_VERSION (dev->gpu) >=IP_VERSION (12 ,1 ,0 )) { dev->node_props.capability |=HSA_CAP_TRAP_DEBUG_PRECISE_MEMORY_OPERATIONS_SUPPORTED ; - dev->node_props.capability |=HSA_CAP_PER_QUEUE_RESET_SUPPORTED ; dev->node_props.capability2 |=HSA_CAP2_TRAP_DEBUG_LDS_OUT_OF_ADDR_RANGE_SUPPORTED ; }
Signature · 1 line
2.49.0
PATCH v2 42/42 drm/amdgpu: Expand MES queue/pipe reset support
In reply to Jesse ZhangFrom: Amber Lin <[email protected]>
MES in newer versions on gfx11 and gfx12 can support queue/pipe reset via MES.
XXX: fix the version numbers when FW is complete
--- drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c +5 -1
@@ -853,7 +853,11 @@ bool amdgpu_mes_suspend_resume_all_supported(struct amdgpu_device *adev)bool amdgpu_mes_queue_reset_by_mes_supported (struct amdgpu_device *adev) {return (amdgpu_ip_version (adev,GC_HWIP ,0 ) ==IP_VERSION (12 ,1 ,0 ) && - (adev->mes.sched_version &AMDGPU_MES_VERSION_MASK ) >=0x73 ); + (adev->mes.sched_version &AMDGPU_MES_VERSION_MASK ) >=0x73 ) || + (IP_VERSION_MAJ (amdgpu_ip_version (adev,GC_HWIP ,0 )) ==11 && + (adev->mes.sched_version &AMDGPU_MES_VERSION_MASK ) >=0x8a ) || + (amdgpu_ip_version (adev,GC_HWIP ,0 ) ==IP_VERSION (12 ,0 ,0 ) && + (adev->mes.sched_version &AMDGPU_MES_VERSION_MASK ) >=0x8b ); }/* Fix me -- node_id is used to identify the correct MES instances in the future */
Signature · 1 line
2.49.0