Reset improvements
Subsystems (3)
Alex Deucher
maintainerv13 cover Reset improvements
This set improves per queue reset support for a number of IPs. When we reset the queue, the queue is lost so we need to re-emit the unprocessed state from subsequent submissions. This is handled in gfx/compute queues via switch buffer and pipeline sync packets. However, you can still end up with parallel execution across queues. For correctness in that cause, enforce isolation needs to be enabled. That can impact certain use cases however and in most cases, the guilty job is correctly identified even without enforce isolation.
Tested on GC 10 and 11 chips with a game running and then running hang tests. The game pauses when the hang happens, then continues after the queue reset.
The same approach is extended to SDMA and VCN. They don't need enforce isolation because those engines are single threaded so they always operate serially.
Rework re-emit to signal the seq number of the bad job and verify that to verify that the reset worked, then re-emit the rest of the non-guilty state. This way we are not waiting on the rest of the state to complete, and if the subsequent state also contains a bad job, we'll end up in queue reset again rather than adapter reset.
Patches apply to the amd-staging-drm-next or drm-next branches in my git tree.
Git tree:
https://gitlab.freedesktop.org/agd5f/linux/-/commits/kq_resets?ref_type=heads
The IGT deadlock tests need the following fixes to properly handle -ETIME fences:
https://patchwork.freedesktop.org/series/150724/
v4: Drop explicit padding patches
Drop new timeout macro
Rework re-emit sequence
v5: Add a helper for reemit
Convert VCN, JPEG, SDMA to use new helpers
v6: Update SDMA 4.4.2 to use new helpers
Move ptr tracking to amdgpu_fence
Skip all jobs from the bad context on the ring
v7: Rework the backup logic
Move and clean up the guilty logic for engine resets Integrate suggestions from Christian
Add JPEG 4.0.5 support
v8: Add non-guilty ring backup handling
Clean up new function signatures
Reorder some bug fixes to the start of the series
v9: Clean up fence_emit
SDMA 5.x fixes
Add new reset helpers
sched wqueue stop/start cleanup
Add support for VCNs without unified queues
v10: Drop enforce isolation default change
Add more documentation
Clean up ring backup logic
v11: SDMA6/7 fixes
v12: Ring backup and reemit fixes
SDMA cleanups
SDMA5.x reemit support
GFX10 KGQ reset fix
v13: drop SDMA cleaups, they caused regressions in some IGT tests
Alex Deucher (28):
drm/amdgpu/sdma: consolidate engine reset handling drm/amdgpu/sdma: allow caller to handle kernel rings in engine reset drm/amdgpu: track ring state associated with a fence drm/amdgpu/gfx9: re-emit unprocessed state on kcq reset drm/amdgpu/gfx9.4.3: re-emit unprocessed state on kcq reset drm/amdgpu/gfx10: re-emit unprocessed state on ring reset drm/amdgpu/gfx11: re-emit unprocessed state on ring reset drm/amdgpu/gfx12: re-emit unprocessed state on ring reset drm/amdgpu/sdma5: re-emit unprocessed state on ring reset drm/amdgpu/sdma5.2: re-emit unprocessed state on ring reset drm/amdgpu/sdma6: re-emit unprocessed state on ring reset drm/amdgpu/sdma7: re-emit unprocessed state on ring reset drm/amdgpu/jpeg2: re-emit unprocessed state on ring reset drm/amdgpu/jpeg2.5: re-emit unprocessed state on ring reset drm/amdgpu/jpeg3: re-emit unprocessed state on ring reset drm/amdgpu/jpeg4: re-emit unprocessed state on ring reset drm/amdgpu/jpeg4.0.3: re-emit unprocessed state on ring reset drm/amdgpu/jpeg4.0.5: add queue reset
drm/amdgpu/jpeg5: add queue reset
drm/amdgpu/jpeg5.0.1: re-emit unprocessed state on ring reset drm/amdgpu/vcn4: re-emit unprocessed state on ring reset drm/amdgpu/vcn4.0.3: re-emit unprocessed state on ring reset drm/amdgpu/vcn4.0.5: re-emit unprocessed state on ring reset drm/amdgpu/vcn5: re-emit unprocessed state on ring reset drm/amdgpu/vcn: add a helper framework for engine resets drm/amdgpu/vcn2: implement ring reset
drm/amdgpu/vcn2.5: implement ring reset
drm/amdgpu/vcn3: implement ring reset
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c | 90 +++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c | 15 +++- drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 4 +- drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c | 67 ++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h | 18 ++++ drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c | 43 +++++---- drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h | 3 +- drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c | 76 ++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h | 6 +- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 4 + drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c | 41 ++------- drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 35 +------- drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c | 35 +------- drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c | 12 +-- drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c | 12 +-- drivers/gpu/drm/amd/amdgpu/jpeg_v2_0.c | 11 +-- drivers/gpu/drm/amd/amdgpu/jpeg_v2_5.c | 11 +-- drivers/gpu/drm/amd/amdgpu/jpeg_v3_0.c | 11 +-- drivers/gpu/drm/amd/amdgpu/jpeg_v4_0.c | 11 +-- drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_3.c | 11 +-- drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_5.c | 11 +++ drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_0.c | 14 +++ drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_1.c | 11 +-- drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c | 19 +--- drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c | 23 +++-- drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c | 23 +++-- drivers/gpu/drm/amd/amdgpu/sdma_v6_0.c | 18 ++-- drivers/gpu/drm/amd/amdgpu/sdma_v7_0.c | 18 ++-- drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c | 12 +++ drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c | 11 +++ drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c | 13 +++ drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c | 11 +-- drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c | 10 +-- drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.c | 11 +-- drivers/gpu/drm/amd/amdgpu/vcn_v5_0_0.c | 11 +-- .../drm/amd/amdkfd/kfd_device_queue_manager.c | 2 +- 36 files changed, 454 insertions(+), 280 deletions(-)
Signature · 1 line
2.50.0
Alex Deucher
maintainerPATCH v13 1/28 drm/amdgpu/sdma: consolidate engine reset handling
Move the force completion handling into the common engine reset function. No need to duplicate it for every IP version.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c | 5 ++++- drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c | 17 +---------------- drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c | 6 ++---- drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c | 6 ++---- 4 files changed, 9 insertions(+), 25 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +4 -1
@@ -573,9 +573,12 @@ int amdgpu_sdma_reset_engine(struct amdgpu_device *adev, uint32_t instance_id)* to be submitted to the queues after the reset is complete. */ if (!ret) { +amdgpu_fence_driver_force_completion (gfx_ring);drm_sched_wqueue_start (&gfx_ring->sched); -if (adev->sdma.has_page_queue) +if (adev->sdma.has_page_queue) { +amdgpu_fence_driver_force_completion (page_ring);drm_sched_wqueue_start (&page_ring->sched); + } }mutex_unlock (&sdma_instance->engine_reset_mutex);
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +1 -16
@@ -1714,7 +1714,7 @@ static int sdma_v4_4_2_stop_queue(struct amdgpu_ring *ring)static int sdma_v4_4_2_restore_queue (struct amdgpu_ring *ring) {struct amdgpu_device *adev = ring->adev; -u32 inst_mask, tmp_mask; +u32 inst_mask;int i, r; inst_mask =1 << ring->me;
@@ -1733,21 +1733,6 @@ static int sdma_v4_4_2_restore_queue(struct amdgpu_ring *ring) } r =sdma_v4_4_2_inst_start (adev, inst_mask, true); -if (r) -return r; - - tmp_mask = inst_mask; -for_each_inst (i, tmp_mask) { - ring = &adev->sdma.instance[i].ring; - -amdgpu_fence_driver_force_completion (ring); - -if (adev->sdma.has_page_queue) { -struct amdgpu_ring *page = &adev->sdma.instance[i].page; - -amdgpu_fence_driver_force_completion (page); - } - }return r; }
drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c +2 -4
@@ -1618,10 +1618,8 @@ static int sdma_v5_0_restore_queue(struct amdgpu_ring *ring) r =sdma_v5_0_gfx_resume_instance (adev, inst_id, true);amdgpu_gfx_rlc_exit_safe_mode (adev,0 ); -if (r) -return r; -amdgpu_fence_driver_force_completion (ring); -return 0 ; + +return r; }static int sdma_v5_0_ring_preempt_ib (struct amdgpu_ring *ring)
drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c +2 -4
@@ -1534,10 +1534,8 @@ static int sdma_v5_2_restore_queue(struct amdgpu_ring *ring) r =sdma_v5_2_gfx_resume_instance (adev, inst_id, true);amdgpu_gfx_rlc_exit_safe_mode (adev,0 ); -if (r) -return r; -amdgpu_fence_driver_force_completion (ring); -return 0 ; + +return r; }static int sdma_v5_2_ring_preempt_ib (struct amdgpu_ring *ring)
Signature · 1 line
2.50.0
RE: [PATCH 01/28] drm/amdgpu/sdma: consolidate engine reset handling
[AMD Official Use Only - AMD Internal Distribution Only]
this patch is Reviewed-by: Jesse Zhang <[email protected]>
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Alex Deucher
Sent: Wednesday, July 2, 2025 2:44 AM
To: [email protected]; Koenig, Christian <[email protected]>; Sundararaju, Sathishkumar <[email protected]>
Cc: Deucher, Alexander <[email protected]>
Subject: [PATCH 01/28] drm/amdgpu/sdma: consolidate engine reset handling
Move the force completion handling into the common engine reset function. No need to duplicate it for every IP version.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c | 5 ++++- drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c | 17 +---------------- drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c | 6 ++---- drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c | 6 ++---- 4 files changed, 9 insertions(+), 25 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +4 -1
@@ -573,9 +573,12 @@ int amdgpu_sdma_reset_engine(struct amdgpu_device *adev, uint32_t instance_id)* to be submitted to the queues after the reset is complete. */ if (!ret) { +amdgpu_fence_driver_force_completion (gfx_ring);drm_sched_wqueue_start (&gfx_ring->sched); -if (adev->sdma.has_page_queue) +if (adev->sdma.has_page_queue) { +amdgpu_fence_driver_force_completion (page_ring);drm_sched_wqueue_start (&page_ring->sched); + } }mutex_unlock (&sdma_instance->engine_reset_mutex);
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +1 -16
@@ -1714,7 +1714,7 @@ static int sdma_v4_4_2_stop_queue(struct amdgpu_ring *ring) static int sdma_v4_4_2_restore_queue(struct amdgpu_ring *ring) {struct amdgpu_device *adev = ring->adev; -u32 inst_mask, tmp_mask; +u32 inst_mask;int i, r; inst_mask =1 << ring->me;
@@ -1733,21 +1733,6 @@ static int sdma_v4_4_2_restore_queue(struct amdgpu_ring *ring) } r =sdma_v4_4_2_inst_start (adev, inst_mask, true); -if (r) -return r; - - tmp_mask = inst_mask; -for_each_inst (i, tmp_mask) { - ring = &adev->sdma.instance[i].ring; - -amdgpu_fence_driver_force_completion (ring); - -if (adev->sdma.has_page_queue) { -struct amdgpu_ring *page = &adev->sdma.instance[i].page; - -amdgpu_fence_driver_force_completion (page); - } - }return r; }
drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c +2 -4
@@ -1618,10 +1618,8 @@ static int sdma_v5_0_restore_queue(struct amdgpu_ring *ring) r =sdma_v5_0_gfx_resume_instance (adev, inst_id, true);amdgpu_gfx_rlc_exit_safe_mode (adev,0 ); -if (r) -return r; -amdgpu_fence_driver_force_completion (ring); -return 0 ; + +return r; } static int sdma_v5_0_ring_preempt_ib(struct amdgpu_ring *ring) diff --git a/drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c b/drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c
index 42a25150f83ac..b87a4b44fa939 100644
drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c +2 -4
@@ -1534,10 +1534,8 @@ static int sdma_v5_2_restore_queue(struct amdgpu_ring *ring) r =sdma_v5_2_gfx_resume_instance (adev, inst_id, true);amdgpu_gfx_rlc_exit_safe_mode (adev,0 ); -if (r) -return r; -amdgpu_fence_driver_force_completion (ring); -return 0 ; + +return r; }static int sdma_v5_2_ring_preempt_ib (struct amdgpu_ring *ring)
--
2.50.0
Re: [PATCH 01/28] drm/amdgpu/sdma: consolidate engine reset handling
In reply to Alex DeucherQuoted 44 lines · Alex Deucher
Move the force completion handling into the common engine reset function. No need to duplicate it for every IP version.
Signed-off-by Alex Deucher <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c | 5 ++++- drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c | 17 +---------------- drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c | 6 ++---- drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c | 6 ++---- 4 files changed, 9 insertions(+), 25 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +4
-1@@ -573,9 +573,12 @@ int amdgpu_sdma_reset_engine(struct amdgpu_device *adev, uint32_t instance_id)* to be submitted to the queues after the reset is complete. */ if (!ret) { +amdgpu_fence_driver_force_completion (gfx_ring);drm_sched_wqueue_start (&gfx_ring->sched); -if (adev->sdma.has_page_queue) +if (adev->sdma.has_page_queue) { +amdgpu_fence_driver_force_completion (page_ring);drm_sched_wqueue_start (&page_ring->sched); + } }mutex_unlock (&sdma_instance->engine_reset_mutex);drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +1
-1@@ -1714,7 +1714,7 @@ static int sdma_v4_4_2_stop_queue(struct amdgpu_ring *ring)static int sdma_v4_4_2_restore_queue (struct amdgpu_ring *ring) {struct amdgpu_device *adev = ring->adev; -u32 inst_mask, tmp_mask; +u32 inst_mask;int i, r; inst_mask =1 << ring->me;
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c static int sdma_v4_4_2_restore_queue(struct amdgpu_ring *ring) · line 1735
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +0
-0@@ -1733,21 +1733,6 @@ static int sdma_v4_4_2_restore_queue(struct amdgpu_ring *ring) } r =sdma_v4_4_2_inst_start (adev, inst_mask, true);
Now that you have deleted the below code, I think you can remove the variable 'r' and use 'return sdma_v4_4_2_inst_start'.
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c static int sdma_v4_4_2_restore_queue(struct amdgpu_ring *ring) · line 1748
Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +0
-13-if (r) -return r; - - tmp_mask = inst_mask; -for_each_inst (i, tmp_mask) { - ring = &adev->sdma.instance[i].ring; - -amdgpu_fence_driver_force_completion (ring); - -if (adev->sdma.has_page_queue) { -struct amdgpu_ring *page = &adev->sdma.instance[i].page; - -amdgpu_fence_driver_force_completion (page);
I guess I'm missing something, but this part is slightly different from amdgpu_sdma_reset_engine since here amdgpu_fence_driver_force_completion() can be called twice in some cases.
Thanks
Quoted 42 lines
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +0
-2- } - }return r; }drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c +2
-4@@ -1618,10 +1618,8 @@ static int sdma_v6_0_restore_queue(struct amdgpu_ring *ring) r =sdma_v5_0_gfx_resume_instance (adev, inst_id, true);amdgpu_gfx_rlc_exit_safe_mode (adev,0 ); -if (r) -return r; -amdgpu_fence_driver_force_completion (ring); -return 0 ; + +return r; }static int sdma_v5_0_ring_preempt_ib (struct amdgpu_ring *ring)drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c +2
-4@@ -1534,10 +1534,8 @@ static int sdma_v5_2_restore_queue(struct amdgpu_ring *ring) r =sdma_v5_2_gfx_resume_instance (adev, inst_id, true);amdgpu_gfx_rlc_exit_safe_mode (adev,0 ); -if (r) -return r; -amdgpu_fence_driver_force_completion (ring); -return 0 ; + +return r; }static int sdma_v5_2_ring_preempt_ib (struct amdgpu_ring *ring)Signature · 1 line
2.50.0
Signature · 1 line
Rodrigo Siqueira
Re: [PATCH 01/28] drm/amdgpu/sdma: consolidate engine reset handling
Quoted 63 lines · Rodrigo Siqueira
Quoted 44 lines · Alex Deucher
Move the force completion handling into the common engine reset function. No need to duplicate it for every IP version.
Signed-off-by Alex Deucher <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c | 5 ++++- drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c | 17 +---------------- drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c | 6 ++---- drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c | 6 ++---- 4 files changed, 9 insertions(+), 25 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +4
-1@@ -573,9 +573,12 @@ int amdgpu_sdma_reset_engine(struct amdgpu_device *adev, uint32_t instance_id)* to be submitted to the queues after the reset is complete. */ if (!ret) { +amdgpu_fence_driver_force_completion (gfx_ring);drm_sched_wqueue_start (&gfx_ring->sched); -if (adev->sdma.has_page_queue) +if (adev->sdma.has_page_queue) { +amdgpu_fence_driver_force_completion (page_ring);drm_sched_wqueue_start (&page_ring->sched); + } }mutex_unlock (&sdma_instance->engine_reset_mutex);drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +1
-1@@ -1714,7 +1714,7 @@ static int sdma_v4_4_2_stop_queue(struct amdgpu_ring *ring)static int sdma_v4_4_2_restore_queue (struct amdgpu_ring *ring) {struct amdgpu_device *adev = ring->adev; -u32 inst_mask, tmp_mask; +u32 inst_mask;int i, r; inst_mask =1 << ring->me;drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c static int sdma_v4_4_2_restore_queue(struct amdgpu_ring *ring) · line 1735
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +0
-0@@ -1733,21 +1733,6 @@ static int sdma_v4_4_2_restore_queue(struct amdgpu_ring *ring) } r =sdma_v4_4_2_inst_start (adev, inst_mask, true);Now that you have deleted the below code, I think you can remove the variable 'r' and use 'return
sdma_v4_4_2_inst_start'.Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +0
-10-if (r) -return r; - - tmp_mask = inst_mask; -for_each_inst (i, tmp_mask) { - ring = &adev->sdma.instance[i].ring; - -amdgpu_fence_driver_force_completion (ring); - -if (adev->sdma.has_page_queue) {
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c static int sdma_v4_4_2_restore_queue(struct amdgpu_ring *ring) · line 1748
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +0
-3-struct amdgpu_ring *page = &adev->sdma.instance[i].page; - -amdgpu_fence_driver_force_completion (page);I guess I'm missing something, but this part is slightly different from
amdgpu_sdma_reset_enginesince hereamdgpu_fence_driver_force_completion()can be called twice in some cases.
The logic should be the same. There are potentially two kernel rings per instance: gfx and page. This function is only ever called per engine instance so we'd only ever reset one instance.
Alex
Quoted 48 lines
Thanks
Quoted 40 lines
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +0
-2- } - }return r; }drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c +2
-4@@ -1618,10 +1618,8 @@ static int sdma_v6_0_restore_queue(struct amdgpu_ring *ring) r =sdma_v5_0_gfx_resume_instance (adev, inst_id, true);amdgpu_gfx_rlc_exit_safe_mode (adev,0 ); -if (r) -return r; -amdgpu_fence_driver_force_completion (ring); -return 0 ; + +return r; }static int sdma_v5_0_ring_preempt_ib (struct amdgpu_ring *ring)drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c +2
-5@@ -1534,10 +1534,8 @@ static int sdma_v5_2_restore_queue(struct amdgpu_ring *ring) r =sdma_v5_2_gfx_resume_instance (adev, inst_id, true);amdgpu_gfx_rlc_exit_safe_mode (adev,0 ); -if (r) -return r; -amdgpu_fence_driver_force_completion (ring); -return 0 ; + +return r; }static int sdma_v5_2_ring_preempt_ib (struct amdgpu_ring *ring) --Quoted 2 lines
2.50.0
--
Rodrigo Siqueira
Alex Deucher
maintainerPATCH v13 2/28 drm/amdgpu/sdma: allow caller to handle kernel rings in engine reset
In reply to Alex DeucherAdd a parameter to amdgpu_sdma_reset_engine() to let the caller handle the kernel rings. This allows the kernel rings to back up their unprocessed state if the reset comes in via the drm scheduler rather than KFD.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c | 44 +++++++++++-------- drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h | 3 +- drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c | 2 +- drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c | 2 +- drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c | 2 +- .../drm/amd/amdkfd/kfd_device_queue_manager.c | 2 +- 6 files changed, 32 insertions(+), 23 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +26 -18
@@ -528,10 +528,13 @@ static int amdgpu_sdma_soft_reset(struct amdgpu_device *adev, u32 instance_id)* amdgpu_sdma_reset_engine - Reset a specific SDMA engine * @adev: Pointer to the AMDGPU device * @instance_id: Logical ID of the SDMA engine instance to reset +* @caller_handles_kernel_queues: Skip kernel queue processing. Caller +* will handle it. * * Returns: 0 on success, or a negative error code on failure. */ -int amdgpu_sdma_reset_engine (struct amdgpu_device *adev,uint32_t instance_id) +int amdgpu_sdma_reset_engine (struct amdgpu_device *adev,uint32_t instance_id, +bool caller_handles_kernel_queues) {int ret =0 ;struct amdgpu_sdma_instance *sdma_instance = &adev->sdma.instance[instance_id];
@@ -539,14 +542,17 @@ int amdgpu_sdma_reset_engine(struct amdgpu_device *adev, uint32_t instance_id)struct amdgpu_ring *page_ring = &sdma_instance->page;mutex_lock (&sdma_instance->engine_reset_mutex); -/* Stop the scheduler's work queue for the GFX and page rings if they are running. -* This ensures that no new tasks are submitted to the queues while -* the reset is in progress. -*/ -drm_sched_wqueue_stop (&gfx_ring->sched); -if (adev->sdma.has_page_queue) -drm_sched_wqueue_stop (&page_ring->sched); +if (!caller_handles_kernel_queues) { +/* Stop the scheduler's work queue for the GFX and page rings if they are running. +* This ensures that no new tasks are submitted to the queues while +* the reset is in progress. +*/ +drm_sched_wqueue_stop (&gfx_ring->sched); + +if (adev->sdma.has_page_queue) +drm_sched_wqueue_stop (&page_ring->sched); + }if (sdma_instance->funcs->stop_kernel_queue) { sdma_instance->funcs->stop_kernel_queue (gfx_ring);
@@ -568,16 +574,18 @@ int amdgpu_sdma_reset_engine(struct amdgpu_device *adev, uint32_t instance_id) } exit: -/* Restart the scheduler's work queue for the GFX and page rings -* if they were stopped by this function. This allows new tasks -* to be submitted to the queues after the reset is complete. -*/ -if (!ret) { -amdgpu_fence_driver_force_completion (gfx_ring); -drm_sched_wqueue_start (&gfx_ring->sched); -if (adev->sdma.has_page_queue) { -amdgpu_fence_driver_force_completion (page_ring); -drm_sched_wqueue_start (&page_ring->sched); +if (!caller_handles_kernel_queues) { +/* Restart the scheduler's work queue for the GFX and page rings +* if they were stopped by this function. This allows new tasks +* to be submitted to the queues after the reset is complete. +*/ +if (!ret) { +amdgpu_fence_driver_force_completion (gfx_ring); +drm_sched_wqueue_start (&gfx_ring->sched); +if (adev->sdma.has_page_queue) { +amdgpu_fence_driver_force_completion (page_ring); +drm_sched_wqueue_start (&page_ring->sched); + } } }mutex_unlock (&sdma_instance->engine_reset_mutex);
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h +2 -1
@@ -172,7 +172,8 @@ struct amdgpu_buffer_funcs { uint32_t byte_count); }; -int amdgpu_sdma_reset_engine (struct amdgpu_device *adev,uint32_t instance_id); +int amdgpu_sdma_reset_engine (struct amdgpu_device *adev,uint32_t instance_id, +bool caller_handles_kernel_queues);#define amdgpu_emit_copy_buffer (adev, ib, s, d, b, t) (adev)->mman.buffer_funcs->emit_copy_buffer((ib), (s), (d), (b), (t))#define amdgpu_emit_fill_buffer (adev, ib, s, d, b) (adev)->mman.buffer_funcs->emit_fill_buffer((ib), (s), (d), (b))
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +1 -1
@@ -1668,7 +1668,7 @@ static int sdma_v4_4_2_reset_queue(struct amdgpu_ring *ring,return -EOPNOTSUPP ;amdgpu_amdkfd_suspend (adev, true); - r =amdgpu_sdma_reset_engine (adev, id); + r =amdgpu_sdma_reset_engine (adev, id, false);amdgpu_amdkfd_resume (adev, true);return r; }
drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c +1 -1
@@ -1548,7 +1548,7 @@ static int sdma_v5_0_reset_queue(struct amdgpu_ring *ring,int r;amdgpu_amdkfd_suspend (adev, true); - r =amdgpu_sdma_reset_engine (adev, inst_id); + r =amdgpu_sdma_reset_engine (adev, inst_id, false);amdgpu_amdkfd_resume (adev, true);return r;
drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c +1 -1
@@ -1461,7 +1461,7 @@ static int sdma_v5_2_reset_queue(struct amdgpu_ring *ring,int r;amdgpu_amdkfd_suspend (adev, true); - r =amdgpu_sdma_reset_engine (adev, inst_id); + r =amdgpu_sdma_reset_engine (adev, inst_id, false);amdgpu_amdkfd_resume (adev, true);return r;
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +1 -1
@@ -2312,7 +2312,7 @@ static int reset_hung_queues_sdma(struct device_queue_manager *dqm)continue ;/* Reset engine and check. */ -if (amdgpu_sdma_reset_engine (dqm->dev->adev, i) || +if (amdgpu_sdma_reset_engine (dqm->dev->adev, i, false) || dqm->dev->kfd2kgd->hqd_sdma_get_doorbell (dqm->dev->adev, i, j) || !set_sdma_queue_as_reset (dqm, doorbell_off)) { r = -ENOTRECOVERABLE ;
Signature · 1 line
2.50.0
RE: [PATCH 02/28] drm/amdgpu/sdma: allow caller to handle kernel rings in engine reset
[AMD Official Use Only - AMD Internal Distribution Only]
this patch is Reviewed-by: Jesse Zhang <[email protected]>
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Alex Deucher
Sent: Wednesday, July 2, 2025 2:44 AM
To: [email protected]; Koenig, Christian <[email protected]>; Sundararaju, Sathishkumar <[email protected]>
Cc: Deucher, Alexander <[email protected]>
Subject: [PATCH 02/28] drm/amdgpu/sdma: allow caller to handle kernel rings in engine reset
Add a parameter to amdgpu_sdma_reset_engine() to let the caller handle the kernel rings. This allows the kernel rings to back up their unprocessed state if the reset comes in via the drm scheduler rather than KFD.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c | 44 +++++++++++-------- drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h | 3 +- drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c | 2 +- drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c | 2 +- drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c | 2 +- .../drm/amd/amdkfd/kfd_device_queue_manager.c | 2 +- 6 files changed, 32 insertions(+), 23 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +26 -18
@@ -528,10 +528,13 @@ static int amdgpu_sdma_soft_reset(struct amdgpu_device *adev, u32 instance_id)* amdgpu_sdma_reset_engine - Reset a specific SDMA engine * @adev: Pointer to the AMDGPU device * @instance_id: Logical ID of the SDMA engine instance to reset +* @caller_handles_kernel_queues: Skip kernel queue processing. Caller +* will handle it. * * Returns: 0 on success, or a negative error code on failure. */ -int amdgpu_sdma_reset_engine (struct amdgpu_device *adev,uint32_t instance_id) +int amdgpu_sdma_reset_engine (struct amdgpu_device *adev,uint32_t instance_id, +bool caller_handles_kernel_queues) {int ret =0 ;struct amdgpu_sdma_instance *sdma_instance = &adev->sdma.instance[instance_id];
@@ -539,14 +542,17 @@ int amdgpu_sdma_reset_engine(struct amdgpu_device *adev, uint32_t instance_id)struct amdgpu_ring *page_ring = &sdma_instance->page;mutex_lock (&sdma_instance->engine_reset_mutex); -/* Stop the scheduler's work queue for the GFX and page rings if they are running. -* This ensures that no new tasks are submitted to the queues while -* the reset is in progress. -*/ -drm_sched_wqueue_stop (&gfx_ring->sched); -if (adev->sdma.has_page_queue) -drm_sched_wqueue_stop (&page_ring->sched); +if (!caller_handles_kernel_queues) { +/* Stop the scheduler's work queue for the GFX and page rings if they are running. +* This ensures that no new tasks are submitted to the queues while +* the reset is in progress. +*/ +drm_sched_wqueue_stop (&gfx_ring->sched); + +if (adev->sdma.has_page_queue) +drm_sched_wqueue_stop (&page_ring->sched); + }if (sdma_instance->funcs->stop_kernel_queue) { sdma_instance->funcs->stop_kernel_queue (gfx_ring);
@@ -568,16 +574,18 @@ int amdgpu_sdma_reset_engine(struct amdgpu_device *adev, uint32_t instance_id) } exit: -/* Restart the scheduler's work queue for the GFX and page rings -* if they were stopped by this function. This allows new tasks -* to be submitted to the queues after the reset is complete. -*/ -if (!ret) { -amdgpu_fence_driver_force_completion (gfx_ring); -drm_sched_wqueue_start (&gfx_ring->sched); -if (adev->sdma.has_page_queue) { -amdgpu_fence_driver_force_completion (page_ring); -drm_sched_wqueue_start (&page_ring->sched); +if (!caller_handles_kernel_queues) { +/* Restart the scheduler's work queue for the GFX and page rings +* if they were stopped by this function. This allows new tasks +* to be submitted to the queues after the reset is complete. +*/ +if (!ret) { +amdgpu_fence_driver_force_completion (gfx_ring); +drm_sched_wqueue_start (&gfx_ring->sched); +if (adev->sdma.has_page_queue) { +amdgpu_fence_driver_force_completion (page_ring); +drm_sched_wqueue_start (&page_ring->sched); + } } }mutex_unlock (&sdma_instance->engine_reset_mutex);
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h +2 -1
@@ -172,7 +172,8 @@ struct amdgpu_buffer_funcs { uint32_t byte_count); }; -int amdgpu_sdma_reset_engine (struct amdgpu_device *adev,uint32_t instance_id); +int amdgpu_sdma_reset_engine (struct amdgpu_device *adev,uint32_t instance_id, +bool caller_handles_kernel_queues);#define amdgpu_emit_copy_buffer (adev, ib, s, d, b, t) (adev)->mman.buffer_funcs->emit_copy_buffer((ib), (s), (d), (b), (t)) #define amdgpu_emit_fill_buffer(adev, ib, s, d, b) (adev)->mman.buffer_funcs->emit_fill_buffer((ib), (s), (d), (b)) diff --git a/drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c b/drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c
index 572d105420ec3..c0c418aa2c299 100644
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +1 -1
@@ -1668,7 +1668,7 @@ static int sdma_v4_4_2_reset_queue(struct amdgpu_ring *ring,return -EOPNOTSUPP ;amdgpu_amdkfd_suspend (adev, true); - r =amdgpu_sdma_reset_engine (adev, id); + r =amdgpu_sdma_reset_engine (adev, id, false);amdgpu_amdkfd_resume (adev, true);return r; }
drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c +1 -1
@@ -1548,7 +1548,7 @@ static int sdma_v5_0_reset_queue(struct amdgpu_ring *ring,int r;amdgpu_amdkfd_suspend (adev, true); - r =amdgpu_sdma_reset_engine (adev, inst_id); + r =amdgpu_sdma_reset_engine (adev, inst_id, false);amdgpu_amdkfd_resume (adev, true);return r;
drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c +1 -1
@@ -1461,7 +1461,7 @@ static int sdma_v5_2_reset_queue(struct amdgpu_ring *ring,int r;amdgpu_amdkfd_suspend (adev, true); - r =amdgpu_sdma_reset_engine (adev, inst_id); + r =amdgpu_sdma_reset_engine (adev, inst_id, false);amdgpu_amdkfd_resume (adev, true);return r;
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +1 -1
@@ -2312,7 +2312,7 @@ static int reset_hung_queues_sdma(struct device_queue_manager *dqm)continue ;/* Reset engine and check. */ -if (amdgpu_sdma_reset_engine (dqm->dev->adev, i) || +if (amdgpu_sdma_reset_engine (dqm->dev->adev, i, false) || dqm->dev->kfd2kgd->hqd_sdma_get_doorbell (dqm->dev->adev, i, j) || !set_sdma_queue_as_reset (dqm, doorbell_off)) { r = -ENOTRECOVERABLE ;
--
2.50.0
Alex Deucher
maintainerPATCH v13 3/28 drm/amdgpu: track ring state associated with a fence
In reply to Alex DeucherWe need to know the wptr and sequence number associated with a fence so that we can re-emit the unprocessed state after a ring reset. Pre-allocate storage space for the ring buffer contents and add helpers to save off and re-emit the unprocessed state so that it can be re-emitted after the queue is reset.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c | 90 +++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c | 15 +++- drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 4 +- drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c | 67 +++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h | 18 +++++ drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 4 + 6 files changed, 195 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +90 -0
@@ -120,6 +120,7 @@ int amdgpu_fence_emit(struct amdgpu_ring *ring, struct dma_fence **f, am_fence =kzalloc (sizeof (*am_fence),GFP_KERNEL );if (!am_fence)return -ENOMEM ; + am_fence->context =0 ; }else { am_fence = af; }
@@ -127,6 +128,7 @@ int amdgpu_fence_emit(struct amdgpu_ring *ring, struct dma_fence **f, am_fence->ring = ring; seq = ++ring->fence_drv.sync_seq; + am_fence->seq = seq;if (af) { dma_fence_init(fence, &amdgpu_job_fence_ops, &ring->fence_drv.lock,
@@ -141,6 +143,7 @@ int amdgpu_fence_emit(struct amdgpu_ring *ring, struct dma_fence **f,amdgpu_ring_emit_fence (ring, ring->fence_drv.gpu_addr, seq, flags |AMDGPU_FENCE_FLAG_INT ); +amdgpu_fence_save_wptr (fence);pm_runtime_get_noresume (adev_to_drm (adev)->dev); ptr = &ring->fence_drv.fences[seq & ring->fence_drv.num_fences_mask];if (unlikely (rcu_dereference_protected (*ptr,1 ))) {
@@ -253,6 +256,7 @@ bool amdgpu_fence_process(struct amdgpu_ring *ring) do { struct dma_fence *fence, **ptr; + struct amdgpu_fence *am_fence; ++last_seq; last_seq &= drv->num_fences_mask;
@@ -265,6 +269,12 @@ bool amdgpu_fence_process(struct amdgpu_ring *ring)if (!fence)continue ; +/* Save the wptr in the fence driver so we know what the last processed +* wptr was. This is required for re-emitting the ring state for +* queues that are reset but are not guilty and thus have no guilty fence. +*/ + am_fence = container_of(fence, struct amdgpu_fence, base); + drv->signalled_wptr = am_fence->wptr;dma_fence_signal (fence);dma_fence_put (fence);pm_runtime_mark_last_busy (adev_to_drm (adev)->dev);
@@ -727,6 +737,86 @@ void amdgpu_fence_driver_force_completion(struct amdgpu_ring *ring)amdgpu_fence_process (ring); } + +/** +* Kernel queue reset handling +* +* The driver can reset individual queues for most engines, but those queues +* may contain work from multiple contexts. Resetting the queue will reset +* lose all of that state. In order to minimize the collateral damage, the +* driver will save the ring contents which are not associated with the guilty +* context prior to resetting the queue. After resetting the queue the queue +* contents from the other contexts is re-emitted to the rings so that it can +* be processed by the engine. To handle this, we save the queue's write +* pointer (wptr) in the fences associated with each context. If we get a +* queue timeout, we can then use the wptrs from the fences to determine +* which data needs to be saved out of the queue's ring buffer. +*/ + +/** +* amdgpu_fence_driver_guilty_force_completion - force signal of specified sequence +* +* @fence: fence of the ring to signal +* +*/ +void amdgpu_fence_driver_guilty_force_completion (struct amdgpu_fence *fence) +{ +dma_fence_set_error (&fence->base, -ETIME ); +amdgpu_fence_write (fence->ring, fence->seq); +amdgpu_fence_process (fence->ring); +} + +void amdgpu_fence_save_wptr (struct dma_fence *fence) +{ + struct amdgpu_fence *am_fence = container_of(fence, struct amdgpu_fence, base); + + am_fence->wptr = am_fence->ring->wptr; +} + +static void amdgpu_ring_backup_unprocessed_command (struct amdgpu_ring *ring, +u64 start_wptr,u32 end_wptr) +{ +unsigned int first_idx = start_wptr & ring->buf_mask; +unsigned int last_idx = end_wptr & ring->buf_mask; +unsigned int i; + +/* Backup the contents of the ring buffer. */ +for (i = first_idx; i != last_idx; ++i, i &= ring->buf_mask) + ring->ring_backup[ring->ring_backup_entries_to_copy++] = ring->ring[i]; +} + +void amdgpu_ring_backup_unprocessed_commands (struct amdgpu_ring *ring, +struct amdgpu_fence *guilty_fence) +{ +struct dma_fence *unprocessed; +struct dma_fence __rcu **ptr; +struct amdgpu_fence *fence; +u64 wptr, i, seqno; + + seqno =amdgpu_fence_read (ring); + wptr = ring->fence_drv.signalled_wptr; + ring->ring_backup_entries_to_copy =0 ; + +for (i = seqno +1 ; i <= ring->fence_drv.sync_seq; ++i) { + ptr = &ring->fence_drv.fences[i & ring->fence_drv.num_fences_mask]; +rcu_read_lock (); + unprocessed =rcu_dereference (*ptr); + +if (unprocessed && !dma_fence_is_signaled (unprocessed)) { + fence = container_of(unprocessed, struct amdgpu_fence, base); + +/* save everything if the ring is not guilty, otherwise +* just save the content from other contexts. +*/ +if (!guilty_fence || (fence->context != guilty_fence->context)) +amdgpu_ring_backup_unprocessed_command (ring, wptr, + fence->wptr); + wptr = fence->wptr; + } +rcu_read_unlock (); + } +} +/* * Common fence implementation */
drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c +14 -1
@@ -139,7 +139,6 @@ int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned int num_ibs,int vmid =AMDGPU_JOB_GET_VMID (job);bool need_pipe_sync = false;unsigned int cond_exec; -unsigned int i;int r =0 ;
@@ -156,6 +155,11 @@ int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned int num_ibs, gds_va = job->gds_va; init_shadow = job->init_shadow; af = &job->hw_fence; +/* Save the context of the job for reset handling. +* The driver needs this so it can skip the ring +* contents for guilty contexts. +*/ + af->context = job->base.s_fence ? job->base.s_fence->finished.context :0 ; }else { vm =NULL ; fence_ctx =0 ;
@@ -307,8 +311,17 @@ int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned int num_ibs, ring->hw_prio == AMDGPU_GFX_PIPE_PRIO_HIGH) ring->funcs->emit_wave_limit(ring, false); +/* Save the wptr associated with this fence. +* This must be last for resets to work properly +* as we need to save the wptr associated with this +* fence so we know what rings contents to backup +* after we reset the queue. +*/ +amdgpu_fence_save_wptr (*f); +amdgpu_ring_ib_end (ring);amdgpu_ring_commit (ring); +return 0 ; }
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +2 -2
@@ -89,8 +89,8 @@ static enum drm_gpu_sched_stat amdgpu_job_timedout(struct drm_sched_job *s_job) {struct amdgpu_ring *ring =to_amdgpu_ring (s_job->sched);struct amdgpu_job *job =to_amdgpu_job (s_job); -struct amdgpu_task_info *ti;struct amdgpu_device *adev = ring->adev; +struct amdgpu_task_info *ti;int idx, r;if (!drm_dev_enter (adev_to_drm (adev), &idx)) {
@@ -135,7 +135,7 @@ static enum drm_gpu_sched_stat amdgpu_job_timedout(struct drm_sched_job *s_job) }else if (amdgpu_gpu_recovery && ring->funcs->reset) {dev_err (adev->dev,"Starting %s ring reset\n" , s_job->sched->name); - r =amdgpu_ring_reset (ring, job->vmid,NULL ); + r =amdgpu_ring_reset (ring, job->vmid, &job->hw_fence);if (!r) {atomic_inc (&ring->adev->gpu_reset_counter); dev_err(adev->dev, "Ring %s reset succeeded\n",
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +67 -0
94 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h +18 -0
@@ -118,6 +118,7 @@ struct amdgpu_fence_driver {/* sync_seq is protected by ring emission lock */ uint32_t sync_seq;atomic_t last_seq; +u64 signalled_wptr;bool initialized;struct amdgpu_irq_src *irq_src;unsigned irq_type;
@@ -141,6 +142,12 @@ struct amdgpu_fence {/* RB, DMA, etc. */ struct amdgpu_ring *ring;ktime_t start_timestamp; + +/* wptr for the fence for resets */ +u64 wptr; +/* fence context for resets */ +u64 context; +uint32_t seq; };extern const struct drm_sched_backend_ops amdgpu_sched_ops;
@@ -148,6 +155,8 @@ extern const struct drm_sched_backend_ops amdgpu_sched_ops;void amdgpu_fence_driver_clear_job_fences (struct amdgpu_ring *ring);void amdgpu_fence_driver_set_error (struct amdgpu_ring *ring,int error);void amdgpu_fence_driver_force_completion (struct amdgpu_ring *ring); +void amdgpu_fence_driver_guilty_force_completion (struct amdgpu_fence *fence); +void amdgpu_fence_save_wptr (struct dma_fence *fence);int amdgpu_fence_driver_init_ring (struct amdgpu_ring *ring); int amdgpu_fence_driver_start_ring(struct amdgpu_ring *ring,
@@ -284,6 +293,9 @@ struct amdgpu_ring {struct amdgpu_bo *ring_obj;uint32_t *ring; +/* backups for resets */ +uint32_t *ring_backup; +unsigned int ring_backup_entries_to_copy;unsigned rptr_offs;u64 rptr_gpu_addr;volatile u32 *rptr_cpu_addr;
@@ -550,4 +562,10 @@ int amdgpu_ib_pool_init(struct amdgpu_device *adev);void amdgpu_ib_pool_fini (struct amdgpu_device *adev);int amdgpu_ib_ring_tests (struct amdgpu_device *adev);bool amdgpu_ring_sched_ready (struct amdgpu_ring *ring); +void amdgpu_ring_backup_unprocessed_commands (struct amdgpu_ring *ring, +struct amdgpu_fence *guilty_fence); +void amdgpu_ring_reset_helper_begin (struct amdgpu_ring *ring, +struct amdgpu_fence *guilty_fence); +int amdgpu_ring_reset_helper_end (struct amdgpu_ring *ring, +struct amdgpu_fence *guilty_fence);#endif
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +4 -0
@@ -765,6 +765,7 @@ int amdgpu_vm_flush(struct amdgpu_ring *ring, struct amdgpu_job *job,bool cleaner_shader_needed = false;bool pasid_mapping_needed = false;struct dma_fence *fence =NULL ; +struct amdgpu_fence *af;unsigned int patch;int r;
@@ -830,6 +831,9 @@ int amdgpu_vm_flush(struct amdgpu_ring *ring, struct amdgpu_job *job, r =amdgpu_fence_emit (ring, &fence,NULL ,0 );if (r)return r; +/* this is part of the job's context */ + af = container_of(fence, struct amdgpu_fence, base); + af->context = job->base.s_fence ? job->base.s_fence->finished.context :0 ; }if (vm_flush_needed) {
Signature · 1 line
2.50.0
Re: [PATCH 03/28] drm/amdgpu: track ring state associated with a fence
Quoted 98 lines · Alex Deucher
We need to know the wptr and sequence number associated with a fence so that we can re-emit the unprocessed state after a ring reset. Pre-allocate storage space for the ring buffer contents and add helpers to save off and re-emit the unprocessed state so that it can be re-emitted after the queue is reset.
Signed-off-by Alex Deucher <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c | 90 +++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c | 15 +++- drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 4 +- drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c | 67 +++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h | 18 +++++ drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 4 + 6 files changed, 195 insertions(+), 3 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +38
-0@@ -120,6 +120,7 @@ int amdgpu_fence_emit(struct amdgpu_ring *ring, struct dma_fence **f, am_fence =kzalloc (sizeof (*am_fence),GFP_KERNEL );if (!am_fence)return -ENOMEM ; + am_fence->context =0 ; }else { am_fence = af; }@@ -127,6 +128,7 @@ int amdgpu_fence_emit(struct amdgpu_ring *ring, struct dma_fence **f, am_fence->ring = ring; seq = ++ring->fence_drv.sync_seq; + am_fence->seq = seq;if (af) { dma_fence_init(fence, &amdgpu_job_fence_ops, &ring->fence_drv.lock,@@ -141,6 +143,7 @@ int amdgpu_fence_emit(struct amdgpu_ring *ring, struct dma_fence **f,amdgpu_ring_emit_fence (ring, ring->fence_drv.gpu_addr, seq, flags |AMDGPU_FENCE_FLAG_INT ); +amdgpu_fence_save_wptr (fence);pm_runtime_get_noresume (adev_to_drm (adev)->dev); ptr = &ring->fence_drv.fences[seq & ring->fence_drv.num_fences_mask];if (unlikely (rcu_dereference_protected (*ptr,1 ))) {@@ -253,6 +256,7 @@ bool amdgpu_fence_process(struct amdgpu_ring *ring) do { struct dma_fence *fence, **ptr; + struct amdgpu_fence *am_fence; ++last_seq; last_seq &= drv->num_fences_mask;@@ -265,6 +269,12 @@ bool amdgpu_fence_process(struct amdgpu_ring *ring)if (!fence)continue ; +/* Save the wptr in the fence driver so we know what the last processed +* wptr was. This is required for re-emitting the ring state for +* queues that are reset but are not guilty and thus have no guilty fence. +*/ + am_fence = container_of(fence, struct amdgpu_fence, base); + drv->signalled_wptr = am_fence->wptr;dma_fence_signal (fence);dma_fence_put (fence);pm_runtime_mark_last_busy (adev_to_drm (adev)->dev);@@ -727,6 +737,86 @@ void amdgpu_fence_driver_force_completion(struct amdgpu_ring *ring)amdgpu_fence_process (ring); } + +/** +* Kernel queue reset handling +* +* The driver can reset individual queues for most engines, but those queues +* may contain work from multiple contexts. Resetting the queue will reset +* lose all of that state. In order to minimize the collateral damage, the +* driver will save the ring contents which are not associated with the guilty +* context prior to resetting the queue. After resetting the queue the queue +* contents from the other contexts is re-emitted to the rings so that it can +* be processed by the engine. To handle this, we save the queue's write +* pointer (wptr) in the fences associated with each context. If we get a +* queue timeout, we can then use the wptrs from the fences to determine +* which data needs to be saved out of the queue's ring buffer. +*/ + +/** +* amdgpu_fence_driver_guilty_force_completion - force signal of specified sequence +* +* @fence: fence of the ring to signal +* +*/ +void amdgpu_fence_driver_guilty_force_completion (struct amdgpu_fence *fence) +{ +dma_fence_set_error (&fence->base, -ETIME ); +amdgpu_fence_write (fence->ring, fence->seq); +amdgpu_fence_process (fence->ring); +}
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c void amdgpu_fence_driver_force_completion(struct amdgpu_ring *ring) · line 777
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +10
-0+ +void amdgpu_fence_save_wptr (struct dma_fence *fence) +{ + struct amdgpu_fence *am_fence = container_of(fence, struct amdgpu_fence, base); + + am_fence->wptr = am_fence->ring->wptr; +} + +static void amdgpu_ring_backup_unprocessed_command (struct amdgpu_ring *ring, +u64 start_wptr,u32 end_wptr)
Perhaps you could call this function something like amdgpu_ring_backup() or a similar name? I suggest this change because you also have the same function name for the exported function.
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c void amdgpu_fence_driver_force_completion(struct amdgpu_ring *ring) · line 785
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +8
-0+{ +unsigned int first_idx = start_wptr & ring->buf_mask; +unsigned int last_idx = end_wptr & ring->buf_mask; +unsigned int i; + +/* Backup the contents of the ring buffer. */ +for (i = first_idx; i != last_idx; ++i, i &= ring->buf_mask) + ring->ring_backup[ring->ring_backup_entries_to_copy++] = ring->ring[i];
After the backup is done, don't you need to setring_backup_entries_to_copy to 0?
Quoted 16 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +16
-0+} + +void amdgpu_ring_backup_unprocessed_commands (struct amdgpu_ring *ring, +struct amdgpu_fence *guilty_fence) +{ +struct dma_fence *unprocessed; +struct dma_fence __rcu **ptr; +struct amdgpu_fence *fence; +u64 wptr, i, seqno; + + seqno =amdgpu_fence_read (ring); + wptr = ring->fence_drv.signalled_wptr; + ring->ring_backup_entries_to_copy =0 ; + +for (i = seqno +1 ; i <= ring->fence_drv.sync_seq; ++i) { + ptr = &ring->fence_drv.fences[i & ring->fence_drv.num_fences_mask];
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c void amdgpu_fence_driver_force_completion(struct amdgpu_ring *ring) · line 811
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +10
-0+rcu_read_lock (); + unprocessed =rcu_dereference (*ptr); + +if (unprocessed && !dma_fence_is_signaled (unprocessed)) { + fence = container_of(unprocessed, struct amdgpu_fence, base); + +/* save everything if the ring is not guilty, otherwise +* just save the content from other contexts. +*/ +if (!guilty_fence || (fence->context != guilty_fence->context))
Why do you need these two checks? Why is guilty_fence not enough here?
Quoted 192 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +8
-0+amdgpu_ring_backup_unprocessed_command (ring, wptr, + fence->wptr); + wptr = fence->wptr; + } +rcu_read_unlock (); + } +} +/* * Common fence implementation */ drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c +14
-1@@ -139,7 +139,6 @@ int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned int num_ibs,int vmid =AMDGPU_JOB_GET_VMID (job);bool need_pipe_sync = false;unsigned int cond_exec; -unsigned int i;int r =0 ;@@ -156,6 +155,11 @@ int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned int num_ibs, gds_va = job->gds_va; init_shadow = job->init_shadow; af = &job->hw_fence; +/* Save the context of the job for reset handling. +* The driver needs this so it can skip the ring +* contents for guilty contexts. +*/ + af->context = job->base.s_fence ? job->base.s_fence->finished.context :0 ; }else { vm =NULL ; fence_ctx =0 ;@@ -307,8 +311,17 @@ int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned int num_ibs, ring->hw_prio == AMDGPU_GFX_PIPE_PRIO_HIGH) ring->funcs->emit_wave_limit(ring, false); +/* Save the wptr associated with this fence. +* This must be last for resets to work properly +* as we need to save the wptr associated with this +* fence so we know what rings contents to backup +* after we reset the queue. +*/ +amdgpu_fence_save_wptr (*f); +amdgpu_ring_ib_end (ring);amdgpu_ring_commit (ring); +return 0 ; }drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +2
-2@@ -89,8 +89,8 @@ static enum drm_gpu_sched_stat amdgpu_job_timedout(struct drm_sched_job *s_job) {struct amdgpu_ring *ring =to_amdgpu_ring (s_job->sched);struct amdgpu_job *job =to_amdgpu_job (s_job); -struct amdgpu_task_info *ti;struct amdgpu_device *adev = ring->adev; +struct amdgpu_task_info *ti;int idx, r;if (!drm_dev_enter (adev_to_drm (adev), &idx)) {@@ -135,7 +135,7 @@ static enum drm_gpu_sched_stat amdgpu_job_timedout(struct drm_sched_job *s_job) }else if (amdgpu_gpu_recovery && ring->funcs->reset) {dev_err (adev->dev,"Starting %s ring reset\n" , s_job->sched->name); - r =amdgpu_ring_reset (ring, job->vmid,NULL ); + r =amdgpu_ring_reset (ring, job->vmid, &job->hw_fence);if (!r) {atomic_inc (&ring->adev->gpu_reset_counter); dev_err(adev->dev, "Ring %s reset succeeded\n",drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +67
-0@@ -99,6 +99,29 @@ int amdgpu_ring_alloc(struct amdgpu_ring *ring, unsigned int ndw)return 0 ; } +/** +* amdgpu_ring_alloc_reemit - allocate space on the ring buffer for reemit +* +* @ring: amdgpu_ring structure holding ring information +* @ndw: number of dwords to allocate in the ring buffer +* +* Allocate @ndw dwords in the ring buffer (all asics). +* doesn't check the max_dw limit as we may be reemitting +* several submissions. +*/ +static void amdgpu_ring_alloc_reemit (struct amdgpu_ring *ring,unsigned int ndw) +{ +/* Align requested size with padding so unlock_commit can +* pad safely */ + ndw = (ndw + ring->funcs->align_mask) & ~ring->funcs->align_mask; + + ring->count_dw = ndw; + ring->wptr_old = ring->wptr; + +if (ring->funcs->begin_use) + ring->funcs->begin_use (ring); +} +/** amdgpu_ring_insert_nop - insert NOP packets * * @ring: amdgpu_ring structure holding ring information @@ -333,6 +356,12 @@ int amdgpu_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring,/* Initialize cached_rptr to 0 */ ring->cached_rptr =0 ; +if (!ring->ring_backup) { + ring->ring_backup =kvzalloc (ring->ring_size,GFP_KERNEL ); +if (!ring->ring_backup) +return -ENOMEM ; + } +/* Allocate ring buffer */ if (ring->ring_obj ==NULL ) { r = amdgpu_bo_create_kernel(adev, ring->ring_size + ring->funcs->extra_dw, PAGE_SIZE,@@ -342,6 +371,7 @@ int amdgpu_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring, (void **)&ring->ring);if (r) {dev_err (adev->dev,"(%d) ring create failed\n" , r); +kvfree (ring->ring_backup);return r; }amdgpu_ring_clear_ring (ring);@@ -385,6 +415,8 @@ void amdgpu_ring_fini(struct amdgpu_ring *ring)amdgpu_bo_free_kernel (&ring->ring_obj, &ring->gpu_addr, (void **)&ring->ring); +kvfree (ring->ring_backup); + ring->ring_backup =NULL ;dma_fence_put (ring->vmid_wait); ring->vmid_wait =NULL ;@@ -753,3 +785,38 @@ bool amdgpu_ring_sched_ready(struct amdgpu_ring *ring)return true; } + +void amdgpu_ring_reset_helper_begin (struct amdgpu_ring *ring, +struct amdgpu_fence *guilty_fence) +{ +/* Stop the scheduler to prevent anybody else from touching the ring buffer. */ +drm_sched_wqueue_stop (&ring->sched); +/* back up the non-guilty commands */ +amdgpu_ring_backup_unprocessed_commands (ring, guilty_fence); +} + +int amdgpu_ring_reset_helper_end (struct amdgpu_ring *ring, +struct amdgpu_fence *guilty_fence) +{ +unsigned int i; +int r; + +/* verify that the ring is functional */ + r =amdgpu_ring_test_ring (ring); +if (r) +return r; + +/* signal the fence of the bad job */ +if (guilty_fence) +amdgpu_fence_driver_guilty_force_completion (guilty_fence); +/* Re-emit the non-guilty commands */ +if (ring->ring_backup_entries_to_copy) { +amdgpu_ring_alloc_reemit (ring, ring->ring_backup_entries_to_copy); +for (i =0 ; i < ring->ring_backup_entries_to_copy; i++) +amdgpu_ring_write (ring, ring->ring_backup[i]); +amdgpu_ring_commit (ring); + } +/* Start the scheduler again */ +drm_sched_wqueue_start (&ring->sched); +return 0 ; +}drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h +1
-0@@ -118,6 +118,7 @@ struct amdgpu_fence_driver {/* sync_seq is protected by ring emission lock */ uint32_t sync_seq;atomic_t last_seq; +u64 signalled_wptr;bool initialized;struct amdgpu_irq_src *irq_src;unsigned irq_type;
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h struct amdgpu_fence { · line 150
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h +6
-0@@ -141,6 +142,12 @@ struct amdgpu_fence {/* RB, DMA, etc. */ struct amdgpu_ring *ring;ktime_t start_timestamp; + +/* wptr for the fence for resets */ +u64 wptr; +/* fence context for resets */ +u64 context; +uint32_t seq;
All of these new fields are associated with reset, and their names are also common in the code (we see wptr, context, and seq everywhere). What do you think of adding a suffix/prefix to identify their purpose in the code clearly? For example, wptr_reset instead of wptr or context_reset instead of context. It does not need to be _reset, but something that helps to identify these field purpose in the code.
Thanks
Quoted 58 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h +11
-0};extern const struct drm_sched_backend_ops amdgpu_sched_ops;@@ -148,6 +155,8 @@ extern const struct drm_sched_backend_ops amdgpu_sched_ops;void amdgpu_fence_driver_clear_job_fences (struct amdgpu_ring *ring);void amdgpu_fence_driver_set_error (struct amdgpu_ring *ring,int error);void amdgpu_fence_driver_force_completion (struct amdgpu_ring *ring); +void amdgpu_fence_driver_guilty_force_completion (struct amdgpu_fence *fence); +void amdgpu_fence_save_wptr (struct dma_fence *fence);int amdgpu_fence_driver_init_ring (struct amdgpu_ring *ring); int amdgpu_fence_driver_start_ring(struct amdgpu_ring *ring,@@ -284,6 +293,9 @@ struct amdgpu_ring {struct amdgpu_bo *ring_obj;uint32_t *ring; +/* backups for resets */ +uint32_t *ring_backup; +unsigned int ring_backup_entries_to_copy;unsigned rptr_offs;u64 rptr_gpu_addr;volatile u32 *rptr_cpu_addr;@@ -550,4 +562,10 @@ int amdgpu_ib_pool_init(struct amdgpu_device *adev);void amdgpu_ib_pool_fini (struct amdgpu_device *adev);int amdgpu_ib_ring_tests (struct amdgpu_device *adev);bool amdgpu_ring_sched_ready (struct amdgpu_ring *ring); +void amdgpu_ring_backup_unprocessed_commands (struct amdgpu_ring *ring, +struct amdgpu_fence *guilty_fence); +void amdgpu_ring_reset_helper_begin (struct amdgpu_ring *ring, +struct amdgpu_fence *guilty_fence); +int amdgpu_ring_reset_helper_end (struct amdgpu_ring *ring, +struct amdgpu_fence *guilty_fence);#endif drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +4
-0@@ -765,6 +765,7 @@ int amdgpu_vm_flush(struct amdgpu_ring *ring, struct amdgpu_job *job,bool cleaner_shader_needed = false;bool pasid_mapping_needed = false;struct dma_fence *fence =NULL ; +struct amdgpu_fence *af;unsigned int patch;int r;@@ -830,6 +831,9 @@ int amdgpu_vm_flush(struct amdgpu_ring *ring, struct amdgpu_job *job, r =amdgpu_fence_emit (ring, &fence,NULL ,0 );if (r)return r; +/* this is part of the job's context */ + af = container_of(fence, struct amdgpu_fence, base); + af->context = job->base.s_fence ? job->base.s_fence->finished.context :0 ; }if (vm_flush_needed) {Signature · 1 line
2.50.0
Signature · 1 line
Rodrigo Siqueira
Re: [PATCH 03/28] drm/amdgpu: track ring state associated with a fence
Quoted 106 lines · Rodrigo Siqueira
Quoted 104 lines · Alex Deucher
We need to know the wptr and sequence number associated with a fence so that we can re-emit the unprocessed state after a ring reset. Pre-allocate storage space for the ring buffer contents and add helpers to save off and re-emit the unprocessed state so that it can be re-emitted after the queue is reset.
Signed-off-by Alex Deucher <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c | 90 +++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c | 15 +++- drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 4 +- drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c | 67 +++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h | 18 +++++ drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 4 + 6 files changed, 195 insertions(+), 3 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +44
-0@@ -120,6 +120,7 @@ int amdgpu_fence_emit(struct amdgpu_ring *ring, struct dma_fence **f, am_fence =kzalloc (sizeof (*am_fence),GFP_KERNEL );if (!am_fence)return -ENOMEM ; + am_fence->context =0 ; }else { am_fence = af; }@@ -127,6 +128,7 @@ int amdgpu_fence_emit(struct amdgpu_ring *ring, struct dma_fence **f, am_fence->ring = ring; seq = ++ring->fence_drv.sync_seq; + am_fence->seq = seq;if (af) { dma_fence_init(fence, &amdgpu_job_fence_ops, &ring->fence_drv.lock,@@ -141,6 +143,7 @@ int amdgpu_fence_emit(struct amdgpu_ring *ring, struct dma_fence **f,amdgpu_ring_emit_fence (ring, ring->fence_drv.gpu_addr, seq, flags |AMDGPU_FENCE_FLAG_INT ); +amdgpu_fence_save_wptr (fence);pm_runtime_get_noresume (adev_to_drm (adev)->dev); ptr = &ring->fence_drv.fences[seq & ring->fence_drv.num_fences_mask];if (unlikely (rcu_dereference_protected (*ptr,1 ))) {@@ -253,6 +256,7 @@ bool amdgpu_fence_process(struct amdgpu_ring *ring) do { struct dma_fence *fence, **ptr; + struct amdgpu_fence *am_fence; ++last_seq; last_seq &= drv->num_fences_mask;@@ -265,6 +269,12 @@ bool amdgpu_fence_process(struct amdgpu_ring *ring)if (!fence)continue ; +/* Save the wptr in the fence driver so we know what the last processed +* wptr was. This is required for re-emitting the ring state for +* queues that are reset but are not guilty and thus have no guilty fence. +*/ + am_fence = container_of(fence, struct amdgpu_fence, base); + drv->signalled_wptr = am_fence->wptr;dma_fence_signal (fence);dma_fence_put (fence);pm_runtime_mark_last_busy (adev_to_drm (adev)->dev);@@ -727,6 +737,86 @@ void amdgpu_fence_driver_force_completion(struct amdgpu_ring *ring)amdgpu_fence_process (ring); } + +/** +* Kernel queue reset handling +* +* The driver can reset individual queues for most engines, but those queues +* may contain work from multiple contexts. Resetting the queue will reset +* lose all of that state. In order to minimize the collateral damage, the +* driver will save the ring contents which are not associated with the guilty +* context prior to resetting the queue. After resetting the queue the queue +* contents from the other contexts is re-emitted to the rings so that it can +* be processed by the engine. To handle this, we save the queue's write +* pointer (wptr) in the fences associated with each context. If we get a +* queue timeout, we can then use the wptrs from the fences to determine +* which data needs to be saved out of the queue's ring buffer. +*/ + +/** +* amdgpu_fence_driver_guilty_force_completion - force signal of specified sequence +* +* @fence: fence of the ring to signal +* +*/ +void amdgpu_fence_driver_guilty_force_completion (struct amdgpu_fence *fence) +{ +dma_fence_set_error (&fence->base, -ETIME ); +amdgpu_fence_write (fence->ring, fence->seq); +amdgpu_fence_process (fence->ring); +} + +void amdgpu_fence_save_wptr (struct dma_fence *fence) +{ + struct amdgpu_fence *am_fence = container_of(fence, struct amdgpu_fence, base); + + am_fence->wptr = am_fence->ring->wptr;
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c void amdgpu_fence_driver_force_completion(struct amdgpu_ring *ring) · line 777
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +4
-0+} + +static void amdgpu_ring_backup_unprocessed_command (struct amdgpu_ring *ring, +u64 start_wptr,u32 end_wptr)Perhaps you could call this function something like
amdgpu_ring_backup()or a similar name? I suggest this change because you also have the same function name for the exported function.
The names are different:amdgpu_ring_backup_unprocessed_command()
vs.amdgpu_ring_backup_unprocessed_commands()
the latter calls the former in a loop to back up all of the necessary commands in the ring.
Quoted 12 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c void amdgpu_fence_driver_force_completion(struct amdgpu_ring *ring) · line 785
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +8
-0+{ +unsigned int first_idx = start_wptr & ring->buf_mask; +unsigned int last_idx = end_wptr & ring->buf_mask; +unsigned int i; + +/* Backup the contents of the ring buffer. */ +for (i = first_idx; i != last_idx; ++i, i &= ring->buf_mask) + ring->ring_backup[ring->ring_backup_entries_to_copy++] = ring->ring[i];After the backup is done, don't you need to set
ring_backup_entries_to_copyto 0?
No. This function is called in a loop so we back up multiple commands from the ring so we need to make sure we keep the index up to date.
Quoted 21 lines
Quoted 21 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +20
-0+} + +void amdgpu_ring_backup_unprocessed_commands (struct amdgpu_ring *ring, +struct amdgpu_fence *guilty_fence) +{ +struct dma_fence *unprocessed; +struct dma_fence __rcu **ptr; +struct amdgpu_fence *fence; +u64 wptr, i, seqno; + + seqno =amdgpu_fence_read (ring); + wptr = ring->fence_drv.signalled_wptr; + ring->ring_backup_entries_to_copy =0 ; + +for (i = seqno +1 ; i <= ring->fence_drv.sync_seq; ++i) { + ptr = &ring->fence_drv.fences[i & ring->fence_drv.num_fences_mask]; +rcu_read_lock (); + unprocessed =rcu_dereference (*ptr); + +if (unprocessed && !dma_fence_is_signaled (unprocessed)) {
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c void amdgpu_fence_driver_force_completion(struct amdgpu_ring *ring) · line 811
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +6
-0+ fence = container_of(unprocessed, struct amdgpu_fence, base); + +/* save everything if the ring is not guilty, otherwise +* just save the content from other contexts. +*/ +if (!guilty_fence || (fence->context != guilty_fence->context))Why do you need these two checks? Why is
guilty_fencenot enough here?
There are two cases:
1. The fence innocent, in which case, we can back up all of the unprocessed ring contents.
2. The fence is guilty, in which case, we want to skip ring content associated with all fences associated with the guilty context.
Quoted 201 lines
Quoted 201 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +8
-0+amdgpu_ring_backup_unprocessed_command (ring, wptr, + fence->wptr); + wptr = fence->wptr; + } +rcu_read_unlock (); + } +} +/* * Common fence implementation */ drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c +14
-1@@ -139,7 +139,6 @@ int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned int num_ibs,int vmid =AMDGPU_JOB_GET_VMID (job);bool need_pipe_sync = false;unsigned int cond_exec; -unsigned int i;int r =0 ;@@ -156,6 +155,11 @@ int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned int num_ibs, gds_va = job->gds_va; init_shadow = job->init_shadow; af = &job->hw_fence; +/* Save the context of the job for reset handling. +* The driver needs this so it can skip the ring +* contents for guilty contexts. +*/ + af->context = job->base.s_fence ? job->base.s_fence->finished.context :0 ; }else { vm =NULL ; fence_ctx =0 ;@@ -307,8 +311,17 @@ int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned int num_ibs, ring->hw_prio == AMDGPU_GFX_PIPE_PRIO_HIGH) ring->funcs->emit_wave_limit (ring, false); +/* Save the wptr associated with this fence. +* This must be last for resets to work properly +* as we need to save the wptr associated with this +* fence so we know what rings contents to backup +* after we reset the queue. +*/ +amdgpu_fence_save_wptr (*f); +amdgpu_ring_ib_end (ring);amdgpu_ring_commit (ring); +return 0 ; }drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +2
-2@@ -89,8 +89,8 @@ static enum drm_gpu_sched_stat amdgpu_job_timedout(struct drm_sched_job *s_job) {struct amdgpu_ring *ring =to_amdgpu_ring (s_job->sched);struct amdgpu_job *job =to_amdgpu_job (s_job); -struct amdgpu_task_info *ti;struct amdgpu_device *adev = ring->adev; +struct amdgpu_task_info *ti;int idx, r;if (!drm_dev_enter (adev_to_drm (adev), &idx)) {@@ -135,7 +135,7 @@ static enum drm_gpu_sched_stat amdgpu_job_timedout(struct drm_sched_job *s_job) }else if (amdgpu_gpu_recovery && ring->funcs->reset) {dev_err (adev->dev,"Starting %s ring reset\n" , s_job->sched->name); - r =amdgpu_ring_reset (ring, job->vmid,NULL ); + r =amdgpu_ring_reset (ring, job->vmid, &job->hw_fence);if (!r) {atomic_inc (&ring->adev->gpu_reset_counter); dev_err(adev->dev, "Ring %s reset succeeded\n",drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +67
-0@@ -99,6 +99,29 @@ int amdgpu_ring_alloc(struct amdgpu_ring *ring, unsigned int ndw)return 0 ; } +/** +* amdgpu_ring_alloc_reemit - allocate space on the ring buffer for reemit +* +* @ring: amdgpu_ring structure holding ring information +* @ndw: number of dwords to allocate in the ring buffer +* +* Allocate @ndw dwords in the ring buffer (all asics). +* doesn't check the max_dw limit as we may be reemitting +* several submissions. +*/ +static void amdgpu_ring_alloc_reemit (struct amdgpu_ring *ring,unsigned int ndw) +{ +/* Align requested size with padding so unlock_commit can +* pad safely */ + ndw = (ndw + ring->funcs->align_mask) & ~ring->funcs->align_mask; + + ring->count_dw = ndw; + ring->wptr_old = ring->wptr; + +if (ring->funcs->begin_use) + ring->funcs->begin_use (ring); +} +/** amdgpu_ring_insert_nop - insert NOP packets * * @ring: amdgpu_ring structure holding ring information @@ -333,6 +356,12 @@ int amdgpu_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring,/* Initialize cached_rptr to 0 */ ring->cached_rptr =0 ; +if (!ring->ring_backup) { + ring->ring_backup =kvzalloc (ring->ring_size,GFP_KERNEL ); +if (!ring->ring_backup) +return -ENOMEM ; + } +/* Allocate ring buffer */ if (ring->ring_obj ==NULL ) { r = amdgpu_bo_create_kernel(adev, ring->ring_size + ring->funcs->extra_dw, PAGE_SIZE,@@ -342,6 +371,7 @@ int amdgpu_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring, (void **)&ring->ring);if (r) {dev_err (adev->dev,"(%d) ring create failed\n" , r); +kvfree (ring->ring_backup);return r; }amdgpu_ring_clear_ring (ring);@@ -385,6 +415,8 @@ void amdgpu_ring_fini(struct amdgpu_ring *ring)amdgpu_bo_free_kernel (&ring->ring_obj, &ring->gpu_addr, (void **)&ring->ring); +kvfree (ring->ring_backup); + ring->ring_backup =NULL ;dma_fence_put (ring->vmid_wait); ring->vmid_wait =NULL ;@@ -753,3 +785,38 @@ bool amdgpu_ring_sched_ready(struct amdgpu_ring *ring)return true; } + +void amdgpu_ring_reset_helper_begin (struct amdgpu_ring *ring, +struct amdgpu_fence *guilty_fence) +{ +/* Stop the scheduler to prevent anybody else from touching the ring buffer. */ +drm_sched_wqueue_stop (&ring->sched); +/* back up the non-guilty commands */ +amdgpu_ring_backup_unprocessed_commands (ring, guilty_fence); +} + +int amdgpu_ring_reset_helper_end (struct amdgpu_ring *ring, +struct amdgpu_fence *guilty_fence) +{ +unsigned int i; +int r; + +/* verify that the ring is functional */ + r =amdgpu_ring_test_ring (ring); +if (r) +return r; + +/* signal the fence of the bad job */ +if (guilty_fence) +amdgpu_fence_driver_guilty_force_completion (guilty_fence); +/* Re-emit the non-guilty commands */ +if (ring->ring_backup_entries_to_copy) { +amdgpu_ring_alloc_reemit (ring, ring->ring_backup_entries_to_copy); +for (i =0 ; i < ring->ring_backup_entries_to_copy; i++) +amdgpu_ring_write (ring, ring->ring_backup[i]); +amdgpu_ring_commit (ring); + } +/* Start the scheduler again */ +drm_sched_wqueue_start (&ring->sched); +return 0 ; +}drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h +6
-0@@ -118,6 +118,7 @@ struct amdgpu_fence_driver {/* sync_seq is protected by ring emission lock */ uint32_t sync_seq;atomic_t last_seq; +u64 signalled_wptr;bool initialized;struct amdgpu_irq_src *irq_src;unsigned irq_type;@@ -141,6 +142,12 @@ struct amdgpu_fence {/* RB, DMA, etc. */ struct amdgpu_ring *ring;ktime_t start_timestamp; + +/* wptr for the fence for resets */ +u64 wptr; +/* fence context for resets */ +u64 context;
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h struct amdgpu_fence { · line 150
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h +1
-0+uint32_t seq;All of these new fields are associated with reset, and their names are also common in the code (we see wptr, context, and seq everywhere). What do you think of adding a suffix/prefix to identify their purpose in the code clearly? For example,
wptr_resetinstead of wptr orcontext_resetinstead of context. It does not need to be_reset, but something that helps to identify these field purpose in the code.
They are used to facilitate the resets, but at a more general level, they are just tagging the fence with additional metadata. The wptr marks the wptr value associated with the work associated with the fence. seq is the sequence number
associated with the fence (i.e., the value that will get written when the work on the engine completes). The context is the context of the job whose work is associated with the fence.
Alex
Quoted 64 lines
Thanks
Quoted 56 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h +11
-0};extern const struct drm_sched_backend_ops amdgpu_sched_ops;@@ -148,6 +155,8 @@ extern const struct drm_sched_backend_ops amdgpu_sched_ops;void amdgpu_fence_driver_clear_job_fences (struct amdgpu_ring *ring);void amdgpu_fence_driver_set_error (struct amdgpu_ring *ring,int error);void amdgpu_fence_driver_force_completion (struct amdgpu_ring *ring); +void amdgpu_fence_driver_guilty_force_completion (struct amdgpu_fence *fence); +void amdgpu_fence_save_wptr (struct dma_fence *fence);int amdgpu_fence_driver_init_ring (struct amdgpu_ring *ring); int amdgpu_fence_driver_start_ring(struct amdgpu_ring *ring,@@ -284,6 +293,9 @@ struct amdgpu_ring {struct amdgpu_bo *ring_obj;uint32_t *ring; +/* backups for resets */ +uint32_t *ring_backup; +unsigned int ring_backup_entries_to_copy;unsigned rptr_offs;u64 rptr_gpu_addr;volatile u32 *rptr_cpu_addr;@@ -550,4 +562,10 @@ int amdgpu_ib_pool_init(struct amdgpu_device *adev);void amdgpu_ib_pool_fini (struct amdgpu_device *adev);int amdgpu_ib_ring_tests (struct amdgpu_device *adev);bool amdgpu_ring_sched_ready (struct amdgpu_ring *ring); +void amdgpu_ring_backup_unprocessed_commands (struct amdgpu_ring *ring, +struct amdgpu_fence *guilty_fence); +void amdgpu_ring_reset_helper_begin (struct amdgpu_ring *ring, +struct amdgpu_fence *guilty_fence); +int amdgpu_ring_reset_helper_end (struct amdgpu_ring *ring, +struct amdgpu_fence *guilty_fence);#endif drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +4
-1@@ -765,6 +765,7 @@ int amdgpu_vm_flush(struct amdgpu_ring *ring, struct amdgpu_job *job,bool cleaner_shader_needed = false;bool pasid_mapping_needed = false;struct dma_fence *fence =NULL ; +struct amdgpu_fence *af;unsigned int patch;int r;@@ -830,6 +831,9 @@ int amdgpu_vm_flush(struct amdgpu_ring *ring, struct amdgpu_job *job, r =amdgpu_fence_emit (ring, &fence,NULL ,0 );if (r)return r; +/* this is part of the job's context */ + af = container_of(fence, struct amdgpu_fence, base); + af->context = job->base.s_fence ? job->base.s_fence->finished.context :0 ; }if (vm_flush_needed) { --Quoted 2 lines
2.50.0
--
Rodrigo Siqueira
Alex Deucher
maintainerPATCH v13 4/28 drm/amdgpu/gfx9: re-emit unprocessed state on kcq reset
In reply to Alex DeucherRe-emit the unprocessed state after resetting the queue.
--- drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +3 -9
@@ -7187,7 +7187,7 @@ static int gfx_v9_0_reset_kcq(struct amdgpu_ring *ring,if (!kiq->pmf || !kiq->pmf->kiq_unmap_queues)return -EINVAL ; -drm_sched_wqueue_stop (&ring->sched); +amdgpu_ring_reset_helper_begin (ring, timedout_fence);spin_lock_irqsave (&kiq->ring_lock, flags);
@@ -7238,19 +7238,13 @@ static int gfx_v9_0_reset_kcq(struct amdgpu_ring *ring, } kiq->pmf->kiq_map_queues (kiq_ring, ring);amdgpu_ring_commit (kiq_ring); -spin_unlock_irqrestore (&kiq->ring_lock, flags); r =amdgpu_ring_test_ring (kiq_ring); +spin_unlock_irqrestore (&kiq->ring_lock, flags);if (r) {DRM_ERROR ("fail to remap queue\n" );return r; } - - r =amdgpu_ring_test_ring (ring); -if (r) -return r; -amdgpu_fence_driver_force_completion (ring); -drm_sched_wqueue_start (&ring->sched); -return 0 ; +return amdgpu_ring_reset_helper_end (ring, timedout_fence); }static void gfx_v9_ip_print (struct amdgpu_ip_block *ip_block,struct drm_printer *p)
Signature · 1 line
2.50.0
RE: [PATCH 04/28] drm/amdgpu/gfx9: re-emit unprocessed state on kcq reset
[AMD Official Use Only - AMD Internal Distribution Only]
[PATCH 04/28] drm/amdgpu/gfx9: re-emit unprocessed state on kcq reset [PATCH 06/28] drm/amdgpu/gfx10: re-emit unprocessed state on ring reset [PATCH 07/28] drm/amdgpu/gfx11: re-emit unprocessed state on ring reset [PATCH 08/28] drm/amdgpu/gfx12: re-emit unprocessed state on ring reset [PATCH 09/28] drm/amdgpu/sdma5: re-emit unprocessed state on ring reset [PATCH 11/28] drm/amdgpu/sdma6: re-emit unprocessed state on ring reset [PATCH 10/28] drm/amdgpu/sdma5.2: re-emit unprocessed state on ring reset
these patches are Reviewed-by: Jesse Zhang <[email protected]>
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Alex Deucher
Sent: Wednesday, July 2, 2025 2:44 AM
To: [email protected]; Koenig, Christian <[email protected]>; Sundararaju, Sathishkumar <[email protected]>
Cc: Deucher, Alexander <[email protected]>
Subject: [PATCH 04/28] drm/amdgpu/gfx9: re-emit unprocessed state on kcq reset
Re-emit the unprocessed state after resetting the queue.
--- drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +3 -9
@@ -7187,7 +7187,7 @@ static int gfx_v9_0_reset_kcq(struct amdgpu_ring *ring,if (!kiq->pmf || !kiq->pmf->kiq_unmap_queues)return -EINVAL ; -drm_sched_wqueue_stop (&ring->sched); +amdgpu_ring_reset_helper_begin (ring, timedout_fence);spin_lock_irqsave (&kiq->ring_lock, flags);
@@ -7238,19 +7238,13 @@ static int gfx_v9_0_reset_kcq(struct amdgpu_ring *ring, } kiq->pmf->kiq_map_queues (kiq_ring, ring);amdgpu_ring_commit (kiq_ring); -spin_unlock_irqrestore (&kiq->ring_lock, flags); r =amdgpu_ring_test_ring (kiq_ring); +spin_unlock_irqrestore (&kiq->ring_lock, flags);if (r) {DRM_ERROR ("fail to remap queue\n" );return r; } - - r =amdgpu_ring_test_ring (ring); -if (r) -return r; -amdgpu_fence_driver_force_completion (ring); -drm_sched_wqueue_start (&ring->sched); -return 0 ; +return amdgpu_ring_reset_helper_end (ring, timedout_fence); }static void gfx_v9_ip_print (struct amdgpu_ip_block *ip_block,struct drm_printer *p)
--
2.50.0
Re: [PATCH 04/28] drm/amdgpu/gfx9: re-emit unprocessed state on kcq reset
In reply to Alex DeucherQuoted 21 lines · Alex Deucher
Re-emit the unprocessed state after resetting the queue.
Signed-off-by Alex Deucher <[email protected]>--- drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-)drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +1
-1@@ -7187,7 +7187,7 @@ static int gfx_v9_0_reset_kcq(struct amdgpu_ring *ring,if (!kiq->pmf || !kiq->pmf->kiq_unmap_queues)return -EINVAL ; -drm_sched_wqueue_stop (&ring->sched); +amdgpu_ring_reset_helper_begin (ring, timedout_fence);spin_lock_irqsave (&kiq->ring_lock, flags);
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c static int gfx_v9_0_reset_kcq(struct amdgpu_ring *ring, · line 7242
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +1
-1@@ -7238,19 +7238,13 @@ static int gfx_v9_0_reset_kcq(struct amdgpu_ring *ring, } kiq->pmf->kiq_map_queues (kiq_ring, ring);amdgpu_ring_commit (kiq_ring); -spin_unlock_irqrestore (&kiq->ring_lock, flags); r =amdgpu_ring_test_ring (kiq_ring); +spin_unlock_irqrestore (&kiq->ring_lock, flags);
Is this spin_unlock_irqrestore part something that maybe should be in another commit? Maybe one commit that make this change for all of the GFXs?
Thanks
Quoted 18 lines
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +1
-7if (r) {DRM_ERROR ("fail to remap queue\n" );return r; } - - r =amdgpu_ring_test_ring (ring); -if (r) -return r; -amdgpu_fence_driver_force_completion (ring); -drm_sched_wqueue_start (&ring->sched); -return 0 ; +return amdgpu_ring_reset_helper_end (ring, timedout_fence); }static void gfx_v9_ip_print (struct amdgpu_ip_block *ip_block,struct drm_printer *p)Signature · 1 line
2.50.0
Signature · 1 line
Rodrigo Siqueira
Re: [PATCH 04/28] drm/amdgpu/gfx9: re-emit unprocessed state on kcq reset
Quoted 22 lines · Rodrigo Siqueira
Quoted 20 lines · Alex Deucher
Re-emit the unprocessed state after resetting the queue.
Signed-off-by Alex Deucher <[email protected]>--- drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-)drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +1
-1@@ -7187,7 +7187,7 @@ static int gfx_v9_0_reset_kcq(struct amdgpu_ring *ring,if (!kiq->pmf || !kiq->pmf->kiq_unmap_queues)return -EINVAL ; -drm_sched_wqueue_stop (&ring->sched); +amdgpu_ring_reset_helper_begin (ring, timedout_fence);spin_lock_irqsave (&kiq->ring_lock, flags);
Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c static int gfx_v9_0_reset_kcq(struct amdgpu_ring *ring, · line 7242
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +1
-1@@ -7238,19 +7238,13 @@ static int gfx_v9_0_reset_kcq(struct amdgpu_ring *ring, } kiq->pmf->kiq_map_queues (kiq_ring, ring);amdgpu_ring_commit (kiq_ring); -spin_unlock_irqrestore (&kiq->ring_lock, flags); r =amdgpu_ring_test_ring (kiq_ring); +spin_unlock_irqrestore (&kiq->ring_lock, flags);Is this
spin_unlock_irqrestorepart something that maybe should be in another commit? Maybe one commit that make this change for all of the GFXs?
Sure. I'll split them out as bug fixes.
Alex
Quoted 24 lines
Thanks
Quoted 16 lines
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +1
-8if (r) {DRM_ERROR ("fail to remap queue\n" );return r; } - - r =amdgpu_ring_test_ring (ring); -if (r) -return r; -amdgpu_fence_driver_force_completion (ring); -drm_sched_wqueue_start (&ring->sched); -return 0 ; +return amdgpu_ring_reset_helper_end (ring, timedout_fence); }static void gfx_v9_ip_print (struct amdgpu_ip_block *ip_block,struct drm_printer *p) --Quoted 2 lines
2.50.0
--
Rodrigo Siqueira
Alex Deucher
maintainerPATCH v13 5/28 drm/amdgpu/gfx9.4.3: re-emit unprocessed state on kcq reset
In reply to Alex DeucherRe-emit the unprocessed state after resetting the queue.
--- drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c +3 -9
@@ -3567,7 +3567,7 @@ static int gfx_v9_4_3_reset_kcq(struct amdgpu_ring *ring,if (!kiq->pmf || !kiq->pmf->kiq_unmap_queues)return -EINVAL ; -drm_sched_wqueue_stop (&ring->sched); +amdgpu_ring_reset_helper_begin (ring, timedout_fence);spin_lock_irqsave (&kiq->ring_lock, flags);
@@ -3615,20 +3615,14 @@ static int gfx_v9_4_3_reset_kcq(struct amdgpu_ring *ring, } kiq->pmf->kiq_map_queues (kiq_ring, ring);amdgpu_ring_commit (kiq_ring); -spin_unlock_irqrestore (&kiq->ring_lock, flags); - r =amdgpu_ring_test_ring (kiq_ring); +spin_unlock_irqrestore (&kiq->ring_lock, flags);if (r) {dev_err (adev->dev,"fail to remap queue\n" );return r; } - r =amdgpu_ring_test_ring (ring); -if (r) -return r; -amdgpu_fence_driver_force_completion (ring); -drm_sched_wqueue_start (&ring->sched); -return 0 ; +return amdgpu_ring_reset_helper_end (ring, timedout_fence); }enum amdgpu_gfx_cp_ras_mem_id {
Signature · 1 line
2.50.0
Alex Deucher
maintainerPATCH v13 6/28 drm/amdgpu/gfx10: re-emit unprocessed state on ring reset
In reply to Alex DeucherRe-emit the unprocessed state after resetting the queue.
--- drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c | 41 ++++---------------------- 1 file changed, 6 insertions(+), 35 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +6 -35
@@ -9046,21 +9046,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,
@@ -9540,7 +9525,7 @@ static int gfx_v10_0_reset_kgq(struct amdgpu_ring *ring,if (!kiq->pmf || !kiq->pmf->kiq_unmap_queues)return -EINVAL ; -drm_sched_wqueue_stop (&ring->sched); +amdgpu_ring_reset_helper_begin (ring, timedout_fence);spin_lock_irqsave (&kiq->ring_lock, flags);
@@ -9589,12 +9574,7 @@ static int gfx_v10_0_reset_kgq(struct amdgpu_ring *ring,if (r)return r; - r =amdgpu_ring_test_ring (ring); -if (r) -return r; -amdgpu_fence_driver_force_completion (ring); -drm_sched_wqueue_start (&ring->sched); -return 0 ; +return amdgpu_ring_reset_helper_end (ring, timedout_fence); } static int gfx_v10_0_reset_kcq(struct amdgpu_ring *ring,
@@ -9613,7 +9593,7 @@ static int gfx_v10_0_reset_kcq(struct amdgpu_ring *ring,if (!kiq->pmf || !kiq->pmf->kiq_unmap_queues)return -EINVAL ; -drm_sched_wqueue_stop (&ring->sched); +amdgpu_ring_reset_helper_begin (ring, timedout_fence);spin_lock_irqsave (&kiq->ring_lock, flags);
@@ -9625,9 +9605,8 @@ static int gfx_v10_0_reset_kcq(struct amdgpu_ring *ring, kiq->pmf->kiq_unmap_queues (kiq_ring, ring,RESET_QUEUES ,0 ,0 );amdgpu_ring_commit (kiq_ring); -spin_unlock_irqrestore (&kiq->ring_lock, flags); - r =amdgpu_ring_test_ring (kiq_ring); +spin_unlock_irqrestore (&kiq->ring_lock, flags);if (r)return r;
@@ -9663,18 +9642,12 @@ static int gfx_v10_0_reset_kcq(struct amdgpu_ring *ring, } kiq->pmf->kiq_map_queues (kiq_ring, ring);amdgpu_ring_commit (kiq_ring); -spin_unlock_irqrestore (&kiq->ring_lock, flags); - r =amdgpu_ring_test_ring (kiq_ring); +spin_unlock_irqrestore (&kiq->ring_lock, flags);if (r)return r; - r =amdgpu_ring_test_ring (ring); -if (r) -return r; -amdgpu_fence_driver_force_completion (ring); -drm_sched_wqueue_start (&ring->sched); -return 0 ; +return amdgpu_ring_reset_helper_end (ring, timedout_fence); }static void gfx_v10_ip_print (struct amdgpu_ip_block *ip_block,struct drm_printer *p)
@@ -9909,7 +9882,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,
@@ -9950,7 +9922,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.50.0
Re: [PATCH 06/28] drm/amdgpu/gfx10: re-emit unprocessed state on ring reset
Quoted 20 lines · Alex Deucher
Re-emit the unprocessed state after resetting the queue.
Signed-off-by Alex Deucher <[email protected]>--- drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c | 41 ++++---------------------- 1 file changed, 6 insertions(+), 35 deletions(-)drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +0
-5@@ -9046,21 +9046,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 ;
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c static void gfx_v10_0_ring_emit_reg_write_reg_wait(struct amdgpu_ring *ring, · line 9063
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +0
-10- - 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 ); -} -
You are eliminating the gfx_v10_0_ring_soft_recovery here, but why you did not remove it in the GFX9 (previous commit)?
Also, I suppose the new recovery method from this series will replace this soft_recovery, right? If so, I suggest you include this information in the commit message.
Thanks
Quoted 86 lines
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +6
-20static void gfx_v10_0_set_gfx_eop_interrupt_state(struct amdgpu_device *adev, uint32_t me, uint32_t pipe,@@ -9540,7 +9525,7 @@ static int gfx_v10_0_reset_kgq(struct amdgpu_ring *ring,if (!kiq->pmf || !kiq->pmf->kiq_unmap_queues)return -EINVAL ; -drm_sched_wqueue_stop (&ring->sched); +amdgpu_ring_reset_helper_begin (ring, timedout_fence);spin_lock_irqsave (&kiq->ring_lock, flags);@@ -9589,12 +9574,7 @@ static int gfx_v10_0_reset_kgq(struct amdgpu_ring *ring,if (r)return r; - r =amdgpu_ring_test_ring (ring); -if (r) -return r; -amdgpu_fence_driver_force_completion (ring); -drm_sched_wqueue_start (&ring->sched); -return 0 ; +return amdgpu_ring_reset_helper_end (ring, timedout_fence); } static int gfx_v10_0_reset_kcq(struct amdgpu_ring *ring,@@ -9613,7 +9593,7 @@ static int gfx_v10_0_reset_kcq(struct amdgpu_ring *ring,if (!kiq->pmf || !kiq->pmf->kiq_unmap_queues)return -EINVAL ; -drm_sched_wqueue_stop (&ring->sched); +amdgpu_ring_reset_helper_begin (ring, timedout_fence);spin_lock_irqsave (&kiq->ring_lock, flags);@@ -9625,9 +9605,8 @@ static int gfx_v10_0_reset_kcq(struct amdgpu_ring *ring, kiq->pmf->kiq_unmap_queues (kiq_ring, ring,RESET_QUEUES ,0 ,0 );amdgpu_ring_commit (kiq_ring); -spin_unlock_irqrestore (&kiq->ring_lock, flags); - r =amdgpu_ring_test_ring (kiq_ring); +spin_unlock_irqrestore (&kiq->ring_lock, flags);if (r)return r;@@ -9663,18 +9642,12 @@ static int gfx_v10_0_reset_kcq(struct amdgpu_ring *ring, } kiq->pmf->kiq_map_queues (kiq_ring, ring);amdgpu_ring_commit (kiq_ring); -spin_unlock_irqrestore (&kiq->ring_lock, flags); - r =amdgpu_ring_test_ring (kiq_ring); +spin_unlock_irqrestore (&kiq->ring_lock, flags);if (r)return r; - r =amdgpu_ring_test_ring (ring); -if (r) -return r; -amdgpu_fence_driver_force_completion (ring); -drm_sched_wqueue_start (&ring->sched); -return 0 ; +return amdgpu_ring_reset_helper_end (ring, timedout_fence); }static void gfx_v10_ip_print (struct amdgpu_ip_block *ip_block,struct drm_printer *p)@@ -9909,7 +9882,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,@@ -9950,7 +9922,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.50.0
Signature · 1 line
Rodrigo Siqueira
Re: [PATCH 06/28] drm/amdgpu/gfx10: re-emit unprocessed state on ring reset
Quoted 27 lines · Rodrigo Siqueira
Quoted 25 lines · Alex Deucher
Re-emit the unprocessed state after resetting the queue.
Signed-off-by Alex Deucher <[email protected]>--- drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c | 41 ++++---------------------- 1 file changed, 6 insertions(+), 35 deletions(-)drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +0
-10@@ -9046,21 +9046,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);
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c static void gfx_v10_0_ring_emit_reg_write_reg_wait(struct amdgpu_ring *ring, · line 9063
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +0
-5-amdgpu_gfx_rlc_enter_safe_mode (adev,0 ); -WREG32_SOC15 (GC ,0 , mmSQ_CMD, value); -amdgpu_gfx_rlc_exit_safe_mode (adev,0 ); -} -You are eliminating the
gfx_v10_0_ring_soft_recoveryhere, but why you did not remove it in the GFX9 (previous commit)?
gfx9 doesn't implement graphics reset yet so we still need soft recovery.
Quoted 4 lines
Also, I suppose the new recovery method from this series will replace this
soft_recovery, right? If so, I suggest you include this information in the commit message.
Correct. Will update the message.
Alex
Quoted 92 lines
Thanks
Quoted 84 lines
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +6
-21static void gfx_v10_0_set_gfx_eop_interrupt_state(struct amdgpu_device *adev, uint32_t me, uint32_t pipe,@@ -9540,7 +9525,7 @@ static int gfx_v10_0_reset_kgq(struct amdgpu_ring *ring,if (!kiq->pmf || !kiq->pmf->kiq_unmap_queues)return -EINVAL ; -drm_sched_wqueue_stop (&ring->sched); +amdgpu_ring_reset_helper_begin (ring, timedout_fence);spin_lock_irqsave (&kiq->ring_lock, flags);@@ -9589,12 +9574,7 @@ static int gfx_v10_0_reset_kgq(struct amdgpu_ring *ring,if (r)return r; - r =amdgpu_ring_test_ring (ring); -if (r) -return r; -amdgpu_fence_driver_force_completion (ring); -drm_sched_wqueue_start (&ring->sched); -return 0 ; +return amdgpu_ring_reset_helper_end (ring, timedout_fence); } static int gfx_v10_0_reset_kcq(struct amdgpu_ring *ring,@@ -9613,7 +9593,7 @@ static int gfx_v10_0_reset_kcq(struct amdgpu_ring *ring,if (!kiq->pmf || !kiq->pmf->kiq_unmap_queues)return -EINVAL ; -drm_sched_wqueue_stop (&ring->sched); +amdgpu_ring_reset_helper_begin (ring, timedout_fence);spin_lock_irqsave (&kiq->ring_lock, flags);@@ -9625,9 +9605,8 @@ static int gfx_v10_0_reset_kcq(struct amdgpu_ring *ring, kiq->pmf->kiq_unmap_queues (kiq_ring, ring,RESET_QUEUES ,0 ,0 );amdgpu_ring_commit (kiq_ring); -spin_unlock_irqrestore (&kiq->ring_lock, flags); - r =amdgpu_ring_test_ring (kiq_ring); +spin_unlock_irqrestore (&kiq->ring_lock, flags);if (r)return r;@@ -9663,18 +9642,12 @@ static int gfx_v10_0_reset_kcq(struct amdgpu_ring *ring, } kiq->pmf->kiq_map_queues (kiq_ring, ring);amdgpu_ring_commit (kiq_ring); -spin_unlock_irqrestore (&kiq->ring_lock, flags); - r =amdgpu_ring_test_ring (kiq_ring); +spin_unlock_irqrestore (&kiq->ring_lock, flags);if (r)return r; - r =amdgpu_ring_test_ring (ring); -if (r) -return r; -amdgpu_fence_driver_force_completion (ring); -drm_sched_wqueue_start (&ring->sched); -return 0 ; +return amdgpu_ring_reset_helper_end (ring, timedout_fence); }static void gfx_v10_ip_print (struct amdgpu_ip_block *ip_block,struct drm_printer *p)@@ -9909,7 +9882,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,@@ -9950,7 +9922,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, --Quoted 2 lines
2.50.0
--
Rodrigo Siqueira
Alex Deucher
maintainerPATCH v13 7/28 drm/amdgpu/gfx11: re-emit unprocessed state on ring reset
In reply to Alex DeucherRe-emit the unprocessed state after resetting the queue.
--- drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 35 +++----------------------- 1 file changed, 4 insertions(+), 31 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +4 -31
@@ -6283,21 +6283,6 @@ static void gfx_v11_0_ring_emit_reg_write_reg_wait(struct amdgpu_ring *ring, ref, mask, 0x20); } -static void gfx_v11_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 , regSQ_CMD, value); -amdgpu_gfx_rlc_exit_safe_mode (adev,0 ); -} - static void gfx_v11_0_set_gfx_eop_interrupt_state(struct amdgpu_device *adev, uint32_t me, uint32_t pipe,
@@ -6821,7 +6806,7 @@ static int gfx_v11_0_reset_kgq(struct amdgpu_ring *ring,if (amdgpu_sriov_vf (adev))return -EINVAL ; -drm_sched_wqueue_stop (&ring->sched); +amdgpu_ring_reset_helper_begin (ring, timedout_fence); r =amdgpu_mes_reset_legacy_queue (ring->adev, ring, vmid, false);if (r) {
@@ -6844,12 +6829,7 @@ static int gfx_v11_0_reset_kgq(struct amdgpu_ring *ring,return r; } - r =amdgpu_ring_test_ring (ring); -if (r) -return r; -amdgpu_fence_driver_force_completion (ring); -drm_sched_wqueue_start (&ring->sched); -return 0 ; +return amdgpu_ring_reset_helper_end (ring, timedout_fence); }static int gfx_v11_0_reset_compute_pipe (struct amdgpu_ring *ring)
@@ -6992,7 +6972,7 @@ static int gfx_v11_0_reset_kcq(struct amdgpu_ring *ring,if (amdgpu_sriov_vf (adev))return -EINVAL ; -drm_sched_wqueue_stop (&ring->sched); +amdgpu_ring_reset_helper_begin (ring, timedout_fence); r =amdgpu_mes_reset_legacy_queue (ring->adev, ring, vmid, true);if (r) {
@@ -7013,12 +6993,7 @@ static int gfx_v11_0_reset_kcq(struct amdgpu_ring *ring,return r; } - r =amdgpu_ring_test_ring (ring); -if (r) -return r; -amdgpu_fence_driver_force_completion (ring); -drm_sched_wqueue_start (&ring->sched); -return 0 ; +return amdgpu_ring_reset_helper_end (ring, timedout_fence); }static void gfx_v11_ip_print (struct amdgpu_ip_block *ip_block,struct drm_printer *p)
@@ -7254,7 +7229,6 @@ static const struct amdgpu_ring_funcs gfx_v11_0_ring_funcs_gfx = { .emit_wreg = gfx_v11_0_ring_emit_wreg, .emit_reg_wait = gfx_v11_0_ring_emit_reg_wait, .emit_reg_write_reg_wait = gfx_v11_0_ring_emit_reg_write_reg_wait, - .soft_recovery = gfx_v11_0_ring_soft_recovery, .emit_mem_sync = gfx_v11_0_emit_mem_sync, .reset = gfx_v11_0_reset_kgq, .emit_cleaner_shader = gfx_v11_0_ring_emit_cleaner_shader,
@@ -7296,7 +7270,6 @@ static const struct amdgpu_ring_funcs gfx_v11_0_ring_funcs_compute = { .emit_wreg = gfx_v11_0_ring_emit_wreg, .emit_reg_wait = gfx_v11_0_ring_emit_reg_wait, .emit_reg_write_reg_wait = gfx_v11_0_ring_emit_reg_write_reg_wait, - .soft_recovery = gfx_v11_0_ring_soft_recovery, .emit_mem_sync = gfx_v11_0_emit_mem_sync, .reset = gfx_v11_0_reset_kcq, .emit_cleaner_shader = gfx_v11_0_ring_emit_cleaner_shader,
Signature · 1 line
2.50.0
Alex Deucher
maintainerPATCH v13 8/28 drm/amdgpu/gfx12: re-emit unprocessed state on ring reset
In reply to Alex DeucherRe-emit the unprocessed state after resetting the queue.
--- drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c | 35 +++----------------------- 1 file changed, 4 insertions(+), 31 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +4 -31
@@ -4690,21 +4690,6 @@ static void gfx_v12_0_ring_emit_reg_write_reg_wait(struct amdgpu_ring *ring, ref, mask, 0x20); } -static void gfx_v12_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 , regSQ_CMD, value); -amdgpu_gfx_rlc_exit_safe_mode (adev,0 ); -} - static void gfx_v12_0_set_gfx_eop_interrupt_state(struct amdgpu_device *adev, uint32_t me, uint32_t pipe,
@@ -5317,7 +5302,7 @@ static int gfx_v12_0_reset_kgq(struct amdgpu_ring *ring,if (amdgpu_sriov_vf (adev))return -EINVAL ; -drm_sched_wqueue_stop (&ring->sched); +amdgpu_ring_reset_helper_begin (ring, timedout_fence); r =amdgpu_mes_reset_legacy_queue (ring->adev, ring, vmid, false);if (r) {
@@ -5339,12 +5324,7 @@ static int gfx_v12_0_reset_kgq(struct amdgpu_ring *ring,return r; } - r =amdgpu_ring_test_ring (ring); -if (r) -return r; -amdgpu_fence_driver_force_completion (ring); -drm_sched_wqueue_start (&ring->sched); -return 0 ; +return amdgpu_ring_reset_helper_end (ring, timedout_fence); }static int gfx_v12_0_reset_compute_pipe (struct amdgpu_ring *ring)
@@ -5440,7 +5420,7 @@ static int gfx_v12_0_reset_kcq(struct amdgpu_ring *ring,if (amdgpu_sriov_vf (adev))return -EINVAL ; -drm_sched_wqueue_stop (&ring->sched); +amdgpu_ring_reset_helper_begin (ring, timedout_fence); r =amdgpu_mes_reset_legacy_queue (ring->adev, ring, vmid, true);if (r) {
@@ -5461,12 +5441,7 @@ static int gfx_v12_0_reset_kcq(struct amdgpu_ring *ring,return r; } - r =amdgpu_ring_test_ring (ring); -if (r) -return r; -amdgpu_fence_driver_force_completion (ring); -drm_sched_wqueue_start (&ring->sched); -return 0 ; +return amdgpu_ring_reset_helper_end (ring, timedout_fence); }static void gfx_v12_0_ring_begin_use (struct amdgpu_ring *ring)
@@ -5544,7 +5519,6 @@ static const struct amdgpu_ring_funcs gfx_v12_0_ring_funcs_gfx = { .emit_wreg = gfx_v12_0_ring_emit_wreg, .emit_reg_wait = gfx_v12_0_ring_emit_reg_wait, .emit_reg_write_reg_wait = gfx_v12_0_ring_emit_reg_write_reg_wait, - .soft_recovery = gfx_v12_0_ring_soft_recovery, .emit_mem_sync = gfx_v12_0_emit_mem_sync, .reset = gfx_v12_0_reset_kgq, .emit_cleaner_shader = gfx_v12_0_ring_emit_cleaner_shader,
@@ -5583,7 +5557,6 @@ static const struct amdgpu_ring_funcs gfx_v12_0_ring_funcs_compute = { .emit_wreg = gfx_v12_0_ring_emit_wreg, .emit_reg_wait = gfx_v12_0_ring_emit_reg_wait, .emit_reg_write_reg_wait = gfx_v12_0_ring_emit_reg_write_reg_wait, - .soft_recovery = gfx_v12_0_ring_soft_recovery, .emit_mem_sync = gfx_v12_0_emit_mem_sync, .reset = gfx_v12_0_reset_kcq, .emit_cleaner_shader = gfx_v12_0_ring_emit_cleaner_shader,
Signature · 1 line
2.50.0
Alex Deucher
maintainerPATCH v13 9/28 drm/amdgpu/sdma5: re-emit unprocessed state on ring reset
In reply to Alex DeucherRe-emit the unprocessed state after resetting the queue.
--- drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c +14 -3
@@ -1544,14 +1544,25 @@ static int sdma_v5_0_reset_queue(struct amdgpu_ring *ring, struct amdgpu_fence *timedout_fence) {struct amdgpu_device *adev = ring->adev; -u32 inst_id = ring->me;int r; +if (amdgpu_sriov_vf (adev)) +return -EINVAL ; + +if (ring->me >= adev->sdma.num_instances) { +DRM_ERROR ("sdma instance not found\n" ); +return -EINVAL ; + } + +amdgpu_ring_reset_helper_begin (ring, timedout_fence); +amdgpu_amdkfd_suspend (adev, true); - r =amdgpu_sdma_reset_engine (adev, inst_id, false); + r =amdgpu_sdma_reset_engine (adev, ring->me, true);amdgpu_amdkfd_resume (adev, true); +if (r) +return r; -return r; +return amdgpu_ring_reset_helper_end (ring, timedout_fence); }static int sdma_v5_0_stop_queue (struct amdgpu_ring *ring)
Signature · 1 line
2.50.0
Re: [PATCH 09/28] drm/amdgpu/sdma5: re-emit unprocessed state on ring reset
Quoted 15 lines · Alex Deucher
Re-emit the unprocessed state after resetting the queue.
Signed-off-by Alex Deucher <[email protected]>--- drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c +0
-0@@ -1544,14 +1544,25 @@ static int sdma_v5_0_reset_queue(struct amdgpu_ring *ring, struct amdgpu_fence *timedout_fence) {struct amdgpu_device *adev = ring->adev;
drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c static int sdma_v5_0_reset_queue(struct amdgpu_ring *ring, · line 1555
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c +7
-1-u32 inst_id = ring->me;int r; +if (amdgpu_sriov_vf (adev)) +return -EINVAL ; + +if (ring->me >= adev->sdma.num_instances) { +DRM_ERROR ("sdma instance not found\n" ); +return -EINVAL ; + }
Nitpick:
Are these checks part of this commit? I noticed you made a similar modification in the next commit. Maybe you can put these checks in a single commit before this one?
Thanks
Quoted 18 lines
drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c +7
-2+ +amdgpu_ring_reset_helper_begin (ring, timedout_fence); +amdgpu_amdkfd_suspend (adev, true); - r =amdgpu_sdma_reset_engine (adev, inst_id, false); + r =amdgpu_sdma_reset_engine (adev, ring->me, true);amdgpu_amdkfd_resume (adev, true); +if (r) +return r; -return r; +return amdgpu_ring_reset_helper_end (ring, timedout_fence); }static int sdma_v5_0_stop_queue (struct amdgpu_ring *ring)Signature · 1 line
2.50.0
Signature · 1 line
Rodrigo Siqueira
Alex Deucher
maintainerPATCH v13 10/28 drm/amdgpu/sdma5.2: re-emit unprocessed state on ring reset
In reply to Alex DeucherRe-emit the unprocessed state after resetting the queue.
--- drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c +14 -3
@@ -1457,14 +1457,25 @@ static int sdma_v5_2_reset_queue(struct amdgpu_ring *ring, struct amdgpu_fence *timedout_fence) {struct amdgpu_device *adev = ring->adev; -u32 inst_id = ring->me;int r; +if (amdgpu_sriov_vf (adev)) +return -EINVAL ; + +if (ring->me >= adev->sdma.num_instances) { +DRM_ERROR ("sdma instance not found\n" ); +return -EINVAL ; + } + +amdgpu_ring_reset_helper_begin (ring, timedout_fence); +amdgpu_amdkfd_suspend (adev, true); - r =amdgpu_sdma_reset_engine (adev, inst_id, false); + r =amdgpu_sdma_reset_engine (adev, ring->me, true);amdgpu_amdkfd_resume (adev, true); +if (r) +return r; -return r; +return amdgpu_ring_reset_helper_end (ring, timedout_fence); }static int sdma_v5_2_stop_queue (struct amdgpu_ring *ring)
Signature · 1 line
2.50.0
Alex Deucher
maintainerPATCH v13 11/28 drm/amdgpu/sdma6: re-emit unprocessed state on ring reset
In reply to Alex DeucherRe-emit the unprocessed state after resetting the queue.
--- drivers/gpu/drm/amd/amdgpu/sdma_v6_0.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-)
drivers/gpu/drm/amd/amdgpu/sdma_v6_0.c +6 -12
@@ -1575,33 +1575,27 @@ static int sdma_v6_0_reset_queue(struct amdgpu_ring *ring, struct amdgpu_fence *timedout_fence) {struct amdgpu_device *adev = ring->adev; -int i, r; +int r;if (amdgpu_sriov_vf (adev))return -EINVAL ; -for (i =0 ; i < adev->sdma.num_instances; i++) { -if (ring == &adev->sdma.instance[i].ring) -break ; - } - -if (i == adev->sdma.num_instances) { +if (ring->me >= adev->sdma.num_instances) {DRM_ERROR ("sdma instance not found\n" );return -EINVAL ; } -drm_sched_wqueue_stop (&ring->sched); +amdgpu_ring_reset_helper_begin (ring, timedout_fence); r =amdgpu_mes_reset_legacy_queue (adev, ring, vmid, true);if (r)return r; - r =sdma_v6_0_gfx_resume_instance (adev, i, true); + r =sdma_v6_0_gfx_resume_instance (adev, ring->me, true);if (r)return r; -amdgpu_fence_driver_force_completion (ring); -drm_sched_wqueue_start (&ring->sched); -return 0 ; + +return amdgpu_ring_reset_helper_end (ring, timedout_fence); } static int sdma_v6_0_set_trap_irq_state(struct amdgpu_device *adev,
Signature · 1 line
2.50.0
Alex Deucher
maintainerPATCH v13 12/28 drm/amdgpu/sdma7: re-emit unprocessed state on ring reset
In reply to Alex DeucherRe-emit the unprocessed state after resetting the queue.
--- drivers/gpu/drm/amd/amdgpu/sdma_v7_0.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-)
drivers/gpu/drm/amd/amdgpu/sdma_v7_0.c +6 -12
@@ -807,33 +807,27 @@ static int sdma_v7_0_reset_queue(struct amdgpu_ring *ring, struct amdgpu_fence *timedout_fence) {struct amdgpu_device *adev = ring->adev; -int i, r; +int r;if (amdgpu_sriov_vf (adev))return -EINVAL ; -for (i =0 ; i < adev->sdma.num_instances; i++) { -if (ring == &adev->sdma.instance[i].ring) -break ; - } - -if (i == adev->sdma.num_instances) { +if (ring->me >= adev->sdma.num_instances) {DRM_ERROR ("sdma instance not found\n" );return -EINVAL ; } -drm_sched_wqueue_stop (&ring->sched); +amdgpu_ring_reset_helper_begin (ring, timedout_fence); r =amdgpu_mes_reset_legacy_queue (adev, ring, vmid, true);if (r)return r; - r =sdma_v7_0_gfx_resume_instance (adev, i, true); + r =sdma_v7_0_gfx_resume_instance (adev, ring->me, true);if (r)return r; -amdgpu_fence_driver_force_completion (ring); -drm_sched_wqueue_start (&ring->sched); -return 0 ; + +return amdgpu_ring_reset_helper_end (ring, timedout_fence); }/**
Signature · 1 line
2.50.0
RE: [PATCH 12/28] drm/amdgpu/sdma7: re-emit unprocessed state on ring reset
[AMD Official Use Only - AMD Internal Distribution Only]
this patch is Reviewed-by: Jesse Zhang <[email protected]>
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Alex Deucher
Sent: Wednesday, July 2, 2025 2:45 AM
To: [email protected]; Koenig, Christian <[email protected]>; Sundararaju, Sathishkumar <[email protected]>
Cc: Deucher, Alexander <[email protected]>
Subject: [PATCH 12/28] drm/amdgpu/sdma7: re-emit unprocessed state on ring reset
Re-emit the unprocessed state after resetting the queue.
--- drivers/gpu/drm/amd/amdgpu/sdma_v7_0.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-)
drivers/gpu/drm/amd/amdgpu/sdma_v7_0.c +6 -13
@@ -807,33 +807,27 @@ static int sdma_v7_0_reset_queue(struct amdgpu_ring *ring, struct amdgpu_fence *timedout_fence) {struct amdgpu_device *adev = ring->adev; -int i, r; +int r;if (amdgpu_sriov_vf (adev))return -EINVAL ; -for (i =0 ; i < adev->sdma.num_instances; i++) { -if (ring == &adev->sdma.instance[i].ring) -break ; - } - -if (i == adev->sdma.num_instances) { +if (ring->me >= adev->sdma.num_instances) {DRM_ERROR ("sdma instance not found\n" );return -EINVAL ; } -drm_sched_wqueue_stop (&ring->sched); +amdgpu_ring_reset_helper_begin (ring, timedout_fence); r =amdgpu_mes_reset_legacy_queue (adev, ring, vmid, true);if (r)return r; - r =sdma_v7_0_gfx_resume_instance (adev, i, true); + r =sdma_v7_0_gfx_resume_instance (adev, ring->me, true);if (r)return r; -amdgpu_fence_driver_force_completion (ring); -drm_sched_wqueue_start (&ring->sched); -return 0 ; + +return amdgpu_ring_reset_helper_end (ring, timedout_fence); }/** --
2.50.0
Alex Deucher
maintainerPATCH v13 13/28 drm/amdgpu/jpeg2: re-emit unprocessed state on ring reset
In reply to Alex DeucherRe-emit the unprocessed state after resetting the queue.
--- drivers/gpu/drm/amd/amdgpu/jpeg_v2_0.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-)
drivers/gpu/drm/amd/amdgpu/jpeg_v2_0.c +2 -9
@@ -768,17 +768,10 @@ static int jpeg_v2_0_ring_reset(struct amdgpu_ring *ring,unsigned int vmid, struct amdgpu_fence *timedout_fence) { - int r; - -drm_sched_wqueue_stop (&ring->sched); +amdgpu_ring_reset_helper_begin (ring ,timedout_fence );jpeg_v2_0_stop (ring->adev);jpeg_v2_0_start (ring->adev); - r =amdgpu_ring_test_helper (ring); -if (r) -return r; -amdgpu_fence_driver_force_completion (ring); -drm_sched_wqueue_start (&ring->sched); -return 0 ; +return amdgpu_ring_reset_helper_end (ring, timedout_fence); } static const struct amd_ip_funcs jpeg_v2_0_ip_funcs = {
Signature · 1 line
2.50.0
Alex Deucher
maintainerPATCH v13 14/28 drm/amdgpu/jpeg2.5: re-emit unprocessed state on ring reset
In reply to Alex DeucherRe-emit the unprocessed state after resetting the queue.
--- drivers/gpu/drm/amd/amdgpu/jpeg_v2_5.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-)
drivers/gpu/drm/amd/amdgpu/jpeg_v2_5.c +2 -9
@@ -647,17 +647,10 @@ static int jpeg_v2_5_ring_reset(struct amdgpu_ring *ring,unsigned int vmid, struct amdgpu_fence *timedout_fence) { - int r; - -drm_sched_wqueue_stop (&ring->sched); +amdgpu_ring_reset_helper_begin (ring ,timedout_fence );jpeg_v2_5_stop_inst (ring->adev, ring->me);jpeg_v2_5_start_inst (ring->adev, ring->me); - r =amdgpu_ring_test_helper (ring); -if (r) -return r; -amdgpu_fence_driver_force_completion (ring); -drm_sched_wqueue_start (&ring->sched); -return 0 ; +return amdgpu_ring_reset_helper_end (ring, timedout_fence); } static const struct amd_ip_funcs jpeg_v2_5_ip_funcs = {
Signature · 1 line
2.50.0
Alex Deucher
maintainerPATCH v13 15/28 drm/amdgpu/jpeg3: re-emit unprocessed state on ring reset
In reply to Alex DeucherRe-emit the unprocessed state after resetting the queue.
--- drivers/gpu/drm/amd/amdgpu/jpeg_v3_0.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-)
drivers/gpu/drm/amd/amdgpu/jpeg_v3_0.c +2 -9
@@ -559,17 +559,10 @@ static int jpeg_v3_0_ring_reset(struct amdgpu_ring *ring,unsigned int vmid, struct amdgpu_fence *timedout_fence) { - int r; - -drm_sched_wqueue_stop (&ring->sched); +amdgpu_ring_reset_helper_begin (ring ,timedout_fence );jpeg_v3_0_stop (ring->adev);jpeg_v3_0_start (ring->adev); - r =amdgpu_ring_test_helper (ring); -if (r) -return r; -amdgpu_fence_driver_force_completion (ring); -drm_sched_wqueue_start (&ring->sched); -return 0 ; +return amdgpu_ring_reset_helper_end (ring, timedout_fence); } static const struct amd_ip_funcs jpeg_v3_0_ip_funcs = {
Signature · 1 line
2.50.0
Alex Deucher
maintainerPATCH v13 16/28 drm/amdgpu/jpeg4: re-emit unprocessed state on ring reset
In reply to Alex DeucherRe-emit the unprocessed state after resetting the queue.
--- drivers/gpu/drm/amd/amdgpu/jpeg_v4_0.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-)
drivers/gpu/drm/amd/amdgpu/jpeg_v4_0.c +2 -9
@@ -724,20 +724,13 @@ static int jpeg_v4_0_ring_reset(struct amdgpu_ring *ring, unsigned int vmid, struct amdgpu_fence *timedout_fence) { - int r; - if (amdgpu_sriov_vf(ring->adev)) return -EINVAL; -drm_sched_wqueue_stop (&ring->sched); +amdgpu_ring_reset_helper_begin (ring, timedout_fence);jpeg_v4_0_stop (ring->adev);jpeg_v4_0_start (ring->adev); - r =amdgpu_ring_test_helper (ring); -if (r) -return r; -amdgpu_fence_driver_force_completion (ring); -drm_sched_wqueue_start (&ring->sched); -return 0 ; +return amdgpu_ring_reset_helper_end (ring, timedout_fence); } static const struct amd_ip_funcs jpeg_v4_0_ip_funcs = {
Signature · 1 line
2.50.0
Alex Deucher
maintainerPATCH v13 17/28 drm/amdgpu/jpeg4.0.3: re-emit unprocessed state on ring reset
In reply to Alex DeucherRe-emit the unprocessed state after resetting the queue.
--- drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_3.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-)
drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_3.c +2 -9
@@ -1147,20 +1147,13 @@ static int jpeg_v4_0_3_ring_reset(struct amdgpu_ring *ring, unsigned int vmid, struct amdgpu_fence *timedout_fence) { - int r; - if (amdgpu_sriov_vf(ring->adev)) return -EOPNOTSUPP; -drm_sched_wqueue_stop (&ring->sched); +amdgpu_ring_reset_helper_begin (ring, timedout_fence);jpeg_v4_0_3_core_stall_reset (ring);jpeg_v4_0_3_start_jrbc (ring); - r =amdgpu_ring_test_helper (ring); -if (r) -return r; -amdgpu_fence_driver_force_completion (ring); -drm_sched_wqueue_start (&ring->sched); -return 0 ; +return amdgpu_ring_reset_helper_end (ring, timedout_fence); } static const struct amd_ip_funcs jpeg_v4_0_3_ip_funcs = {
Signature · 1 line
2.50.0
Alex Deucher
maintainerPATCH v13 18/28 drm/amdgpu/jpeg4.0.5: add queue reset
In reply to Alex DeucherAdd queue reset support for jpeg 4.0.5.
Use the new helpers to re-emit the unprocessed state after resetting the queue.
--- drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_5.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_5.c +11 -0
@@ -767,6 +767,16 @@ static int jpeg_v4_0_5_process_interrupt(struct amdgpu_device *adev,return 0 ; } +static int jpeg_v4_0_5_ring_reset (struct amdgpu_ring *ring, +unsigned int vmid, +struct amdgpu_fence *timedout_fence) +{ +amdgpu_ring_reset_helper_begin (ring, timedout_fence); +jpeg_v4_0_5_stop (ring->adev); +jpeg_v4_0_5_start (ring->adev); +return amdgpu_ring_reset_helper_end (ring, timedout_fence); +} +static const struct amd_ip_funcs jpeg_v4_0_5_ip_funcs = { .name ="jpeg_v4_0_5" , .early_init = jpeg_v4_0_5_early_init,
@@ -812,6 +822,7 @@ static const struct amdgpu_ring_funcs jpeg_v4_0_5_dec_ring_vm_funcs = { .emit_wreg = jpeg_v2_0_dec_ring_emit_wreg, .emit_reg_wait = jpeg_v2_0_dec_ring_emit_reg_wait, .emit_reg_write_reg_wait = amdgpu_ring_emit_reg_write_reg_wait_helper, + .reset = jpeg_v4_0_5_ring_reset, };static void jpeg_v4_0_5_set_dec_ring_funcs (struct amdgpu_device *adev)
Signature · 1 line
2.50.0
Re: [PATCH 18/28] drm/amdgpu/jpeg4.0.5: add queue reset
Quoted 16 lines · Alex Deucher
Add queue reset support for jpeg 4.0.5.
Use the new helpers to re-emit the unprocessed state after resetting the queue.Reviewed-by Sathishkumar S <[email protected]>Tested-by Sathishkumar S <[email protected]>Signed-off-by Alex Deucher <[email protected]>--- drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_5.c | 11 +++++++++++ 1 file changed, 11 insertions(+)drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_5.c +0
-0
drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_5.c static int jpeg_v4_0_5_process_interrupt(struct amdgpu_device *adev, · line 776
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_5.c +7
-0@@ -767,6 +767,16 @@ static int jpeg_v4_0_5_process_interrupt(struct amdgpu_device *adev,return 0 ; } +static int jpeg_v4_0_5_ring_reset (struct amdgpu_ring *ring, +unsigned int vmid, +struct amdgpu_fence *timedout_fence) +{ +amdgpu_ring_reset_helper_begin (ring, timedout_fence); +jpeg_v4_0_5_stop (ring->adev); +jpeg_v4_0_5_start (ring->adev);
Stop and start return values in case of errors. Maybe you can add a check here? If something goes wrong, you can add a log message.
Thanks
Quoted 17 lines
drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_5.c +4
-0+return amdgpu_ring_reset_helper_end (ring, timedout_fence); +} +static const struct amd_ip_funcs jpeg_v4_0_5_ip_funcs = { .name ="jpeg_v4_0_5" , .early_init = jpeg_v4_0_5_early_init,@@ -812,6 +822,7 @@ static const struct amdgpu_ring_funcs jpeg_v4_0_5_dec_ring_vm_funcs = { .emit_wreg = jpeg_v2_0_dec_ring_emit_wreg, .emit_reg_wait = jpeg_v2_0_dec_ring_emit_reg_wait, .emit_reg_write_reg_wait = amdgpu_ring_emit_reg_write_reg_wait_helper, + .reset = jpeg_v4_0_5_ring_reset, };static void jpeg_v4_0_5_set_dec_ring_funcs (struct amdgpu_device *adev)Signature · 1 line
2.50.0
Signature · 1 line
Rodrigo Siqueira
Alex Deucher
maintainerPATCH v13 19/28 drm/amdgpu/jpeg5: add queue reset
In reply to Alex DeucherAdd queue reset support for jpeg 5.0.0.
Use the new helpers to re-emit the unprocessed state after resetting the queue.
--- drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_0.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_0.c +14 -0
@@ -644,6 +644,19 @@ static int jpeg_v5_0_0_process_interrupt(struct amdgpu_device *adev,return 0 ; } +static int jpeg_v5_0_0_ring_reset (struct amdgpu_ring *ring, +unsigned int vmid, +struct amdgpu_fence *timedout_fence) +{ +if (amdgpu_sriov_vf (ring->adev)) +return -EINVAL ; + +amdgpu_ring_reset_helper_begin (ring, timedout_fence); +jpeg_v5_0_0_stop (ring->adev); +jpeg_v5_0_0_start (ring->adev); +return amdgpu_ring_reset_helper_end (ring, timedout_fence); +} +static const struct amd_ip_funcs jpeg_v5_0_0_ip_funcs = { .name ="jpeg_v5_0_0" , .early_init = jpeg_v5_0_0_early_init,
@@ -689,6 +702,7 @@ static const struct amdgpu_ring_funcs jpeg_v5_0_0_dec_ring_vm_funcs = { .emit_wreg = jpeg_v4_0_3_dec_ring_emit_wreg, .emit_reg_wait = jpeg_v4_0_3_dec_ring_emit_reg_wait, .emit_reg_write_reg_wait = amdgpu_ring_emit_reg_write_reg_wait_helper, + .reset = jpeg_v5_0_0_ring_reset, };static void jpeg_v5_0_0_set_dec_ring_funcs (struct amdgpu_device *adev)
Signature · 1 line
2.50.0
Alex Deucher
maintainerPATCH v13 20/28 drm/amdgpu/jpeg5.0.1: re-emit unprocessed state on ring reset
In reply to Alex DeucherRe-emit the unprocessed state after resetting the queue.
--- drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_1.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-)
drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_1.c +2 -9
@@ -838,20 +838,13 @@ static int jpeg_v5_0_1_ring_reset(struct amdgpu_ring *ring, unsigned int vmid, struct amdgpu_fence *timedout_fence) { - int r; - if (amdgpu_sriov_vf(ring->adev)) return -EOPNOTSUPP; -drm_sched_wqueue_stop (&ring->sched); +amdgpu_ring_reset_helper_begin (ring, timedout_fence);jpeg_v5_0_1_core_stall_reset (ring);jpeg_v5_0_1_init_jrbc (ring); - r =amdgpu_ring_test_helper (ring); -if (r) -return r; -amdgpu_fence_driver_force_completion (ring); -drm_sched_wqueue_start (&ring->sched); -return 0 ; +return amdgpu_ring_reset_helper_end (ring, timedout_fence); } static const struct amd_ip_funcs jpeg_v5_0_1_ip_funcs = {
Signature · 1 line
2.50.0
Alex Deucher
maintainerPATCH v13 21/28 drm/amdgpu/vcn4: re-emit unprocessed state on ring reset
In reply to Alex DeucherRe-emit the unprocessed state after resetting the queue.
--- drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-)
drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c +2 -9
@@ -1973,21 +1973,14 @@ static int vcn_v4_0_ring_reset(struct amdgpu_ring *ring, {struct amdgpu_device *adev = ring->adev;struct amdgpu_vcn_inst *vinst = &adev->vcn.inst[ring->me]; -int r;if (!(adev->vcn.supported_reset &AMDGPU_RESET_TYPE_PER_QUEUE ))return -EOPNOTSUPP ; -drm_sched_wqueue_stop (&ring->sched); +amdgpu_ring_reset_helper_begin (ring, timedout_fence);vcn_v4_0_stop (vinst);vcn_v4_0_start (vinst); - - r =amdgpu_ring_test_helper (ring); -if (r) -return r; -amdgpu_fence_driver_force_completion (ring); -drm_sched_wqueue_start (&ring->sched); -return 0 ; +return amdgpu_ring_reset_helper_end (ring, timedout_fence); }static struct amdgpu_ring_funcs vcn_v4_0_unified_ring_vm_funcs = {
Signature · 1 line
2.50.0
Alex Deucher
maintainerPATCH v13 22/28 drm/amdgpu/vcn4.0.3: re-emit unprocessed state on ring reset
In reply to Alex DeucherRe-emit the unprocessed state after resetting the queue.
--- drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)
drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c +3 -7
@@ -1609,7 +1609,7 @@ static int vcn_v4_0_3_ring_reset(struct amdgpu_ring *ring,if (!(adev->vcn.supported_reset &AMDGPU_RESET_TYPE_PER_QUEUE ))return -EOPNOTSUPP ; -drm_sched_wqueue_stop (&ring->sched); +amdgpu_ring_reset_helper_begin (ring, timedout_fence); vcn_inst =GET_INST (VCN , ring->me); r =amdgpu_dpm_reset_vcn (adev,1 << vcn_inst);
@@ -1624,12 +1624,8 @@ static int vcn_v4_0_3_ring_reset(struct amdgpu_ring *ring, adev->vcn.caps |=AMDGPU_VCN_CAPS (RRMT_ENABLED );vcn_v4_0_3_hw_init_inst (vinst);vcn_v4_0_3_start_dpg_mode (vinst, adev->vcn.inst[ring->me].indirect_sram); - r =amdgpu_ring_test_helper (ring); -if (r) -return r; -amdgpu_fence_driver_force_completion (ring); -drm_sched_wqueue_start (&ring->sched); -return 0 ; + +return amdgpu_ring_reset_helper_end (ring, timedout_fence); }static const struct amdgpu_ring_funcs vcn_v4_0_3_unified_ring_vm_funcs = {
Signature · 1 line
2.50.0
Alex Deucher
maintainerPATCH v13 23/28 drm/amdgpu/vcn4.0.5: re-emit unprocessed state on ring reset
In reply to Alex DeucherRe-emit the unprocessed state after resetting the queue.
--- drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-)
drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.c +2 -9
@@ -1471,21 +1471,14 @@ static int vcn_v4_0_5_ring_reset(struct amdgpu_ring *ring, {struct amdgpu_device *adev = ring->adev;struct amdgpu_vcn_inst *vinst = &adev->vcn.inst[ring->me]; -int r;if (!(adev->vcn.supported_reset &AMDGPU_RESET_TYPE_PER_QUEUE ))return -EOPNOTSUPP ; -drm_sched_wqueue_stop (&ring->sched); +amdgpu_ring_reset_helper_begin (ring, timedout_fence);vcn_v4_0_5_stop (vinst);vcn_v4_0_5_start (vinst); - - r =amdgpu_ring_test_helper (ring); -if (r) -return r; -amdgpu_fence_driver_force_completion (ring); -drm_sched_wqueue_start (&ring->sched); -return 0 ; +return amdgpu_ring_reset_helper_end (ring, timedout_fence); }static struct amdgpu_ring_funcs vcn_v4_0_5_unified_ring_vm_funcs = {
Signature · 1 line
2.50.0
Alex Deucher
maintainerPATCH v13 24/28 drm/amdgpu/vcn5: re-emit unprocessed state on ring reset
In reply to Alex DeucherRe-emit the unprocessed state after resetting the queue.
--- drivers/gpu/drm/amd/amdgpu/vcn_v5_0_0.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-)
drivers/gpu/drm/amd/amdgpu/vcn_v5_0_0.c +2 -9
@@ -1198,21 +1198,14 @@ static int vcn_v5_0_0_ring_reset(struct amdgpu_ring *ring, {struct amdgpu_device *adev = ring->adev;struct amdgpu_vcn_inst *vinst = &adev->vcn.inst[ring->me]; -int r;if (!(adev->vcn.supported_reset &AMDGPU_RESET_TYPE_PER_QUEUE ))return -EOPNOTSUPP ; -drm_sched_wqueue_stop (&ring->sched); +amdgpu_ring_reset_helper_begin (ring, timedout_fence);vcn_v5_0_0_stop (vinst);vcn_v5_0_0_start (vinst); - - r =amdgpu_ring_test_helper (ring); -if (r) -return r; -amdgpu_fence_driver_force_completion (ring); -drm_sched_wqueue_start (&ring->sched); -return 0 ; +return amdgpu_ring_reset_helper_end (ring, timedout_fence); }static const struct amdgpu_ring_funcs vcn_v5_0_0_unified_ring_vm_funcs = {
Signature · 1 line
2.50.0
Alex Deucher
maintainerPATCH v13 25/28 drm/amdgpu/vcn: add a helper framework for engine resets
In reply to Alex DeucherWith engine resets we reset all queues on the engine rather than just a single queue. Add a framework to handle this similar to SDMA.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c | 76 +++++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h | 6 +- 2 files changed, 81 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +76 -0
@@ -134,6 +134,7 @@ int amdgpu_vcn_sw_init(struct amdgpu_device *adev, int i)mutex_init (&adev->vcn.inst[i].vcn1_jpeg1_workaround);mutex_init (&adev->vcn.inst[i].vcn_pg_lock); +mutex_init (&adev->vcn.inst[i].engine_reset_mutex);atomic_set (&adev->vcn.inst[i].total_submission_cnt,0 );INIT_DELAYED_WORK (&adev->vcn.inst[i].idle_work, amdgpu_vcn_idle_work_handler);atomic_set (&adev->vcn.inst[i].dpg_enc_submission_cnt,0 );
@@ -1451,3 +1452,78 @@ int vcn_set_powergating_state(struct amdgpu_ip_block *ip_block,return ret; } + +/** +* amdgpu_vcn_reset_engine - Reset a specific VCN engine +* @adev: Pointer to the AMDGPU device +* @instance_id: VCN engine instance to reset +* +* Returns: 0 on success, or a negative error code on failure. +*/ +static int amdgpu_vcn_reset_engine (struct amdgpu_device *adev, +uint32_t instance_id) +{ +struct amdgpu_vcn_inst *vinst = &adev->vcn.inst[instance_id]; +int r, i; + +mutex_lock (&vinst->engine_reset_mutex); +/* Stop the scheduler's work queue for the dec and enc rings if they are running. +* This ensures that no new tasks are submitted to the queues while +* the reset is in progress. +*/ +drm_sched_wqueue_stop (&vinst->ring_dec.sched); +for (i =0 ; i < vinst->num_enc_rings; i++) +drm_sched_wqueue_stop (&vinst->ring_enc[i].sched); + +/* Perform the VCN reset for the specified instance */ + r = vinst->reset (vinst); +if (r) + goto unlock; + r =amdgpu_ring_test_ring (&vinst->ring_dec); +if (r) + goto unlock; +for (i =0 ; i < vinst->num_enc_rings; i++) { + r =amdgpu_ring_test_ring (&vinst->ring_enc[i]); +if (r) + goto unlock; + } +amdgpu_fence_driver_force_completion (&vinst->ring_dec); +for (i =0 ; i < vinst->num_enc_rings; i++) +amdgpu_fence_driver_force_completion (&vinst->ring_enc[i]); + +/* Restart the scheduler's work queue for the dec and enc rings +* if they were stopped by this function. This allows new tasks +* to be submitted to the queues after the reset is complete. +*/ +drm_sched_wqueue_start (&vinst->ring_dec.sched); +for (i =0 ; i < vinst->num_enc_rings; i++) +drm_sched_wqueue_start (&vinst->ring_enc[i].sched); + +unlock: +mutex_unlock (&vinst->engine_reset_mutex); + +return r; +} + +/** +* amdgpu_vcn_ring_reset - Reset a VCN ring +* @ring: ring to reset +* @vmid: vmid of guilty job +* @timedout_fence: fence of timed out job +* +* This helper is for VCN blocks without unified queues because +* resetting the engine resets all queues in that case. With +* unified queues we have one queue per engine. +* Returns: 0 on success, or a negative error code on failure. +*/ +int amdgpu_vcn_ring_reset (struct amdgpu_ring *ring, +unsigned int vmid, +struct amdgpu_fence *timedout_fence) +{ +struct amdgpu_device *adev = ring->adev; + +if (adev->vcn.inst[ring->me].using_unified_queue) +return -EINVAL ; + +return amdgpu_vcn_reset_engine (adev, ring->me); +}
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h +5 -1
@@ -330,7 +330,9 @@ struct amdgpu_vcn_inst { struct dpg_pause_state *new_state);int (*set_pg_state)(struct amdgpu_vcn_inst *vinst,enum amd_powergating_state state); +int (*reset)(struct amdgpu_vcn_inst *vinst);bool using_unified_queue; +struct mutex engine_reset_mutex; };struct amdgpu_vcn_ras {
@@ -552,5 +554,7 @@ void amdgpu_debugfs_vcn_sched_mask_init(struct amdgpu_device *adev);int vcn_set_powergating_state (struct amdgpu_ip_block *ip_block,enum amd_powergating_state state); - +int amdgpu_vcn_ring_reset (struct amdgpu_ring *ring, +unsigned int vmid, +struct amdgpu_fence *guilty_fence);#endif
Signature · 1 line
2.50.0
Alex Deucher
maintainerPATCH v13 26/28 drm/amdgpu/vcn2: implement ring reset
In reply to Alex DeucherUse the new helpers to handle engine resets for VCN.
--- drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c +12 -0
@@ -98,6 +98,8 @@ static int vcn_v2_0_set_pg_state(struct amdgpu_vcn_inst *vinst,static int vcn_v2_0_pause_dpg_mode (struct amdgpu_vcn_inst *vinst,struct dpg_pause_state *new_state);static int vcn_v2_0_start_sriov (struct amdgpu_device *adev); +static int vcn_v2_0_reset (struct amdgpu_vcn_inst *vinst); +/** * vcn_v2_0_early_init - set function pointers and load microcode *
@@ -213,6 +215,7 @@ static int vcn_v2_0_sw_init(struct amdgpu_ip_block *ip_block) } adev->vcn.inst[0 ].pause_dpg_mode = vcn_v2_0_pause_dpg_mode; + adev->vcn.inst[0 ].reset = vcn_v2_0_reset; r =amdgpu_virt_alloc_mm_table (adev);if (r)
@@ -1355,6 +1358,13 @@ static int vcn_v2_0_pause_dpg_mode(struct amdgpu_vcn_inst *vinst,return 0 ; } +static int vcn_v2_0_reset (struct amdgpu_vcn_inst *vinst) +{ +vcn_v2_0_stop (vinst); +vcn_v2_0_start (vinst); +return 0 ; +} +static bool vcn_v2_0_is_idle (struct amdgpu_ip_block *ip_block) {struct amdgpu_device *adev = ip_block->adev;
@@ -2176,6 +2186,7 @@ static const struct amdgpu_ring_funcs vcn_v2_0_dec_ring_vm_funcs = { .emit_wreg = vcn_v2_0_dec_ring_emit_wreg, .emit_reg_wait = vcn_v2_0_dec_ring_emit_reg_wait, .emit_reg_write_reg_wait = amdgpu_ring_emit_reg_write_reg_wait_helper, + .reset = amdgpu_vcn_ring_reset, };static const struct amdgpu_ring_funcs vcn_v2_0_enc_ring_vm_funcs = {
@@ -2205,6 +2216,7 @@ static const struct amdgpu_ring_funcs vcn_v2_0_enc_ring_vm_funcs = { .emit_wreg = vcn_v2_0_enc_ring_emit_wreg, .emit_reg_wait = vcn_v2_0_enc_ring_emit_reg_wait, .emit_reg_write_reg_wait = amdgpu_ring_emit_reg_write_reg_wait_helper, + .reset = amdgpu_vcn_ring_reset, };static void vcn_v2_0_set_dec_ring_funcs (struct amdgpu_device *adev)
Signature · 1 line
2.50.0
Alex Deucher
maintainerPATCH v13 27/28 drm/amdgpu/vcn2.5: implement ring reset
In reply to Alex DeucherUse the new helpers to handle engine resets for VCN.
--- drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c +11 -0
@@ -102,6 +102,7 @@ static int vcn_v2_5_pause_dpg_mode(struct amdgpu_vcn_inst *vinst, struct dpg_pause_state *new_state);static int vcn_v2_5_sriov_start (struct amdgpu_device *adev);static void vcn_v2_5_set_ras_funcs (struct amdgpu_device *adev); +static int vcn_v2_5_reset (struct amdgpu_vcn_inst *vinst);static int amdgpu_ih_clientid_vcns[] = {SOC15_IH_CLIENTID_VCN ,
@@ -404,6 +405,7 @@ static int vcn_v2_5_sw_init(struct amdgpu_ip_block *ip_block)if (adev->pg_flags &AMD_PG_SUPPORT_VCN_DPG ) adev->vcn.inst[j].pause_dpg_mode = vcn_v2_5_pause_dpg_mode; + adev->vcn.inst[j].reset = vcn_v2_5_reset; }if (amdgpu_sriov_vf (adev)) {
@@ -1816,6 +1818,7 @@ static const struct amdgpu_ring_funcs vcn_v2_5_dec_ring_vm_funcs = { .emit_wreg = vcn_v2_0_dec_ring_emit_wreg, .emit_reg_wait = vcn_v2_0_dec_ring_emit_reg_wait, .emit_reg_write_reg_wait = amdgpu_ring_emit_reg_write_reg_wait_helper, + .reset = amdgpu_vcn_ring_reset, };/**
@@ -1914,6 +1917,7 @@ static const struct amdgpu_ring_funcs vcn_v2_5_enc_ring_vm_funcs = { .emit_wreg = vcn_v2_0_enc_ring_emit_wreg, .emit_reg_wait = vcn_v2_0_enc_ring_emit_reg_wait, .emit_reg_write_reg_wait = amdgpu_ring_emit_reg_write_reg_wait_helper, + .reset = amdgpu_vcn_ring_reset, };static void vcn_v2_5_set_dec_ring_funcs (struct amdgpu_device *adev)
@@ -1942,6 +1946,13 @@ static void vcn_v2_5_set_enc_ring_funcs(struct amdgpu_device *adev) } } +static int vcn_v2_5_reset (struct amdgpu_vcn_inst *vinst) +{ +vcn_v2_5_stop (vinst); +vcn_v2_5_start (vinst); +return 0 ; +} +static bool vcn_v2_5_is_idle (struct amdgpu_ip_block *ip_block) {struct amdgpu_device *adev = ip_block->adev;
Signature · 1 line
2.50.0
Alex Deucher
maintainerPATCH v13 28/28 drm/amdgpu/vcn3: implement ring reset
In reply to Alex DeucherUse the new helpers to handle engine resets for VCN.
--- drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c +13 -0
@@ -110,6 +110,7 @@ static int vcn_v3_0_set_pg_state(struct amdgpu_vcn_inst *vinst, enum amd_powergating_state state);static int vcn_v3_0_pause_dpg_mode (struct amdgpu_vcn_inst *vinst,struct dpg_pause_state *new_state); +static int vcn_v3_0_reset (struct amdgpu_vcn_inst *vinst);static void vcn_v3_0_dec_ring_set_wptr (struct amdgpu_ring *ring);static void vcn_v3_0_enc_ring_set_wptr (struct amdgpu_ring *ring);
@@ -289,6 +290,7 @@ static int vcn_v3_0_sw_init(struct amdgpu_ip_block *ip_block)if (adev->pg_flags &AMD_PG_SUPPORT_VCN_DPG ) adev->vcn.inst[i].pause_dpg_mode = vcn_v3_0_pause_dpg_mode; + adev->vcn.inst[i].reset = vcn_v3_0_reset; }if (amdgpu_sriov_vf (adev)) {
@@ -2033,6 +2035,7 @@ static const struct amdgpu_ring_funcs vcn_v3_0_dec_ring_vm_funcs = { .emit_wreg = vcn_v2_0_dec_ring_emit_wreg, .emit_reg_wait = vcn_v2_0_dec_ring_emit_reg_wait, .emit_reg_write_reg_wait = amdgpu_ring_emit_reg_write_reg_wait_helper, + .reset = amdgpu_vcn_ring_reset, };/**
@@ -2131,6 +2134,7 @@ static const struct amdgpu_ring_funcs vcn_v3_0_enc_ring_vm_funcs = { .emit_wreg = vcn_v2_0_enc_ring_emit_wreg, .emit_reg_wait = vcn_v2_0_enc_ring_emit_reg_wait, .emit_reg_write_reg_wait = amdgpu_ring_emit_reg_write_reg_wait_helper, + .reset = amdgpu_vcn_ring_reset, };static void vcn_v3_0_set_dec_ring_funcs (struct amdgpu_device *adev)
@@ -2164,6 +2168,15 @@ static void vcn_v3_0_set_enc_ring_funcs(struct amdgpu_device *adev) } } +static int vcn_v3_0_reset (struct amdgpu_vcn_inst *vinst) +{ +vcn_v3_0_stop (vinst); +vcn_v3_0_enable_clock_gating (vinst); +vcn_v3_0_enable_static_power_gating (vinst); +vcn_v3_0_start (vinst); +return 0 ; +} +static bool vcn_v3_0_is_idle (struct amdgpu_ip_block *ip_block) {struct amdgpu_device *adev = ip_block->adev;
Signature · 1 line
2.50.0
Quoted 10 lines · Alex Deucher
This set improves per queue reset support for a number of IPs. When we reset the queue, the queue is lost so we need to re-emit the unprocessed state from subsequent submissions. This is handled in gfx/compute queues via switch buffer and pipeline sync packets. However, you can still end up with parallel execution across queues. For correctness in that cause, enforce isolation needs to be enabled. That can impact certain use cases however and in most cases, the guilty job is correctly identified even without enforce isolation.
Quoted 2 lines
Tested on GC 10 and 11 chips with a game running and then running hang tests. The game pauses when the
Hi Alex,
Which hang test did you run?
Thanks
Quoted 123 lines
hang happens, then continues after the queue reset.
The same approach is extended to SDMA and VCN. They don't need enforce isolation because those engines are single threaded so they always operate serially.
Rework re-emit to signal the seq number of the bad job and verify that to verify that the reset worked, then re-emit the rest of the non-guilty state. This way we are not waiting on the rest of the state to complete, and if the subsequent state also contains a bad job, we'll end up in queue reset again rather than adapter reset.
Patches apply to the amd-staging-drm-next or drm-next branches in my git tree.
Git tree:
https://gitlab.freedesktop.org/agd5f/linux/-/commits/kq_resets?ref_type=headsThe IGT deadlock tests need the following fixes to properly handle
-ETIMEfences:
https://patchwork.freedesktop.org/series/150724/v4: Drop explicit padding patches
Drop new timeout macro
Rework re-emit sequence
v5: Add a helper for reemit
Convert VCN, JPEG, SDMA to use new helpers
v6: Update SDMA 4.4.2 to use new helpers
Move ptr tracking toamdgpu_fence
Skip all jobs from the bad context on the ring
v7: Rework the backup logic
Move and clean up the guilty logic for engine resets Integrate suggestions from Christian
Add JPEG 4.0.5 support
v8: Add non-guilty ring backup handling
Clean up new function signatures
Reorder some bug fixes to the start of the series
v9: Clean upfence_emit
SDMA 5.x fixes
Add new reset helpers
sched wqueue stop/start cleanup
Add support for VCNs without unified queues
v10: Drop enforce isolation default change
Add more documentation
Clean up ring backup logic
v11: SDMA6/7 fixes
v12: Ring backup and reemit fixes
SDMA cleanups
SDMA5.x reemit support
GFX10 KGQ reset fix
v13: drop SDMA cleaups, they caused regressions in some IGT testsAlex Deucher (28):
drm/amdgpu/sdma: consolidate engine reset handling drm/amdgpu/sdma: allow caller to handle kernel rings in engine reset drm/amdgpu: track ring state associated with a fence drm/amdgpu/gfx9: re-emit unprocessed state on kcq reset drm/amdgpu/gfx9.4.3: re-emit unprocessed state on kcq reset drm/amdgpu/gfx10: re-emit unprocessed state on ring reset drm/amdgpu/gfx11: re-emit unprocessed state on ring reset drm/amdgpu/gfx12: re-emit unprocessed state on ring reset drm/amdgpu/sdma5: re-emit unprocessed state on ring reset drm/amdgpu/sdma5.2: re-emit unprocessed state on ring reset drm/amdgpu/sdma6: re-emit unprocessed state on ring reset drm/amdgpu/sdma7: re-emit unprocessed state on ring reset drm/amdgpu/jpeg2: re-emit unprocessed state on ring reset drm/amdgpu/jpeg2.5: re-emit unprocessed state on ring reset drm/amdgpu/jpeg3: re-emit unprocessed state on ring reset drm/amdgpu/jpeg4: re-emit unprocessed state on ring reset drm/amdgpu/jpeg4.0.3: re-emit unprocessed state on ring reset drm/amdgpu/jpeg4.0.5: add queue reset
drm/amdgpu/jpeg5: add queue reset
drm/amdgpu/jpeg5.0.1: re-emit unprocessed state on ring reset drm/amdgpu/vcn4: re-emit unprocessed state on ring reset drm/amdgpu/vcn4.0.3: re-emit unprocessed state on ring reset drm/amdgpu/vcn4.0.5: re-emit unprocessed state on ring reset drm/amdgpu/vcn5: re-emit unprocessed state on ring reset drm/amdgpu/vcn: add a helper framework for engine resets drm/amdgpu/vcn2: implement ring reset
drm/amdgpu/vcn2.5: implement ring reset
drm/amdgpu/vcn3: implement ring resetdrivers/gpu/drm/amd/amdgpu/amdgpu_fence.c | 90 +++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c | 15 +++- drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 4 +- drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c | 67 ++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h | 18 ++++ drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c | 43 +++++---- drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h | 3 +- drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c | 76 ++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h | 6 +- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 4 + drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c | 41 ++------- drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 35 +------- drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c | 35 +------- drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c | 12 +-- drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c | 12 +-- drivers/gpu/drm/amd/amdgpu/jpeg_v2_0.c | 11 +-- drivers/gpu/drm/amd/amdgpu/jpeg_v2_5.c | 11 +-- drivers/gpu/drm/amd/amdgpu/jpeg_v3_0.c | 11 +-- drivers/gpu/drm/amd/amdgpu/jpeg_v4_0.c | 11 +-- drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_3.c | 11 +-- drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_5.c | 11 +++ drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_0.c | 14 +++ drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_1.c | 11 +-- drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c | 19 +--- drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c | 23 +++-- drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c | 23 +++-- drivers/gpu/drm/amd/amdgpu/sdma_v6_0.c | 18 ++-- drivers/gpu/drm/amd/amdgpu/sdma_v7_0.c | 18 ++-- drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c | 12 +++ drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c | 11 +++ drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c | 13 +++ drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c | 11 +-- drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c | 10 +-- drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.c | 11 +-- drivers/gpu/drm/amd/amdgpu/vcn_v5_0_0.c | 11 +-- .../drm/amd/amdkfd/kfd_device_queue_manager.c | 2 +- 36 files changed, 454 insertions(+), 280 deletions(-)Signature · 1 line
2.50.0
Signature · 1 line
Rodrigo Siqueira
Quoted 12 lines · Rodrigo Siqueira
Quoted 10 lines · Alex Deucher
This set improves per queue reset support for a number of IPs. When we reset the queue, the queue is lost so we need to re-emit the unprocessed state from subsequent submissions. This is handled in gfx/compute queues via switch buffer and pipeline sync packets. However, you can still end up with parallel execution across queues. For correctness in that cause, enforce isolation needs to be enabled. That can impact certain use cases however and in most cases, the guilty job is correctly identified even without enforce isolation.
Quoted 6 lines
Quoted 2 lines
Tested on GC 10 and 11 chips with a game running and then running hang tests. The game pauses when the
Hi Alex,
Which hang test did you run?
The hang tests in HangTestSuite and IGT.
Alex
Quoted 129 lines
Thanks
Quoted 120 lines
hang happens, then continues after the queue reset.
The same approach is extended to SDMA and VCN. They don't need enforce isolation because those engines are single threaded so they always operate serially.
Rework re-emit to signal the seq number of the bad job and verify that to verify that the reset worked, then re-emit the rest of the non-guilty state. This way we are not waiting on the rest of the state to complete, and if the subsequent state also contains a bad job, we'll end up in queue reset again rather than adapter reset.
Patches apply to the amd-staging-drm-next or drm-next branches in my git tree.
Git tree:
https://gitlab.freedesktop.org/agd5f/linux/-/commits/kq_resets?ref_type=headsThe IGT deadlock tests need the following fixes to properly handle
-ETIMEfences:
https://patchwork.freedesktop.org/series/150724/v4: Drop explicit padding patches
Drop new timeout macro
Rework re-emit sequence
v5: Add a helper for reemit
Convert VCN, JPEG, SDMA to use new helpers
v6: Update SDMA 4.4.2 to use new helpers
Move ptr tracking toamdgpu_fence
Skip all jobs from the bad context on the ring
v7: Rework the backup logic
Move and clean up the guilty logic for engine resets Integrate suggestions from Christian
Add JPEG 4.0.5 support
v8: Add non-guilty ring backup handling
Clean up new function signatures
Reorder some bug fixes to the start of the series
v9: Clean upfence_emit
SDMA 5.x fixes
Add new reset helpers
sched wqueue stop/start cleanup
Add support for VCNs without unified queues
v10: Drop enforce isolation default change
Add more documentation
Clean up ring backup logic
v11: SDMA6/7 fixes
v12: Ring backup and reemit fixes
SDMA cleanups
SDMA5.x reemit support
GFX10 KGQ reset fix
v13: drop SDMA cleaups, they caused regressions in some IGT testsAlex Deucher (28):
drm/amdgpu/sdma: consolidate engine reset handling drm/amdgpu/sdma: allow caller to handle kernel rings in engine reset drm/amdgpu: track ring state associated with a fence drm/amdgpu/gfx9: re-emit unprocessed state on kcq reset drm/amdgpu/gfx9.4.3: re-emit unprocessed state on kcq reset drm/amdgpu/gfx10: re-emit unprocessed state on ring reset drm/amdgpu/gfx11: re-emit unprocessed state on ring reset drm/amdgpu/gfx12: re-emit unprocessed state on ring reset drm/amdgpu/sdma5: re-emit unprocessed state on ring reset drm/amdgpu/sdma5.2: re-emit unprocessed state on ring reset drm/amdgpu/sdma6: re-emit unprocessed state on ring reset drm/amdgpu/sdma7: re-emit unprocessed state on ring reset drm/amdgpu/jpeg2: re-emit unprocessed state on ring reset drm/amdgpu/jpeg2.5: re-emit unprocessed state on ring reset drm/amdgpu/jpeg3: re-emit unprocessed state on ring reset drm/amdgpu/jpeg4: re-emit unprocessed state on ring reset drm/amdgpu/jpeg4.0.3: re-emit unprocessed state on ring reset drm/amdgpu/jpeg4.0.5: add queue reset
drm/amdgpu/jpeg5: add queue reset
drm/amdgpu/jpeg5.0.1: re-emit unprocessed state on ring reset drm/amdgpu/vcn4: re-emit unprocessed state on ring reset drm/amdgpu/vcn4.0.3: re-emit unprocessed state on ring reset drm/amdgpu/vcn4.0.5: re-emit unprocessed state on ring reset drm/amdgpu/vcn5: re-emit unprocessed state on ring reset drm/amdgpu/vcn: add a helper framework for engine resets drm/amdgpu/vcn2: implement ring reset
drm/amdgpu/vcn2.5: implement ring reset
drm/amdgpu/vcn3: implement ring resetdrivers/gpu/drm/amd/amdgpu/amdgpu_fence.c | 90 +++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c | 15 +++- drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 4 +- drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c | 67 ++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h | 18 ++++ drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c | 43 +++++---- drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h | 3 +- drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c | 76 ++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h | 6 +- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 4 + drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c | 41 ++------- drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 35 +------- drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c | 35 +------- drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c | 12 +-- drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c | 12 +-- drivers/gpu/drm/amd/amdgpu/jpeg_v2_0.c | 11 +-- drivers/gpu/drm/amd/amdgpu/jpeg_v2_5.c | 11 +-- drivers/gpu/drm/amd/amdgpu/jpeg_v3_0.c | 11 +-- drivers/gpu/drm/amd/amdgpu/jpeg_v4_0.c | 11 +-- drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_3.c | 11 +-- drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_5.c | 11 +++ drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_0.c | 14 +++ drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_1.c | 11 +-- drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c | 19 +--- drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c | 23 +++-- drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c | 23 +++-- drivers/gpu/drm/amd/amdgpu/sdma_v6_0.c | 18 ++-- drivers/gpu/drm/amd/amdgpu/sdma_v7_0.c | 18 ++-- drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c | 12 +++ drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c | 11 +++ drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c | 13 +++ drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c | 11 +-- drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c | 10 +-- drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.c | 11 +-- drivers/gpu/drm/amd/amdgpu/vcn_v5_0_0.c | 11 +-- .../drm/amd/amdkfd/kfd_device_queue_manager.c | 2 +- 36 files changed, 454 insertions(+), 280 deletions(-)Quoted 3 lines
--
2.50.0--
Rodrigo Siqueira