drm/v3d: Add parameter to retrieve the number of GPU resets per-fd

The GL extension KHR_robustness uses the number of global and per-context
GPU resets to learn about graphics resets that affect a GL context. This
commit introduces a new V3D parameter to retrieve the number of GPU resets
triggered by jobs submitted through a file descriptor.

To retrieve this information, user-space must use DRM_V3D_PARAM_CONTEXT_RESET_COUNTER.

Reviewed-by: Iago Toral Quiroga <itoral@igalia.com>
Link: https://lore.kernel.org/r/20250711-v3d-reset-counter-v1-2-1ac73e9fca2d@igalia.com
Signed-off-by: Maíra Canal <mcanal@igalia.com>
This commit is contained in:
Maíra Canal
2025-07-11 12:18:32 -03:00
parent 5774b3cfde
commit 769c153cfc
4 changed files with 16 additions and 0 deletions

View File

@@ -46,6 +46,7 @@ MODULE_PARM_DESC(super_pages, "Enable/Disable Super Pages support.");
static int v3d_get_param_ioctl(struct drm_device *dev, void *data,
struct drm_file *file_priv)
{
struct v3d_file_priv *v3d_priv = file_priv->driver_priv;
struct v3d_dev *v3d = to_v3d_dev(dev);
struct drm_v3d_get_param *args = data;
static const u32 reg_map[] = {
@@ -112,6 +113,11 @@ static int v3d_get_param_ioctl(struct drm_device *dev, void *data,
args->value = v3d->reset_counter;
mutex_unlock(&v3d->reset_lock);
return 0;
case DRM_V3D_PARAM_CONTEXT_RESET_COUNTER:
mutex_lock(&v3d->reset_lock);
args->value = v3d_priv->reset_counter;
mutex_unlock(&v3d->reset_lock);
return 0;
default:
DRM_DEBUG("Unknown parameter %d\n", args->param);
return -EINVAL;

View File

@@ -230,6 +230,12 @@ struct v3d_file_priv {
/* Stores the GPU stats for a specific queue for this fd. */
struct v3d_stats stats[V3D_MAX_QUEUES];
/* Per-fd reset counter, must be incremented when a job submitted
* by this fd causes a GPU reset. It must be protected by
* &struct v3d_dev->reset_lock.
*/
unsigned int reset_counter;
};
struct v3d_bo {

View File

@@ -717,6 +717,8 @@ v3d_cache_clean_job_run(struct drm_sched_job *sched_job)
static enum drm_gpu_sched_stat
v3d_gpu_reset_for_timeout(struct v3d_dev *v3d, struct drm_sched_job *sched_job)
{
struct v3d_job *job = to_v3d_job(sched_job);
struct v3d_file_priv *v3d_priv = job->file->driver_priv;
enum v3d_queue q;
mutex_lock(&v3d->reset_lock);
@@ -732,6 +734,7 @@ v3d_gpu_reset_for_timeout(struct v3d_dev *v3d, struct drm_sched_job *sched_job)
v3d_reset(v3d);
v3d->reset_counter++;
v3d_priv->reset_counter++;
for (q = 0; q < V3D_MAX_QUEUES; q++)
drm_sched_resubmit_jobs(&v3d->queue[q].sched);

View File

@@ -295,6 +295,7 @@ enum drm_v3d_param {
DRM_V3D_PARAM_MAX_PERF_COUNTERS,
DRM_V3D_PARAM_SUPPORTS_SUPER_PAGES,
DRM_V3D_PARAM_GLOBAL_RESET_COUNTER,
DRM_V3D_PARAM_CONTEXT_RESET_COUNTER,
};
struct drm_v3d_get_param {