Skip to contentSkip to conversation

Add workaround for VCN 4.0.5 timeouts

PATCH Superseded Mario Limonciello 2 participants 4 messages May 6, 2025

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Add workaround for VCN 4.0.5 timeouts

There is an issue reported on platforms with VCN 4.0.5 that some jobs are timing out. This leads to a full GPU reset. That full GPU reset exposed a number of problems in DCN that have since been fixed, but still the GPU reset means a black screen for ~500ms while the GPU resets.

However the issue with VCN in this case doesn't require a full GPU reset to recover, just resetting VCN is enough.

For a workaround while the VCN issue is still being root caused lessen the impact of VCN timeouts use the per-ring reset functionality to reset just VCN.

Mario Limonciello (1):
drm/amd: Add per-ring reset for vcn v4.0.5 use

 drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
Signature · 1 line
2.49.0
#1 lore raw

PATCH 1/1 drm/amd: Add per-ring reset for vcn v4.0.5 use

There is a problem occurring on VCN 4.0.5 where in some situations a job is timing out. This triggers a job timeout which then causes a GPU reset for recovery. That has exposed a number of issues with GPU reset that have since been fixed. But also a GPU reset isn't actually needed for this circumstance. Just restarting the ring is enough.

Add a reset callback for the ring which will stop and start VCN if the issue happens.

---
 drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.c +19 -0
index 558469744f3a..3e6e8127143b 100644
@@ -1440,6 +1440,24 @@ static void vcn_v4_0_5_unified_ring_set_wptr(struct amdgpu_ring *ring)
 	}
 }
 
+static int vcn_v4_0_5_ring_reset(struct amdgpu_ring *ring, unsigned int vmid)
+{
+	struct amdgpu_device *adev = ring->adev;
+	int i;
+
+	for (i = 0; i < adev->vcn.num_vcn_inst; ++i) {
+		struct amdgpu_vcn_inst *vinst = &adev->vcn.inst[i];
+
+		if (ring != &vinst->ring_enc[0])
+			continue;
+		vcn_v4_0_5_stop(vinst);
+		vcn_v4_0_5_start(vinst);
+		break;
+	}
+
+	return amdgpu_ring_test_helper(ring);
+}
+
 static struct amdgpu_ring_funcs vcn_v4_0_5_unified_ring_vm_funcs = {
 	.type = AMDGPU_RING_TYPE_VCN_ENC,
 	.align_mask = 0x3f,
@@ -1467,6 +1485,7 @@ static struct amdgpu_ring_funcs vcn_v4_0_5_unified_ring_vm_funcs = {
 	.emit_wreg = vcn_v2_0_enc_ring_emit_wreg,
 	.emit_reg_wait = vcn_v2_0_enc_ring_emit_reg_wait,
 	.emit_reg_write_reg_wait = amdgpu_ring_emit_reg_write_reg_wait_helper,
+	.reset = vcn_v4_0_5_ring_reset,
 };
 
 /**
Signature · 1 line
2.49.0
#2 lore raw

Re: [PATCH 1/1] drm/amd: Add per-ring reset for vcn v4.0.5 use

Quoted 25 lines · Mario Limonciello

There is a problem occurring on VCN 4.0.5 where in some situations a job is timing out. This triggers a job timeout which then causes a GPU reset for recovery. That has exposed a number of issues with GPU reset that have since been fixed. But also a GPU reset isn't actually needed for this circumstance. Just restarting the ring is enough.

Add a reset callback for the ring which will stop and start VCN if the issue happens.

---
 drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.c +0 -0
index 558469744f3a..3e6e8127143b 100644
@@ -1440,6 +1440,24 @@ static void vcn_v4_0_5_unified_ring_set_wptr(struct amdgpu_ring *ring)
        }
 }
 

drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.c static void vcn_v4_0_5_unified_ring_set_wptr(struct amdgpu_ring *ring) · line 1452

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.c +10 -0
+static int vcn_v4_0_5_ring_reset(struct amdgpu_ring *ring, unsigned int vmid)
+{
+       struct amdgpu_device *adev = ring->adev;
+       int i;
+
+       for (i = 0; i < adev->vcn.num_vcn_inst; ++i) {
+               struct amdgpu_vcn_inst *vinst = &adev->vcn.inst[i];
+
+               if (ring != &vinst->ring_enc[0])
+                       continue;

You can drop the loop and just look up the instance directly:
struct amdgpu_vcn_inst *vinst = &adev->vcn.inst[ring->me];

Also check if per queue reset is supported:
if (!(adev->vcn.supported_reset & AMDGPU_RESET_TYPE_PER_QUEUE))

        return -EOPNOTSUPP;

You'll also need something like:
adev->vcn.supported_reset = amdgpu_get_soft_full_reset_mask(&adev->vcn.inst[0].ring_enc[0]); adev->vcn.supported_reset |= AMDGPU_RESET_TYPE_PER_QUEUE; in vcn_v4_0_5_sw_init().

Also, since each VCN instance is only single threaded, you could theoretically save the other jobs in the ring and fix up the ring pointers after resetting to continue after the bad job. That could be left as a future improvement however.

Alex

Quoted 22 lines
drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.c +9 -1
+               vcn_v4_0_5_stop(vinst);
+               vcn_v4_0_5_start(vinst);
+               break;
+       }
+
+       return amdgpu_ring_test_helper(ring);
+}
+
 static struct amdgpu_ring_funcs vcn_v4_0_5_unified_ring_vm_funcs = {
        .type = AMDGPU_RING_TYPE_VCN_ENC,
        .align_mask = 0x3f,
@@ -1467,6 +1485,7 @@ static struct amdgpu_ring_funcs vcn_v4_0_5_unified_ring_vm_funcs = {
        .emit_wreg = vcn_v2_0_enc_ring_emit_wreg,
        .emit_reg_wait = vcn_v2_0_enc_ring_emit_reg_wait,
        .emit_reg_write_reg_wait = amdgpu_ring_emit_reg_write_reg_wait_helper,
+       .reset = vcn_v4_0_5_ring_reset,
 };
 
 /**
--

2.49.0

#3 lore raw

Re: [PATCH 1/1] drm/amd: Add per-ring reset for vcn v4.0.5 use

Quoted 52 lines · Alex Deucher
Quoted 25 lines · Mario Limonciello

There is a problem occurring on VCN 4.0.5 where in some situations a job is timing out. This triggers a job timeout which then causes a GPU reset for recovery. That has exposed a number of issues with GPU reset that have since been fixed. But also a GPU reset isn't actually needed for this circumstance. Just restarting the ring is enough.

Add a reset callback for the ring which will stop and start VCN if the issue happens.

---
 drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.c +0 -0
index 558469744f3a..3e6e8127143b 100644
@@ -1440,6 +1440,24 @@ static void vcn_v4_0_5_unified_ring_set_wptr(struct amdgpu_ring *ring)
        }
 }
 

drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.c static void vcn_v4_0_5_unified_ring_set_wptr(struct amdgpu_ring *ring) · line 1452

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.c +10 -0
+static int vcn_v4_0_5_ring_reset(struct amdgpu_ring *ring, unsigned int vmid)
+{
+       struct amdgpu_device *adev = ring->adev;
+       int i;
+
+       for (i = 0; i < adev->vcn.num_vcn_inst; ++i) {
+               struct amdgpu_vcn_inst *vinst = &adev->vcn.inst[i];
+
+               if (ring != &vinst->ring_enc[0])
+                       continue;

You can drop the loop and just look up the instance directly:
struct amdgpu_vcn_inst *vinst = &adev->vcn.inst[ring->me];

Also check if per queue reset is supported:
if (!(adev->vcn.supported_reset & AMDGPU_RESET_TYPE_PER_QUEUE))

        return -EOPNOTSUPP;

You'll also need something like:
adev->vcn.supported_reset = amdgpu_get_soft_full_reset_mask(&adev->vcn.inst[0].ring_enc[0]); adev->vcn.supported_reset |= AMDGPU_RESET_TYPE_PER_QUEUE; in vcn_v4_0_5_sw_init().

Quoted 4 lines

Also, since each VCN instance is only single threaded, you could theoretically save the other jobs in the ring and fix up the ring pointers after resetting to continue after the bad job. That could be left as a future improvement however.

While you are at it, you could implement support in vcn_v4_0.c and vcn_v5_0_0.c as well. Older VCNs will be a bit more complex as they support multiple queues per engine, so if you reset the engine, you need to properly clean up all the queues.

Alex

Quoted 25 lines

Alex

Quoted 22 lines
drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.c +9 -1
+               vcn_v4_0_5_stop(vinst);
+               vcn_v4_0_5_start(vinst);
+               break;
+       }
+
+       return amdgpu_ring_test_helper(ring);
+}
+
 static struct amdgpu_ring_funcs vcn_v4_0_5_unified_ring_vm_funcs = {
        .type = AMDGPU_RING_TYPE_VCN_ENC,
        .align_mask = 0x3f,
@@ -1467,6 +1485,7 @@ static struct amdgpu_ring_funcs vcn_v4_0_5_unified_ring_vm_funcs = {
        .emit_wreg = vcn_v2_0_enc_ring_emit_wreg,
        .emit_reg_wait = vcn_v2_0_enc_ring_emit_reg_wait,
        .emit_reg_write_reg_wait = amdgpu_ring_emit_reg_write_reg_wait_helper,
+       .reset = vcn_v4_0_5_ring_reset,
 };
 
 /**
--

2.49.0