mirror of
https://github.com/torvalds/linux.git
synced 2026-11-07 06:17:02 +01:00
drm/xe: Bump prefetch BO LRU via GPUSVM devmem callback
Add xe_svm_devmem_lru_bump() and set it as drm_gpusvm_ctx.devmem_fn in the prefetch worker so each backing BO is moved to the LRU tail during get_pages. v2: - Guard xe_svm_devmem_lru_bump() against foreign device-memory allocations before casting to xe_bo: return early when devmem_allocation->ops != &dpagemap_devmem_ops. A shared device_private_page_owner can hand us another driver's allocation. (Matthew Brost / Sashiko AI review) - Add stub for function (CI) v3: - Guard xe_svm_devmem_lru_bump() body with CONFIG_DRM_XE_PAGEMAP; it references dpagemap_devmem_ops and to_xe_bo(), which only exist when PAGEMAP is enabled. Fixes the build with GPUSVM=y, PAGEMAP=n. (Sashiko AI review) v4: - Fix xe_svm_devmem_lru_bump() kernel-doc to explain the locking (Matt) Suggested-by: Matthew Brost <matthew.brost@intel.com> Reviewed-by: Matthew Brost <matthew.brost@intel.com> Link: https://patch.msgid.link/20261001033602.3166274-9-himal.prasad.ghimiray@intel.com Signed-off-by: Himal Prasad Ghimiray <himal.prasad.ghimiray@intel.com> Signed-off-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
This commit is contained in:
parent
927a6ab619
commit
508444b9f6
|
|
@ -9,6 +9,7 @@
|
|||
#include <drm/drm_managed.h>
|
||||
#include <drm/drm_pagemap.h>
|
||||
#include <drm/drm_pagemap_util.h>
|
||||
#include <drm/ttm/ttm_bo.h>
|
||||
|
||||
#include "xe_bo.h"
|
||||
#include "xe_exec_queue_types.h"
|
||||
|
|
@ -1625,6 +1626,39 @@ int xe_svm_range_get_pages(struct xe_vm *vm, struct xe_svm_range *range,
|
|||
return err;
|
||||
}
|
||||
|
||||
/**
|
||||
* xe_svm_devmem_lru_bump() - Move a range's backing BO to the TTM LRU tail
|
||||
* @devmem_allocation: The device-memory allocation backing the range's pages
|
||||
*
|
||||
* Intended as a &drm_gpusvm_ctx.devmem_fn, so drm_gpusvm_get_pages() calls it
|
||||
* under the GPUSVM notifier lock. That lock sits in the reclaim path, so
|
||||
* dma-resv cannot be acquired blocking beneath it; dma-resv is also the outer
|
||||
* lock of the notifier when memory is allocated and migrated, so a blocking
|
||||
* acquire here would invert that order. Hence the trylock. The BO is private
|
||||
* (dedicated dma-resv), so the trylock succeeds unless the BO is being moved
|
||||
* elsewhere (e.g. eviction); a contended BO is simply skipped.
|
||||
*
|
||||
* A shared device_private_page_owner can hand us allocations backed by a
|
||||
* foreign driver; skip anything that is not an Xe BO before casting.
|
||||
*/
|
||||
void xe_svm_devmem_lru_bump(struct drm_pagemap_devmem *devmem_allocation)
|
||||
{
|
||||
#if IS_ENABLED(CONFIG_DRM_XE_PAGEMAP)
|
||||
struct xe_bo *bo;
|
||||
|
||||
if (devmem_allocation->ops != &dpagemap_devmem_ops)
|
||||
return;
|
||||
|
||||
bo = to_xe_bo(devmem_allocation);
|
||||
|
||||
if (!dma_resv_trylock(bo->ttm.base.resv))
|
||||
return;
|
||||
|
||||
ttm_bo_move_to_lru_tail_unlocked(&bo->ttm);
|
||||
dma_resv_unlock(bo->ttm.base.resv);
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* xe_svm_ranges_zap_ptes_in_range - clear ptes of svm ranges in input range
|
||||
* @vm: Pointer to the xe_vm structure
|
||||
|
|
|
|||
|
|
@ -128,6 +128,8 @@ struct xe_svm_range *xe_svm_range_find_or_insert(struct xe_vm *vm, u64 addr,
|
|||
int xe_svm_range_get_pages(struct xe_vm *vm, struct xe_svm_range *range,
|
||||
struct drm_gpusvm_ctx *ctx);
|
||||
|
||||
void xe_svm_devmem_lru_bump(struct drm_pagemap_devmem *devmem_allocation);
|
||||
|
||||
bool xe_svm_range_needs_migrate_to_vram(struct xe_svm_range *range, struct xe_vma *vma,
|
||||
const struct drm_pagemap *dpagemap);
|
||||
|
||||
|
|
@ -356,6 +358,11 @@ int xe_svm_range_get_pages(struct xe_vm *vm, struct xe_svm_range *range,
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
static inline
|
||||
void xe_svm_devmem_lru_bump(struct drm_pagemap_devmem *devmem_allocation)
|
||||
{
|
||||
}
|
||||
|
||||
static inline struct xe_svm_range *to_xe_range(struct drm_gpusvm_range *r)
|
||||
{
|
||||
return NULL;
|
||||
|
|
|
|||
|
|
@ -3246,6 +3246,7 @@ static int prefetch_ranges(struct xe_vm *vm, struct xe_vma_ops *vops,
|
|||
ctx.devmem_possible = devmem_possible;
|
||||
ctx.check_pages_threshold = devmem_possible ? SZ_64K : 0;
|
||||
ctx.device_private_page_owner = xe_svm_private_page_owner(vm, !dpagemap);
|
||||
ctx.devmem_fn = xe_svm_devmem_lru_bump;
|
||||
|
||||
skip_threads = op->prefetch_range.ranges_count == 1 ||
|
||||
(!dpagemap && !(vops->flags &
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user