Skip to contentSkip to conversation

drm/amdgpu/vce1: Fix checking whether VCE1 is idle

PATCH In review Timur Kristóf 3 participants 6 messages Oct 6 – Nov 5

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/amdgpu/vce1: Fix checking whether VCE1 is idle

It turns out that the VCE_STATUS register bits that we used to check whether VCE1 is idle are actually not useful:
VCE_STATUS.JOB_BUSY doesn't exist until VCE3 VCE_STATUS.UENC_BUSY seems to be stuck high on Cape Verde

Instead, do the following:
Check that the read and write pointer matches for each ring. Check VCE_STATUS.VCPU_REPORT bits to check busy status. Finally, also check SRBM_STATUS2.VCE_BUSY just in case, although this one seems bogus on VCE1.

Fixes d4a640d4b9f3 ("drm/amdgpu/vce1: Implement VCE1 IP block (v2)")
---
 drivers/gpu/drm/amd/amdgpu/vce_v1_0.c         | 25 ++++++++++++++-----
 .../include/asic_reg/vce/vce_1_0_sh_mask.h    |  2 --
 2 files changed, 19 insertions(+), 8 deletions(-)
drivers/gpu/drm/amd/amdgpu/vce_v1_0.c +19 -6
index b1428f5bbc81..38e21d1a3ebb 100644
@@ -47,6 +47,9 @@
 #define VCE_V1_0_STACK_SIZE	(64 * 1024)
 #define VCE_V1_0_DATA_SIZE	(ALIGN(7808 * (AMDGPU_MAX_VCE_HANDLES + 1), VCE_V1_0_ALIGNMENT))
 #define VCE_STATUS_VCPU_REPORT_FW_LOADED_MASK	0x02
+#define VCE_STATUS_VCPU_REPORT_AUTO_BUSY_MASK   0x08
+#define VCE_STATUS_VCPU_REPORT_RB0_BUSY_MASK    0x10
+#define VCE_STATUS_VCPU_REPORT_RB1_BUSY_MASK    0x20
 
 static void vce_v1_0_set_ring_funcs(struct amdgpu_device *adev);
 static void vce_v1_0_set_irq_funcs(struct amdgpu_device *adev);
@@ -349,19 +352,29 @@ static int vce_v1_0_mc_resume(struct amdgpu_device *adev)
  *
  * @ip_block: amdgpu_ip_block pointer
  *
- * Check whether VCE is busy according to VCE_STATUS.
+ * Check whether VCE is busy according to VCE_STATUS
+ * and whether the ring pointers match.
+ *
  * Also check whether the SRBM thinks VCE is busy, although
- * SRBM_STATUS.VCE_BUSY seems to be bogus because it
+ * SRBM_STATUS2.VCE_BUSY seems to be bogus because it
  * appears to mirror the VCE_STATUS.VCPU_REPORT_FW_LOADED bit.
  */
 static bool vce_v1_0_is_idle(struct amdgpu_ip_block *ip_block)
 {
 	struct amdgpu_device *adev = ip_block->adev;
-	bool busy =
-		(RREG32(mmVCE_STATUS) & (VCE_STATUS__JOB_BUSY_MASK | VCE_STATUS__UENC_BUSY_MASK)) ||
-		(RREG32(mmSRBM_STATUS2) & SRBM_STATUS2__VCE_BUSY_MASK);
 
-	return !busy;
+	/* Check whether the rings are busy. */
+	if (RREG32(mmVCE_RB_RPTR) != RREG32(mmVCE_RB_WPTR) ||
+	    RREG32(mmVCE_RB_RPTR2) != RREG32(mmVCE_RB_WPTR2))
+		return false;
+
+	/* Check whether the VCPU is busy. */
+	if (RREG32(mmVCE_STATUS) & (VCE_STATUS_VCPU_REPORT_AUTO_BUSY_MASK |
+				    VCE_STATUS_VCPU_REPORT_RB0_BUSY_MASK |
+				    VCE_STATUS_VCPU_REPORT_RB1_BUSY_MASK))
+		return false;
+
+	return !(RREG32(mmSRBM_STATUS2) & SRBM_STATUS2__VCE_BUSY_MASK);
 }
 
 static int vce_v1_0_wait_for_idle(struct amdgpu_ip_block *ip_block)
drivers/gpu/drm/amd/include/asic_reg/vce/vce_1_0_sh_mask.h +0 -2
index 1f82d6f5abde..13c15c2138b3 100644
@@ -63,8 +63,6 @@
 #define VCE_SOFT_RESET__ECPU_SOFT_RESET__SHIFT 0x00000000
 #define VCE_SOFT_RESET__FME_SOFT_RESET_MASK 0x00000004L
 #define VCE_SOFT_RESET__FME_SOFT_RESET__SHIFT 0x00000002
-#define VCE_STATUS__JOB_BUSY_MASK 0x00000001L
-#define VCE_STATUS__JOB_BUSY__SHIFT 0x00000000
 #define VCE_STATUS__UENC_BUSY_MASK 0x00000100L
 #define VCE_STATUS__UENC_BUSY__SHIFT 0x00000008
 #define VCE_STATUS__VCPU_REPORT_MASK 0x000000feL
Signature · 1 line
2.55.0
Acked-by on v1 1/1
#1 lore raw
Quoted 5 lines · Timur Kristóf

It turns out that the VCE_STATUS register bits that we used to check whether VCE1 is idle are actually not useful:
VCE_STATUS.JOB_BUSY doesn't exist until VCE3 VCE_STATUS.UENC_BUSY seems to be stuck high on Cape Verde

Quoted 8 lines

Instead, do the following:
Check that the read and write pointer matches for each ring. Check VCE_STATUS.VCPU_REPORT bits to check busy status. Finally, also check SRBM_STATUS2.VCE_BUSY just in case, although this one seems bogus on VCE1.

Fixes d4a640d4b9f3 ("drm/amdgpu/vce1: Implement VCE1 IP block (v2)")

There's still occasional warning that VCE is not idle on my cape verde, but it's much better than the current state where it prints it every time.

Quoted 68 lines
---
  drivers/gpu/drm/amd/amdgpu/vce_v1_0.c         | 25 ++++++++++++++-----
  .../include/asic_reg/vce/vce_1_0_sh_mask.h    |  2 --
  2 files changed, 19 insertions(+), 8 deletions(-)
drivers/gpu/drm/amd/amdgpu/vce_v1_0.c +19 -6
index b1428f5bbc81..38e21d1a3ebb 100644
@@ -47,6 +47,9 @@
  #define VCE_V1_0_STACK_SIZE	(64 * 1024)
  #define VCE_V1_0_DATA_SIZE	(ALIGN(7808 * (AMDGPU_MAX_VCE_HANDLES + 1), VCE_V1_0_ALIGNMENT))
  #define VCE_STATUS_VCPU_REPORT_FW_LOADED_MASK	0x02
+#define VCE_STATUS_VCPU_REPORT_AUTO_BUSY_MASK   0x08
+#define VCE_STATUS_VCPU_REPORT_RB0_BUSY_MASK    0x10
+#define VCE_STATUS_VCPU_REPORT_RB1_BUSY_MASK    0x20
 
  static void vce_v1_0_set_ring_funcs(struct amdgpu_device *adev);
  static void vce_v1_0_set_irq_funcs(struct amdgpu_device *adev);
@@ -349,19 +352,29 @@ static int vce_v1_0_mc_resume(struct amdgpu_device *adev)
   *
   * @ip_block: amdgpu_ip_block pointer
   *
- * Check whether VCE is busy according to VCE_STATUS.
+ * Check whether VCE is busy according to VCE_STATUS
+ * and whether the ring pointers match.
+ *
   * Also check whether the SRBM thinks VCE is busy, although
- * SRBM_STATUS.VCE_BUSY seems to be bogus because it
+ * SRBM_STATUS2.VCE_BUSY seems to be bogus because it
   * appears to mirror the VCE_STATUS.VCPU_REPORT_FW_LOADED bit.
   */
  static bool vce_v1_0_is_idle(struct amdgpu_ip_block *ip_block)
  {
  	struct amdgpu_device *adev = ip_block->adev;
-	bool busy =
-		(RREG32(mmVCE_STATUS) & (VCE_STATUS__JOB_BUSY_MASK | VCE_STATUS__UENC_BUSY_MASK)) ||
-		(RREG32(mmSRBM_STATUS2) & SRBM_STATUS2__VCE_BUSY_MASK);
 
-	return !busy;
+	/* Check whether the rings are busy. */
+	if (RREG32(mmVCE_RB_RPTR) != RREG32(mmVCE_RB_WPTR) ||
+	    RREG32(mmVCE_RB_RPTR2) != RREG32(mmVCE_RB_WPTR2))
+		return false;
+
+	/* Check whether the VCPU is busy. */
+	if (RREG32(mmVCE_STATUS) & (VCE_STATUS_VCPU_REPORT_AUTO_BUSY_MASK |
+				    VCE_STATUS_VCPU_REPORT_RB0_BUSY_MASK |
+				    VCE_STATUS_VCPU_REPORT_RB1_BUSY_MASK))
+		return false;
+
+	return !(RREG32(mmSRBM_STATUS2) & SRBM_STATUS2__VCE_BUSY_MASK);
  }
 
  static int vce_v1_0_wait_for_idle(struct amdgpu_ip_block *ip_block)
drivers/gpu/drm/amd/include/asic_reg/vce/vce_1_0_sh_mask.h +0 -2
index 1f82d6f5abde..13c15c2138b3 100644
@@ -63,8 +63,6 @@
  #define VCE_SOFT_RESET__ECPU_SOFT_RESET__SHIFT 0x00000000
  #define VCE_SOFT_RESET__FME_SOFT_RESET_MASK 0x00000004L
  #define VCE_SOFT_RESET__FME_SOFT_RESET__SHIFT 0x00000002
-#define VCE_STATUS__JOB_BUSY_MASK 0x00000001L
-#define VCE_STATUS__JOB_BUSY__SHIFT 0x00000000
  #define VCE_STATUS__UENC_BUSY_MASK 0x00000100L
  #define VCE_STATUS__UENC_BUSY__SHIFT 0x00000008
  #define VCE_STATUS__VCPU_REPORT_MASK 0x000000feL
#2 lore raw
Quoted 12 lines · Central European Standard Time David Rosca
Quoted 11 lines · Timur Kristóf

It turns out that the VCE_STATUS register bits that we used to check whether VCE1 is idle are actually not useful:
VCE_STATUS.JOB_BUSY doesn't exist until VCE3 VCE_STATUS.UENC_BUSY seems to be stuck high on Cape Verde

Instead, do the following:
Check that the read and write pointer matches for each ring. Check VCE_STATUS.VCPU_REPORT bits to check busy status. Finally, also check SRBM_STATUS2.VCE_BUSY just in case, although this one seems bogus on VCE1.

Quoted 6 lines
Quoted 2 lines
Fixes d4a640d4b9f3 ("drm/amdgpu/vce1: Implement VCE1 IP block (v2)")

There's still occasional warning that VCE is not idle on my cape verde, but it's much better than the current state where it prints it every time.

Hi David,

Can you say what the remaining warning says?
Do you think we could fix the remaining warning by removing the check for the SRBM_STATUS bit entirely?

Thanks,
Timur

Quoted 14 lines
Quoted 14 lines

---

  drivers/gpu/drm/amd/amdgpu/vce_v1_0.c         | 25 ++++++++++++++-----
  .../include/asic_reg/vce/vce_1_0_sh_mask.h    |  2 --
  2 files changed, 19 insertions(+), 8 deletions(-)
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/vce_v1_0.c index b1428f5bbc81..38e21d1a3ebb 100644

drivers/gpu/drm/amd/amdgpu/vce_v1_0.c +0 -0
@@ -47,6 +47,9 @@
 
Quoted 2 lines

drivers/gpu/drm/amd/amdgpu/vce_v1_0.c line 49

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/vce_v1_0.c +0 -0
  #define VCE_V1_0_STACK_SIZE	(64 * 1024)
  #define VCE_V1_0_DATA_SIZE	(ALIGN(7808 * (AMDGPU_MAX_VCE_HANDLES + 

1),

Quoted 1 line

drivers/gpu/drm/amd/amdgpu/vce_v1_0.c line 50

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/vce_v1_0.c +0 -0
  VCE_V1_0_ALIGNMENT)) #define VCE_STATUS_VCPU_REPORT_FW_LOADED_MASK	

0x02

Quoted 27 lines
Quoted 27 lines
drivers/gpu/drm/amd/amdgpu/vce_v1_0.c +3 -0
+#define VCE_STATUS_VCPU_REPORT_AUTO_BUSY_MASK   0x08
+#define VCE_STATUS_VCPU_REPORT_RB0_BUSY_MASK    0x10
+#define VCE_STATUS_VCPU_REPORT_RB1_BUSY_MASK    0x20
 
  static void vce_v1_0_set_ring_funcs(struct amdgpu_device *adev);
  static void vce_v1_0_set_irq_funcs(struct amdgpu_device *adev);
drivers/gpu/drm/amd/amdgpu/vce_v1_0.c +4 -2
@@ -349,19 +352,29 @@ static int vce_v1_0_mc_resume(struct amdgpu_device
 *adev)> 
   *
   * @ip_block: amdgpu_ip_block pointer
   *
 
- * Check whether VCE is busy according to VCE_STATUS.
+ * Check whether VCE is busy according to VCE_STATUS
+ * and whether the ring pointers match.
+ *
 
   * Also check whether the SRBM thinks VCE is busy, although
 
- * SRBM_STATUS.VCE_BUSY seems to be bogus because it
+ * SRBM_STATUS2.VCE_BUSY seems to be bogus because it
 
   * appears to mirror the VCE_STATUS.VCPU_REPORT_FW_LOADED bit.
   */
 
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/vce_v1_0.c +0 -2
  static bool vce_v1_0_is_idle(struct amdgpu_ip_block *ip_block)
  {
 
  	struct amdgpu_device *adev = ip_block->adev;
 
-	bool busy =
-		(RREG32(mmVCE_STATUS) & (VCE_STATUS__JOB_BUSY_MASK |

VCE_STATUS__UENC_BUSY_MASK)) || -

(RREG32(mmSRBM_STATUS2) &

Quoted 10 lines

drivers/gpu/drm/amd/amdgpu/vce_v1_0.c static int vce_v1_0_mc_resume(struct amdgpu_device *adev)

Quoted 10 lines

SRBM_STATUS2__VCE_BUSY_MASK);

drivers/gpu/drm/amd/amdgpu/vce_v1_0.c +7 -1
-	return !busy;
+	/* Check whether the rings are busy. */
+	if (RREG32(mmVCE_RB_RPTR) != RREG32(mmVCE_RB_WPTR) ||
+	    RREG32(mmVCE_RB_RPTR2) != RREG32(mmVCE_RB_WPTR2))
+		return false;
+
+	/* Check whether the VCPU is busy. */
+	if (RREG32(mmVCE_STATUS) & (VCE_STATUS_VCPU_REPORT_AUTO_BUSY_MASK 

|

Quoted 1 line

drivers/gpu/drm/amd/amdgpu/vce_v1_0.c

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/vce_v1_0.c +1 -0
+				    

VCE_STATUS_VCPU_REPORT_RB0_BUSY_MASK |

Quoted 1 line

drivers/gpu/drm/amd/amdgpu/vce_v1_0.c

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/vce_v1_0.c +1 -0
+				    

VCE_STATUS_VCPU_REPORT_RB1_BUSY_MASK))

Quoted 25 lines
Quoted 25 lines
drivers/gpu/drm/amd/amdgpu/vce_v1_0.c +3 -0
+		return false;
+
+	return !(RREG32(mmSRBM_STATUS2) & SRBM_STATUS2__VCE_BUSY_MASK);
 
  }
 
  static int vce_v1_0_wait_for_idle(struct amdgpu_ip_block *ip_block)
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/include/asic_reg/vce/vce_1_0_sh_mask.h index 1f82d6f5abde..13c15c2138b3 100644

drivers/gpu/drm/amd/include/asic_reg/vce/vce_1_0_sh_mask.h +0 -2
@@ -63,8 +63,6 @@
 
  #define VCE_SOFT_RESET__ECPU_SOFT_RESET__SHIFT 0x00000000
  #define VCE_SOFT_RESET__FME_SOFT_RESET_MASK 0x00000004L
  #define VCE_SOFT_RESET__FME_SOFT_RESET__SHIFT 0x00000002
 
-#define VCE_STATUS__JOB_BUSY_MASK 0x00000001L
-#define VCE_STATUS__JOB_BUSY__SHIFT 0x00000000
 
  #define VCE_STATUS__UENC_BUSY_MASK 0x00000100L
  #define VCE_STATUS__UENC_BUSY__SHIFT 0x00000008
  #define VCE_STATUS__VCPU_REPORT_MASK 0x000000feL
#3 lore raw
Quoted 16 lines · Timur Kristóf
Quoted 14 lines · Central European Standard Time David Rosca
Quoted 13 lines · Timur Kristóf

It turns out that the VCE_STATUS register bits that we used to check whether VCE1 is idle are actually not useful:
VCE_STATUS.JOB_BUSY doesn't exist until VCE3 VCE_STATUS.UENC_BUSY seems to be stuck high on Cape Verde

Instead, do the following:
Check that the read and write pointer matches for each ring. Check VCE_STATUS.VCPU_REPORT bits to check busy status. Finally, also check SRBM_STATUS2.VCE_BUSY just in case, although this one seems bogus on VCE1.

Fixes d4a640d4b9f3 ("drm/amdgpu/vce1: Implement VCE1 IP block (v2)")
Quoted 8 lines
Quoted 3 lines

There's still occasional warning that VCE is not idle on my cape verde, but it's much better than the current state where it prints it every time.

Hi David,

Can you say what the remaining warning says?
Do you think we could fix the remaining warning by removing the check for the SRBM_STATUS bit entirely?

VCE busy: VCE_STATUS=0x142, SRBM_STATUS2=0x80
VCE busy: VCE_STATUS=0x152, SRBM_STATUS2=0x80

which does look like VCE is indeed busy.

David

Quoted 101 lines

Thanks,
Timur

Quoted 13 lines
Quoted 13 lines

---

   drivers/gpu/drm/amd/amdgpu/vce_v1_0.c         | 25 ++++++++++++++-----
   .../include/asic_reg/vce/vce_1_0_sh_mask.h    |  2 --
   2 files changed, 19 insertions(+), 8 deletions(-)
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/vce_v1_0.c index b1428f5bbc81..38e21d1a3ebb 100644

drivers/gpu/drm/amd/amdgpu/vce_v1_0.c +0 -0
@@ -47,6 +47,9 @@
 
Quoted 2 lines

drivers/gpu/drm/amd/amdgpu/vce_v1_0.c line 49

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/vce_v1_0.c +0 -0
   #define VCE_V1_0_STACK_SIZE	(64 * 1024)
   #define VCE_V1_0_DATA_SIZE	(ALIGN(7808 * (AMDGPU_MAX_VCE_HANDLES +

1),

Quoted 1 line

drivers/gpu/drm/amd/amdgpu/vce_v1_0.c line 50

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/vce_v1_0.c +0 -0
   VCE_V1_0_ALIGNMENT)) #define VCE_STATUS_VCPU_REPORT_FW_LOADED_MASK	

0x02

Quoted 26 lines
Quoted 26 lines
drivers/gpu/drm/amd/amdgpu/vce_v1_0.c +3 -0
+#define VCE_STATUS_VCPU_REPORT_AUTO_BUSY_MASK   0x08
+#define VCE_STATUS_VCPU_REPORT_RB0_BUSY_MASK    0x10
+#define VCE_STATUS_VCPU_REPORT_RB1_BUSY_MASK    0x20
 
   static void vce_v1_0_set_ring_funcs(struct amdgpu_device *adev);
   static void vce_v1_0_set_irq_funcs(struct amdgpu_device *adev);
drivers/gpu/drm/amd/amdgpu/vce_v1_0.c +4 -2
@@ -349,19 +352,29 @@ static int vce_v1_0_mc_resume(struct amdgpu_device
 *adev)>
    *
    * @ip_block: amdgpu_ip_block pointer
    *
 
- * Check whether VCE is busy according to VCE_STATUS.
+ * Check whether VCE is busy according to VCE_STATUS
+ * and whether the ring pointers match.
+ *
 
    * Also check whether the SRBM thinks VCE is busy, although
 
- * SRBM_STATUS.VCE_BUSY seems to be bogus because it
+ * SRBM_STATUS2.VCE_BUSY seems to be bogus because it
 
    * appears to mirror the VCE_STATUS.VCPU_REPORT_FW_LOADED bit.
    */
 
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/vce_v1_0.c +0 -2
   static bool vce_v1_0_is_idle(struct amdgpu_ip_block *ip_block)
   {
 
   	struct amdgpu_device *adev = ip_block->adev;
 
-	bool busy =
-		(RREG32(mmVCE_STATUS) & (VCE_STATUS__JOB_BUSY_MASK |

VCE_STATUS__UENC_BUSY_MASK)) || -

(RREG32(mmSRBM_STATUS2) &

Quoted 10 lines

drivers/gpu/drm/amd/amdgpu/vce_v1_0.c static int vce_v1_0_mc_resume(struct amdgpu_device *adev)

Quoted 10 lines

SRBM_STATUS2__VCE_BUSY_MASK);

drivers/gpu/drm/amd/amdgpu/vce_v1_0.c +7 -1
-	return !busy;
+	/* Check whether the rings are busy. */
+	if (RREG32(mmVCE_RB_RPTR) != RREG32(mmVCE_RB_WPTR) ||
+	    RREG32(mmVCE_RB_RPTR2) != RREG32(mmVCE_RB_WPTR2))
+		return false;
+
+	/* Check whether the VCPU is busy. */
+	if (RREG32(mmVCE_STATUS) & (VCE_STATUS_VCPU_REPORT_AUTO_BUSY_MASK

|

Quoted 1 line

drivers/gpu/drm/amd/amdgpu/vce_v1_0.c

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/vce_v1_0.c +1 -0
+				

VCE_STATUS_VCPU_REPORT_RB0_BUSY_MASK |

Quoted 1 line

drivers/gpu/drm/amd/amdgpu/vce_v1_0.c

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/vce_v1_0.c +1 -0
+				

VCE_STATUS_VCPU_REPORT_RB1_BUSY_MASK))

Quoted 25 lines
Quoted 25 lines
drivers/gpu/drm/amd/amdgpu/vce_v1_0.c +3 -0
+		return false;
+
+	return !(RREG32(mmSRBM_STATUS2) & SRBM_STATUS2__VCE_BUSY_MASK);
 
   }
 
   static int vce_v1_0_wait_for_idle(struct amdgpu_ip_block *ip_block)
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/include/asic_reg/vce/vce_1_0_sh_mask.h index 1f82d6f5abde..13c15c2138b3 100644

drivers/gpu/drm/amd/include/asic_reg/vce/vce_1_0_sh_mask.h +0 -2
@@ -63,8 +63,6 @@
 
   #define VCE_SOFT_RESET__ECPU_SOFT_RESET__SHIFT 0x00000000
   #define VCE_SOFT_RESET__FME_SOFT_RESET_MASK 0x00000004L
   #define VCE_SOFT_RESET__FME_SOFT_RESET__SHIFT 0x00000002
 
-#define VCE_STATUS__JOB_BUSY_MASK 0x00000001L
-#define VCE_STATUS__JOB_BUSY__SHIFT 0x00000000
 
   #define VCE_STATUS__UENC_BUSY_MASK 0x00000100L
   #define VCE_STATUS__UENC_BUSY__SHIFT 0x00000008
   #define VCE_STATUS__VCPU_REPORT_MASK 0x000000feL
#4 lore raw
Quoted 31 lines · David Rosca
Quoted 23 lines · Timur Kristóf
Quoted 12 lines · Central European Standard Time David Rosca
Quoted 11 lines · Timur Kristóf

It turns out that the VCE_STATUS register bits that we used to check whether VCE1 is idle are actually not useful:
VCE_STATUS.JOB_BUSY doesn't exist until VCE3 VCE_STATUS.UENC_BUSY seems to be stuck high on Cape Verde

Instead, do the following:
Check that the read and write pointer matches for each ring. Check VCE_STATUS.VCPU_REPORT bits to check busy status. Finally, also check SRBM_STATUS2.VCE_BUSY just in case, although this one seems bogus on VCE1.

Quoted 8 lines
Quoted 3 lines
Fixes d4a640d4b9f3 ("drm/amdgpu/vce1: Implement VCE1 IP block

(v2)")

There's still occasional warning that VCE is not idle on my cape verde,
but it's much better than the current state where it prints it every time.

Quoted 6 lines

Hi David,

Can you say what the remaining warning says?
Do you think we could fix the remaining warning by removing the check for the
SRBM_STATUS bit entirely?

Quoted 6 lines

VCE busy: VCE_STATUS=0x142, SRBM_STATUS2=0x80
VCE busy: VCE_STATUS=0x152, SRBM_STATUS2=0x80

which does look like VCE is indeed busy.

David

It looks like 0x152 has the RB0_BUSY bit set, but 0x142 seems like it doesn't have any of the busy bits set and only the SRBM thinks that the VCE is busy but it may not be actually busy. It's hard to judge without more information.

When do you see the warning? Does it happen after an encoding job or after suspend/resume? Or...?

Thanks,
Timur

Tested-by
#5 lore raw
Quoted 2 lines · Timur Kristóf

When do you see the warning? Does it happen after an encoding job or after suspend/resume? Or...?

Hi Timur,

I'm not David, but I see both on a MacBookPro11,5 (R9 M370X, Cape Verde, 1002:6821). Kernel 7.2.15 with your patch, VCE enabled (no amdgpu.ip_block_mask), and the SI reset-at-load patch from [1], which this machine needs for S3.

Without your patch, "VCE busy" is logged on every VCE stop: at load, at suspend, right after S3 resume and about 1 s later. That was 24 messages over 8 S3 cycles, 21 of them VCE_STATUS=0x100, SRBM_STATUS2=0x0.

With your patch:

- Load and suspend: no message.
- 8 S3 cycles of 30 s: all resumes fine, 3 messages, each VCE_STATUS=0x102, SRBM_STATUS2=0x80, right after resume or about 1 s later.
- 7 H.264 encodes (ffmpeg h264_vaapi, 1280x720) in two batches: all worked, 1 message per batch, each VCE_STATUS=0x142, SRBM_STATUS2=0x80. That's the same value David reported.

None of the remaining messages has AUTO_BUSY, RB0_BUSY or RB1_BUSY set in VCE_STATUS, so each one came from either a ring pointer mismatch or SRBM_STATUS2.VCE_BUSY. The message doesn't say which. I'm happy to test a version that drops the SRBM_STATUS2 check, or that logs the ring pointers.

[1] https://lore.kernel.org/amd-gfx/[email protected]/T/

Maciej