Rework and fix queue reset for gfx7-gfx10
Subsystems (2)
Hi guys,
I finally found time to work on queue reset a bit more and also gave it some more testing.
The per VMID reset actually seems to work 100% reliable at least on gfx9.
What still could be is that an application is using multiple VMIDs on the graphics ring or that we re-use the same VMID for a different application. Preventing this will need some more work on the VMID management.
The compute queue reset as well as the gfx11 and gfx12 code unfortunately still has some calls to amdgpu_bo_reserv/amdgpu_bo_kmap in their path which are totally illegal inside the reset handling, but that can be fixed later on.
Please test, comment and review,
Christian.
PATCH 1/5 drm/amdgpu: rework queue reset scheduler interaction
Stopping the scheduler for queue reset is generally a good idea because it prevents any worker from touching the ring buffer.
But using amdgpu_fence_driver_force_completion() before restarting it was a really bad idea because it marked fences as failed while the work was potentially still running.
Stop doing that and cleanup the comment a bit.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +11 -12
@@ -133,25 +133,24 @@ static enum drm_gpu_sched_stat amdgpu_job_timedout(struct drm_sched_job *s_job)dma_fence_set_error (&s_job->s_fence->finished, -ETIME );/* attempt a per ring reset */ -if (amdgpu_gpu_recovery && - ring->funcs->reset) { -dev_err (adev->dev,"Starting %s ring reset\n" , s_job->sched->name); -/* stop the scheduler, but don't mess with the -* bad job yet because if ring reset fails -* we'll fall back to full GPU reset. +if (amdgpu_gpu_recovery && ring->funcs->reset) { +dev_err (adev->dev,"Starting %s ring reset\n" , + s_job->sched->name); + +/* +* Stop the scheduler to prevent anybody else from touching the +* ring buffer. */ drm_sched_wqueue_stop (&ring->sched); r =amdgpu_ring_reset (ring, job->vmid);if (!r) { -if (amdgpu_ring_sched_ready (ring)) -drm_sched_stop (&ring->sched, s_job);atomic_inc (&ring->adev->gpu_reset_counter); -amdgpu_fence_driver_force_completion (ring); -if (amdgpu_ring_sched_ready (ring)) -drm_sched_start (&ring->sched,0 ); +drm_sched_wqueue_start (&ring->sched); +dev_err (adev->dev,"Ring %s reset worked\n" , + ring->sched.name); goto exit; } -dev_err (adev->dev,"Ring %s reset failure\n" , ring->sched.name); +dev_err (adev->dev,"Ring %s reset failed\n" , ring->sched.name); }if (amdgpu_device_should_recover_gpu (ring->adev)) {
Signature · 1 line
2.34.1
PATCH 2/5 drm/amdgpu: rework gfx9 queue reset
In reply to Christian KönigTesting this feature turned out that it was a bit unstable. The CP_VMID_RESET register takes the VMID which all submissions from should be canceled.
Unlike Windows Linux uses per process VMIDs instead of per engine VMIDs for the simple reason that we don't have enough. So resetting one VMID only killed the submissions of one specific process.
Fortunately that turned out to be exactly what we want to have.
So clear the CP_VMID_RESET register between every context switch between applications when we do the pipeline sync to avoid trouble if multiple VMIDs are used on the ring right behind each other.
Use the same pipeline sync function in the reset handler and issue an IB test instead of a ring test after the queue reset to provide a longer timeout and additional fence value should there be additional work on the ring after the one aborted.
Also drop the soft recovery since that pretty much does the same thing as CP_VMID_RESET, just on a lower level and with less chance of succeeding.
This now survives a stress test running over night sending a broken submission ever 45 seconds and recovering fine from each of them.
--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 1 + drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c | 47 ++++++++++----------------- 2 files changed, 19 insertions(+), 29 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1 -0
@@ -275,6 +275,7 @@ extern int amdgpu_wbrf;#define AMDGPU_WAIT_IDLE_TIMEOUT_IN_MS 3000#define AMDGPU_MAX_USEC_TIMEOUT 100000/* 100 ms */ #define AMDGPU_FENCE_JIFFIES_TIMEOUT (HZ / 2) +#define AMDGPU_QUEUE_RESET_TIMEOUT (HZ / 10)#define AMDGPU_DEBUGFS_MAX_COMPONENTS 32#define AMDGPUFB_CONN_LIMIT 4#define AMDGPU_BIOS_NUM_SCRATCH 16
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +18 -29
110 lines not on this page · raw message
Signature · 1 line
2.34.1
Re: [PATCH 2/5] drm/amdgpu: rework gfx9 queue reset
Quoted 152 lines · Christian König
Testing this feature turned out that it was a bit unstable. The
CP_VMID_RESETregister takes the VMID which all submissions from should be canceled.Unlike Windows Linux uses per process VMIDs instead of per engine VMIDs for the simple reason that we don't have enough. So resetting one VMID only killed the submissions of one specific process.
Fortunately that turned out to be exactly what we want to have.
So clear the
CP_VMID_RESETregister between every context switch between applications when we do the pipeline sync to avoid trouble if multiple VMIDs are used on the ring right behind each other.Use the same pipeline sync function in the reset handler and issue an IB test instead of a ring test after the queue reset to provide a longer timeout and additional fence value should there be additional work on the ring after the one aborted.
Also drop the soft recovery since that pretty much does the same thing as
CP_VMID_RESET, just on a lower level and with less chance of succeeding.This now survives a stress test running over night sending a broken submission ever 45 seconds and recovering fine from each of them.
Signed-off-by Christian König <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 1 + drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c | 47 ++++++++++----------------- 2 files changed, 19 insertions(+), 29 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu.h +1
-0@@ -275,6 +275,7 @@ extern int amdgpu_wbrf;#define AMDGPU_WAIT_IDLE_TIMEOUT_IN_MS 3000#define AMDGPU_MAX_USEC_TIMEOUT 100000/* 100 ms */ #define AMDGPU_FENCE_JIFFIES_TIMEOUT (HZ / 2) +#define AMDGPU_QUEUE_RESET_TIMEOUT (HZ / 10)#define AMDGPU_DEBUGFS_MAX_COMPONENTS 32#define AMDGPUFB_CONN_LIMIT 4#define AMDGPU_BIOS_NUM_SCRATCH 16drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +17
-27@@ -5607,7 +5607,17 @@ static void gfx_v9_0_ring_emit_pipeline_sync(struct amdgpu_ring *ring)int usepfp = (ring->funcs->type ==AMDGPU_RING_TYPE_GFX );uint32_t seq = ring->fence_drv.sync_seq;uint64_t addr = ring->fence_drv.gpu_addr; +struct amdgpu_device *adev = ring->adev; +amdgpu_ring_emit_reg_wait (ring, +SOC15_REG_OFFSET (GC ,0 , mmCP_VMID_RESET), +0 ,0xffff ); +amdgpu_ring_emit_wreg (ring, +SOC15_REG_OFFSET (GC ,0 , mmCP_VMID_RESET), +0 ); +amdgpu_ring_emit_fence (ring, ring->fence_drv.gpu_addr, + ring->fence_drv.sync_seq, +AMDGPU_FENCE_FLAG_EXEC );gfx_v9_0_wait_reg_mem (ring, usepfp,1 ,0 ,lower_32_bits (addr),upper_32_bits (addr), seq,0xffffffff ,4 );@@ -5963,20 +5973,6 @@ static void gfx_v9_0_ring_emit_reg_write_reg_wait(struct amdgpu_ring *ring, ref, mask); } -static void gfx_v9_0_ring_soft_recovery (struct amdgpu_ring *ring,unsigned vmid) -{ -struct amdgpu_device *adev = ring->adev; -uint32_t value =0 ; - - value =REG_SET_FIELD (value,SQ_CMD ,CMD ,0x03 ); - value =REG_SET_FIELD (value,SQ_CMD ,MODE ,0x01 ); - value =REG_SET_FIELD (value,SQ_CMD ,CHECK_VMID ,1 ); - value =REG_SET_FIELD (value,SQ_CMD ,VM_ID , vmid); -amdgpu_gfx_rlc_enter_safe_mode (adev,0 ); -WREG32_SOC15 (GC ,0 , mmSQ_CMD, value); -amdgpu_gfx_rlc_exit_safe_mode (adev,0 ); -} -static void gfx_v9_0_set_gfx_eop_interrupt_state (struct amdgpu_device *adev,enum amdgpu_interrupt_state state) {@@ -7252,16 +7248,12 @@ static int gfx_v9_0_reset_kgq(struct amdgpu_ring *ring, unsigned int vmid)if (r)return r; -if (amdgpu_ring_alloc (ring,7 +7 +5 )) +if (amdgpu_ring_alloc (ring,7 +7 +5 +7 ))return -ENOMEM ; -gfx_v9_0_ring_emit_fence (ring, ring->fence_drv.gpu_addr, - ring->fence_drv.sync_seq,AMDGPU_FENCE_FLAG_EXEC ); -gfx_v9_0_ring_emit_reg_wait (ring, -SOC15_REG_OFFSET (GC ,0 , mmCP_VMID_RESET),0 ,0xffff ); -gfx_v9_0_ring_emit_wreg (ring, -SOC15_REG_OFFSET (GC ,0 , mmCP_VMID_RESET),0 ); +gfx_v9_0_ring_emit_pipeline_sync (ring); +amdgpu_ring_commit (ring); -return amdgpu_ring_test_ring (ring); +return gfx_v9_0_ring_test_ib (ring,AMDGPU_QUEUE_RESET_TIMEOUT ); } static int gfx_v9_0_reset_kcq(struct amdgpu_ring *ring,@@ -7468,7 +7460,7 @@ static const struct amdgpu_ring_funcs gfx_v9_0_ring_funcs_gfx = { .set_wptr = gfx_v9_0_ring_set_wptr_gfx, .emit_frame_size =/* totally 242 maximum if 16 IBs */ 5 +/* COND_EXEC */ -7 +/* PIPELINE_SYNC */ +7 +7 +5 +7 +/* PIPELINE_SYNC */ SOC15_FLUSH_GPU_TLB_NUM_WREG *5 +SOC15_FLUSH_GPU_TLB_NUM_REG_WAIT *7 + 2 + /* VM_FLUSH */@@ -7506,7 +7498,6 @@ static const struct amdgpu_ring_funcs gfx_v9_0_ring_funcs_gfx = { .emit_wreg = gfx_v9_0_ring_emit_wreg, .emit_reg_wait = gfx_v9_0_ring_emit_reg_wait, .emit_reg_write_reg_wait = gfx_v9_0_ring_emit_reg_write_reg_wait, - .soft_recovery = gfx_v9_0_ring_soft_recovery, .emit_mem_sync = gfx_v9_0_emit_mem_sync, .reset = gfx_v9_0_reset_kgq, .emit_cleaner_shader = gfx_v9_0_ring_emit_cleaner_shader,@@ -7525,7 +7516,7 @@ static const struct amdgpu_ring_funcs gfx_v9_0_sw_ring_funcs_gfx = { .set_wptr = amdgpu_sw_ring_set_wptr_gfx, .emit_frame_size =/* totally 242 maximum if 16 IBs */ 5 +/* COND_EXEC */ -7 +/* PIPELINE_SYNC */ +7 +7 +5 +7 +/* PIPELINE_SYNC */ SOC15_FLUSH_GPU_TLB_NUM_WREG *5 +SOC15_FLUSH_GPU_TLB_NUM_REG_WAIT *7 + 2 + /* VM_FLUSH */@@ -7564,7 +7555,6 @@ static const struct amdgpu_ring_funcs gfx_v9_0_sw_ring_funcs_gfx = { .emit_wreg = gfx_v9_0_ring_emit_wreg, .emit_reg_wait = gfx_v9_0_ring_emit_reg_wait, .emit_reg_write_reg_wait = gfx_v9_0_ring_emit_reg_write_reg_wait, - .soft_recovery = gfx_v9_0_ring_soft_recovery, .emit_mem_sync = gfx_v9_0_emit_mem_sync, .patch_cntl = gfx_v9_0_ring_patch_cntl, .patch_de = gfx_v9_0_ring_patch_de_meta,@@ -7586,7 +7576,7 @@ static const struct amdgpu_ring_funcs gfx_v9_0_ring_funcs_compute = {20 +/* gfx_v9_0_ring_emit_gds_switch */ 7 +/* gfx_v9_0_ring_emit_hdp_flush */ 5 +/* hdp invalidate */ -7 +/* gfx_v9_0_ring_emit_pipeline_sync */ +7 +7 +5 +7 +/* PIPELINE_SYNC */ SOC15_FLUSH_GPU_TLB_NUM_WREG *5 +SOC15_FLUSH_GPU_TLB_NUM_REG_WAIT *7 + 8 + 8 + 8 + /* gfx_v9_0_ring_emit_fence x3 for user fence, vm fence */
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c static const struct amdgpu_ring_funcs gfx_v9_0_ring_funcs_compute = { · line 7611
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +0
-1@@ -7608,7 +7598,6 @@ static const struct amdgpu_ring_funcs gfx_v9_0_ring_funcs_compute = { .emit_wreg = gfx_v9_0_ring_emit_wreg, .emit_reg_wait = gfx_v9_0_ring_emit_reg_wait, .emit_reg_write_reg_wait = gfx_v9_0_ring_emit_reg_write_reg_wait, - .soft_recovery = gfx_v9_0_ring_soft_recovery,
Probably want to keep soft_recovery for compute as compute queues don't support vmid reset.
Alex
Quoted 15 lines
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +1
-2.emit_mem_sync = gfx_v9_0_emit_mem_sync, .emit_wave_limit = gfx_v9_0_emit_wave_limit, .reset = gfx_v9_0_reset_kcq,@@ -7629,7 +7618,7 @@ static const struct amdgpu_ring_funcs gfx_v9_0_ring_funcs_kiq = {20 +/* gfx_v9_0_ring_emit_gds_switch */ 7 +/* gfx_v9_0_ring_emit_hdp_flush */ 5 +/* hdp invalidate */ -7 +/* gfx_v9_0_ring_emit_pipeline_sync */ +7 +7 +5 +7 +/* PIPELINE_SYNC */ SOC15_FLUSH_GPU_TLB_NUM_WREG *5 +SOC15_FLUSH_GPU_TLB_NUM_REG_WAIT *7 + 8 + 8 + 8, /* gfx_v9_0_ring_emit_fence_kiq x3 for user fence, vm fence */ --2.34.1
PATCH 3/5 drm/amdgpu: rework gfx7 queue reset
In reply to Christian KönigApply the same changes to gfx7 as done to gfx9.
Untested and probably needs some more work.
--- drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c | 89 ++++++++++++--------------- 1 file changed, 39 insertions(+), 50 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c +39 -50
@@ -3092,6 +3092,33 @@ static int gfx_v7_0_cp_resume(struct amdgpu_device *adev)return 0 ; } +static void gfx_v7_0_wait_reg_mem (struct amdgpu_ring *ring,int eng_sel, +int mem_space,int opt,uint32_t addr0, +uint32_t addr1,uint32_t ref,uint32_t mask, +uint32_t inv) +{ +amdgpu_ring_write (ring,PACKET3 (PACKET3_WAIT_REG_MEM ,5 )); +amdgpu_ring_write (ring, +/* memory (1) or register (0) */ + (WAIT_REG_MEM_MEM_SPACE (mem_space) | +WAIT_REG_MEM_OPERATION (opt) |/* wait */ +WAIT_REG_MEM_FUNCTION (3 ) |/* equal */ +WAIT_REG_MEM_ENGINE (eng_sel))); + +WARN_ON (mem_space && addr0 &0x3 );/* Dword align */ +amdgpu_ring_write (ring, addr0); +amdgpu_ring_write (ring, addr1); +amdgpu_ring_write (ring, ref); +amdgpu_ring_write (ring, mask); +amdgpu_ring_write (ring, inv);/* poll interval */ +} + +static void gfx_v7_0_ring_emit_reg_wait (struct amdgpu_ring *ring,uint32_t reg, +uint32_t val,uint32_t mask) +{ +gfx_v7_0_wait_reg_mem (ring,0 ,0 ,0 , reg,0 , val, mask,0x20 ); +} +/** * gfx_v7_0_ring_emit_pipeline_sync - cik vm flush using the CP *
@@ -3106,6 +3133,11 @@ static void gfx_v7_0_ring_emit_pipeline_sync(struct amdgpu_ring *ring)uint32_t seq = ring->fence_drv.sync_seq;uint64_t addr = ring->fence_drv.gpu_addr; +gfx_v7_0_ring_emit_reg_wait (ring, mmCP_VMID_RESET,0 ,0xffff ); +amdgpu_ring_emit_wreg (ring, mmCP_VMID_RESET,0 ); +amdgpu_ring_emit_fence (ring, ring->fence_drv.gpu_addr, + ring->fence_drv.sync_seq, +AMDGPU_FENCE_FLAG_EXEC );amdgpu_ring_write (ring,PACKET3 (PACKET3_WAIT_REG_MEM ,5 )); amdgpu_ring_write(ring, (WAIT_REG_MEM_MEM_SPACE(1) | /* memory */ WAIT_REG_MEM_FUNCTION(3) | /* equal */
@@ -4040,18 +4072,6 @@ static void gfx_v7_0_ring_emit_gds_switch(struct amdgpu_ring *ring,amdgpu_ring_write (ring, (1 << (oa_size + oa_base)) - (1 << oa_base)); } -static void gfx_v7_0_ring_soft_recovery (struct amdgpu_ring *ring,unsigned vmid) -{ -struct amdgpu_device *adev = ring->adev; -uint32_t value =0 ; - - value =REG_SET_FIELD (value,SQ_CMD ,CMD ,0x03 ); - value =REG_SET_FIELD (value,SQ_CMD ,MODE ,0x01 ); - value =REG_SET_FIELD (value,SQ_CMD ,CHECK_VMID ,1 ); - value =REG_SET_FIELD (value,SQ_CMD ,VM_ID , vmid); -WREG32 (mmSQ_CMD, value); -} -static uint32_t wave_read_ind (struct amdgpu_device *adev,uint32_t simd,uint32_t wave,uint32_t address) { WREG32(mmSQ_IND_INDEX,
@@ -4926,34 +4946,6 @@ static void gfx_v7_0_emit_mem_sync_compute(struct amdgpu_ring *ring)amdgpu_ring_write (ring,0x0000000A );/* poll interval */ } -static void gfx_v7_0_wait_reg_mem (struct amdgpu_ring *ring,int eng_sel, -int mem_space,int opt,uint32_t addr0, -uint32_t addr1,uint32_t ref,uint32_t mask, -uint32_t inv) -{ -amdgpu_ring_write (ring,PACKET3 (PACKET3_WAIT_REG_MEM ,5 )); -amdgpu_ring_write (ring, -/* memory (1) or register (0) */ - (WAIT_REG_MEM_MEM_SPACE (mem_space) | -WAIT_REG_MEM_OPERATION (opt) |/* wait */ -WAIT_REG_MEM_FUNCTION (3 ) |/* equal */ -WAIT_REG_MEM_ENGINE (eng_sel))); - -if (mem_space) -BUG_ON (addr0 &0x3 );/* Dword align */ -amdgpu_ring_write (ring, addr0); -amdgpu_ring_write (ring, addr1); -amdgpu_ring_write (ring, ref); -amdgpu_ring_write (ring, mask); -amdgpu_ring_write (ring, inv);/* poll interval */ -} - -static void gfx_v7_0_ring_emit_reg_wait (struct amdgpu_ring *ring,uint32_t reg, -uint32_t val,uint32_t mask) -{ -gfx_v7_0_wait_reg_mem (ring,0 ,0 ,0 , reg,0 , val, mask,0x20 ); -} -static int gfx_v7_0_reset_kgq (struct amdgpu_ring *ring,unsigned int vmid) {struct amdgpu_device *adev = ring->adev;
@@ -4986,14 +4978,13 @@ static int gfx_v7_0_reset_kgq(struct amdgpu_ring *ring, unsigned int vmid)if (r)return r; -if (amdgpu_ring_alloc (ring,7 +12 +5 )) +if (amdgpu_ring_alloc (ring,7 +12 +5 +7 +4 ))return -ENOMEM ; -gfx_v7_0_ring_emit_fence_gfx (ring, ring->fence_drv.gpu_addr, - ring->fence_drv.sync_seq,AMDGPU_FENCE_FLAG_EXEC ); -gfx_v7_0_ring_emit_reg_wait (ring, mmCP_VMID_RESET,0 ,0xffff ); -gfx_v7_0_ring_emit_wreg (ring, mmCP_VMID_RESET,0 ); -return amdgpu_ring_test_ring (ring); +gfx_v7_0_ring_emit_pipeline_sync (ring); +amdgpu_ring_commit (ring); + +return gfx_v7_0_ring_test_ib (ring,AMDGPU_QUEUE_RESET_TIMEOUT ); }static const struct amd_ip_funcs gfx_v7_0_ip_funcs = {
@@ -5026,7 +5017,7 @@ static const struct amdgpu_ring_funcs gfx_v7_0_ring_funcs_gfx = {7 +/* gfx_v7_0_ring_emit_hdp_flush */ 5 +/* hdp invalidate */ 12 +12 +12 +/* gfx_v7_0_ring_emit_fence_gfx x3 for user fence, vm fence */ -7 +4 +/* gfx_v7_0_ring_emit_pipeline_sync */ +7 +12 +5 +7 +4 +/* gfx_v7_0_ring_emit_pipeline_sync */ CIK_FLUSH_GPU_TLB_NUM_WREG *5 +7 +6 +/* gfx_v7_0_ring_emit_vm_flush */ 3 +4 +/* gfx_v7_ring_emit_cntxcntl including vgt flush*/ 5, /* SURFACE_SYNC */
@@ -5043,7 +5034,6 @@ static const struct amdgpu_ring_funcs gfx_v7_0_ring_funcs_gfx = { .pad_ib = amdgpu_ring_generic_pad_ib, .emit_cntxcntl = gfx_v7_ring_emit_cntxcntl, .emit_wreg = gfx_v7_0_ring_emit_wreg, - .soft_recovery = gfx_v7_0_ring_soft_recovery, .emit_mem_sync = gfx_v7_0_emit_mem_sync, .reset = gfx_v7_0_reset_kgq, };
@@ -5060,7 +5050,7 @@ static const struct amdgpu_ring_funcs gfx_v7_0_ring_funcs_compute = {20 +/* gfx_v7_0_ring_emit_gds_switch */ 7 +/* gfx_v7_0_ring_emit_hdp_flush */ 5 +/* hdp invalidate */ -7 +/* gfx_v7_0_ring_emit_pipeline_sync */ +7 +12 +5 +7 +/* gfx_v7_0_ring_emit_pipeline_sync */ CIK_FLUSH_GPU_TLB_NUM_WREG *5 +7 +/* gfx_v7_0_ring_emit_vm_flush */ 7 +7 +7 +/* gfx_v7_0_ring_emit_fence_compute x3 for user fence, vm fence */ 7, /* gfx_v7_0_emit_mem_sync_compute */
@@ -5076,7 +5066,6 @@ static const struct amdgpu_ring_funcs gfx_v7_0_ring_funcs_compute = { .insert_nop = amdgpu_ring_insert_nop, .pad_ib = amdgpu_ring_generic_pad_ib, .emit_wreg = gfx_v7_0_ring_emit_wreg, - .soft_recovery = gfx_v7_0_ring_soft_recovery, .emit_mem_sync = gfx_v7_0_emit_mem_sync_compute, };
Signature · 1 line
2.34.1
Re: [PATCH 3/5] drm/amdgpu: rework gfx7 queue reset
Quoted 161 lines · Christian König
Apply the same changes to gfx7 as done to gfx9.
Untested and probably needs some more work.
Signed-off-by Christian König <[email protected]>--- drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c | 89 ++++++++++++--------------- 1 file changed, 39 insertions(+), 50 deletions(-)drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c +39
-49@@ -3092,6 +3092,33 @@ static int gfx_v7_0_cp_resume(struct amdgpu_device *adev)return 0 ; } +static void gfx_v7_0_wait_reg_mem (struct amdgpu_ring *ring,int eng_sel, +int mem_space,int opt,uint32_t addr0, +uint32_t addr1,uint32_t ref,uint32_t mask, +uint32_t inv) +{ +amdgpu_ring_write (ring,PACKET3 (PACKET3_WAIT_REG_MEM ,5 )); +amdgpu_ring_write (ring, +/* memory (1) or register (0) */ + (WAIT_REG_MEM_MEM_SPACE (mem_space) | +WAIT_REG_MEM_OPERATION (opt) |/* wait */ +WAIT_REG_MEM_FUNCTION (3 ) |/* equal */ +WAIT_REG_MEM_ENGINE (eng_sel))); + +WARN_ON (mem_space && addr0 &0x3 );/* Dword align */ +amdgpu_ring_write (ring, addr0); +amdgpu_ring_write (ring, addr1); +amdgpu_ring_write (ring, ref); +amdgpu_ring_write (ring, mask); +amdgpu_ring_write (ring, inv);/* poll interval */ +} + +static void gfx_v7_0_ring_emit_reg_wait (struct amdgpu_ring *ring,uint32_t reg, +uint32_t val,uint32_t mask) +{ +gfx_v7_0_wait_reg_mem (ring,0 ,0 ,0 , reg,0 , val, mask,0x20 ); +} +/** * gfx_v7_0_ring_emit_pipeline_sync - cik vm flush using the CP * @@ -3106,6 +3133,11 @@ static void gfx_v7_0_ring_emit_pipeline_sync(struct amdgpu_ring *ring)uint32_t seq = ring->fence_drv.sync_seq;uint64_t addr = ring->fence_drv.gpu_addr; +gfx_v7_0_ring_emit_reg_wait (ring, mmCP_VMID_RESET,0 ,0xffff ); +amdgpu_ring_emit_wreg (ring, mmCP_VMID_RESET,0 ); +amdgpu_ring_emit_fence (ring, ring->fence_drv.gpu_addr, + ring->fence_drv.sync_seq, +AMDGPU_FENCE_FLAG_EXEC );amdgpu_ring_write (ring,PACKET3 (PACKET3_WAIT_REG_MEM ,5 )); amdgpu_ring_write(ring, (WAIT_REG_MEM_MEM_SPACE(1) | /* memory */ WAIT_REG_MEM_FUNCTION(3) | /* equal */@@ -4040,18 +4072,6 @@ static void gfx_v7_0_ring_emit_gds_switch(struct amdgpu_ring *ring,amdgpu_ring_write (ring, (1 << (oa_size + oa_base)) - (1 << oa_base)); } -static void gfx_v7_0_ring_soft_recovery (struct amdgpu_ring *ring,unsigned vmid) -{ -struct amdgpu_device *adev = ring->adev; -uint32_t value =0 ; - - value =REG_SET_FIELD (value,SQ_CMD ,CMD ,0x03 ); - value =REG_SET_FIELD (value,SQ_CMD ,MODE ,0x01 ); - value =REG_SET_FIELD (value,SQ_CMD ,CHECK_VMID ,1 ); - value =REG_SET_FIELD (value,SQ_CMD ,VM_ID , vmid); -WREG32 (mmSQ_CMD, value); -} -static uint32_t wave_read_ind (struct amdgpu_device *adev,uint32_t simd,uint32_t wave,uint32_t address) { WREG32(mmSQ_IND_INDEX,@@ -4926,34 +4946,6 @@ static void gfx_v7_0_emit_mem_sync_compute(struct amdgpu_ring *ring)amdgpu_ring_write (ring,0x0000000A );/* poll interval */ } -static void gfx_v7_0_wait_reg_mem (struct amdgpu_ring *ring,int eng_sel, -int mem_space,int opt,uint32_t addr0, -uint32_t addr1,uint32_t ref,uint32_t mask, -uint32_t inv) -{ -amdgpu_ring_write (ring,PACKET3 (PACKET3_WAIT_REG_MEM ,5 )); -amdgpu_ring_write (ring, -/* memory (1) or register (0) */ - (WAIT_REG_MEM_MEM_SPACE (mem_space) | -WAIT_REG_MEM_OPERATION (opt) |/* wait */ -WAIT_REG_MEM_FUNCTION (3 ) |/* equal */ -WAIT_REG_MEM_ENGINE (eng_sel))); - -if (mem_space) -BUG_ON (addr0 &0x3 );/* Dword align */ -amdgpu_ring_write (ring, addr0); -amdgpu_ring_write (ring, addr1); -amdgpu_ring_write (ring, ref); -amdgpu_ring_write (ring, mask); -amdgpu_ring_write (ring, inv);/* poll interval */ -} - -static void gfx_v7_0_ring_emit_reg_wait (struct amdgpu_ring *ring,uint32_t reg, -uint32_t val,uint32_t mask) -{ -gfx_v7_0_wait_reg_mem (ring,0 ,0 ,0 , reg,0 , val, mask,0x20 ); -} -static int gfx_v7_0_reset_kgq (struct amdgpu_ring *ring,unsigned int vmid) {struct amdgpu_device *adev = ring->adev;@@ -4986,14 +4978,13 @@ static int gfx_v7_0_reset_kgq(struct amdgpu_ring *ring, unsigned int vmid)if (r)return r; -if (amdgpu_ring_alloc (ring,7 +12 +5 )) +if (amdgpu_ring_alloc (ring,7 +12 +5 +7 +4 ))return -ENOMEM ; -gfx_v7_0_ring_emit_fence_gfx (ring, ring->fence_drv.gpu_addr, - ring->fence_drv.sync_seq,AMDGPU_FENCE_FLAG_EXEC ); -gfx_v7_0_ring_emit_reg_wait (ring, mmCP_VMID_RESET,0 ,0xffff ); -gfx_v7_0_ring_emit_wreg (ring, mmCP_VMID_RESET,0 ); -return amdgpu_ring_test_ring (ring); +gfx_v7_0_ring_emit_pipeline_sync (ring); +amdgpu_ring_commit (ring); + +return gfx_v7_0_ring_test_ib (ring,AMDGPU_QUEUE_RESET_TIMEOUT ); }static const struct amd_ip_funcs gfx_v7_0_ip_funcs = {@@ -5026,7 +5017,7 @@ static const struct amdgpu_ring_funcs gfx_v7_0_ring_funcs_gfx = {7 +/* gfx_v7_0_ring_emit_hdp_flush */ 5 +/* hdp invalidate */ 12 +12 +12 +/* gfx_v7_0_ring_emit_fence_gfx x3 for user fence, vm fence */ -7 +4 +/* gfx_v7_0_ring_emit_pipeline_sync */ +7 +12 +5 +7 +4 +/* gfx_v7_0_ring_emit_pipeline_sync */ CIK_FLUSH_GPU_TLB_NUM_WREG *5 +7 +6 +/* gfx_v7_0_ring_emit_vm_flush */ 3 +4 +/* gfx_v7_ring_emit_cntxcntl including vgt flush*/ 5, /* SURFACE_SYNC */@@ -5043,7 +5034,6 @@ static const struct amdgpu_ring_funcs gfx_v7_0_ring_funcs_gfx = { .pad_ib = amdgpu_ring_generic_pad_ib, .emit_cntxcntl = gfx_v7_ring_emit_cntxcntl, .emit_wreg = gfx_v7_0_ring_emit_wreg, - .soft_recovery = gfx_v7_0_ring_soft_recovery, .emit_mem_sync = gfx_v7_0_emit_mem_sync, .reset = gfx_v7_0_reset_kgq, };@@ -5060,7 +5050,7 @@ static const struct amdgpu_ring_funcs gfx_v7_0_ring_funcs_compute = {20 +/* gfx_v7_0_ring_emit_gds_switch */ 7 +/* gfx_v7_0_ring_emit_hdp_flush */ 5 +/* hdp invalidate */ -7 +/* gfx_v7_0_ring_emit_pipeline_sync */ +7 +12 +5 +7 +/* gfx_v7_0_ring_emit_pipeline_sync */ CIK_FLUSH_GPU_TLB_NUM_WREG *5 +7 +/* gfx_v7_0_ring_emit_vm_flush */ 7 +7 +7 +/* gfx_v7_0_ring_emit_fence_compute x3 for user fence, vm fence */ 7, /* gfx_v7_0_emit_mem_sync_compute */
drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c static const struct amdgpu_ring_funcs gfx_v7_0_ring_funcs_compute = { · line 5079
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c +0
-1@@ -5076,7 +5066,6 @@ static const struct amdgpu_ring_funcs gfx_v7_0_ring_funcs_compute = { .insert_nop = amdgpu_ring_insert_nop, .pad_ib = amdgpu_ring_generic_pad_ib, .emit_wreg = gfx_v7_0_ring_emit_wreg, - .soft_recovery = gfx_v7_0_ring_soft_recovery,
Probably want to keep this for compute.
Alex
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c +0
-1.emit_mem_sync = gfx_v7_0_emit_mem_sync_compute, }; --2.34.1
PATCH 4/5 drm/amdgpu: rework gfx8 queue reset
In reply to Christian KönigApply the same changes to gfx8 as done to gfx9.
Untested and probably needs some more work.
--- drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c | 86 ++++++++++++--------------- 1 file changed, 38 insertions(+), 48 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c +38 -48
@@ -6201,12 +6201,45 @@ static void gfx_v8_0_ring_emit_fence_gfx(struct amdgpu_ring *ring, u64 addr, } +static void gfx_v8_0_wait_reg_mem (struct amdgpu_ring *ring,int eng_sel, +int mem_space,int opt,uint32_t addr0, +uint32_t addr1,uint32_t ref,uint32_t mask, +uint32_t inv) +{ +amdgpu_ring_write (ring,PACKET3 (PACKET3_WAIT_REG_MEM ,5 )); +amdgpu_ring_write (ring, +/* memory (1) or register (0) */ + (WAIT_REG_MEM_MEM_SPACE (mem_space) | +WAIT_REG_MEM_OPERATION (opt) |/* wait */ +WAIT_REG_MEM_FUNCTION (3 ) |/* equal */ +WAIT_REG_MEM_ENGINE (eng_sel))); + +WARN_ON (mem_space && addr0 &0x3 );/* Dword align */ +amdgpu_ring_write (ring, addr0); +amdgpu_ring_write (ring, addr1); +amdgpu_ring_write (ring, ref); +amdgpu_ring_write (ring, mask); +amdgpu_ring_write (ring, inv);/* poll interval */ +} + +static void gfx_v8_0_ring_emit_reg_wait (struct amdgpu_ring *ring,uint32_t reg, +uint32_t val,uint32_t mask) +{ +gfx_v8_0_wait_reg_mem (ring,0 ,0 ,0 , reg,0 , val, mask,0x20 ); +} +static void gfx_v8_0_ring_emit_pipeline_sync (struct amdgpu_ring *ring) {int usepfp = (ring->funcs->type ==AMDGPU_RING_TYPE_GFX );uint32_t seq = ring->fence_drv.sync_seq;uint64_t addr = ring->fence_drv.gpu_addr; +gfx_v8_0_ring_emit_reg_wait (ring, mmCP_VMID_RESET,0 ,0xffff ); +amdgpu_ring_emit_wreg (ring, mmCP_VMID_RESET,0 ); +amdgpu_ring_emit_fence (ring, ring->fence_drv.gpu_addr, + ring->fence_drv.sync_seq, +AMDGPU_FENCE_FLAG_EXEC ); +amdgpu_ring_write (ring,PACKET3 (PACKET3_WAIT_REG_MEM ,5 )); amdgpu_ring_write(ring, (WAIT_REG_MEM_MEM_SPACE(1) | /* memory */ WAIT_REG_MEM_FUNCTION(3) | /* equal */
@@ -6400,46 +6433,6 @@ static void gfx_v8_0_ring_emit_wreg(struct amdgpu_ring *ring, uint32_t reg,amdgpu_ring_write (ring, val); } -static void gfx_v8_0_wait_reg_mem (struct amdgpu_ring *ring,int eng_sel, -int mem_space,int opt,uint32_t addr0, -uint32_t addr1,uint32_t ref,uint32_t mask, -uint32_t inv) -{ -amdgpu_ring_write (ring,PACKET3 (PACKET3_WAIT_REG_MEM ,5 )); -amdgpu_ring_write (ring, -/* memory (1) or register (0) */ - (WAIT_REG_MEM_MEM_SPACE (mem_space) | -WAIT_REG_MEM_OPERATION (opt) |/* wait */ -WAIT_REG_MEM_FUNCTION (3 ) |/* equal */ -WAIT_REG_MEM_ENGINE (eng_sel))); - -if (mem_space) -BUG_ON (addr0 &0x3 );/* Dword align */ -amdgpu_ring_write (ring, addr0); -amdgpu_ring_write (ring, addr1); -amdgpu_ring_write (ring, ref); -amdgpu_ring_write (ring, mask); -amdgpu_ring_write (ring, inv);/* poll interval */ -} - -static void gfx_v8_0_ring_emit_reg_wait (struct amdgpu_ring *ring,uint32_t reg, -uint32_t val,uint32_t mask) -{ -gfx_v8_0_wait_reg_mem (ring,0 ,0 ,0 , reg,0 , val, mask,0x20 ); -} - -static void gfx_v8_0_ring_soft_recovery (struct amdgpu_ring *ring,unsigned vmid) -{ -struct amdgpu_device *adev = ring->adev; -uint32_t value =0 ; - - value =REG_SET_FIELD (value,SQ_CMD ,CMD ,0x03 ); - value =REG_SET_FIELD (value,SQ_CMD ,MODE ,0x01 ); - value =REG_SET_FIELD (value,SQ_CMD ,CHECK_VMID ,1 ); - value =REG_SET_FIELD (value,SQ_CMD ,VM_ID , vmid); -WREG32 (mmSQ_CMD, value); -} -static void gfx_v8_0_set_gfx_eop_interrupt_state (struct amdgpu_device *adev,enum amdgpu_interrupt_state state) {
@@ -6936,14 +6929,13 @@ static int gfx_v8_0_reset_kgq(struct amdgpu_ring *ring, unsigned int vmid)if (r)return r; -if (amdgpu_ring_alloc (ring,7 +12 +5 )) +if (amdgpu_ring_alloc (ring,7 +12 +5 +7 ))return -ENOMEM ; -gfx_v8_0_ring_emit_fence_gfx (ring, ring->fence_drv.gpu_addr, - ring->fence_drv.sync_seq,AMDGPU_FENCE_FLAG_EXEC ); -gfx_v8_0_ring_emit_reg_wait (ring, mmCP_VMID_RESET,0 ,0xffff ); -gfx_v8_0_ring_emit_wreg (ring, mmCP_VMID_RESET,0 ); -return amdgpu_ring_test_ring (ring); +gfx_v8_0_ring_emit_pipeline_sync (ring); +amdgpu_ring_commit (ring); + +return gfx_v8_0_ring_test_ib (ring,AMDGPU_QUEUE_RESET_TIMEOUT ); }static const struct amd_ip_funcs gfx_v8_0_ip_funcs = {
@@ -7009,7 +7001,6 @@ static const struct amdgpu_ring_funcs gfx_v8_0_ring_funcs_gfx = { .emit_cntxcntl = gfx_v8_ring_emit_cntxcntl, .init_cond_exec = gfx_v8_0_ring_emit_init_cond_exec, .emit_wreg = gfx_v8_0_ring_emit_wreg, - .soft_recovery = gfx_v8_0_ring_soft_recovery, .emit_mem_sync = gfx_v8_0_emit_mem_sync, .reset = gfx_v8_0_reset_kgq, };
@@ -7044,7 +7035,6 @@ static const struct amdgpu_ring_funcs gfx_v8_0_ring_funcs_compute = { .insert_nop = amdgpu_ring_insert_nop, .pad_ib = amdgpu_ring_generic_pad_ib, .emit_wreg = gfx_v8_0_ring_emit_wreg, - .soft_recovery = gfx_v8_0_ring_soft_recovery, .emit_mem_sync = gfx_v8_0_emit_mem_sync_compute, .emit_wave_limit = gfx_v8_0_emit_wave_limit, };
Signature · 1 line
2.34.1
Re: [PATCH 4/5] drm/amdgpu: rework gfx8 queue reset
Quoted 136 lines · Christian König
Apply the same changes to gfx8 as done to gfx9.
Untested and probably needs some more work.
Signed-off-by Christian König <[email protected]>--- drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c | 86 ++++++++++++--------------- 1 file changed, 38 insertions(+), 48 deletions(-)drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c +38
-47@@ -6201,12 +6201,45 @@ static void gfx_v8_0_ring_emit_fence_gfx(struct amdgpu_ring *ring, u64 addr, } +static void gfx_v8_0_wait_reg_mem (struct amdgpu_ring *ring,int eng_sel, +int mem_space,int opt,uint32_t addr0, +uint32_t addr1,uint32_t ref,uint32_t mask, +uint32_t inv) +{ +amdgpu_ring_write (ring,PACKET3 (PACKET3_WAIT_REG_MEM ,5 )); +amdgpu_ring_write (ring, +/* memory (1) or register (0) */ + (WAIT_REG_MEM_MEM_SPACE (mem_space) | +WAIT_REG_MEM_OPERATION (opt) |/* wait */ +WAIT_REG_MEM_FUNCTION (3 ) |/* equal */ +WAIT_REG_MEM_ENGINE (eng_sel))); + +WARN_ON (mem_space && addr0 &0x3 );/* Dword align */ +amdgpu_ring_write (ring, addr0); +amdgpu_ring_write (ring, addr1); +amdgpu_ring_write (ring, ref); +amdgpu_ring_write (ring, mask); +amdgpu_ring_write (ring, inv);/* poll interval */ +} + +static void gfx_v8_0_ring_emit_reg_wait (struct amdgpu_ring *ring,uint32_t reg, +uint32_t val,uint32_t mask) +{ +gfx_v8_0_wait_reg_mem (ring,0 ,0 ,0 , reg,0 , val, mask,0x20 ); +} +static void gfx_v8_0_ring_emit_pipeline_sync (struct amdgpu_ring *ring) {int usepfp = (ring->funcs->type ==AMDGPU_RING_TYPE_GFX );uint32_t seq = ring->fence_drv.sync_seq;uint64_t addr = ring->fence_drv.gpu_addr; +gfx_v8_0_ring_emit_reg_wait (ring, mmCP_VMID_RESET,0 ,0xffff ); +amdgpu_ring_emit_wreg (ring, mmCP_VMID_RESET,0 ); +amdgpu_ring_emit_fence (ring, ring->fence_drv.gpu_addr, + ring->fence_drv.sync_seq, +AMDGPU_FENCE_FLAG_EXEC ); +amdgpu_ring_write (ring,PACKET3 (PACKET3_WAIT_REG_MEM ,5 )); amdgpu_ring_write(ring, (WAIT_REG_MEM_MEM_SPACE(1) | /* memory */ WAIT_REG_MEM_FUNCTION(3) | /* equal */@@ -6400,46 +6433,6 @@ static void gfx_v8_0_ring_emit_wreg(struct amdgpu_ring *ring, uint32_t reg,amdgpu_ring_write (ring, val); } -static void gfx_v8_0_wait_reg_mem (struct amdgpu_ring *ring,int eng_sel, -int mem_space,int opt,uint32_t addr0, -uint32_t addr1,uint32_t ref,uint32_t mask, -uint32_t inv) -{ -amdgpu_ring_write (ring,PACKET3 (PACKET3_WAIT_REG_MEM ,5 )); -amdgpu_ring_write (ring, -/* memory (1) or register (0) */ - (WAIT_REG_MEM_MEM_SPACE (mem_space) | -WAIT_REG_MEM_OPERATION (opt) |/* wait */ -WAIT_REG_MEM_FUNCTION (3 ) |/* equal */ -WAIT_REG_MEM_ENGINE (eng_sel))); - -if (mem_space) -BUG_ON (addr0 &0x3 );/* Dword align */ -amdgpu_ring_write (ring, addr0); -amdgpu_ring_write (ring, addr1); -amdgpu_ring_write (ring, ref); -amdgpu_ring_write (ring, mask); -amdgpu_ring_write (ring, inv);/* poll interval */ -} - -static void gfx_v8_0_ring_emit_reg_wait (struct amdgpu_ring *ring,uint32_t reg, -uint32_t val,uint32_t mask) -{ -gfx_v8_0_wait_reg_mem (ring,0 ,0 ,0 , reg,0 , val, mask,0x20 ); -} - -static void gfx_v8_0_ring_soft_recovery (struct amdgpu_ring *ring,unsigned vmid) -{ -struct amdgpu_device *adev = ring->adev; -uint32_t value =0 ; - - value =REG_SET_FIELD (value,SQ_CMD ,CMD ,0x03 ); - value =REG_SET_FIELD (value,SQ_CMD ,MODE ,0x01 ); - value =REG_SET_FIELD (value,SQ_CMD ,CHECK_VMID ,1 ); - value =REG_SET_FIELD (value,SQ_CMD ,VM_ID , vmid); -WREG32 (mmSQ_CMD, value); -} -static void gfx_v8_0_set_gfx_eop_interrupt_state (struct amdgpu_device *adev,enum amdgpu_interrupt_state state) {@@ -6936,14 +6929,13 @@ static int gfx_v8_0_reset_kgq(struct amdgpu_ring *ring, unsigned int vmid)if (r)return r; -if (amdgpu_ring_alloc (ring,7 +12 +5 )) +if (amdgpu_ring_alloc (ring,7 +12 +5 +7 ))return -ENOMEM ; -gfx_v8_0_ring_emit_fence_gfx (ring, ring->fence_drv.gpu_addr, - ring->fence_drv.sync_seq,AMDGPU_FENCE_FLAG_EXEC ); -gfx_v8_0_ring_emit_reg_wait (ring, mmCP_VMID_RESET,0 ,0xffff ); -gfx_v8_0_ring_emit_wreg (ring, mmCP_VMID_RESET,0 ); -return amdgpu_ring_test_ring (ring); +gfx_v8_0_ring_emit_pipeline_sync (ring); +amdgpu_ring_commit (ring); + +return gfx_v8_0_ring_test_ib (ring,AMDGPU_QUEUE_RESET_TIMEOUT ); }static const struct amd_ip_funcs gfx_v8_0_ip_funcs = {@@ -7009,7 +7001,6 @@ static const struct amdgpu_ring_funcs gfx_v8_0_ring_funcs_gfx = { .emit_cntxcntl = gfx_v8_ring_emit_cntxcntl, .init_cond_exec = gfx_v8_0_ring_emit_init_cond_exec, .emit_wreg = gfx_v8_0_ring_emit_wreg, - .soft_recovery = gfx_v8_0_ring_soft_recovery, .emit_mem_sync = gfx_v8_0_emit_mem_sync, .reset = gfx_v8_0_reset_kgq, };
drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c static const struct amdgpu_ring_funcs gfx_v8_0_ring_funcs_compute = { · line 7047
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c +0
-1@@ -7044,7 +7035,6 @@ static const struct amdgpu_ring_funcs gfx_v8_0_ring_funcs_compute = { .insert_nop = amdgpu_ring_insert_nop, .pad_ib = amdgpu_ring_generic_pad_ib, .emit_wreg = gfx_v8_0_ring_emit_wreg, - .soft_recovery = gfx_v8_0_ring_soft_recovery,
Same comment here.
Alex
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c +0
-1.emit_mem_sync = gfx_v8_0_emit_mem_sync_compute, .emit_wave_limit = gfx_v8_0_emit_wave_limit, }; --2.34.1
PATCH 5/5 drm/amdgpu: rework gfx10 queue reset
In reply to Christian KönigApply the same changes to gfx10 as done to gfx9.
The general idea to reset the whole kernel queue and then asking the kiq to map it again didn't worked at all. Background is that we don't use per application kernel queues for gfx10 on Linux for performance reasons.
So instead use the gfx9 approach here as well and only reset all submissions from a specific VMID instead of the whole queue.
This also avoids reserving and kmap the MQD which are operations generally not allowed in the reset handler.
This approach seems to work for at least some time, but not as reliable as it is on gfx9. It will probably need some more work until it survives a whole night of reset stress testing.
--- drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c | 65 +++++++------------------- 1 file changed, 16 insertions(+), 49 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +16 -49
@@ -8684,7 +8684,17 @@ static void gfx_v10_0_ring_emit_pipeline_sync(struct amdgpu_ring *ring)int usepfp = (ring->funcs->type ==AMDGPU_RING_TYPE_GFX );uint32_t seq = ring->fence_drv.sync_seq;uint64_t addr = ring->fence_drv.gpu_addr; +struct amdgpu_device *adev = ring->adev; +amdgpu_ring_emit_reg_wait (ring, +SOC15_REG_OFFSET (GC ,0 , mmCP_VMID_RESET), +0 ,0xffff ); +amdgpu_ring_emit_wreg (ring, +SOC15_REG_OFFSET (GC ,0 , mmCP_VMID_RESET), +0 ); +amdgpu_ring_emit_fence (ring, ring->fence_drv.gpu_addr, + ring->fence_drv.sync_seq, +AMDGPU_FENCE_FLAG_EXEC );gfx_v10_0_wait_reg_mem (ring, usepfp,1 ,0 ,lower_32_bits (addr),upper_32_bits (addr), seq,0xffffffff ,4 ); }
@@ -8984,21 +8994,6 @@ static void gfx_v10_0_ring_emit_reg_write_reg_wait(struct amdgpu_ring *ring, ref, mask); } -static void gfx_v10_0_ring_soft_recovery (struct amdgpu_ring *ring, -unsigned int vmid) -{ -struct amdgpu_device *adev = ring->adev; -uint32_t value =0 ; - - value =REG_SET_FIELD (value,SQ_CMD ,CMD ,0x03 ); - value =REG_SET_FIELD (value,SQ_CMD ,MODE ,0x01 ); - value =REG_SET_FIELD (value,SQ_CMD ,CHECK_VMID ,1 ); - value =REG_SET_FIELD (value,SQ_CMD ,VM_ID , vmid); -amdgpu_gfx_rlc_enter_safe_mode (adev,0 ); -WREG32_SOC15 (GC ,0 , mmSQ_CMD, value); -amdgpu_gfx_rlc_exit_safe_mode (adev,0 ); -} - static void gfx_v10_0_set_gfx_eop_interrupt_state(struct amdgpu_device *adev, uint32_t me, uint32_t pipe,
@@ -9467,7 +9462,6 @@ static int gfx_v10_0_reset_kgq(struct amdgpu_ring *ring, unsigned int vmid)struct amdgpu_ring *kiq_ring = &kiq->ring;unsigned long flags;u32 tmp; -u64 addr;int r;if (amdgpu_sriov_vf (adev))
@@ -9478,27 +9472,14 @@ static int gfx_v10_0_reset_kgq(struct amdgpu_ring *ring, unsigned int vmid)spin_lock_irqsave (&kiq->ring_lock, flags); -if (amdgpu_ring_alloc (kiq_ring,5 +7 +7 + kiq->pmf->map_queues_size)) { +if (amdgpu_ring_alloc (kiq_ring,5 )) {spin_unlock_irqrestore (&kiq->ring_lock, flags);return -ENOMEM ; } - addr =amdgpu_bo_gpu_offset (ring->mqd_obj) + - offsetof(struct v10_gfx_mqd , cp_gfx_hqd_active); tmp =REG_SET_FIELD (0 ,CP_VMID_RESET ,RESET_REQUEST ,1 << vmid); -if (ring->pipe ==0 ) - tmp =REG_SET_FIELD (tmp,CP_VMID_RESET ,PIPE0_QUEUES ,1 << ring->queue); -else - tmp =REG_SET_FIELD (tmp,CP_VMID_RESET ,PIPE1_QUEUES ,1 << ring->queue); -gfx_v10_0_ring_emit_wreg (kiq_ring,SOC15_REG_OFFSET (GC ,0 , mmCP_VMID_RESET), tmp); -gfx_v10_0_wait_reg_mem (kiq_ring,0 ,1 ,0 , -lower_32_bits (addr),upper_32_bits (addr), -0 ,1 ,0x20 ); -gfx_v10_0_ring_emit_reg_wait (kiq_ring, -SOC15_REG_OFFSET (GC ,0 , mmCP_VMID_RESET),0 ,0xffffffff ); - kiq->pmf->kiq_map_queues (kiq_ring, ring);amdgpu_ring_commit (kiq_ring);spin_unlock_irqrestore (&kiq->ring_lock, flags);
@@ -9507,24 +9488,12 @@ static int gfx_v10_0_reset_kgq(struct amdgpu_ring *ring, unsigned int vmid)if (r)return r; - r =amdgpu_bo_reserve (ring->mqd_obj, false); -if (unlikely (r !=0 )) { -DRM_ERROR ("fail to resv mqd_obj\n" ); -return r; - } - r =amdgpu_bo_kmap (ring->mqd_obj, (void **)&ring->mqd_ptr); -if (!r) { - r =gfx_v10_0_kgq_init_queue (ring, true); -amdgpu_bo_kunmap (ring->mqd_obj); - ring->mqd_ptr =NULL ; - } -amdgpu_bo_unreserve (ring->mqd_obj); -if (r) { -DRM_ERROR ("fail to unresv mqd_obj\n" ); -return r; - } +if (amdgpu_ring_alloc (ring,7 +7 +5 +7 )) +return -ENOMEM ; +gfx_v10_0_ring_emit_pipeline_sync (ring); +amdgpu_ring_commit (ring); -return amdgpu_ring_test_ring (ring); +return gfx_v10_0_ring_test_ib (ring,AMDGPU_QUEUE_RESET_TIMEOUT ); } static int gfx_v10_0_reset_kcq(struct amdgpu_ring *ring,
@@ -9819,7 +9788,6 @@ static const struct amdgpu_ring_funcs gfx_v10_0_ring_funcs_gfx = { .emit_wreg = gfx_v10_0_ring_emit_wreg, .emit_reg_wait = gfx_v10_0_ring_emit_reg_wait, .emit_reg_write_reg_wait = gfx_v10_0_ring_emit_reg_write_reg_wait, - .soft_recovery = gfx_v10_0_ring_soft_recovery, .emit_mem_sync = gfx_v10_0_emit_mem_sync, .reset = gfx_v10_0_reset_kgq, .emit_cleaner_shader = gfx_v10_0_ring_emit_cleaner_shader,
@@ -9860,7 +9828,6 @@ static const struct amdgpu_ring_funcs gfx_v10_0_ring_funcs_compute = { .emit_wreg = gfx_v10_0_ring_emit_wreg, .emit_reg_wait = gfx_v10_0_ring_emit_reg_wait, .emit_reg_write_reg_wait = gfx_v10_0_ring_emit_reg_write_reg_wait, - .soft_recovery = gfx_v10_0_ring_soft_recovery, .emit_mem_sync = gfx_v10_0_emit_mem_sync, .reset = gfx_v10_0_reset_kcq, .emit_cleaner_shader = gfx_v10_0_ring_emit_cleaner_shader,
Signature · 1 line
2.34.1
Re: [PATCH 5/5] drm/amdgpu: rework gfx10 queue reset
Quoted 142 lines · Christian König
Apply the same changes to gfx10 as done to gfx9.
The general idea to reset the whole kernel queue and then asking the kiq to map it again didn't worked at all. Background is that we don't use per application kernel queues for gfx10 on Linux for performance reasons.
So instead use the gfx9 approach here as well and only reset all submissions from a specific VMID instead of the whole queue.
This also avoids reserving and kmap the MQD which are operations generally not allowed in the reset handler.
This approach seems to work for at least some time, but not as reliable as it is on gfx9. It will probably need some more work until it survives a whole night of reset stress testing.
Signed-off-by Christian König <[email protected]>--- drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c | 65 +++++++------------------- 1 file changed, 16 insertions(+), 49 deletions(-)drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +16
-48@@ -8684,7 +8684,17 @@ static void gfx_v10_0_ring_emit_pipeline_sync(struct amdgpu_ring *ring)int usepfp = (ring->funcs->type ==AMDGPU_RING_TYPE_GFX );uint32_t seq = ring->fence_drv.sync_seq;uint64_t addr = ring->fence_drv.gpu_addr; +struct amdgpu_device *adev = ring->adev; +amdgpu_ring_emit_reg_wait (ring, +SOC15_REG_OFFSET (GC ,0 , mmCP_VMID_RESET), +0 ,0xffff ); +amdgpu_ring_emit_wreg (ring, +SOC15_REG_OFFSET (GC ,0 , mmCP_VMID_RESET), +0 ); +amdgpu_ring_emit_fence (ring, ring->fence_drv.gpu_addr, + ring->fence_drv.sync_seq, +AMDGPU_FENCE_FLAG_EXEC );gfx_v10_0_wait_reg_mem (ring, usepfp,1 ,0 ,lower_32_bits (addr),upper_32_bits (addr), seq,0xffffffff ,4 ); }@@ -8984,21 +8994,6 @@ static void gfx_v10_0_ring_emit_reg_write_reg_wait(struct amdgpu_ring *ring, ref, mask); } -static void gfx_v10_0_ring_soft_recovery (struct amdgpu_ring *ring, -unsigned int vmid) -{ -struct amdgpu_device *adev = ring->adev; -uint32_t value =0 ; - - value =REG_SET_FIELD (value,SQ_CMD ,CMD ,0x03 ); - value =REG_SET_FIELD (value,SQ_CMD ,MODE ,0x01 ); - value =REG_SET_FIELD (value,SQ_CMD ,CHECK_VMID ,1 ); - value =REG_SET_FIELD (value,SQ_CMD ,VM_ID , vmid); -amdgpu_gfx_rlc_enter_safe_mode (adev,0 ); -WREG32_SOC15 (GC ,0 , mmSQ_CMD, value); -amdgpu_gfx_rlc_exit_safe_mode (adev,0 ); -} - static void gfx_v10_0_set_gfx_eop_interrupt_state(struct amdgpu_device *adev, uint32_t me, uint32_t pipe,@@ -9467,7 +9462,6 @@ static int gfx_v10_0_reset_kgq(struct amdgpu_ring *ring, unsigned int vmid)struct amdgpu_ring *kiq_ring = &kiq->ring;unsigned long flags;u32 tmp; -u64 addr;int r;if (amdgpu_sriov_vf (adev))@@ -9478,27 +9472,14 @@ static int gfx_v10_0_reset_kgq(struct amdgpu_ring *ring, unsigned int vmid)spin_lock_irqsave (&kiq->ring_lock, flags); -if (amdgpu_ring_alloc (kiq_ring,5 +7 +7 + kiq->pmf->map_queues_size)) { +if (amdgpu_ring_alloc (kiq_ring,5 )) {spin_unlock_irqrestore (&kiq->ring_lock, flags);return -ENOMEM ; } - addr =amdgpu_bo_gpu_offset (ring->mqd_obj) + - offsetof(struct v10_gfx_mqd , cp_gfx_hqd_active); tmp =REG_SET_FIELD (0 ,CP_VMID_RESET ,RESET_REQUEST ,1 << vmid); -if (ring->pipe ==0 ) - tmp =REG_SET_FIELD (tmp,CP_VMID_RESET ,PIPE0_QUEUES ,1 << ring->queue); -else - tmp =REG_SET_FIELD (tmp,CP_VMID_RESET ,PIPE1_QUEUES ,1 << ring->queue); -gfx_v10_0_ring_emit_wreg (kiq_ring,SOC15_REG_OFFSET (GC ,0 , mmCP_VMID_RESET), tmp); -gfx_v10_0_wait_reg_mem (kiq_ring,0 ,1 ,0 , -lower_32_bits (addr),upper_32_bits (addr), -0 ,1 ,0x20 ); -gfx_v10_0_ring_emit_reg_wait (kiq_ring, -SOC15_REG_OFFSET (GC ,0 , mmCP_VMID_RESET),0 ,0xffffffff ); - kiq->pmf->kiq_map_queues (kiq_ring, ring);amdgpu_ring_commit (kiq_ring);spin_unlock_irqrestore (&kiq->ring_lock, flags);@@ -9507,24 +9488,12 @@ static int gfx_v10_0_reset_kgq(struct amdgpu_ring *ring, unsigned int vmid)if (r)return r; - r =amdgpu_bo_reserve (ring->mqd_obj, false); -if (unlikely (r !=0 )) { -DRM_ERROR ("fail to resv mqd_obj\n" ); -return r; - } - r =amdgpu_bo_kmap (ring->mqd_obj, (void **)&ring->mqd_ptr); -if (!r) { - r =gfx_v10_0_kgq_init_queue (ring, true); -amdgpu_bo_kunmap (ring->mqd_obj); - ring->mqd_ptr =NULL ; - } -amdgpu_bo_unreserve (ring->mqd_obj); -if (r) { -DRM_ERROR ("fail to unresv mqd_obj\n" ); -return r; - } +if (amdgpu_ring_alloc (ring,7 +7 +5 +7 )) +return -ENOMEM ; +gfx_v10_0_ring_emit_pipeline_sync (ring); +amdgpu_ring_commit (ring); -return amdgpu_ring_test_ring (ring); +return gfx_v10_0_ring_test_ib (ring,AMDGPU_QUEUE_RESET_TIMEOUT ); } static int gfx_v10_0_reset_kcq(struct amdgpu_ring *ring,@@ -9819,7 +9788,6 @@ static const struct amdgpu_ring_funcs gfx_v10_0_ring_funcs_gfx = { .emit_wreg = gfx_v10_0_ring_emit_wreg, .emit_reg_wait = gfx_v10_0_ring_emit_reg_wait, .emit_reg_write_reg_wait = gfx_v10_0_ring_emit_reg_write_reg_wait, - .soft_recovery = gfx_v10_0_ring_soft_recovery, .emit_mem_sync = gfx_v10_0_emit_mem_sync, .reset = gfx_v10_0_reset_kgq, .emit_cleaner_shader = gfx_v10_0_ring_emit_cleaner_shader,
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c static const struct amdgpu_ring_funcs gfx_v10_0_ring_funcs_compute = { · line 9863
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +0
-1@@ -9860,7 +9828,6 @@ static const struct amdgpu_ring_funcs gfx_v10_0_ring_funcs_compute = { .emit_wreg = gfx_v10_0_ring_emit_wreg, .emit_reg_wait = gfx_v10_0_ring_emit_reg_wait, .emit_reg_write_reg_wait = gfx_v10_0_ring_emit_reg_write_reg_wait, - .soft_recovery = gfx_v10_0_ring_soft_recovery,
And here.
Alex
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +0
-1.emit_mem_sync = gfx_v10_0_emit_mem_sync, .reset = gfx_v10_0_reset_kcq, .emit_cleaner_shader = gfx_v10_0_ring_emit_cleaner_shader, --2.34.1
Re: [PATCH 5/5] drm/amdgpu: rework gfx10 queue reset
In reply to Christian KönigQuoted 10 lines · Christian König
Apply the same changes to gfx10 as done to gfx9.
The general idea to reset the whole kernel queue and then asking the kiq to map it again didn't worked at all. Background is that we don't use per application kernel queues for gfx10 on Linux for performance reasons.
So instead use the gfx9 approach here as well and only reset all submissions from a specific VMID instead of the whole queue.
Quoted 6 lines
This also avoids reserving and kmap the MQD which are operations generally not allowed in the reset handler.
This approach seems to work for at least some time, but not as reliable as it is on gfx9. It will probably need some more work until it survives a whole night of reset stress testing.
Does disabling the second gfx pipe help? E.g., set adev->gfx.me.num_pipe_per_me = 1;
Alex
Quoted 136 lines
Signed-off-by Christian König <[email protected]>--- drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c | 65 +++++++------------------- 1 file changed, 16 insertions(+), 49 deletions(-)drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +16
-50@@ -8684,7 +8684,17 @@ static void gfx_v10_0_ring_emit_pipeline_sync(struct amdgpu_ring *ring)int usepfp = (ring->funcs->type ==AMDGPU_RING_TYPE_GFX );uint32_t seq = ring->fence_drv.sync_seq;uint64_t addr = ring->fence_drv.gpu_addr; +struct amdgpu_device *adev = ring->adev; +amdgpu_ring_emit_reg_wait (ring, +SOC15_REG_OFFSET (GC ,0 , mmCP_VMID_RESET), +0 ,0xffff ); +amdgpu_ring_emit_wreg (ring, +SOC15_REG_OFFSET (GC ,0 , mmCP_VMID_RESET), +0 ); +amdgpu_ring_emit_fence (ring, ring->fence_drv.gpu_addr, + ring->fence_drv.sync_seq, +AMDGPU_FENCE_FLAG_EXEC );gfx_v10_0_wait_reg_mem (ring, usepfp,1 ,0 ,lower_32_bits (addr),upper_32_bits (addr), seq,0xffffffff ,4 ); }@@ -8984,21 +8994,6 @@ static void gfx_v10_0_ring_emit_reg_write_reg_wait(struct amdgpu_ring *ring, ref, mask); } -static void gfx_v10_0_ring_soft_recovery (struct amdgpu_ring *ring, -unsigned int vmid) -{ -struct amdgpu_device *adev = ring->adev; -uint32_t value =0 ; - - value =REG_SET_FIELD (value,SQ_CMD ,CMD ,0x03 ); - value =REG_SET_FIELD (value,SQ_CMD ,MODE ,0x01 ); - value =REG_SET_FIELD (value,SQ_CMD ,CHECK_VMID ,1 ); - value =REG_SET_FIELD (value,SQ_CMD ,VM_ID , vmid); -amdgpu_gfx_rlc_enter_safe_mode (adev,0 ); -WREG32_SOC15 (GC ,0 , mmSQ_CMD, value); -amdgpu_gfx_rlc_exit_safe_mode (adev,0 ); -} - static void gfx_v10_0_set_gfx_eop_interrupt_state(struct amdgpu_device *adev, uint32_t me, uint32_t pipe,@@ -9467,7 +9462,6 @@ static int gfx_v10_0_reset_kgq(struct amdgpu_ring *ring, unsigned int vmid)struct amdgpu_ring *kiq_ring = &kiq->ring;unsigned long flags;u32 tmp; -u64 addr;int r;if (amdgpu_sriov_vf (adev))@@ -9478,27 +9472,14 @@ static int gfx_v10_0_reset_kgq(struct amdgpu_ring *ring, unsigned int vmid)spin_lock_irqsave (&kiq->ring_lock, flags); -if (amdgpu_ring_alloc (kiq_ring,5 +7 +7 + kiq->pmf->map_queues_size)) { +if (amdgpu_ring_alloc (kiq_ring,5 )) {spin_unlock_irqrestore (&kiq->ring_lock, flags);return -ENOMEM ; } - addr =amdgpu_bo_gpu_offset (ring->mqd_obj) + - offsetof(struct v10_gfx_mqd , cp_gfx_hqd_active); tmp =REG_SET_FIELD (0 ,CP_VMID_RESET ,RESET_REQUEST ,1 << vmid); -if (ring->pipe ==0 ) - tmp =REG_SET_FIELD (tmp,CP_VMID_RESET ,PIPE0_QUEUES ,1 << ring->queue); -else - tmp =REG_SET_FIELD (tmp,CP_VMID_RESET ,PIPE1_QUEUES ,1 << ring->queue); -gfx_v10_0_ring_emit_wreg (kiq_ring,SOC15_REG_OFFSET (GC ,0 , mmCP_VMID_RESET), tmp); -gfx_v10_0_wait_reg_mem (kiq_ring,0 ,1 ,0 , -lower_32_bits (addr),upper_32_bits (addr), -0 ,1 ,0x20 ); -gfx_v10_0_ring_emit_reg_wait (kiq_ring, -SOC15_REG_OFFSET (GC ,0 , mmCP_VMID_RESET),0 ,0xffffffff ); - kiq->pmf->kiq_map_queues (kiq_ring, ring);amdgpu_ring_commit (kiq_ring);spin_unlock_irqrestore (&kiq->ring_lock, flags);@@ -9507,24 +9488,12 @@ static int gfx_v10_0_reset_kgq(struct amdgpu_ring *ring, unsigned int vmid)if (r)return r; - r =amdgpu_bo_reserve (ring->mqd_obj, false); -if (unlikely (r !=0 )) { -DRM_ERROR ("fail to resv mqd_obj\n" ); -return r; - } - r =amdgpu_bo_kmap (ring->mqd_obj, (void **)&ring->mqd_ptr); -if (!r) { - r =gfx_v10_0_kgq_init_queue (ring, true); -amdgpu_bo_kunmap (ring->mqd_obj); - ring->mqd_ptr =NULL ; - } -amdgpu_bo_unreserve (ring->mqd_obj); -if (r) { -DRM_ERROR ("fail to unresv mqd_obj\n" ); -return r; - } +if (amdgpu_ring_alloc (ring,7 +7 +5 +7 )) +return -ENOMEM ; +gfx_v10_0_ring_emit_pipeline_sync (ring); +amdgpu_ring_commit (ring); -return amdgpu_ring_test_ring (ring); +return gfx_v10_0_ring_test_ib (ring,AMDGPU_QUEUE_RESET_TIMEOUT ); } static int gfx_v10_0_reset_kcq(struct amdgpu_ring *ring,@@ -9819,7 +9788,6 @@ static const struct amdgpu_ring_funcs gfx_v10_0_ring_funcs_gfx = { .emit_wreg = gfx_v10_0_ring_emit_wreg, .emit_reg_wait = gfx_v10_0_ring_emit_reg_wait, .emit_reg_write_reg_wait = gfx_v10_0_ring_emit_reg_write_reg_wait, - .soft_recovery = gfx_v10_0_ring_soft_recovery, .emit_mem_sync = gfx_v10_0_emit_mem_sync, .reset = gfx_v10_0_reset_kgq, .emit_cleaner_shader = gfx_v10_0_ring_emit_cleaner_shader,@@ -9860,7 +9828,6 @@ static const struct amdgpu_ring_funcs gfx_v10_0_ring_funcs_compute = { .emit_wreg = gfx_v10_0_ring_emit_wreg, .emit_reg_wait = gfx_v10_0_ring_emit_reg_wait, .emit_reg_write_reg_wait = gfx_v10_0_ring_emit_reg_write_reg_wait, - .soft_recovery = gfx_v10_0_ring_soft_recovery, .emit_mem_sync = gfx_v10_0_emit_mem_sync, .reset = gfx_v10_0_reset_kcq, .emit_cleaner_shader = gfx_v10_0_ring_emit_cleaner_shader, --2.34.1
RE: [PATCH 5/5] drm/amdgpu: rework gfx10 queue reset
In reply to Christian König[AMD Official Use Only - AMD Internal Distribution Only]
Quoted 133 lines
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Christian König
Sent: Tuesday, February 4, 2025 10:31 PM
To: [email protected]; Deucher, Alexander <[email protected]>; [email protected]
Subject: [PATCH 5/5] drm/amdgpu: rework gfx10 queue resetApply the same changes to gfx10 as done to gfx9.
The general idea to reset the whole kernel queue and then asking the kiq to map it again didn't worked at all. Background is that we don't use per application kernel queues for gfx10 on Linux for performance reasons.
So instead use the gfx9 approach here as well and only reset all submissions from a specific VMID instead of the whole queue.
This also avoids reserving and kmap the MQD which are operations generally not allowed in the reset handler.
This approach seems to work for at least some time, but not as reliable as it is on gfx9. It will probably need some more work until it survives a whole night of reset stress testing.
Signed-off-by Christian König <[email protected]>--- drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c | 65 +++++++------------------- 1 file changed, 16 insertions(+), 49 deletions(-)drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +10
-0@@ -8684,7 +8684,17 @@ static void gfx_v10_0_ring_emit_pipeline_sync(struct amdgpu_ring *ring)int usepfp = (ring->funcs->type ==AMDGPU_RING_TYPE_GFX );uint32_t seq = ring->fence_drv.sync_seq;uint64_t addr = ring->fence_drv.gpu_addr; +struct amdgpu_device *adev = ring->adev; +amdgpu_ring_emit_reg_wait (ring, +SOC15_REG_OFFSET (GC ,0 , mmCP_VMID_RESET), +0 ,0xffff ); +amdgpu_ring_emit_wreg (ring, +SOC15_REG_OFFSET (GC ,0 , mmCP_VMID_RESET), +0 ); +amdgpu_ring_emit_fence (ring, ring->fence_drv.gpu_addr, + ring->fence_drv.sync_seq, +AMDGPU_FENCE_FLAG_EXEC ); gfx_v10_0_wait_reg_mem(ring, usepfp, 1, 0, lower_32_bits(addr),upper_32_bits(addr), seq, 0xffffffff, 4); } @@ -8984,21 +8994,6 @@ static void gfx_v10_0_ring_emit_reg_write_reg_wait(struct amdgpu_ring *ring, ref, mask);}
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +0
-16-static void gfx_v10_0_ring_soft_recovery (struct amdgpu_ring *ring, -unsigned int vmid) -{ -struct amdgpu_device *adev = ring->adev; -uint32_t value =0 ; - - value =REG_SET_FIELD (value,SQ_CMD ,CMD ,0x03 ); - value =REG_SET_FIELD (value,SQ_CMD ,MODE ,0x01 ); - value =REG_SET_FIELD (value,SQ_CMD ,CHECK_VMID ,1 ); - value =REG_SET_FIELD (value,SQ_CMD ,VM_ID , vmid); -amdgpu_gfx_rlc_enter_safe_mode (adev,0 ); -WREG32_SOC15 (GC ,0 , mmSQ_CMD, value); -amdgpu_gfx_rlc_exit_safe_mode (adev,0 ); -} - static void gfx_v10_0_set_gfx_eop_interrupt_state(struct amdgpu_device *adev, uint32_t me, uint32_t pipe,@@ -9467,7 +9462,6 @@ static int gfx_v10_0_reset_kgq(struct amdgpu_ring *ring, unsigned int vmid)struct amdgpu_ring *kiq_ring = &kiq->ring;unsigned long flags;u32 tmp; -u64 addr;int r;if (
amdgpu_sriov_vf(adev))drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +1
-8@@ -9478,27 +9472,14 @@ static int gfx_v10_0_reset_kgq(struct amdgpu_ring *ring, unsigned int vmid) spin_lock_irqsave(&kiq->ring_lock, flags); -if (amdgpu_ring_alloc (kiq_ring,5 +7 +7 + kiq->pmf->map_queues_size)) { +if (amdgpu_ring_alloc (kiq_ring,5 )) {spin_unlock_irqrestore (&kiq->ring_lock, flags);return -ENOMEM ; } - addr =amdgpu_bo_gpu_offset (ring->mqd_obj) + - offsetof(struct v10_gfx_mqd , cp_gfx_hqd_active); tmp =REG_SET_FIELD (0 ,CP_VMID_RESET ,RESET_REQUEST ,1 << vmid); -if (ring->pipe ==0 ) - tmp =REG_SET_FIELD (tmp,CP_VMID_RESET ,PIPE0_QUEUES , 1 << ring->queue); -else - tmp =REG_SET_FIELD (tmp,CP_VMID_RESET ,PIPE1_QUEUES , 1 << ring->queue); - gfx_v10_0_ring_emit_wreg(kiq_ring, SOC15_REG_OFFSET(GC, 0,
mmCP_VMID_RESET), tmp);drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +0
-5-gfx_v10_0_wait_reg_mem (kiq_ring,0 ,1 ,0 , -lower_32_bits (addr),upper_32_bits (addr), -0 ,1 ,0x20 ); - gfx_v10_0_ring_emit_reg_wait(kiq_ring, - SOC15_REG_OFFSET(GC, 0,
mmCP_VMID_RESET), 0,0xffffffff);- kiq->pmf->kiq_map_queues(kiq_ring, ring); amdgpu_ring_commit(kiq_ring); spin_unlock_irqrestore(&kiq->ring_lock, flags); @@ -9507,24 +9488,12 @@ static int gfx_v10_0_reset_kgq(struct amdgpu_ring *ring, unsigned int vmid) if (r) return r;drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +0
-9- r =amdgpu_bo_reserve (ring->mqd_obj, false); -if (unlikely (r !=0 )) { -DRM_ERROR ("fail to resv mqd_obj\n" ); -return r; - } - r =amdgpu_bo_kmap (ring->mqd_obj, (void **)&ring->mqd_ptr); -if (!r) { - r =gfx_v10_0_kgq_init_queue (ring, true); -amdgpu_bo_kunmap (ring->mqd_obj);
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c static int gfx_v10_0_reset_kgq(struct amdgpu_ring *ring, unsigned int vmid) · line 9493
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +3
-7- ring->mqd_ptr =NULL ; - } -amdgpu_bo_unreserve (ring->mqd_obj); -if (r) { -DRM_ERROR ("fail to unresv mqd_obj\n" ); -return r; - } +if (amdgpu_ring_alloc (ring,7 +7 +5 +7 )) +return -ENOMEM ; +gfx_v10_0_ring_emit_pipeline_sync (ring);
Why we need to set CP_VMID_RESET 0xffff here? Does it mean that we have to reset(terminate) all the waves from the other vmids?
Thanks,
Jiadong
Quoted 27 lines
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +2
-1+amdgpu_ring_commit (ring); -return amdgpu_ring_test_ring (ring); + return gfx_v10_0_ring_test_ib(ring,
AMDGPU_QUEUE_RESET_TIMEOUT);
}static int gfx_v10_0_reset_kcq(struct
amdgpu_ring*ring, @@ -9819,7 +9788,6@@ static const struct amdgpu_ring_funcs gfx_v10_0_ring_funcs_gfx = { .emit_wreg = gfx_v10_0_ring_emit_wreg, .emit_reg_wait = gfx_v10_0_ring_emit_reg_wait, .emit_reg_write_reg_wait = gfx_v10_0_ring_emit_reg_write_reg_wait,drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +0
-2- .soft_recovery = gfx_v10_0_ring_soft_recovery, .emit_mem_sync = gfx_v10_0_emit_mem_sync, .reset = gfx_v10_0_reset_kgq, .emit_cleaner_shader = gfx_v10_0_ring_emit_cleaner_shader,@@ -9860,7 +9828,6 @@ static const struct amdgpu_ring_funcs gfx_v10_0_ring_funcs_compute = { .emit_wreg = gfx_v10_0_ring_emit_wreg, .emit_reg_wait = gfx_v10_0_ring_emit_reg_wait, .emit_reg_write_reg_wait = gfx_v10_0_ring_emit_reg_write_reg_wait, - .soft_recovery = gfx_v10_0_ring_soft_recovery, .emit_mem_sync = gfx_v10_0_emit_mem_sync, .reset = gfx_v10_0_reset_kcq,.emit_cleaner_shader =
gfx_v10_0_ring_emit_cleaner_shader,
--
2.34.1
Hi Christian,
Em 04/02/2025 11:31, Christian König escreveu:
Quoted 5 lines
Hi guys,
I finally found time to work on queue reset a bit more and also gave it some more testing.
How are you testing this series?
Hi André,
Sorry for the late reply - we've been discussing all of this on a different, long email thread.
Alex & Christian - do you think it's OK to include André on that thread?
André - in a nutshell, I was using a Mesa patch that intentionally breaks NGG culling:
https://gitlab.freedesktop.org/Venemo/mesa/-/commit/83bb8d88248cdbe7a7df6532efba0e8f81c9654a
which shows that neither the enforce_isolation series, nor the VMID reset series can actually recover from hangs.
Best regards,
Timur
Quoted 11 lines · André Almeida
Hi Christian,
Em 04/02/2025 11:31, Christian König escreveu:
Quoted 6 lines
Hi guys,
I finally found time to work on queue reset a bit more and also gave it
some more testing.How are you testing this series?