drm/amdgpu: fix VM flush for CPU based updates
Subsystems (2)
PATCH 1/7 drm/amdgpu: fix VM flush for CPU based updates
From: Christian König <[email protected]>
We don't have any update fence in that case, so the need for flushing isn't detected atomatically.
--- 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
@@ -421,7 +421,7 @@ static int amdgpu_vm_grab_reserved_vmid_locked(struct amdgpu_vm *vm,struct dma_fence *updates = sync->last_vm_update;int r =0 ;struct dma_fence *flushed, *tmp; -bool needs_flush = false; +bool needs_flush = vm->use_cpu_for_update; flushed = id->flushed_updates; if ((amdgpu_vm_had_gpu_reset(adev, id)) ||
@@ -542,11 +542,11 @@ int amdgpu_vm_grab_id(struct amdgpu_vm *vm, struct amdgpu_ring *ring, }kfree (fences); - job->vm_needs_flush = false; + job->vm_needs_flush = vm->use_cpu_for_update;/* Check if we can use a VMID already assigned to this VM */ list_for_each_entry_reverse (id, &id_mgr->ids_lru, list) {struct dma_fence *flushed; -bool needs_flush = false; +bool needs_flush = vm->use_cpu_for_update;/* Check all the prerequisites to using this VMID */ if (amdgpu_vm_had_gpu_reset (adev, id))
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): 1499848308-1441-1-git-send-email-deathsimple-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org
PATCH 2/7 drm/amdgpu: fix amdgpu_vm_bo_wait
From: Christian König <[email protected]>
We need to wait with the correct owner on unmap operations or otherwise can run into VM faults.
Also always wait for the page directory since this is where the reservation object comes from. So rename the function to amdgpu_vm_wait_pd instead as well.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +9 -8
@@ -995,13 +995,14 @@ static void amdgpu_vm_cpu_set_ptes(struct amdgpu_pte_update_params *params,amdgpu_gart_flush_gpu_tlb (params->adev,0 ); } -static int amdgpu_vm_bo_wait (struct amdgpu_device *adev,struct amdgpu_bo *bo) +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, bo->tbo.resv,AMDGPU_FENCE_OWNER_VM ); +amdgpu_sync_resv (adev, &sync, vm->root.bo->tbo.resv, owner); r =amdgpu_sync_wait (&sync, true);amdgpu_sync_free (&sync);
@@ -1047,7 +1048,7 @@ static int amdgpu_vm_update_level(struct amdgpu_device *adev, r =amdgpu_bo_kmap (parent->bo, (void **)&pd_addr);if (r)return r; - r =amdgpu_vm_bo_wait (adev, parent->bo); + r =amdgpu_vm_wait_pd (adev, vm,AMDGPU_FENCE_OWNER_VM );if (unlikely (r)) {amdgpu_bo_kunmap (parent->bo);return r;
@@ -1445,6 +1446,10 @@ static int amdgpu_vm_bo_update_mapping(struct amdgpu_device *adev, params.vm = vm; params.src = src; +/* sync to everything on unmapping */ +if (!(flags &AMDGPU_PTE_VALID )) + owner =AMDGPU_FENCE_OWNER_UNDEFINED ; +if (vm->use_cpu_for_update) {/* params.src is used as flag to indicate system Memory */ if (pages_addr)
@@ -1453,7 +1458,7 @@ static int amdgpu_vm_bo_update_mapping(struct amdgpu_device *adev,/* Wait for PT BOs to be free. PTs share the same resv. object * as the root PD BO */ - r =amdgpu_vm_bo_wait (adev, vm->root.bo); + r =amdgpu_vm_wait_pd (adev, vm, owner);if (unlikely (r))return r;
@@ -1465,10 +1470,6 @@ static int amdgpu_vm_bo_update_mapping(struct amdgpu_device *adev, ring = container_of(vm->entity.sched, struct amdgpu_ring, sched); -/* sync to everything on unmapping */ -if (!(flags &AMDGPU_PTE_VALID )) - owner =AMDGPU_FENCE_OWNER_UNDEFINED ; - nptes = last - start +1 ;/*
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): 1499848308-1441-2-git-send-email-deathsimple-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org
Felix Kuehling
Acked-byRe: [PATCH 2/7] drm/amdgpu: fix amdgpu_vm_bo_wait
Quoted 64 lines · Christian König
From: Christian König <[email protected]>
We need to wait with the correct owner on unmap operations or otherwise can run into VM faults.
Also always wait for the page directory since this is where the reservation object comes from. So rename the function to
amdgpu_vm_wait_pdinstead as well.Signed-off-by Christian König <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +9
-4@@ -995,13 +995,14 @@ static void amdgpu_vm_cpu_set_ptes(struct amdgpu_pte_update_params *params,amdgpu_gart_flush_gpu_tlb (params->adev,0 ); } -static int amdgpu_vm_bo_wait (struct amdgpu_device *adev,struct amdgpu_bo *bo) +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, bo->tbo.resv,AMDGPU_FENCE_OWNER_VM ); +amdgpu_sync_resv (adev, &sync, vm->root.bo->tbo.resv, owner); r =amdgpu_sync_wait (&sync, true);amdgpu_sync_free (&sync);@@ -1047,7 +1048,7 @@ static int amdgpu_vm_update_level(struct amdgpu_device *adev, r =amdgpu_bo_kmap (parent->bo, (void **)&pd_addr);if (r)return r; - r =amdgpu_vm_bo_wait (adev, parent->bo); + r =amdgpu_vm_wait_pd (adev, vm,AMDGPU_FENCE_OWNER_VM );if (unlikely (r)) {amdgpu_bo_kunmap (parent->bo);return r;@@ -1445,6 +1446,10 @@ static int amdgpu_vm_bo_update_mapping(struct amdgpu_device *adev, params.vm = vm; params.src = src; +/* sync to everything on unmapping */ +if (!(flags &AMDGPU_PTE_VALID )) + owner =AMDGPU_FENCE_OWNER_UNDEFINED ; +if (vm->use_cpu_for_update) {/* params.src is used as flag to indicate system Memory */ if (pages_addr)@@ -1453,7 +1458,7 @@ static int amdgpu_vm_bo_update_mapping(struct amdgpu_device *adev,/* Wait for PT BOs to be free. PTs share the same resv. object * as the root PD BO */ - r =amdgpu_vm_bo_wait (adev, vm->root.bo); + r =amdgpu_vm_wait_pd (adev, vm, owner);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 1475
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0
-4@@ -1465,10 +1470,6 @@ static int amdgpu_vm_bo_update_mapping(struct amdgpu_device *adev, ring = container_of(vm->entity.sched, struct amdgpu_ring, sched); -/* sync to everything on unmapping */ -if (!(flags &AMDGPU_PTE_VALID )) - owner =AMDGPU_FENCE_OWNER_UNDEFINED ; - nptes = last - start +1 ;/*
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 3/7 drm/amdgpu: remove VM shadow WARN_ONs
In reply to a message not in the archiveFrom: Christian König <[email protected]>
Printing a warning into the logs that we will certainly run into a BUG() is completely nonsense, the BUG() is more than noisy enough.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1 -5
@@ -1043,8 +1043,7 @@ static int amdgpu_vm_update_level(struct amdgpu_device *adev, params.adev = adev; shadow = parent->bo->shadow; -WARN_ON (vm->use_cpu_for_update && shadow); -if (vm->use_cpu_for_update && !shadow) { +if (vm->use_cpu_for_update) { r =amdgpu_bo_kmap (parent->bo, (void **)&pd_addr);if (r)return r;
@@ -1310,9 +1309,6 @@ static int amdgpu_vm_update_ptes(struct amdgpu_pte_update_params *params, r =amdgpu_bo_kmap (pt, (void *)&pe_start);if (r)return r; - -WARN_ONCE (pt->shadow, -"CPU VM update doesn't suuport shadow pages" ); }else {if (pt->shadow) { pe_start =amdgpu_bo_gpu_offset (pt->shadow);
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): 1499848308-1441-3-git-send-email-deathsimple-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org
Felix Kuehling
Reviewed-byRe: [PATCH 3/7] drm/amdgpu: remove VM shadow WARN_ONs
Quoted 25 lines · Christian König
From: Christian König <[email protected]>
Printing a warning into the logs that we will certainly run into a
BUG()is completely nonsense, theBUG()is more than noisy enough.Signed-off-by Christian König <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1
-2@@ -1043,8 +1043,7 @@ static int amdgpu_vm_update_level(struct amdgpu_device *adev, params.adev = adev; shadow = parent->bo->shadow; -WARN_ON (vm->use_cpu_for_update && shadow); -if (vm->use_cpu_for_update && !shadow) { +if (vm->use_cpu_for_update) { r =amdgpu_bo_kmap (parent->bo, (void **)&pd_addr);if (r)return r;
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c static int amdgpu_vm_update_ptes(struct amdgpu_pte_update_params *params, · line 1314
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0
-3@@ -1310,9 +1309,6 @@ static int amdgpu_vm_update_ptes(struct amdgpu_pte_update_params *params, r =amdgpu_bo_kmap (pt, (void *)&pe_start);if (r)return r; - -WARN_ONCE (pt->shadow, -"CPU VM update doesn't suuport shadow pages" ); }else {if (pt->shadow) { pe_start =amdgpu_bo_gpu_offset (pt->shadow);
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 4/7 drm/amdgpu: trace setting VM page tables with the CPU as well
In reply to a message not in the archiveFrom: Christian König <[email protected]>
Handy for debugging.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2 -0
@@ -981,6 +981,8 @@ static void amdgpu_vm_cpu_set_ptes(struct amdgpu_pte_update_params *params,unsigned int i;uint64_t value; +trace_amdgpu_vm_set_ptes (pe, addr, count, incr, flags); +for (i =0 ; i < count; i++) { value = params->pages_addr ? amdgpu_vm_map_gart(params->pages_addr, addr) :
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): 1499848308-1441-4-git-send-email-deathsimple-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org
Felix Kuehling
Reviewed-byRe: [PATCH 4/7] drm/amdgpu: trace setting VM page tables with the CPU as well
Quoted 14 lines · Christian König
From: Christian König <[email protected]>
Handy for debugging.
Signed-off-by Christian König <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 2 ++ 1 file changed, 2 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0
-0
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c static void amdgpu_vm_cpu_set_ptes(struct amdgpu_pte_update_params *params, · line 988
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2
-0@@ -981,6 +981,8 @@ static void amdgpu_vm_cpu_set_ptes(struct amdgpu_pte_update_params *params,unsigned int i;uint64_t value; +trace_amdgpu_vm_set_ptes (pe, addr, count, incr, flags); +for (i =0 ; i < count; i++) { value = params->pages_addr ? amdgpu_vm_map_gart(params->pages_addr, addr) :
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 5/7 drm/amdgpu: flush the HDP only once for CPU based VM updates
In reply to a message not in the archiveFrom: Christian König <[email protected]>
No need to do this after every single update.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +12 -4
@@ -991,10 +991,6 @@ static void amdgpu_vm_cpu_set_ptes(struct amdgpu_pte_update_params *params, i, value, flags); addr += incr; } - -/* Flush HDP */ -mb (); -amdgpu_gart_flush_gpu_tlb (params->adev,0 ); } static int amdgpu_vm_wait_pd(struct amdgpu_device *adev, struct amdgpu_vm *vm,
@@ -1237,6 +1233,12 @@ int amdgpu_vm_update_directories(struct amdgpu_device *adev,if (r)amdgpu_vm_invalidate_level (&vm->root); +if (vm->use_cpu_for_update) { +/* Flush HDP */ +mb (); +amdgpu_gart_flush_gpu_tlb (adev,0 ); + } +return r; }
@@ -1745,6 +1747,12 @@ int amdgpu_vm_bo_update(struct amdgpu_device *adev,list_add (&bo_va->vm_status, &vm->cleared);spin_unlock (&vm->status_lock); +if (vm->use_cpu_for_update) { +/* Flush HDP */ +mb (); +amdgpu_gart_flush_gpu_tlb (adev,0 ); + } +return 0 ; }
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): 1499848308-1441-5-git-send-email-deathsimple-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org
Re: [PATCH 5/7] drm/amdgpu: flush the HDP only once for CPU based VM updates
I'm wondering if you need a HDP flush in update_directories at all. Are there cases where the directories are updated but the page tables are not?
Also, in case of amdgpu_cs, I think we already have an HPD flush anyway. For KFD we don't use kernel-based submission, so we'd have to add an HDP flush into the KFD-specific VM mapping code.
Either way, this is Reviewed-by: Felix Kuehling <[email protected]>
Regards,
Felix
Quoted 40 lines · Christian König
From: Christian König <[email protected]>
No need to do this after every single update.
Signed-off-by Christian König <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +6
-4@@ -991,10 +991,6 @@ static void amdgpu_vm_cpu_set_ptes(struct amdgpu_pte_update_params *params, i, value, flags); addr += incr; } - -/* Flush HDP */ -mb (); -amdgpu_gart_flush_gpu_tlb (params->adev,0 ); } static int amdgpu_vm_wait_pd(struct amdgpu_device *adev, struct amdgpu_vm *vm,@@ -1237,6 +1233,12 @@ int amdgpu_vm_update_directories(struct amdgpu_device *adev,if (r)amdgpu_vm_invalidate_level (&vm->root); +if (vm->use_cpu_for_update) { +/* Flush HDP */ +mb (); +amdgpu_gart_flush_gpu_tlb (adev,0 ); + } +return r; }@@ -1745,6 +1747,12 @@ int amdgpu_vm_bo_update(struct amdgpu_device *adev,list_add (&bo_va->vm_status, &vm->cleared);spin_unlock (&vm->status_lock);
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c int amdgpu_vm_bo_update(struct amdgpu_device *adev, · line 1758
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +6
-0+if (vm->use_cpu_for_update) { +/* Flush HDP */ +mb (); +amdgpu_gart_flush_gpu_tlb (adev,0 ); + } +return 0 ; }
_______________________________________________
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): 2fddb73c-cd15-de00-7745-f4115ee571d6-5C7GfCeVMHo@public.gmane.org
Re: [PATCH 5/7] drm/amdgpu: flush the HDP only once for CPU based VM updates
Am 12.07.2017 um 22:31 schrieb Felix Kuehling:
Quoted 2 lines
I'm wondering if you need a HDP flush in
update_directoriesat all. Are there cases where the directories are updated but the page tables are not?
It can happen that a page table is swapped out and back in. In this case on the PDs need an update, but not the table itself.
Rather unlikely, but still possible.
Quoted 3 lines
Also, in case of
amdgpu_cs, I think we already have an HPD flush anyway. For KFD we don't use kernel-based submission, so we'd have to add an HDP flush into the KFD-specific VM mapping code.
Yeah, good point. But during CS the HDP flush comes after the VM flush.
I think we could change that, but I'm not 100% sure what the interactions with SRVIO are.
Christian.
Quoted 49 lines
Either way, this is Reviewed-by: Felix Kuehling <[email protected]>
Regards,
FelixQuoted 41 lines · Christian König
From: Christian König <[email protected]>
No need to do this after every single update.
Signed-off-by Christian König <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +6
-4@@ -991,10 +991,6 @@ static void amdgpu_vm_cpu_set_ptes(struct amdgpu_pte_update_params *params, i, value, flags); addr += incr; } - -/* Flush HDP */ -mb (); -amdgpu_gart_flush_gpu_tlb (params->adev,0 ); } static int amdgpu_vm_wait_pd(struct amdgpu_device *adev, struct amdgpu_vm *vm,@@ -1237,6 +1233,12 @@ int amdgpu_vm_update_directories(struct amdgpu_device *adev,if (r)amdgpu_vm_invalidate_level (&vm->root); +if (vm->use_cpu_for_update) { +/* Flush HDP */ +mb (); +amdgpu_gart_flush_gpu_tlb (adev,0 ); + } +return r; }@@ -1745,6 +1747,12 @@ int amdgpu_vm_bo_update(struct amdgpu_device *adev,list_add (&bo_va->vm_status, &vm->cleared);spin_unlock (&vm->status_lock);
Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c int amdgpu_vm_bo_update(struct amdgpu_device *adev, · line 1758
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +6
-0+if (vm->use_cpu_for_update) { +/* Flush HDP */ +mb (); +amdgpu_gart_flush_gpu_tlb (adev,0 ); + } +return 0 ; }_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 6/7 drm/amdgpu: make sure BOs are always kunmapped
In reply to a message not in the archiveFrom: Christian König <[email protected]>
When a BO is moved or destroyed it shouldn't be kmapped any more.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +3 -0
@@ -93,6 +93,7 @@ static void amdgpu_ttm_bo_destroy(struct ttm_buffer_object *tbo) bo = container_of(tbo, struct amdgpu_bo, tbo); +amdgpu_bo_kunmap (bo);amdgpu_update_memory_usage (adev, &bo->tbo.mem,NULL );drm_gem_object_release (&bo->gem_base);
@@ -931,6 +932,8 @@ void amdgpu_bo_move_notify(struct ttm_buffer_object *bo, abo = container_of(bo, struct amdgpu_bo, tbo);amdgpu_vm_bo_invalidate (adev, abo); +amdgpu_bo_kunmap (abo); +/* remember the eviction */ if (evict)atomic64_inc (&adev->num_evictions);
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): 1499848308-1441-6-git-send-email-deathsimple-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org
Felix Kuehling
Reviewed-byRe: [PATCH 6/7] drm/amdgpu: make sure BOs are always kunmapped
Quoted 22 lines · Christian König
From: Christian König <[email protected]>
When a BO is moved or destroyed it shouldn't be kmapped any more.
Signed-off-by Christian König <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 3 +++ 1 file changed, 3 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +1
-0@@ -93,6 +93,7 @@ static void amdgpu_ttm_bo_destroy(struct ttm_buffer_object *tbo) bo = container_of(tbo, struct amdgpu_bo, tbo); +amdgpu_bo_kunmap (bo);amdgpu_update_memory_usage (adev, &bo->tbo.mem,NULL );drm_gem_object_release (&bo->gem_base);
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c void amdgpu_bo_move_notify(struct ttm_buffer_object *bo, · line 939
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +2
-0@@ -931,6 +932,8 @@ void amdgpu_bo_move_notify(struct ttm_buffer_object *bo, abo = container_of(bo, struct amdgpu_bo, tbo);amdgpu_vm_bo_invalidate (adev, abo); +amdgpu_bo_kunmap (abo); +/* remember the eviction */ if (evict)atomic64_inc (&adev->num_evictions);
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 7/7 drm/amdgpu: map VM BOs for CPU based updates only once
In reply to a message not in the archiveFrom: Christian König <[email protected]>
No need to try to map them very time.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 87 ++++++++++++++++++++-------------- 1 file changed, 51 insertions(+), 36 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +51 -36
@@ -159,11 +159,17 @@ void amdgpu_vm_get_pd_bo(struct amdgpu_vm *vm,*/ static int amdgpu_vm_validate_level (struct amdgpu_vm_pt *parent,int (*validate)(void *,struct amdgpu_bo *), -void *param) +void *param,bool use_cpu_for_update) {unsigned i;int r; +if (use_cpu_for_update) { + r =amdgpu_bo_kmap (parent->bo,NULL ); +if (r) +return r; + } +if (!parent->entries)return 0 ;
@@ -181,7 +187,8 @@ static int amdgpu_vm_validate_level(struct amdgpu_vm_pt *parent,* Recurse into the sub directory. This is harmless because we * have only a maximum of 5 layers. */ - r =amdgpu_vm_validate_level (entry, validate, param); + r =amdgpu_vm_validate_level (entry, validate, param, + use_cpu_for_update);if (r)return r; }
@@ -212,7 +219,8 @@ int amdgpu_vm_validate_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm,if (num_evictions == vm->last_eviction_counter)return 0 ; -return amdgpu_vm_validate_level (&vm->root, validate, param); +return amdgpu_vm_validate_level (&vm->root, validate, param, + vm->use_cpu_for_update); }/**
@@ -328,6 +336,14 @@ static int amdgpu_vm_alloc_levels(struct amdgpu_device *adev,if (r)return r; +if (vm->use_cpu_for_update) { + r =amdgpu_bo_kmap (pt,NULL ); +if (r) { +amdgpu_bo_unref (&pt); +return r; + } + } +/* Keep a reference to the root directory to avoid * freeing them up in the wrong order. */
@@ -1042,14 +1058,11 @@ static int amdgpu_vm_update_level(struct amdgpu_device *adev, shadow = parent->bo->shadow;if (vm->use_cpu_for_update) { - r =amdgpu_bo_kmap (parent->bo, (void **)&pd_addr); -if (r) -return r; + pd_addr = (unsigned long )parent->bo->kptr; r =amdgpu_vm_wait_pd (adev, vm,AMDGPU_FENCE_OWNER_VM ); -if (unlikely (r)) { -amdgpu_bo_kunmap (parent->bo); +if (unlikely (r))return r; - } + params.func = amdgpu_vm_cpu_set_ptes; }else {if (shadow) {
@@ -1144,28 +1157,29 @@ static int amdgpu_vm_update_level(struct amdgpu_device *adev, count, incr, AMDGPU_PTE_VALID); } -if (params.func == amdgpu_vm_cpu_set_ptes) -amdgpu_bo_kunmap (parent->bo); -else if (params.ib->length_dw ==0 ) { -amdgpu_job_free (job); - }else { -amdgpu_ring_pad_ib (ring, params.ib); -amdgpu_sync_resv (adev, &job->sync, parent->bo->tbo.resv, -AMDGPU_FENCE_OWNER_VM ); -if (shadow) -amdgpu_sync_resv (adev, &job->sync, shadow->tbo.resv, +if (!vm->use_cpu_for_update) { +if (params.ib->length_dw ==0 ) { +amdgpu_job_free (job); + }else { +amdgpu_ring_pad_ib (ring, params.ib); +amdgpu_sync_resv (adev, &job->sync, parent->bo->tbo.resv,AMDGPU_FENCE_OWNER_VM ); +if (shadow) +amdgpu_sync_resv (adev, &job->sync, + shadow->tbo.resv, +AMDGPU_FENCE_OWNER_VM ); + +WARN_ON (params.ib->length_dw > ndw); + r =amdgpu_job_submit (job, ring, &vm->entity, +AMDGPU_FENCE_OWNER_VM , &fence); +if (r) + goto error_free; -WARN_ON (params.ib->length_dw > ndw); - r =amdgpu_job_submit (job, ring, &vm->entity, -AMDGPU_FENCE_OWNER_VM , &fence); -if (r) - goto error_free; - -amdgpu_bo_fence (parent->bo, fence, true); -dma_fence_put (vm->last_dir_update); - vm->last_dir_update =dma_fence_get (fence); -dma_fence_put (fence); +amdgpu_bo_fence (parent->bo, fence, true); +dma_fence_put (vm->last_dir_update); + vm->last_dir_update =dma_fence_get (fence); +dma_fence_put (fence); + } }/* * Recurse into the subdirectories. This recursion is harmless because
@@ -1291,7 +1305,6 @@ static int amdgpu_vm_update_ptes(struct amdgpu_pte_update_params *params,uint64_t addr, pe_start;struct amdgpu_bo *pt;unsigned nptes; -int r;bool use_cpu_update = (params->func == amdgpu_vm_cpu_set_ptes);
@@ -1310,9 +1323,7 @@ static int amdgpu_vm_update_ptes(struct amdgpu_pte_update_params *params,if (use_cpu_update) { - r =amdgpu_bo_kmap (pt, (void *)&pe_start); -if (r) -return r; + pe_start = (unsigned long )pt->kptr; }else {if (pt->shadow) { pe_start =amdgpu_bo_gpu_offset (pt->shadow);
@@ -1328,9 +1339,6 @@ static int amdgpu_vm_update_ptes(struct amdgpu_pte_update_params *params, AMDGPU_GPU_PAGE_SIZE, flags); dst += nptes *AMDGPU_GPU_PAGE_SIZE ; - -if (use_cpu_update) -amdgpu_bo_kunmap (pt); }return 0 ;
@@ -2458,6 +2466,13 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm, goto error_free_root; vm->last_eviction_counter =atomic64_read (&adev->num_evictions); + +if (vm->use_cpu_for_update) { + r =amdgpu_bo_kmap (vm->root.bo,NULL ); +if (r) + goto error_free_root; + } +amdgpu_bo_unreserve (vm->root.bo);return 0 ;
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): 1499848308-1441-7-git-send-email-deathsimple-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org
Re: [PATCH 7/7] drm/amdgpu: map VM BOs for CPU based updates only once
Quoted 3 lines · Christian König
From: Christian König <[email protected]>
No need to try to map them very time.
s/very/every/
Other than that this is Reviewed-by: Felix Kuehling <[email protected]>.
Regards,
Felix
Quoted 165 lines
Signed-off-by Christian König <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 87 ++++++++++++++++++++-------------- 1 file changed, 51 insertions(+), 36 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +44
-36@@ -159,11 +159,17 @@ void amdgpu_vm_get_pd_bo(struct amdgpu_vm *vm,*/ static int amdgpu_vm_validate_level (struct amdgpu_vm_pt *parent,int (*validate)(void *,struct amdgpu_bo *), -void *param) +void *param,bool use_cpu_for_update) {unsigned i;int r; +if (use_cpu_for_update) { + r =amdgpu_bo_kmap (parent->bo,NULL ); +if (r) +return r; + } +if (!parent->entries)return 0 ;@@ -181,7 +187,8 @@ static int amdgpu_vm_validate_level(struct amdgpu_vm_pt *parent,* Recurse into the sub directory. This is harmless because we * have only a maximum of 5 layers. */ - r =amdgpu_vm_validate_level (entry, validate, param); + r =amdgpu_vm_validate_level (entry, validate, param, + use_cpu_for_update);if (r)return r; }@@ -212,7 +219,8 @@ int amdgpu_vm_validate_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm,if (num_evictions == vm->last_eviction_counter)return 0 ; -return amdgpu_vm_validate_level (&vm->root, validate, param); +return amdgpu_vm_validate_level (&vm->root, validate, param, + vm->use_cpu_for_update); }/** @@ -328,6 +336,14 @@ static int amdgpu_vm_alloc_levels(struct amdgpu_device *adev,if (r)return r; +if (vm->use_cpu_for_update) { + r =amdgpu_bo_kmap (pt,NULL ); +if (r) { +amdgpu_bo_unref (&pt); +return r; + } + } +/* Keep a reference to the root directory to avoid * freeing them up in the wrong order. */ @@ -1042,14 +1058,11 @@ static int amdgpu_vm_update_level(struct amdgpu_device *adev, shadow = parent->bo->shadow;if (vm->use_cpu_for_update) { - r =amdgpu_bo_kmap (parent->bo, (void **)&pd_addr); -if (r) -return r; + pd_addr = (unsigned long )parent->bo->kptr; r =amdgpu_vm_wait_pd (adev, vm,AMDGPU_FENCE_OWNER_VM ); -if (unlikely (r)) { -amdgpu_bo_kunmap (parent->bo); +if (unlikely (r))return r; - } + params.func = amdgpu_vm_cpu_set_ptes; }else {if (shadow) {@@ -1144,28 +1157,29 @@ static int amdgpu_vm_update_level(struct amdgpu_device *adev, count, incr, AMDGPU_PTE_VALID); } -if (params.func == amdgpu_vm_cpu_set_ptes) -amdgpu_bo_kunmap (parent->bo); -else if (params.ib->length_dw ==0 ) { -amdgpu_job_free (job); - }else { -amdgpu_ring_pad_ib (ring, params.ib); -amdgpu_sync_resv (adev, &job->sync, parent->bo->tbo.resv, -AMDGPU_FENCE_OWNER_VM ); -if (shadow) -amdgpu_sync_resv (adev, &job->sync, shadow->tbo.resv, +if (!vm->use_cpu_for_update) { +if (params.ib->length_dw ==0 ) { +amdgpu_job_free (job); + }else { +amdgpu_ring_pad_ib (ring, params.ib); +amdgpu_sync_resv (adev, &job->sync, parent->bo->tbo.resv,AMDGPU_FENCE_OWNER_VM ); +if (shadow) +amdgpu_sync_resv (adev, &job->sync, + shadow->tbo.resv, +AMDGPU_FENCE_OWNER_VM ); + +WARN_ON (params.ib->length_dw > ndw); + r =amdgpu_job_submit (job, ring, &vm->entity, +AMDGPU_FENCE_OWNER_VM , &fence); +if (r) + goto error_free; -WARN_ON (params.ib->length_dw > ndw); - r =amdgpu_job_submit (job, ring, &vm->entity, -AMDGPU_FENCE_OWNER_VM , &fence); -if (r) - goto error_free; - -amdgpu_bo_fence (parent->bo, fence, true); -dma_fence_put (vm->last_dir_update); - vm->last_dir_update =dma_fence_get (fence); -dma_fence_put (fence); +amdgpu_bo_fence (parent->bo, fence, true); +dma_fence_put (vm->last_dir_update); + vm->last_dir_update =dma_fence_get (fence); +dma_fence_put (fence); + } }/* * Recurse into the subdirectories. This recursion is harmless because @@ -1291,7 +1305,6 @@ static int amdgpu_vm_update_ptes(struct amdgpu_pte_update_params *params,uint64_t addr, pe_start;struct amdgpu_bo *pt;unsigned nptes; -int r;bool use_cpu_update = (params->func == amdgpu_vm_cpu_set_ptes);@@ -1310,9 +1323,7 @@ static int amdgpu_vm_update_ptes(struct amdgpu_pte_update_params *params,if (use_cpu_update) { - r =amdgpu_bo_kmap (pt, (void *)&pe_start); -if (r) -return r; + pe_start = (unsigned long )pt->kptr; }else {if (pt->shadow) { pe_start =amdgpu_bo_gpu_offset (pt->shadow);@@ -1328,9 +1339,6 @@ static int amdgpu_vm_update_ptes(struct amdgpu_pte_update_params *params, AMDGPU_GPU_PAGE_SIZE, flags); dst += nptes *AMDGPU_GPU_PAGE_SIZE ; - -if (use_cpu_update) -amdgpu_bo_kunmap (pt); }return 0 ;@@ -2458,6 +2466,13 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm, goto error_free_root; vm->last_eviction_counter =atomic64_read (&adev->num_evictions);
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm, · line 2478
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +7
-0+ +if (vm->use_cpu_for_update) { + r =amdgpu_bo_kmap (vm->root.bo,NULL ); +if (r) + goto error_free_root; + } +amdgpu_bo_unreserve (vm->root.bo);return 0 ;
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Quoted 4 lines · Christian König
From: Christian König <[email protected]>
We don't have any update fence in that case, so the need for flushing isn't detected atomatically.
s/atomatically/automatically/
Quoted 11 lines
Signed-off-by Christian König <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0
-0
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c static int amdgpu_vm_grab_reserved_vmid_locked(struct amdgpu_vm *vm, · line 424
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1
-1@@ -421,7 +421,7 @@ static int amdgpu_vm_grab_reserved_vmid_locked(struct amdgpu_vm *vm,struct dma_fence *updates = sync->last_vm_update;int r =0 ;struct dma_fence *flushed, *tmp; -bool needs_flush = false; +bool needs_flush = vm->use_cpu_for_update;
I think this will result in unnecessary flushing. To avoid that you'd probably have to define a new fence timeline for CPU pagetable updates so that the code below can check which updates have already been flushed. Fences on that timeline would be signalled as soon as they are created.
Anyway, this fixes correctness first. Optimization can come later.
With the typo above fixed, this is Reviewed-by: Felix Kuehling <[email protected]>
Regards,
Felix
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0
-0flushed = id->flushed_updates; if ((amdgpu_vm_had_gpu_reset(adev, id)) ||@@ -542,11 +542,11 @@ int amdgpu_vm_grab_id(struct amdgpu_vm *vm, struct amdgpu_ring *ring, }kfree (fences);
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c int amdgpu_vm_grab_id(struct amdgpu_vm *vm, struct amdgpu_ring *ring, · line 552
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2
-2- job->vm_needs_flush = false; + job->vm_needs_flush = vm->use_cpu_for_update;/* Check if we can use a VMID already assigned to this VM */ list_for_each_entry_reverse (id, &id_mgr->ids_lru, list) {struct dma_fence *flushed; -bool needs_flush = false; +bool needs_flush = vm->use_cpu_for_update;/* Check all the prerequisites to using this VMID */ if (amdgpu_vm_had_gpu_reset (adev, id))
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx