Re: [PATCH 2/2] drm/etnaviv: Add GPU reset counters
From: Lucas Stach
Date: Fri Jul 10 2026 - 04:05:59 EST
Hi Christian,
Am Donnerstag, dem 09.07.2026 um 16:57 +0200 schrieb Christian Gmeiner:
> From: Christian Gmeiner <cgmeiner@xxxxxxxxxx>
>
> The OpenGL and Vulkan robustness extensions let an application detect a
> GPU reset and check if its own context caused it, so the application can
> drop the broken context and build a new one. The kernel knows both
> facts, but etnaviv has no way to report them to userspace.
>
> Add two counters and expose them through GET_PARAM: a per-GPU counter
> that counts every reset of that GPU, and a per-context counter that only
> counts the resets this context was guilty of. Userspace compares the
> counters with saved values: if the context counter moved the context was
> guilty, if only the GPU counter moved the context was an innocent
> victim.
>
> The GPU counter is per GPU core and not per device, so a hang on one
> pipe does not look like an innocent reset to contexts that only use
> another pipe.
>
> Bump the driver minor version so userspace can detect the feature.
>
> Signed-off-by: Christian Gmeiner <cgmeiner@xxxxxxxxxx>
> ---
> drivers/gpu/drm/etnaviv/etnaviv_drv.c | 5 +++--
> drivers/gpu/drm/etnaviv/etnaviv_drv.h | 1 +
> drivers/gpu/drm/etnaviv/etnaviv_gpu.c | 12 +++++++++++-
> drivers/gpu/drm/etnaviv/etnaviv_gpu.h | 6 +++++-
> drivers/gpu/drm/etnaviv/etnaviv_sched.c | 3 +++
> include/uapi/drm/etnaviv_drm.h | 2 ++
> 6 files changed, 25 insertions(+), 4 deletions(-)
>
[...]
> diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gpu.h b/drivers/gpu/drm/etnaviv/etnaviv_gpu.h
> index 5cb46c84e03a..a5d7c2158eb5 100644
> --- a/drivers/gpu/drm/etnaviv/etnaviv_gpu.h
> +++ b/drivers/gpu/drm/etnaviv/etnaviv_gpu.h
> @@ -148,6 +148,8 @@ struct etnaviv_gpu {
> u32 hangcheck_primid;
> u32 hangcheck_fence;
>
> + atomic_t reset_counter;
> +
> void __iomem *mmio;
> int irq;
>
> @@ -204,7 +206,9 @@ static inline u32 gpu_read_power(struct etnaviv_gpu *gpu, u32 reg)
> return readl(gpu->mmio + gpu_fix_power_address(gpu, reg));
> }
>
> -int etnaviv_gpu_get_param(struct etnaviv_gpu *gpu, u32 param, u64 *value);
> +int etnaviv_gpu_get_param(struct etnaviv_gpu *gpu,
> + struct etnaviv_file_private *ctx,
> + u32 param, u64 *value);
>
> int etnaviv_gpu_init(struct etnaviv_gpu *gpu);
> bool etnaviv_fill_identity_from_hwdb(struct etnaviv_gpu *gpu);
> diff --git a/drivers/gpu/drm/etnaviv/etnaviv_sched.c b/drivers/gpu/drm/etnaviv/etnaviv_sched.c
> index 139e6e38784b..398608009924 100644
> --- a/drivers/gpu/drm/etnaviv/etnaviv_sched.c
> +++ b/drivers/gpu/drm/etnaviv/etnaviv_sched.c
> @@ -79,6 +79,9 @@ static enum drm_gpu_sched_stat etnaviv_sched_timedout_job(struct drm_sched_job
> if(sched_job)
> drm_sched_increase_karma(sched_job);
>
> + atomic_inc(&gpu->reset_counter);
> + atomic_inc(&submit->ctx->reset_counter);
> +
There is no reason for those to be atomics. We only have a single
submission channel per GPU, so there can never be more than a single
timeout handler active at the same time, so those variables can be
plain ints.
Regards,
Lucas