drm/amdgpu: move size calculations to the front of the file again
Subsystems (2)
PATCH 1/2 drm/amdgpu: move size calculations to the front of the file again
amdgpu_vm_bo_* functions should come much later.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 90 +++++++++++++++++----------------- 1 file changed, 45 insertions(+), 45 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +45 -45
@@ -133,51 +133,6 @@ struct amdgpu_prt_cb {struct dma_fence_cb cb; }; -/** -* amdgpu_vm_bo_base_init - Adds bo to the list of bos associated with the vm -* -* @base: base structure for tracking BO usage in a VM -* @vm: vm to which bo is to be added -* @bo: amdgpu buffer object -* -* Initialize a bo_va_base structure and add it to the appropriate lists -* -*/ -static void amdgpu_vm_bo_base_init (struct amdgpu_vm_bo_base *base, -struct amdgpu_vm *vm, -struct amdgpu_bo *bo) -{ - base->vm = vm; - base->bo = bo; -INIT_LIST_HEAD (&base->bo_list); -INIT_LIST_HEAD (&base->vm_status); - -if (!bo) -return ; -list_add_tail (&base->bo_list, &bo->va); - -if (bo->tbo.resv != vm->root.base.bo->tbo.resv) -return ; - - vm->bulk_moveable = false; -if (bo->tbo.type == ttm_bo_type_kernel) -list_move (&base->vm_status, &vm->relocated); -else -list_move (&base->vm_status, &vm->idle); - -if (bo->preferred_domains & -amdgpu_mem_type_to_domain (bo->tbo.mem.mem_type)) -return ; - -/* -* we checked all the prerequisites, but it looks like this per vm bo -* is currently evicted. add the bo to the evicted list to make sure it -* is validated on next vm use to avoid fault. -* */ -list_move_tail (&base->vm_status, &vm->evicted); - base->moved = true; -} -/** * amdgpu_vm_level_shift - return the addr shift for each level *
@@ -249,6 +204,51 @@ static unsigned amdgpu_vm_bo_size(struct amdgpu_device *adev, unsigned level)return AMDGPU_GPU_PAGE_ALIGN (amdgpu_vm_num_entries (adev, level) *8 ); } +/** +* amdgpu_vm_bo_base_init - Adds bo to the list of bos associated with the vm +* +* @base: base structure for tracking BO usage in a VM +* @vm: vm to which bo is to be added +* @bo: amdgpu buffer object +* +* Initialize a bo_va_base structure and add it to the appropriate lists +* +*/ +static void amdgpu_vm_bo_base_init (struct amdgpu_vm_bo_base *base, +struct amdgpu_vm *vm, +struct amdgpu_bo *bo) +{ + base->vm = vm; + base->bo = bo; +INIT_LIST_HEAD (&base->bo_list); +INIT_LIST_HEAD (&base->vm_status); + +if (!bo) +return ; +list_add_tail (&base->bo_list, &bo->va); + +if (bo->tbo.resv != vm->root.base.bo->tbo.resv) +return ; + + vm->bulk_moveable = false; +if (bo->tbo.type == ttm_bo_type_kernel) +list_move (&base->vm_status, &vm->relocated); +else +list_move (&base->vm_status, &vm->idle); + +if (bo->preferred_domains & +amdgpu_mem_type_to_domain (bo->tbo.mem.mem_type)) +return ; + +/* +* we checked all the prerequisites, but it looks like this per vm bo +* is currently evicted. add the bo to the evicted list to make sure it +* is validated on next vm use to avoid fault. +* */ +list_move_tail (&base->vm_status, &vm->evicted); + base->moved = true; +} +/** * amdgpu_vm_get_pd_bo - add the VM PD to a validation list *
Signature · 6 lines
2.14.1 _______________________________________________ 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): 20180831132741.112280-1-christian.koenig-5C7GfCeVMHo@public.gmane.org
PATCH 2/2 drm/amdgpu: improve VM state machine documentation
Since we have a lot of FAQ on the VM state machine try to improve the documentation by adding functions for each state move.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 107 ++++++++++++++++++++++++--------- 1 file changed, 79 insertions(+), 28 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +79 -28
@@ -204,6 +204,69 @@ static unsigned amdgpu_vm_bo_size(struct amdgpu_device *adev, unsigned level)return AMDGPU_GPU_PAGE_ALIGN (amdgpu_vm_num_entries (adev, level) *8 ); } +/** +* amdgpu_vm_bo_evicted - vm_bo is evicted +* +* @vm_bo: vm_bo which is evicted +* +* State for PDs/PTs and per VM BOs which are not at the location they should +* be. +*/ +static void amdgpu_vm_bo_evicted (struct amdgpu_vm_bo_base *vm_bo) +{ +struct amdgpu_vm *vm = vm_bo->vm; +struct amdgpu_bo *bo = vm_bo->bo; + + vm_bo->moved = true; +if (bo->tbo.type == ttm_bo_type_kernel) +list_move (&vm_bo->vm_status, &vm->evicted); +else +list_move_tail (&vm_bo->vm_status, &vm->evicted); +} + +/** +* amdgpu_vm_bo_relocated - vm_bo is reloacted +* +* @vm_bo: vm_bo which is relocated +* +* State for PDs/PTs which needs to update their parent PD. +*/ +static void amdgpu_vm_bo_relocated (struct amdgpu_vm_bo_base *vm_bo) +{ +list_move (&vm_bo->vm_status, &vm_bo->vm->relocated); +} + +/** +* amdgpu_vm_bo_moved - vm_bo is moved +* +* @vm_bo: vm_bo which is moved +* +* State for per VM and normal BOs which are moved, but that change is not yet +* reflected in the page tables. +*/ +static void amdgpu_vm_bo_moved (struct amdgpu_vm_bo_base *vm_bo) +{ +struct amdgpu_vm *vm = vm_bo->vm; + +spin_lock (&vm->moved_lock); +list_move (&vm_bo->vm_status, &vm->moved); +spin_unlock (&vm->moved_lock); +} + +/** +* amdgpu_vm_bo_idle - vm_bo is idle +* +* @vm_bo: vm_bo which is now idle +* +* State for PDs/PTs and per VM BOs which have gone through the state machine +* and are now idle. +*/ +static void amdgpu_vm_bo_idle (struct amdgpu_vm_bo_base *vm_bo) +{ +list_move (&vm_bo->vm_status, &vm_bo->vm->idle); + vm_bo->moved = false; +} +/** * amdgpu_vm_bo_base_init - Adds bo to the list of bos associated with the vm *
@@ -232,9 +295,9 @@ static void amdgpu_vm_bo_base_init(struct amdgpu_vm_bo_base *base, vm->bulk_moveable = false;if (bo->tbo.type == ttm_bo_type_kernel) -list_move (&base->vm_status, &vm->relocated); +amdgpu_vm_bo_relocated (base);else -list_move (&base->vm_status, &vm->idle); +amdgpu_vm_bo_idle (base);if (bo->preferred_domains &amdgpu_mem_type_to_domain (bo->tbo.mem.mem_type))
@@ -245,8 +308,7 @@ static void amdgpu_vm_bo_base_init(struct amdgpu_vm_bo_base *base,* is currently evicted. add the bo to the evicted list to make sure it * is validated on next vm use to avoid fault. * */ -list_move_tail (&base->vm_status, &vm->evicted); - base->moved = true; +amdgpu_vm_bo_evicted (base); }/**
@@ -342,9 +404,7 @@ int amdgpu_vm_validate_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm,break ;if (bo->tbo.type != ttm_bo_type_kernel) { -spin_lock (&vm->moved_lock); -list_move (&bo_base->vm_status, &vm->moved); -spin_unlock (&vm->moved_lock); +amdgpu_vm_bo_moved (bo_base); }else {if (vm->use_cpu_for_update) r =amdgpu_bo_kmap (bo,NULL );
@@ -352,7 +412,7 @@ int amdgpu_vm_validate_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm, r =amdgpu_ttm_alloc_gart (&bo->tbo);if (r)break ; -list_move (&bo_base->vm_status, &vm->relocated); +amdgpu_vm_bo_relocated (bo_base); } }
@@ -1123,8 +1183,7 @@ int amdgpu_vm_update_directories(struct amdgpu_device *adev, bo_base =list_first_entry (&vm->relocated, struct amdgpu_vm_bo_base, vm_status); - bo_base->moved = false; -list_move (&bo_base->vm_status, &vm->idle); +amdgpu_vm_bo_idle (bo_base); bo = bo_base->bo->parent;if (!bo)
@@ -1243,7 +1302,7 @@ static void amdgpu_vm_handle_huge_pages(struct amdgpu_pte_update_params *p,if (entry->huge) {/* Add the entry to the relocated list to update it. */ entry->huge = false; -list_move (&entry->base.vm_status, &p->vm->relocated); +amdgpu_vm_bo_relocated (&entry->base); }return ; }
@@ -1746,9 +1805,9 @@ int amdgpu_vm_bo_update(struct amdgpu_device *adev,uint32_t mem_type = bo->tbo.mem.mem_type;if (!(bo->preferred_domains &amdgpu_mem_type_to_domain (mem_type))) -list_add_tail (&bo_va->base.vm_status, &vm->evicted); +amdgpu_vm_bo_evicted (&bo_va->base);else -list_add (&bo_va->base.vm_status, &vm->idle); +amdgpu_vm_bo_idle (&bo_va->base); }list_splice_init (&bo_va->invalids, &bo_va->valids);
@@ -2472,28 +2531,20 @@ void amdgpu_vm_bo_invalidate(struct amdgpu_device *adev,list_for_each_entry (bo_base, &bo->va, bo_list) {struct amdgpu_vm *vm = bo_base->vm; -bool was_moved = bo_base->moved; - bo_base->moved = true;if (evicted && bo->tbo.resv == vm->root.base.bo->tbo.resv) { -if (bo->tbo.type == ttm_bo_type_kernel) -list_move (&bo_base->vm_status, &vm->evicted); -else -list_move_tail (&bo_base->vm_status, - &vm->evicted); +amdgpu_vm_bo_evicted (bo_base);continue ; } -if (was_moved) +if (bo_base->moved)continue ; -if (bo->tbo.type == ttm_bo_type_kernel) { -list_move (&bo_base->vm_status, &vm->relocated); - }else { -spin_lock (&bo_base->vm->moved_lock); -list_move (&bo_base->vm_status, &vm->moved); -spin_unlock (&bo_base->vm->moved_lock); - } + bo_base->moved = true; +if (bo->tbo.type == ttm_bo_type_kernel) +amdgpu_vm_bo_relocated (bo_base); +else +amdgpu_vm_bo_moved (bo_base); } }
Signature · 6 lines
2.14.1 _______________________________________________ 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): 20180831132741.112280-2-christian.koenig-5C7GfCeVMHo@public.gmane.org
Re: [PATCH 2/2] drm/amdgpu: improve VM state machine documentation
Thanks for this. A few comments and a question inline.
Quoted 45 lines · Christian König
Since we have a lot of FAQ on the VM state machine try to improve the documentation by adding functions for each state move.
Signed-off-by Christian König <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 107 ++++++++++++++++++++++++--------- 1 file changed, 79 insertions(+), 28 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +29
-0@@ -204,6 +204,69 @@ static unsigned amdgpu_vm_bo_size(struct amdgpu_device *adev, unsigned level)return AMDGPU_GPU_PAGE_ALIGN (amdgpu_vm_num_entries (adev, level) *8 ); } +/** +* amdgpu_vm_bo_evicted - vm_bo is evicted +* +* @vm_bo: vm_bo which is evicted +* +* State for PDs/PTs and per VM BOs which are not at the location they should +* be. +*/ +static void amdgpu_vm_bo_evicted (struct amdgpu_vm_bo_base *vm_bo) +{ +struct amdgpu_vm *vm = vm_bo->vm; +struct amdgpu_bo *bo = vm_bo->bo; + + vm_bo->moved = true; +if (bo->tbo.type == ttm_bo_type_kernel) +list_move (&vm_bo->vm_status, &vm->evicted); +else +list_move_tail (&vm_bo->vm_status, &vm->evicted); +} + +/** +* amdgpu_vm_bo_relocated - vm_bo is reloacted +* +* @vm_bo: vm_bo which is relocated +* +* State for PDs/PTs which needs to update their parent PD. +*/ +static void amdgpu_vm_bo_relocated (struct amdgpu_vm_bo_base *vm_bo) +{
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c static unsigned amdgpu_vm_bo_size(struct amdgpu_device *adev, unsigned level) · line 245
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +10
-0+list_move (&vm_bo->vm_status, &vm_bo->vm->relocated); +} + +/** +* amdgpu_vm_bo_moved - vm_bo is moved +* +* @vm_bo: vm_bo which is moved +* +* State for per VM and normal BOs which are moved, but that change is not yet +* reflected in the page tables.
I have a question here. Why does amdgpu_cs_vm_handling call amdgpu_vm_bo_update manually for its BO list entries? Wouldn't it be enough to just call amdgpu_vm_handle_moved?
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c static unsigned amdgpu_vm_bo_size(struct amdgpu_device *adev, unsigned level) · line 253
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +8
-0+*/ +static void amdgpu_vm_bo_moved (struct amdgpu_vm_bo_base *vm_bo) +{ +struct amdgpu_vm *vm = vm_bo->vm; + +spin_lock (&vm->moved_lock); +list_move (&vm_bo->vm_status, &vm->moved); +spin_unlock (&vm->moved_lock);
If vm->moved_lock protects the moved list, do we also need to take it whenever something is moved from that list? That could potentially be any list_move operation that uses vm_bo->vm_status. I found one case below where that may not be handled correctly.
Quoted 81 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +23
-11+} + +/** +* amdgpu_vm_bo_idle - vm_bo is idle +* +* @vm_bo: vm_bo which is now idle +* +* State for PDs/PTs and per VM BOs which have gone through the state machine +* and are now idle. +*/ +static void amdgpu_vm_bo_idle (struct amdgpu_vm_bo_base *vm_bo) +{ +list_move (&vm_bo->vm_status, &vm_bo->vm->idle); + vm_bo->moved = false; +} +/** * amdgpu_vm_bo_base_init - Adds bo to the list of bos associated with the vm * @@ -232,9 +295,9 @@ static void amdgpu_vm_bo_base_init(struct amdgpu_vm_bo_base *base, vm->bulk_moveable = false;if (bo->tbo.type == ttm_bo_type_kernel) -list_move (&base->vm_status, &vm->relocated); +amdgpu_vm_bo_relocated (base);else -list_move (&base->vm_status, &vm->idle); +amdgpu_vm_bo_idle (base);if (bo->preferred_domains &amdgpu_mem_type_to_domain (bo->tbo.mem.mem_type))@@ -245,8 +308,7 @@ static void amdgpu_vm_bo_base_init(struct amdgpu_vm_bo_base *base,* is currently evicted. add the bo to the evicted list to make sure it * is validated on next vm use to avoid fault. * */ -list_move_tail (&base->vm_status, &vm->evicted); - base->moved = true; +amdgpu_vm_bo_evicted (base); }/** @@ -342,9 +404,7 @@ int amdgpu_vm_validate_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm,break ;if (bo->tbo.type != ttm_bo_type_kernel) { -spin_lock (&vm->moved_lock); -list_move (&bo_base->vm_status, &vm->moved); -spin_unlock (&vm->moved_lock); +amdgpu_vm_bo_moved (bo_base); }else {if (vm->use_cpu_for_update) r =amdgpu_bo_kmap (bo,NULL );@@ -352,7 +412,7 @@ int amdgpu_vm_validate_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm, r =amdgpu_ttm_alloc_gart (&bo->tbo);if (r)break ; -list_move (&bo_base->vm_status, &vm->relocated); +amdgpu_vm_bo_relocated (bo_base); } }@@ -1123,8 +1183,7 @@ int amdgpu_vm_update_directories(struct amdgpu_device *adev, bo_base =list_first_entry (&vm->relocated, struct amdgpu_vm_bo_base, vm_status); - bo_base->moved = false; -list_move (&bo_base->vm_status, &vm->idle); +amdgpu_vm_bo_idle (bo_base); bo = bo_base->bo->parent;if (!bo)@@ -1243,7 +1302,7 @@ static void amdgpu_vm_handle_huge_pages(struct amdgpu_pte_update_params *p,if (entry->huge) {/* Add the entry to the relocated list to update it. */ entry->huge = false; -list_move (&entry->base.vm_status, &p->vm->relocated); +amdgpu_vm_bo_relocated (&entry->base); }return ; }
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c int amdgpu_vm_bo_update(struct amdgpu_device *adev, · line 1810
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2
-2@@ -1746,9 +1805,9 @@ int amdgpu_vm_bo_update(struct amdgpu_device *adev,uint32_t mem_type = bo->tbo.mem.mem_type;if (!(bo->preferred_domains &amdgpu_mem_type_to_domain (mem_type))) -list_add_tail (&bo_va->base.vm_status, &vm->evicted); +amdgpu_vm_bo_evicted (&bo_va->base);else -list_add (&bo_va->base.vm_status, &vm->idle); +amdgpu_vm_bo_idle (&bo_va->base);
There is a small change in behaviour here for clearing bo_va->base.moved. Not sure if it matters.
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0
-0}list_splice_init (&bo_va->invalids, &bo_va->valids);@@ -2472,28 +2531,20 @@ void amdgpu_vm_bo_invalidate(struct amdgpu_device *adev,list_for_each_entry (bo_base, &bo->va, bo_list) {struct amdgpu_vm *vm = bo_base->vm;
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c void amdgpu_vm_bo_invalidate(struct amdgpu_device *adev, · line 2536
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1
-7-bool was_moved = bo_base->moved; - bo_base->moved = true;if (evicted && bo->tbo.resv == vm->root.base.bo->tbo.resv) { -if (bo->tbo.type == ttm_bo_type_kernel) -list_move (&bo_base->vm_status, &vm->evicted); -else -list_move_tail (&bo_base->vm_status, - &vm->evicted); +amdgpu_vm_bo_evicted (bo_base);
I think here it's possible that the BO was on the moved list. I think that means amdgpu_vm_bo_evicted should take the moved_lock just in case.
Regards,
Felix
Quoted 12 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1
-6continue ; } -if (was_moved) +if (bo_base->moved)continue ; -if (bo->tbo.type == ttm_bo_type_kernel) { -list_move (&bo_base->vm_status, &vm->relocated); - }else { -spin_lock (&bo_base->vm->moved_lock); -list_move (&bo_base->vm_status, &vm->moved);
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c void amdgpu_vm_bo_invalidate(struct amdgpu_device *adev, · line 2550
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +5
-2-spin_unlock (&bo_base->vm->moved_lock); - } + bo_base->moved = true; +if (bo->tbo.type == ttm_bo_type_kernel) +amdgpu_vm_bo_relocated (bo_base); +else +amdgpu_vm_bo_moved (bo_base); } }
_______________________________________________
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): 2ac28ad5-ccd3-51f0-f4da-3fce40a9f20a-5C7GfCeVMHo@public.gmane.org
Re: [PATCH 2/2] drm/amdgpu: improve VM state machine documentation
Am 01.09.2018 um 01:51 schrieb Felix Kuehling:
Quoted 53 lines
Thanks for this. A few comments and a question inline.
Quoted 50 lines · Christian König
Since we have a lot of FAQ on the VM state machine try to improve the documentation by adding functions for each state move.
Signed-off-by Christian König <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 107 ++++++++++++++++++++++++--------- 1 file changed, 79 insertions(+), 28 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +34
-0@@ -204,6 +204,69 @@ static unsigned amdgpu_vm_bo_size(struct amdgpu_device *adev, unsigned level)return AMDGPU_GPU_PAGE_ALIGN (amdgpu_vm_num_entries (adev, level) *8 ); } +/** +* amdgpu_vm_bo_evicted - vm_bo is evicted +* +* @vm_bo: vm_bo which is evicted +* +* State for PDs/PTs and per VM BOs which are not at the location they should +* be. +*/ +static void amdgpu_vm_bo_evicted (struct amdgpu_vm_bo_base *vm_bo) +{ +struct amdgpu_vm *vm = vm_bo->vm; +struct amdgpu_bo *bo = vm_bo->bo; + + vm_bo->moved = true; +if (bo->tbo.type == ttm_bo_type_kernel) +list_move (&vm_bo->vm_status, &vm->evicted); +else +list_move_tail (&vm_bo->vm_status, &vm->evicted); +} + +/** +* amdgpu_vm_bo_relocated - vm_bo is reloacted +* +* @vm_bo: vm_bo which is relocated +* +* State for PDs/PTs which needs to update their parent PD. +*/ +static void amdgpu_vm_bo_relocated (struct amdgpu_vm_bo_base *vm_bo) +{ +list_move (&vm_bo->vm_status, &vm_bo->vm->relocated); +} + +/** +* amdgpu_vm_bo_moved - vm_bo is moved
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c static unsigned amdgpu_vm_bo_size(struct amdgpu_device *adev, unsigned level) · line 245
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +5
-0+* +* @vm_bo: vm_bo which is moved +* +* State for per VM and normal BOs which are moved, but that change is not yet +* reflected in the page tables. I have a question here. Why does
amdgpu_cs_vm_handlingcallamdgpu_vm_bo_updatemanually for its BO list entries? Wouldn't it be enough to just callamdgpu_vm_handle_moved?
No, it is still possible that the mapping of the BO was never updated because the VM page tables where evicted.
We still need to make sure that all BOs of the current submission are updated correctly.
Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c static unsigned amdgpu_vm_bo_size(struct amdgpu_device *adev, unsigned level) · line 253
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +8
-0+*/ +static void amdgpu_vm_bo_moved (struct amdgpu_vm_bo_base *vm_bo) +{ +struct amdgpu_vm *vm = vm_bo->vm; + +spin_lock (&vm->moved_lock); +list_move (&vm_bo->vm_status, &vm->moved); +spin_unlock (&vm->moved_lock);If
vm->moved_lockprotects the moved list, do we also need to take it whenever something is moved from that list?
Correct, yes.
Quoted 87 lines
That could potentially be
anylist_moveoperation that usesvm_bo->vm_status. I found one case below where that may not be handled correctly.Quoted 83 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +23
-11+} + +/** +* amdgpu_vm_bo_idle - vm_bo is idle +* +* @vm_bo: vm_bo which is now idle +* +* State for PDs/PTs and per VM BOs which have gone through the state machine +* and are now idle. +*/ +static void amdgpu_vm_bo_idle (struct amdgpu_vm_bo_base *vm_bo) +{ +list_move (&vm_bo->vm_status, &vm_bo->vm->idle); + vm_bo->moved = false; +} +/** * amdgpu_vm_bo_base_init - Adds bo to the list of bos associated with the vm * @@ -232,9 +295,9 @@ static void amdgpu_vm_bo_base_init(struct amdgpu_vm_bo_base *base, vm->bulk_moveable = false;if (bo->tbo.type == ttm_bo_type_kernel) -list_move (&base->vm_status, &vm->relocated); +amdgpu_vm_bo_relocated (base);else -list_move (&base->vm_status, &vm->idle); +amdgpu_vm_bo_idle (base);if (bo->preferred_domains &amdgpu_mem_type_to_domain (bo->tbo.mem.mem_type))@@ -245,8 +308,7 @@ static void amdgpu_vm_bo_base_init(struct amdgpu_vm_bo_base *base,* is currently evicted. add the bo to the evicted list to make sure it * is validated on next vm use to avoid fault. * */ -list_move_tail (&base->vm_status, &vm->evicted); - base->moved = true; +amdgpu_vm_bo_evicted (base); }/** @@ -342,9 +404,7 @@ int amdgpu_vm_validate_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm,break ;if (bo->tbo.type != ttm_bo_type_kernel) { -spin_lock (&vm->moved_lock); -list_move (&bo_base->vm_status, &vm->moved); -spin_unlock (&vm->moved_lock); +amdgpu_vm_bo_moved (bo_base); }else {if (vm->use_cpu_for_update) r =amdgpu_bo_kmap (bo,NULL );@@ -352,7 +412,7 @@ int amdgpu_vm_validate_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm, r =amdgpu_ttm_alloc_gart (&bo->tbo);if (r)break ; -list_move (&bo_base->vm_status, &vm->relocated); +amdgpu_vm_bo_relocated (bo_base); } }@@ -1123,8 +1183,7 @@ int amdgpu_vm_update_directories(struct amdgpu_device *adev, bo_base =list_first_entry (&vm->relocated, struct amdgpu_vm_bo_base, vm_status); - bo_base->moved = false; -list_move (&bo_base->vm_status, &vm->idle); +amdgpu_vm_bo_idle (bo_base); bo = bo_base->bo->parent;if (!bo)@@ -1243,7 +1302,7 @@ static void amdgpu_vm_handle_huge_pages(struct amdgpu_pte_update_params *p,if (entry->huge) {/* Add the entry to the relocated list to update it. */ entry->huge = false; -list_move (&entry->base.vm_status, &p->vm->relocated); +amdgpu_vm_bo_relocated (&entry->base); }return ; }@@ -1746,9 +1805,9 @@ int amdgpu_vm_bo_update(struct amdgpu_device *adev,uint32_t mem_type = bo->tbo.mem.mem_type;
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c int amdgpu_vm_bo_update(struct amdgpu_device *adev, · line 1810
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2
-2if (!(bo->preferred_domains &amdgpu_mem_type_to_domain (mem_type))) -list_add_tail (&bo_va->base.vm_status, &vm->evicted); +amdgpu_vm_bo_evicted (&bo_va->base);else -list_add (&bo_va->base.vm_status, &vm->idle); +amdgpu_vm_bo_idle (&bo_va->base);There is a small change in behaviour here for clearing
bo_va->base.moved. Not sure if it matters.
Using list_add is minimal more efficient.
Quoted 10 lines
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0
-1}list_splice_init (&bo_va->invalids, &bo_va->valids);@@ -2472,28 +2531,20 @@ void amdgpu_vm_bo_invalidate(struct amdgpu_device *adev,list_for_each_entry (bo_base, &bo->va, bo_list) {struct amdgpu_vm *vm = bo_base->vm; -bool was_moved = bo_base->moved;
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c void amdgpu_vm_bo_invalidate(struct amdgpu_device *adev, · line 2536
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1
-6- bo_base->moved = true;if (evicted && bo->tbo.resv == vm->root.base.bo->tbo.resv) { -if (bo->tbo.type == ttm_bo_type_kernel) -list_move (&bo_base->vm_status, &vm->evicted); -else -list_move_tail (&bo_base->vm_status, - &vm->evicted); +amdgpu_vm_bo_evicted (bo_base);I think here it's possible that the BO was on the moved list. I think that means
amdgpu_vm_bo_evictedshould take themoved_lockjust in case.
Good point, probably best if I split up the moved list into per VM BOs and all other BOs.
That should make the locking much more clear.
Regards,
Christian.
Quoted 11 lines
Regards,
FelixQuoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1
-1continue ; } -if (was_moved) +if (bo_base->moved)continue ;
Quoted 15 lines
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0
-5-if (bo->tbo.type == ttm_bo_type_kernel) { -list_move (&bo_base->vm_status, &vm->relocated); - }else { -spin_lock (&bo_base->vm->moved_lock); -list_move (&bo_base->vm_status, &vm->moved);drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c void amdgpu_vm_bo_invalidate(struct amdgpu_device *adev, · line 2550
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +5
-2-spin_unlock (&bo_base->vm->moved_lock); - } + bo_base->moved = true; +if (bo->tbo.type == ttm_bo_type_kernel) +amdgpu_vm_bo_relocated (bo_base); +else +amdgpu_vm_bo_moved (bo_base); } }
_______________________________________________
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): 5424812b-2efb-4643-114d-a4609a0c69a3-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Re: [PATCH 2/2] drm/amdgpu: improve VM state machine documentation
Quoted 12 lines
Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c int amdgpu_vm_bo_update(struct amdgpu_device *adev, · line 1810
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2
-2@@ -1746,9 +1805,9 @@ int amdgpu_vm_bo_update(struct amdgpu_device *adev,uint32_t mem_type = bo->tbo.mem.mem_type;if (!(bo->preferred_domains &amdgpu_mem_type_to_domain (mem_type))) -list_add_tail (&bo_va->base.vm_status, &vm->evicted); +amdgpu_vm_bo_evicted (&bo_va->base);else -list_add (&bo_va->base.vm_status, &vm->idle); +amdgpu_vm_bo_idle (&bo_va->base);There is a small change in behaviour here for clearing
bo_va->base.moved. Not sure if it matters.
Quoted 1 line
Using
list_addis minimal more efficient.
What I meant was that the original code would not always set bo_va->base.moved = false (it's done a few lines above this under some conditions, but not always). The new code will always set bo_va->base.moved = false inside amdgpu_vm_bo_idle.
Regards,
Felix
________________________________________
From: Christian König <[email protected]>
Sent: Saturday, September 1, 2018 4:16:17 AM
To: Kuehling, Felix; [email protected]
Subject: Re: [PATCH 2/2] drm/amdgpu: improve VM state machine documentation
Am 01.09.2018 um 01:51 schrieb Felix Kuehling:
Quoted 53 lines
Thanks for this. A few comments and a question inline.
Quoted 50 lines · Christian König
Since we have a lot of FAQ on the VM state machine try to improve the documentation by adding functions for each state move.
Signed-off-by Christian König <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 107 ++++++++++++++++++++++++--------- 1 file changed, 79 insertions(+), 28 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +34
-0@@ -204,6 +204,69 @@ static unsigned amdgpu_vm_bo_size(struct amdgpu_device *adev, unsigned level)return AMDGPU_GPU_PAGE_ALIGN (amdgpu_vm_num_entries (adev, level) *8 ); } +/** +* amdgpu_vm_bo_evicted - vm_bo is evicted +* +* @vm_bo: vm_bo which is evicted +* +* State for PDs/PTs and per VM BOs which are not at the location they should +* be. +*/ +static void amdgpu_vm_bo_evicted (struct amdgpu_vm_bo_base *vm_bo) +{ +struct amdgpu_vm *vm = vm_bo->vm; +struct amdgpu_bo *bo = vm_bo->bo; + + vm_bo->moved = true; +if (bo->tbo.type == ttm_bo_type_kernel) +list_move (&vm_bo->vm_status, &vm->evicted); +else +list_move_tail (&vm_bo->vm_status, &vm->evicted); +} + +/** +* amdgpu_vm_bo_relocated - vm_bo is reloacted +* +* @vm_bo: vm_bo which is relocated +* +* State for PDs/PTs which needs to update their parent PD. +*/ +static void amdgpu_vm_bo_relocated (struct amdgpu_vm_bo_base *vm_bo) +{ +list_move (&vm_bo->vm_status, &vm_bo->vm->relocated); +} + +/** +* amdgpu_vm_bo_moved - vm_bo is moved
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c static unsigned amdgpu_vm_bo_size(struct amdgpu_device *adev, unsigned level) · line 245
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +5
-0+* +* @vm_bo: vm_bo which is moved +* +* State for per VM and normal BOs which are moved, but that change is not yet +* reflected in the page tables. I have a question here. Why does
amdgpu_cs_vm_handlingcallamdgpu_vm_bo_updatemanually for its BO list entries? Wouldn't it be enough to just callamdgpu_vm_handle_moved?
No, it is still possible that the mapping of the BO was never updated because the VM page tables where evicted.
We still need to make sure that all BOs of the current submission are updated correctly.
Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c static unsigned amdgpu_vm_bo_size(struct amdgpu_device *adev, unsigned level) · line 253
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +8
-0+*/ +static void amdgpu_vm_bo_moved (struct amdgpu_vm_bo_base *vm_bo) +{ +struct amdgpu_vm *vm = vm_bo->vm; + +spin_lock (&vm->moved_lock); +list_move (&vm_bo->vm_status, &vm->moved); +spin_unlock (&vm->moved_lock);If
vm->moved_lockprotects the moved list, do we also need to take it whenever something is moved from that list?
Correct, yes.
Quoted 87 lines
That could potentially be
anylist_moveoperation that usesvm_bo->vm_status. I found one case below where that may not be handled correctly.Quoted 83 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +23
-11+} + +/** +* amdgpu_vm_bo_idle - vm_bo is idle +* +* @vm_bo: vm_bo which is now idle +* +* State for PDs/PTs and per VM BOs which have gone through the state machine +* and are now idle. +*/ +static void amdgpu_vm_bo_idle (struct amdgpu_vm_bo_base *vm_bo) +{ +list_move (&vm_bo->vm_status, &vm_bo->vm->idle); + vm_bo->moved = false; +} +/** * amdgpu_vm_bo_base_init - Adds bo to the list of bos associated with the vm * @@ -232,9 +295,9 @@ static void amdgpu_vm_bo_base_init(struct amdgpu_vm_bo_base *base, vm->bulk_moveable = false;if (bo->tbo.type == ttm_bo_type_kernel) -list_move (&base->vm_status, &vm->relocated); +amdgpu_vm_bo_relocated (base);else -list_move (&base->vm_status, &vm->idle); +amdgpu_vm_bo_idle (base);if (bo->preferred_domains &amdgpu_mem_type_to_domain (bo->tbo.mem.mem_type))@@ -245,8 +308,7 @@ static void amdgpu_vm_bo_base_init(struct amdgpu_vm_bo_base *base,* is currently evicted. add the bo to the evicted list to make sure it * is validated on next vm use to avoid fault. * */ -list_move_tail (&base->vm_status, &vm->evicted); - base->moved = true; +amdgpu_vm_bo_evicted (base); }/** @@ -342,9 +404,7 @@ int amdgpu_vm_validate_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm,break ;if (bo->tbo.type != ttm_bo_type_kernel) { -spin_lock (&vm->moved_lock); -list_move (&bo_base->vm_status, &vm->moved); -spin_unlock (&vm->moved_lock); +amdgpu_vm_bo_moved (bo_base); }else {if (vm->use_cpu_for_update) r =amdgpu_bo_kmap (bo,NULL );@@ -352,7 +412,7 @@ int amdgpu_vm_validate_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm, r =amdgpu_ttm_alloc_gart (&bo->tbo);if (r)break ; -list_move (&bo_base->vm_status, &vm->relocated); +amdgpu_vm_bo_relocated (bo_base); } }@@ -1123,8 +1183,7 @@ int amdgpu_vm_update_directories(struct amdgpu_device *adev, bo_base =list_first_entry (&vm->relocated, struct amdgpu_vm_bo_base, vm_status); - bo_base->moved = false; -list_move (&bo_base->vm_status, &vm->idle); +amdgpu_vm_bo_idle (bo_base); bo = bo_base->bo->parent;if (!bo)@@ -1243,7 +1302,7 @@ static void amdgpu_vm_handle_huge_pages(struct amdgpu_pte_update_params *p,if (entry->huge) {/* Add the entry to the relocated list to update it. */ entry->huge = false; -list_move (&entry->base.vm_status, &p->vm->relocated); +amdgpu_vm_bo_relocated (&entry->base); }return ; }@@ -1746,9 +1805,9 @@ int amdgpu_vm_bo_update(struct amdgpu_device *adev,uint32_t mem_type = bo->tbo.mem.mem_type;
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c int amdgpu_vm_bo_update(struct amdgpu_device *adev, · line 1810
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2
-2if (!(bo->preferred_domains &amdgpu_mem_type_to_domain (mem_type))) -list_add_tail (&bo_va->base.vm_status, &vm->evicted); +amdgpu_vm_bo_evicted (&bo_va->base);else -list_add (&bo_va->base.vm_status, &vm->idle); +amdgpu_vm_bo_idle (&bo_va->base);There is a small change in behaviour here for clearing
bo_va->base.moved. Not sure if it matters.
Using list_add is minimal more efficient.
Quoted 10 lines
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0
-1}list_splice_init (&bo_va->invalids, &bo_va->valids);@@ -2472,28 +2531,20 @@ void amdgpu_vm_bo_invalidate(struct amdgpu_device *adev,list_for_each_entry (bo_base, &bo->va, bo_list) {struct amdgpu_vm *vm = bo_base->vm; -bool was_moved = bo_base->moved;
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c void amdgpu_vm_bo_invalidate(struct amdgpu_device *adev, · line 2536
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1
-6- bo_base->moved = true;if (evicted && bo->tbo.resv == vm->root.base.bo->tbo.resv) { -if (bo->tbo.type == ttm_bo_type_kernel) -list_move (&bo_base->vm_status, &vm->evicted); -else -list_move_tail (&bo_base->vm_status, - &vm->evicted); +amdgpu_vm_bo_evicted (bo_base);I think here it's possible that the BO was on the moved list. I think that means
amdgpu_vm_bo_evictedshould take themoved_lockjust in case.
Good point, probably best if I split up the moved list into per VM BOs and all other BOs.
That should make the locking much more clear.
Regards,
Christian.
Quoted 26 lines
Regards,
FelixQuoted 22 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +6
-8continue ; } -if (was_moved) +if (bo_base->moved)continue ; -if (bo->tbo.type == ttm_bo_type_kernel) { -list_move (&bo_base->vm_status, &vm->relocated); - }else { -spin_lock (&bo_base->vm->moved_lock); -list_move (&bo_base->vm_status, &vm->moved); -spin_unlock (&bo_base->vm->moved_lock); - } + bo_base->moved = true; +if (bo->tbo.type == ttm_bo_type_kernel) +amdgpu_vm_bo_relocated (bo_base); +else +amdgpu_vm_bo_moved (bo_base); } }
_______________________________________________
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): DM5PR12MB170702D12F63415DA2979AEB920E0-2J9CzHegvk9TCtO+SvGBKwdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org
Re: [PATCH 2/2] drm/amdgpu: improve VM state machine documentation
Am 01.09.2018 um 18:45 schrieb Kuehling, Felix:
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Review int amdgpu_vm_bo_update(struct amdgpu_device *adev, · line 1810
Quoted 9 lines
(quoted diff) +2
-2@@ -1746,9 +1805,9 @@ int amdgpu_vm_bo_update(struct amdgpu_device *adev, uint32_t mem_type = bo->tbo.mem.mem_type; if (!(bo->preferred_domains & amdgpu_mem_type_to_domain(mem_type))) - list_add_tail(&bo_va->base.vm_status, &vm->evicted); + amdgpu_vm_bo_evicted(&bo_va->base); else - list_add(&bo_va->base.vm_status, &vm->idle); + amdgpu_vm_bo_idle(&bo_va->base);There is a small change in behaviour here for clearing
bo_va->base.moved. Not sure if it matters.
Quoted 2 lines
Quoted 1 line
Using
list_addis minimal more efficient.What I meant was that the original code would not always set
bo_va->base.moved= false (it's done a few lines above this under some conditions, but not always). The new code will always setbo_va->base.moved= false insideamdgpu_vm_bo_idle.
Good point as well, but that is indeed correct.
Regards,
Christian.
Quoted 206 lines
Regards,
Felix________________________________________
From: Christian König <[email protected]>
Sent: Saturday, September 1, 2018 4:16:17 AM
To: Kuehling, Felix; [email protected]
Subject: Re: [PATCH 2/2] drm/amdgpu: improve VM state machine documentationAm 01.09.2018 um 01:51 schrieb Felix Kuehling:
Quoted 53 lines
Thanks for this. A few comments and a question inline.
Quoted 50 lines · Christian König
Since we have a lot of FAQ on the VM state machine try to improve the documentation by adding functions for each state move.
Signed-off-by Christian König <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 107 ++++++++++++++++++++++++--------- 1 file changed, 79 insertions(+), 28 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +34
-0@@ -204,6 +204,69 @@ static unsigned amdgpu_vm_bo_size(struct amdgpu_device *adev, unsigned level)return AMDGPU_GPU_PAGE_ALIGN (amdgpu_vm_num_entries (adev, level) *8 ); } +/** +* amdgpu_vm_bo_evicted - vm_bo is evicted +* +* @vm_bo: vm_bo which is evicted +* +* State for PDs/PTs and per VM BOs which are not at the location they should +* be. +*/ +static void amdgpu_vm_bo_evicted (struct amdgpu_vm_bo_base *vm_bo) +{ +struct amdgpu_vm *vm = vm_bo->vm; +struct amdgpu_bo *bo = vm_bo->bo; + + vm_bo->moved = true; +if (bo->tbo.type == ttm_bo_type_kernel) +list_move (&vm_bo->vm_status, &vm->evicted); +else +list_move_tail (&vm_bo->vm_status, &vm->evicted); +} + +/** +* amdgpu_vm_bo_relocated - vm_bo is reloacted +* +* @vm_bo: vm_bo which is relocated +* +* State for PDs/PTs which needs to update their parent PD. +*/ +static void amdgpu_vm_bo_relocated (struct amdgpu_vm_bo_base *vm_bo) +{ +list_move (&vm_bo->vm_status, &vm_bo->vm->relocated); +} + +/** +* amdgpu_vm_bo_moved - vm_bo is moved Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c static unsigned amdgpu_vm_bo_size(struct amdgpu_device *adev, unsigned level) · line 245
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +5
-0+* +* @vm_bo: vm_bo which is moved +* +* State for per VM and normal BOs which are moved, but that change is not yet +* reflected in the page tables. I have a question here. Why does
amdgpu_cs_vm_handlingcallamdgpu_vm_bo_updatemanually for its BO list entries? Wouldn't it be enough to just callamdgpu_vm_handle_moved?No, it is still possible that the mapping of the BO was never updated because the VM page tables where evicted.
We still need to make sure that all BOs of the current submission are updated correctly.
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c static unsigned amdgpu_vm_bo_size(struct amdgpu_device *adev, unsigned level) · line 253
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +8
-0+*/ +static void amdgpu_vm_bo_moved (struct amdgpu_vm_bo_base *vm_bo) +{ +struct amdgpu_vm *vm = vm_bo->vm; + +spin_lock (&vm->moved_lock); +list_move (&vm_bo->vm_status, &vm->moved); +spin_unlock (&vm->moved_lock);If
vm->moved_lockprotects the moved list, do we also need to take it whenever something is moved from that list?Correct, yes.
Quoted 87 lines
That could potentially be
anylist_moveoperation that usesvm_bo->vm_status. I found one case below where that may not be handled correctly.Quoted 83 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +23
-11+} + +/** +* amdgpu_vm_bo_idle - vm_bo is idle +* +* @vm_bo: vm_bo which is now idle +* +* State for PDs/PTs and per VM BOs which have gone through the state machine +* and are now idle. +*/ +static void amdgpu_vm_bo_idle (struct amdgpu_vm_bo_base *vm_bo) +{ +list_move (&vm_bo->vm_status, &vm_bo->vm->idle); + vm_bo->moved = false; +} +/** * amdgpu_vm_bo_base_init - Adds bo to the list of bos associated with the vm * @@ -232,9 +295,9 @@ static void amdgpu_vm_bo_base_init(struct amdgpu_vm_bo_base *base, vm->bulk_moveable = false;if (bo->tbo.type == ttm_bo_type_kernel) -list_move (&base->vm_status, &vm->relocated); +amdgpu_vm_bo_relocated (base);else -list_move (&base->vm_status, &vm->idle); +amdgpu_vm_bo_idle (base);if (bo->preferred_domains &amdgpu_mem_type_to_domain (bo->tbo.mem.mem_type))@@ -245,8 +308,7 @@ static void amdgpu_vm_bo_base_init(struct amdgpu_vm_bo_base *base,* is currently evicted. add the bo to the evicted list to make sure it * is validated on next vm use to avoid fault. * */ -list_move_tail (&base->vm_status, &vm->evicted); - base->moved = true; +amdgpu_vm_bo_evicted (base); }/** @@ -342,9 +404,7 @@ int amdgpu_vm_validate_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm,break ;if (bo->tbo.type != ttm_bo_type_kernel) { -spin_lock (&vm->moved_lock); -list_move (&bo_base->vm_status, &vm->moved); -spin_unlock (&vm->moved_lock); +amdgpu_vm_bo_moved (bo_base); }else {if (vm->use_cpu_for_update) r =amdgpu_bo_kmap (bo,NULL );@@ -352,7 +412,7 @@ int amdgpu_vm_validate_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm, r =amdgpu_ttm_alloc_gart (&bo->tbo);if (r)break ; -list_move (&bo_base->vm_status, &vm->relocated); +amdgpu_vm_bo_relocated (bo_base); } }@@ -1123,8 +1183,7 @@ int amdgpu_vm_update_directories(struct amdgpu_device *adev, bo_base =list_first_entry (&vm->relocated, struct amdgpu_vm_bo_base, vm_status); - bo_base->moved = false; -list_move (&bo_base->vm_status, &vm->idle); +amdgpu_vm_bo_idle (bo_base); bo = bo_base->bo->parent;if (!bo)@@ -1243,7 +1302,7 @@ static void amdgpu_vm_handle_huge_pages(struct amdgpu_pte_update_params *p,if (entry->huge) {/* Add the entry to the relocated list to update it. */ entry->huge = false; -list_move (&entry->base.vm_status, &p->vm->relocated); +amdgpu_vm_bo_relocated (&entry->base); }return ; }@@ -1746,9 +1805,9 @@ int amdgpu_vm_bo_update(struct amdgpu_device *adev,uint32_t mem_type = bo->tbo.mem.mem_type;Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c int amdgpu_vm_bo_update(struct amdgpu_device *adev, · line 1810
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2
-2if (!(bo->preferred_domains &amdgpu_mem_type_to_domain (mem_type))) -list_add_tail (&bo_va->base.vm_status, &vm->evicted); +amdgpu_vm_bo_evicted (&bo_va->base);else -list_add (&bo_va->base.vm_status, &vm->idle); +amdgpu_vm_bo_idle (&bo_va->base);There is a small change in behaviour here for clearing
bo_va->base.moved. Not sure if it matters.Using
list_addis minimal more efficient.Quoted 9 lines
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0
-1}list_splice_init (&bo_va->invalids, &bo_va->valids);@@ -2472,28 +2531,20 @@ void amdgpu_vm_bo_invalidate(struct amdgpu_device *adev,list_for_each_entry (bo_base, &bo->va, bo_list) {struct amdgpu_vm *vm = bo_base->vm; -bool was_moved = bo_base->moved;Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c void amdgpu_vm_bo_invalidate(struct amdgpu_device *adev, · line 2536
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1
-6- bo_base->moved = true;if (evicted && bo->tbo.resv == vm->root.base.bo->tbo.resv) { -if (bo->tbo.type == ttm_bo_type_kernel) -list_move (&bo_base->vm_status, &vm->evicted); -else -list_move_tail (&bo_base->vm_status, - &vm->evicted); +amdgpu_vm_bo_evicted (bo_base);I think here it's possible that the BO was on the moved list. I think that means
amdgpu_vm_bo_evictedshould take themoved_lockjust in case.
Quoted 33 lines
Good point, probably best if I split up the moved list into per VM BOs and all other BOs.
That should make the locking much more clear.
Regards,
Christian.Quoted 25 lines
Regards,
FelixQuoted 22 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +6
-8continue ; } -if (was_moved) +if (bo_base->moved)continue ; -if (bo->tbo.type == ttm_bo_type_kernel) { -list_move (&bo_base->vm_status, &vm->relocated); - }else { -spin_lock (&bo_base->vm->moved_lock); -list_move (&bo_base->vm_status, &vm->moved); -spin_unlock (&bo_base->vm->moved_lock); - } + bo_base->moved = true; +if (bo->tbo.type == ttm_bo_type_kernel) +amdgpu_vm_bo_relocated (bo_base); +else +amdgpu_vm_bo_moved (bo_base); } }
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Zhang, Jerry (Junwei)
Reviewed-by Junwei ZhangQuoted 3 lines · Christian König
amdgpu_vm_bo_* functions should come much later.
Signed-off-by Christian König <[email protected]>
Quoted 103 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 90 +++++++++++++++++----------------- 1 file changed, 45 insertions(+), 45 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +38
-45@@ -133,51 +133,6 @@ struct amdgpu_prt_cb {struct dma_fence_cb cb; }; -/** -* amdgpu_vm_bo_base_init - Adds bo to the list of bos associated with the vm -* -* @base: base structure for tracking BO usage in a VM -* @vm: vm to which bo is to be added -* @bo: amdgpu buffer object -* -* Initialize a bo_va_base structure and add it to the appropriate lists -* -*/ -static void amdgpu_vm_bo_base_init (struct amdgpu_vm_bo_base *base, -struct amdgpu_vm *vm, -struct amdgpu_bo *bo) -{ - base->vm = vm; - base->bo = bo; -INIT_LIST_HEAD (&base->bo_list); -INIT_LIST_HEAD (&base->vm_status); - -if (!bo) -return ; -list_add_tail (&base->bo_list, &bo->va); - -if (bo->tbo.resv != vm->root.base.bo->tbo.resv) -return ; - - vm->bulk_moveable = false; -if (bo->tbo.type == ttm_bo_type_kernel) -list_move (&base->vm_status, &vm->relocated); -else -list_move (&base->vm_status, &vm->idle); - -if (bo->preferred_domains & -amdgpu_mem_type_to_domain (bo->tbo.mem.mem_type)) -return ; - -/* -* we checked all the prerequisites, but it looks like this per vm bo -* is currently evicted. add the bo to the evicted list to make sure it -* is validated on next vm use to avoid fault. -* */ -list_move_tail (&base->vm_status, &vm->evicted); - base->moved = true; -} -/** * amdgpu_vm_level_shift - return the addr shift for each level * @@ -249,6 +204,51 @@ static unsigned amdgpu_vm_bo_size(struct amdgpu_device *adev, unsigned level)return AMDGPU_GPU_PAGE_ALIGN (amdgpu_vm_num_entries (adev, level) *8 ); } +/** +* amdgpu_vm_bo_base_init - Adds bo to the list of bos associated with the vm +* +* @base: base structure for tracking BO usage in a VM +* @vm: vm to which bo is to be added +* @bo: amdgpu buffer object +* +* Initialize a bo_va_base structure and add it to the appropriate lists +* +*/ +static void amdgpu_vm_bo_base_init (struct amdgpu_vm_bo_base *base, +struct amdgpu_vm *vm, +struct amdgpu_bo *bo) +{ + base->vm = vm; + base->bo = bo; +INIT_LIST_HEAD (&base->bo_list); +INIT_LIST_HEAD (&base->vm_status); + +if (!bo) +return ; +list_add_tail (&base->bo_list, &bo->va); + +if (bo->tbo.resv != vm->root.base.bo->tbo.resv) +return ; + + vm->bulk_moveable = false; +if (bo->tbo.type == ttm_bo_type_kernel) +list_move (&base->vm_status, &vm->relocated); +else +list_move (&base->vm_status, &vm->idle); + +if (bo->preferred_domains & +amdgpu_mem_type_to_domain (bo->tbo.mem.mem_type)) +return ; + +/* +* we checked all the prerequisites, but it looks like this per vm bo
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c static unsigned amdgpu_vm_bo_size(struct amdgpu_device *adev, unsigned level) · line 254
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +7
-0+* is currently evicted. add the bo to the evicted list to make sure it +* is validated on next vm use to avoid fault. +* */ +list_move_tail (&base->vm_status, &vm->evicted); + base->moved = true; +} +/** * amdgpu_vm_get_pd_bo - add the VM PD to a validation list *
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx