drm/amdgpu: add amdgpu_bo_vm bo type
Subsystems (2)
PATCH 1/5 drm/amdgpu: add amdgpu_bo_vm bo type
Add new BO subclass that will be used by amdgpu vm code.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 32 ++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | 10 +++++++ 2 files changed, 42 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +32 -0
@@ -694,6 +694,38 @@ int amdgpu_bo_create_user(struct amdgpu_device *adev, *ubo_ptr =to_amdgpu_bo_user (bo_ptr);return r; } + +/** +* amdgpu_bo_create_vm - create an &amdgpu_bo_vm buffer object +* @adev: amdgpu device object +* @bp: parameters to be used for the buffer object +* @vmbo_ptr: pointer to the buffer object pointer +* +* Create a BO to be for GPUVM. +* +* Returns: +* 0 for success or a negative error code on failure. +*/ + +int amdgpu_bo_create_vm (struct amdgpu_device *adev, +struct amdgpu_bo_param *bp, +struct amdgpu_bo_vm **vmbo_ptr) +{ +struct amdgpu_bo *bo_ptr; +int r; + +/* bo_ptr_size will be determined by the caller and it depends on +* num of amdgpu_vm_pt entries. +*/ +BUG_ON (bp->bo_ptr_size <sizeof (struct amdgpu_bo_vm )); + r =amdgpu_bo_create (adev, bp, &bo_ptr); +if (r) +return r; + + *vmbo_ptr =to_amdgpu_bo_vm (bo_ptr); +return r; +} +/** * amdgpu_bo_validate - validate an &amdgpu_bo buffer object * @bo: pointer to the buffer object
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +10 -0
@@ -44,6 +44,7 @@#define AMDGPU_AMDKFD_CREATE_SVM_BO (1ULL << 62)#define to_amdgpu_bo_user (abo) container_of((abo), struct amdgpu_bo_user, bo) +#define to_amdgpu_bo_vm (abo) container_of((abo), struct amdgpu_bo_vm, bo)struct amdgpu_bo_param {unsigned long size;
@@ -125,6 +126,12 @@ struct amdgpu_bo_user { }; +struct amdgpu_bo_vm { +struct amdgpu_bo bo; +struct amdgpu_bo *shadow; +struct amdgpu_vm_pt entries[]; +}; +static inline struct amdgpu_bo *ttm_to_amdgpu_bo (struct ttm_buffer_object *tbo) { return container_of(tbo, struct amdgpu_bo, tbo);
@@ -272,6 +279,9 @@ int amdgpu_bo_create_kernel_at(struct amdgpu_device *adev,int amdgpu_bo_create_user (struct amdgpu_device *adev,struct amdgpu_bo_param *bp,struct amdgpu_bo_user **ubo_ptr); +int amdgpu_bo_create_vm (struct amdgpu_device *adev, +struct amdgpu_bo_param *bp, +struct amdgpu_bo_vm **ubo_ptr);void amdgpu_bo_free_kernel (struct amdgpu_bo **bo,u64 *gpu_addr,void **cpu_addr); int amdgpu_bo_create_shadow(struct amdgpu_device *adev,
Signature · 6 lines
2.31.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH v2 2/5 drm/amdgpu: move shadow bo validation to VM code
Do the shadow bo validation in the VM code as
VM code knows/owns shadow BOs.
v2: Fix a typo.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 23 ++++------------------- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 5 +++++ 2 files changed, 9 insertions(+), 19 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +4 -19
@@ -396,10 +396,10 @@ void amdgpu_cs_report_moved_bytes(struct amdgpu_device *adev, u64 num_bytes,spin_unlock (&adev->mm_stats.lock); } -static int amdgpu_cs_bo_validate (struct amdgpu_cs_parser *p, -struct amdgpu_bo *bo) +static int amdgpu_cs_bo_validate (void *param,struct amdgpu_bo *bo) {struct amdgpu_device *adev =amdgpu_ttm_adev (bo->tbo.bdev); +struct amdgpu_cs_parser *p = param;struct ttm_operation_ctx ctx = { .interruptible = true, .no_wait_gpu = false,
@@ -451,21 +451,6 @@ static int amdgpu_cs_bo_validate(struct amdgpu_cs_parser *p,return r; } -static int amdgpu_cs_validate (void *param,struct amdgpu_bo *bo) -{ -struct amdgpu_cs_parser *p = param; -int r; - - r =amdgpu_cs_bo_validate (p, bo); -if (r) -return r; - -if (bo->shadow) - r =amdgpu_cs_bo_validate (p, bo->shadow); - -return r; -} -static int amdgpu_cs_list_validate (struct amdgpu_cs_parser *p,struct list_head *validated) {
@@ -493,7 +478,7 @@ static int amdgpu_cs_list_validate(struct amdgpu_cs_parser *p, lobj->user_pages); } - r =amdgpu_cs_validate (p, bo); + r =amdgpu_cs_bo_validate (p, bo);if (r)return r;
@@ -593,7 +578,7 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p, p->bytes_moved_vis =0 ; r =amdgpu_vm_validate_pt_bos (p->adev, &fpriv->vm, - amdgpu_cs_validate, p); + amdgpu_cs_bo_validate, p);if (r) {DRM_ERROR ("amdgpu_vm_validate_pt_bos() failed.\n" ); goto error_validate;
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +5 -0
@@ -696,6 +696,11 @@ int amdgpu_vm_validate_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm, r =validate (param, bo);if (r)return r; +if (bo->shadow) { + r =validate (param, bo->shadow); +if (r) +return r; + }if (bo->tbo.type != ttm_bo_type_kernel) {amdgpu_vm_bo_moved (bo_base);
--
2.31.1
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Re: [PATCH v2 2/5] drm/amdgpu: move shadow bo validation to VM code
Am 26.05.21 um 15:06 schrieb Nirmoy Das:
Quoted 6 lines
Do the shadow bo validation in the VM code as
VM code knows/owns shadow BOs.v2: Fix a typo.
Signed-off-by Nirmoy Das <[email protected]>
Quoted 79 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 23 ++++------------------- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 5 +++++ 2 files changed, 9 insertions(+), 19 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +4
-19@@ -396,10 +396,10 @@ void amdgpu_cs_report_moved_bytes(struct amdgpu_device *adev, u64 num_bytes,spin_unlock (&adev->mm_stats.lock); } -static int amdgpu_cs_bo_validate (struct amdgpu_cs_parser *p, -struct amdgpu_bo *bo) +static int amdgpu_cs_bo_validate (void *param,struct amdgpu_bo *bo) {struct amdgpu_device *adev =amdgpu_ttm_adev (bo->tbo.bdev); +struct amdgpu_cs_parser *p = param;struct ttm_operation_ctx ctx = { .interruptible = true, .no_wait_gpu = false,@@ -451,21 +451,6 @@ static int amdgpu_cs_bo_validate(struct amdgpu_cs_parser *p,return r; } -static int amdgpu_cs_validate (void *param,struct amdgpu_bo *bo) -{ -struct amdgpu_cs_parser *p = param; -int r; - - r =amdgpu_cs_bo_validate (p, bo); -if (r) -return r; - -if (bo->shadow) - r =amdgpu_cs_bo_validate (p, bo->shadow); - -return r; -} -static int amdgpu_cs_list_validate (struct amdgpu_cs_parser *p,struct list_head *validated) {@@ -493,7 +478,7 @@ static int amdgpu_cs_list_validate(struct amdgpu_cs_parser *p, lobj->user_pages); } - r =amdgpu_cs_validate (p, bo); + r =amdgpu_cs_bo_validate (p, bo);if (r)return r;@@ -593,7 +578,7 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p, p->bytes_moved_vis =0 ; r =amdgpu_vm_validate_pt_bos (p->adev, &fpriv->vm, - amdgpu_cs_validate, p); + amdgpu_cs_bo_validate, p);if (r) {DRM_ERROR ("amdgpu_vm_validate_pt_bos() failed.\n" ); goto error_validate;drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +5
-1@@ -696,6 +696,11 @@ int amdgpu_vm_validate_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm, r =validate (param, bo);if (r)return r; +if (bo->shadow) { + r =validate (param, bo->shadow); +if (r) +return r; + }if (bo->tbo.type != ttm_bo_type_kernel) {amdgpu_vm_bo_moved (bo_base); --
Quoted 2 lines
2.31.1
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH v2 3/5 drm/amdgpu: switch to amdgpu_bo_vm for vm code
In reply to Nirmoy DasThe subclass, amdgpu_bo_vm is intended for PT/PD BOs which are also shadowed, so switch to amdgpu_bo_vm BO for PT/PD BOs.
v2: squash three related patches.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 90 +++++++++++++-------- drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c | 16 ++-- 2 files changed, 67 insertions(+), 39 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +58 -32
@@ -658,9 +658,9 @@ void amdgpu_vm_move_to_lru_tail(struct amdgpu_device *adev,ttm_bo_move_to_lru_tail (&bo->tbo, &bo->tbo.mem, &vm->lru_bulk_move); -if (bo->shadow) -ttm_bo_move_to_lru_tail (&bo->shadow->tbo, - &bo->shadow->tbo.mem, +if (bo->tbo.type == ttm_bo_type_kernel) +ttm_bo_move_to_lru_tail (&to_amdgpu_bo_vm (bo)->shadow->tbo, + &to_amdgpu_bo_vm (bo)->shadow->tbo.mem, &vm->lru_bulk_move); }spin_unlock (&adev->mman.bdev.lru_lock);
@@ -696,8 +696,8 @@ int amdgpu_vm_validate_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm, r =validate (param, bo);if (r)return r; -if (bo->shadow) { - r =validate (param, bo->shadow); +if (bo->tbo.type == ttm_bo_type_kernel) { + r =validate (param,to_amdgpu_bo_vm (bo)->shadow);if (r)return r; }
@@ -793,8 +793,9 @@ static int amdgpu_vm_clear_bo(struct amdgpu_device *adev,if (r)return r; -if (bo->shadow) { - r =ttm_bo_validate (&bo->shadow->tbo, &bo->shadow->placement, +if (bo->tbo.type == ttm_bo_type_kernel) { + r =ttm_bo_validate (&to_amdgpu_bo_vm (bo)->shadow->tbo, + &to_amdgpu_bo_vm (bo)->shadow->placement, &ctx);if (r)return r;
@@ -863,14 +864,17 @@ static int amdgpu_vm_clear_bo(struct amdgpu_device *adev,* @vm: requesting vm * @level: the page table level * @immediate: use a immediate update -* @bo: pointer to the buffer object pointer +* @vmbo: pointer to the buffer object pointer */ static int amdgpu_vm_pt_create (struct amdgpu_device *adev,struct amdgpu_vm *vm,int level,bool immediate, -struct amdgpu_bo **bo) +struct amdgpu_bo_vm **vmbo) {struct amdgpu_bo_param bp; +struct amdgpu_bo *bo; +struct amdgpu_bo *shadow_bo; +struct dma_resv *resv;int r;memset (&bp,0 ,sizeof (bp));
@@ -881,7 +885,7 @@ static int amdgpu_vm_pt_create(struct amdgpu_device *adev, bp.domain =amdgpu_bo_get_preferred_pin_domain (adev, bp.domain); bp.flags =AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS |AMDGPU_GEM_CREATE_CPU_GTT_USWC ; - bp.bo_ptr_size =sizeof (struct amdgpu_bo ); + bp.bo_ptr_size =sizeof (struct amdgpu_bo_vm );if (vm->use_cpu_for_update) bp.flags |=AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED ;
@@ -890,26 +894,43 @@ static int amdgpu_vm_pt_create(struct amdgpu_device *adev,if (vm->root.base.bo) bp.resv = vm->root.base.bo->tbo.base.resv; - r =amdgpu_bo_create (adev, &bp, bo); + r =amdgpu_bo_create_vm (adev, &bp, vmbo);if (r)return r; + bo = &(*vmbo)->bo;if (vm->is_compute_context && (adev->flags &AMD_IS_APU ))return 0 ;if (!bp.resv) -WARN_ON (dma_resv_lock ((*bo)->tbo.base.resv, +WARN_ON (dma_resv_lock (bo->tbo.base.resv,NULL )); - r =amdgpu_bo_create_shadow (adev, bp.size, *bo); + resv = bp.resv; +memset (&bp,0 ,sizeof (bp)); + bp.size =amdgpu_vm_bo_size (adev, level); + bp.domain =AMDGPU_GEM_DOMAIN_GTT ; + bp.flags =AMDGPU_GEM_CREATE_CPU_GTT_USWC ; + bp.type = ttm_bo_type_kernel; + bp.resv = bo->tbo.base.resv; + bp.bo_ptr_size =sizeof (struct amdgpu_bo ); -if (!bp.resv) -dma_resv_unlock ((*bo)->tbo.base.resv); + r =amdgpu_bo_create (adev, &bp, &shadow_bo); + + +if (!resv) +dma_resv_unlock (bo->tbo.base.resv);if (r) { -amdgpu_bo_unref (bo); +amdgpu_bo_unref (&bo);return r; } + shadow_bo->parent =amdgpu_bo_ref (bo); +mutex_lock (&adev->shadow_list_lock); +list_add_tail (&shadow_bo->shadow_list, &adev->shadow_list); +mutex_unlock (&adev->shadow_list_lock); + (*vmbo)->shadow = shadow_bo; +return 0 ; }
@@ -933,7 +954,8 @@ static int amdgpu_vm_alloc_pts(struct amdgpu_device *adev, bool immediate) {struct amdgpu_vm_pt *entry = cursor->entry; -struct amdgpu_bo *pt; +struct amdgpu_bo *pt_bo; +struct amdgpu_bo_vm *pt;int r;if (cursor->level <AMDGPU_VM_PTB && !entry->entries) {
@@ -957,10 +979,11 @@ static int amdgpu_vm_alloc_pts(struct amdgpu_device *adev,/* Keep a reference to the root directory to avoid * freeing them up in the wrong order. */ - pt->parent =amdgpu_bo_ref (cursor->parent->base.bo); -amdgpu_vm_bo_base_init (&entry->base, vm, pt); + pt_bo = &pt->bo; + pt_bo->parent =amdgpu_bo_ref (cursor->parent->base.bo); +amdgpu_vm_bo_base_init (&entry->base, vm, pt_bo); - r =amdgpu_vm_clear_bo (adev, vm, pt, immediate); + r =amdgpu_vm_clear_bo (adev, vm, pt_bo, immediate);if (r) goto error_free_pt;
@@ -968,7 +991,7 @@ static int amdgpu_vm_alloc_pts(struct amdgpu_device *adev, error_free_pt:amdgpu_bo_unref (&pt->shadow); -amdgpu_bo_unref (&pt); +amdgpu_bo_unref (&pt_bo);return r; }
@@ -982,7 +1005,8 @@ static void amdgpu_vm_free_table(struct amdgpu_vm_pt *entry)if (entry->base.bo) { entry->base.bo->vm_bo =NULL ;list_del (&entry->base.vm_status); -amdgpu_bo_unref (&entry->base.bo->shadow); +if (entry->base.bo->tbo.type == ttm_bo_type_kernel) +amdgpu_bo_unref (&to_amdgpu_bo_vm (entry->base.bo)->shadow);amdgpu_bo_unref (&entry->base.bo); }kvfree (entry->entries);
@@ -2674,7 +2698,8 @@ void amdgpu_vm_bo_invalidate(struct amdgpu_device *adev,struct amdgpu_vm_bo_base *bo_base;/* shadow bo doesn't have bo base, its validation needs its parent */ -if (bo->parent && bo->parent->shadow == bo) +if (bo->parent && bo->tbo.type == ttm_bo_type_kernel && +to_amdgpu_bo_vm (bo->parent)->shadow == bo) bo = bo->parent;for (bo_base = bo->vm_bo; bo_base; bo_base = bo_base->next) {
@@ -2843,7 +2868,8 @@ long amdgpu_vm_wait_idle(struct amdgpu_vm *vm, long timeout)*/ int amdgpu_vm_init (struct amdgpu_device *adev,struct amdgpu_vm *vm,u32 pasid) { -struct amdgpu_bo *root; +struct amdgpu_bo *root_bo; +struct amdgpu_bo_vm *root;int r, i; vm->va =RB_ROOT_CACHED ;
@@ -2897,18 +2923,18 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm, u32 pasid) false, &root);if (r) goto error_free_delayed; - - r =amdgpu_bo_reserve (root, true); + root_bo = &root->bo; + r =amdgpu_bo_reserve (root_bo, true);if (r) goto error_free_root; - r =dma_resv_reserve_shared (root->tbo.base.resv,1 ); + r =dma_resv_reserve_shared (root_bo->tbo.base.resv,1 );if (r) goto error_unreserve; -amdgpu_vm_bo_base_init (&vm->root.base, vm, root); +amdgpu_vm_bo_base_init (&vm->root.base, vm, root_bo); - r =amdgpu_vm_clear_bo (adev, vm, root, false); + r =amdgpu_vm_clear_bo (adev, vm, root_bo, false);if (r) goto error_unreserve;
@@ -2935,8 +2961,8 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm, u32 pasid)amdgpu_bo_unreserve (vm->root.base.bo); error_free_root: -amdgpu_bo_unref (&vm->root.base.bo->shadow); -amdgpu_bo_unref (&vm->root.base.bo); +amdgpu_bo_unref (&root->shadow); +amdgpu_bo_unref (&root_bo); vm->root.base.bo =NULL ; error_free_delayed:
@@ -3078,7 +3104,7 @@ int amdgpu_vm_make_compute(struct amdgpu_device *adev, struct amdgpu_vm *vm, }/* Free the shadow bo for compute VM */ -amdgpu_bo_unref (&vm->root.base.bo->shadow); +amdgpu_bo_unref (&to_amdgpu_bo_vm (vm->root.base.bo)->shadow);if (pasid) vm->pasid = pasid;
drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c +9 -7
@@ -41,8 +41,8 @@ static int amdgpu_vm_sdma_map_table(struct amdgpu_bo *table)if (r)return r; -if (table->shadow) - r =amdgpu_ttm_alloc_gart (&table->shadow->tbo); +if (table->tbo.type == ttm_bo_type_kernel) + r =amdgpu_ttm_alloc_gart (&to_amdgpu_bo_vm (table)->shadow->tbo);return r; }
@@ -238,8 +238,9 @@ static int amdgpu_vm_sdma_update(struct amdgpu_vm_update_params *p,if (!p->pages_addr) {/* set page commands needed */ -if (bo->shadow) -amdgpu_vm_sdma_set_ptes (p, bo->shadow, pe, addr, +if (bo->tbo.type == ttm_bo_type_kernel) +amdgpu_vm_sdma_set_ptes (p,to_amdgpu_bo_vm (bo)->shadow, + pe, addr, count, incr, flags);amdgpu_vm_sdma_set_ptes (p, bo, pe, addr, count, incr, flags);
@@ -248,7 +249,7 @@ static int amdgpu_vm_sdma_update(struct amdgpu_vm_update_params *p,/* copy commands needed */ ndw -= p->adev->vm_manager.vm_pte_funcs->copy_pte_num_dw * - (bo->shadow ?2 :1 ); + ((bo->tbo.type == ttm_bo_type_kernel) ?2 :1 );/* for padding */ ndw -=7 ;
@@ -263,8 +264,9 @@ static int amdgpu_vm_sdma_update(struct amdgpu_vm_update_params *p, pte[i] |= flags; } -if (bo->shadow) -amdgpu_vm_sdma_copy_ptes (p, bo->shadow, pe, nptes); +if (bo->tbo.type == ttm_bo_type_kernel) +amdgpu_vm_sdma_copy_ptes (p,to_amdgpu_bo_vm (bo)->shadow, + pe, nptes);amdgpu_vm_sdma_copy_ptes (p, bo, pe, nptes); pe += nptes *8 ;
--
2.31.1
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Christian König
maintainerRe: [PATCH v2 3/5] drm/amdgpu: switch to amdgpu_bo_vm for vm code
Am 26.05.21 um 15:06 schrieb Nirmoy Das:
Quoted 16 lines
The subclass,
amdgpu_bo_vmis intended for PT/PD BOs which are also shadowed, so switch toamdgpu_bo_vmBO for PT/PD BOs.v2: squash three related patches.
Signed-off-by Nirmoy Das <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 90 +++++++++++++-------- drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c | 16 ++-- 2 files changed, 67 insertions(+), 39 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0
-0
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c void amdgpu_vm_move_to_lru_tail(struct amdgpu_device *adev, · line 663
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +3
-3@@ -658,9 +658,9 @@ void amdgpu_vm_move_to_lru_tail(struct amdgpu_device *adev,ttm_bo_move_to_lru_tail (&bo->tbo, &bo->tbo.mem, &vm->lru_bulk_move); -if (bo->shadow) - ttm_bo_move_to_lru_tail(&bo->shadow->tbo, - &bo->shadow->tbo.mem, +if (bo->tbo.type == ttm_bo_type_kernel) + ttm_bo_move_to_lru_tail(&to_amdgpu_bo_vm(bo)->shadow->tbo, + &to_amdgpu_bo_vm(bo)->shadow->tbo.mem,
Maybe use a local variable for the shadow BO here.
Quoted 15 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2
-2&vm->lru_bulk_move); }spin_unlock (&adev->mman.bdev.lru_lock);@@ -696,8 +696,8 @@ int amdgpu_vm_validate_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm, r =validate (param, bo);if (r)return r; -if (bo->shadow) { - r =validate (param, bo->shadow); +if (bo->tbo.type == ttm_bo_type_kernel) { + r =validate (param,to_amdgpu_bo_vm (bo)->shadow);if (r)return r; }
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c static int amdgpu_vm_clear_bo(struct amdgpu_device *adev, · line 798
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +3
-2@@ -793,8 +793,9 @@ static int amdgpu_vm_clear_bo(struct amdgpu_device *adev,if (r)return r; -if (bo->shadow) { - r = ttm_bo_validate(&bo->shadow->tbo, &bo->shadow->placement, +if (bo->tbo.type == ttm_bo_type_kernel) { + r = ttm_bo_validate(&to_amdgpu_bo_vm(bo)->shadow->tbo, + &to_amdgpu_bo_vm(bo)->shadow->placement,
Same here.
Quoted 41 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +7
-4&ctx);if (r)return r;@@ -863,14 +864,17 @@ static int amdgpu_vm_clear_bo(struct amdgpu_device *adev,* @vm: requesting vm * @level: the page table level * @immediate: use a immediate update -* @bo: pointer to the buffer object pointer +* @vmbo: pointer to the buffer object pointer */ static int amdgpu_vm_pt_create (struct amdgpu_device *adev,struct amdgpu_vm *vm,int level,bool immediate, -struct amdgpu_bo **bo) +struct amdgpu_bo_vm **vmbo) {struct amdgpu_bo_param bp; +struct amdgpu_bo *bo; +struct amdgpu_bo *shadow_bo; +struct dma_resv *resv;int r;memset (&bp,0 ,sizeof (bp));@@ -881,7 +885,7 @@ static int amdgpu_vm_pt_create(struct amdgpu_device *adev, bp.domain =amdgpu_bo_get_preferred_pin_domain (adev, bp.domain); bp.flags =AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS |AMDGPU_GEM_CREATE_CPU_GTT_USWC ; - bp.bo_ptr_size =sizeof (struct amdgpu_bo ); + bp.bo_ptr_size =sizeof (struct amdgpu_bo_vm );if (vm->use_cpu_for_update) bp.flags |=AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED ;@@ -890,26 +894,43 @@ static int amdgpu_vm_pt_create(struct amdgpu_device *adev,if (vm->root.base.bo) bp.resv = vm->root.base.bo->tbo.base.resv; - r =amdgpu_bo_create (adev, &bp, bo); + r =amdgpu_bo_create_vm (adev, &bp, vmbo);if (r)return r;
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c static int amdgpu_vm_pt_create(struct amdgpu_device *adev, · line 908
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +3
-2+ bo = &(*vmbo)->bo;if (vm->is_compute_context && (adev->flags &AMD_IS_APU ))return 0 ;if (!bp.resv) -WARN_ON (dma_resv_lock ((*bo)->tbo.base.resv, +WARN_ON (dma_resv_lock (bo->tbo.base.resv,NULL )); - r =amdgpu_bo_create_shadow (adev, bp.size, *bo); + resv = bp.resv;
Maybe shuffle that code around a bit, then you only need the resv variable and no longer the bo variable.
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +4
-0+memset (&bp,0 ,sizeof (bp)); + bp.size =amdgpu_vm_bo_size (adev, level); + bp.domain =AMDGPU_GEM_DOMAIN_GTT ; + bp.flags =AMDGPU_GEM_CREATE_CPU_GTT_USWC ;
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c static int amdgpu_vm_pt_create(struct amdgpu_device *adev,
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +6
-2+ bp.type = ttm_bo_type_kernel; + bp.resv = bo->tbo.base.resv; + bp.bo_ptr_size =sizeof (struct amdgpu_bo ); -if (!bp.resv) -dma_resv_unlock ((*bo)->tbo.base.resv); + r =amdgpu_bo_create (adev, &bp, &shadow_bo); + +
Remove the two empty lines here
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2
-0+if (!resv) +dma_resv_unlock (bo->tbo.base.resv);if (r) {
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c static int amdgpu_vm_pt_create(struct amdgpu_device *adev, · line 932
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +6
-1-amdgpu_bo_unref (bo); +amdgpu_bo_unref (&bo);return r; } + shadow_bo->parent =amdgpu_bo_ref (bo); +mutex_lock (&adev->shadow_list_lock); +list_add_tail (&shadow_bo->shadow_list, &adev->shadow_list); +mutex_unlock (&adev->shadow_list_lock); + (*vmbo)->shadow = shadow_bo;
Ok, we should either move the shadow_list into the vm_mgr structure or keep that in the object code.
I think I prefer the later, something like amdgpu_bo_add_to_shadow_list().
Quoted 39 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +8
-5+return 0 ; }@@ -933,7 +954,8 @@ static int amdgpu_vm_alloc_pts(struct amdgpu_device *adev, bool immediate) {struct amdgpu_vm_pt *entry = cursor->entry; -struct amdgpu_bo *pt; +struct amdgpu_bo *pt_bo; +struct amdgpu_bo_vm *pt;int r;if (cursor->level <AMDGPU_VM_PTB && !entry->entries) {@@ -957,10 +979,11 @@ static int amdgpu_vm_alloc_pts(struct amdgpu_device *adev,/* Keep a reference to the root directory to avoid * freeing them up in the wrong order. */ - pt->parent =amdgpu_bo_ref (cursor->parent->base.bo); -amdgpu_vm_bo_base_init (&entry->base, vm, pt); + pt_bo = &pt->bo; + pt_bo->parent =amdgpu_bo_ref (cursor->parent->base.bo); +amdgpu_vm_bo_base_init (&entry->base, vm, pt_bo); - r =amdgpu_vm_clear_bo (adev, vm, pt, immediate); + r =amdgpu_vm_clear_bo (adev, vm, pt_bo, immediate);if (r) goto error_free_pt;@@ -968,7 +991,7 @@ static int amdgpu_vm_alloc_pts(struct amdgpu_device *adev, error_free_pt:amdgpu_bo_unref (&pt->shadow); -amdgpu_bo_unref (&pt); +amdgpu_bo_unref (&pt_bo);return r; }
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c static void amdgpu_vm_free_table(struct amdgpu_vm_pt *entry) · line 1008
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1
-1@@ -982,7 +1005,8 @@ static void amdgpu_vm_free_table(struct amdgpu_vm_pt *entry)if (entry->base.bo) { entry->base.bo->vm_bo =NULL ;list_del (&entry->base.vm_status); -amdgpu_bo_unref (&entry->base.bo->shadow); +if (entry->base.bo->tbo.type == ttm_bo_type_kernel)
That should always be true, otherwise we have a rather big bug.
So no need to check that here.
Quoted 73 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +13
-10+amdgpu_bo_unref (&to_amdgpu_bo_vm (entry->base.bo)->shadow);amdgpu_bo_unref (&entry->base.bo); }kvfree (entry->entries);@@ -2674,7 +2698,8 @@ void amdgpu_vm_bo_invalidate(struct amdgpu_device *adev,struct amdgpu_vm_bo_base *bo_base;/* shadow bo doesn't have bo base, its validation needs its parent */ -if (bo->parent && bo->parent->shadow == bo) +if (bo->parent && bo->tbo.type == ttm_bo_type_kernel && +to_amdgpu_bo_vm (bo->parent)->shadow == bo) bo = bo->parent;for (bo_base = bo->vm_bo; bo_base; bo_base = bo_base->next) {@@ -2843,7 +2868,8 @@ long amdgpu_vm_wait_idle(struct amdgpu_vm *vm, long timeout)*/ int amdgpu_vm_init (struct amdgpu_device *adev,struct amdgpu_vm *vm,u32 pasid) { -struct amdgpu_bo *root; +struct amdgpu_bo *root_bo; +struct amdgpu_bo_vm *root;int r, i; vm->va =RB_ROOT_CACHED ;@@ -2897,18 +2923,18 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm, u32 pasid) false, &root);if (r) goto error_free_delayed; - - r =amdgpu_bo_reserve (root, true); + root_bo = &root->bo; + r =amdgpu_bo_reserve (root_bo, true);if (r) goto error_free_root; - r =dma_resv_reserve_shared (root->tbo.base.resv,1 ); + r =dma_resv_reserve_shared (root_bo->tbo.base.resv,1 );if (r) goto error_unreserve; -amdgpu_vm_bo_base_init (&vm->root.base, vm, root); +amdgpu_vm_bo_base_init (&vm->root.base, vm, root_bo); - r =amdgpu_vm_clear_bo (adev, vm, root, false); + r =amdgpu_vm_clear_bo (adev, vm, root_bo, false);if (r) goto error_unreserve;@@ -2935,8 +2961,8 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm, u32 pasid)amdgpu_bo_unreserve (vm->root.base.bo); error_free_root: -amdgpu_bo_unref (&vm->root.base.bo->shadow); -amdgpu_bo_unref (&vm->root.base.bo); +amdgpu_bo_unref (&root->shadow); +amdgpu_bo_unref (&root_bo); vm->root.base.bo =NULL ; error_free_delayed:@@ -3078,7 +3104,7 @@ int amdgpu_vm_make_compute(struct amdgpu_device *adev, struct amdgpu_vm *vm, }/* Free the shadow bo for compute VM */ -amdgpu_bo_unref (&vm->root.base.bo->shadow); +amdgpu_bo_unref (&to_amdgpu_bo_vm (vm->root.base.bo)->shadow);if (pasid) vm->pasid = pasid;drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c +0
-0
drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c static int amdgpu_vm_sdma_map_table(struct amdgpu_bo *table) · line 44
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c +1
-2@@ -41,8 +41,8 @@ static int amdgpu_vm_sdma_map_table(struct amdgpu_bo *table)if (r)return r; -if (table->shadow) - r =amdgpu_ttm_alloc_gart (&table->shadow->tbo); +if (table->tbo.type == ttm_bo_type_kernel)
Again that check should be unecessary.
drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c static int amdgpu_vm_sdma_update(struct amdgpu_vm_update_params *p, · line 241
Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c +2
-2+ r =amdgpu_ttm_alloc_gart (&to_amdgpu_bo_vm (table)->shadow->tbo);return r; }@@ -238,8 +238,9 @@ static int amdgpu_vm_sdma_update(struct amdgpu_vm_update_params *p,if (!p->pages_addr) {/* set page commands needed */ -if (bo->shadow) - amdgpu_vm_sdma_set_ptes(p, bo->shadow, pe, addr, +if (bo->tbo.type == ttm_bo_type_kernel)
Same here.
drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c static int amdgpu_vm_sdma_update(struct amdgpu_vm_update_params *p, · line 252
Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c +3
-1+amdgpu_vm_sdma_set_ptes (p,to_amdgpu_bo_vm (bo)->shadow, + pe, addr, count, incr, flags);amdgpu_vm_sdma_set_ptes (p, bo, pe, addr, count, incr, flags);@@ -248,7 +249,7 @@ static int amdgpu_vm_sdma_update(struct amdgpu_vm_update_params *p,/* copy commands needed */ ndw -= p->adev->vm_manager.vm_pte_funcs->copy_pte_num_dw * - (bo->shadow ?2 :1 ); + ((bo->tbo.type == ttm_bo_type_kernel) ?2 :1 );
And that here won't work and allocate to much SDMA space.
drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c static int amdgpu_vm_sdma_update(struct amdgpu_vm_update_params *p, · line 267
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c +1
-2/* for padding */ ndw -=7 ;@@ -263,8 +264,9 @@ static int amdgpu_vm_sdma_update(struct amdgpu_vm_update_params *p, pte[i] |= flags; } -if (bo->shadow) -amdgpu_vm_sdma_copy_ptes (p, bo->shadow, pe, nptes); +if (bo->tbo.type == ttm_bo_type_kernel)
And that is wrong as well.
Christian.
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c +2
-1+amdgpu_vm_sdma_copy_ptes (p,to_amdgpu_bo_vm (bo)->shadow, + pe, nptes);amdgpu_vm_sdma_copy_ptes (p, bo, pe, nptes); pe += nptes *8 ; --2.31.1
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Re: [PATCH v2 3/5] drm/amdgpu: switch to amdgpu_bo_vm for vm code
Hi Christian,
Quoted 106 lines · Christian König
Am 26.05.21 um 15:06 schrieb Nirmoy Das:
Quoted 16 lines
The subclass,
amdgpu_bo_vmis intended for PT/PD BOs which are also shadowed, so switch toamdgpu_bo_vmBO for PT/PD BOs.v2: squash three related patches.
Signed-off-by Nirmoy Das <[email protected]>---
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 90 +++++++++++++--------drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c| 16 ++--2 files changed, 67 insertions(+), 39 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0
-0drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c void amdgpu_vm_move_to_lru_tail(struct · line 664
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +3
-3@@ -658,9 +658,9 @@ void amdgpu_vm_move_to_lru_tail(structamdgpu_device *adev, ttm_bo_move_to_lru_tail(&bo->tbo, &bo->tbo.mem, &vm->lru_bulk_move); - if (bo->shadow) - ttm_bo_move_to_lru_tail(&bo->shadow->tbo, - &bo->shadow->tbo.mem, + if (bo->tbo.type == ttm_bo_type_kernel) + ttm_bo_move_to_lru_tail(&to_amdgpu_bo_vm(bo)->shadow->tbo, + &to_amdgpu_bo_vm(bo)->shadow->tbo.mem,Maybe use a local variable for the shadow BO here.
Quoted 16 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0
-0&vm->lru_bulk_move); }
spin_unlock(&adev->mman.bdev.lru_lock);drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2
-2@@ -696,8 +696,8 @@ int amdgpu_vm_validate_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm, r = validate(param, bo); if (r) return r; - if (bo->shadow) { - r = validate(param, bo->shadow); + if (bo->tbo.type == ttm_bo_type_kernel) { + r = validate(param, to_amdgpu_bo_vm(bo)->shadow); if (r) return r;}
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c static int amdgpu_vm_clear_bo(struct · line 799
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +3
-2@@ -793,8 +793,9 @@ static int amdgpu_vm_clear_bo(structamdgpu_device *adev, if (r) return r; - if (bo->shadow) { - r = ttm_bo_validate(&bo->shadow->tbo, &bo->shadow->placement, + if (bo->tbo.type == ttm_bo_type_kernel) { + r = ttm_bo_validate(&to_amdgpu_bo_vm(bo)->shadow->tbo, + &to_amdgpu_bo_vm(bo)->shadow->placement,Same here.
Quoted 48 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0
-0&ctx); if (r)return r;
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +5
-2@@ -863,14 +864,17 @@ static int amdgpu_vm_clear_bo(structamdgpu_device *adev, * @vm: requesting vm * @level: the page table level * @immediate: use a immediate update -* @bo: pointer to the buffer object pointer +* @vmbo: pointer to the buffer object pointer */ static int amdgpu_vm_pt_create(struct amdgpu_device *adev, struct amdgpu_vm *vm, int level, bool immediate, - struct amdgpu_bo **bo) + struct amdgpu_bo_vm **vmbo) { struct amdgpu_bo_param bp; + struct amdgpu_bo *bo; + struct amdgpu_bo *shadow_bo; + struct dma_resv *resv; int r;
memset(&bp, 0, sizeof(bp));drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0
-0@@ -881,7 +885,7 @@ static int amdgpu_vm_pt_create(structamdgpu_device *adev, bp.domain = amdgpu_bo_get_preferred_pin_domain(adev, bp.domain);bp.flags =
AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS|AMDGPU_GEM_CREATE_CPU_GTT_USWC;
- bp.bo_ptr_size =sizeof(struct amdgpu_bo);
+ bp.bo_ptr_size =sizeof(struct amdgpu_bo_vm); if (vm->use_cpu_for_update)
bp.flags |=AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED;drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2
-1@@ -890,26 +894,43 @@ static int amdgpu_vm_pt_create(struct amdgpu_device *adev, if (vm->root.base.bo) bp.resv = vm->root.base.bo->tbo.base.resv; - r = amdgpu_bo_create(adev, &bp, bo); + r = amdgpu_bo_create_vm(adev, &bp, vmbo); if (r) return r; + bo = &(*vmbo)->bo; if (vm->is_compute_context && (adev->flags & AMD_IS_APU)) return 0;
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c static int amdgpu_vm_pt_create(struct amdgpu_device *adev, · line 908
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2
-2if (!bp.resv) - WARN_ON(dma_resv_lock((*bo)->tbo.base.resv, + WARN_ON(dma_resv_lock(bo->tbo.base.resv, NULL)); - r = amdgpu_bo_create_shadow(adev, bp.size, *bo); + resv = bp.resv;Maybe shuffle that code around a bit, then you only need the resv variable and no longer the bo variable.
I can remove the shadow_bo variable but I need the bo for amdgpu_bo_unref(), as this takes amdgpu_bo ** as argument.
Regards,
Nirmoy
Quoted 217 lines
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +4
-0+ memset(&bp, 0, sizeof(bp)); + bp.size = amdgpu_vm_bo_size(adev, level); + bp.domain = AMDGPU_GEM_DOMAIN_GTT; + bp.flags = AMDGPU_GEM_CREATE_CPU_GTT_USWC;drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c static int amdgpu_vm_pt_create(struct amdgpu_device *adev,
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +6
-2+ bp.type = ttm_bo_type_kernel; + bp.resv = bo->tbo.base.resv; + bp.bo_ptr_size = sizeof(struct amdgpu_bo); - if (!bp.resv) - dma_resv_unlock((*bo)->tbo.base.resv); + r = amdgpu_bo_create(adev, &bp, &shadow_bo); + +Remove the two empty lines here
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2
-0+ if (!resv) + dma_resv_unlock(bo->tbo.base.resv); if (r) {drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c static int amdgpu_vm_pt_create(struct amdgpu_device *adev, · line 932
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +6
-1- amdgpu_bo_unref(bo); + amdgpu_bo_unref(&bo); return r; } + shadow_bo->parent = amdgpu_bo_ref(bo); + mutex_lock(&adev->shadow_list_lock); + list_add_tail(&shadow_bo->shadow_list, &adev->shadow_list); + mutex_unlock(&adev->shadow_list_lock); + (*vmbo)->shadow = shadow_bo;Ok, we should either move the
shadow_listinto thevm_mgrstructure or keep that in the object code.I think I prefer the later, something like
amdgpu_bo_add_to_shadow_list().Quoted 42 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1
-0+ return 0;}
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2
-1@@ -933,7 +954,8 @@ static int amdgpu_vm_alloc_pts(structamdgpu_device *adev, bool immediate) { struct amdgpu_vm_pt *entry = cursor->entry; - struct amdgpu_bo *pt; + struct amdgpu_bo *pt_bo; + struct amdgpu_bo_vm *pt; int r;if (
cursor->level<AMDGPU_VM_PTB&& !entry->entries) {drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +4
-3@@ -957,10 +979,11 @@ static int amdgpu_vm_alloc_pts(structamdgpu_device *adev, /* Keep a reference to the root directory to avoid * freeing them up in the wrong order. */ - pt->parent = amdgpu_bo_ref(cursor->parent->base.bo); - amdgpu_vm_bo_base_init(&entry->base, vm, pt); + pt_bo = &pt->bo; + pt_bo->parent = amdgpu_bo_ref(cursor->parent->base.bo); + amdgpu_vm_bo_base_init(&entry->base, vm, pt_bo); - r = amdgpu_vm_clear_bo(adev, vm, pt, immediate); + r = amdgpu_vm_clear_bo(adev, vm, pt_bo, immediate); if (r) goto error_free_pt;@@ -968,7 +991,7 @@ static int amdgpu_vm_alloc_pts(struct amdgpu_device *adev,
error_free_pt:
amdgpu_bo_unref(&pt->shadow);
-amdgpu_bo_unref(&pt);
+amdgpu_bo_unref(&pt_bo);
return r;
}drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c static void amdgpu_vm_free_table(struct · line 1009
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1
-1@@ -982,7 +1005,8 @@ static void amdgpu_vm_free_table(struct amdgpu_vm_pt *entry) if (entry->base.bo) { entry->base.bo->vm_bo = NULL; list_del(&entry->base.vm_status); - amdgpu_bo_unref(&entry->base.bo->shadow); + if (entry->base.bo->tbo.type == ttm_bo_type_kernel)That should always be true, otherwise we have a rather big bug.
So no need to check that here.
Quoted 78 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1
-0+amdgpu_bo_unref (&to_amdgpu_bo_vm (entry->base.bo)->shadow); amdgpu_bo_unref(&entry->base.bo); }
kvfree(entry->entries);drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2
-1@@ -2674,7 +2698,8 @@ void amdgpu_vm_bo_invalidate(struct amdgpu_device *adev, struct amdgpu_vm_bo_base *bo_base; /* shadow bo doesn't have bo base, its validation needs its parent */ - if (bo->parent && bo->parent->shadow == bo) + if (bo->parent && bo->tbo.type == ttm_bo_type_kernel && + to_amdgpu_bo_vm(bo->parent)->shadow == bo) bo = bo->parent;for (
bo_base=bo->vm_bo;bo_base;bo_base=bo_base->next) {drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2
-1@@ -2843,7 +2868,8 @@ long amdgpu_vm_wait_idle(struct amdgpu_vm *vm,long timeout) */ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm, u32 pasid) { - struct amdgpu_bo *root; + struct amdgpu_bo *root_bo; + struct amdgpu_bo_vm *root; int r, i;
vm->va=RB_ROOT_CACHED;drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +5
-5@@ -2897,18 +2923,18 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm, u32 pasid) false, &root); if (r) goto error_free_delayed; - - r = amdgpu_bo_reserve(root, true); + root_bo = &root->bo; + r = amdgpu_bo_reserve(root_bo, true); if (r) goto error_free_root; - r = dma_resv_reserve_shared(root->tbo.base.resv, 1); + r = dma_resv_reserve_shared(root_bo->tbo.base.resv, 1); if (r) goto error_unreserve; - amdgpu_vm_bo_base_init(&vm->root.base, vm, root); + amdgpu_vm_bo_base_init(&vm->root.base, vm, root_bo); - r = amdgpu_vm_clear_bo(adev, vm, root, false); + r = amdgpu_vm_clear_bo(adev, vm, root_bo, false); if (r) goto error_unreserve;@@ -2935,8 +2961,8 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm, u32 pasid) amdgpu_bo_unreserve(vm->root.base.bo);
error_free_root:
-amdgpu_bo_unref(&vm->root.base.bo->shadow);
-amdgpu_bo_unref(&vm->root.base.bo);
+amdgpu_bo_unref(&root->shadow);
+amdgpu_bo_unref(&root_bo);
vm->root.base.bo= NULL;
error_free_delayed:drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1
-1@@ -3078,7 +3104,7 @@ int amdgpu_vm_make_compute(struct amdgpu_device *adev, struct amdgpu_vm *vm, } /* Free the shadow bo for compute VM */ - amdgpu_bo_unref(&vm->root.base.bo->shadow); +amdgpu_bo_unref (&to_amdgpu_bo_vm (vm->root.base.bo)->shadow); if (pasid)
vm->pasid= pasid;drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c +0
-0drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c static int amdgpu_vm_sdma_map_table(struct · line 45
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c +1
-2@@ -41,8 +41,8 @@ static int amdgpu_vm_sdma_map_table(struct amdgpu_bo *table) if (r) return r; - if (table->shadow) - r = amdgpu_ttm_alloc_gart(&table->shadow->tbo); + if (table->tbo.type == ttm_bo_type_kernel)Again that check should be unecessary.
drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c static int amdgpu_vm_sdma_update(struct · line 242
Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c +1
-0+ r =amdgpu_ttm_alloc_gart (&to_amdgpu_bo_vm (table)->shadow->tbo);return r;
}drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c +1
-2@@ -238,8 +238,9 @@ static int amdgpu_vm_sdma_update(struct amdgpu_vm_update_params *p, if (!p->pages_addr) { /* set page commands needed */ - if (bo->shadow) - amdgpu_vm_sdma_set_ptes(p, bo->shadow, pe, addr, + if (bo->tbo.type == ttm_bo_type_kernel)Same here.
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c +2
-0+amdgpu_vm_sdma_set_ptes (p,to_amdgpu_bo_vm (bo)->shadow, + pe, addr, count, incr, flags); amdgpu_vm_sdma_set_ptes(p, bo, pe, addr, count,incr, flags);
drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c +0
-0@@ -248,7 +249,7 @@ static int amdgpu_vm_sdma_update(struct amdgpu_vm_update_params *p, /* copy commands needed */Quoted 3 lines
ndw -=
p->adev->vm_manager.vm_pte_funcs->copy_pte_num_dw* - (bo->shadow? 2 : 1);
+ ((bo->tbo.type==ttm_bo_type_kernel) ? 2 : 1);And that here won't work and allocate to much SDMA space.
Quoted 8 lines
/* for padding */
ndw -= 7;drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c +0
-0@@ -263,8 +264,9 @@ static int amdgpu_vm_sdma_update(structamdgpu_vm_update_params *p, pte[i] |= flags; }
Quoted 16 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c static int amdgpu_vm_sdma_update(struct amdgpu_vm_update_params *p, · line 267
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c +1
-2- if (bo->shadow) - amdgpu_vm_sdma_copy_ptes(p, bo->shadow, pe, nptes); + if (bo->tbo.type == ttm_bo_type_kernel)And that is wrong as well.
Christian.
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c +2
-0+ amdgpu_vm_sdma_copy_ptes(p, to_amdgpu_bo_vm(bo)->shadow, + pe, nptes); amdgpu_vm_sdma_copy_ptes(p, bo, pe, nptes);pe += nptes * 8;
Signature · 1 line
2.31.1
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Christian König
maintainerRe: [PATCH v2 3/5] drm/amdgpu: switch to amdgpu_bo_vm for vm code
Am 26.05.21 um 19:32 schrieb Nirmoy:
Quoted 117 lines
Hi Christian,
Quoted 114 lines · Christian König
Am 26.05.21 um 15:06 schrieb Nirmoy Das:
Quoted 17 lines
The subclass,
amdgpu_bo_vmis intended for PT/PD BOs which are also shadowed, so switch toamdgpu_bo_vmBO for PT/PD BOs.v2: squash three related patches.
Signed-off-by Nirmoy Das <[email protected]>---
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 90
+++++++++++++--------
drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c| 16 ++--2 files changed, 67 insertions(+), 39 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0
-0drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c void amdgpu_vm_move_to_lru_tail(struct · line 664
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +3
-3@@ -658,9 +658,9 @@ void amdgpu_vm_move_to_lru_tail(structamdgpu_device *adev, ttm_bo_move_to_lru_tail(&bo->tbo, &bo->tbo.mem, &vm->lru_bulk_move); - if (bo->shadow) - ttm_bo_move_to_lru_tail(&bo->shadow->tbo, - &bo->shadow->tbo.mem, + if (bo->tbo.type == ttm_bo_type_kernel) + ttm_bo_move_to_lru_tail(&to_amdgpu_bo_vm(bo)->shadow->tbo, + &to_amdgpu_bo_vm(bo)->shadow->tbo.mem,Maybe use a local variable for the shadow BO here.
Quoted 16 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0
-0&vm->lru_bulk_move); }
spin_unlock(&adev->mman.bdev.lru_lock);drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2
-2@@ -696,8 +696,8 @@ int amdgpu_vm_validate_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm, r = validate(param, bo); if (r) return r; - if (bo->shadow) { - r = validate(param, bo->shadow); + if (bo->tbo.type == ttm_bo_type_kernel) { + r = validate(param, to_amdgpu_bo_vm(bo)->shadow); if (r) return r;}
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c static int amdgpu_vm_clear_bo(struct · line 799
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +3
-2@@ -793,8 +793,9 @@ static int amdgpu_vm_clear_bo(structamdgpu_device *adev, if (r) return r; - if (bo->shadow) { - r = ttm_bo_validate(&bo->shadow->tbo, &bo->shadow->placement, + if (bo->tbo.type == ttm_bo_type_kernel) { + r = ttm_bo_validate(&to_amdgpu_bo_vm(bo)->shadow->tbo, + &to_amdgpu_bo_vm(bo)->shadow->placement,Same here.
Quoted 54 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0
-0&ctx); if (r)return r;
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +5
-2@@ -863,14 +864,17 @@ static int amdgpu_vm_clear_bo(structamdgpu_device *adev, * @vm: requesting vm * @level: the page table level * @immediate: use a immediate update -* @bo: pointer to the buffer object pointer +* @vmbo: pointer to the buffer object pointer */ static int amdgpu_vm_pt_create(struct amdgpu_device *adev, struct amdgpu_vm *vm, int level, bool immediate, - struct amdgpu_bo **bo) + struct amdgpu_bo_vm **vmbo) { struct amdgpu_bo_param bp; + struct amdgpu_bo *bo; + struct amdgpu_bo *shadow_bo; + struct dma_resv *resv; int r;
memset(&bp, 0, sizeof(bp));drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0
-0@@ -881,7 +885,7 @@ static int amdgpu_vm_pt_create(structamdgpu_device *adev, bp.domain = amdgpu_bo_get_preferred_pin_domain(adev, bp.domain);bp.flags =
AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS|AMDGPU_GEM_CREATE_CPU_GTT_USWC;
- bp.bo_ptr_size =sizeof(struct amdgpu_bo);
+ bp.bo_ptr_size =sizeof(struct amdgpu_bo_vm); if (vm->use_cpu_for_update)
bp.flags |=AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED;drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +4
-3@@ -890,26 +894,43 @@ static int amdgpu_vm_pt_create(struct amdgpu_device *adev, if (vm->root.base.bo) bp.resv = vm->root.base.bo->tbo.base.resv; - r = amdgpu_bo_create(adev, &bp, bo); + r = amdgpu_bo_create_vm(adev, &bp, vmbo); if (r) return r; + bo = &(*vmbo)->bo; if (vm->is_compute_context && (adev->flags & AMD_IS_APU)) return 0; if (!bp.resv) - WARN_ON(dma_resv_lock((*bo)->tbo.base.resv, + WARN_ON(dma_resv_lock(bo->tbo.base.resv, NULL)); - r = amdgpu_bo_create_shadow(adev, bp.size, *bo); + resv = bp.resv;
Quoted 4 lines
Quoted 1 line
Maybe shuffle that code around a bit, then you only need the resv variable and no longer the bo variable.
I can remove the
shadow_bovariable but I need the bo foramdgpu_bo_unref(), as this takesamdgpu_bo** as argument.
Fine with me as well, just try to clean up the code a bit.
Regards,
Christian.
Quoted 240 lines
Regards,
Nirmoy
Quoted 233 lines
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +4
-0+ memset(&bp, 0, sizeof(bp)); + bp.size = amdgpu_vm_bo_size(adev, level); + bp.domain = AMDGPU_GEM_DOMAIN_GTT; + bp.flags = AMDGPU_GEM_CREATE_CPU_GTT_USWC;drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c static int amdgpu_vm_pt_create(struct amdgpu_device *adev,
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +6
-2+ bp.type = ttm_bo_type_kernel; + bp.resv = bo->tbo.base.resv; + bp.bo_ptr_size = sizeof(struct amdgpu_bo); - if (!bp.resv) - dma_resv_unlock((*bo)->tbo.base.resv); + r = amdgpu_bo_create(adev, &bp, &shadow_bo); + +Remove the two empty lines here
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2
-0+ if (!resv) + dma_resv_unlock(bo->tbo.base.resv); if (r) {drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c static int amdgpu_vm_pt_create(struct amdgpu_device *adev, · line 932
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +6
-1- amdgpu_bo_unref(bo); + amdgpu_bo_unref(&bo); return r; } + shadow_bo->parent = amdgpu_bo_ref(bo); + mutex_lock(&adev->shadow_list_lock); + list_add_tail(&shadow_bo->shadow_list, &adev->shadow_list); + mutex_unlock(&adev->shadow_list_lock); + (*vmbo)->shadow = shadow_bo;Ok, we should either move the
shadow_listinto thevm_mgrstructure or keep that in the object code.I think I prefer the later, something like
amdgpu_bo_add_to_shadow_list().Quoted 42 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1
-0+ return 0;}
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2
-1@@ -933,7 +954,8 @@ static int amdgpu_vm_alloc_pts(structamdgpu_device *adev, bool immediate) { struct amdgpu_vm_pt *entry = cursor->entry; - struct amdgpu_bo *pt; + struct amdgpu_bo *pt_bo; + struct amdgpu_bo_vm *pt; int r;if (
cursor->level<AMDGPU_VM_PTB&& !entry->entries) {drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +4
-3@@ -957,10 +979,11 @@ static int amdgpu_vm_alloc_pts(structamdgpu_device *adev, /* Keep a reference to the root directory to avoid * freeing them up in the wrong order. */ - pt->parent = amdgpu_bo_ref(cursor->parent->base.bo); - amdgpu_vm_bo_base_init(&entry->base, vm, pt); + pt_bo = &pt->bo; + pt_bo->parent = amdgpu_bo_ref(cursor->parent->base.bo); + amdgpu_vm_bo_base_init(&entry->base, vm, pt_bo); - r = amdgpu_vm_clear_bo(adev, vm, pt, immediate); + r = amdgpu_vm_clear_bo(adev, vm, pt_bo, immediate); if (r) goto error_free_pt;@@ -968,7 +991,7 @@ static int amdgpu_vm_alloc_pts(struct amdgpu_device *adev,
error_free_pt:
amdgpu_bo_unref(&pt->shadow);
-amdgpu_bo_unref(&pt);
+amdgpu_bo_unref(&pt_bo);
return r;
}drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c static void amdgpu_vm_free_table(struct · line 1009
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1
-1@@ -982,7 +1005,8 @@ static void amdgpu_vm_free_table(struct amdgpu_vm_pt *entry) if (entry->base.bo) { entry->base.bo->vm_bo = NULL; list_del(&entry->base.vm_status); - amdgpu_bo_unref(&entry->base.bo->shadow); + if (entry->base.bo->tbo.type == ttm_bo_type_kernel)That should always be true, otherwise we have a rather big bug.
So no need to check that here.
Quoted 78 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1
-0+amdgpu_bo_unref (&to_amdgpu_bo_vm (entry->base.bo)->shadow); amdgpu_bo_unref(&entry->base.bo); }
kvfree(entry->entries);drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2
-1@@ -2674,7 +2698,8 @@ void amdgpu_vm_bo_invalidate(struct amdgpu_device *adev, struct amdgpu_vm_bo_base *bo_base; /* shadow bo doesn't have bo base, its validation needs its parent */ - if (bo->parent && bo->parent->shadow == bo) + if (bo->parent && bo->tbo.type == ttm_bo_type_kernel && + to_amdgpu_bo_vm(bo->parent)->shadow == bo) bo = bo->parent;for (
bo_base=bo->vm_bo;bo_base;bo_base=bo_base->next) {drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2
-1@@ -2843,7 +2868,8 @@ long amdgpu_vm_wait_idle(struct amdgpu_vm *vm,long timeout) */ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm, u32 pasid) { - struct amdgpu_bo *root; + struct amdgpu_bo *root_bo; + struct amdgpu_bo_vm *root; int r, i;
vm->va=RB_ROOT_CACHED;drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +5
-5@@ -2897,18 +2923,18 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm, u32 pasid) false, &root); if (r) goto error_free_delayed; - - r = amdgpu_bo_reserve(root, true); + root_bo = &root->bo; + r = amdgpu_bo_reserve(root_bo, true); if (r) goto error_free_root; - r = dma_resv_reserve_shared(root->tbo.base.resv, 1); + r = dma_resv_reserve_shared(root_bo->tbo.base.resv, 1); if (r) goto error_unreserve; - amdgpu_vm_bo_base_init(&vm->root.base, vm, root); + amdgpu_vm_bo_base_init(&vm->root.base, vm, root_bo); - r = amdgpu_vm_clear_bo(adev, vm, root, false); + r = amdgpu_vm_clear_bo(adev, vm, root_bo, false); if (r) goto error_unreserve;@@ -2935,8 +2961,8 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm, u32 pasid) amdgpu_bo_unreserve(vm->root.base.bo);
error_free_root:
-amdgpu_bo_unref(&vm->root.base.bo->shadow);
-amdgpu_bo_unref(&vm->root.base.bo);
+amdgpu_bo_unref(&root->shadow);
+amdgpu_bo_unref(&root_bo);
vm->root.base.bo= NULL;
error_free_delayed:drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1
-1@@ -3078,7 +3104,7 @@ int amdgpu_vm_make_compute(struct amdgpu_device *adev, struct amdgpu_vm *vm, } /* Free the shadow bo for compute VM */ - amdgpu_bo_unref(&vm->root.base.bo->shadow); + amdgpu_bo_unref(&to_amdgpu_bo_vm(vm->root.base.bo)->shadow); if (pasid)
vm->pasid= pasid;drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c +0
-0drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c static int amdgpu_vm_sdma_map_table(struct · line 45
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c +1
-2@@ -41,8 +41,8 @@ static int amdgpu_vm_sdma_map_table(struct amdgpu_bo *table) if (r) return r; - if (table->shadow) - r = amdgpu_ttm_alloc_gart(&table->shadow->tbo); + if (table->tbo.type == ttm_bo_type_kernel)Again that check should be unecessary.
drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c static int amdgpu_vm_sdma_update(struct · line 242
Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c +1
-0+ r =amdgpu_ttm_alloc_gart (&to_amdgpu_bo_vm (table)->shadow->tbo);return r;
}drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c +1
-2@@ -238,8 +238,9 @@ static int amdgpu_vm_sdma_update(struct amdgpu_vm_update_params *p, if (!p->pages_addr) { /* set page commands needed */ - if (bo->shadow) - amdgpu_vm_sdma_set_ptes(p, bo->shadow, pe, addr, + if (bo->tbo.type == ttm_bo_type_kernel)Same here.
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c +2
-0+amdgpu_vm_sdma_set_ptes (p,to_amdgpu_bo_vm (bo)->shadow, + pe, addr, count, incr, flags); amdgpu_vm_sdma_set_ptes(p, bo, pe, addr, count,incr, flags);
drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c +0
-0@@ -248,7 +249,7 @@ static int amdgpu_vm_sdma_update(struct amdgpu_vm_update_params *p, /* copy commands needed */Quoted 3 lines
ndw -=
p->adev->vm_manager.vm_pte_funcs->copy_pte_num_dw* - (bo->shadow? 2 : 1);
+ ((bo->tbo.type==ttm_bo_type_kernel) ? 2 : 1);And that here won't work and allocate to much SDMA space.
drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c static int amdgpu_vm_sdma_update(struct · line 268
Quoted 11 lines
/* for padding */
ndw -= 7;drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c +1
-2@@ -263,8 +264,9 @@ static int amdgpu_vm_sdma_update(structamdgpu_vm_update_params *p, pte[i] |= flags; } - if (bo->shadow) - amdgpu_vm_sdma_copy_ptes(p, bo->shadow, pe, nptes); + if (bo->tbo.type == ttm_bo_type_kernel)And that is wrong as well.
Christian.
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c +2
-0+ amdgpu_vm_sdma_copy_ptes(p, to_amdgpu_bo_vm(bo)->shadow, + pe, nptes); amdgpu_vm_sdma_copy_ptes(p, bo, pe, nptes);pe += nptes * 8;
Signature · 1 line
2.31.1
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH v2 4/5 drm/amdgpu: remove unused code
In reply to Nirmoy DasRemove unused code related to shadow BO.
v2: removing shadow bo ptr from base class.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 29 ---------------------- drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | 6 ----- 2 files changed, 35 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +0 -29
@@ -638,35 +638,6 @@ int amdgpu_bo_create(struct amdgpu_device *adev,return r; } -int amdgpu_bo_create_shadow (struct amdgpu_device *adev, -unsigned long size, -struct amdgpu_bo *bo) -{ -struct amdgpu_bo_param bp; -int r; - -if (bo->shadow) -return 0 ; - -memset (&bp,0 ,sizeof (bp)); - bp.size = size; - bp.domain =AMDGPU_GEM_DOMAIN_GTT ; - bp.flags =AMDGPU_GEM_CREATE_CPU_GTT_USWC ; - bp.type = ttm_bo_type_kernel; - bp.resv = bo->tbo.base.resv; - bp.bo_ptr_size =sizeof (struct amdgpu_bo ); - - r =amdgpu_bo_create (adev, &bp, &bo->shadow); -if (!r) { - bo->shadow->parent =amdgpu_bo_ref (bo); -mutex_lock (&adev->shadow_list_lock); -list_add_tail (&bo->shadow->shadow_list, &adev->shadow_list); -mutex_unlock (&adev->shadow_list_lock); - } - -return r; -} -/** * amdgpu_bo_create_user - create an &amdgpu_bo_user buffer object * @adev: amdgpu device object
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +0 -6
@@ -104,9 +104,6 @@ struct amdgpu_bo {struct amdgpu_vm_bo_base *vm_bo;/* Constant after initialization */ struct amdgpu_bo *parent; -struct amdgpu_bo *shadow; - -#ifdef CONFIG_MMU_NOTIFIER struct mmu_interval_notifier notifier;
@@ -284,9 +281,6 @@ int amdgpu_bo_create_vm(struct amdgpu_device *adev, struct amdgpu_bo_vm **ubo_ptr);void amdgpu_bo_free_kernel (struct amdgpu_bo **bo,u64 *gpu_addr,void **cpu_addr); -int amdgpu_bo_create_shadow (struct amdgpu_device *adev, -unsigned long size, -struct amdgpu_bo *bo);int amdgpu_bo_kmap (struct amdgpu_bo *bo,void **ptr);void *amdgpu_bo_kptr (struct amdgpu_bo *bo);void amdgpu_bo_kunmap (struct amdgpu_bo *bo);
--
2.31.1
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 5/5 drm/amdgpu: do not allocate entries separately
In reply to Nirmoy DasAllocate PD/PT entries while allocating VM BOs and use that instead of allocating those entries separately.
v2: create a new var for num entries.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 34 +++++++++++++++----------- 1 file changed, 20 insertions(+), 14 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +20 -14
@@ -876,6 +876,7 @@ static int amdgpu_vm_pt_create(struct amdgpu_device *adev,struct amdgpu_bo *shadow_bo;struct dma_resv *resv;int r; +unsigned int num_entries;memset (&bp,0 ,sizeof (bp));
@@ -885,7 +886,14 @@ static int amdgpu_vm_pt_create(struct amdgpu_device *adev, bp.domain =amdgpu_bo_get_preferred_pin_domain (adev, bp.domain); bp.flags =AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS |AMDGPU_GEM_CREATE_CPU_GTT_USWC ; - bp.bo_ptr_size =sizeof (struct amdgpu_bo_vm ); + +if (level <AMDGPU_VM_PTB ) + num_entries =amdgpu_vm_num_entries (adev, level); +else + num_entries =0 ; + + bp.bo_ptr_size =struct_size ((*vmbo), entries, num_entries); +if (vm->use_cpu_for_update) bp.flags |=AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED ;
@@ -958,19 +966,14 @@ static int amdgpu_vm_alloc_pts(struct amdgpu_device *adev,struct amdgpu_bo_vm *pt;int r; -if (cursor->level <AMDGPU_VM_PTB && !entry->entries) { -unsigned num_entries; - - num_entries =amdgpu_vm_num_entries (adev, cursor->level); - entry->entries =kvmalloc_array (num_entries, -sizeof (*entry->entries), -GFP_KERNEL | __GFP_ZERO); -if (!entry->entries) -return -ENOMEM ; - } - -if (entry->base.bo) +if (entry->base.bo) { +if (cursor->level <AMDGPU_VM_PTB ) + entry->entries = +to_amdgpu_bo_vm (entry->base.bo)->entries; +else + entry->entries =NULL ;return 0 ; + } r =amdgpu_vm_pt_create (adev, vm, cursor->level, immediate, &pt);if (r)
@@ -982,6 +985,10 @@ static int amdgpu_vm_alloc_pts(struct amdgpu_device *adev, pt_bo = &pt->bo; pt_bo->parent =amdgpu_bo_ref (cursor->parent->base.bo);amdgpu_vm_bo_base_init (&entry->base, vm, pt_bo); +if (cursor->level <AMDGPU_VM_PTB ) + entry->entries = pt->entries; +else + entry->entries =NULL ; r =amdgpu_vm_clear_bo (adev, vm, pt_bo, immediate);if (r)
@@ -1009,7 +1016,6 @@ static void amdgpu_vm_free_table(struct amdgpu_vm_pt *entry)amdgpu_bo_unref (&to_amdgpu_bo_vm (entry->base.bo)->shadow);amdgpu_bo_unref (&entry->base.bo); } -kvfree (entry->entries); entry->entries =NULL ; }
Signature · 6 lines
2.31.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx