Skip to contentSkip to conversation

drm/msm/adreno: implement progress handlers for a2xx, a3xx and a5xx

PATCH In review Dmitry Baryshkov 3 participants 8 messages Sep 30 – Oct 3

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

v2 cover drm/msm/adreno: implement progress handlers for a2xx, a3xx and a5xx

Adreno A2xx, A3xx and A5xx don't have progress callbacks, so any submit still running when the hangcheck timer expires is declared hung, and long compute or drawing dispatches are reset while still making progress.

Implement a2xx_progress(), a3xx_progress() and a5xx_progress() callbacks.

---
Changes in v2:
- Added a matching progress callback for a2xx (new patch 1).
- Link to v1: https://patch.msgid.link/[email protected]

---
Dmitry Baryshkov (3):
drm/msm/a2xx: Add hangcheck progress detection drm/msm/a3xx: Add hangcheck progress detection drm/msm/a5xx: Add hangcheck progress detection

 drivers/gpu/drm/msm/adreno/a2xx_gpu.c | 18 ++++++++++++++++++
 drivers/gpu/drm/msm/adreno/a3xx_gpu.c | 18 ++++++++++++++++++
 drivers/gpu/drm/msm/adreno/a5xx_gpu.c | 27 +++++++++++++++++++++++++++
 drivers/gpu/drm/msm/adreno/a5xx_gpu.h |  2 ++
 4 files changed, 65 insertions(+)

---
base-commit: a15fac810c76397ec9f62a6fc26c4d7ab6e238a7
change-id: 20260927-adreno-progress-87f92d081376

Best regards,

Signature · 2 lines
With best wishes
Dmitry
#1 lore raw

PATCH v2 1/3 drm/msm/a2xx: Add hangcheck progress detection

A2xx has no progress callback, so any submit still running when the hangcheck timer expires is declared hung, no matter whether the CP is advancing. A false lockup is particularly expensive here: a2xx recovery is unreliable, and a second reset shortly after the first one leaves a2xx_hw_init() failing for good, so everything submitted afterwards fails as well.

Compare the CP IB1/IB2 base and remaining size between timer expirations, like a6xx does.

Assisted-by LLM
---
 drivers/gpu/drm/msm/adreno/a2xx_gpu.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
drivers/gpu/drm/msm/adreno/a2xx_gpu.c +18 -0
index df4cded9143f..59d2f1684e6a 100644
@@ -489,6 +489,23 @@ static u32 a2xx_get_rptr(struct msm_gpu *gpu, struct msm_ringbuffer *ring)
 	return ring->memptrs->rptr;
 }
 
+static bool a2xx_progress(struct msm_gpu *gpu, struct msm_ringbuffer *ring)
+{
+	struct msm_cp_state cp_state = {
+		.ib1_base = gpu_read(gpu, REG_AXXX_CP_IB1_BASE),
+		.ib2_base = gpu_read(gpu, REG_AXXX_CP_IB2_BASE),
+		.ib1_rem  = gpu_read(gpu, REG_AXXX_CP_IB1_BUFSZ),
+		.ib2_rem  = gpu_read(gpu, REG_AXXX_CP_IB2_BUFSZ),
+	};
+	bool progress;
+
+	progress = !!memcmp(&cp_state, &ring->last_cp_state, sizeof(cp_state));
+
+	ring->last_cp_state = cp_state;
+
+	return progress;
+}
+
 static struct msm_gpu *a2xx_gpu_init(struct drm_device *dev)
 {
 	struct a2xx_gpu *a2xx_gpu = NULL;
@@ -553,6 +570,7 @@ const struct adreno_gpu_funcs a2xx_gpu_funcs = {
 		.gpu_state_put = adreno_gpu_state_put,
 		.create_vm = a2xx_create_vm,
 		.get_rptr = a2xx_get_rptr,
+		.progress = a2xx_progress,
 	},
 	.init = a2xx_gpu_init,
 };
Signature · 1 line
2.47.3
#2 lore raw

PATCH v2 2/3 drm/msm/a3xx: Add hangcheck progress detection

In reply to Dmitry Baryshkov

A3xx has no progress callback, so the hangcheck declares a lockup as soon as a submit is still running when the timer expires, no matter whether the CP is advancing. On A306 a piglit tex-miplevel-selection run is a single submit of about 58k draws that takes 1.2-1.3 s to complete, and it gets reset partway through on every run. With the hangcheck period raised to 10 s the same runs pass without a hang.

Compare the CP IB1/IB2 base and remaining size between timer expirations, like a6xx does. On A306 these move on every 20 ms sample while such a submit executes and read zero when idle. The prefetch queues are small (32 and 64 for IB1 and IB2), so buffered data does not hide progress for long.

Assisted-by LLM
---
 drivers/gpu/drm/msm/adreno/a3xx_gpu.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
drivers/gpu/drm/msm/adreno/a3xx_gpu.c +18 -0
index 0259e60b8011..c95bbb4bcf47 100644
@@ -536,6 +536,23 @@ static u32 a3xx_get_rptr(struct msm_gpu *gpu, struct msm_ringbuffer *ring)
 	return ring->memptrs->rptr;
 }
 
+static bool a3xx_progress(struct msm_gpu *gpu, struct msm_ringbuffer *ring)
+{
+	struct msm_cp_state cp_state = {
+		.ib1_base = gpu_read(gpu, REG_AXXX_CP_IB1_BASE),
+		.ib2_base = gpu_read(gpu, REG_AXXX_CP_IB2_BASE),
+		.ib1_rem  = gpu_read(gpu, REG_AXXX_CP_IB1_BUFSZ),
+		.ib2_rem  = gpu_read(gpu, REG_AXXX_CP_IB2_BUFSZ),
+	};
+	bool progress;
+
+	progress = !!memcmp(&cp_state, &ring->last_cp_state, sizeof(cp_state));
+
+	ring->last_cp_state = cp_state;
+
+	return progress;
+}
+
 static struct msm_gpu *a3xx_gpu_init(struct drm_device *dev)
 {
 	struct a3xx_gpu *a3xx_gpu = NULL;
@@ -630,6 +647,7 @@ const struct adreno_gpu_funcs a3xx_gpu_funcs = {
 		.gpu_state_put = adreno_gpu_state_put,
 		.create_vm = adreno_create_vm,
 		.get_rptr = a3xx_get_rptr,
+		.progress = a3xx_progress,
 	},
 	.init = a3xx_gpu_init,
 };
Signature · 1 line
2.47.3
#3 lore raw

PATCH v2 3/3 drm/msm/a5xx: Add hangcheck progress detection

In reply to Dmitry Baryshkov

A5xx has no progress callback, so any submit still running when the hangcheck timer expires is declared hung, and long compute dispatches such as KHR-GLES31.core.compute_shader.simple-compute-shared_context are reset on A530 while still making progress.

Comparing the CP IB1/IB2 state, as a3xx and a6xx do, is not enough: during a long dispatch the CP has fetched the whole IB and waits in one packet. Also count ALU working cycles on SP performance counter 0, which Mesa leaves to the kernel (and the kernel hasn't been using up to now).

Assisted-by LLM
---
 drivers/gpu/drm/msm/adreno/a5xx_gpu.c | 27 +++++++++++++++++++++++++++
 drivers/gpu/drm/msm/adreno/a5xx_gpu.h |  2 ++
 2 files changed, 29 insertions(+)
drivers/gpu/drm/msm/adreno/a5xx_gpu.c +27 -0
index 5d96b8f63156..9f4a97195cde 100644
@@ -748,6 +748,9 @@ static int a5xx_hw_init(struct msm_gpu *gpu)
 	/* Select RBBM0 to countable 6 to get the busy status for devfreq */
 	gpu_write(gpu, REG_A5XX_RBBM_PERFCTR_RBBM_SEL_0, 6);
 
+	/* Select SP0 to count ALU cycles for hangcheck progress detection */
+	gpu_write(gpu, REG_A5XX_SP_PERFCTR_SP_SEL_0, PERF_SP_ALU_WORKING_CYCLES);
+
 	/* Increase VFD cache access so LRZ and other data gets evicted less */
 	gpu_write(gpu, REG_A5XX_UCHE_CACHE_WAYS, 0x02);
 
@@ -1687,6 +1690,29 @@ static uint32_t a5xx_get_rptr(struct msm_gpu *gpu, struct msm_ringbuffer *ring)
 	return ring->memptrs->rptr = gpu_read(gpu, REG_A5XX_CP_RB_RPTR);
 }
 
+static bool a5xx_progress(struct msm_gpu *gpu, struct msm_ringbuffer *ring)
+{
+	struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu);
+	struct a5xx_gpu *a5xx_gpu = to_a5xx_gpu(adreno_gpu);
+	struct msm_cp_state cp_state = {
+		.ib1_base = gpu_read64(gpu, REG_A5XX_CP_IB1_BASE),
+		.ib2_base = gpu_read64(gpu, REG_A5XX_CP_IB2_BASE),
+		.ib1_rem  = gpu_read(gpu, REG_A5XX_CP_IB1_BUFSZ),
+		.ib2_rem  = gpu_read(gpu, REG_A5XX_CP_IB2_BUFSZ),
+	};
+	u64 alu_cycles = gpu_read64(gpu, REG_A5XX_RBBM_PERFCTR_SP_0_LO);
+	bool progress;
+
+	/* The CP can stall on one packet while shaders keep running */
+	progress = !!memcmp(&cp_state, &ring->last_cp_state, sizeof(cp_state)) ||
+		   alu_cycles != a5xx_gpu->last_alu_cycles;
+
+	ring->last_cp_state = cp_state;
+	a5xx_gpu->last_alu_cycles = alu_cycles;
+
+	return progress;
+}
+
 static void check_speed_bin(struct device *dev)
 {
 	struct nvmem_cell *cell;
@@ -1800,6 +1826,7 @@ const struct adreno_gpu_funcs a5xx_gpu_funcs = {
 		.gpu_state_put = a5xx_gpu_state_put,
 		.create_vm = adreno_create_vm,
 		.get_rptr = a5xx_get_rptr,
+		.progress = a5xx_progress,
 	},
 	.init = a5xx_gpu_init,
 	.get_timestamp = a5xx_get_timestamp,
drivers/gpu/drm/msm/adreno/a5xx_gpu.h +2 -0
index 407bb950d350..fb05f1ca3e81 100644
@@ -36,6 +36,8 @@ struct a5xx_gpu {
 	uint64_t preempt_iova[MSM_GPU_MAX_RINGS];
 	uint32_t last_seqno[MSM_GPU_MAX_RINGS];
 
+	uint64_t last_alu_cycles;
+
 	atomic_t preempt_state;
 	spinlock_t preempt_start_lock;
 	struct timer_list preempt_timer;
Signature · 1 line
2.47.3
#4 lore raw

Re: [PATCH v2 3/3] drm/msm/a5xx: Add hangcheck progress detection

Didn't solved hangs on sdm660, but I think that it isn't related to this. However I've managed to get a command stream from hang_rd. How can I share it?

#5 lore raw

Re: [PATCH v2 3/3] drm/msm/a5xx: Add hangcheck progress detection

In reply to Dmitry Baryshkov

Didn't solved hangs on sdm660, but I think that it isn't related to this. However I've managed to get a command stream from hang_rd. How can I share it?

Signature · 2 lines
Best regards,
Nickolay
#6 lore raw

Re: [PATCH v2 3/3] drm/msm/a5xx: Add hangcheck progress detection

Quoted 3 lines · Nickolay Goppen

Didn't solved hangs on sdm660, but I think that it isn't related to this. However I've managed to get a command stream from hang_rd. How can I share it?

Open an issue at https://gitlab.freedesktop.org/mesa/mesa, tag robclark and lumag. Please note that for sdm660 you really need the patch at [1].

There are also several known issues which affect SDM660, but they are mostly on the userspace side. I hope to submit and fix them one by one (e.g. on that chip there is an issue with the blitter programming).

[1] https://patchwork.freedesktop.org/series/174541/

Signature · 2 lines
With best wishes
Dmitry
#7 lore raw

Re: [PATCH v2 3/3] drm/msm/a5xx: Add hangcheck progress detection

Quoted 6 lines · Dmitry Baryshkov
Quoted 3 lines · Nickolay Goppen

Didn't solved hangs on sdm660, but I think that it isn't related to this. However I've managed to get a command stream from hang_rd. How can I share it?

Open an issue at https://gitlab.freedesktop.org/mesa/mesa, tag robclark and lumag. Please note that for sdm660 you really need the patch at [1].

I've applied this patch, but I haven't triggered a fault to test it.

Got it, Will open an issue about it.

Quoted 7 lines

There are also several known issues which affect SDM660, but they are mostly on the userspace side. I hope to submit and fix them one by one (e.g. on that chip there is an issue with the blitter programming).

[1] https://patchwork.freedesktop.org/series/174541/

Signature · 2 lines
Best regards,
Nickolay