drm/amdgpu: fix amdgpu_fill_buffer
Subsystems (2)
PATCH 1/4 drm/amdgpu: fix amdgpu_fill_buffer
From: Christian König <[email protected]>
The mem start is relative to the domain in the address space, so this worked only when VRAM was mapped at offset 0.
It also didn't handled multiple drm_mm_nodes for split VRAM.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 70 ++++++++++++++++++++++----------- 1 file changed, 48 insertions(+), 22 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +48 -22
@@ -1378,29 +1378,40 @@ error_free:return r; } -int amdgpu_fill_buffer (struct amdgpu_bo *bo, -uint32_t src_data, -struct reservation_object *resv, -struct fence **fence) +int amdgpu_fill_buffer (struct amdgpu_bo *bo,uint32_t src_data, +struct reservation_object *resv, +struct fence **fence) {struct amdgpu_device *adev =amdgpu_ttm_adev (bo->tbo.bdev); -struct amdgpu_job *job; +uint32_t max_bytes = adev->mman.buffer_funcs->fill_max_bytes;struct amdgpu_ring *ring = adev->mman.buffer_funcs_ring; -uint32_t max_bytes, byte_count; -uint64_t dst_offset; +struct drm_mm_node *mm_node; +unsigned long num_pages;unsigned int num_loops, num_dw; -unsigned int i; + +struct amdgpu_job *job;int r; - byte_count = bo->tbo.num_pages <<PAGE_SHIFT ; - max_bytes = adev->mman.buffer_funcs->fill_max_bytes; - num_loops =DIV_ROUND_UP (byte_count, max_bytes); +if (!ring->ready) { +DRM_ERROR ("Trying to clear memory with ring turned off.\n" ); +return -EINVAL ; + } + + num_pages = bo->tbo.num_pages; + mm_node = bo->tbo.mem.mm_node; + num_loops =0 ; +while (num_pages) { +uint32_t byte_count = mm_node->size <<PAGE_SHIFT ; + + num_loops +=DIV_ROUND_UP (byte_count, max_bytes); + num_pages -= mm_node->size; + ++mm_node; + } num_dw = num_loops * adev->mman.buffer_funcs->fill_num_dw;/* for IB padding */ -while (num_dw &0x7 ) - num_dw++; + num_dw +=64 ; r =amdgpu_job_alloc_with_ib (adev, num_dw *4 , &job);if (r)
@@ -1408,28 +1419,43 @@ int amdgpu_fill_buffer(struct amdgpu_bo *bo,if (resv) { r =amdgpu_sync_resv (adev, &job->sync, resv, -AMDGPU_FENCE_OWNER_UNDEFINED ); +AMDGPU_FENCE_OWNER_UNDEFINED );if (r) {DRM_ERROR ("sync failed (%d).\n" , r); goto error_free; } } - dst_offset = bo->tbo.mem.start <<PAGE_SHIFT ; -for (i =0 ; i < num_loops; i++) { -uint32_t cur_size_in_bytes =min (byte_count, max_bytes); + num_pages = bo->tbo.num_pages; + mm_node = bo->tbo.mem.mm_node; -amdgpu_emit_fill_buffer (adev, &job->ibs[0 ], src_data, - dst_offset, cur_size_in_bytes); +while (num_pages) { +uint32_t byte_count = mm_node->size <<PAGE_SHIFT ; +uint64_t dst_addr; - dst_offset += cur_size_in_bytes; - byte_count -= cur_size_in_bytes; + r =amdgpu_mm_node_addr (&bo->tbo, mm_node, + &bo->tbo.mem, &dst_addr); +if (r) +return r; + +while (byte_count) { +uint32_t cur_size_in_bytes =min (byte_count, max_bytes); + +amdgpu_emit_fill_buffer (adev, &job->ibs[0 ], src_data, + dst_addr, cur_size_in_bytes); + + dst_addr += cur_size_in_bytes; + byte_count -= cur_size_in_bytes; + } + + num_pages -= mm_node->size; + ++mm_node; }amdgpu_ring_pad_ib (ring, &job->ibs[0 ]);WARN_ON (job->ibs[0 ].length_dw > num_dw); r =amdgpu_job_submit (job, ring, &adev->mman.entity, -AMDGPU_FENCE_OWNER_UNDEFINED , fence); +AMDGPU_FENCE_OWNER_UNDEFINED , fence);if (r) goto error_free;
Signature · 6 lines
2.5.0 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 1479394810-1887-1-git-send-email-deathsimple-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org
PATCH 2/4 drm/amdgpu: fix error handling in amdgpu_bo_create_restricted
From: Christian König <[email protected]>
Manually checking why a function could fail is not a good idea if you can just check the functions return code.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +4 -7
@@ -382,12 +382,6 @@ int amdgpu_bo_create_restricted(struct amdgpu_device *adev, bo->tbo.mem.placement & TTM_PL_FLAG_VRAM) {struct fence *fence; -if (adev->mman.buffer_funcs_ring ==NULL || - !adev->mman.buffer_funcs_ring->ready) { - r = -EBUSY ; - goto fail_free; - } - r =amdgpu_bo_reserve (bo, false);if (unlikely (r !=0 )) goto fail_free;
@@ -397,7 +391,10 @@ int amdgpu_bo_create_restricted(struct amdgpu_device *adev,if (unlikely (r !=0 )) goto fail_unreserve; -amdgpu_fill_buffer (bo,0 , bo->tbo.resv, &fence); + r =amdgpu_fill_buffer (bo,0 , bo->tbo.resv, &fence); +if (unlikely (r)) + goto fail_unreserve; +amdgpu_bo_fence (bo, fence, false);amdgpu_bo_unreserve (bo);fence_put (bo->tbo.moving);
Signature · 6 lines
2.5.0 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 3/4 drm/amdgpu: improve AMDGPU_GEM_CREATE_VRAM_CLEARED handling
In reply to a message not in the archiveFrom: Christian König <[email protected]>
Drop this whole reserve/unreserve dance, just lock the reservation object manually when creating the BO.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +14 -15
@@ -371,36 +371,36 @@ int amdgpu_bo_create_restricted(struct amdgpu_device *adev,amdgpu_fill_placement_to_bo (bo, placement);/* Kernel allocation are uninterruptible */ + +if (!resv) { +bool locked; + +reservation_object_init (&bo->tbo.ttm_resv); + locked =ww_mutex_trylock (&bo->tbo.ttm_resv.lock); +WARN_ON (!locked); + } r =ttm_bo_init (&adev->mman.bdev, &bo->tbo, size, type, &bo->placement, page_align, !kernel,NULL , - acc_size, sg, resv, &amdgpu_ttm_bo_destroy); -if (unlikely (r !=0 )) { + acc_size, sg, resv ? resv : &bo->tbo.ttm_resv, + &amdgpu_ttm_bo_destroy); +if (unlikely (r !=0 ))return r; - }if (flags &AMDGPU_GEM_CREATE_VRAM_CLEARED && bo->tbo.mem.placement &TTM_PL_FLAG_VRAM ) {struct fence *fence; - r =amdgpu_bo_reserve (bo, false); -if (unlikely (r !=0 )) - goto fail_free; - -amdgpu_ttm_placement_from_domain (bo,AMDGPU_GEM_DOMAIN_VRAM ); - r =ttm_bo_validate (&bo->tbo, &bo->placement, false, false); -if (unlikely (r !=0 )) - goto fail_unreserve; - r =amdgpu_fill_buffer (bo,0 , bo->tbo.resv, &fence);if (unlikely (r)) goto fail_unreserve;amdgpu_bo_fence (bo, fence, false); -amdgpu_bo_unreserve (bo);fence_put (bo->tbo.moving); bo->tbo.moving =fence_get (fence);fence_put (fence); } +if (!resv) +ww_mutex_unlock (&bo->tbo.resv->lock); *bo_ptr = bo;trace_amdgpu_bo_create (bo);
@@ -408,8 +408,7 @@ int amdgpu_bo_create_restricted(struct amdgpu_device *adev,return 0 ; fail_unreserve: -amdgpu_bo_unreserve (bo); -fail_free: +ww_mutex_unlock (&bo->tbo.resv->lock);amdgpu_bo_unref (&bo);return r; }
Signature · 6 lines
2.5.0 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 4/4 drm/amdgpu: use AMDGPU_GEM_CREATE_VRAM_CLEARED for VM PD/PTs
In reply to a message not in the archiveFrom: Christian König <[email protected]>
Doesn't make much sense to have the same functionality twice.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 99 ++-------------------------------- 1 file changed, 4 insertions(+), 95 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +4 -95
@@ -530,70 +530,6 @@ static void amdgpu_vm_do_copy_ptes(struct amdgpu_pte_update_params *params, }/** -* amdgpu_vm_clear_bo - initially clear the page dir/table -* -* @adev: amdgpu_device pointer -* @bo: bo to clear -* -* need to reserve bo first before calling it. -*/ -static int amdgpu_vm_clear_bo (struct amdgpu_device *adev, -struct amdgpu_vm *vm, -struct amdgpu_bo *bo) -{ -struct amdgpu_ring *ring; -struct fence *fence =NULL ; -struct amdgpu_job *job; -struct amdgpu_pte_update_params params; -unsigned entries; -uint64_t addr; -int r; - - ring = container_of(vm->entity.sched, struct amdgpu_ring, sched); - - r =reservation_object_reserve_shared (bo->tbo.resv); -if (r) -return r; - - r =ttm_bo_validate (&bo->tbo, &bo->placement, true, false); -if (r) - goto error; - - r =amdgpu_ttm_bind (&bo->tbo, &bo->tbo.mem); -if (r) - goto error; - - addr =amdgpu_bo_gpu_offset (bo); - entries =amdgpu_bo_size (bo) /8 ; - - r =amdgpu_job_alloc_with_ib (adev,64 , &job); -if (r) - goto error; - -memset (¶ms,0 ,sizeof (params)); - params.adev = adev; - params.ib = &job->ibs[0 ]; -amdgpu_vm_do_set_ptes (¶ms, addr,0 , entries,0 ,0 ); -amdgpu_ring_pad_ib (ring, &job->ibs[0 ]); - -WARN_ON (job->ibs[0 ].length_dw >64 ); - r =amdgpu_job_submit (job, ring, &vm->entity, -AMDGPU_FENCE_OWNER_VM , &fence); -if (r) - goto error_free; - -amdgpu_bo_fence (bo, fence, true); -fence_put (fence); -return 0 ; - -error_free: -amdgpu_job_free (job); - -error: -return r; -} - -/** * amdgpu_vm_map_gart - Resolve gart mapping of addr * * @pages_addr: optional DMA address to use for lookup
@@ -1435,7 +1371,8 @@ int amdgpu_vm_bo_map(struct amdgpu_device *adev,AMDGPU_GEM_DOMAIN_VRAM ,AMDGPU_GEM_CREATE_NO_CPU_ACCESS |AMDGPU_GEM_CREATE_SHADOW | -AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS , +AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS | +AMDGPU_GEM_CREATE_VRAM_CLEARED , NULL, resv, &pt);if (r) goto error_free;
@@ -1445,22 +1382,6 @@ int amdgpu_vm_bo_map(struct amdgpu_device *adev,*/ pt->parent =amdgpu_bo_ref (vm->page_directory); - r =amdgpu_vm_clear_bo (adev, vm, pt); -if (r) { -amdgpu_bo_unref (&pt->shadow); -amdgpu_bo_unref (&pt); - goto error_free; - } - -if (pt->shadow) { - r =amdgpu_vm_clear_bo (adev, vm, pt->shadow); -if (r) { -amdgpu_bo_unref (&pt->shadow); -amdgpu_bo_unref (&pt); - goto error_free; - } - } - vm->page_tables[pt_idx].bo = pt; vm->page_tables[pt_idx].addr =0 ; }
@@ -1642,7 +1563,8 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm)AMDGPU_GEM_DOMAIN_VRAM ,AMDGPU_GEM_CREATE_NO_CPU_ACCESS |AMDGPU_GEM_CREATE_SHADOW | -AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS , +AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS | +AMDGPU_GEM_CREATE_VRAM_CLEARED , NULL, NULL, &vm->page_directory);if (r) goto error_free_sched_entity;
@@ -1651,24 +1573,11 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm)if (r) goto error_free_page_directory; - r =amdgpu_vm_clear_bo (adev, vm, vm->page_directory); -if (r) - goto error_unreserve; - -if (vm->page_directory->shadow) { - r =amdgpu_vm_clear_bo (adev, vm, vm->page_directory->shadow); -if (r) - goto error_unreserve; - } - vm->last_eviction_counter =atomic64_read (&adev->num_evictions);amdgpu_bo_unreserve (vm->page_directory);return 0 ; -error_unreserve: -amdgpu_bo_unreserve (vm->page_directory); - error_free_page_directory:amdgpu_bo_unref (&vm->page_directory->shadow);amdgpu_bo_unref (&vm->page_directory);
Signature · 6 lines
2.5.0 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 1479394810-1887-4-git-send-email-deathsimple-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org
Deucher, Alexander
Reviewed-by Alex DeucherRE: [PATCH 4/4] drm/amdgpu: use AMDGPU_GEM_CREATE_VRAM_CLEARED for VM PD/PTs
Quoted 8 lines
-----Original Message-----
From: amd-gfx [mailto:[email protected]] On Behalf Of Christian König
Sent: Thursday, November 17, 2016 10:00 AM
To: [email protected]
Subject: [PATCH 4/4] drm/amdgpu: useAMDGPU_GEM_CREATE_VRAM_CLEAREDfor VM PD/PTs
Quoted 5 lines
From: Christian König <[email protected]>
Doesn't make much sense to have the same functionality twice.
Signed-off-by Christian König <[email protected]>
Series is:
Quoted 163 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 99 ++--------------------------- ----- 1 file changed, 4 insertions(+), 95 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0
-64@@ -530,70 +530,6 @@ static void amdgpu_vm_do_copy_ptes(struct amdgpu_pte_update_params *params, }/** -* amdgpu_vm_clear_bo - initially clear the page dir/table -* -* @adev: amdgpu_device pointer -* @bo: bo to clear -* -* need to reserve bo first before calling it. -*/ -static int amdgpu_vm_clear_bo (struct amdgpu_device *adev, -struct amdgpu_vm *vm, -struct amdgpu_bo *bo) -{ -struct amdgpu_ring *ring; -struct fence *fence =NULL ; -struct amdgpu_job *job; -struct amdgpu_pte_update_params params; -unsigned entries; -uint64_t addr; -int r; - - ring = container_of(vm->entity.sched, struct amdgpu_ring, sched); - - r =reservation_object_reserve_shared (bo->tbo.resv); -if (r) -return r; - - r =ttm_bo_validate (&bo->tbo, &bo->placement, true, false); -if (r) - goto error; - - r =amdgpu_ttm_bind (&bo->tbo, &bo->tbo.mem); -if (r) - goto error; - - addr =amdgpu_bo_gpu_offset (bo); - entries =amdgpu_bo_size (bo) /8 ; - - r =amdgpu_job_alloc_with_ib (adev,64 , &job); -if (r) - goto error; - -memset (¶ms,0 ,sizeof (params)); - params.adev = adev; - params.ib = &job->ibs[0 ]; -amdgpu_vm_do_set_ptes (¶ms, addr,0 , entries,0 ,0 ); -amdgpu_ring_pad_ib (ring, &job->ibs[0 ]); - -WARN_ON (job->ibs[0 ].length_dw >64 ); - r =amdgpu_job_submit (job, ring, &vm->entity, -AMDGPU_FENCE_OWNER_VM , &fence); -if (r) - goto error_free; - -amdgpu_bo_fence (bo, fence, true); -fence_put (fence); -return 0 ; - -error_free: -amdgpu_job_free (job); - -error: -return r; -} - -/** * amdgpu_vm_map_gart - Resolve gart mapping of addr * * @pages_addr: optional DMA address to use for lookup
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0
-0@@ -1435,7 +1371,8 @@ int amdgpu_vm_bo_map(struct amdgpu_device *adev, AMDGPU_GEM_DOMAIN_VRAM,
AMDGPU_GEM_CREATE_NO_CPU_ACCESS|drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0
-1AMDGPU_GEM_CREATE_SHADOW | -
AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS,
+AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS|
+AMDGPU_GEM_CREATE_VRAM_CLEARED,drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0
-16NULL, resv, &pt);if (r) goto error_free;@@ -1445,22 +1382,6 @@ int amdgpu_vm_bo_map(struct amdgpu_device*adev, */ pt->parent =amdgpu_bo_ref (vm->page_directory); - r =amdgpu_vm_clear_bo (adev, vm, pt); -if (r) { -amdgpu_bo_unref (&pt->shadow); -amdgpu_bo_unref (&pt); - goto error_free; - } - -if (pt->shadow) { - r =amdgpu_vm_clear_bo (adev, vm, pt->shadow); -if (r) { -amdgpu_bo_unref (&pt->shadow); -amdgpu_bo_unref (&pt); - goto error_free; - } - } - vm->page_tables[pt_idx].bo = pt; vm->page_tables[pt_idx].addr =0 ;drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2
-1}@@ -1642,7 +1563,8 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm)AMDGPU_GEM_DOMAIN_VRAM , AMDGPU_GEM_CREATE_NO_CPU_ACCESS | AMDGPU_GEM_CREATE_SHADOW | -AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS , + AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS | +AMDGPU_GEM_CREATE_VRAM_CLEARED , NULL, NULL, &vm->page_directory);if (r)drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0
-13goto error_free_sched_entity;@@ -1651,24 +1573,11 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm)if (r) goto error_free_page_directory; - r =amdgpu_vm_clear_bo (adev, vm, vm->page_directory); -if (r) - goto error_unreserve; - -if (vm->page_directory->shadow) { - r =amdgpu_vm_clear_bo (adev, vm, vm->page_directory- >shadow); -if (r) - goto error_unreserve; - } - vm->last_eviction_counter =atomic64_read (&adev- >num_evictions);amdgpu_bo_unreserve (vm->page_directory);return 0 ; -error_unreserve: -amdgpu_bo_unreserve (vm->page_directory); -
error_free_page_directory:drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0
-1amdgpu_bo_unref (&vm->page_directory->shadow);amdgpu_bo_unref (&vm->page_directory); --2.5.0
Quoted 4 lines
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx