drm/amdgpu: rework queue reset scheduler interaction
Subsystems (2)
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 | 27 ++++++++++++------------- 1 file changed, 13 insertions(+), 14 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +13 -14
@@ -136,10 +136,12 @@ static enum drm_gpu_sched_stat amdgpu_job_timedout(struct drm_sched_job *s_job) }else if (amdgpu_gpu_recovery && ring->funcs->reset) {bool is_guilty; -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. +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);
@@ -157,19 +159,16 @@ static enum drm_gpu_sched_stat amdgpu_job_timedout(struct drm_sched_job *s_job) r =amdgpu_ring_reset (ring, job->vmid);if (!r) { -if (amdgpu_ring_sched_ready (ring)) -drm_sched_stop (&ring->sched, s_job); -if (is_guilty) { +if (is_guilty)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 ); -dev_err (adev->dev,"Ring %s reset succeeded\n" , ring->sched.name); -drm_dev_wedged_event (adev_to_drm (adev),DRM_WEDGE_RECOVERY_NONE ); +drm_sched_wqueue_start (&ring->sched); +dev_err (adev->dev,"Ring %s reset succeeded\n" , + ring->sched.name); +drm_dev_wedged_event (adev_to_drm (adev), +DRM_WEDGE_RECOVERY_NONE ); 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); }dma_fence_set_error (&s_job->s_fence->finished, -ETIME );
Signature · 1 line
2.34.1
PATCH 2/5 drm/amdgpu: rework gfx9 queue reset
Testing 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
@@ -278,6 +278,7 @@ extern int amdgpu_user_queue;#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@@ -278,6 +278,7 @@ extern int amdgpu_user_queue;#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@@ -5565,7 +5565,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 );@@ -5896,20 +5906,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) {@@ -7185,16 +7181,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,@@ -7437,7 +7429,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 */@@ -7475,7 +7467,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,@@ -7494,7 +7485,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 */@@ -7533,7 +7524,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,@@ -7555,7 +7545,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 7580
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +0
-1@@ -7577,7 +7567,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,
I think we should keep soft recovery for compute. For compute, it should do what we want.
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,@@ -7598,7 +7587,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
Christian König
maintainerRe: [PATCH 2/5] drm/amdgpu: rework gfx9 queue reset
Quoted 9 lines · Alex Deucher
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +1
-1@@ -7555,7 +7545,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 */
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c static const struct amdgpu_ring_funcs gfx_v9_0_ring_funcs_compute = { · line 7580
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +0
-1@@ -7577,7 +7567,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,I think we should keep soft recovery for compute. For compute, it should do what we want.
I would rather like to avoid that. As far as I can see the soft recovery is not guaranteed to work for compute queues when the VMID filter is used.
Instead I've worked on a patch to make sure that only one application at a time can use each queue. Should be unproblematic for compute since we have enough queues and use them round robin anyway.
Christian.
Quoted 2 lines
Alex
Re: [PATCH 2/5] drm/amdgpu: rework gfx9 queue reset
In reply to Christian KönigQuoted 87 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@@ -278,6 +278,7 @@ extern int amdgpu_user_queue;#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 +10
-14@@ -5565,7 +5565,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 );@@ -5896,20 +5906,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) {
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c static int gfx_v9_0_reset_kgq(struct amdgpu_ring *ring, unsigned int vmid) · line 7184
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +1
-1@@ -7185,16 +7181,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 ))
Hi Christian,
What is the meaning of all of the above additions (7 + 7 + 5 + 7)? I see it in many different parts of the code. Is this some indication of preambles?
Thanks
Quoted 78 lines
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +7
-14return -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,@@ -7437,7 +7429,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 */@@ -7475,7 +7467,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,@@ -7494,7 +7485,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 */@@ -7533,7 +7524,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,@@ -7555,7 +7545,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 */@@ -7577,7 +7567,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, .emit_mem_sync = gfx_v9_0_emit_mem_sync, .emit_wave_limit = gfx_v9_0_emit_wave_limit, .reset = gfx_v9_0_reset_kcq,@@ -7598,7 +7587,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 */Signature · 1 line
2.34.1
Signature · 1 line
Rodrigo Siqueira
Re: [PATCH 2/5] drm/amdgpu: rework gfx9 queue reset
Quoted 92 lines · Rodrigo Siqueira
Quoted 90 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@@ -278,6 +278,7 @@ extern int amdgpu_user_queue;#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 +10
-14@@ -5565,7 +5565,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 );@@ -5896,20 +5906,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) {@@ -7185,16 +7181,12 @@ static int gfx_v9_0_reset_kgq(struct amdgpu_ring *ring, unsigned int vmid)if (r)return r;
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c static int gfx_v9_0_reset_kgq(struct amdgpu_ring *ring, unsigned int vmid) · line 7184
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +1
-1-if (amdgpu_ring_alloc (ring,7 +7 +5 )) +if (amdgpu_ring_alloc (ring,7 +7 +5 +7 ))Hi Christian,
What is the meaning of all of the above additions (7 + 7 + 5 + 7)? I see it in many different parts of the code. Is this some indication of preambles?
It's the number of dwords needed for the operation. In this case gfx_v9_0_ring_emit_pipeline_sync() uses 7 + 7 + 5 + 7. Actually It should be 7 (gfx_v9_0_wait_reg_mem()) + 7 (amdgpu_ring_emit_reg_wait()) + 5 (amdgpu_ring_emit_wreg()) + 8 (amdgpu_ring_emit_fence()). Fixed up locally.
Alex
Quoted 84 lines
Thanks
Quoted 76 lines
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +7
-15return -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,@@ -7437,7 +7429,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 */@@ -7475,7 +7467,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,@@ -7494,7 +7485,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 */@@ -7533,7 +7524,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,@@ -7555,7 +7545,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 */@@ -7577,7 +7567,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, .emit_mem_sync = gfx_v9_0_emit_mem_sync, .emit_wave_limit = gfx_v9_0_emit_wave_limit, .reset = gfx_v9_0_reset_kcq,@@ -7598,7 +7587,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 */ --Quoted 2 lines
2.34.1
--
Rodrigo Siqueira
Re: [PATCH 2/5] drm/amdgpu: rework gfx9 queue reset
Quoted 11 lines · Alex Deucher
Quoted 10 lines · Rodrigo Siqueira
Quoted 8 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.
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
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.
Sorry, but could you elaborate a little bit more on what it is this pipeline sync?
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
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.
It appears that the soft recovery has passed the time validation, and in some ways, it is stable. How about to keep this approach as a fallback solution?
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
This now survives a stress test running over night sending a broken submission ever 45 seconds and recovering fine from each of them.
What is this stress test? Some sort of IGT test? Is it publicly available?
Quoted 20 lines
Quoted 20 lines
Quoted 20 lines
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@@ -278,6 +278,7 @@ extern int amdgpu_user_queue;#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 +0
-0
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c static void gfx_v9_0_ring_emit_pipeline_sync(struct amdgpu_ring *ring) · line 5568
Quoted 8 lines
index
d377a7c57d5e..92d9a28c62d3100644drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +1
-0@@ -5565,7 +5565,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;
btw, you don't need this variable.
Quoted 10 lines
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c static void gfx_v9_0_ring_emit_pipeline_sync(struct amdgpu_ring *ring) · line 5578
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +9
-0+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 );
Just for curiosity, why do we need reg_wait in the beginning and emit_fence in the end? Why not just use emit_wreg directly?
Quoted 37 lines
Quoted 28 lines
Quoted 28 lines
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +0
-14gfx_v9_0_wait_reg_mem (ring, usepfp,1 ,0 ,lower_32_bits (addr),upper_32_bits (addr), seq,0xffffffff ,4 );@@ -5896,20 +5906,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) {@@ -7185,16 +7181,12 @@ static int gfx_v9_0_reset_kgq(struct amdgpu_ring *ring, unsigned int vmid)if (r)return r;Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c static int gfx_v9_0_reset_kgq(struct amdgpu_ring *ring, unsigned int vmid) · line 7184
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +1
-1-if (amdgpu_ring_alloc (ring,7 +7 +5 )) +if (amdgpu_ring_alloc (ring,7 +7 +5 +7 ))Hi Christian,
What is the meaning of all of the above additions (7 + 7 + 5 + 7)? I see it in many different parts of the code. Is this some indication of preambles?
Quoted 5 lines
It's the number of dwords needed for the operation. In this case
gfx_v9_0_ring_emit_pipeline_sync()uses 7 + 7 + 5 + 7. Actually It should be 7 (gfx_v9_0_wait_reg_mem()) + 7 (amdgpu_ring_emit_reg_wait()) + 5 (amdgpu_ring_emit_wreg()) + 8 (amdgpu_ring_emit_fence()). Fixed up locally.
Nice! Thanks for the explantion.
Thanks
Siqueira
Quoted 87 lines
Alex
Quoted 84 lines
Thanks
Quoted 76 lines
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +7
-15return -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,@@ -7437,7 +7429,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 */@@ -7475,7 +7467,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,@@ -7494,7 +7485,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 */@@ -7533,7 +7524,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,@@ -7555,7 +7545,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 */@@ -7577,7 +7567,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, .emit_mem_sync = gfx_v9_0_emit_mem_sync, .emit_wave_limit = gfx_v9_0_emit_wave_limit, .reset = gfx_v9_0_reset_kcq,@@ -7598,7 +7587,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 */ --Quoted 2 lines
2.34.1
--
Rodrigo Siqueira
Signature · 1 line
Rodrigo Siqueira
Re: [PATCH 2/5] drm/amdgpu: rework gfx9 queue reset
Quoted 13 lines · Rodrigo Siqueira
Quoted 11 lines · Alex Deucher
Quoted 10 lines · Rodrigo Siqueira
Quoted 8 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.
Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
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.Sorry, but could you elaborate a little bit more on what it is this pipeline sync?
pipeline sync waits for the previous job to complete before the next job starts.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
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.
Quoted 6 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
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.It appears that the soft recovery has passed the time validation, and in some ways, it is stable. How about to keep this approach as a fallback solution?
We can definitely keep it where queue reset is not available. Queue reset is able to recover from more hang cases.
Quoted 30 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
This now survives a stress test running over night sending a broken submission ever 45 seconds and recovering fine from each of them.
What is this stress test? Some sort of IGT test? Is it publicly available?
Quoted 22 lines
Quoted 22 lines
Quoted 22 lines
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@@ -278,6 +278,7 @@ extern int amdgpu_user_queue;#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 +0
-1--- a/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c
Quoted 8 lines
Quoted 6 lines
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c static void gfx_v9_0_ring_emit_pipeline_sync(struct amdgpu_ring *ring) · line 5568
Quoted 6 lines
+++
b/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.cdrivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +1
-0@@ -5565,7 +5565,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;btw, you don't need this variable.
I think it's needed by the register macros.
Quoted 12 lines
Quoted 11 lines
Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c static void gfx_v9_0_ring_emit_pipeline_sync(struct amdgpu_ring *ring) · line 5578
Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +9
-0+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 );
Quoted 2 lines
Just for curiosity, why do we need
reg_waitin the beginning andemit_fencein the end? Why not just useemit_wregdirectly?
That's the programming sequence for the reset. You program the CP_VMID_RESET register and then you wait for it to go to 0, then write 0 to it, then wait on the fence. In theory is just resets the pipeline state associated with the vmid, but in practice it doesn't seem to work that way.
Alex
Quoted 139 lines
Quoted 38 lines
Quoted 29 lines
Quoted 29 lines
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +0
-14gfx_v9_0_wait_reg_mem (ring, usepfp,1 ,0 ,lower_32_bits (addr),upper_32_bits (addr), seq,0xffffffff ,4 );@@ -5896,20 +5906,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) {@@ -7185,16 +7181,12 @@ static int gfx_v9_0_reset_kgq(struct amdgpu_ring *ring, unsigned int vmid)if (r)return r;Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c static int gfx_v9_0_reset_kgq(struct amdgpu_ring *ring, unsigned int vmid) · line 7184
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +1
-1-if (amdgpu_ring_alloc (ring,7 +7 +5 )) +if (amdgpu_ring_alloc (ring,7 +7 +5 +7 ))Hi Christian,
What is the meaning of all of the above additions (7 + 7 + 5 + 7)? I see it in many different parts of the code. Is this some indication of preambles?
Quoted 5 lines
It's the number of dwords needed for the operation. In this case
gfx_v9_0_ring_emit_pipeline_sync()uses 7 + 7 + 5 + 7. Actually It should be 7 (gfx_v9_0_wait_reg_mem()) + 7 (amdgpu_ring_emit_reg_wait()) + 5 (amdgpu_ring_emit_wreg()) + 8 (amdgpu_ring_emit_fence()). Fixed up locally.Nice! Thanks for the explantion.
Thanks
SiqueiraQuoted 87 lines
Alex
Quoted 84 lines
Thanks
Quoted 76 lines
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +7
-15return -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,@@ -7437,7 +7429,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 */@@ -7475,7 +7467,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,@@ -7494,7 +7485,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 */@@ -7533,7 +7524,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,@@ -7555,7 +7545,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 */@@ -7577,7 +7567,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, .emit_mem_sync = gfx_v9_0_emit_mem_sync, .emit_wave_limit = gfx_v9_0_emit_wave_limit, .reset = gfx_v9_0_reset_kcq,@@ -7598,7 +7587,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 */ --Quoted 2 lines
2.34.1
--
Rodrigo Siqueira--
Rodrigo Siqueira
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
@@ -3095,6 +3095,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 *
@@ -3109,6 +3136,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 */
@@ -3998,18 +4030,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,
@@ -4884,34 +4904,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;
@@ -4944,14 +4936,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 = {
@@ -4984,7 +4975,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 */
@@ -5001,7 +4992,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, };
@@ -5018,7 +5008,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 */
@@ -5034,7 +5024,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@@ -3095,6 +3095,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 * @@ -3109,6 +3136,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 */@@ -3998,18 +4030,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,@@ -4884,34 +4904,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;@@ -4944,14 +4936,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 = {@@ -4984,7 +4975,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 */@@ -5001,7 +4992,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, };@@ -5018,7 +5008,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 5037
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c +0
-1@@ -5034,7 +5024,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,
Same comment here 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
@@ -6140,12 +6140,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 */
@@ -6339,46 +6372,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) {
@@ -6875,14 +6868,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 = {
@@ -6948,7 +6940,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, };
@@ -6983,7 +6974,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@@ -6140,12 +6140,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 */@@ -6339,46 +6372,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) {@@ -6875,14 +6868,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 = {@@ -6948,7 +6940,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 6986
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c +0
-1@@ -6983,7 +6974,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 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.
Navi 10 seems to be stable, but Navi 2x still shows hangs during over night testing. This needs more investigation, but the result is clearly better than before.
--- drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c | 57 ++++++++------------------ 1 file changed, 16 insertions(+), 41 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +16 -41
@@ -8746,7 +8746,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 ); }
@@ -9046,21 +9056,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,
@@ -9529,38 +9524,21 @@ 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))return -EINVAL ; -if (!kiq->pmf || !kiq->pmf->kiq_unmap_queues) -return -EINVAL ; -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);
@@ -9569,13 +9547,12 @@ static int gfx_v10_0_reset_kgq(struct amdgpu_ring *ring, unsigned int vmid)if (r)return r; - r =gfx_v10_0_kgq_init_queue (ring, true); -if (r) { -DRM_ERROR ("fail to init kgq\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,
@@ -9882,7 +9859,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,
@@ -9923,7 +9899,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 7 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.
Quoted 6 lines
So instead use the gfx9 approach here as well and only reset all submissions from a specific VMID instead of the whole queue.
Navi 10 seems to be stable, but Navi 2x still shows hangs during over night testing. This needs more investigation, but the result is clearly better than before.
For gfx 10.3, we enable the second gfx pipe as a high priority queue. Disabling that might help. Revert:
commit b7a1a0ef12b81957584fef7b61e2d5ec049c7209
Author: Arunpravin Paneer Selvam <[email protected]> Date: Mon Jun 6 13:59:13 2022 +0530
drm/amd/amdgpu: add pipe1 hardware support
Enable pipe1 support starting from SIENNA CICHLID asic
Quoted 118 lines
Signed-off-by Christian König <[email protected]>--- drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c | 57 ++++++++------------------ 1 file changed, 16 insertions(+), 41 deletions(-)drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +16
-40@@ -8746,7 +8746,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 ); }@@ -9046,21 +9056,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,@@ -9529,38 +9524,21 @@ 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))return -EINVAL ; -if (!kiq->pmf || !kiq->pmf->kiq_unmap_queues) -return -EINVAL ; -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);@@ -9569,13 +9547,12 @@ static int gfx_v10_0_reset_kgq(struct amdgpu_ring *ring, unsigned int vmid)if (r)return r; - r =gfx_v10_0_kgq_init_queue (ring, true); -if (r) { -DRM_ERROR ("fail to init kgq\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,@@ -9882,7 +9859,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 9926
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +0
-1@@ -9923,7 +9899,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,
Same comment as the rest of the series for compute.
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
Quoted 65 lines · Christian König
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.
Signed-off-by Christian König <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 27 ++++++++++++------------- 1 file changed, 13 insertions(+), 14 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +13
-14@@ -136,10 +136,12 @@ static enum drm_gpu_sched_stat amdgpu_job_timedout(struct drm_sched_job *s_job) }else if (amdgpu_gpu_recovery && ring->funcs->reset) {bool is_guilty; -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. +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);@@ -157,19 +159,16 @@ static enum drm_gpu_sched_stat amdgpu_job_timedout(struct drm_sched_job *s_job) r =amdgpu_ring_reset (ring, job->vmid);if (!r) { -if (amdgpu_ring_sched_ready (ring)) -drm_sched_stop (&ring->sched, s_job); -if (is_guilty) { +if (is_guilty)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 ); -dev_err (adev->dev,"Ring %s reset succeeded\n" , ring->sched.name); -drm_dev_wedged_event (adev_to_drm (adev),DRM_WEDGE_RECOVERY_NONE ); +drm_sched_wqueue_start (&ring->sched); +dev_err (adev->dev,"Ring %s reset succeeded\n" , + ring->sched.name); +drm_dev_wedged_event (adev_to_drm (adev), +DRM_WEDGE_RECOVERY_NONE ); 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); }dma_fence_set_error (&s_job->s_fence->finished, -ETIME );Signature · 1 line
2.34.1
Hi Christian,
I tested your series with Polaris and the 6600 series with the HangTest suite, and with your series, the following tests failed:
- soft_recovery_loop
- soft_recovery_pagefault_read
- soft_recovery_pagefault_write
When using the latest code of the amd-staging-drm-next, all of the above tests behave well. I'll try to identify what is going on.
Thanks
Signature · 1 line
Rodrigo Siqueira