Skip to content

Commit

Permalink
drm/xe/svm: Add stats for SVM page faults
Browse files Browse the repository at this point in the history
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@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20250312092749.164232-1-francois.dugast@intel.com
Signed-off-by: Francois Dugast <francois.dugast@intel.com>
  • Loading branch information
Francois Dugast committed Mar 13, 2025
1 parent 459664c commit 80bcbdf
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion drivers/gpu/drm/xe/xe_gt_pagefault.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions drivers/gpu/drm/xe/xe_gt_stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions drivers/gpu/drm/xe/xe_gt_stats_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 6 additions & 2 deletions drivers/gpu/drm/xe/xe_svm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.
*
Expand All @@ -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 = {
Expand All @@ -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);
Expand Down
7 changes: 4 additions & 3 deletions drivers/gpu/drm/xe/xe_svm.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 80bcbdf

Please sign in to comment.