[PATCH v3] drm/xe/svm: Add stats for SVM page faults

Rodrigo Vivi rodrigo.vivi at intel.com
Wed Mar 12 20:09:08 UTC 2025


On Wed, Mar 12, 2025 at 10:27:49AM +0100, Francois Dugast wrote:
> Add a new entry in stats to for svm page faults. If CONFIG_DEBUG_FS is
> enabled, the count can be viewed with per GT stat debugfs file.
> 
> This is similar to what is already in place for vma page faults.
> 
> Example output:
> 
>     cat /sys/kernel/debug/dri/0/gt0/stats
>     svm_pagefault_count: 6
>     tlb_inval_count: 78
>     vma_pagefault_count: 0
>     vma_pagefault_kb: 0
> 
> v2: Fix build with CONFIG_DRM_GPUSVM disabled
> 
> v3: Update argument in kernel doc
> 

Reviewed-by: Rodrigo Vivi <rodrigo.vivi at intel.com>

> Signed-off-by: Francois Dugast <francois.dugast at intel.com>
> ---
>  drivers/gpu/drm/xe/xe_gt_pagefault.c   | 2 +-
>  drivers/gpu/drm/xe/xe_gt_stats.c       | 1 +
>  drivers/gpu/drm/xe/xe_gt_stats_types.h | 1 +
>  drivers/gpu/drm/xe/xe_svm.c            | 8 ++++++--
>  drivers/gpu/drm/xe/xe_svm.h            | 7 ++++---
>  5 files changed, 13 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/gpu/drm/xe/xe_gt_pagefault.c b/drivers/gpu/drm/xe/xe_gt_pagefault.c
> index c5ad9a0a89c2..9fa11e837dd1 100644
> --- a/drivers/gpu/drm/xe/xe_gt_pagefault.c
> +++ b/drivers/gpu/drm/xe/xe_gt_pagefault.c
> @@ -240,7 +240,7 @@ static int handle_pagefault(struct xe_gt *gt, struct pagefault *pf)
>  	atomic = access_is_atomic(pf->access_type);
>  
>  	if (xe_vma_is_cpu_addr_mirror(vma))
> -		err = xe_svm_handle_pagefault(vm, vma, gt_to_tile(gt),
> +		err = xe_svm_handle_pagefault(vm, vma, gt,
>  					      pf->page_addr, atomic);
>  	else
>  		err = handle_vma_pagefault(gt, vma, atomic);
> diff --git a/drivers/gpu/drm/xe/xe_gt_stats.c b/drivers/gpu/drm/xe/xe_gt_stats.c
> index 6155ea354432..30f942671c2b 100644
> --- a/drivers/gpu/drm/xe/xe_gt_stats.c
> +++ b/drivers/gpu/drm/xe/xe_gt_stats.c
> @@ -27,6 +27,7 @@ void xe_gt_stats_incr(struct xe_gt *gt, const enum xe_gt_stats_id id, int incr)
>  }
>  
>  static const char *const stat_description[__XE_GT_STATS_NUM_IDS] = {
> +	"svm_pagefault_count",
>  	"tlb_inval_count",
>  	"vma_pagefault_count",
>  	"vma_pagefault_kb",
> diff --git a/drivers/gpu/drm/xe/xe_gt_stats_types.h b/drivers/gpu/drm/xe/xe_gt_stats_types.h
> index d556771f99d6..be3244d7133c 100644
> --- a/drivers/gpu/drm/xe/xe_gt_stats_types.h
> +++ b/drivers/gpu/drm/xe/xe_gt_stats_types.h
> @@ -7,6 +7,7 @@
>  #define _XE_GT_STATS_TYPES_H_
>  
>  enum xe_gt_stats_id {
> +	XE_GT_STATS_ID_SVM_PAGEFAULT_COUNT,
>  	XE_GT_STATS_ID_TLB_INVAL,
>  	XE_GT_STATS_ID_VMA_PAGEFAULT_COUNT,
>  	XE_GT_STATS_ID_VMA_PAGEFAULT_KB,
> diff --git a/drivers/gpu/drm/xe/xe_svm.c b/drivers/gpu/drm/xe/xe_svm.c
> index 516898e99b26..08617a62ab07 100644
> --- a/drivers/gpu/drm/xe/xe_svm.c
> +++ b/drivers/gpu/drm/xe/xe_svm.c
> @@ -4,6 +4,7 @@
>   */
>  
>  #include "xe_bo.h"
> +#include "xe_gt_stats.h"
>  #include "xe_gt_tlb_invalidation.h"
>  #include "xe_migrate.h"
>  #include "xe_module.h"
> @@ -713,7 +714,7 @@ static int xe_svm_alloc_vram(struct xe_vm *vm, struct xe_tile *tile,
>   * xe_svm_handle_pagefault() - SVM handle page fault
>   * @vm: The VM.
>   * @vma: The CPU address mirror VMA.
> - * @tile: The tile upon the fault occurred.
> + * @gt: The gt upon the fault occurred.
>   * @fault_addr: The GPU fault address.
>   * @atomic: The fault atomic access bit.
>   *
> @@ -723,7 +724,7 @@ static int xe_svm_alloc_vram(struct xe_vm *vm, struct xe_tile *tile,
>   * Return: 0 on success, negative error code on error.
>   */
>  int xe_svm_handle_pagefault(struct xe_vm *vm, struct xe_vma *vma,
> -			    struct xe_tile *tile, u64 fault_addr,
> +			    struct xe_gt *gt, u64 fault_addr,
>  			    bool atomic)
>  {
>  	struct drm_gpusvm_ctx ctx = {
> @@ -737,12 +738,15 @@ int xe_svm_handle_pagefault(struct xe_vm *vm, struct xe_vma *vma,
>  	struct drm_gpusvm_range *r;
>  	struct drm_exec exec;
>  	struct dma_fence *fence;
> +	struct xe_tile *tile = gt_to_tile(gt);
>  	ktime_t end = 0;
>  	int err;
>  
>  	lockdep_assert_held_write(&vm->lock);
>  	xe_assert(vm->xe, xe_vma_is_cpu_addr_mirror(vma));
>  
> +	xe_gt_stats_incr(gt, XE_GT_STATS_ID_SVM_PAGEFAULT_COUNT, 1);
> +
>  retry:
>  	/* Always process UNMAPs first so view SVM ranges is current */
>  	err = xe_svm_garbage_collector(vm);
> diff --git a/drivers/gpu/drm/xe/xe_svm.h b/drivers/gpu/drm/xe/xe_svm.h
> index e059590e5076..93442738666e 100644
> --- a/drivers/gpu/drm/xe/xe_svm.h
> +++ b/drivers/gpu/drm/xe/xe_svm.h
> @@ -12,10 +12,11 @@
>  #define XE_INTERCONNECT_VRAM DRM_INTERCONNECT_DRIVER
>  
>  struct xe_bo;
> -struct xe_vram_region;
> +struct xe_gt;
>  struct xe_tile;
>  struct xe_vm;
>  struct xe_vma;
> +struct xe_vram_region;
>  
>  /** struct xe_svm_range - SVM range */
>  struct xe_svm_range {
> @@ -64,7 +65,7 @@ void xe_svm_fini(struct xe_vm *vm);
>  void xe_svm_close(struct xe_vm *vm);
>  
>  int xe_svm_handle_pagefault(struct xe_vm *vm, struct xe_vma *vma,
> -			    struct xe_tile *tile, u64 fault_addr,
> +			    struct xe_gt *gt, u64 fault_addr,
>  			    bool atomic);
>  
>  bool xe_svm_has_mapping(struct xe_vm *vm, u64 start, u64 end);
> @@ -102,7 +103,7 @@ void xe_svm_close(struct xe_vm *vm)
>  
>  static inline
>  int xe_svm_handle_pagefault(struct xe_vm *vm, struct xe_vma *vma,
> -			    struct xe_tile *tile, u64 fault_addr,
> +			    struct xe_gt *gt, u64 fault_addr,
>  			    bool atomic)
>  {
>  	return 0;
> -- 
> 2.43.0
> 


More information about the Intel-xe mailing list