Skip to contentSkip to conversation

drm/amd/amdgpu: Simplify SDMA reset mechanism by removing dynamic callbacks

PATCH Superseded [email protected] 4 participants 16 messages Mar 12, 2025 – Mar 14, 2025

Subsystems (2)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/7 drm/amd/amdgpu: Simplify SDMA reset mechanism by removing dynamic callbacks

From: "[email protected]" <[email protected]>

Since KFD no longer registers its own callbacks for SDMA resets, and only KGD uses the reset mechanism, we can simplify the SDMA reset flow by directly calling the ring's stop_queue and start_queue functions. This patch removes the dynamic callback mechanism and prepares for its eventual deprecation.

The current SDMA reset mechanism uses a dynamic callback registration system to allow both KFD and KGD to register pre-reset and post-reset functions. However, KFD no longer registers its callbacks, and the reset logic is now entirely handled by KGD.
This makes the dynamic callback mechanism unnecessary and adds complexity to the code.

1. **Remove Dynamic Callbacks**:
- The pre_reset and post_reset callback invocations in amdgpu_sdma_reset_engine are removed.
- Instead, the ring's stop_queue and start_queue functions are called directly during the reset process.

2. **Add stop_queue and start_queue to Ring Functions**:
- The amdgpu_ring_funcs structure is extended to include stop_queue and start_queue functions.
- These functions are implemented in the SDMA version-specific code (e.g., sdma_v4_4_2_stop_queue and sdma_v4_4_2_restore_queue).

3. **Prepare for Deprecation of Dynamic Mechanism**:
- By removing the callback invocations, this patch prepares the codebase for the eventual removal of the dynamic callback registration mechanism.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h |  2 ++
 drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c | 33 ++----------------------
 drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c |  2 ++
 3 files changed, 6 insertions(+), 31 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h +2 -0
index b4fd1e17205e..1c52ff92ea26 100644
@@ -237,6 +237,8 @@ struct amdgpu_ring_funcs {
 	void (*patch_ce)(struct amdgpu_ring *ring, unsigned offset);
 	void (*patch_de)(struct amdgpu_ring *ring, unsigned offset);
 	int (*reset)(struct amdgpu_ring *ring, unsigned int vmid);
+	int (*stop_queue)(struct amdgpu_device *adev, uint32_t instance_id);
+	int (*start_queue)(struct amdgpu_device *adev, uint32_t instance_id);
 	void (*emit_cleaner_shader)(struct amdgpu_ring *ring);
 	bool (*is_guilty)(struct amdgpu_ring *ring);
 };
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +2 -31
index 39669f8788a7..b1f4a11ad0c9 100644
@@ -534,16 +534,10 @@ void amdgpu_sdma_register_on_reset_callbacks(struct amdgpu_device *adev, struct
  * @instance_id: ID of the SDMA engine instance to reset
  * @suspend_user_queues: check if suspend user queue.
  *
- * This function performs the following steps:
- * 1. Calls all registered pre_reset callbacks to allow KFD and AMDGPU to save their state.
- * 2. Resets the specified SDMA engine instance.
- * 3. Calls all registered post_reset callbacks to allow KFD and AMDGPU to restore their state.
- *
  * Returns: 0 on success, or a negative error code on failure.
  */
 int amdgpu_sdma_reset_engine(struct amdgpu_device *adev, uint32_t instance_id, bool suspend_user_queues)
 {
-	struct sdma_on_reset_funcs *funcs;
 	int ret = 0;
 	struct amdgpu_sdma_instance *sdma_instance = &adev->sdma.instance[instance_id];;
 	struct amdgpu_ring *gfx_ring = &sdma_instance->ring;
@@ -571,19 +565,7 @@ int amdgpu_sdma_reset_engine(struct amdgpu_device *adev, uint32_t instance_id, b
 		page_sched_stopped = true;
 	}
 
-	/* Invoke all registered pre_reset callbacks */
-	list_for_each_entry(funcs, &adev->sdma.reset_callback_list, list) {
-		if (funcs->pre_reset) {
-			ret = funcs->pre_reset(adev, instance_id);
-			if (ret) {
-				dev_err(adev->dev,
-				"beforeReset callback failed for instance %u: %d\n",
-					instance_id, ret);
-				goto exit;
-			}
-		}
-	}
-
+	gfx_ring->funcs->stop_queue(adev, instance_id);
 	/* Perform the SDMA reset for the specified instance */
 	ret = amdgpu_dpm_reset_sdma(adev, 1 << instance_id);
 	if (ret) {
@@ -591,18 +573,7 @@ int amdgpu_sdma_reset_engine(struct amdgpu_device *adev, uint32_t instance_id, b
 		goto exit;
 	}
 
-	/* Invoke all registered post_reset callbacks */
-	list_for_each_entry(funcs, &adev->sdma.reset_callback_list, list) {
-		if (funcs->post_reset) {
-			ret = funcs->post_reset(adev, instance_id);
-			if (ret) {
-				dev_err(adev->dev,
-				"afterReset callback failed for instance %u: %d\n",
-					instance_id, ret);
-				goto exit;
-			}
-		}
-	}
+	gfx_ring->funcs->start_queue(adev, instance_id);
 
 exit:
 	/* Restart the scheduler's work queue for the GFX and page rings
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +2 -0
index fd34dc138081..c1f7ccff9c4e 100644
@@ -2132,6 +2132,8 @@ static const struct amdgpu_ring_funcs sdma_v4_4_2_ring_funcs = {
 	.emit_reg_wait = sdma_v4_4_2_ring_emit_reg_wait,
 	.emit_reg_write_reg_wait = amdgpu_ring_emit_reg_write_reg_wait_helper,
 	.reset = sdma_v4_4_2_reset_queue,
+	.stop_queue = sdma_v4_4_2_stop_queue,
+	.start_queue = sdma_v4_4_2_restore_queue,
 	.is_guilty = sdma_v4_4_2_ring_is_guilty,
 };
 
Signature · 1 line
2.25.1
#1 lore raw

PATCH 2/7 drm/amd/amdgpu: Implement SDMA soft reset directly for sdma v5

From: "[email protected]" <[email protected]>

This patch introduces a new function amdgpu_sdma_soft_reset to handle SDMA soft resets directly, rather than relying on the DPM interface.

1. **New amdgpu_sdma_soft_reset Function**:
- Implements a soft reset for SDMA engines by directly writing to the hardware registers.
- Handles SDMA versions 4.x and 5.x separately:
- For SDMA 4.x, the existing amdgpu_dpm_reset_sdma function is used for backward compatibility.
- For SDMA 5.x, the driver directly manipulates the GRBM_SOFT_RESET register to reset the specified SDMA instance.

2. **Integration into amdgpu_sdma_reset_engine**:
- The amdgpu_sdma_soft_reset function is called during the SDMA reset process, replacing the previous call to amdgpu_dpm_reset_sdma.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c | 46 +++++++++++++++++++++++-
 1 file changed, 45 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +45 -1
index b1f4a11ad0c9..c01154313a92 100644
@@ -26,6 +26,8 @@
 #include "amdgpu_sdma.h"
 #include "amdgpu_ras.h"
 #include "amdgpu_reset.h"
+#include "gc/gc_10_1_0_offset.h"
+#include "gc/gc_10_3_0_sh_mask.h"
 
 #define AMDGPU_CSA_SDMA_SIZE 64
 /* SDMA CSA reside in the 3rd page of CSA */
@@ -528,6 +530,48 @@ void amdgpu_sdma_register_on_reset_callbacks(struct amdgpu_device *adev, struct
 	list_add_tail(&funcs->list, &adev->sdma.reset_callback_list);
 }
 
+static int amdgpu_sdma_soft_reset(struct amdgpu_device *adev, u32 instance_id)
+{
+	u32 soft_reset;
+	int r = 0;
+
+	switch (amdgpu_ip_version(adev, SDMA0_HWIP, 0)) {
+	case IP_VERSION(4, 4, 2):
+	case IP_VERSION(4, 4, 4):
+	case IP_VERSION(4, 4, 5):
+		/* For SDMA 4.x, use the existing DPM interface for backward compatibility */
+		r = amdgpu_dpm_reset_sdma(adev, 1 << instance_id);
+		break;
+	case IP_VERSION(5, 0, 0):
+	case IP_VERSION(5, 0, 1):
+	case IP_VERSION(5, 0, 2):
+	case IP_VERSION(5, 0, 5):
+	case IP_VERSION(5, 2, 0):
+	case IP_VERSION(5, 2, 2):
+	case IP_VERSION(5, 2, 4):
+	case IP_VERSION(5, 2, 5):
+	case IP_VERSION(5, 2, 6):
+	case IP_VERSION(5, 2, 3):
+	case IP_VERSION(5, 2, 1):
+	case IP_VERSION(5, 2, 7):
+		/* For SDMA 5.x, directly manipulate the GRBM_SOFT_RESET register */
+		soft_reset = RREG32_SOC15(GC, 0, mmGRBM_SOFT_RESET);
+		soft_reset |= 1 << GRBM_SOFT_RESET__SOFT_RESET_SDMA0__SHIFT << instance_id;
+		/* Issue the soft reset */
+		WREG32_SOC15(GC, 0, mmGRBM_SOFT_RESET, soft_reset);
+
+		udelay(50);
+		/* Clear the soft reset bit */
+		soft_reset &= ~(1 << GRBM_SOFT_RESET__SOFT_RESET_SDMA0__SHIFT << instance_id);
+		WREG32_SOC15(GC, 0, mmGRBM_SOFT_RESET, soft_reset);
+		break;
+	default:
+		break;
+	}
+
+	return r;
+}
+
 /**
  * amdgpu_sdma_reset_engine - Reset a specific SDMA engine
  * @adev: Pointer to the AMDGPU device
@@ -567,7 +611,7 @@ int amdgpu_sdma_reset_engine(struct amdgpu_device *adev, uint32_t instance_id, b
 
 	gfx_ring->funcs->stop_queue(adev, instance_id);
 	/* Perform the SDMA reset for the specified instance */
-	ret = amdgpu_dpm_reset_sdma(adev, 1 << instance_id);
+	ret = amdgpu_sdma_soft_reset(adev, instance_id);
 	if (ret) {
 		dev_err(adev->dev, "Failed to reset SDMA instance %u\n", instance_id);
 		goto exit;
Signature · 1 line
2.25.1
#2 lore raw

PATCH 3/7 drm/amdgpu: Optimize SDMA v5.0 queue reset and stop logic

In reply to [email protected]

From: "[email protected]" <[email protected]>

This patch refactors the SDMA v5.0 queue reset and stop logic to improve code readability, maintainability, and performance. The key changes include:

1. **Generalized sdma_v5_0_gfx_stop Function**:
- Added an inst_mask parameter to allow stopping specific SDMA instances instead of all instances. This is useful for resetting individual queues.

2. **Simplified sdma_v5_0_reset_queue Function**:
- Removed redundant loops and checks by directly using the ring->me field to identify the SDMA instance.
- Reused the sdma_v5_0_gfx_stop function to stop the queue, reducing code duplication.

---
 drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c | 65 +++++++++++---------------
 1 file changed, 26 insertions(+), 39 deletions(-)
drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c +26 -39
index 0dce59f4f6e2..387a626936b3 100644
@@ -588,15 +588,15 @@ static void sdma_v5_0_ring_emit_fence(struct amdgpu_ring *ring, u64 addr, u64 se
  * sdma_v5_0_gfx_stop - stop the gfx async dma engines
  *
  * @adev: amdgpu_device pointer
- *
+ * @inst_mask: mask of dma engine instances to be disabled
  * Stop the gfx async dma ring buffers (NAVI10).
  */
-static void sdma_v5_0_gfx_stop(struct amdgpu_device *adev)
+static void sdma_v5_0_gfx_stop(struct amdgpu_device *adev, uint32_t inst_mask)
 {
 	u32 rb_cntl, ib_cntl;
 	int i;
 
-	for (i = 0; i < adev->sdma.num_instances; i++) {
+	for_each_inst(i, inst_mask) {
 		rb_cntl = RREG32_SOC15_IP(GC, sdma_v5_0_get_reg_offset(adev, i, mmSDMA0_GFX_RB_CNTL));
 		rb_cntl = REG_SET_FIELD(rb_cntl, SDMA0_GFX_RB_CNTL, RB_ENABLE, 0);
 		WREG32_SOC15_IP(GC, sdma_v5_0_get_reg_offset(adev, i, mmSDMA0_GFX_RB_CNTL), rb_cntl);
@@ -688,9 +688,11 @@ static void sdma_v5_0_enable(struct amdgpu_device *adev, bool enable)
 {
 	u32 f32_cntl;
 	int i;
+	uint32_t inst_mask;
 
+	inst_mask = GENMASK(adev->sdma.num_instances - 1, 0);
 	if (!enable) {
-		sdma_v5_0_gfx_stop(adev);
+		sdma_v5_0_gfx_stop(adev, 1 << inst_mask);
 		sdma_v5_0_rlc_stop(adev);
 	}
 
@@ -1572,40 +1574,25 @@ static int sdma_v5_0_soft_reset(struct amdgpu_ip_block *ip_block)
 static int sdma_v5_0_reset_queue(struct amdgpu_ring *ring, unsigned int vmid)
 {
 	struct amdgpu_device *adev = ring->adev;
-	int i, j, r;
-	u32 rb_cntl, ib_cntl, f32_cntl, freeze, cntl, preempt, soft_reset, stat1_reg;
+	int j, r;
+	u32 f32_cntl, freeze, cntl, preempt, soft_reset, stat1_reg;
+	u32 inst_id;
 
 	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) {
-		DRM_ERROR("sdma instance not found\n");
-		return -EINVAL;
-	}
-
+	inst_id = ring->me;
 	amdgpu_gfx_rlc_enter_safe_mode(adev, 0);
 
 	/* stop queue */
-	ib_cntl = RREG32(sdma_v5_0_get_reg_offset(adev, i, mmSDMA0_GFX_IB_CNTL));
-	ib_cntl = REG_SET_FIELD(ib_cntl, SDMA0_GFX_IB_CNTL, IB_ENABLE, 0);
-	WREG32(sdma_v5_0_get_reg_offset(adev, i, mmSDMA0_GFX_IB_CNTL), ib_cntl);
-
-	rb_cntl = RREG32(sdma_v5_0_get_reg_offset(adev, i, mmSDMA0_GFX_RB_CNTL));
-	rb_cntl = REG_SET_FIELD(rb_cntl, SDMA0_GFX_RB_CNTL, RB_ENABLE, 0);
-	WREG32(sdma_v5_0_get_reg_offset(adev, i, mmSDMA0_GFX_RB_CNTL), rb_cntl);
+	sdma_v5_0_gfx_stop(adev, 1 << ring->me);
 
 	/* engine stop SDMA1_F32_CNTL.HALT to 1 and SDMAx_FREEZE freeze bit to 1 */
-	freeze = RREG32(sdma_v5_0_get_reg_offset(adev, i, mmSDMA0_FREEZE));
+	freeze = RREG32(sdma_v5_0_get_reg_offset(adev, inst_id, mmSDMA0_FREEZE));
 	freeze = REG_SET_FIELD(freeze, SDMA0_FREEZE, FREEZE, 1);
-	WREG32(sdma_v5_0_get_reg_offset(adev, i, mmSDMA0_FREEZE), freeze);
+	WREG32(sdma_v5_0_get_reg_offset(adev, inst_id, mmSDMA0_FREEZE), freeze);
 
 	for (j = 0; j < adev->usec_timeout; j++) {
-		freeze = RREG32(sdma_v5_0_get_reg_offset(adev, i, mmSDMA0_FREEZE));
+		freeze = RREG32(sdma_v5_0_get_reg_offset(adev, inst_id, mmSDMA0_FREEZE));
 		if (REG_GET_FIELD(freeze, SDMA0_FREEZE, FROZEN) & 1)
 			break;
 		udelay(1);
@@ -1613,7 +1600,7 @@ static int sdma_v5_0_reset_queue(struct amdgpu_ring *ring, unsigned int vmid)
 
 	/* check sdma copy engine all idle if frozen not received*/
 	if (j == adev->usec_timeout) {
-		stat1_reg = RREG32(sdma_v5_0_get_reg_offset(adev, i, mmSDMA0_STATUS1_REG));
+		stat1_reg = RREG32(sdma_v5_0_get_reg_offset(adev, inst_id, mmSDMA0_STATUS1_REG));
 		if ((stat1_reg & 0x3FF) != 0x3FF) {
 			DRM_ERROR("cannot soft reset as sdma not idle\n");
 			r = -ETIMEDOUT;
@@ -1621,35 +1608,35 @@ static int sdma_v5_0_reset_queue(struct amdgpu_ring *ring, unsigned int vmid)
 		}
 	}
 
-	f32_cntl = RREG32(sdma_v5_0_get_reg_offset(adev, i, mmSDMA0_F32_CNTL));
+	f32_cntl = RREG32(sdma_v5_0_get_reg_offset(adev, inst_id, mmSDMA0_F32_CNTL));
 	f32_cntl = REG_SET_FIELD(f32_cntl, SDMA0_F32_CNTL, HALT, 1);
-	WREG32(sdma_v5_0_get_reg_offset(adev, i, mmSDMA0_F32_CNTL), f32_cntl);
+	WREG32(sdma_v5_0_get_reg_offset(adev, inst_id, mmSDMA0_F32_CNTL), f32_cntl);
 
-	cntl = RREG32(sdma_v5_0_get_reg_offset(adev, i, mmSDMA0_CNTL));
+	cntl = RREG32(sdma_v5_0_get_reg_offset(adev, inst_id, mmSDMA0_CNTL));
 	cntl = REG_SET_FIELD(cntl, SDMA0_CNTL, UTC_L1_ENABLE, 0);
-	WREG32(sdma_v5_0_get_reg_offset(adev, i, mmSDMA0_CNTL), cntl);
+	WREG32(sdma_v5_0_get_reg_offset(adev, inst_id, mmSDMA0_CNTL), cntl);
 
 	/* soft reset SDMA_GFX_PREEMPT.IB_PREEMPT = 0 mmGRBM_SOFT_RESET.SOFT_RESET_SDMA0/1 = 1 */
-	preempt = RREG32(sdma_v5_0_get_reg_offset(adev, i, mmSDMA0_GFX_PREEMPT));
+	preempt = RREG32(sdma_v5_0_get_reg_offset(adev, inst_id, mmSDMA0_GFX_PREEMPT));
 	preempt = REG_SET_FIELD(preempt, SDMA0_GFX_PREEMPT, IB_PREEMPT, 0);
-	WREG32(sdma_v5_0_get_reg_offset(adev, i, mmSDMA0_GFX_PREEMPT), preempt);
+	WREG32(sdma_v5_0_get_reg_offset(adev, inst_id, mmSDMA0_GFX_PREEMPT), preempt);
 
 	soft_reset = RREG32_SOC15(GC, 0, mmGRBM_SOFT_RESET);
-	soft_reset |= 1 << GRBM_SOFT_RESET__SOFT_RESET_SDMA0__SHIFT << i;
+	soft_reset |= 1 << GRBM_SOFT_RESET__SOFT_RESET_SDMA0__SHIFT << inst_id;
 
 	WREG32_SOC15(GC, 0, mmGRBM_SOFT_RESET, soft_reset);
 
 	udelay(50);
 
-	soft_reset &= ~(1 << GRBM_SOFT_RESET__SOFT_RESET_SDMA0__SHIFT << i);
+	soft_reset &= ~(1 << GRBM_SOFT_RESET__SOFT_RESET_SDMA0__SHIFT << inst_id);
 	WREG32_SOC15(GC, 0, mmGRBM_SOFT_RESET, soft_reset);
 
 	/* unfreeze*/
-	freeze = RREG32(sdma_v5_0_get_reg_offset(adev, i, mmSDMA0_FREEZE));
+	freeze = RREG32(sdma_v5_0_get_reg_offset(adev, inst_id, mmSDMA0_FREEZE));
 	freeze = REG_SET_FIELD(freeze, SDMA0_FREEZE, FREEZE, 0);
-	WREG32(sdma_v5_0_get_reg_offset(adev, i, mmSDMA0_FREEZE), freeze);
+	WREG32(sdma_v5_0_get_reg_offset(adev, inst_id, mmSDMA0_FREEZE), freeze);
 
-	r = sdma_v5_0_gfx_resume_instance(adev, i, true);
+	r = sdma_v5_0_gfx_resume_instance(adev, inst_id, true);
 
 err0:
 	amdgpu_gfx_rlc_exit_safe_mode(adev, 0);
Signature · 1 line
2.25.1
#3 lore raw

PATCH 4/7 drm/amd/amdgpu: Refactor SDMA v5.0 reset logic into stop_queue and restore_queue functions

In reply to [email protected]

From: "[email protected]" <[email protected]>

This patch refactors the SDMA v5.0 reset logic by splitting the sdma_v5_0_reset_queue function into two separate functions: sdma_v5_0_stop_queue and sdma_v5_0_restore_queue.
This change aligns with the new SDMA reset mechanism, where the reset process is divided into stopping the queue, performing the reset, and restoring the queue.

1. **Split sdma_v5_0_reset_queue**:
- Extracted the queue stopping logic into sdma_v5_0_stop_queue.
- Extracted the queue restoration logic into sdma_v5_0_restore_queue.
- The soft reset step is now handled by the caller (amdgpu_sdma_reset_engine).

2. **Update Ring Functions**:
- Added stop_queue and start_queue to the sdma_v5_0_ring_funcs structure to support the new reset mechanism.

---
 drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c | 37 +++++++++++++++-----------
 1 file changed, 22 insertions(+), 15 deletions(-)
drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c +22 -15
index 387a626936b3..9458d95a4795 100644
@@ -1574,17 +1574,23 @@ static int sdma_v5_0_soft_reset(struct amdgpu_ip_block *ip_block)
 static int sdma_v5_0_reset_queue(struct amdgpu_ring *ring, unsigned int vmid)
 {
 	struct amdgpu_device *adev = ring->adev;
-	int j, r;
-	u32 f32_cntl, freeze, cntl, preempt, soft_reset, stat1_reg;
-	u32 inst_id;
+	u32 inst_id = ring->me;
+
+	return amdgpu_sdma_reset_engine(adev, inst_id, true);
+}
+
+static int sdma_v5_0_stop_queue(struct amdgpu_device *adev, uint32_t inst_id)
+{
+	int j, r = 0;
+	u32 f32_cntl, freeze, cntl, preempt, stat1_reg;
 
 	if (amdgpu_sriov_vf(adev))
 		return -EINVAL;
-	inst_id = ring->me;
+
 	amdgpu_gfx_rlc_enter_safe_mode(adev, 0);
 
 	/* stop queue */
-	sdma_v5_0_gfx_stop(adev, 1 << ring->me);
+	sdma_v5_0_gfx_stop(adev, inst_id);
 
 	/* engine stop SDMA1_F32_CNTL.HALT to 1 and SDMAx_FREEZE freeze bit to 1 */
 	freeze = RREG32(sdma_v5_0_get_reg_offset(adev, inst_id, mmSDMA0_FREEZE));
@@ -1620,17 +1626,17 @@ static int sdma_v5_0_reset_queue(struct amdgpu_ring *ring, unsigned int vmid)
 	preempt = RREG32(sdma_v5_0_get_reg_offset(adev, inst_id, mmSDMA0_GFX_PREEMPT));
 	preempt = REG_SET_FIELD(preempt, SDMA0_GFX_PREEMPT, IB_PREEMPT, 0);
 	WREG32(sdma_v5_0_get_reg_offset(adev, inst_id, mmSDMA0_GFX_PREEMPT), preempt);
+err0:
+	amdgpu_gfx_rlc_exit_safe_mode(adev, 0);
+	return r;
+}
 
-	soft_reset = RREG32_SOC15(GC, 0, mmGRBM_SOFT_RESET);
-	soft_reset |= 1 << GRBM_SOFT_RESET__SOFT_RESET_SDMA0__SHIFT << inst_id;
-
-	WREG32_SOC15(GC, 0, mmGRBM_SOFT_RESET, soft_reset);
-
-	udelay(50);
-
-	soft_reset &= ~(1 << GRBM_SOFT_RESET__SOFT_RESET_SDMA0__SHIFT << inst_id);
-	WREG32_SOC15(GC, 0, mmGRBM_SOFT_RESET, soft_reset);
+static int sdma_v5_0_restore_queue(struct amdgpu_device *adev, uint32_t inst_id)
+{
+	int r;
+	u32 freeze;
 
+	amdgpu_gfx_rlc_enter_safe_mode(adev, 0);
 	/* unfreeze*/
 	freeze = RREG32(sdma_v5_0_get_reg_offset(adev, inst_id, mmSDMA0_FREEZE));
 	freeze = REG_SET_FIELD(freeze, SDMA0_FREEZE, FREEZE, 0);
@@ -1638,7 +1644,6 @@ static int sdma_v5_0_reset_queue(struct amdgpu_ring *ring, unsigned int vmid)
 
 	r = sdma_v5_0_gfx_resume_instance(adev, inst_id, true);
 
-err0:
 	amdgpu_gfx_rlc_exit_safe_mode(adev, 0);
 	return r;
 }
@@ -1985,6 +1990,8 @@ static const struct amdgpu_ring_funcs sdma_v5_0_ring_funcs = {
 	.init_cond_exec = sdma_v5_0_ring_init_cond_exec,
 	.preempt_ib = sdma_v5_0_ring_preempt_ib,
 	.reset = sdma_v5_0_reset_queue,
+	.stop_queue = sdma_v5_0_stop_queue,
+	.start_queue = sdma_v5_0_restore_queue,
 };
 
 static void sdma_v5_0_set_ring_funcs(struct amdgpu_device *adev)
Signature · 1 line
2.25.1
#4 lore raw

PATCH 5/7 drm/amdgpu: Optimize SDMA v5.2 queue reset and stop logic

In reply to [email protected]

From: "[email protected]" <[email protected]>

This patch refactors the SDMA v5.2 queue reset and stop logic to improve code readability, maintainability, and performance. The key changes include:

1. **Generalized sdma_v5_2_gfx_stop Function**:
- Added an inst_mask parameter to allow stopping specific SDMA instances instead of all instances. This is useful for resetting individual queues.

2. **Simplified sdma_v5_2_reset_queue Function**:
- Removed redundant loops and checks by directly using the ring->me field to identify the SDMA instance.
- Reused the sdma_v5_2_gfx_stop function to stop the queue, reducing code duplication.

---
 drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c | 64 +++++++++++---------------
 1 file changed, 26 insertions(+), 38 deletions(-)
drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c +26 -38
index 2b39a03ff0c1..267110725b2f 100644
@@ -407,15 +407,15 @@ static void sdma_v5_2_ring_emit_fence(struct amdgpu_ring *ring, u64 addr, u64 se
  * sdma_v5_2_gfx_stop - stop the gfx async dma engines
  *
  * @adev: amdgpu_device pointer
- *
+ * @inst_mask: mask of dma engine instances to be disabled
  * Stop the gfx async dma ring buffers.
  */
-static void sdma_v5_2_gfx_stop(struct amdgpu_device *adev)
+static void sdma_v5_2_gfx_stop(struct amdgpu_device *adev,  uint32_t inst_mask)
 {
 	u32 rb_cntl, ib_cntl;
 	int i;
 
-	for (i = 0; i < adev->sdma.num_instances; i++) {
+	for_each_inst(i, inst_mask) {
 		rb_cntl = RREG32_SOC15_IP(GC, sdma_v5_2_get_reg_offset(adev, i, mmSDMA0_GFX_RB_CNTL));
 		rb_cntl = REG_SET_FIELD(rb_cntl, SDMA0_GFX_RB_CNTL, RB_ENABLE, 0);
 		WREG32_SOC15_IP(GC, sdma_v5_2_get_reg_offset(adev, i, mmSDMA0_GFX_RB_CNTL), rb_cntl);
@@ -506,9 +506,11 @@ static void sdma_v5_2_enable(struct amdgpu_device *adev, bool enable)
 {
 	u32 f32_cntl;
 	int i;
+	uint32_t inst_mask;
 
+	inst_mask = GENMASK(adev->sdma.num_instances - 1, 0);
 	if (!enable) {
-		sdma_v5_2_gfx_stop(adev);
+		sdma_v5_2_gfx_stop(adev, inst_mask);
 		sdma_v5_2_rlc_stop(adev);
 	}
 
@@ -1472,40 +1474,26 @@ static int sdma_v5_2_wait_for_idle(struct amdgpu_ip_block *ip_block)
 static int sdma_v5_2_reset_queue(struct amdgpu_ring *ring, unsigned int vmid)
 {
 	struct amdgpu_device *adev = ring->adev;
-	int i, j, r;
-	u32 rb_cntl, ib_cntl, f32_cntl, freeze, cntl, preempt, soft_reset, stat1_reg;
+	int j, r;
+	u32 f32_cntl, freeze, cntl, preempt, soft_reset, stat1_reg;
+	u32 inst_id;
 
 	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) {
-		DRM_ERROR("sdma instance not found\n");
-		return -EINVAL;
-	}
-
+	inst_id = ring->me;
 	amdgpu_gfx_rlc_enter_safe_mode(adev, 0);
 
 	/* stop queue */
-	ib_cntl = RREG32(sdma_v5_2_get_reg_offset(adev, i, mmSDMA0_GFX_IB_CNTL));
-	ib_cntl = REG_SET_FIELD(ib_cntl, SDMA0_GFX_IB_CNTL, IB_ENABLE, 0);
-	WREG32(sdma_v5_2_get_reg_offset(adev, i, mmSDMA0_GFX_IB_CNTL), ib_cntl);
-
-	rb_cntl = RREG32(sdma_v5_2_get_reg_offset(adev, i, mmSDMA0_GFX_RB_CNTL));
-	rb_cntl = REG_SET_FIELD(rb_cntl, SDMA0_GFX_RB_CNTL, RB_ENABLE, 0);
-	WREG32(sdma_v5_2_get_reg_offset(adev, i, mmSDMA0_GFX_RB_CNTL), rb_cntl);
+	sdma_v5_2_gfx_stop(adev, 1 << ring->me);
 
 	/*engine stop SDMA1_F32_CNTL.HALT to 1 and SDMAx_FREEZE freeze bit to 1 */
-	freeze = RREG32(sdma_v5_2_get_reg_offset(adev, i, mmSDMA0_FREEZE));
+	freeze = RREG32(sdma_v5_2_get_reg_offset(adev, inst_id, mmSDMA0_FREEZE));
 	freeze = REG_SET_FIELD(freeze, SDMA0_FREEZE, FREEZE, 1);
-	WREG32(sdma_v5_2_get_reg_offset(adev, i, mmSDMA0_FREEZE), freeze);
+	WREG32(sdma_v5_2_get_reg_offset(adev, inst_id, mmSDMA0_FREEZE), freeze);
 
 	for (j = 0; j < adev->usec_timeout; j++) {
-		freeze = RREG32(sdma_v5_2_get_reg_offset(adev, i, mmSDMA0_FREEZE));
+		freeze = RREG32(sdma_v5_2_get_reg_offset(adev, inst_id, mmSDMA0_FREEZE));
 
 		if (REG_GET_FIELD(freeze, SDMA0_FREEZE, FROZEN) & 1)
 			break;
@@ -1514,7 +1502,7 @@ static int sdma_v5_2_reset_queue(struct amdgpu_ring *ring, unsigned int vmid)
 
 
 	if (j == adev->usec_timeout) {
-		stat1_reg = RREG32(sdma_v5_2_get_reg_offset(adev, i, mmSDMA0_STATUS1_REG));
+		stat1_reg = RREG32(sdma_v5_2_get_reg_offset(adev, inst_id, mmSDMA0_STATUS1_REG));
 		if ((stat1_reg & 0x3FF) != 0x3FF) {
 			DRM_ERROR("cannot soft reset as sdma not idle\n");
 			r = -ETIMEDOUT;
@@ -1522,37 +1510,37 @@ static int sdma_v5_2_reset_queue(struct amdgpu_ring *ring, unsigned int vmid)
 		}
 	}
 
-	f32_cntl = RREG32(sdma_v5_2_get_reg_offset(adev, i, mmSDMA0_F32_CNTL));
+	f32_cntl = RREG32(sdma_v5_2_get_reg_offset(adev, inst_id, mmSDMA0_F32_CNTL));
 	f32_cntl = REG_SET_FIELD(f32_cntl, SDMA0_F32_CNTL, HALT, 1);
-	WREG32(sdma_v5_2_get_reg_offset(adev, i, mmSDMA0_F32_CNTL), f32_cntl);
+	WREG32(sdma_v5_2_get_reg_offset(adev, inst_id, mmSDMA0_F32_CNTL), f32_cntl);
 
-	cntl = RREG32(sdma_v5_2_get_reg_offset(adev, i, mmSDMA0_CNTL));
+	cntl = RREG32(sdma_v5_2_get_reg_offset(adev, inst_id, mmSDMA0_CNTL));
 	cntl = REG_SET_FIELD(cntl, SDMA0_CNTL, UTC_L1_ENABLE, 0);
-	WREG32(sdma_v5_2_get_reg_offset(adev, i, mmSDMA0_CNTL), cntl);
+	WREG32(sdma_v5_2_get_reg_offset(adev, inst_id, mmSDMA0_CNTL), cntl);
 
 	/* soft reset SDMA_GFX_PREEMPT.IB_PREEMPT = 0 mmGRBM_SOFT_RESET.SOFT_RESET_SDMA0/1 = 1 */
-	preempt = RREG32(sdma_v5_2_get_reg_offset(adev, i, mmSDMA0_GFX_PREEMPT));
+	preempt = RREG32(sdma_v5_2_get_reg_offset(adev, inst_id, mmSDMA0_GFX_PREEMPT));
 	preempt = REG_SET_FIELD(preempt, SDMA0_GFX_PREEMPT, IB_PREEMPT, 0);
-	WREG32(sdma_v5_2_get_reg_offset(adev, i, mmSDMA0_GFX_PREEMPT), preempt);
+	WREG32(sdma_v5_2_get_reg_offset(adev, inst_id, mmSDMA0_GFX_PREEMPT), preempt);
 
 	soft_reset = RREG32_SOC15(GC, 0, mmGRBM_SOFT_RESET);
-	soft_reset |= 1 << GRBM_SOFT_RESET__SOFT_RESET_SDMA0__SHIFT << i;
+	soft_reset |= 1 << GRBM_SOFT_RESET__SOFT_RESET_SDMA0__SHIFT << inst_id;
 
 
 	WREG32_SOC15(GC, 0, mmGRBM_SOFT_RESET, soft_reset);
 
 	udelay(50);
 
-	soft_reset &= ~(1 << GRBM_SOFT_RESET__SOFT_RESET_SDMA0__SHIFT << i);
+	soft_reset &= ~(1 << GRBM_SOFT_RESET__SOFT_RESET_SDMA0__SHIFT << inst_id);
 
 	WREG32_SOC15(GC, 0, mmGRBM_SOFT_RESET, soft_reset);
 
 	/* unfreeze and unhalt */
-	freeze = RREG32(sdma_v5_2_get_reg_offset(adev, i, mmSDMA0_FREEZE));
+	freeze = RREG32(sdma_v5_2_get_reg_offset(adev, inst_id, mmSDMA0_FREEZE));
 	freeze = REG_SET_FIELD(freeze, SDMA0_FREEZE, FREEZE, 0);
-	WREG32(sdma_v5_2_get_reg_offset(adev, i, mmSDMA0_FREEZE), freeze);
+	WREG32(sdma_v5_2_get_reg_offset(adev, inst_id, mmSDMA0_FREEZE), freeze);
 
-	r = sdma_v5_2_gfx_resume_instance(adev, i, true);
+	r = sdma_v5_2_gfx_resume_instance(adev, inst_id, true);
 
 err0:
 	amdgpu_gfx_rlc_exit_safe_mode(adev, 0);
Signature · 1 line
2.25.1
#5 lore raw

PATCH 6/7 drm/amd/amdgpu: Refactor SDMA v5.2 reset logic into stop_queue and restore_queue functions

In reply to [email protected]

From: "[email protected]" <[email protected]>

This patch refactors the SDMA v5.2 reset logic by splitting the sdma_v5_2_reset_queue function into two separate functions: sdma_v5_2_stop_queue and sdma_v5_2_restore_queue. This change aligns with the new SDMA reset mechanism, where the reset process is divided into stopping the queue, performing the reset, and restoring the queue.

1. **Split sdma_v5_2_reset_queue**:
- Extracted the queue stopping logic into sdma_v5_2_stop_queue.
- Extracted the queue restoration logic into sdma_v5_2_restore_queue.
- The soft reset step is now handled by the caller (amdgpu_sdma_reset_engine).

2. **Update Ring Functions**:
- Added stop_queue and start_queue to the sdma_v5_2_ring_funcs structure to support the new reset mechanism.

---
 drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c | 38 ++++++++++++++------------
 1 file changed, 21 insertions(+), 17 deletions(-)
drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c +21 -17
index 267110725b2f..faccac68a27c 100644
@@ -1474,18 +1474,22 @@ static int sdma_v5_2_wait_for_idle(struct amdgpu_ip_block *ip_block)
 static int sdma_v5_2_reset_queue(struct amdgpu_ring *ring, unsigned int vmid)
 {
 	struct amdgpu_device *adev = ring->adev;
-	int j, r;
-	u32 f32_cntl, freeze, cntl, preempt, soft_reset, stat1_reg;
-	u32 inst_id;
+	u32 inst_id = ring->me;
+
+	return amdgpu_sdma_reset_engine(adev, inst_id, true);
+}
+
+static int sdma_v5_2_stop_queue(struct amdgpu_device *adev, uint32_t inst_id)
+{
+	int j, r = 0;
+	u32 f32_cntl, freeze, cntl, preempt, stat1_reg;
 
 	if (amdgpu_sriov_vf(adev))
 		return -EINVAL;
 
-	inst_id = ring->me;
 	amdgpu_gfx_rlc_enter_safe_mode(adev, 0);
-
 	/* stop queue */
-	sdma_v5_2_gfx_stop(adev, 1 << ring->me);
+	sdma_v5_2_gfx_stop(adev, 1 << inst_id);
 
 	/*engine stop SDMA1_F32_CNTL.HALT to 1 and SDMAx_FREEZE freeze bit to 1 */
 	freeze = RREG32(sdma_v5_2_get_reg_offset(adev, inst_id, mmSDMA0_FREEZE));
@@ -1523,18 +1527,17 @@ static int sdma_v5_2_reset_queue(struct amdgpu_ring *ring, unsigned int vmid)
 	preempt = REG_SET_FIELD(preempt, SDMA0_GFX_PREEMPT, IB_PREEMPT, 0);
 	WREG32(sdma_v5_2_get_reg_offset(adev, inst_id, mmSDMA0_GFX_PREEMPT), preempt);
 
-	soft_reset = RREG32_SOC15(GC, 0, mmGRBM_SOFT_RESET);
-	soft_reset |= 1 << GRBM_SOFT_RESET__SOFT_RESET_SDMA0__SHIFT << inst_id;
-
-
-	WREG32_SOC15(GC, 0, mmGRBM_SOFT_RESET, soft_reset);
-
-	udelay(50);
-
-	soft_reset &= ~(1 << GRBM_SOFT_RESET__SOFT_RESET_SDMA0__SHIFT << inst_id);
+err0:
+	amdgpu_gfx_rlc_exit_safe_mode(adev, 0);
+	return r;
+}
 
-	WREG32_SOC15(GC, 0, mmGRBM_SOFT_RESET, soft_reset);
+static int sdma_v5_2_restore_queue(struct amdgpu_device *adev, uint32_t inst_id)
+{
+	u32 freeze;
+	int r;
 
+	amdgpu_gfx_rlc_enter_safe_mode(adev, 0);
 	/* unfreeze and unhalt */
 	freeze = RREG32(sdma_v5_2_get_reg_offset(adev, inst_id, mmSDMA0_FREEZE));
 	freeze = REG_SET_FIELD(freeze, SDMA0_FREEZE, FREEZE, 0);
@@ -1542,7 +1545,6 @@ static int sdma_v5_2_reset_queue(struct amdgpu_ring *ring, unsigned int vmid)
 
 	r = sdma_v5_2_gfx_resume_instance(adev, inst_id, true);
 
-err0:
 	amdgpu_gfx_rlc_exit_safe_mode(adev, 0);
 	return r;
 }
@@ -1982,6 +1984,8 @@ static const struct amdgpu_ring_funcs sdma_v5_2_ring_funcs = {
 	.init_cond_exec = sdma_v5_2_ring_init_cond_exec,
 	.preempt_ib = sdma_v5_2_ring_preempt_ib,
 	.reset = sdma_v5_2_reset_queue,
+	.stop_queue = sdma_v5_2_stop_queue,
+	.start_queue = sdma_v5_2_restore_queue,
 };
 
 static void sdma_v5_2_set_ring_funcs(struct amdgpu_device *adev)
Signature · 1 line
2.25.1
#6 lore raw

PATCH 7/7 drm/amd/amdgpu: Remove deprecated SDMA reset callback mechanism

In reply to [email protected]

From: "[email protected]" <[email protected]>

This patch removes the deprecated SDMA reset callback mechanism, which was previously used to register pre-reset and post-reset callbacks for SDMA engine resets.
The callback mechanism has been replaced with a more direct and efficient approach using stop_queue and start_queue functions in the ring's function table.

The SDMA reset callback mechanism allowed KFD and AMDGPU to register pre-reset and post-reset functions for handling SDMA engine resets.
However, this approach added unnecessary complexity and was no longer needed after the introduction of the stop_queue and start_queue functions in the ring's function table.

1. **Remove Callback Mechanism**:
- Removed the amdgpu_sdma_register_on_reset_callbacks function and its associated data structures (sdma_on_reset_funcs).
- Removed the callback registration logic from the SDMA v4.4.2 initialization code.

2. **Clean Up Related Code**:
- Removed the sdma_v4_4_2_set_engine_reset_funcs function, which was used to register the callbacks.
- Removed the sdma_v4_4_2_engine_reset_funcs structure, which contained the pre-reset and post-reset callback functions.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c | 24 ------------------------
 drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h |  8 --------
 drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c | 12 ------------
 3 files changed, 44 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +0 -24
index c01154313a92..e88fa0f84bb8 100644
@@ -506,30 +506,6 @@ void amdgpu_sdma_sysfs_reset_mask_fini(struct amdgpu_device *adev)
 	}
 }
 
-/**
- * amdgpu_sdma_register_on_reset_callbacks - Register SDMA reset callbacks
- * @funcs: Pointer to the callback structure containing pre_reset and post_reset functions
- *
- * This function allows KFD and AMDGPU to register their own callbacks for handling
- * pre-reset and post-reset operations for engine reset. These are needed because engine
- * reset will stop all queues on that engine.
- */
-void amdgpu_sdma_register_on_reset_callbacks(struct amdgpu_device *adev, struct sdma_on_reset_funcs *funcs)
-{
-	if (!funcs)
-		return;
-
-	/* Ensure the reset_callback_list is initialized */
-	if (!adev->sdma.reset_callback_list.next) {
-		INIT_LIST_HEAD(&adev->sdma.reset_callback_list);
-	}
-	/* Initialize the list node in the callback structure */
-	INIT_LIST_HEAD(&funcs->list);
-
-	/* Add the callback structure to the global list */
-	list_add_tail(&funcs->list, &adev->sdma.reset_callback_list);
-}
-
 static int amdgpu_sdma_soft_reset(struct amdgpu_device *adev, u32 instance_id)
 {
 	u32 soft_reset;
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h +0 -8
index 965169320065..1b6d304c6074 100644
@@ -98,13 +98,6 @@ struct amdgpu_sdma_ras {
 	struct amdgpu_ras_block_object ras_block;
 };
 
-struct sdma_on_reset_funcs {
-	int (*pre_reset)(struct amdgpu_device *adev, uint32_t instance_id);
-	int (*post_reset)(struct amdgpu_device *adev, uint32_t instance_id);
-	/* Linked list node to store this structure in a list; */
-	struct list_head list;
-};
-
 struct amdgpu_sdma {
 	struct amdgpu_sdma_instance instance[AMDGPU_MAX_SDMA_INSTANCES];
 	struct amdgpu_irq_src	trap_irq;
@@ -168,7 +161,6 @@ struct amdgpu_buffer_funcs {
 				 uint32_t byte_count);
 };
 
-void amdgpu_sdma_register_on_reset_callbacks(struct amdgpu_device *adev, struct sdma_on_reset_funcs *funcs);
 int amdgpu_sdma_reset_engine(struct amdgpu_device *adev, uint32_t instance_id, bool suspend_user_queues);
 
 #define amdgpu_emit_copy_buffer(adev, ib, s, d, b, t) (adev)->mman.buffer_funcs->emit_copy_buffer((ib),  (s), (d), (b), (t))
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +0 -12
index c1f7ccff9c4e..cb3148324e90 100644
@@ -106,7 +106,6 @@ static void sdma_v4_4_2_set_buffer_funcs(struct amdgpu_device *adev);
 static void sdma_v4_4_2_set_vm_pte_funcs(struct amdgpu_device *adev);
 static void sdma_v4_4_2_set_irq_funcs(struct amdgpu_device *adev);
 static void sdma_v4_4_2_set_ras_funcs(struct amdgpu_device *adev);
-static void sdma_v4_4_2_set_engine_reset_funcs(struct amdgpu_device *adev);
 static void sdma_v4_4_2_update_reset_mask(struct amdgpu_device *adev);
 
 static u32 sdma_v4_4_2_get_reg_offset(struct amdgpu_device *adev,
@@ -1353,7 +1352,6 @@ static int sdma_v4_4_2_early_init(struct amdgpu_ip_block *ip_block)
 	sdma_v4_4_2_set_vm_pte_funcs(adev);
 	sdma_v4_4_2_set_irq_funcs(adev);
 	sdma_v4_4_2_set_ras_funcs(adev);
-	sdma_v4_4_2_set_engine_reset_funcs(adev);
 
 	return 0;
 }
@@ -1728,16 +1726,6 @@ static int sdma_v4_4_2_restore_queue(struct amdgpu_device *adev, uint32_t instan
 	return sdma_v4_4_2_inst_start(adev, inst_mask, true);
 }
 
-static struct sdma_on_reset_funcs sdma_v4_4_2_engine_reset_funcs = {
-	.pre_reset = sdma_v4_4_2_stop_queue,
-	.post_reset = sdma_v4_4_2_restore_queue,
-};
-
-static void sdma_v4_4_2_set_engine_reset_funcs(struct amdgpu_device *adev)
-{
-	amdgpu_sdma_register_on_reset_callbacks(adev, &sdma_v4_4_2_engine_reset_funcs);
-}
-
 static int sdma_v4_4_2_set_trap_irq_state(struct amdgpu_device *adev,
 					struct amdgpu_irq_src *source,
 					unsigned type,
Signature · 1 line
2.25.1
maintainer
#7 lore raw
In reply to [email protected]

Am 12.03.25 um 08:59 schrieb [email protected]:

Quoted 70 lines

From: "[email protected]" <[email protected]>

Since KFD no longer registers its own callbacks for SDMA resets, and only KGD uses the reset mechanism, we can simplify the SDMA reset flow by directly calling the ring's stop_queue and start_queue functions. This patch removes the dynamic callback mechanism and prepares for its eventual deprecation.

The current SDMA reset mechanism uses a dynamic callback registration system to allow both KFD and KGD to register pre-reset and post-reset functions. However, KFD no longer registers its callbacks, and the reset logic is now entirely handled by KGD.
This makes the dynamic callback mechanism unnecessary and adds complexity to the code.

1. **Remove Dynamic Callbacks**:
- The pre_reset and post_reset callback invocations in amdgpu_sdma_reset_engine are removed.
- Instead, the ring's stop_queue and start_queue functions are called directly during the reset process.

2. **Add stop_queue and start_queue to Ring Functions**:
- The amdgpu_ring_funcs structure is extended to include stop_queue and start_queue functions.
- These functions are implemented in the SDMA version-specific code (e.g., sdma_v4_4_2_stop_queue and sdma_v4_4_2_restore_queue).

3. **Prepare for Deprecation of Dynamic Mechanism**:
- By removing the callback invocations, this patch prepares the codebase for the eventual removal of the dynamic callback registration mechanism.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h |  2 ++
 drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c | 33 ++----------------------
 drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c |  2 ++
 3 files changed, 6 insertions(+), 31 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h +2 -0
index b4fd1e17205e..1c52ff92ea26 100644
@@ -237,6 +237,8 @@ struct amdgpu_ring_funcs {
 	void (*patch_ce)(struct amdgpu_ring *ring, unsigned offset);
 	void (*patch_de)(struct amdgpu_ring *ring, unsigned offset);
 	int (*reset)(struct amdgpu_ring *ring, unsigned int vmid);
+	int (*stop_queue)(struct amdgpu_device *adev, uint32_t instance_id);
+	int (*start_queue)(struct amdgpu_device *adev, uint32_t instance_id);
 	void (*emit_cleaner_shader)(struct amdgpu_ring *ring);
 	bool (*is_guilty)(struct amdgpu_ring *ring);
 };
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +0 -10
index 39669f8788a7..b1f4a11ad0c9 100644
@@ -534,16 +534,10 @@ void amdgpu_sdma_register_on_reset_callbacks(struct amdgpu_device *adev, struct
  * @instance_id: ID of the SDMA engine instance to reset
  * @suspend_user_queues: check if suspend user queue.
  *
- * This function performs the following steps:
- * 1. Calls all registered pre_reset callbacks to allow KFD and AMDGPU to save their state.
- * 2. Resets the specified SDMA engine instance.
- * 3. Calls all registered post_reset callbacks to allow KFD and AMDGPU to restore their state.
- *
  * Returns: 0 on success, or a negative error code on failure.
  */
 int amdgpu_sdma_reset_engine(struct amdgpu_device *adev, uint32_t instance_id, bool suspend_user_queues)
 {
-	struct sdma_on_reset_funcs *funcs;
 	int ret = 0;
 	struct amdgpu_sdma_instance *sdma_instance = &adev->sdma.instance[instance_id];;
 	struct amdgpu_ring *gfx_ring = &sdma_instance->ring;
@@ -571,19 +565,7 @@ int amdgpu_sdma_reset_engine(struct amdgpu_device *adev, uint32_t instance_id, b
 		page_sched_stopped = true;
 	}
 
-	/* Invoke all registered pre_reset callbacks */
-	list_for_each_entry(funcs, &adev->sdma.reset_callback_list, list) {
-		if (funcs->pre_reset) {
-			ret = funcs->pre_reset(adev, instance_id);

drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c int amdgpu_sdma_reset_engine(struct amdgpu_device *adev, uint32_t instance_id, b · line 568

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +1 -9
-			if (ret) {
-				dev_err(adev->dev,
-				"beforeReset callback failed for instance %u: %d\n",
-					instance_id, ret);
-				goto exit;
-			}
-		}
-	}
-
+	gfx_ring->funcs->stop_queue(adev, instance_id);

Yeah that starts to look good. Question here is who is calling amdgpu_sdma_reset_engine()?

If this call comes from engine specific code we might not need the start/stop_queue callbacks all together.

Regards,
Christian.

Quoted 36 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +1 -12
 	/* Perform the SDMA reset for the specified instance */
 	ret = amdgpu_dpm_reset_sdma(adev, 1 << instance_id);
 	if (ret) {
@@ -591,18 +573,7 @@ int amdgpu_sdma_reset_engine(struct amdgpu_device *adev, uint32_t instance_id, b
 		goto exit;
 	}
 
-	/* Invoke all registered post_reset callbacks */
-	list_for_each_entry(funcs, &adev->sdma.reset_callback_list, list) {
-		if (funcs->post_reset) {
-			ret = funcs->post_reset(adev, instance_id);
-			if (ret) {
-				dev_err(adev->dev,
-				"afterReset callback failed for instance %u: %d\n",
-					instance_id, ret);
-				goto exit;
-			}
-		}
-	}
+	gfx_ring->funcs->start_queue(adev, instance_id);
 
 exit:
 	/* Restart the scheduler's work queue for the GFX and page rings
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +2 -0
index fd34dc138081..c1f7ccff9c4e 100644
@@ -2132,6 +2132,8 @@ static const struct amdgpu_ring_funcs sdma_v4_4_2_ring_funcs = {
 	.emit_reg_wait = sdma_v4_4_2_ring_emit_reg_wait,
 	.emit_reg_write_reg_wait = amdgpu_ring_emit_reg_write_reg_wait_helper,
 	.reset = sdma_v4_4_2_reset_queue,
+	.stop_queue = sdma_v4_4_2_stop_queue,
+	.start_queue = sdma_v4_4_2_restore_queue,
 	.is_guilty = sdma_v4_4_2_ring_is_guilty,
 };
 
#8 lore raw

[AMD Official Use Only - AMD Internal Distribution Only]

-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: Wednesday, March 12, 2025 4:07 PM
To: Zhang, Jesse(Jie) <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Kim, Jonathan <[email protected]>; Zhu, Jiadong <[email protected]>
Subject: Re: [PATCH 1/7] drm/amd/amdgpu: Simplify SDMA reset mechanism by removing dynamic callbacks

Am 12.03.25 um 08:59 schrieb [email protected]:

Quoted 72 lines

From: "[email protected]" <[email protected]>

Since KFD no longer registers its own callbacks for SDMA resets, and
only KGD uses the reset mechanism, we can simplify the SDMA reset flow by directly calling the ring's stop_queue and start_queue functions. This patch removes the dynamic callback mechanism and prepares for its eventual deprecation.

The current SDMA reset mechanism uses a dynamic callback registration system to allow both KFD and KGD to register pre-reset and post-reset functions. However, KFD no longer registers its callbacks, and the reset logic is now entirely handled by KGD.
This makes the dynamic callback mechanism unnecessary and adds complexity to the code.

1. **Remove Dynamic Callbacks**:
- The pre_reset and post_reset callback invocations in amdgpu_sdma_reset_engine are removed.
- Instead, the ring's stop_queue and start_queue functions are called directly during the reset process.

2. **Add stop_queue and start_queue to Ring Functions**:
- The amdgpu_ring_funcs structure is extended to include stop_queue and start_queue functions.
- These functions are implemented in the SDMA version-specific code (e.g., sdma_v4_4_2_stop_queue and sdma_v4_4_2_restore_queue).

3. **Prepare for Deprecation of Dynamic Mechanism**:
- By removing the callback invocations, this patch prepares the codebase for the eventual removal of the dynamic callback registration mechanism.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h |  2 ++
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c | 33 ++----------------------
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c |  2 ++
 3 files changed, 6 insertions(+), 31 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h +3 -0
index b4fd1e17205e..1c52ff92ea26 100644
@@ -237,6 +237,8 @@ struct amdgpu_ring_funcs {
      void (*patch_ce)(struct amdgpu_ring *ring, unsigned offset);
      void (*patch_de)(struct amdgpu_ring *ring, unsigned offset);
      int (*reset)(struct amdgpu_ring *ring, unsigned int vmid);
+     int (*stop_queue)(struct amdgpu_device *adev, uint32_t instance_id);
+     int (*start_queue)(struct amdgpu_device *adev, uint32_t
+instance_id);
      void (*emit_cleaner_shader)(struct amdgpu_ring *ring);
      bool (*is_guilty)(struct amdgpu_ring *ring);  }; diff --git

a/drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c
b/drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c
index 39669f8788a7..b1f4a11ad0c9 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +1 -10
@@ -534,16 +534,10 @@ void amdgpu_sdma_register_on_reset_callbacks(struct amdgpu_device *adev, struct
  * @instance_id: ID of the SDMA engine instance to reset
  * @suspend_user_queues: check if suspend user queue.
  *
- * This function performs the following steps:
- * 1. Calls all registered pre_reset callbacks to allow KFD and AMDGPU to save their state.
- * 2. Resets the specified SDMA engine instance.
- * 3. Calls all registered post_reset callbacks to allow KFD and AMDGPU to restore their state.
- *
  * Returns: 0 on success, or a negative error code on failure.
  */
 int amdgpu_sdma_reset_engine(struct amdgpu_device *adev, uint32_t
 instance_id, bool suspend_user_queues)  {
-     struct sdma_on_reset_funcs *funcs;
      int ret = 0;
      struct amdgpu_sdma_instance *sdma_instance = &adev->sdma.instance[instance_id];;
      struct amdgpu_ring *gfx_ring = &sdma_instance->ring; @@ -571,19
+565,7 @@ int amdgpu_sdma_reset_engine(struct amdgpu_device *adev, uint32_t instance_id, b
              page_sched_stopped = true;
      }
 
-     /* Invoke all registered pre_reset callbacks */
-     list_for_each_entry(funcs, &adev->sdma.reset_callback_list, list) {
-             if (funcs->pre_reset) {
-                     ret = funcs->pre_reset(adev, instance_id);

drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c void amdgpu_sdma_register_on_reset_callbacks(struct amdgpu_device *adev, struct

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +1 -9
-                     if (ret) {
-                             dev_err(adev->dev,
-                             "beforeReset callback failed for instance %u: %d\n",
-                                     instance_id, ret);
-                             goto exit;
-                     }
-             }
-     }
-
+     gfx_ring->funcs->stop_queue(adev, instance_id);

Yeah that starts to look good. Question here is who is calling amdgpu_sdma_reset_engine()?

If this call comes from engine specific code we might not need the start/stop_queue callbacks all together.

Kfd and sdma v4/v5/v5_2 will call amdgpu_sdma_reset_engine, and start/stop_queue callbacks are only implemented in sdmav4/sdmav5/sdma5_2.

Thanks
Jesse

Regards,
Christian.

Quoted 36 lines
      /* Perform the SDMA reset for the specified instance */
      ret = amdgpu_dpm_reset_sdma(adev, 1 << instance_id);
      if (ret) {
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +1 -12
@@ -591,18 +573,7 @@ int amdgpu_sdma_reset_engine(struct amdgpu_device *adev, uint32_t instance_id, b
              goto exit;
      }
 
-     /* Invoke all registered post_reset callbacks */
-     list_for_each_entry(funcs, &adev->sdma.reset_callback_list, list) {
-             if (funcs->post_reset) {
-                     ret = funcs->post_reset(adev, instance_id);
-                     if (ret) {
-                             dev_err(adev->dev,
-                             "afterReset callback failed for instance %u: %d\n",
-                                     instance_id, ret);
-                             goto exit;
-                     }
-             }
-     }
+     gfx_ring->funcs->start_queue(adev, instance_id);
 
 exit:
      /* Restart the scheduler's work queue for the GFX and page rings
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +2 -0
index fd34dc138081..c1f7ccff9c4e 100644
@@ -2132,6 +2132,8 @@ static const struct amdgpu_ring_funcs sdma_v4_4_2_ring_funcs = {
      .emit_reg_wait = sdma_v4_4_2_ring_emit_reg_wait,
      .emit_reg_write_reg_wait = amdgpu_ring_emit_reg_write_reg_wait_helper,
      .reset = sdma_v4_4_2_reset_queue,
+     .stop_queue = sdma_v4_4_2_stop_queue,
+     .start_queue = sdma_v4_4_2_restore_queue,
      .is_guilty = sdma_v4_4_2_ring_is_guilty,  };
 
maintainer
#9 lore raw

Am 12.03.25 um 09:15 schrieb Zhang, Jesse(Jie):

Quoted 8 lines

[SNIP9

drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c int amdgpu_sdma_reset_engine(struct amdgpu_device *adev, uint32_t instance_id, b · line 568

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +1 -1
-
+     gfx_ring->funcs->stop_queue(adev, instance_id);

Yeah that starts to look good. Question here is who is calling amdgpu_sdma_reset_engine()?

If this call comes from engine specific code we might not need the start/stop_queue callbacks all together.

Kfd and sdma v4/v5/v5_2 will call amdgpu_sdma_reset_engine, and start/stop_queue callbacks are only implemented in sdmav4/sdmav5/sdma5_2.

Why would the KFD call this as well? Because it detects an issue with a SDMA user queue  If yes I would rather suggest that the KFD calls the reset function of the paging queue.

Since this reset function is specific to the SDMA HW generation anyway you don't need those extra functions to abstract starting and stopping of the queue for each HW generation.

Regards,
Christian.

Quoted 43 lines

Thanks
Jesse

Regards,
Christian.

Quoted 36 lines
      /* Perform the SDMA reset for the specified instance */
      ret = amdgpu_dpm_reset_sdma(adev, 1 << instance_id);
      if (ret) {
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +1 -12
@@ -591,18 +573,7 @@ int amdgpu_sdma_reset_engine(struct amdgpu_device *adev, uint32_t instance_id, b
              goto exit;
      }
 
-     /* Invoke all registered post_reset callbacks */
-     list_for_each_entry(funcs, &adev->sdma.reset_callback_list, list) {
-             if (funcs->post_reset) {
-                     ret = funcs->post_reset(adev, instance_id);
-                     if (ret) {
-                             dev_err(adev->dev,
-                             "afterReset callback failed for instance %u: %d\n",
-                                     instance_id, ret);
-                             goto exit;
-                     }
-             }
-     }
+     gfx_ring->funcs->start_queue(adev, instance_id);
 
 exit:
      /* Restart the scheduler's work queue for the GFX and page rings
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +2 -0
index fd34dc138081..c1f7ccff9c4e 100644
@@ -2132,6 +2132,8 @@ static const struct amdgpu_ring_funcs sdma_v4_4_2_ring_funcs = {
      .emit_reg_wait = sdma_v4_4_2_ring_emit_reg_wait,
      .emit_reg_write_reg_wait = amdgpu_ring_emit_reg_write_reg_wait_helper,
      .reset = sdma_v4_4_2_reset_queue,
+     .stop_queue = sdma_v4_4_2_stop_queue,
+     .start_queue = sdma_v4_4_2_restore_queue,
      .is_guilty = sdma_v4_4_2_ring_is_guilty,  };
 
#10 lore raw

[AMD Official Use Only - AMD Internal Distribution Only]

From: Koenig, Christian <[email protected]>
Sent: Wednesday, March 12, 2025 4:39 PM
To: Zhang, Jesse(Jie) <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Kim, Jonathan <[email protected]>; Zhu, Jiadong <[email protected]>
Subject: Re: [PATCH 1/7] drm/amd/amdgpu: Simplify SDMA reset mechanism by removing dynamic callbacks

Am 12.03.25 um 09:15 schrieb Zhang, Jesse(Jie):

[SNIP9

-

+ gfx_ring->funcs->stop_queue(adev, instance_id);

Yeah that starts to look good. Question here is who is calling amdgpu_sdma_reset_engine()?

If this call comes from engine specific code we might not need the start/stop_queue callbacks all together.

Kfd and sdma v4/v5/v5_2 will call amdgpu_sdma_reset_engine, and start/stop_queue callbacks are only implemented in sdmav4/sdmav5/sdma5_2.

Why would the KFD call this as well? Because it detects an issue with a SDMA user queue If yes I would rather suggest that the KFD calls the reset function of the paging queue.

Since this reset function is specific to the SDMA HW generation anyway you don't need those extra functions to abstract starting and stopping of the queue for each HW generation.

kfd can't call reset function directly, unless we add a parameter src to distinguish kfd and kgd in reset function, like this:
int (*reset)(struct amdgpu_ring *ring, unsigned int vmid, int src );
As Alex said in another thread,
We need to distinguish kfd and kgd in reset.
If kfd triggers a reset, kgd must save healthy jobs and recover jobs after reset.
If kgd triggers a reset, kgd must abandon bad jobs after reset.(and perhaps kfd needs to save its healthy jobs for recovery).

If we can add a parameter, I am ok for that solution too.

Additionally:
For sdma6/7, when a queue reset fails, we may need to fall back to an engine reset for a attempt.

Thanks
Jesse

Regards,
Christian.

Thanks

Jesse

Regards,

Christian.

      /* Perform the SDMA reset for the specified instance */

      ret = amdgpu_dpm_reset_sdma(adev, 1 << instance_id);

      if (ret) {

@@ -591,18 +573,7 @@ int amdgpu_sdma_reset_engine(struct amdgpu_device *adev, uint32_t instance_id, b

              goto exit;

      }

- /* Invoke all registered post_reset callbacks */

- list_for_each_entry(funcs, &adev->sdma.reset_callback_list, list) {

- if (funcs->post_reset) {

- ret = funcs->post_reset(adev, instance_id);

- if (ret) {

- dev_err(adev->dev,

- "afterReset callback failed for instance %u: %d\n",

- instance_id, ret);

- goto exit;

- }

- }

- }

+ gfx_ring->funcs->start_queue(adev, instance_id);

exit:

      /* Restart the scheduler's work queue for the GFX and page rings
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c

index fd34dc138081..c1f7ccff9c4e 100644

--- a/drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c

+++ b/drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c

@@ -2132,6 +2132,8 @@ static const struct amdgpu_ring_funcs sdma_v4_4_2_ring_funcs = {

      .emit_reg_wait = sdma_v4_4_2_ring_emit_reg_wait,

      .emit_reg_write_reg_wait = amdgpu_ring_emit_reg_write_reg_wait_helper,

      .reset = sdma_v4_4_2_reset_queue,

+ .stop_queue = sdma_v4_4_2_stop_queue,

+ .start_queue = sdma_v4_4_2_restore_queue,

      .is_guilty = sdma_v4_4_2_ring_is_guilty,  };
maintainer
#11 lore raw

Am 12.03.25 um 10:23 schrieb Zhang, Jesse(Jie):

Quoted 45 lines

[AMD Official Use Only - AMD Internal Distribution Only]

*From:*Koenig, Christian <[email protected]>
*Sent:* Wednesday, March 12, 2025 4:39 PM
*To:* Zhang, Jesse(Jie) <[email protected]>; [email protected]
*Cc:* Deucher, Alexander <[email protected]>; Kim, Jonathan <[email protected]>; Zhu, Jiadong <[email protected]> *Subject:* Re: [PATCH 1/7] drm/amd/amdgpu: Simplify SDMA reset mechanism by removing dynamic callbacks

Am 12.03.25 um 09:15 schrieb Zhang, Jesse(Jie):

[SNIP9

-

+     gfx_ring->funcs->stop_queue(adev, instance_id);

Yeah that starts to look good. Question here is who is calling amdgpu_sdma_reset_engine()?

If this call comes from engine specific code we might not need the start/stop_queue callbacks all together.

    Kfd and sdma v4/v5/v5_2 will call amdgpu_sdma_reset_engine, and start/stop_queue callbacks are only implemented in sdmav4/sdmav5/sdma5_2.

Why would the KFD call this as well? Because it detects an issue with a SDMA user queue  If yes I would rather suggest that the KFD calls the reset function of the paging queue.

Since this reset function is specific to the SDMA HW generation anyway you don't need those extra functions to abstract starting and stopping of the queue for each HW generation.

kfd can't call reset function directly, unless we add a parameter src  to distinguish kfd and kgd in reset function, like this:

int (*reset)(struct amdgpu_ring *ring, unsigned int vmid, */int src/* );

Quoted 8 lines

As Alex said in another thread,

We need to distinguish  kfd and kgd  in reset.

If kfd triggers a reset, kgd must save healthy jobs and recover jobs after reset.

If kgd triggers a reset, kgd must abandon bad jobs after reset.(and perhaps kfd needs to save its healthy jobs for recovery).

I don't think the source of the reset should be relevant to the reset procedure.

The source is basically just the first one who runs into a timeout, that can be both KFD and KGD.

But the cause of the timeout is not necessary the one who signals that a timeout happens.

So as far as I can see you should not have that as parameter either.

Quoted 10 lines

If we can add a parameter, I am ok for that solution too.

Additionally:

For sdma6/7, when a queue reset fails, we may need to fall back to an engine reset for a attempt.

Yeah, but that should be trivial.

Regards,
Christian.

Quoted 103 lines

Thanks

Jesse

Regards,
Christian.

     

     

    Thanks

    Jesse

     

    Regards,

    Christian.

     

              /* Perform the SDMA reset for the specified instance */

              ret = amdgpu_dpm_reset_sdma(adev, 1 << instance_id);

              if (ret) {

        @@ -591,18 +573,7 @@ int amdgpu_sdma_reset_engine(struct amdgpu_device *adev, uint32_t instance_id, b

                      goto exit;

              }

         

        -     /* Invoke all registered post_reset callbacks */

        -     list_for_each_entry(funcs, &adev->sdma.reset_callback_list, list) {

        -             if (funcs->post_reset) {

        -                     ret = funcs->post_reset(adev, instance_id);

        -                     if (ret) {

        -                             dev_err(adev->dev,

        -                             "afterReset callback failed for instance %u: %d\n",

        -                                     instance_id, ret);

        -                             goto exit;

        -                     }

        -             }

        -     }

        +     gfx_ring->funcs->start_queue(adev, instance_id);

         

         exit:

              /* Restart the scheduler's work queue for the GFX and page rings

        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 fd34dc138081..c1f7ccff9c4e 100644

        --- a/drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c

        +++ b/drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c

        @@ -2132,6 +2132,8 @@ static const struct amdgpu_ring_funcs sdma_v4_4_2_ring_funcs = {

              .emit_reg_wait = sdma_v4_4_2_ring_emit_reg_wait,

              .emit_reg_write_reg_wait = amdgpu_ring_emit_reg_write_reg_wait_helper,

              .reset = sdma_v4_4_2_reset_queue,

        +     .stop_queue = sdma_v4_4_2_stop_queue,

        +     .start_queue = sdma_v4_4_2_restore_queue,

              .is_guilty = sdma_v4_4_2_ring_is_guilty,  };

         

     

#12 lore raw
In reply to Zhang, Jesse(Jie)

I think as long as the locking is correct, the src shouldn't matter. You just need to stop the kernel queues (and save state) and evict the user queues (since HWS is responsible for saving the MQDs of the non-guilty user queues). If KFD detected the hang (e.g., queue eviction fails when called for memory pressure, etc.), we just need to make sure that it's ok for the sdma reset routine to call evict queues again even if it was already called (presumably it should exit early since the queues are already evicted). If KGD initiates the reset, it will call into KFD to evict queues. We just need to make sure the evict queues function we call just evicts the queues and doesn't also try and reset.

Alex

Quoted 165 lines · Jesse(Jie)

[AMD Official Use Only - AMD Internal Distribution Only]

From: Koenig, Christian <[email protected]>
Sent: Wednesday, March 12, 2025 4:39 PM
To: Zhang, Jesse(Jie) <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Kim, Jonathan <[email protected]>; Zhu, Jiadong <[email protected]>
Subject: Re: [PATCH 1/7] drm/amd/amdgpu: Simplify SDMA reset mechanism by removing dynamic callbacks

Am 12.03.25 um 09:15 schrieb Zhang, Jesse(Jie):

[SNIP9

(quoted diff) +1 -1
-
 
+     gfx_ring->funcs->stop_queue(adev, instance_id);

Yeah that starts to look good. Question here is who is calling amdgpu_sdma_reset_engine()?

If this call comes from engine specific code we might not need the start/stop_queue callbacks all together.

Kfd and sdma v4/v5/v5_2 will call amdgpu_sdma_reset_engine, and start/stop_queue callbacks are only implemented in sdmav4/sdmav5/sdma5_2.

Why would the KFD call this as well? Because it detects an issue with a SDMA user queue If yes I would rather suggest that the KFD calls the reset function of the paging queue.

Since this reset function is specific to the SDMA HW generation anyway you don't need those extra functions to abstract starting and stopping of the queue for each HW generation.

kfd can't call reset function directly, unless we add a parameter src to distinguish kfd and kgd in reset function, like this:

int (*reset)(struct amdgpu_ring *ring, unsigned int vmid, int src );

As Alex said in another thread,

We need to distinguish kfd and kgd in reset.

If kfd triggers a reset, kgd must save healthy jobs and recover jobs after reset.

If kgd triggers a reset, kgd must abandon bad jobs after reset.(and perhaps kfd needs to save its healthy jobs for recovery).

If we can add a parameter, I am ok for that solution too.

Additionally:

For sdma6/7, when a queue reset fails, we may need to fall back to an engine reset for a attempt.

Thanks

Jesse

Regards,
Christian.

Thanks

Jesse

Regards,

Christian.

      /* Perform the SDMA reset for the specified instance */

      ret = amdgpu_dpm_reset_sdma(adev, 1 << instance_id);

      if (ret) {
(quoted diff) +1 -12
@@ -591,18 +573,7 @@ int amdgpu_sdma_reset_engine(struct amdgpu_device *adev, uint32_t instance_id, b
 
              goto exit;
 
      }
 
 
 
-     /* Invoke all registered post_reset callbacks */
 
-     list_for_each_entry(funcs, &adev->sdma.reset_callback_list, list) {
 
-             if (funcs->post_reset) {
 
-                     ret = funcs->post_reset(adev, instance_id);
 
-                     if (ret) {
 
-                             dev_err(adev->dev,
 
-                             "afterReset callback failed for instance %u: %d\n",
 
-                                     instance_id, ret);
 
-                             goto exit;
 
-                     }
 
-             }
 
-     }
 
+     gfx_ring->funcs->start_queue(adev, instance_id);
 
 
 
 exit:
 
      /* Restart the scheduler's work queue for the GFX and page rings
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c

index fd34dc138081..c1f7ccff9c4e 100644

--- a/drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c

+++ b/drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c

(quoted diff) +2 -0
@@ -2132,6 +2132,8 @@ static const struct amdgpu_ring_funcs sdma_v4_4_2_ring_funcs = {
 
      .emit_reg_wait = sdma_v4_4_2_ring_emit_reg_wait,
 
      .emit_reg_write_reg_wait = amdgpu_ring_emit_reg_write_reg_wait_helper,
 
      .reset = sdma_v4_4_2_reset_queue,
 
+     .stop_queue = sdma_v4_4_2_stop_queue,
 
+     .start_queue = sdma_v4_4_2_restore_queue,
 
      .is_guilty = sdma_v4_4_2_ring_is_guilty,  };
#13 lore raw

[Public]

Quoted 11 lines

-----Original Message-----
From: Alex Deucher <[email protected]>
Sent: Thursday, March 13, 2025 10:38 AM
To: Zhang, Jesse(Jie) <[email protected]>
Cc: Koenig, Christian <[email protected]>; amd- [email protected]; Deucher, Alexander <[email protected]>; Kim, Jonathan <[email protected]>; Zhu, Jiadong <[email protected]>
Subject: Re: [PATCH 1/7] drm/amd/amdgpu: Simplify SDMA reset mechanism by removing dynamic callbacks

Quoted 11 lines

I think as long as the locking is correct, the src shouldn't matter. You just need to stop the kernel queues (and save state) and evict the user queues (since HWS is responsible for saving the MQDs of the non-guilty user queues). If KFD detected the hang (e.g., queue eviction fails when called for memory pressure, etc.), we just need to make sure that it's ok for the sdma reset routine to call evict queues again even if it was already called (presumably it should exit early since the queues are already evicted). If KGD initiates the reset, it will call into KFD to evict queues. We just need to make sure the evict queues function we call just evicts the queues and doesn't also try and reset.

If we're removing the src parameter, we need to be careful we don't end up in a double lock scenario in the KFD.
i.e. kgd inits reset -> kfd detects hang on kgd reset trigger and calls back to kgd -> amdgpu_amdkfd_suspend gets called again but is blocked on previous suspend call from original kgd reset (which is holding a bunch of KFD locks) while KFD is trying to clean up immediately.

Safest way to remove the parameter seems like to move the KFD suspend/restore outside of the common call and have KGD call suspend/resume when it's calling the common call itself.

Jon

Quoted 184 lines

Alex

Quoted 8 lines · Jesse(Jie)

[AMD Official Use Only - AMD Internal Distribution Only]

Quoted 4 lines

From: Koenig, Christian <[email protected]>
Sent: Wednesday, March 12, 2025 4:39 PM
To: Zhang, Jesse(Jie) <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Kim, Jonathan

<[email protected]>; Zhu, Jiadong <[email protected]>

Quoted 1 line

Subject: Re: [PATCH 1/7] drm/amd/amdgpu: Simplify SDMA reset mechanism by

removing dynamic callbacks

Quoted 13 lines

Am 12.03.25 um 09:15 schrieb Zhang, Jesse(Jie):

[SNIP9

(quoted diff) +1 -1
-
 
+     gfx_ring->funcs->stop_queue(adev, instance_id);
Quoted 1 line

Yeah that starts to look good. Question here is who is calling

amdgpu_sdma_reset_engine()?

Quoted 4 lines

If this call comes from engine specific code we might not need the

start/stop_queue callbacks all together.

Quoted 4 lines

Kfd and sdma v4/v5/v5_2 will call amdgpu_sdma_reset_engine, and

start/stop_queue callbacks are only implemented in sdmav4/sdmav5/sdma5_2.

Quoted 3 lines

Why would the KFD call this as well? Because it detects an issue with a SDMA

user queue If yes I would rather suggest that the KFD calls the reset function of the paging queue.

Quoted 2 lines

Since this reset function is specific to the SDMA HW generation anyway you don't

need those extra functions to abstract starting and stopping of the queue for each HW generation.

Quoted 2 lines

kfd can't call reset function directly, unless we add a parameter src to distinguish

kfd and kgd in reset function, like this:

Quoted 10 lines

int (*reset)(struct amdgpu_ring *ring, unsigned int vmid, int src );

As Alex said in another thread,

We need to distinguish kfd and kgd in reset.

If kfd triggers a reset, kgd must save healthy jobs and recover jobs after reset.

If kgd triggers a reset, kgd must abandon bad jobs after reset.(and perhaps kfd

needs to save its healthy jobs for recovery).

Quoted 10 lines

If we can add a parameter, I am ok for that solution too.

Additionally:

For sdma6/7, when a queue reset fails, we may need to fall back to an engine

reset for a attempt.

Review int amdgpu_sdma_reset_engine(struct amdgpu_device

Quoted 35 lines

Thanks

Jesse

Regards,
Christian.

Thanks

Jesse

Regards,

Christian.

      /* Perform the SDMA reset for the specified instance */

      ret = amdgpu_dpm_reset_sdma(adev, 1 << instance_id);

      if (ret) {
(quoted diff) +0 -0
@@ -591,18 +573,7 @@ int amdgpu_sdma_reset_engine(struct amdgpu_device

*adev, uint32_t instance_id, b

Review static const struct amdgpu_ring_funcs

Quoted 50 lines
(quoted diff) +1 -12
              goto exit;
 
      }
 
 
 
-     /* Invoke all registered post_reset callbacks */
 
-     list_for_each_entry(funcs, &adev->sdma.reset_callback_list, list) {
 
-             if (funcs->post_reset) {
 
-                     ret = funcs->post_reset(adev, instance_id);
 
-                     if (ret) {
 
-                             dev_err(adev->dev,
 
-                             "afterReset callback failed for instance %u: %d\n",
 
-                                     instance_id, ret);
 
-                             goto exit;
 
-                     }
 
-             }
 
-     }
 
+     gfx_ring->funcs->start_queue(adev, instance_id);
 
 
 
 exit:
 
      /* Restart the scheduler's work queue for the GFX and page rings
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c

index fd34dc138081..c1f7ccff9c4e 100644

--- a/drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c

+++ b/drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c

(quoted diff) +0 -0
@@ -2132,6 +2132,8 @@ static const struct amdgpu_ring_funcs

sdma_v4_4_2_ring_funcs = {

Quoted 18 lines
(quoted diff) +2 -0
      .emit_reg_wait = sdma_v4_4_2_ring_emit_reg_wait,
 
      .emit_reg_write_reg_wait = amdgpu_ring_emit_reg_write_reg_wait_helper,
 
      .reset = sdma_v4_4_2_reset_queue,
 
+     .stop_queue = sdma_v4_4_2_stop_queue,
 
+     .start_queue = sdma_v4_4_2_restore_queue,
 
      .is_guilty = sdma_v4_4_2_ring_is_guilty,  };
#14 lore raw
Quoted 26 lines · Jonathan

[Public]

Quoted 11 lines

-----Original Message-----
From: Alex Deucher <[email protected]>
Sent: Thursday, March 13, 2025 10:38 AM
To: Zhang, Jesse(Jie) <[email protected]>
Cc: Koenig, Christian <[email protected]>; amd- [email protected]; Deucher, Alexander <[email protected]>; Kim, Jonathan <[email protected]>; Zhu, Jiadong <[email protected]>
Subject: Re: [PATCH 1/7] drm/amd/amdgpu: Simplify SDMA reset mechanism by removing dynamic callbacks

Quoted 11 lines

I think as long as the locking is correct, the src shouldn't matter. You just need to stop the kernel queues (and save state) and evict the user queues (since HWS is responsible for saving the MQDs of the non-guilty user queues). If KFD detected the hang (e.g., queue eviction fails when called for memory pressure, etc.), we just need to make sure that it's ok for the sdma reset routine to call evict queues again even if it was already called (presumably it should exit early since the queues are already evicted). If KGD initiates the reset, it will call into KFD to evict queues. We just need to make sure the evict queues function we call just evicts the queues and doesn't also try and reset.

Quoted 3 lines

If we're removing the src parameter, we need to be careful we don't end up in a double lock scenario in the KFD.
i.e. kgd inits reset -> kfd detects hang on kgd reset trigger and calls back to kgd -> amdgpu_amdkfd_suspend gets called again but is blocked on previous suspend call from original kgd reset (which is holding a bunch of KFD locks) while KFD is trying to clean up immediately.

How would this work even with the src parameter? I think you could still get into that case. E.g., KGD detects a hang and initiates an engine reset. In parallel, KFD tries to unmap all queues for some reason and detects a hang, so it tries to reset SDMA. Assuming there is a lock that protects SDMA reset, that should work. However, it requires that the prerequisites on each side don't attempt to reset anything.

sdma_engine_reset()
{

KFD pre reset requirements
1. unmap all SDMA queues (CP firmware will save non-guilty state in MQDs)
2. detect guilty queue

KGD pre reset requirements:
1. stop relevant drm schedulers
2. detect guilt queue
3. save non-guilty queue state

Do engine reset

KGD post reset requirements:
1. restore non-guilty queue state
2. start relevant drm schedulers

KFD post reset requirements
1. map all non-guilty SDMA queues

}

I think what we need on the KFD side, if we don't have it already, is a function to just umap queues and update guilty state, but not to attempt to reset anything. Then on the KFD side, in your normal flows, you could call this function to unamp queues and update queue state, and then after calling that walk through the queue state and trigger any resets based on queues flagged as bad. On the KFD side, in a normal flow you will have called this unmap and update state function and now you have a list of bad queues. You can then initiate an engine reset for the engine the bad queue is on. This is safe because you've already unmapped the queues, so if the unmap queues function gets called again from the sdma reset function, it will return early as the queues are already unmapped and marked guilty if they are. The engine will reset, the reset sdma reset function will clean up the KGD side and then call the KFD map_queues(). Once it returns you are done. If KGD detects the hang, it will call the sdma reset function and that will call the KFD unmap queues and update state function. This will update the KFD side state, but not initiate any resets. The engine will then be reset and then the KGD state will be restored and finally it will call the KFD map_queues() function to remap the non-guilty queues. At completion both sides should be functional again. I'm not too familiar with the KFD unmap and reset flows, but I think they will need to be decoupled if they are currently intermixed.

Alex

}

Quoted 191 lines

Safest way to remove the parameter seems like to move the KFD suspend/restore outside of the common call and have KGD call suspend/resume when it's calling the common call itself.

Jon

Quoted 184 lines

Alex

Quoted 8 lines · Jesse(Jie)

[AMD Official Use Only - AMD Internal Distribution Only]

Quoted 4 lines

From: Koenig, Christian <[email protected]>
Sent: Wednesday, March 12, 2025 4:39 PM
To: Zhang, Jesse(Jie) <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Kim, Jonathan

<[email protected]>; Zhu, Jiadong <[email protected]>

Quoted 1 line

Subject: Re: [PATCH 1/7] drm/amd/amdgpu: Simplify SDMA reset mechanism by

removing dynamic callbacks

Quoted 13 lines

Am 12.03.25 um 09:15 schrieb Zhang, Jesse(Jie):

[SNIP9

(quoted diff) +1 -1
-
 
+     gfx_ring->funcs->stop_queue(adev, instance_id);
Quoted 1 line

Yeah that starts to look good. Question here is who is calling

amdgpu_sdma_reset_engine()?

Quoted 4 lines

If this call comes from engine specific code we might not need the

start/stop_queue callbacks all together.

Quoted 4 lines

Kfd and sdma v4/v5/v5_2 will call amdgpu_sdma_reset_engine, and

start/stop_queue callbacks are only implemented in sdmav4/sdmav5/sdma5_2.

Quoted 3 lines

Why would the KFD call this as well? Because it detects an issue with a SDMA

user queue If yes I would rather suggest that the KFD calls the reset function of the paging queue.

Quoted 2 lines

Since this reset function is specific to the SDMA HW generation anyway you don't

need those extra functions to abstract starting and stopping of the queue for each HW generation.

Quoted 2 lines

kfd can't call reset function directly, unless we add a parameter src to distinguish

kfd and kgd in reset function, like this:

Quoted 10 lines

int (*reset)(struct amdgpu_ring *ring, unsigned int vmid, int src );

As Alex said in another thread,

We need to distinguish kfd and kgd in reset.

If kfd triggers a reset, kgd must save healthy jobs and recover jobs after reset.

If kgd triggers a reset, kgd must abandon bad jobs after reset.(and perhaps kfd

needs to save its healthy jobs for recovery).

Quoted 10 lines

If we can add a parameter, I am ok for that solution too.

Additionally:

For sdma6/7, when a queue reset fails, we may need to fall back to an engine

reset for a attempt.

Review int amdgpu_sdma_reset_engine(struct amdgpu_device

Quoted 35 lines

Thanks

Jesse

Regards,
Christian.

Thanks

Jesse

Regards,

Christian.

      /* Perform the SDMA reset for the specified instance */

      ret = amdgpu_dpm_reset_sdma(adev, 1 << instance_id);

      if (ret) {
(quoted diff) +0 -0
@@ -591,18 +573,7 @@ int amdgpu_sdma_reset_engine(struct amdgpu_device

*adev, uint32_t instance_id, b

Review static const struct amdgpu_ring_funcs

Quoted 50 lines
(quoted diff) +1 -12
              goto exit;
 
      }
 
 
 
-     /* Invoke all registered post_reset callbacks */
 
-     list_for_each_entry(funcs, &adev->sdma.reset_callback_list, list) {
 
-             if (funcs->post_reset) {
 
-                     ret = funcs->post_reset(adev, instance_id);
 
-                     if (ret) {
 
-                             dev_err(adev->dev,
 
-                             "afterReset callback failed for instance %u: %d\n",
 
-                                     instance_id, ret);
 
-                             goto exit;
 
-                     }
 
-             }
 
-     }
 
+     gfx_ring->funcs->start_queue(adev, instance_id);
 
 
 
 exit:
 
      /* Restart the scheduler's work queue for the GFX and page rings
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c

index fd34dc138081..c1f7ccff9c4e 100644

--- a/drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c

+++ b/drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c

(quoted diff) +0 -0
@@ -2132,6 +2132,8 @@ static const struct amdgpu_ring_funcs

sdma_v4_4_2_ring_funcs = {

Quoted 18 lines
(quoted diff) +2 -0
      .emit_reg_wait = sdma_v4_4_2_ring_emit_reg_wait,
 
      .emit_reg_write_reg_wait = amdgpu_ring_emit_reg_write_reg_wait_helper,
 
      .reset = sdma_v4_4_2_reset_queue,
 
+     .stop_queue = sdma_v4_4_2_stop_queue,
 
+     .start_queue = sdma_v4_4_2_restore_queue,
 
      .is_guilty = sdma_v4_4_2_ring_is_guilty,  };
#15 lore raw

[Public]

Quoted 48 lines

-----Original Message-----
From: Alex Deucher <[email protected]>
Sent: Friday, March 14, 2025 5:46 PM
To: Kim, Jonathan <[email protected]>
Cc: Zhang, Jesse(Jie) <[email protected]>; Koenig, Christian <[email protected]>; [email protected]; Deucher, Alexander <[email protected]>; Zhu, Jiadong <[email protected]>
Subject: Re: [PATCH 1/7] drm/amd/amdgpu: Simplify SDMA reset mechanism by removing dynamic callbacks

Quoted 9 lines · Jonathan

[Public]

Quoted 6 lines

-----Original Message-----
From: Alex Deucher <[email protected]>
Sent: Thursday, March 13, 2025 10:38 AM
To: Zhang, Jesse(Jie) <[email protected]>
Cc: Koenig, Christian <[email protected]>; amd- [email protected]; Deucher, Alexander

<[email protected]>;

Quoted 3 lines
Quoted 3 lines

Kim, Jonathan <[email protected]>; Zhu, Jiadong <[email protected]>
Subject: Re: [PATCH 1/7] drm/amd/amdgpu: Simplify SDMA reset mechanism

by

Quoted 14 lines
Quoted 13 lines

removing dynamic callbacks

I think as long as the locking is correct, the src shouldn't matter. You just need to stop the kernel queues (and save state) and evict the user queues (since HWS is responsible for saving the MQDs of the non-guilty user queues). If KFD detected the hang (e.g., queue eviction fails when called for memory pressure, etc.), we just need to make sure that it's ok for the sdma reset routine to call evict queues again even if it was already called (presumably it should exit early since the queues are already evicted). If KGD initiates the reset, it will call into KFD to evict queues. We just need to make sure the evict queues function we call just evicts the queues and doesn't also try and reset.

Quoted 1 line

If we're removing the src parameter, we need to be careful we don't end up in a

double lock scenario in the KFD.

Quoted 2 lines

i.e. kgd inits reset -> kfd detects hang on kgd reset trigger and calls back to kgd - amdgpu_amdkfd_suspend gets called again but is blocked on previous suspend

call from original kgd reset (which is holding a bunch of KFD locks) while KFD is trying to clean up immediately.

Quoted 1 line
Quoted 7 lines

How would this work even with the src parameter? I think you could still get into that case. E.g., KGD detects a hang and initiates an engine reset. In parallel, KFD tries to unmap all queues for some reason and detects a hang, so it tries to reset SDMA. Assuming there is a lock that protects SDMA reset, that should work. However, it requires that the prerequisites on each side don't attempt to reset anything.

If the KGD succeeds in suspending the KFD, then KFD will be quiesced and no KFD reset is possible.
If the KFD is trying to reset inside a KGD initiated reset due to a KFD suspend call failure or is resetting in parallel, the current and any future KGD resets calls will be blocked on KFD suspend calls due to KFD locks (assuming suspend is the first action and suspend_user_queues == true).
KFD will then always reset with suspend_user_queues == false (and always hold a device/suspend or reset lock during this time), which avoids the KFD suspend on the KGD callback and avoids deadlocking itself. Any other KGD future calls should be blocked on their own calls to KFD suspend due to KFD locking until the KFD is done resetting, avoiding any reset deadlocks.

Quoted 22 lines

sdma_engine_reset()
{

KFD pre reset requirements
1. unmap all SDMA queues (CP firmware will save non-guilty state in MQDs)
2. detect guilty queue

KGD pre reset requirements:
1. stop relevant drm schedulers
2. detect guilt queue
3. save non-guilty queue state

Do engine reset

KGD post reset requirements:
1. restore non-guilty queue state
2. start relevant drm schedulers

KFD post reset requirements
1. map all non-guilty SDMA queues

Quoted 8 lines

}

I think what we need on the KFD side, if we don't have it already, is a function to just umap queues and update guilty state, but not to attempt to reset anything. Then on the KFD side, in your normal flows, you could call this function to unamp queues and update queue state, and then after calling that walk through the queue state and trigger any resets based on queues flagged as bad. On the KFD side,

I'd have to look at this more carefully, but it seems like you're suggesting the KFD to defer reset on preemption failure via scheduling similar to GPU resets.
The problem is future map/unmap request in the KFD are user requested so they're unpredictable.
GPU resets could just "flick-away" user queue update request failures subsequent to the initial preemption failure because the device is dead and all HSA processes have to die at some point.
You can't do this with SDMA resets since other processes are still good so the KFD would have to immediately lock itself down (which could be problematic during preemption routines) if it wants to unblock and schedule the reset later.

Jon

Quoted 228 lines

in a normal flow you will have called this unmap and update state function and now you have a list of bad queues. You can then initiate an engine reset for the engine the bad queue is on. This is safe because you've already unmapped the queues, so if the unmap queues function gets called again from the sdma reset function, it will return early as the queues are already unmapped and marked guilty if they are. The engine will reset, the reset sdma reset function will clean up the KGD side and then call the KFD map_queues(). Once it returns you are done. If KGD detects the hang, it will call the sdma reset function and that will call the KFD unmap queues and update state function. This will update the KFD side state, but not initiate any resets. The engine will then be reset and then the KGD state will be restored and finally it will call the KFD map_queues() function to remap the non-guilty queues. At completion both sides should be functional again. I'm not too familiar with the KFD unmap and reset flows, but I think they will need to be decoupled if they are currently intermixed.

Alex

}

Quoted 1 line

Safest way to remove the parameter seems like to move the KFD

suspend/restore outside of the common call and have KGD call suspend/resume when it's calling the common call itself.

Quoted 10 lines

Jon

Quoted 4 lines

Alex

On Wed, Mar 12, 2025 at 5:24 AM Zhang, Jesse(Jie)

<[email protected]>

Quoted 9 lines
Quoted 9 lines
Quoted 8 lines · wrote:

[AMD Official Use Only - AMD Internal Distribution Only]

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

From: Koenig, Christian <[email protected]>
Sent: Wednesday, March 12, 2025 4:39 PM
To: Zhang, Jesse(Jie) <[email protected]>; amd-

[email protected]

Quoted 3 lines
Quoted 3 lines
Quoted 1 line
Cc Deucher, Alexander <[email protected]>; Kim, Jonathan

<[email protected]>; Zhu, Jiadong <[email protected]>

Quoted 1 line

Subject: Re: [PATCH 1/7] drm/amd/amdgpu: Simplify SDMA reset mechanism

by

Quoted 24 lines
Quoted 24 lines

removing dynamic callbacks

Quoted 13 lines

Am 12.03.25 um 09:15 schrieb Zhang, Jesse(Jie):

[SNIP9

(quoted diff) +1 -1
-
 
+     gfx_ring->funcs->stop_queue(adev, instance_id);
Quoted 1 line

Yeah that starts to look good. Question here is who is calling

amdgpu_sdma_reset_engine()?

Quoted 4 lines

If this call comes from engine specific code we might not need the

start/stop_queue callbacks all together.

Quoted 3 lines
Quoted 5 lines
Quoted 5 lines
Quoted 1 line

Kfd and sdma v4/v5/v5_2 will call amdgpu_sdma_reset_engine, and

start/stop_queue callbacks are only implemented in sdmav4/sdmav5/sdma5_2.

Quoted 3 lines

Why would the KFD call this as well? Because it detects an issue with a

SDMA

Quoted 1 line
Quoted 1 line

user queue If yes I would rather suggest that the KFD calls the reset function

of

Quoted 3 lines
Quoted 3 lines

the paging queue.

Quoted 2 lines

Since this reset function is specific to the SDMA HW generation anyway you

don't

Quoted 1 line
Quoted 1 line

need those extra functions to abstract starting and stopping of the queue for

each

Quoted 3 lines
Quoted 3 lines

HW generation.

Quoted 2 lines

kfd can't call reset function directly, unless we add a parameter src to

distinguish

Quoted 9 lines
Quoted 9 lines

kfd and kgd in reset function, like this:

Quoted 8 lines

int (*reset)(struct amdgpu_ring *ring, unsigned int vmid, int src );

As Alex said in another thread,

We need to distinguish kfd and kgd in reset.

If kfd triggers a reset, kgd must save healthy jobs and recover jobs after

reset.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

If kgd triggers a reset, kgd must abandon bad jobs after reset.(and perhaps

kfd

Quoted 40 lines
Quoted 40 lines

needs to save its healthy jobs for recovery).

Quoted 10 lines

If we can add a parameter, I am ok for that solution too.

Additionally:

For sdma6/7, when a queue reset fails, we may need to fall back to an engine

reset for a attempt.

Quoted 28 lines

Thanks

Jesse

Regards,
Christian.

Thanks

Jesse

Regards,

Christian.

Quoted 7 lines
Quoted 7 lines

Review int amdgpu_sdma_reset_engine(struct

Quoted 7 lines
      /* Perform the SDMA reset for the specified instance */

      ret = amdgpu_dpm_reset_sdma(adev, 1 << instance_id);

      if (ret) {
(quoted diff) +0 -0
@@ -591,18 +573,7 @@ int amdgpu_sdma_reset_engine(struct

amdgpu_device

Quoted 48 lines
Quoted 48 lines

*adev, uint32_t instance_id, b

Quoted 47 lines
(quoted diff) +1 -12
              goto exit;
 
      }
 
 
 
-     /* Invoke all registered post_reset callbacks */
 
-     list_for_each_entry(funcs, &adev->sdma.reset_callback_list, list) {
 
-             if (funcs->post_reset) {
 
-                     ret = funcs->post_reset(adev, instance_id);
 
-                     if (ret) {
 
-                             dev_err(adev->dev,
 
-                             "afterReset callback failed for instance %u: %d\n",
 
-                                     instance_id, ret);
 
-                             goto exit;
 
-                     }
 
-             }
 
-     }
 
+     gfx_ring->funcs->start_queue(adev, instance_id);
 
 
 
 exit:
 
      /* Restart the scheduler's work queue for the GFX and page rings
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c

index fd34dc138081..c1f7ccff9c4e 100644

--- a/drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c

Quoted 8 lines
Quoted 8 lines

Review static const struct amdgpu_ring_funcs

Quoted 3 lines

+++ b/drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c

(quoted diff) +0 -0
@@ -2132,6 +2132,8 @@ static const struct amdgpu_ring_funcs

sdma_v4_4_2_ring_funcs = {

Quoted 4 lines
(quoted diff) +0 -0
      .emit_reg_wait = sdma_v4_4_2_ring_emit_reg_wait,
 
      .emit_reg_write_reg_wait =

amdgpu_ring_emit_reg_write_reg_wait_helper,

Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
(quoted diff) +2 -0
      .reset = sdma_v4_4_2_reset_queue,
 
+     .stop_queue = sdma_v4_4_2_stop_queue,
 
+     .start_queue = sdma_v4_4_2_restore_queue,
      .is_guilty = sdma_v4_4_2_ring_is_guilty,  };