[PATCH v2 2/2] drm/xe: Opportunistically skip TLB invalidaion on unbind

Matthew Brost matthew.brost at intel.com
Sun Jun 15 03:56:45 UTC 2025


On Fri, Jun 13, 2025 at 02:02:42PM -0700, Matthew Brost wrote:
> If a range or VMA is invalidated and scratch page is disabled, there
> is no reason to issue a TLB invalidation on unbind, skip TLB
> innvalidation is this condition is true. This is an opportunistic check
> as it is done without the notifier lock, thus it possible for the range
> or VMA to be invalidated after this check is performed.
> 
> This should improve performance of the SVM garbage collector, for
> example, xe_exec_system_allocator --r many-stride-new-prefetch, went
> ~20s to ~9.5s on a BMG.
> 
> v2:
>  - Use helper for valid check (Thomas)
> 

This patch doesn't quite work either - I'm a roll here of posting
things that don't work [1]...

If we are removing PTEs are higher level than the size of the VMA /
range, those will not have been invalidated and could still be in GPU
TLBs. We need a helper to check the walk results against the size of the
VMA / range too.

Matt

[1] https://patchwork.freedesktop.org/patch/658370/?series=150188&rev=1#comment_1206030

> Signed-off-by: Matthew Brost <matthew.brost at intel.com>
> Reviewed-by: Himal Prasad Ghimiray <himal.prasad.ghimiray at intel.com>>
> ---
>  drivers/gpu/drm/xe/xe_pt.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpu/drm/xe/xe_pt.c b/drivers/gpu/drm/xe/xe_pt.c
> index 59496c1a1e77..39947fd5c3a2 100644
> --- a/drivers/gpu/drm/xe/xe_pt.c
> +++ b/drivers/gpu/drm/xe/xe_pt.c
> @@ -1988,7 +1988,9 @@ static int unbind_op_prepare(struct xe_tile *tile,
>  					 xe_vma_end(vma));
>  	++pt_update_ops->current_op;
>  	pt_update_ops->needs_userptr_lock |= xe_vma_is_userptr(vma);
> -	pt_update_ops->needs_invalidation = true;
> +	pt_update_ops->needs_invalidation |= xe_vm_has_scratch(xe_vma_vm(vma)) ||
> +		xe_vm_has_valid_gpu_pages(tile, vma->tile_present,
> +					  vma->tile_invalidated);
>  
>  	xe_pt_commit_prepare_unbind(vma, pt_op->entries, pt_op->num_entries);
>  
> @@ -2023,7 +2025,9 @@ static int unbind_range_prepare(struct xe_vm *vm,
>  					 range->base.itree.last + 1);
>  	++pt_update_ops->current_op;
>  	pt_update_ops->needs_svm_lock = true;
> -	pt_update_ops->needs_invalidation = true;
> +	pt_update_ops->needs_invalidation |= xe_vm_has_scratch(vm) ||
> +		xe_vm_has_valid_gpu_pages(tile, range->tile_present,
> +					  range->tile_invalidated);
>  
>  	xe_pt_commit_prepare_unbind(XE_INVALID_VMA, pt_op->entries,
>  				    pt_op->num_entries);
> -- 
> 2.34.1
> 


More information about the Intel-xe mailing list