From: Alex Deucher <alexander.deucher@amd.com>
To: <amd-gfx@lists.freedesktop.org>, <christian.koenig@amd.com>,
<sasundar@amd.com>
Cc: Alex Deucher <alexander.deucher@amd.com>,
Sathishkumar S <sathishkumar.sundararaju@amd.com>
Subject: [PATCH 30/33] drm/amdgpu/vcn: add a helper framework for engine resets
Date: Thu, 26 Jun 2025 23:39:59 -0400 [thread overview]
Message-ID: <20250627034002.5590-31-alexander.deucher@amd.com> (raw)
In-Reply-To: <20250627034002.5590-1-alexander.deucher@amd.com>
With engine resets we reset all queues on the engine rather
than just a single queue. Add a framework to handle this
similar to SDMA.
Reviewed-by: Sathishkumar S <sathishkumar.sundararaju@amd.com>
Tested-by: Sathishkumar S <sathishkumar.sundararaju@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
---
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(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c
index c8885c3d54b33..f1f67521c29ca 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c
@@ -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);
+}
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h
index 83adf81defc71..0bc0a94d7cf0f 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h
@@ -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
--
2.50.0
next prev parent reply other threads:[~2025-06-27 3:40 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-27 3:39 [PATCH V12 00/33] Reset improvements Alex Deucher
2025-06-27 3:39 ` [PATCH 01/33] drm/amdgpu/gfx10: fix KGQ reset sequence Alex Deucher
2025-06-30 8:37 ` Christian König
2025-06-27 3:39 ` [PATCH 02/33] drm/amdgpu/sdma: consolidate engine reset handling Alex Deucher
2025-06-30 8:40 ` Christian König
2025-06-30 13:47 ` Alex Deucher
2025-06-27 3:39 ` [PATCH 03/33] drm/amdgpu/sdma: allow caller to handle kernel rings in engine reset Alex Deucher
2025-06-27 3:39 ` [PATCH 04/33] drm/amdgpu/sdma5: clean up resume code Alex Deucher
2025-06-30 8:52 ` Christian König
2025-06-27 3:39 ` [PATCH 05/33] drm/amdgpu/sdma5.2: " Alex Deucher
2025-06-30 8:53 ` Christian König
2025-06-27 3:39 ` [PATCH 06/33] drm/amdgpu/sdma6: " Alex Deucher
2025-06-30 8:55 ` Christian König
2025-06-27 3:39 ` [PATCH 07/33] drm/amdgpu/sdma7: " Alex Deucher
2025-06-30 8:56 ` Christian König
2025-06-27 3:39 ` [PATCH 08/33] drm/amdgpu: track ring state associated with a fence Alex Deucher
2025-06-27 3:39 ` [PATCH 09/33] drm/amdgpu/gfx9: re-emit unprocessed state on kcq reset Alex Deucher
2025-06-27 3:39 ` [PATCH 10/33] drm/amdgpu/gfx9.4.3: " Alex Deucher
2025-06-27 3:39 ` [PATCH 11/33] drm/amdgpu/gfx10: re-emit unprocessed state on ring reset Alex Deucher
2025-06-27 3:39 ` [PATCH 12/33] drm/amdgpu/gfx11: " Alex Deucher
2025-06-27 3:39 ` [PATCH 13/33] drm/amdgpu/gfx12: " Alex Deucher
2025-06-27 3:39 ` [PATCH 14/33] drm/amdgpu/sdma5: " Alex Deucher
2025-06-27 3:39 ` [PATCH 15/33] drm/amdgpu/sdma5.2: " Alex Deucher
2025-06-27 3:39 ` [PATCH 16/33] drm/amdgpu/sdma6: " Alex Deucher
2025-06-27 3:39 ` [PATCH 17/33] drm/amdgpu/sdma7: " Alex Deucher
2025-06-27 3:39 ` [PATCH 18/33] drm/amdgpu/jpeg2: " Alex Deucher
2025-06-27 3:39 ` [PATCH 19/33] drm/amdgpu/jpeg2.5: " Alex Deucher
2025-06-27 3:39 ` [PATCH 20/33] drm/amdgpu/jpeg3: " Alex Deucher
2025-06-27 3:39 ` [PATCH 21/33] drm/amdgpu/jpeg4: " Alex Deucher
2025-06-27 3:39 ` [PATCH 22/33] drm/amdgpu/jpeg4.0.3: " Alex Deucher
2025-06-27 3:39 ` [PATCH 23/33] drm/amdgpu/jpeg4.0.5: add queue reset Alex Deucher
2025-06-27 3:39 ` [PATCH 24/33] drm/amdgpu/jpeg5: " Alex Deucher
2025-06-27 3:39 ` [PATCH 25/33] drm/amdgpu/jpeg5.0.1: re-emit unprocessed state on ring reset Alex Deucher
2025-06-27 3:39 ` [PATCH 26/33] drm/amdgpu/vcn4: " Alex Deucher
2025-06-27 3:39 ` [PATCH 27/33] drm/amdgpu/vcn4.0.3: " Alex Deucher
2025-06-27 3:39 ` [PATCH 28/33] drm/amdgpu/vcn4.0.5: " Alex Deucher
2025-06-27 3:39 ` [PATCH 29/33] drm/amdgpu/vcn5: " Alex Deucher
2025-06-27 3:39 ` Alex Deucher [this message]
2025-06-27 3:40 ` [PATCH 31/33] drm/amdgpu/vcn2: implement " Alex Deucher
2025-06-27 3:40 ` [PATCH 32/33] drm/amdgpu/vcn2.5: " Alex Deucher
2025-06-27 3:40 ` [PATCH 33/33] drm/amdgpu/vcn3: " Alex Deucher
2025-07-01 15:25 ` [PATCH V12 00/33] Reset improvements Krzysztof Łopatowski
2025-07-01 15:30 ` Alex Deucher
-- strict thread matches above, loose matches on Subject: below --
2025-07-11 22:39 [PATCH V15 " Alex Deucher
2025-07-11 22:40 ` [PATCH 30/33] drm/amdgpu/vcn: add a helper framework for engine resets Alex Deucher
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250627034002.5590-31-alexander.deucher@amd.com \
--to=alexander.deucher@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=christian.koenig@amd.com \
--cc=sasundar@amd.com \
--cc=sathishkumar.sundararaju@amd.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.