[PATCH v3 1/2] drm/xe: Add clear_stats GT debugfs

Francois Dugast francois.dugast at intel.com
Fri Jun 27 16:24:43 UTC 2025


On Tue, Jun 03, 2025 at 04:34:44PM -0700, Matthew Brost wrote:
> It helpful to clear GT stats, run a test cases which is being profiled,
> and look at the results of the stats from the individual test case. Add
> clear_stats GT debugfs entry whih allows the clearing of GT stats.
> 
> Signed-off-by: Matthew Brost <matthew.brost at intel.com>
> ---
>  drivers/gpu/drm/xe/xe_gt_debugfs.c | 22 ++++++++++++++++++++++
>  drivers/gpu/drm/xe/xe_gt_stats.c   | 14 ++++++++++++++
>  drivers/gpu/drm/xe/xe_gt_stats.h   |  1 +
>  3 files changed, 37 insertions(+)
> 
> diff --git a/drivers/gpu/drm/xe/xe_gt_debugfs.c b/drivers/gpu/drm/xe/xe_gt_debugfs.c
> index 848618acdca8..a6888f03a4dd 100644
> --- a/drivers/gpu/drm/xe/xe_gt_debugfs.c
> +++ b/drivers/gpu/drm/xe/xe_gt_debugfs.c
> @@ -328,6 +328,27 @@ static ssize_t write_to_gt_call(const char __user *userbuf, size_t count, loff_t
>  	return count;
>  }
>  
> +static void clear_stats(struct xe_gt *gt)
> +{
> +	xe_gt_stats_clear(gt);
> +}
> +
> +static ssize_t clear_stats_write(struct file *file,
> +				 const char __user *userbuf,
> +				 size_t count, loff_t *ppos)
> +{
> +	struct seq_file *s = file->private_data;
> +	struct xe_gt *gt = s->private;
> +
> +	return write_to_gt_call(userbuf, count, ppos, clear_stats, gt);
> +}
> +
> +static int clear_stats_show(struct seq_file *s, void *unused)
> +{
> +	return 0;
> +}
> +DEFINE_SHOW_STORE_ATTRIBUTE(clear_stats);
> +
>  static void force_reset(struct xe_gt *gt)
>  {
>  	struct xe_device *xe = gt_to_xe(gt);
> @@ -408,6 +429,7 @@ void xe_gt_debugfs_register(struct xe_gt *gt)
>  	root->d_inode->i_private = gt;
>  
>  	/* VF safe */
> +	debugfs_create_file("clear_stats", 0600, root, gt, &clear_stats_fops);

It seems Himal's comment on v2 regarding permission is not addressed in this
version.

Francois

>  	debugfs_create_file("force_reset", 0600, root, gt, &force_reset_fops);
>  	debugfs_create_file("force_reset_sync", 0600, root, gt, &force_reset_sync_fops);
>  
> diff --git a/drivers/gpu/drm/xe/xe_gt_stats.c b/drivers/gpu/drm/xe/xe_gt_stats.c
> index 30f942671c2b..7e12fc3759e2 100644
> --- a/drivers/gpu/drm/xe/xe_gt_stats.c
> +++ b/drivers/gpu/drm/xe/xe_gt_stats.c
> @@ -50,3 +50,17 @@ int xe_gt_stats_print_info(struct xe_gt *gt, struct drm_printer *p)
>  
>  	return 0;
>  }
> +
> +/**
> + * xe_gt_stats_clear - Clear the GT stats
> + * @gt: GT structure
> + *
> + * This clear (zeros) all the available GT stats.
> + */
> +void xe_gt_stats_clear(struct xe_gt *gt)
> +{
> +	enum xe_gt_stats_id id;
> +
> +	for (id = 0; id < __XE_GT_STATS_NUM_IDS; ++id)
> +		atomic64_set(&gt->stats.counters[id], 0);
> +}
> diff --git a/drivers/gpu/drm/xe/xe_gt_stats.h b/drivers/gpu/drm/xe/xe_gt_stats.h
> index 38325ef53617..e8aea32bc971 100644
> --- a/drivers/gpu/drm/xe/xe_gt_stats.h
> +++ b/drivers/gpu/drm/xe/xe_gt_stats.h
> @@ -13,6 +13,7 @@ struct drm_printer;
>  
>  #ifdef CONFIG_DEBUG_FS
>  int xe_gt_stats_print_info(struct xe_gt *gt, struct drm_printer *p);
> +void xe_gt_stats_clear(struct xe_gt *gt);
>  void xe_gt_stats_incr(struct xe_gt *gt, const enum xe_gt_stats_id id, int incr);
>  #else
>  static inline void
> -- 
> 2.34.1
> 


More information about the Intel-xe mailing list