On Fri, Nov 06, 2026 at 05:46:28PM +0100, Anna Maniscalco wrote:
> 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.
> 
> 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.

> 
> 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(-)
> 
> diff --git a/drivers/gpu/drm/msm/adreno/a5xx_gpu.c 
> b/drivers/gpu/drm/msm/adreno/a5xx_gpu.c
> index 16c7335c4b1f..8800352455df 100644
> --- a/drivers/gpu/drm/msm/adreno/a5xx_gpu.c
> +++ b/drivers/gpu/drm/msm/adreno/a5xx_gpu.c
> @@ -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 \
> diff --git a/drivers/gpu/drm/msm/adreno/a6xx_gmu.c 
> b/drivers/gpu/drm/msm/adreno/a6xx_gmu.c
> index bba5468db42e..bcbe1b949217 100644
> --- a/drivers/gpu/drm/msm/adreno/a6xx_gmu.c
> +++ b/drivers/gpu/drm/msm/adreno/a6xx_gmu.c
> @@ -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)
> diff --git a/drivers/gpu/drm/msm/adreno/a6xx_gpu.c 
> b/drivers/gpu/drm/msm/adreno/a6xx_gpu.c
> index 773c1727dd31..179e42119307 100644
> --- a/drivers/gpu/drm/msm/adreno/a6xx_gpu.c
> +++ b/drivers/gpu/drm/msm/adreno/a6xx_gpu.c
> @@ -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
> +              *
> +              * 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.

> +
> +     return ret;
> +}
> +
>  static struct msm_ringbuffer *a6xx_active_ring(struct msm_gpu *gpu)
>  {
>       struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu);

> @@ -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

> +             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;

-- 
With best wishes
Dmitry

Reply via email to