drm/amdgpu: Add helper to wait for a reservation using a sync object
Subsystems (3)
PATCH 1/4 drm/amdgpu: Add helper to wait for a reservation using a sync object
Creates a temporary sync object to wait for the reservation. This generalizes amdgpu_vm_wait_pd.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c | 25 +++++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_sync.h | 3 +++ drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 31 ++++--------------------------- 3 files changed, 32 insertions(+), 27 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c +25 -0
@@ -377,6 +377,31 @@ int amdgpu_sync_wait(struct amdgpu_sync *sync, bool intr) }/** +* amdgpu_sync_wait_resv - Wait for reservation fences +* +* @vm: related vm +* @owner: fence owner +* @intr: Whether the wait is interruptible +* +* Returns: +* 0 on success, errno otherwise. +*/ +int amdgpu_sync_wait_resv (struct amdgpu_device *adev, +struct reservation_object *resv, +void *owner,bool intr) +{ +struct amdgpu_sync sync; +int r; + +amdgpu_sync_create (&sync); +amdgpu_sync_resv (adev, &sync, resv, owner, false); + r =amdgpu_sync_wait (&sync, intr); +amdgpu_sync_free (&sync); + +return r; +} + +/** * amdgpu_sync_free - free the sync object * * @sync: sync object to use
drivers/gpu/drm/amd/amdgpu/amdgpu_sync.h +3 -0
@@ -52,6 +52,9 @@ struct dma_fence *amdgpu_sync_peek_fence(struct amdgpu_sync *sync,struct dma_fence *amdgpu_sync_get_fence (struct amdgpu_sync *sync,bool *explicit);int amdgpu_sync_clone (struct amdgpu_sync *source,struct amdgpu_sync *clone);int amdgpu_sync_wait (struct amdgpu_sync *sync,bool intr); +int amdgpu_sync_wait_resv (struct amdgpu_device *adev, +struct reservation_object *resv, +void *owner,bool intr);void amdgpu_sync_free (struct amdgpu_sync *sync);int amdgpu_sync_init (void );void amdgpu_sync_fini (void );
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +4 -27
@@ -1330,31 +1330,6 @@ static void amdgpu_vm_cpu_set_ptes(struct amdgpu_pte_update_params *params, } } - -/** -* amdgpu_vm_wait_pd - Wait for PT BOs to be free. -* -* @adev: amdgpu_device pointer -* @vm: related vm -* @owner: fence owner -* -* Returns: -* 0 on success, errno otherwise. -*/ -static int amdgpu_vm_wait_pd (struct amdgpu_device *adev,struct amdgpu_vm *vm, -void *owner) -{ -struct amdgpu_sync sync; -int r; - -amdgpu_sync_create (&sync); -amdgpu_sync_resv (adev, &sync, vm->root.base.bo->tbo.resv, owner, false); - r =amdgpu_sync_wait (&sync, true); -amdgpu_sync_free (&sync); - -return r; -} -/** * amdgpu_vm_update_func - helper to call update function *
@@ -1449,7 +1424,8 @@ int amdgpu_vm_update_directories(struct amdgpu_device *adev, params.adev = adev;if (vm->use_cpu_for_update) { - r =amdgpu_vm_wait_pd (adev, vm,AMDGPU_FENCE_OWNER_VM ); + r =amdgpu_sync_wait_resv (adev, vm->root.base.bo->tbo.resv, +AMDGPU_FENCE_OWNER_VM , true);if (unlikely (r))return r;
@@ -1782,7 +1758,8 @@ static int amdgpu_vm_bo_update_mapping(struct amdgpu_device *adev,/* Wait for PT BOs to be idle. PTs share the same resv. object * as the root PD BO */ - r =amdgpu_vm_wait_pd (adev, vm, owner); + r =amdgpu_sync_wait_resv (adev, vm->root.base.bo->tbo.resv, + owner, true);if (unlikely (r))return r;
Signature · 6 lines
2.7.4 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 1549569222-13251-1-git-send-email-Felix.Kuehling-5C7GfCeVMHo@public.gmane.org
PATCH 2/4 drm/amdgpu: Replace ttm_bo_wait with amdgpu_sync_wait_resv
The fence_owner logic in amdgpu_sync_wait will allow waiting without having to temporarily remove eviction fences.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +4 -2
@@ -355,7 +355,8 @@ static int amdgpu_amdkfd_bo_validate(struct amdgpu_bo *bo, uint32_t domain,if (ret) goto validate_fail; -ttm_bo_wait (&bo->tbo, false, false); +amdgpu_sync_wait_resv (NULL , bo->tbo.resv, +AMDGPU_FENCE_OWNER_KFD , false);amdgpu_amdkfd_add_eviction_fence (bo, ef_list, ef_count); }
@@ -1002,7 +1003,8 @@ static int init_kfd_vm(struct amdgpu_vm *vm, void **process_info,pr_err ("validate_pt_pd_bos() failed\n" ); goto validate_pd_fail; } - ret =ttm_bo_wait (&vm->root.base.bo->tbo, false, false); +amdgpu_sync_wait_resv (NULL , vm->root.base.bo->tbo.resv, +AMDGPU_FENCE_OWNER_KFD , false);if (ret) goto wait_pd_fail; amdgpu_bo_fence(vm->root.base.bo,
Signature · 6 lines
2.7.4 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 3/4 drm/amdgpu: Avoid setting off KFD eviction fences in amdgpu_vm
In reply to a message not in the archiveUse FENCE_OWNER_KFD to synchronize PT/PD initialization and clearing of page table entries. This avoids triggering KFD eviction fences on the PD reservation objects of compute VMs.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +3 -3
@@ -826,7 +826,7 @@ static int amdgpu_vm_clear_bo(struct amdgpu_device *adev,WARN_ON (job->ibs[0 ].length_dw >64 ); r =amdgpu_sync_resv (adev, &job->sync, bo->tbo.resv, -AMDGPU_FENCE_OWNER_UNDEFINED , false); +AMDGPU_FENCE_OWNER_KFD , false);if (r) goto error_free;
@@ -1746,9 +1746,9 @@ static int amdgpu_vm_bo_update_mapping(struct amdgpu_device *adev, params.adev = adev; params.vm = vm; -/* sync to everything on unmapping */ +/* sync to everything except eviction fences on unmapping */ if (!(flags &AMDGPU_PTE_VALID )) - owner =AMDGPU_FENCE_OWNER_UNDEFINED ; + owner =AMDGPU_FENCE_OWNER_KFD ;if (vm->use_cpu_for_update) {/* params.src is used as flag to indicate system Memory */
Signature · 6 lines
2.7.4 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 4/4 drm/amdgpu: Simplify eviction fence handling
In reply to a message not in the archiveTemporarily removing eviction fences to avoid triggering them by accident is no longer necessary due to the fence_owner logic in amdgpu_sync_resv.
As a result the ef_list usage of amdgpu_amdkfd_remove_eviction_fence and amdgpu_amdkfd_add_eviction_fence are no longer needed.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 134 ++--------------------- 1 file changed, 11 insertions(+), 123 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +11 -123
@@ -204,38 +204,25 @@ void amdgpu_amdkfd_unreserve_memory_limit(struct amdgpu_bo *bo) } -/* amdgpu_amdkfd_remove_eviction_fence - Removes eviction fence(s) from BO's +/* amdgpu_amdkfd_remove_eviction_fence - Removes eviction fence from BO's * reservation object. * * @bo: [IN] Remove eviction fence(s) from this BO -* @ef: [IN] If ef is specified, then this eviction fence is removed if it +* @ef: [IN] This eviction fence is removed if it * is present in the shared list. -* @ef_list: [OUT] Returns list of eviction fences. These fences are removed -* from BO's reservation object shared list. -* @ef_count: [OUT] Number of fences in ef_list. * -* NOTE: If called with ef_list, then amdgpu_amdkfd_add_eviction_fence must be -* called to restore the eviction fences and to avoid memory leak. This is -* useful for shared BOs. * NOTE: Must be called with BO reserved i.e. bo->tbo.resv->lock held. */ static int amdgpu_amdkfd_remove_eviction_fence (struct amdgpu_bo *bo, -struct amdgpu_amdkfd_fence *ef, -struct amdgpu_amdkfd_fence ***ef_list, -unsigned int *ef_count) +struct amdgpu_amdkfd_fence *ef) {struct reservation_object *resv = bo->tbo.resv;struct reservation_object_list *old, *new;unsigned int i, j, k; -if (!ef && !ef_list) +if (!ef)return -EINVAL ; -if (ef_list) { - *ef_list =NULL ; - *ef_count =0 ; - } - old =reservation_object_get_list (resv);if (!old)return 0 ;
@@ -254,8 +241,7 @@ static int amdgpu_amdkfd_remove_eviction_fence(struct amdgpu_bo *bo, f =rcu_dereference_protected (old->shared[i],reservation_object_held (resv)); -if ((ef && f->context == ef->base.context) || - (!ef &&to_amdgpu_amdkfd_fence (f))) +if (f->context == ef->base.context)RCU_INIT_POINTER (new->shared[--j], f);else RCU_INIT_POINTER (new->shared[k++], f);
@@ -263,21 +249,6 @@ static int amdgpu_amdkfd_remove_eviction_fence(struct amdgpu_bo *bo, new->shared_max = old->shared_max; new->shared_count = k; -if (!ef) { -unsigned int count = old->shared_count - j; - -/* Alloc memory for count number of eviction fence pointers. -* Fill the ef_list array and ef_count -*/ - *ef_list =kcalloc (count,sizeof (**ef_list),GFP_KERNEL ); - *ef_count = count; - -if (!*ef_list) { -kfree (new); -return -ENOMEM ; - } - } -/* Install the new fence list, seqcount provides the barriers */ preempt_disable ();write_seqcount_begin (&resv->seq);
@@ -291,46 +262,13 @@ static int amdgpu_amdkfd_remove_eviction_fence(struct amdgpu_bo *bo, f =rcu_dereference_protected (new->shared[i],reservation_object_held (resv)); -if (!ef) - (*ef_list)[k++] =to_amdgpu_amdkfd_fence (f); -else -dma_fence_put (f); +dma_fence_put (f); }kfree_rcu (old, rcu);return 0 ; } -/* amdgpu_amdkfd_add_eviction_fence - Adds eviction fence(s) back into BO's -* reservation object. -* -* @bo: [IN] Add eviction fences to this BO -* @ef_list: [IN] List of eviction fences to be added -* @ef_count: [IN] Number of fences in ef_list. -* -* NOTE: Must call amdgpu_amdkfd_remove_eviction_fence before calling this -* function. -*/ -static void amdgpu_amdkfd_add_eviction_fence (struct amdgpu_bo *bo, -struct amdgpu_amdkfd_fence **ef_list, -unsigned int ef_count) -{ -int i; - -if (!ef_list || !ef_count) -return ; - -for (i =0 ; i < ef_count; i++) { -amdgpu_bo_fence (bo, &ef_list[i]->base, true); -/* Re-adding the fence takes an additional reference. Drop that -* reference. -*/ -dma_fence_put (&ef_list[i]->base); - } - -kfree (ef_list); -} -static int amdgpu_amdkfd_bo_validate (struct amdgpu_bo *bo,uint32_t domain,bool wait) {
@@ -346,19 +284,9 @@ static int amdgpu_amdkfd_bo_validate(struct amdgpu_bo *bo, uint32_t domain, ret =ttm_bo_validate (&bo->tbo, &bo->placement, &ctx);if (ret) goto validate_fail; -if (wait) { -struct amdgpu_amdkfd_fence **ef_list; -unsigned int ef_count; - - ret =amdgpu_amdkfd_remove_eviction_fence (bo,NULL , &ef_list, - &ef_count); -if (ret) - goto validate_fail; - +if (wait)amdgpu_sync_wait_resv (NULL , bo->tbo.resv,AMDGPU_FENCE_OWNER_KFD , false); -amdgpu_amdkfd_add_eviction_fence (bo, ef_list, ef_count); - } validate_fail:return ret;
@@ -445,7 +373,6 @@ static int add_bo_to_vm(struct amdgpu_device *adev, struct kgd_mem *mem, {int ret;struct kfd_bo_va_list *bo_va_entry; -struct amdgpu_bo *pd = vm->root.base.bo;struct amdgpu_bo *bo = mem->bo;uint64_t va = mem->va;struct list_head *list_bo_va = &mem->bo_va_list;
@@ -485,14 +412,8 @@ static int add_bo_to_vm(struct amdgpu_device *adev, struct kgd_mem *mem, *p_bo_va_entry = bo_va_entry;/* Allocate new page tables if needed and validate -* them. Clearing of new page tables and validate need to wait -* on move fences. We don't want that to trigger the eviction -* fence, so remove it temporarily. +* them. */ -amdgpu_amdkfd_remove_eviction_fence (pd, - vm->process_info->eviction_fence, -NULL ,NULL ); - ret =amdgpu_vm_alloc_pts (adev, vm, va,amdgpu_bo_size (bo));if (ret) {pr_err ("Failed to allocate pts, err=%d\n" , ret);
@@ -505,13 +426,9 @@ static int add_bo_to_vm(struct amdgpu_device *adev, struct kgd_mem *mem, goto err_alloc_pts; } -/* Add the eviction fence back */ -amdgpu_bo_fence (pd, &vm->process_info->eviction_fence->base, true); -return 0 ; err_alloc_pts: -amdgpu_bo_fence (pd, &vm->process_info->eviction_fence->base, true);amdgpu_vm_bo_rmv (adev, bo_va_entry->bo_va);list_del (&bo_va_entry->bo_list); err_vmadd:
@@ -810,24 +727,11 @@ static int unmap_bo_from_gpuvm(struct amdgpu_device *adev, {struct amdgpu_bo_va *bo_va = entry->bo_va;struct amdgpu_vm *vm = bo_va->base.vm; -struct amdgpu_bo *pd = vm->root.base.bo; -/* Remove eviction fence from PD (and thereby from PTs too as -* they share the resv. object). Otherwise during PT update -* job (see amdgpu_vm_bo_update_mapping), eviction fence would -* get added to job->sync object and job execution would -* trigger the eviction fence. -*/ -amdgpu_amdkfd_remove_eviction_fence (pd, - vm->process_info->eviction_fence, -NULL ,NULL );amdgpu_vm_bo_unmap (adev, bo_va, entry->va);amdgpu_vm_clear_freed (adev, vm, &bo_va->last_pt_update); -/* Add the eviction fence back */ -amdgpu_bo_fence (pd, &vm->process_info->eviction_fence->base, true); -amdgpu_sync_fence (NULL , sync, bo_va->last_pt_update, false);return 0 ;
@@ -1391,8 +1295,7 @@ int amdgpu_amdkfd_gpuvm_free_memory_of_gpu(* attached */ amdgpu_amdkfd_remove_eviction_fence (mem->bo, - process_info->eviction_fence, -NULL ,NULL ); + process_info->eviction_fence);pr_debug ("Release VA 0x%llx - 0x%llx\n" , mem->va, mem->va + bo_size * (1 + mem->aql_queue));
@@ -1619,8 +1522,7 @@ int amdgpu_amdkfd_gpuvm_unmap_memory_from_gpu(if (mem->mapped_to_gpu_memory ==0 && !amdgpu_ttm_tt_get_usermm (mem->bo->tbo.ttm) && !mem->bo->pin_count)amdgpu_amdkfd_remove_eviction_fence (mem->bo, - process_info->eviction_fence, -NULL ,NULL ); + process_info->eviction_fence); unreserve_out:unreserve_bo_and_vms (&ctx, false, false);
@@ -1681,7 +1583,7 @@ int amdgpu_amdkfd_gpuvm_map_gtt_bo_to_kernel(struct kgd_dev *kgd, }amdgpu_amdkfd_remove_eviction_fence ( - bo, mem->process_info->eviction_fence,NULL ,NULL ); + bo, mem->process_info->eviction_fence);list_del_init (&mem->validate_list.head);if (size)
@@ -1947,16 +1849,6 @@ static int validate_invalid_user_pages(struct amdkfd_process_info *process_info)amdgpu_sync_create (&sync); -/* Avoid triggering eviction fences when unmapping invalid -* userptr BOs (waits for all fences, doesn't use -* FENCE_OWNER_VM) -*/ -list_for_each_entry (peer_vm, &process_info->vm_list_head, - vm_list_node) -amdgpu_amdkfd_remove_eviction_fence (peer_vm->root.base.bo, - process_info->eviction_fence, -NULL ,NULL ); - ret =process_validate_vms (process_info);if (ret) goto unreserve_out;
@@ -2017,10 +1909,6 @@ static int validate_invalid_user_pages(struct amdkfd_process_info *process_info) ret =process_update_pds (process_info, &sync); unreserve_out: -list_for_each_entry (peer_vm, &process_info->vm_list_head, - vm_list_node) -amdgpu_bo_fence (peer_vm->root.base.bo, - &process_info->eviction_fence->base, true);ttm_eu_backoff_reservation (&ticket, &resv_list);amdgpu_sync_wait (&sync, false);amdgpu_sync_free (&sync);
Signature · 6 lines
2.7.4 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Am 07.02.19 um 20:53 schrieb Kuehling, Felix:
Quoted 4 lines
Creates a temporary sync object to wait for the reservation. This generalizes
amdgpu_vm_wait_pd.Signed-off-by Felix Kuehling <[email protected]>
For this one it might be better to name this function amdgpu_bo_sync_wait and add it to amdgpu_object.c.
Just because the object we work with is the BO/resv and not the sync container.
Apart from that the series looks good to me and patches #2 and #3 are
Regards,
Christian.
Quoted 103 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c | 25 +++++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_sync.h | 3 +++ drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 31 ++++--------------------------- 3 files changed, 32 insertions(+), 27 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c +25
-0@@ -377,6 +377,31 @@ int amdgpu_sync_wait(struct amdgpu_sync *sync, bool intr) }/** +* amdgpu_sync_wait_resv - Wait for reservation fences +* +* @vm: related vm +* @owner: fence owner +* @intr: Whether the wait is interruptible +* +* Returns: +* 0 on success, errno otherwise. +*/ +int amdgpu_sync_wait_resv (struct amdgpu_device *adev, +struct reservation_object *resv, +void *owner,bool intr) +{ +struct amdgpu_sync sync; +int r; + +amdgpu_sync_create (&sync); +amdgpu_sync_resv (adev, &sync, resv, owner, false); + r =amdgpu_sync_wait (&sync, intr); +amdgpu_sync_free (&sync); + +return r; +} + +/** * amdgpu_sync_free - free the sync object * * @sync: sync object to use drivers/gpu/drm/amd/amdgpu/amdgpu_sync.h +3
-0@@ -52,6 +52,9 @@ struct dma_fence *amdgpu_sync_peek_fence(struct amdgpu_sync *sync,struct dma_fence *amdgpu_sync_get_fence (struct amdgpu_sync *sync,bool *explicit);int amdgpu_sync_clone (struct amdgpu_sync *source,struct amdgpu_sync *clone);int amdgpu_sync_wait (struct amdgpu_sync *sync,bool intr); +int amdgpu_sync_wait_resv (struct amdgpu_device *adev, +struct reservation_object *resv, +void *owner,bool intr);void amdgpu_sync_free (struct amdgpu_sync *sync);int amdgpu_sync_init (void );void amdgpu_sync_fini (void );drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2
-26@@ -1330,31 +1330,6 @@ static void amdgpu_vm_cpu_set_ptes(struct amdgpu_pte_update_params *params, } } - -/** -* amdgpu_vm_wait_pd - Wait for PT BOs to be free. -* -* @adev: amdgpu_device pointer -* @vm: related vm -* @owner: fence owner -* -* Returns: -* 0 on success, errno otherwise. -*/ -static int amdgpu_vm_wait_pd (struct amdgpu_device *adev,struct amdgpu_vm *vm, -void *owner) -{ -struct amdgpu_sync sync; -int r; - -amdgpu_sync_create (&sync); -amdgpu_sync_resv (adev, &sync, vm->root.base.bo->tbo.resv, owner, false); - r =amdgpu_sync_wait (&sync, true); -amdgpu_sync_free (&sync); - -return r; -} -/** * amdgpu_vm_update_func - helper to call update function * @@ -1449,7 +1424,8 @@ int amdgpu_vm_update_directories(struct amdgpu_device *adev, params.adev = adev;if (vm->use_cpu_for_update) { - r =amdgpu_vm_wait_pd (adev, vm,AMDGPU_FENCE_OWNER_VM ); + r =amdgpu_sync_wait_resv (adev, vm->root.base.bo->tbo.resv, +AMDGPU_FENCE_OWNER_VM , true);if (unlikely (r))return r;
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c static int amdgpu_vm_bo_update_mapping(struct amdgpu_device *adev, · line 1765
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2
-1@@ -1782,7 +1758,8 @@ static int amdgpu_vm_bo_update_mapping(struct amdgpu_device *adev,/* Wait for PT BOs to be idle. PTs share the same resv. object * as the root PD BO */ - r =amdgpu_vm_wait_pd (adev, vm, owner); + r =amdgpu_sync_wait_resv (adev, vm->root.base.bo->tbo.resv, + owner, true);if (unlikely (r))return r;
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx