drm/msm: preemption aware hangcheck
Subsystems (4)
PATCH v3 1/1 drm/msm: preemption aware hangcheck
Rework hangcheck code to work well toghether with preemption.
Track the time a job has spent in a ring by storing timestamps of the CP_ALWAYS_ON_CONTEXT register at the beginning of a job and when switching rings as well as reading it back if the ring is currently active.
---
Ever since we added support for preemption hangcheck has been somewhat broken as it is not aware of multiple rings.
In some cases it might not recognize that one ring is stuck if the gpu switches in and out of it.
depends on https://lore.kernel.org/linux-arm-msm/[email protected]
---
Changes in v3:
- Addressed sashiko's feedback
- Rebased on reworked IFPC disable series
- Link to v2: https://patch.msgid.link/[email protected]
Changes in v2:
- Various fixes
- Fix interaction with IFPC by using OOB vote
- Link to v1: https://lore.kernel.org/r/[email protected]
To: Rob Clark <[email protected]>
To: Sean Paul <[email protected]>
To: Konrad Dybcio <[email protected]>
To: Akhil P Oommen <[email protected]>
To: Dmitry Baryshkov <[email protected]>
To: Abhinav Kumar <[email protected]>
To: Jessica Zhang <[email protected]>
To: Marijn Suijten <[email protected]>
To: David Airlie <[email protected]>
To: Simona Vetter <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
--- drivers/gpu/drm/msm/adreno/a5xx_gpu.c | 5 +-- drivers/gpu/drm/msm/adreno/a6xx_gmu.c | 6 +--- drivers/gpu/drm/msm/adreno/a6xx_gpu.c | 54 +++++++++++++++++++++++------ drivers/gpu/drm/msm/adreno/a6xx_gpu.h | 1 + drivers/gpu/drm/msm/adreno/a6xx_preempt.c | 32 +++++++++++++----- drivers/gpu/drm/msm/adreno/a8xx_gpu.c | 12 ++----- drivers/gpu/drm/msm/adreno/adreno_gpu.c | 3 +- drivers/gpu/drm/msm/msm_gpu.c | 56 ++++++++++++++++++++++++------- drivers/gpu/drm/msm/msm_gpu.h | 11 ++++++ drivers/gpu/drm/msm/msm_ringbuffer.h | 10 ++++++ 10 files changed, 140 insertions(+), 50 deletions(-)
drivers/gpu/drm/msm/adreno/a5xx_gpu.c +1 -4
@@ -1251,10 +1251,7 @@ static void a5xx_fault_detect_irq(struct msm_gpu *gpu)gpu_read64 (gpu,REG_A5XX_CP_IB2_BASE ), gpu_read(gpu, REG_A5XX_CP_IB2_BUFSZ)); -/* Turn off the hangcheck timer to keep it from bothering us */ -timer_delete (&gpu->hangcheck_timer); - -kthread_queue_work (gpu->worker, &gpu->recover_work); +msm_trigger_recovery (gpu); }#define RBBM_ERROR_MASK \
drivers/gpu/drm/msm/adreno/a6xx_gmu.c +1 -5
@@ -28,11 +28,7 @@ static void a6xx_gmu_fault(struct a6xx_gmu *gmu)/* FIXME: add a banner here */ gmu->hung = true; -/* Turn off the hangcheck timer while we are resetting */ -timer_delete (&gpu->hangcheck_timer); - -/* Queue the GPU handler because we need to treat this as a recovery */ -kthread_queue_work (gpu->worker, &gpu->recover_work); +msm_trigger_recovery (gpu); }static irqreturn_t a6xx_gmu_irq (int irq,void *data)
drivers/gpu/drm/msm/adreno/a6xx_gpu.c +44 -10
94 lines not on this page · raw message
drivers/gpu/drm/msm/adreno/a6xx_gpu.h +1 -0
@@ -105,6 +105,7 @@ struct a6xx_gpu {struct drm_gem_object *preempt_postamble_bo;void *preempt_postamble_ptr;uint64_t preempt_postamble_iova; +uint64_t preempt_postamble_cntreset_end;uint64_t preempt_postamble_len;bool postamble_enabled;
drivers/gpu/drm/msm/adreno/a6xx_preempt.c +23 -9
@@ -21,14 +21,18 @@ static void a6xx_preempt_timer(struct timer_list *t)return ;dev_err (dev->dev,"%s: preemption timed out\n" , gpu->name); -kthread_queue_work (gpu->worker, &gpu->recover_work); +msm_trigger_recovery (gpu); } -static void preempt_prepare_postamble (struct a6xx_gpu *a6xx_gpu) +static void preempt_prepare_postamble (struct a6xx_gpu *a6xx_gpu,struct msm_ringbuffer *ring) {u32 *postamble = a6xx_gpu->preempt_postamble_ptr; +uint64_t last_active_ctxcycles =0 ;u32 count =0 ; +if (ring) + last_active_ctxcycles =rbmemptr (ring, last_active_ctxcycles); + postamble[count++] =PKT7 (CP_REG_RMW ,3 ); postamble[count++] =REG_A6XX_RBBM_PERFCTR_SRAM_INIT_CMD ; postamble[count++] =0 ;
@@ -43,6 +47,17 @@ static void preempt_prepare_postamble(struct a6xx_gpu *a6xx_gpu) postamble[count++] =CP_WAIT_REG_MEM_4_MASK (0x1 ); postamble[count++] =CP_WAIT_REG_MEM_5_DELAY_LOOP_CYCLES (0 ); + a6xx_gpu->preempt_postamble_cntreset_end = count; + +if (last_active_ctxcycles) { + postamble[count++] =PKT7 (ring ?CP_REG_TO_MEM :CP_NOP ,3 ); + postamble[count++] =CP_REG_TO_MEM_0_REG (REG_A6XX_CP_ALWAYS_ON_CONTEXT ) | +CP_REG_TO_MEM_0_CNT (2 ) | +CP_REG_TO_MEM_0_IS_64B ; + postamble[count++] =lower_32_bits (last_active_ctxcycles); + postamble[count++] =upper_32_bits (last_active_ctxcycles); + } + a6xx_gpu->preempt_postamble_len = count; a6xx_gpu->postamble_enabled = true;
@@ -54,9 +69,9 @@ static void preempt_disable_postamble(struct a6xx_gpu *a6xx_gpu)/* * Disable the postamble by replacing the first packet header with a NOP -* that covers the whole buffer. +* that skips the counters reset part. */ - *postamble =PKT7 (CP_NOP , (a6xx_gpu->preempt_postamble_len -1 )); + *postamble =PKT7 (CP_NOP , (a6xx_gpu->preempt_postamble_cntreset_end -1 )); a6xx_gpu->postamble_enabled = false; }
@@ -263,10 +278,9 @@ void a6xx_preempt_trigger(struct msm_gpu *gpu)/* Enable or disable postamble as needed */ sysprof =msm_gpu_sysprof_no_perfcntr_zap (gpu); -if (!sysprof && !a6xx_gpu->postamble_enabled) -preempt_prepare_postamble (a6xx_gpu); - -if (sysprof && a6xx_gpu->postamble_enabled) +if (!sysprof) +preempt_prepare_postamble (a6xx_gpu, ring); +else preempt_disable_postamble (a6xx_gpu);/* Set the preemption state to triggered */
@@ -382,7 +396,7 @@ void a6xx_preempt_init(struct msm_gpu *gpu)if (IS_ERR (a6xx_gpu->preempt_postamble_ptr)) goto fail; -preempt_prepare_postamble (a6xx_gpu); +preempt_prepare_postamble (a6xx_gpu,NULL );timer_setup (&a6xx_gpu->preempt_timer, a6xx_preempt_timer,0 );
drivers/gpu/drm/msm/adreno/a8xx_gpu.c +3 -9
@@ -1184,10 +1184,7 @@ static void a8xx_fault_detect_irq(struct msm_gpu *gpu)a8xx_aperture_release (gpu, flags);a8xx_aperture_clear (gpu); -/* Turn off the hangcheck timer to keep it from bothering us */ -timer_delete (&gpu->hangcheck_timer); - -kthread_queue_work (gpu->worker, &gpu->recover_work); +msm_trigger_recovery (gpu); }static void a8xx_sw_fuse_violation_irq (struct msm_gpu *gpu)
@@ -1204,11 +1201,8 @@ static void a8xx_sw_fuse_violation_irq(struct msm_gpu *gpu)* to legacy blending. */ if (status & (A7XX_CX_MISC_SW_FUSE_VALUE_RAYTRACING | -A7XX_CX_MISC_SW_FUSE_VALUE_LPAC )) { -timer_delete (&gpu->hangcheck_timer); - -kthread_queue_work (gpu->worker, &gpu->recover_work); - } +A7XX_CX_MISC_SW_FUSE_VALUE_LPAC )) +msm_trigger_recovery (gpu); }irqreturn_t a8xx_irq (struct msm_gpu *gpu)
drivers/gpu/drm/msm/adreno/adreno_gpu.c +2 -1
@@ -335,7 +335,8 @@ int adreno_fault_handler(struct msm_gpu *gpu, unsigned long iova, int flags,struct msm_gpu_fault_info fault_info = {};/* Turn off the hangcheck timer to keep it from bothering us */ -timer_delete (&gpu->hangcheck_timer); +for (int i =0 ; i < gpu->nr_rings; i++) +timer_delete (&gpu->rb[i]->hangcheck_timer);/* Let any concurrent GMU transactions know that the MMU may be * blocked for a while and they should wait on us.
drivers/gpu/drm/msm/msm_gpu.c +44 -12
118 lines not on this page · raw message
drivers/gpu/drm/msm/msm_gpu.h +11 -0
@@ -101,6 +101,7 @@ struct msm_gpu_funcs {/* Flush perfcntrs before reading (optional): */ void (*perfcntr_flush)(struct msm_gpu *gpu); +int (*get_ctx_timestamp)(struct msm_ringbuffer *ring,uint64_t *value); };/* Additional state for iommu faults: */
@@ -249,6 +250,8 @@ struct msm_gpu {/* work for handling GPU recovery: */ struct kthread_work recover_work; +struct msm_ringbuffer *hung_ring; +/** retire_event: notified when submits are retired: */ wait_queue_head_t retire_event;
@@ -816,6 +819,14 @@ static inline void msm_gpu_crashstate_put(struct msm_gpu *gpu)mutex_unlock (&gpu->lock); } +static inline void msm_trigger_recovery (struct msm_gpu *gpu) +{ +for (int i =0 ; i < gpu->nr_rings; i++) +timer_delete (&gpu->rb[i]->hangcheck_timer); + +kthread_queue_work (gpu->worker, &gpu->recover_work); +} +void msm_gpu_fault_crashstate_capture (struct msm_gpu *gpu,struct msm_gpu_fault_info *fault_info);/*
drivers/gpu/drm/msm/msm_ringbuffer.h +10 -0
@@ -39,6 +39,9 @@ struct msm_rbmemptrs {volatile u32 context_idr;volatile u32 perfcntr_fence; + +volatile u64 last_job_start_ctx; +volatile u64 last_active_ctxcycles; };struct msm_cp_state {
@@ -77,6 +80,13 @@ struct msm_ringbuffer {uint64_t memptrs_iova;struct msm_fence_context *fctx; +/* Hang and Inactivity Detection: +*/ +struct timer_list hangcheck_timer; + +/* work for handling GPU hangcheck: */ +struct kthread_work hangcheck_work; +/** * hangcheck_progress_retries: *
---
base-commit: 446a86f7c96426b3f9f7d23d239c95cf9dd95ffe
change-id: 20250911-preemption_aware_hangcheck-8b9b3708efcc
Best regards,
Signature · 1 line
Anna Maniscalco <[email protected]>
Quoted 7 lines · Anna Maniscalco
Rework hangcheck code to work well toghether with preemption.
Track the time a job has spent in a ring by storing timestamps of the
CP_ALWAYS_ON_CONTEXTregister at the beginning of a job and when switching rings as well as reading it back if the ring is currently active.
Quoted 7 lines
Signed-off-by Anna Maniscalco <[email protected]>---
Ever since we added support for preemption hangcheck has been somewhat broken as it is not aware of multiple rings.In some cases it might not recognize that one ring is stuck if the gpu switches in and out of it.
This text should start the commit message, it's a description of the problem. The text under three dashes will not land in the kernel and so nobody would know why you were doing these changes.
Quoted 152 lines
depends on https://lore.kernel.org/linux-arm-msm/[email protected]
---
Changes in v3:
- Addressed sashiko's feedback
- Rebased on reworked IFPC disable series
- Link to v2: https://patch.msgid.link/[email protected]Changes in v2:
- Various fixes
- Fix interaction with IFPC by using OOB vote
- Link to v1: https://lore.kernel.org/r/[email protected]To: Rob Clark <[email protected]>
To: Sean Paul <[email protected]>
To: Konrad Dybcio <[email protected]>
To: Akhil P Oommen <[email protected]>
To: Dmitry Baryshkov <[email protected]>
To: Abhinav Kumar <[email protected]>
To: Jessica Zhang <[email protected]>
To: Marijn Suijten <[email protected]>
To: David Airlie <[email protected]>
To: Simona Vetter <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]--- drivers/gpu/drm/msm/adreno/a5xx_gpu.c | 5 +-- drivers/gpu/drm/msm/adreno/a6xx_gmu.c | 6 +--- drivers/gpu/drm/msm/adreno/a6xx_gpu.c | 54 +++++++++++++++++++++++------ drivers/gpu/drm/msm/adreno/a6xx_gpu.h | 1 + drivers/gpu/drm/msm/adreno/a6xx_preempt.c | 32 +++++++++++++----- drivers/gpu/drm/msm/adreno/a8xx_gpu.c | 12 ++----- drivers/gpu/drm/msm/adreno/adreno_gpu.c | 3 +- drivers/gpu/drm/msm/msm_gpu.c | 56 ++++++++++++++++++++++++------- drivers/gpu/drm/msm/msm_gpu.h | 11 ++++++ drivers/gpu/drm/msm/msm_ringbuffer.h | 10 ++++++ 10 files changed, 140 insertions(+), 50 deletions(-)drivers/gpu/drm/msm/adreno/a5xx_gpu.c +1
-4@@ -1251,10 +1251,7 @@ static void a5xx_fault_detect_irq(struct msm_gpu *gpu)gpu_read64 (gpu,REG_A5XX_CP_IB2_BASE ), gpu_read(gpu, REG_A5XX_CP_IB2_BUFSZ)); -/* Turn off the hangcheck timer to keep it from bothering us */ -timer_delete (&gpu->hangcheck_timer); - -kthread_queue_work (gpu->worker, &gpu->recover_work); +msm_trigger_recovery (gpu); }#define RBBM_ERROR_MASK \drivers/gpu/drm/msm/adreno/a6xx_gmu.c +1
-5@@ -28,11 +28,7 @@ static void a6xx_gmu_fault(struct a6xx_gmu *gmu)/* FIXME: add a banner here */ gmu->hung = true; -/* Turn off the hangcheck timer while we are resetting */ -timer_delete (&gpu->hangcheck_timer); - -/* Queue the GPU handler because we need to treat this as a recovery */ -kthread_queue_work (gpu->worker, &gpu->recover_work); +msm_trigger_recovery (gpu); }static irqreturn_t a6xx_gmu_irq (int irq,void *data)drivers/gpu/drm/msm/adreno/a6xx_gpu.c +29
-10@@ -519,6 +519,9 @@ static void a7xx_submit(struct msm_gpu *gpu, struct msm_gem_submit *submit)get_stats_counter (ring, rbbm_perfctr_cp0,rbmemptr_stats (ring, index, cpcycles_start));get_stats_counter (ring, cp_always_on_context,rbmemptr_stats (ring, index, alwayson_start)); +get_stats_counter (ring, cp_always_on_context, +rbmemptr (ring, last_job_start_ctx)); +OUT_PKT7 (ring,CP_THREAD_CONTROL ,1 );OUT_RING (ring,CP_SET_THREAD_BOTH );@@ -1474,8 +1477,11 @@ static int hw_init(struct msm_gpu *gpu)/* Always come up on rb 0 */ a6xx_gpu->cur_ring = gpu->rb[0 ]; -for (i =0 ; i < gpu->nr_rings; i++) +for (i =0 ; i < gpu->nr_rings; i++) { gpu->rb[i]->cur_ctx_seqno =0 ; + gpu->rb[i]->memptrs->last_job_start_ctx =0 ; + gpu->rb[i]->memptrs->last_active_ctxcycles =0 ; + }/* Enable the SQE_to start the CP engine */ gpu_write (gpu,REG_A6XX_CP_SQE_CNTL ,1 );@@ -1838,13 +1844,10 @@ static void a6xx_fault_detect_irq(struct msm_gpu *gpu)gpu_read64 (gpu,REG_A6XX_CP_IB2_BASE ), gpu_read(gpu, REG_A6XX_CP_IB2_REM_SIZE)); -/* Turn off the hangcheck timer to keep it from bothering us */ -timer_delete (&gpu->hangcheck_timer); -/* Turn off interrupts to avoid triggering recovery again */ gpu_write (gpu,REG_A6XX_RBBM_INT_0_MASK ,0 ); -kthread_queue_work (gpu->worker, &gpu->recover_work); +msm_trigger_recovery (gpu); }static void a7xx_sw_fuse_violation_irq (struct msm_gpu *gpu)@@ -1861,11 +1864,8 @@ static void a7xx_sw_fuse_violation_irq(struct msm_gpu *gpu)* to legacy blending. */ if (status & (A7XX_CX_MISC_SW_FUSE_VALUE_RAYTRACING | -A7XX_CX_MISC_SW_FUSE_VALUE_LPAC )) { -timer_delete (&gpu->hangcheck_timer); - -kthread_queue_work (gpu->worker, &gpu->recover_work); - } +A7XX_CX_MISC_SW_FUSE_VALUE_LPAC )) +msm_trigger_recovery (gpu); }static void a6xx_gpu_keepalive_vote (struct msm_gpu *gpu,bool on)@@ -2293,6 +2293,39 @@ static u64 a6xx_get_timestamp(struct msm_gpu *gpu)return gpu_read64 (gpu,REG_A6XX_CP_ALWAYS_ON_COUNTER ); } +static int a6xx_get_ctx_timestamp (struct msm_ringbuffer *ring,uint64_t *value) +{ +struct msm_gpu *gpu = ring->gpu; +struct adreno_gpu *adreno_gpu =to_adreno_gpu (gpu); +struct a6xx_gpu *a6xx_gpu =to_a6xx_gpu (adreno_gpu); +int ret =0 ; + +/* Inhibit IFPC while accessing registers: */ +guard (ifpc_disable)(gpu); + +/* +* a6xx_gmu_set_oob cannot be called while holding a spinlock. +* Limit the scope. +*/ +if (gpu->nr_rings ==1 ) { +guard (spinlock_irqsave)(&a6xx_gpu->eval_lock); + +/* +* Make sure the GMU keeps the GPU on while we read the register
drivers/gpu/drm/msm/adreno/a6xx_gpu.c static u64 a6xx_get_timestamp(struct msm_gpu *gpu) · line 2324
Quoted 10 lines
drivers/gpu/drm/msm/adreno/a6xx_gpu.c +10
-0+* +* This should normally not be waking up the gpu since the +* hangcheck timer shouldn't fire when the gpu is idle. +*/ +if (a6xx_in_preempt (a6xx_gpu) || ring != a6xx_gpu->cur_ring) +return -EBUSY ; + + *value =gpu_read64 (gpu,REG_A6XX_CP_ALWAYS_ON_CONTEXT ); + }else + *value =gpu_read64 (gpu,REG_A6XX_CP_ALWAYS_ON_CONTEXT );
Isn't this inverted? With the single ring, there is no other ring and no preemtpion.
Quoted 9 lines
drivers/gpu/drm/msm/adreno/a6xx_gpu.c +4
-0+ +return ret; +} +static struct msm_ringbuffer *a6xx_active_ring (struct msm_gpu *gpu) {struct adreno_gpu *adreno_gpu =to_adreno_gpu (gpu);
drivers/gpu/drm/msm/adreno/a6xx_gpu.c static void preempt_prepare_postamble(struct a6xx_gpu *a6xx_gpu) · line 53
Quoted 7 lines
drivers/gpu/drm/msm/adreno/a6xx_gpu.c +4
-0@@ -43,6 +47,17 @@ static void preempt_prepare_postamble(struct a6xx_gpu *a6xx_gpu) postamble[count++] =CP_WAIT_REG_MEM_4_MASK (0x1 ); postamble[count++] =CP_WAIT_REG_MEM_5_DELAY_LOOP_CYCLES (0 ); + a6xx_gpu->preempt_postamble_cntreset_end = count; + +if (last_active_ctxcycles) { + postamble[count++] =PKT7 (ring ?CP_REG_TO_MEM :CP_NOP ,3 );
ring is always non-NULL here
Quoted 10 lines
drivers/gpu/drm/msm/adreno/a6xx_gpu.c +7
-0+ postamble[count++] =CP_REG_TO_MEM_0_REG (REG_A6XX_CP_ALWAYS_ON_CONTEXT ) | +CP_REG_TO_MEM_0_CNT (2 ) | +CP_REG_TO_MEM_0_IS_64B ; + postamble[count++] =lower_32_bits (last_active_ctxcycles); + postamble[count++] =upper_32_bits (last_active_ctxcycles); + } + a6xx_gpu->preempt_postamble_len = count; a6xx_gpu->postamble_enabled = true;
Signature · 2 lines
With best wishes Dmitry